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 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
53 void *event_info __UNUSED__);
54 static void _freeze_off(void *data __UNUSED__, Evas_Object *obj,
55 void *event_info __UNUSED__);
56 static void _hold_on(void *data __UNUSED__, Evas_Object *obj,
57 void *event_info __UNUSED__);
58 static void _hold_off(void *data __UNUSED__, Evas_Object *obj,
59 void *event_info __UNUSED__);
60 static void _scroller_size_reset(Widget_Data *wd);
61 static void _hover_parent_callbacks_del(Evas_Object *obj);
62 static void _hover_parent_resize(void *data, Evas *e __UNUSED__,
63 Evas_Object *obj __UNUSED__,
64 void *event_info __UNUSED__);
65 static void _hover_parent_move(void *data, Evas *e __UNUSED__,
66 Evas_Object *obj __UNUSED__,
67 void *event_info __UNUSED__);
68 static void _hover_parent_del(void *data, Evas *e __UNUSED__,
69 Evas_Object *obj __UNUSED__,
70 void *event_info __UNUSED__);
71 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
72 static void _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
73 Evas_Coord_Rectangle *hover_area);
74 static void _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
75 Evas_Coord_Rectangle *hover_area);
76 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
77 Evas *e __UNUSED__, Evas_Object *obj,
78 void *event_info __UNUSED__);
79 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
80 Evas_Coord_Rectangle *rect);
81 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
82 static void _sizing_eval(Evas_Object *obj);
83 static void _shift_base_by_arrow(Evas_Object *arrow,
84 Elm_Ctxpopup_Direction dir,
85 Evas_Coord_Rectangle *rect);
86 static void _del_pre_hook(Evas_Object *obj);
87 static void _del_hook(Evas_Object *obj);
88 static void _theme_hook(Evas_Object *obj);
89 static void _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
90 const char *emission __UNUSED__,
91 const char *source __UNUSED__);
92 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
93 void *event_info __UNUSED__);
94 static void _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__,
95 Evas_Object *obj, void *event_info __UNUSED__);
96 static void _hide(Evas_Object *obj);
97 static void _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__,
98 Evas_Object *obj, void *event_info __UNUSED__);
99 static void _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
100 void *event_info __UNUSED__);
101 static void _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__,
102 Evas_Object *obj, void *event_info __UNUSED__);
103 static void _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
104 const char *emission __UNUSED__,
105 const char *source __UNUSED__);
106 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
107 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
108 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
109 static void _content_del(void *data, Evas *e, Evas_Object *obj __UNUSED__,
110 void *event_info __UNUSED__);
111 static void _list_del(Widget_Data *wd);
112 static void _list_new(Evas_Object *obj);
113 static void _remove_items(Widget_Data * wd);
115 static const char SIG_DISMISSED[] = "dismissed";
117 static const Evas_Smart_Cb_Description _signals[] = {
122 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
123 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
124 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
127 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
128 void *event_info __UNUSED__)
130 Widget_Data *wd = elm_widget_data_get(obj);
132 if ((!wd) || (!wd->scr)) return;
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);
142 if ((!wd) || (!wd->scr)) return;
143 elm_object_scroll_freeze_pop(wd->scr);
147 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
149 Widget_Data *wd = elm_widget_data_get(obj);
151 if ((!wd) || (!wd->scr)) return;
152 elm_object_scroll_hold_push(wd->scr);
156 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
158 Widget_Data *wd = elm_widget_data_get(obj);
160 if ((!wd) || (!wd->scr)) return;
161 elm_object_scroll_hold_pop(wd->scr);
165 _scroller_size_reset(Widget_Data *wd)
167 wd->finished = EINA_FALSE;
173 _hover_parent_callbacks_del(Evas_Object *obj)
175 Widget_Data *wd = elm_widget_data_get(obj);
177 if ((!wd) || (!wd->hover_parent))
180 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
181 _hover_parent_del, obj);
182 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
183 _hover_parent_move, obj);
184 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
185 _hover_parent_resize, obj);
189 _hover_parent_resize(void *data, Evas *e __UNUSED__,
190 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
192 Widget_Data *wd = elm_widget_data_get(data);
198 _scroller_size_reset(wd);
204 _hover_parent_move(void *data, Evas *e __UNUSED__,
205 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
207 Widget_Data *wd = elm_widget_data_get(data);
213 _scroller_size_reset(wd);
219 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
220 void *event_info __UNUSED__)
222 Widget_Data *wd = elm_widget_data_get(data);
226 wd->hover_parent = NULL;
230 _item_sizing_eval(Elm_Ctxpopup_Item *item)
232 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
236 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
238 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
239 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
243 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
244 Evas_Coord_Rectangle *hover_area)
246 pos->x -= (base_size->x / 2);
248 if (pos->x < hover_area->x)
249 pos->x = hover_area->x;
250 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
251 pos->x = (hover_area->x + hover_area->w) - base_size->x;
253 if (base_size->x > hover_area->w)
254 base_size->x -= (base_size->x - hover_area->w);
256 if (pos->x < hover_area->x)
257 pos->x = hover_area->x;
261 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
262 Evas_Coord_Rectangle *hover_area)
264 pos->y -= (base_size->y / 2);
266 if (pos->y < hover_area->y)
267 pos->y = hover_area->y;
268 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
269 pos->y = hover_area->y + hover_area->h - base_size->y;
271 if (base_size->y > hover_area->h)
272 base_size->y -= (base_size->y - hover_area->h);
274 if (pos->y < hover_area->y)
275 pos->y = hover_area->y;
279 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
280 Evas_Object *obj, void *event_info __UNUSED__)
284 wd = elm_widget_data_get(obj);
291 static Elm_Ctxpopup_Direction
292 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
295 Evas_Coord_Point pos = {0, 0};
296 Evas_Coord_Point base_size;
297 Evas_Coord_Point max_size;
298 Evas_Coord_Point min_size;
299 Evas_Coord_Rectangle hover_area;
300 Evas_Coord_Rectangle parent_size;
301 Evas_Coord_Point arrow_size;
302 Elm_Ctxpopup_Direction arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
303 Evas_Coord_Point temp;
306 wd = elm_widget_data_get(obj);
308 if ((!wd) || (!rect))
309 return ELM_CTXPOPUP_DIRECTION_DOWN;
311 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
312 &arrow_size.x, &arrow_size.y);
313 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
315 //Initialize Area Rectangle.
316 if (wd->hover_parent)
317 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
318 &hover_area.w, &hover_area.h);
321 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
322 &parent_size.w, &parent_size.h);
323 hover_area.x = parent_size.x;
324 hover_area.y = parent_size.y;
325 hover_area.w = parent_size.w;
326 hover_area.h = parent_size.h;
329 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
332 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
333 evas_object_smart_calculate(wd->base);
336 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
338 if ((max_size.y > 0) && (base_size.y > max_size.y))
339 base_size.y = max_size.y;
341 if ((max_size.x > 0) && (base_size.x > max_size.x))
342 base_size.x = max_size.x;
345 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
347 if ((min_size.y > 0) && (base_size.y < min_size.y))
348 base_size.y = min_size.y;
350 if ((min_size.x > 0) && (base_size.x < min_size.x))
351 base_size.x = min_size.x;
353 //Check the Which direction is available.
354 //If find a avaialble direction, it adjusts position and size.
355 for (idx = 0; idx < 4; idx++)
357 switch (wd->dir_priority[idx])
359 case ELM_CTXPOPUP_DIRECTION_UP:
360 temp.y = (pos.y - base_size.y);
361 if ((temp.y - arrow_size.y) < hover_area.y)
363 _adjust_pos_x(&pos, &base_size, &hover_area);
364 pos.y -= base_size.y;
365 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
367 case ELM_CTXPOPUP_DIRECTION_LEFT:
368 temp.x = (pos.x - base_size.x);
369 if ((temp.x - arrow_size.x) < hover_area.x)
371 _adjust_pos_y(&pos, &base_size, &hover_area);
372 pos.x -= base_size.x;
373 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
375 case ELM_CTXPOPUP_DIRECTION_RIGHT:
376 temp.x = (pos.x + base_size.x);
377 if ((temp.x + arrow_size.x) >
378 (hover_area.x + hover_area.w))
380 _adjust_pos_y(&pos, &base_size, &hover_area);
381 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
383 case ELM_CTXPOPUP_DIRECTION_DOWN:
384 temp.y = (pos.y + base_size.y);
385 if ((temp.y + arrow_size.y) >
386 (hover_area.y + hover_area.h))
388 _adjust_pos_x(&pos, &base_size, &hover_area);
389 arrow = ELM_CTXPOPUP_DIRECTION_UP;
397 //In this case, all directions are invalid because of lack of space.
400 //TODO 1: Find the largest space direction.
401 Evas_Coord length[2];
403 length[0] = pos.y - hover_area.y;
404 length[1] = (hover_area.y + hover_area.h) - pos.y;
406 if (length[0] > length[1])
407 idx = ELM_CTXPOPUP_DIRECTION_UP;
409 idx = ELM_CTXPOPUP_DIRECTION_DOWN;
411 //TODO 2: determine x , y
414 case ELM_CTXPOPUP_DIRECTION_UP:
415 _adjust_pos_x(&pos, &base_size, &hover_area);
416 pos.y -= base_size.y;
417 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
418 if (pos.y < hover_area.y + arrow_size.y)
420 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
421 pos.y = hover_area.y + arrow_size.y;
424 case ELM_CTXPOPUP_DIRECTION_LEFT:
425 _adjust_pos_y(&pos, &base_size, &hover_area);
426 pos.x -= base_size.x;
427 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
428 if (pos.x < hover_area.x + arrow_size.x)
430 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
431 pos.x = hover_area.x + arrow_size.x;
434 case ELM_CTXPOPUP_DIRECTION_RIGHT:
435 _adjust_pos_y(&pos, &base_size, &hover_area);
436 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
437 if (pos.x + arrow_size.x + base_size.x >
438 hover_area.x + hover_area.w)
440 ((pos.x + arrow_size.x + base_size.x) -
441 (hover_area.x + hover_area.w));
443 case ELM_CTXPOPUP_DIRECTION_DOWN:
444 _adjust_pos_x(&pos, &base_size, &hover_area);
445 arrow = ELM_CTXPOPUP_DIRECTION_UP;
446 if (pos.y + arrow_size.y + base_size.y >
447 hover_area.y + hover_area.h)
449 ((pos.y + arrow_size.y + base_size.y) -
450 (hover_area.y + hover_area.h));
457 //Final position and size.
460 rect->w = base_size.x;
461 rect->h = base_size.y;
467 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
470 Evas_Coord_Rectangle arrow_size;
471 Evas_Coord_Rectangle base_size;
474 wd = elm_widget_data_get(obj);
477 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
478 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
480 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
481 &base_size.w, &base_size.h);
485 case ELM_CTXPOPUP_DIRECTION_LEFT:
486 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
487 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
490 if (y < (arrow_size.h * 0.5) + base_size.y) y = 0;
491 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5)) y = base_size.h - arrow_size.h;
492 else y = y - base_size.y - (arrow_size.h * 0.5);
493 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 0.5,
494 (double) (y) / (double) (base_size.h - arrow_size.h));
497 case ELM_CTXPOPUP_DIRECTION_RIGHT:
498 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
499 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
502 if (y < (arrow_size.h * 0.5) + base_size.y) y = 0;
503 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5)) y = base_size.h - arrow_size.h;
504 else y = y - base_size.y - (arrow_size.h * 0.5);
505 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0.5,
506 (double) (y) / (double) (base_size.h - arrow_size.h));
509 case ELM_CTXPOPUP_DIRECTION_UP:
510 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
511 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
514 if (x < (arrow_size.w * 0.5) + base_size.x) x = 0;
515 else if (x > base_size.x + base_size.w - (arrow_size.w * 0.5)) x = base_size.w - arrow_size.w;
516 else x = x - base_size.x - (arrow_size.w * 0.5);
517 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
518 (double) (x) / (double) (base_size.w - arrow_size.w), 0.5);
521 case ELM_CTXPOPUP_DIRECTION_DOWN:
522 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
523 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
526 if (x < (arrow_size.w * 0.5) + base_size.x) x = 0;
527 else if (x > base_size.x + base_size.w - (arrow_size.w * 0.5)) x = base_size.w - arrow_size.w;
528 else x = x - base_size.x - (arrow_size.w * 0.5);
529 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
530 (double) (x) / (double) (base_size.w - arrow_size.w), 0.5);
539 _sizing_eval(Evas_Object *obj)
543 Elm_Ctxpopup_Item *item;
544 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
545 Evas_Coord_Point box_size = { 0, 0 };
546 Evas_Coord_Point _box_size = { 0, 0 };
548 wd = elm_widget_data_get(obj);
549 if ((!wd) || (!wd->parent)) return;
552 EINA_LIST_FOREACH(wd->items, elist, item)
554 _item_sizing_eval(item);
555 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
558 if (_box_size.x > box_size.x)
559 box_size.x = _box_size.x;
560 if (_box_size.y != -1)
561 box_size.y += _box_size.y;
565 if (_box_size.x != -1)
566 box_size.x += _box_size.x;
567 if (_box_size.y > box_size.y)
568 box_size.y = _box_size.y;
574 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
575 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
579 wd->dir = _calc_base_geometry(obj, &rect);
580 _update_arrow(obj, wd->dir);
581 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
583 //resize scroller according to final size.
585 evas_object_smart_calculate(wd->scr);
587 evas_object_move(wd->base, rect.x, rect.y);
588 evas_object_resize(wd->base, rect.w, rect.h);
592 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
593 Evas_Coord_Rectangle *rect)
595 Evas_Coord arrow_w, arrow_h;
597 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
601 case ELM_CTXPOPUP_DIRECTION_LEFT:
604 case ELM_CTXPOPUP_DIRECTION_RIGHT:
607 case ELM_CTXPOPUP_DIRECTION_UP:
610 case ELM_CTXPOPUP_DIRECTION_DOWN:
619 _del_pre_hook(Evas_Object *obj)
623 wd = elm_widget_data_get(obj);
626 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
627 _parent_resize, obj);
629 _hover_parent_callbacks_del(obj);
633 _del_hook(Evas_Object *obj)
637 wd = elm_widget_data_get(obj);
640 elm_ctxpopup_clear(obj);
641 evas_object_del(wd->arrow);
642 evas_object_del(wd->base);
647 _theme_hook(Evas_Object *obj)
651 Elm_Ctxpopup_Item *item;
653 wd = elm_widget_data_get(obj);
657 EINA_LIST_FOREACH(wd->items, elist, item)
659 if (item->label && item->icon)
660 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
661 "icon_text_style_item",
662 elm_widget_style_get(obj));
663 else if (item->label)
664 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
665 elm_widget_style_get(obj));
667 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
668 elm_widget_style_get(obj));
670 edje_object_part_text_set(item->base.view, "elm.text", item->label);
673 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
675 edje_object_message_signal_process(item->base.view);
678 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
679 elm_widget_style_get(obj));
680 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
681 elm_widget_style_get(obj));
682 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
683 elm_widget_style_get(obj));
687 if (!strncmp(elm_object_style_get(obj), "default",
689 elm_object_style_set(wd->scr, "ctxpopup");
691 elm_object_style_set(wd->scr, elm_object_style_get(obj));
696 _scroller_size_reset(wd);
702 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
703 const char *emission __UNUSED__, const char *source __UNUSED__)
705 evas_object_hide(data);
709 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
710 void *event_info __UNUSED__)
715 wd = elm_widget_data_get(data);
718 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
719 evas_object_resize(wd->bg, w, h);
721 if (!wd->visible) return;
727 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
728 void *event_info __UNUSED__)
732 wd = elm_widget_data_get(obj);
735 if ((!wd->items) && (!wd->content)) return;
737 wd->visible = EINA_TRUE;
739 evas_object_show(wd->bg);
740 evas_object_show(wd->base);
741 evas_object_show(wd->arrow);
743 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
749 _hide(Evas_Object *obj)
751 Widget_Data *wd = elm_widget_data_get(obj);
755 evas_object_hide(wd->bg);
756 evas_object_hide(wd->arrow);
757 evas_object_hide(wd->base);
759 _scroller_size_reset(wd);
761 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
762 wd->visible = EINA_FALSE;
766 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
767 void *event_info __UNUSED__)
771 wd = elm_widget_data_get(obj);
772 if ((!wd) || (!wd->visible))
779 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
780 void *event_info __UNUSED__)
785 wd = elm_widget_data_get(data);
787 if (!wd->visible) return;
788 if (wd->finished) return;
790 evas_object_geometry_get(obj, 0, 0, &w, &h);
792 if (w != 0 && h != 0)
794 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
797 wd->finished = EINA_TRUE;
802 if (wd->max_sc_w < w)
804 if (wd->max_sc_h < h)
811 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
812 void *event_info __UNUSED__)
816 wd = elm_widget_data_get(obj);
821 evas_object_show(wd->arrow);
823 _scroller_size_reset(wd);
828 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
829 const char *emission __UNUSED__, const char *source __UNUSED__)
831 Elm_Ctxpopup_Item *item = data;
834 if (item->disabled) return;
837 item->func((void*) item->base.data, item->base.widget, data);
841 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
844 evas_object_del(item->icon);
849 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
850 edje_object_message_signal_process(item->base.view);
854 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
856 if (!eina_stringshare_replace(&item->label, label))
859 edje_object_part_text_set(item->base.view, "elm.text", label);
860 edje_object_message_signal_process(item->base.view);
864 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
868 wd = elm_widget_data_get(item->base.widget);
871 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
872 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
873 elm_widget_style_get(item->base.widget));
874 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
875 _item_select_cb, item);
876 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
877 evas_object_show(item->base.view);
881 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
882 void *event_info __UNUSED__)
884 elm_ctxpopup_content_unset(data);
888 _list_del(Widget_Data *wd)
890 if (!wd->scr) return;
892 edje_object_part_unswallow(wd->base, wd->scr);
893 evas_object_del(wd->scr);
899 _list_new(Evas_Object *obj)
902 wd = elm_widget_data_get(obj);
906 wd->scr = elm_scroller_add(obj);
907 elm_object_style_set(wd->scr, "ctxpopup");
908 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
909 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
910 _scroller_resize, obj);
911 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
914 wd->box = elm_box_add(obj);
915 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
918 elm_scroller_content_set(wd->scr, wd->box);
919 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
923 _remove_items(Widget_Data *wd)
926 Elm_Ctxpopup_Item *item;
928 if (!wd->items) return;
930 EINA_LIST_FOREACH(wd->items, elist, item)
933 eina_stringshare_del(item->label);
935 evas_object_del(item->icon);
936 wd->items = eina_list_remove(wd->items, item);
944 * Add a new Ctxpopup object to the parent.
946 * @param parent Parent object
947 * @return New object or @c NULL, if it cannot be created
952 elm_ctxpopup_add(Evas_Object *parent)
957 Evas_Coord x, y, w, h;
959 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
961 ELM_SET_WIDTYPE(widtype, "ctxpopup");
962 elm_widget_type_set(obj, "ctxpopup");
963 elm_widget_sub_object_add(parent, obj);
964 elm_widget_data_set(obj, wd);
965 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
966 elm_widget_del_hook_set(obj, _del_hook);
967 elm_widget_theme_hook_set(obj, _theme_hook);
972 wd->bg = edje_object_add(e);
973 elm_widget_sub_object_add(obj, wd->bg);
974 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
975 evas_object_geometry_get(parent, &x, &y, &w, &h);
976 evas_object_move(wd->bg, x, y);
977 evas_object_resize(wd->bg, w, h);
978 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
979 _bg_clicked_cb, obj);
982 wd->base = edje_object_add(e);
983 elm_widget_sub_object_add(obj, wd->base);
984 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
987 wd->arrow = edje_object_add(e);
988 elm_widget_sub_object_add(obj, wd->arrow);
989 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
991 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
992 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
993 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
994 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
996 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
998 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1000 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1002 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1004 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1005 _ctxpopup_changed_size_hints, NULL);
1006 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1007 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1008 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1009 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1011 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1017 * Get the icon object for the given ctxpopup item.
1019 * @param item Ctxpopup item
1020 * @return icon object or @c NULL, if the item does not have icon or an error occurred
1025 elm_ctxpopup_item_icon_get(const Elm_Ctxpopup_Item *item)
1027 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1032 * Sets the side icon associated with the ctxpopup item
1034 * Once the icon object is set, a previously set one will be deleted.
1035 * You probably don't want, then, to have the <b>same</b> icon object
1036 * set for more than one item of the list (when replacing one of its
1039 * @param item Ctxpopup item
1040 * @param icon Icon object to be set
1045 elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1047 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1051 wd = elm_widget_data_get(item->base.widget);
1054 _item_icon_set(item, icon);
1058 _scroller_size_reset(wd);
1059 _sizing_eval(item->base.widget);
1064 * Get the label object for the given ctxpopup item.
1066 * @param item Ctxpopup item
1067 * @return label object or @c NULL, if the item does not have label or an error occured
1073 elm_ctxpopup_item_label_get(const Elm_Ctxpopup_Item *item)
1075 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1080 * (Re)set the label on the given ctxpopup item.
1082 * @param item Ctxpopup item
1083 * @param label String to set as label
1088 elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1090 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1094 wd = elm_widget_data_get(item->base.widget);
1097 _item_label_set(item, label);
1101 _scroller_size_reset(wd);
1102 _sizing_eval(item->base.widget);
1107 * Set the Ctxpopup's parent
1108 * Set the parent object (it would much probably be the
1109 * window that the ctxpopup is in).
1111 * @param obj The ctxpopup object
1112 * @param area The parent to use
1114 * @note elm_ctxpopup_add() will automatically call this function
1115 * with its @c parent argument.
1120 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1122 ELM_CHECK_WIDTYPE(obj, widtype);
1126 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);
1161 if (!wd) return NULL;
1163 return wd->hover_parent;
1167 * Clear all items in the given ctxpopup object.
1169 * @param obj Ctxpopup object
1174 elm_ctxpopup_clear(Evas_Object * obj)
1176 ELM_CHECK_WIDTYPE(obj, widtype);
1178 Widget_Data *wd = elm_widget_data_get(obj);
1186 * Change the ctxpopup's orientation to horizontal or vertical.
1188 * @param obj Ctxpopup object
1189 * @param horizontal @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical
1194 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1196 ELM_CHECK_WIDTYPE(obj, widtype);
1200 wd = elm_widget_data_get(obj);
1203 wd->horizontal = !!horizontal;
1205 if ((!wd->scr) && (!wd->box))
1210 elm_box_horizontal_set(wd->box, EINA_FALSE);
1211 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1215 elm_box_horizontal_set(wd->box, EINA_TRUE);
1216 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1224 * Get the value of current ctxpopup object's orientation.
1226 * @param obj Ctxpopup object
1227 * @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical mode (or errors)
1232 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1234 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1238 wd = elm_widget_data_get(obj);
1239 if (!wd) return EINA_FALSE;
1241 return wd->horizontal;
1245 * Add a new item to a ctxpopup object.
1247 * Both a item list and a content could not be set at the same time!
1248 * once you set add a item, the previous content will be removed.
1250 * @param obj Ctxpopup object
1251 * @param icon Icon to be set on new item
1252 * @param label The Label of the new item
1253 * @param func Convenience function called when item selected
1254 * @param data Data passed to @p func above
1255 * @return A handle to the item added or @c NULL, on errors
1259 EAPI Elm_Ctxpopup_Item *
1260 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1261 Evas_Object *icon, Evas_Smart_Cb func,
1264 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1267 Elm_Ctxpopup_Item *item;
1269 wd = elm_widget_data_get(obj);
1270 if (!wd) return NULL;
1272 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1273 if (!item) return NULL;
1275 //The first item is appended.
1277 evas_object_del(elm_ctxpopup_content_unset(obj));
1283 item->base.data = data;
1286 _item_new(item, "icon_text_style_item");
1288 _item_new(item, "text_style_item");
1290 _item_new(item, "icon_style_item");
1292 _item_icon_set(item, icon);
1293 _item_label_set(item, label);
1294 elm_box_pack_end(wd->box, item->base.view);
1295 wd->items = eina_list_append(wd->items, item);
1299 _scroller_size_reset(wd);
1307 * Delete the given item in a ctxpopup object.
1309 * @param item Ctxpopup item to be deleted
1314 elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item)
1316 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1320 wd = elm_widget_data_get(item->base.widget);
1324 evas_object_del(item->icon);
1325 if (item->base.view)
1326 evas_object_del(item->base.view);
1328 eina_stringshare_del(item->label);
1330 wd->items = eina_list_remove(wd->items, item);
1332 if (eina_list_count(wd->items) < 1)
1336 _sizing_eval(item->base.widget);
1342 * Set the ctxpopup item's state as disabled or enabled.
1344 * @param item Ctxpopup item to be enabled/disabled
1345 * @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable it
1350 elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, Eina_Bool disabled)
1352 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1356 wd = elm_widget_data_get(item->base.widget);
1359 if (disabled == item->disabled)
1363 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1365 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1367 item->disabled = !!disabled;
1371 * Get the ctxpopup item's disabled/enabled state.
1373 * @param item Ctxpopup item to be enabled/disabled
1374 * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
1379 elm_ctxpopup_item_disabled_get(const Elm_Ctxpopup_Item *item)
1381 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, EINA_FALSE);
1382 return item->disabled;
1386 * Once the content object is set, a previously set one will be deleted.
1387 * If you want to keep that old content object, use the
1388 * elm_ctxpopup_content_unset() function
1390 * Both a item list and a content could not be set at the same time!
1391 * once you set a content, the previous list items will be removed.
1393 * @param obj Ctxpopup object
1394 * @param content Content to be swallowed
1399 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1401 ELM_CHECK_WIDTYPE(obj, widtype);
1405 wd = elm_widget_data_get(obj);
1406 if ((!wd) || (!content))
1410 elm_ctxpopup_clear(obj);
1413 evas_object_del(wd->content);
1415 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1418 elm_widget_sub_object_add(obj, content);
1419 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1420 edje_object_message_signal_process(wd->base);
1422 wd->content = content;
1429 * Unset the ctxpopup content
1431 * Unparent and return the content object which was set for this widget
1433 * @param obj Ctxpopup object
1434 * @return The content that was being used
1439 elm_ctxpopup_content_unset(Evas_Object *obj)
1441 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1444 Evas_Object *content;
1446 wd = elm_widget_data_get(obj);
1447 if (!wd) return NULL;
1449 content = wd->content;
1450 if (!content) return NULL;
1452 edje_object_part_unswallow(wd->base, content);
1453 elm_widget_sub_object_del(obj, content);
1454 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1455 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1463 * Set the direction priority of a ctxpopup.
1464 * This functions gives a chance to user to set the priority of ctxpopup showing direction.
1466 * @param obj Ctxpopup object
1467 * @param first 1st priority of direction
1468 * @param second 2nd priority of direction
1469 * @param third 3th priority of direction
1470 * @param fourth 4th priority of direction
1475 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1476 Elm_Ctxpopup_Direction first,
1477 Elm_Ctxpopup_Direction second,
1478 Elm_Ctxpopup_Direction third,
1479 Elm_Ctxpopup_Direction fourth)
1481 ELM_CHECK_WIDTYPE(obj, widtype);
1484 wd = elm_widget_data_get(obj);
1487 wd->dir_priority[0] = first;
1488 wd->dir_priority[1] = second;
1489 wd->dir_priority[2] = third;
1490 wd->dir_priority[3] = fourth;
1497 * Get the direction priority of a ctxpopup.
1499 * @param obj Ctxpopup object
1500 * @param first 1st priority of direction to be returned
1501 * @param second 2nd priority of direction to be returned
1502 * @param third 3th priority of direction to be returned
1503 * @param fourth 4th priority of direction to be returned
1505 * @see elm_ctxpopup_direction_priority_set for more information.
1510 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1511 Elm_Ctxpopup_Direction *first,
1512 Elm_Ctxpopup_Direction *second,
1513 Elm_Ctxpopup_Direction *third,
1514 Elm_Ctxpopup_Direction *fourth)
1516 ELM_CHECK_WIDTYPE(obj, widtype);
1519 wd = elm_widget_data_get(obj);
1522 if (first) *first = wd->dir_priority[0];
1523 if (second) *second = wd->dir_priority[1];
1524 if (third) *third = wd->dir_priority[2];
1525 if (fourth) *fourth = wd->dir_priority[3];