add VIEW() and WIDGET() macros for use with Elm_Widget_Items to create more consisten...
[framework/uifw/elementary.git] / src / lib / elc_ctxpopup.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Elm_Ctxpopup_Item Elm_Ctxpopup_Item;
6
7 struct _Elm_Ctxpopup_Item
8 {
9    ELM_WIDGET_ITEM;
10    const char *label;
11    Evas_Object *icon;
12    Evas_Smart_Cb func;
13    Eina_Bool disabled:1;
14 };
15
16 struct _Widget_Data
17 {
18    Evas_Object *parent;
19    Evas_Object *base;
20    Evas_Object *content;
21    Evas_Object *box;
22    Evas_Object *arrow;
23    Evas_Object *scr;
24    Evas_Object *bg;
25    Eina_List *items;
26    Elm_Ctxpopup_Direction dir;
27    Elm_Ctxpopup_Direction dir_priority[4];
28    Evas_Coord max_sc_w, max_sc_h;
29    Eina_Bool horizontal:1;
30    Eina_Bool visible:1;
31    Eina_Bool finished:1;
32 };
33
34 static const char *widtype = NULL;
35
36 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
37 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
38 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
39 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
40 static void _scroller_size_reset(Widget_Data *wd);
41 static void _on_focus_hook(void *data, Evas_Object *obj);
42 static Eina_Bool _event_hook(Evas_Object *obj,
43                              Evas_Object *src,
44                              Evas_Callback_Type type,
45                              void *event_info);
46 static void _parent_cut_off(Evas_Object *obj);
47 static void _parent_resize(void *data,
48                            Evas *e,
49                            Evas_Object *obj,
50                            void *event_info);
51 static void _parent_move(void *data,
52                          Evas *e,
53                          Evas_Object *obj,
54                          void *event_info);
55 static void _parent_del(void *data,
56                         Evas *e,
57                         Evas_Object *obj,
58                         void *event_info);
59 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
60 static void _adjust_pos_x(Evas_Coord_Point *pos,
61                           Evas_Coord_Point *base_size,
62                           Evas_Coord_Rectangle *hover_area);
63 static void _adjust_pos_y(Evas_Coord_Point *pos,
64                           Evas_Coord_Point *base_size,
65                           Evas_Coord_Rectangle *hover_area);
66 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
67                                                   Evas_Coord_Rectangle *rect);
68 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
69 static void _sizing_eval(Evas_Object *obj);
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,
77                               const char *part,
78                               Evas_Object *content);
79 static Evas_Object * _content_unset_hook(Evas_Object *obj,
80                                          const char *part__);
81 static Evas_Object * _content_get_hook(const Evas_Object *obj,
82                                        const char *part);
83 static void _bg_clicked_cb(void *data, Evas_Object *obj,
84                            const char *emission,
85                            const char *source);
86 static void _ctxpopup_show(void *data,
87                            Evas *e,
88                            Evas_Object *obj,
89                            void *event_info);
90 static void _hide(Evas_Object *obj);
91 static void _ctxpopup_hide(void *data,
92                            Evas *e,
93                            Evas_Object *obj,
94                            void *event_info);
95 static void _scroller_resize(void *data,
96                              Evas *e,
97                              Evas_Object *obj,
98                              void *event_info);
99 static void _ctxpopup_move(void *data,
100                            Evas *e,
101                            Evas_Object *obj,
102                            void *event_info);
103 static void _item_select_cb(void *data, Evas_Object *obj,
104                             const char *emission,
105                             const char *source);
106 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
107 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
108 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
109 static void _content_del(void *data,
110                          Evas *e,
111                          Evas_Object *obj,
112                          void *event_info);
113 static void _list_del(Widget_Data *wd);
114 static void _list_new(Evas_Object *obj);
115 static void _remove_items(Widget_Data * wd);
116
117 static const char SIG_DISMISSED[] = "dismissed";
118
119 static const Evas_Smart_Cb_Description _signals[] = {
120    {SIG_DISMISSED, ""},
121    {NULL, NULL}
122 };
123
124 static void
125 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
126            void *event_info __UNUSED__)
127 {
128    Widget_Data *wd = elm_widget_data_get(obj);
129
130    if ((!wd) || (!wd->scr)) return;
131    elm_object_scroll_freeze_push(wd->scr);
132 }
133
134 static void
135 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
136             void *event_info __UNUSED__)
137 {
138    Widget_Data *wd = elm_widget_data_get(obj);
139
140    if ((!wd) || (!wd->scr)) return;
141    elm_object_scroll_freeze_pop(wd->scr);
142 }
143
144 static void
145 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
146 {
147    Widget_Data *wd = elm_widget_data_get(obj);
148
149    if ((!wd) || (!wd->scr)) return;
150    elm_object_scroll_hold_push(wd->scr);
151 }
152
153 static void
154 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
155 {
156    Widget_Data *wd = elm_widget_data_get(obj);
157
158    if ((!wd) || (!wd->scr)) return;
159    elm_object_scroll_hold_pop(wd->scr);
160 }
161
162 static void
163 _scroller_size_reset(Widget_Data *wd)
164 {
165    wd->finished = EINA_FALSE;
166    wd->max_sc_h = -1;
167    wd->max_sc_w = -1;
168 }
169
170 static void
171 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
172 {
173    Widget_Data *wd = elm_widget_data_get(obj);
174    if (!wd) return;
175
176    if (elm_widget_focus_get(obj))
177      {
178         //FIXME:
179      }
180    else
181      {
182         //FIXME:
183      }
184 }
185
186 static Eina_Bool
187 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
188 {
189    Evas_Event_Key_Down *ev;
190    Widget_Data *wd;
191
192    if (type != EVAS_CALLBACK_KEY_DOWN)
193      return EINA_FALSE;
194    wd = elm_widget_data_get(obj);
195    if (!wd) return EINA_FALSE;
196
197    ev = event_info;
198    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
199    if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
200
201    evas_object_hide(obj);
202    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
203    return EINA_TRUE;
204 }
205
206 static void
207 _parent_cut_off(Evas_Object *obj)
208 {
209    Widget_Data *wd = elm_widget_data_get(obj);
210
211    if (!wd) return;
212
213    evas_object_event_callback_del_full(wd->parent,
214                                        EVAS_CALLBACK_DEL,
215                                        _parent_del,
216                                        obj);
217    evas_object_event_callback_del_full(wd->parent,
218                                        EVAS_CALLBACK_MOVE,
219                                        _parent_move,
220                                        obj);
221    evas_object_event_callback_del_full(wd->parent,
222                                        EVAS_CALLBACK_RESIZE,
223                                        _parent_resize,
224                                        obj);
225
226    elm_widget_sub_object_del(wd->parent, obj);
227 }
228
229 static void
230 _parent_resize(void *data,
231                Evas *e __UNUSED__,
232                Evas_Object *obj __UNUSED__,
233                void *event_info __UNUSED__)
234 {
235    Widget_Data *wd = elm_widget_data_get(data);
236    if (!wd) return;
237
238    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
239
240    _hide(data);
241 }
242
243 static void
244 _parent_move(void *data,
245              Evas *e __UNUSED__,
246              Evas_Object *obj __UNUSED__,
247              void *event_info __UNUSED__)
248 {
249    Widget_Data *wd = elm_widget_data_get(data);
250
251    if (!wd) return;
252
253    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
254
255    if (wd->visible)
256      {
257         _scroller_size_reset(wd);
258         _sizing_eval(obj);
259      }
260 }
261
262 static void
263 _parent_del(void *data,
264             Evas *e __UNUSED__,
265             Evas_Object *obj __UNUSED__,
266             void *event_info __UNUSED__)
267 {
268    evas_object_del(data);
269 }
270
271 static void
272 _item_sizing_eval(Elm_Ctxpopup_Item *item)
273 {
274    Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
275
276    if (!item) return;
277
278    edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
279                                         min_h);
280    evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
281    evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
282 }
283
284 static void
285 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
286               Evas_Coord_Rectangle *hover_area)
287 {
288    pos->x -= (base_size->x / 2);
289
290    if (pos->x < hover_area->x)
291      pos->x = hover_area->x;
292    else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
293      pos->x = (hover_area->x + hover_area->w) - base_size->x;
294
295    if (base_size->x > hover_area->w)
296      base_size->x -= (base_size->x - hover_area->w);
297
298    if (pos->x < hover_area->x)
299      pos->x = hover_area->x;
300 }
301
302 static void
303 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
304               Evas_Coord_Rectangle *hover_area)
305 {
306    pos->y -= (base_size->y / 2);
307
308    if (pos->y < hover_area->y)
309      pos->y = hover_area->y;
310    else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
311      pos->y = hover_area->y + hover_area->h - base_size->y;
312
313    if (base_size->y > hover_area->h)
314      base_size->y -= (base_size->y - hover_area->h);
315
316    if (pos->y < hover_area->y)
317      pos->y = hover_area->y;
318 }
319
320 static Elm_Ctxpopup_Direction
321 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
322 {
323    Widget_Data *wd;
324    Evas_Coord_Point pos = {0, 0};
325    Evas_Coord_Point base_size;
326    Evas_Coord_Point max_size;
327    Evas_Coord_Point min_size;
328    Evas_Coord_Rectangle hover_area;
329    Evas_Coord_Point arrow_size;
330    Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
331    Evas_Coord_Point temp;
332    int idx;
333
334    wd = elm_widget_data_get(obj);
335
336    if ((!wd) || (!rect))
337      return ELM_CTXPOPUP_DIRECTION_DOWN;
338
339    edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
340                                  &arrow_size.x, &arrow_size.y);
341    evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
342
343    //Initialize Area Rectangle.
344    evas_object_geometry_get(wd->parent,
345                             &hover_area.x,
346                             &hover_area.y,
347                             &hover_area.w,
348                             &hover_area.h);
349
350    evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
351
352    //recalc the edje
353    edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
354    evas_object_smart_calculate(wd->base);
355
356    //Limit to Max Size
357    evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
358
359    if ((max_size.y > 0) && (base_size.y > max_size.y))
360      base_size.y = max_size.y;
361
362    if ((max_size.x > 0) && (base_size.x > max_size.x))
363      base_size.x = max_size.x;
364
365    //Limit to Min Size
366    evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
367
368    if ((min_size.y > 0) && (base_size.y < min_size.y))
369      base_size.y = min_size.y;
370
371    if ((min_size.x > 0) && (base_size.x < min_size.x))
372      base_size.x = min_size.x;
373
374    //Check the Which direction is available.
375    //If find a avaialble direction, it adjusts position and size.
376    for (idx = 0; idx < 4; idx++)
377      {
378         switch (wd->dir_priority[idx])
379           {
380            case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
381            case ELM_CTXPOPUP_DIRECTION_UP:
382               temp.y = (pos.y - base_size.y);
383               if ((temp.y - arrow_size.y) < hover_area.y)
384                 continue;
385               _adjust_pos_x(&pos, &base_size, &hover_area);
386               pos.y -= base_size.y;
387               dir = ELM_CTXPOPUP_DIRECTION_UP;
388               break;
389            case ELM_CTXPOPUP_DIRECTION_LEFT:
390               temp.x = (pos.x - base_size.x);
391               if ((temp.x - arrow_size.x) < hover_area.x)
392                 continue;
393               _adjust_pos_y(&pos, &base_size, &hover_area);
394               pos.x -= base_size.x;
395               dir = ELM_CTXPOPUP_DIRECTION_LEFT;
396               break;
397            case ELM_CTXPOPUP_DIRECTION_RIGHT:
398               temp.x = (pos.x + base_size.x);
399               if ((temp.x + arrow_size.x) >
400                   (hover_area.x + hover_area.w))
401                 continue;
402               _adjust_pos_y(&pos, &base_size, &hover_area);
403               dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
404               break;
405            case ELM_CTXPOPUP_DIRECTION_DOWN:
406               temp.y = (pos.y + base_size.y);
407               if ((temp.y + arrow_size.y) >
408                   (hover_area.y + hover_area.h))
409                 continue;
410               _adjust_pos_x(&pos, &base_size, &hover_area);
411               dir = ELM_CTXPOPUP_DIRECTION_DOWN;
412               break;
413            default:
414               break;
415           }
416         break;
417      }
418
419    //In this case, all directions are invalid because of lack of space.
420    if (idx == 4)
421      {
422         Evas_Coord length[2];
423
424         if(!wd->horizontal)
425           {
426              length[0] = pos.y - hover_area.y;
427              length[1] = (hover_area.y + hover_area.h) - pos.y;
428
429              // ELM_CTXPOPUP_DIRECTION_UP
430              if (length[0] > length[1])
431                {
432                   _adjust_pos_x(&pos, &base_size, &hover_area);
433                   pos.y -= base_size.y;
434                   dir = ELM_CTXPOPUP_DIRECTION_UP;
435                   if (pos.y < (hover_area.y + arrow_size.y))
436                     {
437                        base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
438                        pos.y = hover_area.y + arrow_size.y;
439                     }
440                }
441              //ELM_CTXPOPUP_DIRECTION_DOWN
442              else
443                {
444                   _adjust_pos_x(&pos, &base_size, &hover_area);
445                   dir = ELM_CTXPOPUP_DIRECTION_DOWN;
446                   if ((pos.y + arrow_size.y + base_size.y) >
447                       (hover_area.y + hover_area.h))
448                      base_size.y -=
449                         ((pos.y + arrow_size.y + base_size.y) -
450                          (hover_area.y + hover_area.h));
451                }
452           }
453         else
454           {
455              length[0] = pos.x - hover_area.x;
456              length[1] = (hover_area.x + hover_area.w) - pos.x;
457
458              //ELM_CTXPOPUP_DIRECTION_LEFT
459              if (length[0] > length[1])
460                {
461                   _adjust_pos_y(&pos, &base_size, &hover_area);
462                   pos.x -= base_size.x;
463                   dir = ELM_CTXPOPUP_DIRECTION_LEFT;
464                   if (pos.x < (hover_area.x + arrow_size.x))
465                     {
466                        base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
467                        pos.x = hover_area.x + arrow_size.x;
468                     }
469                }
470              //ELM_CTXPOPUP_DIRECTION_RIGHT
471              else
472                {
473                   _adjust_pos_y(&pos, &base_size, &hover_area);
474                   dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
475                   if (pos.x + (arrow_size.x + base_size.x) >
476                       hover_area.x + hover_area.w)
477                      base_size.x -=
478                         ((pos.x + arrow_size.x + base_size.x) -
479                          (hover_area.x + hover_area.w));
480                }
481           }
482      }
483
484    //Final position and size.
485    rect->x = pos.x;
486    rect->y = pos.y;
487    rect->w = base_size.x;
488    rect->h = base_size.y;
489
490    return dir;
491 }
492
493 static void
494 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
495 {
496    Evas_Coord x, y;
497    Evas_Coord_Rectangle arrow_size;
498    Evas_Coord_Rectangle base_size;
499    Widget_Data *wd;
500
501    wd = elm_widget_data_get(obj);
502    if (!wd) return;
503
504    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
505    evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
506                             &arrow_size.h);
507    evas_object_geometry_get(wd->base, &base_size.x, &base_size.y,
508                             &base_size.w, &base_size.h);
509
510    edje_object_part_unswallow(wd->base, wd->arrow);
511
512    switch (dir)
513      {
514       case ELM_CTXPOPUP_DIRECTION_RIGHT:
515          edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
516          edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
517          if (base_size.h > 0)
518            {
519               if (y < ((arrow_size.h * 0.5) + base_size.y))
520                 y = 0;
521               else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
522                 y = base_size.h - arrow_size.h;
523               else
524                 y = y - base_size.y - (arrow_size.h * 0.5);
525               edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
526                                               (double) (y) / (double) (base_size.h - arrow_size.h));
527            }
528          break;
529       case ELM_CTXPOPUP_DIRECTION_LEFT:
530          edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
531          edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
532          if (base_size.h > 0)
533             {
534               if (y < (arrow_size.h * 0.5) + base_size.y)
535                 y = 0;
536               else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
537                 y = base_size.h - arrow_size.h;
538               else y = y - base_size.y - (arrow_size.h * 0.5);
539               edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
540                                               (double) (y) / (double) (base_size.h - arrow_size.h));
541             }
542          break;
543       case ELM_CTXPOPUP_DIRECTION_DOWN:
544          edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
545          edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
546          if (base_size.w > 0)
547            {
548               if (x < (arrow_size.w * 0.5) + base_size.x)
549                 x = 0;
550               else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
551                 x = base_size.w - arrow_size.w;
552               else
553                 x = x - base_size.x - (arrow_size.w * 0.5);
554               edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
555                                               (double) (x) / (double) (base_size.w - arrow_size.w), 1);
556            }
557          break;
558       case ELM_CTXPOPUP_DIRECTION_UP:
559          edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
560          edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
561          if (base_size.w > 0)
562            {
563               if (x < (arrow_size.w * 0.5) + base_size.x)
564                 x = 0;
565               else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
566                 x = base_size.w - arrow_size.w;
567               else x = x - base_size.x - (arrow_size.w * 0.5);
568               edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
569                                               (double) (x) / (double) (base_size.w - arrow_size.w), 0);
570            }
571          break;
572       default:
573          break;
574      }
575 }
576
577 static void
578 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
579 {
580    Widget_Data *wd;
581
582    wd = elm_widget_data_get(obj);
583    if (!wd || wd->visible) return;
584
585    switch (dir)
586      {
587         case ELM_CTXPOPUP_DIRECTION_UP:
588            edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
589            break;
590         case ELM_CTXPOPUP_DIRECTION_LEFT:
591            edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
592            break;
593         case ELM_CTXPOPUP_DIRECTION_RIGHT:
594            edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
595            break;
596         case ELM_CTXPOPUP_DIRECTION_DOWN:
597            edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
598            break;
599         default:
600            break;
601      }
602 }
603
604 static void
605 _sizing_eval(Evas_Object *obj)
606 {
607    Widget_Data *wd;
608    Eina_List *elist;
609    Elm_Ctxpopup_Item *item;
610    Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
611    Evas_Coord_Point box_size = { 0, 0 };
612    Evas_Coord_Point _box_size = { 0, 0 };
613
614    wd = elm_widget_data_get(obj);
615    if (!wd) return;
616
617    //Box, Scroller
618    EINA_LIST_FOREACH(wd->items, elist, item)
619      {
620         _item_sizing_eval(item);
621         evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
622         if (!wd->horizontal)
623           {
624              if (_box_size.x > box_size.x)
625                box_size.x = _box_size.x;
626              if (_box_size.y != -1)
627                box_size.y += _box_size.y;
628           }
629         else
630           {
631              if (_box_size.x != -1)
632                box_size.x += _box_size.x;
633              if (_box_size.y > box_size.y)
634                box_size.y = _box_size.y;
635           }
636      }
637
638    if (!wd->content)
639      {
640         evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
641         evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
642      }
643
644    //Base
645    wd->dir = _calc_base_geometry(obj, &rect);
646    _show_signal_emit(obj, wd->dir);
647    _update_arrow(obj, wd->dir);
648    _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
649
650    //resize scroller according to final size.
651    if (!wd->content)
652      evas_object_smart_calculate(wd->scr);
653
654    evas_object_move(wd->base, rect.x, rect.y);
655    evas_object_resize(wd->base, rect.w, rect.h);
656 }
657
658 static void
659 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
660                      Evas_Coord_Rectangle *rect)
661 {
662    Evas_Coord arrow_w, arrow_h;
663
664    evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
665
666    switch (dir)
667      {
668       case ELM_CTXPOPUP_DIRECTION_RIGHT:
669          rect->x += arrow_w;
670          break;
671       case ELM_CTXPOPUP_DIRECTION_LEFT:
672          rect->x -= arrow_w;
673          break;
674       case ELM_CTXPOPUP_DIRECTION_DOWN:
675          rect->y += arrow_h;
676          break;
677       case ELM_CTXPOPUP_DIRECTION_UP:
678          rect->y -= arrow_h;
679          break;
680       default:
681          break;
682      }
683 }
684
685 static void
686 _del_pre_hook(Evas_Object *obj)
687 {
688    Widget_Data *wd;
689
690    wd = elm_widget_data_get(obj);
691    if (!wd) return;
692
693    _parent_cut_off(obj);
694 }
695
696 static void
697 _del_hook(Evas_Object *obj)
698 {
699    Widget_Data *wd;
700
701    wd = elm_widget_data_get(obj);
702    if (!wd) return;
703
704    elm_ctxpopup_clear(obj);
705    evas_object_del(wd->arrow);
706    evas_object_del(wd->base);
707    free(wd);
708 }
709
710 static void
711 _theme_hook(Evas_Object *obj)
712 {
713    Widget_Data *wd;
714    Eina_List *elist;
715    Elm_Ctxpopup_Item *item;
716
717    wd = elm_widget_data_get(obj);
718    if (!wd) return;
719
720    //Items
721    EINA_LIST_FOREACH(wd->items, elist, item)
722      {
723         if (item->label && item->icon)
724           _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
725                                 "icon_text_style_item",
726                                 elm_widget_style_get(obj));
727         else if (item->label)
728           _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
729                                 elm_widget_style_get(obj));
730         else if (item->icon)
731           _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
732                                 elm_widget_style_get(obj));
733         if (item->label)
734           edje_object_part_text_set(VIEW(item), "elm.text", item->label);
735
736         if (item->disabled)
737           edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
738
739         edje_object_message_signal_process(VIEW(item));
740      }
741
742    _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
743                          elm_widget_style_get(obj));
744    _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
745                          elm_widget_style_get(obj));
746    _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
747                          elm_widget_style_get(obj));
748
749    if (wd->scr)
750      {
751         if (!strncmp(elm_object_style_get(obj), "default",
752                      strlen("default")))
753            elm_object_style_set(wd->scr, "ctxpopup");
754         else
755            elm_object_style_set(wd->scr, elm_object_style_get(obj));
756      }
757
758    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
759
760    if (wd->visible)
761      {
762         _scroller_size_reset(wd);
763         _sizing_eval(obj);
764      }
765 }
766
767 static void
768 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__,
769                   Evas_Object *content)
770 {
771    ELM_CHECK_WIDTYPE(obj, widtype);
772
773    Widget_Data *wd;
774
775    wd = elm_widget_data_get(obj);
776    if ((!wd) || (!content)) return;
777
778    if (wd->items) elm_ctxpopup_clear(obj);
779    if (wd->content) evas_object_del(wd->content);
780
781    evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
782                                   obj);
783
784    elm_widget_sub_object_add(obj, content);
785    edje_object_part_swallow(wd->base, "elm.swallow.content", content);
786
787    wd->content = content;
788
789    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
790
791    if (wd->visible)
792      _sizing_eval(obj);
793 }
794
795 static Evas_Object *
796 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
797 {
798    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
799
800    Widget_Data *wd;
801    Evas_Object *content;
802
803    wd = elm_widget_data_get(obj);
804    if (!wd) return NULL;
805
806    content = wd->content;
807    if (!content) return NULL;
808
809    edje_object_part_unswallow(wd->base, content);
810    elm_widget_sub_object_del(obj, content);
811    evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
812    edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
813
814    wd->content = NULL;
815    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
816
817    return content;
818
819 }
820
821 static Evas_Object *
822 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
823 {
824    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
825
826    Widget_Data *wd = elm_widget_data_get(obj);
827    if (!wd) return NULL;
828    return wd->content;
829 }
830
831 static void
832 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
833                const char *emission __UNUSED__, const char *source __UNUSED__)
834 {
835    evas_object_hide(data);
836 }
837
838 static void
839 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
840                void *event_info __UNUSED__)
841 {
842    Widget_Data *wd;
843
844    wd = elm_widget_data_get(obj);
845    if (!wd) return;
846
847    if ((!wd->items) && (!wd->content)) return;
848
849    wd->visible = EINA_TRUE;
850
851    evas_object_show(wd->bg);
852    evas_object_show(wd->base);
853    evas_object_show(wd->arrow);
854
855    edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
856    edje_object_signal_emit(wd->base, "elm,state,show", "elm");
857
858    _sizing_eval(obj);
859
860    elm_object_focus_set(obj, EINA_TRUE);
861 }
862
863 static void
864 _hide(Evas_Object *obj)
865 {
866    Widget_Data *wd = elm_widget_data_get(obj);
867
868    if ((!wd) || (!wd->visible)) return;
869
870    evas_object_hide(wd->bg);
871    evas_object_hide(wd->arrow);
872    evas_object_hide(wd->base);
873
874    _scroller_size_reset(wd);
875
876    evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
877    wd->visible = EINA_FALSE;
878 }
879
880 static void
881 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
882                void *event_info __UNUSED__)
883 {
884    _hide(obj);
885 }
886
887 static void
888 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
889                  void *event_info __UNUSED__)
890 {
891    Widget_Data *wd;
892    Evas_Coord w, h;
893
894    wd = elm_widget_data_get(data);
895    if (!wd) return;
896    if (!wd->visible) return;
897    if (wd->finished) return;
898
899    evas_object_geometry_get(obj, 0, 0, &w, &h);
900
901    if (w != 0 && h != 0)
902      {
903         if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
904           {
905              _sizing_eval(data);
906              wd->finished = EINA_TRUE;
907              return;
908           }
909      }
910
911    if (wd->max_sc_w < w)
912      wd->max_sc_w = w;
913    if (wd->max_sc_h < h)
914      wd->max_sc_h = h;
915
916    _sizing_eval(data);
917 }
918
919 static void
920 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
921                void *event_info __UNUSED__)
922 {
923    Widget_Data *wd;
924
925    wd = elm_widget_data_get(obj);
926
927    if (!wd) return;
928
929    if (wd->visible)
930      evas_object_show(wd->arrow);
931
932    _scroller_size_reset(wd);
933    _sizing_eval(obj);
934 }
935
936 static void
937 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
938                 const char *emission __UNUSED__, const char *source __UNUSED__)
939 {
940    Elm_Ctxpopup_Item *item = data;
941
942    if (!item) return;
943    if (item->disabled) return;
944
945    if (item->func)
946      item->func((void*) item->base.data, WIDGET(item), data);
947 }
948
949 static void
950 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
951 {
952    if (item->icon)
953      evas_object_del(item->icon);
954
955    item->icon = icon;
956    if (!icon) return;
957
958    edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
959    edje_object_message_signal_process(VIEW(item));
960 }
961
962 static void
963 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
964 {
965    if (!eina_stringshare_replace(&item->label, label))
966      return;
967
968    edje_object_part_text_set(VIEW(item), "elm.text", label);
969    edje_object_message_signal_process(VIEW(item));
970 }
971
972 static void
973 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
974 {
975    Widget_Data *wd;
976
977    wd = elm_widget_data_get(WIDGET(item));
978    if (!wd) return;
979
980    VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
981    _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
982                          elm_widget_style_get(WIDGET(item)));
983    edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
984                                    _item_select_cb, item);
985    evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
986    evas_object_show(VIEW(item));
987 }
988
989 static void
990 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
991              void *event_info __UNUSED__)
992 {
993    elm_object_content_unset(data);
994 }
995
996 static void
997 _list_del(Widget_Data *wd)
998 {
999    if (!wd->scr) return;
1000
1001    edje_object_part_unswallow(wd->base, wd->scr);
1002    evas_object_del(wd->scr);
1003    wd->scr = NULL;
1004    wd->box = NULL;
1005 }
1006
1007 static void
1008 _list_new(Evas_Object *obj)
1009 {
1010    Widget_Data *wd;
1011    wd = elm_widget_data_get(obj);
1012    if (!wd) return;
1013
1014    //scroller
1015    wd->scr = elm_scroller_add(obj);
1016    elm_object_style_set(wd->scr, "ctxpopup");
1017    evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1018    evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1019                                   _scroller_resize, obj);
1020    edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1021
1022    //box
1023    wd->box = elm_box_add(obj);
1024    evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1025                                     EVAS_HINT_EXPAND);
1026
1027    elm_scroller_content_set(wd->scr, wd->box);
1028    elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1029 }
1030
1031 static void
1032 _remove_items(Widget_Data *wd)
1033 {
1034    Eina_List *elist;
1035    Elm_Ctxpopup_Item *item;
1036
1037    if (!wd->items) return;
1038
1039    EINA_LIST_FOREACH(wd->items, elist, item)
1040      {
1041         if (item->label)
1042           eina_stringshare_del(item->label);
1043         if (item->icon)
1044           evas_object_del(item->icon);
1045         wd->items = eina_list_remove(wd->items, item);
1046         free(item);
1047      }
1048
1049    wd->items = NULL;
1050 }
1051
1052 EAPI Evas_Object *
1053 elm_ctxpopup_add(Evas_Object *parent)
1054 {
1055    Evas_Object *obj;
1056    Evas *e;
1057    Widget_Data *wd;
1058
1059    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1060
1061    ELM_SET_WIDTYPE(widtype, "ctxpopup");
1062    elm_widget_type_set(obj, "ctxpopup");
1063    elm_widget_data_set(obj, wd);
1064    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1065    elm_widget_del_hook_set(obj, _del_hook);
1066    elm_widget_theme_hook_set(obj, _theme_hook);
1067    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1068    elm_widget_can_focus_set(obj, EINA_TRUE);
1069    elm_widget_event_hook_set(obj, _event_hook);
1070    elm_widget_content_set_hook_set(obj, _content_set_hook);
1071    elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1072    elm_widget_content_get_hook_set(obj, _content_get_hook);
1073
1074    //Background
1075    wd->bg = edje_object_add(e);
1076    elm_widget_sub_object_add(obj, wd->bg);
1077    _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1078    edje_object_signal_callback_add(wd->bg,
1079                                    "elm,action,click",
1080                                    "",
1081                                    _bg_clicked_cb,
1082                                     obj);
1083    //Base
1084    wd->base = edje_object_add(e);
1085    elm_widget_sub_object_add(obj, wd->base);
1086    _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1087
1088    //Arrow
1089    wd->arrow = edje_object_add(e);
1090    elm_widget_sub_object_add(obj, wd->arrow);
1091    _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1092
1093    wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1094    wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1095    wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1096    wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1097    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1098
1099    evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1100                                   NULL);
1101    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1102                                   NULL);
1103    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1104                                   NULL);
1105    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1106    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1107    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1108    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1109
1110    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1111
1112    //default parent is to be hover parent
1113    elm_ctxpopup_hover_parent_set(obj, parent);
1114
1115    return obj;
1116 }
1117
1118 EAPI Evas_Object *
1119 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1120 {
1121    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1122    Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1123    return ctxpopup_it->icon;
1124 }
1125
1126 EAPI void
1127 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1128 {
1129    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1130
1131    Widget_Data *wd;
1132    Elm_Ctxpopup_Item *ctxpopup_it  = (Elm_Ctxpopup_Item *) it;
1133
1134    wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1135    if (!wd) return;
1136
1137    _item_icon_set(ctxpopup_it, icon);
1138    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1139
1140    if (wd->visible)
1141      {
1142         _scroller_size_reset(wd);
1143         _sizing_eval(WIDGET(ctxpopup_it));
1144      }
1145 }
1146
1147 EAPI const char *
1148 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1149 {
1150    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1151    Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1152    return ctxpopup_it->label;
1153 }
1154
1155 EAPI void
1156 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1157 {
1158    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1159
1160    Widget_Data *wd;
1161    Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1162
1163    wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1164    if (!wd) return;
1165
1166    _item_label_set(ctxpopup_it, label);
1167    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1168
1169    if (wd->visible)
1170      {
1171         _scroller_size_reset(wd);
1172         _sizing_eval(WIDGET(ctxpopup_it));
1173      }
1174 }
1175
1176 EAPI void
1177 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1178 {
1179    ELM_CHECK_WIDTYPE(obj, widtype);
1180
1181    Widget_Data *wd;
1182    Evas_Coord x, y, w, h;
1183
1184    wd = elm_widget_data_get(obj);
1185    if ((!wd) || (!parent)) return;
1186
1187    _parent_cut_off(obj);
1188
1189    if (parent)
1190      {
1191         evas_object_event_callback_add(parent,
1192                                        EVAS_CALLBACK_DEL,
1193                                        _parent_del,
1194                                        obj);
1195         evas_object_event_callback_add(parent,
1196                                        EVAS_CALLBACK_MOVE,
1197                                        _parent_move,
1198                                        obj);
1199         evas_object_event_callback_add(parent,
1200                                        EVAS_CALLBACK_RESIZE,
1201                                        _parent_resize,
1202                                        obj);
1203      }
1204
1205    elm_widget_sub_object_add(parent, obj);
1206    wd->parent = parent;
1207
1208    //Update Background
1209    evas_object_geometry_get(parent, &x, &y, &w, &h);
1210    evas_object_move(wd->bg, x, y);
1211    evas_object_resize(wd->bg, w, h);
1212
1213    if (wd->visible) _sizing_eval(obj);
1214 }
1215
1216 EAPI Evas_Object *
1217 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1218 {
1219    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1220
1221    Widget_Data *wd;
1222
1223    wd = elm_widget_data_get(obj);
1224    if (!wd) return NULL;
1225
1226    return wd->parent;
1227 }
1228
1229 EAPI void
1230 elm_ctxpopup_clear(Evas_Object * obj)
1231 {
1232    ELM_CHECK_WIDTYPE(obj, widtype);
1233
1234    Widget_Data *wd = elm_widget_data_get(obj);
1235    if (!wd) return;
1236
1237    _remove_items(wd);
1238    _list_del(wd);
1239    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1240 }
1241
1242 EAPI void
1243 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1244 {
1245    ELM_CHECK_WIDTYPE(obj, widtype);
1246
1247    Widget_Data *wd;
1248
1249    wd = elm_widget_data_get(obj);
1250    if (!wd) return;
1251
1252    wd->horizontal = !!horizontal;
1253
1254    if ((!wd->scr) && (!wd->box))
1255       return;
1256
1257    if (!horizontal)
1258      {
1259         elm_box_horizontal_set(wd->box, EINA_FALSE);
1260         elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1261      }
1262    else
1263      {
1264         elm_box_horizontal_set(wd->box, EINA_TRUE);
1265         elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1266      }
1267
1268    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1269
1270    if (wd->visible)
1271       _sizing_eval(obj);
1272 }
1273
1274 EAPI Eina_Bool
1275 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1276 {
1277    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1278
1279    Widget_Data *wd;
1280
1281    wd = elm_widget_data_get(obj);
1282    if (!wd) return EINA_FALSE;
1283
1284    return wd->horizontal;
1285 }
1286
1287 EAPI Elm_Object_Item *
1288 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1289                          Evas_Object *icon, Evas_Smart_Cb func,
1290                          const void *data)
1291 {
1292    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1293
1294    Widget_Data *wd;
1295    Evas_Object *content;
1296    Elm_Ctxpopup_Item *item;
1297
1298    wd = elm_widget_data_get(obj);
1299    if (!wd) return NULL;
1300
1301    item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1302    if (!item) return NULL;
1303
1304    //The first item is appended.
1305    content = elm_object_content_unset(obj);
1306    if (content) evas_object_del(content);
1307
1308    if (!wd->items)
1309      _list_new(obj);
1310
1311    item->func = func;
1312    item->base.data = data;
1313
1314    if (icon && label)
1315      _item_new(item, "icon_text_style_item");
1316    else if (label)
1317      _item_new(item, "text_style_item");
1318    else
1319      _item_new(item, "icon_style_item");
1320
1321    _item_icon_set(item, icon);
1322    _item_label_set(item, label);
1323    elm_box_pack_end(wd->box, VIEW(item));
1324    wd->items = eina_list_append(wd->items, item);
1325    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1326
1327    if (wd->visible)
1328      {
1329         _scroller_size_reset(wd);
1330         _sizing_eval(obj);
1331      }
1332
1333    return (Elm_Object_Item *) item;
1334 }
1335
1336 EAPI void
1337 elm_ctxpopup_item_del(Elm_Object_Item *it)
1338 {
1339    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1340
1341    Widget_Data *wd;
1342    Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1343
1344    wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1345    if (!wd) return;
1346
1347    if (ctxpopup_it->icon)
1348      evas_object_del(ctxpopup_it->icon);
1349    if (VIEW(ctxpopup_it))
1350      evas_object_del(VIEW(ctxpopup_it));
1351
1352    eina_stringshare_del(ctxpopup_it->label);
1353
1354    wd->items = eina_list_remove(wd->items, ctxpopup_it);
1355
1356    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1357
1358    elm_widget_item_del(ctxpopup_it);
1359
1360    if (eina_list_count(wd->items) < 1)
1361      {
1362         evas_object_hide(WIDGET(ctxpopup_it));
1363         return;
1364      }
1365
1366    if (wd->visible)
1367      _sizing_eval(WIDGET(ctxpopup_it));
1368
1369 }
1370
1371 EAPI void
1372 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1373 {
1374    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1375
1376    Widget_Data *wd;
1377    Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1378
1379    wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1380    if (!wd) return;
1381
1382    if (disabled == ctxpopup_it->disabled)
1383      return;
1384
1385    if (disabled)
1386      edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
1387    else
1388      edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
1389
1390    ctxpopup_it->disabled = !!disabled;
1391 }
1392
1393 EAPI Eina_Bool
1394 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1395 {
1396    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1397    Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1398    return ctxpopup_it->disabled;
1399 }
1400
1401 EAPI void
1402 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1403 {
1404    elm_object_content_set(obj, content);
1405 }
1406
1407 EAPI Evas_Object *
1408 elm_ctxpopup_content_unset(Evas_Object *obj)
1409 {
1410    return elm_object_content_unset(obj);
1411 }
1412
1413 EAPI void
1414 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1415                                     Elm_Ctxpopup_Direction first,
1416                                     Elm_Ctxpopup_Direction second,
1417                                     Elm_Ctxpopup_Direction third,
1418                                     Elm_Ctxpopup_Direction fourth)
1419 {
1420    ELM_CHECK_WIDTYPE(obj, widtype);
1421    Widget_Data *wd;
1422
1423    wd = elm_widget_data_get(obj);
1424    if (!wd) return;
1425
1426    wd->dir_priority[0] = first;
1427    wd->dir_priority[1] = second;
1428    wd->dir_priority[2] = third;
1429    wd->dir_priority[3] = fourth;
1430
1431    if (wd->visible)
1432      _sizing_eval(obj);
1433 }
1434
1435 EAPI void
1436 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1437                                     Elm_Ctxpopup_Direction *first,
1438                                     Elm_Ctxpopup_Direction *second,
1439                                     Elm_Ctxpopup_Direction *third,
1440                                     Elm_Ctxpopup_Direction *fourth)
1441 {
1442    ELM_CHECK_WIDTYPE(obj, widtype);
1443    Widget_Data *wd;
1444
1445    wd = elm_widget_data_get(obj);
1446    if (!wd) return;
1447
1448    if (first) *first = wd->dir_priority[0];
1449    if (second) *second = wd->dir_priority[1];
1450    if (third) *third = wd->dir_priority[2];
1451    if (fourth) *fourth = wd->dir_priority[3];
1452 }
1453
1454 EAPI Elm_Ctxpopup_Direction
1455 elm_ctxpopup_direction_get(const Evas_Object *obj)
1456 {
1457    ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1458    Widget_Data *wd;
1459
1460    wd = elm_widget_data_get(obj);
1461    if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1462    return wd->dir;
1463 }