Merge branch 'master' of juyung.seo@165.213.180.234:/git/slp2.0/slp2.0-pkgs/EFL-pkgs...
[framework/uifw/elementary.git] / src / lib / elm_photocam.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Photocam Photocam
6  *
7  * This is a widget specifically for displaying high-resolution digital
8  * camera photos giving speedy feedback (fast load), low memory footprint
9  * and zooming and panning as well as fitting logic. It is entirely focused
10  * on jpeg images, and takes advantage of properties of the jpeg format (via
11  * evas loader features in the jpeg loader).
12  * 
13  * Signals that you can add callbacks for are:
14  *
15  * clicked - This is called when a user has clicked the photo without dragging
16  * around.
17  * 
18  * press - This is called when a user has pressed down on the photo.
19  * 
20  * longpressed - This is called when a user has pressed down on the photo for
21  * a long time without dragging around.
22  * 
23  * clicked,double - This is called when a user has double-clicked the photo.
24  * 
25  * load - Photo load begins.
26  * 
27  * loaded - This is called when the image file load is complete for the first
28  * view (low resolution blurry version).
29  *
30  * load,details - Photo detailed data load begins.
31  * 
32  * loaded,details - This is called when the image file load is complete for the
33  * detailed image data (full resolution needed).
34  *
35  * zoom,start - Zoom animation started.
36  * 
37  * zoom,stop - Zoom animation stopped.
38  * 
39  * zoom,change - Zoom changed when using an auto zoom mode.
40  * 
41  * scroll - the content has been scrolled (moved)
42  *
43  * scroll,anim,start - scrolling animation has started
44  *
45  * scroll,anim,stop - scrolling animation has stopped
46  *
47  * scroll,drag,start - dragging the contents around has started
48  *
49  * scroll,drag,stop - dragging the contents around has stopped
50  * 
51  * ---
52  * 
53  * TODO (maybe - optional future stuff):
54  * 
55  * 1. wrap photo in theme edje so u can have styling around photo (like white
56  *    photo bordering).
57  * 2. exif handling
58  * 3. rotation flags in exif handling (nasty! should have rot in evas)
59  *
60  */
61 typedef struct _Widget_Data Widget_Data;
62 typedef struct _Pan Pan;
63 typedef struct _Grid Grid;
64 typedef struct _Grid_Item Grid_Item;
65
66 struct _Grid_Item
67 {
68    Widget_Data *wd;
69    Evas_Object *img;
70    struct 
71      {
72         int x, y, w, h;
73      } src, out;
74    Eina_Bool want : 1;
75    Eina_Bool have : 1;
76 };
77
78 struct _Grid
79 {
80    int tsize; // size of tile (tsize x tsize pixels)
81    int zoom; // zoom level tiles want for optimal display (1, 2, 4, 8)
82    int iw, ih; // size of image in pixels
83    int w, h; // size of grid image in pixels (represented by grid)
84    int gw, gh; // size of grid in tiles
85    Grid_Item *grid; // the grid (gw * gh items)
86    Eina_Bool dead : 1; // old grid. will die as soon as anim is over
87 };
88
89 struct _Widget_Data
90 {
91    Evas_Object *obj;
92    Evas_Object *scr;
93    Evas_Object *pan_smart;
94    Pan *pan;
95    Evas_Coord pan_x, pan_y, minw, minh;
96
97    double zoom;
98    Elm_Photocam_Zoom_Mode mode;
99    const char *file;
100    
101    Ecore_Job *calc_job;
102    Ecore_Timer *scr_timer;
103    Ecore_Timer *long_timer;
104    Ecore_Animator *zoom_animator;
105    double t_start, t_end;
106    struct 
107      {
108         int imw, imh;
109         int w, h;
110         int ow, oh, nw, nh;
111         struct 
112           {
113              double x, y;
114           } spos;
115      } size;
116    struct
117      {
118         Eina_Bool show : 1;
119         Evas_Coord x, y ,w ,h;
120      } show;
121    int tsize;
122    Evas_Object *img; // low res version of image (scale down == 8)
123    int nosmooth;
124    int preload_num;
125    Eina_List *grids;
126    Eina_Bool main_load_pending : 1;
127    Eina_Bool resized : 1;
128    Eina_Bool longpressed : 1;
129    Eina_Bool on_hold : 1;
130    Eina_Bool paused : 1;
131 };
132
133 struct _Pan
134 {
135    Evas_Object_Smart_Clipped_Data __clipped_data;
136    Widget_Data *wd;
137 };
138
139 static const char *widtype = NULL;
140 static void _del_hook(Evas_Object *obj);
141 static void _theme_hook(Evas_Object *obj);
142 //static void _show_region_hook(void *data, Evas_Object *obj);
143 static void _sizing_eval(Evas_Object *obj);
144 static void _calc_job(void *data);
145 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);
146 static void grid_clear(Evas_Object *obj, Grid *g);
147 static Grid *grid_create(Evas_Object *obj);
148 static void grid_load(Evas_Object *obj, Grid *g);
149
150 static int
151 nearest_pow2(int num)
152 {
153    unsigned int n = num - 1;
154    n |= n >> 1;
155    n |= n >> 2;
156    n |= n >> 4;
157    n |= n >> 8;
158    n |= n >> 16;
159    return n + 1;
160 }
161
162 static void
163 img_place(Evas_Object *obj, Evas_Coord px, Evas_Coord py, Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
164 {
165    Widget_Data *wd = elm_widget_data_get(obj);
166    Evas_Coord ax, ay, gw, gh;
167    if (!wd) return;
168    ax = 0;
169    ay = 0;
170    gw = wd->size.w;
171    gh = wd->size.h;
172    if (ow > gw) ax = (ow - gw) / 2;
173    if (oh > gh) ay = (oh - gh) / 2;
174    evas_object_move(wd->img, ox + 0 - px + ax, oy + 0 - py + ay);
175    evas_object_resize(wd->img, gw, gh);
176
177    if (wd->show.show)
178      {
179         wd->show.show = EINA_FALSE;
180         elm_smart_scroller_child_region_show(wd->scr, wd->show.x, wd->show.y, wd->show.w, wd->show.h);
181      }
182 }
183
184 static void
185 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)
186 {
187    Widget_Data *wd = elm_widget_data_get(obj);
188    Evas_Coord ax, ay, gw, gh, tx, ty;
189    int x, y;
190    if (!wd) return;
191    ax = 0;
192    ay = 0;
193    gw = wd->size.w;
194    gh = wd->size.h;
195    if (ow > gw) ax = (ow - gw) / 2;
196    if (oh > gh) ay = (oh - gh) / 2;
197    for (y = 0; y < g->gh; y++)
198      {
199         for (x = 0; x < g->gw; x++)
200           {
201              int tn, xx, yy, ww, hh;
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              evas_object_move(g->grid[tn].img,
221                               ox + xx - px + ax,
222                               oy + yy - py + ay);
223              evas_object_resize(g->grid[tn].img, ww, hh);
224           }
225      }
226 }
227
228 static void
229 grid_clear(Evas_Object *obj, Grid *g)
230 {
231    Widget_Data *wd = elm_widget_data_get(obj);
232    int x, y;
233    if (!wd) return;
234    if (!g->grid) return;
235    for (y = 0; y < g->gh; y++)
236      {
237         for (x = 0; x < g->gw; x++)
238           {
239              int tn;
240              
241              tn = (y * g->gw) + x;
242              evas_object_del(g->grid[tn].img);
243              if (g->grid[tn].want)
244                {
245                   wd->preload_num--;
246                   if (wd->preload_num == 0)
247                     {
248                        edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
249                                                "elm,state,busy,stop", "elm");
250                        evas_object_smart_callback_call(obj, "loaded,detail", NULL);
251                     }
252                }
253           }
254      }
255    free(g->grid);
256    g->grid = NULL;
257    g->gw = 0;
258    g->gh = 0;
259 }
260
261 static void
262 _tile_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
263 {
264    Grid_Item *git = data;
265
266    if (git->want)
267      {
268         git->want = 0;
269         evas_object_show(git->img);
270         git->have = 1;
271         git->wd->preload_num--;
272         if (git->wd->preload_num == 0)
273           {
274              edje_object_signal_emit(elm_smart_scroller_edje_object_get(git->wd->scr),
275                                      "elm,state,busy,stop", "elm");
276              evas_object_smart_callback_call(git->wd->obj, "loaded,detail", NULL);
277           }
278      }
279 }
280
281 static int
282 grid_zoom_calc(double zoom)
283 {
284    int z = zoom;
285    if (z < 1) z = 1;
286    return nearest_pow2(z);
287 }
288
289 static Grid *
290 grid_create(Evas_Object *obj)
291 {
292    Widget_Data *wd = elm_widget_data_get(obj);
293    int x, y;
294    Grid *g;
295    
296    if (!wd) return NULL;
297    g = calloc(1, sizeof(Grid));
298    
299    g->zoom = grid_zoom_calc(wd->zoom);
300    g->tsize = wd->tsize;
301    g->iw = wd->size.imw;
302    g->ih = wd->size.imh;
303    
304    g->w = g->iw / g->zoom;
305    g->h = g->ih / g->zoom;
306    if (g->zoom >= 8) return NULL;
307    g->gw = (g->w + g->tsize - 1) / g->tsize;
308    g->gh = (g->h + g->tsize - 1) / g->tsize;
309    g->grid = calloc(1, sizeof(Grid_Item) * g->gw * g->gh);
310    if (!g->grid)
311      {
312         g->gw = 0;
313         g->gh = 0;
314         return g;
315      }
316    for (y = 0; y < g->gh; y++)
317      {
318         for (x = 0; x < g->gw; x++)
319           {
320              int tn;
321              
322              tn = (y * g->gw) + x;
323              g->grid[tn].src.x = x * g->tsize;
324              if (x == (g->gw - 1))
325                g->grid[tn].src.w = g->w - ((g->gw - 1) * g->tsize);
326              else
327                g->grid[tn].src.w = g->tsize;
328              g->grid[tn].src.y = y * g->tsize;
329              if (y == (g->gh - 1))
330                g->grid[tn].src.h = g->h - ((g->gh - 1) * g->tsize);
331              else
332                g->grid[tn].src.h = g->tsize;
333              
334              g->grid[tn].out.x = g->grid[tn].src.x;
335              g->grid[tn].out.y = g->grid[tn].src.y;
336              g->grid[tn].out.w = g->grid[tn].src.w;
337              g->grid[tn].out.h = g->grid[tn].src.h;
338              
339              g->grid[tn].wd = wd;
340              g->grid[tn].img = 
341                evas_object_image_add(evas_object_evas_get(obj));
342              evas_object_image_scale_hint_set
343                (g->grid[tn].img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
344              evas_object_pass_events_set(g->grid[tn].img, 1);
345              evas_object_smart_member_add(g->grid[tn].img, 
346                                           wd->pan_smart);
347              elm_widget_sub_object_add(obj, g->grid[tn].img);
348              evas_object_image_filled_set(g->grid[tn].img, 1);
349              evas_object_event_callback_add(g->grid[tn].img, 
350                                             EVAS_CALLBACK_IMAGE_PRELOADED,
351                                             _tile_preloaded, 
352                                             &(g->grid[tn]));
353           }
354      }
355    return g;
356 }
357
358 static void
359 grid_load(Evas_Object *obj, Grid *g)
360 {
361    Widget_Data *wd = elm_widget_data_get(obj);
362    int x, y;
363    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh, gw, gh, ax, ay, tx, ty;
364    if (!wd) return;
365    evas_object_geometry_get(wd->pan_smart, &ox, &oy, &ow, &oh);
366    evas_output_viewport_get(evas_object_evas_get(wd->obj), &cvx, &cvy, &cvw, &cvh);
367    ax = 0;
368    ay = 0;
369    gw = wd->size.w;
370    gh = wd->size.h;
371    if (ow > gw) ax = (ow - gw) / 2;
372    if (oh > gh) ay = (oh - gh) / 2;
373    for (y = 0; y < g->gh; y++)
374      {
375         for (x = 0; x < g->gw; x++)
376           {
377              int tn, xx, yy, ww, hh;
378              Eina_Bool visible = EINA_FALSE;
379              
380              tn = (y * g->gw) + x;
381              xx = g->grid[tn].out.x;
382              yy = g->grid[tn].out.y;
383              ww = g->grid[tn].out.w;
384              hh = g->grid[tn].out.h;
385              if ((gw != g->w) && (g->w > 0))
386                {
387                   tx = xx;
388                   xx = (gw * xx) / g->w;
389                   ww = ((gw * (tx + ww)) / g->w) - xx;
390                }
391              if ((gh != g->h) && (g->h > 0))
392                {
393                   ty = yy;
394                   yy = (gh * yy) / g->h;
395                   hh = ((gh * (ty + hh)) / g->h) - yy;
396                }
397 //             xx += ax;
398 //             yy += ay;
399              if (ELM_RECTS_INTERSECT(xx - wd->pan_x + ox, 
400                                      yy  - wd->pan_y + oy,
401                                      ww, hh,
402                                      cvx, cvy, cvw, cvh))
403                visible = 1;
404              if ((visible) && (!g->grid[tn].have) && (!g->grid[tn].want))
405                {
406                   g->grid[tn].want = 1;
407                   evas_object_hide(g->grid[tn].img);
408                   evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
409                   evas_object_image_load_scale_down_set(g->grid[tn].img, g->zoom);
410                   evas_object_image_load_region_set(g->grid[tn].img,
411                                                     g->grid[tn].src.x,
412                                                     g->grid[tn].src.y,
413                                                     g->grid[tn].src.w,
414                                                     g->grid[tn].src.h);
415                   evas_object_image_file_set(g->grid[tn].img, wd->file, NULL); 
416                   evas_object_image_preload(g->grid[tn].img, 0);
417                   wd->preload_num++;
418                   if (wd->preload_num == 1)
419                     {
420                        edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
421                                                "elm,state,busy,start", "elm");
422                        evas_object_smart_callback_call(obj, "load,detail", NULL);
423                     }
424                }
425              else if ((g->grid[tn].want) && (!visible))
426                {
427                   wd->preload_num--;
428                   if (wd->preload_num == 0)
429                     {
430                        edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
431                                                "elm,state,busy,stop", "elm");
432                        evas_object_smart_callback_call(obj, "loaded,detail", NULL);
433                     }
434                   g->grid[tn].want = 0;
435                   evas_object_hide(g->grid[tn].img);
436                   evas_object_image_preload(g->grid[tn].img, 1);
437                   evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
438                }
439              else if ((g->grid[tn].have) && (!visible))
440                {
441                   g->grid[tn].have = 0;
442                   evas_object_hide(g->grid[tn].img);
443                   evas_object_image_preload(g->grid[tn].img, 1);
444                   evas_object_image_file_set(g->grid[tn].img, NULL, NULL);
445                }
446           }
447      }
448 }
449
450 static void
451 grid_clearall(Evas_Object *obj)
452 {
453    Widget_Data *wd = elm_widget_data_get(obj);
454    Grid *g;
455    if (!wd) return;
456    EINA_LIST_FREE(wd->grids, g)
457      {
458         grid_clear(obj, g);
459         free(g);
460      }
461 }
462
463 static void
464 _smooth_update(Evas_Object *obj)
465 {
466    Widget_Data *wd = elm_widget_data_get(obj);
467    int x, y;
468    Eina_List *l;
469    Grid *g;
470    if (!wd) return;
471    EINA_LIST_FOREACH(wd->grids, l, g)
472      {
473         for (y = 0; y < g->gh; y++)
474           {
475              for (x = 0; x < g->gw; x++)
476                {
477                   int tn;
478                   
479                   tn = (y * g->gw) + x;
480                   evas_object_image_smooth_scale_set(g->grid[tn].img, (wd->nosmooth == 0));
481                }
482           }
483      }
484    evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
485 }
486
487 static void
488 _grid_raise(Grid *g)
489 {
490    int x, y;
491    
492    for (y = 0; y < g->gh; y++)
493      {
494         for (x = 0; x < g->gw; x++)
495           {
496              int tn;
497              
498              tn = (y * g->gw) + x;
499              evas_object_raise(g->grid[tn].img);
500           }
501      }
502 }
503
504 static int
505 _scr_timeout(void *data)
506 {
507    Widget_Data *wd = elm_widget_data_get(data);
508    if (!wd) return 0;
509    wd->nosmooth--;
510    if (wd->nosmooth == 0) _smooth_update(data);
511    wd->scr_timer = NULL;
512    return 0;
513 }
514
515 static void
516 _scr(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
517 {
518    Widget_Data *wd = elm_widget_data_get(data);
519    if (!wd) return;
520    if (!wd->scr_timer)
521      {
522         wd->nosmooth++;
523         if (wd->nosmooth == 1) _smooth_update(data);
524      }
525    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
526    wd->scr_timer = ecore_timer_add(0.5, _scr_timeout, data);
527 }
528
529 static void
530 _main_preloaded(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
531 {
532    Evas_Object *obj = data;
533    Widget_Data *wd = elm_widget_data_get(obj);
534    Grid *g;
535    if (!wd) return;
536    evas_object_show(wd->img);
537    wd->main_load_pending = 0;
538    g = grid_create(obj);
539    if (g)
540      {
541         wd->grids = eina_list_prepend(wd->grids, g);
542         grid_load(wd->obj, g);
543      }
544    if (wd->calc_job) ecore_job_del(wd->calc_job);
545    wd->calc_job = ecore_job_add(_calc_job, wd);
546    evas_object_smart_callback_call(data, "loaded", NULL);
547    wd->preload_num--;
548    if (wd->preload_num == 0)
549      {
550         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
551                                 "elm,state,busy,stop", "elm");
552         evas_object_smart_callback_call(obj, "loaded,detail", NULL);
553      }
554 }
555
556 static int
557 zoom_do(Evas_Object *obj, double t)
558 {
559    Widget_Data *wd = elm_widget_data_get(obj);
560    Evas_Coord xx, yy, ow, oh;
561    if (!wd) return 0;
562    wd->size.w = (wd->size.ow * (1.0 - t)) + (wd->size.nw * t);
563    wd->size.h = (wd->size.oh * (1.0 - t)) + (wd->size.nh * t);
564    elm_smart_scroller_child_viewport_size_get(wd->scr, &ow, &oh);
565    xx = (wd->size.spos.x * wd->size.w) - (ow / 2);
566    yy = (wd->size.spos.y * wd->size.h) - (oh / 2);
567    if (xx < 0) xx = 0;
568    else if (xx > (wd->size.w - ow)) xx = wd->size.w - ow;
569    if (yy < 0) yy = 0;
570    else if (yy > (wd->size.h - oh)) yy = wd->size.h - oh;
571
572    wd->show.show = EINA_TRUE;
573    wd->show.x = xx;
574    wd->show.y = yy;
575    wd->show.w = ow;
576    wd->show.h = oh;
577
578    if (wd->calc_job) ecore_job_del(wd->calc_job);
579    wd->calc_job = ecore_job_add(_calc_job, wd);
580    if (t >= 1.0)
581      {
582         Eina_List *l, *l_next;
583         Grid *g;
584         
585         EINA_LIST_FOREACH_SAFE(wd->grids, l, l_next, g)
586           {
587              if (g->dead)
588                {
589                   wd->grids = eina_list_remove_list(wd->grids, l);
590                   grid_clear(obj, g);
591                   free(g);
592                }
593           }
594         return 0;
595      }
596    return 1;
597 }
598
599
600 static int
601 _zoom_anim(void *data)
602 {
603    Evas_Object *obj = data;
604    Widget_Data *wd = elm_widget_data_get(obj);
605    double t;
606    int go;
607    if (!wd) return 0;
608    t = ecore_loop_time_get();
609    if (t >= wd->t_end)
610      t = 1.0;
611    else if (wd->t_end > wd->t_start)
612      t = (t - wd->t_start) / (wd->t_end - wd->t_start);
613    else
614      t = 1.0;
615    t = 1.0 - t;
616    t = 1.0 - (t * t);
617    go = zoom_do(obj, t);
618    if (!go)
619      {
620         wd->nosmooth--;
621         if (wd->nosmooth == 0) _smooth_update(data);
622         wd->zoom_animator = NULL;
623         evas_object_smart_callback_call(obj, "zoom,stop", NULL);
624      }
625    return go;
626 }
627
628 static void
629 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
630 {
631    Widget_Data *wd = elm_widget_data_get(data);
632 //   Evas_Event_Mouse_Move *ev = event_info;
633    if (!wd) return;
634 }
635
636 static int
637 _long_press(void *data)
638 {
639    Widget_Data *wd = elm_widget_data_get(data);
640    if (!wd) return 0;
641    wd->long_timer = NULL;
642    wd->longpressed = EINA_TRUE;
643    evas_object_smart_callback_call(data, "longpressed", NULL);
644    return 0;
645 }
646
647 static void
648 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
649 {
650    Widget_Data *wd = elm_widget_data_get(data);
651    Evas_Event_Mouse_Down *ev = event_info;
652    if (!wd) return;
653    if (ev->button != 1) return;
654    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
655    else wd->on_hold = EINA_FALSE;
656    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
657      evas_object_smart_callback_call(data, "clicked,double", NULL);
658    else
659      evas_object_smart_callback_call(data, "press", NULL);
660    wd->longpressed = EINA_FALSE;
661    if (wd->long_timer) ecore_timer_del(wd->long_timer);
662    wd->long_timer = ecore_timer_add(1.0, _long_press, data);
663 }
664    
665 static void
666 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
667 {
668    Widget_Data *wd = elm_widget_data_get(data);
669    Evas_Event_Mouse_Up *ev = event_info;
670    if (!wd) return;
671    if (ev->button != 1) return;
672    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) wd->on_hold = EINA_TRUE;
673    else wd->on_hold = EINA_FALSE;
674    if (wd->long_timer)
675      {
676         ecore_timer_del(wd->long_timer);
677         wd->long_timer = NULL;
678      }
679    if (!wd->on_hold)
680      evas_object_smart_callback_call(data, "clicked", NULL);
681    wd->on_hold = EINA_FALSE;
682 }
683    
684 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_NULL;
685
686 static void
687 _del_hook(Evas_Object *obj)
688 {
689    Widget_Data *wd = elm_widget_data_get(obj);
690    Grid *g;
691    if (!wd) return;
692    EINA_LIST_FREE(wd->grids, g)
693      {
694         if (g->grid) free(g->grid);
695         free(g);
696      }
697    evas_object_del(wd->pan_smart);
698    wd->pan_smart = NULL;
699    if (wd->file) eina_stringshare_del(wd->file);
700    if (wd->calc_job) ecore_job_del(wd->calc_job);
701    if (wd->scr_timer) ecore_timer_del(wd->scr_timer);
702    if (wd->zoom_animator) ecore_animator_del(wd->zoom_animator);
703    if (wd->long_timer) ecore_timer_del(wd->long_timer);
704    free(wd);
705 }
706
707 static void
708 _theme_hook(Evas_Object *obj)
709 {
710    Widget_Data *wd = elm_widget_data_get(obj);
711    if (!wd) return;
712    elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", elm_widget_style_get(obj));
713 //   edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
714    _sizing_eval(obj);
715 }
716
717 /*
718 static void
719 _show_region_hook(void *data, Evas_Object *obj)
720 {
721    Widget_Data *wd = elm_widget_data_get(data);
722    Evas_Coord x, y, w, h;
723    if (!wd) return;
724    elm_widget_show_region_get(obj, &x, &y, &w, &h);
725    elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
726 }
727 */
728
729 static void
730 _sizing_eval(Evas_Object *obj)
731 {
732    Widget_Data *wd = elm_widget_data_get(obj);
733    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
734    if (!wd) return;
735 //   evas_object_size_hint_min_get(wd->scr, &minw, &minh);
736    evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
737 //   minw = -1;
738 //   minh = -1;
739 //   if (wd->mode != ELM_LIST_LIMIT) minw = -1;
740    evas_object_size_hint_min_set(obj, minw, minh);
741    evas_object_size_hint_max_set(obj, maxw, maxh);
742 }
743
744 static void
745 _calc_job(void *data)
746 {
747    Widget_Data *wd = data;
748    Evas_Coord minw, minh;
749    if (!wd) return;
750    minw = wd->size.w;
751    minh = wd->size.h;
752    if (wd->resized)
753      {
754         wd->resized = 0;
755         if (wd->mode != ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
756           {
757              double tz = wd->zoom;
758              wd->zoom = 0.0;
759              elm_photocam_zoom_set(wd->obj, tz);
760           }
761      }
762    if ((minw != wd->minw) || (minh != wd->minh))
763      {
764         wd->minw = minw;
765         wd->minh = minh;
766         evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
767         _sizing_eval(wd->obj);
768      }
769    wd->calc_job = NULL;
770    evas_object_smart_changed(wd->pan_smart);
771 }
772
773 static void
774 _pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
775 {
776    Pan *sd = evas_object_smart_data_get(obj);
777    if (!sd) return;
778    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
779    sd->wd->pan_x = x;
780    sd->wd->pan_y = y;
781    evas_object_smart_changed(obj);
782 }
783
784 static void
785 _pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
786 {
787    Pan *sd = evas_object_smart_data_get(obj);
788    if (!sd) return;
789    if (x) *x = sd->wd->pan_x;
790    if (y) *y = sd->wd->pan_y;
791 }
792
793 static void
794 _pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
795 {
796    Pan *sd = evas_object_smart_data_get(obj);
797    Evas_Coord ow, oh;
798    if (!sd) return;
799    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
800    ow = sd->wd->minw - ow;
801    if (ow < 0) ow = 0;
802    oh = sd->wd->minh - oh;
803    if (oh < 0) oh = 0;
804    if (x) *x = ow;
805    if (y) *y = oh;
806 }
807
808 static void
809 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
810 {
811    Pan *sd = evas_object_smart_data_get(obj);
812    if (!sd) return;
813    if (w) *w = sd->wd->minw;
814    if (h) *h = sd->wd->minh;
815 }
816
817 static void
818 _pan_add(Evas_Object *obj)
819 {
820    Pan *sd;
821    Evas_Object_Smart_Clipped_Data *cd;
822    _pan_sc.add(obj);
823    cd = evas_object_smart_data_get(obj);
824    if (!cd) return;
825    sd = calloc(1, sizeof(Pan));
826    if (!sd) return;
827    sd->__clipped_data = *cd;
828    free(cd);
829    evas_object_smart_data_set(obj, sd);
830 }
831
832 static void
833 _pan_del(Evas_Object *obj)
834 {
835    Pan *sd = evas_object_smart_data_get(obj);
836    if (!sd) return;
837    _pan_sc.del(obj);
838 }
839
840 static void
841 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
842 {
843    Pan *sd = evas_object_smart_data_get(obj);
844    Evas_Coord ow, oh;
845    if (!sd) return;
846    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
847    if ((ow == w) && (oh == h)) return;
848    sd->wd->resized = 1;
849    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
850    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
851 }
852
853 static void
854 _pan_calculate(Evas_Object *obj)
855 {
856    Pan *sd = evas_object_smart_data_get(obj);
857    Evas_Coord ox, oy, ow, oh;
858    Eina_List *l;
859    Grid *g;
860    if (!sd) return;
861    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
862    img_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
863    EINA_LIST_FOREACH(sd->wd->grids, l, g)
864      {
865         grid_load(sd->wd->obj, g);
866         grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
867      }
868 }
869
870 static void
871 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
872 {
873    Pan *sd = evas_object_smart_data_get(obj);
874    if (!sd) return;
875    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
876    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
877 }
878
879 static void
880 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
881 {
882    Widget_Data *wd = elm_widget_data_get(obj);
883    if (!wd) return;
884    elm_smart_scroller_hold_set(wd->scr, 1);
885 }
886
887 static void
888 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
889 {
890    Widget_Data *wd = elm_widget_data_get(obj);
891    if (!wd) return;
892    elm_smart_scroller_hold_set(wd->scr, 0);
893 }
894
895 static void
896 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
897 {
898    Widget_Data *wd = elm_widget_data_get(obj);
899    if (!wd) return;
900    elm_smart_scroller_freeze_set(wd->scr, 1);
901 }
902
903 static void
904 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
905 {
906    Widget_Data *wd = elm_widget_data_get(obj);
907    if (!wd) return;
908    elm_smart_scroller_freeze_set(wd->scr, 0);
909 }
910
911 static void
912 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
913 {
914    evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
915 }
916
917 static void
918 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
919 {
920    evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
921 }
922
923 static void
924 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
925 {
926    evas_object_smart_callback_call(data, "scroll,drag,start", NULL);
927 }
928
929 static void
930 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
931 {
932    evas_object_smart_callback_call(data, "scroll,drag,stop", NULL);
933 }
934
935 static void
936 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
937 {
938    evas_object_smart_callback_call(data, "scroll", NULL);
939 }
940
941 /**
942  * Add a new Photocam object
943  *
944  * @param parent The parent object
945  * @return The new object or NULL if it cannot be created
946  *
947  * @ingroup Photocam
948  */
949 EAPI Evas_Object *
950 elm_photocam_add(Evas_Object *parent)
951 {
952    Evas_Object *obj;
953    Evas *e;
954    Widget_Data *wd;
955    Evas_Coord minw, minh;
956    static Evas_Smart *smart = NULL;
957
958    wd = ELM_NEW(Widget_Data);
959    e = evas_object_evas_get(parent);
960    obj = elm_widget_add(e);
961    ELM_SET_WIDTYPE(widtype, "photocam");
962    elm_widget_type_set(obj, "photocam");
963    elm_widget_sub_object_add(parent, obj);
964    elm_widget_data_set(obj, wd);
965    elm_widget_del_hook_set(obj, _del_hook);
966    elm_widget_theme_hook_set(obj, _theme_hook);
967
968    wd->scr = elm_smart_scroller_add(e);
969    elm_smart_scroller_widget_set(wd->scr, obj);
970    elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", "default");
971    evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
972    evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
973    elm_widget_resize_object_set(obj, wd->scr);
974
975    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
976    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
977    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
978    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
979    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
980    
981    elm_smart_scroller_bounce_allow_set(wd->scr, 1, 1);
982
983    wd->obj = obj;
984
985    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
986    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
987    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
988    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
989    
990    if (!smart)
991      {
992         static Evas_Smart_Class sc;
993
994         evas_object_smart_clipped_smart_set(&_pan_sc);
995         sc = _pan_sc;
996         sc.name = "elm_photocam_pan";
997         sc.version = EVAS_SMART_CLASS_VERSION;
998         sc.add = _pan_add;
999         sc.del = _pan_del;
1000         sc.resize = _pan_resize;
1001         sc.move = _pan_move;
1002         sc.calculate = _pan_calculate;
1003         smart = evas_smart_class_new(&sc);
1004      }
1005    if (smart)
1006      {
1007         wd->pan_smart = evas_object_smart_add(e, smart);
1008         wd->pan = evas_object_smart_data_get(wd->pan_smart);
1009         wd->pan->wd = wd;
1010      }
1011
1012    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1013                                      _pan_set, _pan_get,
1014                                      _pan_max_get, _pan_child_size_get);
1015
1016    wd->zoom = 1;
1017    wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1018    
1019    wd->tsize = 512;
1020    
1021    wd->img = evas_object_image_add(e);
1022    evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1023    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
1024                                   _mouse_down, obj);
1025    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
1026                                   _mouse_up, obj);
1027    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_MOVE,
1028                                   _mouse_move, obj);
1029    evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_STATIC);
1030    evas_object_smart_member_add(wd->img, wd->pan_smart);
1031    elm_widget_sub_object_add(obj, wd->img);
1032    evas_object_image_filled_set(wd->img, 1);
1033    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_IMAGE_PRELOADED,
1034                                   _main_preloaded, obj);
1035    
1036    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), 
1037                              &minw, &minh);
1038    evas_object_size_hint_min_set(obj, minw, minh);
1039
1040    _sizing_eval(obj);
1041    return obj;
1042 }
1043
1044 /**
1045  * Set the photo file to be shown
1046  *
1047  * This sets (and shows) the specified file (with a relative or absolute path)
1048  * and will return a load error (same error that
1049  * evas_object_image_load_error_get() will return). The image will change and
1050  * adjust its size at this point and begin a background load process for this
1051  * photo that at some time in the future will be displayed at the full quality
1052  * needed.
1053  *
1054  * @param obj The photocam object
1055  * @param file The photo file
1056  * @return The return error (see EVAS_LOAD_ERROR_NONE, EVAS_LOAD_ERROR_GENERIC etc.)
1057  *
1058  * @ingroup Photocam
1059  */
1060 EAPI int
1061 elm_photocam_file_set(Evas_Object *obj, const char *file)
1062 {
1063    ELM_CHECK_WIDTYPE(obj, widtype) 0;
1064    Widget_Data *wd = elm_widget_data_get(obj);
1065    int w, h;
1066    if (!wd) return EVAS_LOAD_ERROR_GENERIC;
1067    if (!eina_stringshare_replace(&wd->file, file)) return EVAS_LOAD_ERROR_NONE;
1068    evas_object_hide(wd->img);
1069    evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
1070    evas_object_image_file_set(wd->img, NULL, NULL);
1071    evas_object_image_load_scale_down_set(wd->img, 0);
1072    evas_object_image_file_set(wd->img, wd->file, NULL);
1073    evas_object_image_size_get(wd->img, &w, &h);
1074    wd->size.imw = w;
1075    wd->size.imh = h;
1076    wd->size.w = wd->size.imw / wd->zoom;
1077    wd->size.h = wd->size.imh / wd->zoom;
1078    if (wd->zoom_animator)
1079      {
1080         wd->nosmooth--;
1081         if (wd->nosmooth == 0) _smooth_update(obj);
1082         ecore_animator_del(wd->zoom_animator);
1083         wd->zoom_animator = NULL;
1084      }
1085    evas_object_image_file_set(wd->img, NULL, NULL);
1086    evas_object_image_load_scale_down_set(wd->img, 8);
1087    evas_object_image_file_set(wd->img, wd->file, NULL);
1088    evas_object_image_preload(wd->img, 0);
1089    wd->main_load_pending = 1;
1090    grid_clearall(obj);
1091    if (wd->calc_job) ecore_job_del(wd->calc_job);
1092    wd->calc_job = ecore_job_add(_calc_job, wd);
1093    evas_object_smart_callback_call(obj, "load", NULL);
1094    wd->preload_num++;
1095    if (wd->preload_num == 1)
1096      {
1097         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1098                                 "elm,state,busy,start", "elm");
1099         evas_object_smart_callback_call(obj, "load,detail", NULL);
1100      }
1101      {
1102         double tz = wd->zoom;
1103         wd->zoom = 0.0;
1104         elm_photocam_zoom_set(wd->obj, tz);
1105      }
1106    return evas_object_image_load_error_get(wd->img);
1107 }
1108
1109 /*
1110  * Returns the path of the current image file
1111  *
1112  * @param obj The photocam object
1113  * @return Returns the path 
1114  *
1115  * @ingroup Photocam
1116  */
1117 EAPI const char *
1118 elm_photocam_file_get(const Evas_Object *obj)
1119 {
1120    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1121    Widget_Data *wd = elm_widget_data_get(obj);
1122    if (!wd) return NULL;
1123    return wd->file;
1124 }
1125
1126 /**
1127  * Set the zoom level of the photo
1128  *
1129  * This sets the zoom level. 1 will be 1:1 pixel for pixel. 2 will be 2:1
1130  * (that is 2x2 photo pixels will display as 1 on-screen pixel). 4:1 will be
1131  * 4x4 photo pixels as 1 screen pixel, and so on. The @p zoom parameter must
1132  * be greater than 0. It is usggested to stick to powers of 2. (1, 2, 4, 8,
1133  * 16, 32, etc.). 
1134  *
1135  * @param obj The photocam object
1136  * @param zoom The zoom level to set
1137  *
1138  * @ingroup Photocam
1139  */
1140 EAPI void
1141 elm_photocam_zoom_set(Evas_Object *obj, double zoom)
1142 {
1143    ELM_CHECK_WIDTYPE(obj, widtype);
1144    Widget_Data *wd = elm_widget_data_get(obj);
1145    Eina_List *l;
1146    Grid *g, *g_zoom = NULL;
1147    Evas_Coord pw, ph, rx, ry, rw, rh;
1148    int z;
1149    int zoom_changed = 0, started = 0;
1150    Ecore_Animator *an;
1151    if (!wd) return;
1152    if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1153    if (zoom == wd->zoom) return;
1154    wd->zoom = zoom;
1155    wd->size.ow = wd->size.w;
1156    wd->size.oh = wd->size.h;
1157    elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
1158    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1159    if ((rw <= 0) || (rh <= 0)) return;
1160
1161    if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
1162      {
1163         wd->size.nw = (double)wd->size.imw / wd->zoom;
1164         wd->size.nh = (double)wd->size.imh / wd->zoom;
1165      }
1166    else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT)
1167      {
1168         if ((wd->size.imw < 1) || (wd->size.imh < 1))
1169           {
1170              wd->size.nw = 0;
1171              wd->size.nw = 0;
1172           }
1173         else
1174           {
1175              ph = (wd->size.imh * rw) / wd->size.imw;
1176              if (ph > rh)
1177                {
1178                   pw = (wd->size.imw * rh) / wd->size.imh;
1179                   ph = rh;
1180                }
1181              else
1182                {
1183                   pw = rw;
1184                }
1185              if (wd->size.imw > wd->size.imh)
1186                z = wd->size.imw / pw;
1187              else
1188                z = wd->size.imh / ph;
1189              if      (z >= 8) z = 8;
1190              else if (z >= 4) z = 4;
1191              else if (z >= 2) z = 2;
1192              else             z = 1;
1193              if (z != wd->zoom) zoom_changed = 1;
1194              wd->zoom = z;
1195              wd->size.nw = pw;
1196              wd->size.nh = ph;
1197           }
1198      }
1199    else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL)
1200      {
1201         if ((wd->size.imw < 1) || (wd->size.imh < 1))
1202           {
1203              wd->size.nw = 0;
1204              wd->size.nw = 0;
1205           }
1206         else
1207           {
1208              ph = (wd->size.imh * rw) / wd->size.imw;
1209              if (ph < rh)
1210                {
1211                   pw = (wd->size.imw * rh) / wd->size.imh;
1212                   ph = rh;
1213                }
1214              else
1215                {
1216                   pw = rw;
1217                }
1218              if (wd->size.imw > wd->size.imh)
1219                z = wd->size.imw / pw;
1220              else
1221                z = wd->size.imh / ph;
1222              if      (z >= 8) z = 8;
1223              else if (z >= 4) z = 4;
1224              else if (z >= 2) z = 2;
1225              else             z = 1;
1226              if (z != wd->zoom) zoom_changed = 1;
1227              wd->zoom = z;
1228              wd->size.nw = pw;
1229              wd->size.nh = ph;
1230           }
1231      }
1232    if (wd->main_load_pending)
1233      {
1234         wd->size.w = wd->size.nw;
1235         wd->size.h = wd->size.nh;
1236         goto done;
1237      }
1238    EINA_LIST_FOREACH(wd->grids, l, g)
1239      {
1240         if (g->zoom == grid_zoom_calc(wd->zoom))
1241           {
1242              wd->grids = eina_list_remove(wd->grids, g);
1243              wd->grids = eina_list_prepend(wd->grids, g);
1244              _grid_raise(g);
1245              goto done;
1246           }
1247      }
1248    g = grid_create(obj);
1249    if (g)
1250      {
1251         if (eina_list_count(wd->grids) > 1)
1252           {
1253              g_zoom = eina_list_last(wd->grids)->data;
1254              wd->grids = eina_list_remove(wd->grids, g_zoom);
1255              grid_clear(obj, g_zoom);
1256              free(g_zoom);
1257              EINA_LIST_FOREACH(wd->grids, l, g_zoom)
1258                {
1259                   g_zoom->dead = 1;
1260                }
1261           }
1262         wd->grids = eina_list_prepend(wd->grids, g);
1263      }
1264    else
1265      {
1266         EINA_LIST_FREE(wd->grids, g)
1267           {
1268              grid_clear(obj, g);
1269              free(g);
1270           }
1271      }
1272    done:
1273    wd->t_start = ecore_loop_time_get();
1274    wd->t_end = wd->t_start + _elm_config->zoom_friction;
1275    if ((wd->size.w > 0) && (wd->size.h > 0))
1276      {
1277         wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.w;
1278         wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.h;
1279      }
1280    else
1281      {
1282         wd->size.spos.x = 0.5;
1283         wd->size.spos.y = 0.5;
1284      }
1285    if (rw > wd->size.w) wd->size.spos.x = 0.5;
1286    if (rh > wd->size.h) wd->size.spos.y = 0.5;
1287    if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
1288    if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
1289    if (wd->paused)
1290      {
1291         zoom_do(obj, 1.0);
1292      }
1293    else
1294      {
1295         if (!wd->zoom_animator)
1296           {
1297              wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
1298              wd->nosmooth++;
1299              if (wd->nosmooth == 1) _smooth_update(obj);
1300              started = 1;
1301           }
1302      }
1303    an = wd->zoom_animator;
1304    if (an)
1305      {
1306         if (!_zoom_anim(obj))
1307           {
1308              ecore_animator_del(an);
1309              an = NULL;
1310           }
1311      }
1312    if (wd->calc_job) ecore_job_del(wd->calc_job);
1313    wd->calc_job = ecore_job_add(_calc_job, wd);
1314    if (!wd->paused)
1315      {
1316         if (started)
1317           evas_object_smart_callback_call(obj, "zoom,start", NULL);
1318         if (!an)
1319           evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1320      }
1321    if (zoom_changed)
1322      evas_object_smart_callback_call(obj, "zoom,change", NULL);
1323 }
1324
1325 /**
1326  * Get the zoom level of the photo
1327  *
1328  * This returns the current zoom level of the photocam object. Note that if
1329  * you set the fill mode to other than ELM_PHOTOCAM_ZOOM_MODE_MANUAL
1330  * (which is the default), the zoom level may be changed at any time by the
1331  * photocam object itself to account for photo size and photocam viewpoer size
1332  *
1333  * @param obj The photocam object
1334  * @return The current zoom level
1335  *
1336  * @ingroup Photocam
1337  */
1338 EAPI double
1339 elm_photocam_zoom_get(const Evas_Object *obj)
1340 {
1341    ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
1342    Widget_Data *wd = elm_widget_data_get(obj);
1343    if (!wd) return 1.0;
1344    return wd->zoom;
1345 }
1346
1347 /**
1348  * Set the zoom mode
1349  *
1350  * This sets the zoom mode to manual or one of several automatic levels.
1351  * Manual (ELM_PHOTOCAM_ZOOM_MODE_MANUAL) means that zoom is set manually by
1352  * elm_photocam_zoom_set() and will stay at that level until changed by code
1353  * or until zoom mode is changed. This is the default mode.
1354  * The Automatic modes will allow the photocam object to automatically
1355  * adjust zoom mode based on properties. ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT) will
1356  * adjust zoom so the photo fits EXACTLY inside the scroll frame with no pixels
1357  * outside this area. ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL will be similar but
1358  * ensure no pixels within the frame are left unfilled.
1359  *
1360  * @param obj The photocam object
1361  * @param mode The desired mode
1362  *
1363  * @ingroup Photocam
1364  */
1365 EAPI void
1366 elm_photocam_zoom_mode_set(Evas_Object *obj, Elm_Photocam_Zoom_Mode mode)
1367 {
1368    ELM_CHECK_WIDTYPE(obj, widtype);
1369    Widget_Data *wd = elm_widget_data_get(obj);
1370    if (!wd) return;
1371    if (wd->mode == mode) return;
1372    wd->mode = mode;
1373      {
1374         double tz = wd->zoom;
1375         wd->zoom = 0.0;
1376         elm_photocam_zoom_set(wd->obj, tz);
1377      }
1378 }
1379
1380 /**
1381  * Get the zoom mode
1382  *
1383  * This gets the current zoom mode of the photocam object
1384  *
1385  * @param obj The photocam object
1386  * @return The current zoom mode
1387  *
1388  * @ingroup Photocam
1389  */
1390 EAPI Elm_Photocam_Zoom_Mode
1391 elm_photocam_zoom_mode_get(const Evas_Object *obj)
1392 {
1393    ELM_CHECK_WIDTYPE(obj, widtype) ELM_PHOTOCAM_ZOOM_MODE_LAST;
1394    Widget_Data *wd = elm_widget_data_get(obj);
1395    if (!wd) return ELM_PHOTOCAM_ZOOM_MODE_LAST;
1396    return wd->mode;
1397 }
1398
1399 /**
1400  * Get the current image pixel width and height
1401  *
1402  * This gets the current photo pixel width and height (for the original).
1403  * The size will be returned in the integers @p w and @p h that are pointed
1404  * to.
1405  *
1406  * @param obj The photocam object
1407  * @param w A pointer to the width return
1408  * @param h A pointer to the height return
1409  *
1410  * @ingroup Photocam
1411  */
1412 EAPI void
1413 elm_photocam_image_size_get(const Evas_Object *obj, int *w, int *h)
1414 {
1415    ELM_CHECK_WIDTYPE(obj, widtype);
1416    Widget_Data *wd = elm_widget_data_get(obj);
1417    if (!wd) return;
1418    if (w) *w = wd->size.imw;
1419    if (h) *h = wd->size.imh;
1420 }
1421
1422 /**
1423  * Get the current area of the image that is currently shown
1424  * 
1425  * This gets the region 
1426  * 
1427  */
1428 EAPI void
1429 elm_photocam_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1430 {
1431    ELM_CHECK_WIDTYPE(obj, widtype);
1432    Widget_Data *wd = elm_widget_data_get(obj);
1433    Evas_Coord sx, sy, sw, sh;
1434    if (!wd) return;
1435    elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
1436    elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
1437    if (wd->size.w > 0)
1438      {
1439         if (x)
1440           {
1441              *x = (wd->size.imw * sx) / wd->size.w;
1442              if (*x > wd->size.imw) *x = wd->size.imw;
1443              else if (*x < 0) *x = 0;
1444           }
1445         if (w)
1446           {
1447              *w = (wd->size.imw * sw) / wd->size.w;
1448              if (*w > wd->size.imw) *w = wd->size.imw;
1449              else if (*w < 0) *w = 0;
1450           }
1451      }
1452    else
1453      {
1454         if (x) *x = 0;
1455         if (w) *w = 0;
1456      }
1457
1458    if (wd->size.h > 0)
1459      {
1460         if (y)
1461           {
1462              *y = (wd->size.imh * sy) / wd->size.h;
1463              if (*y > wd->size.imh) *y = wd->size.imh;
1464              else if (*y < 0) *y = 0;
1465           }
1466         if (h)
1467           {
1468              *h = (wd->size.imh * sh) / wd->size.h;
1469              if (*h > wd->size.imh) *h = wd->size.imh;
1470              else if (*h < 0) *h = 0;
1471           }
1472      }
1473    else
1474      {
1475         if (y) *y = 0;
1476         if (h) *h = 0;
1477      }
1478 }
1479
1480 /**
1481  * Set the viewed portion of the image
1482  *
1483  * This sets the region of the image to be viewed
1484  *
1485  * @param obj The photocam object
1486  * @param x X-coordinate of region in image original pixels
1487  * @param y Y-coordinate of region in image original pixels
1488  * @param w Width of region in image original pixels
1489  * @param h Height of region in image original pixels
1490  *
1491  * @ingroup Photocam
1492  */
1493 EAPI void
1494 elm_photocam_image_region_show(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1495 {
1496    ELM_CHECK_WIDTYPE(obj, widtype);
1497    Widget_Data *wd = elm_widget_data_get(obj);
1498    int rx, ry, rw, rh;
1499    if (!wd) return;
1500    if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1501    rx = (x * wd->size.w) / wd->size.imw;
1502    ry = (y * wd->size.h) / wd->size.imh;
1503    rw = (w * wd->size.w) / wd->size.imw;
1504    rh = (w * wd->size.h) / wd->size.imh;
1505    if (rw < 1) rw = 1;
1506    if (rh < 1) rh = 1;
1507    if ((rx + rw) > wd->size.w) rx = wd->size.w - rw; 
1508    if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1509    if (wd->zoom_animator)
1510      {
1511         wd->nosmooth--;
1512         ecore_animator_del(wd->zoom_animator);
1513         wd->zoom_animator = NULL;
1514         zoom_do(obj, 1.0);
1515         evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1516      }
1517    elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
1518 }
1519
1520 /**
1521  * Bring in the viewed portion of the image
1522  *
1523  * This brings in the region of the image over time
1524  *
1525  * @param obj The photocam object
1526  * @param x X-coordinate of region in image original pixels
1527  * @param y Y-coordinate of region in image original pixels
1528  * @param w Width of region in image original pixels
1529  * @param h Height of region in image original pixels
1530  *
1531  * @ingroup Photocam
1532  */
1533 EAPI void
1534 elm_photocam_image_region_bring_in(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1535 {
1536    ELM_CHECK_WIDTYPE(obj, widtype);
1537    Widget_Data *wd = elm_widget_data_get(obj);
1538    int rx, ry, rw, rh;
1539    if (!wd) return;
1540    if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1541    rx = (x * wd->size.w) / wd->size.imw;
1542    ry = (y * wd->size.h) / wd->size.imh;
1543    rw = (w * wd->size.w) / wd->size.imw;
1544    rh = (w * wd->size.h) / wd->size.imh;
1545    if (rw < 1) rw = 1;
1546    if (rh < 1) rh = 1;
1547    if ((rx + rw) > wd->size.w) rx = wd->size.w - rw; 
1548    if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1549    if (wd->zoom_animator)
1550      {
1551         wd->nosmooth--;
1552         if (wd->nosmooth == 0) _smooth_update(obj);
1553         ecore_animator_del(wd->zoom_animator);
1554         wd->zoom_animator = NULL;
1555         zoom_do(obj, 1.0);
1556         evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1557     }
1558    elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
1559 }
1560
1561 /**
1562  * Set the paused state for photocam
1563  * 
1564  * This sets the paused state to on (1) or off (0) for photocam. The default
1565  * is on. This will stop zooming using animation ch change zoom levels and
1566  * change instantly. This will stop any existing animations that are running.
1567  * 
1568  * @param obj The photocam object
1569  * @param paused The pause state to set
1570  *
1571  * @ingroup Photocam
1572  */
1573 EAPI void
1574 elm_photocam_paused_set(Evas_Object *obj, Eina_Bool paused)
1575 {
1576    ELM_CHECK_WIDTYPE(obj, widtype);
1577    Widget_Data *wd = elm_widget_data_get(obj);
1578    if (!wd) return;
1579    if (wd->paused == !!paused) return;
1580    wd->paused = paused;
1581    if (wd->paused)
1582      {
1583         if (wd->zoom_animator)
1584           {
1585              ecore_animator_del(wd->zoom_animator);
1586              wd->zoom_animator = NULL;
1587              zoom_do(obj, 1.0);
1588              evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1589           }
1590      }
1591 }
1592
1593 /**
1594  * Get the paused state for photocam
1595  * 
1596  * This gets the current paused state for the photocam object.
1597  * 
1598  * @param obj The photocam object
1599  * @return The current paused state
1600  *
1601  * @ingroup Photocam
1602  */
1603 EAPI Eina_Bool
1604 elm_photocam_paused_get(const Evas_Object *obj)
1605 {
1606    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1607    Widget_Data *wd = elm_widget_data_get(obj);
1608    if (!wd) return EINA_FALSE;
1609    return wd->paused;
1610 }
1611
1612 /**
1613  * Get ther internal low-res image used for photocam
1614  * 
1615  * This gets the internal image object inside photocam. Do not modify it. It
1616  * is for inspection only, and hooking callbacks to. Nothing else. It may be
1617  * deleted at any time as well.
1618  *
1619  * @param obj The photocam object
1620  * @return The internal image object handle, or NULL if none exists
1621  *
1622  * @ingroup Photocam
1623  */
1624 EAPI Evas_Object *
1625 elm_photocam_internal_image_get(const Evas_Object *obj)
1626 {
1627    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1628    Widget_Data *wd = elm_widget_data_get(obj);
1629    if (!wd) return NULL;
1630    return wd->img;
1631 }