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 _content_resize(void *data,
112 static void _scroller_resize(void *data,
116 static void _ctxpopup_move(void *data,
120 static void _item_select_cb(void *data, Evas_Object *obj,
121 const char *emission,
123 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
124 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
125 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
126 static void _content_del(void *data,
130 static void _list_del(Widget_Data *wd);
131 static void _list_new(Evas_Object *obj);
132 static void _remove_items(Widget_Data * wd);
134 static const char SIG_DISMISSED[] = "dismissed";
136 static const Evas_Smart_Cb_Description _signals[] = {
142 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
143 void *event_info __UNUSED__)
145 Widget_Data *wd = elm_widget_data_get(obj);
147 if ((!wd) || (!wd->scr)) return;
148 elm_object_scroll_freeze_push(wd->scr);
152 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
153 void *event_info __UNUSED__)
155 Widget_Data *wd = elm_widget_data_get(obj);
157 if ((!wd) || (!wd->scr)) return;
158 elm_object_scroll_freeze_pop(wd->scr);
162 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
164 Widget_Data *wd = elm_widget_data_get(obj);
166 if ((!wd) || (!wd->scr)) return;
167 elm_object_scroll_hold_push(wd->scr);
171 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
173 Widget_Data *wd = elm_widget_data_get(obj);
175 if ((!wd) || (!wd->scr)) return;
176 elm_object_scroll_hold_pop(wd->scr);
180 _scroller_size_reset(Widget_Data *wd)
182 wd->finished = EINA_FALSE;
188 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
190 Widget_Data *wd = elm_widget_data_get(obj);
193 if (elm_widget_focus_get(obj))
204 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
206 Evas_Event_Key_Down *ev;
209 if (type != EVAS_CALLBACK_KEY_DOWN)
211 wd = elm_widget_data_get(obj);
212 if (!wd) return EINA_FALSE;
215 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
216 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
218 evas_object_hide(obj);
219 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
224 _parent_cut_off(Evas_Object *obj)
226 Widget_Data *wd = elm_widget_data_get(obj);
230 evas_object_event_callback_del_full(wd->parent,
234 evas_object_event_callback_del_full(wd->parent,
238 evas_object_event_callback_del_full(wd->parent,
239 EVAS_CALLBACK_RESIZE,
243 elm_widget_sub_object_del(wd->parent, obj);
247 _parent_resize(void *data,
249 Evas_Object *obj __UNUSED__,
250 void *event_info __UNUSED__)
252 Widget_Data *wd = elm_widget_data_get(data);
255 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
261 _parent_move(void *data,
263 Evas_Object *obj __UNUSED__,
264 void *event_info __UNUSED__)
266 Widget_Data *wd = elm_widget_data_get(data);
270 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
274 _scroller_size_reset(wd);
280 _parent_del(void *data,
282 Evas_Object *obj __UNUSED__,
283 void *event_info __UNUSED__)
285 evas_object_del(data);
289 _item_sizing_eval(Elm_Ctxpopup_Item *item)
291 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
295 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
297 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
298 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
302 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
303 Evas_Coord_Rectangle *hover_area)
305 pos->x -= (base_size->x / 2);
307 if (pos->x < hover_area->x)
308 pos->x = hover_area->x;
309 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
310 pos->x = (hover_area->x + hover_area->w) - base_size->x;
312 if (base_size->x > hover_area->w)
313 base_size->x -= (base_size->x - hover_area->w);
315 if (pos->x < hover_area->x)
316 pos->x = hover_area->x;
320 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
321 Evas_Coord_Rectangle *hover_area)
323 pos->y -= (base_size->y / 2);
325 if (pos->y < hover_area->y)
326 pos->y = hover_area->y;
327 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
328 pos->y = hover_area->y + hover_area->h - base_size->y;
330 if (base_size->y > hover_area->h)
331 base_size->y -= (base_size->y - hover_area->h);
333 if (pos->y < hover_area->y)
334 pos->y = hover_area->y;
337 static Elm_Ctxpopup_Direction
338 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
341 Evas_Coord_Point pos = {0, 0};
342 Evas_Coord_Point base_size;
343 Evas_Coord_Point max_size;
344 Evas_Coord_Point min_size;
345 Evas_Coord_Rectangle hover_area;
346 Evas_Coord_Point arrow_size;
347 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
348 Evas_Coord_Point temp;
351 wd = elm_widget_data_get(obj);
353 if ((!wd) || (!rect))
354 return ELM_CTXPOPUP_DIRECTION_DOWN;
356 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
357 &arrow_size.x, &arrow_size.y);
358 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
360 //Initialize Area Rectangle.
361 evas_object_geometry_get(wd->parent,
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_UNKNOWN:
398 case ELM_CTXPOPUP_DIRECTION_UP:
399 temp.y = (pos.y - base_size.y);
400 if ((temp.y - arrow_size.y) < hover_area.y)
402 _adjust_pos_x(&pos, &base_size, &hover_area);
403 pos.y -= base_size.y;
404 dir = ELM_CTXPOPUP_DIRECTION_UP;
406 case ELM_CTXPOPUP_DIRECTION_LEFT:
407 temp.x = (pos.x - base_size.x);
408 if ((temp.x - arrow_size.x) < hover_area.x)
410 _adjust_pos_y(&pos, &base_size, &hover_area);
411 pos.x -= base_size.x;
412 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
414 case ELM_CTXPOPUP_DIRECTION_RIGHT:
415 temp.x = (pos.x + base_size.x);
416 if ((temp.x + arrow_size.x) >
417 (hover_area.x + hover_area.w))
419 _adjust_pos_y(&pos, &base_size, &hover_area);
420 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
422 case ELM_CTXPOPUP_DIRECTION_DOWN:
423 temp.y = (pos.y + base_size.y);
424 if ((temp.y + arrow_size.y) >
425 (hover_area.y + hover_area.h))
427 _adjust_pos_x(&pos, &base_size, &hover_area);
428 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
436 //In this case, all directions are invalid because of lack of space.
439 Evas_Coord length[2];
443 length[0] = pos.y - hover_area.y;
444 length[1] = (hover_area.y + hover_area.h) - pos.y;
446 // ELM_CTXPOPUP_DIRECTION_UP
447 if (length[0] > length[1])
449 _adjust_pos_x(&pos, &base_size, &hover_area);
450 pos.y -= base_size.y;
451 dir = ELM_CTXPOPUP_DIRECTION_UP;
452 if (pos.y < (hover_area.y + arrow_size.y))
454 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
455 pos.y = hover_area.y + arrow_size.y;
458 //ELM_CTXPOPUP_DIRECTION_DOWN
461 _adjust_pos_x(&pos, &base_size, &hover_area);
462 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
463 if ((pos.y + arrow_size.y + base_size.y) >
464 (hover_area.y + hover_area.h))
466 ((pos.y + arrow_size.y + base_size.y) -
467 (hover_area.y + hover_area.h));
472 length[0] = pos.x - hover_area.x;
473 length[1] = (hover_area.x + hover_area.w) - pos.x;
475 //ELM_CTXPOPUP_DIRECTION_LEFT
476 if (length[0] > length[1])
478 _adjust_pos_y(&pos, &base_size, &hover_area);
479 pos.x -= base_size.x;
480 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
481 if (pos.x < (hover_area.x + arrow_size.x))
483 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
484 pos.x = hover_area.x + arrow_size.x;
487 //ELM_CTXPOPUP_DIRECTION_RIGHT
490 _adjust_pos_y(&pos, &base_size, &hover_area);
491 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
492 if (pos.x + (arrow_size.x + base_size.x) >
493 hover_area.x + hover_area.w)
495 ((pos.x + arrow_size.x + base_size.x) -
496 (hover_area.x + hover_area.w));
501 //Final position and size.
504 rect->w = base_size.x;
505 rect->h = base_size.y;
511 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir, Evas_Coord_Rectangle base_size)
514 Evas_Coord_Rectangle arrow_size;
518 wd = elm_widget_data_get(obj);
521 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
522 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
525 edje_object_part_unswallow(wd->base, wd->arrow);
529 case ELM_CTXPOPUP_DIRECTION_RIGHT:
530 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
531 edje_object_part_swallow(wd->base,
532 "elm.swallow.arrow_left",
536 if (y < ((arrow_size.h * 0.5) + base_size.y))
538 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
539 y = base_size.h - arrow_size.h;
541 y = y - base_size.y - (arrow_size.h * 0.5);
542 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
543 edje_object_part_drag_value_set(wd->base,
544 "elm.swallow.arrow_left",
549 case ELM_CTXPOPUP_DIRECTION_LEFT:
550 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
551 edje_object_part_swallow(wd->base,
552 "elm.swallow.arrow_right",
556 if (y < ((arrow_size.h * 0.5) + base_size.y))
558 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
559 y = base_size.h - arrow_size.h;
561 y = y - base_size.y - (arrow_size.h * 0.5);
562 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
563 edje_object_part_drag_value_set(wd->base,
564 "elm.swallow.arrow_right",
569 case ELM_CTXPOPUP_DIRECTION_DOWN:
570 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
571 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
574 if (x < ((arrow_size.w * 0.5) + base_size.x))
576 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
577 x = base_size.w - arrow_size.w;
579 x = x - base_size.x - (arrow_size.w * 0.5);
580 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
581 edje_object_part_drag_value_set(wd->base,
582 "elm.swallow.arrow_up",
587 case ELM_CTXPOPUP_DIRECTION_UP:
588 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
589 edje_object_part_swallow(wd->base,
590 "elm.swallow.arrow_down",
594 if (x < ((arrow_size.w * 0.5) + base_size.x))
596 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
597 x = base_size.w - arrow_size.w;
598 else x = x - base_size.x - (arrow_size.w * 0.5);
599 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
600 edje_object_part_drag_value_set(wd->base,
601 "elm.swallow.arrow_down",
612 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
616 wd = elm_widget_data_get(obj);
617 if (!wd || wd->visible) return;
621 case ELM_CTXPOPUP_DIRECTION_UP:
622 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
624 case ELM_CTXPOPUP_DIRECTION_LEFT:
625 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
627 case ELM_CTXPOPUP_DIRECTION_RIGHT:
628 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
630 case ELM_CTXPOPUP_DIRECTION_DOWN:
631 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
639 _sizing_eval(Evas_Object *obj)
643 Elm_Ctxpopup_Item *item;
644 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
645 Evas_Coord_Point box_size = { 0, 0 };
646 Evas_Coord_Point _box_size = { 0, 0 };
648 wd = elm_widget_data_get(obj);
652 EINA_LIST_FOREACH(wd->items, elist, item)
654 _item_sizing_eval(item);
655 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
658 if (_box_size.x > box_size.x)
659 box_size.x = _box_size.x;
660 if (_box_size.y != -1)
661 box_size.y += _box_size.y;
665 if (_box_size.x != -1)
666 box_size.x += _box_size.x;
667 if (_box_size.y > box_size.y)
668 box_size.y = _box_size.y;
674 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
675 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
679 wd->dir = _calc_base_geometry(obj, &rect);
680 _show_signal_emit(obj, wd->dir);
681 _update_arrow(obj, wd->dir, rect);
682 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
684 //resize scroller according to final size.
686 evas_object_smart_calculate(wd->scr);
688 evas_object_move(wd->base, rect.x, rect.y);
689 evas_object_resize(wd->base, rect.w, rect.h);
693 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
694 Evas_Coord_Rectangle *rect)
696 Evas_Coord arrow_w, arrow_h;
698 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
702 case ELM_CTXPOPUP_DIRECTION_RIGHT:
705 case ELM_CTXPOPUP_DIRECTION_LEFT:
708 case ELM_CTXPOPUP_DIRECTION_DOWN:
711 case ELM_CTXPOPUP_DIRECTION_UP:
720 _del_pre_hook(Evas_Object *obj)
724 wd = elm_widget_data_get(obj);
727 _parent_cut_off(obj);
731 _del_hook(Evas_Object *obj)
735 wd = elm_widget_data_get(obj);
738 elm_ctxpopup_clear(obj);
739 evas_object_del(wd->arrow);
740 evas_object_del(wd->base);
744 //FIXME: lost the content size when theme hook is called.
746 _theme_hook(Evas_Object *obj)
750 Elm_Ctxpopup_Item *item;
753 wd = elm_widget_data_get(obj);
756 _elm_widget_mirrored_reload(obj);
757 rtl = elm_widget_mirrored_get(obj);
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));
767 EINA_LIST_FOREACH(wd->items, elist, item)
769 edje_object_mirrored_set(VIEW(item), rtl);
771 if (item->label && item->icon)
772 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
773 "icon_text_style_item",
774 elm_widget_style_get(obj));
775 else if (item->label)
776 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
777 elm_widget_style_get(obj));
779 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
780 elm_widget_style_get(obj));
782 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
784 if (elm_widget_item_disabled_get(item))
785 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
787 edje_object_message_signal_process(VIEW(item));
792 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
793 elm_object_style_set(wd->scr, "ctxpopup");
795 elm_object_style_set(wd->scr, elm_object_style_get(obj));
798 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
802 _scroller_size_reset(wd);
808 _content_set_hook(Evas_Object *obj, const char *part,
809 Evas_Object *content)
811 ELM_CHECK_WIDTYPE(obj, widtype);
812 Evas_Coord min_w = -1, min_h = -1;
816 if (part && strcmp(part, "default")) return;
818 wd = elm_widget_data_get(obj);
819 if ((!wd) || (!content)) return;
821 if (wd->items) elm_ctxpopup_clear(obj);
822 if (wd->content) evas_object_del(wd->content);
825 wd->box = elm_box_add(obj);
826 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
828 evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
830 evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
832 evas_object_show(content);
833 evas_object_size_hint_min_get(content, &min_w, &min_h);
834 evas_object_size_hint_min_set(wd->box, min_w, min_h);
835 elm_box_pack_end(wd->box, content);
837 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
838 _content_resize, obj);
839 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
842 elm_widget_sub_object_add(obj, wd->box);
843 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
845 wd->content = content;
846 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
853 _content_unset_hook(Evas_Object *obj, const char *part)
855 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
858 Evas_Object *content;
859 if (part && strcmp(part, "default")) return NULL;
860 wd = elm_widget_data_get(obj);
861 if (!wd) return NULL;
863 content = wd->content;
864 if (!content || !wd->box) return NULL;
866 edje_object_part_unswallow(wd->base, wd->box);
867 elm_widget_sub_object_del(obj, wd->box);
868 evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
869 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
871 evas_object_del(wd->box);
874 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
880 _content_get_hook(const Evas_Object *obj, const char *part)
882 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
884 if (part && strcmp(part, "default")) return NULL;
885 wd = elm_widget_data_get(obj);
886 if (!wd) return NULL;
891 _item_text_set_hook(Elm_Object_Item *it,
895 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
898 Elm_Ctxpopup_Item *ctxpopup_it;
900 if (part && strcmp(part, "default")) return;
902 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
904 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
907 _item_label_set(ctxpopup_it, label);
908 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
912 _scroller_size_reset(wd);
913 _sizing_eval(WIDGET(ctxpopup_it));
918 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
920 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
921 Elm_Ctxpopup_Item *ctxpopup_it;
922 if (part && strcmp(part, "default")) return NULL;
923 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
924 return ctxpopup_it->label;
928 _item_content_set_hook(Elm_Object_Item *it,
930 Evas_Object *content)
932 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
934 Elm_Ctxpopup_Item *ctxpopup_it;
936 if (part && strcmp(part, "icon")) return;
938 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
940 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
943 _item_icon_set(ctxpopup_it, content);
944 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
948 _scroller_size_reset(wd);
949 _sizing_eval(WIDGET(ctxpopup_it));
954 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
956 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
957 Elm_Ctxpopup_Item *ctxpopup_it;
958 if (part && strcmp(part, "icon")) return NULL;
959 ctxpopup_it = (Elm_Ctxpopup_Item *) it;
960 return ctxpopup_it->icon;
964 _item_disable_set_hook(Elm_Object_Item *it)
966 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
969 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
971 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
974 if (elm_widget_item_disabled_get(it))
975 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
977 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
981 _item_signal_emit_hook(Elm_Object_Item *it,
982 const char *emission,
985 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
986 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
987 edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
991 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
992 const char *emission __UNUSED__, const char *source __UNUSED__)
994 evas_object_hide(data);
998 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
999 void *event_info __UNUSED__)
1003 wd = elm_widget_data_get(obj);
1006 if ((!wd->items) && (!wd->content)) return;
1008 wd->visible = EINA_TRUE;
1010 evas_object_show(wd->bg);
1011 evas_object_show(wd->base);
1012 evas_object_show(wd->arrow);
1014 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
1015 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
1019 elm_object_focus_set(obj, EINA_TRUE);
1023 _hide(Evas_Object *obj)
1025 Widget_Data *wd = elm_widget_data_get(obj);
1027 if ((!wd) || (!wd->visible)) return;
1029 evas_object_hide(wd->bg);
1030 evas_object_hide(wd->arrow);
1031 evas_object_hide(wd->base);
1033 _scroller_size_reset(wd);
1035 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1036 wd->visible = EINA_FALSE;
1040 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1041 void *event_info __UNUSED__)
1047 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1048 void *event_info __UNUSED__)
1052 wd = elm_widget_data_get(data);
1055 elm_box_recalculate(wd->box);
1060 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1061 void *event_info __UNUSED__)
1066 wd = elm_widget_data_get(data);
1068 if (!wd->visible) return;
1069 if (wd->finished) return;
1071 evas_object_geometry_get(obj, 0, 0, &w, &h);
1073 if (w != 0 && h != 0)
1075 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1078 wd->finished = EINA_TRUE;
1083 if (wd->max_sc_w < w)
1085 if (wd->max_sc_h < h)
1092 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1093 void *event_info __UNUSED__)
1097 wd = elm_widget_data_get(obj);
1102 evas_object_show(wd->arrow);
1104 _scroller_size_reset(wd);
1109 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1110 const char *emission __UNUSED__, const char *source __UNUSED__)
1112 Elm_Ctxpopup_Item *item = data;
1115 if (elm_widget_item_disabled_get(item)) return;
1118 item->func((void*) item->base.data, WIDGET(item), data);
1122 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1125 evas_object_del(item->icon);
1130 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1131 edje_object_message_signal_process(VIEW(item));
1135 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1137 if (!eina_stringshare_replace(&item->label, label))
1140 edje_object_part_text_set(VIEW(item), "elm.text", label);
1141 edje_object_message_signal_process(VIEW(item));
1145 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1149 wd = elm_widget_data_get(WIDGET(item));
1152 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1153 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
1154 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1155 elm_widget_style_get(WIDGET(item)));
1156 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1157 _item_select_cb, item);
1158 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1159 evas_object_show(VIEW(item));
1163 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1164 void *event_info __UNUSED__)
1166 elm_object_content_unset(data);
1170 _list_del(Widget_Data *wd)
1172 if (!wd->scr) return;
1174 edje_object_part_unswallow(wd->base, wd->scr);
1175 evas_object_del(wd->scr);
1181 _list_new(Evas_Object *obj)
1184 wd = elm_widget_data_get(obj);
1188 wd->scr = elm_scroller_add(obj);
1189 elm_object_style_set(wd->scr, "ctxpopup");
1190 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1191 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1192 _scroller_resize, obj);
1193 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1196 wd->box = elm_box_add(obj);
1197 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1200 elm_object_content_set(wd->scr, wd->box);
1201 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1205 _remove_items(Widget_Data *wd)
1208 Elm_Ctxpopup_Item *item;
1210 if (!wd->items) return;
1212 EINA_LIST_FOREACH(wd->items, elist, item)
1215 eina_stringshare_del(item->label);
1217 evas_object_del(item->icon);
1218 wd->items = eina_list_remove(wd->items, item);
1226 elm_ctxpopup_add(Evas_Object *parent)
1232 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1234 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1235 elm_widget_type_set(obj, "ctxpopup");
1236 elm_widget_data_set(obj, wd);
1237 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1238 elm_widget_del_hook_set(obj, _del_hook);
1239 elm_widget_theme_hook_set(obj, _theme_hook);
1240 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1241 elm_widget_can_focus_set(obj, EINA_TRUE);
1242 elm_widget_event_hook_set(obj, _event_hook);
1243 elm_widget_content_set_hook_set(obj, _content_set_hook);
1244 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1245 elm_widget_content_get_hook_set(obj, _content_get_hook);
1248 wd->bg = edje_object_add(e);
1249 elm_widget_sub_object_add(obj, wd->bg);
1250 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1251 edje_object_signal_callback_add(wd->bg,
1257 wd->base = edje_object_add(e);
1258 elm_widget_sub_object_add(obj, wd->base);
1259 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1262 wd->arrow = edje_object_add(e);
1263 elm_widget_sub_object_add(obj, wd->arrow);
1264 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1266 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1267 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1268 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1269 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1270 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1272 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1274 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1276 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1278 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1279 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1280 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1281 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1283 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1285 //default parent is to be hover parent
1286 elm_ctxpopup_hover_parent_set(obj, parent);
1292 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1294 return _item_content_get_hook(it, "icon");
1298 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1300 _item_content_set_hook(it, "icon", icon);
1304 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1306 return _item_text_get_hook(it, NULL);
1310 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1312 _item_text_set_hook(it, NULL, label);
1316 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1318 ELM_CHECK_WIDTYPE(obj, widtype);
1321 Evas_Coord x, y, w, h;
1323 wd = elm_widget_data_get(obj);
1324 if ((!wd) || (!parent)) return;
1326 _parent_cut_off(obj);
1330 evas_object_event_callback_add(parent,
1334 evas_object_event_callback_add(parent,
1338 evas_object_event_callback_add(parent,
1339 EVAS_CALLBACK_RESIZE,
1344 elm_widget_sub_object_add(parent, obj);
1345 wd->parent = parent;
1348 evas_object_geometry_get(parent, &x, &y, &w, &h);
1349 evas_object_move(wd->bg, x, y);
1350 evas_object_resize(wd->bg, w, h);
1352 if (wd->visible) _sizing_eval(obj);
1356 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1358 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1362 wd = elm_widget_data_get(obj);
1363 if (!wd) return NULL;
1369 elm_ctxpopup_clear(Evas_Object * obj)
1371 ELM_CHECK_WIDTYPE(obj, widtype);
1373 Widget_Data *wd = elm_widget_data_get(obj);
1378 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1382 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1384 ELM_CHECK_WIDTYPE(obj, widtype);
1388 wd = elm_widget_data_get(obj);
1391 wd->horizontal = !!horizontal;
1393 if ((!wd->scr) && (!wd->box))
1398 elm_box_horizontal_set(wd->box, EINA_FALSE);
1399 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1403 elm_box_horizontal_set(wd->box, EINA_TRUE);
1404 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1407 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1414 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1416 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1420 wd = elm_widget_data_get(obj);
1421 if (!wd) return EINA_FALSE;
1423 return wd->horizontal;
1426 EAPI Elm_Object_Item *
1427 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1428 Evas_Object *icon, Evas_Smart_Cb func,
1431 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1434 Evas_Object *content;
1435 Elm_Ctxpopup_Item *item;
1437 wd = elm_widget_data_get(obj);
1438 if (!wd) return NULL;
1440 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1441 if (!item) return NULL;
1443 elm_widget_item_disable_set_hook_set(item, _item_disable_set_hook);
1444 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1445 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1446 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1447 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1448 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1450 //The first item is appended.
1451 content = elm_object_content_unset(obj);
1452 if (content) evas_object_del(content);
1458 item->base.data = data;
1461 _item_new(item, "icon_text_style_item");
1463 _item_new(item, "text_style_item");
1465 _item_new(item, "icon_style_item");
1467 _item_icon_set(item, icon);
1468 _item_label_set(item, label);
1469 elm_box_pack_end(wd->box, VIEW(item));
1470 wd->items = eina_list_append(wd->items, item);
1471 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1475 _scroller_size_reset(wd);
1479 return (Elm_Object_Item *) item;
1483 elm_ctxpopup_item_del(Elm_Object_Item *it)
1485 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1488 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1490 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1493 if (ctxpopup_it->icon)
1494 evas_object_del(ctxpopup_it->icon);
1495 if (VIEW(ctxpopup_it))
1496 evas_object_del(VIEW(ctxpopup_it));
1498 eina_stringshare_del(ctxpopup_it->label);
1500 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1502 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1504 elm_widget_item_del(ctxpopup_it);
1506 if (eina_list_count(wd->items) < 1)
1508 evas_object_hide(WIDGET(ctxpopup_it));
1513 _sizing_eval(WIDGET(ctxpopup_it));
1518 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1520 elm_object_item_disabled_set(it, disabled);
1524 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1526 return elm_object_item_disabled_get(it);
1530 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1532 elm_object_content_set(obj, content);
1536 elm_ctxpopup_content_unset(Evas_Object *obj)
1538 return elm_object_content_unset(obj);
1542 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1543 Elm_Ctxpopup_Direction first,
1544 Elm_Ctxpopup_Direction second,
1545 Elm_Ctxpopup_Direction third,
1546 Elm_Ctxpopup_Direction fourth)
1548 ELM_CHECK_WIDTYPE(obj, widtype);
1551 wd = elm_widget_data_get(obj);
1554 wd->dir_priority[0] = first;
1555 wd->dir_priority[1] = second;
1556 wd->dir_priority[2] = third;
1557 wd->dir_priority[3] = fourth;
1564 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1565 Elm_Ctxpopup_Direction *first,
1566 Elm_Ctxpopup_Direction *second,
1567 Elm_Ctxpopup_Direction *third,
1568 Elm_Ctxpopup_Direction *fourth)
1570 ELM_CHECK_WIDTYPE(obj, widtype);
1573 wd = elm_widget_data_get(obj);
1576 if (first) *first = wd->dir_priority[0];
1577 if (second) *second = wd->dir_priority[1];
1578 if (third) *third = wd->dir_priority[2];
1579 if (fourth) *fourth = wd->dir_priority[3];
1582 EAPI Elm_Ctxpopup_Direction
1583 elm_ctxpopup_direction_get(const Evas_Object *obj)
1585 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1588 wd = elm_widget_data_get(obj);
1589 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;