]> Pileus Git - ~andy/gtk/blob - gtk/gtkhpaned.c
Fix ZWJ => ZWN typo. (#83092, Tino Meinen)
[~andy/gtk] / gtk / gtkhpaned.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 "gtkhpaned.h"
28
29 static void     gtk_hpaned_class_init     (GtkHPanedClass *klass);
30 static void     gtk_hpaned_init           (GtkHPaned      *hpaned);
31 static void     gtk_hpaned_size_request   (GtkWidget      *widget,
32                                            GtkRequisition *requisition);
33 static void     gtk_hpaned_size_allocate  (GtkWidget      *widget,
34                                            GtkAllocation  *allocation);
35
36 static gpointer parent_class;
37
38 GtkType
39 gtk_hpaned_get_type (void)
40 {
41   static GtkType hpaned_type = 0;
42
43   if (!hpaned_type)
44     {
45       static const GtkTypeInfo hpaned_info =
46       {
47         "GtkHPaned",
48         sizeof (GtkHPaned),
49         sizeof (GtkHPanedClass),
50         (GtkClassInitFunc) gtk_hpaned_class_init,
51         (GtkObjectInitFunc) gtk_hpaned_init,
52         /* reserved_1 */ NULL,
53         /* reserved_2 */ NULL,
54         (GtkClassInitFunc) NULL,
55       };
56
57       hpaned_type = gtk_type_unique (GTK_TYPE_PANED, &hpaned_info);
58     }
59
60   return hpaned_type;
61 }
62
63 static void
64 gtk_hpaned_class_init (GtkHPanedClass *class)
65 {
66   GtkWidgetClass *widget_class;
67
68   parent_class = gtk_type_class (GTK_TYPE_PANED);
69   
70   widget_class = (GtkWidgetClass *) class;
71
72   widget_class->size_request = gtk_hpaned_size_request;
73   widget_class->size_allocate = gtk_hpaned_size_allocate;
74 }
75
76 static void
77 gtk_hpaned_init (GtkHPaned *hpaned)
78 {
79   GtkPaned *paned;
80
81   g_return_if_fail (GTK_IS_PANED (hpaned));
82
83   paned = GTK_PANED (hpaned);
84   
85   paned->cursor_type = GDK_SB_H_DOUBLE_ARROW;
86   paned->orientation = GTK_ORIENTATION_VERTICAL;
87 }
88
89 GtkWidget *
90 gtk_hpaned_new (void)
91 {
92   GtkHPaned *hpaned;
93
94   hpaned = gtk_type_new (GTK_TYPE_HPANED);
95
96   return GTK_WIDGET (hpaned);
97 }
98
99 static void
100 gtk_hpaned_size_request (GtkWidget      *widget,
101                          GtkRequisition *requisition)
102 {
103   GtkPaned *paned = GTK_PANED (widget);
104   GtkRequisition child_requisition;
105
106   requisition->width = 0;
107   requisition->height = 0;
108
109   if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
110     {
111       gtk_widget_size_request (paned->child1, &child_requisition);
112
113       requisition->height = child_requisition.height;
114       requisition->width = child_requisition.width;
115     }
116
117   if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
118     {
119       gtk_widget_size_request (paned->child2, &child_requisition);
120
121       requisition->height = MAX(requisition->height, child_requisition.height);
122       requisition->width += child_requisition.width;
123     }
124
125   requisition->width += GTK_CONTAINER (paned)->border_width * 2;
126   requisition->height += GTK_CONTAINER (paned)->border_width * 2;
127
128   if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
129       paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
130     {
131       gint handle_size;
132       
133       gtk_widget_style_get (widget, "handle_size", &handle_size, NULL);
134       requisition->width += handle_size;
135     }
136 }
137
138 static void
139 gtk_hpaned_size_allocate (GtkWidget     *widget,
140                           GtkAllocation *allocation)
141 {
142   GtkPaned *paned = GTK_PANED (widget);
143   gint border_width = GTK_CONTAINER (paned)->border_width;
144
145   widget->allocation = *allocation;
146
147   if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) &&
148       paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
149     {
150       GtkAllocation child1_allocation;
151       GtkAllocation child2_allocation;
152       GtkRequisition child1_requisition;
153       GtkRequisition child2_requisition;
154       gint handle_size;
155       
156       gtk_widget_style_get (widget, "handle_size", &handle_size, NULL);
157
158       gtk_widget_get_child_requisition (paned->child1, &child1_requisition);
159       gtk_widget_get_child_requisition (paned->child2, &child2_requisition);
160       
161       gtk_paned_compute_position (paned,
162                                   MAX (1, widget->allocation.width
163                                        - handle_size
164                                        - 2 * border_width),
165                                   child1_requisition.width,
166                                   child2_requisition.width);
167       
168       paned->handle_pos.x = widget->allocation.x + paned->child1_size + border_width;
169       paned->handle_pos.y = widget->allocation.y + border_width;
170       paned->handle_pos.width = handle_size;
171       paned->handle_pos.height = MAX (1, widget->allocation.height - 2 * border_width);
172       
173       if (GTK_WIDGET_REALIZED (widget))
174         {
175           if (GTK_WIDGET_MAPPED (widget))
176             gdk_window_show (paned->handle);
177           gdk_window_move_resize (paned->handle,
178                                   paned->handle_pos.x,
179                                   paned->handle_pos.y,
180                                   handle_size,
181                                   paned->handle_pos.height);
182         }
183       
184       child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2);
185       child1_allocation.width = paned->child1_size;
186       child1_allocation.x = widget->allocation.x + border_width;
187       child1_allocation.y = child2_allocation.y = widget->allocation.y + border_width;
188       
189       child2_allocation.x = child1_allocation.x + child1_allocation.width +  paned->handle_pos.width;
190       child2_allocation.width = MAX (1, widget->allocation.x + widget->allocation.width - child2_allocation.x - border_width);
191       
192       /* Now allocate the childen, making sure, when resizing not to
193        * overlap the windows
194        */
195       if (GTK_WIDGET_MAPPED (widget) &&
196           paned->child1->allocation.width < child1_allocation.width)
197         {
198           gtk_widget_size_allocate (paned->child2, &child2_allocation);
199           gtk_widget_size_allocate (paned->child1, &child1_allocation);
200         }
201       else
202         {
203           gtk_widget_size_allocate (paned->child1, &child1_allocation);
204           gtk_widget_size_allocate (paned->child2, &child2_allocation);
205         }
206     }
207   else
208     {
209       GtkAllocation child_allocation;
210
211       if (GTK_WIDGET_REALIZED (widget))      
212         gdk_window_hide (paned->handle);
213           
214       child_allocation.x = widget->allocation.x + border_width;
215       child_allocation.y = widget->allocation.y + border_width;
216       child_allocation.width = MAX (1, allocation->width - 2 * border_width);
217       child_allocation.height = MAX (1, allocation->height - 2 * border_width);
218       
219       if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1))
220         gtk_widget_size_allocate (paned->child1, &child_allocation);
221       else if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2))
222         gtk_widget_size_allocate (paned->child2, &child_allocation);
223     }
224 }