1 #include <Elementary.h>
5 * @defgroup Panes panes
9 typedef struct _Widget_Data Widget_Data;
28 Eina_Bool clicked_double;
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);
40 _del_hook(Evas_Object *obj)
42 Widget_Data *wd = elm_widget_data_get(obj);
48 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
50 Widget_Data *wd = elm_widget_data_get(obj);
52 edje_object_mirrored_set(wd->panes, rtl);
56 _theme_hook(Evas_Object *obj)
58 Widget_Data *wd = elm_widget_data_get(obj);
59 const char *style = elm_widget_style_get(obj);
63 _mirrored_set(obj, elm_widget_mirrored_get(obj));
64 size = elm_panes_content_left_size_get(obj);
67 _elm_theme_object_set(obj, wd->panes, "panes", "horizontal", style);
69 _elm_theme_object_set(obj, wd->panes, "panes", "vertical", style);
71 if (wd->contents.left)
72 edje_object_part_swallow(wd->panes, "elm.swallow.left", wd->contents.left);
73 if (wd->contents.right)
74 edje_object_part_swallow(wd->panes, "elm.swallow.right", wd->contents.right);
76 edje_object_scale_set(wd->panes, elm_widget_scale_get(obj) *
79 elm_panes_content_left_size_set(obj, size);
83 _elm_panes_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
85 Widget_Data *wd = elm_widget_data_get(obj);
91 edje_object_part_drag_value_get(wd->panes, "elm.bar", &w, &h);
92 if (((wd->horizontal) && ( h == 0.0 )) || ((!wd->horizontal) && ( w == 0.0 )))
93 return elm_widget_focus_next_get(wd->contents.right, dir, next);
95 Evas_Object *chain[2];
98 if (dir == ELM_FOCUS_PREVIOUS)
100 chain[0] = wd->contents.right;
101 chain[1] = wd->contents.left;
103 else if (dir == ELM_FOCUS_NEXT)
105 chain[0] = wd->contents.left;
106 chain[1] = wd->contents.right;
111 unsigned char i = elm_widget_focus_get(chain[1]);
113 if (elm_widget_focus_next_get(chain[i], dir, next))
118 Evas_Object *to_focus;
119 if (elm_widget_focus_next_get(chain[i], dir, &to_focus))
129 _sizing_eval(Evas_Object *obj)
131 Widget_Data *wd = elm_widget_data_get(obj);
136 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
142 _sub_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
144 Widget_Data *wd = elm_widget_data_get(obj);
145 Evas_Object *sub = event_info;
148 if (sub == wd->contents.left)
150 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
151 _changed_size_hints, obj);
152 wd->contents.left = NULL;
155 else if (sub == wd->contents.right)
157 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
158 _changed_size_hints, obj);
159 wd->contents.right= NULL;
165 _clicked(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
167 evas_object_smart_callback_call(data, "clicked", NULL);
171 _clicked_double(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
173 Widget_Data *wd = elm_widget_data_get(data);
175 wd->clicked_double = EINA_TRUE;
179 _press(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
181 evas_object_smart_callback_call(data, "press", NULL);
185 _unpress(void *data, Evas_Object *obj __UNUSED__ , const char *emission __UNUSED__, const char *source __UNUSED__)
187 Widget_Data *wd = elm_widget_data_get(data);
188 evas_object_smart_callback_call(data, "unpress", NULL);
190 if (wd->clicked_double)
192 evas_object_smart_callback_call(data, "clicked,double", NULL);
193 wd->clicked_double = EINA_FALSE;
198 * Add a new panes to the parent
200 * @param parent The parent object
201 * @return The new object or NULL if it cannot be created
206 elm_panes_add(Evas_Object *parent)
212 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
214 wd = ELM_NEW(Widget_Data);
215 e = evas_object_evas_get(parent);
217 obj = elm_widget_add(e);
218 ELM_SET_WIDTYPE(widtype, "panes");
219 elm_widget_type_set(obj, "panes");
220 elm_widget_sub_object_add(parent, obj);
221 elm_widget_data_set(obj, wd);
222 elm_widget_del_hook_set(obj, _del_hook);
223 elm_widget_theme_hook_set(obj, _theme_hook);
224 elm_widget_focus_next_hook_set(obj, _elm_panes_focus_next_hook);
225 elm_widget_can_focus_set(obj, EINA_FALSE);
227 wd->panes = edje_object_add(e);
228 _elm_theme_object_set(obj, wd->panes, "panes", "vertical", "default");
229 elm_widget_resize_object_set(obj, wd->panes);
230 evas_object_show(wd->panes);
232 elm_panes_content_left_size_set(obj, 0.5);
234 edje_object_signal_callback_add(wd->panes, "elm,action,click", "",
236 edje_object_signal_callback_add(wd->panes, "elm,action,click,double", "",
237 _clicked_double, obj);
238 edje_object_signal_callback_add(wd->panes, "elm,action,press", "",
240 edje_object_signal_callback_add(wd->panes, "elm,action,unpress", "",
243 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
244 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
245 _changed_size_hints, obj);
247 _mirrored_set(obj, elm_widget_mirrored_get(obj));
254 * Set the left content of the panes widget.
256 * Once the content object is set, a previously set one will be deleted.
257 * If you want to keep that old content object, use the
258 * elm_panes_content_left_unset() function.
260 * @param obj The panes object
261 * @param content The new left content object
266 elm_panes_content_left_set(Evas_Object *obj, Evas_Object *content)
268 ELM_CHECK_WIDTYPE(obj, widtype);
269 Widget_Data *wd = elm_widget_data_get(obj);
270 if (wd->contents.left)
272 evas_object_del(wd->contents.left);
273 wd->contents.left = NULL;
277 wd->contents.left = content;
278 elm_widget_sub_object_add(obj, content);
279 edje_object_part_swallow(wd->panes, "elm.swallow.left", content);
284 * Set the right content of the panes widget.
286 * Once the content object is set, a previously set one will be deleted.
287 * If you want to keep that old content object, use the
288 * elm_panes_content_right_unset() function.
290 * @param obj The panes object
291 * @param content The new right content object
296 elm_panes_content_right_set(Evas_Object *obj, Evas_Object *content)
298 ELM_CHECK_WIDTYPE(obj, widtype);
299 Widget_Data *wd = elm_widget_data_get(obj);
300 if (wd->contents.right)
302 evas_object_del(wd->contents.right);
303 wd->contents.right = NULL;
307 wd->contents.right = content;
308 elm_widget_sub_object_add(obj, content);
309 edje_object_part_swallow(wd->panes, "elm.swallow.right", content);
314 * Get the left content used for the panes
316 * Return the left content object which is set for this widget.
318 * @param obj The panes object
319 * @return The left content object that is being used
324 elm_panes_content_left_get(const Evas_Object *obj)
326 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
327 Widget_Data *wd = elm_widget_data_get(obj);
328 return wd->contents.left;
332 * Get the right content used for the panes
334 * Return the right content object which is set for this widget.
336 * @param obj The panes object
337 * @return The right content object that is being used
342 elm_panes_content_right_get(const Evas_Object *obj)
344 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
345 Widget_Data *wd = elm_widget_data_get(obj);
346 return wd->contents.right;
350 * Unset the left content used for the panes
352 * Unparent and return the left content object which was set for this widget.
354 * @param obj The panes object
355 * @return The left content object that was being used
360 elm_panes_content_left_unset(Evas_Object *obj)
362 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
363 Widget_Data *wd = elm_widget_data_get(obj);
364 if (!wd) return NULL;
365 if (!wd->contents.left) return NULL;
366 Evas_Object *content = wd->contents.left;
367 elm_widget_sub_object_del(obj, content);
368 edje_object_part_unswallow(wd->panes, content);
369 wd->contents.left = NULL;
374 * Unset the right content used for the panes
376 * Unparent and return the right content object which was set for this widget.
378 * @param obj The panes object
379 * @return The right content object that was being used
384 elm_panes_content_right_unset(Evas_Object *obj)
386 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
387 Widget_Data *wd = elm_widget_data_get(obj);
388 if (!wd) return NULL;
389 if (!wd->contents.right) return NULL;
390 Evas_Object *content = wd->contents.right;
391 elm_widget_sub_object_del(obj, content);
392 edje_object_part_unswallow(wd->panes, content);
393 wd->contents.right = NULL;
398 elm_panes_content_left_size_get(const Evas_Object *obj)
400 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
401 Widget_Data *wd = elm_widget_data_get(obj);
404 edje_object_part_drag_value_get(wd->panes, "elm.bar", &w, &h);
405 if (wd->horizontal) return h;
410 elm_panes_content_left_size_set(Evas_Object *obj, double size)
412 ELM_CHECK_WIDTYPE(obj, widtype);
413 Widget_Data *wd = elm_widget_data_get(obj);
415 if (size < 0.0) size = 0.0;
416 else if (size > 1.0) size = 1.0;
418 edje_object_part_drag_value_set(wd->panes, "elm.bar", 0.0, size);
420 edje_object_part_drag_value_set(wd->panes, "elm.bar", size, 0.0);
424 elm_panes_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
426 ELM_CHECK_WIDTYPE(obj, widtype);
427 Widget_Data *wd = elm_widget_data_get(obj);
429 wd->horizontal = horizontal;
431 elm_panes_content_left_size_set(obj, 0.5);
435 elm_panes_horizontal_get(const Evas_Object *obj)
437 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
438 Widget_Data *wd = elm_widget_data_get(obj);
439 return wd->horizontal;