]> Pileus Git - ~andy/gtk/blob - gtk/gtkframe.c
Add GtkBuilder, fixes #172535
[~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                 (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.5,
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 = gtk_frame_buildable_add;
166 }
167
168 static void
169 gtk_frame_buildable_add (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: 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 (frame->label_widget && 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_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_VISIBLE (label_widget);
393     }
394   
395   if (GTK_WIDGET_VISIBLE (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.
429  * 
430  * Sets the alignment of the frame widget's label. The
431  * default values for a newly created frame are 0.0 and 0.5.
432  **/
433 void
434 gtk_frame_set_label_align (GtkFrame *frame,
435                            gfloat    xalign,
436                            gfloat    yalign)
437 {
438   g_return_if_fail (GTK_IS_FRAME (frame));
439
440   xalign = CLAMP (xalign, 0.0, 1.0);
441   yalign = CLAMP (yalign, 0.0, 1.0);
442
443   g_object_freeze_notify (G_OBJECT (frame));
444   if (xalign != frame->label_xalign)
445     {
446       frame->label_xalign = xalign;
447       g_object_notify (G_OBJECT (frame), "label-xalign");
448     }
449
450   if (yalign != frame->label_yalign)
451     {
452       frame->label_yalign = yalign;
453       g_object_notify (G_OBJECT (frame), "label-yalign");
454     }
455
456   g_object_thaw_notify (G_OBJECT (frame));
457   gtk_widget_queue_resize (GTK_WIDGET (frame));
458 }
459
460 /**
461  * gtk_frame_get_label_align:
462  * @frame: a #GtkFrame
463  * @xalign: location to store X alignment of frame's label, or %NULL
464  * @yalign: location to store X alignment of frame's label, or %NULL
465  * 
466  * Retrieves the X and Y alignment of the frame's label. See
467  * gtk_frame_set_label_align().
468  **/
469 void
470 gtk_frame_get_label_align (GtkFrame *frame,
471                            gfloat   *xalign,
472                            gfloat   *yalign)
473 {
474   g_return_if_fail (GTK_IS_FRAME (frame));
475
476   if (xalign)
477     *xalign = frame->label_xalign;
478   if (yalign)
479     *yalign = frame->label_yalign;
480 }
481
482 /**
483  * gtk_frame_set_shadow_type:
484  * @frame: a #GtkFrame
485  * @type: the new #GtkShadowType
486  * 
487  * Sets the shadow type for @frame.
488  **/
489 void
490 gtk_frame_set_shadow_type (GtkFrame      *frame,
491                            GtkShadowType  type)
492 {
493   g_return_if_fail (GTK_IS_FRAME (frame));
494
495   if ((GtkShadowType) frame->shadow_type != type)
496     {
497       frame->shadow_type = type;
498       g_object_notify (G_OBJECT (frame), "shadow-type");
499
500       if (GTK_WIDGET_DRAWABLE (frame))
501         {
502           gtk_widget_queue_draw (GTK_WIDGET (frame));
503         }
504       
505       gtk_widget_queue_resize (GTK_WIDGET (frame));
506     }
507 }
508
509 /**
510  * gtk_frame_get_shadow_type:
511  * @frame: a #GtkFrame
512  *
513  * Retrieves the shadow type of the frame. See
514  * gtk_frame_set_shadow_type().
515  *
516  * Return value: the current shadow type of the frame.
517  **/
518 GtkShadowType
519 gtk_frame_get_shadow_type (GtkFrame *frame)
520 {
521   g_return_val_if_fail (GTK_IS_FRAME (frame), GTK_SHADOW_ETCHED_IN);
522
523   return frame->shadow_type;
524 }
525
526 static void
527 gtk_frame_paint (GtkWidget    *widget,
528                  GdkRectangle *area)
529 {
530   GtkFrame *frame;
531   gint x, y, width, height;
532
533   if (GTK_WIDGET_DRAWABLE (widget))
534     {
535       frame = GTK_FRAME (widget);
536
537       x = frame->child_allocation.x - widget->style->xthickness;
538       y = frame->child_allocation.y - widget->style->ythickness;
539       width = frame->child_allocation.width + 2 * widget->style->xthickness;
540       height =  frame->child_allocation.height + 2 * widget->style->ythickness;
541
542       if (frame->label_widget)
543         {
544           GtkRequisition child_requisition;
545           gfloat xalign;
546           gint height_extra;
547           gint x2;
548
549           gtk_widget_get_child_requisition (frame->label_widget, &child_requisition);
550
551           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
552             xalign = frame->label_xalign;
553           else
554             xalign = 1 - frame->label_xalign;
555
556           height_extra = MAX (0, child_requisition.height - widget->style->ythickness);
557           height_extra *= (1 - frame->label_yalign);
558           y -= height_extra;
559           height += height_extra;
560           
561           x2 = widget->style->xthickness + (frame->child_allocation.width - child_requisition.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
562
563           
564           gtk_paint_shadow_gap (widget->style, widget->window,
565                                 widget->state, frame->shadow_type,
566                                 area, widget, "frame",
567                                 x, y, width, height,
568                                 GTK_POS_TOP, 
569                                 x2, child_requisition.width + 2 * LABEL_PAD);
570         }
571        else
572          gtk_paint_shadow (widget->style, widget->window,
573                            widget->state, frame->shadow_type,
574                            area, widget, "frame",
575                            x, y, width, height);
576     }
577 }
578
579 static gboolean
580 gtk_frame_expose (GtkWidget      *widget,
581                   GdkEventExpose *event)
582 {
583   if (GTK_WIDGET_DRAWABLE (widget))
584     {
585       gtk_frame_paint (widget, &event->area);
586
587       (* GTK_WIDGET_CLASS (gtk_frame_parent_class)->expose_event) (widget, event);
588     }
589
590   return FALSE;
591 }
592
593 static void
594 gtk_frame_size_request (GtkWidget      *widget,
595                         GtkRequisition *requisition)
596 {
597   GtkFrame *frame = GTK_FRAME (widget);
598   GtkBin *bin = GTK_BIN (widget);
599   GtkRequisition child_requisition;
600   
601   if (frame->label_widget && GTK_WIDGET_VISIBLE (frame->label_widget))
602     {
603       gtk_widget_size_request (frame->label_widget, &child_requisition);
604
605       requisition->width = child_requisition.width + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
606       requisition->height =
607         MAX (0, child_requisition.height - GTK_WIDGET (widget)->style->ythickness);
608     }
609   else
610     {
611       requisition->width = 0;
612       requisition->height = 0;
613     }
614   
615   if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
616     {
617       gtk_widget_size_request (bin->child, &child_requisition);
618
619       requisition->width = MAX (requisition->width, child_requisition.width);
620       requisition->height += child_requisition.height;
621     }
622
623   requisition->width += (GTK_CONTAINER (widget)->border_width +
624                          GTK_WIDGET (widget)->style->xthickness) * 2;
625   requisition->height += (GTK_CONTAINER (widget)->border_width +
626                           GTK_WIDGET (widget)->style->ythickness) * 2;
627 }
628
629 static void
630 gtk_frame_size_allocate (GtkWidget     *widget,
631                          GtkAllocation *allocation)
632 {
633   GtkFrame *frame = GTK_FRAME (widget);
634   GtkBin *bin = GTK_BIN (widget);
635   GtkAllocation new_allocation;
636
637   widget->allocation = *allocation;
638
639   gtk_frame_compute_child_allocation (frame, &new_allocation);
640   
641   /* If the child allocation changed, that means that the frame is drawn
642    * in a new place, so we must redraw the entire widget.
643    */
644   if (GTK_WIDGET_MAPPED (widget) &&
645       (new_allocation.x != frame->child_allocation.x ||
646        new_allocation.y != frame->child_allocation.y ||
647        new_allocation.width != frame->child_allocation.width ||
648        new_allocation.height != frame->child_allocation.height))
649     gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
650   
651   if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
652     gtk_widget_size_allocate (bin->child, &new_allocation);
653   
654   frame->child_allocation = new_allocation;
655   
656   if (frame->label_widget && GTK_WIDGET_VISIBLE (frame->label_widget))
657     {
658       GtkRequisition child_requisition;
659       GtkAllocation child_allocation;
660       gfloat xalign;
661
662       gtk_widget_get_child_requisition (frame->label_widget, &child_requisition);
663
664       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
665         xalign = frame->label_xalign;
666       else
667         xalign = 1 - frame->label_xalign;
668       
669       child_allocation.x = frame->child_allocation.x + LABEL_SIDE_PAD +
670         (frame->child_allocation.width - child_requisition.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_PAD;
671       child_allocation.width = child_requisition.width;
672
673       child_allocation.y = frame->child_allocation.y - MAX (child_requisition.height, widget->style->ythickness);
674       child_allocation.height = child_requisition.height;
675
676       gtk_widget_size_allocate (frame->label_widget, &child_allocation);
677     }
678 }
679
680 static void
681 gtk_frame_compute_child_allocation (GtkFrame      *frame,
682                                     GtkAllocation *child_allocation)
683 {
684   g_return_if_fail (GTK_IS_FRAME (frame));
685   g_return_if_fail (child_allocation != NULL);
686
687   GTK_FRAME_GET_CLASS (frame)->compute_child_allocation (frame, child_allocation);
688 }
689
690 static void
691 gtk_frame_real_compute_child_allocation (GtkFrame      *frame,
692                                          GtkAllocation *child_allocation)
693 {
694   GtkWidget *widget = GTK_WIDGET (frame);
695   GtkAllocation *allocation = &widget->allocation;
696   GtkRequisition child_requisition;
697   gint top_margin;
698
699   if (frame->label_widget)
700     {
701       gtk_widget_get_child_requisition (frame->label_widget, &child_requisition);
702       top_margin = MAX (child_requisition.height, widget->style->ythickness);
703     }
704   else
705     top_margin = widget->style->ythickness;
706   
707   child_allocation->x = (GTK_CONTAINER (frame)->border_width +
708                          widget->style->xthickness);
709   child_allocation->width = MAX(1, (gint)allocation->width - child_allocation->x * 2);
710   
711   child_allocation->y = (GTK_CONTAINER (frame)->border_width + top_margin);
712   child_allocation->height = MAX (1, ((gint)allocation->height - child_allocation->y -
713                                       (gint)GTK_CONTAINER (frame)->border_width -
714                                       (gint)widget->style->ythickness));
715   
716   child_allocation->x += allocation->x;
717   child_allocation->y += allocation->y;
718 }
719
720 #define __GTK_FRAME_C__
721 #include "gtkaliasdef.c"