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