#include <dali-toolkit/internal/text/text-controller.h>
// EXTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
#include <dali/integration-api/debug.h>
#include <memory.h>
#include <cmath>
const std::string EMPTY_STRING("");
-int ConvertPixelToPint(float pixel)
+template<typename Type>
+void EnsureCreated(Type*& object)
{
- unsigned int horizontalDpi = 0u;
- unsigned int verticalDpi = 0u;
- Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
- fontClient.GetDpi(horizontalDpi, verticalDpi);
-
- return (pixel * 72.f) / static_cast<float>(horizontalDpi);
+ if(!object)
+ {
+ object = new Type();
+ }
}
-} // namespace
+template<typename Type>
+void EnsureCreated(std::unique_ptr<Type>& object)
+{
+ if(!object)
+ {
+ object = std::unique_ptr<Type>(new Type());
+ }
+}
-namespace Dali
+template<typename Type, typename Arg1>
+void EnsureCreated(Type*& object, Arg1 arg1)
{
-namespace Toolkit
+ if(!object)
+ {
+ object = new Type(arg1);
+ }
+}
+
+template<typename Type, typename Arg1, typename Arg2>
+void EnsureCreated(Type*& object, Arg1 arg1, Arg2 arg2)
{
-namespace Text
+ if(!object)
+ {
+ object = new Type(arg1, arg2);
+ }
+}
+
+float GetDpi()
{
-// public : Constructor.
+ unsigned int horizontalDpi = 0u;
+ unsigned int verticalDpi = 0u;
+ Dali::TextAbstraction::FontClient fontClient = Dali::TextAbstraction::FontClient::Get();
+ fontClient.GetDpi(horizontalDpi, verticalDpi);
+ return static_cast<float>(horizontalDpi);
+}
-ControllerPtr Controller::New()
+float ConvertPixelToPoint(float pixel)
{
- return ControllerPtr(new Controller());
+ return pixel * 72.0f / GetDpi();
}
-ControllerPtr Controller::New(ControlInterface* controlInterface)
+float ConvertPointToPixel(float point)
{
- return ControllerPtr(new Controller(controlInterface));
+ // Pixel size = Point size * DPI / 72.f
+ return point * GetDpi() / 72.0f;
}
-ControllerPtr Controller::New(ControlInterface* controlInterface,
- EditableControlInterface* editableControlInterface,
- SelectableControlInterface* selectableControlInterface,
- AnchorControlInterface* anchorControlInterface)
+void UpdateCursorPosition(Dali::Toolkit::Text::EventData* eventData)
{
- return ControllerPtr(new Controller(controlInterface,
- editableControlInterface,
- selectableControlInterface,
- anchorControlInterface));
+ if(eventData && Dali::Toolkit::Text::EventData::IsEditingState(eventData->mState))
+ {
+ // Update the cursor position if it's in editing mode
+ eventData->mDecoratorUpdated = true;
+ eventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
+ }
}
-// public : Configure the text controller.
+} // namespace
+
+namespace Dali::Toolkit::Text
+{
void Controller::EnableTextInput(DecoratorPtr decorator, InputMethodContext& inputMethodContext)
{
return;
}
- if(NULL == mImpl->mEventData)
- {
- mImpl->mEventData = new EventData(decorator, inputMethodContext);
- }
+ EnsureCreated(mImpl->mEventData, decorator, inputMethodContext);
}
void Controller::SetGlyphType(TextAbstraction::GlyphType glyphType)
return mImpl->mMarkupProcessorEnabled;
}
+bool Controller::HasAnchors() const
+{
+ return (mImpl->mMarkupProcessorEnabled && mImpl->mModel->mLogicalModel->mAnchors.Count() && mImpl->IsShowingRealText());
+}
+
void Controller::SetAutoScrollEnabled(bool enable)
{
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);
if(mImpl->mLayoutEngine.GetLayout() == Layout::Engine::SINGLE_LINE_BOX)
{
+ mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
+ LAYOUT |
+ ALIGN |
+ UPDATE_LAYOUT_SIZE |
+ REORDER);
+
if(enable)
{
DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled for SINGLE_LINE_BOX\n");
- mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
- LAYOUT |
- ALIGN |
- UPDATE_LAYOUT_SIZE |
- UPDATE_DIRECTION |
- REORDER);
+ mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | UPDATE_DIRECTION);
}
else
{
DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetAutoScrollEnabled Disabling autoscroll\n");
- mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending |
- LAYOUT |
- ALIGN |
- UPDATE_LAYOUT_SIZE |
- REORDER);
}
mImpl->mIsAutoScrollEnabled = enable;
float Controller::GetAutoScrollLineAlignment() const
{
float offset = 0.f;
-
- if(mImpl->mModel->mVisualModel &&
- (0u != mImpl->mModel->mVisualModel->mLines.Count()))
+ if(mImpl->mModel->mVisualModel && (0u != mImpl->mModel->mVisualModel->mLines.Count()))
{
offset = (*mImpl->mModel->mVisualModel->mLines.Begin()).alignmentOffset;
}
-
return offset;
}
void Controller::SetHorizontalScrollEnabled(bool enable)
{
- if((NULL != mImpl->mEventData) &&
- mImpl->mEventData->mDecorator)
+ if(mImpl->mEventData && mImpl->mEventData->mDecorator)
{
mImpl->mEventData->mDecorator->SetHorizontalScrollEnabled(enable);
}
}
+
bool Controller::IsHorizontalScrollEnabled() const
{
- if((NULL != mImpl->mEventData) &&
- mImpl->mEventData->mDecorator)
- {
- return mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
- }
-
- return false;
+ return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsHorizontalScrollEnabled();
}
void Controller::SetVerticalScrollEnabled(bool enable)
{
- if((NULL != mImpl->mEventData) &&
- mImpl->mEventData->mDecorator)
+ if(mImpl->mEventData && mImpl->mEventData->mDecorator)
{
- if(mImpl->mEventData->mDecorator)
- {
- mImpl->mEventData->mDecorator->SetVerticalScrollEnabled(enable);
- }
+ mImpl->mEventData->mDecorator->SetVerticalScrollEnabled(enable);
}
}
bool Controller::IsVerticalScrollEnabled() const
{
- if((NULL != mImpl->mEventData) &&
- mImpl->mEventData->mDecorator)
- {
- return mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
- }
-
- return false;
+ return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsVerticalScrollEnabled();
}
void Controller::SetSmoothHandlePanEnabled(bool enable)
{
- if((NULL != mImpl->mEventData) &&
- mImpl->mEventData->mDecorator)
+ if(mImpl->mEventData && mImpl->mEventData->mDecorator)
{
mImpl->mEventData->mDecorator->SetSmoothHandlePanEnabled(enable);
}
bool Controller::IsSmoothHandlePanEnabled() const
{
- if((NULL != mImpl->mEventData) &&
- mImpl->mEventData->mDecorator)
- {
- return mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
- }
-
- return false;
+ return mImpl->mEventData && mImpl->mEventData->mDecorator && mImpl->mEventData->mDecorator->IsSmoothHandlePanEnabled();
}
void Controller::SetMaximumNumberOfCharacters(Length maxCharacters)
{
DALI_ASSERT_DEBUG(NULL != mImpl->mEventData && "TextInput disabled");
- if(NULL != mImpl->mEventData)
+ if(mImpl->mEventData)
{
mImpl->mEventData->mCursorBlinkEnabled = enable;
- if(!enable &&
- mImpl->mEventData->mDecorator)
+ if(!enable && mImpl->mEventData->mDecorator)
{
mImpl->mEventData->mDecorator->StopCursorBlink();
}
bool Controller::GetEnableCursorBlink() const
{
- if(NULL != mImpl->mEventData)
- {
- return mImpl->mEventData->mCursorBlinkEnabled;
- }
-
- return false;
+ return mImpl->mEventData && mImpl->mEventData->mCursorBlinkEnabled;
}
void Controller::SetMultiLineEnabled(bool enable)
{
// Set the alignment.
mImpl->mModel->mVerticalAlignment = alignment;
-
mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | ALIGN);
-
mImpl->RequestRelayout();
}
}
mImpl->mModel->mIgnoreSpacesAfterText = ignore;
}
-bool Controller::IsMatchSystemLanguageDirection() const
+void Controller::ChangedLayoutDirection()
{
- return mImpl->mModel->mMatchSystemLanguageDirection;
+ mImpl->mIsLayoutDirectionChanged = true;
}
-void Controller::SetMatchSystemLanguageDirection(bool match)
+void Controller::SetMatchLayoutDirection(DevelText::MatchLayoutDirection type)
{
- mImpl->mModel->mMatchSystemLanguageDirection = match;
+ mImpl->mModel->mMatchLayoutDirection = type;
+}
+
+DevelText::MatchLayoutDirection Controller::GetMatchLayoutDirection() const
+{
+ return mImpl->mModel->mMatchLayoutDirection;
}
void Controller::SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection)
mImpl->mLayoutDirection = layoutDirection;
}
+Dali::LayoutDirection::Type Controller::GetLayoutDirection(Dali::Actor& actor) const
+{
+ if(mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::LOCALE ||
+ (mImpl->mModel->mMatchLayoutDirection == DevelText::MatchLayoutDirection::INHERIT && !mImpl->mIsLayoutDirectionChanged))
+ {
+ return static_cast<Dali::LayoutDirection::Type>(DevelWindow::Get(actor).GetRootLayer().GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
+ }
+ else
+ {
+ return static_cast<Dali::LayoutDirection::Type>(actor.GetProperty(Dali::Actor::Property::LAYOUT_DIRECTION).Get<int>());
+ }
+}
+
bool Controller::IsShowingRealText() const
{
return mImpl->IsShowingRealText();
void Controller::SetTextElideEnabled(bool enabled)
{
mImpl->mModel->mElideEnabled = enabled;
+ mImpl->mModel->mVisualModel->SetTextElideEnabled(enabled);
}
bool Controller::IsTextElideEnabled() const
void Controller::SetTextFitMinSize(float minSize, FontSizeType type)
{
- switch(type)
- {
- case POINT_SIZE:
- {
- mImpl->mTextFitMinSize = minSize;
- break;
- }
- case PIXEL_SIZE:
- {
- mImpl->mTextFitMinSize = ConvertPixelToPint(minSize);
- break;
- }
- }
+ mImpl->mTextFitMinSize = (type == POINT_SIZE) ? minSize : ConvertPixelToPoint(minSize);
}
float Controller::GetTextFitMinSize() const
void Controller::SetTextFitMaxSize(float maxSize, FontSizeType type)
{
- switch(type)
- {
- case POINT_SIZE:
- {
- mImpl->mTextFitMaxSize = maxSize;
- break;
- }
- case PIXEL_SIZE:
- {
- mImpl->mTextFitMaxSize = ConvertPixelToPint(maxSize);
- break;
- }
- }
+ mImpl->mTextFitMaxSize = (type == POINT_SIZE) ? maxSize : ConvertPixelToPoint(maxSize);
}
float Controller::GetTextFitMaxSize() const
void Controller::SetTextFitStepSize(float step, FontSizeType type)
{
- switch(type)
- {
- case POINT_SIZE:
- {
- mImpl->mTextFitStepSize = step;
- break;
- }
- case PIXEL_SIZE:
- {
- mImpl->mTextFitStepSize = ConvertPixelToPint(step);
- break;
- }
- }
+ mImpl->mTextFitStepSize = (type == POINT_SIZE) ? step : ConvertPixelToPoint(step);
}
float Controller::GetTextFitStepSize() const
return mImpl->mEventData->mGrabHandlePopupEnabled;
}
-// public : Update
-
void Controller::SetText(const std::string& text)
{
TextUpdater::SetText(*this, text);
mImpl->SendSelectionToClipboard(deleteAfterSending);
}
-// public : Default style & Input style
-
void Controller::SetDefaultFontFamily(const std::string& defaultFontFamily)
{
- if(NULL == mImpl->mFontDefaults)
- {
- mImpl->mFontDefaults = new FontDefaults();
- }
+ EnsureCreated(mImpl->mFontDefaults);
mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
DALI_LOG_INFO(gLogFilter, Debug::General, "Controller::SetDefaultFontFamily %s\n", defaultFontFamily.c_str());
mImpl->mFontDefaults->familyDefined = !defaultFontFamily.empty();
- if(mImpl->mEventData)
- {
- // Update the cursor position if it's in editing mode
- if(EventData::IsEditingState(mImpl->mEventData->mState))
- {
- mImpl->mEventData->mDecoratorUpdated = true;
- mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font family is updated.
- }
- }
+ // Update the cursor position if it's in editing mode
+ UpdateCursorPosition(mImpl->mEventData);
// Clear the font-specific data
ClearFontData();
const std::string& Controller::GetDefaultFontFamily() const
{
- if(NULL != mImpl->mFontDefaults)
- {
- return mImpl->mFontDefaults->mFontDescription.family;
- }
-
- return EMPTY_STRING;
+ return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.family : EMPTY_STRING;
}
void Controller::SetPlaceholderFontFamily(const std::string& placeholderTextFontFamily)
void Controller::SetDefaultFontWeight(FontWeight weight)
{
- if(NULL == mImpl->mFontDefaults)
- {
- mImpl->mFontDefaults = new FontDefaults();
- }
+ EnsureCreated(mImpl->mFontDefaults);
mImpl->mFontDefaults->mFontDescription.weight = weight;
mImpl->mFontDefaults->weightDefined = true;
- if(mImpl->mEventData)
- {
- // Update the cursor position if it's in editing mode
- if(EventData::IsEditingState(mImpl->mEventData->mState))
- {
- mImpl->mEventData->mDecoratorUpdated = true;
- mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font weight is updated.
- }
- }
+ // Update the cursor position if it's in editing mode
+ UpdateCursorPosition(mImpl->mEventData);
// Clear the font-specific data
ClearFontData();
bool Controller::IsDefaultFontWeightDefined() const
{
- if(NULL != mImpl->mFontDefaults)
- {
- return mImpl->mFontDefaults->weightDefined;
- }
-
- return false;
+ return mImpl->mFontDefaults && mImpl->mFontDefaults->weightDefined;
}
FontWeight Controller::GetDefaultFontWeight() const
{
- if(NULL != mImpl->mFontDefaults)
- {
- return mImpl->mFontDefaults->mFontDescription.weight;
- }
-
- return TextAbstraction::FontWeight::NORMAL;
+ return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.weight : TextAbstraction::FontWeight::NORMAL;
}
void Controller::SetPlaceholderTextFontWeight(FontWeight weight)
bool Controller::IsPlaceholderTextFontWeightDefined() const
{
return PlaceholderHandler::IsPlaceholderTextFontWeightDefined(*this);
- ;
}
FontWeight Controller::GetPlaceholderTextFontWeight() const
void Controller::SetDefaultFontWidth(FontWidth width)
{
- if(NULL == mImpl->mFontDefaults)
- {
- mImpl->mFontDefaults = new FontDefaults();
- }
+ EnsureCreated(mImpl->mFontDefaults);
mImpl->mFontDefaults->mFontDescription.width = width;
mImpl->mFontDefaults->widthDefined = true;
- if(mImpl->mEventData)
- {
- // Update the cursor position if it's in editing mode
- if(EventData::IsEditingState(mImpl->mEventData->mState))
- {
- mImpl->mEventData->mDecoratorUpdated = true;
- mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font width is updated.
- }
- }
+ // Update the cursor position if it's in editing mode
+ UpdateCursorPosition(mImpl->mEventData);
// Clear the font-specific data
ClearFontData();
bool Controller::IsDefaultFontWidthDefined() const
{
- if(NULL != mImpl->mFontDefaults)
- {
- return mImpl->mFontDefaults->widthDefined;
- }
-
- return false;
+ return mImpl->mFontDefaults && mImpl->mFontDefaults->widthDefined;
}
FontWidth Controller::GetDefaultFontWidth() const
{
- if(NULL != mImpl->mFontDefaults)
- {
- return mImpl->mFontDefaults->mFontDescription.width;
- }
-
- return TextAbstraction::FontWidth::NORMAL;
+ return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.width : TextAbstraction::FontWidth::NORMAL;
}
void Controller::SetPlaceholderTextFontWidth(FontWidth width)
void Controller::SetDefaultFontSlant(FontSlant slant)
{
- if(NULL == mImpl->mFontDefaults)
- {
- mImpl->mFontDefaults = new FontDefaults();
- }
+ EnsureCreated(mImpl->mFontDefaults);
mImpl->mFontDefaults->mFontDescription.slant = slant;
mImpl->mFontDefaults->slantDefined = true;
- if(mImpl->mEventData)
- {
- // Update the cursor position if it's in editing mode
- if(EventData::IsEditingState(mImpl->mEventData->mState))
- {
- mImpl->mEventData->mDecoratorUpdated = true;
- mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font slant is updated.
- }
- }
+ // Update the cursor position if it's in editing mode
+ UpdateCursorPosition(mImpl->mEventData);
// Clear the font-specific data
ClearFontData();
bool Controller::IsDefaultFontSlantDefined() const
{
- if(NULL != mImpl->mFontDefaults)
- {
- return mImpl->mFontDefaults->slantDefined;
- }
- return false;
+ return mImpl->mFontDefaults && mImpl->mFontDefaults->slantDefined;
}
FontSlant Controller::GetDefaultFontSlant() const
{
- if(NULL != mImpl->mFontDefaults)
- {
- return mImpl->mFontDefaults->mFontDescription.slant;
- }
-
- return TextAbstraction::FontSlant::NORMAL;
+ return mImpl->mFontDefaults ? mImpl->mFontDefaults->mFontDescription.slant : TextAbstraction::FontSlant::NORMAL;
}
void Controller::SetPlaceholderTextFontSlant(FontSlant slant)
{
mImpl->mFontSizeScale = scale;
- if(mImpl->mEventData)
- {
- // Update the cursor position if it's in editing mode
- if(EventData::IsEditingState(mImpl->mEventData->mState))
- {
- mImpl->mEventData->mDecoratorUpdated = true;
- mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
- }
- }
+ // Update the cursor position if it's in editing mode
+ UpdateCursorPosition(mImpl->mEventData);
// Clear the font-specific data
ClearFontData();
float Controller::GetFontSizeScale() const
{
- if(nullptr != mImpl->mFontDefaults)
- {
- return mImpl->mFontSizeScale;
- }
-
- return 1.f;
+ return mImpl->mFontDefaults ? mImpl->mFontSizeScale : 1.0f;
}
void Controller::SetDefaultFontSize(float fontSize, FontSizeType type)
{
- if(NULL == mImpl->mFontDefaults)
- {
- mImpl->mFontDefaults = new FontDefaults();
- }
+ EnsureCreated(mImpl->mFontDefaults);
- switch(type)
- {
- case POINT_SIZE:
- {
- mImpl->mFontDefaults->mDefaultPointSize = fontSize;
- mImpl->mFontDefaults->sizeDefined = true;
- break;
- }
- case PIXEL_SIZE:
- {
- // Point size = Pixel size * 72.f / DPI
- unsigned int horizontalDpi = 0u;
- unsigned int verticalDpi = 0u;
- TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
- fontClient.GetDpi(horizontalDpi, verticalDpi);
-
- mImpl->mFontDefaults->mDefaultPointSize = (fontSize * 72.f) / static_cast<float>(horizontalDpi);
- mImpl->mFontDefaults->sizeDefined = true;
- break;
- }
- }
+ mImpl->mFontDefaults->mDefaultPointSize = (type == POINT_SIZE) ? fontSize : ConvertPixelToPoint(fontSize);
+ mImpl->mFontDefaults->sizeDefined = true;
- if(mImpl->mEventData)
- {
- // Update the cursor position if it's in editing mode
- if(EventData::IsEditingState(mImpl->mEventData->mState))
- {
- mImpl->mEventData->mDecoratorUpdated = true;
- mImpl->mEventData->mUpdateCursorPosition = true; // Cursor position should be updated when the font size is updated.
- }
- }
+ // Update the cursor position if it's in editing mode
+ UpdateCursorPosition(mImpl->mEventData);
// Clear the font-specific data
ClearFontData();
float Controller::GetDefaultFontSize(FontSizeType type) const
{
- float value = 0.0f;
- if(NULL != mImpl->mFontDefaults)
+ if(mImpl->mFontDefaults)
{
- switch(type)
- {
- case POINT_SIZE:
- {
- value = mImpl->mFontDefaults->mDefaultPointSize;
- break;
- }
- case PIXEL_SIZE:
- {
- // Pixel size = Point size * DPI / 72.f
- unsigned int horizontalDpi = 0u;
- unsigned int verticalDpi = 0u;
- TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
- fontClient.GetDpi(horizontalDpi, verticalDpi);
-
- value = mImpl->mFontDefaults->mDefaultPointSize * static_cast<float>(horizontalDpi) / 72.f;
- break;
- }
- }
- return value;
+ return (type == POINT_SIZE) ? mImpl->mFontDefaults->mDefaultPointSize : ConvertPointToPixel(mImpl->mFontDefaults->mDefaultPointSize);
}
-
- return value;
+ return 0.0f;
}
void Controller::SetPlaceholderTextFontSize(float fontSize, FontSizeType type)
if(!mImpl->IsShowingPlaceholderText())
{
mImpl->mModel->mVisualModel->SetTextColor(color);
-
mImpl->mModel->mLogicalModel->mColorRuns.Clear();
-
mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | COLOR);
-
mImpl->RequestRelayout();
}
}
void Controller::SetShadowOffset(const Vector2& shadowOffset)
{
mImpl->mModel->mVisualModel->SetShadowOffset(shadowOffset);
-
mImpl->RequestRelayout();
}
void Controller::SetShadowColor(const Vector4& shadowColor)
{
mImpl->mModel->mVisualModel->SetShadowColor(shadowColor);
-
mImpl->RequestRelayout();
}
if(fabsf(GetShadowBlurRadius() - shadowBlurRadius) > Math::MACHINE_EPSILON_1)
{
mImpl->mModel->mVisualModel->SetShadowBlurRadius(shadowBlurRadius);
-
mImpl->RequestRelayout();
}
}
void Controller::SetUnderlineColor(const Vector4& color)
{
mImpl->mModel->mVisualModel->SetUnderlineColor(color);
-
mImpl->RequestRelayout();
}
void Controller::SetUnderlineEnabled(bool enabled)
{
mImpl->mModel->mVisualModel->SetUnderlineEnabled(enabled);
-
mImpl->RequestRelayout();
}
void Controller::SetUnderlineHeight(float height)
{
mImpl->mModel->mVisualModel->SetUnderlineHeight(height);
-
mImpl->RequestRelayout();
}
void Controller::SetOutlineColor(const Vector4& color)
{
mImpl->mModel->mVisualModel->SetOutlineColor(color);
-
mImpl->RequestRelayout();
}
void Controller::SetOutlineWidth(uint16_t width)
{
mImpl->mModel->mVisualModel->SetOutlineWidth(width);
-
mImpl->RequestRelayout();
}
void Controller::SetBackgroundColor(const Vector4& color)
{
mImpl->mModel->mVisualModel->SetBackgroundColor(color);
-
mImpl->RequestRelayout();
}
void Controller::SetBackgroundEnabled(bool enabled)
{
mImpl->mModel->mVisualModel->SetBackgroundEnabled(enabled);
-
mImpl->RequestRelayout();
}
void Controller::SetDefaultEmbossProperties(const std::string& embossProperties)
{
- if(NULL == mImpl->mEmbossDefaults)
- {
- mImpl->mEmbossDefaults = new EmbossDefaults();
- }
-
+ EnsureCreated(mImpl->mEmbossDefaults);
mImpl->mEmbossDefaults->properties = embossProperties;
}
const std::string& Controller::GetDefaultEmbossProperties() const
{
- if(NULL != mImpl->mEmbossDefaults)
- {
- return mImpl->mEmbossDefaults->properties;
- }
-
- return EMPTY_STRING;
+ return mImpl->mEmbossDefaults ? mImpl->mEmbossDefaults->properties : EMPTY_STRING;
}
void Controller::SetDefaultOutlineProperties(const std::string& outlineProperties)
{
- if(NULL == mImpl->mOutlineDefaults)
- {
- mImpl->mOutlineDefaults = new OutlineDefaults();
- }
-
+ EnsureCreated(mImpl->mOutlineDefaults);
mImpl->mOutlineDefaults->properties = outlineProperties;
}
const std::string& Controller::GetDefaultOutlineProperties() const
{
- if(NULL != mImpl->mOutlineDefaults)
+ return mImpl->mOutlineDefaults ? mImpl->mOutlineDefaults->properties : EMPTY_STRING;
+}
+
+void Controller::RelayoutForNewLineSize()
+{
+ // relayout all characters
+ mImpl->mTextUpdateInfo.mCharacterIndex = 0;
+ mImpl->mTextUpdateInfo.mNumberOfCharactersToRemove = mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters;
+ mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
+ mImpl->mOperationsPending = static_cast<OperationsMask>(mImpl->mOperationsPending | LAYOUT);
+
+ //remove selection
+ if(mImpl->mEventData && mImpl->mEventData->mState == EventData::SELECTING)
{
- return mImpl->mOutlineDefaults->properties;
+ mImpl->ChangeState(EventData::EDITING);
}
- return EMPTY_STRING;
+ mImpl->RequestRelayout();
}
bool Controller::SetDefaultLineSpacing(float lineSpacing)
{
mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
mImpl->mRecalculateNaturalSize = true;
+
+ RelayoutForNewLineSize();
return true;
}
return false;
{
mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
mImpl->mRecalculateNaturalSize = true;
+
+ RelayoutForNewLineSize();
return true;
}
return false;
void Controller::SetInputColor(const Vector4& color)
{
- if(NULL != mImpl->mEventData)
+ if(mImpl->mEventData)
{
mImpl->mEventData->mInputStyle.textColor = color;
mImpl->mEventData->mInputStyle.isDefaultColor = false;
const Vector4& Controller::GetInputColor() const
{
- if(NULL != mImpl->mEventData)
- {
- return mImpl->mEventData->mInputStyle.textColor;
- }
-
- // Return the default text's color if there is no EventData.
- return mImpl->mTextColor;
+ // Return event text input color if we have it, otherwise just return the default text's color
+ return mImpl->mEventData ? mImpl->mEventData->mInputStyle.textColor : mImpl->mTextColor;
}
void Controller::SetInputFontFamily(const std::string& fontFamily)
void Controller::SetInputLineSpacing(float lineSpacing)
{
- if(NULL != mImpl->mEventData)
+ if(mImpl->mEventData)
{
mImpl->mEventData->mInputStyle.lineSpacing = lineSpacing;
mImpl->mEventData->mInputStyle.isLineSpacingDefined = true;
float Controller::GetInputLineSpacing() const
{
- if(NULL != mImpl->mEventData)
- {
- return mImpl->mEventData->mInputStyle.lineSpacing;
- }
-
- return 0.f;
+ return mImpl->mEventData ? mImpl->mEventData->mInputStyle.lineSpacing : 0.0f;
}
void Controller::SetInputShadowProperties(const std::string& shadowProperties)
{
- if(NULL != mImpl->mEventData)
+ if(mImpl->mEventData)
{
mImpl->mEventData->mInputStyle.shadowProperties = shadowProperties;
}
const std::string& Controller::GetInputShadowProperties() const
{
- if(NULL != mImpl->mEventData)
- {
- return mImpl->mEventData->mInputStyle.shadowProperties;
- }
-
- return EMPTY_STRING;
+ return mImpl->mEventData ? mImpl->mEventData->mInputStyle.shadowProperties : EMPTY_STRING;
}
void Controller::SetInputUnderlineProperties(const std::string& underlineProperties)
{
- if(NULL != mImpl->mEventData)
+ if(mImpl->mEventData)
{
mImpl->mEventData->mInputStyle.underlineProperties = underlineProperties;
}
const std::string& Controller::GetInputUnderlineProperties() const
{
- if(NULL != mImpl->mEventData)
- {
- return mImpl->mEventData->mInputStyle.underlineProperties;
- }
-
- return EMPTY_STRING;
+ return mImpl->mEventData ? mImpl->mEventData->mInputStyle.underlineProperties : EMPTY_STRING;
}
void Controller::SetInputEmbossProperties(const std::string& embossProperties)
{
- if(NULL != mImpl->mEventData)
+ if(mImpl->mEventData)
{
mImpl->mEventData->mInputStyle.embossProperties = embossProperties;
}
const std::string& Controller::GetInputEmbossProperties() const
{
- if(NULL != mImpl->mEventData)
- {
- return mImpl->mEventData->mInputStyle.embossProperties;
- }
-
- return GetDefaultEmbossProperties();
+ return mImpl->mEventData ? mImpl->mEventData->mInputStyle.embossProperties : GetDefaultEmbossProperties();
}
void Controller::SetInputOutlineProperties(const std::string& outlineProperties)
{
- if(NULL != mImpl->mEventData)
+ if(mImpl->mEventData)
{
mImpl->mEventData->mInputStyle.outlineProperties = outlineProperties;
}
const std::string& Controller::GetInputOutlineProperties() const
{
- if(NULL != mImpl->mEventData)
- {
- return mImpl->mEventData->mInputStyle.outlineProperties;
- }
-
- return GetDefaultOutlineProperties();
+ return mImpl->mEventData ? mImpl->mEventData->mInputStyle.outlineProperties : GetDefaultOutlineProperties();
}
void Controller::SetInputModePassword(bool passwordInput)
{
- if(NULL != mImpl->mEventData)
+ if(mImpl->mEventData)
{
mImpl->mEventData->mPasswordInput = passwordInput;
}
bool Controller::IsInputModePassword()
{
- if(NULL != mImpl->mEventData)
- {
- return mImpl->mEventData->mPasswordInput;
- }
- return false;
+ return mImpl->mEventData && mImpl->mEventData->mPasswordInput;
}
void Controller::SetNoTextDoubleTapAction(NoTextTap::Action action)
{
- if(NULL != mImpl->mEventData)
+ if(mImpl->mEventData)
{
mImpl->mEventData->mDoubleTapAction = action;
}
Controller::NoTextTap::Action Controller::GetNoTextDoubleTapAction() const
{
- NoTextTap::Action action = NoTextTap::NO_ACTION;
-
- if(NULL != mImpl->mEventData)
- {
- action = mImpl->mEventData->mDoubleTapAction;
- }
-
- return action;
+ return mImpl->mEventData ? mImpl->mEventData->mDoubleTapAction : NoTextTap::NO_ACTION;
}
void Controller::SetNoTextLongPressAction(NoTextTap::Action action)
{
- if(NULL != mImpl->mEventData)
+ if(mImpl->mEventData)
{
mImpl->mEventData->mLongPressAction = action;
}
Controller::NoTextTap::Action Controller::GetNoTextLongPressAction() const
{
- NoTextTap::Action action = NoTextTap::NO_ACTION;
-
- if(NULL != mImpl->mEventData)
- {
- action = mImpl->mEventData->mLongPressAction;
- }
-
- return action;
+ return mImpl->mEventData ? mImpl->mEventData->mLongPressAction : NoTextTap::NO_ACTION;
}
bool Controller::IsUnderlineSetByString()
mImpl->mFontStyleSetByString = setByString;
}
-// public : Queries & retrieves.
-
Layout::Engine& Controller::GetLayoutEngine()
{
return mImpl->mLayoutEngine;
int Controller::GetLineCount(float width)
{
GetHeightForWidth(width);
- int numberofLines = mImpl->mModel->GetNumberOfLines();
- return numberofLines;
+ return mImpl->mModel->GetNumberOfLines();
}
const ModelInterface* const Controller::GetTextModel() const
void Controller::SetHiddenInputOption(const Property::Map& options)
{
- if(NULL == mImpl->mHiddenInput)
- {
- mImpl->mHiddenInput = new HiddenText(this);
- }
+ EnsureCreated<HiddenText, Controller*>(mImpl->mHiddenInput, this);
mImpl->mHiddenInput->SetProperties(options);
}
void Controller::GetHiddenInputOption(Property::Map& options)
{
- if(NULL != mImpl->mHiddenInput)
+ if(mImpl->mHiddenInput)
{
mImpl->mHiddenInput->GetProperties(options);
}
}
+void Controller::SetInputFilterOption(const Property::Map& options)
+{
+ EnsureCreated(mImpl->mInputFilter);
+ mImpl->mInputFilter->SetProperties(options);
+}
+
+void Controller::GetInputFilterOption(Property::Map& options)
+{
+ if(mImpl->mInputFilter)
+ {
+ mImpl->mInputFilter->GetProperties(options);
+ }
+}
+
void Controller::SetPlaceholderProperty(const Property::Map& map)
{
PlaceholderHandler::SetPlaceholderProperty(*this, map);
mImpl->mModel->mVerticalLineAlignment = alignment;
}
-// public : Relayout.
+Toolkit::DevelText::EllipsisPosition::Type Controller::GetEllipsisPosition() const
+{
+ return mImpl->mModel->GetEllipsisPosition();
+}
+
+void Controller::SetEllipsisPosition(Toolkit::DevelText::EllipsisPosition::Type ellipsisPosition)
+{
+ mImpl->mModel->mEllipsisPosition = ellipsisPosition;
+ mImpl->mModel->mVisualModel->SetEllipsisPosition(ellipsisPosition);
+}
Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection)
{
mImpl->RequestRelayout();
}
-// public : Input style change signals.
-
bool Controller::IsInputStyleChangedSignalsQueueEmpty()
{
return (NULL == mImpl->mEventData) || (0u == mImpl->mEventData->mInputStyleChangedQueue.Count());
void Controller::ProcessInputStyleChangedSignals()
{
- if(NULL == mImpl->mEventData)
- {
- // Nothing to do.
- return;
- }
-
- for(Vector<InputStyle::Mask>::ConstIterator it = mImpl->mEventData->mInputStyleChangedQueue.Begin(),
- endIt = mImpl->mEventData->mInputStyleChangedQueue.End();
- it != endIt;
- ++it)
+ if(mImpl->mEventData)
{
- const InputStyle::Mask mask = *it;
-
- if(NULL != mImpl->mEditableControlInterface)
+ if(mImpl->mEditableControlInterface)
{
- // Emit the input style changed signal.
- mImpl->mEditableControlInterface->InputStyleChanged(mask);
+ // Emit the input style changed signal for each mask
+ std::for_each(mImpl->mEventData->mInputStyleChangedQueue.begin(),
+ mImpl->mEventData->mInputStyleChangedQueue.end(),
+ [&](const auto mask) { mImpl->mEditableControlInterface->InputStyleChanged(mask); } );
}
- }
- mImpl->mEventData->mInputStyleChangedQueue.Clear();
+ mImpl->mEventData->mInputStyleChangedQueue.Clear();
+ }
}
-// public : Text-input Event Queuing.
-
void Controller::KeyboardFocusGainEvent()
{
EventHandler::KeyboardFocusGainEvent(*this);
EventHandler::SelectEvent(*this, x, y, selectType);
}
+void Controller::SelectEvent(const uint32_t start, const uint32_t end, SelectionType selectType)
+{
+ EventHandler::SelectEvent(*this, start, end, selectType);
+}
+
void Controller::SetTextSelectionRange(const uint32_t* start, const uint32_t* end)
{
if(mImpl->mEventData)
return mImpl->GetPrimaryCursorPosition();
}
-bool Controller::SetPrimaryCursorPosition(CharacterIndex index)
+bool Controller::SetPrimaryCursorPosition(CharacterIndex index, bool focused)
{
if(mImpl->mEventData)
{
mImpl->mEventData->mIsLeftHandleSelected = true;
mImpl->mEventData->mIsRightHandleSelected = true;
mImpl->mEventData->mCheckScrollAmount = true;
- if(mImpl->SetPrimaryCursorPosition(index))
+ if(mImpl->SetPrimaryCursorPosition(index, focused) && focused)
{
KeyboardFocusGainEvent();
return true;
SelectEvent(0.f, 0.f, SelectionType::NONE);
}
+void Controller::SelectText(const uint32_t start, const uint32_t end)
+{
+ SelectEvent(start, end, SelectionType::RANGE);
+}
+
string Controller::GetSelectedText() const
{
string text;
return text;
}
+string Controller::CopyText()
+{
+ string text;
+ mImpl->RetrieveSelection(text, false);
+ mImpl->SendSelectionToClipboard(false); // Text not modified
+
+ mImpl->mEventData->mUpdateCursorPosition = true;
+
+ mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup
+
+ return text;
+}
+
+string Controller::CutText()
+{
+ string text;
+ mImpl->RetrieveSelection(text, false);
+
+ if(!IsEditable())
+ {
+ return EMPTY_STRING;
+ }
+
+ mImpl->SendSelectionToClipboard(true); // Synchronous call to modify text
+ mImpl->mOperationsPending = ALL_OPERATIONS;
+
+ if((0u != mImpl->mModel->mLogicalModel->mText.Count()) ||
+ !mImpl->IsPlaceholderAvailable())
+ {
+ mImpl->QueueModifyEvent(ModifyEvent::TEXT_DELETED);
+ }
+ else
+ {
+ ShowPlaceholderText();
+ }
+
+ mImpl->mEventData->mUpdateCursorPosition = true;
+ mImpl->mEventData->mScrollAfterDelete = true;
+
+ mImpl->RequestRelayout();
+
+ if(nullptr != mImpl->mEditableControlInterface)
+ {
+ mImpl->mEditableControlInterface->TextChanged(true);
+ }
+ return text;
+}
+
+void Controller::PasteText()
+{
+ mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item
+}
+
InputMethodContext::CallbackData Controller::OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent)
{
return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent);
EventHandler::PasteClipboardItemEvent(*this);
}
-// protected : Inherit from Text::Decorator::ControllerInterface.
-
void Controller::GetTargetSize(Vector2& targetSize)
{
targetSize = mImpl->mModel->mVisualModel->mControlSize;
void Controller::AddDecoration(Actor& actor, bool needsClipping)
{
- if(NULL != mImpl->mEditableControlInterface)
+ if(mImpl->mEditableControlInterface)
{
mImpl->mEditableControlInterface->AddDecoration(actor, needsClipping);
}
float Controller::GetHorizontalScrollPosition()
{
- if(mImpl->mEventData)
- {
- //scroll values are negative internally so we convert them to positive numbers
- return -mImpl->mModel->mScrollPosition.x;
- }
- return 0;
+ // Scroll values are negative internally so we convert them to positive numbers
+ return mImpl->mEventData ? -mImpl->mModel->mScrollPosition.x : 0.0f;
}
float Controller::GetVerticalScrollPosition()
{
- if(mImpl->mEventData)
- {
- //scroll values are negative internally so we convert them to positive numbers
- return -mImpl->mModel->mScrollPosition.y;
- }
- return 0;
+ // Scroll values are negative internally so we convert them to positive numbers
+ return mImpl->mEventData ? -mImpl->mModel->mScrollPosition.y : 0.0f;
}
void Controller::DecorationEvent(HandleType handleType, HandleState state, float x, float y)
EventHandler::DecorationEvent(*this, handleType, state, x, y);
}
-// protected : Inherit from TextSelectionPopup::TextPopupButtonCallbackInterface.
-
void Controller::TextPopupButtonTouched(Dali::Toolkit::TextSelectionPopup::Buttons button)
{
EventHandler::TextPopupButtonTouched(*this, button);
mImpl->RequestRelayout();
}
-// private : Update.
-
void Controller::InsertText(const std::string& text, Controller::InsertType type)
{
TextUpdater::InsertText(*this, text, type);
TextUpdater::PasteText(*this, stringToPaste);
}
-bool Controller::RemoveText(int cursorOffset,
- int numberOfCharacters,
- UpdateInputStyleType type)
+bool Controller::RemoveText(int cursorOffset, int numberOfCharacters, UpdateInputStyleType type)
{
return TextUpdater::RemoveText(*this, cursorOffset, numberOfCharacters, type);
}
return TextUpdater::RemoveSelectedText(*this);
}
-void Controller::InsertTextAnchor(int numberOfCharacters,
- CharacterIndex previousCursorIndex)
+void Controller::InsertTextAnchor(int numberOfCharacters, CharacterIndex previousCursorIndex)
{
TextUpdater::InsertTextAnchor(*this, numberOfCharacters, previousCursorIndex);
}
-void Controller::RemoveTextAnchor(int cursorOffset,
- int numberOfCharacters,
- CharacterIndex previousCursorIndex)
+void Controller::RemoveTextAnchor(int cursorOffset, int numberOfCharacters, CharacterIndex previousCursorIndex)
{
TextUpdater::RemoveTextAnchor(*this, cursorOffset, numberOfCharacters, previousCursorIndex);
}
-// private : Relayout.
-
-bool Controller::DoRelayout(const Size& size,
- OperationsMask operationsRequired,
- Size& layoutSize)
+bool Controller::DoRelayout(const Size& size, OperationsMask operationsRequired, Size& layoutSize)
{
return Relayouter::DoRelayout(*this, size, operationsRequired, layoutSize);
}
Relayouter::CalculateVerticalOffset(*this, controlSize);
}
-// private : Events.
-
void Controller::ProcessModifyEvents()
{
EventHandler::ProcessModifyEvents(*this);
void Controller::ResetScrollPosition()
{
- if(NULL != mImpl->mEventData)
+ if(mImpl->mEventData)
{
// Reset the scroll position.
mImpl->mModel->mScrollPosition = Vector2::ZERO;
return mImpl->CreateBackgroundActor();
}
-// private : Private contructors & copy operator.
-
-Controller::Controller()
-: Controller(nullptr, nullptr, nullptr, nullptr)
-{
-}
-
-Controller::Controller(ControlInterface* controlInterface)
-: Controller(controlInterface, nullptr, nullptr, nullptr)
-{
-}
-
Controller::Controller(ControlInterface* controlInterface,
EditableControlInterface* editableControlInterface,
SelectableControlInterface* selectableControlInterface,
{
}
-// The copy constructor and operator are left unimplemented.
-
-// protected : Destructor.
-
Controller::~Controller()
{
delete mImpl;
}
-} // namespace Text
-
-} // namespace Toolkit
-
-} // namespace Dali
+} // namespace Dali::Toolkit::Text