System Clipboard shown and items can be pasted 78/42378/6
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Fri, 26 Jun 2015 12:19:12 +0000 (13:19 +0100)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Mon, 29 Jun 2015 10:14:39 +0000 (03:14 -0700)
Change-Id: I8703607879dd8e2c4ea2595ff24e6bbef579b145
Signed-off-by: Agnelo Vaz <agnelo.vaz@samsung.com>
dali-toolkit/internal/controls/text-controls/text-field-impl.cpp
dali-toolkit/internal/controls/text-controls/text-field-impl.h
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 385fd62..fbe2fd5 100644 (file)
@@ -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 );
index a305880..eb35b4f 100644 (file)
@@ -27,6 +27,9 @@
 #include <dali-toolkit/internal/text/text-controller.h>
 #include <dali-toolkit/internal/text/rendering/text-renderer.h>
 
+// EXTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
+
 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
 
   /**
index d5c6a14..5df31dc 100644 (file)
@@ -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 )
index 880004a..db0c0c3 100644 (file)
@@ -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 );
index 32e3ed3..e8df944 100644 (file)
@@ -23,6 +23,7 @@
 #include <iostream>
 #include <dali/public-api/adaptor-framework/key.h>
 #include <dali/integration-api/debug.h>
+#include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/text/bidirectional-support.h>
@@ -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;
index 2f83407..dfeffdc 100644 (file)
@@ -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 );