513ec21952bcc5ebdfbde7628b2c50db56ddc78d
[platform/core/uifw/dali-adaptor.git] / adaptors / ecore / wayland / clipboard-impl-ecore-wl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "clipboard-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <Ecore.h>
23 #include <Ecore_Wayland.h>
24 #include <dali/public-api/object/any.h>
25 #include <dali/public-api/object/type-registry.h>
26 #include <dali/integration-api/debug.h>
27 #include <bundle.h>
28
29 // INTERNAL INCLUDES
30 #include <singleton-service-impl.h>
31
32 #define CLIPBOARD_STR  "CLIPBOARD_STR"
33
34 ///////////////////////////////////////////////////////////////////////////////////////////////////
35 // Clipboard
36 ///////////////////////////////////////////////////////////////////////////////////////////////////
37
38 namespace Dali
39 {
40
41 namespace Internal
42 {
43
44 namespace Adaptor
45 {
46
47 struct Clipboard::Impl
48 {
49   Impl()
50   {
51     mBundle = bundle_create();
52   }
53
54   void SetItem(const char *data)
55   {
56     bundle_add_str(mBundle, CLIPBOARD_STR, data);
57   }
58
59   char *GetItem()
60   {
61     char *data = NULL;
62
63     if ( bundle_get_count(mBundle) )
64     {
65       bundle_get_str(mBundle, CLIPBOARD_STR, &data);
66     }
67     return data;
68   }
69
70   int GetCount()
71   {
72     return bundle_get_count(mBundle);
73   }
74
75   bundle *mBundle;
76 };
77
78 Clipboard::Clipboard(Impl* impl)
79 : mImpl(impl)
80 {
81 }
82
83 Clipboard::~Clipboard()
84 {
85 }
86
87 Dali::Clipboard Clipboard::Get()
88 {
89   Dali::Clipboard clipboard;
90
91   Dali::SingletonService service( SingletonService::Get() );
92   if ( service )
93   {
94     // Check whether the singleton is already created
95     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::Clipboard ) );
96     if(handle)
97     {
98       // If so, downcast the handle
99       clipboard = Dali::Clipboard( dynamic_cast< Clipboard* >( handle.GetObjectPtr() ) );
100     }
101     else
102     {
103       Clipboard::Impl* impl( new Clipboard::Impl() );
104       clipboard = Dali::Clipboard( new Clipboard(impl) );
105       service.Register( typeid(Dali::Clipboard), clipboard );
106     }
107   }
108
109   return clipboard;
110 }
111
112 bool Clipboard::SetItem(const std::string &itemData )
113 {
114   mImpl->SetItem( const_cast<char*>( itemData.c_str()) );
115   return true;
116 }
117
118 /*
119  * Get string at given index of clipboard
120  */
121 std::string Clipboard::GetItem( unsigned int index )  // change string to a Dali::Text object.
122 {
123   std::string clipboardString(mImpl->GetItem());
124   return clipboardString;
125 }
126
127 /*
128  * Get number of items in clipboard
129  */
130 unsigned int Clipboard::NumberOfItems()
131 {
132   return mImpl->GetCount();
133 }
134
135 /**
136  * Show clipboard window
137  * Function to send message to show the Clipboard (cbhm) as no direct API available
138  * Reference elementary/src/modules/ctxpopup_copypasteUI/cbhm_helper.c
139  */
140 void Clipboard::ShowClipboard()
141 {
142 }
143
144 void Clipboard::HideClipboard()
145 {
146 }
147
148
149 } // namespace Adaptor
150
151 } // namespace Internal
152
153 } // namespace Dali