mega modif by Mathieu Desnoyers. Independant main windows, multiple tracesets, contro...
[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/gtkTraceSet.h>
6
7 static void gtk_custom_class_init (GtkCustomClass *klass);
8 static void gtk_custom_init (GtkCustom *custom);
9
10
11 static void gtk_custom_size_request (GtkWidget *widget,
12 GtkRequisition *requisition);
13 static void gtk_custom_size_allocate (GtkWidget *widget,
14 GtkAllocation *allocation);
15
16 void gtk_custom_scroll_value_changed (GtkRange *range, gpointer custom);
17
18 GType
19 gtk_custom_get_type (void)
20 {
21 static GType custom_type = 0;
22
23 if (!custom_type)
24 {
25 static const GTypeInfo custom_info =
26 {
27 sizeof (GtkCustomClass),
28 NULL, /* base_init */
29 NULL, /* base_finalize */
30 (GClassInitFunc) gtk_custom_class_init,
31 NULL, /* class_finalize */
32 NULL, /* class_data */
33 sizeof (GtkCustom),
34 0, /* n_preallocs */
35 (GInstanceInitFunc) gtk_custom_init,
36 NULL, /* value_table */
37 };
38
39 custom_type = g_type_register_static (GTK_TYPE_PANED, "GtkCustom",
40 &custom_info, 0);
41 }
42
43 return custom_type;
44 }
45
46 static void
47 gtk_custom_class_init (GtkCustomClass *class)
48 {
49 GtkWidgetClass *widget_class;
50
51 widget_class = (GtkWidgetClass *) class;
52
53 widget_class->size_request = gtk_custom_size_request;
54 widget_class->size_allocate = gtk_custom_size_allocate;
55 }
56
57 static void
58 gtk_custom_init (GtkCustom *custom)
59 {
60 GtkWidget * button;
61
62 GTK_WIDGET_SET_FLAGS (custom, GTK_NO_WINDOW);
63 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (custom), FALSE);
64
65 custom->firstPane = NULL;
66 custom->lastPane = NULL;
67 custom->focusedPane = NULL;
68 custom->numChildren = 0;
69
70 custom->vbox = NULL;
71 // custom->scrollWindow = NULL;
72 // custom->viewport = NULL;
73 custom->hScrollbar = NULL;
74 }
75
76
77 GtkWidget* gtk_custom_new ()
78 {
79 return GTK_WIDGET (g_object_new (gtk_custom_get_type (), NULL));
80 }
81
82
83 void gtk_custom_set_focus (GtkWidget * widget, gpointer user_data)
84 {
85 GtkCustom * custom = (GtkCustom*) widget;
86 GtkPaned * pane;
87 if(!custom->firstPane) return;
88
89
90 pane = custom->firstPane;
91 while(1){
92 if((GtkWidget*)pane == (GtkWidget*)user_data){
93 custom->focusedPane = pane;
94 break;
95 }
96 if(pane == custom->lastPane){
97 custom->focusedPane = NULL;
98 break;
99 }
100 pane = (GtkPaned*)pane->child1;
101 }
102 }
103
104 void gtk_custom_widget_add(GtkCustom * custom, GtkWidget * widget1)
105 {
106 GtkPaned * tmpPane;
107 GtkWidget * w;
108 TimeWindow Time_Window;
109 LttTime time;
110 double tmpValue;
111 TimeInterval *Time_Span;
112
113 g_return_if_fail(GTK_IS_CUSTOM(custom));
114 g_object_ref(G_OBJECT(widget1));
115
116
117 if(!custom->firstPane){
118 custom->firstPane = (GtkPaned *)gtk_vpaned_new();
119 custom->lastPane = custom->firstPane;
120
121 custom->hScrollbar = gtk_hscrollbar_new (NULL);
122 gtk_widget_show(custom->hScrollbar);
123
124 custom->hAdjust = gtk_range_get_adjustment(GTK_RANGE(custom->hScrollbar));
125 GetTimeWindow(custom->mw,&Time_Window);
126 GetCurrentTime(custom->mw,&time);
127 Time_Span = LTTV_TRACESET_CONTEXT(custom->mw->Traceset_Info->TracesetContext)->Time_Span ;
128
129 tmpValue = Time_Span->startTime.tv_sec;
130 tmpValue *= NANSECOND_CONST;
131 tmpValue += Time_Span->startTime.tv_nsec;
132 custom->hAdjust->lower = tmpValue;
133 custom->hAdjust->value = tmpValue;
134 tmpValue = Time_Span->endTime.tv_sec;
135 tmpValue *= NANSECOND_CONST;
136 tmpValue += Time_Span->endTime.tv_nsec;
137 custom->hAdjust->upper = tmpValue;
138 //tmpValue = time.tv_sec;
139 //tmpValue *= NANSECOND_CONST;
140 //tmpValue += time.tv_nsec;
141 //custom->hAdjust->value = tmpValue;
142 /* Step increment to 1/10 of visible area */
143 tmpValue = Time_Window.Time_Width.tv_sec;
144 tmpValue *= NANSECOND_CONST;
145 tmpValue += Time_Window.Time_Width.tv_nsec;
146 custom->hAdjust->step_increment = tmpValue / 10;
147 /* Page increment of whole visible area */
148 custom->hAdjust->page_increment = tmpValue;
149 /* page_size to the whole visible area will take care that the
150 * scroll value + the shown area will never be more than what is
151 * in the trace. */
152 custom->hAdjust->page_size = tmpValue;
153
154 gtk_range_set_update_policy (GTK_RANGE(custom->hScrollbar),
155 GTK_UPDATE_DISCONTINUOUS);
156 g_signal_connect(G_OBJECT(custom->hScrollbar), "value-changed",
157 G_CALLBACK(gtk_custom_scroll_value_changed), custom);
158
159 custom->vbox = gtk_vbox_new(FALSE,0);
160 gtk_widget_show(custom->vbox);
161
162 // custom->viewport = gtk_viewport_new (NULL,NULL);
163 // gtk_widget_show(custom->viewport);
164
165 // gtk_container_add(GTK_CONTAINER(custom->viewport), (GtkWidget*)custom->vbox);
166 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->hScrollbar,FALSE,FALSE,0);
167 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->firstPane,TRUE,TRUE,0);
168
169 // custom->scrollWindow = gtk_scrolled_window_new (NULL, NULL);
170 // gtk_widget_show(custom->scrollWindow);
171 // gtk_container_add (GTK_CONTAINER (custom->scrollWindow), (GtkWidget*)custom->viewport);
172 // gtk_paned_pack1(GTK_PANED(custom), (GtkWidget*)custom->scrollWindow,FALSE, TRUE);
173
174 gtk_paned_pack1(GTK_PANED(custom), (GtkWidget*)custom->vbox,FALSE, TRUE);
175 }else{
176 tmpPane = custom->lastPane;
177 custom->lastPane = (GtkPaned *)gtk_vpaned_new();
178 gtk_paned_pack1 (tmpPane,(GtkWidget*)custom->lastPane, FALSE,TRUE);
179 }
180 gtk_widget_show((GtkWidget *)custom->lastPane);
181
182 gtk_paned_pack2 (custom->lastPane,widget1, TRUE, TRUE);
183 custom->focusedPane = custom->lastPane;
184 custom->numChildren++;
185
186 }
187
188 void gtk_custom_widget_delete(GtkCustom * custom)
189 {
190 GtkPaned * tmp, *prev, *next;
191
192 if(!custom->focusedPane) return;
193
194 tmp = (GtkPaned*)custom->focusedPane->child2; //widget in vpaned
195 g_object_unref(G_OBJECT(tmp));
196
197 if(custom->focusedPane == custom->firstPane &&
198 custom->focusedPane == custom->lastPane){
199 // gtk_container_remove(GTK_CONTAINER(custom),(GtkWidget*)custom->scrollWindow);
200 gtk_container_remove(GTK_CONTAINER(custom),(GtkWidget*)custom->vbox);
201 custom->firstPane = NULL;
202 custom->lastPane = NULL;
203 custom->focusedPane = NULL;
204 }else if(custom->focusedPane == custom->firstPane &&
205 custom->focusedPane != custom->lastPane){
206 next = (GtkPaned*)custom->firstPane->child1;
207 g_object_ref(G_OBJECT(next));
208 gtk_container_remove(GTK_CONTAINER(custom->firstPane),(GtkWidget*)next);
209 gtk_container_remove(GTK_CONTAINER(custom->vbox),(GtkWidget*)custom->firstPane);
210 custom->firstPane = next;
211 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->firstPane,TRUE,TRUE,0);
212 custom->focusedPane = custom->firstPane;
213 g_object_unref(G_OBJECT(next));
214 }else if(custom->focusedPane != custom->firstPane &&
215 custom->focusedPane == custom->lastPane){
216 tmp = custom->lastPane;
217 custom->lastPane = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)custom->lastPane);
218 custom->focusedPane = custom->lastPane;
219 gtk_container_remove(GTK_CONTAINER(custom->lastPane),(GtkWidget*)tmp);
220 }else{
221 tmp = custom->focusedPane;
222 prev = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)tmp);
223 next = (GtkPaned*)tmp->child1;
224 g_object_ref(G_OBJECT(next));
225 gtk_container_remove(GTK_CONTAINER(custom->focusedPane),(GtkWidget*)next);
226 gtk_container_remove(GTK_CONTAINER(prev),(GtkWidget*)custom->focusedPane);
227 gtk_paned_pack1(prev, (GtkWidget*)next, FALSE, TRUE);
228 custom->focusedPane = next;
229 g_object_unref(G_OBJECT(next));
230 }
231
232 custom->numChildren--;
233 }
234
235
236 void gtk_custom_widget_move_up(GtkCustom * custom)
237 {
238 GtkWidget* upWidget, *downWidget;
239 GtkPaned * prev,*next, *prevPrev;
240
241 if(custom->lastPane == custom->focusedPane) return;
242
243 // move VPane
244 prev = (GtkPaned*)custom->focusedPane->child1;
245 g_object_ref(G_OBJECT(prev));
246 gtk_container_remove(GTK_CONTAINER(custom->focusedPane),(GtkWidget*)prev);
247
248 if(prev == custom->lastPane){
249 prevPrev = NULL;
250 custom->lastPane = custom->focusedPane;
251 }else{
252 prevPrev = (GtkPaned*)prev->child1;
253 g_object_ref(G_OBJECT(prevPrev));
254 gtk_container_remove(GTK_CONTAINER(prev),(GtkWidget*)prevPrev);
255 }
256
257 g_object_ref(G_OBJECT(custom->focusedPane));
258 if(custom->firstPane == custom->focusedPane){
259 gtk_container_remove(GTK_CONTAINER(custom->vbox),(GtkWidget*)custom->focusedPane);
260 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)prev,TRUE,TRUE,0);
261 custom->firstPane = prev;
262 }else{
263 next = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)custom->focusedPane);
264 gtk_container_remove(GTK_CONTAINER(next),(GtkWidget*)custom->focusedPane);
265 gtk_paned_pack1(GTK_PANED(next), (GtkWidget*)prev, FALSE,TRUE);
266 }
267 gtk_paned_pack1(GTK_PANED(prev),(GtkWidget*)custom->focusedPane, FALSE,TRUE);
268 if(prevPrev)
269 gtk_paned_pack1(GTK_PANED(custom->focusedPane),(GtkWidget*)prevPrev, FALSE,TRUE);
270
271 g_object_unref(G_OBJECT(prev));
272 if(prevPrev) g_object_unref(G_OBJECT(prevPrev));
273 g_object_unref(G_OBJECT(custom->focusedPane));
274 }
275
276
277 void gtk_custom_widget_move_down(GtkCustom * custom)
278 {
279 GtkWidget* upWidget, *downWidget;
280 GtkPaned * prev,*next, *nextNext;
281
282 if(custom->firstPane == custom->focusedPane) return;
283
284 //move VPane
285 next = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)custom->focusedPane);
286 g_object_ref(G_OBJECT(next));
287
288 if(custom->lastPane == custom->focusedPane){
289 prev = NULL;
290 custom->lastPane = next;
291 }else{
292 prev = (GtkPaned*)custom->focusedPane->child1;
293 g_object_ref(G_OBJECT(prev));
294 gtk_container_remove(GTK_CONTAINER(custom->focusedPane),(GtkWidget*)prev);
295 }
296
297 g_object_ref(G_OBJECT(custom->focusedPane));
298 gtk_container_remove(GTK_CONTAINER(next),(GtkWidget*)custom->focusedPane);
299
300 if(next == custom->firstPane){
301 custom->firstPane = custom->focusedPane;
302 gtk_container_remove(GTK_CONTAINER(custom->vbox),(GtkWidget*)next);
303 gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->focusedPane,TRUE,TRUE,0);
304 }else{
305 nextNext = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)next);
306 gtk_container_remove(GTK_CONTAINER(nextNext),(GtkWidget*)next);
307 gtk_paned_pack1(nextNext, (GtkWidget*)custom->focusedPane, FALSE, TRUE);
308 }
309 gtk_paned_pack1(custom->focusedPane,(GtkWidget*)next, FALSE,TRUE);
310 if(prev)
311 gtk_paned_pack1(next,(GtkWidget*)prev, FALSE,TRUE);
312
313 if(prev)g_object_unref(G_OBJECT(prev));
314 g_object_unref(G_OBJECT(next));
315 g_object_unref(G_OBJECT(custom->focusedPane));
316 }
317
318 void gtk_custom_scroll_value_changed(GtkRange *range, gpointer custom_arg)
319 {
320 LttTime time;
321 GtkCustom * custom = (GtkCustom*)custom_arg;
322 gdouble value = gtk_range_get_value(range);
323 time.tv_sec = value / NANSECOND_CONST;
324 time.tv_nsec = (value / NANSECOND_CONST - time.tv_sec) * NANSECOND_CONST;
325 SetCurrentTime(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.038571 seconds and 4 git commands to generate.