Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_ListBaseImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /**
19 * @file         FUiCtrl_ListBaseImpl.cpp
20 * @brief        This file contains implementation of common classes used by 1.x Lists
21 */
22
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
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Base;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Graphics::_Text;
35
36 namespace Tizen { namespace Ui { namespace Controls
37 {
38
39 _ListBaseImpl::_ListBaseImpl(Control* pList, _TableView* pCore)
40         : _ControlImpl(pList, pCore)
41         , _annexStyle(TABLE_VIEW_ANNEX_STYLE_NORMAL)
42         , _currentRadioIndex(-1)
43         , _currentRadioGroupIndex(-1)
44         , _isDividerEnabled(false)
45         , _itemsList(_CustomListItemImpl::DeleteCustomListItem)
46         , __pEmptyText(null)
47 {
48         GET_SHAPE_CONFIG(LIST::LIST_DEFAULT_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, _defaultItemHeight);
49         GET_COLOR_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_NORMAL, __emptyTextColor);
50
51         for (int i = 0; i < CHECK_BOX_MAX; i++)
52         {
53                 _pCheckBitmaps[i] = null;
54         }
55
56 }
57
58 _ListBaseImpl::~_ListBaseImpl(void)
59 {
60         for (int i = 0; i < CHECK_BOX_MAX; i++)
61         {
62                 delete _pCheckBitmaps[i];
63         }
64
65         _TableView* pCore = static_cast<_TableView*>(&GetCore());
66         SysTryReturnVoidResult(NID_UI_CTRL, (pCore != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get _TableView core object.");
67
68         pCore->DetachAllChildren();
69 }
70
71 result
72 _ListBaseImpl::LoadDefaultBitmap(void)
73 {
74         result r = E_SUCCESS;
75
76         if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
77         {
78                 r = GET_BITMAP_CONFIG_N(LIST::BUTTON_RADIO_BITMAP, BITMAP_PIXEL_FORMAT_ARGB8888, _pCheckBitmaps[CHECK_BOX_UNCHECKED]);
79                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
80
81                 r = GET_BITMAP_CONFIG_N(LIST::BUTTON_RADIO_SELECTED_BITMAP, BITMAP_PIXEL_FORMAT_ARGB8888, _pCheckBitmaps[CHECK_BOX_CHECKED]);
82                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
83         }
84         else if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING)
85         {
86                 r = GET_BITMAP_CONFIG_N(LIST::BUTTON_OFF_BITMAP, BITMAP_PIXEL_FORMAT_ARGB8888, _pCheckBitmaps[CHECK_BOX_UNCHECKED]);
87                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
88
89                 r = GET_BITMAP_CONFIG_N(LIST::BUTTON_ON_BITMAP, BITMAP_PIXEL_FORMAT_ARGB8888, _pCheckBitmaps[CHECK_BOX_CHECKED]);
90                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
91         }
92         else
93         {
94                 r = GET_BITMAP_CONFIG_N(LIST::CHECK_BG_BITMAP, BITMAP_PIXEL_FORMAT_ARGB8888, _pCheckBitmaps[CHECK_BOX_UNCHECKED]);
95                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
96
97                 r = GET_BITMAP_CONFIG_N(LIST::CHECK_MARK_BG_BITMAP, BITMAP_PIXEL_FORMAT_ARGB8888, _pCheckBitmaps[CHECK_BOX_CHECKED]);
98                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
99
100                 r = GET_BITMAP_CONFIG_N(LIST::CHECK_DIM_BITMAP, BITMAP_PIXEL_FORMAT_ARGB8888, _pCheckBitmaps[CHECK_BOX_DISABLED]);
101                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
102         }
103
104         return r;
105 }
106
107 Tizen::Graphics::Bitmap**
108 _ListBaseImpl::GetCheckBitmaps(void)
109 {
110         return _pCheckBitmaps;
111 }
112
113 result
114 _ListBaseImpl::SetItemChecked(int groupIndex, int itemIndex, bool check)
115 {
116         return E_SUCCESS;
117 }
118
119 bool
120 _ListBaseImpl::IsItemChecked(int groupIndex, int itemIndex) const
121 {
122         return false;
123 }
124
125 void
126 _ListBaseImpl::OnTouchDoublePressed(const Control &source, const Point &currentPosition, const TouchEventInfo &touchInfo)
127 {
128         return;
129 }
130
131 void
132 _ListBaseImpl::OnTouchFocusIn(const Control &source, const Point &currentPosition, const TouchEventInfo &touchInfo)
133 {
134         return;
135 }
136
137 void
138 _ListBaseImpl::OnTouchFocusOut(const Control &source, const Point &currentPosition, const TouchEventInfo &touchInfo)
139 {
140         OnTouchReleased(source, currentPosition, touchInfo);
141         return;
142 }
143
144 void
145 _ListBaseImpl::OnTouchLongPressed(const Control &source, const Point &currentPosition, const TouchEventInfo &touchInfo)
146 {
147         return;
148 }
149
150 void
151 _ListBaseImpl::OnTouchMoved(const Control &source, const Point &currentPosition, const TouchEventInfo &touchInfo)
152 {
153         return;
154 }
155
156 void
157 _ListBaseImpl::OnTouchPressed(const Control &source, const Point &currentPosition, const TouchEventInfo &touchInfo)
158 {
159         CustomListItem* pCustomListItem = GetItemFromControl(source);
160         SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item");
161
162         pCustomListItem->__pCustomListItemImpl->StartSliding();
163
164     UpdateElements(source, CUSTOM_LIST_ITEM_STATUS_FOCUSED);
165     return;
166 }
167
168 void
169 _ListBaseImpl::OnTouchReleased(const Control &source, const Point &currentPosition, const TouchEventInfo &touchInfo)
170 {
171         CustomListItem* pCustomListItem = GetItemFromControl(source);
172         SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item");
173
174         pCustomListItem->__pCustomListItemImpl->StopSliding();
175
176     UpdateElements(source, CUSTOM_LIST_ITEM_STATUS_NORMAL);
177     return;
178 }
179
180 CustomListItem*
181 _ListBaseImpl::GetItemFromControl(const Control &source)
182 {
183     _ITableViewBaseItemData* pBaseData = dynamic_cast<_ITableViewBaseItemData*>(const_cast<Control*>(&source));
184     SysTryReturn(NID_UI_CTRL, (pBaseData != null), null, E_SYSTEM, "[E_SYSTEM]  A system error has occurred. Failed to get item.");
185
186     int groupIndex = -1;
187     int itemIndex = -1;
188
189     pBaseData->GetIndex(groupIndex, itemIndex);
190
191     return GetCustomListItemAt(groupIndex, itemIndex- GetTopItemIndex(groupIndex));
192 }
193
194 void
195 _ListBaseImpl::UpdateElements(const Control &source, CustomListItemStatus itemStatus)
196 {
197         _ITableViewBaseItemData* pBaseData = dynamic_cast<_ITableViewBaseItemData*>(const_cast<Control*>(&source));
198         SysTryReturnVoidResult(NID_UI_CTRL, (pBaseData != null), E_SYSTEM, "[E_SYSTEM]  A system error has occurred. Failed to get item.");
199
200         int groupIndex = -1;
201         int itemIndex = -1;
202
203         pBaseData->GetIndex(groupIndex, itemIndex);
204
205         CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, itemIndex - GetTopItemIndex(groupIndex));
206         SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item");
207
208         LinkedList* pElements = &pCustomListItem->__pCustomListItemImpl->elements;
209
210         int elementCount = pElements->GetCount();
211         for (int i = 0; i < elementCount; i++)
212         {
213                 _ElementBaseModel* pElementBase = dynamic_cast<_ElementBaseModel*>(pElements->GetAt(i));
214                 SysTryReturnVoidResult(NID_UI_CTRL, (pElementBase != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get element.");
215
216                 if (pElementBase->_elementType != LIST_ITEM_ELEMENT_TYPE_CHECKBOX)
217                 {
218                         pElementBase->HandleElementEvent(itemStatus);
219                 }
220         }
221
222         DrawItem(groupIndex, itemIndex);
223 }
224
225 int
226 _ListBaseImpl::GetTopItemIndex(int groupIndex) const
227 {
228         return 0;
229 }
230
231 bool
232 _ListBaseImpl::IsItemNew(const CustomListItem& item) const
233 {
234         for (int itemCount = 0; itemCount < _itemsList.GetCount(); itemCount++)
235         {
236                 CustomListItem* pCustomListItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(_itemsList.GetAt(itemCount)));
237                 SysTryReturnResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM,
238                                    "A system error has occurred. Failed to get CustomList item at index %d.", itemCount);
239
240                 _CustomListItemImpl* pCustomListItemImpl = pCustomListItem->__pCustomListItemImpl;
241                 SysTryReturnResult(NID_UI_CTRL, pCustomListItemImpl, E_SYSTEM, "A system error has occurred. Failed to get an item at index(%d)", itemCount);
242
243                 if ((pCustomListItem == const_cast<CustomListItem*>(&item)) && (pCustomListItemImpl->itemId == item.__pCustomListItemImpl->itemId))
244                 {
245                         return false;
246                 }
247
248                 for (int subItemCount = 0; subItemCount < GetSubItemCountAt(itemCount); subItemCount++)
249                 {
250                         CustomListItem* pCustomListItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(pCustomListItemImpl->__pSubItemsList->GetAt(subItemCount)));
251                         SysTryReturnResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM,
252                                            "A system error has occurred. Failed to get CustomList item at index %d.", itemCount);
253
254                         if ((pCustomListItem == const_cast<CustomListItem*>(&item)) && (pCustomListItem->__pCustomListItemImpl->itemId == item.__pCustomListItemImpl->itemId))
255                         {
256                                 return false;
257                         }
258                 }
259         }
260
261         return true;
262 }
263
264 result
265 _ListBaseImpl::UpdateIndices(int groupIndex, int itemIndex, int updateBy)
266 {
267         if (groupIndex == -1)
268         {
269                 for (int index = itemIndex; index < _itemsList.GetCount(); index++)
270                 {
271                         _TableViewItemData* pTableViewItemData = GetTableViewItemAt(-1, index);
272
273                         if (pTableViewItemData)
274                         {
275                                 pTableViewItemData->itemIndex += updateBy;
276                         }
277                 }
278
279                 if (_currentRadioIndex >= itemIndex)
280                 {
281                         _currentRadioIndex += updateBy;
282                 }
283         }
284         else if (itemIndex == -1)
285         {
286                 for (int index = groupIndex; index < _itemsList.GetCount(); index++)
287                 {
288                         _TableViewGroupItemData* pGroupItem = GetTableViewGroupItemAt(index);
289
290                         if (pGroupItem)
291                         {
292                                 pGroupItem->groupIndex += updateBy;
293                         }
294                 }
295
296                 if (_currentRadioGroupIndex >= groupIndex)
297                 {
298                         _currentRadioGroupIndex += updateBy;
299                 }
300         }
301         else
302         {
303                 int subItemCount = GetSubItemCountAt(groupIndex);
304
305                 for (int index = itemIndex; index < subItemCount; index++)
306                 {
307                         _TableViewItemData* pTableViewItemData = GetTableViewItemAt(groupIndex, index);
308
309                         if (pTableViewItemData)
310                         {
311                                 pTableViewItemData->itemIndex += updateBy;
312                         }
313                 }
314
315                 if (_currentRadioIndex >= itemIndex)
316                 {
317                         _currentRadioIndex += updateBy;
318                 }
319         }
320
321         return E_SUCCESS;
322 }
323
324 result
325 _ListBaseImpl::InsertIntoItemsList(const CustomListItem& item, int groupIndex, int itemIndex, bool updateIndexes)
326 {
327         result r = E_SUCCESS;
328
329         if (GetCore().GetFirstDrawnFlag() == true)
330         {
331                 updateIndexes = false;
332         }
333
334         if (groupIndex == -1)
335         {
336                 r = _itemsList.InsertAt(item, itemIndex);
337                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
338         }
339         else if (itemIndex == -1)
340         {
341                 r = _itemsList.InsertAt(item, groupIndex);
342                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to insert an item.");
343         }
344         else
345         {
346                 CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, -1);
347                 SysTryReturnResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "A system error has occurred. Failed to get item at %d index.", groupIndex);
348
349                 if (pCustomListItem->__pCustomListItemImpl->__pSubItemsList == null)
350                 {
351                         pCustomListItem->__pCustomListItemImpl->__pSubItemsList = new (std::nothrow) ArrayList(_CustomListItemImpl::DeleteCustomListItem);
352                         SysTryReturnResult(NID_UI_CTRL, pCustomListItem->__pCustomListItemImpl->__pSubItemsList, E_OUT_OF_MEMORY, "Memory allocation failed.");
353
354                         pCustomListItem->__pCustomListItemImpl->__pSubItemsList->Construct(1);
355                 }
356
357                 pCustomListItem->__pCustomListItemImpl->__pSubItemsList->InsertAt(item, itemIndex);
358         }
359
360         if (updateIndexes)
361         {
362                 return UpdateIndices(groupIndex, itemIndex, 1);
363         }
364         else
365         {
366                 return E_SUCCESS;
367         }
368 }
369
370 result
371 _ListBaseImpl::RemoveFromItemsList(int groupIndex, int itemIndex, bool updateIndexes)
372 {
373         result r = E_SUCCESS;
374
375         if (GetCore().GetFirstDrawnFlag() == true)
376         {
377                 updateIndexes = false;
378         }
379
380         if (groupIndex == -1)
381         {
382                 r = _itemsList.RemoveAt(itemIndex, true);
383                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "A system error has occurred. Failed to remove an item.");
384         }
385         else if (itemIndex == -1)
386         {
387                 r = _itemsList.RemoveAt(groupIndex, true);
388                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to remove an item.");
389         }
390         else
391         {
392                 CustomListItem* pCustomListGroupItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(_itemsList.GetAt(groupIndex)));
393                 SysTryReturnResult(NID_UI_CTRL, pCustomListGroupItem, E_SYSTEM, "A system error has occurred. Failed to get an item at groupIndex(%d)", groupIndex);
394
395                 ArrayList* pList = pCustomListGroupItem->__pCustomListItemImpl->__pSubItemsList;
396                 SysTryReturnResult(NID_UI_CTRL, pList, E_SYSTEM, "A system error has occurred. Failed to get subItem at groupIndex(%d) itemIndex(%d)", groupIndex, itemIndex);
397
398                 r = pList->RemoveAt(itemIndex, true);
399                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "A system error has occurred. Failed to remove an item.");
400         }
401
402         if (updateIndexes)
403         {
404                 return UpdateIndices(groupIndex, itemIndex, -1);
405         }
406         else
407         {
408                 return E_SUCCESS;
409         }
410
411 }
412
413 result
414 _ListBaseImpl::SetInItemsList(const CustomListItem& item, int groupIndex, int itemIndex)
415 {
416         result r = E_SUCCESS;
417
418         if (groupIndex == -1)
419         {
420                 r = _itemsList.SetAt(item, itemIndex, true);
421                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "A system error has occurred. Failed to remove an item.");
422         }
423         else if (itemIndex == -1)
424         {
425                 CustomListItem* pOldItem = GetCustomListItemAt(groupIndex, -1);
426                 SysTryReturnResult(NID_UI_CTRL, pOldItem, E_SYSTEM, "A system error has occurred. Failed to get current item.");
427
428                 item.__pCustomListItemImpl->__pTableViewGroupItemData = pOldItem->__pCustomListItemImpl->__pTableViewGroupItemData;
429                 item.__pCustomListItemImpl->__pSubItemsList = pOldItem->__pCustomListItemImpl->__pSubItemsList;
430
431                 r = _itemsList.SetAt(item, groupIndex, true);
432                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to remove an item.");
433         }
434         else
435         {
436                 CustomListItem* pCustomListGroupItem = GetCustomListItemAt(groupIndex, -1);
437                 SysTryReturnResult(NID_UI_CTRL, pCustomListGroupItem, E_SYSTEM, "A system error has occurred. Failed to get GroupItem at %d index.", groupIndex);
438
439                 ArrayList* pList = pCustomListGroupItem->__pCustomListItemImpl->__pSubItemsList;
440                 SysTryReturnResult(NID_UI_CTRL, pList, E_SYSTEM, "A system error has occurred. Failed to get subItem at groupIndex(%d) itemIndex(%d)", groupIndex, itemIndex);
441
442                 pList->SetAt(item, itemIndex, true);
443         }
444
445         return E_SUCCESS;
446 }
447
448 void
449 _ListBaseImpl::RemoveAllFromItemsList(void)
450 {
451         _itemsList.RemoveAll(true);
452 }
453
454 CustomListItem*
455 _ListBaseImpl::GetCustomListItemAt(int groupIndex, int itemIndex)
456 {
457         const CustomListItem* pItem = (static_cast<const _ListBaseImpl*>(this))->GetCustomListItemAt(groupIndex, itemIndex);
458         return const_cast<CustomListItem*>(pItem);
459 }
460
461 const CustomListItem*
462 _ListBaseImpl::GetCustomListItemAt(int groupIndex, int itemIndex) const
463 {
464         if (groupIndex == -1)
465         {
466                 CustomListItem* pCustomListItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(_itemsList.GetAt(itemIndex)));
467                 SysTryReturn(NID_UI_CTRL, pCustomListItem, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d", itemIndex);
468
469                 return pCustomListItem;
470         }
471         else if (itemIndex == -1)
472         {
473                 CustomListItem* pCustomListItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(_itemsList.GetAt(groupIndex)));
474                 SysTryReturn(NID_UI_CTRL, pCustomListItem, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
475
476                 return pCustomListItem;
477         }
478         else
479         {
480                 CustomListItem* pCustomListGroupItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(_itemsList.GetAt(groupIndex)));
481                 SysTryReturn(NID_UI_CTRL, pCustomListGroupItem, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d)", groupIndex);
482
483                 ArrayList* pList = pCustomListGroupItem->__pCustomListItemImpl->__pSubItemsList;
484                 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);
485
486                 CustomListItem* pCustomListItem = dynamic_cast<CustomListItem*>(const_cast<Object*>(pList->GetAt(itemIndex)));
487                 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);
488
489                 return pCustomListItem;
490         }
491 }
492
493 _TableViewItemData*
494 _ListBaseImpl::GetTableViewItemAt(int groupIndex, int itemIndex)
495 {
496         const _TableViewItemData* pTableViewItemData = (static_cast<const _ListBaseImpl*>(this))->GetTableViewItemAt(groupIndex, itemIndex);
497         return const_cast<_TableViewItemData*>(pTableViewItemData);
498 }
499
500 const _TableViewItemData*
501 _ListBaseImpl::GetTableViewItemAt(int groupIndex, int itemIndex) const
502 {
503         const CustomListItem* pCustomListGroupItem = (static_cast<const _ListBaseImpl*>(this))->GetCustomListItemAt(groupIndex, itemIndex);
504         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);
505
506         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);
507
508         return pCustomListGroupItem->__pCustomListItemImpl->__pTableViewItemData;
509 }
510
511 _TableViewGroupItemData*
512 _ListBaseImpl::GetTableViewGroupItemAt(int groupIndex)
513 {
514         const _TableViewGroupItemData* pTableViewGroupItemData = (static_cast<const _ListBaseImpl*>(this))->GetTableViewGroupItemAt(groupIndex);
515         return const_cast<_TableViewGroupItemData*>(pTableViewGroupItemData);
516 }
517
518 const _TableViewGroupItemData*
519 _ListBaseImpl::GetTableViewGroupItemAt(int groupIndex) const
520 {
521         const CustomListItem* pCustomListGroupItem = (static_cast<const _ListBaseImpl*>(this))->GetCustomListItemAt(groupIndex, -1);
522         SysTryReturn(NID_UI_CTRL, pCustomListGroupItem, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d)", groupIndex);
523
524         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);
525
526         return pCustomListGroupItem->__pCustomListItemImpl->__pTableViewGroupItemData;
527 }
528
529 _CheckElementModel*
530 _ListBaseImpl::GetCheckElementAt(int groupIndex, int itemIndex)
531 {
532         const _CheckElementModel* pCheckElementModel = (static_cast<const _ListBaseImpl*>(this))->GetCheckElementAt(groupIndex, itemIndex);
533         return const_cast<_CheckElementModel*>(pCheckElementModel);
534 }
535
536 const _CheckElementModel*
537 _ListBaseImpl::GetCheckElementAt(int groupIndex, int itemIndex) const
538 {
539         const CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, itemIndex);
540         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);
541
542         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);
543
544         return pCustomListItem->__pCustomListItemImpl->GetCheckElement();
545 }
546
547 void
548 _ListBaseImpl::DrawItem(int groupIndex, int itemIndex)
549 {
550         if (itemIndex == -1)
551         {
552                 _TableViewGroupItemData* pTableViewGroupItemData = GetTableViewGroupItemAt(groupIndex);
553                 SysTryReturnVoidResult(NID_UI_CTRL, pTableViewGroupItemData, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d)", groupIndex);
554
555                 pTableViewGroupItemData->Invalidate(true);
556         }
557         else
558         {
559                 _TableViewItemData* pTableViewItemData = GetTableViewItemAt(groupIndex, itemIndex);
560                 SysTryReturnVoidResult(NID_UI_CTRL, pTableViewItemData, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d), itemIndex(%d)", groupIndex, itemIndex);
561
562                 pTableViewItemData->Invalidate(true);
563         }
564 }
565
566 result
567 _ListBaseImpl::SetListStyle(CustomListStyle style)
568 {
569         result r = E_SUCCESS;
570
571         switch (style)
572         {
573         case CUSTOM_LIST_STYLE_NORMAL:
574                 _annexStyle = TABLE_VIEW_ANNEX_STYLE_NORMAL;
575                 break;
576
577         case CUSTOM_LIST_STYLE_RADIO:
578                 _annexStyle = TABLE_VIEW_ANNEX_STYLE_RADIO;
579                 break;
580
581         case CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER:
582                 _annexStyle = TABLE_VIEW_ANNEX_STYLE_RADIO;
583                 _isDividerEnabled = true;
584                 break;
585
586         case CUSTOM_LIST_STYLE_MARK:
587                 _annexStyle = TABLE_VIEW_ANNEX_STYLE_MARK;
588                 break;
589
590         case CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER:
591                 _annexStyle = TABLE_VIEW_ANNEX_STYLE_MARK;
592                 _isDividerEnabled = true;
593                 break;
594
595         case CUSTOM_LIST_STYLE_ONOFF:
596                 _annexStyle = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
597                 break;
598
599         case CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER:
600                 _annexStyle = TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING;
601                 _isDividerEnabled = true;
602                 break;
603
604         default:
605                 SysLog(NID_UI_CTRL, "[E_INVALID_ARG] Invalid argument used. style is invalid.");
606                 r = E_INVALID_ARG;
607                 break;
608         }
609
610         return r;
611 }
612
613 _TableView&
614 _ListBaseImpl::GetCore(void)
615 {
616         return static_cast<_TableView&>(_ControlImpl::GetCore());
617 }
618
619 const _TableView&
620 _ListBaseImpl::GetCore(void) const
621 {
622         return static_cast<const _TableView&>(_ControlImpl::GetCore());
623 }
624
625 void
626 _ListBaseImpl::SetTextOfEmptyList(const String& text)
627 {
628         if (text.IsEmpty())
629         {
630                 if (__pEmptyText != null)
631                 {
632                         GetCore().DetachChild(*__pEmptyText);
633
634                         delete __pEmptyText;
635                         __pEmptyText = null;
636                 }
637         }
638         else
639         {
640                 if (__pEmptyText == null)
641                 {
642                         __pEmptyText = _Label::CreateLabelN();
643                         SysTryReturnVoidResult(NID_UI_CTRL, (__pEmptyText != null), E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
644
645                         __pEmptyText->SetVisibleState(false);
646                         __pEmptyText->SetMargin(0, 0);
647
648                         GetCore().AttachChild(*__pEmptyText);
649                 }
650
651                 TextObject* pText = new (std::nothrow) TextObject;
652                 SysTryReturnVoidResult(NID_UI_CTRL, (pText != null), E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
653
654                 pText->Construct();
655
656                 TextSimple* pSimpleText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(text.GetPointer()), text.GetLength());
657                 SysTryReturnVoidResult(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
658
659                 pText->AppendElement(*pSimpleText);
660
661                 int textSize = 0;
662                 GET_SHAPE_CONFIG(LIST::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, textSize);
663
664                 Font font;
665                 font.Construct(GetFont(), FONT_STYLE_PLAIN, textSize);
666                 pText->SetFont(&font, 0, pText->GetTextLength());
667
668                 Dimension listDimension = GetCore().GetSize();
669
670                 pText->SetBounds(Rectangle(0, 0, listDimension.width, 1));
671                 pText->Compose();
672
673                 Dimension labelDimension = pText->GetTextExtent(0, pText->GetTextLength());
674                 labelDimension.height = pText->GetTotalHeight();
675
676                 if (labelDimension.width > listDimension.width)
677                 {
678                         pText->SetBounds(Rectangle(0, 0, listDimension.width, 1));
679                         pText->Compose();
680
681                         int labelHeight = pText->GetTotalHeight();
682
683                         labelDimension.width = listDimension.width;
684                         labelDimension.height = ((listDimension.height < labelHeight) ? listDimension.height : labelHeight);
685                 }
686
687                 delete pText;
688
689                 Rectangle bounds = GetCore().GetBounds();
690
691                 __pEmptyText->SetBounds(Rectangle((bounds.width - labelDimension.width)/2, (bounds.height - labelDimension.height)/2, labelDimension.width, labelDimension.height));
692                 __pEmptyText->SetBackgroundColor(Color(0, 0, 0, 0));
693                 __pEmptyText->SetTextColor(__emptyTextColor);
694                 __pEmptyText->SetTextConfig(textSize, LABEL_TEXT_STYLE_NORMAL);
695                 __pEmptyText->SetText(text);
696         }
697
698         return;
699 }
700
701 void
702 _ListBaseImpl::SetTextColorOfEmptyList(const Color& color)
703 {
704         __emptyTextColor = color;
705
706         if (__pEmptyText != null)
707         {
708                 __pEmptyText->SetTextColor(color);
709         }
710
711         return;
712 }
713
714 Color
715 _ListBaseImpl::GetTextColorOfEmptyList(void) const
716 {
717         return __emptyTextColor;
718 }
719
720 result
721 _ListBaseImpl::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
722 {
723         result r = GetCore().GetTopDrawnItemIndex(groupIndex, itemIndex);
724         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
725
726         return E_SUCCESS;
727 }
728
729 result
730 _ListBaseImpl::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
731 {
732         result r = GetCore().GetBottomDrawnItemIndex(groupIndex, itemIndex);
733         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
734
735         return E_SUCCESS;
736 }
737
738 result
739 _ListBaseImpl::GetItemIndexFromPosition(const Point& position, int& groupIndex, int& itemIndex) const
740 {
741         return GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
742 }
743
744 int
745 _ListBaseImpl::GetItemCount(void) const
746 {
747         return _itemsList.GetCount();
748 }
749
750 int
751 _ListBaseImpl::GetGroupCount(void) const
752 {
753         return _itemsList.GetCount();
754 }
755
756 int
757 _ListBaseImpl::GetSubItemCountAt(int groupIndex) const
758 {
759         result r = E_SUCCESS;
760
761         const CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, -1);
762         r = GetLastResult();
763         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), -1, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
764
765         ArrayList* pList = pCustomListItem->__pCustomListItemImpl->__pSubItemsList;
766         SysTryReturn(NID_UI_CTRL, pList, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get subItemsList at groupIndex(%d)", groupIndex);
767
768         return pList->GetCount();
769 }
770
771 result
772 _ListBaseImpl::RemoveFromSubItemsList(int groupIndex)
773 {
774         result r = E_SUCCESS;
775
776         const CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, -1);
777         r = GetLastResult();
778         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
779
780         ArrayList* pList = pCustomListItem->__pCustomListItemImpl->__pSubItemsList;
781
782         if (pList)
783         {
784                 pList->RemoveAll();
785                 delete pList;
786                 pCustomListItem->__pCustomListItemImpl->__pSubItemsList = null;
787         }
788
789         return E_SUCCESS;
790 }
791
792 void
793 _ListBaseImpl::OnDraw(void)
794 {
795         _ControlImpl::OnDraw();
796
797         bool isEmpty = (GetItemCount() <= 0);
798
799         if (__pEmptyText != null)
800         {
801                 __pEmptyText->SetVisibleState(isEmpty);
802         }
803 }
804
805 }}} //Tizen::Ui::Controls