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