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