Merge branch 'intefl/svn_merge' of ssh://165.213.149.219:21922/slp/pkgs/e/elementary...
[framework/uifw/elementary.git] / src / lib / elm_photocam.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "els_scroller.h"
4
5 /*
6  * TODO (maybe - optional future stuff):
7  *
8  * 1. wrap photo in theme edje so u can have styling around photo (like white
9  *    photo bordering).
10  * 2. exif handling
11  * 3. rotation flags in exif handling (nasty! should have rot in evas)
12  */
13
14 typedef struct _Widget_Data Widget_Data;
15 typedef struct _Pan Pan;
16 typedef struct _Grid Grid;
17 typedef struct _Grid_Item Grid_Item;
18
19 struct _Grid_Item
20 {
21    Widget_Data *wd;
22    Evas_Object *img;
23    struct
24    {
25       int x, y, w, h;
26    } src, out;
27    Eina_Bool want : 1;
28    Eina_Bool have : 1;
29 };
30
31 struct _Grid
32 {
33    int tsize; // size of tile (tsize x tsize pixels)
34    int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
35    int iw, ih; // size of image in pixels
36    int w, h; // size of grid image in pixels (represented by grid)
37    int gw, gh; // size of grid in tiles
38    Grid_Item *grid; // the grid (gw * gh items)
39    Eina_Bool dead : 1; // old grid. will die as soon as anim is over
40 };
41
42 struct _Widget_Data
43 {
44    Evas_Object *obj;
45    Evas_Object *scr;
46    Evas_Object *pan_smart;
47 <<<<<<< HEAD
48 =======
49    Evas_Object *gest;
50    double       gest_start;
51
52 >>>>>>> remotes/origin/upstream
53    Pan *pan;
54    Evas_Coord pan_x, pan_y, minw, minh;
55
56    double zoom;
57    Elm_Photocam_Zoom_Mode mode;
58 <<<<<<< HEAD
59 =======
60    Evas_Coord pvx, pvy, px, py, zoom_point_x, zoom_point_y;
61    struct
62    {
63       int imx, imy;
64       struct
65       {
66          int x_start, y_start;
67          int x_end, y_end;
68          double t_start;
69          double t_end;
70          Ecore_Animator *animator;
71       } bounce;
72    } gzoom;
73 >>>>>>> remotes/origin/upstream
74    const char *file;
75
76    Ecore_Job *calc_job;
77    Ecore_Timer *scr_timer;
78    Ecore_Timer *long_timer;
79    Ecore_Animator *zoom_animator;
80    double t_start, t_end;
81    struct
82    {
83       int imw, imh;
84       int w, h;
85       int ow, oh, nw, nh;
86       struct
87       {
88          double x, y;
89       } spos;
90    } size;
91    struct
92    {
93       Eina_Bool show : 1;
94       Evas_Coord x, y ,w ,h;
95    } show;
96    int tsize;
97    Evas_Object *img; // low res version of image (scale down == 8)
98    int nosmooth;
99    int preload_num;
100    Eina_List *grids;
101    Eina_Bool main_load_pending : 1;
102    Eina_Bool resized : 1;
103    Eina_Bool longpressed : 1;
104    Eina_Bool on_hold : 1;
105    Eina_Bool paused : 1;
106    Eina_Bool do_region : 1;
107 <<<<<<< HEAD
108 =======
109    Eina_Bool do_gesture : 1;
110    Eina_Bool zoom_gest : 1;
111 >>>>>>> remotes/origin/upstream
112 };
113
114 struct _Pan
115 {
116    Evas_Object_Smart_Clipped_Data __clipped_data;
117    Widget_Data *wd;
118 };
119
120 static const char *widtype = NULL;
121 static void _del_hook(Evas_Object *obj);
122 static void _theme_hook(Evas_Object *obj);
123 static void _on_focus_hook(void *data, Evas_Object *obj);
124 //static void _show_region_hook(void *data, Evas_Object *obj);
125 static void _sizing_eval(Evas_Object *obj);
126 static void _calc_job(void *data);
127 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
128                              Evas_Callback_Type type, void *event_info);
129 static void grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh);
130 static void grid_clear(Evas_Object *obj, Grid *g);
131 static Grid *grid_create(Evas_Object *obj);
132 static void grid_load(Evas_Object *obj, Grid *g);
133
134 static const char SIG_CLICKED[] = "clicked";
135 static const char SIG_PRESS[] = "press";
136 static const char SIG_LONGPRESSED[] = "longpressed";
137 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
138 static const char SIG_LOAD[] = "load";
139 static const char SIG_LOADED[] = "loaded";
140 static const char SIG_LOAD_DETAIL[] = "load,detail";
141 static const char SIG_LOADED_DETAIL[] = "loaded,detail";
142 static const char SIG_ZOOM_START[] = "zoom,start";
143 static const char SIG_ZOOM_STOP[] = "zoom,stop";
144 static const char SIG_ZOOM_CHANGE[] = "zoom,change";
145 static const char SIG_SCROLL[] = "scroll";
146 static const char SIG_SCROLL_ANIM_START[] = "scroll,anim,start";
147 static const char SIG_SCROLL_ANIM_STOP[] = "scroll,anim,stop";
148 static const char SIG_SCROLL_DRAG_START[] = "scroll,drag,start";
149 static const char SIG_SCROLL_DRAG_STOP[] = "scroll,drag,stop";
150
151 static const Evas_Smart_Cb_Description _signals[] = {
152    {SIG_CLICKED, ""},
153    {SIG_PRESS, ""},
154    {SIG_LONGPRESSED, ""},
155    {SIG_CLICKED_DOUBLE, ""},
156    {SIG_LOAD, ""},
157    {SIG_LOADED, ""},
158    {SIG_LOAD_DETAIL, ""},
159    {SIG_LOADED_DETAIL, ""},
160    {SIG_ZOOM_START, ""},
161    {SIG_ZOOM_STOP, ""},
162    {SIG_ZOOM_CHANGE, ""},
163    {SIG_SCROLL, ""},
164    {SIG_SCROLL_ANIM_START, ""},
165    {SIG_SCROLL_ANIM_STOP, ""},
166    {SIG_SCROLL_DRAG_START, ""},
167    {SIG_SCROLL_DRAG_STOP, ""},
168    {NULL, NULL}
169 };
170
171
172 static int
173 nearest_pow2(int num)
174 {
175    unsigned int n = num - 1;
176    n |= n >> 1;
177    n |= n >> 2;
178    n |= n >> 4;
179    n |= n >> 8;
180    n |= n >> 16;
181    return n + 1;
182 }
183
184 static void
185 img_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
186 {
187    Widget_Data *wd = elm_widget_data_get(obj);
188    Evas_Coord ax, ay, gw, gh;
189    if (!wd) return;
190    ax = 0;
191    ay = 0;
192    gw = wd->size.w;
193    gh = wd->size.h;
194 <<<<<<< HEAD
195    if (ow > gw) ax = (ow - gw) / 2;
196    if (oh > gh) ay = (oh - gh) / 2;
197 =======
198    if (!wd->zoom_gest)
199      {
200         if (ow > gw) ax = (ow - gw) / 2;
201         if (oh > gh) ay = (oh - gh) / 2;
202      }
203 >>>>>>> remotes/origin/upstream
204    evas_object_move(wd->img, ox + 0 - px + ax, oy + 0 - py + ay);
205    evas_object_resize(wd->img, gw, gh);
206
207    if (wd->show.show)
208      {
209         wd->show.show = EINA_FALSE;
210         elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
211      }
212 }
213
214 static void
215 grid_place(Evas_Object *obj, Grid *g, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
216 {
217    Widget_Data *wd = elm_widget_data_get(obj);
218    Evas_Coord ax, ay, gw, gh, tx, ty;
219    int x, y;
220    if (!wd) return;
221    ax = 0;
222    ay = 0;
223    gw = wd->size.w;
224    gh = wd->size.h;
225 <<<<<<< HEAD
226    if (ow > gw) ax = (ow - gw) / 2;
227    if (oh > gh) ay = (oh - gh) / 2;
228 =======
229    if (!wd->zoom_gest)
230      {
231         if (ow > gw) ax = (ow - gw) / 2;
232         if (oh > gh) ay = (oh - gh) / 2;
233      }
234 >>>>>>> remotes/origin/upstream
235    for (y = 0; y < g->gh; y++)
236      {
237         for (x = 0; x < g->gw; x++)
238           {
239              int tn, xx, yy, ww, hh;
240
241              tn = (y * g->gw) + x;
242              xx = g->grid[tn].out.x;
243              yy = g->grid[tn].out.y;
244              ww = g->grid[tn].out.w;
245              hh = g->grid[tn].out.h;
246              if ((gw != g->w) && (g->w > 0))
247                {
248                   tx = xx;
249                   xx = (gw * xx) / g->w;
250                   ww = ((gw * (tx + ww)) / g->w) - xx;
251                }
252              if ((gh != g->h) && (g->h > 0))
253                {
254                   ty = yy;
255                   yy = (gh * yy) / g->h;
256                   hh = ((gh * (ty + hh)) / g->h) - yy;
257                }
258              evas_object_move(g->grid[tn].img,
259                               ox + xx - px + ax,
260                               oy + yy - py + ay);
261              evas_object_resize(g->grid[tn].img, ww, hh);
262           }
263      }
264 }
265
266 static void
267 grid_clear(Evas_Object *obj, Grid *g)
268 {
269    Widget_Data *wd = elm_widget_data_get(obj);
270    int x, y;
271    if (!wd) return;
272    if (!g->grid) return;
273    for (y = 0; y < g->gh; y++)
274      {
275         for (x = 0; x < g->gw; x++)
276           {
277              int tn;
278
279              tn = (y * g->gw) + x;
280              evas_object_del(g->grid[tn].img);
281              if (g->grid[tn].want)
282                {
283                   wd->preload_num--;
284                   if (!wd->preload_num)
285                     {
286                        edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
287                                                "elm,state,busy,stop", "elm");
288                        evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
289                     }
290                }
291           }
292      }
293    free(g->grid);
294    g->grid = NULL;
295    g->gw = 0;
296    g->gh = 0;
297 }
298
299 static void
300 _tile_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
301 {
302    Grid_Item *git = data;
303
304    if (git->want)
305      {
306         git->want = 0;
307         evas_object_show(git->img);
308         git->have = 1;
309         git->wd->preload_num--;
310         if (!git->wd->preload_num)
311           {
312              edje_object_signal_emit(elm_smart_scroller_edje_object_get(git->wd->scr),
313                                      "elm,state,busy,stop", "elm");
314              evas_object_smart_callback_call(git->wd->obj, SIG_LOADED_DETAIL, NULL);
315           }
316      }
317 }
318
319 static int
320 grid_zoom_calc(double zoom)
321 {
322    int z = zoom;
323    if (z < 1) z = 1;
324    return nearest_pow2(z);
325 }
326
327 static Grid *
328 grid_create(Evas_Object *obj)
329 {
330    Widget_Data *wd = elm_widget_data_get(obj);
331    int x, y;
332    Grid *g;
333
334    if (!wd) return NULL;
335    g = calloc(1, sizeof(Grid));
336    if (!g) return NULL;
337
338    g->zoom = grid_zoom_calc(wd->zoom);
339    g->tsize = wd->tsize;
340    g->iw = wd->size.imw;
341    g->ih = wd->size.imh;
342
343    g->w = g->iw / g->zoom;
344    g->h = g->ih / g->zoom;
345    if (g->zoom >= 8)
346      {
347         free(g);
348         return NULL;
349      }
350    if (wd->do_region)
351      {
352         g->gw = (g->w + g->tsize - 1) / g->tsize;
353         g->gh = (g->h + g->tsize - 1) / g->tsize;
354      }
355    else
356      {
357         g->gw = 1;
358         g->gh = 1;
359      }
360    g->grid = calloc(1, sizeof(Grid_Item) * g->gw * g->gh);
361    if (!g->grid)
362      {
363         g->gw = 0;
364         g->gh = 0;
365         return g;
366      }
367    for (y = 0; y < g->gh; y++)
368      {
369         for (x = 0; x < g->gw; x++)
370           {
371              int tn;
372
373              tn = (y * g->gw) + x;
374              g->grid[tn].src.x = x * g->tsize;
375              if (x == (g->gw - 1))
376                g->grid[tn].src.w = g->w - ((g->gw - 1) * g->tsize);
377              else
378                g->grid[tn].src.w = g->tsize;
379              g->grid[tn].src.y = y * g->tsize;
380              if (y == (g->gh - 1))
381                g->grid[tn].src.h = g->h - ((g->gh - 1) * g->tsize);
382              else
383                g->grid[tn].src.h = g->tsize;
384
385              g->grid[tn].out.x = g->grid[tn].src.x;
386              g->grid[tn].out.y = g->grid[tn].src.y;
387              g->grid[tn].out.w = g->grid[tn].src.w;
388              g->grid[tn].out.h = g->grid[tn].src.h;
389
390              g->grid[tn].wd = wd;
391              g->grid[tn].img =
392                 evas_object_image_add(evas_object_evas_get(obj));
393              evas_object_image_load_orientation_set(g->grid[tn].img, EINA_TRUE);
394              evas_object_image_scale_hint_set
395                 (g->grid[tn].img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
396              evas_object_pass_events_set(g->grid[tn].img, EINA_TRUE);
397              evas_object_smart_member_add(g->grid[tn].img,
398                                           wd->pan_smart);
399              elm_widget_sub_object_add(obj, g->grid[tn].img);
400              evas_object_image_filled_set(g->grid[tn].img, 1);
401              evas_object_event_callback_add(g->grid[tn].img,
402                                             EVAS_CALLBACK_IMAGE_PRELOADED,
403                                             _tile_preloaded,
404                                             &(g->grid[tn]));
405           }
406      }
407    return g;
408 }
409
410 static void
411 grid_load(Evas_Object *obj, Grid *g)
412 {
413    Widget_Data *wd = elm_widget_data_get(obj);
414    int x, y;
415    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, gw, gh, tx, ty;
416    if (!wd) return;
417    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
418    evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
419    gw = wd->size.w;
420    gh = wd->size.h;
421    for (y = 0; y < g->gh; y++)
422      {
423         for (x = 0; x < g->gw; x++)
424           {
425              int tn, xx, yy, ww, hh;
426              Eina_Bool visible = EINA_FALSE;
427
428              tn = (y * g->gw) + x;
429              xx = g->grid[tn].out.x;
430              yy = g->grid[tn].out.y;
431              ww = g->grid[tn].out.w;
432              hh = g->grid[tn].out.h;
433              if ((gw != g->w) && (g->w > 0))
434                {
435                   tx = xx;
436                   xx = (gw * xx) / g->w;
437                   ww = ((gw * (tx + ww)) / g->w) - xx;
438                }
439              if ((gh != g->h) && (g->h > 0))
440                {
441                   ty = yy;
442                   yy = (gh * yy) / g->h;
443                   hh = ((gh * (ty + hh)) / g->h) - yy;
444                }
445              if (ELM_RECTS_INTERSECT(xx - wd->pan_x + ox,
446                                      yy  - wd->pan_y + oy,
447                                      ww, hh,
448                                      cvx, cvy, cvw, cvh))
449                visible = 1;
450              if ((visible) && (!g->grid[tn].have) && (!g->grid[tn].want))
451                {
452                   g->grid[tn].want = 1;
453                   evas_object_hide(g->grid[tn].img);
454                   evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
455                   evas_object_image_load_scale_down_set(g->grid[tn].img, g->zoom);
456                   evas_object_image_load_region_set(g->grid[tn].img,
457                                                     g->grid[tn].src.x,
458                                                     g->grid[tn].src.y,
459                                                     g->grid[tn].src.w,
460                                                     g->grid[tn].src.h);
461                   evas_object_image_file_set(g->grid[tn].img, wd->file, NULL);
462                   evas_object_image_preload(g->grid[tn].img, 0);
463                   wd->preload_num++;
464                   if (wd->preload_num == 1)
465                     {
466                        edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
467                                                "elm,state,busy,start", "elm");
468                        evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
469                     }
470                }
471              else if ((g->grid[tn].want) && (!visible))
472                {
473                   wd->preload_num--;
474                   if (!wd->preload_num)
475                     {
476                        edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
477                                                "elm,state,busy,stop", "elm");
478                        evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
479                     }
480                   g->grid[tn].want = 0;
481                   evas_object_hide(g->grid[tn].img);
482                   evas_object_image_preload(g->grid[tn].img, 1);
483                   evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
484                }
485              else if ((g->grid[tn].have) && (!visible))
486                {
487                   g->grid[tn].have = 0;
488                   evas_object_hide(g->grid[tn].img);
489                   evas_object_image_preload(g->grid[tn].img, 1);
490                   evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
491                }
492           }
493      }
494 }
495
496 static void
497 grid_clearall(Evas_Object *obj)
498 {
499    Widget_Data *wd = elm_widget_data_get(obj);
500    Grid *g;
501    if (!wd) return;
502    EINA_LIST_FREE(wd->grids, g)
503      {
504         grid_clear(obj, g);
505         free(g);
506      }
507 }
508
509 static void
510 _smooth_update(Evas_Object *obj)
511 {
512    Widget_Data *wd = elm_widget_data_get(obj);
513    int x, y;
514    Eina_List *l;
515    Grid *g;
516    if (!wd) return;
517    EINA_LIST_FOREACH(wd->grids, l, g)
518      {
519         for (y = 0; y < g->gh; y++)
520           {
521              for (x = 0; x < g->gw; x++)
522                {
523                   int tn;
524
525                   tn = (y * g->gw) + x;
526                   evas_object_image_smooth_scale_set(g->grid[tn].img, (!wd->nosmooth));
527                }
528           }
529      }
530    evas_object_image_smooth_scale_set(wd->img, (!wd->nosmooth));
531 }
532
533 static void
534 _grid_raise(Grid *g)
535 {
536    int x, y;
537
538    for (y = 0; y < g->gh; y++)
539      {
540         for (x = 0; x < g->gw; x++)
541           {
542              int tn;
543
544              tn = (y * g->gw) + x;
545              evas_object_raise(g->grid[tn].img);
546           }
547      }
548 }
549
550 static Eina_Bool
551 _scr_timeout(void *data)
552 {
553    Widget_Data *wd = elm_widget_data_get(data);
554    if (!wd) return ECORE_CALLBACK_CANCEL;
555    wd->nosmooth--;
556    if (!wd->nosmooth) _smooth_update(data);
557    wd->scr_timer = NULL;
558    return ECORE_CALLBACK_CANCEL;
559 }
560
561 static void
562 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
563 {
564    Widget_Data *wd = elm_widget_data_get(data);
565    if (!wd) return;
566    if (!wd->scr_timer)
567      {
568         wd->nosmooth++;
569         if (wd->nosmooth == 1) _smooth_update(data);
570      }
571    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
572    wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
573 }
574
575 static void
576 _main_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
577 {
578    Evas_Object *obj = data;
579    Widget_Data *wd = elm_widget_data_get(obj);
580    Grid *g;
581    if (!wd) return;
582    evas_object_show(wd->img);
583    wd->main_load_pending = 0;
584    g = grid_create(obj);
585    if (g)
586      {
587         wd->grids = eina_list_prepend(wd->grids, g);
588         grid_load(wd->obj, g);
589      }
590    if (wd->calc_job) ecore_job_del(wd->calc_job);
591    wd->calc_job = ecore_job_add(_calc_job, wd);
592    evas_object_smart_callback_call(data, SIG_LOADED, NULL);
593    wd->preload_num--;
594    if (!wd->preload_num)
595      {
596         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
597                                 "elm,state,busy,stop", "elm");
598         evas_object_smart_callback_call(obj, SIG_LOADED_DETAIL, NULL);
599      }
600 }
601
602 static Eina_Bool
603 zoom_do(Evas_Object *obj, double t)
604 {
605    Widget_Data *wd = elm_widget_data_get(obj);
606    Evas_Coord xx, yy, ow, oh;
607    if (!wd) return ECORE_CALLBACK_CANCEL;
608    wd->size.w = (wd->size.ow * (1.0 - t)) + (wd->size.nw * t);
609    wd->size.h = (wd->size.oh * (1.0 - t)) + (wd->size.nh * t);
610    elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
611    xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
612    yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
613    if (xx < 0) xx = 0;
614    else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
615    if (yy < 0) yy = 0;
616    else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
617
618    wd->show.show = EINA_TRUE;
619    wd->show.x = xx;
620    wd->show.y = yy;
621    wd->show.w = ow;
622    wd->show.h = oh;
623
624    if (wd->calc_job) ecore_job_del(wd->calc_job);
625    wd->calc_job = ecore_job_add(_calc_job, wd);
626    if (t >= 1.0)
627      {
628         Eina_List *l, *l_next;
629         Grid *g;
630
631         EINA_LIST_FOREACH_SAFE(wd->grids, l, l_next, g)
632           {
633              if (g->dead)
634                {
635                   wd->grids = eina_list_remove_list(wd->grids, l);
636                   grid_clear(obj, g);
637                   free(g);
638                }
639           }
640         return ECORE_CALLBACK_CANCEL;
641      }
642    return ECORE_CALLBACK_RENEW;
643 }
644
645
646 static Eina_Bool
647 _zoom_anim(void *data)
648 {
649    Evas_Object *obj = data;
650    Widget_Data *wd = elm_widget_data_get(obj);
651    double t;
652    Eina_Bool go;
653    if (!wd) return ECORE_CALLBACK_CANCEL;
654    t = ecore_loop_time_get();
655    if (t >= wd->t_end)
656      t = 1.0;
657    else if (wd->t_end > wd->t_start)
658      t = (t - wd->t_start) / (wd->t_end - wd->t_start);
659    else
660      t = 1.0;
661    t = 1.0 - t;
662    t = 1.0 - (t * t);
663    go = zoom_do(obj, t);
664    if (!go)
665      {
666         wd->nosmooth--;
667         if (!wd->nosmooth) _smooth_update(data);
668         wd->zoom_animator = NULL;
669         evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
670      }
671    return go;
672 }
673
674 static void
675 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
676 {
677    Widget_Data *wd = elm_widget_data_get(data);
678    //   Evas_Event_Mouse_Move *ev = event_info;
679    if (!wd) return;
680 }
681
682 static Eina_Bool
683 _long_press(void *data)
684 {
685    Widget_Data *wd = elm_widget_data_get(data);
686    if (!wd) return ECORE_CALLBACK_CANCEL;
687    wd->long_timer = NULL;
688    wd->longpressed = EINA_TRUE;
689    evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
690    return ECORE_CALLBACK_CANCEL;
691 }
692
693 static void
694 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
695 {
696    Widget_Data *wd = elm_widget_data_get(data);
697    Evas_Event_Mouse_Down *ev = event_info;
698    if (!wd) return;
699    if (ev->button != 1) return;
700    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
701    else wd->on_hold = EINA_FALSE;
702    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
703      evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
704    else
705      evas_object_smart_callback_call(data, SIG_PRESS, NULL);
706    wd->longpressed = EINA_FALSE;
707    if (wd->long_timer) ecore_timer_del(wd->long_timer);
708    wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
709 }
710
711 static void
712 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
713 {
714    Widget_Data *wd = elm_widget_data_get(data);
715    Evas_Event_Mouse_Up *ev = event_info;
716    if (!wd) return;
717    if (ev->button != 1) return;
718    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
719    else wd->on_hold = EINA_FALSE;
720    if (wd->long_timer)
721      {
722         ecore_timer_del(wd->long_timer);
723         wd->long_timer = NULL;
724      }
725    if (!wd->on_hold)
726      evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
727    wd->on_hold = EINA_FALSE;
728 }
729
730 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
731
732 static void
733 _del_hook(Evas_Object *obj)
734 {
735    Widget_Data *wd = elm_widget_data_get(obj);
736    Grid *g;
737    if (!wd) return;
738    EINA_LIST_FREE(wd->grids, g)
739      {
740         if (g->grid) free(g->grid);
741         free(g);
742      }
743    evas_object_del(wd->pan_smart);
744    wd->pan_smart = NULL;
745    if (wd->file) eina_stringshare_del(wd->file);
746    if (wd->calc_job) ecore_job_del(wd->calc_job);
747    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
748    if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
749 <<<<<<< HEAD
750 =======
751    if (wd->gzoom.bounce.animator) ecore_animator_del(wd->gzoom.bounce.animator);
752 >>>>>>> remotes/origin/upstream
753    if (wd->long_timer) ecore_timer_del(wd->long_timer);
754    free(wd);
755 }
756
757 static void
758 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
759 {
760    Widget_Data *wd = elm_widget_data_get(obj);
761    if (!wd) return;
762    if (elm_widget_focus_get(obj))
763      {
764         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,focus", "elm");
765         evas_object_focus_set(wd->obj, EINA_TRUE);
766      }
767    else
768      {
769         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr), "elm,action,unfocus", "elm");
770         evas_object_focus_set(wd->obj, EINA_FALSE);
771      }
772 }
773
774 static void
775 _theme_hook(Evas_Object *obj)
776 {
777    Widget_Data *wd = elm_widget_data_get(obj);
778    if (!wd) return;
779    elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", elm_widget_style_get(obj));
780    //   edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
781    _sizing_eval(obj);
782 }
783
784 /*
785 static void
786 _show_region_hook(void *data, Evas_Object *obj)
787 {
788    Widget_Data *wd = elm_widget_data_get(data);
789    Evas_Coord x, y, w, h;
790    if (!wd) return;
791    elm_widget_show_region_get(obj, &x, &y, &w, &h);
792    elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
793 }
794 */
795
796 static void
797 _sizing_eval(Evas_Object *obj)
798 {
799    Widget_Data *wd = elm_widget_data_get(obj);
800    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
801    if (!wd) return;
802    //   evas_object_size_hint_min_get(wd->scr, &minw, &minh);
803    evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
804    //   minw = -1;
805    //   minh = -1;
806    //   if (wd->mode != ELM_LIST_LIMIT) minw = -1;
807    evas_object_size_hint_min_set(obj, minw, minh);
808    evas_object_size_hint_max_set(obj, maxw, maxh);
809 }
810
811 static void
812 _calc_job(void *data)
813 {
814    Widget_Data *wd = data;
815    Evas_Coord minw, minh;
816    if (!wd) return;
817    minw = wd->size.w;
818    minh = wd->size.h;
819    if (wd->resized)
820      {
821         wd->resized = 0;
822         if (wd->mode != ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
823           {
824              double tz = wd->zoom;
825              wd->zoom = 0.0;
826              elm_photocam_zoom_set(wd->obj, tz);
827           }
828      }
829    if ((minw != wd->minw) || (minh != wd->minh))
830      {
831         wd->minw = minw;
832         wd->minh = minh;
833         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
834         _sizing_eval(wd->obj);
835      }
836    wd->calc_job = NULL;
837    evas_object_smart_changed(wd->pan_smart);
838 }
839
840 static void
841 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
842 {
843    Pan *sd = evas_object_smart_data_get(obj);
844    if (!sd) return;
845    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
846    sd->wd->pan_x = x;
847    sd->wd->pan_y = y;
848    evas_object_smart_changed(obj);
849 }
850
851 static void
852 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
853 {
854    Pan *sd = evas_object_smart_data_get(obj);
855    if (!sd) return;
856    if (x) *x = sd->wd->pan_x;
857    if (y) *y = sd->wd->pan_y;
858 }
859
860 static void
861 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
862 {
863    Pan *sd = evas_object_smart_data_get(obj);
864    Evas_Coord ow, oh;
865    if (!sd) return;
866    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
867    ow = sd->wd->minw - ow;
868    if (ow < 0) ow = 0;
869    oh = sd->wd->minh - oh;
870    if (oh < 0) oh = 0;
871    if (x) *x = ow;
872    if (y) *y = oh;
873 }
874
875 static void
876 _pan_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
877 {
878    if (x) *x = 0;
879    if (y) *y = 0;
880 }
881
882 static void
883 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
884 {
885    Pan *sd = evas_object_smart_data_get(obj);
886    if (!sd) return;
887    if (w) *w = sd->wd->minw;
888    if (h) *h = sd->wd->minh;
889 }
890
891 static void
892 _pan_add(Evas_Object *obj)
893 {
894    Pan *sd;
895    Evas_Object_Smart_Clipped_Data *cd;
896    _pan_sc.add(obj);
897    cd = evas_object_smart_data_get(obj);
898    if (!cd) return;
899    sd = calloc(1, sizeof(Pan));
900    if (!sd) return;
901    sd->__clipped_data = *cd;
902    free(cd);
903    evas_object_smart_data_set(obj, sd);
904 }
905
906 static void
907 _pan_del(Evas_Object *obj)
908 {
909    Pan *sd = evas_object_smart_data_get(obj);
910    if (!sd) return;
911    _pan_sc.del(obj);
912 }
913
914 static void
915 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
916 {
917    Pan *sd = evas_object_smart_data_get(obj);
918    Evas_Coord ow, oh;
919    if (!sd) return;
920    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
921    if ((ow == w) && (oh == h)) return;
922    sd->wd->resized = 1;
923    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
924    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
925 }
926
927 static void
928 _pan_calculate(Evas_Object *obj)
929 {
930    Pan *sd = evas_object_smart_data_get(obj);
931    Evas_Coord ox, oy, ow, oh;
932    Eina_List *l;
933    Grid *g;
934    if (!sd) return;
935    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
936 <<<<<<< HEAD
937    img_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
938    EINA_LIST_FOREACH(sd->wd->grids, l, g)
939      {
940         grid_load(sd->wd->obj, g);
941         grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
942 =======
943    img_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y,
944              ox - sd->wd->gzoom.imx, oy - sd->wd->gzoom.imy, ow, oh);
945    EINA_LIST_FOREACH(sd->wd->grids, l, g)
946      {
947         grid_load(sd->wd->obj, g);
948         grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y,
949                    ox - sd->wd->gzoom.imx, oy - sd->wd->gzoom.imy, ow, oh);
950 >>>>>>> remotes/origin/upstream
951      }
952 }
953
954 static void
955 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
956 {
957    Pan *sd = evas_object_smart_data_get(obj);
958    if (!sd) return;
959    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
960    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
961 }
962
963 static void
964 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
965 {
966    Widget_Data *wd = elm_widget_data_get(obj);
967    if (!wd) return;
968    elm_smart_scroller_hold_set(wd->scr, 1);
969 }
970
971 static void
972 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
973 {
974    Widget_Data *wd = elm_widget_data_get(obj);
975    if (!wd) return;
976    elm_smart_scroller_hold_set(wd->scr, 0);
977 }
978
979 static void
980 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
981 {
982    Widget_Data *wd = elm_widget_data_get(obj);
983    if (!wd) return;
984    elm_smart_scroller_freeze_set(wd->scr, 1);
985 }
986
987 static void
988 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
989 {
990    Widget_Data *wd = elm_widget_data_get(obj);
991    if (!wd) return;
992    elm_smart_scroller_freeze_set(wd->scr, 0);
993 }
994
995 static void
996 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
997 {
998    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_START, NULL);
999 }
1000
1001 static void
1002 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1003 {
1004    evas_object_smart_callback_call(data, SIG_SCROLL_ANIM_STOP, NULL);
1005 }
1006
1007 static void
1008 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1009 {
1010    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_START, NULL);
1011 }
1012
1013 static void
1014 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1015 {
1016    evas_object_smart_callback_call(data, SIG_SCROLL_DRAG_STOP, NULL);
1017 }
1018
1019 static void
1020 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1021 {
1022    evas_object_smart_callback_call(data, SIG_SCROLL, NULL);
1023 }
1024
1025 static Eina_Bool
1026 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__,
1027             Evas_Callback_Type type, void *event_info)
1028 {
1029    double zoom;
1030    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
1031    Evas_Event_Key_Down *ev = event_info;
1032    Widget_Data *wd = elm_widget_data_get(obj);
1033    if (!wd) return EINA_FALSE;
1034    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
1035
1036    Evas_Coord x = 0;
1037    Evas_Coord y = 0;
1038    Evas_Coord step_x = 0;
1039    Evas_Coord step_y = 0;
1040    Evas_Coord v_w = 0;
1041    Evas_Coord v_h = 0;
1042    Evas_Coord page_x = 0;
1043    Evas_Coord page_y = 0;
1044
1045    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
1046    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
1047    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
1048    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
1049
1050    if ((!strcmp(ev->keyname, "Left")) ||
1051        (!strcmp(ev->keyname, "KP_Left")))
1052      {
1053         x -= step_x;
1054      }
1055    else if ((!strcmp(ev->keyname, "Right")) ||
1056             (!strcmp(ev->keyname, "KP_Right")))
1057      {
1058         x += step_x;
1059      }
1060    else if ((!strcmp(ev->keyname, "Up"))  ||
1061             (!strcmp(ev->keyname, "KP_Up")))
1062      {
1063         y -= step_y;
1064      }
1065    else if ((!strcmp(ev->keyname, "Down")) ||
1066             (!strcmp(ev->keyname, "KP_Down")))
1067      {
1068         y += step_y;
1069      }
1070    else if ((!strcmp(ev->keyname, "Prior")) ||
1071             (!strcmp(ev->keyname, "KP_Prior")))
1072      {
1073         if (page_y < 0)
1074           y -= -(page_y * v_h) / 100;
1075         else
1076           y -= page_y;
1077      }
1078    else if ((!strcmp(ev->keyname, "Next")) ||
1079             (!strcmp(ev->keyname, "KP_Next")))
1080      {
1081         if (page_y < 0)
1082           y += -(page_y * v_h) / 100;
1083         else
1084           y += page_y;
1085      }
1086    else if ((!strcmp(ev->keyname, "KP_Add")))
1087      {
1088         zoom = elm_photocam_zoom_get(obj);
1089         zoom -= 0.5;
1090         elm_photocam_zoom_mode_set(obj, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
1091         elm_photocam_zoom_set(obj, zoom);
1092         return EINA_TRUE;
1093      }
1094    else if ((!strcmp(ev->keyname, "KP_Subtract")))
1095      {
1096         zoom = elm_photocam_zoom_get(obj);
1097         zoom += 0.5;
1098         elm_photocam_zoom_mode_set(obj, ELM_PHOTOCAM_ZOOM_MODE_MANUAL);
1099         elm_photocam_zoom_set(obj, zoom);
1100         return EINA_TRUE;
1101      }
1102    else return EINA_FALSE;
1103
1104    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1105    elm_smart_scroller_child_pos_set(wd->scr, x, y);
1106
1107    return EINA_TRUE;
1108 }
1109
1110 <<<<<<< HEAD
1111 =======
1112 Eina_Bool
1113 _bounce_eval(void *_wd)
1114 {
1115    Widget_Data *wd = (Widget_Data *)_wd;
1116    double t, tt;
1117
1118    if (!wd) return ECORE_CALLBACK_CANCEL;
1119    if ((wd->gzoom.imx == wd->gzoom.bounce.x_end) &&
1120        (wd->gzoom.imy == wd->gzoom.bounce.y_end))
1121      {
1122         wd->gzoom.imx = 0;
1123         wd->gzoom.imy = 0;
1124         wd->zoom_gest = EINA_FALSE;
1125         wd->gzoom.bounce.animator = NULL;
1126         _freeze_off(NULL, wd->obj, NULL);
1127         return ECORE_CALLBACK_CANCEL;
1128      }
1129
1130    t = ecore_loop_time_get();
1131    tt = (t - wd->gzoom.bounce.t_start) / (wd->gzoom.bounce.t_end - wd->gzoom.bounce.t_start);
1132    tt = 1.0 - tt;
1133    tt = 1.0 - (tt * tt);
1134
1135    if (t > wd->gzoom.bounce.t_end)
1136      {
1137         wd->gzoom.imx = 0;
1138         wd->gzoom.imy = 0;
1139         wd->zoom_gest = EINA_FALSE;
1140         _freeze_off(NULL, wd->obj, NULL);
1141         zoom_do(wd->obj, 1.0);
1142         wd->gzoom.bounce.animator = NULL;
1143         return ECORE_CALLBACK_CANCEL;
1144      }
1145
1146    if (wd->gzoom.imx != wd->gzoom.bounce.x_end)
1147      wd->gzoom.imx = wd->gzoom.bounce.x_start * (1.0 - tt) + wd->gzoom.bounce.x_end * tt;
1148
1149    if (wd->gzoom.imy != wd->gzoom.bounce.y_end)
1150      wd->gzoom.imy = wd->gzoom.bounce.y_start * (1.0 - tt) + wd->gzoom.bounce.y_end * tt;
1151
1152    zoom_do(wd->obj, 1.0 - (1.0 - tt));
1153    return ECORE_CALLBACK_RENEW;
1154 }
1155
1156 static void
1157 _gzoom(Widget_Data *_wd, Evas_Coord px, Evas_Coord py, Elm_Gesture_Zoom_Info* gest)
1158 {
1159    Widget_Data *wd = (Widget_Data *)_wd;
1160    Evas_Coord rx, ry, rw, rh;
1161    int regx, regy, regw, regh, ix, iy, iw, ih;
1162    int xx, yy;
1163
1164    if (!wd) return;
1165    wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1166    wd->zoom = wd->gest_start / gest->zoom;
1167    wd->size.ow = wd->size.w;
1168    wd->size.oh = wd->size.h;
1169    elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
1170    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1171    if ((rw <= 0) || (rh <= 0)) return;
1172
1173    wd->size.nw = (double)wd->size.imw / wd->zoom;
1174    wd->size.nh = (double)wd->size.imh / wd->zoom;
1175
1176    elm_photocam_image_region_get(wd->obj, &regx, &regy, &regw, &regh);
1177    evas_object_geometry_get(wd->img, &ix, &iy, &iw, &ih);
1178
1179    wd->pvx = gest->x;
1180    wd->pvy = gest->y;
1181
1182    xx = (px / wd->zoom) - wd->pvx;
1183    yy = (py / wd->zoom) - wd->pvy;
1184    wd->gzoom.imx = 0;
1185    wd->gzoom.imy = 0;
1186
1187    if ((xx < 0) || (rw > wd->size.nw))
1188      {
1189         wd->gzoom.imx = xx;
1190         xx = 0;
1191      }
1192    else if ((xx + rw) > wd->size.nw)
1193      {
1194         wd->gzoom.imx = xx + rw - wd->size.nw;
1195         xx = wd->size.nw - rw;
1196      }
1197
1198    if ((yy < 0) || (rh > wd->size.nh))
1199      {
1200         wd->gzoom.imy = yy;
1201         yy = 0;
1202      }
1203    else if ((yy + rh) > wd->size.nh)
1204      {
1205         wd->gzoom.imy = yy + rh - wd->size.nh;
1206         yy = wd->size.nh - rh;
1207      }
1208
1209    wd->size.spos.x = (double)(xx + (rw / 2)) / (double)(wd->size.nw);
1210    wd->size.spos.y = (double)(yy + (rh / 2)) / (double)(wd->size.nh);
1211
1212    zoom_do(wd->obj, 1.0);
1213 }
1214
1215 static Evas_Event_Flags
1216 _gzoom_start(void *_wd, void *event_info)
1217 {
1218    Widget_Data *wd = (Widget_Data *)_wd;
1219    Elm_Gesture_Zoom_Info *p = (Elm_Gesture_Zoom_Info *) event_info;
1220    Evas_Coord rw, rh;
1221    int x,y,w,h;
1222    double marginx = 0, marginy = 0;
1223
1224    if (wd->gzoom.bounce.animator)
1225      {
1226         ecore_animator_del(wd->gzoom.bounce.animator);
1227         wd->gzoom.bounce.animator = NULL;
1228      }
1229    wd->zoom_gest = EINA_TRUE;
1230    _freeze_on(NULL, wd->obj, NULL);
1231
1232    elm_photocam_image_region_get(wd->obj, &x, &y, &w, &h);
1233    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1234
1235    if (rw > wd->size.nw)
1236      marginx = (rw - wd->size.nw) / 2;
1237    if (rh > wd->size.nh)
1238      marginy = (rh - wd->size.nh) / 2;
1239
1240    wd->gest_start = wd->zoom;
1241
1242    wd->zoom_point_x = x + ((p->x - marginx) * wd->zoom) + wd->gzoom.imx;
1243    wd->zoom_point_y = y + ((p->y - marginy) * wd->zoom) + wd->gzoom.imy;
1244
1245    return EVAS_EVENT_FLAG_NONE;
1246 }
1247
1248 static Evas_Event_Flags
1249 _gzoom_move(void *_wd, void *event_info)
1250 {
1251    Widget_Data *wd = (Widget_Data *)_wd;
1252    Elm_Gesture_Zoom_Info *p = (Elm_Gesture_Zoom_Info *) event_info;
1253
1254    _gzoom(wd, wd->zoom_point_x, wd->zoom_point_y, p);
1255    return EVAS_EVENT_FLAG_NONE;
1256 }
1257
1258 static Evas_Event_Flags
1259 _gzoom_end(void *_wd, void *event_info __UNUSED__)
1260 {
1261    Widget_Data *wd = (Widget_Data *)_wd;
1262    Evas_Coord rw, rh;
1263
1264    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1265    wd->gest_start = 1.0;
1266
1267    if (wd->gzoom.imx || wd->gzoom.imy)
1268      {
1269         double t;
1270
1271         t = ecore_loop_time_get();
1272         wd->gzoom.bounce.x_start = wd->gzoom.imx;
1273         wd->gzoom.bounce.y_start = wd->gzoom.imy;
1274         wd->gzoom.bounce.x_end = 0;
1275         wd->gzoom.bounce.y_end = 0;
1276
1277         if (rw > wd->size.nw &&
1278             rh > wd->size.nh)
1279           {
1280              Evas_Coord pw, ph;
1281              double z;
1282
1283              if ((wd->size.imw < rw) && (wd->size.imh < rh))
1284                {
1285                   wd->zoom = 1;
1286                   wd->size.nw = wd->size.imw;
1287                   wd->size.nh = wd->size.imh;
1288                }
1289              else
1290                {
1291                   ph = (wd->size.imh * rw) / wd->size.imw;
1292                   if (ph > rh)
1293                     {
1294                        pw = (wd->size.imw * rh) / wd->size.imh;
1295                        ph = rh;
1296                     }
1297                   else
1298                     {
1299                        pw = rw;
1300                     }
1301                   if (wd->size.imw > wd->size.imh)
1302                     z = (double)wd->size.imw / pw;
1303                   else
1304                     z = (double)wd->size.imh / ph;
1305
1306                   wd->zoom = z;
1307                   wd->size.nw = pw;
1308                   wd->size.nh = ph;
1309                }
1310              wd->gzoom.bounce.x_end = (wd->size.nw - rw) / 2;
1311              wd->gzoom.bounce.y_end = (wd->size.nh - rh) / 2;
1312           }
1313         else
1314           {
1315              int xx, yy;
1316
1317              xx = (wd->zoom_point_x / wd->zoom) - wd->pvx;
1318              yy = (wd->zoom_point_y / wd->zoom) - wd->pvy;
1319
1320              if (xx < 0) xx = 0;
1321              if (yy < 0) yy = 0;
1322
1323              if (rw > wd->size.nw)
1324                wd->gzoom.bounce.x_end = (wd->size.nw -rw) / 2;
1325              if ((xx + rw) > wd->size.nw)
1326                xx = wd->size.nw - rw;
1327
1328              if (rh > wd->size.nh)
1329                wd->gzoom.bounce.y_end = (wd->size.nh - rh) / 2;
1330              if ((yy + rh) > wd->size.nh)
1331                yy = wd->size.nh - rh;
1332
1333              wd->size.spos.x = (double)(xx + (rw / 2)) / (double)(wd->size.nw);
1334              wd->size.spos.y = (double)(yy + (rh / 2)) / (double)(wd->size.nh);
1335           }
1336
1337         wd->gzoom.bounce.t_start = t;
1338         wd->gzoom.bounce.t_end = t + _elm_config->page_scroll_friction;
1339
1340         wd->gzoom.bounce.animator = ecore_animator_add(_bounce_eval, wd);
1341      }
1342    else
1343      {
1344         _freeze_off(NULL, wd->obj, NULL);
1345         wd->zoom_gest = EINA_FALSE;
1346      }
1347
1348    return EVAS_EVENT_FLAG_NONE;
1349 }
1350
1351 >>>>>>> remotes/origin/upstream
1352 EAPI Evas_Object *
1353 elm_photocam_add(Evas_Object *parent)
1354 {
1355    Evas_Object *obj;
1356    Evas *e;
1357    Widget_Data *wd;
1358    Evas_Coord minw, minh;
1359    static Evas_Smart *smart = NULL;
1360    Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
1361
1362    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1363
1364    ELM_SET_WIDTYPE(widtype, "photocam");
1365    elm_widget_type_set(obj, "photocam");
1366    elm_widget_sub_object_add(parent, obj);
1367    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1368    elm_widget_data_set(obj, wd);
1369    elm_widget_del_hook_set(obj, _del_hook);
1370    elm_widget_theme_hook_set(obj, _theme_hook);
1371    elm_widget_can_focus_set(obj, EINA_TRUE);
1372    elm_widget_event_hook_set(obj, _event_hook);
1373
1374    wd->scr = elm_smart_scroller_add(e);
1375    elm_smart_scroller_widget_set(wd->scr, obj);
1376    elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", "default");
1377    evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
1378    evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
1379    elm_widget_resize_object_set(obj, wd->scr);
1380
1381    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
1382    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
1383    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1384    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1385    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1386
1387    elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1388
1389    wd->obj = obj;
1390
1391    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1392    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1393    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1394    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1395
1396    if (!smart)
1397      {
1398         static Evas_Smart_Class sc;
1399
1400         evas_object_smart_clipped_smart_set(&_pan_sc);
1401         sc = _pan_sc;
1402         sc.name = "elm_photocam_pan";
1403         sc.version = EVAS_SMART_CLASS_VERSION;
1404         sc.add = _pan_add;
1405         sc.del = _pan_del;
1406         sc.resize = _pan_resize;
1407         sc.move = _pan_move;
1408         sc.calculate = _pan_calculate;
1409         smart = evas_smart_class_new(&sc);
1410      }
1411    if (smart)
1412      {
1413         wd->pan_smart = evas_object_smart_add(e, smart);
1414         wd->pan = evas_object_smart_data_get(wd->pan_smart);
1415         wd->pan->wd = wd;
1416      }
1417
1418    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1419                                      _pan_set, _pan_get, _pan_max_get,
1420                                      _pan_min_get, _pan_child_size_get);
1421
1422 <<<<<<< HEAD
1423    wd->zoom = 1;
1424    wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1425
1426 =======
1427    wd->zoom_gest = EINA_FALSE;
1428    wd->gest_start = 1.0;
1429    wd->zoom = 1;
1430    wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1431 >>>>>>> remotes/origin/upstream
1432    wd->tsize = 512;
1433
1434    wd->img = evas_object_image_add(e);
1435    evas_object_image_load_orientation_set(wd->img, EINA_TRUE);
1436    evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1437    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
1438                                   _mouse_down, obj);
1439    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
1440                                   _mouse_up, obj);
1441    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_MOVE,
1442                                   _mouse_move, obj);
1443    evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_STATIC);
1444    evas_object_smart_member_add(wd->img, wd->pan_smart);
1445    elm_widget_sub_object_add(obj, wd->img);
1446    evas_object_image_filled_set(wd->img, 1);
1447    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_IMAGE_PRELOADED,
1448                                   _main_preloaded, obj);
1449
1450    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
1451                              &minw, &minh);
1452    evas_object_size_hint_min_set(obj, minw, minh);
1453
1454    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1455
1456    _sizing_eval(obj);
1457    return obj;
1458 }
1459
1460 EAPI Evas_Load_Error
1461 elm_photocam_file_set(Evas_Object *obj, const char *file)
1462 {
1463    ELM_CHECK_WIDTYPE(obj, widtype) EVAS_LOAD_ERROR_NONE;
1464    Widget_Data *wd = elm_widget_data_get(obj);
1465    int w, h;
1466    if (!wd) return EVAS_LOAD_ERROR_GENERIC;
1467    if (!eina_stringshare_replace(&wd->file, file)) return EVAS_LOAD_ERROR_NONE;
1468    grid_clearall(obj);
1469
1470    evas_object_hide(wd->img);
1471    evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
1472    evas_object_image_file_set(wd->img, NULL, NULL);
1473    evas_object_image_load_scale_down_set(wd->img, 0);
1474    evas_object_image_file_set(wd->img, wd->file, NULL);
1475    evas_object_image_size_get(wd->img, &w, &h);
1476    wd->do_region = evas_object_image_region_support_get(wd->img);
1477    wd->size.imw = w;
1478    wd->size.imh = h;
1479    wd->size.w = wd->size.imw / wd->zoom;
1480    wd->size.h = wd->size.imh / wd->zoom;
1481 <<<<<<< HEAD
1482 =======
1483    if (wd->gzoom.bounce.animator)
1484      {
1485         ecore_animator_del(wd->gzoom.bounce.animator);
1486         wd->gzoom.bounce.animator = NULL;
1487      }
1488 >>>>>>> remotes/origin/upstream
1489    if (wd->zoom_animator)
1490      {
1491         wd->nosmooth--;
1492         if (wd->nosmooth == 0) _smooth_update(obj);
1493         ecore_animator_del(wd->zoom_animator);
1494         wd->zoom_animator = NULL;
1495      }
1496    evas_object_image_file_set(wd->img, NULL, NULL);
1497    evas_object_image_load_scale_down_set(wd->img, 8);
1498    evas_object_image_file_set(wd->img, wd->file, NULL);
1499    evas_object_image_preload(wd->img, 0);
1500    wd->main_load_pending = 1;
1501    if (wd->calc_job) ecore_job_del(wd->calc_job);
1502    wd->calc_job = ecore_job_add(_calc_job, wd);
1503    evas_object_smart_callback_call(obj, SIG_LOAD, NULL);
1504    wd->preload_num++;
1505    if (wd->preload_num == 1)
1506      {
1507         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1508                                 "elm,state,busy,start", "elm");
1509         evas_object_smart_callback_call(obj, SIG_LOAD_DETAIL, NULL);
1510      }
1511 <<<<<<< HEAD
1512      {
1513         double tz = wd->zoom;
1514         wd->zoom = 0.0;
1515         elm_photocam_zoom_set(wd->obj, tz);
1516      }
1517 =======
1518    {
1519       double tz = wd->zoom;
1520       wd->zoom = 0.0;
1521       elm_photocam_zoom_set(wd->obj, tz);
1522    }
1523 >>>>>>> remotes/origin/upstream
1524    return evas_object_image_load_error_get(wd->img);
1525 }
1526
1527 EAPI const char *
1528 elm_photocam_file_get(const Evas_Object *obj)
1529 {
1530    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1531    Widget_Data *wd = elm_widget_data_get(obj);
1532    if (!wd) return NULL;
1533    return wd->file;
1534 }
1535
1536 EAPI void
1537 elm_photocam_zoom_set(Evas_Object *obj, double zoom)
1538 {
1539    ELM_CHECK_WIDTYPE(obj, widtype);
1540    Widget_Data *wd = elm_widget_data_get(obj);
1541    Eina_List *l;
1542    Grid *g, *g_zoom = NULL;
1543    Evas_Coord pw, ph, rx, ry, rw, rh;
1544    double z;
1545    int zoom_changed = 0, started = 0;
1546    Ecore_Animator *an;
1547    if (!wd) return;
1548    if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1549    if (zoom == wd->zoom) return;
1550    wd->zoom = zoom;
1551    wd->size.ow = wd->size.w;
1552    wd->size.oh = wd->size.h;
1553    elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
1554    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1555    if ((rw <= 0) || (rh <= 0)) return;
1556
1557    if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
1558      {
1559         wd->size.nw = (double)wd->size.imw / wd->zoom;
1560         wd->size.nh = (double)wd->size.imh / wd->zoom;
1561      }
1562    else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT)
1563      {
1564         if ((wd->size.imw < 1) || (wd->size.imh < 1))
1565           {
1566              wd->size.nw = 0;
1567              wd->size.nh = 0;
1568           }
1569         else
1570           {
1571              ph = (wd->size.imh * rw) / wd->size.imw;
1572              if (ph > rh)
1573                {
1574                   pw = (wd->size.imw * rh) / wd->size.imh;
1575                   ph = rh;
1576                }
1577              else
1578                {
1579                   pw = rw;
1580                }
1581              if (wd->size.imw > wd->size.imh)
1582                z = (double)wd->size.imw / pw;
1583              else
1584                z = (double)wd->size.imh / ph;
1585              if (z != wd->zoom)
1586                zoom_changed = 1;
1587              wd->zoom = z;
1588              wd->size.nw = pw;
1589              wd->size.nh = ph;
1590           }
1591      }
1592    else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL)
1593      {
1594         if ((wd->size.imw < 1) || (wd->size.imh < 1))
1595           {
1596              wd->size.nw = 0;
1597              wd->size.nw = 0;
1598           }
1599         else
1600           {
1601              ph = (wd->size.imh * rw) / wd->size.imw;
1602              if (ph < rh)
1603                {
1604                   pw = (wd->size.imw * rh) / wd->size.imh;
1605                   ph = rh;
1606                }
1607              else
1608                {
1609                   pw = rw;
1610                }
1611              if (wd->size.imw > wd->size.imh)
1612                z = (double)wd->size.imw / pw;
1613              else
1614                z = (double)wd->size.imh / ph;
1615              if (z != wd->zoom)
1616                zoom_changed = 1;
1617              wd->zoom = z;
1618              wd->size.nw = pw;
1619              wd->size.nh = ph;
1620           }
1621      }
1622 <<<<<<< HEAD
1623 =======
1624    else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT_IN)
1625      {
1626         if ((wd->size.imw < 1) || (wd->size.imh < 1))
1627           {
1628              wd->size.nw = 0;
1629              wd->size.nh = 0;
1630           }
1631         else if ((wd->size.imw < rw) && (wd->size.imh < rh))
1632           {
1633              if (1 != wd->zoom) zoom_changed = 1;
1634              wd->zoom = 1;
1635              wd->size.nw = wd->size.imw;
1636              wd->size.nh = wd->size.imh;
1637           }
1638         else
1639           {
1640              ph = (wd->size.imh * rw) / wd->size.imw;
1641              if (ph > rh)
1642                {
1643                   pw = (wd->size.imw * rh) / wd->size.imh;
1644                   ph = rh;
1645                }
1646              else
1647                pw = rw;
1648              if (wd->size.imw > wd->size.imh)
1649                z = (double)wd->size.imw / pw;
1650              else
1651                z = (double)wd->size.imh / ph;
1652              if (z != wd->zoom)
1653                zoom_changed = 1;
1654              wd->zoom = z;
1655              wd->size.nw = pw;
1656              wd->size.nh = ph;
1657           }
1658      }
1659 >>>>>>> remotes/origin/upstream
1660    if (wd->main_load_pending)
1661      {
1662         wd->size.w = wd->size.nw;
1663         wd->size.h = wd->size.nh;
1664         goto done;
1665      }
1666    EINA_LIST_FOREACH(wd->grids, l, g)
1667      {
1668         if (g->zoom == grid_zoom_calc(wd->zoom))
1669           {
1670              wd->grids = eina_list_remove(wd->grids, g);
1671              wd->grids = eina_list_prepend(wd->grids, g);
1672              _grid_raise(g);
1673              goto done;
1674           }
1675      }
1676    g = grid_create(obj);
1677    if (g)
1678      {
1679         if (eina_list_count(wd->grids) > 1)
1680           {
1681              g_zoom = eina_list_last(wd->grids)->data;
1682              wd->grids = eina_list_remove(wd->grids, g_zoom);
1683              grid_clear(obj, g_zoom);
1684              free(g_zoom);
1685              EINA_LIST_FOREACH(wd->grids, l, g_zoom)
1686                {
1687                   g_zoom->dead = 1;
1688                }
1689           }
1690         wd->grids = eina_list_prepend(wd->grids, g);
1691      }
1692    else
1693      {
1694         EINA_LIST_FREE(wd->grids, g)
1695           {
1696              grid_clear(obj, g);
1697              free(g);
1698           }
1699      }
1700 <<<<<<< HEAD
1701 done:
1702 =======
1703  done:
1704 >>>>>>> remotes/origin/upstream
1705    wd->t_start = ecore_loop_time_get();
1706    wd->t_end = wd->t_start + _elm_config->zoom_friction;
1707    if ((wd->size.w > 0) && (wd->size.h > 0))
1708      {
1709         wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.w;
1710         wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.h;
1711      }
1712    else
1713      {
1714         wd->size.spos.x = 0.5;
1715         wd->size.spos.y = 0.5;
1716      }
1717    if (rw > wd->size.w) wd->size.spos.x = 0.5;
1718    if (rh > wd->size.h) wd->size.spos.y = 0.5;
1719    if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
1720    if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
1721    if (wd->paused)
1722      {
1723         zoom_do(obj, 1.0);
1724      }
1725    else
1726      {
1727         if (!wd->zoom_animator)
1728           {
1729              wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
1730              wd->nosmooth++;
1731              if (wd->nosmooth == 1) _smooth_update(obj);
1732              started = 1;
1733           }
1734      }
1735    an = wd->zoom_animator;
1736    if (an)
1737      {
1738         if (!_zoom_anim(obj))
1739           {
1740              ecore_animator_del(an);
1741              an = NULL;
1742           }
1743      }
1744    if (wd->calc_job) ecore_job_del(wd->calc_job);
1745    wd->calc_job = ecore_job_add(_calc_job, wd);
1746    if (!wd->paused)
1747      {
1748         if (started)
1749           evas_object_smart_callback_call(obj, SIG_ZOOM_START, NULL);
1750         if (!an)
1751           evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1752      }
1753    if (zoom_changed)
1754      evas_object_smart_callback_call(obj, SIG_ZOOM_CHANGE, NULL);
1755 }
1756
1757 EAPI double
1758 elm_photocam_zoom_get(const Evas_Object *obj)
1759 {
1760    ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
1761    Widget_Data *wd = elm_widget_data_get(obj);
1762    if (!wd) return 1.0;
1763    return wd->zoom;
1764 }
1765
1766 EAPI void
1767 elm_photocam_zoom_mode_set(Evas_Object *obj, Elm_Photocam_Zoom_Mode mode)
1768 {
1769    ELM_CHECK_WIDTYPE(obj, widtype);
1770    Widget_Data *wd = elm_widget_data_get(obj);
1771    if (!wd) return;
1772    if (wd->mode == mode) return;
1773    wd->mode = mode;
1774 <<<<<<< HEAD
1775      {
1776         double tz = wd->zoom;
1777         wd->zoom = 0.0;
1778         elm_photocam_zoom_set(wd->obj, tz);
1779      }
1780 =======
1781    {
1782       double tz = wd->zoom;
1783       wd->zoom = 0.0;
1784       elm_photocam_zoom_set(wd->obj, tz);
1785    }
1786 >>>>>>> remotes/origin/upstream
1787 }
1788
1789 EAPI Elm_Photocam_Zoom_Mode
1790 elm_photocam_zoom_mode_get(const Evas_Object *obj)
1791 {
1792    ELM_CHECK_WIDTYPE(obj, widtype) ELM_PHOTOCAM_ZOOM_MODE_LAST;
1793    Widget_Data *wd = elm_widget_data_get(obj);
1794    if (!wd) return ELM_PHOTOCAM_ZOOM_MODE_LAST;
1795    return wd->mode;
1796 }
1797
1798 EAPI void
1799 elm_photocam_image_size_get(const Evas_Object *obj, int *w, int *h)
1800 {
1801    ELM_CHECK_WIDTYPE(obj, widtype);
1802    Widget_Data *wd = elm_widget_data_get(obj);
1803    if (!wd) return;
1804    if (w) *w = wd->size.imw;
1805    if (h) *h = wd->size.imh;
1806 }
1807
1808 <<<<<<< HEAD
1809 EAPI void
1810 elm_photocam_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1811 {
1812 =======
1813 EINA_DEPRECATED EAPI void
1814 elm_photocam_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1815 {
1816    return elm_photocam_image_region_get(obj, x, y, w, h);
1817 }
1818
1819 EAPI void
1820 elm_photocam_image_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1821 {
1822 >>>>>>> remotes/origin/upstream
1823    ELM_CHECK_WIDTYPE(obj, widtype);
1824    Widget_Data *wd = elm_widget_data_get(obj);
1825    Evas_Coord sx, sy, sw, sh;
1826    if (!wd) return;
1827    elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
1828    elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
1829    if (wd->size.w > 0)
1830      {
1831         if (x)
1832           {
1833              *x = (wd->size.imw * sx) / wd->size.w;
1834              if (*x > wd->size.imw) *x = wd->size.imw;
1835           }
1836         if (w)
1837           {
1838              *w = (wd->size.imw * sw) / wd->size.w;
1839              if (*w > wd->size.imw) *w = wd->size.imw;
1840              else if (*w < 0) *w = 0;
1841           }
1842      }
1843    else
1844      {
1845         if (x) *x = 0;
1846         if (w) *w = 0;
1847      }
1848
1849    if (wd->size.h > 0)
1850      {
1851         if (y)
1852           {
1853              *y = (wd->size.imh * sy) / wd->size.h;
1854              if (*y > wd->size.imh) *y = wd->size.imh;
1855           }
1856         if (h)
1857           {
1858              *h = (wd->size.imh * sh) / wd->size.h;
1859              if (*h > wd->size.imh) *h = wd->size.imh;
1860              else if (*h < 0) *h = 0;
1861           }
1862      }
1863    else
1864      {
1865         if (y) *y = 0;
1866         if (h) *h = 0;
1867      }
1868 }
1869
1870 EAPI void
1871 elm_photocam_image_region_show(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1872 {
1873    ELM_CHECK_WIDTYPE(obj, widtype);
1874    Widget_Data *wd = elm_widget_data_get(obj);
1875    int rx, ry, rw, rh;
1876    if (!wd) return;
1877    if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1878    rx = (x * wd->size.w) / wd->size.imw;
1879    ry = (y * wd->size.h) / wd->size.imh;
1880    rw = (w * wd->size.w) / wd->size.imw;
1881    rh = (h * wd->size.h) / wd->size.imh;
1882    if (rw < 1) rw = 1;
1883    if (rh < 1) rh = 1;
1884    if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1885    if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1886 <<<<<<< HEAD
1887 =======
1888    if (wd->gzoom.bounce.animator)
1889      {
1890         ecore_animator_del(wd->gzoom.bounce.animator);
1891         wd->gzoom.bounce.animator = NULL;
1892         zoom_do(obj, 1.0);
1893      }
1894 >>>>>>> remotes/origin/upstream
1895    if (wd->zoom_animator)
1896      {
1897         wd->nosmooth--;
1898         ecore_animator_del(wd->zoom_animator);
1899         wd->zoom_animator = NULL;
1900         zoom_do(obj, 1.0);
1901         evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1902      }
1903    elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
1904 }
1905
1906 EAPI void
1907 elm_photocam_image_region_bring_in(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1908 {
1909    ELM_CHECK_WIDTYPE(obj, widtype);
1910    Widget_Data *wd = elm_widget_data_get(obj);
1911    int rx, ry, rw, rh;
1912    if (!wd) return;
1913    if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1914    rx = (x * wd->size.w) / wd->size.imw;
1915    ry = (y * wd->size.h) / wd->size.imh;
1916    rw = (w * wd->size.w) / wd->size.imw;
1917    rh = (h * wd->size.h) / wd->size.imh;
1918    if (rw < 1) rw = 1;
1919    if (rh < 1) rh = 1;
1920    if ((rx + rw) > wd->size.w) rx = wd->size.w - rw;
1921    if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1922 <<<<<<< HEAD
1923 =======
1924    if (wd->gzoom.bounce.animator)
1925      {
1926         ecore_animator_del(wd->gzoom.bounce.animator);
1927         wd->gzoom.bounce.animator = NULL;
1928         zoom_do(obj, 1.0);
1929      }
1930 >>>>>>> remotes/origin/upstream
1931    if (wd->zoom_animator)
1932      {
1933         wd->nosmooth--;
1934         if (!wd->nosmooth) _smooth_update(obj);
1935         ecore_animator_del(wd->zoom_animator);
1936         wd->zoom_animator = NULL;
1937         zoom_do(obj, 1.0);
1938         evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1939      }
1940    elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
1941 }
1942
1943 EAPI void
1944 elm_photocam_paused_set(Evas_Object *obj, Eina_Bool paused)
1945 {
1946    ELM_CHECK_WIDTYPE(obj, widtype);
1947    Widget_Data *wd = elm_widget_data_get(obj);
1948    if (!wd) return;
1949    if (wd->paused == !!paused) return;
1950    wd->paused = paused;
1951    if (wd->paused)
1952      {
1953 <<<<<<< HEAD
1954 =======
1955         if (wd->gzoom.bounce.animator)
1956           {
1957              ecore_animator_del(wd->gzoom.bounce.animator);
1958              wd->gzoom.bounce.animator = NULL;
1959              zoom_do(obj, 1.0);
1960           }
1961 >>>>>>> remotes/origin/upstream
1962         if (wd->zoom_animator)
1963           {
1964              ecore_animator_del(wd->zoom_animator);
1965              wd->zoom_animator = NULL;
1966              zoom_do(obj, 1.0);
1967              evas_object_smart_callback_call(obj, SIG_ZOOM_STOP, NULL);
1968           }
1969      }
1970 }
1971
1972 EAPI Eina_Bool
1973 elm_photocam_paused_get(const Evas_Object *obj)
1974 {
1975    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1976    Widget_Data *wd = elm_widget_data_get(obj);
1977    if (!wd) return EINA_FALSE;
1978    return wd->paused;
1979 }
1980
1981 EAPI Evas_Object *
1982 elm_photocam_internal_image_get(const Evas_Object *obj)
1983 {
1984    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1985    Widget_Data *wd = elm_widget_data_get(obj);
1986    if (!wd) return NULL;
1987    return wd->img;
1988 }
1989
1990 EAPI void
1991 elm_photocam_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1992 {
1993    ELM_CHECK_WIDTYPE(obj, widtype);
1994    Widget_Data *wd = elm_widget_data_get(obj);
1995    if (!wd) return;
1996    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
1997 }
1998
1999 EAPI void
2000 elm_photocam_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
2001 {
2002    ELM_CHECK_WIDTYPE(obj, widtype);
2003    Widget_Data *wd = elm_widget_data_get(obj);
2004    if (!wd) return;
2005    elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
2006 }
2007
2008 <<<<<<< HEAD
2009 =======
2010 EAPI void
2011 elm_photocam_gesture_enabled_set(Evas_Object *obj, Eina_Bool gesture)
2012 {
2013    ELM_CHECK_WIDTYPE(obj, widtype);
2014    Widget_Data *wd = elm_widget_data_get(obj);
2015    if (!wd) return;
2016    if (wd->do_gesture == !!gesture) return;
2017
2018    if (wd->gest)
2019      {
2020         evas_object_del(wd->gest);
2021         wd->gest = NULL;
2022      }
2023
2024    if (gesture)
2025      {
2026         wd->gest = elm_gesture_layer_add(wd->obj);
2027         if (!wd->gest) return;
2028         elm_gesture_layer_attach(wd->gest, wd->obj);
2029         elm_gesture_layer_cb_set(wd->gest, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_START,
2030                                  _gzoom_start, wd);
2031         elm_gesture_layer_cb_set(wd->gest, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_MOVE,
2032                                  _gzoom_move, wd);
2033         elm_gesture_layer_cb_set(wd->gest, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_END,
2034                                  _gzoom_end, wd);
2035         elm_gesture_layer_cb_set(wd->gest, ELM_GESTURE_ZOOM, ELM_GESTURE_STATE_ABORT,
2036                                  _gzoom_end, wd);
2037      }
2038
2039    wd->do_gesture = !!gesture;
2040 }
2041
2042 EAPI Eina_Bool
2043 elm_photocam_gesture_enabled_get(const Evas_Object *obj)
2044 {
2045    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2046    Widget_Data *wd = elm_widget_data_get(obj);
2047    if (!wd) return EINA_FALSE;
2048
2049    return wd->do_gesture;
2050 }
2051 >>>>>>> remotes/origin/upstream