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_ListBaseImpl.cpp
20 * @brief This file contains implementation of common classes used by 1.x Lists
23 #include <FGrpBitmap.h>
24 #include <FBaseSysLog.h>
25 #include <FGrp_TextTextSimple.h>
26 #include "FUiCtrl_ListBaseImpl.h"
27 #include "FUiCtrl_CustomListElements.h"
28 #include "FUiCtrl_CustomListItemImpl.h"
29 #include "FUiCtrl_Label.h"
30 #include "FUi_CoordinateSystemUtils.h"
31 #include "FGrp_BitmapImpl.h"
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Base;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Graphics::_Text;
38 namespace Tizen { namespace Ui { namespace Controls
41 _ListBaseImpl::_ListBaseImpl(Control* pList, _TableView* pCore)
42 : _ControlImpl(pList, pCore)
43 , _annexStyle(TABLE_VIEW_ANNEX_STYLE_NORMAL)
44 , _currentRadioIndex(-1)
45 , _currentRadioGroupIndex(-1)
46 , _isDividerEnabled(false)
47 , _itemsList(_CustomListItemImpl::DeleteCustomListItem)
50 GET_SHAPE_CONFIG(LIST::LIST_DEFAULT_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, _defaultItemHeight);
51 GET_COLOR_CONFIG(TABLEVIEW::EMPTY_CONTENTS_TEXT_NORMAL, __emptyTextColor);
53 for (int i = 0; i < CHECK_BOX_MAX; i++)
55 _pCheckBitmaps[i] = null;
60 _ListBaseImpl::~_ListBaseImpl(void)
62 for (int i = 0; i < CHECK_BOX_MAX; i++)
64 delete _pCheckBitmaps[i];
67 _TableView* pCore = static_cast<_TableView*>(&GetCore());
68 SysTryReturnVoidResult(NID_UI_CTRL, (pCore != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get _TableView core object.");
70 pCore->DetachAllChildren();
74 _ListBaseImpl::CreateMergedBitmapN(Bitmap& pNormalBitmap, Bitmap* pSelectedBitmap)
76 Bitmap* pMergeBitmap = null;
77 Canvas* pCanvas = null;
79 Rectangle bitmapBounds;
82 bitmapBounds = Rectangle(0, 0, pNormalBitmap.GetWidth(), pNormalBitmap.GetHeight());
84 pCanvas = new (std::nothrow) Canvas();
85 SysTryReturn(NID_UI_CTRL, pCanvas != null, null, E_OUT_OF_MEMORY, "Memory allocation failed.");
87 pCanvas->Construct(bitmapBounds);
88 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
91 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(pNormalBitmap))
93 pCanvas->DrawNinePatchedBitmap(bitmapBounds, pNormalBitmap);
97 pCanvas->DrawBitmap(bitmapBounds, pNormalBitmap);
100 if (pSelectedBitmap != null)
102 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*pSelectedBitmap))
104 pCanvas->DrawNinePatchedBitmap(bitmapBounds, *pSelectedBitmap);
108 pCanvas->DrawBitmap(bitmapBounds, *pSelectedBitmap);
112 pMergeBitmap = new (std::nothrow) Bitmap();
113 SysTryCatch(NID_UI_CTRL, pMergeBitmap != null, , E_OUT_OF_MEMORY, "Memory allocation failed.");
115 r = pMergeBitmap->Construct(*pCanvas, bitmapBounds);
116 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "A system error has occurred. Failed to construct an item.");
131 _ListBaseImpl::CreateOnOffMergedBitmapN(Bitmap& pNormalBitmap, Bitmap& pSelectedBitmap, _CheckBoxBitmapType status)
133 Bitmap* pMergeBitmap = null;
134 Canvas* pCanvas = null;
136 Rectangle bitmapBounds;
137 Rectangle handlerBounds;
138 result r = E_SUCCESS;
140 bitmapBounds = Rectangle(0, 0, pNormalBitmap.GetWidth(), pNormalBitmap.GetHeight());
142 if (status == CHECK_BOX_UNCHECKED)
144 handlerBounds = Rectangle(0, 0, pSelectedBitmap.GetWidth(), pSelectedBitmap.GetHeight());
148 handlerBounds.x = pNormalBitmap.GetWidth() - pSelectedBitmap.GetWidth();
150 handlerBounds.width = pSelectedBitmap.GetWidth();
151 handlerBounds.height = pSelectedBitmap.GetHeight();
154 pCanvas = new (std::nothrow) Canvas();
155 SysTryReturn(NID_UI_CTRL, pCanvas != null, null, E_OUT_OF_MEMORY, "Memory allocation failed.");
157 pCanvas->Construct(bitmapBounds);
158 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
161 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(pNormalBitmap))
163 pCanvas->DrawNinePatchedBitmap(bitmapBounds, pNormalBitmap);
167 pCanvas->DrawBitmap(bitmapBounds, pNormalBitmap);
170 if(_BitmapImpl::CheckNinePatchedBitmapStrictly(pSelectedBitmap))
172 pCanvas->DrawNinePatchedBitmap(handlerBounds, pSelectedBitmap);
176 pCanvas->DrawBitmap(handlerBounds, pSelectedBitmap);
179 pMergeBitmap = new (std::nothrow) Bitmap();
180 SysTryCatch(NID_UI_CTRL, pMergeBitmap != null, , E_OUT_OF_MEMORY, "Memory allocation failed.");
182 r = pMergeBitmap->Construct(*pCanvas, bitmapBounds);
183 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "A system error has occurred. Failed to construct an item.");
196 _ListBaseImpl::LoadDefaultBitmap(void)
198 Bitmap* pNormalBitmap = null;
199 Bitmap* pSelectedBitmap = null;
200 Bitmap* pHandlerBitmap = null;
201 Bitmap* pDisabledNormalBitmap = null;
202 Bitmap* pDisabledSelectedBitmap = null;
203 Bitmap* pDisabledHandlerBitmap = null;
204 Bitmap* pPressedBitmap = null;
206 result r = E_SUCCESS;
208 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
210 r = GET_BITMAP_CONFIG_N(TABLEVIEW::RADIOBUTTON_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pNormalBitmap);
211 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, GetErrorMessage(r), "[%s] Propagating.", GetErrorMessage(r));
213 _pCheckBitmaps[BITMAP_UNCHECKED] = CreateMergedBitmapN(*pNormalBitmap, pSelectedBitmap);
215 r = GET_BITMAP_CONFIG_N(TABLEVIEW::RADIOBUTTON_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pPressedBitmap);
216 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
218 _pCheckBitmaps[BITMAP_UNCHECKED_PRESSED] = CreateMergedBitmapN(*pPressedBitmap, pSelectedBitmap);
220 r = GET_BITMAP_CONFIG_N(TABLEVIEW::RADIOBUTTON_BUTTON_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pSelectedBitmap);
221 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
223 _pCheckBitmaps[BITMAP_CHECKED] = CreateMergedBitmapN(*pNormalBitmap, pSelectedBitmap);
225 _pCheckBitmaps[BITMAP_CHECKED_PRESSED] = CreateMergedBitmapN(*pPressedBitmap, pSelectedBitmap);
227 r = GET_BITMAP_CONFIG_N(TABLEVIEW::RADIOBUTTON_NORMAL_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisabledNormalBitmap);
228 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
230 r = GET_BITMAP_CONFIG_N(TABLEVIEW::RADIOBUTTON_BUTTON_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pSelectedBitmap);
231 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
233 _pCheckBitmaps[BITMAP_CHECKED_DISABLED] = CreateMergedBitmapN(*pDisabledNormalBitmap, pSelectedBitmap);
235 else if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING || _annexStyle == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING_WITH_DIVIDER)
237 r = GET_BITMAP_CONFIG_N(TABLEVIEW::ONOFFBUTTON_OFF_HANDLER, BITMAP_PIXEL_FORMAT_ARGB8888, pHandlerBitmap);
238 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, GetErrorMessage(r), "[%s] Propagating.", GetErrorMessage(r));
240 r = GET_BITMAP_CONFIG_N(TABLEVIEW::ONOFFBUTTON_BG, BITMAP_PIXEL_FORMAT_ARGB8888, pNormalBitmap);
241 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
243 _pCheckBitmaps[BITMAP_UNCHECKED] = CreateOnOffMergedBitmapN(*pNormalBitmap, *pHandlerBitmap, CHECK_BOX_UNCHECKED);
245 delete pHandlerBitmap;
246 pHandlerBitmap = null;
248 r = GET_BITMAP_CONFIG_N(TABLEVIEW::ONOFFBUTTON_ON_HANDLER, BITMAP_PIXEL_FORMAT_ARGB8888, pHandlerBitmap);
249 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
252 _pCheckBitmaps[BITMAP_CHECKED] = CreateOnOffMergedBitmapN(*pNormalBitmap, *pHandlerBitmap, CHECK_BOX_CHECKED);
254 r = GET_BITMAP_CONFIG_N(TABLEVIEW::ONOFFBUTTON_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisabledNormalBitmap);
255 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
257 r = GET_BITMAP_CONFIG_N(TABLEVIEW::ONOFFBUTTON_ON_HANDLER_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisabledHandlerBitmap);
258 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
260 _pCheckBitmaps[BITMAP_CHECKED_DISABLED] = CreateOnOffMergedBitmapN(*pDisabledNormalBitmap, *pDisabledHandlerBitmap, CHECK_BOX_CHECKED);
262 delete pDisabledHandlerBitmap;
263 pDisabledHandlerBitmap = null;
265 r = GET_BITMAP_CONFIG_N(TABLEVIEW::ONOFFBUTTON_OFF_HANDLER_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisabledHandlerBitmap);
266 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
268 _pCheckBitmaps[BITMAP_UNCHECKED_DISABLED] = CreateOnOffMergedBitmapN(*pDisabledNormalBitmap, *pDisabledHandlerBitmap, CHECK_BOX_UNCHECKED);
272 r = GET_BITMAP_CONFIG_N(TABLEVIEW::CHECKBOX_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pNormalBitmap);
273 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, GetErrorMessage(r), "[%s] Propagating.", GetErrorMessage(r));
275 _pCheckBitmaps[BITMAP_UNCHECKED] = CreateMergedBitmapN(*pNormalBitmap, pSelectedBitmap);
277 r = GET_BITMAP_CONFIG_N(TABLEVIEW::CHECKBOX_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pPressedBitmap);
278 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
280 _pCheckBitmaps[BITMAP_UNCHECKED_PRESSED] = CreateMergedBitmapN(*pPressedBitmap, pSelectedBitmap);
282 r = GET_BITMAP_CONFIG_N(TABLEVIEW::CHECKBOX_CHECK_MARK_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pSelectedBitmap);
283 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
285 _pCheckBitmaps[BITMAP_CHECKED] = CreateMergedBitmapN(*pNormalBitmap, pSelectedBitmap);
287 delete pSelectedBitmap;
288 pSelectedBitmap = null;
290 r = GET_BITMAP_CONFIG_N(TABLEVIEW::CHECKBOX_CHECK_MARK_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, pSelectedBitmap);
291 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
293 _pCheckBitmaps[BITMAP_CHECKED_PRESSED] = CreateMergedBitmapN(*pPressedBitmap, pSelectedBitmap);
295 r = GET_BITMAP_CONFIG_N(TABLEVIEW::CHECKBOX_BG_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisabledNormalBitmap);
296 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
298 r = GET_BITMAP_CONFIG_N(TABLEVIEW::CHECKBOX_CHECK_MARK_DISABLED, BITMAP_PIXEL_FORMAT_ARGB8888, pDisabledSelectedBitmap);
299 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
301 _pCheckBitmaps[BITMAP_CHECKED_DISABLED] = CreateMergedBitmapN(*pDisabledNormalBitmap, pDisabledSelectedBitmap);
304 delete pNormalBitmap;
305 delete pSelectedBitmap;
306 delete pHandlerBitmap;
307 delete pDisabledNormalBitmap;
308 delete pDisabledSelectedBitmap;
309 delete pDisabledHandlerBitmap;
310 delete pPressedBitmap;
315 delete pNormalBitmap;
316 delete pSelectedBitmap;
317 delete pHandlerBitmap;
318 delete pDisabledNormalBitmap;
319 delete pDisabledSelectedBitmap;
320 delete pDisabledHandlerBitmap;
321 delete pPressedBitmap;
327 Tizen::Ui::Controls::TableViewAnnexStyle
328 _ListBaseImpl::GetAnnexStyle(void)
333 Tizen::Graphics::Bitmap**
334 _ListBaseImpl::GetCheckBitmaps(void)
336 return _pCheckBitmaps;
340 _ListBaseImpl::SetItemChecked(int groupIndex, int itemIndex, bool check)
346 _ListBaseImpl::IsItemChecked(int groupIndex, int itemIndex) const
352 _ListBaseImpl::OnTouchDoublePressed(const Control &source, const Point ¤tPosition, const TouchEventInfo &touchInfo)
358 _ListBaseImpl::OnTouchFocusIn(const Control &source, const Point ¤tPosition, const TouchEventInfo &touchInfo)
364 _ListBaseImpl::OnTouchFocusOut(const Control &source, const Point ¤tPosition, const TouchEventInfo &touchInfo)
366 OnTouchReleased(source, currentPosition, touchInfo);
371 _ListBaseImpl::OnTouchLongPressed(const Control &source, const Point ¤tPosition, const TouchEventInfo &touchInfo)
377 _ListBaseImpl::OnTouchMoved(const Control &source, const Point ¤tPosition, const TouchEventInfo &touchInfo)
383 _ListBaseImpl::OnTouchPressed(const Control &source, const Point ¤tPosition, const TouchEventInfo &touchInfo)
385 CustomListItem* pCustomListItem = GetItemFromControl(source);
386 SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item");
388 pCustomListItem->__pCustomListItemImpl->StartSliding();
390 UpdateElements(source, CUSTOM_LIST_ITEM_STATUS_FOCUSED);
395 _ListBaseImpl::OnTouchReleased(const Control &source, const Point ¤tPosition, const TouchEventInfo &touchInfo)
397 CustomListItem* pCustomListItem = GetItemFromControl(source);
398 SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item");
400 pCustomListItem->__pCustomListItemImpl->StopSliding();
402 UpdateElements(source, CUSTOM_LIST_ITEM_STATUS_NORMAL);
407 _ListBaseImpl::GetItemFromControl(const Control &source)
409 _ITableViewBaseItemData* pBaseData = dynamic_cast<_ITableViewBaseItemData*>(const_cast<Control*>(&source));
410 SysTryReturn(NID_UI_CTRL, (pBaseData != null), null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get item.");
415 pBaseData->GetIndex(groupIndex, itemIndex);
417 return GetCustomListItemAt(groupIndex, itemIndex- GetTopItemIndex(groupIndex));
421 _ListBaseImpl::UpdateElements(const Control &source, CustomListItemStatus itemStatus)
423 _ITableViewBaseItemData* pBaseData = dynamic_cast<_ITableViewBaseItemData*>(const_cast<Control*>(&source));
424 SysTryReturnVoidResult(NID_UI_CTRL, (pBaseData != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get item.");
429 pBaseData->GetIndex(groupIndex, itemIndex);
431 CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, itemIndex - GetTopItemIndex(groupIndex));
432 SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item");
434 LinkedList* pElements = &pCustomListItem->__pCustomListItemImpl->elements;
436 int elementCount = pElements->GetCount();
437 for (int i = 0; i < elementCount; i++)
439 _ElementBaseModel* pElementBase = dynamic_cast<_ElementBaseModel*>(pElements->GetAt(i));
440 SysTryReturnVoidResult(NID_UI_CTRL, (pElementBase != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get element.");
442 if (pElementBase->_elementType != LIST_ITEM_ELEMENT_TYPE_CHECKBOX)
444 pElementBase->HandleElementEvent(itemStatus);
448 DrawItem(groupIndex, itemIndex);
452 _ListBaseImpl::GetTopItemIndex(int groupIndex) const
458 _ListBaseImpl::IsItemNew(const CustomListItem& item) const
460 for (int itemCount = 0; itemCount < _itemsList.GetCount(); itemCount++)
462 CustomListItem* pCustomListItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(_itemsList.GetAt(itemCount)));
463 SysTryReturnResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM,
464 "A system error has occurred. Failed to get CustomList item at index %d.", itemCount);
466 _CustomListItemImpl* pCustomListItemImpl = pCustomListItem->__pCustomListItemImpl;
467 SysTryReturnResult(NID_UI_CTRL, pCustomListItemImpl, E_SYSTEM, "A system error has occurred. Failed to get an item at index(%d)", itemCount);
469 if ((pCustomListItem == const_cast<CustomListItem*>(&item)) && (pCustomListItemImpl->itemId == item.__pCustomListItemImpl->itemId))
474 for (int subItemCount = 0; subItemCount < GetSubItemCountAt(itemCount); subItemCount++)
476 CustomListItem* pCustomListItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(pCustomListItemImpl->__pSubItemsList->GetAt(subItemCount)));
477 SysTryReturnResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM,
478 "A system error has occurred. Failed to get CustomList item at index %d.", itemCount);
480 if ((pCustomListItem == const_cast<CustomListItem*>(&item)) && (pCustomListItem->__pCustomListItemImpl->itemId == item.__pCustomListItemImpl->itemId))
491 _ListBaseImpl::UpdateIndices(int groupIndex, int itemIndex, int updateBy)
500 index = itemIndex + 1;
503 if (groupIndex == -1)
505 for (; index < _itemsList.GetCount(); index++)
507 _TableViewItemData* pTableViewItemData = GetTableViewItemAt(-1, index);
509 if (pTableViewItemData)
511 pTableViewItemData->itemIndex += updateBy;
515 if (_currentRadioIndex >= itemIndex)
517 _currentRadioIndex += updateBy;
520 else if (itemIndex == -1)
522 for (int index = groupIndex; index < _itemsList.GetCount(); index++)
524 _TableViewGroupItemData* pGroupItem = GetTableViewGroupItemAt(index);
528 pGroupItem->groupIndex += updateBy;
532 if (_currentRadioGroupIndex >= groupIndex)
534 _currentRadioGroupIndex += updateBy;
539 int subItemCount = GetSubItemCountAt(groupIndex);
541 for (; index < subItemCount; index++)
543 _TableViewItemData* pTableViewItemData = GetTableViewItemAt(groupIndex, index);
545 if (pTableViewItemData)
547 pTableViewItemData->itemIndex += updateBy;
551 if (_currentRadioIndex >= itemIndex)
553 _currentRadioIndex += updateBy;
561 _ListBaseImpl::InsertIntoItemsList(const CustomListItem& item, int groupIndex, int itemIndex, bool updateIndices)
563 result r = E_SUCCESS;
565 if (GetCore().GetFirstDrawnFlag() == true)
567 updateIndices = false;
570 if (groupIndex == -1)
572 r = _itemsList.InsertAt(item, itemIndex);
573 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
575 else if (itemIndex == -1)
577 r = _itemsList.InsertAt(item, groupIndex);
578 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to insert an item.");
582 CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, -1);
583 SysTryReturnResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "A system error has occurred. Failed to get item at %d index.", groupIndex);
585 if (pCustomListItem->__pCustomListItemImpl->__pSubItemsList == null)
587 pCustomListItem->__pCustomListItemImpl->__pSubItemsList = new (std::nothrow) ArrayList(_CustomListItemImpl::DeleteCustomListItem);
588 SysTryReturnResult(NID_UI_CTRL, pCustomListItem->__pCustomListItemImpl->__pSubItemsList, E_OUT_OF_MEMORY, "Memory allocation failed.");
590 pCustomListItem->__pCustomListItemImpl->__pSubItemsList->Construct(1);
593 pCustomListItem->__pCustomListItemImpl->__pSubItemsList->InsertAt(item, itemIndex);
598 return UpdateIndices(groupIndex, itemIndex, 1);
607 _ListBaseImpl::RemoveFromItemsList(int groupIndex, int itemIndex, bool updateIndices)
609 result r = E_SUCCESS;
611 if (GetCore().GetFirstDrawnFlag() == true)
613 updateIndices = false;
616 if (groupIndex == -1)
618 r = _itemsList.RemoveAt(itemIndex, true);
619 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "A system error has occurred. Failed to remove an item.");
621 else if (itemIndex == -1)
623 r = _itemsList.RemoveAt(groupIndex, true);
624 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to remove an item.");
628 CustomListItem* pCustomListGroupItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(_itemsList.GetAt(groupIndex)));
629 SysTryReturnResult(NID_UI_CTRL, pCustomListGroupItem, E_SYSTEM, "A system error has occurred. Failed to get an item at groupIndex(%d)", groupIndex);
631 ArrayList* pList = pCustomListGroupItem->__pCustomListItemImpl->__pSubItemsList;
632 SysTryReturnResult(NID_UI_CTRL, pList, E_SYSTEM, "A system error has occurred. Failed to get subItem at groupIndex(%d) itemIndex(%d)", groupIndex, itemIndex);
634 r = pList->RemoveAt(itemIndex, true);
635 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "A system error has occurred. Failed to remove an item.");
640 return UpdateIndices(groupIndex, itemIndex, -1);
650 _ListBaseImpl::SetInItemsList(const CustomListItem& item, int groupIndex, int itemIndex)
652 result r = E_SUCCESS;
654 if (groupIndex == -1)
656 r = _itemsList.SetAt(item, itemIndex, true);
657 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "A system error has occurred. Failed to remove an item.");
659 else if (itemIndex == -1)
661 CustomListItem* pOldItem = GetCustomListItemAt(groupIndex, -1);
662 SysTryReturnResult(NID_UI_CTRL, pOldItem, E_SYSTEM, "A system error has occurred. Failed to get current item.");
664 item.__pCustomListItemImpl->__pTableViewGroupItemData = pOldItem->__pCustomListItemImpl->__pTableViewGroupItemData;
665 item.__pCustomListItemImpl->__pSubItemsList = pOldItem->__pCustomListItemImpl->__pSubItemsList;
667 r = _itemsList.SetAt(item, groupIndex, true);
668 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to remove an item.");
672 CustomListItem* pCustomListGroupItem = GetCustomListItemAt(groupIndex, -1);
673 SysTryReturnResult(NID_UI_CTRL, pCustomListGroupItem, E_SYSTEM, "A system error has occurred. Failed to get GroupItem at %d index.", groupIndex);
675 ArrayList* pList = pCustomListGroupItem->__pCustomListItemImpl->__pSubItemsList;
676 SysTryReturnResult(NID_UI_CTRL, pList, E_SYSTEM, "A system error has occurred. Failed to get subItem at groupIndex(%d) itemIndex(%d)", groupIndex, itemIndex);
678 pList->SetAt(item, itemIndex, true);
685 _ListBaseImpl::RemoveAllFromItemsList(void)
687 _itemsList.RemoveAll(true);
691 _ListBaseImpl::GetCustomListItemAt(int groupIndex, int itemIndex)
693 const CustomListItem* pItem = (static_cast<const _ListBaseImpl*>(this))->GetCustomListItemAt(groupIndex, itemIndex);
694 return const_cast<CustomListItem*>(pItem);
697 const CustomListItem*
698 _ListBaseImpl::GetCustomListItemAt(int groupIndex, int itemIndex) const
700 if (groupIndex == -1)
702 CustomListItem* pCustomListItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(_itemsList.GetAt(itemIndex)));
703 SysTryReturn(NID_UI_CTRL, pCustomListItem, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d", itemIndex);
705 return pCustomListItem;
707 else if (itemIndex == -1)
709 CustomListItem* pCustomListItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(_itemsList.GetAt(groupIndex)));
710 SysTryReturn(NID_UI_CTRL, pCustomListItem, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
712 return pCustomListItem;
716 CustomListItem* pCustomListGroupItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(_itemsList.GetAt(groupIndex)));
717 SysTryReturn(NID_UI_CTRL, pCustomListGroupItem, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d)", groupIndex);
719 ArrayList* pList = pCustomListGroupItem->__pCustomListItemImpl->__pSubItemsList;
720 SysTryReturn(NID_UI_CTRL, pList, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get subItem at groupIndex(%d) itemIndex(%d)", groupIndex, itemIndex);
722 CustomListItem* pCustomListItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(pList->GetAt(itemIndex)));
723 SysTryReturn(NID_UI_CTRL, pCustomListItem, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d) itemIndex(%d)", groupIndex, itemIndex);
725 return pCustomListItem;
730 _ListBaseImpl::GetTableViewItemAt(int groupIndex, int itemIndex)
732 const _TableViewItemData* pTableViewItemData = (static_cast<const _ListBaseImpl*>(this))->GetTableViewItemAt(groupIndex, itemIndex);
733 return const_cast<_TableViewItemData*>(pTableViewItemData);
736 const _TableViewItemData*
737 _ListBaseImpl::GetTableViewItemAt(int groupIndex, int itemIndex) const
739 const CustomListItem* pCustomListGroupItem = (static_cast<const _ListBaseImpl*>(this))->GetCustomListItemAt(groupIndex, itemIndex);
740 SysTryReturn(NID_UI_CTRL, pCustomListGroupItem, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d) itemIndex(%d)", groupIndex, itemIndex);
742 SysTryReturn(NID_UI_CTRL, pCustomListGroupItem->__pCustomListItemImpl, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d) itemIndex(%d)", groupIndex, itemIndex);
744 return pCustomListGroupItem->__pCustomListItemImpl->__pTableViewItemData;
747 _TableViewGroupItemData*
748 _ListBaseImpl::GetTableViewGroupItemAt(int groupIndex)
750 const _TableViewGroupItemData* pTableViewGroupItemData = (static_cast<const _ListBaseImpl*>(this))->GetTableViewGroupItemAt(groupIndex);
751 return const_cast<_TableViewGroupItemData*>(pTableViewGroupItemData);
754 const _TableViewGroupItemData*
755 _ListBaseImpl::GetTableViewGroupItemAt(int groupIndex) const
757 const CustomListItem* pCustomListGroupItem = (static_cast<const _ListBaseImpl*>(this))->GetCustomListItemAt(groupIndex, -1);
758 SysTryReturn(NID_UI_CTRL, pCustomListGroupItem, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d)", groupIndex);
760 SysTryReturn(NID_UI_CTRL, pCustomListGroupItem->__pCustomListItemImpl, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d)", groupIndex);
762 return pCustomListGroupItem->__pCustomListItemImpl->__pTableViewGroupItemData;
766 _ListBaseImpl::GetCheckElementAt(int groupIndex, int itemIndex)
768 const _CheckElementModel* pCheckElementModel = (static_cast<const _ListBaseImpl*>(this))->GetCheckElementAt(groupIndex, itemIndex);
769 return const_cast<_CheckElementModel*>(pCheckElementModel);
772 const _CheckElementModel*
773 _ListBaseImpl::GetCheckElementAt(int groupIndex, int itemIndex) const
775 const CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, itemIndex);
776 SysTryReturn(NID_UI_CTRL, pCustomListItem, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d), itemIndex(%d)", groupIndex, itemIndex);
778 SysTryReturn(NID_UI_CTRL, pCustomListItem->__pCustomListItemImpl, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d), itemIndex(%d)", groupIndex, itemIndex);
780 return pCustomListItem->__pCustomListItemImpl->GetCheckElement();
784 _ListBaseImpl::DrawItem(int groupIndex, int itemIndex)
788 _TableViewGroupItemData* pTableViewGroupItemData = GetTableViewGroupItemAt(groupIndex);
790 if (pTableViewGroupItemData)
792 pTableViewGroupItemData->Invalidate(true);
797 _TableViewItemData* pTableViewItemData = GetTableViewItemAt(groupIndex, itemIndex);
799 if (pTableViewItemData)
801 pTableViewItemData->Invalidate(true);
807 _ListBaseImpl::SetListStyle(CustomListStyle style)
809 result r = E_SUCCESS;
813 case CUSTOM_LIST_STYLE_NORMAL:
814 _annexStyle = TABLE_VIEW_ANNEX_STYLE_NORMAL;
817 case CUSTOM_LIST_STYLE_RADIO:
818 _annexStyle = TABLE_VIEW_ANNEX_STYLE_RADIO;
821 case CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER:
822 _annexStyle = TABLE_VIEW_ANNEX_STYLE_RADIO;
823 _isDividerEnabled = true;
826 case CUSTOM_LIST_STYLE_MARK:
827 _annexStyle = TABLE_VIEW_ANNEX_STYLE_MARK;
830 case CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER:
831 _annexStyle = TABLE_VIEW_ANNEX_STYLE_MARK;
832 _isDividerEnabled = true;
835 case CUSTOM_LIST_STYLE_ONOFF:
836 _annexStyle = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
839 case CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER:
840 _annexStyle = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
841 _isDividerEnabled = true;
845 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument used. style is invalid.");
854 _ListBaseImpl::GetCore(void)
856 return static_cast<_TableView&>(_ControlImpl::GetCore());
860 _ListBaseImpl::GetCore(void) const
862 return static_cast<const _TableView&>(_ControlImpl::GetCore());
866 _ListBaseImpl::SetTextOfEmptyList(const String& text)
870 if (__pEmptyText != null)
872 GetCore().DetachChild(*__pEmptyText);
880 if (__pEmptyText == null)
882 __pEmptyText = _Label::CreateLabelN();
883 SysTryReturnVoidResult(NID_UI_CTRL, (__pEmptyText != null), E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
885 __pEmptyText->SetVisibleState(false);
886 __pEmptyText->SetMargin(0, 0);
888 GetCore().AttachChild(*__pEmptyText);
891 TextObject* pText = new (std::nothrow) TextObject;
892 SysTryReturnVoidResult(NID_UI_CTRL, (pText != null), E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
896 TextSimple* pSimpleText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(text.GetPointer()), text.GetLength());
897 SysTryReturnVoidResult(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
899 pText->AppendElement(*pSimpleText);
902 GET_SHAPE_CONFIG(LIST::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, textSize);
905 font.Construct(GetFont(), FONT_STYLE_PLAIN, textSize);
906 pText->SetFont(&font, 0, pText->GetTextLength());
908 FloatDimension listDimension = GetCore().GetSizeF();
910 pText->SetBounds(FloatRectangle(0.0f, 0.0f, listDimension.width, 1.0f));
913 FloatDimension labelDimension = pText->GetTextExtentF(0, pText->GetTextLength());
914 labelDimension.height = pText->GetTotalHeightF();
916 if (labelDimension.width > listDimension.width)
918 pText->SetBounds(FloatRectangle(0.0f, 0.0f, listDimension.width, 1.0f));
921 float labelHeight = pText->GetTotalHeightF();
923 labelDimension.width = listDimension.width;
924 labelDimension.height = ((listDimension.height < labelHeight) ? listDimension.height : labelHeight);
929 FloatRectangle bounds = GetCore().GetBoundsF();
931 __pEmptyText->SetBounds(FloatRectangle((bounds.width - labelDimension.width)/2.0f, (bounds.height - labelDimension.height)/2.0f, labelDimension.width, labelDimension.height));
932 __pEmptyText->SetBackgroundColor(Color(0, 0, 0, 0));
933 __pEmptyText->SetTextColor(__emptyTextColor);
934 __pEmptyText->SetTextConfig(textSize, LABEL_TEXT_STYLE_NORMAL);
935 __pEmptyText->SetText(text);
942 _ListBaseImpl::SetTextColorOfEmptyList(const Color& color)
944 __emptyTextColor = color;
946 if (__pEmptyText != null)
948 __pEmptyText->SetTextColor(color);
955 _ListBaseImpl::GetTextColorOfEmptyList(void) const
957 return __emptyTextColor;
961 _ListBaseImpl::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
963 result r = GetCore().GetTopDrawnItemIndex(groupIndex, itemIndex);
964 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
970 _ListBaseImpl::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
972 result r = GetCore().GetBottomDrawnItemIndex(groupIndex, itemIndex);
973 SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
979 _ListBaseImpl::GetItemIndexFromPosition(const Point& position, int& groupIndex, int& itemIndex) const
981 return GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
985 _ListBaseImpl::GetItemCount(void) const
987 return _itemsList.GetCount();
991 _ListBaseImpl::GetGroupCount(void) const
993 return _itemsList.GetCount();
997 _ListBaseImpl::GetSubItemCountAt(int groupIndex) const
999 result r = E_SUCCESS;
1001 const CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, -1);
1002 r = GetLastResult();
1003 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), -1, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
1005 ArrayList* pList = pCustomListItem->__pCustomListItemImpl->__pSubItemsList;
1006 SysTryReturn(NID_UI_CTRL, pList, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get subItemsList at groupIndex(%d)", groupIndex);
1008 return pList->GetCount();
1012 _ListBaseImpl::RemoveFromSubItemsList(int groupIndex)
1014 result r = E_SUCCESS;
1016 const CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, -1);
1017 r = GetLastResult();
1018 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1020 ArrayList* pList = pCustomListItem->__pCustomListItemImpl->__pSubItemsList;
1026 pCustomListItem->__pCustomListItemImpl->__pSubItemsList = null;
1033 _ListBaseImpl::OnDraw(void)
1035 _ControlImpl::OnDraw();
1037 bool isEmpty = (GetItemCount() <= 0);
1039 if (__pEmptyText != null)
1041 __pEmptyText->SetVisibleState(isEmpty);
1046 _ListBaseImpl::OnBoundsChanged(void)
1048 GetCore().OnBoundsChanged();
1051 }}} //Tizen::Ui::Controls