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 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 r = GetCore().SetItemEnabled(0, index, enable);
422 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
430 _CustomListImpl::IsItemEnabled(int index) const
432 return GetCore().IsItemEnabled(0, index);
436 _CustomListImpl::SetItemChecked(int groupIndex, int itemIndex, bool check)
438 return SetItemChecked(itemIndex, check);
442 _CustomListImpl::SetItemChecked(int index, bool check)
444 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), E_SYSTEM, "[E_SYSTEM] A system error has occurred. The index %d is invalid.", index);
446 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");
448 if (IsItemChecked(index) == check)
453 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);
455 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
459 if (_currentRadioIndex != -1)
461 _CheckElementModel* pOldCheckElementModel = GetCheckElementAt(-1, _currentRadioIndex);
462 SysTryReturnResult(NID_UI_CTRL, pOldCheckElementModel, E_SYSTEM, "A system error has occurred. tableViewItem is not constructed correctly.");
464 pOldCheckElementModel->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
466 _TableViewItemData* pOldRadioItem = GetTableViewItemAt(-1, _currentRadioIndex);
467 SysTryReturnResult(NID_UI_CTRL, pOldRadioItem, E_SYSTEM, "A system error has occurred. Failed to get item at %d index.", _currentRadioIndex);
469 pOldRadioItem->Invalidate(true);
471 _currentRadioIndex = index;
475 _currentRadioIndex = -1;
479 _CheckElementModel* pCheckElementModel = GetCheckElementAt(-1, index);
480 SysTryReturnResult(NID_UI_CTRL, pCheckElementModel, E_SYSTEM, "A system error has occurred. TableViewItem is not constructed correctly.");
482 pCheckElementModel->SetCheckBoxStatus((_CheckBoxBitmapType)check);
490 _CustomListImpl::IsItemChecked(int groupIndex, int subIndex) const
492 return IsItemChecked(subIndex);
496 _CustomListImpl::IsItemChecked(int index) const
498 SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL),
499 false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. list style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL.");
501 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
502 false, E_INVALID_ARG, "[E_INVALID_ARG] The index %d is invalid.", index);
504 const _CheckElementModel* pCheckElement = GetCheckElementAt(-1, index);
505 SysTryReturn(NID_UI_CTRL, pCheckElement, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. CheckElement is not constructed properly.");
507 return (bool)pCheckElement->GetCheckBoxStatus();
511 _CustomListImpl::SetAllItemsChecked(bool check)
513 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");
514 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");
516 _CheckElementModel* pCheckElement = null;
518 for (int index = 0; index < GetItemCount(); index++)
520 if (IsItemEnabled(index))
522 pCheckElement = GetCheckElementAt(-1, index);
523 SysTryReturnResult(NID_UI_CTRL, (pCheckElement != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Checkbox element not created");
525 pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
535 _CustomListImpl::RemoveAllCheckedItems(void)
537 result r = E_SUCCESS;
538 result finalResult = E_SUCCESS;
540 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");
541 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");
543 for (int index = GetItemCount() -1; index >= 0; index--)
545 if (IsItemChecked(index))
547 r = RemoveItemAt(index);
552 SysLog(NID_UI_CTRL, "Item at %d index not removed successfully.", index);
561 _CustomListImpl::GetFirstCheckedItemIndex(void) const
563 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");
565 for (int index = 0; index < GetItemCount(); index++)
567 if (IsItemChecked(index))
569 SetLastResult(E_SUCCESS);
573 SetLastResult(E_SUCCESS);
574 return INVALID_INDEX;
578 _CustomListImpl::GetLastCheckedItemIndex(void) const
580 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");
582 for (int index = GetItemCount() - 1; index >= 0; index--)
584 if (IsItemChecked(index))
586 SetLastResult(E_SUCCESS);
590 SetLastResult(E_SUCCESS);
591 return INVALID_INDEX;
595 _CustomListImpl::GetNextCheckedItemIndexAfter(int index) const
597 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");
599 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
600 INVALID_INDEX, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The index %d is invalid.", index);
602 for (int itemCount = index + 1; itemCount < GetItemCount(); itemCount++)
604 if (IsItemChecked(itemCount))
606 SetLastResult(E_SUCCESS);
610 SetLastResult(E_SUCCESS);
611 return INVALID_INDEX;
615 _CustomListImpl::GetItemIndexFromItemId(int itemId) const
617 for (int index = 0; index < GetItemCount(); index++)
619 const CustomListItem* pCustomListItem = GetCustomListItemAt(-1, index);
620 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);
622 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);
624 if (pCustomListItem->__pCustomListItemImpl->itemId == itemId)
626 SetLastResult(E_SUCCESS);
630 SetLastResult(E_SUCCESS);
631 return INVALID_INDEX;
635 _CustomListImpl::ScrollToBottom(void)
637 GetCore().SetBottomDrawnItemIndex(0 ,GetItemCount() - 1);
642 _CustomListImpl::ScrollToTop(void)
644 GetCore().SetTopDrawnItemIndex(0,0);
650 _CustomListImpl::ScrollToTop(int index)
652 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), E_INVALID_ARG, "Invalid index(%d).", index);
654 result r = GetCore().SetTopDrawnItemIndex(0, index);
655 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
663 _CustomListImpl::RefreshItem(int index)
665 SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), E_INVALID_ARG, "Invalid index(%d).", index);
667 int topItemIndex = -1;
668 int bottomItemIndex = -1;
671 GetCore().GetTopDrawnItemIndex(groupIndex, topItemIndex);
672 GetCore().GetBottomDrawnItemIndex(groupIndex, bottomItemIndex);
674 SysTryReturnResult(NID_UI_CTRL, (index >= topItemIndex && index <= bottomItemIndex), E_INVALID_OPERATION,
675 "Index should be within drawn item range %d.", index);
677 result r = E_SUCCESS;
679 _TableViewItemUpdateParams updateParams;
680 updateParams.pItem = GetCustomListItemAt(-1, index);
681 updateParams.isDividerEnabled = _isDividerEnabled;
682 updateParams.pCheckBitmaps = _pCheckBitmaps;
683 updateParams.annexStyle = _annexStyle;
685 r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
686 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to refresh an item.");
694 _CustomListImpl::GetItemIdAt(int index) const
696 SysTryReturn(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
697 -1, E_INVALID_ARG, "[E_INVALID_ARG] The index %d is invalid.", index);
699 const CustomListItem* pCustomListItem = GetCustomListItemAt(-1, index);
700 SysTryReturn(NID_UI_CTRL, pCustomListItem, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", index);
702 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);
704 SetLastResult(E_SUCCESS);
705 return pCustomListItem->__pCustomListItemImpl->itemId;
709 _CustomListImpl::OnTableViewItemStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
711 ItemStatus itemStatus = ITEM_HIGHLIGHTED;
715 case TABLE_VIEW_ITEM_STATUS_SELECTED:
716 itemStatus = ITEM_SELECTED;
718 case TABLE_VIEW_ITEM_STATUS_HIGHLIGHTED:
719 itemStatus = ITEM_HIGHLIGHTED;
721 case TABLE_VIEW_ITEM_STATUS_CHECKED:
722 itemStatus = ITEM_CHECKED;
724 case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
725 itemStatus = ITEM_UNCHECKED;
728 SetLastResult(E_SYSTEM);
732 if ((!_isDividerEnabled) && (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL))
734 bool isChecked = IsItemChecked(itemIndex);
738 itemStatus = ITEM_UNCHECKED;
742 itemStatus = ITEM_CHECKED;
745 SetItemChecked(itemIndex, !isChecked);
748 ProcessItemStateChange(-1, itemIndex, itemStatus);
753 _CustomListImpl::OnTableViewContextItemActivationStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pContextItem, bool activated)
759 _CustomListImpl::OnTableViewItemReordered(_TableView& tableView, int itemIndexFrom, int itemIndexTo)
765 _CustomListImpl::OnGroupedTableViewGroupItemStateChanged(_TableView& tableView, int groupIndex, _TableViewItem* pItem, TableViewItemStatus status)
771 _CustomListImpl::OnGroupedTableViewItemStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
777 _CustomListImpl::OnGroupedTableViewContextItemActivationStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
783 _CustomListImpl::OnGroupedTableViewItemReordered(_TableView& tableView, int groupIndexFrom, int itemIndexFrom, int groupIndexTo, int itemIndexTo)
789 _CustomListImpl::OnSectionTableViewItemStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
795 _CustomListImpl::OnSectionTableViewContextItemActivationStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
801 _CustomListImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
807 _CustomListImpl::ProcessItemStateChange(int groupIndex, int index, int elementId, ItemStatus itemStatus)
809 int itemId = GetItemIdAt(index);
811 _ListListener* pListenerList = null;
812 ICustomItemEventListener* pEventListener = null;
814 int count = __itemListenersList.GetCount();
815 for (int listenerCount = 0; listenerCount < count; listenerCount++)
817 pListenerList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
818 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerList != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
820 pEventListener = dynamic_cast<ICustomItemEventListener*>(pListenerList->pListener);
821 SysTryReturnVoidResult(NID_UI_CTRL, (pEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
823 pEventListener->OnItemStateChanged(GetPublic(), index, itemId, elementId, itemStatus);
825 SetLastResult(E_SUCCESS);
831 _CustomListImpl::ProcessItemStateChange(int groupIndex, int index, ItemStatus itemStatus)
833 int itemId = GetItemIdAt(index);
835 _ListListener* pListenerList = null;
836 ICustomItemEventListener* pEventListener = null;
838 int count = __itemListenersList.GetCount();
839 for (int listenerCount = 0; listenerCount < count; listenerCount++)
841 pListenerList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
842 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerList != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
844 pEventListener = dynamic_cast<ICustomItemEventListener*>(pListenerList->pListener);
845 SysTryReturnVoidResult(NID_UI_CTRL, (pEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
847 pEventListener->OnItemStateChanged(GetPublic(), index, itemId, itemStatus);
849 SetLastResult(E_SUCCESS);
854 class _CustomListMaker
855 : public _UiBuilderControlMaker
858 _CustomListMaker(_UiBuilder* uibuilder)
859 : _UiBuilderControlMaker(uibuilder){};
860 virtual ~_CustomListMaker(){};
861 static _UiBuilderControlMaker*
862 GetInstance(_UiBuilder* uibuilder)
864 _CustomListMaker* pCustomListMaker = new (std::nothrow) _CustomListMaker(uibuilder);
865 return pCustomListMaker;
869 Make(_UiBuilderControl* pControl)
872 _UiBuilderControlLayout* pControlProperty = null;
873 CustomList* pCustomList = null;
875 Tizen::Base::String elementString;
879 CustomListStyle style = CUSTOM_LIST_STYLE_NORMAL;
880 bool isItemDivider = true;
882 GetProperty(pControl, &pControlProperty);
884 if (pControlProperty == null)
889 pCustomList = new (std::nothrow) CustomList();
890 if (pCustomList == null)
895 rect = pControlProperty->GetRect();
897 Tizen::Base::String styleString;
898 styleString = pControlProperty->GetStyle();
900 if (styleString.Equals(L"CUSTOM_LIST_STYLE_NORMAL", false))
902 style = CUSTOM_LIST_STYLE_NORMAL;
904 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO", false))
906 style = CUSTOM_LIST_STYLE_RADIO;
908 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER", false))
910 style = CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER;
912 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK", false))
914 style = CUSTOM_LIST_STYLE_MARK;
916 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER", false))
918 style = CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER;
920 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF", false))
922 style = CUSTOM_LIST_STYLE_ONOFF;
924 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER", false))
926 style = CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER;
930 style = CUSTOM_LIST_STYLE_NORMAL;
934 if (pControl->GetElement(L"itemDivider", elementString))
936 if (elementString.Equals(L"true", false))
938 isItemDivider = true;
942 isItemDivider = false;
946 r = pCustomList->Construct(rect, style, isItemDivider);
953 if (pControl->GetElement(L"textOfEmptyList", elementString))
955 pCustomList->SetTextOfEmptyList(elementString);
958 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
960 ConvertStringToColor(elementString, color);
961 pCustomList->SetTextColorOfEmptyList(color);
969 _CustomListRegister::_CustomListRegister(void)
971 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
973 if (pUiBuilderControlTableManager)
975 pUiBuilderControlTableManager->RegisterControl(L"CustomList", _CustomListMaker::GetInstance);
978 _CustomListRegister::~_CustomListRegister(void)
980 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
982 if (pUiBuilderControlTableManager)
984 pUiBuilderControlTableManager->UnregisterControl(L"CustomList");
987 static _CustomListRegister CustomListRegisterToUiBuilder;
988 }}} //Tizen::Ui::Controls