tizen 2.3.1 release
[framework/uifw/elementary.git] / src / lib / elm_panes.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "elm_widget_panes.h"
4
5 /**
6  * TODO
7  * Update the minimun height of the bar in the theme.
8  * No minimun should be set in the vertical theme
9  * Add events (move, start ...)
10  */
11
12 EAPI const char ELM_PANES_SMART_NAME[] = "elm_panes";
13
14 static const char SIG_CLICKED[] = "clicked";
15 static const char SIG_PRESS[] = "press";
16 static const char SIG_UNPRESS[] = "unpress";
17 static const char SIG_DOUBLE_CLICKED[] = "clicked,double";
18 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
19    {SIG_CLICKED, ""},
20    {SIG_PRESS, ""},
21    {SIG_UNPRESS, ""},
22    {SIG_DOUBLE_CLICKED, ""},
23    {NULL, NULL}
24 };
25
26 static const Elm_Layout_Part_Alias_Description _content_aliases[] =
27 {
28    {"left", "elm.swallow.left"},
29    {"right", "elm.swallow.right"},
30    {"top", "elm.swallow.left"},
31    {"bottom", "elm.swallow.right"},
32    {NULL, NULL}
33 };
34
35 EVAS_SMART_SUBCLASS_NEW
36   (ELM_PANES_SMART_NAME, _elm_panes, Elm_Panes_Smart_Class,
37   Elm_Layout_Smart_Class, elm_layout_smart_class_get, _smart_callbacks);
38
39 static Eina_Bool
40 _elm_panes_smart_theme(Evas_Object *obj)
41 {
42    double size;
43
44    ELM_PANES_DATA_GET(obj, sd);
45
46    if (sd->horizontal)
47      eina_stringshare_replace(&(ELM_LAYOUT_DATA(sd)->group), "horizontal");
48    else
49      eina_stringshare_replace(&(ELM_LAYOUT_DATA(sd)->group), "vertical");
50
51    if (!ELM_WIDGET_CLASS(_elm_panes_parent_sc)->theme(obj)) return EINA_FALSE;
52
53    size = elm_panes_content_left_size_get(obj);
54
55    if (sd->fixed) elm_layout_signal_emit(obj, "elm.panes.fixed", "elm");
56
57    elm_layout_sizing_eval(obj);
58
59    elm_panes_content_left_size_set(obj, size);
60
61    return EINA_TRUE;
62 }
63
64 static Eina_Bool
65 _elm_panes_smart_focus_next(const Evas_Object *obj,
66                             Elm_Focus_Direction dir,
67                             Evas_Object **next)
68 {
69    double w, h;
70    unsigned char i;
71    Evas_Object *to_focus;
72    Evas_Object *chain[2];
73    Evas_Object *left, *right;
74
75    ELM_PANES_DATA_GET(obj, sd);
76
77    edje_object_part_drag_value_get
78      (ELM_WIDGET_DATA(sd)->resize_obj, "elm.bar", &w, &h);
79
80    left = elm_layout_content_get(obj, "left");
81    right = elm_layout_content_get(obj, "right");
82
83    if (((sd->horizontal) && (h == 0.0)) || ((!sd->horizontal) && (w == 0.0)))
84      return elm_widget_focus_next_get(right, dir, next);
85
86    /* Direction */
87    if (dir == ELM_FOCUS_PREVIOUS)
88      {
89         chain[0] = right;
90         chain[1] = left;
91      }
92    else if (dir == ELM_FOCUS_NEXT)
93      {
94         chain[0] = left;
95         chain[1] = right;
96      }
97    else return EINA_FALSE;
98
99    i = elm_widget_focus_get(chain[1]);
100
101    if (elm_widget_focus_next_get(chain[i], dir, next)) return EINA_TRUE;
102
103    i = !i;
104
105    if (elm_widget_focus_next_get(chain[i], dir, &to_focus))
106      {
107         *next = to_focus;
108         return !!i;
109      }
110
111    return EINA_FALSE;
112 }
113
114 static void
115 _on_clicked(void *data,
116             Evas_Object *obj __UNUSED__,
117             const char *emission __UNUSED__,
118             const char *source __UNUSED__)
119 {
120    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
121 }
122
123 static void
124 _double_clicked(void *data,
125                 Evas_Object *obj __UNUSED__,
126                 const char *emission __UNUSED__,
127                 const char *source __UNUSED__)
128 {
129    ELM_PANES_DATA_GET(data, sd);
130
131    sd->double_clicked = EINA_TRUE;
132 }
133
134 static void
135 _on_pressed(void *data,
136             Evas_Object *obj __UNUSED__,
137             const char *emission __UNUSED__,
138             const char *source __UNUSED__)
139 {
140    evas_object_smart_callback_call(data, SIG_PRESS, NULL);
141 }
142
143 static void
144 _on_unpressed(void *data,
145               Evas_Object *obj __UNUSED__,
146               const char *emission __UNUSED__,
147               const char *source __UNUSED__)
148 {
149    ELM_PANES_DATA_GET(data, sd);
150    evas_object_smart_callback_call(data, SIG_UNPRESS, NULL);
151
152    if (sd->double_clicked)
153      {
154         evas_object_smart_callback_call(data, SIG_DOUBLE_CLICKED, NULL);
155         sd->double_clicked = EINA_FALSE;
156      }
157 }
158
159 static void
160 _elm_panes_smart_add(Evas_Object *obj)
161 {
162    EVAS_SMART_DATA_ALLOC(obj, Elm_Panes_Smart_Data);
163
164    ELM_WIDGET_CLASS(_elm_panes_parent_sc)->base.add(obj);
165
166 }
167
168 static void
169 _elm_panes_smart_set_user(Elm_Panes_Smart_Class *sc)
170 {
171    ELM_WIDGET_CLASS(sc)->base.add = _elm_panes_smart_add;
172
173    ELM_WIDGET_CLASS(sc)->theme = _elm_panes_smart_theme;
174    ELM_WIDGET_CLASS(sc)->focus_next = _elm_panes_smart_focus_next;
175
176    ELM_LAYOUT_CLASS(sc)->content_aliases = _content_aliases;
177 }
178
179 EAPI const Elm_Panes_Smart_Class *
180 elm_panes_smart_class_get(void)
181 {
182    static Elm_Panes_Smart_Class _sc =
183      ELM_PANES_SMART_CLASS_INIT_NAME_VERSION(ELM_PANES_SMART_NAME);
184    static const Elm_Panes_Smart_Class *class = NULL;
185    Evas_Smart_Class *esc = (Evas_Smart_Class *)&_sc;
186
187    if (class)
188      return class;
189
190    _elm_panes_smart_set(&_sc);
191    esc->callbacks = _smart_callbacks;
192    class = &_sc;
193
194    return class;
195 }
196
197 EAPI Evas_Object *
198 elm_panes_add(Evas_Object *parent)
199 {
200    Evas_Object *obj;
201
202    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
203
204    obj = elm_widget_add(_elm_panes_smart_class_new(), parent);
205    if (!obj) return NULL;
206
207    if (!elm_widget_sub_object_add(parent, obj))
208      ERR("could not add %p as sub object of %p", obj, parent);
209
210    elm_layout_theme_set(obj, "panes", "vertical", elm_widget_style_get(obj));
211
212    elm_panes_content_left_size_set(obj, 0.5);
213
214    ELM_WIDGET_DATA_GET(obj, wsd);
215
216    edje_object_signal_callback_add
217      (wsd->resize_obj, "elm,action,click", "",
218      _on_clicked, obj);
219    edje_object_signal_callback_add
220      (wsd->resize_obj, "elm,action,click,double", "",
221      _double_clicked, obj);
222    edje_object_signal_callback_add
223      (wsd->resize_obj, "elm,action,press", "",
224      _on_pressed, obj);
225    edje_object_signal_callback_add
226      (wsd->resize_obj, "elm,action,unpress", "",
227      _on_unpressed, obj);
228
229    elm_widget_can_focus_set(obj, EINA_FALSE);
230
231    elm_layout_sizing_eval(obj);
232
233    //Tizen Only: This should be removed when eo is applied.
234    wsd->on_create = EINA_FALSE;
235
236    return obj;
237 }
238
239 EINA_DEPRECATED EAPI void
240 elm_panes_content_left_set(Evas_Object *obj,
241                            Evas_Object *content)
242 {
243    elm_layout_content_set(obj, "left", content);
244 }
245
246 EINA_DEPRECATED EAPI void
247 elm_panes_content_right_set(Evas_Object *obj,
248                             Evas_Object *content)
249 {
250    elm_layout_content_set(obj, "right", content);
251 }
252
253 EINA_DEPRECATED EAPI Evas_Object *
254 elm_panes_content_left_get(const Evas_Object *obj)
255 {
256    return elm_layout_content_get(obj, "left");
257 }
258
259 EINA_DEPRECATED EAPI Evas_Object *
260 elm_panes_content_right_get(const Evas_Object *obj)
261 {
262    return elm_layout_content_get(obj, "right");
263 }
264
265 EINA_DEPRECATED EAPI Evas_Object *
266 elm_panes_content_left_unset(Evas_Object *obj)
267 {
268    return elm_layout_content_unset(obj, "left");
269 }
270
271 EINA_DEPRECATED EAPI Evas_Object *
272 elm_panes_content_right_unset(Evas_Object *obj)
273 {
274    return elm_layout_content_unset(obj, "right");
275 }
276
277 EAPI double
278 elm_panes_content_left_size_get(const Evas_Object *obj)
279 {
280    double w, h;
281
282    ELM_PANES_CHECK(obj) 0.0;
283    ELM_PANES_DATA_GET(obj, sd);
284
285    edje_object_part_drag_value_get
286      (ELM_WIDGET_DATA(sd)->resize_obj, "elm.bar", &w, &h);
287
288    if (sd->horizontal) return h;
289    else return w;
290 }
291
292 EAPI void
293 elm_panes_content_left_size_set(Evas_Object *obj,
294                                 double size)
295 {
296    ELM_PANES_CHECK(obj);
297    ELM_PANES_DATA_GET(obj, sd);
298
299    if (size < 0.0) size = 0.0;
300    else if (size > 1.0)
301      size = 1.0;
302    if (sd->horizontal)
303      edje_object_part_drag_value_set
304        (ELM_WIDGET_DATA(sd)->resize_obj, "elm.bar", 0.0, size);
305    else
306      edje_object_part_drag_value_set
307        (ELM_WIDGET_DATA(sd)->resize_obj, "elm.bar", size, 0.0);
308 }
309
310 EAPI double
311 elm_panes_content_right_size_get(const Evas_Object *obj)
312 {
313    return 1.0 - elm_panes_content_left_size_get(obj);
314 }
315
316 EAPI void
317 elm_panes_content_right_size_set(Evas_Object *obj,
318                                  double size)
319 {
320    elm_panes_content_left_size_set(obj, (1.0 - size));
321 }
322
323 EAPI void
324 elm_panes_horizontal_set(Evas_Object *obj,
325                          Eina_Bool horizontal)
326 {
327    ELM_PANES_CHECK(obj);
328    ELM_PANES_DATA_GET(obj, sd);
329
330    sd->horizontal = horizontal;
331    _elm_panes_smart_theme(obj);
332
333    elm_panes_content_left_size_set(obj, 0.5);
334 }
335
336 EAPI Eina_Bool
337 elm_panes_horizontal_get(const Evas_Object *obj)
338 {
339    ELM_PANES_CHECK(obj) EINA_FALSE;
340    ELM_PANES_DATA_GET(obj, sd);
341
342    return sd->horizontal;
343 }
344
345 EAPI void
346 elm_panes_fixed_set(Evas_Object *obj, Eina_Bool fixed)
347 {
348    ELM_PANES_CHECK(obj);
349    ELM_PANES_DATA_GET(obj, sd);
350
351    sd->fixed = !!fixed;
352    if (sd->fixed == EINA_TRUE)
353      elm_layout_signal_emit(obj, "elm.panes.fixed", "elm");
354    else
355      elm_layout_signal_emit(obj, "elm.panes.unfixed", "elm");
356 }
357
358 EAPI Eina_Bool
359 elm_panes_fixed_get(const Evas_Object *obj)
360 {
361    ELM_PANES_CHECK(obj) EINA_FALSE;
362    ELM_PANES_DATA_GET(obj, sd);
363
364    return sd->fixed;
365 }