Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_progressbar.c
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 /**
21  * @file eail_progressbar.c
22  * @brief EailProgressbar implementation
23  */
24
25 #include <Elementary.h>
26
27 #include "eail_progressbar.h"
28 #include "eail_utils.h"
29
30 static void atk_value_interface_init(AtkValueIface *iface);
31
32 /**
33  * @brief Define EailProgressbar GObject type
34  */
35 G_DEFINE_TYPE_WITH_CODE(EailProgressbar,
36                         eail_progressbar,
37                         EAIL_TYPE_WIDGET,
38                         G_IMPLEMENT_INTERFACE(ATK_TYPE_VALUE,
39                                               atk_value_interface_init));
40
41 /*
42  * Implementation of the *AtkObject* interface
43  */
44
45 /**
46  * @brief Handler for changed event
47  *
48  * @param data data passed to callback
49  * @param obj Evas_Object that raised event
50  * @param event_info additional event info
51  */
52 void
53 _eail_progressbar_handle_changed_event(void *data,
54                                        Evas_Object *obj,
55                                        void *event_info)
56 {
57    eail_emit_atk_signal
58                   (ATK_OBJECT(data), "visible-data-changed", ATK_TYPE_OBJECT);
59 }
60
61 /**
62  * @brief EailProgressbar object initialization
63  *
64  * @param obj AtkObject instance
65  * @param data user set additional initialization data
66  */
67 static void
68 eail_progressbar_initialize(AtkObject *obj, gpointer data)
69 {
70    Evas_Object *nested_widget = NULL;
71
72    ATK_OBJECT_CLASS(eail_progressbar_parent_class)->initialize(obj, data);
73
74    obj->role = ATK_ROLE_PROGRESS_BAR;
75    g_return_if_fail(EAIL_IS_WIDGET(obj));
76
77    nested_widget = eail_widget_get_widget(EAIL_WIDGET(obj));
78    evas_object_smart_callback_add(nested_widget, "changed",
79                                   _eail_progressbar_handle_changed_event, obj);
80
81 }
82
83 /**
84  * @brief Gets the list of child widgets
85  *
86  * @param widget EailWidget object
87  *
88  * @return Eina_List representing the list of widget's children
89  * or NULL if widget has no children
90  */
91 static Eina_List *
92 eail_progressbar_get_widget_children(EailWidget *widget)
93 {
94    Eina_List *list = NULL;
95    Evas_Object *child, *obj;
96
97    obj = eail_widget_get_widget(EAIL_WIDGET(widget));
98    if (obj)
99      {
100         child = elm_object_part_content_get(obj, "icon");
101         if (child && elm_object_widget_check(child))
102           list = eina_list_append(list, child);
103      }
104
105    return list;
106 }
107
108 /**
109  * @brief Gets the slider's name
110  *
111  * @param obj AtkObject instance
112  * @returns string representing the accessible name of the slider
113  */
114 static const gchar*
115 eail_progressbar_get_name(AtkObject *obj)
116 {
117    const gchar *name;
118    Evas_Object *widget;
119
120    name = ATK_OBJECT_CLASS(eail_progressbar_parent_class)->get_name(obj);
121    if (name) return name;
122
123    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
124    if (widget)
125      name = (const gchar*)elm_object_text_get(widget);
126
127    return name;
128 }
129
130 /**
131  * @brief EailProgressbar instance initialization
132  *
133  * @param progressbar EailProgressbar instance
134  */
135 static void
136 eail_progressbar_init(EailProgressbar *progressbar)
137 {
138 }
139
140 /**
141  * @brief GObject type initialization function
142  *
143  * @param klass EailProgressbarClass instance
144  */
145 static void
146 eail_progressbar_class_init(EailProgressbarClass *klass)
147 {
148    AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
149    EailWidgetClass *widget_class = EAIL_WIDGET_CLASS(klass);
150
151    atk_class->initialize = eail_progressbar_initialize;
152    atk_class->get_name = eail_progressbar_get_name;
153    widget_class->get_widget_children = eail_progressbar_get_widget_children;
154 }
155
156 /*
157  * Implementation of the *AtkValue* interface
158  */
159
160 /**
161  * @brief Gets the current value of obj
162  *
163  * @param obj AtkValue instance
164  * @param [out] value obj's current value
165  */
166 static void
167 eail_progressbar_get_current_value(AtkValue *obj,
168                                    GValue   *value)
169 {
170    Evas_Object *widget;
171
172    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
173    if (!widget) return;
174
175    memset(value, 0, sizeof(GValue));
176    g_value_init(value, G_TYPE_DOUBLE);
177    g_value_set_double(value, elm_progressbar_value_get(widget));
178 }
179
180 /**
181  * @brief Gets the maxiumum value of obj
182  *
183  * @param obj AtkValue instance
184  * @param [out] value obj's maxiumum value
185  */
186 static void
187 eail_progressbar_get_maximum_value(AtkValue *obj,
188                                    GValue   *value)
189 {
190    Evas_Object *widget;
191
192    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
193    if (!widget) return;
194
195    memset(value, 0, sizeof(GValue));
196    g_value_init(value, G_TYPE_DOUBLE);
197    g_value_set_double(value, 1.0);
198 }
199
200 /**
201  * @brief Gets the minimum value of obj
202  *
203  * @param obj AtkValue instance
204  * @param [out] value obj's minimum value
205  */
206 static void
207 eail_progressbar_get_minimum_value(AtkValue *obj,
208                                    GValue   *value)
209 {
210    Evas_Object *widget;
211
212    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
213    if (!widget) return;
214
215    memset(value, 0, sizeof(GValue));
216    g_value_init(value, G_TYPE_DOUBLE);
217    g_value_set_double(value, 0.0);
218 }
219
220 /**
221  * @brief Sets the value of obj
222  *
223  * @param obj AtkValue instance
224  * @param value obj's new value
225  * @return TRUE if new value is set successfully, FALSE otherwise
226  */
227 static gboolean
228 eail_progressbar_set_current_value(AtkValue *obj,
229                                    const GValue *value)
230 {
231    Evas_Object *widget;
232    double val;
233
234    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
235    if (!widget) return FALSE;
236
237    val = g_value_get_double(value);
238
239    if (0.0 > val || 1.0 < val)
240      return FALSE;
241
242    elm_progressbar_value_set(widget, val);
243
244    return TRUE;
245 }
246
247 /**
248  * @brief Gets the minimum increment of obj
249  *
250  * @param obj AtkValue instance
251  * @param [out] value obj's minimum increment
252  */
253 static void
254 eail_progressbar_get_minimum_increment(AtkValue *obj,
255                                        GValue *value)
256 {
257    Evas_Object *widget;
258
259    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
260    if (!widget) return;
261
262    memset(value, 0, sizeof(GValue));
263    g_value_init(value, G_TYPE_DOUBLE);
264    g_value_set_double(value, G_MINDOUBLE);
265 }
266
267 /**
268  * @brief AtkValue interface initializer
269  *
270  * @param iface AtkValueIface instance
271  */
272 static void
273 atk_value_interface_init(AtkValueIface *iface)
274 {
275    g_return_if_fail(iface != NULL);
276
277    iface->get_current_value     = eail_progressbar_get_current_value;
278    iface->get_maximum_value     = eail_progressbar_get_maximum_value;
279    iface->get_minimum_value     = eail_progressbar_get_minimum_value;
280    iface->set_current_value     = eail_progressbar_set_current_value;
281    iface->get_minimum_increment = eail_progressbar_get_minimum_increment;
282 }