From fec5b904ea23bc8b023445d6d5764922e41ed6f2 Mon Sep 17 00:00:00 2001 From: Kunal Sinha Date: Thu, 9 May 2013 16:30:40 +0530 Subject: [PATCH] Added Token Construct Change-Id: Ifdc597de201d37231081a0e2f31ddd85266aa663 Signed-off-by: Kunal Sinha --- src/ui/controls/FUiCtrl_TokenEditPresenter.cpp | 31 ++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/ui/controls/FUiCtrl_TokenEditPresenter.cpp b/src/ui/controls/FUiCtrl_TokenEditPresenter.cpp index 1c4e4d8..cc5d17a 100644 --- a/src/ui/controls/FUiCtrl_TokenEditPresenter.cpp +++ b/src/ui/controls/FUiCtrl_TokenEditPresenter.cpp @@ -67,7 +67,8 @@ class _Token : public Object { public: - _Token(const String& text, Font* pEditFont); + _Token(void); + result Construct(const String& text, Font* pEditFont); virtual ~_Token(void); float GetTextPixelWidth(void) const; wchar_t* GetText(void) const; @@ -91,7 +92,7 @@ private: _VisualElement* __pVisualElement; }; // _Token -_Token::_Token(const String& text, Font* pEditFont) +_Token::_Token(void) : pTextObject(null) , pFont(null) , currTokenLength(0) @@ -102,13 +103,18 @@ _Token::_Token(const String& text, Font* pEditFont) , __textPixelHeight(0.0f) , __pVisualElement(null) { +} + +result +_Token::Construct(const String& text, Font* pEditFont) +{ result r = E_SUCCESS; currTokenLength = text.GetLength(); float tokenFontSize = 0.0f; pTextObject = new (std::nothrow) TextObject; - SysTryReturnVoidResult(NID_UI_CTRL, pTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + SysTryReturnResult(NID_UI_CTRL, pTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); // for default initialize. r = pTextObject->Construct(); @@ -123,7 +129,8 @@ _Token::_Token(const String& text, Font* pEditFont) GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, tokenFontSize); pFont = _FontImpl::CloneN(*pEditFont); - SysTryCatch(NID_UI_CTRL, pFont != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult())); + r = GetLastResult(); + SysTryCatch(NID_UI_CTRL, pFont != null, , r, "[%s] Propagating.", GetErrorMessage(r)); (_FontImpl::GetInstance(*pFont))->SetStyle(FONT_STYLE_PLAIN); (_FontImpl::GetInstance(*pFont))->SetSize(tokenFontSize); @@ -135,7 +142,7 @@ _Token::_Token(const String& text, Font* pEditFont) SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); __pVisualElement = new (std::nothrow) _VisualElement; - SysTryCatch(NID_UI_CTRL, __pVisualElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); + SysTryCatch(NID_UI_CTRL, __pVisualElement != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed."); r = __pVisualElement->Construct(); SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct _VisualElement.", GetErrorMessage(r)); @@ -143,7 +150,7 @@ _Token::_Token(const String& text, Font* pEditFont) __pVisualElement->SetImplicitAnimationEnabled(false); __pVisualElement->SetOpacity(0.0f); - return; + return r; CATCH: delete pTextObject; @@ -158,7 +165,7 @@ CATCH: delete pFont; pFont = null; - return; + return r; } result @@ -915,9 +922,12 @@ _TokenEditPresenter::MakeToken(const String& tokenString) return E_INVALID_ARG; } - _Token* pToken = new (std::nothrow) _Token(inputTokenString, GetFont()); + _Token* pToken = new (std::nothrow) _Token(); SysTryReturnResult(NID_UI_CTRL, pToken != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + r = pToken->Construct(inputTokenString, GetFont()); + SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct token.", GetErrorMessage(r)); + r = __pTokenList->Add(static_cast (*pToken)); SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r)); @@ -992,9 +1002,12 @@ _TokenEditPresenter::InsertTokenAt(int index, const String& token, bool isUser) result r = E_SUCCESS; - _Token* pToken = new (std::nothrow) _Token(token, GetFont()); + _Token* pToken = new (std::nothrow) _Token(); SysTryReturnResult(NID_UI_CTRL, pToken != null, E_OUT_OF_MEMORY, "Memory allocation failed."); + r = pToken->Construct(token, GetFont()); + SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct token.", GetErrorMessage(r)); + r = __pTokenList->InsertAt(*pToken, index); SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to insert token.", GetErrorMessage(r)); -- 2.7.4