From 9aeba99da095f26ba535e4b2fb0797943309a851 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 20 Jul 2004 16:06:02 +0000 Subject: [PATCH] Allow custom initialization of cell editables. (#147221) 2004-07-20 Matthias Clasen Allow custom initialization of cell editables. (#147221) * gtk/gtkcellrenderer.h (struct _GtkCellRendererClass): * gtk/gtkcellrenderer.c (gtk_cell_renderer_class_init): Add a ::editing-started signal as a hook for setting up the GtkCellEditable. (gtk_cell_renderer_start_editing): ...and emit it here. --- ChangeLog | 10 ++++++ ChangeLog.pre-2-10 | 10 ++++++ ChangeLog.pre-2-6 | 10 ++++++ ChangeLog.pre-2-8 | 10 ++++++ gtk/gtkcellrenderer.c | 73 +++++++++++++++++++++++++++++++++++++------ gtk/gtkcellrenderer.h | 4 ++- 6 files changed, 107 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d3c335751..bfd6b74925 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-07-20 Matthias Clasen + + Allow custom initialization of cell editables. (#147221) + + * gtk/gtkcellrenderer.h (struct _GtkCellRendererClass): + * gtk/gtkcellrenderer.c (gtk_cell_renderer_class_init): Add a + ::editing-started signal as a hook for setting up the + GtkCellEditable. + (gtk_cell_renderer_start_editing): ...and emit it here. + Mon Jul 19 23:51:50 2004 Matthias Clasen * gtk/gtktreeview.c (gtk_tree_view_button_press): Set drag_pos diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 2d3c335751..bfd6b74925 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,13 @@ +2004-07-20 Matthias Clasen + + Allow custom initialization of cell editables. (#147221) + + * gtk/gtkcellrenderer.h (struct _GtkCellRendererClass): + * gtk/gtkcellrenderer.c (gtk_cell_renderer_class_init): Add a + ::editing-started signal as a hook for setting up the + GtkCellEditable. + (gtk_cell_renderer_start_editing): ...and emit it here. + Mon Jul 19 23:51:50 2004 Matthias Clasen * gtk/gtktreeview.c (gtk_tree_view_button_press): Set drag_pos diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 2d3c335751..bfd6b74925 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,13 @@ +2004-07-20 Matthias Clasen + + Allow custom initialization of cell editables. (#147221) + + * gtk/gtkcellrenderer.h (struct _GtkCellRendererClass): + * gtk/gtkcellrenderer.c (gtk_cell_renderer_class_init): Add a + ::editing-started signal as a hook for setting up the + GtkCellEditable. + (gtk_cell_renderer_start_editing): ...and emit it here. + Mon Jul 19 23:51:50 2004 Matthias Clasen * gtk/gtktreeview.c (gtk_tree_view_button_press): Set drag_pos diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 2d3c335751..bfd6b74925 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,13 @@ +2004-07-20 Matthias Clasen + + Allow custom initialization of cell editables. (#147221) + + * gtk/gtkcellrenderer.h (struct _GtkCellRendererClass): + * gtk/gtkcellrenderer.c (gtk_cell_renderer_class_init): Add a + ::editing-started signal as a hook for setting up the + GtkCellEditable. + (gtk_cell_renderer_start_editing): ...and emit it here. + Mon Jul 19 23:51:50 2004 Matthias Clasen * gtk/gtktreeview.c (gtk_tree_view_button_press): Set drag_pos diff --git a/gtk/gtkcellrenderer.c b/gtk/gtkcellrenderer.c index c6d7fd3052..446475169c 100644 --- a/gtk/gtkcellrenderer.c +++ b/gtk/gtkcellrenderer.c @@ -67,6 +67,7 @@ enum { /* Signal IDs */ enum { EDITING_CANCELED, + EDITING_STARTED, LAST_SIGNAL }; @@ -134,13 +135,12 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *class) * * 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), @@ -150,6 +150,53 @@ gtk_cell_renderer_class_init (GtkCellRendererClass *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: + * + * + * 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); + * } + * } + * + * + * 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", @@ -629,6 +676,8 @@ gtk_cell_renderer_start_editing (GtkCellRenderer *cell, GtkCellRendererState flags) { + GtkCellEditable *editable; + g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL); if (cell->mode != GTK_CELL_RENDERER_MODE_EDITABLE) @@ -638,13 +687,19 @@ gtk_cell_renderer_start_editing (GtkCellRenderer *cell, 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); + + return editable; } /** diff --git a/gtk/gtkcellrenderer.h b/gtk/gtkcellrenderer.h index d6cab83c45..01e882419a 100644 --- a/gtk/gtkcellrenderer.h +++ b/gtk/gtkcellrenderer.h @@ -110,11 +110,13 @@ struct _GtkCellRendererClass /* Signals */ void (* editing_canceled) (GtkCellRenderer *cell); + void (* editing_started) (GtkCellRenderer *cell, + GtkCellEditable *editable, + const gchar *path); /* Padding for future expansion */ void (*_gtk_reserved1) (void); void (*_gtk_reserved2) (void); - void (*_gtk_reserved3) (void); }; GType gtk_cell_renderer_get_type (void) G_GNUC_CONST;