1 #include <Elementary.h>
5 * @defgroup Panel Panel
7 * A panel is a type of animated container that contains subobjects. It
8 * can be expanded or contracted.
10 * Orientations are as follows:
11 * ELM_PANEL_ORIENT_TOP
12 * ELM_PANEL_ORIENT_BOTTOM
13 * ELM_PANEL_ORIENT_LEFT
14 * ELM_PANEL_ORIENT_RIGHT
15 * NOTE: Only LEFT and RIGHT orientations are implemented.
17 * THIS WIDGET IS UNDER CONSTRUCTION!
20 typedef struct _Widget_Data Widget_Data;
23 Evas_Object *scr, *bx, *content;
24 Elm_Panel_Orient orient;
28 static const char *widtype = NULL;
29 static void _del_hook(Evas_Object *obj);
30 static void _theme_hook(Evas_Object *obj);
31 static void _on_focus_hook(void *data, Evas_Object *obj);
32 static void _sizing_eval(Evas_Object *obj);
33 static void _resize(void *data, Evas *evas, Evas_Object *obj, void *event);
34 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
35 static void _toggle_panel(void *data, Evas_Object *obj, const char *emission, const char *source);
38 _del_hook(Evas_Object *obj)
40 Widget_Data *wd = elm_widget_data_get(obj);
46 _theme_hook(Evas_Object *obj)
48 Widget_Data *wd = elm_widget_data_get(obj);
55 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base",
56 elm_widget_style_get(obj));
57 // scale = (elm_widget_scale_get(obj) * _elm_config->scale);
58 // edje_object_scale_set(wd->scr, scale);
59 edj = elm_smart_scroller_edje_object_get(wd->scr);
60 str = edje_object_data_get(edj, "focus_highlight");
61 if ((str) && (!strcmp(str, "on")))
62 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
64 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, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), 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, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), 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);
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 * Adds a panel object
229 * @param parent The parent object
231 * @return The panel object, or NULL on failure
236 elm_panel_add(Evas_Object *parent)
242 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
244 wd = ELM_NEW(Widget_Data);
245 evas = evas_object_evas_get(parent);
246 if (!evas) return NULL;
247 obj = elm_widget_add(evas);
248 ELM_SET_WIDTYPE(widtype, "panel");
249 elm_widget_type_set(obj, "panel");
250 elm_widget_sub_object_add(parent, obj);
251 elm_widget_data_set(obj, wd);
252 elm_widget_del_hook_set(obj, _del_hook);
253 elm_widget_theme_hook_set(obj, _theme_hook);
254 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
255 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
256 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
257 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
258 elm_widget_focus_next_hook_set(obj, _elm_panel_focus_next_hook);
259 elm_widget_can_focus_set(obj, EINA_TRUE);
260 elm_widget_event_hook_set(obj, _event_hook);
262 wd->scr = elm_smart_scroller_add(evas);
263 elm_smart_scroller_widget_set(wd->scr, obj);
265 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE, EINA_FALSE);
266 elm_widget_resize_object_set(obj, wd->scr);
267 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
268 ELM_SMART_SCROLLER_POLICY_OFF);
270 wd->hidden = EINA_FALSE;
271 wd->orient = ELM_PANEL_ORIENT_LEFT;
273 wd->bx = evas_object_box_add(evas);
274 evas_object_size_hint_align_set(wd->bx, 0.5, 0.5);
275 evas_object_box_layout_set(wd->bx, _layout, wd, NULL);
276 elm_widget_sub_object_add(obj, wd->bx);
277 elm_smart_scroller_child_set(wd->scr, wd->bx);
278 evas_object_show(wd->bx);
280 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
281 "elm,action,panel,toggle", "*",
284 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
291 * Sets the orientation of the panel
293 * @param parent The parent object
294 * @param orient The panel orientation. Can be one of the following:
295 * ELM_PANEL_ORIENT_TOP
296 * ELM_PANEL_ORIENT_BOTTOM
297 * ELM_PANEL_ORIENT_LEFT
298 * ELM_PANEL_ORIENT_RIGHT
300 * NOTE: Only LEFT and RIGHT orientations are implemented.
305 elm_panel_orient_set(Evas_Object *obj, Elm_Panel_Orient orient)
307 ELM_CHECK_WIDTYPE(obj, widtype);
308 Widget_Data *wd = elm_widget_data_get(obj);
313 case ELM_PANEL_ORIENT_TOP:
314 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "top");
316 case ELM_PANEL_ORIENT_BOTTOM:
317 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "bottom");
319 case ELM_PANEL_ORIENT_LEFT:
320 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "left");
322 case ELM_PANEL_ORIENT_RIGHT:
323 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "right");
330 * Get the orientation of the panel.
332 * @param obj The panel object
333 * @return The Elm_Panel_Orient, or ELM_PANEL_ORIENT_LEFT on failure.
337 EAPI Elm_Panel_Orient
338 elm_panel_orient_get(const Evas_Object *obj)
340 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PANEL_ORIENT_LEFT;
341 Widget_Data *wd = elm_widget_data_get(obj);
342 if (!wd) return ELM_PANEL_ORIENT_LEFT;
347 * Set the content of the panel.
349 * Once the content object is set, a previously set one will be deleted.
350 * If you want to keep that old content object, use the
351 * elm_panel_content_unset() function.
353 * @param obj The panel object
354 * @param content The panel content
359 elm_panel_content_set(Evas_Object *obj, Evas_Object *content)
361 ELM_CHECK_WIDTYPE(obj, widtype);
362 Widget_Data *wd = elm_widget_data_get(obj);
364 if (wd->content == content) return;
366 evas_object_box_remove_all(wd->bx, EINA_TRUE);
367 wd->content = content;
370 evas_object_box_append(wd->bx, wd->content);
371 evas_object_show(wd->content);
377 * Get the content of the panel.
379 * Return the content object which is set for this widget.
381 * @param obj The panel object
382 * @return The content that is being used
387 elm_panel_content_get(const Evas_Object *obj)
389 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
390 Widget_Data *wd = elm_widget_data_get(obj);
391 if (!wd) return NULL;
396 * Unset the content of the panel.
398 * Unparent and return the content object which was set for this widget.
400 * @param obj The panel object
401 * @return The content that was being used
406 elm_panel_content_unset(Evas_Object *obj)
408 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
409 Widget_Data *wd = elm_widget_data_get(obj);
410 Evas_Object *content;
411 if (!wd) return NULL;
412 if (!wd->content) return NULL;
413 content = wd->content;
414 evas_object_box_remove_all(wd->bx, EINA_FALSE);
420 * Set the state of the panel.
422 * @param obj The panel object
423 * @param hidden If true, the panel will run the edje animation to contract
428 elm_panel_hidden_set(Evas_Object *obj, Eina_Bool hidden)
430 ELM_CHECK_WIDTYPE(obj, widtype);
431 Widget_Data *wd = elm_widget_data_get(obj);
433 if (wd->hidden == hidden) return;
434 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");
438 * Get the state of the panel.
440 * @param obj The panel object
441 * @param hidden If true, the panel is in the "hide" state
446 elm_panel_hidden_get(const Evas_Object *obj)
448 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
449 Widget_Data *wd = elm_widget_data_get(obj);
450 if (!wd) return EINA_FALSE;
455 * Toggle the state of the panel from code
457 * @param obj The panel object
462 elm_panel_toggle(Evas_Object *obj)
464 ELM_CHECK_WIDTYPE(obj, widtype);
465 Widget_Data *wd = elm_widget_data_get(obj);
467 wd->hidden = !(wd->hidden);
468 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");