1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gtkprivate.h"
30 #include "gtktypebuiltins.h"
32 #include "gtkbuildable.h"
33 #include "gtkwidgetpath.h"
35 #include "a11y/gtkframeaccessible.h"
39 * @Short_description: A bin with a decorative frame and optional label
42 * The frame widget is a Bin that surrounds its child
43 * with a decorative frame and an optional label.
44 * If present, the label is drawn in a gap in the
45 * top side of the frame. The position of the
46 * label can be controlled with gtk_frame_set_label_align().
48 * <refsect2 id="GtkFrame-BUILDER-UI">
49 * <title>GtkFrame as GtkBuildable</title>
51 * The GtkFrame implementation of the GtkBuildable interface
52 * supports placing a child in the label position by specifying
53 * "label" as the "type" attribute of a <child> element.
54 * A normal content child can be specified without specifying
55 * a <child> type attribute.
58 * <title>A UI definition fragment with GtkFrame</title>
59 * <programlisting><![CDATA[
60 * <object class="GtkFrame">
61 * <child type="label">
62 * <object class="GtkLabel" id="frame-label"/>
65 * <object class="GtkEntry" id="frame-content"/>
68 * ]]></programlisting>
75 #define LABEL_SIDE_PAD 2
77 struct _GtkFramePrivate
80 GtkWidget *label_widget;
87 GtkAllocation child_allocation;
88 GtkAllocation label_allocation;
100 static void gtk_frame_set_property (GObject *object,
104 static void gtk_frame_get_property (GObject *object,
108 static gboolean gtk_frame_draw (GtkWidget *widget,
110 static void gtk_frame_size_allocate (GtkWidget *widget,
111 GtkAllocation *allocation);
112 static void gtk_frame_remove (GtkContainer *container,
114 static void gtk_frame_forall (GtkContainer *container,
115 gboolean include_internals,
116 GtkCallback callback,
117 gpointer callback_data);
118 static GtkWidgetPath * gtk_frame_get_path_for_child (GtkContainer *container,
121 static void gtk_frame_compute_child_allocation (GtkFrame *frame,
122 GtkAllocation *child_allocation);
123 static void gtk_frame_real_compute_child_allocation (GtkFrame *frame,
124 GtkAllocation *child_allocation);
127 static void gtk_frame_buildable_init (GtkBuildableIface *iface);
128 static void gtk_frame_buildable_add_child (GtkBuildable *buildable,
133 static void gtk_frame_get_preferred_width (GtkWidget *widget,
136 static void gtk_frame_get_preferred_height (GtkWidget *widget,
139 static void gtk_frame_get_preferred_height_for_width(GtkWidget *layout,
141 gint *minimum_height,
142 gint *natural_height);
143 static void gtk_frame_get_preferred_width_for_height(GtkWidget *layout,
145 gint *minimum_height,
146 gint *natural_height);
149 G_DEFINE_TYPE_WITH_CODE (GtkFrame, gtk_frame, GTK_TYPE_BIN,
150 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
151 gtk_frame_buildable_init))
154 gtk_frame_class_init (GtkFrameClass *class)
156 GObjectClass *gobject_class;
157 GtkWidgetClass *widget_class;
158 GtkContainerClass *container_class;
160 gobject_class = (GObjectClass*) class;
161 widget_class = GTK_WIDGET_CLASS (class);
162 container_class = GTK_CONTAINER_CLASS (class);
164 gobject_class->set_property = gtk_frame_set_property;
165 gobject_class->get_property = gtk_frame_get_property;
167 g_object_class_install_property (gobject_class,
169 g_param_spec_string ("label",
171 P_("Text of the frame's label"),
174 GTK_PARAM_WRITABLE));
175 g_object_class_install_property (gobject_class,
177 g_param_spec_float ("label-xalign",
179 P_("The horizontal alignment of the label"),
183 GTK_PARAM_READWRITE));
184 g_object_class_install_property (gobject_class,
186 g_param_spec_float ("label-yalign",
188 P_("The vertical alignment of the label"),
192 GTK_PARAM_READWRITE));
193 g_object_class_install_property (gobject_class,
195 g_param_spec_enum ("shadow-type",
197 P_("Appearance of the frame border"),
198 GTK_TYPE_SHADOW_TYPE,
199 GTK_SHADOW_ETCHED_IN,
200 GTK_PARAM_READWRITE));
202 g_object_class_install_property (gobject_class,
204 g_param_spec_object ("label-widget",
206 P_("A widget to display in place of the usual frame label"),
208 GTK_PARAM_READWRITE));
210 widget_class->draw = gtk_frame_draw;
211 widget_class->size_allocate = gtk_frame_size_allocate;
212 widget_class->get_preferred_width = gtk_frame_get_preferred_width;
213 widget_class->get_preferred_height = gtk_frame_get_preferred_height;
214 widget_class->get_preferred_height_for_width = gtk_frame_get_preferred_height_for_width;
215 widget_class->get_preferred_width_for_height = gtk_frame_get_preferred_width_for_height;
217 container_class->remove = gtk_frame_remove;
218 container_class->forall = gtk_frame_forall;
219 container_class->get_path_for_child = gtk_frame_get_path_for_child;
221 class->compute_child_allocation = gtk_frame_real_compute_child_allocation;
223 g_type_class_add_private (class, sizeof (GtkFramePrivate));
225 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_FRAME_ACCESSIBLE);
229 gtk_frame_buildable_init (GtkBuildableIface *iface)
231 iface->add_child = gtk_frame_buildable_add_child;
235 gtk_frame_buildable_add_child (GtkBuildable *buildable,
240 if (type && strcmp (type, "label") == 0)
241 gtk_frame_set_label_widget (GTK_FRAME (buildable), GTK_WIDGET (child));
243 gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
245 GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_FRAME (buildable), type);
249 gtk_frame_init (GtkFrame *frame)
251 GtkFramePrivate *priv;
252 GtkStyleContext *context;
254 frame->priv = G_TYPE_INSTANCE_GET_PRIVATE (frame,
259 priv->label_widget = NULL;
260 priv->shadow_type = GTK_SHADOW_ETCHED_IN;
261 priv->label_xalign = 0.0;
262 priv->label_yalign = 0.5;
264 context = gtk_widget_get_style_context (GTK_WIDGET (frame));
265 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
269 gtk_frame_set_property (GObject *object,
274 GtkFrame *frame = GTK_FRAME (object);
275 GtkFramePrivate *priv = frame->priv;
280 gtk_frame_set_label (frame, g_value_get_string (value));
282 case PROP_LABEL_XALIGN:
283 gtk_frame_set_label_align (frame, g_value_get_float (value),
286 case PROP_LABEL_YALIGN:
287 gtk_frame_set_label_align (frame, priv->label_xalign,
288 g_value_get_float (value));
290 case PROP_SHADOW_TYPE:
291 gtk_frame_set_shadow_type (frame, g_value_get_enum (value));
293 case PROP_LABEL_WIDGET:
294 gtk_frame_set_label_widget (frame, g_value_get_object (value));
297 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
303 gtk_frame_get_property (GObject *object,
308 GtkFrame *frame = GTK_FRAME (object);
309 GtkFramePrivate *priv = frame->priv;
314 g_value_set_string (value, gtk_frame_get_label (frame));
316 case PROP_LABEL_XALIGN:
317 g_value_set_float (value, priv->label_xalign);
319 case PROP_LABEL_YALIGN:
320 g_value_set_float (value, priv->label_yalign);
322 case PROP_SHADOW_TYPE:
323 g_value_set_enum (value, priv->shadow_type);
325 case PROP_LABEL_WIDGET:
326 g_value_set_object (value,
328 G_OBJECT (priv->label_widget) : NULL);
331 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
338 * @label: the text to use as the label of the frame
340 * Creates a new #GtkFrame, with optional label @label.
341 * If @label is %NULL, the label is omitted.
343 * Return value: a new #GtkFrame widget
346 gtk_frame_new (const gchar *label)
348 return g_object_new (GTK_TYPE_FRAME, "label", label, NULL);
352 gtk_frame_remove (GtkContainer *container,
355 GtkFrame *frame = GTK_FRAME (container);
356 GtkFramePrivate *priv = frame->priv;
358 if (priv->label_widget == child)
359 gtk_frame_set_label_widget (frame, NULL);
361 GTK_CONTAINER_CLASS (gtk_frame_parent_class)->remove (container, child);
365 gtk_frame_forall (GtkContainer *container,
366 gboolean include_internals,
367 GtkCallback callback,
368 gpointer callback_data)
370 GtkBin *bin = GTK_BIN (container);
371 GtkFrame *frame = GTK_FRAME (container);
372 GtkFramePrivate *priv = frame->priv;
375 child = gtk_bin_get_child (bin);
377 (* callback) (child, callback_data);
379 if (priv->label_widget)
380 (* callback) (priv->label_widget, callback_data);
383 static GtkWidgetPath *
384 gtk_frame_get_path_for_child (GtkContainer *container,
387 GtkFramePrivate *priv = GTK_FRAME (container)->priv;
390 path = GTK_CONTAINER_CLASS (gtk_frame_parent_class)->get_path_for_child (container, child);
392 if (child == priv->label_widget)
393 gtk_widget_path_iter_add_class (path,
394 gtk_widget_path_length (path) - 2,
395 GTK_STYLE_CLASS_FRAME);
401 * gtk_frame_set_label:
402 * @frame: a #GtkFrame
403 * @label: (allow-none): the text to use as the label of the frame
405 * Sets the text of the label. If @label is %NULL,
406 * the current label is removed.
409 gtk_frame_set_label (GtkFrame *frame,
412 g_return_if_fail (GTK_IS_FRAME (frame));
416 gtk_frame_set_label_widget (frame, NULL);
420 GtkWidget *child = gtk_label_new (label);
421 gtk_widget_show (child);
423 gtk_frame_set_label_widget (frame, child);
428 * gtk_frame_get_label:
429 * @frame: a #GtkFrame
431 * If the frame's label widget is a #GtkLabel, returns the
432 * text in the label widget. (The frame will have a #GtkLabel
433 * for the label widget if a non-%NULL argument was passed
434 * to gtk_frame_new().)
436 * Return value: the text in the label, or %NULL if there
437 * was no label widget or the lable widget was not
438 * a #GtkLabel. This string is owned by GTK+ and
439 * must not be modified or freed.
442 gtk_frame_get_label (GtkFrame *frame)
444 GtkFramePrivate *priv;
446 g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
450 if (GTK_IS_LABEL (priv->label_widget))
451 return gtk_label_get_text (GTK_LABEL (priv->label_widget));
457 * gtk_frame_set_label_widget:
458 * @frame: a #GtkFrame
459 * @label_widget: the new label widget
461 * Sets the label widget for the frame. This is the widget that
462 * will appear embedded in the top edge of the frame as a
466 gtk_frame_set_label_widget (GtkFrame *frame,
467 GtkWidget *label_widget)
469 GtkFramePrivate *priv;
470 gboolean need_resize = FALSE;
472 g_return_if_fail (GTK_IS_FRAME (frame));
473 g_return_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget));
474 g_return_if_fail (label_widget == NULL || gtk_widget_get_parent (label_widget) == NULL);
478 if (priv->label_widget == label_widget)
481 if (priv->label_widget)
483 need_resize = gtk_widget_get_visible (priv->label_widget);
484 gtk_widget_unparent (priv->label_widget);
487 priv->label_widget = label_widget;
491 priv->label_widget = label_widget;
492 gtk_widget_set_parent (label_widget, GTK_WIDGET (frame));
493 need_resize |= gtk_widget_get_visible (label_widget);
496 if (gtk_widget_get_visible (GTK_WIDGET (frame)) && need_resize)
497 gtk_widget_queue_resize (GTK_WIDGET (frame));
499 g_object_freeze_notify (G_OBJECT (frame));
500 g_object_notify (G_OBJECT (frame), "label-widget");
501 g_object_notify (G_OBJECT (frame), "label");
502 g_object_thaw_notify (G_OBJECT (frame));
506 * gtk_frame_get_label_widget:
507 * @frame: a #GtkFrame
509 * Retrieves the label widget for the frame. See
510 * gtk_frame_set_label_widget().
512 * Return value: (transfer none): the label widget, or %NULL if there is none.
515 gtk_frame_get_label_widget (GtkFrame *frame)
517 g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
519 return frame->priv->label_widget;
523 * gtk_frame_set_label_align:
524 * @frame: a #GtkFrame
525 * @xalign: The position of the label along the top edge
526 * of the widget. A value of 0.0 represents left alignment;
527 * 1.0 represents right alignment.
528 * @yalign: The y alignment of the label. A value of 0.0 aligns under
529 * the frame; 1.0 aligns above the frame. If the values are exactly
530 * 0.0 or 1.0 the gap in the frame won't be painted because the label
531 * will be completely above or below the frame.
533 * Sets the alignment of the frame widget's label. The
534 * default values for a newly created frame are 0.0 and 0.5.
537 gtk_frame_set_label_align (GtkFrame *frame,
541 GtkFramePrivate *priv;
543 g_return_if_fail (GTK_IS_FRAME (frame));
547 xalign = CLAMP (xalign, 0.0, 1.0);
548 yalign = CLAMP (yalign, 0.0, 1.0);
550 g_object_freeze_notify (G_OBJECT (frame));
551 if (xalign != priv->label_xalign)
553 priv->label_xalign = xalign;
554 g_object_notify (G_OBJECT (frame), "label-xalign");
557 if (yalign != priv->label_yalign)
559 priv->label_yalign = yalign;
560 g_object_notify (G_OBJECT (frame), "label-yalign");
563 g_object_thaw_notify (G_OBJECT (frame));
564 gtk_widget_queue_resize (GTK_WIDGET (frame));
568 * gtk_frame_get_label_align:
569 * @frame: a #GtkFrame
570 * @xalign: (out) (allow-none): location to store X alignment of
571 * frame's label, or %NULL
572 * @yalign: (out) (allow-none): location to store X alignment of
573 * frame's label, or %NULL
575 * Retrieves the X and Y alignment of the frame's label. See
576 * gtk_frame_set_label_align().
579 gtk_frame_get_label_align (GtkFrame *frame,
583 GtkFramePrivate *priv;
585 g_return_if_fail (GTK_IS_FRAME (frame));
590 *xalign = priv->label_xalign;
592 *yalign = priv->label_yalign;
596 * gtk_frame_set_shadow_type:
597 * @frame: a #GtkFrame
598 * @type: the new #GtkShadowType
600 * Sets the shadow type for @frame.
603 gtk_frame_set_shadow_type (GtkFrame *frame,
606 GtkFramePrivate *priv;
609 g_return_if_fail (GTK_IS_FRAME (frame));
613 if ((GtkShadowType) priv->shadow_type != type)
615 widget = GTK_WIDGET (frame);
616 priv->shadow_type = type;
617 g_object_notify (G_OBJECT (frame), "shadow-type");
619 if (gtk_widget_is_drawable (widget))
621 gtk_widget_queue_draw (widget);
624 gtk_widget_queue_resize (widget);
629 * gtk_frame_get_shadow_type:
630 * @frame: a #GtkFrame
632 * Retrieves the shadow type of the frame. See
633 * gtk_frame_set_shadow_type().
635 * Return value: the current shadow type of the frame.
638 gtk_frame_get_shadow_type (GtkFrame *frame)
640 g_return_val_if_fail (GTK_IS_FRAME (frame), GTK_SHADOW_ETCHED_IN);
642 return frame->priv->shadow_type;
646 get_padding_and_border (GtkFrame *frame,
649 GtkStyleContext *context;
652 context = gtk_widget_get_style_context (GTK_WIDGET (frame));
653 state = gtk_widget_get_state_flags (GTK_WIDGET (frame));
655 gtk_style_context_get_padding (context, state, border);
657 if (frame->priv->shadow_type != GTK_SHADOW_NONE)
661 gtk_style_context_get_border (context, state, &tmp);
662 border->top += tmp.top;
663 border->right += tmp.right;
664 border->bottom += tmp.bottom;
665 border->left += tmp.left;
670 gtk_frame_draw (GtkWidget *widget,
674 GtkFramePrivate *priv;
675 GtkStyleContext *context;
676 gint x, y, width, height;
677 GtkAllocation allocation;
680 frame = GTK_FRAME (widget);
683 gtk_widget_get_allocation (widget, &allocation);
684 get_padding_and_border (frame, &padding);
685 context = gtk_widget_get_style_context (widget);
687 x = priv->child_allocation.x - allocation.x - padding.left;
688 y = priv->child_allocation.y - allocation.y - padding.top;
689 width = priv->child_allocation.width + padding.left + padding.right;
690 height = priv->child_allocation.height + padding.top + padding.bottom;
692 if (priv->shadow_type != GTK_SHADOW_NONE)
694 if (priv->label_widget)
700 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
701 xalign = priv->label_xalign;
703 xalign = 1 - priv->label_xalign;
705 height_extra = MAX (0, priv->label_allocation.height - padding.top)
706 - priv->label_yalign * priv->label_allocation.height;
708 height += height_extra;
710 x2 = padding.left + (priv->child_allocation.width - priv->label_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
712 gtk_render_background (context, cr, x, y, width, height);
714 /* If the label is completely over or under the frame we can omit the gap */
715 if (priv->label_yalign == 0.0 || priv->label_yalign == 1.0)
716 gtk_render_frame (context, cr, x, y, width, height);
718 gtk_render_frame_gap (context, cr,
721 x2 + priv->label_allocation.width + 2 * LABEL_PAD);
725 gtk_render_background (context, cr, x, y, width, height);
726 gtk_render_frame (context, cr, x, y, width, height);
731 gtk_render_background (context, cr, x, y, width, height);
734 GTK_WIDGET_CLASS (gtk_frame_parent_class)->draw (widget, cr);
740 gtk_frame_size_allocate (GtkWidget *widget,
741 GtkAllocation *allocation)
743 GtkFrame *frame = GTK_FRAME (widget);
744 GtkFramePrivate *priv = frame->priv;
745 GtkBin *bin = GTK_BIN (widget);
746 GtkAllocation new_allocation;
749 gtk_widget_set_allocation (widget, allocation);
751 gtk_frame_compute_child_allocation (frame, &new_allocation);
753 /* If the child allocation changed, that means that the frame is drawn
754 * in a new place, so we must redraw the entire widget.
756 if (gtk_widget_get_mapped (widget))
758 gdk_window_invalidate_rect (gtk_widget_get_window (widget), allocation, FALSE);
761 child = gtk_bin_get_child (bin);
762 if (child && gtk_widget_get_visible (child))
763 gtk_widget_size_allocate (child, &new_allocation);
765 priv->child_allocation = new_allocation;
767 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
770 gint nat_width, width, height;
773 get_padding_and_border (frame, &padding);
775 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
776 xalign = priv->label_xalign;
778 xalign = 1 - priv->label_xalign;
780 gtk_widget_get_preferred_width (priv->label_widget, NULL, &nat_width);
781 width = new_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD;
782 width = MIN (width, nat_width);
784 gtk_widget_get_preferred_height_for_width (priv->label_widget, width,
788 priv->label_allocation.x = priv->child_allocation.x + LABEL_SIDE_PAD +
789 (new_allocation.width - width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_PAD;
791 priv->label_allocation.width = width;
793 priv->label_allocation.y = priv->child_allocation.y - MAX (height, padding.top);
794 priv->label_allocation.height = height;
796 gtk_widget_size_allocate (priv->label_widget, &priv->label_allocation);
801 gtk_frame_compute_child_allocation (GtkFrame *frame,
802 GtkAllocation *child_allocation)
804 g_return_if_fail (GTK_IS_FRAME (frame));
805 g_return_if_fail (child_allocation != NULL);
807 GTK_FRAME_GET_CLASS (frame)->compute_child_allocation (frame, child_allocation);
811 gtk_frame_real_compute_child_allocation (GtkFrame *frame,
812 GtkAllocation *child_allocation)
814 GtkFramePrivate *priv = frame->priv;
815 GtkWidget *widget = GTK_WIDGET (frame);
816 GtkAllocation allocation;
821 gtk_widget_get_allocation (widget, &allocation);
822 get_padding_and_border (frame, &padding);
823 border_width = gtk_container_get_border_width (GTK_CONTAINER (frame));
825 if (priv->label_widget)
827 gint nat_width, width, height;
829 gtk_widget_get_preferred_width (priv->label_widget, NULL, &nat_width);
831 width = allocation.width;
832 width -= 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
833 width -= (border_width * 2) + padding.left + padding.right;
835 width = MIN (width, nat_width);
837 gtk_widget_get_preferred_height_for_width (priv->label_widget, width,
840 top_margin = MAX (height, padding.top);
843 top_margin = padding.top;
845 child_allocation->x = border_width + padding.left;
846 child_allocation->y = border_width + top_margin;
847 child_allocation->width = MAX (1, (gint) (allocation.width - (border_width * 2) -
848 padding.left - padding.right));
849 child_allocation->height = MAX (1, (gint) (allocation.height - child_allocation->y -
850 border_width - padding.bottom));
852 child_allocation->x += allocation.x;
853 child_allocation->y += allocation.y;
857 gtk_frame_get_preferred_size (GtkWidget *request,
858 GtkOrientation orientation,
862 GtkFrame *frame = GTK_FRAME (request);
863 GtkFramePrivate *priv = frame->priv;
865 GtkWidget *widget = GTK_WIDGET (request);
867 GtkBin *bin = GTK_BIN (widget);
868 gint child_min, child_nat;
869 gint minimum, natural;
872 get_padding_and_border (frame, &padding);
873 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
875 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
877 if (orientation == GTK_ORIENTATION_HORIZONTAL)
879 gtk_widget_get_preferred_width (priv->label_widget,
880 &child_min, &child_nat);
881 minimum = child_min + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
882 natural = child_nat + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
886 gtk_widget_get_preferred_height (priv->label_widget,
887 &child_min, &child_nat);
888 minimum = MAX (0, child_min - padding.top);
889 natural = MAX (0, child_nat - padding.top);
898 child = gtk_bin_get_child (bin);
899 if (child && gtk_widget_get_visible (child))
901 if (orientation == GTK_ORIENTATION_HORIZONTAL)
903 gtk_widget_get_preferred_width (child,
904 &child_min, &child_nat);
905 minimum = MAX (minimum, child_min);
906 natural = MAX (natural, child_nat);
910 gtk_widget_get_preferred_height (child,
911 &child_min, &child_nat);
912 minimum += child_min;
913 natural += child_nat;
917 if (orientation == GTK_ORIENTATION_HORIZONTAL)
919 minimum += (border_width * 2) + padding.left + padding.right;
920 natural += (border_width * 2) + padding.left + padding.right;
924 minimum += (border_width * 2) + padding.top + padding.bottom;
925 natural += (border_width * 2) + padding.top + padding.bottom;
929 *minimum_size = minimum;
932 *natural_size = natural;
936 gtk_frame_get_preferred_width (GtkWidget *widget,
940 gtk_frame_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
944 gtk_frame_get_preferred_height (GtkWidget *widget,
948 gtk_frame_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
953 gtk_frame_get_preferred_height_for_width (GtkWidget *request,
955 gint *minimum_height,
956 gint *natural_height)
958 GtkWidget *widget = GTK_WIDGET (request);
960 GtkFrame *frame = GTK_FRAME (widget);
961 GtkFramePrivate *priv = frame->priv;
962 GtkBin *bin = GTK_BIN (widget);
964 gint child_min, child_nat, label_width;
965 gint minimum, natural;
968 get_padding_and_border (frame, &padding);
969 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
971 minimum = (border_width * 2) + padding.top + padding.bottom;
972 natural = (border_width * 2) + padding.top + padding.bottom;
974 width -= (border_width * 2) + padding.left + padding.right;
975 label_width = width - 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
977 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
979 gtk_widget_get_preferred_height_for_width (priv->label_widget,
980 label_width, &child_min, &child_nat);
981 minimum += child_min;
982 natural += child_nat;
985 child = gtk_bin_get_child (bin);
986 if (child && gtk_widget_get_visible (child))
988 gtk_widget_get_preferred_height_for_width (child,
989 width, &child_min, &child_nat);
990 minimum += child_min;
991 natural += child_nat;
995 *minimum_height = minimum;
998 *natural_height = natural;
1002 gtk_frame_get_preferred_width_for_height (GtkWidget *widget,
1004 gint *minimum_width,
1005 gint *natural_width)
1007 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);