Mercurial > dwindows
comparison gtk4/dw.c @ 2327:0d7f8136d771
GTK4: Move dw_messagebox() into thread safety protection using dw_messagebox_int().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 28 Feb 2021 10:42:55 +0000 |
parents | 258c1b9c29f4 |
children | 5363f953b22a |
comparison
equal
deleted
inserted
replaced
2326:258c1b9c29f4 | 2327:0d7f8136d771 |
---|---|
1599 va_end(args); | 1599 va_end(args); |
1600 | 1600 |
1601 fprintf(stderr, "%s", outbuf); | 1601 fprintf(stderr, "%s", outbuf); |
1602 } | 1602 } |
1603 | 1603 |
1604 /* | 1604 /* Internal version that does not use variable arguments */ |
1605 * Displays a Message Box with given text and title.. | 1605 DW_FUNCTION_DEFINITION(dw_messagebox_int, int, const char *title, int flags, char *outbuf) |
1606 * Parameters: | 1606 DW_FUNCTION_ADD_PARAM3(title, flags, outbuf) |
1607 * title: The title of the message box. | 1607 DW_FUNCTION_RETURN(dw_messagebox_int, int) |
1608 * flags: Defines buttons and icons to display | 1608 DW_FUNCTION_RESTORE_PARAM3(title, const char *, flags, int, outbuf, char *) |
1609 * format: printf style format string. | |
1610 * ...: Additional variables for use in the format. | |
1611 */ | |
1612 int API dw_messagebox(const char *title, int flags, const char *format, ...) | |
1613 { | 1609 { |
1614 GtkMessageType gtkicon = GTK_MESSAGE_OTHER; | 1610 GtkMessageType gtkicon = GTK_MESSAGE_OTHER; |
1615 GtkButtonsType gtkbuttons = GTK_BUTTONS_OK; | 1611 GtkButtonsType gtkbuttons = GTK_BUTTONS_OK; |
1616 GtkWidget *dialog; | 1612 GtkWidget *dialog; |
1617 int response; | 1613 int response, retval = DW_MB_RETURN_OK; |
1618 va_list args; | |
1619 char outbuf[1025] = {0}; | |
1620 DWDialog *tmp = dw_dialog_new(NULL); | 1614 DWDialog *tmp = dw_dialog_new(NULL); |
1621 ULONG width, height; | 1615 ULONG width, height; |
1622 | |
1623 va_start(args, format); | |
1624 vsnprintf(outbuf, 1024, format, args); | |
1625 va_end(args); | |
1626 | 1616 |
1627 if(flags & DW_MB_ERROR) | 1617 if(flags & DW_MB_ERROR) |
1628 gtkicon = GTK_MESSAGE_ERROR; | 1618 gtkicon = GTK_MESSAGE_ERROR; |
1629 else if(flags & DW_MB_WARNING) | 1619 else if(flags & DW_MB_WARNING) |
1630 gtkicon = GTK_MESSAGE_WARNING; | 1620 gtkicon = GTK_MESSAGE_WARNING; |
1653 if(GTK_IS_WINDOW(dialog)) | 1643 if(GTK_IS_WINDOW(dialog)) |
1654 gtk_window_destroy(GTK_WINDOW(dialog)); | 1644 gtk_window_destroy(GTK_WINDOW(dialog)); |
1655 switch(response) | 1645 switch(response) |
1656 { | 1646 { |
1657 case GTK_RESPONSE_OK: | 1647 case GTK_RESPONSE_OK: |
1658 return DW_MB_RETURN_OK; | 1648 retval = DW_MB_RETURN_OK; |
1649 break; | |
1659 case GTK_RESPONSE_CANCEL: | 1650 case GTK_RESPONSE_CANCEL: |
1660 return DW_MB_RETURN_CANCEL; | 1651 retval = DW_MB_RETURN_CANCEL; |
1652 break; | |
1661 case GTK_RESPONSE_YES: | 1653 case GTK_RESPONSE_YES: |
1662 return DW_MB_RETURN_YES; | 1654 retval = DW_MB_RETURN_YES; |
1655 break; | |
1663 case GTK_RESPONSE_NO: | 1656 case GTK_RESPONSE_NO: |
1664 return DW_MB_RETURN_NO; | 1657 retval = DW_MB_RETURN_NO; |
1658 break; | |
1665 default: | 1659 default: |
1666 { | 1660 { |
1667 /* Handle the destruction of the dialog result */ | 1661 /* Handle the destruction of the dialog result */ |
1668 if(flags & (DW_MB_OKCANCEL | DW_MB_YESNOCANCEL)) | 1662 if(flags & (DW_MB_OKCANCEL | DW_MB_YESNOCANCEL)) |
1669 return DW_MB_RETURN_CANCEL; | 1663 retval = DW_MB_RETURN_CANCEL; |
1670 else if(flags & DW_MB_YESNO) | 1664 else if(flags & DW_MB_YESNO) |
1671 return DW_MB_RETURN_NO; | 1665 retval = DW_MB_RETURN_NO; |
1672 } | 1666 } |
1673 } | 1667 } |
1674 return DW_MB_RETURN_OK; | 1668 DW_FUNCTION_RETURN_THIS(retval); |
1669 } | |
1670 | |
1671 /* | |
1672 * Displays a Message Box with given text and title.. | |
1673 * Parameters: | |
1674 * title: The title of the message box. | |
1675 * flags: Defines buttons and icons to display | |
1676 * format: printf style format string. | |
1677 * ...: Additional variables for use in the format. | |
1678 */ | |
1679 int API dw_messagebox(const char *title, int flags, const char *format, ...) | |
1680 { | |
1681 va_list args; | |
1682 char outbuf[1025] = {0}; | |
1683 | |
1684 va_start(args, format); | |
1685 vsnprintf(outbuf, 1024, format, args); | |
1686 va_end(args); | |
1687 | |
1688 return dw_messagebox_int(title, flags, outbuf); | |
1675 } | 1689 } |
1676 | 1690 |
1677 /* | 1691 /* |
1678 * Minimizes or Iconifies a top-level window. | 1692 * Minimizes or Iconifies a top-level window. |
1679 * Parameters: | 1693 * Parameters: |