]> Pileus Git - ~andy/gtk/blob - gtk/gtkvpaned.c
Updated Bulgarian translation by Alexander Shopov <ash@contact.bg>
[~andy/gtk] / gtk / gtkvpaned.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 #include <config.h>
28 #include "gtkvpaned.h"
29 #include "gtkintl.h"
30 #include "gtkalias.h"
31
32 static void     gtk_vpaned_size_request   (GtkWidget      *widget,
33                                            GtkRequisition *requisition);
34 static void     gtk_vpaned_size_allocate  (GtkWidget      *widget,
35                                            GtkAllocation  *allocation);
36
37 G_DEFINE_TYPE (GtkVPaned, gtk_vpaned, GTK_TYPE_PANED)
38
39 static void
40 gtk_vpaned_class_init (GtkVPanedClass *class)
41 {
42   GtkWidgetClass *widget_class;
43
44   widget_class = (GtkWidgetClass *) class;
45
46   widget_class->size_request = gtk_vpaned_size_request;
47   widget_class->size_allocate = gtk_vpaned_size_allocate;
48 }
49
50 static void
51 gtk_vpaned_init (GtkVPaned *vpaned)
52 {
53   GtkPaned *paned;
54
55   g_return_if_fail (GTK_IS_PANED (vpaned));
56
57   paned = GTK_PANED (vpaned);
58
59   paned->cursor_type = GDK_SB_V_DOUBLE_ARROW;
60   paned->orientation = GTK_ORIENTATION_HORIZONTAL;
61 }
62
63 GtkWidget *
64 gtk_vpaned_new (void)
65 {
66   GtkVPaned *vpaned;
67
68   vpaned = g_object_new (GTK_TYPE_VPANED, NULL);
69
70   return GTK_WIDGET (vpaned);
71 }
72
73 static void
74 gtk_vpaned_size_request (GtkWidget      *widget,
75                          GtkRequisition *requisition)
76 {
77   GtkPaned *paned = GTK_PANED (widget);
78   GtkRequisition child_requisition;
79
80   requisition->width = 0;
81   requisition->height = 0;
82
83   if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
84     {
85       gtk_widget_size_request (paned->child1, &child_requisition);
86
87       requisition->height = child_requisition.height;
88       requisition->width = child_requisition.width;
89     }
90
91   if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
92     {
93       gtk_widget_size_request (paned->child2, &child_requisition);
94
95       requisition->width = MAX (requisition->width, child_requisition.width);
96       requisition->height += child_requisition.height;
97     }
98
99   requisition->height += GTK_CONTAINER (paned)->border_width * 2;
100   requisition->width += GTK_CONTAINER (paned)->border_width * 2;
101   
102   if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
103       paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
104     {
105       gint handle_size;
106
107       gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
108       requisition->height += handle_size;
109     }
110 }
111
112 static void
113 gtk_vpaned_size_allocate (GtkWidget     *widget,
114                           GtkAllocation *allocation)
115 {
116   GtkPaned *paned = GTK_PANED (widget);
117   gint border_width = GTK_CONTAINER (paned)->border_width;
118
119   widget->allocation = *allocation;
120
121   if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
122       paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
123     {
124       GtkRequisition child1_requisition;
125       GtkRequisition child2_requisition;
126       GtkAllocation child1_allocation;
127       GtkAllocation child2_allocation;
128       gint handle_size;
129       
130       gtk_widget_style_get (widget, "handle-size", &handle_size, NULL);
131
132       gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
133       gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
134     
135       gtk_paned_compute_position (paned,
136                                   MAX (1, widget->allocation.height
137                                        - handle_size
138                                        - 2 * border_width),
139                                   child1_requisition.height,
140                                   child2_requisition.height);
141
142       paned->handle_pos.x = widget->allocation.x + border_width;
143       paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
144       paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
145       paned->handle_pos.height = handle_size;
146       
147       if (GTK_WIDGET_REALIZED (widget))
148         {
149           if (GTK_WIDGET_MAPPED (widget))
150             gdk_window_show (paned->handle);
151           gdk_window_move_resize (paned->handle,
152                                   paned->handle_pos.x,
153                                   paned->handle_pos.y,
154                                   paned->handle_pos.width,
155                                   handle_size);
156         }
157
158       child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
159       child1_allocation.height = MAX (1, paned->child1_size);
160       child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
161       child1_allocation.y = widget->allocation.y + border_width;
162       
163       child2_allocation.y = child1_allocation.y + paned->child1_size + paned->handle_pos.height;
164       child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
165       
166       /* Now allocate the childen, making sure, when resizing not to
167        * overlap the windows
168        */
169       if (GTK_WIDGET_MAPPED (widget) &&
170           paned->child1->allocation.height < child1_allocation.height)
171         {
172           gtk_widget_size_allocate (paned->child2, &child2_allocation);
173           gtk_widget_size_allocate (paned->child1, &child1_allocation);
174         }
175       else
176         {
177           gtk_widget_size_allocate (paned->child1, &child1_allocation);
178           gtk_widget_size_allocate (paned->child2, &child2_allocation);
179         }
180     }
181   else
182     {
183       GtkAllocation child_allocation;
184
185       if (GTK_WIDGET_REALIZED (widget))      
186         gdk_window_hide (paned->handle);
187
188       if (paned->child1)
189         gtk_widget_set_child_visible (paned->child1, TRUE);
190       if (paned->child2)
191         gtk_widget_set_child_visible (paned->child2, TRUE);
192
193       child_allocation.x = widget->allocation.x + border_width;
194       child_allocation.y = widget->allocation.y + border_width;
195       child_allocation.width = MAX (1, allocation->width - 2 * border_width);
196       child_allocation.height = MAX (1, allocation->height - 2 * border_width);
197       
198       if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
199         gtk_widget_size_allocate (paned->child1, &child_allocation);
200       else if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
201         gtk_widget_size_allocate (paned->child2, &child_allocation);
202     }
203 }
204
205 #define __GTK_VPANED_C__
206 #include "gtkaliasdef.c"