elementary / menu, notify, list, panes, module, map, pager, panel, mapbuf - removed...
[framework/uifw/elementary.git] / src / lib / elm_panes.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Panes Panes
6  *
7  */
8
9 typedef struct _Widget_Data Widget_Data;
10
11 struct _Widget_Data
12 {
13    Evas_Object *panes;
14
15    struct
16      {
17         Evas_Object *left;
18         Evas_Object *right;
19      } contents;
20
21    struct
22      {
23         int x_diff;
24         int y_diff;
25         Eina_Bool move;
26      } move;
27
28    Eina_Bool clicked_double;
29    Eina_Bool horizontal;
30 };
31
32 static const char *widtype = NULL;
33 static void _del_hook(Evas_Object *obj);
34 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
35 static void _theme_hook(Evas_Object *obj);
36 static void _sizing_eval(Evas_Object *obj);
37 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
38
39 static void
40 _del_hook(Evas_Object *obj)
41 {
42    Widget_Data *wd = elm_widget_data_get(obj);
43    if (!wd) return;
44    free(wd);
45 }
46
47 static void
48 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
49 {
50    Widget_Data *wd = elm_widget_data_get(obj);
51    if (!wd) return;
52    edje_object_mirrored_set(wd->panes, rtl);
53 }
54
55 static void
56 _theme_hook(Evas_Object *obj)
57 {
58    Widget_Data *wd = elm_widget_data_get(obj);
59    const char *style = elm_widget_style_get(obj);
60    double size;
61
62    if (!wd) return;
63    _elm_widget_mirrored_reload(obj);
64    _mirrored_set(obj, elm_widget_mirrored_get(obj));
65    size = elm_panes_content_left_size_get(obj);
66
67    if (wd->horizontal)
68      _elm_theme_object_set(obj, wd->panes, "panes", "horizontal", style);
69    else
70      _elm_theme_object_set(obj, wd->panes, "panes", "vertical", style);
71
72    if (wd->contents.left)
73      edje_object_part_swallow(wd->panes, "elm.swallow.left", wd->contents.left);
74    if (wd->contents.right)
75      edje_object_part_swallow(wd->panes, "elm.swallow.right", wd->contents.right);
76
77    edje_object_scale_set(wd->panes, elm_widget_scale_get(obj) *
78                          _elm_config->scale);
79    _sizing_eval(obj);
80    elm_panes_content_left_size_set(obj, size);
81 }
82
83 static Eina_Bool
84 _elm_panes_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
85 {
86    Widget_Data *wd = elm_widget_data_get(obj);
87
88    if (!wd)
89      return EINA_FALSE;
90
91    double w, h;
92    edje_object_part_drag_value_get(wd->panes, "elm.bar", &w, &h);
93    if (((wd->horizontal) && ( h == 0.0 )) || ((!wd->horizontal) && ( w == 0.0 )))
94      return elm_widget_focus_next_get(wd->contents.right, dir, next);
95
96    Evas_Object *chain[2];
97
98    /* Direction */
99    if (dir == ELM_FOCUS_PREVIOUS)
100      {
101         chain[0] = wd->contents.right;
102         chain[1] = wd->contents.left;
103      }
104    else if (dir == ELM_FOCUS_NEXT)
105      {
106         chain[0] = wd->contents.left;
107         chain[1] = wd->contents.right;
108      }
109    else
110      return EINA_FALSE;
111
112    unsigned char i = elm_widget_focus_get(chain[1]);
113
114    if (elm_widget_focus_next_get(chain[i], dir, next))
115      return EINA_TRUE;
116
117    i = !i;
118
119    Evas_Object *to_focus;
120    if (elm_widget_focus_next_get(chain[i], dir, &to_focus))
121      {
122         *next = to_focus;
123         return !!i;
124      }
125
126    return EINA_FALSE;
127 }
128
129 static void
130 _sizing_eval(Evas_Object *obj)
131 {
132    Widget_Data *wd = elm_widget_data_get(obj);
133    if (!wd) return;
134 }
135
136 static void
137 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
138 {
139    _sizing_eval(data);
140 }
141
142 static void
143 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
144 {
145    Widget_Data *wd = elm_widget_data_get(obj);
146    Evas_Object *sub = event_info;
147
148    if (!wd) return;
149    if (sub == wd->contents.left)
150      {
151         evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
152                                             _changed_size_hints, obj);
153         wd->contents.left = NULL;
154         _sizing_eval(obj);
155      }
156    else if (sub == wd->contents.right)
157      {
158         evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
159                                             _changed_size_hints, obj);
160         wd->contents.right= NULL;
161         _sizing_eval(obj);
162      }
163 }
164
165 static void
166 _clicked(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
167 {
168    evas_object_smart_callback_call(data, "clicked", NULL);
169 }
170
171 static void
172 _clicked_double(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
173 {
174    Widget_Data *wd = elm_widget_data_get(data);
175
176    wd->clicked_double = EINA_TRUE;
177 }
178
179 static void
180 _press(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
181 {
182    evas_object_smart_callback_call(data, "press", NULL);
183 }
184
185 static void
186 _unpress(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
187 {
188    Widget_Data *wd = elm_widget_data_get(data);
189    evas_object_smart_callback_call(data, "unpress", NULL);
190
191    if (wd->clicked_double)
192      {
193         evas_object_smart_callback_call(data, "clicked,double", NULL);
194         wd->clicked_double = EINA_FALSE;
195      }
196 }
197
198 /**
199  * Add a new panes to the parent
200  *
201  * @param parent The parent object
202  * @return The new object or NULL if it cannot be created
203  *
204  * @ingroup Panes
205  */
206 EAPI Evas_Object *
207 elm_panes_add(Evas_Object *parent)
208 {
209    Evas_Object *obj;
210    Evas *e;
211    Widget_Data *wd;
212
213    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
214
215    ELM_SET_WIDTYPE(widtype, "panes");
216    elm_widget_type_set(obj, "panes");
217    elm_widget_sub_object_add(parent, obj);
218    elm_widget_data_set(obj, wd);
219    elm_widget_del_hook_set(obj, _del_hook);
220    elm_widget_theme_hook_set(obj, _theme_hook);
221    elm_widget_focus_next_hook_set(obj, _elm_panes_focus_next_hook);
222    elm_widget_can_focus_set(obj, EINA_FALSE);
223
224    wd->panes = edje_object_add(e);
225    _elm_theme_object_set(obj, wd->panes, "panes", "vertical", "default");
226    elm_widget_resize_object_set(obj, wd->panes);
227    evas_object_show(wd->panes);
228
229    elm_panes_content_left_size_set(obj, 0.5);
230
231    edje_object_signal_callback_add(wd->panes, "elm,action,click", "",
232                                    _clicked, obj);
233    edje_object_signal_callback_add(wd->panes, "elm,action,click,double", "",
234                                    _clicked_double, obj);
235    edje_object_signal_callback_add(wd->panes, "elm,action,press", "",
236                                    _press, obj);
237    edje_object_signal_callback_add(wd->panes, "elm,action,unpress", "",
238                                    _unpress, obj);
239
240    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
241    evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
242                                   _changed_size_hints, obj);
243
244    _mirrored_set(obj, elm_widget_mirrored_get(obj));
245    _sizing_eval(obj);
246    return obj;
247 }
248
249
250 /**
251  * Set the left content of the panes widget.
252  *
253  * Once the content object is set, a previously set one will be deleted.
254  * If you want to keep that old content object, use the
255  * elm_panes_content_left_unset() function.
256  *
257  * @param obj The panes object
258  * @param content The new left content object
259  *
260  * @ingroup Panes
261  */
262 EAPI void
263 elm_panes_content_left_set(Evas_Object *obj, Evas_Object *content)
264 {
265    ELM_CHECK_WIDTYPE(obj, widtype);
266    Widget_Data *wd = elm_widget_data_get(obj);
267    if (wd->contents.left)
268      {
269         evas_object_del(wd->contents.left);
270         wd->contents.left = NULL;
271      }
272    if (content)
273      {
274         wd->contents.left = content;
275         elm_widget_sub_object_add(obj, content);
276         edje_object_part_swallow(wd->panes, "elm.swallow.left", content);
277      }
278 }
279
280 /**
281  * Set the right content of the panes widget.
282  *
283  * Once the content object is set, a previously set one will be deleted.
284  * If you want to keep that old content object, use the
285  * elm_panes_content_right_unset() function.
286  *
287  * @param obj The panes object
288  * @param content The new right content object
289  *
290  * @ingroup Panes
291  */
292 EAPI void
293 elm_panes_content_right_set(Evas_Object *obj, Evas_Object *content)
294 {
295    ELM_CHECK_WIDTYPE(obj, widtype);
296    Widget_Data *wd = elm_widget_data_get(obj);
297    if (wd->contents.right)
298      {
299         evas_object_del(wd->contents.right);
300         wd->contents.right = NULL;
301      }
302    if (content)
303      {
304         wd->contents.right = content;
305         elm_widget_sub_object_add(obj, content);
306         edje_object_part_swallow(wd->panes, "elm.swallow.right", content);
307      }
308 }
309
310 /**
311  * Get the left content used for the panes
312  *
313  * Return the left content object which is set for this widget.
314  *
315  * @param obj The panes object
316  * @return The left content object that is being used
317  *
318  * @ingroup Panes
319  */
320 EAPI Evas_Object *
321 elm_panes_content_left_get(const Evas_Object *obj)
322 {
323    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
324    Widget_Data *wd = elm_widget_data_get(obj);
325    return wd->contents.left;
326 }
327
328 /**
329  * Get the right content used for the panes
330  *
331  * Return the right content object which is set for this widget.
332  *
333  * @param obj The panes object
334  * @return The right content object that is being used
335  *
336  * @ingroup Panes
337  */
338 EAPI Evas_Object *
339 elm_panes_content_right_get(const Evas_Object *obj)
340 {
341    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
342    Widget_Data *wd = elm_widget_data_get(obj);
343    return wd->contents.right;
344 }
345
346 /**
347  * Unset the left content used for the panes
348  *
349  * Unparent and return the left content object which was set for this widget.
350  *
351  * @param obj The panes object
352  * @return The left content object that was being used
353  *
354  * @ingroup Panes
355  */
356 EAPI Evas_Object *
357 elm_panes_content_left_unset(Evas_Object *obj)
358 {
359    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
360    Widget_Data *wd = elm_widget_data_get(obj);
361    if (!wd) return NULL;
362    if (!wd->contents.left) return NULL;
363    Evas_Object *content = wd->contents.left;
364    elm_widget_sub_object_del(obj, content);
365    edje_object_part_unswallow(wd->panes, content);
366    wd->contents.left = NULL;
367    return content;
368 }
369
370 /**
371  * Unset the right content used for the panes
372  *
373  * Unparent and return the right content object which was set for this widget.
374  *
375  * @param obj The panes object
376  * @return The right content object that was being used
377  *
378  * @ingroup Panes
379  */
380 EAPI Evas_Object *
381 elm_panes_content_right_unset(Evas_Object *obj)
382 {
383    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
384    Widget_Data *wd = elm_widget_data_get(obj);
385    if (!wd) return NULL;
386    if (!wd->contents.right) return NULL;
387    Evas_Object *content = wd->contents.right;
388    elm_widget_sub_object_del(obj, content);
389    edje_object_part_unswallow(wd->panes, content);
390    wd->contents.right = NULL;
391    return content;
392 }
393
394 EAPI double
395 elm_panes_content_left_size_get(const Evas_Object *obj)
396 {
397    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
398    Widget_Data *wd = elm_widget_data_get(obj);
399    double w, h;
400
401    edje_object_part_drag_value_get(wd->panes, "elm.bar", &w, &h);
402    if (wd->horizontal) return h;
403    else return w;
404 }
405
406 EAPI void
407 elm_panes_content_left_size_set(Evas_Object *obj, double size)
408 {
409    ELM_CHECK_WIDTYPE(obj, widtype);
410    Widget_Data *wd = elm_widget_data_get(obj);
411
412    if (size < 0.0) size = 0.0;
413    else if (size > 1.0) size = 1.0;
414    if (wd->horizontal)
415      edje_object_part_drag_value_set(wd->panes, "elm.bar", 0.0, size);
416    else
417      edje_object_part_drag_value_set(wd->panes, "elm.bar", size, 0.0);
418 }
419
420 EAPI void
421 elm_panes_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
422 {
423    ELM_CHECK_WIDTYPE(obj, widtype);
424    Widget_Data *wd = elm_widget_data_get(obj);
425
426    wd->horizontal = horizontal;
427    _theme_hook(obj);
428    elm_panes_content_left_size_set(obj, 0.5);
429 }
430
431 EAPI Eina_Bool
432 elm_panes_horizontal_get(const Evas_Object *obj)
433 {
434    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
435    Widget_Data *wd = elm_widget_data_get(obj);
436    return wd->horizontal;
437 }