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__, Evas_Object *obj,
40 void *event_info __UNUSED__);
41 static void _freeze_off(void *data __UNUSED__, Evas_Object *obj,
42 void *event_info __UNUSED__);
43 static void _hold_on(void *data __UNUSED__, Evas_Object *obj,
44 void *event_info __UNUSED__);
45 static void _hold_off(void *data __UNUSED__, Evas_Object *obj,
46 void *event_info __UNUSED__);
47 static void _scroller_size_reset(Widget_Data *wd);
48 static void _hover_parent_callbacks_del(Evas_Object *obj);
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, Evas_Coord_Point *base_size,
60 Evas_Coord_Rectangle *hover_area);
61 static void _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
62 Evas_Coord_Rectangle *hover_area);
63 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
64 Evas *e __UNUSED__, Evas_Object *obj,
65 void *event_info __UNUSED__);
66 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
67 Evas_Coord_Rectangle *rect);
68 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
69 static void _sizing_eval(Evas_Object *obj);
70 static void _shift_base_by_arrow(Evas_Object *arrow,
71 Elm_Ctxpopup_Direction dir,
72 Evas_Coord_Rectangle *rect);
73 static void _del_pre_hook(Evas_Object *obj);
74 static void _del_hook(Evas_Object *obj);
75 static void _theme_hook(Evas_Object *obj);
76 static void _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
77 const char *emission __UNUSED__,
78 const char *source __UNUSED__);
79 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
80 void *event_info __UNUSED__);
81 static void _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__,
82 Evas_Object *obj, void *event_info __UNUSED__);
83 static void _hide(Evas_Object *obj);
84 static void _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__,
85 Evas_Object *obj, void *event_info __UNUSED__);
86 static void _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
87 void *event_info __UNUSED__);
88 static void _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__,
89 Evas_Object *obj, void *event_info __UNUSED__);
90 static void _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
91 const char *emission __UNUSED__,
92 const char *source __UNUSED__);
93 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
94 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
95 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
96 static void _content_del(void *data, Evas *e, Evas_Object *obj __UNUSED__,
97 void *event_info __UNUSED__);
98 static void _list_del(Widget_Data *wd);
99 static void _list_new(Evas_Object *obj);
100 static void _remove_items(Widget_Data * wd);
102 static const char SIG_DISMISSED[] = "dismissed";
104 static const Evas_Smart_Cb_Description _signals[] = {
109 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
110 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
111 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
114 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
115 void *event_info __UNUSED__)
117 Widget_Data *wd = elm_widget_data_get(obj);
119 if ((!wd) || (!wd->scr)) return;
121 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
125 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
126 void *event_info __UNUSED__)
128 Widget_Data *wd = elm_widget_data_get(obj);
130 if ((!wd) || (!wd->scr)) return;
133 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
135 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
139 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
141 Widget_Data *wd = elm_widget_data_get(obj);
143 if ((!wd) || (!wd->scr)) return;
145 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
149 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
151 Widget_Data *wd = elm_widget_data_get(obj);
153 if ((!wd) || (!wd->scr)) return;
156 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
158 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
162 _scroller_size_reset(Widget_Data *wd)
164 wd->finished = EINA_FALSE;
170 _hover_parent_callbacks_del(Evas_Object *obj)
172 Widget_Data *wd = elm_widget_data_get(obj);
174 if ((!wd) || (!wd->hover_parent))
177 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
178 _hover_parent_del, obj);
179 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
180 _hover_parent_move, obj);
181 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
182 _hover_parent_resize, obj);
186 _hover_parent_resize(void *data, Evas *e __UNUSED__,
187 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
189 Widget_Data *wd = elm_widget_data_get(data);
195 _scroller_size_reset(wd);
201 _hover_parent_move(void *data, Evas *e __UNUSED__,
202 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
204 Widget_Data *wd = elm_widget_data_get(data);
210 _scroller_size_reset(wd);
216 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
217 void *event_info __UNUSED__)
219 Widget_Data *wd = elm_widget_data_get(data);
223 wd->hover_parent = NULL;
227 _item_sizing_eval(Elm_Ctxpopup_Item *item)
229 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
233 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
235 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
236 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
240 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
241 Evas_Coord_Rectangle *hover_area)
243 pos->x -= (base_size->x / 2);
245 if (pos->x < hover_area->x)
246 pos->x = hover_area->x;
247 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
248 pos->x = (hover_area->x + hover_area->w) - base_size->x;
250 if (base_size->x > hover_area->w)
251 base_size->x -= (base_size->x - hover_area->w);
253 if (pos->x < hover_area->x)
254 pos->x = hover_area->x;
258 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
259 Evas_Coord_Rectangle *hover_area)
261 pos->y -= (base_size->y / 2);
263 if (pos->y < hover_area->y)
264 pos->y = hover_area->y;
265 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
266 pos->y = hover_area->y + hover_area->h - base_size->y;
268 if (base_size->y > hover_area->h)
269 base_size->y -= (base_size->y - hover_area->h);
271 if (pos->y < hover_area->y)
272 pos->y = hover_area->y;
276 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
277 Evas_Object *obj, void *event_info __UNUSED__)
281 wd = elm_widget_data_get(obj);
288 static Elm_Ctxpopup_Direction
289 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
292 Evas_Coord_Point pos = {0, 0};
293 Evas_Coord_Point base_size;
294 Evas_Coord_Point max_size;
295 Evas_Coord_Point min_size;
296 Evas_Coord_Rectangle hover_area;
297 Evas_Coord_Rectangle parent_size;
298 Evas_Coord_Point arrow_size;
299 Elm_Ctxpopup_Direction arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
300 Evas_Coord_Point temp;
303 wd = elm_widget_data_get(obj);
305 if ((!wd) || (!rect))
306 return ELM_CTXPOPUP_DIRECTION_DOWN;
308 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
309 &arrow_size.x, &arrow_size.y);
310 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
312 //Initialize Area Rectangle.
313 if (wd->hover_parent)
314 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
315 &hover_area.w, &hover_area.h);
318 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
319 &parent_size.w, &parent_size.h);
320 hover_area.x = parent_size.x;
321 hover_area.y = parent_size.y;
322 hover_area.w = parent_size.w;
323 hover_area.h = parent_size.h;
326 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
329 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
330 evas_object_smart_calculate(wd->base);
333 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
335 if ((max_size.y > 0) && (base_size.y > max_size.y))
336 base_size.y = max_size.y;
338 if ((max_size.x > 0) && (base_size.x > max_size.x))
339 base_size.x = max_size.x;
342 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
344 if ((min_size.y > 0) && (base_size.y < min_size.y))
345 base_size.y = min_size.y;
347 if ((min_size.x > 0) && (base_size.x < min_size.x))
348 base_size.x = min_size.x;
350 //Check the Which direction is available.
351 //If find a avaialble direction, it adjusts position and size.
352 for (idx = 0; idx < 4; idx++)
354 switch (wd->dir_priority[idx])
356 case ELM_CTXPOPUP_DIRECTION_UP:
357 temp.y = (pos.y - base_size.y);
358 if ((temp.y - arrow_size.y) < hover_area.y)
360 _adjust_pos_x(&pos, &base_size, &hover_area);
361 pos.y -= base_size.y;
362 arrow = ELM_CTXPOPUP_DIRECTION_UP;
364 case ELM_CTXPOPUP_DIRECTION_LEFT:
365 temp.x = (pos.x - base_size.x);
366 if ((temp.x - arrow_size.x) < hover_area.x)
368 _adjust_pos_y(&pos, &base_size, &hover_area);
369 pos.x -= base_size.x;
370 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
372 case ELM_CTXPOPUP_DIRECTION_RIGHT:
373 temp.x = (pos.x + base_size.x);
374 if ((temp.x + arrow_size.x) >
375 (hover_area.x + hover_area.w))
377 _adjust_pos_y(&pos, &base_size, &hover_area);
378 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
380 case ELM_CTXPOPUP_DIRECTION_DOWN:
381 temp.y = (pos.y + base_size.y);
382 if ((temp.y + arrow_size.y) >
383 (hover_area.y + hover_area.h))
385 _adjust_pos_x(&pos, &base_size, &hover_area);
386 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
394 //In this case, all directions are invalid because of lack of space.
397 Evas_Coord length[2];
401 length[0] = pos.y - hover_area.y;
402 length[1] = (hover_area.y + hover_area.h) - pos.y;
404 // ELM_CTXPOPUP_DIRECTION_UP
405 if (length[0] > length[1])
407 _adjust_pos_x(&pos, &base_size, &hover_area);
408 pos.y -= base_size.y;
409 arrow = ELM_CTXPOPUP_DIRECTION_UP;
410 if (pos.y < (hover_area.y + arrow_size.y))
412 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
413 pos.y = hover_area.y + arrow_size.y;
416 //ELM_CTXPOPUP_DIRECTION_DOWN
419 _adjust_pos_x(&pos, &base_size, &hover_area);
420 arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
421 if ((pos.y + arrow_size.y + base_size.y) >
422 (hover_area.y + hover_area.h))
424 ((pos.y + arrow_size.y + base_size.y) -
425 (hover_area.y + hover_area.h));
430 length[0] = pos.x - hover_area.x;
431 length[1] = (hover_area.x + hover_area.w) - pos.x;
433 //ELM_CTXPOPUP_DIRECTION_LEFT
434 if (length[0] > length[1])
436 _adjust_pos_y(&pos, &base_size, &hover_area);
437 pos.x -= base_size.x;
438 arrow = ELM_CTXPOPUP_DIRECTION_LEFT;
439 if (pos.x < (hover_area.x + arrow_size.x))
441 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
442 pos.x = hover_area.x + arrow_size.x;
445 //ELM_CTXPOPUP_DIRECTION_RIGHT
448 _adjust_pos_y(&pos, &base_size, &hover_area);
449 arrow = ELM_CTXPOPUP_DIRECTION_RIGHT;
450 if (pos.x + (arrow_size.x + base_size.x) >
451 hover_area.x + hover_area.w)
453 ((pos.x + arrow_size.x + base_size.x) -
454 (hover_area.x + hover_area.w));
459 //Final position and size.
462 rect->w = base_size.x;
463 rect->h = base_size.y;
469 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
472 Evas_Coord_Rectangle arrow_size;
473 Evas_Coord_Rectangle base_size;
476 wd = elm_widget_data_get(obj);
479 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
480 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
482 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
483 &base_size.w, &base_size.h);
485 // unswallow arrow from base
486 edje_object_part_unswallow(wd->base, wd->arrow);
490 case ELM_CTXPOPUP_DIRECTION_RIGHT:
491 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
493 // if user does not use dragable part
494 arrow_size.y = (y - (arrow_size.h * 0.5));
497 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
500 if (y < ((arrow_size.h * 0.5) + base_size.y))
502 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
503 y = base_size.h - arrow_size.h;
505 y = y - base_size.y - (arrow_size.h * 0.5);
506 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
507 (double) (y) / (double) (base_size.h - arrow_size.h));
510 case ELM_CTXPOPUP_DIRECTION_LEFT:
511 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
513 // if user does not use dragable part
514 arrow_size.y = (y - (arrow_size.h * 0.5));
515 arrow_size.x = (x - arrow_size.w);
517 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
520 if (y < (arrow_size.h * 0.5) + base_size.y)
522 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
523 y = base_size.h - arrow_size.h;
524 else y = y - base_size.y - (arrow_size.h * 0.5);
525 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
526 (double) (y) / (double) (base_size.h - arrow_size.h));
529 case ELM_CTXPOPUP_DIRECTION_DOWN:
530 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
532 // if user does not use dragable part
533 arrow_size.x = (x - (arrow_size.w * 0.5));
536 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
539 if (x < (arrow_size.w * 0.5) + base_size.x)
541 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
542 x = base_size.w - arrow_size.w;
544 x = x - base_size.x - (arrow_size.w * 0.5);
545 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
546 (double) (x) / (double) (base_size.w - arrow_size.w), 1);
549 case ELM_CTXPOPUP_DIRECTION_UP:
550 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
552 // if user does not use dragable part
553 arrow_size.x = (x - (arrow_size.w * 0.5));
554 arrow_size.y = (y - arrow_size.h);
556 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
559 if (x < (arrow_size.w * 0.5) + base_size.x)
561 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
562 x = base_size.w - arrow_size.w;
563 else x = x - base_size.x - (arrow_size.w * 0.5);
564 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
565 (double) (x) / (double) (base_size.w - arrow_size.w), 0);
572 // if user does not use dragable part
573 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
576 //TODO: compress item - different from opensource
578 _compress_item(Evas_Object *obj)
582 Elm_Ctxpopup_Item *item;
584 wd = elm_widget_data_get(obj);
587 EINA_LIST_FOREACH(wd->items, elist, item)
589 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
594 _sizing_eval(Evas_Object *obj)
598 Elm_Ctxpopup_Item *item;
599 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
600 Evas_Coord_Point box_size = { 0, 0 };
601 Evas_Coord_Point _box_size = { 0, 0 };
603 wd = elm_widget_data_get(obj);
604 if ((!wd) || (!wd->parent)) return;
607 EINA_LIST_FOREACH(wd->items, elist, item)
609 _item_sizing_eval(item);
610 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
613 if (_box_size.x > box_size.x)
614 box_size.x = _box_size.x;
615 if (_box_size.y != -1)
616 box_size.y += _box_size.y;
620 if (_box_size.x != -1)
621 box_size.x += _box_size.x;
622 if (_box_size.y > box_size.y)
623 box_size.y = _box_size.y;
629 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
630 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
634 wd->dir = _calc_base_geometry(obj, &rect);
636 //TODO: compress item - different from opensource
637 if (!wd->horizontal && !wd->content)
640 _update_arrow(obj, wd->dir);
641 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
643 //resize scroller according to final size.
645 evas_object_smart_calculate(wd->scr);
647 evas_object_move(wd->base, rect.x, rect.y);
648 evas_object_resize(wd->base, rect.w, rect.h);
652 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
653 Evas_Coord_Rectangle *rect)
655 Evas_Coord arrow_w, arrow_h;
657 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
661 case ELM_CTXPOPUP_DIRECTION_RIGHT:
664 case ELM_CTXPOPUP_DIRECTION_LEFT:
667 case ELM_CTXPOPUP_DIRECTION_DOWN:
670 case ELM_CTXPOPUP_DIRECTION_UP:
679 _del_pre_hook(Evas_Object *obj)
683 wd = elm_widget_data_get(obj);
686 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
687 _parent_resize, obj);
689 _hover_parent_callbacks_del(obj);
693 _del_hook(Evas_Object *obj)
697 wd = elm_widget_data_get(obj);
700 elm_ctxpopup_clear(obj);
701 evas_object_del(wd->arrow);
702 evas_object_del(wd->base);
707 _theme_hook(Evas_Object *obj)
711 Elm_Ctxpopup_Item *item;
714 wd = elm_widget_data_get(obj);
718 EINA_LIST_FOREACH(wd->items, elist, item)
720 if (item->label && item->icon)
721 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
722 "icon_text_style_item",
723 elm_widget_style_get(obj));
724 else if (item->label)
725 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
726 elm_widget_style_get(obj));
728 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
729 elm_widget_style_get(obj));
731 edje_object_part_text_set(item->base.view, "elm.text", item->label);
734 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
737 * For separator, if the first item has visible separator,
738 * then it should be aligned with edge of the base part.
739 * In some cases, it gives improper display. Ex) rounded corner
740 * So the first item separator should be invisible.
743 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
747 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
749 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
752 edje_object_message_signal_process(item->base.view);
755 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
756 elm_widget_style_get(obj));
757 if (evas_object_visible_get(wd->bg))
758 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
760 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
761 elm_widget_style_get(obj));
762 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
763 elm_widget_style_get(obj));
767 if (!strncmp(elm_object_style_get(obj), "default",
769 elm_object_style_set(wd->scr, "ctxpopup");
771 elm_object_style_set(wd->scr, elm_object_style_get(obj));
776 _scroller_size_reset(wd);
782 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
783 const char *emission __UNUSED__, const char *source __UNUSED__)
785 evas_object_hide(data);
789 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
790 void *event_info __UNUSED__)
795 wd = elm_widget_data_get(data);
798 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
799 evas_object_resize(wd->bg, w, h);
801 if (!wd->visible) return;
807 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
808 void *event_info __UNUSED__)
812 Elm_Ctxpopup_Item *item;
815 wd = elm_widget_data_get(obj);
818 if ((!wd->items) && (!wd->content)) return;
820 wd->visible = EINA_TRUE;
822 evas_object_show(wd->bg);
823 evas_object_show(wd->base);
824 evas_object_show(wd->arrow);
826 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
828 EINA_LIST_FOREACH(wd->items, elist, item)
831 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
835 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
837 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
845 _hide(Evas_Object *obj)
847 Widget_Data *wd = elm_widget_data_get(obj);
851 evas_object_hide(wd->bg);
852 evas_object_hide(wd->arrow);
853 evas_object_hide(wd->base);
855 _scroller_size_reset(wd);
857 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
858 wd->visible = EINA_FALSE;
862 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
863 void *event_info __UNUSED__)
867 wd = elm_widget_data_get(obj);
868 if ((!wd) || (!wd->visible))
875 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
876 void *event_info __UNUSED__)
881 wd = elm_widget_data_get(data);
883 if (!wd->visible) return;
884 if (wd->finished) return;
886 evas_object_geometry_get(obj, 0, 0, &w, &h);
888 if (w != 0 && h != 0)
890 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
893 wd->finished = EINA_TRUE;
898 if (wd->max_sc_w < w)
900 if (wd->max_sc_h < h)
907 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
908 void *event_info __UNUSED__)
912 wd = elm_widget_data_get(obj);
917 evas_object_show(wd->arrow);
919 _scroller_size_reset(wd);
924 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
925 const char *emission __UNUSED__, const char *source __UNUSED__)
927 Elm_Ctxpopup_Item *item = data;
930 if (item->disabled) return;
933 item->func((void*) item->base.data, item->base.widget, data);
937 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
941 elm_widget_sub_object_del(item->base.view, item->icon);
942 evas_object_del(item->icon);
948 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
949 edje_object_message_signal_process(item->base.view);
953 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
955 if (!eina_stringshare_replace(&item->label, label))
958 edje_object_part_text_set(item->base.view, "elm.text", label);
959 edje_object_message_signal_process(item->base.view);
963 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
967 wd = elm_widget_data_get(item->base.widget);
970 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
971 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
972 elm_widget_style_get(item->base.widget));
973 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
974 _item_select_cb, item);
975 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
976 evas_object_show(item->base.view);
980 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
981 void *event_info __UNUSED__)
983 elm_ctxpopup_content_unset(data);
987 _list_del(Widget_Data *wd)
989 if (!wd->scr) return;
991 edje_object_part_unswallow(wd->base, wd->scr);
992 evas_object_del(wd->scr);
998 _list_new(Evas_Object *obj)
1001 wd = elm_widget_data_get(obj);
1005 wd->scr = elm_scroller_add(obj);
1006 elm_object_style_set(wd->scr, "ctxpopup");
1007 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1008 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1009 _scroller_resize, obj);
1010 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1013 wd->box = elm_box_add(obj);
1014 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1017 elm_scroller_content_set(wd->scr, wd->box);
1018 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1022 _remove_items(Widget_Data *wd)
1025 Elm_Ctxpopup_Item *item;
1027 if (!wd->items) return;
1029 EINA_LIST_FOREACH(wd->items, elist, item)
1032 eina_stringshare_del(item->label);
1034 evas_object_del(item->icon);
1035 wd->items = eina_list_remove(wd->items, item);
1043 * Add a new Ctxpopup object to the parent.
1045 * @param parent Parent object
1046 * @return New object or @c NULL, if it cannot be created
1051 elm_ctxpopup_add(Evas_Object *parent)
1056 Evas_Coord x, y, w, h;
1058 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1060 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1061 elm_widget_type_set(obj, "ctxpopup");
1062 elm_widget_sub_object_add(parent, obj);
1063 elm_widget_data_set(obj, wd);
1064 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1065 elm_widget_del_hook_set(obj, _del_hook);
1066 elm_widget_theme_hook_set(obj, _theme_hook);
1068 wd->parent = parent;
1071 wd->bg = edje_object_add(e);
1072 elm_widget_sub_object_add(obj, wd->bg);
1073 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1074 evas_object_geometry_get(parent, &x, &y, &w, &h);
1075 evas_object_move(wd->bg, x, y);
1076 evas_object_resize(wd->bg, w, h);
1077 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1078 _bg_clicked_cb, obj);
1081 wd->base = edje_object_add(e);
1082 elm_widget_sub_object_add(obj, wd->base);
1083 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1086 wd->arrow = edje_object_add(e);
1087 elm_widget_sub_object_add(obj, wd->arrow);
1088 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1090 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1091 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1092 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1093 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1095 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1097 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1099 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1101 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1103 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1104 _ctxpopup_changed_size_hints, NULL);
1105 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1106 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1107 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1108 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1110 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1116 * Get the icon object for the given ctxpopup item.
1118 * @param item Ctxpopup item
1119 * @return icon object or @c NULL, if the item does not have icon or an error occurred
1124 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1126 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1127 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1132 * Sets the side icon associated with the ctxpopup item
1134 * Once the icon object is set, a previously set one will be deleted.
1135 * You probably don't want, then, to have the <b>same</b> icon object
1136 * set for more than one item of the list (when replacing one of its
1139 * @param item Ctxpopup item
1140 * @param icon Icon object to be set
1145 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1147 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1150 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1152 wd = elm_widget_data_get(item->base.widget);
1155 _item_icon_set(item, icon);
1159 _scroller_size_reset(wd);
1160 _sizing_eval(item->base.widget);
1165 * Get the label object for the given ctxpopup item.
1167 * @param item Ctxpopup item
1168 * @return label object or @c NULL, if the item does not have label or an error occured
1174 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1176 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1177 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1182 * (Re)set the label on the given ctxpopup item.
1184 * @param item Ctxpopup item
1185 * @param label String to set as label
1190 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1192 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1195 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1197 wd = elm_widget_data_get(item->base.widget);
1200 _item_label_set(item, label);
1204 _scroller_size_reset(wd);
1205 _sizing_eval(item->base.widget);
1210 * Set the Ctxpopup's parent
1211 * Set the parent object (it would much probably be the
1212 * window that the ctxpopup is in).
1214 * @param obj The ctxpopup object
1215 * @param area The parent to use
1217 * @note elm_ctxpopup_add() will automatically call this function
1218 * with its @c parent argument.
1223 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1225 ELM_CHECK_WIDTYPE(obj, widtype);
1229 wd = elm_widget_data_get(obj);
1232 _hover_parent_callbacks_del(obj);
1236 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1237 _hover_parent_del, obj);
1238 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1239 _hover_parent_move, obj);
1240 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1241 _hover_parent_resize, obj);
1244 wd->hover_parent = hover_parent;
1248 * Get the Ctxpopup's parent
1250 * @param obj The ctxpopup object
1252 * @see elm_ctxpopup_hover_parent_set() for more information
1257 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1259 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1263 wd = elm_widget_data_get(obj);
1264 if (!wd) return NULL;
1266 return wd->hover_parent;
1270 * Clear all items in the given ctxpopup object.
1272 * @param obj Ctxpopup object
1277 elm_ctxpopup_clear(Evas_Object * obj)
1279 ELM_CHECK_WIDTYPE(obj, widtype);
1281 Widget_Data *wd = elm_widget_data_get(obj);
1289 * Change the ctxpopup's orientation to horizontal or vertical.
1291 * @param obj Ctxpopup object
1292 * @param horizontal @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical
1297 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1299 ELM_CHECK_WIDTYPE(obj, widtype);
1303 Elm_Ctxpopup_Item *item;
1306 wd = elm_widget_data_get(obj);
1309 wd->horizontal = !!horizontal;
1311 if ((!wd->scr) && (!wd->box))
1316 elm_box_horizontal_set(wd->box, EINA_FALSE);
1317 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1319 EINA_LIST_FOREACH(wd->items, elist, item)
1322 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
1324 edje_object_signal_emit(item->base.view, "elm,state,vertical", "elm");
1329 elm_box_horizontal_set(wd->box, EINA_TRUE);
1330 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1332 EINA_LIST_FOREACH(wd->items, elist, item)
1335 edje_object_signal_emit(item->base.view, "elm,state,default", "elm");
1337 edje_object_signal_emit(item->base.view, "elm,state,horizontal", "elm");
1346 * Get the value of current ctxpopup object's orientation.
1348 * @param obj Ctxpopup object
1349 * @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical mode (or errors)
1354 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1356 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1360 wd = elm_widget_data_get(obj);
1361 if (!wd) return EINA_FALSE;
1363 return wd->horizontal;
1367 * Add a new item to a ctxpopup object.
1369 * Both a item list and a content could not be set at the same time!
1370 * once you set add a item, the previous content will be removed.
1372 * @param obj Ctxpopup object
1373 * @param icon Icon to be set on new item
1374 * @param label The Label of the new item
1375 * @param func Convenience function called when item selected
1376 * @param data Data passed to @p func above
1377 * @return A handle to the item added or @c NULL, on errors
1381 EAPI Elm_Object_Item *
1382 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1383 Evas_Object *icon, Evas_Smart_Cb func,
1386 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1389 Elm_Ctxpopup_Item *item;
1391 wd = elm_widget_data_get(obj);
1392 if (!wd) return NULL;
1394 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1395 if (!item) return NULL;
1397 //The first item is appended.
1399 evas_object_del(elm_ctxpopup_content_unset(obj));
1405 item->base.data = data;
1408 _item_new(item, "icon_text_style_item");
1410 _item_new(item, "text_style_item");
1412 _item_new(item, "icon_style_item");
1414 _item_icon_set(item, icon);
1415 _item_label_set(item, label);
1416 elm_box_pack_end(wd->box, item->base.view);
1417 wd->items = eina_list_append(wd->items, item);
1421 _scroller_size_reset(wd);
1425 return (Elm_Object_Item*) item;
1429 * Delete the given item in a ctxpopup object.
1431 * @param item Ctxpopup item to be deleted
1436 elm_ctxpopup_item_del(Elm_Object_Item *it)
1438 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1441 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1443 wd = elm_widget_data_get(item->base.widget);
1447 evas_object_del(item->icon);
1448 if (item->base.view)
1449 evas_object_del(item->base.view);
1451 eina_stringshare_del(item->label);
1453 wd->items = eina_list_remove(wd->items, item);
1455 if (eina_list_count(wd->items) < 1)
1459 _sizing_eval(item->base.widget);
1465 * Set the ctxpopup item's state as disabled or enabled.
1467 * @param item Ctxpopup item to be enabled/disabled
1468 * @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable it
1473 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1475 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1478 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1480 wd = elm_widget_data_get(item->base.widget);
1483 if (disabled == item->disabled)
1487 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1489 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1491 item->disabled = !!disabled;
1495 * Get the ctxpopup item's disabled/enabled state.
1497 * @param item Ctxpopup item to be enabled/disabled
1498 * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
1503 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1505 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1506 Elm_Ctxpopup_Item *item = (Elm_Ctxpopup_Item *) it;
1507 return item->disabled;
1511 * Once the content object is set, a previously set one will be deleted.
1512 * If you want to keep that old content object, use the
1513 * elm_ctxpopup_content_unset() function
1515 * Both a item list and a content could not be set at the same time!
1516 * once you set a content, the previous list items will be removed.
1518 * @param obj Ctxpopup object
1519 * @param content Content to be swallowed
1524 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1526 ELM_CHECK_WIDTYPE(obj, widtype);
1530 wd = elm_widget_data_get(obj);
1531 if ((!wd) || (!content))
1535 elm_ctxpopup_clear(obj);
1538 evas_object_del(wd->content);
1540 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1543 elm_widget_sub_object_add(obj, content);
1544 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1545 edje_object_message_signal_process(wd->base);
1547 wd->content = content;
1554 * Unset the ctxpopup content
1556 * Unparent and return the content object which was set for this widget
1558 * @param obj Ctxpopup object
1559 * @return The content that was being used
1564 elm_ctxpopup_content_unset(Evas_Object *obj)
1566 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1569 Evas_Object *content;
1571 wd = elm_widget_data_get(obj);
1572 if (!wd) return NULL;
1574 content = wd->content;
1575 if (!content) return NULL;
1577 edje_object_part_unswallow(wd->base, content);
1578 elm_widget_sub_object_del(obj, content);
1579 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1580 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1588 * Set the direction priority of a ctxpopup.
1589 * This functions gives a chance to user to set the priority of ctxpopup showing direction.
1591 * @param obj Ctxpopup object
1592 * @param first 1st priority of direction
1593 * @param second 2nd priority of direction
1594 * @param third 3th priority of direction
1595 * @param fourth 4th priority of direction
1600 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1601 Elm_Ctxpopup_Direction first,
1602 Elm_Ctxpopup_Direction second,
1603 Elm_Ctxpopup_Direction third,
1604 Elm_Ctxpopup_Direction fourth)
1606 ELM_CHECK_WIDTYPE(obj, widtype);
1609 wd = elm_widget_data_get(obj);
1612 wd->dir_priority[0] = first;
1613 wd->dir_priority[1] = second;
1614 wd->dir_priority[2] = third;
1615 wd->dir_priority[3] = fourth;
1622 * Get the direction priority of a ctxpopup.
1624 * @param obj Ctxpopup object
1625 * @param first 1st priority of direction to be returned
1626 * @param second 2nd priority of direction to be returned
1627 * @param third 3th priority of direction to be returned
1628 * @param fourth 4th priority of direction to be returned
1630 * @see elm_ctxpopup_direction_priority_set for more information.
1635 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1636 Elm_Ctxpopup_Direction *first,
1637 Elm_Ctxpopup_Direction *second,
1638 Elm_Ctxpopup_Direction *third,
1639 Elm_Ctxpopup_Direction *fourth)
1641 ELM_CHECK_WIDTYPE(obj, widtype);
1644 wd = elm_widget_data_get(obj);
1647 if (first) *first = wd->dir_priority[0];
1648 if (second) *second = wd->dir_priority[1];
1649 if (third) *third = wd->dir_priority[2];
1650 if (fourth) *fourth = wd->dir_priority[3];
1654 * @brief Get the current direction of a ctxpopup.
1656 * @param obj Ctxpopup object
1657 * @return current direction of a ctxpopup
1659 * @warning Once the ctxpopup showed up, the direction would be determined
1662 EAPI Elm_Ctxpopup_Direction
1663 elm_ctxpopup_direction_get(const Evas_Object *obj)
1665 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1668 wd = elm_widget_data_get(obj);
1669 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;