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