unref attribute should work better
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / lttvwindow / gtkmultivpaned.c
CommitLineData
e076699e 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 XangXiu Yang
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
daecc161 19#include <gtk/gtk.h>
20
13f86ce2 21#include <lttvwindow/gtkmultivpaned.h>
13f86ce2 22#include <lttvwindow/mainwindow.h>
2d262115 23#include <lttvwindow/mainwindow-private.h>
24//#include "gtkintl.h"
daecc161 25
26static void gtk_multi_vpaned_class_init (GtkMultiVPanedClass *klass);
27static void gtk_multi_vpaned_init (GtkMultiVPaned *multi_vpaned);
28
29
30static void gtk_multi_vpaned_size_request (GtkWidget *widget,
31 GtkRequisition *requisition);
32static void gtk_multi_vpaned_size_allocate (GtkWidget *widget,
33 GtkAllocation *allocation);
34
a43d67ba 35void gtk_multi_vpaned_scroll_value_changed (GtkAdjustment *adjust, gpointer multi_vpaned);
daecc161 36
0ed9daf7 37gboolean gtk_multi_vpaned_destroy(GtkObject *object,
38 gpointer user_data)
39{
40 GtkMultiVPaned * multi_vpaned = (GtkMultiVPaned * )object;
41 while(multi_vpaned->num_children){
42 gtk_multi_vpaned_widget_delete(multi_vpaned);
43 }
44 return FALSE;
45}
46
daecc161 47GType
48gtk_multi_vpaned_get_type (void)
49{
50 static GType multi_vpaned_type = 0;
51
52 if (!multi_vpaned_type)
53 {
54 static const GTypeInfo multi_vpaned_info =
55 {
56 sizeof (GtkMultiVPanedClass),
57 NULL, /* base_init */
58 NULL, /* base_finalize */
59 (GClassInitFunc) gtk_multi_vpaned_class_init,
60 NULL, /* class_finalize */
61 NULL, /* class_data */
62 sizeof (GtkMultiVPaned),
63 0, /* n_preallocs */
64 (GInstanceInitFunc) gtk_multi_vpaned_init,
65 NULL, /* value_table */
66 };
67
68 multi_vpaned_type = g_type_register_static (GTK_TYPE_PANED, "GtkMultiVPaned",
69 &multi_vpaned_info, 0);
70 }
71
72 return multi_vpaned_type;
73}
74
75static void
76gtk_multi_vpaned_class_init (GtkMultiVPanedClass *class)
77{
78 GtkWidgetClass *widget_class;
79
80 widget_class = (GtkWidgetClass *) class;
81
82 widget_class->size_request = gtk_multi_vpaned_size_request;
83 widget_class->size_allocate = gtk_multi_vpaned_size_allocate;
84}
85
86static void
87gtk_multi_vpaned_init (GtkMultiVPaned * multi_vpaned)
88{
89 GtkWidget * button;
90
91 GTK_WIDGET_SET_FLAGS (multi_vpaned, GTK_NO_WINDOW);
92 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (multi_vpaned), FALSE);
93
94 multi_vpaned->first_pane = NULL;
95 multi_vpaned->last_pane = NULL;
96 multi_vpaned->focused_pane = NULL;
49bf71b5 97 multi_vpaned->iter = NULL;
daecc161 98 multi_vpaned->num_children = 0;
99
100 multi_vpaned->vbox = NULL;
101 // multi_vpaned->scrollWindow = NULL;
102 // multi_vpaned->viewport = NULL;
103 multi_vpaned->hscrollbar = NULL;
104}
105
106
107GtkWidget* gtk_multi_vpaned_new ()
108{
0ed9daf7 109 GtkWidget * widget = GTK_WIDGET (g_object_new (gtk_multi_vpaned_get_type (), NULL));
110 g_signal_connect(G_OBJECT(widget), "destroy",
111 G_CALLBACK(gtk_multi_vpaned_destroy),NULL);
112
113 return widget;
daecc161 114}
115
49bf71b5 116GtkWidget * gtk_multi_vpaned_get_widget(GtkMultiVPaned * multi_vpaned)
117{
118 if(multi_vpaned->focused_pane == NULL)return NULL;
119 return (GtkWidget*)multi_vpaned->focused_pane->child2;
120}
121
122GtkWidget * gtk_multi_vpaned_get_first_widget(GtkMultiVPaned * multi_vpaned)
123{
124 if(multi_vpaned->first_pane == NULL)return NULL;
125 multi_vpaned->iter = multi_vpaned->first_pane;
126 return multi_vpaned->first_pane->child2;
127}
128
129GtkWidget * gtk_multi_vpaned_get_next_widget(GtkMultiVPaned * multi_vpaned)
130{
131 if(multi_vpaned->iter != multi_vpaned->last_pane){
132 multi_vpaned->iter = (GtkPaned *)multi_vpaned->iter->child1;
133 return multi_vpaned->iter->child2;
134 }else {
135 return NULL;
136 }
137}
138
139void gtk_multi_vpaned_set_data(GtkMultiVPaned * multi_vpaned,char * key, gpointer value)
140{
141 g_object_set_data(G_OBJECT(multi_vpaned->focused_pane), key, value);
142}
143
144gpointer gtk_multi_vpaned_get_data(GtkMultiVPaned * multi_vpaned,char * key)
145{
146 if(multi_vpaned->focused_pane == NULL)return NULL;
147 return g_object_get_data(G_OBJECT(multi_vpaned->focused_pane), key);
148}
daecc161 149
5a5b35c5 150void gtk_multi_vpaned_set_focus (GtkWidget * widget, GtkPaned* paned)
daecc161 151{
5a5b35c5 152 GtkMultiVPaned * multi_vpaned = GTK_MULTI_VPANED(widget);
daecc161 153 GtkPaned * pane;
154 if(!multi_vpaned->first_pane) return;
155
156
157 pane = multi_vpaned->first_pane;
158 while(1){
7afc14aa 159 if((GtkWidget*)pane == GTK_WIDGET(paned)){
daecc161 160 multi_vpaned->focused_pane = pane;
161 break;
162 }
163 if(pane == multi_vpaned->last_pane){
164 multi_vpaned->focused_pane = NULL;
165 break;
166 }
167 pane = (GtkPaned*)pane->child1;
168 }
169}
170
a43d67ba 171void gtk_multi_vpaned_set_adjust(GtkMultiVPaned * multi_vpaned, const TimeWindow *time_window, gboolean first_time)
daecc161 172{
daecc161 173 TimeInterval *time_span;
a43d67ba 174 double len, start;
6ced96ef 175 Tab *tab = (Tab *)g_object_get_data(G_OBJECT(multi_vpaned), "Tab_Info");
501e4e70 176 LttvTracesetContext *tsc =
2d262115 177 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
daecc161 178
297f7a48 179
daecc161 180 if(first_time){
501e4e70 181 time_span = &tsc->time_span ;
daecc161 182
7afc14aa 183 multi_vpaned->hadjust->lower = ltt_time_to_double(time_span->start_time) *
daecc161 184 NANOSECONDS_PER_SECOND;
185 multi_vpaned->hadjust->value = multi_vpaned->hadjust->lower;
7afc14aa 186 multi_vpaned->hadjust->upper = ltt_time_to_double(time_span->end_time) *
daecc161 187 NANOSECONDS_PER_SECOND;
188 }
189
190 /* Page increment of whole visible area */
191 if(multi_vpaned->hadjust == NULL){
192 g_warning("Insert a viewer first");
193 return;
194 }
195
a43d67ba 196 start = ltt_time_to_double(time_window->start_time) * NANOSECONDS_PER_SECOND;
197 len = multi_vpaned->hadjust->upper - multi_vpaned->hadjust->lower;
daecc161 198
199 multi_vpaned->hadjust->page_increment = ltt_time_to_double(
a43d67ba 200 time_window->time_width) * NANOSECONDS_PER_SECOND;
daecc161 201
a43d67ba 202 //if(multi_vpaned->hadjust->page_increment >= len )
203 // multi_vpaned->hadjust->value = multi_vpaned->hadjust->lower;
204 //if(start + multi_vpaned->hadjust->page_increment >= multi_vpaned->hadjust->upper )
205 // multi_vpaned->hadjust->value = start;
206 multi_vpaned->hadjust->value = start;
daecc161 207
208 /* page_size to the whole visible area will take care that the
209 * scroll value + the shown area will never be more than what is
210 * in the trace. */
211 multi_vpaned->hadjust->page_size = multi_vpaned->hadjust->page_increment;
212 multi_vpaned->hadjust->step_increment = multi_vpaned->hadjust->page_increment / 10;
213
214 gtk_adjustment_changed (multi_vpaned->hadjust);
a43d67ba 215
daecc161 216}
217
218void gtk_multi_vpaned_widget_add(GtkMultiVPaned * multi_vpaned, GtkWidget * widget1)
219{
220 GtkPaned * tmpPane;
221 GtkWidget * w;
6ced96ef 222 Tab *tab = (Tab *)g_object_get_data(G_OBJECT(multi_vpaned), "Tab_Info");
daecc161 223
224 g_return_if_fail(GTK_IS_MULTI_VPANED(multi_vpaned));
225 g_object_ref(G_OBJECT(widget1));
226
227
228 if(!multi_vpaned->first_pane){
229 multi_vpaned->first_pane = (GtkPaned *)gtk_vpaned_new();
230 multi_vpaned->last_pane = multi_vpaned->first_pane;
231
232 multi_vpaned->hscrollbar = gtk_hscrollbar_new (NULL);
233 gtk_widget_show(multi_vpaned->hscrollbar);
234
235 multi_vpaned->hadjust = gtk_range_get_adjustment(GTK_RANGE(multi_vpaned->hscrollbar));
2d262115 236 gtk_multi_vpaned_set_adjust(multi_vpaned, &tab->time_window, TRUE);
daecc161 237
238 gtk_range_set_update_policy (GTK_RANGE(multi_vpaned->hscrollbar),
4a93bd36 239 GTK_UPDATE_CONTINUOUS);
240 //changed by Mathieu Desnoyers, was :
241 // GTK_UPDATE_DISCONTINUOUS);
a43d67ba 242 g_signal_connect(G_OBJECT(multi_vpaned->hadjust), "value-changed",
daecc161 243 G_CALLBACK(gtk_multi_vpaned_scroll_value_changed), multi_vpaned);
a43d67ba 244 g_signal_connect(G_OBJECT(multi_vpaned->hadjust), "changed",
245 G_CALLBACK(gtk_multi_vpaned_scroll_value_changed), multi_vpaned);
246
daecc161 247
248 multi_vpaned->vbox = gtk_vbox_new(FALSE,0);
249 gtk_widget_show(multi_vpaned->vbox);
250
251 // multi_vpaned->viewport = gtk_viewport_new (NULL,NULL);
252 // gtk_widget_show(multi_vpaned->viewport);
253
254 // gtk_container_add(GTK_CONTAINER(multi_vpaned->viewport), (GtkWidget*)multi_vpaned->vbox);
255 gtk_box_pack_end(GTK_BOX(multi_vpaned->vbox),(GtkWidget*)multi_vpaned->hscrollbar,FALSE,FALSE,0);
256 gtk_box_pack_end(GTK_BOX(multi_vpaned->vbox),(GtkWidget*)multi_vpaned->first_pane,TRUE,TRUE,0);
257
258 // multi_vpaned->scrollWindow = gtk_scrolled_window_new (NULL, NULL);
259 // gtk_widget_show(multi_vpaned->scrollWindow);
260 // gtk_container_add (GTK_CONTAINER (multi_vpaned->scrollWindow), (GtkWidget*)multi_vpaned->viewport);
261 // gtk_paned_pack1(GTK_PANED(multi_vpaned), (GtkWidget*)multi_vpaned->scrollWindow,FALSE, TRUE);
262
263 gtk_paned_pack1(GTK_PANED(multi_vpaned), (GtkWidget*)multi_vpaned->vbox,FALSE, TRUE);
264 }else{
265 tmpPane = multi_vpaned->last_pane;
266 multi_vpaned->last_pane = (GtkPaned *)gtk_vpaned_new();
267 gtk_paned_pack1 (tmpPane,(GtkWidget*)multi_vpaned->last_pane, FALSE,TRUE);
268 }
269 gtk_widget_show((GtkWidget *)multi_vpaned->last_pane);
270
271 gtk_paned_pack2 (multi_vpaned->last_pane,widget1, TRUE, TRUE);
272 multi_vpaned->focused_pane = multi_vpaned->last_pane;
273 multi_vpaned->num_children++;
274
275}
276
277void gtk_multi_vpaned_widget_delete(GtkMultiVPaned * multi_vpaned)
278{
279 GtkPaned * tmp, *prev, *next;
280
281 if(!multi_vpaned->focused_pane) return;
282
283 tmp = (GtkPaned*)multi_vpaned->focused_pane->child2; //widget in vpaned
284 g_object_unref(G_OBJECT(tmp));
285
286 if(multi_vpaned->focused_pane == multi_vpaned->first_pane &&
287 multi_vpaned->focused_pane == multi_vpaned->last_pane){
288 // gtk_container_remove(GTK_CONTAINER(multi_vpaned),(GtkWidget*)multi_vpaned->scrollWindow);
289 gtk_container_remove(GTK_CONTAINER(multi_vpaned),(GtkWidget*)multi_vpaned->vbox);
290 multi_vpaned->first_pane = NULL;
291 multi_vpaned->last_pane = NULL;
292 multi_vpaned->focused_pane = NULL;
293 }else if(multi_vpaned->focused_pane == multi_vpaned->first_pane &&
294 multi_vpaned->focused_pane != multi_vpaned->last_pane){
295 next = (GtkPaned*)multi_vpaned->first_pane->child1;
296 g_object_ref(G_OBJECT(next));
297 gtk_container_remove(GTK_CONTAINER(multi_vpaned->first_pane),(GtkWidget*)next);
298 gtk_container_remove(GTK_CONTAINER(multi_vpaned->vbox),(GtkWidget*)multi_vpaned->first_pane);
299 multi_vpaned->first_pane = next;
300 gtk_box_pack_end(GTK_BOX(multi_vpaned->vbox),(GtkWidget*)multi_vpaned->first_pane,TRUE,TRUE,0);
301 multi_vpaned->focused_pane = multi_vpaned->first_pane;
302 g_object_unref(G_OBJECT(next));
303 }else if(multi_vpaned->focused_pane != multi_vpaned->first_pane &&
304 multi_vpaned->focused_pane == multi_vpaned->last_pane){
305 tmp = multi_vpaned->last_pane;
306 multi_vpaned->last_pane = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)multi_vpaned->last_pane);
307 multi_vpaned->focused_pane = multi_vpaned->last_pane;
308 gtk_container_remove(GTK_CONTAINER(multi_vpaned->last_pane),(GtkWidget*)tmp);
309 }else{
310 tmp = multi_vpaned->focused_pane;
311 prev = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)tmp);
312 next = (GtkPaned*)tmp->child1;
313 g_object_ref(G_OBJECT(next));
314 gtk_container_remove(GTK_CONTAINER(multi_vpaned->focused_pane),(GtkWidget*)next);
315 gtk_container_remove(GTK_CONTAINER(prev),(GtkWidget*)multi_vpaned->focused_pane);
316 gtk_paned_pack1(prev, (GtkWidget*)next, FALSE, TRUE);
317 multi_vpaned->focused_pane = next;
318 g_object_unref(G_OBJECT(next));
319 }
320
321 multi_vpaned->num_children--;
322}
323
324
325void gtk_multi_vpaned_widget_move_up(GtkMultiVPaned * multi_vpaned)
326{
327 GtkWidget* upWidget, *downWidget;
328 GtkPaned * prev,*next, *prevPrev;
329
330 if(multi_vpaned->last_pane == multi_vpaned->focused_pane) return;
331
332 // move VPane
333 prev = (GtkPaned*)multi_vpaned->focused_pane->child1;
334 g_object_ref(G_OBJECT(prev));
335 gtk_container_remove(GTK_CONTAINER(multi_vpaned->focused_pane),(GtkWidget*)prev);
336
337 if(prev == multi_vpaned->last_pane){
338 prevPrev = NULL;
339 multi_vpaned->last_pane = multi_vpaned->focused_pane;
340 }else{
341 prevPrev = (GtkPaned*)prev->child1;
342 g_object_ref(G_OBJECT(prevPrev));
343 gtk_container_remove(GTK_CONTAINER(prev),(GtkWidget*)prevPrev);
344 }
345
346 g_object_ref(G_OBJECT(multi_vpaned->focused_pane));
347 if(multi_vpaned->first_pane == multi_vpaned->focused_pane){
348 gtk_container_remove(GTK_CONTAINER(multi_vpaned->vbox),(GtkWidget*)multi_vpaned->focused_pane);
349 gtk_box_pack_end(GTK_BOX(multi_vpaned->vbox),(GtkWidget*)prev,TRUE,TRUE,0);
350 multi_vpaned->first_pane = prev;
351 }else{
352 next = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)multi_vpaned->focused_pane);
353 gtk_container_remove(GTK_CONTAINER(next),(GtkWidget*)multi_vpaned->focused_pane);
354 gtk_paned_pack1(GTK_PANED(next), (GtkWidget*)prev, FALSE,TRUE);
355 }
356 gtk_paned_pack1(GTK_PANED(prev),(GtkWidget*)multi_vpaned->focused_pane, FALSE,TRUE);
357 if(prevPrev)
358 gtk_paned_pack1(GTK_PANED(multi_vpaned->focused_pane),(GtkWidget*)prevPrev, FALSE,TRUE);
359
360 g_object_unref(G_OBJECT(prev));
361 if(prevPrev) g_object_unref(G_OBJECT(prevPrev));
362 g_object_unref(G_OBJECT(multi_vpaned->focused_pane));
363}
364
365
366void gtk_multi_vpaned_widget_move_down(GtkMultiVPaned * multi_vpaned)
367{
368 GtkWidget* upWidget, *downWidget;
369 GtkPaned * prev,*next, *nextNext;
370
371 if(multi_vpaned->first_pane == multi_vpaned->focused_pane) return;
372
373 //move VPane
374 next = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)multi_vpaned->focused_pane);
375 g_object_ref(G_OBJECT(next));
376
377 if(multi_vpaned->last_pane == multi_vpaned->focused_pane){
378 prev = NULL;
379 multi_vpaned->last_pane = next;
380 }else{
381 prev = (GtkPaned*)multi_vpaned->focused_pane->child1;
382 g_object_ref(G_OBJECT(prev));
383 gtk_container_remove(GTK_CONTAINER(multi_vpaned->focused_pane),(GtkWidget*)prev);
384 }
385
386 g_object_ref(G_OBJECT(multi_vpaned->focused_pane));
387 gtk_container_remove(GTK_CONTAINER(next),(GtkWidget*)multi_vpaned->focused_pane);
388
389 if(next == multi_vpaned->first_pane){
390 multi_vpaned->first_pane = multi_vpaned->focused_pane;
391 gtk_container_remove(GTK_CONTAINER(multi_vpaned->vbox),(GtkWidget*)next);
392 gtk_box_pack_end(GTK_BOX(multi_vpaned->vbox),(GtkWidget*)multi_vpaned->focused_pane,TRUE,TRUE,0);
393 }else{
394 nextNext = (GtkPaned*)gtk_widget_get_parent((GtkWidget*)next);
395 gtk_container_remove(GTK_CONTAINER(nextNext),(GtkWidget*)next);
396 gtk_paned_pack1(nextNext, (GtkWidget*)multi_vpaned->focused_pane, FALSE, TRUE);
397 }
398 gtk_paned_pack1(multi_vpaned->focused_pane,(GtkWidget*)next, FALSE,TRUE);
399 if(prev)
400 gtk_paned_pack1(next,(GtkWidget*)prev, FALSE,TRUE);
401
402 if(prev)g_object_unref(G_OBJECT(prev));
403 g_object_unref(G_OBJECT(next));
404 g_object_unref(G_OBJECT(multi_vpaned->focused_pane));
405}
406
bca085a1 407void gtk_multi_vpaned_set_scroll_value(GtkMultiVPaned * multi_vpaned, double value)
408{
409 gtk_adjustment_set_value(multi_vpaned->hadjust, value);
a43d67ba 410 //g_signal_stop_emission_by_name(G_OBJECT(multi_vpaned->hscrollbar), "value-changed");
bca085a1 411}
412
a43d67ba 413void gtk_multi_vpaned_scroll_value_changed(GtkAdjustment *adjust, gpointer multi_vpaned_arg)
daecc161 414{
58eecf4a 415 TimeWindow time_window;
416 TimeInterval *time_span;
daecc161 417 LttTime time;
418 GtkMultiVPaned * multi_vpaned = (GtkMultiVPaned*)multi_vpaned_arg;
a43d67ba 419 gdouble value = gtk_adjustment_get_value(adjust);
58eecf4a 420 gdouble upper, lower, ratio;
6ced96ef 421 Tab *tab = (Tab *)g_object_get_data(G_OBJECT(multi_vpaned), "Tab_Info");
501e4e70 422 LttvTracesetContext * tsc =
2d262115 423 LTTV_TRACESET_CONTEXT(tab->traceset_info->traceset_context);
58eecf4a 424
2d262115 425 time_window = tab->time_window;
58eecf4a 426
501e4e70 427 time_span = &tsc->time_span ;
58eecf4a 428 lower = multi_vpaned->hadjust->lower;
429 upper = multi_vpaned->hadjust->upper;
430 ratio = (value - lower) / (upper - lower);
431
7afc14aa 432 time = ltt_time_sub(time_span->end_time, time_span->start_time);
58eecf4a 433 time = ltt_time_mul(time, (float)ratio);
7afc14aa 434 time = ltt_time_add(time_span->start_time, time);
58eecf4a 435
436 time_window.start_time = time;
437
7afc14aa 438 time = ltt_time_sub(time_span->end_time, time);
58eecf4a 439 if(ltt_time_compare(time,time_window.time_width) < 0){
440 time_window.time_width = time;
441 }
2d262115 442 set_time_window(tab, &time_window);
daecc161 443}
444
445
446static void
447gtk_multi_vpaned_size_request (GtkWidget *widget,
448 GtkRequisition *requisition)
449{
450 GtkPaned *paned = GTK_PANED (widget);
451 GtkRequisition child_requisition;
452
453 requisition->width = 0;
454 requisition->height = 0;
455
456 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
457 {
458 gtk_widget_size_request (paned->child1, &child_requisition);
459
460 requisition->height = child_requisition.height;
461 requisition->width = child_requisition.width;
462 }
463
464 if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
465 {
466 gtk_widget_size_request (paned->child2, &child_requisition);
467
468 requisition->width = MAX (requisition->width, child_requisition.width);
469 requisition->height += child_requisition.height;
470 }
471
472 requisition->height += GTK_CONTAINER (paned)->border_width * 2;
473 requisition->width += GTK_CONTAINER (paned)->border_width * 2;
474
475 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
476 paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
477 {
478 gint handle_size;
479
480 gtk_widget_style_get (widget, "handle_size", &handle_size, NULL);
481 requisition->height += handle_size;
482 }
483
484}
485
486static void
487gtk_multi_vpaned_size_allocate (GtkWidget *widget,
488 GtkAllocation *allocation)
489{
490 GtkPaned *paned = GTK_PANED (widget);
491 gint border_width = GTK_CONTAINER (paned)->border_width;
492
493 widget->allocation = *allocation;
494
495 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
496 paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
497 {
498 GtkRequisition child1_requisition;
499 GtkRequisition child2_requisition;
500 GtkAllocation child1_allocation;
501 GtkAllocation child2_allocation;
502 gint handle_size;
503
504 gtk_widget_style_get (widget, "handle_size", &handle_size, NULL);
505
506 gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
507 gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
508
509 gtk_paned_compute_position (paned,
510 MAX (1, widget->allocation.height
511 - handle_size
512 - 2 * border_width),
513 child1_requisition.height,
514 child2_requisition.height);
515
516 paned->handle_pos.x = widget->allocation.x + border_width;
517 paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
518 paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
519 paned->handle_pos.height = handle_size;
520
521 if (GTK_WIDGET_REALIZED (widget))
522 {
523 if (GTK_WIDGET_MAPPED (widget))
524 gdk_window_show (paned->handle);
525 gdk_window_move_resize (paned->handle,
526 paned->handle_pos.x,
527 paned->handle_pos.y,
528 paned->handle_pos.width,
529 handle_size);
530 }
531
532 child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
533 child1_allocation.height = MAX (1, paned->child1_size);
534 child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
535 child1_allocation.y = widget->allocation.y + border_width;
536
537 child2_allocation.y = child1_allocation.y + paned->child1_size + paned->handle_pos.height;
538 child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
539
540 if (GTK_WIDGET_MAPPED (widget) &&
541 paned->child1->allocation.height < child1_allocation.height)
542 {
543 gtk_widget_size_allocate (paned->child2, &child2_allocation);
544 gtk_widget_size_allocate (paned->child1, &child1_allocation);
545 }
546 else
547 {
548 gtk_widget_size_allocate (paned->child1, &child1_allocation);
549 gtk_widget_size_allocate (paned->child2, &child2_allocation);
550 }
551 }
552 else
553 {
554 GtkAllocation child_allocation;
555
556 if (GTK_WIDGET_REALIZED (widget))
557 gdk_window_hide (paned->handle);
558
559 if (paned->child1)
560 gtk_widget_set_child_visible (paned->child1, TRUE);
561 if (paned->child2)
562 gtk_widget_set_child_visible (paned->child2, TRUE);
563
564 child_allocation.x = widget->allocation.x + border_width;
565 child_allocation.y = widget->allocation.y + border_width;
566 child_allocation.width = MAX (1, allocation->width - 2 * border_width);
567 child_allocation.height = MAX (1, allocation->height - 2 * border_width);
568
569 if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
570 gtk_widget_size_allocate (paned->child1, &child_allocation);
571 else if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
572 gtk_widget_size_allocate (paned->child2, &child_allocation);
573 }
574}
575
This page took 0.050447 seconds and 4 git commands to generate.