Remove unnecessray Clipboard creation in text controller
[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 #include <dali/devel-api/adaptor-framework/clipboard-event-notifier.h>
23
24 namespace Dali
25 {
26
27 namespace Internal
28 {
29
30 namespace Adaptor
31 {
32
33 /**
34  * Implementation of the Clip Board
35  */
36
37 class Clipboard :  public Dali::BaseObject
38 {
39 public:
40
41   /**
42    * @copydoc Dali::ClipboardEventNotifier::Get()
43    */
44   static Dali::Clipboard Get();
45
46   /**
47    * Constructor
48    * @param[in] ecoreXwin, The window is created by application.
49    */
50   Clipboard(/*Ecore_X_Window ecoreXwin*/);
51   virtual ~Clipboard();
52
53   /**
54    * @copydoc Dali::Clipboard::IsAvailable()
55    */
56   static bool IsAvailable();
57
58   /**
59    * @copydoc Dali::Clipboard::SetItem()
60    */
61   bool SetItem(const std::string &itemData);
62
63   /**
64    * @copydoc Dali::Clipboard::RequestItem()
65    */
66   void RequestItem();
67
68   /**
69    * @copydoc Dali::Clipboard::NumberOfClipboardItems()
70    */
71   unsigned int NumberOfItems();
72
73   /**
74    * @copydoc Dali::Clipboard::ShowClipboard()
75    */
76   void ShowClipboard();
77
78   /**
79    * @copydoc Dali::Clipboard::HideClipboard()
80    */
81   void HideClipboard();
82
83   /**
84   * @copydoc Dali::Clipboard::IsVisible()
85   */
86   bool IsVisible() const;
87
88 private:
89   Clipboard( const Clipboard& );
90   Clipboard& operator=( Clipboard& );
91
92   static Dali::Clipboard mToolkitClipboard;
93   bool mVisible;
94   std::string mItem;
95   int mCount;
96 }; // class clipboard
97
98
99 Dali::Clipboard Dali::Internal::Adaptor::Clipboard::mToolkitClipboard;
100
101
102 Clipboard::Clipboard()
103 {
104   mVisible = false;
105   mCount = 0;
106 }
107
108 Clipboard::~Clipboard()
109 {
110 }
111
112 Dali::Clipboard Clipboard::Get()
113 {
114   if( ! mToolkitClipboard )
115   {
116     mToolkitClipboard = Dali::Clipboard( new Dali::Internal::Adaptor::Clipboard() );
117   }
118   return mToolkitClipboard;
119 }
120
121 bool Clipboard::IsAvailable()
122 {
123   if(mToolkitClipboard)
124   {
125     return true;
126   }
127   return false;
128 }
129
130 bool Clipboard::SetItem(const std::string &itemData )
131 {
132   mItem = itemData;
133   mCount = 1;
134   return true;
135 }
136
137 void Clipboard::RequestItem()
138 {
139   Dali::ClipboardEventNotifier clipboardEventNotifier(Dali::ClipboardEventNotifier::Get());
140   if ( clipboardEventNotifier )
141   {
142     clipboardEventNotifier.SetContent( mItem );
143     clipboardEventNotifier.EmitContentSelectedSignal();
144   }
145 }
146
147 unsigned int Clipboard::NumberOfItems()
148 {
149   return mCount;
150 }
151
152 void Clipboard::ShowClipboard()
153 {
154   mVisible = true;
155 }
156
157 void Clipboard::HideClipboard()
158 {
159   mVisible = false;
160 }
161
162 bool Clipboard::IsVisible() const
163 {
164   return mVisible;
165 }
166
167 } // namespace Adaptor
168
169 } // namespace Internal
170
171
172 inline static Internal::Adaptor::Clipboard& GetImplementation(Dali::Clipboard& clipboard)
173 {
174   // Bypass any passed in clipboard handle - it probably won't be initialized
175   Dali::Clipboard theClipboard = Dali::Clipboard::Get();
176   BaseObject& object = theClipboard.GetBaseObject();
177   return static_cast<Internal::Adaptor::Clipboard&>(object);
178 }
179
180 inline static const  Internal::Adaptor::Clipboard& GetImplementation(const Dali::Clipboard& clipboard)
181 {
182   // Bypass any passed in clipboard handle - it probably won't be initialized
183   Dali::Clipboard theClipboard = Dali::Clipboard::Get();
184   const BaseObject& object = theClipboard.GetBaseObject();
185   return static_cast<const Internal::Adaptor::Clipboard&>(object);
186 }
187
188
189 Clipboard::Clipboard()
190 {
191 }
192 Clipboard::~Clipboard()
193 {
194 }
195 Clipboard::Clipboard(Internal::Adaptor::Clipboard *impl)
196   : BaseHandle(impl)
197 {
198 }
199
200 Clipboard Clipboard::Get()
201 {
202   return Internal::Adaptor::Clipboard::Get();
203 }
204 bool Clipboard::SetItem( const std::string &itemData)
205 {
206   return GetImplementation(*this).SetItem( itemData );
207 }
208
209 void Clipboard::RequestItem()
210 {
211   GetImplementation(*this).RequestItem();
212 }
213
214 unsigned int Clipboard::NumberOfItems()
215 {
216   return GetImplementation(*this).NumberOfItems();
217 }
218
219 void Clipboard::ShowClipboard()
220 {
221   GetImplementation(*this).ShowClipboard();
222 }
223
224 void Clipboard::HideClipboard()
225 {
226   GetImplementation(*this).HideClipboard();
227 }
228
229 bool Clipboard::IsVisible() const
230 {
231   return GetImplementation(*this).IsVisible();
232 }
233
234 } // namespace Dali