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
26 Elm_Ctxpopup_Direction dir;
27 Elm_Ctxpopup_Direction dir_priority[4];
28 Evas_Coord max_sc_w, max_sc_h;
29 Eina_Bool horizontal:1;
34 static const char *widtype = NULL;
36 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
37 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
38 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
39 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
40 static void _scroller_size_reset(Widget_Data *wd);
41 static void _on_focus_hook(void *data, Evas_Object *obj);
42 static Eina_Bool _event_hook(Evas_Object *obj,
44 Evas_Callback_Type type,
46 static void _parent_cut_off(Evas_Object *obj);
47 static void _parent_resize(void *data,
51 static void _parent_move(void *data,
55 static void _parent_del(void *data,
59 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
60 static void _adjust_pos_x(Evas_Coord_Point *pos,
61 Evas_Coord_Point *base_size,
62 Evas_Coord_Rectangle *hover_area);
63 static void _adjust_pos_y(Evas_Coord_Point *pos,
64 Evas_Coord_Point *base_size,
65 Evas_Coord_Rectangle *hover_area);
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 _content_set_hook(Evas_Object *obj,
78 Evas_Object *content);
79 static Evas_Object * _content_unset_hook(Evas_Object *obj,
81 static Evas_Object * _content_get_hook(const Evas_Object *obj,
83 static void _bg_clicked_cb(void *data, Evas_Object *obj,
86 static void _ctxpopup_show(void *data,
90 static void _hide(Evas_Object *obj);
91 static void _ctxpopup_hide(void *data,
95 static void _scroller_resize(void *data,
99 static void _ctxpopup_move(void *data,
103 static void _item_select_cb(void *data, Evas_Object *obj,
104 const char *emission,
106 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
107 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
108 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
109 static void _content_del(void *data,
113 static void _list_del(Widget_Data *wd);
114 static void _list_new(Evas_Object *obj);
115 static void _remove_items(Widget_Data * wd);
117 static const char SIG_DISMISSED[] = "dismissed";
119 static const Evas_Smart_Cb_Description _signals[] = {
125 _freeze_on(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;
131 elm_object_scroll_freeze_push(wd->scr);
135 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
136 void *event_info __UNUSED__)
138 Widget_Data *wd = elm_widget_data_get(obj);
140 if ((!wd) || (!wd->scr)) return;
141 elm_object_scroll_freeze_pop(wd->scr);
145 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
147 Widget_Data *wd = elm_widget_data_get(obj);
149 if ((!wd) || (!wd->scr)) return;
150 elm_object_scroll_hold_push(wd->scr);
154 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
156 Widget_Data *wd = elm_widget_data_get(obj);
158 if ((!wd) || (!wd->scr)) return;
159 elm_object_scroll_hold_pop(wd->scr);
163 _scroller_size_reset(Widget_Data *wd)
165 wd->finished = EINA_FALSE;
171 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
173 Widget_Data *wd = elm_widget_data_get(obj);
176 if (elm_widget_focus_get(obj))
187 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
189 Evas_Event_Key_Down *ev;
192 if (type != EVAS_CALLBACK_KEY_DOWN)
194 wd = elm_widget_data_get(obj);
195 if (!wd) return EINA_FALSE;
198 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
199 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
201 evas_object_hide(obj);
202 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
207 _parent_cut_off(Evas_Object *obj)
209 Widget_Data *wd = elm_widget_data_get(obj);
213 evas_object_event_callback_del_full(wd->parent,
217 evas_object_event_callback_del_full(wd->parent,
221 evas_object_event_callback_del_full(wd->parent,
222 EVAS_CALLBACK_RESIZE,
226 elm_widget_sub_object_del(wd->parent, obj);
230 _parent_resize(void *data,
232 Evas_Object *obj __UNUSED__,
233 void *event_info __UNUSED__)
235 Widget_Data *wd = elm_widget_data_get(data);
238 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
244 _parent_move(void *data,
246 Evas_Object *obj __UNUSED__,
247 void *event_info __UNUSED__)
249 Widget_Data *wd = elm_widget_data_get(data);
253 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
257 _scroller_size_reset(wd);
263 _parent_del(void *data,
265 Evas_Object *obj __UNUSED__,
266 void *event_info __UNUSED__)
268 evas_object_del(data);
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;
320 static Elm_Ctxpopup_Direction
321 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
324 Evas_Coord_Point pos = {0, 0};
325 Evas_Coord_Point base_size;
326 Evas_Coord_Point max_size;
327 Evas_Coord_Point min_size;
328 Evas_Coord_Rectangle hover_area;
329 Evas_Coord_Point arrow_size;
330 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
331 Evas_Coord_Point temp;
334 wd = elm_widget_data_get(obj);
336 if ((!wd) || (!rect))
337 return ELM_CTXPOPUP_DIRECTION_DOWN;
339 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
340 &arrow_size.x, &arrow_size.y);
341 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
343 //Initialize Area Rectangle.
344 evas_object_geometry_get(wd->parent,
350 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
353 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
354 evas_object_smart_calculate(wd->base);
357 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
359 if ((max_size.y > 0) && (base_size.y > max_size.y))
360 base_size.y = max_size.y;
362 if ((max_size.x > 0) && (base_size.x > max_size.x))
363 base_size.x = max_size.x;
366 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
368 if ((min_size.y > 0) && (base_size.y < min_size.y))
369 base_size.y = min_size.y;
371 if ((min_size.x > 0) && (base_size.x < min_size.x))
372 base_size.x = min_size.x;
374 //Check the Which direction is available.
375 //If find a avaialble direction, it adjusts position and size.
376 for (idx = 0; idx < 4; idx++)
378 switch (wd->dir_priority[idx])
380 case ELM_CTXPOPUP_DIRECTION_DONT_KNOW:
381 case ELM_CTXPOPUP_DIRECTION_UP:
382 temp.y = (pos.y - base_size.y);
383 if ((temp.y - arrow_size.y) < hover_area.y)
385 _adjust_pos_x(&pos, &base_size, &hover_area);
386 pos.y -= base_size.y;
387 dir = ELM_CTXPOPUP_DIRECTION_UP;
389 case ELM_CTXPOPUP_DIRECTION_LEFT:
390 temp.x = (pos.x - base_size.x);
391 if ((temp.x - arrow_size.x) < hover_area.x)
393 _adjust_pos_y(&pos, &base_size, &hover_area);
394 pos.x -= base_size.x;
395 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
397 case ELM_CTXPOPUP_DIRECTION_RIGHT:
398 temp.x = (pos.x + base_size.x);
399 if ((temp.x + arrow_size.x) >
400 (hover_area.x + hover_area.w))
402 _adjust_pos_y(&pos, &base_size, &hover_area);
403 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
405 case ELM_CTXPOPUP_DIRECTION_DOWN:
406 temp.y = (pos.y + base_size.y);
407 if ((temp.y + arrow_size.y) >
408 (hover_area.y + hover_area.h))
410 _adjust_pos_x(&pos, &base_size, &hover_area);
411 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
419 //In this case, all directions are invalid because of lack of space.
422 Evas_Coord length[2];
426 length[0] = pos.y - hover_area.y;
427 length[1] = (hover_area.y + hover_area.h) - pos.y;
429 // ELM_CTXPOPUP_DIRECTION_UP
430 if (length[0] > length[1])
432 _adjust_pos_x(&pos, &base_size, &hover_area);
433 pos.y -= base_size.y;
434 dir = ELM_CTXPOPUP_DIRECTION_UP;
435 if (pos.y < (hover_area.y + arrow_size.y))
437 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
438 pos.y = hover_area.y + arrow_size.y;
441 //ELM_CTXPOPUP_DIRECTION_DOWN
444 _adjust_pos_x(&pos, &base_size, &hover_area);
445 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
446 if ((pos.y + arrow_size.y + base_size.y) >
447 (hover_area.y + hover_area.h))
449 ((pos.y + arrow_size.y + base_size.y) -
450 (hover_area.y + hover_area.h));
455 length[0] = pos.x - hover_area.x;
456 length[1] = (hover_area.x + hover_area.w) - pos.x;
458 //ELM_CTXPOPUP_DIRECTION_LEFT
459 if (length[0] > length[1])
461 _adjust_pos_y(&pos, &base_size, &hover_area);
462 pos.x -= base_size.x;
463 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
464 if (pos.x < (hover_area.x + arrow_size.x))
466 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
467 pos.x = hover_area.x + arrow_size.x;
470 //ELM_CTXPOPUP_DIRECTION_RIGHT
473 _adjust_pos_y(&pos, &base_size, &hover_area);
474 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
475 if (pos.x + (arrow_size.x + base_size.x) >
476 hover_area.x + hover_area.w)
478 ((pos.x + arrow_size.x + base_size.x) -
479 (hover_area.x + hover_area.w));
484 //Final position and size.
487 rect->w = base_size.x;
488 rect->h = base_size.y;
494 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
497 Evas_Coord_Rectangle arrow_size;
498 Evas_Coord_Rectangle base_size;
501 wd = elm_widget_data_get(obj);
504 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
505 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
507 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
508 &base_size.w, &base_size.h);
512 case ELM_CTXPOPUP_DIRECTION_RIGHT:
513 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
514 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
517 if (y < ((arrow_size.h * 0.5) + base_size.y))
519 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
520 y = base_size.h - arrow_size.h;
522 y = y - base_size.y - (arrow_size.h * 0.5);
523 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
524 (double) (y) / (double) (base_size.h - arrow_size.h));
527 case ELM_CTXPOPUP_DIRECTION_LEFT:
528 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
529 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
532 if (y < (arrow_size.h * 0.5) + base_size.y)
534 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
535 y = base_size.h - arrow_size.h;
536 else y = y - base_size.y - (arrow_size.h * 0.5);
537 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
538 (double) (y) / (double) (base_size.h - arrow_size.h));
541 case ELM_CTXPOPUP_DIRECTION_DOWN:
542 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
543 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
546 if (x < (arrow_size.w * 0.5) + base_size.x)
548 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
549 x = base_size.w - arrow_size.w;
551 x = x - base_size.x - (arrow_size.w * 0.5);
552 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
553 (double) (x) / (double) (base_size.w - arrow_size.w), 1);
556 case ELM_CTXPOPUP_DIRECTION_UP:
557 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
558 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
561 if (x < (arrow_size.w * 0.5) + base_size.x)
563 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
564 x = base_size.w - arrow_size.w;
565 else x = x - base_size.x - (arrow_size.w * 0.5);
566 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
567 (double) (x) / (double) (base_size.w - arrow_size.w), 0);
576 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
580 wd = elm_widget_data_get(obj);
581 if (!wd || wd->visible) return;
585 case ELM_CTXPOPUP_DIRECTION_UP:
586 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
588 case ELM_CTXPOPUP_DIRECTION_LEFT:
589 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
591 case ELM_CTXPOPUP_DIRECTION_RIGHT:
592 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
594 case ELM_CTXPOPUP_DIRECTION_DOWN:
595 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
603 _sizing_eval(Evas_Object *obj)
607 Elm_Ctxpopup_Item *item;
608 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
609 Evas_Coord_Point box_size = { 0, 0 };
610 Evas_Coord_Point _box_size = { 0, 0 };
612 wd = elm_widget_data_get(obj);
616 EINA_LIST_FOREACH(wd->items, elist, item)
618 _item_sizing_eval(item);
619 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
622 if (_box_size.x > box_size.x)
623 box_size.x = _box_size.x;
624 if (_box_size.y != -1)
625 box_size.y += _box_size.y;
629 if (_box_size.x != -1)
630 box_size.x += _box_size.x;
631 if (_box_size.y > box_size.y)
632 box_size.y = _box_size.y;
638 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
639 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
643 wd->dir = _calc_base_geometry(obj, &rect);
644 _show_signal_emit(obj, wd->dir);
645 _update_arrow(obj, wd->dir);
646 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
648 //resize scroller according to final size.
650 evas_object_smart_calculate(wd->scr);
652 evas_object_move(wd->base, rect.x, rect.y);
653 evas_object_resize(wd->base, rect.w, rect.h);
657 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
658 Evas_Coord_Rectangle *rect)
660 Evas_Coord arrow_w, arrow_h;
662 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
666 case ELM_CTXPOPUP_DIRECTION_RIGHT:
669 case ELM_CTXPOPUP_DIRECTION_LEFT:
672 case ELM_CTXPOPUP_DIRECTION_DOWN:
675 case ELM_CTXPOPUP_DIRECTION_UP:
684 _del_pre_hook(Evas_Object *obj)
688 wd = elm_widget_data_get(obj);
691 _parent_cut_off(obj);
695 _del_hook(Evas_Object *obj)
699 wd = elm_widget_data_get(obj);
702 elm_ctxpopup_clear(obj);
703 evas_object_del(wd->arrow);
704 evas_object_del(wd->base);
709 _theme_hook(Evas_Object *obj)
713 Elm_Ctxpopup_Item *item;
715 wd = elm_widget_data_get(obj);
719 EINA_LIST_FOREACH(wd->items, elist, item)
721 if (item->label && item->icon)
722 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
723 "icon_text_style_item",
724 elm_widget_style_get(obj));
725 else if (item->label)
726 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
727 elm_widget_style_get(obj));
729 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
730 elm_widget_style_get(obj));
732 edje_object_part_text_set(item->base.view, "elm.text", item->label);
735 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
737 edje_object_message_signal_process(item->base.view);
740 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
741 elm_widget_style_get(obj));
742 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
743 elm_widget_style_get(obj));
744 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
745 elm_widget_style_get(obj));
749 if (!strncmp(elm_object_style_get(obj), "default",
751 elm_object_style_set(wd->scr, "ctxpopup");
753 elm_object_style_set(wd->scr, elm_object_style_get(obj));
756 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
760 _scroller_size_reset(wd);
766 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__,
767 Evas_Object *content)
769 ELM_CHECK_WIDTYPE(obj, widtype);
773 wd = elm_widget_data_get(obj);
774 if ((!wd) || (!content)) return;
776 if (wd->items) elm_ctxpopup_clear(obj);
777 if (wd->content) evas_object_del(wd->content);
779 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
782 elm_widget_sub_object_add(obj, content);
783 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
785 wd->content = content;
787 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
794 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
796 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
799 Evas_Object *content;
801 wd = elm_widget_data_get(obj);
802 if (!wd) return NULL;
804 content = wd->content;
805 if (!content) return NULL;
807 edje_object_part_unswallow(wd->base, content);
808 elm_widget_sub_object_del(obj, content);
809 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
810 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
813 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
820 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
822 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
824 Widget_Data *wd = elm_widget_data_get(obj);
825 if (!wd) return NULL;
830 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
831 const char *emission __UNUSED__, const char *source __UNUSED__)
833 evas_object_hide(data);
837 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
838 void *event_info __UNUSED__)
842 wd = elm_widget_data_get(obj);
845 if ((!wd->items) && (!wd->content)) return;
847 wd->visible = EINA_TRUE;
849 evas_object_show(wd->bg);
850 evas_object_show(wd->base);
851 evas_object_show(wd->arrow);
853 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
854 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
858 elm_object_focus_set(obj, EINA_TRUE);
862 _hide(Evas_Object *obj)
864 Widget_Data *wd = elm_widget_data_get(obj);
866 if ((!wd) || (!wd->visible)) return;
868 evas_object_hide(wd->bg);
869 evas_object_hide(wd->arrow);
870 evas_object_hide(wd->base);
872 _scroller_size_reset(wd);
874 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
875 wd->visible = EINA_FALSE;
879 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
880 void *event_info __UNUSED__)
886 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
887 void *event_info __UNUSED__)
892 wd = elm_widget_data_get(data);
894 if (!wd->visible) return;
895 if (wd->finished) return;
897 evas_object_geometry_get(obj, 0, 0, &w, &h);
899 if (w != 0 && h != 0)
901 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
904 wd->finished = EINA_TRUE;
909 if (wd->max_sc_w < w)
911 if (wd->max_sc_h < h)
918 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
919 void *event_info __UNUSED__)
923 wd = elm_widget_data_get(obj);
928 evas_object_show(wd->arrow);
930 _scroller_size_reset(wd);
935 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
936 const char *emission __UNUSED__, const char *source __UNUSED__)
938 Elm_Ctxpopup_Item *item = data;
941 if (item->disabled) return;
944 item->func((void*) item->base.data, item->base.widget, data);
948 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
951 evas_object_del(item->icon);
956 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
957 edje_object_message_signal_process(item->base.view);
961 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
963 if (!eina_stringshare_replace(&item->label, label))
966 edje_object_part_text_set(item->base.view, "elm.text", label);
967 edje_object_message_signal_process(item->base.view);
971 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
975 wd = elm_widget_data_get(item->base.widget);
978 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
979 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
980 elm_widget_style_get(item->base.widget));
981 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
982 _item_select_cb, item);
983 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
984 evas_object_show(item->base.view);
988 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
989 void *event_info __UNUSED__)
991 elm_object_content_unset(data);
995 _list_del(Widget_Data *wd)
997 if (!wd->scr) return;
999 edje_object_part_unswallow(wd->base, wd->scr);
1000 evas_object_del(wd->scr);
1006 _list_new(Evas_Object *obj)
1009 wd = elm_widget_data_get(obj);
1013 wd->scr = elm_scroller_add(obj);
1014 elm_object_style_set(wd->scr, "ctxpopup");
1015 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1016 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1017 _scroller_resize, obj);
1018 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1021 wd->box = elm_box_add(obj);
1022 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1025 elm_scroller_content_set(wd->scr, wd->box);
1026 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1030 _remove_items(Widget_Data *wd)
1033 Elm_Ctxpopup_Item *item;
1035 if (!wd->items) return;
1037 EINA_LIST_FOREACH(wd->items, elist, item)
1040 eina_stringshare_del(item->label);
1042 evas_object_del(item->icon);
1043 wd->items = eina_list_remove(wd->items, item);
1051 elm_ctxpopup_add(Evas_Object *parent)
1057 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1059 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1060 elm_widget_type_set(obj, "ctxpopup");
1061 elm_widget_data_set(obj, wd);
1062 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1063 elm_widget_del_hook_set(obj, _del_hook);
1064 elm_widget_theme_hook_set(obj, _theme_hook);
1065 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1066 elm_widget_can_focus_set(obj, EINA_TRUE);
1067 elm_widget_event_hook_set(obj, _event_hook);
1068 elm_widget_content_set_hook_set(obj, _content_set_hook);
1069 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1070 elm_widget_content_get_hook_set(obj, _content_get_hook);
1073 wd->bg = edje_object_add(e);
1074 elm_widget_sub_object_add(obj, wd->bg);
1075 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1076 edje_object_signal_callback_add(wd->bg,
1082 wd->base = edje_object_add(e);
1083 elm_widget_sub_object_add(obj, wd->base);
1084 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1087 wd->arrow = edje_object_add(e);
1088 elm_widget_sub_object_add(obj, wd->arrow);
1089 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1091 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1092 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1093 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1094 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1095 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
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_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1104 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1105 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1106 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1108 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1110 //default parent is to be hover parent
1111 elm_ctxpopup_hover_parent_set(obj, parent);
1117 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1119 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1120 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1121 return ctxpopup_it->icon;
1125 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1127 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1130 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1132 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1135 _item_icon_set(ctxpopup_it, icon);
1136 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1140 _scroller_size_reset(wd);
1141 _sizing_eval(ctxpopup_it->base.widget);
1146 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1148 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1149 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1150 return ctxpopup_it->label;
1154 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1156 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1159 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1161 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1164 _item_label_set(ctxpopup_it, label);
1165 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1169 _scroller_size_reset(wd);
1170 _sizing_eval(ctxpopup_it->base.widget);
1175 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1177 ELM_CHECK_WIDTYPE(obj, widtype);
1180 Evas_Coord x, y, w, h;
1182 wd = elm_widget_data_get(obj);
1183 if ((!wd) || (!parent)) return;
1185 _parent_cut_off(obj);
1189 evas_object_event_callback_add(parent,
1193 evas_object_event_callback_add(parent,
1197 evas_object_event_callback_add(parent,
1198 EVAS_CALLBACK_RESIZE,
1203 elm_widget_sub_object_add(parent, obj);
1204 wd->parent = parent;
1207 evas_object_geometry_get(parent, &x, &y, &w, &h);
1208 evas_object_move(wd->bg, x, y);
1209 evas_object_resize(wd->bg, w, h);
1211 if (wd->visible) _sizing_eval(obj);
1215 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1217 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1221 wd = elm_widget_data_get(obj);
1222 if (!wd) return NULL;
1228 elm_ctxpopup_clear(Evas_Object * obj)
1230 ELM_CHECK_WIDTYPE(obj, widtype);
1232 Widget_Data *wd = elm_widget_data_get(obj);
1237 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1241 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1243 ELM_CHECK_WIDTYPE(obj, widtype);
1247 wd = elm_widget_data_get(obj);
1250 wd->horizontal = !!horizontal;
1252 if ((!wd->scr) && (!wd->box))
1257 elm_box_horizontal_set(wd->box, EINA_FALSE);
1258 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1262 elm_box_horizontal_set(wd->box, EINA_TRUE);
1263 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1266 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1273 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1275 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1279 wd = elm_widget_data_get(obj);
1280 if (!wd) return EINA_FALSE;
1282 return wd->horizontal;
1285 EAPI Elm_Object_Item *
1286 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1287 Evas_Object *icon, Evas_Smart_Cb func,
1290 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1293 Elm_Ctxpopup_Item *item;
1295 wd = elm_widget_data_get(obj);
1296 if (!wd) return NULL;
1298 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1299 if (!item) return NULL;
1301 //The first item is appended.
1303 evas_object_del(elm_object_content_unset(obj));
1309 item->base.data = data;
1312 _item_new(item, "icon_text_style_item");
1314 _item_new(item, "text_style_item");
1316 _item_new(item, "icon_style_item");
1318 _item_icon_set(item, icon);
1319 _item_label_set(item, label);
1320 elm_box_pack_end(wd->box, item->base.view);
1321 wd->items = eina_list_append(wd->items, item);
1322 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1326 _scroller_size_reset(wd);
1330 return ELM_CAST(item);
1334 elm_ctxpopup_item_del(Elm_Object_Item *it)
1336 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1339 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1341 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1344 if (ctxpopup_it->icon)
1345 evas_object_del(ctxpopup_it->icon);
1346 if (ctxpopup_it->base.view)
1347 evas_object_del(ctxpopup_it->base.view);
1349 eina_stringshare_del(ctxpopup_it->label);
1351 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1353 if (eina_list_count(wd->items) < 1)
1356 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1359 _sizing_eval(ctxpopup_it->base.widget);
1365 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1367 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1370 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1372 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1375 ctxpopup_it = ELM_CAST(it);
1377 if (disabled == ctxpopup_it->disabled)
1381 edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,disabled", "elm");
1383 edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,enabled", "elm");
1385 ctxpopup_it->disabled = !!disabled;
1389 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1391 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1392 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1393 return ctxpopup_it->disabled;
1397 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1399 elm_object_content_set(obj, content);
1403 elm_ctxpopup_content_unset(Evas_Object *obj)
1405 return elm_object_content_unset(obj);
1409 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1410 Elm_Ctxpopup_Direction first,
1411 Elm_Ctxpopup_Direction second,
1412 Elm_Ctxpopup_Direction third,
1413 Elm_Ctxpopup_Direction fourth)
1415 ELM_CHECK_WIDTYPE(obj, widtype);
1418 wd = elm_widget_data_get(obj);
1421 wd->dir_priority[0] = first;
1422 wd->dir_priority[1] = second;
1423 wd->dir_priority[2] = third;
1424 wd->dir_priority[3] = fourth;
1431 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1432 Elm_Ctxpopup_Direction *first,
1433 Elm_Ctxpopup_Direction *second,
1434 Elm_Ctxpopup_Direction *third,
1435 Elm_Ctxpopup_Direction *fourth)
1437 ELM_CHECK_WIDTYPE(obj, widtype);
1440 wd = elm_widget_data_get(obj);
1443 if (first) *first = wd->dir_priority[0];
1444 if (second) *second = wd->dir_priority[1];
1445 if (third) *third = wd->dir_priority[2];
1446 if (fourth) *fourth = wd->dir_priority[3];
1449 EAPI Elm_Ctxpopup_Direction
1450 elm_ctxpopup_direction_get(const Evas_Object *obj)
1452 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1455 wd = elm_widget_data_get(obj);
1456 if (!wd) return ELM_CTXPOPUP_DIRECTION_DONT_KNOW;