1 #include <Elementary.h>
5 * @defgroup Panel Panel
8 * A panel is a type of animated container that contains subobjects. It
9 * can be expanded or contracted.
11 * Orientations are as follows:
12 * ELM_PANEL_ORIENT_TOP
13 * ELM_PANEL_ORIENT_BOTTOM
14 * ELM_PANEL_ORIENT_LEFT
15 * ELM_PANEL_ORIENT_RIGHT
16 * NOTE: Only LEFT and RIGHT orientations are implemented.
18 * THIS WIDGET IS UNDER CONSTRUCTION!
21 typedef struct _Widget_Data Widget_Data;
24 Evas_Object *scr, *bx, *content;
25 Elm_Panel_Orient orient;
29 static const char *widtype = NULL;
30 static void _del_hook(Evas_Object *obj);
31 static void _theme_hook(Evas_Object *obj);
32 static void _on_focus_hook(void *data, Evas_Object *obj);
33 static void _sizing_eval(Evas_Object *obj);
34 static void _resize(void *data, Evas *evas, Evas_Object *obj, void *event);
35 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
36 static void _toggle_panel(void *data, Evas_Object *obj, const char *emission, const char *source);
39 _del_hook(Evas_Object *obj)
41 Widget_Data *wd = elm_widget_data_get(obj);
47 _theme_hook(Evas_Object *obj)
49 Widget_Data *wd = elm_widget_data_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);
71 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
73 Widget_Data *wd = elm_widget_data_get(obj);
75 if (elm_widget_focus_get(obj))
76 evas_object_focus_set(obj, EINA_TRUE);
78 evas_object_focus_set(obj, EINA_FALSE);
82 _elm_panel_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
84 Widget_Data *wd = elm_widget_data_get(obj);
87 if ((!wd) || (!wd->content))
92 /* Try Focus cycle in subitem */
94 return elm_widget_focus_next_get(cur, dir, next);
97 *next = (Evas_Object *)obj;
98 return !elm_widget_focus_get(obj);
102 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
104 Widget_Data *wd = elm_widget_data_get(obj);
106 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
111 _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)
113 Widget_Data *wd = elm_widget_data_get(obj);
115 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
116 emission, source, func_cb, data);
120 _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)
122 Widget_Data *wd = elm_widget_data_get(obj);
123 edje_object_signal_callback_del_full(
124 elm_smart_scroller_edje_object_get(wd->scr), emission, source,
129 _sizing_eval(Evas_Object *obj)
131 Widget_Data *wd = elm_widget_data_get(obj);
132 Evas_Coord mw = -1, mh = -1;
133 Evas_Coord vw = 0, vh = 0;
136 evas_object_smart_calculate(wd->bx);
137 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
139 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
142 evas_object_resize(wd->scr, w, h);
144 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
147 evas_object_resize(wd->bx, mw, mh);
149 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
152 evas_object_size_hint_min_set(obj, mw, mh);
153 evas_object_size_hint_max_set(obj, -1, -1);
157 _resize(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__)
159 Widget_Data *wd = elm_widget_data_get(data);
160 Evas_Coord mw, mh, vw, vh, w, h;
162 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
163 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
164 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
165 if ((vw >= mw) || (vh >= mh))
167 if ((w != vw) || (h != vh)) evas_object_resize(wd->bx, vw, vh);
172 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
174 Widget_Data *wd = data;
176 _els_box_layout(o, priv, EINA_TRUE, EINA_FALSE);
180 _toggle_panel(void *data, Evas_Object *obj, const char *emission __UNUSED__, const char *source __UNUSED__)
182 Widget_Data *wd = elm_widget_data_get(data);
186 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
187 "elm,action,show", "elm");
188 wd->hidden = EINA_FALSE;
189 evas_object_repeat_events_set(obj, EINA_FALSE);
193 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
194 "elm,action,hide", "elm");
195 wd->hidden = EINA_TRUE;
196 evas_object_repeat_events_set(obj, EINA_TRUE);
197 if (elm_widget_focus_get(wd->content))
199 elm_widget_focused_object_clear(obj);
200 elm_widget_focus_steal(obj);
206 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
208 if ((src != obj) || (type != EVAS_CALLBACK_KEY_DOWN)) return EINA_FALSE;
210 Evas_Event_Key_Down *ev = event_info;
211 Widget_Data *wd = elm_widget_data_get(obj);
212 if (!wd) return EINA_FALSE;
214 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
216 if ((strcmp(ev->keyname, "Return")) &&
217 (strcmp(ev->keyname, "KP_Enter")) &&
218 (strcmp(ev->keyname, "space")))
221 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");
223 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
228 * Adds a panel object
230 * @param parent The parent object
232 * @return The panel object, or NULL on failure
237 elm_panel_add(Evas_Object *parent)
243 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
245 wd = ELM_NEW(Widget_Data);
246 evas = evas_object_evas_get(parent);
247 if (!evas) return NULL;
248 obj = elm_widget_add(evas);
249 ELM_SET_WIDTYPE(widtype, "panel");
250 elm_widget_type_set(obj, "panel");
251 elm_widget_sub_object_add(parent, obj);
252 elm_widget_data_set(obj, wd);
253 elm_widget_del_hook_set(obj, _del_hook);
254 elm_widget_theme_hook_set(obj, _theme_hook);
255 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
256 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
257 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
258 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
259 elm_widget_focus_next_hook_set(obj, _elm_panel_focus_next_hook);
260 elm_widget_can_focus_set(obj, EINA_TRUE);
261 elm_widget_event_hook_set(obj, _event_hook);
263 wd->scr = elm_smart_scroller_add(evas);
264 elm_smart_scroller_widget_set(wd->scr, obj);
266 elm_smart_scroller_bounce_allow_set(wd->scr, EINA_FALSE, EINA_FALSE);
267 elm_widget_resize_object_set(obj, wd->scr);
268 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
269 ELM_SMART_SCROLLER_POLICY_OFF);
271 wd->hidden = EINA_FALSE;
272 wd->orient = ELM_PANEL_ORIENT_LEFT;
274 wd->bx = evas_object_box_add(evas);
275 evas_object_size_hint_align_set(wd->bx, 0.5, 0.5);
276 evas_object_box_layout_set(wd->bx, _layout, wd, NULL);
277 elm_widget_sub_object_add(obj, wd->bx);
278 elm_smart_scroller_child_set(wd->scr, wd->bx);
279 evas_object_show(wd->bx);
281 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scr),
282 "elm,action,panel,toggle", "*",
285 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
292 * Sets the orientation of the panel
294 * @param parent The parent object
295 * @param orient The panel orientation. Can be one of the following:
296 * ELM_PANEL_ORIENT_TOP
297 * ELM_PANEL_ORIENT_BOTTOM
298 * ELM_PANEL_ORIENT_LEFT
299 * ELM_PANEL_ORIENT_RIGHT
301 * NOTE: Only LEFT and RIGHT orientations are implemented.
306 elm_panel_orient_set(Evas_Object *obj, Elm_Panel_Orient orient)
308 ELM_CHECK_WIDTYPE(obj, widtype);
309 Widget_Data *wd = elm_widget_data_get(obj);
314 case ELM_PANEL_ORIENT_TOP:
315 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "top");
317 case ELM_PANEL_ORIENT_BOTTOM:
318 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "bottom");
320 case ELM_PANEL_ORIENT_LEFT:
321 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "left");
323 case ELM_PANEL_ORIENT_RIGHT:
324 elm_smart_scroller_object_theme_set(obj, wd->scr, "panel", "base", "right");
331 * Get the orientation of the panel.
333 * @param obj The panel object
334 * @return The Elm_Panel_Orient, or ELM_PANEL_ORIENT_LEFT on failure.
338 EAPI Elm_Panel_Orient
339 elm_panel_orient_get(const Evas_Object *obj)
341 ELM_CHECK_WIDTYPE(obj, widtype) ELM_PANEL_ORIENT_LEFT;
342 Widget_Data *wd = elm_widget_data_get(obj);
343 if (!wd) return ELM_PANEL_ORIENT_LEFT;
348 * Set the content of the panel.
350 * Once the content object is set, a previously set one will be deleted.
351 * If you want to keep that old content object, use the
352 * elm_panel_content_unset() function.
354 * @param obj The panel object
355 * @param content The panel content
360 elm_panel_content_set(Evas_Object *obj, Evas_Object *content)
362 ELM_CHECK_WIDTYPE(obj, widtype);
363 Widget_Data *wd = elm_widget_data_get(obj);
365 if (wd->content == content) return;
367 evas_object_box_remove_all(wd->bx, EINA_TRUE);
368 wd->content = content;
371 evas_object_box_append(wd->bx, wd->content);
372 evas_object_show(wd->content);
378 * Get the content of the panel.
380 * Return the content object which is set for this widget.
382 * @param obj The panel object
383 * @return The content that is being used
388 elm_panel_content_get(const Evas_Object *obj)
390 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
391 Widget_Data *wd = elm_widget_data_get(obj);
392 if (!wd) return NULL;
397 * Unset the content of the panel.
399 * Unparent and return the content object which was set for this widget.
401 * @param obj The panel object
402 * @return The content that was being used
407 elm_panel_content_unset(Evas_Object *obj)
409 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
410 Widget_Data *wd = elm_widget_data_get(obj);
411 Evas_Object *content;
412 if (!wd) return NULL;
413 if (!wd->content) return NULL;
414 content = wd->content;
415 evas_object_box_remove_all(wd->bx, EINA_FALSE);
421 * Set the state of the panel.
423 * @param obj The panel object
424 * @param hidden If true, the panel will run the edje animation to contract
429 elm_panel_hidden_set(Evas_Object *obj, Eina_Bool hidden)
431 ELM_CHECK_WIDTYPE(obj, widtype);
432 Widget_Data *wd = elm_widget_data_get(obj);
434 if (wd->hidden == hidden) return;
435 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");
439 * Get the state of the panel.
441 * @param obj The panel object
442 * @param hidden If true, the panel is in the "hide" state
447 elm_panel_hidden_get(const Evas_Object *obj)
449 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
450 Widget_Data *wd = elm_widget_data_get(obj);
451 if (!wd) return EINA_FALSE;
456 * Toggle the state of the panel from code
458 * @param obj The panel object
463 elm_panel_toggle(Evas_Object *obj)
465 ELM_CHECK_WIDTYPE(obj, widtype);
466 Widget_Data *wd = elm_widget_data_get(obj);
468 wd->hidden = !(wd->hidden);
469 _toggle_panel(obj, NULL, "elm,action,panel,toggle", "*");