Nabi issue fix for .ico image
[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
151         if (pArgs != null)
152         {
153                 __sourceFilePath = *(static_cast<String*>(pArgs->GetAt(0)));
154                 __cropMode = *(static_cast<String*>(pArgs->GetAt(1)));
155                 if (__cropMode == APPCONTROL_DATA_FIT_TO_SCREEN)
156                 {
157                         Integer* pStatus = static_cast<Integer*>(pArgs->GetAt(2));
158                         if (pStatus != null)
159                         {
160                                 __statusValue = pStatus->ToInt();
161                         }
162                         if (__statusValue == SET_AT_TYPE_CALLER_IMAGE)
163                         {
164                                 LongLong* pContentId = static_cast<LongLong*>(pArgs->GetAt(3));
165                                 if (pContentId != null)
166                                 {
167                                         __contentId = pContentId->ToLongLong();
168                                 }
169                         }
170                 }
171         }
172         else
173         {
174                 __sourceFilePath = __pPresentationModel->GetFilePathAt(0);
175
176                 ImageViewerApp* pImageViewerApp = static_cast<ImageViewerApp*>(ImageViewerApp::GetInstance());
177                 const IMap* pIMap = pImageViewerApp->GetAppControlArguments();
178
179                 if (pIMap != null)
180                 {
181                         const String* pCropMode = static_cast<const String*>(pIMap->GetValue(String(APPCONTROL_KEY_IMAGE_CROP_MODE)));
182
183                         if (pCropMode != null)
184                         {
185                                 __cropMode = *pCropMode;
186                         }
187                 }
188         }
189
190         if (__sourceFilePath.IsEmpty() == false)
191         {
192                 result r = __imageBuffer.Construct(__sourceFilePath.GetPointer());
193                 if (r == E_SUCCESS)
194                 {
195                         __imageWidth = __imageBuffer.GetWidth();
196                         __imageHeight = __imageBuffer.GetHeight();
197                         __pCurrentBitmap = __imageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_AUTO);
198                 }
199                 Image img;
200                 r = img.Construct();
201                 if (r == E_SUCCESS)
202                 {
203                         __imageFormat = img.GetImageFormat(__sourceFilePath);
204                 }
205         }
206         SetValue();
207         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
208 }
209
210 void
211 ImageCropForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
212 {
213         AppLogDebug("ENTER");
214         __pPresentationModel->RemoveFileUpdateListener(*this);
215         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
216 }
217
218 result
219 ImageCropForm::OnDraw(void)
220 {
221         result r = E_SUCCESS;
222         AppLogDebug("ENTER");
223         if (__pCanvas != null)
224         {
225                 r = __pCanvas->SetLineWidth(CROP_BOX_LINE_WIDTH);
226                 r = __pCanvas->DrawBitmap(Rectangle(__imageBox.x, __imageBox.y, __imageBox.width, __imageBox.height), *__pCurrentBitmap);
227                 r = __pCanvas->DrawRectangle(Rectangle(__cropBox.x, __cropBox.y, __cropBox.width, __cropBox.height));
228                 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
229                 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
230                 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
231                 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
232                 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
233                 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
234                 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
235                 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
236         }
237         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
238         return r;
239 }
240
241 void
242 ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
243 {
244         SceneManager* pSceneManager = SceneManager::GetInstance();
245         switch(actionId)
246         {
247         case IDA_BUTTON_CANCEL:
248         {
249                 ImageViewerApp* pApp = dynamic_cast<ImageViewerApp*>(UiApp::GetInstance());
250
251                 if ( pApp != null && pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_IMAGE_CROP)
252                 {
253                         pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
254                         pApp->Terminate();
255                 }
256                 else
257                 {
258                         pSceneManager->GoBackward(BackwardSceneTransition());
259                 }
260         }
261         break;
262
263         case IDA_BUTTON_SAVE:
264         {
265                 ImageBuffer imageBuffer;
266                 result r = imageBuffer.Construct(__sourceFilePath);
267
268                 if (r != E_SUCCESS)
269                 {
270                         MessageBox messageBox;
271                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_COM_BODY_UNSUPPORTED_FILE_TYPE"), MSGBOX_STYLE_NONE, 3000);
272                         int modalResult = 0;
273                         messageBox.ShowAndWait(modalResult);
274                         UiApp* pApp = UiApp::GetInstance();
275                         pApp->Terminate();
276                         return;
277                 }
278
279                 if (File::IsFileExist(__sourceFilePath))
280                 {
281                         ImageViewerApp* pApp = dynamic_cast<ImageViewerApp*>(UiApp::GetInstance());
282
283                         if (pApp != null && pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_IMAGE_CROP)
284                         {
285                                 ImageBuffer* pCropBuffer = null;
286                                 int count = 1;
287                                 int index = 0;
288                                 String destFilePath;
289                                 destFilePath.Append(App::GetInstance()->GetAppDataPath());
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()->GetAppDataPath());
302                                         destFilePath.Append(__pPresentationModel->GetFileName(__sourceFilePath));
303                                         destFilePath.Insert(FILE_NAME_SEPARATOR, destFilePath.GetLength() - index - 1);
304                                         destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
305                                 }
306                                 pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
307                                                         (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height);
308                                 pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
309                                 delete pCropBuffer;
310
311                                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
312                                 pList->Add(new (std::nothrow) String(destFilePath));
313
314                                 HashMap* pMap = new (std::nothrow) HashMap(SingleObjectDeleter);
315                                 pMap->Construct();
316                                 pMap->Add(new (std::nothrow) String(APPCONTROL_KEY_SELECTED), pList);
317
318                                 pApp->SendAppControlResult(APP_CTRL_RESULT_SUCCEEDED, pMap);
319                                 pApp->Terminate();
320                         }
321                         else
322                         {
323                                 ImageBuffer* pCropBuffer = null;
324
325                                 if (__cropMode == APPCONTROL_DATA_AUTO)
326                                 {
327                                         String destFilePath;
328                                         int count = 1;
329                                         int index = 0;
330
331                                         if (__sourceFilePath.IsEmpty() == false)
332                                         {
333                                                 __sourceFilePath.Reverse();
334                                                 __sourceFilePath.IndexOf(FILE_EXT_SEPARATOR, 0, index);
335                                                 __sourceFilePath.Reverse();
336                                                 __sourceFilePath.Insert(FILE_NAME_SEPARATOR, __sourceFilePath.GetLength() - index - 1);
337                                                 destFilePath.Append(__sourceFilePath);
338                                                 destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
339                                                 while (File::IsFileExist(destFilePath) == true)
340                                                 {
341                                                         count++;
342                                                         destFilePath.Clear();
343                                                         destFilePath.Append(__sourceFilePath);
344                                                         destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
345                                                 }
346
347                                                 pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
348                                                                          (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height);
349                                                 pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
350                                                 ContentManager::ScanFile(destFilePath);
351                                                 delete pCropBuffer;
352                                         }
353                                         ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
354                                         pList->Add(new (std::nothrow) String(destFilePath));
355                                         pSceneManager->GoBackward(BackwardSceneTransition(), pList);
356                                 }
357                                 else if (__cropMode == APPCONTROL_DATA_FIT_TO_SCREEN)
358                                 {
359                                         result r = E_SUCCESS;
360                                         pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
361                                                         (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height);
362
363                                         if (__statusValue == SET_AT_TYPE_HOME_SCREEN_WALLPAPER)
364                                         {
365                                                 String destPath = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_HOME_SCREEN_WALLPAPER;
366                                                 r = pCropBuffer->EncodeToFile(destPath, IMG_FORMAT_JPG, true, 100);
367                                                 if (r == E_SUCCESS)
368                                                 {
369                                                         r = SettingInfo::SetValue(SETTING_VALUE_HOME_SCREEN_WALLPAPER, destPath);
370                                                 }
371                                         }
372                                         else if (__statusValue == SET_AT_TYPE_LOCK_SCREEN_WALLPAPER)
373                                         {
374                                                 String destPath = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_LOCK_SCREEN_WALLPAPER;
375                                                 r = pCropBuffer->EncodeToFile(destPath, IMG_FORMAT_JPG, true, 100);
376                                                 if (r == E_SUCCESS)
377                                                 {
378                                                         r = SettingInfo::SetValue(SETTING_VALUE_LOCK_SCREEN_WALLPAPER, destPath);
379                                                 }
380                                         }
381                                         else if (__statusValue == SET_AT_TYPE_HOME_AND_LOCK_SCREEN_WALLPAPER)
382                                         {
383                                                 String destPath = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_LOCK_SCREEN_WALLPAPER;
384                                                 String destPathHome = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_HOME_SCREEN_WALLPAPER;
385                                                 r = pCropBuffer->EncodeToFile(destPath, IMG_FORMAT_JPG, true, 100);
386                                                 r = pCropBuffer->EncodeToFile(destPathHome, IMG_FORMAT_JPG, true, 100);
387                                                 if (r == E_SUCCESS)
388                                                 {
389                                                         r = SettingInfo::SetValue(SETTING_VALUE_LOCK_SCREEN_WALLPAPER, destPath);
390                                                         r = SettingInfo::SetValue(SETTING_VALUE_HOME_SCREEN_WALLPAPER, destPathHome);
391                                                 }
392                                         }
393                                         else if (__statusValue == SET_AT_TYPE_CALLER_IMAGE)
394                                         {
395                                                 String destFilePath;
396
397                                                 if (__sourceFilePath.IsEmpty() == false)
398                                                 {
399                                                         destFilePath = App::GetInstance()->GetAppRootPath() + TEMP_FILE_PATH_CONTACT_IMAGE;
400                                                         r = pCropBuffer->EncodeToFile(destFilePath, IMG_FORMAT_JPG, true, 100);
401                                                         Contact* pContact = null;
402                                                         AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
403                                                         Addressbook* pAddressbook = null;
404
405                                                         pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
406                                                         if (pAddressbook != null)
407                                                         {
408                                                                 pContact = pAddressbook->GetContactN(__contentId);
409                                                                 if (pContact != null)
410                                                                 {
411                                                                         pContact->SetThumbnail(destFilePath);
412                                                                         pAddressbook->UpdateContact(*pContact);
413                                                                         delete pContact;
414                                                                 }
415                                                                 delete pAddressbook;
416                                                         }
417                                                 }
418                                         }
419                                         delete pCropBuffer;
420                                         pSceneManager->GoBackward(BackwardSceneTransition());
421                                 }
422                         }
423                 }
424                 else
425                 {
426                         MessageBox messageBox;
427                         messageBox.Construct(L"", ResourceManager::GetString(L"IDS_IV_POP_INVALID_IMAGE_FILE"), MSGBOX_STYLE_NONE, 3000);
428                         int modalResult = 0;
429                         messageBox.ShowAndWait(modalResult);
430                         UiApp* pApp = UiApp::GetInstance();
431                         pApp->Terminate();
432                         return;
433                 }
434         }
435         break;
436         }
437         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
438 }
439
440 void
441 ImageCropForm::OnOrientationChanged(const Control &source, OrientationStatus orientationStatus)
442 {
443         AppLogDebug("ENTER");
444         __isOrientationChanged = true;
445         SetValue();
446         __pCanvas->Clear();
447         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
448 }
449
450 void
451 ImageCropForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
452 {
453         AppLogDebug("ENTER");
454         __touchStart = currentPosition;
455         CheckCurrentPosition(currentPosition);
456         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
457 }
458
459 void
460 ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
461 {
462         AppLogDebug("ENTER");
463         int deltaX = currentPosition.x - __touchStart.x;
464         int deltaY = currentPosition.y - __touchStart.y;
465         if (__cropMode.Equals(APPCONTROL_DATA_AUTO, false))
466         {
467                 switch(__pointLocation)
468                 {
469                 case INSIDE_TOP_RECTANGLE:
470                 {
471                         if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 3)))
472                         {
473                                 __cropBox.y += deltaY;
474                                 __cropBox.height -= deltaY;
475                         }
476                 }
477                 break;
478
479                 case INSIDE_BOTTOM_RECTANGLE:
480                 {
481                         if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height)
482                                 && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 3))
483                         {
484                                 __cropBox.height += deltaY;
485                         }
486                 }
487                 break;
488
489                 case INSIDE_LEFT_RECTANGLE:
490                 {
491                         if ((__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3))
492                         {
493                                 __cropBox.x += deltaX;
494                                 __cropBox.width -= deltaX;
495                         }
496                 }
497                 break;
498
499                 case INSIDE_RIGHT_RECTANGLE:
500                 {
501                         if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width)
502                                 && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 3))
503                         {
504                                 __cropBox.width += deltaX;
505                         }
506                 }
507                 break;
508
509                 case INSIDE_TOP_LEFT_RECTANGLE:
510                 {
511                         if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 3))
512                                         && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3))
513                         {
514                                 __cropBox.y += deltaY;
515                                 __cropBox.height -= deltaY;
516                                 __cropBox.x += deltaX;
517                                 __cropBox.width -= deltaX;
518                         }
519                 }
520                 break;
521
522                 case INSIDE_TOP_RIGHT_RECTANGLE:
523                 {
524                         if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 3))
525                                         && (__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 3))
526                         {
527                                 __cropBox.width += deltaX;
528                                 __cropBox.y += deltaY;
529                                 __cropBox.height -= deltaY;
530                         }
531                 }
532                 break;
533
534                 case INSIDE_BOTTOM_LEFT_RECTANGLE:
535                 {
536                         if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 3)
537                                 && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3))
538                         {
539                                 __cropBox.x += deltaX;
540                                 __cropBox.width -= deltaX;
541                                 __cropBox.height += deltaY;
542                         }
543                 }
544                 break;
545
546                 case INSIDE_BOTTOM_RIGHT_RECTANGLE:
547                 {
548                         if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 3)
549                                 && (__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 3))
550                         {
551                                 __cropBox.width += deltaX;
552                                 __cropBox.height += deltaY;
553                         }
554                 }
555                 break;
556
557                 case INSIDE_CROPBOX:
558                 {
559                         if ((__cropBox.x + deltaX) > __imageBox.x)
560                         {
561                                 __cropBox.x += deltaX;
562                         }
563                         else
564                         {
565                                 __cropBox.x = __imageBox.x;
566                         }
567                         if ((__cropBox.y + deltaY) > __imageBox.y)
568                         {
569                                 __cropBox.y += deltaY;
570                         }
571                         else
572                         {
573                                 __cropBox.y = __imageBox.y;
574                         }
575                         if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
576                         {
577                                 __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
578                         }
579                         if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
580                         {
581                                 __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
582                         }
583                 }
584                 break;
585
586                 default:
587                         break;
588                 }
589         }
590         else if (__cropMode.Equals(APPCONTROL_DATA_FIT_TO_SCREEN, false))
591         {
592                 if (__pointLocation == INSIDE_LEFT_RECTANGLE || __pointLocation == INSIDE_BOTTOM_LEFT_RECTANGLE
593                         || __pointLocation == INSIDE_TOP_LEFT_RECTANGLE)
594                 {
595                         int temp = __cropBox.height;
596                         int height = (__formHeight * (__cropBox.width - (2 * deltaX))) /__formWidth;
597                         temp = height - temp;
598                         if ((__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 3)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width)))
599                         {
600                                 if (__cropBox.x + deltaX >= __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
601                                         && __cropBox.y - (temp / 2) >= __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height
602                                         && (__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 3)))
603                                 {
604                                         __cropBox.x += deltaX;
605                                         __cropBox.width = __cropBox.width - (2 * deltaX);
606                                         __cropBox.height = height;
607                                         __cropBox.y = __cropBox.y - (temp / 2);
608                                 }
609                                 else if ((__cropBox.y + __cropBox.height) <= (__imageBox.y + __imageBox.height)
610                                                 && __cropBox.width < __imageBox.width
611                                                 && __cropBox.x + deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
612                                 {
613                                         if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
614                                                 && __cropBox.x + deltaX >= __imageBox.x)
615                                         {
616                                                 __cropBox.x += deltaX;
617                                         }
618                                         else
619                                         {
620                                                 __cropBox.x = __cropBox.x + (2 * deltaX);
621                                         }
622                                         __cropBox.width = __cropBox.width - (2 * deltaX);
623                                         __cropBox.height = height;
624                                         __cropBox.y = __cropBox.y - temp;
625                                 }
626                                 else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.width - (deltaX) <= __imageBox.width
627                                                 && __cropBox.x + deltaX >= __imageBox.x && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
628                                 {
629                                         if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width)
630                                         {
631                                                 __cropBox.x += deltaX;
632                                         }
633                                         else
634                                         {
635                                                 __cropBox.x = __cropBox.x + (2 * deltaX);
636                                         }
637                                         __cropBox.width = __cropBox.width - (2 * deltaX);
638                                         __cropBox.height = height;
639                                 }
640                         }
641                 }
642                 else if (__pointLocation == INSIDE_RIGHT_RECTANGLE || __pointLocation == INSIDE_BOTTOM_RIGHT_RECTANGLE
643                                 || __pointLocation == INSIDE_TOP_RIGHT_RECTANGLE)
644                 {
645                         deltaX *= -1;
646
647                         int temp = __cropBox.height;
648                         int height = (__formHeight * (__cropBox.width - (2 * deltaX))) / __formWidth;
649                         temp = height - temp;
650                         if ((__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 3)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width)))
651                         {
652                                 if (deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3))
653                                 {
654                                         if (__cropBox.x + deltaX > __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
655                                                 && __cropBox.y - (temp / 2) > __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height)
656                                         {
657                                                 __cropBox.x += deltaX;
658                                                 __cropBox.width = __cropBox.width - (2 * deltaX);;
659                                                 __cropBox.height = height;
660                                                 __cropBox.y = __cropBox.y - (temp / 2);
661                                         }
662                                         else if ((__cropBox.y + __cropBox.height + (temp / 2)) >= (__imageBox.y + __imageBox.height)
663                                                         && __cropBox.x + __cropBox.width - (2 * deltaX) <= __imageBox.x + __imageBox.width
664                                                         && __cropBox.x - deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
665                                         {
666                                                 if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
667                                                         && __cropBox.x + deltaX >= __imageBox.x)
668                                                 {
669                                                         __cropBox.x += deltaX;
670                                                 }
671                                                 else
672                                                 {
673                                                         __cropBox.width = __cropBox.width - (2 * deltaX);
674                                                 }
675                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
676                                                 __cropBox.height = height;
677                                                 __cropBox.y = __cropBox.y - temp;
678                                         }
679                                         else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.width - (deltaX) <= __imageBox.width
680                                                         && __cropBox.x + deltaX <= __imageBox.x && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
681                                         {
682                                                 if (__cropBox.x + deltaX >= __imageBox.x)
683                                                 {
684                                                         __cropBox.x += deltaX;
685                                                 }
686                                                 else
687                                                 {
688                                                         __cropBox.x = __imageBox.x;
689                                                 }
690                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
691                                                 __cropBox.height = height;
692                                         }
693                                         else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.x + deltaX >= __imageBox.x
694                                                         && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
695                                                         && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
696                                         {
697                                                 __cropBox.x += deltaX;
698                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
699                                                 __cropBox.height = height;
700                                         }
701                                         else if (__cropBox.x + deltaX <= __imageBox.x && __cropBox.y - (temp / 2) >= __imageBox.y
702                                                         && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
703                                                         && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
704                                         {
705                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
706                                                 __cropBox.y = __cropBox.y - (temp / 2);
707                                                 __cropBox.height = height;
708                                         }
709                                 }
710                         }
711                 }
712                 else if (__pointLocation == INSIDE_TOP_RECTANGLE)
713                 {
714                         int temp = __cropBox.width;
715                         int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight;
716                         temp = width - temp;
717                         if (__cropBox.height - (2 * deltaY) > (__formHeight * (H_CROP_RECTANGLE * 3)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width)))
718                         {
719                                 if (__cropBox.x - (temp /2 ) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
720                                         && __cropBox.y + (deltaY) > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
721                                 {
722                                         __cropBox.y += deltaY;
723                                         __cropBox.height = __cropBox.height - (2 * deltaY);
724                                         __cropBox.width = width;
725                                         __cropBox.x = __cropBox.x - (temp / 2);
726                                 }
727                                 else if (__cropBox.x - (temp / 2) < __imageBox.x)
728                                 {
729                                         if (__cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width)
730                                         {
731                                                 __cropBox.width = width;
732                                         }
733                                         if (__cropBox.y + deltaY >= __imageBox.y)
734                                         {
735                                                 __cropBox.y += deltaY;
736                                         }
737                                         if (__cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
738                                         {
739                                                 __cropBox.height = __cropBox.height - (2 * deltaY);
740                                         }
741                                 }
742                                 else if (__cropBox.y + __cropBox.height - (2 * deltaY) >= __imageBox.x + __imageBox.height
743                                                 && __cropBox.y + (2 * deltaY) >= __imageBox.y)
744                                 {
745                                         if (__cropBox.x - temp >= __imageBox.x
746                                                 && __cropBox.x + __cropBox.width + temp > __imageBox.x + __imageBox.width)
747                                         {
748                                                 __cropBox.x = __cropBox.x - temp;
749                                         }
750                                         else if (__cropBox.x - temp >= __imageBox.x)
751                                         {
752                                                 __cropBox.x = __cropBox.x - temp / 2;
753                                         }
754                                         if (__cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width)
755                                         {
756                                                 __cropBox.width = width;
757                                         }
758                                         if (__cropBox.y + (2 * deltaY) >= __imageBox.y)
759                                         {
760                                                 __cropBox.y = __cropBox.y + (2 * deltaY);
761                                                 __cropBox.height = __cropBox.height - (2 * deltaY);
762                                         }
763                                 }
764                                 else if (__cropBox.x + __cropBox.width + (temp / 2) > __imageBox.x + __imageBox.width
765                                                 && __cropBox.x - temp >= __imageBox.x && __cropBox.y + deltaY >= __imageBox.y
766                                                 && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
767                                 {
768                                         __cropBox.x = __cropBox.x - temp;
769                                         __cropBox.width = width;
770                                         __cropBox.y += deltaY;
771                                         __cropBox.height = __cropBox.height - (2 * deltaY);
772                                 }
773                         }
774                 }
775                 else if (__pointLocation == INSIDE_BOTTOM_RECTANGLE)
776                 {
777                         deltaY = deltaY * (-1);
778                         int temp = __cropBox.width;
779                         int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight;
780                         temp = width - temp;
781                         if (__cropBox.height - (2 * deltaY) > (__formHeight * (H_CROP_RECTANGLE * 3)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width)))
782                         {
783                                 if (__cropBox.x - (temp / 2) >= __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
784                                         && __cropBox.y + deltaY > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
785                                 {
786                                         __cropBox.y += deltaY;
787                                         __cropBox.height = __cropBox.height - (2 * deltaY);;
788                                         __cropBox.width = width;
789                                         __cropBox.x = __cropBox.x - (temp / 2);
790                                 }
791                                 else if (__cropBox.y + deltaY < __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height
792                                                 && __cropBox.x - (temp / 2) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width)
793                                 {
794                                         __cropBox.x = __cropBox.x - (temp / 2);
795                                         __cropBox.width = width;
796                                         __cropBox.height = __cropBox.height - (2 * deltaY);
797                                 }
798                                 else if (__cropBox.x + __cropBox.width + temp > __imageBox.x + __imageBox.width
799                                                 && __cropBox.y + deltaY >= __imageBox.y && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height
800                                                 && __cropBox.x - temp >= __imageBox.x)
801                                 {
802                                         __cropBox.x = __cropBox.x - temp;
803                                         __cropBox.y += deltaY;
804                                         __cropBox.width = width;
805                                         __cropBox.height = __cropBox.height - (2 * deltaY);
806                                 }
807                                 else if (__cropBox.x + __cropBox.width + temp >= __imageBox.x + __imageBox.width
808                                                 && __cropBox.y + deltaY <= __imageBox.y && __cropBox.x - temp > __imageBox.x
809                                                 && __cropBox.y + __cropBox.height + temp < __imageBox.y + __imageBox.height)
810                                 {
811                                         __cropBox.x -= temp;
812                                         __cropBox.width = width;
813                                         __cropBox.height = __cropBox.height - (2 * deltaY);
814                                 }
815                                 else if (__cropBox.x - temp < __imageBox.x && __cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width
816                                                 && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
817                                 {
818                                         if (__cropBox.y + deltaY >= __imageBox.y)
819                                         {
820                                                 __cropBox.y += deltaY;
821                                         }
822                                         __cropBox.width = width;
823                                         __cropBox.height = __cropBox.height - (2 * deltaY);
824                                 }
825                         }
826                 }
827                 else if (__pointLocation == INSIDE_CROPBOX)
828                 {
829                         if ((__cropBox.x + deltaX) > __imageBox.x)
830                         {
831                                 __cropBox.x += deltaX;
832                         }
833                         else
834                         {
835                                 __cropBox.x = __imageBox.x;
836                         }
837                         if ((__cropBox.y + deltaY) > __imageBox.y)
838                         {
839                                 __cropBox.y += deltaY;
840                         }
841                         else
842                         {
843                                 __cropBox.y = __imageBox.y;
844                         }
845                         if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
846                         {
847                                 __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
848                         }
849                         if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
850                         {
851                                 __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
852                         }
853                 }
854         }
855         RequestRedraw(false);
856         __touchStart = currentPosition;
857         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
858 }
859
860 void
861 ImageCropForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
862 {
863         AppLogDebug("ENTER");
864         __pointLocation = OUTSIDE_CROPBOX;
865         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
866 }
867
868 void
869 ImageCropForm::CheckCurrentPosition(const Point currentPosition)
870 {
871         AppLogDebug("ENTER");
872         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)
873                 && currentPosition.y >  (__cropBox.y - (H_CROP_RECTANGLE / 2) - CROP_BOX_OFFSET) && currentPosition.y < (__cropBox.y + (H_CROP_RECTANGLE / 2) + CROP_BOX_OFFSET))
874         {
875                 __pointLocation = INSIDE_TOP_RECTANGLE;
876         }
877         else if (currentPosition.x > (__cropBox.x - (H_CROP_RECTANGLE / 2) - CROP_BOX_OFFSET) && currentPosition.x < (__cropBox.x + (H_CROP_RECTANGLE / 2) + CROP_BOX_OFFSET)
878                 && 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))
879         {
880                 __pointLocation = INSIDE_LEFT_RECTANGLE;
881         }
882         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)
883                 && 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))
884         {
885                 __pointLocation = INSIDE_RIGHT_RECTANGLE;
886         }
887         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)
888                 && 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))
889         {
890                 __pointLocation = INSIDE_BOTTOM_RECTANGLE;
891         }
892         else if (currentPosition.x > (__cropBox.x - (H_CROP_RECTANGLE / 2) - CROP_BOX_OFFSET) && currentPosition.x < (__cropBox.x + (H_CROP_RECTANGLE / 2) + CROP_BOX_OFFSET)
893                          && currentPosition.y > (__cropBox.y - (H_CROP_RECTANGLE / 2) - CROP_BOX_OFFSET) && currentPosition.y < (__cropBox.y +(H_CROP_RECTANGLE / 2) + CROP_BOX_OFFSET))
894         {
895                 __pointLocation = INSIDE_TOP_LEFT_RECTANGLE;
896         }
897         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)
898                         && currentPosition.y > (__cropBox.y - (H_CROP_RECTANGLE / 2) - CROP_BOX_OFFSET) && currentPosition.y < (__cropBox.y +(H_CROP_RECTANGLE / 2) + CROP_BOX_OFFSET))
899         {
900                 __pointLocation = INSIDE_TOP_RIGHT_RECTANGLE;
901         }
902         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)
903                         && 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))
904         {
905                 __pointLocation = INSIDE_BOTTOM_RIGHT_RECTANGLE;
906         }
907         else if (currentPosition.x > (__cropBox.x - (H_CROP_RECTANGLE / 2) - CROP_BOX_OFFSET) && currentPosition.x < (__cropBox.x + (H_CROP_RECTANGLE / 2) + CROP_BOX_OFFSET)
908                         && 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))
909         {
910                 __pointLocation = INSIDE_BOTTOM_LEFT_RECTANGLE;
911         }
912         else if (currentPosition.x > __cropBox.x && currentPosition.x < (__cropBox.x + __cropBox.width) && currentPosition.y > __cropBox.y && currentPosition.y < (__cropBox.y + __cropBox.height))
913         {
914                 __pointLocation = INSIDE_CROPBOX;
915         }
916         else
917         {
918                 __pointLocation = OUTSIDE_CROPBOX;
919         }
920         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
921         return;
922 }
923
924 void
925 ImageCropForm::SetValue(void)
926 {
927         int prevHeight = __imageBox.height;
928         int prevWidth = __imageBox.width;
929         int prevImageboxX = __imageBox.x;
930         int prevImageBoxY = __imageBox.y;
931         Panel* pPanel = null;
932         pPanel = static_cast<Panel*>(GetControl(L"IDC_FOOTER_PANEL"));
933
934         if (GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT)
935         {
936                 __formHeight = Form::GetBounds().height;
937                 __formWidth = Form::GetBounds().width;
938         }
939         else if (GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
940         {
941                 __formHeight = Form::GetBounds().width;
942                 __formWidth = Form::GetBounds().height;
943         }
944
945         float clientAreaRatio = (GetClientAreaBoundsF().height - pPanel->GetBounds().height) / GetClientAreaBoundsF().width;
946
947         if (__imageWidth >= GetClientAreaBounds().width || __imageHeight > (GetClientAreaBounds().height - pPanel->GetBounds().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 - pPanel->GetBounds().height) - __imageBox.height) / 2;
956                 }
957                 else
958                 {
959                         __imageBox.height = GetClientAreaBounds().height - pPanel->GetBounds().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
1015 ImageCropForm::OnFormFileEventOccuered(const int index, const unsigned long eventId)
1016 {
1017         AppLogDebug(" ENTER");
1018         UiApp::GetInstance()->Terminate();
1019         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
1020 }