2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FUiCtrl_TokenEditPresenter.cpp
19 * @brief This is the implementation file for the _TokenEditPresenter class.
21 #include <FGrp_BitmapImpl.h>
22 #include <FUiAnimVisualElementAnimationGroup.h>
23 #include <FGrp_TextTextSimple.h>
24 #include <FGrp_FontImpl.h>
25 #include "FUiAnim_VisualElement.h"
26 #include "FUi_UiTouchEvent.h"
27 #include "FUiCtrl_TokenEdit.h"
28 #include "FUiCtrl_TokenEditPresenter.h"
29 #include "FUiCtrl_Scroll.h"
31 #include "FUi_CoordinateSystemUtils.h"
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Runtime;
35 using namespace Tizen::Media;
36 using namespace Tizen::Ui::Animations;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Graphics::_Text;
40 namespace Tizen { namespace Ui { namespace Controls
44 SineTimingFunction::CalculateProgress(float timeProgress) const
46 const float segments[3][3] = {{0.0f, 0.01f, 0.37f}, {0.37f, 0.72f, 0.888f}, {0.888f, 0.9999f, 1.0f}};
47 float timeProgressValue = timeProgress;
48 int segmentsLength = 3; //Length of the segments array
49 int index = (int)floor(segmentsLength * timeProgressValue);
50 if (index >= segmentsLength)
52 index = segmentsLength - 1;
55 float progressValue = (timeProgressValue - index * (1.0 / segmentsLength)) * segmentsLength;
56 float segmentAtIndex[3];
57 for(int i = 0; i < 3; i++)
59 segmentAtIndex[i] = segments[index][i];
61 float ret = 0 + 1 * (segmentAtIndex[0] + progressValue * (2 * (1 - progressValue) * (segmentAtIndex[1] - segmentAtIndex[0]) + progressValue * (segmentAtIndex[2] - segmentAtIndex[0])));
71 result Construct(const String& text, Font* pEditFont);
72 virtual ~_Token(void);
73 float GetTextPixelWidth(void) const;
74 wchar_t* GetText(void) const;
75 result ResetToken(const String& text);
76 result SetBounds(FloatRectangle bounds);
77 _VisualElement* GetVisualElement(void) const;
78 _Token(const _Token& src);
79 _Token& operator =(const _Token& value);
82 FloatRectangle displayRect;
83 TextObject* pTextObject;
86 bool isImplicitAnimation;
89 wchar_t* __pTextBuffer;
90 float __textPixelWidth;
91 float __textPixelHeight;
92 _VisualElement* __pVisualElement;
99 , isImplicitAnimation(true)
101 , __pTextBuffer(null)
102 , __textPixelWidth(0.0f)
103 , __textPixelHeight(0.0f)
104 , __pVisualElement(null)
109 _Token::Construct(const String& text, Font* pEditFont)
111 result r = E_SUCCESS;
113 currTokenLength = text.GetLength();
114 float tokenFontSize = 0.0f;
116 pTextObject = new (std::nothrow) TextObject;
117 SysTryReturnResult(NID_UI_CTRL, pTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
119 // for default initialize.
120 r = pTextObject->Construct();
121 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
123 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
124 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
126 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
127 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
129 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, tokenFontSize);
131 pFont = _FontImpl::CloneN(*pEditFont);
133 SysTryCatch(NID_UI_CTRL, pFont != null, , r, "[%s] Propagating.", GetErrorMessage(r));
135 (_FontImpl::GetInstance(*pFont))->SetStyle(FONT_STYLE_PLAIN);
136 (_FontImpl::GetInstance(*pFont))->SetSize(tokenFontSize);
138 r = pTextObject->SetFont(pFont, 0, pTextObject->GetTextLength());
139 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
141 r = ResetToken(text);
142 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
144 __pVisualElement = new (std::nothrow) _VisualElement;
145 SysTryCatch(NID_UI_CTRL, __pVisualElement != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
147 r = __pVisualElement->Construct();
148 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct _VisualElement.", GetErrorMessage(r));
150 __pVisualElement->SetImplicitAnimationEnabled(false);
151 __pVisualElement->SetOpacity(0.0f);
159 if (__pVisualElement)
161 __pVisualElement->Destroy();
162 __pVisualElement = null;
172 _Token::ResetToken(const String& text)
174 result r = E_SUCCESS;
175 FloatDimension textSize;
179 delete[] __pTextBuffer;
180 __pTextBuffer = null;
183 int length = text.GetLength();
184 wchar_t* pTempString = const_cast <wchar_t*>(text.GetPointer());
185 SysTryReturnResult(NID_UI_CTRL, pTempString != null, E_SYSTEM, "A system error has occurred. Token text string is null.");
187 __pTextBuffer = new (std::nothrow) wchar_t[(length + 1) * (sizeof(wchar_t))];
188 SysTryReturnResult(NID_UI_CTRL, __pTextBuffer != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
190 for (int i = 0; i < length; i++)
192 __pTextBuffer[i] = pTempString[i];
194 __pTextBuffer[length] = 0;
196 pTextObject->RemoveAll(true);
198 TextSimple* pSimpleText = new (std::nothrow)TextSimple(__pTextBuffer, length, TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, pFont);
199 SysTryCatch(NID_UI_CTRL, pSimpleText != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
201 r = pTextObject->AppendElement(*pSimpleText);
202 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
204 textSize = pTextObject->GetTextExtentF(0, length);
205 __textPixelWidth = textSize.width;
206 __textPixelHeight = textSize.height;
208 r = pTextObject->Compose();
210 currTokenLength = length;
215 delete[] __pTextBuffer;
216 __pTextBuffer = null;
225 _Token::SetBounds(FloatRectangle bounds)
227 result r = E_SUCCESS;
228 displayRect = bounds;
229 if (__pVisualElement)
231 __pVisualElement->SetBounds(bounds);
237 _Token::GetVisualElement(void) const
239 return __pVisualElement;
242 _Token::~_Token(void)
250 delete[] __pTextBuffer;
251 __pTextBuffer = null;
253 if (__pVisualElement)
255 __pVisualElement->Destroy();
256 __pVisualElement = null;
261 _Token::GetTextPixelWidth(void) const
263 return __textPixelWidth;
267 _Token::GetText(void) const
269 return __pTextBuffer;
272 _TokenEditPresenter::_TokenEditPresenter(void)
275 , __pTokenBgBitmap(null)
276 , __pTokenBgNormalEffectBitmap(null)
277 , __pTokenBgPressedEffectBitmap(null)
278 , __pTokenBgReplacementFocusBitmap(null)
279 , __pTokenBgFocusEffectBitmap(null)
280 , __pressedTokenIndex(-1)
281 , __isEditingToken(false)
282 , __edittingTokenIndex(-1)
283 , __clientRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
284 , __initTextRect(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
285 , __isEditModeEnabled(true)
286 , __pDescriptionTextVisualElement(null)
287 , __pDescriptionTextTextObject(null)
288 , __isTokenEditingFinished(false)
289 , __prevScrollValue(0.0f)
290 , __scrollValue(0.0f)
291 , __isTokenScrolling(false)
292 , __isNeedToScroll(false)
293 , __maxScrollValue(0.0f)
294 , __autoShrink(false)
295 , __descriptionText(String())
296 , __isPopupVisible(false)
297 , __isLongPressed(false)
298 , __lineSpacing(0.0f)
299 , __animatingIndex(-1)
300 , __lastTokenIndex(-1)
301 , __pTimingFunction(null)
302 , __descriptionTextRectForScroll(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f))
303 , __previousTitleWidth(-1.0f)
304 , __isTokenEditPresenterInitialized(false)
306 , __previousCursorPosition(0)
307 , __isScrollValueChanged(false)
309 , __isScrollValueModified(false)
310 , __isTouchMoveInProgress(false)
311 , __isTitleSliding(false)
312 , __touchPressInfo(FloatPoint(-1.0f, -1.0f))
313 , __editContentFontSize(0.0f)
314 , __trackTokenIndex(-1)
315 , __focusedTokenIndex(-1)
316 , __focusedEditingTokenIndex(-1)
317 , __isAnimationInProgress(false)
322 _TokenEditPresenter::InitializeDescriptionText(void)
324 result r = E_SUCCESS;
325 float descriptionTextSize = 0.0f;
327 float editFontSize = 0.0f;
329 __pDescriptionTextTextObject = new (std::nothrow) TextObject();
330 SysTryReturnResult(NID_UI_CTRL, __pDescriptionTextTextObject != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
332 // for default initialize.
333 r = __pDescriptionTextTextObject->Construct();
334 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
336 r = __pDescriptionTextTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
337 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
339 r = __pDescriptionTextTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
340 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
342 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, descriptionTextSize);
345 SysTryCatch(NID_UI_CTRL, pFont != null, , r, "[%s] Propagating.", GetErrorMessage(r));
347 editFontSize = GetTextSize();
348 (_FontImpl::GetInstance(*pFont))->SetSize(descriptionTextSize);
350 r = __pDescriptionTextTextObject->SetFont(pFont, 0, __pDescriptionTextTextObject->GetTextLength());
351 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
353 (_FontImpl::GetInstance(*pFont))->SetSize(editFontSize);
359 delete __pDescriptionTextTextObject;
360 __pDescriptionTextTextObject = null;
365 _TokenEditPresenter::~_TokenEditPresenter(void)
367 DisposeTokenEditPresenter();
371 _TokenEditPresenter::DisposeTokenEditPresenter(void)
373 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
374 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
376 if (pEditVisualElement && pCursorVisualElement)
378 VisualElement* pCursorParent = pCursorVisualElement->GetParent();
379 if (pCursorParent != pEditVisualElement)
383 pCursorParent->DetachChild(*pCursorVisualElement);
384 pEditVisualElement->AttachChild(*pCursorVisualElement);
391 __pTokenList->RemoveAll(true);
396 delete __pTokenBgBitmap;
397 __pTokenBgBitmap = null;
399 delete __pTokenBgNormalEffectBitmap;
400 __pTokenBgNormalEffectBitmap = null;
402 delete __pTokenBgPressedEffectBitmap;
403 __pTokenBgPressedEffectBitmap = null;
405 delete __pTokenBgReplacementFocusBitmap;
406 __pTokenBgReplacementFocusBitmap = null;
408 delete __pTokenBgFocusEffectBitmap;
409 __pTokenBgFocusEffectBitmap = null;
411 if (__pDescriptionTextVisualElement)
413 __pDescriptionTextVisualElement->Destroy();
414 __pDescriptionTextVisualElement = null;
417 delete __pDescriptionTextTextObject;
418 __pDescriptionTextTextObject = null;
420 if (__pTimingFunction)
422 delete __pTimingFunction;
423 __pTimingFunction = null;
430 _TokenEditPresenter::CreateTokenEditPresenterN(void)
432 _TokenEditPresenter* pPresenter = new (std::nothrow) _TokenEditPresenter();
433 SysTryReturn(NID_UI_CTRL, pPresenter != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
439 _TokenEditPresenter::Initialize(const _Control& control)
441 result r = E_SUCCESS;
443 r = _EditPresenter::Initialize(control);
444 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
446 r = InitializeDescriptionText();
447 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
449 TextObject* pTextObject = GetTextObject();
452 pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
453 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
454 pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
455 pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_LEFT | TEXT_OBJECT_ALIGNMENT_MIDDLE);
458 __pTokenEdit = dynamic_cast <_TokenEdit*>(GetEditView());
459 SysTryReturnResult(NID_UI_CTRL, __pTokenEdit != null, E_SYSTEM, "A system error has occurred. The _Token instance is null.");
461 _TokenEditModel* pTokenEditModel = new (std::nothrow) _TokenEditModel();
462 SysTryReturnResult(NID_UI_CTRL, pTokenEditModel != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
464 SetModel(*pTokenEditModel);
466 SetKeypadEnabled(true);
468 float tokenLeftMargin = 0.0f;
469 float tokenRightMargin = 0.0f;
470 float tokenTopMargin = 0.0f;
471 float tokenBottomMargin = 0.0f;
472 float tokenHeight = 0.0f;
473 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
474 Color focusTokenColor;
475 Bitmap* pTokenBgFocusBitmap = null;
477 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, tokenLeftMargin);
478 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, tokenRightMargin);
479 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
480 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
481 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
482 GET_COLOR_CONFIG(TOKENEDIT::BG_FOCUS, focusTokenColor);
484 // For drawing token in specific area
485 __clientRect.x = tokenLeftMargin;
486 __clientRect.y = tokenTopMargin;
487 __clientRect.width = __pTokenEdit->GetBoundsF().width - tokenLeftMargin - tokenRightMargin;
488 __clientRect.height = __pTokenEdit->GetBoundsF().height - tokenTopMargin - tokenBottomMargin;
490 __initTextRect = GetTextBoundsF();
492 FloatRectangle tempDspRect(__initTextRect.x, __initTextRect.y, __clientRect.width, tokenHeight);
493 SetTextBounds(tempDspRect);
495 float textSize = 0.0f;
496 GET_SHAPE_CONFIG(TOKENEDIT::TEXT_SIZE, orientation, textSize);
498 __editContentFontSize = textSize;
500 _EditPresenter::SetTextSize(__editContentFontSize);
502 __pTokenList = new (std::nothrow) Collection::LinkedList();
503 SysTryCatch(NID_UI_CTRL, __pTokenList != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
507 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgBitmap);
508 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
510 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_NORMAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgNormalEffectBitmap);
511 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
513 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_PRESSED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgPressedEffectBitmap);
514 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
516 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_FOCUS, BITMAP_PIXEL_FORMAT_ARGB8888, pTokenBgFocusBitmap);
517 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
519 __pTokenBgReplacementFocusBitmap = _BitmapImpl::GetColorReplacedBitmapN(
520 *pTokenBgFocusBitmap,Color::GetColor(COLOR_ID_MAGENTA), focusTokenColor);
521 SysTryCatch(NID_UI_CTRL, __pTokenBgReplacementFocusBitmap != null, , r, "[%s] Propagating.", GetErrorMessage(r));
523 r = GET_BITMAP_CONFIG_N(TOKENEDIT::BG_FOCUS_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pTokenBgFocusEffectBitmap);
524 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
526 delete pTokenBgFocusBitmap;
527 pTokenBgFocusBitmap = null;
530 __isTokenEditPresenterInitialized = true;
532 __previousCursorPosition = GetCursorPosition();
538 delete pTokenEditModel;
539 pTokenEditModel = null;
541 delete __pTokenBgBitmap;
542 __pTokenBgBitmap = null;
544 delete __pTokenBgNormalEffectBitmap;
545 __pTokenBgNormalEffectBitmap = null;
547 delete __pTokenBgPressedEffectBitmap;
548 __pTokenBgPressedEffectBitmap = null;
550 delete pTokenBgFocusBitmap;
551 pTokenBgFocusBitmap = null;
553 delete __pTokenBgReplacementFocusBitmap;
554 __pTokenBgReplacementFocusBitmap = null;
560 _TokenEditPresenter::DrawText(void)
562 bool isCustomBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_NORMAL);
563 //Checking IsBlocked() is additional check for handler movement in token edit mode
564 if ((__isEditingToken) && (__edittingTokenIndex >= 0))
566 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
569 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
570 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element of token.");
572 Canvas* pTokenCanvas = pTokenVisualElement->GetCanvasN();
573 SysTryReturnVoidResult(NID_UI_CTRL, pTokenCanvas != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get canvas of the token.");
575 FloatRectangle tokenRect(0.0f, 0.0f, pToken->displayRect.width, pToken->displayRect.height);
576 pTokenCanvas->SetBackgroundColor(Color(0));
577 pTokenCanvas->Clear();
579 Color selectedTokenColor = GetTokenEditColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED);
580 Bitmap* pReplacementColorBackgroundBitmap = null;
581 if (__pTokenBgBitmap)
583 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), selectedTokenColor);
585 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
587 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
591 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
596 pTokenCanvas->FillRectangle(selectedTokenColor, tokenRect);
599 if (__pTokenBgPressedEffectBitmap && (!isCustomBitmap))
601 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgPressedEffectBitmap))
603 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
607 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
611 _EditPresenter::DrawText(*pTokenCanvas);
616 delete pReplacementColorBackgroundBitmap;
621 _VisualElement* pTextVisualElement = null;
622 pTextVisualElement = GetTextVisualElement();
623 if (pTextVisualElement)
625 _EditPresenter::DrawText();
629 Canvas* pCanvas = __pTokenEdit->GetCanvasN();
630 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element of Control.");
632 _EditPresenter::DrawText(*pCanvas);
641 _TokenEditPresenter::Draw(Canvas& canvas)
643 if (!IsInitialized())
645 InitializeAtFirstDrawing();
647 if (IsFocused() == true)
653 canvas.SetBackgroundColor(Color(0, 0, 0, 0));
656 DrawBackground(canvas);
660 if (__pDescriptionTextTextObject->GetTextLength() != 0)
662 DrawDescriptionText();
665 if (GetTokenCount() != 0)
670 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
671 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
673 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
674 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
676 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
680 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
681 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "A system error has occurred. Failed to get visual element of token.");
683 if (__isEditingToken)
685 Canvas* pTokenCanvas = pTokenVisualElement->GetCanvasN();
686 SysTryReturnResult(NID_UI_CTRL, pTokenCanvas != null, E_SYSTEM, "A system error has occurred. Failed to get canvas of the token.");
688 _EditPresenter::DrawText(*pTokenCanvas);
702 SysTryReturnResult(NID_UI_CTRL, !__isEditingToken, E_SYSTEM, "An invalid argument is given.");
708 if (__isTokenEditingFinished)
710 __isEditingToken = false;
711 __edittingTokenIndex = -1;
712 _EditPresenter::SetTextSize(__editContentFontSize);
714 __isTokenEditingFinished = false;
721 _TokenEditPresenter::DrawToken(int count)
723 int drawStartIndex = 0;
725 float tokenTextLeftMargin = 0.0f;
726 float tokenVerticalSpacing = 0.0f;
727 bool isCustomBitmap = false;
729 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
731 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
733 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
734 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
736 isCustomBitmap = IS_CUSTOM_BITMAP(TOKENEDIT::BG_NORMAL);
740 tokenCount = __pTokenList->GetCount();
747 Color normalTokenColor;
748 Color selectedTokenColor;
750 for (int i = drawStartIndex; i < tokenCount; i++)
752 Bitmap* pReplacementColorBackgroundBitmap = null;
754 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
755 if (pToken == null || pToken->pTextObject == null)
757 SysLog(NID_UI_CTRL, "[E_SYSTEM] The _Token instance is null");
761 normalTokenColor = GetTokenEditColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL);
762 selectedTokenColor = GetTokenEditColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED);
764 _VisualElement* pTokenElement = pToken->GetVisualElement();
765 if (pTokenElement == null)
767 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. The _VisualElement instance is null");
771 bool isSelected = false;
772 Canvas* pTokenCanvas = pTokenElement->GetCanvasN();
773 if (pTokenCanvas == null)
775 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. The Canvas instance is null");
778 FloatRectangle tokenRect(0.0f, 0.0f, pToken->displayRect.width, pToken->displayRect.height);
779 pTokenCanvas->SetBackgroundColor(Color(0));
780 pTokenCanvas->Clear();
782 if (__pressedTokenIndex == i && IsFocused())
784 if (__pTokenBgBitmap)
786 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), selectedTokenColor);
788 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
790 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
794 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
799 pTokenCanvas->FillRectangle(selectedTokenColor, tokenRect);
803 if (__pTokenBgPressedEffectBitmap && (!isCustomBitmap))
805 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgPressedEffectBitmap))
807 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
811 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgPressedEffectBitmap);
819 if (__pTokenBgBitmap)
821 pReplacementColorBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pTokenBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), normalTokenColor);
823 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pReplacementColorBackgroundBitmap))
825 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
829 pTokenCanvas->DrawBitmap(tokenRect, *pReplacementColorBackgroundBitmap);
834 pTokenCanvas->FillRectangle(normalTokenColor, tokenRect);
838 if (__pTokenBgNormalEffectBitmap && (!isCustomBitmap))
840 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgNormalEffectBitmap))
842 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgNormalEffectBitmap);
846 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgNormalEffectBitmap);
851 if (__focusedTokenIndex == i && IsFocused() && (!__isEditingToken))
853 if (__pTokenBgReplacementFocusBitmap)
855 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgReplacementFocusBitmap))
857 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgReplacementFocusBitmap);
861 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgReplacementFocusBitmap);
865 if (__pTokenBgFocusEffectBitmap)
867 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pTokenBgFocusEffectBitmap))
869 pTokenCanvas->DrawNinePatchedBitmap(tokenRect, *__pTokenBgFocusEffectBitmap);
873 pTokenCanvas->DrawBitmap(tokenRect, *__pTokenBgFocusEffectBitmap);
879 pTokenElement->SetAnimationProvider(null);
880 if (pToken->isImplicitAnimation)
882 VisualElementAnimation* pAnimation = CreateAnimationN(*pTokenElement, true);
883 pTokenElement->AddAnimation(*pAnimation);
885 pToken->isImplicitAnimation = false;
888 if (!__isEditingToken || __pressedTokenIndex != i)
891 FloatRectangle textRect(0.0f, 0.0f, pToken->displayRect.width - ((tokenTextLeftMargin * 2.0f)), pToken->displayRect.height - tokenVerticalSpacing);
893 textRect.x += tokenTextLeftMargin;
894 textRect.y += (tokenVerticalSpacing / 2.0f);
898 textColor = GetTokenEditTextColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED);
902 textColor = GetTokenEditTextColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL);
905 pToken->pTextObject->SetForegroundColor(textColor, 0, pToken->pTextObject->GetTextLength());
906 pToken->pTextObject->SetBounds(textRect);
907 pToken->pTextObject->Compose();
908 pToken->pTextObject->Draw(*_CanvasImpl::GetInstance(*pTokenCanvas));
911 pTokenElement->SetFlushNeeded();
914 delete pReplacementColorBackgroundBitmap;
915 pReplacementColorBackgroundBitmap = null;
921 _TokenEditPresenter::GetTokenEditColor(const ExpandableEditAreaTokenStatus status) const
923 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, Color(0, 0, 0, 0), E_INVALID_STATE, "[E_INVALID_STATE] _TokenEdit is in an invalid state.");
927 if (status == EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL)
929 color = __pTokenEdit->GetTokenColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL);
933 color = __pTokenEdit->GetTokenColor(EXPANDABLE_EDIT_AREA_TOKEN_STATUS_SELECTED);
940 _TokenEditPresenter::GetTokenEditTextColor(const ExpandableEditAreaTokenStatus status) const
942 SysTryReturn(NID_UI_CTRL, __pTokenEdit != null, Color(0, 0, 0, 0), E_INVALID_STATE, "[E_INVALID_STATE] _TokenEdit is in an invalid state.");
946 if (status == EXPANDABLE_EDIT_AREA_TOKEN_STATUS_NORMAL)
948 color = __pTokenEdit->GetTokenTextColor();
952 color = __pTokenEdit->GetSelectedTokenTextColor();
959 _TokenEditPresenter::MakeToken(const String& tokenString)
961 SysTryReturnResult(NID_UI_CTRL, __pTokenEdit != null, E_INVALID_STATE, "_TokenEdit is in an invalid state.");
962 result r = E_SUCCESS;
966 int tokenLength = tokenString.GetLength();
967 SysTryReturnResult(NID_UI_CTRL, tokenLength, E_INVALID_ARG, "Invalid argument is used. Token length is (%d)", tokenLength);
969 String inputTokenString = tokenString;
970 String replacementString = inputTokenString;
973 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
977 inputTokenString = replacementString;
980 if (inputTokenString.GetLength() <= 0)
983 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to clear text object.", GetErrorMessage(r));
985 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
986 return E_INVALID_ARG;
989 _Token* pToken = new (std::nothrow) _Token();
990 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
992 r = pToken->Construct(inputTokenString, GetFont());
993 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct token.", GetErrorMessage(r));
995 r = __pTokenList->Add(static_cast <Object&>(*pToken));
996 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
998 tokenCount = __pTokenList->GetCount();
999 index = tokenCount - 1;
1001 r = CalculateTokenPositionFromIndex(index);
1002 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to calculate token position.", GetErrorMessage(r));
1004 r = TrimTokenAndAdjustEllipsisAt(index);
1005 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to trim token.", GetErrorMessage(r));
1007 r = InitializeTokenVisibilityAt(index);
1008 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to initialize token visibility.", GetErrorMessage(r));
1010 r = SetInitialBounds();
1011 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds.", GetErrorMessage(r));
1014 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to clear text object.", GetErrorMessage(r));
1016 r = AdjustFlexibleHeight();
1017 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process to resize.", GetErrorMessage(r));
1019 r = CheckTokenScrolling();
1020 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process scroll.", GetErrorMessage(r));
1025 __pTokenList->Remove(*pToken);
1034 _TokenEditPresenter::MakeToken(void)
1036 result r = E_SUCCESS;
1038 String tempToken(GetText());
1039 r = MakeToken(tempToken);
1045 _TokenEditPresenter::AppendToken(const Tizen::Base::String& token)
1047 result r = E_SUCCESS;
1049 r = MakeToken(token);
1050 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1052 if (__edittingTokenIndex >= 0)
1054 SetEditingTokenTextBounds(__edittingTokenIndex);
1055 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1062 _TokenEditPresenter::InsertTokenAt(int index, const String& token, bool isUser)
1064 SysTryReturnResult(NID_UI_CTRL, index >= 0, E_INVALID_ARG, "Invalid argument is used. index is (%d).", index);
1065 SysTryReturnResult(NID_UI_CTRL, token.GetLength() > 0, E_INVALID_ARG, "Invalid argument is used. Token length is (%d).", token.GetLength());
1067 result r = E_SUCCESS;
1069 _Token* pToken = new (std::nothrow) _Token();
1070 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1072 r = pToken->Construct(token, GetFont());
1073 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct token.", GetErrorMessage(r));
1075 r = __pTokenList->InsertAt(*pToken, index);
1076 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to insert token.", GetErrorMessage(r));
1080 r = CalculateTokenPositionFromIndex(index);
1081 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to calculate token position.", GetErrorMessage(r));
1083 r = TrimTokenAndAdjustEllipsisAt(index);
1084 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to trim token.", GetErrorMessage(r));
1086 r = InitializeTokenVisibilityAt(index);
1087 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to initialize token visibility.", GetErrorMessage(r));
1089 r = SetInitialBounds();
1090 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds.", GetErrorMessage(r));
1092 r = AdjustFlexibleHeight();
1093 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process to resize.", GetErrorMessage(r));
1095 r = CheckTokenScrolling();
1096 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to process scroll.", GetErrorMessage(r));
1098 for (int i = 0; i < GetTokenCount(); i++)
1100 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
1101 SysTryCatch(NID_UI_CTRL, pToken != null, ,r = E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
1103 r = pToken->SetBounds(pToken->displayRect);
1104 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds", GetErrorMessage(r));
1109 if (__edittingTokenIndex >= 0)
1111 if (index <= __edittingTokenIndex)
1113 __edittingTokenIndex++;
1115 __pressedTokenIndex = __edittingTokenIndex;
1117 SetEditingTokenTextBounds(__edittingTokenIndex);
1118 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1120 else if (__pressedTokenIndex >= index)
1122 __pressedTokenIndex++;
1124 else if (__focusedTokenIndex >= index)
1126 __focusedTokenIndex++;
1133 __pTokenList->Remove(*pToken);
1142 _TokenEditPresenter::GetTokenAt(int index) const
1145 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);
1147 _Token* pToken = null;
1148 pToken = static_cast <_Token*>(__pTokenList->GetAt(index));
1151 tempString = pToken->GetText();
1158 _TokenEditPresenter::GetTokenCount(bool isInvokedByApp) const
1160 if (!isInvokedByApp)
1162 return __pTokenList->GetCount();
1166 if(__isAnimationInProgress)
1168 return __pTokenList->GetCount() -1;
1172 return __pTokenList->GetCount();
1178 _TokenEditPresenter::GetSelectedTokenIndex(void) const
1180 return __pressedTokenIndex;
1184 _TokenEditPresenter::IsTokenEditModeEnabled(void) const
1186 return __isEditModeEnabled;
1190 _TokenEditPresenter::RemoveTokenAt(int index, bool isClearText)
1192 result r = E_SUCCESS;
1193 SysTryReturnResult(NID_UI_CTRL, index >= 0 && index < __pTokenList->GetCount(), E_OUT_OF_RANGE, "index (%d) is out of range.", index);
1195 if (index == __edittingTokenIndex && isClearText)
1197 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
1198 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
1200 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
1201 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
1203 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
1204 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1206 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
1207 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1209 __edittingTokenIndex = -1;
1210 __isEditingToken = false;
1211 __pressedTokenIndex = -1;
1212 __isTokenEditingFinished = true;
1215 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Failed to clear text object.");
1217 _EditPresenter::SetTextSize(__editContentFontSize);
1220 r = __pTokenList->RemoveAt(index, true);
1221 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove token.");
1223 r = CalculateTokenPositionFromIndex(index);
1224 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to calculate token position.");
1226 r = SetInitialBounds();
1227 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
1229 _Token* pToken = null;
1231 for (int i = 0; i < GetTokenCount(); i++)
1233 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
1234 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
1236 r = pToken->SetBounds(pToken->displayRect);
1237 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds");
1240 r = AdjustFlexibleHeight();
1241 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to process to resize.");
1243 r = CheckTokenScrolling();
1244 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to process scroll.");
1248 if (index > __edittingTokenIndex)
1250 SetEditingTokenTextBounds(__edittingTokenIndex);
1251 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1253 if (index < __edittingTokenIndex)
1255 if (__edittingTokenIndex > 0)
1257 __edittingTokenIndex--;
1258 __pressedTokenIndex = __edittingTokenIndex;
1260 SetEditingTokenTextBounds(__edittingTokenIndex);
1261 _EditPresenter::SetCursorPosition(__previousCursorPosition);
1264 else if (index == __pressedTokenIndex)
1266 __pressedTokenIndex = -1;
1268 SetCursorDisabled(false);
1271 else if (index >= 0 && index < __pressedTokenIndex)
1273 __pressedTokenIndex--;
1276 if (index == __focusedTokenIndex)
1278 __focusedTokenIndex = -1;
1280 else if(index >= 0 && index < __focusedTokenIndex)
1282 __focusedTokenIndex--;
1285 else if (index == __pressedTokenIndex)
1287 __pressedTokenIndex = -1;
1289 SetCursorDisabled(false);
1292 else if (index == __focusedTokenIndex)
1294 __focusedTokenIndex = -1;
1301 _TokenEditPresenter::SetTokenSelected(int index, bool selected)
1303 result r = E_SUCCESS;
1305 SysTryReturnResult(NID_UI_CTRL, index >= 0 && index < __pTokenList->GetCount(), E_OUT_OF_RANGE, "index (%d) is out of range.");
1307 if (selected == false)
1309 __pressedTokenIndex = -1;
1313 __pressedTokenIndex = index;
1320 _TokenEditPresenter::SetTokenEditModeEnabled(bool enable)
1322 result r = E_SUCCESS;
1324 __isEditModeEnabled = enable;
1330 _TokenEditPresenter::CalculateTokenPositionFromIndex(int startIndex, bool leftWard)
1332 result r = E_SUCCESS;
1334 int tokenCount = __pTokenList->GetCount();
1336 float tokenLeftMargin = 0.0f;
1337 float tokenRightMargin = 0.0f;
1338 float tokenTopMargin = 0.0f;
1339 float tokenBottomMargin = 0.0f;
1340 float tokenHeight = 0.0f;
1341 float tokenVerticalSpacing = 0.0f;
1342 float tokenHorizontalSpacing = 0.0f;
1343 float tokenTextLeftMargin = 0.0f;
1344 float tokenTextRightMargin = 0.0f;
1345 float descriptionTextRightMargin = 0.0f;
1346 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1348 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, tokenLeftMargin);
1349 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, tokenRightMargin);
1350 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1351 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
1352 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1353 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1354 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HORIZONTAL_SPACING, orientation, tokenHorizontalSpacing);
1355 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1356 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1357 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_RIGHT_MARGIN, orientation, descriptionTextRightMargin);
1359 SysTryReturn(NID_UI_CTRL, startIndex >= 0 && startIndex <= tokenCount, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. startIndex = (%d)", startIndex);
1361 _Token* pToken = null;
1362 _Token* pPreviousToken = null;
1364 int index = startIndex;
1366 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
1367 String titleText = __pTokenEdit->GetTitleText();
1369 if(!_FloatCompare(GetDescriptionTextRect().width, __previousTitleWidth))
1371 __descriptionTextRectForScroll = GetDescriptionTextRect();
1372 __previousTitleWidth = GetDescriptionTextRect().width;
1375 bool findPrevTokenLoopFlag = true;
1376 for (; index < tokenCount; index++)
1378 pToken = static_cast <_Token*>(__pTokenList->GetAt(index));
1379 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
1383 // TODO : description text (title style inner)
1384 if (titleText.GetLength())
1386 pToken->displayRect.x = __descriptionTextRectForScroll.x + __descriptionTextRectForScroll.width + descriptionTextRightMargin;
1387 pToken->displayRect.y = __descriptionTextRectForScroll.y + __scrollValue;
1389 else // Set description text.
1391 pToken->displayRect.x = tokenLeftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1392 pToken->displayRect.y = tokenTopMargin + __scrollValue + __pTokenEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN) + __lineSpacing;
1395 pToken->displayRect.width = tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin;
1400 if (findPrevTokenLoopFlag)
1402 pPreviousToken = static_cast <_Token*>(__pTokenList->GetAt(index - 1));
1403 findPrevTokenLoopFlag = false;
1406 float tempTextWidth = tokenEditBounds.width - pPreviousToken->displayRect.x - pPreviousToken->displayRect.width - tokenHorizontalSpacing - tokenRightMargin - __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1407 if (tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin > tempTextWidth) // Line change
1409 pToken->displayRect.x = tokenLeftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1410 pToken->displayRect.y = pPreviousToken->displayRect.y + tokenHeight + tokenVerticalSpacing + __lineSpacing;
1415 pToken->displayRect.x = pPreviousToken->displayRect.x + pPreviousToken->displayRect.width +
1416 tokenHorizontalSpacing;
1417 pToken->displayRect.y = pPreviousToken->displayRect.y;
1420 pToken->displayRect.width = tokenTextLeftMargin + pToken->GetTextPixelWidth() + tokenTextRightMargin;
1423 pToken->displayRect.height = tokenHeight;
1425 pPreviousToken = pToken;
1428 for (int i = 0; i < __pTokenList->GetCount(); i++)
1430 TrimTokenAndAdjustEllipsisAt(i);
1431 InitializeTokenVisibilityAt(i);
1437 _TokenEditPresenter::InitializeTokenVisibilityAt(int ndex)
1439 result r = E_SUCCESS;
1441 _Token* pToken = null;
1442 pToken = static_cast <_Token*>(__pTokenList->GetAt(ndex));
1443 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
1445 r = pToken->SetBounds(pToken->displayRect);
1446 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to set bounds", GetErrorMessage(r));
1448 _VisualElement* pRootElement = __pTokenEdit->GetVisualElement();
1449 SysTryReturn(NID_UI_CTRL, pRootElement, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
1451 _VisualElement* pVisualElement = pToken->GetVisualElement();
1452 SysTryReturn(NID_UI_CTRL, pVisualElement, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element.");
1454 pVisualElement->SetShowState(true);
1456 r = pRootElement->AttachChild(*pVisualElement);
1457 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to add child", GetErrorMessage(r));
1463 _TokenEditPresenter::GetMaxTextHeight(void)
1466 float maxHeight = __editContentFontSize;
1469 SysTryReturn(NID_UI_CTRL, pFont != null, maxHeight, E_SYSTEM, "[E_SYSTEM] Failed to get Font instance.");
1471 maxHeight = pFont->GetMaxHeightF();
1477 _TokenEditPresenter::ResetTextBounds(void)
1479 if (!__isEditingToken)
1481 result r = SetInitialBounds();
1482 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[E_SYSTEM] A system error has occured. Failed to set margin.");
1488 _TokenEditPresenter::SetInitialBounds(void)
1490 result r = E_SUCCESS;
1492 float tokenLeftMargin = 0.0f;
1493 float tokenRightMargin = 0.0f;
1494 float tokenTopMargin = 0.0f;
1495 float tokenHeight = 0.0f;
1496 float tokenMinWidth = 0.0f;
1497 float tokenVerticalSpacing = 0.0f;
1498 float tokenHorizontalSpacing = 0.0f;
1499 float tokenTextLeftMargin = 0.0f;
1500 float tokenTextRightMargin = 0.0f;
1501 float textBoundsAlignValue = 0.0f;
1502 float descriptionTextRightMargin = 0.0f;
1503 _ControlOrientation orientation = GetEditView()->GetOrientation();
1505 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, tokenLeftMargin);
1506 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, tokenRightMargin);
1507 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1508 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1509 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_MIN_WIDTH, orientation, tokenMinWidth);
1510 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1511 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HORIZONTAL_SPACING, orientation, tokenHorizontalSpacing);
1512 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1513 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1514 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_RIGHT_MARGIN, orientation, descriptionTextRightMargin);
1516 float textObjectMaxHeight = GetMaxTextHeight();
1517 textBoundsAlignValue = (tokenHeight - textObjectMaxHeight) / 2.0f;
1521 int tokenCount = __pTokenList->GetCount();
1523 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
1524 FloatRectangle tokenTextRect = tokenEditBounds;
1526 if (tokenCount == 0)
1528 if (__pTokenEdit->GetTitleText().GetLength())
1530 FloatRectangle descriptionTextRect = GetDescriptionTextRect();
1531 tokenTextRect.x = descriptionTextRect.x + descriptionTextRect.width + descriptionTextRightMargin;
1535 tokenTextRect.x = tokenLeftMargin + __pTokenEdit->GetHorizontalMargin(EDIT_TEXT_LEFT_MARGIN);
1538 tokenTextRect.y = tokenTopMargin + __pTokenEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN) + textBoundsAlignValue;
1539 tokenTextRect.width -= tokenTextRect.x + tokenRightMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1540 tokenTextRect.height = textObjectMaxHeight;
1542 SetTextBounds(tokenTextRect);
1546 _Token* pToken = null;
1547 // SetTextBounds from last token
1548 pToken = static_cast <_Token*>(__pTokenList->GetAt(tokenCount - 1));
1549 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
1551 float tempTextRectWidth = 0.0f;
1552 tempTextRectWidth = tokenEditBounds.width - pToken->displayRect.x - pToken->displayRect.width - tokenHorizontalSpacing - tokenRightMargin - __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1553 if (tokenMinWidth > tempTextRectWidth) // Line change
1555 tokenTextRect.x = tokenLeftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1556 tokenTextRect.y = pToken->displayRect.y + tokenHeight + tokenVerticalSpacing + __lineSpacing + textBoundsAlignValue;
1560 tokenTextRect.x = pToken->displayRect.x + pToken->displayRect.width + tokenHorizontalSpacing;
1561 tokenTextRect.y = pToken->displayRect.y + textBoundsAlignValue;
1564 tokenTextRect.width -= tokenTextRect.x + tokenRightMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1565 tokenTextRect.height = textObjectMaxHeight;
1567 SetTextBounds(tokenTextRect);
1571 r = _EditPresenter::SetInitialBounds();
1578 _TokenEditPresenter::SetDescriptionTextRect(const FloatRectangle& rect)
1580 result r = E_SUCCESS;
1582 __descriptionTextRect = rect;
1588 _TokenEditPresenter::GetDescriptionTextRect() const
1590 return __descriptionTextRect;
1594 _TokenEditPresenter::GetTextBounds(void) const
1596 if ((__isPopupVisible == true || __isLongPressed == true) && __pressedTokenIndex >= 0)
1598 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
1599 SysTryReturn(NID_UI_CTRL, pToken, Rectangle(), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Unable to get valid token.");
1601 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1602 float tokenTextLeftMargin = 0.0f;
1603 float tokenTextVerticalMargin = 0.0f;
1604 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1605 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenTextVerticalMargin);
1607 FloatRectangle textBoundsF(pToken->displayRect.x + tokenTextLeftMargin, pToken->displayRect.y + (tokenTextVerticalMargin /2.0f), pToken->displayRect.width - (tokenTextLeftMargin * 2.0f), pToken->displayRect.height - tokenTextVerticalMargin);
1608 Rectangle textBounds = _CoordinateSystemUtils::ConvertToInteger(textBoundsF);
1614 return _EditPresenter::GetTextBounds();
1619 _TokenEditPresenter::GetTextBoundsF(void) const
1621 if ((__isPopupVisible == true || __isLongPressed == true) && __pressedTokenIndex >= 0)
1623 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
1624 SysTryReturn(NID_UI_CTRL, pToken, FloatRectangle(), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Unable to get valid token.");
1626 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1627 int tokenTextLeftMargin = 0;
1628 int tokenTextVerticalMargin = 0;
1629 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1630 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenTextVerticalMargin);
1632 FloatRectangle textBounds(pToken->displayRect.x + tokenTextLeftMargin, pToken->displayRect.y + (tokenTextVerticalMargin /2.0f), pToken->displayRect.width - (tokenTextLeftMargin * 2.0f), pToken->displayRect.height - tokenTextVerticalMargin);
1638 return _EditPresenter::GetTextBoundsF();
1643 _TokenEditPresenter::CutText(void)
1645 if (__isEditingToken)
1647 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
1648 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
1650 pToken->isTextCut = true;
1652 return _EditPresenter::CutText();
1656 _TokenEditPresenter::SetLineSpacing(int linePixelGap)
1658 __lineSpacing = linePixelGap;
1664 _TokenEditPresenter::SetLineSpacing(float linePixelGap)
1666 __lineSpacing = linePixelGap;
1672 _TokenEditPresenter::GetLineSpacing(void) const
1674 int lineSpacing = _CoordinateSystemUtils::ConvertToInteger(__lineSpacing);
1679 _TokenEditPresenter::GetLineSpacingF(void) const
1681 return __lineSpacing;
1684 VisualElementAnimation*
1685 _TokenEditPresenter::CreateAnimationN(VisualElement& source, bool create)
1687 VisualElementAnimation* pAnimation = null;
1688 VisualElementAnimationGroup* pAnimationGroup = new (std::nothrow) VisualElementAnimationGroup();
1689 SysTryReturn(NID_UI_CTRL, pAnimationGroup, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1691 pAnimationGroup->SetDuration(ANIMATION_DURATION_BOUNDS);
1692 if (__pTimingFunction == null)
1694 __pTimingFunction = new (std::nothrow) SineTimingFunction();
1695 SysTryReturn(NID_UI_CTRL, __pTimingFunction, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1698 if (pAnimationGroup != null)
1700 VisualElementPropertyAnimation* pOpacityAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1701 SysTryReturn(NID_UI_CTRL, pOpacityAnimation, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1703 pOpacityAnimation->SetPropertyName("opacity");
1706 pOpacityAnimation->SetStartValue(Variant(1.0f));
1707 pOpacityAnimation->SetEndValue(Variant(0.0f));
1711 pOpacityAnimation->SetStartValue(Variant(0.0f));
1712 pOpacityAnimation->SetEndValue(Variant(1.0f));
1715 pOpacityAnimation->SetDuration(ANIMATION_DURATION_OPACITY);
1716 pOpacityAnimation->SetTimingFunction(__pTimingFunction);
1717 pAnimationGroup->AddAnimation(*pOpacityAnimation);
1718 delete pOpacityAnimation;
1720 VisualElementPropertyAnimation* pBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1721 SysTryReturn(NID_UI_CTRL, pBoundsAnimation, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1723 pBoundsAnimation->SetPropertyName("bounds");
1724 FloatRectangle startValue = source.GetBounds();
1725 startValue.x = startValue.x + startValue.width * 0.05;
1726 startValue.y = startValue.y + startValue.height * 0.05;
1727 startValue.width = startValue.width * 0.9;
1728 startValue.height = startValue.height * 0.9;
1732 pBoundsAnimation->SetStartValue(Variant(source.GetBounds()));
1733 pBoundsAnimation->SetEndValue(Variant(startValue));
1734 pBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
1738 pBoundsAnimation->SetStartValue(Variant(startValue));
1739 pBoundsAnimation->SetEndValue(Variant(source.GetBounds()));
1742 pBoundsAnimation->SetDuration(ANIMATION_DURATION_BOUNDS);
1743 pBoundsAnimation->SetTimingFunction(__pTimingFunction);
1744 pAnimationGroup->AddAnimation(*pBoundsAnimation);
1746 delete pBoundsAnimation;
1748 pAnimation = pAnimationGroup;
1754 _TokenEditPresenter::CalculateDescriptionTextRect(const String& descriptionText)
1756 result r = E_SUCCESS;
1758 TextSimple* pSimpleText = null;
1759 float leftMargin = 0.0f;
1760 float tokenTopMargin = 0.0f;
1761 float tokenHeight = 0.0f;
1762 float tokenVerticalSpacing = 0.0f;
1763 float tokenTextLeftMargin = 0.0f;
1764 float tokenTextRightMargin = 0.0f;
1765 float tokenTitleWidth = 0.0f;
1766 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1768 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
1769 GET_SHAPE_CONFIG(TOKENEDIT::LEFT_MARGIN, orientation, leftMargin);
1770 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
1771 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
1772 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
1773 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_RIGHT_MARGIN, orientation, tokenTextRightMargin);
1774 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TITLE_RECT_WIDTH, orientation, tokenTitleWidth);
1776 int length = descriptionText.GetLength();
1777 FloatDimension textSize;
1779 wchar_t* pTempString = const_cast <wchar_t*>(descriptionText.GetPointer());
1781 SysAssertf(__pDescriptionTextTextObject != null, "The TextObject instance is null.");
1783 __pDescriptionTextTextObject->RemoveAll(true);
1784 pSimpleText = new (std::nothrow)TextSimple(pTempString, length, TEXT_ELEMENT_SOURCE_TYPE_INTERNAL);
1785 __pDescriptionTextTextObject->AppendElement(*pSimpleText);
1787 textSize = __pDescriptionTextTextObject->GetTextExtentF(0, length);
1788 r = __pDescriptionTextTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1789 r = __pDescriptionTextTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
1791 __descriptionTextRect.x = leftMargin + __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_LEFT_MARGIN);
1792 __descriptionTextRect.y = tokenTopMargin + __pTokenEdit->GetVerticalMarginF(EDIT_TEXT_TOP_MARGIN);
1793 if (textSize.width > tokenTitleWidth)
1795 textSize.width = tokenTitleWidth;
1796 __pDescriptionTextTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
1799 __descriptionTextRect.width = tokenTextLeftMargin + textSize.width + tokenTextRightMargin;
1800 __descriptionTextRect.height = tokenHeight;
1801 __pDescriptionTextTextObject->SetBounds(__descriptionTextRect);
1803 if (__pDescriptionTextTextObject->IsChanged())
1805 _EditPresenter::StopTitleSlidingTimer();
1806 __isTitleSliding = false;
1809 r = __pDescriptionTextTextObject->Compose();
1815 _TokenEditPresenter::IsGuideTextActivated(void) const
1817 bool isGuideTextActivated = _EditPresenter::IsGuideTextActivated();
1819 if (__isTokenEditPresenterInitialized)
1821 if (GetTokenCount())
1827 return isGuideTextActivated;
1831 _TokenEditPresenter::DrawDescriptionText(void)
1833 result r = E_SUCCESS;
1834 FloatRectangle tempDescriptionTextRect;
1835 Canvas* pDescriptionTextCanvas = null;
1837 Font* pDescriptionFont = null;
1838 TextObjectActionType titleAction;
1839 _VisualElement* pRootElement = null;
1841 if (__pDescriptionTextTextObject->GetFont(0)->GetFaceName() != GetTitleFontFaceName())
1843 float descriptionTextSize = 0.0f;
1844 GET_SHAPE_CONFIG(TOKENEDIT::DESCRIPTION_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, descriptionTextSize);
1846 pDescriptionFont = GetFont();
1847 if (pDescriptionFont)
1849 float editFontSize = GetTextSize();
1850 (_FontImpl::GetInstance(*pDescriptionFont))->SetSize(descriptionTextSize);
1852 r = __pDescriptionTextTextObject->SetFont(pDescriptionFont, 0, __pDescriptionTextTextObject->GetTextLength());
1853 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. SetFont failed");
1855 (_FontImpl::GetInstance(*pDescriptionFont))->SetSize(editFontSize);
1859 pRootElement = __pTokenEdit->GetVisualElement();
1860 SysTryCatch(NID_UI_CTRL, pRootElement, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
1862 if (!__pDescriptionTextVisualElement)
1864 __pDescriptionTextVisualElement = new (std::nothrow) _VisualElement();
1865 SysTryCatch(NID_UI_CTRL, __pDescriptionTextVisualElement, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1866 r = __pDescriptionTextVisualElement->Construct();
1867 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[E_SYSTEM] A system error has occurred. Failed to construct _VisualElement");
1868 __pDescriptionTextVisualElement->SetImplicitAnimationEnabled(false);
1869 __pDescriptionTextVisualElement->SetShowState(true);
1871 r = pRootElement->AttachChild(*__pDescriptionTextVisualElement);
1872 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1875 __pDescriptionTextVisualElement->SetBounds(FloatRectangle(__descriptionTextRect.x, (__descriptionTextRectForScroll.y + __scrollValue), __descriptionTextRect.width, __descriptionTextRect.height));
1877 pDescriptionTextCanvas = __pDescriptionTextVisualElement->GetCanvasN();
1878 if (pDescriptionTextCanvas == null)
1880 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Failed to get canvas of an instance of _VisualElement.");
1884 tempDescriptionTextRect = __descriptionTextRect;
1885 tempDescriptionTextRect.x = 0.0f;
1886 tempDescriptionTextRect.y = 0.0f;
1888 titleAction = __pDescriptionTextTextObject->GetAction();
1890 pDescriptionTextCanvas->SetBackgroundColor(Color(0));
1891 pDescriptionTextCanvas->Clear();
1892 __pDescriptionTextTextObject->SetForegroundColor(__pTokenEdit->GetTitleTextColor(GetCurrentStatus()), 0, __pDescriptionTextTextObject->GetTextLength());
1894 if (IsFocused() == true)
1896 if (__pDescriptionTextTextObject->GetTextLengthAt(0) < __pDescriptionTextTextObject->GetTextLength())
1898 if (titleAction != TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT)
1900 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_SLIDE_LEFT);
1901 __pDescriptionTextTextObject->Compose();
1906 if (titleAction != TEXT_OBJECT_ACTION_TYPE_NONE)
1908 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
1909 __pDescriptionTextTextObject->Compose();
1913 if (!__isTitleSliding)
1915 _EditPresenter::StopTitleSlidingTimer();
1916 if (__pDescriptionTextTextObject->IsActionOn() == true)
1918 _EditPresenter::StartTitleSlidingTimer();
1919 __isTitleSliding = true;
1925 if (titleAction != TEXT_OBJECT_ACTION_TYPE_ABBREV)
1927 __pDescriptionTextTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1928 __pDescriptionTextTextObject->Compose();
1933 __pDescriptionTextTextObject->SetBounds(tempDescriptionTextRect);
1934 __pDescriptionTextTextObject->Draw(*_CanvasImpl::GetInstance(*pDescriptionTextCanvas));
1936 delete pDescriptionTextCanvas;
1941 if (__pDescriptionTextVisualElement != null)
1943 __pDescriptionTextVisualElement->Destroy();
1944 __pDescriptionTextVisualElement = null;
1951 _TokenEditPresenter::TrimTokenAndAdjustEllipsisAt(int index)
1953 result r = E_SUCCESS;
1955 float tokenRightMargin = 0.0f;
1956 float tokenMinimumSize = 0.0f;
1958 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
1959 GET_SHAPE_CONFIG(TOKENEDIT::RIGHT_MARGIN, orientation, tokenRightMargin);
1960 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_MIN_WIDTH, orientation, tokenMinimumSize);
1962 _Token* pToken = null;
1963 pToken = static_cast <_Token*>(__pTokenList->GetAt(index));
1964 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
1966 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
1967 FloatRectangle tokenRect = pToken->displayRect;
1969 float remainWidth = tokenEditBounds.width - tokenRightMargin - __pTokenEdit->GetHorizontalMarginF(EDIT_TEXT_RIGHT_MARGIN);
1971 float dspTokenWidth = tokenRect.x + tokenRect.width;
1972 float dspTokenGap = dspTokenWidth - remainWidth;
1974 if (dspTokenGap > 0.0f)
1976 if (pToken->displayRect.width >= tokenMinimumSize)
1978 if ((pToken->displayRect.width - dspTokenGap) < tokenMinimumSize)
1980 pToken->displayRect.width = tokenMinimumSize;
1984 pToken->displayRect.width -= dspTokenGap;
1989 pToken->pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
1990 pToken->pTextObject->SetTextObjectEllipsisType(TEXT_OBJECT_ELLIPSIS_TYPE_TAIL);
1997 _TokenEditPresenter::GetTokenIndexFromCoordinate(const Point point) const
1999 int tokenIndex = -1;
2001 int tokenCount = __pTokenList->GetCount();
2002 for (int i = 0; i < tokenCount; i++)
2004 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2007 FloatRectangle tokenRect = pToken->displayRect;
2008 if (tokenRect.Contains(FloatPoint(point.x, point.y)))
2019 _TokenEditPresenter::SetEditingTokenTextBounds(int index, bool isSetText)
2021 result r = E_SUCCESS;
2023 float tokenHeight = 0.0f;
2024 float tokenVerticalSpacing = 0.0f;
2025 float tokenTextLeftMargin = 0.0f;
2026 float tokenFontSize = 0.0f;
2027 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2029 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
2030 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
2031 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
2032 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_SIZE, orientation, tokenFontSize);
2034 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(index));
2035 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null");
2037 FloatRectangle tempTextDspRect;
2038 tempTextDspRect.x += tokenTextLeftMargin;
2039 tempTextDspRect.y += tokenVerticalSpacing / 2.0f;
2040 tempTextDspRect.width = pToken->displayRect.width - (tokenTextLeftMargin * 2.0f);
2041 tempTextDspRect.height = tokenHeight - tokenVerticalSpacing;
2045 if (!pToken->isTextCut)
2047 SetText(pToken->GetText());
2049 pToken->pTextObject->RemoveAll(true);
2052 _EditPresenter::SetTextSize(tokenFontSize);
2054 SetTextBounds(tempTextDspRect);
2060 _TokenEditPresenter::RecalculateTokenBounds(float position)
2062 result r = E_SUCCESS;
2064 __scrollValue = -position;
2066 int tokenCount = GetTokenCount();
2067 CalculateTokenPositionFromIndex(0);
2069 for (int i = 0; i < tokenCount; i++)
2071 _Token* pToken = null;
2072 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2076 pToken->SetBounds(pToken->displayRect);
2078 TrimTokenAndAdjustEllipsisAt(i);
2079 InitializeTokenVisibilityAt(i);
2082 if (__pDescriptionTextTextObject->GetTextLength() != 0)
2084 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2087 __pTokenEdit->Invalidate();
2089 r = SetInitialBounds();
2090 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
2096 _TokenEditPresenter::SetTokenBoundsByTouchInfo(const _TouchInfo& touchinfo)
2098 result r = E_SUCCESS;
2099 int currentYPosition = _CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()).y;
2101 if(_FloatCompare(__prevScrollValue, 0.0f))
2103 __prevScrollValue = currentYPosition;
2105 else // Adjust moved y position to all tokens.
2107 if (__isNeedToScroll) // Need to scroll
2109 float tempDefference = __prevScrollValue - currentYPosition;
2111 __prevScrollValue = currentYPosition;
2112 __scrollValue -= tempDefference;
2114 if (__scrollValue < -__maxScrollValue)
2116 __scrollValue = -__maxScrollValue;
2121 if (__scrollValue > 0.0f)
2123 __scrollValue = 0.0f;
2128 int tokenCount = GetTokenCount();
2129 CalculateTokenPositionFromIndex(0);
2130 for (int i = 0; i < tokenCount; i++)
2132 _Token* pToken = null;
2133 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2137 pToken->SetBounds(pToken->displayRect);
2139 TrimTokenAndAdjustEllipsisAt(i);
2140 InitializeTokenVisibilityAt(i);
2143 if (__pDescriptionTextTextObject->GetTextLength() != 0)
2145 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2148 __pTokenEdit->Invalidate();
2152 __prevScrollValue = 0.0f;
2153 __scrollValue = 0.0f;
2157 r = SetInitialBounds();
2158 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds.");
2164 _TokenEditPresenter::ProcessTokeningByTouchEvent(const _Control& source, const _TouchInfo& touchinfo)
2166 int tokenIndex = GetTokenIndexFromCoordinate(_CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()));
2168 //Reset "longPressed" when Touch released on a different token after long gesture on a token
2169 if (__trackTokenIndex != tokenIndex)
2171 __isLongPressed = false;
2174 int prevPressedTokenIndex = __pressedTokenIndex;
2175 int prevEditedTokenIndex = __edittingTokenIndex;
2177 result r = E_SUCCESS;
2180 if (__isEditModeEnabled && __pressedTokenIndex != -1 && __pressedTokenIndex == tokenIndex)
2182 //Comment below to Block Copy & Paste functionality in Token Edit mode
2183 __edittingTokenIndex = __pressedTokenIndex;
2184 __isEditingToken = true;
2185 __isTokenEditingFinished = false;
2186 if (prevEditedTokenIndex != __edittingTokenIndex)
2188 SetEditingTokenTextBounds(__edittingTokenIndex);
2190 SetCursorDisabled(false);
2194 if (tokenIndex != -1)
2196 if (__isEditingToken && (prevPressedTokenIndex != tokenIndex)) // Selected another token while editing.
2198 __isPopupVisible = false;
2199 __isLongPressed = false;
2201 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2202 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
2204 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2205 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
2207 _Token* pToken = null;
2208 _VisualElement* pTokenVisualElement = null;
2210 pToken = static_cast <_Token*>(__pTokenList->GetAt(prevPressedTokenIndex));
2212 bool isParentChanged = false;
2215 pTokenVisualElement = pToken->GetVisualElement();
2216 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
2218 if (pCursorVisualElement->GetParent() == pTokenVisualElement)
2220 isParentChanged = true;
2221 result r = E_SUCCESS;
2222 r = pTokenVisualElement->DetachChild(*pCursorVisualElement);
2223 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2225 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2226 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2230 String inputTokenString = GetText();
2231 String replacementString = inputTokenString;
2232 bool enable = false;
2234 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
2237 inputTokenString = replacementString;
2240 __pressedTokenIndex = tokenIndex;
2242 r = RemoveTokenAt(prevPressedTokenIndex);
2243 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2245 if (inputTokenString.GetLength() > 0)
2247 r = InsertTokenAt(prevPressedTokenIndex, inputTokenString);
2248 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2250 pToken = static_cast <_Token*>(__pTokenList->GetAt(prevPressedTokenIndex));
2253 pToken->currTokenLength = inputTokenString.GetLength();
2258 //Flex height adjusted since token can move to another line
2259 AdjustFlexibleHeight();
2260 __edittingTokenIndex = -1;
2261 __isTokenEditingFinished = true;
2262 __isEditingToken = false;
2263 _EditPresenter::SetTextSize(__editContentFontSize);
2265 SetCursorDisabled(true);
2269 __pressedTokenIndex = tokenIndex;
2270 if (GetText().GetLength() > 0 && __pressedTokenIndex != prevPressedTokenIndex)
2273 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2276 if ((__isEditingToken == true) && (__pressedTokenIndex != -1))
2278 r = AttachCursorToPressedToken();
2279 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2282 if (__isEditingToken == false)
2284 SetCursorDisabled(true);
2290 __isPopupVisible = false;
2291 __isLongPressed = false;
2293 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2294 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
2296 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2297 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
2299 if (__isEditingToken)
2301 _Token* pToken = null;
2302 _VisualElement* pTokenVisualElement = null;
2304 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
2306 bool isParentChanged = false;
2309 pTokenVisualElement = pToken->GetVisualElement();
2310 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
2312 if (pCursorVisualElement->GetParent() == pTokenVisualElement)
2314 isParentChanged = true;
2315 result r = E_SUCCESS;
2316 r = pTokenVisualElement->DetachChild(*pCursorVisualElement);
2317 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2319 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2320 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2324 String inputTokenString = GetText();
2325 String replacementString = inputTokenString;
2326 bool enable = false;
2328 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
2331 inputTokenString = replacementString;
2333 __pressedTokenIndex = tokenIndex;
2335 RemoveTokenAt(__edittingTokenIndex);
2337 if (inputTokenString.GetLength() > 0)
2339 InsertTokenAt(__edittingTokenIndex, inputTokenString);
2341 if (isParentChanged)
2343 pToken->currTokenLength = inputTokenString.GetLength();
2347 __isEditingToken = false;
2348 __edittingTokenIndex = -1;
2349 _EditPresenter::SetTextSize(__editContentFontSize);
2350 __isTokenEditingFinished = false;
2354 //Flex height adjusted since token can move to another line
2355 AdjustFlexibleHeight();
2357 SysTryReturnResult(NID_UI_CTRL, (inputTokenString.GetLength() > 0), E_INVALID_ARG, "Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
2363 __pressedTokenIndex = tokenIndex;
2364 if (pCursorVisualElement->GetParent() != pEditVisualElement)
2366 r = (pCursorVisualElement->GetParent())->DetachChild(*pCursorVisualElement);
2367 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2369 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2370 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2374 SetCursorDisabled(false);
2377 for (int i = 0; i < __pTokenList->GetCount(); i++)
2379 TrimTokenAndAdjustEllipsisAt(i);
2380 InitializeTokenVisibilityAt(i);
2387 _TokenEditPresenter::CheckTokenScrolling(bool scrollToCursorPosition)
2389 bool needToScroll = false;
2390 float tokenTopMargin = 0.0f;
2391 float tokenBottomMargin = 0.0f;
2392 float tokenVerticalSpacing = 0.0f;
2393 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2395 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
2396 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
2397 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
2399 int tokenCount = GetTokenCount();
2400 if (tokenCount == 0) // There is no token to scroll
2402 __isNeedToScroll = false;
2403 __maxScrollValue = 0.0f;
2404 __isTokenScrolling = false;
2409 _Token* pToken = static_cast<_Token*>(__pTokenList->GetAt(tokenCount - 1));
2410 SysTryReturn(NID_UI_CTRL, pToken, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
2412 float newScrollValue = 0.0f;
2414 if (scrollToCursorPosition)
2416 FloatRectangle cursorBounds;
2417 GetCursorBounds(false, cursorBounds);
2418 newScrollValue = cursorBounds.y + cursorBounds.height - __scrollValue + tokenBottomMargin - __pTokenEdit->GetBoundsF().height;
2419 __isScrollValueModified = true;
2423 newScrollValue = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin - __pTokenEdit->GetBoundsF().height;
2424 __isScrollValueModified = true;
2427 needToScroll = (newScrollValue > 0.0f) ? (true) : (false);
2429 __isNeedToScroll = needToScroll;
2431 if (__isNeedToScroll)
2433 __maxScrollValue = newScrollValue;
2434 __isTokenScrolling = true;
2436 RecalculateTokenBounds(__maxScrollValue);
2440 if(!_FloatCompare(__scrollValue, 0.0f))
2442 __scrollValue = 0.0f;
2443 __maxScrollValue = 0.0f; // To prevent unnecessary token scrolling.
2444 RecalculateTokenBounds(__scrollValue);
2445 __isTokenScrolling = false;
2453 _TokenEditPresenter::SetTokenVisualElementBounds(int index, const FloatRectangle& bounds)
2455 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(index));
2456 SysTryReturnResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "A system error has occurred. The _Token instance is null.");
2458 return pToken->SetBounds(pToken->displayRect);
2462 _TokenEditPresenter::AdjustFlexibleHeight(void)
2464 result r = E_SUCCESS;
2466 FloatRectangle editRect = __pTokenEdit->GetBoundsF();
2467 FloatRectangle displayScrollBounds = GetDisplayScrollBoundsF();
2468 float calcHeight = CalculateFlexibleHeightF();
2470 if (!_FloatCompare(editRect.height, calcHeight))
2472 displayScrollBounds.height = calcHeight;
2473 SetScrollBarBounds(displayScrollBounds);
2475 editRect.height = calcHeight;
2476 if (!__isEditingToken)
2478 FloatRectangle editRectBounds = CoordinateSystem::AlignToDevice(editRect);
2479 r = SetFlexBounds(editRectBounds);
2487 _TokenEditPresenter::CalculateFlexibleHeightF(void)
2489 float tokenHeight = 0.0f;
2490 float tokenVerticalSpacing = 0.0f;
2491 float tokenTopMargin = 0.0f;
2492 float tokenBottomMargin = 0.0f;
2493 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
2495 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
2496 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
2497 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
2498 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
2500 float height = 0.0f;
2501 int maxLinecount = GetMaxLineCount();
2502 float expectedEditHeight = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin;
2503 float initialHeight = GetInitialBoundsF().height;
2504 float maximumLineHeight = tokenTopMargin + maxLinecount * tokenHeight + tokenVerticalSpacing * (maxLinecount - 1) + tokenBottomMargin;
2506 if (initialHeight < expectedEditHeight)
2508 if (expectedEditHeight > maximumLineHeight)
2510 height = maximumLineHeight;
2514 height = expectedEditHeight;
2519 height = initialHeight;
2526 _TokenEditPresenter::DrawScrollBar(void)
2528 result r = E_SUCCESS;
2530 _Scroll* pScroll = GetScrollBar();
2531 if (pScroll == null)
2536 if (IsFocused() == false)
2538 if (__isTouchMoveInProgress == false)
2540 pScroll->SetScrollVisibility(false);
2545 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(GetTokenCount() - 1));
2551 float tokenBottomMargin = 0.0f;
2552 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, tokenBottomMargin);
2554 float totalHeight = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin;
2555 float dspHeight = __pTokenEdit->GetBoundsF().height;
2556 float firstDspY = -__scrollValue;
2558 if (totalHeight <= dspHeight)
2560 pScroll->SetScrollVisibility(false);
2561 pScroll->SetScrollRange(1, 1);
2562 pScroll->SetScrollPosition(0.0f);
2564 SetScrollBarVisible(false);
2565 SetPreviousScrollBarPosition(0.0f);
2566 SetMaximumPreviousScrollBarPosition(0.0f);
2570 if (firstDspY > 0.0f)
2572 pScroll->SetScrollRange(dspHeight, totalHeight);
2573 pScroll->SetScrollPosition(firstDspY);
2574 SetMaximumPreviousScrollBarPosition(totalHeight - dspHeight);
2578 pScroll->SetScrollRange(dspHeight, totalHeight);
2579 pScroll->SetScrollPosition(0.0f);
2580 SetMaximumPreviousScrollBarPosition(0.0f);
2583 if (pScroll->GetScrollVisibility())
2585 SetScrollBarVisible(true);
2588 SetPreviousScrollBarPosition(firstDspY);
2595 _TokenEditPresenter::SetAutoShrinkModeEnabled(bool enable)
2597 __autoShrink = enable;
2601 _TokenEditPresenter::IsAutoShrinkModeEnabled(void) const
2603 return __autoShrink;
2607 _TokenEditPresenter::SetDescriptionText(String descriptionText)
2609 __descriptionText = descriptionText;
2613 _TokenEditPresenter::GetDescriptionText(void) const
2615 return __descriptionText;
2619 _TokenEditPresenter::CalculateVisibleTokenCount(void)
2621 int visibleTokenCount = 0;
2623 FloatRectangle intialBounds = GetInitialBoundsF();
2624 FloatRectangle tempInitialBounds = intialBounds;
2625 FloatRectangle hiddenTokenDisplayBounds;
2626 int tokenCount = GetTokenCount();
2628 for (int i = 0; i < tokenCount; i++)
2630 tempInitialBounds = intialBounds;
2631 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2632 SysTryReturn(NID_UI_CTRL, pToken != null, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
2634 FloatRectangle displayBounds = pToken->displayRect;
2635 if ((tempInitialBounds.y + displayBounds.y) > (tempInitialBounds.y + tempInitialBounds.height))
2639 visibleTokenCount++;
2641 return visibleTokenCount;
2645 _TokenEditPresenter::OnFocusGained(void)
2647 __isTitleSliding = false;
2650 float tempHeight = CalculateFlexibleHeightF();
2651 FloatRectangle tempRect = GetInitialBoundsF();
2652 tempRect.height = tempHeight;
2654 _Token* pToken = null;
2655 int tokenCount = GetTokenCount();
2657 for (int i = 0; i < tokenCount; i++)
2659 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2663 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
2664 if (pTokenVisualElement)
2666 pTokenVisualElement->SetShowState(true);
2671 SetFlexBounds(tempRect);
2673 SetEditingTokenTextBounds(__edittingTokenIndex, false);
2677 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2681 if (__isScrollValueChanged && !__isScrollValueModified)
2683 __maxScrollValue = __maxScrollValue - (__pTokenEdit->GetBoundsF().height - GetInitialBoundsF().height);
2684 __isScrollValueChanged = false;
2688 if (GetTokenCount())
2690 CheckTokenScrolling();
2693 TextObject* pTextObject = GetTextObject();
2696 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_NONE);
2697 pTextObject->Compose();
2700 if (__pressedTokenIndex < 0)
2703 SetCursorDisabled(false);
2707 return _EditPresenter::OnFocusGained();
2711 _TokenEditPresenter::OnFocusLost(void)
2713 result r = E_SUCCESS;
2716 //Remove pressed state on focus lost
2717 __pressedTokenIndex = -1;
2718 __focusedTokenIndex = -1;
2719 __focusedEditingTokenIndex = -1;
2721 _EditPresenter::StopTitleSlidingTimer();
2722 __isTitleSliding = false;
2724 if (__edittingTokenIndex >= 0)
2726 _Token* pToken = null;
2727 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
2730 if (GetText().GetLength() > 0)
2732 OnTextCommitted(L"\n");
2736 RemoveTokenAt(__edittingTokenIndex, true);
2742 if (GetText().GetLength() > 0)
2744 OnTextCommitted(L"\n");
2750 _Scroll* pScroll = GetScrollBar();
2753 pScroll->SetScrollVisibility(false);
2755 __scrollValue = 0.0f;
2757 int tokenCount = GetTokenCount();
2758 _Token* pToken = null;
2759 for (int i = 0; i < tokenCount; i++)
2761 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2764 pToken->SetBounds(pToken->displayRect);
2768 r = SetInitialBounds();
2769 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating", GetErrorMessage(r));
2771 __scrollValue = 0.0f;
2772 r = CalculateTokenPositionFromIndex(0);
2773 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
2775 int visibleTokenCount = CalculateVisibleTokenCount();
2777 for (int i = visibleTokenCount; i < tokenCount; i++)
2779 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
2782 _VisualElement* pTokenVisualElement = pToken->GetVisualElement();
2783 if (pTokenVisualElement)
2785 pTokenVisualElement->SetShowState(false);
2790 float totalScrollValue = __maxScrollValue + (__pTokenEdit->GetBoundsF().height - GetInitialBoundsF().height);
2792 if (totalScrollValue > 0)
2794 __isNeedToScroll = true;
2795 __maxScrollValue = totalScrollValue;
2796 __isTokenScrolling = true;
2797 if (__lineAdded > 0)
2799 __isScrollValueChanged = true;
2800 __isScrollValueModified = false;
2804 FloatRectangle intialWindowBounds = GetInitialBoundsF();
2805 SetFlexBounds(intialWindowBounds);
2807 SetEditingTokenTextBounds(__edittingTokenIndex, false);
2809 __descriptionTextRect.y = __descriptionTextRectForScroll.y + __scrollValue;
2812 TextObject* pTextObject = GetTextObject();
2815 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
2816 pTextObject->Compose();
2819 return _EditPresenter::OnFocusLost();
2823 _TokenEditPresenter::SetFlexBounds(const FloatRectangle& bounds)
2825 if (__pTokenEdit->GetBoundsF().height > bounds.height)
2827 if (__lineAdded > 0)
2832 return _EditPresenter::SetFlexBounds(bounds);
2836 _TokenEditPresenter::SetTextSize(const int size)
2838 result r = E_SUCCESS;
2839 __editContentFontSize = size;
2841 if (!__isEditingToken)
2843 r = _EditPresenter::SetTextSize(size);
2844 r = SetInitialBounds();
2845 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2852 _TokenEditPresenter::SetTextSize(const float size)
2854 result r = E_SUCCESS;
2855 __editContentFontSize = size;
2857 if (!__isEditingToken)
2859 r = _EditPresenter::SetTextSize(size);
2860 r = SetInitialBounds();
2861 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
2868 _TokenEditPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
2870 //Remove token focus on touch press
2871 __focusedTokenIndex = -1;
2872 __focusedEditingTokenIndex = -1;
2873 int tokenIndex = GetTokenIndexFromCoordinate(_CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()));
2874 __trackTokenIndex = tokenIndex;
2876 _TouchInfo TouchInfo(touchinfo);
2877 if (tokenIndex != -1)
2879 if (tokenIndex == __edittingTokenIndex)
2881 __touchPressInfo.x = touchinfo.GetCurrentPosition().x;
2882 __touchPressInfo.y = touchinfo.GetCurrentPosition().y;
2884 _Token* pToken = null;
2885 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
2888 float tokenX = pToken->displayRect.x;
2889 float tokenY = pToken->displayRect.y;
2890 FloatPoint point(__touchPressInfo.x - tokenX, __touchPressInfo.y - tokenY);
2891 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
2896 return _EditPresenter::OnTouchPressed(source, TouchInfo);
2900 _TokenEditPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
2902 __touchPressInfo = FloatPoint(-1.0f, -1.0f);
2904 ProcessTokeningByTouchEvent(source, touchinfo);
2905 if (GetTokenCount())
2907 //Set token bounds appropriately On Fast flick of scroll bar
2908 if (!(__isEditingToken || __edittingTokenIndex >= 0))
2910 SetTokenBoundsByTouchInfo(touchinfo);
2914 _Scroll* pScroll = GetScrollBar();
2917 pScroll->SetScrollVisibility(false);
2920 if (__prevScrollValue)
2922 __prevScrollValue = 0.0f;
2923 __isTokenScrolling = false;
2926 _TouchInfo TouchInfo(touchinfo);
2927 _Token* pToken = null;
2928 if (__edittingTokenIndex >= 0)
2930 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
2933 int tokenX = _CoordinateSystemUtils::ConvertToInteger(pToken->displayRect.x);
2934 int tokenY = _CoordinateSystemUtils::ConvertToInteger(pToken->displayRect.y);
2935 Point point(_CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()).x - tokenX, _CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition()).y - tokenY);
2936 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
2938 _EditPresenter::OnTouchReleased(source, TouchInfo);
2939 __previousCursorPosition = GetCursorPosition();
2943 _EditPresenter::OnTouchReleased(source, touchinfo);
2946 __isTouchMoveInProgress = false;
2947 __trackTokenIndex = -1;
2953 _TokenEditPresenter::OnInputConnectionTextCommitted(InputConnection& source, const String& committedText)
2955 OnTextCommitted(committedText);
2959 _TokenEditPresenter::OnTextCommitted(const String& commitText)
2961 result r = E_SUCCESS;
2962 char enterText[2] = {'\n', };
2963 String enterTextComma(",");
2964 String enterTextSemiColon(";");
2965 if ((commitText == enterText) || (commitText == enterTextComma) || (commitText == enterTextSemiColon))
2967 CoreKeypadAction keypadaction = GetKeypadAction();
2968 __pTokenEdit->SendKeypadEvent(keypadaction, CORE_KEYPAD_EVENT_STATUS_ENTERACTION);
2970 if (__edittingTokenIndex != -1)
2972 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
2973 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
2975 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
2976 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
2978 _Token* pToken = null;
2979 _VisualElement* pTokenVisualElement = null;
2981 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
2985 pTokenVisualElement = pToken->GetVisualElement();
2986 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
2988 if (pCursorVisualElement->GetParent() != pEditVisualElement)
2990 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
2991 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
2993 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
2994 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
2998 String inputTokenString = GetText();
2999 String replacementString = inputTokenString;
3000 bool enable = false;
3002 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
3005 inputTokenString = replacementString;
3008 r = RemoveTokenAt(__edittingTokenIndex);
3009 _EditPresenter::SetTextSize(__editContentFontSize);
3010 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3012 if (inputTokenString.GetLength() > 0)
3014 r = InsertTokenAt(__edittingTokenIndex, inputTokenString);
3015 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3017 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
3018 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null.");
3020 pToken->currTokenLength = inputTokenString.GetLength();
3023 CalculateTokenPositionFromIndex(0);
3024 int lastTokenIndex = GetTokenCount() - 1;
3025 for (int i = 0; i < lastTokenIndex + 1; i++)
3027 _Token* pToken = null;
3028 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3032 pToken->SetBounds(pToken->displayRect);
3036 AdjustFlexibleHeight();
3037 __pressedTokenIndex = -1;
3038 __isTokenEditingFinished = true;
3039 __edittingTokenIndex = -1;
3040 __isEditingToken = false;
3042 if ((__focusedTokenIndex == -1) && (__focusedEditingTokenIndex != -1)
3043 && (inputTokenString.GetLength() > 0))
3045 //1. Tokenedit is focussed
3046 //2. The valid Editing token is focussed
3047 __focusedTokenIndex = __focusedEditingTokenIndex;
3048 ScrollToFocussedToken();
3052 CheckTokenScrolling();
3054 SetCursorDisabled(false);
3056 if (inputTokenString.GetLength() <= 0)
3058 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument is used. Token length is (%d)", inputTokenString.GetLength());
3063 if (GetText().GetLength() > 0)
3067 else if ((__focusedEditingTokenIndex == -1) && (__focusedTokenIndex != -1) && (!__isEditingToken))
3069 if (__isEditModeEnabled)
3071 __edittingTokenIndex = __focusedTokenIndex;
3072 __pressedTokenIndex = __edittingTokenIndex;
3073 __isEditingToken = true;
3074 __focusedEditingTokenIndex = __focusedTokenIndex;
3075 __focusedTokenIndex = -1;
3076 __isTokenEditingFinished = false;
3078 SetEditingTokenTextBounds(__edittingTokenIndex);
3080 r = AttachCursorToPressedToken();
3081 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3086 //Focussed token is ready to be edited again.
3087 __focusedEditingTokenIndex = -1;
3090 for (int i = 0; i < __pTokenList->GetCount(); i++)
3092 TrimTokenAndAdjustEllipsisAt(i);
3093 InitializeTokenVisibilityAt(i);
3096 if ((__pressedTokenIndex < 0) || (__focusedEditingTokenIndex > -1))
3098 SetCursorDisabled(true);
3099 __pTokenEdit->Draw();
3100 SetCursorDisabled(false);
3107 _EditPresenter::OnTextCommitted(commitText);
3108 __previousCursorPosition = GetCursorPosition();
3110 _Token* pToken = null;
3111 if (__edittingTokenIndex >= 0)
3113 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
3114 SysTryReturnVoidResult(NID_UI_CTRL, pToken, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
3116 pToken->ResetToken(GetText());
3117 TrimTokenAndAdjustEllipsisAt(__edittingTokenIndex);
3119 float tokenHeight = 0.0f;
3120 float tokenVerticalSpacing = 0.0f;
3121 float tokenTextLeftMargin = 0.0f;
3123 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3124 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
3125 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
3126 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
3128 FloatRectangle tempTextDspRect;
3129 tempTextDspRect.x += tokenTextLeftMargin;
3130 tempTextDspRect.y += tokenVerticalSpacing / 2.0f;
3131 tempTextDspRect.width = pToken->displayRect.width - (tokenTextLeftMargin * 2.0f);
3132 tempTextDspRect.height = tokenHeight - tokenVerticalSpacing;
3134 SetTextBounds(tempTextDspRect);
3136 if (GetCursorPosition() > pToken->currTokenLength)
3138 _EditPresenter::SetCursorPosition(pToken->currTokenLength);
3142 _EditPresenter::SetCursorPosition(GetCursorPosition());
3147 if (__isEditingToken == false)
3149 __pressedTokenIndex = -1;
3150 SetCursorDisabled(false);
3153 float tokenTopMargin = 0.0f;
3154 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3155 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
3157 FloatRectangle textBounds = GetTextBoundsF();
3158 textBounds.height = GetMaxTextHeight();
3159 SetTextBounds(textBounds);
3162 if (__edittingTokenIndex < 0)
3164 CheckTokenScrolling();
3166 __pTokenEdit->Invalidate();
3172 _TokenEditPresenter::DeleteSurroundingText(InputConnection& source, int offset, int charCount)
3174 OnSurroundingTextDeleted(offset, charCount);
3178 _TokenEditPresenter::OnSurroundingTextDeleted(int offset, int charCount)
3180 __lastTokenIndex = GetTokenCount() - 1;
3181 int cursorPosition = 0;
3185 if ((offset == -1) && (charCount == 1))
3187 if (GetTextLength() == 0 && GetTokenCount()) // There is no candidate token.
3189 if (__isEditingToken == true)
3191 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3192 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3194 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3195 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3197 _Token* pToken = null;
3198 _VisualElement* pTokenVisualElement = null;
3200 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
3204 pTokenVisualElement = pToken->GetVisualElement();
3205 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3207 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3209 result r = E_SUCCESS;
3210 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3211 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3213 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3214 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3218 RemoveTokenAt(__edittingTokenIndex);
3220 CalculateTokenPositionFromIndex(__edittingTokenIndex);
3221 for (int i = __edittingTokenIndex; i < __lastTokenIndex + 1; i++)
3223 _Token* pToken = null;
3224 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3227 pToken->SetBounds(pToken->displayRect);
3231 __pressedTokenIndex = -1;
3232 __edittingTokenIndex = -1;
3233 __isEditingToken = false;
3234 _EditPresenter::SetTextSize(__editContentFontSize);
3235 __isTokenEditingFinished = false;
3237 AdjustFlexibleHeight();
3238 CheckTokenScrolling();
3240 else if (__pressedTokenIndex != -1)
3242 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3243 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3245 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3246 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3248 _Token* pToken = null;
3249 _VisualElement* pTokenVisualElement = null;
3251 pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
3255 pTokenVisualElement = pToken->GetVisualElement();
3256 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3258 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3260 result r = E_SUCCESS;
3261 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3262 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3264 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3265 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3269 RemoveTokenAt(__pressedTokenIndex);
3271 CalculateTokenPositionFromIndex(__pressedTokenIndex);
3272 for (int i = __pressedTokenIndex; i < __lastTokenIndex + 1; i++)
3274 _Token* pToken = null;
3275 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3279 pToken->SetBounds(pToken->displayRect);
3285 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3286 SysTryReturnVoidResult(NID_UI_CTRL, pEditVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get root visual element.");
3288 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3289 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3291 _Token* pToken = null;
3292 _VisualElement* pTokenVisualElement = null;
3293 if (__animatingIndex == (GetTokenCount() - 1))
3295 pToken = static_cast <_Token*>(__pTokenList->GetAt(GetTokenCount() - 1));
3298 pTokenVisualElement = pToken->GetVisualElement();
3299 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3300 pTokenVisualElement->RemoveAnimation(L"TokenAnimation");
3303 pToken = static_cast <_Token*>(__pTokenList->GetAt(GetTokenCount() - 1));
3306 pTokenVisualElement = pToken->GetVisualElement();
3307 SysTryReturnVoidResult(NID_UI_CTRL, pTokenVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get token visual element.");
3309 if (pCursorVisualElement->GetParent() != pEditVisualElement)
3311 result r = E_SUCCESS;
3312 r = pCursorVisualElement->GetParent()->DetachChild(*pCursorVisualElement);
3313 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3315 r = pEditVisualElement->AttachChild(*pCursorVisualElement);
3316 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
3320 __animatingIndex = GetTokenCount() - 1;
3322 if (pTokenVisualElement && __animatingIndex >= 0)
3324 __isAnimationInProgress = true;
3325 VisualElementAnimation* pAnimation = CreateAnimationN(*pTokenVisualElement, false);
3326 pTokenVisualElement->AddAnimation(L"TokenAnimation", *pAnimation);
3332 __pTokenEdit->Invalidate();
3337 if (__pressedTokenIndex >= 0 && __edittingTokenIndex < 0 && !__isEditingToken)
3339 RemoveTokenAt(__pressedTokenIndex);
3340 __pTokenEdit->Invalidate();
3343 else if (__focusedTokenIndex >= 0 && __edittingTokenIndex < 0 && !__isEditingToken)
3345 RemoveTokenAt(__focusedTokenIndex);
3346 __pTokenEdit->Invalidate();
3351 //Backspace on Blocked text, delete full block
3352 if (IsBlocked() == true)
3354 GetBlockRange(start, end);
3358 cursorPosition = GetCursorPosition();
3359 start = cursorPosition + offset;
3364 end = start + charCount;
3365 if (end > GetTextLength())
3371 DeleteText(start, end);
3372 __previousCursorPosition = start;
3374 if (IsCopyPasteManagerExist())
3376 InitializeCopyPasteManager();
3378 if (IsBlocked() == true)
3382 if (__isEditingToken != true)
3387 __pTokenEdit->SendTextEvent(CORE_TEXT_EVENT_CHANGED);
3390 cursorPosition = GetCursorPosition();
3391 start = cursorPosition + offset;
3396 end = start + charCount;
3397 if (end > GetTextLength())
3402 Rectangle currBounds = __pTokenEdit->GetBounds();
3403 DeleteText(start, end);
3404 __previousCursorPosition = start;
3405 if (__isEditingToken != true)
3411 _Token* pToken = null;
3413 if (__edittingTokenIndex >= 0 && __isEditingToken)
3415 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
3419 float tokenHeight = 0.0f;
3420 float tokenVerticalSpacing = 0.0f;
3421 float tokenTextLeftMargin = 0.0f;
3423 SetCursorPosition(__previousCursorPosition);
3425 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3426 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_HEIGHT, orientation, tokenHeight);
3427 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_VERTICAL_SPACING, orientation, tokenVerticalSpacing);
3428 GET_SHAPE_CONFIG(TOKENEDIT::TOKEN_TEXT_LEFT_MARGIN, orientation, tokenTextLeftMargin);
3430 FloatRectangle tempTextDspRect;
3431 tempTextDspRect.x += tokenTextLeftMargin;
3432 tempTextDspRect.y += tokenVerticalSpacing / 2.0f;
3433 tempTextDspRect.width = pToken->displayRect.width - (tokenTextLeftMargin * 2.0f);
3434 tempTextDspRect.height = tokenHeight - tokenVerticalSpacing;
3436 SetTextBounds(tempTextDspRect);
3437 _EditPresenter::SetCursorPosition(start);
3439 pToken->ResetToken(GetText());
3440 TrimTokenAndAdjustEllipsisAt(__edittingTokenIndex);
3444 __pTokenEdit->Draw();
3448 _TokenEditPresenter::OnTapGestureDetected(void)
3450 if (__edittingTokenIndex >= 0)
3452 __isPopupVisible = true;
3455 //Uncomment below to Block Copy & Paste functionality in Token Edit mode
3456 if (__pressedTokenIndex != -1)
3460 return _EditPresenter::OnTapGestureDetected();
3464 _TokenEditPresenter::CheckCopyPastePopupShowStatus(void)
3466 if (__edittingTokenIndex < 0)
3468 float controlHeight = __pTokenEdit->GetBoundsF().height;
3469 FloatRectangle cursorBounds;
3470 GetCursorBounds(false, cursorBounds);
3471 if (cursorBounds.y > controlHeight)
3481 _TokenEditPresenter::OnLongPressGestureDetected(void)
3483 if (CheckCopyPastePopupShowStatus())
3485 //TextBounds bigger than control height. Dont show Copy paste popup
3489 //Discard all long press that is detected after Touch press on a token
3490 if (__trackTokenIndex >= 0)
3495 __isLongPressed = true;
3497 //Uncomment below to Block Copy & Paste functionality in Token Edit mode
3498 if (__pressedTokenIndex != -1)
3502 return _EditPresenter::OnLongPressGestureDetected();
3506 _TokenEditPresenter::OnCursorTimerExpired(void)
3508 if (__edittingTokenIndex != -1)
3516 FloatRectangle cursorRect;
3518 _Token* pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
3519 SysTryReturnVoidResult(NID_UI_CTRL, pToken != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The _Token instance is null");
3521 //Set Editing token bounds for text scroll and cursor position calculation (SetTextBounds should have been done prior to this)
3522 FloatRectangle cursorDspRect = _EditPresenter::GetTextBoundsF();
3524 if (CalculateCursorBounds(cursorDspRect, cursorRect) != E_SUCCESS)
3530 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3531 SysTryReturnVoidResult(NID_UI_CTRL, pCursorVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get cursor visual element.");
3533 Canvas* pCursorCanvas = pCursorVisualElement->GetCanvasN();
3534 SysTryReturnVoidResult(NID_UI_CTRL, pCursorCanvas != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get canvas of cursor visual element.");
3536 bool cursorEnable = IsCursorEnabled();
3538 pCursorVisualElement->SetBounds(cursorRect);
3539 DrawCursor(*pCursorCanvas, cursorRect, cursorEnable);
3543 cursorEnable = false;
3547 cursorEnable = true;
3549 SetCursorEnabled(cursorEnable);
3551 pCursorCanvas->Show();
3552 delete pCursorCanvas;
3558 _EditPresenter::OnCursorTimerExpired();
3563 _TokenEditPresenter::IsTextBlockedInTokenEdit(void) const
3565 if ((IsBlocked() == true) && (__isEditingToken) && (__edittingTokenIndex >= 0))
3573 _TokenEditPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
3575 __isTouchMoveInProgress = true;
3577 if (GetTokenCount())
3579 //Scrolling is blocked when a popup is visible or when a text is blocked
3580 if (IsBlocked() == true || __isLongPressed == true)
3585 //Allow touch move only in horizontal direction when editing token
3586 _TouchInfo TouchInfo(touchinfo);
3587 _Token* pToken = null;
3588 if (__edittingTokenIndex >= 0)
3590 if (__touchPressInfo.y > 0.0f)
3592 pToken = static_cast <_Token*>(__pTokenList->GetAt(__edittingTokenIndex));
3595 float tokenX = pToken->displayRect.x;
3596 float tokenY = pToken->displayRect.y;
3597 FloatPoint point(touchinfo.GetCurrentPosition().x - tokenX, __touchPressInfo.y - tokenY);
3598 TouchInfo.SetTouchInfo(touchinfo.GetPointId(), touchinfo.GetTouchStatus(), point, touchinfo.IsFlicked(), touchinfo.GetTimeStamp());
3601 bool retValue = _EditPresenter::OnTouchMoved(source, TouchInfo);
3602 __previousCursorPosition = GetCursorPosition();
3612 SetTokenBoundsByTouchInfo(touchinfo);
3614 if (!(__pTokenEdit->GetEditStyle() & EDIT_STYLE_NOSCROLL))
3616 _Scroll* pScroll = GetScrollBar();
3619 float tokenBottomMargin = 0.0f;
3620 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, tokenBottomMargin);
3622 float totalHeight = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin;
3623 float controlHeight = __pTokenEdit->GetBoundsF().height;
3625 if (totalHeight > controlHeight)
3627 pScroll->SetScrollVisibility(true);
3631 pScroll->SetScrollVisibility(false);
3636 return _EditPresenter::OnTouchMoved(source, touchinfo);
3640 return _EditPresenter::OnTouchMoved(source, touchinfo);
3646 _TokenEditPresenter::OnVisualElementAnimationFinished (const Tizen::Ui::Animations::VisualElementAnimation &animation, const Tizen::Base::String &keyName, Tizen::Ui::Animations::VisualElement &target, bool completedNormally)
3648 __isAnimationInProgress = false;
3649 RemoveTokenAt(GetTokenCount() - 1);
3650 CalculateTokenPositionFromIndex(GetTokenCount() - 1);
3652 for (int i = GetTokenCount() - 1; i < GetTokenCount() - 1 + 1; i++)
3654 _Token* pToken = null;
3655 pToken = static_cast <_Token*>(__pTokenList->GetAt(i));
3659 pToken->SetBounds(pToken->displayRect);
3662 if (__lastTokenIndex == __pressedTokenIndex)
3664 __pressedTokenIndex--;
3667 if (GetTokenCount() == 0 && __animatingIndex == 0)
3671 __animatingIndex = -1;
3680 _TokenEditPresenter::OnTimerExpired(Timer& timer)
3682 Timer* onTimer = &timer;
3683 Canvas* pDescriptionTextCanvas = null;
3685 if (onTimer == _EditPresenter::__pTitleSlidingTimer)
3689 _EditPresenter::StopTitleSlidingTimer();
3690 __isTitleSliding = false;
3694 FloatRectangle tempDescriptionTextRect = __descriptionTextRect;
3695 tempDescriptionTextRect.x = 0.0f;
3696 tempDescriptionTextRect.y = 0.0f;
3698 pDescriptionTextCanvas = __pDescriptionTextVisualElement->GetCanvasN();
3699 SysTryReturnVoidResult(NID_UI_CTRL, pDescriptionTextCanvas, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pDescriptionTextCanvas is invalid!");
3701 pDescriptionTextCanvas->SetBackgroundColor(Color(0));
3702 pDescriptionTextCanvas->Clear();
3703 __pDescriptionTextTextObject->SetBounds(tempDescriptionTextRect);
3704 __pDescriptionTextTextObject->DrawWithOffset(*_CanvasImpl::GetInstance(*pDescriptionTextCanvas));
3705 Rectangle descriptionTextRect = _CoordinateSystemUtils::ConvertToInteger(tempDescriptionTextRect);
3706 pDescriptionTextCanvas->Show(descriptionTextRect);
3708 delete pDescriptionTextCanvas;
3710 _EditPresenter::StartTitleSlidingTimer();
3711 __isTitleSliding = true;
3715 _EditPresenter::OnTimerExpired(timer);
3720 _TokenEditPresenter::ChangeInternalLayout(_ControlOrientation orientation)
3722 result r = E_SUCCESS;
3724 __scrollValue = 0.0f;
3725 __maxScrollValue = 0.0f;
3726 float tokenBottomMargin = 0.0f;
3727 float newScrollValue = 0.0f;
3729 FloatRectangle windowBounds = GetInitialBoundsF();
3731 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
3733 r = CalculateTokenPositionFromIndex(0);
3734 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3736 r = SetInitialBounds();
3737 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3739 if (__isEditingToken)
3741 if (__edittingTokenIndex >= 0 && __edittingTokenIndex < GetTokenCount())
3743 String inputTokenString = GetText();
3744 String replacementString = inputTokenString;
3745 bool enable = false;
3747 __pTokenEdit->ProcessTokenFiltering(inputTokenString, replacementString, enable);
3750 inputTokenString = replacementString;
3753 if (inputTokenString.GetLength() > 0)
3755 int index = __edittingTokenIndex;
3756 RemoveTokenAt(__edittingTokenIndex, true);
3757 InsertTokenAt(index, inputTokenString);
3764 r = AdjustFlexibleHeight();
3765 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3767 r = CheckTokenScrolling();
3768 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3774 r = AdjustFlexibleHeight();
3775 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3777 windowBounds = __pTokenEdit->GetBoundsF();
3780 newScrollValue = GetTextBoundsF().y + GetTextBoundsF().height - __scrollValue + tokenBottomMargin - windowBounds.height;
3781 if (newScrollValue > 0.0f)
3783 __maxScrollValue = newScrollValue;
3784 __isNeedToScroll = true;
3791 _TokenEditPresenter::ChangeLayout(_ControlOrientation orientation)
3793 result r = E_SUCCESS;
3795 r = _EditPresenter::ChangeLayout(orientation);
3796 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3798 r = ChangeInternalLayout(orientation);
3804 _TokenEditPresenter::OnBoundsChanged(void)
3806 if (!__isTokenEditPresenterInitialized)
3811 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3812 FloatRectangle tokenEditBounds = __pTokenEdit->GetBoundsF();
3814 if (IsUpdateInitialBounds())
3816 SetControlInitialBounds(tokenEditBounds);
3818 ChangeInternalLayout(orientation);
3824 _TokenEditPresenter::AttachCursorToPressedToken(void)
3826 result r = E_SUCCESS;
3828 _VisualElement* pEditVisualElement = __pTokenEdit->GetVisualElement();
3829 SysTryReturnResult(NID_UI_CTRL, pEditVisualElement, E_SYSTEM, "A system error has occurred. Failed to get root visual element.");
3831 _VisualElement* pCursorVisualElement = GetCursorVisualElement();
3832 SysTryReturnResult(NID_UI_CTRL, pCursorVisualElement, E_SYSTEM, "A system error has occurred. Failed to get cursor visual element.");
3834 _Token* pToken = null;
3835 _VisualElement* pTokenVisualElement = null;
3837 pToken = static_cast <_Token*>(__pTokenList->GetAt(__pressedTokenIndex));
3840 pTokenVisualElement = pToken->GetVisualElement();
3841 SysTryReturnResult(NID_UI_CTRL, pTokenVisualElement, E_SYSTEM, "A system error has occurred. Failed to get token visual element.");
3843 if (pCursorVisualElement->GetParent() != pTokenVisualElement)
3845 r = (pCursorVisualElement->GetParent())->DetachChild(*pCursorVisualElement);
3846 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3848 r = pTokenVisualElement->AttachChild(*pCursorVisualElement);
3849 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3857 _TokenEditPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
3859 _KeyCode keyCode = keyInfo.GetKeyCode();
3860 bool focusChanged = false;
3861 int tokenCount = GetTokenCount();
3863 if (IsUsbKeyboardConnected() && (keyInfo.GetKeyModifier() & _KEY_MODIFIER_CTRL))
3871 if (__isEditingToken)
3882 if ((keyCode == _KEY_NUM_LEFT) || (keyCode == _KEY_LEFT))
3884 if (!__isEditingToken)
3886 if ((__focusedTokenIndex > 0) && (__focusedTokenIndex < tokenCount))
3888 __focusedTokenIndex--;
3889 focusChanged = true;
3894 if ((keyCode == _KEY_NUM_RIGHT) || (keyCode == _KEY_RIGHT))
3896 int lastTokenIndex = tokenCount - 1;
3897 if (!__isEditingToken)
3899 if (__pressedTokenIndex != -1)
3901 __pressedTokenIndex = -1;
3902 __focusedTokenIndex = 0;
3903 focusChanged = true;
3905 else if (__focusedTokenIndex < lastTokenIndex)
3907 __focusedTokenIndex++;
3908 focusChanged = true;
3915 ScrollToFocussedToken();
3918 return _EditPresenter::OnKeyPressed(source, keyInfo);
3922 _TokenEditPresenter::ScrollToFocussedToken(void)
3924 result r = E_SUCCESS;
3925 int tokenCount = GetTokenCount();
3926 FloatRectangle focussedTokenRectangle;
3927 float newScrollValue = 0.0f;
3928 float tokenTopMargin = 0.0f;
3929 float tokenBottomMargin = 0.0f;
3930 _ControlOrientation orientation = __pTokenEdit->GetOrientation();
3933 GET_SHAPE_CONFIG(TOKENEDIT::TOP_MARGIN, orientation, tokenTopMargin);
3934 GET_SHAPE_CONFIG(TOKENEDIT::BOTTOM_MARGIN, orientation, tokenBottomMargin);
3936 FloatRectangle tokenEditRect = __pTokenEdit->GetBoundsF();
3938 if ((__focusedTokenIndex > -1) && (__focusedTokenIndex < tokenCount))
3940 _Token* pToken = null;
3941 pToken = static_cast <_Token*>(__pTokenList->GetAt(__focusedTokenIndex));
3943 focussedTokenRectangle = pToken->displayRect;
3945 float focussedTokenPosition= focussedTokenRectangle.y + focussedTokenRectangle.height ;
3947 if ((focussedTokenRectangle.y > 0) && (focussedTokenPosition < tokenEditRect.height))
3949 //Focused token is within the tokenEdit boundary
3954 if (focussedTokenRectangle.y < 0)
3956 //Focused token is above the upper boundary
3957 newScrollValue = focussedTokenRectangle.y - tokenTopMargin - __scrollValue;
3961 //Focused token is below the lower boundary
3962 newScrollValue = focussedTokenPosition - tokenEditRect.height + tokenBottomMargin - __scrollValue;
3965 r = RecalculateTokenBounds(newScrollValue);
3966 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
3973 }}} //Tizen::Ui::Controls