fix setas view
[apps/core/preloaded/ug-image-viewer-efl.git] / main / src / view / ivug-setas-view-callerid.cpp
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *        http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <Elementary.h>
17
18 #include "ivug-define.h"
19
20 #include "ivug-setas-view-callerid.h"
21 #include "ivug-setas-view.h"
22
23 #include "ivug-selectioninfo.h"
24
25 #include "ivug-image.h"
26 #include "ivug-drm-common.h"
27 #include "EFLUtil.h"
28 #include "ivug-scissorbox.h"
29
30 #include "ivug-db.h"
31
32 #define EDJ_PATH PREFIX"/res/edje/"PACKAGE
33
34 #define SETAS_EDJ_FILE EDJ_PATH"/ivug-setas.edj"
35
36 #define CLICK_TIME_MAX          (500)                           // click time.
37 #define CLICK_WIDTH_MIN (elm_config_finger_size_get() >> 1)     //click width, if mouse move under this value and under click time, it is click.
38 #define CLICK_INTERVAL_TIME 0.15
39
40 /* it is temp define, because scroll, scroll,anim,end is called earlyer.
41    So find bound of scissor box again after SETAS_INTERVAL_TIME */
42 #define SETAS_INTERVAL_TIME 0.1
43 #define SETAS_INTERVAL_TIME_FIRST_LOAD 0.3
44
45 #define POPUP_ICON_DIRECTORY_PATH       IMAGE_PATH"/Popup_icon"
46 #define ICON_PATH_ROTATE_LEFT           POPUP_ICON_DIRECTORY_PATH"/T01_1_popup_icon_Rotate left.png"
47 #define ICON_PATH_ROTATE_RIGHT          POPUP_ICON_DIRECTORY_PATH"/T01_1_popup_icon_Rotate right.png"
48
49 #define CONTROL_ICON_DIRECTORY_PATH IMAGE_PATH"/01_Control icon"
50 #define ICON_PATH_SAVE                          CONTROL_ICON_DIRECTORY_PATH"/T01_controlbar_icon_save.png"
51 #define ICON_PATH_PREV                          CONTROL_ICON_DIRECTORY_PATH"/00_winset_btn_prev.png"
52
53 #define CROP_BOX_INTERVAL_TIME 0.3
54
55 typedef struct {
56         Evas_Object *layout;
57         Evas_Object *notify;
58         Evas_Object *photocam;
59
60         Evas_Object *contents_area;
61
62         Evas_Object *gesture;
63
64         Evas_Object *btn_ok;
65
66         bool bShowMenu;         // Current state for button's visibility
67
68         char *filepath;
69         char *drm_filepath;
70
71         Evas_Coord_Rectangle rect;
72
73         int prev_x;
74         int prev_y;
75         int prev_w;
76         int prev_h;
77
78         struct {
79                 Evas_Object *box;
80                 double ratio;
81
82                 Eina_Bool bAspectPreserve;
83         } crop;
84
85         Ecore_Timer *box_timer;
86
87 } TSetAsData;
88
89 #define SETAS_DATA(obj) \
90                 (TSetAsData *)evas_object_data_get((Evas_Object *)(obj), "pSetAsData")
91
92 static void _on_moved(void *data, Evas *e, Evas_Object *obj, void *event_info);
93 static void _on_resized(void *data, Evas *e, Evas_Object *obj, void *event_info);
94
95 static void
96 _ConvertARGB888toY(unsigned char* pBuf, unsigned char* pGrayBuf, int width, int height)
97 {
98 /*
99         User should malloc output buffer
100 */
101         unsigned char* pSrc = (unsigned char*) pBuf;
102         unsigned char* pDSt = (unsigned char*) pGrayBuf;
103
104         unsigned char* pEnd = pDSt + height * width;
105
106         while (pDSt < pEnd)
107         {
108                 pSrc++;         // throw Alpaha value
109
110                 unsigned long r = *pSrc++;
111                 unsigned long g = *pSrc++;
112                 unsigned long b = *pSrc++;
113
114                 *pDSt++ = (308 * r + 600 * g + 116 * b) >> 10;
115         }
116 }
117
118 static void _put_scissorbox_default(TSetAsData *pSetAsData)
119 {
120         Evas_Object *image = ivug_image_internal_image_get(pSetAsData->photocam);
121
122         int image_w = 0;
123         int image_h = 0;
124         double ratio = pSetAsData->crop.ratio;
125         Evas_Coord_Rectangle rect = {0,};
126
127         ivug_image_image_size_get(pSetAsData->photocam, &image_w, &image_h);    // Get original image size.
128
129         int px, py, pw, ph;
130         ivug_image_region_get(pSetAsData->photocam, &px, &py, &pw, &ph);
131
132         MSG_SETAS_WARN("region XYWH(%d,%d,%d,%d)",      px, py, pw, ph);
133
134         int ix, iy, iw, ih;
135
136         if ( image_w > image_h )        // Landscape image
137         {
138                 if(ratio > 1.0) // height is larger
139                 {
140                         iw = image_h / (2 * ratio);
141                         ih = image_h / 2;
142                 }
143                 else
144                 {
145                         iw = image_h / 2;
146                         ih = (image_h * ratio) / 2;
147                 }
148         }
149         else
150         {
151                 if(ratio > 1.0) // height is larger
152                 {
153                         iw = image_w / (2 * ratio);
154                         ih = image_w / 2;
155                 }
156                 else
157                 {
158                         iw = image_w / 2;
159                         ih = (image_w * ratio) / 2;
160                 }
161         }
162
163         ix = (image_w - iw)/2;
164         iy = (image_h - ih)/2;
165
166
167         rect.x = (double)ix * pw / image_w + px;
168         rect.y = (double)iy * ph / image_h + py;
169
170         rect.w = (double)iw * pw / image_w;
171         rect.h = (double)ih * ph / image_h;
172
173         MSG_SETAS_WARN("Zoom Put Box in LCD XYWH(%d,%d,%d,%d)",
174                 rect.x, rect.y, rect.w, rect.h);
175
176         ivug_scissorbox_region_set(pSetAsData->crop.box, rect.x, rect.y, rect.w, rect.h);
177
178         ivug_scissorbox_attach(pSetAsData->crop.box, image);            // Attach to photocam
179 }
180
181 static Eina_Bool _put_scissorbox_timer_cb(void *data)
182 {
183         TSetAsData *pSetAsData = SETAS_DATA(data);
184
185         pSetAsData->box_timer = NULL;
186
187         _put_scissorbox_default(pSetAsData);
188
189         elm_object_disabled_set(pSetAsData->btn_ok, EINA_FALSE);
190
191         return ECORE_CALLBACK_CANCEL;
192 }
193
194
195 static void
196 _on_btn_ok_clicked(void *data, Evas_Object *obj, void *event_info)
197 {
198         TSetAsData *pSetAsData = SETAS_DATA(data);
199         IV_ASSERT(pSetAsData != NULL);
200
201         MSG_SETAS_HIGH("OK button clicked");
202         evas_object_smart_callback_call(pSetAsData->layout, "ok,clicked", NULL);
203
204         evas_object_event_callback_del_full(pSetAsData->layout, EVAS_CALLBACK_MOVE, _on_moved, pSetAsData->layout);
205         evas_object_event_callback_del_full(pSetAsData->layout, EVAS_CALLBACK_RESIZE, _on_resized, pSetAsData->layout);
206
207         if ( pSetAsData->crop.box )
208         {
209                 evas_object_del(pSetAsData->crop.box);
210                 pSetAsData->crop.box = NULL;
211         }
212
213 }
214
215
216 static void
217 _on_btn_cancel_clicked(void *data, Evas_Object *obj, void *event_info)
218 {
219         TSetAsData *pSetAsData = SETAS_DATA(data);
220         IV_ASSERT(pSetAsData != NULL);
221
222         MSG_SETAS_HIGH("Cancel button clicked");
223
224         evas_object_event_callback_del_full(pSetAsData->layout, EVAS_CALLBACK_MOVE, _on_moved, pSetAsData->layout);
225         evas_object_event_callback_del_full(pSetAsData->layout, EVAS_CALLBACK_RESIZE, _on_resized, pSetAsData->layout);
226
227         if ( pSetAsData->crop.box )
228         {
229                 evas_object_del(pSetAsData->crop.box);
230                 pSetAsData->crop.box = NULL;
231         }
232
233         evas_object_smart_callback_call(pSetAsData->layout, "cancel,clicked", NULL);
234
235 //      _ivug_setas_view_remove(pSetAsData);
236 }
237
238
239 static void
240 _on_btn_rotate_r_clicked(void *data, Evas_Object *obj, void *event_info)
241 {
242         TSetAsData *pSetAsData = SETAS_DATA(data);
243         IV_ASSERT(pSetAsData != NULL);
244
245         MSG_SETAS_HIGH("Rotate r button clicked");
246
247         int degree = (ivug_image_rotate_get(pSetAsData->photocam) - 90) % 360;
248
249         ///////////////////////////////////////////////////////////////////
250         int org_x, org_y, org_w, org_h;
251
252         ivug_image_region_get(pSetAsData->photocam, &org_x, &org_y, &org_w, &org_h);
253         MSG_SETAS_MED("org_x=%d, org_y=%d, org_w=%d, org_h=%d", org_x, org_y, org_w, org_h);
254
255         int org_sx, org_sy, org_sw, org_sh;
256         ivug_scissorbox_region_get(pSetAsData->crop.box, &org_sx, &org_sy, &org_sw, &org_sh);
257
258         int dx = org_sx-org_x;
259         int dy = org_sy-org_y;
260
261         ivug_image_rotate_set(pSetAsData->photocam, degree);
262
263         int x, y, w, h;
264
265         ivug_image_region_get(pSetAsData->photocam, &x, &y, &w, &h);
266         MSG_SETAS_MED("x=%d, y=%d, w=%d, h=%d", x, y, w, h);
267
268         int sx, sy, sw, sh;
269
270         double ratio = (double)h/org_w; // h is rotated w
271
272         sw = org_sw*ratio;
273         sh = org_sh*ratio;
274         dx *= ratio;
275         dy *= ratio;
276
277         ivug_scissorbox_boundary_set(pSetAsData->crop.box, x, y, w, h);
278
279         ///////////////////////////////////////////////////////////////////
280
281         int base_x = x+w;
282         int base_y = y;
283
284         sx = base_x-dy-sh;
285         sy = base_y+dx;
286
287         MSG_SETAS_MED("sx=%d, sy=%d, sw=%d, sh=%d", sx, sy, sw, sh);
288
289         ivug_scissorbox_region_set(pSetAsData->crop.box, sx, sy, sh, sw);
290
291 }
292
293
294 static void
295 _on_btn_rotate_l_clicked(void *data, Evas_Object *obj, void *event_info)
296 {
297         TSetAsData *pSetAsData = SETAS_DATA(data);
298         IV_ASSERT(pSetAsData != NULL);
299
300         MSG_SETAS_HIGH("Rotate l button clicked");
301
302         int degree = (ivug_image_rotate_get(pSetAsData->photocam) + 90) % 360;
303
304         ///////////////////////////////////////////////////////////////////
305         int org_x, org_y, org_w, org_h;
306
307         ivug_image_region_get(pSetAsData->photocam, &org_x, &org_y, &org_w, &org_h);
308         MSG_SETAS_MED("org_x=%d, org_y=%d, org_w=%d, org_h=%d", org_x, org_y, org_w, org_h);
309
310         int org_sx, org_sy, org_sw, org_sh;
311         ivug_scissorbox_region_get(pSetAsData->crop.box, &org_sx, &org_sy, &org_sw, &org_sh);
312
313         int dx = org_sx-org_x;
314         int dy = org_sy-org_y;
315
316         ivug_image_rotate_set(pSetAsData->photocam, degree);
317
318         int x, y, w, h;
319
320         ivug_image_region_get(pSetAsData->photocam, &x, &y, &w, &h);
321         MSG_SETAS_MED("x=%d, y=%d, w=%d, h=%d", x, y, w, h);
322
323         int sx, sy, sw, sh;
324
325         double ratio = (double)h/org_w; // h is rotated w
326
327         sw = org_sw*ratio;
328         sh = org_sh*ratio;
329         dx *= ratio;
330         dy *= ratio;
331
332         ivug_scissorbox_boundary_set(pSetAsData->crop.box, x, y, w, h);
333
334         ///////////////////////////////////////////////////////////////////
335
336         int base_x = x;
337         int base_y = y+h;
338
339         sx = base_x+dy;
340         sy = base_y-dx-sw;
341
342         MSG_SETAS_MED("sx=%d, sy=%d, sw=%d, sh=%d", sx, sy, sw, sh);
343
344         ivug_scissorbox_region_set(pSetAsData->crop.box, sx, sy, sh, sw);
345 }
346
347
348 static void
349 _on_photocam_loaded(void *data, Evas_Object *obj, void *event_info)
350 {
351         TSetAsData *pSetAsData = SETAS_DATA(data);
352         MSG_SETAS_HIGH("Photocam preloaded");
353
354 #if 0
355         typedef enum _Evas_Load_Error
356         {
357            EVAS_LOAD_ERROR_NONE = 0, /**< No error on load */
358            EVAS_LOAD_ERROR_GENERIC = 1, /**< A non-specific error occurred */
359            EVAS_LOAD_ERROR_DOES_NOT_EXIST = 2, /**< File (or file path) does not exist */
360            EVAS_LOAD_ERROR_PERMISSION_DENIED = 3, /**< Permission deinied to an existing file (or path) */
361            EVAS_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED = 4, /**< Allocation of resources failure prevented load */
362            EVAS_LOAD_ERROR_CORRUPT_FILE = 5, /**< File corrupt (but was detected as a known format) */
363            EVAS_LOAD_ERROR_UNKNOWN_FORMAT = 6 /**< File is not a known format */
364         } Evas_Load_Error; /**< Load error you can get from loading of files - see evas_load_error_str() too */
365 #endif
366
367         Evas_Load_Error error = static_cast<Evas_Load_Error>((int)event_info);
368
369         if ( error != EVAS_LOAD_ERROR_NONE )
370         {
371                 MSG_SETAS_ERROR("Error occured during decoding. Error=%d", error);
372
373                 if ( error == EVAS_LOAD_ERROR_UNKNOWN_FORMAT )
374                 {
375                         evas_object_smart_callback_call(pSetAsData->layout, "load,failed", (void *)SETAS_ERROR_TYPE_UNKNOWN_FORMAT);
376                 }
377                 else if ( error == EVAS_LOAD_ERROR_PERMISSION_DENIED )
378                 {
379                         evas_object_smart_callback_call(pSetAsData->layout, "load,failed", (void *)SETAS_ERROR_TYPE_PERMISSION_DENIED);
380                 }
381                 else
382                 {
383                         evas_object_smart_callback_call(pSetAsData->layout, "load,failed", (void *)SETAS_ERROR_TYPE_INVALID_FILE);
384                 }
385
386                 return;
387         }
388
389 // Remove thumbnail
390         Evas_Object *object = elm_object_part_content_unset(pSetAsData->layout, "setasview.thumbnail");
391         if(object != NULL)
392         {
393                 evas_object_del(object);
394         }
395
396         MSG_SETAS_HIGH("Photocam loaded.");
397
398         pSetAsData->box_timer = ecore_timer_add(CROP_BOX_INTERVAL_TIME, _put_scissorbox_timer_cb, (void *)pSetAsData->layout);
399
400         evas_object_smart_callback_call(pSetAsData->layout, "loaded", NULL);
401
402         pSetAsData->notify = ivug_notify_static_create(pSetAsData->contents_area, IDS_CALLER_ID_NOTIFY, NOTIFY_ALIGN_BOTTOM);
403
404         int x, y, w, h;
405         ivug_image_region_get(pSetAsData->photocam,  &x, &y, &w, &h);
406
407         pSetAsData->prev_x = x;
408         pSetAsData->prev_y = y;
409         pSetAsData->prev_w = w;
410         pSetAsData->prev_h = h;
411 }
412
413
414 static void _on_moved(void *data, Evas *e, Evas_Object *obj, void *event_info)
415 {
416 //      TSetAsData *pSetAsData = SETAS_DATA(data);
417
418 }
419
420 static void _on_resized(void *data, Evas *e, Evas_Object *obj, void *event_info)
421 {
422         TSetAsData *pSetAsData = SETAS_DATA(data);
423         ///////////////////////////////////////////////////////////////////
424         int org_x, org_y, org_w, org_h;
425
426         MSG_SETAS_MED("prev_x=%d, prev_y=%d, prev_w=%d, prev_h=%d", pSetAsData->prev_x, pSetAsData->prev_y, pSetAsData->prev_w, pSetAsData->prev_h);
427
428         org_x = pSetAsData->prev_x;
429         org_y = pSetAsData->prev_y;
430         org_w = pSetAsData->prev_w;
431         org_h = pSetAsData->prev_h;
432
433         if(org_w == 0 || org_h == 0)
434                 return;
435
436         int org_sx, org_sy, org_sw, org_sh;
437         ivug_scissorbox_region_get(pSetAsData->crop.box, &org_sx, &org_sy, &org_sw, &org_sh);
438
439         MSG_SETAS_MED("org_sx=%d, org_sy=%d, org_sw=%d, org_sh=%d", org_sx, org_sy, org_sw, org_sh);
440
441         int dx = org_sx-org_x;
442         int dy = org_sy-org_y;
443
444         int lcd_x, lcd_y, lcd_w, lcd_h;
445
446         evas_object_geometry_get(obj, &lcd_x, &lcd_y, &lcd_w, &lcd_h);
447         MSG_SETAS_MED("lcd_x=%d, lcd_y=%d, lcd_w=%d, lcd_h=%d", lcd_x, lcd_y, lcd_w, lcd_h);
448
449         int ph, pw;
450
451         int img_w, img_h;
452         int ext_w, ext_h;
453
454         img_w = org_w;
455         img_h = org_h;
456         ext_w = lcd_w;
457         ext_h = lcd_h;
458
459         ph = (img_h * ext_w) / img_w;
460
461         if (ph > ext_h)
462         {
463                 pw = (img_w * ext_h) / img_h;
464                 ph = ext_h;
465         }
466         else
467         {
468                 pw = ext_w;
469         }
470
471         double zoom = 0.0;
472
473         if ( img_w > img_h)
474         {
475                 zoom = (double)pw / img_w;
476         }
477         else
478         {
479                 zoom = (double)ph / img_h;
480         }
481
482         int sx, sy, sw, sh;
483
484         sw = org_sw*zoom;
485         sh = org_sh*zoom;
486         dx *= zoom;
487         dy *= zoom;
488
489         sx = (ext_w-img_w*zoom)/2 + dx;
490         sy = (ext_h-img_h*zoom)/2 + dy;
491
492         ivug_scissorbox_boundary_set(pSetAsData->crop.box, (ext_w-img_w*zoom)/2, (ext_h-img_h*zoom)/2, img_w*zoom, img_h*zoom);
493
494         ///////////////////////////////////////////////////////////////////
495
496         MSG_SETAS_MED("sx=%d, sy=%d, sw=%d, sh=%d", sx, sy, sw, sh);
497
498         ivug_scissorbox_region_set(pSetAsData->crop.box, sx, sy, sw, sh);
499
500         ivug_image_region_get(pSetAsData->photocam, &org_x, &org_y, &org_w, &org_h);
501
502         MSG_SETAS_MED("org_x=%d, org_y=%d, org_w=%d, org_h=%d", org_x, org_y, org_w, org_h);
503
504         pSetAsData->prev_x = org_x;
505         pSetAsData->prev_y = org_y;
506         pSetAsData->prev_w = org_w;
507         pSetAsData->prev_h = org_h;
508 }
509
510 static void _on_removed(void *data, Evas *e, Evas_Object *obj, void *event_info)
511 {
512         TSetAsData *pSetAsData = (TSetAsData *)data;
513
514         MSG_SETAS_HIGH("Remoing SetAsData");
515
516         if(pSetAsData->notify)
517         {
518                 evas_object_del(pSetAsData->notify);
519                 pSetAsData->notify = NULL;
520         }
521
522         if(pSetAsData->crop.box)
523         {
524                 evas_object_del(pSetAsData->crop.box);
525                 pSetAsData->crop.box = NULL;
526         }
527         if(pSetAsData->filepath)
528         {
529                 free(pSetAsData->filepath);
530                 pSetAsData->filepath = NULL;
531         }
532
533         if(pSetAsData->drm_filepath)
534         {
535                 ivug_remove_file(pSetAsData->drm_filepath);
536                 free(pSetAsData->drm_filepath);
537                 pSetAsData->drm_filepath = NULL;
538         }
539
540         if(pSetAsData->btn_ok)
541         {
542                 evas_object_del(pSetAsData->btn_ok);
543                 pSetAsData->btn_ok = NULL;
544         }
545
546         free(pSetAsData);
547
548 }
549
550 static Evas_Event_Flags _finger_tap_end(void *data , void *event_info)
551 {
552         Elm_Gesture_Taps_Info *p = (Elm_Gesture_Taps_Info *) event_info;
553
554         MSG_SETAS_HIGH("Finger tab end. evt=%d", p->timestamp);
555
556         if ( p->n != 1 ) return EVAS_EVENT_FLAG_NONE;
557
558         TSetAsData *pSetAsData = (TSetAsData *)data;
559         IV_ASSERT(pSetAsData != NULL);
560
561         if(pSetAsData->bShowMenu)
562         {
563                 MSG_SETAS_HIGH("Hide");
564                 elm_win_indicator_mode_set((Evas_Object*)ug_get_window(), ELM_WIN_INDICATOR_HIDE);
565                 evas_object_hide(pSetAsData->notify);
566         }
567         else
568         {
569                 MSG_SETAS_HIGH("Show");
570                 if(gIsDesktopMode() == false)
571                 {
572                         elm_win_indicator_mode_set((Evas_Object *)ug_get_window(), ELM_WIN_INDICATOR_SHOW);
573                 }
574                 evas_object_show(pSetAsData->notify);
575         }
576
577         pSetAsData->bShowMenu = !pSetAsData->bShowMenu;
578
579         return EVAS_EVENT_FLAG_NONE;
580 }
581
582 void _add_gesture_layer(Evas_Object *parent, TSetAsData *pSetAsData)
583 {
584         IV_ASSERT(pSetAsData != NULL);
585
586         Evas_Object *gesture = pSetAsData->gesture;
587
588         gesture = elm_gesture_layer_add(parent);
589         elm_gesture_layer_hold_events_set(gesture, EINA_FALSE);
590
591         elm_gesture_layer_cb_set(gesture, ELM_GESTURE_N_TAPS, ELM_GESTURE_STATE_END, _finger_tap_end, (void *)pSetAsData);
592
593         if ( elm_gesture_layer_attach(gesture, pSetAsData->photocam) == EINA_FALSE)
594         {
595                 MSG_SETAS_ERROR("Cannot attach event rect");
596         }
597
598         evas_object_name_set(gesture, "CallerID:Getsture");
599 }
600
601 Evas_Object *_ivug_setas_callerid_create_layout(Evas_Object *parent)
602 {
603         TSetAsData *pSetAsData = (TSetAsData *)calloc(1, sizeof(TSetAsData));
604
605         if ( pSetAsData == NULL )
606         {
607                 MSG_SETAS_ERROR("Cannot alloc pSetasData");
608                 return NULL;
609         }
610
611         Elm_Object_Item *item[4];
612         Evas_Object *controlbar = NULL;
613
614         Evas_Object *photocam = NULL;
615
616         pSetAsData->layout = ivug_layout_add2(parent, SETAS_EDJ_FILE, "setas_view");
617         if ( pSetAsData->layout == NULL )
618         {
619                 MSG_SETAS_ERROR("Cannot create layout.");
620                 goto error;
621         }
622
623         pSetAsData->crop.box = ivug_scissorbox_add(pSetAsData->layout);
624
625         if ( pSetAsData->crop.box == NULL )
626         {
627                 MSG_SETAS_ERROR("Cannot create layout.");
628                 goto error;
629         }
630
631         evas_object_smart_member_add(pSetAsData->crop.box, pSetAsData->layout);
632
633         photocam = ivug_image_create(pSetAsData->layout);
634         ivug_image_animated_set(photocam, EINA_FALSE);  // Show first frame only when AGIF
635         ivug_image_hold_set(photocam , EINA_TRUE);                      // Disable mouse events
636
637         evas_object_name_set(photocam, "setas_photocam");
638
639         pSetAsData->photocam = photocam;
640
641         evas_object_smart_callback_add(photocam, "loaded", _on_photocam_loaded, (void *)pSetAsData->layout);
642         elm_object_part_content_set(pSetAsData->layout, "setasview.photocam", photocam);
643         evas_object_show(photocam);
644
645         pSetAsData->bShowMenu = true;
646         _add_gesture_layer(pSetAsData->layout, pSetAsData);
647
648         MSG_SETAS_HIGH("Create setas layout");
649         pSetAsData->contents_area = ivug_default_layout_add(parent);
650         evas_object_name_set(pSetAsData->contents_area, "contets_area");
651         if ( pSetAsData->contents_area == NULL )
652         {
653                 MSG_SETAS_ERROR("Cannot create contets_area.");
654         }
655
656         elm_object_part_content_set(pSetAsData->layout, "setasview.contents", pSetAsData->contents_area);
657
658         evas_object_data_set(pSetAsData->layout, "pSetAsData", pSetAsData);
659         //evas_object_event_callback_add(pSetAsData->layout, EVAS_CALLBACK_DEL, _on_removed, pSetAsData);
660         evas_object_event_callback_add(pSetAsData->layout, EVAS_CALLBACK_MOVE, _on_moved, pSetAsData->layout);
661         evas_object_event_callback_add(pSetAsData->layout, EVAS_CALLBACK_RESIZE, _on_resized, pSetAsData->layout);
662
663         return pSetAsData->layout;
664
665 error:
666         if ( pSetAsData->crop.box )
667                 evas_object_del(pSetAsData->crop.box);
668
669         if ( pSetAsData->layout )
670                 evas_object_del(pSetAsData->layout);
671
672         if ( pSetAsData )
673                 free(pSetAsData);
674
675         return NULL;
676 }
677
678 Evas_Object *_ivug_setas_callerid_delete_layout(Evas_Object *obj)
679 {
680         TSetAsData *pSetAsData = SETAS_DATA(obj);
681         IV_ASSERT(pSetAsData != NULL);
682
683         if(pSetAsData->box_timer)
684         {
685                 ecore_timer_del(pSetAsData->box_timer);
686                 pSetAsData->box_timer = NULL;
687         }
688
689         if(pSetAsData->photocam)
690         {
691                 MSG_SETAS_HIGH("Removing photocam");
692                 evas_object_del(pSetAsData->photocam);
693                 pSetAsData->photocam = NULL;
694         }
695
696         if(pSetAsData->notify)
697         {
698                 evas_object_del(pSetAsData->notify);
699                 pSetAsData->notify = NULL;
700         }
701
702         if(pSetAsData->contents_area)
703         {
704                 evas_object_del(pSetAsData->contents_area);
705                 pSetAsData->contents_area = NULL;
706         }
707
708         if(pSetAsData->layout)
709         {
710                 evas_object_event_callback_del_full(pSetAsData->layout, EVAS_CALLBACK_MOVE, _on_moved, pSetAsData->layout);
711                 evas_object_event_callback_del_full(pSetAsData->layout, EVAS_CALLBACK_RESIZE, _on_resized, pSetAsData->layout);
712                 evas_object_del(pSetAsData->layout);
713                 pSetAsData->layout = NULL;
714         }
715
716         if(pSetAsData->crop.box)
717         {
718                 evas_object_del(pSetAsData->crop.box);
719                 pSetAsData->crop.box = NULL;
720         }
721         if(pSetAsData->filepath)
722         {
723                 free(pSetAsData->filepath);
724                 pSetAsData->filepath = NULL;
725         }
726
727         if(pSetAsData->drm_filepath)
728         {
729                 ivug_remove_file(pSetAsData->drm_filepath);
730                 free(pSetAsData->drm_filepath);
731                 pSetAsData->drm_filepath = NULL;
732         }
733
734         if(pSetAsData->btn_ok)
735         {
736                 evas_object_del(pSetAsData->btn_ok);
737                 pSetAsData->btn_ok = NULL;
738         }
739
740         free(pSetAsData);
741
742         return NULL;
743 }
744
745 bool _ivug_setas_callerid_load_file(Evas_Object *obj, const char *filepath)
746 {
747         TSetAsData *pSetAsData = SETAS_DATA(obj);
748
749         MSG_SETAS_HIGH("Load image file : %s", filepath);
750
751         pSetAsData->filepath = strdup(filepath);
752
753 // Set thumnail first
754         Evas_Object *thumbnail = NULL;
755         Evas_Load_Error error = EVAS_LOAD_ERROR_NONE;
756
757         {
758                 error = ivug_image_file_set(pSetAsData->photocam, filepath, "noAnim");
759         }
760
761         if ( error != EVAS_LOAD_ERROR_NONE )
762         {
763                 // TODO : What is good for error handing??????
764                 MSG_SETAS_ERROR("FileSet Error=%d", error);
765
766                 if ( error == EVAS_LOAD_ERROR_UNKNOWN_FORMAT )
767                 {
768                         evas_object_smart_callback_call(pSetAsData->layout, "load,failed", (void *)SETAS_ERROR_TYPE_UNKNOWN_FORMAT);
769                         return false;
770                 }
771                 else if ( error == EVAS_LOAD_ERROR_PERMISSION_DENIED )
772                 {
773                         evas_object_smart_callback_call(pSetAsData->layout, "load,failed", (void *)SETAS_ERROR_TYPE_PERMISSION_DENIED);
774                         return false;
775                 }
776                 else
777                 {
778                         evas_object_smart_callback_call(pSetAsData->layout, "load,failed", (void *)SETAS_ERROR_TYPE_INVALID_FILE);
779                         return false;
780                 }
781
782                 return false;
783         }
784
785         return true;
786 }
787
788 Evas_Object *_ivug_setas_callerid_internal_image_get(Evas_Object *obj)
789 {
790         TSetAsData *pSetAsData = SETAS_DATA(obj);
791
792         MSG_SETAS_HIGH("Internal image get!");
793
794         return pSetAsData->photocam;
795 }
796
797 bool _ivug_setas_callerid_select_region_get(Evas_Object *obj, int *x, int *y, int *w, int *h)
798 {
799         TSetAsData *pSetAsData = SETAS_DATA(obj);
800
801         if ( pSetAsData->crop.box == NULL)
802         {
803                 return false;
804         }
805
806         ivug_scissorbox_region_get(pSetAsData->crop.box, x, y, w, h);
807
808         return true;
809 }
810
811
812 void _ivug_setas_callerid_aspect_ratio_set(Evas_Object *obj, double ratio)
813 {
814         TSetAsData *pSetAsData = SETAS_DATA(obj);
815
816         pSetAsData->crop.bAspectPreserve = TRUE;
817         pSetAsData->crop.ratio = ratio;
818
819         ivug_scissorbox_ratio_fix( pSetAsData->crop.box, EINA_TRUE);
820 }
821
822 void _ivug_setas_callerid_create_menu(Evas_Object *obj, Evas_Object *navi_bar)
823 {
824         TSetAsData *pSetAsData = SETAS_DATA(obj);
825
826         pSetAsData->btn_ok = ivug_button_add(navi_bar, "naviframe/toolbar/default",
827                                                                 IDS_SAVE, NULL, _on_btn_ok_clicked, (void *)pSetAsData->layout);
828
829         Elm_Object_Item *navi_it = elm_naviframe_top_item_get(navi_bar);
830         elm_object_item_part_content_set(navi_it, "toolbar_button1", pSetAsData->btn_ok);
831
832         elm_object_disabled_set(pSetAsData->btn_ok, EINA_TRUE);
833 }
834