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 FUiCtrl_OptionMenuItem.cpp
20 * @brief This is the implementation file for the _OptionMenuItem class.
24 #include <FBaseSysLog.h>
25 #include <FBaseErrorDefine.h>
27 #include "FUiCtrl_OptionMenuItem.h"
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
32 const int MAX_SUB_ITEM_COUNT = 32;
34 namespace Tizen { namespace Ui { namespace Controls
37 _OptionMenuItem::_OptionMenuItem(void)
43 _OptionMenuItem::~_OptionMenuItem(void)
45 if (__pSubItems != null)
47 __pSubItems->RemoveAll(true);
54 _OptionMenuItem::CreateInstanceN(void)
56 _OptionMenuItem* pItem = new (std::nothrow) _OptionMenuItem;
57 SysTryReturn(NID_UI_CTRL, (pItem != null), null, E_OUT_OF_MEMORY,
58 "[E_OUT_OF_MEMORY] Memory allocation failed.");
64 _OptionMenuItem::SetText(const String& text)
70 _OptionMenuItem::GetText(void) const
76 _OptionMenuItem::SetActionId(int actionId)
78 __actionId = actionId;
82 _OptionMenuItem::GetActionId(void) const
88 _OptionMenuItem::InsertSubItemAt(_OptionMenuItem& subItem, int index)
90 if (__pSubItems == null)
92 __pSubItems = new (std::nothrow) ArrayList;
93 SysTryReturn(NID_UI_CTRL, (__pSubItems != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
94 "[E_OUT_OF_MEMORY] Memory allocation failed.");
96 result r = __pSubItems->Construct(MAX_SUB_ITEM_COUNT);
101 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
106 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < MAX_SUB_ITEM_COUNT), null, E_OUT_OF_RANGE,
107 "[E_OUT_OF_RANGE] The specified index (%d) is out of range.", index);
108 SysTryReturn(NID_UI_CTRL, (index <= __pSubItems->GetCount()), null, E_SYSTEM,
109 "[E_SYSTEM] A system error has occurred. The specified index (%d) is greater than the available items count.", index);
111 return __pSubItems->InsertAt(subItem, index);
115 _OptionMenuItem::RemoveSubItemAt(int index)
117 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < MAX_SUB_ITEM_COUNT), null, E_OUT_OF_RANGE,
118 "[E_OUT_OF_RANGE] The specified index (%d) is out of range.", index);
119 SysTryReturn(NID_UI_CTRL, (__pSubItems != null), E_SYSTEM, E_SYSTEM,
120 "[E_SYSTEM] A system error has occurred. The sub items list is null.");
121 SysTryReturn(NID_UI_CTRL, (index < __pSubItems->GetCount()), E_SYSTEM, E_SYSTEM,
122 "[E_SYSTEM] A system error has occurred. The specified index (%d) is greater than the available items count.", index);
124 return __pSubItems->RemoveAt(index, true);
128 _OptionMenuItem::RemoveAllSubItem(void)
130 SysTryReturn(NID_UI_CTRL, (__pSubItems != null), E_SYSTEM, E_SYSTEM,
131 "[E_SYSTEM] A system error has occurred. The sub items list is null.");
133 __pSubItems->RemoveAll(true);
138 _OptionMenuItem::GetSubItem(int index)
140 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < MAX_SUB_ITEM_COUNT), null, E_OUT_OF_RANGE,
141 "[E_OUT_OF_RANGE] The specified index (%d) is out of range.", index);
142 SysTryReturn(NID_UI_CTRL, (__pSubItems != null), null, E_SYSTEM,
143 "[E_SYSTEM] A system error has occurred. The sub items list is null.", index);
144 SysTryReturn(NID_UI_CTRL, (index < __pSubItems->GetCount()), null, E_SYSTEM,
145 "[E_SYSTEM] A system error has occurred. The specified index (%d) is greater than the available items count.", index);
147 return static_cast<_OptionMenuItem*>(__pSubItems->GetAt(index));
150 const _OptionMenuItem*
151 _OptionMenuItem::GetSubItem(int index) const
153 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < MAX_SUB_ITEM_COUNT), null, E_OUT_OF_RANGE,
154 "[E_OUT_OF_RANGE] The specified index (%d) is out of range.", index);
155 SysTryReturn(NID_UI_CTRL, (__pSubItems != null), null, E_SYSTEM,
156 "[E_SYSTEM] A system error has occurred. The sub items list is null.", index);
157 SysTryReturn(NID_UI_CTRL, (index < __pSubItems->GetCount()), null, E_SYSTEM,
158 "[E_SYSTEM] A system error has occurred. The specified index (%d) is greater than the available items count.", index);
160 return static_cast<const _OptionMenuItem*>(__pSubItems->GetAt(index));
164 _OptionMenuItem::GetSubItemCount(void) const
166 if (__pSubItems == null)
171 return __pSubItems->GetCount();
175 _OptionMenuItem::GetSubItemIndexFromActionId(int actionId) const
177 if (__pSubItems == null)
183 int subItemCount = __pSubItems->GetCount();
184 const _OptionMenuItem* pItem = null;
185 for (index = 0; index < subItemCount; index++)
187 pItem = static_cast<const _OptionMenuItem*>(__pSubItems->GetAt(index));
190 if (pItem->__actionId == actionId)
201 _OptionMenuItem::HasSubItem(void) const
203 return (__pSubItems != null && __pSubItems->GetCount() > 0);
206 }}} // Tizen::Ui::Controls