================================================================
[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_min_get(Evas_Object *obj __UNUSED__, Evas_Coord *x, Evas_Coord *y)
823 {
824    if (x) *x = 0;
825    if (y) *y = 0;
826 }
827
828 static void
829 _pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
830 {
831    Pan *sd = evas_object_smart_data_get(obj);
832    if (!sd) return;
833    if (w) *w = sd->wd->minw;
834    if (h) *h = sd->wd->minh;
835 }
836
837 static void
838 _pan_add(Evas_Object *obj)
839 {
840    Pan *sd;
841    Evas_Object_Smart_Clipped_Data *cd;
842    _pan_sc.add(obj);
843    cd = evas_object_smart_data_get(obj);
844    if (!cd) return;
845    sd = calloc(1, sizeof(Pan));
846    if (!sd) return;
847    sd->__clipped_data = *cd;
848    free(cd);
849    evas_object_smart_data_set(obj, sd);
850 }
851
852 static void
853 _pan_del(Evas_Object *obj)
854 {
855    Pan *sd = evas_object_smart_data_get(obj);
856    if (!sd) return;
857    _pan_sc.del(obj);
858 }
859
860 static void
861 _pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
862 {
863    Pan *sd = evas_object_smart_data_get(obj);
864    Evas_Coord ow, oh;
865    if (!sd) return;
866    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
867    if ((ow == w) && (oh == h)) return;
868    sd->wd->resized = 1;
869    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
870    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
871 }
872
873 static void
874 _pan_calculate(Evas_Object *obj)
875 {
876    Pan *sd = evas_object_smart_data_get(obj);
877    Evas_Coord ox, oy, ow, oh;
878    Eina_List *l;
879    Grid *g;
880    if (!sd) return;
881    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
882    img_place(sd->wd->obj, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
883    EINA_LIST_FOREACH(sd->wd->grids, l, g)
884      {
885         grid_load(sd->wd->obj, g);
886         grid_place(sd->wd->obj, g, sd->wd->pan_x, sd->wd->pan_y, ox, oy, ow, oh);
887      }
888 }
889
890 static void
891 _pan_move(Evas_Object *obj, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
892 {
893    Pan *sd = evas_object_smart_data_get(obj);
894    if (!sd) return;
895    if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
896    sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
897 }
898
899 static void
900 _hold_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
901 {
902    Widget_Data *wd = elm_widget_data_get(obj);
903    if (!wd) return;
904    elm_smart_scroller_hold_set(wd->scr, 1);
905 }
906
907 static void
908 _hold_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
909 {
910    Widget_Data *wd = elm_widget_data_get(obj);
911    if (!wd) return;
912    elm_smart_scroller_hold_set(wd->scr, 0);
913 }
914
915 static void
916 _freeze_on(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
917 {
918    Widget_Data *wd = elm_widget_data_get(obj);
919    if (!wd) return;
920    elm_smart_scroller_freeze_set(wd->scr, 1);
921 }
922
923 static void
924 _freeze_off(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
925 {
926    Widget_Data *wd = elm_widget_data_get(obj);
927    if (!wd) return;
928    elm_smart_scroller_freeze_set(wd->scr, 0);
929 }
930
931 static void
932 _scr_anim_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
933 {
934    evas_object_smart_callback_call(data, "scroll,anim,start", NULL);
935 }
936
937 static void
938 _scr_anim_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
939 {
940    evas_object_smart_callback_call(data, "scroll,anim,stop", NULL);
941 }
942
943 static void
944 _scr_drag_start(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
945 {
946    evas_object_smart_callback_call(data, "scroll,drag,start", NULL);
947 }
948
949 static void
950 _scr_drag_stop(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
951 {
952    evas_object_smart_callback_call(data, "scroll,drag,stop", NULL);
953 }
954
955 static void
956 _scr_scroll(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
957 {
958    evas_object_smart_callback_call(data, "scroll", NULL);
959 }
960
961 /**
962  * Add a new Photocam object
963  *
964  * @param parent The parent object
965  * @return The new object or NULL if it cannot be created
966  *
967  * @ingroup Photocam
968  */
969 EAPI Evas_Object *
970 elm_photocam_add(Evas_Object *parent)
971 {
972    Evas_Object *obj;
973    Evas *e;
974    Widget_Data *wd;
975    Evas_Coord minw, minh;
976    static Evas_Smart *smart = NULL;
977    Eina_Bool bounce = _elm_config->thumbscroll_bounce_enable;
978
979    EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
980
981    wd = ELM_NEW(Widget_Data);
982    e = evas_object_evas_get(parent);
983    if (!e) return NULL;
984    obj = elm_widget_add(e);
985    ELM_SET_WIDTYPE(widtype, "photocam");
986    elm_widget_type_set(obj, "photocam");
987    elm_widget_sub_object_add(parent, obj);
988    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
989    elm_widget_data_set(obj, wd);
990    elm_widget_del_hook_set(obj, _del_hook);
991    elm_widget_theme_hook_set(obj, _theme_hook);
992    elm_widget_can_focus_set(obj, EINA_TRUE);
993
994    wd->scr = elm_smart_scroller_add(e);
995    elm_smart_scroller_widget_set(wd->scr, obj);
996    elm_smart_scroller_object_theme_set(obj, wd->scr, "photocam", "base", "default");
997    evas_object_smart_callback_add(wd->scr, "scroll", _scr, obj);
998    evas_object_smart_callback_add(wd->scr, "drag", _scr, obj);
999    elm_widget_resize_object_set(obj, wd->scr);
1000
1001    evas_object_smart_callback_add(wd->scr, "animate,start", _scr_anim_start, obj);
1002    evas_object_smart_callback_add(wd->scr, "animate,stop", _scr_anim_stop, obj);
1003    evas_object_smart_callback_add(wd->scr, "drag,start", _scr_drag_start, obj);
1004    evas_object_smart_callback_add(wd->scr, "drag,stop", _scr_drag_stop, obj);
1005    evas_object_smart_callback_add(wd->scr, "scroll", _scr_scroll, obj);
1006    
1007    elm_smart_scroller_bounce_allow_set(wd->scr, bounce, bounce);
1008
1009    wd->obj = obj;
1010
1011    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
1012    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
1013    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
1014    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
1015    
1016    if (!smart)
1017      {
1018         static Evas_Smart_Class sc;
1019
1020         evas_object_smart_clipped_smart_set(&_pan_sc);
1021         sc = _pan_sc;
1022         sc.name = "elm_photocam_pan";
1023         sc.version = EVAS_SMART_CLASS_VERSION;
1024         sc.add = _pan_add;
1025         sc.del = _pan_del;
1026         sc.resize = _pan_resize;
1027         sc.move = _pan_move;
1028         sc.calculate = _pan_calculate;
1029         smart = evas_smart_class_new(&sc);
1030      }
1031    if (smart)
1032      {
1033         wd->pan_smart = evas_object_smart_add(e, smart);
1034         wd->pan = evas_object_smart_data_get(wd->pan_smart);
1035         wd->pan->wd = wd;
1036      }
1037
1038    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
1039                                      _pan_set, _pan_get, _pan_max_get,
1040                                      _pan_min_get, _pan_child_size_get);
1041
1042    wd->zoom = 1;
1043    wd->mode = ELM_PHOTOCAM_ZOOM_MODE_MANUAL;
1044    
1045    wd->tsize = 512;
1046    
1047    wd->img = evas_object_image_add(e);
1048    evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_DYNAMIC);
1049    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
1050                                   _mouse_down, obj);
1051    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
1052                                   _mouse_up, obj);
1053    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_MOVE,
1054                                   _mouse_move, obj);
1055    evas_object_image_scale_hint_set(wd->img, EVAS_IMAGE_SCALE_HINT_STATIC);
1056    evas_object_smart_member_add(wd->img, wd->pan_smart);
1057    elm_widget_sub_object_add(obj, wd->img);
1058    evas_object_image_filled_set(wd->img, 1);
1059    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_IMAGE_PRELOADED,
1060                                   _main_preloaded, obj);
1061    
1062    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), 
1063                              &minw, &minh);
1064    evas_object_size_hint_min_set(obj, minw, minh);
1065
1066    _sizing_eval(obj);
1067    return obj;
1068 }
1069
1070 /**
1071  * Set the photo file to be shown
1072  *
1073  * This sets (and shows) the specified file (with a relative or absolute path)
1074  * and will return a load error (same error that
1075  * evas_object_image_load_error_get() will return). The image will change and
1076  * adjust its size at this point and begin a background load process for this
1077  * photo that at some time in the future will be displayed at the full quality
1078  * needed.
1079  *
1080  * @param obj The photocam object
1081  * @param file The photo file
1082  * @return The return error (see EVAS_LOAD_ERROR_NONE, EVAS_LOAD_ERROR_GENERIC etc.)
1083  *
1084  * @ingroup Photocam
1085  */
1086 EAPI Evas_Load_Error
1087 elm_photocam_file_set(Evas_Object *obj, const char *file)
1088 {
1089    ELM_CHECK_WIDTYPE(obj, widtype) EVAS_LOAD_ERROR_NONE;
1090    Widget_Data *wd = elm_widget_data_get(obj);
1091    int w, h;
1092    if (!wd) return EVAS_LOAD_ERROR_GENERIC;
1093    if (!eina_stringshare_replace(&wd->file, file)) return EVAS_LOAD_ERROR_NONE;
1094    evas_object_hide(wd->img);
1095    evas_object_image_smooth_scale_set(wd->img, (wd->nosmooth == 0));
1096    evas_object_image_file_set(wd->img, NULL, NULL);
1097    evas_object_image_load_scale_down_set(wd->img, 0);
1098    evas_object_image_file_set(wd->img, wd->file, NULL);
1099    evas_object_image_size_get(wd->img, &w, &h);
1100    wd->size.imw = w;
1101    wd->size.imh = h;
1102    wd->size.w = wd->size.imw / wd->zoom;
1103    wd->size.h = wd->size.imh / wd->zoom;
1104    if (wd->zoom_animator)
1105      {
1106         wd->nosmooth--;
1107         if (wd->nosmooth == 0) _smooth_update(obj);
1108         ecore_animator_del(wd->zoom_animator);
1109         wd->zoom_animator = NULL;
1110      }
1111    evas_object_image_file_set(wd->img, NULL, NULL);
1112    evas_object_image_load_scale_down_set(wd->img, 8);
1113    evas_object_image_file_set(wd->img, wd->file, NULL);
1114    evas_object_image_preload(wd->img, 0);
1115    wd->main_load_pending = 1;
1116    grid_clearall(obj);
1117    if (wd->calc_job) ecore_job_del(wd->calc_job);
1118    wd->calc_job = ecore_job_add(_calc_job, wd);
1119    evas_object_smart_callback_call(obj, "load", NULL);
1120    wd->preload_num++;
1121    if (wd->preload_num == 1)
1122      {
1123         edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
1124                                 "elm,state,busy,start", "elm");
1125         evas_object_smart_callback_call(obj, "load,detail", NULL);
1126      }
1127      {
1128         double tz = wd->zoom;
1129         wd->zoom = 0.0;
1130         elm_photocam_zoom_set(wd->obj, tz);
1131      }
1132    return evas_object_image_load_error_get(wd->img);
1133 }
1134
1135 /*
1136  * Returns the path of the current image file
1137  *
1138  * @param obj The photocam object
1139  * @return Returns the path 
1140  *
1141  * @ingroup Photocam
1142  */
1143 EAPI const char *
1144 elm_photocam_file_get(const Evas_Object *obj)
1145 {
1146    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1147    Widget_Data *wd = elm_widget_data_get(obj);
1148    if (!wd) return NULL;
1149    return wd->file;
1150 }
1151
1152 /**
1153  * Set the zoom level of the photo
1154  *
1155  * This sets the zoom level. 1 will be 1:1 pixel for pixel. 2 will be 2:1
1156  * (that is 2x2 photo pixels will display as 1 on-screen pixel). 4:1 will be
1157  * 4x4 photo pixels as 1 screen pixel, and so on. The @p zoom parameter must
1158  * be greater than 0. It is usggested to stick to powers of 2. (1, 2, 4, 8,
1159  * 16, 32, etc.). 
1160  *
1161  * @param obj The photocam object
1162  * @param zoom The zoom level to set
1163  *
1164  * @ingroup Photocam
1165  */
1166 EAPI void
1167 elm_photocam_zoom_set(Evas_Object *obj, double zoom)
1168 {
1169    ELM_CHECK_WIDTYPE(obj, widtype);
1170    Widget_Data *wd = elm_widget_data_get(obj);
1171    Eina_List *l;
1172    Grid *g, *g_zoom = NULL;
1173    Evas_Coord pw, ph, rx, ry, rw, rh;
1174    int z;
1175    int zoom_changed = 0, started = 0;
1176    Ecore_Animator *an;
1177    if (!wd) return;
1178    if (zoom <= (1.0 / 256.0)) zoom = (1.0 / 256.0);
1179    if (zoom == wd->zoom) return;
1180    wd->zoom = zoom;
1181    wd->size.ow = wd->size.w;
1182    wd->size.oh = wd->size.h;
1183    elm_smart_scroller_child_pos_get(wd->scr, &rx, &ry);
1184    elm_smart_scroller_child_viewport_size_get(wd->scr, &rw, &rh);
1185    if ((rw <= 0) || (rh <= 0)) return;
1186
1187    if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_MANUAL)
1188      {
1189         wd->size.nw = (double)wd->size.imw / wd->zoom;
1190         wd->size.nh = (double)wd->size.imh / wd->zoom;
1191      }
1192    else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT)
1193      {
1194         if ((wd->size.imw < 1) || (wd->size.imh < 1))
1195           {
1196              wd->size.nw = 0;
1197              wd->size.nw = 0;
1198           }
1199         else
1200           {
1201              ph = (wd->size.imh * rw) / wd->size.imw;
1202              if (ph > rh)
1203                {
1204                   pw = (wd->size.imw * rh) / wd->size.imh;
1205                   ph = rh;
1206                }
1207              else
1208                {
1209                   pw = rw;
1210                }
1211              if (wd->size.imw > wd->size.imh)
1212                z = wd->size.imw / pw;
1213              else
1214                z = wd->size.imh / ph;
1215              if      (z >= 8) z = 8;
1216              else if (z >= 4) z = 4;
1217              else if (z >= 2) z = 2;
1218              else             z = 1;
1219              if (z != wd->zoom) zoom_changed = 1;
1220              wd->zoom = z;
1221              wd->size.nw = pw;
1222              wd->size.nh = ph;
1223           }
1224      }
1225    else if (wd->mode == ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL)
1226      {
1227         if ((wd->size.imw < 1) || (wd->size.imh < 1))
1228           {
1229              wd->size.nw = 0;
1230              wd->size.nw = 0;
1231           }
1232         else
1233           {
1234              ph = (wd->size.imh * rw) / wd->size.imw;
1235              if (ph < rh)
1236                {
1237                   pw = (wd->size.imw * rh) / wd->size.imh;
1238                   ph = rh;
1239                }
1240              else
1241                {
1242                   pw = rw;
1243                }
1244              if (wd->size.imw > wd->size.imh)
1245                z = wd->size.imw / pw;
1246              else
1247                z = wd->size.imh / ph;
1248              if      (z >= 8) z = 8;
1249              else if (z >= 4) z = 4;
1250              else if (z >= 2) z = 2;
1251              else             z = 1;
1252              if (z != wd->zoom) zoom_changed = 1;
1253              wd->zoom = z;
1254              wd->size.nw = pw;
1255              wd->size.nh = ph;
1256           }
1257      }
1258    if (wd->main_load_pending)
1259      {
1260         wd->size.w = wd->size.nw;
1261         wd->size.h = wd->size.nh;
1262         goto done;
1263      }
1264    EINA_LIST_FOREACH(wd->grids, l, g)
1265      {
1266         if (g->zoom == grid_zoom_calc(wd->zoom))
1267           {
1268              wd->grids = eina_list_remove(wd->grids, g);
1269              wd->grids = eina_list_prepend(wd->grids, g);
1270              _grid_raise(g);
1271              goto done;
1272           }
1273      }
1274    g = grid_create(obj);
1275    if (g)
1276      {
1277         if (eina_list_count(wd->grids) > 1)
1278           {
1279              g_zoom = eina_list_last(wd->grids)->data;
1280              wd->grids = eina_list_remove(wd->grids, g_zoom);
1281              grid_clear(obj, g_zoom);
1282              free(g_zoom);
1283              EINA_LIST_FOREACH(wd->grids, l, g_zoom)
1284                {
1285                   g_zoom->dead = 1;
1286                }
1287           }
1288         wd->grids = eina_list_prepend(wd->grids, g);
1289      }
1290    else
1291      {
1292         EINA_LIST_FREE(wd->grids, g)
1293           {
1294              grid_clear(obj, g);
1295              free(g);
1296           }
1297      }
1298    done:
1299    wd->t_start = ecore_loop_time_get();
1300    wd->t_end = wd->t_start + _elm_config->zoom_friction;
1301    if ((wd->size.w > 0) && (wd->size.h > 0))
1302      {
1303         wd->size.spos.x = (double)(rx + (rw / 2)) / (double)wd->size.w;
1304         wd->size.spos.y = (double)(ry + (rh / 2)) / (double)wd->size.h;
1305      }
1306    else
1307      {
1308         wd->size.spos.x = 0.5;
1309         wd->size.spos.y = 0.5;
1310      }
1311    if (rw > wd->size.w) wd->size.spos.x = 0.5;
1312    if (rh > wd->size.h) wd->size.spos.y = 0.5;
1313    if (wd->size.spos.x > 1.0) wd->size.spos.x = 1.0;
1314    if (wd->size.spos.y > 1.0) wd->size.spos.y = 1.0;
1315    if (wd->paused)
1316      {
1317         zoom_do(obj, 1.0);
1318      }
1319    else
1320      {
1321         if (!wd->zoom_animator)
1322           {
1323              wd->zoom_animator = ecore_animator_add(_zoom_anim, obj);
1324              wd->nosmooth++;
1325              if (wd->nosmooth == 1) _smooth_update(obj);
1326              started = 1;
1327           }
1328      }
1329    an = wd->zoom_animator;
1330    if (an)
1331      {
1332         if (!_zoom_anim(obj))
1333           {
1334              ecore_animator_del(an);
1335              an = NULL;
1336           }
1337      }
1338    if (wd->calc_job) ecore_job_del(wd->calc_job);
1339    wd->calc_job = ecore_job_add(_calc_job, wd);
1340    if (!wd->paused)
1341      {
1342         if (started)
1343           evas_object_smart_callback_call(obj, "zoom,start", NULL);
1344         if (!an)
1345           evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1346      }
1347    if (zoom_changed)
1348      evas_object_smart_callback_call(obj, "zoom,change", NULL);
1349 }
1350
1351 /**
1352  * Get the zoom level of the photo
1353  *
1354  * This returns the current zoom level of the photocam object. Note that if
1355  * you set the fill mode to other than ELM_PHOTOCAM_ZOOM_MODE_MANUAL
1356  * (which is the default), the zoom level may be changed at any time by the
1357  * photocam object itself to account for photo size and photocam viewpoer size
1358  *
1359  * @param obj The photocam object
1360  * @return The current zoom level
1361  *
1362  * @ingroup Photocam
1363  */
1364 EAPI double
1365 elm_photocam_zoom_get(const Evas_Object *obj)
1366 {
1367    ELM_CHECK_WIDTYPE(obj, widtype) 1.0;
1368    Widget_Data *wd = elm_widget_data_get(obj);
1369    if (!wd) return 1.0;
1370    return wd->zoom;
1371 }
1372
1373 /**
1374  * Set the zoom mode
1375  *
1376  * This sets the zoom mode to manual or one of several automatic levels.
1377  * Manual (ELM_PHOTOCAM_ZOOM_MODE_MANUAL) means that zoom is set manually by
1378  * elm_photocam_zoom_set() and will stay at that level until changed by code
1379  * or until zoom mode is changed. This is the default mode.
1380  * The Automatic modes will allow the photocam object to automatically
1381  * adjust zoom mode based on properties. ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT) will
1382  * adjust zoom so the photo fits EXACTLY inside the scroll frame with no pixels
1383  * outside this area. ELM_PHOTOCAM_ZOOM_MODE_AUTO_FILL will be similar but
1384  * ensure no pixels within the frame are left unfilled.
1385  *
1386  * @param obj The photocam object
1387  * @param mode The desired mode
1388  *
1389  * @ingroup Photocam
1390  */
1391 EAPI void
1392 elm_photocam_zoom_mode_set(Evas_Object *obj, Elm_Photocam_Zoom_Mode mode)
1393 {
1394    ELM_CHECK_WIDTYPE(obj, widtype);
1395    Widget_Data *wd = elm_widget_data_get(obj);
1396    if (!wd) return;
1397    if (wd->mode == mode) return;
1398    wd->mode = mode;
1399      {
1400         double tz = wd->zoom;
1401         wd->zoom = 0.0;
1402         elm_photocam_zoom_set(wd->obj, tz);
1403      }
1404 }
1405
1406 /**
1407  * Get the zoom mode
1408  *
1409  * This gets the current zoom mode of the photocam object
1410  *
1411  * @param obj The photocam object
1412  * @return The current zoom mode
1413  *
1414  * @ingroup Photocam
1415  */
1416 EAPI Elm_Photocam_Zoom_Mode
1417 elm_photocam_zoom_mode_get(const Evas_Object *obj)
1418 {
1419    ELM_CHECK_WIDTYPE(obj, widtype) ELM_PHOTOCAM_ZOOM_MODE_LAST;
1420    Widget_Data *wd = elm_widget_data_get(obj);
1421    if (!wd) return ELM_PHOTOCAM_ZOOM_MODE_LAST;
1422    return wd->mode;
1423 }
1424
1425 /**
1426  * Get the current image pixel width and height
1427  *
1428  * This gets the current photo pixel width and height (for the original).
1429  * The size will be returned in the integers @p w and @p h that are pointed
1430  * to.
1431  *
1432  * @param obj The photocam object
1433  * @param w A pointer to the width return
1434  * @param h A pointer to the height return
1435  *
1436  * @ingroup Photocam
1437  */
1438 EAPI void
1439 elm_photocam_image_size_get(const Evas_Object *obj, int *w, int *h)
1440 {
1441    ELM_CHECK_WIDTYPE(obj, widtype);
1442    Widget_Data *wd = elm_widget_data_get(obj);
1443    if (!wd) return;
1444    if (w) *w = wd->size.imw;
1445    if (h) *h = wd->size.imh;
1446 }
1447
1448 /**
1449  * Get the current area of the image that is currently shown
1450  * 
1451  * This gets the region 
1452  * 
1453  */
1454 EAPI void
1455 elm_photocam_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1456 {
1457    ELM_CHECK_WIDTYPE(obj, widtype);
1458    Widget_Data *wd = elm_widget_data_get(obj);
1459    Evas_Coord sx, sy, sw, sh;
1460    if (!wd) return;
1461    elm_smart_scroller_child_pos_get(wd->scr, &sx, &sy);
1462    elm_smart_scroller_child_viewport_size_get(wd->scr, &sw, &sh);
1463    if (wd->size.w > 0)
1464      {
1465         if (x)
1466           {
1467              *x = (wd->size.imw * sx) / wd->size.w;
1468              if (*x > wd->size.imw) *x = wd->size.imw;
1469              else if (*x < 0) *x = 0;
1470           }
1471         if (w)
1472           {
1473              *w = (wd->size.imw * sw) / wd->size.w;
1474              if (*w > wd->size.imw) *w = wd->size.imw;
1475              else if (*w < 0) *w = 0;
1476           }
1477      }
1478    else
1479      {
1480         if (x) *x = 0;
1481         if (w) *w = 0;
1482      }
1483
1484    if (wd->size.h > 0)
1485      {
1486         if (y)
1487           {
1488              *y = (wd->size.imh * sy) / wd->size.h;
1489              if (*y > wd->size.imh) *y = wd->size.imh;
1490              else if (*y < 0) *y = 0;
1491           }
1492         if (h)
1493           {
1494              *h = (wd->size.imh * sh) / wd->size.h;
1495              if (*h > wd->size.imh) *h = wd->size.imh;
1496              else if (*h < 0) *h = 0;
1497           }
1498      }
1499    else
1500      {
1501         if (y) *y = 0;
1502         if (h) *h = 0;
1503      }
1504 }
1505
1506 /**
1507  * Set the viewed portion of the image
1508  *
1509  * This sets the region of the image to be viewed
1510  *
1511  * @param obj The photocam object
1512  * @param x X-coordinate of region in image original pixels
1513  * @param y Y-coordinate of region in image original pixels
1514  * @param w Width of region in image original pixels
1515  * @param h Height of region in image original pixels
1516  *
1517  * @ingroup Photocam
1518  */
1519 EAPI void
1520 elm_photocam_image_region_show(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1521 {
1522    ELM_CHECK_WIDTYPE(obj, widtype);
1523    Widget_Data *wd = elm_widget_data_get(obj);
1524    int rx, ry, rw, rh;
1525    if (!wd) return;
1526    if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1527    rx = (x * wd->size.w) / wd->size.imw;
1528    ry = (y * wd->size.h) / wd->size.imh;
1529    rw = (w * wd->size.w) / wd->size.imw;
1530    rh = (w * wd->size.h) / wd->size.imh;
1531    if (rw < 1) rw = 1;
1532    if (rh < 1) rh = 1;
1533    if ((rx + rw) > wd->size.w) rx = wd->size.w - rw; 
1534    if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1535    if (wd->zoom_animator)
1536      {
1537         wd->nosmooth--;
1538         ecore_animator_del(wd->zoom_animator);
1539         wd->zoom_animator = NULL;
1540         zoom_do(obj, 1.0);
1541         evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1542      }
1543    elm_smart_scroller_child_region_show(wd->scr, rx, ry, rw, rh);
1544 }
1545
1546 /**
1547  * Bring in the viewed portion of the image
1548  *
1549  * This brings in the region of the image over time
1550  *
1551  * @param obj The photocam object
1552  * @param x X-coordinate of region in image original pixels
1553  * @param y Y-coordinate of region in image original pixels
1554  * @param w Width of region in image original pixels
1555  * @param h Height of region in image original pixels
1556  *
1557  * @ingroup Photocam
1558  */
1559 EAPI void
1560 elm_photocam_image_region_bring_in(Evas_Object *obj, int x, int y, int w, int h __UNUSED__)
1561 {
1562    ELM_CHECK_WIDTYPE(obj, widtype);
1563    Widget_Data *wd = elm_widget_data_get(obj);
1564    int rx, ry, rw, rh;
1565    if (!wd) return;
1566    if ((wd->size.imw < 1) || (wd->size.imh < 1)) return;
1567    rx = (x * wd->size.w) / wd->size.imw;
1568    ry = (y * wd->size.h) / wd->size.imh;
1569    rw = (w * wd->size.w) / wd->size.imw;
1570    rh = (w * wd->size.h) / wd->size.imh;
1571    if (rw < 1) rw = 1;
1572    if (rh < 1) rh = 1;
1573    if ((rx + rw) > wd->size.w) rx = wd->size.w - rw; 
1574    if ((ry + rh) > wd->size.h) ry = wd->size.h - rh;
1575    if (wd->zoom_animator)
1576      {
1577         wd->nosmooth--;
1578         if (!wd->nosmooth) _smooth_update(obj);
1579         ecore_animator_del(wd->zoom_animator);
1580         wd->zoom_animator = NULL;
1581         zoom_do(obj, 1.0);
1582         evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1583     }
1584    elm_smart_scroller_region_bring_in(wd->scr, rx, ry, rw, rh);
1585 }
1586
1587 /**
1588  * Set the paused state for photocam
1589  * 
1590  * This sets the paused state to on (1) or off (0) for photocam. The default
1591  * is on. This will stop zooming using animation ch change zoom levels and
1592  * change instantly. This will stop any existing animations that are running.
1593  * 
1594  * @param obj The photocam object
1595  * @param paused The pause state to set
1596  *
1597  * @ingroup Photocam
1598  */
1599 EAPI void
1600 elm_photocam_paused_set(Evas_Object *obj, Eina_Bool paused)
1601 {
1602    ELM_CHECK_WIDTYPE(obj, widtype);
1603    Widget_Data *wd = elm_widget_data_get(obj);
1604    if (!wd) return;
1605    if (wd->paused == !!paused) return;
1606    wd->paused = paused;
1607    if (wd->paused)
1608      {
1609         if (wd->zoom_animator)
1610           {
1611              ecore_animator_del(wd->zoom_animator);
1612              wd->zoom_animator = NULL;
1613              zoom_do(obj, 1.0);
1614              evas_object_smart_callback_call(obj, "zoom,stop", NULL);
1615           }
1616      }
1617 }
1618
1619 /**
1620  * Get the paused state for photocam
1621  * 
1622  * This gets the current paused state for the photocam object.
1623  * 
1624  * @param obj The photocam object
1625  * @return The current paused state
1626  *
1627  * @ingroup Photocam
1628  */
1629 EAPI Eina_Bool
1630 elm_photocam_paused_get(const Evas_Object *obj)
1631 {
1632    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1633    Widget_Data *wd = elm_widget_data_get(obj);
1634    if (!wd) return EINA_FALSE;
1635    return wd->paused;
1636 }
1637
1638 /**
1639  * Get the internal low-res image used for photocam
1640  * 
1641  * This gets the internal image object inside photocam. Do not modify it. It
1642  * is for inspection only, and hooking callbacks to. Nothing else. It may be
1643  * deleted at any time as well.
1644  *
1645  * @param obj The photocam object
1646  * @return The internal image object handle, or NULL if none exists
1647  *
1648  * @ingroup Photocam
1649  */
1650 EAPI Evas_Object *
1651 elm_photocam_internal_image_get(const Evas_Object *obj)
1652 {
1653    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1654    Widget_Data *wd = elm_widget_data_get(obj);
1655    if (!wd) return NULL;
1656    return wd->img;
1657 }
1658
1659 /**
1660  * Set the photocam scrolling bouncing.
1661  *
1662  * @param obj The photocam object
1663  * @param h_bounce bouncing for horizontal
1664  * @param v_bounce bouncing for vertical
1665  * @ingroup Photocam
1666  */
1667 EAPI void
1668 elm_photocam_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
1669 {
1670    ELM_CHECK_WIDTYPE(obj, widtype);
1671    Widget_Data *wd = elm_widget_data_get(obj);
1672    if (!wd) return;
1673    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
1674 }
1675
1676
1677 /**
1678  * Get the photocam scrolling bouncing.
1679  *
1680  * @param obj The photocam object
1681  * @param h_bounce bouncing for horizontal
1682  * @param v_bounce bouncing for vertical
1683  * @ingroup Photocam
1684  */
1685 EAPI void
1686 elm_photocam_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
1687 {
1688    ELM_CHECK_WIDTYPE(obj, widtype);
1689    Widget_Data *wd = elm_widget_data_get(obj);
1690    if (!wd) return;
1691    elm_smart_scroller_bounce_allow_get(wd->scr, h_bounce, v_bounce);
1692 }
1693