1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <glib/gstdio.h>
33 #include <string.h> /* for strlen */
34 #include <modest-runtime.h>
36 #include <modest-defs.h>
37 #include "modest-toolkit-utils.h"
38 #include "modest-ui-constants.h"
39 #ifdef MODEST_TOOLKIT_HILDON2
40 #include <hildon/hildon.h>
43 /* Label child of a captioned */
44 #define CAPTIONED_LABEL_CHILD "captioned-label"
48 modest_toolkit_utils_get_manager_menubar_as_menu (GtkUIManager *manager,
49 const gchar *item_name)
53 GList *children, *iter;
55 menubar = gtk_ui_manager_get_widget (manager, item_name);
56 new_menu = gtk_menu_new ();
58 children = gtk_container_get_children (GTK_CONTAINER (menubar));
59 for (iter = children; iter != NULL; iter = g_list_next (iter)) {
62 menu = GTK_WIDGET (iter->data);
63 gtk_widget_reparent (menu, new_menu);
66 g_list_free (children);
72 * modest_toolkit_utils_create_captioned:
73 * @title_size_group: a #GtkSizeGroup
74 * @value_size_group: a #GtkSizeGroup
76 * @control: a #GtkWidget
78 * this creates a widget (a #GtkHBox) with a control, and a label
79 * (@string) captioning it. It also uses the proper size groups for title
82 * Returns: a widget containing the control and a proper label.
85 modest_toolkit_utils_create_captioned (GtkSizeGroup *title_size_group,
86 GtkSizeGroup *value_size_group,
91 return modest_toolkit_utils_create_captioned_with_size_type (title_size_group,
100 modest_toolkit_utils_create_vcaptioned (GtkSizeGroup *size_group,
105 return modest_toolkit_utils_create_vcaptioned_with_size_type (size_group,
113 * modest_toolkit_utils_create_captioned_with_size_type:
114 * @title_size_group: a #GtkSizeGroup
115 * @value_size_group: a #GtkSizeGroup
117 * @control: a #GtkWidget
118 * @size_type: a #HildonSizeType
120 * this creates a widget (a #GtkHBox) with a control, and a label
121 * (@string) captioning it. It also uses the proper size groups for title
124 * Returns: a widget containing the control and a proper label.
127 modest_toolkit_utils_create_captioned_with_size_type (GtkSizeGroup *title_size_group,
128 GtkSizeGroup *value_size_group,
132 ModestToolkitSizeType size_type)
139 label = gtk_label_new (NULL);
140 gtk_label_set_markup (GTK_LABEL (label), title);
142 label = gtk_label_new (title);
144 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
145 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
147 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
149 hildon_gtk_widget_set_theme_size (label, HILDON_SIZE_FINGER_HEIGHT);
151 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
152 gtk_widget_show (label);
153 gtk_widget_show (align);
154 box = gtk_hbox_new (FALSE, 0);
155 gtk_container_add (GTK_CONTAINER (align), label);
156 gtk_box_pack_start (GTK_BOX (box), align, FALSE, FALSE, 0);
157 gtk_box_pack_start (GTK_BOX (box), control, TRUE, TRUE, 0);
158 if (title_size_group)
159 gtk_size_group_add_widget (title_size_group, label);
160 if (value_size_group)
161 gtk_size_group_add_widget (value_size_group, control);
164 hildon_gtk_widget_set_theme_size (control, size_type);
167 g_object_set_data (G_OBJECT (box), CAPTIONED_LABEL_CHILD, label);
173 modest_toolkit_utils_create_vcaptioned_with_size_type (GtkSizeGroup *size_group,
177 ModestToolkitSizeType size_type)
184 label = gtk_label_new (NULL);
185 gtk_label_set_markup (GTK_LABEL (label), title);
187 label = gtk_label_new (title);
189 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
190 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
192 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
194 hildon_gtk_widget_set_theme_size (label, HILDON_SIZE_FINGER_HEIGHT);
196 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
197 gtk_widget_show (label);
198 gtk_widget_show (align);
199 box = gtk_vbox_new (FALSE, 0);
200 gtk_container_add (GTK_CONTAINER (align), label);
201 gtk_box_pack_start (GTK_BOX (box), align, FALSE, FALSE, 0);
202 gtk_box_pack_start (GTK_BOX (box), control, TRUE, TRUE, 0);
204 gtk_size_group_add_widget (size_group, label);
205 gtk_size_group_add_widget (size_group, control);
209 hildon_gtk_widget_set_theme_size (control, size_type);
212 g_object_set_data (G_OBJECT (box), CAPTIONED_LABEL_CHILD, label);
218 * modest_toolkit_utils_captioned_set_label:
219 * @captioned: a #GtkWidget built as captioned
220 * @new_label: a string
221 * @use_markup: a #gboolean
223 * set a new label for the captioned
226 modest_toolkit_utils_captioned_set_label (GtkWidget *captioned,
227 const gchar *new_label,
232 g_return_if_fail (GTK_IS_WIDGET (captioned));
234 label = g_object_get_data (G_OBJECT (captioned), CAPTIONED_LABEL_CHILD);
235 g_return_if_fail (GTK_IS_LABEL (label));
238 gtk_label_set_markup (GTK_LABEL (label), new_label);
240 gtk_label_set_text (GTK_LABEL (label), new_label);
245 * modest_toolkit_utils_captioned_get_label_widget:
246 * @captioned: a #GtkWidget built as captioned
248 * obtains the label widget for the captioned
250 * Returns: a #GtkLabel
253 modest_toolkit_utils_captioned_get_label_widget (GtkWidget *captioned)
257 g_return_val_if_fail (GTK_IS_WIDGET (captioned), NULL);
259 label = g_object_get_data (G_OBJECT (captioned), CAPTIONED_LABEL_CHILD);
260 g_return_val_if_fail (GTK_IS_LABEL (label), NULL);
267 * modest_toolkit_utils_set_hbutton_layout:
268 * @title_sizegroup: a #GtkSizeGroup, or %NULL
269 * @value_sizegroup: a #GtkSizeGroup, or %NULL
271 * @button: a #HildonButton
273 * Configures the alignment and layout of @button. If @title_sizegroup is provided,
274 * the title will be aligned to the left using it. If @value_sizegroup is provided,
275 * the value will be aligned to the left using it. It also sets the title
278 * The alignment is left for the title and for the value.
281 modest_toolkit_utils_set_hbutton_layout (GtkSizeGroup *title_sizegroup,
282 GtkSizeGroup *value_sizegroup,
286 #ifdef MODEST_TOOLKIT_HILDON2
287 hildon_button_set_title (HILDON_BUTTON (button), title);
289 hildon_button_add_title_size_group (HILDON_BUTTON (button), title_sizegroup);
291 hildon_button_add_value_size_group (HILDON_BUTTON (button), value_sizegroup);
292 hildon_button_set_alignment (HILDON_BUTTON (button), 0.0, 0.5, 1.0, 0.0);
293 hildon_button_set_title_alignment (HILDON_BUTTON (button), 0.0, 0.5);
294 hildon_button_set_value_alignment (HILDON_BUTTON (button), 0.0, 0.5);
299 modest_toolkit_utils_set_vbutton_layout (GtkSizeGroup *sizegroup,
303 #ifdef MODEST_TOOLKIT_HILDON2
304 hildon_button_set_title (HILDON_BUTTON (button), title);
306 hildon_button_add_title_size_group (HILDON_BUTTON (button), sizegroup);
307 hildon_button_add_value_size_group (HILDON_BUTTON (button), sizegroup);
309 hildon_button_set_alignment (HILDON_BUTTON (button), 0.0, 0.5, 1.0, 0.0);
310 hildon_button_set_title_alignment (HILDON_BUTTON (button), 0.0, 0.5);
311 hildon_button_set_value_alignment (HILDON_BUTTON (button), 0.0, 0.5);
316 modest_toolkit_utils_create_group_box (const gchar *label_text, GtkWidget *contents)
321 label = gtk_label_new (label_text);
322 gtk_widget_show (label);
324 box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
325 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
326 gtk_box_pack_start (GTK_BOX (box), contents, TRUE, TRUE, 0);
327 gtk_widget_show (box);