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 = {0, 0};
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 = ELM_CTXPOPUP_DIRECTION_DOWN;
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);
571 _update_arrow(obj, wd->dir);
572 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
574 //resize scroller according to final size.
576 evas_object_smart_calculate(wd->scr);
578 evas_object_move(wd->base, rect.x, rect.y);
579 evas_object_resize(wd->base, rect.w, rect.h);
583 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
584 Evas_Coord_Rectangle *rect)
586 Evas_Coord arrow_w, arrow_h;
588 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
592 case ELM_CTXPOPUP_DIRECTION_LEFT:
595 case ELM_CTXPOPUP_DIRECTION_RIGHT:
598 case ELM_CTXPOPUP_DIRECTION_UP:
601 case ELM_CTXPOPUP_DIRECTION_DOWN:
610 _del_pre_hook(Evas_Object *obj)
614 wd = elm_widget_data_get(obj);
618 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
619 _parent_resize, obj);
621 _hover_parent_callbacks_del(obj);
625 _del_hook(Evas_Object *obj)
629 wd = elm_widget_data_get(obj);
633 elm_ctxpopup_clear(obj);
634 evas_object_del(wd->arrow);
635 evas_object_del(wd->base);
640 _theme_hook(Evas_Object *obj)
644 Elm_Ctxpopup_Item *item;
646 wd = elm_widget_data_get(obj);
651 EINA_LIST_FOREACH(wd->items, elist, item)
653 if (item->label && item->icon)
654 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
655 "icon_text_style_item",
656 elm_widget_style_get(obj));
657 else if (item->label)
658 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
659 elm_widget_style_get(obj));
661 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
662 elm_widget_style_get(obj));
664 edje_object_part_text_set(item->base.view, "elm.text", item->label);
667 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
669 edje_object_message_signal_process(item->base.view);
672 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
673 elm_widget_style_get(obj));
674 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
675 elm_widget_style_get(obj));
676 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
677 elm_widget_style_get(obj));
679 if (!strncmp(elm_object_style_get(obj), "default",
681 elm_object_style_set(wd->scr, "ctxpopup");
683 elm_object_style_set(wd->scr, elm_object_style_get(obj));
687 _scroller_size_reset(wd);
693 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
694 const char *emission __UNUSED__, const char *source __UNUSED__)
696 evas_object_hide(data);
700 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
701 void *event_info __UNUSED__)
706 wd = elm_widget_data_get(data);
710 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
711 evas_object_resize(wd->bg, w, h);
720 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
721 void *event_info __UNUSED__)
725 wd = elm_widget_data_get(obj);
729 if ((!wd->items) && (!wd->content))
732 wd->visible = EINA_TRUE;
734 evas_object_show(wd->bg);
735 evas_object_show(wd->base);
736 evas_object_show(wd->arrow);
738 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
744 _hide(Evas_Object *obj)
746 Widget_Data *wd = elm_widget_data_get(obj);
751 evas_object_hide(wd->bg);
752 evas_object_hide(wd->arrow);
753 evas_object_hide(wd->base);
755 _scroller_size_reset(wd);
757 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
758 wd->visible = EINA_FALSE;
762 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
763 void *event_info __UNUSED__)
767 wd = elm_widget_data_get(obj);
778 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
779 void *event_info __UNUSED__)
784 wd = elm_widget_data_get(data);
793 evas_object_geometry_get(obj, 0, 0, &w, &h);
795 if (w != 0 && h != 0)
797 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
800 wd->finished = EINA_TRUE;
805 if (wd->max_sc_w < w)
807 if (wd->max_sc_h < h)
814 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
815 void *event_info __UNUSED__)
819 wd = elm_widget_data_get(obj);
825 evas_object_show(wd->arrow);
827 _scroller_size_reset(wd);
832 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
833 const char *emission __UNUSED__, const char *source __UNUSED__)
835 Elm_Ctxpopup_Item *item = data;
843 item->func((void*) item->base.data, item->base.widget, data);
847 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
851 elm_widget_sub_object_del(item->base.view, item->icon);
852 evas_object_del(item->icon);
856 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
857 edje_object_message_signal_process(item->base.view);
861 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
863 if (!eina_stringshare_replace(&item->label, label))
866 edje_object_part_text_set(item->base.view, "elm.text", label);
867 edje_object_message_signal_process(item->base.view);
871 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
875 wd = elm_widget_data_get(item->base.widget);
879 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
880 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
881 elm_widget_style_get(item->base.widget));
882 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
883 _item_select_cb, item);
884 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
885 evas_object_show(item->base.view);
889 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
890 void *event_info __UNUSED__)
892 elm_ctxpopup_content_unset(data);
896 _list_del(Widget_Data *wd)
901 edje_object_part_unswallow(wd->base, wd->scr);
902 evas_object_del(wd->scr);
908 _list_new(Evas_Object *obj)
911 wd = elm_widget_data_get(obj);
916 wd->scr = elm_scroller_add(obj);
917 elm_object_style_set(wd->scr, "ctxpopup");
918 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
919 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
920 _scroller_resize, obj);
921 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
924 wd->box = elm_box_add(obj);
925 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
928 elm_scroller_content_set(wd->scr, wd->box);
929 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
933 * Add a new Ctxpopup object to the parent.
935 * @param parent Parent object
936 * @return New object or @c NULL, if it cannot be created
941 elm_ctxpopup_add(Evas_Object *parent)
946 Evas_Coord x, y, w, h;
948 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
950 wd = ELM_NEW(Widget_Data);
951 e = evas_object_evas_get(parent);
954 obj = elm_widget_add(e);
955 ELM_SET_WIDTYPE(widtype, "ctxpopup");
956 elm_widget_type_set(obj, "ctxpopup");
957 elm_widget_sub_object_add(parent, obj);
958 elm_widget_data_set(obj, wd);
959 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
960 elm_widget_del_hook_set(obj, _del_hook);
961 elm_widget_theme_hook_set(obj, _theme_hook);
966 wd->bg = edje_object_add(e);
967 elm_widget_sub_object_add(obj, wd->bg);
968 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
969 evas_object_geometry_get(parent, &x, &y, &w, &h);
970 evas_object_move(wd->bg, x, y);
971 evas_object_resize(wd->bg, w, h);
972 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
973 _bg_clicked_cb, obj);
976 wd->base = edje_object_add(e);
977 elm_widget_sub_object_add(obj, wd->base);
978 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
981 wd->arrow = edje_object_add(e);
982 elm_widget_sub_object_add(obj, wd->arrow);
983 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
985 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
986 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
987 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
988 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
990 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
992 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
994 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
996 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
998 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
999 _ctxpopup_changed_size_hints, NULL);
1000 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1001 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1002 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1003 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1005 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1011 * Get the icon object for the given ctxpopup item.
1013 * @param item Ctxpopup item
1014 * @return icon object or @c NULL, if the item does not have icon or an error occurred
1019 elm_ctxpopup_item_icon_get(const Elm_Ctxpopup_Item *item)
1021 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1026 * Sets the side icon associated with the ctxpopup item
1028 * Once the icon object is set, a previously set one will be deleted.
1029 * You probably don't want, then, to have the <b>same</b> icon object
1030 * set for more than one item of the list (when replacing one of its
1033 * @param item Ctxpopup item
1034 * @param icon Icon object to be set
1039 elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1041 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1045 wd = elm_widget_data_get(item->base.widget);
1049 _item_icon_set(item, icon);
1053 _scroller_size_reset(wd);
1054 _sizing_eval(item->base.widget);
1059 * Get the label object for the given ctxpopup item.
1061 * @param item Ctxpopup item
1062 * @return label object or @c NULL, if the item does not have label or an error occured
1068 elm_ctxpopup_item_label_get(const Elm_Ctxpopup_Item *item)
1070 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1075 * (Re)set the label on the given ctxpopup item.
1077 * @param item Ctxpopup item
1078 * @param label String to set as label
1083 elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1085 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1089 wd = elm_widget_data_get(item->base.widget);
1093 _item_label_set(item, label);
1097 _scroller_size_reset(wd);
1098 _sizing_eval(item->base.widget);
1103 * Set the Ctxpopup's parent
1104 * Set the parent object (it would much probably be the
1105 * window that the ctxpopup is in).
1107 * @param obj The ctxpopup object
1108 * @param area The parent to use
1110 * @note elm_ctxpopup_add() will automatically call this function
1111 * with its @c parent argument.
1116 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1118 ELM_CHECK_WIDTYPE(obj, widtype);
1122 wd = elm_widget_data_get(obj);
1126 _hover_parent_callbacks_del(obj);
1130 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1131 _hover_parent_del, obj);
1132 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1133 _hover_parent_move, obj);
1134 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1135 _hover_parent_resize, obj);
1138 wd->hover_parent = hover_parent;
1142 * Get the Ctxpopup's parent
1144 * @param obj The ctxpopup object
1146 * @see elm_ctxpopup_hover_parent_set() for more information
1151 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1153 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1157 wd = elm_widget_data_get(obj);
1161 return wd->hover_parent;
1165 _remove_items(Widget_Data *wd)
1168 Elm_Ctxpopup_Item *item;
1173 EINA_LIST_FOREACH(wd->items, elist, item)
1176 eina_stringshare_del(item->label);
1178 evas_object_del(item->icon);
1179 wd->items = eina_list_remove(wd->items, item);
1187 * Clear all items in the given ctxpopup object.
1189 * @param obj Ctxpopup object
1194 elm_ctxpopup_clear(Evas_Object * obj)
1196 ELM_CHECK_WIDTYPE(obj, widtype);
1198 Widget_Data *wd = elm_widget_data_get(obj);
1208 * Change the ctxpopup's orientation to horizontal or vertical.
1210 * @param obj Ctxpopup object
1211 * @param horizontal @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical
1216 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1218 ELM_CHECK_WIDTYPE(obj, widtype);
1222 wd = elm_widget_data_get(obj);
1226 wd->horizontal = !!horizontal;
1228 if ((!wd->scr) && (!wd->box))
1233 elm_box_horizontal_set(wd->box, EINA_FALSE);
1234 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1238 elm_box_horizontal_set(wd->box, EINA_TRUE);
1239 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1247 * Get the value of current ctxpopup object's orientation.
1249 * @param obj Ctxpopup object
1250 * @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical mode (or errors)
1255 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1257 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1261 wd = elm_widget_data_get(obj);
1265 return wd->horizontal;
1269 * Add a new item to a ctxpopup object.
1271 * Both a item list and a content could not be set at the same time!
1272 * once you set add a item, the previous content will be removed.
1274 * @param obj Ctxpopup object
1275 * @param icon Icon to be set on new item
1276 * @param label The Label of the new item
1277 * @param func Convenience function called when item selected
1278 * @param data Data passed to @p func above
1279 * @return A handle to the item added or @c NULL, on errors
1283 EAPI Elm_Ctxpopup_Item *
1284 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1285 Evas_Object *icon, Evas_Smart_Cb func,
1288 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1291 Elm_Ctxpopup_Item *item;
1293 wd = elm_widget_data_get(obj);
1297 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1301 //The first item is appended.
1303 evas_object_del(elm_ctxpopup_content_unset(obj));
1309 item->base.data = data;
1312 _item_new(item, "icon_text_style_item");
1314 _item_new(item, "text_style_item");
1316 _item_new(item, "icon_style_item");
1318 _item_icon_set(item, icon);
1319 _item_label_set(item, label);
1320 elm_box_pack_end(wd->box, item->base.view);
1321 wd->items = eina_list_append(wd->items, item);
1325 _scroller_size_reset(wd);
1333 * Delete the given item in a ctxpopup object.
1335 * @param item Ctxpopup item to be deleted
1340 elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item)
1342 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1346 wd = elm_widget_data_get(item->base.widget);
1351 evas_object_del(item->icon);
1352 if (item->base.view)
1353 evas_object_del(item->base.view);
1355 eina_stringshare_del(item->label);
1357 wd->items = eina_list_remove(wd->items, item);
1359 if (eina_list_count(wd->items) < 1)
1363 _sizing_eval(item->base.widget);
1369 * Set the ctxpopup item's state as disabled or enabled.
1371 * @param item Ctxpopup item to be enabled/disabled
1372 * @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable it
1377 elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, Eina_Bool disabled)
1379 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1383 wd = elm_widget_data_get(item->base.widget);
1387 if (disabled == item->disabled)
1391 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1393 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1395 item->disabled = !!disabled;
1399 * Get the ctxpopup item's disabled/enabled state.
1401 * @param item Ctxpopup item to be enabled/disabled
1402 * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
1407 elm_ctxpopup_item_disabled_get(const Elm_Ctxpopup_Item *item)
1409 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, EINA_FALSE);
1411 return item->disabled;
1415 * Once the content object is set, a previously set one will be deleted.
1416 * If you want to keep that old content object, use the
1417 * elm_ctxpopup_content_unset() function
1419 * Both a item list and a content could not be set at the same time!
1420 * once you set a content, the previous list items will be removed.
1422 * @param obj Ctxpopup object
1423 * @param content Content to be swallowed
1428 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1430 ELM_CHECK_WIDTYPE(obj, widtype);
1434 wd = elm_widget_data_get(obj);
1435 if ((!wd) || (!content))
1439 elm_ctxpopup_clear(obj);
1442 evas_object_del(wd->content);
1444 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1447 elm_widget_sub_object_add(obj, content);
1448 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1449 edje_object_message_signal_process(wd->base);
1451 wd->content = content;
1458 * Unset the ctxpopup content
1460 * Unparent and return the content object which was set for this widget
1462 * @param obj Ctxpopup object
1463 * @return The content that was being used
1468 elm_ctxpopup_content_unset(Evas_Object *obj)
1470 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1473 Evas_Object *content;
1475 wd = elm_widget_data_get(obj);
1479 content = wd->content;
1483 edje_object_part_unswallow(wd->base, content);
1484 elm_widget_sub_object_del(obj, content);
1485 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1486 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1494 * Set the direction priority of a ctxpopup.
1495 * This functions gives a chance to user to set the priority of ctxpopup showing direction.
1497 * @param obj Ctxpopup object
1498 * @param first 1st priority of direction
1499 * @param second 2nd priority of direction
1500 * @param third 3th priority of direction
1501 * @param fourth 4th priority of direction
1506 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1507 Elm_Ctxpopup_Direction first,
1508 Elm_Ctxpopup_Direction second,
1509 Elm_Ctxpopup_Direction third,
1510 Elm_Ctxpopup_Direction fourth)
1512 ELM_CHECK_WIDTYPE(obj, widtype);
1515 wd = elm_widget_data_get(obj);
1519 wd->dir_priority[0] = first;
1520 wd->dir_priority[1] = second;
1521 wd->dir_priority[2] = third;
1522 wd->dir_priority[3] = fourth;
1529 * Get the direction priority of a ctxpopup.
1531 * @param obj Ctxpopup object
1532 * @param first 1st priority of direction to be returned
1533 * @param second 2nd priority of direction to be returned
1534 * @param third 3th priority of direction to be returned
1535 * @param fourth 4th priority of direction to be returned
1537 * @see elm_ctxpopup_direction_priority_set for more information.
1542 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1543 Elm_Ctxpopup_Direction *first,
1544 Elm_Ctxpopup_Direction *second,
1545 Elm_Ctxpopup_Direction *third,
1546 Elm_Ctxpopup_Direction *fourth)
1548 ELM_CHECK_WIDTYPE(obj, widtype);
1551 wd = elm_widget_data_get(obj);
1556 *first = wd->dir_priority[0];
1558 *second = wd->dir_priority[1];
1560 *third = wd->dir_priority[2];
1562 *fourth = wd->dir_priority[3];