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-input-properties.h>
35 #include <dali-toolkit/internal/text/text-controller-placeholder-handler.h>
36 #include <dali-toolkit/internal/text/text-controller-relayouter.h>
37 #include <dali-toolkit/internal/text/text-controller-text-updater.h>
38 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
42 #if defined(DEBUG_ENABLED)
43 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
46 constexpr float MAX_FLOAT = std::numeric_limits<float>::max();
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
121 void Controller::EnableTextInput(DecoratorPtr decorator, InputMethodContext& inputMethodContext)
125 delete mImpl->mEventData;
126 mImpl->mEventData = NULL;
128 // Nothing else to do.
132 EnsureCreated(mImpl->mEventData, decorator, inputMethodContext);
135 void Controller::SetGlyphType(TextAbstraction::GlyphType glyphType)
137 // Metrics for bitmap & vector based glyphs are different
138 mImpl->mMetrics->SetGlyphType(glyphType);
140 // Clear the font-specific data
141 mImpl->ClearFontData();
143 mImpl->RequestRelayout();
146 void Controller::SetMarkupProcessorEnabled(bool enable)
148 if(enable != mImpl->mMarkupProcessorEnabled)
150 //If Text was already set, call the SetText again for enabling or disabling markup
151 mImpl->mMarkupProcessorEnabled = enable;
157 mImpl->mModel->mVisualModel->SetMarkupProcessorEnabled(enable);
160 bool Controller::IsMarkupProcessorEnabled() const
162 return mImpl->mMarkupProcessorEnabled;
165 bool Controller::HasAnchors() const
167 return (mImpl->mMarkupProcessorEnabled && mImpl->mModel->mLogicalModel->mAnchors.Count() && mImpl->IsShowingRealText());
170 void Controller::SetAutoScrollEnabled(bool enable)
172 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 mImpl->SetAutoScrollEnabled(enable);
176 bool Controller::IsAutoScrollEnabled() const
178 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled ? "true" : "false");
179 return mImpl->mIsAutoScrollEnabled;
182 CharacterDirection Controller::GetAutoScrollDirection() const
184 return mImpl->mIsTextDirectionRTL;
187 float Controller::GetAutoScrollLineAlignment() const
190 if(mImpl->mModel->mVisualModel && (0u != mImpl->mModel->mVisualModel->mLines.Count()))
192 offset = (*mImpl->mModel->mVisualModel->mLines.Begin()).alignmentOffset;
197 void Controller::SetHorizontalScrollEnabled(bool enable)
199 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
201 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled(enable);
205 bool Controller::IsHorizontalScrollEnabled() const
207 return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
210 void Controller::SetVerticalScrollEnabled(bool enable)
212 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
214 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled(enable);
218 bool Controller::IsVerticalScrollEnabled() const
220 return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
223 void Controller::SetSmoothHandlePanEnabled(bool enable)
225 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
227 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled(enable);
231 bool Controller::IsSmoothHandlePanEnabled() const
233 return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
236 void Controller::SetMaximumNumberOfCharacters(Length maxCharacters)
238 mImpl->mMaximumNumberOfCharacters = maxCharacters;
241 int Controller::GetMaximumNumberOfCharacters()
243 return mImpl->mMaximumNumberOfCharacters;
246 void Controller::SetEnableCursorBlink(bool enable)
248 mImpl->SetEnableCursorBlink(enable);
251 bool Controller::GetEnableCursorBlink() const
253 return mImpl->mEventData && mImpl->mEventData->mCursorBlinkEnabled;
256 void Controller::SetMultiLineEnabled(bool enable)
258 mImpl->SetMultiLineEnabled(enable);
261 bool Controller::IsMultiLineEnabled() const
263 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
266 void Controller::SetHorizontalAlignment(Text::HorizontalAlignment::Type alignment)
268 mImpl->SetHorizontalAlignment(alignment);
271 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
273 return mImpl->mModel->mHorizontalAlignment;
276 void Controller::SetVerticalAlignment(VerticalAlignment::Type alignment)
278 mImpl->SetVerticalAlignment(alignment);
281 VerticalAlignment::Type Controller::GetVerticalAlignment() const
283 return mImpl->mModel->mVerticalAlignment;
286 bool Controller::IsIgnoreSpacesAfterText() const
288 return mImpl->mModel->mIgnoreSpacesAfterText;
291 void Controller::SetIgnoreSpacesAfterText(bool ignore)
293 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
296 void Controller::ChangedLayoutDirection()
298 mImpl->mIsLayoutDirectionChanged = true;
301 void Controller::SetMatchLayoutDirection(DevelText::MatchLayoutDirection type)
303 mImpl->mModel->mMatchLayoutDirection = type;
306 DevelText::MatchLayoutDirection Controller::GetMatchLayoutDirection() const
308 return mImpl->mModel->mMatchLayoutDirection;
311 void Controller::SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection)
313 mImpl->mLayoutDirection = layoutDirection;
316 Dali::LayoutDirection::Type Controller::GetLayoutDirection(Dali::Actor& actor) const
318 if(mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::LOCALE ||
319 (mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::INHERIT && !mImpl->mIsLayoutDirectionChanged))
321 return static_cast<Dali::LayoutDirection::Type>(DevelWindow::Get(actor).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
325 return static_cast<Dali::LayoutDirection::Type>(actor.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
329 bool Controller::IsShowingRealText() const
331 return mImpl->IsShowingRealText();
334 void Controller::SetLineWrapMode(Text::LineWrap::Mode lineWrapMode)
336 mImpl->SetLineWrapMode(lineWrapMode);
339 Text::LineWrap::Mode Controller::GetLineWrapMode() const
341 return mImpl->mModel->mLineWrapMode;
344 void Controller::SetTextElideEnabled(bool enabled)
346 mImpl->mModel->mElideEnabled = enabled;
347 mImpl->mModel->mVisualModel->SetTextElideEnabled(enabled);
350 bool Controller::IsTextElideEnabled() const
352 return mImpl->mModel->mElideEnabled;
355 void Controller::SetTextFitEnabled(bool enabled)
357 mImpl->mTextFitEnabled = enabled;
360 bool Controller::IsTextFitEnabled() const
362 return mImpl->mTextFitEnabled;
365 void Controller::SetTextFitMinSize(float minSize, FontSizeType type)
367 mImpl->mTextFitMinSize = (type == POINT_SIZE) ? minSize : ConvertPixelToPoint(minSize);
370 float Controller::GetTextFitMinSize() const
372 return mImpl->mTextFitMinSize;
375 void Controller::SetTextFitMaxSize(float maxSize, FontSizeType type)
377 mImpl->mTextFitMaxSize = (type == POINT_SIZE) ? maxSize : ConvertPixelToPoint(maxSize);
380 float Controller::GetTextFitMaxSize() const
382 return mImpl->mTextFitMaxSize;
385 void Controller::SetTextFitStepSize(float step, FontSizeType type)
387 mImpl->mTextFitStepSize = (type == POINT_SIZE) ? step : ConvertPixelToPoint(step);
390 float Controller::GetTextFitStepSize() const
392 return mImpl->mTextFitStepSize;
395 void Controller::SetTextFitContentSize(Vector2 size)
397 mImpl->mTextFitContentSize = size;
400 Vector2 Controller::GetTextFitContentSize() const
402 return mImpl->mTextFitContentSize;
405 void Controller::SetPlaceholderTextElideEnabled(bool enabled)
407 PlaceholderHandler::SetPlaceholderTextElideEnabled(*this, enabled);
410 bool Controller::IsPlaceholderTextElideEnabled() const
412 return PlaceholderHandler::IsPlaceholderTextElideEnabled(*this);
415 void Controller::SetSelectionEnabled(bool enabled)
417 mImpl->mEventData->mSelectionEnabled = enabled;
420 bool Controller::IsSelectionEnabled() const
422 return mImpl->mEventData->mSelectionEnabled;
425 void Controller::SetShiftSelectionEnabled(bool enabled)
427 mImpl->mEventData->mShiftSelectionFlag = enabled;
430 bool Controller::IsShiftSelectionEnabled() const
432 return mImpl->mEventData->mShiftSelectionFlag;
435 void Controller::SetGrabHandleEnabled(bool enabled)
437 mImpl->mEventData->mGrabHandleEnabled = enabled;
440 bool Controller::IsGrabHandleEnabled() const
442 return mImpl->mEventData->mGrabHandleEnabled;
445 void Controller::SetGrabHandlePopupEnabled(bool enabled)
447 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
450 bool Controller::IsGrabHandlePopupEnabled() const
452 return mImpl->mEventData->mGrabHandlePopupEnabled;
455 void Controller::SetText(const std::string& text)
457 TextUpdater::SetText(*this, text);
460 void Controller::GetText(std::string& text) const
462 if(!mImpl->IsShowingPlaceholderText())
464 // Retrieves the text string.
465 mImpl->GetText(0u, text);
469 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this);
473 void Controller::SetPlaceholderText(PlaceholderType type, const std::string& text)
475 PlaceholderHandler::SetPlaceholderText(*this, type, text);
478 void Controller::GetPlaceholderText(PlaceholderType type, std::string& text) const
480 PlaceholderHandler::GetPlaceholderText(*this, type, text);
483 void Controller::UpdateAfterFontChange(const std::string& newDefaultFont)
485 mImpl->UpdateAfterFontChange(newDefaultFont);
488 void Controller::RetrieveSelection(std::string& selectedText) const
490 mImpl->RetrieveSelection(selectedText, false);
493 void Controller::SetSelection(int start, int end)
495 mImpl->SetSelection(start, end);
498 std::pair<int, int> Controller::GetSelectionIndexes() const
500 return mImpl->GetSelectionIndexes();
503 void Controller::CopyStringToClipboard(const std::string& source)
505 mImpl->CopyStringToClipboard(source);
508 void Controller::SendSelectionToClipboard(bool deleteAfterSending)
510 mImpl->SendSelectionToClipboard(deleteAfterSending);
513 void Controller::SetDefaultFontFamily(const std::string& defaultFontFamily)
515 EnsureCreated(mImpl->mFontDefaults);
517 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
518 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
519 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
521 // Update the cursor position if it's in editing mode
522 UpdateCursorPosition(mImpl->mEventData);
524 // Clear the font-specific data
525 mImpl->ClearFontData();
527 mImpl->RequestRelayout();
530 const std::string& Controller::GetDefaultFontFamily() const
532 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.family : EMPTY_STRING;
535 void Controller::SetPlaceholderFontFamily(const std::string& placeholderTextFontFamily)
537 PlaceholderHandler::SetPlaceholderFontFamily(*this, placeholderTextFontFamily);
540 const std::string& Controller::GetPlaceholderFontFamily() const
542 return PlaceholderHandler::GetPlaceholderFontFamily(*this);
545 void Controller::SetDefaultFontWeight(FontWeight weight)
547 EnsureCreated(mImpl->mFontDefaults);
549 mImpl->mFontDefaults->mFontDescription.weight = weight;
550 mImpl->mFontDefaults->weightDefined = true;
552 // Update the cursor position if it's in editing mode
553 UpdateCursorPosition(mImpl->mEventData);
555 // Clear the font-specific data
556 mImpl->ClearFontData();
558 mImpl->RequestRelayout();
561 bool Controller::IsDefaultFontWeightDefined() const
563 return mImpl->mFontDefaults && mImpl->mFontDefaults->weightDefined;
566 FontWeight Controller::GetDefaultFontWeight() const
568 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.weight : TextAbstraction::FontWeight::NORMAL;
571 void Controller::SetPlaceholderTextFontWeight(FontWeight weight)
573 PlaceholderHandler::SetPlaceholderTextFontWeight(*this, weight);
576 bool Controller::IsPlaceholderTextFontWeightDefined() const
578 return PlaceholderHandler::IsPlaceholderTextFontWeightDefined(*this);
581 FontWeight Controller::GetPlaceholderTextFontWeight() const
583 return PlaceholderHandler::GetPlaceholderTextFontWeight(*this);
586 void Controller::SetDefaultFontWidth(FontWidth width)
588 EnsureCreated(mImpl->mFontDefaults);
590 mImpl->mFontDefaults->mFontDescription.width = width;
591 mImpl->mFontDefaults->widthDefined = true;
593 // Update the cursor position if it's in editing mode
594 UpdateCursorPosition(mImpl->mEventData);
596 // Clear the font-specific data
597 mImpl->ClearFontData();
599 mImpl->RequestRelayout();
602 bool Controller::IsDefaultFontWidthDefined() const
604 return mImpl->mFontDefaults && mImpl->mFontDefaults->widthDefined;
607 FontWidth Controller::GetDefaultFontWidth() const
609 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.width : TextAbstraction::FontWidth::NORMAL;
612 void Controller::SetPlaceholderTextFontWidth(FontWidth width)
614 PlaceholderHandler::SetPlaceholderTextFontWidth(*this, width);
617 bool Controller::IsPlaceholderTextFontWidthDefined() const
619 return PlaceholderHandler::IsPlaceholderTextFontWidthDefined(*this);
622 FontWidth Controller::GetPlaceholderTextFontWidth() const
624 return PlaceholderHandler::GetPlaceholderTextFontWidth(*this);
627 void Controller::SetDefaultFontSlant(FontSlant slant)
629 EnsureCreated(mImpl->mFontDefaults);
631 mImpl->mFontDefaults->mFontDescription.slant = slant;
632 mImpl->mFontDefaults->slantDefined = true;
634 // Update the cursor position if it's in editing mode
635 UpdateCursorPosition(mImpl->mEventData);
637 // Clear the font-specific data
638 mImpl->ClearFontData();
640 mImpl->RequestRelayout();
643 bool Controller::IsDefaultFontSlantDefined() const
645 return mImpl->mFontDefaults && mImpl->mFontDefaults->slantDefined;
648 FontSlant Controller::GetDefaultFontSlant() const
650 return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.slant : TextAbstraction::FontSlant::NORMAL;
653 void Controller::SetPlaceholderTextFontSlant(FontSlant slant)
655 PlaceholderHandler::SetPlaceholderTextFontSlant(*this, slant);
658 bool Controller::IsPlaceholderTextFontSlantDefined() const
660 return PlaceholderHandler::IsPlaceholderTextFontSlantDefined(*this);
663 FontSlant Controller::GetPlaceholderTextFontSlant() const
665 return PlaceholderHandler::GetPlaceholderTextFontSlant(*this);
668 void Controller::SetFontSizeScale(float scale)
670 mImpl->mFontSizeScale = scale;
672 // Update the cursor position if it's in editing mode
673 UpdateCursorPosition(mImpl->mEventData);
675 // Clear the font-specific data
676 mImpl->ClearFontData();
678 mImpl->RequestRelayout();
681 float Controller::GetFontSizeScale() const
683 return mImpl->mFontDefaults ? mImpl->mFontSizeScale : 1.0f;
686 void Controller::SetDefaultFontSize(float fontSize, FontSizeType type)
688 EnsureCreated(mImpl->mFontDefaults);
690 mImpl->mFontDefaults->mDefaultPointSize = (type == POINT_SIZE) ? fontSize : ConvertPixelToPoint(fontSize);
691 mImpl->mFontDefaults->sizeDefined = true;
693 // Update the cursor position if it's in editing mode
694 UpdateCursorPosition(mImpl->mEventData);
696 // Clear the font-specific data
697 mImpl->ClearFontData();
699 mImpl->RequestRelayout();
702 float Controller::GetDefaultFontSize(FontSizeType type) const
704 if(mImpl->mFontDefaults)
706 return (type == POINT_SIZE) ? mImpl->mFontDefaults->mDefaultPointSize : ConvertPointToPixel(mImpl->mFontDefaults->mDefaultPointSize);
711 void Controller::SetPlaceholderTextFontSize(float fontSize, FontSizeType type)
713 PlaceholderHandler::SetPlaceholderTextFontSize(*this, fontSize, type);
716 float Controller::GetPlaceholderTextFontSize(FontSizeType type) const
718 return PlaceholderHandler::GetPlaceholderTextFontSize(*this, type);
721 void Controller::SetDefaultColor(const Vector4& color)
723 mImpl->SetDefaultColor(color);
726 const Vector4& Controller::GetDefaultColor() const
728 return mImpl->mTextColor;
731 void Controller::SetPlaceholderTextColor(const Vector4& textColor)
733 PlaceholderHandler::SetPlaceholderTextColor(*this, textColor);
736 const Vector4& Controller::GetPlaceholderTextColor() const
738 return PlaceholderHandler::GetPlaceholderTextColor(*this);
741 void Controller::SetShadowOffset(const Vector2& shadowOffset)
743 mImpl->mModel->mVisualModel->SetShadowOffset(shadowOffset);
744 mImpl->RequestRelayout();
747 const Vector2& Controller::GetShadowOffset() const
749 return mImpl->mModel->mVisualModel->GetShadowOffset();
752 void Controller::SetShadowColor(const Vector4& shadowColor)
754 mImpl->mModel->mVisualModel->SetShadowColor(shadowColor);
755 mImpl->RequestRelayout();
758 const Vector4& Controller::GetShadowColor() const
760 return mImpl->mModel->mVisualModel->GetShadowColor();
763 void Controller::SetShadowBlurRadius(const float& shadowBlurRadius)
765 if(fabsf(GetShadowBlurRadius() - shadowBlurRadius) > Math::MACHINE_EPSILON_1)
767 mImpl->mModel->mVisualModel->SetShadowBlurRadius(shadowBlurRadius);
768 mImpl->RequestRelayout();
772 const float& Controller::GetShadowBlurRadius() const
774 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
777 void Controller::SetUnderlineColor(const Vector4& color)
779 mImpl->mModel->mVisualModel->SetUnderlineColor(color);
780 mImpl->RequestRelayout();
783 const Vector4& Controller::GetUnderlineColor() const
785 return mImpl->mModel->mVisualModel->GetUnderlineColor();
788 void Controller::SetUnderlineEnabled(bool enabled)
790 mImpl->mModel->mVisualModel->SetUnderlineEnabled(enabled);
791 mImpl->RequestRelayout();
794 bool Controller::IsUnderlineEnabled() const
796 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
799 void Controller::SetUnderlineHeight(float height)
801 mImpl->mModel->mVisualModel->SetUnderlineHeight(height);
802 mImpl->RequestRelayout();
805 float Controller::GetUnderlineHeight() const
807 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
810 void Controller::SetOutlineColor(const Vector4& color)
812 mImpl->mModel->mVisualModel->SetOutlineColor(color);
813 mImpl->RequestRelayout();
816 const Vector4& Controller::GetOutlineColor() const
818 return mImpl->mModel->mVisualModel->GetOutlineColor();
821 void Controller::SetOutlineWidth(uint16_t width)
823 mImpl->mModel->mVisualModel->SetOutlineWidth(width);
824 mImpl->RequestRelayout();
827 uint16_t Controller::GetOutlineWidth() const
829 return mImpl->mModel->mVisualModel->GetOutlineWidth();
832 void Controller::SetBackgroundColor(const Vector4& color)
834 mImpl->mModel->mVisualModel->SetBackgroundColor(color);
835 mImpl->RequestRelayout();
838 const Vector4& Controller::GetBackgroundColor() const
840 return mImpl->mModel->mVisualModel->GetBackgroundColor();
843 void Controller::SetBackgroundEnabled(bool enabled)
845 mImpl->mModel->mVisualModel->SetBackgroundEnabled(enabled);
846 mImpl->RequestRelayout();
849 bool Controller::IsBackgroundEnabled() const
851 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
854 void Controller::SetDefaultEmbossProperties(const std::string& embossProperties)
856 EnsureCreated(mImpl->mEmbossDefaults);
857 mImpl->mEmbossDefaults->properties = embossProperties;
860 const std::string& Controller::GetDefaultEmbossProperties() const
862 return mImpl->mEmbossDefaults ? mImpl->mEmbossDefaults->properties : EMPTY_STRING;
865 void Controller::SetDefaultOutlineProperties(const std::string& outlineProperties)
867 EnsureCreated(mImpl->mOutlineDefaults);
868 mImpl->mOutlineDefaults->properties = outlineProperties;
871 const std::string& Controller::GetDefaultOutlineProperties() const
873 return mImpl->mOutlineDefaults ? mImpl->mOutlineDefaults->properties : EMPTY_STRING;
876 bool Controller::SetDefaultLineSpacing(float lineSpacing)
878 return mImpl->SetDefaultLineSpacing(lineSpacing);
881 float Controller::GetDefaultLineSpacing() const
883 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
886 bool Controller::SetDefaultLineSize(float lineSize)
888 return mImpl->SetDefaultLineSize(lineSize);
891 float Controller::GetDefaultLineSize() const
893 return mImpl->mLayoutEngine.GetDefaultLineSize();
896 void Controller::SetInputColor(const Vector4& color)
898 InputProperties::SetInputColor(*this, color);
901 const Vector4& Controller::GetInputColor() const
903 return InputProperties::GetInputColor(*this);
906 void Controller::SetInputFontFamily(const std::string& fontFamily)
908 InputFontHandler::SetInputFontFamily(*this, fontFamily);
911 const std::string& Controller::GetInputFontFamily() const
913 return InputFontHandler::GetInputFontFamily(*this);
916 void Controller::SetInputFontWeight(FontWeight weight)
918 InputFontHandler::SetInputFontWeight(*this, weight);
921 bool Controller::IsInputFontWeightDefined() const
923 return InputFontHandler::IsInputFontWeightDefined(*this);
926 FontWeight Controller::GetInputFontWeight() const
928 return InputFontHandler::GetInputFontWeight(*this);
931 void Controller::SetInputFontWidth(FontWidth width)
933 InputFontHandler::SetInputFontWidth(*this, width);
936 bool Controller::IsInputFontWidthDefined() const
938 return InputFontHandler::IsInputFontWidthDefined(*this);
941 FontWidth Controller::GetInputFontWidth() const
943 return InputFontHandler::GetInputFontWidth(*this);
946 void Controller::SetInputFontSlant(FontSlant slant)
948 InputFontHandler::SetInputFontSlant(*this, slant);
951 bool Controller::IsInputFontSlantDefined() const
953 return InputFontHandler::IsInputFontSlantDefined(*this);
956 FontSlant Controller::GetInputFontSlant() const
958 return InputFontHandler::GetInputFontSlant(*this);
961 void Controller::SetInputFontPointSize(float size)
963 InputFontHandler::SetInputFontPointSize(*this, size);
966 float Controller::GetInputFontPointSize() const
968 return InputFontHandler::GetInputFontPointSize(*this);
971 void Controller::SetInputLineSpacing(float lineSpacing)
973 InputProperties::SetInputLineSpacing(*this, lineSpacing);
976 float Controller::GetInputLineSpacing() const
978 return InputProperties::GetInputLineSpacing(*this);
981 void Controller::SetInputShadowProperties(const std::string& shadowProperties)
983 InputProperties::SetInputShadowProperties(*this, shadowProperties);
986 const std::string& Controller::GetInputShadowProperties() const
988 return InputProperties::GetInputShadowProperties(*this);
991 void Controller::SetInputUnderlineProperties(const std::string& underlineProperties)
993 InputProperties::SetInputUnderlineProperties(*this, underlineProperties);
996 const std::string& Controller::GetInputUnderlineProperties() const
998 return InputProperties::GetInputUnderlineProperties(*this);
1001 void Controller::SetInputEmbossProperties(const std::string& embossProperties)
1003 InputProperties::SetInputEmbossProperties(*this, embossProperties);
1006 const std::string& Controller::GetInputEmbossProperties() const
1008 return InputProperties::GetInputEmbossProperties(*this);
1011 void Controller::SetInputOutlineProperties(const std::string& outlineProperties)
1013 InputProperties::SetInputOutlineProperties(*this, outlineProperties);
1016 const std::string& Controller::GetInputOutlineProperties() const
1018 return InputProperties::GetInputOutlineProperties(*this);
1021 void Controller::SetInputModePassword(bool passwordInput)
1023 InputProperties::SetInputModePassword(*this, passwordInput);
1026 bool Controller::IsInputModePassword()
1028 return InputProperties::IsInputModePassword(*this);
1031 void Controller::SetNoTextDoubleTapAction(NoTextTap::Action action)
1033 if(mImpl->mEventData)
1035 mImpl->mEventData->mDoubleTapAction = action;
1039 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1041 return mImpl->mEventData ? mImpl->mEventData->mDoubleTapAction : NoTextTap::NO_ACTION;
1044 void Controller::SetNoTextLongPressAction(NoTextTap::Action action)
1046 if(mImpl->mEventData)
1048 mImpl->mEventData->mLongPressAction = action;
1052 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1054 return mImpl->mEventData ? mImpl->mEventData->mLongPressAction : NoTextTap::NO_ACTION;
1057 bool Controller::IsUnderlineSetByString()
1059 return mImpl->mUnderlineSetByString;
1062 void Controller::UnderlineSetByString(bool setByString)
1064 mImpl->mUnderlineSetByString = setByString;
1067 bool Controller::IsShadowSetByString()
1069 return mImpl->mShadowSetByString;
1072 void Controller::ShadowSetByString(bool setByString)
1074 mImpl->mShadowSetByString = setByString;
1077 bool Controller::IsOutlineSetByString()
1079 return mImpl->mOutlineSetByString;
1082 void Controller::OutlineSetByString(bool setByString)
1084 mImpl->mOutlineSetByString = setByString;
1087 bool Controller::IsFontStyleSetByString()
1089 return mImpl->mFontStyleSetByString;
1092 void Controller::FontStyleSetByString(bool setByString)
1094 mImpl->mFontStyleSetByString = setByString;
1097 Layout::Engine& Controller::GetLayoutEngine()
1099 return mImpl->mLayoutEngine;
1102 View& Controller::GetView()
1104 return mImpl->mView;
1107 Vector3 Controller::GetNaturalSize()
1109 return Relayouter::GetNaturalSize(*this);
1112 bool Controller::CheckForTextFit(float pointSize, Size& layoutSize)
1114 return Relayouter::CheckForTextFit(*this, pointSize, layoutSize);
1117 void Controller::FitPointSizeforLayout(Size layoutSize)
1119 Relayouter::FitPointSizeforLayout(*this, layoutSize);
1122 float Controller::GetHeightForWidth(float width)
1124 return Relayouter::GetHeightForWidth(*this, width);
1127 int Controller::GetLineCount(float width)
1129 GetHeightForWidth(width);
1130 return mImpl->mModel->GetNumberOfLines();
1133 const ModelInterface* const Controller::GetTextModel() const
1135 return mImpl->mModel.Get();
1138 float Controller::GetScrollAmountByUserInput()
1140 float scrollAmount = 0.0f;
1142 if(NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1144 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1145 mImpl->mEventData->mCheckScrollAmount = false;
1147 return scrollAmount;
1150 bool Controller::GetTextScrollInfo(float& scrollPosition, float& controlHeight, float& layoutHeight)
1152 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1155 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1156 layoutHeight = layout.height;
1157 scrollPosition = mImpl->mModel->mScrollPosition.y;
1158 isScrolled = !Equals(mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1);
1162 void Controller::SetHiddenInputOption(const Property::Map& options)
1164 EnsureCreated<HiddenText, Controller*>(mImpl->mHiddenInput, this);
1165 mImpl->mHiddenInput->SetProperties(options);
1168 void Controller::GetHiddenInputOption(Property::Map& options)
1170 if(mImpl->mHiddenInput)
1172 mImpl->mHiddenInput->GetProperties(options);
1176 void Controller::SetInputFilterOption(const Property::Map& options)
1178 EnsureCreated(mImpl->mInputFilter);
1179 mImpl->mInputFilter->SetProperties(options);
1182 void Controller::GetInputFilterOption(Property::Map& options)
1184 if(mImpl->mInputFilter)
1186 mImpl->mInputFilter->GetProperties(options);
1190 void Controller::SetPlaceholderProperty(const Property::Map& map)
1192 PlaceholderHandler::SetPlaceholderProperty(*this, map);
1195 void Controller::GetPlaceholderProperty(Property::Map& map)
1197 PlaceholderHandler::GetPlaceholderProperty(*this, map);
1200 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
1202 // Make sure the model is up-to-date before layouting
1203 ProcessModifyEvents();
1205 if(mImpl->mUpdateTextDirection)
1207 // Operations that can be done only once until the text changes.
1208 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>(CONVERT_TO_UTF32 |
1216 // Set the update info to relayout the whole text.
1217 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1218 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1220 // Make sure the model is up-to-date before layouting
1221 mImpl->UpdateModel(onlyOnceOperations);
1223 Vector3 naturalSize;
1224 DoRelayout(Size(MAX_FLOAT, MAX_FLOAT),
1225 static_cast<OperationsMask>(onlyOnceOperations |
1226 LAYOUT | REORDER | UPDATE_DIRECTION),
1227 naturalSize.GetVectorXY());
1229 // Do not do again the only once operations.
1230 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending & ~onlyOnceOperations);
1232 // Clear the update info. This info will be set the next time the text is updated.
1233 mImpl->mTextUpdateInfo.Clear();
1235 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
1236 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1238 mImpl->mUpdateTextDirection = false;
1241 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
1244 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
1246 return mImpl->mModel->GetVerticalLineAlignment();
1249 void Controller::SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment)
1251 mImpl->mModel->mVerticalLineAlignment = alignment;
1254 Toolkit::DevelText::EllipsisPosition::Type Controller::GetEllipsisPosition() const
1256 return mImpl->mModel->GetEllipsisPosition();
1259 void Controller::SetEllipsisPosition(Toolkit::DevelText::EllipsisPosition::Type ellipsisPosition)
1261 mImpl->mModel->mEllipsisPosition = ellipsisPosition;
1262 mImpl->mModel->mVisualModel->SetEllipsisPosition(ellipsisPosition);
1265 Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection)
1267 return Relayouter::Relayout(*this, size, layoutDirection);
1270 void Controller::RequestRelayout()
1272 mImpl->RequestRelayout();
1275 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1277 return mImpl->IsInputStyleChangedSignalsQueueEmpty();
1280 void Controller::ProcessInputStyleChangedSignals()
1282 mImpl->ProcessInputStyleChangedSignals();
1285 void Controller::KeyboardFocusGainEvent()
1287 EventHandler::KeyboardFocusGainEvent(*this);
1290 void Controller::KeyboardFocusLostEvent()
1292 EventHandler::KeyboardFocusLostEvent(*this);
1295 bool Controller::KeyEvent(const Dali::KeyEvent& keyEvent)
1297 return EventHandler::KeyEvent(*this, keyEvent);
1300 void Controller::AnchorEvent(float x, float y)
1302 EventHandler::AnchorEvent(*this, x, y);
1305 void Controller::TapEvent(unsigned int tapCount, float x, float y)
1307 EventHandler::TapEvent(*this, tapCount, x, y);
1310 void Controller::PanEvent(GestureState state, const Vector2& displacement)
1312 EventHandler::PanEvent(*this, state, displacement);
1315 void Controller::LongPressEvent(GestureState state, float x, float y)
1317 EventHandler::LongPressEvent(*this, state, x, y);
1320 void Controller::SelectEvent(float x, float y, SelectionType selectType)
1322 EventHandler::SelectEvent(*this, x, y, selectType);
1325 void Controller::SelectEvent(const uint32_t start, const uint32_t end, SelectionType selectType)
1327 EventHandler::SelectEvent(*this, start, end, selectType);
1330 void Controller::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1332 if(mImpl->mEventData)
1334 mImpl->mEventData->mCheckScrollAmount = true;
1335 mImpl->mEventData->mIsLeftHandleSelected = true;
1336 mImpl->mEventData->mIsRightHandleSelected = true;
1337 mImpl->SetTextSelectionRange(start, end);
1338 mImpl->RequestRelayout();
1339 KeyboardFocusGainEvent();
1343 Uint32Pair Controller::GetTextSelectionRange() const
1345 return mImpl->GetTextSelectionRange();
1348 CharacterIndex Controller::GetPrimaryCursorPosition() const
1350 return mImpl->GetPrimaryCursorPosition();
1353 bool Controller::SetPrimaryCursorPosition(CharacterIndex index, bool focused)
1355 if(mImpl->mEventData)
1357 mImpl->mEventData->mCheckScrollAmount = true;
1358 mImpl->mEventData->mIsLeftHandleSelected = true;
1359 mImpl->mEventData->mIsRightHandleSelected = true;
1360 mImpl->mEventData->mCheckScrollAmount = true;
1361 if(mImpl->SetPrimaryCursorPosition(index, focused) && focused)
1363 KeyboardFocusGainEvent();
1370 void Controller::SelectWholeText()
1372 SelectEvent(0.f, 0.f, SelectionType::ALL);
1375 void Controller::SelectNone()
1377 SelectEvent(0.f, 0.f, SelectionType::NONE);
1380 void Controller::SelectText(const uint32_t start, const uint32_t end)
1382 SelectEvent(start, end, SelectionType::RANGE);
1385 string Controller::GetSelectedText() const
1388 if(EventData::SELECTING == mImpl->mEventData->mState)
1390 mImpl->RetrieveSelection(text, false);
1395 string Controller::CopyText()
1398 mImpl->RetrieveSelection(text, false);
1399 mImpl->SendSelectionToClipboard(false); // Text not modified
1401 mImpl->mEventData->mUpdateCursorPosition = true;
1403 mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
1408 string Controller::CutText()
1411 mImpl->RetrieveSelection(text, false);
1415 return EMPTY_STRING;
1418 mImpl->SendSelectionToClipboard(true); // Synchronous call to modify text
1419 mImpl->mOperationsPending = ALL_OPERATIONS;
1421 if((0u != mImpl->mModel->mLogicalModel->mText.Count()) ||
1422 !mImpl->IsPlaceholderAvailable())
1424 mImpl->QueueModifyEvent(ModifyEvent::TEXT_DELETED);
1428 ShowPlaceholderText();
1431 mImpl->mEventData->mUpdateCursorPosition = true;
1432 mImpl->mEventData->mScrollAfterDelete = true;
1434 mImpl->RequestRelayout();
1436 if(nullptr != mImpl->mEditableControlInterface)
1438 mImpl->mEditableControlInterface->TextChanged(true);
1443 void Controller::PasteText()
1445 mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
1448 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1450 return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent);
1453 void Controller::PasteClipboardItemEvent()
1455 EventHandler::PasteClipboardItemEvent(*this);
1458 void Controller::GetTargetSize(Vector2& targetSize)
1460 targetSize = mImpl->mModel->mVisualModel->mControlSize;
1463 void Controller::AddDecoration(Actor& actor, bool needsClipping)
1465 if(mImpl->mEditableControlInterface)
1467 mImpl->mEditableControlInterface->AddDecoration(actor, needsClipping);
1471 bool Controller::IsEditable() const
1473 return mImpl->IsEditable();
1476 void Controller::SetEditable(bool editable)
1478 mImpl->SetEditable(editable);
1481 void Controller::ScrollBy(Vector2 scroll)
1483 mImpl->ScrollBy(scroll);
1486 float Controller::GetHorizontalScrollPosition()
1488 return mImpl->GetHorizontalScrollPosition();
1491 float Controller::GetVerticalScrollPosition()
1493 return mImpl->GetVerticalScrollPosition();
1496 void Controller::DecorationEvent(HandleType handleType, HandleState state, float x, float y)
1498 EventHandler::DecorationEvent(*this, handleType, state, x, y);
1501 void Controller::TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button)
1503 EventHandler::TextPopupButtonTouched(*this, button);
1506 void Controller::DisplayTimeExpired()
1508 mImpl->mEventData->mUpdateCursorPosition = true;
1509 // Apply modifications to the model
1510 mImpl->mOperationsPending = ALL_OPERATIONS;
1512 mImpl->RequestRelayout();
1515 void Controller::InsertText(const std::string& text, Controller::InsertType type)
1517 TextUpdater::InsertText(*this, text, type);
1520 void Controller::PasteText(const std::string& stringToPaste)
1522 TextUpdater::PasteText(*this, stringToPaste);
1525 bool Controller::RemoveText(int cursorOffset, int numberOfCharacters, UpdateInputStyleType type)
1527 return TextUpdater::RemoveText(*this, cursorOffset, numberOfCharacters, type);
1530 bool Controller::RemoveSelectedText()
1532 return TextUpdater::RemoveSelectedText(*this);
1535 void Controller::InsertTextAnchor(int numberOfCharacters, CharacterIndex previousCursorIndex)
1537 TextUpdater::InsertTextAnchor(*this, numberOfCharacters, previousCursorIndex);
1540 void Controller::RemoveTextAnchor(int cursorOffset, int numberOfCharacters, CharacterIndex previousCursorIndex)
1542 TextUpdater::RemoveTextAnchor(*this, cursorOffset, numberOfCharacters, previousCursorIndex);
1545 bool Controller::DoRelayout(const Size& size, OperationsMask operationsRequired, Size& layoutSize)
1547 return Relayouter::DoRelayout(*this, size, operationsRequired, layoutSize);
1550 void Controller::CalculateVerticalOffset(const Size& controlSize)
1552 Relayouter::CalculateVerticalOffset(*this, controlSize);
1555 void Controller::ProcessModifyEvents()
1557 EventHandler::ProcessModifyEvents(*this);
1560 void Controller::TextReplacedEvent()
1562 EventHandler::TextReplacedEvent(*this);
1565 void Controller::TextInsertedEvent()
1567 EventHandler::TextInsertedEvent(*this);
1570 void Controller::TextDeletedEvent()
1572 EventHandler::TextDeletedEvent(*this);
1575 bool Controller::DeleteEvent(int keyCode)
1577 return EventHandler::DeleteEvent(*this, keyCode);
1580 // private : Helpers.
1582 void Controller::ResetText()
1584 TextUpdater::ResetText(*this);
1587 void Controller::ShowPlaceholderText()
1589 PlaceholderHandler::ShowPlaceholderText(*this);
1592 void Controller::ResetCursorPosition(CharacterIndex cursorIndex)
1594 // Reset the cursor position
1595 if(NULL != mImpl->mEventData)
1597 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
1599 // Update the cursor if it's in editing mode.
1600 if(EventData::IsEditingState(mImpl->mEventData->mState))
1602 mImpl->mEventData->mUpdateCursorPosition = true;
1607 CharacterIndex Controller::GetCursorPosition()
1609 return mImpl->mEventData ? mImpl->mEventData->mPrimaryCursorPosition : 0;
1612 void Controller::SetControlInterface(ControlInterface* controlInterface)
1614 mImpl->mControlInterface = controlInterface;
1617 void Controller::SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface)
1619 mImpl->mAnchorControlInterface = anchorControlInterface;
1622 bool Controller::ShouldClearFocusOnEscape() const
1624 return mImpl->mShouldClearFocusOnEscape;
1627 Actor Controller::CreateBackgroundActor()
1629 return mImpl->CreateBackgroundActor();
1632 Controller::Controller(ControlInterface* controlInterface,
1633 EditableControlInterface* editableControlInterface,
1634 SelectableControlInterface* selectableControlInterface,
1635 AnchorControlInterface* anchorControlInterface)
1636 : mImpl(new Controller::Impl(controlInterface, editableControlInterface, selectableControlInterface, anchorControlInterface))
1640 Controller::~Controller()
1645 } // namespace Dali::Toolkit::Text