2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
18 * @file FUiCtrl_OptionMenuImpl.cpp
19 * @brief This is the implementation file for the _OptionMenuImpl class.
22 #include <FBaseSysLog.h>
23 #include <FBaseResult.h>
25 #include "FUiCtrl_OptionMenuImpl.h"
26 #include "FUiCtrl_PublicActionEvent.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Runtime;
30 using namespace Tizen::Ui;
32 namespace Tizen { namespace Ui { namespace Controls
36 _OptionMenuImpl::GetInstance(OptionMenu& optionMenu)
38 return static_cast<_OptionMenuImpl*>(optionMenu._pControlImpl);
41 const _OptionMenuImpl*
42 _OptionMenuImpl::GetInstance(const OptionMenu& optionMenu)
44 return static_cast<const _OptionMenuImpl*>(optionMenu._pControlImpl);
47 _OptionMenuImpl::_OptionMenuImpl(OptionMenu* pPublic, _OptionMenu* pCore)
48 : _WindowImpl(pPublic, pCore)
49 , __pPublicActionEvent(null)
54 _OptionMenuImpl::CreateOptionMenuImplN(OptionMenu& control)
58 _OptionMenu* pCore = _OptionMenu::CreateOptionMenuN();
59 result r = GetLastResult();
60 SysTryReturn(NID_UI_CTRL, (pCore != null), null, r, "[%s] Propagating.", GetErrorMessage(r));
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));
66 pImpl->__pPublicActionEvent = _PublicActionEvent::CreateInstanceN(control);
68 SysTryCatch(NID_UI_CTRL, (pImpl->__pPublicActionEvent != null), , r,
69 "[%s] Propagating.", GetErrorMessage(r));
71 r = pCore->AddActionEventListener(*pImpl);
72 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
81 _OptionMenuImpl::~_OptionMenuImpl(void)
83 if (__pPublicActionEvent != null)
85 delete __pPublicActionEvent;
86 __pPublicActionEvent = null;
91 _OptionMenuImpl::AddActionEventListener(IActionEventListener& listener)
95 return __pPublicActionEvent->AddListener(listener);
99 _OptionMenuImpl::RemoveActionEventListener(IActionEventListener& listener)
103 return __pPublicActionEvent->RemoveListener(listener);
107 _OptionMenuImpl::AddItem(const String& text, int actionId)
111 return GetCore().AddItem(text, actionId);
115 _OptionMenuImpl::InsertItemAt(int mainIndex, const String& text, int actionId)
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);
121 return GetCore().InsertItemAt(mainIndex, text, actionId);
125 _OptionMenuImpl::SetItemAt(int mainIndex, const String& text, int actionId)
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);
131 return GetCore().SetItemAt(mainIndex, text, actionId);
135 _OptionMenuImpl::RemoveItemAt(int mainIndex)
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);
141 return GetCore().RemoveItemAt(mainIndex);
145 _OptionMenuImpl::GetItemCount(void) const
149 return GetCore().GetItemCount();
153 _OptionMenuImpl::GetItemIndexFromActionId(int actionId) const
157 return GetCore().GetItemIndexFromActionId(actionId);
161 _OptionMenuImpl::GetItemActionIdAt(int mainIndex) const
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);
167 return GetCore().GetItemActionIdAt(mainIndex);
171 _OptionMenuImpl::AddSubItem(int mainIndex, const String& text, int actionId)
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);
177 return GetCore().AddSubItem(mainIndex, text, actionId);
181 _OptionMenuImpl::InsertSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
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);
189 return GetCore().InsertSubItemAt(mainIndex, subIndex, text, actionId);
193 _OptionMenuImpl::SetSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
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);
201 return GetCore().SetSubItemAt(mainIndex, subIndex, text, actionId);
205 _OptionMenuImpl::RemoveSubItemAt(int mainIndex, int subIndex)
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);
213 return GetCore().RemoveSubItemAt(mainIndex, subIndex);
217 _OptionMenuImpl::GetSubItemCount(int mainIndex) const
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);
223 return GetCore().GetSubItemCount(mainIndex);
227 _OptionMenuImpl::GetSubItemIndexFromActionId(int actionId) const
231 return GetCore().GetSubItemIndexFromActionId(actionId);
235 _OptionMenuImpl::GetSubItemActionIdAt(int mainIndex, int subIndex) const
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);
243 return GetCore().GetSubItemActionIdAt(mainIndex, subIndex);
247 _OptionMenuImpl::OnAttachedToMainTree(void)
249 SysTryReturn(NID_UI_CTRL, (GetCore().GetItemCount() > 0), E_INVALID_OPERATION, E_INVALID_OPERATION,
250 "[E_INVALID_OPERATION] There is no item to show.");
252 _WindowImpl::OnAttachedToMainTree();
257 _OptionMenuImpl::GetPublicClassName(void) const
259 return "Tizen::Ui::Controls::OptionMenu";
263 _OptionMenuImpl::GetPublic(void) const
265 return static_cast <const OptionMenu&>(_ControlImpl::GetPublic());
269 _OptionMenuImpl::GetPublic(void)
271 return static_cast <OptionMenu&>(_ControlImpl::GetPublic());
275 _OptionMenuImpl::GetCore(void) const
277 return static_cast <const _OptionMenu&>(_ControlImpl::GetCore());
281 _OptionMenuImpl::GetCore(void)
283 return static_cast <_OptionMenu&>(_ControlImpl::GetCore());
287 _OptionMenuImpl::OnActionPerformed(const _Control& source, int actionId)
289 if (__pPublicActionEvent != null)
291 IEventArg* pEventArg = _PublicActionEvent::CreateActionEventArgN(actionId);
292 if (pEventArg == null)
297 __pPublicActionEvent->Fire(*pEventArg);
301 }}} // Tizen::Ui::Controls