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
;
110 TimeInterval
*Time_Span
;
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 GetTimeWindow(custom
->mw
,&Time_Window
);
125 GetCurrentTime(custom
->mw
,&time
);
126 Time_Span
= LTTV_TRACESET_CONTEXT(custom
->mw
->Traceset_Info
->TracesetContext
)->Time_Span
;
128 custom
->hAdjust
->lower
= ltt_time_to_double(Time_Span
->startTime
) *
129 NANOSECONDS_PER_SECOND
;
130 custom
->hAdjust
->value
= custom
->hAdjust
->lower
;
131 custom
->hAdjust
->upper
= ltt_time_to_double(Time_Span
->endTime
) *
132 NANOSECONDS_PER_SECOND
;
133 /* Page increment of whole visible area */
134 custom
->hAdjust
->page_increment
= ltt_time_to_double(
135 Time_Window
.Time_Width
) * NANOSECONDS_PER_SECOND
;
136 /* page_size to the whole visible area will take care that the
137 * scroll value + the shown area will never be more than what is
139 custom
->hAdjust
->page_size
= custom
->hAdjust
->page_increment
;
140 custom
->hAdjust
->step_increment
= custom
->hAdjust
->page_increment
/ 10;
142 gtk_range_set_update_policy (GTK_RANGE(custom
->hScrollbar
),
143 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
= ltt_time_from_double(value
/ NANOSECONDS_PER_SECOND
);
312 SetCurrentTime(custom
->mw
, &time
);
313 g_warning("The current time is second :%d, nanosecond : %d\n", time
.tv_sec
, time
.tv_nsec
);
318 gtk_custom_size_request (GtkWidget
*widget
,
319 GtkRequisition
*requisition
)
321 GtkPaned
*paned
= GTK_PANED (widget
);
322 GtkRequisition child_requisition
;
324 requisition
->width
= 0;
325 requisition
->height
= 0;
327 if (paned
->child1
&& GTK_WIDGET_VISIBLE (paned
->child1
))
329 gtk_widget_size_request (paned
->child1
, &child_requisition
);
331 requisition
->height
= child_requisition
.height
;
332 requisition
->width
= child_requisition
.width
;
335 if (paned
->child2
&& GTK_WIDGET_VISIBLE (paned
->child2
))
337 gtk_widget_size_request (paned
->child2
, &child_requisition
);
339 requisition
->width
= MAX (requisition
->width
, child_requisition
.width
);
340 requisition
->height
+= child_requisition
.height
;
343 requisition
->height
+= GTK_CONTAINER (paned
)->border_width
* 2;
344 requisition
->width
+= GTK_CONTAINER (paned
)->border_width
* 2;
346 if (paned
->child1
&& GTK_WIDGET_VISIBLE (paned
->child1
) &&
347 paned
->child2
&& GTK_WIDGET_VISIBLE (paned
->child2
))
351 gtk_widget_style_get (widget
, "handle_size", &handle_size
, NULL
);
352 requisition
->height
+= handle_size
;
358 gtk_custom_size_allocate (GtkWidget
*widget
,
359 GtkAllocation
*allocation
)
361 GtkPaned
*paned
= GTK_PANED (widget
);
362 gint border_width
= GTK_CONTAINER (paned
)->border_width
;
364 widget
->allocation
= *allocation
;
366 if (paned
->child1
&& GTK_WIDGET_VISIBLE (paned
->child1
) &&
367 paned
->child2
&& GTK_WIDGET_VISIBLE (paned
->child2
))
369 GtkRequisition child1_requisition
;
370 GtkRequisition child2_requisition
;
371 GtkAllocation child1_allocation
;
372 GtkAllocation child2_allocation
;
375 gtk_widget_style_get (widget
, "handle_size", &handle_size
, NULL
);
377 gtk_widget_get_child_requisition (paned
->child1
, &child1_requisition
);
378 gtk_widget_get_child_requisition (paned
->child2
, &child2_requisition
);
380 gtk_paned_compute_position (paned
,
381 MAX (1, widget
->allocation
.height
384 child1_requisition
.height
,
385 child2_requisition
.height
);
387 paned
->handle_pos
.x
= widget
->allocation
.x
+ border_width
;
388 paned
->handle_pos
.y
= widget
->allocation
.y
+ paned
->child1_size
+ border_width
;
389 paned
->handle_pos
.width
= MAX (1, (gint
) widget
->allocation
.width
- 2 * border_width
);
390 paned
->handle_pos
.height
= handle_size
;
392 if (GTK_WIDGET_REALIZED (widget
))
394 if (GTK_WIDGET_MAPPED (widget
))
395 gdk_window_show (paned
->handle
);
396 gdk_window_move_resize (paned
->handle
,
399 paned
->handle_pos
.width
,
403 child1_allocation
.width
= child2_allocation
.width
= MAX (1, (gint
) allocation
->width
- border_width
* 2);
404 child1_allocation
.height
= MAX (1, paned
->child1_size
);
405 child1_allocation
.x
= child2_allocation
.x
= widget
->allocation
.x
+ border_width
;
406 child1_allocation
.y
= widget
->allocation
.y
+ border_width
;
408 child2_allocation
.y
= child1_allocation
.y
+ paned
->child1_size
+ paned
->handle_pos
.height
;
409 child2_allocation
.height
= MAX (1, widget
->allocation
.y
+ widget
->allocation
.height
- child2_allocation
.y
- border_width
);
411 if (GTK_WIDGET_MAPPED (widget
) &&
412 paned
->child1
->allocation
.height
< child1_allocation
.height
)
414 gtk_widget_size_allocate (paned
->child2
, &child2_allocation
);
415 gtk_widget_size_allocate (paned
->child1
, &child1_allocation
);
419 gtk_widget_size_allocate (paned
->child1
, &child1_allocation
);
420 gtk_widget_size_allocate (paned
->child2
, &child2_allocation
);
425 GtkAllocation child_allocation
;
427 if (GTK_WIDGET_REALIZED (widget
))
428 gdk_window_hide (paned
->handle
);
431 gtk_widget_set_child_visible (paned
->child1
, TRUE
);
433 gtk_widget_set_child_visible (paned
->child2
, TRUE
);
435 child_allocation
.x
= widget
->allocation
.x
+ border_width
;
436 child_allocation
.y
= widget
->allocation
.y
+ border_width
;
437 child_allocation
.width
= MAX (1, allocation
->width
- 2 * border_width
);
438 child_allocation
.height
= MAX (1, allocation
->height
- 2 * border_width
);
440 if (paned
->child1
&& GTK_WIDGET_VISIBLE (paned
->child1
))
441 gtk_widget_size_allocate (paned
->child1
, &child_allocation
);
442 else if (paned
->child2
&& GTK_WIDGET_VISIBLE (paned
->child2
))
443 gtk_widget_size_allocate (paned
->child2
, &child_allocation
);