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