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 Elm_Ctxpopup_Direction dir;
26 Elm_Ctxpopup_Direction dir_priority[4];
27 Evas_Coord max_sc_w, max_sc_h;
28 Eina_Bool horizontal:1;
33 static const char *widtype = NULL;
35 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
36 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
37 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
38 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
39 static void _scroller_size_reset(Widget_Data *wd);
40 static void _on_focus_hook(void *data, Evas_Object *obj);
41 static Eina_Bool _event_hook(Evas_Object *obj,
43 Evas_Callback_Type type,
45 static void _parent_cut_off(Evas_Object *obj);
46 static void _parent_resize(void *data,
50 static void _parent_move(void *data,
54 static void _parent_del(void *data,
58 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
59 static void _adjust_pos_x(Evas_Coord_Point *pos,
60 Evas_Coord_Point *base_size,
61 Evas_Coord_Rectangle *hover_area);
62 static void _adjust_pos_y(Evas_Coord_Point *pos,
63 Evas_Coord_Point *base_size,
64 Evas_Coord_Rectangle *hover_area);
65 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
66 Evas_Coord_Rectangle *rect);
67 static void _update_arrow(Evas_Object *obj,
68 Elm_Ctxpopup_Direction dir,
69 Evas_Coord_Rectangle rect);
70 static void _sizing_eval(Evas_Object *obj);
71 static void _shift_base_by_arrow(Evas_Object *arrow,
72 Elm_Ctxpopup_Direction dir,
73 Evas_Coord_Rectangle *rect);
74 static void _del_pre_hook(Evas_Object *obj);
75 static void _del_hook(Evas_Object *obj);
76 static void _theme_hook(Evas_Object *obj);
77 static void _content_set_hook(Evas_Object *obj,
79 Evas_Object *content);
80 static Evas_Object * _content_unset_hook(Evas_Object *obj,
82 static Evas_Object * _content_get_hook(const Evas_Object *obj,
84 static void _item_text_set_hook(Elm_Object_Item *it,
87 static const char * _item_text_get_hook(const Elm_Object_Item *it,
89 static void _item_content_set_hook(Elm_Object_Item *it,
91 Evas_Object *content);
92 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
94 static void _item_disable_hook(Elm_Object_Item *it);
95 static void _item_signal_emit_hook(Elm_Object_Item *it,
98 static void _bg_clicked_cb(void *data, Evas_Object *obj,
101 static void _ctxpopup_show(void *data,
105 static void _hide(Evas_Object *obj);
106 static void _ctxpopup_hide(void *data,
110 static void _content_resize(void *data,
114 static void _scroller_resize(void *data,
118 static void _ctxpopup_move(void *data,
122 static void _restack(void *data, Evas *e, Evas_Object *obj, void *event_info);
123 static void _item_select_cb(void *data, Evas_Object *obj,
124 const char *emission,
126 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
127 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
128 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
129 static void _content_del(void *data,
133 static void _list_del(Widget_Data *wd);
134 static void _list_new(Evas_Object *obj);
135 static void _remove_items(Widget_Data * wd);
137 static const char SIG_DISMISSED[] = "dismissed";
139 static const Evas_Smart_Cb_Description _signals[] = {
145 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
146 void *event_info __UNUSED__)
148 Widget_Data *wd = elm_widget_data_get(obj);
150 if ((!wd) || (!wd->scr)) return;
151 elm_object_scroll_freeze_push(wd->scr);
155 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
156 void *event_info __UNUSED__)
158 Widget_Data *wd = elm_widget_data_get(obj);
160 if ((!wd) || (!wd->scr)) return;
161 elm_object_scroll_freeze_pop(wd->scr);
165 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
167 Widget_Data *wd = elm_widget_data_get(obj);
169 if ((!wd) || (!wd->scr)) return;
170 elm_object_scroll_hold_push(wd->scr);
174 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
176 Widget_Data *wd = elm_widget_data_get(obj);
178 if ((!wd) || (!wd->scr)) return;
179 elm_object_scroll_hold_pop(wd->scr);
183 _scroller_size_reset(Widget_Data *wd)
185 wd->finished = EINA_FALSE;
191 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
193 Widget_Data *wd = elm_widget_data_get(obj);
196 if (elm_widget_focus_get(obj))
207 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
208 Evas_Callback_Type type, void *event_info)
210 Evas_Event_Key_Down *ev;
213 if (type != EVAS_CALLBACK_KEY_DOWN)
215 wd = elm_widget_data_get(obj);
216 if (!wd) return EINA_FALSE;
219 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
220 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
222 evas_object_hide(obj);
223 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
228 _parent_cut_off(Evas_Object *obj)
230 Widget_Data *wd = elm_widget_data_get(obj);
234 evas_object_event_callback_del_full(wd->parent,
238 evas_object_event_callback_del_full(wd->parent,
242 evas_object_event_callback_del_full(wd->parent,
243 EVAS_CALLBACK_RESIZE,
247 elm_widget_sub_object_del(wd->parent, obj);
251 _parent_resize(void *data,
253 Evas_Object *obj __UNUSED__,
254 void *event_info __UNUSED__)
256 Widget_Data *wd = elm_widget_data_get(data);
259 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
265 _parent_move(void *data,
267 Evas_Object *obj __UNUSED__,
268 void *event_info __UNUSED__)
270 Widget_Data *wd = elm_widget_data_get(data);
274 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
278 _scroller_size_reset(wd);
284 _parent_del(void *data,
286 Evas_Object *obj __UNUSED__,
287 void *event_info __UNUSED__)
289 evas_object_del(data);
293 _item_sizing_eval(Elm_Ctxpopup_Item *item)
295 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
299 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
301 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
302 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
306 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
307 Evas_Coord_Rectangle *hover_area)
309 pos->x -= (base_size->x / 2);
311 if (pos->x < hover_area->x)
312 pos->x = hover_area->x;
313 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
314 pos->x = (hover_area->x + hover_area->w) - base_size->x;
316 if (base_size->x > hover_area->w)
317 base_size->x -= (base_size->x - hover_area->w);
319 if (pos->x < hover_area->x)
320 pos->x = hover_area->x;
324 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
325 Evas_Coord_Rectangle *hover_area)
327 pos->y -= (base_size->y / 2);
329 if (pos->y < hover_area->y)
330 pos->y = hover_area->y;
331 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
332 pos->y = hover_area->y + hover_area->h - base_size->y;
334 if (base_size->y > hover_area->h)
335 base_size->y -= (base_size->y - hover_area->h);
337 if (pos->y < hover_area->y)
338 pos->y = hover_area->y;
341 static Elm_Ctxpopup_Direction
342 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
345 Evas_Coord_Point pos = {0, 0};
346 Evas_Coord_Point base_size;
347 Evas_Coord_Point max_size;
348 Evas_Coord_Point min_size;
349 Evas_Coord_Rectangle hover_area;
350 Evas_Coord_Point arrow_size;
351 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
352 Evas_Coord_Point temp;
355 wd = elm_widget_data_get(obj);
357 if ((!wd) || (!rect))
358 return ELM_CTXPOPUP_DIRECTION_DOWN;
360 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
361 &arrow_size.x, &arrow_size.y);
362 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
364 //Initialize Area Rectangle.
365 evas_object_geometry_get(wd->parent,
371 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
374 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
375 evas_object_smart_calculate(wd->base);
378 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
380 if ((max_size.y > 0) && (base_size.y > max_size.y))
381 base_size.y = max_size.y;
383 if ((max_size.x > 0) && (base_size.x > max_size.x))
384 base_size.x = max_size.x;
387 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
389 if ((min_size.y > 0) && (base_size.y < min_size.y))
390 base_size.y = min_size.y;
392 if ((min_size.x > 0) && (base_size.x < min_size.x))
393 base_size.x = min_size.x;
395 //Check the Which direction is available.
396 //If find a avaialble direction, it adjusts position and size.
397 for (idx = 0; idx < 4; idx++)
399 switch (wd->dir_priority[idx])
401 case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
402 case ELM_CTXPOPUP_DIRECTION_UP:
403 temp.y = (pos.y - base_size.y);
404 if ((temp.y - arrow_size.y) < hover_area.y)
406 _adjust_pos_x(&pos, &base_size, &hover_area);
407 pos.y -= base_size.y;
408 dir = ELM_CTXPOPUP_DIRECTION_UP;
410 case ELM_CTXPOPUP_DIRECTION_LEFT:
411 temp.x = (pos.x - base_size.x);
412 if ((temp.x - arrow_size.x) < hover_area.x)
414 _adjust_pos_y(&pos, &base_size, &hover_area);
415 pos.x -= base_size.x;
416 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
418 case ELM_CTXPOPUP_DIRECTION_RIGHT:
419 temp.x = (pos.x + base_size.x);
420 if ((temp.x + arrow_size.x) >
421 (hover_area.x + hover_area.w))
423 _adjust_pos_y(&pos, &base_size, &hover_area);
424 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
426 case ELM_CTXPOPUP_DIRECTION_DOWN:
427 temp.y = (pos.y + base_size.y);
428 if ((temp.y + arrow_size.y) >
429 (hover_area.y + hover_area.h))
431 _adjust_pos_x(&pos, &base_size, &hover_area);
432 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
440 //In this case, all directions are invalid because of lack of space.
443 Evas_Coord length[2];
447 length[0] = pos.y - hover_area.y;
448 length[1] = (hover_area.y + hover_area.h) - pos.y;
450 // ELM_CTXPOPUP_DIRECTION_UP
451 if (length[0] > length[1])
453 _adjust_pos_x(&pos, &base_size, &hover_area);
454 pos.y -= base_size.y;
455 dir = ELM_CTXPOPUP_DIRECTION_UP;
456 if (pos.y < (hover_area.y + arrow_size.y))
458 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
459 pos.y = hover_area.y + arrow_size.y;
462 //ELM_CTXPOPUP_DIRECTION_DOWN
465 _adjust_pos_x(&pos, &base_size, &hover_area);
466 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
467 if ((pos.y + arrow_size.y + base_size.y) >
468 (hover_area.y + hover_area.h))
470 ((pos.y + arrow_size.y + base_size.y) -
471 (hover_area.y + hover_area.h));
476 length[0] = pos.x - hover_area.x;
477 length[1] = (hover_area.x + hover_area.w) - pos.x;
479 //ELM_CTXPOPUP_DIRECTION_LEFT
480 if (length[0] > length[1])
482 _adjust_pos_y(&pos, &base_size, &hover_area);
483 pos.x -= base_size.x;
484 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
485 if (pos.x < (hover_area.x + arrow_size.x))
487 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
488 pos.x = hover_area.x + arrow_size.x;
491 //ELM_CTXPOPUP_DIRECTION_RIGHT
494 _adjust_pos_y(&pos, &base_size, &hover_area);
495 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
496 if (pos.x + (arrow_size.x + base_size.x) >
497 hover_area.x + hover_area.w)
499 ((pos.x + arrow_size.x + base_size.x) -
500 (hover_area.x + hover_area.w));
505 //Final position and size.
508 rect->w = base_size.x;
509 rect->h = base_size.y;
515 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
516 Evas_Coord_Rectangle base_size)
519 Evas_Coord_Rectangle arrow_size;
523 wd = elm_widget_data_get(obj);
526 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
527 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
530 edje_object_part_unswallow(wd->base, wd->arrow);
534 case ELM_CTXPOPUP_DIRECTION_RIGHT:
535 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
536 edje_object_part_swallow(wd->base,
537 "elm.swallow.arrow_left",
541 if (y < ((arrow_size.h * 0.5) + base_size.y))
543 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
544 y = base_size.h - arrow_size.h;
546 y = y - base_size.y - (arrow_size.h * 0.5);
547 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
548 edje_object_part_drag_value_set(wd->base,
549 "elm.swallow.arrow_left",
554 case ELM_CTXPOPUP_DIRECTION_LEFT:
555 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
556 edje_object_part_swallow(wd->base,
557 "elm.swallow.arrow_right",
561 if (y < ((arrow_size.h * 0.5) + base_size.y))
563 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
564 y = base_size.h - arrow_size.h;
566 y = y - base_size.y - (arrow_size.h * 0.5);
567 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
568 edje_object_part_drag_value_set(wd->base,
569 "elm.swallow.arrow_right",
574 case ELM_CTXPOPUP_DIRECTION_DOWN:
575 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
576 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
579 if (x < ((arrow_size.w * 0.5) + base_size.x))
581 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
582 x = base_size.w - arrow_size.w;
584 x = x - base_size.x - (arrow_size.w * 0.5);
585 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
586 edje_object_part_drag_value_set(wd->base,
587 "elm.swallow.arrow_up",
592 case ELM_CTXPOPUP_DIRECTION_UP:
593 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
594 edje_object_part_swallow(wd->base,
595 "elm.swallow.arrow_down",
599 if (x < ((arrow_size.w * 0.5) + base_size.x))
601 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
602 x = base_size.w - arrow_size.w;
603 else x = x - base_size.x - (arrow_size.w * 0.5);
604 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
605 edje_object_part_drag_value_set(wd->base,
606 "elm.swallow.arrow_down",
617 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
621 wd = elm_widget_data_get(obj);
622 if (!wd || wd->visible) return;
626 case ELM_CTXPOPUP_DIRECTION_UP:
627 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
629 case ELM_CTXPOPUP_DIRECTION_LEFT:
630 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
632 case ELM_CTXPOPUP_DIRECTION_RIGHT:
633 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
635 case ELM_CTXPOPUP_DIRECTION_DOWN:
636 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
644 _sizing_eval(Evas_Object *obj)
648 Elm_Ctxpopup_Item *item;
649 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
650 Evas_Coord_Point box_size = { 0, 0 };
651 Evas_Coord_Point _box_size = { 0, 0 };
653 wd = elm_widget_data_get(obj);
657 EINA_LIST_FOREACH(wd->items, elist, item)
659 _item_sizing_eval(item);
660 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
663 if (_box_size.x > box_size.x)
664 box_size.x = _box_size.x;
665 if (_box_size.y != -1)
666 box_size.y += _box_size.y;
670 if (_box_size.x != -1)
671 box_size.x += _box_size.x;
672 if (_box_size.y > box_size.y)
673 box_size.y = _box_size.y;
679 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
680 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
684 wd->dir = _calc_base_geometry(obj, &rect);
685 _show_signal_emit(obj, wd->dir);
686 _update_arrow(obj, wd->dir, rect);
687 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
689 //resize scroller according to final size.
691 evas_object_smart_calculate(wd->scr);
693 evas_object_move(wd->base, rect.x, rect.y);
694 evas_object_resize(wd->base, rect.w, rect.h);
698 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
699 Evas_Coord_Rectangle *rect)
701 Evas_Coord arrow_w, arrow_h;
703 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
707 case ELM_CTXPOPUP_DIRECTION_RIGHT:
710 case ELM_CTXPOPUP_DIRECTION_LEFT:
713 case ELM_CTXPOPUP_DIRECTION_DOWN:
716 case ELM_CTXPOPUP_DIRECTION_UP:
725 _del_pre_hook(Evas_Object *obj)
729 wd = elm_widget_data_get(obj);
732 _parent_cut_off(obj);
736 _del_hook(Evas_Object *obj)
740 wd = elm_widget_data_get(obj);
743 elm_ctxpopup_clear(obj);
744 evas_object_del(wd->arrow);
745 evas_object_del(wd->base);
749 //FIXME: lost the content size when theme hook is called.
751 _theme_hook(Evas_Object *obj)
755 Elm_Ctxpopup_Item *item;
758 wd = elm_widget_data_get(obj);
761 _elm_widget_mirrored_reload(obj);
762 rtl = elm_widget_mirrored_get(obj);
764 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
765 elm_widget_style_get(obj));
766 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
767 elm_widget_style_get(obj));
768 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
769 elm_widget_style_get(obj));
772 EINA_LIST_FOREACH(wd->items, elist, item)
774 edje_object_mirrored_set(VIEW(item), rtl);
776 if (item->label && item->icon)
777 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
778 "icon_text_style_item",
779 elm_widget_style_get(obj));
780 else if (item->label)
781 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
782 elm_widget_style_get(obj));
784 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
785 elm_widget_style_get(obj));
787 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
789 if (elm_widget_item_disabled_get(item))
790 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
792 edje_object_message_signal_process(VIEW(item));
797 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
798 elm_object_style_set(wd->scr, "ctxpopup");
800 elm_object_style_set(wd->scr, elm_object_style_get(obj));
803 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
807 _scroller_size_reset(wd);
813 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
815 ELM_CHECK_WIDTYPE(obj, widtype);
816 Evas_Coord min_w = -1, min_h = -1;
820 if (part && strcmp(part, "default")) return;
822 wd = elm_widget_data_get(obj);
823 if ((!wd) || (!content)) return;
825 if (wd->items) elm_ctxpopup_clear(obj);
826 if (wd->content) evas_object_del(wd->content);
829 wd->box = elm_box_add(obj);
830 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
832 evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
834 evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
836 evas_object_show(content);
837 evas_object_size_hint_min_get(content, &min_w, &min_h);
838 evas_object_size_hint_min_set(wd->box, min_w, min_h);
839 elm_box_pack_end(wd->box, content);
841 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
842 _content_resize, obj);
843 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
846 elm_widget_sub_object_add(obj, wd->box);
847 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
849 wd->content = content;
850 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
857 _content_unset_hook(Evas_Object *obj, const char *part)
859 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
862 Evas_Object *content;
863 if (part && strcmp(part, "default")) return NULL;
864 wd = elm_widget_data_get(obj);
865 if (!wd) return NULL;
867 content = wd->content;
868 if (!content || !wd->box) return NULL;
870 edje_object_part_unswallow(wd->base, wd->box);
871 elm_widget_sub_object_del(obj, wd->box);
872 evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
873 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
875 evas_object_del(wd->box);
878 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
884 _content_get_hook(const Evas_Object *obj, const char *part)
886 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
888 if (part && strcmp(part, "default")) return NULL;
889 wd = elm_widget_data_get(obj);
890 if (!wd) return NULL;
895 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
897 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
900 Elm_Ctxpopup_Item *ctxpopup_it;
902 if (part && strcmp(part, "default")) return;
904 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
906 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
909 _item_label_set(ctxpopup_it, label);
910 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
914 _scroller_size_reset(wd);
915 _sizing_eval(WIDGET(ctxpopup_it));
920 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
922 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
923 Elm_Ctxpopup_Item *ctxpopup_it;
924 if (part && strcmp(part, "default")) return NULL;
925 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
926 return ctxpopup_it->label;
930 _item_content_set_hook(Elm_Object_Item *it,
932 Evas_Object *content)
934 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
936 Elm_Ctxpopup_Item *ctxpopup_it;
938 if (part && strcmp(part, "icon")) return;
940 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
942 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
945 _item_icon_set(ctxpopup_it, content);
946 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
950 _scroller_size_reset(wd);
951 _sizing_eval(WIDGET(ctxpopup_it));
956 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
958 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
959 Elm_Ctxpopup_Item *ctxpopup_it;
960 if (part && strcmp(part, "icon")) return NULL;
961 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
962 return ctxpopup_it->icon;
966 _item_disable_hook(Elm_Object_Item *it)
968 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
971 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
973 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
976 if (elm_widget_item_disabled_get(it))
977 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
979 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
983 _item_signal_emit_hook(Elm_Object_Item *it, const char *emission,
986 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
987 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
988 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
992 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
993 const char *emission __UNUSED__, const char *source __UNUSED__)
995 evas_object_hide(data);
999 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1000 void *event_info __UNUSED__)
1004 wd = elm_widget_data_get(obj);
1007 if ((!wd->items) && (!wd->content)) return;
1009 wd->visible = EINA_TRUE;
1011 evas_object_show(wd->bg);
1012 evas_object_show(wd->base);
1013 evas_object_show(wd->arrow);
1015 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
1016 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
1020 elm_object_focus_set(obj, EINA_TRUE);
1024 _hide(Evas_Object *obj)
1026 Widget_Data *wd = elm_widget_data_get(obj);
1028 if ((!wd) || (!wd->visible)) return;
1030 evas_object_hide(wd->bg);
1031 evas_object_hide(wd->arrow);
1032 evas_object_hide(wd->base);
1034 _scroller_size_reset(wd);
1036 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1037 wd->visible = EINA_FALSE;
1041 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1042 void *event_info __UNUSED__)
1048 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1049 void *event_info __UNUSED__)
1051 Widget_Data *wd = elm_widget_data_get(data);
1053 elm_box_recalculate(wd->box);
1058 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1059 void *event_info __UNUSED__)
1064 wd = elm_widget_data_get(data);
1066 if (!wd->visible) return;
1067 if (wd->finished) return;
1069 evas_object_geometry_get(obj, 0, 0, &w, &h);
1071 if (w != 0 && h != 0)
1073 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1076 wd->finished = EINA_TRUE;
1081 if (wd->max_sc_w < w)
1083 if (wd->max_sc_h < h)
1090 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1091 void *event_info __UNUSED__)
1095 wd = elm_widget_data_get(obj);
1100 evas_object_show(wd->arrow);
1102 _scroller_size_reset(wd);
1107 _restack(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1109 Widget_Data *wd = elm_widget_data_get(obj);
1111 evas_object_layer_set(wd->bg,
1112 evas_object_layer_get(obj));
1113 evas_object_layer_set(wd->base,
1114 evas_object_layer_get(obj));
1118 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1119 const char *emission __UNUSED__, const char *source __UNUSED__)
1121 Elm_Ctxpopup_Item *item = data;
1124 if (elm_widget_item_disabled_get(item)) return;
1127 item->func((void*) item->base.data, WIDGET(item), data);
1131 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1134 evas_object_del(item->icon);
1139 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1140 edje_object_message_signal_process(VIEW(item));
1144 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1146 if (!eina_stringshare_replace(&item->label, label))
1149 edje_object_part_text_set(VIEW(item), "elm.text", label);
1150 edje_object_message_signal_process(VIEW(item));
1154 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1158 wd = elm_widget_data_get(WIDGET(item));
1161 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1162 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
1163 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1164 elm_widget_style_get(WIDGET(item)));
1165 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1166 _item_select_cb, item);
1167 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1168 evas_object_show(VIEW(item));
1172 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1173 void *event_info __UNUSED__)
1175 elm_object_content_unset(data);
1179 _list_del(Widget_Data *wd)
1181 if (!wd->scr) return;
1183 edje_object_part_unswallow(wd->base, wd->scr);
1184 evas_object_del(wd->scr);
1190 _list_new(Evas_Object *obj)
1193 wd = elm_widget_data_get(obj);
1197 wd->scr = elm_scroller_add(obj);
1198 elm_object_style_set(wd->scr, "ctxpopup");
1199 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1200 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1201 _scroller_resize, obj);
1202 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1205 wd->box = elm_box_add(obj);
1206 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1209 elm_object_content_set(wd->scr, wd->box);
1210 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1214 _remove_items(Widget_Data *wd)
1217 Elm_Ctxpopup_Item *item;
1219 if (!wd->items) return;
1221 EINA_LIST_FOREACH(wd->items, elist, item)
1224 eina_stringshare_del(item->label);
1226 evas_object_del(item->icon);
1227 wd->items = eina_list_remove(wd->items, item);
1228 elm_widget_item_free(item);
1235 _item_del_pre_hook(Elm_Object_Item *it)
1237 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1240 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1242 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1245 if (ctxpopup_it->icon)
1246 evas_object_del(ctxpopup_it->icon);
1247 if (VIEW(ctxpopup_it))
1248 evas_object_del(VIEW(ctxpopup_it));
1250 eina_stringshare_del(ctxpopup_it->label);
1252 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1254 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1256 if (eina_list_count(wd->items) < 1)
1258 evas_object_hide(WIDGET(ctxpopup_it));
1263 _sizing_eval(WIDGET(ctxpopup_it));
1267 elm_ctxpopup_add(Evas_Object *parent)
1273 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1275 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1276 elm_widget_type_set(obj, "ctxpopup");
1277 elm_widget_data_set(obj, wd);
1278 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1279 elm_widget_del_hook_set(obj, _del_hook);
1280 elm_widget_theme_hook_set(obj, _theme_hook);
1281 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1282 elm_widget_can_focus_set(obj, EINA_TRUE);
1283 elm_widget_event_hook_set(obj, _event_hook);
1284 elm_widget_content_set_hook_set(obj, _content_set_hook);
1285 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1286 elm_widget_content_get_hook_set(obj, _content_get_hook);
1289 wd->bg = edje_object_add(e);
1290 elm_widget_sub_object_add(obj, wd->bg);
1291 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1292 edje_object_signal_callback_add(wd->bg,
1298 wd->base = edje_object_add(e);
1299 elm_widget_sub_object_add(obj, wd->base);
1300 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1303 wd->arrow = edje_object_add(e);
1304 elm_widget_sub_object_add(obj, wd->arrow);
1305 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1307 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1308 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1309 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1310 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1311 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1313 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1315 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1317 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1319 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESTACK, _restack, obj);
1320 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1321 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1322 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1323 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1325 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1327 //default parent is to be hover parent
1328 elm_ctxpopup_hover_parent_set(obj, parent);
1334 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1336 return _item_content_get_hook(it, "icon");
1340 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1342 _item_content_set_hook(it, "icon", icon);
1346 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1348 return _item_text_get_hook(it, NULL);
1352 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1354 _item_text_set_hook(it, NULL, label);
1358 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1360 ELM_CHECK_WIDTYPE(obj, widtype);
1363 Evas_Coord x, y, w, h;
1365 wd = elm_widget_data_get(obj);
1366 if ((!wd) || (!parent)) return;
1368 _parent_cut_off(obj);
1372 evas_object_event_callback_add(parent,
1376 evas_object_event_callback_add(parent,
1380 evas_object_event_callback_add(parent,
1381 EVAS_CALLBACK_RESIZE,
1386 elm_widget_sub_object_add(parent, obj);
1387 wd->parent = parent;
1390 evas_object_geometry_get(parent, &x, &y, &w, &h);
1391 evas_object_move(wd->bg, x, y);
1392 evas_object_resize(wd->bg, w, h);
1394 if (wd->visible) _sizing_eval(obj);
1398 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1400 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1404 wd = elm_widget_data_get(obj);
1405 if (!wd) return NULL;
1411 elm_ctxpopup_clear(Evas_Object * obj)
1413 ELM_CHECK_WIDTYPE(obj, widtype);
1415 Widget_Data *wd = elm_widget_data_get(obj);
1420 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1424 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1426 ELM_CHECK_WIDTYPE(obj, widtype);
1430 wd = elm_widget_data_get(obj);
1433 wd->horizontal = !!horizontal;
1435 if ((!wd->scr) && (!wd->box))
1440 elm_box_horizontal_set(wd->box, EINA_FALSE);
1441 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1445 elm_box_horizontal_set(wd->box, EINA_TRUE);
1446 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1449 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1456 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1458 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1462 wd = elm_widget_data_get(obj);
1463 if (!wd) return EINA_FALSE;
1465 return wd->horizontal;
1468 EAPI Elm_Object_Item *
1469 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1470 Evas_Object *icon, Evas_Smart_Cb func,
1473 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1476 Evas_Object *content;
1477 Elm_Ctxpopup_Item *item;
1479 wd = elm_widget_data_get(obj);
1480 if (!wd) return NULL;
1482 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1483 if (!item) return NULL;
1485 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1486 elm_widget_item_disable_hook_set(item, _item_disable_hook);
1487 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1488 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1489 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1490 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1491 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1493 //The first item is appended.
1494 content = elm_object_content_unset(obj);
1495 if (content) evas_object_del(content);
1501 item->base.data = data;
1504 _item_new(item, "icon_text_style_item");
1506 _item_new(item, "text_style_item");
1508 _item_new(item, "icon_style_item");
1510 _item_icon_set(item, icon);
1511 _item_label_set(item, label);
1512 elm_box_pack_end(wd->box, VIEW(item));
1513 wd->items = eina_list_append(wd->items, item);
1514 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1518 _scroller_size_reset(wd);
1522 return (Elm_Object_Item *) item;
1526 elm_ctxpopup_item_del(Elm_Object_Item *it)
1528 elm_object_item_del(it);
1532 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1534 elm_object_item_disabled_set(it, disabled);
1538 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1540 return elm_object_item_disabled_get(it);
1544 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1546 elm_object_content_set(obj, content);
1550 elm_ctxpopup_content_unset(Evas_Object *obj)
1552 return elm_object_content_unset(obj);
1556 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1557 Elm_Ctxpopup_Direction first,
1558 Elm_Ctxpopup_Direction second,
1559 Elm_Ctxpopup_Direction third,
1560 Elm_Ctxpopup_Direction fourth)
1562 ELM_CHECK_WIDTYPE(obj, widtype);
1565 wd = elm_widget_data_get(obj);
1568 wd->dir_priority[0] = first;
1569 wd->dir_priority[1] = second;
1570 wd->dir_priority[2] = third;
1571 wd->dir_priority[3] = fourth;
1578 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1579 Elm_Ctxpopup_Direction *first,
1580 Elm_Ctxpopup_Direction *second,
1581 Elm_Ctxpopup_Direction *third,
1582 Elm_Ctxpopup_Direction *fourth)
1584 ELM_CHECK_WIDTYPE(obj, widtype);
1587 wd = elm_widget_data_get(obj);
1590 if (first) *first = wd->dir_priority[0];
1591 if (second) *second = wd->dir_priority[1];
1592 if (third) *third = wd->dir_priority[2];
1593 if (fourth) *fourth = wd->dir_priority[3];
1596 EAPI Elm_Ctxpopup_Direction
1597 elm_ctxpopup_direction_get(const Evas_Object *obj)
1599 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1602 wd = elm_widget_data_get(obj);
1603 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;