quit menu complete
authoryangxx <yangxx@04897980-b3bd-0310-b5e0-8ef037075253>
Fri, 10 Oct 2003 20:53:32 +0000 (20:53 +0000)
committeryangxx <yangxx@04897980-b3bd-0310-b5e0-8ef037075253>
Fri, 10 Oct 2003 20:53:32 +0000 (20:53 +0000)
git-svn-id: http://ltt.polymtl.ca/svn@297 04897980-b3bd-0310-b5e0-8ef037075253

ltt/branches/poly/include/lttv/mainWindow.h
ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.c
ltt/branches/poly/lttv/modules/gui/mainWin/src/callbacks.h
ltt/branches/poly/lttv/modules/gui/mainWin/src/init_module.c
ltt/branches/poly/lttv/modules/guiEvents.c
ltt/branches/poly/lttv/modules/guiStatistic/guiStatistic.c

index c0213e8dfef3c62b49dbdf53b23699dc083ef0ea..391cef0fae8e074d187a58434175fcd44e51de59 100644 (file)
@@ -48,8 +48,8 @@ struct _mainWindow{
 
 struct _systemView{
   gpointer             EventDB;
-  gpointer           * SystemInfo;
-  gpointer           * Options;
+  gpointer             SystemInfo;
+  gpointer             Options;
   mainWindow         * Window;
   struct _systemView * Next;
 };
index 89cc8b1215decbb2efb1b489d681f20d61974aeb..9e5fe0a4b755009c63ba2d57fa93ee504bac35df 100644 (file)
@@ -22,6 +22,8 @@ extern LttvTracesetContext * gTracesetContext;
 /** Array containing instanced objects. */
 extern GSList * Main_Window_List;
 
+static int gWinCount = 0;
+
 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);
@@ -354,7 +356,8 @@ void
 on_quit_activate                       (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-  on_MWindow_destroy(GTK_OBJECT(menuitem), user_data);
+  mainWindow * mwData = get_window_data_struct((GtkWidget*)menuitem);
+  mainWindow_Destructor(mwData);  
 }
 
 
@@ -700,9 +703,10 @@ on_MWindow_destroy                     (GtkObject       *object,
                                         gpointer         user_data)
 {
   g_printf("There are : %d windows\n",g_slist_length(Main_Window_List));
-  
-  gtk_main_quit ();
 
+  gWinCount--;
+  if(gWinCount == 0)
+    gtk_main_quit ();
 }
 
 
@@ -849,13 +853,13 @@ void insertMenuToolbarItem(mainWindow * mw)
 
 void constructMainWin(mainWindow * parent, WindowCreationData * win_creation_data)
 {
-  systemView * sv = NULL; /* System view */
+  //  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;
+  //  if(parent) sv = parent->SystemView;
     
   newMWindow = g_new(mainWindow, 1);
 
@@ -866,10 +870,10 @@ void constructMainWin(mainWindow * parent, WindowCreationData * win_creation_dat
   gtk_widget_show (newWindow);
     
   newSv = g_new(systemView, 1);
-  if(sv){
-    while(sv->Next) sv = sv->Next;
-    sv->Next = newSv;
-  }
+  //  if(sv){
+  //    while(sv->Next) sv = sv->Next;
+  //    sv->Next = newSv;
+  //  }
 
   newSv->EventDB = NULL;
   newSv->SystemInfo = NULL;
@@ -907,6 +911,13 @@ void constructMainWin(mainWindow * parent, WindowCreationData * win_creation_dat
   //Use "Traceset" as the label for the default tab
   create_tab(newMWindow->MWindow, notebook,"Traceset");
 
+  g_object_set_data_full(
+                       G_OBJECT(newMWindow->MWindow),
+                       "Main_Window_Data",
+                       newMWindow,
+                       (GDestroyNotify)mainWindow_free);
+
+  gWinCount++;
 }
 
 void * create_tab(GtkWidget* parent, GtkNotebook * notebook, char * label)
index c07cc3b3b89c52005d5dcfb8566b33e1d43dd5f7..d85d0abebd194f77e6f77f1bbf79c380585740dc 100644 (file)
@@ -7,6 +7,8 @@
 void createNewWindow(GtkWidget* widget, gpointer user_data, gboolean clone);
 void insertMenuToolbarItem(mainWindow * mw);
 void constructMainWin(mainWindow * parent, WindowCreationData *win_creation_data);
+void mainWindow_free(mainWindow * mw);
+void mainWindow_Destructor(mainWindow * mw);
 
 /* callback functions*/
 
index aad203e2bba511b98370e27ad5a877393157071d..19cb148e841a0e77a281fc0de9acc7adcfc0a78b 100644 (file)
@@ -28,6 +28,7 @@
 /* global variable */
 LttvTracesetStats * gTracesetContext = NULL;
 static LttvTraceset * traceset;
+WindowCreationData  gWinCreationData;
 
 /** Array containing instanced objects. */
 GSList * Main_Window_List = NULL ;
@@ -84,7 +85,6 @@ static gboolean Window_Creation_Hook(void *hook_data, void *call_data)
 
   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);
   }
 
@@ -101,7 +101,6 @@ static gboolean Window_Creation_Hook(void *hook_data, void *call_data)
 G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) {
 
   LttvAttributeValue value;
-  WindowCreationData *Window_Creation_Data = g_new(WindowCreationData, 1);
   
   LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
   
@@ -152,16 +151,69 @@ G_MODULE_EXPORT void init(LttvModule *self, int argc, char *argv[]) {
       LTTV_POINTER, &value));
   g_assert((main_hooks = *(value.v_pointer)) != NULL);
 
-  Window_Creation_Data->argc = argc;
-  Window_Creation_Data->argv = argv;
+  gWinCreationData.argc = argc;
+  gWinCreationData.argv = argv;
   
-  lttv_hooks_add(main_hooks, Window_Creation_Hook, Window_Creation_Data);
+  lttv_hooks_add(main_hooks, Window_Creation_Hook, &gWinCreationData);
 
 }
 
+void
+free_system_view(systemView * SystemView)
+{
+  if(!SystemView)return;
+  //free_EventDB(SystemView->EventDB);
+  //free_SystemInfo(SystemView->SystemInfo);
+  //free_Options(SystemView->Options);
+  if(SystemView->Next)
+    free_system_view(SystemView->Next);
+  g_free(SystemView);
+}
+
+void free_tab(tab * Tab)
+{
+  if(!Tab) return;
+  if(Tab->custom->vbox)
+    gtk_widget_destroy(Tab->custom->vbox);
+  if(Tab->Attributes)
+    g_object_unref(Tab->Attributes);
+
+  if(Tab->Next) free_tab(Tab->Next);
+  g_free(Tab);
+}
+
+void
+mainWindow_free(mainWindow * mw)
+{ 
+  if(mw){
+    Main_Window_List = g_slist_remove(Main_Window_List, mw);
+    
+    //should free memory allocated dynamically first
+    free_system_view(mw->SystemView);
+    free_tab(mw->Tab);
+    g_object_unref(mw->Attributes);
+
+    g_free(mw);    
+  }
+}
+
+void
+mainWindow_Destructor(mainWindow * mw)
+{
+  if(GTK_IS_WIDGET(mw->MWindow)){
+    gtk_widget_destroy(mw->MWindow);
+    //    gtk_widget_destroy(mw->HelpContents);
+    //    gtk_widget_destroy(mw->AboutBox);    
+    mw = NULL;
+  }
+  
+  mainWindow_free(mw);
+}
+
+
 void destroy_walk(gpointer data, gpointer user_data)
 {
-       //GuiControlFlow_Destructor((ControlFlowData*)data);
+  mainWindow_Destructor((mainWindow*)data);
 }
 
 
@@ -174,8 +226,7 @@ void destroy_walk(gpointer data, gpointer user_data)
  */
 G_MODULE_EXPORT void destroy() {
 
-  WindowCreationData *Window_Creation_Data;
-  LttvAttributeValue value;
+  LttvAttributeValue value;  
 
   guint i, nb;
 
@@ -189,7 +240,7 @@ G_MODULE_EXPORT void destroy() {
   lttv_hooks_destroy(after_tracefile);
   lttv_hooks_destroy(before_event);
   lttv_hooks_destroy(after_event);
-  lttv_hooks_remove_data(main_hooks, Window_Creation_Hook, NULL);
+  lttv_hooks_remove_data(main_hooks, Window_Creation_Hook, &gWinCreationData);
 
   nb = lttv_traceset_number(traceset);
   for(i = 0 ; i < nb ; i++) {
@@ -200,18 +251,9 @@ G_MODULE_EXPORT void destroy() {
 
   g_critical("GUI destroy()");
 
-
-
-  //ControlFlowData *Control_Flow_Data;
-  
-
   g_slist_foreach(Main_Window_List, destroy_walk, NULL );
+  g_slist_free(Main_Window_List);
   
-  
-  //lttv_hooks_remove_data(main_hooks,Window_Creation_Hook, NULL);
-  //lttv_hooks_remove_data(before_traceset, get_traceset_context, NULL);
-
-  //  g_free(Window_Creation_Data);
 
   g_object_unref(gTracesetContext);
 }
index 0d3b9bc9f1f2a7193d0877c9f25353d0aa6b9132..dc062e7e03252721eaf9c88e58b6325223ea49b6 100644 (file)
@@ -1127,19 +1127,21 @@ void add_test_data(EventViewerData *Event_Viewer_Data)
 void
 GuiEvents_free(EventViewerData *Event_Viewer_Data)
 {
-  lttv_hooks_remove(Event_Viewer_Data->before_event_hooks,parse_event);
-  lttv_hooks_destroy(Event_Viewer_Data->before_event_hooks);
-  
-  remove_all_items_from_queue (Event_Viewer_Data->raw_trace_data_queue);
-  g_queue_free(Event_Viewer_Data->raw_trace_data_queue);
-  g_queue_free(Event_Viewer_Data->raw_trace_data_queue_tmp);
+  if(Event_Viewer_Data){
+    lttv_hooks_remove(Event_Viewer_Data->before_event_hooks,parse_event);
+    lttv_hooks_destroy(Event_Viewer_Data->before_event_hooks);
+    
+    remove_all_items_from_queue (Event_Viewer_Data->raw_trace_data_queue);
+    g_queue_free(Event_Viewer_Data->raw_trace_data_queue);
+    g_queue_free(Event_Viewer_Data->raw_trace_data_queue_tmp);
 
-  UnregUpdateTimeInterval(updateTimeInterval,Event_Viewer_Data, Event_Viewer_Data->mw);
-  UnregUpdateCurrentTime(updateCurrentTime,Event_Viewer_Data, Event_Viewer_Data->mw);
+    UnregUpdateTimeInterval(updateTimeInterval,Event_Viewer_Data, Event_Viewer_Data->mw);
+    UnregUpdateCurrentTime(updateCurrentTime,Event_Viewer_Data, Event_Viewer_Data->mw);
 
-  sEvent_Viewer_Data_List = g_slist_remove(sEvent_Viewer_Data_List, Event_Viewer_Data);
-  g_warning("Delete Event data\n");
-  g_free(Event_Viewer_Data);
+    sEvent_Viewer_Data_List = g_slist_remove(sEvent_Viewer_Data_List, Event_Viewer_Data);
+    g_warning("Delete Event data\n");
+    g_free(Event_Viewer_Data);
+  }
 }
 
 void
@@ -1148,8 +1150,10 @@ GuiEvents_Destructor(EventViewerData *Event_Viewer_Data)
   guint index;
 
   /* May already been done by GTK window closing */
-  if(GTK_IS_WIDGET(Event_Viewer_Data->HBox_V))
+  if(GTK_IS_WIDGET(Event_Viewer_Data->HBox_V)){
     gtk_widget_destroy(Event_Viewer_Data->HBox_V);
+    Event_Viewer_Data = NULL;
+  }
   
   /* Destroy the Tree View */
   //gtk_widget_destroy(Event_Viewer_Data->Tree_V);
index 081a537f2026a2ba5d6b076aec4b7ae2f69b9957..46fa5fb84c4769112e7ee00c4e4665f5870a0d10 100644 (file)
@@ -138,18 +138,22 @@ G_MODULE_EXPORT void destroy() {
 void
 GuiStatistic_free(StatisticViewerData *Statistic_Viewer_Data)
 { 
-  g_hash_table_destroy(Statistic_Viewer_Data->Statistic_Hash);
-  gStatistic_Viewer_Data_List = g_slist_remove(gStatistic_Viewer_Data_List, Statistic_Viewer_Data);
-  g_warning("Delete Statistic data\n");
-  g_free(Statistic_Viewer_Data);
+  if(Statistic_Viewer_Data){
+    g_hash_table_destroy(Statistic_Viewer_Data->Statistic_Hash);
+    gStatistic_Viewer_Data_List = g_slist_remove(gStatistic_Viewer_Data_List, Statistic_Viewer_Data);
+    g_warning("Delete Statistic data\n");
+    g_free(Statistic_Viewer_Data);
+  }
 }
 
 void
 GuiStatistic_Destructor(StatisticViewerData *Statistic_Viewer_Data)
 {
   /* May already been done by GTK window closing */
-  if(GTK_IS_WIDGET(Statistic_Viewer_Data->HPaned_V))
+  if(GTK_IS_WIDGET(Statistic_Viewer_Data->HPaned_V)){
     gtk_widget_destroy(Statistic_Viewer_Data->HPaned_V);
+    Statistic_Viewer_Data = NULL;
+  }
   
   GuiStatistic_free(Statistic_Viewer_Data);
 }
This page took 0.030868 seconds and 4 git commands to generate.