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.
19 * @file FUiCtrlOptionMenu.cpp
20 * @brief This is the implementation file for the OptionMenu class.
23 #include <FUiCtrlOptionMenu.h>
24 #include <FBaseSysLog.h>
26 #include "FUiCtrl_OptionMenuImpl.h"
28 using namespace Tizen::Base;
30 namespace Tizen { namespace Ui { namespace Controls
33 OptionMenu::OptionMenu(void)
37 OptionMenu::~OptionMenu(void)
42 OptionMenu::Construct(void)
45 SysAssertf((_OptionMenuImpl::GetInstance(*this) == null),
46 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
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));
53 // Set _OptionMenuImpl
54 _pControlImpl = pOptionMenuImpl;
60 OptionMenu::AddActionEventListener(IActionEventListener& listener)
64 _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
65 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
67 result r = pOptionMenuImpl->AddActionEventListener(listener);
68 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
72 OptionMenu::RemoveActionEventListener(IActionEventListener& listener)
76 _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
77 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
79 result r = pOptionMenuImpl->RemoveActionEventListener(listener);
80 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
84 OptionMenu::AddItem(const String& text, int actionId)
88 _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
89 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
91 result r = pOptionMenuImpl->AddItem(text, actionId);
92 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
98 OptionMenu::InsertItemAt(int mainIndex, const String& text, int actionId)
102 _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
103 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
105 result r = pOptionMenuImpl->InsertItemAt(mainIndex, text, actionId);
106 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
112 OptionMenu::SetItemAt(int mainIndex, const String& text, int actionId)
116 _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
117 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
119 result r = pOptionMenuImpl->SetItemAt(mainIndex, text, actionId);
120 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
126 OptionMenu::RemoveItemAt(int mainIndex)
130 _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
131 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
133 result r = pOptionMenuImpl->RemoveItemAt(mainIndex);
134 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
140 OptionMenu::GetItemCount(void) const
144 const _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
145 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
147 int count = pOptionMenuImpl->GetItemCount();
148 result r = GetLastResult();
149 SysTryReturn(NID_UI_CTRL, (count >= 0), -1, r, "[%s] Propagating.", GetErrorMessage(r));
155 OptionMenu::GetItemIndexFromActionId(int actionId) const
159 const _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
160 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
162 int index = pOptionMenuImpl->GetItemIndexFromActionId(actionId);
163 result r = GetLastResult();
164 SysTryReturn(NID_UI_CTRL, (index >= 0), -1, r, "[%s] Propagating.", GetErrorMessage(r));
170 OptionMenu::GetItemActionIdAt(int mainIndex) const
174 const _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
175 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
177 int actionId = pOptionMenuImpl->GetItemActionIdAt(mainIndex);
178 result r = GetLastResult();
179 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), -1, r, "[%s] Propagating.", GetErrorMessage(r));
185 OptionMenu::AddSubItem(int mainIndex, const String& text, int actionId)
189 _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
190 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
192 result r = pOptionMenuImpl->AddSubItem(mainIndex, text, actionId);
193 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
199 OptionMenu::InsertSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
203 _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
204 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
206 result r = pOptionMenuImpl->InsertSubItemAt(mainIndex, subIndex, text, actionId);
207 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
213 OptionMenu::SetSubItemAt(int mainIndex, int subIndex, const String& text, int actionId)
217 _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
218 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
220 result r = pOptionMenuImpl->SetSubItemAt(mainIndex, subIndex, text, actionId);
221 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
227 OptionMenu::RemoveSubItemAt(int mainIndex, int subIndex)
231 _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
232 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
234 result r = pOptionMenuImpl->RemoveSubItemAt(mainIndex, subIndex);
235 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
241 OptionMenu::GetSubItemCount(int mainIndex) const
245 const _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
246 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
248 int count = pOptionMenuImpl->GetSubItemCount(mainIndex);
249 result r = GetLastResult();
250 SysTryReturn(NID_UI_CTRL, (count >= 0), -1, r, "[%s] Propagating.", GetErrorMessage(r));
256 OptionMenu::GetSubItemIndexFromActionId(int actionId) const
260 const _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
261 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
263 int index = pOptionMenuImpl->GetSubItemIndexFromActionId(actionId);
264 result r = GetLastResult();
265 SysTryReturn(NID_UI_CTRL, (index >= 0), -1, r, "[%s] Propagating.", GetErrorMessage(r));
271 OptionMenu::GetSubItemActionIdAt(int mainIndex, int subIndex) const
275 const _OptionMenuImpl* pOptionMenuImpl = _OptionMenuImpl::GetInstance(*this);
276 SysAssertf((pOptionMenuImpl != null), "Not yet constructed. Construct() should be called before use.");
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));
285 }}} //Tizen::Ui::Controls