* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
+#include "config.h"
#include <string.h>
#include "gtkframe.h"
#include "gtklabel.h"
+#include "gtkprivate.h"
#include "gtkintl.h"
+#include "gtkbuildable.h"
+#include "gtkalias.h"
#define LABEL_PAD 1
#define LABEL_SIDE_PAD 2
PROP_LABEL_WIDGET
};
-
-static void gtk_frame_class_init (GtkFrameClass *klass);
-static void gtk_frame_init (GtkFrame *frame);
static void gtk_frame_set_property (GObject *object,
guint param_id,
const GValue *value,
static void gtk_frame_real_compute_child_allocation (GtkFrame *frame,
GtkAllocation *child_allocation);
-static GtkBinClass *parent_class = NULL;
-
-
-GtkType
-gtk_frame_get_type (void)
-{
- static GtkType frame_type = 0;
-
- if (!frame_type)
- {
- static const GtkTypeInfo frame_info =
- {
- "GtkFrame",
- sizeof (GtkFrame),
- sizeof (GtkFrameClass),
- (GtkClassInitFunc) gtk_frame_class_init,
- (GtkObjectInitFunc) gtk_frame_init,
- /* reserved_1 */ NULL,
- /* reserved_2 */ NULL,
- (GtkClassInitFunc) NULL,
- };
-
- frame_type = gtk_type_unique (gtk_bin_get_type (), &frame_info);
- }
+/* GtkBuildable */
+static void gtk_frame_buildable_init (GtkBuildableIface *iface);
+static void gtk_frame_buildable_add_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *type);
- return frame_type;
-}
+G_DEFINE_TYPE_WITH_CODE (GtkFrame, gtk_frame, GTK_TYPE_BIN,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+ gtk_frame_buildable_init))
static void
gtk_frame_class_init (GtkFrameClass *class)
{
GObjectClass *gobject_class;
- GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
gobject_class = (GObjectClass*) class;
- object_class = GTK_OBJECT_CLASS (class);
widget_class = GTK_WIDGET_CLASS (class);
container_class = GTK_CONTAINER_CLASS (class);
- parent_class = gtk_type_class (gtk_bin_get_type ());
-
gobject_class->set_property = gtk_frame_set_property;
gobject_class->get_property = gtk_frame_get_property;
g_object_class_install_property (gobject_class,
PROP_LABEL,
g_param_spec_string ("label",
- _("Label"),
- _("Text of the frame's label"),
+ P_("Label"),
+ P_("Text of the frame's label"),
NULL,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ GTK_PARAM_READABLE |
+ GTK_PARAM_WRITABLE));
g_object_class_install_property (gobject_class,
PROP_LABEL_XALIGN,
- g_param_spec_float ("label_xalign",
- _("Label xalign"),
- _("The horizontal alignment of the label"),
+ g_param_spec_float ("label-xalign",
+ P_("Label xalign"),
+ P_("The horizontal alignment of the label"),
0.0,
1.0,
- 0.5,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ 0.0,
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_LABEL_YALIGN,
- g_param_spec_float ("label_yalign",
- _("Label yalign"),
- _("The vertical alignment of the label"),
+ g_param_spec_float ("label-yalign",
+ P_("Label yalign"),
+ P_("The vertical alignment of the label"),
0.0,
1.0,
0.5,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_SHADOW,
g_param_spec_enum ("shadow", NULL,
- _("Deprecated property, use shadow_type instead"),
+ P_("Deprecated property, use shadow_type instead"),
GTK_TYPE_SHADOW_TYPE,
GTK_SHADOW_ETCHED_IN,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_SHADOW_TYPE,
- g_param_spec_enum ("shadow_type",
- _("Frame shadow"),
- _("Appearance of the frame border"),
+ g_param_spec_enum ("shadow-type",
+ P_("Frame shadow"),
+ P_("Appearance of the frame border"),
GTK_TYPE_SHADOW_TYPE,
GTK_SHADOW_ETCHED_IN,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_LABEL_WIDGET,
- g_param_spec_object ("label_widget",
- _("Label widget"),
- _("A widget to display in place of the usual frame label"),
+ g_param_spec_object ("label-widget",
+ P_("Label widget"),
+ P_("A widget to display in place of the usual frame label"),
GTK_TYPE_WIDGET,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
widget_class->expose_event = gtk_frame_expose;
widget_class->size_request = gtk_frame_size_request;
class->compute_child_allocation = gtk_frame_real_compute_child_allocation;
}
+static void
+gtk_frame_buildable_init (GtkBuildableIface *iface)
+{
+ iface->add_child = gtk_frame_buildable_add_child;
+}
+
+static void
+gtk_frame_buildable_add_child (GtkBuildable *buildable,
+ GtkBuilder *builder,
+ GObject *child,
+ const gchar *type)
+{
+ if (type && strcmp (type, "label") == 0)
+ gtk_frame_set_label_widget (GTK_FRAME (buildable), GTK_WIDGET (child));
+ else if (!type)
+ gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
+ else
+ GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_FRAME (buildable), type);
+}
+
static void
gtk_frame_init (GtkFrame *frame)
{
}
}
+/**
+ * gtk_frame_new:
+ * @label: the text to use as the label of the frame
+ *
+ * Creates a new #GtkFrame, with optional label @label.
+ * If @label is %NULL, the label is omitted.
+ *
+ * Return value: a new #GtkFrame widget
+ **/
GtkWidget*
gtk_frame_new (const gchar *label)
{
- GtkFrame *frame;
-
- frame = gtk_type_new (gtk_frame_get_type ());
-
- gtk_frame_set_label (frame, label);
-
- return GTK_WIDGET (frame);
+ return g_object_new (GTK_TYPE_FRAME, "label", label, NULL);
}
static void
if (frame->label_widget == child)
gtk_frame_set_label_widget (frame, NULL);
else
- GTK_CONTAINER_CLASS (parent_class)->remove (container, child);
+ GTK_CONTAINER_CLASS (gtk_frame_parent_class)->remove (container, child);
}
static void
(* callback) (frame->label_widget, callback_data);
}
+/**
+ * gtk_frame_set_label:
+ * @frame: a #GtkFrame
+ * @label: the text to use as the label of the frame
+ *
+ * Sets the text of the label. If @label is %NULL,
+ * the current label is removed.
+ **/
void
gtk_frame_set_label (GtkFrame *frame,
const gchar *label)
gtk_frame_set_label_widget (frame, child);
}
-
- g_object_notify (G_OBJECT (frame), "label");
}
/**
* gtk_frame_get_label:
* @frame: a #GtkFrame
*
- * If the frame's label widget is a #GtkLabel, return the
+ * If the frame's label widget is a #GtkLabel, returns the
* text in the label widget. (The frame will have a #GtkLabel
* for the label widget if a non-%NULL argument was passed
* to gtk_frame_new().)
{
g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
- if (frame->label_widget && GTK_IS_LABEL (frame->label_widget))
+ if (GTK_IS_LABEL (frame->label_widget))
return gtk_label_get_text (GTK_LABEL (frame->label_widget));
else
return NULL;
* @frame: a #GtkFrame
* @label_widget: the new label widget
*
- * Set the label widget for the frame. This is the widget that
+ * Sets the label widget for the frame. This is the widget that
* will appear embedded in the top edge of the frame as a
* title.
**/
if (GTK_WIDGET_VISIBLE (frame) && need_resize)
gtk_widget_queue_resize (GTK_WIDGET (frame));
- g_object_notify (G_OBJECT (frame), "label_widget");
+ g_object_freeze_notify (G_OBJECT (frame));
+ g_object_notify (G_OBJECT (frame), "label-widget");
+ g_object_notify (G_OBJECT (frame), "label");
+ g_object_thaw_notify (G_OBJECT (frame));
}
/**
return frame->label_widget;
}
+/**
+ * gtk_frame_set_label_align:
+ * @frame: a #GtkFrame
+ * @xalign: The position of the label along the top edge
+ * of the widget. A value of 0.0 represents left alignment;
+ * 1.0 represents right alignment.
+ * @yalign: The y alignment of the label. A value of 0.0 aligns under
+ * the frame; 1.0 aligns above the frame. If the values are exactly
+ * 0.0 or 1.0 the gap in the frame won't be painted because the label
+ * will be completely above or below the frame.
+ *
+ * Sets the alignment of the frame widget's label. The
+ * default values for a newly created frame are 0.0 and 0.5.
+ **/
void
gtk_frame_set_label_align (GtkFrame *frame,
gfloat xalign,
if (xalign != frame->label_xalign)
{
frame->label_xalign = xalign;
- g_object_notify (G_OBJECT (frame), "label_xalign");
+ g_object_notify (G_OBJECT (frame), "label-xalign");
}
if (yalign != frame->label_yalign)
{
frame->label_yalign = yalign;
- g_object_notify (G_OBJECT (frame), "label_yalign");
+ g_object_notify (G_OBJECT (frame), "label-yalign");
}
g_object_thaw_notify (G_OBJECT (frame));
*yalign = frame->label_yalign;
}
+/**
+ * gtk_frame_set_shadow_type:
+ * @frame: a #GtkFrame
+ * @type: the new #GtkShadowType
+ *
+ * Sets the shadow type for @frame.
+ **/
void
gtk_frame_set_shadow_type (GtkFrame *frame,
GtkShadowType type)
if ((GtkShadowType) frame->shadow_type != type)
{
frame->shadow_type = type;
- g_object_notify (G_OBJECT (frame), "shadow_type");
+ g_object_notify (G_OBJECT (frame), "shadow-type");
if (GTK_WIDGET_DRAWABLE (frame))
{
- gtk_widget_queue_clear (GTK_WIDGET (frame));
+ gtk_widget_queue_draw (GTK_WIDGET (frame));
}
gtk_widget_queue_resize (GTK_WIDGET (frame));
else
xalign = 1 - frame->label_xalign;
- height_extra = MAX (0, child_requisition.height - widget->style->xthickness);
- y -= height_extra * (1 - frame->label_yalign);
- height += height_extra * (1 - frame->label_yalign);
+ height_extra = MAX (0, child_requisition.height - widget->style->ythickness)
+ - frame->label_yalign * child_requisition.height;
+ y -= height_extra;
+ height += height_extra;
x2 = widget->style->xthickness + (frame->child_allocation.width - child_requisition.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_SIDE_PAD;
-
- gtk_paint_shadow_gap (widget->style, widget->window,
- GTK_STATE_NORMAL, frame->shadow_type,
- area, widget, "frame",
- x, y, width, height,
- GTK_POS_TOP,
- x2, child_requisition.width + 2 * LABEL_PAD);
+ /* If the label is completely over or under the frame we can omit the gap */
+ if (frame->label_yalign == 0.0 || frame->label_yalign == 1.0)
+ gtk_paint_shadow (widget->style, widget->window,
+ widget->state, frame->shadow_type,
+ area, widget, "frame",
+ x, y, width, height);
+ else
+ gtk_paint_shadow_gap (widget->style, widget->window,
+ widget->state, frame->shadow_type,
+ area, widget, "frame",
+ x, y, width, height,
+ GTK_POS_TOP,
+ x2, child_requisition.width + 2 * LABEL_PAD);
}
else
gtk_paint_shadow (widget->style, widget->window,
- GTK_STATE_NORMAL, frame->shadow_type,
+ widget->state, frame->shadow_type,
area, widget, "frame",
x, y, width, height);
}
{
gtk_frame_paint (widget, &event->area);
- (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
+ GTK_WIDGET_CLASS (gtk_frame_parent_class)->expose_event (widget, event);
}
return FALSE;
requisition->width = child_requisition.width + 2 * LABEL_PAD + 2 * LABEL_SIDE_PAD;
requisition->height =
- MAX (0, child_requisition.height - GTK_WIDGET (widget)->style->xthickness);
+ MAX (0, child_requisition.height - widget->style->ythickness);
}
else
{
child_allocation.x = frame->child_allocation.x + LABEL_SIDE_PAD +
(frame->child_allocation.width - child_requisition.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD) * xalign + LABEL_PAD;
- child_allocation.width = child_requisition.width;
+ child_allocation.width = MIN (child_requisition.width, new_allocation.width - 2 * LABEL_PAD - 2 * LABEL_SIDE_PAD);
- child_allocation.y = frame->child_allocation.y - child_requisition.height;
+ child_allocation.y = frame->child_allocation.y - MAX (child_requisition.height, widget->style->ythickness);
child_allocation.height = child_requisition.height;
gtk_widget_size_allocate (frame->label_widget, &child_allocation);
child_allocation->x += allocation->x;
child_allocation->y += allocation->y;
}
+
+#define __GTK_FRAME_C__
+#include "gtkaliasdef.c"