1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Elm_Ctxpopup_Item Elm_Ctxpopup_Item;
7 struct _Elm_Ctxpopup_Item
25 Evas_Object *hover_parent;
27 Elm_Ctxpopup_Direction dir;
28 Elm_Ctxpopup_Direction dir_priority[4];
29 Evas_Coord max_sc_w, max_sc_h;
30 Eina_Bool horizontal:1;
35 static const char *widtype = NULL;
37 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
38 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
39 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
40 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
41 static void _scroller_size_reset(Widget_Data *wd);
42 static void _on_focus_hook(void *data, Evas_Object *obj);
43 static Eina_Bool _event_hook(Evas_Object *obj,
45 Evas_Callback_Type type,
47 static void _hover_parent_callbacks_del(Evas_Object *obj);
48 static void _hover_parent_resize(void *data, Evas *e,
51 static void _hover_parent_move(void *data, Evas *e,
54 static void _hover_parent_del(void *data, Evas *e,
57 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
58 static void _adjust_pos_x(Evas_Coord_Point *pos,
59 Evas_Coord_Point *base_size,
60 Evas_Coord_Rectangle *hover_area);
61 static void _adjust_pos_y(Evas_Coord_Point *pos,
62 Evas_Coord_Point *base_size,
63 Evas_Coord_Rectangle *hover_area);
64 static void _ctxpopup_changed_size_hints(void *data,
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,
80 Evas_Object *content);
81 static Evas_Object * _content_unset_hook(Evas_Object *obj,
83 static Evas_Object * _content_get_hook(const Evas_Object *obj,
85 static void _bg_clicked_cb(void *data, Evas_Object *obj,
88 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
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[] = {
129 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
130 void *event_info __UNUSED__)
132 Widget_Data *wd = elm_widget_data_get(obj);
134 if ((!wd) || (!wd->scr)) return;
135 elm_object_scroll_freeze_push(wd->scr);
139 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
140 void *event_info __UNUSED__)
142 Widget_Data *wd = elm_widget_data_get(obj);
144 if ((!wd) || (!wd->scr)) return;
145 elm_object_scroll_freeze_pop(wd->scr);
149 _hold_on(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;
154 elm_object_scroll_hold_push(wd->scr);
158 _hold_off(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;
163 elm_object_scroll_hold_pop(wd->scr);
167 _scroller_size_reset(Widget_Data *wd)
169 wd->finished = EINA_FALSE;
175 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
177 Widget_Data *wd = elm_widget_data_get(obj);
180 if (elm_widget_focus_get(obj))
191 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
193 Evas_Event_Key_Down *ev;
196 if (type != EVAS_CALLBACK_KEY_DOWN)
198 wd = elm_widget_data_get(obj);
199 if (!wd) return EINA_FALSE;
202 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
203 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
205 evas_object_hide(obj);
206 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
211 _hover_parent_callbacks_del(Evas_Object *obj)
213 Widget_Data *wd = elm_widget_data_get(obj);
215 if ((!wd) || (!wd->hover_parent))
218 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
219 _hover_parent_del, obj);
220 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
221 _hover_parent_move, obj);
222 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
223 _hover_parent_resize, obj);
227 _hover_parent_resize(void *data, Evas *e __UNUSED__,
228 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
230 Widget_Data *wd = elm_widget_data_get(data);
234 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
238 _scroller_size_reset(wd);
244 _hover_parent_move(void *data, Evas *e __UNUSED__,
245 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
247 Widget_Data *wd = elm_widget_data_get(data);
251 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
255 _scroller_size_reset(wd);
261 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
262 void *event_info __UNUSED__)
264 Widget_Data *wd = elm_widget_data_get(data);
268 wd->hover_parent = NULL;
272 _item_sizing_eval(Elm_Ctxpopup_Item *item)
274 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
278 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
280 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
281 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
285 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
286 Evas_Coord_Rectangle *hover_area)
288 pos->x -= (base_size->x / 2);
290 if (pos->x < hover_area->x)
291 pos->x = hover_area->x;
292 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
293 pos->x = (hover_area->x + hover_area->w) - base_size->x;
295 if (base_size->x > hover_area->w)
296 base_size->x -= (base_size->x - hover_area->w);
298 if (pos->x < hover_area->x)
299 pos->x = hover_area->x;
303 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
304 Evas_Coord_Rectangle *hover_area)
306 pos->y -= (base_size->y / 2);
308 if (pos->y < hover_area->y)
309 pos->y = hover_area->y;
310 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
311 pos->y = hover_area->y + hover_area->h - base_size->y;
313 if (base_size->y > hover_area->h)
314 base_size->y -= (base_size->y - hover_area->h);
316 if (pos->y < hover_area->y)
317 pos->y = hover_area->y;
321 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
322 Evas_Object *obj, void *event_info __UNUSED__)
326 wd = elm_widget_data_get(obj);
329 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
335 static Elm_Ctxpopup_Direction
336 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
339 Evas_Coord_Point pos = {0, 0};
340 Evas_Coord_Point base_size;
341 Evas_Coord_Point max_size;
342 Evas_Coord_Point min_size;
343 Evas_Coord_Rectangle hover_area;
344 Evas_Coord_Rectangle parent_size;
345 Evas_Coord_Point arrow_size;
346 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
347 Evas_Coord_Point temp;
350 wd = elm_widget_data_get(obj);
352 if ((!wd) || (!rect))
353 return ELM_CTXPOPUP_DIRECTION_DOWN;
355 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
356 &arrow_size.x, &arrow_size.y);
357 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
359 //Initialize Area Rectangle.
360 if (wd->hover_parent)
361 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
362 &hover_area.w, &hover_area.h);
365 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
366 &parent_size.w, &parent_size.h);
367 hover_area.x = parent_size.x;
368 hover_area.y = parent_size.y;
369 hover_area.w = parent_size.w;
370 hover_area.h = parent_size.h;
373 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
376 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
377 evas_object_smart_calculate(wd->base);
380 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
382 if ((max_size.y > 0) && (base_size.y > max_size.y))
383 base_size.y = max_size.y;
385 if ((max_size.x > 0) && (base_size.x > max_size.x))
386 base_size.x = max_size.x;
389 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
391 if ((min_size.y > 0) && (base_size.y < min_size.y))
392 base_size.y = min_size.y;
394 if ((min_size.x > 0) && (base_size.x < min_size.x))
395 base_size.x = min_size.x;
397 //Check the Which direction is available.
398 //If find a avaialble direction, it adjusts position and size.
399 for (idx = 0; idx < 4; idx++)
401 switch (wd->dir_priority[idx])
403 case ELM_CTXPOPUP_DIRECTION_DONT_KNOW:
404 case ELM_CTXPOPUP_DIRECTION_UP:
405 temp.y = (pos.y - base_size.y);
406 if ((temp.y - arrow_size.y) < hover_area.y)
408 _adjust_pos_x(&pos, &base_size, &hover_area);
409 pos.y -= base_size.y;
410 dir = ELM_CTXPOPUP_DIRECTION_UP;
412 case ELM_CTXPOPUP_DIRECTION_LEFT:
413 temp.x = (pos.x - base_size.x);
414 if ((temp.x - arrow_size.x) < hover_area.x)
416 _adjust_pos_y(&pos, &base_size, &hover_area);
417 pos.x -= base_size.x;
418 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
420 case ELM_CTXPOPUP_DIRECTION_RIGHT:
421 temp.x = (pos.x + base_size.x);
422 if ((temp.x + arrow_size.x) >
423 (hover_area.x + hover_area.w))
425 _adjust_pos_y(&pos, &base_size, &hover_area);
426 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
428 case ELM_CTXPOPUP_DIRECTION_DOWN:
429 temp.y = (pos.y + base_size.y);
430 if ((temp.y + arrow_size.y) >
431 (hover_area.y + hover_area.h))
433 _adjust_pos_x(&pos, &base_size, &hover_area);
434 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
442 //In this case, all directions are invalid because of lack of space.
445 Evas_Coord length[2];
449 length[0] = pos.y - hover_area.y;
450 length[1] = (hover_area.y + hover_area.h) - pos.y;
452 // ELM_CTXPOPUP_DIRECTION_UP
453 if (length[0] > length[1])
455 _adjust_pos_x(&pos, &base_size, &hover_area);
456 pos.y -= base_size.y;
457 dir = ELM_CTXPOPUP_DIRECTION_UP;
458 if (pos.y < (hover_area.y + arrow_size.y))
460 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
461 pos.y = hover_area.y + arrow_size.y;
464 //ELM_CTXPOPUP_DIRECTION_DOWN
467 _adjust_pos_x(&pos, &base_size, &hover_area);
468 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
469 if ((pos.y + arrow_size.y + base_size.y) >
470 (hover_area.y + hover_area.h))
472 ((pos.y + arrow_size.y + base_size.y) -
473 (hover_area.y + hover_area.h));
478 length[0] = pos.x - hover_area.x;
479 length[1] = (hover_area.x + hover_area.w) - pos.x;
481 //ELM_CTXPOPUP_DIRECTION_LEFT
482 if (length[0] > length[1])
484 _adjust_pos_y(&pos, &base_size, &hover_area);
485 pos.x -= base_size.x;
486 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
487 if (pos.x < (hover_area.x + arrow_size.x))
489 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
490 pos.x = hover_area.x + arrow_size.x;
493 //ELM_CTXPOPUP_DIRECTION_RIGHT
496 _adjust_pos_y(&pos, &base_size, &hover_area);
497 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
498 if (pos.x + (arrow_size.x + base_size.x) >
499 hover_area.x + hover_area.w)
501 ((pos.x + arrow_size.x + base_size.x) -
502 (hover_area.x + hover_area.w));
507 //Final position and size.
510 rect->w = base_size.x;
511 rect->h = base_size.y;
517 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
520 Evas_Coord_Rectangle arrow_size;
521 Evas_Coord_Rectangle base_size;
524 wd = elm_widget_data_get(obj);
527 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
528 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
530 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
531 &base_size.w, &base_size.h);
535 case ELM_CTXPOPUP_DIRECTION_RIGHT:
536 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
537 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
540 if (y < ((arrow_size.h * 0.5) + base_size.y))
542 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
543 y = base_size.h - arrow_size.h;
545 y = y - base_size.y - (arrow_size.h * 0.5);
546 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
547 (double) (y) / (double) (base_size.h - arrow_size.h));
550 case ELM_CTXPOPUP_DIRECTION_LEFT:
551 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
552 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
555 if (y < (arrow_size.h * 0.5) + base_size.y)
557 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
558 y = base_size.h - arrow_size.h;
559 else y = y - base_size.y - (arrow_size.h * 0.5);
560 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
561 (double) (y) / (double) (base_size.h - arrow_size.h));
564 case ELM_CTXPOPUP_DIRECTION_DOWN:
565 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
566 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
569 if (x < (arrow_size.w * 0.5) + base_size.x)
571 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
572 x = base_size.w - arrow_size.w;
574 x = x - base_size.x - (arrow_size.w * 0.5);
575 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
576 (double) (x) / (double) (base_size.w - arrow_size.w), 1);
579 case ELM_CTXPOPUP_DIRECTION_UP:
580 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
581 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
584 if (x < (arrow_size.w * 0.5) + base_size.x)
586 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
587 x = base_size.w - arrow_size.w;
588 else x = x - base_size.x - (arrow_size.w * 0.5);
589 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
590 (double) (x) / (double) (base_size.w - arrow_size.w), 0);
599 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
603 wd = elm_widget_data_get(obj);
604 if (!wd || wd->visible) return;
608 case ELM_CTXPOPUP_DIRECTION_UP:
609 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
611 case ELM_CTXPOPUP_DIRECTION_LEFT:
612 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
614 case ELM_CTXPOPUP_DIRECTION_RIGHT:
615 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
617 case ELM_CTXPOPUP_DIRECTION_DOWN:
618 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
626 _sizing_eval(Evas_Object *obj)
630 Elm_Ctxpopup_Item *item;
631 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
632 Evas_Coord_Point box_size = { 0, 0 };
633 Evas_Coord_Point _box_size = { 0, 0 };
635 wd = elm_widget_data_get(obj);
636 if ((!wd) || (!wd->parent)) return;
639 EINA_LIST_FOREACH(wd->items, elist, item)
641 _item_sizing_eval(item);
642 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
645 if (_box_size.x > box_size.x)
646 box_size.x = _box_size.x;
647 if (_box_size.y != -1)
648 box_size.y += _box_size.y;
652 if (_box_size.x != -1)
653 box_size.x += _box_size.x;
654 if (_box_size.y > box_size.y)
655 box_size.y = _box_size.y;
661 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
662 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
666 wd->dir = _calc_base_geometry(obj, &rect);
667 _show_signal_emit(obj, wd->dir);
668 _update_arrow(obj, wd->dir);
669 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
671 //resize scroller according to final size.
673 evas_object_smart_calculate(wd->scr);
675 evas_object_move(wd->base, rect.x, rect.y);
676 evas_object_resize(wd->base, rect.w, rect.h);
680 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
681 Evas_Coord_Rectangle *rect)
683 Evas_Coord arrow_w, arrow_h;
685 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
689 case ELM_CTXPOPUP_DIRECTION_RIGHT:
692 case ELM_CTXPOPUP_DIRECTION_LEFT:
695 case ELM_CTXPOPUP_DIRECTION_DOWN:
698 case ELM_CTXPOPUP_DIRECTION_UP:
707 _del_pre_hook(Evas_Object *obj)
711 wd = elm_widget_data_get(obj);
714 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
715 _parent_resize, obj);
717 _hover_parent_callbacks_del(obj);
721 _del_hook(Evas_Object *obj)
725 wd = elm_widget_data_get(obj);
728 elm_ctxpopup_clear(obj);
729 evas_object_del(wd->arrow);
730 evas_object_del(wd->base);
735 _theme_hook(Evas_Object *obj)
739 Elm_Ctxpopup_Item *item;
741 wd = elm_widget_data_get(obj);
745 EINA_LIST_FOREACH(wd->items, elist, item)
747 if (item->label && item->icon)
748 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
749 "icon_text_style_item",
750 elm_widget_style_get(obj));
751 else if (item->label)
752 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
753 elm_widget_style_get(obj));
755 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
756 elm_widget_style_get(obj));
758 edje_object_part_text_set(item->base.view, "elm.text", item->label);
761 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
763 edje_object_message_signal_process(item->base.view);
766 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
767 elm_widget_style_get(obj));
768 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
769 elm_widget_style_get(obj));
770 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
771 elm_widget_style_get(obj));
775 if (!strncmp(elm_object_style_get(obj), "default",
777 elm_object_style_set(wd->scr, "ctxpopup");
779 elm_object_style_set(wd->scr, elm_object_style_get(obj));
782 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
786 _scroller_size_reset(wd);
792 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__,
793 Evas_Object *content)
795 ELM_CHECK_WIDTYPE(obj, widtype);
799 wd = elm_widget_data_get(obj);
800 if ((!wd) || (!content)) return;
802 if (wd->items) elm_ctxpopup_clear(obj);
803 if (wd->content) evas_object_del(wd->content);
805 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
808 elm_widget_sub_object_add(obj, content);
809 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
811 wd->content = content;
813 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
820 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
822 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
825 Evas_Object *content;
827 wd = elm_widget_data_get(obj);
828 if (!wd) return NULL;
830 content = wd->content;
831 if (!content) return NULL;
833 edje_object_part_unswallow(wd->base, content);
834 elm_widget_sub_object_del(obj, content);
835 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
836 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
839 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
846 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
848 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
850 Widget_Data *wd = elm_widget_data_get(obj);
851 if (!wd) return NULL;
856 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
857 const char *emission __UNUSED__, const char *source __UNUSED__)
859 evas_object_hide(data);
863 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
864 void *event_info __UNUSED__)
869 wd = elm_widget_data_get(data);
872 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
873 evas_object_resize(wd->bg, w, h);
874 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
876 if (!wd->visible) return;
882 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
883 void *event_info __UNUSED__)
887 wd = elm_widget_data_get(obj);
890 if ((!wd->items) && (!wd->content)) return;
892 wd->visible = EINA_TRUE;
894 evas_object_show(wd->bg);
895 evas_object_show(wd->base);
896 evas_object_show(wd->arrow);
898 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
899 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
903 elm_object_focus_set(obj, EINA_TRUE);
907 _hide(Evas_Object *obj)
909 Widget_Data *wd = elm_widget_data_get(obj);
913 evas_object_hide(wd->bg);
914 evas_object_hide(wd->arrow);
915 evas_object_hide(wd->base);
917 _scroller_size_reset(wd);
919 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
920 wd->visible = EINA_FALSE;
924 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
925 void *event_info __UNUSED__)
929 wd = elm_widget_data_get(obj);
930 if ((!wd) || (!wd->visible))
937 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
938 void *event_info __UNUSED__)
943 wd = elm_widget_data_get(data);
945 if (!wd->visible) return;
946 if (wd->finished) return;
948 evas_object_geometry_get(obj, 0, 0, &w, &h);
950 if (w != 0 && h != 0)
952 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
955 wd->finished = EINA_TRUE;
960 if (wd->max_sc_w < w)
962 if (wd->max_sc_h < h)
969 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
970 void *event_info __UNUSED__)
974 wd = elm_widget_data_get(obj);
979 evas_object_show(wd->arrow);
981 _scroller_size_reset(wd);
986 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
987 const char *emission __UNUSED__, const char *source __UNUSED__)
989 Elm_Ctxpopup_Item *item = data;
992 if (item->disabled) return;
995 item->func((void*) item->base.data, item->base.widget, data);
999 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1002 evas_object_del(item->icon);
1007 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
1008 edje_object_message_signal_process(item->base.view);
1012 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1014 if (!eina_stringshare_replace(&item->label, label))
1017 edje_object_part_text_set(item->base.view, "elm.text", label);
1018 edje_object_message_signal_process(item->base.view);
1022 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1026 wd = elm_widget_data_get(item->base.widget);
1029 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
1030 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
1031 elm_widget_style_get(item->base.widget));
1032 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
1033 _item_select_cb, item);
1034 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
1035 evas_object_show(item->base.view);
1039 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1040 void *event_info __UNUSED__)
1042 elm_object_content_unset(data);
1046 _list_del(Widget_Data *wd)
1048 if (!wd->scr) return;
1050 edje_object_part_unswallow(wd->base, wd->scr);
1051 evas_object_del(wd->scr);
1057 _list_new(Evas_Object *obj)
1060 wd = elm_widget_data_get(obj);
1064 wd->scr = elm_scroller_add(obj);
1065 elm_object_style_set(wd->scr, "ctxpopup");
1066 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1067 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1068 _scroller_resize, obj);
1069 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1072 wd->box = elm_box_add(obj);
1073 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1076 elm_scroller_content_set(wd->scr, wd->box);
1077 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1081 _remove_items(Widget_Data *wd)
1084 Elm_Ctxpopup_Item *item;
1086 if (!wd->items) return;
1088 EINA_LIST_FOREACH(wd->items, elist, item)
1091 eina_stringshare_del(item->label);
1093 evas_object_del(item->icon);
1094 wd->items = eina_list_remove(wd->items, item);
1102 elm_ctxpopup_add(Evas_Object *parent)
1107 Evas_Coord x, y, w, h;
1109 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1111 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1112 elm_widget_type_set(obj, "ctxpopup");
1113 elm_widget_sub_object_add(parent, obj);
1114 elm_widget_data_set(obj, wd);
1115 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1116 elm_widget_del_hook_set(obj, _del_hook);
1117 elm_widget_theme_hook_set(obj, _theme_hook);
1118 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1119 elm_widget_can_focus_set(obj, EINA_TRUE);
1120 elm_widget_event_hook_set(obj, _event_hook);
1121 elm_widget_content_set_hook_set(obj, _content_set_hook);
1122 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1123 elm_widget_content_get_hook_set(obj, _content_get_hook);
1125 wd->parent = parent;
1128 wd->bg = edje_object_add(e);
1129 elm_widget_sub_object_add(obj, wd->bg);
1130 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1131 evas_object_geometry_get(parent, &x, &y, &w, &h);
1132 evas_object_move(wd->bg, x, y);
1133 evas_object_resize(wd->bg, w, h);
1134 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1135 _bg_clicked_cb, obj);
1138 wd->base = edje_object_add(e);
1139 elm_widget_sub_object_add(obj, wd->base);
1140 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1143 wd->arrow = edje_object_add(e);
1144 elm_widget_sub_object_add(obj, wd->arrow);
1145 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1147 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1148 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1149 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1150 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1151 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1153 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1155 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1157 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1159 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1161 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1162 _ctxpopup_changed_size_hints, NULL);
1163 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1164 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1165 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1166 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1168 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1174 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1176 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1177 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1178 return ctxpopup_it->icon;
1182 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1184 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1187 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1189 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1192 _item_icon_set(ctxpopup_it, icon);
1193 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1197 _scroller_size_reset(wd);
1198 _sizing_eval(ctxpopup_it->base.widget);
1203 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1205 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1206 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1207 return ctxpopup_it->label;
1211 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1213 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1216 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1218 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1221 _item_label_set(ctxpopup_it, label);
1222 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1226 _scroller_size_reset(wd);
1227 _sizing_eval(ctxpopup_it->base.widget);
1232 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1234 ELM_CHECK_WIDTYPE(obj, widtype);
1238 wd = elm_widget_data_get(obj);
1241 _hover_parent_callbacks_del(obj);
1245 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1246 _hover_parent_del, obj);
1247 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1248 _hover_parent_move, obj);
1249 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1250 _hover_parent_resize, obj);
1253 wd->hover_parent = hover_parent;
1255 if (wd->visible) _sizing_eval(obj);
1259 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1261 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1265 wd = elm_widget_data_get(obj);
1266 if (!wd) return NULL;
1268 return wd->hover_parent;
1272 elm_ctxpopup_clear(Evas_Object * obj)
1274 ELM_CHECK_WIDTYPE(obj, widtype);
1276 Widget_Data *wd = elm_widget_data_get(obj);
1281 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1285 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1287 ELM_CHECK_WIDTYPE(obj, widtype);
1291 wd = elm_widget_data_get(obj);
1294 wd->horizontal = !!horizontal;
1296 if ((!wd->scr) && (!wd->box))
1301 elm_box_horizontal_set(wd->box, EINA_FALSE);
1302 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1306 elm_box_horizontal_set(wd->box, EINA_TRUE);
1307 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1310 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1317 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1319 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1323 wd = elm_widget_data_get(obj);
1324 if (!wd) return EINA_FALSE;
1326 return wd->horizontal;
1329 EAPI Elm_Object_Item *
1330 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1331 Evas_Object *icon, Evas_Smart_Cb func,
1334 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1337 Elm_Ctxpopup_Item *item;
1339 wd = elm_widget_data_get(obj);
1340 if (!wd) return NULL;
1342 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1343 if (!item) return NULL;
1345 //The first item is appended.
1347 evas_object_del(elm_object_content_unset(obj));
1353 item->base.data = data;
1356 _item_new(item, "icon_text_style_item");
1358 _item_new(item, "text_style_item");
1360 _item_new(item, "icon_style_item");
1362 _item_icon_set(item, icon);
1363 _item_label_set(item, label);
1364 elm_box_pack_end(wd->box, item->base.view);
1365 wd->items = eina_list_append(wd->items, item);
1366 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1370 _scroller_size_reset(wd);
1374 return ELM_CAST(item);
1378 elm_ctxpopup_item_del(Elm_Object_Item *it)
1380 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1383 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1385 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1388 if (ctxpopup_it->icon)
1389 evas_object_del(ctxpopup_it->icon);
1390 if (ctxpopup_it->base.view)
1391 evas_object_del(ctxpopup_it->base.view);
1393 eina_stringshare_del(ctxpopup_it->label);
1395 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1397 if (eina_list_count(wd->items) < 1)
1400 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1403 _sizing_eval(ctxpopup_it->base.widget);
1409 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1411 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1414 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1416 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1419 ctxpopup_it = ELM_CAST(it);
1421 if (disabled == ctxpopup_it->disabled)
1425 edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,disabled", "elm");
1427 edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,enabled", "elm");
1429 ctxpopup_it->disabled = !!disabled;
1433 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1435 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1436 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1437 return ctxpopup_it->disabled;
1441 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1443 elm_object_content_set(obj, content);
1447 elm_ctxpopup_content_unset(Evas_Object *obj)
1449 return elm_object_content_unset(obj);
1453 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1454 Elm_Ctxpopup_Direction first,
1455 Elm_Ctxpopup_Direction second,
1456 Elm_Ctxpopup_Direction third,
1457 Elm_Ctxpopup_Direction fourth)
1459 ELM_CHECK_WIDTYPE(obj, widtype);
1462 wd = elm_widget_data_get(obj);
1465 wd->dir_priority[0] = first;
1466 wd->dir_priority[1] = second;
1467 wd->dir_priority[2] = third;
1468 wd->dir_priority[3] = fourth;
1475 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1476 Elm_Ctxpopup_Direction *first,
1477 Elm_Ctxpopup_Direction *second,
1478 Elm_Ctxpopup_Direction *third,
1479 Elm_Ctxpopup_Direction *fourth)
1481 ELM_CHECK_WIDTYPE(obj, widtype);
1484 wd = elm_widget_data_get(obj);
1487 if (first) *first = wd->dir_priority[0];
1488 if (second) *second = wd->dir_priority[1];
1489 if (third) *third = wd->dir_priority[2];
1490 if (fourth) *fourth = wd->dir_priority[3];
1493 EAPI Elm_Ctxpopup_Direction
1494 elm_ctxpopup_direction_get(const Evas_Object *obj)
1496 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1499 wd = elm_widget_data_get(obj);
1500 if (!wd) return ELM_CTXPOPUP_DIRECTION_DONT_KNOW;