1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Elm_Ctxpopup_Item Elm_Ctxpopup_Item;
7 struct _Elm_Ctxpopup_Item
25 Evas_Object *hover_parent;
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 __UNUSED__, Evas_Object *obj,
38 void *event_info __UNUSED__);
39 static void _freeze_off(void *data __UNUSED__, Evas_Object *obj,
40 void *event_info __UNUSED__);
41 static void _hold_on(void *data __UNUSED__, Evas_Object *obj,
42 void *event_info __UNUSED__);
43 static void _hold_off(void *data __UNUSED__, Evas_Object *obj,
44 void *event_info __UNUSED__);
45 static void _scroller_size_reset(Widget_Data *wd);
46 static void _hover_parent_callbacks_del(Evas_Object *obj);
47 static void _hover_parent_resize(void *data, Evas *e __UNUSED__,
48 Evas_Object *obj __UNUSED__,
49 void *event_info __UNUSED__);
50 static void _hover_parent_move(void *data, Evas *e __UNUSED__,
51 Evas_Object *obj __UNUSED__,
52 void *event_info __UNUSED__);
53 static void _hover_parent_del(void *data, Evas *e __UNUSED__,
54 Evas_Object *obj __UNUSED__,
55 void *event_info __UNUSED__);
56 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
57 static void _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
58 Evas_Coord_Rectangle *hover_area);
59 static void _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
60 Evas_Coord_Rectangle *hover_area);
61 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
62 Evas *e __UNUSED__, Evas_Object *obj,
63 void *event_info __UNUSED__);
64 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
65 Evas_Coord_Rectangle *rect);
66 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
67 static void _sizing_eval(Evas_Object *obj);
68 static void _shift_base_by_arrow(Evas_Object *arrow,
69 Elm_Ctxpopup_Direction dir,
70 Evas_Coord_Rectangle *rect);
71 static void _del_pre_hook(Evas_Object *obj);
72 static void _del_hook(Evas_Object *obj);
73 static void _theme_hook(Evas_Object *obj);
74 static void _content_set_hook(Evas_Object *obj,
75 const char *part __UNUSED__,
76 Evas_Object *content);
77 static Evas_Object * _content_unset_hook(Evas_Object *obj,
78 const char *part __UNUSED__);
79 static Evas_Object * _content_get_hook(const Evas_Object *obj,
80 const char *part __UNUSED__);
81 static void _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
82 const char *emission __UNUSED__,
83 const char *source __UNUSED__);
84 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
85 void *event_info __UNUSED__);
86 static void _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__,
87 Evas_Object *obj, void *event_info __UNUSED__);
88 static void _hide(Evas_Object *obj);
89 static void _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__,
90 Evas_Object *obj, void *event_info __UNUSED__);
91 static void _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
92 void *event_info __UNUSED__);
93 static void _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__,
94 Evas_Object *obj, void *event_info __UNUSED__);
95 static void _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
96 const char *emission __UNUSED__,
97 const char *source __UNUSED__);
98 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
99 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
100 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
101 static void _content_del(void *data, Evas *e, Evas_Object *obj __UNUSED__,
102 void *event_info __UNUSED__);
103 static void _list_del(Widget_Data *wd);
104 static void _list_new(Evas_Object *obj);
105 static void _remove_items(Widget_Data * wd);
107 static const char SIG_DISMISSED[] = "dismissed";
109 static const Evas_Smart_Cb_Description _signals[] = {
115 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
116 void *event_info __UNUSED__)
118 Widget_Data *wd = elm_widget_data_get(obj);
120 if ((!wd) || (!wd->scr)) return;
121 elm_object_scroll_freeze_push(wd->scr);
125 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
126 void *event_info __UNUSED__)
128 Widget_Data *wd = elm_widget_data_get(obj);
130 if ((!wd) || (!wd->scr)) return;
131 elm_object_scroll_freeze_pop(wd->scr);
135 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
137 Widget_Data *wd = elm_widget_data_get(obj);
139 if ((!wd) || (!wd->scr)) return;
140 elm_object_scroll_hold_push(wd->scr);
144 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
146 Widget_Data *wd = elm_widget_data_get(obj);
148 if ((!wd) || (!wd->scr)) return;
149 elm_object_scroll_hold_pop(wd->scr);
153 _scroller_size_reset(Widget_Data *wd)
155 wd->finished = EINA_FALSE;
161 _hover_parent_callbacks_del(Evas_Object *obj)
163 Widget_Data *wd = elm_widget_data_get(obj);
165 if ((!wd) || (!wd->hover_parent))
168 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
169 _hover_parent_del, obj);
170 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
171 _hover_parent_move, obj);
172 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
173 _hover_parent_resize, obj);
177 _hover_parent_resize(void *data, Evas *e __UNUSED__,
178 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
180 Widget_Data *wd = elm_widget_data_get(data);
186 _scroller_size_reset(wd);
192 _hover_parent_move(void *data, Evas *e __UNUSED__,
193 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
195 Widget_Data *wd = elm_widget_data_get(data);
201 _scroller_size_reset(wd);
207 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
208 void *event_info __UNUSED__)
210 Widget_Data *wd = elm_widget_data_get(data);
214 wd->hover_parent = NULL;
218 _item_sizing_eval(Elm_Ctxpopup_Item *item)
220 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
224 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
226 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
227 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
231 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
232 Evas_Coord_Rectangle *hover_area)
234 pos->x -= (base_size->x / 2);
236 if (pos->x < hover_area->x)
237 pos->x = hover_area->x;
238 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
239 pos->x = (hover_area->x + hover_area->w) - base_size->x;
241 if (base_size->x > hover_area->w)
242 base_size->x -= (base_size->x - hover_area->w);
244 if (pos->x < hover_area->x)
245 pos->x = hover_area->x;
249 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
250 Evas_Coord_Rectangle *hover_area)
252 pos->y -= (base_size->y / 2);
254 if (pos->y < hover_area->y)
255 pos->y = hover_area->y;
256 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
257 pos->y = hover_area->y + hover_area->h - base_size->y;
259 if (base_size->y > hover_area->h)
260 base_size->y -= (base_size->y - hover_area->h);
262 if (pos->y < hover_area->y)
263 pos->y = hover_area->y;
267 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
268 Evas_Object *obj, void *event_info __UNUSED__)
272 wd = elm_widget_data_get(obj);
279 static Elm_Ctxpopup_Direction
280 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
283 Evas_Coord_Point pos = {0, 0};
284 Evas_Coord_Point base_size;
285 Evas_Coord_Point max_size;
286 Evas_Coord_Point min_size;
287 Evas_Coord_Rectangle hover_area;
288 Evas_Coord_Rectangle parent_size;
289 Evas_Coord_Point arrow_size;
290 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DOWN;
291 Evas_Coord_Point temp;
294 wd = elm_widget_data_get(obj);
296 if ((!wd) || (!rect))
297 return ELM_CTXPOPUP_DIRECTION_DOWN;
299 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
300 &arrow_size.x, &arrow_size.y);
301 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
303 //Initialize Area Rectangle.
304 if (wd->hover_parent)
305 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
306 &hover_area.w, &hover_area.h);
309 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
310 &parent_size.w, &parent_size.h);
311 hover_area.x = parent_size.x;
312 hover_area.y = parent_size.y;
313 hover_area.w = parent_size.w;
314 hover_area.h = parent_size.h;
317 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
320 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
321 evas_object_smart_calculate(wd->base);
324 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
326 if ((max_size.y > 0) && (base_size.y > max_size.y))
327 base_size.y = max_size.y;
329 if ((max_size.x > 0) && (base_size.x > max_size.x))
330 base_size.x = max_size.x;
333 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
335 if ((min_size.y > 0) && (base_size.y < min_size.y))
336 base_size.y = min_size.y;
338 if ((min_size.x > 0) && (base_size.x < min_size.x))
339 base_size.x = min_size.x;
341 //Check the Which direction is available.
342 //If find a avaialble direction, it adjusts position and size.
343 for (idx = 0; idx < 4; idx++)
345 switch (wd->dir_priority[idx])
347 case ELM_CTXPOPUP_DIRECTION_UP:
348 temp.y = (pos.y - base_size.y);
349 if ((temp.y - arrow_size.y) < hover_area.y)
351 _adjust_pos_x(&pos, &base_size, &hover_area);
352 pos.y -= base_size.y;
353 dir = ELM_CTXPOPUP_DIRECTION_UP;
355 case ELM_CTXPOPUP_DIRECTION_LEFT:
356 temp.x = (pos.x - base_size.x);
357 if ((temp.x - arrow_size.x) < hover_area.x)
359 _adjust_pos_y(&pos, &base_size, &hover_area);
360 pos.x -= base_size.x;
361 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
363 case ELM_CTXPOPUP_DIRECTION_RIGHT:
364 temp.x = (pos.x + base_size.x);
365 if ((temp.x + arrow_size.x) >
366 (hover_area.x + hover_area.w))
368 _adjust_pos_y(&pos, &base_size, &hover_area);
369 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
371 case ELM_CTXPOPUP_DIRECTION_DOWN:
372 temp.y = (pos.y + base_size.y);
373 if ((temp.y + arrow_size.y) >
374 (hover_area.y + hover_area.h))
376 _adjust_pos_x(&pos, &base_size, &hover_area);
377 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
385 //In this case, all directions are invalid because of lack of space.
388 Evas_Coord length[2];
392 length[0] = pos.y - hover_area.y;
393 length[1] = (hover_area.y + hover_area.h) - pos.y;
395 // ELM_CTXPOPUP_DIRECTION_UP
396 if (length[0] > length[1])
398 _adjust_pos_x(&pos, &base_size, &hover_area);
399 pos.y -= base_size.y;
400 dir = ELM_CTXPOPUP_DIRECTION_UP;
401 if (pos.y < (hover_area.y + arrow_size.y))
403 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
404 pos.y = hover_area.y + arrow_size.y;
407 //ELM_CTXPOPUP_DIRECTION_DOWN
410 _adjust_pos_x(&pos, &base_size, &hover_area);
411 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
412 if ((pos.y + arrow_size.y + base_size.y) >
413 (hover_area.y + hover_area.h))
415 ((pos.y + arrow_size.y + base_size.y) -
416 (hover_area.y + hover_area.h));
421 length[0] = pos.x - hover_area.x;
422 length[1] = (hover_area.x + hover_area.w) - pos.x;
424 //ELM_CTXPOPUP_DIRECTION_LEFT
425 if (length[0] > length[1])
427 _adjust_pos_y(&pos, &base_size, &hover_area);
428 pos.x -= base_size.x;
429 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
430 if (pos.x < (hover_area.x + arrow_size.x))
432 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
433 pos.x = hover_area.x + arrow_size.x;
436 //ELM_CTXPOPUP_DIRECTION_RIGHT
439 _adjust_pos_y(&pos, &base_size, &hover_area);
440 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
441 if (pos.x + (arrow_size.x + base_size.x) >
442 hover_area.x + hover_area.w)
444 ((pos.x + arrow_size.x + base_size.x) -
445 (hover_area.x + hover_area.w));
450 //Final position and size.
453 rect->w = base_size.x;
454 rect->h = base_size.y;
460 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
463 Evas_Coord_Rectangle arrow_size;
464 Evas_Coord_Rectangle base_size;
467 wd = elm_widget_data_get(obj);
470 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
471 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
473 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
474 &base_size.w, &base_size.h);
478 case ELM_CTXPOPUP_DIRECTION_RIGHT:
479 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
480 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
483 if (y < ((arrow_size.h * 0.5) + base_size.y))
485 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
486 y = base_size.h - arrow_size.h;
488 y = y - base_size.y - (arrow_size.h * 0.5);
489 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
490 (double) (y) / (double) (base_size.h - arrow_size.h));
493 case ELM_CTXPOPUP_DIRECTION_LEFT:
494 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
495 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
498 if (y < (arrow_size.h * 0.5) + base_size.y)
500 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
501 y = base_size.h - arrow_size.h;
502 else y = y - base_size.y - (arrow_size.h * 0.5);
503 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
504 (double) (y) / (double) (base_size.h - arrow_size.h));
507 case ELM_CTXPOPUP_DIRECTION_DOWN:
508 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
509 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
512 if (x < (arrow_size.w * 0.5) + base_size.x)
514 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
515 x = base_size.w - arrow_size.w;
517 x = x - base_size.x - (arrow_size.w * 0.5);
518 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
519 (double) (x) / (double) (base_size.w - arrow_size.w), 1);
522 case ELM_CTXPOPUP_DIRECTION_UP:
523 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
524 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
527 if (x < (arrow_size.w * 0.5) + base_size.x)
529 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
530 x = base_size.w - arrow_size.w;
531 else x = x - base_size.x - (arrow_size.w * 0.5);
532 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
533 (double) (x) / (double) (base_size.w - arrow_size.w), 0);
542 _sizing_eval(Evas_Object *obj)
546 Elm_Ctxpopup_Item *item;
547 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
548 Evas_Coord_Point box_size = { 0, 0 };
549 Evas_Coord_Point _box_size = { 0, 0 };
551 wd = elm_widget_data_get(obj);
552 if ((!wd) || (!wd->parent)) return;
555 EINA_LIST_FOREACH(wd->items, elist, item)
557 _item_sizing_eval(item);
558 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
561 if (_box_size.x > box_size.x)
562 box_size.x = _box_size.x;
563 if (_box_size.y != -1)
564 box_size.y += _box_size.y;
568 if (_box_size.x != -1)
569 box_size.x += _box_size.x;
570 if (_box_size.y > box_size.y)
571 box_size.y = _box_size.y;
577 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
578 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
582 wd->dir = _calc_base_geometry(obj, &rect);
583 _update_arrow(obj, wd->dir);
584 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
586 //resize scroller according to final size.
588 evas_object_smart_calculate(wd->scr);
590 evas_object_move(wd->base, rect.x, rect.y);
591 evas_object_resize(wd->base, rect.w, rect.h);
595 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
596 Evas_Coord_Rectangle *rect)
598 Evas_Coord arrow_w, arrow_h;
600 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
604 case ELM_CTXPOPUP_DIRECTION_RIGHT:
607 case ELM_CTXPOPUP_DIRECTION_LEFT:
610 case ELM_CTXPOPUP_DIRECTION_DOWN:
613 case ELM_CTXPOPUP_DIRECTION_UP:
622 _del_pre_hook(Evas_Object *obj)
626 wd = elm_widget_data_get(obj);
629 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
630 _parent_resize, obj);
632 _hover_parent_callbacks_del(obj);
636 _del_hook(Evas_Object *obj)
640 wd = elm_widget_data_get(obj);
643 elm_ctxpopup_clear(obj);
644 evas_object_del(wd->arrow);
645 evas_object_del(wd->base);
650 _theme_hook(Evas_Object *obj)
654 Elm_Ctxpopup_Item *item;
656 wd = elm_widget_data_get(obj);
660 EINA_LIST_FOREACH(wd->items, elist, item)
662 if (item->label && item->icon)
663 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
664 "icon_text_style_item",
665 elm_widget_style_get(obj));
666 else if (item->label)
667 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
668 elm_widget_style_get(obj));
670 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
671 elm_widget_style_get(obj));
673 edje_object_part_text_set(item->base.view, "elm.text", item->label);
676 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
678 edje_object_message_signal_process(item->base.view);
681 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
682 elm_widget_style_get(obj));
683 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
684 elm_widget_style_get(obj));
685 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
686 elm_widget_style_get(obj));
690 if (!strncmp(elm_object_style_get(obj), "default",
692 elm_object_style_set(wd->scr, "ctxpopup");
694 elm_object_style_set(wd->scr, elm_object_style_get(obj));
699 _scroller_size_reset(wd);
705 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__,
706 Evas_Object *content)
708 ELM_CHECK_WIDTYPE(obj, widtype);
712 wd = elm_widget_data_get(obj);
713 if ((!wd) || (!content)) return;
715 if (wd->items) elm_ctxpopup_clear(obj);
716 if (wd->content) evas_object_del(wd->content);
718 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
721 elm_widget_sub_object_add(obj, content);
722 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
724 wd->content = content;
731 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
733 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
736 Evas_Object *content;
738 wd = elm_widget_data_get(obj);
739 if (!wd) return NULL;
741 content = wd->content;
742 if (!content) return NULL;
744 edje_object_part_unswallow(wd->base, content);
745 elm_widget_sub_object_del(obj, content);
746 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
747 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
756 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
758 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
760 Widget_Data *wd = elm_widget_data_get(obj);
761 if (!wd) return NULL;
766 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
767 const char *emission __UNUSED__, const char *source __UNUSED__)
769 evas_object_hide(data);
773 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
774 void *event_info __UNUSED__)
779 wd = elm_widget_data_get(data);
782 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
783 evas_object_resize(wd->bg, w, h);
785 if (!wd->visible) return;
791 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
792 void *event_info __UNUSED__)
796 wd = elm_widget_data_get(obj);
799 if ((!wd->items) && (!wd->content)) return;
801 wd->visible = EINA_TRUE;
803 evas_object_show(wd->bg);
804 evas_object_show(wd->base);
805 evas_object_show(wd->arrow);
807 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
813 _hide(Evas_Object *obj)
815 Widget_Data *wd = elm_widget_data_get(obj);
819 evas_object_hide(wd->bg);
820 evas_object_hide(wd->arrow);
821 evas_object_hide(wd->base);
823 _scroller_size_reset(wd);
825 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
826 wd->visible = EINA_FALSE;
830 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
831 void *event_info __UNUSED__)
835 wd = elm_widget_data_get(obj);
836 if ((!wd) || (!wd->visible))
843 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
844 void *event_info __UNUSED__)
849 wd = elm_widget_data_get(data);
851 if (!wd->visible) return;
852 if (wd->finished) return;
854 evas_object_geometry_get(obj, 0, 0, &w, &h);
856 if (w != 0 && h != 0)
858 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
861 wd->finished = EINA_TRUE;
866 if (wd->max_sc_w < w)
868 if (wd->max_sc_h < h)
875 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
876 void *event_info __UNUSED__)
880 wd = elm_widget_data_get(obj);
885 evas_object_show(wd->arrow);
887 _scroller_size_reset(wd);
892 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
893 const char *emission __UNUSED__, const char *source __UNUSED__)
895 Elm_Ctxpopup_Item *item = data;
898 if (item->disabled) return;
901 item->func((void*) item->base.data, item->base.widget, data);
905 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
908 evas_object_del(item->icon);
913 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
914 edje_object_message_signal_process(item->base.view);
918 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
920 if (!eina_stringshare_replace(&item->label, label))
923 edje_object_part_text_set(item->base.view, "elm.text", label);
924 edje_object_message_signal_process(item->base.view);
928 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
932 wd = elm_widget_data_get(item->base.widget);
935 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
936 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
937 elm_widget_style_get(item->base.widget));
938 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
939 _item_select_cb, item);
940 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
941 evas_object_show(item->base.view);
945 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
946 void *event_info __UNUSED__)
948 elm_object_content_unset(data);
952 _list_del(Widget_Data *wd)
954 if (!wd->scr) return;
956 edje_object_part_unswallow(wd->base, wd->scr);
957 evas_object_del(wd->scr);
963 _list_new(Evas_Object *obj)
966 wd = elm_widget_data_get(obj);
970 wd->scr = elm_scroller_add(obj);
971 elm_object_style_set(wd->scr, "ctxpopup");
972 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
973 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
974 _scroller_resize, obj);
975 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
978 wd->box = elm_box_add(obj);
979 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
982 elm_scroller_content_set(wd->scr, wd->box);
983 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
987 _remove_items(Widget_Data *wd)
990 Elm_Ctxpopup_Item *item;
992 if (!wd->items) return;
994 EINA_LIST_FOREACH(wd->items, elist, item)
997 eina_stringshare_del(item->label);
999 evas_object_del(item->icon);
1000 wd->items = eina_list_remove(wd->items, item);
1008 elm_ctxpopup_add(Evas_Object *parent)
1013 Evas_Coord x, y, w, h;
1015 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1017 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1018 elm_widget_type_set(obj, "ctxpopup");
1019 elm_widget_sub_object_add(parent, obj);
1020 elm_widget_data_set(obj, wd);
1021 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1022 elm_widget_del_hook_set(obj, _del_hook);
1023 elm_widget_theme_hook_set(obj, _theme_hook);
1024 elm_widget_content_set_hook_set(obj, _content_set_hook);
1025 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1026 elm_widget_content_get_hook_set(obj, _content_get_hook);
1028 wd->parent = parent;
1031 wd->bg = edje_object_add(e);
1032 elm_widget_sub_object_add(obj, wd->bg);
1033 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1034 evas_object_geometry_get(parent, &x, &y, &w, &h);
1035 evas_object_move(wd->bg, x, y);
1036 evas_object_resize(wd->bg, w, h);
1037 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1038 _bg_clicked_cb, obj);
1041 wd->base = edje_object_add(e);
1042 elm_widget_sub_object_add(obj, wd->base);
1043 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1046 wd->arrow = edje_object_add(e);
1047 elm_widget_sub_object_add(obj, wd->arrow);
1048 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1050 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1051 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1052 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1053 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1055 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1057 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1059 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1061 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1063 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1064 _ctxpopup_changed_size_hints, NULL);
1065 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1066 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1067 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1068 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1070 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1076 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1078 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1079 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1080 return ctxpopup_it->icon;
1084 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1086 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1089 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1091 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1094 _item_icon_set(ctxpopup_it, icon);
1098 _scroller_size_reset(wd);
1099 _sizing_eval(ctxpopup_it->base.widget);
1104 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1106 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1107 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1108 return ctxpopup_it->label;
1112 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1114 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1117 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1119 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1122 _item_label_set(ctxpopup_it, label);
1126 _scroller_size_reset(wd);
1127 _sizing_eval(ctxpopup_it->base.widget);
1132 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1134 ELM_CHECK_WIDTYPE(obj, widtype);
1138 wd = elm_widget_data_get(obj);
1141 _hover_parent_callbacks_del(obj);
1145 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1146 _hover_parent_del, obj);
1147 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1148 _hover_parent_move, obj);
1149 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1150 _hover_parent_resize, obj);
1153 wd->hover_parent = hover_parent;
1157 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1159 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1163 wd = elm_widget_data_get(obj);
1164 if (!wd) return NULL;
1166 return wd->hover_parent;
1170 elm_ctxpopup_clear(Evas_Object * obj)
1172 ELM_CHECK_WIDTYPE(obj, widtype);
1174 Widget_Data *wd = elm_widget_data_get(obj);
1182 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1184 ELM_CHECK_WIDTYPE(obj, widtype);
1188 wd = elm_widget_data_get(obj);
1191 wd->horizontal = !!horizontal;
1193 if ((!wd->scr) && (!wd->box))
1198 elm_box_horizontal_set(wd->box, EINA_FALSE);
1199 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1203 elm_box_horizontal_set(wd->box, EINA_TRUE);
1204 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1212 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1214 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1218 wd = elm_widget_data_get(obj);
1219 if (!wd) return EINA_FALSE;
1221 return wd->horizontal;
1224 EAPI Elm_Object_Item *
1225 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1226 Evas_Object *icon, Evas_Smart_Cb func,
1229 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1232 Elm_Ctxpopup_Item *item;
1234 wd = elm_widget_data_get(obj);
1235 if (!wd) return NULL;
1237 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1238 if (!item) return NULL;
1240 //The first item is appended.
1242 evas_object_del(elm_object_content_unset(obj));
1248 item->base.data = data;
1251 _item_new(item, "icon_text_style_item");
1253 _item_new(item, "text_style_item");
1255 _item_new(item, "icon_style_item");
1257 _item_icon_set(item, icon);
1258 _item_label_set(item, label);
1259 elm_box_pack_end(wd->box, item->base.view);
1260 wd->items = eina_list_append(wd->items, item);
1264 _scroller_size_reset(wd);
1268 return ELM_CAST(item);
1272 elm_ctxpopup_item_del(Elm_Object_Item *it)
1274 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1277 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1279 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1282 if (ctxpopup_it->icon)
1283 evas_object_del(ctxpopup_it->icon);
1284 if (ctxpopup_it->base.view)
1285 evas_object_del(ctxpopup_it->base.view);
1287 eina_stringshare_del(ctxpopup_it->label);
1289 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1291 if (eina_list_count(wd->items) < 1)
1295 _sizing_eval(ctxpopup_it->base.widget);
1301 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1303 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1306 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1308 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1311 ctxpopup_it = ELM_CAST(it);
1313 if (disabled == ctxpopup_it->disabled)
1317 edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,disabled", "elm");
1319 edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,enabled", "elm");
1321 ctxpopup_it->disabled = !!disabled;
1325 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1327 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1328 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1329 return ctxpopup_it->disabled;
1333 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1335 elm_object_content_set(obj, content);
1339 elm_ctxpopup_content_unset(Evas_Object *obj)
1341 return elm_object_content_unset(obj);
1345 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1346 Elm_Ctxpopup_Direction first,
1347 Elm_Ctxpopup_Direction second,
1348 Elm_Ctxpopup_Direction third,
1349 Elm_Ctxpopup_Direction fourth)
1351 ELM_CHECK_WIDTYPE(obj, widtype);
1354 wd = elm_widget_data_get(obj);
1357 wd->dir_priority[0] = first;
1358 wd->dir_priority[1] = second;
1359 wd->dir_priority[2] = third;
1360 wd->dir_priority[3] = fourth;
1367 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1368 Elm_Ctxpopup_Direction *first,
1369 Elm_Ctxpopup_Direction *second,
1370 Elm_Ctxpopup_Direction *third,
1371 Elm_Ctxpopup_Direction *fourth)
1373 ELM_CHECK_WIDTYPE(obj, widtype);
1376 wd = elm_widget_data_get(obj);
1379 if (first) *first = wd->dir_priority[0];
1380 if (second) *second = wd->dir_priority[1];
1381 if (third) *third = wd->dir_priority[2];
1382 if (fourth) *fourth = wd->dir_priority[3];