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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
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/.
31 #include "gtkprivate.h"
32 #include "gtktypebuiltins.h"
34 #include "gtkbuildable.h"
36 #include "a11y/gtkframeaccessible.h"
40 * @Short_description: A bin with a decorative frame and optional label
43 * The frame widget is a Bin that surrounds its child
44 * with a decorative frame and an optional label.
45 * If present, the label is drawn in a gap in the
46 * top side of the frame. The position of the
47 * label can be controlled with gtk_frame_set_label_align().
49 * <refsect2 id="GtkFrame-BUILDER-UI">
50 * <title>GtkFrame as GtkBuildable</title>
52 * The GtkFrame implementation of the GtkBuildable interface
53 * supports placing a child in the label position by specifying
54 * "label" as the "type" attribute of a <child> element.
55 * A normal content child can be specified without specifying
56 * a <child> type attribute.
59 * <title>A UI definition fragment with GtkFrame</title>
60 * <programlisting><![CDATA[
61 * <object class="GtkFrame">
62 * <child type="label">
63 * <object class="GtkLabel" id="frame-label"/>
66 * <object class="GtkEntry" id="frame-content"/>
69 * ]]></programlisting>
76 #define LABEL_SIDE_PAD 2
78 struct _GtkFramePrivate
81 GtkWidget *label_widget;
88 GtkAllocation child_allocation;
89 GtkAllocation label_allocation;
101 static void gtk_frame_set_property (GObject *object,
105 static void gtk_frame_get_property (GObject *object,
109 static gboolean gtk_frame_draw (GtkWidget *widget,
111 static void gtk_frame_size_allocate (GtkWidget *widget,
112 GtkAllocation *allocation);
113 static void gtk_frame_remove (GtkContainer *container,
115 static void gtk_frame_forall (GtkContainer *container,
116 gboolean include_internals,
117 GtkCallback callback,
118 gpointer callback_data);
119 static GtkWidgetPath * gtk_frame_get_path_for_child (GtkContainer *container,
122 static void gtk_frame_compute_child_allocation (GtkFrame *frame,
123 GtkAllocation *child_allocation);
124 static void gtk_frame_real_compute_child_allocation (GtkFrame *frame,
125 GtkAllocation *child_allocation);
128 static void gtk_frame_buildable_init (GtkBuildableIface *iface);
129 static void gtk_frame_buildable_add_child (GtkBuildable *buildable,
134 static void gtk_frame_get_preferred_width (GtkWidget *widget,
137 static void gtk_frame_get_preferred_height (GtkWidget *widget,
140 static void gtk_frame_get_preferred_height_for_width(GtkWidget *layout,
142 gint *minimum_height,
143 gint *natural_height);
144 static void gtk_frame_get_preferred_width_for_height(GtkWidget *layout,
146 gint *minimum_height,
147 gint *natural_height);
150 G_DEFINE_TYPE_WITH_CODE (GtkFrame, gtk_frame, GTK_TYPE_BIN,
151 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
152 gtk_frame_buildable_init))
155 gtk_frame_class_init (GtkFrameClass *class)
157 GObjectClass *gobject_class;
158 GtkWidgetClass *widget_class;
159 GtkContainerClass *container_class;
161 gobject_class = (GObjectClass*) class;
162 widget_class = GTK_WIDGET_CLASS (class);
163 container_class = GTK_CONTAINER_CLASS (class);
165 gobject_class->set_property = gtk_frame_set_property;
166 gobject_class->get_property = gtk_frame_get_property;
168 g_object_class_install_property (gobject_class,
170 g_param_spec_string ("label",
172 P_("Text of the frame's label"),
175 GTK_PARAM_WRITABLE));
176 g_object_class_install_property (gobject_class,
178 g_param_spec_float ("label-xalign",
180 P_("The horizontal alignment of the label"),
184 GTK_PARAM_READWRITE));
185 g_object_class_install_property (gobject_class,
187 g_param_spec_float ("label-yalign",
189 P_("The vertical alignment of the label"),
193 GTK_PARAM_READWRITE));
194 g_object_class_install_property (gobject_class,
196 g_param_spec_enum ("shadow-type",
198 P_("Appearance of the frame border"),
199 GTK_TYPE_SHADOW_TYPE,
200 GTK_SHADOW_ETCHED_IN,
201 GTK_PARAM_READWRITE));
203 g_object_class_install_property (gobject_class,
205 g_param_spec_object ("label-widget",
207 P_("A widget to display in place of the usual frame label"),
209 GTK_PARAM_READWRITE));
211 widget_class->draw = gtk_frame_draw;
212 widget_class->size_allocate = gtk_frame_size_allocate;
213 widget_class->get_preferred_width = gtk_frame_get_preferred_width;
214 widget_class->get_preferred_height = gtk_frame_get_preferred_height;
215 widget_class->get_preferred_height_for_width = gtk_frame_get_preferred_height_for_width;
216 widget_class->get_preferred_width_for_height = gtk_frame_get_preferred_width_for_height;
218 container_class->remove = gtk_frame_remove;
219 container_class->forall = gtk_frame_forall;
220 container_class->get_path_for_child = gtk_frame_get_path_for_child;
222 class->compute_child_allocation = gtk_frame_real_compute_child_allocation;
224 g_type_class_add_private (class, sizeof (GtkFramePrivate));
226 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_FRAME_ACCESSIBLE);
230 gtk_frame_buildable_init (GtkBuildableIface *iface)
232 iface->add_child = gtk_frame_buildable_add_child;
236 gtk_frame_buildable_add_child (GtkBuildable *buildable,
241 if (type && strcmp (type, "label") == 0)
242 gtk_frame_set_label_widget (GTK_FRAME (buildable), GTK_WIDGET (child));
244 gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
246 GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_FRAME (buildable), type);
250 gtk_frame_init (GtkFrame *frame)
252 GtkFramePrivate *priv;
253 GtkStyleContext *context;
255 frame->priv = G_TYPE_INSTANCE_GET_PRIVATE (frame,
260 priv->label_widget = NULL;
261 priv->shadow_type = GTK_SHADOW_ETCHED_IN;
262 priv->label_xalign = 0.0;
263 priv->label_yalign = 0.5;
265 context = gtk_widget_get_style_context (GTK_WIDGET (frame));
266 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
270 gtk_frame_set_property (GObject *object,
275 GtkFrame *frame = GTK_FRAME (object);
276 GtkFramePrivate *priv = frame->priv;
281 gtk_frame_set_label (frame, g_value_get_string (value));
283 case PROP_LABEL_XALIGN:
284 gtk_frame_set_label_align (frame, g_value_get_float (value),
287 case PROP_LABEL_YALIGN:
288 gtk_frame_set_label_align (frame, priv->label_xalign,
289 g_value_get_float (value));
291 case PROP_SHADOW_TYPE:
292 gtk_frame_set_shadow_type (frame, g_value_get_enum (value));
294 case PROP_LABEL_WIDGET:
295 gtk_frame_set_label_widget (frame, g_value_get_object (value));
298 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
304 gtk_frame_get_property (GObject *object,
309 GtkFrame *frame = GTK_FRAME (object);
310 GtkFramePrivate *priv = frame->priv;
315 g_value_set_string (value, gtk_frame_get_label (frame));
317 case PROP_LABEL_XALIGN:
318 g_value_set_float (value, priv->label_xalign);
320 case PROP_LABEL_YALIGN:
321 g_value_set_float (value, priv->label_yalign);
323 case PROP_SHADOW_TYPE:
324 g_value_set_enum (value, priv->shadow_type);
326 case PROP_LABEL_WIDGET:
327 g_value_set_object (value,
329 G_OBJECT (priv->label_widget) : NULL);
332 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
339 * @label: the text to use as the label of the frame
341 * Creates a new #GtkFrame, with optional label @label.
342 * If @label is %NULL, the label is omitted.
344 * Return value: a new #GtkFrame widget
347 gtk_frame_new (const gchar *label)
349 return g_object_new (GTK_TYPE_FRAME, "label", label, NULL);
353 gtk_frame_remove (GtkContainer *container,
356 GtkFrame *frame = GTK_FRAME (container);
357 GtkFramePrivate *priv = frame->priv;
359 if (priv->label_widget == child)
360 gtk_frame_set_label_widget (frame, NULL);
362 GTK_CONTAINER_CLASS (gtk_frame_parent_class)->remove (container, child);
366 gtk_frame_forall (GtkContainer *container,
367 gboolean include_internals,
368 GtkCallback callback,
369 gpointer callback_data)
371 GtkBin *bin = GTK_BIN (container);
372 GtkFrame *frame = GTK_FRAME (container);
373 GtkFramePrivate *priv = frame->priv;
376 child = gtk_bin_get_child (bin);
378 (* callback) (child, callback_data);
380 if (priv->label_widget)
381 (* callback) (priv->label_widget, callback_data);
384 static GtkWidgetPath *
385 gtk_frame_get_path_for_child (GtkContainer *container,
388 GtkFramePrivate *priv = GTK_FRAME (container)->priv;
391 path = GTK_CONTAINER_CLASS (gtk_frame_parent_class)->get_path_for_child (container, child);
393 if (child == priv->label_widget)
394 gtk_widget_path_iter_add_class (path,
395 gtk_widget_path_length (path) - 2,
396 GTK_STYLE_CLASS_FRAME);
402 * gtk_frame_set_label:
403 * @frame: a #GtkFrame
404 * @label: (allow-none): the text to use as the label of the frame
406 * Sets the text of the label. If @label is %NULL,
407 * the current label is removed.
410 gtk_frame_set_label (GtkFrame *frame,
413 g_return_if_fail (GTK_IS_FRAME (frame));
417 gtk_frame_set_label_widget (frame, NULL);
421 GtkWidget *child = gtk_label_new (label);
422 gtk_widget_show (child);
424 gtk_frame_set_label_widget (frame, child);
429 * gtk_frame_get_label:
430 * @frame: a #GtkFrame
432 * If the frame's label widget is a #GtkLabel, returns the
433 * text in the label widget. (The frame will have a #GtkLabel
434 * for the label widget if a non-%NULL argument was passed
435 * to gtk_frame_new().)
437 * Return value: the text in the label, or %NULL if there
438 * was no label widget or the lable widget was not
439 * a #GtkLabel. This string is owned by GTK+ and
440 * must not be modified or freed.
443 gtk_frame_get_label (GtkFrame *frame)
445 GtkFramePrivate *priv;
447 g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
451 if (GTK_IS_LABEL (priv->label_widget))
452 return gtk_label_get_text (GTK_LABEL (priv->label_widget));
458 * gtk_frame_set_label_widget:
459 * @frame: a #GtkFrame
460 * @label_widget: the new label widget
462 * Sets the label widget for the frame. This is the widget that
463 * will appear embedded in the top edge of the frame as a
467 gtk_frame_set_label_widget (GtkFrame *frame,
468 GtkWidget *label_widget)
470 GtkFramePrivate *priv;
471 gboolean need_resize = FALSE;
473 g_return_if_fail (GTK_IS_FRAME (frame));
474 g_return_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget));
475 g_return_if_fail (label_widget == NULL || gtk_widget_get_parent (label_widget) == NULL);
479 if (priv->label_widget == label_widget)
482 if (priv->label_widget)
484 need_resize = gtk_widget_get_visible (priv->label_widget);
485 gtk_widget_unparent (priv->label_widget);
488 priv->label_widget = label_widget;
492 priv->label_widget = label_widget;
493 gtk_widget_set_parent (label_widget, GTK_WIDGET (frame));
494 need_resize |= gtk_widget_get_visible (label_widget);
497 if (gtk_widget_get_visible (GTK_WIDGET (frame)) && need_resize)
498 gtk_widget_queue_resize (GTK_WIDGET (frame));
500 g_object_freeze_notify (G_OBJECT (frame));
501 g_object_notify (G_OBJECT (frame), "label-widget");
502 g_object_notify (G_OBJECT (frame), "label");
503 g_object_thaw_notify (G_OBJECT (frame));
507 * gtk_frame_get_label_widget:
508 * @frame: a #GtkFrame
510 * Retrieves the label widget for the frame. See
511 * gtk_frame_set_label_widget().
513 * Return value: (transfer none): the label widget, or %NULL if there is none.
516 gtk_frame_get_label_widget (GtkFrame *frame)
518 g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
520 return frame->priv->label_widget;
524 * gtk_frame_set_label_align:
525 * @frame: a #GtkFrame
526 * @xalign: The position of the label along the top edge
527 * of the widget. A value of 0.0 represents left alignment;
528 * 1.0 represents right alignment.
529 * @yalign: The y alignment of the label. A value of 0.0 aligns under
530 * the frame; 1.0 aligns above the frame. If the values are exactly
531 * 0.0 or 1.0 the gap in the frame won't be painted because the label
532 * will be completely above or below the frame.
534 * Sets the alignment of the frame widget's label. The
535 * default values for a newly created frame are 0.0 and 0.5.
538 gtk_frame_set_label_align (GtkFrame *frame,
542 GtkFramePrivate *priv;
544 g_return_if_fail (GTK_IS_FRAME (frame));
548 xalign = CLAMP (xalign, 0.0, 1.0);
549 yalign = CLAMP (yalign, 0.0, 1.0);
551 g_object_freeze_notify (G_OBJECT (frame));
552 if (xalign != priv->label_xalign)
554 priv->label_xalign = xalign;
555 g_object_notify (G_OBJECT (frame), "label-xalign");
558 if (yalign != priv->label_yalign)
560 priv->label_yalign = yalign;
561 g_object_notify (G_OBJECT (frame), "label-yalign");
564 g_object_thaw_notify (G_OBJECT (frame));
565 gtk_widget_queue_resize (GTK_WIDGET (frame));
569 * gtk_frame_get_label_align:
570 * @frame: a #GtkFrame
571 * @xalign: (out) (allow-none): location to store X alignment of
572 * frame's label, or %NULL
573 * @yalign: (out) (allow-none): location to store X alignment of
574 * frame's label, or %NULL
576 * Retrieves the X and Y alignment of the frame's label. See
577 * gtk_frame_set_label_align().
580 gtk_frame_get_label_align (GtkFrame *frame,
584 GtkFramePrivate *priv;
586 g_return_if_fail (GTK_IS_FRAME (frame));
591 *xalign = priv->label_xalign;
593 *yalign = priv->label_yalign;
597 * gtk_frame_set_shadow_type:
598 * @frame: a #GtkFrame
599 * @type: the new #GtkShadowType
601 * Sets the shadow type for @frame.
604 gtk_frame_set_shadow_type (GtkFrame *frame,
607 GtkFramePrivate *priv;
610 g_return_if_fail (GTK_IS_FRAME (frame));
614 if ((GtkShadowType) priv->shadow_type != type)
616 widget = GTK_WIDGET (frame);
617 priv->shadow_type = type;
618 g_object_notify (G_OBJECT (frame), "shadow-type");
620 if (gtk_widget_is_drawable (widget))
622 gtk_widget_queue_draw (widget);
625 gtk_widget_queue_resize (widget);
630 * gtk_frame_get_shadow_type:
631 * @frame: a #GtkFrame
633 * Retrieves the shadow type of the frame. See
634 * gtk_frame_set_shadow_type().
636 * Return value: the current shadow type of the frame.
639 gtk_frame_get_shadow_type (GtkFrame *frame)
641 g_return_val_if_fail (GTK_IS_FRAME (frame), GTK_SHADOW_ETCHED_IN);
643 return frame->priv->shadow_type;
647 get_padding_and_border (GtkFrame *frame,
650 GtkStyleContext *context;
653 context = gtk_widget_get_style_context (GTK_WIDGET (frame));
654 state = gtk_widget_get_state_flags (GTK_WIDGET (frame));
656 gtk_style_context_get_padding (context, state, border);
658 if (frame->priv->shadow_type != GTK_SHADOW_NONE)
662 gtk_style_context_get_border (context, state, &tmp);
663 border->top += tmp.top;
664 border->right += tmp.right;
665 border->bottom += tmp.bottom;
666 border->left += tmp.left;
671 gtk_frame_draw (GtkWidget *widget,
675 GtkFramePrivate *priv;
676 GtkStyleContext *context;
677 gint x, y, width, height;
678 GtkAllocation allocation;
681 frame = GTK_FRAME (widget);
684 gtk_widget_get_allocation (widget, &allocation);
685 get_padding_and_border (frame, &padding);
686 context = gtk_widget_get_style_context (widget);
688 x = priv->child_allocation.x - allocation.x - padding.left;
689 y = priv->child_allocation.y - allocation.y - padding.top;
690 width = priv->child_allocation.width + padding.left + padding.right;
691 height = priv->child_allocation.height + padding.top + padding.bottom;
693 if (priv->shadow_type != GTK_SHADOW_NONE)
695 if (priv->label_widget)
701 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
702 xalign = priv->label_xalign;
704 xalign = 1 - priv->label_xalign;
706 height_extra = MAX (0, priv->label_allocation.height - padding.top)
707 - priv->label_yalign * priv->label_allocation.height;
709 height += height_extra;
711 x2 = padding.left + (priv->child_allocation.width - priv->label_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
712 /* If the label is completely over or under the frame we can omit the gap */
713 if (priv->label_yalign == 0.0 || priv->label_yalign == 1.0)
714 gtk_render_frame (context, cr, x, y, width, height);
716 gtk_render_frame_gap (context, cr,
719 x2 + priv->label_allocation.width + 2 * LABEL_PAD);
722 gtk_render_frame (context, cr, x, y, width, height);
725 GTK_WIDGET_CLASS (gtk_frame_parent_class)->draw (widget, cr);
731 gtk_frame_size_allocate (GtkWidget *widget,
732 GtkAllocation *allocation)
734 GtkFrame *frame = GTK_FRAME (widget);
735 GtkFramePrivate *priv = frame->priv;
736 GtkBin *bin = GTK_BIN (widget);
737 GtkAllocation new_allocation;
740 gtk_widget_set_allocation (widget, allocation);
742 gtk_frame_compute_child_allocation (frame, &new_allocation);
744 /* If the child allocation changed, that means that the frame is drawn
745 * in a new place, so we must redraw the entire widget.
747 if (gtk_widget_get_mapped (widget))
749 gdk_window_invalidate_rect (gtk_widget_get_window (widget), allocation, FALSE);
752 child = gtk_bin_get_child (bin);
753 if (child && gtk_widget_get_visible (child))
754 gtk_widget_size_allocate (child, &new_allocation);
756 priv->child_allocation = new_allocation;
758 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
761 gint nat_width, width, height;
764 get_padding_and_border (frame, &padding);
766 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
767 xalign = priv->label_xalign;
769 xalign = 1 - priv->label_xalign;
771 gtk_widget_get_preferred_width (priv->label_widget, NULL, &nat_width);
772 width = new_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD;
773 width = MIN (width, nat_width);
775 gtk_widget_get_preferred_height_for_width (priv->label_widget, width,
779 priv->label_allocation.x = priv->child_allocation.x + LABEL_SIDE_PAD +
780 (new_allocation.width - width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_PAD;
782 priv->label_allocation.width = width;
784 priv->label_allocation.y = priv->child_allocation.y - MAX (height, padding.top);
785 priv->label_allocation.height = height;
787 gtk_widget_size_allocate (priv->label_widget, &priv->label_allocation);
792 gtk_frame_compute_child_allocation (GtkFrame *frame,
793 GtkAllocation *child_allocation)
795 g_return_if_fail (GTK_IS_FRAME (frame));
796 g_return_if_fail (child_allocation != NULL);
798 GTK_FRAME_GET_CLASS (frame)->compute_child_allocation (frame, child_allocation);
802 gtk_frame_real_compute_child_allocation (GtkFrame *frame,
803 GtkAllocation *child_allocation)
805 GtkFramePrivate *priv = frame->priv;
806 GtkWidget *widget = GTK_WIDGET (frame);
807 GtkAllocation allocation;
812 gtk_widget_get_allocation (widget, &allocation);
813 get_padding_and_border (frame, &padding);
814 border_width = gtk_container_get_border_width (GTK_CONTAINER (frame));
816 if (priv->label_widget)
818 gint nat_width, width, height;
820 gtk_widget_get_preferred_width (priv->label_widget, NULL, &nat_width);
822 width = allocation.width;
823 width -= 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
824 width -= (border_width * 2) + padding.left + padding.right;
826 width = MIN (width, nat_width);
828 gtk_widget_get_preferred_height_for_width (priv->label_widget, width,
831 top_margin = MAX (height, padding.top);
834 top_margin = padding.top;
836 child_allocation->x = border_width + padding.left;
837 child_allocation->y = border_width + top_margin;
838 child_allocation->width = MAX (1, (gint) (allocation.width - (border_width * 2) -
839 padding.left - padding.right));
840 child_allocation->height = MAX (1, (gint) (allocation.height - child_allocation->y -
841 border_width - padding.bottom));
843 child_allocation->x += allocation.x;
844 child_allocation->y += allocation.y;
848 gtk_frame_get_preferred_size (GtkWidget *request,
849 GtkOrientation orientation,
853 GtkFrame *frame = GTK_FRAME (request);
854 GtkFramePrivate *priv = frame->priv;
856 GtkWidget *widget = GTK_WIDGET (request);
858 GtkBin *bin = GTK_BIN (widget);
859 gint child_min, child_nat;
860 gint minimum, natural;
863 get_padding_and_border (frame, &padding);
864 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
866 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
868 if (orientation == GTK_ORIENTATION_HORIZONTAL)
870 gtk_widget_get_preferred_width (priv->label_widget,
871 &child_min, &child_nat);
872 minimum = child_min + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
873 natural = child_nat + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
877 gtk_widget_get_preferred_height (priv->label_widget,
878 &child_min, &child_nat);
879 minimum = MAX (0, child_min - padding.top);
880 natural = MAX (0, child_nat - padding.top);
889 child = gtk_bin_get_child (bin);
890 if (child && gtk_widget_get_visible (child))
892 if (orientation == GTK_ORIENTATION_HORIZONTAL)
894 gtk_widget_get_preferred_width (child,
895 &child_min, &child_nat);
896 minimum = MAX (minimum, child_min);
897 natural = MAX (natural, child_nat);
901 gtk_widget_get_preferred_height (child,
902 &child_min, &child_nat);
903 minimum += child_min;
904 natural += child_nat;
908 if (orientation == GTK_ORIENTATION_HORIZONTAL)
910 minimum += (border_width * 2) + padding.left + padding.right;
911 natural += (border_width * 2) + padding.left + padding.right;
915 minimum += (border_width * 2) + padding.top + padding.bottom;
916 natural += (border_width * 2) + padding.top + padding.bottom;
920 *minimum_size = minimum;
923 *natural_size = natural;
927 gtk_frame_get_preferred_width (GtkWidget *widget,
931 gtk_frame_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
935 gtk_frame_get_preferred_height (GtkWidget *widget,
939 gtk_frame_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
944 gtk_frame_get_preferred_height_for_width (GtkWidget *request,
946 gint *minimum_height,
947 gint *natural_height)
949 GtkWidget *widget = GTK_WIDGET (request);
951 GtkFrame *frame = GTK_FRAME (widget);
952 GtkFramePrivate *priv = frame->priv;
953 GtkBin *bin = GTK_BIN (widget);
955 gint child_min, child_nat, label_width;
956 gint minimum, natural;
959 get_padding_and_border (frame, &padding);
960 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
962 minimum = (border_width * 2) + padding.top + padding.bottom;
963 natural = (border_width * 2) + padding.top + padding.bottom;
965 width -= (border_width * 2) + padding.left + padding.right;
966 label_width = width - 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
968 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
970 gtk_widget_get_preferred_height_for_width (priv->label_widget,
971 label_width, &child_min, &child_nat);
972 minimum += child_min;
973 natural += child_nat;
976 child = gtk_bin_get_child (bin);
977 if (child && gtk_widget_get_visible (child))
979 gtk_widget_get_preferred_height_for_width (child,
980 width, &child_min, &child_nat);
981 minimum += child_min;
982 natural += child_nat;
986 *minimum_height = minimum;
989 *natural_height = natural;
993 gtk_frame_get_preferred_width_for_height (GtkWidget *widget,
998 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);