2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FUiCtrl_TokenEdit.cpp
19 * @brief This is the implementation file for the _TokenEdit class.
22 #include <FBaseSysLog.h>
23 #include "FUiCtrl_TokenEdit.h"
24 #include "FUiCtrl_TokenEditPresenter.h"
26 #include "FUi_AccessibilityContainer.h"
27 #include "FUi_AccessibilityElement.h"
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Ui;
33 namespace Tizen { namespace Ui { namespace Controls
36 IMPLEMENT_PROPERTY(_TokenEdit);
38 _TokenEdit::_TokenEdit(void)
40 , __pTokenEditPresenter(null)
41 , __isSelectedTokenTextColorSet(false)
42 , __pTokenFilter(null)
43 , __pTitleTextAccessibilityElement(null)
44 , __pCursorAccessibilityElement(null)
46 GET_COLOR_CONFIG(TOKENEDIT::BG_NORMAL, __tokenColor[TOKEN_EDIT_STATUS_NORMAL]);
47 GET_COLOR_CONFIG(TOKENEDIT::BG_SELECTED, __tokenColor[TOKEN_EDIT_STATUS_SELECTED]);
48 GET_COLOR_CONFIG(TOKENEDIT::BG_HIGHLIGHTED, __tokenColor[TOKEN_EDIT_STATUS_HIGHLIGHTED]);
49 GET_COLOR_CONFIG(TOKENEDIT::BG_DISABLED, __tokenColor[TOKEN_EDIT_STATUS_DISABLED]);
50 GET_COLOR_CONFIG(TOKENEDIT::TEXT_NORMAL, __tokenTextColor[EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL]);
51 GET_COLOR_CONFIG(TOKENEDIT::TEXT_SELECTED, __tokenTextColor[EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED]);
53 _AccessibilityContainer* pContainer = null;
54 pContainer = GetAccessibilityContainer();
57 pContainer->Activate(true);
61 _TokenEdit::~_TokenEdit(void)
67 _TokenEdit::CreateTokenEditN(void)
69 _TokenEditPresenter* pPresenter = _TokenEditPresenter::CreateTokenEditPresenterN();
70 result r = GetLastResult();
71 SysTryReturn(NID_UI_CTRL, pPresenter != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
73 _TokenEdit* pTokenEdit = new (std::nothrow) _TokenEdit();
74 SysTryCatch(NID_UI_CTRL, pTokenEdit != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
75 SysTryCatch(NID_UI_CTRL, GetLastResult() == E_SUCCESS, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
77 pTokenEdit->AcquireHandle();
79 pTokenEdit->SetPresenter(*pPresenter);
80 pTokenEdit->__pTokenEditPresenter = pPresenter;
91 _TokenEdit::OnDraw(void)
95 if (__pTokenEditPresenter == null)
100 Canvas* pCanvas = GetCanvasN();
101 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
103 r = __pTokenEditPresenter->Draw(*pCanvas);
104 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
110 _TokenEdit::SetTokenFilter(const _ITokenFilter* pFilter)
112 result r = E_SUCCESS;
114 __pTokenFilter = const_cast< _ITokenFilter* >(pFilter);
120 _TokenEdit::GetTokenFilter(void) const
122 return __pTokenFilter;
126 _TokenEdit::AppendToken(const String& token)
128 result r = E_SUCCESS;
130 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
132 r = __pTokenEditPresenter->AppendToken(token);
133 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
139 _TokenEdit::InsertTokenAt(int index, const String& token)
141 result r = E_SUCCESS;
143 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
145 r = __pTokenEditPresenter->InsertTokenAt(index, token, true);
146 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
152 _TokenEdit::GetTokenAt(int index) const
154 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
156 return __pTokenEditPresenter->GetTokenAt(index);
160 _TokenEdit::GetTokenCount(void) const
162 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
164 return __pTokenEditPresenter->GetTokenCount(true);
168 _TokenEdit::GetSelectedTokenIndex(void) const
170 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
172 return __pTokenEditPresenter->GetSelectedTokenIndex();
176 _TokenEdit::IsTokenEditModeEnabled(void) const
178 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
180 Variant var = GetProperty("tokenEditModeEnabled");
186 _TokenEdit::RemoveTokenAt(int index)
188 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
190 return __pTokenEditPresenter->RemoveTokenAt(index, true);
194 _TokenEdit::SetTokenSelected(int index, bool selected)
196 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
198 return __pTokenEditPresenter->SetTokenSelected(index, selected);
202 _TokenEdit::SetTokenEditModeEnabled(bool enable)
204 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
208 return SetProperty("tokenEditModeEnabled", var);
212 _TokenEdit::GetTokenColor(TokenEditStatus status) const
218 case TOKEN_EDIT_STATUS_NORMAL:
219 var = GetProperty("normalTokenColor");
222 case TOKEN_EDIT_STATUS_SELECTED:
223 var = GetProperty("selectedTokenColor");
226 case TOKEN_EDIT_STATUS_HIGHLIGHTED:
227 var = GetProperty("highlightedTokenColor");
230 case TOKEN_EDIT_STATUS_DISABLED:
231 var = GetProperty("disabledTokenColor");
238 return var.ToColor();
242 _TokenEdit::GetTokenTextColor(void) const
244 Variant var = GetProperty("tokenTextColor");
246 return var.ToColor();
250 _TokenEdit::SetTokenColor(TokenEditStatus status, const Color& color)
252 result r = E_SUCCESS;
257 case TOKEN_EDIT_STATUS_NORMAL:
258 r = SetProperty("normalTokenColor", var);
261 case TOKEN_EDIT_STATUS_SELECTED:
262 r = SetProperty("selectedTokenColor", var);
265 case TOKEN_EDIT_STATUS_HIGHLIGHTED:
266 r = SetProperty("highlightedTokenColor", var);
269 case TOKEN_EDIT_STATUS_DISABLED:
270 r = SetProperty("disabledTokenColor", var);
280 _TokenEdit::SetTokenTextColor(const Color& color)
283 return SetProperty("tokenTextColor", var);
287 _TokenEdit::GetSelectedTokenTextColor(void) const
289 Variant var = GetProperty("selectedTokenTextColor");
291 return var.ToColor();
295 _TokenEdit::SetSelectedTokenTextColor(const Color& color)
299 return SetProperty("selectedTokenTextColor", var);
303 _TokenEdit::SetTitleText(const String& title)
305 result r = E_SUCCESS;
307 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
309 __pTokenEditPresenter->SetDescriptionText(title);
311 r = __pTokenEditPresenter->CalculateDescriptionTextRect(title);
312 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
314 r = __pTokenEditPresenter->CalculateTokenPositionFromIndex(0);
315 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
317 r = __pTokenEditPresenter->SetInitialBounds();
318 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
325 _TokenEdit::GetTitleText(void) const
327 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
329 return __pTokenEditPresenter->GetDescriptionText();
333 _TokenEdit::SetAutoShrinkModeEnabled(bool enable)
335 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
337 __pTokenEditPresenter->SetAutoShrinkModeEnabled(enable);
341 _TokenEdit::IsAutoShrinkModeEnabled(void) const
343 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
345 return __pTokenEditPresenter->IsAutoShrinkModeEnabled();
349 _TokenEdit::ProcessTokenFiltering(const String& inputString, String& replaceString, bool& enable)
353 enable = __pTokenFilter->ReplaceToken(inputString, replaceString);
360 _TokenEdit::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
367 if (__pTokenEditPresenter == null)
371 return __pTokenEditPresenter->OnTouchPressed(source, touchinfo);
375 _TokenEdit::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
381 if (__pTokenEditPresenter == null)
385 return __pTokenEditPresenter->OnTouchReleased(source, touchinfo);
389 _TokenEdit::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
395 if (__pTokenEditPresenter == null)
399 return __pTokenEditPresenter->OnTouchMoved(source, touchinfo);
403 _TokenEdit::SetPropertyNormalTokenColor(const Variant& color)
407 __tokenColor[TOKEN_EDIT_STATUS_NORMAL] = color.ToColor();
413 _TokenEdit::GetPropertyNormalTokenColor(void) const
417 return Variant(__tokenColor[TOKEN_EDIT_STATUS_NORMAL]);
421 _TokenEdit::SetPropertySelectedTokenColor(const Variant& color)
425 __tokenColor[TOKEN_EDIT_STATUS_SELECTED] = color.ToColor();
431 _TokenEdit::GetPropertySelectedTokenColor(void) const
435 return Variant(__tokenColor[TOKEN_EDIT_STATUS_SELECTED]);
439 _TokenEdit::SetPropertyHighlightedTokenColor(const Variant& color)
443 __tokenColor[TOKEN_EDIT_STATUS_HIGHLIGHTED] = color.ToColor();
449 _TokenEdit::GetPropertyHighlightedTokenColor(void) const
453 return Variant(__tokenColor[TOKEN_EDIT_STATUS_HIGHLIGHTED]);
457 _TokenEdit::SetPropertyDisabledTokenColor(const Variant& color)
461 __tokenColor[TOKEN_EDIT_STATUS_DISABLED] = color.ToColor();
467 _TokenEdit::GetPropertyDisabledTokenColor(void) const
471 return Variant(__tokenColor[TOKEN_EDIT_STATUS_DISABLED]);
475 _TokenEdit::SetPropertyTokenTextColor(const Variant& color)
479 __tokenTextColor[EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL] = color.ToColor();
480 if (!__isSelectedTokenTextColorSet)
482 __tokenTextColor[EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED] = color.ToColor();
489 _TokenEdit::GetPropertyTokenTextColor(void) const
493 return Variant(__tokenTextColor[EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL]);
497 _TokenEdit::SetPropertySelectedTokenTextColor(const Variant& color)
501 __isSelectedTokenTextColorSet = true;
503 __tokenTextColor[EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED] = color.ToColor();
509 _TokenEdit::GetPropertySelectedTokenTextColor(void) const
513 return Variant(__tokenTextColor[EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED]);
517 _TokenEdit::SetPropertyTokenEditModeEnabled(const Variant& enable)
519 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
523 return __pTokenEditPresenter->SetTokenEditModeEnabled(enable.ToBool());
527 _TokenEdit::GetPropertyTokenEditModeEnabled(void) const
529 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
533 bool enabled = __pTokenEditPresenter->IsTokenEditModeEnabled();
535 return Variant(enabled);
539 _TokenEdit::OnAttachedToMainTree(void)
541 _AccessibilityContainer* pContainer = null;
542 pContainer = GetAccessibilityContainer();
545 if (__pTitleTextAccessibilityElement)
549 pContainer->AddListener(*this);
550 UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
557 _TokenEdit::OnBoundsChanged(void)
559 SysAssertf(__pTokenEditPresenter != null, "_TokenEditPresenter instance is null");
561 __pTokenEditPresenter->OnBoundsChanged();
567 _TokenEdit::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
569 return __pTokenEditPresenter->OnAccessibilityFocusIn(control, element);
573 _TokenEdit::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
575 return __pTokenEditPresenter->OnAccessibilityFocusOut(control, element);
579 _TokenEdit::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
581 return __pTokenEditPresenter->OnAccessibilityActionPerformed(control, element);
585 _TokenEdit::UpdateAccessibilityElement(EditAccessibilityElementType type)
587 _AccessibilityElement* pTextAccessibilityElement = _Edit::GetTextAccessibilityElement();
588 String spaceString(L" ");
591 case EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT:
592 if (pTextAccessibilityElement)
594 pTextAccessibilityElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
597 pTextAccessibilityElement->SetLabel(GetTitleText() + spaceString + __pTokenEditPresenter->GetTextAccessibilityElementText());
601 pTextAccessibilityElement->SetLabel(GetTitleText() + spaceString + GetGuideText() + GetText());
603 pTextAccessibilityElement->SetHintWithStringId("IDS_TPLATFORM_BODY_DOUBLE_TAP_TO_EDIT_T_TTS");
614 _AccessibilityElement*
615 _TokenEdit::GetTitleTextAccessibilityElement(void) const
617 return __pTitleTextAccessibilityElement;
620 _AccessibilityElement*
621 _TokenEdit::GetCursorAccessibilityElement(void) const
623 return __pCursorAccessibilityElement;
627 _TokenEdit::AddTitleAccessibilityElement(void)
629 result r = E_SUCCESS;
631 if (!(GetEditStyle() & EDIT_STYLE_TITLE_LEFT))
636 if (__pTitleTextAccessibilityElement)
641 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
645 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
646 SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
648 String labelText = GetTitleText();
649 pAccessibilityElement->SetBounds(__pTokenEditPresenter->GetDescriptionTextRect());
650 pAccessibilityElement->SetLabel(labelText);
651 pContainer->AddElement(*pAccessibilityElement);
652 __pTitleTextAccessibilityElement = pAccessibilityElement;
659 _TokenEdit::AddCursorAccessibilityElement(void)
661 result r = E_SUCCESS;
663 if (__pCursorAccessibilityElement)
668 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
672 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
673 SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
677 pAccessibilityElement->SetLabel(GetText());
681 pAccessibilityElement->SetTrait(L"Edit field");
684 pContainer->AddElement(*pAccessibilityElement);
686 __pCursorAccessibilityElement = pAccessibilityElement;
688 SetCursorAccessibilityBounds(__pTokenEditPresenter->GetTextBoundsF());
695 _TokenEdit::SetCursorAccessibilityBounds(const FloatRectangle& cursorBounds)
697 if (!__pCursorAccessibilityElement)
701 __pCursorAccessibilityElement->SetBounds(cursorBounds);
707 _TokenEdit::RemoveTitleAccessibilityElement(void)
709 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
712 if (__pTitleTextAccessibilityElement)
714 pContainer->RemoveElement(*__pTitleTextAccessibilityElement);
715 __pTitleTextAccessibilityElement = null;
721 _TokenEdit::RemoveCursorAccessibilityElement(void)
723 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
726 if (__pCursorAccessibilityElement)
728 pContainer->RemoveElement(*__pCursorAccessibilityElement);
729 __pCursorAccessibilityElement = null;
735 _TokenEdit::OnDrawFocus(void)
737 //Exit Token editing/pressed mode
738 __pTokenEditPresenter->PrepareFocusUiMode();
740 __pTokenEditPresenter->SetDrawFocusState(true);
746 _TokenEdit::OnFocusModeStateChanged(void)
748 //Reset focus index here
749 __pTokenEditPresenter->SetDrawFocusState(false);
754 }}} //Tizen::Ui::Controls