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 _content_changed_size_hints(void *data __UNUSED__,
103 Evas *e __UNUSED__, Evas_Object *obj,
104 void *event_info __UNUSED__);
105 static void _freeze_on(void *data __UNUSED__, Evas_Object *obj,
106 void *event_info __UNUSED__);
107 static void _freeze_off(void *data __UNUSED__, Evas_Object *obj,
108 void *event_info __UNUSED__);
109 static void _hold_on(void *data __UNUSED__, Evas_Object *obj,
110 void *event_info __UNUSED__);
111 static void _hold_off(void *data __UNUSED__, Evas_Object *obj,
112 void *event_info __UNUSED__);
113 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
114 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
115 static void _remove_items(Widget_Data * wd);
117 static const char SIG_DISMISSED[] = "dismissed";
118 static const char SIG_HIDE[] = "hide";
120 static const Evas_Smart_Cb_Description _signals[] = {
122 {SIG_HIDE, ""}, //TOOD: Remove!!
126 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
127 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
128 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
131 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
132 void *event_info __UNUSED__)
134 Widget_Data *wd = elm_widget_data_get(obj);
137 if (!wd->scr) return;
139 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
143 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
144 void *event_info __UNUSED__)
146 Widget_Data *wd = elm_widget_data_get(obj);
150 if (!wd->scr) return;
153 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
155 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
159 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
161 Widget_Data *wd = elm_widget_data_get(obj);
166 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
170 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
172 Widget_Data *wd = elm_widget_data_get(obj);
178 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
180 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
184 _scroller_size_reset(Widget_Data *wd)
186 wd->finished = EINA_FALSE;
192 _hover_parent_callbacks_del(Evas_Object *obj)
194 Widget_Data *wd = elm_widget_data_get(obj);
196 if ((!wd) || (!wd->hover_parent))
199 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
200 _hover_parent_del, obj);
201 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
202 _hover_parent_move, obj);
203 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
204 _hover_parent_resize, obj);
208 _hover_parent_resize(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_move(void *data, Evas *e __UNUSED__,
225 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
227 Widget_Data *wd = elm_widget_data_get(data);
234 _scroller_size_reset(wd);
240 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
241 void *event_info __UNUSED__)
243 Widget_Data *wd = elm_widget_data_get(data);
248 wd->hover_parent = NULL;
252 _item_sizing_eval(Elm_Ctxpopup_Item *item)
254 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
256 Evas_Coord x, y, w, h;
261 evas_object_geometry_get(item->base.view, &x, &y, &w, &h);
262 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
264 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
265 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
269 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
270 Evas_Coord_Rectangle *hover_area)
272 pos->x -= (base_size->x / 2);
274 if (pos->x < hover_area->x)
275 pos->x = hover_area->x;
276 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
277 pos->x = (hover_area->x + hover_area->w) - base_size->x;
279 if (base_size->x > hover_area->w)
280 base_size->x -= (base_size->x - hover_area->w);
282 if (pos->x < hover_area->x)
283 pos->x = hover_area->x;
287 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
288 Evas_Coord_Rectangle *hover_area)
290 pos->y -= (base_size->y / 2);
292 if (pos->y < hover_area->y)
293 pos->y = hover_area->y;
294 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
295 pos->y = hover_area->y + hover_area->h - base_size->y;
297 if (base_size->y > hover_area->h)
298 base_size->y -= (base_size->y - hover_area->h);
300 if (pos->y < hover_area->y)
301 pos->y = hover_area->y;
305 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
306 Evas_Object *obj, void *event_info __UNUSED__)
310 wd = elm_widget_data_get(obj);
318 static Elm_Ctxpopup_Direction
319 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
322 Evas_Coord_Point pos = {0, 0};
323 Evas_Coord_Point base_size;
324 Evas_Coord_Point max_size;
325 Evas_Coord_Point min_size;
326 Evas_Coord_Rectangle hover_area;
327 Evas_Coord_Rectangle parent_size;
328 Evas_Coord_Point arrow_size;
329 Elm_Ctxpopup_Direction arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
330 Evas_Coord finger_size;
331 Evas_Coord_Point temp;
334 wd = elm_widget_data_get(obj);
336 if ((!wd) || (!rect))
337 return ELM_CTXPOPUP_DIRECTION_DOWN;
339 finger_size = elm_finger_size_get();
341 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
342 &arrow_size.x, &arrow_size.y);
343 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
345 //Initialize Area Rectangle.
346 if (wd->hover_parent)
347 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
348 &hover_area.w, &hover_area.h);
351 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
352 &parent_size.w, &parent_size.h);
353 hover_area.x = parent_size.x;
354 hover_area.y = parent_size.y;
355 hover_area.w = parent_size.w;
356 hover_area.h = parent_size.h;
359 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
362 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
363 evas_object_smart_calculate(wd->base);
366 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
368 if ((max_size.y > 0) && (base_size.y > max_size.y))
369 base_size.y = max_size.y;
371 if ((max_size.x > 0) && (base_size.x > max_size.x))
372 base_size.x = max_size.x;
375 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
377 if ((min_size.y > 0) && (base_size.y < min_size.y))
378 base_size.y = min_size.y;
380 if ((min_size.x > 0) && (base_size.x < min_size.x))
381 base_size.x = min_size.x;
383 //Check the Which direction is available.
384 //If find a avaialble direction, it adjusts position and size.
385 for (idx = 0; idx < 4; idx++)
387 switch (wd->dir_priority[idx])
389 case ELM_CTXPOPUP_DIRECTION_UP:
390 temp.y = pos.y - base_size.y;
391 if ((temp.y - arrow_size.y - finger_size) < hover_area.y)
393 _adjust_pos_x(&pos, &base_size, &hover_area);
394 pos.y -= (base_size.y + finger_size);
395 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
397 case ELM_CTXPOPUP_DIRECTION_LEFT:
398 temp.x = (pos.x - base_size.x);
399 if ((temp.x - arrow_size.x - finger_size) < hover_area.x)
401 _adjust_pos_y(&pos, &base_size, &hover_area);
402 pos.x -= (base_size.x + finger_size);
403 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
405 case ELM_CTXPOPUP_DIRECTION_RIGHT:
406 temp.x = (pos.x + base_size.x);
407 if ((temp.x + arrow_size.x + finger_size) >
408 (hover_area.x + hover_area.w))
410 _adjust_pos_y(&pos, &base_size, &hover_area);
411 pos.x += finger_size;
412 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
414 case ELM_CTXPOPUP_DIRECTION_DOWN:
415 temp.y = (pos.y + base_size.y);
416 if ((temp.y + arrow_size.y + finger_size) >
417 (hover_area.y + hover_area.h))
419 _adjust_pos_x(&pos, &base_size, &hover_area);
420 pos.y += finger_size;
421 arrow = ELM_CTXPOPUP_DIRECTION_UP;
429 //In this case, all directions are invalid because of lack of space.
432 //TODO 1: Find the largest space direction.
433 Evas_Coord length[2];
435 length[0] = pos.y - hover_area.y;
436 length[1] = (hover_area.y + hover_area.h) - pos.y;
438 if (length[0] > length[1])
439 idx = ELM_CTXPOPUP_DIRECTION_DOWN;
441 idx = ELM_CTXPOPUP_DIRECTION_UP;
443 //TODO 2: determine x , y
446 case ELM_CTXPOPUP_DIRECTION_UP:
447 _adjust_pos_x(&pos, &base_size, &hover_area);
448 pos.y -= (base_size.y + finger_size);
449 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
450 if (pos.y < hover_area.y + arrow_size.y)
452 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
453 pos.y = hover_area.y + arrow_size.y;
456 case ELM_CTXPOPUP_DIRECTION_LEFT:
457 _adjust_pos_y(&pos, &base_size, &hover_area);
458 pos.x -= (base_size.x + finger_size);
459 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
460 if (pos.x < hover_area.x + arrow_size.x)
462 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
463 pos.x = hover_area.x + arrow_size.x;
466 case ELM_CTXPOPUP_DIRECTION_RIGHT:
467 _adjust_pos_y(&pos, &base_size, &hover_area);
468 pos.x += finger_size;
469 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
470 if (pos.x + arrow_size.x + base_size.x >
471 hover_area.x + hover_area.w)
473 ((pos.x + arrow_size.x + base_size.x) -
474 (hover_area.x + hover_area.w));
476 case ELM_CTXPOPUP_DIRECTION_DOWN:
477 _adjust_pos_x(&pos, &base_size, &hover_area);
478 pos.y += finger_size;
479 arrow = ELM_CTXPOPUP_DIRECTION_UP;
480 if (pos.y + arrow_size.y + base_size.y >
481 hover_area.y + hover_area.h)
483 ((pos.y + arrow_size.y + base_size.y) -
484 (hover_area.y + hover_area.h));
491 //Final position and size.
494 rect->w = base_size.x;
495 rect->h = base_size.y;
501 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
504 Evas_Coord_Rectangle arrow_size;
507 wd = elm_widget_data_get(obj);
511 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
512 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
517 case ELM_CTXPOPUP_DIRECTION_LEFT:
518 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
519 arrow_size.y = (y - (arrow_size.h * 0.5));
520 arrow_size.x = (x + elm_finger_size_get());
522 case ELM_CTXPOPUP_DIRECTION_RIGHT:
523 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
524 arrow_size.y = (y - (arrow_size.h * 0.5));
525 arrow_size.x = (x - elm_finger_size_get() - arrow_size.w);
527 case ELM_CTXPOPUP_DIRECTION_UP:
528 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
529 arrow_size.x = (x - (arrow_size.w * 0.5));
530 arrow_size.y = (y + elm_finger_size_get());
532 case ELM_CTXPOPUP_DIRECTION_DOWN:
533 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
534 arrow_size.x = (x - (arrow_size.w * 0.5));
535 arrow_size.y = (y - elm_finger_size_get() - arrow_size.h);
541 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
545 _sizing_eval(Evas_Object *obj)
549 Elm_Ctxpopup_Item *item;
550 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
551 Evas_Coord_Point box_size = { 0, 0 };
552 Evas_Coord_Point _box_size = { 0, 0 };
554 wd = elm_widget_data_get(obj);
555 if ((!wd) || (!wd->parent))
559 EINA_LIST_FOREACH(wd->items, elist, item)
561 _item_sizing_eval(item);
562 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
565 if (_box_size.x > box_size.x)
566 box_size.x = _box_size.x;
567 if (_box_size.y != -1)
568 box_size.y += _box_size.y;
572 if (_box_size.x != -1)
573 box_size.x += _box_size.x;
574 if (_box_size.y > box_size.y)
575 box_size.y = _box_size.y;
581 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
582 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
586 wd->dir = _calc_base_geometry(obj, &rect);
587 _update_arrow(obj, wd->dir);
588 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
590 //resize scroller according to final size.
592 evas_object_smart_calculate(wd->scr);
594 evas_object_move(wd->base, rect.x, rect.y);
595 evas_object_resize(wd->base, rect.w, rect.h);
599 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
600 Evas_Coord_Rectangle *rect)
602 Evas_Coord arrow_w, arrow_h;
604 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
608 case ELM_CTXPOPUP_DIRECTION_LEFT:
611 case ELM_CTXPOPUP_DIRECTION_RIGHT:
614 case ELM_CTXPOPUP_DIRECTION_UP:
617 case ELM_CTXPOPUP_DIRECTION_DOWN:
626 _del_pre_hook(Evas_Object *obj)
630 wd = elm_widget_data_get(obj);
634 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
635 _parent_resize, obj);
637 _hover_parent_callbacks_del(obj);
641 _del_hook(Evas_Object *obj)
645 wd = elm_widget_data_get(obj);
649 elm_ctxpopup_clear(obj);
650 evas_object_del(wd->arrow);
651 evas_object_del(wd->base);
656 _theme_hook(Evas_Object *obj)
660 Elm_Ctxpopup_Item *item;
662 wd = elm_widget_data_get(obj);
667 EINA_LIST_FOREACH(wd->items, elist, item)
669 if (item->label && item->icon)
670 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
671 "icon_text_style_item",
672 elm_widget_style_get(obj));
673 else if (item->label)
674 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
675 elm_widget_style_get(obj));
677 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
678 elm_widget_style_get(obj));
680 edje_object_part_text_set(item->base.view, "elm.text", item->label);
683 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
685 edje_object_message_signal_process(item->base.view);
688 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
689 elm_widget_style_get(obj));
690 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
691 elm_widget_style_get(obj));
692 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
693 elm_widget_style_get(obj));
697 if (!strncmp(elm_object_style_get(obj), "default",
699 elm_object_style_set(wd->scr, "ctxpopup");
701 elm_object_style_set(wd->scr, elm_object_style_get(obj));
706 _scroller_size_reset(wd);
712 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
713 const char *emission __UNUSED__, const char *source __UNUSED__)
715 evas_object_hide(data);
719 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
720 void *event_info __UNUSED__)
725 wd = elm_widget_data_get(data);
729 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
730 evas_object_resize(wd->bg, w, h);
739 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
740 void *event_info __UNUSED__)
744 wd = elm_widget_data_get(obj);
748 if ((!wd->items) && (!wd->content))
751 wd->visible = EINA_TRUE;
753 evas_object_show(wd->bg);
754 evas_object_show(wd->base);
755 evas_object_show(wd->arrow);
757 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
763 _hide(Evas_Object *obj)
765 Widget_Data *wd = elm_widget_data_get(obj);
770 evas_object_hide(wd->bg);
771 evas_object_hide(wd->arrow);
772 evas_object_hide(wd->base);
774 _scroller_size_reset(wd);
776 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
777 evas_object_smart_callback_call(obj, SIG_HIDE, NULL); //TODO: Remove!
778 wd->visible = EINA_FALSE;
782 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
783 void *event_info __UNUSED__)
787 wd = elm_widget_data_get(obj);
798 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
799 void *event_info __UNUSED__)
804 wd = elm_widget_data_get(data);
813 evas_object_geometry_get(obj, 0, 0, &w, &h);
815 if (w != 0 && h != 0)
817 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
820 wd->finished = EINA_TRUE;
825 if (wd->max_sc_w < w)
827 if (wd->max_sc_h < h)
834 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
835 void *event_info __UNUSED__)
839 wd = elm_widget_data_get(obj);
845 evas_object_show(wd->arrow);
847 _scroller_size_reset(wd);
852 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
853 const char *emission __UNUSED__, const char *source __UNUSED__)
855 Elm_Ctxpopup_Item *item = data;
863 item->func((void*) item->base.data, item->base.widget, data);
867 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
871 elm_widget_sub_object_del(item->base.view, item->icon);
872 evas_object_del(item->icon);
876 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
877 edje_object_message_signal_process(item->base.view);
881 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
883 if (!eina_stringshare_replace(&item->label, label))
886 edje_object_part_text_set(item->base.view, "elm.text", label);
887 edje_object_message_signal_process(item->base.view);
891 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
895 wd = elm_widget_data_get(item->base.widget);
899 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
900 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
901 elm_widget_style_get(item->base.widget));
902 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
903 _item_select_cb, item);
904 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
905 evas_object_show(item->base.view);
909 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
910 void *event_info __UNUSED__)
912 elm_ctxpopup_content_unset(data);
916 _content_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
917 Evas_Object *obj, void *event_info __UNUSED__)
921 wd = elm_widget_data_get(data);
930 _list_del(Widget_Data *wd)
935 edje_object_part_unswallow(wd->base, wd->scr);
936 evas_object_del(wd->scr);
942 _list_new(Evas_Object *obj)
945 wd = elm_widget_data_get(obj);
950 wd->scr = elm_scroller_add(obj);
951 elm_object_style_set(wd->scr, "ctxpopup");
952 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
953 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
954 _scroller_resize, obj);
955 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
958 wd->box = elm_box_add(obj);
959 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
962 elm_scroller_content_set(wd->scr, wd->box);
963 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
967 * Add a new Ctxpopup object to the parent.
969 * @param parent Parent object
970 * @return New object or @c NULL, if it cannot be created
975 elm_ctxpopup_add(Evas_Object *parent)
980 Evas_Coord x, y, w, h;
982 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
984 wd = ELM_NEW(Widget_Data);
985 e = evas_object_evas_get(parent);
988 obj = elm_widget_add(e);
989 ELM_SET_WIDTYPE(widtype, "ctxpopup");
990 elm_widget_type_set(obj, "ctxpopup");
991 elm_widget_sub_object_add(parent, obj);
992 elm_widget_data_set(obj, wd);
993 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
994 elm_widget_del_hook_set(obj, _del_hook);
995 elm_widget_theme_hook_set(obj, _theme_hook);
1000 wd->bg = edje_object_add(e);
1001 elm_widget_sub_object_add(obj, wd->bg);
1002 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1003 evas_object_geometry_get(parent, &x, &y, &w, &h);
1004 evas_object_move(wd->bg, x, y);
1005 evas_object_resize(wd->bg, w, h);
1006 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1007 _bg_clicked_cb, obj);
1010 wd->base = edje_object_add(e);
1011 elm_widget_sub_object_add(obj, wd->base);
1012 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1015 wd->arrow = edje_object_add(e);
1016 elm_widget_sub_object_add(obj, wd->arrow);
1017 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1019 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1020 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1021 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1022 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1024 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1026 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1028 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1030 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1032 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1033 _ctxpopup_changed_size_hints, NULL);
1034 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1035 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1036 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1037 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1039 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1045 * Get the icon object for the given ctxpopup item.
1047 * @param item Ctxpopup item
1048 * @return icon object or @c NULL, if the item does not have icon or an error occurred
1053 elm_ctxpopup_item_icon_get(const Elm_Ctxpopup_Item *item)
1055 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1060 * Sets the side icon associated with the ctxpopup item
1062 * Once the icon object is set, a previously set one will be deleted.
1063 * You probably don't want, then, to have the <b>same</b> icon object
1064 * set for more than one item of the list (when replacing one of its
1067 * @param item Ctxpopup item
1068 * @param icon Icon object to be set
1073 elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1075 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1079 wd = elm_widget_data_get(item->base.widget);
1083 _item_icon_set(item, icon);
1087 _scroller_size_reset(wd);
1088 _sizing_eval(item->base.widget);
1093 * Get the label object for the given ctxpopup item.
1095 * @param item Ctxpopup item
1096 * @return label object or @c NULL, if the item does not have label or an error occured
1102 elm_ctxpopup_item_label_get(const Elm_Ctxpopup_Item *item)
1104 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1109 * (Re)set the label on the given ctxpopup item.
1111 * @param item Ctxpopup item
1112 * @param label String to set as label
1117 elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1119 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1123 wd = elm_widget_data_get(item->base.widget);
1127 _item_label_set(item, label);
1131 _scroller_size_reset(wd);
1132 _sizing_eval(item->base.widget);
1137 * Set the Ctxpopup's parent
1138 * Set the parent object (it would much probably be the
1139 * window that the ctxpopup is in).
1141 * @param obj The ctxpopup object
1142 * @param area The parent to use
1144 * @note elm_ctxpopup_add() will automatically call this function
1145 * with its @c parent argument.
1150 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1152 ELM_CHECK_WIDTYPE(obj, widtype);
1156 wd = elm_widget_data_get(obj);
1160 _hover_parent_callbacks_del(obj);
1164 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1165 _hover_parent_del, obj);
1166 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1167 _hover_parent_move, obj);
1168 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1169 _hover_parent_resize, obj);
1172 wd->hover_parent = hover_parent;
1176 * Get the Ctxpopup's parent
1178 * @param obj The ctxpopup object
1180 * @see elm_ctxpopup_hover_parent_set() for more information
1185 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1187 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1191 wd = elm_widget_data_get(obj);
1195 return wd->hover_parent;
1199 _remove_items(Widget_Data *wd)
1202 Elm_Ctxpopup_Item *item;
1207 EINA_LIST_FOREACH(wd->items, elist, item)
1210 eina_stringshare_del(item->label);
1212 evas_object_del(item->icon);
1213 wd->items = eina_list_remove(wd->items, item);
1221 * Clear all items in the given ctxpopup object.
1223 * @param obj Ctxpopup object
1228 elm_ctxpopup_clear(Evas_Object * obj)
1230 ELM_CHECK_WIDTYPE(obj, widtype);
1232 Widget_Data *wd = elm_widget_data_get(obj);
1242 * Change the ctxpopup's orientation to horizontal or vertical.
1244 * @param obj Ctxpopup object
1245 * @param horizontal @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical
1250 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1252 ELM_CHECK_WIDTYPE(obj, widtype);
1256 Elm_Ctxpopup_Item *item;
1258 wd = elm_widget_data_get(obj);
1262 wd->horizontal = !!horizontal;
1264 if ((!wd->scr) && (!wd->box))
1269 elm_box_horizontal_set(wd->box, EINA_FALSE);
1270 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1272 edje_object_signal_emit(wd->base, "elm,state,vertical", "elm");
1273 EINA_LIST_FOREACH(wd->items, elist, item)
1275 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
1280 elm_box_horizontal_set(wd->box, EINA_TRUE);
1281 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1283 edje_object_signal_emit(wd->base, "elm,state,horizontal", "elm");
1284 EINA_LIST_FOREACH(wd->items, elist, item)
1286 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
1295 * Get the value of current ctxpopup object's orientation.
1297 * @param obj Ctxpopup object
1298 * @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical mode (or errors)
1303 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1305 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1309 wd = elm_widget_data_get(obj);
1313 return wd->horizontal;
1317 * Add a new item to a ctxpopup object.
1319 * Both a item list and a content could not be set at the same time!
1320 * once you set add a item, the previous content will be removed.
1322 * @param obj Ctxpopup object
1323 * @param icon Icon to be set on new item
1324 * @param label The Label of the new item
1325 * @param func Convenience function called when item selected
1326 * @param data Data passed to @p func above
1327 * @return A handle to the item added or @c NULL, on errors
1331 EAPI Elm_Ctxpopup_Item *
1332 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1333 Evas_Object *icon, Evas_Smart_Cb func,
1336 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1339 Elm_Ctxpopup_Item *item;
1341 wd = elm_widget_data_get(obj);
1345 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1349 //The first item is appended.
1351 evas_object_del(elm_ctxpopup_content_unset(obj));
1357 item->base.data = data;
1360 _item_new(item, "icon_text_style_item");
1362 _item_new(item, "text_style_item");
1364 _item_new(item, "icon_style_item");
1366 _item_icon_set(item, icon);
1367 _item_label_set(item, label);
1368 elm_box_pack_end(wd->box, item->base.view);
1369 wd->items = eina_list_append(wd->items, item);
1373 _scroller_size_reset(wd);
1381 * Delete the given item in a ctxpopup object.
1383 * @param item Ctxpopup item to be deleted
1388 elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item)
1390 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1394 wd = elm_widget_data_get(item->base.widget);
1399 evas_object_del(item->icon);
1400 if (item->base.view)
1401 evas_object_del(item->base.view);
1403 eina_stringshare_del(item->label);
1405 wd->items = eina_list_remove(wd->items, item);
1407 if (eina_list_count(wd->items) < 1)
1411 _sizing_eval(item->base.widget);
1417 * Set the ctxpopup item's state as disabled or enabled.
1419 * @param item Ctxpopup item to be enabled/disabled
1420 * @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable it
1425 elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, Eina_Bool disabled)
1427 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1431 wd = elm_widget_data_get(item->base.widget);
1435 if (disabled == item->disabled)
1439 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1441 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1443 item->disabled = !!disabled;
1447 * Get the ctxpopup item's disabled/enabled state.
1449 * @param item Ctxpopup item to be enabled/disabled
1450 * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
1455 elm_ctxpopup_item_disabled_get(const Elm_Ctxpopup_Item *item)
1457 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, EINA_FALSE);
1459 return item->disabled;
1463 * Once the content object is set, a previously set one will be deleted.
1464 * If you want to keep that old content object, use the
1465 * elm_ctxpopup_content_unset() function
1467 * Both a item list and a content could not be set at the same time!
1468 * once you set a content, the previous list items will be removed.
1470 * @param obj Ctxpopup object
1471 * @param content Content to be swallowed
1476 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1478 ELM_CHECK_WIDTYPE(obj, widtype);
1482 wd = elm_widget_data_get(obj);
1483 if ((!wd) || (!content))
1487 elm_ctxpopup_clear(obj);
1490 evas_object_del(wd->content);
1492 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1494 // evas_object_event_callback_add(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _content_changed_size_hints, obj);
1496 elm_widget_sub_object_add(obj, content);
1497 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1498 edje_object_message_signal_process(wd->base);
1500 wd->content = content;
1507 * Unset the ctxpopup content
1509 * Unparent and return the content object which was set for this widget
1511 * @param obj Ctxpopup object
1512 * @return The content that was being used
1517 elm_ctxpopup_content_unset(Evas_Object *obj)
1519 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1522 Evas_Object *content;
1524 wd = elm_widget_data_get(obj);
1528 content = wd->content;
1532 edje_object_part_unswallow(wd->base, content);
1533 elm_widget_sub_object_del(obj, content);
1534 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1535 evas_object_event_callback_del(content, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _content_changed_size_hints);
1536 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1544 * Set the direction priority of a ctxpopup.
1545 * This functions gives a chance to user to set the priority of ctxpopup showing direction.
1547 * @param obj Ctxpopup object
1548 * @param first 1st priority of direction
1549 * @param second 2nd priority of direction
1550 * @param third 3th priority of direction
1551 * @param fourth 4th priority of direction
1556 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1557 Elm_Ctxpopup_Direction first,
1558 Elm_Ctxpopup_Direction second,
1559 Elm_Ctxpopup_Direction third,
1560 Elm_Ctxpopup_Direction fourth)
1562 ELM_CHECK_WIDTYPE(obj, widtype);
1565 wd = elm_widget_data_get(obj);
1569 wd->dir_priority[0] = first;
1570 wd->dir_priority[1] = second;
1571 wd->dir_priority[2] = third;
1572 wd->dir_priority[3] = fourth;
1579 * Get the direction priority of a ctxpopup.
1581 * @param obj Ctxpopup object
1582 * @param first 1st priority of direction to be returned
1583 * @param second 2nd priority of direction to be returned
1584 * @param third 3th priority of direction to be returned
1585 * @param fourth 4th priority of direction to be returned
1587 * @see elm_ctxpopup_direction_priority_set for more information.
1592 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1593 Elm_Ctxpopup_Direction *first,
1594 Elm_Ctxpopup_Direction *second,
1595 Elm_Ctxpopup_Direction *third,
1596 Elm_Ctxpopup_Direction *fourth)
1598 ELM_CHECK_WIDTYPE(obj, widtype);
1601 wd = elm_widget_data_get(obj);
1606 *first = wd->dir_priority[0];
1608 *second = wd->dir_priority[1];
1610 *third = wd->dir_priority[2];
1612 *fourth = wd->dir_priority[3];
1616 elm_ctxpopup_screen_dimmed_disabled_set(Evas_Object *obj,
1623 elm_ctxpopup_button_append(Evas_Object *obj, const char *label,
1624 Evas_Smart_Cb func, const void *data)
1630 elm_ctxpopup_position_forced_set(Evas_Object *obj, Eina_Bool forced)
1636 elm_ctxpopup_position_forced_get(const Evas_Object *obj)
1641 EAPI Elm_Ctxpopup_Item *
1642 elm_ctxpopup_icon_add(Evas_Object *obj, Evas_Object *icon, Evas_Smart_Cb func,
1645 return elm_ctxpopup_item_append(obj, NULL, icon, func, data);
1648 EAPI Elm_Ctxpopup_Item *
1649 elm_ctxpopup_label_add(Evas_Object *obj, const char *label, Evas_Smart_Cb func,
1652 return elm_ctxpopup_item_append(obj, label, NULL, func, data);
1656 elm_ctxpopup_area_set(Evas_Object *obj, Evas_Object *area)
1658 elm_ctxpopup_hover_parent_set(obj, area);
1662 elm_ctxpopup_scroller_disabled_set(Evas_Object *obj, Eina_Bool disabled)
1664 ELM_CHECK_WIDTYPE(obj, widtype);
1668 wd = elm_widget_data_get(obj);
1673 elm_object_scroll_freeze_push(obj);
1675 elm_object_scroll_freeze_pop(obj);
1678 EAPI Elm_Ctxpopup_Item *
1679 elm_ctxpopup_item_add(Evas_Object *obj, Evas_Object *icon, const char *label,
1680 Evas_Smart_Cb func, void *data)
1682 return elm_ctxpopup_item_append(obj, label, icon, func, data);
1686 elm_ctxpopup_arrow_priority_set(Evas_Object *obj,
1687 Elm_Ctxpopup_Arrow first, Elm_Ctxpopup_Arrow second,
1688 Elm_Ctxpopup_Arrow third, Elm_Ctxpopup_Arrow fourth)
1690 elm_ctxpopup_direction_priority_set(obj, first, second, third, fourth);