1 #include <Elementary.h>
7 * A ctxpopup is a widget that, when shown, pops up a list of items.
8 * It automatically chooses an area inside its parent object's view
9 * (set via elm_ctxpopup_add() and elm_ctxpopup_hover_parent_set()) to
10 * optimally fit into it. In the default theme, it will also point an
11 * arrow to the cursor position at the time one shows it. Ctxpopup
12 * items have a label and/or an icon. It is intended for a small
13 * number of items (hence the use of list, not genlist).
15 * Signals that you can add callbacks for are:
17 * "dismissed" - the ctxpopup was dismissed
20 typedef struct _Widget_Data Widget_Data;
22 struct _Elm_Ctxpopup_Item
40 Evas_Object *hover_parent;
42 Elm_Ctxpopup_Direction dir;
43 Elm_Ctxpopup_Direction dir_priority[4];
44 Evas_Coord max_sc_w, max_sc_h;
45 Eina_Bool horizontal:1;
50 static const char *widtype = NULL;
52 static void _freeze_on(void *data __UNUSED__, Evas_Object *obj,
53 void *event_info __UNUSED__);
54 static void _freeze_off(void *data __UNUSED__, Evas_Object *obj,
55 void *event_info __UNUSED__);
56 static void _hold_on(void *data __UNUSED__, Evas_Object *obj,
57 void *event_info __UNUSED__);
58 static void _hold_off(void *data __UNUSED__, Evas_Object *obj,
59 void *event_info __UNUSED__);
60 static void _scroller_size_reset(Widget_Data *wd);
61 static void _hover_parent_callbacks_del(Evas_Object *obj);
62 static void _hover_parent_resize(void *data, Evas *e __UNUSED__,
63 Evas_Object *obj __UNUSED__,
64 void *event_info __UNUSED__);
65 static void _hover_parent_move(void *data, Evas *e __UNUSED__,
66 Evas_Object *obj __UNUSED__,
67 void *event_info __UNUSED__);
68 static void _hover_parent_del(void *data, Evas *e __UNUSED__,
69 Evas_Object *obj __UNUSED__,
70 void *event_info __UNUSED__);
71 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
72 static void _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
73 Evas_Coord_Rectangle *hover_area);
74 static void _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
75 Evas_Coord_Rectangle *hover_area);
76 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
77 Evas *e __UNUSED__, Evas_Object *obj,
78 void *event_info __UNUSED__);
79 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
80 Evas_Coord_Rectangle *rect);
81 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
82 static void _sizing_eval(Evas_Object *obj);
83 static void _shift_base_by_arrow(Evas_Object *arrow,
84 Elm_Ctxpopup_Direction dir,
85 Evas_Coord_Rectangle *rect);
86 static void _del_pre_hook(Evas_Object *obj);
87 static void _del_hook(Evas_Object *obj);
88 static void _theme_hook(Evas_Object *obj);
89 static void _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
90 const char *emission __UNUSED__,
91 const char *source __UNUSED__);
92 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
93 void *event_info __UNUSED__);
94 static void _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__,
95 Evas_Object *obj, void *event_info __UNUSED__);
96 static void _hide(Evas_Object *obj);
97 static void _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__,
98 Evas_Object *obj, void *event_info __UNUSED__);
99 static void _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
100 void *event_info __UNUSED__);
101 static void _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__,
102 Evas_Object *obj, void *event_info __UNUSED__);
103 static void _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
104 const char *emission __UNUSED__,
105 const char *source __UNUSED__);
106 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
107 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
108 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
109 static void _content_del(void *data, Evas *e, Evas_Object *obj __UNUSED__,
110 void *event_info __UNUSED__);
111 static void _list_del(Widget_Data *wd);
112 static void _list_new(Evas_Object *obj);
113 static void _remove_items(Widget_Data * wd);
115 static const char SIG_DISMISSED[] = "dismissed";
117 static const Evas_Smart_Cb_Description _signals[] = {
122 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
123 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
124 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
127 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
128 void *event_info __UNUSED__)
130 Widget_Data *wd = elm_widget_data_get(obj);
132 if ((!wd) || (!wd->scr)) return;
134 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
138 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
139 void *event_info __UNUSED__)
141 Widget_Data *wd = elm_widget_data_get(obj);
143 if ((!wd) || (!wd->scr)) return;
146 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
148 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
152 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
154 Widget_Data *wd = elm_widget_data_get(obj);
156 if ((!wd) || (!wd->scr)) return;
158 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
162 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
164 Widget_Data *wd = elm_widget_data_get(obj);
166 if ((!wd) || (!wd->scr)) return;
169 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
171 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
175 _scroller_size_reset(Widget_Data *wd)
177 wd->finished = EINA_FALSE;
183 _hover_parent_callbacks_del(Evas_Object *obj)
185 Widget_Data *wd = elm_widget_data_get(obj);
187 if ((!wd) || (!wd->hover_parent))
190 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
191 _hover_parent_del, obj);
192 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
193 _hover_parent_move, obj);
194 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
195 _hover_parent_resize, obj);
199 _hover_parent_resize(void *data, Evas *e __UNUSED__,
200 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
202 Widget_Data *wd = elm_widget_data_get(data);
208 _scroller_size_reset(wd);
214 _hover_parent_move(void *data, Evas *e __UNUSED__,
215 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
217 Widget_Data *wd = elm_widget_data_get(data);
223 _scroller_size_reset(wd);
229 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
230 void *event_info __UNUSED__)
232 Widget_Data *wd = elm_widget_data_get(data);
236 wd->hover_parent = NULL;
240 _item_sizing_eval(Elm_Ctxpopup_Item *item)
242 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
246 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
248 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
249 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
253 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
254 Evas_Coord_Rectangle *hover_area)
256 pos->x -= (base_size->x / 2);
258 if (pos->x < hover_area->x)
259 pos->x = hover_area->x;
260 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
261 pos->x = (hover_area->x + hover_area->w) - base_size->x;
263 if (base_size->x > hover_area->w)
264 base_size->x -= (base_size->x - hover_area->w);
266 if (pos->x < hover_area->x)
267 pos->x = hover_area->x;
271 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
272 Evas_Coord_Rectangle *hover_area)
274 pos->y -= (base_size->y / 2);
276 if (pos->y < hover_area->y)
277 pos->y = hover_area->y;
278 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
279 pos->y = hover_area->y + hover_area->h - base_size->y;
281 if (base_size->y > hover_area->h)
282 base_size->y -= (base_size->y - hover_area->h);
284 if (pos->y < hover_area->y)
285 pos->y = hover_area->y;
289 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
290 Evas_Object *obj, void *event_info __UNUSED__)
294 wd = elm_widget_data_get(obj);
301 static Elm_Ctxpopup_Direction
302 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
305 Evas_Coord_Point pos = {0, 0};
306 Evas_Coord_Point base_size;
307 Evas_Coord_Point max_size;
308 Evas_Coord_Point min_size;
309 Evas_Coord_Rectangle hover_area;
310 Evas_Coord_Rectangle parent_size;
311 Evas_Coord_Point arrow_size;
312 Elm_Ctxpopup_Direction arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
313 Evas_Coord_Point temp;
316 wd = elm_widget_data_get(obj);
318 if ((!wd) || (!rect))
319 return ELM_CTXPOPUP_DIRECTION_DOWN;
321 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
322 &arrow_size.x, &arrow_size.y);
323 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
325 //Initialize Area Rectangle.
326 if (wd->hover_parent)
327 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
328 &hover_area.w, &hover_area.h);
331 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
332 &parent_size.w, &parent_size.h);
333 hover_area.x = parent_size.x;
334 hover_area.y = parent_size.y;
335 hover_area.w = parent_size.w;
336 hover_area.h = parent_size.h;
339 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
342 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
343 evas_object_smart_calculate(wd->base);
346 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
348 if ((max_size.y > 0) && (base_size.y > max_size.y))
349 base_size.y = max_size.y;
351 if ((max_size.x > 0) && (base_size.x > max_size.x))
352 base_size.x = max_size.x;
355 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
357 if ((min_size.y > 0) && (base_size.y < min_size.y))
358 base_size.y = min_size.y;
360 if ((min_size.x > 0) && (base_size.x < min_size.x))
361 base_size.x = min_size.x;
363 //Check the Which direction is available.
364 //If find a avaialble direction, it adjusts position and size.
365 for (idx = 0; idx < 4; idx++)
367 switch (wd->dir_priority[idx])
369 case ELM_CTXPOPUP_DIRECTION_UP:
370 temp.y = (pos.y - base_size.y);
371 if ((temp.y - arrow_size.y) < hover_area.y)
373 _adjust_pos_x(&pos, &base_size, &hover_area);
374 pos.y -= base_size.y;
375 arrow = ELM_CTXPOPUP_DIRECTION_UP;
377 case ELM_CTXPOPUP_DIRECTION_LEFT:
378 temp.x = (pos.x - base_size.x);
379 if ((temp.x - arrow_size.x) < hover_area.x)
381 _adjust_pos_y(&pos, &base_size, &hover_area);
382 pos.x -= base_size.x;
383 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
385 case ELM_CTXPOPUP_DIRECTION_RIGHT:
386 temp.x = (pos.x + base_size.x);
387 if ((temp.x + arrow_size.x) >
388 (hover_area.x + hover_area.w))
390 _adjust_pos_y(&pos, &base_size, &hover_area);
391 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
393 case ELM_CTXPOPUP_DIRECTION_DOWN:
394 temp.y = (pos.y + base_size.y);
395 if ((temp.y + arrow_size.y) >
396 (hover_area.y + hover_area.h))
398 _adjust_pos_x(&pos, &base_size, &hover_area);
399 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
407 //In this case, all directions are invalid because of lack of space.
410 Evas_Coord length[2];
414 length[0] = pos.y - hover_area.y;
415 length[1] = (hover_area.y + hover_area.h) - pos.y;
417 // ELM_CTXPOPUP_DIRECTION_UP
418 if (length[0] > length[1])
420 _adjust_pos_x(&pos, &base_size, &hover_area);
421 pos.y -= base_size.y;
422 arrow = ELM_CTXPOPUP_DIRECTION_UP;
423 if (pos.y < (hover_area.y + arrow_size.y))
425 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
426 pos.y = hover_area.y + arrow_size.y;
429 //ELM_CTXPOPUP_DIRECTION_DOWN
432 _adjust_pos_x(&pos, &base_size, &hover_area);
433 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
434 if ((pos.y + arrow_size.y + base_size.y) >
435 (hover_area.y + hover_area.h))
437 ((pos.y + arrow_size.y + base_size.y) -
438 (hover_area.y + hover_area.h));
443 length[0] = pos.x - hover_area.x;
444 length[1] = (hover_area.x + hover_area.w) - pos.x;
446 //ELM_CTXPOPUP_DIRECTION_LEFT
447 if (length[0] > length[1])
449 _adjust_pos_y(&pos, &base_size, &hover_area);
450 pos.x -= base_size.x;
451 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
452 if (pos.x < (hover_area.x + arrow_size.x))
454 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
455 pos.x = hover_area.x + arrow_size.x;
458 //ELM_CTXPOPUP_DIRECTION_RIGHT
461 _adjust_pos_y(&pos, &base_size, &hover_area);
462 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
463 if (pos.x + (arrow_size.x + base_size.x) >
464 hover_area.x + hover_area.w)
466 ((pos.x + arrow_size.x + base_size.x) -
467 (hover_area.x + hover_area.w));
472 //Final position and size.
475 rect->w = base_size.x;
476 rect->h = base_size.y;
482 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
485 Evas_Coord_Rectangle arrow_size;
486 Evas_Coord_Rectangle base_size;
489 wd = elm_widget_data_get(obj);
492 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
493 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
495 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
496 &base_size.w, &base_size.h);
498 // unswallow arrow from base
499 edje_object_part_unswallow(wd->base, wd->arrow);
503 case ELM_CTXPOPUP_DIRECTION_RIGHT:
504 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
506 // if user does not use dragable part
507 arrow_size.y = (y - (arrow_size.h * 0.5));
510 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
513 if (y < ((arrow_size.h * 0.5) + base_size.y))
515 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
516 y = base_size.h - arrow_size.h;
518 y = y - base_size.y - (arrow_size.h * 0.5);
519 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
520 (double) (y) / (double) (base_size.h - arrow_size.h));
523 case ELM_CTXPOPUP_DIRECTION_LEFT:
524 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
526 // if user does not use dragable part
527 arrow_size.y = (y - (arrow_size.h * 0.5));
528 arrow_size.x = (x - arrow_size.w);
530 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
533 if (y < (arrow_size.h * 0.5) + base_size.y)
535 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
536 y = base_size.h - arrow_size.h;
537 else y = y - base_size.y - (arrow_size.h * 0.5);
538 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
539 (double) (y) / (double) (base_size.h - arrow_size.h));
542 case ELM_CTXPOPUP_DIRECTION_DOWN:
543 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
545 // if user does not use dragable part
546 arrow_size.x = (x - (arrow_size.w * 0.5));
549 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
552 if (x < (arrow_size.w * 0.5) + base_size.x)
554 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
555 x = base_size.w - arrow_size.w;
557 x = x - base_size.x - (arrow_size.w * 0.5);
558 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
559 (double) (x) / (double) (base_size.w - arrow_size.w), 1);
562 case ELM_CTXPOPUP_DIRECTION_UP:
563 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
565 // if user does not use dragable part
566 arrow_size.x = (x - (arrow_size.w * 0.5));
567 arrow_size.y = (y - arrow_size.h);
569 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
572 if (x < (arrow_size.w * 0.5) + base_size.x)
574 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
575 x = base_size.w - arrow_size.w;
576 else x = x - base_size.x - (arrow_size.w * 0.5);
577 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
578 (double) (x) / (double) (base_size.w - arrow_size.w), 0);
585 // if user does not use dragable part
586 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
589 //TODO: compress item - different from opensource
591 _compress_item(Evas_Object *obj)
595 Elm_Ctxpopup_Item *item;
597 wd = elm_widget_data_get(obj);
600 EINA_LIST_FOREACH(wd->items, elist, item)
602 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
607 _sizing_eval(Evas_Object *obj)
611 Elm_Ctxpopup_Item *item;
612 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
613 Evas_Coord_Point box_size = { 0, 0 };
614 Evas_Coord_Point _box_size = { 0, 0 };
616 wd = elm_widget_data_get(obj);
617 if ((!wd) || (!wd->parent)) return;
620 EINA_LIST_FOREACH(wd->items, elist, item)
622 _item_sizing_eval(item);
623 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
626 if (_box_size.x > box_size.x)
627 box_size.x = _box_size.x;
628 if (_box_size.y != -1)
629 box_size.y += _box_size.y;
633 if (_box_size.x != -1)
634 box_size.x += _box_size.x;
635 if (_box_size.y > box_size.y)
636 box_size.y = _box_size.y;
642 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
643 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
647 wd->dir = _calc_base_geometry(obj, &rect);
649 //TODO: compress item - different from opensource
650 if (!wd->horizontal && !wd->content)
653 _update_arrow(obj, wd->dir);
654 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
656 //resize scroller according to final size.
658 evas_object_smart_calculate(wd->scr);
660 evas_object_move(wd->base, rect.x, rect.y);
661 evas_object_resize(wd->base, rect.w, rect.h);
665 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
666 Evas_Coord_Rectangle *rect)
668 Evas_Coord arrow_w, arrow_h;
670 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
674 case ELM_CTXPOPUP_DIRECTION_RIGHT:
677 case ELM_CTXPOPUP_DIRECTION_LEFT:
680 case ELM_CTXPOPUP_DIRECTION_DOWN:
683 case ELM_CTXPOPUP_DIRECTION_UP:
692 _del_pre_hook(Evas_Object *obj)
696 wd = elm_widget_data_get(obj);
699 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
700 _parent_resize, obj);
702 _hover_parent_callbacks_del(obj);
706 _del_hook(Evas_Object *obj)
710 wd = elm_widget_data_get(obj);
713 elm_ctxpopup_clear(obj);
714 evas_object_del(wd->arrow);
715 evas_object_del(wd->base);
720 _theme_hook(Evas_Object *obj)
724 Elm_Ctxpopup_Item *item;
727 wd = elm_widget_data_get(obj);
731 EINA_LIST_FOREACH(wd->items, elist, item)
733 if (item->label && item->icon)
734 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
735 "icon_text_style_item",
736 elm_widget_style_get(obj));
737 else if (item->label)
738 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
739 elm_widget_style_get(obj));
741 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
742 elm_widget_style_get(obj));
744 edje_object_part_text_set(item->base.view, "elm.text", item->label);
747 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
750 * For separator, if the first item has visible separator,
751 * then it should be aligned with edge of the base part.
752 * In some cases, it gives improper display. Ex) rounded corner
753 * So the first item separator should be invisible.
756 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
760 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
762 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
765 edje_object_message_signal_process(item->base.view);
768 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
769 elm_widget_style_get(obj));
770 if (evas_object_visible_get(wd->bg))
771 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
773 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
774 elm_widget_style_get(obj));
775 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
776 elm_widget_style_get(obj));
780 if (!strncmp(elm_object_style_get(obj), "default",
782 elm_object_style_set(wd->scr, "ctxpopup");
784 elm_object_style_set(wd->scr, elm_object_style_get(obj));
789 _scroller_size_reset(wd);
795 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
796 const char *emission __UNUSED__, const char *source __UNUSED__)
798 evas_object_hide(data);
802 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
803 void *event_info __UNUSED__)
808 wd = elm_widget_data_get(data);
811 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
812 evas_object_resize(wd->bg, w, h);
814 if (!wd->visible) return;
820 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
821 void *event_info __UNUSED__)
825 Elm_Ctxpopup_Item *item;
828 wd = elm_widget_data_get(obj);
831 if ((!wd->items) && (!wd->content)) return;
833 wd->visible = EINA_TRUE;
835 evas_object_show(wd->bg);
836 evas_object_show(wd->base);
837 evas_object_show(wd->arrow);
839 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
841 EINA_LIST_FOREACH(wd->items, elist, item)
844 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
848 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
850 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
858 _hide(Evas_Object *obj)
860 Widget_Data *wd = elm_widget_data_get(obj);
864 evas_object_hide(wd->bg);
865 evas_object_hide(wd->arrow);
866 evas_object_hide(wd->base);
868 _scroller_size_reset(wd);
870 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
871 wd->visible = EINA_FALSE;
875 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
876 void *event_info __UNUSED__)
880 wd = elm_widget_data_get(obj);
881 if ((!wd) || (!wd->visible))
888 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
889 void *event_info __UNUSED__)
894 wd = elm_widget_data_get(data);
896 if (!wd->visible) return;
897 if (wd->finished) return;
899 evas_object_geometry_get(obj, 0, 0, &w, &h);
901 if (w != 0 && h != 0)
903 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
906 wd->finished = EINA_TRUE;
911 if (wd->max_sc_w < w)
913 if (wd->max_sc_h < h)
920 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
921 void *event_info __UNUSED__)
925 wd = elm_widget_data_get(obj);
930 evas_object_show(wd->arrow);
932 _scroller_size_reset(wd);
937 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
938 const char *emission __UNUSED__, const char *source __UNUSED__)
940 Elm_Ctxpopup_Item *item = data;
943 if (item->disabled) return;
946 item->func((void*) item->base.data, item->base.widget, data);
950 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
954 elm_widget_sub_object_del(item->base.view, item->icon);
955 evas_object_del(item->icon);
961 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
962 edje_object_message_signal_process(item->base.view);
966 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
968 if (!eina_stringshare_replace(&item->label, label))
971 edje_object_part_text_set(item->base.view, "elm.text", label);
972 edje_object_message_signal_process(item->base.view);
976 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
980 wd = elm_widget_data_get(item->base.widget);
983 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
984 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
985 elm_widget_style_get(item->base.widget));
986 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
987 _item_select_cb, item);
988 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
989 evas_object_show(item->base.view);
993 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
994 void *event_info __UNUSED__)
996 elm_ctxpopup_content_unset(data);
1000 _list_del(Widget_Data *wd)
1002 if (!wd->scr) return;
1004 edje_object_part_unswallow(wd->base, wd->scr);
1005 evas_object_del(wd->scr);
1011 _list_new(Evas_Object *obj)
1014 wd = elm_widget_data_get(obj);
1018 wd->scr = elm_scroller_add(obj);
1019 elm_object_style_set(wd->scr, "ctxpopup");
1020 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1021 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1022 _scroller_resize, obj);
1023 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1026 wd->box = elm_box_add(obj);
1027 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1030 elm_scroller_content_set(wd->scr, wd->box);
1031 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1035 _remove_items(Widget_Data *wd)
1038 Elm_Ctxpopup_Item *item;
1040 if (!wd->items) return;
1042 EINA_LIST_FOREACH(wd->items, elist, item)
1045 eina_stringshare_del(item->label);
1047 evas_object_del(item->icon);
1048 wd->items = eina_list_remove(wd->items, item);
1056 * Add a new Ctxpopup object to the parent.
1058 * @param parent Parent object
1059 * @return New object or @c NULL, if it cannot be created
1064 elm_ctxpopup_add(Evas_Object *parent)
1069 Evas_Coord x, y, w, h;
1071 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1073 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1074 elm_widget_type_set(obj, "ctxpopup");
1075 elm_widget_sub_object_add(parent, obj);
1076 elm_widget_data_set(obj, wd);
1077 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1078 elm_widget_del_hook_set(obj, _del_hook);
1079 elm_widget_theme_hook_set(obj, _theme_hook);
1081 wd->parent = parent;
1084 wd->bg = edje_object_add(e);
1085 elm_widget_sub_object_add(obj, wd->bg);
1086 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1087 evas_object_geometry_get(parent, &x, &y, &w, &h);
1088 evas_object_move(wd->bg, x, y);
1089 evas_object_resize(wd->bg, w, h);
1090 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1091 _bg_clicked_cb, obj);
1094 wd->base = edje_object_add(e);
1095 elm_widget_sub_object_add(obj, wd->base);
1096 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1099 wd->arrow = edje_object_add(e);
1100 elm_widget_sub_object_add(obj, wd->arrow);
1101 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1103 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1104 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1105 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1106 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1108 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1110 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1112 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1114 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1116 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1117 _ctxpopup_changed_size_hints, NULL);
1118 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1119 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1120 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1121 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1123 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1129 * Get the icon object for the given ctxpopup item.
1131 * @param item Ctxpopup item
1132 * @return icon object or @c NULL, if the item does not have icon or an error occurred
1137 elm_ctxpopup_item_icon_get(const Elm_Ctxpopup_Item *item)
1139 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1144 * Sets the side icon associated with the ctxpopup item
1146 * Once the icon object is set, a previously set one will be deleted.
1147 * You probably don't want, then, to have the <b>same</b> icon object
1148 * set for more than one item of the list (when replacing one of its
1151 * @param item Ctxpopup item
1152 * @param icon Icon object to be set
1157 elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1159 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1163 wd = elm_widget_data_get(item->base.widget);
1166 _item_icon_set(item, icon);
1170 _scroller_size_reset(wd);
1171 _sizing_eval(item->base.widget);
1176 * Get the label object for the given ctxpopup item.
1178 * @param item Ctxpopup item
1179 * @return label object or @c NULL, if the item does not have label or an error occured
1185 elm_ctxpopup_item_label_get(const Elm_Ctxpopup_Item *item)
1187 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1192 * (Re)set the label on the given ctxpopup item.
1194 * @param item Ctxpopup item
1195 * @param label String to set as label
1200 elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1202 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1206 wd = elm_widget_data_get(item->base.widget);
1209 _item_label_set(item, label);
1213 _scroller_size_reset(wd);
1214 _sizing_eval(item->base.widget);
1219 * Set the Ctxpopup's parent
1220 * Set the parent object (it would much probably be the
1221 * window that the ctxpopup is in).
1223 * @param obj The ctxpopup object
1224 * @param area The parent to use
1226 * @note elm_ctxpopup_add() will automatically call this function
1227 * with its @c parent argument.
1232 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1234 ELM_CHECK_WIDTYPE(obj, widtype);
1238 wd = elm_widget_data_get(obj);
1241 _hover_parent_callbacks_del(obj);
1245 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1246 _hover_parent_del, obj);
1247 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1248 _hover_parent_move, obj);
1249 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1250 _hover_parent_resize, obj);
1253 wd->hover_parent = hover_parent;
1257 * Get the Ctxpopup's parent
1259 * @param obj The ctxpopup object
1261 * @see elm_ctxpopup_hover_parent_set() for more information
1266 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1268 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1272 wd = elm_widget_data_get(obj);
1273 if (!wd) return NULL;
1275 return wd->hover_parent;
1279 * Clear all items in the given ctxpopup object.
1281 * @param obj Ctxpopup object
1286 elm_ctxpopup_clear(Evas_Object * obj)
1288 ELM_CHECK_WIDTYPE(obj, widtype);
1290 Widget_Data *wd = elm_widget_data_get(obj);
1298 * Change the ctxpopup's orientation to horizontal or vertical.
1300 * @param obj Ctxpopup object
1301 * @param horizontal @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical
1306 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1308 ELM_CHECK_WIDTYPE(obj, widtype);
1312 Elm_Ctxpopup_Item *item;
1315 wd = elm_widget_data_get(obj);
1318 wd->horizontal = !!horizontal;
1320 if ((!wd->scr) && (!wd->box))
1325 elm_box_horizontal_set(wd->box, EINA_FALSE);
1326 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1328 EINA_LIST_FOREACH(wd->items, elist, item)
1331 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
1333 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
1338 elm_box_horizontal_set(wd->box, EINA_TRUE);
1339 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1341 EINA_LIST_FOREACH(wd->items, elist, item)
1344 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
1346 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
1355 * Get the value of current ctxpopup object's orientation.
1357 * @param obj Ctxpopup object
1358 * @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical mode (or errors)
1363 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1365 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1369 wd = elm_widget_data_get(obj);
1370 if (!wd) return EINA_FALSE;
1372 return wd->horizontal;
1376 * Add a new item to a ctxpopup object.
1378 * Both a item list and a content could not be set at the same time!
1379 * once you set add a item, the previous content will be removed.
1381 * @param obj Ctxpopup object
1382 * @param icon Icon to be set on new item
1383 * @param label The Label of the new item
1384 * @param func Convenience function called when item selected
1385 * @param data Data passed to @p func above
1386 * @return A handle to the item added or @c NULL, on errors
1390 EAPI Elm_Ctxpopup_Item *
1391 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1392 Evas_Object *icon, Evas_Smart_Cb func,
1395 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1398 Elm_Ctxpopup_Item *item;
1400 wd = elm_widget_data_get(obj);
1401 if (!wd) return NULL;
1403 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1404 if (!item) return NULL;
1406 //The first item is appended.
1408 evas_object_del(elm_ctxpopup_content_unset(obj));
1414 item->base.data = data;
1417 _item_new(item, "icon_text_style_item");
1419 _item_new(item, "text_style_item");
1421 _item_new(item, "icon_style_item");
1423 _item_icon_set(item, icon);
1424 _item_label_set(item, label);
1425 elm_box_pack_end(wd->box, item->base.view);
1426 wd->items = eina_list_append(wd->items, item);
1430 _scroller_size_reset(wd);
1438 * Delete the given item in a ctxpopup object.
1440 * @param item Ctxpopup item to be deleted
1445 elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item)
1447 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1451 wd = elm_widget_data_get(item->base.widget);
1455 evas_object_del(item->icon);
1456 if (item->base.view)
1457 evas_object_del(item->base.view);
1459 eina_stringshare_del(item->label);
1461 wd->items = eina_list_remove(wd->items, item);
1463 if (eina_list_count(wd->items) < 1)
1467 _sizing_eval(item->base.widget);
1473 * Set the ctxpopup item's state as disabled or enabled.
1475 * @param item Ctxpopup item to be enabled/disabled
1476 * @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable it
1481 elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, Eina_Bool disabled)
1483 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1487 wd = elm_widget_data_get(item->base.widget);
1490 if (disabled == item->disabled)
1494 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1496 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1498 item->disabled = !!disabled;
1502 * Get the ctxpopup item's disabled/enabled state.
1504 * @param item Ctxpopup item to be enabled/disabled
1505 * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
1510 elm_ctxpopup_item_disabled_get(const Elm_Ctxpopup_Item *item)
1512 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, EINA_FALSE);
1513 return item->disabled;
1517 * Once the content object is set, a previously set one will be deleted.
1518 * If you want to keep that old content object, use the
1519 * elm_ctxpopup_content_unset() function
1521 * Both a item list and a content could not be set at the same time!
1522 * once you set a content, the previous list items will be removed.
1524 * @param obj Ctxpopup object
1525 * @param content Content to be swallowed
1530 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1532 ELM_CHECK_WIDTYPE(obj, widtype);
1536 wd = elm_widget_data_get(obj);
1537 if ((!wd) || (!content))
1541 elm_ctxpopup_clear(obj);
1544 evas_object_del(wd->content);
1546 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1549 elm_widget_sub_object_add(obj, content);
1550 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1551 edje_object_message_signal_process(wd->base);
1553 wd->content = content;
1560 * Unset the ctxpopup content
1562 * Unparent and return the content object which was set for this widget
1564 * @param obj Ctxpopup object
1565 * @return The content that was being used
1570 elm_ctxpopup_content_unset(Evas_Object *obj)
1572 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1575 Evas_Object *content;
1577 wd = elm_widget_data_get(obj);
1578 if (!wd) return NULL;
1580 content = wd->content;
1581 if (!content) return NULL;
1583 edje_object_part_unswallow(wd->base, content);
1584 elm_widget_sub_object_del(obj, content);
1585 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1586 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1594 * Set the direction priority of a ctxpopup.
1595 * This functions gives a chance to user to set the priority of ctxpopup showing direction.
1597 * @param obj Ctxpopup object
1598 * @param first 1st priority of direction
1599 * @param second 2nd priority of direction
1600 * @param third 3th priority of direction
1601 * @param fourth 4th priority of direction
1606 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1607 Elm_Ctxpopup_Direction first,
1608 Elm_Ctxpopup_Direction second,
1609 Elm_Ctxpopup_Direction third,
1610 Elm_Ctxpopup_Direction fourth)
1612 ELM_CHECK_WIDTYPE(obj, widtype);
1615 wd = elm_widget_data_get(obj);
1618 wd->dir_priority[0] = first;
1619 wd->dir_priority[1] = second;
1620 wd->dir_priority[2] = third;
1621 wd->dir_priority[3] = fourth;
1628 * Get the direction priority of a ctxpopup.
1630 * @param obj Ctxpopup object
1631 * @param first 1st priority of direction to be returned
1632 * @param second 2nd priority of direction to be returned
1633 * @param third 3th priority of direction to be returned
1634 * @param fourth 4th priority of direction to be returned
1636 * @see elm_ctxpopup_direction_priority_set for more information.
1641 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1642 Elm_Ctxpopup_Direction *first,
1643 Elm_Ctxpopup_Direction *second,
1644 Elm_Ctxpopup_Direction *third,
1645 Elm_Ctxpopup_Direction *fourth)
1647 ELM_CHECK_WIDTYPE(obj, widtype);
1650 wd = elm_widget_data_get(obj);
1653 if (first) *first = wd->dir_priority[0];
1654 if (second) *second = wd->dir_priority[1];
1655 if (third) *third = wd->dir_priority[2];
1656 if (fourth) *fourth = wd->dir_priority[3];
1660 * @brief Get the current direction of a ctxpopup.
1662 * @param obj Ctxpopup object
1663 * @return current direction of a ctxpopup
1665 * @warning Once the ctxpopup showed up, the direction would be determined
1668 EAPI Elm_Ctxpopup_Direction
1669 elm_ctxpopup_direction_get(const Evas_Object *obj)
1671 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1674 wd = elm_widget_data_get(obj);
1675 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;