1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Elm_Ctxpopup_Item Elm_Ctxpopup_Item;
7 struct _Elm_Ctxpopup_Item
25 Elm_Ctxpopup_Direction dir;
26 Elm_Ctxpopup_Direction dir_priority[4];
27 Evas_Coord max_sc_w, max_sc_h;
28 Eina_Bool horizontal:1;
33 static const char *widtype = NULL;
35 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
36 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
37 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
38 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
39 static void _scroller_size_reset(Widget_Data *wd);
40 static void _on_focus_hook(void *data, Evas_Object *obj);
41 static Eina_Bool _event_hook(Evas_Object *obj,
43 Evas_Callback_Type type,
45 static void _parent_cut_off(Evas_Object *obj);
46 static void _parent_resize(void *data,
50 static void _parent_move(void *data,
54 static void _parent_del(void *data,
58 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
59 static void _adjust_pos_x(Evas_Coord_Point *pos,
60 Evas_Coord_Point *base_size,
61 Evas_Coord_Rectangle *hover_area);
62 static void _adjust_pos_y(Evas_Coord_Point *pos,
63 Evas_Coord_Point *base_size,
64 Evas_Coord_Rectangle *hover_area);
65 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
66 Evas *e __UNUSED__, Evas_Object *obj,
67 void *event_info __UNUSED__);
68 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
69 Evas_Coord_Rectangle *rect);
70 static void _update_arrow(Evas_Object *obj,
71 Elm_Ctxpopup_Direction dir,
72 Evas_Coord_Rectangle rect);
73 static void _sizing_eval(Evas_Object *obj);
74 static void _shift_base_by_arrow(Evas_Object *arrow,
75 Elm_Ctxpopup_Direction dir,
76 Evas_Coord_Rectangle *rect);
77 static void _del_pre_hook(Evas_Object *obj);
78 static void _del_hook(Evas_Object *obj);
79 static void _theme_hook(Evas_Object *obj);
80 static void _content_set_hook(Evas_Object *obj,
82 Evas_Object *content);
83 static Evas_Object * _content_unset_hook(Evas_Object *obj,
85 static Evas_Object * _content_get_hook(const Evas_Object *obj,
87 static void _item_text_set_hook(Elm_Object_Item *it,
90 static const char * _item_text_get_hook(const Elm_Object_Item *it,
92 static void _item_content_set_hook(Elm_Object_Item *it,
94 Evas_Object *content);
95 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
97 static void _item_disable_hook(Elm_Object_Item *it);
98 static void _item_signal_emit_hook(Elm_Object_Item *it,
101 static void _bg_clicked_cb(void *data, Evas_Object *obj,
102 const char *emission,
104 static void _ctxpopup_show(void *data,
108 static void _hide(Evas_Object *obj);
109 static void _ctxpopup_hide(void *data,
113 static void _content_resize(void *data,
117 static void _scroller_resize(void *data,
121 static void _ctxpopup_move(void *data,
125 static void _restack(void *data, Evas *e, Evas_Object *obj, void *event_info);
126 static void _item_select_cb(void *data, Evas_Object *obj,
127 const char *emission,
129 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
130 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
131 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
132 static void _content_del(void *data,
136 static void _list_del(Widget_Data *wd);
137 static void _list_new(Evas_Object *obj);
138 static void _remove_items(Widget_Data * wd);
140 static const char SIG_DISMISSED[] = "dismissed";
142 static const Evas_Smart_Cb_Description _signals[] = {
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_object_scroll_freeze_push(wd->scr);
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_object_scroll_freeze_pop(wd->scr);
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 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
196 Widget_Data *wd = elm_widget_data_get(obj);
199 if (elm_widget_focus_get(obj))
210 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
211 Evas_Callback_Type type, void *event_info)
213 Evas_Event_Key_Down *ev;
216 if (type != EVAS_CALLBACK_KEY_DOWN)
218 wd = elm_widget_data_get(obj);
219 if (!wd) return EINA_FALSE;
222 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
223 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
225 evas_object_hide(obj);
226 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
231 _parent_cut_off(Evas_Object *obj)
233 Widget_Data *wd = elm_widget_data_get(obj);
237 evas_object_event_callback_del_full(wd->parent,
241 evas_object_event_callback_del_full(wd->parent,
245 evas_object_event_callback_del_full(wd->parent,
246 EVAS_CALLBACK_RESIZE,
250 elm_widget_sub_object_del(wd->parent, obj);
254 _parent_resize(void *data,
256 Evas_Object *obj __UNUSED__,
257 void *event_info __UNUSED__)
259 Widget_Data *wd = elm_widget_data_get(data);
262 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
268 _parent_move(void *data,
270 Evas_Object *obj __UNUSED__,
271 void *event_info __UNUSED__)
273 Widget_Data *wd = elm_widget_data_get(data);
277 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
281 _scroller_size_reset(wd);
287 _parent_del(void *data,
289 Evas_Object *obj __UNUSED__,
290 void *event_info __UNUSED__)
292 evas_object_del(data);
296 _item_sizing_eval(Elm_Ctxpopup_Item *item)
298 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
302 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
304 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
305 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
309 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
310 Evas_Coord_Rectangle *hover_area)
312 pos->x -= (base_size->x / 2);
314 if (pos->x < hover_area->x)
315 pos->x = hover_area->x;
316 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
317 pos->x = (hover_area->x + hover_area->w) - base_size->x;
319 if (base_size->x > hover_area->w)
320 base_size->x -= (base_size->x - hover_area->w);
322 if (pos->x < hover_area->x)
323 pos->x = hover_area->x;
327 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
328 Evas_Coord_Rectangle *hover_area)
330 pos->y -= (base_size->y / 2);
332 if (pos->y < hover_area->y)
333 pos->y = hover_area->y;
334 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
335 pos->y = hover_area->y + hover_area->h - base_size->y;
337 if (base_size->y > hover_area->h)
338 base_size->y -= (base_size->y - hover_area->h);
340 if (pos->y < hover_area->y)
341 pos->y = hover_area->y;
345 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
346 Evas_Object *obj, void *event_info __UNUSED__)
350 wd = elm_widget_data_get(obj);
357 static Elm_Ctxpopup_Direction
358 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
361 Evas_Coord_Point pos = {0, 0};
362 Evas_Coord_Point base_size;
363 Evas_Coord_Point max_size;
364 Evas_Coord_Point min_size;
365 Evas_Coord_Rectangle hover_area;
366 Evas_Coord_Point arrow_size;
367 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
368 Evas_Coord_Point temp;
371 wd = elm_widget_data_get(obj);
373 if ((!wd) || (!rect))
374 return ELM_CTXPOPUP_DIRECTION_DOWN;
376 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
377 &arrow_size.x, &arrow_size.y);
378 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
380 //Initialize Area Rectangle.
381 evas_object_geometry_get(wd->parent,
387 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
390 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
391 evas_object_smart_calculate(wd->base);
394 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
396 if ((max_size.y > 0) && (base_size.y > max_size.y))
397 base_size.y = max_size.y;
399 if ((max_size.x > 0) && (base_size.x > max_size.x))
400 base_size.x = max_size.x;
403 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
405 if ((min_size.y > 0) && (base_size.y < min_size.y))
406 base_size.y = min_size.y;
408 if ((min_size.x > 0) && (base_size.x < min_size.x))
409 base_size.x = min_size.x;
411 //Check the Which direction is available.
412 //If find a avaialble direction, it adjusts position and size.
413 for (idx = 0; idx < 4; idx++)
415 switch (wd->dir_priority[idx])
417 case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
418 case ELM_CTXPOPUP_DIRECTION_UP:
419 temp.y = (pos.y - base_size.y);
420 if ((temp.y - arrow_size.y) < hover_area.y)
422 _adjust_pos_x(&pos, &base_size, &hover_area);
423 pos.y -= base_size.y;
424 dir = ELM_CTXPOPUP_DIRECTION_UP;
426 case ELM_CTXPOPUP_DIRECTION_LEFT:
427 temp.x = (pos.x - base_size.x);
428 if ((temp.x - arrow_size.x) < hover_area.x)
430 _adjust_pos_y(&pos, &base_size, &hover_area);
431 pos.x -= base_size.x;
432 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
434 case ELM_CTXPOPUP_DIRECTION_RIGHT:
435 temp.x = (pos.x + base_size.x);
436 if ((temp.x + arrow_size.x) >
437 (hover_area.x + hover_area.w))
439 _adjust_pos_y(&pos, &base_size, &hover_area);
440 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
442 case ELM_CTXPOPUP_DIRECTION_DOWN:
443 temp.y = (pos.y + base_size.y);
444 if ((temp.y + arrow_size.y) >
445 (hover_area.y + hover_area.h))
447 _adjust_pos_x(&pos, &base_size, &hover_area);
448 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
456 //In this case, all directions are invalid because of lack of space.
459 Evas_Coord length[2];
463 length[0] = pos.y - hover_area.y;
464 length[1] = (hover_area.y + hover_area.h) - pos.y;
466 // ELM_CTXPOPUP_DIRECTION_UP
467 if (length[0] > length[1])
469 _adjust_pos_x(&pos, &base_size, &hover_area);
470 pos.y -= base_size.y;
471 dir = ELM_CTXPOPUP_DIRECTION_UP;
472 if (pos.y < (hover_area.y + arrow_size.y))
474 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
475 pos.y = hover_area.y + arrow_size.y;
478 //ELM_CTXPOPUP_DIRECTION_DOWN
481 _adjust_pos_x(&pos, &base_size, &hover_area);
482 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
483 if ((pos.y + arrow_size.y + base_size.y) >
484 (hover_area.y + hover_area.h))
486 ((pos.y + arrow_size.y + base_size.y) -
487 (hover_area.y + hover_area.h));
492 length[0] = pos.x - hover_area.x;
493 length[1] = (hover_area.x + hover_area.w) - pos.x;
495 //ELM_CTXPOPUP_DIRECTION_LEFT
496 if (length[0] > length[1])
498 _adjust_pos_y(&pos, &base_size, &hover_area);
499 pos.x -= base_size.x;
500 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
501 if (pos.x < (hover_area.x + arrow_size.x))
503 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
504 pos.x = hover_area.x + arrow_size.x;
507 //ELM_CTXPOPUP_DIRECTION_RIGHT
510 _adjust_pos_y(&pos, &base_size, &hover_area);
511 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
512 if (pos.x + (arrow_size.x + base_size.x) >
513 hover_area.x + hover_area.w)
515 ((pos.x + arrow_size.x + base_size.x) -
516 (hover_area.x + hover_area.w));
521 //Final position and size.
524 rect->w = base_size.x;
525 rect->h = base_size.y;
531 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
532 Evas_Coord_Rectangle base_size)
535 Evas_Coord_Rectangle arrow_size;
539 wd = elm_widget_data_get(obj);
542 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
543 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
546 edje_object_part_unswallow(wd->base, wd->arrow);
550 case ELM_CTXPOPUP_DIRECTION_RIGHT:
551 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
552 edje_object_part_swallow(wd->base,
553 "elm.swallow.arrow_left",
556 // if user does not use dragable part
557 arrow_size.y = (y - (arrow_size.h * 0.5));
562 if (y < ((arrow_size.h * 0.5) + base_size.y))
564 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
565 y = base_size.h - arrow_size.h;
567 y = y - base_size.y - (arrow_size.h * 0.5);
568 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
569 edje_object_part_drag_value_set(wd->base,
570 "elm.swallow.arrow_left",
575 case ELM_CTXPOPUP_DIRECTION_LEFT:
576 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
577 edje_object_part_swallow(wd->base,
578 "elm.swallow.arrow_right",
581 // if user does not use dragable part
582 arrow_size.y = (y - (arrow_size.h * 0.5));
583 arrow_size.x = (x - arrow_size.w);
587 if (y < ((arrow_size.h * 0.5) + base_size.y))
589 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
590 y = base_size.h - arrow_size.h;
592 y = y - base_size.y - (arrow_size.h * 0.5);
593 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
594 edje_object_part_drag_value_set(wd->base,
595 "elm.swallow.arrow_right",
600 case ELM_CTXPOPUP_DIRECTION_DOWN:
601 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
602 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
604 // if user does not use dragable part
605 arrow_size.x = (x - (arrow_size.w * 0.5));
610 if (x < ((arrow_size.w * 0.5) + base_size.x))
612 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
613 x = base_size.w - arrow_size.w;
615 x = x - base_size.x - (arrow_size.w * 0.5);
616 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
617 edje_object_part_drag_value_set(wd->base,
618 "elm.swallow.arrow_up",
623 case ELM_CTXPOPUP_DIRECTION_UP:
624 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
625 edje_object_part_swallow(wd->base,
626 "elm.swallow.arrow_down",
629 // if user does not use dragable part
630 arrow_size.x = (x - (arrow_size.w * 0.5));
631 arrow_size.y = (y - arrow_size.h);
635 if (x < ((arrow_size.w * 0.5) + base_size.x))
637 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
638 x = base_size.w - arrow_size.w;
639 else x = x - base_size.x - (arrow_size.w * 0.5);
640 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
641 edje_object_part_drag_value_set(wd->base,
642 "elm.swallow.arrow_down",
651 // if user does not use dragable part
652 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
655 //TODO: compress item - different from opensource
657 _compress_item(Evas_Object *obj)
661 Elm_Ctxpopup_Item *item;
663 wd = elm_widget_data_get(obj);
666 EINA_LIST_FOREACH(wd->items, elist, item)
668 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
673 _sizing_eval(Evas_Object *obj)
677 Elm_Ctxpopup_Item *item;
678 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
679 Evas_Coord_Point box_size = { 0, 0 };
680 Evas_Coord_Point _box_size = { 0, 0 };
682 wd = elm_widget_data_get(obj);
684 if (!wd->parent) return;
687 EINA_LIST_FOREACH(wd->items, elist, item)
689 _item_sizing_eval(item);
690 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
693 if (_box_size.x > box_size.x)
694 box_size.x = _box_size.x;
695 if (_box_size.y != -1)
696 box_size.y += _box_size.y;
700 if (_box_size.x != -1)
701 box_size.x += _box_size.x;
702 if (_box_size.y > box_size.y)
703 box_size.y = _box_size.y;
709 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
710 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
714 wd->dir = _calc_base_geometry(obj, &rect);
716 //TODO: compress item - different from opensource
717 if (!wd->horizontal && !wd->content)
720 _update_arrow(obj, wd->dir, rect);
721 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
723 //resize scroller according to final size.
725 evas_object_smart_calculate(wd->scr);
727 evas_object_move(wd->base, rect.x, rect.y);
728 evas_object_resize(wd->base, rect.w, rect.h);
732 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
733 Evas_Coord_Rectangle *rect)
735 Evas_Coord arrow_w, arrow_h;
737 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
741 case ELM_CTXPOPUP_DIRECTION_RIGHT:
744 case ELM_CTXPOPUP_DIRECTION_LEFT:
747 case ELM_CTXPOPUP_DIRECTION_DOWN:
750 case ELM_CTXPOPUP_DIRECTION_UP:
759 _del_pre_hook(Evas_Object *obj)
763 wd = elm_widget_data_get(obj);
766 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
767 _parent_resize, obj);
768 evas_object_event_callback_del_full(wd->box, EVAS_CALLBACK_RESIZE,
769 _content_resize, obj);
771 _parent_cut_off(obj);
775 _del_hook(Evas_Object *obj)
779 wd = elm_widget_data_get(obj);
782 elm_ctxpopup_clear(obj);
783 evas_object_del(wd->arrow);
784 evas_object_del(wd->base);
788 //FIXME: lost the content size when theme hook is called.
790 _theme_hook(Evas_Object *obj)
794 Elm_Ctxpopup_Item *item;
798 wd = elm_widget_data_get(obj);
801 _elm_widget_mirrored_reload(obj);
802 rtl = elm_widget_mirrored_get(obj);
804 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
805 elm_widget_style_get(obj));
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));
812 EINA_LIST_FOREACH(wd->items, elist, item)
814 edje_object_mirrored_set(VIEW(item), rtl);
816 if (item->label && item->icon)
817 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
818 "icon_text_style_item",
819 elm_widget_style_get(obj));
820 else if (item->label)
821 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
822 elm_widget_style_get(obj));
824 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
825 elm_widget_style_get(obj));
827 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
829 if (elm_widget_item_disabled_get(item))
830 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
833 * For separator, if the first item has visible separator,
834 * then it should be aligned with edge of the base part.
835 * In some cases, it gives improper display. Ex) rounded corner
836 * So the first item separator should be invisible.
839 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
843 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
845 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
848 edje_object_message_signal_process(VIEW(item));
851 if (evas_object_visible_get(wd->bg))
852 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
856 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
857 elm_object_style_set(wd->scr, "ctxpopup");
859 elm_object_style_set(wd->scr, elm_object_style_get(obj));
862 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
866 _scroller_size_reset(wd);
872 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
874 ELM_CHECK_WIDTYPE(obj, widtype);
875 Evas_Coord min_w = -1, min_h = -1;
879 if (part && strcmp(part, "default")) return;
881 wd = elm_widget_data_get(obj);
882 if ((!wd) || (!content)) return;
884 if (wd->items) elm_ctxpopup_clear(obj);
885 if (wd->content) evas_object_del(wd->content);
888 wd->box = elm_box_add(obj);
889 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
891 evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
893 evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
895 evas_object_show(content);
896 evas_object_size_hint_min_get(content, &min_w, &min_h);
897 evas_object_size_hint_min_set(wd->box, min_w, min_h);
898 elm_box_pack_end(wd->box, content);
900 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
901 _content_resize, obj);
902 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
905 elm_widget_sub_object_add(obj, wd->box);
906 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
908 wd->content = content;
909 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
916 _content_unset_hook(Evas_Object *obj, const char *part)
918 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
921 Evas_Object *content;
922 if (part && strcmp(part, "default")) return NULL;
923 wd = elm_widget_data_get(obj);
924 if (!wd) return NULL;
926 content = wd->content;
927 if (!content || !wd->box) return NULL;
929 edje_object_part_unswallow(wd->base, wd->box);
930 elm_widget_sub_object_del(obj, wd->box);
931 evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
932 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
934 evas_object_del(wd->box);
937 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
943 _content_get_hook(const Evas_Object *obj, const char *part)
945 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
947 if (part && strcmp(part, "default")) return NULL;
948 wd = elm_widget_data_get(obj);
949 if (!wd) return NULL;
954 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
956 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
959 Elm_Ctxpopup_Item *ctxpopup_it;
961 if (part && strcmp(part, "default")) return;
963 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
965 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
968 _item_label_set(ctxpopup_it, label);
969 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
973 _scroller_size_reset(wd);
974 _sizing_eval(WIDGET(ctxpopup_it));
979 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
981 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
982 Elm_Ctxpopup_Item *ctxpopup_it;
983 if (part && strcmp(part, "default")) return NULL;
984 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
985 return ctxpopup_it->label;
989 _item_content_set_hook(Elm_Object_Item *it,
991 Evas_Object *content)
993 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
995 Elm_Ctxpopup_Item *ctxpopup_it;
997 if (part && strcmp(part, "icon")) return;
999 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1001 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1004 _item_icon_set(ctxpopup_it, content);
1005 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1009 _scroller_size_reset(wd);
1010 _sizing_eval(WIDGET(ctxpopup_it));
1014 static Evas_Object *
1015 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
1017 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1018 Elm_Ctxpopup_Item *ctxpopup_it;
1019 if (part && strcmp(part, "icon")) return NULL;
1020 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1021 return ctxpopup_it->icon;
1025 _item_disable_hook(Elm_Object_Item *it)
1027 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1030 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1032 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1035 if (elm_widget_item_disabled_get(it))
1036 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
1038 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
1042 _item_signal_emit_hook(Elm_Object_Item *it, const char *emission,
1045 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1046 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1047 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
1051 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
1052 const char *emission __UNUSED__, const char *source __UNUSED__)
1054 evas_object_hide(data);
1058 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1059 void *event_info __UNUSED__)
1063 Elm_Ctxpopup_Item *item;
1066 wd = elm_widget_data_get(obj);
1069 if ((!wd->items) && (!wd->content)) return;
1071 wd->visible = EINA_TRUE;
1073 evas_object_show(wd->bg);
1074 evas_object_show(wd->base);
1075 evas_object_show(wd->arrow);
1077 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
1079 EINA_LIST_FOREACH(wd->items, elist, item)
1082 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1086 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1088 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1094 elm_object_focus_set(obj, EINA_TRUE);
1098 _hide(Evas_Object *obj)
1100 Widget_Data *wd = elm_widget_data_get(obj);
1102 if ((!wd) || (!wd->visible)) return;
1104 evas_object_hide(wd->bg);
1105 evas_object_hide(wd->arrow);
1106 evas_object_hide(wd->base);
1108 _scroller_size_reset(wd);
1110 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1111 wd->visible = EINA_FALSE;
1115 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1116 void *event_info __UNUSED__)
1122 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1123 void *event_info __UNUSED__)
1125 Widget_Data *wd = elm_widget_data_get(data);
1127 elm_box_recalculate(wd->box);
1132 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1133 void *event_info __UNUSED__)
1138 wd = elm_widget_data_get(data);
1140 if (!wd->visible) return;
1141 if (wd->finished) return;
1143 evas_object_geometry_get(obj, 0, 0, &w, &h);
1145 if (w != 0 && h != 0)
1147 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1150 wd->finished = EINA_TRUE;
1155 if (wd->max_sc_w < w)
1157 if (wd->max_sc_h < h)
1164 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1165 void *event_info __UNUSED__)
1169 wd = elm_widget_data_get(obj);
1174 evas_object_show(wd->arrow);
1176 _scroller_size_reset(wd);
1181 _restack(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1183 Widget_Data *wd = elm_widget_data_get(obj);
1185 evas_object_layer_set(wd->bg,
1186 evas_object_layer_get(obj));
1187 evas_object_layer_set(wd->base,
1188 evas_object_layer_get(obj));
1192 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1193 const char *emission __UNUSED__, const char *source __UNUSED__)
1195 Elm_Ctxpopup_Item *item = data;
1198 if (elm_widget_item_disabled_get(item)) return;
1201 item->func((void*) item->base.data, WIDGET(item), data);
1205 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1209 elm_widget_sub_object_del(VIEW(item), item->icon);
1210 evas_object_del(item->icon);
1216 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1217 edje_object_message_signal_process(VIEW(item));
1221 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1223 if (!eina_stringshare_replace(&item->label, label))
1226 edje_object_part_text_set(VIEW(item), "elm.text", label);
1227 edje_object_message_signal_process(VIEW(item));
1231 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1235 wd = elm_widget_data_get(WIDGET(item));
1238 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1239 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
1240 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1241 elm_widget_style_get(WIDGET(item)));
1242 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1243 _item_select_cb, item);
1244 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1245 evas_object_show(VIEW(item));
1249 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1250 void *event_info __UNUSED__)
1252 elm_object_content_unset(data);
1256 _list_del(Widget_Data *wd)
1258 if (!wd->scr) return;
1260 edje_object_part_unswallow(wd->base, wd->scr);
1261 evas_object_del(wd->scr);
1267 _list_new(Evas_Object *obj)
1270 wd = elm_widget_data_get(obj);
1274 wd->scr = elm_scroller_add(obj);
1275 elm_object_style_set(wd->scr, "ctxpopup");
1276 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1277 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1278 _scroller_resize, obj);
1279 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1282 wd->box = elm_box_add(obj);
1283 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1286 elm_object_content_set(wd->scr, wd->box);
1287 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1291 _remove_items(Widget_Data *wd)
1294 Elm_Ctxpopup_Item *item;
1296 if (!wd->items) return;
1298 EINA_LIST_FOREACH(wd->items, elist, item)
1301 eina_stringshare_del(item->label);
1303 evas_object_del(item->icon);
1304 wd->items = eina_list_remove(wd->items, item);
1305 elm_widget_item_free(item);
1312 _item_del_pre_hook(Elm_Object_Item *it)
1314 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1317 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1319 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1322 if (ctxpopup_it->icon)
1323 evas_object_del(ctxpopup_it->icon);
1324 if (VIEW(ctxpopup_it))
1325 evas_object_del(VIEW(ctxpopup_it));
1327 eina_stringshare_del(ctxpopup_it->label);
1329 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1331 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1333 if (eina_list_count(wd->items) < 1)
1335 evas_object_hide(WIDGET(ctxpopup_it));
1340 _sizing_eval(WIDGET(ctxpopup_it));
1344 elm_ctxpopup_add(Evas_Object *parent)
1349 Evas_Coord x, y, w, h;
1351 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1353 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1354 elm_widget_type_set(obj, "ctxpopup");
1355 elm_widget_sub_object_add(parent, obj);
1356 elm_widget_data_set(obj, wd);
1357 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1358 elm_widget_del_hook_set(obj, _del_hook);
1359 elm_widget_theme_hook_set(obj, _theme_hook);
1360 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1361 elm_widget_can_focus_set(obj, EINA_TRUE);
1362 elm_widget_event_hook_set(obj, _event_hook);
1363 elm_widget_content_set_hook_set(obj, _content_set_hook);
1364 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1365 elm_widget_content_get_hook_set(obj, _content_get_hook);
1368 wd->bg = edje_object_add(e);
1369 elm_widget_sub_object_add(obj, wd->bg);
1370 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1371 evas_object_geometry_get(parent, &x, &y, &w, &h);
1372 evas_object_move(wd->bg, x, y);
1373 evas_object_resize(wd->bg, w, h);
1374 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1375 _bg_clicked_cb, obj);
1378 wd->base = edje_object_add(e);
1379 elm_widget_sub_object_add(obj, wd->base);
1380 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1383 wd->arrow = edje_object_add(e);
1384 elm_widget_sub_object_add(obj, wd->arrow);
1385 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1387 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1388 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1389 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1390 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1392 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1394 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1396 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1398 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1400 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1402 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1403 _ctxpopup_changed_size_hints, NULL);
1404 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESTACK, _restack, obj);
1405 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1406 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1407 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1408 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1410 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1412 //default parent is to be hover parent
1413 elm_ctxpopup_hover_parent_set(obj, parent);
1419 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1421 return _item_content_get_hook(it, "icon");
1425 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1427 _item_content_set_hook(it, "icon", icon);
1431 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1433 return _item_text_get_hook(it, NULL);
1437 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1439 _item_text_set_hook(it, NULL, label);
1443 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1445 ELM_CHECK_WIDTYPE(obj, widtype);
1448 Evas_Coord x, y, w, h;
1450 wd = elm_widget_data_get(obj);
1451 if ((!wd) || (!parent)) return;
1453 _parent_cut_off(obj);
1457 evas_object_event_callback_add(parent,
1461 evas_object_event_callback_add(parent,
1465 evas_object_event_callback_add(parent,
1466 EVAS_CALLBACK_RESIZE,
1471 elm_widget_sub_object_add(parent, obj);
1472 wd->parent = parent;
1475 evas_object_geometry_get(parent, &x, &y, &w, &h);
1476 evas_object_move(wd->bg, x, y);
1477 evas_object_resize(wd->bg, w, h);
1479 if (wd->visible) _sizing_eval(obj);
1483 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1485 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1489 wd = elm_widget_data_get(obj);
1490 if (!wd) return NULL;
1496 elm_ctxpopup_clear(Evas_Object * obj)
1498 ELM_CHECK_WIDTYPE(obj, widtype);
1500 Widget_Data *wd = elm_widget_data_get(obj);
1505 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1509 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1511 ELM_CHECK_WIDTYPE(obj, widtype);
1515 Elm_Ctxpopup_Item *item;
1518 wd = elm_widget_data_get(obj);
1521 wd->horizontal = !!horizontal;
1523 if ((!wd->scr) && (!wd->box))
1528 elm_box_horizontal_set(wd->box, EINA_FALSE);
1529 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1531 EINA_LIST_FOREACH(wd->items, elist, item)
1534 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1536 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1541 elm_box_horizontal_set(wd->box, EINA_TRUE);
1542 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1544 EINA_LIST_FOREACH(wd->items, elist, item)
1547 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1549 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1553 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1560 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1562 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1566 wd = elm_widget_data_get(obj);
1567 if (!wd) return EINA_FALSE;
1569 return wd->horizontal;
1572 EAPI Elm_Object_Item *
1573 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1574 Evas_Object *icon, Evas_Smart_Cb func,
1577 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1580 Evas_Object *content;
1581 Elm_Ctxpopup_Item *item;
1583 wd = elm_widget_data_get(obj);
1584 if (!wd) return NULL;
1586 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1587 if (!item) return NULL;
1589 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1590 elm_widget_item_disable_hook_set(item, _item_disable_hook);
1591 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1592 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1593 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1594 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1595 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1597 //The first item is appended.
1598 content = elm_object_content_unset(obj);
1599 if (content) evas_object_del(content);
1605 item->base.data = data;
1608 _item_new(item, "icon_text_style_item");
1610 _item_new(item, "text_style_item");
1612 _item_new(item, "icon_style_item");
1614 _item_icon_set(item, icon);
1615 _item_label_set(item, label);
1616 elm_box_pack_end(wd->box, VIEW(item));
1617 wd->items = eina_list_append(wd->items, item);
1618 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1622 _scroller_size_reset(wd);
1626 return (Elm_Object_Item *) item;
1630 elm_ctxpopup_item_del(Elm_Object_Item *it)
1632 elm_object_item_del(it);
1636 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1638 elm_object_item_disabled_set(it, disabled);
1642 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1644 return elm_object_item_disabled_get(it);
1648 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1650 elm_object_content_set(obj, content);
1654 elm_ctxpopup_content_unset(Evas_Object *obj)
1656 return elm_object_content_unset(obj);
1660 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1661 Elm_Ctxpopup_Direction first,
1662 Elm_Ctxpopup_Direction second,
1663 Elm_Ctxpopup_Direction third,
1664 Elm_Ctxpopup_Direction fourth)
1666 ELM_CHECK_WIDTYPE(obj, widtype);
1669 wd = elm_widget_data_get(obj);
1672 wd->dir_priority[0] = first;
1673 wd->dir_priority[1] = second;
1674 wd->dir_priority[2] = third;
1675 wd->dir_priority[3] = fourth;
1682 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1683 Elm_Ctxpopup_Direction *first,
1684 Elm_Ctxpopup_Direction *second,
1685 Elm_Ctxpopup_Direction *third,
1686 Elm_Ctxpopup_Direction *fourth)
1688 ELM_CHECK_WIDTYPE(obj, widtype);
1691 wd = elm_widget_data_get(obj);
1694 if (first) *first = wd->dir_priority[0];
1695 if (second) *second = wd->dir_priority[1];
1696 if (third) *third = wd->dir_priority[2];
1697 if (fourth) *fourth = wd->dir_priority[3];
1700 EAPI Elm_Ctxpopup_Direction
1701 elm_ctxpopup_direction_get(const Evas_Object *obj)
1703 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1706 wd = elm_widget_data_get(obj);
1707 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;