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