3 #include <lttv/gtkcustom.h>
5 #include <lttv/gtkTraceSet.h>
7 static void gtk_custom_class_init (GtkCustomClass
*klass
);
8 static void gtk_custom_init (GtkCustom
*custom
);
11 static void gtk_custom_size_request (GtkWidget
*widget
,
12 GtkRequisition
*requisition
);
13 static void gtk_custom_size_allocate (GtkWidget
*widget
,
14 GtkAllocation
*allocation
);
16 void gtk_custom_scroll_value_changed (GtkRange
*range
, gpointer custom
);
19 gtk_custom_get_type (void)
21 static GType custom_type
= 0;
25 static const GTypeInfo custom_info
=
27 sizeof (GtkCustomClass
),
29 NULL
, /* base_finalize */
30 (GClassInitFunc
) gtk_custom_class_init
,
31 NULL
, /* class_finalize */
32 NULL
, /* class_data */
35 (GInstanceInitFunc
) gtk_custom_init
,
36 NULL
, /* value_table */
39 custom_type
= g_type_register_static (GTK_TYPE_PANED
, "GtkCustom",
47 gtk_custom_class_init (GtkCustomClass
*class)
49 GtkWidgetClass
*widget_class
;
51 widget_class
= (GtkWidgetClass
*) class;
53 widget_class
->size_request
= gtk_custom_size_request
;
54 widget_class
->size_allocate
= gtk_custom_size_allocate
;
58 gtk_custom_init (GtkCustom
*custom
)
62 GTK_WIDGET_SET_FLAGS (custom
, GTK_NO_WINDOW
);
63 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (custom
), FALSE
);
65 custom
->firstPane
= NULL
;
66 custom
->lastPane
= NULL
;
67 custom
->focusedPane
= NULL
;
68 custom
->numChildren
= 0;
71 // custom->scrollWindow = NULL;
72 // custom->viewport = NULL;
73 custom
->hScrollbar
= NULL
;
77 GtkWidget
* gtk_custom_new ()
79 return GTK_WIDGET (g_object_new (gtk_custom_get_type (), NULL
));
83 void gtk_custom_set_focus (GtkWidget
* widget
, gpointer user_data
)
85 GtkCustom
* custom
= (GtkCustom
*) widget
;
87 if(!custom
->firstPane
) return;
90 pane
= custom
->firstPane
;
92 if((GtkWidget
*)pane
== (GtkWidget
*)user_data
){
93 custom
->focusedPane
= pane
;
96 if(pane
== custom
->lastPane
){
97 custom
->focusedPane
= NULL
;
100 pane
= (GtkPaned
*)pane
->child1
;
104 void gtk_custom_widget_add(GtkCustom
* custom
, GtkWidget
* widget1
)
108 TimeInterval timeInterval
;
112 g_return_if_fail(GTK_IS_CUSTOM(custom
));
113 g_object_ref(G_OBJECT(widget1
));
116 if(!custom
->firstPane
){
117 custom
->firstPane
= (GtkPaned
*)gtk_vpaned_new();
118 custom
->lastPane
= custom
->firstPane
;
120 custom
->hScrollbar
= gtk_hscrollbar_new (NULL
);
121 gtk_widget_show(custom
->hScrollbar
);
123 custom
->hAdjust
= gtk_range_get_adjustment(GTK_RANGE(custom
->hScrollbar
));
124 GetTimeInterval(custom
->mw
,&timeInterval
);
125 GetCurrentTime(custom
->mw
,&time
);
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;
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
);
147 custom
->vbox
= gtk_vbox_new(FALSE
,0);
148 gtk_widget_show(custom
->vbox
);
150 // custom->viewport = gtk_viewport_new (NULL,NULL);
151 // gtk_widget_show(custom->viewport);
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);
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);
162 gtk_paned_pack1(GTK_PANED(custom
), (GtkWidget
*)custom
->vbox
,FALSE
, TRUE
);
164 tmpPane
= custom
->lastPane
;
165 custom
->lastPane
= (GtkPaned
*)gtk_vpaned_new();
166 gtk_paned_pack1 (tmpPane
,(GtkWidget
*)custom
->lastPane
, FALSE
,TRUE
);
168 gtk_widget_show((GtkWidget
*)custom
->lastPane
);
170 gtk_paned_pack2 (custom
->lastPane
,widget1
, TRUE
, TRUE
);
171 custom
->focusedPane
= custom
->lastPane
;
172 custom
->numChildren
++;
176 void gtk_custom_widget_delete(GtkCustom
* custom
)
178 GtkPaned
* tmp
, *prev
, *next
;
180 if(!custom
->focusedPane
) return;
182 tmp
= (GtkPaned
*)custom
->focusedPane
->child2
; //widget in vpaned
183 g_object_unref(G_OBJECT(tmp
));
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
);
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
));
220 custom
->numChildren
--;
224 void gtk_custom_widget_move_up(GtkCustom
* custom
)
226 GtkWidget
* upWidget
, *downWidget
;
227 GtkPaned
* prev
,*next
, *prevPrev
;
229 if(custom
->lastPane
== custom
->focusedPane
) return;
232 prev
= (GtkPaned
*)custom
->focusedPane
->child1
;
233 g_object_ref(G_OBJECT(prev
));
234 gtk_container_remove(GTK_CONTAINER(custom
->focusedPane
),(GtkWidget
*)prev
);
236 if(prev
== custom
->lastPane
){
238 custom
->lastPane
= custom
->focusedPane
;
240 prevPrev
= (GtkPaned
*)prev
->child1
;
241 g_object_ref(G_OBJECT(prevPrev
));
242 gtk_container_remove(GTK_CONTAINER(prev
),(GtkWidget
*)prevPrev
);
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
;
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
);
255 gtk_paned_pack1(GTK_PANED(prev
),(GtkWidget
*)custom
->focusedPane
, FALSE
,TRUE
);
257 gtk_paned_pack1(GTK_PANED(custom
->focusedPane
),(GtkWidget
*)prevPrev
, FALSE
,TRUE
);
259 g_object_unref(G_OBJECT(prev
));
260 if(prevPrev
) g_object_unref(G_OBJECT(prevPrev
));
261 g_object_unref(G_OBJECT(custom
->focusedPane
));
265 void gtk_custom_widget_move_down(GtkCustom
* custom
)
267 GtkWidget
* upWidget
, *downWidget
;
268 GtkPaned
* prev
,*next
, *nextNext
;
270 if(custom
->firstPane
== custom
->focusedPane
) return;
273 next
= (GtkPaned
*)gtk_widget_get_parent((GtkWidget
*)custom
->focusedPane
);
274 g_object_ref(G_OBJECT(next
));
276 if(custom
->lastPane
== custom
->focusedPane
){
278 custom
->lastPane
= next
;
280 prev
= (GtkPaned
*)custom
->focusedPane
->child1
;
281 g_object_ref(G_OBJECT(prev
));
282 gtk_container_remove(GTK_CONTAINER(custom
->focusedPane
),(GtkWidget
*)prev
);
285 g_object_ref(G_OBJECT(custom
->focusedPane
));
286 gtk_container_remove(GTK_CONTAINER(next
),(GtkWidget
*)custom
->focusedPane
);
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);
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
);
297 gtk_paned_pack1(custom
->focusedPane
,(GtkWidget
*)next
, FALSE
,TRUE
);
299 gtk_paned_pack1(next
,(GtkWidget
*)prev
, FALSE
,TRUE
);
301 if(prev
)g_object_unref(G_OBJECT(prev
));
302 g_object_unref(G_OBJECT(next
));
303 g_object_unref(G_OBJECT(custom
->focusedPane
));
306 void gtk_custom_scroll_value_changed(GtkRange
*range
, gpointer custom_arg
)
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
);
319 gtk_custom_size_request (GtkWidget
*widget
,
320 GtkRequisition
*requisition
)
322 GtkPaned
*paned
= GTK_PANED (widget
);
323 GtkRequisition child_requisition
;
325 requisition
->width
= 0;
326 requisition
->height
= 0;
328 if (paned
->child1
&& GTK_WIDGET_VISIBLE (paned
->child1
))
330 gtk_widget_size_request (paned
->child1
, &child_requisition
);
332 requisition
->height
= child_requisition
.height
;
333 requisition
->width
= child_requisition
.width
;
336 if (paned
->child2
&& GTK_WIDGET_VISIBLE (paned
->child2
))
338 gtk_widget_size_request (paned
->child2
, &child_requisition
);
340 requisition
->width
= MAX (requisition
->width
, child_requisition
.width
);
341 requisition
->height
+= child_requisition
.height
;
344 requisition
->height
+= GTK_CONTAINER (paned
)->border_width
* 2;
345 requisition
->width
+= GTK_CONTAINER (paned
)->border_width
* 2;
347 if (paned
->child1
&& GTK_WIDGET_VISIBLE (paned
->child1
) &&
348 paned
->child2
&& GTK_WIDGET_VISIBLE (paned
->child2
))
352 gtk_widget_style_get (widget
, "handle_size", &handle_size
, NULL
);
353 requisition
->height
+= handle_size
;
359 gtk_custom_size_allocate (GtkWidget
*widget
,
360 GtkAllocation
*allocation
)
362 GtkPaned
*paned
= GTK_PANED (widget
);
363 gint border_width
= GTK_CONTAINER (paned
)->border_width
;
365 widget
->allocation
= *allocation
;
367 if (paned
->child1
&& GTK_WIDGET_VISIBLE (paned
->child1
) &&
368 paned
->child2
&& GTK_WIDGET_VISIBLE (paned
->child2
))
370 GtkRequisition child1_requisition
;
371 GtkRequisition child2_requisition
;
372 GtkAllocation child1_allocation
;
373 GtkAllocation child2_allocation
;
376 gtk_widget_style_get (widget
, "handle_size", &handle_size
, NULL
);
378 gtk_widget_get_child_requisition (paned
->child1
, &child1_requisition
);
379 gtk_widget_get_child_requisition (paned
->child2
, &child2_requisition
);
381 gtk_paned_compute_position (paned
,
382 MAX (1, widget
->allocation
.height
385 child1_requisition
.height
,
386 child2_requisition
.height
);
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
;
393 if (GTK_WIDGET_REALIZED (widget
))
395 if (GTK_WIDGET_MAPPED (widget
))
396 gdk_window_show (paned
->handle
);
397 gdk_window_move_resize (paned
->handle
,
400 paned
->handle_pos
.width
,
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
;
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
);
412 if (GTK_WIDGET_MAPPED (widget
) &&
413 paned
->child1
->allocation
.height
< child1_allocation
.height
)
415 gtk_widget_size_allocate (paned
->child2
, &child2_allocation
);
416 gtk_widget_size_allocate (paned
->child1
, &child1_allocation
);
420 gtk_widget_size_allocate (paned
->child1
, &child1_allocation
);
421 gtk_widget_size_allocate (paned
->child2
, &child2_allocation
);
426 GtkAllocation child_allocation
;
428 if (GTK_WIDGET_REALIZED (widget
))
429 gdk_window_hide (paned
->handle
);
432 gtk_widget_set_child_visible (paned
->child1
, TRUE
);
434 gtk_widget_set_child_visible (paned
->child2
, TRUE
);
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
);
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
);