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"
34 #include "a11y/gtkframeaccessible.h"
38 * @Short_description: A bin with a decorative frame and optional label
41 * The frame widget is a Bin that surrounds its child
42 * with a decorative frame and an optional label.
43 * If present, the label is drawn in a gap in the
44 * top side of the frame. The position of the
45 * label can be controlled with gtk_frame_set_label_align().
47 * <refsect2 id="GtkFrame-BUILDER-UI">
48 * <title>GtkFrame as GtkBuildable</title>
50 * The GtkFrame implementation of the GtkBuildable interface
51 * supports placing a child in the label position by specifying
52 * "label" as the "type" attribute of a <child> element.
53 * A normal content child can be specified without specifying
54 * a <child> type attribute.
57 * <title>A UI definition fragment with GtkFrame</title>
58 * <programlisting><![CDATA[
59 * <object class="GtkFrame">
60 * <child type="label">
61 * <object class="GtkLabel" id="frame-label"/>
64 * <object class="GtkEntry" id="frame-content"/>
67 * ]]></programlisting>
74 #define LABEL_SIDE_PAD 2
76 struct _GtkFramePrivate
79 GtkWidget *label_widget;
86 GtkAllocation child_allocation;
87 GtkAllocation label_allocation;
99 static void gtk_frame_set_property (GObject *object,
103 static void gtk_frame_get_property (GObject *object,
107 static gboolean gtk_frame_draw (GtkWidget *widget,
109 static void gtk_frame_size_allocate (GtkWidget *widget,
110 GtkAllocation *allocation);
111 static void gtk_frame_remove (GtkContainer *container,
113 static void gtk_frame_forall (GtkContainer *container,
114 gboolean include_internals,
115 GtkCallback callback,
116 gpointer callback_data);
117 static GtkWidgetPath * gtk_frame_get_path_for_child (GtkContainer *container,
120 static void gtk_frame_compute_child_allocation (GtkFrame *frame,
121 GtkAllocation *child_allocation);
122 static void gtk_frame_real_compute_child_allocation (GtkFrame *frame,
123 GtkAllocation *child_allocation);
126 static void gtk_frame_buildable_init (GtkBuildableIface *iface);
127 static void gtk_frame_buildable_add_child (GtkBuildable *buildable,
132 static void gtk_frame_get_preferred_width (GtkWidget *widget,
135 static void gtk_frame_get_preferred_height (GtkWidget *widget,
138 static void gtk_frame_get_preferred_height_for_width(GtkWidget *layout,
140 gint *minimum_height,
141 gint *natural_height);
142 static void gtk_frame_get_preferred_width_for_height(GtkWidget *layout,
144 gint *minimum_height,
145 gint *natural_height);
148 G_DEFINE_TYPE_WITH_CODE (GtkFrame, gtk_frame, GTK_TYPE_BIN,
149 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
150 gtk_frame_buildable_init))
153 gtk_frame_class_init (GtkFrameClass *class)
155 GObjectClass *gobject_class;
156 GtkWidgetClass *widget_class;
157 GtkContainerClass *container_class;
159 gobject_class = (GObjectClass*) class;
160 widget_class = GTK_WIDGET_CLASS (class);
161 container_class = GTK_CONTAINER_CLASS (class);
163 gobject_class->set_property = gtk_frame_set_property;
164 gobject_class->get_property = gtk_frame_get_property;
166 g_object_class_install_property (gobject_class,
168 g_param_spec_string ("label",
170 P_("Text of the frame's label"),
173 GTK_PARAM_WRITABLE));
174 g_object_class_install_property (gobject_class,
176 g_param_spec_float ("label-xalign",
178 P_("The horizontal alignment of the label"),
182 GTK_PARAM_READWRITE));
183 g_object_class_install_property (gobject_class,
185 g_param_spec_float ("label-yalign",
187 P_("The vertical alignment of the label"),
191 GTK_PARAM_READWRITE));
192 g_object_class_install_property (gobject_class,
194 g_param_spec_enum ("shadow-type",
196 P_("Appearance of the frame border"),
197 GTK_TYPE_SHADOW_TYPE,
198 GTK_SHADOW_ETCHED_IN,
199 GTK_PARAM_READWRITE));
201 g_object_class_install_property (gobject_class,
203 g_param_spec_object ("label-widget",
205 P_("A widget to display in place of the usual frame label"),
207 GTK_PARAM_READWRITE));
209 widget_class->draw = gtk_frame_draw;
210 widget_class->size_allocate = gtk_frame_size_allocate;
211 widget_class->get_preferred_width = gtk_frame_get_preferred_width;
212 widget_class->get_preferred_height = gtk_frame_get_preferred_height;
213 widget_class->get_preferred_height_for_width = gtk_frame_get_preferred_height_for_width;
214 widget_class->get_preferred_width_for_height = gtk_frame_get_preferred_width_for_height;
216 container_class->remove = gtk_frame_remove;
217 container_class->forall = gtk_frame_forall;
218 container_class->get_path_for_child = gtk_frame_get_path_for_child;
220 class->compute_child_allocation = gtk_frame_real_compute_child_allocation;
222 g_type_class_add_private (class, sizeof (GtkFramePrivate));
224 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_FRAME_ACCESSIBLE);
228 gtk_frame_buildable_init (GtkBuildableIface *iface)
230 iface->add_child = gtk_frame_buildable_add_child;
234 gtk_frame_buildable_add_child (GtkBuildable *buildable,
239 if (type && strcmp (type, "label") == 0)
240 gtk_frame_set_label_widget (GTK_FRAME (buildable), GTK_WIDGET (child));
242 gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
244 GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_FRAME (buildable), type);
248 gtk_frame_init (GtkFrame *frame)
250 GtkFramePrivate *priv;
251 GtkStyleContext *context;
253 frame->priv = G_TYPE_INSTANCE_GET_PRIVATE (frame,
258 priv->label_widget = NULL;
259 priv->shadow_type = GTK_SHADOW_ETCHED_IN;
260 priv->label_xalign = 0.0;
261 priv->label_yalign = 0.5;
263 context = gtk_widget_get_style_context (GTK_WIDGET (frame));
264 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
268 gtk_frame_set_property (GObject *object,
273 GtkFrame *frame = GTK_FRAME (object);
274 GtkFramePrivate *priv = frame->priv;
279 gtk_frame_set_label (frame, g_value_get_string (value));
281 case PROP_LABEL_XALIGN:
282 gtk_frame_set_label_align (frame, g_value_get_float (value),
285 case PROP_LABEL_YALIGN:
286 gtk_frame_set_label_align (frame, priv->label_xalign,
287 g_value_get_float (value));
289 case PROP_SHADOW_TYPE:
290 gtk_frame_set_shadow_type (frame, g_value_get_enum (value));
292 case PROP_LABEL_WIDGET:
293 gtk_frame_set_label_widget (frame, g_value_get_object (value));
296 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
302 gtk_frame_get_property (GObject *object,
307 GtkFrame *frame = GTK_FRAME (object);
308 GtkFramePrivate *priv = frame->priv;
313 g_value_set_string (value, gtk_frame_get_label (frame));
315 case PROP_LABEL_XALIGN:
316 g_value_set_float (value, priv->label_xalign);
318 case PROP_LABEL_YALIGN:
319 g_value_set_float (value, priv->label_yalign);
321 case PROP_SHADOW_TYPE:
322 g_value_set_enum (value, priv->shadow_type);
324 case PROP_LABEL_WIDGET:
325 g_value_set_object (value,
327 G_OBJECT (priv->label_widget) : NULL);
330 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
337 * @label: the text to use as the label of the frame
339 * Creates a new #GtkFrame, with optional label @label.
340 * If @label is %NULL, the label is omitted.
342 * Return value: a new #GtkFrame widget
345 gtk_frame_new (const gchar *label)
347 return g_object_new (GTK_TYPE_FRAME, "label", label, NULL);
351 gtk_frame_remove (GtkContainer *container,
354 GtkFrame *frame = GTK_FRAME (container);
355 GtkFramePrivate *priv = frame->priv;
357 if (priv->label_widget == child)
358 gtk_frame_set_label_widget (frame, NULL);
360 GTK_CONTAINER_CLASS (gtk_frame_parent_class)->remove (container, child);
364 gtk_frame_forall (GtkContainer *container,
365 gboolean include_internals,
366 GtkCallback callback,
367 gpointer callback_data)
369 GtkBin *bin = GTK_BIN (container);
370 GtkFrame *frame = GTK_FRAME (container);
371 GtkFramePrivate *priv = frame->priv;
374 child = gtk_bin_get_child (bin);
376 (* callback) (child, callback_data);
378 if (priv->label_widget)
379 (* callback) (priv->label_widget, callback_data);
382 static GtkWidgetPath *
383 gtk_frame_get_path_for_child (GtkContainer *container,
386 GtkFramePrivate *priv = GTK_FRAME (container)->priv;
389 path = GTK_CONTAINER_CLASS (gtk_frame_parent_class)->get_path_for_child (container, child);
391 if (child == priv->label_widget)
392 gtk_widget_path_iter_add_class (path,
393 gtk_widget_path_length (path) - 2,
394 GTK_STYLE_CLASS_FRAME);
400 * gtk_frame_set_label:
401 * @frame: a #GtkFrame
402 * @label: (allow-none): the text to use as the label of the frame
404 * Sets the text of the label. If @label is %NULL,
405 * the current label is removed.
408 gtk_frame_set_label (GtkFrame *frame,
411 g_return_if_fail (GTK_IS_FRAME (frame));
415 gtk_frame_set_label_widget (frame, NULL);
419 GtkWidget *child = gtk_label_new (label);
420 gtk_widget_show (child);
422 gtk_frame_set_label_widget (frame, child);
427 * gtk_frame_get_label:
428 * @frame: a #GtkFrame
430 * If the frame's label widget is a #GtkLabel, returns the
431 * text in the label widget. (The frame will have a #GtkLabel
432 * for the label widget if a non-%NULL argument was passed
433 * to gtk_frame_new().)
435 * Return value: the text in the label, or %NULL if there
436 * was no label widget or the lable widget was not
437 * a #GtkLabel. This string is owned by GTK+ and
438 * must not be modified or freed.
441 gtk_frame_get_label (GtkFrame *frame)
443 GtkFramePrivate *priv;
445 g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
449 if (GTK_IS_LABEL (priv->label_widget))
450 return gtk_label_get_text (GTK_LABEL (priv->label_widget));
456 * gtk_frame_set_label_widget:
457 * @frame: a #GtkFrame
458 * @label_widget: the new label widget
460 * Sets the label widget for the frame. This is the widget that
461 * will appear embedded in the top edge of the frame as a
465 gtk_frame_set_label_widget (GtkFrame *frame,
466 GtkWidget *label_widget)
468 GtkFramePrivate *priv;
469 gboolean need_resize = FALSE;
471 g_return_if_fail (GTK_IS_FRAME (frame));
472 g_return_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget));
473 g_return_if_fail (label_widget == NULL || gtk_widget_get_parent (label_widget) == NULL);
477 if (priv->label_widget == label_widget)
480 if (priv->label_widget)
482 need_resize = gtk_widget_get_visible (priv->label_widget);
483 gtk_widget_unparent (priv->label_widget);
486 priv->label_widget = label_widget;
490 priv->label_widget = label_widget;
491 gtk_widget_set_parent (label_widget, GTK_WIDGET (frame));
492 need_resize |= gtk_widget_get_visible (label_widget);
495 if (gtk_widget_get_visible (GTK_WIDGET (frame)) && need_resize)
496 gtk_widget_queue_resize (GTK_WIDGET (frame));
498 g_object_freeze_notify (G_OBJECT (frame));
499 g_object_notify (G_OBJECT (frame), "label-widget");
500 g_object_notify (G_OBJECT (frame), "label");
501 g_object_thaw_notify (G_OBJECT (frame));
505 * gtk_frame_get_label_widget:
506 * @frame: a #GtkFrame
508 * Retrieves the label widget for the frame. See
509 * gtk_frame_set_label_widget().
511 * Return value: (transfer none): the label widget, or %NULL if there is none.
514 gtk_frame_get_label_widget (GtkFrame *frame)
516 g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
518 return frame->priv->label_widget;
522 * gtk_frame_set_label_align:
523 * @frame: a #GtkFrame
524 * @xalign: The position of the label along the top edge
525 * of the widget. A value of 0.0 represents left alignment;
526 * 1.0 represents right alignment.
527 * @yalign: The y alignment of the label. A value of 0.0 aligns under
528 * the frame; 1.0 aligns above the frame. If the values are exactly
529 * 0.0 or 1.0 the gap in the frame won't be painted because the label
530 * will be completely above or below the frame.
532 * Sets the alignment of the frame widget's label. The
533 * default values for a newly created frame are 0.0 and 0.5.
536 gtk_frame_set_label_align (GtkFrame *frame,
540 GtkFramePrivate *priv;
542 g_return_if_fail (GTK_IS_FRAME (frame));
546 xalign = CLAMP (xalign, 0.0, 1.0);
547 yalign = CLAMP (yalign, 0.0, 1.0);
549 g_object_freeze_notify (G_OBJECT (frame));
550 if (xalign != priv->label_xalign)
552 priv->label_xalign = xalign;
553 g_object_notify (G_OBJECT (frame), "label-xalign");
556 if (yalign != priv->label_yalign)
558 priv->label_yalign = yalign;
559 g_object_notify (G_OBJECT (frame), "label-yalign");
562 g_object_thaw_notify (G_OBJECT (frame));
563 gtk_widget_queue_resize (GTK_WIDGET (frame));
567 * gtk_frame_get_label_align:
568 * @frame: a #GtkFrame
569 * @xalign: (out) (allow-none): location to store X alignment of
570 * frame's label, or %NULL
571 * @yalign: (out) (allow-none): location to store X alignment of
572 * frame's label, or %NULL
574 * Retrieves the X and Y alignment of the frame's label. See
575 * gtk_frame_set_label_align().
578 gtk_frame_get_label_align (GtkFrame *frame,
582 GtkFramePrivate *priv;
584 g_return_if_fail (GTK_IS_FRAME (frame));
589 *xalign = priv->label_xalign;
591 *yalign = priv->label_yalign;
595 * gtk_frame_set_shadow_type:
596 * @frame: a #GtkFrame
597 * @type: the new #GtkShadowType
599 * Sets the shadow type for @frame.
602 gtk_frame_set_shadow_type (GtkFrame *frame,
605 GtkFramePrivate *priv;
608 g_return_if_fail (GTK_IS_FRAME (frame));
612 if ((GtkShadowType) priv->shadow_type != type)
614 widget = GTK_WIDGET (frame);
615 priv->shadow_type = type;
616 g_object_notify (G_OBJECT (frame), "shadow-type");
618 if (gtk_widget_is_drawable (widget))
620 gtk_widget_queue_draw (widget);
623 gtk_widget_queue_resize (widget);
628 * gtk_frame_get_shadow_type:
629 * @frame: a #GtkFrame
631 * Retrieves the shadow type of the frame. See
632 * gtk_frame_set_shadow_type().
634 * Return value: the current shadow type of the frame.
637 gtk_frame_get_shadow_type (GtkFrame *frame)
639 g_return_val_if_fail (GTK_IS_FRAME (frame), GTK_SHADOW_ETCHED_IN);
641 return frame->priv->shadow_type;
645 get_padding_and_border (GtkFrame *frame,
648 GtkStyleContext *context;
651 context = gtk_widget_get_style_context (GTK_WIDGET (frame));
652 state = gtk_widget_get_state_flags (GTK_WIDGET (frame));
654 gtk_style_context_get_padding (context, state, border);
656 if (frame->priv->shadow_type != GTK_SHADOW_NONE)
660 gtk_style_context_get_border (context, state, &tmp);
661 border->top += tmp.top;
662 border->right += tmp.right;
663 border->bottom += tmp.bottom;
664 border->left += tmp.left;
669 gtk_frame_draw (GtkWidget *widget,
673 GtkFramePrivate *priv;
674 GtkStyleContext *context;
675 gint x, y, width, height;
676 GtkAllocation allocation;
679 frame = GTK_FRAME (widget);
682 gtk_widget_get_allocation (widget, &allocation);
683 get_padding_and_border (frame, &padding);
684 context = gtk_widget_get_style_context (widget);
686 x = priv->child_allocation.x - allocation.x - padding.left;
687 y = priv->child_allocation.y - allocation.y - padding.top;
688 width = priv->child_allocation.width + padding.left + padding.right;
689 height = priv->child_allocation.height + padding.top + padding.bottom;
691 if (priv->shadow_type != GTK_SHADOW_NONE)
693 if (priv->label_widget)
699 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
700 xalign = priv->label_xalign;
702 xalign = 1 - priv->label_xalign;
704 height_extra = MAX (0, priv->label_allocation.height - padding.top)
705 - priv->label_yalign * priv->label_allocation.height;
707 height += height_extra;
709 x2 = padding.left + (priv->child_allocation.width - priv->label_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
710 /* If the label is completely over or under the frame we can omit the gap */
711 if (priv->label_yalign == 0.0 || priv->label_yalign == 1.0)
712 gtk_render_frame (context, cr, x, y, width, height);
714 gtk_render_frame_gap (context, cr,
717 x2 + priv->label_allocation.width + 2 * LABEL_PAD);
720 gtk_render_frame (context, cr, x, y, width, height);
723 GTK_WIDGET_CLASS (gtk_frame_parent_class)->draw (widget, cr);
729 gtk_frame_size_allocate (GtkWidget *widget,
730 GtkAllocation *allocation)
732 GtkFrame *frame = GTK_FRAME (widget);
733 GtkFramePrivate *priv = frame->priv;
734 GtkBin *bin = GTK_BIN (widget);
735 GtkAllocation new_allocation;
738 gtk_widget_set_allocation (widget, allocation);
740 gtk_frame_compute_child_allocation (frame, &new_allocation);
742 /* If the child allocation changed, that means that the frame is drawn
743 * in a new place, so we must redraw the entire widget.
745 if (gtk_widget_get_mapped (widget))
747 gdk_window_invalidate_rect (gtk_widget_get_window (widget), allocation, FALSE);
750 child = gtk_bin_get_child (bin);
751 if (child && gtk_widget_get_visible (child))
752 gtk_widget_size_allocate (child, &new_allocation);
754 priv->child_allocation = new_allocation;
756 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
759 gint nat_width, width, height;
762 get_padding_and_border (frame, &padding);
764 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
765 xalign = priv->label_xalign;
767 xalign = 1 - priv->label_xalign;
769 gtk_widget_get_preferred_width (priv->label_widget, NULL, &nat_width);
770 width = new_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD;
771 width = MIN (width, nat_width);
773 gtk_widget_get_preferred_height_for_width (priv->label_widget, width,
777 priv->label_allocation.x = priv->child_allocation.x + LABEL_SIDE_PAD +
778 (new_allocation.width - width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_PAD;
780 priv->label_allocation.width = width;
782 priv->label_allocation.y = priv->child_allocation.y - MAX (height, padding.top);
783 priv->label_allocation.height = height;
785 gtk_widget_size_allocate (priv->label_widget, &priv->label_allocation);
790 gtk_frame_compute_child_allocation (GtkFrame *frame,
791 GtkAllocation *child_allocation)
793 g_return_if_fail (GTK_IS_FRAME (frame));
794 g_return_if_fail (child_allocation != NULL);
796 GTK_FRAME_GET_CLASS (frame)->compute_child_allocation (frame, child_allocation);
800 gtk_frame_real_compute_child_allocation (GtkFrame *frame,
801 GtkAllocation *child_allocation)
803 GtkFramePrivate *priv = frame->priv;
804 GtkWidget *widget = GTK_WIDGET (frame);
805 GtkAllocation allocation;
810 gtk_widget_get_allocation (widget, &allocation);
811 get_padding_and_border (frame, &padding);
812 border_width = gtk_container_get_border_width (GTK_CONTAINER (frame));
814 if (priv->label_widget)
816 gint nat_width, width, height;
818 gtk_widget_get_preferred_width (priv->label_widget, NULL, &nat_width);
820 width = allocation.width;
821 width -= 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
822 width -= (border_width * 2) + padding.left + padding.right;
824 width = MIN (width, nat_width);
826 gtk_widget_get_preferred_height_for_width (priv->label_widget, width,
829 top_margin = MAX (height, padding.top);
832 top_margin = padding.top;
834 child_allocation->x = border_width + padding.left;
835 child_allocation->y = border_width + top_margin;
836 child_allocation->width = MAX (1, (gint) (allocation.width - (border_width * 2) -
837 padding.left - padding.right));
838 child_allocation->height = MAX (1, (gint) (allocation.height - child_allocation->y -
839 border_width - padding.bottom));
841 child_allocation->x += allocation.x;
842 child_allocation->y += allocation.y;
846 gtk_frame_get_preferred_size (GtkWidget *request,
847 GtkOrientation orientation,
851 GtkFrame *frame = GTK_FRAME (request);
852 GtkFramePrivate *priv = frame->priv;
854 GtkWidget *widget = GTK_WIDGET (request);
856 GtkBin *bin = GTK_BIN (widget);
857 gint child_min, child_nat;
858 gint minimum, natural;
861 get_padding_and_border (frame, &padding);
862 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
864 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
866 if (orientation == GTK_ORIENTATION_HORIZONTAL)
868 gtk_widget_get_preferred_width (priv->label_widget,
869 &child_min, &child_nat);
870 minimum = child_min + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
871 natural = child_nat + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
875 gtk_widget_get_preferred_height (priv->label_widget,
876 &child_min, &child_nat);
877 minimum = MAX (0, child_min - padding.top);
878 natural = MAX (0, child_nat - padding.top);
887 child = gtk_bin_get_child (bin);
888 if (child && gtk_widget_get_visible (child))
890 if (orientation == GTK_ORIENTATION_HORIZONTAL)
892 gtk_widget_get_preferred_width (child,
893 &child_min, &child_nat);
894 minimum = MAX (minimum, child_min);
895 natural = MAX (natural, child_nat);
899 gtk_widget_get_preferred_height (child,
900 &child_min, &child_nat);
901 minimum += child_min;
902 natural += child_nat;
906 if (orientation == GTK_ORIENTATION_HORIZONTAL)
908 minimum += (border_width * 2) + padding.left + padding.right;
909 natural += (border_width * 2) + padding.left + padding.right;
913 minimum += (border_width * 2) + padding.top + padding.bottom;
914 natural += (border_width * 2) + padding.top + padding.bottom;
918 *minimum_size = minimum;
921 *natural_size = natural;
925 gtk_frame_get_preferred_width (GtkWidget *widget,
929 gtk_frame_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
933 gtk_frame_get_preferred_height (GtkWidget *widget,
937 gtk_frame_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
942 gtk_frame_get_preferred_height_for_width (GtkWidget *request,
944 gint *minimum_height,
945 gint *natural_height)
947 GtkWidget *widget = GTK_WIDGET (request);
949 GtkFrame *frame = GTK_FRAME (widget);
950 GtkFramePrivate *priv = frame->priv;
951 GtkBin *bin = GTK_BIN (widget);
953 gint child_min, child_nat, label_width;
954 gint minimum, natural;
957 get_padding_and_border (frame, &padding);
958 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
960 minimum = (border_width * 2) + padding.top + padding.bottom;
961 natural = (border_width * 2) + padding.top + padding.bottom;
963 width -= (border_width * 2) + padding.left + padding.right;
964 label_width = width - 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
966 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
968 gtk_widget_get_preferred_height_for_width (priv->label_widget,
969 label_width, &child_min, &child_nat);
970 minimum += child_min;
971 natural += child_nat;
974 child = gtk_bin_get_child (bin);
975 if (child && gtk_widget_get_visible (child))
977 gtk_widget_get_preferred_height_for_width (child,
978 width, &child_min, &child_nat);
979 minimum += child_min;
980 natural += child_nat;
984 *minimum_height = minimum;
987 *natural_height = natural;
991 gtk_frame_get_preferred_width_for_height (GtkWidget *widget,
996 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);