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(VIEW(item), &min_w, &min_h, min_w,
255 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
256 evas_object_size_hint_max_set(VIEW(item), 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;
497 wd = elm_widget_data_get(obj);
500 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
501 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
503 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
504 &base_size.w, &base_size.h);
506 edje_object_part_unswallow(wd->base, wd->arrow);
510 case ELM_CTXPOPUP_DIRECTION_RIGHT:
511 edje_object_signal_emit(wd->arrow,
515 // if user does not use dragable part
516 arrow_size.y = (y - (arrow_size.h * 0.5));
519 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
522 if (y < ((arrow_size.h * 0.5) + base_size.y))
524 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
525 y = base_size.h - arrow_size.h;
527 y = y - base_size.y - (arrow_size.h * 0.5);
528 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
529 edje_object_part_drag_value_set(wd->base,
530 "elm.swallow.arrow_left",
535 case ELM_CTXPOPUP_DIRECTION_LEFT:
536 edje_object_signal_emit(wd->arrow,
540 // if user does not use dragable part
541 arrow_size.y = (y - (arrow_size.h * 0.5));
542 arrow_size.x = (x - arrow_size.w);
544 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
547 if (y < ((arrow_size.h * 0.5) + base_size.y))
549 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
550 y = base_size.h - arrow_size.h;
551 else y = y - base_size.y - (arrow_size.h * 0.5);
552 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
553 edje_object_part_drag_value_set(wd->base,
554 "elm.swallow.arrow_right",
559 case ELM_CTXPOPUP_DIRECTION_DOWN:
560 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
562 // if user does not use dragable part
563 arrow_size.x = (x - (arrow_size.w * 0.5));
566 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
569 if (x < ((arrow_size.w * 0.5) + base_size.x))
571 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
572 x = base_size.w - arrow_size.w;
574 x = x - base_size.x - (arrow_size.w * 0.5);
575 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
576 edje_object_part_drag_value_set(wd->base,
577 "elm.swallow.arrow_up",
582 case ELM_CTXPOPUP_DIRECTION_UP:
583 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
585 // if user does not use dragable part
586 arrow_size.x = (x - (arrow_size.w * 0.5));
587 arrow_size.y = (y - arrow_size.h);
589 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
592 if (x < ((arrow_size.w * 0.5) + base_size.x))
594 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
595 x = base_size.w - arrow_size.w;
596 else x = x - base_size.x - (arrow_size.w * 0.5);
597 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
598 edje_object_part_drag_value_set(wd->base,
599 "elm.swallow.arrow_down",
608 // if user does not use dragable part
609 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
612 //TODO: compress item - different from opensource
614 _compress_item(Evas_Object *obj)
618 Elm_Ctxpopup_Item *item;
620 wd = elm_widget_data_get(obj);
623 EINA_LIST_FOREACH(wd->items, elist, item)
625 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
630 _sizing_eval(Evas_Object *obj)
634 Elm_Ctxpopup_Item *item;
635 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
636 Evas_Coord_Point box_size = { 0, 0 };
637 Evas_Coord_Point _box_size = { 0, 0 };
639 wd = elm_widget_data_get(obj);
640 if ((!wd) || (!wd->parent)) return;
643 EINA_LIST_FOREACH(wd->items, elist, item)
645 _item_sizing_eval(item);
646 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
649 if (_box_size.x > box_size.x)
650 box_size.x = _box_size.x;
651 if (_box_size.y != -1)
652 box_size.y += _box_size.y;
656 if (_box_size.x != -1)
657 box_size.x += _box_size.x;
658 if (_box_size.y > box_size.y)
659 box_size.y = _box_size.y;
665 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
666 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
670 wd->dir = _calc_base_geometry(obj, &rect);
672 //TODO: compress item - different from opensource
673 if (!wd->horizontal && !wd->content)
676 _update_arrow(obj, wd->dir);
677 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
679 //resize scroller according to final size.
681 evas_object_smart_calculate(wd->scr);
683 evas_object_move(wd->base, rect.x, rect.y);
684 evas_object_resize(wd->base, rect.w, rect.h);
688 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
689 Evas_Coord_Rectangle *rect)
691 Evas_Coord arrow_w, arrow_h;
693 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
697 case ELM_CTXPOPUP_DIRECTION_RIGHT:
700 case ELM_CTXPOPUP_DIRECTION_LEFT:
703 case ELM_CTXPOPUP_DIRECTION_DOWN:
706 case ELM_CTXPOPUP_DIRECTION_UP:
715 _del_pre_hook(Evas_Object *obj)
719 wd = elm_widget_data_get(obj);
722 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
723 _parent_resize, obj);
725 _hover_parent_callbacks_del(obj);
729 _del_hook(Evas_Object *obj)
733 wd = elm_widget_data_get(obj);
736 elm_ctxpopup_clear(obj);
737 evas_object_del(wd->arrow);
738 evas_object_del(wd->base);
742 //FIXME: lost the content size when theme hook is called.
744 _theme_hook(Evas_Object *obj)
748 Elm_Ctxpopup_Item *item;
751 wd = elm_widget_data_get(obj);
755 EINA_LIST_FOREACH(wd->items, elist, item)
757 if (item->label && item->icon)
758 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
759 "icon_text_style_item",
760 elm_widget_style_get(obj));
761 else if (item->label)
762 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
763 elm_widget_style_get(obj));
765 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
766 elm_widget_style_get(obj));
768 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
771 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
774 * For separator, if the first item has visible separator,
775 * then it should be aligned with edge of the base part.
776 * In some cases, it gives improper display. Ex) rounded corner
777 * So the first item separator should be invisible.
780 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
784 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
786 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
789 edje_object_message_signal_process(VIEW(item));
792 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
793 elm_widget_style_get(obj));
794 if (evas_object_visible_get(wd->bg))
795 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
797 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
798 elm_widget_style_get(obj));
799 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
800 elm_widget_style_get(obj));
804 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
805 elm_object_style_set(wd->scr, "ctxpopup");
807 elm_object_style_set(wd->scr, elm_object_style_get(obj));
812 _scroller_size_reset(wd);
818 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
819 const char *emission __UNUSED__, const char *source __UNUSED__)
821 evas_object_hide(data);
825 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
826 void *event_info __UNUSED__)
831 wd = elm_widget_data_get(data);
834 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
835 evas_object_resize(wd->bg, w, h);
837 if (!wd->visible) return;
843 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
844 void *event_info __UNUSED__)
848 Elm_Ctxpopup_Item *item;
851 wd = elm_widget_data_get(obj);
854 if ((!wd->items) && (!wd->content)) return;
856 wd->visible = EINA_TRUE;
858 evas_object_show(wd->bg);
859 evas_object_show(wd->base);
860 evas_object_show(wd->arrow);
862 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
864 EINA_LIST_FOREACH(wd->items, elist, item)
867 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
871 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
873 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
881 _hide(Evas_Object *obj)
883 Widget_Data *wd = elm_widget_data_get(obj);
887 evas_object_hide(wd->bg);
888 evas_object_hide(wd->arrow);
889 evas_object_hide(wd->base);
891 _scroller_size_reset(wd);
893 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
894 wd->visible = EINA_FALSE;
898 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
899 void *event_info __UNUSED__)
903 wd = elm_widget_data_get(obj);
904 if ((!wd) || (!wd->visible))
911 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
912 void *event_info __UNUSED__)
917 wd = elm_widget_data_get(data);
919 if (!wd->visible) return;
920 if (wd->finished) return;
922 evas_object_geometry_get(obj, 0, 0, &w, &h);
924 if (w != 0 && h != 0)
926 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
929 wd->finished = EINA_TRUE;
934 if (wd->max_sc_w < w)
936 if (wd->max_sc_h < h)
943 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
944 void *event_info __UNUSED__)
948 wd = elm_widget_data_get(obj);
953 evas_object_show(wd->arrow);
955 _scroller_size_reset(wd);
960 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
961 const char *emission __UNUSED__, const char *source __UNUSED__)
963 Elm_Ctxpopup_Item *item = data;
966 if (item->disabled) return;
969 item->func((void*) item->base.data, WIDGET(item), data);
973 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
977 elm_widget_sub_object_del(VIEW(item), item->icon);
978 evas_object_del(item->icon);
984 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
985 edje_object_message_signal_process(VIEW(item));
989 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
991 if (!eina_stringshare_replace(&item->label, label))
994 edje_object_part_text_set(VIEW(item), "elm.text", label);
995 edje_object_message_signal_process(VIEW(item));
999 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1003 wd = elm_widget_data_get(WIDGET(item));
1006 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1007 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1008 elm_widget_style_get(WIDGET(item)));
1009 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1010 _item_select_cb, item);
1011 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1012 evas_object_show(VIEW(item));
1016 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1017 void *event_info __UNUSED__)
1019 elm_ctxpopup_content_unset(data);
1023 _list_del(Widget_Data *wd)
1025 if (!wd->scr) return;
1027 edje_object_part_unswallow(wd->base, wd->scr);
1028 evas_object_del(wd->scr);
1034 _list_new(Evas_Object *obj)
1037 wd = elm_widget_data_get(obj);
1041 wd->scr = elm_scroller_add(obj);
1042 elm_object_style_set(wd->scr, "ctxpopup");
1043 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1044 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1045 _scroller_resize, obj);
1046 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1049 wd->box = elm_box_add(obj);
1050 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1053 elm_scroller_content_set(wd->scr, wd->box);
1054 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1058 _remove_items(Widget_Data *wd)
1061 Elm_Ctxpopup_Item *item;
1063 if (!wd->items) return;
1065 EINA_LIST_FOREACH(wd->items, elist, item)
1068 eina_stringshare_del(item->label);
1070 evas_object_del(item->icon);
1071 wd->items = eina_list_remove(wd->items, item);
1079 elm_ctxpopup_add(Evas_Object *parent)
1084 Evas_Coord x, y, w, h;
1086 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1088 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1089 elm_widget_type_set(obj, "ctxpopup");
1090 elm_widget_sub_object_add(parent, obj);
1091 elm_widget_data_set(obj, wd);
1092 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1093 elm_widget_del_hook_set(obj, _del_hook);
1094 elm_widget_theme_hook_set(obj, _theme_hook);
1096 wd->parent = parent;
1099 wd->bg = edje_object_add(e);
1100 elm_widget_sub_object_add(obj, wd->bg);
1101 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1102 evas_object_geometry_get(parent, &x, &y, &w, &h);
1103 evas_object_move(wd->bg, x, y);
1104 evas_object_resize(wd->bg, w, h);
1105 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1106 _bg_clicked_cb, obj);
1109 wd->base = edje_object_add(e);
1110 elm_widget_sub_object_add(obj, wd->base);
1111 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1114 wd->arrow = edje_object_add(e);
1115 elm_widget_sub_object_add(obj, wd->arrow);
1116 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1118 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1119 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1120 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1121 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1123 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1125 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1127 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1129 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1131 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1132 _ctxpopup_changed_size_hints, NULL);
1133 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1134 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1135 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1136 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1138 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1144 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1146 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1147 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1152 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1154 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1157 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1159 wd = elm_widget_data_get(WIDGET(item));
1162 _item_icon_set(item, icon);
1166 _scroller_size_reset(wd);
1167 _sizing_eval(WIDGET(item));
1172 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1174 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1175 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1180 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1182 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1185 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1187 wd = elm_widget_data_get(WIDGET(item));
1190 _item_label_set(item, label);
1194 _scroller_size_reset(wd);
1195 _sizing_eval(WIDGET(item));
1200 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1202 ELM_CHECK_WIDTYPE(obj, widtype);
1206 wd = elm_widget_data_get(obj);
1209 _hover_parent_callbacks_del(obj);
1213 evas_object_event_callback_add(hover_parent,
1217 evas_object_event_callback_add(hover_parent,
1221 evas_object_event_callback_add(hover_parent,
1222 EVAS_CALLBACK_RESIZE,
1223 _hover_parent_resize,
1227 wd->hover_parent = hover_parent;
1231 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1233 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1237 wd = elm_widget_data_get(obj);
1238 if (!wd) return NULL;
1240 return wd->hover_parent;
1244 elm_ctxpopup_clear(Evas_Object * obj)
1246 ELM_CHECK_WIDTYPE(obj, widtype);
1248 Widget_Data *wd = elm_widget_data_get(obj);
1256 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1258 ELM_CHECK_WIDTYPE(obj, widtype);
1262 Elm_Ctxpopup_Item *item;
1265 wd = elm_widget_data_get(obj);
1268 wd->horizontal = !!horizontal;
1270 if ((!wd->scr) && (!wd->box))
1275 elm_box_horizontal_set(wd->box, EINA_FALSE);
1276 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1278 EINA_LIST_FOREACH(wd->items, elist, item)
1281 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1283 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1288 elm_box_horizontal_set(wd->box, EINA_TRUE);
1289 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1291 EINA_LIST_FOREACH(wd->items, elist, item)
1294 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1296 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1305 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1307 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1311 wd = elm_widget_data_get(obj);
1312 if (!wd) return EINA_FALSE;
1314 return wd->horizontal;
1317 EAPI Elm_Object_Item *
1318 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1319 Evas_Object *icon, Evas_Smart_Cb func,
1322 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1325 Elm_Ctxpopup_Item *item;
1327 wd = elm_widget_data_get(obj);
1328 if (!wd) return NULL;
1330 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1331 if (!item) return NULL;
1333 //The first item is appended.
1335 evas_object_del(elm_ctxpopup_content_unset(obj));
1341 item->base.data = data;
1344 _item_new(item, "icon_text_style_item");
1346 _item_new(item, "text_style_item");
1348 _item_new(item, "icon_style_item");
1350 _item_icon_set(item, icon);
1351 _item_label_set(item, label);
1352 elm_box_pack_end(wd->box, VIEW(item));
1353 wd->items = eina_list_append(wd->items, item);
1357 _scroller_size_reset(wd);
1361 return (Elm_Object_Item *) item;
1365 elm_ctxpopup_item_del(Elm_Object_Item *it)
1367 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1370 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1372 wd = elm_widget_data_get(WIDGET(item));
1376 evas_object_del(item->icon);
1378 evas_object_del(VIEW(item));
1380 eina_stringshare_del(item->label);
1382 wd->items = eina_list_remove(wd->items, item);
1384 if (eina_list_count(wd->items) < 1)
1388 _sizing_eval(WIDGET(item));
1394 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1396 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1399 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1401 wd = elm_widget_data_get(WIDGET(item));
1404 if (disabled == item->disabled)
1408 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
1410 edje_object_signal_emit(VIEW(item), "elm,state,enabled", "elm");
1412 item->disabled = !!disabled;
1416 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1418 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1419 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1420 return item->disabled;
1424 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1426 ELM_CHECK_WIDTYPE(obj, widtype);
1430 wd = elm_widget_data_get(obj);
1431 if ((!wd) || (!content))
1435 elm_ctxpopup_clear(obj);
1438 evas_object_del(wd->content);
1440 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1443 elm_widget_sub_object_add(obj, content);
1444 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1445 edje_object_message_signal_process(wd->base);
1447 wd->content = content;
1454 elm_ctxpopup_content_unset(Evas_Object *obj)
1456 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1459 Evas_Object *content;
1461 wd = elm_widget_data_get(obj);
1462 if (!wd) return NULL;
1464 content = wd->content;
1465 if (!content) return NULL;
1467 edje_object_part_unswallow(wd->base, content);
1468 elm_widget_sub_object_del(obj, content);
1469 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1470 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1478 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1479 Elm_Ctxpopup_Direction first,
1480 Elm_Ctxpopup_Direction second,
1481 Elm_Ctxpopup_Direction third,
1482 Elm_Ctxpopup_Direction fourth)
1484 ELM_CHECK_WIDTYPE(obj, widtype);
1487 wd = elm_widget_data_get(obj);
1490 wd->dir_priority[0] = first;
1491 wd->dir_priority[1] = second;
1492 wd->dir_priority[2] = third;
1493 wd->dir_priority[3] = fourth;
1500 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1501 Elm_Ctxpopup_Direction *first,
1502 Elm_Ctxpopup_Direction *second,
1503 Elm_Ctxpopup_Direction *third,
1504 Elm_Ctxpopup_Direction *fourth)
1506 ELM_CHECK_WIDTYPE(obj, widtype);
1509 wd = elm_widget_data_get(obj);
1512 if (first) *first = wd->dir_priority[0];
1513 if (second) *second = wd->dir_priority[1];
1514 if (third) *third = wd->dir_priority[2];
1515 if (fourth) *fourth = wd->dir_priority[3];
1518 EAPI Elm_Ctxpopup_Direction
1519 elm_ctxpopup_direction_get(const Evas_Object *obj)
1521 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1524 wd = elm_widget_data_get(obj);
1525 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;