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_Point temp;
305 wd = elm_widget_data_get(obj);
307 if ((!wd) || (!rect))
308 return ELM_CTXPOPUP_DIRECTION_DOWN;
310 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
311 &arrow_size.x, &arrow_size.y);
312 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
314 //Initialize Area Rectangle.
315 if (wd->hover_parent)
316 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
317 &hover_area.w, &hover_area.h);
320 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
321 &parent_size.w, &parent_size.h);
322 hover_area.x = parent_size.x;
323 hover_area.y = parent_size.y;
324 hover_area.w = parent_size.w;
325 hover_area.h = parent_size.h;
328 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
331 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
332 evas_object_smart_calculate(wd->base);
335 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
337 if ((max_size.y > 0) && (base_size.y > max_size.y))
338 base_size.y = max_size.y;
340 if ((max_size.x > 0) && (base_size.x > max_size.x))
341 base_size.x = max_size.x;
344 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
346 if ((min_size.y > 0) && (base_size.y < min_size.y))
347 base_size.y = min_size.y;
349 if ((min_size.x > 0) && (base_size.x < min_size.x))
350 base_size.x = min_size.x;
352 //Check the Which direction is available.
353 //If find a avaialble direction, it adjusts position and size.
354 for (idx = 0; idx < 4; idx++)
356 switch (wd->dir_priority[idx])
358 case ELM_CTXPOPUP_DIRECTION_UP:
359 temp.y = (pos.y - base_size.y);
360 if ((temp.y - arrow_size.y) < hover_area.y)
362 _adjust_pos_x(&pos, &base_size, &hover_area);
363 pos.y -= base_size.y;
364 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
366 case ELM_CTXPOPUP_DIRECTION_LEFT:
367 temp.x = (pos.x - base_size.x);
368 if ((temp.x - arrow_size.x) < hover_area.x)
370 _adjust_pos_y(&pos, &base_size, &hover_area);
371 pos.x -= base_size.x;
372 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
374 case ELM_CTXPOPUP_DIRECTION_RIGHT:
375 temp.x = (pos.x + base_size.x);
376 if ((temp.x + arrow_size.x) >
377 (hover_area.x + hover_area.w))
379 _adjust_pos_y(&pos, &base_size, &hover_area);
380 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
382 case ELM_CTXPOPUP_DIRECTION_DOWN:
383 temp.y = (pos.y + base_size.y);
384 if ((temp.y + arrow_size.y) >
385 (hover_area.y + hover_area.h))
387 _adjust_pos_x(&pos, &base_size, &hover_area);
388 arrow = ELM_CTXPOPUP_DIRECTION_UP;
396 //In this case, all directions are invalid because of lack of space.
399 //TODO 1: Find the largest space direction.
400 Evas_Coord length[2];
402 length[0] = pos.y - hover_area.y;
403 length[1] = (hover_area.y + hover_area.h) - pos.y;
405 if (length[0] > length[1])
406 idx = ELM_CTXPOPUP_DIRECTION_DOWN;
408 idx = ELM_CTXPOPUP_DIRECTION_UP;
410 //TODO 2: determine x , y
413 case ELM_CTXPOPUP_DIRECTION_UP:
414 _adjust_pos_x(&pos, &base_size, &hover_area);
415 pos.y -= base_size.y;
416 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
417 if (pos.y < hover_area.y + arrow_size.y)
419 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
420 pos.y = hover_area.y + arrow_size.y;
423 case ELM_CTXPOPUP_DIRECTION_LEFT:
424 _adjust_pos_y(&pos, &base_size, &hover_area);
425 pos.x -= base_size.x;
426 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
427 if (pos.x < hover_area.x + arrow_size.x)
429 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
430 pos.x = hover_area.x + arrow_size.x;
433 case ELM_CTXPOPUP_DIRECTION_RIGHT:
434 _adjust_pos_y(&pos, &base_size, &hover_area);
435 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
436 if (pos.x + arrow_size.x + base_size.x >
437 hover_area.x + hover_area.w)
439 ((pos.x + arrow_size.x + base_size.x) -
440 (hover_area.x + hover_area.w));
442 case ELM_CTXPOPUP_DIRECTION_DOWN:
443 _adjust_pos_x(&pos, &base_size, &hover_area);
444 arrow = ELM_CTXPOPUP_DIRECTION_UP;
445 if (pos.y + arrow_size.y + base_size.y >
446 hover_area.y + hover_area.h)
448 ((pos.y + arrow_size.y + base_size.y) -
449 (hover_area.y + hover_area.h));
456 //Final position and size.
459 rect->w = base_size.x;
460 rect->h = base_size.y;
466 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
469 Evas_Coord_Rectangle arrow_size;
472 wd = elm_widget_data_get(obj);
475 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
476 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
481 case ELM_CTXPOPUP_DIRECTION_LEFT:
482 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
483 arrow_size.y = (y - (arrow_size.h * 0.5));
486 case ELM_CTXPOPUP_DIRECTION_RIGHT:
487 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
488 arrow_size.y = (y - (arrow_size.h * 0.5));
489 arrow_size.x = (x - arrow_size.w);
491 case ELM_CTXPOPUP_DIRECTION_UP:
492 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
493 arrow_size.x = (x - (arrow_size.w * 0.5));
496 case ELM_CTXPOPUP_DIRECTION_DOWN:
497 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
498 arrow_size.x = (x - (arrow_size.w * 0.5));
499 arrow_size.y = (y - arrow_size.h);
505 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
509 _sizing_eval(Evas_Object *obj)
513 Elm_Ctxpopup_Item *item;
514 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
515 Evas_Coord_Point box_size = { 0, 0 };
516 Evas_Coord_Point _box_size = { 0, 0 };
518 wd = elm_widget_data_get(obj);
519 if ((!wd) || (!wd->parent)) return;
522 EINA_LIST_FOREACH(wd->items, elist, item)
524 _item_sizing_eval(item);
525 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
528 if (_box_size.x > box_size.x)
529 box_size.x = _box_size.x;
530 if (_box_size.y != -1)
531 box_size.y += _box_size.y;
535 if (_box_size.x != -1)
536 box_size.x += _box_size.x;
537 if (_box_size.y > box_size.y)
538 box_size.y = _box_size.y;
544 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
545 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
549 wd->dir = _calc_base_geometry(obj, &rect);
550 _update_arrow(obj, wd->dir);
551 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
553 //resize scroller according to final size.
555 evas_object_smart_calculate(wd->scr);
557 evas_object_move(wd->base, rect.x, rect.y);
558 evas_object_resize(wd->base, rect.w, rect.h);
562 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
563 Evas_Coord_Rectangle *rect)
565 Evas_Coord arrow_w, arrow_h;
567 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
571 case ELM_CTXPOPUP_DIRECTION_LEFT:
574 case ELM_CTXPOPUP_DIRECTION_RIGHT:
577 case ELM_CTXPOPUP_DIRECTION_UP:
580 case ELM_CTXPOPUP_DIRECTION_DOWN:
589 _del_pre_hook(Evas_Object *obj)
593 wd = elm_widget_data_get(obj);
596 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
597 _parent_resize, obj);
599 _hover_parent_callbacks_del(obj);
603 _del_hook(Evas_Object *obj)
607 wd = elm_widget_data_get(obj);
610 elm_ctxpopup_clear(obj);
611 evas_object_del(wd->arrow);
612 evas_object_del(wd->base);
617 _theme_hook(Evas_Object *obj)
621 Elm_Ctxpopup_Item *item;
623 wd = elm_widget_data_get(obj);
627 EINA_LIST_FOREACH(wd->items, elist, item)
629 if (item->label && item->icon)
630 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
631 "icon_text_style_item",
632 elm_widget_style_get(obj));
633 else if (item->label)
634 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
635 elm_widget_style_get(obj));
637 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
638 elm_widget_style_get(obj));
640 edje_object_part_text_set(item->base.view, "elm.text", item->label);
643 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
645 edje_object_message_signal_process(item->base.view);
648 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
649 elm_widget_style_get(obj));
650 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
651 elm_widget_style_get(obj));
652 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
653 elm_widget_style_get(obj));
657 if (!strncmp(elm_object_style_get(obj), "default",
659 elm_object_style_set(wd->scr, "ctxpopup");
661 elm_object_style_set(wd->scr, elm_object_style_get(obj));
666 _scroller_size_reset(wd);
672 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
673 const char *emission __UNUSED__, const char *source __UNUSED__)
675 evas_object_hide(data);
679 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
680 void *event_info __UNUSED__)
685 wd = elm_widget_data_get(data);
688 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
689 evas_object_resize(wd->bg, w, h);
691 if (!wd->visible) return;
697 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
698 void *event_info __UNUSED__)
702 wd = elm_widget_data_get(obj);
705 if ((!wd->items) && (!wd->content)) return;
707 wd->visible = EINA_TRUE;
709 evas_object_show(wd->bg);
710 evas_object_show(wd->base);
711 evas_object_show(wd->arrow);
713 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
719 _hide(Evas_Object *obj)
721 Widget_Data *wd = elm_widget_data_get(obj);
725 evas_object_hide(wd->bg);
726 evas_object_hide(wd->arrow);
727 evas_object_hide(wd->base);
729 _scroller_size_reset(wd);
731 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
732 wd->visible = EINA_FALSE;
736 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
737 void *event_info __UNUSED__)
741 wd = elm_widget_data_get(obj);
742 if ((!wd) || (!wd->visible))
749 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
750 void *event_info __UNUSED__)
755 wd = elm_widget_data_get(data);
757 if (!wd->visible) return;
758 if (wd->finished) return;
760 evas_object_geometry_get(obj, 0, 0, &w, &h);
762 if (w != 0 && h != 0)
764 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
767 wd->finished = EINA_TRUE;
772 if (wd->max_sc_w < w)
774 if (wd->max_sc_h < h)
781 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
782 void *event_info __UNUSED__)
786 wd = elm_widget_data_get(obj);
791 evas_object_show(wd->arrow);
793 _scroller_size_reset(wd);
798 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
799 const char *emission __UNUSED__, const char *source __UNUSED__)
801 Elm_Ctxpopup_Item *item = data;
804 if (item->disabled) return;
807 item->func((void*) item->base.data, item->base.widget, data);
811 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
815 elm_widget_sub_object_del(item->base.view, item->icon);
816 evas_object_del(item->icon);
822 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
823 edje_object_message_signal_process(item->base.view);
827 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
829 if (!eina_stringshare_replace(&item->label, label))
832 edje_object_part_text_set(item->base.view, "elm.text", label);
833 edje_object_message_signal_process(item->base.view);
837 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
841 wd = elm_widget_data_get(item->base.widget);
844 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
845 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
846 elm_widget_style_get(item->base.widget));
847 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
848 _item_select_cb, item);
849 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
850 evas_object_show(item->base.view);
854 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
855 void *event_info __UNUSED__)
857 elm_ctxpopup_content_unset(data);
861 _list_del(Widget_Data *wd)
863 if (!wd->scr) return;
865 edje_object_part_unswallow(wd->base, wd->scr);
866 evas_object_del(wd->scr);
872 _list_new(Evas_Object *obj)
875 wd = elm_widget_data_get(obj);
879 wd->scr = elm_scroller_add(obj);
880 elm_object_style_set(wd->scr, "ctxpopup");
881 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
882 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
883 _scroller_resize, obj);
884 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
887 wd->box = elm_box_add(obj);
888 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
891 elm_scroller_content_set(wd->scr, wd->box);
892 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
896 _remove_items(Widget_Data *wd)
899 Elm_Ctxpopup_Item *item;
901 if (!wd->items) return;
903 EINA_LIST_FOREACH(wd->items, elist, item)
906 eina_stringshare_del(item->label);
908 evas_object_del(item->icon);
909 wd->items = eina_list_remove(wd->items, item);
917 * Add a new Ctxpopup object to the parent.
919 * @param parent Parent object
920 * @return New object or @c NULL, if it cannot be created
925 elm_ctxpopup_add(Evas_Object *parent)
930 Evas_Coord x, y, w, h;
932 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
934 wd = ELM_NEW(Widget_Data);
935 e = evas_object_evas_get(parent);
937 obj = elm_widget_add(e);
938 ELM_SET_WIDTYPE(widtype, "ctxpopup");
939 elm_widget_type_set(obj, "ctxpopup");
940 elm_widget_sub_object_add(parent, obj);
941 elm_widget_data_set(obj, wd);
942 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
943 elm_widget_del_hook_set(obj, _del_hook);
944 elm_widget_theme_hook_set(obj, _theme_hook);
949 wd->bg = edje_object_add(e);
950 elm_widget_sub_object_add(obj, wd->bg);
951 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
952 evas_object_geometry_get(parent, &x, &y, &w, &h);
953 evas_object_move(wd->bg, x, y);
954 evas_object_resize(wd->bg, w, h);
955 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
956 _bg_clicked_cb, obj);
959 wd->base = edje_object_add(e);
960 elm_widget_sub_object_add(obj, wd->base);
961 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
964 wd->arrow = edje_object_add(e);
965 elm_widget_sub_object_add(obj, wd->arrow);
966 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
968 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
969 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
970 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
971 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
973 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
975 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
977 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
979 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
981 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
982 _ctxpopup_changed_size_hints, NULL);
983 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
984 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
985 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
986 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
988 evas_object_smart_callbacks_descriptions_set(obj, _signals);
994 * Get the icon object for the given ctxpopup item.
996 * @param item Ctxpopup item
997 * @return icon object or @c NULL, if the item does not have icon or an error occurred
1002 elm_ctxpopup_item_icon_get(const Elm_Ctxpopup_Item *item)
1004 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1009 * Sets the side icon associated with the ctxpopup item
1011 * Once the icon object is set, a previously set one will be deleted.
1012 * You probably don't want, then, to have the <b>same</b> icon object
1013 * set for more than one item of the list (when replacing one of its
1016 * @param item Ctxpopup item
1017 * @param icon Icon object to be set
1022 elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1024 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1028 wd = elm_widget_data_get(item->base.widget);
1031 _item_icon_set(item, icon);
1035 _scroller_size_reset(wd);
1036 _sizing_eval(item->base.widget);
1041 * Get the label object for the given ctxpopup item.
1043 * @param item Ctxpopup item
1044 * @return label object or @c NULL, if the item does not have label or an error occured
1050 elm_ctxpopup_item_label_get(const Elm_Ctxpopup_Item *item)
1052 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1057 * (Re)set the label on the given ctxpopup item.
1059 * @param item Ctxpopup item
1060 * @param label String to set as label
1065 elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1067 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1071 wd = elm_widget_data_get(item->base.widget);
1074 _item_label_set(item, label);
1078 _scroller_size_reset(wd);
1079 _sizing_eval(item->base.widget);
1084 * Set the Ctxpopup's parent
1085 * Set the parent object (it would much probably be the
1086 * window that the ctxpopup is in).
1088 * @param obj The ctxpopup object
1089 * @param area The parent to use
1091 * @note elm_ctxpopup_add() will automatically call this function
1092 * with its @c parent argument.
1097 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1099 ELM_CHECK_WIDTYPE(obj, widtype);
1103 wd = elm_widget_data_get(obj);
1106 _hover_parent_callbacks_del(obj);
1110 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1111 _hover_parent_del, obj);
1112 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1113 _hover_parent_move, obj);
1114 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1115 _hover_parent_resize, obj);
1118 wd->hover_parent = hover_parent;
1122 * Get the Ctxpopup's parent
1124 * @param obj The ctxpopup object
1126 * @see elm_ctxpopup_hover_parent_set() for more information
1131 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1133 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1137 wd = elm_widget_data_get(obj);
1138 if (!wd) return NULL;
1140 return wd->hover_parent;
1144 * Clear all items in the given ctxpopup object.
1146 * @param obj Ctxpopup object
1151 elm_ctxpopup_clear(Evas_Object * obj)
1153 ELM_CHECK_WIDTYPE(obj, widtype);
1155 Widget_Data *wd = elm_widget_data_get(obj);
1163 * Change the ctxpopup's orientation to horizontal or vertical.
1165 * @param obj Ctxpopup object
1166 * @param horizontal @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical
1171 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1173 ELM_CHECK_WIDTYPE(obj, widtype);
1177 wd = elm_widget_data_get(obj);
1180 wd->horizontal = !!horizontal;
1182 if ((!wd->scr) && (!wd->box))
1187 elm_box_horizontal_set(wd->box, EINA_FALSE);
1188 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1192 elm_box_horizontal_set(wd->box, EINA_TRUE);
1193 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1201 * Get the value of current ctxpopup object's orientation.
1203 * @param obj Ctxpopup object
1204 * @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical mode (or errors)
1209 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1211 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1215 wd = elm_widget_data_get(obj);
1216 if (!wd) return EINA_FALSE;
1218 return wd->horizontal;
1222 * Add a new item to a ctxpopup object.
1224 * Both a item list and a content could not be set at the same time!
1225 * once you set add a item, the previous content will be removed.
1227 * @param obj Ctxpopup object
1228 * @param icon Icon to be set on new item
1229 * @param label The Label of the new item
1230 * @param func Convenience function called when item selected
1231 * @param data Data passed to @p func above
1232 * @return A handle to the item added or @c NULL, on errors
1236 EAPI Elm_Ctxpopup_Item *
1237 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1238 Evas_Object *icon, Evas_Smart_Cb func,
1241 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1244 Elm_Ctxpopup_Item *item;
1246 wd = elm_widget_data_get(obj);
1247 if (!wd) return NULL;
1249 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1250 if (!item) return NULL;
1252 //The first item is appended.
1254 evas_object_del(elm_ctxpopup_content_unset(obj));
1260 item->base.data = data;
1263 _item_new(item, "icon_text_style_item");
1265 _item_new(item, "text_style_item");
1267 _item_new(item, "icon_style_item");
1269 _item_icon_set(item, icon);
1270 _item_label_set(item, label);
1271 elm_box_pack_end(wd->box, item->base.view);
1272 wd->items = eina_list_append(wd->items, item);
1276 _scroller_size_reset(wd);
1284 * Delete the given item in a ctxpopup object.
1286 * @param item Ctxpopup item to be deleted
1291 elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item)
1293 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1297 wd = elm_widget_data_get(item->base.widget);
1301 evas_object_del(item->icon);
1302 if (item->base.view)
1303 evas_object_del(item->base.view);
1305 eina_stringshare_del(item->label);
1307 wd->items = eina_list_remove(wd->items, item);
1309 if (eina_list_count(wd->items) < 1)
1313 _sizing_eval(item->base.widget);
1319 * Set the ctxpopup item's state as disabled or enabled.
1321 * @param item Ctxpopup item to be enabled/disabled
1322 * @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable it
1327 elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, Eina_Bool disabled)
1329 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1333 wd = elm_widget_data_get(item->base.widget);
1336 if (disabled == item->disabled)
1340 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1342 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1344 item->disabled = !!disabled;
1348 * Get the ctxpopup item's disabled/enabled state.
1350 * @param item Ctxpopup item to be enabled/disabled
1351 * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
1356 elm_ctxpopup_item_disabled_get(const Elm_Ctxpopup_Item *item)
1358 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, EINA_FALSE);
1360 return item->disabled;
1364 * Once the content object is set, a previously set one will be deleted.
1365 * If you want to keep that old content object, use the
1366 * elm_ctxpopup_content_unset() function
1368 * Both a item list and a content could not be set at the same time!
1369 * once you set a content, the previous list items will be removed.
1371 * @param obj Ctxpopup object
1372 * @param content Content to be swallowed
1377 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1379 ELM_CHECK_WIDTYPE(obj, widtype);
1383 wd = elm_widget_data_get(obj);
1384 if ((!wd) || (!content))
1388 elm_ctxpopup_clear(obj);
1391 evas_object_del(wd->content);
1393 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1396 elm_widget_sub_object_add(obj, content);
1397 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1398 edje_object_message_signal_process(wd->base);
1400 wd->content = content;
1407 * Unset the ctxpopup content
1409 * Unparent and return the content object which was set for this widget
1411 * @param obj Ctxpopup object
1412 * @return The content that was being used
1417 elm_ctxpopup_content_unset(Evas_Object *obj)
1419 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1422 Evas_Object *content;
1424 wd = elm_widget_data_get(obj);
1425 if (!wd) return NULL;
1427 content = wd->content;
1428 if (!content) return NULL;
1430 edje_object_part_unswallow(wd->base, content);
1431 elm_widget_sub_object_del(obj, content);
1432 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1433 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1441 * Set the direction priority of a ctxpopup.
1442 * This functions gives a chance to user to set the priority of ctxpopup showing direction.
1444 * @param obj Ctxpopup object
1445 * @param first 1st priority of direction
1446 * @param second 2nd priority of direction
1447 * @param third 3th priority of direction
1448 * @param fourth 4th priority of direction
1453 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1454 Elm_Ctxpopup_Direction first,
1455 Elm_Ctxpopup_Direction second,
1456 Elm_Ctxpopup_Direction third,
1457 Elm_Ctxpopup_Direction fourth)
1459 ELM_CHECK_WIDTYPE(obj, widtype);
1462 wd = elm_widget_data_get(obj);
1465 wd->dir_priority[0] = first;
1466 wd->dir_priority[1] = second;
1467 wd->dir_priority[2] = third;
1468 wd->dir_priority[3] = fourth;
1475 * Get the direction priority of a ctxpopup.
1477 * @param obj Ctxpopup object
1478 * @param first 1st priority of direction to be returned
1479 * @param second 2nd priority of direction to be returned
1480 * @param third 3th priority of direction to be returned
1481 * @param fourth 4th priority of direction to be returned
1483 * @see elm_ctxpopup_direction_priority_set for more information.
1488 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1489 Elm_Ctxpopup_Direction *first,
1490 Elm_Ctxpopup_Direction *second,
1491 Elm_Ctxpopup_Direction *third,
1492 Elm_Ctxpopup_Direction *fourth)
1494 ELM_CHECK_WIDTYPE(obj, widtype);
1497 wd = elm_widget_data_get(obj);
1501 *first = wd->dir_priority[0];
1503 *second = wd->dir_priority[1];
1505 *third = wd->dir_priority[2];
1507 *fourth = wd->dir_priority[3];