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
10 Elm_Object_Item *list_item;
22 Elm_Ctxpopup_Direction dir;
23 Elm_Ctxpopup_Direction dir_priority[4];
24 Eina_Bool horizontal:1;
26 Eina_Bool list_visible:1;
30 static const char *widtype = NULL;
32 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
33 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
34 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
35 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
36 static void _on_focus_hook(void *data, Evas_Object *obj);
37 static Eina_Bool _event_hook(Evas_Object *obj,
39 Evas_Callback_Type type,
41 static void _parent_cut_off(Evas_Object *obj);
42 static void _parent_resize(void *data,
46 static void _parent_move(void *data,
50 static void _parent_del(void *data,
54 static void _adjust_pos_x(Evas_Coord_Point *pos,
55 Evas_Coord_Point *base_size,
56 Evas_Coord_Rectangle *hover_area);
57 static void _adjust_pos_y(Evas_Coord_Point *pos,
58 Evas_Coord_Point *base_size,
59 Evas_Coord_Rectangle *hover_area);
60 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
61 Evas_Coord_Rectangle *rect);
62 static void _update_arrow(Evas_Object *obj,
63 Elm_Ctxpopup_Direction dir,
64 Evas_Coord_Rectangle rect);
65 static void _sizing_eval(Evas_Object *obj);
66 static void _hide_signal_emit(Evas_Object *obj,
67 Elm_Ctxpopup_Direction dir);
68 static void _show_signal_emit(Evas_Object *obj,
69 Elm_Ctxpopup_Direction dir);
70 static void _shift_base_by_arrow(Evas_Object *arrow,
71 Elm_Ctxpopup_Direction dir,
72 Evas_Coord_Rectangle *rect);
73 static void _del_pre_hook(Evas_Object *obj);
74 static void _del_hook(Evas_Object *obj);
75 static void _theme_hook(Evas_Object *obj);
76 static void _content_set_hook(Evas_Object *obj,
78 Evas_Object *content);
79 static Evas_Object * _content_unset_hook(Evas_Object *obj,
81 static Evas_Object * _content_get_hook(const Evas_Object *obj,
83 static void _item_text_set_hook(Elm_Object_Item *it,
86 static const char * _item_text_get_hook(const Elm_Object_Item *it,
88 static void _item_content_set_hook(Elm_Object_Item *it,
90 Evas_Object *content);
91 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
93 static void _item_disable_hook(Elm_Object_Item *it);
94 static void _item_signal_emit_hook(Elm_Object_Item *it,
97 static void _bg_clicked_cb(void *data, Evas_Object *obj,
100 static void _ctxpopup_show(void *data,
104 static void _hide_finished(void *data,
106 const char *emission,
107 const char *source __UNUSED__);
108 static void _ctxpopup_hide(void *data,
112 static void _content_resize(void *data,
116 static void _ctxpopup_move(void *data,
120 static void _restack(void *data, Evas *e, Evas_Object *obj, void *event_info);
121 static void _content_del(void *data,
125 static void _list_del(Widget_Data *wd);
126 static void _disable_hook(Evas_Object *obj);
127 static void _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source);
128 static void _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data);
129 static void _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data);
131 static const char SIG_DISMISSED[] = "dismissed";
133 static const Evas_Smart_Cb_Description _signals[] = {
139 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
140 void *event_info __UNUSED__)
142 Widget_Data *wd = elm_widget_data_get(obj);
144 if ((!wd) || (!wd->list)) return;
145 elm_widget_scroll_freeze_push(wd->list);
149 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
150 void *event_info __UNUSED__)
152 Widget_Data *wd = elm_widget_data_get(obj);
154 if ((!wd) || (!wd->list)) return;
155 elm_widget_scroll_freeze_pop(wd->list);
159 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
161 Widget_Data *wd = elm_widget_data_get(obj);
163 if ((!wd) || (!wd->list)) return;
164 elm_widget_scroll_hold_push(wd->list);
168 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
170 Widget_Data *wd = elm_widget_data_get(obj);
172 if ((!wd) || (!wd->list)) return;
173 elm_widget_scroll_hold_pop(wd->list);
177 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
179 Widget_Data *wd = elm_widget_data_get(obj);
183 if (elm_widget_focus_get(obj))
194 _focus_next_hook(const Evas_Object *obj,
195 Elm_Focus_Direction dir,
198 Widget_Data *wd = elm_widget_data_get(obj);
203 if (!elm_widget_focus_next_get(wd->box, dir, next))
205 elm_widget_focused_object_clear(wd->box);
206 elm_widget_focus_next_get(wd->box, dir, next);
213 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
214 Evas_Callback_Type type, void *event_info)
216 Evas_Event_Key_Down *ev;
219 if (type != EVAS_CALLBACK_KEY_DOWN)
221 wd = elm_widget_data_get(obj);
222 if (!wd) return EINA_FALSE;
226 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
228 if (!strcmp(ev->keyname, "Tab"))
230 if (evas_key_modifier_is_set(ev->modifiers, "Shift"))
231 elm_widget_focus_cycle(wd->box, ELM_FOCUS_PREVIOUS);
233 elm_widget_focus_cycle(wd->box, ELM_FOCUS_NEXT);
237 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
239 evas_object_hide(obj);
240 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
245 _parent_cut_off(Evas_Object *obj)
247 Widget_Data *wd = elm_widget_data_get(obj);
248 if (!wd || !wd->parent) return;
250 evas_object_event_callback_del_full(wd->parent,
254 evas_object_event_callback_del_full(wd->parent,
258 evas_object_event_callback_del_full(wd->parent,
259 EVAS_CALLBACK_RESIZE,
265 _parent_resize(void *data,
267 Evas_Object *obj __UNUSED__,
268 void *event_info __UNUSED__)
270 Widget_Data *wd = elm_widget_data_get(data);
273 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
275 evas_object_hide(data);
279 _parent_move(void *data,
281 Evas_Object *obj __UNUSED__,
282 void *event_info __UNUSED__)
284 Widget_Data *wd = elm_widget_data_get(data);
288 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
297 _parent_del(void *data,
299 Evas_Object *obj __UNUSED__,
300 void *event_info __UNUSED__)
302 evas_object_del(data);
306 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
307 Evas_Coord_Rectangle *hover_area)
309 pos->x -= (base_size->x / 2);
311 if (pos->x < hover_area->x)
312 pos->x = hover_area->x;
313 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
314 pos->x = (hover_area->x + hover_area->w) - base_size->x;
316 if (base_size->x > hover_area->w)
317 base_size->x -= (base_size->x - hover_area->w);
319 if (pos->x < hover_area->x)
320 pos->x = hover_area->x;
324 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
325 Evas_Coord_Rectangle *hover_area)
327 pos->y -= (base_size->y / 2);
329 if (pos->y < hover_area->y)
330 pos->y = hover_area->y;
331 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
332 pos->y = hover_area->y + hover_area->h - base_size->y;
334 if (base_size->y > hover_area->h)
335 base_size->y -= (base_size->y - hover_area->h);
337 if (pos->y < hover_area->y)
338 pos->y = hover_area->y;
341 static Elm_Ctxpopup_Direction
342 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
345 Evas_Coord_Point pos = {0, 0};
346 Evas_Coord_Point base_size;
347 Evas_Coord_Point max_size;
348 Evas_Coord_Point min_size;
349 Evas_Coord_Rectangle hover_area;
350 Evas_Coord_Point arrow_size;
351 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
352 Evas_Coord_Point temp;
355 wd = elm_widget_data_get(obj);
357 if ((!wd) || (!rect))
358 return ELM_CTXPOPUP_DIRECTION_DOWN;
360 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
361 &arrow_size.x, &arrow_size.y);
362 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
364 //Initialize Area Rectangle.
365 evas_object_geometry_get(wd->parent,
371 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
374 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
375 evas_object_smart_calculate(wd->base);
378 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
380 if ((max_size.y > 0) && (base_size.y > max_size.y))
381 base_size.y = max_size.y;
383 if ((max_size.x > 0) && (base_size.x > max_size.x))
384 base_size.x = max_size.x;
388 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
390 if ((min_size.y > 0) && (base_size.y < min_size.y))
391 base_size.y = min_size.y;
393 if ((min_size.x > 0) && (base_size.x < min_size.x))
394 base_size.x = min_size.x;
396 //Check the Which direction is available.
397 //If find a avaialble direction, it adjusts position and size.
398 for (idx = 0; idx < 4; idx++)
400 switch (wd->dir_priority[idx])
402 case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
403 case ELM_CTXPOPUP_DIRECTION_UP:
404 temp.y = (pos.y - base_size.y);
405 if ((temp.y - arrow_size.y) < hover_area.y)
407 _adjust_pos_x(&pos, &base_size, &hover_area);
408 pos.y -= base_size.y;
409 dir = ELM_CTXPOPUP_DIRECTION_UP;
411 case ELM_CTXPOPUP_DIRECTION_LEFT:
412 temp.x = (pos.x - base_size.x);
413 if ((temp.x - arrow_size.x) < hover_area.x)
415 _adjust_pos_y(&pos, &base_size, &hover_area);
416 pos.x -= base_size.x;
417 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
419 case ELM_CTXPOPUP_DIRECTION_RIGHT:
420 temp.x = (pos.x + base_size.x);
421 if ((temp.x + arrow_size.x) >
422 (hover_area.x + hover_area.w))
424 _adjust_pos_y(&pos, &base_size, &hover_area);
425 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
427 case ELM_CTXPOPUP_DIRECTION_DOWN:
428 temp.y = (pos.y + base_size.y);
429 if ((temp.y + arrow_size.y) >
430 (hover_area.y + hover_area.h))
432 _adjust_pos_x(&pos, &base_size, &hover_area);
433 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
441 //In this case, all directions are invalid because of lack of space.
444 Evas_Coord length[2];
448 length[0] = pos.y - hover_area.y;
449 length[1] = (hover_area.y + hover_area.h) - pos.y;
451 // ELM_CTXPOPUP_DIRECTION_UP
452 if (length[0] > length[1])
454 _adjust_pos_x(&pos, &base_size, &hover_area);
455 pos.y -= base_size.y;
456 dir = ELM_CTXPOPUP_DIRECTION_UP;
457 if (pos.y < (hover_area.y + arrow_size.y))
459 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
460 pos.y = hover_area.y + arrow_size.y;
463 //ELM_CTXPOPUP_DIRECTION_DOWN
466 _adjust_pos_x(&pos, &base_size, &hover_area);
467 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
468 if ((pos.y + arrow_size.y + base_size.y) >
469 (hover_area.y + hover_area.h))
471 ((pos.y + arrow_size.y + base_size.y) -
472 (hover_area.y + hover_area.h));
477 length[0] = pos.x - hover_area.x;
478 length[1] = (hover_area.x + hover_area.w) - pos.x;
480 //ELM_CTXPOPUP_DIRECTION_LEFT
481 if (length[0] > length[1])
483 _adjust_pos_y(&pos, &base_size, &hover_area);
484 pos.x -= base_size.x;
485 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
486 if (pos.x < (hover_area.x + arrow_size.x))
488 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
489 pos.x = hover_area.x + arrow_size.x;
492 //ELM_CTXPOPUP_DIRECTION_RIGHT
495 _adjust_pos_y(&pos, &base_size, &hover_area);
496 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
497 if (pos.x + (arrow_size.x + base_size.x) >
498 hover_area.x + hover_area.w)
500 ((pos.x + arrow_size.x + base_size.x) -
501 (hover_area.x + hover_area.w));
506 //Final position and size.
509 rect->w = base_size.x;
510 rect->h = base_size.y;
516 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
517 Evas_Coord_Rectangle base_size)
520 Evas_Coord_Rectangle arrow_size;
524 wd = elm_widget_data_get(obj);
527 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
528 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
531 //edje_object_part_unswallow(wd->base, wd->arrow);
535 case ELM_CTXPOPUP_DIRECTION_RIGHT:
536 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
537 edje_object_part_swallow(wd->base,
538 "elm.swallow.arrow_left",
542 if (y < ((arrow_size.h * 0.5) + base_size.y))
544 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
545 y = base_size.h - arrow_size.h;
547 y = y - base_size.y - (arrow_size.h * 0.5);
548 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
549 edje_object_part_drag_value_set(wd->base,
550 "elm.swallow.arrow_left",
555 case ELM_CTXPOPUP_DIRECTION_LEFT:
556 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
557 edje_object_part_swallow(wd->base,
558 "elm.swallow.arrow_right",
562 if (y < ((arrow_size.h * 0.5) + base_size.y))
564 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
565 y = base_size.h - arrow_size.h;
567 y = y - base_size.y - (arrow_size.h * 0.5);
568 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
569 edje_object_part_drag_value_set(wd->base,
570 "elm.swallow.arrow_right",
575 case ELM_CTXPOPUP_DIRECTION_DOWN:
576 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
577 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
580 if (x < ((arrow_size.w * 0.5) + base_size.x))
582 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
583 x = base_size.w - arrow_size.w;
585 x = x - base_size.x - (arrow_size.w * 0.5);
586 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
587 edje_object_part_drag_value_set(wd->base,
588 "elm.swallow.arrow_up",
593 case ELM_CTXPOPUP_DIRECTION_UP:
594 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
595 edje_object_part_swallow(wd->base,
596 "elm.swallow.arrow_down",
600 if (x < ((arrow_size.w * 0.5) + base_size.x))
602 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
603 x = base_size.w - arrow_size.w;
604 else x = x - base_size.x - (arrow_size.w * 0.5);
605 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
606 edje_object_part_drag_value_set(wd->base,
607 "elm.swallow.arrow_down",
616 //should be here for getting accurate geometry value
617 evas_object_smart_calculate(wd->base);
621 _hide_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
625 wd = elm_widget_data_get(obj);
626 if (!wd->visible) return;
630 case ELM_CTXPOPUP_DIRECTION_UP:
631 edje_object_signal_emit(wd->base, "elm,state,hide,up", "elm");
633 case ELM_CTXPOPUP_DIRECTION_LEFT:
634 edje_object_signal_emit(wd->base, "elm,state,hide,left", "elm");
636 case ELM_CTXPOPUP_DIRECTION_RIGHT:
637 edje_object_signal_emit(wd->base, "elm,state,hide,right", "elm");
639 case ELM_CTXPOPUP_DIRECTION_DOWN:
640 edje_object_signal_emit(wd->base, "elm,state,hide,down", "elm");
646 edje_object_signal_emit(wd->bg, "elm,state,hide", "elm");
650 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
654 wd = elm_widget_data_get(obj);
655 if (!wd->visible) return;
656 if ((wd->list) && (!wd->list_visible)) return;
660 case ELM_CTXPOPUP_DIRECTION_UP:
661 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
663 case ELM_CTXPOPUP_DIRECTION_LEFT:
664 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
666 case ELM_CTXPOPUP_DIRECTION_RIGHT:
667 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
669 case ELM_CTXPOPUP_DIRECTION_DOWN:
670 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
675 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
676 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
680 _sizing_eval(Evas_Object *obj)
683 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
684 Evas_Coord_Point list_size = { 0, 0 };
686 wd = elm_widget_data_get(obj);
690 wd->dir = _calc_base_geometry(obj, &rect);
691 _update_arrow(obj, wd->dir, rect);
692 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
694 if ((wd->list) && (wd->list_visible))
696 evas_object_geometry_get(wd->list, 0, 0, &list_size.x, &list_size.y);
697 if ((list_size.x >= rect.w) || (list_size.y >= rect.h))
699 elm_list_mode_set(wd->list, ELM_LIST_COMPRESS);
700 evas_object_size_hint_min_set(wd->box, rect.w, rect.h);
701 evas_object_size_hint_min_set(obj, rect.w, rect.h);
705 evas_object_move(wd->base, rect.x, rect.y);
706 evas_object_resize(wd->base, rect.w, rect.h);
707 _show_signal_emit(obj, wd->dir);
711 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
712 Evas_Coord_Rectangle *rect)
714 Evas_Coord arrow_w, arrow_h;
716 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
719 case ELM_CTXPOPUP_DIRECTION_RIGHT:
722 case ELM_CTXPOPUP_DIRECTION_LEFT:
725 case ELM_CTXPOPUP_DIRECTION_DOWN:
728 case ELM_CTXPOPUP_DIRECTION_UP:
737 _del_pre_hook(Evas_Object *obj)
741 wd = elm_widget_data_get(obj);
744 evas_object_event_callback_del_full(wd->box, EVAS_CALLBACK_RESIZE,
745 _content_resize, obj);
746 _parent_cut_off(obj);
750 _del_hook(Evas_Object *obj)
754 wd = elm_widget_data_get(obj);
757 elm_ctxpopup_clear(obj);
758 evas_object_del(wd->arrow);
759 evas_object_del(wd->base);
763 //FIXME: lost the content size when theme hook is called.
765 _theme_hook(Evas_Object *obj)
769 wd = elm_widget_data_get(obj);
772 _elm_widget_mirrored_reload(obj);
774 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
775 elm_widget_style_get(obj));
776 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
777 elm_widget_style_get(obj));
778 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
779 elm_widget_style_get(obj));
783 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
784 elm_object_style_set(wd->list, "ctxpopup");
786 elm_object_style_set(wd->list, elm_object_style_get(obj));
789 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
798 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
800 ELM_CHECK_WIDTYPE(obj, widtype);
801 Evas_Coord min_w = -1, min_h = -1;
803 if ((part) && (strcmp(part, "default"))) return;
804 wd = elm_widget_data_get(obj);
805 if ((!wd) || (!content)) return;
806 if (content == wd->content) return;
809 if (wd->content) evas_object_del(wd->content);
812 wd->box = elm_box_add(obj);
813 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
815 evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
817 evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
819 evas_object_show(content);
820 evas_object_size_hint_min_get(content, &min_w, &min_h);
821 evas_object_size_hint_min_set(wd->box, min_w, min_h);
822 elm_box_pack_end(wd->box, content);
824 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
825 _content_resize, obj);
826 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
829 elm_widget_sub_object_add(obj, wd->box);
830 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
832 wd->content = content;
833 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
840 _content_unset_hook(Evas_Object *obj, const char *part)
842 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
845 Evas_Object *content;
846 if ((part) && (strcmp(part, "default"))) return NULL;
847 wd = elm_widget_data_get(obj);
848 if (!wd) return NULL;
850 content = wd->content;
851 if ((!content) || (!wd->box)) return NULL;
853 edje_object_part_unswallow(wd->base, wd->box);
854 elm_widget_sub_object_del(obj, wd->box);
855 evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
856 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
858 evas_object_del(wd->box);
861 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
867 _content_get_hook(const Evas_Object *obj, const char *part)
869 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
871 if ((part) && (strcmp(part, "default"))) return NULL;
872 wd = elm_widget_data_get(obj);
873 if (!wd) return NULL;
878 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
881 Elm_Ctxpopup_Item *ctxpopup_it;
883 if ((part) && (strcmp(part, "default"))) return;
885 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
887 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
890 elm_object_item_part_text_set(ctxpopup_it->list_item, "default", label);
891 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
895 _sizing_eval(WIDGET(ctxpopup_it));
900 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
902 Elm_Ctxpopup_Item *ctxpopup_it;
903 if (part && strcmp(part, "default")) return NULL;
904 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
905 return elm_object_item_part_text_get(ctxpopup_it->list_item, "default");
909 _item_content_set_hook(Elm_Object_Item *it,
911 Evas_Object *content)
914 Elm_Ctxpopup_Item *ctxpopup_it;
916 if ((part) && (strcmp(part, "icon"))
917 && (strcmp(part, "start"))
918 && (strcmp(part, "end"))) return;
920 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
922 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
925 if ((part) && (!strcmp(part, "end")))
926 elm_object_item_part_content_set(ctxpopup_it->list_item, "end", content);
928 elm_object_item_part_content_set(ctxpopup_it->list_item, "start", content);
930 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
934 _sizing_eval(WIDGET(ctxpopup_it));
939 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
941 Elm_Ctxpopup_Item *ctxpopup_it;
943 if (part && strcmp(part, "icon") && strcmp(part, "start")
944 && strcmp(part, "end")) return NULL;
946 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
948 if (part && !strcmp(part, "end"))
949 return elm_object_item_part_content_get(ctxpopup_it->list_item, "end");
951 return elm_object_item_part_content_get(ctxpopup_it->list_item, "start");
955 _item_disable_hook(Elm_Object_Item *it)
958 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
960 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
963 elm_object_item_disabled_set(ctxpopup_it->list_item,
964 elm_widget_item_disabled_get(ctxpopup_it));
968 _item_signal_emit_hook(Elm_Object_Item *it, const char *emission,
971 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
972 elm_object_item_signal_emit(ctxpopup_it->list_item, emission, source);
976 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
977 const char *emission __UNUSED__, const char *source __UNUSED__)
979 Widget_Data *wd = elm_widget_data_get(data);
981 _hide_signal_emit(data, wd->dir);
985 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
986 void *event_info __UNUSED__)
990 wd = elm_widget_data_get(obj);
993 if ((!wd->list) && (!wd->content)) return;
997 elm_list_go(wd->list);
998 wd->visible = EINA_TRUE;
999 elm_object_focus_set(obj, EINA_TRUE);
1003 wd->visible = EINA_TRUE;
1005 evas_object_show(wd->bg);
1006 evas_object_show(wd->base);
1007 evas_object_show(wd->arrow);
1009 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
1010 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
1013 elm_object_focus_set(obj, EINA_TRUE);
1017 _hide_finished(void *data, Evas_Object *obj __UNUSED__,
1018 const char *emission __UNUSED__, const char *source __UNUSED__)
1020 evas_object_hide(data);
1021 evas_object_smart_callback_call(data, SIG_DISMISSED, NULL);
1025 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1026 void *event_info __UNUSED__)
1028 Widget_Data *wd = elm_widget_data_get(obj);
1029 if ((!wd) || (!wd->visible)) return;
1031 evas_object_hide(wd->bg);
1032 evas_object_hide(wd->arrow);
1033 evas_object_hide(wd->base);
1035 wd->visible = EINA_FALSE;
1036 wd->list_visible = EINA_FALSE;
1040 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1041 void *event_info __UNUSED__)
1043 Widget_Data *wd = elm_widget_data_get(data);
1045 elm_box_recalculate(wd->box);
1050 _list_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1051 void *event_info __UNUSED__)
1053 Widget_Data *wd = elm_widget_data_get(data);
1055 if (!wd->visible) return;
1056 if (wd->list_visible) return;
1058 wd->list_visible = EINA_TRUE;
1060 evas_object_show(wd->bg);
1061 evas_object_show(wd->base);
1062 evas_object_show(wd->arrow);
1067 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1068 void *event_info __UNUSED__)
1072 wd = elm_widget_data_get(obj);
1077 evas_object_show(wd->arrow);
1083 _restack(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1085 Widget_Data *wd = elm_widget_data_get(obj);
1087 evas_object_layer_set(wd->bg,
1088 evas_object_layer_get(obj));
1089 evas_object_layer_set(wd->base,
1090 evas_object_layer_get(obj));
1094 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1095 void *event_info __UNUSED__)
1097 elm_object_content_unset(data);
1101 _list_del(Widget_Data *wd)
1103 if (!wd->list) return;
1105 edje_object_part_unswallow(wd->base, wd->box);
1106 elm_box_unpack(wd->box, wd->list);
1107 evas_object_del(wd->list);
1113 _item_del_pre_hook(Elm_Object_Item *it)
1117 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1119 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1120 if (!wd) return EINA_FALSE;
1122 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1124 list = elm_object_item_widget_get(ctxpopup_it->list_item);
1126 if (eina_list_count(elm_list_items_get(list)) < 2)
1128 elm_object_item_del(ctxpopup_it->list_item);
1129 evas_object_hide(WIDGET(ctxpopup_it));
1133 elm_object_item_del(ctxpopup_it->list_item);
1134 if (wd->list_visible)
1135 _sizing_eval(WIDGET(ctxpopup_it));
1141 _disable_hook(Evas_Object *obj)
1143 //TODO: elm_object_disabled_set(); does not ignite this part
1144 Widget_Data *wd = elm_widget_data_get(obj);
1147 elm_object_disabled_set(wd->list, elm_widget_disabled_get(obj));
1151 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
1153 Widget_Data *wd = elm_widget_data_get(obj);
1155 edje_object_signal_emit(wd->base, emission, source);
1159 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
1161 Widget_Data *wd = elm_widget_data_get(obj);
1163 edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
1167 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
1169 Widget_Data *wd = elm_widget_data_get(obj);
1171 edje_object_signal_callback_del_full(wd->base, emission, source, func_cb, data);
1175 elm_ctxpopup_add(Evas_Object *parent)
1181 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1183 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1184 elm_widget_type_set(obj, "ctxpopup");
1185 elm_widget_data_set(obj, wd);
1186 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1187 elm_widget_del_hook_set(obj, _del_hook);
1188 elm_widget_theme_hook_set(obj, _theme_hook);
1189 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1190 elm_widget_can_focus_set(obj, EINA_TRUE);
1191 elm_widget_event_hook_set(obj, _event_hook);
1192 elm_widget_content_set_hook_set(obj, _content_set_hook);
1193 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1194 elm_widget_content_get_hook_set(obj, _content_get_hook);
1195 elm_widget_disable_hook_set(obj, _disable_hook);
1196 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1197 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1198 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1199 elm_widget_focus_next_hook_set(obj, _focus_next_hook);
1202 wd->bg = edje_object_add(e);
1203 elm_widget_sub_object_add(obj, wd->bg);
1204 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1205 edje_object_signal_callback_add(wd->bg,
1211 wd->base = edje_object_add(e);
1212 elm_widget_sub_object_add(obj, wd->base);
1213 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1214 edje_object_signal_callback_add(wd->base, "elm,action,hide,finished", "",
1215 _hide_finished, obj);
1218 wd->arrow = edje_object_add(e);
1219 elm_widget_sub_object_add(obj, wd->arrow);
1220 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1222 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1223 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1224 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1225 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1226 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1228 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1230 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1232 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1234 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESTACK, _restack, obj);
1235 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1236 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1237 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1238 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1240 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1242 //default parent is to be hover parent
1243 elm_ctxpopup_hover_parent_set(obj, parent);
1249 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1251 ELM_CHECK_WIDTYPE(obj, widtype);
1254 Evas_Coord x, y, w, h;
1256 wd = elm_widget_data_get(obj);
1257 if ((!wd) || (!parent)) return;
1259 _parent_cut_off(obj);
1261 evas_object_event_callback_add(parent,
1265 evas_object_event_callback_add(parent,
1269 evas_object_event_callback_add(parent,
1270 EVAS_CALLBACK_RESIZE,
1274 elm_widget_sub_object_add(parent, obj);
1275 wd->parent = parent;
1278 evas_object_geometry_get(parent, &x, &y, &w, &h);
1279 evas_object_move(wd->bg, x, y);
1280 evas_object_resize(wd->bg, w, h);
1282 if (wd->visible) _sizing_eval(obj);
1286 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1288 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1292 wd = elm_widget_data_get(obj);
1293 if (!wd) return NULL;
1299 elm_ctxpopup_clear(Evas_Object * obj)
1301 ELM_CHECK_WIDTYPE(obj, widtype);
1303 Widget_Data *wd = elm_widget_data_get(obj);
1307 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1311 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1313 ELM_CHECK_WIDTYPE(obj, widtype);
1317 wd = elm_widget_data_get(obj);
1320 wd->horizontal = !!horizontal;
1322 if (!wd->list) return;
1324 elm_list_horizontal_set(wd->list, wd->horizontal);
1326 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1328 if (wd->visible) _sizing_eval(obj);
1332 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1334 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1338 wd = elm_widget_data_get(obj);
1339 if (!wd) return EINA_FALSE;
1341 return wd->horizontal;
1344 EAPI Elm_Object_Item *
1345 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1346 Evas_Object *icon, Evas_Smart_Cb func,
1349 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1352 Elm_Ctxpopup_Item *item;
1354 wd = elm_widget_data_get(obj);
1355 if (!wd) return NULL;
1357 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1358 if (!item) return NULL;
1360 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1361 elm_widget_item_disable_hook_set(item, _item_disable_hook);
1362 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1363 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1364 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1365 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1366 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1370 //The first item is appended.
1371 wd->list = elm_list_add(obj);
1372 elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
1373 elm_list_horizontal_set(wd->list, wd->horizontal);
1374 evas_object_event_callback_add(wd->list, EVAS_CALLBACK_RESIZE,
1376 _content_set_hook(obj, "default", wd->list);
1379 item->list_item = elm_list_item_append(wd->list, label, icon, NULL, func, data);
1381 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1383 if (wd->visible) _sizing_eval(obj);
1385 return (Elm_Object_Item *)item;
1389 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1390 Elm_Ctxpopup_Direction first,
1391 Elm_Ctxpopup_Direction second,
1392 Elm_Ctxpopup_Direction third,
1393 Elm_Ctxpopup_Direction fourth)
1395 ELM_CHECK_WIDTYPE(obj, widtype);
1398 wd = elm_widget_data_get(obj);
1401 wd->dir_priority[0] = first;
1402 wd->dir_priority[1] = second;
1403 wd->dir_priority[2] = third;
1404 wd->dir_priority[3] = fourth;
1411 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1412 Elm_Ctxpopup_Direction *first,
1413 Elm_Ctxpopup_Direction *second,
1414 Elm_Ctxpopup_Direction *third,
1415 Elm_Ctxpopup_Direction *fourth)
1417 ELM_CHECK_WIDTYPE(obj, widtype);
1420 wd = elm_widget_data_get(obj);
1423 if (first) *first = wd->dir_priority[0];
1424 if (second) *second = wd->dir_priority[1];
1425 if (third) *third = wd->dir_priority[2];
1426 if (fourth) *fourth = wd->dir_priority[3];
1429 EAPI Elm_Ctxpopup_Direction
1430 elm_ctxpopup_direction_get(const Evas_Object *obj)
1432 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1435 wd = elm_widget_data_get(obj);
1436 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1441 elm_ctxpopup_dismiss(Evas_Object *obj)
1443 ELM_CHECK_WIDTYPE(obj, widtype);
1444 Widget_Data *wd = elm_widget_data_get(obj);
1446 _hide_signal_emit(obj, wd->dir);