Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_panes.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_panes.c
22  * @brief EailPanes implementation
23  */
24
25 #include <Elementary.h>
26
27 #include "eail_panes.h"
28 #include "eail_factory.h"
29 #include "eail_priv.h"
30
31 static void atk_value_interface_init(AtkValueIface *iface);
32
33 /**
34  * @brief EailPanes type definition
35  */
36 G_DEFINE_TYPE_WITH_CODE(EailPanes,
37                         eail_panes,
38                         EAIL_TYPE_WIDGET,
39                         G_IMPLEMENT_INTERFACE(ATK_TYPE_VALUE,
40                                               atk_value_interface_init));
41
42 /**
43  * @brief EailPanes initializer
44  *
45  * @param obj AtkObject instance
46  * @param data initialization data
47  */
48 static void
49 eail_panes_initialize(AtkObject *obj, gpointer data)
50 {
51    ATK_OBJECT_CLASS(eail_panes_parent_class)->initialize(obj, data);
52    obj->role = ATK_ROLE_SPLIT_PANE;
53 }
54
55 /**
56  * @brief EailPanes instance initializer
57  *
58  * @param panes EailPanes instance
59  */
60 static void
61 eail_panes_init(EailPanes *panes)
62 {
63 }
64
65 /**
66  * @brief Gets the number of children of obj
67  *
68  * @param obj AtkObject instance
69  * @returns integer representing the number of children
70  */
71 static gint
72 eail_panes_n_children_get(AtkObject *obj)
73 {
74    g_return_val_if_fail(EAIL_IS_PANES(obj), 0);
75
76    return 2;
77 }
78
79 /**
80  * @brief Gets the state set of obj
81  *
82  * @param obj AtkObject instance
83  * @return AtkStateSet representing the state set of obj
84  */
85 static AtkStateSet*
86 eail_panes_ref_state_set(AtkObject *obj)
87 {
88    AtkStateSet *state_set;
89    Evas_Object *widget;
90
91    state_set = ATK_OBJECT_CLASS(eail_panes_parent_class)->ref_state_set(obj);
92    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
93
94    if (widget == NULL) return state_set;
95
96    if (elm_panes_horizontal_get(widget))
97      atk_state_set_add_state(state_set, ATK_STATE_HORIZONTAL);
98    else
99      atk_state_set_add_state(state_set, ATK_STATE_VERTICAL);
100
101    return state_set;
102 }
103
104 /**
105  * @brief Gets the specified child of obj
106  *
107  * The caller must unreference it when it is no longer needed.
108  *
109  * @param obj AtkObject instance
110  * @param i child index
111  * @return AtkObject representing the specified child of obj
112  */
113 static AtkObject*
114 eail_panes_ref_child(AtkObject *obj, int i)
115 {
116    Evas_Object *e_object, *widget;
117    AtkObject *child;
118
119    g_return_val_if_fail(EAIL_IS_PANES(obj), NULL);
120    g_return_val_if_fail((i < 2), NULL);
121
122    e_object = eail_widget_get_widget(EAIL_WIDGET(obj));
123    switch (i)
124      {
125       case 0:
126          widget = elm_object_part_content_get(e_object, "left");
127          child = eail_factory_get_accessible(widget);
128          break;
129       case 1:
130          widget = elm_object_part_content_get(e_object, "right");
131          child = eail_factory_get_accessible(widget);
132          break;
133       default:
134          child = NULL;
135          break;
136      }
137
138    if (child)
139      g_object_ref(child);
140
141    return child;
142 }
143
144 /**
145  * @brief EailPanes class initializer
146  *
147  * @param klass EailPanesClass instance
148  */
149 static void
150 eail_panes_class_init(EailPanesClass *klass)
151 {
152    AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
153
154    atk_class->initialize = eail_panes_initialize;
155    atk_class->get_n_children = eail_panes_n_children_get;
156    atk_class->ref_child = eail_panes_ref_child;
157    atk_class->ref_state_set = eail_panes_ref_state_set;
158 }
159
160 /**
161  * @brief Gets the maximum value of obj
162  *
163  * @param obj AtkValue instance
164  * @param [out] value maxiumum value of obj
165  */
166 static void
167 eail_panes_maximum_value_get(AtkValue *obj, GValue *value)
168 {
169    g_return_if_fail(EAIL_IS_PANES(obj));
170
171    memset(value, 0, sizeof(GValue));
172    g_value_init(value, G_TYPE_DOUBLE);
173    g_value_set_double(value, 1.0);
174 }
175
176 /**
177  * @brief Gets the minimum value of obj
178  *
179  * @param obj AtkValue instance
180  * @param [out] value minimum value of obj
181  */
182 static void
183 eail_panes_minimum_value_get(AtkValue *obj, GValue *value)
184 {
185    g_return_if_fail(EAIL_IS_PANES(obj));
186
187    memset(value, 0, sizeof(GValue));
188    g_value_init(value, G_TYPE_DOUBLE);
189    g_value_set_double(value, 0.0);
190 }
191
192 /**
193  * @brief Sets the current value of obj
194  *
195  * @param obj AtkValue instance
196  * @param value new value of obj
197  * @return TRUE if value is set successfully, FALSE otherwise
198  */
199 static gboolean
200 eail_panes_current_value_set(AtkValue *obj, const GValue *value)
201 {
202    Evas_Object *widget;
203    gdouble new_value;
204
205    g_return_val_if_fail(EAIL_IS_PANES(obj), FALSE);
206
207    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
208    if (!widget) return FALSE;
209
210    if (G_VALUE_HOLDS_DOUBLE(value))
211         new_value = g_value_get_double(value);
212    else
213      return FALSE;
214
215    if ((new_value >= 0.0) && (new_value <= 1.0))
216      {
217         elm_panes_content_left_size_set(widget, new_value);
218         return TRUE;
219      }
220    else
221      return FALSE;
222 }
223
224 /**
225  * @brief Gets the current value of obj
226  *
227  * @param obj AtkValue instance
228  * @param [out] value current value of obj
229  */
230 static void
231 eail_panes_current_value_get(AtkValue *obj, GValue *value)
232 {
233    Evas_Object *widget;
234    gdouble current_value;
235
236    g_return_if_fail(EAIL_IS_PANES(obj));
237    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
238    if (!widget) return;
239
240    current_value = elm_panes_content_left_size_get(widget);
241    memset(value, 0, sizeof(GValue));
242    g_value_init(value, G_TYPE_DOUBLE);
243    g_value_set_double(value, current_value);
244 }
245
246 /**
247  * @brief Gets obj's minimum increment
248  *
249  * The minimum increment is limited only by the floating point
250  * precision of the platform.
251  *
252  * @param obj AtkValue instance
253  * @param [out] value minimum increment of obj
254  */
255 static void
256 eail_panes_minimum_increment_get(AtkValue *obj,
257                                  GValue   *value)
258 {
259    Evas_Object *widget;
260
261    widget = eail_widget_get_widget(EAIL_WIDGET(obj));
262    if (!widget) return;
263
264    memset(value, 0, sizeof(GValue));
265    g_value_init(value, G_TYPE_DOUBLE);
266    g_value_set_double(value, 0);
267 }
268
269 /**
270  * @brief AtkValue interface initializer
271  *
272  * @param iface AtkValueIface instance
273  */
274 static void
275 atk_value_interface_init(AtkValueIface *iface)
276 {
277    g_return_if_fail(iface != NULL);
278
279    iface->get_current_value = eail_panes_current_value_get;
280    iface->set_current_value = eail_panes_current_value_set;
281    iface->get_maximum_value = eail_panes_maximum_value_get;
282    iface->get_minimum_value = eail_panes_minimum_value_get;
283    iface->get_minimum_increment = eail_panes_minimum_increment_get;
284 }