* 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);
PROP_ZERO,
PROP_MODE,
PROP_VISIBLE,
+ PROP_SENSITIVE,
PROP_XALIGN,
PROP_YALIGN,
PROP_XPAD,
/* Signal IDs */
enum {
EDITING_CANCELED,
+ EDITING_STARTED,
LAST_SIGNAL
};
cell->yalign = 0.5;
cell->xpad = 0;
cell->ypad = 0;
+ cell->sensitive = TRUE;
+ cell->is_expander = FALSE;
+ cell->is_expanded = FALSE;
+ cell->editing = FALSE;
}
static void
/**
* 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.
+ * editing when the user presses Escape.
*
* See also: gtk_cell_renderer_editing_canceled()
*
* Since: 2.4
*/
-
cell_renderer_signals[EDITING_CANCELED] =
g_signal_new ("editing-canceled",
G_OBJECT_CLASS_TYPE (object_class),
_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 ("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",
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,
P_("visible"),
P_("Display the cell"),
TRUE,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ 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,
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_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,
0.0,
1.0,
0.5,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_XPAD,
P_("xpad"),
P_("The xpad"),
0,
- 100,
- 2,
- G_PARAM_READABLE |
- G_PARAM_WRITABLE));
+ G_MAXUINT,
+ 0,
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_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,
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,
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",
+ 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",
+ 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",
+ 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",
+ 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, G_PARAM_READABLE | G_PARAM_WRITABLE))
+#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))
- ADD_SET_PROP ("cell_background_set", PROP_CELL_BACKGROUND_SET,
+ ADD_SET_PROP ("cell-background-set", PROP_CELL_BACKGROUND_SET,
P_("Cell background set"),
P_("Whether this tag affects the cell background color"));
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;
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:
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");
}
priv->cell_background.red = color->red;
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");
}
}
}
if (cell->cell_background_set && !selected)
{
- GdkColor color;
- GdkGC *gc;
-
- color.red = priv->cell_background.red;
- color.green = priv->cell_background.green;
- color.blue = priv->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,
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;
}
/**
* changes were not committed.
*
* Since: 2.4
+ * Deprecated: Use gtk_cell_renderer_stop_editing() instead
**/
void
gtk_cell_renderer_editing_canceled (GtkCellRenderer *cell)
{
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
- g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
+ 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 "editing-canceled"
+ * signal. This function should be called by cell renderer implementations
+ * in response to the "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"