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, "elm,state,left", "elm");
521 edje_object_part_swallow(wd->base,
522 "elm.swallow.arrow_left",
525 // if user does not use dragable part
526 arrow_size.y = (y - (arrow_size.h * 0.5));
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, "elm,state,right", "elm");
546 edje_object_part_swallow(wd->base,
547 "elm.swallow.arrow_right",
550 // if user does not use dragable part
551 arrow_size.y = (y - (arrow_size.h * 0.5));
552 arrow_size.x = (x - arrow_size.w);
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;
561 y = y - base_size.y - (arrow_size.h * 0.5);
562 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
563 edje_object_part_drag_value_set(wd->base,
564 "elm.swallow.arrow_right",
569 case ELM_CTXPOPUP_DIRECTION_DOWN:
570 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
571 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
573 // if user does not use dragable part
574 arrow_size.x = (x - (arrow_size.w * 0.5));
579 if (x < ((arrow_size.w * 0.5) + base_size.x))
581 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
582 x = base_size.w - arrow_size.w;
584 x = x - base_size.x - (arrow_size.w * 0.5);
585 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
586 edje_object_part_drag_value_set(wd->base,
587 "elm.swallow.arrow_up",
592 case ELM_CTXPOPUP_DIRECTION_UP:
593 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
594 edje_object_part_swallow(wd->base,
595 "elm.swallow.arrow_down",
598 // if user does not use dragable part
599 arrow_size.x = (x - (arrow_size.w * 0.5));
600 arrow_size.y = (y - arrow_size.h);
604 if (x < ((arrow_size.w * 0.5) + base_size.x))
606 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
607 x = base_size.w - arrow_size.w;
608 else x = x - base_size.x - (arrow_size.w * 0.5);
609 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
610 edje_object_part_drag_value_set(wd->base,
611 "elm.swallow.arrow_down",
620 // if user does not use dragable part
621 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
624 //TODO: compress item - different from opensource
626 _compress_item(Evas_Object *obj)
630 Elm_Ctxpopup_Item *item;
632 wd = elm_widget_data_get(obj);
635 EINA_LIST_FOREACH(wd->items, elist, item)
637 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
642 _sizing_eval(Evas_Object *obj)
646 Elm_Ctxpopup_Item *item;
647 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
648 Evas_Coord_Point box_size = { 0, 0 };
649 Evas_Coord_Point _box_size = { 0, 0 };
651 wd = elm_widget_data_get(obj);
653 if (!wd->parent) return;
656 EINA_LIST_FOREACH(wd->items, elist, item)
658 _item_sizing_eval(item);
659 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
662 if (_box_size.x > box_size.x)
663 box_size.x = _box_size.x;
664 if (_box_size.y != -1)
665 box_size.y += _box_size.y;
669 if (_box_size.x != -1)
670 box_size.x += _box_size.x;
671 if (_box_size.y > box_size.y)
672 box_size.y = _box_size.y;
678 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
679 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
683 wd->dir = _calc_base_geometry(obj, &rect);
685 //TODO: compress item - different from opensource
686 if (!wd->horizontal && !wd->content)
689 _update_arrow(obj, wd->dir);
690 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
692 //resize scroller according to final size.
694 evas_object_smart_calculate(wd->scr);
696 evas_object_move(wd->base, rect.x, rect.y);
697 evas_object_resize(wd->base, rect.w, rect.h);
701 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
702 Evas_Coord_Rectangle *rect)
704 Evas_Coord arrow_w, arrow_h;
706 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
710 case ELM_CTXPOPUP_DIRECTION_RIGHT:
713 case ELM_CTXPOPUP_DIRECTION_LEFT:
716 case ELM_CTXPOPUP_DIRECTION_DOWN:
719 case ELM_CTXPOPUP_DIRECTION_UP:
728 _del_pre_hook(Evas_Object *obj)
732 wd = elm_widget_data_get(obj);
735 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
736 _parent_resize, obj);
738 _hover_parent_callbacks_del(obj);
742 _del_hook(Evas_Object *obj)
746 wd = elm_widget_data_get(obj);
749 elm_ctxpopup_clear(obj);
750 evas_object_del(wd->arrow);
751 evas_object_del(wd->base);
755 //FIXME: lost the content size when theme hook is called.
757 _theme_hook(Evas_Object *obj)
761 Elm_Ctxpopup_Item *item;
764 wd = elm_widget_data_get(obj);
768 EINA_LIST_FOREACH(wd->items, elist, item)
770 if (item->label && item->icon)
771 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
772 "icon_text_style_item",
773 elm_widget_style_get(obj));
774 else if (item->label)
775 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
776 elm_widget_style_get(obj));
778 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
779 elm_widget_style_get(obj));
781 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
784 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
787 * For separator, if the first item has visible separator,
788 * then it should be aligned with edge of the base part.
789 * In some cases, it gives improper display. Ex) rounded corner
790 * So the first item separator should be invisible.
793 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
797 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
799 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
802 edje_object_message_signal_process(VIEW(item));
805 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
806 elm_widget_style_get(obj));
807 if (evas_object_visible_get(wd->bg))
808 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
810 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
811 elm_widget_style_get(obj));
812 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
813 elm_widget_style_get(obj));
817 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
818 elm_object_style_set(wd->scr, "ctxpopup");
820 elm_object_style_set(wd->scr, elm_object_style_get(obj));
825 _scroller_size_reset(wd);
831 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__,
832 Evas_Object *content)
834 ELM_CHECK_WIDTYPE(obj, widtype);
838 wd = elm_widget_data_get(obj);
839 if ((!wd) || (!content)) return;
841 if (wd->items) elm_ctxpopup_clear(obj);
842 if (wd->content) evas_object_del(wd->content);
844 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
847 elm_widget_sub_object_add(obj, content);
848 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
849 edje_object_message_signal_process(wd->base);
851 wd->content = content;
858 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
860 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
863 Evas_Object *content;
865 wd = elm_widget_data_get(obj);
866 if (!wd) return NULL;
868 content = wd->content;
869 if (!content) return NULL;
871 edje_object_part_unswallow(wd->base, content);
872 elm_widget_sub_object_del(obj, content);
873 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
874 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
883 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
885 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
887 Widget_Data *wd = elm_widget_data_get(obj);
888 if (!wd) return NULL;
893 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
894 const char *emission __UNUSED__, const char *source __UNUSED__)
896 evas_object_hide(data);
900 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
901 void *event_info __UNUSED__)
906 wd = elm_widget_data_get(data);
909 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
910 evas_object_resize(wd->bg, w, h);
912 if (!wd->visible) return;
918 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
919 void *event_info __UNUSED__)
923 Elm_Ctxpopup_Item *item;
926 wd = elm_widget_data_get(obj);
929 if ((!wd->items) && (!wd->content)) return;
931 wd->visible = EINA_TRUE;
933 evas_object_show(wd->bg);
934 evas_object_show(wd->base);
935 evas_object_show(wd->arrow);
937 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
939 EINA_LIST_FOREACH(wd->items, elist, item)
942 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
946 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
948 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
956 _hide(Evas_Object *obj)
958 Widget_Data *wd = elm_widget_data_get(obj);
962 evas_object_hide(wd->bg);
963 evas_object_hide(wd->arrow);
964 evas_object_hide(wd->base);
966 _scroller_size_reset(wd);
968 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
969 wd->visible = EINA_FALSE;
973 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
974 void *event_info __UNUSED__)
978 wd = elm_widget_data_get(obj);
979 if ((!wd) || (!wd->visible))
986 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
987 void *event_info __UNUSED__)
992 wd = elm_widget_data_get(data);
994 if (!wd->visible) return;
995 if (wd->finished) return;
997 evas_object_geometry_get(obj, 0, 0, &w, &h);
999 if (w != 0 && h != 0)
1001 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1004 wd->finished = EINA_TRUE;
1009 if (wd->max_sc_w < w)
1011 if (wd->max_sc_h < h)
1018 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1019 void *event_info __UNUSED__)
1023 wd = elm_widget_data_get(obj);
1028 evas_object_show(wd->arrow);
1030 _scroller_size_reset(wd);
1035 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1036 const char *emission __UNUSED__, const char *source __UNUSED__)
1038 Elm_Ctxpopup_Item *item = data;
1041 if (item->disabled) return;
1044 item->func((void*) item->base.data, WIDGET(item), data);
1048 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1052 elm_widget_sub_object_del(VIEW(item), item->icon);
1053 evas_object_del(item->icon);
1059 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1060 edje_object_message_signal_process(VIEW(item));
1064 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1066 if (!eina_stringshare_replace(&item->label, label))
1069 edje_object_part_text_set(VIEW(item), "elm.text", label);
1070 edje_object_message_signal_process(VIEW(item));
1074 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1078 wd = elm_widget_data_get(WIDGET(item));
1081 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1082 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1083 elm_widget_style_get(WIDGET(item)));
1084 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1085 _item_select_cb, item);
1086 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1087 evas_object_show(VIEW(item));
1091 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1092 void *event_info __UNUSED__)
1094 elm_object_content_unset(data);
1098 _list_del(Widget_Data *wd)
1100 if (!wd->scr) return;
1102 edje_object_part_unswallow(wd->base, wd->scr);
1103 evas_object_del(wd->scr);
1109 _list_new(Evas_Object *obj)
1112 wd = elm_widget_data_get(obj);
1116 wd->scr = elm_scroller_add(obj);
1117 elm_object_style_set(wd->scr, "ctxpopup");
1118 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1119 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1120 _scroller_resize, obj);
1121 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1124 wd->box = elm_box_add(obj);
1125 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1128 elm_object_content_set(wd->scr, wd->box);
1129 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1133 _remove_items(Widget_Data *wd)
1136 Elm_Ctxpopup_Item *item;
1138 if (!wd->items) return;
1140 EINA_LIST_FOREACH(wd->items, elist, item)
1143 eina_stringshare_del(item->label);
1145 evas_object_del(item->icon);
1146 wd->items = eina_list_remove(wd->items, item);
1154 elm_ctxpopup_add(Evas_Object *parent)
1159 Evas_Coord x, y, w, h;
1161 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1163 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1164 elm_widget_type_set(obj, "ctxpopup");
1165 elm_widget_sub_object_add(parent, obj);
1166 elm_widget_data_set(obj, wd);
1167 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1168 elm_widget_del_hook_set(obj, _del_hook);
1169 elm_widget_theme_hook_set(obj, _theme_hook);
1170 elm_widget_content_set_hook_set(obj, _content_set_hook);
1171 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1172 elm_widget_content_get_hook_set(obj, _content_get_hook);
1174 wd->parent = parent;
1177 wd->bg = edje_object_add(e);
1178 elm_widget_sub_object_add(obj, wd->bg);
1179 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1180 evas_object_geometry_get(parent, &x, &y, &w, &h);
1181 evas_object_move(wd->bg, x, y);
1182 evas_object_resize(wd->bg, w, h);
1183 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1184 _bg_clicked_cb, obj);
1187 wd->base = edje_object_add(e);
1188 elm_widget_sub_object_add(obj, wd->base);
1189 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1192 wd->arrow = edje_object_add(e);
1193 elm_widget_sub_object_add(obj, wd->arrow);
1194 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1196 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1197 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1198 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1199 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1201 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1203 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1205 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1207 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1209 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1210 _ctxpopup_changed_size_hints, NULL);
1211 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1212 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1213 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1214 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1216 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1222 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1224 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1225 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1226 return ctxpopup_it->icon;
1230 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1232 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1235 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1237 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1240 _item_icon_set(ctxpopup_it, icon);
1244 _scroller_size_reset(wd);
1245 _sizing_eval(WIDGET(ctxpopup_it));
1250 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1252 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1253 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1254 return ctxpopup_it->label;
1258 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1260 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1263 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1265 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1268 _item_label_set(ctxpopup_it, label);
1272 _scroller_size_reset(wd);
1273 _sizing_eval(WIDGET(ctxpopup_it));
1278 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1280 ELM_CHECK_WIDTYPE(obj, widtype);
1284 wd = elm_widget_data_get(obj);
1287 _hover_parent_callbacks_del(obj);
1291 evas_object_event_callback_add(hover_parent,
1295 evas_object_event_callback_add(hover_parent,
1299 evas_object_event_callback_add(hover_parent,
1300 EVAS_CALLBACK_RESIZE,
1301 _hover_parent_resize,
1305 wd->hover_parent = hover_parent;
1309 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1311 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1315 wd = elm_widget_data_get(obj);
1316 if (!wd) return NULL;
1318 return wd->hover_parent;
1322 elm_ctxpopup_clear(Evas_Object * obj)
1324 ELM_CHECK_WIDTYPE(obj, widtype);
1326 Widget_Data *wd = elm_widget_data_get(obj);
1334 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1336 ELM_CHECK_WIDTYPE(obj, widtype);
1340 Elm_Ctxpopup_Item *item;
1343 wd = elm_widget_data_get(obj);
1346 wd->horizontal = !!horizontal;
1348 if ((!wd->scr) && (!wd->box))
1353 elm_box_horizontal_set(wd->box, EINA_FALSE);
1354 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1356 EINA_LIST_FOREACH(wd->items, elist, item)
1359 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1361 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1366 elm_box_horizontal_set(wd->box, EINA_TRUE);
1367 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1369 EINA_LIST_FOREACH(wd->items, elist, item)
1372 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1374 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1383 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1385 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1389 wd = elm_widget_data_get(obj);
1390 if (!wd) return EINA_FALSE;
1392 return wd->horizontal;
1395 EAPI Elm_Object_Item *
1396 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1397 Evas_Object *icon, Evas_Smart_Cb func,
1400 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1403 Elm_Ctxpopup_Item *item;
1405 wd = elm_widget_data_get(obj);
1406 if (!wd) return NULL;
1408 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1409 if (!item) return NULL;
1411 //The first item is appended.
1413 evas_object_del(elm_object_content_unset(obj));
1419 item->base.data = data;
1422 _item_new(item, "icon_text_style_item");
1424 _item_new(item, "text_style_item");
1426 _item_new(item, "icon_style_item");
1428 _item_icon_set(item, icon);
1429 _item_label_set(item, label);
1430 elm_box_pack_end(wd->box, VIEW(item));
1431 wd->items = eina_list_append(wd->items, item);
1435 _scroller_size_reset(wd);
1439 return (Elm_Object_Item *) item;
1443 elm_ctxpopup_item_del(Elm_Object_Item *it)
1445 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1448 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1450 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1453 if (ctxpopup_it->icon)
1454 evas_object_del(ctxpopup_it->icon);
1455 if (VIEW(ctxpopup_it))
1456 evas_object_del(VIEW(ctxpopup_it));
1458 eina_stringshare_del(ctxpopup_it->label);
1460 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1462 if (eina_list_count(wd->items) < 1)
1466 _sizing_eval(WIDGET(ctxpopup_it));
1472 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1474 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1477 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1479 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1482 if (disabled == ctxpopup_it->disabled)
1486 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
1488 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
1490 ctxpopup_it->disabled = !!disabled;
1494 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1496 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1497 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1498 return ctxpopup_it->disabled;
1502 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1504 elm_object_content_set(obj, content);
1508 elm_ctxpopup_content_unset(Evas_Object *obj)
1510 return elm_object_content_unset(obj);
1514 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1515 Elm_Ctxpopup_Direction first,
1516 Elm_Ctxpopup_Direction second,
1517 Elm_Ctxpopup_Direction third,
1518 Elm_Ctxpopup_Direction fourth)
1520 ELM_CHECK_WIDTYPE(obj, widtype);
1523 wd = elm_widget_data_get(obj);
1526 wd->dir_priority[0] = first;
1527 wd->dir_priority[1] = second;
1528 wd->dir_priority[2] = third;
1529 wd->dir_priority[3] = fourth;
1536 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1537 Elm_Ctxpopup_Direction *first,
1538 Elm_Ctxpopup_Direction *second,
1539 Elm_Ctxpopup_Direction *third,
1540 Elm_Ctxpopup_Direction *fourth)
1542 ELM_CHECK_WIDTYPE(obj, widtype);
1545 wd = elm_widget_data_get(obj);
1548 if (first) *first = wd->dir_priority[0];
1549 if (second) *second = wd->dir_priority[1];
1550 if (third) *third = wd->dir_priority[2];
1551 if (fourth) *fourth = wd->dir_priority[3];
1554 EAPI Elm_Ctxpopup_Direction
1555 elm_ctxpopup_direction_get(const Evas_Object *obj)
1557 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1560 wd = elm_widget_data_get(obj);
1561 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;