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