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/integration-api/debug.h>
28 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
29 #include <dali-toolkit/internal/text/text-controller-event-handler.h>
30 #include <dali-toolkit/internal/text/text-controller-impl.h>
31 #include <dali-toolkit/internal/text/text-controller-input-font-handler.h>
32 #include <dali-toolkit/internal/text/text-controller-placeholder-handler.h>
33 #include <dali-toolkit/internal/text/text-controller-relayouter.h>
34 #include <dali-toolkit/internal/text/text-controller-text-updater.h>
35 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
39 #if defined(DEBUG_ENABLED)
40 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
43 constexpr float MAX_FLOAT = std::numeric_limits<float>::max();
45 const std::string EMPTY_STRING("");
47 int ConvertPixelToPint(float pixel)
49 unsigned int horizontalDpi = 0u;
50 unsigned int verticalDpi = 0u;
51 Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
52 fontClient.GetDpi(horizontalDpi, verticalDpi);
54 return (pixel * 72.f) / static_cast<float>(horizontalDpi);
65 // public : Constructor.
67 ControllerPtr Controller::New()
69 return ControllerPtr(new Controller());
72 ControllerPtr Controller::New(ControlInterface* controlInterface)
74 return ControllerPtr(new Controller(controlInterface));
77 ControllerPtr Controller::New(ControlInterface* controlInterface,
78 EditableControlInterface* editableControlInterface,
79 SelectableControlInterface* selectableControlInterface,
80 AnchorControlInterface* anchorControlInterface)
82 return ControllerPtr(new Controller(controlInterface,
83 editableControlInterface,
84 selectableControlInterface,
85 anchorControlInterface));
88 // public : Configure the text controller.
90 void Controller::EnableTextInput(DecoratorPtr decorator, InputMethodContext& inputMethodContext)
94 delete mImpl->mEventData;
95 mImpl->mEventData = NULL;
97 // Nothing else to do.
101 if(NULL == mImpl->mEventData)
103 mImpl->mEventData = new EventData(decorator, inputMethodContext);
107 void Controller::SetGlyphType(TextAbstraction::GlyphType glyphType)
109 // Metrics for bitmap & vector based glyphs are different
110 mImpl->mMetrics->SetGlyphType(glyphType);
112 // Clear the font-specific data
115 mImpl->RequestRelayout();
118 void Controller::SetMarkupProcessorEnabled(bool enable)
120 if(enable != mImpl->mMarkupProcessorEnabled)
122 //If Text was already set, call the SetText again for enabling or disabling markup
123 mImpl->mMarkupProcessorEnabled = enable;
129 mImpl->mModel->mVisualModel->SetMarkupProcessorEnabled(enable);
132 bool Controller::IsMarkupProcessorEnabled() const
134 return mImpl->mMarkupProcessorEnabled;
137 void Controller::SetAutoScrollEnabled(bool enable)
139 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);
141 if(mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)
145 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n");
146 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
155 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
156 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
163 mImpl->mIsAutoScrollEnabled = enable;
164 mImpl->RequestRelayout();
168 DALI_LOG_WARNING("Attempted AutoScrolling on a non SINGLE_LINE_BOX, request ignored\n");
169 mImpl->mIsAutoScrollEnabled = false;
173 bool Controller::IsAutoScrollEnabled() const
175 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::IsAutoScrollEnabled[%s]\n", mImpl->mIsAutoScrollEnabled ? "true" : "false");
177 return mImpl->mIsAutoScrollEnabled;
180 CharacterDirection Controller::GetAutoScrollDirection() const
182 return mImpl->mIsTextDirectionRTL;
185 float Controller::GetAutoScrollLineAlignment() const
189 if(mImpl->mModel->mVisualModel &&
190 (0u != mImpl->mModel->mVisualModel->mLines.Count()))
192 offset = (*mImpl->mModel->mVisualModel->mLines.Begin()).alignmentOffset;
198 void Controller::SetHorizontalScrollEnabled(bool enable)
200 if((NULL != mImpl->mEventData) &&
201 mImpl->mEventData->mDecorator)
203 mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled(enable);
206 bool Controller::IsHorizontalScrollEnabled() const
208 if((NULL != mImpl->mEventData) &&
209 mImpl->mEventData->mDecorator)
211 return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
217 void Controller::SetVerticalScrollEnabled(bool enable)
219 if((NULL != mImpl->mEventData) &&
220 mImpl->mEventData->mDecorator)
222 if(mImpl->mEventData->mDecorator)
224 mImpl->mEventData->mDecorator->SetVerticalScrollEnabled(enable);
229 bool Controller::IsVerticalScrollEnabled() const
231 if((NULL != mImpl->mEventData) &&
232 mImpl->mEventData->mDecorator)
234 return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
240 void Controller::SetSmoothHandlePanEnabled(bool enable)
242 if((NULL != mImpl->mEventData) &&
243 mImpl->mEventData->mDecorator)
245 mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled(enable);
249 bool Controller::IsSmoothHandlePanEnabled() const
251 if((NULL != mImpl->mEventData) &&
252 mImpl->mEventData->mDecorator)
254 return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
260 void Controller::SetMaximumNumberOfCharacters(Length maxCharacters)
262 mImpl->mMaximumNumberOfCharacters = maxCharacters;
265 int Controller::GetMaximumNumberOfCharacters()
267 return mImpl->mMaximumNumberOfCharacters;
270 void Controller::SetEnableCursorBlink(bool enable)
272 DALI_ASSERT_DEBUG(NULL != mImpl->mEventData && "TextInput disabled");
274 if(NULL != mImpl->mEventData)
276 mImpl->mEventData->mCursorBlinkEnabled = enable;
279 mImpl->mEventData->mDecorator)
281 mImpl->mEventData->mDecorator->StopCursorBlink();
286 bool Controller::GetEnableCursorBlink() const
288 if(NULL != mImpl->mEventData)
290 return mImpl->mEventData->mCursorBlinkEnabled;
296 void Controller::SetMultiLineEnabled(bool enable)
298 const Layout::Engine::Type layout = enable ? Layout::Engine::MULTI_LINE_BOX : Layout::Engine::SINGLE_LINE_BOX;
300 if(layout != mImpl->mLayoutEngine.GetLayout())
302 // Set the layout type.
303 mImpl->mLayoutEngine.SetLayout(layout);
305 // Set the flags to redo the layout operations
306 const OperationsMask layoutOperations = static_cast<OperationsMask>(LAYOUT |
311 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
312 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | layoutOperations);
314 // Need to recalculate natural size
315 mImpl->mRecalculateNaturalSize = true;
317 mImpl->RequestRelayout();
321 bool Controller::IsMultiLineEnabled() const
323 return Layout::Engine::MULTI_LINE_BOX == mImpl->mLayoutEngine.GetLayout();
326 void Controller::SetHorizontalAlignment(Text::HorizontalAlignment::Type alignment)
328 if(alignment != mImpl->mModel->mHorizontalAlignment)
330 // Set the alignment.
331 mImpl->mModel->mHorizontalAlignment = alignment;
333 // Set the flag to redo the alignment operation.
334 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | ALIGN);
336 if(mImpl->mEventData)
338 mImpl->mEventData->mUpdateAlignment = true;
340 // Update the cursor if it's in editing mode
341 if(EventData::IsEditingState(mImpl->mEventData->mState))
343 mImpl->ChangeState(EventData::EDITING);
344 mImpl->mEventData->mUpdateCursorPosition = true;
348 mImpl->RequestRelayout();
352 Text::HorizontalAlignment::Type Controller::GetHorizontalAlignment() const
354 return mImpl->mModel->mHorizontalAlignment;
357 void Controller::SetVerticalAlignment(VerticalAlignment::Type alignment)
359 if(alignment != mImpl->mModel->mVerticalAlignment)
361 // Set the alignment.
362 mImpl->mModel->mVerticalAlignment = alignment;
364 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | ALIGN);
366 mImpl->RequestRelayout();
370 VerticalAlignment::Type Controller::GetVerticalAlignment() const
372 return mImpl->mModel->mVerticalAlignment;
375 bool Controller::IsIgnoreSpacesAfterText() const
377 return mImpl->mModel->mIgnoreSpacesAfterText;
380 void Controller::SetIgnoreSpacesAfterText(bool ignore)
382 mImpl->mModel->mIgnoreSpacesAfterText = ignore;
385 bool Controller::IsMatchSystemLanguageDirection() const
387 return mImpl->mModel->mMatchSystemLanguageDirection;
390 void Controller::SetMatchSystemLanguageDirection(bool match)
392 mImpl->mModel->mMatchSystemLanguageDirection = match;
395 void Controller::SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection)
397 mImpl->mLayoutDirection = layoutDirection;
400 bool Controller::IsShowingRealText() const
402 return mImpl->IsShowingRealText();
405 void Controller::SetLineWrapMode(Text::LineWrap::Mode lineWrapMode)
407 if(lineWrapMode != mImpl->mModel->mLineWrapMode)
409 // Update Text layout for applying wrap mode
410 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
416 if((mImpl->mModel->mLineWrapMode == (Text::LineWrap::Mode)DevelText::LineWrap::HYPHENATION) || (lineWrapMode == (Text::LineWrap::Mode)DevelText::LineWrap::HYPHENATION) ||
417 (mImpl->mModel->mLineWrapMode == (Text::LineWrap::Mode)DevelText::LineWrap::MIXED) || (lineWrapMode == (Text::LineWrap::Mode)DevelText::LineWrap::MIXED)) // hyphen is treated as line break
419 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | GET_LINE_BREAKS);
422 // Set the text wrap mode.
423 mImpl->mModel->mLineWrapMode = lineWrapMode;
425 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
426 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
427 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
430 mImpl->RequestRelayout();
434 Text::LineWrap::Mode Controller::GetLineWrapMode() const
436 return mImpl->mModel->mLineWrapMode;
439 void Controller::SetTextElideEnabled(bool enabled)
441 mImpl->mModel->mElideEnabled = enabled;
444 bool Controller::IsTextElideEnabled() const
446 return mImpl->mModel->mElideEnabled;
449 void Controller::SetTextFitEnabled(bool enabled)
451 mImpl->mTextFitEnabled = enabled;
454 bool Controller::IsTextFitEnabled() const
456 return mImpl->mTextFitEnabled;
459 void Controller::SetTextFitMinSize(float minSize, FontSizeType type)
465 mImpl->mTextFitMinSize = minSize;
470 mImpl->mTextFitMinSize = ConvertPixelToPint(minSize);
476 float Controller::GetTextFitMinSize() const
478 return mImpl->mTextFitMinSize;
481 void Controller::SetTextFitMaxSize(float maxSize, FontSizeType type)
487 mImpl->mTextFitMaxSize = maxSize;
492 mImpl->mTextFitMaxSize = ConvertPixelToPint(maxSize);
498 float Controller::GetTextFitMaxSize() const
500 return mImpl->mTextFitMaxSize;
503 void Controller::SetTextFitStepSize(float step, FontSizeType type)
509 mImpl->mTextFitStepSize = step;
514 mImpl->mTextFitStepSize = ConvertPixelToPint(step);
520 float Controller::GetTextFitStepSize() const
522 return mImpl->mTextFitStepSize;
525 void Controller::SetTextFitContentSize(Vector2 size)
527 mImpl->mTextFitContentSize = size;
530 Vector2 Controller::GetTextFitContentSize() const
532 return mImpl->mTextFitContentSize;
535 void Controller::SetPlaceholderTextElideEnabled(bool enabled)
537 PlaceholderHandler::SetPlaceholderTextElideEnabled(*this, enabled);
540 bool Controller::IsPlaceholderTextElideEnabled() const
542 return PlaceholderHandler::IsPlaceholderTextElideEnabled(*this);
545 void Controller::SetSelectionEnabled(bool enabled)
547 mImpl->mEventData->mSelectionEnabled = enabled;
550 bool Controller::IsSelectionEnabled() const
552 return mImpl->mEventData->mSelectionEnabled;
555 void Controller::SetShiftSelectionEnabled(bool enabled)
557 mImpl->mEventData->mShiftSelectionFlag = enabled;
560 bool Controller::IsShiftSelectionEnabled() const
562 return mImpl->mEventData->mShiftSelectionFlag;
565 void Controller::SetGrabHandleEnabled(bool enabled)
567 mImpl->mEventData->mGrabHandleEnabled = enabled;
570 bool Controller::IsGrabHandleEnabled() const
572 return mImpl->mEventData->mGrabHandleEnabled;
575 void Controller::SetGrabHandlePopupEnabled(bool enabled)
577 mImpl->mEventData->mGrabHandlePopupEnabled = enabled;
580 bool Controller::IsGrabHandlePopupEnabled() const
582 return mImpl->mEventData->mGrabHandlePopupEnabled;
587 void Controller::SetText(const std::string& text)
589 TextUpdater::SetText(*this, text);
592 void Controller::GetText(std::string& text) const
594 if(!mImpl->IsShowingPlaceholderText())
596 // Retrieves the text string.
597 mImpl->GetText(0u, text);
601 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::GetText %p empty (but showing placeholder)\n", this);
605 void Controller::SetPlaceholderText(PlaceholderType type, const std::string& text)
607 PlaceholderHandler::SetPlaceholderText(*this, type, text);
610 void Controller::GetPlaceholderText(PlaceholderType type, std::string& text) const
612 PlaceholderHandler::GetPlaceholderText(*this, type, text);
615 void Controller::UpdateAfterFontChange(const std::string& newDefaultFont)
617 DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Controller::UpdateAfterFontChange\n");
619 if(!mImpl->mFontDefaults->familyDefined) // If user defined font then should not update when system font changes
621 DALI_LOG_INFO(gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str());
622 mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
626 mImpl->RequestRelayout();
630 void Controller::RetrieveSelection(std::string& selectedText) const
632 mImpl->RetrieveSelection(selectedText, false);
635 void Controller::SetSelection(int start, int end)
637 mImpl->SetSelection(start, end);
640 std::pair<int, int> Controller::GetSelectionIndexes() const
642 return mImpl->GetSelectionIndexes();
645 void Controller::CopyStringToClipboard(const std::string& source)
647 mImpl->CopyStringToClipboard(source);
650 void Controller::SendSelectionToClipboard(bool deleteAfterSending)
652 mImpl->SendSelectionToClipboard(deleteAfterSending);
655 // public : Default style & Input style
657 void Controller::SetDefaultFontFamily(const std::string& defaultFontFamily)
659 if(NULL == mImpl->mFontDefaults)
661 mImpl->mFontDefaults = new FontDefaults();
664 mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
665 DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
666 mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
668 if(mImpl->mEventData)
670 // Update the cursor position if it's in editing mode
671 if(EventData::IsEditingState(mImpl->mEventData->mState))
673 mImpl->mEventData->mDecoratorUpdated = true;
674 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font family is updated.
678 // Clear the font-specific data
681 mImpl->RequestRelayout();
684 const std::string& Controller::GetDefaultFontFamily() const
686 if(NULL != mImpl->mFontDefaults)
688 return mImpl->mFontDefaults->mFontDescription.family;
694 void Controller::SetPlaceholderFontFamily(const std::string& placeholderTextFontFamily)
696 PlaceholderHandler::SetPlaceholderFontFamily(*this, placeholderTextFontFamily);
699 const std::string& Controller::GetPlaceholderFontFamily() const
701 return PlaceholderHandler::GetPlaceholderFontFamily(*this);
704 void Controller::SetDefaultFontWeight(FontWeight weight)
706 if(NULL == mImpl->mFontDefaults)
708 mImpl->mFontDefaults = new FontDefaults();
711 mImpl->mFontDefaults->mFontDescription.weight = weight;
712 mImpl->mFontDefaults->weightDefined = true;
714 if(mImpl->mEventData)
716 // Update the cursor position if it's in editing mode
717 if(EventData::IsEditingState(mImpl->mEventData->mState))
719 mImpl->mEventData->mDecoratorUpdated = true;
720 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font weight is updated.
724 // Clear the font-specific data
727 mImpl->RequestRelayout();
730 bool Controller::IsDefaultFontWeightDefined() const
732 if(NULL != mImpl->mFontDefaults)
734 return mImpl->mFontDefaults->weightDefined;
740 FontWeight Controller::GetDefaultFontWeight() const
742 if(NULL != mImpl->mFontDefaults)
744 return mImpl->mFontDefaults->mFontDescription.weight;
747 return TextAbstraction::FontWeight::NORMAL;
750 void Controller::SetPlaceholderTextFontWeight(FontWeight weight)
752 PlaceholderHandler::SetPlaceholderTextFontWeight(*this, weight);
755 bool Controller::IsPlaceholderTextFontWeightDefined() const
757 return PlaceholderHandler::IsPlaceholderTextFontWeightDefined(*this);
761 FontWeight Controller::GetPlaceholderTextFontWeight() const
763 return PlaceholderHandler::GetPlaceholderTextFontWeight(*this);
766 void Controller::SetDefaultFontWidth(FontWidth width)
768 if(NULL == mImpl->mFontDefaults)
770 mImpl->mFontDefaults = new FontDefaults();
773 mImpl->mFontDefaults->mFontDescription.width = width;
774 mImpl->mFontDefaults->widthDefined = true;
776 if(mImpl->mEventData)
778 // Update the cursor position if it's in editing mode
779 if(EventData::IsEditingState(mImpl->mEventData->mState))
781 mImpl->mEventData->mDecoratorUpdated = true;
782 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font width is updated.
786 // Clear the font-specific data
789 mImpl->RequestRelayout();
792 bool Controller::IsDefaultFontWidthDefined() const
794 if(NULL != mImpl->mFontDefaults)
796 return mImpl->mFontDefaults->widthDefined;
802 FontWidth Controller::GetDefaultFontWidth() const
804 if(NULL != mImpl->mFontDefaults)
806 return mImpl->mFontDefaults->mFontDescription.width;
809 return TextAbstraction::FontWidth::NORMAL;
812 void Controller::SetPlaceholderTextFontWidth(FontWidth width)
814 PlaceholderHandler::SetPlaceholderTextFontWidth(*this, width);
817 bool Controller::IsPlaceholderTextFontWidthDefined() const
819 return PlaceholderHandler::IsPlaceholderTextFontWidthDefined(*this);
822 FontWidth Controller::GetPlaceholderTextFontWidth() const
824 return PlaceholderHandler::GetPlaceholderTextFontWidth(*this);
827 void Controller::SetDefaultFontSlant(FontSlant slant)
829 if(NULL == mImpl->mFontDefaults)
831 mImpl->mFontDefaults = new FontDefaults();
834 mImpl->mFontDefaults->mFontDescription.slant = slant;
835 mImpl->mFontDefaults->slantDefined = true;
837 if(mImpl->mEventData)
839 // Update the cursor position if it's in editing mode
840 if(EventData::IsEditingState(mImpl->mEventData->mState))
842 mImpl->mEventData->mDecoratorUpdated = true;
843 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font slant is updated.
847 // Clear the font-specific data
850 mImpl->RequestRelayout();
853 bool Controller::IsDefaultFontSlantDefined() const
855 if(NULL != mImpl->mFontDefaults)
857 return mImpl->mFontDefaults->slantDefined;
862 FontSlant Controller::GetDefaultFontSlant() const
864 if(NULL != mImpl->mFontDefaults)
866 return mImpl->mFontDefaults->mFontDescription.slant;
869 return TextAbstraction::FontSlant::NORMAL;
872 void Controller::SetPlaceholderTextFontSlant(FontSlant slant)
874 PlaceholderHandler::SetPlaceholderTextFontSlant(*this, slant);
877 bool Controller::IsPlaceholderTextFontSlantDefined() const
879 return PlaceholderHandler::IsPlaceholderTextFontSlantDefined(*this);
882 FontSlant Controller::GetPlaceholderTextFontSlant() const
884 return PlaceholderHandler::GetPlaceholderTextFontSlant(*this);
887 void Controller::SetFontSizeScale(float scale)
889 mImpl->mFontSizeScale = scale;
891 if(mImpl->mEventData)
893 // Update the cursor position if it's in editing mode
894 if(EventData::IsEditingState(mImpl->mEventData->mState))
896 mImpl->mEventData->mDecoratorUpdated = true;
897 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
901 // Clear the font-specific data
904 mImpl->RequestRelayout();
907 float Controller::GetFontSizeScale() const
909 if(nullptr != mImpl->mFontDefaults)
911 return mImpl->mFontSizeScale;
917 void Controller::SetDefaultFontSize(float fontSize, FontSizeType type)
919 if(NULL == mImpl->mFontDefaults)
921 mImpl->mFontDefaults = new FontDefaults();
928 mImpl->mFontDefaults->mDefaultPointSize = fontSize;
929 mImpl->mFontDefaults->sizeDefined = true;
934 // Point size = Pixel size * 72.f / DPI
935 unsigned int horizontalDpi = 0u;
936 unsigned int verticalDpi = 0u;
937 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
938 fontClient.GetDpi(horizontalDpi, verticalDpi);
940 mImpl->mFontDefaults->mDefaultPointSize = (fontSize * 72.f) / static_cast<float>(horizontalDpi);
941 mImpl->mFontDefaults->sizeDefined = true;
946 if(mImpl->mEventData)
948 // Update the cursor position if it's in editing mode
949 if(EventData::IsEditingState(mImpl->mEventData->mState))
951 mImpl->mEventData->mDecoratorUpdated = true;
952 mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
956 // Clear the font-specific data
959 mImpl->RequestRelayout();
962 float Controller::GetDefaultFontSize(FontSizeType type) const
965 if(NULL != mImpl->mFontDefaults)
971 value = mImpl->mFontDefaults->mDefaultPointSize;
976 // Pixel size = Point size * DPI / 72.f
977 unsigned int horizontalDpi = 0u;
978 unsigned int verticalDpi = 0u;
979 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
980 fontClient.GetDpi(horizontalDpi, verticalDpi);
982 value = mImpl->mFontDefaults->mDefaultPointSize * static_cast<float>(horizontalDpi) / 72.f;
992 void Controller::SetPlaceholderTextFontSize(float fontSize, FontSizeType type)
994 PlaceholderHandler::SetPlaceholderTextFontSize(*this, fontSize, type);
997 float Controller::GetPlaceholderTextFontSize(FontSizeType type) const
999 return PlaceholderHandler::GetPlaceholderTextFontSize(*this, type);
1002 void Controller::SetDefaultColor(const Vector4& color)
1004 mImpl->mTextColor = color;
1006 if(!mImpl->IsShowingPlaceholderText())
1008 mImpl->mModel->mVisualModel->SetTextColor(color);
1010 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
1012 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | COLOR);
1014 mImpl->RequestRelayout();
1018 const Vector4& Controller::GetDefaultColor() const
1020 return mImpl->mTextColor;
1023 void Controller::SetPlaceholderTextColor(const Vector4& textColor)
1025 PlaceholderHandler::SetPlaceholderTextColor(*this, textColor);
1028 const Vector4& Controller::GetPlaceholderTextColor() const
1030 return PlaceholderHandler::GetPlaceholderTextColor(*this);
1033 void Controller::SetShadowOffset(const Vector2& shadowOffset)
1035 mImpl->mModel->mVisualModel->SetShadowOffset(shadowOffset);
1037 mImpl->RequestRelayout();
1040 const Vector2& Controller::GetShadowOffset() const
1042 return mImpl->mModel->mVisualModel->GetShadowOffset();
1045 void Controller::SetShadowColor(const Vector4& shadowColor)
1047 mImpl->mModel->mVisualModel->SetShadowColor(shadowColor);
1049 mImpl->RequestRelayout();
1052 const Vector4& Controller::GetShadowColor() const
1054 return mImpl->mModel->mVisualModel->GetShadowColor();
1057 void Controller::SetShadowBlurRadius(const float& shadowBlurRadius)
1059 if(fabsf(GetShadowBlurRadius() - shadowBlurRadius) > Math::MACHINE_EPSILON_1)
1061 mImpl->mModel->mVisualModel->SetShadowBlurRadius(shadowBlurRadius);
1063 mImpl->RequestRelayout();
1067 const float& Controller::GetShadowBlurRadius() const
1069 return mImpl->mModel->mVisualModel->GetShadowBlurRadius();
1072 void Controller::SetUnderlineColor(const Vector4& color)
1074 mImpl->mModel->mVisualModel->SetUnderlineColor(color);
1076 mImpl->RequestRelayout();
1079 const Vector4& Controller::GetUnderlineColor() const
1081 return mImpl->mModel->mVisualModel->GetUnderlineColor();
1084 void Controller::SetUnderlineEnabled(bool enabled)
1086 mImpl->mModel->mVisualModel->SetUnderlineEnabled(enabled);
1088 mImpl->RequestRelayout();
1091 bool Controller::IsUnderlineEnabled() const
1093 return mImpl->mModel->mVisualModel->IsUnderlineEnabled();
1096 void Controller::SetUnderlineHeight(float height)
1098 mImpl->mModel->mVisualModel->SetUnderlineHeight(height);
1100 mImpl->RequestRelayout();
1103 float Controller::GetUnderlineHeight() const
1105 return mImpl->mModel->mVisualModel->GetUnderlineHeight();
1108 void Controller::SetOutlineColor(const Vector4& color)
1110 mImpl->mModel->mVisualModel->SetOutlineColor(color);
1112 mImpl->RequestRelayout();
1115 const Vector4& Controller::GetOutlineColor() const
1117 return mImpl->mModel->mVisualModel->GetOutlineColor();
1120 void Controller::SetOutlineWidth(uint16_t width)
1122 mImpl->mModel->mVisualModel->SetOutlineWidth(width);
1124 mImpl->RequestRelayout();
1127 uint16_t Controller::GetOutlineWidth() const
1129 return mImpl->mModel->mVisualModel->GetOutlineWidth();
1132 void Controller::SetBackgroundColor(const Vector4& color)
1134 mImpl->mModel->mVisualModel->SetBackgroundColor(color);
1136 mImpl->RequestRelayout();
1139 const Vector4& Controller::GetBackgroundColor() const
1141 return mImpl->mModel->mVisualModel->GetBackgroundColor();
1144 void Controller::SetBackgroundEnabled(bool enabled)
1146 mImpl->mModel->mVisualModel->SetBackgroundEnabled(enabled);
1148 mImpl->RequestRelayout();
1151 bool Controller::IsBackgroundEnabled() const
1153 return mImpl->mModel->mVisualModel->IsBackgroundEnabled();
1156 void Controller::SetDefaultEmbossProperties(const std::string& embossProperties)
1158 if(NULL == mImpl->mEmbossDefaults)
1160 mImpl->mEmbossDefaults = new EmbossDefaults();
1163 mImpl->mEmbossDefaults->properties = embossProperties;
1166 const std::string& Controller::GetDefaultEmbossProperties() const
1168 if(NULL != mImpl->mEmbossDefaults)
1170 return mImpl->mEmbossDefaults->properties;
1173 return EMPTY_STRING;
1176 void Controller::SetDefaultOutlineProperties(const std::string& outlineProperties)
1178 if(NULL == mImpl->mOutlineDefaults)
1180 mImpl->mOutlineDefaults = new OutlineDefaults();
1183 mImpl->mOutlineDefaults->properties = outlineProperties;
1186 const std::string& Controller::GetDefaultOutlineProperties() const
1188 if(NULL != mImpl->mOutlineDefaults)
1190 return mImpl->mOutlineDefaults->properties;
1193 return EMPTY_STRING;
1196 bool Controller::SetDefaultLineSpacing(float lineSpacing)
1198 if(std::fabs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000)
1200 mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
1201 mImpl->mRecalculateNaturalSize = true;
1207 float Controller::GetDefaultLineSpacing() const
1209 return mImpl->mLayoutEngine.GetDefaultLineSpacing();
1212 bool Controller::SetDefaultLineSize(float lineSize)
1214 if(std::fabs(lineSize - mImpl->mLayoutEngine.GetDefaultLineSize()) > Math::MACHINE_EPSILON_1000)
1216 mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
1217 mImpl->mRecalculateNaturalSize = true;
1223 float Controller::GetDefaultLineSize() const
1225 return mImpl->mLayoutEngine.GetDefaultLineSize();
1228 void Controller::SetInputColor(const Vector4& color)
1230 if(NULL != mImpl->mEventData)
1232 mImpl->mEventData->mInputStyle.textColor = color;
1233 mImpl->mEventData->mInputStyle.isDefaultColor = false;
1235 if(EventData::SELECTING == mImpl->mEventData->mState || EventData::EDITING == mImpl->mEventData->mState || EventData::INACTIVE == mImpl->mEventData->mState)
1237 if(EventData::SELECTING == mImpl->mEventData->mState)
1239 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1241 // Get start and end position of selection
1242 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1243 const Length lengthOfSelectedText = (handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition) - startOfSelectedText;
1245 // Add the color run.
1246 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1247 mImpl->mModel->mLogicalModel->mColorRuns.Resize(numberOfRuns + 1u);
1249 ColorRun& colorRun = *(mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns);
1250 colorRun.color = color;
1251 colorRun.characterRun.characterIndex = startOfSelectedText;
1252 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1254 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1255 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1256 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1260 mImpl->mTextUpdateInfo.mCharacterIndex = 0;
1261 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
1262 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
1265 // Request to relayout.
1266 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | COLOR);
1267 mImpl->RequestRelayout();
1272 const Vector4& Controller::GetInputColor() const
1274 if(NULL != mImpl->mEventData)
1276 return mImpl->mEventData->mInputStyle.textColor;
1279 // Return the default text's color if there is no EventData.
1280 return mImpl->mTextColor;
1283 void Controller::SetInputFontFamily(const std::string& fontFamily)
1285 InputFontHandler::SetInputFontFamily(*this, fontFamily);
1288 const std::string& Controller::GetInputFontFamily() const
1290 return InputFontHandler::GetInputFontFamily(*this);
1293 void Controller::SetInputFontWeight(FontWeight weight)
1295 InputFontHandler::SetInputFontWeight(*this, weight);
1298 bool Controller::IsInputFontWeightDefined() const
1300 return InputFontHandler::IsInputFontWeightDefined(*this);
1303 FontWeight Controller::GetInputFontWeight() const
1305 return InputFontHandler::GetInputFontWeight(*this);
1308 void Controller::SetInputFontWidth(FontWidth width)
1310 InputFontHandler::SetInputFontWidth(*this, width);
1313 bool Controller::IsInputFontWidthDefined() const
1315 return InputFontHandler::IsInputFontWidthDefined(*this);
1318 FontWidth Controller::GetInputFontWidth() const
1320 return InputFontHandler::GetInputFontWidth(*this);
1323 void Controller::SetInputFontSlant(FontSlant slant)
1325 InputFontHandler::SetInputFontSlant(*this, slant);
1328 bool Controller::IsInputFontSlantDefined() const
1330 return InputFontHandler::IsInputFontSlantDefined(*this);
1333 FontSlant Controller::GetInputFontSlant() const
1335 return InputFontHandler::GetInputFontSlant(*this);
1338 void Controller::SetInputFontPointSize(float size)
1340 InputFontHandler::SetInputFontPointSize(*this, size);
1343 float Controller::GetInputFontPointSize() const
1345 return InputFontHandler::GetInputFontPointSize(*this);
1348 void Controller::SetInputLineSpacing(float lineSpacing)
1350 if(NULL != mImpl->mEventData)
1352 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1353 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1357 float Controller::GetInputLineSpacing() const
1359 if(NULL != mImpl->mEventData)
1361 return mImpl->mEventData->mInputStyle.lineSpacing;
1367 void Controller::SetInputShadowProperties(const std::string& shadowProperties)
1369 if(NULL != mImpl->mEventData)
1371 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1375 const std::string& Controller::GetInputShadowProperties() const
1377 if(NULL != mImpl->mEventData)
1379 return mImpl->mEventData->mInputStyle.shadowProperties;
1382 return EMPTY_STRING;
1385 void Controller::SetInputUnderlineProperties(const std::string& underlineProperties)
1387 if(NULL != mImpl->mEventData)
1389 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1393 const std::string& Controller::GetInputUnderlineProperties() const
1395 if(NULL != mImpl->mEventData)
1397 return mImpl->mEventData->mInputStyle.underlineProperties;
1400 return EMPTY_STRING;
1403 void Controller::SetInputEmbossProperties(const std::string& embossProperties)
1405 if(NULL != mImpl->mEventData)
1407 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1411 const std::string& Controller::GetInputEmbossProperties() const
1413 if(NULL != mImpl->mEventData)
1415 return mImpl->mEventData->mInputStyle.embossProperties;
1418 return GetDefaultEmbossProperties();
1421 void Controller::SetInputOutlineProperties(const std::string& outlineProperties)
1423 if(NULL != mImpl->mEventData)
1425 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1429 const std::string& Controller::GetInputOutlineProperties() const
1431 if(NULL != mImpl->mEventData)
1433 return mImpl->mEventData->mInputStyle.outlineProperties;
1436 return GetDefaultOutlineProperties();
1439 void Controller::SetInputModePassword(bool passwordInput)
1441 if(NULL != mImpl->mEventData)
1443 mImpl->mEventData->mPasswordInput = passwordInput;
1447 bool Controller::IsInputModePassword()
1449 if(NULL != mImpl->mEventData)
1451 return mImpl->mEventData->mPasswordInput;
1456 void Controller::SetNoTextDoubleTapAction(NoTextTap::Action action)
1458 if(NULL != mImpl->mEventData)
1460 mImpl->mEventData->mDoubleTapAction = action;
1464 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1466 NoTextTap::Action action = NoTextTap::NO_ACTION;
1468 if(NULL != mImpl->mEventData)
1470 action = mImpl->mEventData->mDoubleTapAction;
1476 void Controller::SetNoTextLongPressAction(NoTextTap::Action action)
1478 if(NULL != mImpl->mEventData)
1480 mImpl->mEventData->mLongPressAction = action;
1484 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1486 NoTextTap::Action action = NoTextTap::NO_ACTION;
1488 if(NULL != mImpl->mEventData)
1490 action = mImpl->mEventData->mLongPressAction;
1496 bool Controller::IsUnderlineSetByString()
1498 return mImpl->mUnderlineSetByString;
1501 void Controller::UnderlineSetByString(bool setByString)
1503 mImpl->mUnderlineSetByString = setByString;
1506 bool Controller::IsShadowSetByString()
1508 return mImpl->mShadowSetByString;
1511 void Controller::ShadowSetByString(bool setByString)
1513 mImpl->mShadowSetByString = setByString;
1516 bool Controller::IsOutlineSetByString()
1518 return mImpl->mOutlineSetByString;
1521 void Controller::OutlineSetByString(bool setByString)
1523 mImpl->mOutlineSetByString = setByString;
1526 bool Controller::IsFontStyleSetByString()
1528 return mImpl->mFontStyleSetByString;
1531 void Controller::FontStyleSetByString(bool setByString)
1533 mImpl->mFontStyleSetByString = setByString;
1536 // public : Queries & retrieves.
1538 Layout::Engine& Controller::GetLayoutEngine()
1540 return mImpl->mLayoutEngine;
1543 View& Controller::GetView()
1545 return mImpl->mView;
1548 Vector3 Controller::GetNaturalSize()
1550 return Relayouter::GetNaturalSize(*this);
1553 bool Controller::CheckForTextFit(float pointSize, Size& layoutSize)
1555 return Relayouter::CheckForTextFit(*this, pointSize, layoutSize);
1558 void Controller::FitPointSizeforLayout(Size layoutSize)
1560 Relayouter::FitPointSizeforLayout(*this, layoutSize);
1563 float Controller::GetHeightForWidth(float width)
1565 return Relayouter::GetHeightForWidth(*this, width);
1568 int Controller::GetLineCount(float width)
1570 GetHeightForWidth(width);
1571 int numberofLines = mImpl->mModel->GetNumberOfLines();
1572 return numberofLines;
1575 const ModelInterface* const Controller::GetTextModel() const
1577 return mImpl->mModel.Get();
1580 float Controller::GetScrollAmountByUserInput()
1582 float scrollAmount = 0.0f;
1584 if(NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1586 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1587 mImpl->mEventData->mCheckScrollAmount = false;
1589 return scrollAmount;
1592 bool Controller::GetTextScrollInfo(float& scrollPosition, float& controlHeight, float& layoutHeight)
1594 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1597 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1598 layoutHeight = layout.height;
1599 scrollPosition = mImpl->mModel->mScrollPosition.y;
1600 isScrolled = !Equals(mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1);
1604 void Controller::SetHiddenInputOption(const Property::Map& options)
1606 if(NULL == mImpl->mHiddenInput)
1608 mImpl->mHiddenInput = new HiddenText(this);
1610 mImpl->mHiddenInput->SetProperties(options);
1613 void Controller::GetHiddenInputOption(Property::Map& options)
1615 if(NULL != mImpl->mHiddenInput)
1617 mImpl->mHiddenInput->GetProperties(options);
1621 void Controller::SetInputFilterOption(const Property::Map& options)
1623 if(!mImpl->mInputFilter)
1625 mImpl->mInputFilter = std::unique_ptr<InputFilter>(new InputFilter());
1627 mImpl->mInputFilter->SetProperties(options);
1630 void Controller::GetInputFilterOption(Property::Map& options)
1632 if(NULL != mImpl->mInputFilter)
1634 mImpl->mInputFilter->GetProperties(options);
1638 void Controller::SetPlaceholderProperty(const Property::Map& map)
1640 PlaceholderHandler::SetPlaceholderProperty(*this, map);
1643 void Controller::GetPlaceholderProperty(Property::Map& map)
1645 PlaceholderHandler::GetPlaceholderProperty(*this, map);
1648 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
1650 // Make sure the model is up-to-date before layouting
1651 ProcessModifyEvents();
1653 if(mImpl->mUpdateTextDirection)
1655 // Operations that can be done only once until the text changes.
1656 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>(CONVERT_TO_UTF32 |
1664 // Set the update info to relayout the whole text.
1665 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1666 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1668 // Make sure the model is up-to-date before layouting
1669 mImpl->UpdateModel(onlyOnceOperations);
1671 Vector3 naturalSize;
1672 DoRelayout(Size(MAX_FLOAT, MAX_FLOAT),
1673 static_cast<OperationsMask>(onlyOnceOperations |
1674 LAYOUT | REORDER | UPDATE_DIRECTION),
1675 naturalSize.GetVectorXY());
1677 // Do not do again the only once operations.
1678 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending & ~onlyOnceOperations);
1680 // Clear the update info. This info will be set the next time the text is updated.
1681 mImpl->mTextUpdateInfo.Clear();
1683 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
1684 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1686 mImpl->mUpdateTextDirection = false;
1689 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
1692 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
1694 return mImpl->mModel->GetVerticalLineAlignment();
1697 void Controller::SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment)
1699 mImpl->mModel->mVerticalLineAlignment = alignment;
1702 // public : Relayout.
1704 Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection)
1706 return Relayouter::Relayout(*this, size, layoutDirection);
1709 void Controller::RequestRelayout()
1711 mImpl->RequestRelayout();
1714 // public : Input style change signals.
1716 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1718 return (NULL == mImpl->mEventData) || (0u == mImpl->mEventData->mInputStyleChangedQueue.Count());
1721 void Controller::ProcessInputStyleChangedSignals()
1723 if(NULL == mImpl->mEventData)
1729 for(Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
1730 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
1734 const InputStyle::Mask mask = *it;
1736 if(NULL != mImpl->mEditableControlInterface)
1738 // Emit the input style changed signal.
1739 mImpl->mEditableControlInterface->InputStyleChanged(mask);
1743 mImpl->mEventData->mInputStyleChangedQueue.Clear();
1746 // public : Text-input Event Queuing.
1748 void Controller::KeyboardFocusGainEvent()
1750 EventHandler::KeyboardFocusGainEvent(*this);
1753 void Controller::KeyboardFocusLostEvent()
1755 EventHandler::KeyboardFocusLostEvent(*this);
1758 bool Controller::KeyEvent(const Dali::KeyEvent& keyEvent)
1760 return EventHandler::KeyEvent(*this, keyEvent);
1763 void Controller::AnchorEvent(float x, float y)
1765 EventHandler::AnchorEvent(*this, x, y);
1768 void Controller::TapEvent(unsigned int tapCount, float x, float y)
1770 EventHandler::TapEvent(*this, tapCount, x, y);
1773 void Controller::PanEvent(GestureState state, const Vector2& displacement)
1775 EventHandler::PanEvent(*this, state, displacement);
1778 void Controller::LongPressEvent(GestureState state, float x, float y)
1780 EventHandler::LongPressEvent(*this, state, x, y);
1783 void Controller::SelectEvent(float x, float y, SelectionType selectType)
1785 EventHandler::SelectEvent(*this, x, y, selectType);
1788 void Controller::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1790 if(mImpl->mEventData)
1792 mImpl->mEventData->mCheckScrollAmount = true;
1793 mImpl->mEventData->mIsLeftHandleSelected = true;
1794 mImpl->mEventData->mIsRightHandleSelected = true;
1795 mImpl->SetTextSelectionRange(start, end);
1796 mImpl->RequestRelayout();
1797 KeyboardFocusGainEvent();
1801 Uint32Pair Controller::GetTextSelectionRange() const
1803 return mImpl->GetTextSelectionRange();
1806 CharacterIndex Controller::GetPrimaryCursorPosition() const
1808 return mImpl->GetPrimaryCursorPosition();
1811 bool Controller::SetPrimaryCursorPosition(CharacterIndex index)
1813 if(mImpl->mEventData)
1815 mImpl->mEventData->mCheckScrollAmount = true;
1816 mImpl->mEventData->mIsLeftHandleSelected = true;
1817 mImpl->mEventData->mIsRightHandleSelected = true;
1818 mImpl->mEventData->mCheckScrollAmount = true;
1819 if(mImpl->SetPrimaryCursorPosition(index))
1821 KeyboardFocusGainEvent();
1828 void Controller::SelectWholeText()
1830 SelectEvent(0.f, 0.f, SelectionType::ALL);
1833 void Controller::SelectNone()
1835 SelectEvent(0.f, 0.f, SelectionType::NONE);
1838 string Controller::GetSelectedText() const
1841 if(EventData::SELECTING == mImpl->mEventData->mState)
1843 mImpl->RetrieveSelection(text, false);
1848 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1850 return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent);
1853 void Controller::PasteClipboardItemEvent()
1855 EventHandler::PasteClipboardItemEvent(*this);
1858 // protected : Inherit from Text::Decorator::ControllerInterface.
1860 void Controller::GetTargetSize(Vector2& targetSize)
1862 targetSize = mImpl->mModel->mVisualModel->mControlSize;
1865 void Controller::AddDecoration(Actor& actor, bool needsClipping)
1867 if(NULL != mImpl->mEditableControlInterface)
1869 mImpl->mEditableControlInterface->AddDecoration(actor, needsClipping);
1873 bool Controller::IsEditable() const
1875 return mImpl->IsEditable();
1878 void Controller::SetEditable(bool editable)
1880 mImpl->SetEditable(editable);
1881 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
1883 mImpl->mEventData->mDecorator->SetEditable(editable);
1887 void Controller::ScrollBy(Vector2 scroll)
1889 if(mImpl->mEventData && (fabs(scroll.x) > Math::MACHINE_EPSILON_0 || fabs(scroll.y) > Math::MACHINE_EPSILON_0))
1891 const Vector2& layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1892 const Vector2 currentScroll = mImpl->mModel->mScrollPosition;
1894 scroll.x = -scroll.x;
1895 scroll.y = -scroll.y;
1897 if(fabs(scroll.x) > Math::MACHINE_EPSILON_0)
1899 mImpl->mModel->mScrollPosition.x += scroll.x;
1900 mImpl->ClampHorizontalScroll(layoutSize);
1903 if(fabs(scroll.y) > Math::MACHINE_EPSILON_0)
1905 mImpl->mModel->mScrollPosition.y += scroll.y;
1906 mImpl->ClampVerticalScroll(layoutSize);
1909 if(mImpl->mModel->mScrollPosition != currentScroll)
1911 mImpl->mEventData->mDecorator->UpdatePositions(mImpl->mModel->mScrollPosition - currentScroll);
1912 mImpl->RequestRelayout();
1917 float Controller::GetHorizontalScrollPosition()
1919 if(mImpl->mEventData)
1921 //scroll values are negative internally so we convert them to positive numbers
1922 return -mImpl->mModel->mScrollPosition.x;
1927 float Controller::GetVerticalScrollPosition()
1929 if(mImpl->mEventData)
1931 //scroll values are negative internally so we convert them to positive numbers
1932 return -mImpl->mModel->mScrollPosition.y;
1937 void Controller::DecorationEvent(HandleType handleType, HandleState state, float x, float y)
1939 EventHandler::DecorationEvent(*this, handleType, state, x, y);
1942 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
1944 void Controller::TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button)
1946 EventHandler::TextPopupButtonTouched(*this, button);
1949 void Controller::DisplayTimeExpired()
1951 mImpl->mEventData->mUpdateCursorPosition = true;
1952 // Apply modifications to the model
1953 mImpl->mOperationsPending = ALL_OPERATIONS;
1955 mImpl->RequestRelayout();
1958 // private : Update.
1960 void Controller::InsertText(const std::string& text, Controller::InsertType type)
1962 TextUpdater::InsertText(*this, text, type);
1965 void Controller::PasteText(const std::string& stringToPaste)
1967 TextUpdater::PasteText(*this, stringToPaste);
1970 bool Controller::RemoveText(int cursorOffset,
1971 int numberOfCharacters,
1972 UpdateInputStyleType type)
1974 return TextUpdater::RemoveText(*this, cursorOffset, numberOfCharacters, type);
1977 bool Controller::RemoveSelectedText()
1979 return TextUpdater::RemoveSelectedText(*this);
1982 void Controller::InsertTextAnchor(int numberOfCharacters,
1983 CharacterIndex previousCursorIndex)
1985 TextUpdater::InsertTextAnchor(*this, numberOfCharacters, previousCursorIndex);
1988 void Controller::RemoveTextAnchor(int cursorOffset,
1989 int numberOfCharacters,
1990 CharacterIndex previousCursorIndex)
1992 TextUpdater::RemoveTextAnchor(*this, cursorOffset, numberOfCharacters, previousCursorIndex);
1995 // private : Relayout.
1997 bool Controller::DoRelayout(const Size& size,
1998 OperationsMask operationsRequired,
2001 return Relayouter::DoRelayout(*this, size, operationsRequired, layoutSize);
2004 void Controller::CalculateVerticalOffset(const Size& controlSize)
2006 Relayouter::CalculateVerticalOffset(*this, controlSize);
2009 // private : Events.
2011 void Controller::ProcessModifyEvents()
2013 EventHandler::ProcessModifyEvents(*this);
2016 void Controller::TextReplacedEvent()
2018 EventHandler::TextReplacedEvent(*this);
2021 void Controller::TextInsertedEvent()
2023 EventHandler::TextInsertedEvent(*this);
2026 void Controller::TextDeletedEvent()
2028 EventHandler::TextDeletedEvent(*this);
2031 bool Controller::DeleteEvent(int keyCode)
2033 return EventHandler::DeleteEvent(*this, keyCode);
2036 // private : Helpers.
2038 void Controller::ResetText()
2040 TextUpdater::ResetText(*this);
2043 void Controller::ShowPlaceholderText()
2045 PlaceholderHandler::ShowPlaceholderText(*this);
2048 void Controller::ClearFontData()
2050 if(mImpl->mFontDefaults)
2052 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
2055 // Set flags to update the model.
2056 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2057 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2058 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2060 mImpl->mTextUpdateInfo.mClearAll = true;
2061 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2062 mImpl->mRecalculateNaturalSize = true;
2064 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
2070 UPDATE_LAYOUT_SIZE |
2075 void Controller::ClearStyleData()
2077 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
2078 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
2081 void Controller::ResetCursorPosition(CharacterIndex cursorIndex)
2083 // Reset the cursor position
2084 if(NULL != mImpl->mEventData)
2086 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
2088 // Update the cursor if it's in editing mode.
2089 if(EventData::IsEditingState(mImpl->mEventData->mState))
2091 mImpl->mEventData->mUpdateCursorPosition = true;
2096 CharacterIndex Controller::GetCursorPosition()
2098 if(!mImpl->mEventData)
2101 return mImpl->mEventData->mPrimaryCursorPosition;
2104 void Controller::ResetScrollPosition()
2106 if(NULL != mImpl->mEventData)
2108 // Reset the scroll position.
2109 mImpl->mModel->mScrollPosition = Vector2::ZERO;
2110 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2114 void Controller::SetControlInterface(ControlInterface* controlInterface)
2116 mImpl->mControlInterface = controlInterface;
2119 void Controller::SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface)
2121 mImpl->mAnchorControlInterface = anchorControlInterface;
2124 bool Controller::ShouldClearFocusOnEscape() const
2126 return mImpl->mShouldClearFocusOnEscape;
2129 Actor Controller::CreateBackgroundActor()
2131 return mImpl->CreateBackgroundActor();
2134 // private : Private contructors & copy operator.
2136 Controller::Controller()
2137 : Controller(nullptr, nullptr, nullptr, nullptr)
2141 Controller::Controller(ControlInterface* controlInterface)
2142 : Controller(controlInterface, nullptr, nullptr, nullptr)
2146 Controller::Controller(ControlInterface* controlInterface,
2147 EditableControlInterface* editableControlInterface,
2148 SelectableControlInterface* selectableControlInterface,
2149 AnchorControlInterface* anchorControlInterface)
2150 : mImpl(new Controller::Impl(controlInterface, editableControlInterface, selectableControlInterface, anchorControlInterface))
2154 // The copy constructor and operator are left unimplemented.
2156 // protected : Destructor.
2158 Controller::~Controller()
2165 } // namespace Toolkit