#include <config.h>
#include <string.h>
-#include "gtkalias.h"
#include "gtkintl.h"
#include "gtkbin.h"
#include "gtkentry.h"
#include "gtkcellrenderertext.h"
#include "gtkcombobox.h"
#include "gtkcomboboxentry.h"
+#include "gtkprivate.h"
+#include "gtkalias.h"
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);
static void gtk_cell_renderer_combo_get_property (GObject *object,
guint prop_id,
GValue *value,
PROP_HAS_ENTRY
};
-static GObjectClass *parent_class = NULL;
-
#define GTK_CELL_RENDERER_COMBO_PATH "gtk-cell-renderer-combo-path"
-GType
-gtk_cell_renderer_combo_get_type (void)
-{
- static GType gtk_cell_renderer_combo_type = 0;
-
- if (!gtk_cell_renderer_combo_type)
- {
- static const GTypeInfo gtk_cell_renderer_combo_info =
- {
- sizeof (GtkCellRendererComboClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gtk_cell_renderer_combo_class_init,
- NULL,
- NULL,
- sizeof (GtkCellRendererCombo),
- 0,
- (GInstanceInitFunc) gtk_cell_renderer_combo_init
- };
- gtk_cell_renderer_combo_type =
- g_type_register_static (GTK_TYPE_CELL_RENDERER_TEXT,
- "GtkCellRendererCombo",
- >k_cell_renderer_combo_info,
- 0);
- }
- return gtk_cell_renderer_combo_type;
-}
+G_DEFINE_TYPE (GtkCellRendererCombo, gtk_cell_renderer_combo, GTK_TYPE_CELL_RENDERER_TEXT)
static void
gtk_cell_renderer_combo_class_init (GtkCellRendererComboClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
+ object_class->finalize = gtk_cell_renderer_combo_finalize;
object_class->get_property = gtk_cell_renderer_combo_get_property;
object_class->set_property = gtk_cell_renderer_combo_set_property;
/**
* GtkCellRendererCombo:model:
*
- * The :model property holds a tree model containing the possible
- * values for the combo box. Use the :text_column property to specify
- * the column holding the values.
+ * Holds a tree model containing the possible values for the combo box.
+ * Use the text_column property to specify the column holding the values.
*
* Since: 2.6
*/
P_("Model"),
P_("The model containing the possible values for the combo box"),
GTK_TYPE_TREE_MODEL,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
/**
- * GtkCellRendererCombo:text_column:
+ * GtkCellRendererCombo:text-column:
+ *
+ * Specifies the model column which holds the possible values for the
+ * combo box.
*
- * The :text_column property specifies the model column which
- * holds the possible values for the combo box. Note that this
- * refers to the model specified in the :model property,
- * <emphasis>not</emphasis> the model backing the tree view to
- * which this cell renderer is attached.
+ * Note that this refers to the model specified in the model property,
+ * <emphasis>not</emphasis> the model backing the tree view to which
+ * this cell renderer is attached.
*
+ * #GtkCellRendererCombo automatically adds a text cell renderer for
+ * this column to its combo box.
+ *
* Since: 2.6
*/
g_object_class_install_property (object_class,
PROP_TEXT_COLUMN,
- g_param_spec_int ("text_column",
+ g_param_spec_int ("text-column",
P_("Text Column"),
P_("A column in the data source model to get the strings from"),
-1,
G_MAXINT,
-1,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
/**
- * GtkCellRendererCombo:has_entry:
+ * GtkCellRendererCombo:has-entry:
*
- * If the :has_entry property is %TRUe, the cell renderer will
- * include an entry and allow to enter values other than the ones
- * in the popup list.
+ * If %TRUE, the cell renderer will include an entry and allow to enter
+ * values other than the ones in the popup list.
*
* Since: 2.6
*/
g_object_class_install_property (object_class,
PROP_HAS_ENTRY,
- g_param_spec_boolean ("has_entry",
+ g_param_spec_boolean ("has-entry",
P_("Has Entry"),
- P_("If %FALSE, don't allow to enter strings other than the chosen ones"),
+ P_("If FALSE, don't allow to enter strings other than the chosen ones"),
TRUE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
}
{
self->model = NULL;
self->text_column = -1;
+ self->has_entry = TRUE;
self->focus_out_id = 0;
}
/**
* gtk_cell_renderer_combo_new:
*
- * Creates a new #GtkCellRendererCombo
+ * Creates a new #GtkCellRendererCombo.
* Adjust how text is drawn using object properties.
* Object properties can be set globally (with g_object_set()).
* Also, with #GtkTreeViewColumn, you can bind a property to a value
return g_object_new (GTK_TYPE_CELL_RENDERER_COMBO, NULL);
}
+static void
+gtk_cell_renderer_combo_finalize (GObject *object)
+{
+ GtkCellRendererCombo *cell = GTK_CELL_RENDERER_COMBO (object);
+
+ if (cell->model)
+ {
+ g_object_unref (cell->model);
+ cell->model = NULL;
+ }
+
+ G_OBJECT_CLASS (gtk_cell_renderer_combo_parent_class)->finalize (object);
+}
+
static void
gtk_cell_renderer_combo_get_property (GObject *object,
guint prop_id,
switch (prop_id)
{
case PROP_MODEL:
- cell->model = g_value_get_object (value);
- break;
+ {
+ GObject *object;
+
+ object = g_value_get_object (value);
+ g_return_if_fail (GTK_IS_TREE_MODEL (object));
+ g_object_ref (object);
+
+ if (cell->model)
+ {
+ g_object_unref (cell->model);
+ cell->model = NULL;
+ }
+ cell->model = GTK_TREE_MODEL (object);
+ break;
+ }
case PROP_TEXT_COLUMN:
cell->text_column = g_value_get_int (value);
break;
GtkTreeIter iter;
GtkCellRendererCombo *cell;
GtkEntry *entry;
+ gboolean canceled;
cell = GTK_CELL_RENDERER_COMBO (data);
g_signal_handler_disconnect (combo, cell->focus_out_id);
cell->focus_out_id = 0;
}
-
- if (_gtk_combo_box_editing_canceled (GTK_COMBO_BOX (combo)))
- {
- gtk_cell_renderer_editing_canceled (GTK_CELL_RENDERER (data));
- return;
- }
+
+ canceled = _gtk_combo_box_editing_canceled (GTK_COMBO_BOX (combo));
+ gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (data), canceled);
+ if (canceled)
+ return;
if (GTK_IS_COMBO_BOX_ENTRY (combo))
{
search_data->iter = *iter;
search_data->found = TRUE;
}
+
+ g_free (text);
return search_data->found;
}
&(search_data.iter));
}
- g_object_set (combo, "has_frame", FALSE, NULL);
+ g_object_set (combo, "has-frame", FALSE, NULL);
g_object_set_data_full (G_OBJECT (combo),
- GTK_CELL_RENDERER_COMBO_PATH,
+ I_(GTK_CELL_RENDERER_COMBO_PATH),
g_strdup (path), g_free);
gtk_widget_show (combo);
return GTK_CELL_EDITABLE (combo);
}
+
+#define __GTK_CELL_RENDERER_COMBO_C__
+#include "gtkaliasdef.c"