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