Merge "Fix numeric error on BLUR_RADIUS" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
index a863317..30c6e04 100644 (file)
@@ -19,6 +19,8 @@
 #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>
@@ -134,6 +136,11 @@ bool Controller::IsMarkupProcessorEnabled() const
   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);
@@ -382,14 +389,19 @@ void Controller::SetIgnoreSpacesAfterText(bool ignore)
   mImpl->mModel->mIgnoreSpacesAfterText = ignore;
 }
 
-bool Controller::IsMatchSystemLanguageDirection() const
+void Controller::ChangedLayoutDirection()
+{
+  mImpl->mIsLayoutDirectionChanged = true;
+}
+
+void Controller::SetMatchLayoutDirection(DevelText::MatchLayoutDirection type)
 {
-  return mImpl->mModel->mMatchSystemLanguageDirection;
+  mImpl->mModel->mMatchLayoutDirection = type;
 }
 
-void Controller::SetMatchSystemLanguageDirection(bool match)
+DevelText::MatchLayoutDirection Controller::GetMatchLayoutDirection() const
 {
-  mImpl->mModel->mMatchSystemLanguageDirection = match;
+  return mImpl->mModel->mMatchLayoutDirection;
 }
 
 void Controller::SetLayoutDirection(Dali::LayoutDirection::Type layoutDirection)
@@ -397,6 +409,19 @@ 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();
@@ -439,6 +464,7 @@ Text::LineWrap::Mode Controller::GetLineWrapMode() const
 void Controller::SetTextElideEnabled(bool enabled)
 {
   mImpl->mModel->mElideEnabled = enabled;
+  mImpl->mModel->mVisualModel->SetTextElideEnabled(enabled);
 }
 
 bool Controller::IsTextElideEnabled() const
@@ -1193,12 +1219,31 @@ const std::string& Controller::GetDefaultOutlineProperties() const
   return 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 != nullptr) && (mImpl->mEventData->mState == EventData::SELECTING))
+  {
+    mImpl->ChangeState(EventData::EDITING);
+  }
+
+  mImpl->RequestRelayout();
+}
+
 bool Controller::SetDefaultLineSpacing(float lineSpacing)
 {
   if(std::fabs(lineSpacing - mImpl->mLayoutEngine.GetDefaultLineSpacing()) > Math::MACHINE_EPSILON_1000)
   {
     mImpl->mLayoutEngine.SetDefaultLineSpacing(lineSpacing);
     mImpl->mRecalculateNaturalSize = true;
+
+    RelayoutForNewLineSize();
     return true;
   }
   return false;
@@ -1215,6 +1260,8 @@ bool Controller::SetDefaultLineSize(float lineSize)
   {
     mImpl->mLayoutEngine.SetDefaultLineSize(lineSize);
     mImpl->mRecalculateNaturalSize = true;
+
+    RelayoutForNewLineSize();
     return true;
   }
   return false;
@@ -1618,6 +1665,23 @@ void Controller::GetHiddenInputOption(Property::Map& options)
   }
 }
 
+void Controller::SetInputFilterOption(const Property::Map& options)
+{
+  if(!mImpl->mInputFilter)
+  {
+    mImpl->mInputFilter = std::unique_ptr<InputFilter>(new InputFilter());
+  }
+  mImpl->mInputFilter->SetProperties(options);
+}
+
+void Controller::GetInputFilterOption(Property::Map& options)
+{
+  if(NULL != mImpl->mInputFilter)
+  {
+    mImpl->mInputFilter->GetProperties(options);
+  }
+}
+
 void Controller::SetPlaceholderProperty(const Property::Map& map)
 {
   PlaceholderHandler::SetPlaceholderProperty(*this, map);
@@ -1682,6 +1746,17 @@ void Controller::SetVerticalLineAlignment(Toolkit::DevelText::VerticalLineAlignm
   mImpl->mModel->mVerticalLineAlignment = alignment;
 }
 
+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);
+}
+
 // public : Relayout.
 
 Controller::UpdateTextType Controller::Relayout(const Size& size, Dali::LayoutDirection::Type layoutDirection)
@@ -1768,6 +1843,11 @@ void Controller::SelectEvent(float x, float y, SelectionType selectType)
   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)
@@ -1791,7 +1871,7 @@ CharacterIndex Controller::GetPrimaryCursorPosition() const
   return mImpl->GetPrimaryCursorPosition();
 }
 
-bool Controller::SetPrimaryCursorPosition(CharacterIndex index)
+bool Controller::SetPrimaryCursorPosition(CharacterIndex index, bool focused)
 {
   if(mImpl->mEventData)
   {
@@ -1799,7 +1879,7 @@ bool Controller::SetPrimaryCursorPosition(CharacterIndex index)
     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;
@@ -1818,6 +1898,11 @@ void Controller::SelectNone()
   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;
@@ -1828,6 +1913,59 @@ string Controller::GetSelectedText() const
   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 "";
+  }
+
+  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);