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.
19 * @file FUiCtrlGroupedList.cpp
20 * @brief This file contains implementation of GroupedList class
24 #include <FUiCtrlGroupedList.h>
25 #include <FBaseSysLog.h>
26 #include "FUiCtrl_GroupedListImpl.h"
28 using namespace Tizen::Base;
29 using namespace Tizen::Graphics;
31 namespace Tizen { namespace Ui { namespace Controls {
33 GroupedList::GroupedList(void)
38 GroupedList::~GroupedList(void)
44 GroupedList::Construct(const Rectangle& rect, CustomListStyle style, bool itemDivider, bool fastScroll)
47 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
49 SysAssertf(pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
51 pImpl = _GroupedListImpl::CreateGroupedListImplN(this, rect, itemDivider, fastScroll);
53 SysTryReturn(NID_UI_CTRL, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
55 _pControlImpl = pImpl;
57 r = pImpl->SetListStyle(style);
58 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "Internal Error");
60 r = pImpl->Initialize();
61 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "Internal Error");
63 r = pImpl->LoadDefaultBitmap();
64 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "Internal Error");
76 GroupedList::AddGroup(const String& text, const Bitmap* pBackgroundBitmap, int groupId)
78 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
79 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
81 result r = pImpl->AddGroup(text, pBackgroundBitmap, groupId);
82 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
88 GroupedList::InsertGroupAt(int groupIndex, const String& text, const Bitmap* pBackgroundBitmap, int groupId)
90 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
91 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
93 result r = pImpl->InsertGroupAt(groupIndex, text, pBackgroundBitmap, groupId);
94 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
100 GroupedList::SetGroupAt(int groupIndex, const String& text, const Bitmap* pBackgroundBitmap, int groupId)
102 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
103 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
105 result r = pImpl->SetGroupAt(groupIndex, text, pBackgroundBitmap, groupId);
106 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
112 GroupedList::RemoveAllGroups(void)
114 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
115 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
117 result r = pImpl->RemoveAllGroups();
118 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
124 GroupedList::GetGroupCount(void) const
126 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
127 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
129 SetLastResult(E_SUCCESS);
130 return pImpl->GetGroupCount();
134 GroupedList::AddFastScrollEventListener(IFastScrollEventListener& listener)
136 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
137 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
139 result r = pImpl->AddFastScrollEventListener(listener);
140 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
142 SetLastResult(E_SUCCESS);
148 GroupedList::RemoveFastScrollEventListener(IFastScrollEventListener& listener)
150 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
151 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
153 result r = pImpl->RemoveFastScrollEventListener(listener);
154 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
156 SetLastResult(E_SUCCESS);
162 GroupedList::AddGroupedItemEventListener(IGroupedItemEventListener& listener)
164 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
165 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
167 result r = pImpl->AddGroupedItemEventListener(listener);
168 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
170 SetLastResult(E_SUCCESS);
176 GroupedList::RemoveGroupedItemEventListener(IGroupedItemEventListener& listener)
178 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
179 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
181 result r = pImpl->RemoveGroupedItemEventListener(listener);
182 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
184 SetLastResult(E_SUCCESS);
190 GroupedList::AddItem(int groupIndex, const CustomListItem& item, int itemId)
192 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
193 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
195 result r = pImpl->AddItem(groupIndex, item, itemId);
196 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
202 GroupedList::InsertItemAt(int groupIndex, int itemIndex, const CustomListItem& item, int itemId)
204 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
205 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
207 result r = pImpl->InsertItemAt(groupIndex, itemIndex, item, itemId);
208 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
214 GroupedList::SetItemAt(int groupIndex, int itemIndex, const CustomListItem& item, int itemId)
216 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
217 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
219 result r = pImpl->SetItemAt(groupIndex, itemIndex, item, itemId);
220 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
226 GroupedList::RemoveItemAt(int groupIndex, int itemIndex)
228 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
229 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
231 result r = pImpl->RemoveItemAt(groupIndex, itemIndex);
232 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
238 GroupedList::RemoveGroupAt(int groupIndex)
240 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
241 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
243 result r = pImpl->RemoveGroupAt(groupIndex);
244 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
250 GroupedList::RemoveAllItems(void)
252 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
253 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
255 result r = pImpl->RemoveAllItems();
256 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
262 GroupedList::RemoveAllItemsAt(int groupIndex)
264 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
265 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
267 result r = pImpl->RemoveAllItemsAt(groupIndex);
268 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
274 GroupedList::RemoveAllCheckedItemsAt(int groupIndex)
276 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
277 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
279 result r = pImpl->RemoveAllCheckedItemsAt(groupIndex);
280 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
286 GroupedList::GetItemCountAt(int groupIndex) const
288 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
289 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
291 return pImpl->GetSubItemCountAt(groupIndex);
294 const CustomListItem*
295 GroupedList::GetItemAt(int groupIndex, int itemIndex) const
297 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
298 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
300 SysTryReturn(NID_UI_CTRL, (groupIndex >= 0 && itemIndex >= 0), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex(%d) itemIndex(%d)", groupIndex, itemIndex);
302 const CustomListItem* pItem = pImpl->GetCustomListItemAt(groupIndex, itemIndex);
307 GroupedList::SetItemEnabled(int groupIndex, int itemIndex, bool enable)
309 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
310 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
312 result r = pImpl->SetItemEnabled(groupIndex, itemIndex, enable);
313 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
319 GroupedList::IsItemEnabled(int groupIndex, int itemIndex) const
321 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
322 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
324 SetLastResult(E_SUCCESS);
325 return pImpl->IsItemEnabled(groupIndex, itemIndex);
329 GroupedList::SetItemChecked(int groupIndex, int itemIndex, bool check)
331 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
332 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
334 result r = pImpl->SetItemChecked(groupIndex, itemIndex, check);
335 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
341 GroupedList::IsItemChecked(int groupIndex, int itemIndex) const
343 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
344 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
346 SetLastResult(E_SUCCESS);
347 return pImpl->IsItemChecked(groupIndex, itemIndex);
351 GroupedList::SetAllItemsChecked(int groupIndex, bool check)
353 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
354 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
356 result r = pImpl->SetAllItemsChecked(groupIndex, check);
357 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
363 GroupedList::RemoveAllCheckedItems(void)
365 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
366 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
368 result r = pImpl->RemoveAllCheckedItems();
369 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
375 GroupedList::GetFirstCheckedItemIndex(int& groupIndex, int& itemIndex) const
377 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
378 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
380 result r = pImpl->GetFirstCheckedItemIndex(groupIndex, itemIndex);
381 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
387 GroupedList::GetLastCheckedItemIndex(int& groupIndex, int& itemIndex) const
389 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
390 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
392 result r = pImpl->GetLastCheckedItemIndex(groupIndex, itemIndex);
393 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
399 GroupedList::GetNextCheckedItemIndexAfter(int& groupIndex, int& itemIndex) const
401 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
402 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
404 result r = pImpl->GetNextCheckedItemIndexAfter(groupIndex, itemIndex);
405 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
411 GroupedList::GetItemIndexFromPosition(int x, int y, int& groupIndex, int& itemIndex) const
413 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
414 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
416 result r = pImpl->GetItemIndexFromPosition(Point(x, y), groupIndex, itemIndex);
417 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
423 GroupedList::GetItemIndexFromPosition(const Point& position, int& groupIndex, int& itemIndex) const
425 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
426 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
428 result r = pImpl->GetItemIndexFromPosition(position, groupIndex, itemIndex);
429 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
435 GroupedList::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
437 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
438 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
440 result r = pImpl->GetTopDrawnItemIndex(groupIndex, itemIndex);
441 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
447 GroupedList::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
449 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
450 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
452 result r = pImpl->GetBottomDrawnItemIndex(groupIndex, itemIndex);
453 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
459 GroupedList::SetBackgroundColor(const Color& color)
461 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
462 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
464 pImpl->SetListBackgroundColor(color);
465 SetLastResult(E_SUCCESS);
470 GroupedList::SetTextOfEmptyList(const String& text)
472 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
473 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
475 pImpl->SetTextOfEmptyList(text);
476 SetLastResult(E_SUCCESS);
481 GroupedList::SetTextColorOfEmptyList(const Color& color)
483 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
484 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
486 pImpl->SetTextColorOfEmptyList(color);
487 SetLastResult(E_SUCCESS);
492 GroupedList::GetTextColorOfEmptyList(void) const
494 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
495 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
497 SetLastResult(E_SUCCESS);
498 return pImpl->GetTextColorOfEmptyList();
502 GroupedList::GetGroupIndexFromGroupId(int groupId) const
504 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
505 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
507 SetLastResult(E_SUCCESS);
508 return pImpl->GetGroupIndexFromGroupId(groupId);
513 GroupedList::GetItemIndexFromItemId(int itemId, int& groupIndex, int& itemIndex) const
515 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
516 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
518 result r = pImpl->GetItemIndexFromItemId(itemId, groupIndex, itemIndex);
519 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
525 GroupedList::GetItemIdAt(int groupIndex, int itemIndex) const
527 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
528 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
530 SetLastResult(E_SUCCESS);
531 return pImpl->GetItemIdAt(groupIndex, itemIndex);
535 GroupedList::GetGroupIdAt(int groupIndex) const
537 const _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
538 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
540 SetLastResult(E_SUCCESS);
541 return pImpl->GetGroupIdAt(groupIndex);
545 GroupedList::ScrollToBottom(void)
547 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
548 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
550 SetLastResult(E_SUCCESS);
551 pImpl->ScrollToBottom();
555 GroupedList::ScrollToTop(void)
557 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
558 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
560 SetLastResult(E_SUCCESS);
561 pImpl->ScrollToTop();
565 GroupedList::ScrollToTop(int groupIndex, int itemIndex)
567 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
568 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
570 result r = pImpl->ScrollToTop(groupIndex, itemIndex);
571 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
577 GroupedList::ScrollToTop(int groupIndex)
579 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
580 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
582 result r = pImpl->ScrollToTop(groupIndex);
583 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
589 GroupedList::SetFastScrollMainIndex(const String& text)
591 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
592 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
594 result r = pImpl->SetFastScrollMainIndex(text);
595 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
601 GroupedList::SetFastScrollSubIndex(const String& text, FastScrollIndexDigit indexDigit)
603 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
604 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
606 result r = pImpl->SetFastScrollSubIndex(text, indexDigit);
607 SysTryReturn(NID_UI_CTRL, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
613 GroupedList::RefreshItem(int groupIndex, int itemIndex)
615 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
616 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
618 result r = pImpl->RefreshItem(groupIndex, itemIndex);
619 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
625 GroupedList::RefreshGroup(int groupIndex)
627 _GroupedListImpl* pImpl = _GroupedListImpl::GetInstance(*this);
628 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
630 result r = pImpl->RefreshGroup(groupIndex);
631 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
636 }}} //Tizen::Ui::Controls