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 Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
65 Evas_Coord_Rectangle *rect);
66 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
67 static void _sizing_eval(Evas_Object *obj);
68 static void _shift_base_by_arrow(Evas_Object *arrow,
69 Elm_Ctxpopup_Direction dir,
70 Evas_Coord_Rectangle *rect);
71 static void _del_pre_hook(Evas_Object *obj);
72 static void _del_hook(Evas_Object *obj);
73 static void _theme_hook(Evas_Object *obj);
74 static void _content_set_hook(Evas_Object *obj,
76 Evas_Object *content);
77 static Evas_Object * _content_unset_hook(Evas_Object *obj,
79 static Evas_Object * _content_get_hook(const Evas_Object *obj,
81 static void _bg_clicked_cb(void *data, Evas_Object *obj,
84 static void _parent_resize(void *data, Evas *e, 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 _hover_parent_callbacks_del(Evas_Object *obj)
209 Widget_Data *wd = elm_widget_data_get(obj);
211 if ((!wd) || (!wd->hover_parent))
214 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
215 _hover_parent_del, obj);
216 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
217 _hover_parent_move, obj);
218 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
219 _hover_parent_resize, obj);
223 _hover_parent_resize(void *data, Evas *e __UNUSED__,
224 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
226 Widget_Data *wd = elm_widget_data_get(data);
230 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
234 _scroller_size_reset(wd);
240 _hover_parent_move(void *data, Evas *e __UNUSED__,
241 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
243 Widget_Data *wd = elm_widget_data_get(data);
247 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
251 _scroller_size_reset(wd);
257 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
258 void *event_info __UNUSED__)
260 Widget_Data *wd = elm_widget_data_get(data);
264 wd->hover_parent = NULL;
268 _item_sizing_eval(Elm_Ctxpopup_Item *item)
270 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
274 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
276 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
277 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
281 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
282 Evas_Coord_Rectangle *hover_area)
284 pos->x -= (base_size->x / 2);
286 if (pos->x < hover_area->x)
287 pos->x = hover_area->x;
288 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
289 pos->x = (hover_area->x + hover_area->w) - base_size->x;
291 if (base_size->x > hover_area->w)
292 base_size->x -= (base_size->x - hover_area->w);
294 if (pos->x < hover_area->x)
295 pos->x = hover_area->x;
299 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
300 Evas_Coord_Rectangle *hover_area)
302 pos->y -= (base_size->y / 2);
304 if (pos->y < hover_area->y)
305 pos->y = hover_area->y;
306 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
307 pos->y = hover_area->y + hover_area->h - base_size->y;
309 if (base_size->y > hover_area->h)
310 base_size->y -= (base_size->y - hover_area->h);
312 if (pos->y < hover_area->y)
313 pos->y = hover_area->y;
316 static Elm_Ctxpopup_Direction
317 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
320 Evas_Coord_Point pos = {0, 0};
321 Evas_Coord_Point base_size;
322 Evas_Coord_Point max_size;
323 Evas_Coord_Point min_size;
324 Evas_Coord_Rectangle hover_area;
325 Evas_Coord_Rectangle parent_size;
326 Evas_Coord_Point arrow_size;
327 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
328 Evas_Coord_Point temp;
331 wd = elm_widget_data_get(obj);
333 if ((!wd) || (!rect))
334 return ELM_CTXPOPUP_DIRECTION_DOWN;
336 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
337 &arrow_size.x, &arrow_size.y);
338 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
340 //Initialize Area Rectangle.
341 if (wd->hover_parent)
342 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
343 &hover_area.w, &hover_area.h);
346 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
347 &parent_size.w, &parent_size.h);
348 hover_area.x = parent_size.x;
349 hover_area.y = parent_size.y;
350 hover_area.w = parent_size.w;
351 hover_area.h = parent_size.h;
354 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
357 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
358 evas_object_smart_calculate(wd->base);
361 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
363 if ((max_size.y > 0) && (base_size.y > max_size.y))
364 base_size.y = max_size.y;
366 if ((max_size.x > 0) && (base_size.x > max_size.x))
367 base_size.x = max_size.x;
370 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
372 if ((min_size.y > 0) && (base_size.y < min_size.y))
373 base_size.y = min_size.y;
375 if ((min_size.x > 0) && (base_size.x < min_size.x))
376 base_size.x = min_size.x;
378 //Check the Which direction is available.
379 //If find a avaialble direction, it adjusts position and size.
380 for (idx = 0; idx < 4; idx++)
382 switch (wd->dir_priority[idx])
384 case ELM_CTXPOPUP_DIRECTION_DONT_KNOW:
385 case ELM_CTXPOPUP_DIRECTION_UP:
386 temp.y = (pos.y - base_size.y);
387 if ((temp.y - arrow_size.y) < hover_area.y)
389 _adjust_pos_x(&pos, &base_size, &hover_area);
390 pos.y -= base_size.y;
391 dir = ELM_CTXPOPUP_DIRECTION_UP;
393 case ELM_CTXPOPUP_DIRECTION_LEFT:
394 temp.x = (pos.x - base_size.x);
395 if ((temp.x - arrow_size.x) < hover_area.x)
397 _adjust_pos_y(&pos, &base_size, &hover_area);
398 pos.x -= base_size.x;
399 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
401 case ELM_CTXPOPUP_DIRECTION_RIGHT:
402 temp.x = (pos.x + base_size.x);
403 if ((temp.x + arrow_size.x) >
404 (hover_area.x + hover_area.w))
406 _adjust_pos_y(&pos, &base_size, &hover_area);
407 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
409 case ELM_CTXPOPUP_DIRECTION_DOWN:
410 temp.y = (pos.y + base_size.y);
411 if ((temp.y + arrow_size.y) >
412 (hover_area.y + hover_area.h))
414 _adjust_pos_x(&pos, &base_size, &hover_area);
415 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
423 //In this case, all directions are invalid because of lack of space.
426 Evas_Coord length[2];
430 length[0] = pos.y - hover_area.y;
431 length[1] = (hover_area.y + hover_area.h) - pos.y;
433 // ELM_CTXPOPUP_DIRECTION_UP
434 if (length[0] > length[1])
436 _adjust_pos_x(&pos, &base_size, &hover_area);
437 pos.y -= base_size.y;
438 dir = ELM_CTXPOPUP_DIRECTION_UP;
439 if (pos.y < (hover_area.y + arrow_size.y))
441 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
442 pos.y = hover_area.y + arrow_size.y;
445 //ELM_CTXPOPUP_DIRECTION_DOWN
448 _adjust_pos_x(&pos, &base_size, &hover_area);
449 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
450 if ((pos.y + arrow_size.y + base_size.y) >
451 (hover_area.y + hover_area.h))
453 ((pos.y + arrow_size.y + base_size.y) -
454 (hover_area.y + hover_area.h));
459 length[0] = pos.x - hover_area.x;
460 length[1] = (hover_area.x + hover_area.w) - pos.x;
462 //ELM_CTXPOPUP_DIRECTION_LEFT
463 if (length[0] > length[1])
465 _adjust_pos_y(&pos, &base_size, &hover_area);
466 pos.x -= base_size.x;
467 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
468 if (pos.x < (hover_area.x + arrow_size.x))
470 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
471 pos.x = hover_area.x + arrow_size.x;
474 //ELM_CTXPOPUP_DIRECTION_RIGHT
477 _adjust_pos_y(&pos, &base_size, &hover_area);
478 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
479 if (pos.x + (arrow_size.x + base_size.x) >
480 hover_area.x + hover_area.w)
482 ((pos.x + arrow_size.x + base_size.x) -
483 (hover_area.x + hover_area.w));
488 //Final position and size.
491 rect->w = base_size.x;
492 rect->h = base_size.y;
498 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
501 Evas_Coord_Rectangle arrow_size;
502 Evas_Coord_Rectangle base_size;
505 wd = elm_widget_data_get(obj);
508 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
509 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
511 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
512 &base_size.w, &base_size.h);
516 case ELM_CTXPOPUP_DIRECTION_RIGHT:
517 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
518 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
521 if (y < ((arrow_size.h * 0.5) + base_size.y))
523 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
524 y = base_size.h - arrow_size.h;
526 y = y - base_size.y - (arrow_size.h * 0.5);
527 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
528 (double) (y) / (double) (base_size.h - arrow_size.h));
531 case ELM_CTXPOPUP_DIRECTION_LEFT:
532 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
533 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
536 if (y < (arrow_size.h * 0.5) + base_size.y)
538 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
539 y = base_size.h - arrow_size.h;
540 else y = y - base_size.y - (arrow_size.h * 0.5);
541 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
542 (double) (y) / (double) (base_size.h - arrow_size.h));
545 case ELM_CTXPOPUP_DIRECTION_DOWN:
546 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
547 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
550 if (x < (arrow_size.w * 0.5) + base_size.x)
552 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
553 x = base_size.w - arrow_size.w;
555 x = x - base_size.x - (arrow_size.w * 0.5);
556 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
557 (double) (x) / (double) (base_size.w - arrow_size.w), 1);
560 case ELM_CTXPOPUP_DIRECTION_UP:
561 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
562 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
565 if (x < (arrow_size.w * 0.5) + base_size.x)
567 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
568 x = base_size.w - arrow_size.w;
569 else x = x - base_size.x - (arrow_size.w * 0.5);
570 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
571 (double) (x) / (double) (base_size.w - arrow_size.w), 0);
580 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
584 wd = elm_widget_data_get(obj);
585 if (!wd || wd->visible) return;
589 case ELM_CTXPOPUP_DIRECTION_UP:
590 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
592 case ELM_CTXPOPUP_DIRECTION_LEFT:
593 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
595 case ELM_CTXPOPUP_DIRECTION_RIGHT:
596 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
598 case ELM_CTXPOPUP_DIRECTION_DOWN:
599 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
607 _sizing_eval(Evas_Object *obj)
611 Elm_Ctxpopup_Item *item;
612 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
613 Evas_Coord_Point box_size = { 0, 0 };
614 Evas_Coord_Point _box_size = { 0, 0 };
616 wd = elm_widget_data_get(obj);
617 if ((!wd) || (!wd->parent)) return;
620 EINA_LIST_FOREACH(wd->items, elist, item)
622 _item_sizing_eval(item);
623 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
626 if (_box_size.x > box_size.x)
627 box_size.x = _box_size.x;
628 if (_box_size.y != -1)
629 box_size.y += _box_size.y;
633 if (_box_size.x != -1)
634 box_size.x += _box_size.x;
635 if (_box_size.y > box_size.y)
636 box_size.y = _box_size.y;
642 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
643 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
647 wd->dir = _calc_base_geometry(obj, &rect);
648 _show_signal_emit(obj, wd->dir);
649 _update_arrow(obj, wd->dir);
650 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
652 //resize scroller according to final size.
654 evas_object_smart_calculate(wd->scr);
656 evas_object_move(wd->base, rect.x, rect.y);
657 evas_object_resize(wd->base, rect.w, rect.h);
661 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
662 Evas_Coord_Rectangle *rect)
664 Evas_Coord arrow_w, arrow_h;
666 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
670 case ELM_CTXPOPUP_DIRECTION_RIGHT:
673 case ELM_CTXPOPUP_DIRECTION_LEFT:
676 case ELM_CTXPOPUP_DIRECTION_DOWN:
679 case ELM_CTXPOPUP_DIRECTION_UP:
688 _del_pre_hook(Evas_Object *obj)
692 wd = elm_widget_data_get(obj);
695 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
696 _parent_resize, obj);
698 _hover_parent_callbacks_del(obj);
702 _del_hook(Evas_Object *obj)
706 wd = elm_widget_data_get(obj);
709 elm_ctxpopup_clear(obj);
710 evas_object_del(wd->arrow);
711 evas_object_del(wd->base);
716 _theme_hook(Evas_Object *obj)
720 Elm_Ctxpopup_Item *item;
722 wd = elm_widget_data_get(obj);
726 EINA_LIST_FOREACH(wd->items, elist, item)
728 if (item->label && item->icon)
729 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
730 "icon_text_style_item",
731 elm_widget_style_get(obj));
732 else if (item->label)
733 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
734 elm_widget_style_get(obj));
736 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
737 elm_widget_style_get(obj));
739 edje_object_part_text_set(item->base.view, "elm.text", item->label);
742 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
744 edje_object_message_signal_process(item->base.view);
747 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
748 elm_widget_style_get(obj));
749 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
750 elm_widget_style_get(obj));
751 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
752 elm_widget_style_get(obj));
756 if (!strncmp(elm_object_style_get(obj), "default",
758 elm_object_style_set(wd->scr, "ctxpopup");
760 elm_object_style_set(wd->scr, elm_object_style_get(obj));
763 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
767 _scroller_size_reset(wd);
773 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__,
774 Evas_Object *content)
776 ELM_CHECK_WIDTYPE(obj, widtype);
780 wd = elm_widget_data_get(obj);
781 if ((!wd) || (!content)) return;
783 if (wd->items) elm_ctxpopup_clear(obj);
784 if (wd->content) evas_object_del(wd->content);
786 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
789 elm_widget_sub_object_add(obj, content);
790 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
792 wd->content = content;
794 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
801 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
803 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
806 Evas_Object *content;
808 wd = elm_widget_data_get(obj);
809 if (!wd) return NULL;
811 content = wd->content;
812 if (!content) return NULL;
814 edje_object_part_unswallow(wd->base, content);
815 elm_widget_sub_object_del(obj, content);
816 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
817 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
820 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
827 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
829 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
831 Widget_Data *wd = elm_widget_data_get(obj);
832 if (!wd) return NULL;
837 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
838 const char *emission __UNUSED__, const char *source __UNUSED__)
840 evas_object_hide(data);
844 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
845 void *event_info __UNUSED__)
850 wd = elm_widget_data_get(data);
853 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
854 evas_object_resize(wd->bg, w, h);
855 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
857 if (!wd->visible) return;
863 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
864 void *event_info __UNUSED__)
868 wd = elm_widget_data_get(obj);
871 if ((!wd->items) && (!wd->content)) return;
873 wd->visible = EINA_TRUE;
875 evas_object_show(wd->bg);
876 evas_object_show(wd->base);
877 evas_object_show(wd->arrow);
879 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
880 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
884 elm_object_focus_set(obj, EINA_TRUE);
888 _hide(Evas_Object *obj)
890 Widget_Data *wd = elm_widget_data_get(obj);
894 evas_object_hide(wd->bg);
895 evas_object_hide(wd->arrow);
896 evas_object_hide(wd->base);
898 _scroller_size_reset(wd);
900 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
901 wd->visible = EINA_FALSE;
905 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
906 void *event_info __UNUSED__)
910 wd = elm_widget_data_get(obj);
911 if ((!wd) || (!wd->visible))
918 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
919 void *event_info __UNUSED__)
924 wd = elm_widget_data_get(data);
926 if (!wd->visible) return;
927 if (wd->finished) return;
929 evas_object_geometry_get(obj, 0, 0, &w, &h);
931 if (w != 0 && h != 0)
933 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
936 wd->finished = EINA_TRUE;
941 if (wd->max_sc_w < w)
943 if (wd->max_sc_h < h)
950 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
951 void *event_info __UNUSED__)
955 wd = elm_widget_data_get(obj);
960 evas_object_show(wd->arrow);
962 _scroller_size_reset(wd);
967 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
968 const char *emission __UNUSED__, const char *source __UNUSED__)
970 Elm_Ctxpopup_Item *item = data;
973 if (item->disabled) return;
976 item->func((void*) item->base.data, item->base.widget, data);
980 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
983 evas_object_del(item->icon);
988 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
989 edje_object_message_signal_process(item->base.view);
993 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
995 if (!eina_stringshare_replace(&item->label, label))
998 edje_object_part_text_set(item->base.view, "elm.text", label);
999 edje_object_message_signal_process(item->base.view);
1003 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1007 wd = elm_widget_data_get(item->base.widget);
1010 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
1011 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
1012 elm_widget_style_get(item->base.widget));
1013 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
1014 _item_select_cb, item);
1015 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
1016 evas_object_show(item->base.view);
1020 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1021 void *event_info __UNUSED__)
1023 elm_object_content_unset(data);
1027 _list_del(Widget_Data *wd)
1029 if (!wd->scr) return;
1031 edje_object_part_unswallow(wd->base, wd->scr);
1032 evas_object_del(wd->scr);
1038 _list_new(Evas_Object *obj)
1041 wd = elm_widget_data_get(obj);
1045 wd->scr = elm_scroller_add(obj);
1046 elm_object_style_set(wd->scr, "ctxpopup");
1047 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1048 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1049 _scroller_resize, obj);
1050 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1053 wd->box = elm_box_add(obj);
1054 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1057 elm_scroller_content_set(wd->scr, wd->box);
1058 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1062 _remove_items(Widget_Data *wd)
1065 Elm_Ctxpopup_Item *item;
1067 if (!wd->items) return;
1069 EINA_LIST_FOREACH(wd->items, elist, item)
1072 eina_stringshare_del(item->label);
1074 evas_object_del(item->icon);
1075 wd->items = eina_list_remove(wd->items, item);
1083 elm_ctxpopup_add(Evas_Object *parent)
1088 Evas_Coord x, y, w, h;
1090 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1092 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1093 elm_widget_type_set(obj, "ctxpopup");
1094 elm_widget_sub_object_add(parent, obj);
1095 elm_widget_data_set(obj, wd);
1096 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1097 elm_widget_del_hook_set(obj, _del_hook);
1098 elm_widget_theme_hook_set(obj, _theme_hook);
1099 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1100 elm_widget_can_focus_set(obj, EINA_TRUE);
1101 elm_widget_event_hook_set(obj, _event_hook);
1102 elm_widget_content_set_hook_set(obj, _content_set_hook);
1103 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1104 elm_widget_content_get_hook_set(obj, _content_get_hook);
1106 wd->parent = parent;
1109 wd->bg = edje_object_add(e);
1110 elm_widget_sub_object_add(obj, wd->bg);
1111 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1112 evas_object_geometry_get(parent, &x, &y, &w, &h);
1113 evas_object_move(wd->bg, x, y);
1114 evas_object_resize(wd->bg, w, h);
1115 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1116 _bg_clicked_cb, obj);
1119 wd->base = edje_object_add(e);
1120 elm_widget_sub_object_add(obj, wd->base);
1121 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1124 wd->arrow = edje_object_add(e);
1125 elm_widget_sub_object_add(obj, wd->arrow);
1126 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1128 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1129 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1130 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1131 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1132 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1134 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1136 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1138 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1140 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1142 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1143 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1144 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1145 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1147 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1153 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1155 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1156 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1157 return ctxpopup_it->icon;
1161 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1163 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1166 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1168 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1171 _item_icon_set(ctxpopup_it, icon);
1172 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1176 _scroller_size_reset(wd);
1177 _sizing_eval(ctxpopup_it->base.widget);
1182 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1184 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1185 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1186 return ctxpopup_it->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 *ctxpopup_it = ELM_CAST(it);
1197 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1200 _item_label_set(ctxpopup_it, label);
1201 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1205 _scroller_size_reset(wd);
1206 _sizing_eval(ctxpopup_it->base.widget);
1211 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1213 ELM_CHECK_WIDTYPE(obj, widtype);
1217 wd = elm_widget_data_get(obj);
1220 _hover_parent_callbacks_del(obj);
1224 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1225 _hover_parent_del, obj);
1226 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1227 _hover_parent_move, obj);
1228 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1229 _hover_parent_resize, obj);
1232 wd->hover_parent = hover_parent;
1234 if (wd->visible) _sizing_eval(obj);
1238 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1240 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1244 wd = elm_widget_data_get(obj);
1245 if (!wd) return NULL;
1247 return wd->hover_parent;
1251 elm_ctxpopup_clear(Evas_Object * obj)
1253 ELM_CHECK_WIDTYPE(obj, widtype);
1255 Widget_Data *wd = elm_widget_data_get(obj);
1260 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1264 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1266 ELM_CHECK_WIDTYPE(obj, widtype);
1270 wd = elm_widget_data_get(obj);
1273 wd->horizontal = !!horizontal;
1275 if ((!wd->scr) && (!wd->box))
1280 elm_box_horizontal_set(wd->box, EINA_FALSE);
1281 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1285 elm_box_horizontal_set(wd->box, EINA_TRUE);
1286 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1289 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1296 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1298 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1302 wd = elm_widget_data_get(obj);
1303 if (!wd) return EINA_FALSE;
1305 return wd->horizontal;
1308 EAPI Elm_Object_Item *
1309 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1310 Evas_Object *icon, Evas_Smart_Cb func,
1313 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1316 Elm_Ctxpopup_Item *item;
1318 wd = elm_widget_data_get(obj);
1319 if (!wd) return NULL;
1321 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1322 if (!item) return NULL;
1324 //The first item is appended.
1326 evas_object_del(elm_object_content_unset(obj));
1332 item->base.data = data;
1335 _item_new(item, "icon_text_style_item");
1337 _item_new(item, "text_style_item");
1339 _item_new(item, "icon_style_item");
1341 _item_icon_set(item, icon);
1342 _item_label_set(item, label);
1343 elm_box_pack_end(wd->box, item->base.view);
1344 wd->items = eina_list_append(wd->items, item);
1345 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1349 _scroller_size_reset(wd);
1353 return ELM_CAST(item);
1357 elm_ctxpopup_item_del(Elm_Object_Item *it)
1359 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1362 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1364 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1367 if (ctxpopup_it->icon)
1368 evas_object_del(ctxpopup_it->icon);
1369 if (ctxpopup_it->base.view)
1370 evas_object_del(ctxpopup_it->base.view);
1372 eina_stringshare_del(ctxpopup_it->label);
1374 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1376 if (eina_list_count(wd->items) < 1)
1379 wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1382 _sizing_eval(ctxpopup_it->base.widget);
1388 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1390 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1393 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1395 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1398 ctxpopup_it = ELM_CAST(it);
1400 if (disabled == ctxpopup_it->disabled)
1404 edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,disabled", "elm");
1406 edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,enabled", "elm");
1408 ctxpopup_it->disabled = !!disabled;
1412 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1414 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1415 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1416 return ctxpopup_it->disabled;
1420 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1422 elm_object_content_set(obj, content);
1426 elm_ctxpopup_content_unset(Evas_Object *obj)
1428 return elm_object_content_unset(obj);
1432 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1433 Elm_Ctxpopup_Direction first,
1434 Elm_Ctxpopup_Direction second,
1435 Elm_Ctxpopup_Direction third,
1436 Elm_Ctxpopup_Direction fourth)
1438 ELM_CHECK_WIDTYPE(obj, widtype);
1441 wd = elm_widget_data_get(obj);
1444 wd->dir_priority[0] = first;
1445 wd->dir_priority[1] = second;
1446 wd->dir_priority[2] = third;
1447 wd->dir_priority[3] = fourth;
1454 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1455 Elm_Ctxpopup_Direction *first,
1456 Elm_Ctxpopup_Direction *second,
1457 Elm_Ctxpopup_Direction *third,
1458 Elm_Ctxpopup_Direction *fourth)
1460 ELM_CHECK_WIDTYPE(obj, widtype);
1463 wd = elm_widget_data_get(obj);
1466 if (first) *first = wd->dir_priority[0];
1467 if (second) *second = wd->dir_priority[1];
1468 if (third) *third = wd->dir_priority[2];
1469 if (fourth) *fourth = wd->dir_priority[3];
1472 EAPI Elm_Ctxpopup_Direction
1473 elm_ctxpopup_direction_get(const Evas_Object *obj)
1475 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1478 wd = elm_widget_data_get(obj);
1479 if (!wd) return ELM_CTXPOPUP_DIRECTION_DONT_KNOW;