[OptionMenu] Added logic to modify item bounds in SetItem and RemoveItem apis.
authorsr.shashank <sr.shashank@samsung.com>
Thu, 4 Jul 2013 06:48:37 +0000 (12:18 +0530)
committersr.shashank <sr.shashank@samsung.com>
Fri, 5 Jul 2013 13:30:37 +0000 (19:00 +0530)
Change-Id: Ic54d4ef34e3e8024e97c9574cffcebee550d474c
Signed-off-by: sr.shashank <sr.shashank@samsung.com>
src/ui/controls/FUiCtrl_OptionMenuPresenter.cpp
src/ui/inc/FUiCtrl_OptionMenuPresenter.h

index cccde7a..da80ff1 100755 (executable)
@@ -423,52 +423,71 @@ _OptionMenuPresenter::GetSubItemActionIdAt(int mainIndex, int subIndex) const
        return pItem->GetActionId();
 }
 
-result
-_OptionMenuPresenter::SetItem(int index, const String& text, int actionId, const Bitmap* normalBitmap, const Bitmap* pPressedBitmap, const Bitmap* pHighlightedBitmap)
+FloatDimension
+_OptionMenuPresenter::GetMainItemMaximumWidth(void)
 {
-       SysTryReturn(NID_UI_CTRL, index >=0 && index < __pModel->GetItemCount(), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid mainIndex %d.", index);
-
-       result r = __pModel->SetItemAt(index, text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap, __itemFontSize);
-       SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       float labelLeftMargin = 0.0f;
+       FloatDimension itemSize(0.0f, 0.0f);
+       FloatDimension maxItemTextArea(0.0f, 0.0f);
 
-       _OptionMenuItem* pItem = __pModel->GetItem(index);
+       GET_SHAPE_CONFIG(LABEL::LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, labelLeftMargin);
 
-       if (pItem == null)
+       for (int i = 0; i < __pModel->GetItemCount() - 1; i++)
        {
-               SysLog(NID_UI_CTRL, "Item is null.");
-               return r;
-       }
-
-       float bitmapWidth = 0.0f;
-       FloatDimension textArea(0.0f, 0.0f);
-       FloatDimension itemSize(0.0f, 0.0f);
+               FloatDimension currentItemTextArea(0.0f, 0.0f);
+               _OptionMenuItem* pItem = null;
 
-       __pFont->GetTextExtent(text, text.GetLength(), textArea);
+               pItem = __pModel->GetItem(i);
+               SysTryReturn(NID_UI_CTRL, pItem != null, FloatDimension(0.0f, 0.0f), E_SYSTEM, "[E_SYSTEM] A system error occurred. Unable to get the item.");
 
-       float labelLeftMargin = 0.0f;
+               String itemText = pItem->GetText();
 
-       GET_SHAPE_CONFIG(LABEL::LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, labelLeftMargin);
+               __pFont->GetTextExtent(itemText, itemText.GetLength(), currentItemTextArea);
 
-       textArea.width  += 2.0f * labelLeftMargin;
-       itemSize.width =  __leftMargin + textArea.width + __rightMargin;
+               if (currentItemTextArea.width > maxItemTextArea.width)
+               {
+                       maxItemTextArea = currentItemTextArea;
+               }
 
-       if (pItem->GetType() == OPTION_MENU_ITEM_DRAWING_TYPE_BITMAP)
-       {
-               bitmapWidth = __itemBitmapWidth;
-               itemSize.width =  itemSize.width + bitmapWidth;
+               if (pItem->GetType() == OPTION_MENU_ITEM_DRAWING_TYPE_BITMAP)
+               {
+                       itemSize.width =  itemSize.width + __itemBitmapWidth;
+               }
        }
 
+       maxItemTextArea.width  += 2.0f * labelLeftMargin;
+       itemSize.width +=  __leftMargin + maxItemTextArea.width + __rightMargin;
+
        itemSize.width = itemSize.width < __itemMinWidth ? __itemMinWidth : itemSize.width;
 
        if (itemSize.width > __itemMaxWidth)
        {
-               textArea.width -= itemSize.width - __itemMaxWidth;
                itemSize.width = __itemMaxWidth;
        }
 
-       pItem->SetSize(itemSize);
+       return itemSize;
+}
+
+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);
 
-       __itemWidth = __itemWidth < itemSize.width ? itemSize.width : __itemWidth;
+       result r = __pModel->SetItemAt(index, text, actionId, normalBitmap, pPressedBitmap, pHighlightedBitmap, __itemFontSize);
+       SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+       _OptionMenuItem* pItem = __pModel->GetItem(index);
+
+       if (pItem == null)
+       {
+               SysLog(NID_UI_CTRL, "Item is null.");
+               return r;
+       }
+
+       FloatDimension maxItemTextArea = GetMainItemMaximumWidth();
+       pItem->SetSize(maxItemTextArea);
+
+       __itemWidth = maxItemTextArea.width;
 
        return r;
 }
@@ -485,6 +504,10 @@ _OptionMenuPresenter::DeleteItem(int index)
        r = __pModel->RemoveItem(index);
        SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to delete item.");
 
+       FloatDimension maxItemTextArea = GetMainItemMaximumWidth();
+
+       __itemWidth = maxItemTextArea.width;
+
        return r;
 }
 
index 7e988e6..cc7b015 100644 (file)
@@ -89,8 +89,8 @@ public:
        virtual result CalculateWindowRect(void);
        virtual result ApplyColorProperty(void);
        int GetSubItemIndexFromActionId(int actionId) const;
-
        int GetSubItemActionIdAt(int mainIndex, int subIndex) const;
+       Tizen::Graphics::FloatDimension GetMainItemMaximumWidth(void);
 
        virtual _UiTouchEventDelivery OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchinfo);
        virtual _UiTouchEventDelivery OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchinfo);