Updated Hungarian translation
[evolution.git] / e-util / e-dialog-widgets.c
blob1386002973348c4471dfed3000da4c858ffa9e47
1 /*
2 * Evolution internal utilities - Glade dialog widget utilities
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17 * Authors:
18 * Federico Mena-Quintero <federico@ximian.com>
20 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
28 #include <math.h>
29 #include <string.h>
30 #include <time.h>
31 #include <gtk/gtk.h>
33 #include "e-dialog-widgets.h"
35 /* Converts an mapped value to the appropriate index in an item group. The
36 * values for the items are provided as a -1-terminated array.
38 static gint
39 value_to_index (const gint *value_map,
40 gint value)
42 gint i;
44 for (i = 0; value_map[i] != -1; i++)
45 if (value_map[i] == value)
46 return i;
48 return -1;
51 /* Converts an index in an item group to the appropriate mapped value. See the
52 * function above.
54 static gint
55 index_to_value (const gint *value_map,
56 gint index)
58 gint i;
60 /* We do this the hard way, i.e. not as a simple array reference, to
61 * check for correctness.
64 for (i = 0; value_map[i] != -1; i++)
65 if (i == index)
66 return value_map[i];
68 return -1;
71 /**
72 * e_dialog_combo_box_set:
73 * @widget: A #GtkComboBox.
74 * @value: Enumerated value.
75 * @value_map: Map from enumeration values to array indices.
77 * Sets the selected item in a #GtkComboBox. Please read the description of
78 * e_dialog_radio_set() to see how @value_map maps enumeration values to item
79 * indices.
80 **/
81 void
82 e_dialog_combo_box_set (GtkWidget *widget,
83 gint value,
84 const gint *value_map)
86 gint i;
88 g_return_if_fail (GTK_IS_COMBO_BOX (widget));
89 g_return_if_fail (value_map != NULL);
91 i = value_to_index (value_map, value);
93 if (i != -1)
94 gtk_combo_box_set_active (GTK_COMBO_BOX (widget), i);
95 else
96 g_message (
97 "e_dialog_combo_box_set(): could not "
98 "find value %d in value map!", value);
102 * e_dialog_combo_box_get:
103 * @widget: A #GtkComboBox.
104 * @value_map: Map from enumeration values to array indices.
106 * Queries the selected item in a #GtkComboBox. Please read the description
107 * of e_dialog_radio_set() to see how @value_map maps enumeration values to item
108 * indices.
110 * Return value: Enumeration value which corresponds to the selected item in the
111 * combo box.
113 gint
114 e_dialog_combo_box_get (GtkWidget *widget,
115 const gint *value_map)
117 gint active;
118 gint i;
120 g_return_val_if_fail (GTK_IS_COMBO_BOX (widget), -1);
121 g_return_val_if_fail (value_map != NULL, -1);
123 active = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
124 i = index_to_value (value_map, active);
126 if (i == -1) {
127 g_message (
128 "e_dialog_combo_box_get(): could not "
129 "find index %d in value map!", i);
130 return -1;
133 return i;
137 * e_dialog_button_new_with_icon:
138 * @icon_name: Icon's name to use; can be %NULL
139 * @label: Button label to set, with mnemonics
141 * Creates a new #GtkButton with preset @label and image set
142 * to @icon_name.
144 * Returns: (transfer-full): A new #GtkButton
146 * Since: 3.12
148 GtkWidget *
149 e_dialog_button_new_with_icon (const gchar *icon_name,
150 const gchar *label)
152 GtkIconSize icon_size = GTK_ICON_SIZE_BUTTON;
153 GtkWidget *button;
155 if (label && *label) {
156 button = gtk_button_new_with_mnemonic (label);
157 } else {
158 button = gtk_button_new ();
159 icon_size = GTK_ICON_SIZE_MENU;
162 if (icon_name)
163 gtk_button_set_image (
164 GTK_BUTTON (button),
165 gtk_image_new_from_icon_name (icon_name, icon_size));
167 gtk_widget_show (button);
169 return button;