elm: Removed all trailing whitespaces.
[platform/upstream/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 base;
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_DONT_KNOW;
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_DONT_KNOW;
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(item->base.view, &min_w, &min_h, min_w,
279                                         min_h);
280    evas_object_size_hint_min_set(item->base.view, min_w, min_h);
281    evas_object_size_hint_max_set(item->base.view, 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_DONT_KNOW;
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_DONT_KNOW:
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    switch (dir)
511      {
512       case ELM_CTXPOPUP_DIRECTION_RIGHT:
513          edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
514          edje_object_part_swallow(wd->base, "elm.swallow.arrow_left", wd->arrow);
515          if (base_size.h > 0)
516            {
517               if (y < ((arrow_size.h * 0.5) + base_size.y))
518                 y = 0;
519               else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
520                 y = base_size.h - arrow_size.h;
521               else
522                 y = y - base_size.y - (arrow_size.h * 0.5);
523               edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_left", 1,
524                                               (double) (y) / (double) (base_size.h - arrow_size.h));
525            }
526          break;
527       case ELM_CTXPOPUP_DIRECTION_LEFT:
528          edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
529          edje_object_part_swallow(wd->base, "elm.swallow.arrow_right", wd->arrow);
530          if (base_size.h > 0)
531             {
532               if (y < (arrow_size.h * 0.5) + base_size.y)
533                 y = 0;
534               else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
535                 y = base_size.h - arrow_size.h;
536               else y = y - base_size.y - (arrow_size.h * 0.5);
537               edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_right", 0,
538                                               (double) (y) / (double) (base_size.h - arrow_size.h));
539             }
540          break;
541       case ELM_CTXPOPUP_DIRECTION_DOWN:
542          edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
543          edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
544          if (base_size.w > 0)
545            {
546               if (x < (arrow_size.w * 0.5) + base_size.x)
547                 x = 0;
548               else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
549                 x = base_size.w - arrow_size.w;
550               else
551                 x = x - base_size.x - (arrow_size.w * 0.5);
552               edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_up",
553                                               (double) (x) / (double) (base_size.w - arrow_size.w), 1);
554            }
555          break;
556       case ELM_CTXPOPUP_DIRECTION_UP:
557          edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
558          edje_object_part_swallow(wd->base, "elm.swallow.arrow_down", wd->arrow);
559          if (base_size.w > 0)
560            {
561               if (x < (arrow_size.w * 0.5) + base_size.x)
562                 x = 0;
563               else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
564                 x = base_size.w - arrow_size.w;
565               else x = x - base_size.x - (arrow_size.w * 0.5);
566               edje_object_part_drag_value_set(wd->base, "elm.swallow.arrow_down",
567                                               (double) (x) / (double) (base_size.w - arrow_size.w), 0);
568            }
569          break;
570       default:
571          break;
572      }
573 }
574
575 static void
576 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
577 {
578    Widget_Data *wd;
579
580    wd = elm_widget_data_get(obj);
581    if (!wd || wd->visible) return;
582
583    switch (dir)
584      {
585         case ELM_CTXPOPUP_DIRECTION_UP:
586            edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
587            break;
588         case ELM_CTXPOPUP_DIRECTION_LEFT:
589            edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
590            break;
591         case ELM_CTXPOPUP_DIRECTION_RIGHT:
592            edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
593            break;
594         case ELM_CTXPOPUP_DIRECTION_DOWN:
595            edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
596            break;
597         default:
598            break;
599      }
600 }
601
602 static void
603 _sizing_eval(Evas_Object *obj)
604 {
605    Widget_Data *wd;
606    Eina_List *elist;
607    Elm_Ctxpopup_Item *item;
608    Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
609    Evas_Coord_Point box_size = { 0, 0 };
610    Evas_Coord_Point _box_size = { 0, 0 };
611
612    wd = elm_widget_data_get(obj);
613    if (!wd) return;
614
615    //Box, Scroller
616    EINA_LIST_FOREACH(wd->items, elist, item)
617      {
618         _item_sizing_eval(item);
619         evas_object_size_hint_min_get(item->base.view, &_box_size.x, &_box_size.y);
620         if (!wd->horizontal)
621           {
622              if (_box_size.x > box_size.x)
623                box_size.x = _box_size.x;
624              if (_box_size.y != -1)
625                box_size.y += _box_size.y;
626           }
627         else
628           {
629              if (_box_size.x != -1)
630                box_size.x += _box_size.x;
631              if (_box_size.y > box_size.y)
632                box_size.y = _box_size.y;
633           }
634      }
635
636    if (!wd->content)
637      {
638         evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
639         evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
640      }
641
642    //Base
643    wd->dir = _calc_base_geometry(obj, &rect);
644    _show_signal_emit(obj, wd->dir);
645    _update_arrow(obj, wd->dir);
646    _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
647
648    //resize scroller according to final size.
649    if (!wd->content)
650      evas_object_smart_calculate(wd->scr);
651
652    evas_object_move(wd->base, rect.x, rect.y);
653    evas_object_resize(wd->base, rect.w, rect.h);
654 }
655
656 static void
657 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
658                      Evas_Coord_Rectangle *rect)
659 {
660    Evas_Coord arrow_w, arrow_h;
661
662    evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
663
664    switch (dir)
665      {
666       case ELM_CTXPOPUP_DIRECTION_RIGHT:
667          rect->x += arrow_w;
668          break;
669       case ELM_CTXPOPUP_DIRECTION_LEFT:
670          rect->x -= arrow_w;
671          break;
672       case ELM_CTXPOPUP_DIRECTION_DOWN:
673          rect->y += arrow_h;
674          break;
675       case ELM_CTXPOPUP_DIRECTION_UP:
676          rect->y -= arrow_h;
677          break;
678       default:
679          break;
680      }
681 }
682
683 static void
684 _del_pre_hook(Evas_Object *obj)
685 {
686    Widget_Data *wd;
687
688    wd = elm_widget_data_get(obj);
689    if (!wd) return;
690
691    _parent_cut_off(obj);
692 }
693
694 static void
695 _del_hook(Evas_Object *obj)
696 {
697    Widget_Data *wd;
698
699    wd = elm_widget_data_get(obj);
700    if (!wd) return;
701
702    elm_ctxpopup_clear(obj);
703    evas_object_del(wd->arrow);
704    evas_object_del(wd->base);
705    free(wd);
706 }
707
708 static void
709 _theme_hook(Evas_Object *obj)
710 {
711    Widget_Data *wd;
712    Eina_List *elist;
713    Elm_Ctxpopup_Item *item;
714
715    wd = elm_widget_data_get(obj);
716    if (!wd) return;
717
718    //Items
719    EINA_LIST_FOREACH(wd->items, elist, item)
720      {
721         if (item->label && item->icon)
722           _elm_theme_object_set(obj, item->base.view, "ctxpopup",
723                                 "icon_text_style_item",
724                                 elm_widget_style_get(obj));
725         else if (item->label)
726           _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
727                                 elm_widget_style_get(obj));
728         else if (item->icon)
729           _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
730                                 elm_widget_style_get(obj));
731         if (item->label)
732           edje_object_part_text_set(item->base.view, "elm.text", item->label);
733
734         if (item->disabled)
735           edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
736
737         edje_object_message_signal_process(item->base.view);
738      }
739
740    _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
741                          elm_widget_style_get(obj));
742    _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
743                          elm_widget_style_get(obj));
744    _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
745                          elm_widget_style_get(obj));
746
747    if (wd->scr)
748      {
749         if (!strncmp(elm_object_style_get(obj), "default",
750                      strlen("default")))
751            elm_object_style_set(wd->scr, "ctxpopup");
752         else
753            elm_object_style_set(wd->scr, elm_object_style_get(obj));
754      }
755
756    wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
757
758    if (wd->visible)
759      {
760         _scroller_size_reset(wd);
761         _sizing_eval(obj);
762      }
763 }
764
765 static void
766 _content_set_hook(Evas_Object *obj, const char *part __UNUSED__,
767                   Evas_Object *content)
768 {
769    ELM_CHECK_WIDTYPE(obj, widtype);
770
771    Widget_Data *wd;
772
773    wd = elm_widget_data_get(obj);
774    if ((!wd) || (!content)) return;
775
776    if (wd->items) elm_ctxpopup_clear(obj);
777    if (wd->content) evas_object_del(wd->content);
778
779    evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
780                                   obj);
781
782    elm_widget_sub_object_add(obj, content);
783    edje_object_part_swallow(wd->base, "elm.swallow.content", content);
784
785    wd->content = content;
786
787    wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
788
789    if (wd->visible)
790      _sizing_eval(obj);
791 }
792
793 static Evas_Object *
794 _content_unset_hook(Evas_Object *obj, const char *part __UNUSED__)
795 {
796    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
797
798    Widget_Data *wd;
799    Evas_Object *content;
800
801    wd = elm_widget_data_get(obj);
802    if (!wd) return NULL;
803
804    content = wd->content;
805    if (!content) return NULL;
806
807    edje_object_part_unswallow(wd->base, content);
808    elm_widget_sub_object_del(obj, content);
809    evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
810    edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
811
812    wd->content = NULL;
813    wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
814
815    return content;
816
817 }
818
819 static Evas_Object *
820 _content_get_hook(const Evas_Object *obj, const char *part __UNUSED__)
821 {
822    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
823
824    Widget_Data *wd = elm_widget_data_get(obj);
825    if (!wd) return NULL;
826    return wd->content;
827 }
828
829 static void
830 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
831                const char *emission __UNUSED__, const char *source __UNUSED__)
832 {
833    evas_object_hide(data);
834 }
835
836 static void
837 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
838                void *event_info __UNUSED__)
839 {
840    Widget_Data *wd;
841
842    wd = elm_widget_data_get(obj);
843    if (!wd) return;
844
845    if ((!wd->items) && (!wd->content)) return;
846
847    wd->visible = EINA_TRUE;
848
849    evas_object_show(wd->bg);
850    evas_object_show(wd->base);
851    evas_object_show(wd->arrow);
852
853    edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
854    edje_object_signal_emit(wd->base, "elm,state,show", "elm");
855
856    _sizing_eval(obj);
857
858    elm_object_focus_set(obj, EINA_TRUE);
859 }
860
861 static void
862 _hide(Evas_Object *obj)
863 {
864    Widget_Data *wd = elm_widget_data_get(obj);
865
866    if ((!wd) || (!wd->visible)) return;
867
868    evas_object_hide(wd->bg);
869    evas_object_hide(wd->arrow);
870    evas_object_hide(wd->base);
871
872    _scroller_size_reset(wd);
873
874    evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
875    wd->visible = EINA_FALSE;
876 }
877
878 static void
879 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
880                void *event_info __UNUSED__)
881 {
882    _hide(obj);
883 }
884
885 static void
886 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
887                  void *event_info __UNUSED__)
888 {
889    Widget_Data *wd;
890    Evas_Coord w, h;
891
892    wd = elm_widget_data_get(data);
893    if (!wd) return;
894    if (!wd->visible) return;
895    if (wd->finished) return;
896
897    evas_object_geometry_get(obj, 0, 0, &w, &h);
898
899    if (w != 0 && h != 0)
900      {
901         if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
902           {
903              _sizing_eval(data);
904              wd->finished = EINA_TRUE;
905              return;
906           }
907      }
908
909    if (wd->max_sc_w < w)
910      wd->max_sc_w = w;
911    if (wd->max_sc_h < h)
912      wd->max_sc_h = h;
913
914    _sizing_eval(data);
915 }
916
917 static void
918 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
919                void *event_info __UNUSED__)
920 {
921    Widget_Data *wd;
922
923    wd = elm_widget_data_get(obj);
924
925    if (!wd) return;
926
927    if (wd->visible)
928      evas_object_show(wd->arrow);
929
930    _scroller_size_reset(wd);
931    _sizing_eval(obj);
932 }
933
934 static void
935 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
936                 const char *emission __UNUSED__, const char *source __UNUSED__)
937 {
938    Elm_Ctxpopup_Item *item = data;
939
940    if (!item) return;
941    if (item->disabled) return;
942
943    if (item->func)
944      item->func((void*) item->base.data, item->base.widget, data);
945 }
946
947 static void
948 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
949 {
950    if (item->icon)
951      evas_object_del(item->icon);
952
953    item->icon = icon;
954    if (!icon) return;
955
956    edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
957    edje_object_message_signal_process(item->base.view);
958 }
959
960 static void
961 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
962 {
963    if (!eina_stringshare_replace(&item->label, label))
964      return;
965
966    edje_object_part_text_set(item->base.view, "elm.text", label);
967    edje_object_message_signal_process(item->base.view);
968 }
969
970 static void
971 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
972 {
973    Widget_Data *wd;
974
975    wd = elm_widget_data_get(item->base.widget);
976    if (!wd) return;
977
978    item->base.view = edje_object_add(evas_object_evas_get(wd->base));
979    _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
980                          elm_widget_style_get(item->base.widget));
981    edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
982                                    _item_select_cb, item);
983    evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
984    evas_object_show(item->base.view);
985 }
986
987 static void
988 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
989              void *event_info __UNUSED__)
990 {
991    elm_object_content_unset(data);
992 }
993
994 static void
995 _list_del(Widget_Data *wd)
996 {
997    if (!wd->scr) return;
998
999    edje_object_part_unswallow(wd->base, wd->scr);
1000    evas_object_del(wd->scr);
1001    wd->scr = NULL;
1002    wd->box = NULL;
1003 }
1004
1005 static void
1006 _list_new(Evas_Object *obj)
1007 {
1008    Widget_Data *wd;
1009    wd = elm_widget_data_get(obj);
1010    if (!wd) return;
1011
1012    //scroller
1013    wd->scr = elm_scroller_add(obj);
1014    elm_object_style_set(wd->scr, "ctxpopup");
1015    evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1016    evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1017                                   _scroller_resize, obj);
1018    edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1019
1020    //box
1021    wd->box = elm_box_add(obj);
1022    evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1023                                     EVAS_HINT_EXPAND);
1024
1025    elm_scroller_content_set(wd->scr, wd->box);
1026    elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1027 }
1028
1029 static void
1030 _remove_items(Widget_Data *wd)
1031 {
1032    Eina_List *elist;
1033    Elm_Ctxpopup_Item *item;
1034
1035    if (!wd->items) return;
1036
1037    EINA_LIST_FOREACH(wd->items, elist, item)
1038      {
1039         if (item->label)
1040           eina_stringshare_del(item->label);
1041         if (item->icon)
1042           evas_object_del(item->icon);
1043         wd->items = eina_list_remove(wd->items, item);
1044         free(item);
1045      }
1046
1047    wd->items = NULL;
1048 }
1049
1050 EAPI Evas_Object *
1051 elm_ctxpopup_add(Evas_Object *parent)
1052 {
1053    Evas_Object *obj;
1054    Evas *e;
1055    Widget_Data *wd;
1056
1057    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1058
1059    ELM_SET_WIDTYPE(widtype, "ctxpopup");
1060    elm_widget_type_set(obj, "ctxpopup");
1061    elm_widget_data_set(obj, wd);
1062    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1063    elm_widget_del_hook_set(obj, _del_hook);
1064    elm_widget_theme_hook_set(obj, _theme_hook);
1065    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1066    elm_widget_can_focus_set(obj, EINA_TRUE);
1067    elm_widget_event_hook_set(obj, _event_hook);
1068    elm_widget_content_set_hook_set(obj, _content_set_hook);
1069    elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1070    elm_widget_content_get_hook_set(obj, _content_get_hook);
1071
1072    //Background
1073    wd->bg = edje_object_add(e);
1074    elm_widget_sub_object_add(obj, wd->bg);
1075    _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1076    edje_object_signal_callback_add(wd->bg,
1077                                    "elm,action,click",
1078                                    "",
1079                                    _bg_clicked_cb,
1080                                     obj);
1081    //Base
1082    wd->base = edje_object_add(e);
1083    elm_widget_sub_object_add(obj, wd->base);
1084    _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1085
1086    //Arrow
1087    wd->arrow = edje_object_add(e);
1088    elm_widget_sub_object_add(obj, wd->arrow);
1089    _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1090
1091    wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1092    wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1093    wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1094    wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1095    wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1096
1097    evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1098                                   NULL);
1099    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1100                                   NULL);
1101    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1102                                   NULL);
1103    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1104    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1105    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1106    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1107
1108    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1109
1110    //default parent is to be hover parent
1111    elm_ctxpopup_hover_parent_set(obj, parent);
1112
1113    return obj;
1114 }
1115
1116 EAPI Evas_Object *
1117 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1118 {
1119    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1120    Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1121    return ctxpopup_it->icon;
1122 }
1123
1124 EAPI void
1125 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1126 {
1127    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1128
1129    Widget_Data *wd;
1130    Elm_Ctxpopup_Item *ctxpopup_it  = ELM_CAST(it);
1131
1132    wd = elm_widget_data_get(ctxpopup_it->base.widget);
1133    if (!wd) return;
1134
1135    _item_icon_set(ctxpopup_it, icon);
1136    wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1137
1138    if (wd->visible)
1139      {
1140         _scroller_size_reset(wd);
1141         _sizing_eval(ctxpopup_it->base.widget);
1142      }
1143 }
1144
1145 EAPI const char *
1146 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1147 {
1148    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1149    Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1150    return ctxpopup_it->label;
1151 }
1152
1153 EAPI void
1154 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1155 {
1156    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1157
1158    Widget_Data *wd;
1159    Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1160
1161    wd = elm_widget_data_get(ctxpopup_it->base.widget);
1162    if (!wd) return;
1163
1164    _item_label_set(ctxpopup_it, label);
1165    wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1166
1167    if (wd->visible)
1168      {
1169         _scroller_size_reset(wd);
1170         _sizing_eval(ctxpopup_it->base.widget);
1171      }
1172 }
1173
1174 EAPI void
1175 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1176 {
1177    ELM_CHECK_WIDTYPE(obj, widtype);
1178
1179    Widget_Data *wd;
1180    Evas_Coord x, y, w, h;
1181
1182    wd = elm_widget_data_get(obj);
1183    if ((!wd) || (!parent)) return;
1184
1185    _parent_cut_off(obj);
1186
1187    if (parent)
1188      {
1189         evas_object_event_callback_add(parent,
1190                                        EVAS_CALLBACK_DEL,
1191                                        _parent_del,
1192                                        obj);
1193         evas_object_event_callback_add(parent,
1194                                        EVAS_CALLBACK_MOVE,
1195                                        _parent_move,
1196                                        obj);
1197         evas_object_event_callback_add(parent,
1198                                        EVAS_CALLBACK_RESIZE,
1199                                        _parent_resize,
1200                                        obj);
1201      }
1202
1203    elm_widget_sub_object_add(parent, obj);
1204    wd->parent = parent;
1205
1206    //Update Background
1207    evas_object_geometry_get(parent, &x, &y, &w, &h);
1208    evas_object_move(wd->bg, x, y);
1209    evas_object_resize(wd->bg, w, h);
1210
1211    if (wd->visible) _sizing_eval(obj);
1212 }
1213
1214 EAPI Evas_Object *
1215 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1216 {
1217    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1218
1219    Widget_Data *wd;
1220
1221    wd = elm_widget_data_get(obj);
1222    if (!wd) return NULL;
1223
1224    return wd->parent;
1225 }
1226
1227 EAPI void
1228 elm_ctxpopup_clear(Evas_Object * obj)
1229 {
1230    ELM_CHECK_WIDTYPE(obj, widtype);
1231
1232    Widget_Data *wd = elm_widget_data_get(obj);
1233    if (!wd) return;
1234
1235    _remove_items(wd);
1236    _list_del(wd);
1237    wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1238 }
1239
1240 EAPI void
1241 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1242 {
1243    ELM_CHECK_WIDTYPE(obj, widtype);
1244
1245    Widget_Data *wd;
1246
1247    wd = elm_widget_data_get(obj);
1248    if (!wd) return;
1249
1250    wd->horizontal = !!horizontal;
1251
1252    if ((!wd->scr) && (!wd->box))
1253       return;
1254
1255    if (!horizontal)
1256      {
1257         elm_box_horizontal_set(wd->box, EINA_FALSE);
1258         elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1259      }
1260    else
1261      {
1262         elm_box_horizontal_set(wd->box, EINA_TRUE);
1263         elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1264      }
1265
1266    wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1267
1268    if (wd->visible)
1269       _sizing_eval(obj);
1270 }
1271
1272 EAPI Eina_Bool
1273 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1274 {
1275    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1276
1277    Widget_Data *wd;
1278
1279    wd = elm_widget_data_get(obj);
1280    if (!wd) return EINA_FALSE;
1281
1282    return wd->horizontal;
1283 }
1284
1285 EAPI Elm_Object_Item *
1286 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1287                          Evas_Object *icon, Evas_Smart_Cb func,
1288                          const void *data)
1289 {
1290    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1291
1292    Widget_Data *wd;
1293    Evas_Object *content;
1294    Elm_Ctxpopup_Item *item;
1295
1296    wd = elm_widget_data_get(obj);
1297    if (!wd) return NULL;
1298
1299    item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1300    if (!item) return NULL;
1301
1302    //The first item is appended.
1303    content = elm_object_content_unset(obj);
1304    if (content) evas_object_del(content);
1305
1306    if (!wd->items)
1307      _list_new(obj);
1308
1309    item->func = func;
1310    item->base.data = data;
1311
1312    if (icon && label)
1313      _item_new(item, "icon_text_style_item");
1314    else if (label)
1315      _item_new(item, "text_style_item");
1316    else
1317      _item_new(item, "icon_style_item");
1318
1319    _item_icon_set(item, icon);
1320    _item_label_set(item, label);
1321    elm_box_pack_end(wd->box, item->base.view);
1322    wd->items = eina_list_append(wd->items, item);
1323    wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1324
1325    if (wd->visible)
1326      {
1327         _scroller_size_reset(wd);
1328         _sizing_eval(obj);
1329      }
1330
1331    return ELM_CAST(item);
1332 }
1333
1334 EAPI void
1335 elm_ctxpopup_item_del(Elm_Object_Item *it)
1336 {
1337    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1338
1339    Widget_Data *wd;
1340    Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1341
1342    wd = elm_widget_data_get(ctxpopup_it->base.widget);
1343    if (!wd) return;
1344
1345    if (ctxpopup_it->icon)
1346       evas_object_del(ctxpopup_it->icon);
1347    if (ctxpopup_it->base.view)
1348      evas_object_del(ctxpopup_it->base.view);
1349
1350    eina_stringshare_del(ctxpopup_it->label);
1351
1352    wd->items = eina_list_remove(wd->items, ctxpopup_it);
1353
1354    if (eina_list_count(wd->items) < 1)
1355      wd->items = NULL;
1356
1357    wd->dir = ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1358
1359    if (wd->visible)
1360      _sizing_eval(ctxpopup_it->base.widget);
1361
1362    free(ctxpopup_it);
1363 }
1364
1365 EAPI void
1366 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1367 {
1368    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1369
1370    Widget_Data *wd;
1371    Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1372
1373    wd = elm_widget_data_get(ctxpopup_it->base.widget);
1374    if (!wd) return;
1375
1376    ctxpopup_it = ELM_CAST(it);
1377
1378    if (disabled == ctxpopup_it->disabled)
1379      return;
1380
1381    if (disabled)
1382      edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,disabled", "elm");
1383    else
1384      edje_object_signal_emit(ctxpopup_it->base.view, "elm,state,enabled", "elm");
1385
1386    ctxpopup_it->disabled = !!disabled;
1387 }
1388
1389 EAPI Eina_Bool
1390 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1391 {
1392    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1393    Elm_Ctxpopup_Item *ctxpopup_it = ELM_CAST(it);
1394    return ctxpopup_it->disabled;
1395 }
1396
1397 EAPI void
1398 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1399 {
1400    elm_object_content_set(obj, content);
1401 }
1402
1403 EAPI Evas_Object *
1404 elm_ctxpopup_content_unset(Evas_Object *obj)
1405 {
1406    return elm_object_content_unset(obj);
1407 }
1408
1409 EAPI void
1410 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1411                                     Elm_Ctxpopup_Direction first,
1412                                     Elm_Ctxpopup_Direction second,
1413                                     Elm_Ctxpopup_Direction third,
1414                                     Elm_Ctxpopup_Direction fourth)
1415 {
1416    ELM_CHECK_WIDTYPE(obj, widtype);
1417    Widget_Data *wd;
1418
1419    wd = elm_widget_data_get(obj);
1420    if (!wd) return;
1421
1422    wd->dir_priority[0] = first;
1423    wd->dir_priority[1] = second;
1424    wd->dir_priority[2] = third;
1425    wd->dir_priority[3] = fourth;
1426
1427    if (wd->visible)
1428      _sizing_eval(obj);
1429 }
1430
1431 EAPI void
1432 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1433                                     Elm_Ctxpopup_Direction *first,
1434                                     Elm_Ctxpopup_Direction *second,
1435                                     Elm_Ctxpopup_Direction *third,
1436                                     Elm_Ctxpopup_Direction *fourth)
1437 {
1438    ELM_CHECK_WIDTYPE(obj, widtype);
1439    Widget_Data *wd;
1440
1441    wd = elm_widget_data_get(obj);
1442    if (!wd) return;
1443
1444    if (first) *first = wd->dir_priority[0];
1445    if (second) *second = wd->dir_priority[1];
1446    if (third) *third = wd->dir_priority[2];
1447    if (fourth) *fourth = wd->dir_priority[3];
1448 }
1449
1450 EAPI Elm_Ctxpopup_Direction
1451 elm_ctxpopup_direction_get(const Evas_Object *obj)
1452 {
1453    ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1454    Widget_Data *wd;
1455
1456    wd = elm_widget_data_get(obj);
1457    if (!wd) return ELM_CTXPOPUP_DIRECTION_DONT_KNOW;
1458    return wd->dir;
1459 }