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