From 5723fa249e8efc13c1ebfe7fafb5f26cf0e40791 Mon Sep 17 00:00:00 2001 From: yangxx Date: Fri, 10 Oct 2003 17:26:56 +0000 Subject: [PATCH] main window with default tab git-svn-id: http://ltt.polymtl.ca/svn@296 04897980-b3bd-0310-b5e0-8ef037075253 --- .../lttv/modules/gui/mainWin/src/callbacks.c | 326 +++++++++--------- .../lttv/modules/gui/mainWin/src/callbacks.h | 5 +- .../modules/gui/mainWin/src/init_module.c | 94 +---- 3 files changed, 178 insertions(+), 247 deletions(-) diff --git a/ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.c b/ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.c index 17050b3f..89cc8b12 100644 --- a/ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.c +++ b/ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.c @@ -17,7 +17,6 @@ #define PATH_LENGTH 256 -extern systemView * gSysView; extern LttvTracesetContext * gTracesetContext; /** Array containing instanced objects. */ @@ -25,6 +24,7 @@ extern GSList * Main_Window_List; mainWindow * get_window_data_struct(GtkWidget * widget); char * get_unload_module(char ** loaded_module_name, int nb_module); +void * create_tab(GtkWidget* parent, GtkNotebook * notebook, char * label); /* test part */ void insertView(GtkWidget* widget, view_constructor constructor); @@ -126,7 +126,7 @@ void get_label(GtkWindow * mw, gchar * str, gchar* dialogue_title, gchar * label GtkWidget * label; gint id; - dialogue = gtk_dialog_new_with_buttons(dialogue_title,mw, + dialogue = gtk_dialog_new_with_buttons(dialogue_title,NULL, GTK_DIALOG_MODAL, GTK_STOCK_OK,GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL,GTK_RESPONSE_REJECT, @@ -175,110 +175,9 @@ mainWindow * get_window_data_struct(GtkWidget * widget) void createNewWindow(GtkWidget* widget, gpointer user_data, gboolean clone) { - GtkWidget * mw = NULL; /* Main window */ - systemView * sv = NULL; /* System view */ - systemView * newSv; /* New system view displayed in the new window */ - GtkWidget * newWindow; /* New generated main window */ - mainWindow * newMWindow;/* New main window structure */ - - //test - int i; - GtkWidget * ToolMenuTitle_menu, *insert_view, *pixmap; - LttvMenus * menu; - LttvToolbars * toolbar; - lttv_menu_closure *menuItem; - lttv_toolbar_closure *toolbarItem; - LttvAttributeValue value; - LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - view_constructor constructor; - GdkPixbuf *pixbuf; - //end - - mw = lookup_widget (widget, "MWindow"); - if(mw == NULL){ - g_printf("Can not find main window\n"); - return; - } - - sv = (systemView *)g_object_get_data(G_OBJECT(mw),"systemView"); - if(sv == NULL){ - g_printf("Can not find system view\n"); - return; - } - - newMWindow = g_new(mainWindow, 1); - - /* Add the object's information to the module's array */ - Main_Window_List = g_slist_append(Main_Window_List, mw); - - newWindow = create_MWindow(); - gtk_widget_show (newWindow); - - - newSv = g_new(systemView, 1); - while(sv->Next) sv = sv->Next; - sv->Next = newSv; - - newSv->EventDB = NULL; - newSv->SystemInfo = NULL; - newSv->Options = NULL; - newSv->Next = NULL; - newSv->Window = newMWindow; - - newMWindow->MWindow = newWindow; - newMWindow->Tab = NULL; - newMWindow->CurrentTab = NULL; - newMWindow->SystemView = newSv; - newMWindow->Attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); - newMWindow->traceset_context = LTTV_TRACESET_CONTEXT(gTracesetContext); - newMWindow->traceset = (LTTV_TRACESET_CONTEXT(gTracesetContext))->ts; - g_object_ref(gTracesetContext); + mainWindow * parent = get_window_data_struct(widget); - //test yxx - 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++){ - menuItem = &g_array_index(menu, lttv_menu_closure, i); - constructor = menuItem->con; - ToolMenuTitle_menu = lookup_widget(newMWindow->MWindow,"ToolMenuTitle_menu"); - insert_view = gtk_menu_item_new_with_mnemonic (menuItem->menuText); - gtk_widget_show (insert_view); - gtk_container_add (GTK_CONTAINER (ToolMenuTitle_menu), insert_view); - g_signal_connect ((gpointer) insert_view, "activate", - G_CALLBACK (insertViewTest), - constructor); - } - } - 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++){ - toolbarItem = &g_array_index(toolbar, lttv_toolbar_closure, i); - constructor = toolbarItem->con; - ToolMenuTitle_menu = lookup_widget(newMWindow->MWindow,"MToolbar2"); - pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**)toolbarItem->pixmap); - pixmap = gtk_image_new_from_pixbuf(pixbuf); - insert_view = gtk_toolbar_append_element (GTK_TOOLBAR (ToolMenuTitle_menu), - GTK_TOOLBAR_CHILD_BUTTON, - NULL, - "", - toolbarItem->tooltip, NULL, - pixmap, NULL, NULL); - gtk_label_set_use_underline (GTK_LABEL (((GtkToolbarChild*) (g_list_last (GTK_TOOLBAR (ToolMenuTitle_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 (insertViewTest),constructor); - } - } - //end - - g_object_set_data(G_OBJECT(newWindow), "systemView", (gpointer)newSv); - g_object_set_data(G_OBJECT(newWindow), "mainWindow", (gpointer)newMWindow); + constructMainWin(parent, NULL); if(clone){ g_printf("Clone : use the same traceset\n"); @@ -381,58 +280,17 @@ void on_tab_activate (GtkMenuItem *menuitem, gpointer user_data) { - GList * list; gchar label[PATH_LENGTH]; - - tab * tmpTab; - GtkWidget * pane; - mainWindow * mwData; GtkNotebook * notebook = (GtkNotebook *)lookup_widget((GtkWidget*)menuitem, "MNotebook"); if(notebook == NULL){ g_printf("Notebook does not exist\n"); return; } - mwData = get_window_data_struct((GtkWidget*)menuitem); - - tmpTab = mwData->Tab; - while(tmpTab && tmpTab->Next) tmpTab = tmpTab->Next; - if(!tmpTab){ - mwData->CurrentTab = NULL; - tmpTab = g_new(tab,1); - mwData->Tab = tmpTab; - }else{ - tmpTab->Next = g_new(tab,1); - tmpTab = tmpTab->Next; - } - if(mwData->CurrentTab){ - tmpTab->traceStartTime = mwData->CurrentTab->traceStartTime; - tmpTab->traceEndTime = mwData->CurrentTab->traceEndTime; - tmpTab->startTime = mwData->CurrentTab->startTime; - tmpTab->endTime = mwData->CurrentTab->endTime; - tmpTab->currentTime = mwData->CurrentTab->currentTime; - }else{ - getTracesetTimeSpan(mwData,&tmpTab->traceStartTime, &tmpTab->traceEndTime); - tmpTab->startTime = tmpTab->traceStartTime; - tmpTab->endTime = tmpTab->traceEndTime; - tmpTab->currentTime = tmpTab->traceStartTime; - } - tmpTab->Attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); - // mwData->CurrentTab = tmpTab; - tmpTab->custom = (GtkCustom*)gtk_custom_new(); - tmpTab->custom->mw = mwData; - gtk_widget_show((GtkWidget*)tmpTab->custom); - tmpTab->Next = NULL; - strcpy(label,"Page"); - get_label((GtkWindow*)mwData->MWindow, label,"Get the name of the tab","Please input tab's name"); - tmpTab->label = gtk_label_new (label); - gtk_widget_show (tmpTab->label); + get_label(NULL, label,"Get the name of the tab","Please input tab's name"); - gtk_notebook_append_page(notebook, (GtkWidget*)tmpTab->custom, tmpTab->label); - - list = gtk_container_get_children(GTK_CONTAINER(notebook)); - gtk_notebook_set_current_page(notebook,g_list_length(list)-1); + create_tab ((GtkWidget*)menuitem, notebook, label); } @@ -841,13 +699,7 @@ void on_MWindow_destroy (GtkObject *object, gpointer user_data) { - systemView * sv = gSysView; - gint count = 0; - while(sv->Next){ - g_printf("There are : %d windows\n",++count); - sv = sv->Next; - } - g_printf("There are : %d windows\n",++count); + g_printf("There are : %d windows\n",g_slist_length(Main_Window_List)); gtk_main_quit (); @@ -938,3 +790,167 @@ char * get_unload_module(char ** loaded_module_name, int nb_module) return unload_module_name; } + +void insertMenuToolbarItem(mainWindow * mw) +{ + int i; + GdkPixbuf *pixbuf; + view_constructor constructor; + LttvMenus * menu; + LttvToolbars * toolbar; + lttv_menu_closure *menuItem; + lttv_toolbar_closure *toolbarItem; + LttvAttributeValue value; + LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); + GtkWidget * ToolMenuTitle_menu, *insert_view, *pixmap; + + 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++){ + menuItem = &g_array_index(menu, lttv_menu_closure, i); + constructor = menuItem->con; + ToolMenuTitle_menu = lookup_widget(mw->MWindow,"ToolMenuTitle_menu"); + insert_view = gtk_menu_item_new_with_mnemonic (menuItem->menuText); + gtk_widget_show (insert_view); + gtk_container_add (GTK_CONTAINER (ToolMenuTitle_menu), insert_view); + g_signal_connect ((gpointer) insert_view, "activate", + G_CALLBACK (insertViewTest), + constructor); + } + } + + 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++){ + toolbarItem = &g_array_index(toolbar, lttv_toolbar_closure, i); + constructor = toolbarItem->con; + ToolMenuTitle_menu = lookup_widget(mw->MWindow,"MToolbar2"); + pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**)toolbarItem->pixmap); + pixmap = gtk_image_new_from_pixbuf(pixbuf); + insert_view = gtk_toolbar_append_element (GTK_TOOLBAR (ToolMenuTitle_menu), + GTK_TOOLBAR_CHILD_BUTTON, + NULL, + "", + toolbarItem->tooltip, NULL, + pixmap, NULL, NULL); + gtk_label_set_use_underline (GTK_LABEL (((GtkToolbarChild*) (g_list_last (GTK_TOOLBAR (ToolMenuTitle_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 (insertViewTest),constructor); + } + } +} + +void constructMainWin(mainWindow * parent, WindowCreationData * win_creation_data) +{ + systemView * sv = NULL; /* System view */ + systemView * newSv; /* New system view displayed in the new window */ + GtkWidget * newWindow; /* New generated main window */ + mainWindow * newMWindow;/* New main window structure */ + GtkNotebook * notebook; + + if(parent) sv = parent->SystemView; + + newMWindow = g_new(mainWindow, 1); + + // Add the object's information to the module's array + Main_Window_List = g_slist_append(Main_Window_List, newMWindow); + + newWindow = create_MWindow(); + gtk_widget_show (newWindow); + + newSv = g_new(systemView, 1); + if(sv){ + while(sv->Next) sv = sv->Next; + sv->Next = newSv; + } + + newSv->EventDB = NULL; + newSv->SystemInfo = NULL; + newSv->Options = NULL; + newSv->Next = NULL; + newSv->Window = newMWindow; + + newMWindow->MWindow = newWindow; + newMWindow->Tab = NULL; + newMWindow->CurrentTab = NULL; + newMWindow->SystemView = newSv; + newMWindow->Attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); + if(parent){ + newMWindow->traceset_context = parent->traceset_context; + newMWindow->traceset = parent->traceset; + newMWindow->winCreationData = parent->winCreationData; + }else{ + newMWindow->traceset_context = LTTV_TRACESET_CONTEXT(gTracesetContext); + newMWindow->traceset = (LTTV_TRACESET_CONTEXT(gTracesetContext))->ts; + newMWindow->winCreationData = win_creation_data; + } + + insertMenuToolbarItem(newMWindow); + + g_object_set_data(G_OBJECT(newWindow), "systemView", (gpointer)newSv); + g_object_set_data(G_OBJECT(newWindow), "mainWindow", (gpointer)newMWindow); + + //create a default tab + notebook = (GtkNotebook *)lookup_widget(newMWindow->MWindow, "MNotebook"); + if(notebook == NULL){ + g_printf("Notebook does not exist\n"); + return; + } + //for now there is no name field in LttvTraceset structure + //Use "Traceset" as the label for the default tab + create_tab(newMWindow->MWindow, notebook,"Traceset"); + +} + +void * create_tab(GtkWidget* parent, GtkNotebook * notebook, char * label) +{ + GList * list; + tab * tmpTab; + mainWindow * mwData; + + mwData = get_window_data_struct(parent); + + tmpTab = mwData->Tab; + while(tmpTab && tmpTab->Next) tmpTab = tmpTab->Next; + if(!tmpTab){ + mwData->CurrentTab = NULL; + tmpTab = g_new(tab,1); + mwData->Tab = tmpTab; + }else{ + tmpTab->Next = g_new(tab,1); + tmpTab = tmpTab->Next; + } + if(mwData->CurrentTab){ + tmpTab->traceStartTime = mwData->CurrentTab->traceStartTime; + tmpTab->traceEndTime = mwData->CurrentTab->traceEndTime; + tmpTab->startTime = mwData->CurrentTab->startTime; + tmpTab->endTime = mwData->CurrentTab->endTime; + tmpTab->currentTime = mwData->CurrentTab->currentTime; + }else{ + getTracesetTimeSpan(mwData,&tmpTab->traceStartTime, &tmpTab->traceEndTime); + tmpTab->startTime = tmpTab->traceStartTime; + tmpTab->endTime = tmpTab->traceEndTime; + tmpTab->currentTime = tmpTab->traceStartTime; + } + tmpTab->Attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); + // mwData->CurrentTab = tmpTab; + tmpTab->custom = (GtkCustom*)gtk_custom_new(); + tmpTab->custom->mw = mwData; + gtk_widget_show((GtkWidget*)tmpTab->custom); + tmpTab->Next = NULL; + + tmpTab->label = gtk_label_new (label); + gtk_widget_show (tmpTab->label); + + gtk_notebook_append_page(notebook, (GtkWidget*)tmpTab->custom, tmpTab->label); + + list = gtk_container_get_children(GTK_CONTAINER(notebook)); + gtk_notebook_set_current_page(notebook,g_list_length(list)-1); +} diff --git a/ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.h b/ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.h index 0c15b356..c07cc3b3 100644 --- a/ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.h +++ b/ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.h @@ -1,9 +1,12 @@ #include +#include +#include /* internal functions */ void createNewWindow(GtkWidget* widget, gpointer user_data, gboolean clone); - +void insertMenuToolbarItem(mainWindow * mw); +void constructMainWin(mainWindow * parent, WindowCreationData *win_creation_data); /* callback functions*/ diff --git a/ltt/branches/poly/lttv/modules/gui/mainWin/src/init_module.c b/ltt/branches/poly/lttv/modules/gui/mainWin/src/init_module.c index a2d74a31..aad203e2 100644 --- a/ltt/branches/poly/lttv/modules/gui/mainWin/src/init_module.c +++ b/ltt/branches/poly/lttv/modules/gui/mainWin/src/init_module.c @@ -26,8 +26,6 @@ #include "callbacks.h" /* global variable */ -systemView * gSysView; - LttvTracesetStats * gTracesetContext = NULL; static LttvTraceset * traceset; @@ -67,26 +65,7 @@ void lttv_trace_option(void *hook_data) static gboolean Window_Creation_Hook(void *hook_data, void *call_data) { - int i; - GdkPixbuf *pixbuf; - view_constructor constructor; - LttvMenus * menu; - LttvToolbars * toolbar; - lttv_menu_closure *menuItem; - lttv_toolbar_closure *toolbarItem; - LttvAttributeValue value; - LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - GModule *gm; - GtkWidget * ToolMenuTitle_menu, *insert_view, *pixmap; - GtkWidget *window1; - mainWindow * mw = g_new(mainWindow, 1); - gSysView = g_new(systemView, 1); - WindowCreationData *Window_Creation_Data = (WindowCreationData*)hook_data; - - mw->winCreationData = Window_Creation_Data; - - /* Add the object's information to the module's array */ - Main_Window_List = g_slist_append(Main_Window_List, mw); + WindowCreationData* Window_Creation_Data = (WindowCreationData*)hook_data; g_critical("GUI Window_Creation_Hook()"); #ifdef ENABLE_NLS @@ -102,81 +81,14 @@ static gboolean Window_Creation_Hook(void *hook_data, void *call_data) add_pixmap_directory ("pixmaps"); add_pixmap_directory ("modules/gui/mainWin/pixmaps"); - /* - * The following code was added by Glade to create one of each component - * (except popup menus), just so that you see something after building - * the project. Delete any components that you don't want shown initially. - */ - window1 = create_MWindow (); - gtk_widget_show (window1); - - mw->MWindow = window1; - mw->SystemView = gSysView; - mw->Tab = NULL; - mw->CurrentTab = NULL; - mw->Attributes = LTTV_IATTRIBUTE(g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); + if(!gTracesetContext){ gTracesetContext = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); //FIXME: lttv_context_fini should be called some where. lttv_context_init(LTTV_TRACESET_CONTEXT(gTracesetContext), traceset); } - mw->traceset_context = LTTV_TRACESET_CONTEXT(gTracesetContext); - mw->traceset = (LTTV_TRACESET_CONTEXT(gTracesetContext))->ts; - g_object_ref(gTracesetContext); - - //test - 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++){ - menuItem = &g_array_index(menu, lttv_menu_closure, i); - constructor = menuItem->con; - ToolMenuTitle_menu = lookup_widget(mw->MWindow,"ToolMenuTitle_menu"); - insert_view = gtk_menu_item_new_with_mnemonic (menuItem->menuText); - gtk_widget_show (insert_view); - gtk_container_add (GTK_CONTAINER (ToolMenuTitle_menu), insert_view); - g_signal_connect ((gpointer) insert_view, "activate", - G_CALLBACK (insertViewTest), - constructor); - } - } - - 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++){ - toolbarItem = &g_array_index(toolbar, lttv_toolbar_closure, i); - constructor = toolbarItem->con; - ToolMenuTitle_menu = lookup_widget(mw->MWindow,"MToolbar2"); - pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**)toolbarItem->pixmap); - pixmap = gtk_image_new_from_pixbuf(pixbuf); - insert_view = gtk_toolbar_append_element (GTK_TOOLBAR (ToolMenuTitle_menu), - GTK_TOOLBAR_CHILD_BUTTON, - NULL, - "", - toolbarItem->tooltip, NULL, - pixmap, NULL, NULL); - gtk_label_set_use_underline (GTK_LABEL (((GtkToolbarChild*) (g_list_last (GTK_TOOLBAR (ToolMenuTitle_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 (insertViewTest),constructor); - } - } - - //end - - gSysView->EventDB = NULL; - gSysView->SystemInfo = NULL; - gSysView->Options = NULL; - gSysView->Window = mw; - gSysView->Next = NULL; - g_object_set_data(G_OBJECT(window1), "systemView", (gpointer)gSysView); - g_object_set_data(G_OBJECT(window1), "mainWindow", (gpointer)mw); + constructMainWin(NULL, Window_Creation_Data); gtk_main (); -- 2.34.1