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;
462 mImpl->mModel->mVisualModel->SetTextElideEnabled(enabled);
465 bool Controller::IsTextElideEnabled() const
467 return mImpl->mModel->mElideEnabled;
470 void Controller::SetTextFitEnabled(bool enabled)
472 mImpl->mTextFitEnabled = enabled;
475 bool Controller::IsTextFitEnabled() const
477 return mImpl->mTextFitEnabled;
480 void Controller::SetTextFitMinSize(float minSize, FontSizeType type)
486 mImpl->mTextFitMinSize = minSize;
491 mImpl->mTextFitMinSize = ConvertPixelToPint(minSize);
497 float Controller::GetTextFitMinSize() const
499 return mImpl->mTextFitMinSize;
502 void Controller::SetTextFitMaxSize(float maxSize, FontSizeType type)
508 mImpl->mTextFitMaxSize = maxSize;
513 mImpl->mTextFitMaxSize = ConvertPixelToPint(maxSize);
519 float Controller::GetTextFitMaxSize() const
521 return mImpl->mTextFitMaxSize;
524 void Controller::SetTextFitStepSize(float step, FontSizeType type)
530 mImpl->mTextFitStepSize = step;
535 mImpl->mTextFitStepSize = ConvertPixelToPint(step);
541 float Controller::GetTextFitStepSize() const
543 return mImpl->mTextFitStepSize;
546 void Controller::SetTextFitContentSize(Vector2 size)
548 mImpl->mTextFitContentSize = size;
551 Vector2 Controller::GetTextFitContentSize() const
553 return mImpl->mTextFitContentSize;
556 void Controller::SetPlaceholderTextElideEnabled(bool enabled)
558 PlaceholderHandler::SetPlaceholderTextElideEnabled(*this, enabled);
561 bool Controller::IsPlaceholderTextElideEnabled() const
563 return PlaceholderHandler::IsPlaceholderTextElideEnabled(*this);
566 void Controller::SetSelectionEnabled(bool enabled)
568 mImpl->mEventData->mSelectionEnabled = enabled;
571 bool Controller::IsSelectionEnabled() const
573 return mImpl->mEventData->mSelectionEnabled;
576 void Controller::SetShiftSelectionEnabled(bool enabled)
578 mImpl->mEventData->mShiftSelectionFlag = enabled;
581 bool Controller::IsShiftSelectionEnabled() const
583 return mImpl->mEventData->mShiftSelectionFlag;
586 void Controller::SetGrabHandleEnabled(bool enabled)
588 mImpl->mEventData->mGrabHandleEnabled = enabled;
591 bool Controller::IsGrabHandleEnabled() const
593 return mImpl->mEventData->mGrabHandleEnabled;
596 void Controller::SetGrabHandlePopupEnabled(bool enabled)
598 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
601 bool Controller::IsGrabHandlePopupEnabled() const
603 return mImpl->mEventData->mGrabHandlePopupEnabled;
608 void Controller::SetText(const std::string& text)
610 TextUpdater::SetText(*this, text);
613 void Controller::GetText(std::string& text) const
615 if(!mImpl->IsShowingPlaceholderText())
617 // Retrieves the text string.
618 mImpl->GetText(0u, text);
622 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this);
626 void Controller::SetPlaceholderText(PlaceholderType type, const std::string& text)
628 PlaceholderHandler::SetPlaceholderText(*this, type, text);
631 void Controller::GetPlaceholderText(PlaceholderType type, std::string& text) const
633 PlaceholderHandler::GetPlaceholderText(*this, type, text);
636 void Controller::UpdateAfterFontChange(const std::string& newDefaultFont)
638 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
640 if(!mImpl->mFontDefaults->familyDefined) // If user defined font then should not update when system font changes
642 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str());
643 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
647 mImpl->RequestRelayout();
651 void Controller::RetrieveSelection(std::string& selectedText) const
653 mImpl->RetrieveSelection(selectedText, false);
656 void Controller::SetSelection(int start, int end)
658 mImpl->SetSelection(start, end);
661 std::pair<int, int> Controller::GetSelectionIndexes() const
663 return mImpl->GetSelectionIndexes();
666 void Controller::CopyStringToClipboard(const std::string& source)
668 mImpl->CopyStringToClipboard(source);
671 void Controller::SendSelectionToClipboard(bool deleteAfterSending)
673 mImpl->SendSelectionToClipboard(deleteAfterSending);
676 // public : Default style & Input style
678 void Controller::SetDefaultFontFamily(const std::string& defaultFontFamily)
680 if(NULL == mImpl->mFontDefaults)
682 mImpl->mFontDefaults = new FontDefaults();
685 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
686 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
687 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
689 if(mImpl->mEventData)
691 // Update the cursor position if it's in editing mode
692 if(EventData::IsEditingState(mImpl->mEventData->mState))
694 mImpl->mEventData->mDecoratorUpdated = true;
695 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font family is updated.
699 // Clear the font-specific data
702 mImpl->RequestRelayout();
705 const std::string& Controller::GetDefaultFontFamily() const
707 if(NULL != mImpl->mFontDefaults)
709 return mImpl->mFontDefaults->mFontDescription.family;
715 void Controller::SetPlaceholderFontFamily(const std::string& placeholderTextFontFamily)
717 PlaceholderHandler::SetPlaceholderFontFamily(*this, placeholderTextFontFamily);
720 const std::string& Controller::GetPlaceholderFontFamily() const
722 return PlaceholderHandler::GetPlaceholderFontFamily(*this);
725 void Controller::SetDefaultFontWeight(FontWeight weight)
727 if(NULL == mImpl->mFontDefaults)
729 mImpl->mFontDefaults = new FontDefaults();
732 mImpl->mFontDefaults->mFontDescription.weight = weight;
733 mImpl->mFontDefaults->weightDefined = true;
735 if(mImpl->mEventData)
737 // Update the cursor position if it's in editing mode
738 if(EventData::IsEditingState(mImpl->mEventData->mState))
740 mImpl->mEventData->mDecoratorUpdated = true;
741 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font weight is updated.
745 // Clear the font-specific data
748 mImpl->RequestRelayout();
751 bool Controller::IsDefaultFontWeightDefined() const
753 if(NULL != mImpl->mFontDefaults)
755 return mImpl->mFontDefaults->weightDefined;
761 FontWeight Controller::GetDefaultFontWeight() const
763 if(NULL != mImpl->mFontDefaults)
765 return mImpl->mFontDefaults->mFontDescription.weight;
768 return TextAbstraction::FontWeight::NORMAL;
771 void Controller::SetPlaceholderTextFontWeight(FontWeight weight)
773 PlaceholderHandler::SetPlaceholderTextFontWeight(*this, weight);
776 bool Controller::IsPlaceholderTextFontWeightDefined() const
778 return PlaceholderHandler::IsPlaceholderTextFontWeightDefined(*this);
782 FontWeight Controller::GetPlaceholderTextFontWeight() const
784 return PlaceholderHandler::GetPlaceholderTextFontWeight(*this);
787 void Controller::SetDefaultFontWidth(FontWidth width)
789 if(NULL == mImpl->mFontDefaults)
791 mImpl->mFontDefaults = new FontDefaults();
794 mImpl->mFontDefaults->mFontDescription.width = width;
795 mImpl->mFontDefaults->widthDefined = true;
797 if(mImpl->mEventData)
799 // Update the cursor position if it's in editing mode
800 if(EventData::IsEditingState(mImpl->mEventData->mState))
802 mImpl->mEventData->mDecoratorUpdated = true;
803 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font width is updated.
807 // Clear the font-specific data
810 mImpl->RequestRelayout();
813 bool Controller::IsDefaultFontWidthDefined() const
815 if(NULL != mImpl->mFontDefaults)
817 return mImpl->mFontDefaults->widthDefined;
823 FontWidth Controller::GetDefaultFontWidth() const
825 if(NULL != mImpl->mFontDefaults)
827 return mImpl->mFontDefaults->mFontDescription.width;
830 return TextAbstraction::FontWidth::NORMAL;
833 void Controller::SetPlaceholderTextFontWidth(FontWidth width)
835 PlaceholderHandler::SetPlaceholderTextFontWidth(*this, width);
838 bool Controller::IsPlaceholderTextFontWidthDefined() const
840 return PlaceholderHandler::IsPlaceholderTextFontWidthDefined(*this);
843 FontWidth Controller::GetPlaceholderTextFontWidth() const
845 return PlaceholderHandler::GetPlaceholderTextFontWidth(*this);
848 void Controller::SetDefaultFontSlant(FontSlant slant)
850 if(NULL == mImpl->mFontDefaults)
852 mImpl->mFontDefaults = new FontDefaults();
855 mImpl->mFontDefaults->mFontDescription.slant = slant;
856 mImpl->mFontDefaults->slantDefined = true;
858 if(mImpl->mEventData)
860 // Update the cursor position if it's in editing mode
861 if(EventData::IsEditingState(mImpl->mEventData->mState))
863 mImpl->mEventData->mDecoratorUpdated = true;
864 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font slant is updated.
868 // Clear the font-specific data
871 mImpl->RequestRelayout();
874 bool Controller::IsDefaultFontSlantDefined() const
876 if(NULL != mImpl->mFontDefaults)
878 return mImpl->mFontDefaults->slantDefined;
883 FontSlant Controller::GetDefaultFontSlant() const
885 if(NULL != mImpl->mFontDefaults)
887 return mImpl->mFontDefaults->mFontDescription.slant;
890 return TextAbstraction::FontSlant::NORMAL;
893 void Controller::SetPlaceholderTextFontSlant(FontSlant slant)
895 PlaceholderHandler::SetPlaceholderTextFontSlant(*this, slant);
898 bool Controller::IsPlaceholderTextFontSlantDefined() const
900 return PlaceholderHandler::IsPlaceholderTextFontSlantDefined(*this);
903 FontSlant Controller::GetPlaceholderTextFontSlant() const
905 return PlaceholderHandler::GetPlaceholderTextFontSlant(*this);
908 void Controller::SetFontSizeScale(float scale)
910 mImpl->mFontSizeScale = scale;
912 if(mImpl->mEventData)
914 // Update the cursor position if it's in editing mode
915 if(EventData::IsEditingState(mImpl->mEventData->mState))
917 mImpl->mEventData->mDecoratorUpdated = true;
918 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
922 // Clear the font-specific data
925 mImpl->RequestRelayout();
928 float Controller::GetFontSizeScale() const
930 if(nullptr != mImpl->mFontDefaults)
932 return mImpl->mFontSizeScale;
938 void Controller::SetDefaultFontSize(float fontSize, FontSizeType type)
940 if(NULL == mImpl->mFontDefaults)
942 mImpl->mFontDefaults = new FontDefaults();
949 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
950 mImpl->mFontDefaults->sizeDefined = true;
955 // Point size = Pixel size * 72.f / DPI
956 unsigned int horizontalDpi = 0u;
957 unsigned int verticalDpi = 0u;
958 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
959 fontClient.GetDpi(horizontalDpi, verticalDpi);
961 mImpl->mFontDefaults->mDefaultPointSize = (fontSize * 72.f) / static_cast<float>(horizontalDpi);
962 mImpl->mFontDefaults->sizeDefined = true;
967 if(mImpl->mEventData)
969 // Update the cursor position if it's in editing mode
970 if(EventData::IsEditingState(mImpl->mEventData->mState))
972 mImpl->mEventData->mDecoratorUpdated = true;
973 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
977 // Clear the font-specific data
980 mImpl->RequestRelayout();
983 float Controller::GetDefaultFontSize(FontSizeType type) const
986 if(NULL != mImpl->mFontDefaults)
992 value = mImpl->mFontDefaults->mDefaultPointSize;
997 // Pixel size = Point size * DPI / 72.f
998 unsigned int horizontalDpi = 0u;
999 unsigned int verticalDpi = 0u;
1000 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1001 fontClient.GetDpi(horizontalDpi, verticalDpi);
1003 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast<float>(horizontalDpi) / 72.f;
1013 void Controller::SetPlaceholderTextFontSize(float fontSize, FontSizeType type)
1015 PlaceholderHandler::SetPlaceholderTextFontSize(*this, fontSize, type);
1018 float Controller::GetPlaceholderTextFontSize(FontSizeType type) const
1020 return PlaceholderHandler::GetPlaceholderTextFontSize(*this, type);
1023 void Controller::SetDefaultColor(const Vector4& color)
1025 mImpl->mTextColor = color;
1027 if(!mImpl->IsShowingPlaceholderText())
1029 mImpl->mModel->mVisualModel->SetTextColor(color);
1031 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1033 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | COLOR);
1035 mImpl->RequestRelayout();
1039 const Vector4& Controller::GetDefaultColor() const
1041 return mImpl->mTextColor;
1044 void Controller::SetPlaceholderTextColor(const Vector4& textColor)
1046 PlaceholderHandler::SetPlaceholderTextColor(*this, textColor);
1049 const Vector4& Controller::GetPlaceholderTextColor() const
1051 return PlaceholderHandler::GetPlaceholderTextColor(*this);
1054 void Controller::SetShadowOffset(const Vector2& shadowOffset)
1056 mImpl->mModel->mVisualModel->SetShadowOffset(shadowOffset);
1058 mImpl->RequestRelayout();
1061 const Vector2& Controller::GetShadowOffset() const
1063 return mImpl->mModel->mVisualModel->GetShadowOffset();
1066 void Controller::SetShadowColor(const Vector4& shadowColor)
1068 mImpl->mModel->mVisualModel->SetShadowColor(shadowColor);
1070 mImpl->RequestRelayout();
1073 const Vector4& Controller::GetShadowColor() const
1075 return mImpl->mModel->mVisualModel->GetShadowColor();
1078 void Controller::SetShadowBlurRadius(const float& shadowBlurRadius)
1080 if(fabsf(GetShadowBlurRadius() - shadowBlurRadius) > Math::MACHINE_EPSILON_1)
1082 mImpl->mModel->mVisualModel->SetShadowBlurRadius(shadowBlurRadius);
1084 mImpl->RequestRelayout();
1088 const float& Controller::GetShadowBlurRadius() const
1090 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1093 void Controller::SetUnderlineColor(const Vector4& color)
1095 mImpl->mModel->mVisualModel->SetUnderlineColor(color);
1097 mImpl->RequestRelayout();
1100 const Vector4& Controller::GetUnderlineColor() const
1102 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1105 void Controller::SetUnderlineEnabled(bool enabled)
1107 mImpl->mModel->mVisualModel->SetUnderlineEnabled(enabled);
1109 mImpl->RequestRelayout();
1112 bool Controller::IsUnderlineEnabled() const
1114 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1117 void Controller::SetUnderlineHeight(float height)
1119 mImpl->mModel->mVisualModel->SetUnderlineHeight(height);
1121 mImpl->RequestRelayout();
1124 float Controller::GetUnderlineHeight() const
1126 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1129 void Controller::SetOutlineColor(const Vector4& color)
1131 mImpl->mModel->mVisualModel->SetOutlineColor(color);
1133 mImpl->RequestRelayout();
1136 const Vector4& Controller::GetOutlineColor() const
1138 return mImpl->mModel->mVisualModel->GetOutlineColor();
1141 void Controller::SetOutlineWidth(uint16_t width)
1143 mImpl->mModel->mVisualModel->SetOutlineWidth(width);
1145 mImpl->RequestRelayout();
1148 uint16_t Controller::GetOutlineWidth() const
1150 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1153 void Controller::SetBackgroundColor(const Vector4& color)
1155 mImpl->mModel->mVisualModel->SetBackgroundColor(color);
1157 mImpl->RequestRelayout();
1160 const Vector4& Controller::GetBackgroundColor() const
1162 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1165 void Controller::SetBackgroundEnabled(bool enabled)
1167 mImpl->mModel->mVisualModel->SetBackgroundEnabled(enabled);
1169 mImpl->RequestRelayout();
1172 bool Controller::IsBackgroundEnabled() const
1174 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1177 void Controller::SetDefaultEmbossProperties(const std::string& embossProperties)
1179 if(NULL == mImpl->mEmbossDefaults)
1181 mImpl->mEmbossDefaults = new EmbossDefaults();
1184 mImpl->mEmbossDefaults->properties = embossProperties;
1187 const std::string& Controller::GetDefaultEmbossProperties() const
1189 if(NULL != mImpl->mEmbossDefaults)
1191 return mImpl->mEmbossDefaults->properties;
1194 return EMPTY_STRING;
1197 void Controller::SetDefaultOutlineProperties(const std::string& outlineProperties)
1199 if(NULL == mImpl->mOutlineDefaults)
1201 mImpl->mOutlineDefaults = new OutlineDefaults();
1204 mImpl->mOutlineDefaults->properties = outlineProperties;
1207 const std::string& Controller::GetDefaultOutlineProperties() const
1209 if(NULL != mImpl->mOutlineDefaults)
1211 return mImpl->mOutlineDefaults->properties;
1214 return EMPTY_STRING;
1217 bool Controller::SetDefaultLineSpacing(float lineSpacing)
1219 if(std::fabs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000)
1221 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1222 mImpl->mRecalculateNaturalSize = true;
1228 float Controller::GetDefaultLineSpacing() const
1230 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1233 bool Controller::SetDefaultLineSize(float lineSize)
1235 if(std::fabs(lineSize - mImpl->mLayoutEngine.GetDefaultLineSize()) > Math::MACHINE_EPSILON_1000)
1237 mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
1238 mImpl->mRecalculateNaturalSize = true;
1244 float Controller::GetDefaultLineSize() const
1246 return mImpl->mLayoutEngine.GetDefaultLineSize();
1249 void Controller::SetInputColor(const Vector4& color)
1251 if(NULL != mImpl->mEventData)
1253 mImpl->mEventData->mInputStyle.textColor = color;
1254 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1256 if(EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState)
1258 if(EventData::SELECTING == mImpl->mEventData->mState)
1260 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1262 // Get start and end position of selection
1263 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1264 const Length lengthOfSelectedText = (handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition) - startOfSelectedText;
1266 // Add the color run.
1267 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1268 mImpl->mModel->mLogicalModel->mColorRuns.Resize(numberOfRuns + 1u);
1270 ColorRun& colorRun = *(mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns);
1271 colorRun.color = color;
1272 colorRun.characterRun.characterIndex = startOfSelectedText;
1273 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1275 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1276 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1277 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1281 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1282 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1283 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1286 // Request to relayout.
1287 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | COLOR);
1288 mImpl->RequestRelayout();
1293 const Vector4& Controller::GetInputColor() const
1295 if(NULL != mImpl->mEventData)
1297 return mImpl->mEventData->mInputStyle.textColor;
1300 // Return the default text's color if there is no EventData.
1301 return mImpl->mTextColor;
1304 void Controller::SetInputFontFamily(const std::string& fontFamily)
1306 InputFontHandler::SetInputFontFamily(*this, fontFamily);
1309 const std::string& Controller::GetInputFontFamily() const
1311 return InputFontHandler::GetInputFontFamily(*this);
1314 void Controller::SetInputFontWeight(FontWeight weight)
1316 InputFontHandler::SetInputFontWeight(*this, weight);
1319 bool Controller::IsInputFontWeightDefined() const
1321 return InputFontHandler::IsInputFontWeightDefined(*this);
1324 FontWeight Controller::GetInputFontWeight() const
1326 return InputFontHandler::GetInputFontWeight(*this);
1329 void Controller::SetInputFontWidth(FontWidth width)
1331 InputFontHandler::SetInputFontWidth(*this, width);
1334 bool Controller::IsInputFontWidthDefined() const
1336 return InputFontHandler::IsInputFontWidthDefined(*this);
1339 FontWidth Controller::GetInputFontWidth() const
1341 return InputFontHandler::GetInputFontWidth(*this);
1344 void Controller::SetInputFontSlant(FontSlant slant)
1346 InputFontHandler::SetInputFontSlant(*this, slant);
1349 bool Controller::IsInputFontSlantDefined() const
1351 return InputFontHandler::IsInputFontSlantDefined(*this);
1354 FontSlant Controller::GetInputFontSlant() const
1356 return InputFontHandler::GetInputFontSlant(*this);
1359 void Controller::SetInputFontPointSize(float size)
1361 InputFontHandler::SetInputFontPointSize(*this, size);
1364 float Controller::GetInputFontPointSize() const
1366 return InputFontHandler::GetInputFontPointSize(*this);
1369 void Controller::SetInputLineSpacing(float lineSpacing)
1371 if(NULL != mImpl->mEventData)
1373 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1374 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1378 float Controller::GetInputLineSpacing() const
1380 if(NULL != mImpl->mEventData)
1382 return mImpl->mEventData->mInputStyle.lineSpacing;
1388 void Controller::SetInputShadowProperties(const std::string& shadowProperties)
1390 if(NULL != mImpl->mEventData)
1392 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1396 const std::string& Controller::GetInputShadowProperties() const
1398 if(NULL != mImpl->mEventData)
1400 return mImpl->mEventData->mInputStyle.shadowProperties;
1403 return EMPTY_STRING;
1406 void Controller::SetInputUnderlineProperties(const std::string& underlineProperties)
1408 if(NULL != mImpl->mEventData)
1410 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1414 const std::string& Controller::GetInputUnderlineProperties() const
1416 if(NULL != mImpl->mEventData)
1418 return mImpl->mEventData->mInputStyle.underlineProperties;
1421 return EMPTY_STRING;
1424 void Controller::SetInputEmbossProperties(const std::string& embossProperties)
1426 if(NULL != mImpl->mEventData)
1428 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1432 const std::string& Controller::GetInputEmbossProperties() const
1434 if(NULL != mImpl->mEventData)
1436 return mImpl->mEventData->mInputStyle.embossProperties;
1439 return GetDefaultEmbossProperties();
1442 void Controller::SetInputOutlineProperties(const std::string& outlineProperties)
1444 if(NULL != mImpl->mEventData)
1446 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1450 const std::string& Controller::GetInputOutlineProperties() const
1452 if(NULL != mImpl->mEventData)
1454 return mImpl->mEventData->mInputStyle.outlineProperties;
1457 return GetDefaultOutlineProperties();
1460 void Controller::SetInputModePassword(bool passwordInput)
1462 if(NULL != mImpl->mEventData)
1464 mImpl->mEventData->mPasswordInput = passwordInput;
1468 bool Controller::IsInputModePassword()
1470 if(NULL != mImpl->mEventData)
1472 return mImpl->mEventData->mPasswordInput;
1477 void Controller::SetNoTextDoubleTapAction(NoTextTap::Action action)
1479 if(NULL != mImpl->mEventData)
1481 mImpl->mEventData->mDoubleTapAction = action;
1485 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1487 NoTextTap::Action action = NoTextTap::NO_ACTION;
1489 if(NULL != mImpl->mEventData)
1491 action = mImpl->mEventData->mDoubleTapAction;
1497 void Controller::SetNoTextLongPressAction(NoTextTap::Action action)
1499 if(NULL != mImpl->mEventData)
1501 mImpl->mEventData->mLongPressAction = action;
1505 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1507 NoTextTap::Action action = NoTextTap::NO_ACTION;
1509 if(NULL != mImpl->mEventData)
1511 action = mImpl->mEventData->mLongPressAction;
1517 bool Controller::IsUnderlineSetByString()
1519 return mImpl->mUnderlineSetByString;
1522 void Controller::UnderlineSetByString(bool setByString)
1524 mImpl->mUnderlineSetByString = setByString;
1527 bool Controller::IsShadowSetByString()
1529 return mImpl->mShadowSetByString;
1532 void Controller::ShadowSetByString(bool setByString)
1534 mImpl->mShadowSetByString = setByString;
1537 bool Controller::IsOutlineSetByString()
1539 return mImpl->mOutlineSetByString;
1542 void Controller::OutlineSetByString(bool setByString)
1544 mImpl->mOutlineSetByString = setByString;
1547 bool Controller::IsFontStyleSetByString()
1549 return mImpl->mFontStyleSetByString;
1552 void Controller::FontStyleSetByString(bool setByString)
1554 mImpl->mFontStyleSetByString = setByString;
1557 // public : Queries & retrieves.
1559 Layout::Engine& Controller::GetLayoutEngine()
1561 return mImpl->mLayoutEngine;
1564 View& Controller::GetView()
1566 return mImpl->mView;
1569 Vector3 Controller::GetNaturalSize()
1571 return Relayouter::GetNaturalSize(*this);
1574 bool Controller::CheckForTextFit(float pointSize, Size& layoutSize)
1576 return Relayouter::CheckForTextFit(*this, pointSize, layoutSize);
1579 void Controller::FitPointSizeforLayout(Size layoutSize)
1581 Relayouter::FitPointSizeforLayout(*this, layoutSize);
1584 float Controller::GetHeightForWidth(float width)
1586 return Relayouter::GetHeightForWidth(*this, width);
1589 int Controller::GetLineCount(float width)
1591 GetHeightForWidth(width);
1592 int numberofLines = mImpl->mModel->GetNumberOfLines();
1593 return numberofLines;
1596 const ModelInterface* const Controller::GetTextModel() const
1598 return mImpl->mModel.Get();
1601 float Controller::GetScrollAmountByUserInput()
1603 float scrollAmount = 0.0f;
1605 if(NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1607 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1608 mImpl->mEventData->mCheckScrollAmount = false;
1610 return scrollAmount;
1613 bool Controller::GetTextScrollInfo(float& scrollPosition, float& controlHeight, float& layoutHeight)
1615 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1618 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1619 layoutHeight = layout.height;
1620 scrollPosition = mImpl->mModel->mScrollPosition.y;
1621 isScrolled = !Equals(mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1);
1625 void Controller::SetHiddenInputOption(const Property::Map& options)
1627 if(NULL == mImpl->mHiddenInput)
1629 mImpl->mHiddenInput = new HiddenText(this);
1631 mImpl->mHiddenInput->SetProperties(options);
1634 void Controller::GetHiddenInputOption(Property::Map& options)
1636 if(NULL != mImpl->mHiddenInput)
1638 mImpl->mHiddenInput->GetProperties(options);
1642 void Controller::SetInputFilterOption(const Property::Map& options)
1644 if(!mImpl->mInputFilter)
1646 mImpl->mInputFilter = std::unique_ptr<InputFilter>(new InputFilter());
1648 mImpl->mInputFilter->SetProperties(options);
1651 void Controller::GetInputFilterOption(Property::Map& options)
1653 if(NULL != mImpl->mInputFilter)
1655 mImpl->mInputFilter->GetProperties(options);
1659 void Controller::SetPlaceholderProperty(const Property::Map& map)
1661 PlaceholderHandler::SetPlaceholderProperty(*this, map);
1664 void Controller::GetPlaceholderProperty(Property::Map& map)
1666 PlaceholderHandler::GetPlaceholderProperty(*this, map);
1669 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
1671 // Make sure the model is up-to-date before layouting
1672 ProcessModifyEvents();
1674 if(mImpl->mUpdateTextDirection)
1676 // Operations that can be done only once until the text changes.
1677 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>(CONVERT_TO_UTF32 |
1685 // Set the update info to relayout the whole text.
1686 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1687 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1689 // Make sure the model is up-to-date before layouting
1690 mImpl->UpdateModel(onlyOnceOperations);
1692 Vector3 naturalSize;
1693 DoRelayout(Size(MAX_FLOAT, MAX_FLOAT),
1694 static_cast<OperationsMask>(onlyOnceOperations |
1695 LAYOUT | REORDER | UPDATE_DIRECTION),
1696 naturalSize.GetVectorXY());
1698 // Do not do again the only once operations.
1699 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending & ~onlyOnceOperations);
1701 // Clear the update info. This info will be set the next time the text is updated.
1702 mImpl->mTextUpdateInfo.Clear();
1704 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
1705 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1707 mImpl->mUpdateTextDirection = false;
1710 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
1713 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
1715 return mImpl->mModel->GetVerticalLineAlignment();
1718 void Controller::SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment)
1720 mImpl->mModel->mVerticalLineAlignment = alignment;
1723 Toolkit::DevelText::EllipsisPosition::Type Controller::GetEllipsisPosition() const
1725 return mImpl->mModel->GetEllipsisPosition();
1728 void Controller::SetEllipsisPosition(Toolkit::DevelText::EllipsisPosition::Type ellipsisPosition)
1730 mImpl->mModel->mEllipsisPosition = ellipsisPosition;
1731 mImpl->mModel->mVisualModel->SetEllipsisPosition(ellipsisPosition);
1734 // public : Relayout.
1736 Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection)
1738 return Relayouter::Relayout(*this, size, layoutDirection);
1741 void Controller::RequestRelayout()
1743 mImpl->RequestRelayout();
1746 // public : Input style change signals.
1748 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1750 return (NULL == mImpl->mEventData) || (0u == mImpl->mEventData->mInputStyleChangedQueue.Count());
1753 void Controller::ProcessInputStyleChangedSignals()
1755 if(NULL == mImpl->mEventData)
1761 for(Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
1762 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
1766 const InputStyle::Mask mask = *it;
1768 if(NULL != mImpl->mEditableControlInterface)
1770 // Emit the input style changed signal.
1771 mImpl->mEditableControlInterface->InputStyleChanged(mask);
1775 mImpl->mEventData->mInputStyleChangedQueue.Clear();
1778 // public : Text-input Event Queuing.
1780 void Controller::KeyboardFocusGainEvent()
1782 EventHandler::KeyboardFocusGainEvent(*this);
1785 void Controller::KeyboardFocusLostEvent()
1787 EventHandler::KeyboardFocusLostEvent(*this);
1790 bool Controller::KeyEvent(const Dali::KeyEvent& keyEvent)
1792 return EventHandler::KeyEvent(*this, keyEvent);
1795 void Controller::AnchorEvent(float x, float y)
1797 EventHandler::AnchorEvent(*this, x, y);
1800 void Controller::TapEvent(unsigned int tapCount, float x, float y)
1802 EventHandler::TapEvent(*this, tapCount, x, y);
1805 void Controller::PanEvent(GestureState state, const Vector2& displacement)
1807 EventHandler::PanEvent(*this, state, displacement);
1810 void Controller::LongPressEvent(GestureState state, float x, float y)
1812 EventHandler::LongPressEvent(*this, state, x, y);
1815 void Controller::SelectEvent(float x, float y, SelectionType selectType)
1817 EventHandler::SelectEvent(*this, x, y, selectType);
1820 void Controller::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1822 if(mImpl->mEventData)
1824 mImpl->mEventData->mCheckScrollAmount = true;
1825 mImpl->mEventData->mIsLeftHandleSelected = true;
1826 mImpl->mEventData->mIsRightHandleSelected = true;
1827 mImpl->SetTextSelectionRange(start, end);
1828 mImpl->RequestRelayout();
1829 KeyboardFocusGainEvent();
1833 Uint32Pair Controller::GetTextSelectionRange() const
1835 return mImpl->GetTextSelectionRange();
1838 CharacterIndex Controller::GetPrimaryCursorPosition() const
1840 return mImpl->GetPrimaryCursorPosition();
1843 bool Controller::SetPrimaryCursorPosition(CharacterIndex index)
1845 if(mImpl->mEventData)
1847 mImpl->mEventData->mCheckScrollAmount = true;
1848 mImpl->mEventData->mIsLeftHandleSelected = true;
1849 mImpl->mEventData->mIsRightHandleSelected = true;
1850 mImpl->mEventData->mCheckScrollAmount = true;
1851 if(mImpl->SetPrimaryCursorPosition(index))
1853 KeyboardFocusGainEvent();
1860 void Controller::SelectWholeText()
1862 SelectEvent(0.f, 0.f, SelectionType::ALL);
1865 void Controller::SelectNone()
1867 SelectEvent(0.f, 0.f, SelectionType::NONE);
1870 string Controller::GetSelectedText() const
1873 if(EventData::SELECTING == mImpl->mEventData->mState)
1875 mImpl->RetrieveSelection(text, false);
1880 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1882 return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent);
1885 void Controller::PasteClipboardItemEvent()
1887 EventHandler::PasteClipboardItemEvent(*this);
1890 // protected : Inherit from Text::Decorator::ControllerInterface.
1892 void Controller::GetTargetSize(Vector2& targetSize)
1894 targetSize = mImpl->mModel->mVisualModel->mControlSize;
1897 void Controller::AddDecoration(Actor& actor, bool needsClipping)
1899 if(NULL != mImpl->mEditableControlInterface)
1901 mImpl->mEditableControlInterface->AddDecoration(actor, needsClipping);
1905 bool Controller::IsEditable() const
1907 return mImpl->IsEditable();
1910 void Controller::SetEditable(bool editable)
1912 mImpl->SetEditable(editable);
1913 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
1915 mImpl->mEventData->mDecorator->SetEditable(editable);
1919 void Controller::ScrollBy(Vector2 scroll)
1921 if(mImpl->mEventData && (fabs(scroll.x) > Math::MACHINE_EPSILON_0 || fabs(scroll.y) > Math::MACHINE_EPSILON_0))
1923 const Vector2& layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1924 const Vector2 currentScroll = mImpl->mModel->mScrollPosition;
1926 scroll.x = -scroll.x;
1927 scroll.y = -scroll.y;
1929 if(fabs(scroll.x) > Math::MACHINE_EPSILON_0)
1931 mImpl->mModel->mScrollPosition.x += scroll.x;
1932 mImpl->ClampHorizontalScroll(layoutSize);
1935 if(fabs(scroll.y) > Math::MACHINE_EPSILON_0)
1937 mImpl->mModel->mScrollPosition.y += scroll.y;
1938 mImpl->ClampVerticalScroll(layoutSize);
1941 if(mImpl->mModel->mScrollPosition != currentScroll)
1943 mImpl->mEventData->mDecorator->UpdatePositions(mImpl->mModel->mScrollPosition - currentScroll);
1944 mImpl->RequestRelayout();
1949 float Controller::GetHorizontalScrollPosition()
1951 if(mImpl->mEventData)
1953 //scroll values are negative internally so we convert them to positive numbers
1954 return -mImpl->mModel->mScrollPosition.x;
1959 float Controller::GetVerticalScrollPosition()
1961 if(mImpl->mEventData)
1963 //scroll values are negative internally so we convert them to positive numbers
1964 return -mImpl->mModel->mScrollPosition.y;
1969 void Controller::DecorationEvent(HandleType handleType, HandleState state, float x, float y)
1971 EventHandler::DecorationEvent(*this, handleType, state, x, y);
1974 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
1976 void Controller::TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button)
1978 EventHandler::TextPopupButtonTouched(*this, button);
1981 void Controller::DisplayTimeExpired()
1983 mImpl->mEventData->mUpdateCursorPosition = true;
1984 // Apply modifications to the model
1985 mImpl->mOperationsPending = ALL_OPERATIONS;
1987 mImpl->RequestRelayout();
1990 // private : Update.
1992 void Controller::InsertText(const std::string& text, Controller::InsertType type)
1994 TextUpdater::InsertText(*this, text, type);
1997 void Controller::PasteText(const std::string& stringToPaste)
1999 TextUpdater::PasteText(*this, stringToPaste);
2002 bool Controller::RemoveText(int cursorOffset,
2003 int numberOfCharacters,
2004 UpdateInputStyleType type)
2006 return TextUpdater::RemoveText(*this, cursorOffset, numberOfCharacters, type);
2009 bool Controller::RemoveSelectedText()
2011 return TextUpdater::RemoveSelectedText(*this);
2014 void Controller::InsertTextAnchor(int numberOfCharacters,
2015 CharacterIndex previousCursorIndex)
2017 TextUpdater::InsertTextAnchor(*this, numberOfCharacters, previousCursorIndex);
2020 void Controller::RemoveTextAnchor(int cursorOffset,
2021 int numberOfCharacters,
2022 CharacterIndex previousCursorIndex)
2024 TextUpdater::RemoveTextAnchor(*this, cursorOffset, numberOfCharacters, previousCursorIndex);
2027 // private : Relayout.
2029 bool Controller::DoRelayout(const Size& size,
2030 OperationsMask operationsRequired,
2033 return Relayouter::DoRelayout(*this, size, operationsRequired, layoutSize);
2036 void Controller::CalculateVerticalOffset(const Size& controlSize)
2038 Relayouter::CalculateVerticalOffset(*this, controlSize);
2041 // private : Events.
2043 void Controller::ProcessModifyEvents()
2045 EventHandler::ProcessModifyEvents(*this);
2048 void Controller::TextReplacedEvent()
2050 EventHandler::TextReplacedEvent(*this);
2053 void Controller::TextInsertedEvent()
2055 EventHandler::TextInsertedEvent(*this);
2058 void Controller::TextDeletedEvent()
2060 EventHandler::TextDeletedEvent(*this);
2063 bool Controller::DeleteEvent(int keyCode)
2065 return EventHandler::DeleteEvent(*this, keyCode);
2068 // private : Helpers.
2070 void Controller::ResetText()
2072 TextUpdater::ResetText(*this);
2075 void Controller::ShowPlaceholderText()
2077 PlaceholderHandler::ShowPlaceholderText(*this);
2080 void Controller::ClearFontData()
2082 if(mImpl->mFontDefaults)
2084 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
2087 // Set flags to update the model.
2088 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2089 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2090 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2092 mImpl->mTextUpdateInfo.mClearAll = true;
2093 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2094 mImpl->mRecalculateNaturalSize = true;
2096 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
2102 UPDATE_LAYOUT_SIZE |
2107 void Controller::ClearStyleData()
2109 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
2110 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
2113 void Controller::ResetCursorPosition(CharacterIndex cursorIndex)
2115 // Reset the cursor position
2116 if(NULL != mImpl->mEventData)
2118 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
2120 // Update the cursor if it's in editing mode.
2121 if(EventData::IsEditingState(mImpl->mEventData->mState))
2123 mImpl->mEventData->mUpdateCursorPosition = true;
2128 CharacterIndex Controller::GetCursorPosition()
2130 if(!mImpl->mEventData)
2133 return mImpl->mEventData->mPrimaryCursorPosition;
2136 void Controller::ResetScrollPosition()
2138 if(NULL != mImpl->mEventData)
2140 // Reset the scroll position.
2141 mImpl->mModel->mScrollPosition = Vector2::ZERO;
2142 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2146 void Controller::SetControlInterface(ControlInterface* controlInterface)
2148 mImpl->mControlInterface = controlInterface;
2151 void Controller::SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface)
2153 mImpl->mAnchorControlInterface = anchorControlInterface;
2156 bool Controller::ShouldClearFocusOnEscape() const
2158 return mImpl->mShouldClearFocusOnEscape;
2161 Actor Controller::CreateBackgroundActor()
2163 return mImpl->CreateBackgroundActor();
2166 // private : Private contructors & copy operator.
2168 Controller::Controller()
2169 : Controller(nullptr, nullptr, nullptr, nullptr)
2173 Controller::Controller(ControlInterface* controlInterface)
2174 : Controller(controlInterface, nullptr, nullptr, nullptr)
2178 Controller::Controller(ControlInterface* controlInterface,
2179 EditableControlInterface* editableControlInterface,
2180 SelectableControlInterface* selectableControlInterface,
2181 AnchorControlInterface* anchorControlInterface)
2182 : mImpl(new Controller::Impl(controlInterface, editableControlInterface, selectableControlInterface, anchorControlInterface))
2186 // The copy constructor and operator are left unimplemented.
2188 // protected : Destructor.
2190 Controller::~Controller()
2197 } // namespace Toolkit