From 001d8606bfda457ee644e2ad88449d8c3053f7ab Mon Sep 17 00:00:00 2001 From: compudj Date: Thu, 27 May 2004 22:35:29 +0000 Subject: [PATCH] toolbar menus now add/remove symmetrical git-svn-id: http://ltt.polymtl.ca/svn@567 04897980-b3bd-0310-b5e0-8ef037075253 --- .../gui/lttvwindow/lttvwindow/callbacks.c | 311 +++++++++--------- .../modules/gui/lttvwindow/lttvwindow/menu.c | 11 +- .../modules/gui/lttvwindow/lttvwindow/menu.h | 9 +- .../gui/lttvwindow/lttvwindow/toolbar.c | 11 +- .../gui/lttvwindow/lttvwindow/toolbar.h | 13 +- .../gui/lttvwindow/lttvwindow/viewer.c | 210 ++++-------- 6 files changed, 238 insertions(+), 327 deletions(-) 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 72a6f9d7..b55ca4c4 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/callbacks.c @@ -1233,7 +1233,7 @@ on_load_module_activate (GtkMenuItem *menuitem, str1++; } lttv_module_require(str1, NULL); - g_slist_foreach(g_main_window_list, (gpointer)insert_menu_toolbar_item, + g_slist_foreach(g_main_window_list, (gpointer)update_menu_toolbar_constructors, NULL); g_strfreev(dir); case GTK_RESPONSE_REJECT: @@ -1278,7 +1278,10 @@ on_unload_module_activate (GtkMenuItem *menuitem, library = lttv_library_get(i); lttv_library_info(library, &library_info); if(strcmp(unload_module_name, library_info.name) == 0){ - lttv_library_unload(library); + lttv_library_unload(library); + g_slist_foreach(g_main_window_list, + (gpointer)update_menu_toolbar_constructors, + NULL); break; } } @@ -1873,85 +1876,166 @@ char * get_selection(char ** loaded_module_name, int nb_module, } -/* hash funtions - */ - -void main_window_destroy_hash_key(gpointer key) -{ - g_free(key); -} - -void main_window_destroy_hash_data(gpointer data) -{ -} - - -/* Insert menu entry and tool button into all main windows for modules - * It checks whether the menu entry or tool button exists or not, - * if they do not exist, then construct the widget and insert them - * into all main windows +/* Insert or remove all menu entry and tool buttons into all main windows + * 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 insert_menu_toolbar_item(MainWindow * mw, gpointer user_data) +void update_menu_toolbar_constructors(MainWindow * mw, gpointer user_data) { int i; GdkPixbuf *pixbuf; lttvwindow_viewer_constructor constructor; - LttvMenus * menu; - LttvToolbars * toolbar; - lttv_menu_closure *menu_item; - lttv_toolbar_closure *toolbar_item; + LttvMenus * global_menu, * instance_menu; + LttvToolbars * global_toolbar, * instance_toolbar; + LttvMenuClosure *menu_item_i, *menu_item_j; + LttvToolbarClosure *toolbar_item_i, *toolbar_item_j; LttvAttributeValue value; - LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - GtkWidget * tool_menu_title_menu, *insert_view, *pixmap, *tmp; + LttvIAttribute *global_attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + LttvIAttribute *attributes = LTTV_IATTRIBUTES(mw->attributes); + GtkWidget * tool_menu_title_menu, *new_widget, *pixmap; + + g_assert(lttv_iattribute_find_by_path(global_attributes, + "viewers/menu", LTTV_POINTER, &value)); + if(*(value.v_pointer) == NULL) + (LttvMenus*)*(value.v_pointer) = lttv_menus_new(); + global_menu = (LttvMenus*)*(value.v_pointer); g_assert(lttv_iattribute_find_by_path(attributes, "viewers/menu", LTTV_POINTER, &value)); - menu = (LttvMenus*)*(value.v_pointer); + if(*(value.v_pointer) == NULL) + (LttvMenus*)*(value.v_pointer) = lttv_menus_new(); + instance_menu = (LttvMenus*)*(value.v_pointer); - if(menu){ - for(i=0;ilen;i++){ - menu_item = &g_array_index(menu, lttv_menu_closure, i); - tmp = g_hash_table_lookup(mw->hash_menu_item, g_strdup(menu_item->menuText)); - if(tmp)continue; + + + g_assert(lttv_iattribute_find_by_path(global_attributes, + "viewers/toolbar", LTTV_POINTER, &value)); + if(*(value.v_pointer) == NULL) + (LttvToolbars*)*(value.v_pointer) = lttv_toolbars_new(); + global_toolbar = (LttvToolbars*)*(value.v_pointer); + + 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); + + /* Add missing menu entries to window instance */ + for(i=0;ilen;i++) { + menu_item_i = &g_array_index(global_menu, LttvMenuClosure, i); + + 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"); - insert_view = gtk_menu_item_new_with_mnemonic (menu_item->menuText); - gtk_widget_show (insert_view); - gtk_container_add (GTK_CONTAINER (tool_menu_title_menu), insert_view); - g_signal_connect ((gpointer) insert_view, "activate", - G_CALLBACK (insert_viewer_wrap), - constructor); - g_hash_table_insert(mw->hash_menu_item, g_strdup(menu_item->menuText), - insert_view); + 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); } + } - g_assert(lttv_iattribute_find_by_path(attributes, - "viewers/toolbar", LTTV_POINTER, &value)); - toolbar = (LttvToolbars*)*(value.v_pointer); + /* 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); - if(toolbar){ - for(i=0;ilen;i++){ - toolbar_item = &g_array_index(toolbar, lttv_toolbar_closure, i); - tmp = g_hash_table_lookup(mw->hash_toolbar_item, g_strdup(toolbar_item->tooltip)); - if(tmp)continue; + 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); + pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)toolbar_item->pixmap); pixmap = gtk_image_new_from_pixbuf(pixbuf); - insert_view = 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_widget_show (insert_view); - gtk_container_set_border_width (GTK_CONTAINER (insert_view), 1); - g_signal_connect ((gpointer) insert_view, "clicked",G_CALLBACK (insert_viewer_wrap),constructor); - g_hash_table_insert(mw->hash_toolbar_item, g_strdup(toolbar_item->tooltip), - insert_view); + 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); + + } + } + + /* 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); } } } @@ -1984,14 +2068,15 @@ void construct_main_window(MainWindow * parent) new_m_window->current_tab = NULL; new_m_window->attributes = attributes; - new_m_window->hash_menu_item = g_hash_table_new_full (g_str_hash, g_str_equal, - main_window_destroy_hash_key, - main_window_destroy_hash_data); - new_m_window->hash_toolbar_item = g_hash_table_new_full (g_str_hash, g_str_equal, - main_window_destroy_hash_key, - main_window_destroy_hash_data); + g_assert(lttv_iattribute_find_by_path(attributes, + "viewers/menu", LTTV_POINTER, &value)); + (LttvMenus*)*(value.v_pointer) = lttv_menus_new(); + + g_assert(lttv_iattribute_find_by_path(attributes_global, + "viewers/toolbar", LTTV_POINTER, &value)); + (LttvToolbars*)*(value.v_pointer) = lttv_toolbars_new(); - insert_menu_toolbar_item(new_m_window, NULL); + update_menu_toolbar_constructors(new_m_window, NULL); g_object_set_data(G_OBJECT(new_window), "mainWindow", (gpointer)new_m_window); //create a default tab @@ -2180,96 +2265,6 @@ void * create_tab(MainWindow * parent, MainWindow* current_window, } - -/* Remove menu entry and tool button from main window for the - * unloaded module - */ - -void remove_menu_item(gpointer main_win, gpointer user_data) -{ - MainWindow * mw = (MainWindow *) main_win; - lttv_menu_closure *menu_item = (lttv_menu_closure *)user_data; - GtkWidget * tool_menu_title_menu, *insert_view; - - tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); - insert_view = (GtkWidget*)g_hash_table_lookup(mw->hash_menu_item, - menu_item->menuText); - if(insert_view){ - g_hash_table_remove(mw->hash_menu_item, menu_item->menuText); - gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), insert_view); - } -} - -void remove_toolbar_item(gpointer main_win, gpointer user_data) -{ - MainWindow * mw = (MainWindow *) main_win; - lttv_toolbar_closure *toolbar_item = (lttv_toolbar_closure *)user_data; - GtkWidget * tool_menu_title_menu, *insert_view; - - - tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1"); - insert_view = (GtkWidget*)g_hash_table_lookup(mw->hash_toolbar_item, - toolbar_item->tooltip); - if(insert_view){ - g_hash_table_remove(mw->hash_toolbar_item, toolbar_item->tooltip); - gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), insert_view); - } -} - -/** - * Remove menu and toolbar item when a module unloaded from all - * main windows - */ - -void main_window_remove_menu_item(lttvwindow_viewer_constructor constructor) -{ - int i; - LttvMenus * menu; - lttv_menu_closure *menu_item; - LttvAttributeValue value; - LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - - g_assert(lttv_iattribute_find_by_path(attributes, - "viewers/menu", LTTV_POINTER, &value)); - menu = (LttvMenus*)*(value.v_pointer); - - if(menu){ - for(i=0;ilen;i++){ - menu_item = &g_array_index(menu, lttv_menu_closure, i); - if(menu_item->con != constructor) continue; - if(g_main_window_list){ - g_slist_foreach(g_main_window_list, remove_menu_item, menu_item); - } - break; - } - } - -} - -void main_window_remove_toolbar_item(lttvwindow_viewer_constructor constructor) -{ - int i; - LttvToolbars * toolbar; - lttv_toolbar_closure *toolbar_item; - LttvAttributeValue value; - LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - - g_assert(lttv_iattribute_find_by_path(attributes, - "viewers/toolbar", LTTV_POINTER, &value)); - toolbar = (LttvToolbars*)*(value.v_pointer); - - if(toolbar){ - for(i=0;ilen;i++){ - toolbar_item = &g_array_index(toolbar, lttv_toolbar_closure, i); - if(toolbar_item->con != constructor) continue; - if(g_main_window_list){ - g_slist_foreach(g_main_window_list, remove_toolbar_item, toolbar_item); - } - break; - } - } -} - /** * Function to show each viewer in the current tab. * It will be called by main window, call show on each registered viewer, 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 66033323..7f6ba8e3 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/menu.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/menu.c @@ -21,7 +21,7 @@ inline LttvMenus *lttv_menus_new() { - return g_array_new(FALSE, FALSE, sizeof(lttv_menu_closure)); + return g_array_new(FALSE, FALSE, sizeof(LttvMenuClosure)); } /* MD: delete elements of the array also, but don't free pointed addresses @@ -32,9 +32,9 @@ 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) +inline void lttv_menus_add(LttvMenus *h, lttvwindow_viewer_constructor f, char* menuPath, char* menuText, GtkWidget *widget) { - lttv_menu_closure c; + LttvMenuClosure c; /* if h is null, do nothing, or popup a warning message */ if(h == NULL)return; @@ -42,15 +42,16 @@ inline void lttv_menus_add(LttvMenus *h, lttvwindow_viewer_constructor f, char* c.con = f; c.menuPath = menuPath; c.menuText = menuText; + c.widget = widget; g_array_append_val(h,c); } gboolean lttv_menus_remove(LttvMenus *h, lttvwindow_viewer_constructor f) { - lttv_menu_closure * tmp; + LttvMenuClosure * tmp; gint i; for(i=0;ilen;i++){ - tmp = & g_array_index(h, lttv_menu_closure, i); + tmp = & g_array_index(h, LttvMenuClosure, i); if(tmp->con == f)break; } if(ilen){ 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 ae519785..952720e0 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/menu.h +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/menu.h @@ -20,21 +20,24 @@ #define MENU_H #include +#include + typedef GArray LttvMenus; -typedef struct _lttv_menu_closure { +typedef struct _LttvMenuClosure { lttvwindow_viewer_constructor con; char * menuPath; char * menuText; -} lttv_menu_closure; + GtkWidget *widget; +} LttvMenuClosure; LttvMenus *lttv_menus_new(); void lttv_menus_destroy(LttvMenus *h); -void lttv_menus_add(LttvMenus *h, lttvwindow_viewer_constructor f, char* menuPath, char * menuText); +void 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); 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 8a39ae74..6497a08f 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/toolbar.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/toolbar.c @@ -21,7 +21,7 @@ inline LttvToolbars *lttv_toolbars_new() { - return g_array_new(FALSE, FALSE, sizeof(lttv_toolbar_closure)); + return g_array_new(FALSE, FALSE, sizeof(LttvToolbarClosure)); } /* MD: delete elements of the array also, but don't free pointed addresses @@ -32,9 +32,9 @@ 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) +inline void lttv_toolbars_add(LttvToolbars *h, lttvwindow_viewer_constructor f, char* tooltip, char ** pixmap, GtkWidget *widget) { - lttv_toolbar_closure c; + LttvToolbarClosure c; /* if h is null, do nothing, or popup a warning message */ if(h == NULL)return; @@ -42,15 +42,16 @@ inline void lttv_toolbars_add(LttvToolbars *h, lttvwindow_viewer_constructor f, c.con = f; c.tooltip = tooltip; c.pixmap = pixmap; + c.widget = widget; g_array_append_val(h,c); } gboolean lttv_toolbars_remove(LttvToolbars *h, lttvwindow_viewer_constructor f) { - lttv_toolbar_closure * tmp; + LttvToolbarClosure * tmp; gint i; for(i=0;ilen;i++){ - tmp = & g_array_index(h, lttv_toolbar_closure, i); + tmp = & g_array_index(h, LttvToolbarClosure, i); if(tmp->con == f)break; } if(ilen){ 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 7e5df0c4..9e08adbb 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/toolbar.h +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/toolbar.h @@ -20,20 +20,27 @@ #define TOOLBAR_H #include +#include +#include typedef GArray LttvToolbars; -typedef struct _lttv_toolbar_closure { +typedef struct _LttvToolbarClosure { lttvwindow_viewer_constructor con; char * tooltip; char ** pixmap; -} lttv_toolbar_closure; + GtkWidget *widget; +} LttvToolbarClosure; LttvToolbars *lttv_toolbars_new(); void lttv_toolbars_destroy(LttvToolbars *h); -void lttv_toolbars_add(LttvToolbars *h, lttvwindow_viewer_constructor f, char* tooltip, char ** pixmap); +void 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); 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 0300cdda..b1ec5c67 100644 --- a/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/viewer.c +++ b/ltt/branches/poly/lttv/modules/gui/lttvwindow/lttvwindow/viewer.c @@ -144,203 +144,107 @@ void set_time_window(MainWindow * main_win, const TimeWindow *time_window) } - -/* Remove menu entry and tool button from main window for the - * unloaded module - */ - -void remove_menu_item(gpointer main_win, gpointer user_data) -{ - MainWindow * mw = (MainWindow *) main_win; - lttv_menu_closure *menu_item = (lttv_menu_closure *)user_data; - GtkWidget * tool_menu_title_menu, *insert_view; - - tool_menu_title_menu = lookup_widget(mw->mwindow,"ToolMenuTitle_menu"); - insert_view = (GtkWidget*)g_hash_table_lookup(mw->hash_menu_item, - menu_item->menuText); - if(insert_view){ - g_hash_table_remove(mw->hash_menu_item, menu_item->menuText); - gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), insert_view); - } -} - -void remove_toolbar_item(gpointer main_win, gpointer user_data) -{ - MainWindow * mw = (MainWindow *) main_win; - lttv_toolbar_closure *toolbar_item = (lttv_toolbar_closure *)user_data; - GtkWidget * tool_menu_title_menu, *insert_view; - - - tool_menu_title_menu = lookup_widget(mw->mwindow,"MToolbar1"); - insert_view = (GtkWidget*)g_hash_table_lookup(mw->hash_toolbar_item, - toolbar_item->tooltip); - if(insert_view){ - g_hash_table_remove(mw->hash_toolbar_item, toolbar_item->tooltip); - gtk_container_remove (GTK_CONTAINER (tool_menu_title_menu), insert_view); - } -} - -/** - * Remove menu and toolbar item when a module unloaded from all - * main windows - */ - -void main_window_remove_menu_item(lttvwindow_viewer_constructor constructor) -{ - int i; - LttvMenus * menu; - lttv_menu_closure *menu_item; - LttvAttributeValue value; - LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - - g_assert(lttv_iattribute_find_by_path(attributes, - "viewers/menu", LTTV_POINTER, &value)); - menu = (LttvMenus*)*(value.v_pointer); - - if(menu){ - for(i=0;ilen;i++){ - menu_item = &g_array_index(menu, lttv_menu_closure, i); - if(menu_item->con != constructor) continue; - if(g_main_window_list){ - g_slist_foreach(g_main_window_list, remove_menu_item, menu_item); - } - break; - } - } - -} - -void main_window_remove_toolbar_item(lttvwindow_viewer_constructor constructor) -{ - int i; - LttvToolbars * toolbar; - lttv_toolbar_closure *toolbar_item; - LttvAttributeValue value; - LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - - g_assert(lttv_iattribute_find_by_path(attributes, - "viewers/toolbar", LTTV_POINTER, &value)); - toolbar = (LttvToolbars*)*(value.v_pointer); - - if(toolbar){ - for(i=0;ilen;i++){ - toolbar_item = &g_array_index(toolbar, lttv_toolbar_closure, i); - if(toolbar_item->con != constructor) continue; - if(g_main_window_list){ - g_slist_foreach(g_main_window_list, remove_toolbar_item, toolbar_item); - } - break; - } - } -} - - - - /** * API parts */ + /** * Function to register a view constructor so that main window can generate - * a toolbar item for the viewer in order to generate a new instance easily. - * It will be called by init function of the module. - * @param ButtonPixmap image shown on the toolbar item. + * a menu item and a toolbar item for the viewer in order to generate a new + * instance easily. A menu entry and toolbar item will be added to each main + * window. + * + * It should be called by init function of the module. + * + * @param menu_path path of the menu item. + * @param menu_text text of the menu item. + * @param pixmap Image shown on the toolbar item. * @param tooltip tooltip of the toolbar item. * @param view_constructor constructor of the viewer. */ -void lttvwindow_register_toolbar(char ** pixmap, char *tooltip, lttvwindow_viewer_constructor view_constructor) +void lttvwindow_register_constructor + (char * menu_path, + char * menu_text, + char ** pixmap, + char * tooltip, + lttvwindow_viewer_constructor view_constructor) { LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); LttvToolbars * toolbar; + LttvMenus * menu; LttvAttributeValue value; - g_assert(lttv_iattribute_find_by_path(attributes_global, - "viewers/toolbar", LTTV_POINTER, &value)); - toolbar = (LttvToolbars*)*(value.v_pointer); + if(pixmap != NULL) { + g_assert(lttv_iattribute_find_by_path(attributes_global, + "viewers/toolbar", LTTV_POINTER, &value)); + toolbar = (LttvToolbars*)*(value.v_pointer); - if(toolbar == NULL){ - toolbar = lttv_toolbars_new(); - *(value.v_pointer) = toolbar; + if(toolbar == NULL) { + 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); + } + + if(menu_path != NULL) { + g_assert(lttv_iattribute_find_by_path(attributes_global, + "viewers/menu", LTTV_POINTER, &value)); + menu = (LttvMenus*)*(value.v_pointer); + + if(menu == NULL) { + 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); } - lttv_toolbars_add(toolbar, view_constructor, tooltip, pixmap); } /** * Function to unregister the viewer's constructor, release the space - * occupied by pixmap, tooltip and constructor of the viewer. + * occupied by menu_path, menu_text, pixmap, tooltip and constructor of the + * viewer. + * * It will be called when a module is unloaded. - * @param view_constructor constructor of the viewer which is used as - * a reference to find out where the pixmap and tooltip are. + * + * @param view_constructor constructor of the viewer. */ -void lttvwindow_unregister_toolbar(lttvwindow_viewer_constructor view_constructor) + +void lttvwindow_unregister_constructor + (lttvwindow_viewer_constructor view_constructor) { LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); LttvToolbars * toolbar; + LttvMenus * menu; LttvAttributeValue value; g_assert(lttv_iattribute_find_by_path(attributes_global, "viewers/toolbar", LTTV_POINTER, &value)); toolbar = (LttvToolbars*)*(value.v_pointer); - main_window_remove_toolbar_item(view_constructor); - - lttv_toolbars_remove(toolbar, view_constructor); -} - - -/** - * Function to register a view constructor so that main window can generate - * a menu item for the viewer in order to generate a new instance easily. - * It will be called by init function of the module. - * @param menu_path path of the menu item. - * @param menu_text text of the menu item. - * @param view_constructor constructor of the viewer. - */ - -void lttvwindow_register_menu(char *menu_path, char *menu_text, lttvwindow_viewer_constructor view_constructor) -{ - LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); - LttvMenus * menu; - LttvAttributeValue value; + if(toolbar != NULL) { + main_window_remove_toolbar_item(view_constructor); + lttv_toolbars_remove(toolbar, view_constructor); + } g_assert(lttv_iattribute_find_by_path(attributes_global, "viewers/menu", LTTV_POINTER, &value)); menu = (LttvMenus*)*(value.v_pointer); - if(menu == NULL){ - menu = lttv_menus_new(); - *(value.v_pointer) = menu; + if(menu != NULL) { + main_window_remove_menu_item(view_constructor); + lttv_menus_remove(menu, view_constructor); } - lttv_menus_add(menu, view_constructor, menu_path, menu_text); -} - -/** - * Function to unregister the viewer's constructor, release the space - * occupied by menu_path, menu_text and constructor of the viewer. - * It will be called when a module is unloaded. - * @param view_constructor constructor of the viewer which is used as - * a reference to find out where the menu_path and menu_text are. - */ -void lttvwindow_unregister_menu(lttvwindow_viewer_constructor view_constructor) -{ - LttvIAttribute *attributes_global = LTTV_IATTRIBUTE(lttv_global_attributes()); - LttvMenus * menu; - LttvAttributeValue value; - g_assert(lttv_iattribute_find_by_path(attributes_global, - "viewers/menu", LTTV_POINTER, &value)); - menu = (LttvMenus*)*(value.v_pointer); - - main_window_remove_menu_item(view_constructor); - - lttv_menus_remove(menu, view_constructor); } + /** * Function to register a hook function for a viewer to set/update its * time interval. -- 2.34.1