[dali-toolkit] TextEditor/TextField add PrimaryCursorPosition property
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / text-controller.cpp
index d683c7f..a1791bc 100644 (file)
@@ -989,6 +989,36 @@ FontSlant Controller::GetPlaceholderTextFontSlant() const
   return PlaceholderHandler::GetPlaceholderTextFontSlant(*this);
 }
 
+void Controller::SetFontSizeScale( float scale )
+{
+  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.
+    }
+  }
+
+  // Clear the font-specific data
+  ClearFontData();
+
+  mImpl->RequestRelayout();
+}
+
+float Controller::GetFontSizeScale() const
+{
+  if( nullptr != mImpl->mFontDefaults )
+  {
+    return mImpl->mFontSizeScale;
+  }
+
+  return 1.f;
+}
+
 void Controller::SetDefaultFontSize( float fontSize, FontSizeType type )
 {
   if( NULL == mImpl->mFontDefaults )
@@ -2205,6 +2235,28 @@ Uint32Pair Controller::GetTextSelectionRange() const
   return mImpl->GetTextSelectionRange();
 }
 
+CharacterIndex Controller::GetPrimaryCursorPosition() const
+{
+  return mImpl->GetPrimaryCursorPosition();
+}
+
+bool Controller::SetPrimaryCursorPosition( CharacterIndex index )
+{
+  if( mImpl->mEventData )
+  {
+    mImpl->mEventData->mCheckScrollAmount = true;
+    mImpl->mEventData->mIsLeftHandleSelected = true;
+    mImpl->mEventData->mIsRightHandleSelected = true;
+    mImpl->mEventData->mCheckScrollAmount = true;
+    if( mImpl->SetPrimaryCursorPosition(index) )
+    {
+      KeyboardFocusGainEvent();
+      return true;
+    }
+  }
+  return false;
+}
+
 void Controller::SelectWholeText()
 {
   SelectEvent( 0.f, 0.f, SelectionType::ALL );
@@ -2264,6 +2316,56 @@ void Controller::SetEditable( bool editable )
   }
 }
 
+void Controller::ScrollBy( Vector2 scroll )
+{
+  if( mImpl->mEventData && (fabs(scroll.x) > Math::MACHINE_EPSILON_0 || fabs(scroll.y) > Math::MACHINE_EPSILON_0))
+  {
+      const Vector2& layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
+      const Vector2 currentScroll = mImpl->mModel->mScrollPosition;
+
+      scroll.x = -scroll.x;
+      scroll.y = -scroll.y;
+
+      if( fabs(scroll.x) > Math::MACHINE_EPSILON_0 )
+      {
+        mImpl->mModel->mScrollPosition.x += scroll.x;
+        mImpl->ClampHorizontalScroll( layoutSize );
+      }
+
+      if( fabs(scroll.y) > Math::MACHINE_EPSILON_0 )
+      {
+        mImpl->mModel->mScrollPosition.y += scroll.y;
+        mImpl->ClampVerticalScroll( layoutSize );
+      }
+
+      if (mImpl->mModel->mScrollPosition != currentScroll)
+      {
+        mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - currentScroll );
+        mImpl->RequestRelayout();
+      }
+  }
+}
+
+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;
+}
+
+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;
+}
+
 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
 {
   EventHandler::DecorationEvent(*this, handleType, state, x, y);
@@ -2461,7 +2563,7 @@ void Controller::InsertText( const std::string& text, Controller::InsertType typ
 
       if( addFontSizeRun )
       {
-        fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * 64.f );
+        fontDescriptionRun.size = static_cast<PointSize26Dot6>( mImpl->mEventData->mInputStyle.size * mImpl->mFontSizeScale * 64.f );
         fontDescriptionRun.sizeDefined = true;
       }
 
@@ -2648,8 +2750,6 @@ bool Controller::RemoveText( int cursorOffset,
       Vector<Character>::Iterator first = currentText.Begin() + cursorIndex;
       Vector<Character>::Iterator last  = first + numberOfCharacters;
 
-      currentText.Erase( first, last );
-
       if( NULL != mImpl->mEditableControlInterface )
       {
         std::string utf8;
@@ -2657,6 +2757,8 @@ bool Controller::RemoveText( int cursorOffset,
         mImpl->mEditableControlInterface->TextDeleted( cursorIndex, numberOfCharacters, utf8 );
       }
 
+      currentText.Erase( first, last );
+
       // Cursor position retreat
       oldCursorIndex = cursorIndex;