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
27 Elm_Ctxpopup_Direction dir;
28 Elm_Ctxpopup_Direction dir_priority[4];
29 Evas_Coord max_sc_w, max_sc_h;
30 Eina_Bool horizontal:1;
35 static const char *widtype = NULL;
37 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
38 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
39 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
40 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
41 static void _scroller_size_reset(Widget_Data *wd);
42 static void _parent_cut_off(Evas_Object *obj);
43 static void _parent_resize(void *data,
47 static void _parent_move(void *data,
51 static void _parent_del(void *data,
55 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
56 static void _adjust_pos_x(Evas_Coord_Point *pos,
57 Evas_Coord_Point *base_size,
58 Evas_Coord_Rectangle *hover_area);
59 static void _adjust_pos_y(Evas_Coord_Point *pos,
60 Evas_Coord_Point *base_size,
61 Evas_Coord_Rectangle *hover_area);
62 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
63 Evas *e __UNUSED__, Evas_Object *obj,
64 void *event_info __UNUSED__);
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 _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 _ctxpopup_show(void *data,
105 static void _hide(Evas_Object *obj);
106 static void _ctxpopup_hide(void *data,
110 static void _content_resize(void *data,
114 static void _scroller_resize(void *data,
118 static void _ctxpopup_move(void *data,
122 static void _item_select_cb(void *data, Evas_Object *obj,
123 const char *emission,
125 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
126 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
127 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
128 static void _content_del(void *data,
132 static void _list_del(Widget_Data *wd);
133 static void _list_new(Evas_Object *obj);
134 static void _remove_items(Widget_Data * wd);
136 static const char SIG_DISMISSED[] = "dismissed";
138 static const Evas_Smart_Cb_Description _signals[] = {
143 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
144 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
145 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
148 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
149 void *event_info __UNUSED__)
151 Widget_Data *wd = elm_widget_data_get(obj);
153 if ((!wd) || (!wd->scr)) return;
154 elm_smart_scroller_freeze_set(wd->scr, EINA_TRUE);
158 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
159 void *event_info __UNUSED__)
161 Widget_Data *wd = elm_widget_data_get(obj);
163 if ((!wd) || (!wd->scr)) return;
164 elm_smart_scroller_freeze_set(wd->scr, EINA_FALSE);
168 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
170 Widget_Data *wd = elm_widget_data_get(obj);
172 if ((!wd) || (!wd->scr)) return;
173 elm_object_scroll_hold_push(wd->scr);
177 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
179 Widget_Data *wd = elm_widget_data_get(obj);
181 if ((!wd) || (!wd->scr)) return;
182 elm_object_scroll_hold_pop(wd->scr);
186 _scroller_size_reset(Widget_Data *wd)
188 wd->finished = EINA_FALSE;
194 _parent_cut_off(Evas_Object *obj)
196 Widget_Data *wd = elm_widget_data_get(obj);
200 evas_object_event_callback_del_full(wd->parent,
204 evas_object_event_callback_del_full(wd->parent,
208 evas_object_event_callback_del_full(wd->parent,
209 EVAS_CALLBACK_RESIZE,
213 elm_widget_sub_object_del(wd->parent, obj);
217 _parent_resize(void *data,
219 Evas_Object *obj __UNUSED__,
220 void *event_info __UNUSED__)
222 Widget_Data *wd = elm_widget_data_get(data);
225 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
231 _parent_move(void *data,
233 Evas_Object *obj __UNUSED__,
234 void *event_info __UNUSED__)
236 Widget_Data *wd = elm_widget_data_get(data);
240 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
244 _scroller_size_reset(wd);
250 _parent_del(void *data,
252 Evas_Object *obj __UNUSED__,
253 void *event_info __UNUSED__)
255 evas_object_del(data);
259 _item_sizing_eval(Elm_Ctxpopup_Item *item)
261 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
265 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
267 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
268 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
272 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
273 Evas_Coord_Rectangle *hover_area)
275 pos->x -= (base_size->x / 2);
277 if (pos->x < hover_area->x)
278 pos->x = hover_area->x;
279 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
280 pos->x = (hover_area->x + hover_area->w) - base_size->x;
282 if (base_size->x > hover_area->w)
283 base_size->x -= (base_size->x - hover_area->w);
285 if (pos->x < hover_area->x)
286 pos->x = hover_area->x;
290 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
291 Evas_Coord_Rectangle *hover_area)
293 pos->y -= (base_size->y / 2);
295 if (pos->y < hover_area->y)
296 pos->y = hover_area->y;
297 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
298 pos->y = hover_area->y + hover_area->h - base_size->y;
300 if (base_size->y > hover_area->h)
301 base_size->y -= (base_size->y - hover_area->h);
303 if (pos->y < hover_area->y)
304 pos->y = hover_area->y;
308 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
309 Evas_Object *obj, void *event_info __UNUSED__)
313 wd = elm_widget_data_get(obj);
320 static Elm_Ctxpopup_Direction
321 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
324 Evas_Coord_Point pos = {0, 0};
325 Evas_Coord_Point base_size;
326 Evas_Coord_Point max_size;
327 Evas_Coord_Point min_size;
328 Evas_Coord_Rectangle hover_area;
329 Evas_Coord_Point arrow_size;
330 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DOWN;
331 Evas_Coord_Point temp;
334 wd = elm_widget_data_get(obj);
336 if ((!wd) || (!rect))
337 return ELM_CTXPOPUP_DIRECTION_DOWN;
339 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
340 &arrow_size.x, &arrow_size.y);
341 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
343 //Initialize Area Rectangle.
344 evas_object_geometry_get(wd->parent,
350 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
353 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
354 evas_object_smart_calculate(wd->base);
357 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
359 if ((max_size.y > 0) && (base_size.y > max_size.y))
360 base_size.y = max_size.y;
362 if ((max_size.x > 0) && (base_size.x > max_size.x))
363 base_size.x = max_size.x;
366 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
368 if ((min_size.y > 0) && (base_size.y < min_size.y))
369 base_size.y = min_size.y;
371 if ((min_size.x > 0) && (base_size.x < min_size.x))
372 base_size.x = min_size.x;
374 //Check the Which direction is available.
375 //If find a avaialble direction, it adjusts position and size.
376 for (idx = 0; idx < 4; idx++)
378 switch (wd->dir_priority[idx])
380 case ELM_CTXPOPUP_DIRECTION_UP:
381 temp.y = (pos.y - base_size.y);
382 if ((temp.y - arrow_size.y) < hover_area.y)
384 _adjust_pos_x(&pos, &base_size, &hover_area);
385 pos.y -= base_size.y;
386 dir = ELM_CTXPOPUP_DIRECTION_UP;
388 case ELM_CTXPOPUP_DIRECTION_LEFT:
389 temp.x = (pos.x - base_size.x);
390 if ((temp.x - arrow_size.x) < hover_area.x)
392 _adjust_pos_y(&pos, &base_size, &hover_area);
393 pos.x -= base_size.x;
394 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
396 case ELM_CTXPOPUP_DIRECTION_RIGHT:
397 temp.x = (pos.x + base_size.x);
398 if ((temp.x + arrow_size.x) >
399 (hover_area.x + hover_area.w))
401 _adjust_pos_y(&pos, &base_size, &hover_area);
402 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
404 case ELM_CTXPOPUP_DIRECTION_DOWN:
405 temp.y = (pos.y + base_size.y);
406 if ((temp.y + arrow_size.y) >
407 (hover_area.y + hover_area.h))
409 _adjust_pos_x(&pos, &base_size, &hover_area);
410 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
418 //In this case, all directions are invalid because of lack of space.
421 Evas_Coord length[2];
425 length[0] = pos.y - hover_area.y;
426 length[1] = (hover_area.y + hover_area.h) - pos.y;
428 // ELM_CTXPOPUP_DIRECTION_UP
429 if (length[0] > length[1])
431 _adjust_pos_x(&pos, &base_size, &hover_area);
432 pos.y -= base_size.y;
433 dir = ELM_CTXPOPUP_DIRECTION_UP;
434 if (pos.y < (hover_area.y + arrow_size.y))
436 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
437 pos.y = hover_area.y + arrow_size.y;
440 //ELM_CTXPOPUP_DIRECTION_DOWN
443 _adjust_pos_x(&pos, &base_size, &hover_area);
444 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
445 if ((pos.y + arrow_size.y + base_size.y) >
446 (hover_area.y + hover_area.h))
448 ((pos.y + arrow_size.y + base_size.y) -
449 (hover_area.y + hover_area.h));
454 length[0] = pos.x - hover_area.x;
455 length[1] = (hover_area.x + hover_area.w) - pos.x;
457 //ELM_CTXPOPUP_DIRECTION_LEFT
458 if (length[0] > length[1])
460 _adjust_pos_y(&pos, &base_size, &hover_area);
461 pos.x -= base_size.x;
462 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
463 if (pos.x < (hover_area.x + arrow_size.x))
465 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
466 pos.x = hover_area.x + arrow_size.x;
469 //ELM_CTXPOPUP_DIRECTION_RIGHT
472 _adjust_pos_y(&pos, &base_size, &hover_area);
473 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
474 if (pos.x + (arrow_size.x + base_size.x) >
475 hover_area.x + hover_area.w)
477 ((pos.x + arrow_size.x + base_size.x) -
478 (hover_area.x + hover_area.w));
483 //Final position and size.
486 rect->w = base_size.x;
487 rect->h = base_size.y;
493 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
494 Evas_Coord_Rectangle base_size)
497 Evas_Coord_Rectangle arrow_size;
501 wd = elm_widget_data_get(obj);
504 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
505 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
508 edje_object_part_unswallow(wd->base, wd->arrow);
512 case ELM_CTXPOPUP_DIRECTION_RIGHT:
513 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
514 edje_object_part_swallow(wd->base,
515 "elm.swallow.arrow_left",
518 // if user does not use dragable part
519 arrow_size.y = (y - (arrow_size.h * 0.5));
524 if (y < ((arrow_size.h * 0.5) + base_size.y))
526 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
527 y = base_size.h - arrow_size.h;
529 y = y - base_size.y - (arrow_size.h * 0.5);
530 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
531 edje_object_part_drag_value_set(wd->base,
532 "elm.swallow.arrow_left",
537 case ELM_CTXPOPUP_DIRECTION_LEFT:
538 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
539 edje_object_part_swallow(wd->base,
540 "elm.swallow.arrow_right",
543 // if user does not use dragable part
544 arrow_size.y = (y - (arrow_size.h * 0.5));
545 arrow_size.x = (x - arrow_size.w);
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_right",
562 case ELM_CTXPOPUP_DIRECTION_DOWN:
563 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
564 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
566 // if user does not use dragable part
567 arrow_size.x = (x - (arrow_size.w * 0.5));
572 if (x < ((arrow_size.w * 0.5) + base_size.x))
574 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
575 x = base_size.w - arrow_size.w;
577 x = x - base_size.x - (arrow_size.w * 0.5);
578 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
579 edje_object_part_drag_value_set(wd->base,
580 "elm.swallow.arrow_up",
585 case ELM_CTXPOPUP_DIRECTION_UP:
586 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
587 edje_object_part_swallow(wd->base,
588 "elm.swallow.arrow_down",
591 // if user does not use dragable part
592 arrow_size.x = (x - (arrow_size.w * 0.5));
593 arrow_size.y = (y - arrow_size.h);
597 if (x < ((arrow_size.w * 0.5) + base_size.x))
599 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
600 x = base_size.w - arrow_size.w;
601 else x = x - base_size.x - (arrow_size.w * 0.5);
602 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
603 edje_object_part_drag_value_set(wd->base,
604 "elm.swallow.arrow_down",
613 // if user does not use dragable part
614 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
617 //TODO: compress item - different from opensource
619 _compress_item(Evas_Object *obj)
623 Elm_Ctxpopup_Item *item;
625 wd = elm_widget_data_get(obj);
628 EINA_LIST_FOREACH(wd->items, elist, item)
630 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
635 _sizing_eval(Evas_Object *obj)
639 Elm_Ctxpopup_Item *item;
640 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
641 Evas_Coord_Point box_size = { 0, 0 };
642 Evas_Coord_Point _box_size = { 0, 0 };
644 wd = elm_widget_data_get(obj);
646 if (!wd->parent) return;
649 EINA_LIST_FOREACH(wd->items, elist, item)
651 _item_sizing_eval(item);
652 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
655 if (_box_size.x > box_size.x)
656 box_size.x = _box_size.x;
657 if (_box_size.y != -1)
658 box_size.y += _box_size.y;
662 if (_box_size.x != -1)
663 box_size.x += _box_size.x;
664 if (_box_size.y > box_size.y)
665 box_size.y = _box_size.y;
671 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
672 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
676 wd->dir = _calc_base_geometry(obj, &rect);
678 //TODO: compress item - different from opensource
679 if (!wd->horizontal && !wd->content)
682 _update_arrow(obj, wd->dir, rect);
683 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
685 //resize scroller according to final size.
687 evas_object_smart_calculate(wd->scr);
689 evas_object_move(wd->base, rect.x, rect.y);
690 evas_object_resize(wd->base, rect.w, rect.h);
694 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
695 Evas_Coord_Rectangle *rect)
697 Evas_Coord arrow_w, arrow_h;
699 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
703 case ELM_CTXPOPUP_DIRECTION_RIGHT:
706 case ELM_CTXPOPUP_DIRECTION_LEFT:
709 case ELM_CTXPOPUP_DIRECTION_DOWN:
712 case ELM_CTXPOPUP_DIRECTION_UP:
721 _del_pre_hook(Evas_Object *obj)
725 wd = elm_widget_data_get(obj);
728 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
729 _parent_resize, obj);
730 evas_object_event_callback_del_full(wd->box, EVAS_CALLBACK_RESIZE,
731 _content_resize, obj);
733 _parent_cut_off(obj);
737 _del_hook(Evas_Object *obj)
741 wd = elm_widget_data_get(obj);
744 elm_ctxpopup_clear(obj);
745 evas_object_del(wd->arrow);
746 evas_object_del(wd->base);
750 //FIXME: lost the content size when theme hook is called.
752 _theme_hook(Evas_Object *obj)
756 Elm_Ctxpopup_Item *item;
759 wd = elm_widget_data_get(obj);
763 EINA_LIST_FOREACH(wd->items, elist, item)
765 if (item->label && item->icon)
766 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
767 "icon_text_style_item",
768 elm_widget_style_get(obj));
769 else if (item->label)
770 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
771 elm_widget_style_get(obj));
773 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
774 elm_widget_style_get(obj));
776 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
778 if (elm_widget_item_disabled_get(item))
779 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
782 * For separator, if the first item has visible separator,
783 * then it should be aligned with edge of the base part.
784 * In some cases, it gives improper display. Ex) rounded corner
785 * So the first item separator should be invisible.
788 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
792 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
794 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
797 edje_object_message_signal_process(VIEW(item));
800 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
801 elm_widget_style_get(obj));
802 if (evas_object_visible_get(wd->bg))
803 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
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));
812 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
813 elm_object_style_set(wd->scr, "ctxpopup");
815 elm_object_style_set(wd->scr, elm_object_style_get(obj));
820 _scroller_size_reset(wd);
826 _content_set_hook(Evas_Object *obj, const char *part,
827 Evas_Object *content)
829 ELM_CHECK_WIDTYPE(obj, widtype);
830 Evas_Coord min_w = -1, min_h = -1;
834 if (part && strcmp(part, "default")) return;
836 wd = elm_widget_data_get(obj);
837 if ((!wd) || (!content)) return;
839 if (wd->items) elm_ctxpopup_clear(obj);
840 if (wd->content) evas_object_del(wd->content);
843 wd->box = elm_box_add(obj);
844 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
846 evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
848 evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
850 evas_object_show(content);
851 evas_object_size_hint_min_get(content, &min_w, &min_h);
852 evas_object_size_hint_min_set(wd->box, min_w, min_h);
853 elm_box_pack_end(wd->box, content);
855 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
856 _content_resize, obj);
857 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
860 elm_widget_sub_object_add(obj, wd->box);
861 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
863 wd->content = content;
864 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
871 _content_unset_hook(Evas_Object *obj, const char *part)
873 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
876 Evas_Object *content;
877 if (part && strcmp(part, "default")) return NULL;
878 wd = elm_widget_data_get(obj);
879 if (!wd) return NULL;
881 content = wd->content;
882 if (!content || !wd->box) return NULL;
884 edje_object_part_unswallow(wd->base, wd->box);
885 elm_widget_sub_object_del(obj, wd->box);
886 evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
887 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
889 evas_object_del(wd->box);
892 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
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 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1017 void *event_info __UNUSED__)
1021 Elm_Ctxpopup_Item *item;
1024 wd = elm_widget_data_get(obj);
1027 if ((!wd->items) && (!wd->content)) return;
1029 wd->visible = EINA_TRUE;
1031 evas_object_show(wd->bg);
1032 evas_object_show(wd->base);
1033 evas_object_show(wd->arrow);
1035 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
1037 EINA_LIST_FOREACH(wd->items, elist, item)
1040 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1044 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1046 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1054 _hide(Evas_Object *obj)
1056 Widget_Data *wd = elm_widget_data_get(obj);
1060 evas_object_hide(wd->bg);
1061 evas_object_hide(wd->arrow);
1062 evas_object_hide(wd->base);
1064 _scroller_size_reset(wd);
1066 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1067 wd->visible = EINA_FALSE;
1071 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1072 void *event_info __UNUSED__)
1076 wd = elm_widget_data_get(obj);
1077 if ((!wd) || (!wd->visible))
1084 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1085 void *event_info __UNUSED__)
1087 Widget_Data *wd = elm_widget_data_get(data);
1089 elm_box_recalculate(wd->box);
1094 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1095 void *event_info __UNUSED__)
1100 wd = elm_widget_data_get(data);
1102 if (!wd->visible) return;
1103 if (wd->finished) return;
1105 evas_object_geometry_get(obj, 0, 0, &w, &h);
1107 if (w != 0 && h != 0)
1109 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1112 wd->finished = EINA_TRUE;
1117 if (wd->max_sc_w < w)
1119 if (wd->max_sc_h < h)
1126 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1127 void *event_info __UNUSED__)
1131 wd = elm_widget_data_get(obj);
1136 evas_object_show(wd->arrow);
1138 _scroller_size_reset(wd);
1143 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1144 const char *emission __UNUSED__, const char *source __UNUSED__)
1146 Elm_Ctxpopup_Item *item = data;
1149 if (elm_widget_item_disabled_get(item)) return;
1152 item->func((void*) item->base.data, WIDGET(item), data);
1156 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1160 elm_widget_sub_object_del(VIEW(item), item->icon);
1161 evas_object_del(item->icon);
1167 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1168 edje_object_message_signal_process(VIEW(item));
1172 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1174 if (!eina_stringshare_replace(&item->label, label))
1177 edje_object_part_text_set(VIEW(item), "elm.text", label);
1178 edje_object_message_signal_process(VIEW(item));
1182 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1186 wd = elm_widget_data_get(WIDGET(item));
1189 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1190 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1191 elm_widget_style_get(WIDGET(item)));
1192 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1193 _item_select_cb, item);
1194 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1195 evas_object_show(VIEW(item));
1199 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1200 void *event_info __UNUSED__)
1202 elm_object_content_unset(data);
1206 _list_del(Widget_Data *wd)
1208 if (!wd->scr) return;
1210 edje_object_part_unswallow(wd->base, wd->scr);
1211 evas_object_del(wd->scr);
1217 _list_new(Evas_Object *obj)
1220 wd = elm_widget_data_get(obj);
1224 wd->scr = elm_scroller_add(obj);
1225 elm_object_style_set(wd->scr, "ctxpopup");
1226 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1227 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1228 _scroller_resize, obj);
1229 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1232 wd->box = elm_box_add(obj);
1233 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1236 elm_object_content_set(wd->scr, wd->box);
1237 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1241 _remove_items(Widget_Data *wd)
1244 Elm_Ctxpopup_Item *item;
1246 if (!wd->items) return;
1248 EINA_LIST_FOREACH(wd->items, elist, item)
1251 eina_stringshare_del(item->label);
1253 evas_object_del(item->icon);
1254 wd->items = eina_list_remove(wd->items, item);
1262 elm_ctxpopup_add(Evas_Object *parent)
1267 Evas_Coord x, y, w, h;
1269 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1271 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1272 elm_widget_type_set(obj, "ctxpopup");
1273 elm_widget_sub_object_add(parent, obj);
1274 elm_widget_data_set(obj, wd);
1275 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1276 elm_widget_del_hook_set(obj, _del_hook);
1277 elm_widget_theme_hook_set(obj, _theme_hook);
1278 elm_widget_content_set_hook_set(obj, _content_set_hook);
1279 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1280 elm_widget_content_get_hook_set(obj, _content_get_hook);
1283 wd->bg = edje_object_add(e);
1284 elm_widget_sub_object_add(obj, wd->bg);
1285 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1286 evas_object_geometry_get(parent, &x, &y, &w, &h);
1287 evas_object_move(wd->bg, x, y);
1288 evas_object_resize(wd->bg, w, h);
1289 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1290 _bg_clicked_cb, obj);
1293 wd->base = edje_object_add(e);
1294 elm_widget_sub_object_add(obj, wd->base);
1295 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1298 wd->arrow = edje_object_add(e);
1299 elm_widget_sub_object_add(obj, wd->arrow);
1300 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1302 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1303 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1304 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1305 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1307 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1309 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1311 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1313 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1315 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1316 _ctxpopup_changed_size_hints, NULL);
1317 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1318 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1319 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1320 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1322 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1324 //default parent is to be hover parent
1325 elm_ctxpopup_hover_parent_set(obj, parent);
1331 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1333 return _item_content_get_hook(it, "icon");
1337 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1339 _item_content_set_hook(it, "icon", icon);
1343 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1345 return _item_text_get_hook(it, NULL);
1349 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1351 _item_text_set_hook(it, NULL, label);
1355 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1357 ELM_CHECK_WIDTYPE(obj, widtype);
1360 Evas_Coord x, y, w, h;
1362 wd = elm_widget_data_get(obj);
1365 _parent_cut_off(obj);
1369 evas_object_event_callback_add(parent,
1373 evas_object_event_callback_add(parent,
1377 evas_object_event_callback_add(parent,
1378 EVAS_CALLBACK_RESIZE,
1383 elm_widget_sub_object_add(parent, obj);
1384 wd->parent = parent;
1387 evas_object_geometry_get(parent, &x, &y, &w, &h);
1388 evas_object_move(wd->bg, x, y);
1389 evas_object_resize(wd->bg, w, h);
1391 if (wd->visible) _sizing_eval(obj);
1395 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1397 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1401 wd = elm_widget_data_get(obj);
1402 if (!wd) return NULL;
1408 elm_ctxpopup_clear(Evas_Object * obj)
1410 ELM_CHECK_WIDTYPE(obj, widtype);
1412 Widget_Data *wd = elm_widget_data_get(obj);
1420 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1422 ELM_CHECK_WIDTYPE(obj, widtype);
1426 Elm_Ctxpopup_Item *item;
1429 wd = elm_widget_data_get(obj);
1432 wd->horizontal = !!horizontal;
1434 if ((!wd->scr) && (!wd->box))
1439 elm_box_horizontal_set(wd->box, EINA_FALSE);
1440 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1442 EINA_LIST_FOREACH(wd->items, elist, item)
1445 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1447 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1452 elm_box_horizontal_set(wd->box, EINA_TRUE);
1453 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1455 EINA_LIST_FOREACH(wd->items, elist, item)
1458 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1460 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1469 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1471 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1475 wd = elm_widget_data_get(obj);
1476 if (!wd) return EINA_FALSE;
1478 return wd->horizontal;
1481 EAPI Elm_Object_Item *
1482 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1483 Evas_Object *icon, Evas_Smart_Cb func,
1486 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1489 Elm_Ctxpopup_Item *item;
1491 wd = elm_widget_data_get(obj);
1492 if (!wd) return NULL;
1494 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1495 if (!item) return NULL;
1497 elm_widget_item_disable_set_hook_set(item, _item_disable_set_hook);
1498 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1499 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1500 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1501 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1502 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1504 //The first item is appended.
1506 evas_object_del(elm_object_content_unset(obj));
1512 item->base.data = data;
1515 _item_new(item, "icon_text_style_item");
1517 _item_new(item, "text_style_item");
1519 _item_new(item, "icon_style_item");
1521 _item_icon_set(item, icon);
1522 _item_label_set(item, label);
1523 elm_box_pack_end(wd->box, VIEW(item));
1524 wd->items = eina_list_append(wd->items, item);
1528 _scroller_size_reset(wd);
1532 return (Elm_Object_Item *) item;
1536 elm_ctxpopup_item_del(Elm_Object_Item *it)
1538 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1541 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1543 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1546 if (ctxpopup_it->icon)
1547 evas_object_del(ctxpopup_it->icon);
1548 if (VIEW(ctxpopup_it))
1549 evas_object_del(VIEW(ctxpopup_it));
1551 eina_stringshare_del(ctxpopup_it->label);
1553 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1555 if (eina_list_count(wd->items) < 1)
1559 _sizing_eval(WIDGET(ctxpopup_it));
1565 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1567 elm_object_item_disabled_set(it, disabled);
1571 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1573 return elm_object_item_disabled_get(it);
1577 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1579 elm_object_content_set(obj, content);
1583 elm_ctxpopup_content_unset(Evas_Object *obj)
1585 return elm_object_content_unset(obj);
1589 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1590 Elm_Ctxpopup_Direction first,
1591 Elm_Ctxpopup_Direction second,
1592 Elm_Ctxpopup_Direction third,
1593 Elm_Ctxpopup_Direction fourth)
1595 ELM_CHECK_WIDTYPE(obj, widtype);
1598 wd = elm_widget_data_get(obj);
1601 wd->dir_priority[0] = first;
1602 wd->dir_priority[1] = second;
1603 wd->dir_priority[2] = third;
1604 wd->dir_priority[3] = fourth;
1611 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1612 Elm_Ctxpopup_Direction *first,
1613 Elm_Ctxpopup_Direction *second,
1614 Elm_Ctxpopup_Direction *third,
1615 Elm_Ctxpopup_Direction *fourth)
1617 ELM_CHECK_WIDTYPE(obj, widtype);
1620 wd = elm_widget_data_get(obj);
1623 if (first) *first = wd->dir_priority[0];
1624 if (second) *second = wd->dir_priority[1];
1625 if (third) *third = wd->dir_priority[2];
1626 if (fourth) *fourth = wd->dir_priority[3];
1629 EAPI Elm_Ctxpopup_Direction
1630 elm_ctxpopup_direction_get(const Evas_Object *obj)
1632 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1635 wd = elm_widget_data_get(obj);
1636 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;