fixed UTS issues in OptionMenu
authorSyed Khaja Moinuddin <moinuddin.s@samsung.com>
Sat, 8 Jun 2013 16:28:21 +0000 (21:58 +0530)
committersriram.k <sriram.k@samsung.com>
Sat, 8 Jun 2013 19:03:18 +0000 (00:33 +0530)
Signed-off-by: Syed Khaja Moinuddin <moinuddin.s@samsung.com>
Change-Id: I1ad9321c8563b1cd0a1e63471ad1e789014baafd

src/ui/controls/FUiCtrl_OptionMenuItem.cpp
src/ui/controls/FUiCtrl_OptionMenuModel.cpp
src/ui/controls/FUiCtrl_OptionMenuPresenter.cpp

index e61334b..9018b83 100644 (file)
@@ -215,10 +215,10 @@ _OptionMenuItem::InsertSubItemAt(_OptionMenuItem& subItem, int index)
                }
        }
 
-       SysTryReturn(NID_UI_CTRL, (index >= 0 && index < MAX_SUB_ITEM_COUNT), null, E_OUT_OF_RANGE,
-                                                       "[E_OUT_OF_RANGE] The specified index (%d) is out of range.", index);
-       SysTryReturn(NID_UI_CTRL, (index <= __pSubItems->GetCount()), null, E_SYSTEM,
-                                                       "[E_SYSTEM]  A system error has occurred. The specified index (%d) is greater than the available items count.", index);
+       SysTryReturn(NID_UI_CTRL, (index >= 0 && index < MAX_SUB_ITEM_COUNT), E_INVALID_ARG, E_INVALID_ARG,
+                                                       "[E_INVALID_ARG] The specified index (%d) is out of range.", index);
+       SysTryReturn(NID_UI_CTRL, (index <= __pSubItems->GetCount()), E_INVALID_ARG, E_INVALID_ARG,
+                                                       "[E_INVALID_ARG]  The specified index (%d) is greater than the available items count.", index);
 
        return __pSubItems->InsertAt(subItem, index);
 }
index e2f23e4..f31e97e 100644 (file)
@@ -105,15 +105,9 @@ _OptionMenuModel::AddItem(_OptionMenuItem* pItem, int mainIndex)
                SysTryReturn(NID_UI_CTRL, (pItem != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
                r = pMainItem->InsertSubItemAt(*pItem, pMainItem->GetSubItemCount());
-               if (r != E_SUCCESS)
-               {
-                       delete pItem;
-                       SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
-                       return r;
-               }
-       }
+       }
 
-        return E_SUCCESS;
+        return r;
 }
 
 result
@@ -137,15 +131,10 @@ _OptionMenuModel::InsertItem( _OptionMenuItem* pItem, int mainIndex, int subInde
                SysTryReturn(NID_UI_CTRL, (pItem != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
                r = pMainItem->InsertSubItemAt(*pItem, subIndex);
-               if (r != E_SUCCESS)
-               {
-                       delete pItem;
-                       SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
-                       return r;
-               }
+
        }
 
-       return E_SUCCESS;
+    return r;
 }
 
 result
@@ -174,15 +163,10 @@ _OptionMenuModel::SetItem(_OptionMenuItem* pItem, int mainIndex, int subIndex)
                 SysTryReturn(NID_UI_CTRL, (pItem != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
                 r = pMainItem->SetSubItemAt(*pItem, subIndex);
-                if (r != E_SUCCESS)
-                {
-                        delete pItem;
-                        SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
-                        return r;
-                }
+
         }
 
-        return E_SUCCESS;
+     return r;
 }
 
 result
index f5a7fdf..387403d 100644 (file)
@@ -276,6 +276,8 @@ _OptionMenuPresenter::AddItem(const String& text, int actionId, const Bitmap* no
 result
 _OptionMenuPresenter::AddSubItem(int mainIndex, const String& text, int actionId)
 {
+    SysTryReturn(NID_UI_CTRL, mainIndex >=0 && mainIndex < __pModel->GetItemCount(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", mainIndex);
+
     _OptionMenuItem* pItem = CreateItem(text, actionId, null, null, null);
     SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
@@ -328,6 +330,9 @@ _OptionMenuPresenter::InsertItem(int mainIndex, const String& text, int actionId
 result
 _OptionMenuPresenter::InsertSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
 {
+    SysTryReturn(NID_UI_CTRL, mainIndex >=0 && mainIndex < __pModel->GetItemCount(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", mainIndex);
+    SysTryReturn(NID_UI_CTRL, subIndex >=0 && subIndex <= __pModel->GetSubItemCount(mainIndex), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid subIndex %d.", subIndex);
+
     _OptionMenuItem* pItem = CreateItem(text, actionId, null, null, null);
     SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
@@ -340,6 +345,9 @@ _OptionMenuPresenter::InsertSubItemAt(int mainIndex, int subIndex, const String&
 result
 _OptionMenuPresenter::SetSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
 {
+    SysTryReturn(NID_UI_CTRL, mainIndex >=0 && mainIndex < __pModel->GetItemCount(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", mainIndex);
+    SysTryReturn(NID_UI_CTRL, subIndex >=0 && subIndex < __pModel->GetSubItemCount(mainIndex), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid subIndex %d.", subIndex);
+
     _OptionMenuItem* pItem = CreateItem(text, actionId, null, null, null);
     SysTryReturn(NID_UI_CTRL, pItem != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient.");
 
@@ -352,6 +360,9 @@ _OptionMenuPresenter::SetSubItemAt(int mainIndex, int subIndex, const String& te
 result
 _OptionMenuPresenter::RemoveSubItemAt(int mainIndex, int subIndex)
 {
+    SysTryReturn(NID_UI_CTRL, mainIndex >=0 && mainIndex < __pModel->GetItemCount(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", mainIndex);
+    SysTryReturn(NID_UI_CTRL, subIndex >=0 && subIndex < __pModel->GetSubItemCount(mainIndex), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid subIndex %d.", subIndex);
+
        result r = __pModel->RemoveItem(mainIndex, subIndex);
        SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
 
@@ -361,6 +372,7 @@ _OptionMenuPresenter::RemoveSubItemAt(int mainIndex, int subIndex)
 int
 _OptionMenuPresenter::GetSubItemCount(int mainIndex) const
 {
+    SysTryReturn(NID_UI_CTRL, mainIndex >=0 && mainIndex < __pModel->GetItemCount(), -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", mainIndex);
        return __pModel->GetSubItemCount(mainIndex);
 }
 
@@ -389,6 +401,7 @@ result
 _OptionMenuPresenter::SetItem(int index, const String& text, int actionId, const Bitmap* normalBitmap,
                                 const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
 {
+    SysTryReturn(NID_UI_CTRL, index >=0 && index < __pModel->GetItemCount(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", index);
     result r = __pOptionMenu->GetScrollPanel()->DetachChild(*__pModel->GetItem(index));
     SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to detach item.");
 
@@ -409,11 +422,8 @@ _OptionMenuPresenter::SetItem(int index, const String& text, int actionId, const
 result
 _OptionMenuPresenter::DeleteItem(int index)
 {
-       if (__pOptionMenu->GetItemCount() <= 0)
-       {
-               SysLogException(NID_UI_CTRL, E_INVALID_STATE, "Invalid argument.");
-               return E_INVALID_STATE;
-       }
+    SysTryReturn(NID_UI_CTRL, (index < __pOptionMenu->GetItemCount()), E_INVALID_ARG, E_INVALID_ARG,
+            "[E_INVALID_ARG] The specified main index (%d) is invalid.", index);
 
        result r = __pOptionMenu->GetScrollPanel()->DetachChild(*__pModel->GetItem(index));
        SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to detach item.");
@@ -427,11 +437,8 @@ _OptionMenuPresenter::DeleteItem(int index)
 result
 _OptionMenuPresenter::DeleteItemAll(void)
 {
-       if (__pOptionMenu->GetItemCount() <= 0)
-       {
-               SysLogException(NID_UI_CTRL, E_INVALID_STATE, "Invalid argument.");
-               return E_INVALID_STATE;
-       }
+    SysTryReturn(NID_UI_CTRL, (__pOptionMenu->GetItemCount() > 0), E_SYSTEM, E_SYSTEM,
+            "[E_SYSTEM] A system error occurred. No items exists.");
 
        __pOptionMenu->GetScrollPanel()->DetachAllChildren();
 
@@ -445,8 +452,7 @@ int
 _OptionMenuPresenter::CalculateShowItemCount(void)
 {
        int itemMaxCount = 0;
-        _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
-       GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, orientation, itemMaxCount);
+       GET_SHAPE_CONFIG(CONTEXTMENU::ITEM_MAX_COUNT, _CONTROL_ORIENTATION_PORTRAIT, itemMaxCount);
 
        int maxVisibleCount = __pOptionMenu->GetShowItemCount();
 
@@ -487,8 +493,7 @@ _OptionMenuPresenter::CalculateRect(void)
        if (__pOptionMenu->GetLayout() == _CONTROL_ORIENTATION_LANDSCAPE)
        {
                screen.SetSize(screen.height, screen.width);
-       }
-
+    }
        AdjustItemLayout();
 
        bodyRect.width = __layoutSize.width + bodyLeftMargin + bodyRightMargin;
@@ -693,9 +698,9 @@ _OptionMenuPresenter::Draw(void)
             screenSize.width = temp.height;
             screenSize.height = temp.width;
         }
-        //int maxItem = 0;
-        //GET_SHAPE_CONFIG(OPTIONMENU::MAX_OPTIONMENU_SHOW_ITEM, orientation, maxItem);
-        //__pOptionMenu->SetPropertyMaxVisibleItemsCount(maxItem);
+        int maxItem = 0;
+        GET_SHAPE_CONFIG(OPTIONMENU::MAX_OPTIONMENU_SHOW_ITEM, orientation, maxItem);
+        __pOptionMenu->SetPropertyMaxVisibleItemsCount(maxItem);
 
                Tizen::Graphics::FloatRectangle bodyRect = __pOptionMenu->GetBodyRect();