2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiClipboard.h
20 * @brief This is the header file for the %Clipboard class.
22 * This header file contains the declarations of the %Clipboard class and its helper classes.
25 #ifndef _FUI_CLIPBOARD_H_
26 #define _FUI_CLIPBOARD_H_
28 #include <FBaseObject.h>
29 #include <FBaseTypes.h>
30 #include <FBaseString.h>
31 #include <FBaseColIList.h>
32 #include <FUiClipboardItem.h>
33 #include <FUiIClipboard.h>
34 #include <FUiIClipboardPopupEventListener.h>
36 namespace Tizen { namespace Ui
42 * @brief This class defines a common behavior for %Clipboard.
46 * @final This class is not intended for extension.
48 * The %Clipboard class manages the copy and paste operation between and within applications.
50 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/ui/clipboard.htm">Clipboard</a>.
52 * The following example demonstrates how to use the %Clipboard class.
55 // Sample code for ClipboardSample.h
59 : public Tizen::Ui::Controls::Form
60 , public Tizen::Ui::IActionEventListener
66 bool Initialize(void);
67 virtual result OnInitializing(void);
69 // IActionEventListener
70 virtual void OnActionPerformed(const Tizen::Ui::Control& source, int actionId);
73 static const int ID_BUTTON_OK = 101;
75 Tizen::Ui::Controls::Label* __pLabel;
80 // Sample code for ClipboardSample.cpp
83 #include <FGraphics.h>
85 #include "ClipboardSample.h"
87 using namespace Tizen::App;
88 using namespace Tizen::Base;
89 using namespace Tizen::Graphics;
90 using namespace Tizen::Ui;
91 using namespace Tizen::Ui::Controls;
94 ClipboardSample::Initialize(void)
96 Construct(FORM_STYLE_NORMAL);
101 ClipboardSample::OnInitializing(void)
103 result r = E_SUCCESS;
105 // Sets data to a clip board item
107 String resourcePath = App::GetInstance()->GetAppResourcePath();
108 item.Construct(CLIPBOARD_DATA_TYPE_HTML, String(resourcePath + L"screen-size-normal/IDF_FORM.xml"));
110 // Gets an instance of Clipboard and copies an item to it
111 Clipboard* pClipboard = Clipboard::GetInstance();
112 pClipboard->CopyItem(item);
114 // Creates controls to test clipboard
115 Button* pButton = new Button();
116 pButton->Construct(Rectangle(50, 50, 200, 80), "COPY");
117 pButton->SetActionId(ID_BUTTON_OK);
118 pButton->AddActionEventListener(*this);
121 __pLabel = new Label();
122 __pLabel->Construct(Rectangle(0, 200, GetClientAreaBounds().width, 80), L"..");
123 AddControl(__pLabel);
129 ClipboardSample::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
135 // Gets an instance of Clipboard
136 Clipboard* pClipboard = Clipboard::GetInstance();
138 // Retrieves a latest item
139 ClipboardItem* pItem = pClipboard->RetrieveLatestItemN(CLIPBOARD_DATA_TYPE_TEXT
140 | CLIPBOARD_DATA_TYPE_HTML
141 | CLIPBOARD_DATA_TYPE_AUDIO
142 | CLIPBOARD_DATA_TYPE_VIDEO );
144 //Gets data from the clipboard item
145 String* pString = dynamic_cast<String*>(pItem->GetData());
147 __pLabel->SetText(*pString + L" is Copied");
148 __pLabel->Invalidate(false);
159 class _OSP_EXPORT_ Clipboard
160 : public Tizen::Base::Object
161 , public Tizen::Ui::IClipboard
165 * Gets the system clipboard.
169 * @return The pointer to the system clipboard, @n
170 * else @c null if a system error has occurred
171 * @remarks The copy and paste operation is performed through the system clipboard.
173 static Clipboard* GetInstance(void);
176 * Copies the specified @c item to the system clipboard.
180 * @return An error code
181 * @param[in] item The item to save in the system clipboard
182 * @exception E_SUCCESS The method is successful.
183 * @exception E_INVALID_ARG The specified input parameter is either invalid or not constructed.
184 * @exception E_SYSTEM A system error has occurred.
185 * @remarks For the text, image data, and html types, the data itself is copied by the method and kept by the system clipboard. @n
186 * For the other types, only the file path is copied and kept.
188 result CopyItem(const ClipboardItem& item);
191 * Retrieves a collection of items that matches the specified data types from the
196 * @return The pointer to a Tizen::Base::Collection::IList that contains a collection of ClipboardItem, @n
197 * else @c null if an error has occurred @n
198 * The items are sorted in the reverse order in which they are copied to the system clipboard. So, the first item is the latest one among them.
199 * @param[in] dataTypes The types of items @n
200 * Multiple data types of ClipboardDataType can be combined using bitwise OR.
201 * @exception E_SUCCESS The method is successful.
202 * @exception E_OBJ_NOT_FOUND The item of the specified data types is not found.
203 * @exception E_SYSTEM A system error has occurred.
204 * @remarks The specific error code can be accessed using the GetLastResult() method.
206 Tizen::Base::Collection::IList* RetrieveItemsN(unsigned long dataTypes);
209 * Retrieves the latest item for the specified data types from the system clipboard.
213 * @return The pointer to a ClipboardItem instance, @n
214 * else @c null if an error has occurred or there is no matched item in the system clipboard
215 * @param[in] dataTypes The types of items @n Multiple data types of ClipboardDataType can be
216 * combined using bitwise OR.
217 * @exception E_SUCCESS The method is successful.
218 * @exception E_OBJ_NOT_FOUND The item of the specified data types is not found.
219 * @exception E_SYSTEM A system error has occurred.
220 * @remarks The specific error code can be accessed using the GetLastResult() method.
222 Tizen::Ui::ClipboardItem* RetrieveLatestItemN(unsigned long dataTypes);
225 * Shows the clipboard popup that is including the current contents of the system clipboard with the specified parameters.
229 * @return An error code
230 * @param[in] dataTypes The types of items to decide whether the clipboard popup shows image items or not @n
231 * Multiple data types of ClipboardDataType can be combined using bitwise OR. @n
232 * If the value contains #CLIPBOARD_DATA_TYPE_IMAGE, all types of items are shown. @n
233 * If not, text items, html items, video items, and audio items are shown except image items.
234 * @param[in] listener The clipboard popup event listener
235 * @exception E_SUCCESS The method is successful.
236 * @exception E_INVALID_OPERATION Either the clipboard popup is currently being shown or attempting to show the clipboard popup
237 * when the application is in the background.
238 * @exception E_SYSTEM A system error has occurred.
239 * @remarks The user can operate the system clipboard when the clipboard popup is shown,
240 * for example, clear the system clipboard or choose a clipboard item for the paste operation.
242 static result ShowPopup(unsigned long dataTypes, const IClipboardPopupEventListener& listener);
245 * Hides the clipboard popup.
249 * @return An error code
250 * @exception E_SUCCESS The method is successful.
251 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
252 * - No clipboard popup is currently being shown.
253 * @exception E_SYSTEM A system error has occurred.
255 static result HidePopup(void);
258 * Checks whether the clipboard popup is currently being shown.
262 * @return @c true if the clipboard popup is being shown, @n
265 static bool IsPopupVisible(void);
269 // This default constructor is intentionally declared as private to implement the Singleton semantic.
274 // This destructor is intentionally declared as private to implement the Singleton semantic.
276 virtual ~Clipboard(void);
279 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
281 Clipboard(const Clipboard& rhs);
284 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
286 Clipboard& operator =(const Clipboard& rhs);
289 friend class _ClipboardImpl;
292 _ClipboardImpl* __pClipboardImpl;
297 #endif //_FUI_CLIPBOARD_H_