| 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 <glib/gprintf.h> |
| 25 | #include <gtk/gtk.h> |
| 26 | #include <gdk/gdk.h> |
| 27 | #include <lttv/lttv.h> |
| 28 | #include <lttvwindow/lttvwindow.h> |
| 29 | #include <lttvwindow/lttvwindowtraces.h> |
| 30 | #include <lttvwindow/support.h> |
| 31 | |
| 32 | #include "cfv.h" |
| 33 | #include "drawing.h" |
| 34 | #include "processlist.h" |
| 35 | #include "eventhooks.h" |
| 36 | #include "lttv_plugin_cfv.h" |
| 37 | |
| 38 | extern GSList *g_control_flow_data_list; |
| 39 | |
| 40 | static gboolean |
| 41 | header_size_allocate(GtkWidget *widget, |
| 42 | GtkAllocation *allocation, |
| 43 | gpointer user_data) |
| 44 | { |
| 45 | Drawing_t *drawing = (Drawing_t*)user_data; |
| 46 | |
| 47 | gtk_widget_set_size_request(drawing->ruler, -1, allocation->height); |
| 48 | //gtk_widget_queue_resize(drawing->padding); |
| 49 | //gtk_widget_queue_resize(drawing->ruler); |
| 50 | gtk_container_check_resize(GTK_CONTAINER(drawing->ruler_hbox)); |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | gboolean cfv_scroll_event(GtkWidget *widget, GdkEventScroll *event, |
| 55 | gpointer data) |
| 56 | { |
| 57 | ControlFlowData *control_flow_data = (ControlFlowData*)data; |
| 58 | unsigned int cell_height = |
| 59 | get_cell_height( |
| 60 | GTK_TREE_VIEW(control_flow_data->process_list->process_list_widget)); |
| 61 | gdouble new; |
| 62 | |
| 63 | switch(event->direction) { |
| 64 | case GDK_SCROLL_UP: |
| 65 | { |
| 66 | new = gtk_adjustment_get_value(control_flow_data->v_adjust) |
| 67 | - cell_height; |
| 68 | } |
| 69 | break; |
| 70 | case GDK_SCROLL_DOWN: |
| 71 | { |
| 72 | new = gtk_adjustment_get_value(control_flow_data->v_adjust) |
| 73 | + cell_height; |
| 74 | } |
| 75 | break; |
| 76 | default: |
| 77 | return FALSE; |
| 78 | } |
| 79 | if(new >= control_flow_data->v_adjust->lower && |
| 80 | new <= control_flow_data->v_adjust->upper |
| 81 | - control_flow_data->v_adjust->page_size) |
| 82 | gtk_adjustment_set_value(control_flow_data->v_adjust, new); |
| 83 | return TRUE; |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /* Toolbar callbacks */ |
| 88 | static void property_button (GtkToolButton *toolbutton, |
| 89 | gpointer user_data) |
| 90 | { |
| 91 | g_printf("CFV Property button clicked\n"); |
| 92 | |
| 93 | } |
| 94 | |
| 95 | /* Toolbar callbacks */ |
| 96 | static void filter_button (GtkToolButton *toolbutton, |
| 97 | gpointer user_data) |
| 98 | { |
| 99 | LttvPluginCFV *plugin_cfv = (LttvPluginCFV*)user_data; |
| 100 | LttvAttribute *attribute; |
| 101 | LttvAttributeValue value; |
| 102 | gboolean ret; |
| 103 | g_printf("Filter button clicked\n"); |
| 104 | |
| 105 | attribute = LTTV_ATTRIBUTE(lttv_iattribute_find_subdir( |
| 106 | LTTV_IATTRIBUTE(lttv_global_attributes()), |
| 107 | LTTV_VIEWER_CONSTRUCTORS)); |
| 108 | g_assert(attribute); |
| 109 | |
| 110 | ret = lttv_iattribute_find_by_path(LTTV_IATTRIBUTE(attribute), |
| 111 | "guifilter", LTTV_POINTER, &value); |
| 112 | g_assert(ret); |
| 113 | lttvwindow_viewer_constructor constructor = |
| 114 | (lttvwindow_viewer_constructor)*(value.v_pointer); |
| 115 | if(constructor) constructor(&plugin_cfv->parent); |
| 116 | else g_warning("Filter module not loaded."); |
| 117 | |
| 118 | //FIXME : viewer returned. |
| 119 | } |
| 120 | |
| 121 | static void legend_button(GtkToolButton *toolbutton, gpointer user_data) |
| 122 | { |
| 123 | GtkWindow *legend = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
| 124 | |
| 125 | gtk_window_set_title(legend, "Control Flow View Legend"); |
| 126 | |
| 127 | GtkWidget *pixmap = create_pixmap(GTK_WIDGET(legend), "controlflow-legend.png"); |
| 128 | |
| 129 | gtk_container_add(GTK_CONTAINER(legend), GTK_WIDGET(pixmap)); |
| 130 | |
| 131 | gtk_widget_show(GTK_WIDGET(pixmap)); |
| 132 | gtk_widget_show(GTK_WIDGET(legend)); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | |
| 137 | /***************************************************************************** |
| 138 | * Control Flow Viewer class implementation * |
| 139 | *****************************************************************************/ |
| 140 | /** |
| 141 | * Control Flow Viewer's constructor |
| 142 | * |
| 143 | * This constructor is given as a parameter to the menuitem and toolbar button |
| 144 | * registration. It creates the drawing widget. |
| 145 | * @param ParentWindow A pointer to the parent window. |
| 146 | * @return The widget created. |
| 147 | */ |
| 148 | ControlFlowData * |
| 149 | guicontrolflow(LttvPluginTab *ptab) |
| 150 | { |
| 151 | Tab *tab = ptab->tab; |
| 152 | GtkWidget *tmp_toolbar_icon; |
| 153 | GtkWidget *process_list_widget, *drawing_widget, *drawing_area; |
| 154 | //ControlFlowData* control_flow_data = g_new(ControlFlowData,1) ; |
| 155 | LttvPluginCFV *plugin_cfv = g_object_new(LTTV_TYPE_PLUGIN_CFV, NULL); |
| 156 | GtkTooltips *tooltips = gtk_tooltips_new(); |
| 157 | ControlFlowData* control_flow_data = plugin_cfv->cfd; |
| 158 | control_flow_data->ptab = ptab; |
| 159 | control_flow_data->tab = ptab->tab; |
| 160 | |
| 161 | control_flow_data->v_adjust = |
| 162 | GTK_ADJUSTMENT(gtk_adjustment_new( 0.0, /* Value */ |
| 163 | 0.0, /* Lower */ |
| 164 | 0.0, /* Upper */ |
| 165 | 0.0, /* Step inc. */ |
| 166 | 0.0, /* Page inc. */ |
| 167 | 0.0)); /* page size */ |
| 168 | |
| 169 | /* Create the drawing */ |
| 170 | control_flow_data->drawing = drawing_construct(control_flow_data); |
| 171 | |
| 172 | drawing_widget = |
| 173 | drawing_get_widget(control_flow_data->drawing); |
| 174 | |
| 175 | drawing_area = |
| 176 | drawing_get_drawing_area(control_flow_data->drawing); |
| 177 | |
| 178 | control_flow_data->number_of_process = 0; |
| 179 | control_flow_data->background_info_waiting = 0; |
| 180 | |
| 181 | /* Create the Process list */ |
| 182 | control_flow_data->process_list = processlist_construct(); |
| 183 | |
| 184 | process_list_widget = |
| 185 | processlist_get_widget(control_flow_data->process_list); |
| 186 | |
| 187 | gtk_tree_view_set_vadjustment(GTK_TREE_VIEW(process_list_widget), |
| 188 | GTK_ADJUSTMENT( |
| 189 | control_flow_data->v_adjust)); |
| 190 | |
| 191 | g_signal_connect (G_OBJECT(process_list_widget), |
| 192 | "scroll-event", |
| 193 | G_CALLBACK (cfv_scroll_event), |
| 194 | (gpointer)control_flow_data); |
| 195 | g_signal_connect (G_OBJECT(drawing_area), |
| 196 | "scroll-event", |
| 197 | G_CALLBACK (cfv_scroll_event), |
| 198 | (gpointer)control_flow_data); |
| 199 | |
| 200 | g_signal_connect (G_OBJECT(control_flow_data->process_list->button), |
| 201 | "size-allocate", |
| 202 | G_CALLBACK(header_size_allocate), |
| 203 | (gpointer)control_flow_data->drawing); |
| 204 | #if 0 /* not ready */ |
| 205 | g_signal_connect ( |
| 206 | // G_OBJECT(control_flow_data->process_list->process_list_widget), |
| 207 | G_OBJECT(control_flow_data->process_list->list_store), |
| 208 | "row-changed", |
| 209 | G_CALLBACK (tree_row_activated), |
| 210 | (gpointer)control_flow_data); |
| 211 | #endif //0 |
| 212 | |
| 213 | control_flow_data->hbox = gtk_hbox_new(FALSE, 1); |
| 214 | control_flow_data->toolbar = gtk_toolbar_new(); |
| 215 | gtk_toolbar_set_orientation(GTK_TOOLBAR(control_flow_data->toolbar), |
| 216 | GTK_ORIENTATION_VERTICAL); |
| 217 | |
| 218 | tmp_toolbar_icon = create_pixmap (main_window_get_widget(tab), |
| 219 | "guifilter16x16.png"); |
| 220 | gtk_widget_show(tmp_toolbar_icon); |
| 221 | control_flow_data->button_filter = gtk_tool_button_new(tmp_toolbar_icon, |
| 222 | "Filter"); |
| 223 | g_signal_connect (G_OBJECT(control_flow_data->button_filter), |
| 224 | "clicked", |
| 225 | G_CALLBACK (filter_button), |
| 226 | (gpointer)plugin_cfv); |
| 227 | gtk_toolbar_insert(GTK_TOOLBAR(control_flow_data->toolbar), |
| 228 | control_flow_data->button_filter, |
| 229 | 0); |
| 230 | gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(control_flow_data->button_filter), |
| 231 | tooltips, "Open the filter window", NULL); |
| 232 | |
| 233 | tmp_toolbar_icon = create_pixmap (main_window_get_widget(tab), |
| 234 | "properties.png"); |
| 235 | gtk_widget_show(tmp_toolbar_icon); |
| 236 | control_flow_data->button_prop = gtk_tool_button_new(tmp_toolbar_icon, |
| 237 | "Properties"); |
| 238 | g_signal_connect (G_OBJECT(control_flow_data->button_prop), |
| 239 | "clicked", |
| 240 | G_CALLBACK (property_button), |
| 241 | (gpointer)control_flow_data); |
| 242 | gtk_toolbar_insert(GTK_TOOLBAR(control_flow_data->toolbar), |
| 243 | control_flow_data->button_prop, |
| 244 | 1); |
| 245 | |
| 246 | tmp_toolbar_icon = create_pixmap (main_window_get_widget(tab), |
| 247 | "qmark.png"); |
| 248 | gtk_widget_show(tmp_toolbar_icon); |
| 249 | control_flow_data->button_legend = gtk_tool_button_new(tmp_toolbar_icon, |
| 250 | "Legend"); |
| 251 | g_signal_connect (G_OBJECT(control_flow_data->button_legend), |
| 252 | "clicked", |
| 253 | G_CALLBACK (legend_button), |
| 254 | (gpointer)plugin_cfv); |
| 255 | gtk_toolbar_insert(GTK_TOOLBAR(control_flow_data->toolbar), |
| 256 | control_flow_data->button_legend, |
| 257 | 0); |
| 258 | gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(control_flow_data->button_legend), |
| 259 | tooltips, "Show the legend", NULL); |
| 260 | |
| 261 | gtk_toolbar_set_style(GTK_TOOLBAR(control_flow_data->toolbar), |
| 262 | GTK_TOOLBAR_ICONS); |
| 263 | |
| 264 | gtk_box_pack_start(GTK_BOX(control_flow_data->hbox), |
| 265 | control_flow_data->toolbar, |
| 266 | FALSE, FALSE, 0); |
| 267 | control_flow_data->h_paned = gtk_hpaned_new(); |
| 268 | control_flow_data->box = gtk_event_box_new(); |
| 269 | gtk_box_pack_end(GTK_BOX(control_flow_data->hbox), |
| 270 | control_flow_data->box, |
| 271 | TRUE, TRUE, 0); |
| 272 | control_flow_data->top_widget = control_flow_data->hbox; |
| 273 | plugin_cfv->parent.top_widget = control_flow_data->top_widget; |
| 274 | gtk_container_add(GTK_CONTAINER(control_flow_data->box), |
| 275 | control_flow_data->h_paned); |
| 276 | |
| 277 | gtk_paned_pack1(GTK_PANED(control_flow_data->h_paned), |
| 278 | process_list_widget, FALSE, TRUE); |
| 279 | gtk_paned_pack2(GTK_PANED(control_flow_data->h_paned), |
| 280 | drawing_widget, TRUE, TRUE); |
| 281 | |
| 282 | gtk_container_set_border_width(GTK_CONTAINER(control_flow_data->box), 1); |
| 283 | |
| 284 | /* Set the size of the drawing area */ |
| 285 | //drawing_Resize(drawing, h, w); |
| 286 | |
| 287 | /* Get trace statistics */ |
| 288 | //control_flow_data->Trace_Statistics = get_trace_statistics(Trace); |
| 289 | |
| 290 | gtk_widget_show(drawing_widget); |
| 291 | gtk_widget_show(process_list_widget); |
| 292 | gtk_widget_show(control_flow_data->h_paned); |
| 293 | gtk_widget_show(control_flow_data->box); |
| 294 | gtk_widget_show(control_flow_data->toolbar); |
| 295 | //gtk_widget_show(GTK_WIDGET(control_flow_data->button_prop)); |
| 296 | gtk_widget_show(GTK_WIDGET(control_flow_data->button_filter)); |
| 297 | gtk_widget_show(GTK_WIDGET(control_flow_data->button_legend)); |
| 298 | gtk_widget_show(control_flow_data->hbox); |
| 299 | |
| 300 | g_object_set_data_full( |
| 301 | G_OBJECT(control_flow_data->top_widget), |
| 302 | "plugin_data", |
| 303 | plugin_cfv, |
| 304 | (GDestroyNotify)guicontrolflow_destructor); |
| 305 | |
| 306 | g_object_set_data( |
| 307 | G_OBJECT(drawing_area), |
| 308 | "control_flow_data", |
| 309 | control_flow_data); |
| 310 | |
| 311 | g_control_flow_data_list = g_slist_append( |
| 312 | g_control_flow_data_list, |
| 313 | plugin_cfv); |
| 314 | |
| 315 | control_flow_data->filter = NULL; |
| 316 | |
| 317 | //WARNING : The widget must be |
| 318 | //inserted in the main window before the drawing area |
| 319 | //can be configured (and this must happend bedore sending |
| 320 | //data) |
| 321 | |
| 322 | return control_flow_data; |
| 323 | |
| 324 | } |
| 325 | |
| 326 | /* Destroys widget also */ |
| 327 | void |
| 328 | guicontrolflow_destructor_full(gpointer data) |
| 329 | { |
| 330 | LttvPluginCFV *plugin_cfv = (LttvPluginCFV*)data; |
| 331 | g_info("CFV.c : guicontrolflow_destructor_full, %p", plugin_cfv); |
| 332 | /* May already have been done by GTK window closing */ |
| 333 | if(GTK_IS_WIDGET(guicontrolflow_get_widget(plugin_cfv->cfd))) |
| 334 | gtk_widget_destroy(guicontrolflow_get_widget(plugin_cfv->cfd)); |
| 335 | //control_flow_data->mw = NULL; |
| 336 | //FIXME guicontrolflow_destructor(control_flow_data); |
| 337 | } |
| 338 | |
| 339 | /* When this destructor is called, the widgets are already disconnected */ |
| 340 | void |
| 341 | guicontrolflow_destructor(gpointer data) |
| 342 | { |
| 343 | LttvPluginCFV *plugin_cfv = (LttvPluginCFV*)data; |
| 344 | Tab *tab = plugin_cfv->cfd->tab; |
| 345 | ControlFlowData *control_flow_data = plugin_cfv->cfd; |
| 346 | |
| 347 | g_info("CFV.c : guicontrolflow_destructor, %p", plugin_cfv); |
| 348 | g_info("%p, %p, %p", update_time_window_hook, plugin_cfv, tab); |
| 349 | if(GTK_IS_WIDGET(guicontrolflow_get_widget(plugin_cfv->cfd))) |
| 350 | g_info("widget still exists"); |
| 351 | |
| 352 | lttv_filter_destroy(plugin_cfv->cfd->filter); |
| 353 | /* Process List is removed with it's widget */ |
| 354 | //ProcessList_destroy(control_flow_data->process_list); |
| 355 | if(tab != NULL) |
| 356 | { |
| 357 | /* Delete reading hooks */ |
| 358 | lttvwindow_unregister_traceset_notify(tab, |
| 359 | traceset_notify, |
| 360 | control_flow_data); |
| 361 | |
| 362 | lttvwindow_unregister_time_window_notify(tab, |
| 363 | update_time_window_hook, |
| 364 | control_flow_data); |
| 365 | |
| 366 | lttvwindow_unregister_current_time_notify(tab, |
| 367 | update_current_time_hook, |
| 368 | control_flow_data); |
| 369 | |
| 370 | lttvwindow_unregister_redraw_notify(tab, redraw_notify, control_flow_data); |
| 371 | lttvwindow_unregister_continue_notify(tab, |
| 372 | continue_notify, |
| 373 | control_flow_data); |
| 374 | |
| 375 | lttvwindow_events_request_remove_all(control_flow_data->tab, |
| 376 | control_flow_data); |
| 377 | |
| 378 | } |
| 379 | lttvwindowtraces_background_notify_remove(control_flow_data); |
| 380 | g_control_flow_data_list = |
| 381 | g_slist_remove(g_control_flow_data_list, control_flow_data); |
| 382 | |
| 383 | g_info("CFV.c : guicontrolflow_destructor end, %p", control_flow_data); |
| 384 | //g_free(control_flow_data); |
| 385 | g_object_unref(plugin_cfv); |
| 386 | } |
| 387 | |
| 388 | |