From: compudj Date: Thu, 27 May 2004 23:37:40 +0000 (+0000) Subject: toolbar menus now add/remove symmetrical, now order 1 X-Git-Tag: v0.12.20~2921 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6c9d86ddd9b3b83e27016d745a2164c0731f2bf3;p=lttv.git toolbar menus now add/remove symmetrical, now order 1 git-svn-id: http://ltt.polymtl.ca/svn@568 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c index b55ca4c4..8f5a612a 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c @@ -1233,8 +1233,6 @@ on_load_module_activate (GtkMenuItem *menuitem, str1++; } lttv_module_require(str1, NULL); - g_slist_foreach(g_main_window_list, (gpointer)update_menu_toolbar_constructors, - NULL); g_strfreev(dir); case GTK_RESPONSE_REJECT: case GTK_RESPONSE_CANCEL: @@ -1279,9 +1277,6 @@ on_unload_module_activate (GtkMenuItem *menuitem, lttv_library_info(library, &library_info); if(strcmp(unload_module_name, library_info.name) == 0){ lttv_library_unload(library); - g_slist_foreach(g_main_window_list, - (gpointer)update_menu_toolbar_constructors, - NULL); break; } } @@ -1876,23 +1871,20 @@ char * get_selection(char ** loaded_module_name, int nb_module, } -/* Insert or remove all menu entry and tool buttons into all main windows +/* Insert or remove all menu entry and tool buttons into this main window * for modules. * - * It adds them in a hash table as well, so it can keep track of which - * menu entries and buttons are currently in each main window, for later - * removal. */ -void update_menu_toolbar_constructors(MainWindow * mw, gpointer user_data) +void add_all_menu_toolbar_constructors(MainWindow * mw, gpointer user_data) { int i; GdkPixbuf *pixbuf; lttvwindow_viewer_constructor constructor; LttvMenus * global_menu, * instance_menu; LttvToolbars * global_toolbar, * instance_toolbar; - LttvMenuClosure *menu_item_i, *menu_item_j; - LttvToolbarClosure *toolbar_item_i, *toolbar_item_j; + LttvMenuClosure *menu_item; + LttvToolbarClosure *toolbar_item; LttvAttributeValue value; LttvIAttribute *global_attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); LttvIAttribute *attributes = LTTV_IATTRIBUTES(mw->attributes); @@ -1926,118 +1918,61 @@ void update_menu_toolbar_constructors(MainWindow * mw, gpointer user_data) /* Add missing menu entries to window instance */ for(i=0;ilen;i++) { - menu_item_i = &g_array_index(global_menu, LttvMenuClosure, i); + menu_item = &g_array_index(global_menu, LttvMenuClosure, i); + + //add menu_item to window instance; + constructor = menu_item->con; + tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); + new_widget = + gtk_menu_item_new_with_mnemonic (menu_item->menuText); + gtk_container_add (GTK_CONTAINER (tool_menu_title_menu), + new_widget); + g_signal_connect ((gpointer) new_widget, "activate", + G_CALLBACK (insert_viewer_wrap), + constructor); + gtk_widget_show (new_widget); + lttv_menus_add(instance_menu, menu_item->con, + menu_item->menu_path, + menu_item->menu_text, + new_widget); - for(j=0;jlen;j++) { - menu_item_j = &g_array_index(instance_menu, LttvMenuClosure, j); - - if(menu_item_i->con == menu_item_j->con) - break; - } - if(j == instance_menu->len) /* not found */ - { - //add menu_item_i to window instance; - constructor = menu_item->con; - tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); - new_widget = - gtk_menu_item_new_with_mnemonic (menu_item_i->menuText); - gtk_container_add (GTK_CONTAINER (tool_menu_title_menu), - new_widget); - g_signal_connect ((gpointer) new_widget, "activate", - G_CALLBACK (insert_viewer_wrap), - constructor); - gtk_widget_show (new_widget); - lttv_menus_add(instance_menu, menu_item_i->con, - menu_item_i->menu_path, - menu_item_i->menu_text, - new_widget); - } - - } - - /* Remove missing menu entries from window instance */ - for(i=0;ilen;i++) { - menu_item_i = &g_array_index(instance_menu, LttvMenuClosure, i); - - for(j=0;jlen;j++) { - menu_item_j = &g_array_index(global_menu, LttvMenuClosure, j); - - if(menu_item_i->con == menu_item_j->con) - break; - } - if(j == global_menu->len) /* not found */ - { - //remove menu_item_i from window instance; - tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); - gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), - menu_item_i->widget); - lttv_menus_remove(instance_menu, menu_item_i->con); - } } /* Add missing toolbar entries to window instance */ for(i=0;ilen;i++) { - toolbar_item_i = &g_array_index(global_toolbar, LttvToolbarClosure, i); - - for(j=0;jlen;j++) { - toolbar_item_j = &g_array_index(instance_toolbar, LttvToolbarClosure, j); - - if(toolbar_item_i->con == toolbar_item_j->con) - break; - } - if(j == instance_toolbar->len) /* not found */ - { - //add toolbar_item_i to window instance; - constructor = toolbar_item->con; - tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1"); - pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)toolbar_item->pixmap); - pixmap = gtk_image_new_from_pixbuf(pixbuf); - new_widget = - gtk_toolbar_append_element (GTK_TOOLBAR (tool_menu_title_menu), - GTK_TOOLBAR_CHILD_BUTTON, - NULL, - "", - toolbar_item->tooltip, NULL, - pixmap, NULL, NULL); - gtk_label_set_use_underline( - GTK_LABEL (((GtkToolbarChild*) ( - g_list_last (GTK_TOOLBAR - (tool_menu_title_menu)->children)->data))->label), - TRUE); - gtk_container_set_border_width (GTK_CONTAINER (new_widget), 1); - g_signal_connect ((gpointer) new_widget, - "clicked", - G_CALLBACK (insert_viewer_wrap), - constructor); - gtk_widget_show (new_widget); - - lttv_toolbars_add(instance_toolbar, toolbar_item_i->con, - toolbar_item_i->tooltip, - toolbar_item_i->pixmap, - new_widget); + toolbar_item = &g_array_index(global_toolbar, LttvToolbarClosure, i); + + //add toolbar_item to window instance; + constructor = toolbar_item->con; + tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1"); + pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)toolbar_item->pixmap); + pixmap = gtk_image_new_from_pixbuf(pixbuf); + new_widget = + gtk_toolbar_append_element (GTK_TOOLBAR (tool_menu_title_menu), + GTK_TOOLBAR_CHILD_BUTTON, + NULL, + "", + toolbar_item->tooltip, NULL, + pixmap, NULL, NULL); + gtk_label_set_use_underline( + GTK_LABEL (((GtkToolbarChild*) ( + g_list_last (GTK_TOOLBAR + (tool_menu_title_menu)->children)->data))->label), + TRUE); + gtk_container_set_border_width (GTK_CONTAINER (new_widget), 1); + g_signal_connect ((gpointer) new_widget, + "clicked", + G_CALLBACK (insert_viewer_wrap), + constructor); + gtk_widget_show (new_widget); - } - } + lttv_toolbars_add(instance_toolbar, toolbar_item->con, + toolbar_item->tooltip, + toolbar_item->pixmap, + new_widget); - /* Remove missing toolbar entries from window instance */ - for(i=0;ilen;i++) { - toolbar_item_i = &g_array_index(instance_toolbar, LttvToolbarClosure, i); - - for(j=0;jlen;j++) { - toolbar_item_j = &g_array_index(global_toolbar, LttvToolbarClosure, j); - - if(toolbar_item_i->con == toolbar_item_j->con) - break; - } - if(j == global_toolbar->len) /* not found */ - { - //remove toolbar_item_i from window instance; - tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); - gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), - toolbar_item_i->widget); - lttv_toolbars_remove(instance_toolbar, toolbar_item_i->con); - } } + } @@ -2076,7 +2011,7 @@ void construct_main_window(MainWindow * parent) "viewers/toolbar", LTTV_POINTER, &value)); (LttvToolbars*)*(value.v_pointer) = lttv_toolbars_new(); - update_menu_toolbar_constructors(new_m_window, NULL); + add_all_menu_toolbar_constructors(new_m_window, NULL); g_object_set_data(G_OBJECT(new_window), "mainWindow", (gpointer)new_m_window); //create a default tab diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/menu.c b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/menu.c index 7f6ba8e3..7437c4aa 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/menu.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/menu.c @@ -32,7 +32,7 @@ inline void lttv_menus_destroy(LttvMenus *h) { g_array_free(h, TRUE); } -inline void lttv_menus_add(LttvMenus *h, lttvwindow_viewer_constructor f, char* menuPath, char* menuText, GtkWidget *widget) +inline LttvMenuClosure lttv_menus_add(LttvMenus *h, lttvwindow_viewer_constructor f, char* menuPath, char* menuText, GtkWidget *widget) { LttvMenuClosure c; @@ -44,20 +44,27 @@ inline void lttv_menus_add(LttvMenus *h, lttvwindow_viewer_constructor f, char* c.menuText = menuText; c.widget = widget; g_array_append_val(h,c); + + return c; } -gboolean lttv_menus_remove(LttvMenus *h, lttvwindow_viewer_constructor f) +GtkWidget *lttv_menus_remove(LttvMenus *h, lttvwindow_viewer_constructor f) { LttvMenuClosure * tmp; gint i; + GtkWidget *widget; + for(i=0;ilen;i++){ tmp = & g_array_index(h, LttvMenuClosure, i); - if(tmp->con == f)break; + if(tmp->con == f) { + widget = tmp->widget; + break; + } } if(ilen){ g_array_remove_index(h, i); - return TRUE; - }else return FALSE; + return widget; + }else return NULL; } diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/menu.h b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/menu.h index 952720e0..fe94847d 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/menu.h +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/menu.h @@ -37,9 +37,9 @@ LttvMenus *lttv_menus_new(); void lttv_menus_destroy(LttvMenus *h); -void lttv_menus_add(LttvMenus *h, lttvwindow_viewer_constructor f, char* menuPath, char * menuText, GtkWidget *widget); +LttvMenuClosure lttv_menus_add(LttvMenus *h, lttvwindow_viewer_constructor f, char* menuPath, char * menuText, GtkWidget *widget); -gboolean lttv_menus_remove(LttvMenus *h, lttvwindow_viewer_constructor f); +GtkWidget *lttv_menus_remove(LttvMenus *h, lttvwindow_viewer_constructor f); unsigned lttv_menus_number(LttvMenus *h); diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/toolbar.c b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/toolbar.c index 6497a08f..7cff5680 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/toolbar.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/toolbar.c @@ -32,7 +32,7 @@ inline void lttv_toolbars_destroy(LttvToolbars *h) { g_array_free(h, TRUE); } -inline void lttv_toolbars_add(LttvToolbars *h, lttvwindow_viewer_constructor f, char* tooltip, char ** pixmap, GtkWidget *widget) +inline LttvToolbarClosure void lttv_toolbars_add(LttvToolbars *h, lttvwindow_viewer_constructor f, char* tooltip, char ** pixmap, GtkWidget *widget) { LttvToolbarClosure c; @@ -44,20 +44,27 @@ inline void lttv_toolbars_add(LttvToolbars *h, lttvwindow_viewer_constructor f, c.pixmap = pixmap; c.widget = widget; g_array_append_val(h,c); + + return c; } -gboolean lttv_toolbars_remove(LttvToolbars *h, lttvwindow_viewer_constructor f) +GtkWidget *lttv_toolbars_remove(LttvToolbars *h, lttvwindow_viewer_constructor f) { LttvToolbarClosure * tmp; gint i; + GtkWidget *widget; + for(i=0;ilen;i++){ tmp = & g_array_index(h, LttvToolbarClosure, i); - if(tmp->con == f)break; + if(tmp->con == f) { + widget = tmp->widget; + break; + } } if(ilen){ g_array_remove_index(h, i); - return TRUE; - }else return FALSE; + return widget; + }else return NULL; } unsigned lttv_toolbars_number(LttvToolbars *h) diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/toolbar.h b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/toolbar.h index 9e08adbb..a7eaf817 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/toolbar.h +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/toolbar.h @@ -36,13 +36,13 @@ LttvToolbars *lttv_toolbars_new(); void lttv_toolbars_destroy(LttvToolbars *h); -void lttv_toolbars_add(LttvToolbars *h, +LttvToolbarClosure lttv_toolbars_add(LttvToolbars *h, lttvwindow_viewer_constructor f, char* tooltip, char ** pixmap, GtkWidget *widget); -gboolean lttv_toolbars_remove(LttvToolbars *h, lttvwindow_viewer_constructor f); +GtkWidget *lttv_toolbars_remove(LttvToolbars *h, lttvwindow_viewer_constructor f); unsigned lttv_toolbars_number(LttvToolbars *h); diff --git a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/viewer.c b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/viewer.c index b1ec5c67..3260abdc 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/viewer.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/viewer.c @@ -144,6 +144,124 @@ void set_time_window(MainWindow * main_win, const TimeWindow *time_window) } +void add_toolbar_constructor(MainWindow *mw, LttvToolbarClosure *toolbar_c) +{ + LttvIAttribute *attributes = LTTV_IATTRIBUTES(mw->attributes); + LttvAttributeValue value; + LttvToolbars * instance_toolbar; + lttvwindow_viewer_constructor constructor; + GtkWidget * tool_menu_title_menu, *new_widget, *pixmap; + GdkPixbuf *pixbuf; + + g_assert(lttv_iattribute_find_by_path(attributes, + "viewers/toolbar", LTTV_POINTER, &value)); + if(*(value.v_pointer) == NULL) + (LttvToolbars*)*(value.v_pointer) = lttv_toolbars_new(); + instance_toolbar = (LttvToolbars*)*(value.v_pointer); + + constructor = toolbar_c->con; + tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1"); + pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)toolbar_c->pixmap); + pixmap = gtk_image_new_from_pixbuf(pixbuf); + new_widget = + gtk_toolbar_append_element (GTK_TOOLBAR (tool_menu_title_menu), + GTK_TOOLBAR_CHILD_BUTTON, + NULL, + "", + toolbar_item->tooltip, NULL, + pixmap, NULL, NULL); + gtk_label_set_use_underline( + GTK_LABEL (((GtkToolbarChild*) ( + g_list_last (GTK_TOOLBAR + (tool_menu_title_menu)->children)->data))->label), + TRUE); + gtk_container_set_border_width (GTK_CONTAINER (new_widget), 1); + g_signal_connect ((gpointer) new_widget, + "clicked", + G_CALLBACK (insert_viewer_wrap), + constructor); + gtk_widget_show (new_widget); + + lttv_toolbars_add(instance_toolbar, toolbar_item_i->con, + toolbar_item_i->tooltip, + toolbar_item_i->pixmap, + new_widget); + +} + +void add_menu_constructor(MainWindow *mw, LttvMenuClosure *menu_c) +{ + LttvIAttribute *attributes = LTTV_IATTRIBUTES(mw->attributes); + LttvAttributeValue value; + LttvToolbars * instance_menu; + lttvwindow_viewer_constructor constructor; + GtkWidget * tool_menu_title_menu, *new_widget; + + g_assert(lttv_iattribute_find_by_path(attributes, + "viewers/menu", LTTV_POINTER, &value)); + if(*(value.v_pointer) == NULL) + (LttvMenus*)*(value.v_pointer) = lttv_menus_new(); + instance_menu = (LttvMenus*)*(value.v_pointer); + + + constructor = menu_item->con; + tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); + new_widget = + gtk_menu_item_new_with_mnemonic (menu_c->menuText); + gtk_container_add (GTK_CONTAINER (tool_menu_title_menu), + new_widget); + g_signal_connect ((gpointer) new_widget, "activate", + G_CALLBACK (insert_viewer_wrap), + constructor); + gtk_widget_show (new_widget); + lttv_menus_add(instance_menu, menu_c->con, + menu_c->menu_path, + menu_c->menu_text, + new_widget); +} + +void remove_toolbar_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor) +{ + LttvIAttribute *attributes = LTTV_IATTRIBUTES(mw->attributes); + LttvAttributeValue value; + LttvToolbars * instance_toolbar; + lttvwindow_viewer_constructor constructor; + GtkWidget * tool_menu_title_menu, *widget; + + g_assert(lttv_iattribute_find_by_path(attributes, + "viewers/toolbar", LTTV_POINTER, &value)); + if(*(value.v_pointer) == NULL) + (LttvToolbars*)*(value.v_pointer) = lttv_toolbars_new(); + instance_toolbar = (LttvToolbars*)*(value.v_pointer); + + tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1"); + widget = lttv_menus_remove(instance_toolbar, viewer_constructor); + gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), + widget); +} + + +void remove_menu_constructor(MainWindow *mw, lttvwindow_viewer_constructor viewer_constructor) +{ + LttvIAttribute *attributes = LTTV_IATTRIBUTES(mw->attributes); + LttvAttributeValue value; + LttvMenus * instance_menu; + lttvwindow_viewer_constructor constructor; + GtkWidget * tool_menu_title_menu, *widget; + LttvMenuClosure *menu_item_i; + + g_assert(lttv_iattribute_find_by_path(attributes, + "viewers/menu", LTTV_POINTER, &value)); + if(*(value.v_pointer) == NULL) + (LttvMenus*)*(value.v_pointer) = lttv_menus_new(); + instance_menu = (LttvMenus*)*(value.v_pointer); + + widget = lttv_menus_remove(instance_menu, viewer_constructor); + tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); + gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), widget); +} + + /** * API parts */ @@ -174,6 +292,8 @@ void lttvwindow_register_constructor LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); LttvToolbars * toolbar; LttvMenus * menu; + LttvToolbarClosure toolbar_c; + LttvMenuClosure menu_c; LttvAttributeValue value; if(pixmap != NULL) { @@ -185,8 +305,11 @@ void lttvwindow_register_constructor toolbar = lttv_toolbars_new(); *(value.v_pointer) = toolbar; } - lttv_toolbars_add(toolbar, view_constructor, tooltip, pixmap); - main_window_add_toolbars_item(toolbar, view_constructor, tooltip, pixmap); + toolbar_c = lttv_toolbars_add(toolbar, view_constructor, tooltip, pixmap); + + g_slist_foreach(g_main_window_list, + (gpointer)add_toolbar_constructor, + &toolbar_c); } if(menu_path != NULL) { @@ -198,8 +321,11 @@ void lttvwindow_register_constructor menu = lttv_menus_new(); *(value.v_pointer) = menu; } - lttv_menus_add(menu, view_constructor, menu_path, menu_text); - main_window_add_menu_item(menu, view_constructor, menu_path, menu_text); + menu_c = lttv_menus_add(menu, view_constructor, menu_path, menu_text); + + g_slist_foreach(g_main_window_list, + (gpointer)add_menu_constructor, + &menu_c); } } @@ -228,7 +354,9 @@ void lttvwindow_unregister_constructor toolbar = (LttvToolbars*)*(value.v_pointer); if(toolbar != NULL) { - main_window_remove_toolbar_item(view_constructor); + g_slist_foreach(g_main_window_list, + (gpointer)remove_toolbar_constructor, + view_constructor); lttv_toolbars_remove(toolbar, view_constructor); } @@ -237,11 +365,11 @@ void lttvwindow_unregister_constructor menu = (LttvMenus*)*(value.v_pointer); if(menu != NULL) { - main_window_remove_menu_item(view_constructor); + g_slist_foreach(g_main_window_list, + (gpointer)remove_menu_constructor, + view_constructor); lttv_menus_remove(menu, view_constructor); } - - }