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, Elm_Ctxpopup_Direction dir);
68 static void _sizing_eval(Evas_Object *obj);
69 static void _shift_base_by_arrow(Evas_Object *arrow,
70 Elm_Ctxpopup_Direction dir,
71 Evas_Coord_Rectangle *rect);
72 static void _del_pre_hook(Evas_Object *obj);
73 static void _del_hook(Evas_Object *obj);
74 static void _theme_hook(Evas_Object *obj);
75 static void _content_set_hook(Evas_Object *obj,
77 Evas_Object *content);
78 static Evas_Object * _content_unset_hook(Evas_Object *obj,
80 static Evas_Object * _content_get_hook(const Evas_Object *obj,
82 static void _item_text_set_hook(Elm_Object_Item *it,
85 static const char * _item_text_get_hook(const Elm_Object_Item *it,
87 static void _item_content_set_hook(Elm_Object_Item *it,
89 Evas_Object *content);
90 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
92 static void _item_disable_set_hook(Elm_Object_Item *it);
93 static void _item_signal_emit_hook(Elm_Object_Item *it,
96 static void _bg_clicked_cb(void *data, Evas_Object *obj,
99 static void _ctxpopup_show(void *data,
103 static void _hide(Evas_Object *obj);
104 static void _ctxpopup_hide(void *data,
108 static void _scroller_resize(void *data,
112 static void _ctxpopup_move(void *data,
116 static void _item_select_cb(void *data, Evas_Object *obj,
117 const char *emission,
119 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
120 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
121 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
122 static void _content_del(void *data,
126 static void _list_del(Widget_Data *wd);
127 static void _list_new(Evas_Object *obj);
128 static void _remove_items(Widget_Data * wd);
130 static const char SIG_DISMISSED[] = "dismissed";
132 static const Evas_Smart_Cb_Description _signals[] = {
138 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
139 void *event_info __UNUSED__)
141 Widget_Data *wd = elm_widget_data_get(obj);
143 if ((!wd) || (!wd->scr)) return;
144 elm_object_scroll_freeze_push(wd->scr);
148 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
149 void *event_info __UNUSED__)
151 Widget_Data *wd = elm_widget_data_get(obj);
153 if ((!wd) || (!wd->scr)) return;
154 elm_object_scroll_freeze_pop(wd->scr);
158 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
160 Widget_Data *wd = elm_widget_data_get(obj);
162 if ((!wd) || (!wd->scr)) return;
163 elm_object_scroll_hold_push(wd->scr);
167 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
169 Widget_Data *wd = elm_widget_data_get(obj);
171 if ((!wd) || (!wd->scr)) return;
172 elm_object_scroll_hold_pop(wd->scr);
176 _scroller_size_reset(Widget_Data *wd)
178 wd->finished = EINA_FALSE;
184 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
186 Widget_Data *wd = elm_widget_data_get(obj);
189 if (elm_widget_focus_get(obj))
200 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
202 Evas_Event_Key_Down *ev;
205 if (type != EVAS_CALLBACK_KEY_DOWN)
207 wd = elm_widget_data_get(obj);
208 if (!wd) return EINA_FALSE;
211 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
212 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
214 evas_object_hide(obj);
215 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
220 _parent_cut_off(Evas_Object *obj)
222 Widget_Data *wd = elm_widget_data_get(obj);
226 evas_object_event_callback_del_full(wd->parent,
230 evas_object_event_callback_del_full(wd->parent,
234 evas_object_event_callback_del_full(wd->parent,
235 EVAS_CALLBACK_RESIZE,
239 elm_widget_sub_object_del(wd->parent, obj);
243 _parent_resize(void *data,
245 Evas_Object *obj __UNUSED__,
246 void *event_info __UNUSED__)
248 Widget_Data *wd = elm_widget_data_get(data);
251 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
257 _parent_move(void *data,
259 Evas_Object *obj __UNUSED__,
260 void *event_info __UNUSED__)
262 Widget_Data *wd = elm_widget_data_get(data);
266 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
270 _scroller_size_reset(wd);
276 _parent_del(void *data,
278 Evas_Object *obj __UNUSED__,
279 void *event_info __UNUSED__)
281 evas_object_del(data);
285 _item_sizing_eval(Elm_Ctxpopup_Item *item)
287 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
291 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
293 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
294 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
298 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
299 Evas_Coord_Rectangle *hover_area)
301 pos->x -= (base_size->x / 2);
303 if (pos->x < hover_area->x)
304 pos->x = hover_area->x;
305 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
306 pos->x = (hover_area->x + hover_area->w) - base_size->x;
308 if (base_size->x > hover_area->w)
309 base_size->x -= (base_size->x - hover_area->w);
311 if (pos->x < hover_area->x)
312 pos->x = hover_area->x;
316 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
317 Evas_Coord_Rectangle *hover_area)
319 pos->y -= (base_size->y / 2);
321 if (pos->y < hover_area->y)
322 pos->y = hover_area->y;
323 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
324 pos->y = hover_area->y + hover_area->h - base_size->y;
326 if (base_size->y > hover_area->h)
327 base_size->y -= (base_size->y - hover_area->h);
329 if (pos->y < hover_area->y)
330 pos->y = hover_area->y;
333 static Elm_Ctxpopup_Direction
334 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
337 Evas_Coord_Point pos = {0, 0};
338 Evas_Coord_Point base_size;
339 Evas_Coord_Point max_size;
340 Evas_Coord_Point min_size;
341 Evas_Coord_Rectangle hover_area;
342 Evas_Coord_Point arrow_size;
343 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
344 Evas_Coord_Point temp;
347 wd = elm_widget_data_get(obj);
349 if ((!wd) || (!rect))
350 return ELM_CTXPOPUP_DIRECTION_DOWN;
352 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
353 &arrow_size.x, &arrow_size.y);
354 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
356 //Initialize Area Rectangle.
357 evas_object_geometry_get(wd->parent,
363 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
366 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
367 evas_object_smart_calculate(wd->base);
370 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
372 if ((max_size.y > 0) && (base_size.y > max_size.y))
373 base_size.y = max_size.y;
375 if ((max_size.x > 0) && (base_size.x > max_size.x))
376 base_size.x = max_size.x;
379 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
381 if ((min_size.y > 0) && (base_size.y < min_size.y))
382 base_size.y = min_size.y;
384 if ((min_size.x > 0) && (base_size.x < min_size.x))
385 base_size.x = min_size.x;
387 //Check the Which direction is available.
388 //If find a avaialble direction, it adjusts position and size.
389 for (idx = 0; idx < 4; idx++)
391 switch (wd->dir_priority[idx])
393 case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
394 case ELM_CTXPOPUP_DIRECTION_UP:
395 temp.y = (pos.y - base_size.y);
396 if ((temp.y - arrow_size.y) < hover_area.y)
398 _adjust_pos_x(&pos, &base_size, &hover_area);
399 pos.y -= base_size.y;
400 dir = ELM_CTXPOPUP_DIRECTION_UP;
402 case ELM_CTXPOPUP_DIRECTION_LEFT:
403 temp.x = (pos.x - base_size.x);
404 if ((temp.x - arrow_size.x) < hover_area.x)
406 _adjust_pos_y(&pos, &base_size, &hover_area);
407 pos.x -= base_size.x;
408 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
410 case ELM_CTXPOPUP_DIRECTION_RIGHT:
411 temp.x = (pos.x + base_size.x);
412 if ((temp.x + arrow_size.x) >
413 (hover_area.x + hover_area.w))
415 _adjust_pos_y(&pos, &base_size, &hover_area);
416 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
418 case ELM_CTXPOPUP_DIRECTION_DOWN:
419 temp.y = (pos.y + base_size.y);
420 if ((temp.y + arrow_size.y) >
421 (hover_area.y + hover_area.h))
423 _adjust_pos_x(&pos, &base_size, &hover_area);
424 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
432 //In this case, all directions are invalid because of lack of space.
435 Evas_Coord length[2];
439 length[0] = pos.y - hover_area.y;
440 length[1] = (hover_area.y + hover_area.h) - pos.y;
442 // ELM_CTXPOPUP_DIRECTION_UP
443 if (length[0] > length[1])
445 _adjust_pos_x(&pos, &base_size, &hover_area);
446 pos.y -= base_size.y;
447 dir = ELM_CTXPOPUP_DIRECTION_UP;
448 if (pos.y < (hover_area.y + arrow_size.y))
450 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
451 pos.y = hover_area.y + arrow_size.y;
454 //ELM_CTXPOPUP_DIRECTION_DOWN
457 _adjust_pos_x(&pos, &base_size, &hover_area);
458 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
459 if ((pos.y + arrow_size.y + base_size.y) >
460 (hover_area.y + hover_area.h))
462 ((pos.y + arrow_size.y + base_size.y) -
463 (hover_area.y + hover_area.h));
468 length[0] = pos.x - hover_area.x;
469 length[1] = (hover_area.x + hover_area.w) - pos.x;
471 //ELM_CTXPOPUP_DIRECTION_LEFT
472 if (length[0] > length[1])
474 _adjust_pos_y(&pos, &base_size, &hover_area);
475 pos.x -= base_size.x;
476 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
477 if (pos.x < (hover_area.x + arrow_size.x))
479 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
480 pos.x = hover_area.x + arrow_size.x;
483 //ELM_CTXPOPUP_DIRECTION_RIGHT
486 _adjust_pos_y(&pos, &base_size, &hover_area);
487 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
488 if (pos.x + (arrow_size.x + base_size.x) >
489 hover_area.x + hover_area.w)
491 ((pos.x + arrow_size.x + base_size.x) -
492 (hover_area.x + hover_area.w));
497 //Final position and size.
500 rect->w = base_size.x;
501 rect->h = base_size.y;
507 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
510 Evas_Coord_Rectangle arrow_size;
511 Evas_Coord_Rectangle base_size;
515 wd = elm_widget_data_get(obj);
518 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
519 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
521 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
522 &base_size.w, &base_size.h);
524 edje_object_part_unswallow(wd->base, wd->arrow);
528 case ELM_CTXPOPUP_DIRECTION_RIGHT:
529 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
530 edje_object_part_swallow(wd->base,
531 "elm.swallow.arrow_left",
535 if (y < ((arrow_size.h * 0.5) + base_size.y))
537 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
538 y = base_size.h - arrow_size.h;
540 y = y - base_size.y - (arrow_size.h * 0.5);
541 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
542 edje_object_part_drag_value_set(wd->base,
543 "elm.swallow.arrow_left",
548 case ELM_CTXPOPUP_DIRECTION_LEFT:
549 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
550 edje_object_part_swallow(wd->base,
551 "elm.swallow.arrow_right",
555 if (y < ((arrow_size.h * 0.5) + base_size.y))
557 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
558 y = base_size.h - arrow_size.h;
560 y = y - base_size.y - (arrow_size.h * 0.5);
561 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
562 edje_object_part_drag_value_set(wd->base,
563 "elm.swallow.arrow_right",
568 case ELM_CTXPOPUP_DIRECTION_DOWN:
569 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
570 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
573 if (x < ((arrow_size.w * 0.5) + base_size.x))
575 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
576 x = base_size.w - arrow_size.w;
578 x = x - base_size.x - (arrow_size.w * 0.5);
579 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
580 edje_object_part_drag_value_set(wd->base,
581 "elm.swallow.arrow_up",
586 case ELM_CTXPOPUP_DIRECTION_UP:
587 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
588 edje_object_part_swallow(wd->base,
589 "elm.swallow.arrow_down",
593 if (x < ((arrow_size.w * 0.5) + base_size.x))
595 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
596 x = base_size.w - arrow_size.w;
597 else x = x - base_size.x - (arrow_size.w * 0.5);
598 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
599 edje_object_part_drag_value_set(wd->base,
600 "elm.swallow.arrow_down",
611 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
615 wd = elm_widget_data_get(obj);
616 if (!wd || wd->visible) return;
620 case ELM_CTXPOPUP_DIRECTION_UP:
621 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
623 case ELM_CTXPOPUP_DIRECTION_LEFT:
624 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
626 case ELM_CTXPOPUP_DIRECTION_RIGHT:
627 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
629 case ELM_CTXPOPUP_DIRECTION_DOWN:
630 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
638 _sizing_eval(Evas_Object *obj)
642 Elm_Ctxpopup_Item *item;
643 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
644 Evas_Coord_Point box_size = { 0, 0 };
645 Evas_Coord_Point _box_size = { 0, 0 };
647 wd = elm_widget_data_get(obj);
651 EINA_LIST_FOREACH(wd->items, elist, item)
653 _item_sizing_eval(item);
654 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
657 if (_box_size.x > box_size.x)
658 box_size.x = _box_size.x;
659 if (_box_size.y != -1)
660 box_size.y += _box_size.y;
664 if (_box_size.x != -1)
665 box_size.x += _box_size.x;
666 if (_box_size.y > box_size.y)
667 box_size.y = _box_size.y;
673 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
674 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
678 wd->dir = _calc_base_geometry(obj, &rect);
679 _show_signal_emit(obj, wd->dir);
680 _update_arrow(obj, wd->dir);
681 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
683 //resize scroller according to final size.
685 evas_object_smart_calculate(wd->scr);
687 evas_object_move(wd->base, rect.x, rect.y);
688 evas_object_resize(wd->base, rect.w, rect.h);
692 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
693 Evas_Coord_Rectangle *rect)
695 Evas_Coord arrow_w, arrow_h;
697 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
701 case ELM_CTXPOPUP_DIRECTION_RIGHT:
704 case ELM_CTXPOPUP_DIRECTION_LEFT:
707 case ELM_CTXPOPUP_DIRECTION_DOWN:
710 case ELM_CTXPOPUP_DIRECTION_UP:
719 _del_pre_hook(Evas_Object *obj)
723 wd = elm_widget_data_get(obj);
726 _parent_cut_off(obj);
730 _del_hook(Evas_Object *obj)
734 wd = elm_widget_data_get(obj);
737 elm_ctxpopup_clear(obj);
738 evas_object_del(wd->arrow);
739 evas_object_del(wd->base);
743 //FIXME: lost the content size when theme hook is called.
745 _theme_hook(Evas_Object *obj)
749 Elm_Ctxpopup_Item *item;
752 wd = elm_widget_data_get(obj);
755 _elm_widget_mirrored_reload(obj);
756 rtl = elm_widget_mirrored_get(obj);
758 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
759 elm_widget_style_get(obj));
760 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
761 elm_widget_style_get(obj));
762 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
763 elm_widget_style_get(obj));
766 EINA_LIST_FOREACH(wd->items, elist, item)
768 edje_object_mirrored_set(VIEW(item), rtl);
770 if (item->label && item->icon)
771 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
772 "icon_text_style_item",
773 elm_widget_style_get(obj));
774 else if (item->label)
775 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
776 elm_widget_style_get(obj));
778 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
779 elm_widget_style_get(obj));
781 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
783 if (elm_widget_item_disabled_get(item))
784 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
786 edje_object_message_signal_process(VIEW(item));
791 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
792 elm_object_style_set(wd->scr, "ctxpopup");
794 elm_object_style_set(wd->scr, elm_object_style_get(obj));
797 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
801 _scroller_size_reset(wd);
807 _content_set_hook(Evas_Object *obj, const char *part,
808 Evas_Object *content)
810 ELM_CHECK_WIDTYPE(obj, widtype);
814 if (part && strcmp(part, "default")) return;
816 wd = elm_widget_data_get(obj);
817 if ((!wd) || (!content)) return;
819 if (wd->items) elm_ctxpopup_clear(obj);
820 if (wd->content) evas_object_del(wd->content);
822 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
825 elm_widget_sub_object_add(obj, content);
826 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
828 wd->content = content;
830 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
837 _content_unset_hook(Evas_Object *obj, const char *part)
839 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
842 Evas_Object *content;
843 if (part && strcmp(part, "default")) return NULL;
844 wd = elm_widget_data_get(obj);
845 if (!wd) return NULL;
847 content = wd->content;
848 if (!content) return NULL;
850 edje_object_part_unswallow(wd->base, content);
851 elm_widget_sub_object_del(obj, content);
852 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
853 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
856 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
863 _content_get_hook(const Evas_Object *obj, const char *part)
865 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
867 if (part && strcmp(part, "default")) return NULL;
868 wd = elm_widget_data_get(obj);
869 if (!wd) return NULL;
874 _item_text_set_hook(Elm_Object_Item *it,
878 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
881 Elm_Ctxpopup_Item *ctxpopup_it;
883 if (part && strcmp(part, "default")) return;
885 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
887 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
890 _item_label_set(ctxpopup_it, label);
891 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
895 _scroller_size_reset(wd);
896 _sizing_eval(WIDGET(ctxpopup_it));
901 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
903 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
904 Elm_Ctxpopup_Item *ctxpopup_it;
905 if (part && strcmp(part, "default")) return NULL;
906 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
907 return ctxpopup_it->label;
911 _item_content_set_hook(Elm_Object_Item *it,
913 Evas_Object *content)
915 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
917 Elm_Ctxpopup_Item *ctxpopup_it;
919 if (part && strcmp(part, "icon")) return;
921 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
923 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
926 _item_icon_set(ctxpopup_it, content);
927 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
931 _scroller_size_reset(wd);
932 _sizing_eval(WIDGET(ctxpopup_it));
937 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
939 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
940 Elm_Ctxpopup_Item *ctxpopup_it;
941 if (part && strcmp(part, "icon")) return NULL;
942 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
943 return ctxpopup_it->icon;
947 _item_disable_set_hook(Elm_Object_Item *it)
949 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
952 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
954 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
957 if (elm_widget_item_disabled_get(it))
958 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
960 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
964 _item_signal_emit_hook(Elm_Object_Item *it,
965 const char *emission,
968 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
969 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
970 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
974 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
975 const char *emission __UNUSED__, const char *source __UNUSED__)
977 evas_object_hide(data);
981 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
982 void *event_info __UNUSED__)
986 wd = elm_widget_data_get(obj);
989 if ((!wd->items) && (!wd->content)) return;
991 wd->visible = EINA_TRUE;
993 evas_object_show(wd->bg);
994 evas_object_show(wd->base);
995 evas_object_show(wd->arrow);
997 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
998 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
1002 elm_object_focus_set(obj, EINA_TRUE);
1006 _hide(Evas_Object *obj)
1008 Widget_Data *wd = elm_widget_data_get(obj);
1010 if ((!wd) || (!wd->visible)) return;
1012 evas_object_hide(wd->bg);
1013 evas_object_hide(wd->arrow);
1014 evas_object_hide(wd->base);
1016 _scroller_size_reset(wd);
1018 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1019 wd->visible = EINA_FALSE;
1023 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1024 void *event_info __UNUSED__)
1030 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1031 void *event_info __UNUSED__)
1036 wd = elm_widget_data_get(data);
1038 if (!wd->visible) return;
1039 if (wd->finished) return;
1041 evas_object_geometry_get(obj, 0, 0, &w, &h);
1043 if (w != 0 && h != 0)
1045 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1048 wd->finished = EINA_TRUE;
1053 if (wd->max_sc_w < w)
1055 if (wd->max_sc_h < h)
1062 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1063 void *event_info __UNUSED__)
1067 wd = elm_widget_data_get(obj);
1072 evas_object_show(wd->arrow);
1074 _scroller_size_reset(wd);
1079 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1080 const char *emission __UNUSED__, const char *source __UNUSED__)
1082 Elm_Ctxpopup_Item *item = data;
1085 if (elm_widget_item_disabled_get(item)) return;
1088 item->func((void*) item->base.data, WIDGET(item), data);
1092 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1095 evas_object_del(item->icon);
1100 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1101 edje_object_message_signal_process(VIEW(item));
1105 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1107 if (!eina_stringshare_replace(&item->label, label))
1110 edje_object_part_text_set(VIEW(item), "elm.text", label);
1111 edje_object_message_signal_process(VIEW(item));
1115 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1119 wd = elm_widget_data_get(WIDGET(item));
1122 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1123 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
1124 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1125 elm_widget_style_get(WIDGET(item)));
1126 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1127 _item_select_cb, item);
1128 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1129 evas_object_show(VIEW(item));
1133 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1134 void *event_info __UNUSED__)
1136 elm_object_content_unset(data);
1140 _list_del(Widget_Data *wd)
1142 if (!wd->scr) return;
1144 edje_object_part_unswallow(wd->base, wd->scr);
1145 evas_object_del(wd->scr);
1151 _list_new(Evas_Object *obj)
1154 wd = elm_widget_data_get(obj);
1158 wd->scr = elm_scroller_add(obj);
1159 elm_object_style_set(wd->scr, "ctxpopup");
1160 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1161 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1162 _scroller_resize, obj);
1163 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1166 wd->box = elm_box_add(obj);
1167 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1170 elm_object_content_set(wd->scr, wd->box);
1171 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1175 _remove_items(Widget_Data *wd)
1178 Elm_Ctxpopup_Item *item;
1180 if (!wd->items) return;
1182 EINA_LIST_FOREACH(wd->items, elist, item)
1185 eina_stringshare_del(item->label);
1187 evas_object_del(item->icon);
1188 wd->items = eina_list_remove(wd->items, item);
1196 elm_ctxpopup_add(Evas_Object *parent)
1202 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1204 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1205 elm_widget_type_set(obj, "ctxpopup");
1206 elm_widget_data_set(obj, wd);
1207 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1208 elm_widget_del_hook_set(obj, _del_hook);
1209 elm_widget_theme_hook_set(obj, _theme_hook);
1210 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1211 elm_widget_can_focus_set(obj, EINA_TRUE);
1212 elm_widget_event_hook_set(obj, _event_hook);
1213 elm_widget_content_set_hook_set(obj, _content_set_hook);
1214 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1215 elm_widget_content_get_hook_set(obj, _content_get_hook);
1218 wd->bg = edje_object_add(e);
1219 elm_widget_sub_object_add(obj, wd->bg);
1220 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1221 edje_object_signal_callback_add(wd->bg,
1227 wd->base = edje_object_add(e);
1228 elm_widget_sub_object_add(obj, wd->base);
1229 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1232 wd->arrow = edje_object_add(e);
1233 elm_widget_sub_object_add(obj, wd->arrow);
1234 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1236 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1237 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1238 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1239 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1240 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1242 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1244 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1246 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1248 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1249 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1250 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1251 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1253 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1255 //default parent is to be hover parent
1256 elm_ctxpopup_hover_parent_set(obj, parent);
1262 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1264 return _item_content_get_hook(it, "icon");
1268 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1270 _item_content_set_hook(it, "icon", icon);
1274 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1276 return _item_text_get_hook(it, NULL);
1280 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1282 _item_text_set_hook(it, NULL, label);
1286 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1288 ELM_CHECK_WIDTYPE(obj, widtype);
1291 Evas_Coord x, y, w, h;
1293 wd = elm_widget_data_get(obj);
1294 if ((!wd) || (!parent)) return;
1296 _parent_cut_off(obj);
1300 evas_object_event_callback_add(parent,
1304 evas_object_event_callback_add(parent,
1308 evas_object_event_callback_add(parent,
1309 EVAS_CALLBACK_RESIZE,
1314 elm_widget_sub_object_add(parent, obj);
1315 wd->parent = parent;
1318 evas_object_geometry_get(parent, &x, &y, &w, &h);
1319 evas_object_move(wd->bg, x, y);
1320 evas_object_resize(wd->bg, w, h);
1322 if (wd->visible) _sizing_eval(obj);
1326 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1328 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1332 wd = elm_widget_data_get(obj);
1333 if (!wd) return NULL;
1339 elm_ctxpopup_clear(Evas_Object * obj)
1341 ELM_CHECK_WIDTYPE(obj, widtype);
1343 Widget_Data *wd = elm_widget_data_get(obj);
1348 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1352 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1354 ELM_CHECK_WIDTYPE(obj, widtype);
1358 wd = elm_widget_data_get(obj);
1361 wd->horizontal = !!horizontal;
1363 if ((!wd->scr) && (!wd->box))
1368 elm_box_horizontal_set(wd->box, EINA_FALSE);
1369 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1373 elm_box_horizontal_set(wd->box, EINA_TRUE);
1374 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1377 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1384 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1386 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1390 wd = elm_widget_data_get(obj);
1391 if (!wd) return EINA_FALSE;
1393 return wd->horizontal;
1396 EAPI Elm_Object_Item *
1397 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1398 Evas_Object *icon, Evas_Smart_Cb func,
1401 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1404 Evas_Object *content;
1405 Elm_Ctxpopup_Item *item;
1407 wd = elm_widget_data_get(obj);
1408 if (!wd) return NULL;
1410 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1411 if (!item) return NULL;
1413 elm_widget_item_disable_set_hook_set(item, _item_disable_set_hook);
1414 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1415 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1416 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1417 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1418 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1420 //The first item is appended.
1421 content = elm_object_content_unset(obj);
1422 if (content) evas_object_del(content);
1428 item->base.data = data;
1431 _item_new(item, "icon_text_style_item");
1433 _item_new(item, "text_style_item");
1435 _item_new(item, "icon_style_item");
1437 _item_icon_set(item, icon);
1438 _item_label_set(item, label);
1439 elm_box_pack_end(wd->box, VIEW(item));
1440 wd->items = eina_list_append(wd->items, item);
1441 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1445 _scroller_size_reset(wd);
1449 return (Elm_Object_Item *) item;
1453 elm_ctxpopup_item_del(Elm_Object_Item *it)
1455 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1458 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1460 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1463 if (ctxpopup_it->icon)
1464 evas_object_del(ctxpopup_it->icon);
1465 if (VIEW(ctxpopup_it))
1466 evas_object_del(VIEW(ctxpopup_it));
1468 eina_stringshare_del(ctxpopup_it->label);
1470 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1472 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1474 elm_widget_item_del(ctxpopup_it);
1476 if (eina_list_count(wd->items) < 1)
1478 evas_object_hide(WIDGET(ctxpopup_it));
1483 _sizing_eval(WIDGET(ctxpopup_it));
1488 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1490 elm_object_item_disabled_set(it, disabled);
1494 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1496 return elm_object_item_disabled_get(it);
1500 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1502 elm_object_content_set(obj, content);
1506 elm_ctxpopup_content_unset(Evas_Object *obj)
1508 return elm_object_content_unset(obj);
1512 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1513 Elm_Ctxpopup_Direction first,
1514 Elm_Ctxpopup_Direction second,
1515 Elm_Ctxpopup_Direction third,
1516 Elm_Ctxpopup_Direction fourth)
1518 ELM_CHECK_WIDTYPE(obj, widtype);
1521 wd = elm_widget_data_get(obj);
1524 wd->dir_priority[0] = first;
1525 wd->dir_priority[1] = second;
1526 wd->dir_priority[2] = third;
1527 wd->dir_priority[3] = fourth;
1534 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1535 Elm_Ctxpopup_Direction *first,
1536 Elm_Ctxpopup_Direction *second,
1537 Elm_Ctxpopup_Direction *third,
1538 Elm_Ctxpopup_Direction *fourth)
1540 ELM_CHECK_WIDTYPE(obj, widtype);
1543 wd = elm_widget_data_get(obj);
1546 if (first) *first = wd->dir_priority[0];
1547 if (second) *second = wd->dir_priority[1];
1548 if (third) *third = wd->dir_priority[2];
1549 if (fourth) *fourth = wd->dir_priority[3];
1552 EAPI Elm_Ctxpopup_Direction
1553 elm_ctxpopup_direction_get(const Evas_Object *obj)
1555 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1558 wd = elm_widget_data_get(obj);
1559 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;