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 _del_hook(Evas_Object *obj);
53 static void _del_pre_hook(Evas_Object *obj);
54 static void _theme_hook(Evas_Object *obj);
55 static void _sizing_eval(Evas_Object *obj);
56 static void _hover_parent_resize(void *data, Evas *e __UNUSED__,
57 Evas_Object *obj __UNUSED__,
58 void *event_info __UNUSED__);
59 static void _hover_parent_move(void *data, Evas *e __UNUSED__,
60 Evas_Object *obj __UNUSED__,
61 void *event_info __UNUSED__);
62 static void _hover_parent_del(void *data, Evas *e __UNUSED__,
63 Evas_Object *obj __UNUSED__,
64 void *event_info __UNUSED__);
65 static void _hover_parent_callbacks_del(Evas_Object *obj);
66 static void _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
67 const char *emission __UNUSED__,
68 const char *source __UNUSED__);
69 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
70 void *event_info __UNUSED__);
71 static void _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__,
72 Evas_Object *obj, void *event_info __UNUSED__);
73 static void _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__,
74 Evas_Object *obj, void *event_info __UNUSED__);
75 static void _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__,
76 Evas_Object *obj, void *event_info __UNUSED__);
77 static void _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
78 void *event_info __UNUSED__);
79 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
80 Evas *e __UNUSED__, Evas_Object *obj,
81 void *event_info __UNUSED__);
82 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
83 static void _list_new(Evas_Object *obj);
84 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
85 static void _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
86 const char *emission __UNUSED__,
87 const char *source __UNUSED__);
88 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
89 Evas_Coord_Rectangle *rect);
90 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
91 static void _shift_base_by_arrow(Evas_Object *arrow,
92 Elm_Ctxpopup_Direction dir,
93 Evas_Coord_Rectangle *rect);
94 static void _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
95 Evas_Coord_Rectangle *hover_area);
96 static void _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
97 Evas_Coord_Rectangle *hover_area);
98 static void _scroller_size_reset(Widget_Data *wd);
99 static void _hide(Evas_Object *obj);
100 static void _content_del(void *data, Evas *e, Evas_Object *obj __UNUSED__,
101 void *event_info __UNUSED__);
102 static void _freeze_on(void *data __UNUSED__, Evas_Object *obj,
103 void *event_info __UNUSED__);
104 static void _freeze_off(void *data __UNUSED__, Evas_Object *obj,
105 void *event_info __UNUSED__);
106 static void _hold_on(void *data __UNUSED__, Evas_Object *obj,
107 void *event_info __UNUSED__);
108 static void _hold_off(void *data __UNUSED__, Evas_Object *obj,
109 void *event_info __UNUSED__);
110 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
111 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
112 static void _remove_items(Widget_Data * wd);
114 static const char SIG_DISMISSED[] = "dismissed";
116 static const Evas_Smart_Cb_Description _signals[] = {
121 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
122 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
123 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
126 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
127 void *event_info __UNUSED__)
129 Widget_Data *wd = elm_widget_data_get(obj);
132 elm_object_scroll_freeze_push(wd->scr);
136 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
137 void *event_info __UNUSED__)
139 Widget_Data *wd = elm_widget_data_get(obj);
142 elm_object_scroll_freeze_pop(wd->scr);
146 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
148 Widget_Data *wd = elm_widget_data_get(obj);
151 elm_object_scroll_hold_push(wd->scr);
155 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
157 Widget_Data *wd = elm_widget_data_get(obj);
160 elm_object_scroll_hold_pop(wd->scr);
164 _scroller_size_reset(Widget_Data *wd)
166 wd->finished = EINA_FALSE;
172 _hover_parent_callbacks_del(Evas_Object *obj)
174 Widget_Data *wd = elm_widget_data_get(obj);
176 if ((!wd) || (!wd->hover_parent))
179 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
180 _hover_parent_del, obj);
181 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
182 _hover_parent_move, obj);
183 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
184 _hover_parent_resize, obj);
188 _hover_parent_resize(void *data, Evas *e __UNUSED__,
189 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
191 Widget_Data *wd = elm_widget_data_get(data);
197 _scroller_size_reset(wd);
203 _hover_parent_move(void *data, Evas *e __UNUSED__,
204 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
206 Widget_Data *wd = elm_widget_data_get(data);
212 _scroller_size_reset(wd);
218 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
219 void *event_info __UNUSED__)
221 Widget_Data *wd = elm_widget_data_get(data);
225 wd->hover_parent = NULL;
229 _item_sizing_eval(Elm_Ctxpopup_Item *item)
231 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
235 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
237 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
238 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
242 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
243 Evas_Coord_Rectangle *hover_area)
245 pos->x -= (base_size->x / 2);
247 if (pos->x < hover_area->x)
248 pos->x = hover_area->x;
249 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
250 pos->x = (hover_area->x + hover_area->w) - base_size->x;
252 if (base_size->x > hover_area->w)
253 base_size->x -= (base_size->x - hover_area->w);
255 if (pos->x < hover_area->x)
256 pos->x = hover_area->x;
260 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
261 Evas_Coord_Rectangle *hover_area)
263 pos->y -= (base_size->y / 2);
265 if (pos->y < hover_area->y)
266 pos->y = hover_area->y;
267 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
268 pos->y = hover_area->y + hover_area->h - base_size->y;
270 if (base_size->y > hover_area->h)
271 base_size->y -= (base_size->y - hover_area->h);
273 if (pos->y < hover_area->y)
274 pos->y = hover_area->y;
278 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
279 Evas_Object *obj, void *event_info __UNUSED__)
283 wd = elm_widget_data_get(obj);
290 static Elm_Ctxpopup_Direction
291 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
294 Evas_Coord_Point pos = {0, 0};
295 Evas_Coord_Point base_size;
296 Evas_Coord_Point max_size;
297 Evas_Coord_Point min_size;
298 Evas_Coord_Rectangle hover_area;
299 Evas_Coord_Rectangle parent_size;
300 Evas_Coord_Point arrow_size;
301 Elm_Ctxpopup_Direction arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
302 Evas_Coord finger_size;
303 Evas_Coord_Point temp;
306 wd = elm_widget_data_get(obj);
308 if ((!wd) || (!rect))
309 return ELM_CTXPOPUP_DIRECTION_DOWN;
311 finger_size = elm_finger_size_get();
313 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
314 &arrow_size.x, &arrow_size.y);
315 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
317 //Initialize Area Rectangle.
318 if (wd->hover_parent)
319 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
320 &hover_area.w, &hover_area.h);
323 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
324 &parent_size.w, &parent_size.h);
325 hover_area.x = parent_size.x;
326 hover_area.y = parent_size.y;
327 hover_area.w = parent_size.w;
328 hover_area.h = parent_size.h;
331 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
334 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
335 evas_object_smart_calculate(wd->base);
338 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
340 if ((max_size.y > 0) && (base_size.y > max_size.y))
341 base_size.y = max_size.y;
343 if ((max_size.x > 0) && (base_size.x > max_size.x))
344 base_size.x = max_size.x;
347 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
349 if ((min_size.y > 0) && (base_size.y < min_size.y))
350 base_size.y = min_size.y;
352 if ((min_size.x > 0) && (base_size.x < min_size.x))
353 base_size.x = min_size.x;
355 //Check the Which direction is available.
356 //If find a avaialble direction, it adjusts position and size.
357 for (idx = 0; idx < 4; idx++)
359 switch (wd->dir_priority[idx])
361 case ELM_CTXPOPUP_DIRECTION_UP:
362 temp.y = pos.y - base_size.y;
363 if ((temp.y - arrow_size.y - finger_size) < hover_area.y)
365 _adjust_pos_x(&pos, &base_size, &hover_area);
366 pos.y -= (base_size.y + finger_size);
367 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
369 case ELM_CTXPOPUP_DIRECTION_LEFT:
370 temp.x = (pos.x - base_size.x);
371 if ((temp.x - arrow_size.x - finger_size) < hover_area.x)
373 _adjust_pos_y(&pos, &base_size, &hover_area);
374 pos.x -= (base_size.x + finger_size);
375 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
377 case ELM_CTXPOPUP_DIRECTION_RIGHT:
378 temp.x = (pos.x + base_size.x);
379 if ((temp.x + arrow_size.x + finger_size) >
380 (hover_area.x + hover_area.w))
382 _adjust_pos_y(&pos, &base_size, &hover_area);
383 pos.x += finger_size;
384 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
386 case ELM_CTXPOPUP_DIRECTION_DOWN:
387 temp.y = (pos.y + base_size.y);
388 if ((temp.y + arrow_size.y + finger_size) >
389 (hover_area.y + hover_area.h))
391 _adjust_pos_x(&pos, &base_size, &hover_area);
392 pos.y += finger_size;
393 arrow = ELM_CTXPOPUP_DIRECTION_UP;
401 //In this case, all directions are invalid because of lack of space.
404 //TODO 1: Find the largest space direction.
405 Evas_Coord length[2];
407 length[0] = pos.y - hover_area.y;
408 length[1] = (hover_area.y + hover_area.h) - pos.y;
410 if (length[0] > length[1])
411 idx = ELM_CTXPOPUP_DIRECTION_DOWN;
413 idx = ELM_CTXPOPUP_DIRECTION_UP;
415 //TODO 2: determine x , y
418 case ELM_CTXPOPUP_DIRECTION_UP:
419 _adjust_pos_x(&pos, &base_size, &hover_area);
420 pos.y -= (base_size.y + finger_size);
421 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
422 if (pos.y < hover_area.y + arrow_size.y)
424 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
425 pos.y = hover_area.y + arrow_size.y;
428 case ELM_CTXPOPUP_DIRECTION_LEFT:
429 _adjust_pos_y(&pos, &base_size, &hover_area);
430 pos.x -= (base_size.x + finger_size);
431 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
432 if (pos.x < hover_area.x + arrow_size.x)
434 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
435 pos.x = hover_area.x + arrow_size.x;
438 case ELM_CTXPOPUP_DIRECTION_RIGHT:
439 _adjust_pos_y(&pos, &base_size, &hover_area);
440 pos.x += finger_size;
441 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
442 if (pos.x + arrow_size.x + base_size.x >
443 hover_area.x + hover_area.w)
445 ((pos.x + arrow_size.x + base_size.x) -
446 (hover_area.x + hover_area.w));
448 case ELM_CTXPOPUP_DIRECTION_DOWN:
449 _adjust_pos_x(&pos, &base_size, &hover_area);
450 pos.y += finger_size;
451 arrow = ELM_CTXPOPUP_DIRECTION_UP;
452 if (pos.y + arrow_size.y + base_size.y >
453 hover_area.y + hover_area.h)
455 ((pos.y + arrow_size.y + base_size.y) -
456 (hover_area.y + hover_area.h));
463 //Final position and size.
466 rect->w = base_size.x;
467 rect->h = base_size.y;
473 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
476 Evas_Coord_Rectangle arrow_size;
479 wd = elm_widget_data_get(obj);
482 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
483 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
488 case ELM_CTXPOPUP_DIRECTION_LEFT:
489 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
490 arrow_size.y = (y - (arrow_size.h * 0.5));
491 arrow_size.x = (x + elm_finger_size_get());
493 case ELM_CTXPOPUP_DIRECTION_RIGHT:
494 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
495 arrow_size.y = (y - (arrow_size.h * 0.5));
496 arrow_size.x = (x - elm_finger_size_get() - arrow_size.w);
498 case ELM_CTXPOPUP_DIRECTION_UP:
499 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
500 arrow_size.x = (x - (arrow_size.w * 0.5));
501 arrow_size.y = (y + elm_finger_size_get());
503 case ELM_CTXPOPUP_DIRECTION_DOWN:
504 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
505 arrow_size.x = (x - (arrow_size.w * 0.5));
506 arrow_size.y = (y - elm_finger_size_get() - arrow_size.h);
512 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
516 _sizing_eval(Evas_Object *obj)
520 Elm_Ctxpopup_Item *item;
521 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
522 Evas_Coord_Point box_size = { 0, 0 };
523 Evas_Coord_Point _box_size = { 0, 0 };
525 wd = elm_widget_data_get(obj);
526 if ((!wd) || (!wd->parent)) return;
529 EINA_LIST_FOREACH(wd->items, elist, item)
531 _item_sizing_eval(item);
532 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
535 if (_box_size.x > box_size.x)
536 box_size.x = _box_size.x;
537 if (_box_size.y != -1)
538 box_size.y += _box_size.y;
542 if (_box_size.x != -1)
543 box_size.x += _box_size.x;
544 if (_box_size.y > box_size.y)
545 box_size.y = _box_size.y;
551 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
552 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
556 wd->dir = _calc_base_geometry(obj, &rect);
557 _update_arrow(obj, wd->dir);
558 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
560 //resize scroller according to final size.
562 evas_object_smart_calculate(wd->scr);
564 evas_object_move(wd->base, rect.x, rect.y);
565 evas_object_resize(wd->base, rect.w, rect.h);
569 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
570 Evas_Coord_Rectangle *rect)
572 Evas_Coord arrow_w, arrow_h;
574 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
578 case ELM_CTXPOPUP_DIRECTION_LEFT:
581 case ELM_CTXPOPUP_DIRECTION_RIGHT:
584 case ELM_CTXPOPUP_DIRECTION_UP:
587 case ELM_CTXPOPUP_DIRECTION_DOWN:
596 _del_pre_hook(Evas_Object *obj)
600 wd = elm_widget_data_get(obj);
603 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
604 _parent_resize, obj);
606 _hover_parent_callbacks_del(obj);
610 _del_hook(Evas_Object *obj)
614 wd = elm_widget_data_get(obj);
617 elm_ctxpopup_clear(obj);
618 evas_object_del(wd->arrow);
619 evas_object_del(wd->base);
624 _theme_hook(Evas_Object *obj)
628 Elm_Ctxpopup_Item *item;
630 wd = elm_widget_data_get(obj);
634 EINA_LIST_FOREACH(wd->items, elist, item)
636 if (item->label && item->icon)
637 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
638 "icon_text_style_item",
639 elm_widget_style_get(obj));
640 else if (item->label)
641 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
642 elm_widget_style_get(obj));
644 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
645 elm_widget_style_get(obj));
647 edje_object_part_text_set(item->base.view, "elm.text", item->label);
650 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
652 edje_object_message_signal_process(item->base.view);
655 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
656 elm_widget_style_get(obj));
657 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
658 elm_widget_style_get(obj));
659 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
660 elm_widget_style_get(obj));
664 if (!strncmp(elm_object_style_get(obj), "default",
666 elm_object_style_set(wd->scr, "ctxpopup");
668 elm_object_style_set(wd->scr, elm_object_style_get(obj));
673 _scroller_size_reset(wd);
679 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
680 const char *emission __UNUSED__, const char *source __UNUSED__)
682 evas_object_hide(data);
686 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
687 void *event_info __UNUSED__)
692 wd = elm_widget_data_get(data);
695 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
696 evas_object_resize(wd->bg, w, h);
698 if (!wd->visible) return;
704 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
705 void *event_info __UNUSED__)
709 wd = elm_widget_data_get(obj);
712 if ((!wd->items) && (!wd->content)) return;
714 wd->visible = EINA_TRUE;
716 evas_object_show(wd->bg);
717 evas_object_show(wd->base);
718 evas_object_show(wd->arrow);
720 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
726 _hide(Evas_Object *obj)
728 Widget_Data *wd = elm_widget_data_get(obj);
732 evas_object_hide(wd->bg);
733 evas_object_hide(wd->arrow);
734 evas_object_hide(wd->base);
736 _scroller_size_reset(wd);
738 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
739 wd->visible = EINA_FALSE;
743 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
744 void *event_info __UNUSED__)
748 wd = elm_widget_data_get(obj);
749 if ((!wd) || (!wd->visible))
756 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
757 void *event_info __UNUSED__)
762 wd = elm_widget_data_get(data);
764 if (!wd->visible) return;
765 if (wd->finished) return;
767 evas_object_geometry_get(obj, 0, 0, &w, &h);
769 if (w != 0 && h != 0)
771 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
774 wd->finished = EINA_TRUE;
779 if (wd->max_sc_w < w)
781 if (wd->max_sc_h < h)
788 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
789 void *event_info __UNUSED__)
793 wd = elm_widget_data_get(obj);
798 evas_object_show(wd->arrow);
800 _scroller_size_reset(wd);
805 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
806 const char *emission __UNUSED__, const char *source __UNUSED__)
808 Elm_Ctxpopup_Item *item = data;
811 if (item->disabled) return;
814 item->func((void*) item->base.data, item->base.widget, data);
818 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
822 elm_widget_sub_object_del(item->base.view, item->icon);
823 evas_object_del(item->icon);
827 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
828 edje_object_message_signal_process(item->base.view);
832 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
834 if (!eina_stringshare_replace(&item->label, label))
837 edje_object_part_text_set(item->base.view, "elm.text", label);
838 edje_object_message_signal_process(item->base.view);
842 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
846 wd = elm_widget_data_get(item->base.widget);
849 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
850 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
851 elm_widget_style_get(item->base.widget));
852 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
853 _item_select_cb, item);
854 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
855 evas_object_show(item->base.view);
859 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
860 void *event_info __UNUSED__)
862 elm_ctxpopup_content_unset(data);
866 _list_del(Widget_Data *wd)
868 if (!wd->scr) return;
870 edje_object_part_unswallow(wd->base, wd->scr);
871 evas_object_del(wd->scr);
877 _list_new(Evas_Object *obj)
880 wd = elm_widget_data_get(obj);
884 wd->scr = elm_scroller_add(obj);
885 elm_object_style_set(wd->scr, "ctxpopup");
886 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
887 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
888 _scroller_resize, obj);
889 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
892 wd->box = elm_box_add(obj);
893 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
896 elm_scroller_content_set(wd->scr, wd->box);
897 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
901 _remove_items(Widget_Data *wd)
904 Elm_Ctxpopup_Item *item;
906 if (!wd->items) return;
908 EINA_LIST_FOREACH(wd->items, elist, item)
911 eina_stringshare_del(item->label);
913 evas_object_del(item->icon);
914 wd->items = eina_list_remove(wd->items, item);
922 * Add a new Ctxpopup object to the parent.
924 * @param parent Parent object
925 * @return New object or @c NULL, if it cannot be created
930 elm_ctxpopup_add(Evas_Object *parent)
935 Evas_Coord x, y, w, h;
937 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
939 wd = ELM_NEW(Widget_Data);
940 e = evas_object_evas_get(parent);
942 obj = elm_widget_add(e);
943 ELM_SET_WIDTYPE(widtype, "ctxpopup");
944 elm_widget_type_set(obj, "ctxpopup");
945 elm_widget_sub_object_add(parent, obj);
946 elm_widget_data_set(obj, wd);
947 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
948 elm_widget_del_hook_set(obj, _del_hook);
949 elm_widget_theme_hook_set(obj, _theme_hook);
954 wd->bg = edje_object_add(e);
955 elm_widget_sub_object_add(obj, wd->bg);
956 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
957 evas_object_geometry_get(parent, &x, &y, &w, &h);
958 evas_object_move(wd->bg, x, y);
959 evas_object_resize(wd->bg, w, h);
960 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
961 _bg_clicked_cb, obj);
964 wd->base = edje_object_add(e);
965 elm_widget_sub_object_add(obj, wd->base);
966 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
969 wd->arrow = edje_object_add(e);
970 elm_widget_sub_object_add(obj, wd->arrow);
971 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
973 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
974 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
975 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
976 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
978 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
980 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
982 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
984 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
986 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
987 _ctxpopup_changed_size_hints, NULL);
988 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
989 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
990 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
991 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
993 evas_object_smart_callbacks_descriptions_set(obj, _signals);
999 * Get the icon object for the given ctxpopup item.
1001 * @param item Ctxpopup item
1002 * @return icon object or @c NULL, if the item does not have icon or an error occurred
1007 elm_ctxpopup_item_icon_get(const Elm_Ctxpopup_Item *item)
1009 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1014 * Sets the side icon associated with the ctxpopup item
1016 * Once the icon object is set, a previously set one will be deleted.
1017 * You probably don't want, then, to have the <b>same</b> icon object
1018 * set for more than one item of the list (when replacing one of its
1021 * @param item Ctxpopup item
1022 * @param icon Icon object to be set
1027 elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1029 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1033 wd = elm_widget_data_get(item->base.widget);
1036 _item_icon_set(item, icon);
1040 _scroller_size_reset(wd);
1041 _sizing_eval(item->base.widget);
1046 * Get the label object for the given ctxpopup item.
1048 * @param item Ctxpopup item
1049 * @return label object or @c NULL, if the item does not have label or an error occured
1055 elm_ctxpopup_item_label_get(const Elm_Ctxpopup_Item *item)
1057 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1062 * (Re)set the label on the given ctxpopup item.
1064 * @param item Ctxpopup item
1065 * @param label String to set as label
1070 elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1072 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1076 wd = elm_widget_data_get(item->base.widget);
1079 _item_label_set(item, label);
1083 _scroller_size_reset(wd);
1084 _sizing_eval(item->base.widget);
1089 * Set the Ctxpopup's parent
1090 * Set the parent object (it would much probably be the
1091 * window that the ctxpopup is in).
1093 * @param obj The ctxpopup object
1094 * @param area The parent to use
1096 * @note elm_ctxpopup_add() will automatically call this function
1097 * with its @c parent argument.
1102 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1104 ELM_CHECK_WIDTYPE(obj, widtype);
1108 wd = elm_widget_data_get(obj);
1111 _hover_parent_callbacks_del(obj);
1115 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1116 _hover_parent_del, obj);
1117 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1118 _hover_parent_move, obj);
1119 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1120 _hover_parent_resize, obj);
1123 wd->hover_parent = hover_parent;
1127 * Get the Ctxpopup's parent
1129 * @param obj The ctxpopup object
1131 * @see elm_ctxpopup_hover_parent_set() for more information
1136 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1138 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1142 wd = elm_widget_data_get(obj);
1143 if (!wd) return NULL;
1145 return wd->hover_parent;
1149 * Clear all items in the given ctxpopup object.
1151 * @param obj Ctxpopup object
1156 elm_ctxpopup_clear(Evas_Object * obj)
1158 ELM_CHECK_WIDTYPE(obj, widtype);
1160 Widget_Data *wd = elm_widget_data_get(obj);
1168 * Change the ctxpopup's orientation to horizontal or vertical.
1170 * @param obj Ctxpopup object
1171 * @param horizontal @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical
1176 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1178 ELM_CHECK_WIDTYPE(obj, widtype);
1182 wd = elm_widget_data_get(obj);
1185 wd->horizontal = !!horizontal;
1187 if ((!wd->scr) && (!wd->box))
1192 elm_box_horizontal_set(wd->box, EINA_FALSE);
1193 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1197 elm_box_horizontal_set(wd->box, EINA_TRUE);
1198 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1206 * Get the value of current ctxpopup object's orientation.
1208 * @param obj Ctxpopup object
1209 * @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical mode (or errors)
1214 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1216 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1220 wd = elm_widget_data_get(obj);
1221 if (!wd) return EINA_FALSE;
1223 return wd->horizontal;
1227 * Add a new item to a ctxpopup object.
1229 * Both a item list and a content could not be set at the same time!
1230 * once you set add a item, the previous content will be removed.
1232 * @param obj Ctxpopup object
1233 * @param icon Icon to be set on new item
1234 * @param label The Label of the new item
1235 * @param func Convenience function called when item selected
1236 * @param data Data passed to @p func above
1237 * @return A handle to the item added or @c NULL, on errors
1241 EAPI Elm_Ctxpopup_Item *
1242 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1243 Evas_Object *icon, Evas_Smart_Cb func,
1246 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1249 Elm_Ctxpopup_Item *item;
1251 wd = elm_widget_data_get(obj);
1252 if (!wd) return NULL;
1254 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1255 if (!item) return NULL;
1257 //The first item is appended.
1259 evas_object_del(elm_ctxpopup_content_unset(obj));
1265 item->base.data = data;
1268 _item_new(item, "icon_text_style_item");
1270 _item_new(item, "text_style_item");
1272 _item_new(item, "icon_style_item");
1274 _item_icon_set(item, icon);
1275 _item_label_set(item, label);
1276 elm_box_pack_end(wd->box, item->base.view);
1277 wd->items = eina_list_append(wd->items, item);
1281 _scroller_size_reset(wd);
1289 * Delete the given item in a ctxpopup object.
1291 * @param item Ctxpopup item to be deleted
1296 elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item)
1298 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1302 wd = elm_widget_data_get(item->base.widget);
1306 evas_object_del(item->icon);
1307 if (item->base.view)
1308 evas_object_del(item->base.view);
1310 eina_stringshare_del(item->label);
1312 wd->items = eina_list_remove(wd->items, item);
1314 if (eina_list_count(wd->items) < 1)
1318 _sizing_eval(item->base.widget);
1324 * Set the ctxpopup item's state as disabled or enabled.
1326 * @param item Ctxpopup item to be enabled/disabled
1327 * @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable it
1332 elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, Eina_Bool disabled)
1334 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1338 wd = elm_widget_data_get(item->base.widget);
1341 if (disabled == item->disabled)
1345 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1347 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1349 item->disabled = !!disabled;
1353 * Get the ctxpopup item's disabled/enabled state.
1355 * @param item Ctxpopup item to be enabled/disabled
1356 * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
1361 elm_ctxpopup_item_disabled_get(const Elm_Ctxpopup_Item *item)
1363 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, EINA_FALSE);
1365 return item->disabled;
1369 * Once the content object is set, a previously set one will be deleted.
1370 * If you want to keep that old content object, use the
1371 * elm_ctxpopup_content_unset() function
1373 * Both a item list and a content could not be set at the same time!
1374 * once you set a content, the previous list items will be removed.
1376 * @param obj Ctxpopup object
1377 * @param content Content to be swallowed
1382 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1384 ELM_CHECK_WIDTYPE(obj, widtype);
1388 wd = elm_widget_data_get(obj);
1389 if ((!wd) || (!content))
1393 elm_ctxpopup_clear(obj);
1396 evas_object_del(wd->content);
1398 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1401 elm_widget_sub_object_add(obj, content);
1402 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1403 edje_object_message_signal_process(wd->base);
1405 wd->content = content;
1412 * Unset the ctxpopup content
1414 * Unparent and return the content object which was set for this widget
1416 * @param obj Ctxpopup object
1417 * @return The content that was being used
1422 elm_ctxpopup_content_unset(Evas_Object *obj)
1424 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1427 Evas_Object *content;
1429 wd = elm_widget_data_get(obj);
1430 if (!wd) return NULL;
1432 content = wd->content;
1433 if (!content) return NULL;
1435 edje_object_part_unswallow(wd->base, content);
1436 elm_widget_sub_object_del(obj, content);
1437 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1438 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1446 * Set the direction priority of a ctxpopup.
1447 * This functions gives a chance to user to set the priority of ctxpopup showing direction.
1449 * @param obj Ctxpopup object
1450 * @param first 1st priority of direction
1451 * @param second 2nd priority of direction
1452 * @param third 3th priority of direction
1453 * @param fourth 4th priority of direction
1458 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1459 Elm_Ctxpopup_Direction first,
1460 Elm_Ctxpopup_Direction second,
1461 Elm_Ctxpopup_Direction third,
1462 Elm_Ctxpopup_Direction fourth)
1464 ELM_CHECK_WIDTYPE(obj, widtype);
1467 wd = elm_widget_data_get(obj);
1470 wd->dir_priority[0] = first;
1471 wd->dir_priority[1] = second;
1472 wd->dir_priority[2] = third;
1473 wd->dir_priority[3] = fourth;
1480 * Get the direction priority of a ctxpopup.
1482 * @param obj Ctxpopup object
1483 * @param first 1st priority of direction to be returned
1484 * @param second 2nd priority of direction to be returned
1485 * @param third 3th priority of direction to be returned
1486 * @param fourth 4th priority of direction to be returned
1488 * @see elm_ctxpopup_direction_priority_set for more information.
1493 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1494 Elm_Ctxpopup_Direction *first,
1495 Elm_Ctxpopup_Direction *second,
1496 Elm_Ctxpopup_Direction *third,
1497 Elm_Ctxpopup_Direction *fourth)
1499 ELM_CHECK_WIDTYPE(obj, widtype);
1502 wd = elm_widget_data_get(obj);
1506 *first = wd->dir_priority[0];
1508 *second = wd->dir_priority[1];
1510 *third = wd->dir_priority[2];
1512 *fourth = wd->dir_priority[3];