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