2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2006 Andrej Kacian and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include <glib/gi18n.h>
29 typedef struct _combobox_sel_by_data_ctx {
30 GtkComboBox *combobox;
34 static gboolean _select_by_data_func(GtkTreeModel *model, GtkTreePath *path,
35 GtkTreeIter *iter, ComboboxSelCtx *ctx)
37 GtkComboBox *combobox = ctx->combobox;
38 gint data = ctx->data;
41 gtk_tree_model_get(model, iter, 1, &curdata, -1);
42 if (data == curdata) {
43 gtk_combo_box_set_active_iter(combobox, iter);
50 void combobox_select_by_data(GtkComboBox *combobox, gint data)
53 ComboboxSelCtx *ctx = NULL;
54 g_return_if_fail(combobox != NULL);
56 model = gtk_combo_box_get_model(combobox);
58 ctx = g_new(ComboboxSelCtx,
59 sizeof(ComboboxSelCtx));
60 ctx->combobox = combobox;
63 gtk_tree_model_foreach(model, (GtkTreeModelForeachFunc)_select_by_data_func, ctx);
67 gint combobox_get_active_data(GtkComboBox *combobox)
73 g_return_val_if_fail(combobox != NULL, -1);
75 gtk_combo_box_get_active_iter(combobox, &iter);
77 model = gtk_combo_box_get_model(combobox);
79 gtk_tree_model_get(model, &iter, 1, &data, -1);
84 void combobox_unset_popdown_strings(GtkComboBox *combobox)
89 g_return_if_fail(combobox != NULL);
91 model = gtk_combo_box_get_model(combobox);
92 count = gtk_tree_model_iter_n_children(model, NULL);
93 for (i = 0; i < count; i++)
94 gtk_combo_box_remove_text(combobox, 0);
97 void combobox_set_popdown_strings(GtkComboBox *combobox,
102 g_return_if_fail(combobox != NULL);
104 for (cur = list; cur != NULL; cur = g_list_next(cur))
105 gtk_combo_box_append_text(combobox, (const gchar*) cur->data);