1 #include <Elementary.h>
3 #include "els_scroller.h"
5 #undef Elm_Ctxpopup_Item
7 typedef struct _Widget_Data Widget_Data;
8 typedef struct _Elm_Ctxpopup_Item Elm_Ctxpopup_Item;
10 struct _Elm_Ctxpopup_Item
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 _parent_cut_off(Evas_Object *obj);
44 static void _parent_resize(void *data,
48 static void _parent_move(void *data,
52 static void _parent_del(void *data,
56 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
57 static void _adjust_pos_x(Evas_Coord_Point *pos,
58 Evas_Coord_Point *base_size,
59 Evas_Coord_Rectangle *hover_area);
60 static void _adjust_pos_y(Evas_Coord_Point *pos,
61 Evas_Coord_Point *base_size,
62 Evas_Coord_Rectangle *hover_area);
63 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
64 Evas *e __UNUSED__, Evas_Object *obj,
65 void *event_info __UNUSED__);
66 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
67 Evas_Coord_Rectangle *rect);
68 static void _update_arrow(Evas_Object *obj,
69 Elm_Ctxpopup_Direction dir,
70 Evas_Coord_Rectangle rect);
71 static void _sizing_eval(Evas_Object *obj);
72 static void _shift_base_by_arrow(Evas_Object *arrow,
73 Elm_Ctxpopup_Direction dir,
74 Evas_Coord_Rectangle *rect);
75 static void _del_pre_hook(Evas_Object *obj);
76 static void _del_hook(Evas_Object *obj);
77 static void _theme_hook(Evas_Object *obj);
78 static void _content_set_hook(Evas_Object *obj,
79 const char *item __UNUSED__,
80 Evas_Object *content);
81 static Evas_Object * _content_unset_hook(Evas_Object *obj,
82 const char *item __UNUSED__);
83 static Evas_Object * _content_get_hook(const Evas_Object *obj,
85 static void _item_text_set_hook(Elm_Object_Item *it,
88 static const char * _item_text_get_hook(const Elm_Object_Item *it,
90 static void _item_content_set_hook(Elm_Object_Item *it,
92 Evas_Object *content);
93 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
95 static void _item_disable_set_hook(Elm_Object_Item *it);
96 static void _item_signal_emit_hook(Elm_Object_Item *it,
99 static void _bg_clicked_cb(void *data, Evas_Object *obj,
100 const char *emission,
102 static void _ctxpopup_show(void *data,
106 static void _hide(Evas_Object *obj);
107 static void _ctxpopup_hide(void *data,
111 static void _content_resize(void *data,
115 static void _scroller_resize(void *data,
119 static void _ctxpopup_move(void *data,
123 static void _item_select_cb(void *data, Evas_Object *obj,
124 const char *emission,
126 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
127 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
128 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
129 static void _content_del(void *data,
133 static void _list_del(Widget_Data *wd);
134 static void _list_new(Evas_Object *obj);
135 static void _remove_items(Widget_Data * wd);
137 static const char SIG_DISMISSED[] = "dismissed";
139 static const Evas_Smart_Cb_Description _signals[] = {
144 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
145 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
146 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
149 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
150 void *event_info __UNUSED__)
152 Widget_Data *wd = elm_widget_data_get(obj);
154 if ((!wd) || (!wd->scr)) return;
155 elm_smart_scroller_freeze_set(wd->scr, EINA_TRUE);
159 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
160 void *event_info __UNUSED__)
162 Widget_Data *wd = elm_widget_data_get(obj);
164 if ((!wd) || (!wd->scr)) return;
165 elm_smart_scroller_freeze_set(wd->scr, EINA_FALSE);
169 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
171 Widget_Data *wd = elm_widget_data_get(obj);
173 if ((!wd) || (!wd->scr)) return;
174 elm_object_scroll_hold_push(wd->scr);
178 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
180 Widget_Data *wd = elm_widget_data_get(obj);
182 if ((!wd) || (!wd->scr)) return;
183 elm_object_scroll_hold_pop(wd->scr);
187 _scroller_size_reset(Widget_Data *wd)
189 wd->finished = EINA_FALSE;
195 _parent_cut_off(Evas_Object *obj)
197 Widget_Data *wd = elm_widget_data_get(obj);
201 evas_object_event_callback_del_full(wd->parent,
205 evas_object_event_callback_del_full(wd->parent,
209 evas_object_event_callback_del_full(wd->parent,
210 EVAS_CALLBACK_RESIZE,
214 elm_widget_sub_object_del(wd->parent, obj);
218 _parent_resize(void *data,
220 Evas_Object *obj __UNUSED__,
221 void *event_info __UNUSED__)
223 Widget_Data *wd = elm_widget_data_get(data);
226 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
232 _parent_move(void *data,
234 Evas_Object *obj __UNUSED__,
235 void *event_info __UNUSED__)
237 Widget_Data *wd = elm_widget_data_get(data);
241 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
245 _scroller_size_reset(wd);
251 _parent_del(void *data,
253 Evas_Object *obj __UNUSED__,
254 void *event_info __UNUSED__)
256 evas_object_del(data);
260 _item_sizing_eval(Elm_Ctxpopup_Item *item)
262 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
266 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
268 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
269 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
273 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
274 Evas_Coord_Rectangle *hover_area)
276 pos->x -= (base_size->x / 2);
278 if (pos->x < hover_area->x)
279 pos->x = hover_area->x;
280 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
281 pos->x = (hover_area->x + hover_area->w) - base_size->x;
283 if (base_size->x > hover_area->w)
284 base_size->x -= (base_size->x - hover_area->w);
286 if (pos->x < hover_area->x)
287 pos->x = hover_area->x;
291 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
292 Evas_Coord_Rectangle *hover_area)
294 pos->y -= (base_size->y / 2);
296 if (pos->y < hover_area->y)
297 pos->y = hover_area->y;
298 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
299 pos->y = hover_area->y + hover_area->h - base_size->y;
301 if (base_size->y > hover_area->h)
302 base_size->y -= (base_size->y - hover_area->h);
304 if (pos->y < hover_area->y)
305 pos->y = hover_area->y;
309 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
310 Evas_Object *obj, void *event_info __UNUSED__)
314 wd = elm_widget_data_get(obj);
321 static Elm_Ctxpopup_Direction
322 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
325 Evas_Coord_Point pos = {0, 0};
326 Evas_Coord_Point base_size;
327 Evas_Coord_Point max_size;
328 Evas_Coord_Point min_size;
329 Evas_Coord_Rectangle hover_area;
330 Evas_Coord_Point arrow_size;
331 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DOWN;
332 Evas_Coord_Point temp;
335 wd = elm_widget_data_get(obj);
337 if ((!wd) || (!rect))
338 return ELM_CTXPOPUP_DIRECTION_DOWN;
340 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
341 &arrow_size.x, &arrow_size.y);
342 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
344 //Initialize Area Rectangle.
345 evas_object_geometry_get(wd->parent,
351 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
354 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
355 evas_object_smart_calculate(wd->base);
358 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
360 if ((max_size.y > 0) && (base_size.y > max_size.y))
361 base_size.y = max_size.y;
363 if ((max_size.x > 0) && (base_size.x > max_size.x))
364 base_size.x = max_size.x;
367 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
369 if ((min_size.y > 0) && (base_size.y < min_size.y))
370 base_size.y = min_size.y;
372 if ((min_size.x > 0) && (base_size.x < min_size.x))
373 base_size.x = min_size.x;
375 //Check the Which direction is available.
376 //If find a avaialble direction, it adjusts position and size.
377 for (idx = 0; idx < 4; idx++)
379 switch (wd->dir_priority[idx])
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,
495 Evas_Coord_Rectangle base_size)
498 Evas_Coord_Rectangle arrow_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,
509 edje_object_part_unswallow(wd->base, wd->arrow);
513 case ELM_CTXPOPUP_DIRECTION_RIGHT:
514 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
515 edje_object_part_swallow(wd->base,
516 "elm.swallow.arrow_left",
519 // if user does not use dragable part
520 arrow_size.y = (y - (arrow_size.h * 0.5));
525 if (y < ((arrow_size.h * 0.5) + base_size.y))
527 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
528 y = base_size.h - arrow_size.h;
530 y = y - base_size.y - (arrow_size.h * 0.5);
531 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
532 edje_object_part_drag_value_set(wd->base,
533 "elm.swallow.arrow_left",
538 case ELM_CTXPOPUP_DIRECTION_LEFT:
539 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
540 edje_object_part_swallow(wd->base,
541 "elm.swallow.arrow_right",
544 // if user does not use dragable part
545 arrow_size.y = (y - (arrow_size.h * 0.5));
546 arrow_size.x = (x - arrow_size.w);
550 if (y < ((arrow_size.h * 0.5) + base_size.y))
552 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
553 y = base_size.h - arrow_size.h;
555 y = y - base_size.y - (arrow_size.h * 0.5);
556 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
557 edje_object_part_drag_value_set(wd->base,
558 "elm.swallow.arrow_right",
563 case ELM_CTXPOPUP_DIRECTION_DOWN:
564 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
565 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
567 // if user does not use dragable part
568 arrow_size.x = (x - (arrow_size.w * 0.5));
573 if (x < ((arrow_size.w * 0.5) + base_size.x))
575 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
576 x = base_size.w - arrow_size.w;
578 x = x - base_size.x - (arrow_size.w * 0.5);
579 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
580 edje_object_part_drag_value_set(wd->base,
581 "elm.swallow.arrow_up",
586 case ELM_CTXPOPUP_DIRECTION_UP:
587 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
588 edje_object_part_swallow(wd->base,
589 "elm.swallow.arrow_down",
592 // if user does not use dragable part
593 arrow_size.x = (x - (arrow_size.w * 0.5));
594 arrow_size.y = (y - arrow_size.h);
598 if (x < ((arrow_size.w * 0.5) + base_size.x))
600 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
601 x = base_size.w - arrow_size.w;
602 else x = x - base_size.x - (arrow_size.w * 0.5);
603 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
604 edje_object_part_drag_value_set(wd->base,
605 "elm.swallow.arrow_down",
614 // if user does not use dragable part
615 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
618 //TODO: compress item - different from opensource
620 _compress_item(Evas_Object *obj)
624 Elm_Ctxpopup_Item *item;
626 wd = elm_widget_data_get(obj);
629 EINA_LIST_FOREACH(wd->items, elist, item)
631 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
636 _sizing_eval(Evas_Object *obj)
640 Elm_Ctxpopup_Item *item;
641 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
642 Evas_Coord_Point box_size = { 0, 0 };
643 Evas_Coord_Point _box_size = { 0, 0 };
645 wd = elm_widget_data_get(obj);
647 if (!wd->parent) return;
650 EINA_LIST_FOREACH(wd->items, elist, item)
652 _item_sizing_eval(item);
653 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
656 if (_box_size.x > box_size.x)
657 box_size.x = _box_size.x;
658 if (_box_size.y != -1)
659 box_size.y += _box_size.y;
663 if (_box_size.x != -1)
664 box_size.x += _box_size.x;
665 if (_box_size.y > box_size.y)
666 box_size.y = _box_size.y;
672 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
673 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
677 wd->dir = _calc_base_geometry(obj, &rect);
679 //TODO: compress item - different from opensource
680 if (!wd->horizontal && !wd->content)
683 _update_arrow(obj, wd->dir, rect);
684 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
686 //resize scroller according to final size.
688 evas_object_smart_calculate(wd->scr);
690 evas_object_move(wd->base, rect.x, rect.y);
691 evas_object_resize(wd->base, rect.w, rect.h);
695 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
696 Evas_Coord_Rectangle *rect)
698 Evas_Coord arrow_w, arrow_h;
700 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
704 case ELM_CTXPOPUP_DIRECTION_RIGHT:
707 case ELM_CTXPOPUP_DIRECTION_LEFT:
710 case ELM_CTXPOPUP_DIRECTION_DOWN:
713 case ELM_CTXPOPUP_DIRECTION_UP:
722 _del_pre_hook(Evas_Object *obj)
726 wd = elm_widget_data_get(obj);
729 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
730 _parent_resize, obj);
731 evas_object_event_callback_del_full(wd->box, EVAS_CALLBACK_RESIZE,
732 _content_resize, obj);
734 _parent_cut_off(obj);
738 _del_hook(Evas_Object *obj)
742 wd = elm_widget_data_get(obj);
745 elm_ctxpopup_clear(obj);
746 evas_object_del(wd->arrow);
747 evas_object_del(wd->base);
751 //FIXME: lost the content size when theme hook is called.
753 _theme_hook(Evas_Object *obj)
757 Elm_Ctxpopup_Item *item;
760 wd = elm_widget_data_get(obj);
764 EINA_LIST_FOREACH(wd->items, elist, item)
766 if (item->label && item->icon)
767 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
768 "icon_text_style_item",
769 elm_widget_style_get(obj));
770 else if (item->label)
771 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
772 elm_widget_style_get(obj));
774 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
775 elm_widget_style_get(obj));
777 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
779 if (elm_widget_item_disabled_get(item))
780 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
783 * For separator, if the first item has visible separator,
784 * then it should be aligned with edge of the base part.
785 * In some cases, it gives improper display. Ex) rounded corner
786 * So the first item separator should be invisible.
789 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
793 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
795 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
798 edje_object_message_signal_process(VIEW(item));
801 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
802 elm_widget_style_get(obj));
803 if (evas_object_visible_get(wd->bg))
804 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
806 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
807 elm_widget_style_get(obj));
808 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
809 elm_widget_style_get(obj));
813 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
814 elm_object_style_set(wd->scr, "ctxpopup");
816 elm_object_style_set(wd->scr, elm_object_style_get(obj));
821 _scroller_size_reset(wd);
827 _content_set_hook(Evas_Object *obj, const char *part,
828 Evas_Object *content)
830 ELM_CHECK_WIDTYPE(obj, widtype);
831 Evas_Coord min_w = -1, min_h = -1;
835 if (part && strcmp(part, "default")) return;
837 wd = elm_widget_data_get(obj);
838 if ((!wd) || (!content)) return;
840 if (wd->items) elm_ctxpopup_clear(obj);
841 if (wd->content) evas_object_del(wd->content);
844 wd->box = elm_box_add(obj);
845 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
847 evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
849 evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
851 evas_object_show(content);
852 evas_object_size_hint_min_get(content, &min_w, &min_h);
853 evas_object_size_hint_min_set(wd->box, min_w, min_h);
854 elm_box_pack_end(wd->box, content);
856 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
857 _content_resize, obj);
858 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
861 elm_widget_sub_object_add(obj, wd->box);
862 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
864 wd->content = content;
865 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
872 _content_unset_hook(Evas_Object *obj, const char *part)
874 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
877 Evas_Object *content;
878 if (part && strcmp(part, "default")) return NULL;
879 wd = elm_widget_data_get(obj);
880 if (!wd) return NULL;
882 content = wd->content;
883 if (!content || !wd->box) return NULL;
885 edje_object_part_unswallow(wd->base, wd->box);
886 elm_widget_sub_object_del(obj, wd->box);
887 evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
888 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
890 evas_object_del(wd->box);
893 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
899 _content_get_hook(const Evas_Object *obj, const char *part)
901 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
903 if (part && strcmp(part, "default")) return NULL;
904 wd = elm_widget_data_get(obj);
905 if (!wd) return NULL;
910 _item_text_set_hook(Elm_Object_Item *it,
914 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
917 Elm_Ctxpopup_Item *ctxpopup_it;
919 if (part && strcmp(part, "default")) return;
921 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
923 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
926 _item_label_set(ctxpopup_it, label);
927 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
931 _scroller_size_reset(wd);
932 _sizing_eval(WIDGET(ctxpopup_it));
937 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
939 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
940 Elm_Ctxpopup_Item *ctxpopup_it;
941 if (part && strcmp(part, "default")) return NULL;
942 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
943 return ctxpopup_it->label;
947 _item_content_set_hook(Elm_Object_Item *it,
949 Evas_Object *content)
951 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
953 Elm_Ctxpopup_Item *ctxpopup_it;
955 if (part && strcmp(part, "icon")) return;
957 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
959 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
962 _item_icon_set(ctxpopup_it, content);
963 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
967 _scroller_size_reset(wd);
968 _sizing_eval(WIDGET(ctxpopup_it));
973 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
975 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
976 Elm_Ctxpopup_Item *ctxpopup_it;
977 if (part && strcmp(part, "icon")) return NULL;
978 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
979 return ctxpopup_it->icon;
983 _item_disable_set_hook(Elm_Object_Item *it)
985 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
988 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
990 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
993 if (elm_widget_item_disabled_get(it))
994 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
996 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
1000 _item_signal_emit_hook(Elm_Object_Item *it,
1001 const char *emission,
1004 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1005 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1006 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
1010 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
1011 const char *emission __UNUSED__, const char *source __UNUSED__)
1013 evas_object_hide(data);
1017 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1018 void *event_info __UNUSED__)
1022 Elm_Ctxpopup_Item *item;
1025 wd = elm_widget_data_get(obj);
1028 if ((!wd->items) && (!wd->content)) return;
1030 wd->visible = EINA_TRUE;
1032 evas_object_show(wd->bg);
1033 evas_object_show(wd->base);
1034 evas_object_show(wd->arrow);
1036 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
1038 EINA_LIST_FOREACH(wd->items, elist, item)
1041 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1045 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1047 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1055 _hide(Evas_Object *obj)
1057 Widget_Data *wd = elm_widget_data_get(obj);
1061 evas_object_hide(wd->bg);
1062 evas_object_hide(wd->arrow);
1063 evas_object_hide(wd->base);
1065 _scroller_size_reset(wd);
1067 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1068 wd->visible = EINA_FALSE;
1072 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1073 void *event_info __UNUSED__)
1077 wd = elm_widget_data_get(obj);
1078 if ((!wd) || (!wd->visible))
1085 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1086 void *event_info __UNUSED__)
1088 Widget_Data *wd = elm_widget_data_get(data);
1090 elm_box_recalculate(wd->box);
1095 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1096 void *event_info __UNUSED__)
1101 wd = elm_widget_data_get(data);
1103 if (!wd->visible) return;
1104 if (wd->finished) return;
1106 evas_object_geometry_get(obj, 0, 0, &w, &h);
1108 if (w != 0 && h != 0)
1110 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1113 wd->finished = EINA_TRUE;
1118 if (wd->max_sc_w < w)
1120 if (wd->max_sc_h < h)
1127 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1128 void *event_info __UNUSED__)
1132 wd = elm_widget_data_get(obj);
1137 evas_object_show(wd->arrow);
1139 _scroller_size_reset(wd);
1144 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1145 const char *emission __UNUSED__, const char *source __UNUSED__)
1147 Elm_Ctxpopup_Item *item = data;
1150 if (elm_widget_item_disabled_get(item)) return;
1153 item->func((void*) item->base.data, WIDGET(item), data);
1157 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1161 elm_widget_sub_object_del(VIEW(item), item->icon);
1162 evas_object_del(item->icon);
1168 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1169 edje_object_message_signal_process(VIEW(item));
1173 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1175 if (!eina_stringshare_replace(&item->label, label))
1178 edje_object_part_text_set(VIEW(item), "elm.text", label);
1179 edje_object_message_signal_process(VIEW(item));
1183 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1187 wd = elm_widget_data_get(WIDGET(item));
1190 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1191 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1192 elm_widget_style_get(WIDGET(item)));
1193 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1194 _item_select_cb, item);
1195 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1196 evas_object_show(VIEW(item));
1200 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1201 void *event_info __UNUSED__)
1203 elm_object_content_unset(data);
1207 _list_del(Widget_Data *wd)
1209 if (!wd->scr) return;
1211 edje_object_part_unswallow(wd->base, wd->scr);
1212 evas_object_del(wd->scr);
1218 _list_new(Evas_Object *obj)
1221 wd = elm_widget_data_get(obj);
1225 wd->scr = elm_scroller_add(obj);
1226 elm_object_style_set(wd->scr, "ctxpopup");
1227 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1228 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1229 _scroller_resize, obj);
1230 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1233 wd->box = elm_box_add(obj);
1234 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1237 elm_object_content_set(wd->scr, wd->box);
1238 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1242 _remove_items(Widget_Data *wd)
1245 Elm_Ctxpopup_Item *item;
1247 if (!wd->items) return;
1249 EINA_LIST_FOREACH(wd->items, elist, item)
1252 eina_stringshare_del(item->label);
1254 evas_object_del(item->icon);
1255 wd->items = eina_list_remove(wd->items, item);
1263 elm_ctxpopup_add(Evas_Object *parent)
1268 Evas_Coord x, y, w, h;
1270 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1272 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1273 elm_widget_type_set(obj, "ctxpopup");
1274 elm_widget_sub_object_add(parent, obj);
1275 elm_widget_data_set(obj, wd);
1276 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1277 elm_widget_del_hook_set(obj, _del_hook);
1278 elm_widget_theme_hook_set(obj, _theme_hook);
1279 elm_widget_content_set_hook_set(obj, _content_set_hook);
1280 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1281 elm_widget_content_get_hook_set(obj, _content_get_hook);
1284 wd->bg = edje_object_add(e);
1285 elm_widget_sub_object_add(obj, wd->bg);
1286 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1287 evas_object_geometry_get(parent, &x, &y, &w, &h);
1288 evas_object_move(wd->bg, x, y);
1289 evas_object_resize(wd->bg, w, h);
1290 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1291 _bg_clicked_cb, obj);
1294 wd->base = edje_object_add(e);
1295 elm_widget_sub_object_add(obj, wd->base);
1296 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1299 wd->arrow = edje_object_add(e);
1300 elm_widget_sub_object_add(obj, wd->arrow);
1301 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1303 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1304 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1305 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1306 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1308 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1310 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1312 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1314 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1316 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1317 _ctxpopup_changed_size_hints, NULL);
1318 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1319 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1320 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1321 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1323 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1325 //default parent is to be hover parent
1326 elm_ctxpopup_hover_parent_set(obj, parent);
1332 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1334 return _item_content_get_hook(it, "icon");
1338 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1340 _item_content_set_hook(it, "icon", icon);
1344 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1346 return _item_text_get_hook(it, NULL);
1350 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1352 _item_text_set_hook(it, NULL, label);
1356 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1358 ELM_CHECK_WIDTYPE(obj, widtype);
1361 Evas_Coord x, y, w, h;
1363 wd = elm_widget_data_get(obj);
1366 _parent_cut_off(obj);
1370 evas_object_event_callback_add(parent,
1374 evas_object_event_callback_add(parent,
1378 evas_object_event_callback_add(parent,
1379 EVAS_CALLBACK_RESIZE,
1384 elm_widget_sub_object_add(parent, obj);
1385 wd->parent = parent;
1388 evas_object_geometry_get(parent, &x, &y, &w, &h);
1389 evas_object_move(wd->bg, x, y);
1390 evas_object_resize(wd->bg, w, h);
1392 if (wd->visible) _sizing_eval(obj);
1396 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1398 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1402 wd = elm_widget_data_get(obj);
1403 if (!wd) return NULL;
1409 elm_ctxpopup_clear(Evas_Object * obj)
1411 ELM_CHECK_WIDTYPE(obj, widtype);
1413 Widget_Data *wd = elm_widget_data_get(obj);
1421 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1423 ELM_CHECK_WIDTYPE(obj, widtype);
1427 Elm_Ctxpopup_Item *item;
1430 wd = elm_widget_data_get(obj);
1433 wd->horizontal = !!horizontal;
1435 if ((!wd->scr) && (!wd->box))
1440 elm_box_horizontal_set(wd->box, EINA_FALSE);
1441 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1443 EINA_LIST_FOREACH(wd->items, elist, item)
1446 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1448 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1453 elm_box_horizontal_set(wd->box, EINA_TRUE);
1454 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1456 EINA_LIST_FOREACH(wd->items, elist, item)
1459 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1461 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1470 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1472 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1476 wd = elm_widget_data_get(obj);
1477 if (!wd) return EINA_FALSE;
1479 return wd->horizontal;
1482 EAPI Elm_Object_Item *
1483 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1484 Evas_Object *icon, Evas_Smart_Cb func,
1487 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1490 Elm_Ctxpopup_Item *item;
1492 wd = elm_widget_data_get(obj);
1493 if (!wd) return NULL;
1495 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1496 if (!item) return NULL;
1498 elm_widget_item_disable_set_hook_set(item, _item_disable_set_hook);
1499 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1500 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1501 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1502 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1503 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1505 //The first item is appended.
1507 evas_object_del(elm_object_content_unset(obj));
1513 item->base.data = data;
1516 _item_new(item, "icon_text_style_item");
1518 _item_new(item, "text_style_item");
1520 _item_new(item, "icon_style_item");
1522 _item_icon_set(item, icon);
1523 _item_label_set(item, label);
1524 elm_box_pack_end(wd->box, VIEW(item));
1525 wd->items = eina_list_append(wd->items, item);
1529 _scroller_size_reset(wd);
1533 return (Elm_Object_Item *) item;
1537 elm_ctxpopup_item_del(Elm_Object_Item *it)
1539 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1542 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1544 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1547 if (ctxpopup_it->icon)
1548 evas_object_del(ctxpopup_it->icon);
1549 if (VIEW(ctxpopup_it))
1550 evas_object_del(VIEW(ctxpopup_it));
1552 eina_stringshare_del(ctxpopup_it->label);
1554 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1556 if (eina_list_count(wd->items) < 1)
1560 _sizing_eval(WIDGET(ctxpopup_it));
1566 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1568 elm_object_item_disabled_set(it, disabled);
1572 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1574 return elm_object_item_disabled_get(it);
1578 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1580 elm_object_content_set(obj, content);
1584 elm_ctxpopup_content_unset(Evas_Object *obj)
1586 return elm_object_content_unset(obj);
1590 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1591 Elm_Ctxpopup_Direction first,
1592 Elm_Ctxpopup_Direction second,
1593 Elm_Ctxpopup_Direction third,
1594 Elm_Ctxpopup_Direction fourth)
1596 ELM_CHECK_WIDTYPE(obj, widtype);
1599 wd = elm_widget_data_get(obj);
1602 wd->dir_priority[0] = first;
1603 wd->dir_priority[1] = second;
1604 wd->dir_priority[2] = third;
1605 wd->dir_priority[3] = fourth;
1612 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1613 Elm_Ctxpopup_Direction *first,
1614 Elm_Ctxpopup_Direction *second,
1615 Elm_Ctxpopup_Direction *third,
1616 Elm_Ctxpopup_Direction *fourth)
1618 ELM_CHECK_WIDTYPE(obj, widtype);
1621 wd = elm_widget_data_get(obj);
1624 if (first) *first = wd->dir_priority[0];
1625 if (second) *second = wd->dir_priority[1];
1626 if (third) *third = wd->dir_priority[2];
1627 if (fourth) *fourth = wd->dir_priority[3];
1630 EAPI Elm_Ctxpopup_Direction
1631 elm_ctxpopup_direction_get(const Evas_Object *obj)
1633 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1636 wd = elm_widget_data_get(obj);
1637 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;