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"
38 #define LABEL_SIDE_PAD 2
40 struct _GtkFramePrivate
43 GtkWidget *label_widget;
50 GtkAllocation child_allocation;
51 GtkAllocation label_allocation;
63 static void gtk_frame_set_property (GObject *object,
67 static void gtk_frame_get_property (GObject *object,
71 static gboolean gtk_frame_draw (GtkWidget *widget,
73 static void gtk_frame_size_allocate (GtkWidget *widget,
74 GtkAllocation *allocation);
75 static void gtk_frame_remove (GtkContainer *container,
77 static void gtk_frame_forall (GtkContainer *container,
78 gboolean include_internals,
80 gpointer callback_data);
81 static GtkWidgetPath * gtk_frame_get_path_for_child (GtkContainer *container,
84 static void gtk_frame_compute_child_allocation (GtkFrame *frame,
85 GtkAllocation *child_allocation);
86 static void gtk_frame_real_compute_child_allocation (GtkFrame *frame,
87 GtkAllocation *child_allocation);
90 static void gtk_frame_buildable_init (GtkBuildableIface *iface);
91 static void gtk_frame_buildable_add_child (GtkBuildable *buildable,
96 static void gtk_frame_get_preferred_width (GtkWidget *widget,
99 static void gtk_frame_get_preferred_height (GtkWidget *widget,
102 static void gtk_frame_get_preferred_height_for_width(GtkWidget *layout,
104 gint *minimum_height,
105 gint *natural_height);
106 static void gtk_frame_get_preferred_width_for_height(GtkWidget *layout,
108 gint *minimum_height,
109 gint *natural_height);
112 G_DEFINE_TYPE_WITH_CODE (GtkFrame, gtk_frame, GTK_TYPE_BIN,
113 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
114 gtk_frame_buildable_init))
117 gtk_frame_class_init (GtkFrameClass *class)
119 GObjectClass *gobject_class;
120 GtkWidgetClass *widget_class;
121 GtkContainerClass *container_class;
123 gobject_class = (GObjectClass*) class;
124 widget_class = GTK_WIDGET_CLASS (class);
125 container_class = GTK_CONTAINER_CLASS (class);
127 gobject_class->set_property = gtk_frame_set_property;
128 gobject_class->get_property = gtk_frame_get_property;
130 g_object_class_install_property (gobject_class,
132 g_param_spec_string ("label",
134 P_("Text of the frame's label"),
137 GTK_PARAM_WRITABLE));
138 g_object_class_install_property (gobject_class,
140 g_param_spec_float ("label-xalign",
142 P_("The horizontal alignment of the label"),
146 GTK_PARAM_READWRITE));
147 g_object_class_install_property (gobject_class,
149 g_param_spec_float ("label-yalign",
151 P_("The vertical alignment of the label"),
155 GTK_PARAM_READWRITE));
156 g_object_class_install_property (gobject_class,
158 g_param_spec_enum ("shadow-type",
160 P_("Appearance of the frame border"),
161 GTK_TYPE_SHADOW_TYPE,
162 GTK_SHADOW_ETCHED_IN,
163 GTK_PARAM_READWRITE));
165 g_object_class_install_property (gobject_class,
167 g_param_spec_object ("label-widget",
169 P_("A widget to display in place of the usual frame label"),
171 GTK_PARAM_READWRITE));
173 widget_class->draw = gtk_frame_draw;
174 widget_class->size_allocate = gtk_frame_size_allocate;
175 widget_class->get_preferred_width = gtk_frame_get_preferred_width;
176 widget_class->get_preferred_height = gtk_frame_get_preferred_height;
177 widget_class->get_preferred_height_for_width = gtk_frame_get_preferred_height_for_width;
178 widget_class->get_preferred_width_for_height = gtk_frame_get_preferred_width_for_height;
180 container_class->remove = gtk_frame_remove;
181 container_class->forall = gtk_frame_forall;
182 container_class->get_path_for_child = gtk_frame_get_path_for_child;
184 class->compute_child_allocation = gtk_frame_real_compute_child_allocation;
186 g_type_class_add_private (class, sizeof (GtkFramePrivate));
190 gtk_frame_buildable_init (GtkBuildableIface *iface)
192 iface->add_child = gtk_frame_buildable_add_child;
196 gtk_frame_buildable_add_child (GtkBuildable *buildable,
201 if (type && strcmp (type, "label") == 0)
202 gtk_frame_set_label_widget (GTK_FRAME (buildable), GTK_WIDGET (child));
204 gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
206 GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_FRAME (buildable), type);
210 gtk_frame_init (GtkFrame *frame)
212 GtkFramePrivate *priv;
214 frame->priv = G_TYPE_INSTANCE_GET_PRIVATE (frame,
219 priv->label_widget = NULL;
220 priv->shadow_type = GTK_SHADOW_ETCHED_IN;
221 priv->label_xalign = 0.0;
222 priv->label_yalign = 0.5;
226 gtk_frame_set_property (GObject *object,
231 GtkFrame *frame = GTK_FRAME (object);
232 GtkFramePrivate *priv = frame->priv;
237 gtk_frame_set_label (frame, g_value_get_string (value));
239 case PROP_LABEL_XALIGN:
240 gtk_frame_set_label_align (frame, g_value_get_float (value),
243 case PROP_LABEL_YALIGN:
244 gtk_frame_set_label_align (frame, priv->label_xalign,
245 g_value_get_float (value));
247 case PROP_SHADOW_TYPE:
248 gtk_frame_set_shadow_type (frame, g_value_get_enum (value));
250 case PROP_LABEL_WIDGET:
251 gtk_frame_set_label_widget (frame, g_value_get_object (value));
254 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
260 gtk_frame_get_property (GObject *object,
265 GtkFrame *frame = GTK_FRAME (object);
266 GtkFramePrivate *priv = frame->priv;
271 g_value_set_string (value, gtk_frame_get_label (frame));
273 case PROP_LABEL_XALIGN:
274 g_value_set_float (value, priv->label_xalign);
276 case PROP_LABEL_YALIGN:
277 g_value_set_float (value, priv->label_yalign);
279 case PROP_SHADOW_TYPE:
280 g_value_set_enum (value, priv->shadow_type);
282 case PROP_LABEL_WIDGET:
283 g_value_set_object (value,
285 G_OBJECT (priv->label_widget) : NULL);
288 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
295 * @label: the text to use as the label of the frame
297 * Creates a new #GtkFrame, with optional label @label.
298 * If @label is %NULL, the label is omitted.
300 * Return value: a new #GtkFrame widget
303 gtk_frame_new (const gchar *label)
305 return g_object_new (GTK_TYPE_FRAME, "label", label, NULL);
309 gtk_frame_remove (GtkContainer *container,
312 GtkFrame *frame = GTK_FRAME (container);
313 GtkFramePrivate *priv = frame->priv;
315 if (priv->label_widget == child)
316 gtk_frame_set_label_widget (frame, NULL);
318 GTK_CONTAINER_CLASS (gtk_frame_parent_class)->remove (container, child);
322 gtk_frame_forall (GtkContainer *container,
323 gboolean include_internals,
324 GtkCallback callback,
325 gpointer callback_data)
327 GtkBin *bin = GTK_BIN (container);
328 GtkFrame *frame = GTK_FRAME (container);
329 GtkFramePrivate *priv = frame->priv;
332 child = gtk_bin_get_child (bin);
334 (* callback) (child, callback_data);
336 if (priv->label_widget)
337 (* callback) (priv->label_widget, callback_data);
340 static GtkWidgetPath *
341 gtk_frame_get_path_for_child (GtkContainer *container,
344 GtkFramePrivate *priv = GTK_FRAME (container)->priv;
347 path = GTK_CONTAINER_CLASS (gtk_frame_parent_class)->get_path_for_child (container, child);
349 if (child == priv->label_widget)
350 gtk_widget_path_iter_add_class (path, -1, GTK_STYLE_CLASS_FRAME);
356 * gtk_frame_set_label:
357 * @frame: a #GtkFrame
358 * @label: (allow-none): the text to use as the label of the frame
360 * Sets the text of the label. If @label is %NULL,
361 * the current label is removed.
364 gtk_frame_set_label (GtkFrame *frame,
367 g_return_if_fail (GTK_IS_FRAME (frame));
371 gtk_frame_set_label_widget (frame, NULL);
375 GtkWidget *child = gtk_label_new (label);
376 gtk_widget_show (child);
378 gtk_frame_set_label_widget (frame, child);
383 * gtk_frame_get_label:
384 * @frame: a #GtkFrame
386 * If the frame's label widget is a #GtkLabel, returns the
387 * text in the label widget. (The frame will have a #GtkLabel
388 * for the label widget if a non-%NULL argument was passed
389 * to gtk_frame_new().)
391 * Return value: the text in the label, or %NULL if there
392 * was no label widget or the lable widget was not
393 * a #GtkLabel. This string is owned by GTK+ and
394 * must not be modified or freed.
396 G_CONST_RETURN gchar *
397 gtk_frame_get_label (GtkFrame *frame)
399 GtkFramePrivate *priv;
401 g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
405 if (GTK_IS_LABEL (priv->label_widget))
406 return gtk_label_get_text (GTK_LABEL (priv->label_widget));
412 * gtk_frame_set_label_widget:
413 * @frame: a #GtkFrame
414 * @label_widget: the new label widget
416 * Sets the label widget for the frame. This is the widget that
417 * will appear embedded in the top edge of the frame as a
421 gtk_frame_set_label_widget (GtkFrame *frame,
422 GtkWidget *label_widget)
424 GtkFramePrivate *priv;
425 gboolean need_resize = FALSE;
427 g_return_if_fail (GTK_IS_FRAME (frame));
428 g_return_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget));
429 g_return_if_fail (label_widget == NULL || gtk_widget_get_parent (label_widget) == NULL);
433 if (priv->label_widget == label_widget)
436 if (priv->label_widget)
438 need_resize = gtk_widget_get_visible (priv->label_widget);
439 gtk_widget_unparent (priv->label_widget);
442 priv->label_widget = label_widget;
446 priv->label_widget = label_widget;
447 gtk_widget_set_parent (label_widget, GTK_WIDGET (frame));
448 need_resize |= gtk_widget_get_visible (label_widget);
451 if (gtk_widget_get_visible (GTK_WIDGET (frame)) && need_resize)
452 gtk_widget_queue_resize (GTK_WIDGET (frame));
454 g_object_freeze_notify (G_OBJECT (frame));
455 g_object_notify (G_OBJECT (frame), "label-widget");
456 g_object_notify (G_OBJECT (frame), "label");
457 g_object_thaw_notify (G_OBJECT (frame));
461 * gtk_frame_get_label_widget:
462 * @frame: a #GtkFrame
464 * Retrieves the label widget for the frame. See
465 * gtk_frame_set_label_widget().
467 * Return value: (transfer none): the label widget, or %NULL if there is none.
470 gtk_frame_get_label_widget (GtkFrame *frame)
472 g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
474 return frame->priv->label_widget;
478 * gtk_frame_set_label_align:
479 * @frame: a #GtkFrame
480 * @xalign: The position of the label along the top edge
481 * of the widget. A value of 0.0 represents left alignment;
482 * 1.0 represents right alignment.
483 * @yalign: The y alignment of the label. A value of 0.0 aligns under
484 * the frame; 1.0 aligns above the frame. If the values are exactly
485 * 0.0 or 1.0 the gap in the frame won't be painted because the label
486 * will be completely above or below the frame.
488 * Sets the alignment of the frame widget's label. The
489 * default values for a newly created frame are 0.0 and 0.5.
492 gtk_frame_set_label_align (GtkFrame *frame,
496 GtkFramePrivate *priv;
498 g_return_if_fail (GTK_IS_FRAME (frame));
502 xalign = CLAMP (xalign, 0.0, 1.0);
503 yalign = CLAMP (yalign, 0.0, 1.0);
505 g_object_freeze_notify (G_OBJECT (frame));
506 if (xalign != priv->label_xalign)
508 priv->label_xalign = xalign;
509 g_object_notify (G_OBJECT (frame), "label-xalign");
512 if (yalign != priv->label_yalign)
514 priv->label_yalign = yalign;
515 g_object_notify (G_OBJECT (frame), "label-yalign");
518 g_object_thaw_notify (G_OBJECT (frame));
519 gtk_widget_queue_resize (GTK_WIDGET (frame));
523 * gtk_frame_get_label_align:
524 * @frame: a #GtkFrame
525 * @xalign: (out) (allow-none): location to store X alignment of
526 * frame's label, or %NULL
527 * @yalign: (out) (allow-none): location to store X alignment of
528 * frame's label, or %NULL
530 * Retrieves the X and Y alignment of the frame's label. See
531 * gtk_frame_set_label_align().
534 gtk_frame_get_label_align (GtkFrame *frame,
538 GtkFramePrivate *priv;
540 g_return_if_fail (GTK_IS_FRAME (frame));
545 *xalign = priv->label_xalign;
547 *yalign = priv->label_yalign;
551 * gtk_frame_set_shadow_type:
552 * @frame: a #GtkFrame
553 * @type: the new #GtkShadowType
555 * Sets the shadow type for @frame.
558 gtk_frame_set_shadow_type (GtkFrame *frame,
561 GtkFramePrivate *priv;
564 g_return_if_fail (GTK_IS_FRAME (frame));
568 if ((GtkShadowType) priv->shadow_type != type)
570 widget = GTK_WIDGET (frame);
571 priv->shadow_type = type;
572 g_object_notify (G_OBJECT (frame), "shadow-type");
574 if (gtk_widget_is_drawable (widget))
576 gtk_widget_queue_draw (widget);
579 gtk_widget_queue_resize (widget);
584 * gtk_frame_get_shadow_type:
585 * @frame: a #GtkFrame
587 * Retrieves the shadow type of the frame. See
588 * gtk_frame_set_shadow_type().
590 * Return value: the current shadow type of the frame.
593 gtk_frame_get_shadow_type (GtkFrame *frame)
595 g_return_val_if_fail (GTK_IS_FRAME (frame), GTK_SHADOW_ETCHED_IN);
597 return frame->priv->shadow_type;
601 gtk_frame_draw (GtkWidget *widget,
605 GtkFramePrivate *priv;
606 GtkStyleContext *context;
608 gint x, y, width, height;
609 GtkAllocation allocation;
612 frame = GTK_FRAME (widget);
615 context = gtk_widget_get_style_context (widget);
616 state = gtk_widget_get_state_flags (widget);
617 gtk_widget_get_allocation (widget, &allocation);
619 gtk_style_context_save (context);
620 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
622 gtk_style_context_get_padding (context, state, &padding);
624 x = priv->child_allocation.x - allocation.x - padding.left;
625 y = priv->child_allocation.y - allocation.y - padding.top;
626 width = priv->child_allocation.width + padding.left + padding.right;
627 height = priv->child_allocation.height + padding.top + padding.bottom;
629 if (priv->shadow_type != GTK_SHADOW_NONE)
631 if (priv->label_widget)
637 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
638 xalign = priv->label_xalign;
640 xalign = 1 - priv->label_xalign;
642 height_extra = MAX (0, priv->label_allocation.height - padding.top)
643 - priv->label_yalign * priv->label_allocation.height;
645 height += height_extra;
647 x2 = padding.left + (priv->child_allocation.width - priv->label_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
648 /* If the label is completely over or under the frame we can omit the gap */
649 if (priv->label_yalign == 0.0 || priv->label_yalign == 1.0)
650 gtk_render_frame (context, cr, x, y, width, height);
652 gtk_render_frame_gap (context, cr,
655 x2 + priv->label_allocation.width + 2 * LABEL_PAD);
658 gtk_render_frame (context, cr, x, y, width, height);
661 gtk_style_context_restore (context);
663 GTK_WIDGET_CLASS (gtk_frame_parent_class)->draw (widget, cr);
669 gtk_frame_size_allocate (GtkWidget *widget,
670 GtkAllocation *allocation)
672 GtkFrame *frame = GTK_FRAME (widget);
673 GtkFramePrivate *priv = frame->priv;
674 GtkBin *bin = GTK_BIN (widget);
675 GtkAllocation new_allocation;
678 gtk_widget_set_allocation (widget, allocation);
680 gtk_frame_compute_child_allocation (frame, &new_allocation);
682 /* If the child allocation changed, that means that the frame is drawn
683 * in a new place, so we must redraw the entire widget.
685 if (gtk_widget_get_mapped (widget))
687 gdk_window_invalidate_rect (gtk_widget_get_window (widget), allocation, FALSE);
690 child = gtk_bin_get_child (bin);
691 if (child && gtk_widget_get_visible (child))
692 gtk_widget_size_allocate (child, &new_allocation);
694 priv->child_allocation = new_allocation;
696 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
698 GtkStyleContext *context;
701 gint nat_width, width, height;
704 context = gtk_widget_get_style_context (widget);
705 state = gtk_widget_get_state_flags (widget);
707 gtk_style_context_save (context);
708 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
710 gtk_style_context_get_padding (context, state, &padding);
712 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
713 xalign = priv->label_xalign;
715 xalign = 1 - priv->label_xalign;
717 gtk_widget_get_preferred_width (priv->label_widget, NULL, &nat_width);
718 width = new_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD;
719 width = MIN (width, nat_width);
721 gtk_widget_get_preferred_height_for_width (priv->label_widget, width,
725 priv->label_allocation.x = priv->child_allocation.x + LABEL_SIDE_PAD +
726 (new_allocation.width - width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_PAD;
728 priv->label_allocation.width = width;
730 priv->label_allocation.y = priv->child_allocation.y - MAX (height, padding.top);
731 priv->label_allocation.height = height;
733 gtk_widget_size_allocate (priv->label_widget, &priv->label_allocation);
735 gtk_style_context_restore (context);
740 gtk_frame_compute_child_allocation (GtkFrame *frame,
741 GtkAllocation *child_allocation)
743 g_return_if_fail (GTK_IS_FRAME (frame));
744 g_return_if_fail (child_allocation != NULL);
746 GTK_FRAME_GET_CLASS (frame)->compute_child_allocation (frame, child_allocation);
750 gtk_frame_real_compute_child_allocation (GtkFrame *frame,
751 GtkAllocation *child_allocation)
753 GtkFramePrivate *priv = frame->priv;
754 GtkWidget *widget = GTK_WIDGET (frame);
755 GtkAllocation allocation;
756 GtkStyleContext *context;
762 context = gtk_widget_get_style_context (widget);
763 state = gtk_widget_get_state_flags (widget);
765 gtk_style_context_save (context);
766 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
768 gtk_style_context_get_padding (context, state, &padding);
769 gtk_widget_get_allocation (widget, &allocation);
771 border_width = gtk_container_get_border_width (GTK_CONTAINER (frame));
773 if (priv->label_widget)
775 gint nat_width, width, height;
777 gtk_widget_get_preferred_width (priv->label_widget, NULL, &nat_width);
779 width = allocation.width;
780 width -= 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
781 width -= (border_width * 2) + padding.left + padding.right;
783 width = MIN (width, nat_width);
785 gtk_widget_get_preferred_height_for_width (priv->label_widget, width,
788 top_margin = MAX (height, padding.top);
791 top_margin = padding.top;
793 child_allocation->x = border_width + padding.left;
794 child_allocation->y = border_width + top_margin;
795 child_allocation->width = MAX (1, (gint) allocation.width - (border_width * 2) -
796 padding.left - padding.right);
797 child_allocation->height = MAX (1, ((gint) allocation.height - child_allocation->y -
798 border_width - padding.bottom));
800 child_allocation->x += allocation.x;
801 child_allocation->y += allocation.y;
803 gtk_style_context_restore (context);
807 gtk_frame_get_preferred_size (GtkWidget *request,
808 GtkOrientation orientation,
812 GtkFrame *frame = GTK_FRAME (request);
813 GtkFramePrivate *priv = frame->priv;
814 GtkStyleContext *context;
817 GtkWidget *widget = GTK_WIDGET (request);
819 GtkBin *bin = GTK_BIN (widget);
820 gint child_min, child_nat;
821 gint minimum, natural;
824 context = gtk_widget_get_style_context (widget);
825 state = gtk_widget_get_state_flags (widget);
827 gtk_style_context_save (context);
828 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
829 gtk_style_context_get_padding (context, state, &padding);
831 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
833 if (orientation == GTK_ORIENTATION_HORIZONTAL)
835 gtk_widget_get_preferred_width (priv->label_widget,
836 &child_min, &child_nat);
837 minimum = child_min + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
838 natural = child_nat + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
842 gtk_widget_get_preferred_height (priv->label_widget,
843 &child_min, &child_nat);
844 minimum = MAX (0, child_min - padding.top);
845 natural = MAX (0, child_nat - padding.top);
854 child = gtk_bin_get_child (bin);
855 if (child && gtk_widget_get_visible (child))
857 if (orientation == GTK_ORIENTATION_HORIZONTAL)
859 gtk_widget_get_preferred_width (child,
860 &child_min, &child_nat);
861 minimum = MAX (minimum, child_min);
862 natural = MAX (natural, child_nat);
866 gtk_widget_get_preferred_height (child,
867 &child_min, &child_nat);
868 minimum += child_min;
869 natural += child_nat;
873 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
875 if (orientation == GTK_ORIENTATION_HORIZONTAL)
877 minimum += (border_width * 2) + padding.left + padding.right;
878 natural += (border_width * 2) + padding.left + padding.right;
882 minimum += (border_width * 2) + padding.top + padding.bottom;
883 natural += (border_width * 2) + padding.top + padding.bottom;
887 *minimum_size = minimum;
890 *natural_size = natural;
892 gtk_style_context_restore (context);
896 gtk_frame_get_preferred_width (GtkWidget *widget,
900 gtk_frame_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
904 gtk_frame_get_preferred_height (GtkWidget *widget,
908 gtk_frame_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
913 gtk_frame_get_preferred_height_for_width (GtkWidget *request,
915 gint *minimum_height,
916 gint *natural_height)
918 GtkWidget *widget = GTK_WIDGET (request);
920 GtkFrame *frame = GTK_FRAME (widget);
921 GtkFramePrivate *priv = frame->priv;
922 GtkBin *bin = GTK_BIN (widget);
923 GtkStyleContext *context;
926 gint child_min, child_nat, label_width;
927 gint minimum, natural;
930 context = gtk_widget_get_style_context (widget);
931 state = gtk_widget_get_state_flags (widget);
933 gtk_style_context_save (context);
934 gtk_style_context_add_class (context, GTK_STYLE_CLASS_FRAME);
935 gtk_style_context_get_padding (context, state, &padding);
937 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
938 minimum = (border_width * 2) + padding.top + padding.bottom;
939 natural = (border_width * 2) + padding.top + padding.bottom;
941 width -= (border_width * 2) + padding.left + padding.right;
942 label_width = width - 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
944 if (priv->label_widget && gtk_widget_get_visible (priv->label_widget))
946 gtk_widget_get_preferred_height_for_width (priv->label_widget,
947 label_width, &child_min, &child_nat);
948 minimum += child_min;
949 natural += child_nat;
952 child = gtk_bin_get_child (bin);
953 if (child && gtk_widget_get_visible (child))
955 gtk_widget_get_preferred_height_for_width (child,
956 width, &child_min, &child_nat);
957 minimum += child_min;
958 natural += child_nat;
962 *minimum_height = minimum;
965 *natural_height = natural;
967 gtk_style_context_restore (context);
971 gtk_frame_get_preferred_width_for_height (GtkWidget *widget,
976 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);