/*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// 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/adaptor-framework/adaptor.h>
#include <dali/integration-api/debug.h>
#include <memory.h>
#include <cmath>
Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, true, "LOG_TEXT_CONTROLS");
#endif
-const char* EMPTY_STRING = "";
+const char* EMPTY_STRING = "";
const char* MIME_TYPE_TEXT_PLAIN = "text/plain;charset=utf-8";
+const char* MIME_TYPE_HTML = "application/xhtml+xml";
template<typename Type>
void EnsureCreated(Type*& object)
mImpl->mModel->mIgnoreSpacesAfterText = ignore;
}
+bool Controller::IsRemoveFrontInset() const
+{
+ return mImpl->mModel->mRemoveFrontInset;
+}
+
+void Controller::SetRemoveFrontInset(bool remove)
+{
+ mImpl->mModel->mRemoveFrontInset = remove;
+}
+
+bool Controller::IsRemoveBackInset() const
+{
+ return mImpl->mModel->mRemoveBackInset;
+}
+
+void Controller::SetRemoveBackInset(bool remove)
+{
+ mImpl->mModel->mRemoveBackInset = remove;
+}
+
+bool Controller::IsTextCutout() const
+{
+ return mImpl->mTextCutout;
+}
+
+void Controller::SetTextCutout(bool cutout)
+{
+ if(cutout != mImpl->mTextCutout)
+ {
+ mImpl->mModel->mVisualModel->SetCutoutEnabled(cutout);
+ mImpl->mTextCutout = cutout;
+ mImpl->RequestRelayout();
+ }
+}
+
void Controller::ChangedLayoutDirection()
{
mImpl->mIsLayoutDirectionChanged = true;
mImpl->ClearFontData();
mImpl->RequestRelayout();
+
+ if(mImpl->mEventData && EventData::INACTIVE != mImpl->mEventData->mState)
+ {
+ SetInputFontPointSize(fontSize, true);
+ }
}
float Controller::GetDefaultFontSize(FontSizeType type) const
return mImpl->mModel->mVisualModel->GetDashedUnderlineGap();
}
+void Controller::SetOutlineOffset(const Vector2& outlineOffset)
+{
+ mImpl->mModel->mVisualModel->SetOutlineOffset(outlineOffset);
+ mImpl->RequestRelayout();
+}
+
+const Vector2& Controller::GetOutlineOffset() const
+{
+ return mImpl->mModel->mVisualModel->GetOutlineOffset();
+}
+
void Controller::SetOutlineColor(const Vector4& color)
{
mImpl->mModel->mVisualModel->SetOutlineColor(color);
return mImpl->mModel->mVisualModel->GetOutlineWidth();
}
+void Controller::SetOutlineBlurRadius(const float& outlineBlurRadius)
+{
+ if(fabsf(GetOutlineBlurRadius() - outlineBlurRadius) > Math::MACHINE_EPSILON_1)
+ {
+ mImpl->mModel->mVisualModel->SetOutlineBlurRadius(outlineBlurRadius);
+ mImpl->RequestRelayout();
+ }
+}
+
+const float& Controller::GetOutlineBlurRadius() const
+{
+ return mImpl->mModel->mVisualModel->GetOutlineBlurRadius();
+}
+
void Controller::SetBackgroundColor(const Vector4& color)
{
mImpl->mModel->mVisualModel->SetBackgroundColor(color);
return InputFontHandler::GetInputFontSlant(*this);
}
-void Controller::SetInputFontPointSize(float size)
+void Controller::SetInputFontPointSize(float size, bool defaultFontSizeUpdated)
{
- InputFontHandler::SetInputFontPointSize(*this, size);
+ InputFontHandler::SetInputFontPointSize(*this, size, defaultFontSizeUpdated);
}
float Controller::GetInputFontPointSize() const
mImpl->mModel->mVisualTransformOffset = offset;
}
+void Controller::SetBackgroundWithCutoutEnabled(bool cutout)
+{
+ mImpl->mModel->mVisualModel->SetBackgroundWithCutoutEnabled(cutout);
+ RequestRelayout();
+}
+
+bool Controller::IsBackgroundWithCutoutEnabled() const
+{
+ return mImpl->mModel->mVisualModel->IsBackgroundWithCutoutEnabled();
+}
+
+void Controller::SetBackgroundColorWithCutout(const Vector4& color)
+{
+ mImpl->mModel->mVisualModel->SetBackgroundColorWithCutout(color);
+ mImpl->RequestRelayout();
+}
+
+const Vector4 Controller::GetBackgroundColorWithCutout() const
+{
+ return mImpl->mModel->mVisualModel->GetBackgroundColorWithCutout();
+}
+
Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection)
{
return Relayouter::Relayout(*this, size, layoutDirection);
return mImpl->IsInputStyleChangedSignalsQueueEmpty();
}
-void Controller::ProcessInputStyleChangedSignals()
+void Controller::RequestProcessInputStyleChangedSignals()
{
- mImpl->ProcessInputStyleChangedSignals();
+ if(Dali::Adaptor::IsAvailable() && !mImpl->mProcessorRegistered)
+ {
+ mImpl->mProcessorRegistered = true;
+ Dali::Adaptor::Get().RegisterProcessor(*this, true);
+ }
+}
+
+void Controller::OnIdleSignal()
+{
+ if(mImpl->mIdleCallback)
+ {
+ mImpl->mIdleCallback = NULL;
+
+ mImpl->ProcessInputStyleChangedSignals();
+ }
}
void Controller::KeyboardFocusGainEvent()
mImpl->mClipboard.DataReceivedSignal().Disconnect(this, &Controller::PasteClipboardItemEvent);
// If the id is 0u, it is an invalid response.
+ if(id == 0u)
+ {
+ return;
+ }
+
// text-controller allows only plain text type.
- if(id != 0u && !strncmp(mimeType, MIME_TYPE_TEXT_PLAIN, strlen(MIME_TYPE_TEXT_PLAIN)))
+ if(!strncmp(mimeType, MIME_TYPE_TEXT_PLAIN, strlen(MIME_TYPE_TEXT_PLAIN)))
{
EventHandler::PasteClipboardItemEvent(*this, data);
}
+ else if(!strncmp(mimeType, MIME_TYPE_HTML, strlen(MIME_TYPE_HTML)))
+ {
+ // This does not mean that text controls can parse html.
+ // This is temporary code, as text controls do not support html type data.
+ // Simply remove the tags inside the angle brackets.
+ // Once multiple types and data can be stored in the clipboard, this code should be removed.
+ std::regex reg("<[^>]*>");
+ std::string result = regex_replace(data, reg, "");
+
+ EventHandler::PasteClipboardItemEvent(*this, result.c_str());
+ }
}
void Controller::PasteText()
// Connect the signal before calling GetData() of the clipboard.
mImpl->mClipboard.DataReceivedSignal().Connect(this, &Controller::PasteClipboardItemEvent);
+ // If there is no plain text type data on the clipboard, request html type data.
+ std::string mimeType = mImpl->mClipboard.HasType(MIME_TYPE_TEXT_PLAIN) ? MIME_TYPE_TEXT_PLAIN : MIME_TYPE_HTML;
+
// Request clipboard service to retrieve an item.
- uint id = mImpl->mClipboard.GetData(MIME_TYPE_TEXT_PLAIN);
+ uint id = mImpl->mClipboard.GetData(mimeType);
if(id == 0u)
{
// If the return id is 0u, the signal is not emitted, we must disconnect signal here.
return mImpl->GetAnchorIndex(characterOffset);
}
+void Controller::Process(bool postProcess)
+{
+ if(Dali::Adaptor::IsAvailable() && mImpl->mProcessorRegistered)
+ {
+ Dali::Adaptor& adaptor = Dali::Adaptor::Get();
+
+ adaptor.UnregisterProcessor(*this, true);
+ mImpl->mProcessorRegistered = false;
+
+ if(NULL == mImpl->mIdleCallback)
+ {
+ // @note: The callback manager takes the ownership of the callback object.
+ mImpl->mIdleCallback = MakeCallback(this, &Controller::OnIdleSignal);
+ if(DALI_UNLIKELY(!adaptor.AddIdle(mImpl->mIdleCallback, false)))
+ {
+ DALI_LOG_ERROR("Fail to add idle callback for text controller style changed signals queue. Skip these callbacks\n");
+
+ // Clear queue forcely.
+ if(mImpl->mEventData)
+ {
+ mImpl->mEventData->mInputStyleChangedQueue.Clear();
+ }
+
+ // Set the pointer to null as the callback manager deletes the callback even AddIdle failed.
+ mImpl->mIdleCallback = NULL;
+ }
+ }
+ }
+}
+
Controller::Controller(ControlInterface* controlInterface,
EditableControlInterface* editableControlInterface,
SelectableControlInterface* selectableControlInterface,
Controller::~Controller()
{
+ if(Dali::Adaptor::IsAvailable())
+ {
+ if(mImpl->mProcessorRegistered)
+ {
+ Dali::Adaptor::Get().UnregisterProcessor(*this, true);
+ }
+ if(mImpl->mIdleCallback)
+ {
+ Dali::Adaptor::Get().RemoveIdle(mImpl->mIdleCallback);
+ }
+ }
}
} // namespace Dali::Toolkit::Text