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