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