X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Ftext-controller-impl.cpp;h=cef33ebf12a69e645f695942b956bde530b0ef92;hb=refs%2Fchanges%2F01%2F42001%2F9;hp=d900032c19d26e5acc440eea4d6192bf2c43292d;hpb=660217ee14bc7302e2658ca76af6dda7b928ab2f;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index d900032..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 ) { @@ -453,7 +452,7 @@ void Controller::Impl::OnCursorKeyEvent( const Event& event ) } else if( Dali::DALI_KEY_CURSOR_RIGHT == keyCode ) { - if( mLogicalModel->GetNumberOfCharacters() > mEventData->mPrimaryCursorPosition ) + if( mLogicalModel->mText.Count() > mEventData->mPrimaryCursorPosition ) { mEventData->mPrimaryCursorPosition = CalculateNewCursorIndex( mEventData->mPrimaryCursorPosition ); } @@ -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 ); } @@ -1150,7 +1205,7 @@ void Controller::Impl::GetCursorPosition( CharacterIndex logical, // Check if the logical position is the first or the last one of the text. const bool isFirstPosition = 0u == logical; - const bool isLastPosition = mLogicalModel->GetNumberOfCharacters() == logical; + const bool isLastPosition = mLogicalModel->mText.Count() == logical; if( isFirstPosition && isLastPosition ) {