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"
33 #include "FUiAnim_VisualElementImpl.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Runtime;
37 using namespace Tizen::Media;
38 using namespace Tizen::Ui::Animations;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Graphics::_Text;
42 namespace Tizen { namespace Ui { namespace Controls
46 SineTimingFunction::CalculateProgress(float timeProgress) const
48 const float segments[3][3] = {{0.0f, 0.01f, 0.37f}, {0.37f, 0.72f, 0.888f}, {0.888f, 0.9999f, 1.0f}};
49 float timeProgressValue = timeProgress;
50 int segmentsLength = 3; //Length of the segments array
51 int index = (int) floor(segmentsLength * timeProgressValue);
52 if (index >= segmentsLength)
54 index = segmentsLength - 1;
57 float progressValue = (timeProgressValue - index * (1.0 / segmentsLength)) * segmentsLength;
58 float segmentAtIndex[3];
59 for (int i = 0; i < 3; i++)
61 segmentAtIndex[i] = segments[index][i];
63 float ret = 0 + 1 * (segmentAtIndex[0] + progressValue * (2 * (1 - progressValue) * (segmentAtIndex[1] - segmentAtIndex[0]) + progressValue * (segmentAtIndex[2] - segmentAtIndex[0])));
73 result Construct(const String& text, Font* pEditFont);
74 virtual ~_Token(void);
75 float GetTextPixelWidth(void) const;
76 wchar_t* GetText(void) const;
77 result ResetToken(const String& text);
78 result SetBounds(FloatRectangle bounds);
79 _VisualElement* GetVisualElement(void) const;
80 _Token(const _Token& src);
81 _Token& operator =(const _Token& value);
84 FloatRectangle displayRect;
85 TextObject* pTextObject;
88 bool isImplicitAnimation;
91 wchar_t* __pTextBuffer;
92 float __textPixelWidth;
93 float __textPixelHeight;
94 _VisualElement* __pVisualElement;
101 , isImplicitAnimation(true)
103 , __pTextBuffer(null)
104 , __textPixelWidth(0.0f)
105 , __textPixelHeight(0.0f)
106 , __pVisualElement(null)
111 _Token::Construct(const String& text, Font* pEditFont)
113 result r = E_SUCCESS;
115 currTokenLength = text.GetLength();
116 float tokenFontSize = 0.0f;
118 pTextObject = new (std::nothrow) TextObject;
119 SysTryReturnResult(NID_UI_CTRL, pTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
121 // for default initialize.
122 r = pTextObject->Construct();
123 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
125 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
126 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
128 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
129 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
131 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, tokenFontSize);
133 pFont = _FontImpl::CloneN(*pEditFont);
135 SysTryCatch(NID_UI_CTRL, pFont != null, , r, "[%s] Propagating.", GetErrorMessage(r));
137 (_FontImpl::GetInstance(*pFont))->SetStyle(FONT_STYLE_PLAIN);
138 (_FontImpl::GetInstance(*pFont))->SetSize(tokenFontSize);
140 r = pTextObject->SetFont(pFont, 0, pTextObject->GetTextLength());
141 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
143 r = ResetToken(text);
144 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
146 __pVisualElement = new (std::nothrow) _VisualElement;
147 SysTryCatch(NID_UI_CTRL, __pVisualElement != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
149 r = __pVisualElement->Construct();
150 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct _VisualElement.", GetErrorMessage(r));
152 __pVisualElement->SetImplicitAnimationEnabled(false);
153 __pVisualElement->SetOpacity(0.0f);
161 if (__pVisualElement)
163 __pVisualElement->Destroy();
164 __pVisualElement = null;
174 _Token::ResetToken(const String& text)
176 result r = E_SUCCESS;
177 FloatDimension textSize;
181 delete[] __pTextBuffer;
182 __pTextBuffer = null;
185 int length = text.GetLength();
186 wchar_t* pTempString = const_cast< wchar_t* >(text.GetPointer());
187 SysTryReturnResult(NID_UI_CTRL, pTempString != null, E_SYSTEM, "A system error has occurred. Token text string is null.");
189 __pTextBuffer = new (std::nothrow) wchar_t[(length + 1) * (sizeof(wchar_t))];
190 SysTryReturnResult(NID_UI_CTRL, __pTextBuffer != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
192 for (int i = 0; i < length; i++)
194 __pTextBuffer[i] = pTempString[i];
196 __pTextBuffer[length] = 0;
198 pTextObject->RemoveAll(true);
200 TextSimple* pSimpleText = new (std::nothrow) TextSimple(__pTextBuffer, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, pFont);
201 SysTryCatch(NID_UI_CTRL, pSimpleText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
203 r = pTextObject->AppendElement(*pSimpleText);
204 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
206 textSize = pTextObject->GetTextExtentF(0, length);
207 __textPixelWidth = textSize.width;
208 __textPixelHeight = textSize.height;
210 r = pTextObject->Compose();
212 currTokenLength = length;
217 delete[] __pTextBuffer;
218 __pTextBuffer = null;
227 _Token::SetBounds(FloatRectangle bounds)
229 result r = E_SUCCESS;
230 displayRect = bounds;
231 if (__pVisualElement)
233 __pVisualElement->SetBounds(bounds);
239 _Token::GetVisualElement(void) const
241 return __pVisualElement;
244 _Token::~_Token(void)
252 delete[] __pTextBuffer;
253 __pTextBuffer = null;
255 if (__pVisualElement)
257 __pVisualElement->Destroy();
258 __pVisualElement = null;
263 _Token::GetTextPixelWidth(void) const
265 return __textPixelWidth;
269 _Token::GetText(void) const
271 return __pTextBuffer;
274 _TokenEditPresenter::_TokenEditPresenter(void)
277 , __pTokenBgBitmap(null)
278 , __pTokenBgNormalEffectBitmap(null)
279 , __pTokenBgPressedEffectBitmap(null)
280 , __pTokenBgReplacementFocusBitmap(null)
281 , __pTokenBgFocusEffectBitmap(null)
282 , __pressedTokenIndex(-1)
283 , __isEditingToken(false)
284 , __editingTokenIndex(-1)
285 , __clientRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
286 , __initTextRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
287 , __isEditModeEnabled(true)
288 , __pDescriptionTextVisualElement(null)
289 , __pDescriptionTextTextObject(null)
290 , __isTokenEditingFinished(false)
291 , __prevScrollValue(0.0f)
292 , __scrollValue(0.0f)
293 , __isTokenScrolling(false)
294 , __isNeedToScroll(false)
295 , __maxScrollValue(0.0f)
296 , __autoShrink(false)
297 , __descriptionText(String())
298 , __isPopupVisible(false)
299 , __isLongPressed(false)
300 , __lineSpacing(0.0f)
301 , __animatingIndex(-1)
302 , __lastTokenIndex(-1)
303 , __pTimingFunction(null)
304 , __descriptionTextRectForScroll(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
305 , __previousTitleWidth(-1.0f)
306 , __isTokenEditPresenterInitialized(false)
308 , __previousCursorPosition(0)
309 , __isScrollValueChanged(false)
311 , __isScrollValueModified(false)
312 , __isTouchMoveInProgress(false)
313 , __isTitleSliding(false)
314 , __touchPressInfo(FloatPoint(-1.0f, -1.0f))
315 , __editContentFontSize(0.0f)
316 , __trackTokenIndex(-1)
317 , __isAnimationInProgress(false)
318 , __focusOutIndex(-1)
319 , __accessibilityElements()
320 , __focusedTokenIndex(-1)
321 , __drawFocusState(false)
322 , __accessibilityFocusIn(false)
327 _TokenEditPresenter::InitializeDescriptionText(void)
329 result r = E_SUCCESS;
330 float descriptionTextSize = 0.0f;
332 float editFontSize = 0.0f;
334 __pDescriptionTextTextObject = new (std::nothrow) TextObject();
335 SysTryReturnResult(NID_UI_CTRL, __pDescriptionTextTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
337 // for default initialize.
338 r = __pDescriptionTextTextObject->Construct();
339 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
341 r = __pDescriptionTextTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
342 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
344 r = __pDescriptionTextTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
345 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
347 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, descriptionTextSize);
350 SysTryCatch(NID_UI_CTRL, pFont != null, , r, "[%s] Propagating.", GetErrorMessage(r));
352 editFontSize = GetTextSize();
353 (_FontImpl::GetInstance(*pFont))->SetSize(descriptionTextSize);
355 r = __pDescriptionTextTextObject->SetFont(pFont, 0, __pDescriptionTextTextObject->GetTextLength());
356 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
358 (_FontImpl::GetInstance(*pFont))->SetSize(editFontSize);
364 delete __pDescriptionTextTextObject;
365 __pDescriptionTextTextObject = null;
370 _TokenEditPresenter::~_TokenEditPresenter(void)
372 DisposeTokenEditPresenter();
376 _TokenEditPresenter::DisposeTokenEditPresenter(void)
378 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
379 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
381 if (pEditVisualElement && pCursorVisualElement)
383 VisualElement* pCursorParent = pCursorVisualElement->GetParent();
384 if (pCursorParent != pEditVisualElement)
388 pCursorParent->DetachChild(*pCursorVisualElement);
389 pEditVisualElement->AttachChild(*pCursorVisualElement);
396 __pTokenList->RemoveAll(true);
401 delete __pTokenBgBitmap;
402 __pTokenBgBitmap = null;
404 delete __pTokenBgNormalEffectBitmap;
405 __pTokenBgNormalEffectBitmap = null;
407 delete __pTokenBgPressedEffectBitmap;
408 __pTokenBgPressedEffectBitmap = null;
410 delete __pTokenBgReplacementFocusBitmap;
411 __pTokenBgReplacementFocusBitmap = null;
413 delete __pTokenBgFocusEffectBitmap;
414 __pTokenBgFocusEffectBitmap = null;
416 if (__pDescriptionTextVisualElement)
418 __pDescriptionTextVisualElement->Destroy();
419 __pDescriptionTextVisualElement = null;
422 delete __pDescriptionTextTextObject;
423 __pDescriptionTextTextObject = null;
425 if (__pTimingFunction)
427 delete __pTimingFunction;
428 __pTimingFunction = null;
431 RemoveChildAccessibilityElements();
437 _TokenEditPresenter::CreateTokenEditPresenterN(void)
439 _TokenEditPresenter* pPresenter = new (std::nothrow) _TokenEditPresenter();
440 SysTryReturn(NID_UI_CTRL, pPresenter != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
446 _TokenEditPresenter::Initialize(const _Control& control)
448 result r = E_SUCCESS;
450 r = _EditPresenter::Initialize(control);
451 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
453 r = InitializeDescriptionText();
454 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
456 TextObject* pTextObject = GetTextObject();
459 pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
460 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
461 pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
462 pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
465 __pTokenEdit = dynamic_cast< _TokenEdit* >(GetEditView());
466 SysTryReturnResult(NID_UI_CTRL, __pTokenEdit != null, E_SYSTEM, "A system error has occurred. The _Token instance is null.");
468 _TokenEditModel* pTokenEditModel = new (std::nothrow) _TokenEditModel();
469 SysTryReturnResult(NID_UI_CTRL, pTokenEditModel != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
471 SetModel(*pTokenEditModel);
473 SetKeypadEnabled(true);
475 // set title text default colors
476 Color titleTextNormalColor;
477 GET_COLOR_CONFIG(TOKENEDIT::TITLE_TEXT_NORMAL, titleTextNormalColor);
478 __pTokenEdit->SetTitleTextColor(EDIT_STATUS_NORMAL, titleTextNormalColor);
480 Color titleTextPressedColor;
481 GET_COLOR_CONFIG(TOKENEDIT::TITLE_TEXT_PRESSED, titleTextPressedColor);
482 __pTokenEdit->SetTitleTextColor(EDIT_STATUS_PRESSED, titleTextPressedColor);
484 Color titleTextHighlightedColor;
485 GET_COLOR_CONFIG(TOKENEDIT::TITLE_TEXT_HIGHLIGHTED, titleTextHighlightedColor);
486 __pTokenEdit->SetTitleTextColor(EDIT_STATUS_HIGHLIGHTED, titleTextHighlightedColor);
488 Color titleTextDisabledColor;
489 GET_COLOR_CONFIG(TOKENEDIT::TITLE_TEXT_DISABLED, titleTextDisabledColor);
490 __pTokenEdit->SetTitleTextColor(EDIT_STATUS_DISABLED, titleTextDisabledColor);
492 Color tokenEditBgNormal;
493 GET_COLOR_CONFIG(TOKENEDIT::EDIT_BG_NORMAL, tokenEditBgNormal);
494 __pTokenEdit->SetColor(EDIT_STATUS_NORMAL, tokenEditBgNormal);
496 Color tokenEditBgPressed;
497 GET_COLOR_CONFIG(TOKENEDIT::EDIT_BG_PRESSED, tokenEditBgPressed);
498 __pTokenEdit->SetColor(EDIT_STATUS_PRESSED, tokenEditBgPressed);
500 Color tokenEditBgHighlighted;
501 GET_COLOR_CONFIG(TOKENEDIT::EDIT_BG_HIGHLIGHTED, tokenEditBgHighlighted);
502 __pTokenEdit->SetColor(EDIT_STATUS_HIGHLIGHTED, tokenEditBgHighlighted);
504 Color tokenEditBgDisabled;
505 GET_COLOR_CONFIG(TOKENEDIT::EDIT_BG_DISABLED, tokenEditBgDisabled);
506 __pTokenEdit->SetColor(EDIT_STATUS_DISABLED, tokenEditBgDisabled);
508 Color tokenEditTextNormal;
509 GET_COLOR_CONFIG(TOKENEDIT::EDIT_TEXT_NORMAL, tokenEditTextNormal);
510 __pTokenEdit->SetTextColor(EDIT_TEXT_COLOR_NORMAL, tokenEditTextNormal);
512 Color tokenEditTextHighlighted;
513 GET_COLOR_CONFIG(TOKENEDIT::EDIT_TEXT_HIGHLIGHTED, tokenEditTextHighlighted);
514 __pTokenEdit->SetTextColor(EDIT_TEXT_COLOR_HIGHLIGHTED, tokenEditTextHighlighted);
516 Color tokenEditTextDisabled;
517 GET_COLOR_CONFIG(TOKENEDIT::EDIT_TEXT_DISABLED, tokenEditTextDisabled);
518 __pTokenEdit->SetTextColor(EDIT_TEXT_COLOR_DISABLED, tokenEditTextDisabled);
520 Color tokenGuideTextNormal;
521 GET_COLOR_CONFIG(TOKENEDIT::GUIDE_TEXT_NORMAL, tokenGuideTextNormal);
522 __pTokenEdit->SetGuideTextColor(tokenGuideTextNormal);
524 float leftMargin = 0.0f;
525 float rightMargin = 0.0f;
526 float tokenTopMargin = 0.0f;
527 float tokenBottomMargin = 0.0f;
528 float tokenHeight = 0.0f;
529 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
530 Color focusTokenColor;
531 Bitmap* pTokenBgFocusBitmap = null;
533 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
534 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
535 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
536 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
537 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
538 GET_COLOR_CONFIG(TOKENEDIT::BG_HIGHLIGHTED, focusTokenColor);
540 // For drawing token in specific area
541 __clientRect.x = leftMargin;
542 __clientRect.y = tokenTopMargin;
543 __clientRect.width = __pTokenEdit->GetBoundsF().width - leftMargin - rightMargin;
544 __clientRect.height = __pTokenEdit->GetBoundsF().height - tokenTopMargin - tokenBottomMargin;
546 __initTextRect = GetTextBoundsF();
548 FloatRectangle tempDspRect(__initTextRect.x, __initTextRect.y, __clientRect.width, tokenHeight);
549 SetTextBounds(tempDspRect);
551 float textSize = 0.0f;
552 GET_SHAPE_CONFIG(TOKENEDIT::TEXT_SIZE, orientation, textSize);
554 __editContentFontSize = textSize;
556 _EditPresenter::SetTextSize(__editContentFontSize);
558 __pTokenList = new (std::nothrow) Collection::LinkedList();
559 SysTryCatch(NID_UI_CTRL, __pTokenList != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
563 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgBitmap);
564 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
566 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_NORMAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgNormalEffectBitmap);
567 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
569 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_PRESSED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgPressedEffectBitmap);
570 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
572 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pTokenBgFocusBitmap);
573 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
575 __pTokenBgReplacementFocusBitmap = _BitmapImpl::GetColorReplacedBitmapN(
576 *pTokenBgFocusBitmap,Color::GetColor(COLOR_ID_MAGENTA), focusTokenColor);
577 SysTryCatch(NID_UI_CTRL, __pTokenBgReplacementFocusBitmap != null, , r, "[%s] Propagating.", GetErrorMessage(r));
579 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_FOCUS_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgFocusEffectBitmap);
580 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
582 delete pTokenBgFocusBitmap;
583 pTokenBgFocusBitmap = null;
586 __isTokenEditPresenterInitialized = true;
588 __previousCursorPosition = GetCursorPosition();
594 delete pTokenEditModel;
595 pTokenEditModel = null;
597 delete __pTokenBgBitmap;
598 __pTokenBgBitmap = null;
600 delete __pTokenBgNormalEffectBitmap;
601 __pTokenBgNormalEffectBitmap = null;
603 delete __pTokenBgPressedEffectBitmap;
604 __pTokenBgPressedEffectBitmap = null;
606 delete pTokenBgFocusBitmap;
607 pTokenBgFocusBitmap = null;
609 delete __pTokenBgReplacementFocusBitmap;
610 __pTokenBgReplacementFocusBitmap = null;
616 _TokenEditPresenter::DrawText(void)
618 bool isCustomBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_NORMAL);
619 //Checking IsBlocked() is additional check for handler movement in token edit mode
620 if ((__isEditingToken) && (__editingTokenIndex >= 0))
622 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
625 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
626 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element of token.");
628 Canvas* pTokenCanvas = pTokenVisualElement->GetCanvasN();
629 SysTryReturnVoidResult(NID_UI_CTRL, pTokenCanvas != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get canvas of the token.");
631 FloatRectangle tokenRect(0.0f, 0.0f, pToken->displayRect.width, pToken->displayRect.height);
632 pTokenCanvas->SetBackgroundColor(Color(0));
633 pTokenCanvas->Clear();
635 Color selectedTokenColor = GetTokenEditColor(TOKEN_EDIT_STATUS_SELECTED);
636 Bitmap* pReplacementColorBackgroundBitmap = null;
637 if (__pTokenBgBitmap)
639 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), selectedTokenColor);
641 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
643 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
647 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
652 pTokenCanvas->FillRectangle(selectedTokenColor, tokenRect);
655 if (__pTokenBgPressedEffectBitmap && (!isCustomBitmap))
657 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgPressedEffectBitmap))
659 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
663 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
667 _EditPresenter::DrawText(*pTokenCanvas);
672 delete pReplacementColorBackgroundBitmap;
677 _VisualElement* pTextVisualElement = null;
678 pTextVisualElement = GetTextVisualElement();
679 if (pTextVisualElement)
681 _EditPresenter::DrawText();
685 Canvas* pCanvas = __pTokenEdit->GetCanvasN();
686 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element of Control.");
688 _EditPresenter::DrawText(*pCanvas);
697 _TokenEditPresenter::Draw(Canvas& canvas)
699 if (!IsInitialized())
701 InitializeAtFirstDrawing();
703 if (IsFocused() == true)
709 canvas.SetBackgroundColor(Color(0, 0, 0, 0));
712 DrawBackground(canvas);
716 if (__pDescriptionTextTextObject->GetTextLength() != 0)
718 DrawDescriptionText();
721 if (GetTokenCount() != 0)
726 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
727 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
729 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
730 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
732 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
736 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
737 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get visual element of token.");
739 if (__isEditingToken)
741 Canvas* pTokenCanvas = pTokenVisualElement->GetCanvasN();
742 SysTryReturnResult(NID_UI_CTRL, pTokenCanvas != null, E_SYSTEM, "A system error has occurred. Failed to get canvas of the token.");
744 _EditPresenter::DrawText(*pTokenCanvas);
759 SysTryReturnResult(NID_UI_CTRL, !__isEditingToken, E_SYSTEM, "An invalid argument is given.");
765 if (__isTokenEditingFinished)
767 __isEditingToken = false;
768 __editingTokenIndex = -1;
769 _EditPresenter::SetTextSize(__editContentFontSize);
771 __isTokenEditingFinished = false;
778 _TokenEditPresenter::DrawToken(int count)
780 int drawStartIndex = 0;
782 float tokenTextLeftMargin = 0.0f;
783 float tokenVerticalSpacing = 0.0f;
784 bool isCustomBitmap = false;
785 bool isCustomFocusBitmap = false;
787 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
789 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
791 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
792 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
794 isCustomBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_NORMAL);
795 isCustomFocusBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_FOCUS);
798 if (__drawFocusState)
800 __pTokenEdit->RefreshFocusUi();
805 tokenCount = __pTokenList->GetCount();
812 Color normalTokenColor;
813 Color selectedTokenColor;
814 Color disabledTokenColor;
816 for (int i = drawStartIndex; i < tokenCount; i++)
818 Bitmap* pReplacementColorBackgroundBitmap = null;
820 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
821 if (pToken == null || pToken->pTextObject == null)
823 SysLog(NID_UI_CTRL, "[E_SYSTEM] The _Token instance is null");
827 normalTokenColor = GetTokenEditColor(TOKEN_EDIT_STATUS_NORMAL);
828 selectedTokenColor = GetTokenEditColor(TOKEN_EDIT_STATUS_SELECTED);
829 disabledTokenColor = GetTokenEditColor(TOKEN_EDIT_STATUS_DISABLED);
831 _VisualElement* pTokenElement = pToken->GetVisualElement();
832 if (pTokenElement == null)
834 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. The _VisualElement instance is null");
838 bool isSelected = false;
839 Canvas* pTokenCanvas = pTokenElement->GetCanvasN();
840 if (pTokenCanvas == null)
842 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. The Canvas instance is null");
845 FloatRectangle tokenRect(0.0f, 0.0f, pToken->displayRect.width, pToken->displayRect.height);
846 pTokenCanvas->SetBackgroundColor(Color(0));
847 pTokenCanvas->Clear();
849 if (__pressedTokenIndex == i && IsFocused())
851 if (__pTokenBgBitmap)
853 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), selectedTokenColor);
855 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
857 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
861 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
866 pTokenCanvas->FillRectangle(selectedTokenColor, tokenRect);
870 if (__pTokenBgPressedEffectBitmap && (!isCustomBitmap))
872 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgPressedEffectBitmap))
874 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
878 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
886 Color tokenBgColor = normalTokenColor;
887 if (GetCurrentStatus() == EDIT_STATUS_DISABLED)
889 tokenBgColor = disabledTokenColor;
892 if (__pTokenBgBitmap)
894 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), tokenBgColor);
896 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
898 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
902 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
907 pTokenCanvas->FillRectangle(tokenBgColor, tokenRect);
911 if (__pTokenBgNormalEffectBitmap && (!isCustomBitmap))
913 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgNormalEffectBitmap))
915 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgNormalEffectBitmap);
919 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgNormalEffectBitmap);
924 if (__focusedTokenIndex == i && __drawFocusState && (!__isEditingToken))
926 if (__pTokenBgReplacementFocusBitmap)
928 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgReplacementFocusBitmap))
930 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgReplacementFocusBitmap);
934 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgReplacementFocusBitmap);
938 if (__pTokenBgFocusEffectBitmap && (!isCustomFocusBitmap))
940 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgFocusEffectBitmap))
942 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgFocusEffectBitmap);
946 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgFocusEffectBitmap);
952 pTokenElement->SetAnimationProvider(null);
953 if (pToken->isImplicitAnimation)
955 VisualElementAnimation* pAnimation = CreateAnimationN(*pTokenElement);
956 pTokenElement->AddAnimation(*pAnimation);
958 pToken->isImplicitAnimation = false;
961 if (!__isEditingToken || __pressedTokenIndex != i)
964 FloatRectangle textRect(0.0f, 0.0f, pToken->displayRect.width - ((tokenTextLeftMargin * 2.0f)), pToken->displayRect.height - tokenVerticalSpacing);
966 textRect.x += tokenTextLeftMargin;
967 textRect.y += (tokenVerticalSpacing / 2.0f);
971 textColor = GetTokenEditTextColor(TOKEN_EDIT_STATUS_SELECTED);
975 textColor = GetTokenEditTextColor(TOKEN_EDIT_STATUS_NORMAL);
978 pToken->pTextObject->SetForegroundColor(textColor, 0, pToken->pTextObject->GetTextLength());
979 pToken->pTextObject->SetBounds(textRect);
980 pToken->pTextObject->Compose();
981 pToken->pTextObject->Draw(*_CanvasImpl::GetInstance(*pTokenCanvas));
984 pTokenElement->SetFlushNeeded();
987 delete pReplacementColorBackgroundBitmap;
988 pReplacementColorBackgroundBitmap = null;
994 _TokenEditPresenter::GetTokenEditColor(const TokenEditStatus status) const
996 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, Color(0, 0, 0, 0), E_INVALID_STATE, "[E_INVALID_STATE] _TokenEdit is in an invalid state.");
998 return __pTokenEdit->GetTokenColor(status);
1002 _TokenEditPresenter::GetTokenEditTextColor(const TokenEditStatus status) const
1004 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, Color(0, 0, 0, 0), E_INVALID_STATE, "[E_INVALID_STATE] _TokenEdit is in an invalid state.");
1008 if (status == TOKEN_EDIT_STATUS_NORMAL)
1010 color = __pTokenEdit->GetTokenTextColor();
1014 color = __pTokenEdit->GetSelectedTokenTextColor();
1021 _TokenEditPresenter::MakeToken(const String& tokenString)
1023 SysTryReturnResult(NID_UI_CTRL, __pTokenEdit != null, E_INVALID_STATE, "_TokenEdit is in an invalid state.");
1024 result r = E_SUCCESS;
1028 int tokenLength = tokenString.GetLength();
1029 SysTryReturnResult(NID_UI_CTRL, tokenLength, E_INVALID_ARG, "Invalid argument is used. Token length is (%d)", tokenLength);
1031 String inputTokenString = tokenString;
1032 String replacementString = inputTokenString;
1033 bool enable = false;
1035 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
1039 inputTokenString = replacementString;
1042 if (inputTokenString.GetLength() <= 0)
1045 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to clear text object.", GetErrorMessage(r));
1047 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
1048 return E_INVALID_ARG;
1051 _Token* pToken = new (std::nothrow) _Token();
1052 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1054 r = pToken->Construct(inputTokenString, GetFont());
1055 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct token.", GetErrorMessage(r));
1057 r = __pTokenList->Add(static_cast< Object& >(*pToken));
1058 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1060 tokenCount = __pTokenList->GetCount();
1061 index = tokenCount - 1;
1063 r = CalculateTokenPositionFromIndex(index);
1064 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to calculate token position.", GetErrorMessage(r));
1066 r = TrimTokenAndAdjustEllipsisAt(index);
1067 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to trim token.", GetErrorMessage(r));
1069 r = InitializeTokenVisibilityAt(index);
1070 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to initialize token visibility.", GetErrorMessage(r));
1072 r = SetInitialBounds();
1073 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds.", GetErrorMessage(r));
1076 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to clear text object.", GetErrorMessage(r));
1078 r = AdjustFlexibleHeight();
1079 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process to resize.", GetErrorMessage(r));
1081 r = CheckTokenScrolling();
1082 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process scroll.", GetErrorMessage(r));
1084 AppendTokenAccessibilityElement();
1085 UpdateTokenAccessibilityBounds();
1090 __pTokenList->Remove(*pToken);
1099 _TokenEditPresenter::MakeToken(void)
1101 result r = E_SUCCESS;
1103 String tempToken(GetText());
1104 r = MakeToken(tempToken);
1110 _TokenEditPresenter::AppendToken(const Tizen::Base::String& token)
1112 result r = E_SUCCESS;
1114 r = MakeToken(token);
1115 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1117 if (__editingTokenIndex >= 0)
1119 SetEditingTokenTextBounds(__editingTokenIndex);
1120 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1127 _TokenEditPresenter::InsertTokenAt(int index, const String& token, bool isUser)
1129 SysTryReturnResult(NID_UI_CTRL, index >= 0, E_INVALID_ARG, "Invalid argument is used. index is (%d).", index);
1130 SysTryReturnResult(NID_UI_CTRL, token.GetLength() > 0, E_INVALID_ARG, "Invalid argument is used. Token length is (%d).", token.GetLength());
1132 result r = E_SUCCESS;
1134 _Token* pToken = new (std::nothrow) _Token();
1135 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1137 r = pToken->Construct(token, GetFont());
1138 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct token.", GetErrorMessage(r));
1140 r = __pTokenList->InsertAt(*pToken, index);
1141 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to insert token.", GetErrorMessage(r));
1145 r = CalculateTokenPositionFromIndex(index);
1146 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to calculate token position.", GetErrorMessage(r));
1148 r = TrimTokenAndAdjustEllipsisAt(index);
1149 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to trim token.", GetErrorMessage(r));
1151 r = InitializeTokenVisibilityAt(index);
1152 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to initialize token visibility.", GetErrorMessage(r));
1154 r = SetInitialBounds();
1155 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds.", GetErrorMessage(r));
1157 r = AdjustFlexibleHeight();
1158 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process to resize.", GetErrorMessage(r));
1160 r = CheckTokenScrolling();
1161 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process scroll.", GetErrorMessage(r));
1163 for (int i = 0; i < GetTokenCount(); i++)
1165 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
1166 SysTryCatch(NID_UI_CTRL, pToken != null, , r = E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
1168 r = pToken->SetBounds(pToken->displayRect);
1169 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds", GetErrorMessage(r));
1172 InsertTokenAccessibilityElementAt(index);
1173 UpdateTokenAccessibilityBounds();
1177 if (__editingTokenIndex >= 0)
1179 if (index <= __editingTokenIndex)
1181 __editingTokenIndex++;
1183 __pressedTokenIndex = __editingTokenIndex;
1185 SetEditingTokenTextBounds(__editingTokenIndex);
1186 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1188 else if (__pressedTokenIndex >= index)
1190 __pressedTokenIndex++;
1192 else if ((__focusedTokenIndex >= index) && __drawFocusState)
1194 __focusedTokenIndex++;
1201 __pTokenList->Remove(*pToken);
1210 _TokenEditPresenter::GetTokenAt(int index) const
1213 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);
1215 _Token* pToken = null;
1216 pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
1219 tempString = pToken->GetText();
1226 _TokenEditPresenter::GetTokenCount(bool isInvokedByApp) const
1228 if (!isInvokedByApp)
1230 return __pTokenList->GetCount();
1234 if (__isAnimationInProgress)
1236 return __pTokenList->GetCount() - 1;
1240 return __pTokenList->GetCount();
1246 _TokenEditPresenter::GetSelectedTokenIndex(void) const
1248 if (__drawFocusState)
1250 return __focusedTokenIndex;
1253 return __pressedTokenIndex;
1257 _TokenEditPresenter::IsTokenEditModeEnabled(void) const
1259 return __isEditModeEnabled;
1263 _TokenEditPresenter::RemoveTokenAt(int index, bool isClearText)
1265 result r = E_SUCCESS;
1266 SysTryReturnResult(NID_UI_CTRL, index >= 0 && index < __pTokenList->GetCount(), E_OUT_OF_RANGE, "index (%d) is out of range.", index);
1268 if (index == __editingTokenIndex && isClearText)
1270 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
1271 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
1273 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
1274 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
1276 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
1277 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1279 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
1280 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1282 __editingTokenIndex = -1;
1283 __isEditingToken = false;
1284 __pressedTokenIndex = -1;
1285 __isTokenEditingFinished = true;
1288 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Failed to clear text object.");
1290 _EditPresenter::SetTextSize(__editContentFontSize);
1293 r = __pTokenList->RemoveAt(index, true);
1294 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove token.");
1296 r = CalculateTokenPositionFromIndex(index);
1297 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to calculate token position.");
1299 r = SetInitialBounds();
1300 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
1302 _Token* pToken = null;
1304 for (int i = 0; i < GetTokenCount(); i++)
1306 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
1307 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
1309 r = pToken->SetBounds(pToken->displayRect);
1310 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds");
1313 r = AdjustFlexibleHeight();
1314 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to process to resize.");
1316 r = CheckTokenScrolling();
1317 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to process scroll.");
1319 RemoveTokenAccessibilityElementAt(index);
1320 UpdateTokenAccessibilityBounds();
1324 if (index > __editingTokenIndex)
1326 SetEditingTokenTextBounds(__editingTokenIndex);
1327 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1329 if (index < __editingTokenIndex)
1331 if (__editingTokenIndex > 0)
1333 __editingTokenIndex--;
1334 __pressedTokenIndex = __editingTokenIndex;
1336 SetEditingTokenTextBounds(__editingTokenIndex);
1337 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1340 else if (index == __pressedTokenIndex)
1342 __pressedTokenIndex = -1;
1344 SetCursorDisabled(false);
1347 else if (index >= 0 && index < __pressedTokenIndex)
1349 __pressedTokenIndex--;
1352 if (__drawFocusState)
1354 if (index == __focusedTokenIndex)
1356 __focusedTokenIndex = -1;
1358 SetCursorDisabled(false);
1361 else if(index >= 0 && index < __focusedTokenIndex)
1363 __focusedTokenIndex--;
1367 else if (index == __pressedTokenIndex)
1369 __pressedTokenIndex = -1;
1371 SetCursorDisabled(false);
1374 else if ((index == __focusedTokenIndex) && __drawFocusState)
1376 __focusedTokenIndex = -1;
1378 SetCursorDisabled(false);
1386 _TokenEditPresenter::SetTokenSelected(int index, bool selected)
1388 result r = E_SUCCESS;
1390 SysTryReturnResult(NID_UI_CTRL, index >= 0 && index < __pTokenList->GetCount(), E_OUT_OF_RANGE, "index (%d) is out of range.");
1392 if (selected == false)
1394 __pressedTokenIndex = -1;
1398 __pressedTokenIndex = index;
1405 _TokenEditPresenter::SetTokenEditModeEnabled(bool enable)
1407 result r = E_SUCCESS;
1409 __isEditModeEnabled = enable;
1415 _TokenEditPresenter::CalculateTokenPositionFromIndex(int startIndex, bool leftWard)
1417 result r = E_SUCCESS;
1419 int tokenCount = __pTokenList->GetCount();
1421 float leftMargin = 0.0f;
1422 float rightMargin = 0.0f;
1423 float tokenTopMargin = 0.0f;
1424 float tokenBottomMargin = 0.0f;
1425 float tokenHeight = 0.0f;
1426 float tokenVerticalSpacing = 0.0f;
1427 float tokenHorizontalSpacing = 0.0f;
1428 float tokenTextLeftMargin = 0.0f;
1429 float tokenTextRightMargin = 0.0f;
1430 float descriptionTextRightMargin = 0.0f;
1431 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1433 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
1434 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
1435 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1436 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
1437 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1438 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1439 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HORIZONTAL_SPACING, orientation, tokenHorizontalSpacing);
1440 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1441 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1442 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_RIGHT_MARGIN, orientation, descriptionTextRightMargin);
1444 SysTryReturn(NID_UI_CTRL, startIndex >= 0 && startIndex <= tokenCount, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. startIndex = (%d)", startIndex);
1446 _Token* pToken = null;
1447 _Token* pPreviousToken = null;
1449 int index = startIndex;
1451 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
1452 String titleText = __pTokenEdit->GetTitleText();
1454 if (!_FloatCompare(GetDescriptionTextRect().width, __previousTitleWidth))
1456 __descriptionTextRectForScroll = GetDescriptionTextRect();
1457 __previousTitleWidth = GetDescriptionTextRect().width;
1460 bool findPrevTokenLoopFlag = true;
1461 for (; index < tokenCount; index++)
1463 pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
1464 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
1468 // TODO : description text (title style inner)
1469 if (titleText.GetLength())
1471 pToken->displayRect.x = __descriptionTextRectForScroll.x + __descriptionTextRectForScroll.width + descriptionTextRightMargin;
1472 pToken->displayRect.y = __descriptionTextRectForScroll.y + __scrollValue;
1474 else // Set description text.
1476 pToken->displayRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1477 pToken->displayRect.y = tokenTopMargin + __scrollValue + __pTokenEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN) + __lineSpacing;
1480 pToken->displayRect.width = tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin;
1485 if (findPrevTokenLoopFlag)
1487 pPreviousToken = static_cast< _Token* >(__pTokenList->GetAt(index - 1));
1488 r = GetLastResult();
1489 SysTryReturnResult(NID_UI_CTRL, pPreviousToken != null, r, "Propagating.");
1491 findPrevTokenLoopFlag = false;
1494 float tempTextWidth = tokenEditBounds.width - pPreviousToken->displayRect.x - pPreviousToken->displayRect.width - tokenHorizontalSpacing - rightMargin - __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1495 if (tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin > tempTextWidth) // Line change
1497 pToken->displayRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1498 pToken->displayRect.y = pPreviousToken->displayRect.y + tokenHeight + tokenVerticalSpacing + __lineSpacing;
1503 pToken->displayRect.x = pPreviousToken->displayRect.x + pPreviousToken->displayRect.width +
1504 tokenHorizontalSpacing;
1505 pToken->displayRect.y = pPreviousToken->displayRect.y;
1508 pToken->displayRect.width = tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin;
1511 pToken->displayRect.height = tokenHeight;
1513 pPreviousToken = pToken;
1516 for (int i = 0; i < __pTokenList->GetCount(); i++)
1518 TrimTokenAndAdjustEllipsisAt(i);
1519 InitializeTokenVisibilityAt(i);
1525 _TokenEditPresenter::InitializeTokenVisibilityAt(int ndex)
1527 result r = E_SUCCESS;
1529 _Token* pToken = null;
1530 pToken = static_cast< _Token* >(__pTokenList->GetAt(ndex));
1531 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
1533 r = pToken->SetBounds(pToken->displayRect);
1534 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to set bounds", GetErrorMessage(r));
1536 _VisualElement* pRootElement = __pTokenEdit->GetVisualElement();
1537 SysTryReturn(NID_UI_CTRL, pRootElement, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
1539 _VisualElement* pVisualElement = pToken->GetVisualElement();
1540 SysTryReturn(NID_UI_CTRL, pVisualElement, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element.");
1542 pVisualElement->SetShowState(true);
1544 r = pRootElement->AttachChild(*pVisualElement);
1545 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to add child", GetErrorMessage(r));
1551 _TokenEditPresenter::GetMaxTextHeight(void)
1554 float maxHeight = __editContentFontSize;
1557 SysTryReturn(NID_UI_CTRL, pFont != null, maxHeight, E_SYSTEM, "[E_SYSTEM] Failed to get Font instance.");
1559 maxHeight = pFont->GetMaxHeightF();
1565 _TokenEditPresenter::ResetTextBounds(void)
1567 if (!__isEditingToken)
1569 result r = SetInitialBounds();
1570 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occured. Failed to set margin.");
1576 _TokenEditPresenter::SetInitialBounds(void)
1578 result r = E_SUCCESS;
1580 float leftMargin = 0.0f;
1581 float rightMargin = 0.0f;
1582 float tokenTopMargin = 0.0f;
1583 float tokenHeight = 0.0f;
1584 float tokenMinWidth = 0.0f;
1585 float tokenVerticalSpacing = 0.0f;
1586 float tokenHorizontalSpacing = 0.0f;
1587 float tokenTextLeftMargin = 0.0f;
1588 float tokenTextRightMargin = 0.0f;
1589 float textBoundsAlignValue = 0.0f;
1590 float descriptionTextRightMargin = 0.0f;
1591 _ControlOrientation orientation = GetEditView()->GetOrientation();
1593 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
1594 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
1595 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1596 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1597 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_MIN_WIDTH, orientation, tokenMinWidth);
1598 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1599 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HORIZONTAL_SPACING, orientation, tokenHorizontalSpacing);
1600 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1601 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1602 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_RIGHT_MARGIN, orientation, descriptionTextRightMargin);
1604 float textObjectMaxHeight = GetMaxTextHeight();
1605 textBoundsAlignValue = (tokenHeight - textObjectMaxHeight) / 2.0f;
1609 int tokenCount = __pTokenList->GetCount();
1611 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
1612 FloatRectangle tokenTextRect = tokenEditBounds;
1614 if (tokenCount == 0)
1616 if (__pTokenEdit->GetTitleText().GetLength())
1618 FloatRectangle descriptionTextRect = GetDescriptionTextRect();
1619 tokenTextRect.x = descriptionTextRect.x + descriptionTextRect.width + descriptionTextRightMargin;
1623 tokenTextRect.x = leftMargin + __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_LEFT_MARGIN);
1626 tokenTextRect.y = tokenTopMargin + __pTokenEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN) + textBoundsAlignValue;
1627 tokenTextRect.width -= tokenTextRect.x + rightMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1628 tokenTextRect.height = textObjectMaxHeight;
1630 SetTextBounds(tokenTextRect);
1631 //set cursor bounds with tokenTextRect
1632 __pTokenEdit->SetCursorAccessibilityBounds(tokenTextRect);
1636 _Token* pToken = null;
1637 // SetTextBounds from last token
1638 pToken = static_cast< _Token* >(__pTokenList->GetAt(tokenCount - 1));
1639 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
1641 float tempTextRectWidth = 0.0f;
1642 tempTextRectWidth = tokenEditBounds.width - pToken->displayRect.x - pToken->displayRect.width - tokenHorizontalSpacing - rightMargin - __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1643 if (tokenMinWidth > tempTextRectWidth) // Line change
1645 tokenTextRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1646 tokenTextRect.y = pToken->displayRect.y + tokenHeight + tokenVerticalSpacing + __lineSpacing + textBoundsAlignValue;
1650 tokenTextRect.x = pToken->displayRect.x + pToken->displayRect.width + tokenHorizontalSpacing;
1651 tokenTextRect.y = pToken->displayRect.y + textBoundsAlignValue;
1654 tokenTextRect.width -= tokenTextRect.x + rightMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1655 tokenTextRect.height = textObjectMaxHeight;
1657 SetTextBounds(tokenTextRect);
1658 if (__pressedTokenIndex < 0) // Set cursor as global focused element if no token is selected
1660 __pTokenEdit->SetCursorAccessibilityBounds(tokenTextRect);
1665 r = _EditPresenter::SetInitialBounds();
1672 _TokenEditPresenter::SetDescriptionTextRect(const FloatRectangle& rect)
1674 result r = E_SUCCESS;
1676 __descriptionTextRect = rect;
1682 _TokenEditPresenter::GetDescriptionTextRect() const
1684 return __descriptionTextRect;
1688 _TokenEditPresenter::GetTextBounds(void) const
1690 if ((__isPopupVisible == true || __isLongPressed == true) && __pressedTokenIndex >= 0)
1692 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__pressedTokenIndex));
1693 SysTryReturn(NID_UI_CTRL, pToken, Rectangle(), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Unable to get valid token.");
1695 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1696 float tokenTextLeftMargin = 0.0f;
1697 float tokenTextVerticalMargin = 0.0f;
1698 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1699 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenTextVerticalMargin);
1701 FloatRectangle textBoundsF(pToken->displayRect.x + tokenTextLeftMargin, pToken->displayRect.y + (tokenTextVerticalMargin / 2.0f), pToken->displayRect.width - (tokenTextLeftMargin * 2.0f), pToken->displayRect.height - tokenTextVerticalMargin);
1702 Rectangle textBounds = _CoordinateSystemUtils::ConvertToInteger(textBoundsF);
1708 return _EditPresenter::GetTextBounds();
1713 _TokenEditPresenter::GetTextBoundsF(void) const
1715 if ((__isPopupVisible == true || __isLongPressed == true) && __pressedTokenIndex >= 0)
1717 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__pressedTokenIndex));
1718 SysTryReturn(NID_UI_CTRL, pToken, FloatRectangle(), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Unable to get valid token.");
1720 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1721 int tokenTextLeftMargin = 0;
1722 int tokenTextVerticalMargin = 0;
1723 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1724 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenTextVerticalMargin);
1726 FloatRectangle textBounds(pToken->displayRect.x + tokenTextLeftMargin, pToken->displayRect.y + (tokenTextVerticalMargin / 2.0f), pToken->displayRect.width - (tokenTextLeftMargin * 2.0f), pToken->displayRect.height - tokenTextVerticalMargin);
1732 return _EditPresenter::GetTextBoundsF();
1737 _TokenEditPresenter::CutText(void)
1739 if (__isEditingToken)
1741 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
1742 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
1744 pToken->isTextCut = true;
1746 return _EditPresenter::CutText();
1750 _TokenEditPresenter::SetLineSpacing(int linePixelGap)
1752 __lineSpacing = linePixelGap;
1758 _TokenEditPresenter::SetLineSpacing(float linePixelGap)
1760 __lineSpacing = linePixelGap;
1766 _TokenEditPresenter::GetLineSpacing(void) const
1768 int lineSpacing = _CoordinateSystemUtils::ConvertToInteger(__lineSpacing);
1773 _TokenEditPresenter::GetLineSpacingF(void) const
1775 return __lineSpacing;
1778 VisualElementAnimation*
1779 _TokenEditPresenter::CreateAnimationN(VisualElement& source)
1781 VisualElementAnimation* pAnimation = null;
1782 VisualElementAnimationGroup* pAnimationGroup = new (std::nothrow) VisualElementAnimationGroup();
1783 SysTryReturn(NID_UI_CTRL, pAnimationGroup, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1785 pAnimationGroup->SetDuration(ANIMATION_DURATION_BOUNDS);
1786 if (__pTimingFunction == null)
1788 __pTimingFunction = new (std::nothrow) SineTimingFunction();
1789 SysTryReturn(NID_UI_CTRL, __pTimingFunction, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1792 if (pAnimationGroup != null)
1794 VisualElementPropertyAnimation* pOpacityAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1795 SysTryReturn(NID_UI_CTRL, pOpacityAnimation, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1797 pOpacityAnimation->SetPropertyName("opacity");
1799 pOpacityAnimation->SetStartValue(Variant(0.0f));
1800 pOpacityAnimation->SetEndValue(Variant(1.0f));
1802 pOpacityAnimation->SetDuration(ANIMATION_DURATION_OPACITY);
1803 pOpacityAnimation->SetTimingFunction(__pTimingFunction);
1804 pAnimationGroup->AddAnimation(*pOpacityAnimation);
1805 delete pOpacityAnimation;
1807 VisualElementPropertyAnimation* pBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1808 SysTryReturn(NID_UI_CTRL, pBoundsAnimation, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1810 pBoundsAnimation->SetPropertyName("bounds");
1811 FloatRectangle startValue = source.GetBounds();
1812 startValue.x = startValue.x + startValue.width * 0.05;
1813 startValue.y = startValue.y + startValue.height * 0.05;
1814 startValue.width = startValue.width * 0.9;
1815 startValue.height = startValue.height * 0.9;
1817 pBoundsAnimation->SetStartValue(Variant(startValue));
1818 pBoundsAnimation->SetEndValue(Variant(source.GetBounds()));
1820 pBoundsAnimation->SetDuration(ANIMATION_DURATION_BOUNDS);
1821 pBoundsAnimation->SetTimingFunction(__pTimingFunction);
1822 pAnimationGroup->AddAnimation(*pBoundsAnimation);
1824 delete pBoundsAnimation;
1826 pAnimation = pAnimationGroup;
1832 _TokenEditPresenter::CalculateDescriptionTextRect(const String& descriptionText)
1834 result r = E_SUCCESS;
1836 TextSimple* pSimpleText = null;
1837 float leftMargin = 0.0f;
1838 float tokenTopMargin = 0.0f;
1839 float tokenHeight = 0.0f;
1840 float tokenVerticalSpacing = 0.0f;
1841 float tokenTextLeftMargin = 0.0f;
1842 float tokenTextRightMargin = 0.0f;
1843 float tokenTitleWidth = 0.0f;
1844 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1846 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1847 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
1848 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1849 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1850 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1851 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1852 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TITLE_RECT_WIDTH, orientation, tokenTitleWidth);
1854 int length = descriptionText.GetLength();
1855 FloatDimension textSize;
1857 wchar_t* pTempString = const_cast< wchar_t* >(descriptionText.GetPointer());
1859 SysAssertf(__pDescriptionTextTextObject != null, "The TextObject instance is null.");
1861 __pDescriptionTextTextObject->RemoveAll(true);
1862 pSimpleText = new (std::nothrow) TextSimple(pTempString, length, TEXT_ELEMENT_SOURCE_TYPE_INTERNAL);
1863 __pDescriptionTextTextObject->AppendElement(*pSimpleText);
1865 textSize = __pDescriptionTextTextObject->GetTextExtentF(0, length);
1866 r = __pDescriptionTextTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1867 r = __pDescriptionTextTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
1869 __descriptionTextRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1870 __descriptionTextRect.y = tokenTopMargin + __pTokenEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN);
1871 if (textSize.width > tokenTitleWidth)
1873 textSize.width = tokenTitleWidth;
1874 __pDescriptionTextTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
1877 __descriptionTextRect.width = tokenTextLeftMargin + textSize.width + tokenTextRightMargin;
1878 __descriptionTextRect.height = tokenHeight;
1879 __pDescriptionTextTextObject->SetBounds(__descriptionTextRect);
1881 if (__pDescriptionTextTextObject->IsChanged())
1883 _EditPresenter::StopTitleSlidingTimer();
1884 __isTitleSliding = false;
1887 r = __pDescriptionTextTextObject->Compose();
1893 _TokenEditPresenter::IsGuideTextActivated(void) const
1895 bool isGuideTextActivated = _EditPresenter::IsGuideTextActivated();
1897 if (__isTokenEditPresenterInitialized)
1899 if (GetTokenCount())
1905 return isGuideTextActivated;
1909 _TokenEditPresenter::DrawDescriptionText(void)
1911 result r = E_SUCCESS;
1912 FloatRectangle tempDescriptionTextRect;
1913 FloatRectangle descriptionTextRect(__descriptionTextRect);
1914 Canvas* pDescriptionTextCanvas = null;
1916 Font* pDescriptionFont = null;
1917 TextObjectActionType titleAction;
1918 _VisualElement* pRootElement = null;
1920 if (__pDescriptionTextTextObject->GetFont(0)->GetFaceName() != GetTitleFontFaceName())
1922 float descriptionTextSize = 0.0f;
1923 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, descriptionTextSize);
1925 pDescriptionFont = GetFont();
1926 if (pDescriptionFont)
1928 float editFontSize = GetTextSize();
1929 (_FontImpl::GetInstance(*pDescriptionFont))->SetSize(descriptionTextSize);
1931 r = __pDescriptionTextTextObject->SetFont(pDescriptionFont, 0, __pDescriptionTextTextObject->GetTextLength());
1932 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. SetFont failed");
1934 (_FontImpl::GetInstance(*pDescriptionFont))->SetSize(editFontSize);
1938 pRootElement = __pTokenEdit->GetVisualElement();
1939 SysTryCatch(NID_UI_CTRL, pRootElement, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
1941 if (!__pDescriptionTextVisualElement)
1943 __pDescriptionTextVisualElement = new (std::nothrow) _VisualElement();
1944 SysTryCatch(NID_UI_CTRL, __pDescriptionTextVisualElement, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1945 r = __pDescriptionTextVisualElement->Construct();
1946 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[E_SYSTEM] A system error has occurred. Failed to construct _VisualElement");
1947 __pDescriptionTextVisualElement->SetImplicitAnimationEnabled(false);
1948 __pDescriptionTextVisualElement->SetShowState(true);
1950 r = pRootElement->AttachChild(*__pDescriptionTextVisualElement);
1951 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1954 descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
1955 __pDescriptionTextVisualElement->SetBounds(descriptionTextRect);
1956 UpdateTitleAccessibilityBounds(descriptionTextRect); // Update title accessibility bounds to same as DescriptionTextVisualElement bounds
1958 pDescriptionTextCanvas = __pDescriptionTextVisualElement->GetCanvasN();
1959 if (pDescriptionTextCanvas == null)
1961 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to get canvas of an instance of _VisualElement.");
1965 tempDescriptionTextRect = __descriptionTextRect;
1966 tempDescriptionTextRect.x = 0.0f;
1967 tempDescriptionTextRect.y = 0.0f;
1969 titleAction = __pDescriptionTextTextObject->GetAction();
1971 pDescriptionTextCanvas->SetBackgroundColor(Color(0));
1972 pDescriptionTextCanvas->Clear();
1973 __pDescriptionTextTextObject->SetForegroundColor(__pTokenEdit->GetTitleTextColor(GetCurrentStatus()), 0, __pDescriptionTextTextObject->GetTextLength());
1975 if (IsFocused() == true)
1977 if (__pDescriptionTextTextObject->GetTextLengthAt(0) < __pDescriptionTextTextObject->GetTextLength())
1979 if (titleAction != TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT)
1981 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT);
1982 __pDescriptionTextTextObject->Compose();
1987 if (titleAction != TEXT_OBJECT_ACTION_TYPE_NONE)
1989 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
1990 __pDescriptionTextTextObject->Compose();
1994 if (!__isTitleSliding)
1996 _EditPresenter::StopTitleSlidingTimer();
1997 if (__pDescriptionTextTextObject->IsActionOn() == true)
1999 _EditPresenter::StartTitleSlidingTimer();
2000 __isTitleSliding = true;
2006 if (titleAction != TEXT_OBJECT_ACTION_TYPE_ABBREV)
2008 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
2009 __pDescriptionTextTextObject->Compose();
2014 __pDescriptionTextTextObject->SetBounds(tempDescriptionTextRect);
2015 __pDescriptionTextTextObject->Draw(*_CanvasImpl::GetInstance(*pDescriptionTextCanvas));
2017 delete pDescriptionTextCanvas;
2022 if (__pDescriptionTextVisualElement != null)
2024 __pDescriptionTextVisualElement->Destroy();
2025 __pDescriptionTextVisualElement = null;
2032 _TokenEditPresenter::TrimTokenAndAdjustEllipsisAt(int index)
2034 result r = E_SUCCESS;
2036 float rightMargin = 0.0f;
2037 float tokenMinimumSize = 0.0f;
2039 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2040 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, rightMargin);
2041 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_MIN_WIDTH, orientation, tokenMinimumSize);
2043 _Token* pToken = null;
2044 pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
2045 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
2047 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
2048 FloatRectangle tokenRect = pToken->displayRect;
2050 float remainWidth = tokenEditBounds.width - rightMargin - __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
2052 float dspTokenWidth = tokenRect.x + tokenRect.width;
2053 float dspTokenGap = dspTokenWidth - remainWidth;
2055 if (dspTokenGap > 0.0f)
2057 if (pToken->displayRect.width >= tokenMinimumSize)
2059 if ((pToken->displayRect.width - dspTokenGap) < tokenMinimumSize)
2061 pToken->displayRect.width = tokenMinimumSize;
2065 pToken->displayRect.width -= dspTokenGap;
2070 pToken->pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
2071 pToken->pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
2078 _TokenEditPresenter::GetTokenIndexFromCoordinate(const FloatPoint point) const
2080 int tokenIndex = -1;
2082 int tokenCount = __pTokenList->GetCount();
2083 for (int i = 0; i < tokenCount; i++)
2085 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2088 FloatRectangle tokenRect = pToken->displayRect;
2089 if (tokenRect.Contains(point))
2100 _TokenEditPresenter::SetEditingTokenTextBounds(int index, bool isSetText)
2102 result r = E_SUCCESS;
2104 float tokenHeight = 0.0f;
2105 float tokenVerticalSpacing = 0.0f;
2106 float tokenTextLeftMargin = 0.0f;
2107 float tokenFontSize = 0.0f;
2108 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2110 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
2111 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
2112 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
2113 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_SIZE, orientation, tokenFontSize);
2115 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
2116 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
2118 FloatRectangle tempTextDspRect;
2119 tempTextDspRect.x += tokenTextLeftMargin;
2120 tempTextDspRect.y += tokenVerticalSpacing / 2.0f;
2121 tempTextDspRect.width = pToken->displayRect.width - (tokenTextLeftMargin * 2.0f);
2122 tempTextDspRect.height = tokenHeight - tokenVerticalSpacing;
2126 if (!pToken->isTextCut)
2128 SetText(pToken->GetText());
2130 pToken->pTextObject->RemoveAll(true);
2133 _EditPresenter::SetTextSize(tokenFontSize);
2135 SetTextBounds(tempTextDspRect);
2141 _TokenEditPresenter::RecalculateTokenBounds(float position)
2143 result r = E_SUCCESS;
2145 __scrollValue = -position;
2147 int tokenCount = GetTokenCount();
2148 CalculateTokenPositionFromIndex(0);
2150 for (int i = 0; i < tokenCount; i++)
2152 _Token* pToken = null;
2153 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2157 pToken->SetBounds(pToken->displayRect);
2159 TrimTokenAndAdjustEllipsisAt(i);
2160 InitializeTokenVisibilityAt(i);
2163 if (__pDescriptionTextTextObject->GetTextLength() != 0)
2165 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2168 __pTokenEdit->Invalidate();
2170 r = SetInitialBounds();
2171 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
2177 _TokenEditPresenter::SetTokenBoundsByTouchInfo(const _TouchInfo& touchinfo)
2179 result r = E_SUCCESS;
2180 int currentYPosition = _CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()).y;
2182 if (_FloatCompare(__prevScrollValue, 0.0f))
2184 __prevScrollValue = currentYPosition;
2186 else // Adjust moved y position to all tokens.
2188 if (__isNeedToScroll) // Need to scroll
2190 float tempDefference = __prevScrollValue - currentYPosition;
2192 __prevScrollValue = currentYPosition;
2193 __scrollValue -= tempDefference;
2195 if (__scrollValue < -__maxScrollValue)
2197 __scrollValue = -__maxScrollValue;
2202 if (__scrollValue > 0.0f)
2204 __scrollValue = 0.0f;
2209 int tokenCount = GetTokenCount();
2210 CalculateTokenPositionFromIndex(0);
2211 for (int i = 0; i < tokenCount; i++)
2213 _Token* pToken = null;
2214 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2218 pToken->SetBounds(pToken->displayRect);
2220 TrimTokenAndAdjustEllipsisAt(i);
2221 InitializeTokenVisibilityAt(i);
2224 if (__pDescriptionTextTextObject->GetTextLength() != 0)
2226 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2229 __pTokenEdit->Invalidate();
2233 __prevScrollValue = 0.0f;
2234 __scrollValue = 0.0f;
2238 r = SetInitialBounds();
2239 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
2245 _TokenEditPresenter::ProcessTokeningByTouchEvent(const _Control& source, const _TouchInfo& touchinfo)
2247 int tokenIndex = GetTokenIndexFromCoordinate(touchinfo.GetCurrentPosition());
2249 //Reset "longPressed" when Touch released on a different token after long gesture on a token
2250 if (__trackTokenIndex != tokenIndex)
2252 __isLongPressed = false;
2255 int prevPressedTokenIndex = __pressedTokenIndex;
2256 int prevEditedTokenIndex = __editingTokenIndex;
2258 result r = E_SUCCESS;
2261 if (__isEditModeEnabled && __pressedTokenIndex != -1 && __pressedTokenIndex == tokenIndex)
2263 //Comment below to Block Copy & Paste functionality in Token Edit mode
2264 __editingTokenIndex = __pressedTokenIndex;
2265 __isEditingToken = true;
2266 __isTokenEditingFinished = false;
2267 if (prevEditedTokenIndex != __editingTokenIndex)
2269 SetEditingTokenTextBounds(__editingTokenIndex);
2271 SetCursorDisabled(false);
2275 if (tokenIndex != -1)
2277 if (__isEditingToken && (prevPressedTokenIndex != tokenIndex)) // Selected another token while editing.
2279 __isPopupVisible = false;
2280 __isLongPressed = false;
2282 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2283 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
2285 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2286 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
2288 _Token* pToken = null;
2289 _VisualElement* pTokenVisualElement = null;
2291 pToken = static_cast< _Token* >(__pTokenList->GetAt(prevPressedTokenIndex));
2293 bool isParentChanged = false;
2296 pTokenVisualElement = pToken->GetVisualElement();
2297 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
2299 if (pCursorVisualElement->GetParent() == pTokenVisualElement)
2301 isParentChanged = true;
2302 result r = E_SUCCESS;
2303 r = pTokenVisualElement->DetachChild(*pCursorVisualElement);
2304 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2306 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2307 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2311 String inputTokenString = GetText();
2312 String replacementString = inputTokenString;
2313 bool enable = false;
2315 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
2318 inputTokenString = replacementString;
2321 __pressedTokenIndex = tokenIndex;
2323 r = RemoveTokenAt(prevPressedTokenIndex);
2324 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2326 if (inputTokenString.GetLength() > 0)
2328 r = InsertTokenAt(prevPressedTokenIndex, inputTokenString);
2329 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2331 pToken = static_cast< _Token* >(__pTokenList->GetAt(prevPressedTokenIndex));
2334 pToken->currTokenLength = inputTokenString.GetLength();
2339 //Flex height adjusted since token can move to another line
2340 AdjustFlexibleHeight();
2341 __editingTokenIndex = -1;
2342 __isTokenEditingFinished = true;
2343 __isEditingToken = false;
2344 _EditPresenter::SetTextSize(__editContentFontSize);
2346 SetCursorDisabled(true);
2350 __pressedTokenIndex = tokenIndex;
2351 if (GetText().GetLength() > 0 && __pressedTokenIndex != prevPressedTokenIndex)
2354 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2357 if ((__isEditingToken == true) && (__pressedTokenIndex != -1))
2359 r = AttachCursorToToken();
2360 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2363 if (__isEditingToken == false)
2365 SetCursorDisabled(true);
2371 __isPopupVisible = false;
2372 __isLongPressed = false;
2374 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2375 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
2377 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2378 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
2380 if (__isEditingToken)
2382 _Token* pToken = null;
2383 _VisualElement* pTokenVisualElement = null;
2385 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
2387 bool isParentChanged = false;
2390 pTokenVisualElement = pToken->GetVisualElement();
2391 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
2393 if (pCursorVisualElement->GetParent() == pTokenVisualElement)
2395 isParentChanged = true;
2396 result r = E_SUCCESS;
2397 r = pTokenVisualElement->DetachChild(*pCursorVisualElement);
2398 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2400 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2401 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2405 String inputTokenString = GetText();
2406 String replacementString = inputTokenString;
2407 bool enable = false;
2409 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
2412 inputTokenString = replacementString;
2414 __pressedTokenIndex = tokenIndex;
2416 RemoveTokenAt(__editingTokenIndex);
2418 if (inputTokenString.GetLength() > 0)
2420 InsertTokenAt(__editingTokenIndex, inputTokenString);
2422 if (isParentChanged)
2424 pToken->currTokenLength = inputTokenString.GetLength();
2428 __isEditingToken = false;
2429 __editingTokenIndex = -1;
2430 _EditPresenter::SetTextSize(__editContentFontSize);
2431 __isTokenEditingFinished = false;
2435 //Flex height adjusted since token can move to another line
2436 AdjustFlexibleHeight();
2438 SysTryReturnResult(NID_UI_CTRL, (inputTokenString.GetLength() > 0), E_INVALID_ARG, "Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
2444 __pressedTokenIndex = tokenIndex;
2445 if (pCursorVisualElement->GetParent() != pEditVisualElement)
2447 r = (pCursorVisualElement->GetParent())->DetachChild(*pCursorVisualElement);
2448 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2450 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2451 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2455 SetCursorDisabled(false);
2458 for (int i = 0; i < __pTokenList->GetCount(); i++)
2460 TrimTokenAndAdjustEllipsisAt(i);
2461 InitializeTokenVisibilityAt(i);
2468 _TokenEditPresenter::CheckTokenScrolling(bool scrollToCursorPosition)
2470 bool needToScroll = false;
2471 float tokenTopMargin = 0.0f;
2472 float tokenBottomMargin = 0.0f;
2473 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2475 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
2476 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
2478 int tokenCount = GetTokenCount();
2479 if (tokenCount == 0) // There is no token to scroll
2481 __isNeedToScroll = false;
2482 __maxScrollValue = 0.0f;
2483 __isTokenScrolling = false;
2488 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(tokenCount - 1));
2489 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
2491 float newScrollValue = 0.0f;
2493 if (scrollToCursorPosition)
2495 FloatRectangle cursorBounds;
2496 GetCursorBounds(false, cursorBounds);
2497 newScrollValue = cursorBounds.y + cursorBounds.height - __scrollValue + tokenBottomMargin - __pTokenEdit->GetBoundsF().height;
2498 __isScrollValueModified = true;
2502 newScrollValue = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin - __pTokenEdit->GetBoundsF().height;
2503 __isScrollValueModified = true;
2506 needToScroll = (newScrollValue > 0.0f) ? (true) : (false);
2508 __isNeedToScroll = needToScroll;
2510 if (__isNeedToScroll)
2512 __maxScrollValue = newScrollValue;
2513 __isTokenScrolling = true;
2515 RecalculateTokenBounds(__maxScrollValue);
2519 if (!_FloatCompare(__scrollValue, 0.0f))
2521 __scrollValue = 0.0f;
2522 __maxScrollValue = 0.0f; // To prevent unnecessary token scrolling.
2523 RecalculateTokenBounds(__scrollValue);
2524 __isTokenScrolling = false;
2532 _TokenEditPresenter::SetTokenVisualElementBounds(int index, const FloatRectangle& bounds)
2534 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
2535 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null.");
2537 return pToken->SetBounds(pToken->displayRect);
2541 _TokenEditPresenter::AdjustFlexibleHeight(void)
2543 result r = E_SUCCESS;
2545 FloatRectangle editRect = __pTokenEdit->GetBoundsF();
2546 FloatRectangle displayScrollBounds = GetDisplayScrollBoundsF();
2547 float calcHeight = CalculateFlexibleHeightF();
2549 if (!_FloatCompare(editRect.height, calcHeight))
2551 displayScrollBounds.height = calcHeight;
2552 SetScrollBarBounds(displayScrollBounds);
2554 editRect.height = calcHeight;
2555 if (!__isEditingToken)
2557 FloatRectangle editRectBounds = CoordinateSystem::AlignToDevice(editRect);
2558 r = SetFlexBounds(editRectBounds);
2566 _TokenEditPresenter::CalculateFlexibleHeightF(void)
2568 float tokenHeight = 0.0f;
2569 float tokenVerticalSpacing = 0.0f;
2570 float tokenTopMargin = 0.0f;
2571 float tokenBottomMargin = 0.0f;
2572 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2574 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
2575 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
2576 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
2577 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
2579 float height = 0.0f;
2580 int maxLinecount = GetMaxLineCount();
2581 float expectedEditHeight = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin;
2582 float initialHeight = GetInitialBoundsF().height;
2583 float maximumLineHeight = tokenTopMargin + maxLinecount * tokenHeight + tokenVerticalSpacing * (maxLinecount - 1) + tokenBottomMargin;
2585 if (initialHeight < expectedEditHeight)
2587 if (expectedEditHeight > maximumLineHeight)
2589 height = maximumLineHeight;
2593 height = expectedEditHeight;
2598 height = initialHeight;
2601 FloatDimension flexHeightDim = CoordinateSystem::AlignToDevice(FloatDimension(0, height));
2602 return flexHeightDim.height;
2606 _TokenEditPresenter::DrawScrollBar(void)
2608 result r = E_SUCCESS;
2610 _Scroll* pScroll = GetScrollBar();
2611 if (pScroll == null)
2616 if (IsFocused() == false)
2618 if (__isTouchMoveInProgress == false)
2620 pScroll->SetScrollVisibility(false);
2625 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(GetTokenCount() - 1));
2631 float tokenBottomMargin = 0.0f;
2632 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, tokenBottomMargin);
2634 float totalHeight = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin;
2635 float dspHeight = __pTokenEdit->GetBoundsF().height;
2636 float firstDspY = -__scrollValue;
2638 if (totalHeight <= dspHeight)
2640 pScroll->SetScrollVisibility(false);
2641 pScroll->SetScrollRange(1, 1);
2642 pScroll->SetScrollPosition(0.0f);
2644 SetScrollBarVisible(false);
2645 SetPreviousScrollBarPosition(0.0f);
2646 SetMaximumPreviousScrollBarPosition(0.0f);
2650 if (firstDspY > 0.0f)
2652 pScroll->SetScrollRange(dspHeight, totalHeight);
2653 pScroll->SetScrollPosition(firstDspY);
2654 SetMaximumPreviousScrollBarPosition(totalHeight - dspHeight);
2658 pScroll->SetScrollRange(dspHeight, totalHeight);
2659 pScroll->SetScrollPosition(0.0f);
2660 SetMaximumPreviousScrollBarPosition(0.0f);
2663 if (pScroll->GetScrollVisibility())
2665 SetScrollBarVisible(true);
2668 SetPreviousScrollBarPosition(firstDspY);
2675 _TokenEditPresenter::SetAutoShrinkModeEnabled(bool enable)
2677 __autoShrink = enable;
2681 _TokenEditPresenter::IsAutoShrinkModeEnabled(void) const
2683 return __autoShrink;
2687 _TokenEditPresenter::SetDescriptionText(String descriptionText)
2689 __descriptionText = descriptionText;
2693 _TokenEditPresenter::GetDescriptionText(void) const
2695 return __descriptionText;
2699 _TokenEditPresenter::CalculateVisibleTokenCount(void)
2701 int visibleTokenCount = 0;
2703 FloatRectangle intialBounds = GetInitialBoundsF();
2704 FloatRectangle tempInitialBounds = intialBounds;
2705 FloatRectangle hiddenTokenDisplayBounds;
2706 int tokenCount = GetTokenCount();
2708 for (int i = 0; i < tokenCount; i++)
2710 tempInitialBounds = intialBounds;
2711 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2712 SysTryReturn(NID_UI_CTRL, pToken != null, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
2714 FloatRectangle displayBounds = pToken->displayRect;
2715 if ((tempInitialBounds.y + displayBounds.y) > (tempInitialBounds.y + tempInitialBounds.height))
2719 visibleTokenCount++;
2721 return visibleTokenCount;
2725 _TokenEditPresenter::OnFocusGained(void)
2727 __isTitleSliding = false;
2730 float tempHeight = CalculateFlexibleHeightF();
2731 FloatRectangle tempRect = GetInitialBoundsF();
2732 tempRect.height = tempHeight;
2734 _Token* pToken = null;
2735 int tokenCount = GetTokenCount();
2737 for (int i = 0; i < tokenCount; i++)
2739 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2743 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
2744 if (pTokenVisualElement)
2746 pTokenVisualElement->SetShowState(true);
2751 SetFlexBounds(tempRect);
2753 SetEditingTokenTextBounds(__editingTokenIndex, false);
2757 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2761 if (__isScrollValueChanged && !__isScrollValueModified)
2763 __maxScrollValue = __maxScrollValue - (__pTokenEdit->GetBoundsF().height - GetInitialBoundsF().height);
2764 __isScrollValueChanged = false;
2768 if (GetTokenCount())
2770 CheckTokenScrolling();
2773 TextObject* pTextObject = GetTextObject();
2776 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
2777 pTextObject->Compose();
2780 if (__pressedTokenIndex < 0)
2783 SetCursorDisabled(false);
2787 RefreshAccessibilityElements();
2789 return _EditPresenter::OnFocusGained();
2793 _TokenEditPresenter::OnFocusLost(void)
2795 result r = E_SUCCESS;
2798 _EditPresenter::StopTitleSlidingTimer();
2799 __isTitleSliding = false;
2801 if (__editingTokenIndex >= 0)
2803 _Token* pToken = null;
2804 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
2807 if (GetText().GetLength() > 0)
2809 OnTextCommitted(L"\n");
2813 RemoveTokenAt(__editingTokenIndex, true);
2819 //Remove pressed state on focus lost
2820 __pressedTokenIndex = -1;
2822 if (GetText().GetLength() > 0)
2824 OnTextCommitted(L"\n");
2830 _Scroll* pScroll = GetScrollBar();
2833 pScroll->SetScrollVisibility(false);
2835 __scrollValue = 0.0f;
2837 int tokenCount = GetTokenCount();
2838 _Token* pToken = null;
2839 for (int i = 0; i < tokenCount; i++)
2841 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2844 pToken->SetBounds(pToken->displayRect);
2848 r = SetInitialBounds();
2849 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating", GetErrorMessage(r));
2851 UpdateTokenAccessibilityBounds();
2853 __scrollValue = 0.0f;
2854 r = CalculateTokenPositionFromIndex(0);
2855 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
2857 int visibleTokenCount = CalculateVisibleTokenCount();
2859 for (int i = visibleTokenCount; i < tokenCount; i++)
2861 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
2864 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
2865 if (pTokenVisualElement)
2867 pTokenVisualElement->SetShowState(false);
2872 float totalScrollValue = __maxScrollValue + (__pTokenEdit->GetBoundsF().height - GetInitialBoundsF().height);
2874 if (totalScrollValue > 0)
2876 __isNeedToScroll = true;
2877 __maxScrollValue = totalScrollValue;
2878 __isTokenScrolling = true;
2879 if (__lineAdded > 0)
2881 __isScrollValueChanged = true;
2882 __isScrollValueModified = false;
2886 FloatRectangle intialWindowBounds = GetInitialBoundsF();
2887 SetFlexBounds(intialWindowBounds);
2889 SetEditingTokenTextBounds(__editingTokenIndex, false);
2891 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2894 TextObject* pTextObject = GetTextObject();
2897 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
2898 pTextObject->Compose();
2901 RemoveChildAccessibilityElements();
2902 __pTokenEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
2903 SetDrawFocusState(false);
2905 return _EditPresenter::OnFocusLost();
2909 _TokenEditPresenter::SetFlexBounds(const FloatRectangle& bounds)
2911 if (__pTokenEdit->GetBoundsF().height > bounds.height)
2913 if (__lineAdded > 0)
2918 return _EditPresenter::SetFlexBounds(bounds);
2922 _TokenEditPresenter::SetTextSize(const int size)
2924 result r = E_SUCCESS;
2925 __editContentFontSize = size;
2927 if (!__isEditingToken)
2929 r = _EditPresenter::SetTextSize(size);
2930 r = SetInitialBounds();
2931 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2938 _TokenEditPresenter::SetTextSize(const float size)
2940 result r = E_SUCCESS;
2941 __editContentFontSize = size;
2943 if (!__isEditingToken)
2945 r = _EditPresenter::SetTextSize(size);
2946 r = SetInitialBounds();
2947 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2954 _TokenEditPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
2956 //Remove token focus on touch press
2957 __focusedTokenIndex = -1;
2959 int tokenIndex = GetTokenIndexFromCoordinate(touchinfo.GetCurrentPosition());
2960 __trackTokenIndex = tokenIndex;
2962 _TouchInfo TouchInfo(touchinfo);
2963 if (tokenIndex != -1)
2965 if (tokenIndex == __editingTokenIndex)
2967 __touchPressInfo.x = touchinfo.GetCurrentPosition().x;
2968 __touchPressInfo.y = touchinfo.GetCurrentPosition().y;
2970 _Token* pToken = null;
2971 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
2974 float tokenX = pToken->displayRect.x;
2975 float tokenY = pToken->displayRect.y;
2976 FloatPoint point(__touchPressInfo.x - tokenX, __touchPressInfo.y - tokenY);
2977 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
2982 return _EditPresenter::OnTouchPressed(source, TouchInfo);
2986 _TokenEditPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
2988 __touchPressInfo = FloatPoint(-1.0f, -1.0f);
2990 ProcessTokeningByTouchEvent(source, touchinfo);
2991 if (GetTokenCount())
2993 //Set token bounds appropriately On Fast flick of scroll bar
2994 if (!(__isEditingToken || __editingTokenIndex >= 0))
2996 SetTokenBoundsByTouchInfo(touchinfo);
3000 _Scroll* pScroll = GetScrollBar();
3003 pScroll->SetScrollVisibility(false);
3006 if (__prevScrollValue)
3008 __prevScrollValue = 0.0f;
3009 __isTokenScrolling = false;
3012 _TouchInfo TouchInfo(touchinfo);
3013 _Token* pToken = null;
3014 if (__editingTokenIndex >= 0)
3016 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3019 int tokenX = _CoordinateSystemUtils::ConvertToInteger(pToken->displayRect.x);
3020 int tokenY = _CoordinateSystemUtils::ConvertToInteger(pToken->displayRect.y);
3021 Point point(_CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()).x - tokenX, _CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()).y - tokenY);
3022 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
3024 _EditPresenter::OnTouchReleased(source, TouchInfo);
3025 __previousCursorPosition = GetCursorPosition();
3029 _EditPresenter::OnTouchReleased(source, touchinfo);
3032 __isTouchMoveInProgress = false;
3033 __trackTokenIndex = -1;
3039 _TokenEditPresenter::OnInputConnectionTextCommitted(InputConnection& source, const String& committedText)
3041 OnTextCommitted(committedText);
3045 _TokenEditPresenter::OnTextCommitted(const String& commitText)
3047 char enterText[2] = {'\n', };
3048 String enterTextComma(",");
3049 String enterTextSemiColon(";");
3051 //OnTextCommitted blocked for these cases
3052 //1. Tab text not to be handled
3053 //2. Token is focused
3054 char tapText[2] = {'\t', };
3055 if (commitText == tapText)
3060 if ((commitText == enterText) || (commitText == enterTextComma) || (commitText == enterTextSemiColon))
3062 CoreKeypadAction keypadaction = GetKeypadAction();
3063 __pTokenEdit->SendKeypadEvent(keypadaction, CORE_KEYPAD_EVENT_STATUS_ENTERACTION);
3065 if (__editingTokenIndex != -1)
3067 ExitTokenEditingMode();
3070 if (GetText().GetLength() > 0)
3075 for (int i = 0; i < __pTokenList->GetCount(); i++)
3077 TrimTokenAndAdjustEllipsisAt(i);
3078 InitializeTokenVisibilityAt(i);
3081 if (__pressedTokenIndex < 0 && __focusedTokenIndex < 0)
3083 SetCursorDisabled(true);
3084 __pTokenEdit->Draw();
3085 SetCursorDisabled(false);
3088 // when pressed enter while editing a token, set cursor as global focused element.
3089 _AccessibilityElement* pCursorAccessibilityElement = __pTokenEdit->GetCursorAccessibilityElement();
3090 if (pCursorAccessibilityElement && __accessibilityFocusIn)
3092 _AccessibilityManager* pAccessibilityManager = _AccessibilityManager::GetInstance();
3093 pAccessibilityManager->SetGlobalFocusedElement(*pCursorAccessibilityElement);
3094 pAccessibilityManager->RequestToDrawFocusUi();
3100 _EditPresenter::OnTextCommitted(commitText);
3101 __previousCursorPosition = GetCursorPosition();
3103 _Token* pToken = null;
3104 if (__editingTokenIndex >= 0)
3106 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3107 SysTryReturnVoidResult(NID_UI_CTRL, pToken, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
3109 pToken->ResetToken(GetText());
3110 TrimTokenAndAdjustEllipsisAt(__editingTokenIndex);
3112 float tokenHeight = 0.0f;
3113 float tokenVerticalSpacing = 0.0f;
3114 float tokenTextLeftMargin = 0.0f;
3116 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3117 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
3118 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
3119 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
3121 FloatRectangle tempTextDspRect;
3122 tempTextDspRect.x += tokenTextLeftMargin;
3123 tempTextDspRect.y += tokenVerticalSpacing / 2.0f;
3124 tempTextDspRect.width = pToken->displayRect.width - (tokenTextLeftMargin * 2.0f);
3125 tempTextDspRect.height = tokenHeight - tokenVerticalSpacing;
3127 SetTextBounds(tempTextDspRect);
3129 if (GetCursorPosition() > pToken->currTokenLength)
3131 _EditPresenter::SetCursorPosition(pToken->currTokenLength);
3135 _EditPresenter::SetCursorPosition(GetCursorPosition());
3140 if (__isEditingToken == false)
3142 __pressedTokenIndex = -1;
3143 __focusedTokenIndex = -1;
3144 SetCursorDisabled(false);
3147 float tokenTopMargin = 0.0f;
3148 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3149 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
3151 FloatRectangle textBounds = GetTextBoundsF();
3152 textBounds.height = GetMaxTextHeight();
3153 SetTextBounds(textBounds);
3156 if (__editingTokenIndex < 0)
3158 CheckTokenScrolling();
3160 __pTokenEdit->Invalidate();
3166 _TokenEditPresenter::DeleteSurroundingText(InputConnection& source, int offset, int charCount)
3168 OnSurroundingTextDeleted(offset, charCount);
3172 _TokenEditPresenter::OnSurroundingTextDeleted(int offset, int charCount)
3174 __lastTokenIndex = GetTokenCount() - 1;
3175 int cursorPosition = 0;
3179 if ((offset == -1) && (charCount == 1))
3181 if (GetTextLength() == 0 && GetTokenCount()) // There is no candidate token.
3183 if (__isEditingToken == true)
3185 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3186 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3188 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3189 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3191 _Token* pToken = null;
3192 _VisualElement* pTokenVisualElement = null;
3194 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3198 pTokenVisualElement = pToken->GetVisualElement();
3199 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3201 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3203 result r = E_SUCCESS;
3204 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3205 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3207 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3208 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3212 RemoveTokenAt(__editingTokenIndex);
3214 CalculateTokenPositionFromIndex(__editingTokenIndex);
3215 for (int i = __editingTokenIndex; i < __lastTokenIndex + 1; i++)
3217 _Token* pToken = null;
3218 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
3221 pToken->SetBounds(pToken->displayRect);
3225 __pressedTokenIndex = -1;
3226 __editingTokenIndex = -1;
3227 __isEditingToken = false;
3228 _EditPresenter::SetTextSize(__editContentFontSize);
3229 __isTokenEditingFinished = false;
3231 AdjustFlexibleHeight();
3232 CheckTokenScrolling();
3234 else if (__pressedTokenIndex != -1)
3236 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3237 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3239 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3240 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3242 _Token* pToken = null;
3243 _VisualElement* pTokenVisualElement = null;
3245 pToken = static_cast< _Token* >(__pTokenList->GetAt(__pressedTokenIndex));
3249 pTokenVisualElement = pToken->GetVisualElement();
3250 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3252 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3254 result r = E_SUCCESS;
3255 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3256 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3258 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3259 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3263 RemoveTokenAt(__pressedTokenIndex);
3265 CalculateTokenPositionFromIndex(__pressedTokenIndex);
3266 for (int i = __pressedTokenIndex; i < __lastTokenIndex + 1; i++)
3268 _Token* pToken = null;
3269 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
3273 pToken->SetBounds(pToken->displayRect);
3278 else if (__focusedTokenIndex != -1)
3280 RemoveTokenAt(__focusedTokenIndex);
3284 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3285 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3287 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3288 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3290 _Token* pToken = null;
3291 _VisualElement* pTokenVisualElement = null;
3293 if (__animatingIndex == (GetTokenCount() - 1))
3295 pToken = static_cast< _Token* >(__pTokenList->GetAt(GetTokenCount() - 1));
3298 pTokenVisualElement = pToken->GetVisualElement();
3299 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3300 pTokenVisualElement->RemoveAllAnimations();
3304 pToken = static_cast< _Token* >(__pTokenList->GetAt(GetTokenCount() - 1));
3307 pTokenVisualElement = pToken->GetVisualElement();
3308 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3310 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3312 result r = E_SUCCESS;
3313 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3314 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3316 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3317 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3321 __animatingIndex = GetTokenCount() - 1;
3323 if (pTokenVisualElement && __animatingIndex >= 0)
3325 __isAnimationInProgress = true;
3326 PerformRemoveTokenAnimation(*pTokenVisualElement);
3330 __pTokenEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
3333 __pTokenEdit->Invalidate();
3338 if (__pressedTokenIndex >= 0 && __editingTokenIndex < 0 && !__isEditingToken)
3340 RemoveTokenAt(__pressedTokenIndex);
3341 __pTokenEdit->Invalidate();
3344 else if (__focusedTokenIndex >= 0 && __editingTokenIndex < 0 && !__isEditingToken)
3346 RemoveTokenAt(__focusedTokenIndex);
3347 __pTokenEdit->Invalidate();
3351 //Backspace on Blocked text, delete full block
3352 if (IsBlocked() == true)
3354 GetBlockRange(start, end);
3358 cursorPosition = GetCursorPosition();
3359 start = cursorPosition + offset;
3364 end = start + charCount;
3365 if (end > GetTextLength())
3371 DeleteText(start, end);
3372 __previousCursorPosition = start;
3374 if (IsCopyPasteManagerExist())
3376 InitializeCopyPasteManager();
3378 if (IsBlocked() == true)
3382 if (__isEditingToken != true)
3387 __pTokenEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
3390 cursorPosition = GetCursorPosition();
3391 start = cursorPosition + offset;
3396 end = start + charCount;
3397 if (end > GetTextLength())
3402 Rectangle currBounds = __pTokenEdit->GetBounds();
3403 DeleteText(start, end);
3404 __previousCursorPosition = start;
3405 if (__isEditingToken != true)
3411 _Token* pToken = null;
3413 if (__editingTokenIndex >= 0 && __isEditingToken)
3415 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3419 float tokenHeight = 0.0f;
3420 float tokenVerticalSpacing = 0.0f;
3421 float tokenTextLeftMargin = 0.0f;
3423 SetCursorPosition(__previousCursorPosition);
3425 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3426 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
3427 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
3428 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
3430 FloatRectangle tempTextDspRect;
3431 tempTextDspRect.x += tokenTextLeftMargin;
3432 tempTextDspRect.y += tokenVerticalSpacing / 2.0f;
3433 tempTextDspRect.width = pToken->displayRect.width - (tokenTextLeftMargin * 2.0f);
3434 tempTextDspRect.height = tokenHeight - tokenVerticalSpacing;
3436 SetTextBounds(tempTextDspRect);
3437 _EditPresenter::SetCursorPosition(start);
3439 pToken->ResetToken(GetText());
3440 TrimTokenAndAdjustEllipsisAt(__editingTokenIndex);
3444 __pTokenEdit->Draw();
3448 _TokenEditPresenter::OnTapGestureDetected(void)
3450 if (__editingTokenIndex >= 0)
3452 __isPopupVisible = true;
3455 //Uncomment below to Block Copy & Paste functionality in Token Edit mode
3456 if (__pressedTokenIndex != -1)
3460 return _EditPresenter::OnTapGestureDetected();
3464 _TokenEditPresenter::CheckCopyPastePopupShowStatus(void)
3466 if (__editingTokenIndex < 0)
3468 float controlHeight = __pTokenEdit->GetBoundsF().height;
3469 FloatRectangle cursorBounds;
3470 GetCursorBounds(false, cursorBounds);
3471 if (cursorBounds.y > controlHeight)
3481 _TokenEditPresenter::OnLongPressGestureDetected(void)
3483 if (CheckCopyPastePopupShowStatus())
3485 //TextBounds bigger than control height. Dont show Copy paste popup
3489 //Discard all long press that is detected after Touch press on a token
3490 if (__trackTokenIndex >= 0)
3495 __isLongPressed = true;
3497 //Uncomment below to Block Copy & Paste functionality in Token Edit mode
3498 if (__pressedTokenIndex != -1)
3502 return _EditPresenter::OnLongPressGestureDetected();
3506 _TokenEditPresenter::OnCursorTimerExpired(void)
3508 if (__editingTokenIndex != -1)
3516 FloatRectangle cursorRect;
3518 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3519 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
3521 //Set Editing token bounds for text scroll and cursor position calculation (SetTextBounds should have been done prior to this)
3522 FloatRectangle cursorDspRect = _EditPresenter::GetTextBoundsF();
3524 if (CalculateCursorBounds(cursorDspRect, cursorRect) != E_SUCCESS)
3530 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3531 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3533 Canvas* pCursorCanvas = pCursorVisualElement->GetCanvasN();
3534 SysTryReturnVoidResult(NID_UI_CTRL, pCursorCanvas != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get canvas of cursor visual element.");
3536 bool cursorEnable = IsCursorEnabled();
3538 pCursorVisualElement->SetBounds(cursorRect);
3539 DrawCursor(*pCursorCanvas, cursorRect, cursorEnable);
3543 cursorEnable = false;
3547 cursorEnable = true;
3549 SetCursorEnabled(cursorEnable);
3551 pCursorCanvas->Show();
3552 delete pCursorCanvas;
3558 _EditPresenter::OnCursorTimerExpired();
3563 _TokenEditPresenter::IsTextBlockedInTokenEdit(void) const
3565 if ((IsBlocked() == true) && (__isEditingToken) && (__editingTokenIndex >= 0))
3573 _TokenEditPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
3575 __isTouchMoveInProgress = true;
3577 if (GetTokenCount())
3579 //Scrolling is blocked when a popup is visible or when a text is blocked
3580 if (IsBlocked() == true || __isLongPressed == true)
3585 //Allow touch move only in horizontal direction when editing token
3586 _TouchInfo TouchInfo(touchinfo);
3587 _Token* pToken = null;
3588 if (__editingTokenIndex >= 0)
3590 if (__touchPressInfo.y > 0.0f)
3592 pToken = static_cast< _Token* >(__pTokenList->GetAt(__editingTokenIndex));
3595 float tokenX = pToken->displayRect.x;
3596 float tokenY = pToken->displayRect.y;
3597 FloatPoint point(touchinfo.GetCurrentPosition().x - tokenX, __touchPressInfo.y - tokenY);
3598 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
3601 bool retValue = _EditPresenter::OnTouchMoved(source, TouchInfo);
3602 __previousCursorPosition = GetCursorPosition();
3612 SetTokenBoundsByTouchInfo(touchinfo);
3614 if (!(__pTokenEdit->GetEditStyle() & EDIT_STYLE_NOSCROLL))
3616 _Scroll* pScroll = GetScrollBar();
3619 float tokenBottomMargin = 0.0f;
3620 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, tokenBottomMargin);
3622 float totalHeight = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin;
3623 float controlHeight = __pTokenEdit->GetBoundsF().height;
3625 if (totalHeight > controlHeight)
3627 pScroll->SetScrollVisibility(true);
3631 pScroll->SetScrollVisibility(false);
3636 return _EditPresenter::OnTouchMoved(source, touchinfo);
3640 return _EditPresenter::OnTouchMoved(source, touchinfo);
3646 _TokenEditPresenter::OnVisualElementAnimationFinished(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, bool completedNormally)
3648 __isAnimationInProgress = false;
3649 RemoveTokenAt(GetTokenCount() - 1);
3650 CalculateTokenPositionFromIndex(GetTokenCount() - 1);
3652 for (int i = GetTokenCount() - 1; i < GetTokenCount() - 1 + 1; i++)
3654 _Token* pToken = null;
3655 pToken = static_cast< _Token* >(__pTokenList->GetAt(i));
3659 pToken->SetBounds(pToken->displayRect);
3663 if (__lastTokenIndex == __pressedTokenIndex)
3665 __pressedTokenIndex--;
3668 if (GetTokenCount() == 0 && __animatingIndex == 0)
3672 __animatingIndex = -1;
3677 __pTokenEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
3683 _TokenEditPresenter::OnTickOccurred(const Tizen::Ui::Animations::VisualElementAnimation& animation, const Tizen::Base::String& keyName, Tizen::Ui::Animations::VisualElement& target, const Tizen::Ui::Variant& currentValue)
3685 VisualElementValueAnimation* pAnimation = dynamic_cast< VisualElementValueAnimation* >(const_cast< VisualElementAnimation* >(&animation));
3686 VisualElement* pPresentation = const_cast< VisualElement* >(target.AcquirePresentationInstance());
3688 if (pPresentation && pAnimation)
3693 diffX = pPresentation->GetBounds().x;
3694 diffY = pPresentation->GetBounds().y;
3696 Variant newBounds(FloatRectangle(diffX, diffY, currentValue.ToFloatRectangle().width, currentValue.ToFloatRectangle().height));
3697 _VisualElementImpl::GetInstance(*pPresentation)->SetProperty(VePropBounds, newBounds);
3701 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Failed to get presentation instance of visual element.");
3704 target.ReleasePresentationInstance();
3708 _TokenEditPresenter::OnTimerExpired(Timer& timer)
3710 Timer* onTimer = &timer;
3711 Canvas* pDescriptionTextCanvas = null;
3713 if (onTimer == _EditPresenter::__pTitleSlidingTimer)
3717 _EditPresenter::StopTitleSlidingTimer();
3718 __isTitleSliding = false;
3722 FloatRectangle tempDescriptionTextRect = __descriptionTextRect;
3723 tempDescriptionTextRect.x = 0.0f;
3724 tempDescriptionTextRect.y = 0.0f;
3726 pDescriptionTextCanvas = __pDescriptionTextVisualElement->GetCanvasN();
3727 SysTryReturnVoidResult(NID_UI_CTRL, pDescriptionTextCanvas, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pDescriptionTextCanvas is invalid!");
3729 pDescriptionTextCanvas->SetBackgroundColor(Color(0));
3730 pDescriptionTextCanvas->Clear();
3731 __pDescriptionTextTextObject->SetBounds(tempDescriptionTextRect);
3732 __pDescriptionTextTextObject->DrawWithOffset(*_CanvasImpl::GetInstance(*pDescriptionTextCanvas));
3733 Rectangle descriptionTextRect = _CoordinateSystemUtils::ConvertToInteger(tempDescriptionTextRect);
3734 pDescriptionTextCanvas->Show(descriptionTextRect);
3736 delete pDescriptionTextCanvas;
3738 _EditPresenter::StartTitleSlidingTimer();
3739 __isTitleSliding = true;
3743 _EditPresenter::OnTimerExpired(timer);
3748 _TokenEditPresenter::ChangeInternalLayout(_ControlOrientation orientation)
3750 result r = E_SUCCESS;
3752 __scrollValue = 0.0f;
3753 __maxScrollValue = 0.0f;
3754 float tokenBottomMargin = 0.0f;
3755 float newScrollValue = 0.0f;
3757 FloatRectangle windowBounds = GetInitialBoundsF();
3759 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
3761 r = CalculateTokenPositionFromIndex(0);
3762 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3764 r = SetInitialBounds();
3765 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3767 if (__isEditingToken)
3769 if (__editingTokenIndex >= 0 && __editingTokenIndex < GetTokenCount())
3771 String inputTokenString = GetText();
3772 String replacementString = inputTokenString;
3773 bool enable = false;
3775 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
3778 inputTokenString = replacementString;
3781 if (inputTokenString.GetLength() > 0)
3783 int index = __editingTokenIndex;
3784 RemoveTokenAt(__editingTokenIndex, true);
3785 InsertTokenAt(index, inputTokenString);
3790 if (__pTokenEdit->IsAttachedToMainTree() && IsFocused())
3792 r = AdjustFlexibleHeight();
3793 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3795 r = CheckTokenScrolling();
3796 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3802 r = AdjustFlexibleHeight();
3803 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3805 windowBounds = __pTokenEdit->GetBoundsF();
3808 newScrollValue = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin - windowBounds.height;
3809 if (newScrollValue > 0.0f)
3811 __maxScrollValue = newScrollValue;
3812 __isNeedToScroll = true;
3820 _TokenEditPresenter::ChangeLayout(_ControlOrientation orientation)
3822 result r = E_SUCCESS;
3824 r = _EditPresenter::ChangeLayout(orientation);
3825 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3827 r = ChangeInternalLayout(orientation);
3833 _TokenEditPresenter::OnBoundsChanged(void)
3835 if (!__isTokenEditPresenterInitialized)
3840 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3841 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
3843 if (IsUpdateInitialBounds())
3845 SetControlInitialBounds(tokenEditBounds);
3847 ChangeInternalLayout(orientation);
3849 __pTokenEdit->UpdateAccessibilityElement(EDIT_ACCESSIBILITY_ELEMENT_TYPE_TEXT);
3855 _TokenEditPresenter::AttachCursorToToken(void)
3857 result r = E_SUCCESS;
3859 if (__pressedTokenIndex != -1)
3861 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3862 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
3864 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3865 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
3867 _Token* pToken = null;
3868 _VisualElement* pTokenVisualElement = null;
3870 pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
3873 pTokenVisualElement = pToken->GetVisualElement();
3874 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
3876 if (pCursorVisualElement->GetParent() != pTokenVisualElement)
3878 r = (pCursorVisualElement->GetParent())->DetachChild(*pCursorVisualElement);
3879 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3881 r = pTokenVisualElement->AttachChild(*pCursorVisualElement);
3882 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3891 _TokenEditPresenter::DetachCursorFromToken(void)
3893 result r = E_SUCCESS;
3895 if (__pressedTokenIndex != -1)
3897 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3898 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3900 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3901 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3903 _Token* pToken = null;
3904 _VisualElement* pTokenVisualElement = null;
3906 pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
3910 pTokenVisualElement = pToken->GetVisualElement();
3911 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3913 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3915 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3916 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
3918 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3919 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
3927 _TokenEditPresenter::ExitTokenEditingMode(void)
3929 result r = E_SUCCESS;
3931 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3932 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3934 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3935 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3937 _Token* pToken = null;
3938 _VisualElement* pTokenVisualElement = null;
3940 pToken = static_cast <_Token*>(__pTokenList->GetAt(__editingTokenIndex));
3944 pTokenVisualElement = pToken->GetVisualElement();
3945 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3947 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3949 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3950 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
3952 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3953 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
3957 String inputTokenString = GetText();
3958 String replacementString = inputTokenString;
3959 bool enable = false;
3961 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
3964 inputTokenString = replacementString;
3967 r = RemoveTokenAt(__editingTokenIndex);
3969 _EditPresenter::SetTextSize(__editContentFontSize);
3970 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3972 if (inputTokenString.GetLength() > 0)
3974 r = InsertTokenAt(__editingTokenIndex, inputTokenString);
3975 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3977 pToken = static_cast <_Token*>(__pTokenList->GetAt(__editingTokenIndex));
3978 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3980 pToken->currTokenLength = inputTokenString.GetLength();
3983 CalculateTokenPositionFromIndex(0);
3984 int lastTokenIndex = GetTokenCount() - 1;
3985 for (int i = 0; i < lastTokenIndex + 1; i++)
3987 _Token* pToken = null;
3988 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3992 pToken->SetBounds(pToken->displayRect);
3996 AdjustFlexibleHeight();
3997 __pressedTokenIndex = -1;
3998 __isTokenEditingFinished = true;
3999 __editingTokenIndex = -1;
4000 __isEditingToken = false;
4002 CheckTokenScrolling();
4003 SetCursorDisabled(false);
4005 if (inputTokenString.GetLength() <= 0)
4007 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
4014 _TokenEditPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
4016 _KeyCode keyCode = keyInfo.GetKeyCode();
4017 bool focusChanged = false;
4018 int tokenCount = GetTokenCount();
4019 int lastTokenIndex = tokenCount - 1;
4021 if (IsUsbKeyboardConnected() && (keyInfo.GetKeyModifier() & _KEY_MODIFIER_CTRL))
4029 if (__isEditingToken)
4040 if ((keyCode == _KEY_NUM_LEFT) || (keyCode == _KEY_LEFT))
4042 if (__drawFocusState && (!__isEditingToken) && (tokenCount > 0))
4044 if (__focusedTokenIndex == -1)
4046 if (GetCursorPosition() == 0)
4048 __focusedTokenIndex = lastTokenIndex;
4049 if (GetTextLength() > 0)
4053 SetCursorDisabled(true);
4054 __pTokenEdit->Invalidate();
4058 return _EditPresenter::OnKeyPressed(source, keyInfo);
4060 focusChanged = true;
4065 if (__focusedTokenIndex > 0)
4067 __focusedTokenIndex--;
4068 focusChanged = true;
4074 if ((keyCode == _KEY_NUM_RIGHT) || (keyCode == _KEY_RIGHT))
4076 if (__drawFocusState && (!__isEditingToken) && (tokenCount > 0))
4078 if (__focusedTokenIndex != -1)
4080 if (__focusedTokenIndex == lastTokenIndex)
4082 __focusedTokenIndex = -1;
4083 focusChanged = true;
4087 __focusedTokenIndex++;
4088 focusChanged = true;
4098 if (__focusedTokenIndex != -1)
4100 SetCursorDisabled(true);
4101 ScrollToFocusedToken();
4105 SetCursorDisabled(false);
4106 CheckTokenScrolling();
4112 return _EditPresenter::OnKeyPressed(source, keyInfo);
4116 _TokenEditPresenter::GetTextAccessibilityElementText(void) const
4119 String spaceText = " ";
4120 _Token* pToken = null;
4121 int tokenCount = GetTokenCount();
4122 static const int readTokenCount = 2;
4125 for (int index = 0; index < readTokenCount; index++)
4127 pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
4128 SysTryReturn(NID_UI_CTRL, pToken, tokenText, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4130 if (index < (readTokenCount - 1))
4132 tokenText += pToken->GetText() + spaceText;
4136 String moreTokenText;
4137 int moreTokenCount = tokenCount - readTokenCount;
4138 if (moreTokenCount > 0)
4140 moreTokenText.Format(15, L"and %d more", moreTokenCount);
4142 tokenText += pToken->GetText() + spaceText + moreTokenText;
4150 _TokenEditPresenter::RefreshAccessibilityElements(void)
4152 RemoveChildAccessibilityElements();
4153 AddChildAccessibilityElements();
4159 _TokenEditPresenter::AddChildAccessibilityElements(void)
4161 //Accessibility Elements added to the container upon focus gained
4164 //3. __accessibilityElements 0 - title 1 - token 0
4166 result r = E_SUCCESS;
4167 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4169 __pTokenEdit->AddTitleAccessibilityElement();
4170 int tokenCount = GetTokenCount();
4172 for (int index = 0; index < tokenCount; index++)
4174 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
4175 SysTryReturn(NID_UI_CTRL, pToken != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4179 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
4180 SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4182 String labelText = pToken->GetText();
4183 pAccessibilityElement->SetBounds(pToken->displayRect);
4184 pAccessibilityElement->SetLabel(labelText);
4185 pContainer->AddElement(*pAccessibilityElement);
4186 __accessibilityElements.Add(pAccessibilityElement);
4190 __pTokenEdit->AddCursorAccessibilityElement();
4196 _TokenEditPresenter::RemoveChildAccessibilityElements(void)
4198 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4199 _AccessibilityElement* pAccessibilityElement = null;
4201 __pTokenEdit->RemoveTitleAccessibilityElement();
4203 while (__accessibilityElements.GetCount() > 0)
4205 if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS)
4207 __accessibilityElements.RemoveAt(0);
4208 pContainer->RemoveElement(*pAccessibilityElement);
4212 __pTokenEdit->RemoveCursorAccessibilityElement();
4218 _TokenEditPresenter::AppendTokenAccessibilityElement(void)
4220 result r = E_SUCCESS;
4221 int tokenCount = GetTokenCount();
4223 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4225 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(tokenCount - 1));
4226 SysTryReturn(NID_UI_CTRL, pToken != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4230 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
4231 SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4233 String labelText = pToken->GetText();
4234 pAccessibilityElement->SetBounds(pToken->displayRect);
4235 pAccessibilityElement->SetLabel(labelText);
4236 pAccessibilityElement->SetHint(L"double tap to edit");
4237 pContainer->AddElement(*pAccessibilityElement);
4238 __accessibilityElements.Add(pAccessibilityElement);
4245 _TokenEditPresenter::InsertTokenAccessibilityElementAt(int index)
4247 result r = E_SUCCESS;
4249 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4250 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
4251 SysTryReturn(NID_UI_CTRL, pToken != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4255 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
4256 SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4258 String labelText = pToken->GetText();
4259 pAccessibilityElement->SetBounds(pToken->displayRect);
4260 pAccessibilityElement->SetLabel(labelText);
4261 pContainer->InsertElement(*pAccessibilityElement, index);
4262 __accessibilityElements.InsertAt(pAccessibilityElement, index);
4269 _TokenEditPresenter::RemoveTokenAccessibilityElementAt(int index)
4271 _AccessibilityContainer* pContainer = __pTokenEdit->GetAccessibilityContainer();
4272 _AccessibilityElement* pAccessibilityElement = null;
4276 if (__accessibilityElements.GetCount() > 0)
4278 if ((__accessibilityElements.GetAt(index, pAccessibilityElement)) == E_SUCCESS)
4280 __accessibilityElements.RemoveAt(index);
4281 pContainer->RemoveElement(*pAccessibilityElement);
4289 _TokenEditPresenter::UpdateTokenAccessibilityBounds(void)
4291 result r = E_SUCCESS;
4292 int tokenCount = GetTokenCount();
4293 _AccessibilityElement* pAccessibilityElement = null;
4295 for (int index = 0; index < tokenCount; index++)
4297 _Token* pToken = static_cast< _Token* >(__pTokenList->GetAt(index));
4298 SysTryReturn(NID_UI_CTRL, pToken != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
4300 if ((__accessibilityElements.GetAt(index, pAccessibilityElement)) == E_SUCCESS)
4302 if (pAccessibilityElement)
4304 pAccessibilityElement->SetBounds(pToken->displayRect);
4312 _TokenEditPresenter::UpdateTitleAccessibilityBounds(const FloatRectangle& titleBounds)
4314 _AccessibilityElement* pTitleAccessibilityElement = __pTokenEdit->GetTitleTextAccessibilityElement();
4316 if (!pTitleAccessibilityElement)
4321 pTitleAccessibilityElement->SetBounds(titleBounds);
4327 _TokenEditPresenter::ScrollToFocusedTokenAccessibilityElement(const _AccessibilityElement& element)
4329 result r = E_SUCCESS;
4330 int focusedTokenIndex = -1;
4331 int tokenCount = GetTokenCount();
4332 FloatRectangle focusedTokenRectangle;
4333 float newScrollValue = 0.0f;
4334 float tokenTopMargin = 0.0f;
4335 float tokenBottomMargin = 0.0f;
4336 float tokenHeight = 0.0f;
4337 float textBoundsAlignValue = 0.0f;
4338 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
4339 _AccessibilityElement* pAccessibilityElement = null;
4341 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
4342 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
4343 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
4345 FloatRectangle tokenEditRect = __pTokenEdit->GetBoundsF();
4346 float textObjectMaxHeight = GetMaxTextHeight();
4347 textBoundsAlignValue = (tokenHeight - textObjectMaxHeight) / 2.0f;
4349 pAccessibilityElement = const_cast< _AccessibilityElement* >(&element);
4350 r = __accessibilityElements.IndexOf(pAccessibilityElement, focusedTokenIndex);
4351 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
4353 if ((focusedTokenIndex > -1) && (focusedTokenIndex < tokenCount))
4355 _Token* pToken = null;
4356 pToken = static_cast< _Token* >(__pTokenList->GetAt(focusedTokenIndex));
4357 r = GetLastResult();
4358 SysTryReturnResult(NID_UI_CTRL, pToken != null, r, "Propagating.");
4360 focusedTokenRectangle = pToken->displayRect;
4362 float focusedTokenPosition = focusedTokenRectangle.y + focusedTokenRectangle.height;
4364 if ((focusedTokenRectangle.y > 0) && (focusedTokenPosition < tokenEditRect.height))
4370 if (focusedTokenRectangle.y < 0)
4372 newScrollValue = focusedTokenRectangle.y - tokenTopMargin - __scrollValue;
4376 newScrollValue = focusedTokenPosition - textBoundsAlignValue - tokenEditRect.height + tokenBottomMargin - __scrollValue;
4379 r = RecalculateTokenBounds(newScrollValue);
4380 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
4383 r = __accessibilityElements.GetAt(focusedTokenIndex, pAccessibilityElement);
4384 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
4386 _AccessibilityManager* pAccessibilityManager = _AccessibilityManager::GetInstance();
4387 pAccessibilityManager->SetGlobalFocusedElement(*pAccessibilityElement);
4388 pAccessibilityManager->RequestToDrawFocusUi();
4395 _TokenEditPresenter::ScrollToTitleAccessibilityElement(void)
4397 _AccessibilityElement* pTitleAccessibilityElement = __pTokenEdit->GetTitleTextAccessibilityElement();
4398 if (pTitleAccessibilityElement)
4400 FloatRectangle titleTextBounds = pTitleAccessibilityElement->GetBounds();
4401 if (titleTextBounds.y < 0)
4403 float tokenTopMargin = 0.0f;
4404 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
4405 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
4406 float newScrollValue = titleTextBounds.y - tokenTopMargin - __scrollValue;
4407 result r = RecalculateTokenBounds(newScrollValue);
4408 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
4416 _TokenEditPresenter::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
4418 result r = E_SUCCESS;
4419 _AccessibilityElement* pTitleAccessibilityElement = __pTokenEdit->GetTitleTextAccessibilityElement();
4421 __accessibilityFocusIn = true;
4423 if (__focusOutIndex < 0) // Not a token accessibility element
4425 if (pTitleAccessibilityElement != &element)
4431 _Token* pToken = null;
4432 _AccessibilityElement* pCurrentElement = const_cast< _AccessibilityElement* >(&element);
4433 _AccessibilityElement* pPreviousAccessibilityElement = null;
4434 _AccessibilityElement* pNextAccessibilityElement = null;
4435 if (pTitleAccessibilityElement == &element)
4437 ScrollToTitleAccessibilityElement();
4438 UpdateTokenAccessibilityBounds();
4441 r = __accessibilityElements.GetAt(__focusOutIndex, pPreviousAccessibilityElement);
4442 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
4444 if (pPreviousAccessibilityElement && pPreviousAccessibilityElement->GetAbsoluteBounds().y > element.GetAbsoluteBounds().y) //Left flick
4446 pToken = static_cast< _Token* >(__pTokenList->GetAt(__focusOutIndex - 1));
4449 if (pToken->displayRect.y < 0.0f && __focusOutIndex > 0)
4451 r = __accessibilityElements.GetAt(__focusOutIndex - 1, pNextAccessibilityElement);
4452 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
4454 ScrollToFocusedTokenAccessibilityElement(*pNextAccessibilityElement);
4459 if (pPreviousAccessibilityElement && pPreviousAccessibilityElement->GetAbsoluteBounds().y < element.GetAbsoluteBounds().y) //Right flick
4461 pToken = static_cast< _Token* >(__pTokenList->GetAt(__focusOutIndex + 1));
4464 if (pToken->displayRect.y + pToken->displayRect.height > __pTokenEdit->GetBoundsF().height)
4466 r = __accessibilityElements.GetAt(__focusOutIndex + 1, pNextAccessibilityElement);
4467 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
4469 ScrollToFocusedTokenAccessibilityElement(*pNextAccessibilityElement);
4474 if (pToken == null) //Draw Cursor Accessibility Element
4476 _AccessibilityElement* pCursorAccessibilityElement = __pTokenEdit->GetCursorAccessibilityElement();
4477 if (pCursorAccessibilityElement && pPreviousAccessibilityElement && pCursorAccessibilityElement != pPreviousAccessibilityElement)
4479 if (GetTextBoundsF().y - pPreviousAccessibilityElement->GetBounds().y > pPreviousAccessibilityElement->GetBounds().height) //check for different lines
4481 float height = GetTextBoundsF().height + pPreviousAccessibilityElement->GetBounds().y + pPreviousAccessibilityElement->GetBounds().height;
4482 if (pCurrentElement == pCursorAccessibilityElement && height > __pTokenEdit->GetBoundsF().height)
4484 float tokenBottomMargin = 0.0f;
4485 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, tokenBottomMargin);
4486 float newScrollValue = GetTextBoundsF().height + tokenBottomMargin - __scrollValue;
4487 RecalculateTokenBounds(newScrollValue);
4488 _AccessibilityManager::GetInstance()->SetGlobalFocusedElement(*(__pTokenEdit->GetCursorAccessibilityElement()));
4489 _AccessibilityManager::GetInstance()->RequestToDrawFocusUi();
4495 __focusOutIndex = -1;
4496 UpdateTokenAccessibilityBounds();
4502 _TokenEditPresenter::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
4504 _AccessibilityElement* pAccessibilityElement = null;
4505 pAccessibilityElement = const_cast< _AccessibilityElement* >(&element);
4506 __accessibilityElements.IndexOf(pAccessibilityElement, __focusOutIndex);
4507 __accessibilityFocusIn = false;
4513 _TokenEditPresenter::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
4515 _AccessibilityElement* pTextAccessibilityElement = __pTokenEdit->GetTextAccessibilityElement();
4516 if (pTextAccessibilityElement != null)
4518 if (pTextAccessibilityElement == &element)
4520 if (__pTokenEdit->IsInternalFocused()) // Set cursor as global focus accessibility element only in focused mode.
4522 _AccessibilityElement* pCursorAccessibilityElement = __pTokenEdit->GetCursorAccessibilityElement();
4523 if (pCursorAccessibilityElement)
4525 _AccessibilityManager::GetInstance()->SetGlobalFocusedElement(*pCursorAccessibilityElement);
4526 _AccessibilityManager::GetInstance()->RequestToDrawFocusUi();
4536 _TokenEditPresenter::ScrollToFocusedToken(void)
4538 result r = E_SUCCESS;
4539 FloatRectangle focussedTokenRectangle;
4540 float newScrollValue = 0.0f;
4541 float tokenTopMargin = 0.0f;
4542 float tokenBottomMargin = 0.0f;
4543 float tokenHeight = 0.0f;
4544 float textBoundsAlignValue = 0.0f;
4545 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
4548 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
4549 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
4550 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
4552 FloatRectangle tokenEditRect = __pTokenEdit->GetBoundsF();
4553 float textObjectMaxHeight = GetMaxTextHeight();
4554 textBoundsAlignValue = (tokenHeight - textObjectMaxHeight) / 2.0f;
4556 if (__focusedTokenIndex == -1)
4558 //Focus bitmap to be reset when no token is focused.
4563 _Token* pToken = null;
4564 pToken = static_cast <_Token*>(__pTokenList->GetAt(__focusedTokenIndex));
4565 r = GetLastResult();
4566 SysTryReturnResult(NID_UI_CTRL, pToken != null, r, "Propagating.");
4568 focussedTokenRectangle = pToken->displayRect;
4570 float focussedTokenPosition= focussedTokenRectangle.y + focussedTokenRectangle.height ;
4572 if ((focussedTokenRectangle.y > 0) && (focussedTokenPosition < tokenEditRect.height))
4574 //Focused token is within the tokenEdit boundary
4579 if (focussedTokenRectangle.y < 0)
4581 //Focused token is above the upper boundary
4582 newScrollValue = focussedTokenRectangle.y - tokenTopMargin - __scrollValue;
4586 //Focused token is below the lower boundary
4587 newScrollValue = focussedTokenPosition - textBoundsAlignValue - tokenEditRect.height + tokenBottomMargin - __scrollValue;
4590 r = RecalculateTokenBounds(newScrollValue);
4591 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
4599 _TokenEditPresenter::SetDrawFocusState(bool focusState)
4603 __focusedTokenIndex = -1;
4605 __drawFocusState = focusState;
4611 _TokenEditPresenter::GetFocusedTokenIndex(void) const
4613 return __focusedTokenIndex;
4617 _TokenEditPresenter::PrepareFocusUiMode(void)
4619 if (__editingTokenIndex != -1)
4621 ExitTokenEditingMode();
4623 else if (__pressedTokenIndex != -1)
4625 __pressedTokenIndex = -1;
4626 DetachCursorFromToken();
4628 SetCursorDisabled(false);
4629 __pTokenEdit->Invalidate();
4637 _TokenEditPresenter::PerformRemoveTokenAnimation(VisualElement& source)
4639 if (__pTimingFunction == null)
4641 __pTimingFunction = new (std::nothrow) SineTimingFunction();
4642 SysTryReturnVoidResult(NID_UI_CTRL, __pTimingFunction, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4645 AnimationTransaction::Begin();
4647 VisualElementPropertyAnimation* pOpacityAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4648 SysTryReturnVoidResult(NID_UI_CTRL, pOpacityAnimation, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4650 pOpacityAnimation->SetPropertyName("opacity");
4651 pOpacityAnimation->SetStartValue(Variant(1.0f));
4652 pOpacityAnimation->SetEndValue(Variant(0.0f));
4654 pOpacityAnimation->SetDuration(ANIMATION_DURATION_OPACITY);
4655 pOpacityAnimation->SetTimingFunction(__pTimingFunction);
4657 source.AddAnimation("OpacityAnimation", *pOpacityAnimation);
4658 delete pOpacityAnimation;
4660 VisualElementValueAnimation* pBoundsAnimation = new (std::nothrow) VisualElementValueAnimation(); //deletion will happen in catch/ in Destroy animation
4661 SysTryReturnVoidResult(NID_UI_CTRL, pBoundsAnimation, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4663 pBoundsAnimation->SetTimingFunction(__pTimingFunction);
4664 FloatRectangle startValue = source.GetBounds();
4665 startValue.x = startValue.x + startValue.width * 0.05;
4666 startValue.y = startValue.y + startValue.height * 0.05;
4667 startValue.width = startValue.width * 0.9;
4668 startValue.height = startValue.height * 0.9;
4670 pBoundsAnimation->SetStartValue(Variant(source.GetBounds()));
4671 pBoundsAnimation->SetEndValue(Variant(startValue));
4672 pBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
4673 pBoundsAnimation->SetVisualElementAnimationTickEventListener(this);
4674 pBoundsAnimation->SetDuration(ANIMATION_DURATION_BOUNDS);
4675 source.AddAnimation(L"BoundsAnimation", *pBoundsAnimation);
4676 delete pBoundsAnimation;
4678 AnimationTransaction::Commit();
4683 }}} //Tizen::Ui::Controls