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