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_set_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 _item_select_cb(void *data, Evas_Object *obj,
123 const char *emission,
125 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
126 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
127 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
128 static void _content_del(void *data,
132 static void _list_del(Widget_Data *wd);
133 static void _list_new(Evas_Object *obj);
134 static void _remove_items(Widget_Data * wd);
136 static const char SIG_DISMISSED[] = "dismissed";
138 static const Evas_Smart_Cb_Description _signals[] = {
144 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
145 void *event_info __UNUSED__)
147 Widget_Data *wd = elm_widget_data_get(obj);
149 if ((!wd) || (!wd->scr)) return;
150 elm_object_scroll_freeze_push(wd->scr);
154 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
155 void *event_info __UNUSED__)
157 Widget_Data *wd = elm_widget_data_get(obj);
159 if ((!wd) || (!wd->scr)) return;
160 elm_object_scroll_freeze_pop(wd->scr);
164 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
166 Widget_Data *wd = elm_widget_data_get(obj);
168 if ((!wd) || (!wd->scr)) return;
169 elm_object_scroll_hold_push(wd->scr);
173 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
175 Widget_Data *wd = elm_widget_data_get(obj);
177 if ((!wd) || (!wd->scr)) return;
178 elm_object_scroll_hold_pop(wd->scr);
182 _scroller_size_reset(Widget_Data *wd)
184 wd->finished = EINA_FALSE;
190 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
192 Widget_Data *wd = elm_widget_data_get(obj);
195 if (elm_widget_focus_get(obj))
206 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
207 Evas_Callback_Type type, void *event_info)
209 Evas_Event_Key_Down *ev;
212 if (type != EVAS_CALLBACK_KEY_DOWN)
214 wd = elm_widget_data_get(obj);
215 if (!wd) return EINA_FALSE;
218 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
219 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
221 evas_object_hide(obj);
222 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
227 _parent_cut_off(Evas_Object *obj)
229 Widget_Data *wd = elm_widget_data_get(obj);
233 evas_object_event_callback_del_full(wd->parent,
237 evas_object_event_callback_del_full(wd->parent,
241 evas_object_event_callback_del_full(wd->parent,
242 EVAS_CALLBACK_RESIZE,
246 elm_widget_sub_object_del(wd->parent, obj);
250 _parent_resize(void *data,
252 Evas_Object *obj __UNUSED__,
253 void *event_info __UNUSED__)
255 Widget_Data *wd = elm_widget_data_get(data);
258 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
264 _parent_move(void *data,
266 Evas_Object *obj __UNUSED__,
267 void *event_info __UNUSED__)
269 Widget_Data *wd = elm_widget_data_get(data);
273 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
277 _scroller_size_reset(wd);
283 _parent_del(void *data,
285 Evas_Object *obj __UNUSED__,
286 void *event_info __UNUSED__)
288 evas_object_del(data);
292 _item_sizing_eval(Elm_Ctxpopup_Item *item)
294 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
298 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
300 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
301 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
305 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
306 Evas_Coord_Rectangle *hover_area)
308 pos->x -= (base_size->x / 2);
310 if (pos->x < hover_area->x)
311 pos->x = hover_area->x;
312 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
313 pos->x = (hover_area->x + hover_area->w) - base_size->x;
315 if (base_size->x > hover_area->w)
316 base_size->x -= (base_size->x - hover_area->w);
318 if (pos->x < hover_area->x)
319 pos->x = hover_area->x;
323 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
324 Evas_Coord_Rectangle *hover_area)
326 pos->y -= (base_size->y / 2);
328 if (pos->y < hover_area->y)
329 pos->y = hover_area->y;
330 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
331 pos->y = hover_area->y + hover_area->h - base_size->y;
333 if (base_size->y > hover_area->h)
334 base_size->y -= (base_size->y - hover_area->h);
336 if (pos->y < hover_area->y)
337 pos->y = hover_area->y;
340 static Elm_Ctxpopup_Direction
341 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
344 Evas_Coord_Point pos = {0, 0};
345 Evas_Coord_Point base_size;
346 Evas_Coord_Point max_size;
347 Evas_Coord_Point min_size;
348 Evas_Coord_Rectangle hover_area;
349 Evas_Coord_Point arrow_size;
350 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
351 Evas_Coord_Point temp;
354 wd = elm_widget_data_get(obj);
356 if ((!wd) || (!rect))
357 return ELM_CTXPOPUP_DIRECTION_DOWN;
359 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
360 &arrow_size.x, &arrow_size.y);
361 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
363 //Initialize Area Rectangle.
364 evas_object_geometry_get(wd->parent,
370 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
373 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
374 evas_object_smart_calculate(wd->base);
377 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
379 if ((max_size.y > 0) && (base_size.y > max_size.y))
380 base_size.y = max_size.y;
382 if ((max_size.x > 0) && (base_size.x > max_size.x))
383 base_size.x = max_size.x;
386 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
388 if ((min_size.y > 0) && (base_size.y < min_size.y))
389 base_size.y = min_size.y;
391 if ((min_size.x > 0) && (base_size.x < min_size.x))
392 base_size.x = min_size.x;
394 //Check the Which direction is available.
395 //If find a avaialble direction, it adjusts position and size.
396 for (idx = 0; idx < 4; idx++)
398 switch (wd->dir_priority[idx])
400 case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
401 case ELM_CTXPOPUP_DIRECTION_UP:
402 temp.y = (pos.y - base_size.y);
403 if ((temp.y - arrow_size.y) < hover_area.y)
405 _adjust_pos_x(&pos, &base_size, &hover_area);
406 pos.y -= base_size.y;
407 dir = ELM_CTXPOPUP_DIRECTION_UP;
409 case ELM_CTXPOPUP_DIRECTION_LEFT:
410 temp.x = (pos.x - base_size.x);
411 if ((temp.x - arrow_size.x) < hover_area.x)
413 _adjust_pos_y(&pos, &base_size, &hover_area);
414 pos.x -= base_size.x;
415 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
417 case ELM_CTXPOPUP_DIRECTION_RIGHT:
418 temp.x = (pos.x + base_size.x);
419 if ((temp.x + arrow_size.x) >
420 (hover_area.x + hover_area.w))
422 _adjust_pos_y(&pos, &base_size, &hover_area);
423 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
425 case ELM_CTXPOPUP_DIRECTION_DOWN:
426 temp.y = (pos.y + base_size.y);
427 if ((temp.y + arrow_size.y) >
428 (hover_area.y + hover_area.h))
430 _adjust_pos_x(&pos, &base_size, &hover_area);
431 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
439 //In this case, all directions are invalid because of lack of space.
442 Evas_Coord length[2];
446 length[0] = pos.y - hover_area.y;
447 length[1] = (hover_area.y + hover_area.h) - pos.y;
449 // ELM_CTXPOPUP_DIRECTION_UP
450 if (length[0] > length[1])
452 _adjust_pos_x(&pos, &base_size, &hover_area);
453 pos.y -= base_size.y;
454 dir = ELM_CTXPOPUP_DIRECTION_UP;
455 if (pos.y < (hover_area.y + arrow_size.y))
457 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
458 pos.y = hover_area.y + arrow_size.y;
461 //ELM_CTXPOPUP_DIRECTION_DOWN
464 _adjust_pos_x(&pos, &base_size, &hover_area);
465 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
466 if ((pos.y + arrow_size.y + base_size.y) >
467 (hover_area.y + hover_area.h))
469 ((pos.y + arrow_size.y + base_size.y) -
470 (hover_area.y + hover_area.h));
475 length[0] = pos.x - hover_area.x;
476 length[1] = (hover_area.x + hover_area.w) - pos.x;
478 //ELM_CTXPOPUP_DIRECTION_LEFT
479 if (length[0] > length[1])
481 _adjust_pos_y(&pos, &base_size, &hover_area);
482 pos.x -= base_size.x;
483 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
484 if (pos.x < (hover_area.x + arrow_size.x))
486 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
487 pos.x = hover_area.x + arrow_size.x;
490 //ELM_CTXPOPUP_DIRECTION_RIGHT
493 _adjust_pos_y(&pos, &base_size, &hover_area);
494 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
495 if (pos.x + (arrow_size.x + base_size.x) >
496 hover_area.x + hover_area.w)
498 ((pos.x + arrow_size.x + base_size.x) -
499 (hover_area.x + hover_area.w));
504 //Final position and size.
507 rect->w = base_size.x;
508 rect->h = base_size.y;
514 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
515 Evas_Coord_Rectangle base_size)
518 Evas_Coord_Rectangle arrow_size;
522 wd = elm_widget_data_get(obj);
525 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
526 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
529 edje_object_part_unswallow(wd->base, wd->arrow);
533 case ELM_CTXPOPUP_DIRECTION_RIGHT:
534 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
535 edje_object_part_swallow(wd->base,
536 "elm.swallow.arrow_left",
540 if (y < ((arrow_size.h * 0.5) + base_size.y))
542 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
543 y = base_size.h - arrow_size.h;
545 y = y - base_size.y - (arrow_size.h * 0.5);
546 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
547 edje_object_part_drag_value_set(wd->base,
548 "elm.swallow.arrow_left",
553 case ELM_CTXPOPUP_DIRECTION_LEFT:
554 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
555 edje_object_part_swallow(wd->base,
556 "elm.swallow.arrow_right",
560 if (y < ((arrow_size.h * 0.5) + base_size.y))
562 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
563 y = base_size.h - arrow_size.h;
565 y = y - base_size.y - (arrow_size.h * 0.5);
566 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
567 edje_object_part_drag_value_set(wd->base,
568 "elm.swallow.arrow_right",
573 case ELM_CTXPOPUP_DIRECTION_DOWN:
574 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
575 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
578 if (x < ((arrow_size.w * 0.5) + base_size.x))
580 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
581 x = base_size.w - arrow_size.w;
583 x = x - base_size.x - (arrow_size.w * 0.5);
584 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
585 edje_object_part_drag_value_set(wd->base,
586 "elm.swallow.arrow_up",
591 case ELM_CTXPOPUP_DIRECTION_UP:
592 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
593 edje_object_part_swallow(wd->base,
594 "elm.swallow.arrow_down",
598 if (x < ((arrow_size.w * 0.5) + base_size.x))
600 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
601 x = base_size.w - arrow_size.w;
602 else x = x - base_size.x - (arrow_size.w * 0.5);
603 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
604 edje_object_part_drag_value_set(wd->base,
605 "elm.swallow.arrow_down",
616 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
620 wd = elm_widget_data_get(obj);
621 if (!wd || wd->visible) return;
625 case ELM_CTXPOPUP_DIRECTION_UP:
626 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
628 case ELM_CTXPOPUP_DIRECTION_LEFT:
629 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
631 case ELM_CTXPOPUP_DIRECTION_RIGHT:
632 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
634 case ELM_CTXPOPUP_DIRECTION_DOWN:
635 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
643 _sizing_eval(Evas_Object *obj)
647 Elm_Ctxpopup_Item *item;
648 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
649 Evas_Coord_Point box_size = { 0, 0 };
650 Evas_Coord_Point _box_size = { 0, 0 };
652 wd = elm_widget_data_get(obj);
656 EINA_LIST_FOREACH(wd->items, elist, item)
658 _item_sizing_eval(item);
659 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
662 if (_box_size.x > box_size.x)
663 box_size.x = _box_size.x;
664 if (_box_size.y != -1)
665 box_size.y += _box_size.y;
669 if (_box_size.x != -1)
670 box_size.x += _box_size.x;
671 if (_box_size.y > box_size.y)
672 box_size.y = _box_size.y;
678 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
679 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
683 wd->dir = _calc_base_geometry(obj, &rect);
684 _show_signal_emit(obj, wd->dir);
685 _update_arrow(obj, wd->dir, rect);
686 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
688 //resize scroller according to final size.
690 evas_object_smart_calculate(wd->scr);
692 evas_object_move(wd->base, rect.x, rect.y);
693 evas_object_resize(wd->base, rect.w, rect.h);
697 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
698 Evas_Coord_Rectangle *rect)
700 Evas_Coord arrow_w, arrow_h;
702 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
706 case ELM_CTXPOPUP_DIRECTION_RIGHT:
709 case ELM_CTXPOPUP_DIRECTION_LEFT:
712 case ELM_CTXPOPUP_DIRECTION_DOWN:
715 case ELM_CTXPOPUP_DIRECTION_UP:
724 _del_pre_hook(Evas_Object *obj)
728 wd = elm_widget_data_get(obj);
731 _parent_cut_off(obj);
735 _del_hook(Evas_Object *obj)
739 wd = elm_widget_data_get(obj);
742 elm_ctxpopup_clear(obj);
743 evas_object_del(wd->arrow);
744 evas_object_del(wd->base);
748 //FIXME: lost the content size when theme hook is called.
750 _theme_hook(Evas_Object *obj)
754 Elm_Ctxpopup_Item *item;
757 wd = elm_widget_data_get(obj);
760 _elm_widget_mirrored_reload(obj);
761 rtl = elm_widget_mirrored_get(obj);
763 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
764 elm_widget_style_get(obj));
765 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
766 elm_widget_style_get(obj));
767 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
768 elm_widget_style_get(obj));
771 EINA_LIST_FOREACH(wd->items, elist, item)
773 edje_object_mirrored_set(VIEW(item), rtl);
775 if (item->label && item->icon)
776 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
777 "icon_text_style_item",
778 elm_widget_style_get(obj));
779 else if (item->label)
780 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
781 elm_widget_style_get(obj));
783 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
784 elm_widget_style_get(obj));
786 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
788 if (elm_widget_item_disabled_get(item))
789 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
791 edje_object_message_signal_process(VIEW(item));
796 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
797 elm_object_style_set(wd->scr, "ctxpopup");
799 elm_object_style_set(wd->scr, elm_object_style_get(obj));
802 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
806 _scroller_size_reset(wd);
812 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
814 ELM_CHECK_WIDTYPE(obj, widtype);
815 Evas_Coord min_w = -1, min_h = -1;
819 if (part && strcmp(part, "default")) return;
821 wd = elm_widget_data_get(obj);
822 if ((!wd) || (!content)) return;
824 if (wd->items) elm_ctxpopup_clear(obj);
825 if (wd->content) evas_object_del(wd->content);
828 wd->box = elm_box_add(obj);
829 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
831 evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
833 evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
835 evas_object_show(content);
836 evas_object_size_hint_min_get(content, &min_w, &min_h);
837 evas_object_size_hint_min_set(wd->box, min_w, min_h);
838 elm_box_pack_end(wd->box, content);
840 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
841 _content_resize, obj);
842 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
845 elm_widget_sub_object_add(obj, wd->box);
846 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
848 wd->content = content;
849 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
856 _content_unset_hook(Evas_Object *obj, const char *part)
858 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
861 Evas_Object *content;
862 if (part && strcmp(part, "default")) return NULL;
863 wd = elm_widget_data_get(obj);
864 if (!wd) return NULL;
866 content = wd->content;
867 if (!content || !wd->box) return NULL;
869 edje_object_part_unswallow(wd->base, wd->box);
870 elm_widget_sub_object_del(obj, wd->box);
871 evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
872 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
874 evas_object_del(wd->box);
877 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
883 _content_get_hook(const Evas_Object *obj, const char *part)
885 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
887 if (part && strcmp(part, "default")) return NULL;
888 wd = elm_widget_data_get(obj);
889 if (!wd) return NULL;
894 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
896 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
899 Elm_Ctxpopup_Item *ctxpopup_it;
901 if (part && strcmp(part, "default")) return;
903 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
905 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
908 _item_label_set(ctxpopup_it, label);
909 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
913 _scroller_size_reset(wd);
914 _sizing_eval(WIDGET(ctxpopup_it));
919 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
921 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
922 Elm_Ctxpopup_Item *ctxpopup_it;
923 if (part && strcmp(part, "default")) return NULL;
924 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
925 return ctxpopup_it->label;
929 _item_content_set_hook(Elm_Object_Item *it,
931 Evas_Object *content)
933 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
935 Elm_Ctxpopup_Item *ctxpopup_it;
937 if (part && strcmp(part, "icon")) return;
939 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
941 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
944 _item_icon_set(ctxpopup_it, content);
945 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
949 _scroller_size_reset(wd);
950 _sizing_eval(WIDGET(ctxpopup_it));
955 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
957 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
958 Elm_Ctxpopup_Item *ctxpopup_it;
959 if (part && strcmp(part, "icon")) return NULL;
960 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
961 return ctxpopup_it->icon;
965 _item_disable_set_hook(Elm_Object_Item *it)
967 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
970 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
972 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
975 if (elm_widget_item_disabled_get(it))
976 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
978 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
982 _item_signal_emit_hook(Elm_Object_Item *it, const char *emission,
985 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
986 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
987 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
991 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
992 const char *emission __UNUSED__, const char *source __UNUSED__)
994 evas_object_hide(data);
998 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
999 void *event_info __UNUSED__)
1003 wd = elm_widget_data_get(obj);
1006 if ((!wd->items) && (!wd->content)) return;
1008 wd->visible = EINA_TRUE;
1010 evas_object_show(wd->bg);
1011 evas_object_show(wd->base);
1012 evas_object_show(wd->arrow);
1014 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
1015 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
1019 elm_object_focus_set(obj, EINA_TRUE);
1023 _hide(Evas_Object *obj)
1025 Widget_Data *wd = elm_widget_data_get(obj);
1027 if ((!wd) || (!wd->visible)) return;
1029 evas_object_hide(wd->bg);
1030 evas_object_hide(wd->arrow);
1031 evas_object_hide(wd->base);
1033 _scroller_size_reset(wd);
1035 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1036 wd->visible = EINA_FALSE;
1040 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1041 void *event_info __UNUSED__)
1047 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1048 void *event_info __UNUSED__)
1050 Widget_Data *wd = elm_widget_data_get(data);
1052 elm_box_recalculate(wd->box);
1057 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1058 void *event_info __UNUSED__)
1063 wd = elm_widget_data_get(data);
1065 if (!wd->visible) return;
1066 if (wd->finished) return;
1068 evas_object_geometry_get(obj, 0, 0, &w, &h);
1070 if (w != 0 && h != 0)
1072 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1075 wd->finished = EINA_TRUE;
1080 if (wd->max_sc_w < w)
1082 if (wd->max_sc_h < h)
1089 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1090 void *event_info __UNUSED__)
1094 wd = elm_widget_data_get(obj);
1099 evas_object_show(wd->arrow);
1101 _scroller_size_reset(wd);
1106 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1107 const char *emission __UNUSED__, const char *source __UNUSED__)
1109 Elm_Ctxpopup_Item *item = data;
1112 if (elm_widget_item_disabled_get(item)) return;
1115 item->func((void*) item->base.data, WIDGET(item), data);
1119 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1122 evas_object_del(item->icon);
1127 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1128 edje_object_message_signal_process(VIEW(item));
1132 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1134 if (!eina_stringshare_replace(&item->label, label))
1137 edje_object_part_text_set(VIEW(item), "elm.text", label);
1138 edje_object_message_signal_process(VIEW(item));
1142 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1146 wd = elm_widget_data_get(WIDGET(item));
1149 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1150 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
1151 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1152 elm_widget_style_get(WIDGET(item)));
1153 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1154 _item_select_cb, item);
1155 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1156 evas_object_show(VIEW(item));
1160 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1161 void *event_info __UNUSED__)
1163 elm_object_content_unset(data);
1167 _list_del(Widget_Data *wd)
1169 if (!wd->scr) return;
1171 edje_object_part_unswallow(wd->base, wd->scr);
1172 evas_object_del(wd->scr);
1178 _list_new(Evas_Object *obj)
1181 wd = elm_widget_data_get(obj);
1185 wd->scr = elm_scroller_add(obj);
1186 elm_object_style_set(wd->scr, "ctxpopup");
1187 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1188 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1189 _scroller_resize, obj);
1190 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1193 wd->box = elm_box_add(obj);
1194 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1197 elm_object_content_set(wd->scr, wd->box);
1198 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1202 _remove_items(Widget_Data *wd)
1205 Elm_Ctxpopup_Item *item;
1207 if (!wd->items) return;
1209 EINA_LIST_FOREACH(wd->items, elist, item)
1212 eina_stringshare_del(item->label);
1214 evas_object_del(item->icon);
1215 wd->items = eina_list_remove(wd->items, item);
1223 elm_ctxpopup_add(Evas_Object *parent)
1229 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1231 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1232 elm_widget_type_set(obj, "ctxpopup");
1233 elm_widget_data_set(obj, wd);
1234 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1235 elm_widget_del_hook_set(obj, _del_hook);
1236 elm_widget_theme_hook_set(obj, _theme_hook);
1237 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1238 elm_widget_can_focus_set(obj, EINA_TRUE);
1239 elm_widget_event_hook_set(obj, _event_hook);
1240 elm_widget_content_set_hook_set(obj, _content_set_hook);
1241 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1242 elm_widget_content_get_hook_set(obj, _content_get_hook);
1245 wd->bg = edje_object_add(e);
1246 elm_widget_sub_object_add(obj, wd->bg);
1247 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1248 edje_object_signal_callback_add(wd->bg,
1254 wd->base = edje_object_add(e);
1255 elm_widget_sub_object_add(obj, wd->base);
1256 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1259 wd->arrow = edje_object_add(e);
1260 elm_widget_sub_object_add(obj, wd->arrow);
1261 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1263 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1264 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1265 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1266 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1267 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1269 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1271 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1273 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1275 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1276 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1277 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1278 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1280 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1282 //default parent is to be hover parent
1283 elm_ctxpopup_hover_parent_set(obj, parent);
1289 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1291 return _item_content_get_hook(it, "icon");
1295 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1297 _item_content_set_hook(it, "icon", icon);
1301 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1303 return _item_text_get_hook(it, NULL);
1307 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1309 _item_text_set_hook(it, NULL, label);
1313 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1315 ELM_CHECK_WIDTYPE(obj, widtype);
1318 Evas_Coord x, y, w, h;
1320 wd = elm_widget_data_get(obj);
1321 if ((!wd) || (!parent)) return;
1323 _parent_cut_off(obj);
1327 evas_object_event_callback_add(parent,
1331 evas_object_event_callback_add(parent,
1335 evas_object_event_callback_add(parent,
1336 EVAS_CALLBACK_RESIZE,
1341 elm_widget_sub_object_add(parent, obj);
1342 wd->parent = parent;
1345 evas_object_geometry_get(parent, &x, &y, &w, &h);
1346 evas_object_move(wd->bg, x, y);
1347 evas_object_resize(wd->bg, w, h);
1349 if (wd->visible) _sizing_eval(obj);
1353 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1355 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1359 wd = elm_widget_data_get(obj);
1360 if (!wd) return NULL;
1366 elm_ctxpopup_clear(Evas_Object * obj)
1368 ELM_CHECK_WIDTYPE(obj, widtype);
1370 Widget_Data *wd = elm_widget_data_get(obj);
1375 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1379 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1381 ELM_CHECK_WIDTYPE(obj, widtype);
1385 wd = elm_widget_data_get(obj);
1388 wd->horizontal = !!horizontal;
1390 if ((!wd->scr) && (!wd->box))
1395 elm_box_horizontal_set(wd->box, EINA_FALSE);
1396 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1400 elm_box_horizontal_set(wd->box, EINA_TRUE);
1401 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1404 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1411 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1413 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1417 wd = elm_widget_data_get(obj);
1418 if (!wd) return EINA_FALSE;
1420 return wd->horizontal;
1423 EAPI Elm_Object_Item *
1424 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1425 Evas_Object *icon, Evas_Smart_Cb func,
1428 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1431 Evas_Object *content;
1432 Elm_Ctxpopup_Item *item;
1434 wd = elm_widget_data_get(obj);
1435 if (!wd) return NULL;
1437 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1438 if (!item) return NULL;
1440 elm_widget_item_disable_set_hook_set(item, _item_disable_set_hook);
1441 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1442 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1443 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1444 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1445 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1447 //The first item is appended.
1448 content = elm_object_content_unset(obj);
1449 if (content) evas_object_del(content);
1455 item->base.data = data;
1458 _item_new(item, "icon_text_style_item");
1460 _item_new(item, "text_style_item");
1462 _item_new(item, "icon_style_item");
1464 _item_icon_set(item, icon);
1465 _item_label_set(item, label);
1466 elm_box_pack_end(wd->box, VIEW(item));
1467 wd->items = eina_list_append(wd->items, item);
1468 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1472 _scroller_size_reset(wd);
1476 return (Elm_Object_Item *) item;
1480 elm_ctxpopup_item_del(Elm_Object_Item *it)
1482 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1485 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1487 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1490 if (ctxpopup_it->icon)
1491 evas_object_del(ctxpopup_it->icon);
1492 if (VIEW(ctxpopup_it))
1493 evas_object_del(VIEW(ctxpopup_it));
1495 eina_stringshare_del(ctxpopup_it->label);
1497 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1499 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1501 elm_widget_item_del(ctxpopup_it);
1503 if (eina_list_count(wd->items) < 1)
1505 evas_object_hide(WIDGET(ctxpopup_it));
1510 _sizing_eval(WIDGET(ctxpopup_it));
1515 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1517 elm_object_item_disabled_set(it, disabled);
1521 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1523 return elm_object_item_disabled_get(it);
1527 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1529 elm_object_content_set(obj, content);
1533 elm_ctxpopup_content_unset(Evas_Object *obj)
1535 return elm_object_content_unset(obj);
1539 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1540 Elm_Ctxpopup_Direction first,
1541 Elm_Ctxpopup_Direction second,
1542 Elm_Ctxpopup_Direction third,
1543 Elm_Ctxpopup_Direction fourth)
1545 ELM_CHECK_WIDTYPE(obj, widtype);
1548 wd = elm_widget_data_get(obj);
1551 wd->dir_priority[0] = first;
1552 wd->dir_priority[1] = second;
1553 wd->dir_priority[2] = third;
1554 wd->dir_priority[3] = fourth;
1561 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1562 Elm_Ctxpopup_Direction *first,
1563 Elm_Ctxpopup_Direction *second,
1564 Elm_Ctxpopup_Direction *third,
1565 Elm_Ctxpopup_Direction *fourth)
1567 ELM_CHECK_WIDTYPE(obj, widtype);
1570 wd = elm_widget_data_get(obj);
1573 if (first) *first = wd->dir_priority[0];
1574 if (second) *second = wd->dir_priority[1];
1575 if (third) *third = wd->dir_priority[2];
1576 if (fourth) *fourth = wd->dir_priority[3];
1579 EAPI Elm_Ctxpopup_Direction
1580 elm_ctxpopup_direction_get(const Evas_Object *obj)
1582 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1585 wd = elm_widget_data_get(obj);
1586 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;