Crop fit to mode implementation and fixed Jira issue
[apps/osp/ImageViewer.git] / src / IvImageCropForm.cpp
1 //
2 // Copyright (c) 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://floralicense.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
17 /**
18  * @file                IvImageCrop.cpp
19  * @brief               This is the implementation file for Image Crop.
20  */
21
22 #include <FApp.h>
23 #include <FMedia.h>
24 #include <FSystem.h>
25 #include <FSocial.h>
26 #include "IvImageCropForm.h"
27 #include "IvImageViewerPresentationModel.h"
28 #include "IvResourceManager.h"
29 #include "IvTypes.h"
30
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Content;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Io;
37 using namespace Tizen::Media;
38 using namespace Tizen::System;
39 using namespace Tizen::Social;
40 using namespace Tizen::Ui::Controls;
41 using namespace Tizen::Ui::Scenes;
42
43 static const unsigned int CROP_BOX_RECTANGLE_COLOR = Color32<199, 110, 6>::Value;
44 static const int CROP_BOX_LINE_WIDTH = 5;
45
46 ImageCropForm::ImageCropForm(void)
47         : __imageHeight(0)
48         , __imageWidth(0)
49         , __isOrientationChanged(false)
50         , __pCanvas(null)
51         , __pCurrentBitmap(null)
52         , __pRectangleBitmap(null)
53         , __pointLocation(OUTSIDE_CROPBOX)
54         , __pPresentationModel(null)
55 {
56 }
57
58 ImageCropForm::~ImageCropForm(void)
59 {
60         if (__pCurrentBitmap != null)
61         {
62                 delete __pCurrentBitmap;
63         }
64         if (__pRectangleBitmap != null)
65         {
66                 delete __pRectangleBitmap;
67         }
68         if (__pCanvas != null)
69         {
70                 delete __pCanvas;
71         }
72 }
73
74 bool
75 ImageCropForm::Initialize(void)
76 {
77         Form::Construct(IDL_FORM_IMAGE_CROP);
78         Form::SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR);
79
80         __pPresentationModel = ImageViewerPresentationModel::GetInstance();
81
82         return true;
83 }
84
85 result
86 ImageCropForm::OnInitializing(void)
87 {
88         result r = E_SUCCESS;
89
90         AppResource* pAppResource = null;
91         Bitmap* pSaveButtonBitmap = null;
92         Bitmap* pCancelButtonBitmap  = null;
93         Bitmap* pCWRotationButtonBitmap  = null;
94         Bitmap* pCCWRotationButtonBitmap  = null;
95         Panel* pPanel = null;
96         Button* pSaveButton = null;
97         Button* pCancelButton = null;
98         pAppResource = UiApp::App::GetInstance()->GetAppResource();
99         if (pAppResource != null)
100         {
101                 pSaveButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_SAVE_ICON);
102                 pCancelButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_CANCEL_ICON);
103                 pCWRotationButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_CW_ROTATION_ICON);
104                 pCCWRotationButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_CCW_ROTATION_ICON);
105                 __pRectangleBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_RECTANGLE);
106         }
107
108         pPanel = static_cast<Panel*>(GetControl(L"IDC_FOOTER_PANEL"));
109         if (pPanel != null)
110         {
111                 pSaveButton = static_cast<Button*>(pPanel->GetControl(L"IDC_SAVE_BUTTON"));
112                 if (pSaveButton != null && pSaveButtonBitmap != null)
113                 {
114                         Point startPoint((pSaveButton->GetWidth() - pSaveButtonBitmap->GetWidth()) / 2,
115                                         (pSaveButton->GetHeight() - pSaveButtonBitmap->GetHeight()) / 2);
116                         pSaveButton->SetNormalBitmap(startPoint, *pSaveButtonBitmap);
117                         pSaveButton->AddActionEventListener(*this);
118                         pSaveButton->SetActionId(IDA_BUTTON_SAVE);
119                         delete pSaveButtonBitmap;
120                 }
121
122                 pCancelButton = static_cast<Button*>(pPanel->GetControl(L"IDC_CANCEL_BUTTON"));
123                 if (pCancelButton != null && pCancelButtonBitmap != null)
124                 {
125                         Point startPoint((pCancelButton->GetWidth() - pCancelButtonBitmap->GetWidth()) / 2,
126                                         (pCancelButton->GetHeight() - pCancelButtonBitmap->GetHeight()) / 2);
127                         pCancelButton->SetNormalBitmap(startPoint, *pCancelButtonBitmap);
128                         pCancelButton->AddActionEventListener(*this);
129                         pCancelButton->SetActionId(IDA_BUTTON_CANCEL);
130                         delete pCancelButtonBitmap;
131                 }
132                 SetControlAlwaysOnTop(*pPanel, true);
133                 Label* pLabel = static_cast<Label*>(pPanel->GetControl(L"IDC_PANEL_LABEL"));
134                 if (pLabel != null)
135                 {
136                         SetControlAlwaysAtBottom(*pLabel, true);
137                 }
138         }
139         AddTouchEventListener(*this);
140         AddOrientationEventListener(*this);
141         __pPresentationModel->AddFileUpdateListener(this);
142
143         delete pCWRotationButtonBitmap;
144         delete pCCWRotationButtonBitmap;
145         return r;
146 }
147
148 void
149 ImageCropForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
150 {
151         AppLogDebug("ENTER pArgs(%x)", pArgs);
152         if (pArgs != null)
153         {
154                 IEnumerator* pEnum = pArgs->GetEnumeratorN();
155                 if (pEnum->MoveNext() != E_SUCCESS)
156                 {
157                         delete pEnum;
158                         delete pArgs;
159                         AppLogDebug("EXIT 1(%s)", GetErrorMessage(GetLastResult()));
160
161                         return;
162                 }
163                 __sourceFilePath = *(static_cast<String*>(pEnum->GetCurrent()));
164                 if (__sourceFilePath.IsEmpty() == false)
165                 {
166                         result r = __imageBuffer.Construct(__sourceFilePath.GetPointer());
167                         if (r == E_SUCCESS)
168                         {
169                                 __imageWidth = __imageBuffer.GetWidth();
170                                 __imageHeight = __imageBuffer.GetHeight();
171                                 __pCurrentBitmap = __imageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_AUTO);
172                         }
173                         Image img;
174                         __imageFormat = img.GetImageFormat(__sourceFilePath);
175                 }
176                 if (pEnum->MoveNext() != E_SUCCESS)
177                 {
178                         delete pEnum;
179                         delete pArgs;
180                         AppLogDebug("EXIT 2(%s)", GetErrorMessage(GetLastResult()));
181
182                         return;
183                 }
184                 __cropMode = *(static_cast<String*>(pEnum->GetCurrent()));
185                 if (__cropMode.IsEmpty() == false)
186                 {
187                         __cropMode.ToLowerCase();
188                         if (__cropMode == "auto")
189                         {
190                                 delete pEnum;
191                                 delete pArgs;
192                                 SetValue();
193                                 return;
194                         }
195                         else if (__cropMode == "fit-to-screen")
196                         {
197                                 if (pEnum->MoveNext() != E_SUCCESS)
198                                 {
199                                         delete pEnum;
200                                         delete pArgs;
201                                         AppLogDebug("EXIT 3(%s)", GetErrorMessage(GetLastResult()));
202
203                                         return;
204                                 }
205                                 Integer *pStatus = static_cast<Integer*>(pEnum->GetCurrent());
206                                 if (pStatus != null)
207                                 {
208                                         __statusValue = pStatus->ToInt();
209                                 }
210                                 if (__statusValue == SET_AT_TYPE_CALLER_IMAGE)
211                                 {
212                                         if (pEnum->MoveNext() != E_SUCCESS)
213                                         {
214                                                 delete pEnum;
215                                                 delete pArgs;
216                                                 AppLogDebug("EXIT 4(%s)", GetErrorMessage(GetLastResult()));
217
218                                                 return;
219                                         }
220
221                                         LongLong* pContentId = static_cast<LongLong*>(pEnum->GetCurrent());
222                                         if (pContentId != null)
223                                         {
224                                                 __contentId = pContentId->ToLongLong();
225                                         }
226                                 }
227
228                                 delete pEnum;
229                                 delete pArgs;
230                                 SetValue();
231                         }
232                 }
233         }
234 //      if (pArgs != null)
235 //      {
236 //              __sourceFilePath = *(static_cast<String*>(pArgs->GetAt(0)));
237 //              __cropMode = *(static_cast<String*>(pArgs->GetAt(1)));
238 //              delete pArgs;
239 //      }
240 //      else
241 //      {
242 //              __sourceFilePath = __pPresentationModel->GetFilePathAt(0);
243 //      }
244 /*      if (__sourceFilePath.IsEmpty() == false && __cropMode.IsEmpty() == false)
245         {
246                 __cropMode.ToLowerCase();
247                 result r = __imageBuffer.Construct(__sourceFilePath.GetPointer());
248                 if (r == E_SUCCESS)
249                 {
250                         __imageWidth = __imageBuffer.GetWidth();
251                         __imageHeight = __imageBuffer.GetHeight();
252                         __pCurrentBitmap = __imageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_AUTO);
253                 }
254                 Image img;
255                 __imageFormat = img.GetImageFormat(__sourceFilePath);
256         }*/
257         SetValue();
258         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
259 }
260
261 void
262 ImageCropForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
263 {
264         AppLogDebug("ENTER");
265         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
266 }
267
268 result
269 ImageCropForm::OnDraw(void)
270 {
271         result r = E_SUCCESS;
272         AppLogDebug("ENTER");
273         if (__pCanvas != null)
274         {
275                 r = __pCanvas->SetLineWidth(CROP_BOX_LINE_WIDTH);
276                 r = __pCanvas->DrawBitmap(Rectangle(__imageBox.x, __imageBox.y, __imageBox.width, __imageBox.height), *__pCurrentBitmap);
277                 r = __pCanvas->DrawRectangle(Rectangle(__cropBox.x, __cropBox.y, __cropBox.width, __cropBox.height));
278                 r = __pCanvas->DrawBitmap(Rectangle((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2), __cropBox.y - (CROP_RECTANGLE_HEIGHT / 2), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); // Top Rectangle
279                 r = __pCanvas->DrawBitmap(Rectangle((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2), (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); // Bottom Rectangle
280                 r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2), (__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); //Left Rectangle
281                 r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2), (__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); //Right Rectangle
282                 r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2), __cropBox.y - (CROP_RECTANGLE_HEIGHT / 2), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); // Top Left Rectangle
283                 r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2), __cropBox.y - (CROP_RECTANGLE_HEIGHT / 2), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); // Top Right Rectangle
284                 r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2), (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); // Bottom Right Rectangle
285                 r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2), (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)), CROP_RECTANGLE_HEIGHT, CROP_RECTANGLE_HEIGHT), *__pRectangleBitmap); // Bottom Left Rectangle
286         }
287         AppLogDebug("EXIT");
288         return r;
289 }
290
291 void
292 ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
293 {
294         SceneManager* pSceneManager = SceneManager::GetInstance();
295         switch(actionId)
296         {
297         case IDA_BUTTON_CANCEL:
298                 pSceneManager->GoBackward(BackwardSceneTransition());
299                 break;
300         case IDA_BUTTON_SAVE:
301         {
302                 if (__cropMode == "auto")
303                 {
304                         ImageBuffer* pCropBuffer = null;
305                         int count = 1;
306                         int index = 0;
307                         String destFilePath;
308                         String stringToInsert = L"_";
309                         String delimiter = L".";
310                         if (__sourceFilePath.IsEmpty() == false)
311                         {
312                                 __sourceFilePath.Reverse();
313                                 __sourceFilePath.IndexOf(delimiter, 0, index);
314                                 __sourceFilePath.Reverse();
315                                 __sourceFilePath.Insert(stringToInsert, __sourceFilePath.GetLength() - index - 1);
316                                 destFilePath.Append(__sourceFilePath);
317                                 destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
318                                 while (File::IsFileExist(destFilePath) == true)
319                                 {
320                                         count++;
321                                         destFilePath.Clear();
322                                         destFilePath.Append(__sourceFilePath);
323                                         destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
324                                 }
325                                 pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
326                                                 (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height);
327                                 pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
328                                 ContentManager::ScanFile(destFilePath);
329                                 delete pCropBuffer;
330                         }
331                         ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
332                         pList->Add(new (std::nothrow) String(destFilePath));
333                         pSceneManager->GoBackward(BackwardSceneTransition(), pList);
334                 }
335                 else if(__cropMode == "fit-to-screen")
336                 {
337                         ImageBuffer* pCropBuffer = null;
338                         result r = E_SUCCESS;
339                         pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
340                                         (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height);
341                         if (__statusValue == SET_AT_TYPE_HOME_SCREEN_WALLPAPER)
342                         {
343                                 String destPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_HOME_SCREEN_WALLPAPER;
344                                 r = pCropBuffer->EncodeToFile(destPath, __imageFormat, true, 100);
345                                 if (r == E_SUCCESS)
346                                 {
347                                         r = SettingInfo::SetValue(SETTING_VALUE_HOME_SCREEN_WALLPAPER, destPath);
348                                 }
349                                 else if (r == E_OVERFLOW)
350                                 {
351                                         MessageBox messageBox;
352                                         messageBox.Construct(L"", L"File size is too big", MSGBOX_STYLE_NONE, 3000);
353                                         int modalResult = 0;
354                                         messageBox.ShowAndWait(modalResult);
355                                 }
356                         }
357                         else if (__statusValue == SET_AT_TYPE_LOCK_SCREEN_WALLPAPER)
358                         {
359                                 String destPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_LOCK_SCREEN_WALLPAPER;
360                                 r = pCropBuffer->EncodeToFile(destPath, __imageFormat, true, 100);
361                                 if (r == E_SUCCESS)
362                                 {
363                                         r = SettingInfo::SetValue(SETTING_VALUE_LOCK_SCREEN_WALLPAPER, destPath);
364                                 }
365                                 else if (r == E_OVERFLOW)
366                                 {
367                                         MessageBox messageBox;
368                                         messageBox.Construct(L"", L"File size is too big", MSGBOX_STYLE_NONE, 3000);
369                                         int modalResult = 0;
370                                         messageBox.ShowAndWait(modalResult);
371                                 }
372                         }
373                         else if (__statusValue == SET_AT_TYPE_HOME_AND_LOCK_SCREEN_WALLPAPER)
374                         {
375                                 String destPath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_LOCK_SCREEN_WALLPAPER;
376                                 String destPathHome = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_HOME_SCREEN_WALLPAPER;
377                                 r = pCropBuffer->EncodeToFile(destPath, __imageFormat, true, 100);
378                                 r = pCropBuffer->EncodeToFile(destPathHome, __imageFormat, true, 100);
379                                 if (r == E_SUCCESS)
380                                 {
381                                         r = SettingInfo::SetValue(SETTING_VALUE_LOCK_SCREEN_WALLPAPER, destPath);
382                                         r = SettingInfo::SetValue(SETTING_VALUE_HOME_SCREEN_WALLPAPER, destPathHome);
383                                 }
384                                 else if (r == E_OVERFLOW)
385                                 {
386                                         MessageBox messageBox;
387                                         messageBox.Construct(L"", L"File size is too big", MSGBOX_STYLE_NONE, 3000);
388                                         int modalResult = 0;
389                                         messageBox.ShowAndWait(modalResult);
390                                 }
391                         }
392                         else if (__statusValue == SET_AT_TYPE_CALLER_IMAGE)
393                         {
394                                 int count = 1;
395                                 int index = 0;
396                                 String destFilePath;
397                                 String stringToInsert = L"_";
398                                 String delimiter = L".";
399                                 if (__sourceFilePath.IsEmpty() == false)
400                                 {
401                                         __sourceFilePath.Reverse();
402                                         __sourceFilePath.IndexOf(delimiter, 0, index);
403                                         __sourceFilePath.Reverse();
404                                         __sourceFilePath.Insert(stringToInsert, __sourceFilePath.GetLength() - index - 1);
405                                         destFilePath.Append(__sourceFilePath);
406                                         destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
407                                         while (File::IsFileExist(destFilePath) == true)
408                                         {
409                                                 count++;
410                                                 destFilePath.Clear();
411                                                 destFilePath.Append(__sourceFilePath);
412                                                 destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
413                                         }
414                                 }
415                                 r = pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
416                                 ContentManager::ScanFile(destFilePath);
417                                 Contact* pContact = null;
418                                 AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
419                                 Addressbook* pAddressbook = null;
420
421                                 pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
422                                 pContact = pAddressbook->GetContactN(__contentId);
423                                 pContact->SetThumbnail(destFilePath);
424                                 pAddressbook->UpdateContact(*pContact);
425
426                                 delete pContact;
427                                 delete pAddressbook;
428                         }
429                         delete pCropBuffer;
430                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_IMAGE_VIEWER));
431                 }
432         }
433         break;
434         }
435         AppLog("Exit");
436 }
437
438 void
439 ImageCropForm::OnOrientationChanged(const Control &source, OrientationStatus orientationStatus)
440 {
441         AppLogDebug("ENTER");
442         __isOrientationChanged = true;
443         SetValue();
444         __pCanvas->Clear();
445         AppLogDebug("EXIT");
446 }
447
448 void
449 ImageCropForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
450 {
451         AppLogDebug("ENTER");
452         __touchStart = currentPosition;
453         CheckCurrentPosition(currentPosition);
454         AppLogDebug("EXIT");
455 }
456
457 void
458 ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
459 {
460         AppLogDebug("ENTER");
461         int deltaX = currentPosition.x - __touchStart.x;
462         int deltaY = currentPosition.y - __touchStart.y;
463         if (__cropMode.Equals("auto", false))
464         {
465                 switch(__pointLocation)
466                 {
467                 case INSIDE_TOP_RECTANGLE:
468                 {
469                         if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3)))
470                         {
471                                 __cropBox.y += deltaY;
472                                 __cropBox.height -= deltaY;
473                         }
474                 }
475                 break;
476
477                 case INSIDE_BOTTOM_RECTANGLE:
478                 {
479                         if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height)
480                                 && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3))
481                         {
482                                 __cropBox.height += deltaY;
483                         }
484                 }
485                 break;
486
487                 case INSIDE_LEFT_RECTANGLE:
488                 {
489                         if ((__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
490                         {
491                                 __cropBox.x += deltaX;
492                                 __cropBox.width -= deltaX;
493                         }
494                 }
495                 break;
496
497                 case INSIDE_RIGHT_RECTANGLE:
498                 {
499                         if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width)
500                                 && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3))
501                         {
502                                 __cropBox.width += deltaX;
503                         }
504                 }
505                 break;
506
507                 case INSIDE_TOP_LEFT_RECTANGLE:
508                 {
509                         if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3))
510                                         && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
511                         {
512                                 __cropBox.y += deltaY;
513                                 __cropBox.height -= deltaY;
514                                 __cropBox.x += deltaX;
515                                 __cropBox.width -= deltaX;
516                         }
517                 }
518                 break;
519
520                 case INSIDE_TOP_RIGHT_RECTANGLE:
521                 {
522                         if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3))
523                                         && (__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3))
524                         {
525                                 __cropBox.width += deltaX;
526                                 __cropBox.y += deltaY;
527                                 __cropBox.height -= deltaY;
528                         }
529                 }
530                 break;
531
532                 case INSIDE_BOTTOM_LEFT_RECTANGLE:
533                 {
534                         if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3)
535                                 && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
536                         {
537                                 __cropBox.x += deltaX;
538                                 __cropBox.width -= deltaX;
539                                 __cropBox.height += deltaY;
540                         }
541                 }
542                 break;
543
544                 case INSIDE_BOTTOM_RIGHT_RECTANGLE:
545                 {
546                         if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3)
547                                 && (__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3))
548                         {
549                                 __cropBox.width += deltaX;
550                                 __cropBox.height += deltaY;
551                         }
552                 }
553                 break;
554
555                 case INSIDE_CROPBOX:
556                 {
557                         if ((__cropBox.x + deltaX) > __imageBox.x)
558                         {
559                                 __cropBox.x += deltaX;
560                         }
561                         else
562                         {
563                                 __cropBox.x = __imageBox.x;
564                         }
565                         if ((__cropBox.y + deltaY) > __imageBox.y)
566                         {
567                                 __cropBox.y += deltaY;
568                         }
569                         else
570                         {
571                                 __cropBox.y = __imageBox.y;
572                         }
573                         if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
574                         {
575                                 __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
576                         }
577                         if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
578                         {
579                                 __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
580                         }
581                 }
582                 break;
583
584                 default:
585                         break;
586                 }
587         }
588         else if (__cropMode != "auto")
589         {
590                 if (__pointLocation == INSIDE_LEFT_RECTANGLE || __pointLocation == INSIDE_BOTTOM_LEFT_RECTANGLE
591                         || __pointLocation == INSIDE_TOP_LEFT_RECTANGLE)
592                 {
593                         int temp = __cropBox.height;
594                         int height = (__formHeight * (__cropBox.width - (2 * deltaX))) /__formWidth;
595                         temp = height - temp;
596                         if ((__cropBox.width - (2 * deltaX) > (CROP_RECTANGLE_HEIGHT * 3)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width)))
597                         {
598                                 if (__cropBox.x + deltaX >= __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
599                                         && __cropBox.y - (temp / 2) >= __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height
600                                         && (__cropBox.width - (2 * deltaX) > (CROP_RECTANGLE_HEIGHT * 3)))
601                                 {
602                                         __cropBox.x += deltaX;
603                                         __cropBox.width = __cropBox.width - (2 * deltaX);
604                                         __cropBox.height = height;
605                                         __cropBox.y = __cropBox.y - (temp / 2);
606                                 }
607                                 else if ((__cropBox.y + __cropBox.height) <= (__imageBox.y + __imageBox.height)
608                                                 && __cropBox.width < __imageBox.width
609                                                 && __cropBox.x + deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
610                                 {
611                                         if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
612                                                 && __cropBox.x + deltaX >= __imageBox.x)
613                                         {
614                                                 __cropBox.x += deltaX;
615                                         }
616                                         else
617                                         {
618                                                 __cropBox.x = __cropBox.x + (2 * deltaX);
619                                         }
620                                         __cropBox.width = __cropBox.width - (2 * deltaX);
621                                         __cropBox.height = height;
622                                         __cropBox.y = __cropBox.y - temp;
623                                 }
624                                 else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.width - (deltaX) <= __imageBox.width
625                                                 && __cropBox.x + deltaX >= __imageBox.x && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
626                                 {
627                                         if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width)
628                                         {
629                                                 __cropBox.x += deltaX;
630                                         }
631                                         else
632                                         {
633                                                 __cropBox.x = __cropBox.x + (2 * deltaX);
634                                         }
635                                         __cropBox.width = __cropBox.width - (2 * deltaX);
636                                         __cropBox.height = height;
637                                 }
638                         }
639                 }
640                 else if (__pointLocation == INSIDE_RIGHT_RECTANGLE || __pointLocation == INSIDE_BOTTOM_RIGHT_RECTANGLE
641                                 || __pointLocation == INSIDE_TOP_RIGHT_RECTANGLE)
642                 {
643                         deltaX *= -1;
644
645                         int temp = __cropBox.height;
646                         int height = (__formHeight * (__cropBox.width - (2 * deltaX))) / __formWidth;
647                         temp = height - temp;
648                         if ((__cropBox.width - (2 * deltaX) > (CROP_RECTANGLE_HEIGHT * 3)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width)))
649                         {
650                                 if (deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
651                                 {
652                                         if (__cropBox.x + deltaX > __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
653                                                 && __cropBox.y - (temp / 2) > __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height)
654                                         {
655                                                 __cropBox.x += deltaX;
656                                                 __cropBox.width = __cropBox.width - (2 * deltaX);;
657                                                 __cropBox.height = height;
658                                                 __cropBox.y = __cropBox.y - (temp / 2);
659                                         }
660                                         else if ((__cropBox.y + __cropBox.height + (temp / 2)) >= (__imageBox.y + __imageBox.height)
661                                                         && __cropBox.x + __cropBox.width - (2 * deltaX) <= __imageBox.x + __imageBox.width
662                                                         && __cropBox.x - deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
663                                         {
664                                                 if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
665                                                         && __cropBox.x + deltaX >= __imageBox.x)
666                                                 {
667                                                         __cropBox.x += deltaX;
668                                                 }
669                                                 else
670                                                 {
671                                                         __cropBox.width = __cropBox.width - (2 * deltaX);
672                                                 }
673                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
674                                                 __cropBox.height = height;
675                                                 __cropBox.y = __cropBox.y - temp;
676                                         }
677                                         else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.width - (deltaX) <= __imageBox.width
678                                                         && __cropBox.x + deltaX <= __imageBox.x && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
679                                         {
680                                                 if (__cropBox.x + deltaX >= __imageBox.x)
681                                                 {
682                                                         __cropBox.x += deltaX;
683                                                 }
684                                                 else
685                                                 {
686                                                         __cropBox.x = __imageBox.x;
687                                                 }
688                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
689                                                 __cropBox.height = height;
690                                         }
691                                         else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.x + deltaX >= __imageBox.x
692                                                         && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
693                                                         && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
694                                         {
695                                                 __cropBox.x += deltaX;
696                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
697                                                 __cropBox.height = height;
698                                         }
699                                         else if (__cropBox.x + deltaX <= __imageBox.x && __cropBox.y - (temp / 2) >= __imageBox.y
700                                                         && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
701                                                         && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
702                                         {
703                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
704                                                 __cropBox.y = __cropBox.y - (temp / 2);
705                                                 __cropBox.height = height;
706                                         }
707                                 }
708                         }
709                 }
710                 else if (__pointLocation == INSIDE_TOP_RECTANGLE)
711                 {
712                         int temp = __cropBox.width;
713                         int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight;
714                         temp = width - temp;
715                         if (__cropBox.height - (2 * deltaY) > (__formHeight * (CROP_RECTANGLE_HEIGHT * 3)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width)))
716                         {
717                                 if (__cropBox.x - (temp /2 ) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
718                                         && __cropBox.y + (deltaY) > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
719                                 {
720                                         __cropBox.y += deltaY;
721                                         __cropBox.height = __cropBox.height - (2 * deltaY);
722                                         __cropBox.width = width;
723                                         __cropBox.x = __cropBox.x - (temp / 2);
724                                 }
725                                 else if (__cropBox.x - (temp / 2) < __imageBox.x)
726                                 {
727                                         if (__cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width)
728                                         {
729                                                 __cropBox.width = width;
730                                         }
731                                         if (__cropBox.y + deltaY >= __imageBox.y)
732                                         {
733                                                 __cropBox.y += deltaY;
734                                         }
735                                         if (__cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
736                                         {
737                                                 __cropBox.height = __cropBox.height - (2 * deltaY);
738                                         }
739                                 }
740                                 else if (__cropBox.y + __cropBox.height - (2 * deltaY) >= __imageBox.x + __imageBox.height
741                                                 && __cropBox.y + (2 * deltaY) >= __imageBox.y)
742                                 {
743                                         if (__cropBox.x - temp >= __imageBox.x
744                                                 && __cropBox.x + __cropBox.width + temp > __imageBox.x + __imageBox.width)
745                                         {
746                                                 __cropBox.x = __cropBox.x - temp;
747                                         }
748                                         else if (__cropBox.x - temp >= __imageBox.x)
749                                         {
750                                                 __cropBox.x = __cropBox.x - temp / 2;
751                                         }
752                                         if (__cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width)
753                                         {
754                                                 __cropBox.width = width;
755                                         }
756                                         if (__cropBox.y + (2 * deltaY) >= __imageBox.y)
757                                         {
758                                                 __cropBox.y = __cropBox.y + (2 * deltaY);
759                                                 __cropBox.height = __cropBox.height - (2 * deltaY);
760                                         }
761                                 }
762                                 else if (__cropBox.x + __cropBox.width + (temp / 2) > __imageBox.x + __imageBox.width
763                                                 && __cropBox.x - temp >= __imageBox.x && __cropBox.y + deltaY >= __imageBox.y
764                                                 && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
765                                 {
766                                         __cropBox.x = __cropBox.x - temp;
767                                         __cropBox.width = width;
768                                         __cropBox.y += deltaY;
769                                         __cropBox.height = __cropBox.height - (2 * deltaY);
770                                 }
771                         }
772                 }
773                 else if (__pointLocation == INSIDE_BOTTOM_RECTANGLE)
774                 {
775                         deltaY = deltaY * (-1);
776                         int temp = __cropBox.width;
777                         int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight;
778                         temp = width - temp;
779                         if (__cropBox.height - (2 * deltaY) > (__formHeight * (CROP_RECTANGLE_HEIGHT * 3)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width)))
780                         {
781                                 if (__cropBox.x - (temp / 2) >= __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
782                                         && __cropBox.y + deltaY > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
783                                 {
784                                         __cropBox.y += deltaY;
785                                         __cropBox.height = __cropBox.height - (2 * deltaY);;
786                                         __cropBox.width = width;
787                                         __cropBox.x = __cropBox.x - (temp / 2);
788                                 }
789                                 else if (__cropBox.y + deltaY < __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height
790                                                 && __cropBox.x - (temp / 2) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width)
791                                 {
792                                         __cropBox.x = __cropBox.x - (temp / 2);
793                                         __cropBox.width = width;
794                                         __cropBox.height = __cropBox.height - (2 * deltaY);
795                                 }
796                                 else if (__cropBox.x + __cropBox.width + temp > __imageBox.x + __imageBox.width
797                                                 && __cropBox.y + deltaY >= __imageBox.y && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height
798                                                 && __cropBox.x - temp >= __imageBox.x)
799                                 {
800                                         __cropBox.x = __cropBox.x - temp;
801                                         __cropBox.y += deltaY;
802                                         __cropBox.width = width;
803                                         __cropBox.height = __cropBox.height - (2 * deltaY);
804                                 }
805                                 else if (__cropBox.x + __cropBox.width + temp >= __imageBox.x + __imageBox.width
806                                                 && __cropBox.y + deltaY <= __imageBox.y && __cropBox.x - temp > __imageBox.x
807                                                 && __cropBox.y + __cropBox.height + temp < __imageBox.y + __imageBox.height)
808                                 {
809                                         __cropBox.x -= temp;
810                                         __cropBox.width = width;
811                                         __cropBox.height = __cropBox.height - (2 * deltaY);
812                                 }
813                                 else if (__cropBox.x - temp < __imageBox.x && __cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width
814                                                 && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
815                                 {
816                                         if (__cropBox.y + deltaY >= __imageBox.y)
817                                         {
818                                                 __cropBox.y += deltaY;
819                                         }
820                                         __cropBox.width = width;
821                                         __cropBox.height = __cropBox.height - (2 * deltaY);
822                                 }
823                         }
824                 }
825                 else if (__pointLocation == INSIDE_CROPBOX)
826                 {
827                         if ((__cropBox.x + deltaX) > __imageBox.x)
828                         {
829                                 __cropBox.x += deltaX;
830                         }
831                         else
832                         {
833                                 __cropBox.x = __imageBox.x;
834                         }
835                         if ((__cropBox.y + deltaY) > __imageBox.y)
836                         {
837                                 __cropBox.y += deltaY;
838                         }
839                         else
840                         {
841                                 __cropBox.y = __imageBox.y;
842                         }
843                         if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
844                         {
845                                 __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
846                         }
847                         if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
848                         {
849                                 __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
850                         }
851                 }
852         }
853         RequestRedraw(false);
854         __touchStart = currentPosition;
855         AppLogDebug("EXIT");
856 }
857
858 void
859 ImageCropForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
860 {
861         AppLogDebug("ENTER");
862         __pointLocation = OUTSIDE_CROPBOX;
863         AppLogDebug("EXIT");
864 }
865
866 void
867 ImageCropForm::CheckCurrentPosition(const Point currentPosition)
868 {
869         AppLogDebug("ENTER");
870         if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (CROP_RECTANGLE_HEIGHT / 2))
871                 && currentPosition.y >  (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + (CROP_RECTANGLE_HEIGHT / 2)))
872         {
873                 __pointLocation = INSIDE_TOP_RECTANGLE;
874         }
875         else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
876                 && currentPosition.y >  ((__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (CROP_RECTANGLE_HEIGHT / 2)))
877         {
878                 __pointLocation = INSIDE_LEFT_RECTANGLE;
879         }
880         else if (currentPosition.x > (__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
881                 && currentPosition.y > ((__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (CROP_RECTANGLE_HEIGHT / 2)))
882         {
883                 __pointLocation = INSIDE_RIGHT_RECTANGLE;
884         }
885         else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (CROP_RECTANGLE_HEIGHT / 2))
886                 && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
887         {
888                 __pointLocation = INSIDE_BOTTOM_RECTANGLE;
889         }
890         else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
891                          && currentPosition.y > (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y +(CROP_RECTANGLE_HEIGHT / 2)))
892         {
893                 __pointLocation = INSIDE_TOP_LEFT_RECTANGLE;
894         }
895         else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
896                         && currentPosition.y > (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y +(CROP_RECTANGLE_HEIGHT / 2)))
897         {
898                 __pointLocation = INSIDE_TOP_RIGHT_RECTANGLE;
899         }
900         else if (currentPosition.x > (__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
901                         && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
902         {
903                 __pointLocation = INSIDE_BOTTOM_RIGHT_RECTANGLE;
904         }
905         else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
906                         && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
907         {
908                 __pointLocation = INSIDE_BOTTOM_LEFT_RECTANGLE;
909         }
910         else if (currentPosition.x > __cropBox.x && currentPosition.x < (__cropBox.x + __cropBox.width) && currentPosition.y > __cropBox.y && currentPosition.y < (__cropBox.y + __cropBox.height))
911         {
912                 __pointLocation = INSIDE_CROPBOX;
913         }
914         else
915         {
916                 __pointLocation = OUTSIDE_CROPBOX;
917         }
918         AppLogDebug("EXIT");
919         return;
920 }
921
922 void
923 ImageCropForm::SetValue(void)
924 {
925         int prevHeight = __imageBox.height;
926         int prevWidth = __imageBox.width;
927         int prevImageboxX = __imageBox.x;
928         int prevImageBoxY = __imageBox.y;
929         if (GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT)
930         {
931                 __formHeight = Form::GetBounds().height;
932                 __formWidth = Form::GetBounds().width;
933         }
934         else if(GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
935         {
936                 __formHeight = Form::GetBounds().width;
937                 __formWidth = Form::GetBounds().height;
938         }
939
940         float clientAreaRatio = (GetClientAreaBoundsF().height - FOOTER_PANEL_HEIGHT) / GetClientAreaBoundsF().width;
941         if (__imageWidth >= GetClientAreaBounds().width || __imageHeight > (GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT))
942         {
943                 float imageRatio = __imageHeight / (float) __imageWidth;
944                 if (imageRatio < clientAreaRatio)
945                 {
946                         __imageBox.width = GetClientAreaBounds().width;
947                         __imageBox.height = (__imageHeight * __imageBox.width) / __imageWidth;
948                         __imageBox.x = GetClientAreaBounds().x;
949                         __imageBox.y = GetClientAreaBounds().y + ((GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT) - __imageBox.height) / 2;
950                 }
951                 else
952                 {
953                         __imageBox.height = GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT;
954                         __imageBox.width = (__imageWidth * __imageBox.height) / __imageHeight;
955                         __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
956                         __imageBox.y = GetClientAreaBounds().y;
957                 }
958         }
959         else
960         {
961                 __imageBox.height = __imageHeight;
962                 __imageBox.width = __imageWidth;
963                 __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
964                 __imageBox.y = (GetClientAreaBounds().height - __imageBox.height) / 2 ;
965         }
966         if (__isOrientationChanged == false)
967         {
968                 if (__imageBox.height > __imageBox.width)
969                 {
970                         __cropBox.width = (2 * __imageBox.width) / 3;
971                         __cropBox.height = (__formHeight * __cropBox.width / __formWidth);
972                         __cropBox.y =  __imageBox.y + (__imageBox.height - __cropBox.height) / 2;
973                         __cropBox.x = __imageBox.x + (__imageBox.width - __cropBox.width) / 2;
974                 }
975                 else
976                 {
977                         __cropBox.height = (2 *__imageBox.height) / 3;
978                         __cropBox.width = (__formWidth * __cropBox.height / __formHeight);
979                         __cropBox.y = __imageBox.y + (__imageBox.height - __cropBox.height) / 2;
980                         __cropBox.x = __imageBox.x + (__imageBox.width - __cropBox.width) / 2;
981                 }
982         }
983         else
984         {
985                 float temp = __imageBox.x + ((__cropBox.x - prevImageboxX) * __imageBox.width) / (float)prevWidth;
986                 __cropBox.x = (temp + 0.5);
987                 temp = __imageBox.y + ((__cropBox.y - prevImageBoxY) * __imageBox.height) / (float)prevHeight;
988                 __cropBox.y = (temp + 0.5);
989                 temp = (__cropBox.height * __imageBox.height) / (float)prevHeight;
990                 __cropBox.height = (temp + 0.5);
991                 temp = (__cropBox.width * __imageBox.width) / (float)prevWidth;
992                 __cropBox.width = (temp + 0.5);
993         }
994         __pCanvas = GetCanvasN();
995         __pCanvas->SetForegroundColor(CROP_BOX_RECTANGLE_COLOR);
996 }
997
998 void ImageCropForm::OnFormFileEventOccuered(const int index, const unsigned long eventId)
999 {
1000         AppLogDebug(" ENTER");
1001         UiApp::GetInstance()->Terminate();
1002         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1003 }