Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrlCustomList.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         FUiCtrlCustomList.cpp
20 * @brief        This file contains implementation of CustomList class
21 */
22
23
24 #include <FUiCtrlCustomList.h>
25 #include <FBaseSysLog.h>
26 #include "FUiCtrl_CustomListImpl.h"
27
28 using namespace Tizen::Ui;
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31
32 namespace Tizen { namespace Ui { namespace Controls
33 {
34
35 CustomList::CustomList(void)
36 {
37 }
38
39 CustomList::~CustomList(void)
40 {
41 }
42
43 result
44 CustomList::Construct(const Rectangle& rect, CustomListStyle style, bool itemDivider)
45 {
46         result r = E_SUCCESS;
47
48         _CustomListImpl* pCustomListImpl = _CustomListImpl::GetInstance(*this);
49         SysAssertf((pCustomListImpl == null), "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
50
51         pCustomListImpl = _CustomListImpl::CreateCustomListImplN(this, rect, itemDivider);
52         r = GetLastResult();
53         SysTryReturn(NID_UI_CTRL, pCustomListImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
54
55         _pControlImpl = pCustomListImpl;
56
57         r = pCustomListImpl->InitializeBounds(rect);
58         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
59
60         r = pCustomListImpl->SetListStyle(style);
61         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
62
63         r = pCustomListImpl->Initialize();
64         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
65
66         r = pCustomListImpl->LoadDefaultBitmap();
67         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
68
69         return E_SUCCESS;
70
71 CATCH:
72         Dispose();
73         return E_SYSTEM;
74 }
75
76 void
77 CustomList::AddCustomItemEventListener(ICustomItemEventListener& listener)
78 {
79         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
80         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
81
82         result r = pImpl->AddCustomItemEventListener(listener);
83         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
84 }
85
86 void
87 CustomList::RemoveCustomItemEventListener(ICustomItemEventListener& listener)
88 {
89         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
90         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
91
92         result r = pImpl->RemoveCustomItemEventListener(listener);
93         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
94 }
95
96 result
97 CustomList::AddItem(const CustomListItem& item, int itemId)
98 {
99         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
100         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
101
102         result r = pImpl->AddItem(item, itemId);
103         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to add an item.", GetErrorMessage(r));
104
105         return r;
106 }
107
108 result
109 CustomList::InsertItemAt(int index, const CustomListItem& item, int itemId)
110 {
111         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
112         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
113
114         result r = pImpl->InsertItemAt(index, item, itemId);
115         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to insert an item.", GetErrorMessage(r));
116
117         return r;
118 }
119
120 result
121 CustomList::SetItemAt(int index, const CustomListItem& item, int itemId)
122 {
123         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
124         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
125
126         result r = pImpl->SetItemAt(index, item, itemId);
127         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to set an item.", GetErrorMessage(r));
128
129         return r;
130 }
131
132 result
133 CustomList::RemoveItemAt(int index)
134 {
135         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
136         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
137
138         result r = pImpl->RemoveItemAt(index);
139         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to remove an item.", GetErrorMessage(r));
140
141         return r;
142 }
143
144 result
145 CustomList::RemoveAllItems(void)
146 {
147         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
148         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
149
150         result r = pImpl->RemoveAllItems();
151         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to remove all items.", GetErrorMessage(r));
152
153         return r;
154 }
155
156 const CustomListItem*
157 CustomList::GetItemAt(int index) const
158 {
159         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
160         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
161
162         const CustomListItem* pItem = pImpl->GetCustomListItemAt(-1, index);
163         return pItem;
164 }
165
166 int
167 CustomList::GetItemCount(void) const
168 {
169         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
170         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
171
172         return pImpl->GetItemCount();
173 }
174
175 result
176 CustomList::SetItemEnabled(int index, bool enable)
177 {
178         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
179         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
180
181         result r = pImpl->SetItemEnabled(index, enable);
182         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to SetItemEnabled.", GetErrorMessage(r));
183
184         return r;
185 }
186
187 bool
188 CustomList::IsItemEnabled(int index) const
189 {
190         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
191         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
192
193         return pImpl->IsItemEnabled(index);
194 }
195
196 result
197 CustomList::SetItemChecked(int index, bool check)
198 {
199         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
200         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
201
202         result r = pImpl->SetItemChecked(index, check);
203         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to SetItemChecked.", GetErrorMessage(r));
204
205         return r;
206 }
207
208 bool
209 CustomList::IsItemChecked(int index) const
210 {
211         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
212         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
213
214         return pImpl->IsItemChecked(index);
215 }
216
217 result
218 CustomList::SetAllItemsChecked(bool check)
219 {
220         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
221         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
222
223         result r = pImpl->SetAllItemsChecked(check);
224         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to SetAllItemsChecked.", GetErrorMessage(r));
225
226         return r;
227 }
228
229 result
230 CustomList::RemoveAllCheckedItems(void)
231 {
232         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
233         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
234
235         result r = pImpl->RemoveAllCheckedItems();
236         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to SetAllItemsChecked.", GetErrorMessage(r));
237
238         return r;
239 }
240
241 int
242 CustomList::GetFirstCheckedItemIndex(void) const
243 {
244         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
245         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
246
247         return pImpl->GetFirstCheckedItemIndex();
248 }
249
250 int
251 CustomList::GetLastCheckedItemIndex(void) const
252 {
253         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
254         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
255
256         return pImpl->GetLastCheckedItemIndex();
257 }
258
259 int
260 CustomList::GetNextCheckedItemIndexAfter(int index) const
261 {
262         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
263         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
264
265         return pImpl->GetNextCheckedItemIndexAfter(index);
266 }
267
268 int
269 CustomList::GetItemIndexFromPosition(int x, int y) const
270 {
271         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
272         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
273
274         int groupIndex = -1;
275         int itemIndex = -1;
276
277         result r = pImpl->GetItemIndexFromPosition(Point(x, y), groupIndex, itemIndex);
278         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), -1, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
279
280         return itemIndex;
281 }
282
283 int
284 CustomList::GetItemIndexFromPosition(const Point& position) const
285 {
286         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
287         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
288
289         int groupIndex = -1;
290         int itemIndex = -1;
291
292         result r = pImpl->GetItemIndexFromPosition(position, groupIndex, itemIndex);
293         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), -1, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
294
295         return itemIndex;
296 }
297
298 int
299 CustomList::GetTopDrawnItemIndex(void) const
300 {
301         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
302         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
303
304         int groupIndex = -1;
305         int itemIndex = -1;
306
307         result r = pImpl->GetTopDrawnItemIndex(groupIndex, itemIndex);
308         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), -1, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
309
310         return itemIndex;
311 }
312
313 int
314 CustomList::GetBottomDrawnItemIndex(void) const
315 {
316         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
317         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
318
319         int groupIndex = -1;
320         int itemIndex = -1;
321
322         result r = pImpl->GetBottomDrawnItemIndex(groupIndex, itemIndex);
323         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), -1, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
324
325         return itemIndex;
326 }
327
328 void
329 CustomList::SetBackgroundColor(const Color& color)
330 {
331         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
332         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
333
334         pImpl->SetBackgroundColor(color);
335 }
336
337 void
338 CustomList::SetTextOfEmptyList(const String& text)
339 {
340         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
341         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
342
343         pImpl->SetTextOfEmptyList(text);
344 }
345
346 void
347 CustomList::SetTextColorOfEmptyList(const Color& color)
348 {
349         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
350         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
351
352         pImpl->SetTextColorOfEmptyList(color);
353 }
354
355 Color
356 CustomList::GetTextColorOfEmptyList(void) const
357 {
358         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
359         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
360
361         return pImpl->GetTextColorOfEmptyList();
362 }
363
364 int
365 CustomList::GetItemIndexFromItemId(int itemId) const
366 {
367         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
368         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
369
370         return pImpl->GetItemIndexFromItemId(itemId);
371 }
372
373 int
374 CustomList::GetItemIdAt(int index) const
375 {
376         const _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
377         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
378
379         return pImpl->GetItemIdAt(index);
380 }
381
382 void
383 CustomList::ScrollToBottom(void)
384 {
385         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
386         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
387
388         pImpl->ScrollToBottom();
389 }
390
391 void
392 CustomList::ScrollToTop(void)
393 {
394         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
395         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
396
397         pImpl->ScrollToTop();
398 }
399
400 result
401 CustomList::ScrollToTop(int index)
402 {
403         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
404         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
405
406         result r = pImpl->ScrollToTop(index);
407         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to ScrollToTop.", GetErrorMessage(r));
408
409         return r;
410 }
411
412 result
413 CustomList::RefreshItem(int index)
414 {
415         _CustomListImpl* pImpl = _CustomListImpl::GetInstance(*this);
416         SysAssertf((pImpl != null), "Not yet constructed. Construct() should be called before use.");
417
418         result r = pImpl->RefreshItem(index);
419         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Failed to Refresh an item.", GetErrorMessage(r));
420
421         return r;
422 }
423
424 }}} // Tizen::Controls::Ui