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)
814 evas_object_del(item->icon);
819 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
820 edje_object_message_signal_process(item->base.view);
824 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
826 if (!eina_stringshare_replace(&item->label, label))
829 edje_object_part_text_set(item->base.view, "elm.text", label);
830 edje_object_message_signal_process(item->base.view);
834 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
838 wd = elm_widget_data_get(item->base.widget);
841 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
842 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
843 elm_widget_style_get(item->base.widget));
844 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
845 _item_select_cb, item);
846 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
847 evas_object_show(item->base.view);
851 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
852 void *event_info __UNUSED__)
854 elm_ctxpopup_content_unset(data);
858 _list_del(Widget_Data *wd)
860 if (!wd->scr) return;
862 edje_object_part_unswallow(wd->base, wd->scr);
863 evas_object_del(wd->scr);
869 _list_new(Evas_Object *obj)
872 wd = elm_widget_data_get(obj);
876 wd->scr = elm_scroller_add(obj);
877 elm_object_style_set(wd->scr, "ctxpopup");
878 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
879 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
880 _scroller_resize, obj);
881 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
884 wd->box = elm_box_add(obj);
885 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
888 elm_scroller_content_set(wd->scr, wd->box);
889 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
893 _remove_items(Widget_Data *wd)
896 Elm_Ctxpopup_Item *item;
898 if (!wd->items) return;
900 EINA_LIST_FOREACH(wd->items, elist, item)
903 eina_stringshare_del(item->label);
905 evas_object_del(item->icon);
906 wd->items = eina_list_remove(wd->items, item);
914 * Add a new Ctxpopup object to the parent.
916 * @param parent Parent object
917 * @return New object or @c NULL, if it cannot be created
922 elm_ctxpopup_add(Evas_Object *parent)
927 Evas_Coord x, y, w, h;
929 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
931 ELM_SET_WIDTYPE(widtype, "ctxpopup");
932 elm_widget_type_set(obj, "ctxpopup");
933 elm_widget_sub_object_add(parent, obj);
934 elm_widget_data_set(obj, wd);
935 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
936 elm_widget_del_hook_set(obj, _del_hook);
937 elm_widget_theme_hook_set(obj, _theme_hook);
942 wd->bg = edje_object_add(e);
943 elm_widget_sub_object_add(obj, wd->bg);
944 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
945 evas_object_geometry_get(parent, &x, &y, &w, &h);
946 evas_object_move(wd->bg, x, y);
947 evas_object_resize(wd->bg, w, h);
948 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
949 _bg_clicked_cb, obj);
952 wd->base = edje_object_add(e);
953 elm_widget_sub_object_add(obj, wd->base);
954 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
957 wd->arrow = edje_object_add(e);
958 elm_widget_sub_object_add(obj, wd->arrow);
959 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
961 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
962 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
963 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
964 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
966 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
968 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
970 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
972 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
974 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
975 _ctxpopup_changed_size_hints, NULL);
976 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
977 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
978 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
979 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
981 evas_object_smart_callbacks_descriptions_set(obj, _signals);
987 * Get the icon object for the given ctxpopup item.
989 * @param item Ctxpopup item
990 * @return icon object or @c NULL, if the item does not have icon or an error occurred
995 elm_ctxpopup_item_icon_get(const Elm_Ctxpopup_Item *item)
997 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1002 * Sets the side icon associated with the ctxpopup item
1004 * Once the icon object is set, a previously set one will be deleted.
1005 * You probably don't want, then, to have the <b>same</b> icon object
1006 * set for more than one item of the list (when replacing one of its
1009 * @param item Ctxpopup item
1010 * @param icon Icon object to be set
1015 elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1017 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1021 wd = elm_widget_data_get(item->base.widget);
1024 _item_icon_set(item, icon);
1028 _scroller_size_reset(wd);
1029 _sizing_eval(item->base.widget);
1034 * Get the label object for the given ctxpopup item.
1036 * @param item Ctxpopup item
1037 * @return label object or @c NULL, if the item does not have label or an error occured
1043 elm_ctxpopup_item_label_get(const Elm_Ctxpopup_Item *item)
1045 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1050 * (Re)set the label on the given ctxpopup item.
1052 * @param item Ctxpopup item
1053 * @param label String to set as label
1058 elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1060 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1064 wd = elm_widget_data_get(item->base.widget);
1067 _item_label_set(item, label);
1071 _scroller_size_reset(wd);
1072 _sizing_eval(item->base.widget);
1077 * Set the Ctxpopup's parent
1078 * Set the parent object (it would much probably be the
1079 * window that the ctxpopup is in).
1081 * @param obj The ctxpopup object
1082 * @param area The parent to use
1084 * @note elm_ctxpopup_add() will automatically call this function
1085 * with its @c parent argument.
1090 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1092 ELM_CHECK_WIDTYPE(obj, widtype);
1096 wd = elm_widget_data_get(obj);
1099 _hover_parent_callbacks_del(obj);
1103 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1104 _hover_parent_del, obj);
1105 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1106 _hover_parent_move, obj);
1107 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1108 _hover_parent_resize, obj);
1111 wd->hover_parent = hover_parent;
1115 * Get the Ctxpopup's parent
1117 * @param obj The ctxpopup object
1119 * @see elm_ctxpopup_hover_parent_set() for more information
1124 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1126 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1130 wd = elm_widget_data_get(obj);
1131 if (!wd) return NULL;
1133 return wd->hover_parent;
1137 * Clear all items in the given ctxpopup object.
1139 * @param obj Ctxpopup object
1144 elm_ctxpopup_clear(Evas_Object * obj)
1146 ELM_CHECK_WIDTYPE(obj, widtype);
1148 Widget_Data *wd = elm_widget_data_get(obj);
1156 * Change the ctxpopup's orientation to horizontal or vertical.
1158 * @param obj Ctxpopup object
1159 * @param horizontal @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical
1164 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1166 ELM_CHECK_WIDTYPE(obj, widtype);
1170 wd = elm_widget_data_get(obj);
1173 wd->horizontal = !!horizontal;
1175 if ((!wd->scr) && (!wd->box))
1180 elm_box_horizontal_set(wd->box, EINA_FALSE);
1181 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1185 elm_box_horizontal_set(wd->box, EINA_TRUE);
1186 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1194 * Get the value of current ctxpopup object's orientation.
1196 * @param obj Ctxpopup object
1197 * @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical mode (or errors)
1202 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1204 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1208 wd = elm_widget_data_get(obj);
1209 if (!wd) return EINA_FALSE;
1211 return wd->horizontal;
1215 * Add a new item to a ctxpopup object.
1217 * Both a item list and a content could not be set at the same time!
1218 * once you set add a item, the previous content will be removed.
1220 * @param obj Ctxpopup object
1221 * @param icon Icon to be set on new item
1222 * @param label The Label of the new item
1223 * @param func Convenience function called when item selected
1224 * @param data Data passed to @p func above
1225 * @return A handle to the item added or @c NULL, on errors
1229 EAPI Elm_Ctxpopup_Item *
1230 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1231 Evas_Object *icon, Evas_Smart_Cb func,
1234 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1237 Elm_Ctxpopup_Item *item;
1239 wd = elm_widget_data_get(obj);
1240 if (!wd) return NULL;
1242 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1243 if (!item) return NULL;
1245 //The first item is appended.
1247 evas_object_del(elm_ctxpopup_content_unset(obj));
1253 item->base.data = data;
1256 _item_new(item, "icon_text_style_item");
1258 _item_new(item, "text_style_item");
1260 _item_new(item, "icon_style_item");
1262 _item_icon_set(item, icon);
1263 _item_label_set(item, label);
1264 elm_box_pack_end(wd->box, item->base.view);
1265 wd->items = eina_list_append(wd->items, item);
1269 _scroller_size_reset(wd);
1277 * Delete the given item in a ctxpopup object.
1279 * @param item Ctxpopup item to be deleted
1284 elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item)
1286 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1290 wd = elm_widget_data_get(item->base.widget);
1294 evas_object_del(item->icon);
1295 if (item->base.view)
1296 evas_object_del(item->base.view);
1298 eina_stringshare_del(item->label);
1300 wd->items = eina_list_remove(wd->items, item);
1302 if (eina_list_count(wd->items) < 1)
1306 _sizing_eval(item->base.widget);
1312 * Set the ctxpopup item's state as disabled or enabled.
1314 * @param item Ctxpopup item to be enabled/disabled
1315 * @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable it
1320 elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, Eina_Bool disabled)
1322 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1326 wd = elm_widget_data_get(item->base.widget);
1329 if (disabled == item->disabled)
1333 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1335 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1337 item->disabled = !!disabled;
1341 * Get the ctxpopup item's disabled/enabled state.
1343 * @param item Ctxpopup item to be enabled/disabled
1344 * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
1349 elm_ctxpopup_item_disabled_get(const Elm_Ctxpopup_Item *item)
1351 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, EINA_FALSE);
1353 return item->disabled;
1357 * Once the content object is set, a previously set one will be deleted.
1358 * If you want to keep that old content object, use the
1359 * elm_ctxpopup_content_unset() function
1361 * Both a item list and a content could not be set at the same time!
1362 * once you set a content, the previous list items will be removed.
1364 * @param obj Ctxpopup object
1365 * @param content Content to be swallowed
1370 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1372 ELM_CHECK_WIDTYPE(obj, widtype);
1376 wd = elm_widget_data_get(obj);
1377 if ((!wd) || (!content))
1381 elm_ctxpopup_clear(obj);
1384 evas_object_del(wd->content);
1386 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1389 elm_widget_sub_object_add(obj, content);
1390 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1391 edje_object_message_signal_process(wd->base);
1393 wd->content = content;
1400 * Unset the ctxpopup content
1402 * Unparent and return the content object which was set for this widget
1404 * @param obj Ctxpopup object
1405 * @return The content that was being used
1410 elm_ctxpopup_content_unset(Evas_Object *obj)
1412 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1415 Evas_Object *content;
1417 wd = elm_widget_data_get(obj);
1418 if (!wd) return NULL;
1420 content = wd->content;
1421 if (!content) return NULL;
1423 edje_object_part_unswallow(wd->base, content);
1424 elm_widget_sub_object_del(obj, content);
1425 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1426 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1434 * Set the direction priority of a ctxpopup.
1435 * This functions gives a chance to user to set the priority of ctxpopup showing direction.
1437 * @param obj Ctxpopup object
1438 * @param first 1st priority of direction
1439 * @param second 2nd priority of direction
1440 * @param third 3th priority of direction
1441 * @param fourth 4th priority of direction
1446 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1447 Elm_Ctxpopup_Direction first,
1448 Elm_Ctxpopup_Direction second,
1449 Elm_Ctxpopup_Direction third,
1450 Elm_Ctxpopup_Direction fourth)
1452 ELM_CHECK_WIDTYPE(obj, widtype);
1455 wd = elm_widget_data_get(obj);
1458 wd->dir_priority[0] = first;
1459 wd->dir_priority[1] = second;
1460 wd->dir_priority[2] = third;
1461 wd->dir_priority[3] = fourth;
1468 * Get the direction priority of a ctxpopup.
1470 * @param obj Ctxpopup object
1471 * @param first 1st priority of direction to be returned
1472 * @param second 2nd priority of direction to be returned
1473 * @param third 3th priority of direction to be returned
1474 * @param fourth 4th priority of direction to be returned
1476 * @see elm_ctxpopup_direction_priority_set for more information.
1481 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1482 Elm_Ctxpopup_Direction *first,
1483 Elm_Ctxpopup_Direction *second,
1484 Elm_Ctxpopup_Direction *third,
1485 Elm_Ctxpopup_Direction *fourth)
1487 ELM_CHECK_WIDTYPE(obj, widtype);
1490 wd = elm_widget_data_get(obj);
1494 *first = wd->dir_priority[0];
1496 *second = wd->dir_priority[1];
1498 *third = wd->dir_priority[2];
1500 *fourth = wd->dir_priority[3];