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