2 * This file is a part of hildon
4 * Copyright (C) 2008 Nokia Corporation, all rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser Public License as published by
8 * the Free Software Foundation; version 2 of the license.
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 Lesser Public License for more details.
18 * SECTION:hildon-edit-toolbar
19 * @short_description: Widget representing a toolbar for editing.
21 * The #HildonEditToolbar is a toolbar which contains a label and two
22 * buttons, one of them being an arrow pointing backwards.
24 * The label is a description of the action that the user is supposed
25 * to do. The button is to be pressed when the user completes the
26 * action. The arrow is used to go back to the previous view
27 * discarding any changes.
29 * Note that those widgets don't do anything themselves by default. To
30 * actually peform actions the developer must provide callbacks for
33 * To add a #HildonEditToolbar to a window use
34 * hildon_window_set_edit_toolbar().
37 * <title>HildonEditToolbar example</title>
41 * // Declare more widgets here ...
43 * window = hildon_stackable_window_new ();
44 * toolbar = hildon_edit_toolbar_new_with_text ("Choose items to delete", "Delete");
45 * // Create more widgets here ...
47 * // Add toolbar to window
48 * hildon_window_set_edit_toolbar (HILDON_WINDOW (window), HILDON_EDIT_TOOLBAR (toolbar));
50 * // Add other widgets ...
52 * g_signal_connect (toolbar, "button-clicked", G_CALLBACK (delete_button_clicked), someparameter);
53 * g_signal_connect_swapped (toolbar, "arrow-clicked", G_CALLBACK (gtk_widget_destroy), window);
55 * gtk_widget_show_all (window);
56 * gtk_window_fullscreen (GTK_WINDOW (window));
61 #include "hildon-edit-toolbar.h"
62 #include "hildon-gtk.h"
64 G_DEFINE_TYPE (HildonEditToolbar, hildon_edit_toolbar, GTK_TYPE_HBOX);
66 #define TOOLBAR_LEFT_PADDING 8
67 #define TOOLBAR_RIGHT_PADDING 8
69 #define HILDON_EDIT_TOOLBAR_GET_PRIVATE(obj) \
70 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
71 HILDON_TYPE_EDIT_TOOLBAR, HildonEditToolbarPrivate));
73 typedef struct _HildonEditToolbarPrivate HildonEditToolbarPrivate;
75 struct _HildonEditToolbarPrivate
88 static guint toolbar_signals [N_SIGNALS] = { 0 };
91 hildon_edit_toolbar_style_set (GtkWidget *widget,
92 GtkStyle *previous_style)
95 HildonEditToolbarPrivate *priv = HILDON_EDIT_TOOLBAR_GET_PRIVATE (widget);
97 if (GTK_WIDGET_CLASS (hildon_edit_toolbar_parent_class)->style_set)
98 GTK_WIDGET_CLASS (hildon_edit_toolbar_parent_class)->style_set (widget, previous_style);
100 gtk_widget_style_get (widget,
101 "arrow-width", &width,
102 "arrow-height", &height,
105 gtk_widget_set_size_request (GTK_WIDGET (priv->arrow), width, height);
109 hildon_edit_toolbar_class_init (HildonEditToolbarClass *klass)
111 GObjectClass *gobject_class = (GObjectClass *) klass;
112 GtkWidgetClass *widget_class = (GtkWidgetClass *)klass;
114 widget_class->style_set = hildon_edit_toolbar_style_set;
116 g_type_class_add_private (klass, sizeof (HildonEditToolbarPrivate));
118 gtk_widget_class_install_style_property (
122 "Width of the arrow button",
123 "Width of the arrow button",
127 gtk_widget_class_install_style_property (
131 "Height of the arrow button",
132 "Height of the arrow button",
137 * HildonEditToolbar::button-clicked:
138 * @widget: the object which received the signal.
140 * Emitted when the toolbar button has been activated (pressed and released).
144 toolbar_signals[BUTTON_CLICKED] =
145 g_signal_new ("button_clicked",
146 G_OBJECT_CLASS_TYPE (gobject_class),
149 g_cclosure_marshal_VOID__VOID,
153 * HildonEditToolbar::arrow-clicked:
154 * @widget: the object which received the signal.
156 * Emitted when the toolbar back button (arrow) has been activated
157 * (pressed and released).
161 toolbar_signals[ARROW_CLICKED] =
162 g_signal_new ("arrow_clicked",
163 G_OBJECT_CLASS_TYPE (gobject_class),
166 g_cclosure_marshal_VOID__VOID,
171 button_clicked_cb (GtkButton *self,
172 HildonEditToolbar *toolbar)
174 g_signal_emit (toolbar, toolbar_signals[BUTTON_CLICKED], 0);
178 arrow_clicked_cb (GtkButton *self,
179 HildonEditToolbar *toolbar)
181 g_signal_emit (toolbar, toolbar_signals[ARROW_CLICKED], 0);
185 hildon_edit_toolbar_init (HildonEditToolbar *self)
187 HildonEditToolbarPrivate *priv = HILDON_EDIT_TOOLBAR_GET_PRIVATE (self);
188 GtkWidget *separator;
190 GtkBox *hbox = GTK_BOX (self);
193 hbox2 = GTK_BOX (gtk_hbox_new (FALSE, 0));
194 align = GTK_ALIGNMENT (gtk_alignment_new (0, 0.5, 1, 1));
195 priv->label = GTK_LABEL (gtk_label_new (NULL));
196 priv->button = GTK_BUTTON (hildon_gtk_button_new (HILDON_SIZE_AUTO));
197 separator = gtk_vseparator_new ();
198 priv->arrow = GTK_BUTTON (gtk_button_new ());
200 gtk_button_set_focus_on_click (priv->arrow, FALSE);
202 g_signal_connect (priv->button, "clicked", G_CALLBACK (button_clicked_cb), self);
203 g_signal_connect (priv->arrow, "clicked", G_CALLBACK (arrow_clicked_cb), self);
205 gtk_box_set_spacing (hbox, 0);
206 gtk_alignment_set_padding (align, 0, 0, TOOLBAR_LEFT_PADDING, TOOLBAR_RIGHT_PADDING);
208 gtk_widget_set_name (GTK_WIDGET (self), "toolbar-edit-mode");
209 gtk_widget_set_name (GTK_WIDGET (priv->arrow), "hildon-edit-toolbar-arrow");
211 gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (hbox2));
212 gtk_box_pack_start (hbox2, GTK_WIDGET (priv->label), TRUE, TRUE, 0);
213 gtk_box_pack_start (hbox2, GTK_WIDGET (priv->button), FALSE, FALSE, 0);
215 gtk_box_pack_start (hbox, GTK_WIDGET (align), TRUE, TRUE, 0);
216 gtk_box_pack_start (hbox, separator, FALSE, FALSE, 0);
217 gtk_box_pack_start (hbox, GTK_WIDGET (priv->arrow), FALSE, FALSE, 0);
219 gtk_misc_set_alignment (GTK_MISC (priv->label), 0, 0.5);
221 gtk_widget_show_all (GTK_WIDGET (align));
222 gtk_widget_show_all (separator);
223 gtk_widget_show_all (GTK_WIDGET (priv->arrow));
227 * hildon_edit_toolbar_set_label:
228 * @toolbar: a #HildonEditToolbar
229 * @label: a new text for the toolbar label
231 * Sets the label of @toolbar to @label. This will clear any
232 * previously set value.
237 hildon_edit_toolbar_set_label (HildonEditToolbar *toolbar,
240 HildonEditToolbarPrivate *priv;
241 g_return_if_fail (HILDON_IS_EDIT_TOOLBAR (toolbar));
242 priv = HILDON_EDIT_TOOLBAR_GET_PRIVATE (toolbar);
243 gtk_label_set_text (priv->label, label);
247 * hildon_edit_toolbar_set_button_label:
248 * @toolbar: a #HildonEditToolbar
249 * @label: a new text for the label of the toolbar button
251 * Sets the label of the toolbar button to @label. This will clear any
252 * previously set value.
257 hildon_edit_toolbar_set_button_label (HildonEditToolbar *toolbar,
260 HildonEditToolbarPrivate *priv;
261 g_return_if_fail (HILDON_IS_EDIT_TOOLBAR (toolbar));
262 priv = HILDON_EDIT_TOOLBAR_GET_PRIVATE (toolbar);
263 gtk_button_set_label (priv->button, label);
267 * hildon_edit_toolbar_new:
269 * Creates a new #HildonEditToolbar.
271 * Returns: a new #HildonEditToolbar
276 hildon_edit_toolbar_new (void)
278 return g_object_new (HILDON_TYPE_EDIT_TOOLBAR, NULL);
282 * hildon_edit_toolbar_new_with_text:
283 * @label: Text for the toolbar label.
284 * @button: Text for the toolbar button.
286 * Creates a new #HildonEditToolbar, with the toolbar label set to
287 * @label and the button label set to @button.
289 * Returns: a new #HildonEditToolbar
294 hildon_edit_toolbar_new_with_text (const gchar *label,
297 GtkWidget *toolbar = g_object_new (HILDON_TYPE_EDIT_TOOLBAR, NULL);
299 hildon_edit_toolbar_set_label (HILDON_EDIT_TOOLBAR (toolbar), label);
300 hildon_edit_toolbar_set_button_label (HILDON_EDIT_TOOLBAR (toolbar), button);