summaryrefslogtreecommitdiff
path: root/gtk/gtkcellrenderercombo.c
diff options
context:
space:
mode:
authorKristian Rietveld <kris@gtk.org>2008-06-08 22:25:57 +0000
committerKristian Rietveld <kristian@src.gnome.org>2008-06-08 22:25:57 +0000
commit0e3d5fb732ab046943435c04d035ed316fd6c6d4 (patch)
tree3f02fe8ea9c8fdf890116f7db4f635a98a40c757 /gtk/gtkcellrenderercombo.c
parent6dfbe3b4f8e6a1f9f8e9b494c21da35618684936 (diff)
downloadgtk+-0e3d5fb732ab046943435c04d035ed316fd6c6d4.tar.gz
Bug 526987 - GtkCellRendererCombo should allow model to be NULL
2008-06-09 Kristian Rietveld <kris@gtk.org> Bug 526987 - GtkCellRendererCombo should allow model to be NULL * gtk/gtkcellrenderercombo.c (gtk_cell_renderer_combo_class_init), (gtk_cell_renderer_combo_set_property), (gtk_cell_renderer_combo_editing_done), (gtk_cell_renderer_combo_start_editing): introduce private class struct, allow model to be set to NULL. svn path=/trunk/; revision=20340
Diffstat (limited to 'gtk/gtkcellrenderercombo.c')
-rw-r--r--gtk/gtkcellrenderercombo.c81
1 files changed, 65 insertions, 16 deletions
diff --git a/gtk/gtkcellrenderercombo.c b/gtk/gtkcellrenderercombo.c
index 6411ef2618..104dbb5b6c 100644
--- a/gtk/gtkcellrenderercombo.c
+++ b/gtk/gtkcellrenderercombo.c
@@ -32,6 +32,16 @@
#include "gtkprivate.h"
#include "gtkalias.h"
+
+#define GTK_CELL_RENDERER_COMBO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER_COMBO, GtkCellRendererComboPrivate))
+
+typedef struct _GtkCellRendererComboPrivate GtkCellRendererComboPrivate;
+struct _GtkCellRendererComboPrivate
+{
+ GtkWidget *combo;
+};
+
+
static void gtk_cell_renderer_combo_class_init (GtkCellRendererComboClass *klass);
static void gtk_cell_renderer_combo_init (GtkCellRendererCombo *self);
static void gtk_cell_renderer_combo_finalize (GObject *object);
@@ -173,6 +183,8 @@ gtk_cell_renderer_combo_class_init (GtkCellRendererComboClass *klass)
G_TYPE_NONE, 2,
G_TYPE_STRING,
GTK_TYPE_TREE_ITER);
+
+ g_type_class_add_private (klass, sizeof (GtkCellRendererComboPrivate));
}
static void
@@ -257,17 +269,28 @@ gtk_cell_renderer_combo_set_property (GObject *object,
case PROP_MODEL:
{
GObject *object;
+ GtkCellRendererComboPrivate *priv;
- object = g_value_get_object (value);
- g_return_if_fail (GTK_IS_TREE_MODEL (object));
- g_object_ref (object);
+ priv = GTK_CELL_RENDERER_COMBO_GET_PRIVATE (cell);
if (cell->model)
{
+ if (priv->combo)
+ gtk_combo_box_set_model (GTK_COMBO_BOX (priv->combo), NULL);
g_object_unref (cell->model);
cell->model = NULL;
}
- cell->model = GTK_TREE_MODEL (object);
+
+ object = g_value_get_object (value);
+ if (object)
+ {
+ g_return_if_fail (GTK_IS_TREE_MODEL (object));
+ g_object_ref (object);
+
+ cell->model = GTK_TREE_MODEL (object);
+ if (priv->combo)
+ gtk_combo_box_set_model (GTK_COMBO_BOX (priv->combo), cell->model);
+ }
break;
}
case PROP_TEXT_COLUMN:
@@ -312,8 +335,10 @@ gtk_cell_renderer_combo_editing_done (GtkCellEditable *combo,
GtkCellRendererCombo *cell;
GtkEntry *entry;
gboolean canceled;
+ GtkCellRendererComboPrivate *priv;
cell = GTK_CELL_RENDERER_COMBO (data);
+ priv = GTK_CELL_RENDERER_COMBO_GET_PRIVATE (data);
if (cell->focus_out_id > 0)
{
@@ -324,7 +349,10 @@ gtk_cell_renderer_combo_editing_done (GtkCellEditable *combo,
canceled = _gtk_combo_box_editing_canceled (GTK_COMBO_BOX (combo));
gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (data), canceled);
if (canceled)
- return;
+ {
+ priv->combo = NULL;
+ return;
+ }
if (GTK_IS_COMBO_BOX_ENTRY (combo))
{
@@ -334,13 +362,17 @@ gtk_cell_renderer_combo_editing_done (GtkCellEditable *combo,
else
{
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
- if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
- gtk_tree_model_get (model, &iter, cell->text_column, &new_text, -1);
+
+ if (model
+ && gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
+ gtk_tree_model_get (model, &iter, cell->text_column, &new_text, -1);
}
path = g_object_get_data (G_OBJECT (combo), GTK_CELL_RENDERER_COMBO_PATH);
g_signal_emit_by_name (cell, "edited", path, new_text);
+ priv->combo = NULL;
+
g_free (new_text);
}
@@ -397,18 +429,26 @@ gtk_cell_renderer_combo_start_editing (GtkCellRenderer *cell,
GtkCellRendererText *cell_text;
GtkWidget *combo;
SearchData search_data;
+ GtkCellRendererComboPrivate *priv;
cell_text = GTK_CELL_RENDERER_TEXT (cell);
if (cell_text->editable == FALSE)
return NULL;
cell_combo = GTK_CELL_RENDERER_COMBO (cell);
- if (cell_combo->model == NULL || cell_combo->text_column < 0)
+ if (cell_combo->text_column < 0)
return NULL;
+ priv = GTK_CELL_RENDERER_COMBO_GET_PRIVATE (cell_combo);
+
if (cell_combo->has_entry)
{
- combo = gtk_combo_box_entry_new_with_model (cell_combo->model, cell_combo->text_column);
+ combo = gtk_combo_box_entry_new ();
+
+ if (cell_combo->model)
+ gtk_combo_box_set_model (GTK_COMBO_BOX (combo), cell_combo->model);
+ gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (combo),
+ cell_combo->text_column);
if (cell_text->text)
gtk_entry_set_text (GTK_ENTRY (GTK_BIN (combo)->child),
@@ -417,19 +457,26 @@ gtk_cell_renderer_combo_start_editing (GtkCellRenderer *cell,
else
{
cell = gtk_cell_renderer_text_new ();
- combo = gtk_combo_box_new_with_model (cell_combo->model);
+
+ combo = gtk_combo_box_new ();
+ if (cell_combo->model)
+ gtk_combo_box_set_model (GTK_COMBO_BOX (combo), cell_combo->model);
+
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo),
cell, "text", cell_combo->text_column,
NULL);
/* determine the current value */
- search_data.cell = cell_combo;
- search_data.found = FALSE;
- gtk_tree_model_foreach (cell_combo->model, find_text, &search_data);
- if (search_data.found)
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo),
- &(search_data.iter));
+ if (cell_combo->model)
+ {
+ search_data.cell = cell_combo;
+ search_data.found = FALSE;
+ gtk_tree_model_foreach (cell_combo->model, find_text, &search_data);
+ if (search_data.found)
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo),
+ &(search_data.iter));
+ }
}
g_object_set (combo, "has-frame", FALSE, NULL);
@@ -450,6 +497,8 @@ gtk_cell_renderer_combo_start_editing (GtkCellRenderer *cell,
G_CALLBACK (gtk_cell_renderer_combo_focus_out_event),
cell_combo);
+ priv->combo = combo;
+
return GTK_CELL_EDITABLE (combo);
}