aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gtk/simple_dialog.c98
-rw-r--r--simple_dialog.h22
2 files changed, 84 insertions, 36 deletions
diff --git a/gtk/simple_dialog.c b/gtk/simple_dialog.c
index 8e601e4787..6ec1740bbd 100644
--- a/gtk/simple_dialog.c
+++ b/gtk/simple_dialog.c
@@ -1,7 +1,7 @@
/* simple_dialog.c
* Simple message dialog box routines.
*
- * $Id: simple_dialog.c,v 1.16 2004/01/21 21:19:34 ulfl Exp $
+ * $Id: simple_dialog.c,v 1.17 2004/01/29 23:07:17 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -45,7 +45,9 @@
static void simple_dialog_cancel_cb(GtkWidget *, gpointer);
-static const gchar bm_key[] = "button mask";
+#define CALLBACK_FCT_KEY "ESD_Callback_Fct"
+#define CALLBACK_BTN_KEY "ESD_Callback_Btn"
+#define CALLBACK_DATA_KEY "ESD_Callback_Data"
/* Simple dialog function - Displays a dialog box with the supplied message
* text.
@@ -61,10 +63,10 @@ static const gchar bm_key[] = "button mask";
*/
#define ESD_MAX_MSG_LEN 2048
-void
-simple_dialog(gint type, gint *btn_mask, gchar *msg_format, ...) {
+gpointer
+simple_dialog(gint type, gint btn_mask, gchar *msg_format, ...) {
GtkWidget *win, *main_vb, *top_hb, *type_pm, *msg_label,
- *bbox, *ok_bt, *cancel_bt;
+ *bbox, *bt;
GdkPixmap *pixmap;
GdkBitmap *mask;
GtkStyle *style;
@@ -83,6 +85,11 @@ simple_dialog(gint type, gint *btn_mask, gchar *msg_format, ...) {
icon = eexcl3d64_xpm;
win = dlg_window_new("Ethereal: Error");
break;
+ case ESD_TYPE_QUEST:
+ /* XXX: we need a question mark here */
+ icon = eexcl3d64_xpm;
+ win = dlg_window_new("Ethereal: Question");
+ break;
case ESD_TYPE_INFO :
default :
icon = eicon3d64_xpm;
@@ -95,8 +102,6 @@ simple_dialog(gint type, gint *btn_mask, gchar *msg_format, ...) {
gtk_container_border_width(GTK_CONTAINER(win), 7);
- OBJECT_SET_DATA(win, bm_key, btn_mask);
-
/* Container for our rows */
main_vb = gtk_vbox_new(FALSE, 5);
gtk_container_border_width(GTK_CONTAINER(main_vb), 5);
@@ -128,44 +133,77 @@ simple_dialog(gint type, gint *btn_mask, gchar *msg_format, ...) {
gtk_widget_show(msg_label);
/* Button row */
- if (btn_mask && *btn_mask == ESD_BTN_CANCEL) {
- bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
- } else {
- bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
+ switch(btn_mask) {
+ case(0):
+ case(ESD_BTN_OK):
+ bbox = dlg_button_row_new(GTK_STOCK_OK, NULL);
+ break;
+ case(ESD_BTN_OK | ESD_BTN_CANCEL):
+ bbox = dlg_button_row_new(GTK_STOCK_OK, GTK_STOCK_CANCEL, NULL);
+ break;
+ case(ESD_BTN_YES | ESD_BTN_NO | ESD_BTN_CANCEL):
+ bbox = dlg_button_row_new(GTK_STOCK_YES, GTK_STOCK_NO, GTK_STOCK_CANCEL, NULL);
+ break;
+ default:
+ g_assert_not_reached();
}
gtk_container_add(GTK_CONTAINER(main_vb), bbox);
gtk_widget_show(bbox);
- ok_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
- SIGNAL_CONNECT_OBJECT(ok_bt, "clicked", gtk_widget_destroy, win);
- gtk_widget_grab_default(ok_bt);
-
- if (btn_mask && *btn_mask == ESD_BTN_CANCEL) {
- cancel_bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
- SIGNAL_CONNECT(cancel_bt, "clicked", simple_dialog_cancel_cb, win);
-
+ bt = OBJECT_GET_DATA(bbox, GTK_STOCK_OK);
+ if(bt) {
+ OBJECT_SET_DATA(bt, CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_OK));
+ SIGNAL_CONNECT(bt, "clicked", simple_dialog_cancel_cb, win);
+ gtk_widget_grab_default(bt);
/* Catch the "key_press_event" signal in the window, so that we can catch
- the ESC key being pressed and act as if the "Cancel" button had
+ the ESC key being pressed and act as if the "OK" button had
been selected. */
- dlg_set_cancel(win, cancel_bt);
- } else {
+ dlg_set_cancel(win, bt);
+ }
+
+ bt = OBJECT_GET_DATA(bbox, GTK_STOCK_YES);
+ if(bt) {
+ OBJECT_SET_DATA(bt, CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_YES));
+ SIGNAL_CONNECT(bt, "clicked", simple_dialog_cancel_cb, win);
+ }
+
+ bt = OBJECT_GET_DATA(bbox, GTK_STOCK_NO);
+ if(bt) {
+ OBJECT_SET_DATA(bt, CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_NO));
+ SIGNAL_CONNECT(bt, "clicked", simple_dialog_cancel_cb, win);
+ }
+
+ bt = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL);
+ if(bt) {
+ OBJECT_SET_DATA(bt, CALLBACK_BTN_KEY, GINT_TO_POINTER(ESD_BTN_CANCEL));
+ SIGNAL_CONNECT(bt, "clicked", simple_dialog_cancel_cb, win);
/* Catch the "key_press_event" signal in the window, so that we can catch
the ESC key being pressed and act as if the "OK" button had
been selected. */
- dlg_set_cancel(win, ok_bt);
+ dlg_set_cancel(win, bt);
+ gtk_widget_grab_default(bt);
}
- if (btn_mask)
- *btn_mask = ESD_BTN_OK;
-
gtk_widget_show(win);
+
+ return win;
}
static void
-simple_dialog_cancel_cb(GtkWidget *w _U_, gpointer win) {
- gint *btn_mask = (gint *) OBJECT_GET_DATA(win, bm_key);
+simple_dialog_cancel_cb(GtkWidget *w, gpointer win) {
+ gint button = GPOINTER_TO_INT( OBJECT_GET_DATA(w, CALLBACK_BTN_KEY));
+ simple_dialog_cb_t callback_fct = OBJECT_GET_DATA(win, CALLBACK_FCT_KEY);
+ gpointer data = OBJECT_GET_DATA(win, CALLBACK_DATA_KEY);
- if (btn_mask)
- *btn_mask = ESD_BTN_CANCEL;
gtk_widget_destroy(GTK_WIDGET(win));
+
+ if (callback_fct)
+ (callback_fct) (win, button, data);
+}
+
+void simple_dialog_set_cb(gpointer dialog, simple_dialog_cb_t callback_fct, gpointer data)
+{
+
+ OBJECT_SET_DATA(GTK_WIDGET(dialog), CALLBACK_FCT_KEY, callback_fct);
+ OBJECT_SET_DATA(GTK_WIDGET(dialog), CALLBACK_DATA_KEY, data);
}
diff --git a/simple_dialog.h b/simple_dialog.h
index 4346eaa973..c57ddb2ea9 100644
--- a/simple_dialog.h
+++ b/simple_dialog.h
@@ -2,7 +2,7 @@
* Definitions for dialog box routines with toolkit-independent APIs but
* toolkit-dependent implementations.
*
- * $Id: simple_dialog.h,v 1.4 2002/08/28 21:00:41 jmayer Exp $
+ * $Id: simple_dialog.h,v 1.5 2004/01/29 23:07:17 ulfl Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -35,22 +35,32 @@ extern "C" {
#define ESD_TYPE_INFO 0x00
#define ESD_TYPE_WARN 0x01
#define ESD_TYPE_CRIT 0x02
+#define ESD_TYPE_QUEST 0x03
/* Flag to be ORed with the dialog type, to specify that the dialog is
to be modal. */
-#define ESD_TYPE_MODAL 0x04
+#define ESD_TYPE_MODAL 0x10
/* Which buttons to display. */
-#define ESD_BTN_OK 0
-#define ESD_BTN_CANCEL 1
+#define ESD_BTN_OK 0x01
+#define ESD_BTN_CANCEL 0x02
+#define ESD_BTN_YES 0x04
+#define ESD_BTN_NO 0x08
+/* show a simple dialog */
#if __GNUC__ >= 2
-void simple_dialog(gint, gint *, gchar *, ...)
+extern gpointer simple_dialog(gint type, gint btn_mask, gchar *msg_format, ...)
__attribute__((format (printf, 3, 4)));
#else
-void simple_dialog(gint, gint *, gchar *, ...);
+extern gpointer simple_dialog(gint type, gint btn_mask, gchar *msg_format, ...);
#endif
+/* callback function type */
+typedef void (* simple_dialog_cb_t) (gpointer dialog, gint btn, gpointer data);
+
+/* set the callback function, which has to be called when a button was pressed */
+extern void simple_dialog_set_cb(gpointer dialog, simple_dialog_cb_t callback_fct, gpointer data);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */