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_TokenEditPresenter.cpp
19 * @brief This is the implementation file for the _TokenEditPresenter class.
21 #include <FGrp_BitmapImpl.h>
22 #include <FUiAnimVisualElementAnimationGroup.h>
23 #include <FGrp_TextTextSimple.h>
24 #include <FGrp_FontImpl.h>
25 #include "FUiAnim_VisualElement.h"
26 #include "FUi_UiTouchEvent.h"
27 #include "FUiCtrl_TokenEdit.h"
28 #include "FUiCtrl_TokenEditPresenter.h"
29 #include "FUiCtrl_Scroll.h"
31 #include "FUi_CoordinateSystemUtils.h"
32 #include "FUi_AccessibilityContainer.h"
33 #include "FUi_AccessibilityElement.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Runtime;
37 using namespace Tizen::Media;
38 using namespace Tizen::Ui::Animations;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Graphics::_Text;
42 namespace Tizen { namespace Ui { namespace Controls
46 SineTimingFunction::CalculateProgress(float timeProgress) const
48 const float segments[3][3] = {{0.0f, 0.01f, 0.37f}, {0.37f, 0.72f, 0.888f}, {0.888f, 0.9999f, 1.0f}};
49 float timeProgressValue = timeProgress;
50 int segmentsLength = 3; //Length of the segments array
51 int index = (int) floor(segmentsLength * timeProgressValue);
52 if (index >= segmentsLength)
54 index = segmentsLength - 1;
57 float progressValue = (timeProgressValue - index * (1.0 / segmentsLength)) * segmentsLength;
58 float segmentAtIndex[3];
59 for (int i = 0; i < 3; i++)
61 segmentAtIndex[i] = segments[index][i];
63 float ret = 0 + 1 * (segmentAtIndex[0] + progressValue * (2 * (1 - progressValue) * (segmentAtIndex[1] - segmentAtIndex[0]) + progressValue * (segmentAtIndex[2] - segmentAtIndex[0])));
73 result Construct(const String& text, Font* pEditFont);
74 virtual ~_Token(void);
75 float GetTextPixelWidth(void) const;
76 wchar_t* GetText(void) const;
77 result ResetToken(const String& text);
78 result SetBounds(FloatRectangle bounds);
79 _VisualElement* GetVisualElement(void) const;
80 _Token(const _Token& src);
81 _Token& operator =(const _Token& value);
84 FloatRectangle displayRect;
85 TextObject* pTextObject;
88 bool isImplicitAnimation;
91 wchar_t* __pTextBuffer;
92 float __textPixelWidth;
93 float __textPixelHeight;
94 _VisualElement* __pVisualElement;
101 , isImplicitAnimation(true)
103 , __pTextBuffer(null)
104 , __textPixelWidth(0.0f)
105 , __textPixelHeight(0.0f)
106 , __pVisualElement(null)
111 _Token::Construct(const String& text, Font* pEditFont)
113 result r = E_SUCCESS;
115 currTokenLength = text.GetLength();
116 float tokenFontSize = 0.0f;
118 pTextObject = new (std::nothrow) TextObject;
119 SysTryReturnResult(NID_UI_CTRL, pTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
121 // for default initialize.
122 r = pTextObject->Construct();
123 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
125 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
126 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
128 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
129 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
131 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, tokenFontSize);
133 pFont = _FontImpl::CloneN(*pEditFont);
135 SysTryCatch(NID_UI_CTRL, pFont != null, , r, "[%s] Propagating.", GetErrorMessage(r));
137 (_FontImpl::GetInstance(*pFont))->SetStyle(FONT_STYLE_PLAIN);
138 (_FontImpl::GetInstance(*pFont))->SetSize(tokenFontSize);
140 r = pTextObject->SetFont(pFont, 0, pTextObject->GetTextLength());
141 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
143 r = ResetToken(text);
144 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
146 __pVisualElement = new (std::nothrow) _VisualElement;
147 SysTryCatch(NID_UI_CTRL, __pVisualElement != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
149 r = __pVisualElement->Construct();
150 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct _VisualElement.", GetErrorMessage(r));
152 __pVisualElement->SetImplicitAnimationEnabled(false);
153 __pVisualElement->SetOpacity(0.0f);
161 if (__pVisualElement)
163 __pVisualElement->Destroy();
164 __pVisualElement = null;
174 _Token::ResetToken(const String& text)
176 result r = E_SUCCESS;
177 FloatDimension textSize;
181 delete[] __pTextBuffer;
182 __pTextBuffer = null;
185 int length = text.GetLength();
186 wchar_t* pTempString = const_cast< wchar_t* >(text.GetPointer());
187 SysTryReturnResult(NID_UI_CTRL, pTempString != null, E_SYSTEM, "A system error has occurred. Token text string is null.");
189 __pTextBuffer = new (std::nothrow) wchar_t[(length + 1) * (sizeof(wchar_t))];
190 SysTryReturnResult(NID_UI_CTRL, __pTextBuffer != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
192 for (int i = 0; i < length; i++)
194 __pTextBuffer[i] = pTempString[i];
196 __pTextBuffer[length] = 0;
198 pTextObject->RemoveAll(true);
200 TextSimple* pSimpleText = new (std::nothrow) TextSimple(__pTextBuffer, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, pFont);
201 SysTryCatch(NID_UI_CTRL, pSimpleText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
203 r = pTextObject->AppendElement(*pSimpleText);
204 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
206 textSize = pTextObject->GetTextExtentF(0, length);
207 __textPixelWidth = textSize.width;
208 __textPixelHeight = textSize.height;
210 r = pTextObject->Compose();
212 currTokenLength = length;
217 delete[] __pTextBuffer;
218 __pTextBuffer = null;
227 _Token::SetBounds(FloatRectangle bounds)
229 result r = E_SUCCESS;
230 displayRect = bounds;
231 if (__pVisualElement)
233 __pVisualElement->SetBounds(bounds);
239 _Token::GetVisualElement(void) const
241 return __pVisualElement;
244 _Token::~_Token(void)
252 delete[] __pTextBuffer;
253 __pTextBuffer = null;
255 if (__pVisualElement)
257 __pVisualElement->Destroy();
258 __pVisualElement = null;
263 _Token::GetTextPixelWidth(void) const
265 return __textPixelWidth;
269 _Token::GetText(void) const
271 return __pTextBuffer;
274 _TokenEditPresenter::_TokenEditPresenter(void)
277 , __pTokenBgBitmap(null)
278 , __pTokenBgNormalEffectBitmap(null)
279 , __pTokenBgPressedEffectBitmap(null)
280 , __pTokenBgReplacementFocusBitmap(null)
281 , __pTokenBgFocusEffectBitmap(null)
282 , __pressedTokenIndex(-1)
283 , __isEditingToken(false)
284 , __editingTokenIndex(-1)
285 , __clientRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
286 , __initTextRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
287 , __isEditModeEnabled(true)
288 , __pDescriptionTextVisualElement(null)
289 , __pDescriptionTextTextObject(null)
290 , __isTokenEditingFinished(false)
291 , __prevScrollValue(0.0f)
292 , __scrollValue(0.0f)
293 , __isTokenScrolling(false)
294 , __isNeedToScroll(false)
295 , __maxScrollValue(0.0f)
296 , __autoShrink(false)
297 , __descriptionText(String())
298 , __isPopupVisible(false)
299 , __isLongPressed(false)
300 , __lineSpacing(0.0f)
301 , __animatingIndex(-1)
302 , __lastTokenIndex(-1)
303 , __pTimingFunction(null)
304 , __descriptionTextRectForScroll(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
305 , __previousTitleWidth(-1.0f)
306 , __isTokenEditPresenterInitialized(false)
308 , __previousCursorPosition(0)
309 , __isScrollValueChanged(false)
311 , __isScrollValueModified(false)
312 , __isTouchMoveInProgress(false)
313 , __isTitleSliding(false)
314 , __touchPressInfo(FloatPoint(-1.0f, -1.0f))
315 , __editContentFontSize(0.0f)
316 , __trackTokenIndex(-1)
317 , __isAnimationInProgress(false)
318 , __focusOutIndex(-1)
319 , __accessibilityElements()
320 , __focusedTokenIndex(-1)
321 , __drawFocusState(false)
326 _TokenEditPresenter::InitializeDescriptionText(void)
328 result r = E_SUCCESS;
329 float descriptionTextSize = 0.0f;
331 float editFontSize = 0.0f;
333 __pDescriptionTextTextObject = new (std::nothrow) TextObject();
334 SysTryReturnResult(NID_UI_CTRL, __pDescriptionTextTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
336 // for default initialize.
337 r = __pDescriptionTextTextObject->Construct();
338 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
340 r = __pDescriptionTextTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
341 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
343 r = __pDescriptionTextTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
344 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
346 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, descriptionTextSize);
349 SysTryCatch(NID_UI_CTRL, pFont != null, , r, "[%s] Propagating.", GetErrorMessage(r));
351 editFontSize = GetTextSize();
352 (_FontImpl::GetInstance(*pFont))->SetSize(descriptionTextSize);
354 r = __pDescriptionTextTextObject->SetFont(pFont, 0, __pDescriptionTextTextObject->GetTextLength());
355 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
357 (_FontImpl::GetInstance(*pFont))->SetSize(editFontSize);
363 delete __pDescriptionTextTextObject;
364 __pDescriptionTextTextObject = null;
369 _TokenEditPresenter::~_TokenEditPresenter(void)
371 DisposeTokenEditPresenter();
375 _TokenEditPresenter::DisposeTokenEditPresenter(void)
377 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
378 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
380 if (pEditVisualElement && pCursorVisualElement)
382 VisualElement* pCursorParent = pCursorVisualElement->GetParent();
383 if (pCursorParent != pEditVisualElement)
387 pCursorParent->DetachChild(*pCursorVisualElement);
388 pEditVisualElement->AttachChild(*pCursorVisualElement);
395 __pTokenList->RemoveAll(true);
400 delete __pTokenBgBitmap;
401 __pTokenBgBitmap = null;
403 delete __pTokenBgNormalEffectBitmap;
404 __pTokenBgNormalEffectBitmap = null;
406 delete __pTokenBgPressedEffectBitmap;
407 __pTokenBgPressedEffectBitmap = null;
409 delete __pTokenBgReplacementFocusBitmap;
410 __pTokenBgReplacementFocusBitmap = null;
412 delete __pTokenBgFocusEffectBitmap;
413 __pTokenBgFocusEffectBitmap = null;
415 if (__pDescriptionTextVisualElement)
417 __pDescriptionTextVisualElement->Destroy();
418 __pDescriptionTextVisualElement = null;
421 delete __pDescriptionTextTextObject;
422 __pDescriptionTextTextObject = null;
424 if (__pTimingFunction)
426 delete __pTimingFunction;
427 __pTimingFunction = null;
430 RemoveChildAccessibilityElements();
436 _TokenEditPresenter::CreateTokenEditPresenterN(void)
438 _TokenEditPresenter* pPresenter = new (std::nothrow) _TokenEditPresenter();
439 SysTryReturn(NID_UI_CTRL, pPresenter != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
445 _TokenEditPresenter::Initialize(const _Control& control)
447 result r = E_SUCCESS;
449 r = _EditPresenter::Initialize(control);
450 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
452 r = InitializeDescriptionText();
453 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
455 TextObject* pTextObject = GetTextObject();
458 pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
459 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
460 pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
461 pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
464 __pTokenEdit = dynamic_cast< _TokenEdit* >(GetEditView());
465 SysTryReturnResult(NID_UI_CTRL, __pTokenEdit != null, E_SYSTEM, "A system error has occurred. The _Token instance is null.");
467 _TokenEditModel* pTokenEditModel = new (std::nothrow) _TokenEditModel();
468 SysTryReturnResult(NID_UI_CTRL, pTokenEditModel != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
470 SetModel(*pTokenEditModel);
472 SetKeypadEnabled(true);
474 float leftMargin = 0.0f;
475 float rightMargin = 0.0f;
476 float tokenTopMargin = 0.0f;
477 float tokenBottomMargin = 0.0f;
478 float tokenHeight = 0.0f;
479 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
480 Color focusTokenColor;
481 Bitmap* pTokenBgFocusBitmap = null;
483 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
484 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
485 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
486 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
487 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
488 GET_COLOR_CONFIG(TOKENEDIT::BG_HIGHLIGHTED, focusTokenColor);
490 // For drawing token in specific area
491 __clientRect.x = leftMargin;
492 __clientRect.y = tokenTopMargin;
493 __clientRect.width = __pTokenEdit->GetBoundsF().width - leftMargin - rightMargin;
494 __clientRect.height = __pTokenEdit->GetBoundsF().height - tokenTopMargin - tokenBottomMargin;
496 __initTextRect = GetTextBoundsF();
498 FloatRectangle tempDspRect(__initTextRect.x, __initTextRect.y, __clientRect.width, tokenHeight);
499 SetTextBounds(tempDspRect);
501 float textSize = 0.0f;
502 GET_SHAPE_CONFIG(TOKENEDIT::TEXT_SIZE, orientation, textSize);
504 __editContentFontSize = textSize;
506 _EditPresenter::SetTextSize(__editContentFontSize);
508 __pTokenList = new (std::nothrow) Collection::LinkedList();
509 SysTryCatch(NID_UI_CTRL, __pTokenList != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
513 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgBitmap);
514 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
516 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_NORMAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgNormalEffectBitmap);
517 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
519 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_PRESSED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgPressedEffectBitmap);
520 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
522 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pTokenBgFocusBitmap);
523 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
525 __pTokenBgReplacementFocusBitmap = _BitmapImpl::GetColorReplacedBitmapN(
526 *pTokenBgFocusBitmap,Color::GetColor(COLOR_ID_MAGENTA), focusTokenColor);
527 SysTryCatch(NID_UI_CTRL, __pTokenBgReplacementFocusBitmap != null, , r, "[%s] Propagating.", GetErrorMessage(r));
529 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_FOCUS_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgFocusEffectBitmap);
530 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
532 delete pTokenBgFocusBitmap;
533 pTokenBgFocusBitmap = null;
536 __isTokenEditPresenterInitialized = true;
538 __previousCursorPosition = GetCursorPosition();
544 delete pTokenEditModel;
545 pTokenEditModel = null;
547 delete __pTokenBgBitmap;
548 __pTokenBgBitmap = null;
550 delete __pTokenBgNormalEffectBitmap;
551 __pTokenBgNormalEffectBitmap = null;
553 delete __pTokenBgPressedEffectBitmap;
554 __pTokenBgPressedEffectBitmap = null;
556 delete pTokenBgFocusBitmap;
557 pTokenBgFocusBitmap = null;
559 delete __pTokenBgReplacementFocusBitmap;
560 __pTokenBgReplacementFocusBitmap = null;
566 _TokenEditPresenter::DrawText(void)
568 bool isCustomBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_NORMAL);
569 //Checking IsBlocked() is additional check for handler movement in token edit mode
570 if ((__isEditingToken) && (__editingTokenIndex >= 0))
572 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
575 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
576 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element of token.");
578 Canvas* pTokenCanvas = pTokenVisualElement->GetCanvasN();
579 SysTryReturnVoidResult(NID_UI_CTRL, pTokenCanvas != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get canvas of the token.");
581 FloatRectangle tokenRect(0.0f, 0.0f, pToken->displayRect.width, pToken->displayRect.height);
582 pTokenCanvas->SetBackgroundColor(Color(0));
583 pTokenCanvas->Clear();
585 Color selectedTokenColor = GetTokenEditColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED);
586 Bitmap* pReplacementColorBackgroundBitmap = null;
587 if (__pTokenBgBitmap)
589 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), selectedTokenColor);
591 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
593 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
597 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
602 pTokenCanvas->FillRectangle(selectedTokenColor, tokenRect);
605 if (__pTokenBgPressedEffectBitmap && (!isCustomBitmap))
607 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgPressedEffectBitmap))
609 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
613 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
617 _EditPresenter::DrawText(*pTokenCanvas);
622 delete pReplacementColorBackgroundBitmap;
627 _VisualElement* pTextVisualElement = null;
628 pTextVisualElement = GetTextVisualElement();
629 if (pTextVisualElement)
631 _EditPresenter::DrawText();
635 Canvas* pCanvas = __pTokenEdit->GetCanvasN();
636 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element of Control.");
638 _EditPresenter::DrawText(*pCanvas);
647 _TokenEditPresenter::Draw(Canvas& canvas)
649 if (!IsInitialized())
651 InitializeAtFirstDrawing();
653 if (IsFocused() == true)
659 canvas.SetBackgroundColor(Color(0, 0, 0, 0));
662 DrawBackground(canvas);
666 if (__pDescriptionTextTextObject->GetTextLength() != 0)
668 DrawDescriptionText();
671 if (GetTokenCount() != 0)
676 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
677 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
679 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
680 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
682 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
686 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
687 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get visual element of token.");
689 if (__isEditingToken)
691 Canvas* pTokenCanvas = pTokenVisualElement->GetCanvasN();
692 SysTryReturnResult(NID_UI_CTRL, pTokenCanvas != null, E_SYSTEM, "A system error has occurred. Failed to get canvas of the token.");
694 _EditPresenter::DrawText(*pTokenCanvas);
709 SysTryReturnResult(NID_UI_CTRL, !__isEditingToken, E_SYSTEM, "An invalid argument is given.");
715 if (__isTokenEditingFinished)
717 __isEditingToken = false;
718 __editingTokenIndex = -1;
719 _EditPresenter::SetTextSize(__editContentFontSize);
721 __isTokenEditingFinished = false;
728 _TokenEditPresenter::DrawToken(int count)
730 int drawStartIndex = 0;
732 float tokenTextLeftMargin = 0.0f;
733 float tokenVerticalSpacing = 0.0f;
734 bool isCustomBitmap = false;
735 bool isCustomFocusBitmap = false;
737 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
739 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
741 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
742 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
744 isCustomBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_NORMAL);
745 isCustomFocusBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_FOCUS);
748 if (__drawFocusState)
750 __pTokenEdit->RefreshFocusUi();
755 tokenCount = __pTokenList->GetCount();
762 Color normalTokenColor;
763 Color selectedTokenColor;
765 for (int i = drawStartIndex; i < tokenCount; i++)
767 Bitmap* pReplacementColorBackgroundBitmap = null;
769 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
770 if (pToken == null || pToken->pTextObject == null)
772 SysLog(NID_UI_CTRL, "[E_SYSTEM] The _Token instance is null");
776 normalTokenColor = GetTokenEditColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL);
777 selectedTokenColor = GetTokenEditColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED);
779 _VisualElement* pTokenElement = pToken->GetVisualElement();
780 if (pTokenElement == null)
782 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. The _VisualElement instance is null");
786 bool isSelected = false;
787 Canvas* pTokenCanvas = pTokenElement->GetCanvasN();
788 if (pTokenCanvas == null)
790 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. The Canvas instance is null");
793 FloatRectangle tokenRect(0.0f, 0.0f, pToken->displayRect.width, pToken->displayRect.height);
794 pTokenCanvas->SetBackgroundColor(Color(0));
795 pTokenCanvas->Clear();
797 if (__pressedTokenIndex == i && IsFocused())
799 if (__pTokenBgBitmap)
801 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), selectedTokenColor);
803 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
805 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
809 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
814 pTokenCanvas->FillRectangle(selectedTokenColor, tokenRect);
818 if (__pTokenBgPressedEffectBitmap && (!isCustomBitmap))
820 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgPressedEffectBitmap))
822 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
826 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
834 if (__pTokenBgBitmap)
836 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), normalTokenColor);
838 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
840 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
844 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
849 pTokenCanvas->FillRectangle(normalTokenColor, tokenRect);
853 if (__pTokenBgNormalEffectBitmap && (!isCustomBitmap))
855 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgNormalEffectBitmap))
857 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgNormalEffectBitmap);
861 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgNormalEffectBitmap);
866 if (__focusedTokenIndex == i && __drawFocusState && (!__isEditingToken))
868 if (__pTokenBgReplacementFocusBitmap)
870 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgReplacementFocusBitmap))
872 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgReplacementFocusBitmap);
876 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgReplacementFocusBitmap);
880 if (__pTokenBgFocusEffectBitmap && (!isCustomFocusBitmap))
882 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgFocusEffectBitmap))
884 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgFocusEffectBitmap);
888 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgFocusEffectBitmap);
894 pTokenElement->SetAnimationProvider(null);
895 if (pToken->isImplicitAnimation)
897 VisualElementAnimation* pAnimation = CreateAnimationN(*pTokenElement, true);
898 pTokenElement->AddAnimation(*pAnimation);
900 pToken->isImplicitAnimation = false;
903 if (!__isEditingToken || __pressedTokenIndex != i)
906 FloatRectangle textRect(0.0f, 0.0f, pToken->displayRect.width - ((tokenTextLeftMargin * 2.0f)), pToken->displayRect.height - tokenVerticalSpacing);
908 textRect.x += tokenTextLeftMargin;
909 textRect.y += (tokenVerticalSpacing / 2.0f);
913 textColor = GetTokenEditTextColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED);
917 textColor = GetTokenEditTextColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL);
920 pToken->pTextObject->SetForegroundColor(textColor, 0, pToken->pTextObject->GetTextLength());
921 pToken->pTextObject->SetBounds(textRect);
922 pToken->pTextObject->Compose();
923 pToken->pTextObject->Draw(*_CanvasImpl::GetInstance(*pTokenCanvas));
926 pTokenElement->SetFlushNeeded();
929 delete pReplacementColorBackgroundBitmap;
930 pReplacementColorBackgroundBitmap = null;
936 _TokenEditPresenter::GetTokenEditColor(const ExpandableEditAreaTokenStatus status) const
938 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, Color(0, 0, 0, 0), E_INVALID_STATE, "[E_INVALID_STATE] _TokenEdit is in an invalid state.");
942 if (status == EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL)
944 color = __pTokenEdit->GetTokenColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL);
948 color = __pTokenEdit->GetTokenColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED);
955 _TokenEditPresenter::GetTokenEditTextColor(const ExpandableEditAreaTokenStatus status) const
957 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, Color(0, 0, 0, 0), E_INVALID_STATE, "[E_INVALID_STATE] _TokenEdit is in an invalid state.");
961 if (status == EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL)
963 color = __pTokenEdit->GetTokenTextColor();
967 color = __pTokenEdit->GetSelectedTokenTextColor();
974 _TokenEditPresenter::MakeToken(const String& tokenString)
976 SysTryReturnResult(NID_UI_CTRL, __pTokenEdit != null, E_INVALID_STATE, "_TokenEdit is in an invalid state.");
977 result r = E_SUCCESS;
981 int tokenLength = tokenString.GetLength();
982 SysTryReturnResult(NID_UI_CTRL, tokenLength, E_INVALID_ARG, "Invalid argument is used. Token length is (%d)", tokenLength);
984 String inputTokenString = tokenString;
985 String replacementString = inputTokenString;
988 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
992 inputTokenString = replacementString;
995 if (inputTokenString.GetLength() <= 0)
998 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to clear text object.", GetErrorMessage(r));
1000 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
1001 return E_INVALID_ARG;
1004 _Token* pToken = new (std::nothrow) _Token();
1005 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1007 r = pToken->Construct(inputTokenString, GetFont());
1008 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct token.", GetErrorMessage(r));
1010 r = __pTokenList->Add(static_cast< Object& >(*pToken));
1011 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1013 tokenCount = __pTokenList->GetCount();
1014 index = tokenCount - 1;
1016 r = CalculateTokenPositionFromIndex(index);
1017 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to calculate token position.", GetErrorMessage(r));
1019 r = TrimTokenAndAdjustEllipsisAt(index);
1020 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to trim token.", GetErrorMessage(r));
1022 r = InitializeTokenVisibilityAt(index);
1023 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to initialize token visibility.", GetErrorMessage(r));
1025 r = SetInitialBounds();
1026 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds.", GetErrorMessage(r));
1029 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to clear text object.", GetErrorMessage(r));
1031 r = AdjustFlexibleHeight();
1032 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process to resize.", GetErrorMessage(r));
1034 r = CheckTokenScrolling();
1035 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process scroll.", GetErrorMessage(r));
1037 AppendTokenAccessibilityElement();
1038 UpdateTokenAccessibilityBounds();
1043 __pTokenList->Remove(*pToken);
1052 _TokenEditPresenter::MakeToken(void)
1054 result r = E_SUCCESS;
1056 String tempToken(GetText());
1057 r = MakeToken(tempToken);
1063 _TokenEditPresenter::AppendToken(const Tizen::Base::String& token)
1065 result r = E_SUCCESS;
1067 r = MakeToken(token);
1068 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1070 if (__editingTokenIndex >= 0)
1072 SetEditingTokenTextBounds(__editingTokenIndex);
1073 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1080 _TokenEditPresenter::InsertTokenAt(int index, const String& token, bool isUser)
1082 SysTryReturnResult(NID_UI_CTRL, index >= 0, E_INVALID_ARG, "Invalid argument is used. index is (%d).", index);
1083 SysTryReturnResult(NID_UI_CTRL, token.GetLength() > 0, E_INVALID_ARG, "Invalid argument is used. Token length is (%d).", token.GetLength());
1085 result r = E_SUCCESS;
1087 _Token* pToken = new (std::nothrow) _Token();
1088 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1090 r = pToken->Construct(token, GetFont());
1091 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct token.", GetErrorMessage(r));
1093 r = __pTokenList->InsertAt(*pToken, index);
1094 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to insert token.", GetErrorMessage(r));
1098 r = CalculateTokenPositionFromIndex(index);
1099 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to calculate token position.", GetErrorMessage(r));
1101 r = TrimTokenAndAdjustEllipsisAt(index);
1102 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to trim token.", GetErrorMessage(r));
1104 r = InitializeTokenVisibilityAt(index);
1105 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to initialize token visibility.", GetErrorMessage(r));
1107 r = SetInitialBounds();
1108 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds.", GetErrorMessage(r));
1110 r = AdjustFlexibleHeight();
1111 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process to resize.", GetErrorMessage(r));
1113 r = CheckTokenScrolling();
1114 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process scroll.", GetErrorMessage(r));
1116 for (int i = 0; i < GetTokenCount(); i++)
1118 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
1119 SysTryCatch(NID_UI_CTRL, pToken != null, , r = E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
1121 r = pToken->SetBounds(pToken->displayRect);
1122 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds", GetErrorMessage(r));
1125 InsertTokenAccessibilityElementAt(index);
1129 if (__editingTokenIndex >= 0)
1131 if (index <= __editingTokenIndex)
1133 __editingTokenIndex++;
1135 __pressedTokenIndex = __editingTokenIndex;
1137 SetEditingTokenTextBounds(__editingTokenIndex);
1138 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1140 else if (__pressedTokenIndex >= index)
1142 __pressedTokenIndex++;
1144 else if ((__focusedTokenIndex >= index) && __drawFocusState)
1146 __focusedTokenIndex++;
1153 __pTokenList->Remove(*pToken);
1162 _TokenEditPresenter::GetTokenAt(int index) const
1165 SysTryReturn(NID_UI_CTRL, index >= 0 && index < __pTokenList->GetCount(), tempString, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] index (%d) is out of range.", index);
1167 _Token* pToken = null;
1168 pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
1171 tempString = pToken->GetText();
1178 _TokenEditPresenter::GetTokenCount(bool isInvokedByApp) const
1180 if (!isInvokedByApp)
1182 return __pTokenList->GetCount();
1186 if (__isAnimationInProgress)
1188 return __pTokenList->GetCount() - 1;
1192 return __pTokenList->GetCount();
1198 _TokenEditPresenter::GetSelectedTokenIndex(void) const
1200 return __pressedTokenIndex;
1204 _TokenEditPresenter::IsTokenEditModeEnabled(void) const
1206 return __isEditModeEnabled;
1210 _TokenEditPresenter::RemoveTokenAt(int index, bool isClearText)
1212 result r = E_SUCCESS;
1213 SysTryReturnResult(NID_UI_CTRL, index >= 0 && index < __pTokenList->GetCount(), E_OUT_OF_RANGE, "index (%d) is out of range.", index);
1215 if (index == __editingTokenIndex && isClearText)
1217 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
1218 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
1220 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
1221 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
1223 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
1224 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1226 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
1227 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1229 __editingTokenIndex = -1;
1230 __isEditingToken = false;
1231 __pressedTokenIndex = -1;
1232 __isTokenEditingFinished = true;
1235 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Failed to clear text object.");
1237 _EditPresenter::SetTextSize(__editContentFontSize);
1240 r = __pTokenList->RemoveAt(index, true);
1241 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove token.");
1243 r = CalculateTokenPositionFromIndex(index);
1244 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to calculate token position.");
1246 r = SetInitialBounds();
1247 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
1249 _Token* pToken = null;
1251 for (int i = 0; i < GetTokenCount(); i++)
1253 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
1254 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
1256 r = pToken->SetBounds(pToken->displayRect);
1257 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds");
1260 r = AdjustFlexibleHeight();
1261 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to process to resize.");
1263 r = CheckTokenScrolling();
1264 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to process scroll.");
1266 RemoveTokenAccessibilityElementAt(index);
1267 UpdateTokenAccessibilityBounds();
1271 if (index > __editingTokenIndex)
1273 SetEditingTokenTextBounds(__editingTokenIndex);
1274 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1276 if (index < __editingTokenIndex)
1278 if (__editingTokenIndex > 0)
1280 __editingTokenIndex--;
1281 __pressedTokenIndex = __editingTokenIndex;
1283 SetEditingTokenTextBounds(__editingTokenIndex);
1284 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1287 else if (index == __pressedTokenIndex)
1289 __pressedTokenIndex = -1;
1291 SetCursorDisabled(false);
1294 else if (index >= 0 && index < __pressedTokenIndex)
1296 __pressedTokenIndex--;
1299 if (__drawFocusState)
1301 if (index == __focusedTokenIndex)
1303 __focusedTokenIndex = -1;
1305 SetCursorDisabled(false);
1308 else if(index >= 0 && index < __focusedTokenIndex)
1310 __focusedTokenIndex--;
1314 else if (index == __pressedTokenIndex)
1316 __pressedTokenIndex = -1;
1318 SetCursorDisabled(false);
1321 else if ((index == __focusedTokenIndex) && __drawFocusState)
1323 __focusedTokenIndex = -1;
1325 SetCursorDisabled(false);
1333 _TokenEditPresenter::SetTokenSelected(int index, bool selected)
1335 result r = E_SUCCESS;
1337 SysTryReturnResult(NID_UI_CTRL, index >= 0 && index < __pTokenList->GetCount(), E_OUT_OF_RANGE, "index (%d) is out of range.");
1339 if (selected == false)
1341 __pressedTokenIndex = -1;
1345 __pressedTokenIndex = index;
1352 _TokenEditPresenter::SetTokenEditModeEnabled(bool enable)
1354 result r = E_SUCCESS;
1356 __isEditModeEnabled = enable;
1362 _TokenEditPresenter::CalculateTokenPositionFromIndex(int startIndex, bool leftWard)
1364 result r = E_SUCCESS;
1366 int tokenCount = __pTokenList->GetCount();
1368 float leftMargin = 0.0f;
1369 float rightMargin = 0.0f;
1370 float tokenTopMargin = 0.0f;
1371 float tokenBottomMargin = 0.0f;
1372 float tokenHeight = 0.0f;
1373 float tokenVerticalSpacing = 0.0f;
1374 float tokenHorizontalSpacing = 0.0f;
1375 float tokenTextLeftMargin = 0.0f;
1376 float tokenTextRightMargin = 0.0f;
1377 float descriptionTextRightMargin = 0.0f;
1378 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1380 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
1381 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
1382 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1383 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
1384 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1385 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1386 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HORIZONTAL_SPACING, orientation, tokenHorizontalSpacing);
1387 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1388 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1389 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_RIGHT_MARGIN, orientation, descriptionTextRightMargin);
1391 SysTryReturn(NID_UI_CTRL, startIndex >= 0 && startIndex <= tokenCount, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. startIndex = (%d)", startIndex);
1393 _Token* pToken = null;
1394 _Token* pPreviousToken = null;
1396 int index = startIndex;
1398 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
1399 String titleText = __pTokenEdit->GetTitleText();
1401 if (!_FloatCompare(GetDescriptionTextRect().width, __previousTitleWidth))
1403 __descriptionTextRectForScroll = GetDescriptionTextRect();
1404 __previousTitleWidth = GetDescriptionTextRect().width;
1407 bool findPrevTokenLoopFlag = true;
1408 for (; index < tokenCount; index++)
1410 pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
1411 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
1415 // TODO : description text (title style inner)
1416 if (titleText.GetLength())
1418 pToken->displayRect.x = __descriptionTextRectForScroll.x + __descriptionTextRectForScroll.width + descriptionTextRightMargin;
1419 pToken->displayRect.y = __descriptionTextRectForScroll.y + __scrollValue;
1421 else // Set description text.
1423 pToken->displayRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1424 pToken->displayRect.y = tokenTopMargin + __scrollValue + __pTokenEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN) + __lineSpacing;
1427 pToken->displayRect.width = tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin;
1432 if (findPrevTokenLoopFlag)
1434 pPreviousToken = static_cast< _Token* >(__pTokenList->GetAt(index - 1));
1435 findPrevTokenLoopFlag = false;
1438 float tempTextWidth = tokenEditBounds.width - pPreviousToken->displayRect.x - pPreviousToken->displayRect.width - tokenHorizontalSpacing - rightMargin - __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1439 if (tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin > tempTextWidth) // Line change
1441 pToken->displayRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1442 pToken->displayRect.y = pPreviousToken->displayRect.y + tokenHeight + tokenVerticalSpacing + __lineSpacing;
1447 pToken->displayRect.x = pPreviousToken->displayRect.x + pPreviousToken->displayRect.width +
1448 tokenHorizontalSpacing;
1449 pToken->displayRect.y = pPreviousToken->displayRect.y;
1452 pToken->displayRect.width = tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin;
1455 pToken->displayRect.height = tokenHeight;
1457 pPreviousToken = pToken;
1460 for (int i = 0; i < __pTokenList->GetCount(); i++)
1462 TrimTokenAndAdjustEllipsisAt(i);
1463 InitializeTokenVisibilityAt(i);
1469 _TokenEditPresenter::InitializeTokenVisibilityAt(int ndex)
1471 result r = E_SUCCESS;
1473 _Token* pToken = null;
1474 pToken = static_cast< _Token* >(__pTokenList->GetAt(ndex));
1475 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
1477 r = pToken->SetBounds(pToken->displayRect);
1478 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to set bounds", GetErrorMessage(r));
1480 _VisualElement* pRootElement = __pTokenEdit->GetVisualElement();
1481 SysTryReturn(NID_UI_CTRL, pRootElement, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
1483 _VisualElement* pVisualElement = pToken->GetVisualElement();
1484 SysTryReturn(NID_UI_CTRL, pVisualElement, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element.");
1486 pVisualElement->SetShowState(true);
1488 r = pRootElement->AttachChild(*pVisualElement);
1489 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to add child", GetErrorMessage(r));
1495 _TokenEditPresenter::GetMaxTextHeight(void)
1498 float maxHeight = __editContentFontSize;
1501 SysTryReturn(NID_UI_CTRL, pFont != null, maxHeight, E_SYSTEM, "[E_SYSTEM] Failed to get Font instance.");
1503 maxHeight = pFont->GetMaxHeightF();
1509 _TokenEditPresenter::ResetTextBounds(void)
1511 if (!__isEditingToken)
1513 result r = SetInitialBounds();
1514 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occured. Failed to set margin.");
1520 _TokenEditPresenter::SetInitialBounds(void)
1522 result r = E_SUCCESS;
1524 float leftMargin = 0.0f;
1525 float rightMargin = 0.0f;
1526 float tokenTopMargin = 0.0f;
1527 float tokenHeight = 0.0f;
1528 float tokenMinWidth = 0.0f;
1529 float tokenVerticalSpacing = 0.0f;
1530 float tokenHorizontalSpacing = 0.0f;
1531 float tokenTextLeftMargin = 0.0f;
1532 float tokenTextRightMargin = 0.0f;
1533 float textBoundsAlignValue = 0.0f;
1534 float descriptionTextRightMargin = 0.0f;
1535 _ControlOrientation orientation = GetEditView()->GetOrientation();
1537 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
1538 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
1539 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1540 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1541 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_MIN_WIDTH, orientation, tokenMinWidth);
1542 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1543 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HORIZONTAL_SPACING, orientation, tokenHorizontalSpacing);
1544 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1545 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1546 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_RIGHT_MARGIN, orientation, descriptionTextRightMargin);
1548 float textObjectMaxHeight = GetMaxTextHeight();
1549 textBoundsAlignValue = (tokenHeight - textObjectMaxHeight) / 2.0f;
1553 int tokenCount = __pTokenList->GetCount();
1555 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
1556 FloatRectangle tokenTextRect = tokenEditBounds;
1558 if (tokenCount == 0)
1560 if (__pTokenEdit->GetTitleText().GetLength())
1562 FloatRectangle descriptionTextRect = GetDescriptionTextRect();
1563 tokenTextRect.x = descriptionTextRect.x + descriptionTextRect.width + descriptionTextRightMargin;
1567 tokenTextRect.x = leftMargin + __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_LEFT_MARGIN);
1570 tokenTextRect.y = tokenTopMargin + __pTokenEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN) + textBoundsAlignValue;
1571 tokenTextRect.width -= tokenTextRect.x + rightMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1572 tokenTextRect.height = textObjectMaxHeight;
1574 SetTextBounds(tokenTextRect);
1575 //set cursor bounds with tokenTextRect
1576 __pTokenEdit->SetCursorAccessibilityBounds(tokenTextRect);
1580 _Token* pToken = null;
1581 // SetTextBounds from last token
1582 pToken = static_cast< _Token* >(__pTokenList->GetAt(tokenCount - 1));
1583 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
1585 float tempTextRectWidth = 0.0f;
1586 tempTextRectWidth = tokenEditBounds.width - pToken->displayRect.x - pToken->displayRect.width - tokenHorizontalSpacing - rightMargin - __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1587 if (tokenMinWidth > tempTextRectWidth) // Line change
1589 tokenTextRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1590 tokenTextRect.y = pToken->displayRect.y + tokenHeight + tokenVerticalSpacing + __lineSpacing + textBoundsAlignValue;
1594 tokenTextRect.x = pToken->displayRect.x + pToken->displayRect.width + tokenHorizontalSpacing;
1595 tokenTextRect.y = pToken->displayRect.y + textBoundsAlignValue;
1598 tokenTextRect.width -= tokenTextRect.x + rightMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1599 tokenTextRect.height = textObjectMaxHeight;
1601 SetTextBounds(tokenTextRect);
1602 if (__pressedTokenIndex < 0) // Set cursor as global focused element if no token is selected
1604 __pTokenEdit->SetCursorAccessibilityBounds(tokenTextRect);
1610 r = _EditPresenter::SetInitialBounds();
1617 _TokenEditPresenter::SetDescriptionTextRect(const FloatRectangle& rect)
1619 result r = E_SUCCESS;
1621 __descriptionTextRect = rect;
1627 _TokenEditPresenter::GetDescriptionTextRect() const
1629 return __descriptionTextRect;
1633 _TokenEditPresenter::GetTextBounds(void) const
1635 if ((__isPopupVisible == true || __isLongPressed == true) && __pressedTokenIndex >= 0)
1637 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__pressedTokenIndex));
1638 SysTryReturn(NID_UI_CTRL, pToken, Rectangle(), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Unable to get valid token.");
1640 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1641 float tokenTextLeftMargin = 0.0f;
1642 float tokenTextVerticalMargin = 0.0f;
1643 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1644 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenTextVerticalMargin);
1646 FloatRectangle textBoundsF(pToken->displayRect.x + tokenTextLeftMargin, pToken->displayRect.y + (tokenTextVerticalMargin / 2.0f), pToken->displayRect.width - (tokenTextLeftMargin * 2.0f), pToken->displayRect.height - tokenTextVerticalMargin);
1647 Rectangle textBounds = _CoordinateSystemUtils::ConvertToInteger(textBoundsF);
1653 return _EditPresenter::GetTextBounds();
1658 _TokenEditPresenter::GetTextBoundsF(void) const
1660 if ((__isPopupVisible == true || __isLongPressed == true) && __pressedTokenIndex >= 0)
1662 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__pressedTokenIndex));
1663 SysTryReturn(NID_UI_CTRL, pToken, FloatRectangle(), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Unable to get valid token.");
1665 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1666 int tokenTextLeftMargin = 0;
1667 int tokenTextVerticalMargin = 0;
1668 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1669 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenTextVerticalMargin);
1671 FloatRectangle textBounds(pToken->displayRect.x + tokenTextLeftMargin, pToken->displayRect.y + (tokenTextVerticalMargin / 2.0f), pToken->displayRect.width - (tokenTextLeftMargin * 2.0f), pToken->displayRect.height - tokenTextVerticalMargin);
1677 return _EditPresenter::GetTextBoundsF();
1682 _TokenEditPresenter::CutText(void)
1684 if (__isEditingToken)
1686 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
1687 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
1689 pToken->isTextCut = true;
1691 return _EditPresenter::CutText();
1695 _TokenEditPresenter::SetLineSpacing(int linePixelGap)
1697 __lineSpacing = linePixelGap;
1703 _TokenEditPresenter::SetLineSpacing(float linePixelGap)
1705 __lineSpacing = linePixelGap;
1711 _TokenEditPresenter::GetLineSpacing(void) const
1713 int lineSpacing = _CoordinateSystemUtils::ConvertToInteger(__lineSpacing);
1718 _TokenEditPresenter::GetLineSpacingF(void) const
1720 return __lineSpacing;
1723 VisualElementAnimation*
1724 _TokenEditPresenter::CreateAnimationN(VisualElement& source, bool create)
1726 VisualElementAnimation* pAnimation = null;
1727 VisualElementAnimationGroup* pAnimationGroup = new (std::nothrow) VisualElementAnimationGroup();
1728 SysTryReturn(NID_UI_CTRL, pAnimationGroup, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1730 pAnimationGroup->SetDuration(ANIMATION_DURATION_BOUNDS);
1731 if (__pTimingFunction == null)
1733 __pTimingFunction = new (std::nothrow) SineTimingFunction();
1734 SysTryReturn(NID_UI_CTRL, __pTimingFunction, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1737 if (pAnimationGroup != null)
1739 VisualElementPropertyAnimation* pOpacityAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1740 SysTryReturn(NID_UI_CTRL, pOpacityAnimation, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1742 pOpacityAnimation->SetPropertyName("opacity");
1745 pOpacityAnimation->SetStartValue(Variant(1.0f));
1746 pOpacityAnimation->SetEndValue(Variant(0.0f));
1750 pOpacityAnimation->SetStartValue(Variant(0.0f));
1751 pOpacityAnimation->SetEndValue(Variant(1.0f));
1754 pOpacityAnimation->SetDuration(ANIMATION_DURATION_OPACITY);
1755 pOpacityAnimation->SetTimingFunction(__pTimingFunction);
1756 pAnimationGroup->AddAnimation(*pOpacityAnimation);
1757 delete pOpacityAnimation;
1759 VisualElementPropertyAnimation* pBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1760 SysTryReturn(NID_UI_CTRL, pBoundsAnimation, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1762 pBoundsAnimation->SetPropertyName("bounds");
1763 FloatRectangle startValue = source.GetBounds();
1764 startValue.x = startValue.x + startValue.width * 0.05;
1765 startValue.y = startValue.y + startValue.height * 0.05;
1766 startValue.width = startValue.width * 0.9;
1767 startValue.height = startValue.height * 0.9;
1771 pBoundsAnimation->SetStartValue(Variant(source.GetBounds()));
1772 pBoundsAnimation->SetEndValue(Variant(startValue));
1773 pBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1777 pBoundsAnimation->SetStartValue(Variant(startValue));
1778 pBoundsAnimation->SetEndValue(Variant(source.GetBounds()));
1781 pBoundsAnimation->SetDuration(ANIMATION_DURATION_BOUNDS);
1782 pBoundsAnimation->SetTimingFunction(__pTimingFunction);
1783 pAnimationGroup->AddAnimation(*pBoundsAnimation);
1785 delete pBoundsAnimation;
1787 pAnimation = pAnimationGroup;
1793 _TokenEditPresenter::CalculateDescriptionTextRect(const String& descriptionText)
1795 result r = E_SUCCESS;
1797 TextSimple* pSimpleText = null;
1798 float leftMargin = 0.0f;
1799 float tokenTopMargin = 0.0f;
1800 float tokenHeight = 0.0f;
1801 float tokenVerticalSpacing = 0.0f;
1802 float tokenTextLeftMargin = 0.0f;
1803 float tokenTextRightMargin = 0.0f;
1804 float tokenTitleWidth = 0.0f;
1805 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1807 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1808 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
1809 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1810 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1811 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1812 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1813 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TITLE_RECT_WIDTH, orientation, tokenTitleWidth);
1815 int length = descriptionText.GetLength();
1816 FloatDimension textSize;
1818 wchar_t* pTempString = const_cast< wchar_t* >(descriptionText.GetPointer());
1820 SysAssertf(__pDescriptionTextTextObject != null, "The TextObject instance is null.");
1822 __pDescriptionTextTextObject->RemoveAll(true);
1823 pSimpleText = new (std::nothrow) TextSimple(pTempString, length, TEXT_ELEMENT_SOURCE_TYPE_INTERNAL);
1824 __pDescriptionTextTextObject->AppendElement(*pSimpleText);
1826 textSize = __pDescriptionTextTextObject->GetTextExtentF(0, length);
1827 r = __pDescriptionTextTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1828 r = __pDescriptionTextTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
1830 __descriptionTextRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1831 __descriptionTextRect.y = tokenTopMargin + __pTokenEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN);
1832 if (textSize.width > tokenTitleWidth)
1834 textSize.width = tokenTitleWidth;
1835 __pDescriptionTextTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
1838 __descriptionTextRect.width = tokenTextLeftMargin + textSize.width + tokenTextRightMargin;
1839 __descriptionTextRect.height = tokenHeight;
1840 __pDescriptionTextTextObject->SetBounds(__descriptionTextRect);
1842 if (__pDescriptionTextTextObject->IsChanged())
1844 _EditPresenter::StopTitleSlidingTimer();
1845 __isTitleSliding = false;
1848 r = __pDescriptionTextTextObject->Compose();
1854 _TokenEditPresenter::IsGuideTextActivated(void) const
1856 bool isGuideTextActivated = _EditPresenter::IsGuideTextActivated();
1858 if (__isTokenEditPresenterInitialized)
1860 if (GetTokenCount())
1866 return isGuideTextActivated;
1870 _TokenEditPresenter::DrawDescriptionText(void)
1872 result r = E_SUCCESS;
1873 FloatRectangle tempDescriptionTextRect;
1874 FloatRectangle descriptionTextRect(__descriptionTextRect);
1875 Canvas* pDescriptionTextCanvas = null;
1877 Font* pDescriptionFont = null;
1878 TextObjectActionType titleAction;
1879 _VisualElement* pRootElement = null;
1881 if (__pDescriptionTextTextObject->GetFont(0)->GetFaceName() != GetTitleFontFaceName())
1883 float descriptionTextSize = 0.0f;
1884 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, descriptionTextSize);
1886 pDescriptionFont = GetFont();
1887 if (pDescriptionFont)
1889 float editFontSize = GetTextSize();
1890 (_FontImpl::GetInstance(*pDescriptionFont))->SetSize(descriptionTextSize);
1892 r = __pDescriptionTextTextObject->SetFont(pDescriptionFont, 0, __pDescriptionTextTextObject->GetTextLength());
1893 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. SetFont failed");
1895 (_FontImpl::GetInstance(*pDescriptionFont))->SetSize(editFontSize);
1899 pRootElement = __pTokenEdit->GetVisualElement();
1900 SysTryCatch(NID_UI_CTRL, pRootElement, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
1902 if (!__pDescriptionTextVisualElement)
1904 __pDescriptionTextVisualElement = new (std::nothrow) _VisualElement();
1905 SysTryCatch(NID_UI_CTRL, __pDescriptionTextVisualElement, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1906 r = __pDescriptionTextVisualElement->Construct();
1907 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[E_SYSTEM] A system error has occurred. Failed to construct _VisualElement");
1908 __pDescriptionTextVisualElement->SetImplicitAnimationEnabled(false);
1909 __pDescriptionTextVisualElement->SetShowState(true);
1911 r = pRootElement->AttachChild(*__pDescriptionTextVisualElement);
1912 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1915 descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
1916 __pDescriptionTextVisualElement->SetBounds(descriptionTextRect);
1917 UpdateTitleAccessibilityBounds(descriptionTextRect); // Update title accessibility bounds to same as DescriptionTextVisualElement bounds
1919 pDescriptionTextCanvas = __pDescriptionTextVisualElement->GetCanvasN();
1920 if (pDescriptionTextCanvas == null)
1922 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to get canvas of an instance of _VisualElement.");
1926 tempDescriptionTextRect = __descriptionTextRect;
1927 tempDescriptionTextRect.x = 0.0f;
1928 tempDescriptionTextRect.y = 0.0f;
1930 titleAction = __pDescriptionTextTextObject->GetAction();
1932 pDescriptionTextCanvas->SetBackgroundColor(Color(0));
1933 pDescriptionTextCanvas->Clear();
1934 __pDescriptionTextTextObject->SetForegroundColor(__pTokenEdit->GetTitleTextColor(GetCurrentStatus()), 0, __pDescriptionTextTextObject->GetTextLength());
1936 if (IsFocused() == true)
1938 if (__pDescriptionTextTextObject->GetTextLengthAt(0) < __pDescriptionTextTextObject->GetTextLength())
1940 if (titleAction != TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT)
1942 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT);
1943 __pDescriptionTextTextObject->Compose();
1948 if (titleAction != TEXT_OBJECT_ACTION_TYPE_NONE)
1950 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
1951 __pDescriptionTextTextObject->Compose();
1955 if (!__isTitleSliding)
1957 _EditPresenter::StopTitleSlidingTimer();
1958 if (__pDescriptionTextTextObject->IsActionOn() == true)
1960 _EditPresenter::StartTitleSlidingTimer();
1961 __isTitleSliding = true;
1967 if (titleAction != TEXT_OBJECT_ACTION_TYPE_ABBREV)
1969 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1970 __pDescriptionTextTextObject->Compose();
1975 __pDescriptionTextTextObject->SetBounds(tempDescriptionTextRect);
1976 __pDescriptionTextTextObject->Draw(*_CanvasImpl::GetInstance(*pDescriptionTextCanvas));
1978 delete pDescriptionTextCanvas;
1983 if (__pDescriptionTextVisualElement != null)
1985 __pDescriptionTextVisualElement->Destroy();
1986 __pDescriptionTextVisualElement = null;
1993 _TokenEditPresenter::TrimTokenAndAdjustEllipsisAt(int index)
1995 result r = E_SUCCESS;
1997 float rightMargin = 0.0f;
1998 float tokenMinimumSize = 0.0f;
2000 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2001 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
2002 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_MIN_WIDTH, orientation, tokenMinimumSize);
2004 _Token* pToken = null;
2005 pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
2006 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
2008 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
2009 FloatRectangle tokenRect = pToken->displayRect;
2011 float remainWidth = tokenEditBounds.width - rightMargin - __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
2013 float dspTokenWidth = tokenRect.x + tokenRect.width;
2014 float dspTokenGap = dspTokenWidth - remainWidth;
2016 if (dspTokenGap > 0.0f)
2018 if (pToken->displayRect.width >= tokenMinimumSize)
2020 if ((pToken->displayRect.width - dspTokenGap) < tokenMinimumSize)
2022 pToken->displayRect.width = tokenMinimumSize;
2026 pToken->displayRect.width -= dspTokenGap;
2031 pToken->pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
2032 pToken->pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
2039 _TokenEditPresenter::GetTokenIndexFromCoordinate(const Point point) const
2041 int tokenIndex = -1;
2043 int tokenCount = __pTokenList->GetCount();
2044 for (int i = 0; i < tokenCount; i++)
2046 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2049 FloatRectangle tokenRect = pToken->displayRect;
2050 if (tokenRect.Contains(FloatPoint(point.x, point.y)))
2061 _TokenEditPresenter::SetEditingTokenTextBounds(int index, bool isSetText)
2063 result r = E_SUCCESS;
2065 float tokenHeight = 0.0f;
2066 float tokenVerticalSpacing = 0.0f;
2067 float tokenTextLeftMargin = 0.0f;
2068 float tokenFontSize = 0.0f;
2069 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2071 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
2072 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
2073 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
2074 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_SIZE, orientation, tokenFontSize);
2076 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
2077 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
2079 FloatRectangle tempTextDspRect;
2080 tempTextDspRect.x += tokenTextLeftMargin;
2081 tempTextDspRect.y += tokenVerticalSpacing / 2.0f;
2082 tempTextDspRect.width = pToken->displayRect.width - (tokenTextLeftMargin * 2.0f);
2083 tempTextDspRect.height = tokenHeight - tokenVerticalSpacing;
2087 if (!pToken->isTextCut)
2089 SetText(pToken->GetText());
2091 pToken->pTextObject->RemoveAll(true);
2094 _EditPresenter::SetTextSize(tokenFontSize);
2096 SetTextBounds(tempTextDspRect);
2102 _TokenEditPresenter::RecalculateTokenBounds(float position)
2104 result r = E_SUCCESS;
2106 __scrollValue = -position;
2108 int tokenCount = GetTokenCount();
2109 CalculateTokenPositionFromIndex(0);
2111 for (int i = 0; i < tokenCount; i++)
2113 _Token* pToken = null;
2114 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2118 pToken->SetBounds(pToken->displayRect);
2120 TrimTokenAndAdjustEllipsisAt(i);
2121 InitializeTokenVisibilityAt(i);
2124 if (__pDescriptionTextTextObject->GetTextLength() != 0)
2126 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2129 __pTokenEdit->Invalidate();
2131 r = SetInitialBounds();
2132 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
2138 _TokenEditPresenter::SetTokenBoundsByTouchInfo(const _TouchInfo& touchinfo)
2140 result r = E_SUCCESS;
2141 int currentYPosition = _CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()).y;
2143 if (_FloatCompare(__prevScrollValue, 0.0f))
2145 __prevScrollValue = currentYPosition;
2147 else // Adjust moved y position to all tokens.
2149 if (__isNeedToScroll) // Need to scroll
2151 float tempDefference = __prevScrollValue - currentYPosition;
2153 __prevScrollValue = currentYPosition;
2154 __scrollValue -= tempDefference;
2156 if (__scrollValue < -__maxScrollValue)
2158 __scrollValue = -__maxScrollValue;
2163 if (__scrollValue > 0.0f)
2165 __scrollValue = 0.0f;
2170 int tokenCount = GetTokenCount();
2171 CalculateTokenPositionFromIndex(0);
2172 for (int i = 0; i < tokenCount; i++)
2174 _Token* pToken = null;
2175 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2179 pToken->SetBounds(pToken->displayRect);
2181 TrimTokenAndAdjustEllipsisAt(i);
2182 InitializeTokenVisibilityAt(i);
2185 if (__pDescriptionTextTextObject->GetTextLength() != 0)
2187 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2190 __pTokenEdit->Invalidate();
2194 __prevScrollValue = 0.0f;
2195 __scrollValue = 0.0f;
2199 r = SetInitialBounds();
2200 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
2206 _TokenEditPresenter::ProcessTokeningByTouchEvent(const _Control& source, const _TouchInfo& touchinfo)
2208 int tokenIndex = GetTokenIndexFromCoordinate(_CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()));
2210 //Reset "longPressed" when Touch released on a different token after long gesture on a token
2211 if (__trackTokenIndex != tokenIndex)
2213 __isLongPressed = false;
2216 int prevPressedTokenIndex = __pressedTokenIndex;
2217 int prevEditedTokenIndex = __editingTokenIndex;
2219 result r = E_SUCCESS;
2222 if (__isEditModeEnabled && __pressedTokenIndex != -1 && __pressedTokenIndex == tokenIndex)
2224 //Comment below to Block Copy & Paste functionality in Token Edit mode
2225 __editingTokenIndex = __pressedTokenIndex;
2226 __isEditingToken = true;
2227 __isTokenEditingFinished = false;
2228 if (prevEditedTokenIndex != __editingTokenIndex)
2230 SetEditingTokenTextBounds(__editingTokenIndex);
2232 SetCursorDisabled(false);
2236 if (tokenIndex != -1)
2238 if (__isEditingToken && (prevPressedTokenIndex != tokenIndex)) // Selected another token while editing.
2240 __isPopupVisible = false;
2241 __isLongPressed = false;
2243 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2244 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
2246 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2247 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
2249 _Token* pToken = null;
2250 _VisualElement* pTokenVisualElement = null;
2252 pToken = static_cast< _Token* >(__pTokenList->GetAt(prevPressedTokenIndex));
2254 bool isParentChanged = false;
2257 pTokenVisualElement = pToken->GetVisualElement();
2258 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
2260 if (pCursorVisualElement->GetParent() == pTokenVisualElement)
2262 isParentChanged = true;
2263 result r = E_SUCCESS;
2264 r = pTokenVisualElement->DetachChild(*pCursorVisualElement);
2265 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2267 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2268 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2272 String inputTokenString = GetText();
2273 String replacementString = inputTokenString;
2274 bool enable = false;
2276 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
2279 inputTokenString = replacementString;
2282 __pressedTokenIndex = tokenIndex;
2284 r = RemoveTokenAt(prevPressedTokenIndex);
2285 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2287 if (inputTokenString.GetLength() > 0)
2289 r = InsertTokenAt(prevPressedTokenIndex, inputTokenString);
2290 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2292 pToken = static_cast< _Token* >(__pTokenList->GetAt(prevPressedTokenIndex));
2295 pToken->currTokenLength = inputTokenString.GetLength();
2300 //Flex height adjusted since token can move to another line
2301 AdjustFlexibleHeight();
2302 __editingTokenIndex = -1;
2303 __isTokenEditingFinished = true;
2304 __isEditingToken = false;
2305 _EditPresenter::SetTextSize(__editContentFontSize);
2307 SetCursorDisabled(true);
2311 __pressedTokenIndex = tokenIndex;
2312 if (GetText().GetLength() > 0 && __pressedTokenIndex != prevPressedTokenIndex)
2315 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2318 if ((__isEditingToken == true) && (__pressedTokenIndex != -1))
2320 r = AttachCursorToToken();
2321 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2324 if (__isEditingToken == false)
2326 SetCursorDisabled(true);
2332 __isPopupVisible = false;
2333 __isLongPressed = false;
2335 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2336 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
2338 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2339 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
2341 if (__isEditingToken)
2343 _Token* pToken = null;
2344 _VisualElement* pTokenVisualElement = null;
2346 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
2348 bool isParentChanged = false;
2351 pTokenVisualElement = pToken->GetVisualElement();
2352 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
2354 if (pCursorVisualElement->GetParent() == pTokenVisualElement)
2356 isParentChanged = true;
2357 result r = E_SUCCESS;
2358 r = pTokenVisualElement->DetachChild(*pCursorVisualElement);
2359 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2361 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2362 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2366 String inputTokenString = GetText();
2367 String replacementString = inputTokenString;
2368 bool enable = false;
2370 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
2373 inputTokenString = replacementString;
2375 __pressedTokenIndex = tokenIndex;
2377 RemoveTokenAt(__editingTokenIndex);
2379 if (inputTokenString.GetLength() > 0)
2381 InsertTokenAt(__editingTokenIndex, inputTokenString);
2383 if (isParentChanged)
2385 pToken->currTokenLength = inputTokenString.GetLength();
2389 __isEditingToken = false;
2390 __editingTokenIndex = -1;
2391 _EditPresenter::SetTextSize(__editContentFontSize);
2392 __isTokenEditingFinished = false;
2396 //Flex height adjusted since token can move to another line
2397 AdjustFlexibleHeight();
2399 SysTryReturnResult(NID_UI_CTRL, (inputTokenString.GetLength() > 0), E_INVALID_ARG, "Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
2405 __pressedTokenIndex = tokenIndex;
2406 if (pCursorVisualElement->GetParent() != pEditVisualElement)
2408 r = (pCursorVisualElement->GetParent())->DetachChild(*pCursorVisualElement);
2409 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2411 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2412 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2416 SetCursorDisabled(false);
2419 for (int i = 0; i < __pTokenList->GetCount(); i++)
2421 TrimTokenAndAdjustEllipsisAt(i);
2422 InitializeTokenVisibilityAt(i);
2429 _TokenEditPresenter::CheckTokenScrolling(bool scrollToCursorPosition)
2431 bool needToScroll = false;
2432 float tokenTopMargin = 0.0f;
2433 float tokenBottomMargin = 0.0f;
2434 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2436 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
2437 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
2439 int tokenCount = GetTokenCount();
2440 if (tokenCount == 0) // There is no token to scroll
2442 __isNeedToScroll = false;
2443 __maxScrollValue = 0.0f;
2444 __isTokenScrolling = false;
2449 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(tokenCount - 1));
2450 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
2452 float newScrollValue = 0.0f;
2454 if (scrollToCursorPosition)
2456 FloatRectangle cursorBounds;
2457 GetCursorBounds(false, cursorBounds);
2458 newScrollValue = cursorBounds.y + cursorBounds.height - __scrollValue + tokenBottomMargin - __pTokenEdit->GetBoundsF().height;
2459 __isScrollValueModified = true;
2463 newScrollValue = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin - __pTokenEdit->GetBoundsF().height;
2464 __isScrollValueModified = true;
2467 needToScroll = (newScrollValue > 0.0f) ? (true) : (false);
2469 __isNeedToScroll = needToScroll;
2471 if (__isNeedToScroll)
2473 __maxScrollValue = newScrollValue;
2474 __isTokenScrolling = true;
2476 RecalculateTokenBounds(__maxScrollValue);
2480 if (!_FloatCompare(__scrollValue, 0.0f))
2482 __scrollValue = 0.0f;
2483 __maxScrollValue = 0.0f; // To prevent unnecessary token scrolling.
2484 RecalculateTokenBounds(__scrollValue);
2485 __isTokenScrolling = false;
2493 _TokenEditPresenter::SetTokenVisualElementBounds(int index, const FloatRectangle& bounds)
2495 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
2496 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null.");
2498 return pToken->SetBounds(pToken->displayRect);
2502 _TokenEditPresenter::AdjustFlexibleHeight(void)
2504 result r = E_SUCCESS;
2506 FloatRectangle editRect = __pTokenEdit->GetBoundsF();
2507 FloatRectangle displayScrollBounds = GetDisplayScrollBoundsF();
2508 float calcHeight = CalculateFlexibleHeightF();
2510 if (!_FloatCompare(editRect.height, calcHeight))
2512 displayScrollBounds.height = calcHeight;
2513 SetScrollBarBounds(displayScrollBounds);
2515 editRect.height = calcHeight;
2516 if (!__isEditingToken)
2518 FloatRectangle editRectBounds = CoordinateSystem::AlignToDevice(editRect);
2519 r = SetFlexBounds(editRectBounds);
2527 _TokenEditPresenter::CalculateFlexibleHeightF(void)
2529 float tokenHeight = 0.0f;
2530 float tokenVerticalSpacing = 0.0f;
2531 float tokenTopMargin = 0.0f;
2532 float tokenBottomMargin = 0.0f;
2533 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2535 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
2536 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
2537 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
2538 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
2540 float height = 0.0f;
2541 int maxLinecount = GetMaxLineCount();
2542 float expectedEditHeight = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin;
2543 float initialHeight = GetInitialBoundsF().height;
2544 float maximumLineHeight = tokenTopMargin + maxLinecount * tokenHeight + tokenVerticalSpacing * (maxLinecount - 1) + tokenBottomMargin;
2546 if (initialHeight < expectedEditHeight)
2548 if (expectedEditHeight > maximumLineHeight)
2550 height = maximumLineHeight;
2554 height = expectedEditHeight;
2559 height = initialHeight;
2566 _TokenEditPresenter::DrawScrollBar(void)
2568 result r = E_SUCCESS;
2570 _Scroll* pScroll = GetScrollBar();
2571 if (pScroll == null)
2576 if (IsFocused() == false)
2578 if (__isTouchMoveInProgress == false)
2580 pScroll->SetScrollVisibility(false);
2585 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(GetTokenCount() - 1));
2591 float tokenBottomMargin = 0.0f;
2592 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, tokenBottomMargin);
2594 float totalHeight = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin;
2595 float dspHeight = __pTokenEdit->GetBoundsF().height;
2596 float firstDspY = -__scrollValue;
2598 if (totalHeight <= dspHeight)
2600 pScroll->SetScrollVisibility(false);
2601 pScroll->SetScrollRange(1, 1);
2602 pScroll->SetScrollPosition(0.0f);
2604 SetScrollBarVisible(false);
2605 SetPreviousScrollBarPosition(0.0f);
2606 SetMaximumPreviousScrollBarPosition(0.0f);
2610 if (firstDspY > 0.0f)
2612 pScroll->SetScrollRange(dspHeight, totalHeight);
2613 pScroll->SetScrollPosition(firstDspY);
2614 SetMaximumPreviousScrollBarPosition(totalHeight - dspHeight);
2618 pScroll->SetScrollRange(dspHeight, totalHeight);
2619 pScroll->SetScrollPosition(0.0f);
2620 SetMaximumPreviousScrollBarPosition(0.0f);
2623 if (pScroll->GetScrollVisibility())
2625 SetScrollBarVisible(true);
2628 SetPreviousScrollBarPosition(firstDspY);
2635 _TokenEditPresenter::SetAutoShrinkModeEnabled(bool enable)
2637 __autoShrink = enable;
2641 _TokenEditPresenter::IsAutoShrinkModeEnabled(void) const
2643 return __autoShrink;
2647 _TokenEditPresenter::SetDescriptionText(String descriptionText)
2649 __descriptionText = descriptionText;
2653 _TokenEditPresenter::GetDescriptionText(void) const
2655 return __descriptionText;
2659 _TokenEditPresenter::CalculateVisibleTokenCount(void)
2661 int visibleTokenCount = 0;
2663 FloatRectangle intialBounds = GetInitialBoundsF();
2664 FloatRectangle tempInitialBounds = intialBounds;
2665 FloatRectangle hiddenTokenDisplayBounds;
2666 int tokenCount = GetTokenCount();
2668 for (int i = 0; i < tokenCount; i++)
2670 tempInitialBounds = intialBounds;
2671 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2672 SysTryReturn(NID_UI_CTRL, pToken != null, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
2674 FloatRectangle displayBounds = pToken->displayRect;
2675 if ((tempInitialBounds.y + displayBounds.y) > (tempInitialBounds.y + tempInitialBounds.height))
2679 visibleTokenCount++;
2681 return visibleTokenCount;
2685 _TokenEditPresenter::OnFocusGained(void)
2687 __isTitleSliding = false;
2690 float tempHeight = CalculateFlexibleHeightF();
2691 FloatRectangle tempRect = GetInitialBoundsF();
2692 tempRect.height = tempHeight;
2694 _Token* pToken = null;
2695 int tokenCount = GetTokenCount();
2697 for (int i = 0; i < tokenCount; i++)
2699 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2703 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
2704 if (pTokenVisualElement)
2706 pTokenVisualElement->SetShowState(true);
2711 SetFlexBounds(tempRect);
2713 SetEditingTokenTextBounds(__editingTokenIndex, false);
2717 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2721 if (__isScrollValueChanged && !__isScrollValueModified)
2723 __maxScrollValue = __maxScrollValue - (__pTokenEdit->GetBoundsF().height - GetInitialBoundsF().height);
2724 __isScrollValueChanged = false;
2728 if (GetTokenCount())
2730 CheckTokenScrolling();
2733 TextObject* pTextObject = GetTextObject();
2736 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
2737 pTextObject->Compose();
2740 if (__pressedTokenIndex < 0)
2743 SetCursorDisabled(false);
2747 RefreshAccessibilityElements();
2749 return _EditPresenter::OnFocusGained();
2753 _TokenEditPresenter::OnFocusLost(void)
2755 result r = E_SUCCESS;
2758 //Remove pressed state on focus lost
2759 __pressedTokenIndex = -1;
2761 _EditPresenter::StopTitleSlidingTimer();
2762 __isTitleSliding = false;
2764 if (__editingTokenIndex >= 0)
2766 _Token* pToken = null;
2767 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
2770 if (GetText().GetLength() > 0)
2772 OnTextCommitted(L"\n");
2776 RemoveTokenAt(__editingTokenIndex, true);
2782 if (GetText().GetLength() > 0)
2784 OnTextCommitted(L"\n");
2790 _Scroll* pScroll = GetScrollBar();
2793 pScroll->SetScrollVisibility(false);
2795 __scrollValue = 0.0f;
2797 int tokenCount = GetTokenCount();
2798 _Token* pToken = null;
2799 for (int i = 0; i < tokenCount; i++)
2801 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2804 pToken->SetBounds(pToken->displayRect);
2808 r = SetInitialBounds();
2809 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating", GetErrorMessage(r));
2811 UpdateTokenAccessibilityBounds();
2813 __scrollValue = 0.0f;
2814 r = CalculateTokenPositionFromIndex(0);
2815 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
2817 int visibleTokenCount = CalculateVisibleTokenCount();
2819 for (int i = visibleTokenCount; i < tokenCount; i++)
2821 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2824 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
2825 if (pTokenVisualElement)
2827 pTokenVisualElement->SetShowState(false);
2832 float totalScrollValue = __maxScrollValue + (__pTokenEdit->GetBoundsF().height - GetInitialBoundsF().height);
2834 if (totalScrollValue > 0)
2836 __isNeedToScroll = true;
2837 __maxScrollValue = totalScrollValue;
2838 __isTokenScrolling = true;
2839 if (__lineAdded > 0)
2841 __isScrollValueChanged = true;
2842 __isScrollValueModified = false;
2846 FloatRectangle intialWindowBounds = GetInitialBoundsF();
2847 SetFlexBounds(intialWindowBounds);
2849 SetEditingTokenTextBounds(__editingTokenIndex, false);
2851 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2854 TextObject* pTextObject = GetTextObject();
2857 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
2858 pTextObject->Compose();
2861 RemoveChildAccessibilityElements();
2862 __pTokenEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
2864 return _EditPresenter::OnFocusLost();
2868 _TokenEditPresenter::SetFlexBounds(const FloatRectangle& bounds)
2870 if (__pTokenEdit->GetBoundsF().height > bounds.height)
2872 if (__lineAdded > 0)
2877 return _EditPresenter::SetFlexBounds(bounds);
2881 _TokenEditPresenter::SetTextSize(const int size)
2883 result r = E_SUCCESS;
2884 __editContentFontSize = size;
2886 if (!__isEditingToken)
2888 r = _EditPresenter::SetTextSize(size);
2889 r = SetInitialBounds();
2890 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2897 _TokenEditPresenter::SetTextSize(const float size)
2899 result r = E_SUCCESS;
2900 __editContentFontSize = size;
2902 if (!__isEditingToken)
2904 r = _EditPresenter::SetTextSize(size);
2905 r = SetInitialBounds();
2906 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2913 _TokenEditPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
2915 //Remove token focus on touch press
2916 __focusedTokenIndex = -1;
2918 int tokenIndex = GetTokenIndexFromCoordinate(_CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()));
2919 __trackTokenIndex = tokenIndex;
2921 _TouchInfo TouchInfo(touchinfo);
2922 if (tokenIndex != -1)
2924 if (tokenIndex == __editingTokenIndex)
2926 __touchPressInfo.x = touchinfo.GetCurrentPosition().x;
2927 __touchPressInfo.y = touchinfo.GetCurrentPosition().y;
2929 _Token* pToken = null;
2930 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
2933 float tokenX = pToken->displayRect.x;
2934 float tokenY = pToken->displayRect.y;
2935 FloatPoint point(__touchPressInfo.x - tokenX, __touchPressInfo.y - tokenY);
2936 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
2941 return _EditPresenter::OnTouchPressed(source, TouchInfo);
2945 _TokenEditPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
2947 __touchPressInfo = FloatPoint(-1.0f, -1.0f);
2949 ProcessTokeningByTouchEvent(source, touchinfo);
2950 if (GetTokenCount())
2952 //Set token bounds appropriately On Fast flick of scroll bar
2953 if (!(__isEditingToken || __editingTokenIndex >= 0))
2955 SetTokenBoundsByTouchInfo(touchinfo);
2959 _Scroll* pScroll = GetScrollBar();
2962 pScroll->SetScrollVisibility(false);
2965 if (__prevScrollValue)
2967 __prevScrollValue = 0.0f;
2968 __isTokenScrolling = false;
2971 _TouchInfo TouchInfo(touchinfo);
2972 _Token* pToken = null;
2973 if (__editingTokenIndex >= 0)
2975 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
2978 int tokenX = _CoordinateSystemUtils::ConvertToInteger(pToken->displayRect.x);
2979 int tokenY = _CoordinateSystemUtils::ConvertToInteger(pToken->displayRect.y);
2980 Point point(_CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()).x - tokenX, _CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()).y - tokenY);
2981 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
2983 _EditPresenter::OnTouchReleased(source, TouchInfo);
2984 __previousCursorPosition = GetCursorPosition();
2988 _EditPresenter::OnTouchReleased(source, touchinfo);
2991 __isTouchMoveInProgress = false;
2992 __trackTokenIndex = -1;
2998 _TokenEditPresenter::OnInputConnectionTextCommitted(InputConnection& source, const String& committedText)
3000 OnTextCommitted(committedText);
3004 _TokenEditPresenter::OnTextCommitted(const String& commitText)
3006 char enterText[2] = {'\n', };
3007 String enterTextComma(",");
3008 String enterTextSemiColon(";");
3010 //OnTextCommitted blocked for these cases
3011 //1. Tab text not to be handled
3012 //2. Token is focused
3013 char tapText[2] = {'\t', };
3014 if (commitText == tapText)
3019 if ((commitText == enterText) || (commitText == enterTextComma) || (commitText == enterTextSemiColon))
3021 CoreKeypadAction keypadaction = GetKeypadAction();
3022 __pTokenEdit->SendKeypadEvent(keypadaction, CORE_KEYPAD_EVENT_STATUS_ENTERACTION);
3024 if (__editingTokenIndex != -1)
3026 ExitTokenEditingMode();
3029 if (GetText().GetLength() > 0)
3034 for (int i = 0; i < __pTokenList->GetCount(); i++)
3036 TrimTokenAndAdjustEllipsisAt(i);
3037 InitializeTokenVisibilityAt(i);
3040 if (__pressedTokenIndex < 0)
3042 SetCursorDisabled(true);
3043 __pTokenEdit->Draw();
3044 SetCursorDisabled(false);
3051 _EditPresenter::OnTextCommitted(commitText);
3052 __previousCursorPosition = GetCursorPosition();
3054 _Token* pToken = null;
3055 if (__editingTokenIndex >= 0)
3057 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3058 SysTryReturnVoidResult(NID_UI_CTRL, pToken, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
3060 pToken->ResetToken(GetText());
3061 TrimTokenAndAdjustEllipsisAt(__editingTokenIndex);
3063 float tokenHeight = 0.0f;
3064 float tokenVerticalSpacing = 0.0f;
3065 float tokenTextLeftMargin = 0.0f;
3067 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3068 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
3069 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
3070 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
3072 FloatRectangle tempTextDspRect;
3073 tempTextDspRect.x += tokenTextLeftMargin;
3074 tempTextDspRect.y += tokenVerticalSpacing / 2.0f;
3075 tempTextDspRect.width = pToken->displayRect.width - (tokenTextLeftMargin * 2.0f);
3076 tempTextDspRect.height = tokenHeight - tokenVerticalSpacing;
3078 SetTextBounds(tempTextDspRect);
3080 if (GetCursorPosition() > pToken->currTokenLength)
3082 _EditPresenter::SetCursorPosition(pToken->currTokenLength);
3086 _EditPresenter::SetCursorPosition(GetCursorPosition());
3091 if (__isEditingToken == false)
3093 __pressedTokenIndex = -1;
3094 __focusedTokenIndex = -1;
3095 SetCursorDisabled(false);
3098 float tokenTopMargin = 0.0f;
3099 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3100 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
3102 FloatRectangle textBounds = GetTextBoundsF();
3103 textBounds.height = GetMaxTextHeight();
3104 SetTextBounds(textBounds);
3107 if (__editingTokenIndex < 0)
3109 CheckTokenScrolling();
3111 __pTokenEdit->Invalidate();
3117 _TokenEditPresenter::DeleteSurroundingText(InputConnection& source, int offset, int charCount)
3119 OnSurroundingTextDeleted(offset, charCount);
3123 _TokenEditPresenter::OnSurroundingTextDeleted(int offset, int charCount)
3125 __lastTokenIndex = GetTokenCount() - 1;
3126 int cursorPosition = 0;
3130 if ((offset == -1) && (charCount == 1))
3132 if (GetTextLength() == 0 && GetTokenCount()) // There is no candidate token.
3134 if (__isEditingToken == true)
3136 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3137 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3139 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3140 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3142 _Token* pToken = null;
3143 _VisualElement* pTokenVisualElement = null;
3145 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3149 pTokenVisualElement = pToken->GetVisualElement();
3150 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3152 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3154 result r = E_SUCCESS;
3155 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3156 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3158 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3159 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3163 RemoveTokenAt(__editingTokenIndex);
3165 CalculateTokenPositionFromIndex(__editingTokenIndex);
3166 for (int i = __editingTokenIndex; i < __lastTokenIndex + 1; i++)
3168 _Token* pToken = null;
3169 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
3172 pToken->SetBounds(pToken->displayRect);
3176 __pressedTokenIndex = -1;
3177 __editingTokenIndex = -1;
3178 __isEditingToken = false;
3179 _EditPresenter::SetTextSize(__editContentFontSize);
3180 __isTokenEditingFinished = false;
3182 AdjustFlexibleHeight();
3183 CheckTokenScrolling();
3185 else if (__pressedTokenIndex != -1)
3187 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3188 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3190 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3191 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3193 _Token* pToken = null;
3194 _VisualElement* pTokenVisualElement = null;
3196 pToken = static_cast< _Token* >(__pTokenList->GetAt(__pressedTokenIndex));
3200 pTokenVisualElement = pToken->GetVisualElement();
3201 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3203 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3205 result r = E_SUCCESS;
3206 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3207 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3209 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3210 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3214 RemoveTokenAt(__pressedTokenIndex);
3216 CalculateTokenPositionFromIndex(__pressedTokenIndex);
3217 for (int i = __pressedTokenIndex; i < __lastTokenIndex + 1; i++)
3219 _Token* pToken = null;
3220 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
3224 pToken->SetBounds(pToken->displayRect);
3229 else if (__focusedTokenIndex != -1)
3231 RemoveTokenAt(__focusedTokenIndex);
3235 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3236 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3238 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3239 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3241 _Token* pToken = null;
3242 _VisualElement* pTokenVisualElement = null;
3243 if (__animatingIndex == (GetTokenCount() - 1))
3245 pToken = static_cast< _Token* >(__pTokenList->GetAt(GetTokenCount() - 1));
3248 pTokenVisualElement = pToken->GetVisualElement();
3249 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3250 pTokenVisualElement->RemoveAnimation(L"TokenAnimation");
3253 pToken = static_cast< _Token* >(__pTokenList->GetAt(GetTokenCount() - 1));
3256 pTokenVisualElement = pToken->GetVisualElement();
3257 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3259 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3261 result r = E_SUCCESS;
3262 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3263 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3265 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3266 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3270 __animatingIndex = GetTokenCount() - 1;
3272 if (pTokenVisualElement && __animatingIndex >= 0)
3274 __isAnimationInProgress = true;
3275 VisualElementAnimation* pAnimation = CreateAnimationN(*pTokenVisualElement, false);
3276 pTokenVisualElement->AddAnimation(L"TokenAnimation", *pAnimation);
3281 __pTokenEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
3284 __pTokenEdit->Invalidate();
3289 if (__pressedTokenIndex >= 0 && __editingTokenIndex < 0 && !__isEditingToken)
3291 RemoveTokenAt(__pressedTokenIndex);
3292 __pTokenEdit->Invalidate();
3295 else if (__focusedTokenIndex >= 0 && __editingTokenIndex < 0 && !__isEditingToken)
3297 RemoveTokenAt(__focusedTokenIndex);
3298 __pTokenEdit->Invalidate();
3302 //Backspace on Blocked text, delete full block
3303 if (IsBlocked() == true)
3305 GetBlockRange(start, end);
3309 cursorPosition = GetCursorPosition();
3310 start = cursorPosition + offset;
3315 end = start + charCount;
3316 if (end > GetTextLength())
3322 DeleteText(start, end);
3323 __previousCursorPosition = start;
3325 if (IsCopyPasteManagerExist())
3327 InitializeCopyPasteManager();
3329 if (IsBlocked() == true)
3333 if (__isEditingToken != true)
3338 __pTokenEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
3341 cursorPosition = GetCursorPosition();
3342 start = cursorPosition + offset;
3347 end = start + charCount;
3348 if (end > GetTextLength())
3353 Rectangle currBounds = __pTokenEdit->GetBounds();
3354 DeleteText(start, end);
3355 __previousCursorPosition = start;
3356 if (__isEditingToken != true)
3362 _Token* pToken = null;
3364 if (__editingTokenIndex >= 0 && __isEditingToken)
3366 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3370 float tokenHeight = 0.0f;
3371 float tokenVerticalSpacing = 0.0f;
3372 float tokenTextLeftMargin = 0.0f;
3374 SetCursorPosition(__previousCursorPosition);
3376 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3377 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
3378 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
3379 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
3381 FloatRectangle tempTextDspRect;
3382 tempTextDspRect.x += tokenTextLeftMargin;
3383 tempTextDspRect.y += tokenVerticalSpacing / 2.0f;
3384 tempTextDspRect.width = pToken->displayRect.width - (tokenTextLeftMargin * 2.0f);
3385 tempTextDspRect.height = tokenHeight - tokenVerticalSpacing;
3387 SetTextBounds(tempTextDspRect);
3388 _EditPresenter::SetCursorPosition(start);
3390 pToken->ResetToken(GetText());
3391 TrimTokenAndAdjustEllipsisAt(__editingTokenIndex);
3395 __pTokenEdit->Draw();
3399 _TokenEditPresenter::OnTapGestureDetected(void)
3401 if (__editingTokenIndex >= 0)
3403 __isPopupVisible = true;
3406 //Uncomment below to Block Copy & Paste functionality in Token Edit mode
3407 if (__pressedTokenIndex != -1)
3411 return _EditPresenter::OnTapGestureDetected();
3415 _TokenEditPresenter::CheckCopyPastePopupShowStatus(void)
3417 if (__editingTokenIndex < 0)
3419 float controlHeight = __pTokenEdit->GetBoundsF().height;
3420 FloatRectangle cursorBounds;
3421 GetCursorBounds(false, cursorBounds);
3422 if (cursorBounds.y > controlHeight)
3432 _TokenEditPresenter::OnLongPressGestureDetected(void)
3434 if (CheckCopyPastePopupShowStatus())
3436 //TextBounds bigger than control height. Dont show Copy paste popup
3440 //Discard all long press that is detected after Touch press on a token
3441 if (__trackTokenIndex >= 0)
3446 __isLongPressed = true;
3448 //Uncomment below to Block Copy & Paste functionality in Token Edit mode
3449 if (__pressedTokenIndex != -1)
3453 return _EditPresenter::OnLongPressGestureDetected();
3457 _TokenEditPresenter::OnCursorTimerExpired(void)
3459 if (__editingTokenIndex != -1)
3467 FloatRectangle cursorRect;
3469 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3470 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
3472 //Set Editing token bounds for text scroll and cursor position calculation (SetTextBounds should have been done prior to this)
3473 FloatRectangle cursorDspRect = _EditPresenter::GetTextBoundsF();
3475 if (CalculateCursorBounds(cursorDspRect, cursorRect) != E_SUCCESS)
3481 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3482 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3484 Canvas* pCursorCanvas = pCursorVisualElement->GetCanvasN();
3485 SysTryReturnVoidResult(NID_UI_CTRL, pCursorCanvas != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get canvas of cursor visual element.");
3487 bool cursorEnable = IsCursorEnabled();
3489 pCursorVisualElement->SetBounds(cursorRect);
3490 DrawCursor(*pCursorCanvas, cursorRect, cursorEnable);
3494 cursorEnable = false;
3498 cursorEnable = true;
3500 SetCursorEnabled(cursorEnable);
3502 pCursorCanvas->Show();
3503 delete pCursorCanvas;
3509 _EditPresenter::OnCursorTimerExpired();
3514 _TokenEditPresenter::IsTextBlockedInTokenEdit(void) const
3516 if ((IsBlocked() == true) && (__isEditingToken) && (__editingTokenIndex >= 0))
3524 _TokenEditPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
3526 __isTouchMoveInProgress = true;
3528 if (GetTokenCount())
3530 //Scrolling is blocked when a popup is visible or when a text is blocked
3531 if (IsBlocked() == true || __isLongPressed == true)
3536 //Allow touch move only in horizontal direction when editing token
3537 _TouchInfo TouchInfo(touchinfo);
3538 _Token* pToken = null;
3539 if (__editingTokenIndex >= 0)
3541 if (__touchPressInfo.y > 0.0f)
3543 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3546 float tokenX = pToken->displayRect.x;
3547 float tokenY = pToken->displayRect.y;
3548 FloatPoint point(touchinfo.GetCurrentPosition().x - tokenX, __touchPressInfo.y - tokenY);
3549 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
3552 bool retValue = _EditPresenter::OnTouchMoved(source, TouchInfo);
3553 __previousCursorPosition = GetCursorPosition();
3563 SetTokenBoundsByTouchInfo(touchinfo);
3565 if (!(__pTokenEdit->GetEditStyle() & EDIT_STYLE_NOSCROLL))
3567 _Scroll* pScroll = GetScrollBar();
3570 float tokenBottomMargin = 0.0f;
3571 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, tokenBottomMargin);
3573 float totalHeight = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin;
3574 float controlHeight = __pTokenEdit->GetBoundsF().height;
3576 if (totalHeight > controlHeight)
3578 pScroll->SetScrollVisibility(true);
3582 pScroll->SetScrollVisibility(false);
3587 return _EditPresenter::OnTouchMoved(source, touchinfo);
3591 return _EditPresenter::OnTouchMoved(source, touchinfo);
3597 _TokenEditPresenter::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
3599 __isAnimationInProgress = false;
3600 RemoveTokenAt(GetTokenCount() - 1);
3601 CalculateTokenPositionFromIndex(GetTokenCount() - 1);
3603 for (int i = GetTokenCount() - 1; i < GetTokenCount() - 1 + 1; i++)
3605 _Token* pToken = null;
3606 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
3610 pToken->SetBounds(pToken->displayRect);
3614 if (__lastTokenIndex == __pressedTokenIndex)
3616 __pressedTokenIndex--;
3619 if (GetTokenCount() == 0 && __animatingIndex == 0)
3623 __animatingIndex = -1;
3628 __pTokenEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
3634 _TokenEditPresenter::OnTimerExpired(Timer& timer)
3636 Timer* onTimer = &timer;
3637 Canvas* pDescriptionTextCanvas = null;
3639 if (onTimer == _EditPresenter::__pTitleSlidingTimer)
3643 _EditPresenter::StopTitleSlidingTimer();
3644 __isTitleSliding = false;
3648 FloatRectangle tempDescriptionTextRect = __descriptionTextRect;
3649 tempDescriptionTextRect.x = 0.0f;
3650 tempDescriptionTextRect.y = 0.0f;
3652 pDescriptionTextCanvas = __pDescriptionTextVisualElement->GetCanvasN();
3653 SysTryReturnVoidResult(NID_UI_CTRL, pDescriptionTextCanvas, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pDescriptionTextCanvas is invalid!");
3655 pDescriptionTextCanvas->SetBackgroundColor(Color(0));
3656 pDescriptionTextCanvas->Clear();
3657 __pDescriptionTextTextObject->SetBounds(tempDescriptionTextRect);
3658 __pDescriptionTextTextObject->DrawWithOffset(*_CanvasImpl::GetInstance(*pDescriptionTextCanvas));
3659 Rectangle descriptionTextRect = _CoordinateSystemUtils::ConvertToInteger(tempDescriptionTextRect);
3660 pDescriptionTextCanvas->Show(descriptionTextRect);
3662 delete pDescriptionTextCanvas;
3664 _EditPresenter::StartTitleSlidingTimer();
3665 __isTitleSliding = true;
3669 _EditPresenter::OnTimerExpired(timer);
3674 _TokenEditPresenter::ChangeInternalLayout(_ControlOrientation orientation)
3676 result r = E_SUCCESS;
3678 __scrollValue = 0.0f;
3679 __maxScrollValue = 0.0f;
3680 float tokenBottomMargin = 0.0f;
3681 float newScrollValue = 0.0f;
3683 FloatRectangle windowBounds = GetInitialBoundsF();
3685 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
3687 r = CalculateTokenPositionFromIndex(0);
3688 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3690 r = SetInitialBounds();
3691 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3693 if (__isEditingToken)
3695 if (__editingTokenIndex >= 0 && __editingTokenIndex < GetTokenCount())
3697 String inputTokenString = GetText();
3698 String replacementString = inputTokenString;
3699 bool enable = false;
3701 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
3704 inputTokenString = replacementString;
3707 if (inputTokenString.GetLength() > 0)
3709 int index = __editingTokenIndex;
3710 RemoveTokenAt(__editingTokenIndex, true);
3711 InsertTokenAt(index, inputTokenString);
3718 r = AdjustFlexibleHeight();
3719 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3721 r = CheckTokenScrolling();
3722 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3728 r = AdjustFlexibleHeight();
3729 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3731 windowBounds = __pTokenEdit->GetBoundsF();
3734 newScrollValue = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin - windowBounds.height;
3735 if (newScrollValue > 0.0f)
3737 __maxScrollValue = newScrollValue;
3738 __isNeedToScroll = true;
3745 _TokenEditPresenter::ChangeLayout(_ControlOrientation orientation)
3747 result r = E_SUCCESS;
3749 r = _EditPresenter::ChangeLayout(orientation);
3750 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3752 r = ChangeInternalLayout(orientation);
3758 _TokenEditPresenter::OnBoundsChanged(void)
3760 if (!__isTokenEditPresenterInitialized)
3765 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3766 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
3768 if (IsUpdateInitialBounds())
3770 SetControlInitialBounds(tokenEditBounds);
3772 ChangeInternalLayout(orientation);
3778 _TokenEditPresenter::AttachCursorToToken(void)
3780 result r = E_SUCCESS;
3782 if (__pressedTokenIndex != -1)
3784 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3785 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
3787 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3788 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
3790 _Token* pToken = null;
3791 _VisualElement* pTokenVisualElement = null;
3793 pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
3796 pTokenVisualElement = pToken->GetVisualElement();
3797 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
3799 if (pCursorVisualElement->GetParent() != pTokenVisualElement)
3801 r = (pCursorVisualElement->GetParent())->DetachChild(*pCursorVisualElement);
3802 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3804 r = pTokenVisualElement->AttachChild(*pCursorVisualElement);
3805 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3814 _TokenEditPresenter::DetachCursorFromToken(void)
3816 result r = E_SUCCESS;
3818 if (__pressedTokenIndex != -1)
3820 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3821 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3823 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3824 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3826 _Token* pToken = null;
3827 _VisualElement* pTokenVisualElement = null;
3829 pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
3833 pTokenVisualElement = pToken->GetVisualElement();
3834 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3836 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3838 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3839 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
3841 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3842 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
3850 _TokenEditPresenter::ExitTokenEditingMode(void)
3852 result r = E_SUCCESS;
3854 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3855 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3857 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3858 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3860 _Token* pToken = null;
3861 _VisualElement* pTokenVisualElement = null;
3863 pToken = static_cast <_Token*>(__pTokenList->GetAt(__editingTokenIndex));
3867 pTokenVisualElement = pToken->GetVisualElement();
3868 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3870 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3872 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3873 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
3875 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3876 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
3880 String inputTokenString = GetText();
3881 String replacementString = inputTokenString;
3882 bool enable = false;
3884 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
3887 inputTokenString = replacementString;
3890 r = RemoveTokenAt(__editingTokenIndex);
3892 _EditPresenter::SetTextSize(__editContentFontSize);
3893 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3895 if (inputTokenString.GetLength() > 0)
3897 r = InsertTokenAt(__editingTokenIndex, inputTokenString);
3898 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3900 pToken = static_cast <_Token*>(__pTokenList->GetAt(__editingTokenIndex));
3901 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3903 pToken->currTokenLength = inputTokenString.GetLength();
3906 CalculateTokenPositionFromIndex(0);
3907 int lastTokenIndex = GetTokenCount() - 1;
3908 for (int i = 0; i < lastTokenIndex + 1; i++)
3910 _Token* pToken = null;
3911 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3915 pToken->SetBounds(pToken->displayRect);
3919 AdjustFlexibleHeight();
3920 __pressedTokenIndex = -1;
3921 __isTokenEditingFinished = true;
3922 __editingTokenIndex = -1;
3923 __isEditingToken = false;
3925 CheckTokenScrolling();
3926 SetCursorDisabled(false);
3928 if (inputTokenString.GetLength() <= 0)
3930 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
3937 _TokenEditPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
3939 _KeyCode keyCode = keyInfo.GetKeyCode();
3940 bool focusChanged = false;
3941 int tokenCount = GetTokenCount();
3942 int lastTokenIndex = tokenCount - 1;
3944 if (IsUsbKeyboardConnected() && (keyInfo.GetKeyModifier() & _KEY_MODIFIER_CTRL))
3952 if (__isEditingToken)
3963 if ((keyCode == _KEY_NUM_LEFT) || (keyCode == _KEY_LEFT))
3965 if (__drawFocusState && (!__isEditingToken) && (tokenCount > 0))
3967 if (__focusedTokenIndex == -1)
3969 if (GetCursorPosition() == 0)
3971 __focusedTokenIndex = lastTokenIndex;
3972 if (GetTextLength() > 0)
3976 SetCursorDisabled(true);
3977 __pTokenEdit->Invalidate();
3981 return _EditPresenter::OnKeyPressed(source, keyInfo);
3983 focusChanged = true;
3988 if (__focusedTokenIndex > 0)
3990 __focusedTokenIndex--;
3991 focusChanged = true;
3997 if ((keyCode == _KEY_NUM_RIGHT) || (keyCode == _KEY_RIGHT))
3999 if (__drawFocusState && (!__isEditingToken) && (tokenCount > 0))
4001 if (__focusedTokenIndex != -1)
4003 if (__focusedTokenIndex == lastTokenIndex)
4005 __focusedTokenIndex = -1;
4006 focusChanged = true;
4010 __focusedTokenIndex++;
4011 focusChanged = true;
4021 if (__focusedTokenIndex != -1)
4023 SetCursorDisabled(true);
4024 ScrollToFocusedToken();
4028 SetCursorDisabled(false);
4029 CheckTokenScrolling();
4035 return _EditPresenter::OnKeyPressed(source, keyInfo);
4039 _TokenEditPresenter::GetTextAccessibilityElementText(void) const
4042 String spaceText = " ";
4043 _Token* pToken = null;
4044 int tokenCount = GetTokenCount();
4045 static const int readTokenCount = 2;
4048 for (int index = 0; index < readTokenCount; index++)
4050 pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
4051 SysTryReturn(NID_UI_CTRL, pToken, tokenText, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4053 if (index < (readTokenCount - 1))
4055 tokenText += pToken->GetText() + spaceText;
4059 String moreTokenText;
4060 int moreTokenCount = tokenCount - readTokenCount;
4061 if (moreTokenCount > 0)
4063 moreTokenText.Format(15, L"and %d more", moreTokenCount);
4065 tokenText += pToken->GetText() + spaceText + moreTokenText;
4073 _TokenEditPresenter::RefreshAccessibilityElements(void)
4075 RemoveChildAccessibilityElements();
4076 AddChildAccessibilityElements();
4082 _TokenEditPresenter::AddChildAccessibilityElements(void)
4084 //Accessibility Elements added to the container upon focus gained
4087 //3. __accessibilityElements 0 - title 1 - token 0
4089 result r = E_SUCCESS;
4090 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4092 __pTokenEdit->AddTitleAccessibilityElement();
4093 int tokenCount = GetTokenCount();
4095 for (int index = 0; index < tokenCount; index++)
4097 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
4098 SysTryReturn(NID_UI_CTRL, pToken != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4102 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
4103 SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4105 String labelText = pToken->GetText();
4106 pAccessibilityElement->SetBounds(pToken->displayRect);
4107 pAccessibilityElement->SetLabel(labelText);
4108 pContainer->AddElement(*pAccessibilityElement);
4109 __accessibilityElements.Add(pAccessibilityElement);
4113 __pTokenEdit->AddCursorAccessibilityElement();
4119 _TokenEditPresenter::RemoveChildAccessibilityElements(void)
4121 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4122 _AccessibilityElement* pAccessibilityElement = null;
4124 __pTokenEdit->RemoveTitleAccessibilityElement();
4126 while (__accessibilityElements.GetCount() > 0)
4128 if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS)
4130 __accessibilityElements.RemoveAt(0);
4131 pContainer->RemoveElement(*pAccessibilityElement);
4135 __pTokenEdit->RemoveCursorAccessibilityElement();
4141 _TokenEditPresenter::AppendTokenAccessibilityElement(void)
4143 result r = E_SUCCESS;
4144 int tokenCount = GetTokenCount();
4146 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4148 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(tokenCount - 1));
4149 SysTryReturn(NID_UI_CTRL, pToken != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4153 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
4154 SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4156 String labelText = pToken->GetText();
4157 pAccessibilityElement->SetBounds(pToken->displayRect);
4158 pAccessibilityElement->SetLabel(labelText);
4159 pAccessibilityElement->SetHint(L"double tap to edit");
4160 pContainer->AddElement(*pAccessibilityElement);
4161 __accessibilityElements.Add(pAccessibilityElement);
4168 _TokenEditPresenter::InsertTokenAccessibilityElementAt(int index)
4170 result r = E_SUCCESS;
4172 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4173 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
4174 SysTryReturn(NID_UI_CTRL, pToken != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4178 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
4179 SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4181 String labelText = pToken->GetText();
4182 pAccessibilityElement->SetBounds(pToken->displayRect);
4183 pAccessibilityElement->SetLabel(labelText);
4184 pContainer->AddElement(*pAccessibilityElement);
4185 __accessibilityElements.InsertAt(pAccessibilityElement, index);
4192 _TokenEditPresenter::RemoveTokenAccessibilityElementAt(int index)
4194 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4195 _AccessibilityElement* pAccessibilityElement = null;
4199 if (__accessibilityElements.GetCount() > 0)
4201 if ((__accessibilityElements.GetAt(index, pAccessibilityElement)) == E_SUCCESS)
4203 __accessibilityElements.RemoveAt(index);
4204 pContainer->RemoveElement(*pAccessibilityElement);
4212 _TokenEditPresenter::UpdateTokenAccessibilityBounds(void)
4214 result r = E_SUCCESS;
4215 int tokenCount = GetTokenCount();
4216 _AccessibilityElement* pAccessibilityElement = null;
4218 for (int index = 0; index < tokenCount; index++)
4220 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
4221 SysTryReturn(NID_UI_CTRL, pToken != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4223 if ((__accessibilityElements.GetAt(index, pAccessibilityElement)) == E_SUCCESS)
4225 pAccessibilityElement->SetBounds(pToken->displayRect);
4232 _TokenEditPresenter::UpdateTitleAccessibilityBounds(const FloatRectangle& titleBounds)
4234 _AccessibilityElement* pTitleAccessibilityElement = __pTokenEdit->GetTitleTextAccessibilityElement();
4236 if (!pTitleAccessibilityElement)
4241 pTitleAccessibilityElement->SetBounds(titleBounds);
4247 _TokenEditPresenter::ScrollToFocusedTokenAccessibilityElement(const _AccessibilityElement& element)
4249 result r = E_SUCCESS;
4250 int focusedTokenIndex = -1;
4251 int tokenCount = GetTokenCount();
4252 FloatRectangle focusedTokenRectangle;
4253 float newScrollValue = 0.0f;
4254 float tokenTopMargin = 0.0f;
4255 float tokenBottomMargin = 0.0f;
4256 float tokenHeight = 0.0f;
4257 float textBoundsAlignValue = 0.0f;
4258 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
4259 _AccessibilityElement* pAccessibilityElement = null;
4261 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
4262 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
4263 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
4265 FloatRectangle tokenEditRect = __pTokenEdit->GetBoundsF();
4266 float textObjectMaxHeight = GetMaxTextHeight();
4267 textBoundsAlignValue = (tokenHeight - textObjectMaxHeight) / 2.0f;
4269 pAccessibilityElement = const_cast< _AccessibilityElement* >(&element);
4270 r = __accessibilityElements.IndexOf(pAccessibilityElement, focusedTokenIndex);
4271 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
4273 if ((focusedTokenIndex > -1) && (focusedTokenIndex < tokenCount))
4275 _Token* pToken = null;
4276 pToken = static_cast< _Token* >(__pTokenList->GetAt(focusedTokenIndex));
4278 focusedTokenRectangle = pToken->displayRect;
4280 float focusedTokenPosition = focusedTokenRectangle.y + focusedTokenRectangle.height;
4282 if ((focusedTokenRectangle.y > 0) && (focusedTokenPosition < tokenEditRect.height))
4288 if (focusedTokenRectangle.y < 0)
4290 newScrollValue = focusedTokenRectangle.y - tokenTopMargin - __scrollValue;
4294 newScrollValue = focusedTokenPosition - textBoundsAlignValue - tokenEditRect.height + tokenBottomMargin - __scrollValue;
4297 r = RecalculateTokenBounds(newScrollValue);
4298 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
4301 __accessibilityElements.GetAt(focusedTokenIndex, pAccessibilityElement);
4302 _AccessibilityManager* pAccessibilityManager = _AccessibilityManager::GetInstance();
4303 pAccessibilityManager->SetGlobalFocusedElement(*pAccessibilityElement);
4304 pAccessibilityManager->RequestToDrawFocusUi();
4311 _TokenEditPresenter::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
4313 if (__focusOutIndex < 0) // Not a token accessibility element
4318 _Token* pToken = null;
4319 _AccessibilityElement* pCurrentElement = const_cast< _AccessibilityElement* >(&element);
4320 _AccessibilityElement* pPreviousAccessibilityElement = null;
4321 _AccessibilityElement* pNextAccessibilityElement = null;
4322 __accessibilityElements.GetAt(__focusOutIndex, pPreviousAccessibilityElement);
4324 if (pPreviousAccessibilityElement && pPreviousAccessibilityElement->GetAbsoluteBounds().y > element.GetAbsoluteBounds().y) //Left flick
4326 pToken = static_cast< _Token* >(__pTokenList->GetAt(__focusOutIndex - 1));
4329 if (pToken->displayRect.y < 0.0f && __focusOutIndex > 0)
4331 __accessibilityElements.GetAt(__focusOutIndex - 1, pNextAccessibilityElement);
4332 ScrollToFocusedTokenAccessibilityElement(*pNextAccessibilityElement);
4337 if (pPreviousAccessibilityElement && pPreviousAccessibilityElement->GetAbsoluteBounds().y < element.GetAbsoluteBounds().y) //Right flick
4339 pToken = static_cast< _Token* >(__pTokenList->GetAt(__focusOutIndex + 1));
4342 if (pToken->displayRect.y + pToken->displayRect.height > __pTokenEdit->GetBoundsF().height)
4344 __accessibilityElements.GetAt(__focusOutIndex + 1, pNextAccessibilityElement);
4345 ScrollToFocusedTokenAccessibilityElement(*pNextAccessibilityElement);
4350 if (pToken == null) //Draw Cursor Accessibility Element
4352 _AccessibilityElement* pCursorAccessibilityElement = __pTokenEdit->GetCursorAccessibilityElement();
4353 if (pCursorAccessibilityElement && pPreviousAccessibilityElement && pCursorAccessibilityElement != pPreviousAccessibilityElement)
4355 if (GetTextBoundsF().y - pPreviousAccessibilityElement->GetBounds().y > pPreviousAccessibilityElement->GetBounds().height) //check for different lines
4357 float height = GetTextBoundsF().height + pPreviousAccessibilityElement->GetBounds().y + pPreviousAccessibilityElement->GetBounds().height;
4358 if (pCurrentElement == pCursorAccessibilityElement && height > __pTokenEdit->GetBoundsF().height)
4360 float tokenBottomMargin = 0.0f;
4361 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, tokenBottomMargin);
4362 float newScrollValue = GetTextBoundsF().height + tokenBottomMargin - __scrollValue;
4363 RecalculateTokenBounds(newScrollValue);
4364 _AccessibilityManager::GetInstance()->SetGlobalFocusedElement(*(__pTokenEdit->GetCursorAccessibilityElement()));
4365 _AccessibilityManager::GetInstance()->RequestToDrawFocusUi();
4371 __focusOutIndex = -1;
4372 UpdateTokenAccessibilityBounds();
4378 _TokenEditPresenter::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
4380 _AccessibilityElement* pAccessibilityElement = null;
4381 pAccessibilityElement = const_cast< _AccessibilityElement* >(&element);
4382 __accessibilityElements.IndexOf(pAccessibilityElement, __focusOutIndex);
4388 _TokenEditPresenter::ScrollToFocusedToken(void)
4390 result r = E_SUCCESS;
4391 FloatRectangle focussedTokenRectangle;
4392 float newScrollValue = 0.0f;
4393 float tokenTopMargin = 0.0f;
4394 float tokenBottomMargin = 0.0f;
4395 float tokenHeight = 0.0f;
4396 float textBoundsAlignValue = 0.0f;
4397 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
4400 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
4401 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
4402 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
4404 FloatRectangle tokenEditRect = __pTokenEdit->GetBoundsF();
4405 float textObjectMaxHeight = GetMaxTextHeight();
4406 textBoundsAlignValue = (tokenHeight - textObjectMaxHeight) / 2.0f;
4408 if (__focusedTokenIndex == -1)
4410 //Focus bitmap to be reset when no token is focused.
4415 _Token* pToken = null;
4416 pToken = static_cast <_Token*>(__pTokenList->GetAt(__focusedTokenIndex));
4418 focussedTokenRectangle = pToken->displayRect;
4420 float focussedTokenPosition= focussedTokenRectangle.y + focussedTokenRectangle.height ;
4422 if ((focussedTokenRectangle.y > 0) && (focussedTokenPosition < tokenEditRect.height))
4424 //Focused token is within the tokenEdit boundary
4429 if (focussedTokenRectangle.y < 0)
4431 //Focused token is above the upper boundary
4432 newScrollValue = focussedTokenRectangle.y - tokenTopMargin - __scrollValue;
4436 //Focused token is below the lower boundary
4437 newScrollValue = focussedTokenPosition - textBoundsAlignValue - tokenEditRect.height + tokenBottomMargin - __scrollValue;
4440 r = RecalculateTokenBounds(newScrollValue);
4441 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
4449 _TokenEditPresenter::SetDrawFocusState(bool focusState)
4453 __focusedTokenIndex = -1;
4455 __drawFocusState = focusState;
4461 _TokenEditPresenter::GetFocusedTokenIndex(void) const
4463 return __focusedTokenIndex;
4467 _TokenEditPresenter::PrepareFocusUiMode(void)
4469 if (__editingTokenIndex != -1)
4471 ExitTokenEditingMode();
4473 else if (__pressedTokenIndex != -1)
4475 __pressedTokenIndex = -1;
4476 DetachCursorFromToken();
4478 SetCursorDisabled(false);
4479 __pTokenEdit->Invalidate();
4486 }}} //Tizen::Ui::Controls