561eba2a |
1 | #include <gtk/gtk.h> |
2 | |
95cd67ef |
3 | #include <lttv/gtkcustom.h> |
561eba2a |
4 | //#include "gtkintl.h" |
58960b51 |
5 | #include <lttv/gtkTraceSet.h> |
561eba2a |
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 | |
58960b51 |
16 | void gtk_custom_scroll_value_changed (GtkRange *range, gpointer custom); |
17 | |
561eba2a |
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; |
f7afe191 |
108 | TimeWindow Time_Window; |
58960b51 |
109 | LttTime time; |
f7afe191 |
110 | TimeInterval *Time_Span; |
111 | |
561eba2a |
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); |
58960b51 |
122 | |
123 | custom->hAdjust = gtk_range_get_adjustment(GTK_RANGE(custom->hScrollbar)); |
f7afe191 |
124 | GetTimeWindow(custom->mw,&Time_Window); |
58960b51 |
125 | GetCurrentTime(custom->mw,&time); |
f7afe191 |
126 | Time_Span = LTTV_TRACESET_CONTEXT(custom->mw->Traceset_Info->TracesetContext)->Time_Span ; |
58960b51 |
127 | |
308711e5 |
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; |
f7afe191 |
133 | /* Page increment of whole visible area */ |
308711e5 |
134 | custom->hAdjust->page_increment = ltt_time_to_double( |
135 | Time_Window.Time_Width) * NANOSECONDS_PER_SECOND; |
f7afe191 |
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 |
138 | * in the trace. */ |
308711e5 |
139 | custom->hAdjust->page_size = custom->hAdjust->page_increment; |
140 | custom->hAdjust->step_increment = custom->hAdjust->page_increment / 10; |
f7afe191 |
141 | |
142 | gtk_range_set_update_policy (GTK_RANGE(custom->hScrollbar), |
143 | GTK_UPDATE_DISCONTINUOUS); |
58960b51 |
144 | g_signal_connect(G_OBJECT(custom->hScrollbar), "value-changed", |
145 | G_CALLBACK(gtk_custom_scroll_value_changed), custom); |
146 | |
561eba2a |
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 | |
58960b51 |
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); |
308711e5 |
311 | time = ltt_time_from_double(value / NANOSECONDS_PER_SECOND); |
58960b51 |
312 | SetCurrentTime(custom->mw, &time); |
313 | g_warning("The current time is second :%d, nanosecond : %d\n", time.tv_sec, time.tv_nsec); |
314 | } |
315 | |
561eba2a |
316 | |
317 | static void |
318 | gtk_custom_size_request (GtkWidget *widget, |
319 | GtkRequisition *requisition) |
320 | { |
321 | GtkPaned *paned = GTK_PANED (widget); |
322 | GtkRequisition child_requisition; |
323 | |
324 | requisition->width = 0; |
325 | requisition->height = 0; |
326 | |
327 | if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1)) |
328 | { |
329 | gtk_widget_size_request (paned->child1, &child_requisition); |
330 | |
331 | requisition->height = child_requisition.height; |
332 | requisition->width = child_requisition.width; |
333 | } |
334 | |
335 | if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) |
336 | { |
337 | gtk_widget_size_request (paned->child2, &child_requisition); |
338 | |
339 | requisition->width = MAX (requisition->width, child_requisition.width); |
340 | requisition->height += child_requisition.height; |
341 | } |
342 | |
343 | requisition->height += GTK_CONTAINER (paned)->border_width * 2; |
344 | requisition->width += GTK_CONTAINER (paned)->border_width * 2; |
345 | |
346 | if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) && |
347 | paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) |
348 | { |
349 | gint handle_size; |
350 | |
351 | gtk_widget_style_get (widget, "handle_size", &handle_size, NULL); |
352 | requisition->height += handle_size; |
353 | } |
354 | |
355 | } |
356 | |
357 | static void |
358 | gtk_custom_size_allocate (GtkWidget *widget, |
359 | GtkAllocation *allocation) |
360 | { |
361 | GtkPaned *paned = GTK_PANED (widget); |
362 | gint border_width = GTK_CONTAINER (paned)->border_width; |
363 | |
364 | widget->allocation = *allocation; |
365 | |
366 | if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) && |
367 | paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) |
368 | { |
369 | GtkRequisition child1_requisition; |
370 | GtkRequisition child2_requisition; |
371 | GtkAllocation child1_allocation; |
372 | GtkAllocation child2_allocation; |
373 | gint handle_size; |
374 | |
375 | gtk_widget_style_get (widget, "handle_size", &handle_size, NULL); |
376 | |
377 | gtk_widget_get_child_requisition (paned->child1, &child1_requisition); |
378 | gtk_widget_get_child_requisition (paned->child2, &child2_requisition); |
379 | |
380 | gtk_paned_compute_position (paned, |
381 | MAX (1, widget->allocation.height |
382 | - handle_size |
383 | - 2 * border_width), |
384 | child1_requisition.height, |
385 | child2_requisition.height); |
386 | |
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; |
391 | |
392 | if (GTK_WIDGET_REALIZED (widget)) |
393 | { |
394 | if (GTK_WIDGET_MAPPED (widget)) |
395 | gdk_window_show (paned->handle); |
396 | gdk_window_move_resize (paned->handle, |
397 | paned->handle_pos.x, |
398 | paned->handle_pos.y, |
399 | paned->handle_pos.width, |
400 | handle_size); |
401 | } |
402 | |
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; |
407 | |
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); |
410 | |
411 | if (GTK_WIDGET_MAPPED (widget) && |
412 | paned->child1->allocation.height < child1_allocation.height) |
413 | { |
414 | gtk_widget_size_allocate (paned->child2, &child2_allocation); |
415 | gtk_widget_size_allocate (paned->child1, &child1_allocation); |
416 | } |
417 | else |
418 | { |
419 | gtk_widget_size_allocate (paned->child1, &child1_allocation); |
420 | gtk_widget_size_allocate (paned->child2, &child2_allocation); |
421 | } |
422 | } |
423 | else |
424 | { |
425 | GtkAllocation child_allocation; |
426 | |
427 | if (GTK_WIDGET_REALIZED (widget)) |
428 | gdk_window_hide (paned->handle); |
429 | |
430 | if (paned->child1) |
431 | gtk_widget_set_child_visible (paned->child1, TRUE); |
432 | if (paned->child2) |
433 | gtk_widget_set_child_visible (paned->child2, TRUE); |
434 | |
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); |
439 | |
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); |
444 | } |
445 | } |
446 | |