# HG changeset patch # User mhessling@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1052484891 0 # Node ID a7a561103eacdb2e0a57d09a1278c496ce3bae8b # Parent 255a31a3a1f5ef26fddd040db9a85b931476a4f1 Add flags parameter to dw_messagebox() to specify buttons and icon displayed. Remove dw_yesno(); now superfluous. diff -r 255a31a3a1f5 -r a7a561103eac gtk/dw.c --- a/gtk/dw.c Fri May 09 12:52:38 2003 +0000 +++ b/gtk/dw.c Fri May 09 12:54:51 2003 +0000 @@ -25,6 +25,11 @@ #include #endif +#include "messagebox_error.xpm" +#include "messagebox_warning.xpm" +#include "messagebox_information.xpm" +#include "messagebox_question.xpm" + /* These are used for resource management */ #if defined(DW_RESOURCES) && !defined(BUILD_DLL) extern DWResources _resources; @@ -1072,65 +1077,10 @@ return FALSE; dw_window_destroy((HWND)dwwait->data); - dw_dialog_dismiss((DWDialog *)data, (void *)0); + dw_dialog_dismiss((DWDialog *)data, (void *)DW_MB_RETURN_OK); return FALSE; } -/* - * Displays a Message Box with given text and title.. - * Parameters: - * title: The title of the message box. - * format: printf style format string. - * ...: Additional variables for use in the format. - */ -int dw_messagebox(char *title, char *format, ...) -{ - HWND entrywindow, mainbox, okbutton, buttonbox, stext; - ULONG flStyle = DW_FCF_TITLEBAR | DW_FCF_SHELLPOSITION | DW_FCF_DLGBORDER; - DWDialog *dwwait; - va_list args; - char outbuf[256]; - int x, y; - - va_start(args, format); - vsprintf(outbuf, format, args); - va_end(args); - - entrywindow = dw_window_new(HWND_DESKTOP, title, flStyle); - mainbox = dw_box_new(DW_VERT, 10); - dw_box_pack_start(entrywindow, mainbox, 0, 0, TRUE, TRUE, 0); - - /* Archive Name */ - stext = dw_text_new(outbuf, 0); - dw_window_set_style(stext, DW_DT_WORDBREAK, DW_DT_WORDBREAK); - - dw_box_pack_start(mainbox, stext, 205, 50, TRUE, TRUE, 2); - - /* Buttons */ - buttonbox = dw_box_new(DW_HORZ, 10); - - dw_box_pack_start(mainbox, buttonbox, 0, 0, TRUE, FALSE, 0); - - okbutton = dw_button_new("Ok", 1001L); - - dw_box_pack_start(buttonbox, okbutton, 50, 30, TRUE, FALSE, 2); - - dwwait = dw_dialog_new((void *)entrywindow); - - dw_signal_connect(okbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_ok_func), (void *)dwwait); - - x = (dw_screen_width() - 220)/2; - y = (dw_screen_height() - 110)/2; - - dw_window_set_pos_size(entrywindow, x, y, 220, 110); - - dw_window_show(entrywindow); - - dw_dialog_wait(dwwait); - - return strlen(outbuf); -} - int _dw_yes_func(HWND window, void *data) { DWDialog *dwwait = (DWDialog *)data; @@ -1139,7 +1089,7 @@ return FALSE; dw_window_destroy((HWND)dwwait->data); - dw_dialog_dismiss((DWDialog *)data, (void *)1); + dw_dialog_dismiss((DWDialog *)data, (void *)DW_MB_RETURN_YES); return FALSE; } @@ -1151,7 +1101,19 @@ return FALSE; dw_window_destroy((HWND)dwwait->data); - dw_dialog_dismiss((DWDialog *)data, (void *)0); + dw_dialog_dismiss((DWDialog *)data, (void *)DW_MB_RETURN_NO); + return FALSE; +} + +int _dw_cancel_func(HWND window, void *data) +{ + DWDialog *dwwait = (DWDialog *)data; + + if(!dwwait) + return FALSE; + + dw_window_destroy((HWND)dwwait->data); + dw_dialog_dismiss((DWDialog *)data, (void *)DW_MB_RETURN_CANCEL); return FALSE; } @@ -1159,46 +1121,127 @@ * Displays a Message Box with given text and title.. * Parameters: * title: The title of the message box. - * text: The text to display in the box. - * Returns: - * True if YES False of NO. - */ -int dw_yesno(char *title, char *text) -{ - HWND entrywindow, mainbox, nobutton, yesbutton, buttonbox, stext; + * flags: Defines buttons and icons to display + * format: printf style format string. + * ...: Additional variables for use in the format. + */ +int dw_messagebox(char *title, int flags, char *format, ...) +{ + HWND entrywindow, texttargetbox, imagetextbox, mainbox, okbutton, nobutton, yesbutton, cancelbutton, buttonbox, stext; ULONG flStyle = DW_FCF_TITLEBAR | DW_FCF_SHELLPOSITION | DW_FCF_DLGBORDER; DWDialog *dwwait; + va_list args; + char outbuf[256]; + char **xpm_data = NULL; int x, y; + va_start(args, format); + vsprintf(outbuf, format, args); + va_end(args); + entrywindow = dw_window_new(HWND_DESKTOP, title, flStyle); - mainbox = dw_box_new(DW_VERT, 10); - dw_box_pack_start(entrywindow, mainbox, 0, 0, TRUE, TRUE, 0); - - /* Archive Name */ - stext = dw_text_new(text, 0); +/* delete me */dw_window_set_color(mainbox, DW_CLR_BLACK, DW_CLR_RED); + +/* determine if an icon is to be used - if so we need another HORZ box */ + if((flags & DW_MB_ERROR) | (flags & DW_MB_WARNING) | (flags & DW_MB_INFORMATION) | (flags & DW_MB_QUESTION)) + { + imagetextbox = dw_box_new(DW_HORZ, 101); + dw_box_pack_start(mainbox, imagetextbox, 0, 0, TRUE, TRUE, 2); + texttargetbox = imagetextbox; +/* delete me */dw_window_set_color(imagetextbox, DW_CLR_BLACK, DW_CLR_YELLOW); + } + else + { + imagetextbox = NULL; + texttargetbox = mainbox; + } + + if(flags & DW_MB_ERROR) + xpm_data = (char **)_dw_messagebox_error; + else if(flags & DW_MB_WARNING) + xpm_data = (char **)_dw_messagebox_warning; + else if(flags & DW_MB_INFORMATION) + xpm_data = (char **)_dw_messagebox_information; + else if(flags & DW_MB_QUESTION) + xpm_data = (char **)_dw_messagebox_question; + + if(texttargetbox == imagetextbox) + { + GdkPixmap *icon_pixmap = NULL; + GdkBitmap *bitmap = NULL; + HWND handle = dw_bitmap_new( 100 ); +#if GTK_MAJOR_VERSION > 1 + GdkPixbuf *icon_pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)xpm_data); + + gdk_pixbuf_render_pixmap_and_mask(icon_pixbuf, &icon_pixmap, &bitmap, 1); + g_object_unref(icon_pixbuf); +#elif defined(USE_IMLIB) + gdk_imlib_data_to_pixmap((char **)xpm_data, &icon_pixmap, &bitmap); +#else + icon_pixmap = gdk_pixmap_create_from_xpm_d(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], (char **)xpm_data); +#endif + +#if GTK_MAJOR_VERSION > 1 + gtk_image_set_from_pixmap(GTK_IMAGE(handle), icon_pixmap, bitmap); +#else + gtk_pixmap_set(GTK_PIXMAP(handle), icon_pixmap, bitmap); +#endif + + dw_box_pack_start( texttargetbox, handle, 32, 32, FALSE, FALSE, 2); + } + + /* Create text */ + stext = dw_text_new(outbuf, 0); dw_window_set_style(stext, DW_DT_WORDBREAK, DW_DT_WORDBREAK); - - dw_box_pack_start(mainbox, stext, 205, 50, TRUE, TRUE, 2); + dw_box_pack_start(texttargetbox, stext, 205, 50, TRUE, TRUE, 2); /* Buttons */ buttonbox = dw_box_new(DW_HORZ, 10); dw_box_pack_start(mainbox, buttonbox, 0, 0, TRUE, FALSE, 0); - - yesbutton = dw_button_new("Yes", 1001L); - - dw_box_pack_start(buttonbox, yesbutton, 50, 30, TRUE, FALSE, 2); - - nobutton = dw_button_new("No", 1002L); - - dw_box_pack_start(buttonbox, nobutton, 50, 30, TRUE, FALSE, 2); +/* delete me */dw_window_set_color(buttonbox, DW_CLR_BLACK, DW_CLR_WHITE); dwwait = dw_dialog_new((void *)entrywindow); - dw_signal_connect(yesbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_yes_func), (void *)dwwait); - dw_signal_connect(nobutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_no_func), (void *)dwwait); +/* which buttons ? */ + if(flags & DW_MB_OK) + { + okbutton = dw_button_new("Ok", 1001L); + dw_box_pack_start(buttonbox, okbutton, 50, 30, TRUE, FALSE, 2); + dw_signal_connect(okbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_ok_func), (void *)dwwait); + } + else if(flags & DW_MB_OKCANCEL) + { + okbutton = dw_button_new("Ok", 1001L); + dw_box_pack_start(buttonbox, okbutton, 50, 30, TRUE, FALSE, 2); + dw_signal_connect(okbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_ok_func), (void *)dwwait); + cancelbutton = dw_button_new("Cancel", 1002L); + dw_box_pack_start(buttonbox, cancelbutton, 50, 30, TRUE, FALSE, 2); + dw_signal_connect(cancelbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_cancel_func), (void *)dwwait); + } + else if(flags & DW_MB_YESNO) + { + yesbutton = dw_button_new("Yes", 1001L); + dw_box_pack_start(buttonbox, yesbutton, 50, 30, TRUE, FALSE, 2); + dw_signal_connect(yesbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_yes_func), (void *)dwwait); + nobutton = dw_button_new("No", 1002L); + dw_box_pack_start(buttonbox, nobutton, 50, 30, TRUE, FALSE, 2); + dw_signal_connect(nobutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_no_func), (void *)dwwait); + } + else if(flags & DW_MB_YESNOCANCEL) + { + yesbutton = dw_button_new("Yes", 1001L); + dw_box_pack_start(buttonbox, yesbutton, 50, 30, TRUE, FALSE, 2); + dw_signal_connect(yesbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_yes_func), (void *)dwwait); + nobutton = dw_button_new("No", 1002L); + dw_box_pack_start(buttonbox, nobutton, 50, 30, TRUE, FALSE, 2); + dw_signal_connect(nobutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_no_func), (void *)dwwait); + cancelbutton = dw_button_new("Cancel", 1003L); + dw_box_pack_start(buttonbox, cancelbutton, 50, 30, TRUE, FALSE, 2); + dw_signal_connect(cancelbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_cancel_func), (void *)dwwait); + } x = (dw_screen_width() - 220)/2; y = (dw_screen_height() - 110)/2; diff -r 255a31a3a1f5 -r a7a561103eac os2/dw.c --- a/os2/dw.c Fri May 09 12:52:38 2003 +0000 +++ b/os2/dw.c Fri May 09 12:54:51 2003 +0000 @@ -3276,36 +3276,30 @@ * Displays a Message Box with given text and title.. * Parameters: * title: The title of the message box. + * flags: flags to indicate buttons and icon * format: printf style format string. * ...: Additional variables for use in the format. */ -int API dw_messagebox(char *title, char *format, ...) +int API dw_messagebox(char *title, int flags, char *format, ...) { va_list args; char outbuf[1024]; + int rc; va_start(args, format); vsprintf(outbuf, format, args); va_end(args); - WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, outbuf, title, 0, MB_OK | MB_INFORMATION | MB_MOVEABLE); - - return strlen(outbuf); -} - -/* - * Displays a Message Box with given text and title.. - * Parameters: - * title: The title of the message box. - * text: The text to display in the box. - * Returns: - * True if YES False of NO. - */ -int API dw_yesno(char *title, char *text) -{ - if(WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, text, title, 0, MB_YESNO | MB_INFORMATION | MB_MOVEABLE | MB_SYSTEMMODAL)==MBID_YES) - return TRUE; - return FALSE; + rc = WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, outbuf, title, 0, flags | MB_MOVEABLE | MB_SYSTEMMODAL); + if(rc == MBID_OK) + return DW_MB_RETURN_OK; + else if(rc == MBID_YES) + return DW_MB_RETURN_YES; + else if(rc == MBID_NO) + return DW_MB_RETURN_NO; + else if(rc == MBID_CANCEL) + return DW_MB_RETURN_CANCEL; + else return 0; } /* diff -r 255a31a3a1f5 -r a7a561103eac win/dw.c --- a/win/dw.c Fri May 09 12:52:38 2003 +0000 +++ b/win/dw.c Fri May 09 12:54:51 2003 +0000 @@ -3046,7 +3046,7 @@ if(!DW_HWND_OBJECT) { - dw_messagebox("Dynamic Windows", "Could not initialize the object window. error code %d", GetLastError()); + dw_messagebox("Dynamic Windows", DW_MB_OK|DW_MB_ERROR, "Could not initialize the object window. error code %d", GetLastError()); exit(1); } @@ -3203,33 +3203,26 @@ * format: printf style format string. * ...: Additional variables for use in the format. */ -int API dw_messagebox(char *title, char *format, ...) +int API dw_messagebox(char *title, int flags, char *format, ...) { va_list args; char outbuf[256]; + int rc; va_start(args, format); vsprintf(outbuf, format, args); va_end(args); - MessageBox(HWND_DESKTOP, outbuf, title, MB_OK); - - return strlen(outbuf); -} - -/* - * Displays a Message Box with given text and title.. - * Parameters: - * title: The title of the message box. - * text: The text to display in the box. - * Returns: - * True if YES False of NO. - */ -int API dw_yesno(char *title, char *text) -{ - if(MessageBox(HWND_DESKTOP, text, title, MB_YESNO) == IDYES) - return TRUE; - return FALSE; + rc = MessageBox(HWND_DESKTOP, outbuf, title, flags); + if(rc == IDOK) + return DW_MB_RETURN_OK; + else if(rc == IDYES) + return DW_MB_RETURN_YES; + else if(rc == IDNO) + return DW_MB_RETURN_NO; + else if(rc == IDCANCEL) + return DW_MB_RETURN_CANCEL; + else return 0; } /* @@ -3535,6 +3528,13 @@ */ void API dw_window_pointer(HWND handle, int pointertype) { +/* + if(pointertype == DW_POINTER_ARROW) + SetClassLong( handle, GCL_HCURSOR, LoadCursor( NULL, IDC_ARROW)); + else if(pointertype == DW_POINTER_CLOCK) + SetClassLong( handle, GCL_HCURSOR, LoadCursor( NULL, IDC_WAIT)); + else +*/ SetCursor(pointertype < 65536 ? LoadCursor(NULL, MAKEINTRESOURCE(pointertype)) : (HCURSOR)pointertype); }