[dali-toolkit] TextEditor/TextField add PrimaryCursorPosition property
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller-impl.cpp
index 0cd6adb..d5edfc3 100644 (file)
@@ -35,6 +35,7 @@
 #include <dali-toolkit/internal/text/text-control-interface.h>
 #include <dali-toolkit/internal/text/text-controller-impl-event-handler.h>
 #include <dali-toolkit/internal/text/text-run-container.h>
+#include <dali-toolkit/internal/text/text-editable-control-interface.h>
 
 using namespace Dali;
 
@@ -246,6 +247,11 @@ bool Controller::Impl::ProcessInputEvents()
     GetCursorPosition( mEventData->mPrimaryCursorPosition,
                        cursorInfo );
 
+    if( NULL != mEditableControlInterface )
+    {
+      mEditableControlInterface->CaretMoved( mEventData->mPrimaryCursorPosition );
+    }
+
     if( mEventData->mUpdateCursorHookPosition )
     {
       // Update the cursor hook position. Used to move the cursor with the keys 'up' and 'down'.
@@ -953,7 +959,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
 
       // Get the default font's description.
       TextAbstraction::FontDescription defaultFontDescription;
-      TextAbstraction::PointSize26Dot6 defaultPointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE;
+      TextAbstraction::PointSize26Dot6 defaultPointSize = TextAbstraction::FontClient::DEFAULT_POINT_SIZE * mFontSizeScale;
 
       if( IsShowingPlaceholderText() && mEventData && ( NULL != mEventData->mPlaceholderFont ) )
       {
@@ -961,7 +967,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
         defaultFontDescription = mEventData->mPlaceholderFont->mFontDescription;
         if( mEventData->mPlaceholderFont->sizeDefined )
         {
-          defaultPointSize = mEventData->mPlaceholderFont->mDefaultPointSize * 64u;
+          defaultPointSize = mEventData->mPlaceholderFont->mDefaultPointSize * mFontSizeScale * 64u;
         }
       }
       else if( NULL != mFontDefaults )
@@ -975,7 +981,7 @@ bool Controller::Impl::UpdateModel( OperationsMask operationsRequired )
         }
         else
         {
-          defaultPointSize = mFontDefaults->mDefaultPointSize * 64u;
+          defaultPointSize = mFontDefaults->mDefaultPointSize * mFontSizeScale * 64u;
         }
       }
 
@@ -1326,11 +1332,11 @@ float Controller::Impl::GetDefaultFontLineHeight()
   if( NULL == mFontDefaults )
   {
     TextAbstraction::FontDescription fontDescription;
-    defaultFontId = mFontClient.GetFontId( fontDescription );
+    defaultFontId = mFontClient.GetFontId( fontDescription, TextAbstraction::FontClient::DEFAULT_POINT_SIZE * mFontSizeScale );
   }
   else
   {
-    defaultFontId = mFontDefaults->GetFontId( mFontClient );
+    defaultFontId = mFontDefaults->GetFontId( mFontClient, mFontDefaults->mDefaultPointSize * mFontSizeScale );
   }
 
   Text::FontMetrics fontMetrics;
@@ -1416,6 +1422,38 @@ void Controller::Impl::SetTextSelectionRange(const uint32_t *pStart, const uint3
   }
 }
 
+CharacterIndex Controller::Impl::GetPrimaryCursorPosition() const
+{
+  if( nullptr == mEventData )
+  {
+    return 0;
+  }
+  return mEventData->mPrimaryCursorPosition;
+}
+
+bool Controller::Impl::SetPrimaryCursorPosition( CharacterIndex index )
+{
+  if( nullptr == mEventData )
+  {
+    // Nothing to do if there is no text.
+    return false;
+  }
+
+  if( mEventData->mPrimaryCursorPosition == index )
+  {
+    // Nothing for same cursor position.
+    return false;
+  }
+
+  uint32_t length = static_cast<uint32_t>(mModel->mLogicalModel->mText.Count());
+  mEventData->mPrimaryCursorPosition = std::min(index, length);
+  ChangeState( EventData::EDITING );
+  mEventData->mLeftSelectionPosition = mEventData->mRightSelectionPosition = mEventData->mPrimaryCursorPosition;
+  mEventData->mUpdateCursorPosition = true;
+  ScrollTextToMatchCursor();
+  return true;
+}
+
 Uint32Pair Controller::Impl::GetTextSelectionRange() const
 {
   Uint32Pair range;
@@ -1519,6 +1557,18 @@ void Controller::Impl::RetrieveSelection( std::string& selectedText, bool delete
   }
 }
 
+void Controller::Impl::SetSelection( int start, int end )
+{
+  mEventData->mLeftSelectionPosition = start;
+  mEventData->mRightSelectionPosition = end;
+  mEventData->mUpdateCursorPosition = true;
+}
+
+std::pair< int, int > Controller::Impl::GetSelectionIndexes() const
+{
+  return { mEventData->mLeftSelectionPosition, mEventData->mRightSelectionPosition };
+}
+
 void Controller::Impl::ShowClipboard()
 {
   if( mClipboard )
@@ -1540,7 +1590,7 @@ void Controller::Impl::SetClipboardHideEnable(bool enable)
   mClipboardHideEnabled = enable;
 }
 
-bool Controller::Impl::CopyStringToClipboard( std::string& source )
+bool Controller::Impl::CopyStringToClipboard( const std::string& source )
 {
   //Send string to clipboard
   return ( mClipboard && mClipboard.SetItem( source ) );
@@ -2657,6 +2707,13 @@ void Controller::Impl::ScrollTextToMatchCursor( const CursorInfo& cursorInfo )
   ScrollToMakePositionVisible( cursorInfo.primaryPosition, cursorInfo.lineHeight );
 }
 
+void Controller::Impl::ScrollTextToMatchCursor()
+{
+  CursorInfo cursorInfo;
+  GetCursorPosition( mEventData->mPrimaryCursorPosition, cursorInfo );
+  ScrollTextToMatchCursor(cursorInfo);
+}
+
 void Controller::Impl::RequestRelayout()
 {
   if( NULL != mControlInterface )