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);
133 elm_object_scroll_freeze_push(wd->scr);
137 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
138 void *event_info __UNUSED__)
140 Widget_Data *wd = elm_widget_data_get(obj);
144 elm_object_scroll_freeze_pop(wd->scr);
148 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
150 Widget_Data *wd = elm_widget_data_get(obj);
154 elm_object_scroll_hold_push(wd->scr);
158 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
160 Widget_Data *wd = elm_widget_data_get(obj);
164 elm_object_scroll_hold_pop(wd->scr);
168 _scroller_size_reset(Widget_Data *wd)
170 wd->finished = EINA_FALSE;
176 _hover_parent_callbacks_del(Evas_Object *obj)
178 Widget_Data *wd = elm_widget_data_get(obj);
180 if ((!wd) || (!wd->hover_parent))
183 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
184 _hover_parent_del, obj);
185 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
186 _hover_parent_move, obj);
187 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
188 _hover_parent_resize, obj);
192 _hover_parent_resize(void *data, Evas *e __UNUSED__,
193 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
195 Widget_Data *wd = elm_widget_data_get(data);
202 _scroller_size_reset(wd);
208 _hover_parent_move(void *data, Evas *e __UNUSED__,
209 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
211 Widget_Data *wd = elm_widget_data_get(data);
218 _scroller_size_reset(wd);
224 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
225 void *event_info __UNUSED__)
227 Widget_Data *wd = elm_widget_data_get(data);
232 wd->hover_parent = NULL;
236 _item_sizing_eval(Elm_Ctxpopup_Item *item)
238 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
240 Evas_Coord x, y, w, h;
245 evas_object_geometry_get(item->base.view, &x, &y, &w, &h);
246 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
248 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
249 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
253 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
254 Evas_Coord_Rectangle *hover_area)
256 pos->x -= (base_size->x / 2);
258 if (pos->x < hover_area->x)
259 pos->x = hover_area->x;
260 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
261 pos->x = (hover_area->x + hover_area->w) - base_size->x;
263 if (base_size->x > hover_area->w)
264 base_size->x -= (base_size->x - hover_area->w);
266 if (pos->x < hover_area->x)
267 pos->x = hover_area->x;
271 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
272 Evas_Coord_Rectangle *hover_area)
274 pos->y -= (base_size->y / 2);
276 if (pos->y < hover_area->y)
277 pos->y = hover_area->y;
278 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
279 pos->y = hover_area->y + hover_area->h - base_size->y;
281 if (base_size->y > hover_area->h)
282 base_size->y -= (base_size->y - hover_area->h);
284 if (pos->y < hover_area->y)
285 pos->y = hover_area->y;
289 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
290 Evas_Object *obj, void *event_info __UNUSED__)
294 wd = elm_widget_data_get(obj);
302 static Elm_Ctxpopup_Direction
303 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
306 Evas_Coord_Point pos;
307 Evas_Coord_Point base_size;
308 Evas_Coord_Point max_size;
309 Evas_Coord_Point min_size;
310 Evas_Coord_Rectangle hover_area;
311 Evas_Coord_Rectangle parent_size;
312 Evas_Coord_Point arrow_size;
313 Elm_Ctxpopup_Direction arrow;
314 Evas_Coord finger_size;
315 Evas_Coord_Point temp;
318 wd = elm_widget_data_get(obj);
320 if ((!wd) || (!rect))
321 return ELM_CTXPOPUP_DIRECTION_DOWN;
323 finger_size = elm_finger_size_get();
325 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
326 &arrow_size.x, &arrow_size.y);
327 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
329 //Initialize Area Rectangle.
330 if (wd->hover_parent)
331 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
332 &hover_area.w, &hover_area.h);
335 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
336 &parent_size.w, &parent_size.h);
337 hover_area.x = parent_size.x;
338 hover_area.y = parent_size.y;
339 hover_area.w = parent_size.w;
340 hover_area.h = parent_size.h;
343 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
346 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
347 evas_object_smart_calculate(wd->base);
350 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
352 if ((max_size.y > 0) && (base_size.y > max_size.y))
353 base_size.y = max_size.y;
355 if ((max_size.x > 0) && (base_size.x > max_size.x))
356 base_size.x = max_size.x;
359 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
361 if ((min_size.y > 0) && (base_size.y < min_size.y))
362 base_size.y = min_size.y;
364 if ((min_size.x > 0) && (base_size.x < min_size.x))
365 base_size.x = min_size.x;
367 //Check the Which direction is available.
368 //If find a avaialble direction, it adjusts position and size.
369 for (idx = 0; idx < 4; idx++)
371 switch (wd->dir_priority[idx])
373 case ELM_CTXPOPUP_DIRECTION_UP:
374 temp.y = pos.y - base_size.y;
375 if ((temp.y - arrow_size.y - finger_size) < hover_area.y)
377 _adjust_pos_x(&pos, &base_size, &hover_area);
378 pos.y -= (base_size.y + finger_size);
379 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
381 case ELM_CTXPOPUP_DIRECTION_LEFT:
382 temp.x = (pos.x - base_size.x);
383 if ((temp.x - arrow_size.x - finger_size) < hover_area.x)
385 _adjust_pos_y(&pos, &base_size, &hover_area);
386 pos.x -= (base_size.x + finger_size);
387 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
389 case ELM_CTXPOPUP_DIRECTION_RIGHT:
390 temp.x = (pos.x + base_size.x);
391 if ((temp.x + arrow_size.x + finger_size) >
392 (hover_area.x + hover_area.w))
394 _adjust_pos_y(&pos, &base_size, &hover_area);
395 pos.x += finger_size;
396 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
398 case ELM_CTXPOPUP_DIRECTION_DOWN:
399 temp.y = (pos.y + base_size.y);
400 if ((temp.y + arrow_size.y + finger_size) >
401 (hover_area.y + hover_area.h))
403 _adjust_pos_x(&pos, &base_size, &hover_area);
404 pos.y += finger_size;
405 arrow = ELM_CTXPOPUP_DIRECTION_UP;
413 //In this case, all directions are invalid because of lack of space.
416 //TODO 1: Find the largest space direction.
417 Evas_Coord length[2];
419 length[0] = pos.y - hover_area.y;
420 length[1] = (hover_area.y + hover_area.h) - pos.y;
422 if (length[0] > length[1])
423 idx = ELM_CTXPOPUP_DIRECTION_DOWN;
425 idx = ELM_CTXPOPUP_DIRECTION_UP;
427 //TODO 2: determine x , y
430 case ELM_CTXPOPUP_DIRECTION_UP:
431 _adjust_pos_x(&pos, &base_size, &hover_area);
432 pos.y -= (base_size.y + finger_size);
433 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
434 if (pos.y < hover_area.y + arrow_size.y)
436 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
437 pos.y = hover_area.y + arrow_size.y;
440 case ELM_CTXPOPUP_DIRECTION_LEFT:
441 _adjust_pos_y(&pos, &base_size, &hover_area);
442 pos.x -= (base_size.x + finger_size);
443 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
444 if (pos.x < hover_area.x + arrow_size.x)
446 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
447 pos.x = hover_area.x + arrow_size.x;
450 case ELM_CTXPOPUP_DIRECTION_RIGHT:
451 _adjust_pos_y(&pos, &base_size, &hover_area);
452 pos.x += finger_size;
453 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
454 if (pos.x + arrow_size.x + base_size.x >
455 hover_area.x + hover_area.w)
457 ((pos.x + arrow_size.x + base_size.x) -
458 (hover_area.x + hover_area.w));
460 case ELM_CTXPOPUP_DIRECTION_DOWN:
461 _adjust_pos_x(&pos, &base_size, &hover_area);
462 pos.y += finger_size;
463 arrow = ELM_CTXPOPUP_DIRECTION_UP;
464 if (pos.y + arrow_size.y + base_size.y >
465 hover_area.y + hover_area.h)
467 ((pos.y + arrow_size.y + base_size.y) -
468 (hover_area.y + hover_area.h));
475 //Final position and size.
478 rect->w = base_size.x;
479 rect->h = base_size.y;
485 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
488 Evas_Coord_Rectangle arrow_size;
491 wd = elm_widget_data_get(obj);
495 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
496 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
501 case ELM_CTXPOPUP_DIRECTION_LEFT:
502 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
503 arrow_size.y = (y - (arrow_size.h * 0.5));
504 arrow_size.x = (x + elm_finger_size_get());
506 case ELM_CTXPOPUP_DIRECTION_RIGHT:
507 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
508 arrow_size.y = (y - (arrow_size.h * 0.5));
509 arrow_size.x = (x - elm_finger_size_get() - arrow_size.w);
511 case ELM_CTXPOPUP_DIRECTION_UP:
512 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
513 arrow_size.x = (x - (arrow_size.w * 0.5));
514 arrow_size.y = (y + elm_finger_size_get());
516 case ELM_CTXPOPUP_DIRECTION_DOWN:
517 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
518 arrow_size.x = (x - (arrow_size.w * 0.5));
519 arrow_size.y = (y - elm_finger_size_get() - arrow_size.h);
525 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
529 _sizing_eval(Evas_Object *obj)
533 Elm_Ctxpopup_Item *item;
534 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
535 Evas_Coord_Point box_size = { 0, 0 };
536 Evas_Coord_Point _box_size = { 0, 0 };
538 wd = elm_widget_data_get(obj);
539 if ((!wd) || (!wd->parent))
543 EINA_LIST_FOREACH(wd->items, elist, item)
545 _item_sizing_eval(item);
546 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
549 if (_box_size.x > box_size.x)
550 box_size.x = _box_size.x;
551 if (_box_size.y != -1)
552 box_size.y += _box_size.y;
556 if (_box_size.x != -1)
557 box_size.x += _box_size.x;
558 if (_box_size.y > box_size.y)
559 box_size.y = _box_size.y;
565 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
566 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
570 wd->dir = _calc_base_geometry(obj, &rect);
573 _update_arrow(obj, wd->dir);
574 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
577 //resize scroller according to final size.
579 evas_object_smart_calculate(wd->scr);
581 evas_object_move(wd->base, rect.x, rect.y);
582 evas_object_resize(wd->base, rect.w, rect.h);
586 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
587 Evas_Coord_Rectangle *rect)
589 Evas_Coord arrow_w, arrow_h;
591 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
595 case ELM_CTXPOPUP_DIRECTION_LEFT:
598 case ELM_CTXPOPUP_DIRECTION_RIGHT:
601 case ELM_CTXPOPUP_DIRECTION_UP:
604 case ELM_CTXPOPUP_DIRECTION_DOWN:
613 _del_pre_hook(Evas_Object *obj)
617 wd = elm_widget_data_get(obj);
621 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
622 _parent_resize, obj);
624 _hover_parent_callbacks_del(obj);
628 _del_hook(Evas_Object *obj)
632 wd = elm_widget_data_get(obj);
636 elm_ctxpopup_clear(obj);
637 evas_object_del(wd->arrow);
638 evas_object_del(wd->base);
643 _theme_hook(Evas_Object *obj)
647 Elm_Ctxpopup_Item *item;
649 wd = elm_widget_data_get(obj);
654 EINA_LIST_FOREACH(wd->items, elist, item)
656 if (item->label && item->icon)
657 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
658 "icon_text_style_item",
659 elm_widget_style_get(obj));
660 else if (item->label)
661 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
662 elm_widget_style_get(obj));
664 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
665 elm_widget_style_get(obj));
667 edje_object_part_text_set(item->base.view, "elm.text", item->label);
670 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
672 edje_object_message_signal_process(item->base.view);
675 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
676 elm_widget_style_get(obj));
677 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
678 elm_widget_style_get(obj));
679 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
680 elm_widget_style_get(obj));
682 if(!strncmp(elm_object_style_get(obj), "default", strlen("default")
684 elm_object_style_set(wd->scr, "ctxpopup");
686 elm_object_style_set(wd->scr, elm_object_style_get(obj));
690 _scroller_size_reset(wd);
696 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
697 const char *emission __UNUSED__, const char *source __UNUSED__)
699 evas_object_hide(data);
703 _parent_resize(void *data, Evas *e, Evas_Object *obj,
704 void *event_info __UNUSED__)
709 wd = elm_widget_data_get(data);
713 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
714 evas_object_resize(wd->bg, w, h);
723 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
724 void *event_info __UNUSED__)
728 wd = elm_widget_data_get(obj);
732 if ((!wd->items) && (!wd->content))
735 wd->visible = EINA_TRUE;
737 evas_object_show(wd->bg);
738 evas_object_show(wd->base);
739 evas_object_show(wd->arrow);
741 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
747 _hide(Evas_Object *obj)
749 Widget_Data *wd = elm_widget_data_get(obj);
754 evas_object_hide(wd->bg);
755 evas_object_hide(wd->arrow);
756 evas_object_hide(wd->base);
758 _scroller_size_reset(wd);
760 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
761 wd->visible = EINA_FALSE;
765 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
766 void *event_info __UNUSED__)
770 wd = elm_widget_data_get(obj);
781 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
782 void *event_info __UNUSED__)
787 wd = elm_widget_data_get(data);
796 evas_object_geometry_get(obj, 0, 0, &w, &h);
798 if (w != 0 && h != 0)
800 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
803 wd->finished = EINA_TRUE;
808 if (wd->max_sc_w < w)
810 if (wd->max_sc_h < h)
817 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
818 void *event_info __UNUSED__)
822 wd = elm_widget_data_get(obj);
828 evas_object_show(wd->arrow);
830 _scroller_size_reset(wd);
835 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
836 const char *emission __UNUSED__, const char *source __UNUSED__)
838 Elm_Ctxpopup_Item *item = data;
846 item->func((void*) item->base.data, item->base.widget, data);
850 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
854 elm_widget_sub_object_del(item->base.view, item->icon);
855 evas_object_del(item->icon);
859 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
860 edje_object_message_signal_process(item->base.view);
864 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
866 if (!eina_stringshare_replace(&item->label, label))
869 edje_object_part_text_set(item->base.view, "elm.text", label);
870 edje_object_message_signal_process(item->base.view);
874 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
878 wd = elm_widget_data_get(item->base.widget);
882 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
883 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
884 elm_widget_style_get(item->base.widget));
885 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
886 _item_select_cb, item);
887 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
888 evas_object_show(item->base.view);
892 _content_del(void *data, Evas *e, Evas_Object *obj __UNUSED__,
893 void *event_info __UNUSED__)
895 elm_ctxpopup_content_unset(data);
899 _list_del(Widget_Data *wd)
904 edje_object_part_unswallow(wd->base, wd->scr);
905 evas_object_del(wd->scr);
911 _list_new(Evas_Object *obj)
914 wd = elm_widget_data_get(obj);
919 wd->scr = elm_scroller_add(obj);
920 elm_object_style_set(wd->scr, "ctxpopup");
921 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
922 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
923 _scroller_resize, obj);
924 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
927 wd->box = elm_box_add(obj);
928 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
931 elm_scroller_content_set(wd->scr, wd->box);
932 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
936 * Add a new Ctxpopup object to the parent.
938 * @param parent Parent object
939 * @return New object or @c NULL, if it cannot be created
944 elm_ctxpopup_add(Evas_Object *parent)
949 Evas_Coord x, y, w, h;
951 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
953 wd = ELM_NEW(Widget_Data);
954 e = evas_object_evas_get(parent);
957 obj = elm_widget_add(e);
958 ELM_SET_WIDTYPE(widtype, "ctxpopup");
959 elm_widget_type_set(obj, "ctxpopup");
960 elm_widget_sub_object_add(parent, obj);
961 elm_widget_data_set(obj, wd);
962 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
963 elm_widget_del_hook_set(obj, _del_hook);
964 elm_widget_theme_hook_set(obj, _theme_hook);
969 wd->bg = edje_object_add(e);
970 elm_widget_sub_object_add(obj, wd->bg);
971 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
972 evas_object_geometry_get(parent, &x, &y, &w, &h);
973 evas_object_move(wd->bg, x, y);
974 evas_object_resize(wd->bg, w, h);
975 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
976 _bg_clicked_cb, obj);
979 wd->base = edje_object_add(e);
980 elm_widget_sub_object_add(obj, wd->base);
981 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
984 wd->arrow = edje_object_add(e);
985 elm_widget_sub_object_add(obj, wd->arrow);
986 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
988 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
989 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
990 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
991 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
993 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
995 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
997 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
999 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1001 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1002 _ctxpopup_changed_size_hints, NULL);
1003 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1004 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1005 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1006 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1008 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1014 * Get the icon object for the given ctxpopup item.
1016 * @param item Ctxpopup item
1017 * @return icon object or @c NULL, if the item does not have icon or an error occurred
1022 elm_ctxpopup_item_icon_get(const Elm_Ctxpopup_Item *item)
1024 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1029 * Sets the side icon associated with the ctxpopup item
1031 * Once the icon object is set, a previously set one will be deleted.
1032 * You probably don't want, then, to have the <b>same</b> icon object
1033 * set for more than one item of the list (when replacing one of its
1036 * @param item Ctxpopup item
1037 * @param icon Icon object to be set
1042 elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1044 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1048 wd = elm_widget_data_get(item->base.widget);
1052 _item_icon_set(item, icon);
1056 _scroller_size_reset(wd);
1057 _sizing_eval(item->base.widget);
1062 * Get the label object for the given ctxpopup item.
1064 * @param item Ctxpopup item
1065 * @return label object or @c NULL, if the item does not have label or an error occured
1071 elm_ctxpopup_item_label_get(const Elm_Ctxpopup_Item *item)
1073 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1078 * (Re)set the label on the given ctxpopup item.
1080 * @param item Ctxpopup item
1081 * @param label String to set as label
1086 elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1088 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1092 wd = elm_widget_data_get(item->base.widget);
1096 _item_label_set(item, label);
1100 _scroller_size_reset(wd);
1101 _sizing_eval(item->base.widget);
1106 * Set the Ctxpopup's parent
1107 * Set the parent object (it would much probably be the
1108 * window that the ctxpopup is in).
1110 * @param obj The ctxpopup object
1111 * @param area The parent to use
1113 * @note elm_ctxpopup_add() will automatically call this function
1114 * with its @c parent argument.
1119 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1121 ELM_CHECK_WIDTYPE(obj, widtype);
1125 wd = elm_widget_data_get(obj);
1129 _hover_parent_callbacks_del(obj);
1133 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1134 _hover_parent_del, obj);
1135 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1136 _hover_parent_move, obj);
1137 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1138 _hover_parent_resize, obj);
1141 wd->hover_parent = hover_parent;
1145 * Get the Ctxpopup's parent
1147 * @param obj The ctxpopup object
1149 * @see elm_ctxpopup_hover_parent_set() for more information
1154 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1156 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1160 wd = elm_widget_data_get(obj);
1164 return wd->hover_parent;
1168 _remove_items(Widget_Data *wd)
1171 Elm_Ctxpopup_Item *item;
1176 EINA_LIST_FOREACH(wd->items, elist, item)
1179 eina_stringshare_del(item->label);
1181 evas_object_del(item->icon);
1182 wd->items = eina_list_remove(wd->items, item);
1190 * Clear all items in the given ctxpopup object.
1192 * @param obj Ctxpopup object
1197 elm_ctxpopup_clear(Evas_Object * obj)
1199 ELM_CHECK_WIDTYPE(obj, widtype);
1201 Widget_Data *wd = elm_widget_data_get(obj);
1211 * Change the ctxpopup's orientation to horizontal or vertical.
1213 * @param obj Ctxpopup object
1214 * @param horizontal @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical
1219 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1221 ELM_CHECK_WIDTYPE(obj, widtype);
1225 wd = elm_widget_data_get(obj);
1229 wd->horizontal = !!horizontal;
1231 if ((!wd->scr) && (!wd->box))
1236 elm_box_horizontal_set(wd->box, EINA_FALSE);
1237 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1241 elm_box_horizontal_set(wd->box, EINA_TRUE);
1242 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1250 * Get the value of current ctxpopup object's orientation.
1252 * @param obj Ctxpopup object
1253 * @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical mode (or errors)
1258 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1260 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1264 wd = elm_widget_data_get(obj);
1268 return wd->horizontal;
1272 * Add a new item to a ctxpopup object.
1274 * Both a item list and a content could not be set at the same time!
1275 * once you set add a item, the previous content will be removed.
1277 * @param obj Ctxpopup object
1278 * @param icon Icon to be set on new item
1279 * @param label The Label of the new item
1280 * @param func Convenience function called when item selected
1281 * @param data Data passed to @p func above
1282 * @return A handle to the item added or @c NULL, on errors
1286 EAPI Elm_Ctxpopup_Item *
1287 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1288 Evas_Object *icon, Evas_Smart_Cb func,
1291 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1294 Elm_Ctxpopup_Item *item;
1296 wd = elm_widget_data_get(obj);
1300 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1304 //The first item is appended.
1306 evas_object_del(elm_ctxpopup_content_unset(obj));
1312 item->base.data = data;
1315 _item_new(item, "icon_text_style_item");
1317 _item_new(item, "text_style_item");
1319 _item_new(item, "icon_style_item");
1321 _item_icon_set(item, icon);
1322 _item_label_set(item, label);
1323 elm_box_pack_end(wd->box, item->base.view);
1324 wd->items = eina_list_append(wd->items, item);
1328 _scroller_size_reset(wd);
1336 * Delete the given item in a ctxpopup object.
1338 * @param item Ctxpopup item to be deleted
1343 elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item)
1345 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1349 wd = elm_widget_data_get(item->base.widget);
1354 evas_object_del(item->icon);
1355 if (item->base.view)
1356 evas_object_del(item->base.view);
1358 eina_stringshare_del(item->label);
1360 wd->items = eina_list_remove(wd->items, item);
1362 if (eina_list_count(wd->items) < 1)
1366 _sizing_eval(item->base.widget);
1372 * Set the ctxpopup item's state as disabled or enabled.
1374 * @param item Ctxpopup item to be enabled/disabled
1375 * @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable it
1380 elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, Eina_Bool disabled)
1382 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1386 wd = elm_widget_data_get(item->base.widget);
1390 if (disabled == item->disabled)
1394 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1396 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1398 item->disabled = !!disabled;
1402 * Get the ctxpopup item's disabled/enabled state.
1404 * @param item Ctxpopup item to be enabled/disabled
1405 * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
1410 elm_ctxpopup_item_disabled_get(const Elm_Ctxpopup_Item *item)
1412 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, EINA_FALSE);
1414 return item->disabled;
1418 * Once the content object is set, a previously set one will be deleted.
1419 * If you want to keep that old content object, use the
1420 * elm_ctxpopup_content_unset() function
1422 * Both a item list and a content could not be set at the same time!
1423 * once you set a content, the previous list items will be removed.
1425 * @param obj Ctxpopup object
1426 * @param content Content to be swallowed
1431 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1433 ELM_CHECK_WIDTYPE(obj, widtype);
1437 wd = elm_widget_data_get(obj);
1438 if ((!wd) || (!content))
1442 elm_ctxpopup_clear(obj);
1445 evas_object_del(wd->content);
1447 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1450 elm_widget_sub_object_add(obj, content);
1451 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1452 edje_object_message_signal_process(wd->base);
1454 wd->content = content;
1461 * Unset the ctxpopup content
1463 * Unparent and return the content object which was set for this widget
1465 * @param obj Ctxpopup object
1466 * @return The content that was being used
1471 elm_ctxpopup_content_unset(Evas_Object *obj)
1473 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1476 Evas_Object *content;
1478 wd = elm_widget_data_get(obj);
1482 content = wd->content;
1486 edje_object_part_unswallow(wd->base, content);
1487 elm_widget_sub_object_del(obj, content);
1488 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1489 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1497 * Set the direction priority of a ctxpopup.
1498 * This functions gives a chance to user to set the priority of ctxpopup showing direction.
1500 * @param obj Ctxpopup object
1501 * @param first 1st priority of direction
1502 * @param second 2nd priority of direction
1503 * @param third 3th priority of direction
1504 * @param fourth 4th priority of direction
1509 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1510 Elm_Ctxpopup_Direction first,
1511 Elm_Ctxpopup_Direction second,
1512 Elm_Ctxpopup_Direction third,
1513 Elm_Ctxpopup_Direction fourth)
1515 ELM_CHECK_WIDTYPE(obj, widtype);
1518 wd = elm_widget_data_get(obj);
1522 wd->dir_priority[0] = first;
1523 wd->dir_priority[1] = second;
1524 wd->dir_priority[2] = third;
1525 wd->dir_priority[3] = fourth;
1532 * Get the direction priority of a ctxpopup.
1534 * @param obj Ctxpopup object
1535 * @param first 1st priority of direction to be returned
1536 * @param second 2nd priority of direction to be returned
1537 * @param third 3th priority of direction to be returned
1538 * @param fourth 4th priority of direction to be returned
1540 * @see elm_ctxpopup_direction_priority_set for more information.
1545 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1546 Elm_Ctxpopup_Direction *first,
1547 Elm_Ctxpopup_Direction *second,
1548 Elm_Ctxpopup_Direction *third,
1549 Elm_Ctxpopup_Direction *fourth)
1551 ELM_CHECK_WIDTYPE(obj, widtype);
1554 wd = elm_widget_data_get(obj);
1559 *first = wd->dir_priority[0];
1561 *second = wd->dir_priority[1];
1563 *third = wd->dir_priority[2];
1565 *fourth = wd->dir_priority[3];