]> Pileus Git - ~andy/gtk/blob - gtk/gtkframe.c
Mass api change from GtkExtendedLayout --> GtkSizeRequest
[~andy/gtk] / gtk / gtkframe.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 <string.h>
29 #include "gtkframe.h"
30 #include "gtklabel.h"
31 #include "gtkprivate.h"
32 #include "gtkintl.h"
33 #include "gtkbuildable.h"
34 #include "gtksizerequest.h"
35 #include "gtkalias.h"
36
37 #define LABEL_PAD 1
38 #define LABEL_SIDE_PAD 2
39
40 enum {
41   PROP_0,
42   PROP_LABEL,
43   PROP_LABEL_XALIGN,
44   PROP_LABEL_YALIGN,
45   PROP_SHADOW,
46   PROP_SHADOW_TYPE,
47   PROP_LABEL_WIDGET
48 };
49
50 static void gtk_frame_set_property (GObject      *object,
51                                     guint         param_id,
52                                     const GValue *value,
53                                     GParamSpec   *pspec);
54 static void gtk_frame_get_property (GObject     *object,
55                                     guint        param_id,
56                                     GValue      *value,
57                                     GParamSpec  *pspec);
58 static void gtk_frame_paint         (GtkWidget      *widget,
59                                      GdkRectangle   *area);
60 static gint gtk_frame_expose        (GtkWidget      *widget,
61                                      GdkEventExpose *event);
62 static void gtk_frame_size_allocate (GtkWidget      *widget,
63                                      GtkAllocation  *allocation);
64 static void gtk_frame_remove        (GtkContainer   *container,
65                                      GtkWidget      *child);
66 static void gtk_frame_forall        (GtkContainer   *container,
67                                      gboolean        include_internals,
68                                      GtkCallback     callback,
69                                      gpointer        callback_data);
70
71 static void gtk_frame_compute_child_allocation      (GtkFrame      *frame,
72                                                      GtkAllocation *child_allocation);
73 static void gtk_frame_real_compute_child_allocation (GtkFrame      *frame,
74                                                      GtkAllocation *child_allocation);
75
76 /* GtkBuildable */
77 static void gtk_frame_buildable_init                (GtkBuildableIface *iface);
78 static void gtk_frame_buildable_add_child           (GtkBuildable *buildable,
79                                                      GtkBuilder   *builder,
80                                                      GObject      *child,
81                                                      const gchar  *type);
82
83 static void gtk_frame_size_request_init             (GtkSizeRequestIface *iface);
84 static void gtk_frame_get_width                     (GtkSizeRequest      *widget,
85                                                      gint                *minimum_size,
86                                                      gint                *natural_size);
87 static void gtk_frame_get_height                    (GtkSizeRequest      *widget,
88                                                      gint                *minimum_size,
89                                                      gint                *natural_size);
90
91 G_DEFINE_TYPE_WITH_CODE (GtkFrame, gtk_frame, GTK_TYPE_BIN,
92                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
93                                                 gtk_frame_buildable_init)
94                          G_IMPLEMENT_INTERFACE (GTK_TYPE_SIZE_REQUEST,
95                                                 gtk_frame_size_request_init))
96
97 static void
98 gtk_frame_class_init (GtkFrameClass *class)
99 {
100   GObjectClass *gobject_class;
101   GtkWidgetClass *widget_class;
102   GtkContainerClass *container_class;
103
104   gobject_class = (GObjectClass*) class;
105   widget_class = GTK_WIDGET_CLASS (class);
106   container_class = GTK_CONTAINER_CLASS (class);
107
108   gobject_class->set_property = gtk_frame_set_property;
109   gobject_class->get_property = gtk_frame_get_property;
110
111   g_object_class_install_property (gobject_class,
112                                    PROP_LABEL,
113                                    g_param_spec_string ("label",
114                                                         P_("Label"),
115                                                         P_("Text of the frame's label"),
116                                                         NULL,
117                                                         GTK_PARAM_READABLE |
118                                                         GTK_PARAM_WRITABLE));
119   g_object_class_install_property (gobject_class,
120                                    PROP_LABEL_XALIGN,
121                                    g_param_spec_float ("label-xalign",
122                                                        P_("Label xalign"),
123                                                        P_("The horizontal alignment of the label"),
124                                                        0.0,
125                                                        1.0,
126                                                        0.0,
127                                                        GTK_PARAM_READWRITE));
128   g_object_class_install_property (gobject_class,
129                                    PROP_LABEL_YALIGN,
130                                    g_param_spec_float ("label-yalign",
131                                                        P_("Label yalign"),
132                                                        P_("The vertical alignment of the label"),
133                                                        0.0,
134                                                        1.0,
135                                                        0.5,
136                                                        GTK_PARAM_READWRITE));
137   g_object_class_install_property (gobject_class,
138                                    PROP_SHADOW,
139                                    g_param_spec_enum ("shadow", NULL,
140                                                       P_("Deprecated property, use shadow_type instead"),
141                                                       GTK_TYPE_SHADOW_TYPE,
142                                                       GTK_SHADOW_ETCHED_IN,
143                                                       GTK_PARAM_READWRITE));
144   g_object_class_install_property (gobject_class,
145                                    PROP_SHADOW_TYPE,
146                                    g_param_spec_enum ("shadow-type",
147                                                       P_("Frame shadow"),
148                                                       P_("Appearance of the frame border"),
149                                                       GTK_TYPE_SHADOW_TYPE,
150                                                       GTK_SHADOW_ETCHED_IN,
151                                                       GTK_PARAM_READWRITE));
152
153   g_object_class_install_property (gobject_class,
154                                    PROP_LABEL_WIDGET,
155                                    g_param_spec_object ("label-widget",
156                                                         P_("Label widget"),
157                                                         P_("A widget to display in place of the usual frame label"),
158                                                         GTK_TYPE_WIDGET,
159                                                         GTK_PARAM_READWRITE));
160   
161   widget_class->expose_event = gtk_frame_expose;
162   widget_class->size_allocate = gtk_frame_size_allocate;
163
164   container_class->remove = gtk_frame_remove;
165   container_class->forall = gtk_frame_forall;
166
167   class->compute_child_allocation = gtk_frame_real_compute_child_allocation;
168 }
169
170 static void
171 gtk_frame_buildable_init (GtkBuildableIface *iface)
172 {
173   iface->add_child = gtk_frame_buildable_add_child;
174 }
175
176 static void
177 gtk_frame_buildable_add_child (GtkBuildable *buildable,
178                                GtkBuilder   *builder,
179                                GObject      *child,
180                                const gchar  *type)
181 {
182   if (type && strcmp (type, "label") == 0)
183     gtk_frame_set_label_widget (GTK_FRAME (buildable), GTK_WIDGET (child));
184   else if (!type)
185     gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
186   else
187     GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_FRAME (buildable), type);
188 }
189
190 static void
191 gtk_frame_init (GtkFrame *frame)
192 {
193   frame->label_widget = NULL;
194   frame->shadow_type = GTK_SHADOW_ETCHED_IN;
195   frame->label_xalign = 0.0;
196   frame->label_yalign = 0.5;
197 }
198
199 static void 
200 gtk_frame_set_property (GObject         *object,
201                         guint            prop_id,
202                         const GValue    *value,
203                         GParamSpec      *pspec)
204 {
205   GtkFrame *frame;
206
207   frame = GTK_FRAME (object);
208
209   switch (prop_id)
210     {
211     case PROP_LABEL:
212       gtk_frame_set_label (frame, g_value_get_string (value));
213       break;
214     case PROP_LABEL_XALIGN:
215       gtk_frame_set_label_align (frame, g_value_get_float (value), 
216                                  frame->label_yalign);
217       break;
218     case PROP_LABEL_YALIGN:
219       gtk_frame_set_label_align (frame, frame->label_xalign, 
220                                  g_value_get_float (value));
221       break;
222     case PROP_SHADOW:
223     case PROP_SHADOW_TYPE:
224       gtk_frame_set_shadow_type (frame, g_value_get_enum (value));
225       break;
226     case PROP_LABEL_WIDGET:
227       gtk_frame_set_label_widget (frame, g_value_get_object (value));
228       break;
229     default:      
230       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
231       break;
232     }
233 }
234
235 static void 
236 gtk_frame_get_property (GObject         *object,
237                         guint            prop_id,
238                         GValue          *value,
239                         GParamSpec      *pspec)
240 {
241   GtkFrame *frame;
242
243   frame = GTK_FRAME (object);
244
245   switch (prop_id)
246     {
247     case PROP_LABEL:
248       g_value_set_string (value, gtk_frame_get_label (frame));
249       break;
250     case PROP_LABEL_XALIGN:
251       g_value_set_float (value, frame->label_xalign);
252       break;
253     case PROP_LABEL_YALIGN:
254       g_value_set_float (value, frame->label_yalign);
255       break;
256     case PROP_SHADOW:
257     case PROP_SHADOW_TYPE:
258       g_value_set_enum (value, frame->shadow_type);
259       break;
260     case PROP_LABEL_WIDGET:
261       g_value_set_object (value,
262                           frame->label_widget ?
263                           G_OBJECT (frame->label_widget) : NULL);
264       break;
265     default:
266       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
267       break;
268     }
269 }
270
271 /**
272  * gtk_frame_new:
273  * @label: the text to use as the label of the frame
274  * 
275  * Creates a new #GtkFrame, with optional label @label.
276  * If @label is %NULL, the label is omitted.
277  * 
278  * Return value: a new #GtkFrame widget
279  **/
280 GtkWidget*
281 gtk_frame_new (const gchar *label)
282 {
283   return g_object_new (GTK_TYPE_FRAME, "label", label, NULL);
284 }
285
286 static void
287 gtk_frame_remove (GtkContainer *container,
288                   GtkWidget    *child)
289 {
290   GtkFrame *frame = GTK_FRAME (container);
291
292   if (frame->label_widget == child)
293     gtk_frame_set_label_widget (frame, NULL);
294   else
295     GTK_CONTAINER_CLASS (gtk_frame_parent_class)->remove (container, child);
296 }
297
298 static void
299 gtk_frame_forall (GtkContainer *container,
300                   gboolean      include_internals,
301                   GtkCallback   callback,
302                   gpointer      callback_data)
303 {
304   GtkBin *bin = GTK_BIN (container);
305   GtkFrame *frame = GTK_FRAME (container);
306
307   if (bin->child)
308     (* callback) (bin->child, callback_data);
309
310   if (frame->label_widget)
311     (* callback) (frame->label_widget, callback_data);
312 }
313
314 /**
315  * gtk_frame_set_label:
316  * @frame: a #GtkFrame
317  * @label: (allow-none): the text to use as the label of the frame
318  *
319  * Sets the text of the label. If @label is %NULL,
320  * the current label is removed.
321  **/
322 void
323 gtk_frame_set_label (GtkFrame *frame,
324                      const gchar *label)
325 {
326   g_return_if_fail (GTK_IS_FRAME (frame));
327
328   if (!label)
329     {
330       gtk_frame_set_label_widget (frame, NULL);
331     }
332   else
333     {
334       GtkWidget *child = gtk_label_new (label);
335       gtk_widget_show (child);
336
337       gtk_frame_set_label_widget (frame, child);
338     }
339 }
340
341 /**
342  * gtk_frame_get_label:
343  * @frame: a #GtkFrame
344  * 
345  * If the frame's label widget is a #GtkLabel, returns the
346  * text in the label widget. (The frame will have a #GtkLabel
347  * for the label widget if a non-%NULL argument was passed
348  * to gtk_frame_new().)
349  * 
350  * Return value: the text in the label, or %NULL if there
351  *               was no label widget or the lable widget was not
352  *               a #GtkLabel. This string is owned by GTK+ and
353  *               must not be modified or freed.
354  **/
355 G_CONST_RETURN gchar *
356 gtk_frame_get_label (GtkFrame *frame)
357 {
358   g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
359
360   if (GTK_IS_LABEL (frame->label_widget))
361     return gtk_label_get_text (GTK_LABEL (frame->label_widget));
362   else
363     return NULL;
364 }
365
366 /**
367  * gtk_frame_set_label_widget:
368  * @frame: a #GtkFrame
369  * @label_widget: the new label widget
370  * 
371  * Sets the label widget for the frame. This is the widget that
372  * will appear embedded in the top edge of the frame as a
373  * title.
374  **/
375 void
376 gtk_frame_set_label_widget (GtkFrame  *frame,
377                             GtkWidget *label_widget)
378 {
379   gboolean need_resize = FALSE;
380   
381   g_return_if_fail (GTK_IS_FRAME (frame));
382   g_return_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget));
383   g_return_if_fail (label_widget == NULL || label_widget->parent == NULL);
384   
385   if (frame->label_widget == label_widget)
386     return;
387   
388   if (frame->label_widget)
389     {
390       need_resize = gtk_widget_get_visible (frame->label_widget);
391       gtk_widget_unparent (frame->label_widget);
392     }
393
394   frame->label_widget = label_widget;
395     
396   if (label_widget)
397     {
398       frame->label_widget = label_widget;
399       gtk_widget_set_parent (label_widget, GTK_WIDGET (frame));
400       need_resize |= gtk_widget_get_visible (label_widget);
401     }
402   
403   if (gtk_widget_get_visible (GTK_WIDGET (frame)) && need_resize)
404     gtk_widget_queue_resize (GTK_WIDGET (frame));
405
406   g_object_freeze_notify (G_OBJECT (frame));
407   g_object_notify (G_OBJECT (frame), "label-widget");
408   g_object_notify (G_OBJECT (frame), "label");
409   g_object_thaw_notify (G_OBJECT (frame));
410 }
411
412 /**
413  * gtk_frame_get_label_widget:
414  * @frame: a #GtkFrame
415  *
416  * Retrieves the label widget for the frame. See
417  * gtk_frame_set_label_widget().
418  *
419  * Return value: the label widget, or %NULL if there is none.
420  **/
421 GtkWidget *
422 gtk_frame_get_label_widget (GtkFrame *frame)
423 {
424   g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
425
426   return frame->label_widget;
427 }
428
429 /**
430  * gtk_frame_set_label_align:
431  * @frame: a #GtkFrame
432  * @xalign: The position of the label along the top edge
433  *   of the widget. A value of 0.0 represents left alignment;
434  *   1.0 represents right alignment.
435  * @yalign: The y alignment of the label. A value of 0.0 aligns under 
436  *   the frame; 1.0 aligns above the frame. If the values are exactly
437  *   0.0 or 1.0 the gap in the frame won't be painted because the label
438  *   will be completely above or below the frame.
439  * 
440  * Sets the alignment of the frame widget's label. The
441  * default values for a newly created frame are 0.0 and 0.5.
442  **/
443 void
444 gtk_frame_set_label_align (GtkFrame *frame,
445                            gfloat    xalign,
446                            gfloat    yalign)
447 {
448   g_return_if_fail (GTK_IS_FRAME (frame));
449
450   xalign = CLAMP (xalign, 0.0, 1.0);
451   yalign = CLAMP (yalign, 0.0, 1.0);
452
453   g_object_freeze_notify (G_OBJECT (frame));
454   if (xalign != frame->label_xalign)
455     {
456       frame->label_xalign = xalign;
457       g_object_notify (G_OBJECT (frame), "label-xalign");
458     }
459
460   if (yalign != frame->label_yalign)
461     {
462       frame->label_yalign = yalign;
463       g_object_notify (G_OBJECT (frame), "label-yalign");
464     }
465
466   g_object_thaw_notify (G_OBJECT (frame));
467   gtk_widget_queue_resize (GTK_WIDGET (frame));
468 }
469
470 /**
471  * gtk_frame_get_label_align:
472  * @frame: a #GtkFrame
473  * @xalign: (allow-none): location to store X alignment of frame's label, or %NULL
474  * @yalign: (allow-none): location to store X alignment of frame's label, or %NULL
475  * 
476  * Retrieves the X and Y alignment of the frame's label. See
477  * gtk_frame_set_label_align().
478  **/
479 void
480 gtk_frame_get_label_align (GtkFrame *frame,
481                            gfloat   *xalign,
482                            gfloat   *yalign)
483 {
484   g_return_if_fail (GTK_IS_FRAME (frame));
485
486   if (xalign)
487     *xalign = frame->label_xalign;
488   if (yalign)
489     *yalign = frame->label_yalign;
490 }
491
492 /**
493  * gtk_frame_set_shadow_type:
494  * @frame: a #GtkFrame
495  * @type: the new #GtkShadowType
496  * 
497  * Sets the shadow type for @frame.
498  **/
499 void
500 gtk_frame_set_shadow_type (GtkFrame      *frame,
501                            GtkShadowType  type)
502 {
503   GtkWidget *widget;
504
505   g_return_if_fail (GTK_IS_FRAME (frame));
506
507   if ((GtkShadowType) frame->shadow_type != type)
508     {
509       widget = GTK_WIDGET (frame);
510       frame->shadow_type = type;
511       g_object_notify (G_OBJECT (frame), "shadow-type");
512
513       if (gtk_widget_is_drawable (widget))
514         {
515           gtk_widget_queue_draw (widget);
516         }
517       
518       gtk_widget_queue_resize (widget);
519     }
520 }
521
522 /**
523  * gtk_frame_get_shadow_type:
524  * @frame: a #GtkFrame
525  *
526  * Retrieves the shadow type of the frame. See
527  * gtk_frame_set_shadow_type().
528  *
529  * Return value: the current shadow type of the frame.
530  **/
531 GtkShadowType
532 gtk_frame_get_shadow_type (GtkFrame *frame)
533 {
534   g_return_val_if_fail (GTK_IS_FRAME (frame), GTK_SHADOW_ETCHED_IN);
535
536   return frame->shadow_type;
537 }
538
539 static void
540 gtk_frame_paint (GtkWidget    *widget,
541                  GdkRectangle *area)
542 {
543   GtkFrame *frame;
544   gint x, y, width, height;
545
546   if (gtk_widget_is_drawable (widget))
547     {
548       frame = GTK_FRAME (widget);
549
550       x = frame->child_allocation.x - widget->style->xthickness;
551       y = frame->child_allocation.y - widget->style->ythickness;
552       width = frame->child_allocation.width + 2 * widget->style->xthickness;
553       height =  frame->child_allocation.height + 2 * widget->style->ythickness;
554
555       if (frame->label_widget)
556         {
557           GtkRequisition child_requisition;
558           gfloat xalign;
559           gint height_extra;
560           gint x2;
561
562           gtk_widget_get_child_requisition (frame->label_widget, &child_requisition);
563
564           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
565             xalign = frame->label_xalign;
566           else
567             xalign = 1 - frame->label_xalign;
568
569           height_extra = MAX (0, child_requisition.height - widget->style->ythickness)
570             - frame->label_yalign * child_requisition.height;
571           y -= height_extra;
572           height += height_extra;
573           
574           x2 = widget->style->xthickness + (frame->child_allocation.width - child_requisition.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
575           
576           /* If the label is completely over or under the frame we can omit the gap */
577           if (frame->label_yalign == 0.0 || frame->label_yalign == 1.0)
578             gtk_paint_shadow (widget->style, widget->window,
579                               widget->state, frame->shadow_type,
580                               area, widget, "frame",
581                               x, y, width, height);
582           else
583             gtk_paint_shadow_gap (widget->style, widget->window,
584                                   widget->state, frame->shadow_type,
585                                   area, widget, "frame",
586                                   x, y, width, height,
587                                   GTK_POS_TOP,
588                                   x2, child_requisition.width + 2 * LABEL_PAD);
589         }
590        else
591          gtk_paint_shadow (widget->style, widget->window,
592                            widget->state, frame->shadow_type,
593                            area, widget, "frame",
594                            x, y, width, height);
595     }
596 }
597
598 static gboolean
599 gtk_frame_expose (GtkWidget      *widget,
600                   GdkEventExpose *event)
601 {
602   if (gtk_widget_is_drawable (widget))
603     {
604       gtk_frame_paint (widget, &event->area);
605
606       GTK_WIDGET_CLASS (gtk_frame_parent_class)->expose_event (widget, event);
607     }
608
609   return FALSE;
610 }
611
612 static void
613 gtk_frame_size_allocate (GtkWidget     *widget,
614                          GtkAllocation *allocation)
615 {
616   GtkFrame *frame = GTK_FRAME (widget);
617   GtkBin *bin = GTK_BIN (widget);
618   GtkAllocation new_allocation;
619
620   widget->allocation = *allocation;
621
622   gtk_frame_compute_child_allocation (frame, &new_allocation);
623   
624   /* If the child allocation changed, that means that the frame is drawn
625    * in a new place, so we must redraw the entire widget.
626    */
627   if (gtk_widget_get_mapped (widget)
628 #if 0
629       &&
630       (new_allocation.x != frame->child_allocation.x ||
631        new_allocation.y != frame->child_allocation.y ||
632        new_allocation.width != frame->child_allocation.width ||
633        new_allocation.height != frame->child_allocation.height)
634 #endif
635      )
636     gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
637   
638   if (bin->child && gtk_widget_get_visible (bin->child))
639     gtk_widget_size_allocate (bin->child, &new_allocation);
640   
641   frame->child_allocation = new_allocation;
642   
643   if (frame->label_widget && gtk_widget_get_visible (frame->label_widget))
644     {
645       GtkRequisition child_requisition;
646       GtkAllocation child_allocation;
647       gfloat xalign;
648
649       gtk_widget_get_child_requisition (frame->label_widget, &child_requisition);
650
651       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
652         xalign = frame->label_xalign;
653       else
654         xalign = 1 - frame->label_xalign;
655       
656       child_allocation.x = frame->child_allocation.x + LABEL_SIDE_PAD +
657         (frame->child_allocation.width - child_requisition.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_PAD;
658       child_allocation.width = MIN (child_requisition.width, new_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD);
659
660       child_allocation.y = frame->child_allocation.y - MAX (child_requisition.height, widget->style->ythickness);
661       child_allocation.height = child_requisition.height;
662
663       gtk_widget_size_allocate (frame->label_widget, &child_allocation);
664     }
665 }
666
667 static void
668 gtk_frame_compute_child_allocation (GtkFrame      *frame,
669                                     GtkAllocation *child_allocation)
670 {
671   g_return_if_fail (GTK_IS_FRAME (frame));
672   g_return_if_fail (child_allocation != NULL);
673
674   GTK_FRAME_GET_CLASS (frame)->compute_child_allocation (frame, child_allocation);
675 }
676
677 static void
678 gtk_frame_real_compute_child_allocation (GtkFrame      *frame,
679                                          GtkAllocation *child_allocation)
680 {
681   GtkWidget *widget = GTK_WIDGET (frame);
682   GtkAllocation *allocation = &widget->allocation;
683   GtkRequisition child_requisition;
684   gint top_margin;
685
686   if (frame->label_widget)
687     {
688       gtk_widget_get_child_requisition (frame->label_widget, &child_requisition);
689       top_margin = MAX (child_requisition.height, widget->style->ythickness);
690     }
691   else
692     top_margin = widget->style->ythickness;
693   
694   child_allocation->x = (GTK_CONTAINER (frame)->border_width +
695                          widget->style->xthickness);
696   child_allocation->width = MAX(1, (gint)allocation->width - child_allocation->x * 2);
697   
698   child_allocation->y = (GTK_CONTAINER (frame)->border_width + top_margin);
699   child_allocation->height = MAX (1, ((gint)allocation->height - child_allocation->y -
700                                       (gint)GTK_CONTAINER (frame)->border_width -
701                                       (gint)widget->style->ythickness));
702   
703   child_allocation->x += allocation->x;
704   child_allocation->y += allocation->y;
705 }
706
707 static void
708 gtk_frame_get_size (GtkSizeRequest *request,
709                     GtkOrientation  orientation,
710                     gint           *minimum_size,
711                     gint           *natural_size)
712 {
713   GtkWidget *widget = GTK_WIDGET (request);
714   GtkFrame *frame = GTK_FRAME (widget);
715   GtkBin *bin = GTK_BIN (widget);
716   gint child_min, child_nat;
717   gint minimum, natural;
718
719   if (frame->label_widget && gtk_widget_get_visible (frame->label_widget))
720     {
721       if (orientation == GTK_ORIENTATION_HORIZONTAL)
722         {
723           gtk_size_request_get_width (GTK_SIZE_REQUEST (frame->label_widget),
724                                       &child_min, &child_nat);
725           minimum = child_min + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
726           natural = child_nat + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
727         }
728       else
729         {
730           gtk_size_request_get_height (GTK_SIZE_REQUEST (frame->label_widget),
731                                        &child_min, &child_nat);
732           minimum = MAX (0, child_min - widget->style->ythickness);
733           natural = MAX (0, child_nat - widget->style->ythickness);
734         }
735     }
736   else
737     {
738       minimum = 0;
739       natural = 0;
740     }
741
742   if (bin->child && gtk_widget_get_visible (bin->child))
743     {
744       if (orientation == GTK_ORIENTATION_HORIZONTAL)
745         {
746           gtk_size_request_get_width (GTK_SIZE_REQUEST (bin->child),
747                                       &child_min, &child_nat);
748           minimum = MAX (minimum, child_min);
749           natural = MAX (natural, child_nat);
750         }
751       else
752         {
753           gtk_size_request_get_height (GTK_SIZE_REQUEST (bin->child),
754                                        &child_min, &child_nat);
755           minimum += child_min;
756           natural += child_nat;
757         }
758     }
759
760   if (orientation == GTK_ORIENTATION_HORIZONTAL)
761     {
762       minimum += (GTK_CONTAINER (widget)->border_width +
763                   GTK_WIDGET (widget)->style->xthickness) * 2;
764       natural += (GTK_CONTAINER (widget)->border_width +
765                   GTK_WIDGET (widget)->style->xthickness) * 2;
766     }
767   else
768     {
769       minimum += (GTK_CONTAINER (widget)->border_width +
770                   GTK_WIDGET (widget)->style->ythickness) * 2;
771       natural += (GTK_CONTAINER (widget)->border_width +
772                   GTK_WIDGET (widget)->style->ythickness) * 2;
773     }
774
775  if (minimum_size)
776     *minimum_size = minimum;
777
778   if (natural_size)
779     *natural_size = natural;
780 }
781
782 static void
783 gtk_frame_get_width (GtkSizeRequest *widget,
784                      gint           *minimum_size,
785                      gint           *natural_size)
786 {
787   gtk_frame_get_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
788 }
789
790 static void
791 gtk_frame_get_height (GtkSizeRequest *widget,
792                       gint           *minimum_size,
793                       gint           *natural_size)
794 {
795   gtk_frame_get_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
796 }
797
798 static void
799 gtk_frame_size_request_init (GtkSizeRequestIface *iface)
800 {
801   iface->get_width = gtk_frame_get_width;
802   iface->get_height = gtk_frame_get_height;
803 }
804
805 #define __GTK_FRAME_C__
806 #include "gtkaliasdef.c"