| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2003-2004 Mathieu Desnoyers |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License Version 2 as |
| 6 | * published by the Free Software Foundation; |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 16 | * MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #ifdef HAVE_CONFIG_H |
| 20 | #include <config.h> |
| 21 | #endif |
| 22 | |
| 23 | #include <glib.h> |
| 24 | #include <gtk/gtk.h> |
| 25 | #include <gdk/gdk.h> |
| 26 | #include <lttv/lttv.h> |
| 27 | #include <lttvwindow/lttvwindow.h> |
| 28 | |
| 29 | #include "cfv.h" |
| 30 | #include "drawing.h" |
| 31 | #include "processlist.h" |
| 32 | #include "eventhooks.h" |
| 33 | |
| 34 | extern GSList *g_control_flow_data_list; |
| 35 | |
| 36 | static gboolean |
| 37 | header_size_allocate(GtkWidget *widget, |
| 38 | GtkAllocation *allocation, |
| 39 | gpointer user_data) |
| 40 | { |
| 41 | Drawing_t *drawing = (Drawing_t*)user_data; |
| 42 | |
| 43 | gtk_widget_set_size_request(drawing->ruler, -1, allocation->height); |
| 44 | //gtk_widget_queue_resize(drawing->padding); |
| 45 | //gtk_widget_queue_resize(drawing->ruler); |
| 46 | gtk_container_check_resize(GTK_CONTAINER(drawing->ruler_hbox)); |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | gboolean cfv_scroll_event(GtkWidget *widget, GdkEventScroll *event, |
| 51 | gpointer data) |
| 52 | { |
| 53 | ControlFlowData *control_flow_data = (ControlFlowData*)data; |
| 54 | unsigned int cell_height = |
| 55 | get_cell_height( |
| 56 | GTK_TREE_VIEW(control_flow_data->process_list->process_list_widget)); |
| 57 | gdouble new; |
| 58 | |
| 59 | switch(event->direction) { |
| 60 | case GDK_SCROLL_UP: |
| 61 | { |
| 62 | new = gtk_adjustment_get_value(control_flow_data->v_adjust) |
| 63 | - cell_height; |
| 64 | } |
| 65 | break; |
| 66 | case GDK_SCROLL_DOWN: |
| 67 | { |
| 68 | new = gtk_adjustment_get_value(control_flow_data->v_adjust) |
| 69 | + cell_height; |
| 70 | } |
| 71 | break; |
| 72 | default: |
| 73 | return FALSE; |
| 74 | } |
| 75 | if(new >= control_flow_data->v_adjust->lower && |
| 76 | new <= control_flow_data->v_adjust->upper |
| 77 | - control_flow_data->v_adjust->page_size) |
| 78 | gtk_adjustment_set_value(control_flow_data->v_adjust, new); |
| 79 | return TRUE; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | /***************************************************************************** |
| 84 | * Control Flow Viewer class implementation * |
| 85 | *****************************************************************************/ |
| 86 | /** |
| 87 | * Control Flow Viewer's constructor |
| 88 | * |
| 89 | * This constructor is given as a parameter to the menuitem and toolbar button |
| 90 | * registration. It creates the drawing widget. |
| 91 | * @param ParentWindow A pointer to the parent window. |
| 92 | * @return The widget created. |
| 93 | */ |
| 94 | ControlFlowData * |
| 95 | guicontrolflow(Tab *tab) |
| 96 | { |
| 97 | GtkWidget *process_list_widget, *drawing_widget, *drawing_area; |
| 98 | |
| 99 | ControlFlowData* control_flow_data = g_new(ControlFlowData,1) ; |
| 100 | |
| 101 | control_flow_data->tab = tab; |
| 102 | |
| 103 | control_flow_data->v_adjust = |
| 104 | GTK_ADJUSTMENT(gtk_adjustment_new( 0.0, /* Value */ |
| 105 | 0.0, /* Lower */ |
| 106 | 0.0, /* Upper */ |
| 107 | 0.0, /* Step inc. */ |
| 108 | 0.0, /* Page inc. */ |
| 109 | 0.0)); /* page size */ |
| 110 | |
| 111 | /* Create the drawing */ |
| 112 | control_flow_data->drawing = drawing_construct(control_flow_data); |
| 113 | |
| 114 | drawing_widget = |
| 115 | drawing_get_widget(control_flow_data->drawing); |
| 116 | |
| 117 | drawing_area = |
| 118 | drawing_get_drawing_area(control_flow_data->drawing); |
| 119 | |
| 120 | control_flow_data->number_of_process = 0; |
| 121 | control_flow_data->background_info_waiting = 0; |
| 122 | |
| 123 | /* Create the Process list */ |
| 124 | control_flow_data->process_list = processlist_construct(); |
| 125 | |
| 126 | process_list_widget = |
| 127 | processlist_get_widget(control_flow_data->process_list); |
| 128 | |
| 129 | gtk_tree_view_set_vadjustment(GTK_TREE_VIEW(process_list_widget), |
| 130 | GTK_ADJUSTMENT( |
| 131 | control_flow_data->v_adjust)); |
| 132 | |
| 133 | g_signal_connect (G_OBJECT(process_list_widget), |
| 134 | "scroll-event", |
| 135 | G_CALLBACK (cfv_scroll_event), |
| 136 | (gpointer)control_flow_data); |
| 137 | g_signal_connect (G_OBJECT(drawing_area), |
| 138 | "scroll-event", |
| 139 | G_CALLBACK (cfv_scroll_event), |
| 140 | (gpointer)control_flow_data); |
| 141 | |
| 142 | g_signal_connect (G_OBJECT(control_flow_data->process_list->button), |
| 143 | "size-allocate", |
| 144 | G_CALLBACK(header_size_allocate), |
| 145 | (gpointer)control_flow_data->drawing); |
| 146 | #if 0 /* not ready */ |
| 147 | g_signal_connect ( |
| 148 | // G_OBJECT(control_flow_data->process_list->process_list_widget), |
| 149 | G_OBJECT(control_flow_data->process_list->list_store), |
| 150 | "row-changed", |
| 151 | G_CALLBACK (tree_row_activated), |
| 152 | (gpointer)control_flow_data); |
| 153 | #endif //0 |
| 154 | |
| 155 | control_flow_data->h_paned = gtk_hpaned_new(); |
| 156 | control_flow_data->box = gtk_event_box_new(); |
| 157 | control_flow_data->top_widget = control_flow_data->box; |
| 158 | gtk_container_add(GTK_CONTAINER(control_flow_data->box), |
| 159 | control_flow_data->h_paned); |
| 160 | |
| 161 | gtk_paned_pack1(GTK_PANED(control_flow_data->h_paned), |
| 162 | process_list_widget, FALSE, TRUE); |
| 163 | gtk_paned_pack2(GTK_PANED(control_flow_data->h_paned), |
| 164 | drawing_widget, TRUE, TRUE); |
| 165 | |
| 166 | gtk_container_set_border_width(GTK_CONTAINER(control_flow_data->box), 1); |
| 167 | |
| 168 | /* Set the size of the drawing area */ |
| 169 | //drawing_Resize(drawing, h, w); |
| 170 | |
| 171 | /* Get trace statistics */ |
| 172 | //control_flow_data->Trace_Statistics = get_trace_statistics(Trace); |
| 173 | |
| 174 | gtk_widget_show(drawing_widget); |
| 175 | gtk_widget_show(process_list_widget); |
| 176 | gtk_widget_show(control_flow_data->h_paned); |
| 177 | gtk_widget_show(control_flow_data->box); |
| 178 | |
| 179 | g_object_set_data_full( |
| 180 | G_OBJECT(control_flow_data->top_widget), |
| 181 | "control_flow_data", |
| 182 | control_flow_data, |
| 183 | (GDestroyNotify)guicontrolflow_destructor); |
| 184 | |
| 185 | g_object_set_data( |
| 186 | G_OBJECT(drawing_area), |
| 187 | "control_flow_data", |
| 188 | control_flow_data); |
| 189 | |
| 190 | g_control_flow_data_list = g_slist_append( |
| 191 | g_control_flow_data_list, |
| 192 | control_flow_data); |
| 193 | |
| 194 | //WARNING : The widget must be |
| 195 | //inserted in the main window before the drawing area |
| 196 | //can be configured (and this must happend bedore sending |
| 197 | //data) |
| 198 | |
| 199 | return control_flow_data; |
| 200 | |
| 201 | } |
| 202 | |
| 203 | /* Destroys widget also */ |
| 204 | void |
| 205 | guicontrolflow_destructor_full(ControlFlowData *control_flow_data) |
| 206 | { |
| 207 | g_info("CFV.c : guicontrolflow_destructor_full, %p", control_flow_data); |
| 208 | /* May already have been done by GTK window closing */ |
| 209 | if(GTK_IS_WIDGET(guicontrolflow_get_widget(control_flow_data))) |
| 210 | gtk_widget_destroy(guicontrolflow_get_widget(control_flow_data)); |
| 211 | //control_flow_data->mw = NULL; |
| 212 | //FIXME guicontrolflow_destructor(control_flow_data); |
| 213 | } |
| 214 | |
| 215 | /* When this destructor is called, the widgets are already disconnected */ |
| 216 | void |
| 217 | guicontrolflow_destructor(ControlFlowData *control_flow_data) |
| 218 | { |
| 219 | Tab *tab = control_flow_data->tab; |
| 220 | |
| 221 | g_info("CFV.c : guicontrolflow_destructor, %p", control_flow_data); |
| 222 | g_info("%p, %p, %p", update_time_window_hook, control_flow_data, tab); |
| 223 | if(GTK_IS_WIDGET(guicontrolflow_get_widget(control_flow_data))) |
| 224 | g_info("widget still exists"); |
| 225 | |
| 226 | /* Process List is removed with it's widget */ |
| 227 | //ProcessList_destroy(control_flow_data->process_list); |
| 228 | if(tab != NULL) |
| 229 | { |
| 230 | /* Delete reading hooks */ |
| 231 | lttvwindow_unregister_traceset_notify(tab, |
| 232 | traceset_notify, |
| 233 | control_flow_data); |
| 234 | |
| 235 | lttvwindow_unregister_time_window_notify(tab, |
| 236 | update_time_window_hook, |
| 237 | control_flow_data); |
| 238 | |
| 239 | lttvwindow_unregister_current_time_notify(tab, |
| 240 | update_current_time_hook, |
| 241 | control_flow_data); |
| 242 | |
| 243 | lttvwindow_unregister_redraw_notify(tab, redraw_notify, control_flow_data); |
| 244 | lttvwindow_unregister_continue_notify(tab, |
| 245 | continue_notify, |
| 246 | control_flow_data); |
| 247 | |
| 248 | lttvwindow_events_request_remove_all(control_flow_data->tab, |
| 249 | control_flow_data); |
| 250 | |
| 251 | } |
| 252 | lttvwindowtraces_background_notify_remove(control_flow_data); |
| 253 | g_control_flow_data_list = |
| 254 | g_slist_remove(g_control_flow_data_list,control_flow_data); |
| 255 | |
| 256 | g_info("CFV.c : guicontrolflow_destructor end, %p", control_flow_data); |
| 257 | g_free(control_flow_data); |
| 258 | |
| 259 | } |
| 260 | |
| 261 | |