1 #include <Elementary.h>
4 #undef Elm_Ctxpopup_Item
6 typedef struct _Widget_Data Widget_Data;
7 typedef struct _Elm_Ctxpopup_Item Elm_Ctxpopup_Item;
9 struct _Elm_Ctxpopup_Item
27 Evas_Object *hover_parent;
29 Elm_Ctxpopup_Direction dir;
30 Elm_Ctxpopup_Direction dir_priority[4];
31 Evas_Coord max_sc_w, max_sc_h;
32 Eina_Bool horizontal:1;
37 static const char *widtype = NULL;
39 static void _freeze_on(void *data __UNUSED__,
41 void *event_info __UNUSED__);
42 static void _freeze_off(void *data __UNUSED__, Evas_Object *obj,
43 void *event_info __UNUSED__);
44 static void _hold_on(void *data __UNUSED__, Evas_Object *obj,
45 void *event_info __UNUSED__);
46 static void _hold_off(void *data __UNUSED__, Evas_Object *obj,
47 void *event_info __UNUSED__);
48 static void _scroller_size_reset(Widget_Data *wd);
49 static void _hover_parent_callbacks_del(Evas_Object *obj);
50 static void _hover_parent_resize(void *data, Evas *e __UNUSED__,
51 Evas_Object *obj __UNUSED__,
52 void *event_info __UNUSED__);
53 static void _hover_parent_move(void *data, Evas *e __UNUSED__,
54 Evas_Object *obj __UNUSED__,
55 void *event_info __UNUSED__);
56 static void _hover_parent_del(void *data, Evas *e __UNUSED__,
57 Evas_Object *obj __UNUSED__,
58 void *event_info __UNUSED__);
59 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
60 static void _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
61 Evas_Coord_Rectangle *hover_area);
62 static void _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
63 Evas_Coord_Rectangle *hover_area);
64 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
65 Evas *e __UNUSED__, Evas_Object *obj,
66 void *event_info __UNUSED__);
67 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
68 Evas_Coord_Rectangle *rect);
69 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
70 static void _sizing_eval(Evas_Object *obj);
71 static void _shift_base_by_arrow(Evas_Object *arrow,
72 Elm_Ctxpopup_Direction dir,
73 Evas_Coord_Rectangle *rect);
74 static void _del_pre_hook(Evas_Object *obj);
75 static void _del_hook(Evas_Object *obj);
76 static void _theme_hook(Evas_Object *obj);
77 static void _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
78 const char *emission __UNUSED__,
79 const char *source __UNUSED__);
80 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
81 void *event_info __UNUSED__);
82 static void _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__,
83 Evas_Object *obj, void *event_info __UNUSED__);
84 static void _hide(Evas_Object *obj);
85 static void _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__,
86 Evas_Object *obj, void *event_info __UNUSED__);
87 static void _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
88 void *event_info __UNUSED__);
89 static void _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__,
90 Evas_Object *obj, void *event_info __UNUSED__);
91 static void _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
92 const char *emission __UNUSED__,
93 const char *source __UNUSED__);
94 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
95 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
96 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
97 static void _content_del(void *data, Evas *e, Evas_Object *obj __UNUSED__,
98 void *event_info __UNUSED__);
99 static void _list_del(Widget_Data *wd);
100 static void _list_new(Evas_Object *obj);
101 static void _remove_items(Widget_Data * wd);
103 static const char SIG_DISMISSED[] = "dismissed";
105 static const Evas_Smart_Cb_Description _signals[] = {
110 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
111 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
112 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
115 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
116 void *event_info __UNUSED__)
118 Widget_Data *wd = elm_widget_data_get(obj);
120 if ((!wd) || (!wd->scr)) return;
122 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
126 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
127 void *event_info __UNUSED__)
129 Widget_Data *wd = elm_widget_data_get(obj);
131 if ((!wd) || (!wd->scr)) return;
134 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
136 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
140 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
142 Widget_Data *wd = elm_widget_data_get(obj);
144 if ((!wd) || (!wd->scr)) return;
146 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
150 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
152 Widget_Data *wd = elm_widget_data_get(obj);
154 if ((!wd) || (!wd->scr)) return;
157 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
159 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
163 _scroller_size_reset(Widget_Data *wd)
165 wd->finished = EINA_FALSE;
171 _hover_parent_callbacks_del(Evas_Object *obj)
173 Widget_Data *wd = elm_widget_data_get(obj);
175 if ((!wd) || (!wd->hover_parent))
178 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
179 _hover_parent_del, obj);
180 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
181 _hover_parent_move, obj);
182 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
183 _hover_parent_resize, obj);
187 _hover_parent_resize(void *data, Evas *e __UNUSED__,
188 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
190 Widget_Data *wd = elm_widget_data_get(data);
196 _scroller_size_reset(wd);
202 _hover_parent_move(void *data, Evas *e __UNUSED__,
203 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
205 Widget_Data *wd = elm_widget_data_get(data);
211 _scroller_size_reset(wd);
217 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
218 void *event_info __UNUSED__)
220 Widget_Data *wd = elm_widget_data_get(data);
224 wd->hover_parent = NULL;
228 _item_sizing_eval(Elm_Ctxpopup_Item *item)
230 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
234 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
236 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
237 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
241 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
242 Evas_Coord_Rectangle *hover_area)
244 pos->x -= (base_size->x / 2);
246 if (pos->x < hover_area->x)
247 pos->x = hover_area->x;
248 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
249 pos->x = (hover_area->x + hover_area->w) - base_size->x;
251 if (base_size->x > hover_area->w)
252 base_size->x -= (base_size->x - hover_area->w);
254 if (pos->x < hover_area->x)
255 pos->x = hover_area->x;
259 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
260 Evas_Coord_Rectangle *hover_area)
262 pos->y -= (base_size->y / 2);
264 if (pos->y < hover_area->y)
265 pos->y = hover_area->y;
266 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
267 pos->y = hover_area->y + hover_area->h - base_size->y;
269 if (base_size->y > hover_area->h)
270 base_size->y -= (base_size->y - hover_area->h);
272 if (pos->y < hover_area->y)
273 pos->y = hover_area->y;
277 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
278 Evas_Object *obj, void *event_info __UNUSED__)
282 wd = elm_widget_data_get(obj);
289 static Elm_Ctxpopup_Direction
290 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
293 Evas_Coord_Point pos = {0, 0};
294 Evas_Coord_Point base_size;
295 Evas_Coord_Point max_size;
296 Evas_Coord_Point min_size;
297 Evas_Coord_Rectangle hover_area;
298 Evas_Coord_Rectangle parent_size;
299 Evas_Coord_Point arrow_size;
300 Elm_Ctxpopup_Direction arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
301 Evas_Coord_Point temp;
304 wd = elm_widget_data_get(obj);
306 if ((!wd) || (!rect))
307 return ELM_CTXPOPUP_DIRECTION_DOWN;
309 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
310 &arrow_size.x, &arrow_size.y);
311 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
313 //Initialize Area Rectangle.
314 if (wd->hover_parent)
315 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
316 &hover_area.w, &hover_area.h);
319 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
320 &parent_size.w, &parent_size.h);
321 hover_area.x = parent_size.x;
322 hover_area.y = parent_size.y;
323 hover_area.w = parent_size.w;
324 hover_area.h = parent_size.h;
327 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
330 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
331 evas_object_smart_calculate(wd->base);
334 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
336 if ((max_size.y > 0) && (base_size.y > max_size.y))
337 base_size.y = max_size.y;
339 if ((max_size.x > 0) && (base_size.x > max_size.x))
340 base_size.x = max_size.x;
343 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
345 if ((min_size.y > 0) && (base_size.y < min_size.y))
346 base_size.y = min_size.y;
348 if ((min_size.x > 0) && (base_size.x < min_size.x))
349 base_size.x = min_size.x;
351 //Check the Which direction is available.
352 //If find a avaialble direction, it adjusts position and size.
353 for (idx = 0; idx < 4; idx++)
355 switch (wd->dir_priority[idx])
357 case ELM_CTXPOPUP_DIRECTION_UP:
358 temp.y = (pos.y - base_size.y);
359 if ((temp.y - arrow_size.y) < hover_area.y)
361 _adjust_pos_x(&pos, &base_size, &hover_area);
362 pos.y -= base_size.y;
363 arrow = ELM_CTXPOPUP_DIRECTION_UP;
365 case ELM_CTXPOPUP_DIRECTION_LEFT:
366 temp.x = (pos.x - base_size.x);
367 if ((temp.x - arrow_size.x) < hover_area.x)
369 _adjust_pos_y(&pos, &base_size, &hover_area);
370 pos.x -= base_size.x;
371 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
373 case ELM_CTXPOPUP_DIRECTION_RIGHT:
374 temp.x = (pos.x + base_size.x);
375 if ((temp.x + arrow_size.x) >
376 (hover_area.x + hover_area.w))
378 _adjust_pos_y(&pos, &base_size, &hover_area);
379 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
381 case ELM_CTXPOPUP_DIRECTION_DOWN:
382 temp.y = (pos.y + base_size.y);
383 if ((temp.y + arrow_size.y) >
384 (hover_area.y + hover_area.h))
386 _adjust_pos_x(&pos, &base_size, &hover_area);
387 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
395 //In this case, all directions are invalid because of lack of space.
398 Evas_Coord length[2];
402 length[0] = pos.y - hover_area.y;
403 length[1] = (hover_area.y + hover_area.h) - pos.y;
405 // ELM_CTXPOPUP_DIRECTION_UP
406 if (length[0] > length[1])
408 _adjust_pos_x(&pos, &base_size, &hover_area);
409 pos.y -= base_size.y;
410 arrow = ELM_CTXPOPUP_DIRECTION_UP;
411 if (pos.y < (hover_area.y + arrow_size.y))
413 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
414 pos.y = hover_area.y + arrow_size.y;
417 //ELM_CTXPOPUP_DIRECTION_DOWN
420 _adjust_pos_x(&pos, &base_size, &hover_area);
421 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
422 if ((pos.y + arrow_size.y + base_size.y) >
423 (hover_area.y + hover_area.h))
425 ((pos.y + arrow_size.y + base_size.y) -
426 (hover_area.y + hover_area.h));
431 length[0] = pos.x - hover_area.x;
432 length[1] = (hover_area.x + hover_area.w) - pos.x;
434 //ELM_CTXPOPUP_DIRECTION_LEFT
435 if (length[0] > length[1])
437 _adjust_pos_y(&pos, &base_size, &hover_area);
438 pos.x -= base_size.x;
439 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
440 if (pos.x < (hover_area.x + arrow_size.x))
442 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
443 pos.x = hover_area.x + arrow_size.x;
446 //ELM_CTXPOPUP_DIRECTION_RIGHT
449 _adjust_pos_y(&pos, &base_size, &hover_area);
450 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
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));
460 //Final position and size.
463 rect->w = base_size.x;
464 rect->h = base_size.y;
470 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
473 Evas_Coord_Rectangle arrow_size;
474 Evas_Coord_Rectangle base_size;
477 wd = elm_widget_data_get(obj);
480 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
481 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
483 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
484 &base_size.w, &base_size.h);
486 // unswallow arrow from base
487 edje_object_part_unswallow(wd->base, wd->arrow);
491 case ELM_CTXPOPUP_DIRECTION_RIGHT:
492 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
494 // if user does not use dragable part
495 arrow_size.y = (y - (arrow_size.h * 0.5));
498 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
501 if (y < ((arrow_size.h * 0.5) + base_size.y))
503 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
504 y = base_size.h - arrow_size.h;
506 y = y - base_size.y - (arrow_size.h * 0.5);
507 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
508 (double) (y) / (double) (base_size.h - arrow_size.h));
511 case ELM_CTXPOPUP_DIRECTION_LEFT:
512 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
514 // if user does not use dragable part
515 arrow_size.y = (y - (arrow_size.h * 0.5));
516 arrow_size.x = (x - arrow_size.w);
518 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
521 if (y < (arrow_size.h * 0.5) + base_size.y)
523 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
524 y = base_size.h - arrow_size.h;
525 else y = y - base_size.y - (arrow_size.h * 0.5);
526 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
527 (double) (y) / (double) (base_size.h - arrow_size.h));
530 case ELM_CTXPOPUP_DIRECTION_DOWN:
531 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
533 // if user does not use dragable part
534 arrow_size.x = (x - (arrow_size.w * 0.5));
537 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
540 if (x < ((arrow_size.w * 0.5) + base_size.x))
542 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
543 x = base_size.w - arrow_size.w;
545 x = x - base_size.x - (arrow_size.w * 0.5);
546 edje_object_part_drag_value_set(wd->base,
547 "elm.swallow.arrow_up",
548 (double) (x) / (double) (base_size.w - arrow_size.w),
552 case ELM_CTXPOPUP_DIRECTION_UP:
553 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
555 // if user does not use dragable part
556 arrow_size.x = (x - (arrow_size.w * 0.5));
557 arrow_size.y = (y - arrow_size.h);
559 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
562 if (x < ((arrow_size.w * 0.5) + base_size.x))
564 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
565 x = base_size.w - arrow_size.w;
566 else x = x - base_size.x - (arrow_size.w * 0.5);
567 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
568 (double) (x) / (double) (base_size.w - arrow_size.w), 0);
575 // if user does not use dragable part
576 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
579 //TODO: compress item - different from opensource
581 _compress_item(Evas_Object *obj)
585 Elm_Ctxpopup_Item *item;
587 wd = elm_widget_data_get(obj);
590 EINA_LIST_FOREACH(wd->items, elist, item)
592 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
597 _sizing_eval(Evas_Object *obj)
601 Elm_Ctxpopup_Item *item;
602 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
603 Evas_Coord_Point box_size = { 0, 0 };
604 Evas_Coord_Point _box_size = { 0, 0 };
606 wd = elm_widget_data_get(obj);
607 if ((!wd) || (!wd->parent)) return;
610 EINA_LIST_FOREACH(wd->items, elist, item)
612 _item_sizing_eval(item);
613 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
616 if (_box_size.x > box_size.x)
617 box_size.x = _box_size.x;
618 if (_box_size.y != -1)
619 box_size.y += _box_size.y;
623 if (_box_size.x != -1)
624 box_size.x += _box_size.x;
625 if (_box_size.y > box_size.y)
626 box_size.y = _box_size.y;
632 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
633 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
637 wd->dir = _calc_base_geometry(obj, &rect);
639 //TODO: compress item - different from opensource
640 if (!wd->horizontal && !wd->content)
643 _update_arrow(obj, wd->dir);
644 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
646 //resize scroller according to final size.
648 evas_object_smart_calculate(wd->scr);
650 evas_object_move(wd->base, rect.x, rect.y);
651 evas_object_resize(wd->base, rect.w, rect.h);
655 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
656 Evas_Coord_Rectangle *rect)
658 Evas_Coord arrow_w, arrow_h;
660 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
664 case ELM_CTXPOPUP_DIRECTION_RIGHT:
667 case ELM_CTXPOPUP_DIRECTION_LEFT:
670 case ELM_CTXPOPUP_DIRECTION_DOWN:
673 case ELM_CTXPOPUP_DIRECTION_UP:
682 _del_pre_hook(Evas_Object *obj)
686 wd = elm_widget_data_get(obj);
689 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
690 _parent_resize, obj);
692 _hover_parent_callbacks_del(obj);
696 _del_hook(Evas_Object *obj)
700 wd = elm_widget_data_get(obj);
703 elm_ctxpopup_clear(obj);
704 evas_object_del(wd->arrow);
705 evas_object_del(wd->base);
710 _theme_hook(Evas_Object *obj)
714 Elm_Ctxpopup_Item *item;
717 wd = elm_widget_data_get(obj);
721 EINA_LIST_FOREACH(wd->items, elist, item)
723 if (item->label && item->icon)
724 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
725 "icon_text_style_item",
726 elm_widget_style_get(obj));
727 else if (item->label)
728 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
729 elm_widget_style_get(obj));
731 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
732 elm_widget_style_get(obj));
734 edje_object_part_text_set(item->base.view, "elm.text", item->label);
737 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
740 * For separator, if the first item has visible separator,
741 * then it should be aligned with edge of the base part.
742 * In some cases, it gives improper display. Ex) rounded corner
743 * So the first item separator should be invisible.
746 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
750 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
752 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
755 edje_object_message_signal_process(item->base.view);
758 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
759 elm_widget_style_get(obj));
760 if (evas_object_visible_get(wd->bg))
761 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
763 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
764 elm_widget_style_get(obj));
765 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
766 elm_widget_style_get(obj));
770 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
771 elm_object_style_set(wd->scr, "ctxpopup");
773 elm_object_style_set(wd->scr, elm_object_style_get(obj));
778 _scroller_size_reset(wd);
784 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
785 const char *emission __UNUSED__, const char *source __UNUSED__)
787 evas_object_hide(data);
791 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
792 void *event_info __UNUSED__)
797 wd = elm_widget_data_get(data);
800 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
801 evas_object_resize(wd->bg, w, h);
803 if (!wd->visible) return;
809 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
810 void *event_info __UNUSED__)
814 Elm_Ctxpopup_Item *item;
817 wd = elm_widget_data_get(obj);
820 if ((!wd->items) && (!wd->content)) return;
822 wd->visible = EINA_TRUE;
824 evas_object_show(wd->bg);
825 evas_object_show(wd->base);
826 evas_object_show(wd->arrow);
828 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
830 EINA_LIST_FOREACH(wd->items, elist, item)
833 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
837 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
839 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
847 _hide(Evas_Object *obj)
849 Widget_Data *wd = elm_widget_data_get(obj);
853 evas_object_hide(wd->bg);
854 evas_object_hide(wd->arrow);
855 evas_object_hide(wd->base);
857 _scroller_size_reset(wd);
859 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
860 wd->visible = EINA_FALSE;
864 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
865 void *event_info __UNUSED__)
869 wd = elm_widget_data_get(obj);
870 if ((!wd) || (!wd->visible))
877 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
878 void *event_info __UNUSED__)
883 wd = elm_widget_data_get(data);
885 if (!wd->visible) return;
886 if (wd->finished) return;
888 evas_object_geometry_get(obj, 0, 0, &w, &h);
890 if (w != 0 && h != 0)
892 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
895 wd->finished = EINA_TRUE;
900 if (wd->max_sc_w < w)
902 if (wd->max_sc_h < h)
909 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
910 void *event_info __UNUSED__)
914 wd = elm_widget_data_get(obj);
919 evas_object_show(wd->arrow);
921 _scroller_size_reset(wd);
926 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
927 const char *emission __UNUSED__, const char *source __UNUSED__)
929 Elm_Ctxpopup_Item *item = data;
932 if (item->disabled) return;
935 item->func((void*) item->base.data, item->base.widget, data);
939 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
943 elm_widget_sub_object_del(item->base.view, item->icon);
944 evas_object_del(item->icon);
950 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
951 edje_object_message_signal_process(item->base.view);
955 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
957 if (!eina_stringshare_replace(&item->label, label))
960 edje_object_part_text_set(item->base.view, "elm.text", label);
961 edje_object_message_signal_process(item->base.view);
965 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
969 wd = elm_widget_data_get(item->base.widget);
972 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
973 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
974 elm_widget_style_get(item->base.widget));
975 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
976 _item_select_cb, item);
977 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
978 evas_object_show(item->base.view);
982 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
983 void *event_info __UNUSED__)
985 elm_ctxpopup_content_unset(data);
989 _list_del(Widget_Data *wd)
991 if (!wd->scr) return;
993 edje_object_part_unswallow(wd->base, wd->scr);
994 evas_object_del(wd->scr);
1000 _list_new(Evas_Object *obj)
1003 wd = elm_widget_data_get(obj);
1007 wd->scr = elm_scroller_add(obj);
1008 elm_object_style_set(wd->scr, "ctxpopup");
1009 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1010 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1011 _scroller_resize, obj);
1012 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1015 wd->box = elm_box_add(obj);
1016 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1019 elm_scroller_content_set(wd->scr, wd->box);
1020 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1024 _remove_items(Widget_Data *wd)
1027 Elm_Ctxpopup_Item *item;
1029 if (!wd->items) return;
1031 EINA_LIST_FOREACH(wd->items, elist, item)
1034 eina_stringshare_del(item->label);
1036 evas_object_del(item->icon);
1037 wd->items = eina_list_remove(wd->items, item);
1045 elm_ctxpopup_add(Evas_Object *parent)
1050 Evas_Coord x, y, w, h;
1052 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1054 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1055 elm_widget_type_set(obj, "ctxpopup");
1056 elm_widget_sub_object_add(parent, obj);
1057 elm_widget_data_set(obj, wd);
1058 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1059 elm_widget_del_hook_set(obj, _del_hook);
1060 elm_widget_theme_hook_set(obj, _theme_hook);
1062 wd->parent = parent;
1065 wd->bg = edje_object_add(e);
1066 elm_widget_sub_object_add(obj, wd->bg);
1067 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1068 evas_object_geometry_get(parent, &x, &y, &w, &h);
1069 evas_object_move(wd->bg, x, y);
1070 evas_object_resize(wd->bg, w, h);
1071 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1072 _bg_clicked_cb, obj);
1075 wd->base = edje_object_add(e);
1076 elm_widget_sub_object_add(obj, wd->base);
1077 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1080 wd->arrow = edje_object_add(e);
1081 elm_widget_sub_object_add(obj, wd->arrow);
1082 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1084 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1085 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1086 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1087 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1089 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1091 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1093 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1095 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1097 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1098 _ctxpopup_changed_size_hints, NULL);
1099 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1100 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1101 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1102 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1104 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1110 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1112 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1113 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1118 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1120 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1123 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1125 wd = elm_widget_data_get(item->base.widget);
1128 _item_icon_set(item, icon);
1132 _scroller_size_reset(wd);
1133 _sizing_eval(item->base.widget);
1138 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1140 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1141 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1146 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1148 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1151 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1153 wd = elm_widget_data_get(item->base.widget);
1156 _item_label_set(item, label);
1160 _scroller_size_reset(wd);
1161 _sizing_eval(item->base.widget);
1166 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1168 ELM_CHECK_WIDTYPE(obj, widtype);
1172 wd = elm_widget_data_get(obj);
1175 _hover_parent_callbacks_del(obj);
1179 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1180 _hover_parent_del, obj);
1181 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1182 _hover_parent_move, obj);
1183 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1184 _hover_parent_resize, obj);
1187 wd->hover_parent = hover_parent;
1191 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1193 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1197 wd = elm_widget_data_get(obj);
1198 if (!wd) return NULL;
1200 return wd->hover_parent;
1204 elm_ctxpopup_clear(Evas_Object * obj)
1206 ELM_CHECK_WIDTYPE(obj, widtype);
1208 Widget_Data *wd = elm_widget_data_get(obj);
1216 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1218 ELM_CHECK_WIDTYPE(obj, widtype);
1222 Elm_Ctxpopup_Item *item;
1225 wd = elm_widget_data_get(obj);
1228 wd->horizontal = !!horizontal;
1230 if ((!wd->scr) && (!wd->box))
1235 elm_box_horizontal_set(wd->box, EINA_FALSE);
1236 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1238 EINA_LIST_FOREACH(wd->items, elist, item)
1241 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
1243 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
1248 elm_box_horizontal_set(wd->box, EINA_TRUE);
1249 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1251 EINA_LIST_FOREACH(wd->items, elist, item)
1254 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
1256 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
1265 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1267 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1271 wd = elm_widget_data_get(obj);
1272 if (!wd) return EINA_FALSE;
1274 return wd->horizontal;
1277 EAPI Elm_Object_Item *
1278 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1279 Evas_Object *icon, Evas_Smart_Cb func,
1282 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1285 Elm_Ctxpopup_Item *item;
1287 wd = elm_widget_data_get(obj);
1288 if (!wd) return NULL;
1290 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1291 if (!item) return NULL;
1293 //The first item is appended.
1295 evas_object_del(elm_ctxpopup_content_unset(obj));
1301 item->base.data = data;
1304 _item_new(item, "icon_text_style_item");
1306 _item_new(item, "text_style_item");
1308 _item_new(item, "icon_style_item");
1310 _item_icon_set(item, icon);
1311 _item_label_set(item, label);
1312 elm_box_pack_end(wd->box, item->base.view);
1313 wd->items = eina_list_append(wd->items, item);
1317 _scroller_size_reset(wd);
1321 return (Elm_Object_Item *) item;
1325 elm_ctxpopup_item_del(Elm_Object_Item *it)
1327 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1330 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1332 wd = elm_widget_data_get(item->base.widget);
1336 evas_object_del(item->icon);
1337 if (item->base.view)
1338 evas_object_del(item->base.view);
1340 eina_stringshare_del(item->label);
1342 wd->items = eina_list_remove(wd->items, item);
1344 if (eina_list_count(wd->items) < 1)
1348 _sizing_eval(item->base.widget);
1354 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1356 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1359 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1361 wd = elm_widget_data_get(item->base.widget);
1364 if (disabled == item->disabled)
1368 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1370 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1372 item->disabled = !!disabled;
1376 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1378 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1379 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1380 return item->disabled;
1384 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1386 ELM_CHECK_WIDTYPE(obj, widtype);
1390 wd = elm_widget_data_get(obj);
1391 if ((!wd) || (!content))
1395 elm_ctxpopup_clear(obj);
1398 evas_object_del(wd->content);
1400 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1403 elm_widget_sub_object_add(obj, content);
1404 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1405 edje_object_message_signal_process(wd->base);
1407 wd->content = content;
1414 elm_ctxpopup_content_unset(Evas_Object *obj)
1416 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1419 Evas_Object *content;
1421 wd = elm_widget_data_get(obj);
1422 if (!wd) return NULL;
1424 content = wd->content;
1425 if (!content) return NULL;
1427 edje_object_part_unswallow(wd->base, content);
1428 elm_widget_sub_object_del(obj, content);
1429 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1430 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1438 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1439 Elm_Ctxpopup_Direction first,
1440 Elm_Ctxpopup_Direction second,
1441 Elm_Ctxpopup_Direction third,
1442 Elm_Ctxpopup_Direction fourth)
1444 ELM_CHECK_WIDTYPE(obj, widtype);
1447 wd = elm_widget_data_get(obj);
1450 wd->dir_priority[0] = first;
1451 wd->dir_priority[1] = second;
1452 wd->dir_priority[2] = third;
1453 wd->dir_priority[3] = fourth;
1460 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1461 Elm_Ctxpopup_Direction *first,
1462 Elm_Ctxpopup_Direction *second,
1463 Elm_Ctxpopup_Direction *third,
1464 Elm_Ctxpopup_Direction *fourth)
1466 ELM_CHECK_WIDTYPE(obj, widtype);
1469 wd = elm_widget_data_get(obj);
1472 if (first) *first = wd->dir_priority[0];
1473 if (second) *second = wd->dir_priority[1];
1474 if (third) *third = wd->dir_priority[2];
1475 if (fourth) *fourth = wd->dir_priority[3];
1478 EAPI Elm_Ctxpopup_Direction
1479 elm_ctxpopup_direction_get(const Evas_Object *obj)
1481 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1484 wd = elm_widget_data_get(obj);
1485 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;