03d7fdf3 |
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 "xfv.h" |
32 | #include "xenoltt_drawing.h" |
33 | #include "xenoltt_threadlist.h" |
34 | #include "xenoltt_eventhooks.h" |
35 | #include "lttv_plugin_xfv.h" |
36 | |
37 | extern GSList *g_xenoltt_data_list; |
38 | |
39 | static gboolean header_size_allocate(GtkWidget *widget,GtkAllocation *allocation,gpointer user_data){ |
40 | XenoLtt_Drawing_t *drawing = (XenoLtt_Drawing_t*)user_data; |
41 | |
42 | gtk_widget_set_size_request(drawing->ruler, -1, allocation->height); |
43 | gtk_container_check_resize(GTK_CONTAINER(drawing->ruler_hbox)); |
44 | return 0; |
45 | } |
46 | |
47 | gboolean xfv_scroll_event(GtkWidget *widget, GdkEventScroll *event,gpointer data){ |
48 | XenoLTTData *xenoltt_data = (XenoLTTData*)data; |
49 | unsigned int cell_height = get_cell_height(GTK_TREE_VIEW(xenoltt_data->thread_list->thread_list_widget)); |
50 | gdouble new; |
51 | |
52 | switch(event->direction) { |
53 | case GDK_SCROLL_UP: |
54 | { |
55 | new = gtk_adjustment_get_value(xenoltt_data->v_adjust) - cell_height; |
56 | } |
57 | break; |
58 | case GDK_SCROLL_DOWN: |
59 | { |
60 | new = gtk_adjustment_get_value(xenoltt_data->v_adjust) + cell_height; |
61 | } |
62 | break; |
63 | default: |
64 | return FALSE; |
65 | } |
66 | if(new >= xenoltt_data->v_adjust->lower && |
67 | new <= xenoltt_data->v_adjust->upper |
68 | - xenoltt_data->v_adjust->page_size) |
69 | gtk_adjustment_set_value(xenoltt_data->v_adjust, new); |
70 | return TRUE; |
71 | } |
72 | |
73 | |
74 | /* Toolbar callbacks */ |
75 | static void property_button(GtkToolButton *toolbutton, gpointer user_data) |
76 | { |
77 | XenoLTTData *xenoltt_data = (XenoLTTData*)user_data; |
78 | |
79 | g_printf("CFV Property button clicked\n"); |
80 | |
81 | } |
82 | |
83 | /* Toolbar callbacks */ |
84 | static void filter_button (GtkToolButton *toolbutton, |
85 | gpointer user_data) |
86 | { |
87 | LttvPluginXFV *plugin_xfv = (LttvPluginXFV*)user_data; |
88 | LttvAttribute *attribute; |
89 | LttvAttributeValue value; |
90 | gboolean ret; |
91 | g_printf("Filter button clicked\n"); |
92 | |
93 | attribute = LTTV_ATTRIBUTE(lttv_iattribute_find_subdir( |
94 | LTTV_IATTRIBUTE(lttv_global_attributes()), |
95 | LTTV_VIEWER_CONSTRUCTORS)); |
96 | g_assert(attribute); |
97 | |
98 | ret = lttv_iattribute_find_by_path(LTTV_IATTRIBUTE(attribute), |
99 | "guifilter", LTTV_POINTER, &value); |
100 | g_assert(ret); |
101 | lttvwindow_viewer_constructor constructor = |
102 | (lttvwindow_viewer_constructor)*(value.v_pointer); |
103 | if(constructor) constructor(&plugin_xfv->parent); |
104 | else g_warning("Filter module not loaded."); |
105 | |
106 | //FIXME : viewer returned. |
107 | } |
108 | |
109 | |
110 | |
111 | /***************************************************************************** |
112 | * XenoLTT Viewer class implementation * |
113 | *****************************************************************************/ |
114 | /** |
115 | * XenoLTT Viewer's constructor |
116 | * |
117 | * This constructor is given as a parameter to the menuitem and toolbar button |
118 | * registration. It creates the drawing widget. |
119 | * @param ParentWindow A pointer to the parent window. |
120 | * @return The widget created. |
121 | */ |
122 | XenoLTTData *guixenoltt(LttvPluginTab *ptab){ |
123 | Tab *tab = ptab->tab; |
124 | GtkWidget *tmp_toolbar_icon; |
125 | GtkWidget *thread_list_widget, *drawing_widget, *drawing_area; |
126 | LttvPluginXFV *plugin_xfv = g_object_new(LTTV_TYPE_PLUGIN_XFV, NULL); |
127 | XenoLTTData* xenoltt_data = plugin_xfv->xfd; |
128 | xenoltt_data->ptab = ptab; |
129 | xenoltt_data->tab = ptab->tab; |
130 | |
131 | xenoltt_data->v_adjust = GTK_ADJUSTMENT(gtk_adjustment_new( 0.0, /* Value */ |
132 | 0.0, /* Lower */ |
133 | 0.0, /* Upper */ |
134 | 0.0, /* Step inc. */ |
135 | 0.0, /* Page inc. */ |
136 | 0.0)); /* page size */ |
137 | |
138 | /* Create the drawing */ |
139 | xenoltt_data->drawing = xenoltt_drawing_construct(xenoltt_data); |
140 | |
141 | drawing_widget = drawing_get_widget(xenoltt_data->drawing); |
142 | |
143 | drawing_area = drawing_get_drawing_area(xenoltt_data->drawing); |
144 | |
145 | xenoltt_data->number_of_thread = 0; |
146 | xenoltt_data->background_info_waiting = 0; |
147 | |
148 | /* Create the Thread list */ |
149 | xenoltt_data->thread_list = threadlist_construct(); |
150 | |
151 | thread_list_widget = threadlist_get_widget(xenoltt_data->thread_list); |
152 | |
153 | gtk_tree_view_set_vadjustment(GTK_TREE_VIEW(thread_list_widget),GTK_ADJUSTMENT(xenoltt_data->v_adjust)); |
154 | |
155 | g_signal_connect (G_OBJECT(thread_list_widget), |
156 | "scroll-event", |
157 | G_CALLBACK (xfv_scroll_event), |
158 | (gpointer)xenoltt_data); |
159 | g_signal_connect (G_OBJECT(drawing_area), |
160 | "scroll-event", |
161 | G_CALLBACK (xfv_scroll_event), |
162 | (gpointer)xenoltt_data); |
163 | |
164 | g_signal_connect (G_OBJECT(xenoltt_data->thread_list->button), |
165 | "size-allocate", |
166 | G_CALLBACK(header_size_allocate), |
167 | (gpointer)xenoltt_data->drawing); |
168 | |
169 | xenoltt_data->hbox = gtk_hbox_new(FALSE, 1); |
170 | xenoltt_data->toolbar = gtk_toolbar_new(); |
171 | gtk_toolbar_set_orientation(GTK_TOOLBAR(xenoltt_data->toolbar), |
172 | GTK_ORIENTATION_VERTICAL); |
173 | |
174 | tmp_toolbar_icon = create_pixmap (main_window_get_widget(tab), |
175 | "guifilter16x16.png"); |
176 | gtk_widget_show(tmp_toolbar_icon); |
177 | xenoltt_data->button_filter = gtk_tool_button_new(tmp_toolbar_icon, |
178 | "Filter"); |
179 | g_signal_connect (G_OBJECT(xenoltt_data->button_filter), |
180 | "clicked", |
181 | G_CALLBACK (filter_button), |
182 | (gpointer)plugin_xfv); |
183 | gtk_toolbar_insert(GTK_TOOLBAR(xenoltt_data->toolbar), |
184 | xenoltt_data->button_filter, |
185 | 0); |
186 | |
187 | tmp_toolbar_icon = create_pixmap (main_window_get_widget(tab), |
188 | "properties.png"); |
189 | gtk_widget_show(tmp_toolbar_icon); |
190 | xenoltt_data->button_prop = gtk_tool_button_new(tmp_toolbar_icon, |
191 | "Properties"); |
192 | g_signal_connect (G_OBJECT(xenoltt_data->button_prop), |
193 | "clicked", |
194 | G_CALLBACK (property_button), |
195 | (gpointer)xenoltt_data); |
196 | gtk_toolbar_insert(GTK_TOOLBAR(xenoltt_data->toolbar),xenoltt_data->button_prop,1); |
197 | |
198 | gtk_toolbar_set_style(GTK_TOOLBAR(xenoltt_data->toolbar),GTK_TOOLBAR_ICONS); |
199 | |
200 | gtk_box_pack_start(GTK_BOX(xenoltt_data->hbox), xenoltt_data->toolbar,FALSE, FALSE, 0); |
201 | |
202 | xenoltt_data->h_paned = gtk_hpaned_new(); |
203 | xenoltt_data->box = gtk_event_box_new(); |
204 | gtk_box_pack_end(GTK_BOX(xenoltt_data->hbox), xenoltt_data->box,TRUE, TRUE, 0); |
205 | xenoltt_data->top_widget = xenoltt_data->hbox; |
206 | plugin_xfv->parent.top_widget = xenoltt_data->top_widget; |
207 | gtk_container_add(GTK_CONTAINER(xenoltt_data->box),xenoltt_data->h_paned); |
208 | |
209 | gtk_paned_pack1(GTK_PANED(xenoltt_data->h_paned),thread_list_widget, FALSE, TRUE); |
210 | gtk_paned_pack2(GTK_PANED(xenoltt_data->h_paned),drawing_widget, TRUE, TRUE); |
211 | |
212 | gtk_container_set_border_width(GTK_CONTAINER(xenoltt_data->box), 1); |
213 | |
214 | |
215 | gtk_widget_show(drawing_widget); |
216 | gtk_widget_show(thread_list_widget); |
217 | gtk_widget_show(xenoltt_data->h_paned); |
218 | gtk_widget_show(xenoltt_data->box); |
219 | // gtk_widget_show(xenoltt_data->toolbar); |
220 | // gtk_widget_show(GTK_WIDGET(xenoltt_data->button_prop)); |
221 | // gtk_widget_show(GTK_WIDGET(xenoltt_data->button_filter)); |
222 | gtk_widget_show(xenoltt_data->hbox); |
223 | |
224 | g_object_set_data_full( |
225 | G_OBJECT(xenoltt_data->top_widget), |
226 | "plugin_data", |
227 | plugin_xfv, |
228 | (GDestroyNotify)guixenoltt_destructor); |
229 | |
230 | g_object_set_data( |
231 | G_OBJECT(drawing_area), |
232 | "xenoltt_data", |
233 | xenoltt_data); |
234 | |
235 | g_xenoltt_data_list = g_slist_append(g_xenoltt_data_list,plugin_xfv); |
236 | |
237 | |
238 | xenoltt_data->filter = NULL; |
239 | |
240 | //WARNING : The widget must be |
241 | //inserted in the main window before the drawing area |
242 | //can be configured (and this must happend bedore sending |
243 | //data) |
244 | return xenoltt_data; |
245 | |
246 | } |
247 | |
248 | /* Destroys widget also */ |
249 | void guixenoltt_destructor_full(gpointer data){ |
250 | LttvPluginXFV *plugin_xfv = (LttvPluginXFV*)data; |
251 | g_info("XFV.c : guixenoltt_destructor_full, %p", plugin_xfv); |
252 | /* May already have been done by GTK window closing */ |
253 | if(GTK_IS_WIDGET(guixenoltt_get_widget(plugin_xfv->xfd))) |
254 | gtk_widget_destroy(guixenoltt_get_widget(plugin_xfv->xfd)); |
255 | } |
256 | |
257 | /* When this destructor is called, the widgets are already disconnected */ |
258 | void guixenoltt_destructor(gpointer data){ |
259 | LttvPluginXFV *plugin_xfv = (LttvPluginXFV*)data; |
260 | Tab *tab = plugin_xfv->xfd->tab; |
261 | XenoLTTData *xenoltt_data = plugin_xfv->xfd; |
262 | |
263 | g_info("CFV.c : guixenoltt_destructor, %p", plugin_xfv); |
264 | g_info("%p, %p, %p", update_time_window_hook, plugin_xfv, tab); |
265 | if(GTK_IS_WIDGET(guixenoltt_get_widget(plugin_xfv->xfd))) |
266 | g_info("widget still exists"); |
267 | |
268 | lttv_filter_destroy(plugin_xfv->xfd->filter); |
269 | /* Thread List is removed with it's widget */ |
270 | if(tab != NULL){ |
271 | /* Delete reading hooks */ |
272 | lttvwindow_unregister_traceset_notify(tab,traceset_notify,xenoltt_data); |
273 | |
274 | lttvwindow_unregister_time_window_notify(tab,update_time_window_hook,xenoltt_data); |
275 | |
276 | lttvwindow_unregister_current_time_notify(tab,update_current_time_hook,xenoltt_data); |
277 | |
278 | lttvwindow_unregister_redraw_notify(tab, redraw_notify, xenoltt_data); |
279 | lttvwindow_unregister_continue_notify(tab,continue_notify,xenoltt_data); |
280 | |
281 | lttvwindow_events_request_remove_all(xenoltt_data->tab,xenoltt_data); |
282 | |
283 | } |
284 | lttvwindowtraces_background_notify_remove(xenoltt_data); |
285 | g_xenoltt_data_list = g_slist_remove(g_xenoltt_data_list, xenoltt_data); |
286 | |
287 | g_info("XFV.c : guixenoltt_destructor end, %p", xenoltt_data); |
288 | g_object_unref(plugin_xfv); |
289 | } |
290 | |
291 | |