aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis Ontanon <luis.ontanon@gmail.com>2006-03-30 19:42:49 +0000
committerLuis Ontanon <luis.ontanon@gmail.com>2006-03-30 19:42:49 +0000
commit2e93b8b751af7a5d88aceb7e6d6f0b0520f38868 (patch)
tree659b7f9490ae93093b78eab6ad3cbf23efadceaa
parent84fb70ef42d8cedf4a74e24e26d54b8bd49e0028 (diff)
TextWindow:
- add buttons - make editable svn path=/trunk/; revision=17773
-rw-r--r--epan/funnel.h10
-rw-r--r--gtk/funnel_stat.c72
-rw-r--r--plugins/lua/elua_gui.c96
-rw-r--r--tap-funnel.c2
4 files changed, 168 insertions, 12 deletions
diff --git a/epan/funnel.h b/epan/funnel.h
index ab3428329f..9f7b37beaf 100644
--- a/epan/funnel.h
+++ b/epan/funnel.h
@@ -43,6 +43,14 @@ typedef void (*text_win_close_cb_t)(void*);
typedef void (*funnel_dlg_cb_t)(gchar** user_input, void* data);
+typedef gboolean (*funnel_bt_cb_t)(funnel_text_window_t* tw, void* data);
+
+typedef struct _funnel_bt_t {
+ funnel_text_window_t* tw;
+ funnel_bt_cb_t func;
+ void* data;
+} funnel_bt_t;
+
typedef struct _funnel_ops_t {
funnel_text_window_t* (*new_text_window)(const gchar* label);
void (*set_text)(funnel_text_window_t* win, const gchar* text);
@@ -51,7 +59,9 @@ typedef struct _funnel_ops_t {
void (*clear_text)(funnel_text_window_t* win);
const gchar* (*get_text)(funnel_text_window_t* win);
void (*set_close_cb)(funnel_text_window_t* win, text_win_close_cb_t cb, void* data);
+ void (*set_editable)(funnel_text_window_t* win, gboolean editable);
void (*destroy_text_window)(funnel_text_window_t* win);
+ void (*add_button)(funnel_text_window_t* win, funnel_bt_t* cb, const gchar* label);
#if 0
funnel_node_t* (*new_tree_window)(const gchar* title, gchar** columns);
funnel_node_t* (*add_node)(funnel_node_t* node, gchar** values);
diff --git a/gtk/funnel_stat.c b/gtk/funnel_stat.c
index 3232ffb34c..ee154210c9 100644
--- a/gtk/funnel_stat.c
+++ b/gtk/funnel_stat.c
@@ -67,6 +67,8 @@
struct _funnel_text_window_t {
GtkWidget* win;
GtkWidget* txt;
+ GtkWidget* hbox;
+ GtkWidget* button_hbox;
GtkWidget* bt_close;
text_win_close_cb_t close_cb;
void* close_data;
@@ -103,6 +105,7 @@ static void unref_text_win_cancel_bt_cb(GtkWidget *bt _U_, gpointer 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;
@@ -132,7 +135,7 @@ static gboolean text_window_delete_event_cb(GtkWidget *win _U_, GdkEvent *event
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;
+ GtkWidget *txt_scrollw, *main_vb;
tw->close_cb = NULL;
tw->close_data = NULL;
@@ -168,16 +171,29 @@ static funnel_text_window_t* new_text_window(const gchar* title) {
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
-
-
- bbox = dlg_button_row_new(GTK_STOCK_CLOSE, NULL);
- gtk_box_pack_start(GTK_BOX(main_vb), bbox, FALSE, FALSE, 0);
- tw->bt_close = OBJECT_GET_DATA(bbox, GTK_STOCK_CLOSE);
- SIGNAL_CONNECT(tw->bt_close, "clicked", text_window_cancel_button_cb, tw);
+ tw->hbox = gtk_hbox_new(FALSE, 0);
+ gtk_widget_show(tw->hbox);
+
+ tw->button_hbox = gtk_hbutton_box_new();
+ gtk_button_box_set_layout(GTK_BUTTON_BOX(tw->button_hbox), GTK_BUTTONBOX_START);
+
+ gtk_box_pack_start(GTK_BOX(tw->hbox), tw->button_hbox, TRUE, TRUE, 0);
+ gtk_widget_show(tw->button_hbox);
+
+ gtk_box_pack_start(GTK_BOX(main_vb), tw->hbox, FALSE, FALSE, 0);
+
+ tw->bt_close = gtk_button_new_with_label("Close");
+ GTK_WIDGET_SET_FLAGS(tw->bt_close, GTK_CAN_DEFAULT);
+ OBJECT_SET_DATA(tw->hbox, "Close", tw->bt_close);
+
+ gtk_box_pack_end(GTK_BOX(tw->hbox), tw->bt_close, FALSE, FALSE, 0);
+ gtk_widget_show(tw->bt_close);
+
+ SIGNAL_CONNECT(tw->bt_close, "clicked", text_window_cancel_button_cb, tw);
gtk_widget_grab_default(tw->bt_close);
- gtk_container_add(GTK_CONTAINER(txt_scrollw), tw->txt);
+ gtk_container_add(GTK_CONTAINER(txt_scrollw), tw->txt);
#if GTK_MAJOR_VERSION >= 2
gtk_window_resize(GTK_WINDOW(tw->win),400,300);
#else
@@ -322,6 +338,8 @@ static const gchar* text_window_get_text(funnel_text_window_t* tw) {
#endif
}
+
+
static void text_window_set_close_cb(funnel_text_window_t* tw, text_win_close_cb_t cb, void* data) {
tw->close_cb = cb;
tw->close_data = data;
@@ -344,6 +362,42 @@ static void text_window_destroy(funnel_text_window_t* tw) {
}
}
+static void text_window_set_editable(funnel_text_window_t* tw, gboolean editable){
+#if GTK_MAJOR_VERSION < 2
+ gtk_text_set_editable(GTK_TEXT(tw->txt), editable);
+#else
+ gtk_text_view_set_editable(GTK_TEXT_VIEW(tw->txt), editable);
+ gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(tw->txt), editable);
+#endif
+}
+
+static gboolean text_window_button_cb(GtkWidget *bt _U_, gpointer user_data)
+{
+ funnel_bt_t* cbd = user_data;
+
+ if (cbd->func) {
+ return cbd->func(cbd->tw,cbd->data);
+ } else {
+ return TRUE;
+ }
+}
+
+static void text_window_add_button(funnel_text_window_t* tw, funnel_bt_t* cbd, const gchar* label) {
+ GtkWidget *button;
+
+ cbd->tw = tw;
+
+ button = gtk_button_new_with_label(label);
+ GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
+ OBJECT_SET_DATA(tw->hbox, label, button);
+
+ gtk_box_pack_start(GTK_BOX(tw->button_hbox), button, FALSE, FALSE, 0);
+
+ gtk_widget_show(button);
+ SIGNAL_CONNECT(button, "clicked", text_window_button_cb, cbd);
+
+}
+
struct _funnel_dlg_data {
GtkWidget* win;
@@ -469,7 +523,9 @@ static const funnel_ops_t funnel_ops = {
text_window_clear,
text_window_get_text,
text_window_set_close_cb,
+ text_window_set_editable,
text_window_destroy,
+ text_window_add_button,
/*...,*/
funnel_new_dialog,
funnel_logger,
diff --git a/plugins/lua/elua_gui.c b/plugins/lua/elua_gui.c
index 811ebf9fc6..719ab52d8d 100644
--- a/plugins/lua/elua_gui.c
+++ b/plugins/lua/elua_gui.c
@@ -263,7 +263,7 @@ static void text_win_close_cb(void* data) {
}
}
-ELUA_METHOD TextWindow_at_close(lua_State* L) { /* Set the function that will be called when the window closes */
+ELUA_METHOD TextWindow_set_atclose(lua_State* L) { /* Set the function that will be called when the window closes */
#define ELUA_ARG_TextWindow_at_close_ACTION 2 /* A function to be executed when the user closes the window */
TextWindow tw = checkTextWindow(L,1);
@@ -366,7 +366,7 @@ ELUA_METHOD TextWindow_get_text(lua_State* L) { /* Get the text of the window */
ELUA_RETURN(1); /* The TextWindow's text. */
}
-static int TextWindow_gc(lua_State* L) {
+static int TextWindow__gc(lua_State* L) {
TextWindow tw = checkTextWindow(L,1);
if (!tw)
@@ -376,6 +376,91 @@ static int TextWindow_gc(lua_State* L) {
return 1;
}
+ELUA_METHOD TextWindow_set_editable(lua_State* L) { /* Set the function that will be called when the window closes */
+#define ELUA_OPTARG_TextWindow_at_close_EDITABLE 2 /* A boolean flag, defaults to true */
+
+ TextWindow tw = checkTextWindow(L,1);
+ gboolean editable = luaL_optint(L,2,1);
+
+ if (!tw)
+ ELUA_ERROR(TextWindow_at_close,"cannot be called for something not a TextWindow");
+
+ if (ops->set_editable)
+ ops->set_editable(tw,editable);
+
+ pushTextWindow(L,tw);
+ ELUA_RETURN(1); /* The TextWindow object. */
+}
+
+typedef struct _elua_bt_cb_t {
+ lua_State* L;
+ int func_ref;
+ int data_ref;
+} elua_bt_cb_t;
+
+static gboolean elua_button_callback(funnel_text_window_t* tw, void* data) {
+ elua_bt_cb_t* cbd = data;
+ lua_State* L = cbd->L;
+
+ lua_settop(L,0);
+ lua_pushcfunction(L,dlg_cb_error_handler);
+ lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->func_ref);
+ pushTextWindow(L,tw);
+ lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->data_ref);
+
+ switch ( lua_pcall(L,2,0,1) ) {
+ case 0:
+ break;
+ case LUA_ERRRUN:
+ g_warning("Runtime error while calling button callback");
+ break;
+ case LUA_ERRMEM:
+ g_warning("Memory alloc error while calling button callback");
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return TRUE;
+}
+
+ELUA_METHOD TextWindow_add_button(lua_State* L) {
+#define ELUA_ARG_TextWindow_add_button_LABEL 2 /* The label of the button */
+#define ELUA_ARG_TextWindow_add_button_FUNCTION 3 /* The function to be called when clicked */
+#define ELUA_ARG_TextWindow_add_button_DATA 4 /* The data to be passed to the function (other than the window) */
+ TextWindow tw = checkTextWindow(L,1);
+ const gchar* label = luaL_checkstring(L,ELUA_ARG_TextWindow_add_button_LABEL);
+
+ funnel_bt_t* fbt;
+ elua_bt_cb_t* cbd;
+
+ if (!tw)
+ ELUA_ERROR(TextWindow_at_close,"cannot be called for something not a TextWindow");
+
+ if (! lua_isfunction(L,ELUA_ARG_TextWindow_add_button_FUNCTION) )
+ ELUA_ARG_ERROR(TextWindow_add_button,FUNCTION,"must be a function");
+
+ lua_settop(L,4);
+
+ if (ops->add_button) {
+ fbt = ep_alloc(sizeof(funnel_bt_t));
+ cbd = ep_alloc(sizeof(elua_bt_cb_t));
+
+ fbt->tw = tw;
+ fbt->func = elua_button_callback;
+ fbt->data = cbd;
+
+ cbd->L = L;
+ cbd->data_ref = luaL_ref(L, LUA_REGISTRYINDEX);
+ cbd->func_ref = luaL_ref(L, LUA_REGISTRYINDEX);
+
+ ops->add_button(tw,fbt,label);
+ }
+
+ pushTextWindow(L,tw);
+ ELUA_RETURN(1); /* The TextWindow object. */
+}
ELUA_METHODS TextWindow_methods[] = {
ELUA_CLASS_FNREG(TextWindow,new),
@@ -384,13 +469,16 @@ ELUA_METHODS TextWindow_methods[] = {
ELUA_CLASS_FNREG(TextWindow,append),
ELUA_CLASS_FNREG(TextWindow,prepend),
ELUA_CLASS_FNREG(TextWindow,clear),
- ELUA_CLASS_FNREG(TextWindow,at_close),
+ ELUA_CLASS_FNREG(TextWindow,set_atclose),
+ ELUA_CLASS_FNREG(TextWindow,set_editable),
+ ELUA_CLASS_FNREG(TextWindow,get_text),
+ ELUA_CLASS_FNREG(TextWindow,add_button),
{0, 0}
};
ELUA_META TextWindow_meta[] = {
{"__tostring", TextWindow_get_text},
- {"__gc", TextWindow_gc},
+ {"__gc", TextWindow__gc},
{0, 0}
};
diff --git a/tap-funnel.c b/tap-funnel.c
index 558ad2e660..490a558a22 100644
--- a/tap-funnel.c
+++ b/tap-funnel.c
@@ -70,6 +70,8 @@ static const funnel_ops_t funnel_ops = {
text_window_get_text,
NULL,
NULL,
+ NULL,
+ NULL,
/*...,*/
NULL,
funnel_logger,