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