comment out not working items in the GUI
[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
110 get_time_window(custom->mw,&time_window);
111 if(first_time){
112 time_span = LTTV_TRACESET_CONTEXT(custom->mw->traceset_info->traceset_context)->Time_Span ;
113
114 custom->hadjust->lower = ltt_time_to_double(time_span->startTime) *
115 NANOSECONDS_PER_SECOND;
116 custom->hadjust->value = custom->hadjust->lower;
117 custom->hadjust->upper = ltt_time_to_double(time_span->endTime) *
118 NANOSECONDS_PER_SECOND;
119 }
120
121 /* Page increment of whole visible area */
122 if(custom->hadjust == NULL){
123 g_warning("Insert a viewer first");
124 return;
125 }
126 custom->hadjust->page_increment = ltt_time_to_double(
127 time_window.time_width) * NANOSECONDS_PER_SECOND;
128 /* page_size to the whole visible area will take care that the
129 * scroll value + the shown area will never be more than what is
130 * in the trace. */
131 custom->hadjust->page_size = custom->hadjust->page_increment;
132 custom->hadjust->step_increment = custom->hadjust->page_increment / 10;
133
134 }
135
136 void gtk_custom_widget_add(GtkCustom * custom, GtkWidget * widget1)
137 {
138 GtkPaned * tmpPane;
139 GtkWidget * w;
140
141 g_return_if_fail(GTK_IS_CUSTOM(custom));
142 g_object_ref(G_OBJECT(widget1));
143
144
145 if(!custom->first_pane){
146 custom->first_pane = (GtkPaned *)gtk_vpaned_new();
147 custom->last_pane = custom->first_pane;
148
149 custom->hscrollbar = gtk_hscrollbar_new (NULL);
150 gtk_widget_show(custom->hscrollbar);
151
152 custom->hadjust = gtk_range_get_adjustment(GTK_RANGE(custom->hscrollbar));
153 gtk_custom_set_adjust(custom, TRUE);
154
155 gtk_range_set_update_policy (GTK_RANGE(custom->hscrollbar),
156 GTK_UPDATE_DISCONTINUOUS);
157 g_signal_connect(G_OBJECT(custom->hscrollbar), "value-changed",
158 G_CALLBACK(gtk_custom_scroll_value_changed), custom);
159
160 custom->vbox = gtk_vbox_new(FALSE,0);
161 gtk_widget_show(custom->vbox);
162
163 // custom->viewport = gtk_viewport_new (NULL,NULL);
164 // gtk_widget_show(custom->viewport);
165
166 // gtk_container_add(GTK_CONTAINER(custom->viewport), (GtkWidget*)custom->vbox);
167 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->hscrollbar,FALSE,FALSE,0);
168 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->first_pane,TRUE,TRUE,0);
169
170 // custom->scrollWindow = gtk_scrolled_window_new (NULL, NULL);
171 // gtk_widget_show(custom->scrollWindow);
172 // gtk_container_add (GTK_CONTAINER (custom->scrollWindow), (GtkWidget*)custom->viewport);
173 // gtk_paned_pack1(GTK_PANED(custom), (GtkWidget*)custom->scrollWindow,FALSE, TRUE);
174
175 gtk_paned_pack1(GTK_PANED(custom), (GtkWidget*)custom->vbox,FALSE, TRUE);
176 }else{
177 tmpPane = custom->last_pane;
178 custom->last_pane = (GtkPaned *)gtk_vpaned_new();
179 gtk_paned_pack1 (tmpPane,(GtkWidget*)custom->last_pane, FALSE,TRUE);
180 }
181 gtk_widget_show((GtkWidget *)custom->last_pane);
182
183 gtk_paned_pack2 (custom->last_pane,widget1, TRUE, TRUE);
184 custom->focused_pane = custom->last_pane;
185 custom->num_children++;
186
187 }
188
189 void gtk_custom_widget_delete(GtkCustom * custom)
190 {
191 GtkPaned * tmp, *prev, *next;
192
193 if(!custom->focused_pane) return;
194
195 tmp = (GtkPaned*)custom->focused_pane->child2; //widget in vpaned
196 g_object_unref(G_OBJECT(tmp));
197
198 if(custom->focused_pane == custom->first_pane &&
199 custom->focused_pane == custom->last_pane){
200 // gtk_container_remove(GTK_CONTAINER(custom),(GtkWidget*)custom->scrollWindow);
201 gtk_container_remove(GTK_CONTAINER(custom),(GtkWidget*)custom->vbox);
202 custom->first_pane = NULL;
203 custom->last_pane = NULL;
204 custom->focused_pane = NULL;
205 }else if(custom->focused_pane == custom->first_pane &&
206 custom->focused_pane != custom->last_pane){
207 next = (GtkPaned*)custom->first_pane->child1;
208 g_object_ref(G_OBJECT(next));
209 gtk_container_remove(GTK_CONTAINER(custom->first_pane),(GtkWidget*)next);
210 gtk_container_remove(GTK_CONTAINER(custom->vbox),(GtkWidget*)custom->first_pane);
211 custom->first_pane = next;
212 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->first_pane,TRUE,TRUE,0);
213 custom->focused_pane = custom->first_pane;
214 g_object_unref(G_OBJECT(next));
215 }else if(custom->focused_pane != custom->first_pane &&
216 custom->focused_pane == custom->last_pane){
217 tmp = custom->last_pane;
218 custom->last_pane = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)custom->last_pane);
219 custom->focused_pane = custom->last_pane;
220 gtk_container_remove(GTK_CONTAINER(custom->last_pane),(GtkWidget*)tmp);
221 }else{
222 tmp = custom->focused_pane;
223 prev = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)tmp);
224 next = (GtkPaned*)tmp->child1;
225 g_object_ref(G_OBJECT(next));
226 gtk_container_remove(GTK_CONTAINER(custom->focused_pane),(GtkWidget*)next);
227 gtk_container_remove(GTK_CONTAINER(prev),(GtkWidget*)custom->focused_pane);
228 gtk_paned_pack1(prev, (GtkWidget*)next, FALSE, TRUE);
229 custom->focused_pane = next;
230 g_object_unref(G_OBJECT(next));
231 }
232
233 custom->num_children--;
234 }
235
236
237 void gtk_custom_widget_move_up(GtkCustom * custom)
238 {
239 GtkWidget* upWidget, *downWidget;
240 GtkPaned * prev,*next, *prevPrev;
241
242 if(custom->last_pane == custom->focused_pane) return;
243
244 // move VPane
245 prev = (GtkPaned*)custom->focused_pane->child1;
246 g_object_ref(G_OBJECT(prev));
247 gtk_container_remove(GTK_CONTAINER(custom->focused_pane),(GtkWidget*)prev);
248
249 if(prev == custom->last_pane){
250 prevPrev = NULL;
251 custom->last_pane = custom->focused_pane;
252 }else{
253 prevPrev = (GtkPaned*)prev->child1;
254 g_object_ref(G_OBJECT(prevPrev));
255 gtk_container_remove(GTK_CONTAINER(prev),(GtkWidget*)prevPrev);
256 }
257
258 g_object_ref(G_OBJECT(custom->focused_pane));
259 if(custom->first_pane == custom->focused_pane){
260 gtk_container_remove(GTK_CONTAINER(custom->vbox),(GtkWidget*)custom->focused_pane);
261 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)prev,TRUE,TRUE,0);
262 custom->first_pane = prev;
263 }else{
264 next = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)custom->focused_pane);
265 gtk_container_remove(GTK_CONTAINER(next),(GtkWidget*)custom->focused_pane);
266 gtk_paned_pack1(GTK_PANED(next), (GtkWidget*)prev, FALSE,TRUE);
267 }
268 gtk_paned_pack1(GTK_PANED(prev),(GtkWidget*)custom->focused_pane, FALSE,TRUE);
269 if(prevPrev)
270 gtk_paned_pack1(GTK_PANED(custom->focused_pane),(GtkWidget*)prevPrev, FALSE,TRUE);
271
272 g_object_unref(G_OBJECT(prev));
273 if(prevPrev) g_object_unref(G_OBJECT(prevPrev));
274 g_object_unref(G_OBJECT(custom->focused_pane));
275 }
276
277
278 void gtk_custom_widget_move_down(GtkCustom * custom)
279 {
280 GtkWidget* upWidget, *downWidget;
281 GtkPaned * prev,*next, *nextNext;
282
283 if(custom->first_pane == custom->focused_pane) return;
284
285 //move VPane
286 next = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)custom->focused_pane);
287 g_object_ref(G_OBJECT(next));
288
289 if(custom->last_pane == custom->focused_pane){
290 prev = NULL;
291 custom->last_pane = next;
292 }else{
293 prev = (GtkPaned*)custom->focused_pane->child1;
294 g_object_ref(G_OBJECT(prev));
295 gtk_container_remove(GTK_CONTAINER(custom->focused_pane),(GtkWidget*)prev);
296 }
297
298 g_object_ref(G_OBJECT(custom->focused_pane));
299 gtk_container_remove(GTK_CONTAINER(next),(GtkWidget*)custom->focused_pane);
300
301 if(next == custom->first_pane){
302 custom->first_pane = custom->focused_pane;
303 gtk_container_remove(GTK_CONTAINER(custom->vbox),(GtkWidget*)next);
304 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->focused_pane,TRUE,TRUE,0);
305 }else{
306 nextNext = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)next);
307 gtk_container_remove(GTK_CONTAINER(nextNext),(GtkWidget*)next);
308 gtk_paned_pack1(nextNext, (GtkWidget*)custom->focused_pane, FALSE, TRUE);
309 }
310 gtk_paned_pack1(custom->focused_pane,(GtkWidget*)next, FALSE,TRUE);
311 if(prev)
312 gtk_paned_pack1(next,(GtkWidget*)prev, FALSE,TRUE);
313
314 if(prev)g_object_unref(G_OBJECT(prev));
315 g_object_unref(G_OBJECT(next));
316 g_object_unref(G_OBJECT(custom->focused_pane));
317 }
318
319 void gtk_custom_scroll_value_changed(GtkRange *range, gpointer custom_arg)
320 {
321 LttTime time;
322 GtkCustom * custom = (GtkCustom*)custom_arg;
323 gdouble value = gtk_range_get_value(range);
324 time = ltt_time_from_double(value / NANOSECONDS_PER_SECOND);
325 set_current_time(custom->mw, &time);
326 g_warning("The current time is second :%d, nanosecond : %d\n", time.tv_sec, time.tv_nsec);
327 }
328
329
330 static void
331 gtk_custom_size_request (GtkWidget *widget,
332 GtkRequisition *requisition)
333 {
334 GtkPaned *paned = GTK_PANED (widget);
335 GtkRequisition child_requisition;
336
337 requisition->width = 0;
338 requisition->height = 0;
339
340 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
341 {
342 gtk_widget_size_request (paned->child1, &child_requisition);
343
344 requisition->height = child_requisition.height;
345 requisition->width = child_requisition.width;
346 }
347
348 if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
349 {
350 gtk_widget_size_request (paned->child2, &child_requisition);
351
352 requisition->width = MAX (requisition->width, child_requisition.width);
353 requisition->height += child_requisition.height;
354 }
355
356 requisition->height += GTK_CONTAINER (paned)->border_width * 2;
357 requisition->width += GTK_CONTAINER (paned)->border_width * 2;
358
359 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
360 paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
361 {
362 gint handle_size;
363
364 gtk_widget_style_get (widget, "handle_size", &handle_size, NULL);
365 requisition->height += handle_size;
366 }
367
368 }
369
370 static void
371 gtk_custom_size_allocate (GtkWidget *widget,
372 GtkAllocation *allocation)
373 {
374 GtkPaned *paned = GTK_PANED (widget);
375 gint border_width = GTK_CONTAINER (paned)->border_width;
376
377 widget->allocation = *allocation;
378
379 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
380 paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
381 {
382 GtkRequisition child1_requisition;
383 GtkRequisition child2_requisition;
384 GtkAllocation child1_allocation;
385 GtkAllocation child2_allocation;
386 gint handle_size;
387
388 gtk_widget_style_get (widget, "handle_size", &handle_size, NULL);
389
390 gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
391 gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
392
393 gtk_paned_compute_position (paned,
394 MAX (1, widget->allocation.height
395 - handle_size
396 - 2 * border_width),
397 child1_requisition.height,
398 child2_requisition.height);
399
400 paned->handle_pos.x = widget->allocation.x + border_width;
401 paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
402 paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
403 paned->handle_pos.height = handle_size;
404
405 if (GTK_WIDGET_REALIZED (widget))
406 {
407 if (GTK_WIDGET_MAPPED (widget))
408 gdk_window_show (paned->handle);
409 gdk_window_move_resize (paned->handle,
410 paned->handle_pos.x,
411 paned->handle_pos.y,
412 paned->handle_pos.width,
413 handle_size);
414 }
415
416 child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
417 child1_allocation.height = MAX (1, paned->child1_size);
418 child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
419 child1_allocation.y = widget->allocation.y + border_width;
420
421 child2_allocation.y = child1_allocation.y + paned->child1_size + paned->handle_pos.height;
422 child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
423
424 if (GTK_WIDGET_MAPPED (widget) &&
425 paned->child1->allocation.height < child1_allocation.height)
426 {
427 gtk_widget_size_allocate (paned->child2, &child2_allocation);
428 gtk_widget_size_allocate (paned->child1, &child1_allocation);
429 }
430 else
431 {
432 gtk_widget_size_allocate (paned->child1, &child1_allocation);
433 gtk_widget_size_allocate (paned->child2, &child2_allocation);
434 }
435 }
436 else
437 {
438 GtkAllocation child_allocation;
439
440 if (GTK_WIDGET_REALIZED (widget))
441 gdk_window_hide (paned->handle);
442
443 if (paned->child1)
444 gtk_widget_set_child_visible (paned->child1, TRUE);
445 if (paned->child2)
446 gtk_widget_set_child_visible (paned->child2, TRUE);
447
448 child_allocation.x = widget->allocation.x + border_width;
449 child_allocation.y = widget->allocation.y + border_width;
450 child_allocation.width = MAX (1, allocation->width - 2 * border_width);
451 child_allocation.height = MAX (1, allocation->height - 2 * border_width);
452
453 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
454 gtk_widget_size_allocate (paned->child1, &child_allocation);
455 else if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
456 gtk_widget_size_allocate (paned->child2, &child_allocation);
457 }
458 }
459
This page took 0.064498 seconds and 4 git commands to generate.