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_ContextMenuModel.cpp
19 * @brief This is the implementation file for the _ContextMenuModel class.
22 #include <FBaseErrorDefine.h>
23 #include <FBaseSysLog.h>
24 #include "FUiCtrl_ContextMenuModel.h"
26 static const int DEFAULT_ITEM_COUNT = 32;
28 using namespace Tizen::Graphics;
30 namespace Tizen { namespace Ui { namespace Controls
33 _ContextMenuModel::_ContextMenuModel(void)
38 _ContextMenuModel::~_ContextMenuModel(void)
40 __items.RemoveAll(true);
45 _ContextMenuModel::Construct(void)
48 result r = __items.Construct(DEFAULT_ITEM_COUNT);
49 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "Failed to construct ArrayList.");
55 _ContextMenuModel::IsValidItem(_ContextMenuItem *pItem)
60 int actionId = pItem->GetActionId();
61 int itemCount = __items.GetCount();
63 for (int i = 0; i < itemCount; i++)
65 _ContextMenuItem* pTargetItem = GetItem(i);
67 if (pTargetItem == null)
70 if (pTargetItem->GetActionId() == actionId)
80 _ContextMenuModel::GetItemCount(void) const
83 return __items.GetCount();
87 _ContextMenuModel::AddItem(_ContextMenuItem* pItem)
89 if (IsValidItem(pItem) == false)
94 return __items.Add(*pItem);
98 _ContextMenuModel::InsertItem( _ContextMenuItem* pItem, int index)
100 if (IsValidItem(pItem) == false)
105 return __items.InsertAt(*pItem, index);
109 _ContextMenuModel::SetItem(_ContextMenuItem* pItem, int index)
111 if (IsValidItem(pItem) == false)
113 _ContextMenuItem* pTargetItem = GetItem(index);
114 if (pItem == null || pTargetItem == null || pItem->GetActionId() != pTargetItem->GetActionId())
120 return __items.SetAt(*pItem, index, true);
124 _ContextMenuModel::RemoveItem(int index)
126 return __items.RemoveAt(index, true);
130 _ContextMenuModel::RemoveAllItem(void)
132 __items.RemoveAll(true);
138 _ContextMenuModel::ResetAllItem()
140 int count = __items.GetCount();
142 _ContextMenuItem* pItem;
143 for(int index = 0; index < count; index++)
145 pItem = static_cast <_ContextMenuItem*>(__items.GetAt(index));
151 _ContextMenuModel::GetItem(int index) const
153 int count = __items.GetCount();
155 if (index < 0 || index >= count)
160 const _ContextMenuItem* pItem = static_cast <const _ContextMenuItem*>(__items.GetAt(index));
161 return const_cast<_ContextMenuItem*>(pItem);
163 // return static_cast <_ContextMenuItem*>(__items.GetAt(index));
167 }}} // Tizen::Ui::Controls