1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
7 Evas_Object *scr, *bx, *content;
8 Elm_Panel_Orient orient;
12 static const char *widtype = NULL;
13 static void _del_hook(Evas_Object *obj);
14 static void _theme_hook(Evas_Object *obj);
15 static void _on_focus_hook(void *data, Evas_Object *obj);
16 static void _sizing_eval(Evas_Object *obj);
17 static void _resize(void *data, Evas *evas, Evas_Object *obj, void *event);
18 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
19 static void _toggle_panel(void *data, Evas_Object *obj, const char *emission, const char *source);
22 _del_hook(Evas_Object *obj)
24 Widget_Data *wd = elm_widget_data_get(obj);
30 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
32 Widget_Data *wd = elm_widget_data_get(obj);
37 elm_widget_mirrored_set(wd->bx, rtl);
38 elm_panel_orient_set(obj, elm_panel_orient_get(obj));
43 _theme_hook(Evas_Object *obj)
45 Widget_Data *wd = elm_widget_data_get(obj);
47 _elm_widget_mirrored_reload(obj);
53 _mirrored_set(obj, elm_widget_mirrored_get(obj));
54 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base",
55 elm_widget_style_get(obj));
56 // scale = (elm_widget_scale_get(obj) * _elm_config->scale);
57 // edje_object_scale_set(wd->scr, scale);
58 edj = elm_smart_scroller_edje_object_get(wd->scr);
59 str = edje_object_data_get(edj, "focus_highlight");
60 if ((str) && (!strcmp(str, "on")))
61 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
63 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
70 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
72 Widget_Data *wd = elm_widget_data_get(obj);
74 if (elm_widget_focus_get(obj))
75 evas_object_focus_set(obj, EINA_TRUE);
77 evas_object_focus_set(obj, EINA_FALSE);
81 _elm_panel_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
83 Widget_Data *wd = elm_widget_data_get(obj);
86 if ((!wd) || (!wd->content))
91 /* Try Focus cycle in subitem */
93 return elm_widget_focus_next_get(cur, dir, next);
96 *next = (Evas_Object *)obj;
97 return !elm_widget_focus_get(obj);
101 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
103 Widget_Data *wd = elm_widget_data_get(obj);
105 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
110 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
112 Widget_Data *wd = elm_widget_data_get(obj);
114 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
115 emission, source, func_cb, data);
119 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
121 Widget_Data *wd = elm_widget_data_get(obj);
122 edje_object_signal_callback_del_full(
123 elm_smart_scroller_edje_object_get(wd->scr), emission, source,
128 _sizing_eval(Evas_Object *obj)
130 Widget_Data *wd = elm_widget_data_get(obj);
131 Evas_Coord mw = -1, mh = -1;
132 Evas_Coord vw = 0, vh = 0;
135 evas_object_smart_calculate(wd->bx);
136 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
138 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
141 evas_object_resize(wd->scr, w, h);
143 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
146 evas_object_resize(wd->bx, mw, mh);
148 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
151 evas_object_size_hint_min_set(obj, mw, mh);
152 evas_object_size_hint_max_set(obj, -1, -1);
156 _resize(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
158 Widget_Data *wd = elm_widget_data_get(data);
159 Evas_Coord mw, mh, vw, vh, w, h;
161 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
162 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
163 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
164 if ((vw >= mw) || (vh >= mh))
166 if ((w != vw) || (h != vh)) evas_object_resize(wd->bx, vw, vh);
171 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
173 Widget_Data *wd = data;
175 _els_box_layout(o, priv, EINA_TRUE, EINA_FALSE, EINA_FALSE);
179 _toggle_panel(void *data, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
181 Widget_Data *wd = elm_widget_data_get(data);
185 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
186 "elm,action,show", "elm");
187 wd->hidden = EINA_FALSE;
188 evas_object_repeat_events_set(obj, EINA_FALSE);
192 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
193 "elm,action,hide", "elm");
194 wd->hidden = EINA_TRUE;
195 evas_object_repeat_events_set(obj, EINA_TRUE);
196 if (elm_widget_focus_get(wd->content))
198 elm_widget_focused_object_clear(obj);
199 elm_widget_focus_steal(obj);
205 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
207 if ((src != obj) || (type != EVAS_CALLBACK_KEY_DOWN)) return EINA_FALSE;
209 Evas_Event_Key_Down *ev = event_info;
210 Widget_Data *wd = elm_widget_data_get(obj);
211 if (!wd) return EINA_FALSE;
213 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
215 if ((strcmp(ev->keyname, "Return")) &&
216 (strcmp(ev->keyname, "KP_Enter")) &&
217 (strcmp(ev->keyname, "space")))
220 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");
222 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
227 elm_panel_add(Evas_Object *parent)
233 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
235 ELM_SET_WIDTYPE(widtype, "panel");
236 elm_widget_type_set(obj, "panel");
237 elm_widget_sub_object_add(parent, obj);
238 elm_widget_data_set(obj, wd);
239 elm_widget_del_hook_set(obj, _del_hook);
240 elm_widget_theme_hook_set(obj, _theme_hook);
241 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
242 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
243 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
244 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
245 elm_widget_focus_next_hook_set(obj, _elm_panel_focus_next_hook);
246 elm_widget_can_focus_set(obj, EINA_TRUE);
247 elm_widget_event_hook_set(obj, _event_hook);
249 wd->scr = elm_smart_scroller_add(e);
250 elm_smart_scroller_widget_set(wd->scr, obj);
252 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE, EINA_FALSE);
253 elm_widget_resize_object_set(obj, wd->scr);
254 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
255 ELM_SMART_SCROLLER_POLICY_OFF);
257 wd->hidden = EINA_FALSE;
258 wd->orient = ELM_PANEL_ORIENT_LEFT;
260 wd->bx = evas_object_box_add(e);
261 evas_object_size_hint_align_set(wd->bx, 0.5, 0.5);
262 evas_object_box_layout_set(wd->bx, _layout, wd, NULL);
263 elm_widget_sub_object_add(obj, wd->bx);
264 elm_smart_scroller_child_set(wd->scr, wd->bx);
265 evas_object_show(wd->bx);
267 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
268 "elm,action,panel,toggle", "*",
271 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
273 _mirrored_set(obj, elm_widget_mirrored_get(obj));
279 elm_panel_orient_set(Evas_Object *obj, Elm_Panel_Orient orient)
281 ELM_CHECK_WIDTYPE(obj, widtype);
282 Widget_Data *wd = elm_widget_data_get(obj);
287 case ELM_PANEL_ORIENT_TOP:
288 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "top");
290 case ELM_PANEL_ORIENT_BOTTOM:
291 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "bottom");
293 case ELM_PANEL_ORIENT_LEFT:
294 if (!elm_widget_mirrored_get(obj))
295 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "left");
297 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "right");
299 case ELM_PANEL_ORIENT_RIGHT:
300 if (!elm_widget_mirrored_get(obj))
301 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "right");
303 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "left");
310 EAPI Elm_Panel_Orient
311 elm_panel_orient_get(const Evas_Object *obj)
313 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PANEL_ORIENT_LEFT;
314 Widget_Data *wd = elm_widget_data_get(obj);
315 if (!wd) return ELM_PANEL_ORIENT_LEFT;
320 elm_panel_content_set(Evas_Object *obj, Evas_Object *content)
322 ELM_CHECK_WIDTYPE(obj, widtype);
323 Widget_Data *wd = elm_widget_data_get(obj);
325 if (wd->content == content) return;
327 evas_object_box_remove_all(wd->bx, EINA_TRUE);
328 wd->content = content;
331 evas_object_box_append(wd->bx, wd->content);
332 evas_object_show(wd->content);
338 elm_panel_content_get(const Evas_Object *obj)
340 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
341 Widget_Data *wd = elm_widget_data_get(obj);
342 if (!wd) return NULL;
347 elm_panel_content_unset(Evas_Object *obj)
349 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
350 Widget_Data *wd = elm_widget_data_get(obj);
351 Evas_Object *content;
352 if (!wd) return NULL;
353 if (!wd->content) return NULL;
354 content = wd->content;
355 evas_object_box_remove_all(wd->bx, EINA_FALSE);
361 elm_panel_hidden_set(Evas_Object *obj, Eina_Bool hidden)
363 ELM_CHECK_WIDTYPE(obj, widtype);
364 Widget_Data *wd = elm_widget_data_get(obj);
366 if (wd->hidden == hidden) return;
367 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");
371 elm_panel_hidden_get(const Evas_Object *obj)
373 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
374 Widget_Data *wd = elm_widget_data_get(obj);
375 if (!wd) return EINA_FALSE;
380 elm_panel_toggle(Evas_Object *obj)
382 ELM_CHECK_WIDTYPE(obj, widtype);
383 Widget_Data *wd = elm_widget_data_get(obj);
385 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");