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;
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;
266 gtk_frame_set_property (GObject *object,
271 GtkFrame *frame = GTK_FRAME (object);
272 GtkFramePrivate *priv = frame->priv;
277 gtk_frame_set_label (frame, g_value_get_string (value));
279 case PROP_LABEL_XALIGN:
280 gtk_frame_set_label_align (frame, g_value_get_float (value),
283 case PROP_LABEL_YALIGN:
284 gtk_frame_set_label_align (frame, priv->label_xalign,
285 g_value_get_float (value));
287 case PROP_SHADOW_TYPE:
288 gtk_frame_set_shadow_type (frame, g_value_get_enum (value));
290 case PROP_LABEL_WIDGET:
291 gtk_frame_set_label_widget (frame, g_value_get_object (value));
294 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
300 gtk_frame_get_property (GObject *object,
305 GtkFrame *frame = GTK_FRAME (object);
306 GtkFramePrivate *priv = frame->priv;
311 g_value_set_string (value, gtk_frame_get_label (frame));
313 case PROP_LABEL_XALIGN:
314 g_value_set_float (value, priv->label_xalign);
316 case PROP_LABEL_YALIGN:
317 g_value_set_float (value, priv->label_yalign);
319 case PROP_SHADOW_TYPE:
320 g_value_set_enum (value, priv->shadow_type);
322 case PROP_LABEL_WIDGET:
323 g_value_set_object (value,
325 G_OBJECT (priv->label_widget) : NULL);
328 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
335 * @label: the text to use as the label of the frame
337 * Creates a new #GtkFrame, with optional label @label.
338 * If @label is %NULL, the label is omitted.
340 * Return value: a new #GtkFrame widget
343 gtk_frame_new (const gchar *label)
345 return g_object_new (GTK_TYPE_FRAME, "label", label, NULL);
349 gtk_frame_remove (GtkContainer *container,
352 GtkFrame *frame = GTK_FRAME (container);
353 GtkFramePrivate *priv = frame->priv;
355 if (priv->label_widget == child)
356 gtk_frame_set_label_widget (frame, NULL);
358 GTK_CONTAINER_CLASS (gtk_frame_parent_class)->remove (container, child);
362 gtk_frame_forall (GtkContainer *container,
363 gboolean include_internals,
364 GtkCallback callback,
365 gpointer callback_data)
367 GtkBin *bin = GTK_BIN (container);
368 GtkFrame *frame = GTK_FRAME (container);
369 GtkFramePrivate *priv = frame->priv;
372 child = gtk_bin_get_child (bin);
374 (* callback) (child, callback_data);
376 if (priv->label_widget)
377 (* callback) (priv->label_widget, callback_data);
380 static GtkWidgetPath *
381 gtk_frame_get_path_for_child (GtkContainer *container,
384 GtkFramePrivate *priv = GTK_FRAME (container)->priv;
387 path = GTK_CONTAINER_CLASS (gtk_frame_parent_class)->get_path_for_child (container, child);
389 if (child == priv->label_widget)
390 gtk_widget_path_iter_add_class (path,
391 gtk_widget_path_length (path) - 2,
392 GTK_STYLE_CLASS_FRAME);
398 * gtk_frame_set_label:
399 * @frame: a #GtkFrame
400 * @label: (allow-none): the text to use as the label of the frame
402 * Sets the text of the label. If @label is %NULL,
403 * the current label is removed.
406 gtk_frame_set_label (GtkFrame *frame,
409 g_return_if_fail (GTK_IS_FRAME (frame));
413 gtk_frame_set_label_widget (frame, NULL);
417 GtkWidget *child = gtk_label_new (label);
418 gtk_widget_show (child);
420 gtk_frame_set_label_widget (frame, child);
425 * gtk_frame_get_label:
426 * @frame: a #GtkFrame
428 * If the frame's label widget is a #GtkLabel, returns the
429 * text in the label widget. (The frame will have a #GtkLabel
430 * for the label widget if a non-%NULL argument was passed
431 * to gtk_frame_new().)
433 * Return value: the text in the label, or %NULL if there
434 * was no label widget or the lable widget was not
435 * a #GtkLabel. This string is owned by GTK+ and
436 * must not be modified or freed.
439 gtk_frame_get_label (GtkFrame *frame)
441 GtkFramePrivate *priv;
443 g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
447 if (GTK_IS_LABEL (priv->label_widget))
448 return gtk_label_get_text (GTK_LABEL (priv->label_widget));
454 * gtk_frame_set_label_widget:
455 * @frame: a #GtkFrame
456 * @label_widget: the new label widget
458 * Sets the label widget for the frame. This is the widget that
459 * will appear embedded in the top edge of the frame as a
463 gtk_frame_set_label_widget (GtkFrame *frame,
464 GtkWidget *label_widget)
466 GtkFramePrivate *priv;
467 gboolean need_resize = FALSE;
469 g_return_if_fail (GTK_IS_FRAME (frame));
470 g_return_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget));
471 g_return_if_fail (label_widget == NULL || gtk_widget_get_parent (label_widget) == NULL);
475 if (priv->label_widget == label_widget)
478 if (priv->label_widget)
480 need_resize = gtk_widget_get_visible (priv->label_widget);
481 gtk_widget_unparent (priv->label_widget);
484 priv->label_widget = label_widget;
488 priv->label_widget = label_widget;
489 gtk_widget_set_parent (label_widget, GTK_WIDGET (frame));
490 need_resize |= gtk_widget_get_visible (label_widget);
493 if (gtk_widget_get_visible (GTK_WIDGET (frame)) && need_resize)
494 gtk_widget_queue_resize (GTK_WIDGET (frame));
496 g_object_freeze_notify (G_OBJECT (frame));
497 g_object_notify (G_OBJECT (frame), "label-widget");
498 g_object_notify (G_OBJECT (frame), "label");
499 g_object_thaw_notify (G_OBJECT (frame));
503 * gtk_frame_get_label_widget:
504 * @frame: a #GtkFrame
506 * Retrieves the label widget for the frame. See
507 * gtk_frame_set_label_widget().
509 * Return value: (transfer none): the label widget, or %NULL if there is none.
512 gtk_frame_get_label_widget (GtkFrame *frame)
514 g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
516 return frame->priv->label_widget;
520 * gtk_frame_set_label_align:
521 * @frame: a #GtkFrame
522 * @xalign: The position of the label along the top edge
523 * of the widget. A value of 0.0 represents left alignment;
524 * 1.0 represents right alignment.
525 * @yalign: The y alignment of the label. A value of 0.0 aligns under
526 * the frame; 1.0 aligns above the frame. If the values are exactly
527 * 0.0 or 1.0 the gap in the frame won't be painted because the label
528 * will be completely above or below the frame.
530 * Sets the alignment of the frame widget's label. The
531 * default values for a newly created frame are 0.0 and 0.5.
534 gtk_frame_set_label_align (GtkFrame *frame,
538 GtkFramePrivate *priv;
540 g_return_if_fail (GTK_IS_FRAME (frame));
544 xalign = CLAMP (xalign, 0.0, 1.0);
545 yalign = CLAMP (yalign, 0.0, 1.0);
547 g_object_freeze_notify (G_OBJECT (frame));
548 if (xalign != priv->label_xalign)
550 priv->label_xalign = xalign;
551 g_object_notify (G_OBJECT (frame), "label-xalign");
554 if (yalign != priv->label_yalign)
556 priv->label_yalign = yalign;
557 g_object_notify (G_OBJECT (frame), "label-yalign");
560 g_object_thaw_notify (G_OBJECT (frame));
561 gtk_widget_queue_resize (GTK_WIDGET (frame));
565 * gtk_frame_get_label_align:
566 * @frame: a #GtkFrame
567 * @xalign: (out) (allow-none): location to store X alignment of
568 * frame's label, or %NULL
569 * @yalign: (out) (allow-none): location to store X alignment of
570 * frame's label, or %NULL
572 * Retrieves the X and Y alignment of the frame's label. See
573 * gtk_frame_set_label_align().
576 gtk_frame_get_label_align (GtkFrame *frame,
580 GtkFramePrivate *priv;
582 g_return_if_fail (GTK_IS_FRAME (frame));
587 *xalign = priv->label_xalign;
589 *yalign = priv->label_yalign;
593 * gtk_frame_set_shadow_type:
594 * @frame: a #GtkFrame
595 * @type: the new #GtkShadowType
597 * Sets the shadow type for @frame.
600 gtk_frame_set_shadow_type (GtkFrame *frame,
603 GtkFramePrivate *priv;
606 g_return_if_fail (GTK_IS_FRAME (frame));
610 if ((GtkShadowType) priv->shadow_type != type)
612 widget = GTK_WIDGET (frame);
613 priv->shadow_type = type;
614 g_object_notify (G_OBJECT (frame), "shadow-type");
616 if (gtk_widget_is_drawable (widget))
618 gtk_widget_queue_draw (widget);
621 gtk_widget_queue_resize (widget);
626 * gtk_frame_get_shadow_type:
627 * @frame: a #GtkFrame
629 * Retrieves the shadow type of the frame. See
630 * gtk_frame_set_shadow_type().
632 * Return value: the current shadow type of the frame.
635 gtk_frame_get_shadow_type (GtkFrame *frame)
637 g_return_val_if_fail (GTK_IS_FRAME (frame), GTK_SHADOW_ETCHED_IN);
639 return frame->priv->shadow_type;
643 gtk_frame_draw (GtkWidget *widget,
647 GtkFramePrivate *priv;
648 GtkStyleContext *context;
650 gint x, y, width, height;
651 GtkAllocation allocation;
654 frame = GTK_FRAME (widget);
657 context = gtk_widget_get_style_context (widget);
658 state = gtk_widget_get_state_flags (widget);
659 gtk_widget_get_allocation (widget, &allocation);
661 gtk_style_context_save (context);
662 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
664 gtk_style_context_get_padding (context, state, &padding);
666 x = priv->child_allocation.x - allocation.x - padding.left;
667 y = priv->child_allocation.y - allocation.y - padding.top;
668 width = priv->child_allocation.width + padding.left + padding.right;
669 height = priv->child_allocation.height + padding.top + padding.bottom;
671 if (priv->shadow_type != GTK_SHADOW_NONE)
673 if (priv->label_widget)
679 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
680 xalign = priv->label_xalign;
682 xalign = 1 - priv->label_xalign;
684 height_extra = MAX (0, priv->label_allocation.height - padding.top)
685 - priv->label_yalign * priv->label_allocation.height;
687 height += height_extra;
689 x2 = padding.left + (priv->child_allocation.width - priv->label_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
690 /* If the label is completely over or under the frame we can omit the gap */
691 if (priv->label_yalign == 0.0 || priv->label_yalign == 1.0)
692 gtk_render_frame (context, cr, x, y, width, height);
694 gtk_render_frame_gap (context, cr,
697 x2 + priv->label_allocation.width + 2 * LABEL_PAD);
700 gtk_render_frame (context, cr, x, y, width, height);
703 gtk_style_context_restore (context);
705 GTK_WIDGET_CLASS (gtk_frame_parent_class)->draw (widget, cr);
711 gtk_frame_size_allocate (GtkWidget *widget,
712 GtkAllocation *allocation)
714 GtkFrame *frame = GTK_FRAME (widget);
715 GtkFramePrivate *priv = frame->priv;
716 GtkBin *bin = GTK_BIN (widget);
717 GtkAllocation new_allocation;
720 gtk_widget_set_allocation (widget, allocation);
722 gtk_frame_compute_child_allocation (frame, &new_allocation);
724 /* If the child allocation changed, that means that the frame is drawn
725 * in a new place, so we must redraw the entire widget.
727 if (gtk_widget_get_mapped (widget))
729 gdk_window_invalidate_rect (gtk_widget_get_window (widget), allocation, FALSE);
732 child = gtk_bin_get_child (bin);
733 if (child && gtk_widget_get_visible (child))
734 gtk_widget_size_allocate (child, &new_allocation);
736 priv->child_allocation = new_allocation;
738 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
740 GtkStyleContext *context;
743 gint nat_width, width, height;
746 context = gtk_widget_get_style_context (widget);
747 state = gtk_widget_get_state_flags (widget);
749 gtk_style_context_save (context);
750 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
752 gtk_style_context_get_padding (context, state, &padding);
754 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
755 xalign = priv->label_xalign;
757 xalign = 1 - priv->label_xalign;
759 gtk_widget_get_preferred_width (priv->label_widget, NULL, &nat_width);
760 width = new_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD;
761 width = MIN (width, nat_width);
763 gtk_widget_get_preferred_height_for_width (priv->label_widget, width,
767 priv->label_allocation.x = priv->child_allocation.x + LABEL_SIDE_PAD +
768 (new_allocation.width - width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_PAD;
770 priv->label_allocation.width = width;
772 priv->label_allocation.y = priv->child_allocation.y - MAX (height, padding.top);
773 priv->label_allocation.height = height;
775 gtk_widget_size_allocate (priv->label_widget, &priv->label_allocation);
777 gtk_style_context_restore (context);
782 gtk_frame_compute_child_allocation (GtkFrame *frame,
783 GtkAllocation *child_allocation)
785 g_return_if_fail (GTK_IS_FRAME (frame));
786 g_return_if_fail (child_allocation != NULL);
788 GTK_FRAME_GET_CLASS (frame)->compute_child_allocation (frame, child_allocation);
792 gtk_frame_real_compute_child_allocation (GtkFrame *frame,
793 GtkAllocation *child_allocation)
795 GtkFramePrivate *priv = frame->priv;
796 GtkWidget *widget = GTK_WIDGET (frame);
797 GtkAllocation allocation;
798 GtkStyleContext *context;
804 context = gtk_widget_get_style_context (widget);
805 state = gtk_widget_get_state_flags (widget);
807 gtk_style_context_save (context);
808 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
810 gtk_style_context_get_padding (context, state, &padding);
811 gtk_widget_get_allocation (widget, &allocation);
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;
845 gtk_style_context_restore (context);
849 gtk_frame_get_preferred_size (GtkWidget *request,
850 GtkOrientation orientation,
854 GtkFrame *frame = GTK_FRAME (request);
855 GtkFramePrivate *priv = frame->priv;
856 GtkStyleContext *context;
859 GtkWidget *widget = GTK_WIDGET (request);
861 GtkBin *bin = GTK_BIN (widget);
862 gint child_min, child_nat;
863 gint minimum, natural;
866 context = gtk_widget_get_style_context (widget);
867 state = gtk_widget_get_state_flags (widget);
869 gtk_style_context_save (context);
870 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
871 gtk_style_context_get_padding (context, state, &padding);
873 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
875 if (orientation == GTK_ORIENTATION_HORIZONTAL)
877 gtk_widget_get_preferred_width (priv->label_widget,
878 &child_min, &child_nat);
879 minimum = child_min + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
880 natural = child_nat + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
884 gtk_widget_get_preferred_height (priv->label_widget,
885 &child_min, &child_nat);
886 minimum = MAX (0, child_min - padding.top);
887 natural = MAX (0, child_nat - padding.top);
896 child = gtk_bin_get_child (bin);
897 if (child && gtk_widget_get_visible (child))
899 if (orientation == GTK_ORIENTATION_HORIZONTAL)
901 gtk_widget_get_preferred_width (child,
902 &child_min, &child_nat);
903 minimum = MAX (minimum, child_min);
904 natural = MAX (natural, child_nat);
908 gtk_widget_get_preferred_height (child,
909 &child_min, &child_nat);
910 minimum += child_min;
911 natural += child_nat;
915 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
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;
934 gtk_style_context_restore (context);
938 gtk_frame_get_preferred_width (GtkWidget *widget,
942 gtk_frame_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
946 gtk_frame_get_preferred_height (GtkWidget *widget,
950 gtk_frame_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
955 gtk_frame_get_preferred_height_for_width (GtkWidget *request,
957 gint *minimum_height,
958 gint *natural_height)
960 GtkWidget *widget = GTK_WIDGET (request);
962 GtkFrame *frame = GTK_FRAME (widget);
963 GtkFramePrivate *priv = frame->priv;
964 GtkBin *bin = GTK_BIN (widget);
965 GtkStyleContext *context;
968 gint child_min, child_nat, label_width;
969 gint minimum, natural;
972 context = gtk_widget_get_style_context (widget);
973 state = gtk_widget_get_state_flags (widget);
975 gtk_style_context_save (context);
976 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
977 gtk_style_context_get_padding (context, state, &padding);
979 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
980 minimum = (border_width * 2) + padding.top + padding.bottom;
981 natural = (border_width * 2) + padding.top + padding.bottom;
983 width -= (border_width * 2) + padding.left + padding.right;
984 label_width = width - 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
986 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
988 gtk_widget_get_preferred_height_for_width (priv->label_widget,
989 label_width, &child_min, &child_nat);
990 minimum += child_min;
991 natural += child_nat;
994 child = gtk_bin_get_child (bin);
995 if (child && gtk_widget_get_visible (child))
997 gtk_widget_get_preferred_height_for_width (child,
998 width, &child_min, &child_nat);
999 minimum += child_min;
1000 natural += child_nat;
1004 *minimum_height = minimum;
1007 *natural_height = natural;
1009 gtk_style_context_restore (context);
1013 gtk_frame_get_preferred_width_for_height (GtkWidget *widget,
1015 gint *minimum_width,
1016 gint *natural_width)
1018 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);