1 #include <Elementary.h>
4 #undef Elm_Ctxpopup_Item
6 typedef struct _Widget_Data Widget_Data;
7 typedef struct _Elm_Ctxpopup_Item Elm_Ctxpopup_Item;
9 struct _Elm_Ctxpopup_Item
26 Evas_Object *hover_parent;
28 Elm_Ctxpopup_Direction dir;
29 Elm_Ctxpopup_Direction dir_priority[4];
30 Evas_Coord max_sc_w, max_sc_h;
31 Eina_Bool horizontal:1;
36 static const char *widtype = NULL;
38 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
39 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
40 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
41 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
42 static void _scroller_size_reset(Widget_Data *wd);
43 static void _hover_parent_callbacks_del(Evas_Object *obj);
44 static void _parent_resize(void *data,
48 static void _hover_parent_resize(void *data, Evas *e __UNUSED__,
49 Evas_Object *obj __UNUSED__,
50 void *event_info __UNUSED__);
51 static void _hover_parent_move(void *data, Evas *e __UNUSED__,
52 Evas_Object *obj __UNUSED__,
53 void *event_info __UNUSED__);
54 static void _hover_parent_del(void *data, Evas *e __UNUSED__,
55 Evas_Object *obj __UNUSED__,
56 void *event_info __UNUSED__);
57 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
58 static void _adjust_pos_x(Evas_Coord_Point *pos,
59 Evas_Coord_Point *base_size,
60 Evas_Coord_Rectangle *hover_area);
61 static void _adjust_pos_y(Evas_Coord_Point *pos,
62 Evas_Coord_Point *base_size,
63 Evas_Coord_Rectangle *hover_area);
64 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
65 Evas *e __UNUSED__, Evas_Object *obj,
66 void *event_info __UNUSED__);
67 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
68 Evas_Coord_Rectangle *rect);
69 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
70 static void _sizing_eval(Evas_Object *obj);
71 static void _shift_base_by_arrow(Evas_Object *arrow,
72 Elm_Ctxpopup_Direction dir,
73 Evas_Coord_Rectangle *rect);
74 static void _del_pre_hook(Evas_Object *obj);
75 static void _del_hook(Evas_Object *obj);
76 static void _theme_hook(Evas_Object *obj);
77 static void _content_set_hook(Evas_Object *obj,
78 const char *item __UNUSED__,
79 Evas_Object *content);
80 static Evas_Object * _content_unset_hook(Evas_Object *obj,
81 const char *item __UNUSED__);
82 static Evas_Object * _content_get_hook(const Evas_Object *obj,
84 static void _item_text_set_hook(Elm_Object_Item *it,
87 static const char * _item_text_get_hook(const Elm_Object_Item *it,
89 static void _item_content_set_hook(Elm_Object_Item *it,
91 Evas_Object *content);
92 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
94 static void _item_disable_set_hook(Elm_Object_Item *it);
95 static void _item_signal_emit_hook(Elm_Object_Item *it,
98 static void _bg_clicked_cb(void *data, Evas_Object *obj,
101 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
102 void *event_info __UNUSED__);
103 static void _ctxpopup_show(void *data,
107 static void _hide(Evas_Object *obj);
108 static void _ctxpopup_hide(void *data,
112 static void _scroller_resize(void *data,
116 static void _ctxpopup_move(void *data,
120 static void _item_select_cb(void *data, Evas_Object *obj,
121 const char *emission,
123 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
124 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
125 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
126 static void _content_del(void *data,
130 static void _list_del(Widget_Data *wd);
131 static void _list_new(Evas_Object *obj);
132 static void _remove_items(Widget_Data * wd);
134 static const char SIG_DISMISSED[] = "dismissed";
136 static const Evas_Smart_Cb_Description _signals[] = {
141 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
142 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
143 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
146 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
147 void *event_info __UNUSED__)
149 Widget_Data *wd = elm_widget_data_get(obj);
151 if ((!wd) || (!wd->scr)) return;
153 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
157 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
158 void *event_info __UNUSED__)
160 Widget_Data *wd = elm_widget_data_get(obj);
162 if ((!wd) || (!wd->scr)) return;
165 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
167 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
171 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
173 Widget_Data *wd = elm_widget_data_get(obj);
175 if ((!wd) || (!wd->scr)) return;
177 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
181 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
183 Widget_Data *wd = elm_widget_data_get(obj);
185 if ((!wd) || (!wd->scr)) return;
188 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
190 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
194 _scroller_size_reset(Widget_Data *wd)
196 wd->finished = EINA_FALSE;
202 _hover_parent_callbacks_del(Evas_Object *obj)
204 Widget_Data *wd = elm_widget_data_get(obj);
206 if ((!wd) || (!wd->hover_parent))
209 evas_object_event_callback_del_full(wd->hover_parent,
213 evas_object_event_callback_del_full(wd->hover_parent,
217 evas_object_event_callback_del_full(wd->hover_parent,
218 EVAS_CALLBACK_RESIZE,
219 _hover_parent_resize,
224 _hover_parent_resize(void *data,
226 Evas_Object *obj __UNUSED__,
227 void *event_info __UNUSED__)
229 Widget_Data *wd = elm_widget_data_get(data);
235 _scroller_size_reset(wd);
241 _hover_parent_move(void *data,
243 Evas_Object *obj __UNUSED__,
244 void *event_info __UNUSED__)
246 Widget_Data *wd = elm_widget_data_get(data);
252 _scroller_size_reset(wd);
258 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
259 void *event_info __UNUSED__)
261 Widget_Data *wd = elm_widget_data_get(data);
265 wd->hover_parent = NULL;
269 _item_sizing_eval(Elm_Ctxpopup_Item *item)
271 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
275 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
277 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
278 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
282 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
283 Evas_Coord_Rectangle *hover_area)
285 pos->x -= (base_size->x / 2);
287 if (pos->x < hover_area->x)
288 pos->x = hover_area->x;
289 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
290 pos->x = (hover_area->x + hover_area->w) - base_size->x;
292 if (base_size->x > hover_area->w)
293 base_size->x -= (base_size->x - hover_area->w);
295 if (pos->x < hover_area->x)
296 pos->x = hover_area->x;
300 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
301 Evas_Coord_Rectangle *hover_area)
303 pos->y -= (base_size->y / 2);
305 if (pos->y < hover_area->y)
306 pos->y = hover_area->y;
307 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
308 pos->y = hover_area->y + hover_area->h - base_size->y;
310 if (base_size->y > hover_area->h)
311 base_size->y -= (base_size->y - hover_area->h);
313 if (pos->y < hover_area->y)
314 pos->y = hover_area->y;
318 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
319 Evas_Object *obj, void *event_info __UNUSED__)
323 wd = elm_widget_data_get(obj);
330 static Elm_Ctxpopup_Direction
331 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
334 Evas_Coord_Point pos = {0, 0};
335 Evas_Coord_Point base_size;
336 Evas_Coord_Point max_size;
337 Evas_Coord_Point min_size;
338 Evas_Coord_Rectangle hover_area;
339 Evas_Coord_Rectangle parent_size;
340 Evas_Coord_Point arrow_size;
341 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DOWN;
342 Evas_Coord_Point temp;
345 wd = elm_widget_data_get(obj);
347 if ((!wd) || (!rect))
348 return ELM_CTXPOPUP_DIRECTION_DOWN;
350 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
351 &arrow_size.x, &arrow_size.y);
352 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
354 //Initialize Area Rectangle.
355 if (wd->hover_parent)
356 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
357 &hover_area.w, &hover_area.h);
360 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
361 &parent_size.w, &parent_size.h);
362 hover_area.x = parent_size.x;
363 hover_area.y = parent_size.y;
364 hover_area.w = parent_size.w;
365 hover_area.h = parent_size.h;
368 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
371 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
372 evas_object_smart_calculate(wd->base);
375 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
377 if ((max_size.y > 0) && (base_size.y > max_size.y))
378 base_size.y = max_size.y;
380 if ((max_size.x > 0) && (base_size.x > max_size.x))
381 base_size.x = max_size.x;
384 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
386 if ((min_size.y > 0) && (base_size.y < min_size.y))
387 base_size.y = min_size.y;
389 if ((min_size.x > 0) && (base_size.x < min_size.x))
390 base_size.x = min_size.x;
392 //Check the Which direction is available.
393 //If find a avaialble direction, it adjusts position and size.
394 for (idx = 0; idx < 4; idx++)
396 switch (wd->dir_priority[idx])
398 case ELM_CTXPOPUP_DIRECTION_UP:
399 temp.y = (pos.y - base_size.y);
400 if ((temp.y - arrow_size.y) < hover_area.y)
402 _adjust_pos_x(&pos, &base_size, &hover_area);
403 pos.y -= base_size.y;
404 dir = ELM_CTXPOPUP_DIRECTION_UP;
406 case ELM_CTXPOPUP_DIRECTION_LEFT:
407 temp.x = (pos.x - base_size.x);
408 if ((temp.x - arrow_size.x) < hover_area.x)
410 _adjust_pos_y(&pos, &base_size, &hover_area);
411 pos.x -= base_size.x;
412 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
414 case ELM_CTXPOPUP_DIRECTION_RIGHT:
415 temp.x = (pos.x + base_size.x);
416 if ((temp.x + arrow_size.x) >
417 (hover_area.x + hover_area.w))
419 _adjust_pos_y(&pos, &base_size, &hover_area);
420 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
422 case ELM_CTXPOPUP_DIRECTION_DOWN:
423 temp.y = (pos.y + base_size.y);
424 if ((temp.y + arrow_size.y) >
425 (hover_area.y + hover_area.h))
427 _adjust_pos_x(&pos, &base_size, &hover_area);
428 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
436 //In this case, all directions are invalid because of lack of space.
439 Evas_Coord length[2];
443 length[0] = pos.y - hover_area.y;
444 length[1] = (hover_area.y + hover_area.h) - pos.y;
446 // ELM_CTXPOPUP_DIRECTION_UP
447 if (length[0] > length[1])
449 _adjust_pos_x(&pos, &base_size, &hover_area);
450 pos.y -= base_size.y;
451 dir = ELM_CTXPOPUP_DIRECTION_UP;
452 if (pos.y < (hover_area.y + arrow_size.y))
454 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
455 pos.y = hover_area.y + arrow_size.y;
458 //ELM_CTXPOPUP_DIRECTION_DOWN
461 _adjust_pos_x(&pos, &base_size, &hover_area);
462 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
463 if ((pos.y + arrow_size.y + base_size.y) >
464 (hover_area.y + hover_area.h))
466 ((pos.y + arrow_size.y + base_size.y) -
467 (hover_area.y + hover_area.h));
472 length[0] = pos.x - hover_area.x;
473 length[1] = (hover_area.x + hover_area.w) - pos.x;
475 //ELM_CTXPOPUP_DIRECTION_LEFT
476 if (length[0] > length[1])
478 _adjust_pos_y(&pos, &base_size, &hover_area);
479 pos.x -= base_size.x;
480 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
481 if (pos.x < (hover_area.x + arrow_size.x))
483 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
484 pos.x = hover_area.x + arrow_size.x;
487 //ELM_CTXPOPUP_DIRECTION_RIGHT
490 _adjust_pos_y(&pos, &base_size, &hover_area);
491 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
492 if (pos.x + (arrow_size.x + base_size.x) >
493 hover_area.x + hover_area.w)
495 ((pos.x + arrow_size.x + base_size.x) -
496 (hover_area.x + hover_area.w));
501 //Final position and size.
504 rect->w = base_size.x;
505 rect->h = base_size.y;
511 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
514 Evas_Coord_Rectangle arrow_size;
515 Evas_Coord_Rectangle base_size;
519 wd = elm_widget_data_get(obj);
522 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
523 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
525 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
526 &base_size.w, &base_size.h);
528 edje_object_part_unswallow(wd->base, wd->arrow);
532 case ELM_CTXPOPUP_DIRECTION_RIGHT:
533 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
534 edje_object_part_swallow(wd->base,
535 "elm.swallow.arrow_left",
538 // if user does not use dragable part
539 arrow_size.y = (y - (arrow_size.h * 0.5));
544 if (y < ((arrow_size.h * 0.5) + base_size.y))
546 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
547 y = base_size.h - arrow_size.h;
549 y = y - base_size.y - (arrow_size.h * 0.5);
550 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
551 edje_object_part_drag_value_set(wd->base,
552 "elm.swallow.arrow_left",
557 case ELM_CTXPOPUP_DIRECTION_LEFT:
558 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
559 edje_object_part_swallow(wd->base,
560 "elm.swallow.arrow_right",
563 // if user does not use dragable part
564 arrow_size.y = (y - (arrow_size.h * 0.5));
565 arrow_size.x = (x - arrow_size.w);
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);
586 // if user does not use dragable part
587 arrow_size.x = (x - (arrow_size.w * 0.5));
592 if (x < ((arrow_size.w * 0.5) + base_size.x))
594 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
595 x = base_size.w - arrow_size.w;
597 x = x - base_size.x - (arrow_size.w * 0.5);
598 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
599 edje_object_part_drag_value_set(wd->base,
600 "elm.swallow.arrow_up",
605 case ELM_CTXPOPUP_DIRECTION_UP:
606 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
607 edje_object_part_swallow(wd->base,
608 "elm.swallow.arrow_down",
611 // if user does not use dragable part
612 arrow_size.x = (x - (arrow_size.w * 0.5));
613 arrow_size.y = (y - arrow_size.h);
617 if (x < ((arrow_size.w * 0.5) + base_size.x))
619 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
620 x = base_size.w - arrow_size.w;
621 else x = x - base_size.x - (arrow_size.w * 0.5);
622 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
623 edje_object_part_drag_value_set(wd->base,
624 "elm.swallow.arrow_down",
633 // if user does not use dragable part
634 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
637 //TODO: compress item - different from opensource
639 _compress_item(Evas_Object *obj)
643 Elm_Ctxpopup_Item *item;
645 wd = elm_widget_data_get(obj);
648 EINA_LIST_FOREACH(wd->items, elist, item)
650 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
655 _sizing_eval(Evas_Object *obj)
659 Elm_Ctxpopup_Item *item;
660 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
661 Evas_Coord_Point box_size = { 0, 0 };
662 Evas_Coord_Point _box_size = { 0, 0 };
664 wd = elm_widget_data_get(obj);
666 if (!wd->parent) return;
669 EINA_LIST_FOREACH(wd->items, elist, item)
671 _item_sizing_eval(item);
672 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
675 if (_box_size.x > box_size.x)
676 box_size.x = _box_size.x;
677 if (_box_size.y != -1)
678 box_size.y += _box_size.y;
682 if (_box_size.x != -1)
683 box_size.x += _box_size.x;
684 if (_box_size.y > box_size.y)
685 box_size.y = _box_size.y;
691 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
692 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
696 wd->dir = _calc_base_geometry(obj, &rect);
698 //TODO: compress item - different from opensource
699 if (!wd->horizontal && !wd->content)
702 _update_arrow(obj, wd->dir);
703 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
705 //resize scroller according to final size.
707 evas_object_smart_calculate(wd->scr);
709 evas_object_move(wd->base, rect.x, rect.y);
710 evas_object_resize(wd->base, rect.w, rect.h);
714 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
715 Evas_Coord_Rectangle *rect)
717 Evas_Coord arrow_w, arrow_h;
719 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
723 case ELM_CTXPOPUP_DIRECTION_RIGHT:
726 case ELM_CTXPOPUP_DIRECTION_LEFT:
729 case ELM_CTXPOPUP_DIRECTION_DOWN:
732 case ELM_CTXPOPUP_DIRECTION_UP:
741 _del_pre_hook(Evas_Object *obj)
745 wd = elm_widget_data_get(obj);
748 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
749 _parent_resize, obj);
751 _hover_parent_callbacks_del(obj);
755 _del_hook(Evas_Object *obj)
759 wd = elm_widget_data_get(obj);
762 elm_ctxpopup_clear(obj);
763 evas_object_del(wd->arrow);
764 evas_object_del(wd->base);
768 //FIXME: lost the content size when theme hook is called.
770 _theme_hook(Evas_Object *obj)
774 Elm_Ctxpopup_Item *item;
777 wd = elm_widget_data_get(obj);
781 EINA_LIST_FOREACH(wd->items, elist, item)
783 if (item->label && item->icon)
784 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
785 "icon_text_style_item",
786 elm_widget_style_get(obj));
787 else if (item->label)
788 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
789 elm_widget_style_get(obj));
791 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
792 elm_widget_style_get(obj));
794 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
796 if (elm_widget_item_disabled_get(item))
797 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
800 * For separator, if the first item has visible separator,
801 * then it should be aligned with edge of the base part.
802 * In some cases, it gives improper display. Ex) rounded corner
803 * So the first item separator should be invisible.
806 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
810 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
812 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
815 edje_object_message_signal_process(VIEW(item));
818 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
819 elm_widget_style_get(obj));
820 if (evas_object_visible_get(wd->bg))
821 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
823 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
824 elm_widget_style_get(obj));
825 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
826 elm_widget_style_get(obj));
830 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
831 elm_object_style_set(wd->scr, "ctxpopup");
833 elm_object_style_set(wd->scr, elm_object_style_get(obj));
838 _scroller_size_reset(wd);
844 _content_set_hook(Evas_Object *obj, const char *part,
845 Evas_Object *content)
847 ELM_CHECK_WIDTYPE(obj, widtype);
851 if (part && strcmp(part, "default")) return;
853 wd = elm_widget_data_get(obj);
854 if ((!wd) || (!content)) return;
856 if (wd->items) elm_ctxpopup_clear(obj);
857 if (wd->content) evas_object_del(wd->content);
859 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
862 elm_widget_sub_object_add(obj, content);
863 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
864 edje_object_message_signal_process(wd->base);
866 wd->content = content;
873 _content_unset_hook(Evas_Object *obj, const char *part)
875 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
878 Evas_Object *content;
879 if (part && strcmp(part, "default")) return NULL;
880 wd = elm_widget_data_get(obj);
881 if (!wd) return NULL;
883 content = wd->content;
884 if (!content) return NULL;
886 edje_object_part_unswallow(wd->base, content);
887 elm_widget_sub_object_del(obj, content);
888 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
889 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
898 _content_get_hook(const Evas_Object *obj, const char *part)
900 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
902 if (part && strcmp(part, "default")) return NULL;
903 wd = elm_widget_data_get(obj);
904 if (!wd) return NULL;
909 _item_text_set_hook(Elm_Object_Item *it,
913 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
916 Elm_Ctxpopup_Item *ctxpopup_it;
918 if (part && strcmp(part, "default")) return;
920 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
922 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
925 _item_label_set(ctxpopup_it, label);
926 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
930 _scroller_size_reset(wd);
931 _sizing_eval(WIDGET(ctxpopup_it));
936 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
938 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
939 Elm_Ctxpopup_Item *ctxpopup_it;
940 if (part && strcmp(part, "default")) return NULL;
941 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
942 return ctxpopup_it->label;
946 _item_content_set_hook(Elm_Object_Item *it,
948 Evas_Object *content)
950 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
952 Elm_Ctxpopup_Item *ctxpopup_it;
954 if (part && strcmp(part, "icon")) return;
956 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
958 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
961 _item_icon_set(ctxpopup_it, content);
962 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
966 _scroller_size_reset(wd);
967 _sizing_eval(WIDGET(ctxpopup_it));
972 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
974 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
975 Elm_Ctxpopup_Item *ctxpopup_it;
976 if (part && strcmp(part, "icon")) return NULL;
977 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
978 return ctxpopup_it->icon;
982 _item_disable_set_hook(Elm_Object_Item *it)
984 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
987 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
989 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
992 if (elm_widget_item_disabled_get(it))
993 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
995 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
999 _item_signal_emit_hook(Elm_Object_Item *it,
1000 const char *emission,
1003 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1004 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1005 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
1009 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
1010 const char *emission __UNUSED__, const char *source __UNUSED__)
1012 evas_object_hide(data);
1016 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1017 void *event_info __UNUSED__)
1022 wd = elm_widget_data_get(data);
1025 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
1026 evas_object_resize(wd->bg, w, h);
1028 if (!wd->visible) return;
1034 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1035 void *event_info __UNUSED__)
1039 Elm_Ctxpopup_Item *item;
1042 wd = elm_widget_data_get(obj);
1045 if ((!wd->items) && (!wd->content)) return;
1047 wd->visible = EINA_TRUE;
1049 evas_object_show(wd->bg);
1050 evas_object_show(wd->base);
1051 evas_object_show(wd->arrow);
1053 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
1055 EINA_LIST_FOREACH(wd->items, elist, item)
1058 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1062 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1064 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1072 _hide(Evas_Object *obj)
1074 Widget_Data *wd = elm_widget_data_get(obj);
1078 evas_object_hide(wd->bg);
1079 evas_object_hide(wd->arrow);
1080 evas_object_hide(wd->base);
1082 _scroller_size_reset(wd);
1084 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1085 wd->visible = EINA_FALSE;
1089 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1090 void *event_info __UNUSED__)
1094 wd = elm_widget_data_get(obj);
1095 if ((!wd) || (!wd->visible))
1102 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1103 void *event_info __UNUSED__)
1108 wd = elm_widget_data_get(data);
1110 if (!wd->visible) return;
1111 if (wd->finished) return;
1113 evas_object_geometry_get(obj, 0, 0, &w, &h);
1115 if (w != 0 && h != 0)
1117 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1120 wd->finished = EINA_TRUE;
1125 if (wd->max_sc_w < w)
1127 if (wd->max_sc_h < h)
1134 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1135 void *event_info __UNUSED__)
1139 wd = elm_widget_data_get(obj);
1144 evas_object_show(wd->arrow);
1146 _scroller_size_reset(wd);
1151 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1152 const char *emission __UNUSED__, const char *source __UNUSED__)
1154 Elm_Ctxpopup_Item *item = data;
1157 if (elm_widget_item_disabled_get(item)) return;
1160 item->func((void*) item->base.data, WIDGET(item), data);
1164 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1168 elm_widget_sub_object_del(VIEW(item), item->icon);
1169 evas_object_del(item->icon);
1175 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1176 edje_object_message_signal_process(VIEW(item));
1180 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1182 if (!eina_stringshare_replace(&item->label, label))
1185 edje_object_part_text_set(VIEW(item), "elm.text", label);
1186 edje_object_message_signal_process(VIEW(item));
1190 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1194 wd = elm_widget_data_get(WIDGET(item));
1197 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1198 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1199 elm_widget_style_get(WIDGET(item)));
1200 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1201 _item_select_cb, item);
1202 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1203 evas_object_show(VIEW(item));
1207 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1208 void *event_info __UNUSED__)
1210 elm_object_content_unset(data);
1214 _list_del(Widget_Data *wd)
1216 if (!wd->scr) return;
1218 edje_object_part_unswallow(wd->base, wd->scr);
1219 evas_object_del(wd->scr);
1225 _list_new(Evas_Object *obj)
1228 wd = elm_widget_data_get(obj);
1232 wd->scr = elm_scroller_add(obj);
1233 elm_object_style_set(wd->scr, "ctxpopup");
1234 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1235 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1236 _scroller_resize, obj);
1237 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1240 wd->box = elm_box_add(obj);
1241 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1244 elm_object_content_set(wd->scr, wd->box);
1245 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1249 _remove_items(Widget_Data *wd)
1252 Elm_Ctxpopup_Item *item;
1254 if (!wd->items) return;
1256 EINA_LIST_FOREACH(wd->items, elist, item)
1259 eina_stringshare_del(item->label);
1261 evas_object_del(item->icon);
1262 wd->items = eina_list_remove(wd->items, item);
1270 elm_ctxpopup_add(Evas_Object *parent)
1275 Evas_Coord x, y, w, h;
1277 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1279 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1280 elm_widget_type_set(obj, "ctxpopup");
1281 elm_widget_sub_object_add(parent, obj);
1282 elm_widget_data_set(obj, wd);
1283 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1284 elm_widget_del_hook_set(obj, _del_hook);
1285 elm_widget_theme_hook_set(obj, _theme_hook);
1286 elm_widget_content_set_hook_set(obj, _content_set_hook);
1287 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1288 elm_widget_content_get_hook_set(obj, _content_get_hook);
1290 wd->parent = parent;
1293 wd->bg = edje_object_add(e);
1294 elm_widget_sub_object_add(obj, wd->bg);
1295 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1296 evas_object_geometry_get(parent, &x, &y, &w, &h);
1297 evas_object_move(wd->bg, x, y);
1298 evas_object_resize(wd->bg, w, h);
1299 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1300 _bg_clicked_cb, obj);
1303 wd->base = edje_object_add(e);
1304 elm_widget_sub_object_add(obj, wd->base);
1305 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1308 wd->arrow = edje_object_add(e);
1309 elm_widget_sub_object_add(obj, wd->arrow);
1310 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1312 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1313 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1314 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1315 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1317 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1319 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1321 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1323 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1325 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1326 _ctxpopup_changed_size_hints, NULL);
1327 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1328 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1329 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1330 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1332 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1338 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1340 return _item_content_get_hook(it, "icon");
1344 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1346 _item_content_set_hook(it, "icon", icon);
1350 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1352 return _item_text_get_hook(it, NULL);
1356 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1358 _item_text_set_hook(it, NULL, label);
1362 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1364 ELM_CHECK_WIDTYPE(obj, widtype);
1368 wd = elm_widget_data_get(obj);
1371 _hover_parent_callbacks_del(obj);
1375 evas_object_event_callback_add(hover_parent,
1379 evas_object_event_callback_add(hover_parent,
1383 evas_object_event_callback_add(hover_parent,
1384 EVAS_CALLBACK_RESIZE,
1385 _hover_parent_resize,
1389 wd->hover_parent = hover_parent;
1393 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1395 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1399 wd = elm_widget_data_get(obj);
1400 if (!wd) return NULL;
1402 return wd->hover_parent;
1406 elm_ctxpopup_clear(Evas_Object * obj)
1408 ELM_CHECK_WIDTYPE(obj, widtype);
1410 Widget_Data *wd = elm_widget_data_get(obj);
1418 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1420 ELM_CHECK_WIDTYPE(obj, widtype);
1424 Elm_Ctxpopup_Item *item;
1427 wd = elm_widget_data_get(obj);
1430 wd->horizontal = !!horizontal;
1432 if ((!wd->scr) && (!wd->box))
1437 elm_box_horizontal_set(wd->box, EINA_FALSE);
1438 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1440 EINA_LIST_FOREACH(wd->items, elist, item)
1443 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1445 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1450 elm_box_horizontal_set(wd->box, EINA_TRUE);
1451 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1453 EINA_LIST_FOREACH(wd->items, elist, item)
1456 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1458 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1467 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1469 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1473 wd = elm_widget_data_get(obj);
1474 if (!wd) return EINA_FALSE;
1476 return wd->horizontal;
1479 EAPI Elm_Object_Item *
1480 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1481 Evas_Object *icon, Evas_Smart_Cb func,
1484 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1487 Elm_Ctxpopup_Item *item;
1489 wd = elm_widget_data_get(obj);
1490 if (!wd) return NULL;
1492 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1493 if (!item) return NULL;
1495 elm_widget_item_disable_set_hook_set(item, _item_disable_set_hook);
1496 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1497 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1498 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1499 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1500 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1502 //The first item is appended.
1504 evas_object_del(elm_object_content_unset(obj));
1510 item->base.data = data;
1513 _item_new(item, "icon_text_style_item");
1515 _item_new(item, "text_style_item");
1517 _item_new(item, "icon_style_item");
1519 _item_icon_set(item, icon);
1520 _item_label_set(item, label);
1521 elm_box_pack_end(wd->box, VIEW(item));
1522 wd->items = eina_list_append(wd->items, item);
1526 _scroller_size_reset(wd);
1530 return (Elm_Object_Item *) item;
1534 elm_ctxpopup_item_del(Elm_Object_Item *it)
1536 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1539 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1541 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1544 if (ctxpopup_it->icon)
1545 evas_object_del(ctxpopup_it->icon);
1546 if (VIEW(ctxpopup_it))
1547 evas_object_del(VIEW(ctxpopup_it));
1549 eina_stringshare_del(ctxpopup_it->label);
1551 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1553 if (eina_list_count(wd->items) < 1)
1557 _sizing_eval(WIDGET(ctxpopup_it));
1563 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1565 elm_object_item_disabled_set(it, disabled);
1569 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1571 return elm_object_item_disabled_get(it);
1575 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1577 elm_object_content_set(obj, content);
1581 elm_ctxpopup_content_unset(Evas_Object *obj)
1583 return elm_object_content_unset(obj);
1587 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1588 Elm_Ctxpopup_Direction first,
1589 Elm_Ctxpopup_Direction second,
1590 Elm_Ctxpopup_Direction third,
1591 Elm_Ctxpopup_Direction fourth)
1593 ELM_CHECK_WIDTYPE(obj, widtype);
1596 wd = elm_widget_data_get(obj);
1599 wd->dir_priority[0] = first;
1600 wd->dir_priority[1] = second;
1601 wd->dir_priority[2] = third;
1602 wd->dir_priority[3] = fourth;
1609 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1610 Elm_Ctxpopup_Direction *first,
1611 Elm_Ctxpopup_Direction *second,
1612 Elm_Ctxpopup_Direction *third,
1613 Elm_Ctxpopup_Direction *fourth)
1615 ELM_CHECK_WIDTYPE(obj, widtype);
1618 wd = elm_widget_data_get(obj);
1621 if (first) *first = wd->dir_priority[0];
1622 if (second) *second = wd->dir_priority[1];
1623 if (third) *third = wd->dir_priority[2];
1624 if (fourth) *fourth = wd->dir_priority[3];
1627 EAPI Elm_Ctxpopup_Direction
1628 elm_ctxpopup_direction_get(const Evas_Object *obj)
1630 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1633 wd = elm_widget_data_get(obj);
1634 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;