Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_action_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_action_slider.c
22  * @brief EailActionSlider implementation
23  */
24
25 #include <Elementary.h>
26
27 #include "eail_action_slider.h"
28 #include "eail_utils.h"
29
30 /**
31  * @brief Initialization of AtkValue interface
32  *
33  * @param iface EailActionSlider object
34  */
35 static void atk_value_interface_init(AtkValueIface *iface);
36
37 /**
38  * @brief Define EailActionSlider GObject type
39  */
40 G_DEFINE_TYPE_WITH_CODE(EailActionSlider,
41                         eail_action_slider,
42                         EAIL_TYPE_WIDGET,
43                         G_IMPLEMENT_INTERFACE(ATK_TYPE_VALUE,
44                                               atk_value_interface_init));
45
46 /*
47  * Implementation of the *AtkObject* interface
48  */
49
50 /**
51  * @brief Handler for pos_changed event
52  *
53  * @param data data passed to callback
54  * @param obj object that raised event
55  * @param event_info additional event info
56  */
57 void
58 _eail_action_slider_handle_pos_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 EailActionSlider object initialization
68  *
69  * @param obj EailActionSlider object
70  * @param data additional initialization data
71  */
72 static void
73 eail_action_slider_initialize(AtkObject *obj, gpointer data)
74 {
75    Evas_Object *nested_widget = NULL;
76
77    ATK_OBJECT_CLASS(eail_action_slider_parent_class)->initialize(obj, data);
78    obj->role = ATK_ROLE_SLIDER;
79
80    g_return_if_fail(EAIL_IS_WIDGET(obj));
81
82    nested_widget = eail_widget_get_widget(EAIL_WIDGET(obj));
83    evas_object_smart_callback_add(nested_widget, "pos_changed",
84                             _eail_action_slider_handle_pos_changed_event, obj);
85
86 }
87
88 /**
89  * @brief EailActionSlider instance initialization
90  *
91  * @param action_slider EailActionSlider instance
92  */
93 static void
94 eail_action_slider_init(EailActionSlider *action_slider)
95 {
96 }
97
98 /**
99  * @brief GObject type initialization function
100  *
101  * @param klass EailActionSliderClass instance
102  */
103 static void
104 eail_action_slider_class_init(EailActionSliderClass *klass)
105 {
106    AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
107
108    atk_class->initialize = eail_action_slider_initialize;
109 }
110
111 /*
112  * Implementation of the *AtkValue* interface
113  */
114
115 /**
116  * @brief Gets obj's current value
117  *
118  * @param obj EailActionSlider instance
119  * @param [out] value obj's current value
120  */
121 static void
122 eail_action_slider_get_current_value(AtkValue *obj,
123                                      GValue   *value)
124 {
125    Evas_Object *widget;
126
127    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
128    if (!widget) return;
129
130    memset(value, 0, sizeof(GValue));
131    g_value_init(value, G_TYPE_UINT);
132    g_value_set_uint(value, elm_actionslider_indicator_pos_get(widget));
133 }
134
135 /**
136  * @brief Gets obj's maxiumum value
137  *
138  * @param obj EailActionSlider instance
139  * @param [out] value obj's maxiumum value
140  */
141 static void
142 eail_action_slider_get_maximum_value(AtkValue *obj,
143                                      GValue   *value)
144 {
145    Evas_Object *widget;
146
147    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
148    if (!widget) return;
149
150    memset(value, 0, sizeof(GValue));
151    g_value_init(value, G_TYPE_UINT);
152    g_value_set_uint(value, elm_actionslider_enabled_pos_get(widget));
153 }
154
155 /**
156  * @brief Gets obj's minimum value
157  *
158  * @param obj EailActionSlider instance
159  * @param [out] value obj's minimum value
160  */
161 static void
162 eail_action_slider_get_minimum_value(AtkValue *obj,
163                                      GValue   *value)
164 {
165    Evas_Object *widget;
166
167    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
168    if (!widget) return;
169
170    memset(value, 0, sizeof(GValue));
171    g_value_init(value, G_TYPE_UINT);
172    g_value_set_uint(value, ELM_ACTIONSLIDER_NONE);
173 }
174
175 /**
176  * @brief Sets obj's value
177  *
178  * @param obj EailActionSlider instance
179  * @param value obj's new value
180  * @return TRUE if new value was set successfully, FALSE otherwise
181  */
182 static gboolean
183 eail_action_slider_set_current_value(AtkValue *obj,
184                                      const GValue *value)
185 {
186    Evas_Object *widget;
187    guint enum_val;
188
189    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
190    if (!widget) return FALSE;
191
192    enum_val = elm_actionslider_enabled_pos_get(widget) &
193               g_value_get_uint(value);
194
195    switch (enum_val)
196      {
197         case ELM_ACTIONSLIDER_LEFT:
198         case ELM_ACTIONSLIDER_CENTER:
199         case ELM_ACTIONSLIDER_RIGHT:
200           elm_actionslider_indicator_pos_set(widget, enum_val);
201           break;
202
203         default:
204           return FALSE;
205           break;
206      }
207
208    return TRUE;
209 }
210
211 /**
212  * @brief Gets obj's minimum increment
213  *
214  * @param obj EailActionSlider instance
215  * @param [out] value obj's minimum increment
216  */
217 static void
218 eail_action_slider_get_minimum_increment(AtkValue *obj,
219                                          GValue *value)
220 {
221    Evas_Object *widget;
222
223    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
224    if (!widget) return;
225
226    memset(value, 0, sizeof(GValue));
227    g_value_init(value, G_TYPE_UINT);
228    g_value_set_uint(value, ELM_ACTIONSLIDER_NONE);
229 }
230
231
232 static void
233 atk_value_interface_init(AtkValueIface *iface)
234 {
235    iface->get_current_value     = eail_action_slider_get_current_value;
236    iface->get_maximum_value     = eail_action_slider_get_maximum_value;
237    iface->get_minimum_value     = eail_action_slider_get_minimum_value;
238    iface->set_current_value     = eail_action_slider_set_current_value;
239    iface->get_minimum_increment = eail_action_slider_get_minimum_increment;
240 }