2 * Copyright (c) 2022 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-background-actor.h>
32 #include <dali-toolkit/internal/text/text-controller-event-handler.h>
33 #include <dali-toolkit/internal/text/text-controller-impl.h>
34 #include <dali-toolkit/internal/text/text-controller-input-font-handler.h>
35 #include <dali-toolkit/internal/text/text-controller-input-properties.h>
36 #include <dali-toolkit/internal/text/text-controller-placeholder-handler.h>
37 #include <dali-toolkit/internal/text/text-controller-relayouter.h>
38 #include <dali-toolkit/internal/text/text-controller-text-updater.h>
39 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
40 #include <dali-toolkit/internal/text/text-geometry.h>
44 #if defined(DEBUG_ENABLED)
45 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
48 const std::string EMPTY_STRING("");
50 template<typename Type>
51 void EnsureCreated(Type*& object)
59 template<typename Type>
60 void EnsureCreated(std::unique_ptr<Type>& object)
64 object = std::unique_ptr<Type>(new Type());
68 template<typename Type, typename Arg1>
69 void EnsureCreated(Type*& object, Arg1 arg1)
73 object = new Type(arg1);
77 template<typename Type, typename Arg1, typename Arg2>
78 void EnsureCreated(Type*& object, Arg1 arg1, Arg2 arg2)
82 object = new Type(arg1, arg2);
88 unsigned int horizontalDpi = 0u;
89 unsigned int verticalDpi = 0u;
90 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
91 fontClient.GetDpi(horizontalDpi, verticalDpi);
92 return static_cast<float>(horizontalDpi);
95 float ConvertPixelToPoint(float pixel)
97 return pixel * 72.0f / GetDpi();
100 float ConvertPointToPixel(float point)
102 // Pixel size = Point size * DPI / 72.f
103 return point * GetDpi() / 72.0f;
106 void UpdateCursorPosition(Dali::Toolkit::Text::EventData* eventData)
108 if(eventData && Dali::Toolkit::Text::EventData::IsEditingState(eventData->mState))
110 // Update the cursor position if it's in editing mode
111 eventData->mDecoratorUpdated = true;
112 eventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
118 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
140 mImpl->ClearFontData();
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);
172 mImpl->SetAutoScrollEnabled(enable);
175 void Controller::SetAutoScrollMaxTextureExceeded(bool exceed)
177 mImpl->mIsAutoScrollMaxTextureExceeded = exceed;
180 bool Controller::IsAutoScrollEnabled() const
182 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled ? "true" : "false");
183 return mImpl->mIsAutoScrollEnabled;
186 CharacterDirection Controller::GetAutoScrollDirection() const
188 return mImpl->mIsTextDirectionRTL;
191 float Controller::GetAutoScrollLineAlignment() const
194 if(mImpl->mModel->mVisualModel && (0u != mImpl->mModel->mVisualModel->mLines.Count()))
196 offset = (*mImpl->mModel->mVisualModel->mLines.Begin()).alignmentOffset;
201 void Controller::SetHorizontalScrollEnabled(bool enable)
203 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
205 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled(enable);
209 bool Controller::IsHorizontalScrollEnabled() const
211 return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
214 void Controller::SetVerticalScrollEnabled(bool enable)
216 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
218 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled(enable);
222 bool Controller::IsVerticalScrollEnabled() const
224 return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
227 void Controller::SetSmoothHandlePanEnabled(bool enable)
229 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
231 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled(enable);
235 bool Controller::IsSmoothHandlePanEnabled() const
237 return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
240 void Controller::SetMaximumNumberOfCharacters(Length maxCharacters)
242 mImpl->mMaximumNumberOfCharacters = maxCharacters;
245 int Controller::GetMaximumNumberOfCharacters()
247 return mImpl->mMaximumNumberOfCharacters;
250 void Controller::SetEnableCursorBlink(bool enable)
252 mImpl->SetEnableCursorBlink(enable);
255 bool Controller::GetEnableCursorBlink() const
257 return mImpl->mEventData && mImpl->mEventData->mCursorBlinkEnabled;
260 void Controller::SetMultiLineEnabled(bool enable)
262 mImpl->SetMultiLineEnabled(enable);
265 bool Controller::IsMultiLineEnabled() const
267 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
270 void Controller::SetHorizontalAlignment(Text::HorizontalAlignment::Type alignment)
272 mImpl->SetHorizontalAlignment(alignment);
275 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
277 return mImpl->mModel->mHorizontalAlignment;
280 void Controller::SetVerticalAlignment(VerticalAlignment::Type alignment)
282 mImpl->SetVerticalAlignment(alignment);
285 VerticalAlignment::Type Controller::GetVerticalAlignment() const
287 return mImpl->mModel->mVerticalAlignment;
290 bool Controller::IsIgnoreSpacesAfterText() const
292 return mImpl->mModel->mIgnoreSpacesAfterText;
295 void Controller::SetIgnoreSpacesAfterText(bool ignore)
297 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
300 void Controller::ChangedLayoutDirection()
302 mImpl->mIsLayoutDirectionChanged = true;
305 void Controller::SetMatchLayoutDirection(DevelText::MatchLayoutDirection type)
307 mImpl->mModel->mMatchLayoutDirection = type;
310 DevelText::MatchLayoutDirection Controller::GetMatchLayoutDirection() const
312 return mImpl->mModel->mMatchLayoutDirection;
315 void Controller::SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection)
317 mImpl->mLayoutDirection = layoutDirection;
320 Dali::LayoutDirection::Type Controller::GetLayoutDirection(Dali::Actor& actor) const
322 return mImpl->GetLayoutDirection(actor);
325 bool Controller::IsShowingRealText() const
327 return mImpl->IsShowingRealText();
330 void Controller::SetLineWrapMode(Text::LineWrap::Mode lineWrapMode)
332 mImpl->SetLineWrapMode(lineWrapMode);
335 Text::LineWrap::Mode Controller::GetLineWrapMode() const
337 return mImpl->mModel->mLineWrapMode;
340 void Controller::SetTextElideEnabled(bool enabled)
342 mImpl->mModel->mElideEnabled = enabled;
343 mImpl->mModel->mVisualModel->SetTextElideEnabled(enabled);
346 bool Controller::IsTextElideEnabled() const
348 return mImpl->mModel->mElideEnabled;
351 void Controller::SetTextFitEnabled(bool enabled)
353 mImpl->mTextFitEnabled = enabled;
356 bool Controller::IsTextFitEnabled() const
358 return mImpl->mTextFitEnabled;
361 void Controller::SetTextFitChanged(bool changed)
363 mImpl->mTextFitChanged = changed;
366 bool Controller::IsTextFitChanged() const
368 return mImpl->mTextFitChanged;
371 void Controller::SetTextFitMinSize(float minSize, FontSizeType type)
373 mImpl->mTextFitMinSize = (type == POINT_SIZE) ? minSize : ConvertPixelToPoint(minSize);
376 float Controller::GetTextFitMinSize() const
378 return mImpl->mTextFitMinSize;
381 void Controller::SetTextFitMaxSize(float maxSize, FontSizeType type)
383 mImpl->mTextFitMaxSize = (type == POINT_SIZE) ? maxSize : ConvertPixelToPoint(maxSize);
386 float Controller::GetTextFitMaxSize() const
388 return mImpl->mTextFitMaxSize;
391 void Controller::SetTextFitStepSize(float step, FontSizeType type)
393 mImpl->mTextFitStepSize = (type == POINT_SIZE) ? step : ConvertPixelToPoint(step);
396 float Controller::GetTextFitStepSize() const
398 return mImpl->mTextFitStepSize;
401 void Controller::SetTextFitContentSize(Vector2 size)
403 mImpl->mTextFitContentSize = size;
406 Vector2 Controller::GetTextFitContentSize() const
408 return mImpl->mTextFitContentSize;
411 float Controller::GetTextFitPointSize() const
413 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFitPointSize : 0.0f;
416 void Controller::SetPlaceholderTextElideEnabled(bool enabled)
418 PlaceholderHandler::SetPlaceholderTextElideEnabled(*this, enabled);
421 bool Controller::IsPlaceholderTextElideEnabled() const
423 return PlaceholderHandler::IsPlaceholderTextElideEnabled(*this);
426 void Controller::SetSelectionEnabled(bool enabled)
428 mImpl->mEventData->mSelectionEnabled = enabled;
431 bool Controller::IsSelectionEnabled() const
433 return mImpl->mEventData->mSelectionEnabled;
436 void Controller::SetShiftSelectionEnabled(bool enabled)
438 mImpl->mEventData->mShiftSelectionFlag = enabled;
441 bool Controller::IsShiftSelectionEnabled() const
443 return mImpl->mEventData->mShiftSelectionFlag;
446 void Controller::SetGrabHandleEnabled(bool enabled)
448 mImpl->mEventData->mGrabHandleEnabled = enabled;
451 bool Controller::IsGrabHandleEnabled() const
453 return mImpl->mEventData->mGrabHandleEnabled;
456 void Controller::SetGrabHandlePopupEnabled(bool enabled)
458 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
461 bool Controller::IsGrabHandlePopupEnabled() const
463 return mImpl->mEventData->mGrabHandlePopupEnabled;
466 void Controller::SetText(const std::string& text)
468 TextUpdater::SetText(*this, text);
471 void Controller::GetText(std::string& text) const
473 mImpl->GetText(text);
476 void Controller::SetPlaceholderText(PlaceholderType type, const std::string& text)
478 PlaceholderHandler::SetPlaceholderText(*this, type, text);
481 void Controller::GetPlaceholderText(PlaceholderType type, std::string& text) const
483 PlaceholderHandler::GetPlaceholderText(*this, type, text);
486 void Controller::UpdateAfterFontChange(const std::string& newDefaultFont)
488 mImpl->UpdateAfterFontChange(newDefaultFont);
491 void Controller::RetrieveSelection(std::string& selectedText) const
493 mImpl->RetrieveSelection(selectedText, false);
496 void Controller::SetSelection(int start, int end)
498 mImpl->SetSelection(start, end);
501 std::pair<int, int> Controller::GetSelectionIndexes() const
503 return mImpl->GetSelectionIndexes();
506 void Controller::CopyStringToClipboard(const std::string& source)
508 mImpl->CopyStringToClipboard(source);
511 void Controller::SendSelectionToClipboard(bool deleteAfterSending)
513 mImpl->SendSelectionToClipboard(deleteAfterSending);
516 void Controller::SetDefaultFontFamily(const std::string& defaultFontFamily)
518 EnsureCreated(mImpl->mFontDefaults);
520 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
521 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
522 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
524 // Update the cursor position if it's in editing mode
525 UpdateCursorPosition(mImpl->mEventData);
527 // Clear the font-specific data
528 mImpl->ClearFontData();
530 mImpl->RequestRelayout();
533 const std::string& Controller::GetDefaultFontFamily() const
535 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.family : EMPTY_STRING;
538 void Controller::SetPlaceholderFontFamily(const std::string& placeholderTextFontFamily)
540 PlaceholderHandler::SetPlaceholderFontFamily(*this, placeholderTextFontFamily);
543 const std::string& Controller::GetPlaceholderFontFamily() const
545 return PlaceholderHandler::GetPlaceholderFontFamily(*this);
548 void Controller::SetDefaultFontWeight(FontWeight weight)
550 EnsureCreated(mImpl->mFontDefaults);
552 mImpl->mFontDefaults->mFontDescription.weight = weight;
553 mImpl->mFontDefaults->weightDefined = true;
555 // Update the cursor position if it's in editing mode
556 UpdateCursorPosition(mImpl->mEventData);
558 // Clear the font-specific data
559 mImpl->ClearFontData();
561 mImpl->RequestRelayout();
564 bool Controller::IsDefaultFontWeightDefined() const
566 return mImpl->mFontDefaults && mImpl->mFontDefaults->weightDefined;
569 FontWeight Controller::GetDefaultFontWeight() const
571 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.weight : TextAbstraction::FontWeight::NORMAL;
574 void Controller::SetPlaceholderTextFontWeight(FontWeight weight)
576 PlaceholderHandler::SetPlaceholderTextFontWeight(*this, weight);
579 bool Controller::IsPlaceholderTextFontWeightDefined() const
581 return PlaceholderHandler::IsPlaceholderTextFontWeightDefined(*this);
584 FontWeight Controller::GetPlaceholderTextFontWeight() const
586 return PlaceholderHandler::GetPlaceholderTextFontWeight(*this);
589 void Controller::SetDefaultFontWidth(FontWidth width)
591 EnsureCreated(mImpl->mFontDefaults);
593 mImpl->mFontDefaults->mFontDescription.width = width;
594 mImpl->mFontDefaults->widthDefined = true;
596 // Update the cursor position if it's in editing mode
597 UpdateCursorPosition(mImpl->mEventData);
599 // Clear the font-specific data
600 mImpl->ClearFontData();
602 mImpl->RequestRelayout();
605 bool Controller::IsDefaultFontWidthDefined() const
607 return mImpl->mFontDefaults && mImpl->mFontDefaults->widthDefined;
610 FontWidth Controller::GetDefaultFontWidth() const
612 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.width : TextAbstraction::FontWidth::NORMAL;
615 void Controller::SetPlaceholderTextFontWidth(FontWidth width)
617 PlaceholderHandler::SetPlaceholderTextFontWidth(*this, width);
620 bool Controller::IsPlaceholderTextFontWidthDefined() const
622 return PlaceholderHandler::IsPlaceholderTextFontWidthDefined(*this);
625 FontWidth Controller::GetPlaceholderTextFontWidth() const
627 return PlaceholderHandler::GetPlaceholderTextFontWidth(*this);
630 void Controller::SetDefaultFontSlant(FontSlant slant)
632 EnsureCreated(mImpl->mFontDefaults);
634 mImpl->mFontDefaults->mFontDescription.slant = slant;
635 mImpl->mFontDefaults->slantDefined = true;
637 // Update the cursor position if it's in editing mode
638 UpdateCursorPosition(mImpl->mEventData);
640 // Clear the font-specific data
641 mImpl->ClearFontData();
643 mImpl->RequestRelayout();
646 bool Controller::IsDefaultFontSlantDefined() const
648 return mImpl->mFontDefaults && mImpl->mFontDefaults->slantDefined;
651 FontSlant Controller::GetDefaultFontSlant() const
653 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.slant : TextAbstraction::FontSlant::NORMAL;
656 void Controller::SetPlaceholderTextFontSlant(FontSlant slant)
658 PlaceholderHandler::SetPlaceholderTextFontSlant(*this, slant);
661 bool Controller::IsPlaceholderTextFontSlantDefined() const
663 return PlaceholderHandler::IsPlaceholderTextFontSlantDefined(*this);
666 FontSlant Controller::GetPlaceholderTextFontSlant() const
668 return PlaceholderHandler::GetPlaceholderTextFontSlant(*this);
671 void Controller::SetFontSizeScale(float scale)
673 mImpl->mFontSizeScale = scale;
675 // No relayout is required
676 if(!mImpl->mFontSizeScaleEnabled) return;
678 // Update the cursor position if it's in editing mode
679 UpdateCursorPosition(mImpl->mEventData);
681 // Clear the font-specific data
682 mImpl->ClearFontData();
684 mImpl->RequestRelayout();
687 float Controller::GetFontSizeScale() const
689 return mImpl->mFontDefaults ? mImpl->mFontSizeScale : 1.0f;
692 void Controller::SetFontSizeScaleEnabled(bool enabled)
694 mImpl->mFontSizeScaleEnabled = enabled;
696 // Update the cursor position if it's in editing mode
697 UpdateCursorPosition(mImpl->mEventData);
699 // Clear the font-specific data
700 mImpl->ClearFontData();
702 mImpl->RequestRelayout();
705 bool Controller::IsFontSizeScaleEnabled() const
707 return mImpl->mFontSizeScaleEnabled;
710 void Controller::SetDefaultFontSize(float fontSize, FontSizeType type)
712 EnsureCreated(mImpl->mFontDefaults);
714 mImpl->mFontDefaults->mDefaultPointSize = (type == POINT_SIZE) ? fontSize : ConvertPixelToPoint(fontSize);
715 mImpl->mFontDefaults->sizeDefined = true;
717 // Update the cursor position if it's in editing mode
718 UpdateCursorPosition(mImpl->mEventData);
720 // Clear the font-specific data
721 mImpl->ClearFontData();
723 mImpl->RequestRelayout();
726 float Controller::GetDefaultFontSize(FontSizeType type) const
728 if(mImpl->mFontDefaults)
730 return (type == POINT_SIZE) ? mImpl->mFontDefaults->mDefaultPointSize : ConvertPointToPixel(mImpl->mFontDefaults->mDefaultPointSize);
735 void Controller::SetPlaceholderTextFontSize(float fontSize, FontSizeType type)
737 PlaceholderHandler::SetPlaceholderTextFontSize(*this, fontSize, type);
740 float Controller::GetPlaceholderTextFontSize(FontSizeType type) const
742 return PlaceholderHandler::GetPlaceholderTextFontSize(*this, type);
745 void Controller::SetDefaultColor(const Vector4& color)
747 mImpl->SetDefaultColor(color);
750 const Vector4& Controller::GetDefaultColor() const
752 return mImpl->mTextColor;
755 void Controller::SetDisabledColorOpacity(float opacity)
757 mImpl->mDisabledColorOpacity = opacity;
760 float Controller::GetDisabledColorOpacity() const
762 return mImpl->mDisabledColorOpacity;
765 void Controller::SetUserInteractionEnabled(bool enabled)
767 mImpl->SetUserInteractionEnabled(enabled);
770 bool Controller::IsUserInteractionEnabled() const
772 return mImpl->mIsUserInteractionEnabled;
775 void Controller::SetPlaceholderTextColor(const Vector4& textColor)
777 PlaceholderHandler::SetPlaceholderTextColor(*this, textColor);
780 const Vector4& Controller::GetPlaceholderTextColor() const
782 return PlaceholderHandler::GetPlaceholderTextColor(*this);
785 void Controller::SetShadowOffset(const Vector2& shadowOffset)
787 mImpl->mModel->mVisualModel->SetShadowOffset(shadowOffset);
788 mImpl->RequestRelayout();
791 const Vector2& Controller::GetShadowOffset() const
793 return mImpl->mModel->mVisualModel->GetShadowOffset();
796 void Controller::SetShadowColor(const Vector4& shadowColor)
798 mImpl->mModel->mVisualModel->SetShadowColor(shadowColor);
799 mImpl->RequestRelayout();
802 const Vector4& Controller::GetShadowColor() const
804 return mImpl->mModel->mVisualModel->GetShadowColor();
807 void Controller::SetShadowBlurRadius(const float& shadowBlurRadius)
809 if(fabsf(GetShadowBlurRadius() - shadowBlurRadius) > Math::MACHINE_EPSILON_1)
811 mImpl->mModel->mVisualModel->SetShadowBlurRadius(shadowBlurRadius);
812 mImpl->RequestRelayout();
816 const float& Controller::GetShadowBlurRadius() const
818 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
821 void Controller::SetUnderlineColor(const Vector4& color)
823 mImpl->mModel->mVisualModel->SetUnderlineColor(color);
824 mImpl->RequestRelayout();
827 const Vector4& Controller::GetUnderlineColor() const
829 return mImpl->mModel->mVisualModel->GetUnderlineColor();
832 void Controller::SetUnderlineEnabled(bool enabled)
834 mImpl->mModel->mVisualModel->SetUnderlineEnabled(enabled);
835 mImpl->RequestRelayout();
838 bool Controller::IsUnderlineEnabled() const
840 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
843 void Controller::SetUnderlineHeight(float height)
845 mImpl->mModel->mVisualModel->SetUnderlineHeight(height);
846 mImpl->RequestRelayout();
849 float Controller::GetUnderlineHeight() const
851 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
854 void Controller::SetUnderlineType(Text::Underline::Type type)
856 mImpl->mModel->mVisualModel->SetUnderlineType(type);
858 mImpl->RequestRelayout();
861 Text::Underline::Type Controller::GetUnderlineType() const
863 return mImpl->mModel->mVisualModel->GetUnderlineType();
866 void Controller::SetDashedUnderlineWidth(float width)
868 mImpl->mModel->mVisualModel->SetDashedUnderlineWidth(width);
870 mImpl->RequestRelayout();
873 float Controller::GetDashedUnderlineWidth() const
875 return mImpl->mModel->mVisualModel->GetDashedUnderlineWidth();
878 void Controller::SetDashedUnderlineGap(float gap)
880 mImpl->mModel->mVisualModel->SetDashedUnderlineGap(gap);
882 mImpl->RequestRelayout();
885 float Controller::GetDashedUnderlineGap() const
887 return mImpl->mModel->mVisualModel->GetDashedUnderlineGap();
890 void Controller::SetOutlineColor(const Vector4& color)
892 mImpl->mModel->mVisualModel->SetOutlineColor(color);
893 mImpl->RequestRelayout();
896 const Vector4& Controller::GetOutlineColor() const
898 return mImpl->mModel->mVisualModel->GetOutlineColor();
901 void Controller::SetOutlineWidth(uint16_t width)
903 mImpl->mModel->mVisualModel->SetOutlineWidth(width);
904 mImpl->RequestRelayout();
907 uint16_t Controller::GetOutlineWidth() const
909 return mImpl->mModel->mVisualModel->GetOutlineWidth();
912 void Controller::SetBackgroundColor(const Vector4& color)
914 mImpl->mModel->mVisualModel->SetBackgroundColor(color);
915 mImpl->RequestRelayout();
918 const Vector4& Controller::GetBackgroundColor() const
920 return mImpl->mModel->mVisualModel->GetBackgroundColor();
923 void Controller::SetBackgroundEnabled(bool enabled)
925 mImpl->mModel->mVisualModel->SetBackgroundEnabled(enabled);
926 mImpl->RequestRelayout();
929 bool Controller::IsBackgroundEnabled() const
931 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
934 void Controller::SetDefaultEmbossProperties(const std::string& embossProperties)
936 EnsureCreated(mImpl->mEmbossDefaults);
937 mImpl->mEmbossDefaults->properties = embossProperties;
940 const std::string& Controller::GetDefaultEmbossProperties() const
942 return mImpl->mEmbossDefaults ? mImpl->mEmbossDefaults->properties : EMPTY_STRING;
945 void Controller::SetDefaultOutlineProperties(const std::string& outlineProperties)
947 EnsureCreated(mImpl->mOutlineDefaults);
948 mImpl->mOutlineDefaults->properties = outlineProperties;
951 const std::string& Controller::GetDefaultOutlineProperties() const
953 return mImpl->mOutlineDefaults ? mImpl->mOutlineDefaults->properties : EMPTY_STRING;
956 bool Controller::SetDefaultLineSpacing(float lineSpacing)
958 return mImpl->SetDefaultLineSpacing(lineSpacing);
961 float Controller::GetDefaultLineSpacing() const
963 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
966 bool Controller::SetDefaultLineSize(float lineSize)
968 return mImpl->SetDefaultLineSize(lineSize);
971 float Controller::GetDefaultLineSize() const
973 return mImpl->mLayoutEngine.GetDefaultLineSize();
976 bool Controller::SetRelativeLineSize(float relativeLineSize)
978 return mImpl->SetRelativeLineSize(relativeLineSize);
981 float Controller::GetRelativeLineSize() const
983 return mImpl->GetRelativeLineSize();
986 void Controller::SetInputColor(const Vector4& color)
988 InputProperties::SetInputColor(*this, color);
991 const Vector4& Controller::GetInputColor() const
993 return InputProperties::GetInputColor(*this);
996 void Controller::SetInputFontFamily(const std::string& fontFamily)
998 InputFontHandler::SetInputFontFamily(*this, fontFamily);
1001 const std::string& Controller::GetInputFontFamily() const
1003 return InputFontHandler::GetInputFontFamily(*this);
1006 void Controller::SetInputFontWeight(FontWeight weight)
1008 InputFontHandler::SetInputFontWeight(*this, weight);
1011 bool Controller::IsInputFontWeightDefined() const
1013 return InputFontHandler::IsInputFontWeightDefined(*this);
1016 FontWeight Controller::GetInputFontWeight() const
1018 return InputFontHandler::GetInputFontWeight(*this);
1021 void Controller::SetInputFontWidth(FontWidth width)
1023 InputFontHandler::SetInputFontWidth(*this, width);
1026 bool Controller::IsInputFontWidthDefined() const
1028 return InputFontHandler::IsInputFontWidthDefined(*this);
1031 FontWidth Controller::GetInputFontWidth() const
1033 return InputFontHandler::GetInputFontWidth(*this);
1036 void Controller::SetInputFontSlant(FontSlant slant)
1038 InputFontHandler::SetInputFontSlant(*this, slant);
1041 bool Controller::IsInputFontSlantDefined() const
1043 return InputFontHandler::IsInputFontSlantDefined(*this);
1046 FontSlant Controller::GetInputFontSlant() const
1048 return InputFontHandler::GetInputFontSlant(*this);
1051 void Controller::SetInputFontPointSize(float size)
1053 InputFontHandler::SetInputFontPointSize(*this, size);
1056 float Controller::GetInputFontPointSize() const
1058 return InputFontHandler::GetInputFontPointSize(*this);
1061 void Controller::SetInputLineSpacing(float lineSpacing)
1063 InputProperties::SetInputLineSpacing(*this, lineSpacing);
1066 float Controller::GetInputLineSpacing() const
1068 return InputProperties::GetInputLineSpacing(*this);
1071 void Controller::SetInputShadowProperties(const std::string& shadowProperties)
1073 InputProperties::SetInputShadowProperties(*this, shadowProperties);
1076 const std::string& Controller::GetInputShadowProperties() const
1078 return InputProperties::GetInputShadowProperties(*this);
1081 void Controller::SetInputUnderlineProperties(const std::string& underlineProperties)
1083 InputProperties::SetInputUnderlineProperties(*this, underlineProperties);
1086 const std::string& Controller::GetInputUnderlineProperties() const
1088 return InputProperties::GetInputUnderlineProperties(*this);
1091 void Controller::SetInputEmbossProperties(const std::string& embossProperties)
1093 InputProperties::SetInputEmbossProperties(*this, embossProperties);
1096 const std::string& Controller::GetInputEmbossProperties() const
1098 return InputProperties::GetInputEmbossProperties(*this);
1101 void Controller::SetInputOutlineProperties(const std::string& outlineProperties)
1103 InputProperties::SetInputOutlineProperties(*this, outlineProperties);
1106 const std::string& Controller::GetInputOutlineProperties() const
1108 return InputProperties::GetInputOutlineProperties(*this);
1111 void Controller::SetInputModePassword(bool passwordInput)
1113 InputProperties::SetInputModePassword(*this, passwordInput);
1116 bool Controller::IsInputModePassword()
1118 return InputProperties::IsInputModePassword(*this);
1121 void Controller::SetNoTextDoubleTapAction(NoTextTap::Action action)
1123 if(mImpl->mEventData)
1125 mImpl->mEventData->mDoubleTapAction = action;
1129 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1131 return mImpl->mEventData ? mImpl->mEventData->mDoubleTapAction : NoTextTap::NO_ACTION;
1134 void Controller::SetNoTextLongPressAction(NoTextTap::Action action)
1136 if(mImpl->mEventData)
1138 mImpl->mEventData->mLongPressAction = action;
1142 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1144 return mImpl->mEventData ? mImpl->mEventData->mLongPressAction : NoTextTap::NO_ACTION;
1147 bool Controller::IsUnderlineSetByString()
1149 return mImpl->mUnderlineSetByString;
1152 void Controller::UnderlineSetByString(bool setByString)
1154 mImpl->mUnderlineSetByString = setByString;
1157 bool Controller::IsShadowSetByString()
1159 return mImpl->mShadowSetByString;
1162 void Controller::ShadowSetByString(bool setByString)
1164 mImpl->mShadowSetByString = setByString;
1167 bool Controller::IsOutlineSetByString()
1169 return mImpl->mOutlineSetByString;
1172 void Controller::OutlineSetByString(bool setByString)
1174 mImpl->mOutlineSetByString = setByString;
1177 bool Controller::IsFontStyleSetByString()
1179 return mImpl->mFontStyleSetByString;
1182 void Controller::FontStyleSetByString(bool setByString)
1184 mImpl->mFontStyleSetByString = setByString;
1187 void Controller::SetStrikethroughHeight(float height)
1189 mImpl->mModel->mVisualModel->SetStrikethroughHeight(height);
1191 mImpl->RequestRelayout();
1194 float Controller::GetStrikethroughHeight() const
1196 return mImpl->mModel->mVisualModel->GetStrikethroughHeight();
1199 void Controller::SetStrikethroughColor(const Vector4& color)
1201 mImpl->mModel->mVisualModel->SetStrikethroughColor(color);
1203 mImpl->RequestRelayout();
1206 const Vector4& Controller::GetStrikethroughColor() const
1208 return mImpl->mModel->mVisualModel->GetStrikethroughColor();
1211 void Controller::SetStrikethroughEnabled(bool enabled)
1213 mImpl->mModel->mVisualModel->SetStrikethroughEnabled(enabled);
1215 mImpl->RequestRelayout();
1218 bool Controller::IsStrikethroughEnabled() const
1220 return mImpl->mModel->mVisualModel->IsStrikethroughEnabled();
1223 void Controller::SetInputStrikethroughProperties(const std::string& strikethroughProperties)
1225 if(NULL != mImpl->mEventData)
1227 mImpl->mEventData->mInputStyle.strikethroughProperties = strikethroughProperties;
1231 const std::string& Controller::GetInputStrikethroughProperties() const
1233 return (NULL != mImpl->mEventData) ? mImpl->mEventData->mInputStyle.strikethroughProperties : EMPTY_STRING;
1236 bool Controller::IsStrikethroughSetByString()
1238 return mImpl->mStrikethroughSetByString;
1241 void Controller::StrikethroughSetByString(bool setByString)
1243 mImpl->mStrikethroughSetByString = setByString;
1246 Layout::Engine& Controller::GetLayoutEngine()
1248 return mImpl->mLayoutEngine;
1251 View& Controller::GetView()
1253 return mImpl->mView;
1256 Vector3 Controller::GetNaturalSize()
1258 return Relayouter::GetNaturalSize(*this);
1261 bool Controller::CheckForTextFit(float pointSize, Size& layoutSize)
1263 return Relayouter::CheckForTextFit(*this, pointSize, layoutSize);
1266 void Controller::FitPointSizeforLayout(Size layoutSize)
1268 Relayouter::FitPointSizeforLayout(*this, layoutSize);
1271 float Controller::GetHeightForWidth(float width)
1273 return Relayouter::GetHeightForWidth(*this, width);
1276 int Controller::GetLineCount(float width)
1278 GetHeightForWidth(width);
1279 return mImpl->mModel->GetNumberOfLines();
1282 const ModelInterface* const Controller::GetTextModel() const
1284 return mImpl->mModel.Get();
1287 float Controller::GetScrollAmountByUserInput()
1289 float scrollAmount = 0.0f;
1291 if(NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1293 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1294 mImpl->mEventData->mCheckScrollAmount = false;
1296 return scrollAmount;
1299 bool Controller::GetTextScrollInfo(float& scrollPosition, float& controlHeight, float& layoutHeight)
1301 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1304 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1305 layoutHeight = layout.height;
1306 scrollPosition = mImpl->mModel->mScrollPosition.y;
1307 isScrolled = !Equals(mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1);
1311 void Controller::SetHiddenInputOption(const Property::Map& options)
1313 EnsureCreated<HiddenText, Controller*>(mImpl->mHiddenInput, this);
1314 mImpl->mHiddenInput->SetProperties(options);
1317 void Controller::GetHiddenInputOption(Property::Map& options)
1319 if(mImpl->mHiddenInput)
1321 mImpl->mHiddenInput->GetProperties(options);
1325 void Controller::SetInputFilterOption(const Property::Map& options)
1327 EnsureCreated(mImpl->mInputFilter);
1328 mImpl->mInputFilter->SetProperties(options);
1331 void Controller::GetInputFilterOption(Property::Map& options)
1333 if(mImpl->mInputFilter)
1335 mImpl->mInputFilter->GetProperties(options);
1339 void Controller::SetPlaceholderProperty(const Property::Map& map)
1341 PlaceholderHandler::SetPlaceholderProperty(*this, map);
1344 void Controller::GetPlaceholderProperty(Property::Map& map)
1346 PlaceholderHandler::GetPlaceholderProperty(*this, map);
1349 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
1351 // Make sure the model is up-to-date before layouting
1352 EventHandler::ProcessModifyEvents(*this);
1354 return mImpl->GetTextDirection();
1357 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
1359 return mImpl->mModel->GetVerticalLineAlignment();
1362 void Controller::SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment)
1364 mImpl->mModel->mVerticalLineAlignment = alignment;
1367 Toolkit::DevelText::EllipsisPosition::Type Controller::GetEllipsisPosition() const
1369 return mImpl->mModel->GetEllipsisPosition();
1372 void Controller::SetEllipsisPosition(Toolkit::DevelText::EllipsisPosition::Type ellipsisPosition)
1374 mImpl->mModel->mEllipsisPosition = ellipsisPosition;
1375 mImpl->mModel->mVisualModel->SetEllipsisPosition(ellipsisPosition);
1378 void Controller::SetCharacterSpacing(float characterSpacing)
1380 mImpl->mModel->mVisualModel->SetCharacterSpacing(characterSpacing);
1382 mImpl->RelayoutAllCharacters();
1383 mImpl->RequestRelayout();
1386 const float Controller::GetCharacterSpacing() const
1388 return mImpl->mModel->mVisualModel->GetCharacterSpacing();
1391 Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection)
1393 return Relayouter::Relayout(*this, size, layoutDirection);
1396 void Controller::RequestRelayout()
1398 mImpl->RequestRelayout();
1401 Vector<Vector2> Controller::GetTextSize(CharacterIndex startIndex, CharacterIndex endIndex)
1403 Vector<Vector2> sizesList;
1404 Vector<Vector2> positionsList;
1406 GetTextGeometry(mImpl->mModel, startIndex, endIndex, sizesList, positionsList);
1410 Vector<Vector2> Controller::GetTextPosition(CharacterIndex startIndex, CharacterIndex endIndex)
1412 Vector<Vector2> sizesList;
1413 Vector<Vector2> positionsList;
1415 GetTextGeometry(mImpl->mModel, startIndex, endIndex, sizesList, positionsList);
1416 return positionsList;
1419 Rect<> Controller::GetTextBoundingRectangle(CharacterIndex startIndex, CharacterIndex endIndex)
1421 Vector<Vector2> sizeList;
1422 Vector<Vector2> positionList;
1424 GetTextGeometry(mImpl->mModel, startIndex, endIndex, sizeList, positionList);
1426 if(sizeList.Empty() || sizeList.Size() != positionList.Size())
1428 return {0, 0, 0, 0};
1431 auto minX = positionList[0].x;
1432 auto minY = positionList[0].y;
1433 auto maxRight = positionList[0].x + sizeList[0].x;
1434 auto maxBottom = positionList[0].y + sizeList[0].y;
1436 for(unsigned int i = 1; i < sizeList.Size(); i++)
1438 minX = std::min(minX, positionList[i].x);
1439 minY = std::min(minY, positionList[i].y);
1440 maxRight = std::max(maxRight, positionList[i].x + sizeList[i].x);
1441 maxBottom = std::max(maxBottom, positionList[i].y + sizeList[i].y);
1444 return {minX, minY, maxRight - minX, maxBottom - minY};
1447 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1449 return mImpl->IsInputStyleChangedSignalsQueueEmpty();
1452 void Controller::ProcessInputStyleChangedSignals()
1454 mImpl->ProcessInputStyleChangedSignals();
1457 void Controller::KeyboardFocusGainEvent()
1459 EventHandler::KeyboardFocusGainEvent(*this);
1462 void Controller::KeyboardFocusLostEvent()
1464 EventHandler::KeyboardFocusLostEvent(*this);
1467 bool Controller::KeyEvent(const Dali::KeyEvent& keyEvent)
1469 return EventHandler::KeyEvent(*this, keyEvent);
1472 void Controller::AnchorEvent(float x, float y)
1474 EventHandler::AnchorEvent(*this, x, y);
1477 void Controller::TapEvent(unsigned int tapCount, float x, float y)
1479 EventHandler::TapEvent(*this, tapCount, x, y);
1482 void Controller::PanEvent(GestureState state, const Vector2& displacement)
1484 EventHandler::PanEvent(*this, state, displacement);
1487 void Controller::LongPressEvent(GestureState state, float x, float y)
1489 EventHandler::LongPressEvent(*this, state, x, y);
1492 void Controller::SelectEvent(float x, float y, SelectionType selectType)
1494 EventHandler::SelectEvent(*this, x, y, selectType);
1497 void Controller::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1499 if(mImpl->mEventData)
1501 mImpl->mEventData->mCheckScrollAmount = true;
1502 mImpl->mEventData->mIsLeftHandleSelected = true;
1503 mImpl->mEventData->mIsRightHandleSelected = true;
1504 mImpl->SetTextSelectionRange(start, end);
1505 mImpl->RequestRelayout();
1506 EventHandler::KeyboardFocusGainEvent(*this);
1510 Uint32Pair Controller::GetTextSelectionRange() const
1512 return mImpl->GetTextSelectionRange();
1515 CharacterIndex Controller::GetPrimaryCursorPosition() const
1517 return mImpl->GetPrimaryCursorPosition();
1520 bool Controller::SetPrimaryCursorPosition(CharacterIndex index, bool focused)
1522 if(mImpl->mEventData)
1524 mImpl->mEventData->mCheckScrollAmount = true;
1525 mImpl->mEventData->mIsLeftHandleSelected = true;
1526 mImpl->mEventData->mIsRightHandleSelected = true;
1527 mImpl->mEventData->mCheckScrollAmount = true;
1528 if(mImpl->SetPrimaryCursorPosition(index, focused) && focused)
1530 EventHandler::KeyboardFocusGainEvent(*this);
1537 void Controller::SelectWholeText()
1539 EventHandler::SelectEvent(*this, 0.f, 0.f, SelectionType::ALL);
1542 void Controller::SelectNone()
1544 EventHandler::SelectEvent(*this, 0.f, 0.f, SelectionType::NONE);
1547 void Controller::SelectText(const uint32_t start, const uint32_t end)
1549 EventHandler::SelectEvent(*this, start, end, SelectionType::RANGE);
1552 string Controller::GetSelectedText() const
1554 return mImpl->GetSelectedText();
1557 string Controller::CopyText()
1559 return mImpl->CopyText();
1562 string Controller::CutText()
1564 return mImpl->CutText();
1567 void Controller::PasteText()
1569 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
1572 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1574 return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent);
1577 void Controller::PasteClipboardItemEvent()
1579 EventHandler::PasteClipboardItemEvent(*this);
1582 void Controller::GetTargetSize(Vector2& targetSize)
1584 targetSize = mImpl->mModel->mVisualModel->mControlSize;
1587 void Controller::AddDecoration(Actor& actor, DecorationType type, bool needsClipping)
1589 if(mImpl->mEditableControlInterface)
1591 mImpl->mEditableControlInterface->AddDecoration(actor, type, needsClipping);
1595 bool Controller::IsEditable() const
1597 return mImpl->IsEditable();
1600 void Controller::SetEditable(bool editable)
1602 mImpl->SetEditable(editable);
1605 void Controller::ScrollBy(Vector2 scroll)
1607 mImpl->ScrollBy(scroll);
1610 bool Controller::IsScrollable(const Vector2& displacement)
1612 return mImpl->IsScrollable(displacement);
1615 float Controller::GetHorizontalScrollPosition()
1617 return mImpl->GetHorizontalScrollPosition();
1620 float Controller::GetVerticalScrollPosition()
1622 return mImpl->GetVerticalScrollPosition();
1625 void Controller::DecorationEvent(HandleType handleType, HandleState state, float x, float y)
1627 EventHandler::DecorationEvent(*this, handleType, state, x, y);
1630 void Controller::TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button)
1632 EventHandler::TextPopupButtonTouched(*this, button);
1635 void Controller::DisplayTimeExpired()
1637 mImpl->mEventData->mUpdateCursorPosition = true;
1638 // Apply modifications to the model
1639 mImpl->mOperationsPending = ALL_OPERATIONS;
1641 mImpl->RequestRelayout();
1644 void Controller::ResetCursorPosition(CharacterIndex cursorIndex)
1646 // Reset the cursor position
1647 if(NULL != mImpl->mEventData)
1649 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
1651 // Update the cursor if it's in editing mode.
1652 if(EventData::IsEditingState(mImpl->mEventData->mState))
1654 mImpl->mEventData->mUpdateCursorPosition = true;
1659 CharacterIndex Controller::GetCursorPosition()
1661 return mImpl->mEventData ? mImpl->mEventData->mPrimaryCursorPosition : 0;
1664 void Controller::SetControlInterface(ControlInterface* controlInterface)
1666 mImpl->mControlInterface = controlInterface;
1669 void Controller::SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface)
1671 mImpl->mAnchorControlInterface = anchorControlInterface;
1674 bool Controller::ShouldClearFocusOnEscape() const
1676 return mImpl->mShouldClearFocusOnEscape;
1679 Actor Controller::CreateBackgroundActor()
1681 return CreateControllerBackgroundActor(mImpl->mView, mImpl->mModel->mVisualModel, mImpl->mModel->mLogicalModel, mImpl->mShaderBackground);
1684 void Controller::GetAnchorActors(std::vector<Toolkit::TextAnchor>& anchorActors)
1686 mImpl->GetAnchorActors(anchorActors);
1689 int Controller::GetAnchorIndex(size_t characterOffset)
1691 return mImpl->GetAnchorIndex(characterOffset);
1694 Controller::Controller(ControlInterface* controlInterface,
1695 EditableControlInterface* editableControlInterface,
1696 SelectableControlInterface* selectableControlInterface,
1697 AnchorControlInterface* anchorControlInterface)
1698 : mImpl(new Controller::Impl(controlInterface, editableControlInterface, selectableControlInterface, anchorControlInterface))
1702 Controller::~Controller()
1707 } // namespace Dali::Toolkit::Text