Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_colorselector.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_colorselector.c
22  * @brief EailColorselector implementation.
23  */
24
25 #include <Elementary.h>
26
27 #include "eail_colorselector.h"
28 #include "eail_utils.h"
29
30 static void atk_value_interface_init(AtkValueIface *iface);
31
32 /**
33  * @brief EailColorselector type definition
34  */
35 G_DEFINE_TYPE_WITH_CODE(EailColorselector,
36                         eail_colorselector,
37                         EAIL_TYPE_WIDGET,
38                         G_IMPLEMENT_INTERFACE(ATK_TYPE_VALUE,
39                                               atk_value_interface_init));
40
41 /**
42  * @brief handler for changed event
43  *
44  * @param data passed to callback
45  * @param obj object that raised event
46  * @param event_info additional event info
47  */
48
49 void
50 _eail_colorselector_handle_changed_event(void *data,
51                                              Evas_Object *obj,
52                                              void *event_info)
53 {
54    eail_emit_atk_signal
55                   (ATK_OBJECT(data), "visible-data-changed", ATK_TYPE_OBJECT);
56 }
57
58 /**
59  * @brief EailColorselector initializer
60  *
61  * @param obj AtkObject instance
62  * @param data initialization data
63  */
64 static void
65 eail_colorselector_initialize(AtkObject *obj, gpointer data)
66 {
67    Evas_Object *nested_widget = NULL;
68    ATK_OBJECT_CLASS(eail_colorselector_parent_class)->initialize(obj, data);
69
70    obj->role = ATK_ROLE_COLOR_CHOOSER;
71    g_return_if_fail(EAIL_IS_WIDGET(obj));
72
73    nested_widget = eail_widget_get_widget(EAIL_WIDGET(obj));
74    evas_object_smart_callback_add(nested_widget, "changed",
75                                   _eail_colorselector_handle_changed_event, obj);
76 }
77
78 /**
79  * @brief EailColorselector instance initializer
80  *
81  * @param selector EailColorselector instance
82  */
83 static void
84 eail_colorselector_init(EailColorselector *selector)
85 {
86 }
87
88 /**
89  * @brief EailColorselector class initializer
90  *
91  * @param klass EailColorselectorClass instance
92  */
93 static void
94 eail_colorselector_class_init(EailColorselectorClass *klass)
95 {
96    AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
97    atk_class->initialize = eail_colorselector_initialize;
98 }
99
100 /**
101  * @brief Gets obj's current value
102  *
103  * @param obj AtkValue instance
104  * @param [out] value obj's current value
105  */
106 static void
107 eail_colorselector_get_current_value(AtkValue *obj,
108                                      GValue   *value)
109 {
110    gint r = 0;
111    gint g = 0;
112    gint b = 0;
113    gint a = 0;
114    gint color = 0;
115    Evas_Object *widget = NULL;
116
117    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
118    if (!widget) return;
119
120    elm_colorselector_color_get(widget, &r, &g, &b, &a);
121    color = (a << 24) | (r << 16) | (g << 8) | b;
122
123    memset(value, 0, sizeof(GValue));
124    g_value_init(value, G_TYPE_INT);
125    g_value_set_int(value, color);
126 }
127
128 /**
129  * @brief Gets obj's maxiumum value
130  *
131  * @param obj AtkValue instance
132  * @param [out] value obj's maximum value
133  */
134 static void
135 eail_colorselector_get_maximum_value(AtkValue *obj,
136                                      GValue   *value)
137 {
138    gint max = 0xFFFFFFFF;
139    Evas_Object *widget = NULL;
140
141    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
142    if (!widget) return;
143
144    memset(value, 0, sizeof(GValue));
145    g_value_init(value, G_TYPE_INT);
146    g_value_set_int(value, max);
147 }
148
149 /**
150  * @brief Gets obj's minimum value
151  *
152  * @param obj AtkValue instance
153  * @param [out] value obj's minimum value
154  */
155 static void
156 eail_colorselector_get_minimum_value(AtkValue *obj,
157                                      GValue   *value)
158 {
159    gint min = 0;
160    Evas_Object *widget = NULL;
161
162    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
163    if (!widget) return;
164
165    memset(value, 0, sizeof(GValue));
166    g_value_init(value, G_TYPE_INT);
167    g_value_set_int(value, min);
168 }
169
170 /**
171  * @brief Sets obj's current value
172  *
173  * @param obj AtkValue instance
174  * @param value obj's current value
175  * @return TRUE if value was set successfully, FALSE otherwise
176  */
177 static gboolean
178 eail_colorselector_set_current_value(AtkValue *obj,
179                                      const GValue *value)
180 {
181    gint r = 0xFFFFFFFF;
182    gint g = 0xFFFFFFFF;
183    gint b = 0xFFFFFFFF;
184    gint a = 0xFFFFFFFF;
185    gint color = 0xFFFFFFFF;
186    Evas_Object *widget = NULL;
187
188    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
189    if (!widget) return FALSE;
190
191    color = g_value_get_int(value);
192    a = (0xFF000000 & (guint)color) >> 24;
193    r = (0x00FF0000 & color) >> 16;
194    g = (0x0000FF00 & color) >> 8;
195    b = 0x000000FF & color;
196    elm_colorselector_color_set(widget, r, g, b, a);
197
198    return TRUE;
199 }
200
201 /**
202  * @brief Gets obj's minimum increment
203  *
204  * @param obj AtkValue instance
205  * @param [out] value obj's minimum increment
206  */
207 static void
208 eail_colorselector_get_minimum_increment(AtkValue *obj,
209                                          GValue *value)
210 {
211    gint inc = 0x01010101;
212
213    memset(value,  0, sizeof(GValue));
214    g_value_init(value, G_TYPE_INT);
215    g_value_set_int(value, inc);
216 }
217
218 /**
219  * @brief AtkValue interface initializer
220  *
221  * @param iface AtkValueIface instance
222  */
223 static void atk_value_interface_init(AtkValueIface *iface)
224 {
225    iface->get_current_value     = eail_colorselector_get_current_value;
226    iface->get_maximum_value     = eail_colorselector_get_maximum_value;
227    iface->get_minimum_value     = eail_colorselector_get_minimum_value;
228    iface->set_current_value     = eail_colorselector_set_current_value;
229    iface->get_minimum_increment = eail_colorselector_get_minimum_increment;
230 }
231