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
25 Elm_Ctxpopup_Direction dir;
26 Elm_Ctxpopup_Direction dir_priority[4];
27 Evas_Coord max_sc_w, max_sc_h;
28 Eina_Bool horizontal:1;
33 static const char *widtype = NULL;
35 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
36 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
37 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
38 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
39 static void _scroller_size_reset(Widget_Data *wd);
40 static void _on_focus_hook(void *data, Evas_Object *obj);
41 static Eina_Bool _event_hook(Evas_Object *obj,
43 Evas_Callback_Type type,
45 static void _parent_cut_off(Evas_Object *obj);
46 static void _parent_resize(void *data,
50 static void _parent_move(void *data,
54 static void _parent_del(void *data,
58 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
59 static void _adjust_pos_x(Evas_Coord_Point *pos,
60 Evas_Coord_Point *base_size,
61 Evas_Coord_Rectangle *hover_area);
62 static void _adjust_pos_y(Evas_Coord_Point *pos,
63 Evas_Coord_Point *base_size,
64 Evas_Coord_Rectangle *hover_area);
65 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
66 Evas_Coord_Rectangle *rect);
67 static void _update_arrow(Evas_Object *obj,
68 Elm_Ctxpopup_Direction dir,
69 Evas_Coord_Rectangle rect);
70 static void _sizing_eval(Evas_Object *obj);
71 static void _hide_signal_emit(Evas_Object *obj,
72 Elm_Ctxpopup_Direction dir);
73 static void _show_signal_emit(Evas_Object *obj,
74 Elm_Ctxpopup_Direction dir);
75 static void _shift_base_by_arrow(Evas_Object *arrow,
76 Elm_Ctxpopup_Direction dir,
77 Evas_Coord_Rectangle *rect);
78 static void _del_pre_hook(Evas_Object *obj);
79 static void _del_hook(Evas_Object *obj);
80 static void _theme_hook(Evas_Object *obj);
81 static void _content_set_hook(Evas_Object *obj,
83 Evas_Object *content);
84 static Evas_Object * _content_unset_hook(Evas_Object *obj,
86 static Evas_Object * _content_get_hook(const Evas_Object *obj,
88 static void _item_text_set_hook(Elm_Object_Item *it,
91 static const char * _item_text_get_hook(const Elm_Object_Item *it,
93 static void _item_content_set_hook(Elm_Object_Item *it,
95 Evas_Object *content);
96 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
98 static void _item_disable_hook(Elm_Object_Item *it);
99 static void _item_signal_emit_hook(Elm_Object_Item *it,
100 const char *emission,
102 static void _bg_clicked_cb(void *data, Evas_Object *obj,
103 const char *emission,
105 static void _ctxpopup_show(void *data,
109 static void _hide_finished(void *data,
111 const char *emission,
112 const char *source __UNUSED__);
113 static void _hide(Evas_Object *obj);
114 static void _ctxpopup_hide(void *data,
118 static void _content_resize(void *data,
122 static void _scroller_resize(void *data,
126 static void _ctxpopup_move(void *data,
130 static void _restack(void *data, Evas *e, Evas_Object *obj, void *event_info);
131 static void _item_select_cb(void *data, Evas_Object *obj,
132 const char *emission,
134 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
135 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
136 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
137 static void _content_del(void *data,
141 static void _list_del(Widget_Data *wd);
142 static void _list_new(Evas_Object *obj);
143 static void _remove_items(Widget_Data * wd);
145 static const char SIG_DISMISSED[] = "dismissed";
147 static const Evas_Smart_Cb_Description _signals[] = {
153 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
154 void *event_info __UNUSED__)
156 Widget_Data *wd = elm_widget_data_get(obj);
158 if ((!wd) || (!wd->scr)) return;
159 elm_object_scroll_freeze_push(wd->scr);
163 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
164 void *event_info __UNUSED__)
166 Widget_Data *wd = elm_widget_data_get(obj);
168 if ((!wd) || (!wd->scr)) return;
169 elm_object_scroll_freeze_pop(wd->scr);
173 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
175 Widget_Data *wd = elm_widget_data_get(obj);
177 if ((!wd) || (!wd->scr)) return;
178 elm_object_scroll_hold_push(wd->scr);
182 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
184 Widget_Data *wd = elm_widget_data_get(obj);
186 if ((!wd) || (!wd->scr)) return;
187 elm_object_scroll_hold_pop(wd->scr);
191 _scroller_size_reset(Widget_Data *wd)
193 wd->finished = EINA_FALSE;
199 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
201 Widget_Data *wd = elm_widget_data_get(obj);
204 if (elm_widget_focus_get(obj))
215 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
216 Evas_Callback_Type type, void *event_info)
218 Evas_Event_Key_Down *ev;
221 if (type != EVAS_CALLBACK_KEY_DOWN)
223 wd = elm_widget_data_get(obj);
224 if (!wd) return EINA_FALSE;
227 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
228 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
230 evas_object_hide(obj);
231 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
236 _parent_cut_off(Evas_Object *obj)
238 Widget_Data *wd = elm_widget_data_get(obj);
242 evas_object_event_callback_del_full(wd->parent,
246 evas_object_event_callback_del_full(wd->parent,
250 evas_object_event_callback_del_full(wd->parent,
251 EVAS_CALLBACK_RESIZE,
255 elm_widget_sub_object_del(wd->parent, obj);
259 _parent_resize(void *data,
261 Evas_Object *obj __UNUSED__,
262 void *event_info __UNUSED__)
264 Widget_Data *wd = elm_widget_data_get(data);
267 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
273 _parent_move(void *data,
275 Evas_Object *obj __UNUSED__,
276 void *event_info __UNUSED__)
278 Widget_Data *wd = elm_widget_data_get(data);
282 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
286 _scroller_size_reset(wd);
292 _parent_del(void *data,
294 Evas_Object *obj __UNUSED__,
295 void *event_info __UNUSED__)
297 evas_object_del(data);
301 _item_sizing_eval(Elm_Ctxpopup_Item *item)
303 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
307 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
309 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
310 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
314 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
315 Evas_Coord_Rectangle *hover_area)
317 pos->x -= (base_size->x / 2);
319 if (pos->x < hover_area->x)
320 pos->x = hover_area->x;
321 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
322 pos->x = (hover_area->x + hover_area->w) - base_size->x;
324 if (base_size->x > hover_area->w)
325 base_size->x -= (base_size->x - hover_area->w);
327 if (pos->x < hover_area->x)
328 pos->x = hover_area->x;
332 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
333 Evas_Coord_Rectangle *hover_area)
335 pos->y -= (base_size->y / 2);
337 if (pos->y < hover_area->y)
338 pos->y = hover_area->y;
339 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
340 pos->y = hover_area->y + hover_area->h - base_size->y;
342 if (base_size->y > hover_area->h)
343 base_size->y -= (base_size->y - hover_area->h);
345 if (pos->y < hover_area->y)
346 pos->y = hover_area->y;
349 static Elm_Ctxpopup_Direction
350 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
353 Evas_Coord_Point pos = {0, 0};
354 Evas_Coord_Point base_size;
355 Evas_Coord_Point max_size;
356 Evas_Coord_Point min_size;
357 Evas_Coord_Rectangle hover_area;
358 Evas_Coord_Point arrow_size;
359 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
360 Evas_Coord_Point temp;
363 wd = elm_widget_data_get(obj);
365 if ((!wd) || (!rect))
366 return ELM_CTXPOPUP_DIRECTION_DOWN;
368 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
369 &arrow_size.x, &arrow_size.y);
370 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
372 //Initialize Area Rectangle.
373 evas_object_geometry_get(wd->parent,
379 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
382 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
383 evas_object_smart_calculate(wd->base);
386 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
388 if ((max_size.y > 0) && (base_size.y > max_size.y))
389 base_size.y = max_size.y;
391 if ((max_size.x > 0) && (base_size.x > max_size.x))
392 base_size.x = max_size.x;
395 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
397 if ((min_size.y > 0) && (base_size.y < min_size.y))
398 base_size.y = min_size.y;
400 if ((min_size.x > 0) && (base_size.x < min_size.x))
401 base_size.x = min_size.x;
403 //Check the Which direction is available.
404 //If find a avaialble direction, it adjusts position and size.
405 for (idx = 0; idx < 4; idx++)
407 switch (wd->dir_priority[idx])
409 case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
410 case ELM_CTXPOPUP_DIRECTION_UP:
411 temp.y = (pos.y - base_size.y);
412 if ((temp.y - arrow_size.y) < hover_area.y)
414 _adjust_pos_x(&pos, &base_size, &hover_area);
415 pos.y -= base_size.y;
416 dir = ELM_CTXPOPUP_DIRECTION_UP;
418 case ELM_CTXPOPUP_DIRECTION_LEFT:
419 temp.x = (pos.x - base_size.x);
420 if ((temp.x - arrow_size.x) < hover_area.x)
422 _adjust_pos_y(&pos, &base_size, &hover_area);
423 pos.x -= base_size.x;
424 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
426 case ELM_CTXPOPUP_DIRECTION_RIGHT:
427 temp.x = (pos.x + base_size.x);
428 if ((temp.x + arrow_size.x) >
429 (hover_area.x + hover_area.w))
431 _adjust_pos_y(&pos, &base_size, &hover_area);
432 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
434 case ELM_CTXPOPUP_DIRECTION_DOWN:
435 temp.y = (pos.y + base_size.y);
436 if ((temp.y + arrow_size.y) >
437 (hover_area.y + hover_area.h))
439 _adjust_pos_x(&pos, &base_size, &hover_area);
440 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
448 //In this case, all directions are invalid because of lack of space.
451 Evas_Coord length[2];
455 length[0] = pos.y - hover_area.y;
456 length[1] = (hover_area.y + hover_area.h) - pos.y;
458 // ELM_CTXPOPUP_DIRECTION_UP
459 if (length[0] > length[1])
461 _adjust_pos_x(&pos, &base_size, &hover_area);
462 pos.y -= base_size.y;
463 dir = ELM_CTXPOPUP_DIRECTION_UP;
464 if (pos.y < (hover_area.y + arrow_size.y))
466 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
467 pos.y = hover_area.y + arrow_size.y;
470 //ELM_CTXPOPUP_DIRECTION_DOWN
473 _adjust_pos_x(&pos, &base_size, &hover_area);
474 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
475 if ((pos.y + arrow_size.y + base_size.y) >
476 (hover_area.y + hover_area.h))
478 ((pos.y + arrow_size.y + base_size.y) -
479 (hover_area.y + hover_area.h));
484 length[0] = pos.x - hover_area.x;
485 length[1] = (hover_area.x + hover_area.w) - pos.x;
487 //ELM_CTXPOPUP_DIRECTION_LEFT
488 if (length[0] > length[1])
490 _adjust_pos_y(&pos, &base_size, &hover_area);
491 pos.x -= base_size.x;
492 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
493 if (pos.x < (hover_area.x + arrow_size.x))
495 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
496 pos.x = hover_area.x + arrow_size.x;
499 //ELM_CTXPOPUP_DIRECTION_RIGHT
502 _adjust_pos_y(&pos, &base_size, &hover_area);
503 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
504 if (pos.x + (arrow_size.x + base_size.x) >
505 hover_area.x + hover_area.w)
507 ((pos.x + arrow_size.x + base_size.x) -
508 (hover_area.x + hover_area.w));
513 //Final position and size.
516 rect->w = base_size.x;
517 rect->h = base_size.y;
523 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
524 Evas_Coord_Rectangle base_size)
527 Evas_Coord_Rectangle arrow_size;
531 wd = elm_widget_data_get(obj);
534 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
535 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
538 edje_object_part_unswallow(wd->base, wd->arrow);
542 case ELM_CTXPOPUP_DIRECTION_RIGHT:
543 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
544 edje_object_part_swallow(wd->base,
545 "elm.swallow.arrow_left",
549 if (y < ((arrow_size.h * 0.5) + base_size.y))
551 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
552 y = base_size.h - arrow_size.h;
554 y = y - base_size.y - (arrow_size.h * 0.5);
555 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
556 edje_object_part_drag_value_set(wd->base,
557 "elm.swallow.arrow_left",
562 case ELM_CTXPOPUP_DIRECTION_LEFT:
563 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
564 edje_object_part_swallow(wd->base,
565 "elm.swallow.arrow_right",
569 if (y < ((arrow_size.h * 0.5) + base_size.y))
571 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
572 y = base_size.h - arrow_size.h;
574 y = y - base_size.y - (arrow_size.h * 0.5);
575 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
576 edje_object_part_drag_value_set(wd->base,
577 "elm.swallow.arrow_right",
582 case ELM_CTXPOPUP_DIRECTION_DOWN:
583 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
584 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
587 if (x < ((arrow_size.w * 0.5) + base_size.x))
589 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
590 x = base_size.w - arrow_size.w;
592 x = x - base_size.x - (arrow_size.w * 0.5);
593 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
594 edje_object_part_drag_value_set(wd->base,
595 "elm.swallow.arrow_up",
600 case ELM_CTXPOPUP_DIRECTION_UP:
601 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
602 edje_object_part_swallow(wd->base,
603 "elm.swallow.arrow_down",
607 if (x < ((arrow_size.w * 0.5) + base_size.x))
609 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
610 x = base_size.w - arrow_size.w;
611 else x = x - base_size.x - (arrow_size.w * 0.5);
612 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
613 edje_object_part_drag_value_set(wd->base,
614 "elm.swallow.arrow_down",
625 _hide_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
629 wd = elm_widget_data_get(obj);
630 if (!wd->visible) return;
634 case ELM_CTXPOPUP_DIRECTION_UP:
635 edje_object_signal_emit(wd->base, "elm,state,hide,up", "elm");
637 case ELM_CTXPOPUP_DIRECTION_LEFT:
638 edje_object_signal_emit(wd->base, "elm,state,hide,left", "elm");
640 case ELM_CTXPOPUP_DIRECTION_RIGHT:
641 edje_object_signal_emit(wd->base, "elm,state,hide,right", "elm");
643 case ELM_CTXPOPUP_DIRECTION_DOWN:
644 edje_object_signal_emit(wd->base, "elm,state,hide,down", "elm");
650 edje_object_signal_emit(wd->bg, "elm,state,hide", "elm");
654 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
658 wd = elm_widget_data_get(obj);
659 if (wd->visible) return;
663 case ELM_CTXPOPUP_DIRECTION_UP:
664 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
666 case ELM_CTXPOPUP_DIRECTION_LEFT:
667 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
669 case ELM_CTXPOPUP_DIRECTION_RIGHT:
670 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
672 case ELM_CTXPOPUP_DIRECTION_DOWN:
673 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
681 _sizing_eval(Evas_Object *obj)
685 Elm_Ctxpopup_Item *item;
686 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
687 Evas_Coord_Point box_size = { 0, 0 };
688 Evas_Coord_Point _box_size = { 0, 0 };
690 wd = elm_widget_data_get(obj);
694 EINA_LIST_FOREACH(wd->items, elist, item)
696 _item_sizing_eval(item);
697 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
700 if (_box_size.x > box_size.x)
701 box_size.x = _box_size.x;
702 if (_box_size.y != -1)
703 box_size.y += _box_size.y;
707 if (_box_size.x != -1)
708 box_size.x += _box_size.x;
709 if (_box_size.y > box_size.y)
710 box_size.y = _box_size.y;
716 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
717 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
721 wd->dir = _calc_base_geometry(obj, &rect);
722 _show_signal_emit(obj, wd->dir);
723 _update_arrow(obj, wd->dir, rect);
724 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
726 //resize scroller according to final size.
728 evas_object_smart_calculate(wd->scr);
730 evas_object_move(wd->base, rect.x, rect.y);
731 evas_object_resize(wd->base, rect.w, rect.h);
735 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
736 Evas_Coord_Rectangle *rect)
738 Evas_Coord arrow_w, arrow_h;
740 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
744 case ELM_CTXPOPUP_DIRECTION_RIGHT:
747 case ELM_CTXPOPUP_DIRECTION_LEFT:
750 case ELM_CTXPOPUP_DIRECTION_DOWN:
753 case ELM_CTXPOPUP_DIRECTION_UP:
762 _del_pre_hook(Evas_Object *obj)
766 wd = elm_widget_data_get(obj);
769 evas_object_event_callback_del_full(wd->box, EVAS_CALLBACK_RESIZE,
770 _content_resize, obj);
771 _parent_cut_off(obj);
775 _del_hook(Evas_Object *obj)
779 wd = elm_widget_data_get(obj);
782 elm_ctxpopup_clear(obj);
783 evas_object_del(wd->arrow);
784 evas_object_del(wd->base);
788 //FIXME: lost the content size when theme hook is called.
790 _theme_hook(Evas_Object *obj)
794 Elm_Ctxpopup_Item *item;
797 wd = elm_widget_data_get(obj);
800 _elm_widget_mirrored_reload(obj);
801 rtl = elm_widget_mirrored_get(obj);
803 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
804 elm_widget_style_get(obj));
805 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
806 elm_widget_style_get(obj));
807 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
808 elm_widget_style_get(obj));
811 EINA_LIST_FOREACH(wd->items, elist, item)
813 edje_object_mirrored_set(VIEW(item), rtl);
815 if (item->label && item->icon)
816 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
817 "icon_text_style_item",
818 elm_widget_style_get(obj));
819 else if (item->label)
820 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
821 elm_widget_style_get(obj));
823 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
824 elm_widget_style_get(obj));
826 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
828 if (elm_widget_item_disabled_get(item))
829 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
831 edje_object_message_signal_process(VIEW(item));
836 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
837 elm_object_style_set(wd->scr, "ctxpopup");
839 elm_object_style_set(wd->scr, elm_object_style_get(obj));
842 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
846 _scroller_size_reset(wd);
852 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
854 ELM_CHECK_WIDTYPE(obj, widtype);
855 Evas_Coord min_w = -1, min_h = -1;
859 if (part && strcmp(part, "default")) return;
861 wd = elm_widget_data_get(obj);
862 if ((!wd) || (!content)) return;
864 if (wd->items) elm_ctxpopup_clear(obj);
865 if (wd->content) evas_object_del(wd->content);
868 wd->box = elm_box_add(obj);
869 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
871 evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
873 evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
875 evas_object_show(content);
876 evas_object_size_hint_min_get(content, &min_w, &min_h);
877 evas_object_size_hint_min_set(wd->box, min_w, min_h);
878 elm_box_pack_end(wd->box, content);
880 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
881 _content_resize, obj);
882 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
885 elm_widget_sub_object_add(obj, wd->box);
886 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
888 wd->content = content;
889 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
896 _content_unset_hook(Evas_Object *obj, const char *part)
898 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
901 Evas_Object *content;
902 if (part && strcmp(part, "default")) return NULL;
903 wd = elm_widget_data_get(obj);
904 if (!wd) return NULL;
906 content = wd->content;
907 if (!content || !wd->box) return NULL;
909 edje_object_part_unswallow(wd->base, wd->box);
910 elm_widget_sub_object_del(obj, wd->box);
911 evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
912 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
914 evas_object_del(wd->box);
917 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
923 _content_get_hook(const Evas_Object *obj, const char *part)
925 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
927 if (part && strcmp(part, "default")) return NULL;
928 wd = elm_widget_data_get(obj);
929 if (!wd) return NULL;
934 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
937 Elm_Ctxpopup_Item *ctxpopup_it;
939 if (part && strcmp(part, "default")) return;
941 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
943 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
946 _item_label_set(ctxpopup_it, label);
947 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
951 _scroller_size_reset(wd);
952 _sizing_eval(WIDGET(ctxpopup_it));
957 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
959 Elm_Ctxpopup_Item *ctxpopup_it;
960 if (part && strcmp(part, "default")) return NULL;
961 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
962 return ctxpopup_it->label;
966 _item_content_set_hook(Elm_Object_Item *it,
968 Evas_Object *content)
971 Elm_Ctxpopup_Item *ctxpopup_it;
973 if (part && strcmp(part, "icon")) return;
975 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
977 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
980 _item_icon_set(ctxpopup_it, content);
981 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
985 _scroller_size_reset(wd);
986 _sizing_eval(WIDGET(ctxpopup_it));
991 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
993 Elm_Ctxpopup_Item *ctxpopup_it;
994 if (part && strcmp(part, "icon")) return NULL;
995 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
996 return ctxpopup_it->icon;
1000 _item_disable_hook(Elm_Object_Item *it)
1003 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1005 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1008 if (elm_widget_item_disabled_get(it))
1009 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
1011 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
1015 _item_signal_emit_hook(Elm_Object_Item *it, const char *emission,
1018 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1019 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
1023 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
1024 const char *emission __UNUSED__, const char *source __UNUSED__)
1026 evas_object_hide(data);
1030 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1031 void *event_info __UNUSED__)
1035 wd = elm_widget_data_get(obj);
1038 if ((!wd->items) && (!wd->content)) return;
1040 wd->visible = EINA_TRUE;
1042 evas_object_show(wd->bg);
1043 evas_object_show(wd->base);
1044 evas_object_show(wd->arrow);
1046 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
1047 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
1051 elm_object_focus_set(obj, EINA_TRUE);
1055 _hide_finished(void *data, Evas_Object *obj __UNUSED__,
1056 const char *emission __UNUSED__, const char *source __UNUSED__)
1062 _hide(Evas_Object *obj)
1064 Widget_Data *wd = elm_widget_data_get(obj);
1066 if ((!wd) || (!wd->visible)) return;
1068 evas_object_hide(wd->bg);
1069 evas_object_hide(wd->arrow);
1070 evas_object_hide(wd->base);
1072 _scroller_size_reset(wd);
1074 wd->visible = EINA_FALSE;
1075 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1079 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1080 void *event_info __UNUSED__)
1082 Widget_Data *wd = elm_widget_data_get(obj);
1084 _hide_signal_emit(obj, wd->dir);
1088 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1089 void *event_info __UNUSED__)
1091 Widget_Data *wd = elm_widget_data_get(data);
1093 elm_box_recalculate(wd->box);
1098 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1099 void *event_info __UNUSED__)
1104 wd = elm_widget_data_get(data);
1106 if (!wd->visible) return;
1107 if (wd->finished) return;
1109 evas_object_geometry_get(obj, 0, 0, &w, &h);
1111 if (w != 0 && h != 0)
1113 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1116 wd->finished = EINA_TRUE;
1121 if (wd->max_sc_w < w)
1123 if (wd->max_sc_h < h)
1130 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1131 void *event_info __UNUSED__)
1135 wd = elm_widget_data_get(obj);
1140 evas_object_show(wd->arrow);
1142 _scroller_size_reset(wd);
1147 _restack(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1149 Widget_Data *wd = elm_widget_data_get(obj);
1151 evas_object_layer_set(wd->bg,
1152 evas_object_layer_get(obj));
1153 evas_object_layer_set(wd->base,
1154 evas_object_layer_get(obj));
1158 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1159 const char *emission __UNUSED__, const char *source __UNUSED__)
1161 Elm_Ctxpopup_Item *item = data;
1164 if (elm_widget_item_disabled_get(item)) return;
1167 item->func((void*) item->base.data, WIDGET(item), data);
1171 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1174 evas_object_del(item->icon);
1179 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1180 edje_object_message_signal_process(VIEW(item));
1184 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1186 if (!eina_stringshare_replace(&item->label, label))
1189 edje_object_part_text_set(VIEW(item), "elm.text", label);
1190 edje_object_message_signal_process(VIEW(item));
1194 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1198 wd = elm_widget_data_get(WIDGET(item));
1201 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1202 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
1203 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1204 elm_widget_style_get(WIDGET(item)));
1205 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1206 _item_select_cb, item);
1207 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1208 evas_object_show(VIEW(item));
1212 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1213 void *event_info __UNUSED__)
1215 elm_object_content_unset(data);
1219 _list_del(Widget_Data *wd)
1221 if (!wd->scr) return;
1223 edje_object_part_unswallow(wd->base, wd->scr);
1224 evas_object_del(wd->scr);
1230 _list_new(Evas_Object *obj)
1233 wd = elm_widget_data_get(obj);
1237 wd->scr = elm_scroller_add(obj);
1238 elm_object_style_set(wd->scr, "ctxpopup");
1239 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1240 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1241 _scroller_resize, obj);
1242 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1245 wd->box = elm_box_add(obj);
1246 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1249 elm_object_content_set(wd->scr, wd->box);
1250 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1254 _remove_items(Widget_Data *wd)
1257 Elm_Ctxpopup_Item *item;
1259 if (!wd->items) return;
1261 EINA_LIST_FOREACH(wd->items, elist, item)
1264 eina_stringshare_del(item->label);
1266 evas_object_del(item->icon);
1267 wd->items = eina_list_remove(wd->items, item);
1268 elm_widget_item_free(item);
1275 _item_del_pre_hook(Elm_Object_Item *it)
1278 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1280 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1281 if (!wd) return EINA_FALSE;
1283 if (ctxpopup_it->icon)
1284 evas_object_del(ctxpopup_it->icon);
1285 if (VIEW(ctxpopup_it))
1286 evas_object_del(VIEW(ctxpopup_it));
1288 eina_stringshare_del(ctxpopup_it->label);
1290 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1292 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1294 if (eina_list_count(wd->items) < 1)
1296 evas_object_hide(WIDGET(ctxpopup_it));
1301 _sizing_eval(WIDGET(ctxpopup_it));
1307 elm_ctxpopup_add(Evas_Object *parent)
1313 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1315 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1316 elm_widget_type_set(obj, "ctxpopup");
1317 elm_widget_data_set(obj, wd);
1318 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1319 elm_widget_del_hook_set(obj, _del_hook);
1320 elm_widget_theme_hook_set(obj, _theme_hook);
1321 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1322 elm_widget_can_focus_set(obj, EINA_TRUE);
1323 elm_widget_event_hook_set(obj, _event_hook);
1324 elm_widget_content_set_hook_set(obj, _content_set_hook);
1325 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1326 elm_widget_content_get_hook_set(obj, _content_get_hook);
1329 wd->bg = edje_object_add(e);
1330 elm_widget_sub_object_add(obj, wd->bg);
1331 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1332 edje_object_signal_callback_add(wd->bg,
1338 wd->base = edje_object_add(e);
1339 elm_widget_sub_object_add(obj, wd->base);
1340 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1341 edje_object_signal_callback_add(wd->base, "elm,action,hide,finished", "",
1342 _hide_finished, obj);
1345 wd->arrow = edje_object_add(e);
1346 elm_widget_sub_object_add(obj, wd->arrow);
1347 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1349 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1350 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1351 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1352 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1353 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1355 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1357 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1359 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1361 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESTACK, _restack, obj);
1362 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1363 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1364 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1365 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1367 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1369 //default parent is to be hover parent
1370 elm_ctxpopup_hover_parent_set(obj, parent);
1376 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1378 return _item_content_get_hook(it, "icon");
1382 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1384 _item_content_set_hook(it, "icon", icon);
1388 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1390 return _item_text_get_hook(it, NULL);
1394 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1396 _item_text_set_hook(it, NULL, label);
1400 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1402 ELM_CHECK_WIDTYPE(obj, widtype);
1405 Evas_Coord x, y, w, h;
1407 wd = elm_widget_data_get(obj);
1408 if ((!wd) || (!parent)) return;
1410 _parent_cut_off(obj);
1414 evas_object_event_callback_add(parent,
1418 evas_object_event_callback_add(parent,
1422 evas_object_event_callback_add(parent,
1423 EVAS_CALLBACK_RESIZE,
1428 elm_widget_sub_object_add(parent, obj);
1429 wd->parent = parent;
1432 evas_object_geometry_get(parent, &x, &y, &w, &h);
1433 evas_object_move(wd->bg, x, y);
1434 evas_object_resize(wd->bg, w, h);
1436 if (wd->visible) _sizing_eval(obj);
1440 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1442 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1446 wd = elm_widget_data_get(obj);
1447 if (!wd) return NULL;
1453 elm_ctxpopup_clear(Evas_Object * obj)
1455 ELM_CHECK_WIDTYPE(obj, widtype);
1457 Widget_Data *wd = elm_widget_data_get(obj);
1462 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1466 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1468 ELM_CHECK_WIDTYPE(obj, widtype);
1472 wd = elm_widget_data_get(obj);
1475 wd->horizontal = !!horizontal;
1477 if ((!wd->scr) && (!wd->box))
1482 elm_box_horizontal_set(wd->box, EINA_FALSE);
1483 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1487 elm_box_horizontal_set(wd->box, EINA_TRUE);
1488 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1491 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1498 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1500 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1504 wd = elm_widget_data_get(obj);
1505 if (!wd) return EINA_FALSE;
1507 return wd->horizontal;
1510 EAPI Elm_Object_Item *
1511 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1512 Evas_Object *icon, Evas_Smart_Cb func,
1515 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1518 Evas_Object *content;
1519 Elm_Ctxpopup_Item *item;
1521 wd = elm_widget_data_get(obj);
1522 if (!wd) return NULL;
1524 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1525 if (!item) return NULL;
1527 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1528 elm_widget_item_disable_hook_set(item, _item_disable_hook);
1529 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1530 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1531 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1532 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1533 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1535 //The first item is appended.
1536 content = elm_object_content_unset(obj);
1537 if (content) evas_object_del(content);
1543 item->base.data = data;
1546 _item_new(item, "icon_text_style_item");
1548 _item_new(item, "text_style_item");
1550 _item_new(item, "icon_style_item");
1552 _item_icon_set(item, icon);
1553 _item_label_set(item, label);
1554 elm_box_pack_end(wd->box, VIEW(item));
1555 wd->items = eina_list_append(wd->items, item);
1556 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1560 _scroller_size_reset(wd);
1564 return (Elm_Object_Item *) item;
1568 elm_ctxpopup_item_del(Elm_Object_Item *it)
1570 elm_object_item_del(it);
1574 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1576 elm_object_item_disabled_set(it, disabled);
1580 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1582 return elm_object_item_disabled_get(it);
1586 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1588 elm_object_content_set(obj, content);
1592 elm_ctxpopup_content_unset(Evas_Object *obj)
1594 return elm_object_content_unset(obj);
1598 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1599 Elm_Ctxpopup_Direction first,
1600 Elm_Ctxpopup_Direction second,
1601 Elm_Ctxpopup_Direction third,
1602 Elm_Ctxpopup_Direction fourth)
1604 ELM_CHECK_WIDTYPE(obj, widtype);
1607 wd = elm_widget_data_get(obj);
1610 wd->dir_priority[0] = first;
1611 wd->dir_priority[1] = second;
1612 wd->dir_priority[2] = third;
1613 wd->dir_priority[3] = fourth;
1620 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1621 Elm_Ctxpopup_Direction *first,
1622 Elm_Ctxpopup_Direction *second,
1623 Elm_Ctxpopup_Direction *third,
1624 Elm_Ctxpopup_Direction *fourth)
1626 ELM_CHECK_WIDTYPE(obj, widtype);
1629 wd = elm_widget_data_get(obj);
1632 if (first) *first = wd->dir_priority[0];
1633 if (second) *second = wd->dir_priority[1];
1634 if (third) *third = wd->dir_priority[2];
1635 if (fourth) *fourth = wd->dir_priority[3];
1638 EAPI Elm_Ctxpopup_Direction
1639 elm_ctxpopup_direction_get(const Evas_Object *obj)
1641 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1644 wd = elm_widget_data_get(obj);
1645 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;