Coding Idioms changes
[apps/osp/ImageViewer.git] / src / IvImageCropForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                IvImageCrop.cpp
19  * @brief               This is the implementation file for Image Crop.
20  */
21
22 #include <FApp.h>
23 #include <FMedia.h>
24 #include <FSystem.h>
25 #include <FSocial.h>
26 #include "IvImageCropForm.h"
27 #include "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                 SetControlAlwaysOnTop(*pPanel, true);
132                 Label* pLabel = static_cast<Label*>(pPanel->GetControl(L"IDC_PANEL_LABEL"));
133                 if (pLabel != null)
134                 {
135                         SetControlAlwaysAtBottom(*pLabel, true);
136                 }
137         }
138         AddTouchEventListener(*this);
139         AddOrientationEventListener(*this);
140         __pPresentationModel->AddFileUpdateListener(this);
141
142         return E_SUCCESS;
143 }
144
145 void
146 ImageCropForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
147 {
148         AppLogDebug("ENTER pArgs(%x)", pArgs);
149         if (pArgs != null)
150         {
151                 __sourceFilePath = *(static_cast<String*>(pArgs->GetAt(0)));
152                 __cropMode = *(static_cast<String*>(pArgs->GetAt(1)));
153         }
154         else
155         {
156                 __sourceFilePath = __pPresentationModel->GetFilePathAt(0);
157
158                 ImageViewerApp* pImageViewerApp = static_cast<ImageViewerApp*>(ImageViewerApp::GetInstance());
159                 const IMap* pIMap = pImageViewerApp->GetAppControlArguments();
160
161                 if (pIMap != null)
162                 {
163                         const String* pCropMode = static_cast<const String*>(pIMap->GetValue(String(APPCONTROL_KEY_IMAGE_CROP_MODE)));
164
165                         if (pCropMode != null)
166                         {
167                                 __cropMode = *pCropMode;
168                         }
169                 }
170         }
171
172         if (__sourceFilePath.IsEmpty() == false)
173         {
174                 result r = __imageBuffer.Construct(__sourceFilePath.GetPointer());
175                 if (r == E_SUCCESS)
176                 {
177                         __imageWidth = __imageBuffer.GetWidth();
178                         __imageHeight = __imageBuffer.GetHeight();
179                         __pCurrentBitmap = __imageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_AUTO);
180                 }
181                 Image img;
182                 __imageFormat = img.GetImageFormat(__sourceFilePath);
183         }
184
185         if (__cropMode == APPCONTROL_DATA_AUTO)
186         {
187                 SetValue();
188                 return;
189         }
190         else if (__cropMode == APPCONTROL_DATA_FIT_TO_SCREEN)
191         {
192                 Integer *pStatus = static_cast<Integer*>(pArgs->GetAt(2));
193                 if (pStatus != null)
194                 {
195                         __statusValue = pStatus->ToInt();
196                 }
197                 if (__statusValue == SET_AT_TYPE_CALLER_IMAGE)
198                 {
199                         LongLong* pContentId = static_cast<LongLong*>(pArgs->GetAt(3));
200                         if (pContentId != null)
201                         {
202                                 __contentId = pContentId->ToLongLong();
203                         }
204                 }
205                 SetValue();
206         }
207         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
208 }
209
210 void
211 ImageCropForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
212 {
213         AppLogDebug("ENTER");
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->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_IMAGE_CROP)
251                 {
252                         if (pApp != null)
253                         {
254                                 pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
255                                 pApp->Terminate();
256                         }
257                 }
258                 else
259                 {
260                         pSceneManager->GoBackward(BackwardSceneTransition());
261                 }
262         }
263         break;
264
265         case IDA_BUTTON_SAVE:
266         {
267                 if (__cropMode == APPCONTROL_DATA_AUTO)
268                 {
269                         ImageBuffer* pCropBuffer = null;
270                         int count = 1;
271                         int index = 0;
272                         String destFilePath;
273                         if (__sourceFilePath.IsEmpty() == false)
274                         {
275                                 __sourceFilePath.Reverse();
276                                 __sourceFilePath.IndexOf(FILE_EXT_SEPARATOR, 0, index);
277                                 __sourceFilePath.Reverse();
278                                 __sourceFilePath.Insert(FILE_NAME_SEPARATOR, __sourceFilePath.GetLength() - index - 1);
279                                 destFilePath.Append(__sourceFilePath);
280                                 destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
281                                 while (File::IsFileExist(destFilePath) == true)
282                                 {
283                                         count++;
284                                         destFilePath.Clear();
285                                         destFilePath.Append(__sourceFilePath);
286                                         destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
287                                 }
288                                 pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
289                                                 (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height);
290                                 pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
291                                 ContentManager::ScanFile(destFilePath);
292                                 delete pCropBuffer;
293                         }
294                         ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
295                         pList->Add(new (std::nothrow) String(destFilePath));
296                         ImageViewerApp* pApp = dynamic_cast<ImageViewerApp*>(UiApp::GetInstance());
297
298                         if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_IMAGE_CROP)
299                         {
300                                 HashMap* pMap = new (std::nothrow) HashMap(SingleObjectDeleter);
301                                 pMap->Construct();
302                                 pMap->Add(new (std::nothrow) String(APPCONTROL_KEY_SELECTED), pList);
303
304                                 if (pApp != null)
305                                 {
306                                         pApp->SendAppControlResult(APP_CTRL_RESULT_SUCCEEDED, pMap);
307                                         pApp->Terminate();
308                                 }
309                         }
310                         else
311                         {
312                                 pSceneManager->GoBackward(BackwardSceneTransition(), pList);
313                         }
314                 }
315                 else if (__cropMode == APPCONTROL_DATA_FIT_TO_SCREEN)
316                 {
317                         ImageBuffer* pCropBuffer = null;
318                         result r = E_SUCCESS;
319                         pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
320                                         (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height);
321
322                         if (__statusValue == SET_AT_TYPE_HOME_SCREEN_WALLPAPER)
323                         {
324                                 String destPath = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_HOME_SCREEN_WALLPAPER;
325                                 r = pCropBuffer->EncodeToFile(destPath, __imageFormat, true, 100);
326                                 if (r == E_SUCCESS)
327                                 {
328                                         r = SettingInfo::SetValue(SETTING_VALUE_HOME_SCREEN_WALLPAPER, destPath);
329                                 }
330                         }
331                         else if (__statusValue == SET_AT_TYPE_LOCK_SCREEN_WALLPAPER)
332                         {
333                                 String destPath = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_LOCK_SCREEN_WALLPAPER;
334                                 r = pCropBuffer->EncodeToFile(destPath, __imageFormat, true, 100);
335                                 if (r == E_SUCCESS)
336                                 {
337                                         r = SettingInfo::SetValue(SETTING_VALUE_LOCK_SCREEN_WALLPAPER, destPath);
338                                 }
339                         }
340                         else if (__statusValue == SET_AT_TYPE_HOME_AND_LOCK_SCREEN_WALLPAPER)
341                         {
342                                 String destPath = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_LOCK_SCREEN_WALLPAPER;
343                                 String destPathHome = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_HOME_SCREEN_WALLPAPER;
344                                 r = pCropBuffer->EncodeToFile(destPath, __imageFormat, true, 100);
345                                 r = pCropBuffer->EncodeToFile(destPathHome, __imageFormat, true, 100);
346                                 if (r == E_SUCCESS)
347                                 {
348                                         r = SettingInfo::SetValue(SETTING_VALUE_LOCK_SCREEN_WALLPAPER, destPath);
349                                         r = SettingInfo::SetValue(SETTING_VALUE_HOME_SCREEN_WALLPAPER, destPathHome);
350                                 }
351                                 else if (r == E_OVERFLOW)
352                                 {
353                                         MessageBox messageBox;
354                                         messageBox.Construct(L"", L"File size is too big", MSGBOX_STYLE_NONE, 3000);
355                                         int modalResult = 0;
356                                         messageBox.ShowAndWait(modalResult);
357                                 }
358                         }
359                         else if (__statusValue == SET_AT_TYPE_CALLER_IMAGE)
360                         {
361                                 int count = 1;
362                                 int index = 0;
363                                 String destFilePath;
364
365                                 if (__sourceFilePath.IsEmpty() == false)
366                                 {
367                                         __sourceFilePath.Reverse();
368                                         __sourceFilePath.IndexOf(FILE_EXT_SEPARATOR, 0, index);
369                                         __sourceFilePath.Reverse();
370                                         __sourceFilePath.Insert(FILE_NAME_SEPARATOR, __sourceFilePath.GetLength() - index - 1);
371                                         destFilePath.Append(__sourceFilePath);
372                                         destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
373                                         while (File::IsFileExist(destFilePath) == true)
374                                         {
375                                                 count++;
376                                                 destFilePath.Clear();
377                                                 destFilePath.Append(__sourceFilePath);
378                                                 destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
379                                         }
380                                 }
381                                  r = pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
382                                 ContentManager::ScanFile(destFilePath);
383                                 Contact* pContact = null;
384                                 AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
385                                 Addressbook* pAddressbook = null;
386
387                                 pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
388                                 pContact = pAddressbook->GetContactN(__contentId);
389                                 pContact->SetThumbnail(destFilePath);
390                                 pAddressbook->UpdateContact(*pContact);
391
392                                 delete pContact;
393                                 delete pAddressbook;
394                                 delete pCropBuffer;
395
396                                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
397                                 pList->Add(new (std::nothrow) String(destFilePath));
398                                 pSceneManager->GoBackward(BackwardSceneTransition(), pList);
399
400                                 AppLogDebug("EXIT(%s)1", GetErrorMessage(GetLastResult()));
401                                 return;
402                         }
403                         delete pCropBuffer;
404                         pSceneManager->GoBackward(BackwardSceneTransition());
405                 }
406         }
407         break;
408         }
409         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
410 }
411
412 void
413 ImageCropForm::OnOrientationChanged(const Control &source, OrientationStatus orientationStatus)
414 {
415         AppLogDebug("ENTER");
416         __isOrientationChanged = true;
417         SetValue();
418         __pCanvas->Clear();
419         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
420 }
421
422 void
423 ImageCropForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
424 {
425         AppLogDebug("ENTER");
426         __touchStart = currentPosition;
427         CheckCurrentPosition(currentPosition);
428         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
429 }
430
431 void
432 ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
433 {
434         AppLogDebug("ENTER");
435         int deltaX = currentPosition.x - __touchStart.x;
436         int deltaY = currentPosition.y - __touchStart.y;
437         if (__cropMode.Equals(APPCONTROL_DATA_AUTO, false))
438         {
439                 switch(__pointLocation)
440                 {
441                 case INSIDE_TOP_RECTANGLE:
442                 {
443                         if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 3)))
444                         {
445                                 __cropBox.y += deltaY;
446                                 __cropBox.height -= deltaY;
447                         }
448                 }
449                 break;
450
451                 case INSIDE_BOTTOM_RECTANGLE:
452                 {
453                         if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height)
454                                 && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 3))
455                         {
456                                 __cropBox.height += deltaY;
457                         }
458                 }
459                 break;
460
461                 case INSIDE_LEFT_RECTANGLE:
462                 {
463                         if ((__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3))
464                         {
465                                 __cropBox.x += deltaX;
466                                 __cropBox.width -= deltaX;
467                         }
468                 }
469                 break;
470
471                 case INSIDE_RIGHT_RECTANGLE:
472                 {
473                         if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width)
474                                 && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 3))
475                         {
476                                 __cropBox.width += deltaX;
477                         }
478                 }
479                 break;
480
481                 case INSIDE_TOP_LEFT_RECTANGLE:
482                 {
483                         if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 3))
484                                         && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3))
485                         {
486                                 __cropBox.y += deltaY;
487                                 __cropBox.height -= deltaY;
488                                 __cropBox.x += deltaX;
489                                 __cropBox.width -= deltaX;
490                         }
491                 }
492                 break;
493
494                 case INSIDE_TOP_RIGHT_RECTANGLE:
495                 {
496                         if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 3))
497                                         && (__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 3))
498                         {
499                                 __cropBox.width += deltaX;
500                                 __cropBox.y += deltaY;
501                                 __cropBox.height -= deltaY;
502                         }
503                 }
504                 break;
505
506                 case INSIDE_BOTTOM_LEFT_RECTANGLE:
507                 {
508                         if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 3)
509                                 && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3))
510                         {
511                                 __cropBox.x += deltaX;
512                                 __cropBox.width -= deltaX;
513                                 __cropBox.height += deltaY;
514                         }
515                 }
516                 break;
517
518                 case INSIDE_BOTTOM_RIGHT_RECTANGLE:
519                 {
520                         if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 3)
521                                 && (__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 3))
522                         {
523                                 __cropBox.width += deltaX;
524                                 __cropBox.height += deltaY;
525                         }
526                 }
527                 break;
528
529                 case INSIDE_CROPBOX:
530                 {
531                         if ((__cropBox.x + deltaX) > __imageBox.x)
532                         {
533                                 __cropBox.x += deltaX;
534                         }
535                         else
536                         {
537                                 __cropBox.x = __imageBox.x;
538                         }
539                         if ((__cropBox.y + deltaY) > __imageBox.y)
540                         {
541                                 __cropBox.y += deltaY;
542                         }
543                         else
544                         {
545                                 __cropBox.y = __imageBox.y;
546                         }
547                         if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
548                         {
549                                 __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
550                         }
551                         if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
552                         {
553                                 __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
554                         }
555                 }
556                 break;
557
558                 default:
559                         break;
560                 }
561         }
562         else if (__cropMode != APPCONTROL_DATA_AUTO)
563         {
564                 if (__pointLocation == INSIDE_LEFT_RECTANGLE || __pointLocation == INSIDE_BOTTOM_LEFT_RECTANGLE
565                         || __pointLocation == INSIDE_TOP_LEFT_RECTANGLE)
566                 {
567                         int temp = __cropBox.height;
568                         int height = (__formHeight * (__cropBox.width - (2 * deltaX))) /__formWidth;
569                         temp = height - temp;
570                         if ((__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 3)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width)))
571                         {
572                                 if (__cropBox.x + deltaX >= __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
573                                         && __cropBox.y - (temp / 2) >= __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height
574                                         && (__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 3)))
575                                 {
576                                         __cropBox.x += deltaX;
577                                         __cropBox.width = __cropBox.width - (2 * deltaX);
578                                         __cropBox.height = height;
579                                         __cropBox.y = __cropBox.y - (temp / 2);
580                                 }
581                                 else if ((__cropBox.y + __cropBox.height) <= (__imageBox.y + __imageBox.height)
582                                                 && __cropBox.width < __imageBox.width
583                                                 && __cropBox.x + deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
584                                 {
585                                         if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
586                                                 && __cropBox.x + deltaX >= __imageBox.x)
587                                         {
588                                                 __cropBox.x += deltaX;
589                                         }
590                                         else
591                                         {
592                                                 __cropBox.x = __cropBox.x + (2 * deltaX);
593                                         }
594                                         __cropBox.width = __cropBox.width - (2 * deltaX);
595                                         __cropBox.height = height;
596                                         __cropBox.y = __cropBox.y - temp;
597                                 }
598                                 else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.width - (deltaX) <= __imageBox.width
599                                                 && __cropBox.x + deltaX >= __imageBox.x && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
600                                 {
601                                         if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width)
602                                         {
603                                                 __cropBox.x += deltaX;
604                                         }
605                                         else
606                                         {
607                                                 __cropBox.x = __cropBox.x + (2 * deltaX);
608                                         }
609                                         __cropBox.width = __cropBox.width - (2 * deltaX);
610                                         __cropBox.height = height;
611                                 }
612                         }
613                 }
614                 else if (__pointLocation == INSIDE_RIGHT_RECTANGLE || __pointLocation == INSIDE_BOTTOM_RIGHT_RECTANGLE
615                                 || __pointLocation == INSIDE_TOP_RIGHT_RECTANGLE)
616                 {
617                         deltaX *= -1;
618
619                         int temp = __cropBox.height;
620                         int height = (__formHeight * (__cropBox.width - (2 * deltaX))) / __formWidth;
621                         temp = height - temp;
622                         if ((__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 3)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width)))
623                         {
624                                 if (deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3))
625                                 {
626                                         if (__cropBox.x + deltaX > __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
627                                                 && __cropBox.y - (temp / 2) > __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height)
628                                         {
629                                                 __cropBox.x += deltaX;
630                                                 __cropBox.width = __cropBox.width - (2 * deltaX);;
631                                                 __cropBox.height = height;
632                                                 __cropBox.y = __cropBox.y - (temp / 2);
633                                         }
634                                         else if ((__cropBox.y + __cropBox.height + (temp / 2)) >= (__imageBox.y + __imageBox.height)
635                                                         && __cropBox.x + __cropBox.width - (2 * deltaX) <= __imageBox.x + __imageBox.width
636                                                         && __cropBox.x - deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
637                                         {
638                                                 if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
639                                                         && __cropBox.x + deltaX >= __imageBox.x)
640                                                 {
641                                                         __cropBox.x += deltaX;
642                                                 }
643                                                 else
644                                                 {
645                                                         __cropBox.width = __cropBox.width - (2 * deltaX);
646                                                 }
647                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
648                                                 __cropBox.height = height;
649                                                 __cropBox.y = __cropBox.y - temp;
650                                         }
651                                         else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.width - (deltaX) <= __imageBox.width
652                                                         && __cropBox.x + deltaX <= __imageBox.x && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
653                                         {
654                                                 if (__cropBox.x + deltaX >= __imageBox.x)
655                                                 {
656                                                         __cropBox.x += deltaX;
657                                                 }
658                                                 else
659                                                 {
660                                                         __cropBox.x = __imageBox.x;
661                                                 }
662                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
663                                                 __cropBox.height = height;
664                                         }
665                                         else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.x + deltaX >= __imageBox.x
666                                                         && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
667                                                         && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
668                                         {
669                                                 __cropBox.x += deltaX;
670                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
671                                                 __cropBox.height = height;
672                                         }
673                                         else if (__cropBox.x + deltaX <= __imageBox.x && __cropBox.y - (temp / 2) >= __imageBox.y
674                                                         && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
675                                                         && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
676                                         {
677                                                 __cropBox.width = __cropBox.width - (2 * deltaX);
678                                                 __cropBox.y = __cropBox.y - (temp / 2);
679                                                 __cropBox.height = height;
680                                         }
681                                 }
682                         }
683                 }
684                 else if (__pointLocation == INSIDE_TOP_RECTANGLE)
685                 {
686                         int temp = __cropBox.width;
687                         int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight;
688                         temp = width - temp;
689                         if (__cropBox.height - (2 * deltaY) > (__formHeight * (H_CROP_RECTANGLE * 3)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width)))
690                         {
691                                 if (__cropBox.x - (temp /2 ) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
692                                         && __cropBox.y + (deltaY) > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
693                                 {
694                                         __cropBox.y += deltaY;
695                                         __cropBox.height = __cropBox.height - (2 * deltaY);
696                                         __cropBox.width = width;
697                                         __cropBox.x = __cropBox.x - (temp / 2);
698                                 }
699                                 else if (__cropBox.x - (temp / 2) < __imageBox.x)
700                                 {
701                                         if (__cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width)
702                                         {
703                                                 __cropBox.width = width;
704                                         }
705                                         if (__cropBox.y + deltaY >= __imageBox.y)
706                                         {
707                                                 __cropBox.y += deltaY;
708                                         }
709                                         if (__cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
710                                         {
711                                                 __cropBox.height = __cropBox.height - (2 * deltaY);
712                                         }
713                                 }
714                                 else if (__cropBox.y + __cropBox.height - (2 * deltaY) >= __imageBox.x + __imageBox.height
715                                                 && __cropBox.y + (2 * deltaY) >= __imageBox.y)
716                                 {
717                                         if (__cropBox.x - temp >= __imageBox.x
718                                                 && __cropBox.x + __cropBox.width + temp > __imageBox.x + __imageBox.width)
719                                         {
720                                                 __cropBox.x = __cropBox.x - temp;
721                                         }
722                                         else if (__cropBox.x - temp >= __imageBox.x)
723                                         {
724                                                 __cropBox.x = __cropBox.x - temp / 2;
725                                         }
726                                         if (__cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width)
727                                         {
728                                                 __cropBox.width = width;
729                                         }
730                                         if (__cropBox.y + (2 * deltaY) >= __imageBox.y)
731                                         {
732                                                 __cropBox.y = __cropBox.y + (2 * deltaY);
733                                                 __cropBox.height = __cropBox.height - (2 * deltaY);
734                                         }
735                                 }
736                                 else if (__cropBox.x + __cropBox.width + (temp / 2) > __imageBox.x + __imageBox.width
737                                                 && __cropBox.x - temp >= __imageBox.x && __cropBox.y + deltaY >= __imageBox.y
738                                                 && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
739                                 {
740                                         __cropBox.x = __cropBox.x - temp;
741                                         __cropBox.width = width;
742                                         __cropBox.y += deltaY;
743                                         __cropBox.height = __cropBox.height - (2 * deltaY);
744                                 }
745                         }
746                 }
747                 else if (__pointLocation == INSIDE_BOTTOM_RECTANGLE)
748                 {
749                         deltaY = deltaY * (-1);
750                         int temp = __cropBox.width;
751                         int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight;
752                         temp = width - temp;
753                         if (__cropBox.height - (2 * deltaY) > (__formHeight * (H_CROP_RECTANGLE * 3)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width)))
754                         {
755                                 if (__cropBox.x - (temp / 2) >= __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
756                                         && __cropBox.y + deltaY > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
757                                 {
758                                         __cropBox.y += deltaY;
759                                         __cropBox.height = __cropBox.height - (2 * deltaY);;
760                                         __cropBox.width = width;
761                                         __cropBox.x = __cropBox.x - (temp / 2);
762                                 }
763                                 else if (__cropBox.y + deltaY < __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height
764                                                 && __cropBox.x - (temp / 2) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width)
765                                 {
766                                         __cropBox.x = __cropBox.x - (temp / 2);
767                                         __cropBox.width = width;
768                                         __cropBox.height = __cropBox.height - (2 * deltaY);
769                                 }
770                                 else if (__cropBox.x + __cropBox.width + temp > __imageBox.x + __imageBox.width
771                                                 && __cropBox.y + deltaY >= __imageBox.y && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height
772                                                 && __cropBox.x - temp >= __imageBox.x)
773                                 {
774                                         __cropBox.x = __cropBox.x - temp;
775                                         __cropBox.y += deltaY;
776                                         __cropBox.width = width;
777                                         __cropBox.height = __cropBox.height - (2 * deltaY);
778                                 }
779                                 else if (__cropBox.x + __cropBox.width + temp >= __imageBox.x + __imageBox.width
780                                                 && __cropBox.y + deltaY <= __imageBox.y && __cropBox.x - temp > __imageBox.x
781                                                 && __cropBox.y + __cropBox.height + temp < __imageBox.y + __imageBox.height)
782                                 {
783                                         __cropBox.x -= temp;
784                                         __cropBox.width = width;
785                                         __cropBox.height = __cropBox.height - (2 * deltaY);
786                                 }
787                                 else if (__cropBox.x - temp < __imageBox.x && __cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width
788                                                 && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
789                                 {
790                                         if (__cropBox.y + deltaY >= __imageBox.y)
791                                         {
792                                                 __cropBox.y += deltaY;
793                                         }
794                                         __cropBox.width = width;
795                                         __cropBox.height = __cropBox.height - (2 * deltaY);
796                                 }
797                         }
798                 }
799                 else if (__pointLocation == INSIDE_CROPBOX)
800                 {
801                         if ((__cropBox.x + deltaX) > __imageBox.x)
802                         {
803                                 __cropBox.x += deltaX;
804                         }
805                         else
806                         {
807                                 __cropBox.x = __imageBox.x;
808                         }
809                         if ((__cropBox.y + deltaY) > __imageBox.y)
810                         {
811                                 __cropBox.y += deltaY;
812                         }
813                         else
814                         {
815                                 __cropBox.y = __imageBox.y;
816                         }
817                         if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
818                         {
819                                 __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
820                         }
821                         if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
822                         {
823                                 __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
824                         }
825                 }
826         }
827         RequestRedraw(false);
828         __touchStart = currentPosition;
829         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
830 }
831
832 void
833 ImageCropForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
834 {
835         AppLogDebug("ENTER");
836         __pointLocation = OUTSIDE_CROPBOX;
837         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
838 }
839
840 void
841 ImageCropForm::CheckCurrentPosition(const Point currentPosition)
842 {
843         AppLogDebug("ENTER");
844         if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (H_CROP_RECTANGLE / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (H_CROP_RECTANGLE / 2))
845                 && currentPosition.y >  (__cropBox.y - (H_CROP_RECTANGLE / 2)) && currentPosition.y < (__cropBox.y + (H_CROP_RECTANGLE / 2)))
846         {
847                 __pointLocation = INSIDE_TOP_RECTANGLE;
848         }
849         else if (currentPosition.x > (__cropBox.x - (H_CROP_RECTANGLE / 2)) && currentPosition.x < (__cropBox.x + (H_CROP_RECTANGLE / 2))
850                 && currentPosition.y >  ((__cropBox.y + __cropBox.height / 2) - (H_CROP_RECTANGLE / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (H_CROP_RECTANGLE / 2)))
851         {
852                 __pointLocation = INSIDE_LEFT_RECTANGLE;
853         }
854         else if (currentPosition.x > (__cropBox.x + __cropBox.width - (H_CROP_RECTANGLE / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (H_CROP_RECTANGLE / 2))
855                 && currentPosition.y > ((__cropBox.y + __cropBox.height / 2) - (H_CROP_RECTANGLE / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (H_CROP_RECTANGLE / 2)))
856         {
857                 __pointLocation = INSIDE_RIGHT_RECTANGLE;
858         }
859         else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (H_CROP_RECTANGLE / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (H_CROP_RECTANGLE / 2))
860                 && currentPosition.y > (__cropBox.y + __cropBox.height - (H_CROP_RECTANGLE / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (H_CROP_RECTANGLE / 2)))
861         {
862                 __pointLocation = INSIDE_BOTTOM_RECTANGLE;
863         }
864         else if (currentPosition.x > (__cropBox.x - (H_CROP_RECTANGLE / 2)) && currentPosition.x < (__cropBox.x + (H_CROP_RECTANGLE / 2))
865                          && currentPosition.y > (__cropBox.y - (H_CROP_RECTANGLE / 2)) && currentPosition.y < (__cropBox.y +(H_CROP_RECTANGLE / 2)))
866         {
867                 __pointLocation = INSIDE_TOP_LEFT_RECTANGLE;
868         }
869         else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (H_CROP_RECTANGLE / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (H_CROP_RECTANGLE / 2))
870                         && currentPosition.y > (__cropBox.y - (H_CROP_RECTANGLE / 2)) && currentPosition.y < (__cropBox.y +(H_CROP_RECTANGLE / 2)))
871         {
872                 __pointLocation = INSIDE_TOP_RIGHT_RECTANGLE;
873         }
874         else if (currentPosition.x > (__cropBox.x + __cropBox.width - (H_CROP_RECTANGLE / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (H_CROP_RECTANGLE / 2))
875                         && currentPosition.y > (__cropBox.y + __cropBox.height - (H_CROP_RECTANGLE / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (H_CROP_RECTANGLE / 2)))
876         {
877                 __pointLocation = INSIDE_BOTTOM_RIGHT_RECTANGLE;
878         }
879         else if (currentPosition.x > (__cropBox.x - (H_CROP_RECTANGLE / 2)) && currentPosition.x < (__cropBox.x + (H_CROP_RECTANGLE / 2))
880                         && currentPosition.y > (__cropBox.y + __cropBox.height - (H_CROP_RECTANGLE / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (H_CROP_RECTANGLE / 2)))
881         {
882                 __pointLocation = INSIDE_BOTTOM_LEFT_RECTANGLE;
883         }
884         else if (currentPosition.x > __cropBox.x && currentPosition.x < (__cropBox.x + __cropBox.width) && currentPosition.y > __cropBox.y && currentPosition.y < (__cropBox.y + __cropBox.height))
885         {
886                 __pointLocation = INSIDE_CROPBOX;
887         }
888         else
889         {
890                 __pointLocation = OUTSIDE_CROPBOX;
891         }
892         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
893         return;
894 }
895
896 void
897 ImageCropForm::SetValue(void)
898 {
899         int prevHeight = __imageBox.height;
900         int prevWidth = __imageBox.width;
901         int prevImageboxX = __imageBox.x;
902         int prevImageBoxY = __imageBox.y;
903         if (GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT)
904         {
905                 __formHeight = Form::GetBounds().height;
906                 __formWidth = Form::GetBounds().width;
907         }
908         else if (GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
909         {
910                 __formHeight = Form::GetBounds().width;
911                 __formWidth = Form::GetBounds().height;
912         }
913
914         float clientAreaRatio = (GetClientAreaBoundsF().height - H_FOOTER_PANEL) / GetClientAreaBoundsF().width;
915         if (__imageWidth >= GetClientAreaBounds().width || __imageHeight > (GetClientAreaBounds().height - H_FOOTER_PANEL))
916         {
917                 float imageRatio = __imageHeight / (float) __imageWidth;
918                 if (imageRatio < clientAreaRatio)
919                 {
920                         __imageBox.width = GetClientAreaBounds().width;
921                         __imageBox.height = (__imageHeight * __imageBox.width) / __imageWidth;
922                         __imageBox.x = GetClientAreaBounds().x;
923                         __imageBox.y = GetClientAreaBounds().y + ((GetClientAreaBounds().height - H_FOOTER_PANEL) - __imageBox.height) / 2;
924                 }
925                 else
926                 {
927                         __imageBox.height = GetClientAreaBounds().height - H_FOOTER_PANEL;
928                         __imageBox.width = (__imageWidth * __imageBox.height) / __imageHeight;
929                         __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
930                         __imageBox.y = GetClientAreaBounds().y;
931                 }
932         }
933         else
934         {
935                 __imageBox.height = __imageHeight;
936                 __imageBox.width = __imageWidth;
937                 __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
938                 __imageBox.y = (GetClientAreaBounds().height - __imageBox.height) / 2 ;
939         }
940         if (__isOrientationChanged == false)
941         {
942                 if (__imageBox.height > __imageBox.width)
943                 {
944                         __cropBox.width = (2 * __imageBox.width) / 3;
945                         __cropBox.height = (__formHeight * __cropBox.width / __formWidth);
946                         if (__cropBox.height > __imageBox.height)
947                         {
948                                 __cropBox.height = (2 * __imageBox.height) / 3;
949                                 __cropBox.width = (__cropBox.height * __formWidth) / __formHeight;
950                         }
951                         __cropBox.y =  __imageBox.y + (__imageBox.height - __cropBox.height) / 2;
952                         __cropBox.x = __imageBox.x + (__imageBox.width - __cropBox.width) / 2;
953                 }
954                 else
955                 {
956                         __cropBox.height = (2 *__imageBox.height) / 3;
957                         __cropBox.width = (__formWidth * __cropBox.height / __formHeight);
958                         if (__cropBox.width > __imageBox.width)
959                         {
960                                 __cropBox.width = (2 * __imageBox.width) / 3;
961                                 __cropBox.height = (__formHeight * __cropBox.width) / __formWidth;
962                         }
963                         __cropBox.y = __imageBox.y + (__imageBox.height - __cropBox.height) / 2;
964                         __cropBox.x = __imageBox.x + (__imageBox.width - __cropBox.width) / 2;
965                 }
966         }
967         else
968         {
969                 float temp = __imageBox.x + ((__cropBox.x - prevImageboxX) * __imageBox.width) / (float)prevWidth;
970                 __cropBox.x = (temp + 0.5);
971                 temp = __imageBox.y + ((__cropBox.y - prevImageBoxY) * __imageBox.height) / (float)prevHeight;
972                 __cropBox.y = (temp + 0.5);
973                 temp = (__cropBox.height * __imageBox.height) / (float)prevHeight;
974                 __cropBox.height = (temp + 0.5);
975                 temp = (__cropBox.width * __imageBox.width) / (float)prevWidth;
976                 __cropBox.width = (temp + 0.5);
977         }
978         __pCanvas = GetCanvasN();
979         __pCanvas->SetForegroundColor(CROP_BOX_RECTANGLE_COLOR);
980 }
981
982 void ImageCropForm::OnFormFileEventOccuered(const int index, const unsigned long eventId)
983 {
984         AppLogDebug(" ENTER");
985         UiApp::GetInstance()->Terminate();
986         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
987 }