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, Evas_Object *obj, void *event_info);
40 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
41 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
42 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
43 static void _scroller_size_reset(Widget_Data *wd);
44 static void _hover_parent_callbacks_del(Evas_Object *obj);
45 static void _parent_resize(void *data,
49 static void _hover_parent_resize(void *data, Evas *e __UNUSED__,
50 Evas_Object *obj __UNUSED__,
51 void *event_info __UNUSED__);
52 static void _hover_parent_move(void *data, Evas *e __UNUSED__,
53 Evas_Object *obj __UNUSED__,
54 void *event_info __UNUSED__);
55 static void _hover_parent_del(void *data, Evas *e __UNUSED__,
56 Evas_Object *obj __UNUSED__,
57 void *event_info __UNUSED__);
58 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
59 static void _adjust_pos_x(Evas_Coord_Point *pos,
60 Evas_Coord_Point *base_size,
61 Evas_Coord_Rectangle *hover_area);
62 static void _adjust_pos_y(Evas_Coord_Point *pos,
63 Evas_Coord_Point *base_size,
64 Evas_Coord_Rectangle *hover_area);
65 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
66 Evas *e __UNUSED__, Evas_Object *obj,
67 void *event_info __UNUSED__);
68 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
69 Evas_Coord_Rectangle *rect);
70 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
71 static void _sizing_eval(Evas_Object *obj);
72 static void _shift_base_by_arrow(Evas_Object *arrow,
73 Elm_Ctxpopup_Direction dir,
74 Evas_Coord_Rectangle *rect);
75 static void _del_pre_hook(Evas_Object *obj);
76 static void _del_hook(Evas_Object *obj);
77 static void _theme_hook(Evas_Object *obj);
78 static void _content_set_hook(Evas_Object *obj,
79 const char *item __UNUSED__,
80 Evas_Object *content);
81 static Evas_Object * _content_unset_hook(Evas_Object *obj,
82 const char *item __UNUSED__);
83 static Evas_Object * _content_get_hook(const Evas_Object *obj,
84 const char *item __UNUSED__);
85 static void _bg_clicked_cb(void *data, Evas_Object *obj,
88 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
89 void *event_info __UNUSED__);
90 static void _ctxpopup_show(void *data,
94 static void _hide(Evas_Object *obj);
95 static void _ctxpopup_hide(void *data,
99 static void _scroller_resize(void *data,
103 static void _ctxpopup_move(void *data,
107 static void _item_select_cb(void *data, Evas_Object *obj,
108 const char *emission,
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 _item_new(Elm_Ctxpopup_Item *item, char *group_name);
113 static void _content_del(void *data,
117 static void _list_del(Widget_Data *wd);
118 static void _list_new(Evas_Object *obj);
119 static void _remove_items(Widget_Data * wd);
121 static const char SIG_DISMISSED[] = "dismissed";
123 static const Evas_Smart_Cb_Description _signals[] = {
128 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
129 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
130 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
133 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
134 void *event_info __UNUSED__)
136 Widget_Data *wd = elm_widget_data_get(obj);
138 if ((!wd) || (!wd->scr)) return;
140 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
144 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
145 void *event_info __UNUSED__)
147 Widget_Data *wd = elm_widget_data_get(obj);
149 if ((!wd) || (!wd->scr)) return;
152 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
154 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
158 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
160 Widget_Data *wd = elm_widget_data_get(obj);
162 if ((!wd) || (!wd->scr)) return;
164 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
168 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
170 Widget_Data *wd = elm_widget_data_get(obj);
172 if ((!wd) || (!wd->scr)) return;
175 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
177 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
181 _scroller_size_reset(Widget_Data *wd)
183 wd->finished = EINA_FALSE;
189 _hover_parent_callbacks_del(Evas_Object *obj)
191 Widget_Data *wd = elm_widget_data_get(obj);
193 if ((!wd) || (!wd->hover_parent))
196 evas_object_event_callback_del_full(wd->hover_parent,
200 evas_object_event_callback_del_full(wd->hover_parent,
204 evas_object_event_callback_del_full(wd->hover_parent,
205 EVAS_CALLBACK_RESIZE,
206 _hover_parent_resize,
211 _hover_parent_resize(void *data,
213 Evas_Object *obj __UNUSED__,
214 void *event_info __UNUSED__)
216 Widget_Data *wd = elm_widget_data_get(data);
222 _scroller_size_reset(wd);
228 _hover_parent_move(void *data,
230 Evas_Object *obj __UNUSED__,
231 void *event_info __UNUSED__)
233 Widget_Data *wd = elm_widget_data_get(data);
239 _scroller_size_reset(wd);
245 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
246 void *event_info __UNUSED__)
248 Widget_Data *wd = elm_widget_data_get(data);
252 wd->hover_parent = NULL;
256 _item_sizing_eval(Elm_Ctxpopup_Item *item)
258 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
262 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
264 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
265 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
269 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
270 Evas_Coord_Rectangle *hover_area)
272 pos->x -= (base_size->x / 2);
274 if (pos->x < hover_area->x)
275 pos->x = hover_area->x;
276 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
277 pos->x = (hover_area->x + hover_area->w) - base_size->x;
279 if (base_size->x > hover_area->w)
280 base_size->x -= (base_size->x - hover_area->w);
282 if (pos->x < hover_area->x)
283 pos->x = hover_area->x;
287 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
288 Evas_Coord_Rectangle *hover_area)
290 pos->y -= (base_size->y / 2);
292 if (pos->y < hover_area->y)
293 pos->y = hover_area->y;
294 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
295 pos->y = hover_area->y + hover_area->h - base_size->y;
297 if (base_size->y > hover_area->h)
298 base_size->y -= (base_size->y - hover_area->h);
300 if (pos->y < hover_area->y)
301 pos->y = hover_area->y;
305 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
306 Evas_Object *obj, void *event_info __UNUSED__)
310 wd = elm_widget_data_get(obj);
317 static Elm_Ctxpopup_Direction
318 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
321 Evas_Coord_Point pos = {0, 0};
322 Evas_Coord_Point base_size;
323 Evas_Coord_Point max_size;
324 Evas_Coord_Point min_size;
325 Evas_Coord_Rectangle hover_area;
326 Evas_Coord_Rectangle parent_size;
327 Evas_Coord_Point arrow_size;
328 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DOWN;
329 Evas_Coord_Point temp;
332 wd = elm_widget_data_get(obj);
334 if ((!wd) || (!rect))
335 return ELM_CTXPOPUP_DIRECTION_DOWN;
337 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
338 &arrow_size.x, &arrow_size.y);
339 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
341 //Initialize Area Rectangle.
342 if (wd->hover_parent)
343 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
344 &hover_area.w, &hover_area.h);
347 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
348 &parent_size.w, &parent_size.h);
349 hover_area.x = parent_size.x;
350 hover_area.y = parent_size.y;
351 hover_area.w = parent_size.w;
352 hover_area.h = parent_size.h;
355 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
358 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
359 evas_object_smart_calculate(wd->base);
362 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
364 if ((max_size.y > 0) && (base_size.y > max_size.y))
365 base_size.y = max_size.y;
367 if ((max_size.x > 0) && (base_size.x > max_size.x))
368 base_size.x = max_size.x;
371 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
373 if ((min_size.y > 0) && (base_size.y < min_size.y))
374 base_size.y = min_size.y;
376 if ((min_size.x > 0) && (base_size.x < min_size.x))
377 base_size.x = min_size.x;
379 //Check the Which direction is available.
380 //If find a avaialble direction, it adjusts position and size.
381 for (idx = 0; idx < 4; idx++)
383 switch (wd->dir_priority[idx])
385 case ELM_CTXPOPUP_DIRECTION_UP:
386 temp.y = (pos.y - base_size.y);
387 if ((temp.y - arrow_size.y) < hover_area.y)
389 _adjust_pos_x(&pos, &base_size, &hover_area);
390 pos.y -= base_size.y;
391 dir = ELM_CTXPOPUP_DIRECTION_UP;
393 case ELM_CTXPOPUP_DIRECTION_LEFT:
394 temp.x = (pos.x - base_size.x);
395 if ((temp.x - arrow_size.x) < hover_area.x)
397 _adjust_pos_y(&pos, &base_size, &hover_area);
398 pos.x -= base_size.x;
399 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
401 case ELM_CTXPOPUP_DIRECTION_RIGHT:
402 temp.x = (pos.x + base_size.x);
403 if ((temp.x + arrow_size.x) >
404 (hover_area.x + hover_area.w))
406 _adjust_pos_y(&pos, &base_size, &hover_area);
407 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
409 case ELM_CTXPOPUP_DIRECTION_DOWN:
410 temp.y = (pos.y + base_size.y);
411 if ((temp.y + arrow_size.y) >
412 (hover_area.y + hover_area.h))
414 _adjust_pos_x(&pos, &base_size, &hover_area);
415 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
423 //In this case, all directions are invalid because of lack of space.
426 Evas_Coord length[2];
430 length[0] = pos.y - hover_area.y;
431 length[1] = (hover_area.y + hover_area.h) - pos.y;
433 // ELM_CTXPOPUP_DIRECTION_UP
434 if (length[0] > length[1])
436 _adjust_pos_x(&pos, &base_size, &hover_area);
437 pos.y -= base_size.y;
438 dir = ELM_CTXPOPUP_DIRECTION_UP;
439 if (pos.y < (hover_area.y + arrow_size.y))
441 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
442 pos.y = hover_area.y + arrow_size.y;
445 //ELM_CTXPOPUP_DIRECTION_DOWN
448 _adjust_pos_x(&pos, &base_size, &hover_area);
449 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
450 if ((pos.y + arrow_size.y + base_size.y) >
451 (hover_area.y + hover_area.h))
453 ((pos.y + arrow_size.y + base_size.y) -
454 (hover_area.y + hover_area.h));
459 length[0] = pos.x - hover_area.x;
460 length[1] = (hover_area.x + hover_area.w) - pos.x;
462 //ELM_CTXPOPUP_DIRECTION_LEFT
463 if (length[0] > length[1])
465 _adjust_pos_y(&pos, &base_size, &hover_area);
466 pos.x -= base_size.x;
467 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
468 if (pos.x < (hover_area.x + arrow_size.x))
470 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
471 pos.x = hover_area.x + arrow_size.x;
474 //ELM_CTXPOPUP_DIRECTION_RIGHT
477 _adjust_pos_y(&pos, &base_size, &hover_area);
478 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
479 if (pos.x + (arrow_size.x + base_size.x) >
480 hover_area.x + hover_area.w)
482 ((pos.x + arrow_size.x + base_size.x) -
483 (hover_area.x + hover_area.w));
488 //Final position and size.
491 rect->w = base_size.x;
492 rect->h = base_size.y;
498 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
501 Evas_Coord_Rectangle arrow_size;
502 Evas_Coord_Rectangle base_size;
506 wd = elm_widget_data_get(obj);
509 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
510 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
512 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
513 &base_size.w, &base_size.h);
515 edje_object_part_unswallow(wd->base, wd->arrow);
519 case ELM_CTXPOPUP_DIRECTION_RIGHT:
520 edje_object_signal_emit(wd->arrow,
524 // if user does not use dragable part
525 arrow_size.y = (y - (arrow_size.h * 0.5));
528 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
531 if (y < ((arrow_size.h * 0.5) + base_size.y))
533 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
534 y = base_size.h - arrow_size.h;
536 y = y - base_size.y - (arrow_size.h * 0.5);
537 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
538 edje_object_part_drag_value_set(wd->base,
539 "elm.swallow.arrow_left",
544 case ELM_CTXPOPUP_DIRECTION_LEFT:
545 edje_object_signal_emit(wd->arrow,
549 // if user does not use dragable part
550 arrow_size.y = (y - (arrow_size.h * 0.5));
551 arrow_size.x = (x - arrow_size.w);
553 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
556 if (y < ((arrow_size.h * 0.5) + base_size.y))
558 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
559 y = base_size.h - arrow_size.h;
560 else y = y - base_size.y - (arrow_size.h * 0.5);
561 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
562 edje_object_part_drag_value_set(wd->base,
563 "elm.swallow.arrow_right",
568 case ELM_CTXPOPUP_DIRECTION_DOWN:
569 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
571 // if user does not use dragable part
572 arrow_size.x = (x - (arrow_size.w * 0.5));
575 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
578 if (x < ((arrow_size.w * 0.5) + base_size.x))
580 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
581 x = base_size.w - arrow_size.w;
583 x = x - base_size.x - (arrow_size.w * 0.5);
584 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
585 edje_object_part_drag_value_set(wd->base,
586 "elm.swallow.arrow_up",
591 case ELM_CTXPOPUP_DIRECTION_UP:
592 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
594 // if user does not use dragable part
595 arrow_size.x = (x - (arrow_size.w * 0.5));
596 arrow_size.y = (y - arrow_size.h);
598 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
601 if (x < ((arrow_size.w * 0.5) + base_size.x))
603 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
604 x = base_size.w - arrow_size.w;
605 else x = x - base_size.x - (arrow_size.w * 0.5);
606 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
607 edje_object_part_drag_value_set(wd->base,
608 "elm.swallow.arrow_down",
617 // if user does not use dragable part
618 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
621 //TODO: compress item - different from opensource
623 _compress_item(Evas_Object *obj)
627 Elm_Ctxpopup_Item *item;
629 wd = elm_widget_data_get(obj);
632 EINA_LIST_FOREACH(wd->items, elist, item)
634 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
639 _sizing_eval(Evas_Object *obj)
643 Elm_Ctxpopup_Item *item;
644 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
645 Evas_Coord_Point box_size = { 0, 0 };
646 Evas_Coord_Point _box_size = { 0, 0 };
648 wd = elm_widget_data_get(obj);
649 if ((!wd) || (!wd->parent)) return;
652 EINA_LIST_FOREACH(wd->items, elist, item)
654 _item_sizing_eval(item);
655 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
658 if (_box_size.x > box_size.x)
659 box_size.x = _box_size.x;
660 if (_box_size.y != -1)
661 box_size.y += _box_size.y;
665 if (_box_size.x != -1)
666 box_size.x += _box_size.x;
667 if (_box_size.y > box_size.y)
668 box_size.y = _box_size.y;
674 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
675 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
679 wd->dir = _calc_base_geometry(obj, &rect);
681 //TODO: compress item - different from opensource
682 if (!wd->horizontal && !wd->content)
685 _update_arrow(obj, wd->dir);
686 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
688 //resize scroller according to final size.
690 evas_object_smart_calculate(wd->scr);
692 evas_object_move(wd->base, rect.x, rect.y);
693 evas_object_resize(wd->base, rect.w, rect.h);
697 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
698 Evas_Coord_Rectangle *rect)
700 Evas_Coord arrow_w, arrow_h;
702 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
706 case ELM_CTXPOPUP_DIRECTION_RIGHT:
709 case ELM_CTXPOPUP_DIRECTION_LEFT:
712 case ELM_CTXPOPUP_DIRECTION_DOWN:
715 case ELM_CTXPOPUP_DIRECTION_UP:
724 _del_pre_hook(Evas_Object *obj)
728 wd = elm_widget_data_get(obj);
731 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
732 _parent_resize, obj);
734 _hover_parent_callbacks_del(obj);
738 _del_hook(Evas_Object *obj)
742 wd = elm_widget_data_get(obj);
745 elm_ctxpopup_clear(obj);
746 evas_object_del(wd->arrow);
747 evas_object_del(wd->base);
751 //FIXME: lost the content size when theme hook is called.
753 _theme_hook(Evas_Object *obj)
757 Elm_Ctxpopup_Item *item;
760 wd = elm_widget_data_get(obj);
764 EINA_LIST_FOREACH(wd->items, elist, item)
766 if (item->label && item->icon)
767 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
768 "icon_text_style_item",
769 elm_widget_style_get(obj));
770 else if (item->label)
771 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
772 elm_widget_style_get(obj));
774 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
775 elm_widget_style_get(obj));
777 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
780 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
783 * For separator, if the first item has visible separator,
784 * then it should be aligned with edge of the base part.
785 * In some cases, it gives improper display. Ex) rounded corner
786 * So the first item separator should be invisible.
789 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
793 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
795 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
798 edje_object_message_signal_process(VIEW(item));
801 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
802 elm_widget_style_get(obj));
803 if (evas_object_visible_get(wd->bg))
804 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
806 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
807 elm_widget_style_get(obj));
808 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
809 elm_widget_style_get(obj));
813 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
814 elm_object_style_set(wd->scr, "ctxpopup");
816 elm_object_style_set(wd->scr, elm_object_style_get(obj));
821 _scroller_size_reset(wd);
827 _content_set_hook(Evas_Object *obj, const char *item __UNUSED__,
828 Evas_Object *content)
830 ELM_CHECK_WIDTYPE(obj, widtype);
834 wd = elm_widget_data_get(obj);
835 if ((!wd) || (!content)) return;
837 if (wd->items) elm_ctxpopup_clear(obj);
838 if (wd->content) evas_object_del(wd->content);
840 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
843 elm_widget_sub_object_add(obj, content);
844 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
845 edje_object_message_signal_process(wd->base);
847 wd->content = content;
854 _content_unset_hook(Evas_Object *obj, const char *item __UNUSED__)
856 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
859 Evas_Object *content;
861 wd = elm_widget_data_get(obj);
862 if (!wd) return NULL;
864 content = wd->content;
865 if (!content) return NULL;
867 edje_object_part_unswallow(wd->base, content);
868 elm_widget_sub_object_del(obj, content);
869 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
870 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
879 _content_get_hook(const Evas_Object *obj, const char *item __UNUSED__)
881 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
883 Widget_Data *wd = elm_widget_data_get(obj);
884 if (!wd) return NULL;
889 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
890 const char *emission __UNUSED__, const char *source __UNUSED__)
892 evas_object_hide(data);
896 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
897 void *event_info __UNUSED__)
902 wd = elm_widget_data_get(data);
905 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
906 evas_object_resize(wd->bg, w, h);
908 if (!wd->visible) return;
914 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
915 void *event_info __UNUSED__)
919 Elm_Ctxpopup_Item *item;
922 wd = elm_widget_data_get(obj);
925 if ((!wd->items) && (!wd->content)) return;
927 wd->visible = EINA_TRUE;
929 evas_object_show(wd->bg);
930 evas_object_show(wd->base);
931 evas_object_show(wd->arrow);
933 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
935 EINA_LIST_FOREACH(wd->items, elist, item)
938 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
942 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
944 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
952 _hide(Evas_Object *obj)
954 Widget_Data *wd = elm_widget_data_get(obj);
958 evas_object_hide(wd->bg);
959 evas_object_hide(wd->arrow);
960 evas_object_hide(wd->base);
962 _scroller_size_reset(wd);
964 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
965 wd->visible = EINA_FALSE;
969 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
970 void *event_info __UNUSED__)
974 wd = elm_widget_data_get(obj);
975 if ((!wd) || (!wd->visible))
982 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
983 void *event_info __UNUSED__)
988 wd = elm_widget_data_get(data);
990 if (!wd->visible) return;
991 if (wd->finished) return;
993 evas_object_geometry_get(obj, 0, 0, &w, &h);
995 if (w != 0 && h != 0)
997 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1000 wd->finished = EINA_TRUE;
1005 if (wd->max_sc_w < w)
1007 if (wd->max_sc_h < h)
1014 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1015 void *event_info __UNUSED__)
1019 wd = elm_widget_data_get(obj);
1024 evas_object_show(wd->arrow);
1026 _scroller_size_reset(wd);
1031 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1032 const char *emission __UNUSED__, const char *source __UNUSED__)
1034 Elm_Ctxpopup_Item *item = data;
1037 if (item->disabled) return;
1040 item->func((void*) item->base.data, WIDGET(item), data);
1044 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1048 elm_widget_sub_object_del(VIEW(item), item->icon);
1049 evas_object_del(item->icon);
1055 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1056 edje_object_message_signal_process(VIEW(item));
1060 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1062 if (!eina_stringshare_replace(&item->label, label))
1065 edje_object_part_text_set(VIEW(item), "elm.text", label);
1066 edje_object_message_signal_process(VIEW(item));
1070 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1074 wd = elm_widget_data_get(WIDGET(item));
1077 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1078 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1079 elm_widget_style_get(WIDGET(item)));
1080 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1081 _item_select_cb, item);
1082 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1083 evas_object_show(VIEW(item));
1087 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1088 void *event_info __UNUSED__)
1090 elm_object_content_unset(data);
1094 _list_del(Widget_Data *wd)
1096 if (!wd->scr) return;
1098 edje_object_part_unswallow(wd->base, wd->scr);
1099 evas_object_del(wd->scr);
1105 _list_new(Evas_Object *obj)
1108 wd = elm_widget_data_get(obj);
1112 wd->scr = elm_scroller_add(obj);
1113 elm_object_style_set(wd->scr, "ctxpopup");
1114 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1115 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1116 _scroller_resize, obj);
1117 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1120 wd->box = elm_box_add(obj);
1121 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1124 elm_object_content_set(wd->scr, wd->box);
1125 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1129 _remove_items(Widget_Data *wd)
1132 Elm_Ctxpopup_Item *item;
1134 if (!wd->items) return;
1136 EINA_LIST_FOREACH(wd->items, elist, item)
1139 eina_stringshare_del(item->label);
1141 evas_object_del(item->icon);
1142 wd->items = eina_list_remove(wd->items, item);
1150 elm_ctxpopup_add(Evas_Object *parent)
1155 Evas_Coord x, y, w, h;
1157 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1159 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1160 elm_widget_type_set(obj, "ctxpopup");
1161 elm_widget_sub_object_add(parent, obj);
1162 elm_widget_data_set(obj, wd);
1163 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1164 elm_widget_del_hook_set(obj, _del_hook);
1165 elm_widget_theme_hook_set(obj, _theme_hook);
1166 elm_widget_content_set_hook_set(obj, _content_set_hook);
1167 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1168 elm_widget_content_get_hook_set(obj, _content_get_hook);
1170 wd->parent = parent;
1173 wd->bg = edje_object_add(e);
1174 elm_widget_sub_object_add(obj, wd->bg);
1175 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1176 evas_object_geometry_get(parent, &x, &y, &w, &h);
1177 evas_object_move(wd->bg, x, y);
1178 evas_object_resize(wd->bg, w, h);
1179 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1180 _bg_clicked_cb, obj);
1183 wd->base = edje_object_add(e);
1184 elm_widget_sub_object_add(obj, wd->base);
1185 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1188 wd->arrow = edje_object_add(e);
1189 elm_widget_sub_object_add(obj, wd->arrow);
1190 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1192 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1193 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1194 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1195 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1197 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1199 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1201 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1203 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1205 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1206 _ctxpopup_changed_size_hints, NULL);
1207 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1208 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1209 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1210 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1212 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1218 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1220 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1221 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1226 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1228 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1231 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1233 wd = elm_widget_data_get(WIDGET(item));
1236 _item_icon_set(item, icon);
1240 _scroller_size_reset(wd);
1241 _sizing_eval(WIDGET(item));
1246 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1248 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1249 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1254 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1256 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1259 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1261 wd = elm_widget_data_get(WIDGET(item));
1264 _item_label_set(item, label);
1268 _scroller_size_reset(wd);
1269 _sizing_eval(WIDGET(item));
1274 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1276 ELM_CHECK_WIDTYPE(obj, widtype);
1280 wd = elm_widget_data_get(obj);
1283 _hover_parent_callbacks_del(obj);
1287 evas_object_event_callback_add(hover_parent,
1291 evas_object_event_callback_add(hover_parent,
1295 evas_object_event_callback_add(hover_parent,
1296 EVAS_CALLBACK_RESIZE,
1297 _hover_parent_resize,
1301 wd->hover_parent = hover_parent;
1305 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1307 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1311 wd = elm_widget_data_get(obj);
1312 if (!wd) return NULL;
1314 return wd->hover_parent;
1318 elm_ctxpopup_clear(Evas_Object * obj)
1320 ELM_CHECK_WIDTYPE(obj, widtype);
1322 Widget_Data *wd = elm_widget_data_get(obj);
1330 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1332 ELM_CHECK_WIDTYPE(obj, widtype);
1336 Elm_Ctxpopup_Item *item;
1339 wd = elm_widget_data_get(obj);
1342 wd->horizontal = !!horizontal;
1344 if ((!wd->scr) && (!wd->box))
1349 elm_box_horizontal_set(wd->box, EINA_FALSE);
1350 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1352 EINA_LIST_FOREACH(wd->items, elist, item)
1355 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1357 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1362 elm_box_horizontal_set(wd->box, EINA_TRUE);
1363 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1365 EINA_LIST_FOREACH(wd->items, elist, item)
1368 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1370 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1379 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1381 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1385 wd = elm_widget_data_get(obj);
1386 if (!wd) return EINA_FALSE;
1388 return wd->horizontal;
1391 EAPI Elm_Object_Item *
1392 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1393 Evas_Object *icon, Evas_Smart_Cb func,
1396 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1399 Elm_Ctxpopup_Item *item;
1401 wd = elm_widget_data_get(obj);
1402 if (!wd) return NULL;
1404 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1405 if (!item) return NULL;
1407 //The first item is appended.
1409 evas_object_del(elm_object_content_unset(obj));
1415 item->base.data = data;
1418 _item_new(item, "icon_text_style_item");
1420 _item_new(item, "text_style_item");
1422 _item_new(item, "icon_style_item");
1424 _item_icon_set(item, icon);
1425 _item_label_set(item, label);
1426 elm_box_pack_end(wd->box, VIEW(item));
1427 wd->items = eina_list_append(wd->items, item);
1431 _scroller_size_reset(wd);
1435 return (Elm_Object_Item *) item;
1439 elm_ctxpopup_item_del(Elm_Object_Item *it)
1441 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1444 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1446 wd = elm_widget_data_get(WIDGET(item));
1450 evas_object_del(item->icon);
1452 evas_object_del(VIEW(item));
1454 eina_stringshare_del(item->label);
1456 wd->items = eina_list_remove(wd->items, item);
1458 if (eina_list_count(wd->items) < 1)
1462 _sizing_eval(WIDGET(item));
1468 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1470 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1473 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1475 wd = elm_widget_data_get(WIDGET(item));
1478 if (disabled == item->disabled)
1482 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
1484 edje_object_signal_emit(VIEW(item), "elm,state,enabled", "elm");
1486 item->disabled = !!disabled;
1490 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1492 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1493 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1494 return item->disabled;
1498 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1500 elm_object_content_set(obj, content);
1504 elm_ctxpopup_content_unset(Evas_Object *obj)
1506 return elm_object_content_unset(obj);
1510 elm_ctxpopup_direction_priority_set(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 wd->dir_priority[0] = first;
1523 wd->dir_priority[1] = second;
1524 wd->dir_priority[2] = third;
1525 wd->dir_priority[3] = fourth;
1532 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1533 Elm_Ctxpopup_Direction *first,
1534 Elm_Ctxpopup_Direction *second,
1535 Elm_Ctxpopup_Direction *third,
1536 Elm_Ctxpopup_Direction *fourth)
1538 ELM_CHECK_WIDTYPE(obj, widtype);
1541 wd = elm_widget_data_get(obj);
1544 if (first) *first = wd->dir_priority[0];
1545 if (second) *second = wd->dir_priority[1];
1546 if (third) *third = wd->dir_priority[2];
1547 if (fourth) *fourth = wd->dir_priority[3];
1550 EAPI Elm_Ctxpopup_Direction
1551 elm_ctxpopup_direction_get(const Evas_Object *obj)
1553 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1556 wd = elm_widget_data_get(obj);
1557 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;