2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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 FUiCtrlExpandableList.cpp
20 * @brief This is the implementation file for FUiCtrlExpandableList class.
24 #include <FUiCtrlExpandableList.h>
25 #include <FBaseSysLog.h>
26 #include "FUiCtrl_CustomListImpl.h"
27 #include "FUiCtrl_ExpandableListImpl.h"
29 using namespace Tizen::Base;
30 using namespace Tizen::Base::Collection;
31 using namespace Tizen::Graphics;
34 namespace Tizen { namespace Ui { namespace Controls
37 ExpandableList::ExpandableList(void)
41 ExpandableList::~ExpandableList(void)
46 ExpandableList::Construct(const Rectangle& rect, CustomListStyle style, bool itemDivider)
50 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
51 SysAssertf(pImpl == null, "Already constructed! Calling Construct() twice or more on a same instance is not allowed for this class");
53 pImpl = _ExpandableListImpl::CreateExpandableListImplN(this, rect, itemDivider);
55 SysTryReturn(NID_UI_CTRL, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
57 _pControlImpl = pImpl;
59 r = pImpl->UpdateBounds(rect);
60 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
62 r = pImpl->SetListStyle(style);
63 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[E_SYSTEM] A system error occurred.");
65 r = pImpl->Initialize();
66 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
68 r = pImpl->LoadDefaultBitmap();
69 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[E_SYSTEM] A system error occurred.");
81 ExpandableList::AddExpandableItemEventListener(IExpandableItemEventListener& listener)
83 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
84 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
86 result r = pImpl->AddExpandableItemEventListener(listener);
88 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
89 SetLastResult(E_SUCCESS);
95 ExpandableList::RemoveExpandableItemEventListener(IExpandableItemEventListener& listener)
97 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
98 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
100 result r = pImpl->RemoveExpandableItemEventListener(listener);
102 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
103 SetLastResult(E_SUCCESS);
109 ExpandableList::AddItem(const CustomListItem& item, int itemId)
111 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
112 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
114 return pImpl->AddItem(item, itemId);
118 ExpandableList::InsertItemAt(int index, const CustomListItem& item, int itemId)
120 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
121 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
123 result r = pImpl->InsertItemAt(index, item, itemId);
124 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
130 ExpandableList::SetItemAt(int index, const CustomListItem& item, int itemId)
132 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
133 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
134 SetLastResult(E_SUCCESS);
136 result r = pImpl->SetItemAt(index, item, itemId);
137 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
143 ExpandableList::RemoveItemAt(int mainIndex)
145 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
146 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
148 result r = pImpl->RemoveItemAt(mainIndex);
149 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
155 ExpandableList::RemoveAllItems(void)
157 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
158 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
160 result r = pImpl->RemoveAllItems();
161 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
166 const CustomListItem*
167 ExpandableList::GetItemAt(int index) const
169 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
170 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
172 const CustomListItem* pItem = pImpl->GetCustomListItemAt(index, -1);
177 ExpandableList::AddSubItem(int mainIndex, const CustomListItem& item, int itemId)
179 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
180 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
182 result r = pImpl->AddSubItem(mainIndex, item, itemId);
183 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
189 ExpandableList::InsertSubItemAt(int mainIndex, int subIndex, const CustomListItem& item, int itemId)
191 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
192 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
194 result r = pImpl->InsertSubItemAt(mainIndex, subIndex, item, itemId);
195 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
201 ExpandableList::SetSubItemAt(int mainIndex, int subIndex, const CustomListItem& item, int itemId)
203 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
204 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
206 result r = pImpl->SetSubItemAt(mainIndex, subIndex, item, itemId);
207 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
213 ExpandableList::RemoveSubItemAt(int mainIndex, int subIndex)
215 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
216 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
218 result r = pImpl->RemoveSubItemAt(mainIndex, subIndex);
219 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
225 ExpandableList::RemoveAllSubItemsAt(int mainIndex)
227 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
228 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
230 result r = pImpl->RemoveAllSubItemsAt(mainIndex);
231 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
237 ExpandableList::GetItemCount(void) const
239 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
240 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
241 SetLastResult(E_SUCCESS);
243 return pImpl->GetItemCount();
247 ExpandableList::GetSubItemCount(int mainIndex) const
249 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
250 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
251 SetLastResult(E_SUCCESS);
253 return pImpl->GetSubItemCount(mainIndex);
256 const CustomListItem*
257 ExpandableList::GetSubItemAt(int mainIndex, int subIndex) const
259 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
260 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
262 SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && subIndex >= 0), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d subIndex = %d", mainIndex, subIndex);
264 const CustomListItem* pItem = pImpl->GetCustomListItemAt(mainIndex, subIndex);
269 ExpandableList::GetFirstCheckedItemIndex(void) const
271 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
272 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
273 SetLastResult(E_SUCCESS);
275 return pImpl->GetFirstCheckedItemIndex();
279 ExpandableList::GetItemIdAt(int mainIndex) const
281 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
282 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
283 SetLastResult(E_SUCCESS);
285 return pImpl->GetItemIdAt(mainIndex);
289 ExpandableList::GetItemIndexFromItemId(int itemId) const
291 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
292 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
293 SetLastResult(E_SUCCESS);
295 return pImpl->GetItemIndexFromItemId(itemId);
299 ExpandableList::GetSubItemIdAt(int mainIndex, int subIndex) const
301 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
302 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
303 SetLastResult(E_SUCCESS);
305 return pImpl->GetSubItemIdAt(mainIndex, subIndex);
309 ExpandableList::SetItemExpanded(int mainIndex, bool expand)
311 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
312 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
314 return pImpl->SetItemExpanded(mainIndex, expand);
318 ExpandableList::IsItemExpanded(int mainIndex) const
320 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
321 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
322 SetLastResult(E_SUCCESS);
324 return pImpl->IsItemExpanded(mainIndex);
328 ExpandableList::SetItemEnabled(int mainIndex, bool enable)
330 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
331 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
333 result r = pImpl->SetItemEnabled(mainIndex, enable);
334 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
340 ExpandableList::IsItemEnabled(int index) const
342 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
343 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
344 SetLastResult(E_SUCCESS);
346 return pImpl->IsItemEnabled(index);
350 ExpandableList::SetSubItemEnabled(int mainIndex, int subIndex, bool enable)
352 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
353 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
355 result r = pImpl->SetSubItemEnabled(mainIndex, subIndex, enable);
356 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
362 ExpandableList::IsSubItemEnabled(int mainIndex, int subIndex) const
364 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
365 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
366 SetLastResult(E_SUCCESS);
368 return pImpl->IsSubItemEnabled(mainIndex, subIndex);
372 ExpandableList::SetItemChecked(int mainIndex, bool check)
374 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
375 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
377 result r = pImpl->SetItemChecked(mainIndex, check);
378 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
384 ExpandableList::IsItemChecked(int mainIndex) const
386 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
387 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
389 return pImpl->IsItemChecked(mainIndex);
393 ExpandableList::SetSubItemChecked(int mainIndex, int subIndex, bool check)
395 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
396 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
398 result r = pImpl->SetSubItemChecked(mainIndex, subIndex, check);
399 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
405 ExpandableList::IsSubItemChecked(int mainIndex, int subIndex) const
407 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
408 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
409 SetLastResult(E_SUCCESS);
411 return pImpl->IsSubItemChecked(mainIndex, subIndex);
415 ExpandableList::SetAllSubItemsChecked(int mainIndex, bool check)
417 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
418 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
420 result r = pImpl->SetAllSubItemsChecked(mainIndex, check);
421 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
427 ExpandableList::RemoveAllCheckedSubItemsAt(int mainIndex)
429 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
430 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
432 result r = pImpl->RemoveAllCheckedSubItemsAt(mainIndex);
433 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
439 ExpandableList::GetFirstCheckedSubItemIndex(int mainIndex) const
441 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
442 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
443 SetLastResult(E_SUCCESS);
445 return pImpl->GetFirstCheckedSubItemIndex(mainIndex);
449 ExpandableList::GetLastCheckedItemIndex(void) const
451 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
452 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
453 SetLastResult(E_SUCCESS);
455 return pImpl->GetLastCheckedItemIndex();
459 ExpandableList::GetLastCheckedSubItemIndex(int mainIndex) const
461 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
462 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
463 SetLastResult(E_SUCCESS);
465 return pImpl->GetLastCheckedSubItemIndex(mainIndex);
469 ExpandableList::GetNextCheckedItemIndexAfter(int index) const
471 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
472 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
473 SetLastResult(E_SUCCESS);
475 return pImpl->GetNextCheckedItemIndexAfter(index);
479 ExpandableList::GetNextCheckedSubItemIndexAfter(int mainIndex, int subIndex) const
481 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
482 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
483 SetLastResult(E_SUCCESS);
485 return pImpl->GetNextCheckedSubItemIndexAfter(mainIndex, subIndex);
489 ExpandableList::GetSubItemIndexFromItemId(int itemId, int& mainIndex, int& subIndex) const
491 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
492 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
494 return pImpl->GetSubItemIndexFromItemId(itemId, mainIndex, subIndex);
498 ExpandableList::GetItemIndexFromPosition(int x, int y, int& mainIndex, int& subIndex) const
500 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
501 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
503 return pImpl->GetItemIndexFromPosition(Point(x, y), mainIndex, subIndex);
507 ExpandableList::GetItemIndexFromPosition(const Point& position, int& mainIndex, int& subIndex) const
509 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
510 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
512 return pImpl->GetItemIndexFromPosition(position, mainIndex, subIndex);
516 ExpandableList::GetTopDrawnItemIndex(int& mainIndex, int& subIndex) const
518 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
519 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
521 return pImpl->GetTopDrawnItemIndex(mainIndex, subIndex);
525 ExpandableList::GetBottomDrawnItemIndex(int& mainIndex, int& subIndex) const
527 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
528 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
530 return pImpl->GetBottomDrawnItemIndex(mainIndex, subIndex);
534 ExpandableList::SetBackgroundColor(const Color& color)
536 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
537 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
538 SetLastResult(E_SUCCESS);
540 pImpl->SetBgColor(color);
545 ExpandableList::SetTextOfEmptyList(const String& text)
547 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
548 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
549 SetLastResult(E_SUCCESS);
551 pImpl->SetTextOfEmptyList(text);
556 ExpandableList::SetTextColorOfEmptyList(const Color& color)
558 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
559 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
561 pImpl->SetTextColorOfEmptyList(color);
562 SetLastResult(E_SUCCESS);
568 ExpandableList::GetTextColorOfEmptyList(void) const
570 const _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
571 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
572 SetLastResult(E_SUCCESS);
574 return pImpl->GetTextColorOfEmptyList();
578 ExpandableList::ScrollToBottom(void)
580 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
581 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
583 result r = pImpl->ScrollToBottom();
584 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
585 SetLastResult(E_SUCCESS);
591 ExpandableList::ScrollToTop(void)
593 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
594 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
595 SetLastResult(E_SUCCESS);
597 result r = pImpl->ScrollToTop();
598 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
604 ExpandableList::ScrollToTop(int mainIndex, int subIndex)
606 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
607 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
609 result r = pImpl->ScrollToTop(mainIndex, subIndex);
610 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
616 ExpandableList::ScrollToTop(int mainIndex)
618 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
619 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
621 result r = pImpl->ScrollToTop(mainIndex);
622 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
628 ExpandableList::RefreshSubItem(int mainIndex, int subIndex)
630 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
631 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
633 result r = pImpl->RefreshSubItem(mainIndex, subIndex);
634 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
640 ExpandableList::RefreshItem(int mainIndex)
642 _ExpandableListImpl* pImpl = _ExpandableListImpl::GetInstance(*this);
643 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
645 result r = pImpl->RefreshItem(mainIndex);
646 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
651 }}} //Tizen::Ui::Controls