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_OptionMenuItem.cpp
19 * @brief This is the implementation file for the _OptionMenuItem class.
23 #include <FBaseSysLog.h>
24 #include <FBaseErrorDefine.h>
26 #include "FUiCtrl_OptionMenuItem.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
31 const int MAX_SUB_ITEM_COUNT = 32;
33 namespace Tizen { namespace Ui { namespace Controls
36 _OptionMenuItem::_OptionMenuItem(void)
42 _OptionMenuItem::~_OptionMenuItem(void)
44 if (__pSubItems != null)
46 __pSubItems->RemoveAll(true);
53 _OptionMenuItem::CreateInstanceN(void)
55 _OptionMenuItem* pItem = new (std::nothrow) _OptionMenuItem;
56 SysTryReturn(NID_UI_CTRL, (pItem != null), null, E_OUT_OF_MEMORY,
57 "[E_OUT_OF_MEMORY] Memory allocation failed.");
63 _OptionMenuItem::SetText(const String& text)
69 _OptionMenuItem::GetText(void) const
75 _OptionMenuItem::SetActionId(int actionId)
77 __actionId = actionId;
81 _OptionMenuItem::GetActionId(void) const
87 _OptionMenuItem::InsertSubItemAt(_OptionMenuItem& subItem, int index)
89 if (__pSubItems == null)
91 __pSubItems = new (std::nothrow) ArrayList;
92 SysTryReturn(NID_UI_CTRL, (__pSubItems != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
93 "[E_OUT_OF_MEMORY] Memory allocation failed.");
95 result r = __pSubItems->Construct(MAX_SUB_ITEM_COUNT);
100 SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
105 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < MAX_SUB_ITEM_COUNT), null, E_OUT_OF_RANGE,
106 "[E_OUT_OF_RANGE] The specified index (%d) is out of range.", index);
107 SysTryReturn(NID_UI_CTRL, (index <= __pSubItems->GetCount()), null, E_SYSTEM,
108 "[E_SYSTEM] A system error has occurred. The specified index (%d) is greater than the available items count.", index);
110 return __pSubItems->InsertAt(subItem, index);
114 _OptionMenuItem::RemoveSubItemAt(int index)
116 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < MAX_SUB_ITEM_COUNT), null, E_OUT_OF_RANGE,
117 "[E_OUT_OF_RANGE] The specified index (%d) is out of range.", index);
118 SysTryReturn(NID_UI_CTRL, (__pSubItems != null), E_SYSTEM, E_SYSTEM,
119 "[E_SYSTEM] A system error has occurred. The sub items list is null.");
120 SysTryReturn(NID_UI_CTRL, (index < __pSubItems->GetCount()), E_SYSTEM, E_SYSTEM,
121 "[E_SYSTEM] A system error has occurred. The specified index (%d) is greater than the available items count.", index);
123 return __pSubItems->RemoveAt(index, true);
127 _OptionMenuItem::RemoveAllSubItem(void)
129 SysTryReturn(NID_UI_CTRL, (__pSubItems != null), E_SYSTEM, E_SYSTEM,
130 "[E_SYSTEM] A system error has occurred. The sub items list is null.");
132 __pSubItems->RemoveAll(true);
137 _OptionMenuItem::GetSubItem(int index)
139 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < MAX_SUB_ITEM_COUNT), null, E_OUT_OF_RANGE,
140 "[E_OUT_OF_RANGE] The specified index (%d) is out of range.", index);
141 SysTryReturn(NID_UI_CTRL, (__pSubItems != null), null, E_SYSTEM,
142 "[E_SYSTEM] A system error has occurred. The sub items list is null.", index);
143 SysTryReturn(NID_UI_CTRL, (index < __pSubItems->GetCount()), null, E_SYSTEM,
144 "[E_SYSTEM] A system error has occurred. The specified index (%d) is greater than the available items count.", index);
146 return static_cast<_OptionMenuItem*>(__pSubItems->GetAt(index));
149 const _OptionMenuItem*
150 _OptionMenuItem::GetSubItem(int index) const
152 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < MAX_SUB_ITEM_COUNT), null, E_OUT_OF_RANGE,
153 "[E_OUT_OF_RANGE] The specified index (%d) is out of range.", index);
154 SysTryReturn(NID_UI_CTRL, (__pSubItems != null), null, E_SYSTEM,
155 "[E_SYSTEM] A system error has occurred. The sub items list is null.", index);
156 SysTryReturn(NID_UI_CTRL, (index < __pSubItems->GetCount()), null, E_SYSTEM,
157 "[E_SYSTEM] A system error has occurred. The specified index (%d) is greater than the available items count.", index);
159 return static_cast<const _OptionMenuItem*>(__pSubItems->GetAt(index));
163 _OptionMenuItem::GetSubItemCount(void) const
165 if (__pSubItems == null)
170 return __pSubItems->GetCount();
174 _OptionMenuItem::GetSubItemIndexFromActionId(int actionId) const
176 if (__pSubItems == null)
182 int subItemCount = __pSubItems->GetCount();
183 const _OptionMenuItem* pItem = null;
184 for (index = 0; index < subItemCount; index++)
186 pItem = static_cast<const _OptionMenuItem*>(__pSubItems->GetAt(index));
189 if (pItem->__actionId == actionId)
200 _OptionMenuItem::HasSubItem(void) const
202 return (__pSubItems != null && __pSubItems->GetCount() > 0);
205 }}} // Tizen::Ui::Controls