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);
221 evas_object_event_callback_del_full(wd->parent,
225 evas_object_event_callback_del_full(wd->parent,
229 evas_object_event_callback_del_full(wd->parent,
230 EVAS_CALLBACK_RESIZE,
234 elm_widget_sub_object_del(wd->parent, obj);
238 _parent_resize(void *data,
240 Evas_Object *obj __UNUSED__,
241 void *event_info __UNUSED__)
243 Widget_Data *wd = elm_widget_data_get(data);
246 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
248 evas_object_hide(data);
252 _parent_move(void *data,
254 Evas_Object *obj __UNUSED__,
255 void *event_info __UNUSED__)
257 Widget_Data *wd = elm_widget_data_get(data);
261 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
270 _parent_del(void *data,
272 Evas_Object *obj __UNUSED__,
273 void *event_info __UNUSED__)
275 evas_object_del(data);
279 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
280 Evas_Coord_Rectangle *hover_area)
282 pos->x -= (base_size->x / 2);
284 if (pos->x < hover_area->x)
285 pos->x = hover_area->x;
286 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
287 pos->x = (hover_area->x + hover_area->w) - base_size->x;
289 if (base_size->x > hover_area->w)
290 base_size->x -= (base_size->x - hover_area->w);
292 if (pos->x < hover_area->x)
293 pos->x = hover_area->x;
297 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
298 Evas_Coord_Rectangle *hover_area)
300 pos->y -= (base_size->y / 2);
302 if (pos->y < hover_area->y)
303 pos->y = hover_area->y;
304 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
305 pos->y = hover_area->y + hover_area->h - base_size->y;
307 if (base_size->y > hover_area->h)
308 base_size->y -= (base_size->y - hover_area->h);
310 if (pos->y < hover_area->y)
311 pos->y = hover_area->y;
314 static Elm_Ctxpopup_Direction
315 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
318 Evas_Coord_Point pos = {0, 0};
319 Evas_Coord_Point base_size;
320 Evas_Coord_Point max_size;
321 Evas_Coord_Point min_size;
322 Evas_Coord_Rectangle hover_area;
323 Evas_Coord_Point arrow_size;
324 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
325 Evas_Coord_Point temp;
328 wd = elm_widget_data_get(obj);
330 if ((!wd) || (!rect))
331 return ELM_CTXPOPUP_DIRECTION_DOWN;
333 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
334 &arrow_size.x, &arrow_size.y);
335 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
337 //Initialize Area Rectangle.
338 evas_object_geometry_get(wd->parent,
344 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
347 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
348 evas_object_smart_calculate(wd->base);
351 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
353 if ((max_size.y > 0) && (base_size.y > max_size.y))
354 base_size.y = max_size.y;
356 if ((max_size.x > 0) && (base_size.x > max_size.x))
357 base_size.x = max_size.x;
361 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
363 if ((min_size.y > 0) && (base_size.y < min_size.y))
364 base_size.y = min_size.y;
366 if ((min_size.x > 0) && (base_size.x < min_size.x))
367 base_size.x = min_size.x;
369 //Check the Which direction is available.
370 //If find a avaialble direction, it adjusts position and size.
371 for (idx = 0; idx < 4; idx++)
373 switch (wd->dir_priority[idx])
375 case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
376 case ELM_CTXPOPUP_DIRECTION_UP:
377 temp.y = (pos.y - base_size.y);
378 if ((temp.y - arrow_size.y) < hover_area.y)
380 _adjust_pos_x(&pos, &base_size, &hover_area);
381 pos.y -= base_size.y;
382 dir = ELM_CTXPOPUP_DIRECTION_UP;
384 case ELM_CTXPOPUP_DIRECTION_LEFT:
385 temp.x = (pos.x - base_size.x);
386 if ((temp.x - arrow_size.x) < hover_area.x)
388 _adjust_pos_y(&pos, &base_size, &hover_area);
389 pos.x -= base_size.x;
390 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
392 case ELM_CTXPOPUP_DIRECTION_RIGHT:
393 temp.x = (pos.x + base_size.x);
394 if ((temp.x + arrow_size.x) >
395 (hover_area.x + hover_area.w))
397 _adjust_pos_y(&pos, &base_size, &hover_area);
398 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
400 case ELM_CTXPOPUP_DIRECTION_DOWN:
401 temp.y = (pos.y + base_size.y);
402 if ((temp.y + arrow_size.y) >
403 (hover_area.y + hover_area.h))
405 _adjust_pos_x(&pos, &base_size, &hover_area);
406 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
414 //In this case, all directions are invalid because of lack of space.
417 Evas_Coord length[2];
421 length[0] = pos.y - hover_area.y;
422 length[1] = (hover_area.y + hover_area.h) - pos.y;
424 // ELM_CTXPOPUP_DIRECTION_UP
425 if (length[0] > length[1])
427 _adjust_pos_x(&pos, &base_size, &hover_area);
428 pos.y -= base_size.y;
429 dir = ELM_CTXPOPUP_DIRECTION_UP;
430 if (pos.y < (hover_area.y + arrow_size.y))
432 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
433 pos.y = hover_area.y + arrow_size.y;
436 //ELM_CTXPOPUP_DIRECTION_DOWN
439 _adjust_pos_x(&pos, &base_size, &hover_area);
440 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
441 if ((pos.y + arrow_size.y + base_size.y) >
442 (hover_area.y + hover_area.h))
444 ((pos.y + arrow_size.y + base_size.y) -
445 (hover_area.y + hover_area.h));
450 length[0] = pos.x - hover_area.x;
451 length[1] = (hover_area.x + hover_area.w) - pos.x;
453 //ELM_CTXPOPUP_DIRECTION_LEFT
454 if (length[0] > length[1])
456 _adjust_pos_y(&pos, &base_size, &hover_area);
457 pos.x -= base_size.x;
458 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
459 if (pos.x < (hover_area.x + arrow_size.x))
461 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
462 pos.x = hover_area.x + arrow_size.x;
465 //ELM_CTXPOPUP_DIRECTION_RIGHT
468 _adjust_pos_y(&pos, &base_size, &hover_area);
469 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
470 if (pos.x + (arrow_size.x + base_size.x) >
471 hover_area.x + hover_area.w)
473 ((pos.x + arrow_size.x + base_size.x) -
474 (hover_area.x + hover_area.w));
479 //Final position and size.
482 rect->w = base_size.x;
483 rect->h = base_size.y;
489 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
490 Evas_Coord_Rectangle base_size)
493 Evas_Coord_Rectangle arrow_size;
497 wd = elm_widget_data_get(obj);
500 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
501 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
504 //edje_object_part_unswallow(wd->base, wd->arrow);
508 case ELM_CTXPOPUP_DIRECTION_RIGHT:
509 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
510 edje_object_part_swallow(wd->base,
511 "elm.swallow.arrow_left",
515 if (y < ((arrow_size.h * 0.5) + base_size.y))
517 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
518 y = base_size.h - arrow_size.h;
520 y = y - base_size.y - (arrow_size.h * 0.5);
521 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
522 edje_object_part_drag_value_set(wd->base,
523 "elm.swallow.arrow_left",
528 case ELM_CTXPOPUP_DIRECTION_LEFT:
529 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
530 edje_object_part_swallow(wd->base,
531 "elm.swallow.arrow_right",
535 if (y < ((arrow_size.h * 0.5) + base_size.y))
537 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
538 y = base_size.h - arrow_size.h;
540 y = y - base_size.y - (arrow_size.h * 0.5);
541 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
542 edje_object_part_drag_value_set(wd->base,
543 "elm.swallow.arrow_right",
548 case ELM_CTXPOPUP_DIRECTION_DOWN:
549 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
550 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
553 if (x < ((arrow_size.w * 0.5) + base_size.x))
555 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
556 x = base_size.w - arrow_size.w;
558 x = x - base_size.x - (arrow_size.w * 0.5);
559 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
560 edje_object_part_drag_value_set(wd->base,
561 "elm.swallow.arrow_up",
566 case ELM_CTXPOPUP_DIRECTION_UP:
567 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
568 edje_object_part_swallow(wd->base,
569 "elm.swallow.arrow_down",
573 if (x < ((arrow_size.w * 0.5) + base_size.x))
575 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
576 x = base_size.w - arrow_size.w;
577 else x = x - base_size.x - (arrow_size.w * 0.5);
578 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
579 edje_object_part_drag_value_set(wd->base,
580 "elm.swallow.arrow_down",
589 //should be here for getting accurate geometry value
590 evas_object_smart_calculate(wd->base);
594 _hide_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
598 wd = elm_widget_data_get(obj);
599 if (!wd->visible) return;
603 case ELM_CTXPOPUP_DIRECTION_UP:
604 edje_object_signal_emit(wd->base, "elm,state,hide,up", "elm");
606 case ELM_CTXPOPUP_DIRECTION_LEFT:
607 edje_object_signal_emit(wd->base, "elm,state,hide,left", "elm");
609 case ELM_CTXPOPUP_DIRECTION_RIGHT:
610 edje_object_signal_emit(wd->base, "elm,state,hide,right", "elm");
612 case ELM_CTXPOPUP_DIRECTION_DOWN:
613 edje_object_signal_emit(wd->base, "elm,state,hide,down", "elm");
619 edje_object_signal_emit(wd->bg, "elm,state,hide", "elm");
623 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
627 wd = elm_widget_data_get(obj);
628 if (!wd->visible) return;
629 if ((wd->list) && (!wd->list_visible)) return;
633 case ELM_CTXPOPUP_DIRECTION_UP:
634 edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
636 case ELM_CTXPOPUP_DIRECTION_LEFT:
637 edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
639 case ELM_CTXPOPUP_DIRECTION_RIGHT:
640 edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
642 case ELM_CTXPOPUP_DIRECTION_DOWN:
643 edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
648 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
649 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
653 _sizing_eval(Evas_Object *obj)
656 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
657 Evas_Coord_Point list_size = { 0, 0 };
659 wd = elm_widget_data_get(obj);
663 wd->dir = _calc_base_geometry(obj, &rect);
664 _update_arrow(obj, wd->dir, rect);
665 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
667 if ((wd->list) && (wd->list_visible))
669 evas_object_geometry_get(wd->list, 0, 0, &list_size.x, &list_size.y);
670 if ((list_size.x >= rect.w) || (list_size.y >= rect.h))
672 elm_list_mode_set(wd->list, ELM_LIST_COMPRESS);
673 evas_object_size_hint_min_set(wd->box, rect.w, rect.h);
674 evas_object_size_hint_min_set(obj, rect.w, rect.h);
678 evas_object_move(wd->base, rect.x, rect.y);
679 evas_object_resize(wd->base, rect.w, rect.h);
680 _show_signal_emit(obj, wd->dir);
684 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
685 Evas_Coord_Rectangle *rect)
687 Evas_Coord arrow_w, arrow_h;
689 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
692 case ELM_CTXPOPUP_DIRECTION_RIGHT:
695 case ELM_CTXPOPUP_DIRECTION_LEFT:
698 case ELM_CTXPOPUP_DIRECTION_DOWN:
701 case ELM_CTXPOPUP_DIRECTION_UP:
710 _del_pre_hook(Evas_Object *obj)
714 wd = elm_widget_data_get(obj);
717 evas_object_event_callback_del_full(wd->box, EVAS_CALLBACK_RESIZE,
718 _content_resize, obj);
719 _parent_cut_off(obj);
723 _del_hook(Evas_Object *obj)
727 wd = elm_widget_data_get(obj);
730 elm_ctxpopup_clear(obj);
731 evas_object_del(wd->arrow);
732 evas_object_del(wd->base);
736 //FIXME: lost the content size when theme hook is called.
738 _theme_hook(Evas_Object *obj)
743 wd = elm_widget_data_get(obj);
746 _elm_widget_mirrored_reload(obj);
747 rtl = elm_widget_mirrored_get(obj);
749 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
750 elm_widget_style_get(obj));
751 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
752 elm_widget_style_get(obj));
753 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
754 elm_widget_style_get(obj));
758 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
759 elm_object_style_set(wd->list, "ctxpopup");
761 elm_object_style_set(wd->list, elm_object_style_get(obj));
764 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
773 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
775 ELM_CHECK_WIDTYPE(obj, widtype);
776 Evas_Coord min_w = -1, min_h = -1;
778 if ((part) && (strcmp(part, "default"))) return;
779 wd = elm_widget_data_get(obj);
780 if ((!wd) || (!content)) return;
781 if (content == wd->content) return;
784 if (wd->content) evas_object_del(wd->content);
787 wd->box = elm_box_add(obj);
788 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
790 evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
792 evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
794 evas_object_show(content);
795 evas_object_size_hint_min_get(content, &min_w, &min_h);
796 evas_object_size_hint_min_set(wd->box, min_w, min_h);
797 elm_box_pack_end(wd->box, content);
799 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
800 _content_resize, obj);
801 evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
804 elm_widget_sub_object_add(obj, wd->box);
805 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
807 wd->content = content;
808 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
815 _content_unset_hook(Evas_Object *obj, const char *part)
817 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
820 Evas_Object *content;
821 if ((part) && (strcmp(part, "default"))) return NULL;
822 wd = elm_widget_data_get(obj);
823 if (!wd) return NULL;
825 content = wd->content;
826 if ((!content) || (!wd->box)) return NULL;
828 edje_object_part_unswallow(wd->base, wd->box);
829 elm_widget_sub_object_del(obj, wd->box);
830 evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
831 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
833 evas_object_del(wd->box);
836 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
842 _content_get_hook(const Evas_Object *obj, const char *part)
844 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
846 if ((part) && (strcmp(part, "default"))) return NULL;
847 wd = elm_widget_data_get(obj);
848 if (!wd) return NULL;
853 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
856 Elm_Ctxpopup_Item *ctxpopup_it;
858 if ((part) && (strcmp(part, "default"))) return;
860 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
862 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
865 elm_object_item_part_text_set(ctxpopup_it->list_item, "default", label);
866 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
870 _sizing_eval(WIDGET(ctxpopup_it));
875 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
877 Elm_Ctxpopup_Item *ctxpopup_it;
878 if (part && strcmp(part, "default")) return NULL;
879 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
880 return elm_object_item_part_text_get(ctxpopup_it->list_item, "default");
884 _item_content_set_hook(Elm_Object_Item *it,
886 Evas_Object *content)
889 Elm_Ctxpopup_Item *ctxpopup_it;
891 if ((part) && (strcmp(part, "icon"))
892 && (strcmp(part, "start"))
893 && (strcmp(part, "end"))) return;
895 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
897 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
900 if ((part) && (!strcmp(part, "end")))
901 elm_object_item_part_content_set(ctxpopup_it->list_item, "end", content);
903 elm_object_item_part_content_set(ctxpopup_it->list_item, "start", content);
905 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
909 _sizing_eval(WIDGET(ctxpopup_it));
914 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
916 Elm_Ctxpopup_Item *ctxpopup_it;
918 if (part && strcmp(part, "icon") && strcmp(part, "start")
919 && strcmp(part, "end")) return NULL;
921 ctxpopup_it = (Elm_Ctxpopup_Item *)it;
923 if (part && !strcmp(part, "end"))
924 return elm_object_item_part_content_get(ctxpopup_it->list_item, "end");
926 return elm_object_item_part_content_get(ctxpopup_it->list_item, "start");
930 _item_disable_hook(Elm_Object_Item *it)
933 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
935 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
938 elm_object_item_disabled_set(ctxpopup_it->list_item,
939 elm_widget_item_disabled_get(ctxpopup_it));
943 _item_signal_emit_hook(Elm_Object_Item *it, const char *emission,
946 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
947 elm_object_item_signal_emit(ctxpopup_it->list_item, emission, source);
951 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
952 const char *emission __UNUSED__, const char *source __UNUSED__)
954 Widget_Data *wd = elm_widget_data_get(data);
956 _hide_signal_emit(data, wd->dir);
960 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
961 void *event_info __UNUSED__)
965 wd = elm_widget_data_get(obj);
968 if ((!wd->list) && (!wd->content)) return;
972 elm_list_go(wd->list);
973 wd->visible = EINA_TRUE;
977 wd->visible = EINA_TRUE;
979 evas_object_show(wd->bg);
980 evas_object_show(wd->base);
981 evas_object_show(wd->arrow);
983 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
984 edje_object_signal_emit(wd->base, "elm,state,show", "elm");
988 elm_object_focus_set(obj, EINA_TRUE);
992 _hide_finished(void *data, Evas_Object *obj __UNUSED__,
993 const char *emission __UNUSED__, const char *source __UNUSED__)
995 evas_object_hide(data);
996 evas_object_smart_callback_call(data, SIG_DISMISSED, NULL);
1000 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1001 void *event_info __UNUSED__)
1003 Widget_Data *wd = elm_widget_data_get(obj);
1004 if ((!wd) || (!wd->visible)) return;
1006 evas_object_hide(wd->bg);
1007 evas_object_hide(wd->arrow);
1008 evas_object_hide(wd->base);
1010 wd->visible = EINA_FALSE;
1011 wd->list_visible = EINA_FALSE;
1015 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1016 void *event_info __UNUSED__)
1018 Widget_Data *wd = elm_widget_data_get(data);
1020 elm_box_recalculate(wd->box);
1025 _list_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1026 void *event_info __UNUSED__)
1028 Widget_Data *wd = elm_widget_data_get(data);
1030 if (!wd->visible) return;
1031 if (wd->list_visible) return;
1033 wd->list_visible = EINA_TRUE;
1035 evas_object_show(wd->bg);
1036 evas_object_show(wd->base);
1037 evas_object_show(wd->arrow);
1042 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1043 void *event_info __UNUSED__)
1047 wd = elm_widget_data_get(obj);
1052 evas_object_show(wd->arrow);
1058 _restack(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1060 Widget_Data *wd = elm_widget_data_get(obj);
1062 evas_object_layer_set(wd->bg,
1063 evas_object_layer_get(obj));
1064 evas_object_layer_set(wd->base,
1065 evas_object_layer_get(obj));
1069 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1070 void *event_info __UNUSED__)
1072 elm_object_content_unset(data);
1076 _list_del(Widget_Data *wd)
1078 if (!wd->list) return;
1080 edje_object_part_unswallow(wd->base, wd->box);
1081 elm_box_unpack(wd->box, wd->list);
1082 evas_object_del(wd->list);
1088 _item_del_pre_hook(Elm_Object_Item *it)
1092 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1094 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1095 if (!wd) return EINA_FALSE;
1097 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1099 list = elm_object_item_widget_get(ctxpopup_it->list_item);
1101 if (eina_list_count(elm_list_items_get(list)) < 2)
1103 elm_object_item_del(ctxpopup_it->list_item);
1104 evas_object_hide(WIDGET(ctxpopup_it));
1108 elm_object_item_del(ctxpopup_it->list_item);
1109 if (wd->list_visible)
1110 _sizing_eval(WIDGET(ctxpopup_it));
1116 _disable_hook(Evas_Object *obj)
1118 //TODO: elm_object_disabled_set(); does not ignite this part
1119 Widget_Data *wd = elm_widget_data_get(obj);
1122 elm_object_disabled_set(wd->list, elm_widget_disabled_get(obj));
1126 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
1128 Widget_Data *wd = elm_widget_data_get(obj);
1130 edje_object_signal_emit(wd->base, emission, source);
1134 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
1136 Widget_Data *wd = elm_widget_data_get(obj);
1138 edje_object_signal_callback_add(wd->base, emission, source, func_cb, data);
1142 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
1144 Widget_Data *wd = elm_widget_data_get(obj);
1146 edje_object_signal_callback_del_full(wd->base, emission, source, func_cb, data);
1150 elm_ctxpopup_add(Evas_Object *parent)
1156 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1158 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1159 elm_widget_type_set(obj, "ctxpopup");
1160 elm_widget_data_set(obj, wd);
1161 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1162 elm_widget_del_hook_set(obj, _del_hook);
1163 elm_widget_theme_hook_set(obj, _theme_hook);
1164 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1165 elm_widget_can_focus_set(obj, EINA_TRUE);
1166 elm_widget_event_hook_set(obj, _event_hook);
1167 elm_widget_content_set_hook_set(obj, _content_set_hook);
1168 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1169 elm_widget_content_get_hook_set(obj, _content_get_hook);
1170 elm_widget_disable_hook_set(obj, _disable_hook);
1171 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1172 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1173 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1176 wd->bg = edje_object_add(e);
1177 elm_widget_sub_object_add(obj, wd->bg);
1178 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1179 edje_object_signal_callback_add(wd->bg,
1185 wd->base = edje_object_add(e);
1186 elm_widget_sub_object_add(obj, wd->base);
1187 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1188 edje_object_signal_callback_add(wd->base, "elm,action,hide,finished", "",
1189 _hide_finished, obj);
1192 wd->arrow = edje_object_add(e);
1193 elm_widget_sub_object_add(obj, wd->arrow);
1194 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1196 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1197 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1198 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1199 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1200 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1202 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1204 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1206 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1208 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESTACK, _restack, obj);
1209 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1210 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1211 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1212 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1214 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1216 //default parent is to be hover parent
1217 elm_ctxpopup_hover_parent_set(obj, parent);
1223 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1225 ELM_CHECK_WIDTYPE(obj, widtype);
1228 Evas_Coord x, y, w, h;
1230 wd = elm_widget_data_get(obj);
1231 if ((!wd) || (!parent)) return;
1233 _parent_cut_off(obj);
1237 evas_object_event_callback_add(parent,
1241 evas_object_event_callback_add(parent,
1245 evas_object_event_callback_add(parent,
1246 EVAS_CALLBACK_RESIZE,
1251 elm_widget_sub_object_add(parent, obj);
1252 wd->parent = parent;
1255 evas_object_geometry_get(parent, &x, &y, &w, &h);
1256 evas_object_move(wd->bg, x, y);
1257 evas_object_resize(wd->bg, w, h);
1259 if (wd->visible) _sizing_eval(obj);
1263 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1265 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1269 wd = elm_widget_data_get(obj);
1270 if (!wd) return NULL;
1276 elm_ctxpopup_clear(Evas_Object * obj)
1278 ELM_CHECK_WIDTYPE(obj, widtype);
1280 Widget_Data *wd = elm_widget_data_get(obj);
1284 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1288 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1290 ELM_CHECK_WIDTYPE(obj, widtype);
1294 wd = elm_widget_data_get(obj);
1297 wd->horizontal = !!horizontal;
1304 elm_list_horizontal_set(wd->list, wd->horizontal);
1308 elm_list_horizontal_set(wd->list, wd->horizontal);
1311 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1318 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1320 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1324 wd = elm_widget_data_get(obj);
1325 if (!wd) return EINA_FALSE;
1327 return wd->horizontal;
1330 EAPI Elm_Object_Item *
1331 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1332 Evas_Object *icon, Evas_Smart_Cb func,
1335 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1338 Elm_Ctxpopup_Item *item;
1340 wd = elm_widget_data_get(obj);
1341 if (!wd) return NULL;
1343 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1344 if (!item) return NULL;
1346 elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1347 elm_widget_item_disable_hook_set(item, _item_disable_hook);
1348 elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1349 elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1350 elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1351 elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1352 elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1356 //The first item is appended.
1357 wd->list = elm_list_add(obj);
1358 elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
1359 elm_list_horizontal_set(wd->list, wd->horizontal);
1360 evas_object_event_callback_add(wd->list, EVAS_CALLBACK_RESIZE,
1362 _content_set_hook(obj, "default", wd->list);
1365 item->list_item = elm_list_item_append(wd->list, label, icon, NULL, func, data);
1367 wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1369 if (wd->visible) _sizing_eval(obj);
1371 return (Elm_Object_Item *)item;
1375 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1376 Elm_Ctxpopup_Direction first,
1377 Elm_Ctxpopup_Direction second,
1378 Elm_Ctxpopup_Direction third,
1379 Elm_Ctxpopup_Direction fourth)
1381 ELM_CHECK_WIDTYPE(obj, widtype);
1384 wd = elm_widget_data_get(obj);
1387 wd->dir_priority[0] = first;
1388 wd->dir_priority[1] = second;
1389 wd->dir_priority[2] = third;
1390 wd->dir_priority[3] = fourth;
1397 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1398 Elm_Ctxpopup_Direction *first,
1399 Elm_Ctxpopup_Direction *second,
1400 Elm_Ctxpopup_Direction *third,
1401 Elm_Ctxpopup_Direction *fourth)
1403 ELM_CHECK_WIDTYPE(obj, widtype);
1406 wd = elm_widget_data_get(obj);
1409 if (first) *first = wd->dir_priority[0];
1410 if (second) *second = wd->dir_priority[1];
1411 if (third) *third = wd->dir_priority[2];
1412 if (fourth) *fourth = wd->dir_priority[3];
1415 EAPI Elm_Ctxpopup_Direction
1416 elm_ctxpopup_direction_get(const Evas_Object *obj)
1418 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1421 wd = elm_widget_data_get(obj);
1422 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1427 elm_ctxpopup_dismiss(Evas_Object *obj)
1429 ELM_CHECK_WIDTYPE(obj, widtype);
1430 Widget_Data *wd = elm_widget_data_get(obj);
1432 _hide_signal_emit(obj, wd->dir);