From: Agnelo Vaz Date: Fri, 26 Jun 2015 12:19:12 +0000 (+0100) Subject: System Clipboard shown and items can be pasted X-Git-Tag: dali_1.0.47~11^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=6a58cf6dc58bc4d8810f545ea700959d59485ae1 System Clipboard shown and items can be pasted Change-Id: I8703607879dd8e2c4ea2595ff24e6bbef579b145 Signed-off-by: Agnelo Vaz --- diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index 385fd62..fbe2fd5 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -1006,6 +1006,13 @@ void TextField::OnKeyInputFocusGained() imfManager.SetRestoreAfterFocusLost( true ); } + ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() ); + + if ( notifier ) + { + notifier.ContentSelectedSignal().Connect( this, &TextField::OnClipboardTextSelected ); + } + mController->KeyboardFocusGainEvent(); EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last. @@ -1029,6 +1036,13 @@ void TextField::OnKeyInputFocusLost() imfManager.EventReceivedSignal().Disconnect( this, &TextField::OnImfEvent ); } + ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() ); + + if ( notifier ) + { + notifier.ContentSelectedSignal().Disconnect( this, &TextField::OnClipboardTextSelected ); + } + mController->KeyboardFocusLostEvent(); EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last. @@ -1147,6 +1161,11 @@ void TextField::EnableClipping( bool clipping, const Vector2& size ) } } +void TextField::OnClipboardTextSelected( ClipboardEventNotifier& clipboard ) +{ + mController->PasteClipboardItemEvent(); +} + void TextField::KeyboardStatusChanged(bool keyboardShown) { DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextField::KeyboardStatusChanged %p keyboardShown %d\n", mController.Get(), keyboardShown ); diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.h b/dali-toolkit/internal/controls/text-controls/text-field-impl.h index a305880..eb35b4f 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -27,6 +27,9 @@ #include #include +// EXTERNAL INCLUDES +#include + namespace Dali { @@ -171,6 +174,12 @@ private: // From Control */ ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent ); + /** + * @brief Callback when Clipboard signals an item should be pasted + * @param[in] clipboard handle to Clipboard Event Notifier + */ + void OnClipboardTextSelected( ClipboardEventNotifier& clipboard ); + private: // Implementation /** diff --git a/dali-toolkit/internal/text/text-controller-impl.cpp b/dali-toolkit/internal/text/text-controller-impl.cpp index d5c6a14..5df31dc 100644 --- a/dali-toolkit/internal/text/text-controller-impl.cpp +++ b/dali-toolkit/internal/text/text-controller-impl.cpp @@ -823,6 +823,22 @@ void Controller::Impl::RetrieveSelection( std::string& selectedText, bool delete } } +void Controller::Impl::ShowClipboard() +{ + if ( mClipboard ) + { + mClipboard.ShowClipboard(); + } +} + +void Controller::Impl::HideClipboard() +{ + if ( mClipboard ) + { + mClipboard.HideClipboard(); + } +} + bool Controller::Impl::CopyStringToClipboard( std::string& source ) { //Send string to clipboard @@ -971,6 +987,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) mEventData->mDecorator->SetHandleActive( RIGHT_SELECTION_HANDLE, false ); mEventData->mDecorator->SetPopupActive( false ); mEventData->mDecoratorUpdated = true; + HideClipboard(); } else if ( EventData::SELECTING == mEventData->mState ) { @@ -985,6 +1002,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) if ( !IsClipboardEmpty() ) { buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); + buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) ); } mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow ); @@ -1000,6 +1018,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) if ( !IsClipboardEmpty() ) { buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); + buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) ); } mEventData->mDecorator->SetActiveCursor( ACTIVE_CURSOR_NONE ); mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow ); @@ -1023,6 +1042,7 @@ void Controller::Impl::ChangeState( EventData::State newState ) mEventData->mDecorator->SetPopupActive( false ); } mEventData->mDecoratorUpdated = true; + HideClipboard(); } else if( EventData::EDITING_WITH_POPUP == mEventData->mState ) { @@ -1047,11 +1067,13 @@ void Controller::Impl::ChangeState( EventData::State newState ) if ( !IsClipboardEmpty() ) { buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::PASTE ) ); + buttonsToShow = TextSelectionPopup::Buttons ( ( buttonsToShow | TextSelectionPopup::CLIPBOARD ) ); } mEventData->mDecorator->SetEnabledPopupButtons( buttonsToShow ); mEventData->mDecorator->SetPopupActive( true ); } + HideClipboard(); mEventData->mDecoratorUpdated = true; } else if ( EventData::SELECTION_HANDLE_PANNING == mEventData->mState ) diff --git a/dali-toolkit/internal/text/text-controller-impl.h b/dali-toolkit/internal/text/text-controller-impl.h index 880004a..db0c0c3 100644 --- a/dali-toolkit/internal/text/text-controller-impl.h +++ b/dali-toolkit/internal/text/text-controller-impl.h @@ -341,6 +341,10 @@ struct Controller::Impl void RetrieveSelection( std::string& selectedText, bool deleteAfterRetreival ); + void ShowClipboard(); + + void HideClipboard(); + bool CopyStringToClipboard( std::string& source ); void SendSelectionToClipboard( bool deleteAfterSending ); diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index 32e3ed3..e8df944 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -23,6 +23,7 @@ #include #include #include +#include // INTERNAL INCLUDES #include @@ -1475,6 +1476,20 @@ void Controller::DecorationEvent( HandleType handleType, HandleState state, floa } } +void Controller::PasteText( const std::string& stringToPaste ) +{ + InsertText( stringToPaste, Text::Controller::COMMIT ); + mImpl->ChangeState( EventData::EDITING ); + mImpl->RequestRelayout(); +} + +void Controller::PasteClipboardItemEvent() +{ + ClipboardEventNotifier notifier( ClipboardEventNotifier::Get() ); + std::string stringToPaste( notifier.GetContent() ); + PasteText( stringToPaste ); +} + void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Buttons button ) { if( NULL == mImpl->mEventData ) @@ -1512,9 +1527,7 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt { std::string stringToPaste(""); mImpl->GetTextFromClipboard( 0, stringToPaste ); // Paste latest item from system clipboard - InsertText( stringToPaste, Text::Controller::COMMIT ); - mImpl->ChangeState( EventData::EDITING ); - mImpl->RequestRelayout(); + PasteText( stringToPaste ); break; } case Toolkit::TextSelectionPopup::SELECT: @@ -1536,6 +1549,7 @@ void Controller::TextPopupButtonTouched( Dali::Toolkit::TextSelectionPopup::Butt } case Toolkit::TextSelectionPopup::CLIPBOARD: { + mImpl->ShowClipboard(); break; } case Toolkit::TextSelectionPopup::NONE: @@ -1611,7 +1625,6 @@ ImfManager::ImfCallbackData Controller::OnImfEvent( ImfManager& imfManager, cons return callbackData; } - Controller::~Controller() { delete mImpl; diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 2f83407..dfeffdc 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -545,6 +545,17 @@ public: ImfManager::ImfCallbackData OnImfEvent( ImfManager& imfManager, const ImfManager::ImfEventData& imfEvent ); /** + * @brief Paste given string into Text model + * @param[in] stringToPaste this string will be inserted into the text model + */ + void PasteText( const std::string& stringToPaste ); + + /** + * @brief Event from Clipboard notifying an Item has been selected for pasting + */ + void PasteClipboardItemEvent(); + + /** * @copydoc Dali::Toolkit::Text::Decorator::ControllerInterface::GetTargetSize() */ virtual void GetTargetSize( Vector2& targetSize );