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"
33 #include "FUi_CoordinateSystemUtils.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)
96 if (__pList->__directDelete == false)
98 CustomListItem* pCustomListItem = __pList->GetCustomListItemAt(-1, itemIndex);
99 pCustomListItem->__pCustomListItemImpl->__pTableViewItemData = null;
106 _CustomListItemDataProvider::UpdateItem(int itemIndex, TableViewItem* pItem)
112 _CustomListItemDataProvider::GetDefaultItemHeight(void)
114 SysTryReturn(NID_UI_CTRL, __pList, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Item provider not constructed properly.");
116 CustomListItem* pCustomListItem = __pList->GetCustomListItemAt(-1, 0);
117 SysTryReturn(NID_UI_CTRL, pCustomListItem, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get first item");
119 _CustomListItemImpl* pCustomListItemImpl = null;
120 pCustomListItemImpl = pCustomListItem->__pCustomListItemImpl;
121 SysTryReturn(NID_UI_CTRL, pCustomListItemImpl, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. CustomListItem not yet constructed.");
123 return pCustomListItemImpl->height;
127 _CustomListImpl::GetInstance(CustomList& customList)
129 return static_cast<_CustomListImpl*>(customList._pControlImpl);
132 const _CustomListImpl*
133 _CustomListImpl::GetInstance(const CustomList& customList)
135 return static_cast<const _CustomListImpl*>(customList._pControlImpl);
138 _CustomListImpl::_CustomListImpl(Control* pList, _TableView* pCore)
139 : _ListBaseImpl(pList, pCore)
140 , __pItemProvider(null)
141 , __directDelete(false)
146 _CustomListImpl::~_CustomListImpl(void)
148 RemoveAllFromItemsList();
150 __itemListenersList.RemoveAll(true);
152 delete __pItemProvider;
156 _CustomListImpl::GetPublicClassName(void) const
162 _CustomListImpl::GetPublic(void) const
164 return static_cast<const CustomList&>(_ControlImpl::GetPublic());
168 _CustomListImpl::GetPublic(void)
170 return static_cast<CustomList&>(_ControlImpl::GetPublic());
174 _CustomListImpl::GetCore(void) const
176 return static_cast<const _TableView&>(_ControlImpl::GetCore());
180 _CustomListImpl::GetCore(void)
182 return static_cast<_TableView&>(_ControlImpl::GetCore());
186 _CustomListImpl::CreateCustomListImplN(CustomList* pControl, const Rectangle& bounds, bool itemDivider)
188 result r = E_SUCCESS;
190 r = GET_SIZE_INFO(CustomList).CheckInitialSizeValidF(FloatDimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
191 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), null, r, "[%s] Propagating.", GetErrorMessage(r));
193 _TableView* pCore = null;
194 _CustomListImpl* pImpl = null;
196 pCore = _TableView::CreateTableViewN(TABLE_VIEW_STYLE_SIMPLE, itemDivider, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
199 SysTryReturn(NID_UI_CTRL, pCore, null, r, "[%s] Propagating.", GetErrorMessage(r));
201 pImpl = new (std::nothrow) _CustomListImpl(pControl, pCore);
202 SysTryCatch(NID_UI_CTRL, pImpl, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
214 _CustomListImpl::InitializeBounds(const Rectangle& rect)
216 result r = E_SUCCESS;
218 r = InitializeBoundsPropertiesF(GET_SIZE_INFO(CustomList), _CoordinateSystemUtils::ConvertToFloat(rect), GetCore().GetOrientation());
219 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
225 _CustomListImpl::AddCustomItemEventListener(const ICustomItemEventListener& listener)
227 _ListListener* pListenersList = new (std::nothrow) _ListListener();
228 SysTryReturn(NID_UI_CTRL, pListenersList, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
230 pListenersList->pListener = const_cast<ICustomItemEventListener*>(&listener);
232 __itemListenersList.Add(*pListenersList);
238 _CustomListImpl::RemoveCustomItemEventListener(const ICustomItemEventListener& listener)
240 _ListListener* pListenersList = null;
243 int count = __itemListenersList.GetCount();
245 for (int itemListenerCount = 0; itemListenerCount < count; itemListenerCount++)
247 pListenersList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(itemListenerCount));
249 if ((pListenersList != null) && (pListenersList->pListener == &listener))
252 __itemListenersList.RemoveAt(itemListenerCount, true);
261 _CustomListImpl::Initialize(void)
263 result r = E_SUCCESS;
265 __pItemProvider = new (std::nothrow) _CustomListItemDataProvider(this);
266 SysTryReturnResult(NID_UI_CTRL, __pItemProvider != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
268 TableViewStyle style = GetCore().GetTableViewStyle();
269 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");
271 _TableViewItemProvider* pItemProvider = _TableViewItemProvider::CreateTableViewItemProviderN(style);
272 SysTryReturn(NID_UI_CTRL, pItemProvider != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
274 r = pItemProvider->SetSimpleStyleItemProvider(__pItemProvider);
278 delete pItemProvider;
279 SysTryReturn(NID_UI_CTRL, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
282 r = GetCore().SetItemProvider(pItemProvider);
283 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
285 r = GetCore().AddTableViewItemEventListener(*this);
286 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
292 _CustomListImpl::AddItem(const CustomListItem& item, int itemId)
294 return InsertItemAt(GetItemCount(), item, itemId);
298 _CustomListImpl::InsertItemAt(int index, const CustomListItem& item, int itemId)
300 result r = E_SUCCESS;
302 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index <= GetItemCount()),
303 E_INVALID_ARG, "The index %d is invalid.", index);
305 item.__pCustomListItemImpl->itemId = itemId;
307 r = InsertIntoItemsList(item, -1, index);
308 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
310 if (GetCore().GetFirstDrawnFlag() == false)
312 r = GetCore().RefreshTableView(0, index, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
313 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[%s] Propagating.",GetErrorMessage(r));
319 RemoveFromItemsList(-1, index);
324 _CustomListImpl::SetItemAt(int index, const CustomListItem& item, int itemId)
326 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
327 E_INVALID_ARG, "The index %d is invalid.", index);
329 SysTryReturnResult(NID_UI_CTRL, (IsItemNew(item) == true), E_SYSTEM, "A system error has occurred. The item already exists.");
331 result r = E_SUCCESS;
333 item.__pCustomListItemImpl->__pTableViewItemData = GetTableViewItemAt(-1, index);
335 _CheckElementModel* pOldCheckElement = GetCheckElementAt(-1, index);
336 _CheckBoxBitmapType oldCheckStatus = (pOldCheckElement) ? (pOldCheckElement->GetCheckBoxStatus()) : CHECK_BOX_UNCHECKED;
338 item.__pCustomListItemImpl->itemId = itemId;
340 _CheckElementModel* pCheckElement = item.__pCustomListItemImpl->GetCheckElement();
344 pCheckElement->SetCheckBoxStatus(oldCheckStatus);
347 r = SetInItemsList(item, -1, index);
348 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to set an item.");
350 _TableViewItemUpdateParams updateParams;
351 updateParams.pItem = const_cast<CustomListItem*>(&item);
352 updateParams.isDividerEnabled = _isDividerEnabled;
353 updateParams.pCheckBitmaps = _pCheckBitmaps;
354 updateParams.annexStyle = _annexStyle;
356 r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
357 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to refresh an item.");
359 if (GetCore().GetFirstDrawnFlag() == false)
361 r = GetCore().RefreshTableView(0, index, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
362 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Propagating.");
369 _CustomListImpl::RemoveItemAt(int index)
371 result r = E_SUCCESS;
374 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
375 E_INVALID_ARG, "The index %d is invalid.", index);
377 r = RemoveFromItemsList(-1, index);
378 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to remove an item.");
380 __directDelete = true;
382 if (GetCore().GetFirstDrawnFlag() == false)
384 r = GetCore().RefreshTableView(groupIndex, index, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
385 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "Propagating.");
388 __directDelete = false;
394 _CustomListImpl::RemoveAllItems(void)
396 result r = E_SUCCESS;
397 result finalResult = E_SUCCESS;
399 for (int index = GetItemCount() - 1; index >= 0; index--)
401 r = RemoveItemAt(index);
406 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Item at %d index not removed successfully.", index);
414 _CustomListImpl::SetItemEnabled(int index, bool enable)
416 result r = E_SUCCESS;
418 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
419 E_SYSTEM, "[E_SYSTEM] A system error has occurred. The index %d is invalid.", index);
421 _CheckElementModel* pCheckElementModel = GetCheckElementAt(-1, index);
423 if (pCheckElementModel)
427 if (pCheckElementModel->GetCheckBoxStatus() == CHECK_BOX_DISABLED)
429 pCheckElementModel->SetCheckBoxStatus(CHECK_BOX_CHECKED);
434 if (pCheckElementModel->GetCheckBoxStatus() == CHECK_BOX_CHECKED)
436 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_MARK)
438 pCheckElementModel->SetCheckBoxStatus(CHECK_BOX_DISABLED);
444 r = GetCore().SetItemEnabled(0, index, enable);
445 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
453 _CustomListImpl::IsItemEnabled(int index) const
455 return GetCore().IsItemEnabled(0, index);
459 _CustomListImpl::SetItemChecked(int groupIndex, int itemIndex, bool check)
461 return SetItemChecked(itemIndex, check);
465 _CustomListImpl::SetItemChecked(int index, bool check)
467 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), E_SYSTEM, "[E_SYSTEM] A system error has occurred. The index %d is invalid.", index);
469 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");
471 if (IsItemChecked(index) == check)
476 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);
478 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
482 if (_currentRadioIndex != -1)
484 _CheckElementModel* pOldCheckElementModel = GetCheckElementAt(-1, _currentRadioIndex);
485 SysTryReturnResult(NID_UI_CTRL, pOldCheckElementModel, E_SYSTEM, "A system error has occurred. tableViewItem is not constructed correctly.");
487 pOldCheckElementModel->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
489 _TableViewItemData* pOldRadioItem = GetTableViewItemAt(-1, _currentRadioIndex);
490 SysTryReturnResult(NID_UI_CTRL, pOldRadioItem, E_SYSTEM, "A system error has occurred. Failed to get item at %d index.", _currentRadioIndex);
492 pOldRadioItem->Invalidate(true);
494 _currentRadioIndex = index;
498 _currentRadioIndex = -1;
502 _CheckElementModel* pCheckElementModel = GetCheckElementAt(-1, index);
503 SysTryReturnResult(NID_UI_CTRL, pCheckElementModel, E_SYSTEM, "A system error has occurred. TableViewItem is not constructed correctly.");
505 pCheckElementModel->SetCheckBoxStatus((_CheckBoxBitmapType)check);
513 _CustomListImpl::IsItemChecked(int groupIndex, int subIndex) const
515 return IsItemChecked(subIndex);
519 _CustomListImpl::IsItemChecked(int index) const
521 SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL),
522 false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. list style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL.");
524 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
525 false, E_INVALID_ARG, "[E_INVALID_ARG] The index %d is invalid.", index);
527 const _CheckElementModel* pCheckElement = GetCheckElementAt(-1, index);
528 SysTryReturn(NID_UI_CTRL, pCheckElement, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. CheckElement is not constructed properly.");
530 return (bool)pCheckElement->GetCheckBoxStatus();
534 _CustomListImpl::SetAllItemsChecked(bool check)
536 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");
537 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");
539 _CheckElementModel* pCheckElement = null;
541 for (int index = 0; index < GetItemCount(); index++)
543 if (IsItemEnabled(index))
545 pCheckElement = GetCheckElementAt(-1, index);
546 SysTryReturnResult(NID_UI_CTRL, (pCheckElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Checkbox element not created");
548 pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
558 _CustomListImpl::RemoveAllCheckedItems(void)
560 result r = E_SUCCESS;
561 result finalResult = E_SUCCESS;
563 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");
564 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");
566 for (int index = GetItemCount() -1; index >= 0; index--)
568 if (IsItemChecked(index))
570 r = RemoveItemAt(index);
575 SysLog(NID_UI_CTRL, "Item at %d index not removed successfully.", index);
584 _CustomListImpl::GetFirstCheckedItemIndex(void) const
586 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");
588 for (int index = 0; index < GetItemCount(); index++)
590 if (IsItemChecked(index))
592 SetLastResult(E_SUCCESS);
596 SetLastResult(E_SUCCESS);
597 return INVALID_INDEX;
601 _CustomListImpl::GetLastCheckedItemIndex(void) const
603 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");
605 for (int index = GetItemCount() - 1; index >= 0; index--)
607 if (IsItemChecked(index))
609 SetLastResult(E_SUCCESS);
613 SetLastResult(E_SUCCESS);
614 return INVALID_INDEX;
618 _CustomListImpl::GetNextCheckedItemIndexAfter(int index) const
620 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");
622 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
623 INVALID_INDEX, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The index %d is invalid.", index);
625 for (int itemCount = index + 1; itemCount < GetItemCount(); itemCount++)
627 if (IsItemChecked(itemCount))
629 SetLastResult(E_SUCCESS);
633 SetLastResult(E_SUCCESS);
634 return INVALID_INDEX;
638 _CustomListImpl::GetItemIndexFromItemId(int itemId) const
640 for (int index = 0; index < GetItemCount(); index++)
642 const CustomListItem* pCustomListItem = GetCustomListItemAt(-1, index);
643 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);
645 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);
647 if (pCustomListItem->__pCustomListItemImpl->itemId == itemId)
649 SetLastResult(E_SUCCESS);
653 SetLastResult(E_SUCCESS);
654 return INVALID_INDEX;
658 _CustomListImpl::ScrollToBottom(void)
660 GetCore().SetBottomDrawnItemIndex(0 ,GetItemCount() - 1);
665 _CustomListImpl::ScrollToTop(void)
667 GetCore().SetTopDrawnItemIndex(0,0);
673 _CustomListImpl::ScrollToTop(int index)
675 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), E_INVALID_ARG, "Invalid index(%d).", index);
677 result r = GetCore().SetTopDrawnItemIndex(0, index);
678 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
686 _CustomListImpl::RefreshItem(int index)
688 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), E_INVALID_ARG, "Invalid index(%d).", index);
690 int topItemIndex = -1;
691 int bottomItemIndex = -1;
694 GetCore().GetTopDrawnItemIndex(groupIndex, topItemIndex);
695 GetCore().GetBottomDrawnItemIndex(groupIndex, bottomItemIndex);
697 SysTryReturnResult(NID_UI_CTRL, (index >= topItemIndex && index <= bottomItemIndex), E_INVALID_OPERATION,
698 "Index should be within drawn item range %d.", index);
700 result r = E_SUCCESS;
702 _TableViewItemUpdateParams updateParams;
703 updateParams.pItem = GetCustomListItemAt(-1, index);
704 updateParams.isDividerEnabled = _isDividerEnabled;
705 updateParams.pCheckBitmaps = _pCheckBitmaps;
706 updateParams.annexStyle = _annexStyle;
708 r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
709 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to refresh an item.");
717 _CustomListImpl::GetItemIdAt(int index) const
719 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
720 -1, E_INVALID_ARG, "[E_INVALID_ARG] The index %d is invalid.", index);
722 const CustomListItem* pCustomListItem = GetCustomListItemAt(-1, index);
723 SysTryReturn(NID_UI_CTRL, pCustomListItem, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", index);
725 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);
727 SetLastResult(E_SUCCESS);
728 return pCustomListItem->__pCustomListItemImpl->itemId;
732 _CustomListImpl::OnTableViewItemStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
734 ItemStatus itemStatus = ITEM_HIGHLIGHTED;
738 case TABLE_VIEW_ITEM_STATUS_SELECTED:
739 itemStatus = ITEM_SELECTED;
741 case TABLE_VIEW_ITEM_STATUS_HIGHLIGHTED:
742 itemStatus = ITEM_HIGHLIGHTED;
744 case TABLE_VIEW_ITEM_STATUS_CHECKED:
745 itemStatus = ITEM_CHECKED;
747 case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
748 itemStatus = ITEM_UNCHECKED;
751 SetLastResult(E_SYSTEM);
755 if ((!_isDividerEnabled) && (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL))
757 bool isChecked = IsItemChecked(itemIndex);
761 itemStatus = ITEM_UNCHECKED;
765 itemStatus = ITEM_CHECKED;
768 SetItemChecked(itemIndex, !isChecked);
771 ProcessItemStateChange(-1, itemIndex, itemStatus);
776 _CustomListImpl::OnTableViewContextItemActivationStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pContextItem, bool activated)
782 _CustomListImpl::OnTableViewItemReordered(_TableView& tableView, int itemIndexFrom, int itemIndexTo)
788 _CustomListImpl::OnGroupedTableViewGroupItemStateChanged(_TableView& tableView, int groupIndex, _TableViewItem* pItem, TableViewItemStatus status)
794 _CustomListImpl::OnGroupedTableViewItemStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
800 _CustomListImpl::OnGroupedTableViewContextItemActivationStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
806 _CustomListImpl::OnGroupedTableViewItemReordered(_TableView& tableView, int groupIndexFrom, int itemIndexFrom, int groupIndexTo, int itemIndexTo)
812 _CustomListImpl::OnSectionTableViewItemStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
818 _CustomListImpl::OnSectionTableViewContextItemActivationStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
824 _CustomListImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
830 _CustomListImpl::ProcessItemStateChange(int groupIndex, int index, int elementId, ItemStatus itemStatus)
832 int itemId = GetItemIdAt(index);
834 _ListListener* pListenerList = null;
835 ICustomItemEventListener* pEventListener = null;
837 int count = __itemListenersList.GetCount();
838 for (int listenerCount = 0; listenerCount < count; listenerCount++)
840 pListenerList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
841 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerList != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
843 pEventListener = dynamic_cast<ICustomItemEventListener*>(pListenerList->pListener);
844 SysTryReturnVoidResult(NID_UI_CTRL, (pEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
846 pEventListener->OnItemStateChanged(GetPublic(), index, itemId, elementId, itemStatus);
848 SetLastResult(E_SUCCESS);
854 _CustomListImpl::ProcessItemStateChange(int groupIndex, int index, ItemStatus itemStatus)
856 int itemId = GetItemIdAt(index);
858 _ListListener* pListenerList = null;
859 ICustomItemEventListener* pEventListener = null;
861 int count = __itemListenersList.GetCount();
862 for (int listenerCount = 0; listenerCount < count; listenerCount++)
864 pListenerList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
865 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerList != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
867 pEventListener = dynamic_cast<ICustomItemEventListener*>(pListenerList->pListener);
868 SysTryReturnVoidResult(NID_UI_CTRL, (pEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
870 pEventListener->OnItemStateChanged(GetPublic(), index, itemId, itemStatus);
872 SetLastResult(E_SUCCESS);
877 class _CustomListMaker
878 : public _UiBuilderControlMaker
881 _CustomListMaker(_UiBuilder* uibuilder)
882 : _UiBuilderControlMaker(uibuilder){};
883 virtual ~_CustomListMaker(){};
884 static _UiBuilderControlMaker*
885 GetInstance(_UiBuilder* uibuilder)
887 _CustomListMaker* pCustomListMaker = new (std::nothrow) _CustomListMaker(uibuilder);
888 return pCustomListMaker;
892 Make(_UiBuilderControl* pControl)
895 _UiBuilderControlLayout* pControlProperty = null;
896 CustomList* pCustomList = null;
898 Tizen::Base::String elementString;
902 CustomListStyle style = CUSTOM_LIST_STYLE_NORMAL;
903 bool isItemDivider = true;
905 GetProperty(pControl, &pControlProperty);
907 if (pControlProperty == null)
912 pCustomList = new (std::nothrow) CustomList();
913 if (pCustomList == null)
918 rect = pControlProperty->GetRect();
920 Tizen::Base::String styleString;
921 styleString = pControlProperty->GetStyle();
923 if (styleString.Equals(L"CUSTOM_LIST_STYLE_NORMAL", false))
925 style = CUSTOM_LIST_STYLE_NORMAL;
927 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO", false))
929 style = CUSTOM_LIST_STYLE_RADIO;
931 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER", false))
933 style = CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER;
935 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK", false))
937 style = CUSTOM_LIST_STYLE_MARK;
939 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER", false))
941 style = CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER;
943 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF", false))
945 style = CUSTOM_LIST_STYLE_ONOFF;
947 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER", false))
949 style = CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER;
953 style = CUSTOM_LIST_STYLE_NORMAL;
957 if (pControl->GetElement(L"itemDivider", elementString))
959 if (elementString.Equals(L"true", false))
961 isItemDivider = true;
965 isItemDivider = false;
969 r = pCustomList->Construct(rect, style, isItemDivider);
976 if (pControl->GetElement(L"textOfEmptyList", elementString))
978 pCustomList->SetTextOfEmptyList(elementString);
981 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
983 ConvertStringToColor(elementString, color);
984 pCustomList->SetTextColorOfEmptyList(color);
992 _CustomListRegister::_CustomListRegister(void)
994 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
996 if (pUiBuilderControlTableManager)
998 pUiBuilderControlTableManager->RegisterControl(L"CustomList", _CustomListMaker::GetInstance);
1001 _CustomListRegister::~_CustomListRegister(void)
1003 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1005 if (pUiBuilderControlTableManager)
1007 pUiBuilderControlTableManager->UnregisterControl(L"CustomList");
1010 static _CustomListRegister CustomListRegisterToUiBuilder;
1011 }}} //Tizen::Ui::Controls