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 int ConvertPixelToPint(float pixel)
51 unsigned int horizontalDpi = 0u;
52 unsigned int verticalDpi = 0u;
53 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
54 fontClient.GetDpi(horizontalDpi, verticalDpi);
56 return (pixel * 72.f) / static_cast<float>(horizontalDpi);
67 // public : Constructor.
69 ControllerPtr Controller::New()
71 return ControllerPtr(new Controller());
74 ControllerPtr Controller::New(ControlInterface* controlInterface)
76 return ControllerPtr(new Controller(controlInterface));
79 ControllerPtr Controller::New(ControlInterface* controlInterface,
80 EditableControlInterface* editableControlInterface,
81 SelectableControlInterface* selectableControlInterface,
82 AnchorControlInterface* anchorControlInterface)
84 return ControllerPtr(new Controller(controlInterface,
85 editableControlInterface,
86 selectableControlInterface,
87 anchorControlInterface));
90 // public : Configure the text controller.
92 void Controller::EnableTextInput(DecoratorPtr decorator, InputMethodContext& inputMethodContext)
96 delete mImpl->mEventData;
97 mImpl->mEventData = NULL;
99 // Nothing else to do.
103 if(NULL == mImpl->mEventData)
105 mImpl->mEventData = new EventData(decorator, inputMethodContext);
109 void Controller::SetGlyphType(TextAbstraction::GlyphType glyphType)
111 // Metrics for bitmap & vector based glyphs are different
112 mImpl->mMetrics->SetGlyphType(glyphType);
114 // Clear the font-specific data
117 mImpl->RequestRelayout();
120 void Controller::SetMarkupProcessorEnabled(bool enable)
122 if(enable != mImpl->mMarkupProcessorEnabled)
124 //If Text was already set, call the SetText again for enabling or disabling markup
125 mImpl->mMarkupProcessorEnabled = enable;
131 mImpl->mModel->mVisualModel->SetMarkupProcessorEnabled(enable);
134 bool Controller::IsMarkupProcessorEnabled() const
136 return mImpl->mMarkupProcessorEnabled;
139 void Controller::SetAutoScrollEnabled(bool enable)
141 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);
143 if(mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)
147 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n");
148 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
157 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
158 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
165 mImpl->mIsAutoScrollEnabled = enable;
166 mImpl->RequestRelayout();
170 DALI_LOG_WARNING("Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n");
171 mImpl->mIsAutoScrollEnabled = false;
175 bool Controller::IsAutoScrollEnabled() const
177 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
191 if(mImpl->mModel->mVisualModel &&
192 (0u != mImpl->mModel->mVisualModel->mLines.Count()))
194 offset = (*mImpl->mModel->mVisualModel->mLines.Begin()).alignmentOffset;
200 void Controller::SetHorizontalScrollEnabled(bool enable)
202 if((NULL != mImpl->mEventData) &&
203 mImpl->mEventData->mDecorator)
205 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled(enable);
208 bool Controller::IsHorizontalScrollEnabled() const
210 if((NULL != mImpl->mEventData) &&
211 mImpl->mEventData->mDecorator)
213 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
219 void Controller::SetVerticalScrollEnabled(bool enable)
221 if((NULL != mImpl->mEventData) &&
222 mImpl->mEventData->mDecorator)
224 if(mImpl->mEventData->mDecorator)
226 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled(enable);
231 bool Controller::IsVerticalScrollEnabled() const
233 if((NULL != mImpl->mEventData) &&
234 mImpl->mEventData->mDecorator)
236 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
242 void Controller::SetSmoothHandlePanEnabled(bool enable)
244 if((NULL != mImpl->mEventData) &&
245 mImpl->mEventData->mDecorator)
247 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled(enable);
251 bool Controller::IsSmoothHandlePanEnabled() const
253 if((NULL != mImpl->mEventData) &&
254 mImpl->mEventData->mDecorator)
256 return 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(NULL != mImpl->mEventData)
278 mImpl->mEventData->mCursorBlinkEnabled = enable;
281 mImpl->mEventData->mDecorator)
283 mImpl->mEventData->mDecorator->StopCursorBlink();
288 bool Controller::GetEnableCursorBlink() const
290 if(NULL != mImpl->mEventData)
292 return mImpl->mEventData->mCursorBlinkEnabled;
298 void Controller::SetMultiLineEnabled(bool enable)
300 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
302 if(layout != mImpl->mLayoutEngine.GetLayout())
304 // Set the layout type.
305 mImpl->mLayoutEngine.SetLayout(layout);
307 // Set the flags to redo the layout operations
308 const OperationsMask layoutOperations = static_cast<OperationsMask>(LAYOUT |
313 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
314 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | layoutOperations);
316 // Need to recalculate natural size
317 mImpl->mRecalculateNaturalSize = true;
319 mImpl->RequestRelayout();
323 bool Controller::IsMultiLineEnabled() const
325 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
328 void Controller::SetHorizontalAlignment(Text::HorizontalAlignment::Type alignment)
330 if(alignment != mImpl->mModel->mHorizontalAlignment)
332 // Set the alignment.
333 mImpl->mModel->mHorizontalAlignment = alignment;
335 // Set the flag to redo the alignment operation.
336 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | ALIGN);
338 if(mImpl->mEventData)
340 mImpl->mEventData->mUpdateAlignment = true;
342 // Update the cursor if it's in editing mode
343 if(EventData::IsEditingState(mImpl->mEventData->mState))
345 mImpl->ChangeState(EventData::EDITING);
346 mImpl->mEventData->mUpdateCursorPosition = true;
350 mImpl->RequestRelayout();
354 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
356 return mImpl->mModel->mHorizontalAlignment;
359 void Controller::SetVerticalAlignment(VerticalAlignment::Type alignment)
361 if(alignment != mImpl->mModel->mVerticalAlignment)
363 // Set the alignment.
364 mImpl->mModel->mVerticalAlignment = alignment;
366 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | ALIGN);
368 mImpl->RequestRelayout();
372 VerticalAlignment::Type Controller::GetVerticalAlignment() const
374 return mImpl->mModel->mVerticalAlignment;
377 bool Controller::IsIgnoreSpacesAfterText() const
379 return mImpl->mModel->mIgnoreSpacesAfterText;
382 void Controller::SetIgnoreSpacesAfterText(bool ignore)
384 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
387 void Controller::ChangedLayoutDirection()
389 mImpl->mIsLayoutDirectionChanged = true;
392 void Controller::SetMatchLayoutDirection(DevelText::MatchLayoutDirection type)
394 mImpl->mModel->mMatchLayoutDirection = type;
397 DevelText::MatchLayoutDirection Controller::GetMatchLayoutDirection() const
399 return mImpl->mModel->mMatchLayoutDirection;
402 void Controller::SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection)
404 mImpl->mLayoutDirection = layoutDirection;
407 Dali::LayoutDirection::Type Controller::GetLayoutDirection(Dali::Actor& actor) const
409 if(mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::LOCALE ||
410 (mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::INHERIT && !mImpl->mIsLayoutDirectionChanged))
412 return static_cast<Dali::LayoutDirection::Type>(DevelWindow::Get(actor).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
416 return static_cast<Dali::LayoutDirection::Type>(actor.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
420 bool Controller::IsShowingRealText() const
422 return mImpl->IsShowingRealText();
425 void Controller::SetLineWrapMode(Text::LineWrap::Mode lineWrapMode)
427 if(lineWrapMode != mImpl->mModel->mLineWrapMode)
429 // Update Text layout for applying wrap mode
430 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
436 if((mImpl->mModel->mLineWrapMode == (Text::LineWrap::Mode)DevelText::LineWrap::HYPHENATION) || (lineWrapMode == (Text::LineWrap::Mode)DevelText::LineWrap::HYPHENATION) ||
437 (mImpl->mModel->mLineWrapMode == (Text::LineWrap::Mode)DevelText::LineWrap::MIXED) || (lineWrapMode == (Text::LineWrap::Mode)DevelText::LineWrap::MIXED)) // hyphen is treated as line break
439 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | GET_LINE_BREAKS);
442 // Set the text wrap mode.
443 mImpl->mModel->mLineWrapMode = lineWrapMode;
445 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
446 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
447 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
450 mImpl->RequestRelayout();
454 Text::LineWrap::Mode Controller::GetLineWrapMode() const
456 return mImpl->mModel->mLineWrapMode;
459 void Controller::SetTextElideEnabled(bool enabled)
461 mImpl->mModel->mElideEnabled = enabled;
464 bool Controller::IsTextElideEnabled() const
466 return mImpl->mModel->mElideEnabled;
469 void Controller::SetTextFitEnabled(bool enabled)
471 mImpl->mTextFitEnabled = enabled;
474 bool Controller::IsTextFitEnabled() const
476 return mImpl->mTextFitEnabled;
479 void Controller::SetTextFitMinSize(float minSize, FontSizeType type)
485 mImpl->mTextFitMinSize = minSize;
490 mImpl->mTextFitMinSize = ConvertPixelToPint(minSize);
496 float Controller::GetTextFitMinSize() const
498 return mImpl->mTextFitMinSize;
501 void Controller::SetTextFitMaxSize(float maxSize, FontSizeType type)
507 mImpl->mTextFitMaxSize = maxSize;
512 mImpl->mTextFitMaxSize = ConvertPixelToPint(maxSize);
518 float Controller::GetTextFitMaxSize() const
520 return mImpl->mTextFitMaxSize;
523 void Controller::SetTextFitStepSize(float step, FontSizeType type)
529 mImpl->mTextFitStepSize = step;
534 mImpl->mTextFitStepSize = ConvertPixelToPint(step);
540 float Controller::GetTextFitStepSize() const
542 return mImpl->mTextFitStepSize;
545 void Controller::SetTextFitContentSize(Vector2 size)
547 mImpl->mTextFitContentSize = size;
550 Vector2 Controller::GetTextFitContentSize() const
552 return mImpl->mTextFitContentSize;
555 void Controller::SetPlaceholderTextElideEnabled(bool enabled)
557 PlaceholderHandler::SetPlaceholderTextElideEnabled(*this, enabled);
560 bool Controller::IsPlaceholderTextElideEnabled() const
562 return PlaceholderHandler::IsPlaceholderTextElideEnabled(*this);
565 void Controller::SetSelectionEnabled(bool enabled)
567 mImpl->mEventData->mSelectionEnabled = enabled;
570 bool Controller::IsSelectionEnabled() const
572 return mImpl->mEventData->mSelectionEnabled;
575 void Controller::SetShiftSelectionEnabled(bool enabled)
577 mImpl->mEventData->mShiftSelectionFlag = enabled;
580 bool Controller::IsShiftSelectionEnabled() const
582 return mImpl->mEventData->mShiftSelectionFlag;
585 void Controller::SetGrabHandleEnabled(bool enabled)
587 mImpl->mEventData->mGrabHandleEnabled = enabled;
590 bool Controller::IsGrabHandleEnabled() const
592 return mImpl->mEventData->mGrabHandleEnabled;
595 void Controller::SetGrabHandlePopupEnabled(bool enabled)
597 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
600 bool Controller::IsGrabHandlePopupEnabled() const
602 return mImpl->mEventData->mGrabHandlePopupEnabled;
607 void Controller::SetText(const std::string& text)
609 TextUpdater::SetText(*this, text);
612 void Controller::GetText(std::string& text) const
614 if(!mImpl->IsShowingPlaceholderText())
616 // Retrieves the text string.
617 mImpl->GetText(0u, text);
621 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this);
625 void Controller::SetPlaceholderText(PlaceholderType type, const std::string& text)
627 PlaceholderHandler::SetPlaceholderText(*this, type, text);
630 void Controller::GetPlaceholderText(PlaceholderType type, std::string& text) const
632 PlaceholderHandler::GetPlaceholderText(*this, type, text);
635 void Controller::UpdateAfterFontChange(const std::string& newDefaultFont)
637 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
639 if(!mImpl->mFontDefaults->familyDefined) // If user defined font then should not update when system font changes
641 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str());
642 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
646 mImpl->RequestRelayout();
650 void Controller::RetrieveSelection(std::string& selectedText) const
652 mImpl->RetrieveSelection(selectedText, false);
655 void Controller::SetSelection(int start, int end)
657 mImpl->SetSelection(start, end);
660 std::pair<int, int> Controller::GetSelectionIndexes() const
662 return mImpl->GetSelectionIndexes();
665 void Controller::CopyStringToClipboard(const std::string& source)
667 mImpl->CopyStringToClipboard(source);
670 void Controller::SendSelectionToClipboard(bool deleteAfterSending)
672 mImpl->SendSelectionToClipboard(deleteAfterSending);
675 // public : Default style & Input style
677 void Controller::SetDefaultFontFamily(const std::string& defaultFontFamily)
679 if(NULL == mImpl->mFontDefaults)
681 mImpl->mFontDefaults = new FontDefaults();
684 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
685 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
686 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
688 if(mImpl->mEventData)
690 // Update the cursor position if it's in editing mode
691 if(EventData::IsEditingState(mImpl->mEventData->mState))
693 mImpl->mEventData->mDecoratorUpdated = true;
694 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font family is updated.
698 // Clear the font-specific data
701 mImpl->RequestRelayout();
704 const std::string& Controller::GetDefaultFontFamily() const
706 if(NULL != mImpl->mFontDefaults)
708 return mImpl->mFontDefaults->mFontDescription.family;
714 void Controller::SetPlaceholderFontFamily(const std::string& placeholderTextFontFamily)
716 PlaceholderHandler::SetPlaceholderFontFamily(*this, placeholderTextFontFamily);
719 const std::string& Controller::GetPlaceholderFontFamily() const
721 return PlaceholderHandler::GetPlaceholderFontFamily(*this);
724 void Controller::SetDefaultFontWeight(FontWeight weight)
726 if(NULL == mImpl->mFontDefaults)
728 mImpl->mFontDefaults = new FontDefaults();
731 mImpl->mFontDefaults->mFontDescription.weight = weight;
732 mImpl->mFontDefaults->weightDefined = true;
734 if(mImpl->mEventData)
736 // Update the cursor position if it's in editing mode
737 if(EventData::IsEditingState(mImpl->mEventData->mState))
739 mImpl->mEventData->mDecoratorUpdated = true;
740 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font weight is updated.
744 // Clear the font-specific data
747 mImpl->RequestRelayout();
750 bool Controller::IsDefaultFontWeightDefined() const
752 if(NULL != mImpl->mFontDefaults)
754 return mImpl->mFontDefaults->weightDefined;
760 FontWeight Controller::GetDefaultFontWeight() const
762 if(NULL != mImpl->mFontDefaults)
764 return mImpl->mFontDefaults->mFontDescription.weight;
767 return TextAbstraction::FontWeight::NORMAL;
770 void Controller::SetPlaceholderTextFontWeight(FontWeight weight)
772 PlaceholderHandler::SetPlaceholderTextFontWeight(*this, weight);
775 bool Controller::IsPlaceholderTextFontWeightDefined() const
777 return PlaceholderHandler::IsPlaceholderTextFontWeightDefined(*this);
781 FontWeight Controller::GetPlaceholderTextFontWeight() const
783 return PlaceholderHandler::GetPlaceholderTextFontWeight(*this);
786 void Controller::SetDefaultFontWidth(FontWidth width)
788 if(NULL == mImpl->mFontDefaults)
790 mImpl->mFontDefaults = new FontDefaults();
793 mImpl->mFontDefaults->mFontDescription.width = width;
794 mImpl->mFontDefaults->widthDefined = true;
796 if(mImpl->mEventData)
798 // Update the cursor position if it's in editing mode
799 if(EventData::IsEditingState(mImpl->mEventData->mState))
801 mImpl->mEventData->mDecoratorUpdated = true;
802 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font width is updated.
806 // Clear the font-specific data
809 mImpl->RequestRelayout();
812 bool Controller::IsDefaultFontWidthDefined() const
814 if(NULL != mImpl->mFontDefaults)
816 return mImpl->mFontDefaults->widthDefined;
822 FontWidth Controller::GetDefaultFontWidth() const
824 if(NULL != mImpl->mFontDefaults)
826 return mImpl->mFontDefaults->mFontDescription.width;
829 return TextAbstraction::FontWidth::NORMAL;
832 void Controller::SetPlaceholderTextFontWidth(FontWidth width)
834 PlaceholderHandler::SetPlaceholderTextFontWidth(*this, width);
837 bool Controller::IsPlaceholderTextFontWidthDefined() const
839 return PlaceholderHandler::IsPlaceholderTextFontWidthDefined(*this);
842 FontWidth Controller::GetPlaceholderTextFontWidth() const
844 return PlaceholderHandler::GetPlaceholderTextFontWidth(*this);
847 void Controller::SetDefaultFontSlant(FontSlant slant)
849 if(NULL == mImpl->mFontDefaults)
851 mImpl->mFontDefaults = new FontDefaults();
854 mImpl->mFontDefaults->mFontDescription.slant = slant;
855 mImpl->mFontDefaults->slantDefined = true;
857 if(mImpl->mEventData)
859 // Update the cursor position if it's in editing mode
860 if(EventData::IsEditingState(mImpl->mEventData->mState))
862 mImpl->mEventData->mDecoratorUpdated = true;
863 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font slant is updated.
867 // Clear the font-specific data
870 mImpl->RequestRelayout();
873 bool Controller::IsDefaultFontSlantDefined() const
875 if(NULL != mImpl->mFontDefaults)
877 return mImpl->mFontDefaults->slantDefined;
882 FontSlant Controller::GetDefaultFontSlant() const
884 if(NULL != mImpl->mFontDefaults)
886 return mImpl->mFontDefaults->mFontDescription.slant;
889 return TextAbstraction::FontSlant::NORMAL;
892 void Controller::SetPlaceholderTextFontSlant(FontSlant slant)
894 PlaceholderHandler::SetPlaceholderTextFontSlant(*this, slant);
897 bool Controller::IsPlaceholderTextFontSlantDefined() const
899 return PlaceholderHandler::IsPlaceholderTextFontSlantDefined(*this);
902 FontSlant Controller::GetPlaceholderTextFontSlant() const
904 return PlaceholderHandler::GetPlaceholderTextFontSlant(*this);
907 void Controller::SetFontSizeScale(float scale)
909 mImpl->mFontSizeScale = scale;
911 if(mImpl->mEventData)
913 // Update the cursor position if it's in editing mode
914 if(EventData::IsEditingState(mImpl->mEventData->mState))
916 mImpl->mEventData->mDecoratorUpdated = true;
917 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
921 // Clear the font-specific data
924 mImpl->RequestRelayout();
927 float Controller::GetFontSizeScale() const
929 if(nullptr != mImpl->mFontDefaults)
931 return mImpl->mFontSizeScale;
937 void Controller::SetDefaultFontSize(float fontSize, FontSizeType type)
939 if(NULL == mImpl->mFontDefaults)
941 mImpl->mFontDefaults = new FontDefaults();
948 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
949 mImpl->mFontDefaults->sizeDefined = true;
954 // Point size = Pixel size * 72.f / DPI
955 unsigned int horizontalDpi = 0u;
956 unsigned int verticalDpi = 0u;
957 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
958 fontClient.GetDpi(horizontalDpi, verticalDpi);
960 mImpl->mFontDefaults->mDefaultPointSize = (fontSize * 72.f) / static_cast<float>(horizontalDpi);
961 mImpl->mFontDefaults->sizeDefined = true;
966 if(mImpl->mEventData)
968 // Update the cursor position if it's in editing mode
969 if(EventData::IsEditingState(mImpl->mEventData->mState))
971 mImpl->mEventData->mDecoratorUpdated = true;
972 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
976 // Clear the font-specific data
979 mImpl->RequestRelayout();
982 float Controller::GetDefaultFontSize(FontSizeType type) const
985 if(NULL != mImpl->mFontDefaults)
991 value = mImpl->mFontDefaults->mDefaultPointSize;
996 // Pixel size = Point size * DPI / 72.f
997 unsigned int horizontalDpi = 0u;
998 unsigned int verticalDpi = 0u;
999 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1000 fontClient.GetDpi(horizontalDpi, verticalDpi);
1002 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast<float>(horizontalDpi) / 72.f;
1012 void Controller::SetPlaceholderTextFontSize(float fontSize, FontSizeType type)
1014 PlaceholderHandler::SetPlaceholderTextFontSize(*this, fontSize, type);
1017 float Controller::GetPlaceholderTextFontSize(FontSizeType type) const
1019 return PlaceholderHandler::GetPlaceholderTextFontSize(*this, type);
1022 void Controller::SetDefaultColor(const Vector4& color)
1024 mImpl->mTextColor = color;
1026 if(!mImpl->IsShowingPlaceholderText())
1028 mImpl->mModel->mVisualModel->SetTextColor(color);
1030 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1032 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | COLOR);
1034 mImpl->RequestRelayout();
1038 const Vector4& Controller::GetDefaultColor() const
1040 return mImpl->mTextColor;
1043 void Controller::SetPlaceholderTextColor(const Vector4& textColor)
1045 PlaceholderHandler::SetPlaceholderTextColor(*this, textColor);
1048 const Vector4& Controller::GetPlaceholderTextColor() const
1050 return PlaceholderHandler::GetPlaceholderTextColor(*this);
1053 void Controller::SetShadowOffset(const Vector2& shadowOffset)
1055 mImpl->mModel->mVisualModel->SetShadowOffset(shadowOffset);
1057 mImpl->RequestRelayout();
1060 const Vector2& Controller::GetShadowOffset() const
1062 return mImpl->mModel->mVisualModel->GetShadowOffset();
1065 void Controller::SetShadowColor(const Vector4& shadowColor)
1067 mImpl->mModel->mVisualModel->SetShadowColor(shadowColor);
1069 mImpl->RequestRelayout();
1072 const Vector4& Controller::GetShadowColor() const
1074 return mImpl->mModel->mVisualModel->GetShadowColor();
1077 void Controller::SetShadowBlurRadius(const float& shadowBlurRadius)
1079 if(fabsf(GetShadowBlurRadius() - shadowBlurRadius) > Math::MACHINE_EPSILON_1)
1081 mImpl->mModel->mVisualModel->SetShadowBlurRadius(shadowBlurRadius);
1083 mImpl->RequestRelayout();
1087 const float& Controller::GetShadowBlurRadius() const
1089 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1092 void Controller::SetUnderlineColor(const Vector4& color)
1094 mImpl->mModel->mVisualModel->SetUnderlineColor(color);
1096 mImpl->RequestRelayout();
1099 const Vector4& Controller::GetUnderlineColor() const
1101 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1104 void Controller::SetUnderlineEnabled(bool enabled)
1106 mImpl->mModel->mVisualModel->SetUnderlineEnabled(enabled);
1108 mImpl->RequestRelayout();
1111 bool Controller::IsUnderlineEnabled() const
1113 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1116 void Controller::SetUnderlineHeight(float height)
1118 mImpl->mModel->mVisualModel->SetUnderlineHeight(height);
1120 mImpl->RequestRelayout();
1123 float Controller::GetUnderlineHeight() const
1125 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1128 void Controller::SetOutlineColor(const Vector4& color)
1130 mImpl->mModel->mVisualModel->SetOutlineColor(color);
1132 mImpl->RequestRelayout();
1135 const Vector4& Controller::GetOutlineColor() const
1137 return mImpl->mModel->mVisualModel->GetOutlineColor();
1140 void Controller::SetOutlineWidth(uint16_t width)
1142 mImpl->mModel->mVisualModel->SetOutlineWidth(width);
1144 mImpl->RequestRelayout();
1147 uint16_t Controller::GetOutlineWidth() const
1149 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1152 void Controller::SetBackgroundColor(const Vector4& color)
1154 mImpl->mModel->mVisualModel->SetBackgroundColor(color);
1156 mImpl->RequestRelayout();
1159 const Vector4& Controller::GetBackgroundColor() const
1161 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1164 void Controller::SetBackgroundEnabled(bool enabled)
1166 mImpl->mModel->mVisualModel->SetBackgroundEnabled(enabled);
1168 mImpl->RequestRelayout();
1171 bool Controller::IsBackgroundEnabled() const
1173 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1176 void Controller::SetDefaultEmbossProperties(const std::string& embossProperties)
1178 if(NULL == mImpl->mEmbossDefaults)
1180 mImpl->mEmbossDefaults = new EmbossDefaults();
1183 mImpl->mEmbossDefaults->properties = embossProperties;
1186 const std::string& Controller::GetDefaultEmbossProperties() const
1188 if(NULL != mImpl->mEmbossDefaults)
1190 return mImpl->mEmbossDefaults->properties;
1193 return EMPTY_STRING;
1196 void Controller::SetDefaultOutlineProperties(const std::string& outlineProperties)
1198 if(NULL == mImpl->mOutlineDefaults)
1200 mImpl->mOutlineDefaults = new OutlineDefaults();
1203 mImpl->mOutlineDefaults->properties = outlineProperties;
1206 const std::string& Controller::GetDefaultOutlineProperties() const
1208 if(NULL != mImpl->mOutlineDefaults)
1210 return mImpl->mOutlineDefaults->properties;
1213 return EMPTY_STRING;
1216 bool Controller::SetDefaultLineSpacing(float lineSpacing)
1218 if(std::fabs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000)
1220 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1221 mImpl->mRecalculateNaturalSize = true;
1227 float Controller::GetDefaultLineSpacing() const
1229 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1232 bool Controller::SetDefaultLineSize(float lineSize)
1234 if(std::fabs(lineSize - mImpl->mLayoutEngine.GetDefaultLineSize()) > Math::MACHINE_EPSILON_1000)
1236 mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
1237 mImpl->mRecalculateNaturalSize = true;
1243 float Controller::GetDefaultLineSize() const
1245 return mImpl->mLayoutEngine.GetDefaultLineSize();
1248 void Controller::SetInputColor(const Vector4& color)
1250 if(NULL != mImpl->mEventData)
1252 mImpl->mEventData->mInputStyle.textColor = color;
1253 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1255 if(EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState)
1257 if(EventData::SELECTING == mImpl->mEventData->mState)
1259 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1261 // Get start and end position of selection
1262 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1263 const Length lengthOfSelectedText = (handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition) - startOfSelectedText;
1265 // Add the color run.
1266 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1267 mImpl->mModel->mLogicalModel->mColorRuns.Resize(numberOfRuns + 1u);
1269 ColorRun& colorRun = *(mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns);
1270 colorRun.color = color;
1271 colorRun.characterRun.characterIndex = startOfSelectedText;
1272 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1274 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1275 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1276 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1280 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1281 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1282 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1285 // Request to relayout.
1286 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | COLOR);
1287 mImpl->RequestRelayout();
1292 const Vector4& Controller::GetInputColor() const
1294 if(NULL != mImpl->mEventData)
1296 return mImpl->mEventData->mInputStyle.textColor;
1299 // Return the default text's color if there is no EventData.
1300 return mImpl->mTextColor;
1303 void Controller::SetInputFontFamily(const std::string& fontFamily)
1305 InputFontHandler::SetInputFontFamily(*this, fontFamily);
1308 const std::string& Controller::GetInputFontFamily() const
1310 return InputFontHandler::GetInputFontFamily(*this);
1313 void Controller::SetInputFontWeight(FontWeight weight)
1315 InputFontHandler::SetInputFontWeight(*this, weight);
1318 bool Controller::IsInputFontWeightDefined() const
1320 return InputFontHandler::IsInputFontWeightDefined(*this);
1323 FontWeight Controller::GetInputFontWeight() const
1325 return InputFontHandler::GetInputFontWeight(*this);
1328 void Controller::SetInputFontWidth(FontWidth width)
1330 InputFontHandler::SetInputFontWidth(*this, width);
1333 bool Controller::IsInputFontWidthDefined() const
1335 return InputFontHandler::IsInputFontWidthDefined(*this);
1338 FontWidth Controller::GetInputFontWidth() const
1340 return InputFontHandler::GetInputFontWidth(*this);
1343 void Controller::SetInputFontSlant(FontSlant slant)
1345 InputFontHandler::SetInputFontSlant(*this, slant);
1348 bool Controller::IsInputFontSlantDefined() const
1350 return InputFontHandler::IsInputFontSlantDefined(*this);
1353 FontSlant Controller::GetInputFontSlant() const
1355 return InputFontHandler::GetInputFontSlant(*this);
1358 void Controller::SetInputFontPointSize(float size)
1360 InputFontHandler::SetInputFontPointSize(*this, size);
1363 float Controller::GetInputFontPointSize() const
1365 return InputFontHandler::GetInputFontPointSize(*this);
1368 void Controller::SetInputLineSpacing(float lineSpacing)
1370 if(NULL != mImpl->mEventData)
1372 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1373 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1377 float Controller::GetInputLineSpacing() const
1379 if(NULL != mImpl->mEventData)
1381 return mImpl->mEventData->mInputStyle.lineSpacing;
1387 void Controller::SetInputShadowProperties(const std::string& shadowProperties)
1389 if(NULL != mImpl->mEventData)
1391 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1395 const std::string& Controller::GetInputShadowProperties() const
1397 if(NULL != mImpl->mEventData)
1399 return mImpl->mEventData->mInputStyle.shadowProperties;
1402 return EMPTY_STRING;
1405 void Controller::SetInputUnderlineProperties(const std::string& underlineProperties)
1407 if(NULL != mImpl->mEventData)
1409 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1413 const std::string& Controller::GetInputUnderlineProperties() const
1415 if(NULL != mImpl->mEventData)
1417 return mImpl->mEventData->mInputStyle.underlineProperties;
1420 return EMPTY_STRING;
1423 void Controller::SetInputEmbossProperties(const std::string& embossProperties)
1425 if(NULL != mImpl->mEventData)
1427 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1431 const std::string& Controller::GetInputEmbossProperties() const
1433 if(NULL != mImpl->mEventData)
1435 return mImpl->mEventData->mInputStyle.embossProperties;
1438 return GetDefaultEmbossProperties();
1441 void Controller::SetInputOutlineProperties(const std::string& outlineProperties)
1443 if(NULL != mImpl->mEventData)
1445 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1449 const std::string& Controller::GetInputOutlineProperties() const
1451 if(NULL != mImpl->mEventData)
1453 return mImpl->mEventData->mInputStyle.outlineProperties;
1456 return GetDefaultOutlineProperties();
1459 void Controller::SetInputModePassword(bool passwordInput)
1461 if(NULL != mImpl->mEventData)
1463 mImpl->mEventData->mPasswordInput = passwordInput;
1467 bool Controller::IsInputModePassword()
1469 if(NULL != mImpl->mEventData)
1471 return mImpl->mEventData->mPasswordInput;
1476 void Controller::SetNoTextDoubleTapAction(NoTextTap::Action action)
1478 if(NULL != mImpl->mEventData)
1480 mImpl->mEventData->mDoubleTapAction = action;
1484 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1486 NoTextTap::Action action = NoTextTap::NO_ACTION;
1488 if(NULL != mImpl->mEventData)
1490 action = mImpl->mEventData->mDoubleTapAction;
1496 void Controller::SetNoTextLongPressAction(NoTextTap::Action action)
1498 if(NULL != mImpl->mEventData)
1500 mImpl->mEventData->mLongPressAction = action;
1504 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1506 NoTextTap::Action action = NoTextTap::NO_ACTION;
1508 if(NULL != mImpl->mEventData)
1510 action = mImpl->mEventData->mLongPressAction;
1516 bool Controller::IsUnderlineSetByString()
1518 return mImpl->mUnderlineSetByString;
1521 void Controller::UnderlineSetByString(bool setByString)
1523 mImpl->mUnderlineSetByString = setByString;
1526 bool Controller::IsShadowSetByString()
1528 return mImpl->mShadowSetByString;
1531 void Controller::ShadowSetByString(bool setByString)
1533 mImpl->mShadowSetByString = setByString;
1536 bool Controller::IsOutlineSetByString()
1538 return mImpl->mOutlineSetByString;
1541 void Controller::OutlineSetByString(bool setByString)
1543 mImpl->mOutlineSetByString = setByString;
1546 bool Controller::IsFontStyleSetByString()
1548 return mImpl->mFontStyleSetByString;
1551 void Controller::FontStyleSetByString(bool setByString)
1553 mImpl->mFontStyleSetByString = setByString;
1556 // public : Queries & retrieves.
1558 Layout::Engine& Controller::GetLayoutEngine()
1560 return mImpl->mLayoutEngine;
1563 View& Controller::GetView()
1565 return mImpl->mView;
1568 Vector3 Controller::GetNaturalSize()
1570 return Relayouter::GetNaturalSize(*this);
1573 bool Controller::CheckForTextFit(float pointSize, Size& layoutSize)
1575 return Relayouter::CheckForTextFit(*this, pointSize, layoutSize);
1578 void Controller::FitPointSizeforLayout(Size layoutSize)
1580 Relayouter::FitPointSizeforLayout(*this, layoutSize);
1583 float Controller::GetHeightForWidth(float width)
1585 return Relayouter::GetHeightForWidth(*this, width);
1588 int Controller::GetLineCount(float width)
1590 GetHeightForWidth(width);
1591 int numberofLines = mImpl->mModel->GetNumberOfLines();
1592 return numberofLines;
1595 const ModelInterface* const Controller::GetTextModel() const
1597 return mImpl->mModel.Get();
1600 float Controller::GetScrollAmountByUserInput()
1602 float scrollAmount = 0.0f;
1604 if(NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1606 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1607 mImpl->mEventData->mCheckScrollAmount = false;
1609 return scrollAmount;
1612 bool Controller::GetTextScrollInfo(float& scrollPosition, float& controlHeight, float& layoutHeight)
1614 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1617 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1618 layoutHeight = layout.height;
1619 scrollPosition = mImpl->mModel->mScrollPosition.y;
1620 isScrolled = !Equals(mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1);
1624 void Controller::SetHiddenInputOption(const Property::Map& options)
1626 if(NULL == mImpl->mHiddenInput)
1628 mImpl->mHiddenInput = new HiddenText(this);
1630 mImpl->mHiddenInput->SetProperties(options);
1633 void Controller::GetHiddenInputOption(Property::Map& options)
1635 if(NULL != mImpl->mHiddenInput)
1637 mImpl->mHiddenInput->GetProperties(options);
1641 void Controller::SetInputFilterOption(const Property::Map& options)
1643 if(!mImpl->mInputFilter)
1645 mImpl->mInputFilter = std::unique_ptr<InputFilter>(new InputFilter());
1647 mImpl->mInputFilter->SetProperties(options);
1650 void Controller::GetInputFilterOption(Property::Map& options)
1652 if(NULL != mImpl->mInputFilter)
1654 mImpl->mInputFilter->GetProperties(options);
1658 void Controller::SetPlaceholderProperty(const Property::Map& map)
1660 PlaceholderHandler::SetPlaceholderProperty(*this, map);
1663 void Controller::GetPlaceholderProperty(Property::Map& map)
1665 PlaceholderHandler::GetPlaceholderProperty(*this, map);
1668 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
1670 // Make sure the model is up-to-date before layouting
1671 ProcessModifyEvents();
1673 if(mImpl->mUpdateTextDirection)
1675 // Operations that can be done only once until the text changes.
1676 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>(CONVERT_TO_UTF32 |
1684 // Set the update info to relayout the whole text.
1685 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1686 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1688 // Make sure the model is up-to-date before layouting
1689 mImpl->UpdateModel(onlyOnceOperations);
1691 Vector3 naturalSize;
1692 DoRelayout(Size(MAX_FLOAT, MAX_FLOAT),
1693 static_cast<OperationsMask>(onlyOnceOperations |
1694 LAYOUT | REORDER | UPDATE_DIRECTION),
1695 naturalSize.GetVectorXY());
1697 // Do not do again the only once operations.
1698 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending & ~onlyOnceOperations);
1700 // Clear the update info. This info will be set the next time the text is updated.
1701 mImpl->mTextUpdateInfo.Clear();
1703 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
1704 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1706 mImpl->mUpdateTextDirection = false;
1709 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
1712 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
1714 return mImpl->mModel->GetVerticalLineAlignment();
1717 void Controller::SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment)
1719 mImpl->mModel->mVerticalLineAlignment = alignment;
1722 // public : Relayout.
1724 Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection)
1726 return Relayouter::Relayout(*this, size, layoutDirection);
1729 void Controller::RequestRelayout()
1731 mImpl->RequestRelayout();
1734 // public : Input style change signals.
1736 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1738 return (NULL == mImpl->mEventData) || (0u == mImpl->mEventData->mInputStyleChangedQueue.Count());
1741 void Controller::ProcessInputStyleChangedSignals()
1743 if(NULL == mImpl->mEventData)
1749 for(Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
1750 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
1754 const InputStyle::Mask mask = *it;
1756 if(NULL != mImpl->mEditableControlInterface)
1758 // Emit the input style changed signal.
1759 mImpl->mEditableControlInterface->InputStyleChanged(mask);
1763 mImpl->mEventData->mInputStyleChangedQueue.Clear();
1766 // public : Text-input Event Queuing.
1768 void Controller::KeyboardFocusGainEvent()
1770 EventHandler::KeyboardFocusGainEvent(*this);
1773 void Controller::KeyboardFocusLostEvent()
1775 EventHandler::KeyboardFocusLostEvent(*this);
1778 bool Controller::KeyEvent(const Dali::KeyEvent& keyEvent)
1780 return EventHandler::KeyEvent(*this, keyEvent);
1783 void Controller::AnchorEvent(float x, float y)
1785 EventHandler::AnchorEvent(*this, x, y);
1788 void Controller::TapEvent(unsigned int tapCount, float x, float y)
1790 EventHandler::TapEvent(*this, tapCount, x, y);
1793 void Controller::PanEvent(GestureState state, const Vector2& displacement)
1795 EventHandler::PanEvent(*this, state, displacement);
1798 void Controller::LongPressEvent(GestureState state, float x, float y)
1800 EventHandler::LongPressEvent(*this, state, x, y);
1803 void Controller::SelectEvent(float x, float y, SelectionType selectType)
1805 EventHandler::SelectEvent(*this, x, y, selectType);
1808 void Controller::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1810 if(mImpl->mEventData)
1812 mImpl->mEventData->mCheckScrollAmount = true;
1813 mImpl->mEventData->mIsLeftHandleSelected = true;
1814 mImpl->mEventData->mIsRightHandleSelected = true;
1815 mImpl->SetTextSelectionRange(start, end);
1816 mImpl->RequestRelayout();
1817 KeyboardFocusGainEvent();
1821 Uint32Pair Controller::GetTextSelectionRange() const
1823 return mImpl->GetTextSelectionRange();
1826 CharacterIndex Controller::GetPrimaryCursorPosition() const
1828 return mImpl->GetPrimaryCursorPosition();
1831 bool Controller::SetPrimaryCursorPosition(CharacterIndex index)
1833 if(mImpl->mEventData)
1835 mImpl->mEventData->mCheckScrollAmount = true;
1836 mImpl->mEventData->mIsLeftHandleSelected = true;
1837 mImpl->mEventData->mIsRightHandleSelected = true;
1838 mImpl->mEventData->mCheckScrollAmount = true;
1839 if(mImpl->SetPrimaryCursorPosition(index))
1841 KeyboardFocusGainEvent();
1848 void Controller::SelectWholeText()
1850 SelectEvent(0.f, 0.f, SelectionType::ALL);
1853 void Controller::SelectNone()
1855 SelectEvent(0.f, 0.f, SelectionType::NONE);
1858 string Controller::GetSelectedText() const
1861 if(EventData::SELECTING == mImpl->mEventData->mState)
1863 mImpl->RetrieveSelection(text, false);
1868 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1870 return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent);
1873 void Controller::PasteClipboardItemEvent()
1875 EventHandler::PasteClipboardItemEvent(*this);
1878 // protected : Inherit from Text::Decorator::ControllerInterface.
1880 void Controller::GetTargetSize(Vector2& targetSize)
1882 targetSize = mImpl->mModel->mVisualModel->mControlSize;
1885 void Controller::AddDecoration(Actor& actor, bool needsClipping)
1887 if(NULL != mImpl->mEditableControlInterface)
1889 mImpl->mEditableControlInterface->AddDecoration(actor, needsClipping);
1893 bool Controller::IsEditable() const
1895 return mImpl->IsEditable();
1898 void Controller::SetEditable(bool editable)
1900 mImpl->SetEditable(editable);
1901 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
1903 mImpl->mEventData->mDecorator->SetEditable(editable);
1907 void Controller::ScrollBy(Vector2 scroll)
1909 if(mImpl->mEventData && (fabs(scroll.x) > Math::MACHINE_EPSILON_0 || fabs(scroll.y) > Math::MACHINE_EPSILON_0))
1911 const Vector2& layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1912 const Vector2 currentScroll = mImpl->mModel->mScrollPosition;
1914 scroll.x = -scroll.x;
1915 scroll.y = -scroll.y;
1917 if(fabs(scroll.x) > Math::MACHINE_EPSILON_0)
1919 mImpl->mModel->mScrollPosition.x += scroll.x;
1920 mImpl->ClampHorizontalScroll(layoutSize);
1923 if(fabs(scroll.y) > Math::MACHINE_EPSILON_0)
1925 mImpl->mModel->mScrollPosition.y += scroll.y;
1926 mImpl->ClampVerticalScroll(layoutSize);
1929 if(mImpl->mModel->mScrollPosition != currentScroll)
1931 mImpl->mEventData->mDecorator->UpdatePositions(mImpl->mModel->mScrollPosition - currentScroll);
1932 mImpl->RequestRelayout();
1937 float Controller::GetHorizontalScrollPosition()
1939 if(mImpl->mEventData)
1941 //scroll values are negative internally so we convert them to positive numbers
1942 return -mImpl->mModel->mScrollPosition.x;
1947 float Controller::GetVerticalScrollPosition()
1949 if(mImpl->mEventData)
1951 //scroll values are negative internally so we convert them to positive numbers
1952 return -mImpl->mModel->mScrollPosition.y;
1957 void Controller::DecorationEvent(HandleType handleType, HandleState state, float x, float y)
1959 EventHandler::DecorationEvent(*this, handleType, state, x, y);
1962 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
1964 void Controller::TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button)
1966 EventHandler::TextPopupButtonTouched(*this, button);
1969 void Controller::DisplayTimeExpired()
1971 mImpl->mEventData->mUpdateCursorPosition = true;
1972 // Apply modifications to the model
1973 mImpl->mOperationsPending = ALL_OPERATIONS;
1975 mImpl->RequestRelayout();
1978 // private : Update.
1980 void Controller::InsertText(const std::string& text, Controller::InsertType type)
1982 TextUpdater::InsertText(*this, text, type);
1985 void Controller::PasteText(const std::string& stringToPaste)
1987 TextUpdater::PasteText(*this, stringToPaste);
1990 bool Controller::RemoveText(int cursorOffset,
1991 int numberOfCharacters,
1992 UpdateInputStyleType type)
1994 return TextUpdater::RemoveText(*this, cursorOffset, numberOfCharacters, type);
1997 bool Controller::RemoveSelectedText()
1999 return TextUpdater::RemoveSelectedText(*this);
2002 void Controller::InsertTextAnchor(int numberOfCharacters,
2003 CharacterIndex previousCursorIndex)
2005 TextUpdater::InsertTextAnchor(*this, numberOfCharacters, previousCursorIndex);
2008 void Controller::RemoveTextAnchor(int cursorOffset,
2009 int numberOfCharacters,
2010 CharacterIndex previousCursorIndex)
2012 TextUpdater::RemoveTextAnchor(*this, cursorOffset, numberOfCharacters, previousCursorIndex);
2015 // private : Relayout.
2017 bool Controller::DoRelayout(const Size& size,
2018 OperationsMask operationsRequired,
2021 return Relayouter::DoRelayout(*this, size, operationsRequired, layoutSize);
2024 void Controller::CalculateVerticalOffset(const Size& controlSize)
2026 Relayouter::CalculateVerticalOffset(*this, controlSize);
2029 // private : Events.
2031 void Controller::ProcessModifyEvents()
2033 EventHandler::ProcessModifyEvents(*this);
2036 void Controller::TextReplacedEvent()
2038 EventHandler::TextReplacedEvent(*this);
2041 void Controller::TextInsertedEvent()
2043 EventHandler::TextInsertedEvent(*this);
2046 void Controller::TextDeletedEvent()
2048 EventHandler::TextDeletedEvent(*this);
2051 bool Controller::DeleteEvent(int keyCode)
2053 return EventHandler::DeleteEvent(*this, keyCode);
2056 // private : Helpers.
2058 void Controller::ResetText()
2060 TextUpdater::ResetText(*this);
2063 void Controller::ShowPlaceholderText()
2065 PlaceholderHandler::ShowPlaceholderText(*this);
2068 void Controller::ClearFontData()
2070 if(mImpl->mFontDefaults)
2072 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
2075 // Set flags to update the model.
2076 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2077 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2078 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2080 mImpl->mTextUpdateInfo.mClearAll = true;
2081 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2082 mImpl->mRecalculateNaturalSize = true;
2084 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
2090 UPDATE_LAYOUT_SIZE |
2095 void Controller::ClearStyleData()
2097 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
2098 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
2101 void Controller::ResetCursorPosition(CharacterIndex cursorIndex)
2103 // Reset the cursor position
2104 if(NULL != mImpl->mEventData)
2106 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
2108 // Update the cursor if it's in editing mode.
2109 if(EventData::IsEditingState(mImpl->mEventData->mState))
2111 mImpl->mEventData->mUpdateCursorPosition = true;
2116 CharacterIndex Controller::GetCursorPosition()
2118 if(!mImpl->mEventData)
2121 return mImpl->mEventData->mPrimaryCursorPosition;
2124 void Controller::ResetScrollPosition()
2126 if(NULL != mImpl->mEventData)
2128 // Reset the scroll position.
2129 mImpl->mModel->mScrollPosition = Vector2::ZERO;
2130 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2134 void Controller::SetControlInterface(ControlInterface* controlInterface)
2136 mImpl->mControlInterface = controlInterface;
2139 void Controller::SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface)
2141 mImpl->mAnchorControlInterface = anchorControlInterface;
2144 bool Controller::ShouldClearFocusOnEscape() const
2146 return mImpl->mShouldClearFocusOnEscape;
2149 Actor Controller::CreateBackgroundActor()
2151 return mImpl->CreateBackgroundActor();
2154 // private : Private contructors & copy operator.
2156 Controller::Controller()
2157 : Controller(nullptr, nullptr, nullptr, nullptr)
2161 Controller::Controller(ControlInterface* controlInterface)
2162 : Controller(controlInterface, nullptr, nullptr, nullptr)
2166 Controller::Controller(ControlInterface* controlInterface,
2167 EditableControlInterface* editableControlInterface,
2168 SelectableControlInterface* selectableControlInterface,
2169 AnchorControlInterface* anchorControlInterface)
2170 : mImpl(new Controller::Impl(controlInterface, editableControlInterface, selectableControlInterface, anchorControlInterface))
2174 // The copy constructor and operator are left unimplemented.
2176 // protected : Destructor.
2178 Controller::~Controller()
2185 } // namespace Toolkit