Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_IconListItemProviderAdaptor.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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_IconListItemProviderAdaptor.cpp
20  * @brief               This is the implementation file for the _IconListItemProviderAdaptor class.
21  */
22
23 //Includes
24 #include <FBaseSysLog.h>
25 #include <FBaseObject.h>
26 #include <FUiCtrlIconListViewItem.h>
27
28 #include "FUiAnim_VisualElement.h"
29 #include "FUiCtrl_IconListItem.h"
30 #include "FUiCtrl_IconListItemProviderAdaptor.h"
31 #include "FUiCtrl_IconListViewItemImpl.h"
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Animations;
37
38 namespace Tizen { namespace Ui { namespace Controls
39 {
40
41 _IconListItemProviderAdaptor::_IconListItemProviderAdaptor(void)
42         : __pItemProvider(null)
43         , __pBlankItem(null)
44         , __pRoot(null)
45 {
46         // Do nothing
47 }
48
49 _IconListItemProviderAdaptor::~_IconListItemProviderAdaptor(void)
50 {
51         __pItemProvider = null;
52
53         delete __pBlankItem;
54         __pBlankItem = null;
55
56         __pRoot = null;
57 }
58
59 // Operation
60 _IListItemCommon*
61 _IconListItemProviderAdaptor::GetBlankItem(void) const
62 {
63         if (__pBlankItem == null)
64         {
65                 // Create Default Blank Item.
66                 _IconListItem* pBlankItem = _IconListItem::CreateIconListItemN(null);
67                 SysTryReturn(NID_UI_CTRL, (pBlankItem != null), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
68
69                 const_cast<_IconListItemProviderAdaptor*>(this)->__pBlankItem = pBlankItem;
70         }
71
72         return __pBlankItem;
73 }
74
75 // Accessor
76 void
77 _IconListItemProviderAdaptor::SetItemProvider(void* pProvider)
78 {
79         IIconListViewItemProvider* pItemProvider = static_cast<IIconListViewItemProvider*>(pProvider);
80         if (pItemProvider != null)
81         {
82                 __pItemProvider = pItemProvider;
83         }
84 }
85
86 IIconListViewItemProvider*
87 _IconListItemProviderAdaptor::GetItemProvider(void) const
88 {
89         return __pItemProvider;
90 }
91
92 _IListItemCommon*
93 _IconListItemProviderAdaptor::LoadItem(int groupIndex, int itemIndex)
94 {
95         // Argument Check
96         SysTryReturn(NID_UI_CTRL, (groupIndex == DEFAULT_GROUP_INDEX), null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Index of group must be 0.");
97         SysTryReturn(NID_UI_CTRL, (itemIndex >= GROUP_TITLE_INDEX), null, E_OUT_OF_RANGE,
98                                 "[E_OUT_OF_RANGE] Index must be a non-negative integer.");
99
100         SysAssertf(__pItemProvider != null, "Not yet initialized. SetItemProvider() should be called before use.");
101
102         ClearLastResult();
103         // Return Group Item
104         if (itemIndex == GROUP_TITLE_INDEX)
105         {
106                 return GetBlankItem();
107         }
108
109         // Valid Check
110         _IconListItem* pIconListItem = null;
111         IconListViewItem* pItem = __pItemProvider->CreateItem(itemIndex);
112         SysTryCatch(NID_UI_CTRL, (pItem != null), , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Can't get new item.");
113         SysTryCatch(NID_UI_CTRL, (pItem->__pImpl != null), , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Can't get new item.");
114
115         pIconListItem = pItem->__pImpl->__pIconListItem;
116         SysTryCatch(NID_UI_CTRL, (pIconListItem != null), , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Can't get new item.");
117
118         pIconListItem->ClearVisualElement();
119         pIconListItem->AddRef();
120
121         // Attach _VisualElement
122         if (__pRoot != null)
123         {
124                 _VisualElement* pBase = pIconListItem->GetVisualElement();
125                 if (pBase != null)
126                 {
127                         __pRoot->AttachChild(*pBase);
128                         pBase->SetShowState(false);
129                         pBase->SetClipToParent(true);
130                 }
131         }
132
133         return pIconListItem;
134
135 CATCH:
136         if (pItem != null)
137         {
138                 if (!__pItemProvider->DeleteItem(itemIndex, pItem))
139                 {
140                         delete pItem;
141                 }
142         }
143
144         return GetBlankItem();
145 }
146
147 result
148 _IconListItemProviderAdaptor::UnloadItem(_IListItemCommon* pListItem, int groupIndex, int itemIndex)
149 {
150         // Argument Check
151         SysTryReturn(NID_UI_CTRL, (pListItem != null), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. Item must not be null.");
152         SysTryReturn(NID_UI_CTRL, (groupIndex == DEFAULT_GROUP_INDEX), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Index of group must be 0.");
153         SysTryReturn(NID_UI_CTRL, (itemIndex >= GROUP_TITLE_INDEX), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
154                                 "[E_OUT_OF_RANGE] Index must be a non-negative integer.");
155
156         // Group Item
157         if (itemIndex == GROUP_TITLE_INDEX)
158         {
159                 return E_SUCCESS;
160         }
161
162         // Is the Blank Item?
163         if (pListItem == GetBlankItem())
164         {
165                 return E_SUCCESS;
166         }
167
168         _IconListItem* pIconListItem = dynamic_cast<_IconListItem*>(pListItem);
169         if (pIconListItem != null)
170         {
171                 _VisualElement* pBase = pIconListItem->GetVisualElement();
172                 if (pBase != null)
173                 {
174                         pBase->SetShowState(false);
175                         pIconListItem->ClearVisualElement();
176                         __pRoot->DetachChild(*pBase);
177                 }
178         }
179
180         IconListViewItem* pItem = static_cast<IconListViewItem*>(pIconListItem->GetAppInfo());
181         pIconListItem->Release();
182         if (pItem == null)
183         {
184                 return E_SUCCESS;
185         }
186
187         SysAssertf(__pItemProvider != null, "Not yet initialized. SetItemProvider() should be called before use.");
188
189         if (!__pItemProvider->DeleteItem(itemIndex, pItem))
190         {
191                 delete pItem;
192         }
193
194         return E_SUCCESS;
195 }
196
197 result
198 _IconListItemProviderAdaptor::DeleteItem(_IListItemCommon* pListItem, int groupIndex, int itemIndex)
199 {
200         // Argument Check
201         SysTryReturn(NID_UI_CTRL, (pListItem != null), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used. Item must not be null.");
202         SysTryReturn(NID_UI_CTRL, (groupIndex == DEFAULT_GROUP_INDEX), E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Index of group must be 0.");
203         SysTryReturn(NID_UI_CTRL, (itemIndex >= GROUP_TITLE_INDEX), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
204                                 "[E_OUT_OF_RANGE] Index must be a non-negative integer.");
205
206         // Group Item
207         if (itemIndex == GROUP_TITLE_INDEX)
208         {
209                 return E_SUCCESS;
210         }
211
212         // Is the Blank Item?
213         if (pListItem == GetBlankItem())
214         {
215                 return E_SUCCESS;
216         }
217
218         _IconListItem* pIconListItem = dynamic_cast <_IconListItem*>(pListItem);
219         if (pIconListItem != null)
220         {
221                 _VisualElement* pBase = pIconListItem->GetVisualElement();
222                 if (pBase != null)
223                 {
224                         pBase->SetShowState(false);
225                         pIconListItem->ClearVisualElement();
226                         __pRoot->DetachChild(*pBase);
227                 }
228         }
229
230         IconListViewItem* pItem = static_cast <IconListViewItem*>(pIconListItem->GetAppInfo());
231         pIconListItem->Release();
232         if (pItem != null)
233         {
234                 delete pItem;
235         }
236
237         return E_SUCCESS;
238 }
239
240 int
241 _IconListItemProviderAdaptor::GetItemCount(int groupIndex) const
242 {
243         // Argument Check
244         SysTryReturn(NID_UI_CTRL, (groupIndex == DEFAULT_GROUP_INDEX), -1, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Index of group must be 0.");
245
246         SysAssertf(__pItemProvider != null, "Not yet initialized. SetItemProvider() should be called before use.");
247
248         ClearLastResult();
249
250         int itemCount = __pItemProvider->GetItemCount();
251         return (itemCount < 0) ? 0 : itemCount;
252 }
253
254 int
255 _IconListItemProviderAdaptor::GetGroupCount(void) const
256 {
257         return DEFAULT_GROUP_COUNT;
258 }
259
260 void
261 _IconListItemProviderAdaptor::SetVisualElement(Tizen::Ui::Animations::_VisualElement* pRoot)
262 {
263         SysTryReturnVoidResult(NID_UI_CTRL, (pRoot != null), E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument is used.");
264
265         ClearLastResult();
266
267         __pRoot = pRoot;
268 }
269
270 }}} // Tizen::Ui::Controls