* Boston, MA 02111-1307, USA.
*/
+#include <config.h>
#include "gtkcellrenderer.h"
#include "gtkintl.h"
+#include "gtkmarshalers.h"
+#include "gtkprivate.h"
+#include "gtktreeprivate.h"
+#include "gtkalias.h"
-static void gtk_cell_renderer_init (GtkCellRenderer *cell);
-static void gtk_cell_renderer_class_init (GtkCellRendererClass *class);
static void gtk_cell_renderer_get_property (GObject *object,
guint param_id,
GValue *value,
GdkColor *color);
+#define GTK_CELL_RENDERER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER, GtkCellRendererPrivate))
+
+typedef struct _GtkCellRendererPrivate GtkCellRendererPrivate;
+struct _GtkCellRendererPrivate
+{
+ GdkColor cell_background;
+};
+
+
enum {
PROP_ZERO,
PROP_MODE,
PROP_VISIBLE,
+ PROP_SENSITIVE,
PROP_XALIGN,
PROP_YALIGN,
PROP_XPAD,
PROP_CELL_BACKGROUND_SET
};
-#define CELLINFO_KEY "gtk-cell-renderer-info"
-
-typedef struct _GtkCellRendererInfo GtkCellRendererInfo;
-struct _GtkCellRendererInfo
-{
- GdkColor cell_background;
+/* Signal IDs */
+enum {
+ EDITING_CANCELED,
+ EDITING_STARTED,
+ LAST_SIGNAL
};
-GType
-gtk_cell_renderer_get_type (void)
-{
- static GType cell_type = 0;
-
- if (!cell_type)
- {
- static const GTypeInfo cell_info =
- {
- sizeof (GtkCellRendererClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_cell_renderer_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkCellRenderer),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_cell_renderer_init,
- NULL, /* value_table */
- };
-
- cell_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkCellRenderer",
- &cell_info, G_TYPE_FLAG_ABSTRACT);
- }
+static guint cell_renderer_signals[LAST_SIGNAL] = { 0 };
- return cell_type;
-}
+G_DEFINE_ABSTRACT_TYPE (GtkCellRenderer, gtk_cell_renderer, GTK_TYPE_OBJECT)
static void
gtk_cell_renderer_init (GtkCellRenderer *cell)
{
- GtkCellRendererInfo *cellinfo;
-
cell->mode = GTK_CELL_RENDERER_MODE_INERT;
cell->visible = TRUE;
cell->width = -1;
cell->yalign = 0.5;
cell->xpad = 0;
cell->ypad = 0;
-
- cellinfo = g_new0 (GtkCellRendererInfo, 1);
- g_object_set_data_full (G_OBJECT (cell), CELLINFO_KEY, cellinfo, g_free);
+ cell->sensitive = TRUE;
+ cell->is_expander = FALSE;
+ cell->is_expanded = FALSE;
+ cell->editing = FALSE;
}
static void
class->render = NULL;
class->get_size = NULL;
+ /**
+ * GtkCellRenderer::editing-canceled:
+ * @renderer: the object which received the signal
+ *
+ * This signal gets emitted when the user cancels the process of editing a
+ * cell. For example, an editable cell renderer could be written to cancel
+ * editing when the user presses Escape.
+ *
+ * See also: gtk_cell_renderer_stop_editing().
+ *
+ * Since: 2.4
+ */
+ cell_renderer_signals[EDITING_CANCELED] =
+ g_signal_new (I_("editing-canceled"),
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GtkCellRendererClass, editing_canceled),
+ NULL, NULL,
+ _gtk_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ /**
+ * GtkCellRenderer::editing-started:
+ * @renderer: the object which received the signal
+ * @editable: the #GtkCellEditable
+ * @path: the path identifying the edited cell
+ *
+ * This signal gets emitted when a cell starts to be edited.
+ * The indended use of this signal is to do special setup
+ * on @editable, e.g. adding a #GtkEntryCompletion or setting
+ * up additional columns in a #GtkComboBox.
+ *
+ * Note that GTK+ doesn't guarantee that cell renderers will
+ * continue to use the same kind of widget for editing in future
+ * releases, therefore you should check the type of @editable
+ * before doing any specific setup, as in the following example:
+ *
+ * <informalexample><programlisting>
+ * static void
+ * text_editing_started (GtkCellRenderer *cell,
+ * GtkCellEditable *editable,
+ * const gchar *path,
+ * gpointer data)
+ * {
+ * if (GTK_IS_ENTRY (editable))
+ * {
+ * GtkEntry *entry = GTK_ENTRY (editable);
+ * <!-- -->
+ * /<!-- -->* ... create a GtkEntryCompletion *<!-- -->/
+ * <!-- -->
+ * gtk_entry_set_completion (entry, completion);
+ * }
+ * }
+ * </programlisting></informalexample>
+ *
+ * Since: 2.6
+ */
+ cell_renderer_signals[EDITING_STARTED] =
+ g_signal_new (I_("editing-started"),
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GtkCellRendererClass, editing_started),
+ NULL, NULL,
+ _gtk_marshal_VOID__OBJECT_STRING,
+ G_TYPE_NONE, 2,
+ GTK_TYPE_CELL_EDITABLE,
+ G_TYPE_STRING);
+
g_object_class_install_property (object_class,
PROP_MODE,
g_param_spec_enum ("mode",
- _("mode"),
- _("Editable mode of the CellRenderer"),
+ P_("mode"),
+ P_("Editable mode of the CellRenderer"),
GTK_TYPE_CELL_RENDERER_MODE,
GTK_CELL_RENDERER_MODE_INERT,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_VISIBLE,
g_param_spec_boolean ("visible",
- _("visible"),
- _("Display the cell"),
+ P_("visible"),
+ P_("Display the cell"),
+ TRUE,
+ GTK_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_SENSITIVE,
+ g_param_spec_boolean ("sensitive",
+ P_("Sensitive"),
+ P_("Display the cell sensitive"),
TRUE,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_XALIGN,
g_param_spec_float ("xalign",
- _("xalign"),
- _("The x-align"),
+ P_("xalign"),
+ P_("The x-align"),
0.0,
1.0,
- 0.0,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ 0.5,
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_YALIGN,
g_param_spec_float ("yalign",
- _("yalign"),
- _("The y-align"),
+ P_("yalign"),
+ P_("The y-align"),
0.0,
1.0,
0.5,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_XPAD,
g_param_spec_uint ("xpad",
- _("xpad"),
- _("The xpad"),
+ P_("xpad"),
+ P_("The xpad"),
+ 0,
+ G_MAXUINT,
0,
- 100,
- 2,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_YPAD,
g_param_spec_uint ("ypad",
- _("ypad"),
- _("The ypad"),
+ P_("ypad"),
+ P_("The ypad"),
0,
- 100,
- 2,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ G_MAXUINT,
+ 0,
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_WIDTH,
g_param_spec_int ("width",
- _("width"),
- _("The fixed width"),
+ P_("width"),
+ P_("The fixed width"),
-1,
- 100,
+ G_MAXINT,
-1,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_HEIGHT,
g_param_spec_int ("height",
- _("height"),
- _("The fixed height"),
+ P_("height"),
+ P_("The fixed height"),
-1,
- 100,
+ G_MAXINT,
-1,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_IS_EXPANDER,
- g_param_spec_boolean ("is_expander",
- _("Is Expander"),
- _("Row has children"),
+ g_param_spec_boolean ("is-expander",
+ P_("Is Expander"),
+ P_("Row has children"),
FALSE,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_IS_EXPANDED,
- g_param_spec_boolean ("is_expanded",
- _("Is Expanded"),
- _("Row is an expander row, and is expanded"),
+ g_param_spec_boolean ("is-expanded",
+ P_("Is Expanded"),
+ P_("Row is an expander row, and is expanded"),
FALSE,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_CELL_BACKGROUND,
- g_param_spec_string ("cell_background",
- _("Cell background color name"),
- _("Cell background color as a string"),
+ g_param_spec_string ("cell-background",
+ P_("Cell background color name"),
+ P_("Cell background color as a string"),
NULL,
- G_PARAM_WRITABLE));
+ GTK_PARAM_WRITABLE));
g_object_class_install_property (object_class,
PROP_CELL_BACKGROUND_GDK,
- g_param_spec_boxed ("cell_background_gdk",
- _("Cell background color"),
- _("Cell background color as a GdkColor"),
+ g_param_spec_boxed ("cell-background-gdk",
+ P_("Cell background color"),
+ P_("Cell background color as a GdkColor"),
GDK_TYPE_COLOR,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
+
+#define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, GTK_PARAM_READWRITE))
-#define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE))
+ ADD_SET_PROP ("cell-background-set", PROP_CELL_BACKGROUND_SET,
+ P_("Cell background set"),
+ P_("Whether this tag affects the cell background color"));
- ADD_SET_PROP ("cell_background_set", PROP_CELL_BACKGROUND_SET,
- _("Cell background set"),
- _("Whether this tag affects the cell background color"));
+ g_type_class_add_private (object_class, sizeof (GtkCellRendererPrivate));
}
static void
GParamSpec *pspec)
{
GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
- GtkCellRendererInfo *cellinfo = g_object_get_data (object, CELLINFO_KEY);
+ GtkCellRendererPrivate *priv = GTK_CELL_RENDERER_GET_PRIVATE (object);
switch (param_id)
{
case PROP_VISIBLE:
g_value_set_boolean (value, cell->visible);
break;
+ case PROP_SENSITIVE:
+ g_value_set_boolean (value, cell->sensitive);
+ break;
case PROP_XALIGN:
g_value_set_float (value, cell->xalign);
break;
g_value_set_int (value, cell->height);
break;
case PROP_IS_EXPANDER:
- g_value_set_int (value, cell->is_expander);
+ g_value_set_boolean (value, cell->is_expander);
break;
case PROP_IS_EXPANDED:
- g_value_set_int (value, cell->is_expanded);
+ g_value_set_boolean (value, cell->is_expanded);
break;
case PROP_CELL_BACKGROUND_GDK:
{
GdkColor color;
- color.red = cellinfo->cell_background.red;
- color.green = cellinfo->cell_background.green;
- color.blue = cellinfo->cell_background.blue;
+ color.red = priv->cell_background.red;
+ color.green = priv->cell_background.green;
+ color.blue = priv->cell_background.blue;
g_value_set_boxed (value, &color);
}
case PROP_VISIBLE:
cell->visible = g_value_get_boolean (value);
break;
+ case PROP_SENSITIVE:
+ cell->sensitive = g_value_get_boolean (value);
+ break;
case PROP_XALIGN:
cell->xalign = g_value_get_float (value);
break;
else
g_warning ("Don't know color `%s'", g_value_get_string (value));
- g_object_notify (object, "cell_background_gdk");
+ g_object_notify (object, "cell-background-gdk");
}
break;
case PROP_CELL_BACKGROUND_GDK:
set_cell_bg_color (GtkCellRenderer *cell,
GdkColor *color)
{
- GtkCellRendererInfo *cellinfo = g_object_get_data (G_OBJECT (cell), CELLINFO_KEY);
+ GtkCellRendererPrivate *priv = GTK_CELL_RENDERER_GET_PRIVATE (cell);
if (color)
{
if (!cell->cell_background_set)
{
cell->cell_background_set = TRUE;
- g_object_notify (G_OBJECT (cell), "cell_background_set");
+ g_object_notify (G_OBJECT (cell), "cell-background-set");
}
- cellinfo->cell_background.red = color->red;
- cellinfo->cell_background.green = color->green;
- cellinfo->cell_background.blue = color->blue;
+ priv->cell_background.red = color->red;
+ priv->cell_background.green = color->green;
+ priv->cell_background.blue = color->blue;
}
else
{
if (cell->cell_background_set)
{
cell->cell_background_set = FALSE;
- g_object_notify (G_OBJECT (cell), "cell_background_set");
+ g_object_notify (G_OBJECT (cell), "cell-background-set");
}
}
}
* @width: location to return width needed to render a cell, or %NULL
* @height: location to return height needed to render a cell, or %NULL
*
- * Obtains the width and height needed to render the cell. Used by view widgets
- * to determine the appropriate size for the cell_area passed to
- * gtk_cell_renderer_render(). If @cell_area is not %NULL, fills in the x and y
- * offsets (if set) of the cell relative to this location. Please note that the
- * values set in @width and @height, as well as those in @x_offset and @y_offset
- * are inclusive of the xpad and ypad properties.
+ * Obtains the width and height needed to render the cell. Used by view
+ * widgets to determine the appropriate size for the cell_area passed to
+ * gtk_cell_renderer_render(). If @cell_area is not %NULL, fills in the
+ * x and y offsets (if set) of the cell relative to this location.
+ *
+ * Please note that the values set in @width and @height, as well as those
+ * in @x_offset and @y_offset are inclusive of the xpad and ypad properties.
**/
void
gtk_cell_renderer_get_size (GtkCellRenderer *cell,
* @cell: a #GtkCellRenderer
* @window: a #GdkDrawable to draw to
* @widget: the widget owning @window
- * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
+ * @background_area: entire cell area (including tree expanders and maybe
+ * padding on the sides)
* @cell_area: area normally rendered by a cell renderer
* @expose_area: area that actually needs updating
* @flags: flags that affect rendering
* blank space around the cell, and also the area containing the tree expander;
* so the @background_area rectangles for all cells tile to cover the entire
* @window. @expose_area is a clip rectangle.
- *
**/
void
gtk_cell_renderer_render (GtkCellRenderer *cell,
GtkCellRendererState flags)
{
gboolean selected = FALSE;
- GtkCellRendererInfo *cellinfo = g_object_get_data (G_OBJECT (cell), CELLINFO_KEY);
+ GtkCellRendererPrivate *priv = GTK_CELL_RENDERER_GET_PRIVATE (cell);
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
if (cell->cell_background_set && !selected)
{
- GdkColor color;
- GdkGC *gc;
-
- color.red = cellinfo->cell_background.red;
- color.green = cellinfo->cell_background.green;
- color.blue = cellinfo->cell_background.blue;
-
- gc = gdk_gc_new (window);
- gdk_gc_set_rgb_fg_color (gc, &color);
- gdk_draw_rectangle (window, gc, TRUE,
- background_area->x, background_area->y,
- background_area->width, background_area->height);
- g_object_unref (gc);
+ cairo_t *cr = gdk_cairo_create (window);
+
+ gdk_cairo_rectangle (cr, background_area);
+ gdk_cairo_set_source_color (cr, &priv->cell_background);
+ cairo_fill (cr);
+
+ cairo_destroy (cr);
}
GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
* @cell: a #GtkCellRenderer
* @event: a #GdkEvent
* @widget: widget that received the event
- * @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
- * @background_area: background area as passed to @gtk_cell_renderer_render
- * @cell_area: cell area as passed to @gtk_cell_renderer_render
+ * @path: widget-dependent string representation of the event location;
+ * e.g. for #GtkTreeView, a string representation of #GtkTreePath
+ * @background_area: background area as passed to gtk_cell_renderer_render()
+ * @cell_area: cell area as passed to gtk_cell_renderer_render()
* @flags: render flags
*
- * Passes an activate event to the cell renderer for possible processing. Some
- * cell renderers may use events; for example, #GtkCellRendererToggle toggles
- * when it gets a mouse click.
+ * Passes an activate event to the cell renderer for possible processing.
+ * Some cell renderers may use events; for example, #GtkCellRendererToggle
+ * toggles when it gets a mouse click.
*
* Return value: %TRUE if the event was consumed/handled
**/
* @cell: a #GtkCellRenderer
* @event: a #GdkEvent
* @widget: widget that received the event
- * @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
- * @background_area: background area as passed to @gtk_cell_renderer_render
- * @cell_area: cell area as passed to @gtk_cell_renderer_render
+ * @path: widget-dependent string representation of the event location;
+ * e.g. for #GtkTreeView, a string representation of #GtkTreePath
+ * @background_area: background area as passed to gtk_cell_renderer_render()
+ * @cell_area: cell area as passed to gtk_cell_renderer_render()
* @flags: render flags
*
* Passes an activate event to the cell renderer for possible processing.
GtkCellRendererState flags)
{
+ GtkCellEditable *editable;
+
g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
if (cell->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
return NULL;
-
- return GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
- event,
- widget,
- path,
- background_area,
- cell_area,
- flags);
+ editable = GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
+ event,
+ widget,
+ path,
+ background_area,
+ cell_area,
+ flags);
+
+ g_signal_emit (cell,
+ cell_renderer_signals[EDITING_STARTED], 0,
+ editable, path);
+
+ cell->editing = TRUE;
+
+ return editable;
}
/**
if (height)
(* height) = cell->height;
}
+
+/**
+ * gtk_cell_renderer_editing_canceled:
+ * @cell: A #GtkCellRenderer
+ *
+ * Causes the cell renderer to emit the #GtkCellRenderer::editing-canceled
+ * signal.
+ *
+ * This function is for use only by implementations of cell renderers that
+ * need to notify the client program that an editing process was canceled
+ * and the changes were not committed.
+ *
+ * Since: 2.4
+ * Deprecated: 2.6: Use gtk_cell_renderer_stop_editing() instead
+ **/
+void
+gtk_cell_renderer_editing_canceled (GtkCellRenderer *cell)
+{
+ g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+
+ gtk_cell_renderer_stop_editing (cell, TRUE);
+}
+
+/**
+ * gtk_cell_renderer_stop_editing:
+ * @cell: A #GtkCellRenderer
+ * @canceled: %TRUE if the editing has been canceled
+ *
+ * Informs the cell renderer that the editing is stopped.
+ * If @canceled is %TRUE, the cell renderer will emit the
+ * #GtkCellRenderer::editing-canceled signal.
+ *
+ * This function should be called by cell renderer implementations
+ * in response to the #GtkCellEditable::editing-done signal of
+ * #GtkCellEditable.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
+ gboolean canceled)
+{
+ g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+
+ if (cell->editing)
+ {
+ cell->editing = FALSE;
+ if (canceled)
+ g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
+ }
+}
+
+#define __GTK_CELL_RENDERER_C__
+#include "gtkaliasdef.c"