[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-clipboard.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 #include "toolkit-clipboard.h"
19
20 // EXTERNAL INCLUDES
21 #include <dali/public-api/object/base-object.h>
22
23 namespace Dali
24 {
25
26 namespace Internal
27 {
28
29 namespace Adaptor
30 {
31
32 /**
33  * Implementation of the Clipboard
34  */
35
36 class Clipboard :  public Dali::BaseObject
37 {
38 public:
39
40   /**
41    * @copydoc Dali::ClipboardEventNotifier::Get()
42    */
43   static Dali::Clipboard Get();
44
45   /**
46    * Constructor
47    * @param[in] ecoreXwin, The window is created by application.
48    */
49   Clipboard(/*Ecore_X_Window ecoreXwin*/);
50   virtual ~Clipboard();
51
52   /**
53    * @copydoc Dali::Clipboard::IsAvailable()
54    */
55   static bool IsAvailable();
56
57   /**
58    * @copydoc Dali::Clipboard::DataSentSignal()
59    */
60   Dali::Clipboard::DataSentSignalType& DataSentSignal();
61
62   /**
63    * @copydoc Dali::Clipboard::DataReceivedSignal()
64    */
65   Dali::Clipboard::DataReceivedSignalType& DataReceivedSignal();
66
67   /**
68    * @copydoc Dali::Clipboard::SetData()
69    */
70   bool SetData(const Dali::Clipboard::ClipData& clipData);
71
72   /**
73    * @copydoc Dali::Clipboard::GetData()
74    */
75   uint32_t GetData(const std::string &mimeType);
76
77   /**
78    * @copydoc Dali::Clipboard::NumberOfClipboardItems()
79    */
80   size_t NumberOfItems();
81
82   /**
83    * @copydoc Dali::Clipboard::ShowClipboard()
84    */
85   void ShowClipboard();
86
87   /**
88    * @copydoc Dali::Clipboard::HideClipboard()
89    */
90   void HideClipboard();
91
92   /**
93   * @copydoc Dali::Clipboard::IsVisible()
94   */
95   bool IsVisible() const;
96
97 private:
98   Clipboard( const Clipboard& );
99   Clipboard& operator=( Clipboard& );
100
101   static Dali::Clipboard mToolkitClipboard;
102
103   bool        mVisible;
104   std::string mMimeType;
105   std::string mData;
106   uint32_t    mDataId{0};
107   size_t      mCount;
108
109   Dali::Clipboard::DataSentSignalType     mDataSentSignal;
110   Dali::Clipboard::DataReceivedSignalType mDataReceivedSignal;
111 }; // class clipboard
112
113
114 Dali::Clipboard Dali::Internal::Adaptor::Clipboard::mToolkitClipboard;
115
116
117 Clipboard::Clipboard()
118 {
119   mVisible = false;
120   mCount = 0u;
121 }
122
123 Clipboard::~Clipboard()
124 {
125 }
126
127 Dali::Clipboard Clipboard::Get()
128 {
129   if(!mToolkitClipboard)
130   {
131     mToolkitClipboard = Dali::Clipboard(new Dali::Internal::Adaptor::Clipboard());
132   }
133   return mToolkitClipboard;
134 }
135
136 bool Clipboard::IsAvailable()
137 {
138   if(mToolkitClipboard)
139   {
140     return true;
141   }
142   return false;
143 }
144
145 Dali::Clipboard::DataSentSignalType& Clipboard::DataSentSignal()
146 {
147   return mDataSentSignal;
148 }
149
150 Dali::Clipboard::DataReceivedSignalType& Clipboard::DataReceivedSignal()
151 {
152   return mDataReceivedSignal;
153 }
154
155 bool Clipboard::SetData(const Dali::Clipboard::ClipData& clipData)
156 {
157   mMimeType = clipData.GetMimeType();
158   mData     = clipData.GetData();
159   mCount    = 1u;
160
161   if(mData.empty())
162   {
163     return false;
164   }
165
166   mDataSentSignal.Emit(mMimeType.c_str(), mData.c_str());
167
168   return true;
169 }
170
171 uint32_t Clipboard::GetData(const std::string &mimeType)
172 {
173   if(!mMimeType.compare(mimeType.c_str()))
174   {
175     mDataId++;
176     mDataReceivedSignal.Emit(mDataId, mMimeType.c_str(), mData.c_str());
177     return mDataId;
178   }
179   return 0u;
180 }
181
182 size_t Clipboard::NumberOfItems()
183 {
184   return mCount;
185 }
186
187 void Clipboard::ShowClipboard()
188 {
189   mVisible = true;
190 }
191
192 void Clipboard::HideClipboard()
193 {
194   mVisible = false;
195 }
196
197 bool Clipboard::IsVisible() const
198 {
199   return mVisible;
200 }
201
202 } // namespace Adaptor
203
204 } // namespace Internal
205
206
207 inline static Internal::Adaptor::Clipboard& GetImplementation(Dali::Clipboard& clipboard)
208 {
209   // Bypass any passed in clipboard handle - it probably won't be initialized
210   Dali::Clipboard theClipboard = Dali::Clipboard::Get();
211   BaseObject& object = theClipboard.GetBaseObject();
212   return static_cast<Internal::Adaptor::Clipboard&>(object);
213 }
214
215 inline static const  Internal::Adaptor::Clipboard& GetImplementation(const Dali::Clipboard& clipboard)
216 {
217   // Bypass any passed in clipboard handle - it probably won't be initialized
218   Dali::Clipboard theClipboard = Dali::Clipboard::Get();
219   const BaseObject& object = theClipboard.GetBaseObject();
220   return static_cast<const Internal::Adaptor::Clipboard&>(object);
221 }
222
223
224 Clipboard::Clipboard()
225 {
226 }
227 Clipboard::~Clipboard()
228 {
229 }
230 Clipboard::Clipboard(Internal::Adaptor::Clipboard *impl)
231   : BaseHandle(impl)
232 {
233 }
234
235 Clipboard Clipboard::Get()
236 {
237   return Internal::Adaptor::Clipboard::Get();
238 }
239
240 size_t Clipboard::NumberOfItems()
241 {
242   return GetImplementation(*this).NumberOfItems();
243 }
244
245 void Clipboard::ShowClipboard()
246 {
247   GetImplementation(*this).ShowClipboard();
248 }
249
250 void Clipboard::HideClipboard()
251 {
252   GetImplementation(*this).HideClipboard();
253 }
254
255 bool Clipboard::IsVisible() const
256 {
257   return GetImplementation(*this).IsVisible();
258 }
259
260 } // namespace Dali