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 const bool handlesCrossed = mImpl->mEventData->mLeftSelectionPosition > mImpl->mEventData->mRightSelectionPosition;
1239 // Get start and end position of selection
1240 const CharacterIndex startOfSelectedText = handlesCrossed ? mImpl->mEventData->mRightSelectionPosition : mImpl->mEventData->mLeftSelectionPosition;
1241 const Length lengthOfSelectedText = (handlesCrossed ? mImpl->mEventData->mLeftSelectionPosition : mImpl->mEventData->mRightSelectionPosition) - startOfSelectedText;
1243 // Add the color run.
1244 const VectorBase::SizeType numberOfRuns = mImpl->mModel->mLogicalModel->mColorRuns.Count();
1245 mImpl->mModel->mLogicalModel->mColorRuns.Resize(numberOfRuns + 1u);
1247 ColorRun& colorRun = *(mImpl->mModel->mLogicalModel->mColorRuns.Begin() + numberOfRuns);
1248 colorRun.color = color;
1249 colorRun.characterRun.characterIndex = startOfSelectedText;
1250 colorRun.characterRun.numberOfCharacters = lengthOfSelectedText;
1252 // Request to relayout.
1253 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | COLOR);
1254 mImpl->RequestRelayout();
1256 mImpl->mTextUpdateInfo.mCharacterIndex = startOfSelectedText;
1257 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = lengthOfSelectedText;
1258 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = lengthOfSelectedText;
1263 const Vector4& Controller::GetInputColor() const
1265 if(NULL != mImpl->mEventData)
1267 return mImpl->mEventData->mInputStyle.textColor;
1270 // Return the default text's color if there is no EventData.
1271 return mImpl->mTextColor;
1274 void Controller::SetInputFontFamily(const std::string& fontFamily)
1276 InputFontHandler::SetInputFontFamily(*this, fontFamily);
1279 const std::string& Controller::GetInputFontFamily() const
1281 return InputFontHandler::GetInputFontFamily(*this);
1284 void Controller::SetInputFontWeight(FontWeight weight)
1286 InputFontHandler::SetInputFontWeight(*this, weight);
1289 bool Controller::IsInputFontWeightDefined() const
1291 return InputFontHandler::IsInputFontWeightDefined(*this);
1294 FontWeight Controller::GetInputFontWeight() const
1296 return InputFontHandler::GetInputFontWeight(*this);
1299 void Controller::SetInputFontWidth(FontWidth width)
1301 InputFontHandler::SetInputFontWidth(*this, width);
1304 bool Controller::IsInputFontWidthDefined() const
1306 return InputFontHandler::IsInputFontWidthDefined(*this);
1309 FontWidth Controller::GetInputFontWidth() const
1311 return InputFontHandler::GetInputFontWidth(*this);
1314 void Controller::SetInputFontSlant(FontSlant slant)
1316 InputFontHandler::SetInputFontSlant(*this, slant);
1319 bool Controller::IsInputFontSlantDefined() const
1321 return InputFontHandler::IsInputFontSlantDefined(*this);
1324 FontSlant Controller::GetInputFontSlant() const
1326 return InputFontHandler::GetInputFontSlant(*this);
1329 void Controller::SetInputFontPointSize(float size)
1331 InputFontHandler::SetInputFontPointSize(*this, size);
1334 float Controller::GetInputFontPointSize() const
1336 return InputFontHandler::GetInputFontPointSize(*this);
1339 void Controller::SetInputLineSpacing(float lineSpacing)
1341 if(NULL != mImpl->mEventData)
1343 mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
1344 mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
1348 float Controller::GetInputLineSpacing() const
1350 if(NULL != mImpl->mEventData)
1352 return mImpl->mEventData->mInputStyle.lineSpacing;
1358 void Controller::SetInputShadowProperties(const std::string& shadowProperties)
1360 if(NULL != mImpl->mEventData)
1362 mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
1366 const std::string& Controller::GetInputShadowProperties() const
1368 if(NULL != mImpl->mEventData)
1370 return mImpl->mEventData->mInputStyle.shadowProperties;
1373 return EMPTY_STRING;
1376 void Controller::SetInputUnderlineProperties(const std::string& underlineProperties)
1378 if(NULL != mImpl->mEventData)
1380 mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
1384 const std::string& Controller::GetInputUnderlineProperties() const
1386 if(NULL != mImpl->mEventData)
1388 return mImpl->mEventData->mInputStyle.underlineProperties;
1391 return EMPTY_STRING;
1394 void Controller::SetInputEmbossProperties(const std::string& embossProperties)
1396 if(NULL != mImpl->mEventData)
1398 mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
1402 const std::string& Controller::GetInputEmbossProperties() const
1404 if(NULL != mImpl->mEventData)
1406 return mImpl->mEventData->mInputStyle.embossProperties;
1409 return GetDefaultEmbossProperties();
1412 void Controller::SetInputOutlineProperties(const std::string& outlineProperties)
1414 if(NULL != mImpl->mEventData)
1416 mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
1420 const std::string& Controller::GetInputOutlineProperties() const
1422 if(NULL != mImpl->mEventData)
1424 return mImpl->mEventData->mInputStyle.outlineProperties;
1427 return GetDefaultOutlineProperties();
1430 void Controller::SetInputModePassword(bool passwordInput)
1432 if(NULL != mImpl->mEventData)
1434 mImpl->mEventData->mPasswordInput = passwordInput;
1438 bool Controller::IsInputModePassword()
1440 if(NULL != mImpl->mEventData)
1442 return mImpl->mEventData->mPasswordInput;
1447 void Controller::SetNoTextDoubleTapAction(NoTextTap::Action action)
1449 if(NULL != mImpl->mEventData)
1451 mImpl->mEventData->mDoubleTapAction = action;
1455 Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
1457 NoTextTap::Action action = NoTextTap::NO_ACTION;
1459 if(NULL != mImpl->mEventData)
1461 action = mImpl->mEventData->mDoubleTapAction;
1467 void Controller::SetNoTextLongPressAction(NoTextTap::Action action)
1469 if(NULL != mImpl->mEventData)
1471 mImpl->mEventData->mLongPressAction = action;
1475 Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
1477 NoTextTap::Action action = NoTextTap::NO_ACTION;
1479 if(NULL != mImpl->mEventData)
1481 action = mImpl->mEventData->mLongPressAction;
1487 bool Controller::IsUnderlineSetByString()
1489 return mImpl->mUnderlineSetByString;
1492 void Controller::UnderlineSetByString(bool setByString)
1494 mImpl->mUnderlineSetByString = setByString;
1497 bool Controller::IsShadowSetByString()
1499 return mImpl->mShadowSetByString;
1502 void Controller::ShadowSetByString(bool setByString)
1504 mImpl->mShadowSetByString = setByString;
1507 bool Controller::IsOutlineSetByString()
1509 return mImpl->mOutlineSetByString;
1512 void Controller::OutlineSetByString(bool setByString)
1514 mImpl->mOutlineSetByString = setByString;
1517 bool Controller::IsFontStyleSetByString()
1519 return mImpl->mFontStyleSetByString;
1522 void Controller::FontStyleSetByString(bool setByString)
1524 mImpl->mFontStyleSetByString = setByString;
1527 // public : Queries & retrieves.
1529 Layout::Engine& Controller::GetLayoutEngine()
1531 return mImpl->mLayoutEngine;
1534 View& Controller::GetView()
1536 return mImpl->mView;
1539 Vector3 Controller::GetNaturalSize()
1541 return Relayouter::GetNaturalSize(*this);
1544 bool Controller::CheckForTextFit(float pointSize, Size& layoutSize)
1546 return Relayouter::CheckForTextFit(*this, pointSize, layoutSize);
1549 void Controller::FitPointSizeforLayout(Size layoutSize)
1551 Relayouter::FitPointSizeforLayout(*this, layoutSize);
1554 float Controller::GetHeightForWidth(float width)
1556 return Relayouter::GetHeightForWidth(*this, width);
1559 int Controller::GetLineCount(float width)
1561 GetHeightForWidth(width);
1562 int numberofLines = mImpl->mModel->GetNumberOfLines();
1563 return numberofLines;
1566 const ModelInterface* const Controller::GetTextModel() const
1568 return mImpl->mModel.Get();
1571 float Controller::GetScrollAmountByUserInput()
1573 float scrollAmount = 0.0f;
1575 if(NULL != mImpl->mEventData && mImpl->mEventData->mCheckScrollAmount)
1577 scrollAmount = mImpl->mModel->mScrollPosition.y - mImpl->mModel->mScrollPositionLast.y;
1578 mImpl->mEventData->mCheckScrollAmount = false;
1580 return scrollAmount;
1583 bool Controller::GetTextScrollInfo(float& scrollPosition, float& controlHeight, float& layoutHeight)
1585 const Vector2& layout = mImpl->mModel->mVisualModel->GetLayoutSize();
1588 controlHeight = mImpl->mModel->mVisualModel->mControlSize.height;
1589 layoutHeight = layout.height;
1590 scrollPosition = mImpl->mModel->mScrollPosition.y;
1591 isScrolled = !Equals(mImpl->mModel->mScrollPosition.y, mImpl->mModel->mScrollPositionLast.y, Math::MACHINE_EPSILON_1);
1595 void Controller::SetHiddenInputOption(const Property::Map& options)
1597 if(NULL == mImpl->mHiddenInput)
1599 mImpl->mHiddenInput = new HiddenText(this);
1601 mImpl->mHiddenInput->SetProperties(options);
1604 void Controller::GetHiddenInputOption(Property::Map& options)
1606 if(NULL != mImpl->mHiddenInput)
1608 mImpl->mHiddenInput->GetProperties(options);
1612 void Controller::SetPlaceholderProperty(const Property::Map& map)
1614 PlaceholderHandler::SetPlaceholderProperty(*this, map);
1617 void Controller::GetPlaceholderProperty(Property::Map& map)
1619 PlaceholderHandler::GetPlaceholderProperty(*this, map);
1622 Toolkit::DevelText::TextDirection::Type Controller::GetTextDirection()
1624 // Make sure the model is up-to-date before layouting
1625 ProcessModifyEvents();
1627 if(mImpl->mUpdateTextDirection)
1629 // Operations that can be done only once until the text changes.
1630 const OperationsMask onlyOnceOperations = static_cast<OperationsMask>(CONVERT_TO_UTF32 |
1638 // Set the update info to relayout the whole text.
1639 mImpl->mTextUpdateInfo.mParagraphCharacterIndex = 0u;
1640 mImpl->mTextUpdateInfo.mRequestedNumberOfCharacters = mImpl->mModel->mLogicalModel->mText.Count();
1642 // Make sure the model is up-to-date before layouting
1643 mImpl->UpdateModel(onlyOnceOperations);
1645 Vector3 naturalSize;
1646 DoRelayout(Size(MAX_FLOAT, MAX_FLOAT),
1647 static_cast<OperationsMask>(onlyOnceOperations |
1648 LAYOUT | REORDER | UPDATE_DIRECTION),
1649 naturalSize.GetVectorXY());
1651 // Do not do again the only once operations.
1652 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending & ~onlyOnceOperations);
1654 // Clear the update info. This info will be set the next time the text is updated.
1655 mImpl->mTextUpdateInfo.Clear();
1657 // FullRelayoutNeeded should be true because DoRelayout is MAX_FLOAT, MAX_FLOAT.
1658 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
1660 mImpl->mUpdateTextDirection = false;
1663 return mImpl->mIsTextDirectionRTL ? Toolkit::DevelText::TextDirection::RIGHT_TO_LEFT : Toolkit::DevelText::TextDirection::LEFT_TO_RIGHT;
1666 Toolkit::DevelText::VerticalLineAlignment::Type Controller::GetVerticalLineAlignment() const
1668 return mImpl->mModel->GetVerticalLineAlignment();
1671 void Controller::SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignment::Type alignment)
1673 mImpl->mModel->mVerticalLineAlignment = alignment;
1676 // public : Relayout.
1678 Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection)
1680 return Relayouter::Relayout(*this, size, layoutDirection);
1683 void Controller::RequestRelayout()
1685 mImpl->RequestRelayout();
1688 // public : Input style change signals.
1690 bool Controller::IsInputStyleChangedSignalsQueueEmpty()
1692 return (NULL == mImpl->mEventData) || (0u == mImpl->mEventData->mInputStyleChangedQueue.Count());
1695 void Controller::ProcessInputStyleChangedSignals()
1697 if(NULL == mImpl->mEventData)
1703 for(Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
1704 endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
1708 const InputStyle::Mask mask = *it;
1710 if(NULL != mImpl->mEditableControlInterface)
1712 // Emit the input style changed signal.
1713 mImpl->mEditableControlInterface->InputStyleChanged(mask);
1717 mImpl->mEventData->mInputStyleChangedQueue.Clear();
1720 // public : Text-input Event Queuing.
1722 void Controller::KeyboardFocusGainEvent()
1724 EventHandler::KeyboardFocusGainEvent(*this);
1727 void Controller::KeyboardFocusLostEvent()
1729 EventHandler::KeyboardFocusLostEvent(*this);
1732 bool Controller::KeyEvent(const Dali::KeyEvent& keyEvent)
1734 return EventHandler::KeyEvent(*this, keyEvent);
1737 void Controller::AnchorEvent(float x, float y)
1739 EventHandler::AnchorEvent(*this, x, y);
1742 void Controller::TapEvent(unsigned int tapCount, float x, float y)
1744 EventHandler::TapEvent(*this, tapCount, x, y);
1747 void Controller::PanEvent(GestureState state, const Vector2& displacement)
1749 EventHandler::PanEvent(*this, state, displacement);
1752 void Controller::LongPressEvent(GestureState state, float x, float y)
1754 EventHandler::LongPressEvent(*this, state, x, y);
1757 void Controller::SelectEvent(float x, float y, SelectionType selectType)
1759 EventHandler::SelectEvent(*this, x, y, selectType);
1762 void Controller::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
1764 if(mImpl->mEventData)
1766 mImpl->mEventData->mCheckScrollAmount = true;
1767 mImpl->mEventData->mIsLeftHandleSelected = true;
1768 mImpl->mEventData->mIsRightHandleSelected = true;
1769 mImpl->SetTextSelectionRange(start, end);
1770 mImpl->RequestRelayout();
1771 KeyboardFocusGainEvent();
1775 Uint32Pair Controller::GetTextSelectionRange() const
1777 return mImpl->GetTextSelectionRange();
1780 CharacterIndex Controller::GetPrimaryCursorPosition() const
1782 return mImpl->GetPrimaryCursorPosition();
1785 bool Controller::SetPrimaryCursorPosition(CharacterIndex index)
1787 if(mImpl->mEventData)
1789 mImpl->mEventData->mCheckScrollAmount = true;
1790 mImpl->mEventData->mIsLeftHandleSelected = true;
1791 mImpl->mEventData->mIsRightHandleSelected = true;
1792 mImpl->mEventData->mCheckScrollAmount = true;
1793 if(mImpl->SetPrimaryCursorPosition(index))
1795 KeyboardFocusGainEvent();
1802 void Controller::SelectWholeText()
1804 SelectEvent(0.f, 0.f, SelectionType::ALL);
1807 void Controller::SelectNone()
1809 SelectEvent(0.f, 0.f, SelectionType::NONE);
1812 string Controller::GetSelectedText() const
1815 if(EventData::SELECTING == mImpl->mEventData->mState)
1817 mImpl->RetrieveSelection(text, false);
1822 InputMethodContext::CallbackData Controller::OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
1824 return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent);
1827 void Controller::PasteClipboardItemEvent()
1829 EventHandler::PasteClipboardItemEvent(*this);
1832 // protected : Inherit from Text::Decorator::ControllerInterface.
1834 void Controller::GetTargetSize(Vector2& targetSize)
1836 targetSize = mImpl->mModel->mVisualModel->mControlSize;
1839 void Controller::AddDecoration(Actor& actor, bool needsClipping)
1841 if(NULL != mImpl->mEditableControlInterface)
1843 mImpl->mEditableControlInterface->AddDecoration(actor, needsClipping);
1847 bool Controller::IsEditable() const
1849 return mImpl->IsEditable();
1852 void Controller::SetEditable(bool editable)
1854 mImpl->SetEditable(editable);
1855 if(mImpl->mEventData && mImpl->mEventData->mDecorator)
1857 mImpl->mEventData->mDecorator->SetEditable(editable);
1861 void Controller::ScrollBy(Vector2 scroll)
1863 if(mImpl->mEventData && (fabs(scroll.x) > Math::MACHINE_EPSILON_0 || fabs(scroll.y) > Math::MACHINE_EPSILON_0))
1865 const Vector2& layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
1866 const Vector2 currentScroll = mImpl->mModel->mScrollPosition;
1868 scroll.x = -scroll.x;
1869 scroll.y = -scroll.y;
1871 if(fabs(scroll.x) > Math::MACHINE_EPSILON_0)
1873 mImpl->mModel->mScrollPosition.x += scroll.x;
1874 mImpl->ClampHorizontalScroll(layoutSize);
1877 if(fabs(scroll.y) > Math::MACHINE_EPSILON_0)
1879 mImpl->mModel->mScrollPosition.y += scroll.y;
1880 mImpl->ClampVerticalScroll(layoutSize);
1883 if(mImpl->mModel->mScrollPosition != currentScroll)
1885 mImpl->mEventData->mDecorator->UpdatePositions(mImpl->mModel->mScrollPosition - currentScroll);
1886 mImpl->RequestRelayout();
1891 float Controller::GetHorizontalScrollPosition()
1893 if(mImpl->mEventData)
1895 //scroll values are negative internally so we convert them to positive numbers
1896 return -mImpl->mModel->mScrollPosition.x;
1901 float Controller::GetVerticalScrollPosition()
1903 if(mImpl->mEventData)
1905 //scroll values are negative internally so we convert them to positive numbers
1906 return -mImpl->mModel->mScrollPosition.y;
1911 void Controller::DecorationEvent(HandleType handleType, HandleState state, float x, float y)
1913 EventHandler::DecorationEvent(*this, handleType, state, x, y);
1916 // protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
1918 void Controller::TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button)
1920 EventHandler::TextPopupButtonTouched(*this, button);
1923 void Controller::DisplayTimeExpired()
1925 mImpl->mEventData->mUpdateCursorPosition = true;
1926 // Apply modifications to the model
1927 mImpl->mOperationsPending = ALL_OPERATIONS;
1929 mImpl->RequestRelayout();
1932 // private : Update.
1934 void Controller::InsertText(const std::string& text, Controller::InsertType type)
1936 TextUpdater::InsertText(*this, text, type);
1939 void Controller::PasteText(const std::string& stringToPaste)
1941 TextUpdater::PasteText(*this, stringToPaste);
1944 bool Controller::RemoveText(int cursorOffset,
1945 int numberOfCharacters,
1946 UpdateInputStyleType type)
1948 return TextUpdater::RemoveText(*this, cursorOffset, numberOfCharacters, type);
1951 bool Controller::RemoveSelectedText()
1953 return TextUpdater::RemoveSelectedText(*this);
1956 void Controller::InsertTextAnchor(int numberOfCharacters,
1957 CharacterIndex previousCursorIndex)
1959 TextUpdater::InsertTextAnchor(*this, numberOfCharacters, previousCursorIndex);
1962 void Controller::RemoveTextAnchor(int cursorOffset,
1963 int numberOfCharacters,
1964 CharacterIndex previousCursorIndex)
1966 TextUpdater::RemoveTextAnchor(*this, cursorOffset, numberOfCharacters, previousCursorIndex);
1969 // private : Relayout.
1971 bool Controller::DoRelayout(const Size& size,
1972 OperationsMask operationsRequired,
1975 return Relayouter::DoRelayout(*this, size, operationsRequired, layoutSize);
1978 void Controller::CalculateVerticalOffset(const Size& controlSize)
1980 Relayouter::CalculateVerticalOffset(*this, controlSize);
1983 // private : Events.
1985 void Controller::ProcessModifyEvents()
1987 EventHandler::ProcessModifyEvents(*this);
1990 void Controller::TextReplacedEvent()
1992 EventHandler::TextReplacedEvent(*this);
1995 void Controller::TextInsertedEvent()
1997 EventHandler::TextInsertedEvent(*this);
2000 void Controller::TextDeletedEvent()
2002 EventHandler::TextDeletedEvent(*this);
2005 bool Controller::DeleteEvent(int keyCode)
2007 return EventHandler::DeleteEvent(*this, keyCode);
2010 // private : Helpers.
2012 void Controller::ResetText()
2014 TextUpdater::ResetText(*this);
2017 void Controller::ShowPlaceholderText()
2019 PlaceholderHandler::ShowPlaceholderText(*this);
2022 void Controller::ClearFontData()
2024 if(mImpl->mFontDefaults)
2026 mImpl->mFontDefaults->mFontId = 0u; // Remove old font ID
2029 // Set flags to update the model.
2030 mImpl->mTextUpdateInfo.mCharacterIndex = 0u;
2031 mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
2032 mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
2034 mImpl->mTextUpdateInfo.mClearAll = true;
2035 mImpl->mTextUpdateInfo.mFullRelayoutNeeded = true;
2036 mImpl->mRecalculateNaturalSize = true;
2038 mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
2044 UPDATE_LAYOUT_SIZE |
2049 void Controller::ClearStyleData()
2051 mImpl->mModel->mLogicalModel->mColorRuns.Clear();
2052 mImpl->mModel->mLogicalModel->ClearFontDescriptionRuns();
2055 void Controller::ResetCursorPosition(CharacterIndex cursorIndex)
2057 // Reset the cursor position
2058 if(NULL != mImpl->mEventData)
2060 mImpl->mEventData->mPrimaryCursorPosition = cursorIndex;
2062 // Update the cursor if it's in editing mode.
2063 if(EventData::IsEditingState(mImpl->mEventData->mState))
2065 mImpl->mEventData->mUpdateCursorPosition = true;
2070 CharacterIndex Controller::GetCursorPosition()
2072 if(!mImpl->mEventData)
2075 return mImpl->mEventData->mPrimaryCursorPosition;
2078 void Controller::ResetScrollPosition()
2080 if(NULL != mImpl->mEventData)
2082 // Reset the scroll position.
2083 mImpl->mModel->mScrollPosition = Vector2::ZERO;
2084 mImpl->mEventData->mScrollAfterUpdatePosition = true;
2088 void Controller::SetControlInterface(ControlInterface* controlInterface)
2090 mImpl->mControlInterface = controlInterface;
2093 void Controller::SetAnchorControlInterface(AnchorControlInterface* anchorControlInterface)
2095 mImpl->mAnchorControlInterface = anchorControlInterface;
2098 bool Controller::ShouldClearFocusOnEscape() const
2100 return mImpl->mShouldClearFocusOnEscape;
2103 Actor Controller::CreateBackgroundActor()
2105 return mImpl->CreateBackgroundActor();
2108 // private : Private contructors & copy operator.
2110 Controller::Controller()
2111 : Controller(nullptr, nullptr, nullptr, nullptr)
2115 Controller::Controller(ControlInterface* controlInterface)
2116 : Controller(controlInterface, nullptr, nullptr, nullptr)
2120 Controller::Controller(ControlInterface* controlInterface,
2121 EditableControlInterface* editableControlInterface,
2122 SelectableControlInterface* selectableControlInterface,
2123 AnchorControlInterface* anchorControlInterface)
2124 : mImpl(new Controller::Impl(controlInterface, editableControlInterface, selectableControlInterface, anchorControlInterface))
2128 // The copy constructor and operator are left unimplemented.
2130 // protected : Destructor.
2132 Controller::~Controller()
2139 } // namespace Toolkit