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
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 _parent_cut_off(Evas_Object *obj);
47 static void _parent_resize(void *data,
51 static void _parent_move(void *data,
55 static void _parent_del(void *data,
59 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
60 static void _adjust_pos_x(Evas_Coord_Point *pos,
61 Evas_Coord_Point *base_size,
62 Evas_Coord_Rectangle *hover_area);
63 static void _adjust_pos_y(Evas_Coord_Point *pos,
64 Evas_Coord_Point *base_size,
65 Evas_Coord_Rectangle *hover_area);
66 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
67 Evas_Coord_Rectangle *rect);
68 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
69 static void _sizing_eval(Evas_Object *obj);
70 static void _shift_base_by_arrow(Evas_Object *arrow,
71 Elm_Ctxpopup_Direction dir,
72 Evas_Coord_Rectangle *rect);
73 static void _del_pre_hook(Evas_Object *obj);
74 static void _del_hook(Evas_Object *obj);
75 static void _theme_hook(Evas_Object *obj);
76 static void _content_set_hook(Evas_Object *obj,
78 Evas_Object *content);
79 static Evas_Object * _content_unset_hook(Evas_Object *obj,
81 static Evas_Object * _content_get_hook(const Evas_Object *obj,
83 static void _bg_clicked_cb(void *data, Evas_Object *obj,
86 static void _ctxpopup_show(void *data,
90 static void _hide(Evas_Object *obj);
91 static void _ctxpopup_hide(void *data,
95 static void _scroller_resize(void *data,
99 static void _ctxpopup_move(void *data,
103 static void _item_select_cb(void *data, Evas_Object *obj,
104 const char *emission,
106 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
107 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
108 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
109 static void _content_del(void *data,
113 static void _list_del(Widget_Data *wd);
114 static void _list_new(Evas_Object *obj);
115 static void _remove_items(Widget_Data * wd);
117 static const char SIG_DISMISSED[] = "dismissed";
119 static const Evas_Smart_Cb_Description _signals[] = {
125 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
126 void *event_info __UNUSED__)
128 Widget_Data *wd = elm_widget_data_get(obj);
130 if ((!wd) || (!wd->scr)) return;
131 elm_object_scroll_freeze_push(wd->scr);
135 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
136 void *event_info __UNUSED__)
138 Widget_Data *wd = elm_widget_data_get(obj);
140 if ((!wd) || (!wd->scr)) return;
141 elm_object_scroll_freeze_pop(wd->scr);
145 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
147 Widget_Data *wd = elm_widget_data_get(obj);
149 if ((!wd) || (!wd->scr)) return;
150 elm_object_scroll_hold_push(wd->scr);
154 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
156 Widget_Data *wd = elm_widget_data_get(obj);
158 if ((!wd) || (!wd->scr)) return;
159 elm_object_scroll_hold_pop(wd->scr);
163 _scroller_size_reset(Widget_Data *wd)
165 wd->finished = EINA_FALSE;
171 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
173 Widget_Data *wd = elm_widget_data_get(obj);
176 if (elm_widget_focus_get(obj))
187 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
189 Evas_Event_Key_Down *ev;
192 if (type != EVAS_CALLBACK_KEY_DOWN)
194 wd = elm_widget_data_get(obj);
195 if (!wd) return EINA_FALSE;
198 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
199 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
201 evas_object_hide(obj);
202 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
207 _parent_cut_off(Evas_Object *obj)
209 Widget_Data *wd = elm_widget_data_get(obj);
213 evas_object_event_callback_del_full(wd->parent,
217 evas_object_event_callback_del_full(wd->parent,
221 evas_object_event_callback_del_full(wd->parent,
222 EVAS_CALLBACK_RESIZE,
226 elm_widget_sub_object_del(wd->parent, obj);
230 _parent_resize(void *data,
232 Evas_Object *obj __UNUSED__,
233 void *event_info __UNUSED__)
235 Widget_Data *wd = elm_widget_data_get(data);
238 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
244 _parent_move(void *data,
246 Evas_Object *obj __UNUSED__,
247 void *event_info __UNUSED__)
249 Widget_Data *wd = elm_widget_data_get(data);
253 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
257 _scroller_size_reset(wd);
263 _parent_del(void *data,
265 Evas_Object *obj __UNUSED__,
266 void *event_info __UNUSED__)
268 evas_object_del(data);
272 _item_sizing_eval(Elm_Ctxpopup_Item *item)
274 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
278 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
280 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
281 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
285 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
286 Evas_Coord_Rectangle *hover_area)
288 pos->x -= (base_size->x / 2);
290 if (pos->x < hover_area->x)
291 pos->x = hover_area->x;
292 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
293 pos->x = (hover_area->x + hover_area->w) - base_size->x;
295 if (base_size->x > hover_area->w)
296 base_size->x -= (base_size->x - hover_area->w);
298 if (pos->x < hover_area->x)
299 pos->x = hover_area->x;
303 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
304 Evas_Coord_Rectangle *hover_area)
306 pos->y -= (base_size->y / 2);
308 if (pos->y < hover_area->y)
309 pos->y = hover_area->y;
310 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
311 pos->y = hover_area->y + hover_area->h - base_size->y;
313 if (base_size->y > hover_area->h)
314 base_size->y -= (base_size->y - hover_area->h);
316 if (pos->y < hover_area->y)
317 pos->y = hover_area->y;
320 static Elm_Ctxpopup_Direction
321 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
324 Evas_Coord_Point pos = {0, 0};
325 Evas_Coord_Point base_size;
326 Evas_Coord_Point max_size;
327 Evas_Coord_Point min_size;
328 Evas_Coord_Rectangle hover_area;
329 Evas_Coord_Point arrow_size;
330 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
331 Evas_Coord_Point temp;
334 wd = elm_widget_data_get(obj);
336 if ((!wd) || (!rect))
337 return ELM_CTXPOPUP_DIRECTION_DOWN;
339 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
340 &arrow_size.x, &arrow_size.y);
341 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
343 //Initialize Area Rectangle.
344 evas_object_geometry_get(wd->parent,
350 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
353 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
354 evas_object_smart_calculate(wd->base);
357 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
359 if ((max_size.y > 0) && (base_size.y > max_size.y))
360 base_size.y = max_size.y;
362 if ((max_size.x > 0) && (base_size.x > max_size.x))
363 base_size.x = max_size.x;
366 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
368 if ((min_size.y > 0) && (base_size.y < min_size.y))
369 base_size.y = min_size.y;
371 if ((min_size.x > 0) && (base_size.x < min_size.x))
372 base_size.x = min_size.x;
374 //Check the Which direction is available.
375 //If find a avaialble direction, it adjusts position and size.
376 for (idx = 0; idx < 4; idx++)
378 switch (wd->dir_priority[idx])
380 case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
381 case ELM_CTXPOPUP_DIRECTION_UP:
382 temp.y = (pos.y - base_size.y);
383 if ((temp.y - arrow_size.y) < hover_area.y)
385 _adjust_pos_x(&pos, &base_size, &hover_area);
386 pos.y -= base_size.y;
387 dir = ELM_CTXPOPUP_DIRECTION_UP;
389 case ELM_CTXPOPUP_DIRECTION_LEFT:
390 temp.x = (pos.x - base_size.x);
391 if ((temp.x - arrow_size.x) < hover_area.x)
393 _adjust_pos_y(&pos, &base_size, &hover_area);
394 pos.x -= base_size.x;
395 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
397 case ELM_CTXPOPUP_DIRECTION_RIGHT:
398 temp.x = (pos.x + base_size.x);
399 if ((temp.x + arrow_size.x) >
400 (hover_area.x + hover_area.w))
402 _adjust_pos_y(&pos, &base_size, &hover_area);
403 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
405 case ELM_CTXPOPUP_DIRECTION_DOWN:
406 temp.y = (pos.y + base_size.y);
407 if ((temp.y + arrow_size.y) >
408 (hover_area.y + hover_area.h))
410 _adjust_pos_x(&pos, &base_size, &hover_area);
411 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
419 //In this case, all directions are invalid because of lack of space.
422 Evas_Coord length[2];
426 length[0] = pos.y - hover_area.y;
427 length[1] = (hover_area.y + hover_area.h) - pos.y;
429 // ELM_CTXPOPUP_DIRECTION_UP
430 if (length[0] > length[1])
432 _adjust_pos_x(&pos, &base_size, &hover_area);
433 pos.y -= base_size.y;
434 dir = ELM_CTXPOPUP_DIRECTION_UP;
435 if (pos.y < (hover_area.y + arrow_size.y))
437 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
438 pos.y = hover_area.y + arrow_size.y;
441 //ELM_CTXPOPUP_DIRECTION_DOWN
444 _adjust_pos_x(&pos, &base_size, &hover_area);
445 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
446 if ((pos.y + arrow_size.y + base_size.y) >
447 (hover_area.y + hover_area.h))
449 ((pos.y + arrow_size.y + base_size.y) -
450 (hover_area.y + hover_area.h));
455 length[0] = pos.x - hover_area.x;
456 length[1] = (hover_area.x + hover_area.w) - pos.x;
458 //ELM_CTXPOPUP_DIRECTION_LEFT
459 if (length[0] > length[1])
461 _adjust_pos_y(&pos, &base_size, &hover_area);
462 pos.x -= base_size.x;
463 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
464 if (pos.x < (hover_area.x + arrow_size.x))
466 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
467 pos.x = hover_area.x + arrow_size.x;
470 //ELM_CTXPOPUP_DIRECTION_RIGHT
473 _adjust_pos_y(&pos, &base_size, &hover_area);
474 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
475 if (pos.x + (arrow_size.x + base_size.x) >
476 hover_area.x + hover_area.w)
478 ((pos.x + arrow_size.x + base_size.x) -
479 (hover_area.x + hover_area.w));
484 //Final position and size.
487 rect->w = base_size.x;
488 rect->h = base_size.y;
494 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
497 Evas_Coord_Rectangle arrow_size;
498 Evas_Coord_Rectangle base_size;
502 wd = elm_widget_data_get(obj);
505 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
506 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
508 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
509 &base_size.w, &base_size.h);
511 edje_object_part_unswallow(wd->base, wd->arrow);
515 case ELM_CTXPOPUP_DIRECTION_RIGHT:
516 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
517 edje_object_part_swallow(wd->base,
518 "elm.swallow.arrow_left",
522 if (y < ((arrow_size.h * 0.5) + base_size.y))
524 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
525 y = base_size.h - arrow_size.h;
527 y = y - base_size.y - (arrow_size.h * 0.5);
528 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
529 edje_object_part_drag_value_set(wd->base,
530 "elm.swallow.arrow_left",
535 case ELM_CTXPOPUP_DIRECTION_LEFT:
536 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
537 edje_object_part_swallow(wd->base,
538 "elm.swallow.arrow_right",
542 if (y < ((arrow_size.h * 0.5) + base_size.y))
544 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
545 y = base_size.h - arrow_size.h;
547 y = y - base_size.y - (arrow_size.h * 0.5);
548 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
549 edje_object_part_drag_value_set(wd->base,
550 "elm.swallow.arrow_right",
555 case ELM_CTXPOPUP_DIRECTION_DOWN:
556 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
557 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
560 if (x < ((arrow_size.w * 0.5) + base_size.x))
562 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
563 x = base_size.w - arrow_size.w;
565 x = x - base_size.x - (arrow_size.w * 0.5);
566 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
567 edje_object_part_drag_value_set(wd->base,
568 "elm.swallow.arrow_up",
573 case ELM_CTXPOPUP_DIRECTION_UP:
574 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
575 edje_object_part_swallow(wd->base,
576 "elm.swallow.arrow_down",
580 if (x < ((arrow_size.w * 0.5) + base_size.x))
582 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
583 x = base_size.w - arrow_size.w;
584 else x = x - base_size.x - (arrow_size.w * 0.5);
585 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
586 edje_object_part_drag_value_set(wd->base,
587 "elm.swallow.arrow_down",
598 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
602 wd = elm_widget_data_get(obj);
603 if (!wd || wd->visible) return;
607 case ELM_CTXPOPUP_DIRECTION_UP:
608 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
610 case ELM_CTXPOPUP_DIRECTION_LEFT:
611 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
613 case ELM_CTXPOPUP_DIRECTION_RIGHT:
614 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
616 case ELM_CTXPOPUP_DIRECTION_DOWN:
617 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
625 _sizing_eval(Evas_Object *obj)
629 Elm_Ctxpopup_Item *item;
630 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
631 Evas_Coord_Point box_size = { 0, 0 };
632 Evas_Coord_Point _box_size = { 0, 0 };
634 wd = elm_widget_data_get(obj);
638 EINA_LIST_FOREACH(wd->items, elist, item)
640 _item_sizing_eval(item);
641 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
644 if (_box_size.x > box_size.x)
645 box_size.x = _box_size.x;
646 if (_box_size.y != -1)
647 box_size.y += _box_size.y;
651 if (_box_size.x != -1)
652 box_size.x += _box_size.x;
653 if (_box_size.y > box_size.y)
654 box_size.y = _box_size.y;
660 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
661 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
665 wd->dir = _calc_base_geometry(obj, &rect);
666 _show_signal_emit(obj, wd->dir);
667 _update_arrow(obj, wd->dir);
668 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
670 //resize scroller according to final size.
672 evas_object_smart_calculate(wd->scr);
674 evas_object_move(wd->base, rect.x, rect.y);
675 evas_object_resize(wd->base, rect.w, rect.h);
679 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
680 Evas_Coord_Rectangle *rect)
682 Evas_Coord arrow_w, arrow_h;
684 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
688 case ELM_CTXPOPUP_DIRECTION_RIGHT:
691 case ELM_CTXPOPUP_DIRECTION_LEFT:
694 case ELM_CTXPOPUP_DIRECTION_DOWN:
697 case ELM_CTXPOPUP_DIRECTION_UP:
706 _del_pre_hook(Evas_Object *obj)
710 wd = elm_widget_data_get(obj);
713 _parent_cut_off(obj);
717 _del_hook(Evas_Object *obj)
721 wd = elm_widget_data_get(obj);
724 elm_ctxpopup_clear(obj);
725 evas_object_del(wd->arrow);
726 evas_object_del(wd->base);
730 //FIXME: lost the content size when theme hook is called.
732 _theme_hook(Evas_Object *obj)
736 Elm_Ctxpopup_Item *item;
739 wd = elm_widget_data_get(obj);
742 _elm_widget_mirrored_reload(obj);
743 rtl = elm_widget_mirrored_get(obj);
745 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
746 elm_widget_style_get(obj));
747 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
748 elm_widget_style_get(obj));
749 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
750 elm_widget_style_get(obj));
753 EINA_LIST_FOREACH(wd->items, elist, item)
755 edje_object_mirrored_set(VIEW(item), rtl);
757 if (item->label && item->icon)
758 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
759 "icon_text_style_item",
760 elm_widget_style_get(obj));
761 else if (item->label)
762 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
763 elm_widget_style_get(obj));
765 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
766 elm_widget_style_get(obj));
768 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
771 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
773 edje_object_message_signal_process(VIEW(item));
778 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
779 elm_object_style_set(wd->scr, "ctxpopup");
781 elm_object_style_set(wd->scr, elm_object_style_get(obj));
784 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
788 _scroller_size_reset(wd);
794 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__,
795 Evas_Object *content)
797 ELM_CHECK_WIDTYPE(obj, widtype);
801 wd = elm_widget_data_get(obj);
802 if ((!wd) || (!content)) return;
804 if (wd->items) elm_ctxpopup_clear(obj);
805 if (wd->content) evas_object_del(wd->content);
807 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
810 elm_widget_sub_object_add(obj, content);
811 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
813 wd->content = content;
815 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
822 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
824 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
827 Evas_Object *content;
829 wd = elm_widget_data_get(obj);
830 if (!wd) return NULL;
832 content = wd->content;
833 if (!content) return NULL;
835 edje_object_part_unswallow(wd->base, content);
836 elm_widget_sub_object_del(obj, content);
837 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
838 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
841 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
848 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
850 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
852 Widget_Data *wd = elm_widget_data_get(obj);
853 if (!wd) return NULL;
858 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
859 const char *emission __UNUSED__, const char *source __UNUSED__)
861 evas_object_hide(data);
865 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
866 void *event_info __UNUSED__)
870 wd = elm_widget_data_get(obj);
873 if ((!wd->items) && (!wd->content)) return;
875 wd->visible = EINA_TRUE;
877 evas_object_show(wd->bg);
878 evas_object_show(wd->base);
879 evas_object_show(wd->arrow);
881 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
882 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
886 elm_object_focus_set(obj, EINA_TRUE);
890 _hide(Evas_Object *obj)
892 Widget_Data *wd = elm_widget_data_get(obj);
894 if ((!wd) || (!wd->visible)) return;
896 evas_object_hide(wd->bg);
897 evas_object_hide(wd->arrow);
898 evas_object_hide(wd->base);
900 _scroller_size_reset(wd);
902 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
903 wd->visible = EINA_FALSE;
907 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
908 void *event_info __UNUSED__)
914 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
915 void *event_info __UNUSED__)
920 wd = elm_widget_data_get(data);
922 if (!wd->visible) return;
923 if (wd->finished) return;
925 evas_object_geometry_get(obj, 0, 0, &w, &h);
927 if (w != 0 && h != 0)
929 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
932 wd->finished = EINA_TRUE;
937 if (wd->max_sc_w < w)
939 if (wd->max_sc_h < h)
946 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
947 void *event_info __UNUSED__)
951 wd = elm_widget_data_get(obj);
956 evas_object_show(wd->arrow);
958 _scroller_size_reset(wd);
963 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
964 const char *emission __UNUSED__, const char *source __UNUSED__)
966 Elm_Ctxpopup_Item *item = data;
969 if (item->disabled) return;
972 item->func((void*) item->base.data, WIDGET(item), data);
976 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
979 evas_object_del(item->icon);
984 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
985 edje_object_message_signal_process(VIEW(item));
989 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
991 if (!eina_stringshare_replace(&item->label, label))
994 edje_object_part_text_set(VIEW(item), "elm.text", label);
995 edje_object_message_signal_process(VIEW(item));
999 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1003 wd = elm_widget_data_get(WIDGET(item));
1006 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1007 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
1008 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1009 elm_widget_style_get(WIDGET(item)));
1010 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1011 _item_select_cb, item);
1012 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1013 evas_object_show(VIEW(item));
1017 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1018 void *event_info __UNUSED__)
1020 elm_object_content_unset(data);
1024 _list_del(Widget_Data *wd)
1026 if (!wd->scr) return;
1028 edje_object_part_unswallow(wd->base, wd->scr);
1029 evas_object_del(wd->scr);
1035 _list_new(Evas_Object *obj)
1038 wd = elm_widget_data_get(obj);
1042 wd->scr = elm_scroller_add(obj);
1043 elm_object_style_set(wd->scr, "ctxpopup");
1044 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1045 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1046 _scroller_resize, obj);
1047 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1050 wd->box = elm_box_add(obj);
1051 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1054 elm_scroller_content_set(wd->scr, wd->box);
1055 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1059 _remove_items(Widget_Data *wd)
1062 Elm_Ctxpopup_Item *item;
1064 if (!wd->items) return;
1066 EINA_LIST_FOREACH(wd->items, elist, item)
1069 eina_stringshare_del(item->label);
1071 evas_object_del(item->icon);
1072 wd->items = eina_list_remove(wd->items, item);
1080 elm_ctxpopup_add(Evas_Object *parent)
1086 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1088 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1089 elm_widget_type_set(obj, "ctxpopup");
1090 elm_widget_data_set(obj, wd);
1091 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1092 elm_widget_del_hook_set(obj, _del_hook);
1093 elm_widget_theme_hook_set(obj, _theme_hook);
1094 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1095 elm_widget_can_focus_set(obj, EINA_TRUE);
1096 elm_widget_event_hook_set(obj, _event_hook);
1097 elm_widget_content_set_hook_set(obj, _content_set_hook);
1098 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1099 elm_widget_content_get_hook_set(obj, _content_get_hook);
1102 wd->bg = edje_object_add(e);
1103 elm_widget_sub_object_add(obj, wd->bg);
1104 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1105 edje_object_signal_callback_add(wd->bg,
1111 wd->base = edje_object_add(e);
1112 elm_widget_sub_object_add(obj, wd->base);
1113 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1116 wd->arrow = edje_object_add(e);
1117 elm_widget_sub_object_add(obj, wd->arrow);
1118 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1120 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1121 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1122 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1123 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1124 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1126 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1128 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1130 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1132 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1133 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1134 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1135 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1137 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1139 //default parent is to be hover parent
1140 elm_ctxpopup_hover_parent_set(obj, parent);
1146 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1148 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1149 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1150 return ctxpopup_it->icon;
1154 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1156 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1159 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1161 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1164 _item_icon_set(ctxpopup_it, icon);
1165 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1169 _scroller_size_reset(wd);
1170 _sizing_eval(WIDGET(ctxpopup_it));
1175 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1177 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1178 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1179 return ctxpopup_it->label;
1183 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1185 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1188 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1190 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1193 _item_label_set(ctxpopup_it, label);
1194 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1198 _scroller_size_reset(wd);
1199 _sizing_eval(WIDGET(ctxpopup_it));
1204 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1206 ELM_CHECK_WIDTYPE(obj, widtype);
1209 Evas_Coord x, y, w, h;
1211 wd = elm_widget_data_get(obj);
1212 if ((!wd) || (!parent)) return;
1214 _parent_cut_off(obj);
1218 evas_object_event_callback_add(parent,
1222 evas_object_event_callback_add(parent,
1226 evas_object_event_callback_add(parent,
1227 EVAS_CALLBACK_RESIZE,
1232 elm_widget_sub_object_add(parent, obj);
1233 wd->parent = parent;
1236 evas_object_geometry_get(parent, &x, &y, &w, &h);
1237 evas_object_move(wd->bg, x, y);
1238 evas_object_resize(wd->bg, w, h);
1240 if (wd->visible) _sizing_eval(obj);
1244 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1246 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1250 wd = elm_widget_data_get(obj);
1251 if (!wd) return NULL;
1257 elm_ctxpopup_clear(Evas_Object * obj)
1259 ELM_CHECK_WIDTYPE(obj, widtype);
1261 Widget_Data *wd = elm_widget_data_get(obj);
1266 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1270 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1272 ELM_CHECK_WIDTYPE(obj, widtype);
1276 wd = elm_widget_data_get(obj);
1279 wd->horizontal = !!horizontal;
1281 if ((!wd->scr) && (!wd->box))
1286 elm_box_horizontal_set(wd->box, EINA_FALSE);
1287 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1291 elm_box_horizontal_set(wd->box, EINA_TRUE);
1292 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1295 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1302 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1304 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1308 wd = elm_widget_data_get(obj);
1309 if (!wd) return EINA_FALSE;
1311 return wd->horizontal;
1314 EAPI Elm_Object_Item *
1315 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1316 Evas_Object *icon, Evas_Smart_Cb func,
1319 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1322 Evas_Object *content;
1323 Elm_Ctxpopup_Item *item;
1325 wd = elm_widget_data_get(obj);
1326 if (!wd) return NULL;
1328 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1329 if (!item) return NULL;
1331 //The first item is appended.
1332 content = elm_object_content_unset(obj);
1333 if (content) evas_object_del(content);
1339 item->base.data = data;
1342 _item_new(item, "icon_text_style_item");
1344 _item_new(item, "text_style_item");
1346 _item_new(item, "icon_style_item");
1348 _item_icon_set(item, icon);
1349 _item_label_set(item, label);
1350 elm_box_pack_end(wd->box, VIEW(item));
1351 wd->items = eina_list_append(wd->items, item);
1352 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1356 _scroller_size_reset(wd);
1360 return (Elm_Object_Item *) item;
1364 elm_ctxpopup_item_del(Elm_Object_Item *it)
1366 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1369 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1371 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1374 if (ctxpopup_it->icon)
1375 evas_object_del(ctxpopup_it->icon);
1376 if (VIEW(ctxpopup_it))
1377 evas_object_del(VIEW(ctxpopup_it));
1379 eina_stringshare_del(ctxpopup_it->label);
1381 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1383 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1385 elm_widget_item_del(ctxpopup_it);
1387 if (eina_list_count(wd->items) < 1)
1389 evas_object_hide(WIDGET(ctxpopup_it));
1394 _sizing_eval(WIDGET(ctxpopup_it));
1399 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1401 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1404 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1406 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1409 if (disabled == ctxpopup_it->disabled)
1413 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
1415 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
1417 ctxpopup_it->disabled = !!disabled;
1421 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1423 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1424 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1425 return ctxpopup_it->disabled;
1429 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1431 elm_object_content_set(obj, content);
1435 elm_ctxpopup_content_unset(Evas_Object *obj)
1437 return elm_object_content_unset(obj);
1441 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1442 Elm_Ctxpopup_Direction first,
1443 Elm_Ctxpopup_Direction second,
1444 Elm_Ctxpopup_Direction third,
1445 Elm_Ctxpopup_Direction fourth)
1447 ELM_CHECK_WIDTYPE(obj, widtype);
1450 wd = elm_widget_data_get(obj);
1453 wd->dir_priority[0] = first;
1454 wd->dir_priority[1] = second;
1455 wd->dir_priority[2] = third;
1456 wd->dir_priority[3] = fourth;
1463 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1464 Elm_Ctxpopup_Direction *first,
1465 Elm_Ctxpopup_Direction *second,
1466 Elm_Ctxpopup_Direction *third,
1467 Elm_Ctxpopup_Direction *fourth)
1469 ELM_CHECK_WIDTYPE(obj, widtype);
1472 wd = elm_widget_data_get(obj);
1475 if (first) *first = wd->dir_priority[0];
1476 if (second) *second = wd->dir_priority[1];
1477 if (third) *third = wd->dir_priority[2];
1478 if (fourth) *fourth = wd->dir_priority[3];
1481 EAPI Elm_Ctxpopup_Direction
1482 elm_ctxpopup_direction_get(const Evas_Object *obj)
1484 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1487 wd = elm_widget_data_get(obj);
1488 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;