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 TimeWindow Time_Window
;
111 TimeInterval
*Time_Span
;
113 g_return_if_fail(GTK_IS_CUSTOM(custom
));
114 g_object_ref(G_OBJECT(widget1
));
117 if(!custom
->firstPane
){
118 custom
->firstPane
= (GtkPaned
*)gtk_vpaned_new();
119 custom
->lastPane
= custom
->firstPane
;
121 custom
->hScrollbar
= gtk_hscrollbar_new (NULL
);
122 gtk_widget_show(custom
->hScrollbar
);
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
;
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
152 custom
->hAdjust
->page_size
= tmpValue
;
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
);
159 custom
->vbox
= gtk_vbox_new(FALSE
,0);
160 gtk_widget_show(custom
->vbox
);
162 // custom->viewport = gtk_viewport_new (NULL,NULL);
163 // gtk_widget_show(custom->viewport);
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);
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);
174 gtk_paned_pack1(GTK_PANED(custom
), (GtkWidget
*)custom
->vbox
,FALSE
, TRUE
);
176 tmpPane
= custom
->lastPane
;
177 custom
->lastPane
= (GtkPaned
*)gtk_vpaned_new();
178 gtk_paned_pack1 (tmpPane
,(GtkWidget
*)custom
->lastPane
, FALSE
,TRUE
);
180 gtk_widget_show((GtkWidget
*)custom
->lastPane
);
182 gtk_paned_pack2 (custom
->lastPane
,widget1
, TRUE
, TRUE
);
183 custom
->focusedPane
= custom
->lastPane
;
184 custom
->numChildren
++;
188 void gtk_custom_widget_delete(GtkCustom
* custom
)
190 GtkPaned
* tmp
, *prev
, *next
;
192 if(!custom
->focusedPane
) return;
194 tmp
= (GtkPaned
*)custom
->focusedPane
->child2
; //widget in vpaned
195 g_object_unref(G_OBJECT(tmp
));
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
);
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
));
232 custom
->numChildren
--;
236 void gtk_custom_widget_move_up(GtkCustom
* custom
)
238 GtkWidget
* upWidget
, *downWidget
;
239 GtkPaned
* prev
,*next
, *prevPrev
;
241 if(custom
->lastPane
== custom
->focusedPane
) return;
244 prev
= (GtkPaned
*)custom
->focusedPane
->child1
;
245 g_object_ref(G_OBJECT(prev
));
246 gtk_container_remove(GTK_CONTAINER(custom
->focusedPane
),(GtkWidget
*)prev
);
248 if(prev
== custom
->lastPane
){
250 custom
->lastPane
= custom
->focusedPane
;
252 prevPrev
= (GtkPaned
*)prev
->child1
;
253 g_object_ref(G_OBJECT(prevPrev
));
254 gtk_container_remove(GTK_CONTAINER(prev
),(GtkWidget
*)prevPrev
);
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
;
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
);
267 gtk_paned_pack1(GTK_PANED(prev
),(GtkWidget
*)custom
->focusedPane
, FALSE
,TRUE
);
269 gtk_paned_pack1(GTK_PANED(custom
->focusedPane
),(GtkWidget
*)prevPrev
, FALSE
,TRUE
);
271 g_object_unref(G_OBJECT(prev
));
272 if(prevPrev
) g_object_unref(G_OBJECT(prevPrev
));
273 g_object_unref(G_OBJECT(custom
->focusedPane
));
277 void gtk_custom_widget_move_down(GtkCustom
* custom
)
279 GtkWidget
* upWidget
, *downWidget
;
280 GtkPaned
* prev
,*next
, *nextNext
;
282 if(custom
->firstPane
== custom
->focusedPane
) return;
285 next
= (GtkPaned
*)gtk_widget_get_parent((GtkWidget
*)custom
->focusedPane
);
286 g_object_ref(G_OBJECT(next
));
288 if(custom
->lastPane
== custom
->focusedPane
){
290 custom
->lastPane
= next
;
292 prev
= (GtkPaned
*)custom
->focusedPane
->child1
;
293 g_object_ref(G_OBJECT(prev
));
294 gtk_container_remove(GTK_CONTAINER(custom
->focusedPane
),(GtkWidget
*)prev
);
297 g_object_ref(G_OBJECT(custom
->focusedPane
));
298 gtk_container_remove(GTK_CONTAINER(next
),(GtkWidget
*)custom
->focusedPane
);
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);
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
);
309 gtk_paned_pack1(custom
->focusedPane
,(GtkWidget
*)next
, FALSE
,TRUE
);
311 gtk_paned_pack1(next
,(GtkWidget
*)prev
, FALSE
,TRUE
);
313 if(prev
)g_object_unref(G_OBJECT(prev
));
314 g_object_unref(G_OBJECT(next
));
315 g_object_unref(G_OBJECT(custom
->focusedPane
));
318 void gtk_custom_scroll_value_changed(GtkRange
*range
, gpointer custom_arg
)
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
);
331 gtk_custom_size_request (GtkWidget
*widget
,
332 GtkRequisition
*requisition
)
334 GtkPaned
*paned
= GTK_PANED (widget
);
335 GtkRequisition child_requisition
;
337 requisition
->width
= 0;
338 requisition
->height
= 0;
340 if (paned
->child1
&& GTK_WIDGET_VISIBLE (paned
->child1
))
342 gtk_widget_size_request (paned
->child1
, &child_requisition
);
344 requisition
->height
= child_requisition
.height
;
345 requisition
->width
= child_requisition
.width
;
348 if (paned
->child2
&& GTK_WIDGET_VISIBLE (paned
->child2
))
350 gtk_widget_size_request (paned
->child2
, &child_requisition
);
352 requisition
->width
= MAX (requisition
->width
, child_requisition
.width
);
353 requisition
->height
+= child_requisition
.height
;
356 requisition
->height
+= GTK_CONTAINER (paned
)->border_width
* 2;
357 requisition
->width
+= GTK_CONTAINER (paned
)->border_width
* 2;
359 if (paned
->child1
&& GTK_WIDGET_VISIBLE (paned
->child1
) &&
360 paned
->child2
&& GTK_WIDGET_VISIBLE (paned
->child2
))
364 gtk_widget_style_get (widget
, "handle_size", &handle_size
, NULL
);
365 requisition
->height
+= handle_size
;
371 gtk_custom_size_allocate (GtkWidget
*widget
,
372 GtkAllocation
*allocation
)
374 GtkPaned
*paned
= GTK_PANED (widget
);
375 gint border_width
= GTK_CONTAINER (paned
)->border_width
;
377 widget
->allocation
= *allocation
;
379 if (paned
->child1
&& GTK_WIDGET_VISIBLE (paned
->child1
) &&
380 paned
->child2
&& GTK_WIDGET_VISIBLE (paned
->child2
))
382 GtkRequisition child1_requisition
;
383 GtkRequisition child2_requisition
;
384 GtkAllocation child1_allocation
;
385 GtkAllocation child2_allocation
;
388 gtk_widget_style_get (widget
, "handle_size", &handle_size
, NULL
);
390 gtk_widget_get_child_requisition (paned
->child1
, &child1_requisition
);
391 gtk_widget_get_child_requisition (paned
->child2
, &child2_requisition
);
393 gtk_paned_compute_position (paned
,
394 MAX (1, widget
->allocation
.height
397 child1_requisition
.height
,
398 child2_requisition
.height
);
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
;
405 if (GTK_WIDGET_REALIZED (widget
))
407 if (GTK_WIDGET_MAPPED (widget
))
408 gdk_window_show (paned
->handle
);
409 gdk_window_move_resize (paned
->handle
,
412 paned
->handle_pos
.width
,
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
;
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
);
424 if (GTK_WIDGET_MAPPED (widget
) &&
425 paned
->child1
->allocation
.height
< child1_allocation
.height
)
427 gtk_widget_size_allocate (paned
->child2
, &child2_allocation
);
428 gtk_widget_size_allocate (paned
->child1
, &child1_allocation
);
432 gtk_widget_size_allocate (paned
->child1
, &child1_allocation
);
433 gtk_widget_size_allocate (paned
->child2
, &child2_allocation
);
438 GtkAllocation child_allocation
;
440 if (GTK_WIDGET_REALIZED (widget
))
441 gdk_window_hide (paned
->handle
);
444 gtk_widget_set_child_visible (paned
->child1
, TRUE
);
446 gtk_widget_set_child_visible (paned
->child2
, TRUE
);
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
);
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
);