1.Cropped image destFilePath changed. 2.Coding idioms fixes
[apps/osp/ImageViewer.git] / src / IvImageCropForm.cpp
index 188c389..a4ce300 100644 (file)
 
 #include <FApp.h>
 #include <FMedia.h>
+#include <FSystem.h>
+#include <FSocial.h>
 #include "IvImageCropForm.h"
+#include "IvImageViewerApp.h"
 #include "IvImageViewerPresentationModel.h"
 #include "IvResourceManager.h"
 #include "IvTypes.h"
 using namespace Tizen::App;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
+using namespace Tizen::Content;
 using namespace Tizen::Graphics;
 using namespace Tizen::Io;
 using namespace Tizen::Media;
+using namespace Tizen::System;
+using namespace Tizen::Social;
 using namespace Tizen::Ui::Controls;
 using namespace Tizen::Ui::Scenes;
 
@@ -39,14 +45,19 @@ static const unsigned int CROP_BOX_RECTANGLE_COLOR = Color32<199, 110, 6>::Value
 static const int CROP_BOX_LINE_WIDTH = 5;
 
 ImageCropForm::ImageCropForm(void)
-       : __imageHeight(0)
+       : __cropMode(APPCONTROL_DATA_AUTO)
+       , __imageHeight(0)
        , __imageWidth(0)
        , __isOrientationChanged(false)
        , __pCanvas(null)
        , __pCurrentBitmap(null)
        , __pRectangleBitmap(null)
+       , __pointLocation(OUTSIDE_CROPBOX)
+       , __pPresentationModel(null)
+       , __statusValue(-1)
+       , __formHeight(0)
+       , __formWidth(0)
 {
-       __pointLocation = OUTSIDE_CROPBOX;
 }
 
 ImageCropForm::~ImageCropForm(void)
@@ -62,7 +73,6 @@ ImageCropForm::~ImageCropForm(void)
        if (__pCanvas != null)
        {
                delete __pCanvas;
-               __pCanvas = null;
        }
 }
 
@@ -71,19 +81,18 @@ ImageCropForm::Initialize(void)
 {
        Form::Construct(IDL_FORM_IMAGE_CROP);
        Form::SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR);
+
+       __pPresentationModel = ImageViewerPresentationModel::GetInstance();
+
        return true;
 }
 
 result
 ImageCropForm::OnInitializing(void)
 {
-       result r = E_SUCCESS;
-
        AppResource* pAppResource = null;
        Bitmap* pSaveButtonBitmap = null;
        Bitmap* pCancelButtonBitmap  = null;
-       Bitmap* pCWRotationButtonBitmap  = null;
-       Bitmap* pCCWRotationButtonBitmap  = null;
        Panel* pPanel = null;
        Button* pSaveButton = null;
        Button* pCancelButton = null;
@@ -92,8 +101,6 @@ ImageCropForm::OnInitializing(void)
        {
                pSaveButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_SAVE_ICON);
                pCancelButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_CANCEL_ICON);
-               pCWRotationButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_CW_ROTATION_ICON);
-               pCCWRotationButtonBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_FORM_CCW_ROTATION_ICON);
                __pRectangleBitmap = pAppResource->GetBitmapN(IDB_IMAGE_CROP_RECTANGLE);
        }
 
@@ -101,63 +108,102 @@ ImageCropForm::OnInitializing(void)
        if (pPanel != null)
        {
                pSaveButton = static_cast<Button*>(pPanel->GetControl(L"IDC_SAVE_BUTTON"));
-               if (pSaveButton != null)
+               if (pSaveButton != null && pSaveButtonBitmap != null)
                {
                        Point startPoint((pSaveButton->GetWidth() - pSaveButtonBitmap->GetWidth()) / 2,
                                        (pSaveButton->GetHeight() - pSaveButtonBitmap->GetHeight()) / 2);
                        pSaveButton->SetNormalBitmap(startPoint, *pSaveButtonBitmap);
                        pSaveButton->AddActionEventListener(*this);
                        pSaveButton->SetActionId(IDA_BUTTON_SAVE);
+                       delete pSaveButtonBitmap;
                }
 
                pCancelButton = static_cast<Button*>(pPanel->GetControl(L"IDC_CANCEL_BUTTON"));
-               if (pCancelButton != null)
+               if (pCancelButton != null && pCancelButtonBitmap != null)
                {
                        Point startPoint((pCancelButton->GetWidth() - pCancelButtonBitmap->GetWidth()) / 2,
                                        (pCancelButton->GetHeight() - pCancelButtonBitmap->GetHeight()) / 2);
                        pCancelButton->SetNormalBitmap(startPoint, *pCancelButtonBitmap);
                        pCancelButton->AddActionEventListener(*this);
                        pCancelButton->SetActionId(IDA_BUTTON_CANCEL);
+                       delete pCancelButtonBitmap;
                }
+               SetControlAlwaysOnTop(*pPanel, true);
                Label* pLabel = static_cast<Label*>(pPanel->GetControl(L"IDC_PANEL_LABEL"));
                if (pLabel != null)
                {
-                       SetControlAlwaysOnTop(*pPanel, true);
+                       SetControlAlwaysAtBottom(*pLabel, true);
                }
-               SetControlAlwaysAtBottom(*pLabel, true);
        }
        AddTouchEventListener(*this);
        AddOrientationEventListener(*this);
+       __pPresentationModel->AddFileUpdateListener(this);
 
-       delete pSaveButtonBitmap;
-       delete pCancelButtonBitmap;
-       delete pCWRotationButtonBitmap;
-       delete pCCWRotationButtonBitmap;
-       return r;
+       return E_SUCCESS;
 }
 
 void
 ImageCropForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
 {
-       AppLogDebug("ENTER");
-       String* pFilePath = null;
+       AppLogDebug("ENTER pArgs(%x)", pArgs);
        if (pArgs != null)
        {
-               pFilePath = static_cast<String*>(pArgs->GetAt(0));
-               delete pArgs;
+               __sourceFilePath = *(static_cast<String*>(pArgs->GetAt(0)));
+               __cropMode = *(static_cast<String*>(pArgs->GetAt(1)));
        }
        else
        {
+               __sourceFilePath = __pPresentationModel->GetFilePathAt(0);
+
+               ImageViewerApp* pImageViewerApp = static_cast<ImageViewerApp*>(ImageViewerApp::GetInstance());
+               const IMap* pIMap = pImageViewerApp->GetAppControlArguments();
+
+               if (pIMap != null)
+               {
+                       const String* pCropMode = static_cast<const String*>(pIMap->GetValue(String(APPCONTROL_KEY_IMAGE_CROP_MODE)));
+
+                       if (pCropMode != null)
+                       {
+                               __cropMode = *pCropMode;
+                       }
+               }
+       }
+
+       if (__sourceFilePath.IsEmpty() == false)
+       {
+               result r = __imageBuffer.Construct(__sourceFilePath.GetPointer());
+               if (r == E_SUCCESS)
+               {
+                       __imageWidth = __imageBuffer.GetWidth();
+                       __imageHeight = __imageBuffer.GetHeight();
+                       __pCurrentBitmap = __imageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_AUTO);
+               }
+               Image img;
+               __imageFormat = img.GetImageFormat(__sourceFilePath);
+       }
+
+       if (__cropMode == APPCONTROL_DATA_AUTO)
+       {
+               SetValue();
                return;
        }
-       if (pFilePath != null)
+       else if (__cropMode == APPCONTROL_DATA_FIT_TO_SCREEN)
        {
-               __sourceFilePath.Append(*pFilePath);
-               __imageBuffer.GetImageInfo(pFilePath->GetPointer(), __imageFormat, __imageWidth, __imageHeight);
-               __imageBuffer.Construct(pFilePath->GetPointer());
-               __pCurrentBitmap = __imageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_AUTO);
+               Integer *pStatus = static_cast<Integer*>(pArgs->GetAt(2));
+               if (pStatus != null)
+               {
+                       __statusValue = pStatus->ToInt();
+               }
+               if (__statusValue == SET_AT_TYPE_CALLER_IMAGE)
+               {
+                       LongLong* pContentId = static_cast<LongLong*>(pArgs->GetAt(3));
+                       if (pContentId != null)
+                       {
+                               __contentId = pContentId->ToLongLong();
+                       }
+               }
+               SetValue();
        }
-       SetValue();
        AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
@@ -178,16 +224,16 @@ ImageCropForm::OnDraw(void)
                r = __pCanvas->SetLineWidth(CROP_BOX_LINE_WIDTH);
                r = __pCanvas->DrawBitmap(Rectangle(__imageBox.x, __imageBox.y, __imageBox.width, __imageBox.height), *__pCurrentBitmap);
                r = __pCanvas->DrawRectangle(Rectangle(__cropBox.x, __cropBox.y, __cropBox.width, __cropBox.height));
-               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
-               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
-               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
-               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
-               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
-               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
-               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
-               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
-       }
-       AppLogDebug("EXIT");
+               r = __pCanvas->DrawBitmap(Rectangle((__cropBox.x + __cropBox.width / 2) - (H_CROP_RECTANGLE / 2), __cropBox.y - (H_CROP_RECTANGLE / 2), H_CROP_RECTANGLE, H_CROP_RECTANGLE), *__pRectangleBitmap); // Top Rectangle
+               r = __pCanvas->DrawBitmap(Rectangle((__cropBox.x + __cropBox.width / 2) - (H_CROP_RECTANGLE / 2), (__cropBox.y + __cropBox.height - (H_CROP_RECTANGLE / 2)), H_CROP_RECTANGLE, H_CROP_RECTANGLE), *__pRectangleBitmap); // Bottom Rectangle
+               r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x - (H_CROP_RECTANGLE / 2), (__cropBox.y + __cropBox.height / 2) - (H_CROP_RECTANGLE / 2), H_CROP_RECTANGLE, H_CROP_RECTANGLE), *__pRectangleBitmap); //Left Rectangle
+               r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x + __cropBox.width - (H_CROP_RECTANGLE / 2), (__cropBox.y + __cropBox.height / 2) - (H_CROP_RECTANGLE / 2), H_CROP_RECTANGLE, H_CROP_RECTANGLE), *__pRectangleBitmap); //Right Rectangle
+               r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x - (H_CROP_RECTANGLE / 2), __cropBox.y - (H_CROP_RECTANGLE / 2), H_CROP_RECTANGLE, H_CROP_RECTANGLE), *__pRectangleBitmap); // Top Left Rectangle
+               r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x + __cropBox.width - (H_CROP_RECTANGLE / 2), __cropBox.y - (H_CROP_RECTANGLE / 2), H_CROP_RECTANGLE, H_CROP_RECTANGLE), *__pRectangleBitmap); // Top Right Rectangle
+               r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x + __cropBox.width - (H_CROP_RECTANGLE / 2), (__cropBox.y + __cropBox.height - (H_CROP_RECTANGLE / 2)), H_CROP_RECTANGLE, H_CROP_RECTANGLE), *__pRectangleBitmap); // Bottom Right Rectangle
+               r = __pCanvas->DrawBitmap(Rectangle(__cropBox.x - (H_CROP_RECTANGLE / 2), (__cropBox.y + __cropBox.height - (H_CROP_RECTANGLE / 2)), H_CROP_RECTANGLE, H_CROP_RECTANGLE), *__pRectangleBitmap); // Bottom Left Rectangle
+       }
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
        return r;
 }
 
@@ -198,41 +244,196 @@ ImageCropForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
        switch(actionId)
        {
        case IDA_BUTTON_CANCEL:
-               pSceneManager->GoBackward(BackwardSceneTransition());
-               break;
+       {
+               ImageViewerApp* pApp = dynamic_cast<ImageViewerApp*>(UiApp::GetInstance());
+
+               if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_IMAGE_CROP)
+               {
+                       if (pApp != null)
+                       {
+                               pApp->SendAppControlResult(APP_CTRL_RESULT_CANCELED, null);
+                               pApp->Terminate();
+                       }
+               }
+               else
+               {
+                       pSceneManager->GoBackward(BackwardSceneTransition());
+               }
+       }
+       break;
+
        case IDA_BUTTON_SAVE:
        {
-               ImageBuffer* pCropBuffer = null;
-               int count = 1;
-               int index = 0;
-               String destFilePath;
-               String stringToInsert = L"_";
-               String delimiter = L".";
-               if (__sourceFilePath.IsEmpty() == false)
+               if (__cropMode == APPCONTROL_DATA_AUTO)
                {
-                       __sourceFilePath.Reverse();
-                       __sourceFilePath.IndexOf(delimiter, 0, index);
-                       __sourceFilePath.Reverse();
-                       __sourceFilePath.Insert(stringToInsert, __sourceFilePath.GetLength() - index - 1);
-                       destFilePath.Append(__sourceFilePath);
-                       destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
-                       while (File::IsFileExist(destFilePath) == true)
-                       {
-                               count++;
-                               destFilePath.Clear();
-                               destFilePath.Append(__sourceFilePath);
-                               destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
+                       ImageBuffer* pCropBuffer = null;
+                       int count = 1;
+                       int index = 0;
+                       String destFilePath;
+                       ImageViewerApp* pApp = dynamic_cast<ImageViewerApp*>(UiApp::GetInstance());
+
+                       if (__sourceFilePath.IsEmpty() == false)
+                       {
+                               if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_IMAGE_CROP)
+                               {
+                                       destFilePath.Append(App::GetInstance()->GetAppDataPath());
+                                       destFilePath.Append(__pPresentationModel->GetFileName(__sourceFilePath));
+                                       destFilePath.Reverse();
+                                       destFilePath.IndexOf(FILE_EXT_SEPARATOR, 0, index);
+                                       destFilePath.Reverse();
+                                       destFilePath.Insert(FILE_NAME_SEPARATOR, destFilePath.GetLength() - index - 1);
+                                       destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
+
+                                       while (File::IsFileExist(destFilePath) == true)
+                                       {
+                                               count++;
+                                               destFilePath.Clear();
+                                               destFilePath.Append(App::GetInstance()->GetAppDataPath());
+                                               destFilePath.Append(__pPresentationModel->GetFileName(__sourceFilePath));
+                                               destFilePath.Insert(FILE_NAME_SEPARATOR, destFilePath.GetLength() - index - 1);
+                                               destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
+                                       }
+
+                               }
+                               else
+                               {
+                                       __sourceFilePath.Reverse();
+                                       __sourceFilePath.IndexOf(FILE_EXT_SEPARATOR, 0, index);
+                                       __sourceFilePath.Reverse();
+                                       __sourceFilePath.Insert(FILE_NAME_SEPARATOR, __sourceFilePath.GetLength() - index - 1);
+                                       destFilePath.Append(__sourceFilePath);
+                                       destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
+                                       while (File::IsFileExist(destFilePath) == true)
+                                       {
+                                               count++;
+                                               destFilePath.Clear();
+                                               destFilePath.Append(__sourceFilePath);
+                                               destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
+                                       }
+
+                               }
+
+                               pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
+                                               (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height);
+                               pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
+                               ContentManager::ScanFile(destFilePath);
+                               delete pCropBuffer;
                        }
+                       ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+                       pList->Add(new (std::nothrow) String(destFilePath));
+
+                       if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_IMAGE_CROP)
+                       {
+                               HashMap* pMap = new (std::nothrow) HashMap(SingleObjectDeleter);
+                               pMap->Construct();
+                               pMap->Add(new (std::nothrow) String(APPCONTROL_KEY_SELECTED), pList);
+
+                               if (pApp != null)
+                               {
+                                       pApp->SendAppControlResult(APP_CTRL_RESULT_SUCCEEDED, pMap);
+                                       pApp->Terminate();
+                               }
+                       }
+                       else
+                       {
+                               pSceneManager->GoBackward(BackwardSceneTransition(), pList);
+                       }
+               }
+               else if (__cropMode == APPCONTROL_DATA_FIT_TO_SCREEN)
+               {
+                       ImageBuffer* pCropBuffer = null;
+                       result r = E_SUCCESS;
                        pCropBuffer = __imageBuffer.CropN(((__cropBox.x - __imageBox.x) * __imageWidth) / __imageBox.width, ((__cropBox.y - __imageBox.y) * __imageHeight) / __imageBox.height,
-                                               (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height);
-                       pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
+                                       (__cropBox.width * __imageWidth) / __imageBox.width, (__cropBox.height * __imageHeight) / __imageBox.height);
+
+                       if (__statusValue == SET_AT_TYPE_HOME_SCREEN_WALLPAPER)
+                       {
+                               String destPath = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_HOME_SCREEN_WALLPAPER;
+                               r = pCropBuffer->EncodeToFile(destPath, __imageFormat, true, 100);
+                               if (r == E_SUCCESS)
+                               {
+                                       r = SettingInfo::SetValue(SETTING_VALUE_HOME_SCREEN_WALLPAPER, destPath);
+                               }
+                       }
+                       else if (__statusValue == SET_AT_TYPE_LOCK_SCREEN_WALLPAPER)
+                       {
+                               String destPath = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_LOCK_SCREEN_WALLPAPER;
+                               r = pCropBuffer->EncodeToFile(destPath, __imageFormat, true, 100);
+                               if (r == E_SUCCESS)
+                               {
+                                       r = SettingInfo::SetValue(SETTING_VALUE_LOCK_SCREEN_WALLPAPER, destPath);
+                               }
+                       }
+                       else if (__statusValue == SET_AT_TYPE_HOME_AND_LOCK_SCREEN_WALLPAPER)
+                       {
+                               String destPath = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_LOCK_SCREEN_WALLPAPER;
+                               String destPathHome = App::GetInstance()->GetAppDataPath() + TEMP_FILE_PATH_HOME_SCREEN_WALLPAPER;
+                               r = pCropBuffer->EncodeToFile(destPath, __imageFormat, true, 100);
+                               r = pCropBuffer->EncodeToFile(destPathHome, __imageFormat, true, 100);
+                               if (r == E_SUCCESS)
+                               {
+                                       r = SettingInfo::SetValue(SETTING_VALUE_LOCK_SCREEN_WALLPAPER, destPath);
+                                       r = SettingInfo::SetValue(SETTING_VALUE_HOME_SCREEN_WALLPAPER, destPathHome);
+                               }
+                               else if (r == E_OVERFLOW)
+                               {
+                                       MessageBox messageBox;
+                                       messageBox.Construct(L"", L"File size is too big", MSGBOX_STYLE_NONE, 3000);
+                                       int modalResult = 0;
+                                       messageBox.ShowAndWait(modalResult);
+                               }
+                       }
+                       else if (__statusValue == SET_AT_TYPE_CALLER_IMAGE)
+                       {
+                               int count = 1;
+                               int index = 0;
+                               String destFilePath;
+
+                               if (__sourceFilePath.IsEmpty() == false)
+                               {
+                                       __sourceFilePath.Reverse();
+                                       __sourceFilePath.IndexOf(FILE_EXT_SEPARATOR, 0, index);
+                                       __sourceFilePath.Reverse();
+                                       __sourceFilePath.Insert(FILE_NAME_SEPARATOR, __sourceFilePath.GetLength() - index - 1);
+                                       destFilePath.Append(__sourceFilePath);
+                                       destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
+                                       while (File::IsFileExist(destFilePath) == true)
+                                       {
+                                               count++;
+                                               destFilePath.Clear();
+                                               destFilePath.Append(__sourceFilePath);
+                                               destFilePath.Insert(count, destFilePath.GetLength() - index - 1);
+                                       }
+                               }
+                                r = pCropBuffer->EncodeToFile(destFilePath, __imageFormat, true, 100);
+                               ContentManager::ScanFile(destFilePath);
+                               Contact* pContact = null;
+                               AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
+                               Addressbook* pAddressbook = null;
+
+                               pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
+                               pContact = pAddressbook->GetContactN(__contentId);
+                               pContact->SetThumbnail(destFilePath);
+                               pAddressbook->UpdateContact(*pContact);
+
+                               delete pContact;
+                               delete pAddressbook;
+                               delete pCropBuffer;
+
+                               ArrayList* pList = new (std::nothrow) ArrayList(SingleObjectDeleter);
+                               pList->Add(new (std::nothrow) String(destFilePath));
+                               pSceneManager->GoBackward(BackwardSceneTransition(), pList);
+
+                               AppLogDebug("EXIT(%s)1", GetErrorMessage(GetLastResult()));
+                               return;
+                       }
                        delete pCropBuffer;
+                       pSceneManager->GoBackward(BackwardSceneTransition());
                }
-               pSceneManager->GoBackward(BackwardSceneTransition());
-               AppLog("Exit");
        }
        break;
        }
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
 void
@@ -242,7 +443,7 @@ ImageCropForm::OnOrientationChanged(const Control &source, OrientationStatus ori
        __isOrientationChanged = true;
        SetValue();
        __pCanvas->Clear();
-       AppLogDebug("EXIT");
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
 void
@@ -251,7 +452,7 @@ ImageCropForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Gra
        AppLogDebug("ENTER");
        __touchStart = currentPosition;
        CheckCurrentPosition(currentPosition);
-       AppLogDebug("EXIT");
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
 void
@@ -260,131 +461,399 @@ ImageCropForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graph
        AppLogDebug("ENTER");
        int deltaX = currentPosition.x - __touchStart.x;
        int deltaY = currentPosition.y - __touchStart.y;
-       switch(__pointLocation)
-       {
-       case INSIDE_TOP_RECTANGLE:
+       if (__cropMode.Equals(APPCONTROL_DATA_AUTO, false))
        {
-               if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3)))
+               switch(__pointLocation)
                {
-                       __cropBox.y += deltaY;
-                       __cropBox.height -= deltaY;
+               case INSIDE_TOP_RECTANGLE:
+               {
+                       if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 3)))
+                       {
+                               __cropBox.y += deltaY;
+                               __cropBox.height -= deltaY;
+                       }
                }
-       }
-       break;
+               break;
 
-       case INSIDE_BOTTOM_RECTANGLE:
-       {
-               if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height)
-                       && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3))
+               case INSIDE_BOTTOM_RECTANGLE:
                {
-                       __cropBox.height += deltaY;
+                       if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height)
+                               && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 3))
+                       {
+                               __cropBox.height += deltaY;
+                       }
                }
-       }
-       break;
+               break;
 
-       case INSIDE_LEFT_RECTANGLE:
-       {
-               if ((__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
+               case INSIDE_LEFT_RECTANGLE:
                {
-                       __cropBox.x += deltaX;
-                       __cropBox.width -= deltaX;
+                       if ((__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3))
+                       {
+                               __cropBox.x += deltaX;
+                               __cropBox.width -= deltaX;
+                       }
                }
-       }
-       break;
+               break;
 
-       case INSIDE_RIGHT_RECTANGLE:
-       {
-               if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width)
-                       && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3))
+               case INSIDE_RIGHT_RECTANGLE:
                {
-                       __cropBox.width += deltaX;
+                       if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width)
+                               && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 3))
+                       {
+                               __cropBox.width += deltaX;
+                       }
                }
-       }
-       break;
+               break;
 
-       case INSIDE_TOP_LEFT_RECTANGLE:
-       {
-               if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3))
-                               && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
+               case INSIDE_TOP_LEFT_RECTANGLE:
                {
-                       __cropBox.y += deltaY;
-                       __cropBox.height -= deltaY;
-                       __cropBox.x += deltaX;
-                       __cropBox.width -= deltaX;
+                       if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 3))
+                                       && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3))
+                       {
+                               __cropBox.y += deltaY;
+                               __cropBox.height -= deltaY;
+                               __cropBox.x += deltaX;
+                               __cropBox.width -= deltaX;
+                       }
                }
-       }
-       break;
+               break;
 
-       case INSIDE_TOP_RIGHT_RECTANGLE:
-       {
-               if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (CROP_RECTANGLE_HEIGHT * 3))
-                               && (__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3))
+               case INSIDE_TOP_RIGHT_RECTANGLE:
                {
-                       __cropBox.width += deltaX;
-                       __cropBox.y += deltaY;
-                       __cropBox.height -= deltaY;
+                       if ((__cropBox.y + deltaY) > __imageBox.y && deltaY < (__cropBox.height - (H_CROP_RECTANGLE * 3))
+                                       && (__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 3))
+                       {
+                               __cropBox.width += deltaX;
+                               __cropBox.y += deltaY;
+                               __cropBox.height -= deltaY;
+                       }
                }
-       }
-       break;
+               break;
 
-       case INSIDE_BOTTOM_LEFT_RECTANGLE:
-       {
-               if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3)
-                       && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (CROP_RECTANGLE_HEIGHT * 3))
+               case INSIDE_BOTTOM_LEFT_RECTANGLE:
                {
-                       __cropBox.x += deltaX;
-                       __cropBox.width -= deltaX;
-                       __cropBox.height += deltaY;
+                       if ((__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 3)
+                               && (__cropBox.x + deltaX) > __imageBox.x && deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3))
+                       {
+                               __cropBox.x += deltaX;
+                               __cropBox.width -= deltaX;
+                               __cropBox.height += deltaY;
+                       }
                }
-       }
-       break;
+               break;
 
-       case INSIDE_BOTTOM_RIGHT_RECTANGLE:
-       {
-               if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (CROP_RECTANGLE_HEIGHT * 3)
-                       && (__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (CROP_RECTANGLE_HEIGHT * 3))
+               case INSIDE_BOTTOM_RIGHT_RECTANGLE:
                {
-                       __cropBox.width += deltaX;
-                       __cropBox.height += deltaY;
+                       if ((__cropBox.x + __cropBox.width + deltaX) < (__imageBox.x + __imageBox.width) && __cropBox.width + deltaX > (H_CROP_RECTANGLE * 3)
+                               && (__cropBox.y + __cropBox.height + deltaY) < (__imageBox.y + __imageBox.height) && (__cropBox.height + deltaY) > (H_CROP_RECTANGLE * 3))
+                       {
+                               __cropBox.width += deltaX;
+                               __cropBox.height += deltaY;
+                       }
                }
-       }
-       break;
+               break;
 
-       case INSIDE_CROPBOX:
-       {
-               if ((__cropBox.x + deltaX) > __imageBox.x)
+               case INSIDE_CROPBOX:
                {
-                       __cropBox.x += deltaX;
+                       if ((__cropBox.x + deltaX) > __imageBox.x)
+                       {
+                               __cropBox.x += deltaX;
+                       }
+                       else
+                       {
+                               __cropBox.x = __imageBox.x;
+                       }
+                       if ((__cropBox.y + deltaY) > __imageBox.y)
+                       {
+                               __cropBox.y += deltaY;
+                       }
+                       else
+                       {
+                               __cropBox.y = __imageBox.y;
+                       }
+                       if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
+                       {
+                               __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
+                       }
+                       if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
+                       {
+                               __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
+                       }
                }
-               else
+               break;
+
+               default:
+                       break;
+               }
+       }
+       else if (__cropMode != APPCONTROL_DATA_AUTO)
+       {
+               if (__pointLocation == INSIDE_LEFT_RECTANGLE || __pointLocation == INSIDE_BOTTOM_LEFT_RECTANGLE
+                       || __pointLocation == INSIDE_TOP_LEFT_RECTANGLE)
                {
-                       __cropBox.x = __imageBox.x;
+                       int temp = __cropBox.height;
+                       int height = (__formHeight * (__cropBox.width - (2 * deltaX))) /__formWidth;
+                       temp = height - temp;
+                       if ((__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 3)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width)))
+                       {
+                               if (__cropBox.x + deltaX >= __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
+                                       && __cropBox.y - (temp / 2) >= __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height
+                                       && (__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 3)))
+                               {
+                                       __cropBox.x += deltaX;
+                                       __cropBox.width = __cropBox.width - (2 * deltaX);
+                                       __cropBox.height = height;
+                                       __cropBox.y = __cropBox.y - (temp / 2);
+                               }
+                               else if ((__cropBox.y + __cropBox.height) <= (__imageBox.y + __imageBox.height)
+                                               && __cropBox.width < __imageBox.width
+                                               && __cropBox.x + deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
+                               {
+                                       if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
+                                               && __cropBox.x + deltaX >= __imageBox.x)
+                                       {
+                                               __cropBox.x += deltaX;
+                                       }
+                                       else
+                                       {
+                                               __cropBox.x = __cropBox.x + (2 * deltaX);
+                                       }
+                                       __cropBox.width = __cropBox.width - (2 * deltaX);
+                                       __cropBox.height = height;
+                                       __cropBox.y = __cropBox.y - temp;
+                               }
+                               else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.width - (deltaX) <= __imageBox.width
+                                               && __cropBox.x + deltaX >= __imageBox.x && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
+                               {
+                                       if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width)
+                                       {
+                                               __cropBox.x += deltaX;
+                                       }
+                                       else
+                                       {
+                                               __cropBox.x = __cropBox.x + (2 * deltaX);
+                                       }
+                                       __cropBox.width = __cropBox.width - (2 * deltaX);
+                                       __cropBox.height = height;
+                               }
+                       }
                }
-               if ((__cropBox.y + deltaY) > __imageBox.y)
+               else if (__pointLocation == INSIDE_RIGHT_RECTANGLE || __pointLocation == INSIDE_BOTTOM_RIGHT_RECTANGLE
+                               || __pointLocation == INSIDE_TOP_RIGHT_RECTANGLE)
                {
-                       __cropBox.y += deltaY;
+                       deltaX *= -1;
+
+                       int temp = __cropBox.height;
+                       int height = (__formHeight * (__cropBox.width - (2 * deltaX))) / __formWidth;
+                       temp = height - temp;
+                       if ((__cropBox.width - (2 * deltaX) > (H_CROP_RECTANGLE * 3)) && (!(height >= __imageBox.height || (__cropBox.width - (2 * deltaX)) >= __imageBox.width)))
+                       {
+                               if (deltaX < __cropBox.width - (H_CROP_RECTANGLE * 3))
+                               {
+                                       if (__cropBox.x + deltaX > __imageBox.x && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
+                                               && __cropBox.y - (temp / 2) > __imageBox.y && __cropBox.y + __cropBox.height + (temp / 2) < __imageBox.y + __imageBox.height)
+                                       {
+                                               __cropBox.x += deltaX;
+                                               __cropBox.width = __cropBox.width - (2 * deltaX);;
+                                               __cropBox.height = height;
+                                               __cropBox.y = __cropBox.y - (temp / 2);
+                                       }
+                                       else if ((__cropBox.y + __cropBox.height + (temp / 2)) >= (__imageBox.y + __imageBox.height)
+                                                       && __cropBox.x + __cropBox.width - (2 * deltaX) <= __imageBox.x + __imageBox.width
+                                                       && __cropBox.x - deltaX >= __imageBox.x && __cropBox.y - temp >= __imageBox.y )
+                                       {
+                                               if (__cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
+                                                       && __cropBox.x + deltaX >= __imageBox.x)
+                                               {
+                                                       __cropBox.x += deltaX;
+                                               }
+                                               else
+                                               {
+                                                       __cropBox.width = __cropBox.width - (2 * deltaX);
+                                               }
+                                               __cropBox.width = __cropBox.width - (2 * deltaX);
+                                               __cropBox.height = height;
+                                               __cropBox.y = __cropBox.y - temp;
+                                       }
+                                       else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.width - (deltaX) <= __imageBox.width
+                                                       && __cropBox.x + deltaX <= __imageBox.x && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
+                                       {
+                                               if (__cropBox.x + deltaX >= __imageBox.x)
+                                               {
+                                                       __cropBox.x += deltaX;
+                                               }
+                                               else
+                                               {
+                                                       __cropBox.x = __imageBox.x;
+                                               }
+                                               __cropBox.width = __cropBox.width - (2 * deltaX);
+                                               __cropBox.height = height;
+                                       }
+                                       else if (__cropBox.y - (temp / 2) <= __imageBox.y && __cropBox.x + deltaX >= __imageBox.x
+                                                       && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
+                                                       && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
+                                       {
+                                               __cropBox.x += deltaX;
+                                               __cropBox.width = __cropBox.width - (2 * deltaX);
+                                               __cropBox.height = height;
+                                       }
+                                       else if (__cropBox.x + deltaX <= __imageBox.x && __cropBox.y - (temp / 2) >= __imageBox.y
+                                                       && __cropBox.x + __cropBox.width - deltaX <= __imageBox.x + __imageBox.width
+                                                       && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height)
+                                       {
+                                               __cropBox.width = __cropBox.width - (2 * deltaX);
+                                               __cropBox.y = __cropBox.y - (temp / 2);
+                                               __cropBox.height = height;
+                                       }
+                               }
+                       }
                }
-               else
+               else if (__pointLocation == INSIDE_TOP_RECTANGLE)
                {
-                       __cropBox.y = __imageBox.y;
+                       int temp = __cropBox.width;
+                       int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight;
+                       temp = width - temp;
+                       if (__cropBox.height - (2 * deltaY) > (__formHeight * (H_CROP_RECTANGLE * 3)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width)))
+                       {
+                               if (__cropBox.x - (temp /2 ) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
+                                       && __cropBox.y + (deltaY) > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
+                               {
+                                       __cropBox.y += deltaY;
+                                       __cropBox.height = __cropBox.height - (2 * deltaY);
+                                       __cropBox.width = width;
+                                       __cropBox.x = __cropBox.x - (temp / 2);
+                               }
+                               else if (__cropBox.x - (temp / 2) < __imageBox.x)
+                               {
+                                       if (__cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width)
+                                       {
+                                               __cropBox.width = width;
+                                       }
+                                       if (__cropBox.y + deltaY >= __imageBox.y)
+                                       {
+                                               __cropBox.y += deltaY;
+                                       }
+                                       if (__cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
+                                       {
+                                               __cropBox.height = __cropBox.height - (2 * deltaY);
+                                       }
+                               }
+                               else if (__cropBox.y + __cropBox.height - (2 * deltaY) >= __imageBox.x + __imageBox.height
+                                               && __cropBox.y + (2 * deltaY) >= __imageBox.y)
+                               {
+                                       if (__cropBox.x - temp >= __imageBox.x
+                                               && __cropBox.x + __cropBox.width + temp > __imageBox.x + __imageBox.width)
+                                       {
+                                               __cropBox.x = __cropBox.x - temp;
+                                       }
+                                       else if (__cropBox.x - temp >= __imageBox.x)
+                                       {
+                                               __cropBox.x = __cropBox.x - temp / 2;
+                                       }
+                                       if (__cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width)
+                                       {
+                                               __cropBox.width = width;
+                                       }
+                                       if (__cropBox.y + (2 * deltaY) >= __imageBox.y)
+                                       {
+                                               __cropBox.y = __cropBox.y + (2 * deltaY);
+                                               __cropBox.height = __cropBox.height - (2 * deltaY);
+                                       }
+                               }
+                               else if (__cropBox.x + __cropBox.width + (temp / 2) > __imageBox.x + __imageBox.width
+                                               && __cropBox.x - temp >= __imageBox.x && __cropBox.y + deltaY >= __imageBox.y
+                                               && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
+                               {
+                                       __cropBox.x = __cropBox.x - temp;
+                                       __cropBox.width = width;
+                                       __cropBox.y += deltaY;
+                                       __cropBox.height = __cropBox.height - (2 * deltaY);
+                               }
+                       }
                }
-               if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
+               else if (__pointLocation == INSIDE_BOTTOM_RECTANGLE)
                {
-                       __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
+                       deltaY = deltaY * (-1);
+                       int temp = __cropBox.width;
+                       int width = (__formWidth * (__cropBox.height - (2 * deltaY))) / __formHeight;
+                       temp = width - temp;
+                       if (__cropBox.height - (2 * deltaY) > (__formHeight * (H_CROP_RECTANGLE * 3)) / __formWidth && (!(__cropBox.height - (2 * deltaY) >= __imageBox.height || width >= __imageBox.width)))
+                       {
+                               if (__cropBox.x - (temp / 2) >= __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width
+                                       && __cropBox.y + deltaY > __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height)
+                               {
+                                       __cropBox.y += deltaY;
+                                       __cropBox.height = __cropBox.height - (2 * deltaY);;
+                                       __cropBox.width = width;
+                                       __cropBox.x = __cropBox.x - (temp / 2);
+                               }
+                               else if (__cropBox.y + deltaY < __imageBox.y && __cropBox.y + __cropBox.height - (2 * deltaY) < __imageBox.y + __imageBox.height
+                                               && __cropBox.x - (temp / 2) > __imageBox.x && __cropBox.x + __cropBox.width + temp < __imageBox.x + __imageBox.width)
+                               {
+                                       __cropBox.x = __cropBox.x - (temp / 2);
+                                       __cropBox.width = width;
+                                       __cropBox.height = __cropBox.height - (2 * deltaY);
+                               }
+                               else if (__cropBox.x + __cropBox.width + temp > __imageBox.x + __imageBox.width
+                                               && __cropBox.y + deltaY >= __imageBox.y && __cropBox.y + __cropBox.height + temp <= __imageBox.y + __imageBox.height
+                                               && __cropBox.x - temp >= __imageBox.x)
+                               {
+                                       __cropBox.x = __cropBox.x - temp;
+                                       __cropBox.y += deltaY;
+                                       __cropBox.width = width;
+                                       __cropBox.height = __cropBox.height - (2 * deltaY);
+                               }
+                               else if (__cropBox.x + __cropBox.width + temp >= __imageBox.x + __imageBox.width
+                                               && __cropBox.y + deltaY <= __imageBox.y && __cropBox.x - temp > __imageBox.x
+                                               && __cropBox.y + __cropBox.height + temp < __imageBox.y + __imageBox.height)
+                               {
+                                       __cropBox.x -= temp;
+                                       __cropBox.width = width;
+                                       __cropBox.height = __cropBox.height - (2 * deltaY);
+                               }
+                               else if (__cropBox.x - temp < __imageBox.x && __cropBox.x + __cropBox.width + temp <= __imageBox.x + __imageBox.width
+                                               && __cropBox.y + __cropBox.height - (2 * deltaY) <= __imageBox.y + __imageBox.height)
+                               {
+                                       if (__cropBox.y + deltaY >= __imageBox.y)
+                                       {
+                                               __cropBox.y += deltaY;
+                                       }
+                                       __cropBox.width = width;
+                                       __cropBox.height = __cropBox.height - (2 * deltaY);
+                               }
+                       }
                }
-               if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
+               else if (__pointLocation == INSIDE_CROPBOX)
                {
-                       __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
+                       if ((__cropBox.x + deltaX) > __imageBox.x)
+                       {
+                               __cropBox.x += deltaX;
+                       }
+                       else
+                       {
+                               __cropBox.x = __imageBox.x;
+                       }
+                       if ((__cropBox.y + deltaY) > __imageBox.y)
+                       {
+                               __cropBox.y += deltaY;
+                       }
+                       else
+                       {
+                               __cropBox.y = __imageBox.y;
+                       }
+                       if ((__cropBox.x + __cropBox.width + deltaX) > (__imageBox.x + __imageBox.width))
+                       {
+                               __cropBox.x = __imageBox.x + __imageBox.width - __cropBox.width;
+                       }
+                       if ((__cropBox.y + __cropBox.height + deltaY) > (__imageBox.y + __imageBox.height))
+                       {
+                               __cropBox.y = __imageBox.y + __imageBox.height - __cropBox.height;
+                       }
                }
        }
-       break;
-
-       default:
-               break;
-       }
        RequestRedraw(false);
        __touchStart = currentPosition;
-       AppLogDebug("EXIT");
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
 void
@@ -392,50 +861,50 @@ ImageCropForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Gr
 {
        AppLogDebug("ENTER");
        __pointLocation = OUTSIDE_CROPBOX;
-       AppLogDebug("EXIT");
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }
 
 void
 ImageCropForm::CheckCurrentPosition(const Point currentPosition)
 {
        AppLogDebug("ENTER");
-       if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (CROP_RECTANGLE_HEIGHT / 2))
-               && currentPosition.y >  (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + (CROP_RECTANGLE_HEIGHT / 2)))
+       if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (H_CROP_RECTANGLE / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (H_CROP_RECTANGLE / 2))
+               && currentPosition.y >  (__cropBox.y - (H_CROP_RECTANGLE / 2)) && currentPosition.y < (__cropBox.y + (H_CROP_RECTANGLE / 2)))
        {
                __pointLocation = INSIDE_TOP_RECTANGLE;
        }
-       else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
-               && currentPosition.y >  ((__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (CROP_RECTANGLE_HEIGHT / 2)))
+       else if (currentPosition.x > (__cropBox.x - (H_CROP_RECTANGLE / 2)) && currentPosition.x < (__cropBox.x + (H_CROP_RECTANGLE / 2))
+               && currentPosition.y >  ((__cropBox.y + __cropBox.height / 2) - (H_CROP_RECTANGLE / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (H_CROP_RECTANGLE / 2)))
        {
                __pointLocation = INSIDE_LEFT_RECTANGLE;
        }
-       else if (currentPosition.x > (__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
-               && currentPosition.y > ((__cropBox.y + __cropBox.height / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (CROP_RECTANGLE_HEIGHT / 2)))
+       else if (currentPosition.x > (__cropBox.x + __cropBox.width - (H_CROP_RECTANGLE / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (H_CROP_RECTANGLE / 2))
+               && currentPosition.y > ((__cropBox.y + __cropBox.height / 2) - (H_CROP_RECTANGLE / 2)) && currentPosition.y < ((__cropBox.y + __cropBox.height / 2) + (H_CROP_RECTANGLE / 2)))
        {
                __pointLocation = INSIDE_RIGHT_RECTANGLE;
        }
-       else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (CROP_RECTANGLE_HEIGHT / 2))
-               && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
+       else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (H_CROP_RECTANGLE / 2)) && currentPosition.x < ((__cropBox.x + __cropBox.width / 2) + (H_CROP_RECTANGLE / 2))
+               && currentPosition.y > (__cropBox.y + __cropBox.height - (H_CROP_RECTANGLE / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (H_CROP_RECTANGLE / 2)))
        {
                __pointLocation = INSIDE_BOTTOM_RECTANGLE;
        }
-       else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
-                        && currentPosition.y > (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y +(CROP_RECTANGLE_HEIGHT / 2)))
+       else if (currentPosition.x > (__cropBox.x - (H_CROP_RECTANGLE / 2)) && currentPosition.x < (__cropBox.x + (H_CROP_RECTANGLE / 2))
+                        && currentPosition.y > (__cropBox.y - (H_CROP_RECTANGLE / 2)) && currentPosition.y < (__cropBox.y +(H_CROP_RECTANGLE / 2)))
        {
                __pointLocation = INSIDE_TOP_LEFT_RECTANGLE;
        }
-       else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
-                       && currentPosition.y > (__cropBox.y - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y +(CROP_RECTANGLE_HEIGHT / 2)))
+       else if (currentPosition.x > ((__cropBox.x + __cropBox.width / 2) - (H_CROP_RECTANGLE / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (H_CROP_RECTANGLE / 2))
+                       && currentPosition.y > (__cropBox.y - (H_CROP_RECTANGLE / 2)) && currentPosition.y < (__cropBox.y +(H_CROP_RECTANGLE / 2)))
        {
                __pointLocation = INSIDE_TOP_RIGHT_RECTANGLE;
        }
-       else if (currentPosition.x > (__cropBox.x + __cropBox.width - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (CROP_RECTANGLE_HEIGHT / 2))
-                       && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
+       else if (currentPosition.x > (__cropBox.x + __cropBox.width - (H_CROP_RECTANGLE / 2)) && currentPosition.x < (__cropBox.x + __cropBox.width + (H_CROP_RECTANGLE / 2))
+                       && currentPosition.y > (__cropBox.y + __cropBox.height - (H_CROP_RECTANGLE / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (H_CROP_RECTANGLE / 2)))
        {
                __pointLocation = INSIDE_BOTTOM_RIGHT_RECTANGLE;
        }
-       else if (currentPosition.x > (__cropBox.x - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.x < (__cropBox.x + (CROP_RECTANGLE_HEIGHT / 2))
-                       && currentPosition.y > (__cropBox.y + __cropBox.height - (CROP_RECTANGLE_HEIGHT / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (CROP_RECTANGLE_HEIGHT / 2)))
+       else if (currentPosition.x > (__cropBox.x - (H_CROP_RECTANGLE / 2)) && currentPosition.x < (__cropBox.x + (H_CROP_RECTANGLE / 2))
+                       && currentPosition.y > (__cropBox.y + __cropBox.height - (H_CROP_RECTANGLE / 2)) && currentPosition.y < (__cropBox.y + __cropBox.height + (H_CROP_RECTANGLE / 2)))
        {
                __pointLocation = INSIDE_BOTTOM_LEFT_RECTANGLE;
        }
@@ -447,7 +916,7 @@ ImageCropForm::CheckCurrentPosition(const Point currentPosition)
        {
                __pointLocation = OUTSIDE_CROPBOX;
        }
-       AppLogDebug("EXIT");
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
        return;
 }
 
@@ -458,49 +927,36 @@ ImageCropForm::SetValue(void)
        int prevWidth = __imageBox.width;
        int prevImageboxX = __imageBox.x;
        int prevImageBoxY = __imageBox.y;
-       int indicatorBarHeight = 0;
-
-       if (GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
+       if (GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT)
        {
-               indicatorBarHeight = 21;
+               __formHeight = Form::GetBounds().height;
+               __formWidth = Form::GetBounds().width;
        }
-       else
+       else if (GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
        {
-               indicatorBarHeight = 60;
+               __formHeight = Form::GetBounds().width;
+               __formWidth = Form::GetBounds().height;
        }
 
-       if (__imageWidth > GetClientAreaBounds().width && __imageHeight > GetClientAreaBounds().height)
+       float clientAreaRatio = (GetClientAreaBoundsF().height - H_FOOTER_PANEL) / GetClientAreaBoundsF().width;
+       if (__imageWidth >= GetClientAreaBounds().width || __imageHeight > (GetClientAreaBounds().height - H_FOOTER_PANEL))
        {
-               if (__imageHeight > __imageWidth)
+               float imageRatio = __imageHeight / (float) __imageWidth;
+               if (imageRatio < clientAreaRatio)
                {
-                       __imageBox.height = GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT;
-                       __imageBox.width = (__imageWidth * GetClientAreaBounds().height) / __imageHeight;
-                       __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
-                       __imageBox.y = indicatorBarHeight;
+                       __imageBox.width = GetClientAreaBounds().width;
+                       __imageBox.height = (__imageHeight * __imageBox.width) / __imageWidth;
+                       __imageBox.x = GetClientAreaBounds().x;
+                       __imageBox.y = GetClientAreaBounds().y + ((GetClientAreaBounds().height - H_FOOTER_PANEL) - __imageBox.height) / 2;
                }
                else
                {
-                       __imageBox.width = GetClientAreaBounds().width;
-                       __imageBox.height = (GetClientAreaBounds().width * __imageHeight) / __imageWidth;
-                       __imageBox.x = 0;
-                       __imageBox.y = (GetClientAreaBounds().height - __imageBox.height) / 2;
+                       __imageBox.height = GetClientAreaBounds().height - H_FOOTER_PANEL;
+                       __imageBox.width = (__imageWidth * __imageBox.height) / __imageHeight;
+                       __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
+                       __imageBox.y = GetClientAreaBounds().y;
                }
        }
-       else if (__imageWidth > GetClientAreaBounds().width)
-       {
-               __imageBox.width = GetClientAreaBounds().width;
-               __imageBox.height = (__imageHeight * GetClientAreaBounds().width) / __imageWidth;
-               __imageBox.x = 0;
-               __imageBox.y = (GetClientAreaBounds().height - __imageBox.height) / 2;
-
-       }
-       else if (__imageHeight > GetClientAreaBounds().height)
-       {
-               __imageBox.height = GetClientAreaBounds().height - FOOTER_PANEL_HEIGHT;
-               __imageBox.width = (__imageWidth * GetClientAreaBounds().height) / __imageHeight;
-               __imageBox.x = (GetClientAreaBounds().width - __imageBox.width) / 2;
-               __imageBox.y = indicatorBarHeight;
-       }
        else
        {
                __imageBox.height = __imageHeight;
@@ -510,17 +966,27 @@ ImageCropForm::SetValue(void)
        }
        if (__isOrientationChanged == false)
        {
-               if (__imageHeight >= __imageWidth)
+               if (__imageBox.height > __imageBox.width)
                {
-                       __cropBox.height = __imageBox.height / 2;
-                       __cropBox.width = __imageBox.width / 2;
-                       __cropBox.y =  __imageBox.y + (__imageBox.height / 4);
-                       __cropBox.x = __imageBox.x + (__imageBox.width / 4);
+                       __cropBox.width = (2 * __imageBox.width) / 3;
+                       __cropBox.height = (__formHeight * __cropBox.width / __formWidth);
+                       if (__cropBox.height > __imageBox.height)
+                       {
+                               __cropBox.height = (2 * __imageBox.height) / 3;
+                               __cropBox.width = (__cropBox.height * __formWidth) / __formHeight;
+                       }
+                       __cropBox.y =  __imageBox.y + (__imageBox.height - __cropBox.height) / 2;
+                       __cropBox.x = __imageBox.x + (__imageBox.width - __cropBox.width) / 2;
                }
                else
                {
-                       __cropBox.height = (2 * __imageBox.height) / 3;
-                       __cropBox.width = (2 * __imageBox.width) / 3;
+                       __cropBox.height = (2 *__imageBox.height) / 3;
+                       __cropBox.width = (__formWidth * __cropBox.height / __formHeight);
+                       if (__cropBox.width > __imageBox.width)
+                       {
+                               __cropBox.width = (2 * __imageBox.width) / 3;
+                               __cropBox.height = (__formHeight * __cropBox.width) / __formWidth;
+                       }
                        __cropBox.y = __imageBox.y + (__imageBox.height - __cropBox.height) / 2;
                        __cropBox.x = __imageBox.x + (__imageBox.width - __cropBox.width) / 2;
                }
@@ -538,5 +1004,11 @@ ImageCropForm::SetValue(void)
        }
        __pCanvas = GetCanvasN();
        __pCanvas->SetForegroundColor(CROP_BOX_RECTANGLE_COLOR);
+}
 
+void ImageCropForm::OnFormFileEventOccuered(const int index, const unsigned long eventId)
+{
+       AppLogDebug(" ENTER");
+       UiApp::GetInstance()->Terminate();
+       AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
 }