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