1 #include <Elementary.h>
7 * A ctxpopup is a widget that, when shown, pops up a list of items.
8 * It automatically chooses an area inside its parent object's view
9 * (set via elm_ctxpopup_add() and elm_ctxpopup_hover_parent_set()) to
10 * optimally fit into it. In the default theme, it will also point an
11 * arrow to the cursor position at the time one shows it. Ctxpopup
12 * items have a label and/or an icon. It is intended for a small
13 * number of items (hence the use of list, not genlist).
15 * Signals that you can add callbacks for are:
17 * "dismissed" - the ctxpopup was dismissed
20 typedef struct _Widget_Data Widget_Data;
22 struct _Elm_Ctxpopup_Item
40 Evas_Object *hover_parent;
42 Elm_Ctxpopup_Direction dir;
43 Elm_Ctxpopup_Direction dir_priority[4];
44 Evas_Coord max_sc_w, max_sc_h;
45 Eina_Bool horizontal:1;
50 static const char *widtype = NULL;
52 static void _del_hook(Evas_Object *obj);
53 static void _del_pre_hook(Evas_Object *obj);
54 static void _theme_hook(Evas_Object *obj);
55 static void _sizing_eval(Evas_Object *obj);
56 static void _hover_parent_resize(void *data, Evas *e __UNUSED__,
57 Evas_Object *obj __UNUSED__,
58 void *event_info __UNUSED__);
59 static void _hover_parent_move(void *data, Evas *e __UNUSED__,
60 Evas_Object *obj __UNUSED__,
61 void *event_info __UNUSED__);
62 static void _hover_parent_del(void *data, Evas *e __UNUSED__,
63 Evas_Object *obj __UNUSED__,
64 void *event_info __UNUSED__);
65 static void _hover_parent_callbacks_del(Evas_Object *obj);
66 static void _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
67 const char *emission __UNUSED__,
68 const char *source __UNUSED__);
69 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
70 void *event_info __UNUSED__);
71 static void _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__,
72 Evas_Object *obj, void *event_info __UNUSED__);
73 static void _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__,
74 Evas_Object *obj, void *event_info __UNUSED__);
75 static void _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__,
76 Evas_Object *obj, void *event_info __UNUSED__);
77 static void _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
78 void *event_info __UNUSED__);
79 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
80 Evas *e __UNUSED__, Evas_Object *obj,
81 void *event_info __UNUSED__);
82 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
83 static void _list_new(Evas_Object *obj);
84 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
85 static void _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
86 const char *emission __UNUSED__,
87 const char *source __UNUSED__);
88 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
89 Evas_Coord_Rectangle *rect);
90 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
91 static void _shift_base_by_arrow(Evas_Object *arrow,
92 Elm_Ctxpopup_Direction dir,
93 Evas_Coord_Rectangle *rect);
94 static void _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
95 Evas_Coord_Rectangle *hover_area);
96 static void _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
97 Evas_Coord_Rectangle *hover_area);
98 static void _scroller_size_reset(Widget_Data *wd);
99 static void _hide(Evas_Object *obj);
100 static void _content_del(void *data, Evas *e, Evas_Object *obj __UNUSED__,
101 void *event_info __UNUSED__);
102 static void _freeze_on(void *data __UNUSED__, Evas_Object *obj,
103 void *event_info __UNUSED__);
104 static void _freeze_off(void *data __UNUSED__, Evas_Object *obj,
105 void *event_info __UNUSED__);
106 static void _hold_on(void *data __UNUSED__, Evas_Object *obj,
107 void *event_info __UNUSED__);
108 static void _hold_off(void *data __UNUSED__, Evas_Object *obj,
109 void *event_info __UNUSED__);
110 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
111 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
112 static void _remove_items(Widget_Data * wd);
114 static const char SIG_DISMISSED[] = "dismissed";
116 static const Evas_Smart_Cb_Description _signals[] = {
121 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
122 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
123 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
126 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
127 void *event_info __UNUSED__)
129 Widget_Data *wd = elm_widget_data_get(obj);
132 if (!wd->scr) return;
134 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
138 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
139 void *event_info __UNUSED__)
141 Widget_Data *wd = elm_widget_data_get(obj);
145 if (!wd->scr) return;
148 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
150 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
154 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
156 Widget_Data *wd = elm_widget_data_get(obj);
161 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
165 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
167 Widget_Data *wd = elm_widget_data_get(obj);
173 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
175 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
179 _scroller_size_reset(Widget_Data *wd)
181 wd->finished = EINA_FALSE;
187 _hover_parent_callbacks_del(Evas_Object *obj)
189 Widget_Data *wd = elm_widget_data_get(obj);
191 if ((!wd) || (!wd->hover_parent))
194 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
195 _hover_parent_del, obj);
196 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
197 _hover_parent_move, obj);
198 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
199 _hover_parent_resize, obj);
203 _hover_parent_resize(void *data, Evas *e __UNUSED__,
204 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
206 Widget_Data *wd = elm_widget_data_get(data);
212 _scroller_size_reset(wd);
218 _hover_parent_move(void *data, Evas *e __UNUSED__,
219 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
221 Widget_Data *wd = elm_widget_data_get(data);
227 _scroller_size_reset(wd);
233 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
234 void *event_info __UNUSED__)
236 Widget_Data *wd = elm_widget_data_get(data);
240 wd->hover_parent = NULL;
244 _item_sizing_eval(Elm_Ctxpopup_Item *item)
246 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
250 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
252 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
253 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
257 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
258 Evas_Coord_Rectangle *hover_area)
260 pos->x -= (base_size->x / 2);
262 if (pos->x < hover_area->x)
263 pos->x = hover_area->x;
264 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
265 pos->x = (hover_area->x + hover_area->w) - base_size->x;
267 if (base_size->x > hover_area->w)
268 base_size->x -= (base_size->x - hover_area->w);
270 if (pos->x < hover_area->x)
271 pos->x = hover_area->x;
275 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
276 Evas_Coord_Rectangle *hover_area)
278 pos->y -= (base_size->y / 2);
280 if (pos->y < hover_area->y)
281 pos->y = hover_area->y;
282 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
283 pos->y = hover_area->y + hover_area->h - base_size->y;
285 if (base_size->y > hover_area->h)
286 base_size->y -= (base_size->y - hover_area->h);
288 if (pos->y < hover_area->y)
289 pos->y = hover_area->y;
293 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
294 Evas_Object *obj, void *event_info __UNUSED__)
298 wd = elm_widget_data_get(obj);
305 static Elm_Ctxpopup_Direction
306 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
309 Evas_Coord_Point pos = {0, 0};
310 Evas_Coord_Point base_size;
311 Evas_Coord_Point max_size;
312 Evas_Coord_Point min_size;
313 Evas_Coord_Rectangle hover_area;
314 Evas_Coord_Rectangle parent_size;
315 Evas_Coord_Point arrow_size;
316 Elm_Ctxpopup_Direction arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
317 Evas_Coord_Point temp;
320 wd = elm_widget_data_get(obj);
322 if ((!wd) || (!rect))
323 return ELM_CTXPOPUP_DIRECTION_DOWN;
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) < hover_area.y)
377 _adjust_pos_x(&pos, &base_size, &hover_area);
378 pos.y -= base_size.y;
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) < hover_area.x)
385 _adjust_pos_y(&pos, &base_size, &hover_area);
386 pos.x -= base_size.x;
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) >
392 (hover_area.x + hover_area.w))
394 _adjust_pos_y(&pos, &base_size, &hover_area);
395 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
397 case ELM_CTXPOPUP_DIRECTION_DOWN:
398 temp.y = (pos.y + base_size.y);
399 if ((temp.y + arrow_size.y) >
400 (hover_area.y + hover_area.h))
402 _adjust_pos_x(&pos, &base_size, &hover_area);
403 arrow = ELM_CTXPOPUP_DIRECTION_UP;
411 //In this case, all directions are invalid because of lack of space.
414 //TODO 1: Find the largest space direction.
415 Evas_Coord length[2];
417 length[0] = pos.y - hover_area.y;
418 length[1] = (hover_area.y + hover_area.h) - pos.y;
420 if (length[0] > length[1])
421 idx = ELM_CTXPOPUP_DIRECTION_UP;
423 idx = ELM_CTXPOPUP_DIRECTION_DOWN;
425 //TODO 2: determine x , y
428 case ELM_CTXPOPUP_DIRECTION_UP:
429 _adjust_pos_x(&pos, &base_size, &hover_area);
430 pos.y -= base_size.y;
431 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
432 if (pos.y < hover_area.y + arrow_size.y)
434 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
435 pos.y = hover_area.y + arrow_size.y;
438 case ELM_CTXPOPUP_DIRECTION_LEFT:
439 _adjust_pos_y(&pos, &base_size, &hover_area);
440 pos.x -= base_size.x;
441 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
442 if (pos.x < hover_area.x + arrow_size.x)
444 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
445 pos.x = hover_area.x + arrow_size.x;
448 case ELM_CTXPOPUP_DIRECTION_RIGHT:
449 _adjust_pos_y(&pos, &base_size, &hover_area);
450 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
451 if (pos.x + arrow_size.x + base_size.x >
452 hover_area.x + hover_area.w)
454 ((pos.x + arrow_size.x + base_size.x) -
455 (hover_area.x + hover_area.w));
457 case ELM_CTXPOPUP_DIRECTION_DOWN:
458 _adjust_pos_x(&pos, &base_size, &hover_area);
459 arrow = ELM_CTXPOPUP_DIRECTION_UP;
460 if (pos.y + arrow_size.y + base_size.y >
461 hover_area.y + hover_area.h)
463 ((pos.y + arrow_size.y + base_size.y) -
464 (hover_area.y + hover_area.h));
471 //Final position and size.
474 rect->w = base_size.x;
475 rect->h = base_size.y;
481 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
484 Evas_Coord_Rectangle arrow_size;
485 Evas_Coord_Rectangle base_size;
488 wd = elm_widget_data_get(obj);
491 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
492 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
494 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
495 &base_size.w, &base_size.h);
499 case ELM_CTXPOPUP_DIRECTION_LEFT:
500 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
502 // if user does not use dragable part
503 arrow_size.y = (y - (arrow_size.h * 0.5));
506 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
509 if (y < (arrow_size.h * 0.5) + base_size.y) y = 0;
510 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5)) y = base_size.h - arrow_size.h;
511 else y = y - base_size.y - (arrow_size.h * 0.5);
512 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
513 (double) (y) / (double) (base_size.h - arrow_size.h));
516 case ELM_CTXPOPUP_DIRECTION_RIGHT:
517 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
519 // if user does not use dragable part
520 arrow_size.y = (y - (arrow_size.h * 0.5));
521 arrow_size.x = (x - arrow_size.w);
523 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
526 if (y < (arrow_size.h * 0.5) + base_size.y) y = 0;
527 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5)) y = base_size.h - arrow_size.h;
528 else y = y - base_size.y - (arrow_size.h * 0.5);
529 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
530 (double) (y) / (double) (base_size.h - arrow_size.h));
533 case ELM_CTXPOPUP_DIRECTION_UP:
534 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
536 // if user does not use dragable part
537 arrow_size.x = (x - (arrow_size.w * 0.5));
540 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
543 if (x < (arrow_size.w * 0.5) + base_size.x) x = 0;
544 else if (x > base_size.x + base_size.w - (arrow_size.w * 0.5)) x = base_size.w - arrow_size.w;
545 else x = x - base_size.x - (arrow_size.w * 0.5);
546 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
547 (double) (x) / (double) (base_size.w - arrow_size.w), 1);
550 case ELM_CTXPOPUP_DIRECTION_DOWN:
551 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
553 // if user does not use dragable part
554 arrow_size.x = (x - (arrow_size.w * 0.5));
555 arrow_size.y = (y - arrow_size.h);
557 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
560 if (x < (arrow_size.w * 0.5) + base_size.x) x = 0;
561 else if (x > base_size.x + base_size.w - (arrow_size.w * 0.5)) x = base_size.w - arrow_size.w;
562 else x = x - base_size.x - (arrow_size.w * 0.5);
563 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
564 (double) (x) / (double) (base_size.w - arrow_size.w), 0);
571 // if user does not use dragable part
572 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
576 _sizing_eval(Evas_Object *obj)
580 Elm_Ctxpopup_Item *item;
581 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
582 Evas_Coord_Point box_size = { 0, 0 };
583 Evas_Coord_Point _box_size = { 0, 0 };
585 wd = elm_widget_data_get(obj);
586 if ((!wd) || (!wd->parent)) return;
589 EINA_LIST_FOREACH(wd->items, elist, item)
591 _item_sizing_eval(item);
592 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
595 if (_box_size.x > box_size.x)
596 box_size.x = _box_size.x;
597 if (_box_size.y != -1)
598 box_size.y += _box_size.y;
602 if (_box_size.x != -1)
603 box_size.x += _box_size.x;
604 if (_box_size.y > box_size.y)
605 box_size.y = _box_size.y;
611 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
612 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
616 wd->dir = _calc_base_geometry(obj, &rect);
617 _update_arrow(obj, wd->dir);
618 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
620 //resize scroller according to final size.
622 evas_object_smart_calculate(wd->scr);
624 evas_object_move(wd->base, rect.x, rect.y);
625 evas_object_resize(wd->base, rect.w, rect.h);
629 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
630 Evas_Coord_Rectangle *rect)
632 Evas_Coord arrow_w, arrow_h;
634 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
638 case ELM_CTXPOPUP_DIRECTION_LEFT:
641 case ELM_CTXPOPUP_DIRECTION_RIGHT:
644 case ELM_CTXPOPUP_DIRECTION_UP:
647 case ELM_CTXPOPUP_DIRECTION_DOWN:
656 _del_pre_hook(Evas_Object *obj)
660 wd = elm_widget_data_get(obj);
663 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
664 _parent_resize, obj);
666 _hover_parent_callbacks_del(obj);
670 _del_hook(Evas_Object *obj)
674 wd = elm_widget_data_get(obj);
677 elm_ctxpopup_clear(obj);
678 evas_object_del(wd->arrow);
679 evas_object_del(wd->base);
684 _theme_hook(Evas_Object *obj)
688 Elm_Ctxpopup_Item *item;
690 wd = elm_widget_data_get(obj);
694 EINA_LIST_FOREACH(wd->items, elist, item)
696 if (item->label && item->icon)
697 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
698 "icon_text_style_item",
699 elm_widget_style_get(obj));
700 else if (item->label)
701 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
702 elm_widget_style_get(obj));
704 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
705 elm_widget_style_get(obj));
707 edje_object_part_text_set(item->base.view, "elm.text", item->label);
710 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
712 edje_object_message_signal_process(item->base.view);
715 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
716 elm_widget_style_get(obj));
717 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
718 elm_widget_style_get(obj));
719 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
720 elm_widget_style_get(obj));
724 if (!strncmp(elm_object_style_get(obj), "default",
726 elm_object_style_set(wd->scr, "ctxpopup");
728 elm_object_style_set(wd->scr, elm_object_style_get(obj));
733 _scroller_size_reset(wd);
739 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
740 const char *emission __UNUSED__, const char *source __UNUSED__)
742 evas_object_hide(data);
746 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
747 void *event_info __UNUSED__)
752 wd = elm_widget_data_get(data);
755 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
756 evas_object_resize(wd->bg, w, h);
758 if (!wd->visible) return;
764 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
765 void *event_info __UNUSED__)
769 Elm_Ctxpopup_Item *item;
772 wd = elm_widget_data_get(obj);
775 if ((!wd->items) && (!wd->content)) return;
777 wd->visible = EINA_TRUE;
779 evas_object_show(wd->bg);
780 evas_object_show(wd->base);
781 evas_object_show(wd->arrow);
783 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
785 EINA_LIST_FOREACH(wd->items, elist, item)
788 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
792 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
794 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
802 _hide(Evas_Object *obj)
804 Widget_Data *wd = elm_widget_data_get(obj);
808 evas_object_hide(wd->bg);
809 evas_object_hide(wd->arrow);
810 evas_object_hide(wd->base);
812 _scroller_size_reset(wd);
814 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
815 wd->visible = EINA_FALSE;
819 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
820 void *event_info __UNUSED__)
824 wd = elm_widget_data_get(obj);
825 if ((!wd) || (!wd->visible))
832 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
833 void *event_info __UNUSED__)
838 wd = elm_widget_data_get(data);
840 if (!wd->visible) return;
841 if (wd->finished) return;
843 evas_object_geometry_get(obj, 0, 0, &w, &h);
845 if (w != 0 && h != 0)
847 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
850 wd->finished = EINA_TRUE;
855 if (wd->max_sc_w < w)
857 if (wd->max_sc_h < h)
864 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
865 void *event_info __UNUSED__)
869 wd = elm_widget_data_get(obj);
874 evas_object_show(wd->arrow);
876 _scroller_size_reset(wd);
881 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
882 const char *emission __UNUSED__, const char *source __UNUSED__)
884 Elm_Ctxpopup_Item *item = data;
887 if (item->disabled) return;
890 item->func((void*) item->base.data, item->base.widget, data);
894 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
898 elm_widget_sub_object_del(item->base.view, item->icon);
899 evas_object_del(item->icon);
905 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
906 edje_object_message_signal_process(item->base.view);
910 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
912 if (!eina_stringshare_replace(&item->label, label))
915 edje_object_part_text_set(item->base.view, "elm.text", label);
916 edje_object_message_signal_process(item->base.view);
920 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
924 wd = elm_widget_data_get(item->base.widget);
927 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
928 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
929 elm_widget_style_get(item->base.widget));
930 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
931 _item_select_cb, item);
932 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
933 evas_object_show(item->base.view);
937 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
938 void *event_info __UNUSED__)
940 elm_ctxpopup_content_unset(data);
944 _list_del(Widget_Data *wd)
946 if (!wd->scr) return;
948 edje_object_part_unswallow(wd->base, wd->scr);
949 evas_object_del(wd->scr);
955 _list_new(Evas_Object *obj)
958 wd = elm_widget_data_get(obj);
962 wd->scr = elm_scroller_add(obj);
963 elm_object_style_set(wd->scr, "ctxpopup");
964 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
965 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
966 _scroller_resize, obj);
967 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
970 wd->box = elm_box_add(obj);
971 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
974 elm_scroller_content_set(wd->scr, wd->box);
975 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
979 _remove_items(Widget_Data *wd)
982 Elm_Ctxpopup_Item *item;
984 if (!wd->items) return;
986 EINA_LIST_FOREACH(wd->items, elist, item)
989 eina_stringshare_del(item->label);
991 evas_object_del(item->icon);
992 wd->items = eina_list_remove(wd->items, item);
1000 * Add a new Ctxpopup object to the parent.
1002 * @param parent Parent object
1003 * @return New object or @c NULL, if it cannot be created
1008 elm_ctxpopup_add(Evas_Object *parent)
1013 Evas_Coord x, y, w, h;
1015 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1017 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1018 elm_widget_type_set(obj, "ctxpopup");
1019 elm_widget_sub_object_add(parent, obj);
1020 elm_widget_data_set(obj, wd);
1021 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1022 elm_widget_del_hook_set(obj, _del_hook);
1023 elm_widget_theme_hook_set(obj, _theme_hook);
1025 wd->parent = parent;
1028 wd->bg = edje_object_add(e);
1029 elm_widget_sub_object_add(obj, wd->bg);
1030 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1031 evas_object_geometry_get(parent, &x, &y, &w, &h);
1032 evas_object_move(wd->bg, x, y);
1033 evas_object_resize(wd->bg, w, h);
1034 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1035 _bg_clicked_cb, obj);
1038 wd->base = edje_object_add(e);
1039 elm_widget_sub_object_add(obj, wd->base);
1040 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1043 wd->arrow = edje_object_add(e);
1044 elm_widget_sub_object_add(obj, wd->arrow);
1045 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1047 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1048 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1049 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1050 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1052 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1054 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1056 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1058 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1060 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1061 _ctxpopup_changed_size_hints, NULL);
1062 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1063 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1064 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1065 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1067 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1073 * Get the icon object for the given ctxpopup item.
1075 * @param item Ctxpopup item
1076 * @return icon object or @c NULL, if the item does not have icon or an error occurred
1081 elm_ctxpopup_item_icon_get(const Elm_Ctxpopup_Item *item)
1083 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1088 * Sets the side icon associated with the ctxpopup item
1090 * Once the icon object is set, a previously set one will be deleted.
1091 * You probably don't want, then, to have the <b>same</b> icon object
1092 * set for more than one item of the list (when replacing one of its
1095 * @param item Ctxpopup item
1096 * @param icon Icon object to be set
1101 elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1103 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1107 wd = elm_widget_data_get(item->base.widget);
1110 _item_icon_set(item, icon);
1114 _scroller_size_reset(wd);
1115 _sizing_eval(item->base.widget);
1120 * Get the label object for the given ctxpopup item.
1122 * @param item Ctxpopup item
1123 * @return label object or @c NULL, if the item does not have label or an error occured
1129 elm_ctxpopup_item_label_get(const Elm_Ctxpopup_Item *item)
1131 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1136 * (Re)set the label on the given ctxpopup item.
1138 * @param item Ctxpopup item
1139 * @param label String to set as label
1144 elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1146 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1150 wd = elm_widget_data_get(item->base.widget);
1153 _item_label_set(item, label);
1157 _scroller_size_reset(wd);
1158 _sizing_eval(item->base.widget);
1163 * Set the Ctxpopup's parent
1164 * Set the parent object (it would much probably be the
1165 * window that the ctxpopup is in).
1167 * @param obj The ctxpopup object
1168 * @param area The parent to use
1170 * @note elm_ctxpopup_add() will automatically call this function
1171 * with its @c parent argument.
1176 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1178 ELM_CHECK_WIDTYPE(obj, widtype);
1182 wd = elm_widget_data_get(obj);
1185 _hover_parent_callbacks_del(obj);
1189 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1190 _hover_parent_del, obj);
1191 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1192 _hover_parent_move, obj);
1193 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1194 _hover_parent_resize, obj);
1197 wd->hover_parent = hover_parent;
1201 * Get the Ctxpopup's parent
1203 * @param obj The ctxpopup object
1205 * @see elm_ctxpopup_hover_parent_set() for more information
1210 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1212 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1216 wd = elm_widget_data_get(obj);
1217 if (!wd) return NULL;
1219 return wd->hover_parent;
1223 * Clear all items in the given ctxpopup object.
1225 * @param obj Ctxpopup object
1230 elm_ctxpopup_clear(Evas_Object * obj)
1232 ELM_CHECK_WIDTYPE(obj, widtype);
1234 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;
1259 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 EINA_LIST_FOREACH(wd->items, elist, item)
1275 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
1277 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
1282 elm_box_horizontal_set(wd->box, EINA_TRUE);
1283 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1285 EINA_LIST_FOREACH(wd->items, elist, item)
1288 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
1290 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
1299 * Get the value of current ctxpopup object's orientation.
1301 * @param obj Ctxpopup object
1302 * @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical mode (or errors)
1307 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1309 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1313 wd = elm_widget_data_get(obj);
1314 if (!wd) return EINA_FALSE;
1316 return wd->horizontal;
1320 * Add a new item to a ctxpopup object.
1322 * Both a item list and a content could not be set at the same time!
1323 * once you set add a item, the previous content will be removed.
1325 * @param obj Ctxpopup object
1326 * @param icon Icon to be set on new item
1327 * @param label The Label of the new item
1328 * @param func Convenience function called when item selected
1329 * @param data Data passed to @p func above
1330 * @return A handle to the item added or @c NULL, on errors
1334 EAPI Elm_Ctxpopup_Item *
1335 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1336 Evas_Object *icon, Evas_Smart_Cb func,
1339 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1342 Elm_Ctxpopup_Item *item;
1344 wd = elm_widget_data_get(obj);
1345 if (!wd) return NULL;
1347 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1348 if (!item) return NULL;
1350 //The first item is appended.
1352 evas_object_del(elm_ctxpopup_content_unset(obj));
1358 item->base.data = data;
1361 _item_new(item, "icon_text_style_item");
1363 _item_new(item, "text_style_item");
1365 _item_new(item, "icon_style_item");
1367 _item_icon_set(item, icon);
1368 _item_label_set(item, label);
1369 elm_box_pack_end(wd->box, item->base.view);
1370 wd->items = eina_list_append(wd->items, item);
1374 _scroller_size_reset(wd);
1382 * Delete the given item in a ctxpopup object.
1384 * @param item Ctxpopup item to be deleted
1389 elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item)
1391 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1395 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);
1434 if (disabled == item->disabled)
1438 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1440 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1442 item->disabled = !!disabled;
1446 * Get the ctxpopup item's disabled/enabled state.
1448 * @param item Ctxpopup item to be enabled/disabled
1449 * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
1454 elm_ctxpopup_item_disabled_get(const Elm_Ctxpopup_Item *item)
1456 ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, EINA_FALSE);
1458 return item->disabled;
1462 * Once the content object is set, a previously set one will be deleted.
1463 * If you want to keep that old content object, use the
1464 * elm_ctxpopup_content_unset() function
1466 * Both a item list and a content could not be set at the same time!
1467 * once you set a content, the previous list items will be removed.
1469 * @param obj Ctxpopup object
1470 * @param content Content to be swallowed
1475 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1477 ELM_CHECK_WIDTYPE(obj, widtype);
1481 wd = elm_widget_data_get(obj);
1482 if ((!wd) || (!content))
1486 elm_ctxpopup_clear(obj);
1489 evas_object_del(wd->content);
1491 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1494 elm_widget_sub_object_add(obj, content);
1495 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1496 edje_object_message_signal_process(wd->base);
1498 wd->content = content;
1505 * Unset the ctxpopup content
1507 * Unparent and return the content object which was set for this widget
1509 * @param obj Ctxpopup object
1510 * @return The content that was being used
1515 elm_ctxpopup_content_unset(Evas_Object *obj)
1517 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1520 Evas_Object *content;
1522 wd = elm_widget_data_get(obj);
1523 if (!wd) return NULL;
1525 content = wd->content;
1526 if (!content) return NULL;
1528 edje_object_part_unswallow(wd->base, content);
1529 elm_widget_sub_object_del(obj, content);
1530 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1531 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1539 * Set the direction priority of a ctxpopup.
1540 * This functions gives a chance to user to set the priority of ctxpopup showing direction.
1542 * @param obj Ctxpopup object
1543 * @param first 1st priority of direction
1544 * @param second 2nd priority of direction
1545 * @param third 3th priority of direction
1546 * @param fourth 4th priority of direction
1551 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1552 Elm_Ctxpopup_Direction first,
1553 Elm_Ctxpopup_Direction second,
1554 Elm_Ctxpopup_Direction third,
1555 Elm_Ctxpopup_Direction fourth)
1557 ELM_CHECK_WIDTYPE(obj, widtype);
1560 wd = elm_widget_data_get(obj);
1563 wd->dir_priority[0] = first;
1564 wd->dir_priority[1] = second;
1565 wd->dir_priority[2] = third;
1566 wd->dir_priority[3] = fourth;
1573 * Get the direction priority of a ctxpopup.
1575 * @param obj Ctxpopup object
1576 * @param first 1st priority of direction to be returned
1577 * @param second 2nd priority of direction to be returned
1578 * @param third 3th priority of direction to be returned
1579 * @param fourth 4th priority of direction to be returned
1581 * @see elm_ctxpopup_direction_priority_set for more information.
1586 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1587 Elm_Ctxpopup_Direction *first,
1588 Elm_Ctxpopup_Direction *second,
1589 Elm_Ctxpopup_Direction *third,
1590 Elm_Ctxpopup_Direction *fourth)
1592 ELM_CHECK_WIDTYPE(obj, widtype);
1595 wd = elm_widget_data_get(obj);
1599 *first = wd->dir_priority[0];
1601 *second = wd->dir_priority[1];
1603 *third = wd->dir_priority[2];
1605 *fourth = wd->dir_priority[3];