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