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