Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrlListView.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        FUiCtrlListView.cpp
20  * @brief       This is the implementation file for ListView class.
21  *
22  * This file contains the implementation of ListView class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlListView.h>
27 #include "FUiCtrl_ListViewImpl.h"
28 #include "FUi_CoordinateSystemUtils.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Graphics;
32
33 namespace Tizen { namespace Ui { namespace Controls
34 {
35
36 ListView::ListView(void)
37 {
38 }
39
40 ListView::~ListView(void)
41 {
42 }
43
44 result
45 ListView::Construct(const Rectangle& rect, bool itemDivider, bool fastScroll)
46 {
47         result r = E_SUCCESS;
48
49         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
50         SysAssertf(pImpl == null,
51                                   "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
52
53         if (fastScroll == true)
54         {
55                 pImpl = _ListViewImpl::CreateListViewImplN(this, itemDivider, SCROLL_STYLE_FAST_SCROLL);
56         }
57         else
58         {
59                 pImpl = _ListViewImpl::CreateListViewImplN(this, itemDivider, SCROLL_STYLE_FADE_OUT);
60         }
61         SysTryReturn(NID_UI_CTRL, pImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
62
63         _pControlImpl = pImpl;
64         r = Control::SetBounds(_CoordinateSystemUtils::ConvertToFloat(rect));
65         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
66
67         return E_SUCCESS;
68
69 CATCH:
70         Control::Dispose();
71
72         return r;
73 }
74
75 result
76 ListView::Construct(const Rectangle& rect, bool itemDivider, ListScrollStyle scrollStyle)
77 {
78         result r = E_SUCCESS;
79
80         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
81         SysAssertf(pImpl == null,
82                                   "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
83
84         pImpl = _ListViewImpl::CreateListViewImplN(this, itemDivider, scrollStyle);
85         SysTryReturn(NID_UI_CTRL, pImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
86
87         _pControlImpl = pImpl;
88         r = Control::SetBounds(_CoordinateSystemUtils::ConvertToFloat(rect));
89         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
90
91         return E_SUCCESS;
92
93 CATCH:
94         Control::Dispose();
95
96         return r;
97 }
98
99 result
100 ListView::Construct(const FloatRectangle& rect, bool itemDivider, ListScrollStyle scrollStyle)
101 {
102         result r = E_SUCCESS;
103
104         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
105         SysAssertf(pImpl == null,
106                                   "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
107
108         pImpl = _ListViewImpl::CreateListViewImplN(this, itemDivider, scrollStyle);
109         SysTryReturn(NID_UI_CTRL, pImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
110
111         _pControlImpl = pImpl;
112         r = Control::SetBounds(rect);
113         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
114
115         return E_SUCCESS;
116
117 CATCH:
118         Control::Dispose();
119
120         return r;
121 }
122
123 result
124 ListView::SetItemProvider(IListViewItemProvider& provider)
125 {
126         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
127         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
128
129         return pImpl->SetItemProvider(provider);
130 }
131
132 result
133 ListView::SetItemProvider(IListViewItemProviderF& provider)
134 {
135         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
136         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
137
138         return pImpl->SetItemProvider(provider);
139 }
140
141 void
142 ListView::AddListViewItemEventListener(IListViewItemEventListener& listener)
143 {
144         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
145         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
146
147         pImpl->AddListViewItemEventListener(listener);
148         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
149 }
150
151 void
152 ListView::RemoveListViewItemEventListener(IListViewItemEventListener& listener)
153 {
154         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
155         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
156
157         pImpl->RemoveListViewItemEventListener(listener);
158         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
159 }
160
161 void
162 ListView::AddFastScrollListener(IFastScrollListener& listener)
163 {
164         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
165         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
166
167         pImpl->AddFastScrollListener(listener);
168         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
169 }
170
171 void
172 ListView::RemoveFastScrollListener(IFastScrollListener& listener)
173 {
174         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
175         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
176
177         pImpl->RemoveFastScrollListener(listener);
178         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
179 }
180
181 void
182 ListView::AddScrollEventListener(IScrollEventListener& listener)
183 {
184         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
185         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
186
187         pImpl->AddScrollEventListener(listener);
188         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
189 }
190
191 void
192 ListView::AddScrollEventListener(IScrollEventListenerF& listener)
193 {
194         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
195         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
196
197         pImpl->AddScrollEventListener(listener);
198         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
199 }
200
201 void
202 ListView::RemoveScrollEventListener(IScrollEventListener& listener)
203 {
204         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
205         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
206
207         pImpl->RemoveScrollEventListener(listener);
208         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
209 }
210
211 void
212 ListView::RemoveScrollEventListener(IScrollEventListenerF& listener)
213 {
214         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
215         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
216
217         pImpl->RemoveScrollEventListener(listener);
218         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
219 }
220
221 void
222 ListView::AddUiLinkEventListener(IUiLinkEventListener& listener)
223 {
224         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
225         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
226
227         pImpl->AddUiLinkEventListener(listener);
228         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
229 }
230
231 void
232 ListView::RemoveUiLinkEventListener(IUiLinkEventListener& listener)
233 {
234         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
235         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
236
237         pImpl->RemoveUiLinkEventListener(listener);
238         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
239 }
240
241 result
242 ListView::SetSweepEnabled(bool enable)
243 {
244         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
245         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
246
247         return pImpl->SetSweepEnabled(enable);
248 }
249
250 result
251 ListView::SetFastScrollIndex(const String& text, bool useSearchIcon)
252 {
253         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
254         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
255
256         return pImpl->SetFastScrollIndex(text, useSearchIcon);
257 }
258
259 int
260 ListView::GetTopDrawnItemIndex(void) const
261 {
262         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
263         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
264
265         return pImpl->GetTopDrawnItemIndex();
266 }
267
268 int
269 ListView::GetBottomDrawnItemIndex(void) const
270 {
271         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
272         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
273
274         return pImpl->GetBottomDrawnItemIndex();
275 }
276
277 result
278 ListView::ScrollToItem(int index)
279 {
280         return ScrollToItem(index, LIST_SCROLL_ITEM_ALIGNMENT_TOP);
281 }
282
283 result
284 ListView::ScrollToItem(int index, ListScrollItemAlignment itemAlignment)
285 {
286         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
287         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
288
289         return pImpl->ScrollToItem(index, itemAlignment);
290 }
291
292 result
293 ListView::SetItemChecked(int index, bool check)
294 {
295         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
296         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
297
298         return pImpl->SetItemChecked(index, check);
299 }
300
301 bool
302 ListView::IsItemChecked(int index) const
303 {
304         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
305         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
306
307         return pImpl->IsItemChecked(index);
308 }
309
310 result
311 ListView::SetItemEnabled(int index, bool enable)
312 {
313         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
314         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
315
316         return pImpl->SetItemEnabled(index, enable);
317 }
318
319 bool
320 ListView::IsItemEnabled(int index) const
321 {
322         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
323         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
324
325         return pImpl->IsItemEnabled(index);
326 }
327
328 int
329 ListView::GetItemCount(void) const
330 {
331         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
332         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
333
334         return pImpl->GetItemCount();
335 }
336
337 result
338 ListView::ShowItemDescriptionText(int index)
339 {
340         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
341         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
342
343         return pImpl->ShowItemDescriptionText(index);
344 }
345
346 result
347 ListView::HideItemDescriptionText(int index)
348 {
349         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
350         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
351
352         return pImpl->HideItemDescriptionText(index);
353 }
354
355 result
356 ListView::RefreshList(int index, ListRefreshType type)
357 {
358         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
359         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
360
361         return pImpl->RefreshList(index, type);
362 }
363
364 result
365 ListView::RefreshList(int index, int elementId)
366 {
367         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
368         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
369
370         return pImpl->RefreshList(index, elementId);
371 }
372
373 result
374 ListView::UpdateList(void)
375 {
376         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
377         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
378
379         return pImpl->UpdateList();
380 }
381
382 int
383 ListView::GetItemIndexFromPosition(int x, int y) const
384 {
385         return GetItemIndexFromPosition(Point(x, y));
386 }
387
388 int
389 ListView::GetItemIndexFromPosition(float x, float y) const
390 {
391         return GetItemIndexFromPosition(FloatPoint(x, y));
392 }
393
394 int
395 ListView::GetItemIndexFromPosition(const Point& position) const
396 {
397         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
398         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
399
400         return pImpl->GetItemIndexFromPosition(_CoordinateSystemUtils::ConvertToFloat(position));
401 }
402
403 int
404 ListView::GetItemIndexFromPosition(const FloatPoint& position) const
405 {
406         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
407         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
408
409         return pImpl->GetItemIndexFromPosition(position);
410 }
411
412 result
413 ListView::GetItemIndexFromPosition(int x, int y, int& itemIndex, int& elementId) const
414 {
415         return GetItemIndexFromPosition(Point(x, y), itemIndex, elementId);
416 }
417
418 result
419 ListView::GetItemIndexFromPosition(float x, float y, int& itemIndex, int& elementId) const
420 {
421         return GetItemIndexFromPosition(FloatPoint(x, y), itemIndex, elementId);
422 }
423
424 result
425 ListView::GetItemIndexFromPosition(const Point& position, int& itemIndex, int& elementId) const
426 {
427         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
428         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
429
430         return pImpl->GetItemIndexFromPosition(_CoordinateSystemUtils::ConvertToFloat(position), itemIndex, elementId);
431 }
432
433 result
434 ListView::GetItemIndexFromPosition(const FloatPoint& position, int& itemIndex, int& elementId) const
435 {
436         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
437         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
438
439         return pImpl->GetItemIndexFromPosition(position, itemIndex, elementId);
440 }
441
442 result
443 ListView::SetItemDividerColor(const Color& color)
444 {
445         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
446         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
447
448         return pImpl->SetItemDividerColor(color);
449 }
450
451 Color
452 ListView::GetItemDividerColor(void) const
453 {
454         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
455         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
456
457         return pImpl->GetItemDividerColor();
458 }
459
460 result
461 ListView::SetBackgroundColor(const Color& color)
462 {
463         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
464         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
465
466         pImpl->SetListBackgroundColor(color);
467
468         return E_SUCCESS;
469 }
470
471 Color
472 ListView::GetBackgroundColor(void) const
473 {
474         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
475         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
476
477         return pImpl->GetBackgroundColor();
478 }
479
480 result
481 ListView::SetBackgroundBitmap(const Bitmap* pBitmap)
482 {
483         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
484         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
485
486         return pImpl->SetBackgroundBitmap(pBitmap);
487 }
488
489 result
490 ListView::SetBitmapOfEmptyList(const Bitmap* pBitmap)
491 {
492         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
493         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
494
495         return pImpl->SetBitmapOfEmptyList(pBitmap);
496 }
497
498 result
499 ListView::SetTextOfEmptyList(const String& text)
500 {
501         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
502         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
503
504         return pImpl->SetTextOfEmptyList(text);
505 }
506
507 String
508 ListView::GetTextOfEmptyList(void) const
509 {
510         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
511         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
512
513         return pImpl->GetTextOfEmptyList();
514 }
515
516 result
517 ListView::SetTextColorOfEmptyList(const Color& color)
518 {
519         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
520         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
521
522         return pImpl->SetTextColorOfEmptyList(color);
523 }
524
525 Color
526 ListView::GetTextColorOfEmptyList(void) const
527 {
528         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
529         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
530
531         return pImpl->GetTextColorOfEmptyList();
532 }
533
534 result
535 ListView::BeginReorderingMode(void)
536 {
537         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
538         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
539
540         return pImpl->BeginReorderingMode();
541 }
542
543 result
544 ListView::EndReorderingMode(void)
545 {
546         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
547         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
548
549         return pImpl->EndReorderingMode();
550 }
551
552 bool
553 ListView::IsInReorderingMode(void) const
554 {
555         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
556         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
557
558         return pImpl->IsInReorderingMode();
559 }
560
561 void
562 ListView::SetScrollInputMode(ScrollInputMode mode)
563 {
564         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
565         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
566
567         pImpl->SetScrollInputMode(mode);
568 }
569
570 ScrollInputMode
571 ListView::GetScrollInputMode(void) const
572 {
573         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
574         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
575
576         return pImpl->GetScrollInputMode();
577 }
578
579 result
580 ListView::OpenContextItem(int itemIndex)
581 {
582         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
583         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
584
585         return pImpl->OpenContextItem(itemIndex);
586 }
587
588 result
589 ListView::CloseContextItem(int itemIndex)
590 {
591         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
592         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
593
594         return pImpl->CloseContextItem(itemIndex);
595 }
596
597 bool
598 ListView::IsContextItemOpened(int itemIndex) const
599 {
600         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
601         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
602
603         return pImpl->IsContextItemOpened(itemIndex);
604 }
605
606 }}} // Controls