2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 "FUiAnim_VisualElement.h"
25 #include "FUi_UiTouchEvent.h"
26 #include "FUiCtrl_TokenEdit.h"
27 #include "FUiCtrl_TokenEditPresenter.h"
28 #include "FUiCtrl_Scroll.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Media;
32 using namespace Tizen::Ui::Animations;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Graphics::_Text;
36 namespace Tizen { namespace Ui { namespace Controls
40 SineTimingFunction::CalculateProgress(float timeProgress) const
42 const float segments[3][3] = {{0.0f, 0.01f, 0.37f}, {0.37f, 0.72f, 0.888f}, {0.888f, 0.9999f, 1.0f}};
43 float timeProgressValue = timeProgress;
44 int segmentsLength = 3; //Length of the segments array
45 int index = (int)floor(segmentsLength * timeProgressValue);
46 if (index >= segmentsLength)
48 index = segmentsLength - 1;
51 float progressValue = (timeProgressValue - index * (1.0 / segmentsLength)) * segmentsLength;
52 float segmentAtIndex[3];
53 for(int i = 0; i < 3; i++)
55 segmentAtIndex[i] = segments[index][i];
57 float ret = 0 + 1 * (segmentAtIndex[0] + progressValue * (2 * (1 - progressValue) * (segmentAtIndex[1] - segmentAtIndex[0]) + progressValue * (segmentAtIndex[2] - segmentAtIndex[0])));
66 _Token(const String& text, Font* pEditFont);
67 virtual ~_Token(void);
68 int GetTextPixelWidth(void) const;
69 wchar_t* GetText(void) const;
70 result ResetToken(const String& text);
71 result SetBounds(Rectangle bounds);
72 _VisualElement* GetVisualElement(void) const;
73 _Token(const _Token& src);
74 _Token& operator =(const _Token& value);
77 Rectangle displayRect;
78 TextObject* pTextObject;
81 bool isImplicitAnimation;
84 wchar_t* __pTextBuffer;
86 int __textPixelHeight;
87 _VisualElement* __pVisualElement;
90 _Token::_Token(const String& text, Font* pEditFont)
94 , isImplicitAnimation(true)
98 , __textPixelHeight(0)
99 , __pVisualElement(null)
101 result r = E_SUCCESS;
103 currTokenLength = text.GetLength();
104 int tokenFontSize = 0;
106 pTextObject = new (std::nothrow) TextObject;
107 SysTryReturnVoidResult(NID_UI_CTRL, pTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
109 // for default initialize.
110 r = pTextObject->Construct();
111 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
113 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
114 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
116 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
117 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
119 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, tokenFontSize);
121 pFont = new (std::nothrow) Font;
122 SysTryCatch(NID_UI_CTRL, pFont != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
124 r = pFont->Construct(pEditFont->GetFaceName(), FONT_STYLE_PLAIN, tokenFontSize);
125 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
127 r = pTextObject->SetFont(pFont, 0, pTextObject->GetTextLength());
128 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
130 r = ResetToken(text);
131 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
133 __pVisualElement = new (std::nothrow) _VisualElement;
134 SysTryCatch(NID_UI_CTRL, __pVisualElement != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
136 r = __pVisualElement->Construct();
137 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct _VisualElement.", GetErrorMessage(r));
139 __pVisualElement->SetImplicitAnimationEnabled(false);
147 if (__pVisualElement)
149 __pVisualElement->Destroy();
150 __pVisualElement = null;
160 _Token::ResetToken(const String& text)
162 result r = E_SUCCESS;
167 delete[] __pTextBuffer;
168 __pTextBuffer = null;
171 int length = text.GetLength();
172 wchar_t* pTempString = const_cast <wchar_t*>(text.GetPointer());
173 SysTryReturnResult(NID_UI_CTRL, pTempString != null, E_SYSTEM, "A system error has occurred. Token text string is null.");
175 __pTextBuffer = new (std::nothrow) wchar_t[(length + 1) * (sizeof(wchar_t))];
176 SysTryReturnResult(NID_UI_CTRL, __pTextBuffer != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
178 for (int i = 0; i < length; i++)
180 __pTextBuffer[i] = pTempString[i];
182 __pTextBuffer[length] = 0;
184 pTextObject->RemoveAll();
186 TextSimple* pSimpleText = new (std::nothrow)TextSimple(__pTextBuffer, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, pFont);
187 SysTryCatch(NID_UI_CTRL, pSimpleText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
189 r = pTextObject->AppendElement(*pSimpleText);
190 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
192 textSize = pTextObject->GetTextExtent(0, length);
193 __textPixelWidth = textSize.width;
194 __textPixelHeight = textSize.height;
196 r = pTextObject->Compose();
198 currTokenLength = length;
203 delete[] __pTextBuffer;
204 __pTextBuffer = null;
213 _Token::SetBounds(Rectangle bounds)
215 result r = E_SUCCESS;
216 displayRect = bounds;
217 if (__pVisualElement)
219 __pVisualElement->SetBounds(FloatRectangle(bounds.x, bounds.y, bounds.width, bounds.height));
225 _Token::GetVisualElement(void) const
227 return __pVisualElement;
230 _Token::~_Token(void)
238 delete[] __pTextBuffer;
239 __pTextBuffer = null;
241 if (__pVisualElement)
243 __pVisualElement->Destroy();
244 __pVisualElement = null;
249 _Token::GetTextPixelWidth(void) const
251 return __textPixelWidth;
255 _Token::GetText(void) const
257 return __pTextBuffer;
260 _TokenEditPresenter::_TokenEditPresenter(void)
263 , __pTokenBgBitmap(null)
264 , __pressedTokenIndex(-1)
265 , __isEditingToken(false)
266 , __edittingTokenIndex(-1)
267 , __clientRect(Rectangle(0, 0, 0, 0))
268 , __initTextRect(Rectangle(0, 0, 0, 0))
269 , __isEditModeEnabled(true)
270 , __pDescriptionTextVisualElement(null)
271 , __pDescriptionTextTextObject(null)
272 , __pDescriptionTextFont(null)
273 , __isTokenEditingFinished(false)
274 , __prevScrollValue(0)
276 , __isTokenScrolling(false)
277 , __isNeedToScroll(false)
278 , __maxScrollValue(0)
279 , __autoShrink(false)
280 , __hiddenTokenDisplayCountBounds(Rectangle())
281 , __pHiddenTokenCountVisualElement(null)
282 , __autoShrinkAlignmentValue(0)
283 , __pHiddenTokenCountTextObject(null)
284 , __descriptionText(String())
285 , __isPopupVisible(false)
286 , __isLongPressed(false)
288 , __animatingIndex(-1)
289 , __lastTokenIndex(-1)
290 , __pTimingFunction(null)
291 , __descriptionTextRectForScroll(Rectangle(0, 0, 0, 0))
292 , __previousTitleWidth(-1)
293 , __previousEditBounds(Rectangle(0, 0, 0, 0))
294 , __isTokenEditPresenterInitialized(false)
296 , __previousCursorPosition(0)
297 , __isScrollValueChanged(false)
299 , __isScrollValueModified(false)
304 _TokenEditPresenter::InitializeDescriptionText(void)
306 result r = E_SUCCESS;
307 int descriptionTextSize = 0;
309 __pDescriptionTextTextObject = new (std::nothrow) TextObject();
310 SysTryReturnResult(NID_UI_CTRL, __pDescriptionTextTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
312 // for default initialize.
313 r = __pDescriptionTextTextObject->Construct();
314 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
316 r = __pDescriptionTextTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
317 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
319 r = __pDescriptionTextTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
320 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
322 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, descriptionTextSize);
324 __pDescriptionTextFont = new (std::nothrow) Font();
325 SysTryCatch(NID_UI_CTRL, __pDescriptionTextFont != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
327 r = __pDescriptionTextFont->Construct(GetTitleFontFaceName(), FONT_STYLE_PLAIN, descriptionTextSize);
328 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
329 r = __pDescriptionTextTextObject->SetFont(__pDescriptionTextFont, 0, __pDescriptionTextTextObject->GetTextLength());
330 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
336 delete __pDescriptionTextTextObject;
337 __pDescriptionTextTextObject = null;
339 delete __pDescriptionTextFont;
340 __pDescriptionTextFont = null;
345 _TokenEditPresenter::~_TokenEditPresenter(void)
347 DisposeTokenEditPresenter();
351 _TokenEditPresenter::DisposeTokenEditPresenter(void)
353 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
354 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
356 if (pEditVisualElement && pCursorVisualElement)
358 VisualElement* pCursorParent = pCursorVisualElement->GetParent();
359 if (pCursorParent != pEditVisualElement)
363 pCursorParent->DetachChild(*pCursorVisualElement);
364 pEditVisualElement->AttachChild(*pCursorVisualElement);
371 __pTokenList->RemoveAll(true);
376 delete __pTokenBgBitmap;
377 __pTokenBgBitmap = null;
379 if (__pDescriptionTextVisualElement)
381 __pDescriptionTextVisualElement->Destroy();
382 __pDescriptionTextVisualElement = null;
385 delete __pDescriptionTextTextObject;
386 __pDescriptionTextTextObject = null;
388 if (__pDescriptionTextFont)
390 delete __pDescriptionTextFont;
391 __pDescriptionTextFont = null;
394 if (__pHiddenTokenCountVisualElement)
396 __pHiddenTokenCountVisualElement->Destroy();
397 __pHiddenTokenCountVisualElement = null;
400 delete __pHiddenTokenCountTextObject;
401 __pHiddenTokenCountTextObject = null;
403 if (__pTimingFunction)
405 delete __pTimingFunction;
406 __pTimingFunction = null;
413 _TokenEditPresenter::CreateTokenEditPresenterN(void)
415 _TokenEditPresenter* pPresenter = new (std::nothrow) _TokenEditPresenter();
416 SysTryReturn(NID_UI_CTRL, pPresenter != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
422 _TokenEditPresenter::Initialize(const _Control& control)
424 result r = E_SUCCESS;
426 r = _EditPresenter::Initialize(control);
427 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
429 r = InitializeDescriptionText();
430 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
432 TextObject* pTextObject = GetTextObject();
435 pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
436 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
437 pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
440 __pTokenEdit = dynamic_cast <_TokenEdit*>(GetEditView());
441 SysTryReturnResult(NID_UI_CTRL, __pTokenEdit != null, E_SYSTEM, "A system error has occurred. The _Token instance is null.");
443 _TokenEditModel* pTokenEditModel = new (std::nothrow) _TokenEditModel();
444 SysTryReturnResult(NID_UI_CTRL, pTokenEditModel != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
446 SetModel(*pTokenEditModel);
448 SetKeypadEnabled(true);
450 int tokenLeftMargin = 0;
451 int tokenRightMargin = 0;
452 int tokenTopMargin = 0;
453 int tokenBottomMargin = 0;
455 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
457 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, tokenLeftMargin);
458 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, tokenRightMargin);
459 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
460 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
461 GET_SHAPE_CONFIG(TOKEN_HEIGHT, orientation, tokenHeight);
463 // For drawing token in specific area
464 __clientRect.x = tokenLeftMargin;
465 __clientRect.y = tokenTopMargin;
466 __clientRect.width = __pTokenEdit->GetBounds().width - tokenLeftMargin - tokenRightMargin;
467 __clientRect.height = __pTokenEdit->GetBounds().height - tokenTopMargin - tokenBottomMargin;
469 __initTextRect = GetTextBounds();
471 Rectangle tempDspRect(__initTextRect.x, __initTextRect.y, __clientRect.width, tokenHeight);
472 SetTextBounds(tempDspRect);
475 GET_SHAPE_CONFIG(TOKENEDIT::TEXT_SIZE, orientation, textSize);
477 Font* pFont = new (std::nothrow) Font();
478 SysTryCatch(NID_UI_CTRL, pFont != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
480 r = pFont->Construct(FONT_STYLE_PLAIN, textSize);
481 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
488 __pTokenList = new (std::nothrow) Collection::LinkedList();
489 SysTryCatch(NID_UI_CTRL, __pTokenList != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
492 GET_BITMAP_CONFIG_N(TOKENEDIT::TOKEN_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgBitmap);
494 __previousEditBounds = __pTokenEdit->GetBounds();
496 __isTokenEditPresenterInitialized = true;
498 __previousCursorPosition = GetCursorPosition();
504 delete pTokenEditModel;
505 pTokenEditModel = null;
514 _TokenEditPresenter::Draw(Canvas& canvas)
516 if (!IsInitialized())
518 InitializeAtFirstDrawing();
520 if (IsFocused() == true)
526 canvas.SetBackgroundColor(Color(0, 0, 0, 0));
529 DrawBackground(canvas);
533 if (__pDescriptionTextTextObject->GetTextLength() != 0)
535 DrawDescriptionText();
538 if (GetTokenCount() != 0)
545 DrawHiddenTokenCount();
548 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
549 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
551 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
552 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
554 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
558 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
559 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get visual element of token.");
561 if (__isEditingToken)
563 Canvas* pTokenCanvas = pTokenVisualElement->GetCanvasN();
564 SysTryReturnResult(NID_UI_CTRL, pTokenCanvas != null, E_SYSTEM, "A system error has occurred. Failed to get canvas of the token.");
566 _EditPresenter::SetFont(*(pToken->pFont));
568 DrawText(*pTokenCanvas);
583 SysTryReturnResult(NID_UI_CTRL, !__isEditingToken, E_SYSTEM, "An invalid argument is given.");
590 if (__isTokenEditingFinished)
592 _EditPresenter::SetDefaultFont();
594 __isEditingToken = false;
595 __edittingTokenIndex = -1;
596 __isTokenEditingFinished = false;
603 _TokenEditPresenter::DrawToken(int count)
605 int drawStartIndex = 0;
607 int tokenTextLeftMargin = 0;
609 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
611 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
613 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
617 tokenCount = __pTokenList->GetCount();
624 Color normalTokenColor;
625 Color selectedTokenColor;
627 for (int i = drawStartIndex; i < tokenCount; i++)
629 Bitmap* pReplacementColorBackgroundBitmap = null;
631 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
632 if (pToken == null || pToken->pTextObject == null)
634 SysLog(NID_UI_CTRL, "[E_SYSTEM] The _Token instance is null");
638 normalTokenColor = GetTokenEditColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL);
639 selectedTokenColor = GetTokenEditColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED);
641 _VisualElement* pTokenElement = pToken->GetVisualElement();
642 if (pTokenElement == null)
644 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. The _VisualElement instance is null");
648 bool isSelected = false;
649 Canvas* pTokenCanvas = pTokenElement->GetCanvasN();
650 if (pTokenCanvas == null)
652 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. The Canvas instance is null");
655 Rectangle tokenRect(0, 0 , pToken->displayRect.width, pToken->displayRect.height);
657 if (__pressedTokenIndex == i && IsFocused())
659 if (__pTokenBgBitmap)
661 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), selectedTokenColor);
663 if (pReplacementColorBackgroundBitmap->IsNinePatchedBitmap())
665 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
669 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
674 pTokenCanvas->FillRectangle(selectedTokenColor, tokenRect);
681 if (__pTokenBgBitmap)
683 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), normalTokenColor);
685 if (pReplacementColorBackgroundBitmap->IsNinePatchedBitmap())
687 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
691 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
696 pTokenCanvas->FillRectangle(normalTokenColor, tokenRect);
700 pTokenElement->SetAnimationProvider(null);
701 if (pToken->isImplicitAnimation)
703 VisualElementAnimation* pAnimation = CreateAnimationN(*pTokenElement, true);
704 pTokenElement->AddAnimation(*pAnimation);
706 pToken->isImplicitAnimation = false;
709 if (!__isEditingToken || __pressedTokenIndex != i)
712 Rectangle textRect(0, 0, pToken->displayRect.width - ((tokenTextLeftMargin * 2)), pToken->displayRect.height);
714 textRect.x += tokenTextLeftMargin;
715 if (pToken->displayRect.width > pToken->GetTextPixelWidth())
717 textRect.width = pToken->GetTextPixelWidth() + 1;
722 textColor = GetTokenEditTextColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED);
726 textColor = GetTokenEditTextColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL);
729 pToken->pTextObject->SetForegroundColor(textColor, 0, pToken->pTextObject->GetTextLength());
730 pToken->pTextObject->SetBounds(textRect);
731 pToken->pTextObject->Compose();
732 pToken->pTextObject->Draw(*_CanvasImpl::GetInstance(*pTokenCanvas));
735 pTokenElement->SetFlushNeeded();
738 delete pReplacementColorBackgroundBitmap;
739 pReplacementColorBackgroundBitmap = null;
745 _TokenEditPresenter::GetTokenEditColor(const ExpandableEditAreaTokenStatus status) const
747 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, Color(0, 0, 0, 0), E_INVALID_STATE, "[E_INVALID_STATE] _TokenEdit is in an invalid state.");
751 if (status == EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL)
752 color = __pTokenEdit->GetTokenColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL);
754 color = __pTokenEdit->GetTokenColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED);
760 _TokenEditPresenter::GetTokenEditTextColor(const ExpandableEditAreaTokenStatus status) const
762 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, Color(0, 0, 0, 0), E_INVALID_STATE, "[E_INVALID_STATE] _TokenEdit is in an invalid state.");
766 if (status == EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL)
767 color = __pTokenEdit->GetTokenTextColor();
769 color = __pTokenEdit->GetSelectedTokenTextColor();
775 _TokenEditPresenter::MakeToken(const String& tokenString)
777 SysTryReturnResult(NID_UI_CTRL, __pTokenEdit != null, E_INVALID_STATE, "_TokenEdit is in an invalid state.");
778 result r = E_SUCCESS;
782 int tokenLength = tokenString.GetLength();
783 SysTryReturnResult(NID_UI_CTRL, tokenLength, E_INVALID_ARG, "Invalid argument is used. Token length is (%d)", tokenLength);
785 String inputTokenString = tokenString;
786 String replacementString = inputTokenString;
789 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
793 inputTokenString = replacementString;
796 if (inputTokenString.GetLength() <= 0)
799 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to clear text object.", GetErrorMessage(r));
801 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
802 return E_INVALID_ARG;
805 _Token* pToken = new (std::nothrow) _Token(inputTokenString, GetFont());
806 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
808 r = __pTokenList->Add(static_cast <Object&>(*pToken));
809 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
811 tokenCount = __pTokenList->GetCount();
812 index = tokenCount - 1;
814 r = CalculateTokenPositionFromIndex(index);
815 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to calculate token position.", GetErrorMessage(r));
817 r = TrimTokenAndAdjustEllipsisAt(index);
818 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to trim token.", GetErrorMessage(r));
820 r = InitializeTokenVisibilityAt(index);
821 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to initialize token visibility.", GetErrorMessage(r));
823 r = SetInitialBounds();
824 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds.", GetErrorMessage(r));
827 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to clear text object.", GetErrorMessage(r));
829 r = AdjustFlexibleHeight();
830 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process to resize.", GetErrorMessage(r));
832 r = CheckTokenScrolling();
833 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process scroll.", GetErrorMessage(r));
845 _TokenEditPresenter::MakeToken(void)
847 result r = E_SUCCESS;
849 String tempToken(GetText());
850 r = MakeToken(tempToken);
856 _TokenEditPresenter::InsertTokenAt(int index, const String& token, bool isUser)
858 SysTryReturnResult(NID_UI_CTRL, index >= 0, E_INVALID_ARG, "Invalid argument is used. index is (%d).", index);
859 SysTryReturnResult(NID_UI_CTRL, token.GetLength() > 0, E_INVALID_ARG, "Invalid argument is used. Token length is (%d).", token.GetLength());
861 result r = E_SUCCESS;
863 _Token* pToken = new (std::nothrow) _Token(token, GetFont());
864 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
866 r = __pTokenList->InsertAt(*pToken, index);
867 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to insert token.", GetErrorMessage(r));
869 if (__isEditingToken)
871 _EditPresenter::SetFont(*(pToken->pFont));
876 r = CalculateTokenPositionFromIndex(index);
877 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to calculate token position.", GetErrorMessage(r));
879 r = TrimTokenAndAdjustEllipsisAt(index);
880 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to trim token.", GetErrorMessage(r));
882 r = InitializeTokenVisibilityAt(index);
883 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to initialize token visibility.", GetErrorMessage(r));
885 r = SetInitialBounds();
886 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds.", GetErrorMessage(r));
888 r = AdjustFlexibleHeight();
889 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process to resize.", GetErrorMessage(r));
891 r = CheckTokenScrolling();
892 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process scroll.", GetErrorMessage(r));
894 for (int i = 0; i < GetTokenCount(); i++)
896 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
897 SysTryCatch(NID_UI_CTRL, pToken != null, ,r = E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
899 r = pToken->SetBounds(pToken->displayRect);
900 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds", GetErrorMessage(r));
905 if (__edittingTokenIndex >= 0)
907 if (index <= __edittingTokenIndex)
909 __edittingTokenIndex++;
911 __pressedTokenIndex = __edittingTokenIndex;
913 SetEditingTokenTextBounds(__edittingTokenIndex);
914 _EditPresenter::SetCursorPosition(__previousCursorPosition);
916 else if (__pressedTokenIndex >= index)
918 __pressedTokenIndex++;
933 _TokenEditPresenter::GetTokenAt(int index) const
936 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);
938 _Token* pToken = null;
939 pToken = static_cast <_Token*>(__pTokenList->GetAt(index));
942 tempString = pToken->GetText();
949 _TokenEditPresenter::GetTokenCount(void) const
951 return __pTokenList->GetCount();
955 _TokenEditPresenter::GetSelectedTokenIndex(void) const
957 return __pressedTokenIndex;
961 _TokenEditPresenter::IsTokenEditModeEnabled(void) const
963 return __isEditModeEnabled;
967 _TokenEditPresenter::RemoveTokenAt(int index, bool isClearText)
969 result r = E_SUCCESS;
970 SysTryReturnResult(NID_UI_CTRL, index >= 0 && index < __pTokenList->GetCount(), E_OUT_OF_RANGE, "index (%d) is out of range.", index);
972 if (index == __edittingTokenIndex && isClearText)
974 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
975 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
977 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
978 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
980 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
981 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
983 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
984 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
986 __edittingTokenIndex = -1;
987 __isEditingToken = false;
988 __pressedTokenIndex = -1;
989 __isTokenEditingFinished = true;
992 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Failed to clear text object.");
994 _EditPresenter::SetDefaultFont();
997 r = __pTokenList->RemoveAt(index, true);
998 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove token.");
1000 r = CalculateTokenPositionFromIndex(index);
1001 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to calculate token position.");
1003 r = SetInitialBounds();
1004 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
1006 _Token* pToken = null;
1008 for (int i = 0; i < GetTokenCount(); i++)
1010 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
1011 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
1013 r = pToken->SetBounds(pToken->displayRect);
1014 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds");
1017 r = AdjustFlexibleHeight();
1018 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to process to resize.");
1020 r = CheckTokenScrolling();
1021 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to process scroll.");
1025 if (index < __edittingTokenIndex)
1027 if (__edittingTokenIndex > 0)
1029 __edittingTokenIndex--;
1030 __pressedTokenIndex = __edittingTokenIndex;
1032 SetEditingTokenTextBounds(__edittingTokenIndex);
1033 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1036 else if (index == __pressedTokenIndex)
1038 __pressedTokenIndex = -1;
1040 else if (index >= 0 && index < __pressedTokenIndex)
1042 __pressedTokenIndex--;
1045 else if (index == __pressedTokenIndex)
1047 __pressedTokenIndex = -1;
1054 _TokenEditPresenter::SetTokenSelected(int index, bool selected)
1056 result r = E_SUCCESS;
1058 SysTryReturnResult(NID_UI_CTRL, index >= 0 && index < __pTokenList->GetCount(), E_OUT_OF_RANGE, "index (%d) is out of range.");
1060 if (selected == false)
1062 __pressedTokenIndex = -1;
1066 __pressedTokenIndex = index;
1073 _TokenEditPresenter::SetTokenEditModeEnabled(bool enable)
1075 result r = E_SUCCESS;
1077 __isEditModeEnabled = enable;
1083 _TokenEditPresenter::CalculateTokenPositionFromIndex(int startIndex, bool leftWard)
1085 result r = E_SUCCESS;
1087 int tokenCount = __pTokenList->GetCount();
1089 int tokenLeftMargin = 0;
1090 int tokenRighttMargin = 0;
1091 int tokenTopMargin = 0;
1092 int tokenBottomMargin = 0;
1093 int tokenHeight = 0;
1094 int tokenVerticalSpacing = 0;
1095 int tokenHorizontalSpacing = 0;
1096 int tokenTextLeftMargin = 0;
1097 int tokenTextRightMargin = 0;
1098 int descriptionTextRightMargin = 0;
1099 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1101 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, tokenLeftMargin);
1102 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, tokenRighttMargin);
1103 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1104 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
1105 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1106 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1107 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HORIZONTAL_SPACING, orientation, tokenHorizontalSpacing);
1108 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1109 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1110 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_RIGHT_MARGIN, orientation, descriptionTextRightMargin);
1112 SysTryReturn(NID_UI_CTRL, startIndex >= 0 && startIndex <= tokenCount, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. startIndex = (%d)", startIndex);
1114 _Token* pToken = null;
1115 _Token* pPreviousToken = null;
1117 int index = startIndex;
1119 Rectangle tokenEditBounds = __pTokenEdit->GetBounds();
1120 String titleText = __pTokenEdit->GetTitleText();
1122 if (GetDescriptionTextRect().width != __previousTitleWidth)
1124 __descriptionTextRectForScroll = GetDescriptionTextRect();
1125 __previousTitleWidth = GetDescriptionTextRect().width;
1128 bool findPrevTokenLoopFlag = true;
1129 for (; index < tokenCount; index++)
1131 pToken = static_cast <_Token*>(__pTokenList->GetAt(index));
1132 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
1136 // TODO : description text (title style inner)
1137 if (titleText.GetLength())
1139 pToken->displayRect.x = __descriptionTextRectForScroll.x + __descriptionTextRectForScroll.width + descriptionTextRightMargin;
1140 pToken->displayRect.y = __descriptionTextRectForScroll.y + __scrollValue;
1142 else // Set description text.
1144 pToken->displayRect.x = tokenTextLeftMargin + __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_LEFT_MARGIN);
1145 pToken->displayRect.y = tokenTopMargin + __scrollValue + __pTokenEdit->GetVerticalMargin(EDIT_TEXT_TOP_MARGIN) + __lineSpacing;
1148 pToken->displayRect.width = tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin;
1153 if (findPrevTokenLoopFlag)
1155 pPreviousToken = static_cast <_Token*>(__pTokenList->GetAt(index - 1));
1156 findPrevTokenLoopFlag = false;
1159 int tempTextWidth = tokenEditBounds.width - pPreviousToken->displayRect.x - pPreviousToken->displayRect.width - tokenHorizontalSpacing - __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_RIGHT_MARGIN);
1160 if (tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin > tempTextWidth) // Line change
1162 pToken->displayRect.x = tokenTextLeftMargin + __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_LEFT_MARGIN);
1163 pToken->displayRect.y = pPreviousToken->displayRect.y + tokenHeight + tokenVerticalSpacing + __lineSpacing;
1168 pToken->displayRect.x = pPreviousToken->displayRect.x + pPreviousToken->displayRect.width +
1169 tokenHorizontalSpacing;
1170 pToken->displayRect.y = pPreviousToken->displayRect.y;
1173 pToken->displayRect.width = tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin;
1176 pToken->displayRect.height = tokenHeight;
1178 pPreviousToken = pToken;
1181 for (int i = 0; i < __pTokenList->GetCount(); i++)
1183 TrimTokenAndAdjustEllipsisAt(i);
1184 InitializeTokenVisibilityAt(i);
1190 _TokenEditPresenter::InitializeTokenVisibilityAt(int ndex)
1192 result r = E_SUCCESS;
1194 _Token* pToken = null;
1195 pToken = static_cast <_Token*>(__pTokenList->GetAt(ndex));
1196 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
1198 r = pToken->SetBounds(pToken->displayRect);
1199 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to set bounds", GetErrorMessage(r));
1201 _VisualElement* pRootElement = __pTokenEdit->GetVisualElement();
1202 SysTryReturn(NID_UI_CTRL, pRootElement, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
1204 _VisualElement* pVisualElement = pToken->GetVisualElement();
1205 SysTryReturn(NID_UI_CTRL, pVisualElement, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element.");
1207 pVisualElement->SetShowState(true);
1209 r = pRootElement->AttachChild(*pVisualElement);
1210 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to add child", GetErrorMessage(r));
1216 _TokenEditPresenter::SetInitialBounds(void)
1218 result r = E_SUCCESS;
1220 int tokenTopMargin = 0;
1221 int tokenHeight = 0;
1222 int tokenMinWidth = 0;
1223 int tokenVerticalSpacing = 0;
1224 int tokenHorizontalSpacing = 0;
1225 int tokenTextLeftMargin = 0;
1226 int tokenTextRightMargin = 0;
1227 _ControlOrientation orientation = GetEditView()->GetOrientation();
1229 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1230 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1231 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_MIN_WIDTH, orientation, tokenMinWidth);
1232 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1233 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HORIZONTAL_SPACING, orientation, tokenHorizontalSpacing);
1234 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1235 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1239 int tokenCount = __pTokenList->GetCount();
1241 Rectangle tokenEditBounds = __pTokenEdit->GetBounds();
1242 Rectangle tokenTextRect = tokenEditBounds;
1244 if (tokenCount == 0)
1246 if (__pTokenEdit->GetTitleText().GetLength())
1248 Rectangle descriptionTextRect = GetDescriptionTextRect();
1250 tokenTextRect.x = descriptionTextRect.x + descriptionTextRect.width + tokenVerticalSpacing;
1251 tokenTextRect.width -= (tokenTextLeftMargin + tokenTextRightMargin + descriptionTextRect.width + 2 * __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_RIGHT_MARGIN));
1255 tokenTextRect.x = tokenTextLeftMargin + __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_LEFT_MARGIN);
1256 tokenTextRect.width -= (tokenTextLeftMargin + tokenTextRightMargin + 2 * __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_RIGHT_MARGIN));
1259 tokenTextRect.y = tokenTopMargin + __pTokenEdit->GetVerticalMargin(EDIT_TEXT_TOP_MARGIN);
1260 tokenTextRect.height = __pTokenEdit->GetTextSize() + (2 * tokenTopMargin);
1262 SetTextBounds(tokenTextRect);
1267 _Token* pToken = null;
1268 // SetTextBounds from last token
1269 pToken = static_cast <_Token*>(__pTokenList->GetAt(tokenCount - 1));
1270 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
1272 int tempTextRectWidth = 0;
1273 tempTextRectWidth = tokenEditBounds.width - pToken->displayRect.x - pToken->displayRect.width - tokenHorizontalSpacing - __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_RIGHT_MARGIN);
1274 if (tokenMinWidth > tempTextRectWidth) // Line change
1276 tokenTextRect.x = tokenTextLeftMargin + __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_LEFT_MARGIN);
1277 tokenTextRect.y = pToken->displayRect.y + tokenHeight + tokenVerticalSpacing + __lineSpacing;
1278 tokenTextRect.width = tokenEditBounds.width - tokenTextLeftMargin - tokenTextRightMargin - 2 * __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_RIGHT_MARGIN);
1282 tokenTextRect.x = pToken->displayRect.x + pToken->displayRect.width + tokenHorizontalSpacing;
1283 tokenTextRect.y = pToken->displayRect.y;
1284 tokenTextRect.width = tokenEditBounds.width - pToken->displayRect.x - pToken->displayRect.width -
1285 tokenTextRightMargin - __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_RIGHT_MARGIN) - tokenTextLeftMargin;
1288 tokenTextRect.height = __pTokenEdit->GetTextSize() + (2 * tokenTopMargin);
1290 SetTextBounds(tokenTextRect);
1294 r = _EditPresenter::SetInitialBounds();
1301 _TokenEditPresenter::SetDescriptionTextRect(const Rectangle& rect)
1303 result r = E_SUCCESS;
1305 __descriptionTextRect = rect;
1311 _TokenEditPresenter::GetDescriptionTextRect() const
1313 return __descriptionTextRect;
1317 _TokenEditPresenter::GetTextBounds(void) const
1319 if ((__isPopupVisible == true || __isLongPressed == true) && __pressedTokenIndex >= 0)
1321 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
1322 SysTryReturn(NID_UI_CTRL, pToken, Rectangle(), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Unable to get valid token.");
1324 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1325 int tokenTextLeftMargin = 0;
1326 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1328 Rectangle textBounds(pToken->displayRect.x + tokenTextLeftMargin, pToken->displayRect.y, pToken->displayRect.width, pToken->displayRect.height);
1333 return _EditPresenter::GetTextBounds();
1338 _TokenEditPresenter::CutText(void)
1340 if (__isEditingToken)
1342 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
1343 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
1345 pToken->isTextCut = true;
1347 return _EditPresenter::CutText();
1351 _TokenEditPresenter::SetLineSpacing(int linePixelGap)
1353 __lineSpacing = linePixelGap;
1359 _TokenEditPresenter::GetLineSpacing(void) const
1361 return __lineSpacing;
1364 VisualElementAnimation*
1365 _TokenEditPresenter::CreateAnimationN(VisualElement& source, bool create)
1367 VisualElementAnimation* pAnimation = null;
1368 VisualElementAnimationGroup* pAnimationGroup = new (std::nothrow) VisualElementAnimationGroup();
1369 SysTryReturn(NID_UI_CTRL, pAnimationGroup, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1371 pAnimationGroup->SetDuration(ANIMATION_DURATION_BOUNDS);
1372 if (__pTimingFunction == null)
1374 __pTimingFunction = new (std::nothrow) SineTimingFunction();
1375 SysTryReturn(NID_UI_CTRL, __pTimingFunction, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1378 if (pAnimationGroup != null)
1380 VisualElementPropertyAnimation* pOpacityAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1381 SysTryReturn(NID_UI_CTRL, pOpacityAnimation, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1383 pOpacityAnimation->SetPropertyName("opacity");
1386 pOpacityAnimation->SetStartValue(Variant(1.0f));
1387 pOpacityAnimation->SetEndValue(Variant(0.0f));
1391 pOpacityAnimation->SetStartValue(Variant(0.0f));
1392 pOpacityAnimation->SetEndValue(Variant(1.0f));
1395 pOpacityAnimation->SetDuration(ANIMATION_DURATION_OPACITY);
1396 pOpacityAnimation->SetTimingFunction(__pTimingFunction);
1397 pAnimationGroup->AddAnimation(*pOpacityAnimation);
1398 delete pOpacityAnimation;
1400 VisualElementPropertyAnimation* pBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1401 SysTryReturn(NID_UI_CTRL, pBoundsAnimation, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1403 pBoundsAnimation->SetPropertyName("bounds");
1404 FloatRectangle startValue = source.GetBounds();
1405 startValue.x = startValue.x + startValue.width * 0.05;
1406 startValue.y = startValue.y + startValue.height * 0.05;
1407 startValue.width = startValue.width * 0.9;
1408 startValue.height = startValue.height * 0.9;
1412 pBoundsAnimation->SetStartValue(Variant(source.GetBounds()));
1413 pBoundsAnimation->SetEndValue(Variant(startValue));
1414 pBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1418 pBoundsAnimation->SetStartValue(Variant(startValue));
1419 pBoundsAnimation->SetEndValue(Variant(source.GetBounds()));
1422 pBoundsAnimation->SetDuration(ANIMATION_DURATION_BOUNDS);
1423 pBoundsAnimation->SetTimingFunction(__pTimingFunction);
1424 pAnimationGroup->AddAnimation(*pBoundsAnimation);
1426 delete pBoundsAnimation;
1428 pAnimation = pAnimationGroup;
1434 _TokenEditPresenter::CalculateDescriptionTextRect(const String& descriptionText)
1436 result r = E_SUCCESS;
1438 TextSimple* pSimpleText = null;
1439 int tokenTopMargin = 0;
1440 int tokenHeight = 0;
1441 int tokenVerticalSpacing = 0;
1442 int tokenTextLeftMargin = 0;
1443 int tokenTextRightMargin = 0;
1444 int tokenTitleWidth = 0;
1445 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1447 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1448 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1449 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1450 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1451 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1452 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TITLE_RECT_WIDTH, orientation, tokenTitleWidth);
1454 int length = descriptionText.GetLength();
1457 wchar_t* pTempString = const_cast <wchar_t*>(descriptionText.GetPointer());
1459 SysAssertf(__pDescriptionTextTextObject != null, "The TextObject instance is null.");
1461 __pDescriptionTextTextObject->RemoveAll();
1462 pSimpleText = new (std::nothrow)TextSimple(pTempString, length, TEXT_ELEMENT_SOURCE_TYPE_INTERNAL);
1463 __pDescriptionTextTextObject->AppendElement(*pSimpleText);
1465 textSize = __pDescriptionTextTextObject->GetTextExtent(0, length);
1466 r = __pDescriptionTextTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1467 r = __pDescriptionTextTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
1469 __descriptionTextRect.x = tokenTextLeftMargin + __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_LEFT_MARGIN);;
1470 __descriptionTextRect.y = tokenTopMargin + __pTokenEdit->GetVerticalMargin(EDIT_TEXT_TOP_MARGIN);;
1471 if (textSize.width > tokenTitleWidth)
1473 textSize.width = tokenTitleWidth;
1474 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1475 __pDescriptionTextTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
1477 __descriptionTextRect.width = tokenTextLeftMargin + textSize.width + tokenTextRightMargin;
1478 __descriptionTextRect.height = tokenHeight;
1479 __pDescriptionTextTextObject->SetBounds(__descriptionTextRect);
1481 r = __pDescriptionTextTextObject->Compose();
1487 _TokenEditPresenter::DrawDescriptionText(void)
1489 result r = E_SUCCESS;
1490 Rectangle tempDescriptionTextRect;
1491 Canvas* pDescriptionTextCanvas = null;
1493 Font* pDescriptionFont = null;
1495 if (__pDescriptionTextTextObject->GetFont(0)->GetFaceName() != GetTitleFontFaceName())
1497 int descriptionTextSize = 0;
1498 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, descriptionTextSize);
1500 pDescriptionFont = new (std::nothrow) Font();
1501 SysTryReturn(NID_UI_CTRL, pDescriptionFont != null, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1503 r = pDescriptionFont->Construct(GetTitleFontFaceName(), FONT_STYLE_PLAIN, descriptionTextSize);
1506 delete pDescriptionFont;
1507 pDescriptionFont = null;
1509 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1511 r = __pDescriptionTextTextObject->SetFont(pDescriptionFont, 0, __pDescriptionTextTextObject->GetTextLength());
1514 delete pDescriptionFont;
1515 pDescriptionFont = null;
1517 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
1519 delete __pDescriptionTextFont;
1520 __pDescriptionTextFont = null;
1522 __pDescriptionTextFont = pDescriptionFont;
1525 _VisualElement* pRootElement = __pTokenEdit->GetVisualElement();
1526 SysTryReturn(NID_UI_CTRL, pRootElement, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
1528 if (__pDescriptionTextVisualElement)
1530 __pDescriptionTextVisualElement->Destroy();
1531 __pDescriptionTextVisualElement = null;
1533 __pDescriptionTextVisualElement = new (std::nothrow) _VisualElement();
1534 SysTryReturn(NID_UI_CTRL, __pDescriptionTextVisualElement, false, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1535 r = __pDescriptionTextVisualElement->Construct();
1536 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[E_SYSTEM] A system error has occurred. Failed to construct _VisualElement");
1537 __pDescriptionTextVisualElement->SetImplicitAnimationEnabled(false);
1538 __pDescriptionTextVisualElement->SetBounds(FloatRectangle(__descriptionTextRect.x, __descriptionTextRect.y, __descriptionTextRect.width, __descriptionTextRect.height)); // TBD.
1539 __pDescriptionTextVisualElement->SetShowState(true);
1541 r = pRootElement->AttachChild(*__pDescriptionTextVisualElement);
1542 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1544 pDescriptionTextCanvas = __pDescriptionTextVisualElement->GetCanvasN();
1545 if (pDescriptionTextCanvas == null)
1547 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to get canvas of an instance of _VisualElement.");
1551 tempDescriptionTextRect = __descriptionTextRect;
1552 tempDescriptionTextRect.x = 0;
1553 tempDescriptionTextRect.y = 0;
1555 __pDescriptionTextTextObject->SetForegroundColor(__pTokenEdit->GetTitleTextColor(GetCurrentStatus()), 0, __pDescriptionTextTextObject->GetTextLength());
1557 pDescriptionTextCanvas->FillRectangle(__pTokenEdit->GetColor(GetCurrentStatus()), tempDescriptionTextRect);
1558 __pDescriptionTextTextObject->SetBounds(tempDescriptionTextRect);
1559 __pDescriptionTextTextObject->Compose();
1560 __pDescriptionTextTextObject->Draw(*_CanvasImpl::GetInstance(*pDescriptionTextCanvas));
1561 __pDescriptionTextVisualElement->SetFlushNeeded();
1563 delete pDescriptionTextCanvas;
1567 __pDescriptionTextVisualElement->Destroy();
1568 __pDescriptionTextVisualElement = null;
1574 _TokenEditPresenter::TrimTokenAndAdjustEllipsisAt(int index)
1576 result r = E_SUCCESS;
1578 int tokenTextRightMargin = 0;
1579 int tokenMinimumSize = 0;
1581 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1582 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1583 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_MIN_WIDTH, orientation, tokenMinimumSize);
1585 _Token* pToken = null;
1586 pToken = static_cast <_Token*>(__pTokenList->GetAt(index));
1587 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
1589 Rectangle tokenEditBounds = __pTokenEdit->GetBounds();
1590 Rectangle tokenRect = pToken->displayRect;
1592 int remainWidth = tokenEditBounds.width - tokenTextRightMargin - __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_RIGHT_MARGIN);;
1593 int dspTokenWidth = tokenRect.x + tokenRect.width;
1594 int dspTokenGap = dspTokenWidth - remainWidth;
1596 if (dspTokenGap > 0)
1598 if (pToken->displayRect.width >= tokenMinimumSize)
1600 if ((pToken->displayRect.width - dspTokenGap) < tokenMinimumSize)
1602 pToken->displayRect.width = tokenMinimumSize;
1606 pToken->displayRect.width -= dspTokenGap;
1611 pToken->pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1612 pToken->pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
1619 _TokenEditPresenter::GetTokenIndexFromCoordinate(const Point point) const
1621 int tokenIndex = -1;
1623 int tokenCount = __pTokenList->GetCount();
1624 for (int i = 0; i < tokenCount; i++)
1626 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
1629 Rectangle tokenRect = pToken->displayRect;
1630 if (tokenRect.Contains(point))
1641 _TokenEditPresenter::SetEditingTokenTextBounds(int index, bool isSetText)
1643 result r = E_SUCCESS;
1645 int tokenHeight = 0;
1646 int tokenVerticalSpacing = 0;
1647 int tokenTextLeftMargin = 0;
1648 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1650 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1651 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1652 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1654 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(index));
1655 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
1657 Rectangle tempTextDspRect;
1658 tempTextDspRect.x += tokenTextLeftMargin;
1659 tempTextDspRect.y += tokenVerticalSpacing / 2;
1660 tempTextDspRect.width = pToken->GetTextPixelWidth();
1661 tempTextDspRect.height = tokenHeight;
1665 if (!pToken->isTextCut)
1667 SetText(pToken->GetText());
1669 pToken->pTextObject->RemoveAll();
1672 SetTextBounds(tempTextDspRect);
1678 _TokenEditPresenter::RecalculateTokenBounds(int position)
1680 result r = E_SUCCESS;
1682 __scrollValue = -position;
1684 int tokenCount = GetTokenCount();
1685 CalculateTokenPositionFromIndex(0);
1687 for (int i = 0; i < tokenCount; i++)
1689 _Token* pToken = null;
1690 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
1694 pToken->SetBounds(pToken->displayRect);
1696 TrimTokenAndAdjustEllipsisAt(i);
1697 InitializeTokenVisibilityAt(i);
1700 if (__pDescriptionTextTextObject->GetTextLength() != 0)
1702 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
1705 __pTokenEdit->Draw();
1706 __pTokenEdit->Show();
1708 r = SetInitialBounds();
1709 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
1715 _TokenEditPresenter::SetTokenBoundsByTouchInfo(const _TouchInfo& touchinfo)
1717 result r = E_SUCCESS;
1718 int currentYPosition = touchinfo.GetCurrentPosition().y;
1720 if (__prevScrollValue == 0)
1722 __prevScrollValue = currentYPosition;
1724 else // Adjust moved y position to all tokens.
1726 if (__isNeedToScroll) // Need to scroll
1728 int tempDefference = __prevScrollValue - currentYPosition;
1730 __prevScrollValue = currentYPosition;
1731 __scrollValue -= tempDefference;
1733 if (__scrollValue < -__maxScrollValue)
1735 __scrollValue = -__maxScrollValue;
1740 if (__scrollValue > 0)
1747 int tokenCount = GetTokenCount();
1748 CalculateTokenPositionFromIndex(0);
1749 for (int i = 0; i < tokenCount; i++)
1751 _Token* pToken = null;
1752 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
1756 pToken->SetBounds(pToken->displayRect);
1758 TrimTokenAndAdjustEllipsisAt(i);
1759 InitializeTokenVisibilityAt(i);
1762 if (__pDescriptionTextTextObject->GetTextLength() != 0)
1764 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
1767 __pTokenEdit->Draw();
1768 __pTokenEdit->Show();
1772 __prevScrollValue = 0;
1777 r = SetInitialBounds();
1778 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
1784 _TokenEditPresenter::ProcessTokeningByTouchEvent(const _Control& source, const _TouchInfo& touchinfo)
1786 int tokenIndex = GetTokenIndexFromCoordinate(touchinfo.GetCurrentPosition());
1787 int prevPressedTokenIndex = __pressedTokenIndex;
1789 result r = E_SUCCESS;
1792 if (__isEditModeEnabled && __pressedTokenIndex != -1 && __pressedTokenIndex == tokenIndex)
1794 /*__edittingTokenIndex = __pressedTokenIndex;
1795 __isEditingToken = true;
1796 SetEditingTokenTextBounds(__edittingTokenIndex);
1797 SetCursorDisabled(false);*/
1799 __pressedTokenIndex = tokenIndex;
1802 if (__pressedTokenIndex != -1)
1804 if (__isEditingToken && (prevPressedTokenIndex != __pressedTokenIndex)) // Selected another token while editing.
1806 __isPopupVisible = false;
1807 __isLongPressed = false;
1809 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
1810 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
1812 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
1813 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
1815 _Token* pToken = null;
1816 _VisualElement* pTokenVisualElement = null;
1818 pToken = static_cast <_Token*>(__pTokenList->GetAt(prevPressedTokenIndex));
1820 bool isParentChanged = false;
1823 pTokenVisualElement = pToken->GetVisualElement();
1824 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
1826 if (pCursorVisualElement->GetParent() == pTokenVisualElement)
1828 isParentChanged = true;
1829 result r = E_SUCCESS;
1830 r = pTokenVisualElement->DetachChild(*pCursorVisualElement);
1831 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1833 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
1834 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1838 r = RemoveTokenAt(prevPressedTokenIndex);
1839 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1841 if (GetText().GetLength() > 0)
1843 r = InsertTokenAt(prevPressedTokenIndex, GetText());
1844 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1846 pToken = static_cast <_Token*>(__pTokenList->GetAt(prevPressedTokenIndex));
1849 pToken->currTokenLength = GetText().GetLength();
1853 __edittingTokenIndex = -1;
1854 __isTokenEditingFinished = true;
1855 __isEditingToken = false;
1856 SetCursorDisabled(true);
1860 if (GetText().GetLength() > 0 && __pressedTokenIndex != prevPressedTokenIndex)
1863 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1866 if ((__isEditingToken == true) && (__pressedTokenIndex != -1))
1868 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
1869 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
1871 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
1872 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
1874 _Token* pToken = null;
1875 _VisualElement* pTokenVisualElement = null;
1877 pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
1879 bool isParentChanged = false;
1882 pTokenVisualElement = pToken->GetVisualElement();
1883 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
1885 if (pCursorVisualElement->GetParent() != pTokenVisualElement)
1887 isParentChanged = true;
1888 result r = E_SUCCESS;
1889 r = (pCursorVisualElement->GetParent())->DetachChild(*pCursorVisualElement);
1890 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1892 r = pTokenVisualElement->AttachChild(*pCursorVisualElement);
1893 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1898 if (__isEditingToken == false)
1900 SetCursorDisabled(true);
1906 __isPopupVisible = false;
1907 __isLongPressed = false;
1909 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
1910 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
1912 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
1913 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
1915 if (__isEditingToken)
1917 _Token* pToken = null;
1918 _VisualElement* pTokenVisualElement = null;
1920 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
1922 bool isParentChanged = false;
1925 pTokenVisualElement = pToken->GetVisualElement();
1926 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
1928 if (pCursorVisualElement->GetParent() == pTokenVisualElement)
1930 isParentChanged = true;
1931 result r = E_SUCCESS;
1932 r = pTokenVisualElement->DetachChild(*pCursorVisualElement);
1933 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1935 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
1936 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1940 String inputTokenString = GetText();
1941 String replacementString = inputTokenString;
1942 bool enable = false;
1944 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
1947 inputTokenString = replacementString;
1950 RemoveTokenAt(__edittingTokenIndex);
1952 if (inputTokenString.GetLength() > 0)
1954 InsertTokenAt(__edittingTokenIndex, inputTokenString);
1956 if (isParentChanged)
1958 pToken->currTokenLength = inputTokenString.GetLength();
1960 __isTokenEditingFinished = true;
1961 __isEditingToken = false;
1962 __edittingTokenIndex = -1;
1966 __isTokenEditingFinished = true;
1967 __isEditingToken = false;
1968 __edittingTokenIndex = -1;
1970 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
1971 return E_INVALID_ARG;
1978 if (pCursorVisualElement->GetParent() != pEditVisualElement)
1980 r = (pCursorVisualElement->GetParent())->DetachChild(*pCursorVisualElement);
1981 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1983 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
1984 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1988 SetCursorDisabled(false);
1991 for (int i = 0; i < __pTokenList->GetCount(); i++)
1993 TrimTokenAndAdjustEllipsisAt(i);
1994 InitializeTokenVisibilityAt(i);
2001 _TokenEditPresenter::CheckTokenScrolling(bool scrollToCursorPosition)
2003 bool needToScroll = false;
2004 int tokenTopMargin = 0;
2005 int tokenBottomMargin = 0;
2006 int tokenVerticalSpacing = 0;
2007 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2009 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
2010 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
2011 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
2013 int tokenCount = GetTokenCount();
2014 if (tokenCount == 0) // There is no token to scroll
2016 __isNeedToScroll = false;
2017 __maxScrollValue = 0;
2018 __isTokenScrolling = false;
2023 _Token* pToken = static_cast<_Token*>(__pTokenList->GetAt(tokenCount - 1));
2024 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
2026 int newScrollValue = 0;
2028 if (scrollToCursorPosition)
2030 Rectangle cursorBounds;
2031 GetCursorBounds(false, cursorBounds);
2032 newScrollValue = cursorBounds.y + cursorBounds.height - __scrollValue + tokenBottomMargin - __pTokenEdit->GetBounds().height;
2033 __isScrollValueModified = true;
2037 newScrollValue = GetTextBounds().y + GetTextBounds().height - __scrollValue + tokenBottomMargin - __pTokenEdit->GetBounds().height;
2038 __isScrollValueModified = true;
2041 needToScroll = (newScrollValue > 0) ? (true) : (false);
2043 __isNeedToScroll = needToScroll;
2045 if (__isNeedToScroll)
2047 __maxScrollValue = newScrollValue;
2048 __isTokenScrolling = true;
2050 RecalculateTokenBounds(__maxScrollValue);
2054 if (__scrollValue != 0)
2057 __maxScrollValue = 0; // To prevent unnecessary token scrolling.
2058 RecalculateTokenBounds(__scrollValue);
2059 __isTokenScrolling = false;
2067 _TokenEditPresenter::SetTokenVisualElementBounds(int index, const Rectangle& bounds)
2069 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(index));
2070 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null.");
2072 return pToken->SetBounds(pToken->displayRect);
2076 _TokenEditPresenter::AdjustFlexibleHeight(void)
2078 result r = E_SUCCESS;
2080 Rectangle editRect = __pTokenEdit->GetBounds();
2081 Rectangle displayScrollBounds = GetDisplayScrollBounds();
2082 int calcHeight = CalculateFlexibleHeight();
2084 if (editRect.height != calcHeight)
2086 displayScrollBounds.height = calcHeight;
2087 SetScrollBarBounds(displayScrollBounds);
2089 editRect.height = calcHeight;
2090 if (!__isEditingToken)
2092 r = SetFlexBounds(editRect);
2100 _TokenEditPresenter::CalculateFlexibleHeight(void)
2102 int tokenHeight = 0;
2103 int tokenVerticalSpacing = 0;
2104 int tokenTopMargin =0;
2105 int tokenBottomMargin = 0;
2106 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2108 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
2109 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
2110 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
2111 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
2114 int maxLinecount = GetMaxLineCount();
2115 int expectedEditHeight = GetTextBounds().y + GetTextBounds().height - __scrollValue + tokenBottomMargin;
2116 int initialHeight = GetInitialBounds().height;
2117 int maximumLineHeight = tokenTopMargin + maxLinecount * tokenHeight + tokenVerticalSpacing * (maxLinecount - 1) + tokenBottomMargin;
2119 if (initialHeight < expectedEditHeight)
2121 if (expectedEditHeight > maximumLineHeight)
2123 height = maximumLineHeight;
2127 height = expectedEditHeight;
2132 height = initialHeight;
2139 _TokenEditPresenter::DrawScrollBar(void)
2141 result r = E_SUCCESS;
2143 _Scroll* pScroll = GetScrollBar();
2144 if (pScroll == null)
2149 if (IsFocused() == false)
2151 pScroll->SetScrollVisibility(false);
2155 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(GetTokenCount() - 1));
2161 int tokenBottomMargin = 0;
2162 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, tokenBottomMargin);
2164 int totalHeight = GetTextBounds().y + GetTextBounds().height - __scrollValue + tokenBottomMargin;
2165 int dspHeight = __pTokenEdit->GetBounds().height;
2166 int firstDspY = -__scrollValue;
2168 if (totalHeight <= dspHeight)
2170 pScroll->SetScrollVisibility(false);
2171 pScroll->SetScrollRange(1, 1);
2172 pScroll->SetScrollPosition(0);
2174 SetScrollBarVisible(false);
2175 SetPreviousScrollBarPosition(0);
2176 SetMaximumPreviousScrollBarPosition(0);
2180 pScroll->SetScrollVisibility(true);
2181 // if (_pScroll->IsVisible())
2185 pScroll->SetScrollRange(dspHeight, totalHeight);
2186 pScroll->SetScrollPosition(firstDspY);
2188 SetScrollBarVisible(true);
2189 SetMaximumPreviousScrollBarPosition(totalHeight - dspHeight);
2193 pScroll->SetScrollRange(dspHeight, totalHeight);
2194 pScroll->SetScrollPosition(0);
2196 SetScrollBarVisible(true);
2197 SetMaximumPreviousScrollBarPosition(0);
2200 SetScrollBarVisible(true);
2203 SetPreviousScrollBarPosition(firstDspY);
2210 _TokenEditPresenter::SetAutoShrinkModeEnabled(bool enable)
2212 __autoShrink = enable;
2216 _TokenEditPresenter::IsAutoShrinkModeEnabled(void) const
2218 return __autoShrink;
2222 _TokenEditPresenter::SetDescriptionText(String descriptionText)
2224 __descriptionText = descriptionText;
2228 _TokenEditPresenter::GetDescriptionText(void) const
2230 return __descriptionText;
2234 _TokenEditPresenter::CalculateVisibleTokenCount(void)
2236 int visibleTokenCount = 0;
2238 Rectangle intialBounds = GetInitialBounds();
2239 Rectangle tempInitialBounds = intialBounds;
2240 Rectangle hiddenTokenDisplayBounds;
2241 int tokenCount = GetTokenCount();
2243 for (int i = 0; i < tokenCount; i++)
2245 tempInitialBounds = intialBounds;
2247 hiddenTokenDisplayBounds = CalculateHiddenTokenCountDisplayBounds(tokenCount - i - 1);
2248 tempInitialBounds.width -= hiddenTokenDisplayBounds.width;
2250 Point leftTop(hiddenTokenDisplayBounds.x, hiddenTokenDisplayBounds.y);
2251 Point rightBottom(hiddenTokenDisplayBounds.x + hiddenTokenDisplayBounds.width, hiddenTokenDisplayBounds.y + hiddenTokenDisplayBounds.height);
2253 if (tempInitialBounds.Contains(leftTop) == false || tempInitialBounds.Contains(rightBottom) == false)
2257 visibleTokenCount++;
2259 return visibleTokenCount;
2263 _TokenEditPresenter::CalculateHiddenTokenCountDisplayBounds(int hiddenTokenCount)
2265 result r = E_SUCCESS;
2266 Rectangle displayBounds;
2271 int horizontalSpace = 0;
2273 TextSimple* pSimpleText = null;
2276 GET_SHAPE_CONFIG(TOKENEDIT::HIDDEN_TOKEN_COUNT_DISPLAY_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, textSize);
2277 GET_SHAPE_CONFIG(TOKENEDIT::HIDDEN_TOKEN_COUNT_DISPLAY_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, margin);
2278 GET_SHAPE_CONFIG(TOKENEDIT::HIDDEN_TOKEN_COUNT_DISPLAY_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, height);
2279 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HORIZONTAL_SPACING, _CONTROL_ORIENTATION_PORTRAIT, horizontalSpace);
2281 int tokenIndex = GetTokenCount() - hiddenTokenCount - 1;
2282 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(tokenIndex));
2283 SysTryReturn(NID_UI_CTRL, pToken != null && pToken->pTextObject != null, Rectangle(), E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
2285 displayBounds.x = pToken->displayRect.x + pToken->displayRect.width + margin;
2286 displayBounds.y = pToken->displayRect.y;
2287 displayBounds.height = height;
2289 String hiddenTokenCountString("+");
2290 hiddenTokenCountString.Append(hiddenTokenCount);
2292 int length = hiddenTokenCountString.GetLength();
2293 wchar_t* pTempString = const_cast <wchar_t*>(hiddenTokenCountString.GetPointer());
2295 if (__pHiddenTokenCountTextObject)
2297 delete __pHiddenTokenCountTextObject;
2298 __pHiddenTokenCountTextObject = null;
2301 __pHiddenTokenCountTextObject = new (std::nothrow) TextObject;
2302 SysTryReturn(NID_UI_CTRL, __pHiddenTokenCountTextObject != null, Rectangle(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2304 r = __pHiddenTokenCountTextObject->Construct();
2305 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2307 pSimpleText = new (std::nothrow) TextSimple(pTempString, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
2308 SysTryCatch(NID_UI_CTRL, pSimpleText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2310 __pHiddenTokenCountTextObject->AppendElement(*pSimpleText);
2311 __pHiddenTokenCountTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
2312 __pHiddenTokenCountTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
2314 pFont = new (std::nothrow) Font;
2315 SysTryCatch(NID_UI_CTRL, pFont != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2317 r = pFont->Construct(FONT_STYLE_PLAIN, textSize);
2318 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2320 __pHiddenTokenCountTextObject->SetFont(pFont, 0, __pHiddenTokenCountTextObject->GetTextLength());
2322 textDim = __pHiddenTokenCountTextObject->GetTextExtent(0, length);
2323 displayBounds.width = margin + textDim.width + margin;
2328 return displayBounds;
2332 delete __pHiddenTokenCountTextObject;
2333 __pHiddenTokenCountTextObject = null;
2345 _TokenEditPresenter::CalculateAutoShrinkAlignmentValue(int visibleTokenCount) const
2349 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(visibleTokenCount - 1));
2350 SysTryReturn(NID_UI_CTRL, pToken != null && pToken->pTextObject != null, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
2352 value = pToken->displayRect.y;
2354 pToken = static_cast <_Token*>(__pTokenList->GetAt(0));
2355 SysTryReturn(NID_UI_CTRL, pToken != null && pToken->pTextObject != null, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
2357 value = pToken->displayRect.y + pToken->displayRect.height - value;
2359 int initialHeight = GetInitialBounds().height;
2361 value = (initialHeight - value) / 2;
2364 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, topMargin);
2377 _TokenEditPresenter::DrawHiddenTokenCount(void)
2379 result r = E_SUCCESS;
2381 if (__pHiddenTokenCountVisualElement)
2383 Canvas* pHiddenTokenCountCanvas = __pHiddenTokenCountVisualElement->GetCanvasN();
2385 if (pHiddenTokenCountCanvas)
2387 __pHiddenTokenCountTextObject->SetForegroundColor(Color::GetColor(COLOR_ID_WHITE), 0, __pHiddenTokenCountTextObject->GetTextLength());
2388 __pHiddenTokenCountTextObject->Compose();
2389 __pHiddenTokenCountTextObject->SetBounds(__hiddenTokenDisplayCountBounds);
2390 __pHiddenTokenCountTextObject->Draw(*_CanvasImpl::GetInstance(*pHiddenTokenCountCanvas));
2392 delete pHiddenTokenCountCanvas;
2393 pHiddenTokenCountCanvas = null;
2396 __pHiddenTokenCountVisualElement->SetFlushNeeded();
2403 _TokenEditPresenter::OnFocusGained(void)
2407 int tempHeight = CalculateFlexibleHeight();
2408 Rectangle tempRect = GetInitialBounds();
2409 tempRect.height = tempHeight;
2411 _Token* pToken = null;
2412 int tokenCount = GetTokenCount();
2414 for (int i = 0; i < tokenCount; i++)
2416 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2420 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
2421 if (pTokenVisualElement)
2423 pTokenVisualElement->SetShowState(true);
2430 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2431 SysTryReturn(NID_UI_CTRL, pEditVisualElement, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
2433 if (__pHiddenTokenCountVisualElement)
2435 pEditVisualElement->DetachChild(*__pHiddenTokenCountVisualElement);
2436 __pHiddenTokenCountVisualElement->Destroy();
2437 __pHiddenTokenCountVisualElement = null;
2440 __scrollValue = -__autoShrinkAlignmentValue;
2441 __autoShrinkAlignmentValue = 0;
2442 CalculateTokenPositionFromIndex(0);
2445 SetFlexBounds(tempRect);
2447 SetEditingTokenTextBounds(__edittingTokenIndex, false);
2451 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2455 if (__isScrollValueChanged && !__isScrollValueModified)
2457 __maxScrollValue = __maxScrollValue - (__pTokenEdit->GetBounds().height - GetInitialBounds().height);
2458 __isScrollValueChanged = false;
2461 return _EditPresenter::OnFocusGained();
2465 _TokenEditPresenter::OnFocusLost(void)
2467 result r = E_SUCCESS;
2471 if (__edittingTokenIndex >= 0)
2473 _Token* pToken = null;
2474 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
2477 if (GetText().GetLength() > 0)
2479 OnTextCommitted(L"\n");
2485 if (GetText().GetLength() > 0)
2487 OnTextCommitted(L"\n");
2493 _Scroll* pScroll = GetScrollBar();
2496 pScroll->SetScrollVisibility(false);
2500 int tokenCount = GetTokenCount();
2501 _Token* pToken = null;
2502 for (int i = 0; i < tokenCount; i++)
2504 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2507 pToken->SetBounds(pToken->displayRect);
2511 r = SetInitialBounds();
2512 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating", GetErrorMessage(r));
2514 int visibleTokenCount = CalculateVisibleTokenCount();
2515 __hiddenTokenDisplayCountBounds = CalculateHiddenTokenCountDisplayBounds(tokenCount - visibleTokenCount);
2517 __autoShrinkAlignmentValue = CalculateAutoShrinkAlignmentValue(visibleTokenCount);
2519 if (visibleTokenCount > 0)
2521 _Token* pToken = null;
2522 for (int i = visibleTokenCount; i < tokenCount; i++)
2524 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2527 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
2528 if (pTokenVisualElement)
2530 pTokenVisualElement->SetShowState(false);
2535 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2536 SysTryReturn(NID_UI_CTRL, pEditVisualElement != null, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
2538 if (__pHiddenTokenCountVisualElement)
2540 pEditVisualElement->DetachChild(*__pHiddenTokenCountVisualElement);
2541 __pHiddenTokenCountVisualElement->Destroy();
2542 __pHiddenTokenCountVisualElement = null;
2545 __pHiddenTokenCountVisualElement = new (std::nothrow) _VisualElement;
2546 if (__pHiddenTokenCountVisualElement)
2548 r = __pHiddenTokenCountVisualElement->Construct();
2549 __pHiddenTokenCountVisualElement->SetShowState(true);
2550 // Draw hidden token count
2551 __pHiddenTokenCountVisualElement->SetBounds(FloatRectangle(__hiddenTokenDisplayCountBounds.x,
2552 __hiddenTokenDisplayCountBounds.y, __hiddenTokenDisplayCountBounds.width, __hiddenTokenDisplayCountBounds.height));
2554 pEditVisualElement->AttachChild(*__pHiddenTokenCountVisualElement);
2558 __scrollValue = __autoShrinkAlignmentValue;
2559 r = CalculateTokenPositionFromIndex(0);
2560 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
2562 int totalScrollValue = __maxScrollValue + (__pTokenEdit->GetBounds().height - GetInitialBounds().height);
2564 if (totalScrollValue > 0)
2566 __isNeedToScroll = true;
2567 __maxScrollValue = totalScrollValue;
2568 __isTokenScrolling = true;
2569 if (__lineAdded > 0)
2571 __isScrollValueChanged = true;
2572 __isScrollValueModified = false;
2576 Rectangle intialWindowBounds = GetInitialBounds();
2577 SetFlexBounds(intialWindowBounds);
2579 SetEditingTokenTextBounds(__edittingTokenIndex, false);
2581 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2584 return _EditPresenter::OnFocusLost();
2588 _TokenEditPresenter::SetFlexBounds(const Rectangle& bounds)
2590 if (__pTokenEdit->GetBounds().height > bounds.height)
2592 if (__lineAdded > 0)
2597 return _EditPresenter::SetFlexBounds(bounds);
2601 _TokenEditPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
2603 int tokenIndex = GetTokenIndexFromCoordinate(touchinfo.GetCurrentPosition());
2605 if (tokenIndex != -1)
2610 return _EditPresenter::OnTouchPressed(source, touchinfo);
2614 _TokenEditPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
2616 ProcessTokeningByTouchEvent(source, touchinfo);
2618 if (__prevScrollValue)
2620 __prevScrollValue = 0;
2621 __isTokenScrolling = false;
2624 _TouchInfo TouchInfo(touchinfo);
2625 _Token* pToken = null;
2626 if (__edittingTokenIndex >= 0)
2628 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
2631 Point point(touchinfo.GetCurrentPosition().x - pToken->displayRect.x, touchinfo.GetCurrentPosition().y - pToken->displayRect.y);
2632 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
2634 _EditPresenter::OnTouchReleased(source, TouchInfo);
2635 __previousCursorPosition = GetCursorPosition();
2639 _EditPresenter::OnTouchReleased(source, touchinfo);
2646 _TokenEditPresenter::OnInputConnectionTextCommitted(InputConnection& source, const String& committedText)
2648 OnTextCommitted(committedText);
2652 _TokenEditPresenter::OnTextCommitted(const String& commitText)
2654 result r = E_SUCCESS;
2655 char enterText[2] = {'\n', };
2656 if (commitText == enterText)
2658 if (__edittingTokenIndex != -1)
2660 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2661 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
2663 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2664 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
2666 _Token* pToken = null;
2667 _VisualElement* pTokenVisualElement = null;
2669 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
2673 pTokenVisualElement = pToken->GetVisualElement();
2674 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
2676 if (pCursorVisualElement->GetParent() != pEditVisualElement)
2678 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
2679 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
2681 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2682 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
2686 String inputTokenString = GetText();
2687 String replacementString = inputTokenString;
2688 bool enable = false;
2690 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
2693 inputTokenString = replacementString;
2696 r = RemoveTokenAt(__edittingTokenIndex);
2697 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2699 if (inputTokenString.GetLength() > 0)
2701 r = InsertTokenAt(__edittingTokenIndex, inputTokenString);
2702 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2704 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
2705 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
2707 pToken->currTokenLength = inputTokenString.GetLength();
2710 CalculateTokenPositionFromIndex(0);
2711 int lastTokenIndex = GetTokenCount() - 1;
2712 for (int i = 0; i < lastTokenIndex + 1; i++)
2714 _Token* pToken = null;
2715 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2719 pToken->SetBounds(pToken->displayRect);
2723 __pressedTokenIndex = -1;
2724 __isTokenEditingFinished = true;
2725 __edittingTokenIndex = -1;
2726 __isEditingToken = false;
2728 SetCursorDisabled(false);
2730 if (inputTokenString.GetLength() <= 0)
2732 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
2738 if (GetText().GetLength() > 0)
2743 for (int i = 0; i < __pTokenList->GetCount(); i++)
2745 TrimTokenAndAdjustEllipsisAt(i);
2746 InitializeTokenVisibilityAt(i);
2749 SetCursorDisabled(true);
2750 __pTokenEdit->Draw();
2751 SetCursorDisabled(false);
2757 _EditPresenter::OnTextCommitted(commitText);
2758 __previousCursorPosition = GetCursorPosition();
2760 _Token* pToken = null;
2761 if (__edittingTokenIndex >= 0)
2763 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
2764 SysTryReturnVoidResult(NID_UI_CTRL, pToken, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
2766 pToken->ResetToken(GetText());
2767 TrimTokenAndAdjustEllipsisAt(__edittingTokenIndex);
2769 int tokenHeight = 0;
2770 int tokenVerticalSpacing = 0;
2771 int tokenTextLeftMargin = 0;
2773 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2774 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
2775 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
2776 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
2778 Rectangle tempTextDspRect;
2779 tempTextDspRect.x += tokenTextLeftMargin;
2780 tempTextDspRect.y += tokenVerticalSpacing / 2;
2781 tempTextDspRect.width = pToken->GetTextPixelWidth();
2782 tempTextDspRect.height = tokenHeight;
2784 if (pToken->GetTextPixelWidth() > (pToken->displayRect.width - tokenTextLeftMargin - 20))
2786 tempTextDspRect.width = pToken->displayRect.width - tokenTextLeftMargin - 20;
2788 SetTextBounds(tempTextDspRect);
2790 if (GetCursorPosition() > pToken->currTokenLength)
2792 _EditPresenter::SetCursorPosition(pToken->currTokenLength);
2796 _EditPresenter::SetCursorPosition(GetCursorPosition());
2801 if (__isEditingToken == false)
2803 __pressedTokenIndex = -1;
2804 SetCursorDisabled(false);
2807 int tokenTopMargin = 0;
2809 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2810 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
2812 Rectangle textBounds = GetTextBounds();
2813 textBounds.height = __pTokenEdit->GetTextSize() + (2 * tokenTopMargin);
2815 SetTextBounds(textBounds);
2818 CheckTokenScrolling(true);
2819 __pTokenEdit->Draw();
2825 _TokenEditPresenter::DeleteSurroundingText(InputConnection& source, int offset, int charCount)
2827 OnSurroundingTextDeleted(offset, charCount);
2831 _TokenEditPresenter::OnSurroundingTextDeleted(int offset, int charCount)
2833 __lastTokenIndex = GetTokenCount() - 1;
2834 int cursorPosition = 0;
2838 if ((offset == -1) && (charCount == 1))
2840 if (GetTextLength() == 0 && GetTokenCount()) // There is no candidate token.
2842 if (__isEditingToken == true)
2844 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2845 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
2847 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2848 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
2850 _Token* pToken = null;
2851 _VisualElement* pTokenVisualElement = null;
2853 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
2857 pTokenVisualElement = pToken->GetVisualElement();
2858 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
2860 if (pCursorVisualElement->GetParent() != pEditVisualElement)
2862 result r = E_SUCCESS;
2863 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
2864 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
2866 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2867 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
2871 RemoveTokenAt(__edittingTokenIndex);
2873 CalculateTokenPositionFromIndex(__edittingTokenIndex);
2874 for (int i = __edittingTokenIndex; i < __lastTokenIndex + 1; i++)
2876 _Token* pToken = null;
2877 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2880 pToken->SetBounds(pToken->displayRect);
2884 __pressedTokenIndex = -1;
2885 __edittingTokenIndex = -1;
2886 __isEditingToken = false;
2887 __isTokenEditingFinished = true;
2889 else if (__pressedTokenIndex != -1)
2891 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2892 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
2894 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2895 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
2897 _Token* pToken = null;
2898 _VisualElement* pTokenVisualElement = null;
2900 pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
2904 pTokenVisualElement = pToken->GetVisualElement();
2905 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
2907 if (pCursorVisualElement->GetParent() != pEditVisualElement)
2909 result r = E_SUCCESS;
2910 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
2911 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
2913 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2914 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
2918 RemoveTokenAt(__pressedTokenIndex);
2920 CalculateTokenPositionFromIndex(__pressedTokenIndex);
2921 for (int i = __pressedTokenIndex; i < __lastTokenIndex + 1; i++)
2923 _Token* pToken = null;
2924 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2928 pToken->SetBounds(pToken->displayRect);
2934 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2935 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
2937 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2938 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
2940 _Token* pToken = null;
2941 _VisualElement* pTokenVisualElement = null;
2942 if (__animatingIndex == (GetTokenCount() - 1))
2944 pToken = static_cast <_Token*>(__pTokenList->GetAt(GetTokenCount() - 1));
2947 pTokenVisualElement = pToken->GetVisualElement();
2948 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
2949 pTokenVisualElement->RemoveAnimation(L"TokenAnimation");
2952 pToken = static_cast <_Token*>(__pTokenList->GetAt(GetTokenCount() - 1));
2955 pTokenVisualElement = pToken->GetVisualElement();
2956 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
2958 if (pCursorVisualElement->GetParent() != pEditVisualElement)
2960 result r = E_SUCCESS;
2961 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
2962 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
2964 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2965 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
2969 __animatingIndex = GetTokenCount() - 1;
2971 if (pTokenVisualElement && __animatingIndex >= 0)
2973 VisualElementAnimation* pAnimation = CreateAnimationN(*pTokenVisualElement, false);
2974 pTokenVisualElement->AddAnimation(L"TokenAnimation", *pAnimation);
2979 __pTokenEdit->Invalidate();
2984 if (__pressedTokenIndex >= 0 && __edittingTokenIndex < 0 && !__isEditingToken)
2986 RemoveTokenAt(__pressedTokenIndex);
2987 __pTokenEdit->Invalidate();
2991 //Backspace on Blocked text, delete full block
2992 if (IsBlocked() == true)
2994 GetBlockRange(start, end);
2998 cursorPosition = GetCursorPosition();
2999 start = cursorPosition + offset;
3004 end = start + charCount;
3005 if (end > GetTextLength())
3011 DeleteText(start, end);
3012 __previousCursorPosition = start;
3014 if (IsCopyPastePopupVisible())
3016 InitializeCopyPasteManager();
3018 if (IsBlocked() == true)
3022 if (__isEditingToken != true)
3027 __pTokenEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
3030 cursorPosition = GetCursorPosition();
3031 start = cursorPosition + offset;
3036 end = start + charCount;
3037 if (end > GetTextLength())
3042 Rectangle currBounds = __pTokenEdit->GetBounds();
3043 DeleteText(start, end);
3044 __previousCursorPosition = start;
3045 if (__isEditingToken != true)
3051 _Token* pToken = null;
3053 if (__edittingTokenIndex >= 0 && __isEditingToken)
3055 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
3059 int tokenHeight = 0;
3060 int tokenVerticalSpacing = 0;
3061 int tokenTextLeftMargin = 0;
3064 SetCursorPosition(__previousCursorPosition);
3066 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3067 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
3068 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
3069 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
3071 Rectangle tempTextDspRect;
3072 tempTextDspRect.x += tokenTextLeftMargin;
3073 tempTextDspRect.y += tokenVerticalSpacing/2;
3074 tempTextDspRect.width = pToken->GetTextPixelWidth();
3075 tempTextDspRect.height = tokenHeight;
3077 SetTextBounds(tempTextDspRect);
3078 _EditPresenter::SetCursorPosition(start);
3080 pToken->ResetToken(GetText());
3081 TrimTokenAndAdjustEllipsisAt(__edittingTokenIndex);
3085 __pTokenEdit->Draw();
3089 _TokenEditPresenter::OnTapGestureDetected(void)
3091 __isPopupVisible = true;
3093 if (__pressedTokenIndex != -1)
3097 return _EditPresenter::OnTapGestureDetected();
3101 _TokenEditPresenter::OnLongPressGestureDetected(void)
3103 __isLongPressed = true;
3104 if (__pressedTokenIndex != -1)
3108 return _EditPresenter::OnLongPressGestureDetected();
3112 _TokenEditPresenter::OnCursorTimerExpired(void)
3114 if (__edittingTokenIndex != -1)
3122 Rectangle cursorRect;
3124 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
3125 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
3127 Rectangle cursorDspRect = pToken->displayRect;
3128 cursorDspRect.x = 12;
3129 cursorDspRect.y = 10;
3130 if (CalculateCursorBounds(cursorDspRect, cursorRect) != E_SUCCESS)
3136 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3137 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3139 Canvas* pCursorCanvas = pCursorVisualElement->GetCanvasN();
3140 SysTryReturnVoidResult(NID_UI_CTRL, pCursorCanvas != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get canvas of cursor visual element.");
3142 bool cursorEnable = IsCursorEnabled();
3144 pCursorVisualElement->SetBounds(FloatRectangle(cursorRect.x, cursorRect.y, cursorRect.width, cursorRect.height));
3145 DrawCursor(*pCursorCanvas, cursorRect, cursorEnable);
3149 cursorEnable = false;
3153 cursorEnable = true;
3155 SetCursorEnabled(cursorEnable);
3157 pCursorCanvas->Show();
3158 delete pCursorCanvas;
3164 _EditPresenter::OnCursorTimerExpired();
3169 _TokenEditPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
3171 if (GetTokenCount())
3173 SetTokenBoundsByTouchInfo(touchinfo);
3174 return false; // Event through
3178 return _EditPresenter::OnTouchMoved(source, touchinfo);
3184 _TokenEditPresenter::OnVisualElementAnimationFinished (const Tizen::Ui::Animations::VisualElementAnimation &animation, const Tizen::Base::String &keyName, Tizen::Ui::Animations::VisualElement &target, bool completedNormally)
3186 RemoveTokenAt(GetTokenCount() - 1);
3187 CalculateTokenPositionFromIndex(GetTokenCount() - 1);
3189 for (int i = GetTokenCount() - 1; i < GetTokenCount() - 1 + 1; i++)
3191 _Token* pToken = null;
3192 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3196 pToken->SetBounds(pToken->displayRect);
3199 if (__lastTokenIndex == __pressedTokenIndex)
3201 __pressedTokenIndex--;
3204 __animatingIndex = -1;
3213 _TokenEditPresenter::ResizeTokenAndAdjustEllipsis(int index, int value, bool isTokenShrink)
3217 int trimValue = value;
3218 int extraTrimValue = 0;
3220 _Token* pToken = null;
3221 pToken = static_cast <_Token*>(__pTokenList->GetAt(index));
3222 SysTryReturn(NID_UI_CTRL, pToken != null, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3224 int tokenMinimumSize = 0;
3226 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3228 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_MIN_WIDTH, orientation, tokenMinimumSize);
3230 if ((pToken->displayRect.width - trimValue) >= tokenMinimumSize)
3232 pToken->displayRect.width -= trimValue;
3236 extraTrimValue = (tokenMinimumSize - (pToken->displayRect.width - trimValue));
3237 pToken->displayRect.width = tokenMinimumSize;
3240 InitializeTokenVisibilityAt(index);
3242 pToken->pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
3243 pToken->pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
3245 return extraTrimValue;
3249 int expandValue = value;
3250 int extraExpandValue = 0;
3252 _Token* pToken = null;
3253 pToken = static_cast <_Token*>(__pTokenList->GetAt(index));
3254 SysTryReturn(NID_UI_CTRL, pToken != null, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3256 int tokenTextLeftMargin = 0;
3257 int tokenTextRightMargin = 0;
3259 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3261 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
3262 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
3264 int tokenTextWidth = pToken->GetTextPixelWidth();
3266 int tokenDisplayRectWidth = tokenTextLeftMargin + tokenTextWidth + tokenTextRightMargin;
3267 if ((pToken->displayRect.width + expandValue) <= tokenDisplayRectWidth)
3269 pToken->displayRect.width += expandValue;
3273 extraExpandValue = ((pToken->displayRect.width + expandValue) - tokenDisplayRectWidth);
3274 pToken->displayRect.width = tokenDisplayRectWidth;
3277 InitializeTokenVisibilityAt(index);
3279 pToken->pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
3280 pToken->pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
3282 return extraExpandValue;
3289 _TokenEditPresenter::PickToken(int index, Rectangle tokenDispRect, bool isTokenShrink)
3291 int tokenCount = __pTokenList->GetCount();
3293 int tokenMinimumSize = 0;
3294 int tokenTextLeftMargin = 0;
3295 int tokenTextRightMargin = 0;
3297 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3299 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_MIN_WIDTH, orientation, tokenMinimumSize);
3300 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
3301 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
3305 if (index < tokenCount)
3307 for (int i = index; i >= 0; i--)
3309 _Token* pToken = null;
3310 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3311 SysTryReturn(NID_UI_CTRL, pToken != null, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3313 Rectangle tokenRect = pToken->displayRect;
3314 if (tokenDispRect.y == tokenRect.y)
3316 if (tokenRect.width > tokenMinimumSize)
3326 for (int i = index; i < tokenCount; i++)
3328 _Token* pToken = null;
3329 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3330 SysTryReturn(NID_UI_CTRL, pToken != null, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3332 Rectangle tokenRect = pToken->displayRect;
3333 if (tokenDispRect.y == tokenRect.y)
3335 int tokenTextWidth = pToken->GetTextPixelWidth();
3337 if (tokenRect.width < (tokenTextLeftMargin + tokenTextWidth + tokenTextRightMargin))
3349 _TokenEditPresenter::RepositionToken(int currentTokenIndex, int moveDistance, bool isTokenShrink)
3351 int tokenCount = __pTokenList->GetCount();
3353 _Token* pCurrentToken = null;
3354 pCurrentToken = static_cast <_Token*>(__pTokenList->GetAt(currentTokenIndex));
3355 SysTryReturnVoidResult(NID_UI_CTRL, pCurrentToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3357 Rectangle currentTokenRect = pCurrentToken->displayRect;
3359 if (currentTokenIndex < (tokenCount - 1))
3361 for (int i = currentTokenIndex + 1; i < tokenCount; i++)
3363 _Token* pToken = null;
3364 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3365 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3369 Rectangle tokenRect = pToken->displayRect;
3370 if (currentTokenRect.y == tokenRect.y)
3374 pToken->displayRect.x -= moveDistance;
3378 pToken->displayRect.x += moveDistance;
3381 InitializeTokenVisibilityAt(i);
3395 _TokenEditPresenter::ShrinkTokens()
3397 int tokenTextRightMargin = 0;
3399 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3400 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
3402 int tokenCount = __pTokenList->GetCount();
3403 Rectangle currentEditBounds = __pTokenEdit->GetBounds();
3405 for (int i = 0; i < tokenCount; i++)
3407 bool isTokenPicked = false;
3408 _Token* pToken = null;
3409 _Token* pNextToken = null;
3411 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3412 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3414 Rectangle tokenRect = pToken->displayRect;
3416 Rectangle nextTokenRect;
3417 if (i < tokenCount - 1)
3419 pNextToken = static_cast <_Token*>(__pTokenList->GetAt(i + 1));
3420 SysTryReturnVoidResult(NID_UI_CTRL, pNextToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3422 nextTokenRect = pNextToken->displayRect;
3427 if (nextTokenRect.y > tokenRect.y)
3429 isTokenPicked = true;
3434 isTokenPicked = true;
3437 //"pToken" (isTokenPicked = true) is the last token in a row
3438 if (isTokenPicked == false)
3443 int tokenEndPoint = tokenRect.x + tokenRect.width + tokenTextRightMargin + __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_RIGHT_MARGIN);
3444 if (tokenEndPoint <= currentEditBounds.width)
3449 //Trimming Token required
3450 int trimValue = tokenEndPoint - currentEditBounds.width;
3452 while (trimValue > 0)
3454 int tokenIndex = PickToken(i, tokenRect, true);
3455 if (tokenIndex >= 0)
3457 int extraTrimValue = ResizeTokenAndAdjustEllipsis(tokenIndex, trimValue, true);
3458 if (extraTrimValue < 0)
3460 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3464 if ((trimValue - extraTrimValue) > 0)
3466 RepositionToken(tokenIndex, (trimValue - extraTrimValue), true);
3469 trimValue = extraTrimValue;
3482 _TokenEditPresenter::GetPickedTokenEndPoint(int index, Tizen::Graphics::Rectangle tokenDispRect)
3484 int tokenTextRightMargin = 0;
3487 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3488 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
3490 int marginValue = tokenTextRightMargin + __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_RIGHT_MARGIN);;
3492 Rectangle lastTokenRect(0,0,0,0);
3494 int tokenCount = __pTokenList->GetCount();
3495 for (int i = index; i < tokenCount; i++)
3497 _Token* pToken = null;
3498 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3499 SysTryReturn(NID_UI_CTRL, pToken != null, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3501 Rectangle tokenRect = pToken->displayRect;
3502 if (tokenDispRect.y == tokenRect.y)
3504 lastTokenRect = tokenRect;
3512 endValue = marginValue + lastTokenRect.x + lastTokenRect.width;
3518 _TokenEditPresenter::ExpandTokens()
3520 int tokenCount = __pTokenList->GetCount();
3521 Rectangle currentEditBounds = __pTokenEdit->GetBounds();
3523 for (int i = tokenCount - 1; i >= 0; i--)
3525 bool isTokenPicked = false;
3526 _Token* pToken = null;
3527 _Token* pPrevToken = null;
3529 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3530 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3532 Rectangle tokenRect = pToken->displayRect;
3534 Rectangle prevTokenRect;
3537 pPrevToken = static_cast <_Token*>(__pTokenList->GetAt(i - 1));
3538 SysTryReturnVoidResult(NID_UI_CTRL, pPrevToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3540 prevTokenRect = pPrevToken->displayRect;
3545 if (prevTokenRect.y < tokenRect.y)
3547 isTokenPicked = true;
3552 isTokenPicked = true;
3555 //"pToken" (isTokenPicked = true) is the first token in a row
3556 if (isTokenPicked == false)
3561 int tokenEndPoint = GetPickedTokenEndPoint(i, tokenRect);;
3563 if ((tokenEndPoint == 0) || (tokenEndPoint >= currentEditBounds.width))
3568 //Expanding Token required
3569 int expandValue = currentEditBounds.width - tokenEndPoint;
3571 while (expandValue > 0)
3573 int tokenIndex = PickToken(i, tokenRect, false);
3574 if (tokenIndex >= 0)
3576 int extraExpandValue = ResizeTokenAndAdjustEllipsis(tokenIndex, expandValue, false);
3577 if (extraExpandValue < 0)
3579 SysLogException(NID_UI_CTRL, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3583 if ((expandValue - extraExpandValue) > 0)
3585 RepositionToken(tokenIndex, (expandValue - extraExpandValue), false);
3588 expandValue = extraExpandValue;
3601 _TokenEditPresenter::OnBoundsChanged(void)
3603 if (!__isTokenEditPresenterInitialized)
3608 int tokenCount = __pTokenList->GetCount();
3609 SysTryReturnVoidResult(NID_UI_CTRL, tokenCount > 0, E_SUCCESS, "No Tokens available.");
3611 Rectangle tokenEditBounds = __pTokenEdit->GetBounds();
3613 if (tokenEditBounds.width < __previousEditBounds.width)
3617 else if (tokenEditBounds.width > __previousEditBounds.width)
3622 __previousEditBounds = tokenEditBounds;
3628 }}} //Tizen::Ui::Controls