1 /* modest-combo-box.c */
3 /* insert (c)/licensing information) */
5 #include "modest-combo-box.h"
6 /* include other impl specific header files */
8 /* 'private'/'protected' functions */
9 static void modest_combo_box_class_init (ModestComboBoxClass *klass);
10 static void modest_combo_box_init (ModestComboBox *obj);
11 static void modest_combo_box_finalize (GObject *obj);
26 typedef struct _ModestComboBoxPrivate ModestComboBoxPrivate;
27 struct _ModestComboBoxPrivate {
28 /* my private members go here, eg. */
29 /* gboolean frobnicate_mode; */
31 #define MODEST_COMBO_BOX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
32 MODEST_TYPE_COMBO_BOX, \
33 ModestComboBoxPrivate))
35 static GtkComboBoxClass *parent_class = NULL;
37 /* uncomment the following if you have defined any signals */
38 /* static guint signals[LAST_SIGNAL] = {0}; */
41 modest_combo_box_get_type (void)
43 static GType my_type = 0;
45 static const GTypeInfo my_info = {
46 sizeof(ModestComboBoxClass),
48 NULL, /* base finalize */
49 (GClassInitFunc) modest_combo_box_class_init,
50 NULL, /* class finalize */
51 NULL, /* class data */
52 sizeof(ModestComboBox),
54 (GInstanceInitFunc) modest_combo_box_init,
57 my_type = g_type_register_static (GTK_TYPE_COMBO_BOX,
65 modest_combo_box_class_init (ModestComboBoxClass *klass)
67 GObjectClass *gobject_class;
68 gobject_class = (GObjectClass*) klass;
70 parent_class = g_type_class_peek_parent (klass);
71 gobject_class->finalize = modest_combo_box_finalize;
73 g_type_class_add_private (gobject_class, sizeof(ModestComboBoxPrivate));
75 /* signal definitions go here, e.g.: */
76 /* signals[MY_SIGNAL_1] = */
77 /* g_signal_new ("my_signal_1",....); */
78 /* signals[MY_SIGNAL_2] = */
79 /* g_signal_new ("my_signal_2",....); */
84 modest_combo_box_init (ModestComboBox *obj)
86 /* uncomment the following if you init any of the private data */
87 /* ModestComboBoxPrivate *priv = MODEST_COMBO_BOX_GET_PRIVATE(obj); */
89 /* initialize this object, eg.: */
90 /* priv->frobnicate_mode = FALSE; */
94 modest_combo_box_finalize (GObject *obj)
96 /* free/unref instance resources here */
97 G_OBJECT_CLASS(parent_class)->finalize (obj);
102 get_model (ModestComboBoxLemma *lemmas)
106 ModestComboBoxLemma *lemma;
109 return NULL; /* not an error */
111 store = gtk_list_store_new (2,
112 G_TYPE_STRING, /* the display name */
113 G_TYPE_POINTER); /* the id */
115 for (lemma = lemmas; lemma; ++lemma)
116 gtk_list_store_insert_with_values (store, &iter, G_MAXINT,
117 /* FIXME: g_strdup?*/
118 COLUMN_DISPLAY_NAME, lemma->display_name,
119 COLUMN_ID, lemma->id,
121 return GTK_TREE_MODEL (store);
126 modest_combo_box_new (ModestComboBoxLemma *lemmas)
131 obj = g_object_new(MODEST_TYPE_COMBO_BOX, NULL);
133 model = get_model (lemmas);
135 gtk_combo_box_set_model (GTK_COMBO_BOX(obj), model);
136 g_object_unref (model);
138 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT(obj),
139 gtk_cell_renderer_text_new(),
140 "text", COLUMN_DISPLAY_NAME,
142 return GTK_WIDGET(obj);
146 modest_combo_box_get_active_id (ModestComboBox *self)
151 g_return_val_if_fail (self, NULL);
153 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX(self), &iter))
154 retval = NULL; /* nothing found */
159 model = gtk_combo_box_get_model (GTK_COMBO_BOX(self));
161 g_value_init (&val, G_TYPE_POINTER);
162 gtk_tree_model_get_value (model, &iter, COLUMN_ID, &val);
164 retval = g_value_get_pointer (&val);
165 g_value_unset (&val);