561eba2a |
1 | #include <gtk/gtk.h> |
2 | |
95cd67ef |
3 | #include <lttv/gtkcustom.h> |
561eba2a |
4 | //#include "gtkintl.h" |
68b48a45 |
5 | #include <lttv/mainWindow.h> |
58960b51 |
6 | #include <lttv/gtkTraceSet.h> |
561eba2a |
7 | |
8 | static void gtk_custom_class_init (GtkCustomClass *klass); |
9 | static void gtk_custom_init (GtkCustom *custom); |
10 | |
11 | |
12 | static void gtk_custom_size_request (GtkWidget *widget, |
13 | GtkRequisition *requisition); |
14 | static void gtk_custom_size_allocate (GtkWidget *widget, |
15 | GtkAllocation *allocation); |
16 | |
58960b51 |
17 | void gtk_custom_scroll_value_changed (GtkRange *range, gpointer custom); |
18 | |
561eba2a |
19 | GType |
20 | gtk_custom_get_type (void) |
21 | { |
22 | static GType custom_type = 0; |
23 | |
24 | if (!custom_type) |
25 | { |
26 | static const GTypeInfo custom_info = |
27 | { |
28 | sizeof (GtkCustomClass), |
29 | NULL, /* base_init */ |
30 | NULL, /* base_finalize */ |
31 | (GClassInitFunc) gtk_custom_class_init, |
32 | NULL, /* class_finalize */ |
33 | NULL, /* class_data */ |
34 | sizeof (GtkCustom), |
35 | 0, /* n_preallocs */ |
36 | (GInstanceInitFunc) gtk_custom_init, |
37 | NULL, /* value_table */ |
38 | }; |
39 | |
40 | custom_type = g_type_register_static (GTK_TYPE_PANED, "GtkCustom", |
41 | &custom_info, 0); |
42 | } |
43 | |
44 | return custom_type; |
45 | } |
46 | |
47 | static void |
48 | gtk_custom_class_init (GtkCustomClass *class) |
49 | { |
50 | GtkWidgetClass *widget_class; |
51 | |
52 | widget_class = (GtkWidgetClass *) class; |
53 | |
54 | widget_class->size_request = gtk_custom_size_request; |
55 | widget_class->size_allocate = gtk_custom_size_allocate; |
56 | } |
57 | |
58 | static void |
59 | gtk_custom_init (GtkCustom *custom) |
60 | { |
61 | GtkWidget * button; |
62 | |
63 | GTK_WIDGET_SET_FLAGS (custom, GTK_NO_WINDOW); |
64 | gtk_widget_set_redraw_on_allocate (GTK_WIDGET (custom), FALSE); |
65 | |
66 | custom->firstPane = NULL; |
67 | custom->lastPane = NULL; |
68 | custom->focusedPane = NULL; |
69 | custom->numChildren = 0; |
70 | |
71 | custom->vbox = NULL; |
72 | // custom->scrollWindow = NULL; |
73 | // custom->viewport = NULL; |
74 | custom->hScrollbar = NULL; |
75 | } |
76 | |
77 | |
78 | GtkWidget* gtk_custom_new () |
79 | { |
80 | return GTK_WIDGET (g_object_new (gtk_custom_get_type (), NULL)); |
81 | } |
82 | |
83 | |
84 | void gtk_custom_set_focus (GtkWidget * widget, gpointer user_data) |
85 | { |
86 | GtkCustom * custom = (GtkCustom*) widget; |
87 | GtkPaned * pane; |
88 | if(!custom->firstPane) return; |
89 | |
90 | |
91 | pane = custom->firstPane; |
92 | while(1){ |
93 | if((GtkWidget*)pane == (GtkWidget*)user_data){ |
94 | custom->focusedPane = pane; |
95 | break; |
96 | } |
97 | if(pane == custom->lastPane){ |
98 | custom->focusedPane = NULL; |
99 | break; |
100 | } |
101 | pane = (GtkPaned*)pane->child1; |
102 | } |
103 | } |
104 | |
105 | void gtk_custom_widget_add(GtkCustom * custom, GtkWidget * widget1) |
106 | { |
107 | GtkPaned * tmpPane; |
108 | GtkWidget * w; |
f7afe191 |
109 | TimeWindow Time_Window; |
58960b51 |
110 | LttTime time; |
f7afe191 |
111 | TimeInterval *Time_Span; |
112 | |
561eba2a |
113 | g_return_if_fail(GTK_IS_CUSTOM(custom)); |
114 | g_object_ref(G_OBJECT(widget1)); |
115 | |
116 | |
117 | if(!custom->firstPane){ |
118 | custom->firstPane = (GtkPaned *)gtk_vpaned_new(); |
119 | custom->lastPane = custom->firstPane; |
120 | |
121 | custom->hScrollbar = gtk_hscrollbar_new (NULL); |
122 | gtk_widget_show(custom->hScrollbar); |
58960b51 |
123 | |
124 | custom->hAdjust = gtk_range_get_adjustment(GTK_RANGE(custom->hScrollbar)); |
f7afe191 |
125 | GetTimeWindow(custom->mw,&Time_Window); |
58960b51 |
126 | GetCurrentTime(custom->mw,&time); |
f7afe191 |
127 | Time_Span = LTTV_TRACESET_CONTEXT(custom->mw->Traceset_Info->TracesetContext)->Time_Span ; |
58960b51 |
128 | |
308711e5 |
129 | custom->hAdjust->lower = ltt_time_to_double(Time_Span->startTime) * |
130 | NANOSECONDS_PER_SECOND; |
131 | custom->hAdjust->value = custom->hAdjust->lower; |
132 | custom->hAdjust->upper = ltt_time_to_double(Time_Span->endTime) * |
133 | NANOSECONDS_PER_SECOND; |
f7afe191 |
134 | /* Page increment of whole visible area */ |
308711e5 |
135 | custom->hAdjust->page_increment = ltt_time_to_double( |
136 | Time_Window.Time_Width) * NANOSECONDS_PER_SECOND; |
f7afe191 |
137 | /* page_size to the whole visible area will take care that the |
138 | * scroll value + the shown area will never be more than what is |
139 | * in the trace. */ |
308711e5 |
140 | custom->hAdjust->page_size = custom->hAdjust->page_increment; |
141 | custom->hAdjust->step_increment = custom->hAdjust->page_increment / 10; |
f7afe191 |
142 | |
143 | gtk_range_set_update_policy (GTK_RANGE(custom->hScrollbar), |
144 | GTK_UPDATE_DISCONTINUOUS); |
58960b51 |
145 | g_signal_connect(G_OBJECT(custom->hScrollbar), "value-changed", |
146 | G_CALLBACK(gtk_custom_scroll_value_changed), custom); |
147 | |
561eba2a |
148 | custom->vbox = gtk_vbox_new(FALSE,0); |
149 | gtk_widget_show(custom->vbox); |
150 | |
151 | // custom->viewport = gtk_viewport_new (NULL,NULL); |
152 | // gtk_widget_show(custom->viewport); |
153 | |
154 | // gtk_container_add(GTK_CONTAINER(custom->viewport), (GtkWidget*)custom->vbox); |
155 | gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->hScrollbar,FALSE,FALSE,0); |
156 | gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->firstPane,TRUE,TRUE,0); |
157 | |
158 | // custom->scrollWindow = gtk_scrolled_window_new (NULL, NULL); |
159 | // gtk_widget_show(custom->scrollWindow); |
160 | // gtk_container_add (GTK_CONTAINER (custom->scrollWindow), (GtkWidget*)custom->viewport); |
161 | // gtk_paned_pack1(GTK_PANED(custom), (GtkWidget*)custom->scrollWindow,FALSE, TRUE); |
162 | |
163 | gtk_paned_pack1(GTK_PANED(custom), (GtkWidget*)custom->vbox,FALSE, TRUE); |
164 | }else{ |
165 | tmpPane = custom->lastPane; |
166 | custom->lastPane = (GtkPaned *)gtk_vpaned_new(); |
167 | gtk_paned_pack1 (tmpPane,(GtkWidget*)custom->lastPane, FALSE,TRUE); |
168 | } |
169 | gtk_widget_show((GtkWidget *)custom->lastPane); |
170 | |
171 | gtk_paned_pack2 (custom->lastPane,widget1, TRUE, TRUE); |
172 | custom->focusedPane = custom->lastPane; |
173 | custom->numChildren++; |
174 | |
175 | } |
176 | |
177 | void gtk_custom_widget_delete(GtkCustom * custom) |
178 | { |
179 | GtkPaned * tmp, *prev, *next; |
180 | |
181 | if(!custom->focusedPane) return; |
182 | |
183 | tmp = (GtkPaned*)custom->focusedPane->child2; //widget in vpaned |
184 | g_object_unref(G_OBJECT(tmp)); |
185 | |
186 | if(custom->focusedPane == custom->firstPane && |
187 | custom->focusedPane == custom->lastPane){ |
188 | // gtk_container_remove(GTK_CONTAINER(custom),(GtkWidget*)custom->scrollWindow); |
189 | gtk_container_remove(GTK_CONTAINER(custom),(GtkWidget*)custom->vbox); |
190 | custom->firstPane = NULL; |
191 | custom->lastPane = NULL; |
192 | custom->focusedPane = NULL; |
193 | }else if(custom->focusedPane == custom->firstPane && |
194 | custom->focusedPane != custom->lastPane){ |
195 | next = (GtkPaned*)custom->firstPane->child1; |
196 | g_object_ref(G_OBJECT(next)); |
197 | gtk_container_remove(GTK_CONTAINER(custom->firstPane),(GtkWidget*)next); |
198 | gtk_container_remove(GTK_CONTAINER(custom->vbox),(GtkWidget*)custom->firstPane); |
199 | custom->firstPane = next; |
200 | gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->firstPane,TRUE,TRUE,0); |
201 | custom->focusedPane = custom->firstPane; |
202 | g_object_unref(G_OBJECT(next)); |
203 | }else if(custom->focusedPane != custom->firstPane && |
204 | custom->focusedPane == custom->lastPane){ |
205 | tmp = custom->lastPane; |
206 | custom->lastPane = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)custom->lastPane); |
207 | custom->focusedPane = custom->lastPane; |
208 | gtk_container_remove(GTK_CONTAINER(custom->lastPane),(GtkWidget*)tmp); |
209 | }else{ |
210 | tmp = custom->focusedPane; |
211 | prev = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)tmp); |
212 | next = (GtkPaned*)tmp->child1; |
213 | g_object_ref(G_OBJECT(next)); |
214 | gtk_container_remove(GTK_CONTAINER(custom->focusedPane),(GtkWidget*)next); |
215 | gtk_container_remove(GTK_CONTAINER(prev),(GtkWidget*)custom->focusedPane); |
216 | gtk_paned_pack1(prev, (GtkWidget*)next, FALSE, TRUE); |
217 | custom->focusedPane = next; |
218 | g_object_unref(G_OBJECT(next)); |
219 | } |
220 | |
221 | custom->numChildren--; |
222 | } |
223 | |
224 | |
225 | void gtk_custom_widget_move_up(GtkCustom * custom) |
226 | { |
227 | GtkWidget* upWidget, *downWidget; |
228 | GtkPaned * prev,*next, *prevPrev; |
229 | |
230 | if(custom->lastPane == custom->focusedPane) return; |
231 | |
232 | // move VPane |
233 | prev = (GtkPaned*)custom->focusedPane->child1; |
234 | g_object_ref(G_OBJECT(prev)); |
235 | gtk_container_remove(GTK_CONTAINER(custom->focusedPane),(GtkWidget*)prev); |
236 | |
237 | if(prev == custom->lastPane){ |
238 | prevPrev = NULL; |
239 | custom->lastPane = custom->focusedPane; |
240 | }else{ |
241 | prevPrev = (GtkPaned*)prev->child1; |
242 | g_object_ref(G_OBJECT(prevPrev)); |
243 | gtk_container_remove(GTK_CONTAINER(prev),(GtkWidget*)prevPrev); |
244 | } |
245 | |
246 | g_object_ref(G_OBJECT(custom->focusedPane)); |
247 | if(custom->firstPane == custom->focusedPane){ |
248 | gtk_container_remove(GTK_CONTAINER(custom->vbox),(GtkWidget*)custom->focusedPane); |
249 | gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)prev,TRUE,TRUE,0); |
250 | custom->firstPane = prev; |
251 | }else{ |
252 | next = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)custom->focusedPane); |
253 | gtk_container_remove(GTK_CONTAINER(next),(GtkWidget*)custom->focusedPane); |
254 | gtk_paned_pack1(GTK_PANED(next), (GtkWidget*)prev, FALSE,TRUE); |
255 | } |
256 | gtk_paned_pack1(GTK_PANED(prev),(GtkWidget*)custom->focusedPane, FALSE,TRUE); |
257 | if(prevPrev) |
258 | gtk_paned_pack1(GTK_PANED(custom->focusedPane),(GtkWidget*)prevPrev, FALSE,TRUE); |
259 | |
260 | g_object_unref(G_OBJECT(prev)); |
261 | if(prevPrev) g_object_unref(G_OBJECT(prevPrev)); |
262 | g_object_unref(G_OBJECT(custom->focusedPane)); |
263 | } |
264 | |
265 | |
266 | void gtk_custom_widget_move_down(GtkCustom * custom) |
267 | { |
268 | GtkWidget* upWidget, *downWidget; |
269 | GtkPaned * prev,*next, *nextNext; |
270 | |
271 | if(custom->firstPane == custom->focusedPane) return; |
272 | |
273 | //move VPane |
274 | next = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)custom->focusedPane); |
275 | g_object_ref(G_OBJECT(next)); |
276 | |
277 | if(custom->lastPane == custom->focusedPane){ |
278 | prev = NULL; |
279 | custom->lastPane = next; |
280 | }else{ |
281 | prev = (GtkPaned*)custom->focusedPane->child1; |
282 | g_object_ref(G_OBJECT(prev)); |
283 | gtk_container_remove(GTK_CONTAINER(custom->focusedPane),(GtkWidget*)prev); |
284 | } |
285 | |
286 | g_object_ref(G_OBJECT(custom->focusedPane)); |
287 | gtk_container_remove(GTK_CONTAINER(next),(GtkWidget*)custom->focusedPane); |
288 | |
289 | if(next == custom->firstPane){ |
290 | custom->firstPane = custom->focusedPane; |
291 | gtk_container_remove(GTK_CONTAINER(custom->vbox),(GtkWidget*)next); |
292 | gtk_box_pack_end(GTK_BOX(custom->vbox),(GtkWidget*)custom->focusedPane,TRUE,TRUE,0); |
293 | }else{ |
294 | nextNext = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)next); |
295 | gtk_container_remove(GTK_CONTAINER(nextNext),(GtkWidget*)next); |
296 | gtk_paned_pack1(nextNext, (GtkWidget*)custom->focusedPane, FALSE, TRUE); |
297 | } |
298 | gtk_paned_pack1(custom->focusedPane,(GtkWidget*)next, FALSE,TRUE); |
299 | if(prev) |
300 | gtk_paned_pack1(next,(GtkWidget*)prev, FALSE,TRUE); |
301 | |
302 | if(prev)g_object_unref(G_OBJECT(prev)); |
303 | g_object_unref(G_OBJECT(next)); |
304 | g_object_unref(G_OBJECT(custom->focusedPane)); |
305 | } |
306 | |
58960b51 |
307 | void gtk_custom_scroll_value_changed(GtkRange *range, gpointer custom_arg) |
308 | { |
309 | LttTime time; |
310 | GtkCustom * custom = (GtkCustom*)custom_arg; |
311 | gdouble value = gtk_range_get_value(range); |
308711e5 |
312 | time = ltt_time_from_double(value / NANOSECONDS_PER_SECOND); |
58960b51 |
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 | |
561eba2a |
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 | |