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 Evas_Object *hover_parent;
29 Elm_Ctxpopup_Direction dir;
30 Elm_Ctxpopup_Direction dir_priority[4];
31 Evas_Coord max_sc_w, max_sc_h;
32 Eina_Bool horizontal:1;
37 static const char *widtype = NULL;
39 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
40 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
41 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
42 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
43 static void _scroller_size_reset(Widget_Data *wd);
44 static void _hover_parent_callbacks_del(Evas_Object *obj);
45 static void _parent_resize(void *data,
49 static void _hover_parent_resize(void *data, Evas *e __UNUSED__,
50 Evas_Object *obj __UNUSED__,
51 void *event_info __UNUSED__);
52 static void _hover_parent_move(void *data, Evas *e __UNUSED__,
53 Evas_Object *obj __UNUSED__,
54 void *event_info __UNUSED__);
55 static void _hover_parent_del(void *data, Evas *e __UNUSED__,
56 Evas_Object *obj __UNUSED__,
57 void *event_info __UNUSED__);
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, Elm_Ctxpopup_Direction dir);
71 static void _sizing_eval(Evas_Object *obj);
72 static void _shift_base_by_arrow(Evas_Object *arrow,
73 Elm_Ctxpopup_Direction dir,
74 Evas_Coord_Rectangle *rect);
75 static void _del_pre_hook(Evas_Object *obj);
76 static void _del_hook(Evas_Object *obj);
77 static void _theme_hook(Evas_Object *obj);
78 static void _bg_clicked_cb(void *data, Evas_Object *obj,
81 static void _ctxpopup_show(void *data,
85 static void _hide(Evas_Object *obj);
86 static void _ctxpopup_hide(void *data,
90 static void _scroller_resize(void *data,
94 static void _ctxpopup_move(void *data,
98 static void _item_select_cb(void *data, Evas_Object *obj,
101 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
102 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
103 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
104 static void _content_del(void *data,
108 static void _list_del(Widget_Data *wd);
109 static void _list_new(Evas_Object *obj);
110 static void _remove_items(Widget_Data * wd);
112 static const char SIG_DISMISSED[] = "dismissed";
114 static const Evas_Smart_Cb_Description _signals[] = {
119 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
120 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
121 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
124 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
125 void *event_info __UNUSED__)
127 Widget_Data *wd = elm_widget_data_get(obj);
129 if ((!wd) || (!wd->scr)) return;
131 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
135 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
136 void *event_info __UNUSED__)
138 Widget_Data *wd = elm_widget_data_get(obj);
140 if ((!wd) || (!wd->scr)) return;
143 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
145 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
149 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
151 Widget_Data *wd = elm_widget_data_get(obj);
153 if ((!wd) || (!wd->scr)) return;
155 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
159 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
161 Widget_Data *wd = elm_widget_data_get(obj);
163 if ((!wd) || (!wd->scr)) return;
166 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
168 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
172 _scroller_size_reset(Widget_Data *wd)
174 wd->finished = EINA_FALSE;
180 _hover_parent_callbacks_del(Evas_Object *obj)
182 Widget_Data *wd = elm_widget_data_get(obj);
184 if ((!wd) || (!wd->hover_parent))
187 evas_object_event_callback_del_full(wd->hover_parent,
191 evas_object_event_callback_del_full(wd->hover_parent,
195 evas_object_event_callback_del_full(wd->hover_parent,
196 EVAS_CALLBACK_RESIZE,
197 _hover_parent_resize,
202 _hover_parent_resize(void *data,
204 Evas_Object *obj __UNUSED__,
205 void *event_info __UNUSED__)
207 Widget_Data *wd = elm_widget_data_get(data);
213 _scroller_size_reset(wd);
219 _hover_parent_move(void *data,
221 Evas_Object *obj __UNUSED__,
222 void *event_info __UNUSED__)
224 Widget_Data *wd = elm_widget_data_get(data);
230 _scroller_size_reset(wd);
236 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
237 void *event_info __UNUSED__)
239 Widget_Data *wd = elm_widget_data_get(data);
243 wd->hover_parent = NULL;
247 _item_sizing_eval(Elm_Ctxpopup_Item *item)
249 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
253 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
255 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
256 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
260 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
261 Evas_Coord_Rectangle *hover_area)
263 pos->x -= (base_size->x / 2);
265 if (pos->x < hover_area->x)
266 pos->x = hover_area->x;
267 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
268 pos->x = (hover_area->x + hover_area->w) - base_size->x;
270 if (base_size->x > hover_area->w)
271 base_size->x -= (base_size->x - hover_area->w);
273 if (pos->x < hover_area->x)
274 pos->x = hover_area->x;
278 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
279 Evas_Coord_Rectangle *hover_area)
281 pos->y -= (base_size->y / 2);
283 if (pos->y < hover_area->y)
284 pos->y = hover_area->y;
285 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
286 pos->y = hover_area->y + hover_area->h - base_size->y;
288 if (base_size->y > hover_area->h)
289 base_size->y -= (base_size->y - hover_area->h);
291 if (pos->y < hover_area->y)
292 pos->y = hover_area->y;
296 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
297 Evas_Object *obj, void *event_info __UNUSED__)
301 wd = elm_widget_data_get(obj);
308 static Elm_Ctxpopup_Direction
309 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
312 Evas_Coord_Point pos = {0, 0};
313 Evas_Coord_Point base_size;
314 Evas_Coord_Point max_size;
315 Evas_Coord_Point min_size;
316 Evas_Coord_Rectangle hover_area;
317 Evas_Coord_Rectangle parent_size;
318 Evas_Coord_Point arrow_size;
319 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DOWN;
320 Evas_Coord_Point temp;
323 wd = elm_widget_data_get(obj);
325 if ((!wd) || (!rect))
326 return ELM_CTXPOPUP_DIRECTION_DOWN;
328 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
329 &arrow_size.x, &arrow_size.y);
330 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
332 //Initialize Area Rectangle.
333 if (wd->hover_parent)
334 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
335 &hover_area.w, &hover_area.h);
338 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
339 &parent_size.w, &parent_size.h);
340 hover_area.x = parent_size.x;
341 hover_area.y = parent_size.y;
342 hover_area.w = parent_size.w;
343 hover_area.h = parent_size.h;
346 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
349 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
350 evas_object_smart_calculate(wd->base);
353 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
355 if ((max_size.y > 0) && (base_size.y > max_size.y))
356 base_size.y = max_size.y;
358 if ((max_size.x > 0) && (base_size.x > max_size.x))
359 base_size.x = max_size.x;
362 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
364 if ((min_size.y > 0) && (base_size.y < min_size.y))
365 base_size.y = min_size.y;
367 if ((min_size.x > 0) && (base_size.x < min_size.x))
368 base_size.x = min_size.x;
370 //Check the Which direction is available.
371 //If find a avaialble direction, it adjusts position and size.
372 for (idx = 0; idx < 4; idx++)
374 switch (wd->dir_priority[idx])
376 case ELM_CTXPOPUP_DIRECTION_UP:
377 temp.y = (pos.y - base_size.y);
378 if ((temp.y - arrow_size.y) < hover_area.y)
380 _adjust_pos_x(&pos, &base_size, &hover_area);
381 pos.y -= base_size.y;
382 dir = ELM_CTXPOPUP_DIRECTION_UP;
384 case ELM_CTXPOPUP_DIRECTION_LEFT:
385 temp.x = (pos.x - base_size.x);
386 if ((temp.x - arrow_size.x) < hover_area.x)
388 _adjust_pos_y(&pos, &base_size, &hover_area);
389 pos.x -= base_size.x;
390 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
392 case ELM_CTXPOPUP_DIRECTION_RIGHT:
393 temp.x = (pos.x + base_size.x);
394 if ((temp.x + arrow_size.x) >
395 (hover_area.x + hover_area.w))
397 _adjust_pos_y(&pos, &base_size, &hover_area);
398 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
400 case ELM_CTXPOPUP_DIRECTION_DOWN:
401 temp.y = (pos.y + base_size.y);
402 if ((temp.y + arrow_size.y) >
403 (hover_area.y + hover_area.h))
405 _adjust_pos_x(&pos, &base_size, &hover_area);
406 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
414 //In this case, all directions are invalid because of lack of space.
417 Evas_Coord length[2];
421 length[0] = pos.y - hover_area.y;
422 length[1] = (hover_area.y + hover_area.h) - pos.y;
424 // ELM_CTXPOPUP_DIRECTION_UP
425 if (length[0] > length[1])
427 _adjust_pos_x(&pos, &base_size, &hover_area);
428 pos.y -= base_size.y;
429 dir = ELM_CTXPOPUP_DIRECTION_UP;
430 if (pos.y < (hover_area.y + arrow_size.y))
432 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
433 pos.y = hover_area.y + arrow_size.y;
436 //ELM_CTXPOPUP_DIRECTION_DOWN
439 _adjust_pos_x(&pos, &base_size, &hover_area);
440 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
441 if ((pos.y + arrow_size.y + base_size.y) >
442 (hover_area.y + hover_area.h))
444 ((pos.y + arrow_size.y + base_size.y) -
445 (hover_area.y + hover_area.h));
450 length[0] = pos.x - hover_area.x;
451 length[1] = (hover_area.x + hover_area.w) - pos.x;
453 //ELM_CTXPOPUP_DIRECTION_LEFT
454 if (length[0] > length[1])
456 _adjust_pos_y(&pos, &base_size, &hover_area);
457 pos.x -= base_size.x;
458 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
459 if (pos.x < (hover_area.x + arrow_size.x))
461 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
462 pos.x = hover_area.x + arrow_size.x;
465 //ELM_CTXPOPUP_DIRECTION_RIGHT
468 _adjust_pos_y(&pos, &base_size, &hover_area);
469 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
470 if (pos.x + (arrow_size.x + base_size.x) >
471 hover_area.x + hover_area.w)
473 ((pos.x + arrow_size.x + base_size.x) -
474 (hover_area.x + hover_area.w));
479 //Final position and size.
482 rect->w = base_size.x;
483 rect->h = base_size.y;
489 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
492 Evas_Coord_Rectangle arrow_size;
493 Evas_Coord_Rectangle base_size;
496 wd = elm_widget_data_get(obj);
499 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
500 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
502 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
503 &base_size.w, &base_size.h);
505 edje_object_part_unswallow(wd->base, wd->arrow);
509 case ELM_CTXPOPUP_DIRECTION_RIGHT:
510 edje_object_signal_emit(wd->arrow,
514 // if user does not use dragable part
515 arrow_size.y = (y - (arrow_size.h * 0.5));
518 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
521 if (y < ((arrow_size.h * 0.5) + base_size.y))
523 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
524 y = base_size.h - arrow_size.h;
526 y = y - base_size.y - (arrow_size.h * 0.5);
527 edje_object_part_drag_value_set(wd->base,
528 "elm.swallow.arrow_left",
530 (double) (y) / (double) (base_size.h - arrow_size.h));
533 case ELM_CTXPOPUP_DIRECTION_LEFT:
534 edje_object_signal_emit(wd->arrow,
538 // if user does not use dragable part
539 arrow_size.y = (y - (arrow_size.h * 0.5));
540 arrow_size.x = (x - arrow_size.w);
542 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
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;
549 else y = y - base_size.y - (arrow_size.h * 0.5);
550 edje_object_part_drag_value_set(wd->base,
551 "elm.swallow.arrow_right",
553 (double) (y) / (double) (base_size.h - arrow_size.h));
556 case ELM_CTXPOPUP_DIRECTION_DOWN:
557 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
559 // if user does not use dragable part
560 arrow_size.x = (x - (arrow_size.w * 0.5));
563 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
566 if (x < ((arrow_size.w * 0.5) + base_size.x))
568 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
569 x = base_size.w - arrow_size.w;
571 x = x - base_size.x - (arrow_size.w * 0.5);
572 edje_object_part_drag_value_set(wd->base,
573 "elm.swallow.arrow_up",
574 (double) (x) / (double) (base_size.w - arrow_size.w),
578 case ELM_CTXPOPUP_DIRECTION_UP:
579 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
581 // if user does not use dragable part
582 arrow_size.x = (x - (arrow_size.w * 0.5));
583 arrow_size.y = (y - arrow_size.h);
585 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
588 if (x < ((arrow_size.w * 0.5) + base_size.x))
590 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
591 x = base_size.w - arrow_size.w;
592 else x = x - base_size.x - (arrow_size.w * 0.5);
593 edje_object_part_drag_value_set(wd->base,
594 "elm.swallow.arrow_down",
595 (double) (x) / (double) (base_size.w - arrow_size.w),
603 // if user does not use dragable part
604 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
607 //TODO: compress item - different from opensource
609 _compress_item(Evas_Object *obj)
613 Elm_Ctxpopup_Item *item;
615 wd = elm_widget_data_get(obj);
618 EINA_LIST_FOREACH(wd->items, elist, item)
620 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
625 _sizing_eval(Evas_Object *obj)
629 Elm_Ctxpopup_Item *item;
630 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
631 Evas_Coord_Point box_size = { 0, 0 };
632 Evas_Coord_Point _box_size = { 0, 0 };
634 wd = elm_widget_data_get(obj);
635 if ((!wd) || (!wd->parent)) return;
638 EINA_LIST_FOREACH(wd->items, elist, item)
640 _item_sizing_eval(item);
641 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
644 if (_box_size.x > box_size.x)
645 box_size.x = _box_size.x;
646 if (_box_size.y != -1)
647 box_size.y += _box_size.y;
651 if (_box_size.x != -1)
652 box_size.x += _box_size.x;
653 if (_box_size.y > box_size.y)
654 box_size.y = _box_size.y;
660 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
661 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
665 wd->dir = _calc_base_geometry(obj, &rect);
667 //TODO: compress item - different from opensource
668 if (!wd->horizontal && !wd->content)
671 _update_arrow(obj, wd->dir);
672 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
674 //resize scroller according to final size.
676 evas_object_smart_calculate(wd->scr);
678 evas_object_move(wd->base, rect.x, rect.y);
679 evas_object_resize(wd->base, rect.w, rect.h);
683 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
684 Evas_Coord_Rectangle *rect)
686 Evas_Coord arrow_w, arrow_h;
688 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
692 case ELM_CTXPOPUP_DIRECTION_RIGHT:
695 case ELM_CTXPOPUP_DIRECTION_LEFT:
698 case ELM_CTXPOPUP_DIRECTION_DOWN:
701 case ELM_CTXPOPUP_DIRECTION_UP:
710 _del_pre_hook(Evas_Object *obj)
714 wd = elm_widget_data_get(obj);
717 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
718 _parent_resize, obj);
720 _hover_parent_callbacks_del(obj);
724 _del_hook(Evas_Object *obj)
728 wd = elm_widget_data_get(obj);
731 elm_ctxpopup_clear(obj);
732 evas_object_del(wd->arrow);
733 evas_object_del(wd->base);
737 //FIXME: lost the content size when theme hook is called.
739 _theme_hook(Evas_Object *obj)
743 Elm_Ctxpopup_Item *item;
746 wd = elm_widget_data_get(obj);
750 EINA_LIST_FOREACH(wd->items, elist, item)
752 if (item->label && item->icon)
753 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
754 "icon_text_style_item",
755 elm_widget_style_get(obj));
756 else if (item->label)
757 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
758 elm_widget_style_get(obj));
760 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
761 elm_widget_style_get(obj));
763 edje_object_part_text_set(item->base.view, "elm.text", item->label);
766 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
769 * For separator, if the first item has visible separator,
770 * then it should be aligned with edge of the base part.
771 * In some cases, it gives improper display. Ex) rounded corner
772 * So the first item separator should be invisible.
775 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
779 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
781 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
784 edje_object_message_signal_process(item->base.view);
787 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
788 elm_widget_style_get(obj));
789 if (evas_object_visible_get(wd->bg))
790 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
792 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
793 elm_widget_style_get(obj));
794 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
795 elm_widget_style_get(obj));
799 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
800 elm_object_style_set(wd->scr, "ctxpopup");
802 elm_object_style_set(wd->scr, elm_object_style_get(obj));
807 _scroller_size_reset(wd);
813 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
814 const char *emission __UNUSED__, const char *source __UNUSED__)
816 evas_object_hide(data);
820 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
821 void *event_info __UNUSED__)
826 wd = elm_widget_data_get(data);
829 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
830 evas_object_resize(wd->bg, w, h);
832 if (!wd->visible) return;
838 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
839 void *event_info __UNUSED__)
843 Elm_Ctxpopup_Item *item;
846 wd = elm_widget_data_get(obj);
849 if ((!wd->items) && (!wd->content)) return;
851 wd->visible = EINA_TRUE;
853 evas_object_show(wd->bg);
854 evas_object_show(wd->base);
855 evas_object_show(wd->arrow);
857 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
859 EINA_LIST_FOREACH(wd->items, elist, item)
862 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
866 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
868 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
876 _hide(Evas_Object *obj)
878 Widget_Data *wd = elm_widget_data_get(obj);
882 evas_object_hide(wd->bg);
883 evas_object_hide(wd->arrow);
884 evas_object_hide(wd->base);
886 _scroller_size_reset(wd);
888 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
889 wd->visible = EINA_FALSE;
893 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
894 void *event_info __UNUSED__)
898 wd = elm_widget_data_get(obj);
899 if ((!wd) || (!wd->visible))
906 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
907 void *event_info __UNUSED__)
912 wd = elm_widget_data_get(data);
914 if (!wd->visible) return;
915 if (wd->finished) return;
917 evas_object_geometry_get(obj, 0, 0, &w, &h);
919 if (w != 0 && h != 0)
921 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
924 wd->finished = EINA_TRUE;
929 if (wd->max_sc_w < w)
931 if (wd->max_sc_h < h)
938 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
939 void *event_info __UNUSED__)
943 wd = elm_widget_data_get(obj);
948 evas_object_show(wd->arrow);
950 _scroller_size_reset(wd);
955 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
956 const char *emission __UNUSED__, const char *source __UNUSED__)
958 Elm_Ctxpopup_Item *item = data;
961 if (item->disabled) return;
964 item->func((void*) item->base.data, item->base.widget, data);
968 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
972 elm_widget_sub_object_del(item->base.view, item->icon);
973 evas_object_del(item->icon);
979 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
980 edje_object_message_signal_process(item->base.view);
984 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
986 if (!eina_stringshare_replace(&item->label, label))
989 edje_object_part_text_set(item->base.view, "elm.text", label);
990 edje_object_message_signal_process(item->base.view);
994 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
998 wd = elm_widget_data_get(item->base.widget);
1001 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
1002 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
1003 elm_widget_style_get(item->base.widget));
1004 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
1005 _item_select_cb, item);
1006 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
1007 evas_object_show(item->base.view);
1011 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1012 void *event_info __UNUSED__)
1014 elm_ctxpopup_content_unset(data);
1018 _list_del(Widget_Data *wd)
1020 if (!wd->scr) return;
1022 edje_object_part_unswallow(wd->base, wd->scr);
1023 evas_object_del(wd->scr);
1029 _list_new(Evas_Object *obj)
1032 wd = elm_widget_data_get(obj);
1036 wd->scr = elm_scroller_add(obj);
1037 elm_object_style_set(wd->scr, "ctxpopup");
1038 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1039 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1040 _scroller_resize, obj);
1041 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1044 wd->box = elm_box_add(obj);
1045 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1048 elm_scroller_content_set(wd->scr, wd->box);
1049 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1053 _remove_items(Widget_Data *wd)
1056 Elm_Ctxpopup_Item *item;
1058 if (!wd->items) return;
1060 EINA_LIST_FOREACH(wd->items, elist, item)
1063 eina_stringshare_del(item->label);
1065 evas_object_del(item->icon);
1066 wd->items = eina_list_remove(wd->items, item);
1074 elm_ctxpopup_add(Evas_Object *parent)
1079 Evas_Coord x, y, w, h;
1081 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1083 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1084 elm_widget_type_set(obj, "ctxpopup");
1085 elm_widget_sub_object_add(parent, obj);
1086 elm_widget_data_set(obj, wd);
1087 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1088 elm_widget_del_hook_set(obj, _del_hook);
1089 elm_widget_theme_hook_set(obj, _theme_hook);
1091 wd->parent = parent;
1094 wd->bg = edje_object_add(e);
1095 elm_widget_sub_object_add(obj, wd->bg);
1096 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1097 evas_object_geometry_get(parent, &x, &y, &w, &h);
1098 evas_object_move(wd->bg, x, y);
1099 evas_object_resize(wd->bg, w, h);
1100 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1101 _bg_clicked_cb, obj);
1104 wd->base = edje_object_add(e);
1105 elm_widget_sub_object_add(obj, wd->base);
1106 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1109 wd->arrow = edje_object_add(e);
1110 elm_widget_sub_object_add(obj, wd->arrow);
1111 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1113 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1114 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1115 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1116 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1118 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1120 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1122 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1124 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1126 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1127 _ctxpopup_changed_size_hints, NULL);
1128 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1129 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1130 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1131 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1133 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1139 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1141 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1142 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1147 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1149 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1152 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1154 wd = elm_widget_data_get(item->base.widget);
1157 _item_icon_set(item, icon);
1161 _scroller_size_reset(wd);
1162 _sizing_eval(item->base.widget);
1167 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1169 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1170 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1175 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1177 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1180 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1182 wd = elm_widget_data_get(item->base.widget);
1185 _item_label_set(item, label);
1189 _scroller_size_reset(wd);
1190 _sizing_eval(item->base.widget);
1195 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1197 ELM_CHECK_WIDTYPE(obj, widtype);
1201 wd = elm_widget_data_get(obj);
1204 _hover_parent_callbacks_del(obj);
1208 evas_object_event_callback_add(hover_parent,
1212 evas_object_event_callback_add(hover_parent,
1216 evas_object_event_callback_add(hover_parent,
1217 EVAS_CALLBACK_RESIZE,
1218 _hover_parent_resize,
1222 wd->hover_parent = hover_parent;
1226 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1228 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1232 wd = elm_widget_data_get(obj);
1233 if (!wd) return NULL;
1235 return wd->hover_parent;
1239 elm_ctxpopup_clear(Evas_Object * obj)
1241 ELM_CHECK_WIDTYPE(obj, widtype);
1243 Widget_Data *wd = elm_widget_data_get(obj);
1251 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1253 ELM_CHECK_WIDTYPE(obj, widtype);
1257 Elm_Ctxpopup_Item *item;
1260 wd = elm_widget_data_get(obj);
1263 wd->horizontal = !!horizontal;
1265 if ((!wd->scr) && (!wd->box))
1270 elm_box_horizontal_set(wd->box, EINA_FALSE);
1271 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1273 EINA_LIST_FOREACH(wd->items, elist, item)
1276 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
1278 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
1283 elm_box_horizontal_set(wd->box, EINA_TRUE);
1284 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1286 EINA_LIST_FOREACH(wd->items, elist, item)
1289 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
1291 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
1300 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1302 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1306 wd = elm_widget_data_get(obj);
1307 if (!wd) return EINA_FALSE;
1309 return wd->horizontal;
1312 EAPI Elm_Object_Item *
1313 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1314 Evas_Object *icon, Evas_Smart_Cb func,
1317 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1320 Elm_Ctxpopup_Item *item;
1322 wd = elm_widget_data_get(obj);
1323 if (!wd) return NULL;
1325 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1326 if (!item) return NULL;
1328 //The first item is appended.
1330 evas_object_del(elm_ctxpopup_content_unset(obj));
1336 item->base.data = data;
1339 _item_new(item, "icon_text_style_item");
1341 _item_new(item, "text_style_item");
1343 _item_new(item, "icon_style_item");
1345 _item_icon_set(item, icon);
1346 _item_label_set(item, label);
1347 elm_box_pack_end(wd->box, item->base.view);
1348 wd->items = eina_list_append(wd->items, item);
1352 _scroller_size_reset(wd);
1356 return (Elm_Object_Item *) item;
1360 elm_ctxpopup_item_del(Elm_Object_Item *it)
1362 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1365 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1367 wd = elm_widget_data_get(item->base.widget);
1371 evas_object_del(item->icon);
1372 if (item->base.view)
1373 evas_object_del(item->base.view);
1375 eina_stringshare_del(item->label);
1377 wd->items = eina_list_remove(wd->items, item);
1379 if (eina_list_count(wd->items) < 1)
1383 _sizing_eval(item->base.widget);
1389 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1391 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1394 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1396 wd = elm_widget_data_get(item->base.widget);
1399 if (disabled == item->disabled)
1403 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1405 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1407 item->disabled = !!disabled;
1411 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1413 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1414 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1415 return item->disabled;
1419 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1421 ELM_CHECK_WIDTYPE(obj, widtype);
1425 wd = elm_widget_data_get(obj);
1426 if ((!wd) || (!content))
1430 elm_ctxpopup_clear(obj);
1433 evas_object_del(wd->content);
1435 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1438 elm_widget_sub_object_add(obj, content);
1439 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1440 edje_object_message_signal_process(wd->base);
1442 wd->content = content;
1449 elm_ctxpopup_content_unset(Evas_Object *obj)
1451 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1454 Evas_Object *content;
1456 wd = elm_widget_data_get(obj);
1457 if (!wd) return NULL;
1459 content = wd->content;
1460 if (!content) return NULL;
1462 edje_object_part_unswallow(wd->base, content);
1463 elm_widget_sub_object_del(obj, content);
1464 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1465 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1473 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1474 Elm_Ctxpopup_Direction first,
1475 Elm_Ctxpopup_Direction second,
1476 Elm_Ctxpopup_Direction third,
1477 Elm_Ctxpopup_Direction fourth)
1479 ELM_CHECK_WIDTYPE(obj, widtype);
1482 wd = elm_widget_data_get(obj);
1485 wd->dir_priority[0] = first;
1486 wd->dir_priority[1] = second;
1487 wd->dir_priority[2] = third;
1488 wd->dir_priority[3] = fourth;
1495 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1496 Elm_Ctxpopup_Direction *first,
1497 Elm_Ctxpopup_Direction *second,
1498 Elm_Ctxpopup_Direction *third,
1499 Elm_Ctxpopup_Direction *fourth)
1501 ELM_CHECK_WIDTYPE(obj, widtype);
1504 wd = elm_widget_data_get(obj);
1507 if (first) *first = wd->dir_priority[0];
1508 if (second) *second = wd->dir_priority[1];
1509 if (third) *third = wd->dir_priority[2];
1510 if (fourth) *fourth = wd->dir_priority[3];
1513 EAPI Elm_Ctxpopup_Direction
1514 elm_ctxpopup_direction_get(const Evas_Object *obj)
1516 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1519 wd = elm_widget_data_get(obj);
1520 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;