diff options
author | Luis Ontanon <luis.ontanon@gmail.com> | 2006-02-06 01:27:05 +0000 |
---|---|---|
committer | Luis Ontanon <luis.ontanon@gmail.com> | 2006-02-06 01:27:05 +0000 |
commit | fc89f6d4391530b2a36380b6d4136f9caa62fc80 (patch) | |
tree | e2174cef1a7d5123102f5858e0685594f3e4a3a6 /gtk | |
parent | 6a77df11b1b2d6602e39140b13acc31d986cc11f (diff) | |
download | wireshark-fc89f6d4391530b2a36380b6d4136f9caa62fc80.tar.gz |
The simple dialog
svn path=/trunk/; revision=17172
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/funnel_stat.c | 167 |
1 files changed, 144 insertions, 23 deletions
diff --git a/gtk/funnel_stat.c b/gtk/funnel_stat.c index d115d66d39..850bd52f03 100644 --- a/gtk/funnel_stat.c +++ b/gtk/funnel_stat.c @@ -4,7 +4,7 @@ * EPAN's funneled GUI mini-API * * (c) 2006, Luis E. Garcia Ontanon <luis.ontanon@gmail.com> - * + * * $Id$ * * Ethereal - Network traffic analyzer @@ -26,6 +26,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* + * Most of the code here has been harvested from other ethereal gtk modules. + * most from prefs_dlg.c and about_dlg.c + */ + #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -46,12 +51,14 @@ #include "dlg_utils.h" #include "../file.h" #include "../globals.h" -#include "filter_dlg.h" #include "../stat_menu.h" #include "../tap_dfilter_dlg.h" #include "font_utils.h" #include "../stat_menu.h" #include "gui_stat_menu.h" +#include <epan/prefs.h> +#include "column_prefs.h" +#include "prefs_dlg.h" #include "gtkglobals.h" @@ -74,9 +81,7 @@ struct _funnel_node_t { void* dummy; }; -struct _funnel_dialog_t { - void* dummy; -}; +static gboolean text_window_delete_event_cb(GtkWidget*, GdkEvent*, gpointer); static void text_window_cancel_button_cb(GtkWidget *bt _U_, gpointer data) { funnel_text_window_t* tw = data; @@ -84,7 +89,8 @@ static void text_window_cancel_button_cb(GtkWidget *bt _U_, gpointer data) { window_destroy(GTK_WIDGET(tw->win)); tw->win = NULL; - tw->close_cb(tw->close_data); + if (tw->close_cb) + tw->close_cb(tw->close_data); } static void unref_text_win_cancel_bt_cb(GtkWidget *bt _U_, gpointer data) { @@ -93,17 +99,38 @@ static void unref_text_win_cancel_bt_cb(GtkWidget *bt _U_, gpointer data) { window_destroy(GTK_WIDGET(tw->win)); tw->win = NULL; - tw->close_cb(tw->close_data); + if (tw->close_cb) + tw->close_cb(tw->close_data); + + g_free(tw); + +} + +static gboolean text_window_unref_del_event_cb(GtkWidget *win _U_, GdkEvent *event _U_, gpointer user_data) { + funnel_text_window_t* tw = user_data; + + window_destroy(GTK_WIDGET(tw->win)); + tw->win = NULL; + + if (tw->close_cb) + tw->close_cb(tw->close_data); g_free(tw); + return TRUE; + } -static gboolean text_window_delete_event_cb(GtkWidget *win, GdkEvent *event _U_, gpointer user_data) +static gboolean text_window_delete_event_cb(GtkWidget *win _U_, GdkEvent *event _U_, gpointer user_data) { funnel_text_window_t* tw = user_data; - window_destroy(win); - tw->close_cb(tw->close_data); + + window_destroy(GTK_WIDGET(tw->win)); + tw->win = NULL; + + if (tw->close_cb) + tw->close_cb(tw->close_data); + return TRUE; } @@ -111,12 +138,15 @@ static funnel_text_window_t* new_text_window(const gchar* title) { funnel_text_window_t* tw = g_malloc(sizeof(funnel_text_window_t)); GtkWidget *txt_scrollw, *main_vb, *bbox; + tw->close_cb = NULL; + tw->close_data = NULL; + tw->win = window_new(GTK_WINDOW_TOPLEVEL,title); SIGNAL_CONNECT(tw->win, "delete-event", text_window_delete_event_cb, tw); txt_scrollw = scrolled_window_new(NULL, NULL); main_vb = gtk_vbox_new(FALSE, 3); - gtk_container_border_width(GTK_CONTAINER(main_vb), 12); + gtk_container_border_width(GTK_CONTAINER(main_vb), 6); gtk_container_add(GTK_CONTAINER(tw->win), main_vb); gtk_container_add(GTK_CONTAINER(main_vb), txt_scrollw); @@ -138,12 +168,9 @@ static funnel_text_window_t* new_text_window(const gchar* title) { gtk_text_view_set_editable(GTK_TEXT_VIEW(tw->txt), FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(tw->txt), GTK_WRAP_WORD); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(tw->txt), FALSE); - /* XXX: there seems to be no way to add a small border *around* the whole text, - * so the text will be "bump" against the edges. - * the following is only working for left and right edges, - * there is no such thing for top and bottom :-( */ -/* gtk_text_view_set_left_margin(GTK_TEXT_VIEW(tw->txt), 4); - gtk_text_view_set_right_margin(GTK_TEXT_VIEW(tw->txt), 4);*/ + + gtk_text_view_set_left_margin(GTK_TEXT_VIEW(tw->txt), 4); + gtk_text_view_set_right_margin(GTK_TEXT_VIEW(tw->txt), 4); #endif @@ -252,17 +279,13 @@ static void text_window_set_close_cb(funnel_text_window_t* tw, text_win_close_c } static void text_window_destroy(funnel_text_window_t* tw) { - /* - * XXX: This way Lua's garbage collector might destroy the window. - * Here we need to change the callbacks for closing the window so that - * the window can live after Lua has destroyed it and we do not leak the window object. - */ if (tw->win) { /* * the window is still there and its callbacks refer to this data structure * we need to change the callback so that they free tw. */ SIGNAL_CONNECT(tw->bt_close, "clicked", unref_text_win_cancel_bt_cb, tw); + SIGNAL_CONNECT(tw->win, "delete-event", text_window_unref_del_event_cb, tw); } else { /* * we have no window anymore a human user closed @@ -272,6 +295,102 @@ static void text_window_destroy(funnel_text_window_t* tw) { } } + +struct _funnel_dlg_data { + GtkWidget* win; + GPtrArray* entries; + funnel_dlg_cb_t dlg_cb; + void* data; +}; + +static gboolean funnel_dlg_cb(GtkWidget *win _U_, gpointer user_data) +{ + struct _funnel_dlg_data* dd = user_data; + guint i; + guint len = dd->entries->len; + GPtrArray* returns = g_ptr_array_new(); + + for(i=0; i<len; i++) { + GtkEntry* entry = g_ptr_array_index(dd->entries,i); + g_ptr_array_add(returns,g_strdup(gtk_entry_get_text(entry))); + } + + g_ptr_array_add(returns,NULL); + + if (dd->dlg_cb) + dd->dlg_cb((gchar**)returns->pdata,dd->data); + + window_destroy(GTK_WIDGET(dd->win)); + + return TRUE; +} + +static void funnel_cancel_btn_cb(GtkWidget *bt _U_, gpointer data) { + GtkWidget* win = data; + + window_destroy(GTK_WIDGET(win)); +} + +static void funnel_new_dialog(const gchar* title, + const gchar** fieldnames, + funnel_dlg_cb_t dlg_cb, + void* data) { + GtkWidget *win, *main_tb, *main_vb, *bbox, *bt_cancel, *bt_ok; + guint i; + const gchar* fieldname; + struct _funnel_dlg_data* dd = g_malloc(sizeof(struct _funnel_dlg_data)); + + dd->entries = g_ptr_array_new(); + dd->dlg_cb = dlg_cb; + dd->data = data; + + for (i=0;fieldnames[i];i++); + + win = dlg_window_new(title); + + dd->win = win; + + gtk_window_resize(GTK_WINDOW(win),400,10*(i+2)); + + main_vb = gtk_vbox_new(TRUE,5); + gtk_container_add(GTK_CONTAINER(win), main_vb); + gtk_container_border_width(GTK_CONTAINER(main_vb), 6); + + main_tb = gtk_table_new(i+1, 2, FALSE); + gtk_box_pack_start(GTK_BOX(main_vb), main_tb, FALSE, FALSE, 0); + gtk_table_set_row_spacings(GTK_TABLE(main_tb), 10); + gtk_table_set_col_spacings(GTK_TABLE(main_tb), 15); + + for (i = 0; (fieldname = fieldnames[i]) ; i++) { + GtkWidget *entry, *label; + + label = gtk_label_new(fieldname); + gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5); + gtk_table_attach_defaults(GTK_TABLE(main_tb), label, 0, 1, i+1, i + 2); + gtk_widget_show(label); + + entry = gtk_entry_new(); + g_ptr_array_add(dd->entries,entry); + gtk_table_attach_defaults(GTK_TABLE(main_tb), entry, 1, 2, i+1, i + 2); + gtk_widget_show(entry); + } + + bbox = dlg_button_row_new(GTK_STOCK_CANCEL,GTK_STOCK_OK, NULL); + gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0); + + bt_ok = OBJECT_GET_DATA(bbox, GTK_STOCK_OK); + SIGNAL_CONNECT(bt_ok, "clicked", funnel_dlg_cb, dd); + gtk_widget_grab_default(bt_ok); + + bt_cancel = OBJECT_GET_DATA(bbox, GTK_STOCK_CANCEL); + SIGNAL_CONNECT(bt_cancel, "clicked", funnel_cancel_btn_cb, win); + gtk_widget_grab_default(bt_cancel); + + gtk_widget_show(main_tb); + gtk_widget_show(main_vb); + gtk_widget_show(win); +} + static const funnel_ops_t ops = { new_text_window, text_window_set_text, @@ -280,7 +399,9 @@ static const funnel_ops_t ops = { text_window_clear, text_window_get_text, text_window_set_close_cb, - text_window_destroy + text_window_destroy, + /*...,*/ + funnel_new_dialog }; |