From: Agnelo Vaz Date: Fri, 19 Jun 2015 15:39:55 +0000 (+0100) Subject: TextContoller Copy and Cut buttons functional X-Git-Tag: dali_1.0.46~7^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F01%2F42001%2F9;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git TextContoller Copy and Cut buttons functional Change-Id: I5a0d810048156e32f829fa05617fd2d25ac2ac40 Signed-off-by: Agnelo Vaz --- diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index e3ee4d6..cef33eb 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -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& utf32Characters = mLogicalModel->mText; + + Utf32ToUtf8( &utf32Characters[startOfSelectedText], lengthOfSelectedText, selectedText ); + + if ( deleteAfterRetreival ) // Only delete text if copied successfully + { + // Delete text between handles + Vector& currentText = mLogicalModel->mText; + + Vector::Iterator first = currentText.Begin() + startOfSelectedText; + Vector::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 ); } diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index bb0c2b5..dc5d3a6 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -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 ); diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index de3aa91..55ece1c 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -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: diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index c067321..69c210d 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -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.