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, Elm_Ctxpopup_Direction dir);
68 static void _sizing_eval(Evas_Object *obj);
69 static void _shift_base_by_arrow(Evas_Object *arrow,
70 Elm_Ctxpopup_Direction dir,
71 Evas_Coord_Rectangle *rect);
72 static void _del_pre_hook(Evas_Object *obj);
73 static void _del_hook(Evas_Object *obj);
74 static void _theme_hook(Evas_Object *obj);
75 static void _content_set_hook(Evas_Object *obj,
76 const char *item __UNUSED__,
77 Evas_Object *content);
78 static Evas_Object * _content_unset_hook(Evas_Object *obj,
79 const char *item __UNUSED__);
80 static Evas_Object * _content_get_hook(const Evas_Object *obj,
82 static void _item_text_set_hook(Elm_Object_Item *it,
85 static const char * _item_text_get_hook(const Elm_Object_Item *it,
87 static void _item_content_set_hook(Elm_Object_Item *it,
89 Evas_Object *content);
90 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
92 static void _item_disable_set_hook(Elm_Object_Item *it);
93 static void _item_signal_emit_hook(Elm_Object_Item *it,
96 static void _bg_clicked_cb(void *data, Evas_Object *obj,
99 static void _ctxpopup_show(void *data,
103 static void _hide(Evas_Object *obj);
104 static void _ctxpopup_hide(void *data,
108 static void _scroller_resize(void *data,
112 static void _ctxpopup_move(void *data,
116 static void _item_select_cb(void *data, Evas_Object *obj,
117 const char *emission,
119 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
120 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
121 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
122 static void _content_del(void *data,
126 static void _list_del(Widget_Data *wd);
127 static void _list_new(Evas_Object *obj);
128 static void _remove_items(Widget_Data * wd);
130 static const char SIG_DISMISSED[] = "dismissed";
132 static const Evas_Smart_Cb_Description _signals[] = {
137 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
138 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
139 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
142 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
143 void *event_info __UNUSED__)
145 Widget_Data *wd = elm_widget_data_get(obj);
147 if ((!wd) || (!wd->scr)) return;
148 elm_object_scroll_freeze_push(wd->scr);
152 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
153 void *event_info __UNUSED__)
155 Widget_Data *wd = elm_widget_data_get(obj);
157 if ((!wd) || (!wd->scr)) return;
158 elm_object_scroll_freeze_pop(wd->scr);
162 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
164 Widget_Data *wd = elm_widget_data_get(obj);
166 if ((!wd) || (!wd->scr)) return;
167 elm_object_scroll_hold_push(wd->scr);
171 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
173 Widget_Data *wd = elm_widget_data_get(obj);
175 if ((!wd) || (!wd->scr)) return;
176 elm_object_scroll_hold_pop(wd->scr);
180 _scroller_size_reset(Widget_Data *wd)
182 wd->finished = EINA_FALSE;
188 _parent_cut_off(Evas_Object *obj)
190 Widget_Data *wd = elm_widget_data_get(obj);
194 evas_object_event_callback_del_full(wd->parent,
198 evas_object_event_callback_del_full(wd->parent,
202 evas_object_event_callback_del_full(wd->parent,
203 EVAS_CALLBACK_RESIZE,
207 elm_widget_sub_object_del(wd->parent, obj);
211 _parent_resize(void *data,
213 Evas_Object *obj __UNUSED__,
214 void *event_info __UNUSED__)
216 Widget_Data *wd = elm_widget_data_get(data);
219 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
225 _parent_move(void *data,
227 Evas_Object *obj __UNUSED__,
228 void *event_info __UNUSED__)
230 Widget_Data *wd = elm_widget_data_get(data);
234 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
238 _scroller_size_reset(wd);
244 _parent_del(void *data,
246 Evas_Object *obj __UNUSED__,
247 void *event_info __UNUSED__)
249 evas_object_del(data);
253 _item_sizing_eval(Elm_Ctxpopup_Item *item)
255 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
259 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
261 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
262 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
266 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
267 Evas_Coord_Rectangle *hover_area)
269 pos->x -= (base_size->x / 2);
271 if (pos->x < hover_area->x)
272 pos->x = hover_area->x;
273 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
274 pos->x = (hover_area->x + hover_area->w) - base_size->x;
276 if (base_size->x > hover_area->w)
277 base_size->x -= (base_size->x - hover_area->w);
279 if (pos->x < hover_area->x)
280 pos->x = hover_area->x;
284 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
285 Evas_Coord_Rectangle *hover_area)
287 pos->y -= (base_size->y / 2);
289 if (pos->y < hover_area->y)
290 pos->y = hover_area->y;
291 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
292 pos->y = hover_area->y + hover_area->h - base_size->y;
294 if (base_size->y > hover_area->h)
295 base_size->y -= (base_size->y - hover_area->h);
297 if (pos->y < hover_area->y)
298 pos->y = hover_area->y;
302 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
303 Evas_Object *obj, void *event_info __UNUSED__)
307 wd = elm_widget_data_get(obj);
314 static Elm_Ctxpopup_Direction
315 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
318 Evas_Coord_Point pos = {0, 0};
319 Evas_Coord_Point base_size;
320 Evas_Coord_Point max_size;
321 Evas_Coord_Point min_size;
322 Evas_Coord_Rectangle hover_area;
323 Evas_Coord_Point arrow_size;
324 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DOWN;
325 Evas_Coord_Point temp;
328 wd = elm_widget_data_get(obj);
330 if ((!wd) || (!rect))
331 return ELM_CTXPOPUP_DIRECTION_DOWN;
333 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
334 &arrow_size.x, &arrow_size.y);
335 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
337 //Initialize Area Rectangle.
338 evas_object_geometry_get(wd->parent,
344 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
347 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
348 evas_object_smart_calculate(wd->base);
351 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
353 if ((max_size.y > 0) && (base_size.y > max_size.y))
354 base_size.y = max_size.y;
356 if ((max_size.x > 0) && (base_size.x > max_size.x))
357 base_size.x = max_size.x;
360 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
362 if ((min_size.y > 0) && (base_size.y < min_size.y))
363 base_size.y = min_size.y;
365 if ((min_size.x > 0) && (base_size.x < min_size.x))
366 base_size.x = min_size.x;
368 //Check the Which direction is available.
369 //If find a avaialble direction, it adjusts position and size.
370 for (idx = 0; idx < 4; idx++)
372 switch (wd->dir_priority[idx])
374 case ELM_CTXPOPUP_DIRECTION_UP:
375 temp.y = (pos.y - base_size.y);
376 if ((temp.y - arrow_size.y) < hover_area.y)
378 _adjust_pos_x(&pos, &base_size, &hover_area);
379 pos.y -= base_size.y;
380 dir = ELM_CTXPOPUP_DIRECTION_UP;
382 case ELM_CTXPOPUP_DIRECTION_LEFT:
383 temp.x = (pos.x - base_size.x);
384 if ((temp.x - arrow_size.x) < hover_area.x)
386 _adjust_pos_y(&pos, &base_size, &hover_area);
387 pos.x -= base_size.x;
388 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
390 case ELM_CTXPOPUP_DIRECTION_RIGHT:
391 temp.x = (pos.x + base_size.x);
392 if ((temp.x + arrow_size.x) >
393 (hover_area.x + hover_area.w))
395 _adjust_pos_y(&pos, &base_size, &hover_area);
396 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
398 case ELM_CTXPOPUP_DIRECTION_DOWN:
399 temp.y = (pos.y + base_size.y);
400 if ((temp.y + arrow_size.y) >
401 (hover_area.y + hover_area.h))
403 _adjust_pos_x(&pos, &base_size, &hover_area);
404 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
412 //In this case, all directions are invalid because of lack of space.
415 Evas_Coord length[2];
419 length[0] = pos.y - hover_area.y;
420 length[1] = (hover_area.y + hover_area.h) - pos.y;
422 // ELM_CTXPOPUP_DIRECTION_UP
423 if (length[0] > length[1])
425 _adjust_pos_x(&pos, &base_size, &hover_area);
426 pos.y -= base_size.y;
427 dir = ELM_CTXPOPUP_DIRECTION_UP;
428 if (pos.y < (hover_area.y + arrow_size.y))
430 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
431 pos.y = hover_area.y + arrow_size.y;
434 //ELM_CTXPOPUP_DIRECTION_DOWN
437 _adjust_pos_x(&pos, &base_size, &hover_area);
438 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
439 if ((pos.y + arrow_size.y + base_size.y) >
440 (hover_area.y + hover_area.h))
442 ((pos.y + arrow_size.y + base_size.y) -
443 (hover_area.y + hover_area.h));
448 length[0] = pos.x - hover_area.x;
449 length[1] = (hover_area.x + hover_area.w) - pos.x;
451 //ELM_CTXPOPUP_DIRECTION_LEFT
452 if (length[0] > length[1])
454 _adjust_pos_y(&pos, &base_size, &hover_area);
455 pos.x -= base_size.x;
456 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
457 if (pos.x < (hover_area.x + arrow_size.x))
459 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
460 pos.x = hover_area.x + arrow_size.x;
463 //ELM_CTXPOPUP_DIRECTION_RIGHT
466 _adjust_pos_y(&pos, &base_size, &hover_area);
467 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
468 if (pos.x + (arrow_size.x + base_size.x) >
469 hover_area.x + hover_area.w)
471 ((pos.x + arrow_size.x + base_size.x) -
472 (hover_area.x + hover_area.w));
477 //Final position and size.
480 rect->w = base_size.x;
481 rect->h = base_size.y;
487 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
490 Evas_Coord_Rectangle arrow_size;
491 Evas_Coord_Rectangle base_size;
495 wd = elm_widget_data_get(obj);
498 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
499 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
501 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
502 &base_size.w, &base_size.h);
504 edje_object_part_unswallow(wd->base, wd->arrow);
508 case ELM_CTXPOPUP_DIRECTION_RIGHT:
509 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
510 edje_object_part_swallow(wd->base,
511 "elm.swallow.arrow_left",
514 // if user does not use dragable part
515 arrow_size.y = (y - (arrow_size.h * 0.5));
520 if (y < ((arrow_size.h * 0.5) + base_size.y))
522 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
523 y = base_size.h - arrow_size.h;
525 y = y - base_size.y - (arrow_size.h * 0.5);
526 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
527 edje_object_part_drag_value_set(wd->base,
528 "elm.swallow.arrow_left",
533 case ELM_CTXPOPUP_DIRECTION_LEFT:
534 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
535 edje_object_part_swallow(wd->base,
536 "elm.swallow.arrow_right",
539 // if user does not use dragable part
540 arrow_size.y = (y - (arrow_size.h * 0.5));
541 arrow_size.x = (x - arrow_size.w);
545 if (y < ((arrow_size.h * 0.5) + base_size.y))
547 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
548 y = base_size.h - arrow_size.h;
550 y = y - base_size.y - (arrow_size.h * 0.5);
551 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
552 edje_object_part_drag_value_set(wd->base,
553 "elm.swallow.arrow_right",
558 case ELM_CTXPOPUP_DIRECTION_DOWN:
559 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
560 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
562 // if user does not use dragable part
563 arrow_size.x = (x - (arrow_size.w * 0.5));
568 if (x < ((arrow_size.w * 0.5) + base_size.x))
570 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
571 x = base_size.w - arrow_size.w;
573 x = x - base_size.x - (arrow_size.w * 0.5);
574 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
575 edje_object_part_drag_value_set(wd->base,
576 "elm.swallow.arrow_up",
581 case ELM_CTXPOPUP_DIRECTION_UP:
582 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
583 edje_object_part_swallow(wd->base,
584 "elm.swallow.arrow_down",
587 // if user does not use dragable part
588 arrow_size.x = (x - (arrow_size.w * 0.5));
589 arrow_size.y = (y - arrow_size.h);
593 if (x < ((arrow_size.w * 0.5) + base_size.x))
595 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
596 x = base_size.w - arrow_size.w;
597 else x = x - base_size.x - (arrow_size.w * 0.5);
598 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
599 edje_object_part_drag_value_set(wd->base,
600 "elm.swallow.arrow_down",
609 // if user does not use dragable part
610 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
613 //TODO: compress item - different from opensource
615 _compress_item(Evas_Object *obj)
619 Elm_Ctxpopup_Item *item;
621 wd = elm_widget_data_get(obj);
624 EINA_LIST_FOREACH(wd->items, elist, item)
626 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
631 _sizing_eval(Evas_Object *obj)
635 Elm_Ctxpopup_Item *item;
636 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
637 Evas_Coord_Point box_size = { 0, 0 };
638 Evas_Coord_Point _box_size = { 0, 0 };
640 wd = elm_widget_data_get(obj);
642 if (!wd->parent) return;
645 EINA_LIST_FOREACH(wd->items, elist, item)
647 _item_sizing_eval(item);
648 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
651 if (_box_size.x > box_size.x)
652 box_size.x = _box_size.x;
653 if (_box_size.y != -1)
654 box_size.y += _box_size.y;
658 if (_box_size.x != -1)
659 box_size.x += _box_size.x;
660 if (_box_size.y > box_size.y)
661 box_size.y = _box_size.y;
667 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
668 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
672 wd->dir = _calc_base_geometry(obj, &rect);
674 //TODO: compress item - different from opensource
675 if (!wd->horizontal && !wd->content)
678 _update_arrow(obj, wd->dir);
679 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
681 //resize scroller according to final size.
683 evas_object_smart_calculate(wd->scr);
685 evas_object_move(wd->base, rect.x, rect.y);
686 evas_object_resize(wd->base, rect.w, rect.h);
690 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
691 Evas_Coord_Rectangle *rect)
693 Evas_Coord arrow_w, arrow_h;
695 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
699 case ELM_CTXPOPUP_DIRECTION_RIGHT:
702 case ELM_CTXPOPUP_DIRECTION_LEFT:
705 case ELM_CTXPOPUP_DIRECTION_DOWN:
708 case ELM_CTXPOPUP_DIRECTION_UP:
717 _del_pre_hook(Evas_Object *obj)
721 wd = elm_widget_data_get(obj);
724 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
725 _parent_resize, obj);
727 _parent_cut_off(obj);
731 _del_hook(Evas_Object *obj)
735 wd = elm_widget_data_get(obj);
738 elm_ctxpopup_clear(obj);
739 evas_object_del(wd->arrow);
740 evas_object_del(wd->base);
744 //FIXME: lost the content size when theme hook is called.
746 _theme_hook(Evas_Object *obj)
750 Elm_Ctxpopup_Item *item;
753 wd = elm_widget_data_get(obj);
757 EINA_LIST_FOREACH(wd->items, elist, item)
759 if (item->label && item->icon)
760 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
761 "icon_text_style_item",
762 elm_widget_style_get(obj));
763 else if (item->label)
764 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
765 elm_widget_style_get(obj));
767 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
768 elm_widget_style_get(obj));
770 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
772 if (elm_widget_item_disabled_get(item))
773 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
776 * For separator, if the first item has visible separator,
777 * then it should be aligned with edge of the base part.
778 * In some cases, it gives improper display. Ex) rounded corner
779 * So the first item separator should be invisible.
782 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
786 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
788 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
791 edje_object_message_signal_process(VIEW(item));
794 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
795 elm_widget_style_get(obj));
796 if (evas_object_visible_get(wd->bg))
797 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
799 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
800 elm_widget_style_get(obj));
801 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
802 elm_widget_style_get(obj));
806 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
807 elm_object_style_set(wd->scr, "ctxpopup");
809 elm_object_style_set(wd->scr, elm_object_style_get(obj));
814 _scroller_size_reset(wd);
820 _content_set_hook(Evas_Object *obj, const char *part,
821 Evas_Object *content)
823 ELM_CHECK_WIDTYPE(obj, widtype);
827 if (part && strcmp(part, "default")) return;
829 wd = elm_widget_data_get(obj);
830 if ((!wd) || (!content)) return;
832 if (wd->items) elm_ctxpopup_clear(obj);
833 if (wd->content) evas_object_del(wd->content);
835 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
838 elm_widget_sub_object_add(obj, content);
839 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
840 edje_object_message_signal_process(wd->base);
842 wd->content = content;
849 _content_unset_hook(Evas_Object *obj, const char *part)
851 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
854 Evas_Object *content;
855 if (part && strcmp(part, "default")) return NULL;
856 wd = elm_widget_data_get(obj);
857 if (!wd) return NULL;
859 content = wd->content;
860 if (!content) return NULL;
862 edje_object_part_unswallow(wd->base, content);
863 elm_widget_sub_object_del(obj, content);
864 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
865 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
874 _content_get_hook(const Evas_Object *obj, const char *part)
876 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
878 if (part && strcmp(part, "default")) return NULL;
879 wd = elm_widget_data_get(obj);
880 if (!wd) return NULL;
885 _item_text_set_hook(Elm_Object_Item *it,
889 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
892 Elm_Ctxpopup_Item *ctxpopup_it;
894 if (part && strcmp(part, "default")) return;
896 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
898 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
901 _item_label_set(ctxpopup_it, label);
902 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
906 _scroller_size_reset(wd);
907 _sizing_eval(WIDGET(ctxpopup_it));
912 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
914 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
915 Elm_Ctxpopup_Item *ctxpopup_it;
916 if (part && strcmp(part, "default")) return NULL;
917 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
918 return ctxpopup_it->label;
922 _item_content_set_hook(Elm_Object_Item *it,
924 Evas_Object *content)
926 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
928 Elm_Ctxpopup_Item *ctxpopup_it;
930 if (part && strcmp(part, "icon")) return;
932 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
934 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
937 _item_icon_set(ctxpopup_it, content);
938 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
942 _scroller_size_reset(wd);
943 _sizing_eval(WIDGET(ctxpopup_it));
948 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
950 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
951 Elm_Ctxpopup_Item *ctxpopup_it;
952 if (part && strcmp(part, "icon")) return NULL;
953 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
954 return ctxpopup_it->icon;
958 _item_disable_set_hook(Elm_Object_Item *it)
960 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
963 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
965 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
968 if (elm_widget_item_disabled_get(it))
969 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
971 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
975 _item_signal_emit_hook(Elm_Object_Item *it,
976 const char *emission,
979 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
980 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
981 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
985 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
986 const char *emission __UNUSED__, const char *source __UNUSED__)
988 evas_object_hide(data);
992 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
993 void *event_info __UNUSED__)
997 Elm_Ctxpopup_Item *item;
1000 wd = elm_widget_data_get(obj);
1003 if ((!wd->items) && (!wd->content)) return;
1005 wd->visible = EINA_TRUE;
1007 evas_object_show(wd->bg);
1008 evas_object_show(wd->base);
1009 evas_object_show(wd->arrow);
1011 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
1013 EINA_LIST_FOREACH(wd->items, elist, item)
1016 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1020 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1022 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1030 _hide(Evas_Object *obj)
1032 Widget_Data *wd = elm_widget_data_get(obj);
1036 evas_object_hide(wd->bg);
1037 evas_object_hide(wd->arrow);
1038 evas_object_hide(wd->base);
1040 _scroller_size_reset(wd);
1042 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1043 wd->visible = EINA_FALSE;
1047 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1048 void *event_info __UNUSED__)
1052 wd = elm_widget_data_get(obj);
1053 if ((!wd) || (!wd->visible))
1060 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1061 void *event_info __UNUSED__)
1066 wd = elm_widget_data_get(data);
1068 if (!wd->visible) return;
1069 if (wd->finished) return;
1071 evas_object_geometry_get(obj, 0, 0, &w, &h);
1073 if (w != 0 && h != 0)
1075 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1078 wd->finished = EINA_TRUE;
1083 if (wd->max_sc_w < w)
1085 if (wd->max_sc_h < h)
1092 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1093 void *event_info __UNUSED__)
1097 wd = elm_widget_data_get(obj);
1102 evas_object_show(wd->arrow);
1104 _scroller_size_reset(wd);
1109 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1110 const char *emission __UNUSED__, const char *source __UNUSED__)
1112 Elm_Ctxpopup_Item *item = data;
1115 if (elm_widget_item_disabled_get(item)) return;
1118 item->func((void*) item->base.data, WIDGET(item), data);
1122 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1126 elm_widget_sub_object_del(VIEW(item), item->icon);
1127 evas_object_del(item->icon);
1133 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1134 edje_object_message_signal_process(VIEW(item));
1138 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1140 if (!eina_stringshare_replace(&item->label, label))
1143 edje_object_part_text_set(VIEW(item), "elm.text", label);
1144 edje_object_message_signal_process(VIEW(item));
1148 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1152 wd = elm_widget_data_get(WIDGET(item));
1155 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1156 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1157 elm_widget_style_get(WIDGET(item)));
1158 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1159 _item_select_cb, item);
1160 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1161 evas_object_show(VIEW(item));
1165 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1166 void *event_info __UNUSED__)
1168 elm_object_content_unset(data);
1172 _list_del(Widget_Data *wd)
1174 if (!wd->scr) return;
1176 edje_object_part_unswallow(wd->base, wd->scr);
1177 evas_object_del(wd->scr);
1183 _list_new(Evas_Object *obj)
1186 wd = elm_widget_data_get(obj);
1190 wd->scr = elm_scroller_add(obj);
1191 elm_object_style_set(wd->scr, "ctxpopup");
1192 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1193 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1194 _scroller_resize, obj);
1195 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1198 wd->box = elm_box_add(obj);
1199 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1202 elm_object_content_set(wd->scr, wd->box);
1203 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1207 _remove_items(Widget_Data *wd)
1210 Elm_Ctxpopup_Item *item;
1212 if (!wd->items) return;
1214 EINA_LIST_FOREACH(wd->items, elist, item)
1217 eina_stringshare_del(item->label);
1219 evas_object_del(item->icon);
1220 wd->items = eina_list_remove(wd->items, item);
1228 elm_ctxpopup_add(Evas_Object *parent)
1233 Evas_Coord x, y, w, h;
1235 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1237 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1238 elm_widget_type_set(obj, "ctxpopup");
1239 elm_widget_sub_object_add(parent, obj);
1240 elm_widget_data_set(obj, wd);
1241 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1242 elm_widget_del_hook_set(obj, _del_hook);
1243 elm_widget_theme_hook_set(obj, _theme_hook);
1244 elm_widget_content_set_hook_set(obj, _content_set_hook);
1245 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1246 elm_widget_content_get_hook_set(obj, _content_get_hook);
1249 wd->bg = edje_object_add(e);
1250 elm_widget_sub_object_add(obj, wd->bg);
1251 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1252 evas_object_geometry_get(parent, &x, &y, &w, &h);
1253 evas_object_move(wd->bg, x, y);
1254 evas_object_resize(wd->bg, w, h);
1255 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1256 _bg_clicked_cb, obj);
1259 wd->base = edje_object_add(e);
1260 elm_widget_sub_object_add(obj, wd->base);
1261 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1264 wd->arrow = edje_object_add(e);
1265 elm_widget_sub_object_add(obj, wd->arrow);
1266 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1268 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1269 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1270 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1271 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1273 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1275 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1277 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1279 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1281 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1282 _ctxpopup_changed_size_hints, NULL);
1283 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1284 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1285 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1286 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1288 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1290 //default parent is to be hover parent
1291 elm_ctxpopup_hover_parent_set(obj, parent);
1297 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1299 return _item_content_get_hook(it, "icon");
1303 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1305 _item_content_set_hook(it, "icon", icon);
1309 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1311 return _item_text_get_hook(it, NULL);
1315 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1317 _item_text_set_hook(it, NULL, label);
1321 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1323 ELM_CHECK_WIDTYPE(obj, widtype);
1326 Evas_Coord x, y, w, h;
1328 wd = elm_widget_data_get(obj);
1331 _parent_cut_off(obj);
1335 evas_object_event_callback_add(parent,
1339 evas_object_event_callback_add(parent,
1343 evas_object_event_callback_add(parent,
1344 EVAS_CALLBACK_RESIZE,
1349 elm_widget_sub_object_add(parent, obj);
1350 wd->parent = parent;
1353 evas_object_geometry_get(parent, &x, &y, &w, &h);
1354 evas_object_move(wd->bg, x, y);
1355 evas_object_resize(wd->bg, w, h);
1357 if (wd->visible) _sizing_eval(obj);
1361 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1363 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1367 wd = elm_widget_data_get(obj);
1368 if (!wd) return NULL;
1374 elm_ctxpopup_clear(Evas_Object * obj)
1376 ELM_CHECK_WIDTYPE(obj, widtype);
1378 Widget_Data *wd = elm_widget_data_get(obj);
1386 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1388 ELM_CHECK_WIDTYPE(obj, widtype);
1392 Elm_Ctxpopup_Item *item;
1395 wd = elm_widget_data_get(obj);
1398 wd->horizontal = !!horizontal;
1400 if ((!wd->scr) && (!wd->box))
1405 elm_box_horizontal_set(wd->box, EINA_FALSE);
1406 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1408 EINA_LIST_FOREACH(wd->items, elist, item)
1411 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1413 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1418 elm_box_horizontal_set(wd->box, EINA_TRUE);
1419 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1421 EINA_LIST_FOREACH(wd->items, elist, item)
1424 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1426 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1435 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1437 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1441 wd = elm_widget_data_get(obj);
1442 if (!wd) return EINA_FALSE;
1444 return wd->horizontal;
1447 EAPI Elm_Object_Item *
1448 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1449 Evas_Object *icon, Evas_Smart_Cb func,
1452 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1455 Elm_Ctxpopup_Item *item;
1457 wd = elm_widget_data_get(obj);
1458 if (!wd) return NULL;
1460 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1461 if (!item) return NULL;
1463 elm_widget_item_disable_set_hook_set(item, _item_disable_set_hook);
1464 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1465 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1466 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1467 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1468 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1470 //The first item is appended.
1472 evas_object_del(elm_object_content_unset(obj));
1478 item->base.data = data;
1481 _item_new(item, "icon_text_style_item");
1483 _item_new(item, "text_style_item");
1485 _item_new(item, "icon_style_item");
1487 _item_icon_set(item, icon);
1488 _item_label_set(item, label);
1489 elm_box_pack_end(wd->box, VIEW(item));
1490 wd->items = eina_list_append(wd->items, item);
1494 _scroller_size_reset(wd);
1498 return (Elm_Object_Item *) item;
1502 elm_ctxpopup_item_del(Elm_Object_Item *it)
1504 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1507 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1509 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1512 if (ctxpopup_it->icon)
1513 evas_object_del(ctxpopup_it->icon);
1514 if (VIEW(ctxpopup_it))
1515 evas_object_del(VIEW(ctxpopup_it));
1517 eina_stringshare_del(ctxpopup_it->label);
1519 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1521 if (eina_list_count(wd->items) < 1)
1525 _sizing_eval(WIDGET(ctxpopup_it));
1531 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1533 elm_object_item_disabled_set(it, disabled);
1537 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1539 return elm_object_item_disabled_get(it);
1543 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1545 elm_object_content_set(obj, content);
1549 elm_ctxpopup_content_unset(Evas_Object *obj)
1551 return elm_object_content_unset(obj);
1555 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1556 Elm_Ctxpopup_Direction first,
1557 Elm_Ctxpopup_Direction second,
1558 Elm_Ctxpopup_Direction third,
1559 Elm_Ctxpopup_Direction fourth)
1561 ELM_CHECK_WIDTYPE(obj, widtype);
1564 wd = elm_widget_data_get(obj);
1567 wd->dir_priority[0] = first;
1568 wd->dir_priority[1] = second;
1569 wd->dir_priority[2] = third;
1570 wd->dir_priority[3] = fourth;
1577 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1578 Elm_Ctxpopup_Direction *first,
1579 Elm_Ctxpopup_Direction *second,
1580 Elm_Ctxpopup_Direction *third,
1581 Elm_Ctxpopup_Direction *fourth)
1583 ELM_CHECK_WIDTYPE(obj, widtype);
1586 wd = elm_widget_data_get(obj);
1589 if (first) *first = wd->dir_priority[0];
1590 if (second) *second = wd->dir_priority[1];
1591 if (third) *third = wd->dir_priority[2];
1592 if (fourth) *fourth = wd->dir_priority[3];
1595 EAPI Elm_Ctxpopup_Direction
1596 elm_ctxpopup_direction_get(const Evas_Object *obj)
1598 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1601 wd = elm_widget_data_get(obj);
1602 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;