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, Evas_Coord_Rectangle rect);
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, Evas_Coord_Rectangle base_size)
510 Evas_Coord_Rectangle arrow_size;
514 wd = elm_widget_data_get(obj);
517 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
518 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
521 edje_object_part_unswallow(wd->base, wd->arrow);
525 case ELM_CTXPOPUP_DIRECTION_RIGHT:
526 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
527 edje_object_part_swallow(wd->base,
528 "elm.swallow.arrow_left",
532 if (y < ((arrow_size.h * 0.5) + base_size.y))
534 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
535 y = base_size.h - arrow_size.h;
537 y = y - base_size.y - (arrow_size.h * 0.5);
538 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
539 edje_object_part_drag_value_set(wd->base,
540 "elm.swallow.arrow_left",
545 case ELM_CTXPOPUP_DIRECTION_LEFT:
546 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
547 edje_object_part_swallow(wd->base,
548 "elm.swallow.arrow_right",
552 if (y < ((arrow_size.h * 0.5) + base_size.y))
554 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
555 y = base_size.h - arrow_size.h;
557 y = y - base_size.y - (arrow_size.h * 0.5);
558 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
559 edje_object_part_drag_value_set(wd->base,
560 "elm.swallow.arrow_right",
565 case ELM_CTXPOPUP_DIRECTION_DOWN:
566 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
567 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
570 if (x < ((arrow_size.w * 0.5) + base_size.x))
572 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
573 x = base_size.w - arrow_size.w;
575 x = x - base_size.x - (arrow_size.w * 0.5);
576 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
577 edje_object_part_drag_value_set(wd->base,
578 "elm.swallow.arrow_up",
583 case ELM_CTXPOPUP_DIRECTION_UP:
584 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
585 edje_object_part_swallow(wd->base,
586 "elm.swallow.arrow_down",
590 if (x < ((arrow_size.w * 0.5) + base_size.x))
592 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
593 x = base_size.w - arrow_size.w;
594 else x = x - base_size.x - (arrow_size.w * 0.5);
595 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
596 edje_object_part_drag_value_set(wd->base,
597 "elm.swallow.arrow_down",
608 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
612 wd = elm_widget_data_get(obj);
613 if (!wd || wd->visible) return;
617 case ELM_CTXPOPUP_DIRECTION_UP:
618 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
620 case ELM_CTXPOPUP_DIRECTION_LEFT:
621 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
623 case ELM_CTXPOPUP_DIRECTION_RIGHT:
624 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
626 case ELM_CTXPOPUP_DIRECTION_DOWN:
627 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
635 _sizing_eval(Evas_Object *obj)
639 Elm_Ctxpopup_Item *item;
640 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
641 Evas_Coord_Point box_size = { 0, 0 };
642 Evas_Coord_Point _box_size = { 0, 0 };
644 wd = elm_widget_data_get(obj);
648 EINA_LIST_FOREACH(wd->items, elist, item)
650 _item_sizing_eval(item);
651 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
654 if (_box_size.x > box_size.x)
655 box_size.x = _box_size.x;
656 if (_box_size.y != -1)
657 box_size.y += _box_size.y;
661 if (_box_size.x != -1)
662 box_size.x += _box_size.x;
663 if (_box_size.y > box_size.y)
664 box_size.y = _box_size.y;
670 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
671 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
675 wd->dir = _calc_base_geometry(obj, &rect);
676 _show_signal_emit(obj, wd->dir);
677 _update_arrow(obj, wd->dir, rect);
678 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
680 //resize scroller according to final size.
682 evas_object_smart_calculate(wd->scr);
684 evas_object_move(wd->base, rect.x, rect.y);
685 evas_object_resize(wd->base, rect.w, rect.h);
689 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
690 Evas_Coord_Rectangle *rect)
692 Evas_Coord arrow_w, arrow_h;
694 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
698 case ELM_CTXPOPUP_DIRECTION_RIGHT:
701 case ELM_CTXPOPUP_DIRECTION_LEFT:
704 case ELM_CTXPOPUP_DIRECTION_DOWN:
707 case ELM_CTXPOPUP_DIRECTION_UP:
716 _del_pre_hook(Evas_Object *obj)
720 wd = elm_widget_data_get(obj);
723 _parent_cut_off(obj);
727 _del_hook(Evas_Object *obj)
731 wd = elm_widget_data_get(obj);
734 elm_ctxpopup_clear(obj);
735 evas_object_del(wd->arrow);
736 evas_object_del(wd->base);
740 //FIXME: lost the content size when theme hook is called.
742 _theme_hook(Evas_Object *obj)
746 Elm_Ctxpopup_Item *item;
749 wd = elm_widget_data_get(obj);
752 _elm_widget_mirrored_reload(obj);
753 rtl = elm_widget_mirrored_get(obj);
755 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
756 elm_widget_style_get(obj));
757 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
758 elm_widget_style_get(obj));
759 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
760 elm_widget_style_get(obj));
763 EINA_LIST_FOREACH(wd->items, elist, item)
765 edje_object_mirrored_set(VIEW(item), rtl);
767 if (item->label && item->icon)
768 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
769 "icon_text_style_item",
770 elm_widget_style_get(obj));
771 else if (item->label)
772 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
773 elm_widget_style_get(obj));
775 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
776 elm_widget_style_get(obj));
778 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
780 if (elm_widget_item_disabled_get(item))
781 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
783 edje_object_message_signal_process(VIEW(item));
788 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
789 elm_object_style_set(wd->scr, "ctxpopup");
791 elm_object_style_set(wd->scr, elm_object_style_get(obj));
794 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
798 _scroller_size_reset(wd);
804 _content_set_hook(Evas_Object *obj, const char *part,
805 Evas_Object *content)
807 ELM_CHECK_WIDTYPE(obj, widtype);
811 if (part && strcmp(part, "default")) return;
813 wd = elm_widget_data_get(obj);
814 if ((!wd) || (!content)) return;
816 if (wd->items) elm_ctxpopup_clear(obj);
817 if (wd->content) evas_object_del(wd->content);
819 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
822 elm_widget_sub_object_add(obj, content);
823 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
825 wd->content = content;
827 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
834 _content_unset_hook(Evas_Object *obj, const char *part)
836 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
839 Evas_Object *content;
840 if (part && strcmp(part, "default")) return NULL;
841 wd = elm_widget_data_get(obj);
842 if (!wd) return NULL;
844 content = wd->content;
845 if (!content) return NULL;
847 edje_object_part_unswallow(wd->base, content);
848 elm_widget_sub_object_del(obj, content);
849 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
850 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
853 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
860 _content_get_hook(const Evas_Object *obj, const char *part)
862 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
864 if (part && strcmp(part, "default")) return NULL;
865 wd = elm_widget_data_get(obj);
866 if (!wd) return NULL;
871 _item_text_set_hook(Elm_Object_Item *it,
875 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
878 Elm_Ctxpopup_Item *ctxpopup_it;
880 if (part && strcmp(part, "default")) return;
882 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
884 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
887 _item_label_set(ctxpopup_it, label);
888 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
892 _scroller_size_reset(wd);
893 _sizing_eval(WIDGET(ctxpopup_it));
898 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
900 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
901 Elm_Ctxpopup_Item *ctxpopup_it;
902 if (part && strcmp(part, "default")) return NULL;
903 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
904 return ctxpopup_it->label;
908 _item_content_set_hook(Elm_Object_Item *it,
910 Evas_Object *content)
912 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
914 Elm_Ctxpopup_Item *ctxpopup_it;
916 if (part && strcmp(part, "icon")) return;
918 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
920 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
923 _item_icon_set(ctxpopup_it, content);
924 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
928 _scroller_size_reset(wd);
929 _sizing_eval(WIDGET(ctxpopup_it));
934 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
936 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
937 Elm_Ctxpopup_Item *ctxpopup_it;
938 if (part && strcmp(part, "icon")) return NULL;
939 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
940 return ctxpopup_it->icon;
944 _item_disable_set_hook(Elm_Object_Item *it)
946 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
949 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
951 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
954 if (elm_widget_item_disabled_get(it))
955 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
957 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
961 _item_signal_emit_hook(Elm_Object_Item *it,
962 const char *emission,
965 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
966 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
967 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
971 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
972 const char *emission __UNUSED__, const char *source __UNUSED__)
974 evas_object_hide(data);
978 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
979 void *event_info __UNUSED__)
983 wd = elm_widget_data_get(obj);
986 if ((!wd->items) && (!wd->content)) return;
988 wd->visible = EINA_TRUE;
990 evas_object_show(wd->bg);
991 evas_object_show(wd->base);
992 evas_object_show(wd->arrow);
994 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
995 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
999 elm_object_focus_set(obj, EINA_TRUE);
1003 _hide(Evas_Object *obj)
1005 Widget_Data *wd = elm_widget_data_get(obj);
1007 if ((!wd) || (!wd->visible)) return;
1009 evas_object_hide(wd->bg);
1010 evas_object_hide(wd->arrow);
1011 evas_object_hide(wd->base);
1013 _scroller_size_reset(wd);
1015 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1016 wd->visible = EINA_FALSE;
1020 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1021 void *event_info __UNUSED__)
1027 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1028 void *event_info __UNUSED__)
1032 wd = elm_widget_data_get(data);
1035 elm_box_recalculate(wd->box);
1040 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1041 void *event_info __UNUSED__)
1046 wd = elm_widget_data_get(data);
1048 if (!wd->visible) return;
1049 if (wd->finished) return;
1051 evas_object_geometry_get(obj, 0, 0, &w, &h);
1053 if (w != 0 && h != 0)
1055 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1058 wd->finished = EINA_TRUE;
1063 if (wd->max_sc_w < w)
1065 if (wd->max_sc_h < h)
1072 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1073 void *event_info __UNUSED__)
1077 wd = elm_widget_data_get(obj);
1082 evas_object_show(wd->arrow);
1084 _scroller_size_reset(wd);
1089 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1090 const char *emission __UNUSED__, const char *source __UNUSED__)
1092 Elm_Ctxpopup_Item *item = data;
1095 if (elm_widget_item_disabled_get(item)) return;
1098 item->func((void*) item->base.data, WIDGET(item), data);
1102 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1105 evas_object_del(item->icon);
1110 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1111 edje_object_message_signal_process(VIEW(item));
1115 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1117 if (!eina_stringshare_replace(&item->label, label))
1120 edje_object_part_text_set(VIEW(item), "elm.text", label);
1121 edje_object_message_signal_process(VIEW(item));
1125 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1129 wd = elm_widget_data_get(WIDGET(item));
1132 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1133 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
1134 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1135 elm_widget_style_get(WIDGET(item)));
1136 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1137 _item_select_cb, item);
1138 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1139 evas_object_show(VIEW(item));
1143 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1144 void *event_info __UNUSED__)
1146 elm_object_content_unset(data);
1150 _list_del(Widget_Data *wd)
1152 if (!wd->scr) return;
1154 edje_object_part_unswallow(wd->base, wd->scr);
1155 evas_object_del(wd->scr);
1161 _list_new(Evas_Object *obj)
1164 wd = elm_widget_data_get(obj);
1168 wd->scr = elm_scroller_add(obj);
1169 elm_object_style_set(wd->scr, "ctxpopup");
1170 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1171 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1172 _scroller_resize, obj);
1173 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1176 wd->box = elm_box_add(obj);
1177 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1180 elm_object_content_set(wd->scr, wd->box);
1181 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1185 _remove_items(Widget_Data *wd)
1188 Elm_Ctxpopup_Item *item;
1190 if (!wd->items) return;
1192 EINA_LIST_FOREACH(wd->items, elist, item)
1195 eina_stringshare_del(item->label);
1197 evas_object_del(item->icon);
1198 wd->items = eina_list_remove(wd->items, item);
1206 elm_ctxpopup_add(Evas_Object *parent)
1212 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1214 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1215 elm_widget_type_set(obj, "ctxpopup");
1216 elm_widget_data_set(obj, wd);
1217 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1218 elm_widget_del_hook_set(obj, _del_hook);
1219 elm_widget_theme_hook_set(obj, _theme_hook);
1220 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1221 elm_widget_can_focus_set(obj, EINA_TRUE);
1222 elm_widget_event_hook_set(obj, _event_hook);
1223 elm_widget_content_set_hook_set(obj, _content_set_hook);
1224 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1225 elm_widget_content_get_hook_set(obj, _content_get_hook);
1228 wd->bg = edje_object_add(e);
1229 elm_widget_sub_object_add(obj, wd->bg);
1230 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1231 edje_object_signal_callback_add(wd->bg,
1237 wd->base = edje_object_add(e);
1238 elm_widget_sub_object_add(obj, wd->base);
1239 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1242 wd->arrow = edje_object_add(e);
1243 elm_widget_sub_object_add(obj, wd->arrow);
1244 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1246 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1247 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1248 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1249 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1250 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1252 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1254 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1256 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1258 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1259 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1260 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1261 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1263 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1265 //default parent is to be hover parent
1266 elm_ctxpopup_hover_parent_set(obj, parent);
1272 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1274 return _item_content_get_hook(it, "icon");
1278 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1280 _item_content_set_hook(it, "icon", icon);
1284 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1286 return _item_text_get_hook(it, NULL);
1290 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1292 _item_text_set_hook(it, NULL, label);
1296 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1298 ELM_CHECK_WIDTYPE(obj, widtype);
1301 Evas_Coord x, y, w, h;
1303 wd = elm_widget_data_get(obj);
1304 if ((!wd) || (!parent)) return;
1306 _parent_cut_off(obj);
1310 evas_object_event_callback_add(parent,
1314 evas_object_event_callback_add(parent,
1318 evas_object_event_callback_add(parent,
1319 EVAS_CALLBACK_RESIZE,
1324 elm_widget_sub_object_add(parent, obj);
1325 wd->parent = parent;
1328 evas_object_geometry_get(parent, &x, &y, &w, &h);
1329 evas_object_move(wd->bg, x, y);
1330 evas_object_resize(wd->bg, w, h);
1332 if (wd->visible) _sizing_eval(obj);
1336 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1338 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1342 wd = elm_widget_data_get(obj);
1343 if (!wd) return NULL;
1349 elm_ctxpopup_clear(Evas_Object * obj)
1351 ELM_CHECK_WIDTYPE(obj, widtype);
1353 Widget_Data *wd = elm_widget_data_get(obj);
1358 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1362 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1364 ELM_CHECK_WIDTYPE(obj, widtype);
1368 wd = elm_widget_data_get(obj);
1371 wd->horizontal = !!horizontal;
1373 if ((!wd->scr) && (!wd->box))
1378 elm_box_horizontal_set(wd->box, EINA_FALSE);
1379 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1383 elm_box_horizontal_set(wd->box, EINA_TRUE);
1384 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1387 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1394 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1396 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1400 wd = elm_widget_data_get(obj);
1401 if (!wd) return EINA_FALSE;
1403 return wd->horizontal;
1406 EAPI Elm_Object_Item *
1407 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1408 Evas_Object *icon, Evas_Smart_Cb func,
1411 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1414 Evas_Object *content;
1415 Elm_Ctxpopup_Item *item;
1417 wd = elm_widget_data_get(obj);
1418 if (!wd) return NULL;
1420 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1421 if (!item) return NULL;
1423 elm_widget_item_disable_set_hook_set(item, _item_disable_set_hook);
1424 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1425 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1426 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1427 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1428 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1430 //The first item is appended.
1431 content = elm_object_content_unset(obj);
1432 if (content) evas_object_del(content);
1438 item->base.data = data;
1441 _item_new(item, "icon_text_style_item");
1443 _item_new(item, "text_style_item");
1445 _item_new(item, "icon_style_item");
1447 _item_icon_set(item, icon);
1448 _item_label_set(item, label);
1449 elm_box_pack_end(wd->box, VIEW(item));
1450 wd->items = eina_list_append(wd->items, item);
1451 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1455 _scroller_size_reset(wd);
1459 return (Elm_Object_Item *) item;
1463 elm_ctxpopup_item_del(Elm_Object_Item *it)
1465 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1468 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1470 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1473 if (ctxpopup_it->icon)
1474 evas_object_del(ctxpopup_it->icon);
1475 if (VIEW(ctxpopup_it))
1476 evas_object_del(VIEW(ctxpopup_it));
1478 eina_stringshare_del(ctxpopup_it->label);
1480 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1482 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1484 elm_widget_item_del(ctxpopup_it);
1486 if (eina_list_count(wd->items) < 1)
1488 evas_object_hide(WIDGET(ctxpopup_it));
1493 _sizing_eval(WIDGET(ctxpopup_it));
1498 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1500 elm_object_item_disabled_set(it, disabled);
1504 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1506 return elm_object_item_disabled_get(it);
1510 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1513 wd = elm_widget_data_get(obj);
1516 wd->box = elm_box_add(obj);
1517 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1519 evas_object_show(content);
1521 elm_box_pack_end(wd->box, content);
1523 evas_object_event_callback_add(content, EVAS_CALLBACK_RESIZE,
1524 _content_resize, obj);
1525 elm_object_content_set(obj, wd->box);
1529 elm_ctxpopup_content_unset(Evas_Object *obj)
1531 return elm_object_content_unset(obj);
1535 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1536 Elm_Ctxpopup_Direction first,
1537 Elm_Ctxpopup_Direction second,
1538 Elm_Ctxpopup_Direction third,
1539 Elm_Ctxpopup_Direction fourth)
1541 ELM_CHECK_WIDTYPE(obj, widtype);
1544 wd = elm_widget_data_get(obj);
1547 wd->dir_priority[0] = first;
1548 wd->dir_priority[1] = second;
1549 wd->dir_priority[2] = third;
1550 wd->dir_priority[3] = fourth;
1557 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1558 Elm_Ctxpopup_Direction *first,
1559 Elm_Ctxpopup_Direction *second,
1560 Elm_Ctxpopup_Direction *third,
1561 Elm_Ctxpopup_Direction *fourth)
1563 ELM_CHECK_WIDTYPE(obj, widtype);
1566 wd = elm_widget_data_get(obj);
1569 if (first) *first = wd->dir_priority[0];
1570 if (second) *second = wd->dir_priority[1];
1571 if (third) *third = wd->dir_priority[2];
1572 if (fourth) *fourth = wd->dir_priority[3];
1575 EAPI Elm_Ctxpopup_Direction
1576 elm_ctxpopup_direction_get(const Evas_Object *obj)
1578 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1581 wd = elm_widget_data_get(obj);
1582 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;