Mercurial > dwindows
comparison gtk/dw.c @ 399:a7a561103eac
Add flags parameter to dw_messagebox() to specify buttons and icon displayed.
Remove dw_yesno(); now superfluous.
author | mhessling@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 09 May 2003 12:54:51 +0000 |
parents | 5326544ab2ec |
children | 306ce9765a61 |
comparison
equal
deleted
inserted
replaced
398:255a31a3a1f5 | 399:a7a561103eac |
---|---|
22 #include <gdk_imlib.h> | 22 #include <gdk_imlib.h> |
23 #endif | 23 #endif |
24 #if GTK_MAJOR_VERSION > 1 | 24 #if GTK_MAJOR_VERSION > 1 |
25 #include <gdk-pixbuf/gdk-pixbuf.h> | 25 #include <gdk-pixbuf/gdk-pixbuf.h> |
26 #endif | 26 #endif |
27 | |
28 #include "messagebox_error.xpm" | |
29 #include "messagebox_warning.xpm" | |
30 #include "messagebox_information.xpm" | |
31 #include "messagebox_question.xpm" | |
27 | 32 |
28 /* These are used for resource management */ | 33 /* These are used for resource management */ |
29 #if defined(DW_RESOURCES) && !defined(BUILD_DLL) | 34 #if defined(DW_RESOURCES) && !defined(BUILD_DLL) |
30 extern DWResources _resources; | 35 extern DWResources _resources; |
31 #endif | 36 #endif |
1070 | 1075 |
1071 if(!dwwait) | 1076 if(!dwwait) |
1072 return FALSE; | 1077 return FALSE; |
1073 | 1078 |
1074 dw_window_destroy((HWND)dwwait->data); | 1079 dw_window_destroy((HWND)dwwait->data); |
1075 dw_dialog_dismiss((DWDialog *)data, (void *)0); | 1080 dw_dialog_dismiss((DWDialog *)data, (void *)DW_MB_RETURN_OK); |
1076 return FALSE; | 1081 return FALSE; |
1077 } | 1082 } |
1078 | 1083 |
1084 int _dw_yes_func(HWND window, void *data) | |
1085 { | |
1086 DWDialog *dwwait = (DWDialog *)data; | |
1087 | |
1088 if(!dwwait) | |
1089 return FALSE; | |
1090 | |
1091 dw_window_destroy((HWND)dwwait->data); | |
1092 dw_dialog_dismiss((DWDialog *)data, (void *)DW_MB_RETURN_YES); | |
1093 return FALSE; | |
1094 } | |
1095 | |
1096 int _dw_no_func(HWND window, void *data) | |
1097 { | |
1098 DWDialog *dwwait = (DWDialog *)data; | |
1099 | |
1100 if(!dwwait) | |
1101 return FALSE; | |
1102 | |
1103 dw_window_destroy((HWND)dwwait->data); | |
1104 dw_dialog_dismiss((DWDialog *)data, (void *)DW_MB_RETURN_NO); | |
1105 return FALSE; | |
1106 } | |
1107 | |
1108 int _dw_cancel_func(HWND window, void *data) | |
1109 { | |
1110 DWDialog *dwwait = (DWDialog *)data; | |
1111 | |
1112 if(!dwwait) | |
1113 return FALSE; | |
1114 | |
1115 dw_window_destroy((HWND)dwwait->data); | |
1116 dw_dialog_dismiss((DWDialog *)data, (void *)DW_MB_RETURN_CANCEL); | |
1117 return FALSE; | |
1118 } | |
1119 | |
1079 /* | 1120 /* |
1080 * Displays a Message Box with given text and title.. | 1121 * Displays a Message Box with given text and title.. |
1081 * Parameters: | 1122 * Parameters: |
1082 * title: The title of the message box. | 1123 * title: The title of the message box. |
1124 * flags: Defines buttons and icons to display | |
1083 * format: printf style format string. | 1125 * format: printf style format string. |
1084 * ...: Additional variables for use in the format. | 1126 * ...: Additional variables for use in the format. |
1085 */ | 1127 */ |
1086 int dw_messagebox(char *title, char *format, ...) | 1128 int dw_messagebox(char *title, int flags, char *format, ...) |
1087 { | 1129 { |
1088 HWND entrywindow, mainbox, okbutton, buttonbox, stext; | 1130 HWND entrywindow, texttargetbox, imagetextbox, mainbox, okbutton, nobutton, yesbutton, cancelbutton, buttonbox, stext; |
1089 ULONG flStyle = DW_FCF_TITLEBAR | DW_FCF_SHELLPOSITION | DW_FCF_DLGBORDER; | 1131 ULONG flStyle = DW_FCF_TITLEBAR | DW_FCF_SHELLPOSITION | DW_FCF_DLGBORDER; |
1090 DWDialog *dwwait; | 1132 DWDialog *dwwait; |
1091 va_list args; | 1133 va_list args; |
1092 char outbuf[256]; | 1134 char outbuf[256]; |
1135 char **xpm_data = NULL; | |
1093 int x, y; | 1136 int x, y; |
1094 | 1137 |
1095 va_start(args, format); | 1138 va_start(args, format); |
1096 vsprintf(outbuf, format, args); | 1139 vsprintf(outbuf, format, args); |
1097 va_end(args); | 1140 va_end(args); |
1098 | 1141 |
1099 entrywindow = dw_window_new(HWND_DESKTOP, title, flStyle); | 1142 entrywindow = dw_window_new(HWND_DESKTOP, title, flStyle); |
1100 mainbox = dw_box_new(DW_VERT, 10); | 1143 mainbox = dw_box_new(DW_VERT, 10); |
1101 dw_box_pack_start(entrywindow, mainbox, 0, 0, TRUE, TRUE, 0); | 1144 dw_box_pack_start(entrywindow, mainbox, 0, 0, TRUE, TRUE, 0); |
1102 | 1145 /* delete me */dw_window_set_color(mainbox, DW_CLR_BLACK, DW_CLR_RED); |
1103 /* Archive Name */ | 1146 |
1147 /* determine if an icon is to be used - if so we need another HORZ box */ | |
1148 if((flags & DW_MB_ERROR) | (flags & DW_MB_WARNING) | (flags & DW_MB_INFORMATION) | (flags & DW_MB_QUESTION)) | |
1149 { | |
1150 imagetextbox = dw_box_new(DW_HORZ, 101); | |
1151 dw_box_pack_start(mainbox, imagetextbox, 0, 0, TRUE, TRUE, 2); | |
1152 texttargetbox = imagetextbox; | |
1153 /* delete me */dw_window_set_color(imagetextbox, DW_CLR_BLACK, DW_CLR_YELLOW); | |
1154 } | |
1155 else | |
1156 { | |
1157 imagetextbox = NULL; | |
1158 texttargetbox = mainbox; | |
1159 } | |
1160 | |
1161 if(flags & DW_MB_ERROR) | |
1162 xpm_data = (char **)_dw_messagebox_error; | |
1163 else if(flags & DW_MB_WARNING) | |
1164 xpm_data = (char **)_dw_messagebox_warning; | |
1165 else if(flags & DW_MB_INFORMATION) | |
1166 xpm_data = (char **)_dw_messagebox_information; | |
1167 else if(flags & DW_MB_QUESTION) | |
1168 xpm_data = (char **)_dw_messagebox_question; | |
1169 | |
1170 if(texttargetbox == imagetextbox) | |
1171 { | |
1172 GdkPixmap *icon_pixmap = NULL; | |
1173 GdkBitmap *bitmap = NULL; | |
1174 HWND handle = dw_bitmap_new( 100 ); | |
1175 #if GTK_MAJOR_VERSION > 1 | |
1176 GdkPixbuf *icon_pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)xpm_data); | |
1177 | |
1178 gdk_pixbuf_render_pixmap_and_mask(icon_pixbuf, &icon_pixmap, &bitmap, 1); | |
1179 g_object_unref(icon_pixbuf); | |
1180 #elif defined(USE_IMLIB) | |
1181 gdk_imlib_data_to_pixmap((char **)xpm_data, &icon_pixmap, &bitmap); | |
1182 #else | |
1183 icon_pixmap = gdk_pixmap_create_from_xpm_d(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], (char **)xpm_data); | |
1184 #endif | |
1185 | |
1186 #if GTK_MAJOR_VERSION > 1 | |
1187 gtk_image_set_from_pixmap(GTK_IMAGE(handle), icon_pixmap, bitmap); | |
1188 #else | |
1189 gtk_pixmap_set(GTK_PIXMAP(handle), icon_pixmap, bitmap); | |
1190 #endif | |
1191 | |
1192 dw_box_pack_start( texttargetbox, handle, 32, 32, FALSE, FALSE, 2); | |
1193 } | |
1194 | |
1195 /* Create text */ | |
1104 stext = dw_text_new(outbuf, 0); | 1196 stext = dw_text_new(outbuf, 0); |
1105 dw_window_set_style(stext, DW_DT_WORDBREAK, DW_DT_WORDBREAK); | 1197 dw_window_set_style(stext, DW_DT_WORDBREAK, DW_DT_WORDBREAK); |
1106 | 1198 dw_box_pack_start(texttargetbox, stext, 205, 50, TRUE, TRUE, 2); |
1107 dw_box_pack_start(mainbox, stext, 205, 50, TRUE, TRUE, 2); | |
1108 | 1199 |
1109 /* Buttons */ | 1200 /* Buttons */ |
1110 buttonbox = dw_box_new(DW_HORZ, 10); | 1201 buttonbox = dw_box_new(DW_HORZ, 10); |
1111 | 1202 |
1112 dw_box_pack_start(mainbox, buttonbox, 0, 0, TRUE, FALSE, 0); | 1203 dw_box_pack_start(mainbox, buttonbox, 0, 0, TRUE, FALSE, 0); |
1113 | 1204 /* delete me */dw_window_set_color(buttonbox, DW_CLR_BLACK, DW_CLR_WHITE); |
1114 okbutton = dw_button_new("Ok", 1001L); | |
1115 | |
1116 dw_box_pack_start(buttonbox, okbutton, 50, 30, TRUE, FALSE, 2); | |
1117 | 1205 |
1118 dwwait = dw_dialog_new((void *)entrywindow); | 1206 dwwait = dw_dialog_new((void *)entrywindow); |
1119 | 1207 |
1120 dw_signal_connect(okbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_ok_func), (void *)dwwait); | 1208 /* which buttons ? */ |
1121 | 1209 if(flags & DW_MB_OK) |
1122 x = (dw_screen_width() - 220)/2; | 1210 { |
1123 y = (dw_screen_height() - 110)/2; | 1211 okbutton = dw_button_new("Ok", 1001L); |
1124 | 1212 dw_box_pack_start(buttonbox, okbutton, 50, 30, TRUE, FALSE, 2); |
1125 dw_window_set_pos_size(entrywindow, x, y, 220, 110); | 1213 dw_signal_connect(okbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_ok_func), (void *)dwwait); |
1126 | 1214 } |
1127 dw_window_show(entrywindow); | 1215 else if(flags & DW_MB_OKCANCEL) |
1128 | 1216 { |
1129 dw_dialog_wait(dwwait); | 1217 okbutton = dw_button_new("Ok", 1001L); |
1130 | 1218 dw_box_pack_start(buttonbox, okbutton, 50, 30, TRUE, FALSE, 2); |
1131 return strlen(outbuf); | 1219 dw_signal_connect(okbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_ok_func), (void *)dwwait); |
1132 } | 1220 cancelbutton = dw_button_new("Cancel", 1002L); |
1133 | 1221 dw_box_pack_start(buttonbox, cancelbutton, 50, 30, TRUE, FALSE, 2); |
1134 int _dw_yes_func(HWND window, void *data) | 1222 dw_signal_connect(cancelbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_cancel_func), (void *)dwwait); |
1135 { | 1223 } |
1136 DWDialog *dwwait = (DWDialog *)data; | 1224 else if(flags & DW_MB_YESNO) |
1137 | 1225 { |
1138 if(!dwwait) | 1226 yesbutton = dw_button_new("Yes", 1001L); |
1139 return FALSE; | 1227 dw_box_pack_start(buttonbox, yesbutton, 50, 30, TRUE, FALSE, 2); |
1140 | 1228 dw_signal_connect(yesbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_yes_func), (void *)dwwait); |
1141 dw_window_destroy((HWND)dwwait->data); | 1229 nobutton = dw_button_new("No", 1002L); |
1142 dw_dialog_dismiss((DWDialog *)data, (void *)1); | 1230 dw_box_pack_start(buttonbox, nobutton, 50, 30, TRUE, FALSE, 2); |
1143 return FALSE; | 1231 dw_signal_connect(nobutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_no_func), (void *)dwwait); |
1144 } | 1232 } |
1145 | 1233 else if(flags & DW_MB_YESNOCANCEL) |
1146 int _dw_no_func(HWND window, void *data) | 1234 { |
1147 { | 1235 yesbutton = dw_button_new("Yes", 1001L); |
1148 DWDialog *dwwait = (DWDialog *)data; | 1236 dw_box_pack_start(buttonbox, yesbutton, 50, 30, TRUE, FALSE, 2); |
1149 | 1237 dw_signal_connect(yesbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_yes_func), (void *)dwwait); |
1150 if(!dwwait) | 1238 nobutton = dw_button_new("No", 1002L); |
1151 return FALSE; | 1239 dw_box_pack_start(buttonbox, nobutton, 50, 30, TRUE, FALSE, 2); |
1152 | 1240 dw_signal_connect(nobutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_no_func), (void *)dwwait); |
1153 dw_window_destroy((HWND)dwwait->data); | 1241 cancelbutton = dw_button_new("Cancel", 1003L); |
1154 dw_dialog_dismiss((DWDialog *)data, (void *)0); | 1242 dw_box_pack_start(buttonbox, cancelbutton, 50, 30, TRUE, FALSE, 2); |
1155 return FALSE; | 1243 dw_signal_connect(cancelbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_cancel_func), (void *)dwwait); |
1156 } | 1244 } |
1157 | |
1158 /* | |
1159 * Displays a Message Box with given text and title.. | |
1160 * Parameters: | |
1161 * title: The title of the message box. | |
1162 * text: The text to display in the box. | |
1163 * Returns: | |
1164 * True if YES False of NO. | |
1165 */ | |
1166 int dw_yesno(char *title, char *text) | |
1167 { | |
1168 HWND entrywindow, mainbox, nobutton, yesbutton, buttonbox, stext; | |
1169 ULONG flStyle = DW_FCF_TITLEBAR | DW_FCF_SHELLPOSITION | DW_FCF_DLGBORDER; | |
1170 DWDialog *dwwait; | |
1171 int x, y; | |
1172 | |
1173 entrywindow = dw_window_new(HWND_DESKTOP, title, flStyle); | |
1174 | |
1175 mainbox = dw_box_new(DW_VERT, 10); | |
1176 | |
1177 dw_box_pack_start(entrywindow, mainbox, 0, 0, TRUE, TRUE, 0); | |
1178 | |
1179 /* Archive Name */ | |
1180 stext = dw_text_new(text, 0); | |
1181 dw_window_set_style(stext, DW_DT_WORDBREAK, DW_DT_WORDBREAK); | |
1182 | |
1183 dw_box_pack_start(mainbox, stext, 205, 50, TRUE, TRUE, 2); | |
1184 | |
1185 /* Buttons */ | |
1186 buttonbox = dw_box_new(DW_HORZ, 10); | |
1187 | |
1188 dw_box_pack_start(mainbox, buttonbox, 0, 0, TRUE, FALSE, 0); | |
1189 | |
1190 yesbutton = dw_button_new("Yes", 1001L); | |
1191 | |
1192 dw_box_pack_start(buttonbox, yesbutton, 50, 30, TRUE, FALSE, 2); | |
1193 | |
1194 nobutton = dw_button_new("No", 1002L); | |
1195 | |
1196 dw_box_pack_start(buttonbox, nobutton, 50, 30, TRUE, FALSE, 2); | |
1197 | |
1198 dwwait = dw_dialog_new((void *)entrywindow); | |
1199 | |
1200 dw_signal_connect(yesbutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_yes_func), (void *)dwwait); | |
1201 dw_signal_connect(nobutton, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(_dw_no_func), (void *)dwwait); | |
1202 | 1245 |
1203 x = (dw_screen_width() - 220)/2; | 1246 x = (dw_screen_width() - 220)/2; |
1204 y = (dw_screen_height() - 110)/2; | 1247 y = (dw_screen_height() - 110)/2; |
1205 | 1248 |
1206 dw_window_set_pos_size(entrywindow, x, y, 220, 110); | 1249 dw_window_set_pos_size(entrywindow, x, y, 220, 110); |