1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Elm_Ctxpopup_Item Elm_Ctxpopup_Item;
7 struct _Elm_Ctxpopup_Item
18 Evas_Object *hover_parent;
26 Elm_Ctxpopup_Direction dir;
27 Elm_Ctxpopup_Direction dir_priority[4];
28 Evas_Coord max_sc_w, max_sc_h;
29 Eina_Bool horizontal:1;
34 static const char *widtype = NULL;
36 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
37 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
38 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
39 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
40 static void _scroller_size_reset(Widget_Data *wd);
41 static void _on_focus_hook(void *data, Evas_Object *obj);
42 static Eina_Bool _event_hook(Evas_Object *obj,
44 Evas_Callback_Type type,
46 static void _hover_parent_cut_off(Evas_Object *obj);
47 static void _hover_parent_resize(void *data, Evas *e,
50 static void _hover_parent_move(void *data, Evas *e,
53 static void _hover_parent_del(void *data, Evas *e,
56 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
57 static void _adjust_pos_x(Evas_Coord_Point *pos,
58 Evas_Coord_Point *base_size,
59 Evas_Coord_Rectangle *hover_area);
60 static void _adjust_pos_y(Evas_Coord_Point *pos,
61 Evas_Coord_Point *base_size,
62 Evas_Coord_Rectangle *hover_area);
63 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
64 Evas_Coord_Rectangle *rect);
65 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
66 static void _sizing_eval(Evas_Object *obj);
67 static void _shift_base_by_arrow(Evas_Object *arrow,
68 Elm_Ctxpopup_Direction dir,
69 Evas_Coord_Rectangle *rect);
70 static void _del_pre_hook(Evas_Object *obj);
71 static void _del_hook(Evas_Object *obj);
72 static void _theme_hook(Evas_Object *obj);
73 static void _content_set_hook(Evas_Object *obj,
75 Evas_Object *content);
76 static Evas_Object * _content_unset_hook(Evas_Object *obj,
78 static Evas_Object * _content_get_hook(const Evas_Object *obj,
80 static void _bg_clicked_cb(void *data, Evas_Object *obj,
83 static void _ctxpopup_show(void *data,
87 static void _hide(Evas_Object *obj);
88 static void _ctxpopup_hide(void *data,
92 static void _scroller_resize(void *data,
96 static void _ctxpopup_move(void *data,
100 static void _item_select_cb(void *data, Evas_Object *obj,
101 const char *emission,
103 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
104 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
105 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
106 static void _content_del(void *data,
110 static void _list_del(Widget_Data *wd);
111 static void _list_new(Evas_Object *obj);
112 static void _remove_items(Widget_Data * wd);
114 static const char SIG_DISMISSED[] = "dismissed";
116 static const Evas_Smart_Cb_Description _signals[] = {
122 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
123 void *event_info __UNUSED__)
125 Widget_Data *wd = elm_widget_data_get(obj);
127 if ((!wd) || (!wd->scr)) return;
128 elm_object_scroll_freeze_push(wd->scr);
132 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
133 void *event_info __UNUSED__)
135 Widget_Data *wd = elm_widget_data_get(obj);
137 if ((!wd) || (!wd->scr)) return;
138 elm_object_scroll_freeze_pop(wd->scr);
142 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
144 Widget_Data *wd = elm_widget_data_get(obj);
146 if ((!wd) || (!wd->scr)) return;
147 elm_object_scroll_hold_push(wd->scr);
151 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
153 Widget_Data *wd = elm_widget_data_get(obj);
155 if ((!wd) || (!wd->scr)) return;
156 elm_object_scroll_hold_pop(wd->scr);
160 _scroller_size_reset(Widget_Data *wd)
162 wd->finished = EINA_FALSE;
168 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
170 Widget_Data *wd = elm_widget_data_get(obj);
173 if (elm_widget_focus_get(obj))
184 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
186 Evas_Event_Key_Down *ev;
189 if (type != EVAS_CALLBACK_KEY_DOWN)
191 wd = elm_widget_data_get(obj);
192 if (!wd) return EINA_FALSE;
195 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
196 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
198 evas_object_hide(obj);
199 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
204 _hover_parent_cut_off(Evas_Object *obj)
206 Widget_Data *wd = elm_widget_data_get(obj);
208 if ((!wd) || (!wd->hover_parent)) return;
210 evas_object_event_callback_del_full(wd->hover_parent,
214 evas_object_event_callback_del_full(wd->hover_parent,
218 evas_object_event_callback_del_full(wd->hover_parent,
219 EVAS_CALLBACK_RESIZE,
220 _hover_parent_resize,
223 elm_widget_sub_object_del(wd->hover_parent, obj);
227 _hover_parent_resize(void *data, Evas *e __UNUSED__,
228 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
230 Widget_Data *wd = elm_widget_data_get(data);
233 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
239 _hover_parent_move(void *data, Evas *e __UNUSED__,
240 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
242 Widget_Data *wd = elm_widget_data_get(data);
246 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
250 _scroller_size_reset(wd);
256 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
257 void *event_info __UNUSED__)
259 evas_object_del(data);
263 _item_sizing_eval(Elm_Ctxpopup_Item *item)
265 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
269 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
271 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
272 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
276 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
277 Evas_Coord_Rectangle *hover_area)
279 pos->x -= (base_size->x / 2);
281 if (pos->x < hover_area->x)
282 pos->x = hover_area->x;
283 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
284 pos->x = (hover_area->x + hover_area->w) - base_size->x;
286 if (base_size->x > hover_area->w)
287 base_size->x -= (base_size->x - hover_area->w);
289 if (pos->x < hover_area->x)
290 pos->x = hover_area->x;
294 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
295 Evas_Coord_Rectangle *hover_area)
297 pos->y -= (base_size->y / 2);
299 if (pos->y < hover_area->y)
300 pos->y = hover_area->y;
301 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
302 pos->y = hover_area->y + hover_area->h - base_size->y;
304 if (base_size->y > hover_area->h)
305 base_size->y -= (base_size->y - hover_area->h);
307 if (pos->y < hover_area->y)
308 pos->y = hover_area->y;
311 static Elm_Ctxpopup_Direction
312 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
315 Evas_Coord_Point pos = {0, 0};
316 Evas_Coord_Point base_size;
317 Evas_Coord_Point max_size;
318 Evas_Coord_Point min_size;
319 Evas_Coord_Rectangle hover_area;
320 Evas_Coord_Point arrow_size;
321 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
322 Evas_Coord_Point temp;
325 wd = elm_widget_data_get(obj);
327 if ((!wd) || (!rect))
328 return ELM_CTXPOPUP_DIRECTION_DOWN;
330 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
331 &arrow_size.x, &arrow_size.y);
332 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
334 //Initialize Area Rectangle.
335 if (wd->hover_parent)
336 evas_object_geometry_get(wd->hover_parent,
342 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
345 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
346 evas_object_smart_calculate(wd->base);
349 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
351 if ((max_size.y > 0) && (base_size.y > max_size.y))
352 base_size.y = max_size.y;
354 if ((max_size.x > 0) && (base_size.x > max_size.x))
355 base_size.x = max_size.x;
358 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
360 if ((min_size.y > 0) && (base_size.y < min_size.y))
361 base_size.y = min_size.y;
363 if ((min_size.x > 0) && (base_size.x < min_size.x))
364 base_size.x = min_size.x;
366 //Check the Which direction is available.
367 //If find a avaialble direction, it adjusts position and size.
368 for (idx = 0; idx < 4; idx++)
370 switch (wd->dir_priority[idx])
372 case ELM_CTXPOPUP_DIRECTION_DONT_KNOW:
373 case ELM_CTXPOPUP_DIRECTION_UP:
374 temp.y = (pos.y - base_size.y);
375 if ((temp.y - arrow_size.y) < hover_area.y)
377 _adjust_pos_x(&pos, &base_size, &hover_area);
378 pos.y -= base_size.y;
379 dir = ELM_CTXPOPUP_DIRECTION_UP;
381 case ELM_CTXPOPUP_DIRECTION_LEFT:
382 temp.x = (pos.x - base_size.x);
383 if ((temp.x - arrow_size.x) < hover_area.x)
385 _adjust_pos_y(&pos, &base_size, &hover_area);
386 pos.x -= base_size.x;
387 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
389 case ELM_CTXPOPUP_DIRECTION_RIGHT:
390 temp.x = (pos.x + base_size.x);
391 if ((temp.x + arrow_size.x) >
392 (hover_area.x + hover_area.w))
394 _adjust_pos_y(&pos, &base_size, &hover_area);
395 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
397 case ELM_CTXPOPUP_DIRECTION_DOWN:
398 temp.y = (pos.y + base_size.y);
399 if ((temp.y + arrow_size.y) >
400 (hover_area.y + hover_area.h))
402 _adjust_pos_x(&pos, &base_size, &hover_area);
403 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
411 //In this case, all directions are invalid because of lack of space.
414 Evas_Coord length[2];
418 length[0] = pos.y - hover_area.y;
419 length[1] = (hover_area.y + hover_area.h) - pos.y;
421 // ELM_CTXPOPUP_DIRECTION_UP
422 if (length[0] > length[1])
424 _adjust_pos_x(&pos, &base_size, &hover_area);
425 pos.y -= base_size.y;
426 dir = ELM_CTXPOPUP_DIRECTION_UP;
427 if (pos.y < (hover_area.y + arrow_size.y))
429 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
430 pos.y = hover_area.y + arrow_size.y;
433 //ELM_CTXPOPUP_DIRECTION_DOWN
436 _adjust_pos_x(&pos, &base_size, &hover_area);
437 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
438 if ((pos.y + arrow_size.y + base_size.y) >
439 (hover_area.y + hover_area.h))
441 ((pos.y + arrow_size.y + base_size.y) -
442 (hover_area.y + hover_area.h));
447 length[0] = pos.x - hover_area.x;
448 length[1] = (hover_area.x + hover_area.w) - pos.x;
450 //ELM_CTXPOPUP_DIRECTION_LEFT
451 if (length[0] > length[1])
453 _adjust_pos_y(&pos, &base_size, &hover_area);
454 pos.x -= base_size.x;
455 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
456 if (pos.x < (hover_area.x + arrow_size.x))
458 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
459 pos.x = hover_area.x + arrow_size.x;
462 //ELM_CTXPOPUP_DIRECTION_RIGHT
465 _adjust_pos_y(&pos, &base_size, &hover_area);
466 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
467 if (pos.x + (arrow_size.x + base_size.x) >
468 hover_area.x + hover_area.w)
470 ((pos.x + arrow_size.x + base_size.x) -
471 (hover_area.x + hover_area.w));
476 //Final position and size.
479 rect->w = base_size.x;
480 rect->h = base_size.y;
486 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
489 Evas_Coord_Rectangle arrow_size;
490 Evas_Coord_Rectangle base_size;
493 wd = elm_widget_data_get(obj);
496 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
497 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
499 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
500 &base_size.w, &base_size.h);
504 case ELM_CTXPOPUP_DIRECTION_RIGHT:
505 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
506 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
509 if (y < ((arrow_size.h * 0.5) + base_size.y))
511 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
512 y = base_size.h - arrow_size.h;
514 y = y - base_size.y - (arrow_size.h * 0.5);
515 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
516 (double) (y) / (double) (base_size.h - arrow_size.h));
519 case ELM_CTXPOPUP_DIRECTION_LEFT:
520 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
521 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
524 if (y < (arrow_size.h * 0.5) + base_size.y)
526 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
527 y = base_size.h - arrow_size.h;
528 else y = y - base_size.y - (arrow_size.h * 0.5);
529 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
530 (double) (y) / (double) (base_size.h - arrow_size.h));
533 case ELM_CTXPOPUP_DIRECTION_DOWN:
534 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
535 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
538 if (x < (arrow_size.w * 0.5) + base_size.x)
540 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
541 x = base_size.w - arrow_size.w;
543 x = x - base_size.x - (arrow_size.w * 0.5);
544 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
545 (double) (x) / (double) (base_size.w - arrow_size.w), 1);
548 case ELM_CTXPOPUP_DIRECTION_UP:
549 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
550 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
553 if (x < (arrow_size.w * 0.5) + base_size.x)
555 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
556 x = base_size.w - arrow_size.w;
557 else x = x - base_size.x - (arrow_size.w * 0.5);
558 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
559 (double) (x) / (double) (base_size.w - arrow_size.w), 0);
568 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
572 wd = elm_widget_data_get(obj);
573 if (!wd || wd->visible) return;
577 case ELM_CTXPOPUP_DIRECTION_UP:
578 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
580 case ELM_CTXPOPUP_DIRECTION_LEFT:
581 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
583 case ELM_CTXPOPUP_DIRECTION_RIGHT:
584 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
586 case ELM_CTXPOPUP_DIRECTION_DOWN:
587 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
595 _sizing_eval(Evas_Object *obj)
599 Elm_Ctxpopup_Item *item;
600 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
601 Evas_Coord_Point box_size = { 0, 0 };
602 Evas_Coord_Point _box_size = { 0, 0 };
604 wd = elm_widget_data_get(obj);
605 if ((!wd) || (!wd->hover_parent)) return;
608 EINA_LIST_FOREACH(wd->items, elist, item)
610 _item_sizing_eval(item);
611 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
614 if (_box_size.x > box_size.x)
615 box_size.x = _box_size.x;
616 if (_box_size.y != -1)
617 box_size.y += _box_size.y;
621 if (_box_size.x != -1)
622 box_size.x += _box_size.x;
623 if (_box_size.y > box_size.y)
624 box_size.y = _box_size.y;
630 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
631 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
635 wd->dir = _calc_base_geometry(obj, &rect);
636 _show_signal_emit(obj, wd->dir);
637 _update_arrow(obj, wd->dir);
638 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
640 //resize scroller according to final size.
642 evas_object_smart_calculate(wd->scr);
644 evas_object_move(wd->base, rect.x, rect.y);
645 evas_object_resize(wd->base, rect.w, rect.h);
649 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
650 Evas_Coord_Rectangle *rect)
652 Evas_Coord arrow_w, arrow_h;
654 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
658 case ELM_CTXPOPUP_DIRECTION_RIGHT:
661 case ELM_CTXPOPUP_DIRECTION_LEFT:
664 case ELM_CTXPOPUP_DIRECTION_DOWN:
667 case ELM_CTXPOPUP_DIRECTION_UP:
676 _del_pre_hook(Evas_Object *obj)
680 wd = elm_widget_data_get(obj);
683 _hover_parent_cut_off(obj);
687 _del_hook(Evas_Object *obj)
691 wd = elm_widget_data_get(obj);
694 elm_ctxpopup_clear(obj);
695 evas_object_del(wd->arrow);
696 evas_object_del(wd->base);
701 _theme_hook(Evas_Object *obj)
705 Elm_Ctxpopup_Item *item;
707 wd = elm_widget_data_get(obj);
711 EINA_LIST_FOREACH(wd->items, elist, item)
713 if (item->label && item->icon)
714 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
715 "icon_text_style_item",
716 elm_widget_style_get(obj));
717 else if (item->label)
718 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
719 elm_widget_style_get(obj));
721 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
722 elm_widget_style_get(obj));
724 edje_object_part_text_set(item->base.view, "elm.text", item->label);
727 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
729 edje_object_message_signal_process(item->base.view);
732 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
733 elm_widget_style_get(obj));
734 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
735 elm_widget_style_get(obj));
736 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
737 elm_widget_style_get(obj));
741 if (!strncmp(elm_object_style_get(obj), "default",
743 elm_object_style_set(wd->scr, "ctxpopup");
745 elm_object_style_set(wd->scr, elm_object_style_get(obj));
748 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
752 _scroller_size_reset(wd);
758 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__,
759 Evas_Object *content)
761 ELM_CHECK_WIDTYPE(obj, widtype);
765 wd = elm_widget_data_get(obj);
766 if ((!wd) || (!content)) return;
768 if (wd->items) elm_ctxpopup_clear(obj);
769 if (wd->content) evas_object_del(wd->content);
771 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
774 elm_widget_sub_object_add(obj, content);
775 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
777 wd->content = content;
779 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
786 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
788 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
791 Evas_Object *content;
793 wd = elm_widget_data_get(obj);
794 if (!wd) return NULL;
796 content = wd->content;
797 if (!content) return NULL;
799 edje_object_part_unswallow(wd->base, content);
800 elm_widget_sub_object_del(obj, content);
801 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
802 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
805 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
812 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
814 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
816 Widget_Data *wd = elm_widget_data_get(obj);
817 if (!wd) return NULL;
822 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
823 const char *emission __UNUSED__, const char *source __UNUSED__)
825 evas_object_hide(data);
829 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
830 void *event_info __UNUSED__)
834 wd = elm_widget_data_get(obj);
837 if ((!wd->items) && (!wd->content)) return;
839 wd->visible = EINA_TRUE;
841 evas_object_show(wd->bg);
842 evas_object_show(wd->base);
843 evas_object_show(wd->arrow);
845 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
846 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
850 elm_object_focus_set(obj, EINA_TRUE);
854 _hide(Evas_Object *obj)
856 Widget_Data *wd = elm_widget_data_get(obj);
858 if ((!wd) || (!wd->visible)) return;
860 evas_object_hide(wd->bg);
861 evas_object_hide(wd->arrow);
862 evas_object_hide(wd->base);
864 _scroller_size_reset(wd);
866 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
867 wd->visible = EINA_FALSE;
871 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
872 void *event_info __UNUSED__)
878 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
879 void *event_info __UNUSED__)
884 wd = elm_widget_data_get(data);
886 if (!wd->visible) return;
887 if (wd->finished) return;
889 evas_object_geometry_get(obj, 0, 0, &w, &h);
891 if (w != 0 && h != 0)
893 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
896 wd->finished = EINA_TRUE;
901 if (wd->max_sc_w < w)
903 if (wd->max_sc_h < h)
910 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
911 void *event_info __UNUSED__)
915 wd = elm_widget_data_get(obj);
920 evas_object_show(wd->arrow);
922 _scroller_size_reset(wd);
927 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
928 const char *emission __UNUSED__, const char *source __UNUSED__)
930 Elm_Ctxpopup_Item *item = data;
933 if (item->disabled) return;
936 item->func((void*) item->base.data, item->base.widget, data);
940 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
943 evas_object_del(item->icon);
948 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
949 edje_object_message_signal_process(item->base.view);
953 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
955 if (!eina_stringshare_replace(&item->label, label))
958 edje_object_part_text_set(item->base.view, "elm.text", label);
959 edje_object_message_signal_process(item->base.view);
963 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
967 wd = elm_widget_data_get(item->base.widget);
970 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
971 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
972 elm_widget_style_get(item->base.widget));
973 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
974 _item_select_cb, item);
975 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
976 evas_object_show(item->base.view);
980 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
981 void *event_info __UNUSED__)
983 elm_object_content_unset(data);
987 _list_del(Widget_Data *wd)
989 if (!wd->scr) return;
991 edje_object_part_unswallow(wd->base, wd->scr);
992 evas_object_del(wd->scr);
998 _list_new(Evas_Object *obj)
1001 wd = elm_widget_data_get(obj);
1005 wd->scr = elm_scroller_add(obj);
1006 elm_object_style_set(wd->scr, "ctxpopup");
1007 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1008 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1009 _scroller_resize, obj);
1010 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1013 wd->box = elm_box_add(obj);
1014 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1017 elm_scroller_content_set(wd->scr, wd->box);
1018 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1022 _remove_items(Widget_Data *wd)
1025 Elm_Ctxpopup_Item *item;
1027 if (!wd->items) return;
1029 EINA_LIST_FOREACH(wd->items, elist, item)
1032 eina_stringshare_del(item->label);
1034 evas_object_del(item->icon);
1035 wd->items = eina_list_remove(wd->items, item);
1043 elm_ctxpopup_add(Evas_Object *parent)
1049 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1051 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1052 elm_widget_type_set(obj, "ctxpopup");
1053 elm_widget_data_set(obj, wd);
1054 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1055 elm_widget_del_hook_set(obj, _del_hook);
1056 elm_widget_theme_hook_set(obj, _theme_hook);
1057 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1058 elm_widget_can_focus_set(obj, EINA_TRUE);
1059 elm_widget_event_hook_set(obj, _event_hook);
1060 elm_widget_content_set_hook_set(obj, _content_set_hook);
1061 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1062 elm_widget_content_get_hook_set(obj, _content_get_hook);
1065 wd->bg = edje_object_add(e);
1066 elm_widget_sub_object_add(obj, wd->bg);
1067 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1068 edje_object_signal_callback_add(wd->bg,
1074 wd->base = edje_object_add(e);
1075 elm_widget_sub_object_add(obj, wd->base);
1076 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1079 wd->arrow = edje_object_add(e);
1080 elm_widget_sub_object_add(obj, wd->arrow);
1081 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1083 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1084 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1085 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1086 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1087 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1089 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1091 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1093 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1095 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1096 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1097 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1098 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1100 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1102 //default parent is to be hover parent
1103 elm_ctxpopup_hover_parent_set(obj, parent);
1109 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1111 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1112 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1113 return ctxpopup_it->icon;
1117 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1119 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1122 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1124 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1127 _item_icon_set(ctxpopup_it, icon);
1128 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1132 _scroller_size_reset(wd);
1133 _sizing_eval(ctxpopup_it->base.widget);
1138 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1140 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1141 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1142 return ctxpopup_it->label;
1146 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1148 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1151 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1153 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1156 _item_label_set(ctxpopup_it, label);
1157 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1161 _scroller_size_reset(wd);
1162 _sizing_eval(ctxpopup_it->base.widget);
1167 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1169 ELM_CHECK_WIDTYPE(obj, widtype);
1172 Evas_Coord x, y, w, h;
1174 wd = elm_widget_data_get(obj);
1175 if ((!wd) || (!hover_parent)) return;
1177 _hover_parent_cut_off(obj);
1181 evas_object_event_callback_add(hover_parent,
1185 evas_object_event_callback_add(hover_parent,
1189 evas_object_event_callback_add(hover_parent,
1190 EVAS_CALLBACK_RESIZE,
1191 _hover_parent_resize,
1195 elm_widget_sub_object_add(hover_parent, obj);
1196 wd->hover_parent = hover_parent;
1199 evas_object_geometry_get(hover_parent, &x, &y, &w, &h);
1200 evas_object_move(wd->bg, x, y);
1201 evas_object_resize(wd->bg, w, h);
1203 if (wd->visible) _sizing_eval(obj);
1207 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1209 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1213 wd = elm_widget_data_get(obj);
1214 if (!wd) return NULL;
1216 return wd->hover_parent;
1220 elm_ctxpopup_clear(Evas_Object * obj)
1222 ELM_CHECK_WIDTYPE(obj, widtype);
1224 Widget_Data *wd = elm_widget_data_get(obj);
1229 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1233 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1235 ELM_CHECK_WIDTYPE(obj, widtype);
1239 wd = elm_widget_data_get(obj);
1242 wd->horizontal = !!horizontal;
1244 if ((!wd->scr) && (!wd->box))
1249 elm_box_horizontal_set(wd->box, EINA_FALSE);
1250 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1254 elm_box_horizontal_set(wd->box, EINA_TRUE);
1255 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1258 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1265 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1267 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1271 wd = elm_widget_data_get(obj);
1272 if (!wd) return EINA_FALSE;
1274 return wd->horizontal;
1277 EAPI Elm_Object_Item *
1278 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1279 Evas_Object *icon, Evas_Smart_Cb func,
1282 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1285 Elm_Ctxpopup_Item *item;
1287 wd = elm_widget_data_get(obj);
1288 if (!wd) return NULL;
1290 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1291 if (!item) return NULL;
1293 //The first item is appended.
1295 evas_object_del(elm_object_content_unset(obj));
1301 item->base.data = data;
1304 _item_new(item, "icon_text_style_item");
1306 _item_new(item, "text_style_item");
1308 _item_new(item, "icon_style_item");
1310 _item_icon_set(item, icon);
1311 _item_label_set(item, label);
1312 elm_box_pack_end(wd->box, item->base.view);
1313 wd->items = eina_list_append(wd->items, item);
1314 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1318 _scroller_size_reset(wd);
1322 return ELM_CAST(item);
1326 elm_ctxpopup_item_del(Elm_Object_Item *it)
1328 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1331 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1333 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1336 if (ctxpopup_it->icon)
1337 evas_object_del(ctxpopup_it->icon);
1338 if (ctxpopup_it->base.view)
1339 evas_object_del(ctxpopup_it->base.view);
1341 eina_stringshare_del(ctxpopup_it->label);
1343 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1345 if (eina_list_count(wd->items) < 1)
1348 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1351 _sizing_eval(ctxpopup_it->base.widget);
1357 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1359 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1362 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1364 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1367 ctxpopup_it = ELM_CAST(it);
1369 if (disabled == ctxpopup_it->disabled)
1373 edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,disabled", "elm");
1375 edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,enabled", "elm");
1377 ctxpopup_it->disabled = !!disabled;
1381 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1383 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1384 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1385 return ctxpopup_it->disabled;
1389 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1391 elm_object_content_set(obj, content);
1395 elm_ctxpopup_content_unset(Evas_Object *obj)
1397 return elm_object_content_unset(obj);
1401 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1402 Elm_Ctxpopup_Direction first,
1403 Elm_Ctxpopup_Direction second,
1404 Elm_Ctxpopup_Direction third,
1405 Elm_Ctxpopup_Direction fourth)
1407 ELM_CHECK_WIDTYPE(obj, widtype);
1410 wd = elm_widget_data_get(obj);
1413 wd->dir_priority[0] = first;
1414 wd->dir_priority[1] = second;
1415 wd->dir_priority[2] = third;
1416 wd->dir_priority[3] = fourth;
1423 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1424 Elm_Ctxpopup_Direction *first,
1425 Elm_Ctxpopup_Direction *second,
1426 Elm_Ctxpopup_Direction *third,
1427 Elm_Ctxpopup_Direction *fourth)
1429 ELM_CHECK_WIDTYPE(obj, widtype);
1432 wd = elm_widget_data_get(obj);
1435 if (first) *first = wd->dir_priority[0];
1436 if (second) *second = wd->dir_priority[1];
1437 if (third) *third = wd->dir_priority[2];
1438 if (fourth) *fourth = wd->dir_priority[3];
1441 EAPI Elm_Ctxpopup_Direction
1442 elm_ctxpopup_direction_get(const Evas_Object *obj)
1444 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1447 wd = elm_widget_data_get(obj);
1448 if (!wd) return ELM_CTXPOPUP_DIRECTION_DONT_KNOW;