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