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