29 #include <glib/gi18n.h> 31 #include "search-core-utils.h" 35 search_combo_changed (GtkWidget *widget, gint *value)
40 g_return_if_fail(GTK_IS_COMBO_BOX(widget));
41 g_return_if_fail(value);
43 model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
44 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter))
47 gtk_tree_model_get(model, &iter,
48 GNC_COMBO_SEARCH_COL_VALUE, value,
53 gnc_combo_box_new_search (
void)
57 GtkCellRenderer *renderer;
59 store = gtk_list_store_new(NUM_GNC_COMBO_SEARCH_COLS, G_TYPE_STRING, G_TYPE_UINT);
60 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
61 g_object_unref(store);
63 renderer = gtk_cell_renderer_text_new ();
64 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
65 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
66 "text", GNC_COMBO_SEARCH_COL_TEXT,
72 gnc_combo_box_search_add (GtkComboBox *combo,
const gchar *text, guint value)
77 g_return_if_fail(GTK_IS_COMBO_BOX(combo));
78 g_return_if_fail(text);
80 store = GTK_LIST_STORE(gtk_combo_box_get_model(combo));
81 gtk_list_store_append(store, &iter);
82 gtk_list_store_set(store, &iter,
83 GNC_COMBO_SEARCH_COL_TEXT, text,
84 GNC_COMBO_SEARCH_COL_VALUE, value,
89 gnc_combo_box_search_get_active (GtkComboBox *combo)
95 g_return_val_if_fail(GTK_IS_COMBO_BOX(combo), 0);
97 model = gtk_combo_box_get_model(combo);
98 if (!gtk_combo_box_get_active_iter(combo, &iter))
101 gtk_tree_model_get(model, &iter,
102 GNC_COMBO_SEARCH_COL_VALUE, &value,
108 gnc_combo_box_search_set_active (GtkComboBox *combo, guint value)
114 g_return_if_fail(GTK_IS_COMBO_BOX(combo));
116 model = gtk_combo_box_get_model(combo);
117 if (!gtk_tree_model_get_iter_first(model, &iter))
122 gtk_tree_model_get(model, &iter,
123 GNC_COMBO_SEARCH_COL_VALUE, &row_value,
125 if (value == row_value)
127 gtk_combo_box_set_active_iter(combo, &iter);
131 while (gtk_tree_model_iter_next(model, &iter));
134 gtk_combo_box_set_active(combo, 0);
138 gnc_combo_box_search_changed(GtkComboBox *combo, guint *value)
140 g_signal_connect (combo,
"changed",
141 G_CALLBACK (search_combo_changed), value);