Revert "[Tizen] keygrab & ecore-wl-window-handle c# binding"
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / clipboard-impl-x.cpp
index 3d0f0f9..de8c98d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 // EXTERNAL INCLUDES
 #include <Ecore_X.h>
-#include <dali/public-api/dali-core.h>
+#include <dali/public-api/object/any.h>
+#include <dali/public-api/object/type-registry.h>
 #include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/object/any.h>
 #include <adaptor-impl.h>
 #include <ecore-x-window-interface.h>
 #include <singleton-service-impl.h>
+#include <clipboard-event-notifier-impl.h>
 
 namespace //unnamed namespace
 {
@@ -54,50 +55,24 @@ namespace Internal
 namespace Adaptor
 {
 
-namespace
-{
-BaseHandle Create()
+struct Clipboard::Impl
 {
-  BaseHandle handle( Clipboard::Get() );
-
-  if ( !handle && Adaptor::IsAvailable() )
+  Impl( Ecore_X_Window ecoreXwin )
   {
-    Dali::SingletonService service( SingletonService::Get() );
-    if ( service )
-    {
-      Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
-
-      // The Ecore_X_Window needs to use the Clipboard.
-      // Only when the render surface is window, we can get the Ecore_X_Window.
-      Ecore_X_Window ecoreXwin( 0 );
-      Dali::RenderSurface& surface( adaptorImpl.GetSurface() );
-      if( surface.GetType() == Dali::RenderSurface::WINDOW )
-      {
-        ecoreXwin = AnyCast< Ecore_X_Window >( adaptorImpl.GetSurface().GetSurface() );
-      }
-
-      // If we fail to get Ecore_X_Window, we can't use the Clipboard correctly.
-      // Thus you have to call "ecore_imf_context_client_window_set" somewhere.
-      // In EvasPlugIn, this function is called in EvasPlugin::ConnectEcoreEvent().
-      Dali::Clipboard clipboard = Dali::Clipboard( new Clipboard( ecoreXwin ) );
-      service.Register( typeid( clipboard ), clipboard );
-      handle = clipboard;
-    }
+    mApplicationWindow = ecoreXwin;
   }
 
-  return handle;
-}
-TypeRegistration CLIPBOARD_TYPE( typeid(Dali::Clipboard), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
-
-} // unnamed namespace
+  Ecore_X_Window mApplicationWindow;
+};
 
-Clipboard::Clipboard( Ecore_X_Window ecoreXwin)
+Clipboard::Clipboard(Impl* impl)
+: mImpl( impl )
 {
-  mApplicationWindow = ecoreXwin;
 }
 
 Clipboard::~Clipboard()
 {
+  delete mImpl;
 }
 
 Dali::Clipboard Clipboard::Get()
@@ -114,6 +89,24 @@ Dali::Clipboard Clipboard::Get()
       // If so, downcast the handle
       clipboard = Dali::Clipboard( dynamic_cast< Clipboard* >( handle.GetObjectPtr() ) );
     }
+    else
+    {
+      Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
+      Any nativewindow = adaptorImpl.GetNativeWindowHandle();
+
+      // The Ecore_X_Window needs to use the Clipboard.
+      // Only when the render surface is window, we can get the Ecore_X_Window.
+      Ecore_X_Window ecoreXwin( AnyCast<Ecore_X_Window>(nativewindow) );
+      if (ecoreXwin)
+      {
+        // If we fail to get Ecore_X_Window, we can't use the Clipboard correctly.
+        // Thus you have to call "ecore_imf_context_client_window_set" somewhere.
+        // In EvasPlugIn, this function is called in EvasPlugin::ConnectEcoreEvent().
+        Clipboard::Impl* impl( new Clipboard::Impl( ecoreXwin ) );
+        clipboard = Dali::Clipboard( new Clipboard( impl ) );
+        service.Register( typeid( clipboard ), clipboard );
+      }
+    }
   }
 
   return clipboard;
@@ -135,32 +128,36 @@ bool Clipboard::SetItem(const std::string &itemData )
 }
 
 /*
- * Get string at given index of clipboard
+ * Request clipboard service to retrieve an item
  */
-std::string Clipboard::GetItem( unsigned int index )  // change string to a Dali::Text object.
+void Clipboard::RequestItem()
 {
-  if ( index >= NumberOfItems() )
-  {
-    return "";
-  }
-
-  std::string emptyString( "" );
+  int index = 0;
   char sendBuf[20];
-
   snprintf( sendBuf, 20,  "%s%d", CBHM_ITEM, index );
   Ecore_X_Atom xAtomCbhmItem = ecore_x_atom_get( sendBuf );
   Ecore_X_Atom xAtomItemType = 0;
 
   std::string clipboardString( ECore::WindowInterface::GetWindowProperty(xAtomCbhmItem, &xAtomItemType, index ) );
-  if ( !clipboardString.empty() )
+
+  // Only return the text string if the Atom type is text (Do not return a text string/URL for images).
+  if( !clipboardString.empty() &&
+      ( xAtomItemType == ECORE_X_ATOM_TEXT || xAtomItemType == ECORE_X_ATOM_COMPOUND_TEXT || xAtomItemType == ECORE_X_ATOM_STRING || xAtomItemType == ECORE_X_ATOM_UTF8_STRING ) )
   {
     Ecore_X_Atom xAtomCbhmError = ecore_x_atom_get( CBHM_ERROR );
     if ( xAtomItemType != xAtomCbhmError )
     {
-      return clipboardString;
+      // Call ClipboardEventNotifier to notify event observe of retrieved string
+      Dali::ClipboardEventNotifier clipboardEventNotifier(ClipboardEventNotifier::Get());
+      if ( clipboardEventNotifier )
+      {
+        ClipboardEventNotifier& notifierImpl( ClipboardEventNotifier::GetImplementation( clipboardEventNotifier ) );
+
+        notifierImpl.SetContent( clipboardString );
+        notifierImpl.EmitContentSelectedSignal();
+      }
     }
-   }
-   return emptyString;
+  }
 }
 
 /*
@@ -171,7 +168,7 @@ unsigned int Clipboard::NumberOfItems()
   Ecore_X_Atom xAtomCbhmCountGet = ecore_x_atom_get( CBHM_cCOUNT );
 
   std::string ret( ECore::WindowInterface::GetWindowProperty( xAtomCbhmCountGet, NULL, 0 ) );
-  int count = -1;
+  int count = 0;
 
   if ( !ret.empty() )
   {
@@ -189,7 +186,7 @@ unsigned int Clipboard::NumberOfItems()
 void Clipboard::ShowClipboard()
 {
   // Claim the ownership of the SECONDARY selection.
-  ecore_x_selection_secondary_set(mApplicationWindow, "", 1);
+  ecore_x_selection_secondary_set(mImpl->mApplicationWindow, "", 1);
   Ecore_X_Window cbhmWin = ECore::WindowInterface::GetWindow();
 
   // Launch the clipboard window
@@ -197,7 +194,7 @@ void Clipboard::ShowClipboard()
   ECore::WindowInterface::SendXEvent( ecore_x_display_get(), cbhmWin, False, NoEventMask, atomCbhmMsg, 8, SHOW );
 }
 
-void Clipboard::HideClipboard()
+void Clipboard::HideClipboard(bool skipFirstHide)
 {
   Ecore_X_Window cbhmWin = ECore::WindowInterface::GetWindow();
   // Launch the clipboard window
@@ -208,6 +205,15 @@ void Clipboard::HideClipboard()
   ecore_x_selection_secondary_clear();
 }
 
+bool Clipboard::IsVisible() const
+{
+  return false;
+}
+
+char* Clipboard::ExcuteBuffered( bool type, void *event )
+{
+  return NULL;
+}
 
 } // namespace Adaptor