traceset per tab
[lttv.git] / ltt / branches / poly / lttv / modules / gui / mainWin / src / gtkcustom.c
1 #include <gtk/gtk.h>
2
3 #include <lttv/gtkcustom.h>
4 //#include "gtkintl.h"
5 #include <lttv/mainWindow.h>
6 #include <lttv/gtkTraceSet.h>
7
8 static void gtk_custom_class_init (GtkCustomClass *klass);
9 static void gtk_custom_init (GtkCustom *custom);
10
11
12 static void gtk_custom_size_request (GtkWidget *widget,
13 GtkRequisition *requisition);
14 static void gtk_custom_size_allocate (GtkWidget *widget,
15 GtkAllocation *allocation);
16
17 void gtk_custom_scroll_value_changed (GtkRange *range, gpointer custom);
18
19 GType
20 gtk_custom_get_type (void)
21 {
22 static GType custom_type = 0;
23
24 if (!custom_type)
25 {
26 static const GTypeInfo custom_info =
27 {
28 sizeof (GtkCustomClass),
29 NULL, /* base_init */
30 NULL, /* base_finalize */
31 (GClassInitFunc) gtk_custom_class_init,
32 NULL, /* class_finalize */
33 NULL, /* class_data */
34 sizeof (GtkCustom),
35 0, /* n_preallocs */
36 (GInstanceInitFunc) gtk_custom_init,
37 NULL, /* value_table */
38 };
39
40 custom_type = g_type_register_static (GTK_TYPE_PANED, "GtkCustom",
41 &custom_info, 0);
42 }
43
44 return custom_type;
45 }
46
47 static void
48 gtk_custom_class_init (GtkCustomClass *class)
49 {
50 GtkWidgetClass *widget_class;
51
52 widget_class = (GtkWidgetClass *) class;
53
54 widget_class->size_request = gtk_custom_size_request;
55 widget_class->size_allocate = gtk_custom_size_allocate;
56 }
57
58 static void
59 gtk_custom_init (GtkCustom *custom)
60 {
61 GtkWidget * button;
62
63 GTK_WIDGET_SET_FLAGS (custom, GTK_NO_WINDOW);
64 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (custom), FALSE);
65
66 custom->first_pane = NULL;
67 custom->last_pane = NULL;
68 custom->focused_pane = NULL;
69 custom->num_children = 0;
70
71 custom->vbox = NULL;
72 // custom->scrollWindow = NULL;
73 // custom->viewport = NULL;
74 custom->hscrollbar = NULL;
75 }
76
77
78 GtkWidget* gtk_custom_new ()
79 {
80 return GTK_WIDGET (g_object_new (gtk_custom_get_type (), NULL));
81 }
82
83
84 void gtk_custom_set_focus (GtkWidget * widget, gpointer user_data)
85 {
86 GtkCustom * custom = (GtkCustom*) widget;
87 GtkPaned * pane;
88 if(!custom->first_pane) return;
89
90
91 pane = custom->first_pane;
92 while(1){
93 if((GtkWidget*)pane == (GtkWidget*)user_data){
94 custom->focused_pane = pane;
95 break;
96 }
97 if(pane == custom->last_pane){
98 custom->focused_pane = NULL;
99 break;
100 }
101 pane = (GtkPaned*)pane->child1;
102 }
103 }
104
105 void gtk_custom_set_adjust(GtkCustom * custom, gboolean first_time)
106 {
107 TimeWindow time_window;
108 TimeInterval *time_span;
109 double tmp, start;
110 double range = 0;
111
112 get_time_window(custom->mw,&time_window);
113 if(first_time){
114 time_span = LTTV_TRACESET_CONTEXT(custom->mw->current_tab->traceset_info->
115 traceset_context)->Time_Span ;
116
117 custom->hadjust->lower = ltt_time_to_double(time_span->startTime) *
118 NANOSECONDS_PER_SECOND;
119 custom->hadjust->value = custom->hadjust->lower;
120 custom->hadjust->upper = ltt_time_to_double(time_span->endTime) *
121 NANOSECONDS_PER_SECOND;
122 }
123
124 /* Page increment of whole visible area */
125 if(custom->hadjust == NULL){
126 g_warning("Insert a viewer first");
127 return;
128 }
129
130 start = ltt_time_to_double(time_window.start_time) * NANOSECONDS_PER_SECOND;
131 tmp = custom->hadjust->upper - custom->hadjust->lower;
132
133 custom->hadjust->page_increment = ltt_time_to_double(
134 time_window.time_width) * NANOSECONDS_PER_SECOND;
135
136 if(custom->hadjust->page_increment >= tmp - range)
137 custom->hadjust->value = custom->hadjust->lower;
138 if(start + custom->hadjust->page_increment >= custom->hadjust->upper - range)
139 custom->hadjust->value = start;
140
141 /* page_size to the whole visible area will take care that the
142 * scroll value + the shown area will never be more than what is
143 * in the trace. */
144 custom->hadjust->page_size = custom->hadjust->page_increment;
145 custom->hadjust->step_increment = custom->hadjust->page_increment / 10;
146
147 gtk_adjustment_changed (custom->hadjust);
148 }
149
150 void gtk_custom_widget_add(GtkCustom * custom, GtkWidget * widget1)
151 {
152 GtkPaned * tmpPane;
153 GtkWidget * w;
154
155 g_return_if_fail(GTK_IS_CUSTOM(custom));
156 g_object_ref(G_OBJECT(widget1));
157
158
159 if(!custom->first_pane){
160 custom->first_pane = (GtkPaned *)gtk_vpaned_new();
161 custom->last_pane = custom->first_pane;
162
163 custom->hscrollbar = gtk_hscrollbar_new (NULL);
164 gtk_widget_show(custom->hscrollbar);
165
166 custom->hadjust = gtk_range_get_adjustment(GTK_RANGE(custom->hscrollbar));
167 gtk_custom_set_adjust(custom, TRUE);
168
169 gtk_range_set_update_policy (GTK_RANGE(custom->hscrollbar),
170 GTK_UPDATE_DISCONTINUOUS);
171 g_signal_connect(G_OBJECT(custom->hscrollbar), "value-changed",
172 G_CALLBACK(gtk_custom_scroll_value_changed), custom);
173
174 custom->vbox = gtk_vbox_new(FALSE,0);
175 gtk_widget_show(custom->vbox);
176
177 // custom->viewport = gtk_viewport_new (NULL,NULL);
178 // gtk_widget_show(custom->viewport);
179
180 // gtk_container_add(GTK_CONTAINER(custom->viewport), (GtkWidget*)custom->vbox);
181 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->hscrollbar,FALSE,FALSE,0);
182 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->first_pane,TRUE,TRUE,0);
183
184 // custom->scrollWindow = gtk_scrolled_window_new (NULL, NULL);
185 // gtk_widget_show(custom->scrollWindow);
186 // gtk_container_add (GTK_CONTAINER (custom->scrollWindow), (GtkWidget*)custom->viewport);
187 // gtk_paned_pack1(GTK_PANED(custom), (GtkWidget*)custom->scrollWindow,FALSE, TRUE);
188
189 gtk_paned_pack1(GTK_PANED(custom), (GtkWidget*)custom->vbox,FALSE, TRUE);
190 }else{
191 tmpPane = custom->last_pane;
192 custom->last_pane = (GtkPaned *)gtk_vpaned_new();
193 gtk_paned_pack1 (tmpPane,(GtkWidget*)custom->last_pane, FALSE,TRUE);
194 }
195 gtk_widget_show((GtkWidget *)custom->last_pane);
196
197 gtk_paned_pack2 (custom->last_pane,widget1, TRUE, TRUE);
198 custom->focused_pane = custom->last_pane;
199 custom->num_children++;
200
201 }
202
203 void gtk_custom_widget_delete(GtkCustom * custom)
204 {
205 GtkPaned * tmp, *prev, *next;
206
207 if(!custom->focused_pane) return;
208
209 tmp = (GtkPaned*)custom->focused_pane->child2; //widget in vpaned
210 g_object_unref(G_OBJECT(tmp));
211
212 if(custom->focused_pane == custom->first_pane &&
213 custom->focused_pane == custom->last_pane){
214 // gtk_container_remove(GTK_CONTAINER(custom),(GtkWidget*)custom->scrollWindow);
215 gtk_container_remove(GTK_CONTAINER(custom),(GtkWidget*)custom->vbox);
216 custom->first_pane = NULL;
217 custom->last_pane = NULL;
218 custom->focused_pane = NULL;
219 }else if(custom->focused_pane == custom->first_pane &&
220 custom->focused_pane != custom->last_pane){
221 next = (GtkPaned*)custom->first_pane->child1;
222 g_object_ref(G_OBJECT(next));
223 gtk_container_remove(GTK_CONTAINER(custom->first_pane),(GtkWidget*)next);
224 gtk_container_remove(GTK_CONTAINER(custom->vbox),(GtkWidget*)custom->first_pane);
225 custom->first_pane = next;
226 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->first_pane,TRUE,TRUE,0);
227 custom->focused_pane = custom->first_pane;
228 g_object_unref(G_OBJECT(next));
229 }else if(custom->focused_pane != custom->first_pane &&
230 custom->focused_pane == custom->last_pane){
231 tmp = custom->last_pane;
232 custom->last_pane = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)custom->last_pane);
233 custom->focused_pane = custom->last_pane;
234 gtk_container_remove(GTK_CONTAINER(custom->last_pane),(GtkWidget*)tmp);
235 }else{
236 tmp = custom->focused_pane;
237 prev = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)tmp);
238 next = (GtkPaned*)tmp->child1;
239 g_object_ref(G_OBJECT(next));
240 gtk_container_remove(GTK_CONTAINER(custom->focused_pane),(GtkWidget*)next);
241 gtk_container_remove(GTK_CONTAINER(prev),(GtkWidget*)custom->focused_pane);
242 gtk_paned_pack1(prev, (GtkWidget*)next, FALSE, TRUE);
243 custom->focused_pane = next;
244 g_object_unref(G_OBJECT(next));
245 }
246
247 custom->num_children--;
248 }
249
250
251 void gtk_custom_widget_move_up(GtkCustom * custom)
252 {
253 GtkWidget* upWidget, *downWidget;
254 GtkPaned * prev,*next, *prevPrev;
255
256 if(custom->last_pane == custom->focused_pane) return;
257
258 // move VPane
259 prev = (GtkPaned*)custom->focused_pane->child1;
260 g_object_ref(G_OBJECT(prev));
261 gtk_container_remove(GTK_CONTAINER(custom->focused_pane),(GtkWidget*)prev);
262
263 if(prev == custom->last_pane){
264 prevPrev = NULL;
265 custom->last_pane = custom->focused_pane;
266 }else{
267 prevPrev = (GtkPaned*)prev->child1;
268 g_object_ref(G_OBJECT(prevPrev));
269 gtk_container_remove(GTK_CONTAINER(prev),(GtkWidget*)prevPrev);
270 }
271
272 g_object_ref(G_OBJECT(custom->focused_pane));
273 if(custom->first_pane == custom->focused_pane){
274 gtk_container_remove(GTK_CONTAINER(custom->vbox),(GtkWidget*)custom->focused_pane);
275 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)prev,TRUE,TRUE,0);
276 custom->first_pane = prev;
277 }else{
278 next = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)custom->focused_pane);
279 gtk_container_remove(GTK_CONTAINER(next),(GtkWidget*)custom->focused_pane);
280 gtk_paned_pack1(GTK_PANED(next), (GtkWidget*)prev, FALSE,TRUE);
281 }
282 gtk_paned_pack1(GTK_PANED(prev),(GtkWidget*)custom->focused_pane, FALSE,TRUE);
283 if(prevPrev)
284 gtk_paned_pack1(GTK_PANED(custom->focused_pane),(GtkWidget*)prevPrev, FALSE,TRUE);
285
286 g_object_unref(G_OBJECT(prev));
287 if(prevPrev) g_object_unref(G_OBJECT(prevPrev));
288 g_object_unref(G_OBJECT(custom->focused_pane));
289 }
290
291
292 void gtk_custom_widget_move_down(GtkCustom * custom)
293 {
294 GtkWidget* upWidget, *downWidget;
295 GtkPaned * prev,*next, *nextNext;
296
297 if(custom->first_pane == custom->focused_pane) return;
298
299 //move VPane
300 next = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)custom->focused_pane);
301 g_object_ref(G_OBJECT(next));
302
303 if(custom->last_pane == custom->focused_pane){
304 prev = NULL;
305 custom->last_pane = next;
306 }else{
307 prev = (GtkPaned*)custom->focused_pane->child1;
308 g_object_ref(G_OBJECT(prev));
309 gtk_container_remove(GTK_CONTAINER(custom->focused_pane),(GtkWidget*)prev);
310 }
311
312 g_object_ref(G_OBJECT(custom->focused_pane));
313 gtk_container_remove(GTK_CONTAINER(next),(GtkWidget*)custom->focused_pane);
314
315 if(next == custom->first_pane){
316 custom->first_pane = custom->focused_pane;
317 gtk_container_remove(GTK_CONTAINER(custom->vbox),(GtkWidget*)next);
318 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->focused_pane,TRUE,TRUE,0);
319 }else{
320 nextNext = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)next);
321 gtk_container_remove(GTK_CONTAINER(nextNext),(GtkWidget*)next);
322 gtk_paned_pack1(nextNext, (GtkWidget*)custom->focused_pane, FALSE, TRUE);
323 }
324 gtk_paned_pack1(custom->focused_pane,(GtkWidget*)next, FALSE,TRUE);
325 if(prev)
326 gtk_paned_pack1(next,(GtkWidget*)prev, FALSE,TRUE);
327
328 if(prev)g_object_unref(G_OBJECT(prev));
329 g_object_unref(G_OBJECT(next));
330 g_object_unref(G_OBJECT(custom->focused_pane));
331 }
332
333 void gtk_custom_scroll_value_changed(GtkRange *range, gpointer custom_arg)
334 {
335 LttTime time;
336 GtkCustom * custom = (GtkCustom*)custom_arg;
337 gdouble value = gtk_range_get_value(range);
338 time = ltt_time_from_double(value / NANOSECONDS_PER_SECOND);
339 set_current_time(custom->mw, &time);
340 g_warning("The current time is second :%d, nanosecond : %d\n", time.tv_sec, time.tv_nsec);
341 }
342
343
344 static void
345 gtk_custom_size_request (GtkWidget *widget,
346 GtkRequisition *requisition)
347 {
348 GtkPaned *paned = GTK_PANED (widget);
349 GtkRequisition child_requisition;
350
351 requisition->width = 0;
352 requisition->height = 0;
353
354 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
355 {
356 gtk_widget_size_request (paned->child1, &child_requisition);
357
358 requisition->height = child_requisition.height;
359 requisition->width = child_requisition.width;
360 }
361
362 if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
363 {
364 gtk_widget_size_request (paned->child2, &child_requisition);
365
366 requisition->width = MAX (requisition->width, child_requisition.width);
367 requisition->height += child_requisition.height;
368 }
369
370 requisition->height += GTK_CONTAINER (paned)->border_width * 2;
371 requisition->width += GTK_CONTAINER (paned)->border_width * 2;
372
373 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
374 paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
375 {
376 gint handle_size;
377
378 gtk_widget_style_get (widget, "handle_size", &handle_size, NULL);
379 requisition->height += handle_size;
380 }
381
382 }
383
384 static void
385 gtk_custom_size_allocate (GtkWidget *widget,
386 GtkAllocation *allocation)
387 {
388 GtkPaned *paned = GTK_PANED (widget);
389 gint border_width = GTK_CONTAINER (paned)->border_width;
390
391 widget->allocation = *allocation;
392
393 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
394 paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
395 {
396 GtkRequisition child1_requisition;
397 GtkRequisition child2_requisition;
398 GtkAllocation child1_allocation;
399 GtkAllocation child2_allocation;
400 gint handle_size;
401
402 gtk_widget_style_get (widget, "handle_size", &handle_size, NULL);
403
404 gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
405 gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
406
407 gtk_paned_compute_position (paned,
408 MAX (1, widget->allocation.height
409 - handle_size
410 - 2 * border_width),
411 child1_requisition.height,
412 child2_requisition.height);
413
414 paned->handle_pos.x = widget->allocation.x + border_width;
415 paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
416 paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
417 paned->handle_pos.height = handle_size;
418
419 if (GTK_WIDGET_REALIZED (widget))
420 {
421 if (GTK_WIDGET_MAPPED (widget))
422 gdk_window_show (paned->handle);
423 gdk_window_move_resize (paned->handle,
424 paned->handle_pos.x,
425 paned->handle_pos.y,
426 paned->handle_pos.width,
427 handle_size);
428 }
429
430 child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
431 child1_allocation.height = MAX (1, paned->child1_size);
432 child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
433 child1_allocation.y = widget->allocation.y + border_width;
434
435 child2_allocation.y = child1_allocation.y + paned->child1_size + paned->handle_pos.height;
436 child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
437
438 if (GTK_WIDGET_MAPPED (widget) &&
439 paned->child1->allocation.height < child1_allocation.height)
440 {
441 gtk_widget_size_allocate (paned->child2, &child2_allocation);
442 gtk_widget_size_allocate (paned->child1, &child1_allocation);
443 }
444 else
445 {
446 gtk_widget_size_allocate (paned->child1, &child1_allocation);
447 gtk_widget_size_allocate (paned->child2, &child2_allocation);
448 }
449 }
450 else
451 {
452 GtkAllocation child_allocation;
453
454 if (GTK_WIDGET_REALIZED (widget))
455 gdk_window_hide (paned->handle);
456
457 if (paned->child1)
458 gtk_widget_set_child_visible (paned->child1, TRUE);
459 if (paned->child2)
460 gtk_widget_set_child_visible (paned->child2, TRUE);
461
462 child_allocation.x = widget->allocation.x + border_width;
463 child_allocation.y = widget->allocation.y + border_width;
464 child_allocation.width = MAX (1, allocation->width - 2 * border_width);
465 child_allocation.height = MAX (1, allocation->height - 2 * border_width);
466
467 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
468 gtk_widget_size_allocate (paned->child1, &child_allocation);
469 else if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
470 gtk_widget_size_allocate (paned->child2, &child_allocation);
471 }
472 }
473
This page took 0.040063 seconds and 4 git commands to generate.