Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_OptionMenuImpl.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                FUiCtrl_OptionMenuImpl.cpp
19  * @brief               This is the implementation file for the _OptionMenuImpl class.
20  */
21
22 #include <FBaseSysLog.h>
23 #include <FBaseResult.h>
24
25 #include "FUiCtrl_OptionMenuImpl.h"
26 #include "FUiCtrl_PublicActionEvent.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Runtime;
30 using namespace Tizen::Ui;
31
32 namespace Tizen { namespace Ui { namespace Controls
33 {
34
35 _OptionMenuImpl*
36 _OptionMenuImpl::GetInstance(OptionMenu& optionMenu)
37 {
38         return static_cast<_OptionMenuImpl*>(optionMenu._pControlImpl);
39 }
40
41 const _OptionMenuImpl*
42 _OptionMenuImpl::GetInstance(const OptionMenu& optionMenu)
43 {
44         return static_cast<const _OptionMenuImpl*>(optionMenu._pControlImpl);
45 }
46
47 _OptionMenuImpl::_OptionMenuImpl(OptionMenu* pPublic, _OptionMenu* pCore)
48         : _WindowImpl(pPublic, pCore)
49         , __pPublicActionEvent(null)
50 {
51 }
52
53 _OptionMenuImpl*
54 _OptionMenuImpl::CreateOptionMenuImplN(OptionMenu& control)
55 {
56         ClearLastResult();
57
58         _OptionMenu* pCore = _OptionMenu::CreateOptionMenuN();
59         result r = GetLastResult();
60         SysTryReturn(NID_UI_CTRL, (pCore != null), null, r, "[%s] Propagating.", GetErrorMessage(r));
61
62         _OptionMenuImpl* pImpl = new (std::nothrow) _OptionMenuImpl(&control, pCore);
63         r = CheckConstruction(pCore, pImpl);
64         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), null, r, "[%s] Propagating.", GetErrorMessage(r));
65
66         pImpl->__pPublicActionEvent = _PublicActionEvent::CreateInstanceN(control);
67         r = GetLastResult();
68         SysTryCatch(NID_UI_CTRL, (pImpl->__pPublicActionEvent != null), , r,
69                            "[%s] Propagating.", GetErrorMessage(r));
70
71         r = pCore->AddActionEventListener(*pImpl);
72         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
73
74         return pImpl;
75
76 CATCH:
77         delete pImpl;
78         return null;
79 }
80
81 _OptionMenuImpl::~_OptionMenuImpl(void)
82 {
83         if (__pPublicActionEvent != null)
84         {
85                 delete __pPublicActionEvent;
86                 __pPublicActionEvent = null;
87         }
88 }
89
90 result
91 _OptionMenuImpl::AddActionEventListener(IActionEventListener& listener)
92 {
93         ClearLastResult();
94
95         return __pPublicActionEvent->AddListener(listener);
96 }
97
98 result
99 _OptionMenuImpl::RemoveActionEventListener(IActionEventListener& listener)
100 {
101         ClearLastResult();
102
103         return __pPublicActionEvent->RemoveListener(listener);
104 }
105
106 result
107 _OptionMenuImpl::AddItem(const String& text, int actionId)
108 {
109         ClearLastResult();
110
111         return GetCore().AddItem(text, actionId);
112 }
113
114 result
115 _OptionMenuImpl::InsertItemAt(int mainIndex, const String& text, int actionId)
116 {
117         ClearLastResult();
118         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
119                                 "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex);
120
121         return GetCore().InsertItemAt(mainIndex, text, actionId);
122 }
123
124 result
125 _OptionMenuImpl::SetItemAt(int mainIndex, const String& text, int actionId)
126 {
127         ClearLastResult();
128         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
129                                 "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex);
130
131         return GetCore().SetItemAt(mainIndex, text, actionId);
132 }
133
134 result
135 _OptionMenuImpl::RemoveItemAt(int mainIndex)
136 {
137         ClearLastResult();
138         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
139                                 "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex);
140
141         return GetCore().RemoveItemAt(mainIndex);
142 }
143
144 int
145 _OptionMenuImpl::GetItemCount(void) const
146 {
147         ClearLastResult();
148
149         return GetCore().GetItemCount();
150 }
151
152 int
153 _OptionMenuImpl::GetItemIndexFromActionId(int actionId) const
154 {
155         ClearLastResult();
156
157         return GetCore().GetItemIndexFromActionId(actionId);
158 }
159
160 int
161 _OptionMenuImpl::GetItemActionIdAt(int mainIndex) const
162 {
163         ClearLastResult();
164         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
165                                 "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex);
166
167         return GetCore().GetItemActionIdAt(mainIndex);
168 }
169
170 result
171 _OptionMenuImpl::AddSubItem(int mainIndex, const String& text, int actionId)
172 {
173         ClearLastResult();
174         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
175                                 "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex);
176
177         return GetCore().AddSubItem(mainIndex, text, actionId);
178 }
179
180 result
181 _OptionMenuImpl::InsertSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
182 {
183         ClearLastResult();
184         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
185                                 "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex);
186         SysTryReturn(NID_UI_CTRL, (subIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
187                                 "[E_OUT_OF_RANGE] The specified sub index (%d) is negative.", subIndex);
188
189         return GetCore().InsertSubItemAt(mainIndex, subIndex, text, actionId);
190 }
191
192 result
193 _OptionMenuImpl::SetSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
194 {
195         ClearLastResult();
196         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
197                                 "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex);
198         SysTryReturn(NID_UI_CTRL, (subIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
199                                 "[E_OUT_OF_RANGE] The specified sub index (%d) is negative.", subIndex);
200
201         return GetCore().SetSubItemAt(mainIndex, subIndex, text, actionId);
202 }
203
204 result
205 _OptionMenuImpl::RemoveSubItemAt(int mainIndex, int subIndex)
206 {
207         ClearLastResult();
208         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
209                                 "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex);
210         SysTryReturn(NID_UI_CTRL, (subIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
211                                 "[E_OUT_OF_RANGE] The specified sub index (%d) is negative.", subIndex);
212
213         return GetCore().RemoveSubItemAt(mainIndex, subIndex);
214 }
215
216 int
217 _OptionMenuImpl::GetSubItemCount(int mainIndex) const
218 {
219         ClearLastResult();
220         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
221                                 "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex);
222
223         return GetCore().GetSubItemCount(mainIndex);
224 }
225
226 int
227 _OptionMenuImpl::GetSubItemIndexFromActionId(int actionId) const
228 {
229         ClearLastResult();
230
231         return GetCore().GetSubItemIndexFromActionId(actionId);
232 }
233
234 int
235 _OptionMenuImpl::GetSubItemActionIdAt(int mainIndex, int subIndex) const
236 {
237         ClearLastResult();
238         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
239                                 "[E_OUT_OF_RANGE] The specified main index (%d) is negative.", mainIndex);
240         SysTryReturn(NID_UI_CTRL, (subIndex >= 0), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
241                                 "[E_OUT_OF_RANGE] The specified sub index (%d) is negative.", subIndex);
242
243         return GetCore().GetSubItemActionIdAt(mainIndex, subIndex);
244 }
245
246 result
247 _OptionMenuImpl::OnAttachedToMainTree(void)
248 {
249         SysTryReturn(NID_UI_CTRL, (GetCore().GetItemCount() > 0), E_INVALID_OPERATION, E_INVALID_OPERATION,
250                                 "[E_INVALID_OPERATION] There is no item to show.");
251
252         _WindowImpl::OnAttachedToMainTree();
253         return E_SUCCESS;
254 }
255
256 const char*
257 _OptionMenuImpl::GetPublicClassName(void) const
258 {
259         return "Tizen::Ui::Controls::OptionMenu";
260 }
261
262 const OptionMenu&
263 _OptionMenuImpl::GetPublic(void) const
264 {
265         return static_cast <const OptionMenu&>(_ControlImpl::GetPublic());
266 }
267
268 OptionMenu&
269 _OptionMenuImpl::GetPublic(void)
270 {
271         return static_cast <OptionMenu&>(_ControlImpl::GetPublic());
272 }
273
274 const _OptionMenu&
275 _OptionMenuImpl::GetCore(void) const
276 {
277         return static_cast <const _OptionMenu&>(_ControlImpl::GetCore());
278 }
279
280 _OptionMenu&
281 _OptionMenuImpl::GetCore(void)
282 {
283         return static_cast <_OptionMenu&>(_ControlImpl::GetCore());
284 }
285
286 void
287 _OptionMenuImpl::OnActionPerformed(const _Control& source, int actionId)
288 {
289         if (__pPublicActionEvent != null)
290         {
291                 IEventArg* pEventArg = _PublicActionEvent::CreateActionEventArgN(actionId);
292                 if (pEventArg == null)
293                 {
294                         return;
295                 }
296
297                 __pPublicActionEvent->Fire(*pEventArg);
298         }
299 }
300
301 }}} // Tizen::Ui::Controls