* 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 "gtkalias.h"
+
+#define LABEL_PAD 1
+#define LABEL_SIDE_PAD 2
enum {
- ARG_0,
- ARG_LABEL,
- ARG_LABEL_XALIGN,
- ARG_LABEL_YALIGN,
- ARG_SHADOW
+ PROP_0,
+ PROP_LABEL,
+ PROP_LABEL_XALIGN,
+ PROP_LABEL_YALIGN,
+ PROP_SHADOW,
+ PROP_SHADOW_TYPE,
+ PROP_LABEL_WIDGET
};
static void gtk_frame_class_init (GtkFrameClass *klass);
static void gtk_frame_init (GtkFrame *frame);
-static void gtk_frame_set_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id);
-static void gtk_frame_get_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id);
+static void gtk_frame_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_frame_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
static void gtk_frame_paint (GtkWidget *widget,
GdkRectangle *area);
static gint gtk_frame_expose (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_frame_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static void gtk_frame_map (GtkWidget *widget);
-static void gtk_frame_unmap (GtkWidget *widget);
static void gtk_frame_remove (GtkContainer *container,
GtkWidget *child);
static void gtk_frame_forall (GtkContainer *container,
static GtkBinClass *parent_class = NULL;
-/* Here until I convince timj about memory management behavior
- */
-gchar * gtk_frame_get_label (GtkFrame *frame);
-gchar * gtk_label_get_text (GtkLabel *label);
-
-
-GtkType
+GType
gtk_frame_get_type (void)
{
- static GtkType frame_type = 0;
+ static GType frame_type = 0;
if (!frame_type)
{
- static const GtkTypeInfo frame_info =
+ static const GTypeInfo frame_info =
{
- "GtkFrame",
- sizeof (GtkFrame),
sizeof (GtkFrameClass),
- (GtkClassInitFunc) gtk_frame_class_init,
- (GtkObjectInitFunc) gtk_frame_init,
- /* reserved_1 */ NULL,
- /* reserved_2 */ NULL,
- (GtkClassInitFunc) NULL,
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) gtk_frame_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GtkFrame),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) gtk_frame_init,
};
- frame_type = gtk_type_unique (gtk_bin_get_type (), &frame_info);
+ frame_type = g_type_register_static (GTK_TYPE_BIN, I_("GtkFrame"),
+ &frame_info, 0);
}
return frame_type;
static void
gtk_frame_class_init (GtkFrameClass *class)
{
- GtkObjectClass *object_class;
+ GObjectClass *gobject_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
- object_class = GTK_OBJECT_CLASS (class);
+ gobject_class = (GObjectClass*) class;
widget_class = GTK_WIDGET_CLASS (class);
container_class = GTK_CONTAINER_CLASS (class);
- parent_class = gtk_type_class (gtk_bin_get_type ());
-
- gtk_object_add_arg_type ("GtkFrame::label", GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_LABEL);
- gtk_object_add_arg_type ("GtkFrame::label_xalign", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_LABEL_XALIGN);
- gtk_object_add_arg_type ("GtkFrame::label_yalign", GTK_TYPE_FLOAT, GTK_ARG_READWRITE, ARG_LABEL_YALIGN);
- gtk_object_add_arg_type ("GtkFrame::shadow", GTK_TYPE_SHADOW_TYPE, GTK_ARG_READWRITE, ARG_SHADOW);
-
- object_class->set_arg = gtk_frame_set_arg;
- object_class->get_arg = gtk_frame_get_arg;
-
+ parent_class = g_type_class_peek_parent (class);
+
+ 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",
+ P_("Label"),
+ P_("Text of the frame's label"),
+ NULL,
+ GTK_PARAM_READABLE |
+ GTK_PARAM_WRITABLE));
+ g_object_class_install_property (gobject_class,
+ PROP_LABEL_XALIGN,
+ g_param_spec_float ("label-xalign",
+ P_("Label xalign"),
+ P_("The horizontal alignment of the label"),
+ 0.0,
+ 1.0,
+ 0.5,
+ GTK_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class,
+ PROP_LABEL_YALIGN,
+ g_param_spec_float ("label-yalign",
+ P_("Label yalign"),
+ P_("The vertical alignment of the label"),
+ 0.0,
+ 1.0,
+ 0.5,
+ GTK_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class,
+ PROP_SHADOW,
+ g_param_spec_enum ("shadow", NULL,
+ P_("Deprecated property, use shadow_type instead"),
+ GTK_TYPE_SHADOW_TYPE,
+ GTK_SHADOW_ETCHED_IN,
+ GTK_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class,
+ PROP_SHADOW_TYPE,
+ g_param_spec_enum ("shadow-type",
+ P_("Frame shadow"),
+ P_("Appearance of the frame border"),
+ GTK_TYPE_SHADOW_TYPE,
+ GTK_SHADOW_ETCHED_IN,
+ GTK_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_LABEL_WIDGET,
+ g_param_spec_object ("label-widget",
+ P_("Label widget"),
+ P_("A widget to display in place of the usual frame label"),
+ GTK_TYPE_WIDGET,
+ GTK_PARAM_READWRITE));
+
widget_class->expose_event = gtk_frame_expose;
widget_class->size_request = gtk_frame_size_request;
widget_class->size_allocate = gtk_frame_size_allocate;
- widget_class->map = gtk_frame_map;
- widget_class->unmap = gtk_frame_unmap;
container_class->remove = gtk_frame_remove;
container_class->forall = gtk_frame_forall;
frame->label_yalign = 0.5;
}
-static void
-gtk_frame_set_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id)
+static void
+gtk_frame_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GtkFrame *frame;
frame = GTK_FRAME (object);
- switch (arg_id)
+ switch (prop_id)
{
- case ARG_LABEL:
- gtk_frame_set_label (frame, GTK_VALUE_STRING (*arg));
+ case PROP_LABEL:
+ gtk_frame_set_label (frame, g_value_get_string (value));
break;
- case ARG_LABEL_XALIGN:
- gtk_frame_set_label_align (frame, GTK_VALUE_FLOAT (*arg), frame->label_yalign);
+ case PROP_LABEL_XALIGN:
+ gtk_frame_set_label_align (frame, g_value_get_float (value),
+ frame->label_yalign);
break;
- case ARG_LABEL_YALIGN:
- gtk_frame_set_label_align (frame, frame->label_xalign, GTK_VALUE_FLOAT (*arg));
+ case PROP_LABEL_YALIGN:
+ gtk_frame_set_label_align (frame, frame->label_xalign,
+ g_value_get_float (value));
break;
- case ARG_SHADOW:
- gtk_frame_set_shadow_type (frame, GTK_VALUE_ENUM (*arg));
+ case PROP_SHADOW:
+ case PROP_SHADOW_TYPE:
+ gtk_frame_set_shadow_type (frame, g_value_get_enum (value));
break;
- default:
+ case PROP_LABEL_WIDGET:
+ gtk_frame_set_label_widget (frame, g_value_get_object (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
-static void
-gtk_frame_get_arg (GtkObject *object,
- GtkArg *arg,
- guint arg_id)
+static void
+gtk_frame_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GtkFrame *frame;
frame = GTK_FRAME (object);
- switch (arg_id)
+ switch (prop_id)
{
- case ARG_LABEL:
- GTK_VALUE_STRING (*arg) = gtk_frame_get_label (frame);
+ case PROP_LABEL:
+ g_value_set_string (value, gtk_frame_get_label (frame));
+ break;
+ case PROP_LABEL_XALIGN:
+ g_value_set_float (value, frame->label_xalign);
break;
- case ARG_LABEL_XALIGN:
- GTK_VALUE_FLOAT (*arg) = frame->label_xalign;
+ case PROP_LABEL_YALIGN:
+ g_value_set_float (value, frame->label_yalign);
break;
- case ARG_LABEL_YALIGN:
- GTK_VALUE_FLOAT (*arg) = frame->label_yalign;
+ case PROP_SHADOW:
+ case PROP_SHADOW_TYPE:
+ g_value_set_enum (value, frame->shadow_type);
break;
- case ARG_SHADOW:
- GTK_VALUE_ENUM (*arg) = frame->shadow_type;
+ case PROP_LABEL_WIDGET:
+ g_value_set_object (value,
+ frame->label_widget ?
+ G_OBJECT (frame->label_widget) : NULL);
break;
default:
- arg->type = GTK_TYPE_INVALID;
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
+/**
+ * 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
(* 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)
{
- g_return_if_fail (frame != NULL);
g_return_if_fail (GTK_IS_FRAME (frame));
if (!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().)
*
* Return value: the text in the label, or %NULL if there
* was no label widget or the lable widget was not
- * a #GtkLabel. This value must be freed with g_free().
+ * a #GtkLabel. This string is owned by GTK+ and
+ * must not be modified or freed.
**/
-gchar *
+G_CONST_RETURN gchar *
gtk_frame_get_label (GtkFrame *frame)
{
- g_return_val_if_fail (frame != NULL, NULL);
g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
if (frame->label_widget && GTK_IS_LABEL (frame->label_widget))
* @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.
**/
{
gboolean need_resize = FALSE;
- g_return_if_fail (frame != NULL);
g_return_if_fail (GTK_IS_FRAME (frame));
g_return_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget));
g_return_if_fail (label_widget == NULL || label_widget->parent == NULL);
gtk_widget_set_parent (label_widget, GTK_WIDGET (frame));
need_resize |= GTK_WIDGET_VISIBLE (label_widget);
}
-
+
if (GTK_WIDGET_VISIBLE (frame) && need_resize)
gtk_widget_queue_resize (GTK_WIDGET (frame));
+
+ 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));
+}
+
+/**
+ * gtk_frame_get_label_widget:
+ * @frame: a #GtkFrame
+ *
+ * Retrieves the label widget for the frame. See
+ * gtk_frame_set_label_widget().
+ *
+ * Return value: the label widget, or %NULL if there is none.
+ **/
+GtkWidget *
+gtk_frame_get_label_widget (GtkFrame *frame)
+{
+ g_return_val_if_fail (GTK_IS_FRAME (frame), NULL);
+
+ 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.
+ *
+ * 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,
gfloat yalign)
{
- g_return_if_fail (frame != NULL);
g_return_if_fail (GTK_IS_FRAME (frame));
xalign = CLAMP (xalign, 0.0, 1.0);
yalign = CLAMP (yalign, 0.0, 1.0);
- if ((xalign != frame->label_xalign) || (yalign != frame->label_yalign))
+ g_object_freeze_notify (G_OBJECT (frame));
+ if (xalign != frame->label_xalign)
{
frame->label_xalign = xalign;
- frame->label_yalign = yalign;
+ g_object_notify (G_OBJECT (frame), "label-xalign");
+ }
- gtk_widget_queue_resize (GTK_WIDGET (frame));
+ if (yalign != frame->label_yalign)
+ {
+ frame->label_yalign = yalign;
+ g_object_notify (G_OBJECT (frame), "label-yalign");
}
+
+ g_object_thaw_notify (G_OBJECT (frame));
+ gtk_widget_queue_resize (GTK_WIDGET (frame));
}
+/**
+ * gtk_frame_get_label_align:
+ * @frame: a #GtkFrame
+ * @xalign: location to store X alignment of frame's label, or %NULL
+ * @yalign: location to store X alignment of frame's label, or %NULL
+ *
+ * Retrieves the X and Y alignment of the frame's label. See
+ * gtk_frame_set_label_align().
+ **/
+void
+gtk_frame_get_label_align (GtkFrame *frame,
+ gfloat *xalign,
+ gfloat *yalign)
+{
+ g_return_if_fail (GTK_IS_FRAME (frame));
+
+ if (xalign)
+ *xalign = frame->label_xalign;
+ if (yalign)
+ *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)
{
- g_return_if_fail (frame != NULL);
g_return_if_fail (GTK_IS_FRAME (frame));
if ((GtkShadowType) frame->shadow_type != type)
{
frame->shadow_type = 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));
}
}
+/**
+ * gtk_frame_get_shadow_type:
+ * @frame: a #GtkFrame
+ *
+ * Retrieves the shadow type of the frame. See
+ * gtk_frame_set_shadow_type().
+ *
+ * Return value: the current shadow type of the frame.
+ **/
+GtkShadowType
+gtk_frame_get_shadow_type (GtkFrame *frame)
+{
+ g_return_val_if_fail (GTK_IS_FRAME (frame), GTK_SHADOW_ETCHED_IN);
+
+ return frame->shadow_type;
+}
+
static void
gtk_frame_paint (GtkWidget *widget,
GdkRectangle *area)
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);
+ height_extra *= (1 - frame->label_yalign);
+ y -= height_extra;
+ height += height_extra;
- x2 = 2 + (frame->child_allocation.width - child_requisition.width) * xalign;
+ 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,
+ widget->state, frame->shadow_type,
area, widget, "frame",
x, y, width, height,
GTK_POS_TOP,
- x2, child_requisition.width - 4);
+ 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_expose (GtkWidget *widget,
GdkEventExpose *event)
{
- GtkBin *bin = GTK_BIN (widget);
- GtkFrame *frame = GTK_FRAME (widget);
- GdkEventExpose child_event;
-
if (GTK_WIDGET_DRAWABLE (widget))
{
gtk_frame_paint (widget, &event->area);
- if (bin->child && GTK_WIDGET_NO_WINDOW (bin->child))
- {
- child_event = *event;
- if (gtk_widget_intersect (bin->child, &event->area, &child_event.area))
- gtk_widget_event (bin->child, (GdkEvent*) &child_event);
- }
-
- if (frame->label_widget && GTK_WIDGET_NO_WINDOW (frame->label_widget))
- {
- child_event = *event;
- if (gtk_widget_intersect (frame->label_widget, &event->area, &child_event.area))
- gtk_widget_event (frame->label_widget, (GdkEvent*) &child_event);
- }
+ (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
}
return FALSE;
{
gtk_widget_size_request (frame->label_widget, &child_requisition);
- requisition->width = child_requisition.width;
+ 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 - GTK_WIDGET (widget)->style->ythickness);
}
else
{
new_allocation.y != frame->child_allocation.y ||
new_allocation.width != frame->child_allocation.width ||
new_allocation.height != frame->child_allocation.height))
- gtk_widget_queue_clear (widget);
+ gdk_window_invalidate_rect (widget->window, &widget->allocation, FALSE);
if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
gtk_widget_size_allocate (bin->child, &new_allocation);
else
xalign = 1 - frame->label_xalign;
- child_allocation.x = frame->child_allocation.x +
- (frame->child_allocation.width - child_requisition.width) * xalign;
+ 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.y = frame->child_allocation.y - child_requisition.height;
}
}
-static void
-gtk_frame_map (GtkWidget *widget)
-{
- GtkFrame *frame = GTK_FRAME (widget);
-
- if (frame->label_widget &&
- GTK_WIDGET_VISIBLE (frame->label_widget) &&
- !GTK_WIDGET_MAPPED (frame->label_widget))
- gtk_widget_map (frame->label_widget);
-
- if (GTK_WIDGET_CLASS (parent_class)->map)
- (* GTK_WIDGET_CLASS (parent_class)->map) (widget);
-}
-
-static void
-gtk_frame_unmap (GtkWidget *widget)
-{
- GtkFrame *frame = GTK_FRAME (widget);
-
- if (GTK_WIDGET_CLASS (parent_class)->unmap)
- (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget);
-
- if (frame->label_widget && GTK_WIDGET_MAPPED (frame->label_widget))
- gtk_widget_unmap (frame->label_widget);
-}
-
static void
gtk_frame_compute_child_allocation (GtkFrame *frame,
GtkAllocation *child_allocation)
{
- g_return_if_fail (frame != NULL);
g_return_if_fail (GTK_IS_FRAME (frame));
g_return_if_fail (child_allocation != NULL);
child_allocation->x += allocation->x;
child_allocation->y += allocation->y;
}
+
+#define __GTK_FRAME_C__
+#include "gtkaliasdef.c"