Revert " modify license, permission and remove ^M char"
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_OptionMenuItem.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 /**
19  * @file                FUiCtrl_OptionMenuItem.cpp
20  * @brief               This is the implementation file for the _OptionMenuItem class.
21  */
22
23 #include <new>
24 #include <FBaseSysLog.h>
25 #include <FBaseErrorDefine.h>
26
27 #include "FUiCtrl_OptionMenuItem.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31
32 const int MAX_SUB_ITEM_COUNT = 32;
33
34 namespace Tizen { namespace Ui { namespace Controls
35 {
36
37 _OptionMenuItem::_OptionMenuItem(void)
38         : __actionId(-1)
39         , __pSubItems(null)
40 {
41 }
42
43 _OptionMenuItem::~_OptionMenuItem(void)
44 {
45         if (__pSubItems != null)
46         {
47                 __pSubItems->RemoveAll(true);
48                 delete __pSubItems;
49                 __pSubItems = null;
50         }
51 }
52
53 _OptionMenuItem*
54 _OptionMenuItem::CreateInstanceN(void)
55 {
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.");
59
60         return pItem;
61 }
62
63 void
64 _OptionMenuItem::SetText(const String& text)
65 {
66         __text = text;
67 }
68
69 const String&
70 _OptionMenuItem::GetText(void) const
71 {
72         return __text;
73 }
74
75 void
76 _OptionMenuItem::SetActionId(int actionId)
77 {
78         __actionId = actionId;
79 }
80
81 int
82 _OptionMenuItem::GetActionId(void) const
83 {
84         return __actionId;
85 }
86
87 result
88 _OptionMenuItem::InsertSubItemAt(_OptionMenuItem& subItem, int index)
89 {
90         if (__pSubItems == null)
91         {
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.");
95
96                 result r = __pSubItems->Construct(MAX_SUB_ITEM_COUNT);
97                 if (r != E_SUCCESS)
98                 {
99                         delete __pSubItems;
100                         __pSubItems = null;
101                         SysLogException(NID_UI_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
102                         return r;
103                 }
104         }
105
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);
110
111         return __pSubItems->InsertAt(subItem, index);
112 }
113
114 result
115 _OptionMenuItem::RemoveSubItemAt(int index)
116 {
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);
123
124         return __pSubItems->RemoveAt(index, true);
125 }
126
127 result
128 _OptionMenuItem::RemoveAllSubItem(void)
129 {
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.");
132
133         __pSubItems->RemoveAll(true);
134         return E_SUCCESS;
135 }
136
137 _OptionMenuItem*
138 _OptionMenuItem::GetSubItem(int index)
139 {
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);
146
147         return static_cast<_OptionMenuItem*>(__pSubItems->GetAt(index));
148 }
149
150 const _OptionMenuItem*
151 _OptionMenuItem::GetSubItem(int index) const
152 {
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);
159
160         return static_cast<const _OptionMenuItem*>(__pSubItems->GetAt(index));
161 }
162
163 int
164 _OptionMenuItem::GetSubItemCount(void) const
165 {
166         if (__pSubItems == null)
167         {
168                 return 0;
169         }
170
171         return __pSubItems->GetCount();
172 }
173
174 int
175 _OptionMenuItem::GetSubItemIndexFromActionId(int actionId) const
176 {
177         if (__pSubItems == null)
178         {
179                 return -1;
180         }
181
182         int index = 0;
183         int subItemCount = __pSubItems->GetCount();
184         const _OptionMenuItem* pItem = null;
185         for (index = 0; index < subItemCount; index++)
186         {
187                 pItem = static_cast<const _OptionMenuItem*>(__pSubItems->GetAt(index));
188                 if (pItem != null)
189                 {
190                         if (pItem->__actionId == actionId)
191                         {
192                                 return index;
193                         }
194                 }
195         }
196
197         return -1;
198 }
199
200 bool
201 _OptionMenuItem::HasSubItem(void) const
202 {
203         return (__pSubItems != null && __pSubItems->GetCount() > 0);
204 }
205
206 }}} // Tizen::Ui::Controls