TextContoller Copy and Cut buttons functional 01/42001/9
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Fri, 19 Jun 2015 15:39:55 +0000 (16:39 +0100)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Mon, 22 Jun 2015 16:35:02 +0000 (17:35 +0100)
Change-Id: I5a0d810048156e32f829fa05617fd2d25ac2ac40
Signed-off-by: Agnelo Vaz <agnelo.vaz@samsung.com>
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-controller-impl.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h

index e3ee4d6..cef33eb 100644 (file)
@@ -196,7 +196,6 @@ bool Controller::Impl::ProcessInputEvents()
     }
   }
 
-
   // The cursor must also be repositioned after inserts into the model
   if( mEventData->mUpdateCursorPosition )
   {
@@ -750,6 +749,61 @@ void Controller::Impl::OnSelectAllEvent()
   }
 }
 
+void Controller::Impl::RetreiveSelection( std::string& selectedText, bool deleteAfterRetreival )
+{
+  if( mEventData->mLeftSelectionPosition ==  mEventData->mRightSelectionPosition )
+  {
+    // Nothing to select if handles are in the same place.
+    selectedText="";
+    return;
+  }
+
+  //Get start and end position of selection
+  uint32_t startOfSelectedText = mEventData->mLeftSelectionPosition;
+  uint32_t lengthOfSelectedText =  mEventData->mRightSelectionPosition - startOfSelectedText;
+
+  // Validate the start and end selection points
+  if( ( startOfSelectedText >= 0 ) && (  ( startOfSelectedText + lengthOfSelectedText ) <=  mLogicalModel->mText.Count() ) )
+  {
+    //Get text as a UTF8 string
+    Vector<Character>& utf32Characters = mLogicalModel->mText;
+
+    Utf32ToUtf8( &utf32Characters[startOfSelectedText], lengthOfSelectedText, selectedText );
+
+    if ( deleteAfterRetreival  ) // Only delete text if copied successfully
+    {
+      // Delete text between handles
+      Vector<Character>& currentText = mLogicalModel->mText;
+
+      Vector<Character>::Iterator first = currentText.Begin() + startOfSelectedText;
+      Vector<Character>::Iterator last  = first + lengthOfSelectedText;
+      currentText.Erase( first, last );
+    }
+    mEventData->mPrimaryCursorPosition = mEventData->mLeftSelectionPosition;
+    mEventData->mScrollAfterDelete = true;
+    mEventData->mDecoratorUpdated = true;
+  }
+}
+
+bool Controller::Impl::CopyStringToClipboard( std::string& source )
+{
+  //Send string to clipboard
+  return ( mClipboard && mClipboard.SetItem( source ) );
+}
+
+void Controller::Impl::SendSelectionToClipboard( bool deleteAfterSending )
+{
+  std::string selectedText;
+  RetreiveSelection( selectedText, deleteAfterSending );
+  CopyStringToClipboard( selectedText );
+  ChangeState( EventData::EDITING );
+}
+
+void Controller::Impl::PasteTextFromClipboard()
+{
+  // Not supported
+}
+
 void Controller::Impl::RepositionSelectionHandles( CharacterIndex selectionStart, CharacterIndex selectionEnd )
 {
   if( selectionStart == selectionEnd )
@@ -906,6 +960,7 @@ void Controller::Impl::ChangeState( EventData::State newState )
         {
           buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) );
         }
+        mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE );
         mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow );
         mEventData->mDecorator->SetPopupActive( true );
       }
index bb0c2b5..dc5d3a6 100644 (file)
@@ -339,6 +339,14 @@ struct Controller::Impl
 
   void OnSelectAllEvent();
 
+  void RetreiveSelection( std::string& selectedText, bool deleteAfterRetreival );
+
+  bool CopyStringToClipboard( std::string& source );
+
+  void SendSelectionToClipboard( bool deleteAfterSending );
+
+  void PasteTextFromClipboard();
+
   void RepositionSelectionHandles( CharacterIndex selectionStart, CharacterIndex selectionEnd );
   void RepositionSelectionHandles( float visualX, float visualY );
 
index de3aa91..55ece1c 100644 (file)
@@ -1466,14 +1466,31 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt
   {
     case Toolkit::TextSelectionPopup::CUT:
     {
+      mImpl->SendSelectionToClipboard( true ); // Synchronous call to modify text
+      mImpl->mOperationsPending = ALL_OPERATIONS;
+      if( 0u != mImpl->mLogicalModel->mText.Count() ||
+          !mImpl->IsPlaceholderAvailable() )
+      {
+        mImpl->QueueModifyEvent( ModifyEvent::TEXT_DELETED );
+      }
+      else
+      {
+        ShowPlaceholderText();
+        mImpl->mEventData->mUpdateCursorPosition = true;
+      }
+      mImpl->RequestRelayout();
+      mImpl->mControlInterface.TextChanged();
       break;
     }
     case Toolkit::TextSelectionPopup::COPY:
     {
+      mImpl->SendSelectionToClipboard( false ); // Text not modified
+      mImpl->RequestRelayout(); // Handles, Selection Highlight, Popup
       break;
     }
     case Toolkit::TextSelectionPopup::PASTE:
     {
+      mImpl->PasteTextFromClipboard();
       break;
     }
     case Toolkit::TextSelectionPopup::SELECT:
index c067321..69c210d 100644 (file)
@@ -138,7 +138,7 @@ public:
   void GetText( std::string& text ) const;
 
   /**
-   * @brief Replaces any placeholder text previously set.
+   * @brief Remove a given number of characters
    *
    * @param[in] cursorOffset Start position from the current cursor position to start deleting characters.
    * @param[in] numberOfChars The number of characters to delete from the cursorOffset.