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