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