1 #include <Elementary.h>
4 #undef Elm_Ctxpopup_Item
6 typedef struct _Widget_Data Widget_Data;
7 typedef struct _Elm_Ctxpopup_Item Elm_Ctxpopup_Item;
9 struct _Elm_Ctxpopup_Item
27 Evas_Object *hover_parent;
29 Elm_Ctxpopup_Direction dir;
30 Elm_Ctxpopup_Direction dir_priority[4];
31 Evas_Coord max_sc_w, max_sc_h;
32 Eina_Bool horizontal:1;
37 static const char *widtype = NULL;
39 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
40 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
41 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
42 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
43 static void _scroller_size_reset(Widget_Data *wd);
44 static void _hover_parent_callbacks_del(Evas_Object *obj);
45 static void _parent_resize(void *data,
49 static void _hover_parent_resize(void *data, Evas *e __UNUSED__,
50 Evas_Object *obj __UNUSED__,
51 void *event_info __UNUSED__);
52 static void _hover_parent_move(void *data, Evas *e __UNUSED__,
53 Evas_Object *obj __UNUSED__,
54 void *event_info __UNUSED__);
55 static void _hover_parent_del(void *data, Evas *e __UNUSED__,
56 Evas_Object *obj __UNUSED__,
57 void *event_info __UNUSED__);
58 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
59 static void _adjust_pos_x(Evas_Coord_Point *pos,
60 Evas_Coord_Point *base_size,
61 Evas_Coord_Rectangle *hover_area);
62 static void _adjust_pos_y(Evas_Coord_Point *pos,
63 Evas_Coord_Point *base_size,
64 Evas_Coord_Rectangle *hover_area);
65 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
66 Evas *e __UNUSED__, Evas_Object *obj,
67 void *event_info __UNUSED__);
68 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
69 Evas_Coord_Rectangle *rect);
70 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
71 static void _sizing_eval(Evas_Object *obj);
72 static void _shift_base_by_arrow(Evas_Object *arrow,
73 Elm_Ctxpopup_Direction dir,
74 Evas_Coord_Rectangle *rect);
75 static void _del_pre_hook(Evas_Object *obj);
76 static void _del_hook(Evas_Object *obj);
77 static void _theme_hook(Evas_Object *obj);
78 static void _content_set_hook(Evas_Object *obj,
79 const char *item __UNUSED__,
80 Evas_Object *content);
81 static Evas_Object * _content_unset_hook(Evas_Object *obj,
82 const char *item __UNUSED__);
83 static Evas_Object * _content_get_hook(const Evas_Object *obj,
84 const char *item __UNUSED__);
85 static void _bg_clicked_cb(void *data, Evas_Object *obj,
88 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
89 void *event_info __UNUSED__);
90 static void _ctxpopup_show(void *data,
94 static void _hide(Evas_Object *obj);
95 static void _ctxpopup_hide(void *data,
99 static void _scroller_resize(void *data,
103 static void _ctxpopup_move(void *data,
107 static void _item_select_cb(void *data, Evas_Object *obj,
108 const char *emission,
110 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
111 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
112 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
113 static void _content_del(void *data,
117 static void _list_del(Widget_Data *wd);
118 static void _list_new(Evas_Object *obj);
119 static void _remove_items(Widget_Data * wd);
121 static const char SIG_DISMISSED[] = "dismissed";
123 static const Evas_Smart_Cb_Description _signals[] = {
128 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...) \
129 ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
130 ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
133 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
134 void *event_info __UNUSED__)
136 Widget_Data *wd = elm_widget_data_get(obj);
138 if ((!wd) || (!wd->scr)) return;
140 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
144 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
145 void *event_info __UNUSED__)
147 Widget_Data *wd = elm_widget_data_get(obj);
149 if ((!wd) || (!wd->scr)) return;
152 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
154 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
158 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
160 Widget_Data *wd = elm_widget_data_get(obj);
162 if ((!wd) || (!wd->scr)) return;
164 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_FALSE);
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->scr)) return;
175 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
177 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
181 _scroller_size_reset(Widget_Data *wd)
183 wd->finished = EINA_FALSE;
189 _hover_parent_callbacks_del(Evas_Object *obj)
191 Widget_Data *wd = elm_widget_data_get(obj);
193 if ((!wd) || (!wd->hover_parent))
196 evas_object_event_callback_del_full(wd->hover_parent,
200 evas_object_event_callback_del_full(wd->hover_parent,
204 evas_object_event_callback_del_full(wd->hover_parent,
205 EVAS_CALLBACK_RESIZE,
206 _hover_parent_resize,
211 _hover_parent_resize(void *data,
213 Evas_Object *obj __UNUSED__,
214 void *event_info __UNUSED__)
216 Widget_Data *wd = elm_widget_data_get(data);
222 _scroller_size_reset(wd);
228 _hover_parent_move(void *data,
230 Evas_Object *obj __UNUSED__,
231 void *event_info __UNUSED__)
233 Widget_Data *wd = elm_widget_data_get(data);
239 _scroller_size_reset(wd);
245 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
246 void *event_info __UNUSED__)
248 Widget_Data *wd = elm_widget_data_get(data);
252 wd->hover_parent = NULL;
256 _item_sizing_eval(Elm_Ctxpopup_Item *item)
258 Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
262 edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
264 evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
265 evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
269 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
270 Evas_Coord_Rectangle *hover_area)
272 pos->x -= (base_size->x / 2);
274 if (pos->x < hover_area->x)
275 pos->x = hover_area->x;
276 else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
277 pos->x = (hover_area->x + hover_area->w) - base_size->x;
279 if (base_size->x > hover_area->w)
280 base_size->x -= (base_size->x - hover_area->w);
282 if (pos->x < hover_area->x)
283 pos->x = hover_area->x;
287 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
288 Evas_Coord_Rectangle *hover_area)
290 pos->y -= (base_size->y / 2);
292 if (pos->y < hover_area->y)
293 pos->y = hover_area->y;
294 else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
295 pos->y = hover_area->y + hover_area->h - base_size->y;
297 if (base_size->y > hover_area->h)
298 base_size->y -= (base_size->y - hover_area->h);
300 if (pos->y < hover_area->y)
301 pos->y = hover_area->y;
305 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
306 Evas_Object *obj, void *event_info __UNUSED__)
310 wd = elm_widget_data_get(obj);
317 static Elm_Ctxpopup_Direction
318 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
321 Evas_Coord_Point pos = {0, 0};
322 Evas_Coord_Point base_size;
323 Evas_Coord_Point max_size;
324 Evas_Coord_Point min_size;
325 Evas_Coord_Rectangle hover_area;
326 Evas_Coord_Rectangle parent_size;
327 Evas_Coord_Point arrow_size;
328 Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_DOWN;
329 Evas_Coord_Point temp;
332 wd = elm_widget_data_get(obj);
334 if ((!wd) || (!rect))
335 return ELM_CTXPOPUP_DIRECTION_DOWN;
337 edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
338 &arrow_size.x, &arrow_size.y);
339 evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
341 //Initialize Area Rectangle.
342 if (wd->hover_parent)
343 evas_object_geometry_get(wd->hover_parent, &hover_area.x, &hover_area.y,
344 &hover_area.w, &hover_area.h);
347 evas_object_geometry_get(wd->parent, &parent_size.x, &parent_size.y,
348 &parent_size.w, &parent_size.h);
349 hover_area.x = parent_size.x;
350 hover_area.y = parent_size.y;
351 hover_area.w = parent_size.w;
352 hover_area.h = parent_size.h;
355 evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
358 edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
359 evas_object_smart_calculate(wd->base);
362 evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
364 if ((max_size.y > 0) && (base_size.y > max_size.y))
365 base_size.y = max_size.y;
367 if ((max_size.x > 0) && (base_size.x > max_size.x))
368 base_size.x = max_size.x;
371 evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
373 if ((min_size.y > 0) && (base_size.y < min_size.y))
374 base_size.y = min_size.y;
376 if ((min_size.x > 0) && (base_size.x < min_size.x))
377 base_size.x = min_size.x;
379 //Check the Which direction is available.
380 //If find a avaialble direction, it adjusts position and size.
381 for (idx = 0; idx < 4; idx++)
383 switch (wd->dir_priority[idx])
385 case ELM_CTXPOPUP_DIRECTION_UP:
386 temp.y = (pos.y - base_size.y);
387 if ((temp.y - arrow_size.y) < hover_area.y)
389 _adjust_pos_x(&pos, &base_size, &hover_area);
390 pos.y -= base_size.y;
391 dir = ELM_CTXPOPUP_DIRECTION_UP;
393 case ELM_CTXPOPUP_DIRECTION_LEFT:
394 temp.x = (pos.x - base_size.x);
395 if ((temp.x - arrow_size.x) < hover_area.x)
397 _adjust_pos_y(&pos, &base_size, &hover_area);
398 pos.x -= base_size.x;
399 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
401 case ELM_CTXPOPUP_DIRECTION_RIGHT:
402 temp.x = (pos.x + base_size.x);
403 if ((temp.x + arrow_size.x) >
404 (hover_area.x + hover_area.w))
406 _adjust_pos_y(&pos, &base_size, &hover_area);
407 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
409 case ELM_CTXPOPUP_DIRECTION_DOWN:
410 temp.y = (pos.y + base_size.y);
411 if ((temp.y + arrow_size.y) >
412 (hover_area.y + hover_area.h))
414 _adjust_pos_x(&pos, &base_size, &hover_area);
415 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
423 //In this case, all directions are invalid because of lack of space.
426 Evas_Coord length[2];
430 length[0] = pos.y - hover_area.y;
431 length[1] = (hover_area.y + hover_area.h) - pos.y;
433 // ELM_CTXPOPUP_DIRECTION_UP
434 if (length[0] > length[1])
436 _adjust_pos_x(&pos, &base_size, &hover_area);
437 pos.y -= base_size.y;
438 dir = ELM_CTXPOPUP_DIRECTION_UP;
439 if (pos.y < (hover_area.y + arrow_size.y))
441 base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
442 pos.y = hover_area.y + arrow_size.y;
445 //ELM_CTXPOPUP_DIRECTION_DOWN
448 _adjust_pos_x(&pos, &base_size, &hover_area);
449 dir = ELM_CTXPOPUP_DIRECTION_DOWN;
450 if ((pos.y + arrow_size.y + base_size.y) >
451 (hover_area.y + hover_area.h))
453 ((pos.y + arrow_size.y + base_size.y) -
454 (hover_area.y + hover_area.h));
459 length[0] = pos.x - hover_area.x;
460 length[1] = (hover_area.x + hover_area.w) - pos.x;
462 //ELM_CTXPOPUP_DIRECTION_LEFT
463 if (length[0] > length[1])
465 _adjust_pos_y(&pos, &base_size, &hover_area);
466 pos.x -= base_size.x;
467 dir = ELM_CTXPOPUP_DIRECTION_LEFT;
468 if (pos.x < (hover_area.x + arrow_size.x))
470 base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
471 pos.x = hover_area.x + arrow_size.x;
474 //ELM_CTXPOPUP_DIRECTION_RIGHT
477 _adjust_pos_y(&pos, &base_size, &hover_area);
478 dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
479 if (pos.x + (arrow_size.x + base_size.x) >
480 hover_area.x + hover_area.w)
482 ((pos.x + arrow_size.x + base_size.x) -
483 (hover_area.x + hover_area.w));
488 //Final position and size.
491 rect->w = base_size.x;
492 rect->h = base_size.y;
498 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
501 Evas_Coord_Rectangle arrow_size;
502 Evas_Coord_Rectangle base_size;
506 wd = elm_widget_data_get(obj);
509 evas_object_geometry_get(obj, &x, &y, NULL, NULL);
510 evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
512 evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
513 &base_size.w, &base_size.h);
515 edje_object_part_unswallow(wd->base, wd->arrow);
519 case ELM_CTXPOPUP_DIRECTION_RIGHT:
520 edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
521 edje_object_part_swallow(wd->base,
522 "elm.swallow.arrow_left",
525 // if user does not use dragable part
526 arrow_size.y = (y - (arrow_size.h * 0.5));
531 if (y < ((arrow_size.h * 0.5) + base_size.y))
533 else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
534 y = base_size.h - arrow_size.h;
536 y = y - base_size.y - (arrow_size.h * 0.5);
537 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
538 edje_object_part_drag_value_set(wd->base,
539 "elm.swallow.arrow_left",
544 case ELM_CTXPOPUP_DIRECTION_LEFT:
545 edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
546 edje_object_part_swallow(wd->base,
547 "elm.swallow.arrow_right",
550 // if user does not use dragable part
551 arrow_size.y = (y - (arrow_size.h * 0.5));
552 arrow_size.x = (x - arrow_size.w);
556 if (y < ((arrow_size.h * 0.5) + base_size.y))
558 else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
559 y = base_size.h - arrow_size.h;
561 y = y - base_size.y - (arrow_size.h * 0.5);
562 drag = (double) (y) / (double) (base_size.h - arrow_size.h);
563 edje_object_part_drag_value_set(wd->base,
564 "elm.swallow.arrow_right",
569 case ELM_CTXPOPUP_DIRECTION_DOWN:
570 edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
571 edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
573 // if user does not use dragable part
574 arrow_size.x = (x - (arrow_size.w * 0.5));
579 if (x < ((arrow_size.w * 0.5) + base_size.x))
581 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
582 x = base_size.w - arrow_size.w;
584 x = x - base_size.x - (arrow_size.w * 0.5);
585 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
586 edje_object_part_drag_value_set(wd->base,
587 "elm.swallow.arrow_up",
592 case ELM_CTXPOPUP_DIRECTION_UP:
593 edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
594 edje_object_part_swallow(wd->base,
595 "elm.swallow.arrow_down",
598 // if user does not use dragable part
599 arrow_size.x = (x - (arrow_size.w * 0.5));
600 arrow_size.y = (y - arrow_size.h);
604 if (x < ((arrow_size.w * 0.5) + base_size.x))
606 else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
607 x = base_size.w - arrow_size.w;
608 else x = x - base_size.x - (arrow_size.w * 0.5);
609 drag = (double) (x) / (double) (base_size.w - arrow_size.w);
610 edje_object_part_drag_value_set(wd->base,
611 "elm.swallow.arrow_down",
620 // if user does not use dragable part
621 evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
624 //TODO: compress item - different from opensource
626 _compress_item(Evas_Object *obj)
630 Elm_Ctxpopup_Item *item;
632 wd = elm_widget_data_get(obj);
635 EINA_LIST_FOREACH(wd->items, elist, item)
637 edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
642 _sizing_eval(Evas_Object *obj)
646 Elm_Ctxpopup_Item *item;
647 Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
648 Evas_Coord_Point box_size = { 0, 0 };
649 Evas_Coord_Point _box_size = { 0, 0 };
651 wd = elm_widget_data_get(obj);
653 if (!wd->parent) return;
656 EINA_LIST_FOREACH(wd->items, elist, item)
658 _item_sizing_eval(item);
659 evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
662 if (_box_size.x > box_size.x)
663 box_size.x = _box_size.x;
664 if (_box_size.y != -1)
665 box_size.y += _box_size.y;
669 if (_box_size.x != -1)
670 box_size.x += _box_size.x;
671 if (_box_size.y > box_size.y)
672 box_size.y = _box_size.y;
678 evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
679 evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
683 wd->dir = _calc_base_geometry(obj, &rect);
685 //TODO: compress item - different from opensource
686 if (!wd->horizontal && !wd->content)
689 _update_arrow(obj, wd->dir);
690 _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
692 //resize scroller according to final size.
694 evas_object_smart_calculate(wd->scr);
696 evas_object_move(wd->base, rect.x, rect.y);
697 evas_object_resize(wd->base, rect.w, rect.h);
701 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
702 Evas_Coord_Rectangle *rect)
704 Evas_Coord arrow_w, arrow_h;
706 evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
710 case ELM_CTXPOPUP_DIRECTION_RIGHT:
713 case ELM_CTXPOPUP_DIRECTION_LEFT:
716 case ELM_CTXPOPUP_DIRECTION_DOWN:
719 case ELM_CTXPOPUP_DIRECTION_UP:
728 _del_pre_hook(Evas_Object *obj)
732 wd = elm_widget_data_get(obj);
735 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
736 _parent_resize, obj);
738 _hover_parent_callbacks_del(obj);
742 _del_hook(Evas_Object *obj)
746 wd = elm_widget_data_get(obj);
749 elm_ctxpopup_clear(obj);
750 evas_object_del(wd->arrow);
751 evas_object_del(wd->base);
755 //FIXME: lost the content size when theme hook is called.
757 _theme_hook(Evas_Object *obj)
761 Elm_Ctxpopup_Item *item;
764 wd = elm_widget_data_get(obj);
768 EINA_LIST_FOREACH(wd->items, elist, item)
770 if (item->label && item->icon)
771 _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
772 "icon_text_style_item",
773 elm_widget_style_get(obj));
774 else if (item->label)
775 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
776 elm_widget_style_get(obj));
778 _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
779 elm_widget_style_get(obj));
781 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
784 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
787 * For separator, if the first item has visible separator,
788 * then it should be aligned with edge of the base part.
789 * In some cases, it gives improper display. Ex) rounded corner
790 * So the first item separator should be invisible.
793 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
797 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
799 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
802 edje_object_message_signal_process(VIEW(item));
805 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
806 elm_widget_style_get(obj));
807 if (evas_object_visible_get(wd->bg))
808 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
810 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
811 elm_widget_style_get(obj));
812 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
813 elm_widget_style_get(obj));
817 if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
818 elm_object_style_set(wd->scr, "ctxpopup");
820 elm_object_style_set(wd->scr, elm_object_style_get(obj));
825 _scroller_size_reset(wd);
831 _content_set_hook(Evas_Object *obj, const char *part,
832 Evas_Object *content)
834 ELM_CHECK_WIDTYPE(obj, widtype);
838 if (part && strcmp(part, "default")) return;
840 wd = elm_widget_data_get(obj);
841 if ((!wd) || (!content)) return;
843 if (wd->items) elm_ctxpopup_clear(obj);
844 if (wd->content) evas_object_del(wd->content);
846 evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
849 elm_widget_sub_object_add(obj, content);
850 edje_object_part_swallow(wd->base, "elm.swallow.content", content);
851 edje_object_message_signal_process(wd->base);
853 wd->content = content;
860 _content_unset_hook(Evas_Object *obj, const char *part)
862 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
865 Evas_Object *content;
866 if (part && strcmp(part, "default")) return NULL;
867 wd = elm_widget_data_get(obj);
868 if (!wd) return NULL;
870 content = wd->content;
871 if (!content) return NULL;
873 edje_object_part_unswallow(wd->base, content);
874 elm_widget_sub_object_del(obj, content);
875 evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
876 edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
885 _content_get_hook(const Evas_Object *obj, const char *part)
887 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
889 if (part && strcmp(part, "default")) return NULL;
890 wd = elm_widget_data_get(obj);
891 if (!wd) return NULL;
896 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
897 const char *emission __UNUSED__, const char *source __UNUSED__)
899 evas_object_hide(data);
903 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
904 void *event_info __UNUSED__)
909 wd = elm_widget_data_get(data);
912 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
913 evas_object_resize(wd->bg, w, h);
915 if (!wd->visible) return;
921 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
922 void *event_info __UNUSED__)
926 Elm_Ctxpopup_Item *item;
929 wd = elm_widget_data_get(obj);
932 if ((!wd->items) && (!wd->content)) return;
934 wd->visible = EINA_TRUE;
936 evas_object_show(wd->bg);
937 evas_object_show(wd->base);
938 evas_object_show(wd->arrow);
940 edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
942 EINA_LIST_FOREACH(wd->items, elist, item)
945 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
949 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
951 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
959 _hide(Evas_Object *obj)
961 Widget_Data *wd = elm_widget_data_get(obj);
965 evas_object_hide(wd->bg);
966 evas_object_hide(wd->arrow);
967 evas_object_hide(wd->base);
969 _scroller_size_reset(wd);
971 evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
972 wd->visible = EINA_FALSE;
976 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
977 void *event_info __UNUSED__)
981 wd = elm_widget_data_get(obj);
982 if ((!wd) || (!wd->visible))
989 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
990 void *event_info __UNUSED__)
995 wd = elm_widget_data_get(data);
997 if (!wd->visible) return;
998 if (wd->finished) return;
1000 evas_object_geometry_get(obj, 0, 0, &w, &h);
1002 if (w != 0 && h != 0)
1004 if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1007 wd->finished = EINA_TRUE;
1012 if (wd->max_sc_w < w)
1014 if (wd->max_sc_h < h)
1021 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1022 void *event_info __UNUSED__)
1026 wd = elm_widget_data_get(obj);
1031 evas_object_show(wd->arrow);
1033 _scroller_size_reset(wd);
1038 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1039 const char *emission __UNUSED__, const char *source __UNUSED__)
1041 Elm_Ctxpopup_Item *item = data;
1044 if (item->disabled) return;
1047 item->func((void*) item->base.data, WIDGET(item), data);
1051 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1055 elm_widget_sub_object_del(VIEW(item), item->icon);
1056 evas_object_del(item->icon);
1062 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1063 edje_object_message_signal_process(VIEW(item));
1067 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1069 if (!eina_stringshare_replace(&item->label, label))
1072 edje_object_part_text_set(VIEW(item), "elm.text", label);
1073 edje_object_message_signal_process(VIEW(item));
1077 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1081 wd = elm_widget_data_get(WIDGET(item));
1084 VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1085 _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1086 elm_widget_style_get(WIDGET(item)));
1087 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1088 _item_select_cb, item);
1089 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1090 evas_object_show(VIEW(item));
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->scr) return;
1105 edje_object_part_unswallow(wd->base, wd->scr);
1106 evas_object_del(wd->scr);
1112 _list_new(Evas_Object *obj)
1115 wd = elm_widget_data_get(obj);
1119 wd->scr = elm_scroller_add(obj);
1120 elm_object_style_set(wd->scr, "ctxpopup");
1121 evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1122 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1123 _scroller_resize, obj);
1124 edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1127 wd->box = elm_box_add(obj);
1128 evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1131 elm_object_content_set(wd->scr, wd->box);
1132 elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1136 _remove_items(Widget_Data *wd)
1139 Elm_Ctxpopup_Item *item;
1141 if (!wd->items) return;
1143 EINA_LIST_FOREACH(wd->items, elist, item)
1146 eina_stringshare_del(item->label);
1148 evas_object_del(item->icon);
1149 wd->items = eina_list_remove(wd->items, item);
1157 elm_ctxpopup_add(Evas_Object *parent)
1162 Evas_Coord x, y, w, h;
1164 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1166 ELM_SET_WIDTYPE(widtype, "ctxpopup");
1167 elm_widget_type_set(obj, "ctxpopup");
1168 elm_widget_sub_object_add(parent, obj);
1169 elm_widget_data_set(obj, wd);
1170 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1171 elm_widget_del_hook_set(obj, _del_hook);
1172 elm_widget_theme_hook_set(obj, _theme_hook);
1173 elm_widget_content_set_hook_set(obj, _content_set_hook);
1174 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1175 elm_widget_content_get_hook_set(obj, _content_get_hook);
1177 wd->parent = parent;
1180 wd->bg = edje_object_add(e);
1181 elm_widget_sub_object_add(obj, wd->bg);
1182 _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1183 evas_object_geometry_get(parent, &x, &y, &w, &h);
1184 evas_object_move(wd->bg, x, y);
1185 evas_object_resize(wd->bg, w, h);
1186 edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1187 _bg_clicked_cb, obj);
1190 wd->base = edje_object_add(e);
1191 elm_widget_sub_object_add(obj, wd->base);
1192 _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1195 wd->arrow = edje_object_add(e);
1196 elm_widget_sub_object_add(obj, wd->arrow);
1197 _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1199 wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1200 wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1201 wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1202 wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1204 evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1206 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1208 evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1210 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1212 evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1213 _ctxpopup_changed_size_hints, NULL);
1214 evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1215 evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1216 evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1217 evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1219 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1225 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1227 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1228 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1229 return ctxpopup_it->icon;
1233 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1235 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1238 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1240 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1243 _item_icon_set(ctxpopup_it, icon);
1247 _scroller_size_reset(wd);
1248 _sizing_eval(WIDGET(ctxpopup_it));
1253 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1255 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1256 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1257 return ctxpopup_it->label;
1261 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1263 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1266 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1268 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1271 _item_label_set(ctxpopup_it, label);
1275 _scroller_size_reset(wd);
1276 _sizing_eval(WIDGET(ctxpopup_it));
1281 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1283 ELM_CHECK_WIDTYPE(obj, widtype);
1287 wd = elm_widget_data_get(obj);
1290 _hover_parent_callbacks_del(obj);
1294 evas_object_event_callback_add(hover_parent,
1298 evas_object_event_callback_add(hover_parent,
1302 evas_object_event_callback_add(hover_parent,
1303 EVAS_CALLBACK_RESIZE,
1304 _hover_parent_resize,
1308 wd->hover_parent = hover_parent;
1312 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1314 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1318 wd = elm_widget_data_get(obj);
1319 if (!wd) return NULL;
1321 return wd->hover_parent;
1325 elm_ctxpopup_clear(Evas_Object * obj)
1327 ELM_CHECK_WIDTYPE(obj, widtype);
1329 Widget_Data *wd = elm_widget_data_get(obj);
1337 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1339 ELM_CHECK_WIDTYPE(obj, widtype);
1343 Elm_Ctxpopup_Item *item;
1346 wd = elm_widget_data_get(obj);
1349 wd->horizontal = !!horizontal;
1351 if ((!wd->scr) && (!wd->box))
1356 elm_box_horizontal_set(wd->box, EINA_FALSE);
1357 elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1359 EINA_LIST_FOREACH(wd->items, elist, item)
1362 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1364 edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1369 elm_box_horizontal_set(wd->box, EINA_TRUE);
1370 elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1372 EINA_LIST_FOREACH(wd->items, elist, item)
1375 edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1377 edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1386 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1388 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1392 wd = elm_widget_data_get(obj);
1393 if (!wd) return EINA_FALSE;
1395 return wd->horizontal;
1398 EAPI Elm_Object_Item *
1399 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1400 Evas_Object *icon, Evas_Smart_Cb func,
1403 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1406 Elm_Ctxpopup_Item *item;
1408 wd = elm_widget_data_get(obj);
1409 if (!wd) return NULL;
1411 item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1412 if (!item) return NULL;
1414 //The first item is appended.
1416 evas_object_del(elm_object_content_unset(obj));
1422 item->base.data = data;
1425 _item_new(item, "icon_text_style_item");
1427 _item_new(item, "text_style_item");
1429 _item_new(item, "icon_style_item");
1431 _item_icon_set(item, icon);
1432 _item_label_set(item, label);
1433 elm_box_pack_end(wd->box, VIEW(item));
1434 wd->items = eina_list_append(wd->items, item);
1438 _scroller_size_reset(wd);
1442 return (Elm_Object_Item *) item;
1446 elm_ctxpopup_item_del(Elm_Object_Item *it)
1448 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1451 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1453 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1456 if (ctxpopup_it->icon)
1457 evas_object_del(ctxpopup_it->icon);
1458 if (VIEW(ctxpopup_it))
1459 evas_object_del(VIEW(ctxpopup_it));
1461 eina_stringshare_del(ctxpopup_it->label);
1463 wd->items = eina_list_remove(wd->items, ctxpopup_it);
1465 if (eina_list_count(wd->items) < 1)
1469 _sizing_eval(WIDGET(ctxpopup_it));
1475 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1477 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1480 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1482 wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1485 if (disabled == ctxpopup_it->disabled)
1489 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
1491 edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
1493 ctxpopup_it->disabled = !!disabled;
1497 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1499 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1500 Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1501 return ctxpopup_it->disabled;
1505 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1507 elm_object_content_set(obj, content);
1511 elm_ctxpopup_content_unset(Evas_Object *obj)
1513 return elm_object_content_unset(obj);
1517 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1518 Elm_Ctxpopup_Direction first,
1519 Elm_Ctxpopup_Direction second,
1520 Elm_Ctxpopup_Direction third,
1521 Elm_Ctxpopup_Direction fourth)
1523 ELM_CHECK_WIDTYPE(obj, widtype);
1526 wd = elm_widget_data_get(obj);
1529 wd->dir_priority[0] = first;
1530 wd->dir_priority[1] = second;
1531 wd->dir_priority[2] = third;
1532 wd->dir_priority[3] = fourth;
1539 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1540 Elm_Ctxpopup_Direction *first,
1541 Elm_Ctxpopup_Direction *second,
1542 Elm_Ctxpopup_Direction *third,
1543 Elm_Ctxpopup_Direction *fourth)
1545 ELM_CHECK_WIDTYPE(obj, widtype);
1548 wd = elm_widget_data_get(obj);
1551 if (first) *first = wd->dir_priority[0];
1552 if (second) *second = wd->dir_priority[1];
1553 if (third) *third = wd->dir_priority[2];
1554 if (fourth) *fourth = wd->dir_priority[3];
1557 EAPI Elm_Ctxpopup_Direction
1558 elm_ctxpopup_direction_get(const Evas_Object *obj)
1560 ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1563 wd = elm_widget_data_get(obj);
1564 if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;