1. Added 'Home and lock screen option' 2. Solved crop crash issue
[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 "IvImageCropForm.h"
25 #include "IvImageViewerPresentationModel.h"
26 #include "IvResourceManager.h"
27 #include "IvTypes.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Content;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Io;
35 using namespace Tizen::Media;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
38
39 static const unsigned int CROP_BOX_RECTANGLE_COLOR = Color32<199, 110, 6>::Value;
40 static const int CROP_BOX_LINE_WIDTH = 5;
41
42 ImageCropForm::ImageCropForm(void)
43         : __imageHeight(0)
44         , __imageWidth(0)
45         , __isOrientationChanged(false)
46         , __pCanvas(null)
47         , __pCurrentBitmap(null)
48         , __pRectangleBitmap(null)
49 {
50         __pointLocation = OUTSIDE_CROPBOX;
51 }
52
53 ImageCropForm::~ImageCropForm(void)
54 {
55         if (__pCurrentBitmap != null)
56         {
57                 delete __pCurrentBitmap;
58         }
59         if (__pRectangleBitmap != null)
60         {
61                 delete __pRectangleBitmap;
62         }
63         if (__pCanvas != null)
64         {
65                 delete __pCanvas;
66                 __pCanvas = null;
67         }
68 }
69
70 bool
71 ImageCropForm::Initialize(void)
72 {
73         Form::Construct(IDL_FORM_IMAGE_CROP);
74         Form::SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR);
75         return true;
76 }
77
78 result
79 ImageCropForm::OnInitializing(void)
80 {
81         result r = E_SUCCESS;
82
83         AppResource* pAppResource = null;
84         Bitmap* pSaveButtonBitmap = null;
85         Bitmap* pCancelButtonBitmap  = null;
86         Bitmap* pCWRotationButtonBitmap  = null;
87         Bitmap* pCCWRotationButtonBitmap  = null;
88         Panel* pPanel = null;
89         Button* pSaveButton = null;
90         Button* pCancelButton = null;
91         pAppResource = UiApp::App::GetInstance()->GetAppResource();
92         if (pAppResource != null)
93         {
94                 pSaveButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_SAVE_ICON);
95                 pCancelButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_CANCEL_ICON);
96                 pCWRotationButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_CW_ROTATION_ICON);
97                 pCCWRotationButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_CCW_ROTATION_ICON);
98                 __pRectangleBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_RECTANGLE);
99         }
100
101         pPanel = static_cast<Panel*>(GetControl(L"IDC_FOOTER_PANEL"));
102         if (pPanel != null)
103         {
104                 pSaveButton = static_cast<Button*>(pPanel->GetControl(L"IDC_SAVE_BUTTON"));
105                 if (pSaveButton != null)
106                 {
107                         Point startPoint((pSaveButton->GetWidth() - pSaveButtonBitmap->GetWidth()) / 2,
108                                         (pSaveButton->GetHeight() - pSaveButtonBitmap->GetHeight()) / 2);
109                         pSaveButton->SetNormalBitmap(startPoint, *pSaveButtonBitmap);
110                         pSaveButton->AddActionEventListener(*this);
111                         pSaveButton->SetActionId(IDA_BUTTON_SAVE);
112                 }
113
114                 pCancelButton = static_cast<Button*>(pPanel->GetControl(L"IDC_CANCEL_BUTTON"));
115                 if (pCancelButton != null)
116                 {
117                         Point startPoint((pCancelButton->GetWidth() - pCancelButtonBitmap->GetWidth()) / 2,
118                                         (pCancelButton->GetHeight() - pCancelButtonBitmap->GetHeight()) / 2);
119                         pCancelButton->SetNormalBitmap(startPoint, *pCancelButtonBitmap);
120                         pCancelButton->AddActionEventListener(*this);
121                         pCancelButton->SetActionId(IDA_BUTTON_CANCEL);
122                 }
123                 Label* pLabel = static_cast<Label*>(pPanel->GetControl(L"IDC_PANEL_LABEL"));
124                 if (pLabel != null)
125                 {
126                         SetControlAlwaysOnTop(*pPanel, true);
127                 }
128                 SetControlAlwaysAtBottom(*pLabel, true);
129         }
130         AddTouchEventListener(*this);
131         AddOrientationEventListener(*this);
132
133         delete pSaveButtonBitmap;
134         delete pCancelButtonBitmap;
135         delete pCWRotationButtonBitmap;
136         delete pCCWRotationButtonBitmap;
137         return r;
138 }
139
140 void
141 ImageCropForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
142 {
143         AppLogDebug("ENTER");
144         String* pFilePath = null;
145         if (pArgs != null)
146         {
147                 pFilePath = static_cast<String*>(pArgs->GetAt(0));
148                 delete pArgs;
149         }
150         else
151         {
152                 return;
153         }
154         if (pFilePath != null)
155         {
156                 __sourceFilePath.Append(*pFilePath);
157                 result r = __imageBuffer.Construct(pFilePath->GetPointer());
158                 if (r == E_SUCCESS)
159                 {
160                         __imageWidth = __imageBuffer.GetWidth();
161                         __imageHeight = __imageBuffer.GetHeight();
162                         __pCurrentBitmap = __imageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_AUTO);
163                 }
164                 Image img;
165                 __imageFormat = img.GetImageFormat(__sourceFilePath);
166         }
167         SetValue();
168         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
169 }
170
171 void
172 ImageCropForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
173 {
174         AppLogDebug("ENTER");
175         AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
176 }
177
178 result
179 ImageCropForm::OnDraw(void)
180 {
181         result r = E_SUCCESS;
182         AppLogDebug("ENTER");
183         if (__pCanvas != null)
184         {
185                 r = __pCanvas->SetLineWidth(CROP_BOX_LINE_WIDTH);
186                 r = __pCanvas->DrawBitmap(Rectangle(__imageBox.x, __imageBox.y, __imageBox.width, __imageBox.height), *__pCurrentBitmap);
187                 r = __pCanvas->DrawRectangle(Rectangle(__cropBox.x, __cropBox.y, __cropBox.width, __cropBox.height));
188                 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
189                 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
190                 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
191                 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
192                 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
193                 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
194                 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
195                 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
196         }
197         AppLogDebug("EXIT");
198         return r;
199 }
200
201 void
202 ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
203 {
204         SceneManager* pSceneManager = SceneManager::GetInstance();
205         switch(actionId)
206         {
207         case IDA_BUTTON_CANCEL:
208                 pSceneManager->GoBackward(BackwardSceneTransition());
209                 break;
210         case IDA_BUTTON_SAVE:
211         {
212                 ImageBuffer* pCropBuffer = null;
213                 int count = 1;
214                 int index = 0;
215                 String destFilePath;
216                 String stringToInsert = L"_";
217                 String delimiter = L".";
218                 if (__sourceFilePath.IsEmpty() == false)
219                 {
220                         __sourceFilePath.Reverse();
221                         __sourceFilePath.IndexOf(delimiter, 0, index);
222                         __sourceFilePath.Reverse();
223                         __sourceFilePath.Insert(stringToInsert, __sourceFilePath.GetLength() - index - 1);
224                         destFilePath.Append(__sourceFilePath);
225                         destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
226                         while (File::IsFileExist(destFilePath) == true)
227                         {
228                                 count++;
229                                 destFilePath.Clear();
230                                 destFilePath.Append(__sourceFilePath);
231                                 destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
232                         }
233                         pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
234                                                 (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height);
235                         pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
236                         delete pCropBuffer;
237                 }
238                 ContentManager contentManager;
239                 contentManager.Construct();
240                 //contentManager.ScanDirectory(Tizen::System::Environment::GetMediaPath(), true, )
241                 ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
242                 pList->Add(new (std::nothrow) String(destFilePath));
243                 AppLog("Manish %ls", destFilePath.GetPointer());
244                 pSceneManager->GoBackward(BackwardSceneTransition());
245                 AppLog("Exit");
246         }
247         break;
248         }
249 }
250
251 void
252 ImageCropForm::OnOrientationChanged(const Control &source, OrientationStatus orientationStatus)
253 {
254         AppLogDebug("ENTER");
255         __isOrientationChanged = true;
256         SetValue();
257         __pCanvas->Clear();
258         AppLogDebug("EXIT");
259 }
260
261 void
262 ImageCropForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
263 {
264         AppLogDebug("ENTER");
265         __touchStart = currentPosition;
266         CheckCurrentPosition(currentPosition);
267         AppLogDebug("EXIT");
268 }
269
270 void
271 ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
272 {
273         AppLogDebug("ENTER");
274         int deltaX = currentPosition.x - __touchStart.x;
275         int deltaY = currentPosition.y - __touchStart.y;
276         switch(__pointLocation)
277         {
278         case INSIDE_TOP_RECTANGLE:
279         {
280                 if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3)))
281                 {
282                         __cropBox.y += deltaY;
283                         __cropBox.height -= deltaY;
284                 }
285         }
286         break;
287
288         case INSIDE_BOTTOM_RECTANGLE:
289         {
290                 if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height)
291                         && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3))
292                 {
293                         __cropBox.height += deltaY;
294                 }
295         }
296         break;
297
298         case INSIDE_LEFT_RECTANGLE:
299         {
300                 if ((__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
301                 {
302                         __cropBox.x += deltaX;
303                         __cropBox.width -= deltaX;
304                 }
305         }
306         break;
307
308         case INSIDE_RIGHT_RECTANGLE:
309         {
310                 if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width)
311                         && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3))
312                 {
313                         __cropBox.width += deltaX;
314                 }
315         }
316         break;
317
318         case INSIDE_TOP_LEFT_RECTANGLE:
319         {
320                 if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3))
321                                 && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
322                 {
323                         __cropBox.y += deltaY;
324                         __cropBox.height -= deltaY;
325                         __cropBox.x += deltaX;
326                         __cropBox.width -= deltaX;
327                 }
328         }
329         break;
330
331         case INSIDE_TOP_RIGHT_RECTANGLE:
332         {
333                 if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3))
334                                 && (__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3))
335                 {
336                         __cropBox.width += deltaX;
337                         __cropBox.y += deltaY;
338                         __cropBox.height -= deltaY;
339                 }
340         }
341         break;
342
343         case INSIDE_BOTTOM_LEFT_RECTANGLE:
344         {
345                 if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3)
346                         && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
347                 {
348                         __cropBox.x += deltaX;
349                         __cropBox.width -= deltaX;
350                         __cropBox.height += deltaY;
351                 }
352         }
353         break;
354
355         case INSIDE_BOTTOM_RIGHT_RECTANGLE:
356         {
357                 if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3)
358                         && (__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3))
359                 {
360                         __cropBox.width += deltaX;
361                         __cropBox.height += deltaY;
362                 }
363         }
364         break;
365
366         case INSIDE_CROPBOX:
367         {
368                 if ((__cropBox.x + deltaX) > __imageBox.x)
369                 {
370                         __cropBox.x += deltaX;
371                 }
372                 else
373                 {
374                         __cropBox.x = __imageBox.x;
375                 }
376                 if ((__cropBox.y + deltaY) > __imageBox.y)
377                 {
378                         __cropBox.y += deltaY;
379                 }
380                 else
381                 {
382                         __cropBox.y = __imageBox.y;
383                 }
384                 if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
385                 {
386                         __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
387                 }
388                 if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
389                 {
390                         __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
391                 }
392         }
393         break;
394
395         default:
396                 break;
397         }
398         RequestRedraw(false);
399         __touchStart = currentPosition;
400         AppLogDebug("EXIT");
401 }
402
403 void
404 ImageCropForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
405 {
406         AppLogDebug("ENTER");
407         __pointLocation = OUTSIDE_CROPBOX;
408         AppLogDebug("EXIT");
409 }
410
411 void
412 ImageCropForm::CheckCurrentPosition(const Point currentPosition)
413 {
414         AppLogDebug("ENTER");
415         if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (CROP_RECTANGLE_HEIGHT / 2))
416                 && currentPosition.y >  (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + (CROP_RECTANGLE_HEIGHT / 2)))
417         {
418                 __pointLocation = INSIDE_TOP_RECTANGLE;
419         }
420         else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
421                 && currentPosition.y >  ((__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (CROP_RECTANGLE_HEIGHT / 2)))
422         {
423                 __pointLocation = INSIDE_LEFT_RECTANGLE;
424         }
425         else if (currentPosition.x > (__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
426                 && currentPosition.y > ((__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (CROP_RECTANGLE_HEIGHT / 2)))
427         {
428                 __pointLocation = INSIDE_RIGHT_RECTANGLE;
429         }
430         else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (CROP_RECTANGLE_HEIGHT / 2))
431                 && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
432         {
433                 __pointLocation = INSIDE_BOTTOM_RECTANGLE;
434         }
435         else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
436                          && currentPosition.y > (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y +(CROP_RECTANGLE_HEIGHT / 2)))
437         {
438                 __pointLocation = INSIDE_TOP_LEFT_RECTANGLE;
439         }
440         else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
441                         && currentPosition.y > (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y +(CROP_RECTANGLE_HEIGHT / 2)))
442         {
443                 __pointLocation = INSIDE_TOP_RIGHT_RECTANGLE;
444         }
445         else if (currentPosition.x > (__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
446                         && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
447         {
448                 __pointLocation = INSIDE_BOTTOM_RIGHT_RECTANGLE;
449         }
450         else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
451                         && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
452         {
453                 __pointLocation = INSIDE_BOTTOM_LEFT_RECTANGLE;
454         }
455         else if (currentPosition.x > __cropBox.x && currentPosition.x < (__cropBox.x + __cropBox.width) && currentPosition.y > __cropBox.y && currentPosition.y < (__cropBox.y + __cropBox.height))
456         {
457                 __pointLocation = INSIDE_CROPBOX;
458         }
459         else
460         {
461                 __pointLocation = OUTSIDE_CROPBOX;
462         }
463         AppLogDebug("EXIT");
464         return;
465 }
466
467 void
468 ImageCropForm::SetValue(void)
469 {
470         int prevHeight = __imageBox.height;
471         int prevWidth = __imageBox.width;
472         int prevImageboxX = __imageBox.x;
473         int prevImageBoxY = __imageBox.y;
474         int indicatorBarHeight = 0;
475
476         if (GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
477         {
478                 indicatorBarHeight = 21;
479         }
480         else
481         {
482                 indicatorBarHeight = 60;
483         }
484
485         if (__imageWidth > GetClientAreaBounds().width && __imageHeight > GetClientAreaBounds().height)
486         {
487                 if (__imageHeight > __imageWidth)
488                 {
489                         __imageBox.height = GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT;
490                         __imageBox.width = (__imageWidth * GetClientAreaBounds().height) / __imageHeight;
491                         __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
492                         __imageBox.y = indicatorBarHeight;
493                 }
494                 else
495                 {
496                         __imageBox.width = GetClientAreaBounds().width;
497                         __imageBox.height = (GetClientAreaBounds().width * __imageHeight) / __imageWidth;
498                         __imageBox.x = 0;
499                         __imageBox.y = (GetClientAreaBounds().height - __imageBox.height) / 2;
500                 }
501         }
502         else if (__imageWidth > GetClientAreaBounds().width)
503         {
504                 __imageBox.width = GetClientAreaBounds().width;
505                 __imageBox.height = (__imageHeight * GetClientAreaBounds().width) / __imageWidth;
506                 __imageBox.x = 0;
507                 __imageBox.y = (GetClientAreaBounds().height - __imageBox.height) / 2;
508
509         }
510         else if (__imageHeight > GetClientAreaBounds().height)
511         {
512                 __imageBox.height = GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT;
513                 __imageBox.width = (__imageWidth * GetClientAreaBounds().height) / __imageHeight;
514                 __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
515                 __imageBox.y = indicatorBarHeight;
516         }
517         else
518         {
519                 __imageBox.height = __imageHeight;
520                 __imageBox.width = __imageWidth;
521                 __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
522                 __imageBox.y = (GetClientAreaBounds().height - __imageBox.height) / 2 ;
523         }
524         if (__isOrientationChanged == false)
525         {
526                 if (__imageHeight >= __imageWidth)
527                 {
528                         __cropBox.height = __imageBox.height / 2;
529                         __cropBox.width = __imageBox.width / 2;
530                         __cropBox.y =  __imageBox.y + (__imageBox.height / 4);
531                         __cropBox.x = __imageBox.x + (__imageBox.width / 4);
532                 }
533                 else
534                 {
535                         __cropBox.height = (2 * __imageBox.height) / 3;
536                         __cropBox.width = (2 * __imageBox.width) / 3;
537                         __cropBox.y = __imageBox.y + (__imageBox.height - __cropBox.height) / 2;
538                         __cropBox.x = __imageBox.x + (__imageBox.width - __cropBox.width) / 2;
539                 }
540         }
541         else
542         {
543                 float temp = __imageBox.x + ((__cropBox.x - prevImageboxX) * __imageBox.width) / (float)prevWidth;
544                 __cropBox.x = (temp + 0.5);
545                 temp = __imageBox.y + ((__cropBox.y - prevImageBoxY) * __imageBox.height) / (float)prevHeight;
546                 __cropBox.y = (temp + 0.5);
547                 temp = (__cropBox.height * __imageBox.height) / (float)prevHeight;
548                 __cropBox.height = (temp + 0.5);
549                 temp = (__cropBox.width * __imageBox.width) / (float)prevWidth;
550                 __cropBox.width = (temp + 0.5);
551         }
552         __pCanvas = GetCanvasN();
553         __pCanvas->SetForegroundColor(CROP_BOX_RECTANGLE_COLOR);
554
555 }