1 #include <Elementary.h>
3 #include "els_scroller.h"
6 typedef struct _Widget_Data Widget_Data;
9 Evas_Object *scr, *bx, *content;
10 Elm_Panel_Orient orient;
14 static const char *widtype = NULL;
15 static void _del_hook(Evas_Object *obj);
16 static void _theme_hook(Evas_Object *obj);
17 static void _on_focus_hook(void *data, Evas_Object *obj);
18 static void _sizing_eval(Evas_Object *obj);
19 static void _resize(void *data, Evas *evas, Evas_Object *obj, void *event);
20 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
21 static void _toggle_panel(void *data, Evas_Object *obj, const char *emission, const char *source);
24 _del_hook(Evas_Object *obj)
26 Widget_Data *wd = elm_widget_data_get(obj);
32 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
34 Widget_Data *wd = elm_widget_data_get(obj);
39 elm_widget_mirrored_set(wd->bx, rtl);
40 elm_panel_orient_set(obj, elm_panel_orient_get(obj));
45 _theme_hook(Evas_Object *obj)
47 Widget_Data *wd = elm_widget_data_get(obj);
49 _elm_widget_mirrored_reload(obj);
55 _mirrored_set(obj, elm_widget_mirrored_get(obj));
56 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base",
57 elm_widget_style_get(obj));
58 // scale = (elm_widget_scale_get(obj) * _elm_config->scale);
59 // edje_object_scale_set(wd->scr, scale);
60 edj = elm_smart_scroller_edje_object_get(wd->scr);
61 str = edje_object_data_get(edj, "focus_highlight");
62 if ((str) && (!strcmp(str, "on")))
63 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
65 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
72 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
74 Widget_Data *wd = elm_widget_data_get(obj);
76 if (elm_widget_focus_get(obj))
77 evas_object_focus_set(obj, EINA_TRUE);
79 evas_object_focus_set(obj, EINA_FALSE);
83 _elm_panel_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
85 Widget_Data *wd = elm_widget_data_get(obj);
88 if ((!wd) || (!wd->content))
93 /* Try Focus cycle in subitem */
95 return elm_widget_focus_next_get(cur, dir, next);
98 *next = (Evas_Object *)obj;
99 return !elm_widget_focus_get(obj);
103 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
105 Widget_Data *wd = elm_widget_data_get(obj);
107 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
112 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
114 Widget_Data *wd = elm_widget_data_get(obj);
116 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
117 emission, source, func_cb, data);
121 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
123 Widget_Data *wd = elm_widget_data_get(obj);
124 edje_object_signal_callback_del_full(
125 elm_smart_scroller_edje_object_get(wd->scr), emission, source,
130 _sizing_eval(Evas_Object *obj)
132 Widget_Data *wd = elm_widget_data_get(obj);
133 Evas_Coord mw = -1, mh = -1;
134 Evas_Coord vw = 0, vh = 0;
137 evas_object_smart_calculate(wd->bx);
138 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
140 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
143 evas_object_resize(wd->scr, w, h);
145 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
148 evas_object_resize(wd->bx, mw, mh);
150 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
153 evas_object_size_hint_min_set(obj, mw, mh);
154 evas_object_size_hint_max_set(obj, -1, -1);
158 _resize(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
160 Widget_Data *wd = elm_widget_data_get(data);
161 Evas_Coord mw, mh, vw, vh, w, h;
163 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
164 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
165 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
166 if ((vw >= mw) || (vh >= mh))
168 if ((w != vw) || (h != vh)) evas_object_resize(wd->bx, vw, vh);
173 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
175 Widget_Data *wd = data;
177 _els_box_layout(o, priv, EINA_TRUE, EINA_FALSE, EINA_FALSE);
181 _toggle_panel(void *data, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
183 Widget_Data *wd = elm_widget_data_get(data);
187 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
188 "elm,action,show", "elm");
189 wd->hidden = EINA_FALSE;
190 evas_object_repeat_events_set(obj, EINA_FALSE);
194 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
195 "elm,action,hide", "elm");
196 wd->hidden = EINA_TRUE;
197 evas_object_repeat_events_set(obj, EINA_TRUE);
198 if (elm_widget_focus_get(wd->content))
200 elm_widget_focused_object_clear(obj);
201 elm_widget_focus_steal(obj);
207 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
209 if ((src != obj) || (type != EVAS_CALLBACK_KEY_DOWN)) return EINA_FALSE;
211 Evas_Event_Key_Down *ev = event_info;
212 Widget_Data *wd = elm_widget_data_get(obj);
213 if (!wd) return EINA_FALSE;
215 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
217 if ((strcmp(ev->keyname, "Return")) &&
218 (strcmp(ev->keyname, "KP_Enter")) &&
219 (strcmp(ev->keyname, "space")))
222 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");
224 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
229 elm_panel_add(Evas_Object *parent)
235 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
237 ELM_SET_WIDTYPE(widtype, "panel");
238 elm_widget_type_set(obj, "panel");
239 elm_widget_sub_object_add(parent, obj);
240 elm_widget_data_set(obj, wd);
241 elm_widget_del_hook_set(obj, _del_hook);
242 elm_widget_theme_hook_set(obj, _theme_hook);
243 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
244 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
245 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
246 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
247 elm_widget_focus_next_hook_set(obj, _elm_panel_focus_next_hook);
248 elm_widget_can_focus_set(obj, EINA_TRUE);
249 elm_widget_event_hook_set(obj, _event_hook);
251 wd->scr = elm_smart_scroller_add(e);
252 elm_smart_scroller_widget_set(wd->scr, obj);
254 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE, EINA_FALSE);
255 elm_widget_resize_object_set(obj, wd->scr);
256 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
257 ELM_SMART_SCROLLER_POLICY_OFF);
259 wd->hidden = EINA_FALSE;
260 wd->orient = ELM_PANEL_ORIENT_LEFT;
262 wd->bx = evas_object_box_add(e);
263 evas_object_size_hint_align_set(wd->bx, 0.5, 0.5);
264 evas_object_box_layout_set(wd->bx, _layout, wd, NULL);
265 elm_widget_sub_object_add(obj, wd->bx);
266 elm_smart_scroller_child_set(wd->scr, wd->bx);
267 evas_object_show(wd->bx);
269 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
270 "elm,action,panel,toggle", "*",
273 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
275 _mirrored_set(obj, elm_widget_mirrored_get(obj));
281 elm_panel_orient_set(Evas_Object *obj, Elm_Panel_Orient orient)
283 ELM_CHECK_WIDTYPE(obj, widtype);
284 Widget_Data *wd = elm_widget_data_get(obj);
289 case ELM_PANEL_ORIENT_TOP:
290 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "top");
292 case ELM_PANEL_ORIENT_BOTTOM:
293 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "bottom");
295 case ELM_PANEL_ORIENT_LEFT:
296 if (!elm_widget_mirrored_get(obj))
297 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "left");
299 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "right");
301 case ELM_PANEL_ORIENT_RIGHT:
302 if (!elm_widget_mirrored_get(obj))
303 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "right");
305 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "left");
312 EAPI Elm_Panel_Orient
313 elm_panel_orient_get(const Evas_Object *obj)
315 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PANEL_ORIENT_LEFT;
316 Widget_Data *wd = elm_widget_data_get(obj);
317 if (!wd) return ELM_PANEL_ORIENT_LEFT;
322 elm_panel_content_set(Evas_Object *obj, Evas_Object *content)
324 ELM_CHECK_WIDTYPE(obj, widtype);
325 Widget_Data *wd = elm_widget_data_get(obj);
327 if (wd->content == content) return;
329 evas_object_box_remove_all(wd->bx, EINA_TRUE);
330 wd->content = content;
333 evas_object_box_append(wd->bx, wd->content);
334 evas_object_show(wd->content);
340 elm_panel_content_get(const Evas_Object *obj)
342 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
343 Widget_Data *wd = elm_widget_data_get(obj);
344 if (!wd) return NULL;
349 elm_panel_content_unset(Evas_Object *obj)
351 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
352 Widget_Data *wd = elm_widget_data_get(obj);
353 Evas_Object *content;
354 if (!wd) return NULL;
355 if (!wd->content) return NULL;
356 content = wd->content;
357 evas_object_box_remove_all(wd->bx, EINA_FALSE);
363 elm_panel_hidden_set(Evas_Object *obj, Eina_Bool hidden)
365 ELM_CHECK_WIDTYPE(obj, widtype);
366 Widget_Data *wd = elm_widget_data_get(obj);
368 if (wd->hidden == hidden) return;
369 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");
373 elm_panel_hidden_get(const Evas_Object *obj)
375 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
376 Widget_Data *wd = elm_widget_data_get(obj);
377 if (!wd) return EINA_FALSE;
382 elm_panel_toggle(Evas_Object *obj)
384 ELM_CHECK_WIDTYPE(obj, widtype);
385 Widget_Data *wd = elm_widget_data_get(obj);
387 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");