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