In gtk now we instantiate the new ModestFindToolbar
[modest] / src / widgets / modest-toolkit-factory.c
1 /* Copyright (c) 2009, Igalia
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30 #include <glib/gi18n.h>
31 #ifdef MODEST_TOOLKIT_HILDON2
32 #include <modest-hildon-pannable-area-scrollable.h>
33 #include <modest-hildon-find-toolbar.h>
34 #include <hildon/hildon.h>
35 #else
36 #include <modest-scrolled-window-scrollable.h>
37 #include <modest-find-toolbar.h>
38 #endif
39 #include "modest-toolkit-factory.h"
40
41 static void modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass);
42 static void modest_toolkit_factory_init (ModestToolkitFactory *self);
43
44 /* GObject interface */
45 static GtkWidget * modest_toolkit_factory_create_scrollable_default (ModestToolkitFactory *self);
46 static GtkWidget * modest_toolkit_factory_create_check_button_default (ModestToolkitFactory *self, const gchar *label);
47 static GtkWidget * modest_toolkit_factory_create_check_menu_default (ModestToolkitFactory *self, const gchar *label);
48 static GtkWidget * modest_toolkit_factory_create_isearch_toolbar_default (ModestToolkitFactory *self, const gchar *label);
49 /* globals */
50 static GObjectClass *parent_class = NULL;
51
52 G_DEFINE_TYPE    (ModestToolkitFactory,
53                   modest_toolkit_factory,
54                   G_TYPE_OBJECT);
55
56 ModestToolkitFactory *
57 modest_toolkit_factory_get_instance                            (void)
58 {
59     GObject* self = g_object_new (MODEST_TYPE_TOOLKIT_FACTORY, NULL);
60
61     return (ModestToolkitFactory *) self;
62 }
63
64 static void
65 modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass)
66 {
67         parent_class = g_type_class_peek_parent (klass);
68
69         klass->create_scrollable = modest_toolkit_factory_create_scrollable_default;
70         klass->create_check_button = modest_toolkit_factory_create_check_button_default;
71         klass->create_check_menu = modest_toolkit_factory_create_check_menu_default;
72         klass->create_isearch_toolbar = modest_toolkit_factory_create_isearch_toolbar_default;
73 }
74
75 static void
76 modest_toolkit_factory_init (ModestToolkitFactory *self)
77 {
78 }
79
80 GtkWidget *
81 modest_toolkit_factory_create_scrollable (ModestToolkitFactory *self)
82 {
83         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_scrollable (self);
84 }
85
86 static GtkWidget *
87 modest_toolkit_factory_create_scrollable_default (ModestToolkitFactory *self)
88 {
89 #ifdef MODEST_TOOLKIT_HILDON2
90         return modest_hildon_pannable_area_scrollable_new ();
91 #else
92         return modest_scrolled_window_scrollable_new ();
93 #endif
94 }
95
96 GtkWidget *
97 modest_toolkit_factory_create_check_button (ModestToolkitFactory *self, const gchar *label)
98 {
99         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_check_button (self, label);
100 }
101
102 static GtkWidget *
103 modest_toolkit_factory_create_check_button_default (ModestToolkitFactory *self, const gchar *label)
104 {
105         GtkWidget *result;
106 #ifdef MODEST_TOOLKIT_HILDON2
107         result = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
108         gtk_button_set_label (GTK_BUTTON (result), label);
109         gtk_button_set_alignment (GTK_BUTTON (result), 0.0, 0.5);
110 #else
111         result = gtk_check_button_new_with_label (label);
112 #endif
113         return result;
114 }
115
116 GtkWidget *
117 modest_toolkit_factory_create_check_menu (ModestToolkitFactory *self, const gchar *label)
118 {
119         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_check_menu (self, label);
120 }
121
122 static GtkWidget *
123 modest_toolkit_factory_create_check_menu_default (ModestToolkitFactory *self, const gchar *label)
124 {
125         GtkWidget *result;
126 #ifdef MODEST_TOOLKIT_HILDON2
127         result = hildon_check_button_new (0);
128         gtk_button_set_label (GTK_BUTTON (result), label);
129         gtk_button_set_alignment (GTK_BUTTON (result), 0.5, 0.5);
130 #else
131         result = gtk_check_menu_item_new_with_label (label);
132 #endif
133         return result;
134 }
135
136 gboolean
137 modest_togglable_get_active (GtkWidget *widget)
138 {
139 #ifdef MODEST_TOOLKIT_HILDON2
140         return hildon_check_button_get_active (HILDON_CHECK_BUTTON (widget));
141 #else
142         if (GTK_IS_CHECK_MENU_ITEM (widget)) {
143                 return gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget));
144         } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
145                 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
146         }
147 #endif
148 }
149
150 void
151 modest_togglable_set_active (GtkWidget *widget, gboolean active)
152 {
153 #ifdef MODEST_TOOLKIT_HILDON2
154         hildon_check_button_set_active (HILDON_CHECK_BUTTON (widget), active);
155 #else
156         if (GTK_IS_CHECK_MENU_ITEM (widget)) {
157                 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (widget), active);
158         } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
159                 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), active);
160         }
161 #endif
162 }
163
164 gboolean
165 modest_is_togglable (GtkWidget *widget)
166 {
167 #ifdef MODEST_TOOLKIT_HILDON2
168         return HILDON_IS_CHECK_BUTTON (widget);
169 #else
170         return GTK_IS_CHECK_MENU_ITEM (widget) || GTK_IS_TOGGLE_BUTTON (widget);
171 #endif
172 }
173
174 GtkWidget *
175 modest_toolkit_factory_create_isearch_toolbar (ModestToolkitFactory *self, const gchar *label)
176 {
177         return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_isearch_toolbar (self, label);
178 }
179
180 static GtkWidget *
181 modest_toolkit_factory_create_isearch_toolbar_default (ModestToolkitFactory *self, const gchar *label)
182 {
183         GtkWidget *result;
184 #ifdef MODEST_TOOLKIT_HILDON2
185         result = modest_hildon_find_toolbar_new (label);
186 #else
187         /* TODO: create gtk-only based isearch toolbar implementation */
188         result = modest_find_toolbar_new (label);
189 #endif
190         return result;
191 }
192