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 _hide_signal_emit(Evas_Object *obj,
72 Elm_Ctxpopup_Direction dir);
73 static void _show_signal_emit(Evas_Object *obj,
74 Elm_Ctxpopup_Direction dir);
75 static void _shift_base_by_arrow(Evas_Object *arrow,
76 Elm_Ctxpopup_Direction dir,
77 Evas_Coord_Rectangle *rect);
78 static void _del_pre_hook(Evas_Object *obj);
79 static void _del_hook(Evas_Object *obj);
80 static void _theme_hook(Evas_Object *obj);
81 static void _content_set_hook(Evas_Object *obj,
83 Evas_Object *content);
84 static Evas_Object * _content_unset_hook(Evas_Object *obj,
86 static Evas_Object * _content_get_hook(const Evas_Object *obj,
88 static void _item_text_set_hook(Elm_Object_Item *it,
91 static const char * _item_text_get_hook(const Elm_Object_Item *it,
93 static void _item_content_set_hook(Elm_Object_Item *it,
95 Evas_Object *content);
96 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
98 static void _item_disable_hook(Elm_Object_Item *it);
99 static void _item_signal_emit_hook(Elm_Object_Item *it,
100 const char *emission,
102 static void _bg_clicked_cb(void *data, Evas_Object *obj,
103 const char *emission,
105 static void _ctxpopup_show(void *data,
109 static void _hide_finished(void *data,
111 const char *emission,
112 const char *source __UNUSED__);
113 static void _ctxpopup_hide(void *data,
117 static void _content_resize(void *data,
121 static void _scroller_resize(void *data,
125 static void _ctxpopup_move(void *data,
129 static void _restack(void *data, Evas *e, Evas_Object *obj, void *event_info);
130 static void _item_select_cb(void *data, Evas_Object *obj,
131 const char *emission,
133 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
134 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
135 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
136 static void _content_del(void *data,
140 static void _list_del(Widget_Data *wd);
141 static void _list_new(Evas_Object *obj);
142 static void _remove_items(Widget_Data * wd);
144 static const char SIG_DISMISSED[] = "dismissed";
146 static const Evas_Smart_Cb_Description _signals[] = {
152 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
153 void *event_info __UNUSED__)
155 Widget_Data *wd = elm_widget_data_get(obj);
157 if ((!wd) || (!wd->scr)) return;
158 elm_object_scroll_freeze_push(wd->scr);
162 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
163 void *event_info __UNUSED__)
165 Widget_Data *wd = elm_widget_data_get(obj);
167 if ((!wd) || (!wd->scr)) return;
168 elm_object_scroll_freeze_pop(wd->scr);
172 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
174 Widget_Data *wd = elm_widget_data_get(obj);
176 if ((!wd) || (!wd->scr)) return;
177 elm_object_scroll_hold_push(wd->scr);
181 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
183 Widget_Data *wd = elm_widget_data_get(obj);
185 if ((!wd) || (!wd->scr)) return;
186 elm_object_scroll_hold_pop(wd->scr);
190 _scroller_size_reset(Widget_Data *wd)
192 wd->finished = EINA_FALSE;
198 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
200 Widget_Data *wd = elm_widget_data_get(obj);
203 if (elm_widget_focus_get(obj))
214 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
215 Evas_Callback_Type type, void *event_info)
217 Evas_Event_Key_Down *ev;
220 if (type != EVAS_CALLBACK_KEY_DOWN)
222 wd = elm_widget_data_get(obj);
223 if (!wd) return EINA_FALSE;
226 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
227 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
229 evas_object_hide(obj);
230 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
235 _parent_cut_off(Evas_Object *obj)
237 Widget_Data *wd = elm_widget_data_get(obj);
241 evas_object_event_callback_del_full(wd->parent,
245 evas_object_event_callback_del_full(wd->parent,
249 evas_object_event_callback_del_full(wd->parent,
250 EVAS_CALLBACK_RESIZE,
254 elm_widget_sub_object_del(wd->parent, obj);
258 _parent_resize(void *data,
260 Evas_Object *obj __UNUSED__,
261 void *event_info __UNUSED__)
263 Widget_Data *wd = elm_widget_data_get(data);
266 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
268 evas_object_hide(data);
272 _parent_move(void *data,
274 Evas_Object *obj __UNUSED__,
275 void *event_info __UNUSED__)
277 Widget_Data *wd = elm_widget_data_get(data);
281 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
285 _scroller_size_reset(wd);
291 _parent_del(void *data,
293 Evas_Object *obj __UNUSED__,
294 void *event_info __UNUSED__)
296 evas_object_del(data);
300 _item_sizing_eval(Elm_Ctxpopup_Item *item)
302 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
306 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
308 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
309 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
313 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
314 Evas_Coord_Rectangle *hover_area)
316 pos->x -= (base_size->x / 2);
318 if (pos->x < hover_area->x)
319 pos->x = hover_area->x;
320 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
321 pos->x = (hover_area->x + hover_area->w) - base_size->x;
323 if (base_size->x > hover_area->w)
324 base_size->x -= (base_size->x - hover_area->w);
326 if (pos->x < hover_area->x)
327 pos->x = hover_area->x;
331 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
332 Evas_Coord_Rectangle *hover_area)
334 pos->y -= (base_size->y / 2);
336 if (pos->y < hover_area->y)
337 pos->y = hover_area->y;
338 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
339 pos->y = hover_area->y + hover_area->h - base_size->y;
341 if (base_size->y > hover_area->h)
342 base_size->y -= (base_size->y - hover_area->h);
344 if (pos->y < hover_area->y)
345 pos->y = hover_area->y;
348 static Elm_Ctxpopup_Direction
349 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
352 Evas_Coord_Point pos = {0, 0};
353 Evas_Coord_Point base_size;
354 Evas_Coord_Point max_size;
355 Evas_Coord_Point min_size;
356 Evas_Coord_Rectangle hover_area;
357 Evas_Coord_Point arrow_size;
358 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
359 Evas_Coord_Point temp;
362 wd = elm_widget_data_get(obj);
364 if ((!wd) || (!rect))
365 return ELM_CTXPOPUP_DIRECTION_DOWN;
367 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
368 &arrow_size.x, &arrow_size.y);
369 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
371 //Initialize Area Rectangle.
372 evas_object_geometry_get(wd->parent,
378 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
381 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
382 evas_object_smart_calculate(wd->base);
385 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
387 if ((max_size.y > 0) && (base_size.y > max_size.y))
388 base_size.y = max_size.y;
390 if ((max_size.x > 0) && (base_size.x > max_size.x))
391 base_size.x = max_size.x;
394 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
396 if ((min_size.y > 0) && (base_size.y < min_size.y))
397 base_size.y = min_size.y;
399 if ((min_size.x > 0) && (base_size.x < min_size.x))
400 base_size.x = min_size.x;
402 //Check the Which direction is available.
403 //If find a avaialble direction, it adjusts position and size.
404 for (idx = 0; idx < 4; idx++)
406 switch (wd->dir_priority[idx])
408 case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
409 case ELM_CTXPOPUP_DIRECTION_UP:
410 temp.y = (pos.y - base_size.y);
411 if ((temp.y - arrow_size.y) < hover_area.y)
413 _adjust_pos_x(&pos, &base_size, &hover_area);
414 pos.y -= base_size.y;
415 dir = ELM_CTXPOPUP_DIRECTION_UP;
417 case ELM_CTXPOPUP_DIRECTION_LEFT:
418 temp.x = (pos.x - base_size.x);
419 if ((temp.x - arrow_size.x) < hover_area.x)
421 _adjust_pos_y(&pos, &base_size, &hover_area);
422 pos.x -= base_size.x;
423 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
425 case ELM_CTXPOPUP_DIRECTION_RIGHT:
426 temp.x = (pos.x + base_size.x);
427 if ((temp.x + arrow_size.x) >
428 (hover_area.x + hover_area.w))
430 _adjust_pos_y(&pos, &base_size, &hover_area);
431 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
433 case ELM_CTXPOPUP_DIRECTION_DOWN:
434 temp.y = (pos.y + base_size.y);
435 if ((temp.y + arrow_size.y) >
436 (hover_area.y + hover_area.h))
438 _adjust_pos_x(&pos, &base_size, &hover_area);
439 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
447 //In this case, all directions are invalid because of lack of space.
450 Evas_Coord length[2];
454 length[0] = pos.y - hover_area.y;
455 length[1] = (hover_area.y + hover_area.h) - pos.y;
457 // ELM_CTXPOPUP_DIRECTION_UP
458 if (length[0] > length[1])
460 _adjust_pos_x(&pos, &base_size, &hover_area);
461 pos.y -= base_size.y;
462 dir = ELM_CTXPOPUP_DIRECTION_UP;
463 if (pos.y < (hover_area.y + arrow_size.y))
465 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
466 pos.y = hover_area.y + arrow_size.y;
469 //ELM_CTXPOPUP_DIRECTION_DOWN
472 _adjust_pos_x(&pos, &base_size, &hover_area);
473 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
474 if ((pos.y + arrow_size.y + base_size.y) >
475 (hover_area.y + hover_area.h))
477 ((pos.y + arrow_size.y + base_size.y) -
478 (hover_area.y + hover_area.h));
483 length[0] = pos.x - hover_area.x;
484 length[1] = (hover_area.x + hover_area.w) - pos.x;
486 //ELM_CTXPOPUP_DIRECTION_LEFT
487 if (length[0] > length[1])
489 _adjust_pos_y(&pos, &base_size, &hover_area);
490 pos.x -= base_size.x;
491 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
492 if (pos.x < (hover_area.x + arrow_size.x))
494 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
495 pos.x = hover_area.x + arrow_size.x;
498 //ELM_CTXPOPUP_DIRECTION_RIGHT
501 _adjust_pos_y(&pos, &base_size, &hover_area);
502 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
503 if (pos.x + (arrow_size.x + base_size.x) >
504 hover_area.x + hover_area.w)
506 ((pos.x + arrow_size.x + base_size.x) -
507 (hover_area.x + hover_area.w));
512 //Final position and size.
515 rect->w = base_size.x;
516 rect->h = base_size.y;
522 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
523 Evas_Coord_Rectangle base_size)
526 Evas_Coord_Rectangle arrow_size;
530 wd = elm_widget_data_get(obj);
533 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
534 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
537 edje_object_part_unswallow(wd->base, wd->arrow);
541 case ELM_CTXPOPUP_DIRECTION_RIGHT:
542 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
543 edje_object_part_swallow(wd->base,
544 "elm.swallow.arrow_left",
548 if (y < ((arrow_size.h * 0.5) + base_size.y))
550 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
551 y = base_size.h - arrow_size.h;
553 y = y - base_size.y - (arrow_size.h * 0.5);
554 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
555 edje_object_part_drag_value_set(wd->base,
556 "elm.swallow.arrow_left",
561 case ELM_CTXPOPUP_DIRECTION_LEFT:
562 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
563 edje_object_part_swallow(wd->base,
564 "elm.swallow.arrow_right",
568 if (y < ((arrow_size.h * 0.5) + base_size.y))
570 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
571 y = base_size.h - arrow_size.h;
573 y = y - base_size.y - (arrow_size.h * 0.5);
574 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
575 edje_object_part_drag_value_set(wd->base,
576 "elm.swallow.arrow_right",
581 case ELM_CTXPOPUP_DIRECTION_DOWN:
582 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
583 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
586 if (x < ((arrow_size.w * 0.5) + base_size.x))
588 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
589 x = base_size.w - arrow_size.w;
591 x = x - base_size.x - (arrow_size.w * 0.5);
592 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
593 edje_object_part_drag_value_set(wd->base,
594 "elm.swallow.arrow_up",
599 case ELM_CTXPOPUP_DIRECTION_UP:
600 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
601 edje_object_part_swallow(wd->base,
602 "elm.swallow.arrow_down",
606 if (x < ((arrow_size.w * 0.5) + base_size.x))
608 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
609 x = base_size.w - arrow_size.w;
610 else x = x - base_size.x - (arrow_size.w * 0.5);
611 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
612 edje_object_part_drag_value_set(wd->base,
613 "elm.swallow.arrow_down",
624 _hide_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
628 wd = elm_widget_data_get(obj);
629 if (!wd->visible) return;
633 case ELM_CTXPOPUP_DIRECTION_UP:
634 edje_object_signal_emit(wd->base, "elm,state,hide,up", "elm");
636 case ELM_CTXPOPUP_DIRECTION_LEFT:
637 edje_object_signal_emit(wd->base, "elm,state,hide,left", "elm");
639 case ELM_CTXPOPUP_DIRECTION_RIGHT:
640 edje_object_signal_emit(wd->base, "elm,state,hide,right", "elm");
642 case ELM_CTXPOPUP_DIRECTION_DOWN:
643 edje_object_signal_emit(wd->base, "elm,state,hide,down", "elm");
649 edje_object_signal_emit(wd->bg, "elm,state,hide", "elm");
653 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
657 wd = elm_widget_data_get(obj);
658 if (wd->visible) return;
662 case ELM_CTXPOPUP_DIRECTION_UP:
663 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
665 case ELM_CTXPOPUP_DIRECTION_LEFT:
666 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
668 case ELM_CTXPOPUP_DIRECTION_RIGHT:
669 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
671 case ELM_CTXPOPUP_DIRECTION_DOWN:
672 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
680 _sizing_eval(Evas_Object *obj)
684 Elm_Ctxpopup_Item *item;
685 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
686 Evas_Coord_Point box_size = { 0, 0 };
687 Evas_Coord_Point _box_size = { 0, 0 };
689 wd = elm_widget_data_get(obj);
693 EINA_LIST_FOREACH(wd->items, elist, item)
695 _item_sizing_eval(item);
696 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
699 if (_box_size.x > box_size.x)
700 box_size.x = _box_size.x;
701 if (_box_size.y != -1)
702 box_size.y += _box_size.y;
706 if (_box_size.x != -1)
707 box_size.x += _box_size.x;
708 if (_box_size.y > box_size.y)
709 box_size.y = _box_size.y;
715 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
716 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
720 wd->dir = _calc_base_geometry(obj, &rect);
721 _show_signal_emit(obj, wd->dir);
722 _update_arrow(obj, wd->dir, rect);
723 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
725 //resize scroller according to final size.
727 evas_object_smart_calculate(wd->scr);
729 evas_object_move(wd->base, rect.x, rect.y);
730 evas_object_resize(wd->base, rect.w, rect.h);
734 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
735 Evas_Coord_Rectangle *rect)
737 Evas_Coord arrow_w, arrow_h;
739 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
743 case ELM_CTXPOPUP_DIRECTION_RIGHT:
746 case ELM_CTXPOPUP_DIRECTION_LEFT:
749 case ELM_CTXPOPUP_DIRECTION_DOWN:
752 case ELM_CTXPOPUP_DIRECTION_UP:
761 _del_pre_hook(Evas_Object *obj)
765 wd = elm_widget_data_get(obj);
768 evas_object_event_callback_del_full(wd->box, EVAS_CALLBACK_RESIZE,
769 _content_resize, obj);
770 _parent_cut_off(obj);
774 _del_hook(Evas_Object *obj)
778 wd = elm_widget_data_get(obj);
781 elm_ctxpopup_clear(obj);
782 evas_object_del(wd->arrow);
783 evas_object_del(wd->base);
787 //FIXME: lost the content size when theme hook is called.
789 _theme_hook(Evas_Object *obj)
793 Elm_Ctxpopup_Item *item;
796 wd = elm_widget_data_get(obj);
799 _elm_widget_mirrored_reload(obj);
800 rtl = elm_widget_mirrored_get(obj);
802 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
803 elm_widget_style_get(obj));
804 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
805 elm_widget_style_get(obj));
806 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
807 elm_widget_style_get(obj));
810 EINA_LIST_FOREACH(wd->items, elist, item)
812 edje_object_mirrored_set(VIEW(item), rtl);
814 if (item->label && item->icon)
815 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
816 "icon_text_style_item",
817 elm_widget_style_get(obj));
818 else if (item->label)
819 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
820 elm_widget_style_get(obj));
822 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
823 elm_widget_style_get(obj));
825 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
827 if (elm_widget_item_disabled_get(item))
828 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
830 edje_object_message_signal_process(VIEW(item));
835 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
836 elm_object_style_set(wd->scr, "ctxpopup");
838 elm_object_style_set(wd->scr, elm_object_style_get(obj));
841 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
845 _scroller_size_reset(wd);
851 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
853 ELM_CHECK_WIDTYPE(obj, widtype);
854 Evas_Coord min_w = -1, min_h = -1;
858 if (part && strcmp(part, "default")) return;
860 wd = elm_widget_data_get(obj);
861 if ((!wd) || (!content)) return;
863 if (wd->items) elm_ctxpopup_clear(obj);
864 if (wd->content) evas_object_del(wd->content);
867 wd->box = elm_box_add(obj);
868 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
870 evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
872 evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
874 evas_object_show(content);
875 evas_object_size_hint_min_get(content, &min_w, &min_h);
876 evas_object_size_hint_min_set(wd->box, min_w, min_h);
877 elm_box_pack_end(wd->box, content);
879 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
880 _content_resize, obj);
881 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
884 elm_widget_sub_object_add(obj, wd->box);
885 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
887 wd->content = content;
888 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
895 _content_unset_hook(Evas_Object *obj, const char *part)
897 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
900 Evas_Object *content;
901 if (part && strcmp(part, "default")) return NULL;
902 wd = elm_widget_data_get(obj);
903 if (!wd) return NULL;
905 content = wd->content;
906 if (!content || !wd->box) return NULL;
908 edje_object_part_unswallow(wd->base, wd->box);
909 elm_widget_sub_object_del(obj, wd->box);
910 evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
911 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
913 evas_object_del(wd->box);
916 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
922 _content_get_hook(const Evas_Object *obj, const char *part)
924 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
926 if (part && strcmp(part, "default")) return NULL;
927 wd = elm_widget_data_get(obj);
928 if (!wd) return NULL;
933 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
936 Elm_Ctxpopup_Item *ctxpopup_it;
938 if (part && strcmp(part, "default")) return;
940 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
942 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
945 _item_label_set(ctxpopup_it, label);
946 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
950 _scroller_size_reset(wd);
951 _sizing_eval(WIDGET(ctxpopup_it));
956 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
958 Elm_Ctxpopup_Item *ctxpopup_it;
959 if (part && strcmp(part, "default")) return NULL;
960 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
961 return ctxpopup_it->label;
965 _item_content_set_hook(Elm_Object_Item *it,
967 Evas_Object *content)
970 Elm_Ctxpopup_Item *ctxpopup_it;
972 if (part && strcmp(part, "icon")) return;
974 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
976 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
979 _item_icon_set(ctxpopup_it, content);
980 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
984 _scroller_size_reset(wd);
985 _sizing_eval(WIDGET(ctxpopup_it));
990 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
992 Elm_Ctxpopup_Item *ctxpopup_it;
993 if (part && strcmp(part, "icon")) return NULL;
994 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
995 return ctxpopup_it->icon;
999 _item_disable_hook(Elm_Object_Item *it)
1002 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1004 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1007 if (elm_widget_item_disabled_get(it))
1008 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
1010 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
1014 _item_signal_emit_hook(Elm_Object_Item *it, const char *emission,
1017 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1018 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
1022 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
1023 const char *emission __UNUSED__, const char *source __UNUSED__)
1025 Widget_Data *wd = elm_widget_data_get(data);
1027 _hide_signal_emit(data, wd->dir);
1031 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1032 void *event_info __UNUSED__)
1036 wd = elm_widget_data_get(obj);
1039 if ((!wd->items) && (!wd->content)) return;
1041 wd->visible = EINA_TRUE;
1043 evas_object_show(wd->bg);
1044 evas_object_show(wd->base);
1045 evas_object_show(wd->arrow);
1047 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
1048 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
1052 elm_object_focus_set(obj, EINA_TRUE);
1056 _hide_finished(void *data, Evas_Object *obj __UNUSED__,
1057 const char *emission __UNUSED__, const char *source __UNUSED__)
1059 evas_object_hide(data);
1060 evas_object_smart_callback_call(data, SIG_DISMISSED, NULL);
1064 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1065 void *event_info __UNUSED__)
1067 Widget_Data *wd = elm_widget_data_get(obj);
1068 if ((!wd) || (!wd->visible)) return;
1070 evas_object_hide(wd->bg);
1071 evas_object_hide(wd->arrow);
1072 evas_object_hide(wd->base);
1074 _scroller_size_reset(wd);
1076 wd->visible = EINA_FALSE;
1080 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1081 void *event_info __UNUSED__)
1083 Widget_Data *wd = elm_widget_data_get(data);
1085 elm_box_recalculate(wd->box);
1090 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1091 void *event_info __UNUSED__)
1096 wd = elm_widget_data_get(data);
1098 if (!wd->visible) return;
1099 if (wd->finished) return;
1101 evas_object_geometry_get(obj, 0, 0, &w, &h);
1103 if (w != 0 && h != 0)
1105 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1108 wd->finished = EINA_TRUE;
1113 if (wd->max_sc_w < w)
1115 if (wd->max_sc_h < h)
1122 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1123 void *event_info __UNUSED__)
1127 wd = elm_widget_data_get(obj);
1132 evas_object_show(wd->arrow);
1134 _scroller_size_reset(wd);
1139 _restack(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1141 Widget_Data *wd = elm_widget_data_get(obj);
1143 evas_object_layer_set(wd->bg,
1144 evas_object_layer_get(obj));
1145 evas_object_layer_set(wd->base,
1146 evas_object_layer_get(obj));
1150 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1151 const char *emission __UNUSED__, const char *source __UNUSED__)
1153 Elm_Ctxpopup_Item *item = data;
1156 if (elm_widget_item_disabled_get(item)) return;
1159 item->func((void*)item->base.data, WIDGET(item), data);
1163 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1166 evas_object_del(item->icon);
1171 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1172 edje_object_message_signal_process(VIEW(item));
1176 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1178 if (!eina_stringshare_replace(&item->label, label))
1181 edje_object_part_text_set(VIEW(item), "elm.text", label);
1182 edje_object_message_signal_process(VIEW(item));
1186 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1190 wd = elm_widget_data_get(WIDGET(item));
1193 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1194 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
1195 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1196 elm_widget_style_get(WIDGET(item)));
1197 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1198 _item_select_cb, item);
1199 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1200 evas_object_show(VIEW(item));
1204 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1205 void *event_info __UNUSED__)
1207 elm_object_content_unset(data);
1211 _list_del(Widget_Data *wd)
1213 if (!wd->scr) return;
1215 edje_object_part_unswallow(wd->base, wd->scr);
1216 evas_object_del(wd->scr);
1222 _list_new(Evas_Object *obj)
1225 wd = elm_widget_data_get(obj);
1229 wd->scr = elm_scroller_add(obj);
1230 elm_object_style_set(wd->scr, "ctxpopup");
1231 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1232 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1233 _scroller_resize, obj);
1234 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1237 wd->box = elm_box_add(obj);
1238 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1241 elm_object_content_set(wd->scr, wd->box);
1242 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1246 _remove_items(Widget_Data *wd)
1249 Elm_Ctxpopup_Item *item;
1251 if (!wd->items) return;
1253 EINA_LIST_FOREACH(wd->items, elist, item)
1256 eina_stringshare_del(item->label);
1258 evas_object_del(item->icon);
1259 wd->items = eina_list_remove(wd->items, item);
1260 elm_widget_item_free(item);
1267 _item_del_pre_hook(Elm_Object_Item *it)
1270 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1272 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1273 if (!wd) return EINA_FALSE;
1275 if (ctxpopup_it->icon)
1276 evas_object_del(ctxpopup_it->icon);
1277 if (VIEW(ctxpopup_it))
1278 evas_object_del(VIEW(ctxpopup_it));
1280 eina_stringshare_del(ctxpopup_it->label);
1282 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1284 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1286 if (eina_list_count(wd->items) < 1)
1288 evas_object_hide(WIDGET(ctxpopup_it));
1293 _sizing_eval(WIDGET(ctxpopup_it));
1299 elm_ctxpopup_add(Evas_Object *parent)
1305 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1307 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1308 elm_widget_type_set(obj, "ctxpopup");
1309 elm_widget_data_set(obj, wd);
1310 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1311 elm_widget_del_hook_set(obj, _del_hook);
1312 elm_widget_theme_hook_set(obj, _theme_hook);
1313 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1314 elm_widget_can_focus_set(obj, EINA_TRUE);
1315 elm_widget_event_hook_set(obj, _event_hook);
1316 elm_widget_content_set_hook_set(obj, _content_set_hook);
1317 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1318 elm_widget_content_get_hook_set(obj, _content_get_hook);
1321 wd->bg = edje_object_add(e);
1322 elm_widget_sub_object_add(obj, wd->bg);
1323 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1324 edje_object_signal_callback_add(wd->bg,
1330 wd->base = edje_object_add(e);
1331 elm_widget_sub_object_add(obj, wd->base);
1332 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1333 edje_object_signal_callback_add(wd->base, "elm,action,hide,finished", "",
1334 _hide_finished, obj);
1337 wd->arrow = edje_object_add(e);
1338 elm_widget_sub_object_add(obj, wd->arrow);
1339 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1341 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1342 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1343 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1344 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1345 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1347 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1349 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1351 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1353 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESTACK, _restack, obj);
1354 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1355 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1356 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1357 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1359 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1361 //default parent is to be hover parent
1362 elm_ctxpopup_hover_parent_set(obj, parent);
1368 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1370 ELM_CHECK_WIDTYPE(obj, widtype);
1373 Evas_Coord x, y, w, h;
1375 wd = elm_widget_data_get(obj);
1376 if ((!wd) || (!parent)) return;
1378 _parent_cut_off(obj);
1382 evas_object_event_callback_add(parent,
1386 evas_object_event_callback_add(parent,
1390 evas_object_event_callback_add(parent,
1391 EVAS_CALLBACK_RESIZE,
1396 elm_widget_sub_object_add(parent, obj);
1397 wd->parent = parent;
1400 evas_object_geometry_get(parent, &x, &y, &w, &h);
1401 evas_object_move(wd->bg, x, y);
1402 evas_object_resize(wd->bg, w, h);
1404 if (wd->visible) _sizing_eval(obj);
1408 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1410 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1414 wd = elm_widget_data_get(obj);
1415 if (!wd) return NULL;
1421 elm_ctxpopup_clear(Evas_Object * obj)
1423 ELM_CHECK_WIDTYPE(obj, widtype);
1425 Widget_Data *wd = elm_widget_data_get(obj);
1430 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1434 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1436 ELM_CHECK_WIDTYPE(obj, widtype);
1440 wd = elm_widget_data_get(obj);
1443 wd->horizontal = !!horizontal;
1445 if ((!wd->scr) && (!wd->box))
1450 elm_box_horizontal_set(wd->box, EINA_FALSE);
1451 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1455 elm_box_horizontal_set(wd->box, EINA_TRUE);
1456 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1459 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1466 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1468 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1472 wd = elm_widget_data_get(obj);
1473 if (!wd) return EINA_FALSE;
1475 return wd->horizontal;
1478 EAPI Elm_Object_Item *
1479 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1480 Evas_Object *icon, Evas_Smart_Cb func,
1483 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1486 Evas_Object *content;
1487 Elm_Ctxpopup_Item *item;
1489 wd = elm_widget_data_get(obj);
1490 if (!wd) return NULL;
1492 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1493 if (!item) return NULL;
1495 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1496 elm_widget_item_disable_hook_set(item, _item_disable_hook);
1497 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1498 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1499 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1500 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1501 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1503 //The first item is appended.
1504 content = elm_object_content_unset(obj);
1505 if (content) evas_object_del(content);
1511 item->base.data = data;
1514 _item_new(item, "icon_text_style_item");
1516 _item_new(item, "text_style_item");
1518 _item_new(item, "icon_style_item");
1520 _item_icon_set(item, icon);
1521 _item_label_set(item, label);
1522 elm_box_pack_end(wd->box, VIEW(item));
1523 wd->items = eina_list_append(wd->items, item);
1524 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1528 _scroller_size_reset(wd);
1532 return (Elm_Object_Item *)item;
1536 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1537 Elm_Ctxpopup_Direction first,
1538 Elm_Ctxpopup_Direction second,
1539 Elm_Ctxpopup_Direction third,
1540 Elm_Ctxpopup_Direction fourth)
1542 ELM_CHECK_WIDTYPE(obj, widtype);
1545 wd = elm_widget_data_get(obj);
1548 wd->dir_priority[0] = first;
1549 wd->dir_priority[1] = second;
1550 wd->dir_priority[2] = third;
1551 wd->dir_priority[3] = fourth;
1558 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1559 Elm_Ctxpopup_Direction *first,
1560 Elm_Ctxpopup_Direction *second,
1561 Elm_Ctxpopup_Direction *third,
1562 Elm_Ctxpopup_Direction *fourth)
1564 ELM_CHECK_WIDTYPE(obj, widtype);
1567 wd = elm_widget_data_get(obj);
1570 if (first) *first = wd->dir_priority[0];
1571 if (second) *second = wd->dir_priority[1];
1572 if (third) *third = wd->dir_priority[2];
1573 if (fourth) *fourth = wd->dir_priority[3];
1576 EAPI Elm_Ctxpopup_Direction
1577 elm_ctxpopup_direction_get(const Evas_Object *obj)
1579 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1582 wd = elm_widget_data_get(obj);
1583 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1588 elm_ctxpopup_dismiss(Evas_Object *obj)
1590 ELM_CHECK_WIDTYPE(obj, widtype);
1591 Widget_Data *wd = elm_widget_data_get(obj);
1593 _hide_signal_emit(obj, wd->dir);