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