3 * Copyright (C) 2001-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "combo-util.h"
27 #include <libglabels.h>
30 /****************************************************************************/
31 /* Convienience function to set strings in a text combo_box from a GList */
32 /****************************************************************************/
34 gl_combo_util_set_strings (GtkComboBox *combo,
40 g_return_if_fail (list);
42 model = gtk_combo_box_get_model(combo);
43 gtk_list_store_clear (GTK_LIST_STORE (model));
45 for (p=list; p!=NULL; p=p->next) {
47 gtk_combo_box_append_text (combo, p->data);
53 /*---------------------------------------------------------------------------*/
54 /* PRIVATE. gl_combo_util_set_active_text support. */
55 /*---------------------------------------------------------------------------*/
64 search_text_func (GtkTreeModel *model,
69 TextSearchData *search_data = (TextSearchData *)data;
72 gtk_tree_model_get (model, iter, 0, &text, -1);
74 if (strcmp (text,search_data->text) == 0) {
75 search_data->found = TRUE;
76 search_data->iter = *iter;
85 /****************************************************************************/
86 /* Convienience function to set active text in a text combo_box from text */
87 /****************************************************************************/
89 gl_combo_util_set_active_text (GtkComboBox *combo,
92 GtkTreeModel *model = gtk_combo_box_get_model(combo);
94 g_return_if_fail (GTK_IS_LIST_STORE (model));
98 gtk_combo_box_set_active (combo, -1);
101 TextSearchData search_data;
103 search_data.text = text;
104 search_data.found = FALSE;
106 gtk_tree_model_foreach (model, search_text_func, &search_data);
107 if (search_data.found) {
108 gtk_combo_box_set_active_iter (combo,
111 gtk_combo_box_set_active (combo, -1);
119 /****************************************************************************/
120 /* Convienience function to add a simple text model to an existing */
121 /* combo_box. This is needed since combo_boxes created with glade do not */
122 /* use the gtk_combo_box_new_text() constructor. */
123 /****************************************************************************/
125 gl_combo_util_add_text_model (GtkComboBox *combo)
127 GtkCellRenderer *cell;
130 store = gtk_list_store_new (1, G_TYPE_STRING);
131 gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
132 g_object_unref (store);
134 cell = gtk_cell_renderer_text_new ();
135 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
136 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
144 * Local Variables: -- emacs
146 * c-basic-offset: 8 -- emacs
147 * tab-width: 8 -- emacs
148 * indent-tabs-mode: nil -- emacs