2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/text-controller.h>
22 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
23 #include <dali/devel-api/adaptor-framework/window-devel.h>
24 #include <dali/integration-api/debug.h>
30 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
31 #include <dali-toolkit/internal/text/text-controller-event-handler.h>
32 #include <dali-toolkit/internal/text/text-controller-impl.h>
33 #include <dali-toolkit/internal/text/text-controller-input-font-handler.h>
34 #include <dali-toolkit/internal/text/text-controller-placeholder-handler.h>
35 #include <dali-toolkit/internal/text/text-controller-relayouter.h>
36 #include <dali-toolkit/internal/text/text-controller-text-updater.h>
37 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
41 #if defined(DEBUG_ENABLED)
42 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
45 constexpr float MAX_FLOAT = std::numeric_limits<float>::max();
47 const std::string EMPTY_STRING("");
49 template<typename Type>
50 void EnsureCreated(Type*& object)
58 template<typename Type>
59 void EnsureCreated(std::unique_ptr<Type>& object)
63 object = std::unique_ptr<Type>(new Type());
67 template<typename Type, typename Arg1>
68 void EnsureCreated(Type*& object, Arg1 arg1)
72 object = new Type(arg1);
76 template<typename Type, typename Arg1, typename Arg2>
77 void EnsureCreated(Type*& object, Arg1 arg1, Arg2 arg2)
81 object = new Type(arg1, arg2);
87 unsigned int horizontalDpi = 0u;
88 unsigned int verticalDpi = 0u;
89 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
90 fontClient.GetDpi(horizontalDpi, verticalDpi);
91 return static_cast<float>(horizontalDpi);
94 float ConvertPixelToPoint(float pixel)
96 return pixel * 72.0f / GetDpi();
99 float ConvertPointToPixel(float point)
101 // Pixel size = Point size * DPI / 72.f
102 return point * GetDpi() / 72.0f;
105 void UpdateCursorPosition(Dali::Toolkit::Text::EventData* eventData)
107 if(eventData && Dali::Toolkit::Text::EventData::IsEditingState(eventData->mState))
109 // Update the cursor position if it's in editing mode
110 eventData->mDecoratorUpdated = true;
111 eventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
117 namespace Dali::Toolkit::Text
120 void Controller::EnableTextInput(DecoratorPtr decorator, InputMethodContext& inputMethodContext)
124 delete mImpl->mEventData;
125 mImpl->mEventData = NULL;
127 // Nothing else to do.
131 EnsureCreated(mImpl->mEventData, decorator, inputMethodContext);
134 void Controller::SetGlyphType(TextAbstraction::GlyphType glyphType)
136 // Metrics for bitmap & vector based glyphs are different
137 mImpl->mMetrics->SetGlyphType(glyphType);
139 // Clear the font-specific data
142 mImpl->RequestRelayout();
145 void Controller::SetMarkupProcessorEnabled(bool enable)
147 if(enable != mImpl->mMarkupProcessorEnabled)
149 //If Text was already set, call the SetText again for enabling or disabling markup
150 mImpl->mMarkupProcessorEnabled = enable;
156 mImpl->mModel->mVisualModel->SetMarkupProcessorEnabled(enable);
159 bool Controller::IsMarkupProcessorEnabled() const
161 return mImpl->mMarkupProcessorEnabled;
164 bool Controller::HasAnchors() const
166 return (mImpl->mMarkupProcessorEnabled && mImpl->mModel->mLogicalModel->mAnchors.Count() && mImpl->IsShowingRealText());
169 void Controller::SetAutoScrollEnabled(bool enable)
171 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled[%s] SingleBox[%s]-> [%p]\n", (enable) ? "true" : "false", (mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX) ? "true" : "false", this);
173 if(mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)
175 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
183 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n");
184 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | UPDATE_DIRECTION);
188 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
191 mImpl->mIsAutoScrollEnabled = enable;
192 mImpl->RequestRelayout();
196 DALI_LOG_WARNING("Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n");
197 mImpl->mIsAutoScrollEnabled = false;
201 bool Controller::IsAutoScrollEnabled() const
203 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled ? "true" : "false");
205 return mImpl->mIsAutoScrollEnabled;
208 CharacterDirection Controller::GetAutoScrollDirection() const
210 return mImpl->mIsTextDirectionRTL;
213 float Controller::GetAutoScrollLineAlignment() const
216 if(mImpl->mModel->mVisualModel && (0u != mImpl->mModel->mVisualModel->mLines.Count()))
218 offset = (*mImpl->mModel->mVisualModel->mLines.Begin()).alignmentOffset;
223 void Controller::SetHorizontalScrollEnabled(bool enable)
225 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
227 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled(enable);
231 bool Controller::IsHorizontalScrollEnabled() const
233 return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
236 void Controller::SetVerticalScrollEnabled(bool enable)
238 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
240 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled(enable);
244 bool Controller::IsVerticalScrollEnabled() const
246 return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
249 void Controller::SetSmoothHandlePanEnabled(bool enable)
251 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
253 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled(enable);
257 bool Controller::IsSmoothHandlePanEnabled() const
259 return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
262 void Controller::SetMaximumNumberOfCharacters(Length maxCharacters)
264 mImpl->mMaximumNumberOfCharacters = maxCharacters;
267 int Controller::GetMaximumNumberOfCharacters()
269 return mImpl->mMaximumNumberOfCharacters;
272 void Controller::SetEnableCursorBlink(bool enable)
274 DALI_ASSERT_DEBUG(NULL != mImpl->mEventData && "TextInput disabled");
276 if(mImpl->mEventData)
278 mImpl->mEventData->mCursorBlinkEnabled = enable;
280 if(!enable && mImpl->mEventData->mDecorator)
282 mImpl->mEventData->mDecorator->StopCursorBlink();
287 bool Controller::GetEnableCursorBlink() const
289 return mImpl->mEventData && mImpl->mEventData->mCursorBlinkEnabled;
292 void Controller::SetMultiLineEnabled(bool enable)
294 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
296 if(layout != mImpl->mLayoutEngine.GetLayout())
298 // Set the layout type.
299 mImpl->mLayoutEngine.SetLayout(layout);
301 // Set the flags to redo the layout operations
302 const OperationsMask layoutOperations = static_cast<OperationsMask>(LAYOUT |
307 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
308 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | layoutOperations);
310 // Need to recalculate natural size
311 mImpl->mRecalculateNaturalSize = true;
313 mImpl->RequestRelayout();
317 bool Controller::IsMultiLineEnabled() const
319 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
322 void Controller::SetHorizontalAlignment(Text::HorizontalAlignment::Type alignment)
324 if(alignment != mImpl->mModel->mHorizontalAlignment)
326 // Set the alignment.
327 mImpl->mModel->mHorizontalAlignment = alignment;
329 // Set the flag to redo the alignment operation.
330 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | ALIGN);
332 if(mImpl->mEventData)
334 mImpl->mEventData->mUpdateAlignment = true;
336 // Update the cursor if it's in editing mode
337 if(EventData::IsEditingState(mImpl->mEventData->mState))
339 mImpl->ChangeState(EventData::EDITING);
340 mImpl->mEventData->mUpdateCursorPosition = true;
344 mImpl->RequestRelayout();
348 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
350 return mImpl->mModel->mHorizontalAlignment;
353 void Controller::SetVerticalAlignment(VerticalAlignment::Type alignment)
355 if(alignment != mImpl->mModel->mVerticalAlignment)
357 // Set the alignment.
358 mImpl->mModel->mVerticalAlignment = alignment;
359 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | ALIGN);
360 mImpl->RequestRelayout();
364 VerticalAlignment::Type Controller::GetVerticalAlignment() const
366 return mImpl->mModel->mVerticalAlignment;
369 bool Controller::IsIgnoreSpacesAfterText() const
371 return mImpl->mModel->mIgnoreSpacesAfterText;
374 void Controller::SetIgnoreSpacesAfterText(bool ignore)
376 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
379 void Controller::ChangedLayoutDirection()
381 mImpl->mIsLayoutDirectionChanged = true;
384 void Controller::SetMatchLayoutDirection(DevelText::MatchLayoutDirection type)
386 mImpl->mModel->mMatchLayoutDirection = type;
389 DevelText::MatchLayoutDirection Controller::GetMatchLayoutDirection() const
391 return mImpl->mModel->mMatchLayoutDirection;
394 void Controller::SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection)
396 mImpl->mLayoutDirection = layoutDirection;
399 Dali::LayoutDirection::Type Controller::GetLayoutDirection(Dali::Actor& actor) const
401 if(mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::LOCALE ||
402 (mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::INHERIT && !mImpl->mIsLayoutDirectionChanged))
404 return static_cast<Dali::LayoutDirection::Type>(DevelWindow::Get(actor).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
408 return static_cast<Dali::LayoutDirection::Type>(actor.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
412 bool Controller::IsShowingRealText() const
414 return mImpl->IsShowingRealText();
417 void Controller::SetLineWrapMode(Text::LineWrap::Mode lineWrapMode)
419 if(lineWrapMode != mImpl->mModel->mLineWrapMode)
421 // Update Text layout for applying wrap mode
422 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
428 if((mImpl->mModel->mLineWrapMode == (Text::LineWrap::Mode)DevelText::LineWrap::HYPHENATION) || (lineWrapMode == (Text::LineWrap::Mode)DevelText::LineWrap::HYPHENATION) ||
429 (mImpl->mModel->mLineWrapMode == (Text::LineWrap::Mode)DevelText::LineWrap::MIXED) || (lineWrapMode == (Text::LineWrap::Mode)DevelText::LineWrap::MIXED)) // hyphen is treated as line break
431 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | GET_LINE_BREAKS);
434 // Set the text wrap mode.
435 mImpl->mModel->mLineWrapMode = lineWrapMode;
437 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
438 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
439 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
442 mImpl->RequestRelayout();
446 Text::LineWrap::Mode Controller::GetLineWrapMode() const
448 return mImpl->mModel->mLineWrapMode;
451 void Controller::SetTextElideEnabled(bool enabled)
453 mImpl->mModel->mElideEnabled = enabled;
454 mImpl->mModel->mVisualModel->SetTextElideEnabled(enabled);
457 bool Controller::IsTextElideEnabled() const
459 return mImpl->mModel->mElideEnabled;
462 void Controller::SetTextFitEnabled(bool enabled)
464 mImpl->mTextFitEnabled = enabled;
467 bool Controller::IsTextFitEnabled() const
469 return mImpl->mTextFitEnabled;
472 void Controller::SetTextFitMinSize(float minSize, FontSizeType type)
474 mImpl->mTextFitMinSize = (type == POINT_SIZE) ? minSize : ConvertPixelToPoint(minSize);
477 float Controller::GetTextFitMinSize() const
479 return mImpl->mTextFitMinSize;
482 void Controller::SetTextFitMaxSize(float maxSize, FontSizeType type)
484 mImpl->mTextFitMaxSize = (type == POINT_SIZE) ? maxSize : ConvertPixelToPoint(maxSize);
487 float Controller::GetTextFitMaxSize() const
489 return mImpl->mTextFitMaxSize;
492 void Controller::SetTextFitStepSize(float step, FontSizeType type)
494 mImpl->mTextFitStepSize = (type == POINT_SIZE) ? step : ConvertPixelToPoint(step);
497 float Controller::GetTextFitStepSize() const
499 return mImpl->mTextFitStepSize;
502 void Controller::SetTextFitContentSize(Vector2 size)
504 mImpl->mTextFitContentSize = size;
507 Vector2 Controller::GetTextFitContentSize() const
509 return mImpl->mTextFitContentSize;
512 void Controller::SetPlaceholderTextElideEnabled(bool enabled)
514 PlaceholderHandler::SetPlaceholderTextElideEnabled(*this, enabled);
517 bool Controller::IsPlaceholderTextElideEnabled() const
519 return PlaceholderHandler::IsPlaceholderTextElideEnabled(*this);
522 void Controller::SetSelectionEnabled(bool enabled)
524 mImpl->mEventData->mSelectionEnabled = enabled;
527 bool Controller::IsSelectionEnabled() const
529 return mImpl->mEventData->mSelectionEnabled;
532 void Controller::SetShiftSelectionEnabled(bool enabled)
534 mImpl->mEventData->mShiftSelectionFlag = enabled;
537 bool Controller::IsShiftSelectionEnabled() const
539 return mImpl->mEventData->mShiftSelectionFlag;
542 void Controller::SetGrabHandleEnabled(bool enabled)
544 mImpl->mEventData->mGrabHandleEnabled = enabled;
547 bool Controller::IsGrabHandleEnabled() const
549 return mImpl->mEventData->mGrabHandleEnabled;
552 void Controller::SetGrabHandlePopupEnabled(bool enabled)
554 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
557 bool Controller::IsGrabHandlePopupEnabled() const
559 return mImpl->mEventData->mGrabHandlePopupEnabled;
562 void Controller::SetText(const std::string& text)
564 TextUpdater::SetText(*this, text);
567 void Controller::GetText(std::string& text) const
569 if(!mImpl->IsShowingPlaceholderText())
571 // Retrieves the text string.
572 mImpl->GetText(0u, text);
576 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this);
580 void Controller::SetPlaceholderText(PlaceholderType type, const std::string& text)
582 PlaceholderHandler::SetPlaceholderText(*this, type, text);
585 void Controller::GetPlaceholderText(PlaceholderType type, std::string& text) const
587 PlaceholderHandler::GetPlaceholderText(*this, type, text);
590 void Controller::UpdateAfterFontChange(const std::string& newDefaultFont)
592 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
594 if(!mImpl->mFontDefaults->familyDefined) // If user defined font then should not update when system font changes
596 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str());
597 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
601 mImpl->RequestRelayout();
605 void Controller::RetrieveSelection(std::string& selectedText) const
607 mImpl->RetrieveSelection(selectedText, false);
610 void Controller::SetSelection(int start, int end)
612 mImpl->SetSelection(start, end);
615 std::pair<int, int> Controller::GetSelectionIndexes() const
617 return mImpl->GetSelectionIndexes();
620 void Controller::CopyStringToClipboard(const std::string& source)
622 mImpl->CopyStringToClipboard(source);
625 void Controller::SendSelectionToClipboard(bool deleteAfterSending)
627 mImpl->SendSelectionToClipboard(deleteAfterSending);
630 void Controller::SetDefaultFontFamily(const std::string& defaultFontFamily)
632 EnsureCreated(mImpl->mFontDefaults);
634 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
635 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
636 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
638 // Update the cursor position if it's in editing mode
639 UpdateCursorPosition(mImpl->mEventData);
641 // Clear the font-specific data
644 mImpl->RequestRelayout();
647 const std::string& Controller::GetDefaultFontFamily() const
649 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.family : EMPTY_STRING;
652 void Controller::SetPlaceholderFontFamily(const std::string& placeholderTextFontFamily)
654 PlaceholderHandler::SetPlaceholderFontFamily(*this, placeholderTextFontFamily);
657 const std::string& Controller::GetPlaceholderFontFamily() const
659 return PlaceholderHandler::GetPlaceholderFontFamily(*this);
662 void Controller::SetDefaultFontWeight(FontWeight weight)
664 EnsureCreated(mImpl->mFontDefaults);
666 mImpl->mFontDefaults->mFontDescription.weight = weight;
667 mImpl->mFontDefaults->weightDefined = true;
669 // Update the cursor position if it's in editing mode
670 UpdateCursorPosition(mImpl->mEventData);
672 // Clear the font-specific data
675 mImpl->RequestRelayout();
678 bool Controller::IsDefaultFontWeightDefined() const
680 return mImpl->mFontDefaults && mImpl->mFontDefaults->weightDefined;
683 FontWeight Controller::GetDefaultFontWeight() const
685 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.weight : TextAbstraction::FontWeight::NORMAL;
688 void Controller::SetPlaceholderTextFontWeight(FontWeight weight)
690 PlaceholderHandler::SetPlaceholderTextFontWeight(*this, weight);
693 bool Controller::IsPlaceholderTextFontWeightDefined() const
695 return PlaceholderHandler::IsPlaceholderTextFontWeightDefined(*this);
698 FontWeight Controller::GetPlaceholderTextFontWeight() const
700 return PlaceholderHandler::GetPlaceholderTextFontWeight(*this);
703 void Controller::SetDefaultFontWidth(FontWidth width)
705 EnsureCreated(mImpl->mFontDefaults);
707 mImpl->mFontDefaults->mFontDescription.width = width;
708 mImpl->mFontDefaults->widthDefined = true;
710 // Update the cursor position if it's in editing mode
711 UpdateCursorPosition(mImpl->mEventData);
713 // Clear the font-specific data
716 mImpl->RequestRelayout();
719 bool Controller::IsDefaultFontWidthDefined() const
721 return mImpl->mFontDefaults && mImpl->mFontDefaults->widthDefined;
724 FontWidth Controller::GetDefaultFontWidth() const
726 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.width : TextAbstraction::FontWidth::NORMAL;
729 void Controller::SetPlaceholderTextFontWidth(FontWidth width)
731 PlaceholderHandler::SetPlaceholderTextFontWidth(*this, width);
734 bool Controller::IsPlaceholderTextFontWidthDefined() const
736 return PlaceholderHandler::IsPlaceholderTextFontWidthDefined(*this);
739 FontWidth Controller::GetPlaceholderTextFontWidth() const
741 return PlaceholderHandler::GetPlaceholderTextFontWidth(*this);
744 void Controller::SetDefaultFontSlant(FontSlant slant)
746 EnsureCreated(mImpl->mFontDefaults);
748 mImpl->mFontDefaults->mFontDescription.slant = slant;
749 mImpl->mFontDefaults->slantDefined = true;
751 // Update the cursor position if it's in editing mode
752 UpdateCursorPosition(mImpl->mEventData);
754 // Clear the font-specific data
757 mImpl->RequestRelayout();
760 bool Controller::IsDefaultFontSlantDefined() const
762 return mImpl->mFontDefaults && mImpl->mFontDefaults->slantDefined;
765 FontSlant Controller::GetDefaultFontSlant() const
767 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.slant : TextAbstraction::FontSlant::NORMAL;
770 void Controller::SetPlaceholderTextFontSlant(FontSlant slant)
772 PlaceholderHandler::SetPlaceholderTextFontSlant(*this, slant);
775 bool Controller::IsPlaceholderTextFontSlantDefined() const
777 return PlaceholderHandler::IsPlaceholderTextFontSlantDefined(*this);
780 FontSlant Controller::GetPlaceholderTextFontSlant() const
782 return PlaceholderHandler::GetPlaceholderTextFontSlant(*this);
785 void Controller::SetFontSizeScale(float scale)
787 mImpl->mFontSizeScale = scale;
789 // Update the cursor position if it's in editing mode
790 UpdateCursorPosition(mImpl->mEventData);
792 // Clear the font-specific data
795 mImpl->RequestRelayout();
798 float Controller::GetFontSizeScale() const
800 return mImpl->mFontDefaults ? mImpl->mFontSizeScale : 1.0f;
803 void Controller::SetDefaultFontSize(float fontSize, FontSizeType type)
805 EnsureCreated(mImpl->mFontDefaults);
807 mImpl->mFontDefaults->mDefaultPointSize = (type == POINT_SIZE) ? fontSize : ConvertPixelToPoint(fontSize);
808 mImpl->mFontDefaults->sizeDefined = true;
810 // Update the cursor position if it's in editing mode
811 UpdateCursorPosition(mImpl->mEventData);
813 // Clear the font-specific data
816 mImpl->RequestRelayout();
819 float Controller::GetDefaultFontSize(FontSizeType type) const
821 if(mImpl->mFontDefaults)
823 return (type == POINT_SIZE) ? mImpl->mFontDefaults->mDefaultPointSize : ConvertPointToPixel(mImpl->mFontDefaults->mDefaultPointSize);
828 void Controller::SetPlaceholderTextFontSize(float fontSize, FontSizeType type)
830 PlaceholderHandler::SetPlaceholderTextFontSize(*this, fontSize, type);
833 float Controller::GetPlaceholderTextFontSize(FontSizeType type) const
835 return PlaceholderHandler::GetPlaceholderTextFontSize(*this, type);
838 void Controller::SetDefaultColor(const Vector4& color)
840 mImpl->mTextColor = color;
842 if(!mImpl->IsShowingPlaceholderText())
844 mImpl->mModel->mVisualModel->SetTextColor(color);
845 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
846 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | COLOR);
847 mImpl->RequestRelayout();
851 const Vector4& Controller::GetDefaultColor() const
853 return mImpl->mTextColor;
856 void Controller::SetPlaceholderTextColor(const Vector4& textColor)
858 PlaceholderHandler::SetPlaceholderTextColor(*this, textColor);
861 const Vector4& Controller::GetPlaceholderTextColor() const
863 return PlaceholderHandler::GetPlaceholderTextColor(*this);
866 void Controller::SetShadowOffset(const Vector2& shadowOffset)
868 mImpl->mModel->mVisualModel->SetShadowOffset(shadowOffset);
869 mImpl->RequestRelayout();
872 const Vector2& Controller::GetShadowOffset() const
874 return mImpl->mModel->mVisualModel->GetShadowOffset();
877 void Controller::SetShadowColor(const Vector4& shadowColor)
879 mImpl->mModel->mVisualModel->SetShadowColor(shadowColor);
880 mImpl->RequestRelayout();
883 const Vector4& Controller::GetShadowColor() const
885 return mImpl->mModel->mVisualModel->GetShadowColor();
888 void Controller::SetShadowBlurRadius(const float& shadowBlurRadius)
890 if(fabsf(GetShadowBlurRadius() - shadowBlurRadius) > Math::MACHINE_EPSILON_1)
892 mImpl->mModel->mVisualModel->SetShadowBlurRadius(shadowBlurRadius);
893 mImpl->RequestRelayout();
897 const float& Controller::GetShadowBlurRadius() const
899 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
902 void Controller::SetUnderlineColor(const Vector4& color)
904 mImpl->mModel->mVisualModel->SetUnderlineColor(color);
905 mImpl->RequestRelayout();
908 const Vector4& Controller::GetUnderlineColor() const
910 return mImpl->mModel->mVisualModel->GetUnderlineColor();
913 void Controller::SetUnderlineEnabled(bool enabled)
915 mImpl->mModel->mVisualModel->SetUnderlineEnabled(enabled);
916 mImpl->RequestRelayout();
919 bool Controller::IsUnderlineEnabled() const
921 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
924 void Controller::SetUnderlineHeight(float height)
926 mImpl->mModel->mVisualModel->SetUnderlineHeight(height);
927 mImpl->RequestRelayout();
930 float Controller::GetUnderlineHeight() const
932 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
935 void Controller::SetOutlineColor(const Vector4& color)
937 mImpl->mModel->mVisualModel->SetOutlineColor(color);
938 mImpl->RequestRelayout();
941 const Vector4& Controller::GetOutlineColor() const
943 return mImpl->mModel->mVisualModel->GetOutlineColor();
946 void Controller::SetOutlineWidth(uint16_t width)
948 mImpl->mModel->mVisualModel->SetOutlineWidth(width);
949 mImpl->RequestRelayout();
952 uint16_t Controller::GetOutlineWidth() const
954 return mImpl->mModel->mVisualModel->GetOutlineWidth();
957 void Controller::SetBackgroundColor(const Vector4& color)
959 mImpl->mModel->mVisualModel->SetBackgroundColor(color);
960 mImpl->RequestRelayout();
963 const Vector4& Controller::GetBackgroundColor() const
965 return mImpl->mModel->mVisualModel->GetBackgroundColor();
968 void Controller::SetBackgroundEnabled(bool enabled)
970 mImpl->mModel->mVisualModel->SetBackgroundEnabled(enabled);
971 mImpl->RequestRelayout();
974 bool Controller::IsBackgroundEnabled() const
976 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
979 void Controller::SetDefaultEmbossProperties(const std::string& embossProperties)
981 EnsureCreated(mImpl->mEmbossDefaults);
982 mImpl->mEmbossDefaults->properties = embossProperties;
985 const std::string& Controller::GetDefaultEmbossProperties() const
987 return mImpl->mEmbossDefaults ? mImpl->mEmbossDefaults->properties : EMPTY_STRING;
990 void Controller::SetDefaultOutlineProperties(const std::string& outlineProperties)
992 EnsureCreated(mImpl->mOutlineDefaults);
993 mImpl->mOutlineDefaults->properties = outlineProperties;
996 const std::string& Controller::GetDefaultOutlineProperties() const
998 return mImpl->mOutlineDefaults ? mImpl->mOutlineDefaults->properties : EMPTY_STRING;
1001 void Controller::RelayoutForNewLineSize()
1003 // relayout all characters
1004 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1005 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1006 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1007 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | LAYOUT);
1010 if(mImpl->mEventData && mImpl->mEventData->mState == EventData::SELECTING)
1012 mImpl->ChangeState(EventData::EDITING);
1015 mImpl->RequestRelayout();
1018 bool Controller::SetDefaultLineSpacing(float lineSpacing)
1020 if(std::fabs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000)
1022 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1023 mImpl->mRecalculateNaturalSize = true;
1025 RelayoutForNewLineSize();
1031 float Controller::GetDefaultLineSpacing() const
1033 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1036 bool Controller::SetDefaultLineSize(float lineSize)
1038 if(std::fabs(lineSize - mImpl->mLayoutEngine.GetDefaultLineSize()) > Math::MACHINE_EPSILON_1000)
1040 mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
1041 mImpl->mRecalculateNaturalSize = true;
1043 RelayoutForNewLineSize();
1049 float Controller::GetDefaultLineSize() const
1051 return mImpl->mLayoutEngine.GetDefaultLineSize();
1054 void Controller::SetInputColor(const Vector4& color)
1056 if(mImpl->mEventData)
1058 mImpl->mEventData->mInputStyle.textColor = color;
1059 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1061 if(EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState)
1063 if(EventData::SELECTING == mImpl->mEventData->mState)
1065 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1067 // Get start and end position of selection
1068 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1069 const Length lengthOfSelectedText = (handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition) - startOfSelectedText;
1071 // Add the color run.
1072 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1073 mImpl->mModel->mLogicalModel->mColorRuns.Resize(numberOfRuns + 1u);
1075 ColorRun& colorRun = *(mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns);
1076 colorRun.color = color;
1077 colorRun.characterRun.characterIndex = startOfSelectedText;
1078 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1080 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1081 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1082 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1086 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1087 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1088 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1091 // Request to relayout.
1092 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | COLOR);
1093 mImpl->RequestRelayout();
1098 const Vector4& Controller::GetInputColor() const
1100 // Return event text input color if we have it, otherwise just return the default text's color
1101 return mImpl->mEventData ? mImpl->mEventData->mInputStyle.textColor : mImpl->mTextColor;
1104 void Controller::SetInputFontFamily(const std::string& fontFamily)
1106 InputFontHandler::SetInputFontFamily(*this, fontFamily);
1109 const std::string& Controller::GetInputFontFamily() const
1111 return InputFontHandler::GetInputFontFamily(*this);
1114 void Controller::SetInputFontWeight(FontWeight weight)
1116 InputFontHandler::SetInputFontWeight(*this, weight);
1119 bool Controller::IsInputFontWeightDefined() const
1121 return InputFontHandler::IsInputFontWeightDefined(*this);
1124 FontWeight Controller::GetInputFontWeight() const
1126 return InputFontHandler::GetInputFontWeight(*this);
1129 void Controller::SetInputFontWidth(FontWidth width)
1131 InputFontHandler::SetInputFontWidth(*this, width);
1134 bool Controller::IsInputFontWidthDefined() const
1136 return InputFontHandler::IsInputFontWidthDefined(*this);
1139 FontWidth Controller::GetInputFontWidth() const
1141 return InputFontHandler::GetInputFontWidth(*this);
1144 void Controller::SetInputFontSlant(FontSlant slant)
1146 InputFontHandler::SetInputFontSlant(*this, slant);
1149 bool Controller::IsInputFontSlantDefined() const
1151 return InputFontHandler::IsInputFontSlantDefined(*this);
1154 FontSlant Controller::GetInputFontSlant() const
1156 return InputFontHandler::GetInputFontSlant(*this);
1159 void Controller::SetInputFontPointSize(float size)
1161 InputFontHandler::SetInputFontPointSize(*this, size);
1164 float Controller::GetInputFontPointSize() const
1166 return InputFontHandler::GetInputFontPointSize(*this);
1169 void Controller::SetInputLineSpacing(float lineSpacing)
1171 if(mImpl->mEventData)
1173 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1174 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1178 float Controller::GetInputLineSpacing() const
1180 return mImpl->mEventData ? mImpl->mEventData->mInputStyle.lineSpacing : 0.0f;
1183 void Controller::SetInputShadowProperties(const std::string& shadowProperties)
1185 if(mImpl->mEventData)
1187 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1191 const std::string& Controller::GetInputShadowProperties() const
1193 return mImpl->mEventData ? mImpl->mEventData->mInputStyle.shadowProperties : EMPTY_STRING;
1196 void Controller::SetInputUnderlineProperties(const std::string& underlineProperties)
1198 if(mImpl->mEventData)
1200 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1204 const std::string& Controller::GetInputUnderlineProperties() const
1206 return mImpl->mEventData ? mImpl->mEventData->mInputStyle.underlineProperties : EMPTY_STRING;
1209 void Controller::SetInputEmbossProperties(const std::string& embossProperties)
1211 if(mImpl->mEventData)
1213 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1217 const std::string& Controller::GetInputEmbossProperties() const
1219 return mImpl->mEventData ? mImpl->mEventData->mInputStyle.embossProperties : GetDefaultEmbossProperties();
1222 void Controller::SetInputOutlineProperties(const std::string& outlineProperties)
1224 if(mImpl->mEventData)
1226 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1230 const std::string& Controller::GetInputOutlineProperties() const
1232 return mImpl->mEventData ? mImpl->mEventData->mInputStyle.outlineProperties : GetDefaultOutlineProperties();
1235 void Controller::SetInputModePassword(bool passwordInput)
1237 if(mImpl->mEventData)
1239 mImpl->mEventData->mPasswordInput = passwordInput;
1243 bool Controller::IsInputModePassword()
1245 return mImpl->mEventData && mImpl->mEventData->mPasswordInput;
1248 void Controller::SetNoTextDoubleTapAction(NoTextTap::Action action)
1250 if(mImpl->mEventData)
1252 mImpl->mEventData->mDoubleTapAction = action;
1256 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1258 return mImpl->mEventData ? mImpl->mEventData->mDoubleTapAction : NoTextTap::NO_ACTION;
1261 void Controller::SetNoTextLongPressAction(NoTextTap::Action action)
1263 if(mImpl->mEventData)
1265 mImpl->mEventData->mLongPressAction = action;
1269 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1271 return mImpl->mEventData ? mImpl->mEventData->mLongPressAction : NoTextTap::NO_ACTION;
1274 bool Controller::IsUnderlineSetByString()
1276 return mImpl->mUnderlineSetByString;
1279 void Controller::UnderlineSetByString(bool setByString)
1281 mImpl->mUnderlineSetByString = setByString;
1284 bool Controller::IsShadowSetByString()
1286 return mImpl->mShadowSetByString;
1289 void Controller::ShadowSetByString(bool setByString)
1291 mImpl->mShadowSetByString = setByString;
1294 bool Controller::IsOutlineSetByString()
1296 return mImpl->mOutlineSetByString;
1299 void Controller::OutlineSetByString(bool setByString)
1301 mImpl->mOutlineSetByString = setByString;
1304 bool Controller::IsFontStyleSetByString()
1306 return mImpl->mFontStyleSetByString;
1309 void Controller::FontStyleSetByString(bool setByString)
1311 mImpl->mFontStyleSetByString = setByString;
1314 Layout::Engine& Controller::GetLayoutEngine()
1316 return mImpl->mLayoutEngine;
1319 View& Controller::GetView()
1321 return mImpl->mView;
1324 Vector3 Controller::GetNaturalSize()
1326 return Relayouter::GetNaturalSize(*this);
1329 bool Controller::CheckForTextFit(float pointSize, Size& layoutSize)
1331 return Relayouter::CheckForTextFit(*this, pointSize, layoutSize);
1334 void Controller::FitPointSizeforLayout(Size layoutSize)
1336 Relayouter::FitPointSizeforLayout(*this, layoutSize);
1339 float Controller::GetHeightForWidth(float width)
1341 return Relayouter::GetHeightForWidth(*this, width);
1344 int Controller::GetLineCount(float width)
1346 GetHeightForWidth(width);
1347 return mImpl->mModel->GetNumberOfLines();
1350 const ModelInterface* const Controller::GetTextModel() const
1352 return mImpl->mModel.Get();
1355 float Controller::GetScrollAmountByUserInput()
1357 float scrollAmount = 0.0f;
1359 if(NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1361 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1362 mImpl->mEventData->mCheckScrollAmount = false;
1364 return scrollAmount;
1367 bool Controller::GetTextScrollInfo(float& scrollPosition, float& controlHeight, float& layoutHeight)
1369 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1372 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1373 layoutHeight = layout.height;
1374 scrollPosition = mImpl->mModel->mScrollPosition.y;
1375 isScrolled = !Equals(mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1);
1379 void Controller::SetHiddenInputOption(const Property::Map& options)
1381 EnsureCreated<HiddenText, Controller*>(mImpl->mHiddenInput, this);
1382 mImpl->mHiddenInput->SetProperties(options);
1385 void Controller::GetHiddenInputOption(Property::Map& options)
1387 if(mImpl->mHiddenInput)
1389 mImpl->mHiddenInput->GetProperties(options);
1393 void Controller::SetInputFilterOption(const Property::Map& options)
1395 EnsureCreated(mImpl->mInputFilter);
1396 mImpl->mInputFilter->SetProperties(options);
1399 void Controller::GetInputFilterOption(Property::Map& options)
1401 if(mImpl->mInputFilter)
1403 mImpl->mInputFilter->GetProperties(options);
1407 void Controller::SetPlaceholderProperty(const Property::Map& map)
1409 PlaceholderHandler::SetPlaceholderProperty(*this, map);
1412 void Controller::GetPlaceholderProperty(Property::Map& map)
1414 PlaceholderHandler::GetPlaceholderProperty(*this, map);
1417 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
1419 // Make sure the model is up-to-date before layouting
1420 ProcessModifyEvents();
1422 if(mImpl->mUpdateTextDirection)
1424 // Operations that can be done only once until the text changes.
1425 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>(CONVERT_TO_UTF32 |
1433 // Set the update info to relayout the whole text.
1434 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1435 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1437 // Make sure the model is up-to-date before layouting
1438 mImpl->UpdateModel(onlyOnceOperations);
1440 Vector3 naturalSize;
1441 DoRelayout(Size(MAX_FLOAT, MAX_FLOAT),
1442 static_cast<OperationsMask>(onlyOnceOperations |
1443 LAYOUT | REORDER | UPDATE_DIRECTION),
1444 naturalSize.GetVectorXY());
1446 // Do not do again the only once operations.
1447 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending & ~onlyOnceOperations);
1449 // Clear the update info. This info will be set the next time the text is updated.
1450 mImpl->mTextUpdateInfo.Clear();
1452 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
1453 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1455 mImpl->mUpdateTextDirection = false;
1458 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
1461 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
1463 return mImpl->mModel->GetVerticalLineAlignment();
1466 void Controller::SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment)
1468 mImpl->mModel->mVerticalLineAlignment = alignment;
1471 Toolkit::DevelText::EllipsisPosition::Type Controller::GetEllipsisPosition() const
1473 return mImpl->mModel->GetEllipsisPosition();
1476 void Controller::SetEllipsisPosition(Toolkit::DevelText::EllipsisPosition::Type ellipsisPosition)
1478 mImpl->mModel->mEllipsisPosition = ellipsisPosition;
1479 mImpl->mModel->mVisualModel->SetEllipsisPosition(ellipsisPosition);
1482 Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection)
1484 return Relayouter::Relayout(*this, size, layoutDirection);
1487 void Controller::RequestRelayout()
1489 mImpl->RequestRelayout();
1492 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1494 return (NULL == mImpl->mEventData) || (0u == mImpl->mEventData->mInputStyleChangedQueue.Count());
1497 void Controller::ProcessInputStyleChangedSignals()
1499 if(mImpl->mEventData)
1501 if(mImpl->mEditableControlInterface)
1503 // Emit the input style changed signal for each mask
1504 std::for_each(mImpl->mEventData->mInputStyleChangedQueue.begin(),
1505 mImpl->mEventData->mInputStyleChangedQueue.end(),
1506 [&](const auto mask) { mImpl->mEditableControlInterface->InputStyleChanged(mask); } );
1509 mImpl->mEventData->mInputStyleChangedQueue.Clear();
1513 void Controller::KeyboardFocusGainEvent()
1515 EventHandler::KeyboardFocusGainEvent(*this);
1518 void Controller::KeyboardFocusLostEvent()
1520 EventHandler::KeyboardFocusLostEvent(*this);
1523 bool Controller::KeyEvent(const Dali::KeyEvent& keyEvent)
1525 return EventHandler::KeyEvent(*this, keyEvent);
1528 void Controller::AnchorEvent(float x, float y)
1530 EventHandler::AnchorEvent(*this, x, y);
1533 void Controller::TapEvent(unsigned int tapCount, float x, float y)
1535 EventHandler::TapEvent(*this, tapCount, x, y);
1538 void Controller::PanEvent(GestureState state, const Vector2& displacement)
1540 EventHandler::PanEvent(*this, state, displacement);
1543 void Controller::LongPressEvent(GestureState state, float x, float y)
1545 EventHandler::LongPressEvent(*this, state, x, y);
1548 void Controller::SelectEvent(float x, float y, SelectionType selectType)
1550 EventHandler::SelectEvent(*this, x, y, selectType);
1553 void Controller::SelectEvent(const uint32_t start, const uint32_t end, SelectionType selectType)
1555 EventHandler::SelectEvent(*this, start, end, selectType);
1558 void Controller::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1560 if(mImpl->mEventData)
1562 mImpl->mEventData->mCheckScrollAmount = true;
1563 mImpl->mEventData->mIsLeftHandleSelected = true;
1564 mImpl->mEventData->mIsRightHandleSelected = true;
1565 mImpl->SetTextSelectionRange(start, end);
1566 mImpl->RequestRelayout();
1567 KeyboardFocusGainEvent();
1571 Uint32Pair Controller::GetTextSelectionRange() const
1573 return mImpl->GetTextSelectionRange();
1576 CharacterIndex Controller::GetPrimaryCursorPosition() const
1578 return mImpl->GetPrimaryCursorPosition();
1581 bool Controller::SetPrimaryCursorPosition(CharacterIndex index, bool focused)
1583 if(mImpl->mEventData)
1585 mImpl->mEventData->mCheckScrollAmount = true;
1586 mImpl->mEventData->mIsLeftHandleSelected = true;
1587 mImpl->mEventData->mIsRightHandleSelected = true;
1588 mImpl->mEventData->mCheckScrollAmount = true;
1589 if(mImpl->SetPrimaryCursorPosition(index, focused) && focused)
1591 KeyboardFocusGainEvent();
1598 void Controller::SelectWholeText()
1600 SelectEvent(0.f, 0.f, SelectionType::ALL);
1603 void Controller::SelectNone()
1605 SelectEvent(0.f, 0.f, SelectionType::NONE);
1608 void Controller::SelectText(const uint32_t start, const uint32_t end)
1610 SelectEvent(start, end, SelectionType::RANGE);
1613 string Controller::GetSelectedText() const
1616 if(EventData::SELECTING == mImpl->mEventData->mState)
1618 mImpl->RetrieveSelection(text, false);
1623 string Controller::CopyText()
1626 mImpl->RetrieveSelection(text, false);
1627 mImpl->SendSelectionToClipboard(false); // Text not modified
1629 mImpl->mEventData->mUpdateCursorPosition = true;
1631 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
1636 string Controller::CutText()
1639 mImpl->RetrieveSelection(text, false);
1643 return EMPTY_STRING;
1646 mImpl->SendSelectionToClipboard(true); // Synchronous call to modify text
1647 mImpl->mOperationsPending = ALL_OPERATIONS;
1649 if((0u != mImpl->mModel->mLogicalModel->mText.Count()) ||
1650 !mImpl->IsPlaceholderAvailable())
1652 mImpl->QueueModifyEvent(ModifyEvent::TEXT_DELETED);
1656 ShowPlaceholderText();
1659 mImpl->mEventData->mUpdateCursorPosition = true;
1660 mImpl->mEventData->mScrollAfterDelete = true;
1662 mImpl->RequestRelayout();
1664 if(nullptr != mImpl->mEditableControlInterface)
1666 mImpl->mEditableControlInterface->TextChanged(true);
1671 void Controller::PasteText()
1673 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
1676 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1678 return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent);
1681 void Controller::PasteClipboardItemEvent()
1683 EventHandler::PasteClipboardItemEvent(*this);
1686 void Controller::GetTargetSize(Vector2& targetSize)
1688 targetSize = mImpl->mModel->mVisualModel->mControlSize;
1691 void Controller::AddDecoration(Actor& actor, bool needsClipping)
1693 if(mImpl->mEditableControlInterface)
1695 mImpl->mEditableControlInterface->AddDecoration(actor, needsClipping);
1699 bool Controller::IsEditable() const
1701 return mImpl->IsEditable();
1704 void Controller::SetEditable(bool editable)
1706 mImpl->SetEditable(editable);
1707 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
1709 mImpl->mEventData->mDecorator->SetEditable(editable);
1713 void Controller::ScrollBy(Vector2 scroll)
1715 if(mImpl->mEventData && (fabs(scroll.x) > Math::MACHINE_EPSILON_0 || fabs(scroll.y) > Math::MACHINE_EPSILON_0))
1717 const Vector2& layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1718 const Vector2 currentScroll = mImpl->mModel->mScrollPosition;
1720 scroll.x = -scroll.x;
1721 scroll.y = -scroll.y;
1723 if(fabs(scroll.x) > Math::MACHINE_EPSILON_0)
1725 mImpl->mModel->mScrollPosition.x += scroll.x;
1726 mImpl->ClampHorizontalScroll(layoutSize);
1729 if(fabs(scroll.y) > Math::MACHINE_EPSILON_0)
1731 mImpl->mModel->mScrollPosition.y += scroll.y;
1732 mImpl->ClampVerticalScroll(layoutSize);
1735 if(mImpl->mModel->mScrollPosition != currentScroll)
1737 mImpl->mEventData->mDecorator->UpdatePositions(mImpl->mModel->mScrollPosition - currentScroll);
1738 mImpl->RequestRelayout();
1743 float Controller::GetHorizontalScrollPosition()
1745 // Scroll values are negative internally so we convert them to positive numbers
1746 return mImpl->mEventData ? -mImpl->mModel->mScrollPosition.x : 0.0f;
1749 float Controller::GetVerticalScrollPosition()
1751 // Scroll values are negative internally so we convert them to positive numbers
1752 return mImpl->mEventData ? -mImpl->mModel->mScrollPosition.y : 0.0f;
1755 void Controller::DecorationEvent(HandleType handleType, HandleState state, float x, float y)
1757 EventHandler::DecorationEvent(*this, handleType, state, x, y);
1760 void Controller::TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button)
1762 EventHandler::TextPopupButtonTouched(*this, button);
1765 void Controller::DisplayTimeExpired()
1767 mImpl->mEventData->mUpdateCursorPosition = true;
1768 // Apply modifications to the model
1769 mImpl->mOperationsPending = ALL_OPERATIONS;
1771 mImpl->RequestRelayout();
1774 void Controller::InsertText(const std::string& text, Controller::InsertType type)
1776 TextUpdater::InsertText(*this, text, type);
1779 void Controller::PasteText(const std::string& stringToPaste)
1781 TextUpdater::PasteText(*this, stringToPaste);
1784 bool Controller::RemoveText(int cursorOffset, int numberOfCharacters, UpdateInputStyleType type)
1786 return TextUpdater::RemoveText(*this, cursorOffset, numberOfCharacters, type);
1789 bool Controller::RemoveSelectedText()
1791 return TextUpdater::RemoveSelectedText(*this);
1794 void Controller::InsertTextAnchor(int numberOfCharacters, CharacterIndex previousCursorIndex)
1796 TextUpdater::InsertTextAnchor(*this, numberOfCharacters, previousCursorIndex);
1799 void Controller::RemoveTextAnchor(int cursorOffset, int numberOfCharacters, CharacterIndex previousCursorIndex)
1801 TextUpdater::RemoveTextAnchor(*this, cursorOffset, numberOfCharacters, previousCursorIndex);
1804 bool Controller::DoRelayout(const Size& size, OperationsMask operationsRequired, Size& layoutSize)
1806 return Relayouter::DoRelayout(*this, size, operationsRequired, layoutSize);
1809 void Controller::CalculateVerticalOffset(const Size& controlSize)
1811 Relayouter::CalculateVerticalOffset(*this, controlSize);
1814 void Controller::ProcessModifyEvents()
1816 EventHandler::ProcessModifyEvents(*this);
1819 void Controller::TextReplacedEvent()
1821 EventHandler::TextReplacedEvent(*this);
1824 void Controller::TextInsertedEvent()
1826 EventHandler::TextInsertedEvent(*this);
1829 void Controller::TextDeletedEvent()
1831 EventHandler::TextDeletedEvent(*this);
1834 bool Controller::DeleteEvent(int keyCode)
1836 return EventHandler::DeleteEvent(*this, keyCode);
1839 // private : Helpers.
1841 void Controller::ResetText()
1843 TextUpdater::ResetText(*this);
1846 void Controller::ShowPlaceholderText()
1848 PlaceholderHandler::ShowPlaceholderText(*this);
1851 void Controller::ClearFontData()
1853 if(mImpl->mFontDefaults)
1855 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
1858 // Set flags to update the model.
1859 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
1860 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1861 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1863 mImpl->mTextUpdateInfo.mClearAll = true;
1864 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1865 mImpl->mRecalculateNaturalSize = true;
1867 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
1873 UPDATE_LAYOUT_SIZE |
1878 void Controller::ClearStyleData()
1880 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1881 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
1884 void Controller::ResetCursorPosition(CharacterIndex cursorIndex)
1886 // Reset the cursor position
1887 if(NULL != mImpl->mEventData)
1889 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
1891 // Update the cursor if it's in editing mode.
1892 if(EventData::IsEditingState(mImpl->mEventData->mState))
1894 mImpl->mEventData->mUpdateCursorPosition = true;
1899 CharacterIndex Controller::GetCursorPosition()
1901 if(!mImpl->mEventData)
1904 return mImpl->mEventData->mPrimaryCursorPosition;
1907 void Controller::ResetScrollPosition()
1909 if(mImpl->mEventData)
1911 // Reset the scroll position.
1912 mImpl->mModel->mScrollPosition = Vector2::ZERO;
1913 mImpl->mEventData->mScrollAfterUpdatePosition = true;
1917 void Controller::SetControlInterface(ControlInterface* controlInterface)
1919 mImpl->mControlInterface = controlInterface;
1922 void Controller::SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface)
1924 mImpl->mAnchorControlInterface = anchorControlInterface;
1927 bool Controller::ShouldClearFocusOnEscape() const
1929 return mImpl->mShouldClearFocusOnEscape;
1932 Actor Controller::CreateBackgroundActor()
1934 return mImpl->CreateBackgroundActor();
1937 Controller::Controller(ControlInterface* controlInterface,
1938 EditableControlInterface* editableControlInterface,
1939 SelectableControlInterface* selectableControlInterface,
1940 AnchorControlInterface* anchorControlInterface)
1941 : mImpl(new Controller::Impl(controlInterface, editableControlInterface, selectableControlInterface, anchorControlInterface))
1945 Controller::~Controller()
1950 } // namespace Dali::Toolkit::Text