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
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/>.
18 * Federico Mena-Quintero <federico@ximian.com>
20 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
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.
39 value_to_index (const gint
*value_map
,
44 for (i
= 0; value_map
[i
] != -1; i
++)
45 if (value_map
[i
] == value
)
51 /* Converts an index in an item group to the appropriate mapped value. See the
55 index_to_value (const gint
*value_map
,
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
++)
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
82 e_dialog_combo_box_set (GtkWidget
*widget
,
84 const gint
*value_map
)
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
);
94 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), i
);
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
110 * Return value: Enumeration value which corresponds to the selected item in the
114 e_dialog_combo_box_get (GtkWidget
*widget
,
115 const gint
*value_map
)
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
);
128 "e_dialog_combo_box_get(): could not "
129 "find index %d in value map!", 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
144 * Returns: (transfer-full): A new #GtkButton
149 e_dialog_button_new_with_icon (const gchar
*icon_name
,
152 GtkIconSize icon_size
= GTK_ICON_SIZE_BUTTON
;
155 if (label
&& *label
) {
156 button
= gtk_button_new_with_mnemonic (label
);
158 button
= gtk_button_new ();
159 icon_size
= GTK_ICON_SIZE_MENU
;
163 gtk_button_set_image (
165 gtk_image_new_from_icon_name (icon_name
, icon_size
));
167 gtk_widget_show (button
);