Revert " modify license, permission and remove ^M char"
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlOptionMenu.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 /**
19  * @file                FUiCtrlOptionMenu.cpp
20  * @brief               This is the implementation file for the OptionMenu class.
21  */
22
23 #include <FUiCtrlOptionMenu.h>
24 #include <FBaseSysLog.h>
25
26 #include "FUiCtrl_OptionMenuImpl.h"
27
28 using namespace Tizen::Base;
29
30 namespace Tizen { namespace Ui { namespace Controls
31 {
32
33 OptionMenu::OptionMenu(void)
34 {
35 }
36
37 OptionMenu::~OptionMenu(void)
38 {
39 }
40
41 result
42 OptionMenu::Construct(void)
43 {
44         ClearLastResult();
45         SysAssertf((_OptionMenuImpl::GetInstance(*this) == null),
46                                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
47
48         // Create _OptionMenuImpl
49         _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::CreateOptionMenuImplN(*this);
50         result r = GetLastResult();
51         SysTryReturn(NID_UI_CTRL, pOptionMenuImpl != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
52
53         // Set _OptionMenuImpl
54         _pControlImpl = pOptionMenuImpl;
55
56         return E_SUCCESS;
57 }
58
59 void
60 OptionMenu::AddActionEventListener(IActionEventListener& listener)
61 {
62         ClearLastResult();
63
64         _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
65         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
66
67         result r = pOptionMenuImpl->AddActionEventListener(listener);
68         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
69 }
70
71 void
72 OptionMenu::RemoveActionEventListener(IActionEventListener& listener)
73 {
74         ClearLastResult();
75
76         _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
77         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
78
79         result r = pOptionMenuImpl->RemoveActionEventListener(listener);
80         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
81 }
82
83 result
84 OptionMenu::AddItem(const String& text, int actionId)
85 {
86         ClearLastResult();
87
88         _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
89         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
90
91         result r = pOptionMenuImpl->AddItem(text, actionId);
92         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
93
94         return r;
95 }
96
97 result
98 OptionMenu::InsertItemAt(int mainIndex, const String& text, int actionId)
99 {
100         ClearLastResult();
101
102         _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
103         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
104
105         result r = pOptionMenuImpl->InsertItemAt(mainIndex, text, actionId);
106         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
107
108         return r;
109 }
110
111 result
112 OptionMenu::SetItemAt(int mainIndex, const String& text, int actionId)
113 {
114         ClearLastResult();
115
116         _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
117         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
118
119         result r = pOptionMenuImpl->SetItemAt(mainIndex, text, actionId);
120         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
121
122         return r;
123 }
124
125 result
126 OptionMenu::RemoveItemAt(int mainIndex)
127 {
128         ClearLastResult();
129
130         _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
131         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
132
133         result r = pOptionMenuImpl->RemoveItemAt(mainIndex);
134         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
135
136         return r;
137 }
138
139 int
140 OptionMenu::GetItemCount(void) const
141 {
142         ClearLastResult();
143
144         const _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
145         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
146
147         int count = pOptionMenuImpl->GetItemCount();
148         result r = GetLastResult();
149         SysTryReturn(NID_UI_CTRL, (count >= 0), -1, r, "[%s] Propagating.", GetErrorMessage(r));
150
151         return count;
152 }
153
154 int
155 OptionMenu::GetItemIndexFromActionId(int actionId) const
156 {
157         ClearLastResult();
158
159         const _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
160         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
161
162         int index = pOptionMenuImpl->GetItemIndexFromActionId(actionId);
163         result r = GetLastResult();
164         SysTryReturn(NID_UI_CTRL, (index >= 0), -1, r, "[%s] Propagating.", GetErrorMessage(r));
165
166         return index;
167 }
168
169 int
170 OptionMenu::GetItemActionIdAt(int mainIndex) const
171 {
172         ClearLastResult();
173
174         const _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
175         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
176
177         int actionId = pOptionMenuImpl->GetItemActionIdAt(mainIndex);
178         result r = GetLastResult();
179         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), -1, r, "[%s] Propagating.", GetErrorMessage(r));
180
181         return actionId;
182 }
183
184 result
185 OptionMenu::AddSubItem(int mainIndex, const String& text, int actionId)
186 {
187         ClearLastResult();
188
189         _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
190         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
191
192         result r = pOptionMenuImpl->AddSubItem(mainIndex, text, actionId);
193         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
194
195         return r;
196 }
197
198 result
199 OptionMenu::InsertSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
200 {
201         ClearLastResult();
202
203         _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
204         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
205
206         result r = pOptionMenuImpl->InsertSubItemAt(mainIndex, subIndex, text, actionId);
207         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
208
209         return r;
210 }
211
212 result
213 OptionMenu::SetSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
214 {
215         ClearLastResult();
216
217         _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
218         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
219
220         result r = pOptionMenuImpl->SetSubItemAt(mainIndex, subIndex, text, actionId);
221         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
222
223         return r;
224 }
225
226 result
227 OptionMenu::RemoveSubItemAt(int mainIndex, int subIndex)
228 {
229         ClearLastResult();
230
231         _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
232         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
233
234         result r = pOptionMenuImpl->RemoveSubItemAt(mainIndex, subIndex);
235         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
236
237         return r;
238 }
239
240 int
241 OptionMenu::GetSubItemCount(int mainIndex) const
242 {
243         ClearLastResult();
244
245         const _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
246         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
247
248         int count = pOptionMenuImpl->GetSubItemCount(mainIndex);
249         result r = GetLastResult();
250         SysTryReturn(NID_UI_CTRL, (count >= 0), -1, r, "[%s] Propagating.", GetErrorMessage(r));
251
252         return count;
253 }
254
255 int
256 OptionMenu::GetSubItemIndexFromActionId(int actionId) const
257 {
258         ClearLastResult();
259
260         const _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
261         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
262
263         int index = pOptionMenuImpl->GetSubItemIndexFromActionId(actionId);
264         result r = GetLastResult();
265         SysTryReturn(NID_UI_CTRL, (index >= 0), -1, r, "[%s] Propagating.", GetErrorMessage(r));
266
267         return index;
268 }
269
270 int
271 OptionMenu::GetSubItemActionIdAt(int mainIndex, int subIndex) const
272 {
273         ClearLastResult();
274
275         const _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
276         SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
277
278         int actionId = pOptionMenuImpl->GetSubItemActionIdAt(mainIndex, subIndex);
279         result r = GetLastResult();
280         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), -1, r, "[%s] Propagating.", GetErrorMessage(r));
281
282         return actionId;
283 }
284
285 }}} //Tizen::Ui::Controls