Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_slider.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_slider.c
22  * @brief EailSlider implementation
23  */
24
25 #include <Elementary.h>
26
27 #include "eail_slider.h"
28 #include "eail_utils.h"
29
30 /*
31  * Implementation of the *AtkObject* interface
32  */
33
34 /**
35  * @brief Initialization of AtkValue interface
36  *
37  * @param iface AtkValueIface instance
38  */
39 static void atk_value_interface_init(AtkValueIface *iface);
40
41 /**
42  * @brief Define EailSlider GObject type
43  */
44 G_DEFINE_TYPE_WITH_CODE(EailSlider,
45                         eail_slider,
46                         EAIL_TYPE_WIDGET,
47                         G_IMPLEMENT_INTERFACE(ATK_TYPE_VALUE,
48                                               atk_value_interface_init));
49
50 /**
51  * @brief Handler for changed event
52  *
53  * @param data passed to callback
54  * @param obj Evas_Object that raised event
55  * @param event_info additional event info
56  */
57 void
58 _eail_slider_handle_changed_event(void *data,
59                                       Evas_Object *obj,
60                                       void *event_info)
61 {
62    eail_emit_atk_signal
63                   (ATK_OBJECT(data), "visible-data-changed", ATK_TYPE_OBJECT);
64 }
65
66 /**
67  * @brief EailSlider object initialization
68  *
69  * @param obj AtkObject instance
70  * @param data user set additional initialization data
71  */
72 static void
73 eail_slider_initialize(AtkObject *obj, gpointer data)
74 {
75    Evas_Object *nested_widget = NULL;
76    ATK_OBJECT_CLASS(eail_slider_parent_class)->initialize(obj, data);
77
78    obj->role = ATK_ROLE_SLIDER;
79    g_return_if_fail(EAIL_IS_WIDGET(obj));
80
81    nested_widget = eail_widget_get_widget(EAIL_WIDGET(obj));
82    evas_object_smart_callback_add(nested_widget, "changed",
83                                   _eail_slider_handle_changed_event, obj);
84 }
85
86 /**
87  * @brief Gets the list of child widgets
88  *
89  * @param widget EailWidget instance
90  *
91  * @return Eina_List representing the list of widget's children
92  */
93 static Eina_List *
94 eail_slider_get_widget_children(EailWidget *widget)
95 {
96    Eina_List *list = NULL;
97    Evas_Object *child, *obj;
98
99    obj = eail_widget_get_widget(EAIL_WIDGET(widget));
100    if (obj)
101      {
102         child = elm_object_part_content_get(obj, "icon");
103         if (child && elm_object_widget_check(child))
104           list = eina_list_append(list, child);
105
106         child = elm_object_part_content_get(obj, "end");
107         if (child && elm_object_widget_check(child))
108           list = eina_list_append(list, child);
109      }
110
111    return list;
112 }
113
114 /**
115  * @brief Gets the name of the slider
116  *
117  * @param obj AtkObject instance
118  *
119  * @returns string representing the name of the slider
120  */
121 static const gchar*
122 eail_slider_get_name(AtkObject *obj)
123 {
124    const gchar *name;
125    Evas_Object *widget;
126
127    name = ATK_OBJECT_CLASS(eail_slider_parent_class)->get_name(obj);
128    if (name) return name;
129
130    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
131    if (widget)
132      name = (const gchar*)elm_object_text_get(widget);
133
134    return name;
135 }
136
137 /**
138  * @brief EailSlider instance initialization
139  *
140  * @param slider EailSlider instance
141  */
142 static void
143 eail_slider_init(EailSlider *slider)
144 {
145 }
146
147 /**
148  * @brief GObject type initialization function
149  *
150  * @param klass EailSliderClass instance
151  */
152 static void
153 eail_slider_class_init(EailSliderClass *klass)
154 {
155    AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
156    EailWidgetClass *widget_class = EAIL_WIDGET_CLASS(klass);
157
158    widget_class->get_widget_children = eail_slider_get_widget_children;
159    atk_class->initialize = eail_slider_initialize;
160    atk_class->get_name = eail_slider_get_name;
161 }
162
163 /*
164  * Implementation of the *AtkValue* interface
165  */
166
167 /**
168  * @brief Gets the current value of obj
169  *
170  * @param obj AtkValue instance
171  * @param [out] value obj's current value
172  */
173 static void
174 eail_slider_get_current_value(AtkValue *obj,
175                               GValue   *value)
176 {
177    Evas_Object *widget;
178
179    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
180    if (!widget) return;
181
182    memset(value, 0, sizeof(GValue));
183    g_value_init(value, G_TYPE_DOUBLE);
184    g_value_set_double(value, elm_slider_value_get(widget));
185 }
186
187 /**
188  * @brief Gets the maxiumum value of obj
189  *
190  * @param obj AtkValue instance
191  * @param [out] value obj's maxiumum value
192  */
193 static void
194 eail_slider_get_maximum_value(AtkValue *obj,
195                               GValue   *value)
196 {
197    Evas_Object *widget;
198    double max;
199
200    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
201    if (!widget) return;
202
203    memset(value, 0, sizeof(GValue));
204    g_value_init(value, G_TYPE_DOUBLE);
205    elm_slider_min_max_get(widget, NULL, &max);
206    g_value_set_double(value, max);
207 }
208
209 /**
210  * @brief Gets the minimum value of obj
211  *
212  * @param obj AtkValue instance
213  * @param [out] value obj's minimum value
214  */
215 static void
216 eail_slider_get_minimum_value(AtkValue *obj,
217                               GValue   *value)
218 {
219    Evas_Object *widget;
220    double min;
221
222    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
223    if (!widget) return;
224
225    memset(value, 0, sizeof(GValue));
226    g_value_init(value, G_TYPE_DOUBLE);
227    elm_slider_min_max_get(widget, &min, NULL);
228    g_value_set_double(value, min);
229 }
230
231 /**
232  * @brief Sets the value of obj
233  *
234  * @param obj AtkValue instance
235  * @param value obj's new value
236  * @return TRUE if new value was set successfully, FALSE otherwise
237  */
238 static gboolean
239 eail_slider_set_current_value(AtkValue     *obj,
240                               const GValue *value)
241 {
242    Evas_Object *widget;
243    double min, max, val;
244
245    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
246    if (!widget) return FALSE;
247
248    val = g_value_get_double(value);
249    elm_slider_min_max_get(widget, &min, &max);
250
251    if (min > val || max < val)
252      return FALSE;
253
254    elm_slider_value_set(widget, val);
255
256    return TRUE;
257 }
258
259 /**
260  * @brief Gets the minimum increment of obj
261  *
262  * @param obj AtkValue instance
263  * @param [out] value obj's minimum increment
264  */
265 static void
266 eail_slider_get_minimum_increment(AtkValue *obj,
267                                   GValue *value)
268 {
269    Evas_Object *widget;
270
271    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
272    if (!widget) return;
273
274    memset(value, 0, sizeof(GValue));
275    g_value_init(value, G_TYPE_DOUBLE);
276    g_value_set_double(value, 0);
277 }
278
279 /**
280  * @brief AtkValue interface initializer
281  *
282  * @param iface AtkValueIface instance
283  */
284 static void
285 atk_value_interface_init(AtkValueIface *iface)
286 {
287    g_return_if_fail(iface != NULL);
288
289    iface->get_current_value     = eail_slider_get_current_value;
290    iface->get_maximum_value     = eail_slider_get_maximum_value;
291    iface->get_minimum_value     = eail_slider_get_minimum_value;
292    iface->set_current_value     = eail_slider_set_current_value;
293    iface->get_minimum_increment = eail_slider_get_minimum_increment;
294 }