Merge branch 'master' of ryuan.choi@165.213.180.234:/git/slp/pkgs/elementary
[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 _theme_hook(Evas_Object *obj);
35 static void _sizing_eval(Evas_Object *obj);
36 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
37
38 static void
39 _del_hook(Evas_Object *obj)
40 {
41    Widget_Data *wd = elm_widget_data_get(obj);
42    if (!wd) return;
43    free(wd);
44 }
45
46 static void
47 _theme_hook(Evas_Object *obj)
48 {
49    Widget_Data *wd = elm_widget_data_get(obj);
50    const char *style = elm_widget_style_get(obj);
51
52    if (!wd) return;
53    if (wd->horizontal)
54      _elm_theme_object_set(obj, wd->panes, "panes", "horizontal", style);
55    else
56      _elm_theme_object_set(obj, wd->panes, "panes", "vertical", style);
57
58    if (wd->contents.left)
59      edje_object_part_swallow(wd->panes, "elm.swallow.left", wd->contents.right);
60    if (wd->contents.right)
61      edje_object_part_swallow(wd->panes, "elm.swallow.right", wd->contents.right);
62
63    edje_object_scale_set(wd->panes, elm_widget_scale_get(obj) *
64                          _elm_config->scale);
65    _sizing_eval(obj);
66 }
67
68 static void
69 _sizing_eval(Evas_Object *obj)
70 {
71    Widget_Data *wd = elm_widget_data_get(obj);
72    if (!wd) return;
73 }
74
75 static void
76 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
77 {
78    _sizing_eval(data);
79 }
80
81 static void
82 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
83 {
84    Widget_Data *wd = elm_widget_data_get(obj);
85    Evas_Object *sub = event_info;
86
87    if (!wd) return;
88    if (sub == wd->contents.left)
89      {
90         evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
91                                             _changed_size_hints, obj);
92         wd->contents.left = NULL;
93         _sizing_eval(obj);
94      }
95    else if (sub == wd->contents.right)
96      {
97         evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
98                                             _changed_size_hints, obj);
99         wd->contents.right= NULL;
100         _sizing_eval(obj);
101      }
102 }
103
104 static void
105 _clicked(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
106 {
107    evas_object_smart_callback_call(data, "clicked", NULL);
108 }
109
110 static void
111 _clicked_double(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
112 {
113    Widget_Data *wd = elm_widget_data_get(data);
114
115    wd->clicked_double = EINA_TRUE;
116 }
117
118 static void
119 _press(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
120 {
121    evas_object_smart_callback_call(data, "press", NULL);
122 }
123
124 static void
125 _unpress(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
126 {
127    Widget_Data *wd = elm_widget_data_get(data);
128    evas_object_smart_callback_call(data, "unpress", NULL);
129
130    if (wd->clicked_double)
131      {
132         evas_object_smart_callback_call(data, "clicked,double", NULL);
133         wd->clicked_double = EINA_FALSE;
134      }
135 }
136
137 /**
138  * Add a new panes to the parent
139  *
140  * @param parent The parent object
141  * @return The new object or NULL if it cannot be created
142  *
143  * @ingroup Panel
144  */
145 EAPI Evas_Object *
146 elm_panes_add(Evas_Object *parent)
147 {
148    Evas_Object *obj;
149    Evas *e;
150    Widget_Data *wd;
151
152    wd = ELM_NEW(Widget_Data);
153    e = evas_object_evas_get(parent);
154    obj = elm_widget_add(e);
155    ELM_SET_WIDTYPE(widtype, "panes");
156    elm_widget_type_set(obj, "panes");
157    elm_widget_sub_object_add(parent, obj);
158    elm_widget_data_set(obj, wd);
159    elm_widget_del_hook_set(obj, _del_hook);
160    elm_widget_theme_hook_set(obj, _theme_hook);
161
162    wd->panes = edje_object_add(e);
163    _elm_theme_object_set(obj, wd->panes, "panes", "vertical", "default");
164    elm_widget_resize_object_set(obj, wd->panes);
165    evas_object_show(wd->panes);
166
167    elm_panes_content_left_size_set(obj, 0.5);
168
169    edje_object_signal_callback_add(wd->panes, "elm,action,click", "", 
170                                    _clicked, obj);
171    edje_object_signal_callback_add(wd->panes, "elm,action,click,double", "", 
172                                    _clicked_double, obj);
173    edje_object_signal_callback_add(wd->panes, "elm,action,press", "", 
174                                    _press, obj);
175    edje_object_signal_callback_add(wd->panes, "elm,action,unpress", "", 
176                                    _unpress, obj);
177
178    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
179    evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, 
180                                   _changed_size_hints, obj);
181
182    _sizing_eval(obj);
183    return obj;
184 }
185
186 EAPI void elm_panes_content_left_set(Evas_Object *obj, Evas_Object *content)
187 {
188    Widget_Data *wd = elm_widget_data_get(obj);
189
190    if (wd->contents.left)
191      {
192         evas_object_del(wd->contents.left);
193         wd->contents.left = NULL;
194      }
195
196    if (content)
197      {
198         wd->contents.left = content;
199         elm_widget_sub_object_add(obj, content);
200         edje_object_part_swallow(wd->panes, "elm.swallow.left", content);
201      }
202 }
203
204
205 EAPI void elm_panes_content_right_set(Evas_Object *obj, Evas_Object *content)
206 {
207    Widget_Data *wd = elm_widget_data_get(obj);
208
209    if (wd->contents.right)
210      {
211         evas_object_del(wd->contents.right);
212         wd->contents.right = NULL;
213      }
214
215    if (content)
216      {
217         wd->contents.right = content;
218         elm_widget_sub_object_add(obj, content);
219         edje_object_part_swallow(wd->panes, "elm.swallow.right", content);
220      }
221 }
222
223
224 EAPI Evas_Object
225 *elm_panes_content_left_get(const Evas_Object *obj)
226 {
227    Widget_Data *wd = elm_widget_data_get(obj);
228    return wd->contents.left;
229 }
230
231 EAPI Evas_Object
232 *elm_panes_content_right_get(const Evas_Object *obj)
233 {
234    Widget_Data *wd = elm_widget_data_get(obj);
235    return wd->contents.right;
236 }
237
238 EAPI double 
239 elm_panes_content_left_size_get(const Evas_Object *obj)
240 {
241    Widget_Data *wd = elm_widget_data_get(obj);
242    double w, h;
243
244    edje_object_part_drag_value_get(wd->panes, "elm.bar", &w, &h);
245
246    if (wd->horizontal)
247      return h;
248    else
249      return w;
250 }
251
252 EAPI void 
253 elm_panes_content_left_size_set(Evas_Object *obj, double size)
254 {
255    Widget_Data *wd = elm_widget_data_get(obj);
256
257    if (wd->horizontal)
258      edje_object_part_drag_value_set(wd->panes, "elm.bar", 0.0, size);
259    else
260      edje_object_part_drag_value_set(wd->panes, "elm.bar", size, 0.0);
261 }
262
263 EAPI void 
264 elm_panes_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
265 {
266    Widget_Data *wd = elm_widget_data_get(obj);
267
268    wd->horizontal = horizontal;
269    _theme_hook(obj);
270    elm_panes_content_left_size_set(obj, 0.5);
271 }
272
273 EAPI Eina_Bool 
274 elm_panes_horizontal_is(const Evas_Object *obj)
275 {
276    Widget_Data *wd = elm_widget_data_get(obj);
277
278    return wd->horizontal;
279 }