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