Merge branch 'intefl/svn_merge' of ssh://165.213.149.219:21922/slp/pkgs/e/elementary...
[framework/uifw/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;
10    const char *label;
11    Evas_Object *icon;
12    Evas_Smart_Cb func;
13 };
14
15 struct _Widget_Data
16 {
17    Evas_Object *parent;
18    Evas_Object *base;
19    Evas_Object *content;
20    Evas_Object *box;
21    Evas_Object *arrow;
22    Evas_Object *scr;
23    Evas_Object *bg;
24    Eina_List *items;
25    Elm_Ctxpopup_Direction dir;
26    Elm_Ctxpopup_Direction dir_priority[4];
27    Evas_Coord max_sc_w, max_sc_h;
28    Eina_Bool horizontal:1;
29    Eina_Bool visible:1;
30    Eina_Bool finished:1;
31 };
32
33 static const char *widtype = NULL;
34
35 static void _freeze_on(void *data, Evas_Object *obj, void *event_info);
36 static void _freeze_off(void *data, Evas_Object *obj, void *event_info);
37 static void _hold_on(void *data, Evas_Object *obj, void *event_info);
38 static void _hold_off(void *data, Evas_Object *obj, void *event_info);
39 static void _scroller_size_reset(Widget_Data *wd);
40 static void _on_focus_hook(void *data, Evas_Object *obj);
41 static Eina_Bool _event_hook(Evas_Object *obj,
42                              Evas_Object *src,
43                              Evas_Callback_Type type,
44                              void *event_info);
45 static void _parent_cut_off(Evas_Object *obj);
46 static void _parent_resize(void *data,
47                            Evas *e,
48                            Evas_Object *obj,
49                            void *event_info);
50 static void _parent_move(void *data,
51                          Evas *e,
52                          Evas_Object *obj,
53                          void *event_info);
54 static void _parent_del(void *data,
55                         Evas *e,
56                         Evas_Object *obj,
57                         void *event_info);
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 <<<<<<< HEAD
66 static void _ctxpopup_changed_size_hints(void *data __UNUSED__,
67                                          Evas *e __UNUSED__, Evas_Object *obj,
68                                          void *event_info __UNUSED__);
69 =======
70 >>>>>>> remotes/origin/upstream
71 static Elm_Ctxpopup_Direction _calc_base_geometry(Evas_Object *obj,
72                                                   Evas_Coord_Rectangle *rect);
73 static void _update_arrow(Evas_Object *obj,
74                           Elm_Ctxpopup_Direction dir,
75                           Evas_Coord_Rectangle rect);
76 static void _sizing_eval(Evas_Object *obj);
77 <<<<<<< HEAD
78 =======
79 static void _hide_signal_emit(Evas_Object *obj,
80                               Elm_Ctxpopup_Direction dir);
81 static void _show_signal_emit(Evas_Object *obj,
82                               Elm_Ctxpopup_Direction dir);
83 >>>>>>> remotes/origin/upstream
84 static void _shift_base_by_arrow(Evas_Object *arrow,
85                                  Elm_Ctxpopup_Direction dir,
86                                  Evas_Coord_Rectangle *rect);
87 static void _del_pre_hook(Evas_Object *obj);
88 static void _del_hook(Evas_Object *obj);
89 static void _theme_hook(Evas_Object *obj);
90 static void _content_set_hook(Evas_Object *obj,
91                               const char *part,
92                               Evas_Object *content);
93 static Evas_Object * _content_unset_hook(Evas_Object *obj,
94                                          const char *part__);
95 static Evas_Object * _content_get_hook(const Evas_Object *obj,
96                                        const char *part);
97 static void _item_text_set_hook(Elm_Object_Item *it,
98                                const char *part,
99                                const char *label);
100 static const char * _item_text_get_hook(const Elm_Object_Item *it,
101                                         const char *part);
102 static void _item_content_set_hook(Elm_Object_Item *it,
103                                    const char *part,
104                                    Evas_Object *content);
105 static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it,
106                                             const char *part);
107 static void _item_disable_hook(Elm_Object_Item *it);
108 static void _item_signal_emit_hook(Elm_Object_Item *it,
109                                    const char *emission,
110                                    const char *source);
111 static void _bg_clicked_cb(void *data, Evas_Object *obj,
112                            const char *emission,
113                            const char *source);
114 static void _ctxpopup_show(void *data,
115                            Evas *e,
116                            Evas_Object *obj,
117                            void *event_info);
118 <<<<<<< HEAD
119 =======
120 static void _hide_finished(void *data,
121                            Evas_Object *obj,
122                            const char *emission,
123                            const char *source __UNUSED__);
124 >>>>>>> remotes/origin/upstream
125 static void _hide(Evas_Object *obj);
126 static void _ctxpopup_hide(void *data,
127                            Evas *e,
128                            Evas_Object *obj,
129                            void *event_info);
130 static void _content_resize(void *data,
131                             Evas *e,
132                             Evas_Object *obj,
133                             void *event_info);
134 static void _scroller_resize(void *data,
135                              Evas *e,
136                              Evas_Object *obj,
137                              void *event_info);
138 static void _ctxpopup_move(void *data,
139                            Evas *e,
140                            Evas_Object *obj,
141                            void *event_info);
142 static void _restack(void *data, Evas *e, Evas_Object *obj, void *event_info);
143 static void _item_select_cb(void *data, Evas_Object *obj,
144                             const char *emission,
145                             const char *source);
146 static void _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon);
147 static void _item_label_set(Elm_Ctxpopup_Item *item, const char *label);
148 static void _item_new(Elm_Ctxpopup_Item *item, char *group_name);
149 static void _content_del(void *data,
150                          Evas *e,
151                          Evas_Object *obj,
152                          void *event_info);
153 static void _list_del(Widget_Data *wd);
154 static void _list_new(Evas_Object *obj);
155 static void _remove_items(Widget_Data * wd);
156
157 static const char SIG_DISMISSED[] = "dismissed";
158
159 static const Evas_Smart_Cb_Description _signals[] = {
160    {SIG_DISMISSED, ""},
161    {NULL, NULL}
162 };
163
164 static void
165 _freeze_on(void *data __UNUSED__, Evas_Object *obj,
166            void *event_info __UNUSED__)
167 {
168    Widget_Data *wd = elm_widget_data_get(obj);
169
170    if ((!wd) || (!wd->scr)) return;
171    elm_object_scroll_freeze_push(wd->scr);
172 }
173
174 static void
175 _freeze_off(void *data __UNUSED__, Evas_Object *obj,
176             void *event_info __UNUSED__)
177 {
178    Widget_Data *wd = elm_widget_data_get(obj);
179
180    if ((!wd) || (!wd->scr)) return;
181    elm_object_scroll_freeze_pop(wd->scr);
182 }
183
184 static void
185 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
186 {
187    Widget_Data *wd = elm_widget_data_get(obj);
188
189    if ((!wd) || (!wd->scr)) return;
190    elm_object_scroll_hold_push(wd->scr);
191 }
192
193 static void
194 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
195 {
196    Widget_Data *wd = elm_widget_data_get(obj);
197
198    if ((!wd) || (!wd->scr)) return;
199    elm_object_scroll_hold_pop(wd->scr);
200 }
201
202 static void
203 _scroller_size_reset(Widget_Data *wd)
204 {
205    wd->finished = EINA_FALSE;
206    wd->max_sc_h = -1;
207    wd->max_sc_w = -1;
208 }
209
210 static void
211 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
212 {
213    Widget_Data *wd = elm_widget_data_get(obj);
214    if (!wd) return;
215
216    if (elm_widget_focus_get(obj))
217      {
218         //FIXME:
219      }
220    else
221      {
222         //FIXME:
223      }
224 }
225
226 static Eina_Bool
227 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
228             Evas_Callback_Type type, void *event_info)
229 {
230    Evas_Event_Key_Down *ev;
231    Widget_Data *wd;
232
233    if (type != EVAS_CALLBACK_KEY_DOWN)
234      return EINA_FALSE;
235    wd = elm_widget_data_get(obj);
236    if (!wd) return EINA_FALSE;
237
238    ev = event_info;
239    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
240    if (strcmp(ev->keyname, "Escape")) return EINA_FALSE;
241
242    evas_object_hide(obj);
243    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
244    return EINA_TRUE;
245 }
246
247 static void
248 _parent_cut_off(Evas_Object *obj)
249 {
250    Widget_Data *wd = elm_widget_data_get(obj);
251
252    if (!wd) return;
253
254    evas_object_event_callback_del_full(wd->parent,
255                                        EVAS_CALLBACK_DEL,
256                                        _parent_del,
257                                        obj);
258    evas_object_event_callback_del_full(wd->parent,
259                                        EVAS_CALLBACK_MOVE,
260                                        _parent_move,
261                                        obj);
262    evas_object_event_callback_del_full(wd->parent,
263                                        EVAS_CALLBACK_RESIZE,
264                                        _parent_resize,
265                                        obj);
266
267    elm_widget_sub_object_del(wd->parent, obj);
268 }
269
270 static void
271 _parent_resize(void *data,
272                Evas *e __UNUSED__,
273                Evas_Object *obj __UNUSED__,
274                void *event_info __UNUSED__)
275 {
276    Widget_Data *wd = elm_widget_data_get(data);
277    if (!wd) return;
278
279    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
280
281    _hide(data);
282 }
283
284 static void
285 _parent_move(void *data,
286              Evas *e __UNUSED__,
287              Evas_Object *obj __UNUSED__,
288              void *event_info __UNUSED__)
289 {
290    Widget_Data *wd = elm_widget_data_get(data);
291
292    if (!wd) return;
293
294    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
295
296    if (wd->visible)
297      {
298         _scroller_size_reset(wd);
299         _sizing_eval(obj);
300      }
301 }
302
303 static void
304 _parent_del(void *data,
305             Evas *e __UNUSED__,
306             Evas_Object *obj __UNUSED__,
307             void *event_info __UNUSED__)
308 {
309    evas_object_del(data);
310 }
311
312 static void
313 _item_sizing_eval(Elm_Ctxpopup_Item *item)
314 {
315    Evas_Coord min_w = -1, min_h = -1, max_w = -1, max_h = -1;
316
317    if (!item) return;
318
319    edje_object_size_min_restricted_calc(VIEW(item), &min_w, &min_h, min_w,
320                                         min_h);
321    evas_object_size_hint_min_set(VIEW(item), min_w, min_h);
322    evas_object_size_hint_max_set(VIEW(item), max_w, max_h);
323 }
324
325 static void
326 _adjust_pos_x(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
327               Evas_Coord_Rectangle *hover_area)
328 {
329    pos->x -= (base_size->x / 2);
330
331    if (pos->x < hover_area->x)
332      pos->x = hover_area->x;
333    else if ((pos->x + base_size->x) > (hover_area->x + hover_area->w))
334      pos->x = (hover_area->x + hover_area->w) - base_size->x;
335
336    if (base_size->x > hover_area->w)
337      base_size->x -= (base_size->x - hover_area->w);
338
339    if (pos->x < hover_area->x)
340      pos->x = hover_area->x;
341 }
342
343 static void
344 _adjust_pos_y(Evas_Coord_Point *pos, Evas_Coord_Point *base_size,
345               Evas_Coord_Rectangle *hover_area)
346 {
347    pos->y -= (base_size->y / 2);
348
349    if (pos->y < hover_area->y)
350      pos->y = hover_area->y;
351    else if ((pos->y + base_size->y) > (hover_area->y + hover_area->h))
352      pos->y = hover_area->y + hover_area->h - base_size->y;
353
354    if (base_size->y > hover_area->h)
355      base_size->y -= (base_size->y - hover_area->h);
356
357    if (pos->y < hover_area->y)
358      pos->y = hover_area->y;
359 }
360
361 <<<<<<< HEAD
362 static void
363 _ctxpopup_changed_size_hints(void *data __UNUSED__, Evas *e __UNUSED__,
364                              Evas_Object *obj, void *event_info __UNUSED__)
365 {
366    Widget_Data *wd;
367
368    wd = elm_widget_data_get(obj);
369    if (!wd) return;
370
371    if (wd->visible)
372       _sizing_eval(obj);
373 }
374
375 =======
376 >>>>>>> remotes/origin/upstream
377 static Elm_Ctxpopup_Direction
378 _calc_base_geometry(Evas_Object *obj, Evas_Coord_Rectangle *rect)
379 {
380    Widget_Data *wd;
381    Evas_Coord_Point pos = {0, 0};
382    Evas_Coord_Point base_size;
383    Evas_Coord_Point max_size;
384    Evas_Coord_Point min_size;
385    Evas_Coord_Rectangle hover_area;
386    Evas_Coord_Point arrow_size;
387    Elm_Ctxpopup_Direction dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
388    Evas_Coord_Point temp;
389    int idx;
390
391    wd = elm_widget_data_get(obj);
392
393    if ((!wd) || (!rect))
394      return ELM_CTXPOPUP_DIRECTION_DOWN;
395
396    edje_object_part_geometry_get(wd->arrow, "ctxpopup_arrow", NULL, NULL,
397                                  &arrow_size.x, &arrow_size.y);
398    evas_object_resize(wd->arrow, arrow_size.x, arrow_size.y);
399
400    //Initialize Area Rectangle.
401    evas_object_geometry_get(wd->parent,
402                             &hover_area.x,
403                             &hover_area.y,
404                             &hover_area.w,
405                             &hover_area.h);
406
407    evas_object_geometry_get(obj, &pos.x, &pos.y, NULL, NULL);
408
409    //recalc the edje
410    edje_object_size_min_calc(wd->base, &base_size.x, &base_size.y);
411    evas_object_smart_calculate(wd->base);
412
413    //Limit to Max Size
414    evas_object_size_hint_max_get(obj, &max_size.x, &max_size.y);
415
416    if ((max_size.y > 0) && (base_size.y > max_size.y))
417      base_size.y = max_size.y;
418
419    if ((max_size.x > 0) && (base_size.x > max_size.x))
420      base_size.x = max_size.x;
421
422    //Limit to Min Size
423    evas_object_size_hint_min_get(obj, &min_size.x, &min_size.y);
424
425    if ((min_size.y > 0) && (base_size.y < min_size.y))
426      base_size.y = min_size.y;
427
428    if ((min_size.x > 0) && (base_size.x < min_size.x))
429      base_size.x = min_size.x;
430
431    //Check the Which direction is available.
432    //If find a avaialble direction, it adjusts position and size.
433    for (idx = 0; idx < 4; idx++)
434      {
435         switch (wd->dir_priority[idx])
436           {
437            case ELM_CTXPOPUP_DIRECTION_UNKNOWN:
438            case ELM_CTXPOPUP_DIRECTION_UP:
439               temp.y = (pos.y - base_size.y);
440               if ((temp.y - arrow_size.y) < hover_area.y)
441                 continue;
442               _adjust_pos_x(&pos, &base_size, &hover_area);
443               pos.y -= base_size.y;
444               dir = ELM_CTXPOPUP_DIRECTION_UP;
445               break;
446            case ELM_CTXPOPUP_DIRECTION_LEFT:
447               temp.x = (pos.x - base_size.x);
448               if ((temp.x - arrow_size.x) < hover_area.x)
449                 continue;
450               _adjust_pos_y(&pos, &base_size, &hover_area);
451               pos.x -= base_size.x;
452               dir = ELM_CTXPOPUP_DIRECTION_LEFT;
453               break;
454            case ELM_CTXPOPUP_DIRECTION_RIGHT:
455               temp.x = (pos.x + base_size.x);
456               if ((temp.x + arrow_size.x) >
457                   (hover_area.x + hover_area.w))
458                 continue;
459               _adjust_pos_y(&pos, &base_size, &hover_area);
460               dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
461               break;
462            case ELM_CTXPOPUP_DIRECTION_DOWN:
463               temp.y = (pos.y + base_size.y);
464               if ((temp.y + arrow_size.y) >
465                   (hover_area.y + hover_area.h))
466                 continue;
467               _adjust_pos_x(&pos, &base_size, &hover_area);
468               dir = ELM_CTXPOPUP_DIRECTION_DOWN;
469               break;
470            default:
471               break;
472           }
473         break;
474      }
475
476    //In this case, all directions are invalid because of lack of space.
477    if (idx == 4)
478      {
479         Evas_Coord length[2];
480
481         if(!wd->horizontal)
482           {
483              length[0] = pos.y - hover_area.y;
484              length[1] = (hover_area.y + hover_area.h) - pos.y;
485
486              // ELM_CTXPOPUP_DIRECTION_UP
487              if (length[0] > length[1])
488                {
489                   _adjust_pos_x(&pos, &base_size, &hover_area);
490                   pos.y -= base_size.y;
491                   dir = ELM_CTXPOPUP_DIRECTION_UP;
492                   if (pos.y < (hover_area.y + arrow_size.y))
493                     {
494                        base_size.y -= ((hover_area.y + arrow_size.y) - pos.y);
495                        pos.y = hover_area.y + arrow_size.y;
496                     }
497                }
498              //ELM_CTXPOPUP_DIRECTION_DOWN
499              else
500                {
501                   _adjust_pos_x(&pos, &base_size, &hover_area);
502                   dir = ELM_CTXPOPUP_DIRECTION_DOWN;
503                   if ((pos.y + arrow_size.y + base_size.y) >
504                       (hover_area.y + hover_area.h))
505                      base_size.y -=
506                         ((pos.y + arrow_size.y + base_size.y) -
507                          (hover_area.y + hover_area.h));
508                }
509           }
510         else
511           {
512              length[0] = pos.x - hover_area.x;
513              length[1] = (hover_area.x + hover_area.w) - pos.x;
514
515              //ELM_CTXPOPUP_DIRECTION_LEFT
516              if (length[0] > length[1])
517                {
518                   _adjust_pos_y(&pos, &base_size, &hover_area);
519                   pos.x -= base_size.x;
520                   dir = ELM_CTXPOPUP_DIRECTION_LEFT;
521                   if (pos.x < (hover_area.x + arrow_size.x))
522                     {
523                        base_size.x -= ((hover_area.x + arrow_size.x) - pos.x);
524                        pos.x = hover_area.x + arrow_size.x;
525                     }
526                }
527              //ELM_CTXPOPUP_DIRECTION_RIGHT
528              else
529                {
530                   _adjust_pos_y(&pos, &base_size, &hover_area);
531                   dir = ELM_CTXPOPUP_DIRECTION_RIGHT;
532                   if (pos.x + (arrow_size.x + base_size.x) >
533                       hover_area.x + hover_area.w)
534                      base_size.x -=
535                         ((pos.x + arrow_size.x + base_size.x) -
536                          (hover_area.x + hover_area.w));
537                }
538           }
539      }
540
541    //Final position and size.
542    rect->x = pos.x;
543    rect->y = pos.y;
544    rect->w = base_size.x;
545    rect->h = base_size.y;
546
547    return dir;
548 }
549
550 static void
551 _update_arrow(Evas_Object *obj, Elm_Ctxpopup_Direction dir,
552               Evas_Coord_Rectangle base_size)
553 {
554    Evas_Coord x, y;
555    Evas_Coord_Rectangle arrow_size;
556    Widget_Data *wd;
557    double drag;
558
559    wd = elm_widget_data_get(obj);
560    if (!wd) return;
561
562    evas_object_geometry_get(obj, &x, &y, NULL, NULL);
563    evas_object_geometry_get(wd->arrow, NULL, NULL, &arrow_size.w,
564                             &arrow_size.h);
565
566    edje_object_part_unswallow(wd->base, wd->arrow);
567
568    switch (dir)
569      {
570       case ELM_CTXPOPUP_DIRECTION_RIGHT:
571          edje_object_signal_emit(wd->arrow, "elm,state,left", "elm");
572          edje_object_part_swallow(wd->base,
573                                   "elm.swallow.arrow_left",
574                                   wd->arrow);
575 <<<<<<< HEAD
576
577          // if user does not use dragable part
578          arrow_size.y = (y - (arrow_size.h * 0.5));
579          arrow_size.x = x;
580
581 =======
582 >>>>>>> remotes/origin/upstream
583          if (base_size.h > 0)
584            {
585               if (y < ((arrow_size.h * 0.5) + base_size.y))
586                 y = 0;
587               else if (y > base_size.y + base_size.h - (arrow_size.h * 0.5))
588                 y = base_size.h - arrow_size.h;
589               else
590                 y = y - base_size.y - (arrow_size.h * 0.5);
591               drag = (double) (y) / (double) (base_size.h - arrow_size.h);
592               edje_object_part_drag_value_set(wd->base,
593                                               "elm.swallow.arrow_left",
594                                               1,
595                                               drag);
596            }
597          break;
598       case ELM_CTXPOPUP_DIRECTION_LEFT:
599          edje_object_signal_emit(wd->arrow, "elm,state,right", "elm");
600          edje_object_part_swallow(wd->base,
601                                   "elm.swallow.arrow_right",
602                                   wd->arrow);
603 <<<<<<< HEAD
604
605          // if user does not use dragable part
606          arrow_size.y = (y - (arrow_size.h * 0.5));
607          arrow_size.x = (x - arrow_size.w);
608
609 =======
610 >>>>>>> remotes/origin/upstream
611          if (base_size.h > 0)
612            {
613               if (y < ((arrow_size.h * 0.5) + base_size.y))
614                 y = 0;
615               else if (y > (base_size.y + base_size.h - (arrow_size.h * 0.5)))
616                 y = base_size.h - arrow_size.h;
617               else
618                 y = y - base_size.y - (arrow_size.h * 0.5);
619               drag = (double) (y) / (double) (base_size.h - arrow_size.h);
620               edje_object_part_drag_value_set(wd->base,
621                                               "elm.swallow.arrow_right",
622                                               0,
623                                               drag);
624            }
625          break;
626       case ELM_CTXPOPUP_DIRECTION_DOWN:
627          edje_object_signal_emit(wd->arrow, "elm,state,top", "elm");
628          edje_object_part_swallow(wd->base, "elm.swallow.arrow_up", wd->arrow);
629 <<<<<<< HEAD
630
631          // if user does not use dragable part
632          arrow_size.x = (x - (arrow_size.w * 0.5));
633          arrow_size.y = y;
634
635 =======
636 >>>>>>> remotes/origin/upstream
637          if (base_size.w > 0)
638            {
639               if (x < ((arrow_size.w * 0.5) + base_size.x))
640                 x = 0;
641               else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
642                 x = base_size.w - arrow_size.w;
643               else
644                 x = x - base_size.x - (arrow_size.w * 0.5);
645               drag = (double) (x) / (double) (base_size.w - arrow_size.w);
646               edje_object_part_drag_value_set(wd->base,
647                                               "elm.swallow.arrow_up",
648                                               drag,
649                                               1);
650            }
651          break;
652       case ELM_CTXPOPUP_DIRECTION_UP:
653          edje_object_signal_emit(wd->arrow, "elm,state,bottom", "elm");
654          edje_object_part_swallow(wd->base,
655                                   "elm.swallow.arrow_down",
656                                   wd->arrow);
657 <<<<<<< HEAD
658
659          // if user does not use dragable part
660          arrow_size.x = (x - (arrow_size.w * 0.5));
661          arrow_size.y = (y - arrow_size.h);
662
663 =======
664 >>>>>>> remotes/origin/upstream
665          if (base_size.w > 0)
666            {
667               if (x < ((arrow_size.w * 0.5) + base_size.x))
668                 x = 0;
669               else if (x > (base_size.x + base_size.w - (arrow_size.w * 0.5)))
670                 x = base_size.w - arrow_size.w;
671               else x = x - base_size.x - (arrow_size.w * 0.5);
672               drag = (double) (x) / (double) (base_size.w - arrow_size.w);
673               edje_object_part_drag_value_set(wd->base,
674                                               "elm.swallow.arrow_down",
675                                               drag,
676                                               0);
677            }
678          break;
679       default:
680          break;
681      }
682 <<<<<<< HEAD
683
684    // if user does not use dragable part
685    evas_object_move(wd->arrow, arrow_size.x, arrow_size.y);
686 }
687
688 //TODO: compress item - different from opensource
689 static void
690 _compress_item(Evas_Object *obj)
691 {
692    Widget_Data *wd;
693    Eina_List *elist;
694    Elm_Ctxpopup_Item *item;
695
696    wd = elm_widget_data_get(obj);
697    if (!wd) return;
698
699    EINA_LIST_FOREACH(wd->items, elist, item)
700      {
701            edje_object_signal_emit(item->base.view, "elm,state,compress", "elm");
702 =======
703 }
704
705 static void
706 _hide_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
707 {
708    Widget_Data *wd;
709
710    wd = elm_widget_data_get(obj);
711    if (!wd->visible) return;
712
713    switch (dir)
714      {
715         case ELM_CTXPOPUP_DIRECTION_UP:
716            edje_object_signal_emit(wd->base, "elm,state,hide,up", "elm");
717            break;
718         case ELM_CTXPOPUP_DIRECTION_LEFT:
719            edje_object_signal_emit(wd->base, "elm,state,hide,left", "elm");
720            break;
721         case ELM_CTXPOPUP_DIRECTION_RIGHT:
722            edje_object_signal_emit(wd->base, "elm,state,hide,right", "elm");
723            break;
724         case ELM_CTXPOPUP_DIRECTION_DOWN:
725            edje_object_signal_emit(wd->base, "elm,state,hide,down", "elm");
726            break;
727         default:
728            break;
729      }
730
731    edje_object_signal_emit(wd->bg, "elm,state,hide", "elm");
732 }
733
734 static void
735 _show_signal_emit(Evas_Object *obj, Elm_Ctxpopup_Direction dir)
736 {
737    Widget_Data *wd;
738
739    wd = elm_widget_data_get(obj);
740    if (wd->visible) return;
741
742    switch (dir)
743      {
744         case ELM_CTXPOPUP_DIRECTION_UP:
745            edje_object_signal_emit(wd->base, "elm,state,show,up", "elm");
746            break;
747         case ELM_CTXPOPUP_DIRECTION_LEFT:
748            edje_object_signal_emit(wd->base, "elm,state,show,left", "elm");
749            break;
750         case ELM_CTXPOPUP_DIRECTION_RIGHT:
751            edje_object_signal_emit(wd->base, "elm,state,show,right", "elm");
752            break;
753         case ELM_CTXPOPUP_DIRECTION_DOWN:
754            edje_object_signal_emit(wd->base, "elm,state,show,down", "elm");
755            break;
756         default:
757            break;
758 >>>>>>> remotes/origin/upstream
759      }
760 }
761
762 static void
763 _sizing_eval(Evas_Object *obj)
764 {
765    Widget_Data *wd;
766    Eina_List *elist;
767    Elm_Ctxpopup_Item *item;
768    Evas_Coord_Rectangle rect = { 0, 0, 1, 1 };
769    Evas_Coord_Point box_size = { 0, 0 };
770    Evas_Coord_Point _box_size = { 0, 0 };
771
772    wd = elm_widget_data_get(obj);
773    if (!wd) return;
774 <<<<<<< HEAD
775    if (!wd->parent) return;
776 =======
777 >>>>>>> remotes/origin/upstream
778
779    //Box, Scroller
780    EINA_LIST_FOREACH(wd->items, elist, item)
781      {
782         _item_sizing_eval(item);
783         evas_object_size_hint_min_get(VIEW(item), &_box_size.x, &_box_size.y);
784         if (!wd->horizontal)
785           {
786              if (_box_size.x > box_size.x)
787                box_size.x = _box_size.x;
788              if (_box_size.y != -1)
789                box_size.y += _box_size.y;
790           }
791         else
792           {
793              if (_box_size.x != -1)
794                box_size.x += _box_size.x;
795              if (_box_size.y > box_size.y)
796                box_size.y = _box_size.y;
797           }
798      }
799
800    if (!wd->content)
801      {
802         evas_object_size_hint_min_set(wd->box, box_size.x, box_size.y);
803         evas_object_size_hint_min_set(wd->scr, box_size.x, box_size.y);
804      }
805
806    //Base
807    wd->dir = _calc_base_geometry(obj, &rect);
808 <<<<<<< HEAD
809
810    //TODO: compress item - different from opensource
811    if (!wd->horizontal && !wd->content)
812      _compress_item(obj);
813
814 =======
815    _show_signal_emit(obj, wd->dir);
816 >>>>>>> remotes/origin/upstream
817    _update_arrow(obj, wd->dir, rect);
818    _shift_base_by_arrow(wd->arrow, wd->dir, &rect);
819
820    //resize scroller according to final size.
821    if (!wd->content)
822      evas_object_smart_calculate(wd->scr);
823
824    evas_object_move(wd->base, rect.x, rect.y);
825    evas_object_resize(wd->base, rect.w, rect.h);
826 }
827
828 static void
829 _shift_base_by_arrow(Evas_Object *arrow, Elm_Ctxpopup_Direction dir,
830                      Evas_Coord_Rectangle *rect)
831 {
832    Evas_Coord arrow_w, arrow_h;
833
834    evas_object_geometry_get(arrow, NULL, NULL, &arrow_w, &arrow_h);
835
836    switch (dir)
837      {
838       case ELM_CTXPOPUP_DIRECTION_RIGHT:
839          rect->x += arrow_w;
840          break;
841       case ELM_CTXPOPUP_DIRECTION_LEFT:
842          rect->x -= arrow_w;
843          break;
844       case ELM_CTXPOPUP_DIRECTION_DOWN:
845          rect->y += arrow_h;
846          break;
847       case ELM_CTXPOPUP_DIRECTION_UP:
848          rect->y -= arrow_h;
849          break;
850       default:
851          break;
852      }
853 }
854
855 static void
856 _del_pre_hook(Evas_Object *obj)
857 {
858    Widget_Data *wd;
859
860    wd = elm_widget_data_get(obj);
861    if (!wd) return;
862
863 <<<<<<< HEAD
864    evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE,
865                                        _parent_resize, obj);
866    evas_object_event_callback_del_full(wd->box, EVAS_CALLBACK_RESIZE,
867                                        _content_resize, obj);
868
869 =======
870    evas_object_event_callback_del_full(wd->box, EVAS_CALLBACK_RESIZE,
871                                        _content_resize, obj);
872 >>>>>>> remotes/origin/upstream
873    _parent_cut_off(obj);
874 }
875
876 static void
877 _del_hook(Evas_Object *obj)
878 {
879    Widget_Data *wd;
880
881    wd = elm_widget_data_get(obj);
882    if (!wd) return;
883
884    elm_ctxpopup_clear(obj);
885    evas_object_del(wd->arrow);
886    evas_object_del(wd->base);
887    free(wd);
888 }
889
890 //FIXME: lost the content size when theme hook is called.
891 static void
892 _theme_hook(Evas_Object *obj)
893 {
894    Widget_Data *wd;
895    Eina_List *elist;
896    Elm_Ctxpopup_Item *item;
897 <<<<<<< HEAD
898    int idx = 0;
899 =======
900 >>>>>>> remotes/origin/upstream
901    Eina_Bool rtl;
902
903    wd = elm_widget_data_get(obj);
904    if (!wd) return;
905
906    _elm_widget_mirrored_reload(obj);
907    rtl = elm_widget_mirrored_get(obj);
908
909    _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg",
910                          elm_widget_style_get(obj));
911    _elm_theme_object_set(obj, wd->base, "ctxpopup", "base",
912                          elm_widget_style_get(obj));
913    _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow",
914                          elm_widget_style_get(obj));
915
916    //Items
917    EINA_LIST_FOREACH(wd->items, elist, item)
918      {
919         edje_object_mirrored_set(VIEW(item), rtl);
920
921         if (item->label && item->icon)
922           _elm_theme_object_set(obj, VIEW(item), "ctxpopup",
923                                 "icon_text_style_item",
924                                 elm_widget_style_get(obj));
925         else if (item->label)
926           _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "text_style_item",
927                                 elm_widget_style_get(obj));
928         else if (item->icon)
929           _elm_theme_object_set(obj, VIEW(item), "ctxpopup", "icon_style_item",
930                                 elm_widget_style_get(obj));
931         if (item->label)
932           edje_object_part_text_set(VIEW(item), "elm.text", item->label);
933
934         if (elm_widget_item_disabled_get(item))
935           edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
936
937 <<<<<<< HEAD
938        /*
939         *  For separator, if the first item has visible separator,
940         *  then it should be aligned with edge of the base part.
941         *  In some cases, it gives improper display. Ex) rounded corner
942         *  So the first item separator should be invisible.
943         */
944        if ((idx++) == 0)
945          edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
946        else
947          {
948            if(!wd->horizontal)
949              edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
950            else
951              edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
952          }
953
954         edje_object_message_signal_process(VIEW(item));
955      }
956
957    if (evas_object_visible_get(wd->bg))
958      edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
959
960 =======
961         edje_object_message_signal_process(VIEW(item));
962      }
963
964 >>>>>>> remotes/origin/upstream
965    if (wd->scr)
966      {
967         if (!strncmp(elm_object_style_get(obj), "default", strlen("default")))
968            elm_object_style_set(wd->scr, "ctxpopup");
969         else
970            elm_object_style_set(wd->scr, elm_object_style_get(obj));
971      }
972
973    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
974
975    if (wd->visible)
976      {
977         _scroller_size_reset(wd);
978         _sizing_eval(obj);
979      }
980 }
981
982 static void
983 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
984 {
985    ELM_CHECK_WIDTYPE(obj, widtype);
986    Evas_Coord min_w = -1, min_h = -1;
987
988    Widget_Data *wd;
989
990    if (part && strcmp(part, "default")) return;
991
992    wd = elm_widget_data_get(obj);
993    if ((!wd) || (!content)) return;
994
995    if (wd->items) elm_ctxpopup_clear(obj);
996    if (wd->content) evas_object_del(wd->content);
997
998    //Use Box
999    wd->box = elm_box_add(obj);
1000    evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1001                                     EVAS_HINT_EXPAND);
1002    evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND,
1003                                     EVAS_HINT_EXPAND);
1004    evas_object_size_hint_fill_set(content, EVAS_HINT_FILL,
1005                                   EVAS_HINT_FILL);
1006    evas_object_show(content);
1007    evas_object_size_hint_min_get(content, &min_w, &min_h);
1008    evas_object_size_hint_min_set(wd->box, min_w, min_h);
1009    elm_box_pack_end(wd->box, content);
1010
1011    evas_object_event_callback_add(wd->box, EVAS_CALLBACK_RESIZE,
1012                                   _content_resize, obj);
1013    evas_object_event_callback_add(wd->box, EVAS_CALLBACK_DEL,
1014                                   _content_del, obj);
1015
1016    elm_widget_sub_object_add(obj, wd->box);
1017    edje_object_part_swallow(wd->base, "elm.swallow.content", wd->box);
1018
1019    wd->content = content;
1020    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1021
1022    if (wd->visible)
1023      _sizing_eval(obj);
1024 }
1025
1026 static Evas_Object *
1027 _content_unset_hook(Evas_Object *obj, const char *part)
1028 {
1029    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1030
1031    Widget_Data *wd;
1032    Evas_Object *content;
1033    if (part && strcmp(part, "default")) return NULL;
1034    wd = elm_widget_data_get(obj);
1035    if (!wd) return NULL;
1036
1037    content = wd->content;
1038    if (!content || !wd->box) return NULL;
1039
1040    edje_object_part_unswallow(wd->base, wd->box);
1041    elm_widget_sub_object_del(obj, wd->box);
1042    evas_object_event_callback_del(wd->box, EVAS_CALLBACK_DEL, _content_del);
1043    edje_object_signal_emit(wd->base, "elm,state,content,disable", "elm");
1044
1045    evas_object_del(wd->box);
1046    wd->box = NULL;
1047    wd->content = NULL;
1048    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1049
1050    return content;
1051 }
1052
1053 static Evas_Object *
1054 _content_get_hook(const Evas_Object *obj, const char *part)
1055 {
1056    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1057    Widget_Data *wd;
1058    if (part && strcmp(part, "default")) return NULL;
1059    wd = elm_widget_data_get(obj);
1060    if (!wd) return NULL;
1061    return wd->content;
1062 }
1063
1064 static void
1065 _item_text_set_hook(Elm_Object_Item *it, const char *part, const char *label)
1066 {
1067 <<<<<<< HEAD
1068    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1069
1070 =======
1071 >>>>>>> remotes/origin/upstream
1072    Widget_Data *wd;
1073    Elm_Ctxpopup_Item *ctxpopup_it;
1074
1075    if (part && strcmp(part, "default")) return;
1076
1077 <<<<<<< HEAD
1078    ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1079 =======
1080    ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1081 >>>>>>> remotes/origin/upstream
1082
1083    wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1084    if (!wd) return;
1085
1086    _item_label_set(ctxpopup_it, label);
1087    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1088
1089    if (wd->visible)
1090      {
1091         _scroller_size_reset(wd);
1092         _sizing_eval(WIDGET(ctxpopup_it));
1093      }
1094 }
1095
1096 static const char *
1097 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
1098 {
1099 <<<<<<< HEAD
1100    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1101    Elm_Ctxpopup_Item *ctxpopup_it;
1102    if (part && strcmp(part, "default")) return NULL;
1103    ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1104 =======
1105    Elm_Ctxpopup_Item *ctxpopup_it;
1106    if (part && strcmp(part, "default")) return NULL;
1107    ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1108 >>>>>>> remotes/origin/upstream
1109    return ctxpopup_it->label;
1110 }
1111
1112 static void
1113 _item_content_set_hook(Elm_Object_Item *it,
1114                        const char *part,
1115                        Evas_Object *content)
1116 {
1117 <<<<<<< HEAD
1118    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1119 =======
1120 >>>>>>> remotes/origin/upstream
1121    Widget_Data *wd;
1122    Elm_Ctxpopup_Item *ctxpopup_it;
1123
1124    if (part && strcmp(part, "icon")) return;
1125
1126 <<<<<<< HEAD
1127    ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1128 =======
1129    ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1130 >>>>>>> remotes/origin/upstream
1131
1132    wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1133    if (!wd) return;
1134
1135    _item_icon_set(ctxpopup_it, content);
1136    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1137
1138    if (wd->visible)
1139      {
1140         _scroller_size_reset(wd);
1141         _sizing_eval(WIDGET(ctxpopup_it));
1142      }
1143 }
1144
1145 static Evas_Object *
1146 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
1147 {
1148 <<<<<<< HEAD
1149    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1150    Elm_Ctxpopup_Item *ctxpopup_it;
1151    if (part && strcmp(part, "icon")) return NULL;
1152    ctxpopup_it  = (Elm_Ctxpopup_Item *) it;
1153 =======
1154    Elm_Ctxpopup_Item *ctxpopup_it;
1155    if (part && strcmp(part, "icon")) return NULL;
1156    ctxpopup_it  = (Elm_Ctxpopup_Item *)it;
1157 >>>>>>> remotes/origin/upstream
1158    return ctxpopup_it->icon;
1159 }
1160
1161 static void
1162 _item_disable_hook(Elm_Object_Item *it)
1163 {
1164 <<<<<<< HEAD
1165    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1166
1167    Widget_Data *wd;
1168    Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1169 =======
1170    Widget_Data *wd;
1171    Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1172 >>>>>>> remotes/origin/upstream
1173
1174    wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1175    if (!wd) return;
1176
1177    if (elm_widget_item_disabled_get(it))
1178      edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm");
1179    else
1180      edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm");
1181 }
1182
1183 static void
1184 _item_signal_emit_hook(Elm_Object_Item *it, const char *emission,
1185                        const char *source)
1186 {
1187 <<<<<<< HEAD
1188    ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1189    Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1190 =======
1191    Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1192 >>>>>>> remotes/origin/upstream
1193    edje_object_signal_emit(VIEW(ctxpopup_it), emission, source);
1194 }
1195
1196 static void
1197 _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__,
1198                const char *emission __UNUSED__, const char *source __UNUSED__)
1199 {
1200 <<<<<<< HEAD
1201    evas_object_hide(data);
1202 =======
1203    Widget_Data *wd = elm_widget_data_get(data);
1204    if (!wd) return;
1205    _hide_signal_emit(data, wd->dir);
1206 >>>>>>> remotes/origin/upstream
1207 }
1208
1209 static void
1210 _ctxpopup_show(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1211                void *event_info __UNUSED__)
1212 {
1213    Widget_Data *wd;
1214 <<<<<<< HEAD
1215    Eina_List *elist;
1216    Elm_Ctxpopup_Item *item;
1217    int idx = 0;
1218 =======
1219 >>>>>>> remotes/origin/upstream
1220
1221    wd = elm_widget_data_get(obj);
1222    if (!wd) return;
1223
1224    if ((!wd->items) && (!wd->content)) return;
1225
1226    wd->visible = EINA_TRUE;
1227
1228    evas_object_show(wd->bg);
1229    evas_object_show(wd->base);
1230    evas_object_show(wd->arrow);
1231
1232    edje_object_signal_emit(wd->bg, "elm,state,show", "elm");
1233 <<<<<<< HEAD
1234
1235    EINA_LIST_FOREACH(wd->items, elist, item)
1236      {
1237        if (idx++ == 0)
1238          edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1239        else
1240          {
1241            if(!wd->horizontal)
1242              edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1243            else
1244              edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1245          }
1246      }
1247 =======
1248    edje_object_signal_emit(wd->base, "elm,state,show", "elm");
1249 >>>>>>> remotes/origin/upstream
1250
1251    _sizing_eval(obj);
1252
1253    elm_object_focus_set(obj, EINA_TRUE);
1254 }
1255
1256 static void
1257 <<<<<<< HEAD
1258 _hide(Evas_Object *obj)
1259 {
1260    Widget_Data *wd = elm_widget_data_get(obj);
1261
1262 =======
1263 _hide_finished(void *data, Evas_Object *obj __UNUSED__,
1264                const char *emission __UNUSED__, const char *source __UNUSED__)
1265 {
1266    _hide(data);
1267 }
1268
1269 static void
1270 _hide(Evas_Object *obj)
1271 {
1272    _ctxpopup_hide(NULL, NULL, obj, NULL);
1273    evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1274 }
1275
1276 static void
1277 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1278                void *event_info __UNUSED__)
1279 {
1280    Widget_Data *wd = elm_widget_data_get(obj);
1281 >>>>>>> remotes/origin/upstream
1282    if ((!wd) || (!wd->visible)) return;
1283
1284    evas_object_hide(wd->bg);
1285    evas_object_hide(wd->arrow);
1286    evas_object_hide(wd->base);
1287
1288    _scroller_size_reset(wd);
1289
1290 <<<<<<< HEAD
1291    evas_object_smart_callback_call(obj, SIG_DISMISSED, NULL);
1292 =======
1293 >>>>>>> remotes/origin/upstream
1294    wd->visible = EINA_FALSE;
1295 }
1296
1297 static void
1298 <<<<<<< HEAD
1299 _ctxpopup_hide(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1300                void *event_info __UNUSED__)
1301 {
1302    _hide(obj);
1303 }
1304
1305 static void
1306 =======
1307 >>>>>>> remotes/origin/upstream
1308 _content_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1309                 void *event_info __UNUSED__)
1310 {
1311    Widget_Data *wd = elm_widget_data_get(data);
1312    if (!wd) return;
1313    elm_box_recalculate(wd->box);
1314    _sizing_eval(data);
1315 }
1316
1317 static void
1318 _scroller_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj,
1319                  void *event_info __UNUSED__)
1320 {
1321    Widget_Data *wd;
1322    Evas_Coord w, h;
1323
1324    wd = elm_widget_data_get(data);
1325    if (!wd) return;
1326    if (!wd->visible) return;
1327    if (wd->finished) return;
1328
1329    evas_object_geometry_get(obj, 0, 0, &w, &h);
1330
1331    if (w != 0 && h != 0)
1332      {
1333         if ((w <= wd->max_sc_w) && (h <= wd->max_sc_h))
1334           {
1335              _sizing_eval(data);
1336              wd->finished = EINA_TRUE;
1337              return;
1338           }
1339      }
1340
1341    if (wd->max_sc_w < w)
1342      wd->max_sc_w = w;
1343    if (wd->max_sc_h < h)
1344      wd->max_sc_h = h;
1345
1346    _sizing_eval(data);
1347 }
1348
1349 static void
1350 _ctxpopup_move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
1351                void *event_info __UNUSED__)
1352 {
1353    Widget_Data *wd;
1354
1355    wd = elm_widget_data_get(obj);
1356
1357    if (!wd) return;
1358
1359    if (wd->visible)
1360      evas_object_show(wd->arrow);
1361
1362    _scroller_size_reset(wd);
1363    _sizing_eval(obj);
1364 }
1365
1366 static void
1367 _restack(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1368 {
1369    Widget_Data *wd = elm_widget_data_get(obj);
1370    if (!wd) return;
1371    evas_object_layer_set(wd->bg,
1372                          evas_object_layer_get(obj));
1373    evas_object_layer_set(wd->base,
1374                          evas_object_layer_get(obj));
1375 }
1376
1377 static void
1378 _item_select_cb(void *data, Evas_Object *obj __UNUSED__,
1379                 const char *emission __UNUSED__, const char *source __UNUSED__)
1380 {
1381    Elm_Ctxpopup_Item *item = data;
1382
1383    if (!item) return;
1384    if (elm_widget_item_disabled_get(item)) return;
1385
1386    if (item->func)
1387 <<<<<<< HEAD
1388      item->func((void*) item->base.data, WIDGET(item), data);
1389 =======
1390      item->func((void*)item->base.data, WIDGET(item), data);
1391 >>>>>>> remotes/origin/upstream
1392 }
1393
1394 static void
1395 _item_icon_set(Elm_Ctxpopup_Item *item, Evas_Object *icon)
1396 {
1397    if (item->icon)
1398 <<<<<<< HEAD
1399      {
1400         elm_widget_sub_object_del(VIEW(item), item->icon);
1401         evas_object_del(item->icon);
1402      }
1403 =======
1404      evas_object_del(item->icon);
1405 >>>>>>> remotes/origin/upstream
1406
1407    item->icon = icon;
1408    if (!icon) return;
1409
1410    edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1411    edje_object_message_signal_process(VIEW(item));
1412 }
1413
1414 static void
1415 _item_label_set(Elm_Ctxpopup_Item *item, const char *label)
1416 {
1417    if (!eina_stringshare_replace(&item->label, label))
1418      return;
1419
1420    edje_object_part_text_set(VIEW(item), "elm.text", label);
1421    edje_object_message_signal_process(VIEW(item));
1422 }
1423
1424 static void
1425 _item_new(Elm_Ctxpopup_Item *item, char *group_name)
1426 {
1427    Widget_Data *wd;
1428
1429    wd = elm_widget_data_get(WIDGET(item));
1430    if (!wd) return;
1431
1432    VIEW(item) = edje_object_add(evas_object_evas_get(wd->base));
1433    edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
1434    _elm_theme_object_set(WIDGET(item), VIEW(item), "ctxpopup", group_name,
1435                          elm_widget_style_get(WIDGET(item)));
1436    edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
1437                                    _item_select_cb, item);
1438    evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1439    evas_object_show(VIEW(item));
1440 }
1441
1442 static void
1443 _content_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
1444              void *event_info __UNUSED__)
1445 {
1446    elm_object_content_unset(data);
1447 }
1448
1449 static void
1450 _list_del(Widget_Data *wd)
1451 {
1452    if (!wd->scr) return;
1453
1454    edje_object_part_unswallow(wd->base, wd->scr);
1455    evas_object_del(wd->scr);
1456    wd->scr = NULL;
1457    wd->box = NULL;
1458 }
1459
1460 static void
1461 _list_new(Evas_Object *obj)
1462 {
1463    Widget_Data *wd;
1464    wd = elm_widget_data_get(obj);
1465    if (!wd) return;
1466
1467    //scroller
1468    wd->scr = elm_scroller_add(obj);
1469    elm_object_style_set(wd->scr, "ctxpopup");
1470    evas_object_size_hint_align_set(wd->scr, EVAS_HINT_FILL, EVAS_HINT_FILL);
1471    evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE,
1472                                   _scroller_resize, obj);
1473    edje_object_part_swallow(wd->base, "elm.swallow.content", wd->scr);
1474
1475    //box
1476    wd->box = elm_box_add(obj);
1477    evas_object_size_hint_weight_set(wd->box, EVAS_HINT_EXPAND,
1478                                     EVAS_HINT_EXPAND);
1479
1480    elm_object_content_set(wd->scr, wd->box);
1481    elm_ctxpopup_horizontal_set(obj, wd->horizontal);
1482 }
1483
1484 static void
1485 _remove_items(Widget_Data *wd)
1486 {
1487    Eina_List *elist;
1488    Elm_Ctxpopup_Item *item;
1489
1490    if (!wd->items) return;
1491
1492    EINA_LIST_FOREACH(wd->items, elist, item)
1493      {
1494         if (item->label)
1495           eina_stringshare_del(item->label);
1496         if (item->icon)
1497           evas_object_del(item->icon);
1498         wd->items = eina_list_remove(wd->items, item);
1499         elm_widget_item_free(item);
1500      }
1501
1502    wd->items = NULL;
1503 }
1504
1505 static Eina_Bool
1506 _item_del_pre_hook(Elm_Object_Item *it)
1507 {
1508 <<<<<<< HEAD
1509    ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1510
1511    Widget_Data *wd;
1512    Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it;
1513 =======
1514    Widget_Data *wd;
1515    Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *)it;
1516 >>>>>>> remotes/origin/upstream
1517
1518    wd = elm_widget_data_get(WIDGET(ctxpopup_it));
1519    if (!wd) return EINA_FALSE;
1520
1521    if (ctxpopup_it->icon)
1522      evas_object_del(ctxpopup_it->icon);
1523    if (VIEW(ctxpopup_it))
1524      evas_object_del(VIEW(ctxpopup_it));
1525
1526    eina_stringshare_del(ctxpopup_it->label);
1527
1528    wd->items = eina_list_remove(wd->items, ctxpopup_it);
1529
1530    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1531
1532    if (eina_list_count(wd->items) < 1)
1533      {
1534         evas_object_hide(WIDGET(ctxpopup_it));
1535         return EINA_TRUE;
1536      }
1537
1538    if (wd->visible)
1539      _sizing_eval(WIDGET(ctxpopup_it));
1540
1541    return EINA_TRUE;
1542 }
1543
1544 EAPI Evas_Object *
1545 elm_ctxpopup_add(Evas_Object *parent)
1546 {
1547    Evas_Object *obj;
1548    Evas *e;
1549    Widget_Data *wd;
1550 <<<<<<< HEAD
1551    Evas_Coord x, y, w, h;
1552 =======
1553 >>>>>>> remotes/origin/upstream
1554
1555    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1556
1557    ELM_SET_WIDTYPE(widtype, "ctxpopup");
1558    elm_widget_type_set(obj, "ctxpopup");
1559 <<<<<<< HEAD
1560    elm_widget_sub_object_add(parent, obj);
1561 =======
1562 >>>>>>> remotes/origin/upstream
1563    elm_widget_data_set(obj, wd);
1564    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1565    elm_widget_del_hook_set(obj, _del_hook);
1566    elm_widget_theme_hook_set(obj, _theme_hook);
1567    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1568    elm_widget_can_focus_set(obj, EINA_TRUE);
1569    elm_widget_event_hook_set(obj, _event_hook);
1570    elm_widget_content_set_hook_set(obj, _content_set_hook);
1571    elm_widget_content_unset_hook_set(obj, _content_unset_hook);
1572    elm_widget_content_get_hook_set(obj, _content_get_hook);
1573
1574    //Background
1575    wd->bg = edje_object_add(e);
1576    elm_widget_sub_object_add(obj, wd->bg);
1577    _elm_theme_object_set(obj, wd->bg, "ctxpopup", "bg", "default");
1578 <<<<<<< HEAD
1579    evas_object_geometry_get(parent, &x, &y, &w, &h);
1580    evas_object_move(wd->bg, x, y);
1581    evas_object_resize(wd->bg, w, h);
1582    edje_object_signal_callback_add(wd->bg, "elm,action,click", "",
1583                                    _bg_clicked_cb, obj);
1584
1585 =======
1586    edje_object_signal_callback_add(wd->bg,
1587                                    "elm,action,click",
1588                                    "",
1589                                    _bg_clicked_cb,
1590                                     obj);
1591 >>>>>>> remotes/origin/upstream
1592    //Base
1593    wd->base = edje_object_add(e);
1594    elm_widget_sub_object_add(obj, wd->base);
1595    _elm_theme_object_set(obj, wd->base, "ctxpopup", "base", "default");
1596 <<<<<<< HEAD
1597 =======
1598    edje_object_signal_callback_add(wd->base, "elm,action,hide,finished", "",
1599                                    _hide_finished, obj);
1600 >>>>>>> remotes/origin/upstream
1601
1602    //Arrow
1603    wd->arrow = edje_object_add(e);
1604    elm_widget_sub_object_add(obj, wd->arrow);
1605    _elm_theme_object_set(obj, wd->arrow, "ctxpopup", "arrow", "default");
1606
1607    wd->dir_priority[0] = ELM_CTXPOPUP_DIRECTION_UP;
1608    wd->dir_priority[1] = ELM_CTXPOPUP_DIRECTION_LEFT;
1609    wd->dir_priority[2] = ELM_CTXPOPUP_DIRECTION_RIGHT;
1610    wd->dir_priority[3] = ELM_CTXPOPUP_DIRECTION_DOWN;
1611 <<<<<<< HEAD
1612
1613    evas_object_event_callback_add(parent, EVAS_CALLBACK_RESIZE, _parent_resize,
1614                                   obj);
1615 =======
1616 >>>>>>> remotes/origin/upstream
1617    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1618
1619    evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _ctxpopup_show,
1620                                   NULL);
1621    evas_object_event_callback_add(obj, EVAS_CALLBACK_HIDE, _ctxpopup_hide,
1622                                   NULL);
1623    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _ctxpopup_move,
1624                                   NULL);
1625 <<<<<<< HEAD
1626    evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1627                                   _ctxpopup_changed_size_hints, NULL);
1628 =======
1629 >>>>>>> remotes/origin/upstream
1630    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESTACK, _restack, obj);
1631    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1632    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1633    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1634    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1635
1636    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1637
1638    //default parent is to be hover parent
1639    elm_ctxpopup_hover_parent_set(obj, parent);
1640
1641    return obj;
1642 }
1643
1644 <<<<<<< HEAD
1645 EAPI Evas_Object *
1646 elm_ctxpopup_item_icon_get(const Elm_Object_Item *it)
1647 {
1648    return _item_content_get_hook(it, "icon");
1649 }
1650
1651 EAPI void
1652 elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon)
1653 {
1654    _item_content_set_hook(it, "icon", icon);
1655 }
1656
1657 EAPI const char *
1658 elm_ctxpopup_item_label_get(const Elm_Object_Item *it)
1659 {
1660    return _item_text_get_hook(it, NULL);
1661 }
1662
1663 EAPI void
1664 elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label)
1665 {
1666    _item_text_set_hook(it, NULL, label);
1667 }
1668
1669 =======
1670 >>>>>>> remotes/origin/upstream
1671 EAPI void
1672 elm_ctxpopup_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
1673 {
1674    ELM_CHECK_WIDTYPE(obj, widtype);
1675
1676    Widget_Data *wd;
1677    Evas_Coord x, y, w, h;
1678
1679    wd = elm_widget_data_get(obj);
1680    if ((!wd) || (!parent)) return;
1681
1682    _parent_cut_off(obj);
1683
1684    if (parent)
1685      {
1686         evas_object_event_callback_add(parent,
1687                                        EVAS_CALLBACK_DEL,
1688                                        _parent_del,
1689                                        obj);
1690         evas_object_event_callback_add(parent,
1691                                        EVAS_CALLBACK_MOVE,
1692                                        _parent_move,
1693                                        obj);
1694         evas_object_event_callback_add(parent,
1695                                        EVAS_CALLBACK_RESIZE,
1696                                        _parent_resize,
1697                                        obj);
1698      }
1699
1700    elm_widget_sub_object_add(parent, obj);
1701    wd->parent = parent;
1702
1703    //Update Background
1704    evas_object_geometry_get(parent, &x, &y, &w, &h);
1705    evas_object_move(wd->bg, x, y);
1706    evas_object_resize(wd->bg, w, h);
1707
1708    if (wd->visible) _sizing_eval(obj);
1709 }
1710
1711 EAPI Evas_Object *
1712 elm_ctxpopup_hover_parent_get(const Evas_Object *obj)
1713 {
1714    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1715
1716    Widget_Data *wd;
1717
1718    wd = elm_widget_data_get(obj);
1719    if (!wd) return NULL;
1720
1721    return wd->parent;
1722 }
1723
1724 EAPI void
1725 elm_ctxpopup_clear(Evas_Object * obj)
1726 {
1727    ELM_CHECK_WIDTYPE(obj, widtype);
1728
1729    Widget_Data *wd = elm_widget_data_get(obj);
1730    if (!wd) return;
1731
1732    _remove_items(wd);
1733    _list_del(wd);
1734    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1735 }
1736
1737 EAPI void
1738 elm_ctxpopup_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1739 {
1740    ELM_CHECK_WIDTYPE(obj, widtype);
1741
1742    Widget_Data *wd;
1743 <<<<<<< HEAD
1744    Eina_List *elist;
1745    Elm_Ctxpopup_Item *item;
1746    int idx = 0;
1747 =======
1748 >>>>>>> remotes/origin/upstream
1749
1750    wd = elm_widget_data_get(obj);
1751    if (!wd) return;
1752
1753    wd->horizontal = !!horizontal;
1754
1755    if ((!wd->scr) && (!wd->box))
1756       return;
1757
1758    if (!horizontal)
1759      {
1760         elm_box_horizontal_set(wd->box, EINA_FALSE);
1761         elm_scroller_bounce_set(wd->scr, EINA_FALSE, EINA_TRUE);
1762 <<<<<<< HEAD
1763
1764         EINA_LIST_FOREACH(wd->items, elist, item)
1765           {
1766              if (idx++ == 0)
1767                edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1768              else
1769                edje_object_signal_emit(VIEW(item), "elm,state,vertical", "elm");
1770           }
1771 =======
1772 >>>>>>> remotes/origin/upstream
1773      }
1774    else
1775      {
1776         elm_box_horizontal_set(wd->box, EINA_TRUE);
1777         elm_scroller_bounce_set(wd->scr, EINA_TRUE, EINA_FALSE);
1778 <<<<<<< HEAD
1779
1780         EINA_LIST_FOREACH(wd->items, elist, item)
1781           {
1782              if (idx++ == 0)
1783                edje_object_signal_emit(VIEW(item), "elm,state,default", "elm");
1784              else
1785                edje_object_signal_emit(VIEW(item), "elm,state,horizontal", "elm");
1786           }
1787 =======
1788 >>>>>>> remotes/origin/upstream
1789      }
1790
1791    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1792
1793    if (wd->visible)
1794       _sizing_eval(obj);
1795 }
1796
1797 EAPI Eina_Bool
1798 elm_ctxpopup_horizontal_get(const Evas_Object *obj)
1799 {
1800    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1801
1802    Widget_Data *wd;
1803
1804    wd = elm_widget_data_get(obj);
1805    if (!wd) return EINA_FALSE;
1806
1807    return wd->horizontal;
1808 }
1809
1810 EAPI Elm_Object_Item *
1811 elm_ctxpopup_item_append(Evas_Object *obj, const char *label,
1812                          Evas_Object *icon, Evas_Smart_Cb func,
1813                          const void *data)
1814 {
1815    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1816
1817    Widget_Data *wd;
1818    Evas_Object *content;
1819    Elm_Ctxpopup_Item *item;
1820
1821    wd = elm_widget_data_get(obj);
1822    if (!wd) return NULL;
1823
1824    item = elm_widget_item_new(obj, Elm_Ctxpopup_Item);
1825    if (!item) return NULL;
1826
1827    elm_widget_item_del_pre_hook_set(item, _item_del_pre_hook);
1828    elm_widget_item_disable_hook_set(item, _item_disable_hook);
1829    elm_widget_item_text_set_hook_set(item, _item_text_set_hook);
1830    elm_widget_item_text_get_hook_set(item, _item_text_get_hook);
1831    elm_widget_item_content_set_hook_set(item, _item_content_set_hook);
1832    elm_widget_item_content_get_hook_set(item, _item_content_get_hook);
1833    elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook);
1834
1835    //The first item is appended.
1836    content = elm_object_content_unset(obj);
1837    if (content) evas_object_del(content);
1838
1839    if (!wd->items)
1840      _list_new(obj);
1841
1842    item->func = func;
1843    item->base.data = data;
1844
1845    if (icon && label)
1846      _item_new(item, "icon_text_style_item");
1847    else if (label)
1848      _item_new(item, "text_style_item");
1849    else
1850      _item_new(item, "icon_style_item");
1851
1852    _item_icon_set(item, icon);
1853    _item_label_set(item, label);
1854    elm_box_pack_end(wd->box, VIEW(item));
1855    wd->items = eina_list_append(wd->items, item);
1856    wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1857
1858    if (wd->visible)
1859      {
1860         _scroller_size_reset(wd);
1861         _sizing_eval(obj);
1862      }
1863
1864 <<<<<<< HEAD
1865    return (Elm_Object_Item *) item;
1866 }
1867
1868 EAPI void
1869 elm_ctxpopup_item_del(Elm_Object_Item *it)
1870 {
1871    elm_object_item_del(it);
1872 }
1873
1874 EAPI void
1875 elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1876 {
1877    elm_object_item_disabled_set(it, disabled);
1878 }
1879
1880 EAPI Eina_Bool
1881 elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it)
1882 {
1883    return elm_object_item_disabled_get(it);
1884 }
1885
1886 EAPI void
1887 elm_ctxpopup_content_set(Evas_Object *obj, Evas_Object *content)
1888 {
1889    elm_object_content_set(obj, content);
1890 }
1891
1892 EAPI Evas_Object *
1893 elm_ctxpopup_content_unset(Evas_Object *obj)
1894 {
1895    return elm_object_content_unset(obj);
1896 =======
1897    return (Elm_Object_Item *)item;
1898 >>>>>>> remotes/origin/upstream
1899 }
1900
1901 EAPI void
1902 elm_ctxpopup_direction_priority_set(Evas_Object *obj,
1903                                     Elm_Ctxpopup_Direction first,
1904                                     Elm_Ctxpopup_Direction second,
1905                                     Elm_Ctxpopup_Direction third,
1906                                     Elm_Ctxpopup_Direction fourth)
1907 {
1908    ELM_CHECK_WIDTYPE(obj, widtype);
1909    Widget_Data *wd;
1910
1911    wd = elm_widget_data_get(obj);
1912    if (!wd) return;
1913
1914    wd->dir_priority[0] = first;
1915    wd->dir_priority[1] = second;
1916    wd->dir_priority[2] = third;
1917    wd->dir_priority[3] = fourth;
1918
1919    if (wd->visible)
1920      _sizing_eval(obj);
1921 }
1922
1923 EAPI void
1924 elm_ctxpopup_direction_priority_get(Evas_Object *obj,
1925                                     Elm_Ctxpopup_Direction *first,
1926                                     Elm_Ctxpopup_Direction *second,
1927                                     Elm_Ctxpopup_Direction *third,
1928                                     Elm_Ctxpopup_Direction *fourth)
1929 {
1930    ELM_CHECK_WIDTYPE(obj, widtype);
1931    Widget_Data *wd;
1932
1933    wd = elm_widget_data_get(obj);
1934    if (!wd) return;
1935
1936    if (first) *first = wd->dir_priority[0];
1937    if (second) *second = wd->dir_priority[1];
1938    if (third) *third = wd->dir_priority[2];
1939    if (fourth) *fourth = wd->dir_priority[3];
1940 }
1941
1942 EAPI Elm_Ctxpopup_Direction
1943 elm_ctxpopup_direction_get(const Evas_Object *obj)
1944 {
1945    ELM_CHECK_WIDTYPE(obj, widtype) ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1946    Widget_Data *wd;
1947
1948    wd = elm_widget_data_get(obj);
1949    if (!wd) return ELM_CTXPOPUP_DIRECTION_UNKNOWN;
1950    return wd->dir;
1951 }
1952 <<<<<<< HEAD
1953 =======
1954
1955 EAPI void
1956 elm_ctxpopup_dismiss(Evas_Object *obj)
1957 {
1958    ELM_CHECK_WIDTYPE(obj, widtype);
1959    Widget_Data *wd = elm_widget_data_get(obj);
1960    if (!wd) return;
1961    _hide_signal_emit(obj, wd->dir);
1962 }
1963 >>>>>>> remotes/origin/upstream