Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / FUiClipboard.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17 /**
18  * @file                FUiClipboard.cpp
19  * @brief               This is the implementation file for Clipboard class.
20  * @version             1.0
21  *
22  * This file contains the implementation of Header class.
23  */
24 #include <FUiClipboard.h>
25 #include <FUiClipboardItem.h>
26 #include <FBaseSysLog.h>
27 #include "FUi_ClipboardImpl.h"
28 #include "FUi_ClipboardItemImpl.h"
29
30 using namespace Tizen::Base::Collection;
31
32 namespace Tizen { namespace Ui
33 {
34
35 result
36 Clipboard::CopyItem(const ClipboardItem& item)
37 {
38         SysAssertf((__pClipboardImpl != null), "Clipboard wasn't initialized.");
39
40         const _ClipboardItemImpl* pItemImpl = _ClipboardItemImpl::GetInstance(item);
41         SysTryReturn(NID_UI, pItemImpl, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] A specified input parameter is invalid.");
42
43         result r = __pClipboardImpl->CopyItem(*pItemImpl);
44         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
45
46         return r;
47 }
48
49 IList*
50 Clipboard::RetrieveItemsN(unsigned long dataTypes)
51 {
52         SysAssertf((__pClipboardImpl != null), "Clipboard wasn't initialized.");
53
54         IList* pList = __pClipboardImpl->RetrieveItemsN(dataTypes);
55         result r = GetLastResult();
56         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
57
58         SetLastResult(E_SUCCESS);
59
60         return pList;
61
62 CATCH:
63         if (pList)
64         {
65                 pList->RemoveAll(true);
66                 delete pList;
67         }
68
69         return null;
70 }
71
72 ClipboardItem*
73 Clipboard::RetrieveLatestItemN(unsigned long dataTypes)
74 {
75         SysAssertf((__pClipboardImpl != null), "Clipboard wasn't initialized.");
76
77         _ClipboardItemImpl* pItemImpl = __pClipboardImpl->RetrieveLatestItemN(dataTypes);
78         result r = GetLastResult();
79         SysTryReturn(NID_UI, pItemImpl, null, r, "[%s] Propagating.", GetErrorMessage(r));
80         SysTryReturn(NID_UI, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
81
82         SetLastResult(E_SUCCESS);
83
84         return &(pItemImpl->GetPublic());
85 }
86
87 result
88 Clipboard::ShowPopup(unsigned long dataTypes, const Tizen::Ui::IClipboardPopupEventListener& listener)
89 {
90         Clipboard* pClipboard = GetInstance();
91         SysAssertf((pClipboard != null), "Clipboard wasn't initialized.");
92
93         _ClipboardImpl* pClipboardImpl = _ClipboardImpl::GetInstance(*pClipboard);
94         SysAssertf((pClipboardImpl != null), "Clipboard wasn't initialized.");
95
96         result r = pClipboardImpl->ShowPopup(dataTypes, listener);
97         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
98
99         return r;
100 }
101
102 result
103 Clipboard::HidePopup(void)
104 {
105         Clipboard* pClipboard = GetInstance();
106         SysAssertf((pClipboard != null), "Clipboard wasn't initialized.");
107
108         _ClipboardImpl* pClipboardImpl = _ClipboardImpl::GetInstance(*pClipboard);
109         SysAssertf((pClipboardImpl != null), "Clipboard wasn't initialized.");
110
111         result r = pClipboardImpl->HidePopup();
112         SysTryReturn(NID_UI, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
113
114         return r;
115 }
116
117 bool
118 Clipboard::IsPopupVisible(void)
119 {
120         Clipboard* pClipboard = GetInstance();
121         SysAssertf((pClipboard != null), "Clipboard wasn't initialized.");
122
123         _ClipboardImpl* pClipboardImpl = _ClipboardImpl::GetInstance(*pClipboard);
124         SysAssertf((pClipboardImpl != null), "Clipboard wasn't initialized.");
125
126         return pClipboardImpl->IsPopupVisible();
127 }
128
129 Clipboard*
130 Clipboard::GetInstance(void)
131 {
132         static Clipboard instance;
133
134         return (&instance);
135 }
136
137 Clipboard::Clipboard(void)
138         : __pClipboardImpl(null)
139 {
140         __pClipboardImpl = _ClipboardImpl::CreateInstanceN();
141 }
142
143 Clipboard::~Clipboard(void)
144 {
145         delete __pClipboardImpl;
146         __pClipboardImpl = null;
147 }
148
149 }} //Tizen::Ui