Set as caller image implementation by crop mode fit-to-screen
[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                                 delete pCropBuffer;
429                                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
430                                 pList->Add(new (std::nothrow) String(destFilePath));
431                                 pSceneManager->GoBackward(BackwardSceneTransition(), pList);
432                                 AppLog("Exit");
433                                 return;
434                         }
435                         delete pCropBuffer;
436                         pSceneManager->GoBackward(BackwardSceneTransition());
437                 }
438         }
439         break;
440         }
441         AppLog("Exit");
442 }
443
444 void
445 ImageCropForm::OnOrientationChanged(const Control &source, OrientationStatus orientationStatus)
446 {
447         AppLogDebug("ENTER");
448         __isOrientationChanged = true;
449         SetValue();
450         __pCanvas->Clear();
451         AppLogDebug("EXIT");
452 }
453
454 void
455 ImageCropForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
456 {
457         AppLogDebug("ENTER");
458         __touchStart = currentPosition;
459         CheckCurrentPosition(currentPosition);
460         AppLogDebug("EXIT");
461 }
462
463 void
464 ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
465 {
466         AppLogDebug("ENTER");
467         int deltaX = currentPosition.x - __touchStart.x;
468         int deltaY = currentPosition.y - __touchStart.y;
469         if (__cropMode.Equals("auto", false))
470         {
471                 switch(__pointLocation)
472                 {
473                 case INSIDE_TOP_RECTANGLE:
474                 {
475                         if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3)))
476                         {
477                                 __cropBox.y += deltaY;
478                                 __cropBox.height -= deltaY;
479                         }
480                 }
481                 break;
482
483                 case INSIDE_BOTTOM_RECTANGLE:
484                 {
485                         if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height)
486                                 && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3))
487                         {
488                                 __cropBox.height += deltaY;
489                         }
490                 }
491                 break;
492
493                 case INSIDE_LEFT_RECTANGLE:
494                 {
495                         if ((__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
496                         {
497                                 __cropBox.x += deltaX;
498                                 __cropBox.width -= deltaX;
499                         }
500                 }
501                 break;
502
503                 case INSIDE_RIGHT_RECTANGLE:
504                 {
505                         if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width)
506                                 && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3))
507                         {
508                                 __cropBox.width += deltaX;
509                         }
510                 }
511                 break;
512
513                 case INSIDE_TOP_LEFT_RECTANGLE:
514                 {
515                         if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3))
516                                         && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
517                         {
518                                 __cropBox.y += deltaY;
519                                 __cropBox.height -= deltaY;
520                                 __cropBox.x += deltaX;
521                                 __cropBox.width -= deltaX;
522                         }
523                 }
524                 break;
525
526                 case INSIDE_TOP_RIGHT_RECTANGLE:
527                 {
528                         if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3))
529                                         && (__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3))
530                         {
531                                 __cropBox.width += deltaX;
532                                 __cropBox.y += deltaY;
533                                 __cropBox.height -= deltaY;
534                         }
535                 }
536                 break;
537
538                 case INSIDE_BOTTOM_LEFT_RECTANGLE:
539                 {
540                         if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3)
541                                 && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
542                         {
543                                 __cropBox.x += deltaX;
544                                 __cropBox.width -= deltaX;
545                                 __cropBox.height += deltaY;
546                         }
547                 }
548                 break;
549
550                 case INSIDE_BOTTOM_RIGHT_RECTANGLE:
551                 {
552                         if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3)
553                                 && (__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3))
554                         {
555                                 __cropBox.width += deltaX;
556                                 __cropBox.height += deltaY;
557                         }
558                 }
559                 break;
560
561                 case INSIDE_CROPBOX:
562                 {
563                         if ((__cropBox.x + deltaX) > __imageBox.x)
564                         {
565                                 __cropBox.x += deltaX;
566                         }
567                         else
568                         {
569                                 __cropBox.x = __imageBox.x;
570                         }
571                         if ((__cropBox.y + deltaY) > __imageBox.y)
572                         {
573                                 __cropBox.y += deltaY;
574                         }
575                         else
576                         {
577                                 __cropBox.y = __imageBox.y;
578                         }
579                         if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
580                         {
581                                 __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
582                         }
583                         if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
584                         {
585                                 __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
586                         }
587                 }
588                 break;
589
590                 default:
591                         break;
592                 }
593         }
594         else if (__cropMode != "auto")
595         {
596                 if (__pointLocation == INSIDE_LEFT_RECTANGLE || __pointLocation == INSIDE_BOTTOM_LEFT_RECTANGLE
597                         || __pointLocation == INSIDE_TOP_LEFT_RECTANGLE)
598                 {
599                         int temp = __cropBox.height;
600                         int height = (__formHeight * (__cropBox.width - (2 * deltaX))) /__formWidth;
601                         temp = height - temp;
602                         if ((__cropBox.width - (2 * deltaX) > (CROP_RECTANGLE_HEIGHT * 3)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width)))
603                         {
604                                 if (__cropBox.x + deltaX >= __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
605                                         && __cropBox.y - (temp / 2) >= __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height
606                                         && (__cropBox.width - (2 * deltaX) > (CROP_RECTANGLE_HEIGHT * 3)))
607                                 {
608                                         __cropBox.x += deltaX;
609                                         __cropBox.width = __cropBox.width - (2 * deltaX);
610                                         __cropBox.height = height;
611                                         __cropBox.y = __cropBox.y - (temp / 2);
612                                 }
613                                 else if ((__cropBox.y + __cropBox.height) <= (__imageBox.y + __imageBox.height)
614                                                 && __cropBox.width < __imageBox.width
615                                                 && __cropBox.x + deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
616                                 {
617                                         if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
618                                                 && __cropBox.x + deltaX >= __imageBox.x)
619                                         {
620                                                 __cropBox.x += deltaX;
621                                         }
622                                         else
623                                         {
624                                                 __cropBox.x = __cropBox.x + (2 * deltaX);
625                                         }
626                                         __cropBox.width = __cropBox.width - (2 * deltaX);
627                                         __cropBox.height = height;
628                                         __cropBox.y = __cropBox.y - temp;
629                                 }
630                                 else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.width - (deltaX) <= __imageBox.width
631                                                 && __cropBox.x + deltaX >= __imageBox.x && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
632                                 {
633                                         if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width)
634                                         {
635                                                 __cropBox.x += deltaX;
636                                         }
637                                         else
638                                         {
639                                                 __cropBox.x = __cropBox.x + (2 * deltaX);
640                                         }
641                                         __cropBox.width = __cropBox.width - (2 * deltaX);
642                                         __cropBox.height = height;
643                                 }
644                         }
645                 }
646                 else if (__pointLocation == INSIDE_RIGHT_RECTANGLE || __pointLocation == INSIDE_BOTTOM_RIGHT_RECTANGLE
647                                 || __pointLocation == INSIDE_TOP_RIGHT_RECTANGLE)
648                 {
649                         deltaX *= -1;
650
651                         int temp = __cropBox.height;
652                         int height = (__formHeight * (__cropBox.width - (2 * deltaX))) / __formWidth;
653                         temp = height - temp;
654                         if ((__cropBox.width - (2 * deltaX) > (CROP_RECTANGLE_HEIGHT * 3)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width)))
655                         {
656                                 if (deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
657                                 {
658                                         if (__cropBox.x + deltaX > __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
659                                                 && __cropBox.y - (temp / 2) > __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height)
660                                         {
661                                                 __cropBox.x += deltaX;
662                                                 __cropBox.width = __cropBox.width - (2 * deltaX);;
663                                                 __cropBox.height = height;
664                                                 __cropBox.y = __cropBox.y - (temp / 2);
665                                         }
666                                         else if ((__cropBox.y + __cropBox.height + (temp / 2)) >= (__imageBox.y + __imageBox.height)
667                                                         && __cropBox.x + __cropBox.width - (2 * deltaX) <= __imageBox.x + __imageBox.width
668                                                         && __cropBox.x - deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
669                                         {
670                                                 if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
671                                                         && __cropBox.x + deltaX >= __imageBox.x)
672                                                 {
673                                                         __cropBox.x += deltaX;
674                                                 }
675                                                 else
676                                                 {
677                                                         __cropBox.width = __cropBox.width - (2 * deltaX);
678                                                 }
679                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
680                                                 __cropBox.height = height;
681                                                 __cropBox.y = __cropBox.y - temp;
682                                         }
683                                         else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.width - (deltaX) <= __imageBox.width
684                                                         && __cropBox.x + deltaX <= __imageBox.x && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
685                                         {
686                                                 if (__cropBox.x + deltaX >= __imageBox.x)
687                                                 {
688                                                         __cropBox.x += deltaX;
689                                                 }
690                                                 else
691                                                 {
692                                                         __cropBox.x = __imageBox.x;
693                                                 }
694                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
695                                                 __cropBox.height = height;
696                                         }
697                                         else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.x + deltaX >= __imageBox.x
698                                                         && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
699                                                         && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
700                                         {
701                                                 __cropBox.x += deltaX;
702                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
703                                                 __cropBox.height = height;
704                                         }
705                                         else if (__cropBox.x + deltaX <= __imageBox.x && __cropBox.y - (temp / 2) >= __imageBox.y
706                                                         && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
707                                                         && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
708                                         {
709                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
710                                                 __cropBox.y = __cropBox.y - (temp / 2);
711                                                 __cropBox.height = height;
712                                         }
713                                 }
714                         }
715                 }
716                 else if (__pointLocation == INSIDE_TOP_RECTANGLE)
717                 {
718                         int temp = __cropBox.width;
719                         int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight;
720                         temp = width - temp;
721                         if (__cropBox.height - (2 * deltaY) > (__formHeight * (CROP_RECTANGLE_HEIGHT * 3)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width)))
722                         {
723                                 if (__cropBox.x - (temp /2 ) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
724                                         && __cropBox.y + (deltaY) > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
725                                 {
726                                         __cropBox.y += deltaY;
727                                         __cropBox.height = __cropBox.height - (2 * deltaY);
728                                         __cropBox.width = width;
729                                         __cropBox.x = __cropBox.x - (temp / 2);
730                                 }
731                                 else if (__cropBox.x - (temp / 2) < __imageBox.x)
732                                 {
733                                         if (__cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width)
734                                         {
735                                                 __cropBox.width = width;
736                                         }
737                                         if (__cropBox.y + deltaY >= __imageBox.y)
738                                         {
739                                                 __cropBox.y += deltaY;
740                                         }
741                                         if (__cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
742                                         {
743                                                 __cropBox.height = __cropBox.height - (2 * deltaY);
744                                         }
745                                 }
746                                 else if (__cropBox.y + __cropBox.height - (2 * deltaY) >= __imageBox.x + __imageBox.height
747                                                 && __cropBox.y + (2 * deltaY) >= __imageBox.y)
748                                 {
749                                         if (__cropBox.x - temp >= __imageBox.x
750                                                 && __cropBox.x + __cropBox.width + temp > __imageBox.x + __imageBox.width)
751                                         {
752                                                 __cropBox.x = __cropBox.x - temp;
753                                         }
754                                         else if (__cropBox.x - temp >= __imageBox.x)
755                                         {
756                                                 __cropBox.x = __cropBox.x - temp / 2;
757                                         }
758                                         if (__cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width)
759                                         {
760                                                 __cropBox.width = width;
761                                         }
762                                         if (__cropBox.y + (2 * deltaY) >= __imageBox.y)
763                                         {
764                                                 __cropBox.y = __cropBox.y + (2 * deltaY);
765                                                 __cropBox.height = __cropBox.height - (2 * deltaY);
766                                         }
767                                 }
768                                 else if (__cropBox.x + __cropBox.width + (temp / 2) > __imageBox.x + __imageBox.width
769                                                 && __cropBox.x - temp >= __imageBox.x && __cropBox.y + deltaY >= __imageBox.y
770                                                 && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
771                                 {
772                                         __cropBox.x = __cropBox.x - temp;
773                                         __cropBox.width = width;
774                                         __cropBox.y += deltaY;
775                                         __cropBox.height = __cropBox.height - (2 * deltaY);
776                                 }
777                         }
778                 }
779                 else if (__pointLocation == INSIDE_BOTTOM_RECTANGLE)
780                 {
781                         deltaY = deltaY * (-1);
782                         int temp = __cropBox.width;
783                         int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight;
784                         temp = width - temp;
785                         if (__cropBox.height - (2 * deltaY) > (__formHeight * (CROP_RECTANGLE_HEIGHT * 3)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width)))
786                         {
787                                 if (__cropBox.x - (temp / 2) >= __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
788                                         && __cropBox.y + deltaY > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
789                                 {
790                                         __cropBox.y += deltaY;
791                                         __cropBox.height = __cropBox.height - (2 * deltaY);;
792                                         __cropBox.width = width;
793                                         __cropBox.x = __cropBox.x - (temp / 2);
794                                 }
795                                 else if (__cropBox.y + deltaY < __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height
796                                                 && __cropBox.x - (temp / 2) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width)
797                                 {
798                                         __cropBox.x = __cropBox.x - (temp / 2);
799                                         __cropBox.width = width;
800                                         __cropBox.height = __cropBox.height - (2 * deltaY);
801                                 }
802                                 else if (__cropBox.x + __cropBox.width + temp > __imageBox.x + __imageBox.width
803                                                 && __cropBox.y + deltaY >= __imageBox.y && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height
804                                                 && __cropBox.x - temp >= __imageBox.x)
805                                 {
806                                         __cropBox.x = __cropBox.x - temp;
807                                         __cropBox.y += deltaY;
808                                         __cropBox.width = width;
809                                         __cropBox.height = __cropBox.height - (2 * deltaY);
810                                 }
811                                 else if (__cropBox.x + __cropBox.width + temp >= __imageBox.x + __imageBox.width
812                                                 && __cropBox.y + deltaY <= __imageBox.y && __cropBox.x - temp > __imageBox.x
813                                                 && __cropBox.y + __cropBox.height + temp < __imageBox.y + __imageBox.height)
814                                 {
815                                         __cropBox.x -= temp;
816                                         __cropBox.width = width;
817                                         __cropBox.height = __cropBox.height - (2 * deltaY);
818                                 }
819                                 else if (__cropBox.x - temp < __imageBox.x && __cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width
820                                                 && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
821                                 {
822                                         if (__cropBox.y + deltaY >= __imageBox.y)
823                                         {
824                                                 __cropBox.y += deltaY;
825                                         }
826                                         __cropBox.width = width;
827                                         __cropBox.height = __cropBox.height - (2 * deltaY);
828                                 }
829                         }
830                 }
831                 else if (__pointLocation == INSIDE_CROPBOX)
832                 {
833                         if ((__cropBox.x + deltaX) > __imageBox.x)
834                         {
835                                 __cropBox.x += deltaX;
836                         }
837                         else
838                         {
839                                 __cropBox.x = __imageBox.x;
840                         }
841                         if ((__cropBox.y + deltaY) > __imageBox.y)
842                         {
843                                 __cropBox.y += deltaY;
844                         }
845                         else
846                         {
847                                 __cropBox.y = __imageBox.y;
848                         }
849                         if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
850                         {
851                                 __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
852                         }
853                         if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
854                         {
855                                 __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
856                         }
857                 }
858         }
859         RequestRedraw(false);
860         __touchStart = currentPosition;
861         AppLogDebug("EXIT");
862 }
863
864 void
865 ImageCropForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
866 {
867         AppLogDebug("ENTER");
868         __pointLocation = OUTSIDE_CROPBOX;
869         AppLogDebug("EXIT");
870 }
871
872 void
873 ImageCropForm::CheckCurrentPosition(const Point currentPosition)
874 {
875         AppLogDebug("ENTER");
876         if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (CROP_RECTANGLE_HEIGHT / 2))
877                 && currentPosition.y >  (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + (CROP_RECTANGLE_HEIGHT / 2)))
878         {
879                 __pointLocation = INSIDE_TOP_RECTANGLE;
880         }
881         else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
882                 && currentPosition.y >  ((__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (CROP_RECTANGLE_HEIGHT / 2)))
883         {
884                 __pointLocation = INSIDE_LEFT_RECTANGLE;
885         }
886         else if (currentPosition.x > (__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
887                 && currentPosition.y > ((__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (CROP_RECTANGLE_HEIGHT / 2)))
888         {
889                 __pointLocation = INSIDE_RIGHT_RECTANGLE;
890         }
891         else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (CROP_RECTANGLE_HEIGHT / 2))
892                 && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
893         {
894                 __pointLocation = INSIDE_BOTTOM_RECTANGLE;
895         }
896         else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
897                          && currentPosition.y > (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y +(CROP_RECTANGLE_HEIGHT / 2)))
898         {
899                 __pointLocation = INSIDE_TOP_LEFT_RECTANGLE;
900         }
901         else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
902                         && currentPosition.y > (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y +(CROP_RECTANGLE_HEIGHT / 2)))
903         {
904                 __pointLocation = INSIDE_TOP_RIGHT_RECTANGLE;
905         }
906         else if (currentPosition.x > (__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
907                         && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
908         {
909                 __pointLocation = INSIDE_BOTTOM_RIGHT_RECTANGLE;
910         }
911         else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
912                         && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
913         {
914                 __pointLocation = INSIDE_BOTTOM_LEFT_RECTANGLE;
915         }
916         else if (currentPosition.x > __cropBox.x && currentPosition.x < (__cropBox.x + __cropBox.width) && currentPosition.y > __cropBox.y && currentPosition.y < (__cropBox.y + __cropBox.height))
917         {
918                 __pointLocation = INSIDE_CROPBOX;
919         }
920         else
921         {
922                 __pointLocation = OUTSIDE_CROPBOX;
923         }
924         AppLogDebug("EXIT");
925         return;
926 }
927
928 void
929 ImageCropForm::SetValue(void)
930 {
931         int prevHeight = __imageBox.height;
932         int prevWidth = __imageBox.width;
933         int prevImageboxX = __imageBox.x;
934         int prevImageBoxY = __imageBox.y;
935         if (GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT)
936         {
937                 __formHeight = Form::GetBounds().height;
938                 __formWidth = Form::GetBounds().width;
939         }
940         else if(GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
941         {
942                 __formHeight = Form::GetBounds().width;
943                 __formWidth = Form::GetBounds().height;
944         }
945
946         float clientAreaRatio = (GetClientAreaBoundsF().height - FOOTER_PANEL_HEIGHT) / GetClientAreaBoundsF().width;
947         if (__imageWidth >= GetClientAreaBounds().width || __imageHeight > (GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT))
948         {
949                 float imageRatio = __imageHeight / (float) __imageWidth;
950                 if (imageRatio < clientAreaRatio)
951                 {
952                         __imageBox.width = GetClientAreaBounds().width;
953                         __imageBox.height = (__imageHeight * __imageBox.width) / __imageWidth;
954                         __imageBox.x = GetClientAreaBounds().x;
955                         __imageBox.y = GetClientAreaBounds().y + ((GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT) - __imageBox.height) / 2;
956                 }
957                 else
958                 {
959                         __imageBox.height = GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT;
960                         __imageBox.width = (__imageWidth * __imageBox.height) / __imageHeight;
961                         __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
962                         __imageBox.y = GetClientAreaBounds().y;
963                 }
964         }
965         else
966         {
967                 __imageBox.height = __imageHeight;
968                 __imageBox.width = __imageWidth;
969                 __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
970                 __imageBox.y = (GetClientAreaBounds().height - __imageBox.height) / 2 ;
971         }
972         if (__isOrientationChanged == false)
973         {
974                 if (__imageBox.height > __imageBox.width)
975                 {
976                         __cropBox.width = (2 * __imageBox.width) / 3;
977                         __cropBox.height = (__formHeight * __cropBox.width / __formWidth);
978                         if (__cropBox.height > __imageBox.height)
979                         {
980                                 __cropBox.height = (2 * __imageBox.height) / 3;
981                                 __cropBox.width = (__cropBox.height * __formWidth) / __formHeight;
982                         }
983                         __cropBox.y =  __imageBox.y + (__imageBox.height - __cropBox.height) / 2;
984                         __cropBox.x = __imageBox.x + (__imageBox.width - __cropBox.width) / 2;
985                 }
986                 else
987                 {
988                         __cropBox.height = (2 *__imageBox.height) / 3;
989                         __cropBox.width = (__formWidth * __cropBox.height / __formHeight);
990                         if (__cropBox.width > __imageBox.width)
991                         {
992                                 __cropBox.width = (2 * __imageBox.width) / 3;
993                                 __cropBox.height = (__formHeight * __cropBox.width) / __formWidth;
994                         }
995                         __cropBox.y = __imageBox.y + (__imageBox.height - __cropBox.height) / 2;
996                         __cropBox.x = __imageBox.x + (__imageBox.width - __cropBox.width) / 2;
997                 }
998         }
999         else
1000         {
1001                 float temp = __imageBox.x + ((__cropBox.x - prevImageboxX) * __imageBox.width) / (float)prevWidth;
1002                 __cropBox.x = (temp + 0.5);
1003                 temp = __imageBox.y + ((__cropBox.y - prevImageBoxY) * __imageBox.height) / (float)prevHeight;
1004                 __cropBox.y = (temp + 0.5);
1005                 temp = (__cropBox.height * __imageBox.height) / (float)prevHeight;
1006                 __cropBox.height = (temp + 0.5);
1007                 temp = (__cropBox.width * __imageBox.width) / (float)prevWidth;
1008                 __cropBox.width = (temp + 0.5);
1009         }
1010         __pCanvas = GetCanvasN();
1011         __pCanvas->SetForegroundColor(CROP_BOX_RECTANGLE_COLOR);
1012 }
1013
1014 void ImageCropForm::OnFormFileEventOccuered(const int index, const unsigned long eventId)
1015 {
1016         AppLogDebug(" ENTER");
1017         UiApp::GetInstance()->Terminate();
1018         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1019 }