elementary / ctxpopup - modified doxygen smart object signal callbacks
[platform/upstream/elementary.git] / src / lib / elc_ctxpopup.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Ctxpopup
6  *
7  * A ctxpopup is a widget that, when shown, pops up a list of items.
8  * It automatically chooses an area inside its parent object's view
9  * (set via elm_ctxpopup_add() and elm_ctxpopup_hover_parent_set()) to
10  * optimally fit into it. In the default theme, it will also point an
11  * arrow to the cursor position at the time one shows it. Ctxpopup
12  * items have a label and/or an icon. It is intended for a small
13  * number of items (hence the use of list, not genlist).
14  *
15  * Signals that you can add callbacks for are:
16  *
17  * "dismissed" - the ctxpopup was dismissed
18  */
19
20 typedef struct _Widget_Data Widget_Data;
21
22 struct _Elm_Ctxpopup_Item
23 {
24    Elm_Widget_Item base;
25    const char *label;
26    Evas_Object *icon;
27    Evas_Smart_Cb func;
28    Eina_Bool disabled:1;
29 };
30
31 struct _Widget_Data
32 {
33    Evas_Object *parent;
34    Evas_Object *base;
35    Evas_Object *content;
36    Evas_Object *box;
37    Evas_Object *arrow;
38    Evas_Object *scr;
39    Evas_Object *bg;
40    Evas_Object *hover_parent;
41    Eina_List *items;
42    Elm_Ctxpopup_Direction dir;
43    Elm_Ctxpopup_Direction dir_priority[4];
44    Evas_Coord max_sc_w, max_sc_h;
45    Eina_Bool horizontal:1;
46    Eina_Bool visible:1;
47    Eina_Bool finished:1;
48 };
49
50 static const char *widtype = NULL;
51
52 static void _del_hook(Evas_Object *obj);
53 static void _del_pre_hook(Evas_Object *obj);
54 static void _theme_hook(Evas_Object *obj);
55 static void _sizing_eval(Evas_Object *obj);
56 static void _hover_parent_resize(void *data, Evas *e __UNUSED__,
57                                  Evas_Object *obj __UNUSED__,
58                                  void *event_info __UNUSED__);
59 static void _hover_parent_move(void *data, Evas *e __UNUSED__,
60                                Evas_Object *obj __UNUSED__,
61                                void *event_info __UNUSED__);
62 static void _hover_parent_del(void *data, Evas *e __UNUSED__,
63                               Evas_Object *obj __UNUSED__,
64                               void *event_info __UNUSED__);
65 static void _hover_parent_callbacks_del(Evas_Object *obj);
66 static void _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
67                            const char *emission __UNUSED__,
68                            const char *source __UNUSED__);
69 static void _parent_resize(void *data, Evas *e, Evas_Object *obj,
70                            void *event_info __UNUSED__);
71 static void _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__,
72                            Evas_Object *obj, void *event_info __UNUSED__);
73 static void _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__,
74                            Evas_Object *obj, void *event_info __UNUSED__);
75 static void _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__,
76                            Evas_Object *obj, void *event_info __UNUSED__);
77 static void _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
78                              void *event_info __UNUSED__);
79 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
80                                          Evas *e __UNUSED__, Evas_Object *obj,
81                                          void *event_info __UNUSED__);
82 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
83 static void _list_new(Evas_Object *obj);
84 static void _item_sizing_eval(Elm_Ctxpopup_Item *item);
85 static void _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
86                             const char *emission __UNUSED__,
87                             const char *source __UNUSED__);
88 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
89                                                   Evas_Coord_Rectangle *rect);
90 static void _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir);
91 static void _shift_base_by_arrow(Evas_Object *arrow,
92                                  Elm_Ctxpopup_Direction dir,
93                                  Evas_Coord_Rectangle *rect);
94 static void _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
95                           Evas_Coord_Rectangle *hover_area);
96 static void _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
97                           Evas_Coord_Rectangle *hover_area);
98 static void _scroller_size_reset(Widget_Data *wd);
99 static void _hide(Evas_Object *obj);
100 static void _content_del(void *data, Evas *e, Evas_Object *obj __UNUSED__,
101                          void *event_info __UNUSED__);
102 static void _freeze_on(void *data __UNUSED__, Evas_Object *obj,
103                        void *event_info __UNUSED__);
104 static void _freeze_off(void *data __UNUSED__, Evas_Object *obj,
105                         void *event_info __UNUSED__);
106 static void _hold_on(void *data __UNUSED__, Evas_Object *obj,
107                      void *event_info __UNUSED__);
108 static void _hold_off(void *data __UNUSED__, Evas_Object *obj,
109                       void *event_info __UNUSED__);
110 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
111 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
112 static void _remove_items(Widget_Data * wd);
113
114 static const char SIG_DISMISSED[] = "dismissed";
115
116 static const Evas_Smart_Cb_Description _signals[] = {
117    {SIG_DISMISSED, ""},
118    {NULL, NULL}
119 };
120
121 #define ELM_CTXPOPUP_ITEM_CHECK_RETURN(it, ...)                        \
122   ELM_WIDGET_ITEM_CHECK_OR_RETURN((Elm_Widget_Item *)it, __VA_ARGS__); \
123   ELM_CHECK_WIDTYPE(item->base.widget, widtype) __VA_ARGS__;
124
125 static void
126 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
127            void *event_info __UNUSED__)
128 {
129    Widget_Data *wd = elm_widget_data_get(obj);
130
131    if (!wd) return;
132    elm_object_scroll_freeze_push(wd->scr);
133 }
134
135 static void
136 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
137             void *event_info __UNUSED__)
138 {
139    Widget_Data *wd = elm_widget_data_get(obj);
140
141    if (!wd) return;
142    elm_object_scroll_freeze_pop(wd->scr);
143 }
144
145 static void
146 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
147 {
148    Widget_Data *wd = elm_widget_data_get(obj);
149
150    if (!wd) return;
151    elm_object_scroll_hold_push(wd->scr);
152 }
153
154 static void
155 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
156 {
157    Widget_Data *wd = elm_widget_data_get(obj);
158
159    if (!wd) return;
160    elm_object_scroll_hold_pop(wd->scr);
161 }
162
163 static void
164 _scroller_size_reset(Widget_Data *wd)
165 {
166    wd->finished = EINA_FALSE;
167    wd->max_sc_h = -1;
168    wd->max_sc_w = -1;
169 }
170
171 static void
172 _hover_parent_callbacks_del(Evas_Object *obj)
173 {
174    Widget_Data *wd = elm_widget_data_get(obj);
175
176    if ((!wd) || (!wd->hover_parent))
177       return;
178
179    evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_DEL,
180                                        _hover_parent_del, obj);
181    evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_MOVE,
182                                        _hover_parent_move, obj);
183    evas_object_event_callback_del_full(wd->hover_parent, EVAS_CALLBACK_RESIZE,
184                                        _hover_parent_resize, obj);
185 }
186
187 static void
188 _hover_parent_resize(void *data, Evas *e __UNUSED__,
189                      Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
190 {
191    Widget_Data *wd = elm_widget_data_get(data);
192
193    if (!wd) return;
194
195    if (wd->visible)
196      {
197         _scroller_size_reset(wd);
198         _sizing_eval(data);
199      }
200 }
201
202 static void
203 _hover_parent_move(void *data, Evas *e __UNUSED__,
204                    Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
205 {
206    Widget_Data *wd = elm_widget_data_get(data);
207
208    if (!wd) return;
209
210    if (wd->visible)
211      {
212         _scroller_size_reset(wd);
213         _sizing_eval(obj);
214      }
215 }
216
217 static void
218 _hover_parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
219                   void *event_info __UNUSED__)
220 {
221    Widget_Data *wd = elm_widget_data_get(data);
222
223    if (!wd) return;
224
225    wd->hover_parent = NULL;
226 }
227
228 static void
229 _item_sizing_eval(Elm_Ctxpopup_Item *item)
230 {
231    Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
232
233    if (!item) return;
234
235    edje_object_size_min_restricted_calc(item->base.view, &min_w, &min_h, min_w,
236                                         min_h);
237    evas_object_size_hint_min_set(item->base.view, min_w, min_h);
238    evas_object_size_hint_max_set(item->base.view, max_w, max_h);
239 }
240
241 static void
242 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
243               Evas_Coord_Rectangle *hover_area)
244 {
245    pos->x -= (base_size->x / 2);
246
247    if (pos->x < hover_area->x)
248       pos->x = hover_area->x;
249    else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
250       pos->x = (hover_area->x + hover_area->w) - base_size->x;
251
252    if (base_size->x > hover_area->w)
253       base_size->x -= (base_size->x - hover_area->w);
254
255    if (pos->x < hover_area->x)
256       pos->x = hover_area->x;
257 }
258
259 static void
260 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
261               Evas_Coord_Rectangle *hover_area)
262 {
263    pos->y -= (base_size->y / 2);
264
265    if (pos->y < hover_area->y)
266       pos->y = hover_area->y;
267    else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
268       pos->y = hover_area->y + hover_area->h - base_size->y;
269
270    if (base_size->y > hover_area->h)
271       base_size->y -= (base_size->y - hover_area->h);
272
273    if (pos->y < hover_area->y)
274       pos->y = hover_area->y;
275 }
276
277 static void
278 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
279                              Evas_Object *obj, void *event_info __UNUSED__)
280 {
281    Widget_Data *wd;
282
283    wd = elm_widget_data_get(obj);
284    if (!wd) return;
285
286    if (wd->visible)
287       _sizing_eval(obj);
288 }
289
290 static Elm_Ctxpopup_Direction
291 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
292 {
293    Widget_Data *wd;
294    Evas_Coord_Point pos = {0, 0};
295    Evas_Coord_Point base_size;
296    Evas_Coord_Point max_size;
297    Evas_Coord_Point min_size;
298    Evas_Coord_Rectangle hover_area;
299    Evas_Coord_Rectangle parent_size;
300    Evas_Coord_Point arrow_size;
301    Elm_Ctxpopup_Direction arrow = ELM_CTXPOPUP_DIRECTION_DOWN;
302    Evas_Coord_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      evas_object_del(item->icon);
815
816    item->icon = icon;
817    if (!icon) return;
818
819    edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
820    edje_object_message_signal_process(item->base.view);
821 }
822
823 static void
824 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
825 {
826    if (!eina_stringshare_replace(&item->label, label))
827       return;
828
829    edje_object_part_text_set(item->base.view, "elm.text", label);
830    edje_object_message_signal_process(item->base.view);
831 }
832
833 static void
834 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
835 {
836    Widget_Data *wd;
837
838    wd = elm_widget_data_get(item->base.widget);
839    if (!wd) return;
840
841    item->base.view = edje_object_add(evas_object_evas_get(wd->base));
842    _elm_theme_object_set(item->base.widget, item->base.view, "ctxpopup", group_name,
843                          elm_widget_style_get(item->base.widget));
844    edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
845                                    _item_select_cb, item);
846    evas_object_size_hint_align_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
847    evas_object_show(item->base.view);
848 }
849
850 static void
851 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
852              void *event_info __UNUSED__)
853 {
854    elm_ctxpopup_content_unset(data);
855 }
856
857 static void
858 _list_del(Widget_Data *wd)
859 {
860    if (!wd->scr) return;
861
862    edje_object_part_unswallow(wd->base, wd->scr);
863    evas_object_del(wd->scr);
864    wd->scr = NULL;
865    wd->box = NULL;
866 }
867
868 static void
869 _list_new(Evas_Object *obj)
870 {
871    Widget_Data *wd;
872    wd = elm_widget_data_get(obj);
873    if (!wd) return;
874
875    //scroller
876    wd->scr = elm_scroller_add(obj);
877    elm_object_style_set(wd->scr, "ctxpopup");
878    evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
879    evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
880                                   _scroller_resize, obj);
881    edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
882
883    //box
884    wd->box = elm_box_add(obj);
885    evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
886                                     EVAS_HINT_EXPAND);
887
888    elm_scroller_content_set(wd->scr, wd->box);
889    elm_ctxpopup_horizontal_set(obj, wd->horizontal);
890 }
891
892 static void
893 _remove_items(Widget_Data *wd)
894 {
895    Eina_List *elist;
896    Elm_Ctxpopup_Item *item;
897
898    if (!wd->items) return;
899
900    EINA_LIST_FOREACH(wd->items, elist, item)
901      {
902         if (item->label)
903            eina_stringshare_del(item->label);
904         if (item->icon)
905            evas_object_del(item->icon);
906         wd->items = eina_list_remove(wd->items, item);
907         free(item);
908      }
909
910    wd->items = NULL;
911 }
912
913 /**
914  * Add a new Ctxpopup object to the parent.
915  *
916  * @param parent Parent object
917  * @return New object or @c NULL, if it cannot be created
918  *
919  * @ingroup Ctxpopup
920  */
921 EAPI Evas_Object *
922 elm_ctxpopup_add(Evas_Object *parent)
923 {
924    Evas_Object *obj;
925    Evas *e;
926    Widget_Data *wd;
927    Evas_Coord x, y, w, h;
928
929    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
930
931    ELM_SET_WIDTYPE(widtype, "ctxpopup");
932    elm_widget_type_set(obj, "ctxpopup");
933    elm_widget_sub_object_add(parent, obj);
934    elm_widget_data_set(obj, wd);
935    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
936    elm_widget_del_hook_set(obj, _del_hook);
937    elm_widget_theme_hook_set(obj, _theme_hook);
938
939    wd->parent = parent;
940
941    //Background
942    wd->bg = edje_object_add(e);
943    elm_widget_sub_object_add(obj, wd->bg);
944    _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
945    evas_object_geometry_get(parent, &x, &y, &w, &h);
946    evas_object_move(wd->bg, x, y);
947    evas_object_resize(wd->bg, w, h);
948    edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
949                                    _bg_clicked_cb, obj);
950
951    //Base
952    wd->base = edje_object_add(e);
953    elm_widget_sub_object_add(obj, wd->base);
954    _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
955
956    //Arrow
957    wd->arrow = edje_object_add(e);
958    elm_widget_sub_object_add(obj, wd->arrow);
959    _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
960
961    wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
962    wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
963    wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
964    wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
965
966    evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
967                                   obj);
968    evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
969                                   NULL);
970    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
971                                   NULL);
972    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
973                                   NULL);
974    evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
975                                   _ctxpopup_changed_size_hints, NULL);
976    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
977    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
978    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
979    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
980
981    evas_object_smart_callbacks_descriptions_set(obj, _signals);
982
983    return obj;
984 }
985
986 /**
987  * Get the icon object for the given ctxpopup item.
988  *
989  * @param item Ctxpopup item
990  * @return icon object or @c NULL, if the item does not have icon or an error occurred
991  *
992  * @ingroup Ctxpopup
993  */
994 EAPI Evas_Object *
995 elm_ctxpopup_item_icon_get(const Elm_Ctxpopup_Item *item)
996 {
997    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
998    return item->icon;
999 }
1000
1001 /**
1002  * Sets the side icon associated with the ctxpopup item
1003  *
1004  * Once the icon object is set, a previously set one will be deleted.
1005  * You probably don't want, then, to have the <b>same</b> icon object
1006  * set for more than one item of the list (when replacing one of its
1007  * instances).
1008  *
1009  * @param item Ctxpopup item
1010  * @param icon Icon object to be set
1011  *
1012  * @ingroup Ctxpopup
1013  */
1014 EAPI void
1015 elm_ctxpopup_item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1016 {
1017    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1018
1019    Widget_Data *wd;
1020
1021    wd = elm_widget_data_get(item->base.widget);
1022    if (!wd) return;
1023
1024    _item_icon_set(item, icon);
1025
1026    if (wd->visible)
1027      {
1028         _scroller_size_reset(wd);
1029         _sizing_eval(item->base.widget);
1030      }
1031 }
1032
1033 /**
1034  * Get the label object for the given ctxpopup item.
1035  *
1036  * @param item Ctxpopup item
1037  * @return label object or @c NULL, if the item does not have label or an error occured
1038  *
1039  * @ingroup Ctxpopup
1040  *
1041  */
1042 EAPI const char *
1043 elm_ctxpopup_item_label_get(const Elm_Ctxpopup_Item *item)
1044 {
1045    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, NULL);
1046    return item->label;
1047 }
1048
1049 /**
1050  * (Re)set the label on the given ctxpopup item.
1051  *
1052  * @param item Ctxpopup item
1053  * @param label String to set as label
1054  *
1055  * @ingroup Ctxpopup
1056  */
1057 EAPI void
1058 elm_ctxpopup_item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1059 {
1060    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1061
1062    Widget_Data *wd;
1063
1064    wd = elm_widget_data_get(item->base.widget);
1065    if (!wd) return;
1066
1067    _item_label_set(item, label);
1068
1069    if (wd->visible)
1070      {
1071         _scroller_size_reset(wd);
1072         _sizing_eval(item->base.widget);
1073      }
1074 }
1075
1076 /**
1077  * Set the Ctxpopup's parent
1078  * Set the parent object (it would much probably be the
1079  * window that the ctxpopup is in).
1080  *
1081  * @param obj The ctxpopup object
1082  * @param area The parent to use
1083  *
1084  * @note elm_ctxpopup_add() will automatically call this function
1085  * with its @c parent argument.
1086  *
1087  * @ingroup Ctxpopup
1088  */
1089 EAPI void
1090 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *hover_parent)
1091 {
1092    ELM_CHECK_WIDTYPE(obj, widtype);
1093
1094    Widget_Data *wd;
1095
1096    wd = elm_widget_data_get(obj);
1097    if (!wd) return;
1098
1099    _hover_parent_callbacks_del(obj);
1100
1101    if (hover_parent)
1102      {
1103         evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_DEL,
1104                                        _hover_parent_del, obj);
1105         evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_MOVE,
1106                                        _hover_parent_move, obj);
1107         evas_object_event_callback_add(hover_parent, EVAS_CALLBACK_RESIZE,
1108                                        _hover_parent_resize, obj);
1109      }
1110
1111    wd->hover_parent = hover_parent;
1112 }
1113
1114 /**
1115  * Get the Ctxpopup's parent
1116  *
1117  * @param obj The ctxpopup object
1118  *
1119  * @see elm_ctxpopup_hover_parent_set() for more information
1120  *
1121  * @ingroup Ctxpopup
1122  */
1123 EAPI Evas_Object *
1124 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1125 {
1126    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1127
1128    Widget_Data *wd;
1129
1130    wd = elm_widget_data_get(obj);
1131    if (!wd) return NULL;
1132
1133    return wd->hover_parent;
1134 }
1135
1136 /**
1137  * Clear all items in the given ctxpopup object.
1138  *
1139  * @param obj Ctxpopup object
1140  *
1141  * @ingroup Ctxpopup
1142  */
1143 EAPI void
1144 elm_ctxpopup_clear(Evas_Object * obj)
1145 {
1146    ELM_CHECK_WIDTYPE(obj, widtype);
1147
1148    Widget_Data *wd = elm_widget_data_get(obj);
1149    if (!wd) return;
1150
1151    _remove_items(wd);
1152    _list_del(wd);
1153 }
1154
1155 /**
1156  * Change the ctxpopup's orientation to horizontal or vertical.
1157  *
1158  * @param obj Ctxpopup object
1159  * @param horizontal @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical
1160  *
1161  * @ingroup Ctxpopup
1162  */
1163 EAPI void
1164 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1165 {
1166    ELM_CHECK_WIDTYPE(obj, widtype);
1167
1168    Widget_Data *wd;
1169
1170    wd = elm_widget_data_get(obj);
1171    if (!wd) return;
1172
1173    wd->horizontal = !!horizontal;
1174
1175    if ((!wd->scr) && (!wd->box))
1176       return;
1177
1178    if (!horizontal)
1179      {
1180         elm_box_horizontal_set(wd->box, EINA_FALSE);
1181         elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1182      }
1183    else
1184      {
1185         elm_box_horizontal_set(wd->box, EINA_TRUE);
1186         elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1187      }
1188
1189    if (wd->visible)
1190       _sizing_eval(obj);
1191 }
1192
1193 /**
1194  * Get the value of current ctxpopup object's orientation.
1195  *
1196  * @param obj Ctxpopup object
1197  * @return @c EINA_TRUE for horizontal mode, @c EINA_FALSE for vertical mode (or errors)
1198  *
1199  * @ingroup Ctxpopup
1200  */
1201 EAPI Eina_Bool
1202 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1203 {
1204    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1205
1206    Widget_Data *wd;
1207
1208    wd = elm_widget_data_get(obj);
1209    if (!wd) return EINA_FALSE;
1210
1211    return wd->horizontal;
1212 }
1213
1214 /**
1215  * Add a new item to a ctxpopup object.
1216  *
1217  * Both a item list and a content could not be set at the same time!
1218  * once you set add a item, the previous content will be removed.
1219  *
1220  * @param obj Ctxpopup object
1221  * @param icon Icon to be set on new item
1222  * @param label The Label of the new item
1223  * @param func Convenience function called when item selected
1224  * @param data Data passed to @p func above
1225  * @return A handle to the item added or @c NULL, on errors
1226  *
1227  * @ingroup Ctxpopup
1228  */
1229 EAPI Elm_Ctxpopup_Item *
1230 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1231                          Evas_Object *icon, Evas_Smart_Cb func,
1232                          const void *data)
1233 {
1234    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1235
1236    Widget_Data *wd;
1237    Elm_Ctxpopup_Item *item;
1238
1239    wd = elm_widget_data_get(obj);
1240    if (!wd) return NULL;
1241
1242    item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1243    if (!item) return NULL;
1244
1245    //The first item is appended.
1246    if (wd->content)
1247       evas_object_del(elm_ctxpopup_content_unset(obj));
1248
1249    if (!wd->items)
1250       _list_new(obj);
1251
1252    item->func = func;
1253    item->base.data = data;
1254
1255    if (icon && label)
1256       _item_new(item, "icon_text_style_item");
1257    else if (label)
1258       _item_new(item, "text_style_item");
1259    else
1260       _item_new(item, "icon_style_item");
1261
1262    _item_icon_set(item, icon);
1263    _item_label_set(item, label);
1264    elm_box_pack_end(wd->box, item->base.view);
1265    wd->items = eina_list_append(wd->items, item);
1266
1267    if (wd->visible)
1268      {
1269         _scroller_size_reset(wd);
1270         _sizing_eval(obj);
1271      }
1272
1273    return item;
1274 }
1275
1276 /**
1277  * Delete the given item in a ctxpopup object.
1278  *
1279  * @param item Ctxpopup item to be deleted
1280  *
1281  * @ingroup Ctxpopup
1282  */
1283 EAPI void
1284 elm_ctxpopup_item_del(Elm_Ctxpopup_Item *item)
1285 {
1286    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1287
1288    Widget_Data *wd;
1289
1290    wd = elm_widget_data_get(item->base.widget);
1291    if (!wd) return;
1292
1293    if (item->icon)
1294       evas_object_del(item->icon);
1295    if (item->base.view)
1296       evas_object_del(item->base.view);
1297
1298    eina_stringshare_del(item->label);
1299
1300    wd->items = eina_list_remove(wd->items, item);
1301
1302    if (eina_list_count(wd->items) < 1)
1303       wd->items = NULL;
1304
1305    if (wd->visible)
1306       _sizing_eval(item->base.widget);
1307
1308    free(item);
1309 }
1310
1311 /**
1312  * Set the ctxpopup item's state as disabled or enabled.
1313  *
1314  * @param item Ctxpopup item to be enabled/disabled
1315  * @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable it
1316  *
1317  * @ingroup Ctxpopup
1318  */
1319 EAPI void
1320 elm_ctxpopup_item_disabled_set(Elm_Ctxpopup_Item *item, Eina_Bool disabled)
1321 {
1322    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item);
1323
1324    Widget_Data *wd;
1325
1326    wd = elm_widget_data_get(item->base.widget);
1327    if (!wd) return;
1328
1329    if (disabled == item->disabled)
1330       return;
1331
1332    if (disabled)
1333       edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
1334    else
1335       edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
1336
1337    item->disabled = !!disabled;
1338 }
1339
1340 /**
1341  * Get the ctxpopup item's disabled/enabled state.
1342  *
1343  * @param item Ctxpopup item to be enabled/disabled
1344  * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise
1345  *
1346  * @ingroup Ctxpopup
1347  */
1348 EAPI Eina_Bool
1349 elm_ctxpopup_item_disabled_get(const Elm_Ctxpopup_Item *item)
1350 {
1351    ELM_CTXPOPUP_ITEM_CHECK_RETURN(item, EINA_FALSE);
1352
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)
1494       *first = wd->dir_priority[0];
1495    if (second)
1496       *second = wd->dir_priority[1];
1497    if (third)
1498       *third = wd->dir_priority[2];
1499    if (fourth)
1500       *fourth = wd->dir_priority[3];
1501 }