# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1614508975 0 # Node ID 0d7f8136d77172f14d47b048161b9d467f41b580 # Parent 258c1b9c29f41cdbca527aeb3dd86bc7072bb1b3 GTK4: Move dw_messagebox() into thread safety protection using dw_messagebox_int(). diff -r 258c1b9c29f4 -r 0d7f8136d771 gtk4/dw.c --- a/gtk4/dw.c Tue Feb 23 22:43:19 2021 +0000 +++ b/gtk4/dw.c Sun Feb 28 10:42:55 2021 +0000 @@ -1601,29 +1601,19 @@ fprintf(stderr, "%s", outbuf); } -/* - * Displays a Message Box with given text and title.. - * Parameters: - * title: The title of the message box. - * flags: Defines buttons and icons to display - * format: printf style format string. - * ...: Additional variables for use in the format. - */ -int API dw_messagebox(const char *title, int flags, const char *format, ...) +/* Internal version that does not use variable arguments */ +DW_FUNCTION_DEFINITION(dw_messagebox_int, int, const char *title, int flags, char *outbuf) +DW_FUNCTION_ADD_PARAM3(title, flags, outbuf) +DW_FUNCTION_RETURN(dw_messagebox_int, int) +DW_FUNCTION_RESTORE_PARAM3(title, const char *, flags, int, outbuf, char *) { GtkMessageType gtkicon = GTK_MESSAGE_OTHER; GtkButtonsType gtkbuttons = GTK_BUTTONS_OK; GtkWidget *dialog; - int response; - va_list args; - char outbuf[1025] = {0}; + int response, retval = DW_MB_RETURN_OK; DWDialog *tmp = dw_dialog_new(NULL); ULONG width, height; - va_start(args, format); - vsnprintf(outbuf, 1024, format, args); - va_end(args); - if(flags & DW_MB_ERROR) gtkicon = GTK_MESSAGE_ERROR; else if(flags & DW_MB_WARNING) @@ -1655,23 +1645,47 @@ switch(response) { case GTK_RESPONSE_OK: - return DW_MB_RETURN_OK; + retval = DW_MB_RETURN_OK; + break; case GTK_RESPONSE_CANCEL: - return DW_MB_RETURN_CANCEL; + retval = DW_MB_RETURN_CANCEL; + break; case GTK_RESPONSE_YES: - return DW_MB_RETURN_YES; + retval = DW_MB_RETURN_YES; + break; case GTK_RESPONSE_NO: - return DW_MB_RETURN_NO; + retval = DW_MB_RETURN_NO; + break; default: { /* Handle the destruction of the dialog result */ if(flags & (DW_MB_OKCANCEL | DW_MB_YESNOCANCEL)) - return DW_MB_RETURN_CANCEL; + retval = DW_MB_RETURN_CANCEL; else if(flags & DW_MB_YESNO) - return DW_MB_RETURN_NO; - } - } - return DW_MB_RETURN_OK; + retval = DW_MB_RETURN_NO; + } + } + DW_FUNCTION_RETURN_THIS(retval); +} + +/* + * Displays a Message Box with given text and title.. + * Parameters: + * title: The title of the message box. + * flags: Defines buttons and icons to display + * format: printf style format string. + * ...: Additional variables for use in the format. + */ +int API dw_messagebox(const char *title, int flags, const char *format, ...) +{ + va_list args; + char outbuf[1025] = {0}; + + va_start(args, format); + vsnprintf(outbuf, 1024, format, args); + va_end(args); + + return dw_messagebox_int(title, flags, outbuf); } /*