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 Evas_Object *hover_parent;
27 Elm_Ctxpopup_Direction dir;
28 Elm_Ctxpopup_Direction dir_priority[4];
29 Evas_Coord max_sc_w, max_sc_h;
30 Eina_Bool horizontal:1;
35 static const char *widtype = NULL;
37 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
38 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
39 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
40 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
41 static void _scroller_size_reset(Widget_Data *wd);
42 static void _on_focus_hook(void *data, Evas_Object *obj);
43 static Eina_Bool _event_hook(Evas_Object *obj,
45 Evas_Callback_Type type,
47 static void _hover_parent_callbacks_del(Evas_Object *obj);
48 static void _hover_parent_resize(void *data, Evas *e,
51 static void _hover_parent_move(void *data, Evas *e,
54 static void _hover_parent_del(void *data, Evas *e,
57 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
58 static void _adjust_pos_x(Evas_Coord_Point *pos,
59 Evas_Coord_Point *base_size,
60 Evas_Coord_Rectangle *hover_area);
61 static void _adjust_pos_y(Evas_Coord_Point *pos,
62 Evas_Coord_Point *base_size,
63 Evas_Coord_Rectangle *hover_area);
64 static void _ctxpopup_changed_size_hints(void *data,
68 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
69 Evas_Coord_Rectangle *rect);
70 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
71 static void _sizing_eval(Evas_Object *obj);
72 static void _shift_base_by_arrow(Evas_Object *arrow,
73 Elm_Ctxpopup_Direction dir,
74 Evas_Coord_Rectangle *rect);
75 static void _del_pre_hook(Evas_Object *obj);
76 static void _del_hook(Evas_Object *obj);
77 static void _theme_hook(Evas_Object *obj);
78 static void _content_set_hook(Evas_Object *obj,
80 Evas_Object *content);
81 static Evas_Object * _content_unset_hook(Evas_Object *obj,
83 static Evas_Object * _content_get_hook(const Evas_Object *obj,
85 static void _bg_clicked_cb(void *data, Evas_Object *obj,
88 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
90 static void _ctxpopup_show(void *data,
94 static void _hide(Evas_Object *obj);
95 static void _ctxpopup_hide(void *data,
99 static void _scroller_resize(void *data,
103 static void _ctxpopup_move(void *data,
107 static void _item_select_cb(void *data, Evas_Object *obj,
108 const char *emission,
110 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
111 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
112 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
113 static void _content_del(void *data,
117 static void _list_del(Widget_Data *wd);
118 static void _list_new(Evas_Object *obj);
119 static void _remove_items(Widget_Data * wd);
121 static const char SIG_DISMISSED[] = "dismissed";
123 static const Evas_Smart_Cb_Description _signals[] = {
129 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
130 void *event_info __UNUSED__)
132 Widget_Data *wd = elm_widget_data_get(obj);
134 if ((!wd) || (!wd->scr)) return;
135 elm_object_scroll_freeze_push(wd->scr);
139 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
140 void *event_info __UNUSED__)
142 Widget_Data *wd = elm_widget_data_get(obj);
144 if ((!wd) || (!wd->scr)) return;
145 elm_object_scroll_freeze_pop(wd->scr);
149 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
151 Widget_Data *wd = elm_widget_data_get(obj);
153 if ((!wd) || (!wd->scr)) return;
154 elm_object_scroll_hold_push(wd->scr);
158 _hold_off(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_pop(wd->scr);
167 _scroller_size_reset(Widget_Data *wd)
169 wd->finished = EINA_FALSE;
175 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
177 Widget_Data *wd = elm_widget_data_get(obj);
180 if (elm_widget_focus_get(obj))
191 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
193 Evas_Event_Key_Down *ev;
196 if (type != EVAS_CALLBACK_KEY_DOWN)
198 wd = elm_widget_data_get(obj);
199 if (!wd) return EINA_FALSE;
202 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
203 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
205 evas_object_hide(obj);
206 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
211 _hover_parent_callbacks_del(Evas_Object *obj)
213 Widget_Data *wd = elm_widget_data_get(obj);
215 if ((!wd) || (!wd->hover_parent))
218 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
219 _hover_parent_del, obj);
220 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
221 _hover_parent_move, obj);
222 evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
223 _hover_parent_resize, obj);
227 _hover_parent_resize(void *data, Evas *e __UNUSED__,
228 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
230 Widget_Data *wd = elm_widget_data_get(data);
236 _scroller_size_reset(wd);
242 _hover_parent_move(void *data, Evas *e __UNUSED__,
243 Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
245 Widget_Data *wd = elm_widget_data_get(data);
251 _scroller_size_reset(wd);
257 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
258 void *event_info __UNUSED__)
260 Widget_Data *wd = elm_widget_data_get(data);
264 wd->hover_parent = NULL;
268 _item_sizing_eval(Elm_Ctxpopup_Item *item)
270 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
274 edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
276 evas_object_size_hint_min_set(item->base.view, min_w, min_h);
277 evas_object_size_hint_max_set(item->base.view, max_w, max_h);
281 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
282 Evas_Coord_Rectangle *hover_area)
284 pos->x -= (base_size->x / 2);
286 if (pos->x < hover_area->x)
287 pos->x = hover_area->x;
288 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
289 pos->x = (hover_area->x + hover_area->w) - base_size->x;
291 if (base_size->x > hover_area->w)
292 base_size->x -= (base_size->x - hover_area->w);
294 if (pos->x < hover_area->x)
295 pos->x = hover_area->x;
299 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
300 Evas_Coord_Rectangle *hover_area)
302 pos->y -= (base_size->y / 2);
304 if (pos->y < hover_area->y)
305 pos->y = hover_area->y;
306 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
307 pos->y = hover_area->y + hover_area->h - base_size->y;
309 if (base_size->y > hover_area->h)
310 base_size->y -= (base_size->y - hover_area->h);
312 if (pos->y < hover_area->y)
313 pos->y = hover_area->y;
317 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
318 Evas_Object *obj, void *event_info __UNUSED__)
322 wd = elm_widget_data_get(obj);
329 static Elm_Ctxpopup_Direction
330 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
333 Evas_Coord_Point pos = {0, 0};
334 Evas_Coord_Point base_size;
335 Evas_Coord_Point max_size;
336 Evas_Coord_Point min_size;
337 Evas_Coord_Rectangle hover_area;
338 Evas_Coord_Rectangle parent_size;
339 Evas_Coord_Point arrow_size;
340 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DOWN;
341 Evas_Coord_Point temp;
344 wd = elm_widget_data_get(obj);
346 if ((!wd) || (!rect))
347 return ELM_CTXPOPUP_DIRECTION_DOWN;
349 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
350 &arrow_size.x, &arrow_size.y);
351 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
353 //Initialize Area Rectangle.
354 if (wd->hover_parent)
355 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
356 &hover_area.w, &hover_area.h);
359 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
360 &parent_size.w, &parent_size.h);
361 hover_area.x = parent_size.x;
362 hover_area.y = parent_size.y;
363 hover_area.w = parent_size.w;
364 hover_area.h = parent_size.h;
367 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
370 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
371 evas_object_smart_calculate(wd->base);
374 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
376 if ((max_size.y > 0) && (base_size.y > max_size.y))
377 base_size.y = max_size.y;
379 if ((max_size.x > 0) && (base_size.x > max_size.x))
380 base_size.x = max_size.x;
383 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
385 if ((min_size.y > 0) && (base_size.y < min_size.y))
386 base_size.y = min_size.y;
388 if ((min_size.x > 0) && (base_size.x < min_size.x))
389 base_size.x = min_size.x;
391 //Check the Which direction is available.
392 //If find a avaialble direction, it adjusts position and size.
393 for (idx = 0; idx < 4; idx++)
395 switch (wd->dir_priority[idx])
397 case ELM_CTXPOPUP_DIRECTION_UP:
398 temp.y = (pos.y - base_size.y);
399 if ((temp.y - arrow_size.y) < hover_area.y)
401 _adjust_pos_x(&pos, &base_size, &hover_area);
402 pos.y -= base_size.y;
403 dir = ELM_CTXPOPUP_DIRECTION_UP;
405 case ELM_CTXPOPUP_DIRECTION_LEFT:
406 temp.x = (pos.x - base_size.x);
407 if ((temp.x - arrow_size.x) < hover_area.x)
409 _adjust_pos_y(&pos, &base_size, &hover_area);
410 pos.x -= base_size.x;
411 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
413 case ELM_CTXPOPUP_DIRECTION_RIGHT:
414 temp.x = (pos.x + base_size.x);
415 if ((temp.x + arrow_size.x) >
416 (hover_area.x + hover_area.w))
418 _adjust_pos_y(&pos, &base_size, &hover_area);
419 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
421 case ELM_CTXPOPUP_DIRECTION_DOWN:
422 temp.y = (pos.y + base_size.y);
423 if ((temp.y + arrow_size.y) >
424 (hover_area.y + hover_area.h))
426 _adjust_pos_x(&pos, &base_size, &hover_area);
427 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
435 //In this case, all directions are invalid because of lack of space.
438 Evas_Coord length[2];
442 length[0] = pos.y - hover_area.y;
443 length[1] = (hover_area.y + hover_area.h) - pos.y;
445 // ELM_CTXPOPUP_DIRECTION_UP
446 if (length[0] > length[1])
448 _adjust_pos_x(&pos, &base_size, &hover_area);
449 pos.y -= base_size.y;
450 dir = ELM_CTXPOPUP_DIRECTION_UP;
451 if (pos.y < (hover_area.y + arrow_size.y))
453 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
454 pos.y = hover_area.y + arrow_size.y;
457 //ELM_CTXPOPUP_DIRECTION_DOWN
460 _adjust_pos_x(&pos, &base_size, &hover_area);
461 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
462 if ((pos.y + arrow_size.y + base_size.y) >
463 (hover_area.y + hover_area.h))
465 ((pos.y + arrow_size.y + base_size.y) -
466 (hover_area.y + hover_area.h));
471 length[0] = pos.x - hover_area.x;
472 length[1] = (hover_area.x + hover_area.w) - pos.x;
474 //ELM_CTXPOPUP_DIRECTION_LEFT
475 if (length[0] > length[1])
477 _adjust_pos_y(&pos, &base_size, &hover_area);
478 pos.x -= base_size.x;
479 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
480 if (pos.x < (hover_area.x + arrow_size.x))
482 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
483 pos.x = hover_area.x + arrow_size.x;
486 //ELM_CTXPOPUP_DIRECTION_RIGHT
489 _adjust_pos_y(&pos, &base_size, &hover_area);
490 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
491 if (pos.x + (arrow_size.x + base_size.x) >
492 hover_area.x + hover_area.w)
494 ((pos.x + arrow_size.x + base_size.x) -
495 (hover_area.x + hover_area.w));
500 //Final position and size.
503 rect->w = base_size.x;
504 rect->h = base_size.y;
510 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
513 Evas_Coord_Rectangle arrow_size;
514 Evas_Coord_Rectangle base_size;
517 wd = elm_widget_data_get(obj);
520 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
521 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
523 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
524 &base_size.w, &base_size.h);
528 case ELM_CTXPOPUP_DIRECTION_RIGHT:
529 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
530 edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
533 if (y < ((arrow_size.h * 0.5) + base_size.y))
535 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
536 y = base_size.h - arrow_size.h;
538 y = y - base_size.y - (arrow_size.h * 0.5);
539 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
540 (double) (y) / (double) (base_size.h - arrow_size.h));
543 case ELM_CTXPOPUP_DIRECTION_LEFT:
544 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
545 edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
548 if (y < (arrow_size.h * 0.5) + base_size.y)
550 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
551 y = base_size.h - arrow_size.h;
552 else y = y - base_size.y - (arrow_size.h * 0.5);
553 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
554 (double) (y) / (double) (base_size.h - arrow_size.h));
557 case ELM_CTXPOPUP_DIRECTION_DOWN:
558 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
559 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
562 if (x < (arrow_size.w * 0.5) + base_size.x)
564 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
565 x = base_size.w - arrow_size.w;
567 x = x - base_size.x - (arrow_size.w * 0.5);
568 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
569 (double) (x) / (double) (base_size.w - arrow_size.w), 1);
572 case ELM_CTXPOPUP_DIRECTION_UP:
573 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
574 edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
577 if (x < (arrow_size.w * 0.5) + base_size.x)
579 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
580 x = base_size.w - arrow_size.w;
581 else x = x - base_size.x - (arrow_size.w * 0.5);
582 edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
583 (double) (x) / (double) (base_size.w - arrow_size.w), 0);
592 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
596 wd = elm_widget_data_get(obj);
597 if (!wd || wd->visible) return;
601 case ELM_CTXPOPUP_DIRECTION_UP:
602 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
604 case ELM_CTXPOPUP_DIRECTION_LEFT:
605 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
607 case ELM_CTXPOPUP_DIRECTION_RIGHT:
608 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
610 case ELM_CTXPOPUP_DIRECTION_DOWN:
611 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
619 _sizing_eval(Evas_Object *obj)
623 Elm_Ctxpopup_Item *item;
624 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
625 Evas_Coord_Point box_size = { 0, 0 };
626 Evas_Coord_Point _box_size = { 0, 0 };
628 wd = elm_widget_data_get(obj);
629 if ((!wd) || (!wd->parent)) return;
632 EINA_LIST_FOREACH(wd->items, elist, item)
634 _item_sizing_eval(item);
635 evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
638 if (_box_size.x > box_size.x)
639 box_size.x = _box_size.x;
640 if (_box_size.y != -1)
641 box_size.y += _box_size.y;
645 if (_box_size.x != -1)
646 box_size.x += _box_size.x;
647 if (_box_size.y > box_size.y)
648 box_size.y = _box_size.y;
654 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
655 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
659 wd->dir = _calc_base_geometry(obj, &rect);
660 _show_signal_emit(obj, wd->dir);
661 _update_arrow(obj, wd->dir);
662 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
664 //resize scroller according to final size.
666 evas_object_smart_calculate(wd->scr);
668 evas_object_move(wd->base, rect.x, rect.y);
669 evas_object_resize(wd->base, rect.w, rect.h);
673 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
674 Evas_Coord_Rectangle *rect)
676 Evas_Coord arrow_w, arrow_h;
678 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
682 case ELM_CTXPOPUP_DIRECTION_RIGHT:
685 case ELM_CTXPOPUP_DIRECTION_LEFT:
688 case ELM_CTXPOPUP_DIRECTION_DOWN:
691 case ELM_CTXPOPUP_DIRECTION_UP:
700 _del_pre_hook(Evas_Object *obj)
704 wd = elm_widget_data_get(obj);
707 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
708 _parent_resize, obj);
710 _hover_parent_callbacks_del(obj);
714 _del_hook(Evas_Object *obj)
718 wd = elm_widget_data_get(obj);
721 elm_ctxpopup_clear(obj);
722 evas_object_del(wd->arrow);
723 evas_object_del(wd->base);
728 _theme_hook(Evas_Object *obj)
732 Elm_Ctxpopup_Item *item;
734 wd = elm_widget_data_get(obj);
738 EINA_LIST_FOREACH(wd->items, elist, item)
740 if (item->label && item->icon)
741 _elm_theme_object_set(obj, item->base.view, "ctxpopup",
742 "icon_text_style_item",
743 elm_widget_style_get(obj));
744 else if (item->label)
745 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
746 elm_widget_style_get(obj));
748 _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
749 elm_widget_style_get(obj));
751 edje_object_part_text_set(item->base.view, "elm.text", item->label);
754 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
756 edje_object_message_signal_process(item->base.view);
759 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
760 elm_widget_style_get(obj));
761 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
762 elm_widget_style_get(obj));
763 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
764 elm_widget_style_get(obj));
768 if (!strncmp(elm_object_style_get(obj), "default",
770 elm_object_style_set(wd->scr, "ctxpopup");
772 elm_object_style_set(wd->scr, elm_object_style_get(obj));
777 _scroller_size_reset(wd);
783 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__,
784 Evas_Object *content)
786 ELM_CHECK_WIDTYPE(obj, widtype);
790 wd = elm_widget_data_get(obj);
791 if ((!wd) || (!content)) return;
793 if (wd->items) elm_ctxpopup_clear(obj);
794 if (wd->content) evas_object_del(wd->content);
796 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
799 elm_widget_sub_object_add(obj, content);
800 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
802 wd->content = content;
809 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
811 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
814 Evas_Object *content;
816 wd = elm_widget_data_get(obj);
817 if (!wd) return NULL;
819 content = wd->content;
820 if (!content) return NULL;
822 edje_object_part_unswallow(wd->base, content);
823 elm_widget_sub_object_del(obj, content);
824 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
825 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
834 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
836 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
838 Widget_Data *wd = elm_widget_data_get(obj);
839 if (!wd) return NULL;
844 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
845 const char *emission __UNUSED__, const char *source __UNUSED__)
847 evas_object_hide(data);
851 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
852 void *event_info __UNUSED__)
857 wd = elm_widget_data_get(data);
860 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
861 evas_object_resize(wd->bg, w, h);
863 if (!wd->visible) return;
869 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
870 void *event_info __UNUSED__)
874 wd = elm_widget_data_get(obj);
877 if ((!wd->items) && (!wd->content)) return;
879 wd->visible = EINA_TRUE;
881 evas_object_show(wd->bg);
882 evas_object_show(wd->base);
883 evas_object_show(wd->arrow);
885 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
886 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
890 elm_object_focus_set(obj, EINA_TRUE);
894 _hide(Evas_Object *obj)
896 Widget_Data *wd = elm_widget_data_get(obj);
900 evas_object_hide(wd->bg);
901 evas_object_hide(wd->arrow);
902 evas_object_hide(wd->base);
904 _scroller_size_reset(wd);
906 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
907 wd->visible = EINA_FALSE;
911 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
912 void *event_info __UNUSED__)
916 wd = elm_widget_data_get(obj);
917 if ((!wd) || (!wd->visible))
924 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
925 void *event_info __UNUSED__)
930 wd = elm_widget_data_get(data);
932 if (!wd->visible) return;
933 if (wd->finished) return;
935 evas_object_geometry_get(obj, 0, 0, &w, &h);
937 if (w != 0 && h != 0)
939 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
942 wd->finished = EINA_TRUE;
947 if (wd->max_sc_w < w)
949 if (wd->max_sc_h < h)
956 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
957 void *event_info __UNUSED__)
961 wd = elm_widget_data_get(obj);
966 evas_object_show(wd->arrow);
968 _scroller_size_reset(wd);
973 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
974 const char *emission __UNUSED__, const char *source __UNUSED__)
976 Elm_Ctxpopup_Item *item = data;
979 if (item->disabled) return;
982 item->func((void*) item->base.data, item->base.widget, data);
986 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
989 evas_object_del(item->icon);
994 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
995 edje_object_message_signal_process(item->base.view);
999 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1001 if (!eina_stringshare_replace(&item->label, label))
1004 edje_object_part_text_set(item->base.view, "elm.text", label);
1005 edje_object_message_signal_process(item->base.view);
1009 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1013 wd = elm_widget_data_get(item->base.widget);
1016 item->base.view = edje_object_add(evas_object_evas_get(wd->base));
1017 _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
1018 elm_widget_style_get(item->base.widget));
1019 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
1020 _item_select_cb, item);
1021 evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
1022 evas_object_show(item->base.view);
1026 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1027 void *event_info __UNUSED__)
1029 elm_object_content_unset(data);
1033 _list_del(Widget_Data *wd)
1035 if (!wd->scr) return;
1037 edje_object_part_unswallow(wd->base, wd->scr);
1038 evas_object_del(wd->scr);
1044 _list_new(Evas_Object *obj)
1047 wd = elm_widget_data_get(obj);
1051 wd->scr = elm_scroller_add(obj);
1052 elm_object_style_set(wd->scr, "ctxpopup");
1053 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1054 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1055 _scroller_resize, obj);
1056 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1059 wd->box = elm_box_add(obj);
1060 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1063 elm_scroller_content_set(wd->scr, wd->box);
1064 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1068 _remove_items(Widget_Data *wd)
1071 Elm_Ctxpopup_Item *item;
1073 if (!wd->items) return;
1075 EINA_LIST_FOREACH(wd->items, elist, item)
1078 eina_stringshare_del(item->label);
1080 evas_object_del(item->icon);
1081 wd->items = eina_list_remove(wd->items, item);
1089 elm_ctxpopup_add(Evas_Object *parent)
1094 Evas_Coord x, y, w, h;
1096 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1098 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1099 elm_widget_type_set(obj, "ctxpopup");
1100 elm_widget_sub_object_add(parent, obj);
1101 elm_widget_data_set(obj, wd);
1102 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1103 elm_widget_del_hook_set(obj, _del_hook);
1104 elm_widget_theme_hook_set(obj, _theme_hook);
1105 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1106 elm_widget_can_focus_set(obj, EINA_TRUE);
1107 elm_widget_event_hook_set(obj, _event_hook);
1108 elm_widget_content_set_hook_set(obj, _content_set_hook);
1109 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1110 elm_widget_content_get_hook_set(obj, _content_get_hook);
1112 wd->parent = parent;
1115 wd->bg = edje_object_add(e);
1116 elm_widget_sub_object_add(obj, wd->bg);
1117 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1118 evas_object_geometry_get(parent, &x, &y, &w, &h);
1119 evas_object_move(wd->bg, x, y);
1120 evas_object_resize(wd->bg, w, h);
1121 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1122 _bg_clicked_cb, obj);
1125 wd->base = edje_object_add(e);
1126 elm_widget_sub_object_add(obj, wd->base);
1127 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1130 wd->arrow = edje_object_add(e);
1131 elm_widget_sub_object_add(obj, wd->arrow);
1132 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1134 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1135 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1136 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1137 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1139 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1141 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1143 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1145 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1147 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1148 _ctxpopup_changed_size_hints, NULL);
1149 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1150 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1151 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1152 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1154 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1160 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1162 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1163 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1164 return ctxpopup_it->icon;
1168 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1170 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1173 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1175 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1178 _item_icon_set(ctxpopup_it, icon);
1182 _scroller_size_reset(wd);
1183 _sizing_eval(ctxpopup_it->base.widget);
1188 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1190 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1191 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1192 return ctxpopup_it->label;
1196 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1198 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1201 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1203 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1206 _item_label_set(ctxpopup_it, label);
1210 _scroller_size_reset(wd);
1211 _sizing_eval(ctxpopup_it->base.widget);
1216 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1218 ELM_CHECK_WIDTYPE(obj, widtype);
1222 wd = elm_widget_data_get(obj);
1225 _hover_parent_callbacks_del(obj);
1229 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1230 _hover_parent_del, obj);
1231 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1232 _hover_parent_move, obj);
1233 evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1234 _hover_parent_resize, obj);
1237 wd->hover_parent = hover_parent;
1241 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1243 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1247 wd = elm_widget_data_get(obj);
1248 if (!wd) return NULL;
1250 return wd->hover_parent;
1254 elm_ctxpopup_clear(Evas_Object * obj)
1256 ELM_CHECK_WIDTYPE(obj, widtype);
1258 Widget_Data *wd = elm_widget_data_get(obj);
1266 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1268 ELM_CHECK_WIDTYPE(obj, widtype);
1272 wd = elm_widget_data_get(obj);
1275 wd->horizontal = !!horizontal;
1277 if ((!wd->scr) && (!wd->box))
1282 elm_box_horizontal_set(wd->box, EINA_FALSE);
1283 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1287 elm_box_horizontal_set(wd->box, EINA_TRUE);
1288 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1296 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1298 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1302 wd = elm_widget_data_get(obj);
1303 if (!wd) return EINA_FALSE;
1305 return wd->horizontal;
1308 EAPI Elm_Object_Item *
1309 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1310 Evas_Object *icon, Evas_Smart_Cb func,
1313 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1316 Elm_Ctxpopup_Item *item;
1318 wd = elm_widget_data_get(obj);
1319 if (!wd) return NULL;
1321 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1322 if (!item) return NULL;
1324 //The first item is appended.
1326 evas_object_del(elm_object_content_unset(obj));
1332 item->base.data = data;
1335 _item_new(item, "icon_text_style_item");
1337 _item_new(item, "text_style_item");
1339 _item_new(item, "icon_style_item");
1341 _item_icon_set(item, icon);
1342 _item_label_set(item, label);
1343 elm_box_pack_end(wd->box, item->base.view);
1344 wd->items = eina_list_append(wd->items, item);
1348 _scroller_size_reset(wd);
1352 return ELM_CAST(item);
1356 elm_ctxpopup_item_del(Elm_Object_Item *it)
1358 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1361 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1363 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1366 if (ctxpopup_it->icon)
1367 evas_object_del(ctxpopup_it->icon);
1368 if (ctxpopup_it->base.view)
1369 evas_object_del(ctxpopup_it->base.view);
1371 eina_stringshare_del(ctxpopup_it->label);
1373 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1375 if (eina_list_count(wd->items) < 1)
1379 _sizing_eval(ctxpopup_it->base.widget);
1385 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1387 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1390 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1392 wd = elm_widget_data_get(ctxpopup_it->base.widget);
1395 ctxpopup_it = ELM_CAST(it);
1397 if (disabled == ctxpopup_it->disabled)
1401 edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,disabled", "elm");
1403 edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,enabled", "elm");
1405 ctxpopup_it->disabled = !!disabled;
1409 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1411 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1412 Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1413 return ctxpopup_it->disabled;
1417 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1419 elm_object_content_set(obj, content);
1423 elm_ctxpopup_content_unset(Evas_Object *obj)
1425 return elm_object_content_unset(obj);
1429 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1430 Elm_Ctxpopup_Direction first,
1431 Elm_Ctxpopup_Direction second,
1432 Elm_Ctxpopup_Direction third,
1433 Elm_Ctxpopup_Direction fourth)
1435 ELM_CHECK_WIDTYPE(obj, widtype);
1438 wd = elm_widget_data_get(obj);
1441 wd->dir_priority[0] = first;
1442 wd->dir_priority[1] = second;
1443 wd->dir_priority[2] = third;
1444 wd->dir_priority[3] = fourth;
1451 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1452 Elm_Ctxpopup_Direction *first,
1453 Elm_Ctxpopup_Direction *second,
1454 Elm_Ctxpopup_Direction *third,
1455 Elm_Ctxpopup_Direction *fourth)
1457 ELM_CHECK_WIDTYPE(obj, widtype);
1460 wd = elm_widget_data_get(obj);
1463 if (first) *first = wd->dir_priority[0];
1464 if (second) *second = wd->dir_priority[1];
1465 if (third) *third = wd->dir_priority[2];
1466 if (fourth) *fourth = wd->dir_priority[3];