[src/lib/elm_panes.c] Comment modification.
[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    Eina_Bool fixed;
31 };
32
33 static const char *widtype = NULL;
34 static void _del_hook(Evas_Object *obj);
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 _theme_hook(Evas_Object *obj)
49 {
50    Widget_Data *wd = elm_widget_data_get(obj);
51    const char *style = elm_widget_style_get(obj);
52
53    if (!wd) return;
54    if (wd->horizontal)
55      _elm_theme_object_set(obj, wd->panes, "panes", "horizontal", style);
56    else
57      _elm_theme_object_set(obj, wd->panes, "panes", "vertical", style);
58
59    if (wd->contents.left)
60      edje_object_part_swallow(wd->panes, "elm.swallow.left", wd->contents.right);
61    if (wd->contents.right)
62      edje_object_part_swallow(wd->panes, "elm.swallow.right", wd->contents.right);
63
64    edje_object_scale_set(wd->panes, elm_widget_scale_get(obj) *
65                          _elm_config->scale);
66    _sizing_eval(obj);
67 }
68
69 static void
70 _sizing_eval(Evas_Object *obj)
71 {
72    Widget_Data *wd = elm_widget_data_get(obj);
73    if (!wd) return;
74 }
75
76 static void
77 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
78 {
79    _sizing_eval(data);
80 }
81
82 static void
83 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
84 {
85    Widget_Data *wd = elm_widget_data_get(obj);
86    Evas_Object *sub = event_info;
87
88    if (!wd) return;
89    if (sub == wd->contents.left)
90      {
91         evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
92                                             _changed_size_hints, obj);
93         wd->contents.left = NULL;
94         _sizing_eval(obj);
95      }
96    else if (sub == wd->contents.right)
97      {
98         evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
99                                             _changed_size_hints, obj);
100         wd->contents.right= NULL;
101         _sizing_eval(obj);
102      }
103 }
104
105 static void
106 _clicked(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
107 {
108    evas_object_smart_callback_call(data, "clicked", NULL);
109 }
110
111 static void
112 _clicked_double(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
113 {
114    Widget_Data *wd = elm_widget_data_get(data);
115
116    wd->clicked_double = EINA_TRUE;
117 }
118
119 static void
120 _press(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
121 {
122    evas_object_smart_callback_call(data, "press", NULL);
123 }
124
125 static void
126 _unpress(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
127 {
128    Widget_Data *wd = elm_widget_data_get(data);
129    evas_object_smart_callback_call(data, "unpress", NULL);
130
131    if (wd->clicked_double)
132      {
133         evas_object_smart_callback_call(data, "clicked,double", NULL);
134         wd->clicked_double = EINA_FALSE;
135      }
136 }
137
138 /**
139  * Add a new panes to the parent
140  *
141  * @param parent The parent object
142  * @return The new object or NULL if it cannot be created
143  *
144  * @ingroup Panes
145  */
146 EAPI Evas_Object *
147 elm_panes_add(Evas_Object *parent)
148 {
149    Evas_Object *obj;
150    Evas *e;
151    Widget_Data *wd;
152
153    wd = ELM_NEW(Widget_Data);
154    e = evas_object_evas_get(parent);
155    obj = elm_widget_add(e);
156    ELM_SET_WIDTYPE(widtype, "panes");
157    elm_widget_type_set(obj, "panes");
158    elm_widget_sub_object_add(parent, obj);
159    elm_widget_data_set(obj, wd);
160    elm_widget_del_hook_set(obj, _del_hook);
161    elm_widget_theme_hook_set(obj, _theme_hook);
162
163    wd->panes = edje_object_add(e);
164    _elm_theme_object_set(obj, wd->panes, "panes", "vertical", "default");
165    elm_widget_resize_object_set(obj, wd->panes);
166    evas_object_show(wd->panes);
167
168    elm_panes_content_left_size_set(obj, 0.5);
169
170    edje_object_signal_callback_add(wd->panes, "elm,action,click", "", 
171                                    _clicked, obj);
172    edje_object_signal_callback_add(wd->panes, "elm,action,click,double", "", 
173                                    _clicked_double, obj);
174    edje_object_signal_callback_add(wd->panes, "elm,action,press", "", 
175                                    _press, obj);
176    edje_object_signal_callback_add(wd->panes, "elm,action,unpress", "", 
177                                    _unpress, obj);
178
179    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
180    evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, 
181                                   _changed_size_hints, obj);
182
183    _sizing_eval(obj);
184    return obj;
185 }
186
187 /**
188  * Set a control as a left/top content of the pane
189  *
190  * @param obj The pane object
191  * @param content The object to be set as content
192  *
193  * @ingroup Panes
194  */
195 EAPI void elm_panes_content_left_set(Evas_Object *obj, Evas_Object *content)
196 {
197    Widget_Data *wd = elm_widget_data_get(obj);
198
199    if (wd->contents.left)
200      {
201         evas_object_del(wd->contents.left);
202         wd->contents.left = NULL;
203      }
204
205    if (content)
206      {
207         wd->contents.left = content;
208         elm_widget_sub_object_add(obj, content);
209         edje_object_part_swallow(wd->panes, "elm.swallow.left", content);
210      }
211 }
212
213 /**
214  * Set a control as a right/bottom content of the pane
215  *
216  * @param obj The pane object
217  * @param content The object to be set as content
218  *
219  * @ingroup Panes
220  */
221 EAPI void elm_panes_content_right_set(Evas_Object *obj, Evas_Object *content)
222 {
223    Widget_Data *wd = elm_widget_data_get(obj);
224
225    if (wd->contents.right)
226      {
227         evas_object_del(wd->contents.right);
228         wd->contents.right = NULL;
229      }
230
231    if (content)
232      {
233         wd->contents.right = content;
234         elm_widget_sub_object_add(obj, content);
235         edje_object_part_swallow(wd->panes, "elm.swallow.right", content);
236      }
237 }
238
239 /**
240  * Get the left/top content of the pane
241  *
242  * @param obj The pane object
243  * @return The Evas Object set as a left/top content of the pane
244  *
245  * @ingroup Panes
246  */
247 EAPI Evas_Object
248 *elm_panes_content_left_get(const Evas_Object *obj)
249 {
250    Widget_Data *wd = elm_widget_data_get(obj);
251    return wd->contents.left;
252 }
253
254 /**
255  * Get the right/bottom content of the pane
256  *
257  * @param obj The pane object
258  * @return The Evas Object set as a right/bottom content of the pane
259  *
260  * @ingroup Panes
261  */
262 EAPI Evas_Object
263 *elm_panes_content_right_get(const Evas_Object *obj)
264 {
265    Widget_Data *wd = elm_widget_data_get(obj);
266    return wd->contents.right;
267 }
268
269 /**
270  * Get the relative normalized size of left/top content of the pane
271  *
272  * @param obj The pane object
273  * @return The value of type double in the range [0.0,1.0]
274  *
275  * @ingroup Panes
276  */
277 EAPI double 
278 elm_panes_content_left_size_get(const Evas_Object *obj)
279 {
280    Widget_Data *wd = elm_widget_data_get(obj);
281    double w, h;
282
283    edje_object_part_drag_value_get(wd->panes, "elm.bar", &w, &h);
284
285    if (wd->horizontal)
286      return h;
287    else
288      return w;
289 }
290
291 /**
292  * Set a size of the left content with a relative normalized double value
293  *
294  * @param obj The pane object
295  * @param size The value of type double in the range [0.0,1.0]
296  *
297  * @ingroup Panes
298  */
299 EAPI void 
300 elm_panes_content_left_size_set(Evas_Object *obj, double size)
301 {
302    Widget_Data *wd = elm_widget_data_get(obj);
303
304    if (wd->horizontal)
305      edje_object_part_drag_value_set(wd->panes, "elm.bar", 0.0, size);
306    else
307      edje_object_part_drag_value_set(wd->panes, "elm.bar", size, 0.0);
308 }
309
310 /**
311  * Set the type of an existing pane object to horizontal/vertical
312  *
313  * @param obj The pane object
314  * @param horizontal Boolean value. If true, then the type is set to horizontal else vertical
315  *
316  * @ingroup Panes
317  */
318 EAPI void 
319 elm_panes_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
320 {
321    Widget_Data *wd = elm_widget_data_get(obj);
322
323    wd->horizontal = horizontal;
324    _theme_hook(obj);
325    elm_panes_content_left_size_set(obj, 0.5);
326 }
327
328 /**
329  * Indicate if the type of pane object is horizontal or not
330  *
331  * @param obj The pane object
332  * @return true if it is of horizontal type else false
333  *
334  * @ingroup Panes
335  */
336 EAPI Eina_Bool 
337 elm_panes_horizontal_is(const Evas_Object *obj)
338 {
339    Widget_Data *wd = elm_widget_data_get(obj);
340
341    return wd->horizontal;
342 }
343
344 /**
345  * Set a handler of the pane object non-movable or movable
346  *
347  * @param obj The pane object
348  * @param fixed If set to true then the views size can't be changed using handler otherwise using handler they can be resized
349  *
350  * @ingroup Panes
351  */
352 EAPI void
353 elm_panes_fixed_set(Evas_Object *obj, Eina_Bool fixed)
354 {
355    Widget_Data *wd = elm_widget_data_get(obj);
356    wd->fixed = fixed;
357    if(wd->fixed == EINA_TRUE)
358       edje_object_signal_emit(wd->panes, "elm.fixed", "movement.decider");
359    else
360       edje_object_signal_emit(wd->panes, "elm.unfixed", "movement.decider");
361 }
362
363 /**
364  * Indicate if the handler of the pane object can be moved with user interaction
365  *
366  * @param obj The pane object
367  * @return false if the views can be resized using handler else true
368  *
369  * @ingroup Panes
370  */
371 EAPI Eina_Bool
372 elm_panes_fixed_is(const Evas_Object *obj)
373 {
374    Widget_Data *wd = elm_widget_data_get(obj);
375    return wd->fixed;
376 }