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_TokenEditPresenter.h"
28 #include "FUiCtrl_Scroll.h"
30 #include "FUi_CoordinateSystemUtils.h"
31 #include "FUi_AccessibilityContainer.h"
32 #include "FUi_AccessibilityElement.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Runtime;
36 using namespace Tizen::Media;
37 using namespace Tizen::Ui::Animations;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Graphics::_Text;
41 namespace Tizen { namespace Ui { namespace Controls
45 SineTimingFunction::CalculateProgress(float timeProgress) const
47 const float segments[3][3] = {{0.0f, 0.01f, 0.37f}, {0.37f, 0.72f, 0.888f}, {0.888f, 0.9999f, 1.0f}};
48 float timeProgressValue = timeProgress;
49 int segmentsLength = 3; //Length of the segments array
50 int index = (int) floor(segmentsLength * timeProgressValue);
51 if (index >= segmentsLength)
53 index = segmentsLength - 1;
56 float progressValue = (timeProgressValue - index * (1.0 / segmentsLength)) * segmentsLength;
57 float segmentAtIndex[3];
58 for (int i = 0; i < 3; i++)
60 segmentAtIndex[i] = segments[index][i];
62 float ret = 0 + 1 * (segmentAtIndex[0] + progressValue * (2 * (1 - progressValue) * (segmentAtIndex[1] - segmentAtIndex[0]) + progressValue * (segmentAtIndex[2] - segmentAtIndex[0])));
72 result Construct(const String& text, Font* pEditFont);
73 virtual ~_Token(void);
74 float GetTextPixelWidth(void) const;
75 wchar_t* GetText(void) const;
76 result ResetToken(const String& text);
77 result SetBounds(FloatRectangle bounds);
78 _VisualElement* GetVisualElement(void) const;
79 _Token(const _Token& src);
80 _Token& operator =(const _Token& value);
83 FloatRectangle displayRect;
84 TextObject* pTextObject;
87 bool isImplicitAnimation;
90 wchar_t* __pTextBuffer;
91 float __textPixelWidth;
92 float __textPixelHeight;
93 _VisualElement* __pVisualElement;
100 , isImplicitAnimation(true)
102 , __pTextBuffer(null)
103 , __textPixelWidth(0.0f)
104 , __textPixelHeight(0.0f)
105 , __pVisualElement(null)
110 _Token::Construct(const String& text, Font* pEditFont)
112 result r = E_SUCCESS;
114 currTokenLength = text.GetLength();
115 float tokenFontSize = 0.0f;
117 pTextObject = new (std::nothrow) TextObject;
118 SysTryReturnResult(NID_UI_CTRL, pTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
120 // for default initialize.
121 r = pTextObject->Construct();
122 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
124 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
125 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
127 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
128 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
130 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, tokenFontSize);
132 pFont = _FontImpl::CloneN(*pEditFont);
134 SysTryCatch(NID_UI_CTRL, pFont != null, , r, "[%s] Propagating.", GetErrorMessage(r));
136 (_FontImpl::GetInstance(*pFont))->SetStyle(FONT_STYLE_PLAIN);
137 (_FontImpl::GetInstance(*pFont))->SetSize(tokenFontSize);
139 r = pTextObject->SetFont(pFont, 0, pTextObject->GetTextLength());
140 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
142 r = ResetToken(text);
143 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
145 __pVisualElement = new (std::nothrow) _VisualElement;
146 SysTryCatch(NID_UI_CTRL, __pVisualElement != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
148 r = __pVisualElement->Construct();
149 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct _VisualElement.", GetErrorMessage(r));
151 __pVisualElement->SetImplicitAnimationEnabled(false);
152 __pVisualElement->SetOpacity(0.0f);
160 if (__pVisualElement)
162 __pVisualElement->Destroy();
163 __pVisualElement = null;
173 _Token::ResetToken(const String& text)
175 result r = E_SUCCESS;
176 FloatDimension textSize;
180 delete[] __pTextBuffer;
181 __pTextBuffer = null;
184 int length = text.GetLength();
185 wchar_t* pTempString = const_cast< wchar_t* >(text.GetPointer());
186 SysTryReturnResult(NID_UI_CTRL, pTempString != null, E_SYSTEM, "A system error has occurred. Token text string is null.");
188 __pTextBuffer = new (std::nothrow) wchar_t[(length + 1) * (sizeof(wchar_t))];
189 SysTryReturnResult(NID_UI_CTRL, __pTextBuffer != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
191 for (int i = 0; i < length; i++)
193 __pTextBuffer[i] = pTempString[i];
195 __pTextBuffer[length] = 0;
197 pTextObject->RemoveAll(true);
199 TextSimple* pSimpleText = new (std::nothrow) TextSimple(__pTextBuffer, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, pFont);
200 SysTryCatch(NID_UI_CTRL, pSimpleText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
202 r = pTextObject->AppendElement(*pSimpleText);
203 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
205 textSize = pTextObject->GetTextExtentF(0, length);
206 __textPixelWidth = textSize.width;
207 __textPixelHeight = textSize.height;
209 r = pTextObject->Compose();
211 currTokenLength = length;
216 delete[] __pTextBuffer;
217 __pTextBuffer = null;
226 _Token::SetBounds(FloatRectangle bounds)
228 result r = E_SUCCESS;
229 displayRect = bounds;
230 if (__pVisualElement)
232 __pVisualElement->SetBounds(bounds);
238 _Token::GetVisualElement(void) const
240 return __pVisualElement;
243 _Token::~_Token(void)
251 delete[] __pTextBuffer;
252 __pTextBuffer = null;
254 if (__pVisualElement)
256 __pVisualElement->Destroy();
257 __pVisualElement = null;
262 _Token::GetTextPixelWidth(void) const
264 return __textPixelWidth;
268 _Token::GetText(void) const
270 return __pTextBuffer;
273 _TokenEditPresenter::_TokenEditPresenter(void)
276 , __pTokenBgBitmap(null)
277 , __pTokenBgNormalEffectBitmap(null)
278 , __pTokenBgPressedEffectBitmap(null)
279 , __pTokenBgReplacementFocusBitmap(null)
280 , __pTokenBgFocusEffectBitmap(null)
281 , __pressedTokenIndex(-1)
282 , __isEditingToken(false)
283 , __editingTokenIndex(-1)
284 , __clientRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
285 , __initTextRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
286 , __isEditModeEnabled(true)
287 , __pDescriptionTextVisualElement(null)
288 , __pDescriptionTextTextObject(null)
289 , __isTokenEditingFinished(false)
290 , __prevScrollValue(0.0f)
291 , __scrollValue(0.0f)
292 , __isTokenScrolling(false)
293 , __isNeedToScroll(false)
294 , __maxScrollValue(0.0f)
295 , __autoShrink(false)
296 , __descriptionText(String())
297 , __isPopupVisible(false)
298 , __isLongPressed(false)
299 , __lineSpacing(0.0f)
300 , __animatingIndex(-1)
301 , __lastTokenIndex(-1)
302 , __pTimingFunction(null)
303 , __descriptionTextRectForScroll(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
304 , __previousTitleWidth(-1.0f)
305 , __isTokenEditPresenterInitialized(false)
307 , __previousCursorPosition(0)
308 , __isScrollValueChanged(false)
310 , __isScrollValueModified(false)
311 , __isTouchMoveInProgress(false)
312 , __isTitleSliding(false)
313 , __touchPressInfo(FloatPoint(-1.0f, -1.0f))
314 , __editContentFontSize(0.0f)
315 , __trackTokenIndex(-1)
316 , __isAnimationInProgress(false)
317 , __focusOutIndex(-1)
318 , __accessibilityElements()
319 , __focusedTokenIndex(-1)
320 , __drawFocusState(false)
325 _TokenEditPresenter::InitializeDescriptionText(void)
327 result r = E_SUCCESS;
328 float descriptionTextSize = 0.0f;
330 float editFontSize = 0.0f;
332 __pDescriptionTextTextObject = new (std::nothrow) TextObject();
333 SysTryReturnResult(NID_UI_CTRL, __pDescriptionTextTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
335 // for default initialize.
336 r = __pDescriptionTextTextObject->Construct();
337 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
339 r = __pDescriptionTextTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
340 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
342 r = __pDescriptionTextTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
343 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
345 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, descriptionTextSize);
348 SysTryCatch(NID_UI_CTRL, pFont != null, , r, "[%s] Propagating.", GetErrorMessage(r));
350 editFontSize = GetTextSize();
351 (_FontImpl::GetInstance(*pFont))->SetSize(descriptionTextSize);
353 r = __pDescriptionTextTextObject->SetFont(pFont, 0, __pDescriptionTextTextObject->GetTextLength());
354 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
356 (_FontImpl::GetInstance(*pFont))->SetSize(editFontSize);
362 delete __pDescriptionTextTextObject;
363 __pDescriptionTextTextObject = null;
368 _TokenEditPresenter::~_TokenEditPresenter(void)
370 DisposeTokenEditPresenter();
374 _TokenEditPresenter::DisposeTokenEditPresenter(void)
376 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
377 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
379 if (pEditVisualElement && pCursorVisualElement)
381 VisualElement* pCursorParent = pCursorVisualElement->GetParent();
382 if (pCursorParent != pEditVisualElement)
386 pCursorParent->DetachChild(*pCursorVisualElement);
387 pEditVisualElement->AttachChild(*pCursorVisualElement);
394 __pTokenList->RemoveAll(true);
399 delete __pTokenBgBitmap;
400 __pTokenBgBitmap = null;
402 delete __pTokenBgNormalEffectBitmap;
403 __pTokenBgNormalEffectBitmap = null;
405 delete __pTokenBgPressedEffectBitmap;
406 __pTokenBgPressedEffectBitmap = null;
408 delete __pTokenBgReplacementFocusBitmap;
409 __pTokenBgReplacementFocusBitmap = null;
411 delete __pTokenBgFocusEffectBitmap;
412 __pTokenBgFocusEffectBitmap = null;
414 if (__pDescriptionTextVisualElement)
416 __pDescriptionTextVisualElement->Destroy();
417 __pDescriptionTextVisualElement = null;
420 delete __pDescriptionTextTextObject;
421 __pDescriptionTextTextObject = null;
423 if (__pTimingFunction)
425 delete __pTimingFunction;
426 __pTimingFunction = null;
429 RemoveChildAccessibilityElements();
435 _TokenEditPresenter::CreateTokenEditPresenterN(void)
437 _TokenEditPresenter* pPresenter = new (std::nothrow) _TokenEditPresenter();
438 SysTryReturn(NID_UI_CTRL, pPresenter != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
444 _TokenEditPresenter::Initialize(const _Control& control)
446 result r = E_SUCCESS;
448 r = _EditPresenter::Initialize(control);
449 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
451 r = InitializeDescriptionText();
452 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
454 TextObject* pTextObject = GetTextObject();
457 pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
458 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
459 pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
460 pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
463 __pTokenEdit = dynamic_cast< _TokenEdit* >(GetEditView());
464 SysTryReturnResult(NID_UI_CTRL, __pTokenEdit != null, E_SYSTEM, "A system error has occurred. The _Token instance is null.");
466 _TokenEditModel* pTokenEditModel = new (std::nothrow) _TokenEditModel();
467 SysTryReturnResult(NID_UI_CTRL, pTokenEditModel != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
469 SetModel(*pTokenEditModel);
471 SetKeypadEnabled(true);
473 // set title text default colors
474 Color titleTextNormalColor;
475 GET_COLOR_CONFIG(TOKENEDIT::TITLE_TEXT_NORMAL, titleTextNormalColor);
476 __pTokenEdit->SetTitleTextColor(EDIT_STATUS_NORMAL, titleTextNormalColor);
478 Color titleTextPressedColor;
479 GET_COLOR_CONFIG(TOKENEDIT::TITLE_TEXT_PRESSED, titleTextPressedColor);
480 __pTokenEdit->SetTitleTextColor(EDIT_STATUS_PRESSED, titleTextPressedColor);
482 Color titleTextHighlightedColor;
483 GET_COLOR_CONFIG(TOKENEDIT::TITLE_TEXT_HIGHLIGHTED, titleTextHighlightedColor);
484 __pTokenEdit->SetTitleTextColor(EDIT_STATUS_HIGHLIGHTED, titleTextHighlightedColor);
486 Color titleTextDisabledColor;
487 GET_COLOR_CONFIG(TOKENEDIT::TITLE_TEXT_DISABLED, titleTextDisabledColor);
488 __pTokenEdit->SetTitleTextColor(EDIT_STATUS_DISABLED, titleTextDisabledColor);
490 float leftMargin = 0.0f;
491 float rightMargin = 0.0f;
492 float tokenTopMargin = 0.0f;
493 float tokenBottomMargin = 0.0f;
494 float tokenHeight = 0.0f;
495 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
496 Color focusTokenColor;
497 Bitmap* pTokenBgFocusBitmap = null;
499 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
500 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
501 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
502 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
503 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
504 GET_COLOR_CONFIG(TOKENEDIT::BG_HIGHLIGHTED, focusTokenColor);
506 // For drawing token in specific area
507 __clientRect.x = leftMargin;
508 __clientRect.y = tokenTopMargin;
509 __clientRect.width = __pTokenEdit->GetBoundsF().width - leftMargin - rightMargin;
510 __clientRect.height = __pTokenEdit->GetBoundsF().height - tokenTopMargin - tokenBottomMargin;
512 __initTextRect = GetTextBoundsF();
514 FloatRectangle tempDspRect(__initTextRect.x, __initTextRect.y, __clientRect.width, tokenHeight);
515 SetTextBounds(tempDspRect);
517 float textSize = 0.0f;
518 GET_SHAPE_CONFIG(TOKENEDIT::TEXT_SIZE, orientation, textSize);
520 __editContentFontSize = textSize;
522 _EditPresenter::SetTextSize(__editContentFontSize);
524 __pTokenList = new (std::nothrow) Collection::LinkedList();
525 SysTryCatch(NID_UI_CTRL, __pTokenList != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
529 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgBitmap);
530 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
532 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_NORMAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgNormalEffectBitmap);
533 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
535 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_PRESSED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgPressedEffectBitmap);
536 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
538 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pTokenBgFocusBitmap);
539 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
541 __pTokenBgReplacementFocusBitmap = _BitmapImpl::GetColorReplacedBitmapN(
542 *pTokenBgFocusBitmap,Color::GetColor(COLOR_ID_MAGENTA), focusTokenColor);
543 SysTryCatch(NID_UI_CTRL, __pTokenBgReplacementFocusBitmap != null, , r, "[%s] Propagating.", GetErrorMessage(r));
545 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_FOCUS_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgFocusEffectBitmap);
546 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
548 delete pTokenBgFocusBitmap;
549 pTokenBgFocusBitmap = null;
552 __isTokenEditPresenterInitialized = true;
554 __previousCursorPosition = GetCursorPosition();
560 delete pTokenEditModel;
561 pTokenEditModel = null;
563 delete __pTokenBgBitmap;
564 __pTokenBgBitmap = null;
566 delete __pTokenBgNormalEffectBitmap;
567 __pTokenBgNormalEffectBitmap = null;
569 delete __pTokenBgPressedEffectBitmap;
570 __pTokenBgPressedEffectBitmap = null;
572 delete pTokenBgFocusBitmap;
573 pTokenBgFocusBitmap = null;
575 delete __pTokenBgReplacementFocusBitmap;
576 __pTokenBgReplacementFocusBitmap = null;
582 _TokenEditPresenter::DrawText(void)
584 bool isCustomBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_NORMAL);
585 //Checking IsBlocked() is additional check for handler movement in token edit mode
586 if ((__isEditingToken) && (__editingTokenIndex >= 0))
588 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
591 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
592 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element of token.");
594 Canvas* pTokenCanvas = pTokenVisualElement->GetCanvasN();
595 SysTryReturnVoidResult(NID_UI_CTRL, pTokenCanvas != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get canvas of the token.");
597 FloatRectangle tokenRect(0.0f, 0.0f, pToken->displayRect.width, pToken->displayRect.height);
598 pTokenCanvas->SetBackgroundColor(Color(0));
599 pTokenCanvas->Clear();
601 Color selectedTokenColor = GetTokenEditColor(TOKEN_EDIT_STATUS_SELECTED);
602 Bitmap* pReplacementColorBackgroundBitmap = null;
603 if (__pTokenBgBitmap)
605 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), selectedTokenColor);
607 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
609 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
613 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
618 pTokenCanvas->FillRectangle(selectedTokenColor, tokenRect);
621 if (__pTokenBgPressedEffectBitmap && (!isCustomBitmap))
623 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgPressedEffectBitmap))
625 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
629 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
633 _EditPresenter::DrawText(*pTokenCanvas);
638 delete pReplacementColorBackgroundBitmap;
643 _VisualElement* pTextVisualElement = null;
644 pTextVisualElement = GetTextVisualElement();
645 if (pTextVisualElement)
647 _EditPresenter::DrawText();
651 Canvas* pCanvas = __pTokenEdit->GetCanvasN();
652 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element of Control.");
654 _EditPresenter::DrawText(*pCanvas);
663 _TokenEditPresenter::Draw(Canvas& canvas)
665 if (!IsInitialized())
667 InitializeAtFirstDrawing();
669 if (IsFocused() == true)
675 canvas.SetBackgroundColor(Color(0, 0, 0, 0));
678 DrawBackground(canvas);
682 if (__pDescriptionTextTextObject->GetTextLength() != 0)
684 DrawDescriptionText();
687 if (GetTokenCount() != 0)
692 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
693 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
695 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
696 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
698 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
702 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
703 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get visual element of token.");
705 if (__isEditingToken)
707 Canvas* pTokenCanvas = pTokenVisualElement->GetCanvasN();
708 SysTryReturnResult(NID_UI_CTRL, pTokenCanvas != null, E_SYSTEM, "A system error has occurred. Failed to get canvas of the token.");
710 _EditPresenter::DrawText(*pTokenCanvas);
725 SysTryReturnResult(NID_UI_CTRL, !__isEditingToken, E_SYSTEM, "An invalid argument is given.");
731 if (__isTokenEditingFinished)
733 __isEditingToken = false;
734 __editingTokenIndex = -1;
735 _EditPresenter::SetTextSize(__editContentFontSize);
737 __isTokenEditingFinished = false;
744 _TokenEditPresenter::DrawToken(int count)
746 int drawStartIndex = 0;
748 float tokenTextLeftMargin = 0.0f;
749 float tokenVerticalSpacing = 0.0f;
750 bool isCustomBitmap = false;
751 bool isCustomFocusBitmap = false;
753 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
755 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
757 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
758 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
760 isCustomBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_NORMAL);
761 isCustomFocusBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_FOCUS);
764 if (__drawFocusState)
766 __pTokenEdit->RefreshFocusUi();
771 tokenCount = __pTokenList->GetCount();
778 Color normalTokenColor;
779 Color selectedTokenColor;
780 Color disabledTokenColor;
782 for (int i = drawStartIndex; i < tokenCount; i++)
784 Bitmap* pReplacementColorBackgroundBitmap = null;
786 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
787 if (pToken == null || pToken->pTextObject == null)
789 SysLog(NID_UI_CTRL, "[E_SYSTEM] The _Token instance is null");
793 normalTokenColor = GetTokenEditColor(TOKEN_EDIT_STATUS_NORMAL);
794 selectedTokenColor = GetTokenEditColor(TOKEN_EDIT_STATUS_SELECTED);
795 disabledTokenColor = GetTokenEditColor(TOKEN_EDIT_STATUS_DISABLED);
797 _VisualElement* pTokenElement = pToken->GetVisualElement();
798 if (pTokenElement == null)
800 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. The _VisualElement instance is null");
804 bool isSelected = false;
805 Canvas* pTokenCanvas = pTokenElement->GetCanvasN();
806 if (pTokenCanvas == null)
808 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. The Canvas instance is null");
811 FloatRectangle tokenRect(0.0f, 0.0f, pToken->displayRect.width, pToken->displayRect.height);
812 pTokenCanvas->SetBackgroundColor(Color(0));
813 pTokenCanvas->Clear();
815 if (__pressedTokenIndex == i && IsFocused())
817 if (__pTokenBgBitmap)
819 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), selectedTokenColor);
821 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
823 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
827 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
832 pTokenCanvas->FillRectangle(selectedTokenColor, tokenRect);
836 if (__pTokenBgPressedEffectBitmap && (!isCustomBitmap))
838 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgPressedEffectBitmap))
840 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
844 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
852 Color tokenBgColor = normalTokenColor;
853 if (GetCurrentStatus() == EDIT_STATUS_DISABLED)
855 tokenBgColor = disabledTokenColor;
858 if (__pTokenBgBitmap)
860 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), tokenBgColor);
862 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
864 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
868 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
873 pTokenCanvas->FillRectangle(tokenBgColor, tokenRect);
877 if (__pTokenBgNormalEffectBitmap && (!isCustomBitmap))
879 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgNormalEffectBitmap))
881 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgNormalEffectBitmap);
885 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgNormalEffectBitmap);
890 if (__focusedTokenIndex == i && __drawFocusState && (!__isEditingToken))
892 if (__pTokenBgReplacementFocusBitmap)
894 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgReplacementFocusBitmap))
896 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgReplacementFocusBitmap);
900 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgReplacementFocusBitmap);
904 if (__pTokenBgFocusEffectBitmap && (!isCustomFocusBitmap))
906 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgFocusEffectBitmap))
908 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgFocusEffectBitmap);
912 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgFocusEffectBitmap);
918 pTokenElement->SetAnimationProvider(null);
919 if (pToken->isImplicitAnimation)
921 VisualElementAnimation* pAnimation = CreateAnimationN(*pTokenElement, true);
922 pTokenElement->AddAnimation(*pAnimation);
924 pToken->isImplicitAnimation = false;
927 if (!__isEditingToken || __pressedTokenIndex != i)
930 FloatRectangle textRect(0.0f, 0.0f, pToken->displayRect.width - ((tokenTextLeftMargin * 2.0f)), pToken->displayRect.height - tokenVerticalSpacing);
932 textRect.x += tokenTextLeftMargin;
933 textRect.y += (tokenVerticalSpacing / 2.0f);
937 textColor = GetTokenEditTextColor(TOKEN_EDIT_STATUS_SELECTED);
941 textColor = GetTokenEditTextColor(TOKEN_EDIT_STATUS_NORMAL);
944 pToken->pTextObject->SetForegroundColor(textColor, 0, pToken->pTextObject->GetTextLength());
945 pToken->pTextObject->SetBounds(textRect);
946 pToken->pTextObject->Compose();
947 pToken->pTextObject->Draw(*_CanvasImpl::GetInstance(*pTokenCanvas));
950 pTokenElement->SetFlushNeeded();
953 delete pReplacementColorBackgroundBitmap;
954 pReplacementColorBackgroundBitmap = null;
960 _TokenEditPresenter::GetTokenEditColor(const TokenEditStatus status) const
962 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, Color(0, 0, 0, 0), E_INVALID_STATE, "[E_INVALID_STATE] _TokenEdit is in an invalid state.");
964 return __pTokenEdit->GetTokenColor(status);
968 _TokenEditPresenter::GetTokenEditTextColor(const TokenEditStatus status) const
970 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, Color(0, 0, 0, 0), E_INVALID_STATE, "[E_INVALID_STATE] _TokenEdit is in an invalid state.");
974 if (status == TOKEN_EDIT_STATUS_NORMAL)
976 color = __pTokenEdit->GetTokenTextColor();
980 color = __pTokenEdit->GetSelectedTokenTextColor();
987 _TokenEditPresenter::MakeToken(const String& tokenString)
989 SysTryReturnResult(NID_UI_CTRL, __pTokenEdit != null, E_INVALID_STATE, "_TokenEdit is in an invalid state.");
990 result r = E_SUCCESS;
994 int tokenLength = tokenString.GetLength();
995 SysTryReturnResult(NID_UI_CTRL, tokenLength, E_INVALID_ARG, "Invalid argument is used. Token length is (%d)", tokenLength);
997 String inputTokenString = tokenString;
998 String replacementString = inputTokenString;
1001 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
1005 inputTokenString = replacementString;
1008 if (inputTokenString.GetLength() <= 0)
1011 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to clear text object.", GetErrorMessage(r));
1013 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
1014 return E_INVALID_ARG;
1017 _Token* pToken = new (std::nothrow) _Token();
1018 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1020 r = pToken->Construct(inputTokenString, GetFont());
1021 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct token.", GetErrorMessage(r));
1023 r = __pTokenList->Add(static_cast< Object& >(*pToken));
1024 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1026 tokenCount = __pTokenList->GetCount();
1027 index = tokenCount - 1;
1029 r = CalculateTokenPositionFromIndex(index);
1030 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to calculate token position.", GetErrorMessage(r));
1032 r = TrimTokenAndAdjustEllipsisAt(index);
1033 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to trim token.", GetErrorMessage(r));
1035 r = InitializeTokenVisibilityAt(index);
1036 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to initialize token visibility.", GetErrorMessage(r));
1038 r = SetInitialBounds();
1039 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds.", GetErrorMessage(r));
1042 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to clear text object.", GetErrorMessage(r));
1044 r = AdjustFlexibleHeight();
1045 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process to resize.", GetErrorMessage(r));
1047 r = CheckTokenScrolling();
1048 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process scroll.", GetErrorMessage(r));
1050 AppendTokenAccessibilityElement();
1051 UpdateTokenAccessibilityBounds();
1056 __pTokenList->Remove(*pToken);
1065 _TokenEditPresenter::MakeToken(void)
1067 result r = E_SUCCESS;
1069 String tempToken(GetText());
1070 r = MakeToken(tempToken);
1076 _TokenEditPresenter::AppendToken(const Tizen::Base::String& token)
1078 result r = E_SUCCESS;
1080 r = MakeToken(token);
1081 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1083 if (__editingTokenIndex >= 0)
1085 SetEditingTokenTextBounds(__editingTokenIndex);
1086 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1093 _TokenEditPresenter::InsertTokenAt(int index, const String& token, bool isUser)
1095 SysTryReturnResult(NID_UI_CTRL, index >= 0, E_INVALID_ARG, "Invalid argument is used. index is (%d).", index);
1096 SysTryReturnResult(NID_UI_CTRL, token.GetLength() > 0, E_INVALID_ARG, "Invalid argument is used. Token length is (%d).", token.GetLength());
1098 result r = E_SUCCESS;
1100 _Token* pToken = new (std::nothrow) _Token();
1101 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1103 r = pToken->Construct(token, GetFont());
1104 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct token.", GetErrorMessage(r));
1106 r = __pTokenList->InsertAt(*pToken, index);
1107 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to insert token.", GetErrorMessage(r));
1111 r = CalculateTokenPositionFromIndex(index);
1112 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to calculate token position.", GetErrorMessage(r));
1114 r = TrimTokenAndAdjustEllipsisAt(index);
1115 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to trim token.", GetErrorMessage(r));
1117 r = InitializeTokenVisibilityAt(index);
1118 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to initialize token visibility.", GetErrorMessage(r));
1120 r = SetInitialBounds();
1121 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds.", GetErrorMessage(r));
1123 r = AdjustFlexibleHeight();
1124 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process to resize.", GetErrorMessage(r));
1126 r = CheckTokenScrolling();
1127 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process scroll.", GetErrorMessage(r));
1129 for (int i = 0; i < GetTokenCount(); i++)
1131 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
1132 SysTryCatch(NID_UI_CTRL, pToken != null, , r = E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
1134 r = pToken->SetBounds(pToken->displayRect);
1135 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds", GetErrorMessage(r));
1138 InsertTokenAccessibilityElementAt(index);
1142 if (__editingTokenIndex >= 0)
1144 if (index <= __editingTokenIndex)
1146 __editingTokenIndex++;
1148 __pressedTokenIndex = __editingTokenIndex;
1150 SetEditingTokenTextBounds(__editingTokenIndex);
1151 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1153 else if (__pressedTokenIndex >= index)
1155 __pressedTokenIndex++;
1157 else if ((__focusedTokenIndex >= index) && __drawFocusState)
1159 __focusedTokenIndex++;
1166 __pTokenList->Remove(*pToken);
1175 _TokenEditPresenter::GetTokenAt(int index) const
1178 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);
1180 _Token* pToken = null;
1181 pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
1184 tempString = pToken->GetText();
1191 _TokenEditPresenter::GetTokenCount(bool isInvokedByApp) const
1193 if (!isInvokedByApp)
1195 return __pTokenList->GetCount();
1199 if (__isAnimationInProgress)
1201 return __pTokenList->GetCount() - 1;
1205 return __pTokenList->GetCount();
1211 _TokenEditPresenter::GetSelectedTokenIndex(void) const
1213 return __pressedTokenIndex;
1217 _TokenEditPresenter::IsTokenEditModeEnabled(void) const
1219 return __isEditModeEnabled;
1223 _TokenEditPresenter::RemoveTokenAt(int index, bool isClearText)
1225 result r = E_SUCCESS;
1226 SysTryReturnResult(NID_UI_CTRL, index >= 0 && index < __pTokenList->GetCount(), E_OUT_OF_RANGE, "index (%d) is out of range.", index);
1228 if (index == __editingTokenIndex && isClearText)
1230 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
1231 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
1233 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
1234 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
1236 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
1237 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1239 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
1240 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1242 __editingTokenIndex = -1;
1243 __isEditingToken = false;
1244 __pressedTokenIndex = -1;
1245 __isTokenEditingFinished = true;
1248 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Failed to clear text object.");
1250 _EditPresenter::SetTextSize(__editContentFontSize);
1253 r = __pTokenList->RemoveAt(index, true);
1254 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove token.");
1256 r = CalculateTokenPositionFromIndex(index);
1257 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to calculate token position.");
1259 r = SetInitialBounds();
1260 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
1262 _Token* pToken = null;
1264 for (int i = 0; i < GetTokenCount(); i++)
1266 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
1267 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
1269 r = pToken->SetBounds(pToken->displayRect);
1270 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds");
1273 r = AdjustFlexibleHeight();
1274 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to process to resize.");
1276 r = CheckTokenScrolling();
1277 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to process scroll.");
1279 RemoveTokenAccessibilityElementAt(index);
1280 UpdateTokenAccessibilityBounds();
1284 if (index > __editingTokenIndex)
1286 SetEditingTokenTextBounds(__editingTokenIndex);
1287 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1289 if (index < __editingTokenIndex)
1291 if (__editingTokenIndex > 0)
1293 __editingTokenIndex--;
1294 __pressedTokenIndex = __editingTokenIndex;
1296 SetEditingTokenTextBounds(__editingTokenIndex);
1297 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1300 else if (index == __pressedTokenIndex)
1302 __pressedTokenIndex = -1;
1304 SetCursorDisabled(false);
1307 else if (index >= 0 && index < __pressedTokenIndex)
1309 __pressedTokenIndex--;
1312 if (__drawFocusState)
1314 if (index == __focusedTokenIndex)
1316 __focusedTokenIndex = -1;
1318 SetCursorDisabled(false);
1321 else if(index >= 0 && index < __focusedTokenIndex)
1323 __focusedTokenIndex--;
1327 else if (index == __pressedTokenIndex)
1329 __pressedTokenIndex = -1;
1331 SetCursorDisabled(false);
1334 else if ((index == __focusedTokenIndex) && __drawFocusState)
1336 __focusedTokenIndex = -1;
1338 SetCursorDisabled(false);
1346 _TokenEditPresenter::SetTokenSelected(int index, bool selected)
1348 result r = E_SUCCESS;
1350 SysTryReturnResult(NID_UI_CTRL, index >= 0 && index < __pTokenList->GetCount(), E_OUT_OF_RANGE, "index (%d) is out of range.");
1352 if (selected == false)
1354 __pressedTokenIndex = -1;
1358 __pressedTokenIndex = index;
1365 _TokenEditPresenter::SetTokenEditModeEnabled(bool enable)
1367 result r = E_SUCCESS;
1369 __isEditModeEnabled = enable;
1375 _TokenEditPresenter::CalculateTokenPositionFromIndex(int startIndex, bool leftWard)
1377 result r = E_SUCCESS;
1379 int tokenCount = __pTokenList->GetCount();
1381 float leftMargin = 0.0f;
1382 float rightMargin = 0.0f;
1383 float tokenTopMargin = 0.0f;
1384 float tokenBottomMargin = 0.0f;
1385 float tokenHeight = 0.0f;
1386 float tokenVerticalSpacing = 0.0f;
1387 float tokenHorizontalSpacing = 0.0f;
1388 float tokenTextLeftMargin = 0.0f;
1389 float tokenTextRightMargin = 0.0f;
1390 float descriptionTextRightMargin = 0.0f;
1391 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1393 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
1394 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
1395 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1396 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
1397 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1398 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1399 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HORIZONTAL_SPACING, orientation, tokenHorizontalSpacing);
1400 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1401 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1402 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_RIGHT_MARGIN, orientation, descriptionTextRightMargin);
1404 SysTryReturn(NID_UI_CTRL, startIndex >= 0 && startIndex <= tokenCount, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. startIndex = (%d)", startIndex);
1406 _Token* pToken = null;
1407 _Token* pPreviousToken = null;
1409 int index = startIndex;
1411 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
1412 String titleText = __pTokenEdit->GetTitleText();
1414 if (!_FloatCompare(GetDescriptionTextRect().width, __previousTitleWidth))
1416 __descriptionTextRectForScroll = GetDescriptionTextRect();
1417 __previousTitleWidth = GetDescriptionTextRect().width;
1420 bool findPrevTokenLoopFlag = true;
1421 for (; index < tokenCount; index++)
1423 pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
1424 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
1428 // TODO : description text (title style inner)
1429 if (titleText.GetLength())
1431 pToken->displayRect.x = __descriptionTextRectForScroll.x + __descriptionTextRectForScroll.width + descriptionTextRightMargin;
1432 pToken->displayRect.y = __descriptionTextRectForScroll.y + __scrollValue;
1434 else // Set description text.
1436 pToken->displayRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1437 pToken->displayRect.y = tokenTopMargin + __scrollValue + __pTokenEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN) + __lineSpacing;
1440 pToken->displayRect.width = tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin;
1445 if (findPrevTokenLoopFlag)
1447 pPreviousToken = static_cast< _Token* >(__pTokenList->GetAt(index - 1));
1448 findPrevTokenLoopFlag = false;
1451 float tempTextWidth = tokenEditBounds.width - pPreviousToken->displayRect.x - pPreviousToken->displayRect.width - tokenHorizontalSpacing - rightMargin - __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1452 if (tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin > tempTextWidth) // Line change
1454 pToken->displayRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1455 pToken->displayRect.y = pPreviousToken->displayRect.y + tokenHeight + tokenVerticalSpacing + __lineSpacing;
1460 pToken->displayRect.x = pPreviousToken->displayRect.x + pPreviousToken->displayRect.width +
1461 tokenHorizontalSpacing;
1462 pToken->displayRect.y = pPreviousToken->displayRect.y;
1465 pToken->displayRect.width = tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin;
1468 pToken->displayRect.height = tokenHeight;
1470 pPreviousToken = pToken;
1473 for (int i = 0; i < __pTokenList->GetCount(); i++)
1475 TrimTokenAndAdjustEllipsisAt(i);
1476 InitializeTokenVisibilityAt(i);
1482 _TokenEditPresenter::InitializeTokenVisibilityAt(int ndex)
1484 result r = E_SUCCESS;
1486 _Token* pToken = null;
1487 pToken = static_cast< _Token* >(__pTokenList->GetAt(ndex));
1488 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
1490 r = pToken->SetBounds(pToken->displayRect);
1491 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to set bounds", GetErrorMessage(r));
1493 _VisualElement* pRootElement = __pTokenEdit->GetVisualElement();
1494 SysTryReturn(NID_UI_CTRL, pRootElement, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
1496 _VisualElement* pVisualElement = pToken->GetVisualElement();
1497 SysTryReturn(NID_UI_CTRL, pVisualElement, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element.");
1499 pVisualElement->SetShowState(true);
1501 r = pRootElement->AttachChild(*pVisualElement);
1502 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to add child", GetErrorMessage(r));
1508 _TokenEditPresenter::GetMaxTextHeight(void)
1511 float maxHeight = __editContentFontSize;
1514 SysTryReturn(NID_UI_CTRL, pFont != null, maxHeight, E_SYSTEM, "[E_SYSTEM] Failed to get Font instance.");
1516 maxHeight = pFont->GetMaxHeightF();
1522 _TokenEditPresenter::ResetTextBounds(void)
1524 if (!__isEditingToken)
1526 result r = SetInitialBounds();
1527 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occured. Failed to set margin.");
1533 _TokenEditPresenter::SetInitialBounds(void)
1535 result r = E_SUCCESS;
1537 float leftMargin = 0.0f;
1538 float rightMargin = 0.0f;
1539 float tokenTopMargin = 0.0f;
1540 float tokenHeight = 0.0f;
1541 float tokenMinWidth = 0.0f;
1542 float tokenVerticalSpacing = 0.0f;
1543 float tokenHorizontalSpacing = 0.0f;
1544 float tokenTextLeftMargin = 0.0f;
1545 float tokenTextRightMargin = 0.0f;
1546 float textBoundsAlignValue = 0.0f;
1547 float descriptionTextRightMargin = 0.0f;
1548 _ControlOrientation orientation = GetEditView()->GetOrientation();
1550 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
1551 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
1552 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1553 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1554 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_MIN_WIDTH, orientation, tokenMinWidth);
1555 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1556 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HORIZONTAL_SPACING, orientation, tokenHorizontalSpacing);
1557 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1558 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1559 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_RIGHT_MARGIN, orientation, descriptionTextRightMargin);
1561 float textObjectMaxHeight = GetMaxTextHeight();
1562 textBoundsAlignValue = (tokenHeight - textObjectMaxHeight) / 2.0f;
1566 int tokenCount = __pTokenList->GetCount();
1568 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
1569 FloatRectangle tokenTextRect = tokenEditBounds;
1571 if (tokenCount == 0)
1573 if (__pTokenEdit->GetTitleText().GetLength())
1575 FloatRectangle descriptionTextRect = GetDescriptionTextRect();
1576 tokenTextRect.x = descriptionTextRect.x + descriptionTextRect.width + descriptionTextRightMargin;
1580 tokenTextRect.x = leftMargin + __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_LEFT_MARGIN);
1583 tokenTextRect.y = tokenTopMargin + __pTokenEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN) + textBoundsAlignValue;
1584 tokenTextRect.width -= tokenTextRect.x + rightMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1585 tokenTextRect.height = textObjectMaxHeight;
1587 SetTextBounds(tokenTextRect);
1588 //set cursor bounds with tokenTextRect
1589 __pTokenEdit->SetCursorAccessibilityBounds(tokenTextRect);
1593 _Token* pToken = null;
1594 // SetTextBounds from last token
1595 pToken = static_cast< _Token* >(__pTokenList->GetAt(tokenCount - 1));
1596 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
1598 float tempTextRectWidth = 0.0f;
1599 tempTextRectWidth = tokenEditBounds.width - pToken->displayRect.x - pToken->displayRect.width - tokenHorizontalSpacing - rightMargin - __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1600 if (tokenMinWidth > tempTextRectWidth) // Line change
1602 tokenTextRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1603 tokenTextRect.y = pToken->displayRect.y + tokenHeight + tokenVerticalSpacing + __lineSpacing + textBoundsAlignValue;
1607 tokenTextRect.x = pToken->displayRect.x + pToken->displayRect.width + tokenHorizontalSpacing;
1608 tokenTextRect.y = pToken->displayRect.y + textBoundsAlignValue;
1611 tokenTextRect.width -= tokenTextRect.x + rightMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1612 tokenTextRect.height = textObjectMaxHeight;
1614 SetTextBounds(tokenTextRect);
1615 if (__pressedTokenIndex < 0) // Set cursor as global focused element if no token is selected
1617 __pTokenEdit->SetCursorAccessibilityBounds(tokenTextRect);
1623 r = _EditPresenter::SetInitialBounds();
1630 _TokenEditPresenter::SetDescriptionTextRect(const FloatRectangle& rect)
1632 result r = E_SUCCESS;
1634 __descriptionTextRect = rect;
1640 _TokenEditPresenter::GetDescriptionTextRect() const
1642 return __descriptionTextRect;
1646 _TokenEditPresenter::GetTextBounds(void) const
1648 if ((__isPopupVisible == true || __isLongPressed == true) && __pressedTokenIndex >= 0)
1650 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__pressedTokenIndex));
1651 SysTryReturn(NID_UI_CTRL, pToken, Rectangle(), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Unable to get valid token.");
1653 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1654 float tokenTextLeftMargin = 0.0f;
1655 float tokenTextVerticalMargin = 0.0f;
1656 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1657 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenTextVerticalMargin);
1659 FloatRectangle textBoundsF(pToken->displayRect.x + tokenTextLeftMargin, pToken->displayRect.y + (tokenTextVerticalMargin / 2.0f), pToken->displayRect.width - (tokenTextLeftMargin * 2.0f), pToken->displayRect.height - tokenTextVerticalMargin);
1660 Rectangle textBounds = _CoordinateSystemUtils::ConvertToInteger(textBoundsF);
1666 return _EditPresenter::GetTextBounds();
1671 _TokenEditPresenter::GetTextBoundsF(void) const
1673 if ((__isPopupVisible == true || __isLongPressed == true) && __pressedTokenIndex >= 0)
1675 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__pressedTokenIndex));
1676 SysTryReturn(NID_UI_CTRL, pToken, FloatRectangle(), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Unable to get valid token.");
1678 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1679 int tokenTextLeftMargin = 0;
1680 int tokenTextVerticalMargin = 0;
1681 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1682 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenTextVerticalMargin);
1684 FloatRectangle textBounds(pToken->displayRect.x + tokenTextLeftMargin, pToken->displayRect.y + (tokenTextVerticalMargin / 2.0f), pToken->displayRect.width - (tokenTextLeftMargin * 2.0f), pToken->displayRect.height - tokenTextVerticalMargin);
1690 return _EditPresenter::GetTextBoundsF();
1695 _TokenEditPresenter::CutText(void)
1697 if (__isEditingToken)
1699 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
1700 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
1702 pToken->isTextCut = true;
1704 return _EditPresenter::CutText();
1708 _TokenEditPresenter::SetLineSpacing(int linePixelGap)
1710 __lineSpacing = linePixelGap;
1716 _TokenEditPresenter::SetLineSpacing(float linePixelGap)
1718 __lineSpacing = linePixelGap;
1724 _TokenEditPresenter::GetLineSpacing(void) const
1726 int lineSpacing = _CoordinateSystemUtils::ConvertToInteger(__lineSpacing);
1731 _TokenEditPresenter::GetLineSpacingF(void) const
1733 return __lineSpacing;
1736 VisualElementAnimation*
1737 _TokenEditPresenter::CreateAnimationN(VisualElement& source, bool create)
1739 VisualElementAnimation* pAnimation = null;
1740 VisualElementAnimationGroup* pAnimationGroup = new (std::nothrow) VisualElementAnimationGroup();
1741 SysTryReturn(NID_UI_CTRL, pAnimationGroup, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1743 pAnimationGroup->SetDuration(ANIMATION_DURATION_BOUNDS);
1744 if (__pTimingFunction == null)
1746 __pTimingFunction = new (std::nothrow) SineTimingFunction();
1747 SysTryReturn(NID_UI_CTRL, __pTimingFunction, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1750 if (pAnimationGroup != null)
1752 VisualElementPropertyAnimation* pOpacityAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1753 SysTryReturn(NID_UI_CTRL, pOpacityAnimation, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1755 pOpacityAnimation->SetPropertyName("opacity");
1758 pOpacityAnimation->SetStartValue(Variant(1.0f));
1759 pOpacityAnimation->SetEndValue(Variant(0.0f));
1763 pOpacityAnimation->SetStartValue(Variant(0.0f));
1764 pOpacityAnimation->SetEndValue(Variant(1.0f));
1767 pOpacityAnimation->SetDuration(ANIMATION_DURATION_OPACITY);
1768 pOpacityAnimation->SetTimingFunction(__pTimingFunction);
1769 pAnimationGroup->AddAnimation(*pOpacityAnimation);
1770 delete pOpacityAnimation;
1772 VisualElementPropertyAnimation* pBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1773 SysTryReturn(NID_UI_CTRL, pBoundsAnimation, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1775 pBoundsAnimation->SetPropertyName("bounds");
1776 FloatRectangle startValue = source.GetBounds();
1777 startValue.x = startValue.x + startValue.width * 0.05;
1778 startValue.y = startValue.y + startValue.height * 0.05;
1779 startValue.width = startValue.width * 0.9;
1780 startValue.height = startValue.height * 0.9;
1784 pBoundsAnimation->SetStartValue(Variant(source.GetBounds()));
1785 pBoundsAnimation->SetEndValue(Variant(startValue));
1786 pBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1790 pBoundsAnimation->SetStartValue(Variant(startValue));
1791 pBoundsAnimation->SetEndValue(Variant(source.GetBounds()));
1794 pBoundsAnimation->SetDuration(ANIMATION_DURATION_BOUNDS);
1795 pBoundsAnimation->SetTimingFunction(__pTimingFunction);
1796 pAnimationGroup->AddAnimation(*pBoundsAnimation);
1798 delete pBoundsAnimation;
1800 pAnimation = pAnimationGroup;
1806 _TokenEditPresenter::CalculateDescriptionTextRect(const String& descriptionText)
1808 result r = E_SUCCESS;
1810 TextSimple* pSimpleText = null;
1811 float leftMargin = 0.0f;
1812 float tokenTopMargin = 0.0f;
1813 float tokenHeight = 0.0f;
1814 float tokenVerticalSpacing = 0.0f;
1815 float tokenTextLeftMargin = 0.0f;
1816 float tokenTextRightMargin = 0.0f;
1817 float tokenTitleWidth = 0.0f;
1818 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1820 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1821 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
1822 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1823 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1824 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1825 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1826 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TITLE_RECT_WIDTH, orientation, tokenTitleWidth);
1828 int length = descriptionText.GetLength();
1829 FloatDimension textSize;
1831 wchar_t* pTempString = const_cast< wchar_t* >(descriptionText.GetPointer());
1833 SysAssertf(__pDescriptionTextTextObject != null, "The TextObject instance is null.");
1835 __pDescriptionTextTextObject->RemoveAll(true);
1836 pSimpleText = new (std::nothrow) TextSimple(pTempString, length, TEXT_ELEMENT_SOURCE_TYPE_INTERNAL);
1837 __pDescriptionTextTextObject->AppendElement(*pSimpleText);
1839 textSize = __pDescriptionTextTextObject->GetTextExtentF(0, length);
1840 r = __pDescriptionTextTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1841 r = __pDescriptionTextTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
1843 __descriptionTextRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1844 __descriptionTextRect.y = tokenTopMargin + __pTokenEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN);
1845 if (textSize.width > tokenTitleWidth)
1847 textSize.width = tokenTitleWidth;
1848 __pDescriptionTextTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
1851 __descriptionTextRect.width = tokenTextLeftMargin + textSize.width + tokenTextRightMargin;
1852 __descriptionTextRect.height = tokenHeight;
1853 __pDescriptionTextTextObject->SetBounds(__descriptionTextRect);
1855 if (__pDescriptionTextTextObject->IsChanged())
1857 _EditPresenter::StopTitleSlidingTimer();
1858 __isTitleSliding = false;
1861 r = __pDescriptionTextTextObject->Compose();
1867 _TokenEditPresenter::IsGuideTextActivated(void) const
1869 bool isGuideTextActivated = _EditPresenter::IsGuideTextActivated();
1871 if (__isTokenEditPresenterInitialized)
1873 if (GetTokenCount())
1879 return isGuideTextActivated;
1883 _TokenEditPresenter::DrawDescriptionText(void)
1885 result r = E_SUCCESS;
1886 FloatRectangle tempDescriptionTextRect;
1887 FloatRectangle descriptionTextRect(__descriptionTextRect);
1888 Canvas* pDescriptionTextCanvas = null;
1890 Font* pDescriptionFont = null;
1891 TextObjectActionType titleAction;
1892 _VisualElement* pRootElement = null;
1894 if (__pDescriptionTextTextObject->GetFont(0)->GetFaceName() != GetTitleFontFaceName())
1896 float descriptionTextSize = 0.0f;
1897 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, descriptionTextSize);
1899 pDescriptionFont = GetFont();
1900 if (pDescriptionFont)
1902 float editFontSize = GetTextSize();
1903 (_FontImpl::GetInstance(*pDescriptionFont))->SetSize(descriptionTextSize);
1905 r = __pDescriptionTextTextObject->SetFont(pDescriptionFont, 0, __pDescriptionTextTextObject->GetTextLength());
1906 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. SetFont failed");
1908 (_FontImpl::GetInstance(*pDescriptionFont))->SetSize(editFontSize);
1912 pRootElement = __pTokenEdit->GetVisualElement();
1913 SysTryCatch(NID_UI_CTRL, pRootElement, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
1915 if (!__pDescriptionTextVisualElement)
1917 __pDescriptionTextVisualElement = new (std::nothrow) _VisualElement();
1918 SysTryCatch(NID_UI_CTRL, __pDescriptionTextVisualElement, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1919 r = __pDescriptionTextVisualElement->Construct();
1920 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[E_SYSTEM] A system error has occurred. Failed to construct _VisualElement");
1921 __pDescriptionTextVisualElement->SetImplicitAnimationEnabled(false);
1922 __pDescriptionTextVisualElement->SetShowState(true);
1924 r = pRootElement->AttachChild(*__pDescriptionTextVisualElement);
1925 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1928 descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
1929 __pDescriptionTextVisualElement->SetBounds(descriptionTextRect);
1930 UpdateTitleAccessibilityBounds(descriptionTextRect); // Update title accessibility bounds to same as DescriptionTextVisualElement bounds
1932 pDescriptionTextCanvas = __pDescriptionTextVisualElement->GetCanvasN();
1933 if (pDescriptionTextCanvas == null)
1935 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to get canvas of an instance of _VisualElement.");
1939 tempDescriptionTextRect = __descriptionTextRect;
1940 tempDescriptionTextRect.x = 0.0f;
1941 tempDescriptionTextRect.y = 0.0f;
1943 titleAction = __pDescriptionTextTextObject->GetAction();
1945 pDescriptionTextCanvas->SetBackgroundColor(Color(0));
1946 pDescriptionTextCanvas->Clear();
1947 __pDescriptionTextTextObject->SetForegroundColor(__pTokenEdit->GetTitleTextColor(GetCurrentStatus()), 0, __pDescriptionTextTextObject->GetTextLength());
1949 if (IsFocused() == true)
1951 if (__pDescriptionTextTextObject->GetTextLengthAt(0) < __pDescriptionTextTextObject->GetTextLength())
1953 if (titleAction != TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT)
1955 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT);
1956 __pDescriptionTextTextObject->Compose();
1961 if (titleAction != TEXT_OBJECT_ACTION_TYPE_NONE)
1963 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
1964 __pDescriptionTextTextObject->Compose();
1968 if (!__isTitleSliding)
1970 _EditPresenter::StopTitleSlidingTimer();
1971 if (__pDescriptionTextTextObject->IsActionOn() == true)
1973 _EditPresenter::StartTitleSlidingTimer();
1974 __isTitleSliding = true;
1980 if (titleAction != TEXT_OBJECT_ACTION_TYPE_ABBREV)
1982 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1983 __pDescriptionTextTextObject->Compose();
1988 __pDescriptionTextTextObject->SetBounds(tempDescriptionTextRect);
1989 __pDescriptionTextTextObject->Draw(*_CanvasImpl::GetInstance(*pDescriptionTextCanvas));
1991 delete pDescriptionTextCanvas;
1996 if (__pDescriptionTextVisualElement != null)
1998 __pDescriptionTextVisualElement->Destroy();
1999 __pDescriptionTextVisualElement = null;
2006 _TokenEditPresenter::TrimTokenAndAdjustEllipsisAt(int index)
2008 result r = E_SUCCESS;
2010 float rightMargin = 0.0f;
2011 float tokenMinimumSize = 0.0f;
2013 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2014 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
2015 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_MIN_WIDTH, orientation, tokenMinimumSize);
2017 _Token* pToken = null;
2018 pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
2019 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
2021 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
2022 FloatRectangle tokenRect = pToken->displayRect;
2024 float remainWidth = tokenEditBounds.width - rightMargin - __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
2026 float dspTokenWidth = tokenRect.x + tokenRect.width;
2027 float dspTokenGap = dspTokenWidth - remainWidth;
2029 if (dspTokenGap > 0.0f)
2031 if (pToken->displayRect.width >= tokenMinimumSize)
2033 if ((pToken->displayRect.width - dspTokenGap) < tokenMinimumSize)
2035 pToken->displayRect.width = tokenMinimumSize;
2039 pToken->displayRect.width -= dspTokenGap;
2044 pToken->pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
2045 pToken->pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
2052 _TokenEditPresenter::GetTokenIndexFromCoordinate(const Point point) const
2054 int tokenIndex = -1;
2056 int tokenCount = __pTokenList->GetCount();
2057 for (int i = 0; i < tokenCount; i++)
2059 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2062 FloatRectangle tokenRect = pToken->displayRect;
2063 if (tokenRect.Contains(FloatPoint(point.x, point.y)))
2074 _TokenEditPresenter::SetEditingTokenTextBounds(int index, bool isSetText)
2076 result r = E_SUCCESS;
2078 float tokenHeight = 0.0f;
2079 float tokenVerticalSpacing = 0.0f;
2080 float tokenTextLeftMargin = 0.0f;
2081 float tokenFontSize = 0.0f;
2082 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2084 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
2085 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
2086 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
2087 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_SIZE, orientation, tokenFontSize);
2089 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
2090 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
2092 FloatRectangle tempTextDspRect;
2093 tempTextDspRect.x += tokenTextLeftMargin;
2094 tempTextDspRect.y += tokenVerticalSpacing / 2.0f;
2095 tempTextDspRect.width = pToken->displayRect.width - (tokenTextLeftMargin * 2.0f);
2096 tempTextDspRect.height = tokenHeight - tokenVerticalSpacing;
2100 if (!pToken->isTextCut)
2102 SetText(pToken->GetText());
2104 pToken->pTextObject->RemoveAll(true);
2107 _EditPresenter::SetTextSize(tokenFontSize);
2109 SetTextBounds(tempTextDspRect);
2115 _TokenEditPresenter::RecalculateTokenBounds(float position)
2117 result r = E_SUCCESS;
2119 __scrollValue = -position;
2121 int tokenCount = GetTokenCount();
2122 CalculateTokenPositionFromIndex(0);
2124 for (int i = 0; i < tokenCount; i++)
2126 _Token* pToken = null;
2127 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2131 pToken->SetBounds(pToken->displayRect);
2133 TrimTokenAndAdjustEllipsisAt(i);
2134 InitializeTokenVisibilityAt(i);
2137 if (__pDescriptionTextTextObject->GetTextLength() != 0)
2139 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2142 __pTokenEdit->Invalidate();
2144 r = SetInitialBounds();
2145 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
2151 _TokenEditPresenter::SetTokenBoundsByTouchInfo(const _TouchInfo& touchinfo)
2153 result r = E_SUCCESS;
2154 int currentYPosition = _CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()).y;
2156 if (_FloatCompare(__prevScrollValue, 0.0f))
2158 __prevScrollValue = currentYPosition;
2160 else // Adjust moved y position to all tokens.
2162 if (__isNeedToScroll) // Need to scroll
2164 float tempDefference = __prevScrollValue - currentYPosition;
2166 __prevScrollValue = currentYPosition;
2167 __scrollValue -= tempDefference;
2169 if (__scrollValue < -__maxScrollValue)
2171 __scrollValue = -__maxScrollValue;
2176 if (__scrollValue > 0.0f)
2178 __scrollValue = 0.0f;
2183 int tokenCount = GetTokenCount();
2184 CalculateTokenPositionFromIndex(0);
2185 for (int i = 0; i < tokenCount; i++)
2187 _Token* pToken = null;
2188 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2192 pToken->SetBounds(pToken->displayRect);
2194 TrimTokenAndAdjustEllipsisAt(i);
2195 InitializeTokenVisibilityAt(i);
2198 if (__pDescriptionTextTextObject->GetTextLength() != 0)
2200 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2203 __pTokenEdit->Invalidate();
2207 __prevScrollValue = 0.0f;
2208 __scrollValue = 0.0f;
2212 r = SetInitialBounds();
2213 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
2219 _TokenEditPresenter::ProcessTokeningByTouchEvent(const _Control& source, const _TouchInfo& touchinfo)
2221 int tokenIndex = GetTokenIndexFromCoordinate(_CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()));
2223 //Reset "longPressed" when Touch released on a different token after long gesture on a token
2224 if (__trackTokenIndex != tokenIndex)
2226 __isLongPressed = false;
2229 int prevPressedTokenIndex = __pressedTokenIndex;
2230 int prevEditedTokenIndex = __editingTokenIndex;
2232 result r = E_SUCCESS;
2235 if (__isEditModeEnabled && __pressedTokenIndex != -1 && __pressedTokenIndex == tokenIndex)
2237 //Comment below to Block Copy & Paste functionality in Token Edit mode
2238 __editingTokenIndex = __pressedTokenIndex;
2239 __isEditingToken = true;
2240 __isTokenEditingFinished = false;
2241 if (prevEditedTokenIndex != __editingTokenIndex)
2243 SetEditingTokenTextBounds(__editingTokenIndex);
2245 SetCursorDisabled(false);
2249 if (tokenIndex != -1)
2251 if (__isEditingToken && (prevPressedTokenIndex != tokenIndex)) // Selected another token while editing.
2253 __isPopupVisible = false;
2254 __isLongPressed = false;
2256 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2257 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
2259 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2260 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
2262 _Token* pToken = null;
2263 _VisualElement* pTokenVisualElement = null;
2265 pToken = static_cast< _Token* >(__pTokenList->GetAt(prevPressedTokenIndex));
2267 bool isParentChanged = false;
2270 pTokenVisualElement = pToken->GetVisualElement();
2271 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
2273 if (pCursorVisualElement->GetParent() == pTokenVisualElement)
2275 isParentChanged = true;
2276 result r = E_SUCCESS;
2277 r = pTokenVisualElement->DetachChild(*pCursorVisualElement);
2278 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2280 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2281 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2285 String inputTokenString = GetText();
2286 String replacementString = inputTokenString;
2287 bool enable = false;
2289 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
2292 inputTokenString = replacementString;
2295 __pressedTokenIndex = tokenIndex;
2297 r = RemoveTokenAt(prevPressedTokenIndex);
2298 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2300 if (inputTokenString.GetLength() > 0)
2302 r = InsertTokenAt(prevPressedTokenIndex, inputTokenString);
2303 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2305 pToken = static_cast< _Token* >(__pTokenList->GetAt(prevPressedTokenIndex));
2308 pToken->currTokenLength = inputTokenString.GetLength();
2313 //Flex height adjusted since token can move to another line
2314 AdjustFlexibleHeight();
2315 __editingTokenIndex = -1;
2316 __isTokenEditingFinished = true;
2317 __isEditingToken = false;
2318 _EditPresenter::SetTextSize(__editContentFontSize);
2320 SetCursorDisabled(true);
2324 __pressedTokenIndex = tokenIndex;
2325 if (GetText().GetLength() > 0 && __pressedTokenIndex != prevPressedTokenIndex)
2328 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2331 if ((__isEditingToken == true) && (__pressedTokenIndex != -1))
2333 r = AttachCursorToToken();
2334 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2337 if (__isEditingToken == false)
2339 SetCursorDisabled(true);
2345 __isPopupVisible = false;
2346 __isLongPressed = false;
2348 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2349 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
2351 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2352 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
2354 if (__isEditingToken)
2356 _Token* pToken = null;
2357 _VisualElement* pTokenVisualElement = null;
2359 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
2361 bool isParentChanged = false;
2364 pTokenVisualElement = pToken->GetVisualElement();
2365 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
2367 if (pCursorVisualElement->GetParent() == pTokenVisualElement)
2369 isParentChanged = true;
2370 result r = E_SUCCESS;
2371 r = pTokenVisualElement->DetachChild(*pCursorVisualElement);
2372 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2374 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2375 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2379 String inputTokenString = GetText();
2380 String replacementString = inputTokenString;
2381 bool enable = false;
2383 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
2386 inputTokenString = replacementString;
2388 __pressedTokenIndex = tokenIndex;
2390 RemoveTokenAt(__editingTokenIndex);
2392 if (inputTokenString.GetLength() > 0)
2394 InsertTokenAt(__editingTokenIndex, inputTokenString);
2396 if (isParentChanged)
2398 pToken->currTokenLength = inputTokenString.GetLength();
2402 __isEditingToken = false;
2403 __editingTokenIndex = -1;
2404 _EditPresenter::SetTextSize(__editContentFontSize);
2405 __isTokenEditingFinished = false;
2409 //Flex height adjusted since token can move to another line
2410 AdjustFlexibleHeight();
2412 SysTryReturnResult(NID_UI_CTRL, (inputTokenString.GetLength() > 0), E_INVALID_ARG, "Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
2418 __pressedTokenIndex = tokenIndex;
2419 if (pCursorVisualElement->GetParent() != pEditVisualElement)
2421 r = (pCursorVisualElement->GetParent())->DetachChild(*pCursorVisualElement);
2422 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2424 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2425 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2429 SetCursorDisabled(false);
2432 for (int i = 0; i < __pTokenList->GetCount(); i++)
2434 TrimTokenAndAdjustEllipsisAt(i);
2435 InitializeTokenVisibilityAt(i);
2442 _TokenEditPresenter::CheckTokenScrolling(bool scrollToCursorPosition)
2444 bool needToScroll = false;
2445 float tokenTopMargin = 0.0f;
2446 float tokenBottomMargin = 0.0f;
2447 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2449 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
2450 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
2452 int tokenCount = GetTokenCount();
2453 if (tokenCount == 0) // There is no token to scroll
2455 __isNeedToScroll = false;
2456 __maxScrollValue = 0.0f;
2457 __isTokenScrolling = false;
2462 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(tokenCount - 1));
2463 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
2465 float newScrollValue = 0.0f;
2467 if (scrollToCursorPosition)
2469 FloatRectangle cursorBounds;
2470 GetCursorBounds(false, cursorBounds);
2471 newScrollValue = cursorBounds.y + cursorBounds.height - __scrollValue + tokenBottomMargin - __pTokenEdit->GetBoundsF().height;
2472 __isScrollValueModified = true;
2476 newScrollValue = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin - __pTokenEdit->GetBoundsF().height;
2477 __isScrollValueModified = true;
2480 needToScroll = (newScrollValue > 0.0f) ? (true) : (false);
2482 __isNeedToScroll = needToScroll;
2484 if (__isNeedToScroll)
2486 __maxScrollValue = newScrollValue;
2487 __isTokenScrolling = true;
2489 RecalculateTokenBounds(__maxScrollValue);
2493 if (!_FloatCompare(__scrollValue, 0.0f))
2495 __scrollValue = 0.0f;
2496 __maxScrollValue = 0.0f; // To prevent unnecessary token scrolling.
2497 RecalculateTokenBounds(__scrollValue);
2498 __isTokenScrolling = false;
2506 _TokenEditPresenter::SetTokenVisualElementBounds(int index, const FloatRectangle& bounds)
2508 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
2509 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null.");
2511 return pToken->SetBounds(pToken->displayRect);
2515 _TokenEditPresenter::AdjustFlexibleHeight(void)
2517 result r = E_SUCCESS;
2519 FloatRectangle editRect = __pTokenEdit->GetBoundsF();
2520 FloatRectangle displayScrollBounds = GetDisplayScrollBoundsF();
2521 float calcHeight = CalculateFlexibleHeightF();
2523 if (!_FloatCompare(editRect.height, calcHeight))
2525 displayScrollBounds.height = calcHeight;
2526 SetScrollBarBounds(displayScrollBounds);
2528 editRect.height = calcHeight;
2529 if (!__isEditingToken)
2531 FloatRectangle editRectBounds = CoordinateSystem::AlignToDevice(editRect);
2532 r = SetFlexBounds(editRectBounds);
2540 _TokenEditPresenter::CalculateFlexibleHeightF(void)
2542 float tokenHeight = 0.0f;
2543 float tokenVerticalSpacing = 0.0f;
2544 float tokenTopMargin = 0.0f;
2545 float tokenBottomMargin = 0.0f;
2546 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2548 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
2549 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
2550 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
2551 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
2553 float height = 0.0f;
2554 int maxLinecount = GetMaxLineCount();
2555 float expectedEditHeight = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin;
2556 float initialHeight = GetInitialBoundsF().height;
2557 float maximumLineHeight = tokenTopMargin + maxLinecount * tokenHeight + tokenVerticalSpacing * (maxLinecount - 1) + tokenBottomMargin;
2559 if (initialHeight < expectedEditHeight)
2561 if (expectedEditHeight > maximumLineHeight)
2563 height = maximumLineHeight;
2567 height = expectedEditHeight;
2572 height = initialHeight;
2575 FloatDimension flexHeightDim = CoordinateSystem::AlignToDevice(FloatDimension(0, height));
2576 return flexHeightDim.height;
2580 _TokenEditPresenter::DrawScrollBar(void)
2582 result r = E_SUCCESS;
2584 _Scroll* pScroll = GetScrollBar();
2585 if (pScroll == null)
2590 if (IsFocused() == false)
2592 if (__isTouchMoveInProgress == false)
2594 pScroll->SetScrollVisibility(false);
2599 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(GetTokenCount() - 1));
2605 float tokenBottomMargin = 0.0f;
2606 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, tokenBottomMargin);
2608 float totalHeight = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin;
2609 float dspHeight = __pTokenEdit->GetBoundsF().height;
2610 float firstDspY = -__scrollValue;
2612 if (totalHeight <= dspHeight)
2614 pScroll->SetScrollVisibility(false);
2615 pScroll->SetScrollRange(1, 1);
2616 pScroll->SetScrollPosition(0.0f);
2618 SetScrollBarVisible(false);
2619 SetPreviousScrollBarPosition(0.0f);
2620 SetMaximumPreviousScrollBarPosition(0.0f);
2624 if (firstDspY > 0.0f)
2626 pScroll->SetScrollRange(dspHeight, totalHeight);
2627 pScroll->SetScrollPosition(firstDspY);
2628 SetMaximumPreviousScrollBarPosition(totalHeight - dspHeight);
2632 pScroll->SetScrollRange(dspHeight, totalHeight);
2633 pScroll->SetScrollPosition(0.0f);
2634 SetMaximumPreviousScrollBarPosition(0.0f);
2637 if (pScroll->GetScrollVisibility())
2639 SetScrollBarVisible(true);
2642 SetPreviousScrollBarPosition(firstDspY);
2649 _TokenEditPresenter::SetAutoShrinkModeEnabled(bool enable)
2651 __autoShrink = enable;
2655 _TokenEditPresenter::IsAutoShrinkModeEnabled(void) const
2657 return __autoShrink;
2661 _TokenEditPresenter::SetDescriptionText(String descriptionText)
2663 __descriptionText = descriptionText;
2667 _TokenEditPresenter::GetDescriptionText(void) const
2669 return __descriptionText;
2673 _TokenEditPresenter::CalculateVisibleTokenCount(void)
2675 int visibleTokenCount = 0;
2677 FloatRectangle intialBounds = GetInitialBoundsF();
2678 FloatRectangle tempInitialBounds = intialBounds;
2679 FloatRectangle hiddenTokenDisplayBounds;
2680 int tokenCount = GetTokenCount();
2682 for (int i = 0; i < tokenCount; i++)
2684 tempInitialBounds = intialBounds;
2685 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2686 SysTryReturn(NID_UI_CTRL, pToken != null, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
2688 FloatRectangle displayBounds = pToken->displayRect;
2689 if ((tempInitialBounds.y + displayBounds.y) > (tempInitialBounds.y + tempInitialBounds.height))
2693 visibleTokenCount++;
2695 return visibleTokenCount;
2699 _TokenEditPresenter::OnFocusGained(void)
2701 __isTitleSliding = false;
2704 float tempHeight = CalculateFlexibleHeightF();
2705 FloatRectangle tempRect = GetInitialBoundsF();
2706 tempRect.height = tempHeight;
2708 _Token* pToken = null;
2709 int tokenCount = GetTokenCount();
2711 for (int i = 0; i < tokenCount; i++)
2713 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2717 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
2718 if (pTokenVisualElement)
2720 pTokenVisualElement->SetShowState(true);
2725 SetFlexBounds(tempRect);
2727 SetEditingTokenTextBounds(__editingTokenIndex, false);
2731 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2735 if (__isScrollValueChanged && !__isScrollValueModified)
2737 __maxScrollValue = __maxScrollValue - (__pTokenEdit->GetBoundsF().height - GetInitialBoundsF().height);
2738 __isScrollValueChanged = false;
2742 if (GetTokenCount())
2744 CheckTokenScrolling();
2747 TextObject* pTextObject = GetTextObject();
2750 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
2751 pTextObject->Compose();
2754 if (__pressedTokenIndex < 0)
2757 SetCursorDisabled(false);
2761 RefreshAccessibilityElements();
2763 return _EditPresenter::OnFocusGained();
2767 _TokenEditPresenter::OnFocusLost(void)
2769 result r = E_SUCCESS;
2772 //Remove pressed state on focus lost
2773 __pressedTokenIndex = -1;
2775 _EditPresenter::StopTitleSlidingTimer();
2776 __isTitleSliding = false;
2778 if (__editingTokenIndex >= 0)
2780 _Token* pToken = null;
2781 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
2784 if (GetText().GetLength() > 0)
2786 OnTextCommitted(L"\n");
2790 RemoveTokenAt(__editingTokenIndex, true);
2796 if (GetText().GetLength() > 0)
2798 OnTextCommitted(L"\n");
2804 _Scroll* pScroll = GetScrollBar();
2807 pScroll->SetScrollVisibility(false);
2809 __scrollValue = 0.0f;
2811 int tokenCount = GetTokenCount();
2812 _Token* pToken = null;
2813 for (int i = 0; i < tokenCount; i++)
2815 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2818 pToken->SetBounds(pToken->displayRect);
2822 r = SetInitialBounds();
2823 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating", GetErrorMessage(r));
2825 UpdateTokenAccessibilityBounds();
2827 __scrollValue = 0.0f;
2828 r = CalculateTokenPositionFromIndex(0);
2829 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
2831 int visibleTokenCount = CalculateVisibleTokenCount();
2833 for (int i = visibleTokenCount; i < tokenCount; i++)
2835 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2838 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
2839 if (pTokenVisualElement)
2841 pTokenVisualElement->SetShowState(false);
2846 float totalScrollValue = __maxScrollValue + (__pTokenEdit->GetBoundsF().height - GetInitialBoundsF().height);
2848 if (totalScrollValue > 0)
2850 __isNeedToScroll = true;
2851 __maxScrollValue = totalScrollValue;
2852 __isTokenScrolling = true;
2853 if (__lineAdded > 0)
2855 __isScrollValueChanged = true;
2856 __isScrollValueModified = false;
2860 FloatRectangle intialWindowBounds = GetInitialBoundsF();
2861 SetFlexBounds(intialWindowBounds);
2863 SetEditingTokenTextBounds(__editingTokenIndex, false);
2865 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2868 TextObject* pTextObject = GetTextObject();
2871 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
2872 pTextObject->Compose();
2875 RemoveChildAccessibilityElements();
2876 __pTokenEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
2877 SetDrawFocusState(false);
2879 return _EditPresenter::OnFocusLost();
2883 _TokenEditPresenter::SetFlexBounds(const FloatRectangle& bounds)
2885 if (__pTokenEdit->GetBoundsF().height > bounds.height)
2887 if (__lineAdded > 0)
2892 return _EditPresenter::SetFlexBounds(bounds);
2896 _TokenEditPresenter::SetTextSize(const int size)
2898 result r = E_SUCCESS;
2899 __editContentFontSize = size;
2901 if (!__isEditingToken)
2903 r = _EditPresenter::SetTextSize(size);
2904 r = SetInitialBounds();
2905 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2912 _TokenEditPresenter::SetTextSize(const float size)
2914 result r = E_SUCCESS;
2915 __editContentFontSize = size;
2917 if (!__isEditingToken)
2919 r = _EditPresenter::SetTextSize(size);
2920 r = SetInitialBounds();
2921 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2928 _TokenEditPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
2930 //Remove token focus on touch press
2931 __focusedTokenIndex = -1;
2933 int tokenIndex = GetTokenIndexFromCoordinate(_CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()));
2934 __trackTokenIndex = tokenIndex;
2936 _TouchInfo TouchInfo(touchinfo);
2937 if (tokenIndex != -1)
2939 if (tokenIndex == __editingTokenIndex)
2941 __touchPressInfo.x = touchinfo.GetCurrentPosition().x;
2942 __touchPressInfo.y = touchinfo.GetCurrentPosition().y;
2944 _Token* pToken = null;
2945 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
2948 float tokenX = pToken->displayRect.x;
2949 float tokenY = pToken->displayRect.y;
2950 FloatPoint point(__touchPressInfo.x - tokenX, __touchPressInfo.y - tokenY);
2951 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
2956 return _EditPresenter::OnTouchPressed(source, TouchInfo);
2960 _TokenEditPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
2962 __touchPressInfo = FloatPoint(-1.0f, -1.0f);
2964 ProcessTokeningByTouchEvent(source, touchinfo);
2965 if (GetTokenCount())
2967 //Set token bounds appropriately On Fast flick of scroll bar
2968 if (!(__isEditingToken || __editingTokenIndex >= 0))
2970 SetTokenBoundsByTouchInfo(touchinfo);
2974 _Scroll* pScroll = GetScrollBar();
2977 pScroll->SetScrollVisibility(false);
2980 if (__prevScrollValue)
2982 __prevScrollValue = 0.0f;
2983 __isTokenScrolling = false;
2986 _TouchInfo TouchInfo(touchinfo);
2987 _Token* pToken = null;
2988 if (__editingTokenIndex >= 0)
2990 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
2993 int tokenX = _CoordinateSystemUtils::ConvertToInteger(pToken->displayRect.x);
2994 int tokenY = _CoordinateSystemUtils::ConvertToInteger(pToken->displayRect.y);
2995 Point point(_CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()).x - tokenX, _CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()).y - tokenY);
2996 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
2998 _EditPresenter::OnTouchReleased(source, TouchInfo);
2999 __previousCursorPosition = GetCursorPosition();
3003 _EditPresenter::OnTouchReleased(source, touchinfo);
3006 __isTouchMoveInProgress = false;
3007 __trackTokenIndex = -1;
3013 _TokenEditPresenter::OnInputConnectionTextCommitted(InputConnection& source, const String& committedText)
3015 OnTextCommitted(committedText);
3019 _TokenEditPresenter::OnTextCommitted(const String& commitText)
3021 char enterText[2] = {'\n', };
3022 String enterTextComma(",");
3023 String enterTextSemiColon(";");
3025 //OnTextCommitted blocked for these cases
3026 //1. Tab text not to be handled
3027 //2. Token is focused
3028 char tapText[2] = {'\t', };
3029 if (commitText == tapText)
3034 if ((commitText == enterText) || (commitText == enterTextComma) || (commitText == enterTextSemiColon))
3036 CoreKeypadAction keypadaction = GetKeypadAction();
3037 __pTokenEdit->SendKeypadEvent(keypadaction, CORE_KEYPAD_EVENT_STATUS_ENTERACTION);
3039 if (__editingTokenIndex != -1)
3041 ExitTokenEditingMode();
3044 if (GetText().GetLength() > 0)
3049 for (int i = 0; i < __pTokenList->GetCount(); i++)
3051 TrimTokenAndAdjustEllipsisAt(i);
3052 InitializeTokenVisibilityAt(i);
3055 if (__pressedTokenIndex < 0 && __focusedTokenIndex < 0)
3057 SetCursorDisabled(true);
3058 __pTokenEdit->Draw();
3059 SetCursorDisabled(false);
3066 _EditPresenter::OnTextCommitted(commitText);
3067 __previousCursorPosition = GetCursorPosition();
3069 _Token* pToken = null;
3070 if (__editingTokenIndex >= 0)
3072 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3073 SysTryReturnVoidResult(NID_UI_CTRL, pToken, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
3075 pToken->ResetToken(GetText());
3076 TrimTokenAndAdjustEllipsisAt(__editingTokenIndex);
3078 float tokenHeight = 0.0f;
3079 float tokenVerticalSpacing = 0.0f;
3080 float tokenTextLeftMargin = 0.0f;
3082 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3083 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
3084 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
3085 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
3087 FloatRectangle tempTextDspRect;
3088 tempTextDspRect.x += tokenTextLeftMargin;
3089 tempTextDspRect.y += tokenVerticalSpacing / 2.0f;
3090 tempTextDspRect.width = pToken->displayRect.width - (tokenTextLeftMargin * 2.0f);
3091 tempTextDspRect.height = tokenHeight - tokenVerticalSpacing;
3093 SetTextBounds(tempTextDspRect);
3095 if (GetCursorPosition() > pToken->currTokenLength)
3097 _EditPresenter::SetCursorPosition(pToken->currTokenLength);
3101 _EditPresenter::SetCursorPosition(GetCursorPosition());
3106 if (__isEditingToken == false)
3108 __pressedTokenIndex = -1;
3109 __focusedTokenIndex = -1;
3110 SetCursorDisabled(false);
3113 float tokenTopMargin = 0.0f;
3114 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3115 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
3117 FloatRectangle textBounds = GetTextBoundsF();
3118 textBounds.height = GetMaxTextHeight();
3119 SetTextBounds(textBounds);
3122 if (__editingTokenIndex < 0)
3124 CheckTokenScrolling();
3126 __pTokenEdit->Invalidate();
3132 _TokenEditPresenter::DeleteSurroundingText(InputConnection& source, int offset, int charCount)
3134 OnSurroundingTextDeleted(offset, charCount);
3138 _TokenEditPresenter::OnSurroundingTextDeleted(int offset, int charCount)
3140 __lastTokenIndex = GetTokenCount() - 1;
3141 int cursorPosition = 0;
3145 if ((offset == -1) && (charCount == 1))
3147 if (GetTextLength() == 0 && GetTokenCount()) // There is no candidate token.
3149 if (__isEditingToken == true)
3151 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3152 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3154 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3155 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3157 _Token* pToken = null;
3158 _VisualElement* pTokenVisualElement = null;
3160 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3164 pTokenVisualElement = pToken->GetVisualElement();
3165 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3167 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3169 result r = E_SUCCESS;
3170 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3171 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3173 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3174 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3178 RemoveTokenAt(__editingTokenIndex);
3180 CalculateTokenPositionFromIndex(__editingTokenIndex);
3181 for (int i = __editingTokenIndex; i < __lastTokenIndex + 1; i++)
3183 _Token* pToken = null;
3184 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
3187 pToken->SetBounds(pToken->displayRect);
3191 __pressedTokenIndex = -1;
3192 __editingTokenIndex = -1;
3193 __isEditingToken = false;
3194 _EditPresenter::SetTextSize(__editContentFontSize);
3195 __isTokenEditingFinished = false;
3197 AdjustFlexibleHeight();
3198 CheckTokenScrolling();
3200 else if (__pressedTokenIndex != -1)
3202 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3203 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3205 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3206 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3208 _Token* pToken = null;
3209 _VisualElement* pTokenVisualElement = null;
3211 pToken = static_cast< _Token* >(__pTokenList->GetAt(__pressedTokenIndex));
3215 pTokenVisualElement = pToken->GetVisualElement();
3216 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3218 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3220 result r = E_SUCCESS;
3221 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3222 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3224 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3225 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3229 RemoveTokenAt(__pressedTokenIndex);
3231 CalculateTokenPositionFromIndex(__pressedTokenIndex);
3232 for (int i = __pressedTokenIndex; i < __lastTokenIndex + 1; i++)
3234 _Token* pToken = null;
3235 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
3239 pToken->SetBounds(pToken->displayRect);
3244 else if (__focusedTokenIndex != -1)
3246 RemoveTokenAt(__focusedTokenIndex);
3250 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3251 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3253 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3254 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3256 _Token* pToken = null;
3257 _VisualElement* pTokenVisualElement = null;
3258 if (__animatingIndex == (GetTokenCount() - 1))
3260 pToken = static_cast< _Token* >(__pTokenList->GetAt(GetTokenCount() - 1));
3263 pTokenVisualElement = pToken->GetVisualElement();
3264 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3265 pTokenVisualElement->RemoveAnimation(L"TokenAnimation");
3268 pToken = static_cast< _Token* >(__pTokenList->GetAt(GetTokenCount() - 1));
3271 pTokenVisualElement = pToken->GetVisualElement();
3272 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3274 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3276 result r = E_SUCCESS;
3277 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3278 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3280 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3281 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3285 __animatingIndex = GetTokenCount() - 1;
3287 if (pTokenVisualElement && __animatingIndex >= 0)
3289 __isAnimationInProgress = true;
3290 VisualElementAnimation* pAnimation = CreateAnimationN(*pTokenVisualElement, false);
3291 pTokenVisualElement->AddAnimation(L"TokenAnimation", *pAnimation);
3296 __pTokenEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
3299 __pTokenEdit->Invalidate();
3304 if (__pressedTokenIndex >= 0 && __editingTokenIndex < 0 && !__isEditingToken)
3306 RemoveTokenAt(__pressedTokenIndex);
3307 __pTokenEdit->Invalidate();
3310 else if (__focusedTokenIndex >= 0 && __editingTokenIndex < 0 && !__isEditingToken)
3312 RemoveTokenAt(__focusedTokenIndex);
3313 __pTokenEdit->Invalidate();
3317 //Backspace on Blocked text, delete full block
3318 if (IsBlocked() == true)
3320 GetBlockRange(start, end);
3324 cursorPosition = GetCursorPosition();
3325 start = cursorPosition + offset;
3330 end = start + charCount;
3331 if (end > GetTextLength())
3337 DeleteText(start, end);
3338 __previousCursorPosition = start;
3340 if (IsCopyPasteManagerExist())
3342 InitializeCopyPasteManager();
3344 if (IsBlocked() == true)
3348 if (__isEditingToken != true)
3353 __pTokenEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
3356 cursorPosition = GetCursorPosition();
3357 start = cursorPosition + offset;
3362 end = start + charCount;
3363 if (end > GetTextLength())
3368 Rectangle currBounds = __pTokenEdit->GetBounds();
3369 DeleteText(start, end);
3370 __previousCursorPosition = start;
3371 if (__isEditingToken != true)
3377 _Token* pToken = null;
3379 if (__editingTokenIndex >= 0 && __isEditingToken)
3381 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3385 float tokenHeight = 0.0f;
3386 float tokenVerticalSpacing = 0.0f;
3387 float tokenTextLeftMargin = 0.0f;
3389 SetCursorPosition(__previousCursorPosition);
3391 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3392 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
3393 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
3394 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
3396 FloatRectangle tempTextDspRect;
3397 tempTextDspRect.x += tokenTextLeftMargin;
3398 tempTextDspRect.y += tokenVerticalSpacing / 2.0f;
3399 tempTextDspRect.width = pToken->displayRect.width - (tokenTextLeftMargin * 2.0f);
3400 tempTextDspRect.height = tokenHeight - tokenVerticalSpacing;
3402 SetTextBounds(tempTextDspRect);
3403 _EditPresenter::SetCursorPosition(start);
3405 pToken->ResetToken(GetText());
3406 TrimTokenAndAdjustEllipsisAt(__editingTokenIndex);
3410 __pTokenEdit->Draw();
3414 _TokenEditPresenter::OnTapGestureDetected(void)
3416 if (__editingTokenIndex >= 0)
3418 __isPopupVisible = true;
3421 //Uncomment below to Block Copy & Paste functionality in Token Edit mode
3422 if (__pressedTokenIndex != -1)
3426 return _EditPresenter::OnTapGestureDetected();
3430 _TokenEditPresenter::CheckCopyPastePopupShowStatus(void)
3432 if (__editingTokenIndex < 0)
3434 float controlHeight = __pTokenEdit->GetBoundsF().height;
3435 FloatRectangle cursorBounds;
3436 GetCursorBounds(false, cursorBounds);
3437 if (cursorBounds.y > controlHeight)
3447 _TokenEditPresenter::OnLongPressGestureDetected(void)
3449 if (CheckCopyPastePopupShowStatus())
3451 //TextBounds bigger than control height. Dont show Copy paste popup
3455 //Discard all long press that is detected after Touch press on a token
3456 if (__trackTokenIndex >= 0)
3461 __isLongPressed = true;
3463 //Uncomment below to Block Copy & Paste functionality in Token Edit mode
3464 if (__pressedTokenIndex != -1)
3468 return _EditPresenter::OnLongPressGestureDetected();
3472 _TokenEditPresenter::OnCursorTimerExpired(void)
3474 if (__editingTokenIndex != -1)
3482 FloatRectangle cursorRect;
3484 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3485 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
3487 //Set Editing token bounds for text scroll and cursor position calculation (SetTextBounds should have been done prior to this)
3488 FloatRectangle cursorDspRect = _EditPresenter::GetTextBoundsF();
3490 if (CalculateCursorBounds(cursorDspRect, cursorRect) != E_SUCCESS)
3496 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3497 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3499 Canvas* pCursorCanvas = pCursorVisualElement->GetCanvasN();
3500 SysTryReturnVoidResult(NID_UI_CTRL, pCursorCanvas != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get canvas of cursor visual element.");
3502 bool cursorEnable = IsCursorEnabled();
3504 pCursorVisualElement->SetBounds(cursorRect);
3505 DrawCursor(*pCursorCanvas, cursorRect, cursorEnable);
3509 cursorEnable = false;
3513 cursorEnable = true;
3515 SetCursorEnabled(cursorEnable);
3517 pCursorCanvas->Show();
3518 delete pCursorCanvas;
3524 _EditPresenter::OnCursorTimerExpired();
3529 _TokenEditPresenter::IsTextBlockedInTokenEdit(void) const
3531 if ((IsBlocked() == true) && (__isEditingToken) && (__editingTokenIndex >= 0))
3539 _TokenEditPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
3541 __isTouchMoveInProgress = true;
3543 if (GetTokenCount())
3545 //Scrolling is blocked when a popup is visible or when a text is blocked
3546 if (IsBlocked() == true || __isLongPressed == true)
3551 //Allow touch move only in horizontal direction when editing token
3552 _TouchInfo TouchInfo(touchinfo);
3553 _Token* pToken = null;
3554 if (__editingTokenIndex >= 0)
3556 if (__touchPressInfo.y > 0.0f)
3558 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3561 float tokenX = pToken->displayRect.x;
3562 float tokenY = pToken->displayRect.y;
3563 FloatPoint point(touchinfo.GetCurrentPosition().x - tokenX, __touchPressInfo.y - tokenY);
3564 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
3567 bool retValue = _EditPresenter::OnTouchMoved(source, TouchInfo);
3568 __previousCursorPosition = GetCursorPosition();
3578 SetTokenBoundsByTouchInfo(touchinfo);
3580 if (!(__pTokenEdit->GetEditStyle() & EDIT_STYLE_NOSCROLL))
3582 _Scroll* pScroll = GetScrollBar();
3585 float tokenBottomMargin = 0.0f;
3586 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, tokenBottomMargin);
3588 float totalHeight = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin;
3589 float controlHeight = __pTokenEdit->GetBoundsF().height;
3591 if (totalHeight > controlHeight)
3593 pScroll->SetScrollVisibility(true);
3597 pScroll->SetScrollVisibility(false);
3602 return _EditPresenter::OnTouchMoved(source, touchinfo);
3606 return _EditPresenter::OnTouchMoved(source, touchinfo);
3612 _TokenEditPresenter::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
3614 __isAnimationInProgress = false;
3615 RemoveTokenAt(GetTokenCount() - 1);
3616 CalculateTokenPositionFromIndex(GetTokenCount() - 1);
3618 for (int i = GetTokenCount() - 1; i < GetTokenCount() - 1 + 1; i++)
3620 _Token* pToken = null;
3621 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
3625 pToken->SetBounds(pToken->displayRect);
3629 if (__lastTokenIndex == __pressedTokenIndex)
3631 __pressedTokenIndex--;
3634 if (GetTokenCount() == 0 && __animatingIndex == 0)
3638 __animatingIndex = -1;
3643 __pTokenEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
3649 _TokenEditPresenter::OnTimerExpired(Timer& timer)
3651 Timer* onTimer = &timer;
3652 Canvas* pDescriptionTextCanvas = null;
3654 if (onTimer == _EditPresenter::__pTitleSlidingTimer)
3658 _EditPresenter::StopTitleSlidingTimer();
3659 __isTitleSliding = false;
3663 FloatRectangle tempDescriptionTextRect = __descriptionTextRect;
3664 tempDescriptionTextRect.x = 0.0f;
3665 tempDescriptionTextRect.y = 0.0f;
3667 pDescriptionTextCanvas = __pDescriptionTextVisualElement->GetCanvasN();
3668 SysTryReturnVoidResult(NID_UI_CTRL, pDescriptionTextCanvas, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pDescriptionTextCanvas is invalid!");
3670 pDescriptionTextCanvas->SetBackgroundColor(Color(0));
3671 pDescriptionTextCanvas->Clear();
3672 __pDescriptionTextTextObject->SetBounds(tempDescriptionTextRect);
3673 __pDescriptionTextTextObject->DrawWithOffset(*_CanvasImpl::GetInstance(*pDescriptionTextCanvas));
3674 Rectangle descriptionTextRect = _CoordinateSystemUtils::ConvertToInteger(tempDescriptionTextRect);
3675 pDescriptionTextCanvas->Show(descriptionTextRect);
3677 delete pDescriptionTextCanvas;
3679 _EditPresenter::StartTitleSlidingTimer();
3680 __isTitleSliding = true;
3684 _EditPresenter::OnTimerExpired(timer);
3689 _TokenEditPresenter::ChangeInternalLayout(_ControlOrientation orientation)
3691 result r = E_SUCCESS;
3693 __scrollValue = 0.0f;
3694 __maxScrollValue = 0.0f;
3695 float tokenBottomMargin = 0.0f;
3696 float newScrollValue = 0.0f;
3698 FloatRectangle windowBounds = GetInitialBoundsF();
3700 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
3702 r = CalculateTokenPositionFromIndex(0);
3703 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3705 r = SetInitialBounds();
3706 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3708 if (__isEditingToken)
3710 if (__editingTokenIndex >= 0 && __editingTokenIndex < GetTokenCount())
3712 String inputTokenString = GetText();
3713 String replacementString = inputTokenString;
3714 bool enable = false;
3716 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
3719 inputTokenString = replacementString;
3722 if (inputTokenString.GetLength() > 0)
3724 int index = __editingTokenIndex;
3725 RemoveTokenAt(__editingTokenIndex, true);
3726 InsertTokenAt(index, inputTokenString);
3731 if (__pTokenEdit->IsAttachedToMainTree() && IsFocused())
3733 r = AdjustFlexibleHeight();
3734 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3736 r = CheckTokenScrolling();
3737 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3743 r = AdjustFlexibleHeight();
3744 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3746 windowBounds = __pTokenEdit->GetBoundsF();
3749 newScrollValue = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin - windowBounds.height;
3750 if (newScrollValue > 0.0f)
3752 __maxScrollValue = newScrollValue;
3753 __isNeedToScroll = true;
3761 _TokenEditPresenter::ChangeLayout(_ControlOrientation orientation)
3763 result r = E_SUCCESS;
3765 r = _EditPresenter::ChangeLayout(orientation);
3766 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3768 r = ChangeInternalLayout(orientation);
3774 _TokenEditPresenter::OnBoundsChanged(void)
3776 if (!__isTokenEditPresenterInitialized)
3781 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3782 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
3784 if (IsUpdateInitialBounds())
3786 SetControlInitialBounds(tokenEditBounds);
3788 ChangeInternalLayout(orientation);
3794 _TokenEditPresenter::AttachCursorToToken(void)
3796 result r = E_SUCCESS;
3798 if (__pressedTokenIndex != -1)
3800 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3801 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
3803 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3804 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
3806 _Token* pToken = null;
3807 _VisualElement* pTokenVisualElement = null;
3809 pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
3812 pTokenVisualElement = pToken->GetVisualElement();
3813 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
3815 if (pCursorVisualElement->GetParent() != pTokenVisualElement)
3817 r = (pCursorVisualElement->GetParent())->DetachChild(*pCursorVisualElement);
3818 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3820 r = pTokenVisualElement->AttachChild(*pCursorVisualElement);
3821 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3830 _TokenEditPresenter::DetachCursorFromToken(void)
3832 result r = E_SUCCESS;
3834 if (__pressedTokenIndex != -1)
3836 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3837 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3839 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3840 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3842 _Token* pToken = null;
3843 _VisualElement* pTokenVisualElement = null;
3845 pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
3849 pTokenVisualElement = pToken->GetVisualElement();
3850 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3852 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3854 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3855 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
3857 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3858 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
3866 _TokenEditPresenter::ExitTokenEditingMode(void)
3868 result r = E_SUCCESS;
3870 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3871 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3873 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3874 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3876 _Token* pToken = null;
3877 _VisualElement* pTokenVisualElement = null;
3879 pToken = static_cast <_Token*>(__pTokenList->GetAt(__editingTokenIndex));
3883 pTokenVisualElement = pToken->GetVisualElement();
3884 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3886 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3888 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3889 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
3891 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3892 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
3896 String inputTokenString = GetText();
3897 String replacementString = inputTokenString;
3898 bool enable = false;
3900 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
3903 inputTokenString = replacementString;
3906 r = RemoveTokenAt(__editingTokenIndex);
3908 _EditPresenter::SetTextSize(__editContentFontSize);
3909 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3911 if (inputTokenString.GetLength() > 0)
3913 r = InsertTokenAt(__editingTokenIndex, inputTokenString);
3914 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3916 pToken = static_cast <_Token*>(__pTokenList->GetAt(__editingTokenIndex));
3917 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3919 pToken->currTokenLength = inputTokenString.GetLength();
3922 CalculateTokenPositionFromIndex(0);
3923 int lastTokenIndex = GetTokenCount() - 1;
3924 for (int i = 0; i < lastTokenIndex + 1; i++)
3926 _Token* pToken = null;
3927 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3931 pToken->SetBounds(pToken->displayRect);
3935 AdjustFlexibleHeight();
3936 __pressedTokenIndex = -1;
3937 __isTokenEditingFinished = true;
3938 __editingTokenIndex = -1;
3939 __isEditingToken = false;
3941 CheckTokenScrolling();
3942 SetCursorDisabled(false);
3944 if (inputTokenString.GetLength() <= 0)
3946 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
3953 _TokenEditPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
3955 _KeyCode keyCode = keyInfo.GetKeyCode();
3956 bool focusChanged = false;
3957 int tokenCount = GetTokenCount();
3958 int lastTokenIndex = tokenCount - 1;
3960 if (IsUsbKeyboardConnected() && (keyInfo.GetKeyModifier() & _KEY_MODIFIER_CTRL))
3968 if (__isEditingToken)
3979 if ((keyCode == _KEY_NUM_LEFT) || (keyCode == _KEY_LEFT))
3981 if (__drawFocusState && (!__isEditingToken) && (tokenCount > 0))
3983 if (__focusedTokenIndex == -1)
3985 if (GetCursorPosition() == 0)
3987 __focusedTokenIndex = lastTokenIndex;
3988 if (GetTextLength() > 0)
3992 SetCursorDisabled(true);
3993 __pTokenEdit->Invalidate();
3997 return _EditPresenter::OnKeyPressed(source, keyInfo);
3999 focusChanged = true;
4004 if (__focusedTokenIndex > 0)
4006 __focusedTokenIndex--;
4007 focusChanged = true;
4013 if ((keyCode == _KEY_NUM_RIGHT) || (keyCode == _KEY_RIGHT))
4015 if (__drawFocusState && (!__isEditingToken) && (tokenCount > 0))
4017 if (__focusedTokenIndex != -1)
4019 if (__focusedTokenIndex == lastTokenIndex)
4021 __focusedTokenIndex = -1;
4022 focusChanged = true;
4026 __focusedTokenIndex++;
4027 focusChanged = true;
4037 if (__focusedTokenIndex != -1)
4039 SetCursorDisabled(true);
4040 ScrollToFocusedToken();
4044 SetCursorDisabled(false);
4045 CheckTokenScrolling();
4051 return _EditPresenter::OnKeyPressed(source, keyInfo);
4055 _TokenEditPresenter::GetTextAccessibilityElementText(void) const
4058 String spaceText = " ";
4059 _Token* pToken = null;
4060 int tokenCount = GetTokenCount();
4061 static const int readTokenCount = 2;
4064 for (int index = 0; index < readTokenCount; index++)
4066 pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
4067 SysTryReturn(NID_UI_CTRL, pToken, tokenText, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4069 if (index < (readTokenCount - 1))
4071 tokenText += pToken->GetText() + spaceText;
4075 String moreTokenText;
4076 int moreTokenCount = tokenCount - readTokenCount;
4077 if (moreTokenCount > 0)
4079 moreTokenText.Format(15, L"and %d more", moreTokenCount);
4081 tokenText += pToken->GetText() + spaceText + moreTokenText;
4089 _TokenEditPresenter::RefreshAccessibilityElements(void)
4091 RemoveChildAccessibilityElements();
4092 AddChildAccessibilityElements();
4098 _TokenEditPresenter::AddChildAccessibilityElements(void)
4100 //Accessibility Elements added to the container upon focus gained
4103 //3. __accessibilityElements 0 - title 1 - token 0
4105 result r = E_SUCCESS;
4106 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4108 __pTokenEdit->AddTitleAccessibilityElement();
4109 int tokenCount = GetTokenCount();
4111 for (int index = 0; index < tokenCount; index++)
4113 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
4114 SysTryReturn(NID_UI_CTRL, pToken != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4118 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
4119 SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4121 String labelText = pToken->GetText();
4122 pAccessibilityElement->SetBounds(pToken->displayRect);
4123 pAccessibilityElement->SetLabel(labelText);
4124 pContainer->AddElement(*pAccessibilityElement);
4125 __accessibilityElements.Add(pAccessibilityElement);
4129 __pTokenEdit->AddCursorAccessibilityElement();
4135 _TokenEditPresenter::RemoveChildAccessibilityElements(void)
4137 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4138 _AccessibilityElement* pAccessibilityElement = null;
4140 __pTokenEdit->RemoveTitleAccessibilityElement();
4142 while (__accessibilityElements.GetCount() > 0)
4144 if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS)
4146 __accessibilityElements.RemoveAt(0);
4147 pContainer->RemoveElement(*pAccessibilityElement);
4151 __pTokenEdit->RemoveCursorAccessibilityElement();
4157 _TokenEditPresenter::AppendTokenAccessibilityElement(void)
4159 result r = E_SUCCESS;
4160 int tokenCount = GetTokenCount();
4162 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4164 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(tokenCount - 1));
4165 SysTryReturn(NID_UI_CTRL, pToken != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4169 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
4170 SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4172 String labelText = pToken->GetText();
4173 pAccessibilityElement->SetBounds(pToken->displayRect);
4174 pAccessibilityElement->SetLabel(labelText);
4175 pAccessibilityElement->SetHint(L"double tap to edit");
4176 pContainer->AddElement(*pAccessibilityElement);
4177 __accessibilityElements.Add(pAccessibilityElement);
4184 _TokenEditPresenter::InsertTokenAccessibilityElementAt(int index)
4186 result r = E_SUCCESS;
4188 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4189 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
4190 SysTryReturn(NID_UI_CTRL, pToken != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4194 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
4195 SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4197 String labelText = pToken->GetText();
4198 pAccessibilityElement->SetBounds(pToken->displayRect);
4199 pAccessibilityElement->SetLabel(labelText);
4200 pContainer->AddElement(*pAccessibilityElement);
4201 __accessibilityElements.InsertAt(pAccessibilityElement, index);
4208 _TokenEditPresenter::RemoveTokenAccessibilityElementAt(int index)
4210 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4211 _AccessibilityElement* pAccessibilityElement = null;
4215 if (__accessibilityElements.GetCount() > 0)
4217 if ((__accessibilityElements.GetAt(index, pAccessibilityElement)) == E_SUCCESS)
4219 __accessibilityElements.RemoveAt(index);
4220 pContainer->RemoveElement(*pAccessibilityElement);
4228 _TokenEditPresenter::UpdateTokenAccessibilityBounds(void)
4230 result r = E_SUCCESS;
4231 int tokenCount = GetTokenCount();
4232 _AccessibilityElement* pAccessibilityElement = null;
4234 for (int index = 0; index < tokenCount; index++)
4236 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
4237 SysTryReturn(NID_UI_CTRL, pToken != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4239 if ((__accessibilityElements.GetAt(index, pAccessibilityElement)) == E_SUCCESS)
4241 pAccessibilityElement->SetBounds(pToken->displayRect);
4248 _TokenEditPresenter::UpdateTitleAccessibilityBounds(const FloatRectangle& titleBounds)
4250 _AccessibilityElement* pTitleAccessibilityElement = __pTokenEdit->GetTitleTextAccessibilityElement();
4252 if (!pTitleAccessibilityElement)
4257 pTitleAccessibilityElement->SetBounds(titleBounds);
4263 _TokenEditPresenter::ScrollToFocusedTokenAccessibilityElement(const _AccessibilityElement& element)
4265 result r = E_SUCCESS;
4266 int focusedTokenIndex = -1;
4267 int tokenCount = GetTokenCount();
4268 FloatRectangle focusedTokenRectangle;
4269 float newScrollValue = 0.0f;
4270 float tokenTopMargin = 0.0f;
4271 float tokenBottomMargin = 0.0f;
4272 float tokenHeight = 0.0f;
4273 float textBoundsAlignValue = 0.0f;
4274 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
4275 _AccessibilityElement* pAccessibilityElement = null;
4277 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
4278 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
4279 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
4281 FloatRectangle tokenEditRect = __pTokenEdit->GetBoundsF();
4282 float textObjectMaxHeight = GetMaxTextHeight();
4283 textBoundsAlignValue = (tokenHeight - textObjectMaxHeight) / 2.0f;
4285 pAccessibilityElement = const_cast< _AccessibilityElement* >(&element);
4286 r = __accessibilityElements.IndexOf(pAccessibilityElement, focusedTokenIndex);
4287 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
4289 if ((focusedTokenIndex > -1) && (focusedTokenIndex < tokenCount))
4291 _Token* pToken = null;
4292 pToken = static_cast< _Token* >(__pTokenList->GetAt(focusedTokenIndex));
4294 focusedTokenRectangle = pToken->displayRect;
4296 float focusedTokenPosition = focusedTokenRectangle.y + focusedTokenRectangle.height;
4298 if ((focusedTokenRectangle.y > 0) && (focusedTokenPosition < tokenEditRect.height))
4304 if (focusedTokenRectangle.y < 0)
4306 newScrollValue = focusedTokenRectangle.y - tokenTopMargin - __scrollValue;
4310 newScrollValue = focusedTokenPosition - textBoundsAlignValue - tokenEditRect.height + tokenBottomMargin - __scrollValue;
4313 r = RecalculateTokenBounds(newScrollValue);
4314 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
4317 r = __accessibilityElements.GetAt(focusedTokenIndex, pAccessibilityElement);
4318 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
4320 _AccessibilityManager* pAccessibilityManager = _AccessibilityManager::GetInstance();
4321 pAccessibilityManager->SetGlobalFocusedElement(*pAccessibilityElement);
4322 pAccessibilityManager->RequestToDrawFocusUi();
4329 _TokenEditPresenter::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
4331 result r = E_SUCCESS;
4332 if (__focusOutIndex < 0) // Not a token accessibility element
4337 _Token* pToken = null;
4338 _AccessibilityElement* pCurrentElement = const_cast< _AccessibilityElement* >(&element);
4339 _AccessibilityElement* pPreviousAccessibilityElement = null;
4340 _AccessibilityElement* pNextAccessibilityElement = null;
4341 r = __accessibilityElements.GetAt(__focusOutIndex, pPreviousAccessibilityElement);
4342 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
4344 if (pPreviousAccessibilityElement && pPreviousAccessibilityElement->GetAbsoluteBounds().y > element.GetAbsoluteBounds().y) //Left flick
4346 pToken = static_cast< _Token* >(__pTokenList->GetAt(__focusOutIndex - 1));
4349 if (pToken->displayRect.y < 0.0f && __focusOutIndex > 0)
4351 r = __accessibilityElements.GetAt(__focusOutIndex - 1, pNextAccessibilityElement);
4352 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
4354 ScrollToFocusedTokenAccessibilityElement(*pNextAccessibilityElement);
4359 if (pPreviousAccessibilityElement && pPreviousAccessibilityElement->GetAbsoluteBounds().y < element.GetAbsoluteBounds().y) //Right flick
4361 pToken = static_cast< _Token* >(__pTokenList->GetAt(__focusOutIndex + 1));
4364 if (pToken->displayRect.y + pToken->displayRect.height > __pTokenEdit->GetBoundsF().height)
4366 r = __accessibilityElements.GetAt(__focusOutIndex + 1, pNextAccessibilityElement);
4367 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
4369 ScrollToFocusedTokenAccessibilityElement(*pNextAccessibilityElement);
4374 if (pToken == null) //Draw Cursor Accessibility Element
4376 _AccessibilityElement* pCursorAccessibilityElement = __pTokenEdit->GetCursorAccessibilityElement();
4377 if (pCursorAccessibilityElement && pPreviousAccessibilityElement && pCursorAccessibilityElement != pPreviousAccessibilityElement)
4379 if (GetTextBoundsF().y - pPreviousAccessibilityElement->GetBounds().y > pPreviousAccessibilityElement->GetBounds().height) //check for different lines
4381 float height = GetTextBoundsF().height + pPreviousAccessibilityElement->GetBounds().y + pPreviousAccessibilityElement->GetBounds().height;
4382 if (pCurrentElement == pCursorAccessibilityElement && height > __pTokenEdit->GetBoundsF().height)
4384 float tokenBottomMargin = 0.0f;
4385 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, tokenBottomMargin);
4386 float newScrollValue = GetTextBoundsF().height + tokenBottomMargin - __scrollValue;
4387 RecalculateTokenBounds(newScrollValue);
4388 _AccessibilityManager::GetInstance()->SetGlobalFocusedElement(*(__pTokenEdit->GetCursorAccessibilityElement()));
4389 _AccessibilityManager::GetInstance()->RequestToDrawFocusUi();
4395 __focusOutIndex = -1;
4396 UpdateTokenAccessibilityBounds();
4402 _TokenEditPresenter::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
4404 _AccessibilityElement* pAccessibilityElement = null;
4405 pAccessibilityElement = const_cast< _AccessibilityElement* >(&element);
4406 __accessibilityElements.IndexOf(pAccessibilityElement, __focusOutIndex);
4412 _TokenEditPresenter::ScrollToFocusedToken(void)
4414 result r = E_SUCCESS;
4415 FloatRectangle focussedTokenRectangle;
4416 float newScrollValue = 0.0f;
4417 float tokenTopMargin = 0.0f;
4418 float tokenBottomMargin = 0.0f;
4419 float tokenHeight = 0.0f;
4420 float textBoundsAlignValue = 0.0f;
4421 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
4424 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
4425 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
4426 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
4428 FloatRectangle tokenEditRect = __pTokenEdit->GetBoundsF();
4429 float textObjectMaxHeight = GetMaxTextHeight();
4430 textBoundsAlignValue = (tokenHeight - textObjectMaxHeight) / 2.0f;
4432 if (__focusedTokenIndex == -1)
4434 //Focus bitmap to be reset when no token is focused.
4439 _Token* pToken = null;
4440 pToken = static_cast <_Token*>(__pTokenList->GetAt(__focusedTokenIndex));
4442 focussedTokenRectangle = pToken->displayRect;
4444 float focussedTokenPosition= focussedTokenRectangle.y + focussedTokenRectangle.height ;
4446 if ((focussedTokenRectangle.y > 0) && (focussedTokenPosition < tokenEditRect.height))
4448 //Focused token is within the tokenEdit boundary
4453 if (focussedTokenRectangle.y < 0)
4455 //Focused token is above the upper boundary
4456 newScrollValue = focussedTokenRectangle.y - tokenTopMargin - __scrollValue;
4460 //Focused token is below the lower boundary
4461 newScrollValue = focussedTokenPosition - textBoundsAlignValue - tokenEditRect.height + tokenBottomMargin - __scrollValue;
4464 r = RecalculateTokenBounds(newScrollValue);
4465 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
4473 _TokenEditPresenter::SetDrawFocusState(bool focusState)
4477 __focusedTokenIndex = -1;
4479 __drawFocusState = focusState;
4485 _TokenEditPresenter::GetFocusedTokenIndex(void) const
4487 return __focusedTokenIndex;
4491 _TokenEditPresenter::PrepareFocusUiMode(void)
4493 if (__editingTokenIndex != -1)
4495 ExitTokenEditingMode();
4497 else if (__pressedTokenIndex != -1)
4499 __pressedTokenIndex = -1;
4500 DetachCursorFromToken();
4502 SetCursorDisabled(false);
4503 __pTokenEdit->Invalidate();
4510 }}} //Tizen::Ui::Controls