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 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
195 Evas_Callback_Type type, void *event_info)
197 Evas_Event_Key_Down *ev;
200 if (type != EVAS_CALLBACK_KEY_DOWN)
202 wd = elm_widget_data_get(obj);
203 if (!wd) return EINA_FALSE;
206 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
207 if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
209 evas_object_hide(obj);
210 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
215 _parent_cut_off(Evas_Object *obj)
217 Widget_Data *wd = elm_widget_data_get(obj);
220 evas_object_event_callback_del_full(wd->parent,
224 evas_object_event_callback_del_full(wd->parent,
228 evas_object_event_callback_del_full(wd->parent,
229 EVAS_CALLBACK_RESIZE,
235 _parent_resize(void *data,
237 Evas_Object *obj __UNUSED__,
238 void *event_info __UNUSED__)
240 Widget_Data *wd = elm_widget_data_get(data);
243 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
245 evas_object_hide(data);
249 _parent_move(void *data,
251 Evas_Object *obj __UNUSED__,
252 void *event_info __UNUSED__)
254 Widget_Data *wd = elm_widget_data_get(data);
258 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
267 _parent_del(void *data,
269 Evas_Object *obj __UNUSED__,
270 void *event_info __UNUSED__)
272 evas_object_del(data);
276 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
277 Evas_Coord_Rectangle *hover_area)
279 pos->x -= (base_size->x / 2);
281 if (pos->x < hover_area->x)
282 pos->x = hover_area->x;
283 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
284 pos->x = (hover_area->x + hover_area->w) - base_size->x;
286 if (base_size->x > hover_area->w)
287 base_size->x -= (base_size->x - hover_area->w);
289 if (pos->x < hover_area->x)
290 pos->x = hover_area->x;
294 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
295 Evas_Coord_Rectangle *hover_area)
297 pos->y -= (base_size->y / 2);
299 if (pos->y < hover_area->y)
300 pos->y = hover_area->y;
301 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
302 pos->y = hover_area->y + hover_area->h - base_size->y;
304 if (base_size->y > hover_area->h)
305 base_size->y -= (base_size->y - hover_area->h);
307 if (pos->y < hover_area->y)
308 pos->y = hover_area->y;
311 static Elm_Ctxpopup_Direction
312 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
315 Evas_Coord_Point pos = {0, 0};
316 Evas_Coord_Point base_size;
317 Evas_Coord_Point max_size;
318 Evas_Coord_Point min_size;
319 Evas_Coord_Rectangle hover_area;
320 Evas_Coord_Point arrow_size;
321 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
322 Evas_Coord_Point temp;
325 wd = elm_widget_data_get(obj);
327 if ((!wd) || (!rect))
328 return ELM_CTXPOPUP_DIRECTION_DOWN;
330 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
331 &arrow_size.x, &arrow_size.y);
332 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
334 //Initialize Area Rectangle.
335 evas_object_geometry_get(wd->parent,
341 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
344 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
345 evas_object_smart_calculate(wd->base);
348 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
350 if ((max_size.y > 0) && (base_size.y > max_size.y))
351 base_size.y = max_size.y;
353 if ((max_size.x > 0) && (base_size.x > max_size.x))
354 base_size.x = max_size.x;
358 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
360 if ((min_size.y > 0) && (base_size.y < min_size.y))
361 base_size.y = min_size.y;
363 if ((min_size.x > 0) && (base_size.x < min_size.x))
364 base_size.x = min_size.x;
366 //Check the Which direction is available.
367 //If find a avaialble direction, it adjusts position and size.
368 for (idx = 0; idx < 4; idx++)
370 switch (wd->dir_priority[idx])
372 case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
373 case ELM_CTXPOPUP_DIRECTION_UP:
374 temp.y = (pos.y - base_size.y);
375 if ((temp.y - arrow_size.y) < hover_area.y)
377 _adjust_pos_x(&pos, &base_size, &hover_area);
378 pos.y -= base_size.y;
379 dir = ELM_CTXPOPUP_DIRECTION_UP;
381 case ELM_CTXPOPUP_DIRECTION_LEFT:
382 temp.x = (pos.x - base_size.x);
383 if ((temp.x - arrow_size.x) < hover_area.x)
385 _adjust_pos_y(&pos, &base_size, &hover_area);
386 pos.x -= base_size.x;
387 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
389 case ELM_CTXPOPUP_DIRECTION_RIGHT:
390 temp.x = (pos.x + base_size.x);
391 if ((temp.x + arrow_size.x) >
392 (hover_area.x + hover_area.w))
394 _adjust_pos_y(&pos, &base_size, &hover_area);
395 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
397 case ELM_CTXPOPUP_DIRECTION_DOWN:
398 temp.y = (pos.y + base_size.y);
399 if ((temp.y + arrow_size.y) >
400 (hover_area.y + hover_area.h))
402 _adjust_pos_x(&pos, &base_size, &hover_area);
403 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
411 //In this case, all directions are invalid because of lack of space.
414 Evas_Coord length[2];
418 length[0] = pos.y - hover_area.y;
419 length[1] = (hover_area.y + hover_area.h) - pos.y;
421 // ELM_CTXPOPUP_DIRECTION_UP
422 if (length[0] > length[1])
424 _adjust_pos_x(&pos, &base_size, &hover_area);
425 pos.y -= base_size.y;
426 dir = ELM_CTXPOPUP_DIRECTION_UP;
427 if (pos.y < (hover_area.y + arrow_size.y))
429 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
430 pos.y = hover_area.y + arrow_size.y;
433 //ELM_CTXPOPUP_DIRECTION_DOWN
436 _adjust_pos_x(&pos, &base_size, &hover_area);
437 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
438 if ((pos.y + arrow_size.y + base_size.y) >
439 (hover_area.y + hover_area.h))
441 ((pos.y + arrow_size.y + base_size.y) -
442 (hover_area.y + hover_area.h));
447 length[0] = pos.x - hover_area.x;
448 length[1] = (hover_area.x + hover_area.w) - pos.x;
450 //ELM_CTXPOPUP_DIRECTION_LEFT
451 if (length[0] > length[1])
453 _adjust_pos_y(&pos, &base_size, &hover_area);
454 pos.x -= base_size.x;
455 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
456 if (pos.x < (hover_area.x + arrow_size.x))
458 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
459 pos.x = hover_area.x + arrow_size.x;
462 //ELM_CTXPOPUP_DIRECTION_RIGHT
465 _adjust_pos_y(&pos, &base_size, &hover_area);
466 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
467 if (pos.x + (arrow_size.x + base_size.x) >
468 hover_area.x + hover_area.w)
470 ((pos.x + arrow_size.x + base_size.x) -
471 (hover_area.x + hover_area.w));
476 //Final position and size.
479 rect->w = base_size.x;
480 rect->h = base_size.y;
486 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
487 Evas_Coord_Rectangle base_size)
490 Evas_Coord_Rectangle arrow_size;
494 wd = elm_widget_data_get(obj);
497 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
498 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
501 //edje_object_part_unswallow(wd->base, wd->arrow);
505 case ELM_CTXPOPUP_DIRECTION_RIGHT:
506 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
507 edje_object_part_swallow(wd->base,
508 "elm.swallow.arrow_left",
512 if (y < ((arrow_size.h * 0.5) + base_size.y))
514 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
515 y = base_size.h - arrow_size.h;
517 y = y - base_size.y - (arrow_size.h * 0.5);
518 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
519 edje_object_part_drag_value_set(wd->base,
520 "elm.swallow.arrow_left",
525 case ELM_CTXPOPUP_DIRECTION_LEFT:
526 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
527 edje_object_part_swallow(wd->base,
528 "elm.swallow.arrow_right",
532 if (y < ((arrow_size.h * 0.5) + base_size.y))
534 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
535 y = base_size.h - arrow_size.h;
537 y = y - base_size.y - (arrow_size.h * 0.5);
538 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
539 edje_object_part_drag_value_set(wd->base,
540 "elm.swallow.arrow_right",
545 case ELM_CTXPOPUP_DIRECTION_DOWN:
546 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
547 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
550 if (x < ((arrow_size.w * 0.5) + base_size.x))
552 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
553 x = base_size.w - arrow_size.w;
555 x = x - base_size.x - (arrow_size.w * 0.5);
556 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
557 edje_object_part_drag_value_set(wd->base,
558 "elm.swallow.arrow_up",
563 case ELM_CTXPOPUP_DIRECTION_UP:
564 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
565 edje_object_part_swallow(wd->base,
566 "elm.swallow.arrow_down",
570 if (x < ((arrow_size.w * 0.5) + base_size.x))
572 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
573 x = base_size.w - arrow_size.w;
574 else x = x - base_size.x - (arrow_size.w * 0.5);
575 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
576 edje_object_part_drag_value_set(wd->base,
577 "elm.swallow.arrow_down",
586 //should be here for getting accurate geometry value
587 evas_object_smart_calculate(wd->base);
591 _hide_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
595 wd = elm_widget_data_get(obj);
596 if (!wd->visible) return;
600 case ELM_CTXPOPUP_DIRECTION_UP:
601 edje_object_signal_emit(wd->base, "elm,state,hide,up", "elm");
603 case ELM_CTXPOPUP_DIRECTION_LEFT:
604 edje_object_signal_emit(wd->base, "elm,state,hide,left", "elm");
606 case ELM_CTXPOPUP_DIRECTION_RIGHT:
607 edje_object_signal_emit(wd->base, "elm,state,hide,right", "elm");
609 case ELM_CTXPOPUP_DIRECTION_DOWN:
610 edje_object_signal_emit(wd->base, "elm,state,hide,down", "elm");
616 edje_object_signal_emit(wd->bg, "elm,state,hide", "elm");
620 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
624 wd = elm_widget_data_get(obj);
625 if (!wd->visible) return;
626 if ((wd->list) && (!wd->list_visible)) return;
630 case ELM_CTXPOPUP_DIRECTION_UP:
631 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
633 case ELM_CTXPOPUP_DIRECTION_LEFT:
634 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
636 case ELM_CTXPOPUP_DIRECTION_RIGHT:
637 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
639 case ELM_CTXPOPUP_DIRECTION_DOWN:
640 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
645 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
646 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
650 _sizing_eval(Evas_Object *obj)
653 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
654 Evas_Coord_Point list_size = { 0, 0 };
656 wd = elm_widget_data_get(obj);
660 wd->dir = _calc_base_geometry(obj, &rect);
661 _update_arrow(obj, wd->dir, rect);
662 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
664 if ((wd->list) && (wd->list_visible))
666 evas_object_geometry_get(wd->list, 0, 0, &list_size.x, &list_size.y);
667 if ((list_size.x >= rect.w) || (list_size.y >= rect.h))
669 elm_list_mode_set(wd->list, ELM_LIST_COMPRESS);
670 evas_object_size_hint_min_set(wd->box, rect.w, rect.h);
671 evas_object_size_hint_min_set(obj, rect.w, rect.h);
675 evas_object_move(wd->base, rect.x, rect.y);
676 evas_object_resize(wd->base, rect.w, rect.h);
677 _show_signal_emit(obj, wd->dir);
681 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
682 Evas_Coord_Rectangle *rect)
684 Evas_Coord arrow_w, arrow_h;
686 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
689 case ELM_CTXPOPUP_DIRECTION_RIGHT:
692 case ELM_CTXPOPUP_DIRECTION_LEFT:
695 case ELM_CTXPOPUP_DIRECTION_DOWN:
698 case ELM_CTXPOPUP_DIRECTION_UP:
707 _del_pre_hook(Evas_Object *obj)
711 wd = elm_widget_data_get(obj);
714 evas_object_event_callback_del_full(wd->box, EVAS_CALLBACK_RESIZE,
715 _content_resize, obj);
716 _parent_cut_off(obj);
720 _del_hook(Evas_Object *obj)
724 wd = elm_widget_data_get(obj);
727 elm_ctxpopup_clear(obj);
728 evas_object_del(wd->arrow);
729 evas_object_del(wd->base);
733 //FIXME: lost the content size when theme hook is called.
735 _theme_hook(Evas_Object *obj)
739 wd = elm_widget_data_get(obj);
742 _elm_widget_mirrored_reload(obj);
744 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
745 elm_widget_style_get(obj));
746 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
747 elm_widget_style_get(obj));
748 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
749 elm_widget_style_get(obj));
753 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
754 elm_object_style_set(wd->list, "ctxpopup");
756 elm_object_style_set(wd->list, elm_object_style_get(obj));
759 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
768 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
770 ELM_CHECK_WIDTYPE(obj, widtype);
771 Evas_Coord min_w = -1, min_h = -1;
773 if ((part) && (strcmp(part, "default"))) return;
774 wd = elm_widget_data_get(obj);
775 if ((!wd) || (!content)) return;
776 if (content == wd->content) return;
779 if (wd->content) evas_object_del(wd->content);
782 wd->box = elm_box_add(obj);
783 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
785 evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
787 evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
789 evas_object_show(content);
790 evas_object_size_hint_min_get(content, &min_w, &min_h);
791 evas_object_size_hint_min_set(wd->box, min_w, min_h);
792 elm_box_pack_end(wd->box, content);
794 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
795 _content_resize, obj);
796 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
799 elm_widget_sub_object_add(obj, wd->box);
800 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
802 wd->content = content;
803 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
810 _content_unset_hook(Evas_Object *obj, const char *part)
812 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
815 Evas_Object *content;
816 if ((part) && (strcmp(part, "default"))) return NULL;
817 wd = elm_widget_data_get(obj);
818 if (!wd) return NULL;
820 content = wd->content;
821 if ((!content) || (!wd->box)) return NULL;
823 edje_object_part_unswallow(wd->base, wd->box);
824 elm_widget_sub_object_del(obj, wd->box);
825 evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
826 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
828 evas_object_del(wd->box);
831 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
837 _content_get_hook(const Evas_Object *obj, const char *part)
839 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
841 if ((part) && (strcmp(part, "default"))) return NULL;
842 wd = elm_widget_data_get(obj);
843 if (!wd) return NULL;
848 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
851 Elm_Ctxpopup_Item *ctxpopup_it;
853 if ((part) && (strcmp(part, "default"))) return;
855 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
857 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
860 elm_object_item_part_text_set(ctxpopup_it->list_item, "default", label);
861 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
865 _sizing_eval(WIDGET(ctxpopup_it));
870 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
872 Elm_Ctxpopup_Item *ctxpopup_it;
873 if (part && strcmp(part, "default")) return NULL;
874 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
875 return elm_object_item_part_text_get(ctxpopup_it->list_item, "default");
879 _item_content_set_hook(Elm_Object_Item *it,
881 Evas_Object *content)
884 Elm_Ctxpopup_Item *ctxpopup_it;
886 if ((part) && (strcmp(part, "icon"))
887 && (strcmp(part, "start"))
888 && (strcmp(part, "end"))) return;
890 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
892 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
895 if ((part) && (!strcmp(part, "end")))
896 elm_object_item_part_content_set(ctxpopup_it->list_item, "end", content);
898 elm_object_item_part_content_set(ctxpopup_it->list_item, "start", content);
900 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
904 _sizing_eval(WIDGET(ctxpopup_it));
909 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
911 Elm_Ctxpopup_Item *ctxpopup_it;
913 if (part && strcmp(part, "icon") && strcmp(part, "start")
914 && strcmp(part, "end")) return NULL;
916 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
918 if (part && !strcmp(part, "end"))
919 return elm_object_item_part_content_get(ctxpopup_it->list_item, "end");
921 return elm_object_item_part_content_get(ctxpopup_it->list_item, "start");
925 _item_disable_hook(Elm_Object_Item *it)
928 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
930 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
933 elm_object_item_disabled_set(ctxpopup_it->list_item,
934 elm_widget_item_disabled_get(ctxpopup_it));
938 _item_signal_emit_hook(Elm_Object_Item *it, const char *emission,
941 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
942 elm_object_item_signal_emit(ctxpopup_it->list_item, emission, source);
946 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
947 const char *emission __UNUSED__, const char *source __UNUSED__)
949 Widget_Data *wd = elm_widget_data_get(data);
951 _hide_signal_emit(data, wd->dir);
955 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
956 void *event_info __UNUSED__)
960 wd = elm_widget_data_get(obj);
963 if ((!wd->list) && (!wd->content)) return;
967 elm_list_go(wd->list);
968 wd->visible = EINA_TRUE;
972 wd->visible = EINA_TRUE;
974 evas_object_show(wd->bg);
975 evas_object_show(wd->base);
976 evas_object_show(wd->arrow);
978 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
979 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
983 elm_object_focus_set(obj, EINA_TRUE);
987 _hide_finished(void *data, Evas_Object *obj __UNUSED__,
988 const char *emission __UNUSED__, const char *source __UNUSED__)
990 evas_object_hide(data);
991 evas_object_smart_callback_call(data, SIG_DISMISSED, NULL);
995 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
996 void *event_info __UNUSED__)
998 Widget_Data *wd = elm_widget_data_get(obj);
999 if ((!wd) || (!wd->visible)) return;
1001 evas_object_hide(wd->bg);
1002 evas_object_hide(wd->arrow);
1003 evas_object_hide(wd->base);
1005 wd->visible = EINA_FALSE;
1006 wd->list_visible = EINA_FALSE;
1010 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1011 void *event_info __UNUSED__)
1013 Widget_Data *wd = elm_widget_data_get(data);
1015 elm_box_recalculate(wd->box);
1020 _list_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1021 void *event_info __UNUSED__)
1023 Widget_Data *wd = elm_widget_data_get(data);
1025 if (!wd->visible) return;
1026 if (wd->list_visible) return;
1028 wd->list_visible = EINA_TRUE;
1030 evas_object_show(wd->bg);
1031 evas_object_show(wd->base);
1032 evas_object_show(wd->arrow);
1037 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1038 void *event_info __UNUSED__)
1042 wd = elm_widget_data_get(obj);
1047 evas_object_show(wd->arrow);
1053 _restack(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1055 Widget_Data *wd = elm_widget_data_get(obj);
1057 evas_object_layer_set(wd->bg,
1058 evas_object_layer_get(obj));
1059 evas_object_layer_set(wd->base,
1060 evas_object_layer_get(obj));
1064 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1065 void *event_info __UNUSED__)
1067 elm_object_content_unset(data);
1071 _list_del(Widget_Data *wd)
1073 if (!wd->list) return;
1075 edje_object_part_unswallow(wd->base, wd->box);
1076 elm_box_unpack(wd->box, wd->list);
1077 evas_object_del(wd->list);
1083 _item_del_pre_hook(Elm_Object_Item *it)
1087 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1089 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1090 if (!wd) return EINA_FALSE;
1092 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1094 list = elm_object_item_widget_get(ctxpopup_it->list_item);
1096 if (eina_list_count(elm_list_items_get(list)) < 2)
1098 elm_object_item_del(ctxpopup_it->list_item);
1099 evas_object_hide(WIDGET(ctxpopup_it));
1103 elm_object_item_del(ctxpopup_it->list_item);
1104 if (wd->list_visible)
1105 _sizing_eval(WIDGET(ctxpopup_it));
1111 _disable_hook(Evas_Object *obj)
1113 //TODO: elm_object_disabled_set(); does not ignite this part
1114 Widget_Data *wd = elm_widget_data_get(obj);
1117 elm_object_disabled_set(wd->list, elm_widget_disabled_get(obj));
1121 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
1123 Widget_Data *wd = elm_widget_data_get(obj);
1125 edje_object_signal_emit(wd->base, emission, source);
1129 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
1131 Widget_Data *wd = elm_widget_data_get(obj);
1133 edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
1137 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
1139 Widget_Data *wd = elm_widget_data_get(obj);
1141 edje_object_signal_callback_del_full(wd->base, emission, source, func_cb, data);
1145 elm_ctxpopup_add(Evas_Object *parent)
1151 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1153 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1154 elm_widget_type_set(obj, "ctxpopup");
1155 elm_widget_data_set(obj, wd);
1156 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1157 elm_widget_del_hook_set(obj, _del_hook);
1158 elm_widget_theme_hook_set(obj, _theme_hook);
1159 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1160 elm_widget_can_focus_set(obj, EINA_TRUE);
1161 elm_widget_event_hook_set(obj, _event_hook);
1162 elm_widget_content_set_hook_set(obj, _content_set_hook);
1163 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1164 elm_widget_content_get_hook_set(obj, _content_get_hook);
1165 elm_widget_disable_hook_set(obj, _disable_hook);
1166 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1167 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1168 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1171 wd->bg = edje_object_add(e);
1172 elm_widget_sub_object_add(obj, wd->bg);
1173 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1174 edje_object_signal_callback_add(wd->bg,
1180 wd->base = edje_object_add(e);
1181 elm_widget_sub_object_add(obj, wd->base);
1182 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1183 edje_object_signal_callback_add(wd->base, "elm,action,hide,finished", "",
1184 _hide_finished, obj);
1187 wd->arrow = edje_object_add(e);
1188 elm_widget_sub_object_add(obj, wd->arrow);
1189 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1191 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1192 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1193 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1194 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1195 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1197 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1199 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1201 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1203 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESTACK, _restack, obj);
1204 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1205 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1206 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1207 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1209 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1211 //default parent is to be hover parent
1212 elm_ctxpopup_hover_parent_set(obj, parent);
1218 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1220 ELM_CHECK_WIDTYPE(obj, widtype);
1223 Evas_Coord x, y, w, h;
1225 wd = elm_widget_data_get(obj);
1226 if ((!wd) || (!parent)) return;
1228 _parent_cut_off(obj);
1230 evas_object_event_callback_add(parent,
1234 evas_object_event_callback_add(parent,
1238 evas_object_event_callback_add(parent,
1239 EVAS_CALLBACK_RESIZE,
1243 elm_widget_sub_object_add(parent, obj);
1244 wd->parent = parent;
1247 evas_object_geometry_get(parent, &x, &y, &w, &h);
1248 evas_object_move(wd->bg, x, y);
1249 evas_object_resize(wd->bg, w, h);
1251 if (wd->visible) _sizing_eval(obj);
1255 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1257 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1261 wd = elm_widget_data_get(obj);
1262 if (!wd) return NULL;
1268 elm_ctxpopup_clear(Evas_Object * obj)
1270 ELM_CHECK_WIDTYPE(obj, widtype);
1272 Widget_Data *wd = elm_widget_data_get(obj);
1276 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1280 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1282 ELM_CHECK_WIDTYPE(obj, widtype);
1286 wd = elm_widget_data_get(obj);
1289 wd->horizontal = !!horizontal;
1296 elm_list_horizontal_set(wd->list, wd->horizontal);
1300 elm_list_horizontal_set(wd->list, wd->horizontal);
1303 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1310 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1312 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1316 wd = elm_widget_data_get(obj);
1317 if (!wd) return EINA_FALSE;
1319 return wd->horizontal;
1322 EAPI Elm_Object_Item *
1323 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1324 Evas_Object *icon, Evas_Smart_Cb func,
1327 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1330 Elm_Ctxpopup_Item *item;
1332 wd = elm_widget_data_get(obj);
1333 if (!wd) return NULL;
1335 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1336 if (!item) return NULL;
1338 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1339 elm_widget_item_disable_hook_set(item, _item_disable_hook);
1340 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1341 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1342 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1343 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1344 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1348 //The first item is appended.
1349 wd->list = elm_list_add(obj);
1350 elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
1351 elm_list_horizontal_set(wd->list, wd->horizontal);
1352 evas_object_event_callback_add(wd->list, EVAS_CALLBACK_RESIZE,
1354 _content_set_hook(obj, "default", wd->list);
1357 item->list_item = elm_list_item_append(wd->list, label, icon, NULL, func, data);
1359 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1361 if (wd->visible) _sizing_eval(obj);
1363 return (Elm_Object_Item *)item;
1367 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1368 Elm_Ctxpopup_Direction first,
1369 Elm_Ctxpopup_Direction second,
1370 Elm_Ctxpopup_Direction third,
1371 Elm_Ctxpopup_Direction fourth)
1373 ELM_CHECK_WIDTYPE(obj, widtype);
1376 wd = elm_widget_data_get(obj);
1379 wd->dir_priority[0] = first;
1380 wd->dir_priority[1] = second;
1381 wd->dir_priority[2] = third;
1382 wd->dir_priority[3] = fourth;
1389 elm_ctxpopup_direction_priority_get(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 if (first) *first = wd->dir_priority[0];
1402 if (second) *second = wd->dir_priority[1];
1403 if (third) *third = wd->dir_priority[2];
1404 if (fourth) *fourth = wd->dir_priority[3];
1407 EAPI Elm_Ctxpopup_Direction
1408 elm_ctxpopup_direction_get(const Evas_Object *obj)
1410 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1413 wd = elm_widget_data_get(obj);
1414 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1419 elm_ctxpopup_dismiss(Evas_Object *obj)
1421 ELM_CHECK_WIDTYPE(obj, widtype);
1422 Widget_Data *wd = elm_widget_data_get(obj);
1424 _hide_signal_emit(obj, wd->dir);