Revert "[3.0] Implement wayland clipboard"
[platform/core/uifw/dali-adaptor.git] / adaptors / ecore / wayland / clipboard-impl-ecore-wl.cpp
index 6c1ff67..a55508a 100644 (file)
 #include <dali/public-api/object/any.h>
 #include <dali/public-api/object/type-registry.h>
 #include <dali/integration-api/debug.h>
+#include <bundle.h>
 
 // INTERNAL INCLUDES
 #include <singleton-service-impl.h>
 
-namespace //unnamed namespace
-{
-const char* const CBHM_WINDOW = "CBHM_XWIN";
-const char* const CBHM_MSG = "CBHM_MSG";
-const char* const CBHM_ITEM = "CBHM_ITEM";
-const char* const CBHM_cCOUNT = "CBHM_cCOUNT";
-const char* const CBHM_ERROR = "CBHM_ERROR";
-const char* const SET_ITEM = "SET_ITEM";
-const char* const SHOW = "show0";
-const char* const HIDE = "cbhm_hide";
-}
+#define CLIPBOARD_STR  "CLIPBOARD_STR"
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Clipboard
@@ -53,17 +44,47 @@ namespace Internal
 namespace Adaptor
 {
 
-namespace
+struct Clipboard::Impl
 {
-BaseHandle Create()
-{
-  BaseHandle handle( Clipboard::Get() );
+  Impl()
+  {
+    mBundle = bundle_create();
+  }
 
-  return handle;
-}
-TypeRegistration CLIPBOARD_TYPE( typeid(Dali::Clipboard), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
+  void SetItem(const char *data)
+  {
+    char *temp = NULL;
+
+    if (bundle_get_str(mBundle, CLIPBOARD_STR, &temp) == BUNDLE_ERROR_NONE)
+    {
+      bundle_del(mBundle, CLIPBOARD_STR);
+    }
+    bundle_add_str(mBundle, CLIPBOARD_STR, data);
+  }
+
+  char *GetItem()
+  {
+    char *data = NULL;
 
-} // unnamed namespace
+    if ( bundle_get_count(mBundle) )
+    {
+      bundle_get_str(mBundle, CLIPBOARD_STR, &data);
+    }
+    return data;
+  }
+
+  int GetCount()
+  {
+    return bundle_get_count(mBundle);
+  }
+
+  bundle *mBundle;
+};
+
+Clipboard::Clipboard(Impl* impl)
+: mImpl(impl)
+{
+}
 
 Clipboard::~Clipboard()
 {
@@ -83,12 +104,20 @@ Dali::Clipboard Clipboard::Get()
       // If so, downcast the handle
       clipboard = Dali::Clipboard( dynamic_cast< Clipboard* >( handle.GetObjectPtr() ) );
     }
+    else
+    {
+      Clipboard::Impl* impl( new Clipboard::Impl() );
+      clipboard = Dali::Clipboard( new Clipboard(impl) );
+      service.Register( typeid(Dali::Clipboard), clipboard );
+    }
   }
 
   return clipboard;
 }
+
 bool Clipboard::SetItem(const std::string &itemData )
 {
+  mImpl->SetItem( const_cast<char*>( itemData.c_str()) );
   return true;
 }
 
@@ -97,16 +126,8 @@ bool Clipboard::SetItem(const std::string &itemData )
  */
 std::string Clipboard::GetItem( unsigned int index )  // change string to a Dali::Text object.
 {
-  if ( index >= NumberOfItems() )
-  {
-    return "";
-  }
-
-  std::string emptyString( "" );
-  char sendBuf[20];
-
-  snprintf( sendBuf, 20,  "%s%d", CBHM_ITEM, index );
-  return emptyString;
+  std::string clipboardString(mImpl->GetItem());
+  return clipboardString;
 }
 
 /*
@@ -114,9 +135,7 @@ std::string Clipboard::GetItem( unsigned int index )  // change string to a Dali
  */
 unsigned int Clipboard::NumberOfItems()
 {
-  int count = -1;
-
-  return count;
+  return mImpl->GetCount();
 }
 
 /**