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;
711 /* If the label is completely over or under the frame we can omit the gap */
712 if (priv->label_yalign == 0.0 || priv->label_yalign == 1.0)
713 gtk_render_frame (context, cr, x, y, width, height);
715 gtk_render_frame_gap (context, cr,
718 x2 + priv->label_allocation.width + 2 * LABEL_PAD);
721 gtk_render_frame (context, cr, x, y, width, height);
724 GTK_WIDGET_CLASS (gtk_frame_parent_class)->draw (widget, cr);
730 gtk_frame_size_allocate (GtkWidget *widget,
731 GtkAllocation *allocation)
733 GtkFrame *frame = GTK_FRAME (widget);
734 GtkFramePrivate *priv = frame->priv;
735 GtkBin *bin = GTK_BIN (widget);
736 GtkAllocation new_allocation;
739 gtk_widget_set_allocation (widget, allocation);
741 gtk_frame_compute_child_allocation (frame, &new_allocation);
743 /* If the child allocation changed, that means that the frame is drawn
744 * in a new place, so we must redraw the entire widget.
746 if (gtk_widget_get_mapped (widget))
748 gdk_window_invalidate_rect (gtk_widget_get_window (widget), allocation, FALSE);
751 child = gtk_bin_get_child (bin);
752 if (child && gtk_widget_get_visible (child))
753 gtk_widget_size_allocate (child, &new_allocation);
755 priv->child_allocation = new_allocation;
757 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
760 gint nat_width, width, height;
763 get_padding_and_border (frame, &padding);
765 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
766 xalign = priv->label_xalign;
768 xalign = 1 - priv->label_xalign;
770 gtk_widget_get_preferred_width (priv->label_widget, NULL, &nat_width);
771 width = new_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD;
772 width = MIN (width, nat_width);
774 gtk_widget_get_preferred_height_for_width (priv->label_widget, width,
778 priv->label_allocation.x = priv->child_allocation.x + LABEL_SIDE_PAD +
779 (new_allocation.width - width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_PAD;
781 priv->label_allocation.width = width;
783 priv->label_allocation.y = priv->child_allocation.y - MAX (height, padding.top);
784 priv->label_allocation.height = height;
786 gtk_widget_size_allocate (priv->label_widget, &priv->label_allocation);
791 gtk_frame_compute_child_allocation (GtkFrame *frame,
792 GtkAllocation *child_allocation)
794 g_return_if_fail (GTK_IS_FRAME (frame));
795 g_return_if_fail (child_allocation != NULL);
797 GTK_FRAME_GET_CLASS (frame)->compute_child_allocation (frame, child_allocation);
801 gtk_frame_real_compute_child_allocation (GtkFrame *frame,
802 GtkAllocation *child_allocation)
804 GtkFramePrivate *priv = frame->priv;
805 GtkWidget *widget = GTK_WIDGET (frame);
806 GtkAllocation allocation;
811 gtk_widget_get_allocation (widget, &allocation);
812 get_padding_and_border (frame, &padding);
813 border_width = gtk_container_get_border_width (GTK_CONTAINER (frame));
815 if (priv->label_widget)
817 gint nat_width, width, height;
819 gtk_widget_get_preferred_width (priv->label_widget, NULL, &nat_width);
821 width = allocation.width;
822 width -= 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
823 width -= (border_width * 2) + padding.left + padding.right;
825 width = MIN (width, nat_width);
827 gtk_widget_get_preferred_height_for_width (priv->label_widget, width,
830 top_margin = MAX (height, padding.top);
833 top_margin = padding.top;
835 child_allocation->x = border_width + padding.left;
836 child_allocation->y = border_width + top_margin;
837 child_allocation->width = MAX (1, (gint) (allocation.width - (border_width * 2) -
838 padding.left - padding.right));
839 child_allocation->height = MAX (1, (gint) (allocation.height - child_allocation->y -
840 border_width - padding.bottom));
842 child_allocation->x += allocation.x;
843 child_allocation->y += allocation.y;
847 gtk_frame_get_preferred_size (GtkWidget *request,
848 GtkOrientation orientation,
852 GtkFrame *frame = GTK_FRAME (request);
853 GtkFramePrivate *priv = frame->priv;
855 GtkWidget *widget = GTK_WIDGET (request);
857 GtkBin *bin = GTK_BIN (widget);
858 gint child_min, child_nat;
859 gint minimum, natural;
862 get_padding_and_border (frame, &padding);
863 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
865 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
867 if (orientation == GTK_ORIENTATION_HORIZONTAL)
869 gtk_widget_get_preferred_width (priv->label_widget,
870 &child_min, &child_nat);
871 minimum = child_min + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
872 natural = child_nat + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
876 gtk_widget_get_preferred_height (priv->label_widget,
877 &child_min, &child_nat);
878 minimum = MAX (0, child_min - padding.top);
879 natural = MAX (0, child_nat - padding.top);
888 child = gtk_bin_get_child (bin);
889 if (child && gtk_widget_get_visible (child))
891 if (orientation == GTK_ORIENTATION_HORIZONTAL)
893 gtk_widget_get_preferred_width (child,
894 &child_min, &child_nat);
895 minimum = MAX (minimum, child_min);
896 natural = MAX (natural, child_nat);
900 gtk_widget_get_preferred_height (child,
901 &child_min, &child_nat);
902 minimum += child_min;
903 natural += child_nat;
907 if (orientation == GTK_ORIENTATION_HORIZONTAL)
909 minimum += (border_width * 2) + padding.left + padding.right;
910 natural += (border_width * 2) + padding.left + padding.right;
914 minimum += (border_width * 2) + padding.top + padding.bottom;
915 natural += (border_width * 2) + padding.top + padding.bottom;
919 *minimum_size = minimum;
922 *natural_size = natural;
926 gtk_frame_get_preferred_width (GtkWidget *widget,
930 gtk_frame_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
934 gtk_frame_get_preferred_height (GtkWidget *widget,
938 gtk_frame_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
943 gtk_frame_get_preferred_height_for_width (GtkWidget *request,
945 gint *minimum_height,
946 gint *natural_height)
948 GtkWidget *widget = GTK_WIDGET (request);
950 GtkFrame *frame = GTK_FRAME (widget);
951 GtkFramePrivate *priv = frame->priv;
952 GtkBin *bin = GTK_BIN (widget);
954 gint child_min, child_nat, label_width;
955 gint minimum, natural;
958 get_padding_and_border (frame, &padding);
959 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
961 minimum = (border_width * 2) + padding.top + padding.bottom;
962 natural = (border_width * 2) + padding.top + padding.bottom;
964 width -= (border_width * 2) + padding.left + padding.right;
965 label_width = width - 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
967 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
969 gtk_widget_get_preferred_height_for_width (priv->label_widget,
970 label_width, &child_min, &child_nat);
971 minimum += child_min;
972 natural += child_nat;
975 child = gtk_bin_get_child (bin);
976 if (child && gtk_widget_get_visible (child))
978 gtk_widget_get_preferred_height_for_width (child,
979 width, &child_min, &child_nat);
980 minimum += child_min;
981 natural += child_nat;
985 *minimum_height = minimum;
988 *natural_height = natural;
992 gtk_frame_get_preferred_width_for_height (GtkWidget *widget,
997 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);