warning--
[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 = {0, 0};
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 = ELM_CTXPOPUP_DIRECTION_DOWN;
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    _update_arrow(obj, wd->dir);
572    _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
573
574    //resize scroller according to final size. 
575    if (!wd->content)
576       evas_object_smart_calculate(wd->scr); 
577
578    evas_object_move(wd->base, rect.x, rect.y);
579    evas_object_resize(wd->base, rect.w, rect.h);
580 }
581
582 static void
583 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
584                      Evas_Coord_Rectangle *rect)
585 {
586    Evas_Coord arrow_w, arrow_h;
587
588    evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
589
590    switch (dir)
591      {
592       case ELM_CTXPOPUP_DIRECTION_LEFT:
593          rect->x += arrow_w;
594          break;
595       case ELM_CTXPOPUP_DIRECTION_RIGHT:
596          rect->x -= arrow_w;
597          break;
598       case ELM_CTXPOPUP_DIRECTION_UP:
599          rect->y += arrow_h;
600          break;
601       case ELM_CTXPOPUP_DIRECTION_DOWN:
602          rect->y -= arrow_h;
603          break;
604       default:
605          break;
606      }
607 }
608
609 static void
610 _del_pre_hook(Evas_Object *obj)
611 {
612    Widget_Data *wd;
613
614    wd = elm_widget_data_get(obj);
615    if (!wd)
616       return;
617
618    evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
619                                        _parent_resize, obj);
620
621    _hover_parent_callbacks_del(obj);
622 }
623
624 static void
625 _del_hook(Evas_Object *obj)
626 {
627    Widget_Data *wd;
628
629    wd = elm_widget_data_get(obj);
630    if (!wd)
631       return;
632
633    elm_ctxpopup_clear(obj);
634    evas_object_del(wd->arrow);
635    evas_object_del(wd->base);
636    free(wd);
637 }
638
639 static void
640 _theme_hook(Evas_Object *obj)
641 {
642    Widget_Data *wd;
643    Eina_List *elist;
644    Elm_Ctxpopup_Item *item;
645
646    wd = elm_widget_data_get(obj);
647    if (!wd)
648       return;
649
650    //Items
651    EINA_LIST_FOREACH(wd->items, elist, item)
652      {
653         if (item->label && item->icon)
654            _elm_theme_object_set(obj, item->base.view, "ctxpopup",
655                                  "icon_text_style_item",
656                                  elm_widget_style_get(obj));
657         else if (item->label)
658            _elm_theme_object_set(obj, item->base.view, "ctxpopup", "text_style_item",
659                                  elm_widget_style_get(obj));
660         else if (item->icon)
661            _elm_theme_object_set(obj, item->base.view, "ctxpopup", "icon_style_item",
662                                  elm_widget_style_get(obj));
663         if (item->label)
664            edje_object_part_text_set(item->base.view, "elm.text", item->label);
665
666         if (item->disabled)
667            edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
668
669         edje_object_message_signal_process(item->base.view);
670      }
671
672    _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
673                          elm_widget_style_get(obj));
674    _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
675                          elm_widget_style_get(obj));
676    _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
677                          elm_widget_style_get(obj));
678
679    if (!strncmp(elm_object_style_get(obj), "default", 
680                 strlen("default")))
681       elm_object_style_set(wd->scr, "ctxpopup");
682    else 
683       elm_object_style_set(wd->scr, elm_object_style_get(obj));
684
685    if (wd->visible)
686      {
687         _scroller_size_reset(wd);
688         _sizing_eval(obj);
689      }
690 }
691
692 static void
693 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
694                const char *emission __UNUSED__, const char *source __UNUSED__)
695 {
696    evas_object_hide(data);
697 }
698
699 static void
700 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
701                void *event_info __UNUSED__)
702 {
703    Evas_Coord w, h;
704    Widget_Data *wd;
705
706    wd = elm_widget_data_get(data);
707    if (!wd)
708       return;
709
710    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
711    evas_object_resize(wd->bg, w, h);
712
713    if (!wd->visible)
714       return;
715
716    _hide(data);
717 }
718
719 static void
720 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
721                void *event_info __UNUSED__)
722 {
723    Widget_Data *wd;
724
725    wd = elm_widget_data_get(obj);
726    if (!wd)
727       return;
728
729    if ((!wd->items) && (!wd->content))
730       return;
731
732    wd->visible = EINA_TRUE;
733
734    evas_object_show(wd->bg);
735    evas_object_show(wd->base);
736    evas_object_show(wd->arrow);
737
738    edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
739
740    _sizing_eval(obj);
741 }
742
743 static void
744 _hide(Evas_Object *obj)
745 {
746    Widget_Data *wd = elm_widget_data_get(obj);
747
748    if (!wd)
749       return;
750
751    evas_object_hide(wd->bg);
752    evas_object_hide(wd->arrow);
753    evas_object_hide(wd->base);
754
755    _scroller_size_reset(wd);
756
757    evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
758    wd->visible = EINA_FALSE;
759 }
760
761 static void
762 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
763                void *event_info __UNUSED__)
764 {
765    Widget_Data *wd;
766
767    wd = elm_widget_data_get(obj);
768    if (!wd)
769       return;
770
771    if (!wd->visible)
772       return;
773
774    _hide(obj);
775 }
776
777 static void
778 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
779                  void *event_info __UNUSED__)
780 {
781    Widget_Data *wd;
782    Evas_Coord w, h;
783
784    wd = elm_widget_data_get(data);
785    if (!wd)
786       return;
787
788    if (!wd->visible)
789       return;
790    if (wd->finished)
791       return;
792
793    evas_object_geometry_get(obj, 0, 0, &w, &h);
794
795    if (w != 0 && h != 0)
796      {
797         if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
798           {
799              _sizing_eval(data);
800              wd->finished = EINA_TRUE;
801              return;
802           }
803      }
804
805    if (wd->max_sc_w < w)
806       wd->max_sc_w = w;
807    if (wd->max_sc_h < h)
808       wd->max_sc_h = h;
809
810    _sizing_eval(data);
811 }
812
813 static void
814 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
815                void *event_info __UNUSED__)
816 {
817    Widget_Data *wd;
818
819    wd = elm_widget_data_get(obj);
820
821    if (!wd)
822       return;
823
824    if (wd->visible)
825       evas_object_show(wd->arrow);
826
827    _scroller_size_reset(wd);
828    _sizing_eval(obj);
829 }
830
831 static void
832 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
833                 const char *emission __UNUSED__, const char *source __UNUSED__)
834 {
835    Elm_Ctxpopup_Item *item = data;
836
837    if (!item)
838       return;
839    if (item->disabled)
840       return;
841
842    if (item->func)
843       item->func((void*) item->base.data, item->base.widget, data);
844 }
845
846 static void
847 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
848 {
849    if (item->icon)
850      {
851         elm_widget_sub_object_del(item->base.view, item->icon);
852         evas_object_del(item->icon);
853      }
854
855    item->icon = icon;
856    edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
857    edje_object_message_signal_process(item->base.view);
858 }
859
860 static void
861 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
862 {
863    if (!eina_stringshare_replace(&item->label, label))
864       return;
865
866    edje_object_part_text_set(item->base.view, "elm.text", label);
867    edje_object_message_signal_process(item->base.view);
868 }
869
870 static void
871 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
872 {
873    Widget_Data *wd;
874
875    wd = elm_widget_data_get(item->base.widget);
876    if (!wd)
877       return;
878
879    item->base.view = edje_object_add(evas_object_evas_get(wd->base));
880    _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
881                          elm_widget_style_get(item->base.widget));
882    edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
883                                    _item_select_cb, item);
884    evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
885    evas_object_show(item->base.view);
886 }
887
888 static void
889 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
890              void *event_info __UNUSED__)
891 {
892    elm_ctxpopup_content_unset(data);
893 }
894
895 static void
896 _list_del(Widget_Data *wd)
897 {
898    if (!wd->scr)
899       return;
900
901    edje_object_part_unswallow(wd->base, wd->scr);
902    evas_object_del(wd->scr);
903    wd->scr = NULL;
904    wd->box = NULL;
905 }
906
907 static void
908 _list_new(Evas_Object *obj)
909 {
910    Widget_Data *wd;
911    wd = elm_widget_data_get(obj);
912    if (!wd)
913       return;
914
915    //scroller
916    wd->scr = elm_scroller_add(obj);
917    elm_object_style_set(wd->scr, "ctxpopup");
918    evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
919    evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
920                                   _scroller_resize, obj);  
921    edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr); 
922
923    //box
924    wd->box = elm_box_add(obj);
925    evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
926                                     EVAS_HINT_EXPAND);
927
928    elm_scroller_content_set(wd->scr, wd->box);
929    elm_ctxpopup_horizontal_set(obj, wd->horizontal); 
930 }
931
932 /**
933  * Add a new Ctxpopup object to the parent.
934  *
935  * @param parent Parent object
936  * @return New object or @c NULL, if it cannot be created
937  *
938  * @ingroup Ctxpopup
939  */
940 EAPI Evas_Object *
941 elm_ctxpopup_add(Evas_Object *parent)
942 {
943    Evas_Object *obj;
944    Evas *e;
945    Widget_Data *wd;
946    Evas_Coord x, y, w, h;
947
948    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
949
950    wd = ELM_NEW(Widget_Data);
951    e = evas_object_evas_get(parent);
952    if (!e)
953       return NULL;
954    obj = elm_widget_add(e);
955    ELM_SET_WIDTYPE(widtype, "ctxpopup");
956    elm_widget_type_set(obj, "ctxpopup");
957    elm_widget_sub_object_add(parent, obj);
958    elm_widget_data_set(obj, wd);
959    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
960    elm_widget_del_hook_set(obj, _del_hook);
961    elm_widget_theme_hook_set(obj, _theme_hook);
962
963    wd->parent = parent;
964
965    //Background
966    wd->bg = edje_object_add(e);
967    elm_widget_sub_object_add(obj, wd->bg);
968    _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
969    evas_object_geometry_get(parent, &x, &y, &w, &h);
970    evas_object_move(wd->bg, x, y);
971    evas_object_resize(wd->bg, w, h);
972    edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
973                                    _bg_clicked_cb, obj);
974
975    //Base
976    wd->base = edje_object_add(e);
977    elm_widget_sub_object_add(obj, wd->base);
978    _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
979
980    //Arrow
981    wd->arrow = edje_object_add(e);
982    elm_widget_sub_object_add(obj, wd->arrow);
983    _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
984
985    wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
986    wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
987    wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
988    wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
989
990    evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
991                                   obj);
992    evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
993                                   NULL);
994    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
995                                   NULL);
996    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
997                                   NULL);
998    evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
999                                   _ctxpopup_changed_size_hints, NULL);
1000    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1001    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1002    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1003    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1004
1005    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1006
1007    return obj;
1008 }
1009
1010 /**
1011  * Get the icon object for the given ctxpopup item.
1012  *
1013  * @param item Ctxpopup item
1014  * @return icon object or @c NULL, if the item does not have icon or an error occurred
1015  *
1016  * @ingroup Ctxpopup
1017  */
1018 EAPI Evas_Object *
1019 elm_ctxpopup_item_icon_get(const Elm_Ctxpopup_Item *item)
1020 {
1021    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1022    return item->icon;
1023 }
1024
1025 /**
1026  * Sets the side icon associated with the ctxpopup item  
1027  *
1028  * Once the icon object is set, a previously set one will be deleted.
1029  * You probably don't want, then, to have the <b>same</b> icon object
1030  * set for more than one item of the list (when replacing one of its
1031  * instances).
1032  * 
1033  * @param item Ctxpopup item
1034  * @param icon  Icon object to be set
1035  *
1036  * @ingroup Ctxpopup
1037  */
1038 EAPI void
1039 elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1040 {
1041    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1042
1043    Widget_Data *wd;
1044
1045    wd = elm_widget_data_get(item->base.widget);
1046    if (!wd)
1047       return;
1048
1049    _item_icon_set(item, icon);
1050
1051    if (wd->visible)
1052      {
1053         _scroller_size_reset(wd);
1054         _sizing_eval(item->base.widget);
1055      }
1056 }
1057
1058 /**
1059  * Get the label object for the given ctxpopup item.
1060  *
1061  * @param item Ctxpopup item
1062  * @return label object or @c NULL, if the item does not have label or an error occured
1063  *
1064  * @ingroup Ctxpopup
1065  *
1066  */
1067 EAPI const char *
1068 elm_ctxpopup_item_label_get(const Elm_Ctxpopup_Item *item)
1069 {
1070    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1071    return item->label;
1072 }
1073
1074 /**
1075  * (Re)set the label on the given ctxpopup item.
1076  *
1077  * @param item Ctxpopup item
1078  * @param label String to set as label
1079  * 
1080  * @ingroup Ctxpopup
1081  */
1082 EAPI void
1083 elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1084 {
1085    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1086
1087    Widget_Data *wd;
1088
1089    wd = elm_widget_data_get(item->base.widget);
1090    if (!wd)
1091       return;
1092
1093    _item_label_set(item, label);
1094
1095    if (wd->visible)
1096      {
1097         _scroller_size_reset(wd);
1098         _sizing_eval(item->base.widget);
1099      }
1100 }
1101
1102 /**
1103  * Set the Ctxpopup's parent 
1104  * Set the parent object (it would much probably be the 
1105  * window that the ctxpopup is in).
1106  *
1107  * @param obj The ctxpopup object
1108  * @param area  The parent to use
1109  *
1110  * @note elm_ctxpopup_add() will automatically call this function
1111  * with its @c parent argument.
1112  *
1113  * @ingroup Ctxpopup
1114  */
1115 EAPI void
1116 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1117 {
1118    ELM_CHECK_WIDTYPE(obj, widtype);
1119
1120    Widget_Data *wd;
1121
1122    wd = elm_widget_data_get(obj);
1123    if (!wd)
1124       return;
1125
1126    _hover_parent_callbacks_del(obj);
1127
1128    if (hover_parent)
1129      {
1130         evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1131                                        _hover_parent_del, obj);
1132         evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1133                                        _hover_parent_move, obj);
1134         evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1135                                        _hover_parent_resize, obj);
1136      }
1137
1138    wd->hover_parent = hover_parent;
1139 }
1140
1141 /**
1142  * Get the Ctxpopup's parent 
1143  *
1144  * @param obj The ctxpopup object
1145  *
1146  * @see elm_ctxpopup_hover_parent_set() for more information
1147  *
1148  * @ingroup Ctxpopup
1149  */
1150 EAPI Evas_Object *
1151 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1152 {
1153    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1154
1155    Widget_Data *wd;
1156
1157    wd = elm_widget_data_get(obj);
1158    if (!wd)
1159       return NULL;
1160
1161    return wd->hover_parent;
1162 }
1163
1164 static void
1165 _remove_items(Widget_Data *wd)
1166 {
1167    Eina_List *elist;
1168    Elm_Ctxpopup_Item *item;
1169
1170    if (!wd->items)
1171       return;
1172
1173    EINA_LIST_FOREACH(wd->items, elist, item)
1174      {
1175         if (item->label)
1176            eina_stringshare_del(item->label);
1177         if (item->icon)
1178            evas_object_del(item->icon);
1179         wd->items = eina_list_remove(wd->items, item);
1180         free(item);
1181      }
1182
1183    wd->items = NULL;
1184 }
1185
1186 /**
1187  * Clear all items in the given ctxpopup object.
1188  *
1189  * @param obj Ctxpopup object
1190  *
1191  * @ingroup Ctxpopup
1192  */
1193 EAPI void
1194 elm_ctxpopup_clear(Evas_Object * obj)
1195 {
1196    ELM_CHECK_WIDTYPE(obj, widtype);
1197
1198    Widget_Data *wd = elm_widget_data_get(obj);
1199
1200    if (!wd)
1201       return;
1202
1203    _remove_items(wd);
1204    _list_del(wd);
1205 }
1206
1207 /**
1208  * Change the ctxpopup's orientation to horizontal or vertical.
1209  *
1210  * @param obj Ctxpopup object
1211  * @param horizontal @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical
1212  *
1213  * @ingroup Ctxpopup
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
1222    wd = elm_widget_data_get(obj);
1223    if (!wd)
1224       return;
1225
1226    wd->horizontal = !!horizontal;
1227
1228    if ((!wd->scr) && (!wd->box))
1229       return;
1230
1231    if (!horizontal)
1232      {
1233         elm_box_horizontal_set(wd->box, EINA_FALSE);
1234         elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1235      }
1236    else
1237      {
1238         elm_box_horizontal_set(wd->box, EINA_TRUE);
1239         elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1240      }
1241
1242    if (wd->visible)
1243       _sizing_eval(obj);
1244 }
1245
1246 /**
1247  * Get the value of current ctxpopup object's orientation.
1248  *
1249  * @param obj Ctxpopup object
1250  * @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical mode (or errors)
1251  *
1252  * @ingroup Ctxpopup
1253  */
1254 EAPI Eina_Bool
1255 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1256 {
1257    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1258
1259    Widget_Data *wd;
1260
1261    wd = elm_widget_data_get(obj);
1262    if (!wd)
1263       return EINA_FALSE;
1264
1265    return wd->horizontal;
1266 }
1267
1268 /**
1269  * Add a new item to a ctxpopup object.
1270  *
1271  * Both a item list and a content could not be set at the same time!
1272  * once you set add a item, the previous content will be removed. 
1273  *
1274  * @param obj Ctxpopup object
1275  * @param icon Icon to be set on new item 
1276  * @param label The Label of the new item 
1277  * @param func Convenience function called when item selected
1278  * @param data Data passed to @p func above
1279  * @return A handle to the item added or @c NULL, on errors
1280  * 
1281  * @ingroup Ctxpopup
1282  */
1283 EAPI Elm_Ctxpopup_Item *
1284 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1285                          Evas_Object *icon, Evas_Smart_Cb func,
1286                          const void *data)
1287 {
1288    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1289
1290    Widget_Data *wd;
1291    Elm_Ctxpopup_Item *item;
1292
1293    wd = elm_widget_data_get(obj);
1294    if (!wd)
1295       return NULL;
1296
1297    item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1298    if (!item)
1299       return NULL;
1300
1301    //The first item is appended.
1302    if (wd->content)
1303       evas_object_del(elm_ctxpopup_content_unset(obj));
1304
1305    if (!wd->items)
1306       _list_new(obj);
1307
1308    item->func = func;
1309    item->base.data = data;
1310
1311    if (icon && label)
1312       _item_new(item, "icon_text_style_item");
1313    else if (label)
1314       _item_new(item, "text_style_item");
1315    else 
1316       _item_new(item, "icon_style_item");
1317
1318    _item_icon_set(item, icon);
1319    _item_label_set(item, label);
1320    elm_box_pack_end(wd->box, item->base.view);
1321    wd->items = eina_list_append(wd->items, item);
1322
1323    if (wd->visible)
1324      {
1325         _scroller_size_reset(wd);
1326         _sizing_eval(obj);
1327      }
1328
1329    return item;
1330 }
1331
1332 /**
1333  * Delete the given item in a ctxpopup object.
1334  *
1335  * @param item Ctxpopup item to be deleted
1336  *
1337  * @ingroup Ctxpopup
1338  */
1339 EAPI void
1340 elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item)
1341 {
1342    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1343
1344    Widget_Data *wd;
1345
1346    wd = elm_widget_data_get(item->base.widget);
1347    if (!wd)
1348       return;
1349
1350    if (item->icon)
1351       evas_object_del(item->icon);
1352    if (item->base.view)
1353       evas_object_del(item->base.view);
1354
1355    eina_stringshare_del(item->label);
1356
1357    wd->items = eina_list_remove(wd->items, item);
1358
1359    if (eina_list_count(wd->items) < 1)
1360       wd->items = NULL;
1361
1362    if (wd->visible)
1363       _sizing_eval(item->base.widget);
1364
1365    free(item);
1366 }
1367
1368 /**
1369  * Set the ctxpopup item's state as disabled or enabled.
1370  *
1371  * @param item Ctxpopup item to be enabled/disabled
1372  * @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable it
1373  *
1374  * @ingroup Ctxpopup
1375  */
1376 EAPI void
1377 elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, Eina_Bool disabled)
1378 {
1379    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1380
1381    Widget_Data *wd;
1382
1383    wd = elm_widget_data_get(item->base.widget);
1384    if (!wd)
1385       return;
1386
1387    if (disabled == item->disabled)
1388       return;
1389
1390    if (disabled)
1391       edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1392    else
1393       edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1394
1395    item->disabled = !!disabled;
1396 }
1397
1398 /**
1399  * Get the ctxpopup item's disabled/enabled state.
1400  *
1401  * @param item Ctxpopup item to be enabled/disabled
1402  * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
1403  *
1404  * @ingroup Ctxpopup
1405  */
1406 EAPI Eina_Bool
1407 elm_ctxpopup_item_disabled_get(const Elm_Ctxpopup_Item *item)
1408 {
1409    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, EINA_FALSE);
1410
1411    return item->disabled;
1412 }
1413
1414 /**
1415  * Once the content object is set, a previously set one will be deleted.
1416  * If you want to keep that old content object, use the 
1417  * elm_ctxpopup_content_unset() function
1418  * 
1419  * Both a item list and a content could not be set at the same time!
1420  * once you set a content, the previous list items will be removed. 
1421  *
1422  * @param obj Ctxpopup object
1423  * @param content       Content to be swallowed
1424  *
1425  * @ingroup Ctxpopup
1426  */
1427 EAPI void
1428 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1429 {
1430    ELM_CHECK_WIDTYPE(obj, widtype);
1431
1432    Widget_Data *wd;
1433
1434    wd = elm_widget_data_get(obj);
1435    if ((!wd) || (!content))
1436       return;
1437
1438    if (wd->items)
1439       elm_ctxpopup_clear(obj);
1440
1441    if (wd->content)
1442       evas_object_del(wd->content);
1443
1444    evas_object_event_callback_add(content, EVAS_CALLBACK_DEL, _content_del,
1445                                   obj);
1446
1447    elm_widget_sub_object_add(obj, content);
1448    edje_object_part_swallow(wd->base, "elm.swallow.content", content);
1449    edje_object_message_signal_process(wd->base);
1450
1451    wd->content = content;
1452
1453    if (wd->visible)
1454       _sizing_eval(obj);
1455 }
1456
1457 /**
1458  * Unset the ctxpopup content
1459  *
1460  * Unparent and return the content object which was set for this widget
1461  * 
1462  * @param obj Ctxpopup object
1463  * @return The content that was being used
1464  *
1465  * @ingroup Ctxpopup
1466  */
1467 EAPI Evas_Object *
1468 elm_ctxpopup_content_unset(Evas_Object *obj)
1469 {
1470    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1471
1472    Widget_Data *wd;
1473    Evas_Object *content;
1474
1475    wd = elm_widget_data_get(obj);
1476    if (!wd)
1477       return NULL;
1478
1479    content = wd->content;
1480    if (!content)
1481       return NULL;
1482
1483    edje_object_part_unswallow(wd->base, content);
1484    elm_widget_sub_object_del(obj, content);
1485    evas_object_event_callback_del(content, EVAS_CALLBACK_DEL, _content_del);
1486    edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1487
1488    wd->content = NULL;
1489
1490    return content;
1491 }
1492
1493 /**
1494  * Set the direction priority of a ctxpopup.
1495  * This functions gives a chance to user to set the priority of ctxpopup showing direction.
1496  *
1497  * @param obj Ctxpopup object
1498  * @param first 1st priority of direction
1499  * @param second 2nd priority of direction
1500  * @param third 3th priority of direction
1501  * @param fourth 4th priority of direction
1502  *
1503  * @ingroup Ctxpopup
1504  */
1505 EAPI void
1506 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1507                                     Elm_Ctxpopup_Direction first,
1508                                     Elm_Ctxpopup_Direction second,
1509                                     Elm_Ctxpopup_Direction third,
1510                                     Elm_Ctxpopup_Direction fourth)
1511 {
1512    ELM_CHECK_WIDTYPE(obj, widtype);
1513    Widget_Data *wd;
1514
1515    wd = elm_widget_data_get(obj);
1516    if (!wd)
1517       return;
1518
1519    wd->dir_priority[0] = first;
1520    wd->dir_priority[1] = second;
1521    wd->dir_priority[2] = third;
1522    wd->dir_priority[3] = fourth;
1523
1524    if (wd->visible)
1525       _sizing_eval(obj);
1526 }
1527
1528 /**
1529  * Get the direction priority of a ctxpopup.
1530  *
1531  * @param obj Ctxpopup object
1532  * @param first 1st priority of direction to be returned
1533  * @param second 2nd priority of direction to be returned 
1534  * @param third 3th priority of direction to be returned 
1535  * @param fourth 4th priority of direction to be returned 
1536  *
1537  * @see elm_ctxpopup_direction_priority_set for more information.
1538  * 
1539  * @ingroup Ctxpopup
1540  */
1541 EAPI void
1542 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1543                                     Elm_Ctxpopup_Direction *first,
1544                                     Elm_Ctxpopup_Direction *second,
1545                                     Elm_Ctxpopup_Direction *third,
1546                                     Elm_Ctxpopup_Direction *fourth)
1547 {
1548    ELM_CHECK_WIDTYPE(obj, widtype);
1549    Widget_Data *wd;
1550
1551    wd = elm_widget_data_get(obj);
1552    if (!wd)
1553       return;
1554
1555    if (first)
1556       *first = wd->dir_priority[0];
1557    if (second)
1558       *second = wd->dir_priority[1];
1559    if (third)
1560       *third = wd->dir_priority[2];
1561    if (fourth)
1562       *fourth = wd->dir_priority[3];
1563 }