_OptionMenu::_OptionMenu(void)
: __pOptionMenuPresenter(null)
, __showItemCount(0)
- , __showItemMaxCount(0)
, __isAttachedToMainTree(false)
- , __ownerInputEnableState(false)
+ , __isMaxVisibleCountSet(false)
+ , __isFocused(false)
+ , __currentFocusedIndex(-1)
, __windowRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
, __bodyRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
, __itemRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
pOptionMenu->AttachChild(*(pOptionMenu->__pScrollPanel));
}
- GET_SHAPE_CONFIG(OPTIONMENU::MAX_VISIBLE_ITEM_COUNT, pOptionMenu->GetOrientation(), pOptionMenu->__showItemMaxCount);
-
-
return pOptionMenu;
CATCH:
}
bool
+_OptionMenu::OnFocusGained(const _Control &source)
+{
+ __currentFocusedIndex = 0;
+ __isFocused = false;
+ return true;
+}
+
+bool
+_OptionMenu::OnFocusLost(const _Control &source)
+{
+ __isFocused = false;
+ return true;
+}
+
+void
+_OptionMenu::OnDrawFocus(void)
+{
+ if (!__isFocused)
+ {
+ GetScrollPanel()->ScrollToTop();
+ __isFocused = true;
+ __currentFocusedIndex = 0;
+ __pOptionMenuPresenter->DrawFocus(__currentFocusedIndex);
+ }
+ return;
+}
+
+void
+_OptionMenu::OnFocusModeStateChanged(void)
+{
+ __isFocused = false;
+ Invalidate(true);
+}
+
+bool
+_OptionMenu::OnKeyPressed(const _Control &source, const _KeyInfo &keyInfo)
+{
+ if (&source != this)
+ {
+ return false;
+ }
+
+ _KeyCode keyCode = keyInfo.GetKeyCode();
+
+ int count = GetMaximumVisibleItemsCount();
+ int totalItemCount = GetItemCount();
+ int height;
+ int dividerHeight;
+
+ GET_SHAPE_CONFIG(OPTIONMENU::ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, height);
+ GET_SHAPE_CONFIG(CONTEXTMENU::LIST_DIVIDER_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, dividerHeight);
+
+ if (!__isFocused)
+ {
+ return false;
+ }
+
+ switch (keyCode)
+ {
+ case _KEY_DOWN:
+ if (__currentFocusedIndex < totalItemCount - 1)
+ {
+ if (__currentFocusedIndex < count - 1)
+ {
+ __currentFocusedIndex++;
+ }
+ else
+ {
+ int pos = GetScrollPanel()->GetScrollPosition();
+ GetScrollPanel()->SetScrollPosition(pos + height + 2 * dividerHeight);
+ __currentFocusedIndex++;
+ }
+ }
+ else
+ {
+ __currentFocusedIndex = totalItemCount - 1;
+ }
+ break;
+
+ case _KEY_UP:
+ if (__currentFocusedIndex > 0)
+ {
+ if (__currentFocusedIndex < count - 1)
+ {
+ __currentFocusedIndex--;
+ }
+ else
+ {
+ int pos = GetScrollPanel()->GetScrollPosition();
+ GetScrollPanel()->SetScrollPosition(pos - height - 2 * dividerHeight);
+ __currentFocusedIndex--;
+ }
+ }
+ else
+ {
+ __currentFocusedIndex = 0;
+ }
+ break;
+
+ case _KEY_ENTER:
+ __pOptionMenuPresenter->OnEnterKeyPressed(__currentFocusedIndex);
+ return true;
+
+ default :
+ return true;
+ }
+ __pOptionMenuPresenter->DrawFocus(__currentFocusedIndex);
+
+ return true;
+}
+
+bool
_OptionMenu::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
{
_KeyCode keyCode = keyInfo.GetKeyCode();
_Form* pForm = pFrame->GetCurrentForm();
pForm != null ? SetOwner(pForm) : SetOwner(pFrame);
- GET_SHAPE_CONFIG(OPTIONMENU::MAX_VISIBLE_ITEM_COUNT, __layout, __showItemMaxCount);
}
else
{
__isAttachedToMainTree = false;
+ __pScrollPanel->ScrollToTop();
+
return _Window::OnDetachingFromMainTree();
}
result
-_OptionMenu::ShowSubMenu(int mainIndex, _OptionMenuItem& item, FloatPoint touchPosition)
+_OptionMenu::ShowSubMenu(int mainIndex, _OptionMenuItem& item)
{
if (__pSubMenu != null)
{
GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, itemHeight);
// FloatRectangle itemBounds = __pOptionMenuPresenter->GetItemBounds(mainIndex);
- _OptionMenuItem* pMainItem = __pOptionMenuPresenter->GetItemFromPosition(touchPosition).pOptionMenuItem;
- FloatRectangle itemBounds = pMainItem->GetBoundsF();
+ //_OptionMenuItem* pMainItem = __pOptionMenuPresenter->GetItemFromPosition(touchPosition).pOptionMenuItem;
+ FloatRectangle itemBounds = item.GetBoundsF();
itemBounds.height = itemHeight;
float scrollPosition = __pScrollPanel->GetScrollPosition();
FloatPoint anchorPosition(GetBoundsF().x + itemBounds.x + itemBounds.width,
}
int
-_OptionMenu::GetShowItemCount(void) const
+_OptionMenu::GetMaximumVisibleItemsCount(void) const
{
Variant count = GetProperty("maxVisibleItemsCount");
return count.ToInt();
}
-int
-_OptionMenu::GetShowItemMaxCount(void) const
-{
- return __showItemMaxCount;
-}
-
result
_OptionMenu::SetShowItemCount(int count)
{
result r = SetPropertyMaxVisibleItemsCount(maxItemsCount);
SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+ __isMaxVisibleCountSet = true;
+
__pOptionMenuPresenter->CalculateShowItemCount();
__pOptionMenuPresenter->CalculateWindowRect();
void
_OptionMenu::OnChangeLayout(_ControlOrientation orientation)
{
- GET_SHAPE_CONFIG(OPTIONMENU::MAX_VISIBLE_ITEM_COUNT, orientation, __showItemMaxCount);
-
- __pOptionMenuPresenter->CalculateShowItemCount();
- __pOptionMenuPresenter->CalculateWindowRect();
+ if (!__isMaxVisibleCountSet)
+ {
+ GET_SHAPE_CONFIG(OPTIONMENU::MAX_VISIBLE_ITEM_COUNT, orientation, __showItemCount);
+ }
if (__isAttachedToMainTree == true)
{
}
__layout = orientation;
+
+ __pOptionMenuPresenter->CalculateShowItemCount();
+ __pOptionMenuPresenter->CalculateWindowRect();
}
void
result
_OptionMenuItem::SetText(const String& text)
{
- __text = text;
+ __text = text;
return E_SUCCESS;
}
{
DrawArrow();
}
-
}
void
_OptionMenuItem::DrawItemBitmap(void)
{
-
if (IsSelected())
{
__pBitmapLabel->SetBackgroundBitmap(*__pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_PRESSED]);
__pBitmapLabel->SetBackgroundBitmap(*__pBitmap[OPTION_MENU_ITEM_DRAWING_STATUS_NORMAL]);
}
- FloatRectangle bounds = __pTextLabel->GetBoundsF();
+ FloatRectangle bounds = __pTextLabel->GetBoundsF();\r
+ FloatRectangle itemBounds = GetBoundsF();\r
+
+ float bitmapWidth = (__type == OPTION_MENU_ITEM_DRAWING_TYPE_BITMAP) ? __pBitmapLabel->GetBoundsF().width : 0.0f;\r
+ float textLabelX = __leftMargin + bitmapWidth;\r
+
+ bounds.x = textLabelX;\r
+ bounds.width = itemBounds.width;\r
- float bitmapWidth = (__type == OPTION_MENU_ITEM_DRAWING_TYPE_BITMAP) ? __pBitmapLabel->GetBoundsF().width : 0.0f;
- float textLabelX = __leftMargin + bitmapWidth;
+ bounds.width = bounds.width - __textLeftMargin - __textRightMargin - bitmapWidth;\r
- bounds.x = textLabelX;
- __pTextLabel->SetBounds(bounds);
- __pBitmapLabel->Invalidate();
- __pTextLabel->Invalidate();
+ if (HasSubItem())\r
+ {\r
+ bounds.width = bounds.width - __arrowLeftMargin - __arrowRightMargin;\r
+ }\r
+\r
+ __pTextLabel->SetBounds(bounds);\r
+ __pBitmapLabel->Invalidate();\r
+ __pTextLabel->Invalidate();\r
}
void
int
_OptionMenuPresenter::CalculateShowItemCount(void)
{
- return __pOptionMenu->GetShowItemCount();
+ return __pOptionMenu->GetMaximumVisibleItemsCount();
}
result
{
FloatRectangle windowRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // OptionMenu window itself
FloatRectangle bodyRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // bg surronding showing items, relative to window
- // FloatRectangle arrowRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // relative to window
FloatRectangle itemRect = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f); // relative to window
float bodyTopMargin = __topMargin;
float bodyLeftMargin = __leftMargin;
float bodyRightMargin = __rightMargin;
- FloatPoint anchorPosition(0.0f, 0.0f);
FloatDimension screen = _ControlManager::GetInstance()->GetScreenSizeF();
if (__pOptionMenu->GetLayout() == _CONTROL_ORIENTATION_LANDSCAPE)
{
screen.SetSize(screen.height, screen.width);
}
+
AdjustItemLayout();
bodyRect.width = __layoutSize.width + bodyLeftMargin + bodyRightMargin;
bodyRect.height = __layoutSize.height + bodyTopMargin + bodyBottomMargin;
- {
- bodyRect.y = anchorPosition.y - (bodyRect.height / 2.0f);
+ bodyRect.y = screen.height - bodyRect.height;
- windowRect.x = bodyRect.x ;//+ correctLength;
- windowRect.y = bodyRect.y;
- windowRect.width = bodyRect.width ;//+ arrowRect.width - correctLength;
- windowRect.height = bodyRect.height;
+ windowRect.x = bodyRect.x ;
+ windowRect.y = bodyRect.y;
+ windowRect.width = bodyRect.width ;
+ windowRect.height = bodyRect.height;
- bodyRect.x = 0.0f;
- bodyRect.y = 0.0f;
- }
+ bodyRect.x = 0.0f;
+ bodyRect.y = 0.0f;
itemRect.x = bodyRect.x + bodyLeftMargin;
itemRect.y = bodyRect.y + bodyTopMargin;
__pOptionMenu->SetMovable(true);
__pOptionMenu->SetResizable(true);
- __pOptionMenu->SetMinimumSize(FloatDimension(0.0f, 0.0f));
- __pOptionMenu->SetMaximumSize(screen);
__pOptionMenu->SetBounds(windowRect);
__pOptionMenu->SetMovable(false);
{
result r = E_SUCCESS;
- // calculate bounds
- _ControlManager *pManager = _ControlManager::GetInstance();
- FloatDimension screenSize = pManager->GetScreenSizeF();
- _ControlOrientation orientation = __pOptionMenu->GetOrientation();
-
- if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
- {
- FloatDimension temp = screenSize;
- screenSize.width = temp.height;
- screenSize.height = temp.width;
- }
-
- FloatRectangle bodyRect = __pOptionMenu->GetBodyRect();
-
- bodyRect.y = screenSize.height - bodyRect.height;
-
- __pOptionMenu->SetMovable(true);
- __pOptionMenu->SetResizable(true);
-
- __pOptionMenu->SetBounds(CoordinateSystem::AlignToDevice(bodyRect));
-
- __pOptionMenu->SetMovable(false);
- __pOptionMenu->SetResizable(false);
-
Canvas* pCanvas = __pOptionMenu->GetCanvasN();
SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "The memory is insufficient.");
}
result
+_OptionMenuPresenter::DrawFocus(int index)
+{
+ Draw();
+
+ result r = E_SUCCESS;
+
+ int count = __pOptionMenu->GetMaximumVisibleItemsCount();
+
+ Canvas* pCanvas;
+ pCanvas = __pOptionMenu->GetCanvasN();
+
+ SysTryReturn(NID_UI_CTRL, (pCanvas != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
+
+ FloatRectangle bounds;
+
+ if (index >= count)
+ {
+ index = count - 1;
+ }
+
+ _OptionMenuItem* pItem = __pModel->GetItem(index);
+ bounds = pItem->GetDrawRect();
+
+ Bitmap* pBitmap = null;
+ r = GET_BITMAP_CONFIG_N(FOCUSUI::FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pBitmap);
+ SysTryCatch(NID_UI_CTRL, (pBitmap != null), , r, "[%s] Propagating.", GetErrorMessage(r));
+
+ if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pBitmap))
+ {
+ r = pCanvas->DrawNinePatchedBitmap(bounds, *pBitmap);
+ }
+ else
+ {
+ r = pCanvas->DrawBitmap(bounds, *pBitmap);
+ }
+
+ delete pCanvas;
+ delete pBitmap;
+
+ return r;
+
+ CATCH:
+ delete pCanvas;
+ return r;
+}
+
+void
+_OptionMenuPresenter::OnEnterKeyPressed(int selectedIndex)
+{
+ _OptionMenuItem* pItem = null;
+ pItem = __pModel->GetItem(selectedIndex);
+ __selectedIndex = -1;
+
+ if (pItem != null)
+ {
+ if (pItem->HasSubItem() == true)
+ {
+ // Show SubItem
+ __pOptionMenu->ShowSubMenu(selectedIndex, *pItem);
+ return ;
+ }
+ else
+ {
+ __pOptionMenu->Close();
+ __pOptionMenu->FireActionEvent(pItem->GetActionId());
+ }
+ }
+ return;
+}
+
+result
_OptionMenuPresenter::DrawBackground(Canvas* pCanvas)
{
SysTryReturn(NID_UI_CTRL, pCanvas != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
if (pItem->HasSubItem() == true)
{
// Show SubItem
- __pOptionMenu->ShowSubMenu(__selectedIndex, *pItem, touchPosition);
+ __pOptionMenu->ShowSubMenu(__selectedIndex, *pItem);
return true;
}
else
// Fire Action Event
__pOptionMenu->SetVisibleState(false);
//PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
-
__pOptionMenu->FireActionEvent(pItem->GetActionId());
}
}
{
// for SubMenu Events
__pOptionMenu->DestroySubMenu();
- //Hide();
__pOptionMenu->SetVisibleState(false);
__pOptionMenu->FireActionEvent(actionId);
}
int GetSubItemCount(int mainIndex) const;
int GetSubItemIndexFromActionId(int actionId) const;
int GetSubItemActionIdAt(int mainIndex, int subIndex) const;
- result ShowSubMenu(int mainIndex, _OptionMenuItem& item, Tizen::Graphics::FloatPoint touchPosition);
+ result ShowSubMenu(int mainIndex, _OptionMenuItem& item);
bool IsSubMenuShown(void) const;
result DestroySubMenu(void);
result InsertItem(int index, const Tizen::Base::String& text, int actionId, const Tizen::Graphics::Bitmap* pNormalBitmap,
void RemoveAllItems(void);
int GetItemCount(void) const;
result SetShowItemCount(int count);
- int GetShowItemCount(void) const;
- int GetShowItemMaxCount(void) const;
+ int GetMaximumVisibleItemsCount(void) const;
int GetItemIndexAt(int actionId) const;
int GetItemActionIdAt(int index) const;
result SetWindowRect(const Tizen::Graphics::FloatRectangle& rect);
virtual void OnChangeLayout(_ControlOrientation orientation);
virtual void OnOwnerChanged(_Control* pOldOwner);
- void OnActivated(void);
- void OnDeactivated(void);
+ void OnActivated(void);
+ void OnDeactivated(void);
virtual bool OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element);
virtual bool OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element);
_ScrollPanel* GetScrollPanel(void);
- // virtual bool OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo);
+ virtual bool OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo);
virtual bool OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo);
- // virtual bool OnFocusGained(const _Control& source);
- // virtual bool OnFocusLost(const _Control& source);
- // virtual void OnDrawFocus(void);
- // void OnFocusModeStateChanged(void);
- // bool IsChildControlFocusManage(void) const;
+ virtual bool OnFocusGained(const _Control& source);
+ virtual bool OnFocusLost(const _Control& source);
+ virtual void OnDrawFocus(void);
+ virtual void OnFocusModeStateChanged(void);
protected:
result SetPresenter(const _OptionMenuPresenter& OptionMenuPresenter);
private:
_OptionMenuPresenter* __pOptionMenuPresenter;
int __showItemCount;
- int __showItemMaxCount;
bool __isAttachedToMainTree;
- bool __ownerInputEnableState;
+ bool __isMaxVisibleCountSet;
+ bool __isFocused;
+ int __currentFocusedIndex;
// attribute for position fo the window
Tizen::Graphics::FloatRectangle __windowRect; // OptionMenu window in the whole screen area
public:
virtual result Install(void);
virtual result Draw(void);
+ result DrawFocus(int index);
+ void OnEnterKeyPressed(int selectedIndex);
virtual result DrawBackground(Tizen::Graphics::Canvas* pCanvas);
virtual result AddItem(const Tizen::Base::String& text, int actionId, const Tizen::Graphics::Bitmap* normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap);
virtual result AddSubItem(int mainIndex, const Tizen::Base::String& text, int actionId);
- int GetItemIndexFromActionId(int actionId) const;
- int GetItemActionIdAt(int mainIndex) const;
- virtual result InsertItem(int mainIndex, const Tizen::Base::String& text, int actionId, const Tizen::Graphics::Bitmap* normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap);
+ int GetItemIndexFromActionId(int actionId) const;
+ int GetItemActionIdAt(int mainIndex) const;
+ virtual result InsertItem(int mainIndex, const Tizen::Base::String& text, int actionId, const Tizen::Graphics::Bitmap* normalBitmap, const Tizen::Graphics::Bitmap* pPressedBitmap, const Tizen::Graphics::Bitmap* pHighlightedBitmap);
virtual result InsertSubItemAt(int mainIndex, int subIndex, const Tizen::Base::String& text, int actionId);
virtual result SetSubItemAt(int mainIndex, int subIndex, const Tizen::Base::String& text, int actionId);
virtual result RemoveSubItemAt(int mainIndex, int subIndex);
virtual result DeleteItemAll(void);
virtual int CalculateShowItemCount(void);
virtual result CalculateWindowRect(void);
- virtual result ApplyColorProperty(void);
+ virtual result ApplyColorProperty(void);
int GetSubItemIndexFromActionId(int actionId) const;
int GetSubItemActionIdAt(int mainIndex, int subIndex) const;
virtual result SetTopDrawnItemIndex(int index);
virtual result DrawBitmap(Tizen::Graphics::Canvas& canvas, const Tizen::Graphics::FloatRectangle& bounds, const Tizen::Graphics::Bitmap& bitmap);
-// virtual bool OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo);
-
-// virtual bool OnFocusGained(const _Control& source);
-// virtual bool OnFocusLost(const _Control& source);
-// virtual void OnDrawFocus(void);
-
private:
void LoadShape(void);
result CalculateRect(void);
float __topMargin;
float __bottomMargin;
float __leftMargin;
- float __rightMargin;
+ float __rightMargin;
float __itemWidth;
float __itemMinWidth;
float __itemHeight;
float __itemBitmapWidth;
float __itemBitmapHeight;
float __itemFontSize;
- float __dividerHeight;
+ float __dividerHeight;
}; // _OptionMenuListPresenter
}}} // Tizen::Ui: Control