]> Pileus Git - ~andy/gtk/blob - gtk/gtkvpaned.c
ru.po: Updated Russian translation from Russian team <gnome-cyr@gnome.org>.
[~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
30 static void     gtk_vpaned_class_init     (GtkVPanedClass *klass);
31 static void     gtk_vpaned_init           (GtkVPaned      *vpaned);
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 static gpointer parent_class;
38
39 GType
40 gtk_vpaned_get_type (void)
41 {
42   static GType vpaned_type = 0;
43
44   if (!vpaned_type)
45     {
46       static const GTypeInfo vpaned_info =
47       {
48         sizeof (GtkVPanedClass),
49         NULL,           /* base_init */
50         NULL,           /* base_finalize */
51         (GClassInitFunc) gtk_vpaned_class_init,
52         NULL,           /* class_finalize */
53         NULL,           /* class_data */
54         sizeof (GtkVPaned),
55         0,              /* n_preallocs */
56         (GInstanceInitFunc) gtk_vpaned_init,
57       };
58
59       vpaned_type = g_type_register_static (GTK_TYPE_PANED, "GtkVPaned",
60                                             &vpaned_info, 0);
61     }
62
63   return vpaned_type;
64 }
65
66 static void
67 gtk_vpaned_class_init (GtkVPanedClass *class)
68 {
69   GtkWidgetClass *widget_class;
70
71   parent_class = g_type_class_peek_parent (class);
72   
73   widget_class = (GtkWidgetClass *) class;
74
75   widget_class->size_request = gtk_vpaned_size_request;
76   widget_class->size_allocate = gtk_vpaned_size_allocate;
77 }
78
79 static void
80 gtk_vpaned_init (GtkVPaned *vpaned)
81 {
82   GtkPaned *paned;
83
84   g_return_if_fail (GTK_IS_PANED (vpaned));
85
86   paned = GTK_PANED (vpaned);
87
88   paned->cursor_type = GDK_SB_V_DOUBLE_ARROW;
89   paned->orientation = GTK_ORIENTATION_HORIZONTAL;
90 }
91
92 GtkWidget *
93 gtk_vpaned_new (void)
94 {
95   GtkVPaned *vpaned;
96
97   vpaned = g_object_new (GTK_TYPE_VPANED, NULL);
98
99   return GTK_WIDGET (vpaned);
100 }
101
102 static void
103 gtk_vpaned_size_request (GtkWidget      *widget,
104                          GtkRequisition *requisition)
105 {
106   GtkPaned *paned = GTK_PANED (widget);
107   GtkRequisition child_requisition;
108
109   requisition->width = 0;
110   requisition->height = 0;
111
112   if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
113     {
114       gtk_widget_size_request (paned->child1, &child_requisition);
115
116       requisition->height = child_requisition.height;
117       requisition->width = child_requisition.width;
118     }
119
120   if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
121     {
122       gtk_widget_size_request (paned->child2, &child_requisition);
123
124       requisition->width = MAX (requisition->width, child_requisition.width);
125       requisition->height += child_requisition.height;
126     }
127
128   requisition->height += GTK_CONTAINER (paned)->border_width * 2;
129   requisition->width += GTK_CONTAINER (paned)->border_width * 2;
130   
131   if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
132       paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
133     {
134       gint handle_size;
135
136       gtk_widget_style_get (widget, "handle_size", &handle_size, NULL);
137       requisition->height += handle_size;
138     }
139 }
140
141 static void
142 gtk_vpaned_size_allocate (GtkWidget     *widget,
143                           GtkAllocation *allocation)
144 {
145   GtkPaned *paned = GTK_PANED (widget);
146   gint border_width = GTK_CONTAINER (paned)->border_width;
147
148   widget->allocation = *allocation;
149
150   if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
151       paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
152     {
153       GtkRequisition child1_requisition;
154       GtkRequisition child2_requisition;
155       GtkAllocation child1_allocation;
156       GtkAllocation child2_allocation;
157       gint handle_size;
158       
159       gtk_widget_style_get (widget, "handle_size", &handle_size, NULL);
160
161       gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
162       gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
163     
164       gtk_paned_compute_position (paned,
165                                   MAX (1, widget->allocation.height
166                                        - handle_size
167                                        - 2 * border_width),
168                                   child1_requisition.height,
169                                   child2_requisition.height);
170
171       paned->handle_pos.x = widget->allocation.x + border_width;
172       paned->handle_pos.y = widget->allocation.y + paned->child1_size + border_width;
173       paned->handle_pos.width = MAX (1, (gint) widget->allocation.width - 2 * border_width);
174       paned->handle_pos.height = handle_size;
175       
176       if (GTK_WIDGET_REALIZED (widget))
177         {
178           if (GTK_WIDGET_MAPPED (widget))
179             gdk_window_show (paned->handle);
180           gdk_window_move_resize (paned->handle,
181                                   paned->handle_pos.x,
182                                   paned->handle_pos.y,
183                                   paned->handle_pos.width,
184                                   handle_size);
185         }
186
187       child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2);
188       child1_allocation.height = MAX (1, paned->child1_size);
189       child1_allocation.x = child2_allocation.x = widget->allocation.x + border_width;
190       child1_allocation.y = widget->allocation.y + border_width;
191       
192       child2_allocation.y = child1_allocation.y + paned->child1_size + paned->handle_pos.height;
193       child2_allocation.height = MAX (1, widget->allocation.y + widget->allocation.height - child2_allocation.y - border_width);
194       
195       /* Now allocate the childen, making sure, when resizing not to
196        * overlap the windows
197        */
198       if (GTK_WIDGET_MAPPED (widget) &&
199           paned->child1->allocation.height < child1_allocation.height)
200         {
201           gtk_widget_size_allocate (paned->child2, &child2_allocation);
202           gtk_widget_size_allocate (paned->child1, &child1_allocation);
203         }
204       else
205         {
206           gtk_widget_size_allocate (paned->child1, &child1_allocation);
207           gtk_widget_size_allocate (paned->child2, &child2_allocation);
208         }
209     }
210   else
211     {
212       GtkAllocation child_allocation;
213
214       if (GTK_WIDGET_REALIZED (widget))      
215         gdk_window_hide (paned->handle);
216
217       if (paned->child1)
218         gtk_widget_set_child_visible (paned->child1, TRUE);
219       if (paned->child2)
220         gtk_widget_set_child_visible (paned->child2, TRUE);
221
222       child_allocation.x = widget->allocation.x + border_width;
223       child_allocation.y = widget->allocation.y + border_width;
224       child_allocation.width = MAX (1, allocation->width - 2 * border_width);
225       child_allocation.height = MAX (1, allocation->height - 2 * border_width);
226       
227       if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
228         gtk_widget_size_allocate (paned->child1, &child_allocation);
229       else if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
230         gtk_widget_size_allocate (paned->child2, &child_allocation);
231     }
232 }