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 FUiCtrl_CustomListImpl.cpp
20 * @brief This file contains implementation of _CustomListImpl class
23 #include <FUiCtrlCustomListItem.h>
24 #include <FUiCtrlCustomListItemFormat.h>
25 #include <FBaseSysLog.h>
26 #include "FUi_ResourceSizeInfo.h"
27 #include "FUi_UiBuilder.h"
28 #include "FUiCtrl_CustomListItemFormatImpl.h"
29 #include "FUiCtrl_CustomListItemImpl.h"
30 #include "FUiCtrl_CustomListImpl.h"
31 #include "FUiCtrl_ListListener.h"
32 #include "FUiCtrl_ListItemBaseImpl.h"
34 #include "FUiCtrl_TableViewItemProvider.h"
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Graphics;
40 namespace Tizen { namespace Ui { namespace Controls
43 extern const int INVALID_INDEX;
45 _CustomListItemDataProvider::_CustomListItemDataProvider(_CustomListImpl* pList)
50 _CustomListItemDataProvider::~_CustomListItemDataProvider(void)
55 _CustomListItemDataProvider::GetItemCount(void)
57 SysTryReturn(NID_UI_CTRL, __pList, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Item provider not constructed properly.");
58 return __pList->GetItemCount();
62 _CustomListItemDataProvider::CreateItem(int index, int itemWidth)
64 SysTryReturn(NID_UI_CTRL, __pList, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Item provider not constructed properly.");
66 CustomListItem* pCustomListItem = __pList->GetCustomListItemAt(-1, index);
67 SysTryReturn(NID_UI_CTRL, pCustomListItem, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", index);
69 _CustomListItemImpl* pCustomListItemImpl = null;
70 pCustomListItemImpl = pCustomListItem->__pCustomListItemImpl;
71 SysTryReturn(NID_UI_CTRL, pCustomListItemImpl, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. CustomListItem not yet constructed.");
73 _TableViewItemParams tableViewItemParams;
74 tableViewItemParams.pItem = pCustomListItem;
75 tableViewItemParams.width = itemWidth;
76 tableViewItemParams.itemId = pCustomListItemImpl->itemId;
77 tableViewItemParams.groupIndex = -1;
78 tableViewItemParams.itemIndex = index;
79 tableViewItemParams.isDividerEnabled = __pList->_isDividerEnabled;
80 tableViewItemParams.pCheckBitmaps = __pList->_pCheckBitmaps;
81 tableViewItemParams.annexStyle = __pList->_annexStyle;
83 result r = _CustomListItemImpl::CreateTableViewItem(tableViewItemParams);
84 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
86 pCustomListItemImpl->__pTableViewItemData->AddTouchEventListener(*__pList);
88 return pCustomListItemImpl->__pTableViewItemData;
92 _CustomListItemDataProvider::DeleteItem(const int itemIndex, TableViewItem* pItem)
94 _TableViewItemData* pTableViewItemData = dynamic_cast<_TableViewItemData*>(pItem);
95 delete pTableViewItemData;
97 CustomListItem* pCustomListItem = __pList->GetCustomListItemAt(-1, itemIndex);
98 pCustomListItem->__pCustomListItemImpl->__pTableViewItemData = null;
104 _CustomListItemDataProvider::UpdateItem(int itemIndex, TableViewItem* pItem)
110 _CustomListItemDataProvider::GetDefaultItemHeight(void)
112 SysTryReturn(NID_UI_CTRL, __pList, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Item provider not constructed properly.");
114 CustomListItem* pCustomListItem = __pList->GetCustomListItemAt(-1, 0);
115 SysTryReturn(NID_UI_CTRL, pCustomListItem, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get first item");
117 _CustomListItemImpl* pCustomListItemImpl = null;
118 pCustomListItemImpl = pCustomListItem->__pCustomListItemImpl;
119 SysTryReturn(NID_UI_CTRL, pCustomListItemImpl, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. CustomListItem not yet constructed.");
121 return pCustomListItemImpl->height;
125 _CustomListImpl::GetInstance(CustomList& customList)
127 return static_cast<_CustomListImpl*>(customList._pControlImpl);
130 const _CustomListImpl*
131 _CustomListImpl::GetInstance(const CustomList& customList)
133 return static_cast<const _CustomListImpl*>(customList._pControlImpl);
136 _CustomListImpl::_CustomListImpl(Control* pList, _TableView* pCore)
137 : _ListBaseImpl(pList, pCore)
138 , __pItemProvider(null)
142 _CustomListImpl::~_CustomListImpl(void)
144 RemoveAllFromItemsList();
146 __itemListenersList.RemoveAll(true);
148 delete __pItemProvider;
152 _CustomListImpl::GetPublicClassName(void) const
158 _CustomListImpl::GetPublic(void) const
160 return static_cast<const CustomList&>(_ControlImpl::GetPublic());
164 _CustomListImpl::GetPublic(void)
166 return static_cast<CustomList&>(_ControlImpl::GetPublic());
170 _CustomListImpl::GetCore(void) const
172 return static_cast<const _TableView&>(_ControlImpl::GetCore());
176 _CustomListImpl::GetCore(void)
178 return static_cast<_TableView&>(_ControlImpl::GetCore());
182 _CustomListImpl::CreateCustomListImplN(CustomList* pControl, const Rectangle& bounds, bool itemDivider)
184 result r = E_SUCCESS;
186 r = GET_SIZE_INFO(CustomList).CheckInitialSizeValid(Dimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
187 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), null, r, "[%s] Propagating.", GetErrorMessage(r));
189 _TableView* pCore = null;
190 _CustomListImpl* pImpl = null;
192 pCore = _TableView::CreateTableViewN(TABLE_VIEW_STYLE_SIMPLE, itemDivider, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
195 SysTryReturn(NID_UI_CTRL, pCore, null, r, "[%s] Propagating.", GetErrorMessage(r));
197 pImpl = new (std::nothrow) _CustomListImpl(pControl, pCore);
198 SysTryCatch(NID_UI_CTRL, pImpl, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
210 _CustomListImpl::InitializeBounds(const Rectangle& rect)
212 result r = E_SUCCESS;
214 r = InitializeBoundsProperties(GET_SIZE_INFO(CustomList), rect, GetCore().GetOrientation());
215 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
221 _CustomListImpl::AddCustomItemEventListener(const ICustomItemEventListener& listener)
223 _ListListener* pListenersList = new (std::nothrow) _ListListener();
224 SysTryReturn(NID_UI_CTRL, pListenersList, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
226 pListenersList->pListener = const_cast<ICustomItemEventListener*>(&listener);
228 __itemListenersList.Add(*pListenersList);
234 _CustomListImpl::RemoveCustomItemEventListener(const ICustomItemEventListener& listener)
236 _ListListener* pListenersList = null;
239 int count = __itemListenersList.GetCount();
241 for (int itemListenerCount = 0; itemListenerCount < count; itemListenerCount++)
243 pListenersList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(itemListenerCount));
245 if ((pListenersList != null) && (pListenersList->pListener == &listener))
248 __itemListenersList.RemoveAt(itemListenerCount, true);
257 _CustomListImpl::Initialize(void)
259 result r = E_SUCCESS;
261 __pItemProvider = new (std::nothrow) _CustomListItemDataProvider(this);
262 SysTryReturnResult(NID_UI_CTRL, __pItemProvider != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
264 TableViewStyle style = GetCore().GetTableViewStyle();
265 SysTryReturn(NID_UI_CTRL, style == TABLE_VIEW_STYLE_SIMPLE, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The style of TableView is not TABLE_VIEW_STYLE_SIMPLE");
267 _TableViewItemProvider* pItemProvider = _TableViewItemProvider::CreateTableViewItemProviderN(style);
268 SysTryReturn(NID_UI_CTRL, pItemProvider != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
270 r = pItemProvider->SetSimpleStyleItemProvider(__pItemProvider);
274 delete pItemProvider;
275 SysTryReturn(NID_UI_CTRL, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
278 r = GetCore().SetItemProvider(pItemProvider);
279 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
281 r = GetCore().AddTableViewItemEventListener(*this);
282 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
288 _CustomListImpl::AddItem(const CustomListItem& item, int itemId)
290 return InsertItemAt(GetItemCount(), item, itemId);
294 _CustomListImpl::InsertItemAt(int index, const CustomListItem& item, int itemId)
296 result r = E_SUCCESS;
298 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index <= GetItemCount()),
299 E_INVALID_ARG, "The index %d is invalid.", index);
301 item.__pCustomListItemImpl->itemId = itemId;
303 r = InsertIntoItemsList(item, -1, index);
304 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
306 if (GetCore().GetFirstDrawnFlag() == false)
308 r = GetCore().RefreshTableView(0, index, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
309 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[%s] Propagating.",GetErrorMessage(r));
315 RemoveFromItemsList(-1, index);
320 _CustomListImpl::SetItemAt(int index, const CustomListItem& item, int itemId)
322 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
323 E_INVALID_ARG, "The index %d is invalid.", index);
325 SysTryReturnResult(NID_UI_CTRL, (IsItemNew(item) == true), E_SYSTEM, "A system error has occurred. The item already exists.");
327 result r = E_SUCCESS;
329 item.__pCustomListItemImpl->__pTableViewItemData = GetTableViewItemAt(-1, index);
331 _CheckElementModel* pOldCheckElement = GetCheckElementAt(-1, index);
332 _CheckBoxBitmapType oldCheckStatus = (pOldCheckElement) ? (pOldCheckElement->GetCheckBoxStatus()) : CHECK_BOX_UNCHECKED;
334 item.__pCustomListItemImpl->itemId = itemId;
336 _CheckElementModel* pCheckElement = item.__pCustomListItemImpl->GetCheckElement();
340 pCheckElement->SetCheckBoxStatus(oldCheckStatus);
343 r = SetInItemsList(item, -1, index);
344 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to set an item.");
346 _TableViewItemUpdateParams updateParams;
347 updateParams.pItem = const_cast<CustomListItem*>(&item);
348 updateParams.isDividerEnabled = _isDividerEnabled;
349 updateParams.pCheckBitmaps = _pCheckBitmaps;
350 updateParams.annexStyle = _annexStyle;
352 r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
353 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to refresh an item.");
355 if (GetCore().GetFirstDrawnFlag() == false)
357 r = GetCore().RefreshTableView(0, index, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
358 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Propagating.");
365 _CustomListImpl::RemoveItemAt(int index)
367 result r = E_SUCCESS;
369 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
370 E_INVALID_ARG, "The index %d is invalid.", index);
374 if (GetCore().GetFirstDrawnFlag() == false)
376 r = GetCore().RefreshTableView(groupIndex, index, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
377 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Propagating.");
380 r = RemoveFromItemsList(-1, index);
381 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to remove an item.");
387 _CustomListImpl::RemoveAllItems(void)
389 result r = E_SUCCESS;
390 result finalResult = E_SUCCESS;
392 for (int index = GetItemCount() - 1; index >= 0; index--)
394 r = RemoveItemAt(index);
399 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Item at %d index not removed successfully.", index);
407 _CustomListImpl::SetItemEnabled(int index, bool enable)
409 result r = E_SUCCESS;
411 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
412 E_SYSTEM, "[E_SYSTEM] A system error has occurred. The index %d is invalid.", index);
414 _CheckElementModel* pCheckElementModel = GetCheckElementAt(-1, index);
416 if (pCheckElementModel)
420 if (pCheckElementModel->GetCheckBoxStatus() == CHECK_BOX_DISABLED)
422 pCheckElementModel->SetCheckBoxStatus(CHECK_BOX_CHECKED);
427 if (pCheckElementModel->GetCheckBoxStatus() == CHECK_BOX_CHECKED)
429 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_MARK)
431 pCheckElementModel->SetCheckBoxStatus(CHECK_BOX_DISABLED);
437 r = GetCore().SetItemEnabled(0, index, enable);
438 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
446 _CustomListImpl::IsItemEnabled(int index) const
448 return GetCore().IsItemEnabled(0, index);
452 _CustomListImpl::SetItemChecked(int groupIndex, int itemIndex, bool check)
454 return SetItemChecked(itemIndex, check);
458 _CustomListImpl::SetItemChecked(int index, bool check)
460 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), E_SYSTEM, "[E_SYSTEM] A system error has occurred. The index %d is invalid.", index);
462 SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "[E_SYSTEM] A system error has occurred. List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
464 if (IsItemChecked(index) == check)
469 SysTryReturnResult(NID_UI_CTRL, (IsItemEnabled(index)), E_SYSTEM, "[E_SYSTEM] A system error has occurred. The List item is not enabled at index %d.", index);
471 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
475 if (_currentRadioIndex != -1)
477 _CheckElementModel* pOldCheckElementModel = GetCheckElementAt(-1, _currentRadioIndex);
478 SysTryReturnResult(NID_UI_CTRL, pOldCheckElementModel, E_SYSTEM, "A system error has occurred. tableViewItem is not constructed correctly.");
480 pOldCheckElementModel->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
482 _TableViewItemData* pOldRadioItem = GetTableViewItemAt(-1, _currentRadioIndex);
483 SysTryReturnResult(NID_UI_CTRL, pOldRadioItem, E_SYSTEM, "A system error has occurred. Failed to get item at %d index.", _currentRadioIndex);
485 pOldRadioItem->Invalidate(true);
487 _currentRadioIndex = index;
491 _currentRadioIndex = -1;
495 _CheckElementModel* pCheckElementModel = GetCheckElementAt(-1, index);
496 SysTryReturnResult(NID_UI_CTRL, pCheckElementModel, E_SYSTEM, "A system error has occurred. TableViewItem is not constructed correctly.");
498 pCheckElementModel->SetCheckBoxStatus((_CheckBoxBitmapType)check);
506 _CustomListImpl::IsItemChecked(int groupIndex, int subIndex) const
508 return IsItemChecked(subIndex);
512 _CustomListImpl::IsItemChecked(int index) const
514 SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL),
515 false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. list style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL.");
517 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
518 false, E_INVALID_ARG, "[E_INVALID_ARG] The index %d is invalid.", index);
520 const _CheckElementModel* pCheckElement = GetCheckElementAt(-1, index);
521 SysTryReturn(NID_UI_CTRL, pCheckElement, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. CheckElement is not constructed properly.");
523 return (bool)pCheckElement->GetCheckBoxStatus();
527 _CustomListImpl::SetAllItemsChecked(bool check)
529 SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "[E_SYSTEM] A system error has occurred. List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
530 SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_RADIO), E_SYSTEM, "[E_SYSTEM] A system error has occurred. List style should not be TABLE_VIEW_ANNEX_STYLE_RADIO");
532 _CheckElementModel* pCheckElement = null;
534 for (int index = 0; index < GetItemCount(); index++)
536 if (IsItemEnabled(index))
538 pCheckElement = GetCheckElementAt(-1, index);
539 SysTryReturnResult(NID_UI_CTRL, (pCheckElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Checkbox element not created");
541 pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
551 _CustomListImpl::RemoveAllCheckedItems(void)
553 result r = E_SUCCESS;
554 result finalResult = E_SUCCESS;
556 SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "[E_SYSTEM] A system error has occurred. List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
557 SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_RADIO), E_SYSTEM, "[E_SYSTEM] A system error has occurred. List style should not be TABLE_VIEW_ANNEX_STYLE_RADIO");
559 for (int index = GetItemCount() -1; index >= 0; index--)
561 if (IsItemChecked(index))
563 r = RemoveItemAt(index);
568 SysLog(NID_UI_CTRL, "Item at %d index not removed successfully.", index);
577 _CustomListImpl::GetFirstCheckedItemIndex(void) const
579 SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), INVALID_INDEX, E_SYSTEM, "[E_SYSTEM] A system error has occurred. List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
581 for (int index = 0; index < GetItemCount(); index++)
583 if (IsItemChecked(index))
585 SetLastResult(E_SUCCESS);
589 SetLastResult(E_SUCCESS);
590 return INVALID_INDEX;
594 _CustomListImpl::GetLastCheckedItemIndex(void) const
596 SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), INVALID_INDEX, E_SYSTEM, "[E_SYSTEM] A system error has occurred. List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
598 for (int index = GetItemCount() - 1; index >= 0; index--)
600 if (IsItemChecked(index))
602 SetLastResult(E_SUCCESS);
606 SetLastResult(E_SUCCESS);
607 return INVALID_INDEX;
611 _CustomListImpl::GetNextCheckedItemIndexAfter(int index) const
613 SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), INVALID_INDEX, E_SYSTEM, "[E_SYSTEM] A system error has occurred. List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
615 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
616 INVALID_INDEX, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The index %d is invalid.", index);
618 for (int itemCount = index + 1; itemCount < GetItemCount(); itemCount++)
620 if (IsItemChecked(itemCount))
622 SetLastResult(E_SUCCESS);
626 SetLastResult(E_SUCCESS);
627 return INVALID_INDEX;
631 _CustomListImpl::GetItemIndexFromItemId(int itemId) const
633 for (int index = 0; index < GetItemCount(); index++)
635 const CustomListItem* pCustomListItem = GetCustomListItemAt(-1, index);
636 SysTryReturn(NID_UI_CTRL, pCustomListItem, INVALID_INDEX, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", index);
638 SysTryReturn(NID_UI_CTRL, pCustomListItem->__pCustomListItemImpl, INVALID_INDEX, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", index);
640 if (pCustomListItem->__pCustomListItemImpl->itemId == itemId)
642 SetLastResult(E_SUCCESS);
646 SetLastResult(E_SUCCESS);
647 return INVALID_INDEX;
651 _CustomListImpl::ScrollToBottom(void)
653 GetCore().SetBottomDrawnItemIndex(0 ,GetItemCount() - 1);
658 _CustomListImpl::ScrollToTop(void)
660 GetCore().SetTopDrawnItemIndex(0,0);
666 _CustomListImpl::ScrollToTop(int index)
668 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), E_INVALID_ARG, "Invalid index(%d).", index);
670 result r = GetCore().SetTopDrawnItemIndex(0, index);
671 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
679 _CustomListImpl::RefreshItem(int index)
681 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), E_INVALID_ARG, "Invalid index(%d).", index);
683 int topItemIndex = -1;
684 int bottomItemIndex = -1;
687 GetCore().GetTopDrawnItemIndex(groupIndex, topItemIndex);
688 GetCore().GetBottomDrawnItemIndex(groupIndex, bottomItemIndex);
690 SysTryReturnResult(NID_UI_CTRL, (index >= topItemIndex && index <= bottomItemIndex), E_INVALID_OPERATION,
691 "Index should be within drawn item range %d.", index);
693 result r = E_SUCCESS;
695 _TableViewItemUpdateParams updateParams;
696 updateParams.pItem = GetCustomListItemAt(-1, index);
697 updateParams.isDividerEnabled = _isDividerEnabled;
698 updateParams.pCheckBitmaps = _pCheckBitmaps;
699 updateParams.annexStyle = _annexStyle;
701 r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
702 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to refresh an item.");
710 _CustomListImpl::GetItemIdAt(int index) const
712 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
713 -1, E_INVALID_ARG, "[E_INVALID_ARG] The index %d is invalid.", index);
715 const CustomListItem* pCustomListItem = GetCustomListItemAt(-1, index);
716 SysTryReturn(NID_UI_CTRL, pCustomListItem, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", index);
718 SysTryReturn(NID_UI_CTRL, pCustomListItem->__pCustomListItemImpl, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", index);
720 SetLastResult(E_SUCCESS);
721 return pCustomListItem->__pCustomListItemImpl->itemId;
725 _CustomListImpl::OnTableViewItemStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
727 ItemStatus itemStatus = ITEM_HIGHLIGHTED;
731 case TABLE_VIEW_ITEM_STATUS_SELECTED:
732 itemStatus = ITEM_SELECTED;
734 case TABLE_VIEW_ITEM_STATUS_HIGHLIGHTED:
735 itemStatus = ITEM_HIGHLIGHTED;
737 case TABLE_VIEW_ITEM_STATUS_CHECKED:
738 itemStatus = ITEM_CHECKED;
740 case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
741 itemStatus = ITEM_UNCHECKED;
744 SetLastResult(E_SYSTEM);
748 if ((!_isDividerEnabled) && (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL))
750 bool isChecked = IsItemChecked(itemIndex);
754 itemStatus = ITEM_UNCHECKED;
758 itemStatus = ITEM_CHECKED;
761 SetItemChecked(itemIndex, !isChecked);
764 ProcessItemStateChange(-1, itemIndex, itemStatus);
769 _CustomListImpl::OnTableViewContextItemActivationStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pContextItem, bool activated)
775 _CustomListImpl::OnTableViewItemReordered(_TableView& tableView, int itemIndexFrom, int itemIndexTo)
781 _CustomListImpl::OnGroupedTableViewGroupItemStateChanged(_TableView& tableView, int groupIndex, _TableViewItem* pItem, TableViewItemStatus status)
787 _CustomListImpl::OnGroupedTableViewItemStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
793 _CustomListImpl::OnGroupedTableViewContextItemActivationStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
799 _CustomListImpl::OnGroupedTableViewItemReordered(_TableView& tableView, int groupIndexFrom, int itemIndexFrom, int groupIndexTo, int itemIndexTo)
805 _CustomListImpl::OnSectionTableViewItemStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
811 _CustomListImpl::OnSectionTableViewContextItemActivationStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
817 _CustomListImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
823 _CustomListImpl::ProcessItemStateChange(int groupIndex, int index, int elementId, ItemStatus itemStatus)
825 int itemId = GetItemIdAt(index);
827 _ListListener* pListenerList = null;
828 ICustomItemEventListener* pEventListener = null;
830 int count = __itemListenersList.GetCount();
831 for (int listenerCount = 0; listenerCount < count; listenerCount++)
833 pListenerList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
834 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerList != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
836 pEventListener = dynamic_cast<ICustomItemEventListener*>(pListenerList->pListener);
837 SysTryReturnVoidResult(NID_UI_CTRL, (pEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
839 pEventListener->OnItemStateChanged(GetPublic(), index, itemId, elementId, itemStatus);
841 SetLastResult(E_SUCCESS);
847 _CustomListImpl::ProcessItemStateChange(int groupIndex, int index, ItemStatus itemStatus)
849 int itemId = GetItemIdAt(index);
851 _ListListener* pListenerList = null;
852 ICustomItemEventListener* pEventListener = null;
854 int count = __itemListenersList.GetCount();
855 for (int listenerCount = 0; listenerCount < count; listenerCount++)
857 pListenerList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
858 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerList != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
860 pEventListener = dynamic_cast<ICustomItemEventListener*>(pListenerList->pListener);
861 SysTryReturnVoidResult(NID_UI_CTRL, (pEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
863 pEventListener->OnItemStateChanged(GetPublic(), index, itemId, itemStatus);
865 SetLastResult(E_SUCCESS);
870 class _CustomListMaker
871 : public _UiBuilderControlMaker
874 _CustomListMaker(_UiBuilder* uibuilder)
875 : _UiBuilderControlMaker(uibuilder){};
876 virtual ~_CustomListMaker(){};
877 static _UiBuilderControlMaker*
878 GetInstance(_UiBuilder* uibuilder)
880 _CustomListMaker* pCustomListMaker = new (std::nothrow) _CustomListMaker(uibuilder);
881 return pCustomListMaker;
885 Make(_UiBuilderControl* pControl)
888 _UiBuilderControlLayout* pControlProperty = null;
889 CustomList* pCustomList = null;
891 Tizen::Base::String elementString;
895 CustomListStyle style = CUSTOM_LIST_STYLE_NORMAL;
896 bool isItemDivider = true;
898 GetProperty(pControl, &pControlProperty);
900 if (pControlProperty == null)
905 pCustomList = new (std::nothrow) CustomList();
906 if (pCustomList == null)
911 rect = pControlProperty->GetRect();
913 Tizen::Base::String styleString;
914 styleString = pControlProperty->GetStyle();
916 if (styleString.Equals(L"CUSTOM_LIST_STYLE_NORMAL", false))
918 style = CUSTOM_LIST_STYLE_NORMAL;
920 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO", false))
922 style = CUSTOM_LIST_STYLE_RADIO;
924 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER", false))
926 style = CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER;
928 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK", false))
930 style = CUSTOM_LIST_STYLE_MARK;
932 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER", false))
934 style = CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER;
936 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF", false))
938 style = CUSTOM_LIST_STYLE_ONOFF;
940 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER", false))
942 style = CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER;
946 style = CUSTOM_LIST_STYLE_NORMAL;
950 if (pControl->GetElement(L"itemDivider", elementString))
952 if (elementString.Equals(L"true", false))
954 isItemDivider = true;
958 isItemDivider = false;
962 r = pCustomList->Construct(rect, style, isItemDivider);
969 if (pControl->GetElement(L"textOfEmptyList", elementString))
971 pCustomList->SetTextOfEmptyList(elementString);
974 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
976 ConvertStringToColor(elementString, color);
977 pCustomList->SetTextColorOfEmptyList(color);
985 _CustomListRegister::_CustomListRegister(void)
987 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
989 if (pUiBuilderControlTableManager)
991 pUiBuilderControlTableManager->RegisterControl(L"CustomList", _CustomListMaker::GetInstance);
994 _CustomListRegister::~_CustomListRegister(void)
996 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
998 if (pUiBuilderControlTableManager)
1000 pUiBuilderControlTableManager->UnregisterControl(L"CustomList");
1003 static _CustomListRegister CustomListRegisterToUiBuilder;
1004 }}} //Tizen::Ui::Controls