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