Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_ExpandableListImpl.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_ExpandableListImpl.cpp
20  * @brief       This file contains implementation of _ExpandableListImpl class
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FGrp_BitmapImpl.h>
25 #include "FUiCtrl_CustomListItemImpl.h"
26 #include "FUiCtrl_CustomListItemFormatImpl.h"
27 #include "FUiCtrl_ExpandableListImpl.h"
28 #include "FUiCtrl_ListListener.h"
29 #include "FUi_ResourceSizeInfo.h"
30 #include "FUi_ResourceManager.h"
31 #include "FUiCtrl_ListItemBaseImpl.h"
32 #include "FUiCtrl_CustomListImpl.h"
33 #include "FUi_UiBuilder.h"
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Runtime;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Base::Collection;
39
40 namespace Tizen { namespace Ui { namespace Controls
41 {
42
43 extern const int INVALID_INDEX;
44
45 static const int _EXPANDABLE_ARROW_X_POSITION = 5;
46 static const int _EXPANDABLE_ARROW_Y_POSITION = 20;
47 static const char* ARROW_ELEMENT_NAME = "Arrow";
48
49 _ExpandableListItemDataProvider::_ExpandableListItemDataProvider(_ExpandableListImpl* pList)
50         : __pListImpl(pList)
51 {
52 }
53
54 _ExpandableListItemDataProvider::~_ExpandableListItemDataProvider(void)
55 {
56
57 }
58
59 int
60 _ExpandableListItemDataProvider::GetGroupCount(void)
61 {
62         SysTryReturn(NID_UI_CTRL, __pListImpl, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Item provider not constructed properly.");
63         return __pListImpl->GetGroupCount();
64 }
65
66 int
67 _ExpandableListItemDataProvider::GetItemCount(int groupIndex)
68 {
69         SysTryReturn(NID_UI_CTRL, __pListImpl, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Item provider not constructed properly.");
70
71         return __pListImpl->GetSubItemCountAt(groupIndex);
72 }
73
74 TableViewGroupItem*
75 _ExpandableListItemDataProvider::CreateGroupItem(int groupIndex, int itemWidth)
76 {
77         SysTryReturn(NID_UI_CTRL, __pListImpl, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Item provider not constructed properly.");
78
79         CustomListItem* pCustomListItem = __pListImpl->GetCustomListItemAt(groupIndex, -1);
80         SysTryReturn(NID_UI_CTRL, pCustomListItem, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", groupIndex);
81
82         SysTryReturn(NID_UI_CTRL, pCustomListItem->__pCustomListItemImpl, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", groupIndex);
83
84         _TableViewItemParams tableViewItemParams;
85         tableViewItemParams.pItem = pCustomListItem;
86         tableViewItemParams.width = itemWidth;
87         tableViewItemParams.itemId = pCustomListItem->__pCustomListItemImpl->itemId;
88         tableViewItemParams.groupIndex = groupIndex;
89         tableViewItemParams.itemIndex =  -1;
90         tableViewItemParams.isDividerEnabled = __pListImpl->_isDividerEnabled;
91         tableViewItemParams.pCheckBitmaps = __pListImpl->_pCheckBitmaps;
92         tableViewItemParams.annexStyle = __pListImpl->_annexStyle;
93
94         result r = _CustomListItemImpl::CreateTableViewItem(tableViewItemParams);
95         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
96
97         pCustomListItem->__pCustomListItemImpl->__pTableViewGroupItemData->AddTouchEventListener(*__pListImpl);
98
99         if (__pListImpl->GetSubItemCountAt(groupIndex) > 0)
100         {
101                 r = __pListImpl->CreateArrowIcon(groupIndex);
102                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
103         }
104
105         return pCustomListItem->__pCustomListItemImpl->__pTableViewGroupItemData;
106 }
107
108 TableViewItem*
109 _ExpandableListItemDataProvider::CreateItem(int groupIndex, int itemIndex, int itemWidth)
110 {
111         SysTryReturn(NID_UI_CTRL, __pListImpl, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Invalid data structure.");
112
113         CustomListItem* pCustomListItem = __pListImpl->GetCustomListItemAt(groupIndex, itemIndex);
114         SysTryReturn(NID_UI_CTRL, pCustomListItem, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", groupIndex);
115
116         _TableViewItemParams tableViewItemParams;
117         tableViewItemParams.pItem = pCustomListItem;
118         tableViewItemParams.width = itemWidth;
119         tableViewItemParams.itemId = pCustomListItem->__pCustomListItemImpl->itemId;
120         tableViewItemParams.groupIndex = groupIndex;
121         tableViewItemParams.itemIndex =  itemIndex;
122         tableViewItemParams.isDividerEnabled = __pListImpl->_isDividerEnabled;
123         tableViewItemParams.pCheckBitmaps = __pListImpl->_pCheckBitmaps;
124         tableViewItemParams.annexStyle = __pListImpl->_annexStyle;
125
126         result r = _CustomListItemImpl::CreateTableViewItem(tableViewItemParams);
127         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
128
129         pCustomListItem->__pCustomListItemImpl->__pTableViewItemData->AddTouchEventListener(*__pListImpl);
130
131         if (__pListImpl->GetSubItemCountAt(groupIndex) == 1)
132         {
133                 r = __pListImpl->CreateArrowIcon(groupIndex);
134                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
135         }
136
137         return pCustomListItem->__pCustomListItemImpl->__pTableViewItemData;
138 }
139
140 int
141 _ExpandableListItemDataProvider::GetDefaultGroupItemHeight(void)
142 {
143         CustomListItem* pCustomListItem = __pListImpl->GetCustomListItemAt(0, -1);
144         SysTryReturn(NID_UI_CTRL, pCustomListItem, __pListImpl->_defaultItemHeight, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get first item");
145
146         SysTryReturn(NID_UI_CTRL, pCustomListItem->__pCustomListItemImpl, __pListImpl->_defaultItemHeight, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get first item");
147
148         return pCustomListItem->__pCustomListItemImpl->height;
149 }
150
151 int
152 _ExpandableListItemDataProvider::GetDefaultItemHeight(void)
153 {
154         CustomListItem* pCustomListItem = __pListImpl->GetCustomListItemAt(0, 0);
155
156         if (!pCustomListItem)
157         {
158                 return __pListImpl->_defaultItemHeight;
159         }
160         else
161         {
162                 return pCustomListItem->__pCustomListItemImpl->height;
163         }
164 }
165
166 bool
167 _ExpandableListItemDataProvider::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
168 {
169         delete pItem;
170
171         if (__pListImpl->__directDelete == false)
172         {
173                 CustomListItem* pCustomListItem = __pListImpl->GetCustomListItemAt(groupIndex, itemIndex);
174                 pCustomListItem->__pCustomListItemImpl->__pTableViewItemData = null;
175         }
176
177         return true;
178 }
179
180 bool
181 _ExpandableListItemDataProvider::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
182 {
183         delete pItem;
184
185         if (__pListImpl->__directDelete == false)
186         {
187                 CustomListItem* pCustomListItem = __pListImpl->GetCustomListItemAt(groupIndex, -1);
188                 pCustomListItem->__pCustomListItemImpl->__pTableViewGroupItemData = null;
189         }
190
191         return true;
192 }
193
194 bool
195 _ExpandableListItemDataProvider::IsReorderable(int groupIndexFrom, int groupIndexTo)
196 {
197         return false;
198 }
199
200 void
201 _ExpandableListItemDataProvider::UpdateGroupItem(int groupIndex, TableViewGroupItem* pItem)
202 {
203         CustomListItem* pGroupCustomListItem = __pListImpl->GetCustomListItemAt(groupIndex, -1);
204         SysTryReturnVoidResult(NID_UI_CTRL, pGroupCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", groupIndex);
205
206         _TableViewItemUpdateParams updateParams;
207         updateParams.pItem = pGroupCustomListItem;
208         updateParams.isDividerEnabled = __pListImpl->_isDividerEnabled;
209         updateParams.pCheckBitmaps = __pListImpl->_pCheckBitmaps;
210         updateParams.annexStyle = __pListImpl->_annexStyle;
211
212         result r = E_SUCCESS;
213
214         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
215         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS),  E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to refresh an item.");
216
217         SysTryReturnVoidResult(NID_UI_CTRL, pGroupCustomListItem->__pCustomListItemImpl,  E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", groupIndex);
218
219         _TableViewItemData* pTableViewItemData = pGroupCustomListItem->__pCustomListItemImpl->__pTableViewItemData;
220         SysTryReturnVoidResult(NID_UI_CTRL, pTableViewItemData, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d)", groupIndex);
221
222         pTableViewItemData->SetEnabled(true);
223         return;
224 }
225
226 void
227 _ExpandableListItemDataProvider::UpdateItem(int groupIndex, int itemIndex, TableViewItem* pItem)
228 {
229         CustomListItem* pCustomListItem = __pListImpl->GetCustomListItemAt(groupIndex, itemIndex);
230         SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d) itemIndex(%d)", groupIndex, itemIndex);
231
232         _TableViewItemUpdateParams updateParams;
233         updateParams.pItem = pCustomListItem;
234         updateParams.isDividerEnabled = __pListImpl->_isDividerEnabled;
235         updateParams.pCheckBitmaps = __pListImpl->_pCheckBitmaps;
236         updateParams.annexStyle = __pListImpl->_annexStyle;
237
238         result r = E_SUCCESS;
239
240         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
241         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to refresh an item.");
242
243         _TableViewItemData* pTableViewItemData = pCustomListItem->__pCustomListItemImpl->__pTableViewItemData;
244         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);
245
246         pTableViewItemData->SetEnabled(true);
247
248         return;
249 }
250
251 _ExpandableListImpl*
252 _ExpandableListImpl::GetInstance(ExpandableList& expandableList)
253 {
254         return static_cast<_ExpandableListImpl*>(expandableList._pControlImpl);
255 }
256
257 const _ExpandableListImpl*
258 _ExpandableListImpl::GetInstance(const ExpandableList& expandableList)
259 {
260         return static_cast<const _ExpandableListImpl*>(expandableList._pControlImpl);
261 }
262
263 _ExpandableListImpl::_ExpandableListImpl(Control* pList, _TableView* pCore)
264         : _ListBaseImpl(pList, pCore)
265         , __pOpenedImage(null)
266         , __pClosedImage(null)
267         , __pItemProvider(null)
268         , __directDelete(false)
269         , __groupExpandStateList(DeleteExpandStateFlag)
270 {
271 }
272
273 _ExpandableListImpl::~_ExpandableListImpl(void)
274 {
275         GetCore().SetItemProvider(null);
276
277         int count = GetItemCount();
278
279         for (int index = 0; index < count; index++)
280         {
281                 RemoveFromSubItemsList(index);
282         }
283
284         RemoveAllFromItemsList();
285
286         __groupExpandStateList.RemoveAll(true);
287
288         __itemListenersList.RemoveAll(true);
289
290         delete __pOpenedImage;
291         __pOpenedImage = null;
292
293         delete __pClosedImage;
294         __pClosedImage = null;
295
296         delete __pItemProvider;
297         __pItemProvider = null;
298 }
299
300 const char*
301 _ExpandableListImpl::GetPublicClassName(void) const
302 {
303         return "ExpandableList";
304 }
305
306 const ExpandableList&
307 _ExpandableListImpl::GetPublic(void) const
308 {
309         return static_cast<const ExpandableList&>(_ControlImpl::GetPublic());
310 }
311
312 ExpandableList&
313 _ExpandableListImpl::GetPublic(void)
314 {
315         return static_cast<ExpandableList&>(_ControlImpl::GetPublic());
316 }
317
318 const _TableView&
319 _ExpandableListImpl::GetCore(void) const
320 {
321         return static_cast<const _TableView&>(_ControlImpl::GetCore());
322 }
323
324 _TableView&
325 _ExpandableListImpl::GetCore(void)
326 {
327         return static_cast<_TableView&>(_ControlImpl::GetCore());
328 }
329
330 _ExpandableListImpl*
331 _ExpandableListImpl::CreateExpandableListImplN(ExpandableList* pControl, const Rectangle& bounds, bool itemDivider)
332 {
333         result r = E_SUCCESS;
334
335         r = GET_SIZE_INFO(ExpandableList).CheckInitialSizeValid(Dimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
336         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
337
338         _TableView* pCore = _TableView::CreateTableViewN(TABLE_VIEW_STYLE_GROUPED, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
339
340         r = GetLastResult();
341         SysTryReturn(NID_UI_CTRL, pCore, null, r, "[%s] Propagating.", GetErrorMessage(r));
342
343         _ExpandableListImpl* pImpl = new (std::nothrow) _ExpandableListImpl(pControl, pCore);
344         SysTryCatch(NID_UI_CTRL, pImpl, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
345
346         pCore->SetItemDividerEnabled(itemDivider);
347
348         r = pCore->SetScrollStyle(TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
349         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
350         ClearLastResult();
351
352         return pImpl;
353
354 CATCH:
355         delete pCore;
356         delete pImpl;
357         return null;
358 }
359
360 result
361 _ExpandableListImpl::UpdateBounds(const Rectangle& rect)
362 {
363         result r = E_SUCCESS;
364
365         r = InitializeBoundsProperties(GET_SIZE_INFO(CustomList), rect, GetCore().GetOrientation());
366         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
367
368         return E_SUCCESS;
369 }
370
371 result
372 _ExpandableListImpl::Initialize(void)
373 {
374         result r = E_SUCCESS;
375
376         __pItemProvider = new (std::nothrow) _ExpandableListItemDataProvider(this);
377         SysTryReturnResult(NID_UI_CTRL, (__pItemProvider != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
378
379         TableViewStyle style = GetCore().GetTableViewStyle();
380         SysTryReturnResult(NID_UI_CTRL, style == TABLE_VIEW_STYLE_GROUPED, E_INVALID_OPERATION, "The style of TableView is not TABLE_VIEW_STYLE_GROUPED");
381
382         _TableViewItemProvider* pItemProvider = _TableViewItemProvider::CreateTableViewItemProviderN(style);
383         SysTryReturnResult(NID_UI_CTRL, pItemProvider != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
384
385         r = pItemProvider->SetGroupedStyleItemProvider(__pItemProvider);
386
387         if (r != E_SUCCESS)
388         {
389                 delete pItemProvider;
390                 SysTryReturn(NID_UI_CTRL, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
391         }
392
393         r = GetCore().SetItemProvider(pItemProvider);
394         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
395
396         r = GetCore().AddGroupedTableViewItemEventListener(*this);
397         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
398
399         LoadArrowBitmap();
400
401         GET_COLOR_CONFIG(LIST::EXPANDABLELIST_SUB_ITEM_BG_COLOR, __subItemBgColor);
402
403         return r;
404 }
405
406 result
407 _ExpandableListImpl::CreateArrowIcon(int groupIndex)
408 {
409         int size = __pOpenedImage->GetWidth();
410         result r = E_SUCCESS;
411
412         _TableViewGroupItemData* pTableViewGroupItemData = GetTableViewGroupItemAt(groupIndex);
413         SysTryReturnResult(NID_UI_CTRL, pTableViewGroupItemData, E_SYSTEM, "A system error has occurred. Failed to get GroupItemData at %d index.", groupIndex);
414
415         Label* pArrowLabel = null;
416         pArrowLabel = dynamic_cast<Label*>(pTableViewGroupItemData->GetControl(ARROW_ELEMENT_NAME));
417
418         if (!pArrowLabel)
419         {
420                 Label* pArrowLabel = new (std::nothrow) Label();
421                 SysTryReturn(NID_UI_CTRL, pArrowLabel, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
422
423                 r = pArrowLabel->Construct(Rectangle((GetCore().GetBounds().width - (size + _EXPANDABLE_ARROW_X_POSITION)), _EXPANDABLE_ARROW_Y_POSITION, size, size), L"");
424                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
425
426                 pArrowLabel->SetName(ARROW_ELEMENT_NAME);
427                 pArrowLabel->SetBackgroundBitmap(*__pOpenedImage);
428                 pArrowLabel->AddTouchEventListener(*this);
429
430                 pTableViewGroupItemData->AddControl(*pArrowLabel);
431                 pTableViewGroupItemData->SetIndividualSelectionEnabled(pArrowLabel, true);
432         }
433
434         return E_SUCCESS;
435 }
436
437 result
438 _ExpandableListImpl::LoadArrowBitmap(void)
439 {
440         result r = E_SUCCESS;
441         Bitmap* pTempBitmap = null;
442         Color normalColor;
443
444         GET_COLOR_CONFIG(LIST::EXPANDABLELIST_DOWN_AND_UP_ARROW_COLOR, normalColor);
445
446         r = GET_BITMAP_CONFIG_N(LIST::BUTTON_COLLAPSE_GROUP, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
447         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Failed to fetch Arrow Bitmap");
448         __pOpenedImage = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), normalColor);
449
450         delete pTempBitmap;
451         pTempBitmap = null;
452
453         r = GET_BITMAP_CONFIG_N(LIST::BUTTON_EXPAND_GROUP, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
454         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Failed to fetch Arrow Bitmap");
455         __pClosedImage = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), normalColor);
456
457         delete pTempBitmap;
458         pTempBitmap = null;
459
460         return r;
461 }
462
463 result
464 _ExpandableListImpl::AddExpandableItemEventListener(const IExpandableItemEventListener& listener)
465 {
466         _ListListener* pListenersList = new (std::nothrow) _ListListener();
467
468         SysTryReturn(NID_UI_CTRL, pListenersList, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
469
470         pListenersList->pListener = const_cast<IExpandableItemEventListener*>(&listener);
471         __itemListenersList.Add(*pListenersList);
472
473         return E_SUCCESS;
474 }
475
476 result
477 _ExpandableListImpl::RemoveExpandableItemEventListener(const IExpandableItemEventListener& listener)
478 {
479         _ListListener* pListenersList = null;
480         result r = E_SYSTEM;
481         int count = __itemListenersList.GetCount();
482
483         for (int listenerCount = 0; listenerCount < count; listenerCount++)
484         {
485                 pListenersList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
486
487                 if ((pListenersList != null) && (pListenersList->pListener == &listener))
488                 {
489                         r = E_SUCCESS;
490                         __itemListenersList.RemoveAt(listenerCount, true);
491                         break;
492                 }
493         }
494
495         return r;
496 }
497
498 result
499 _ExpandableListImpl::AddItem(const CustomListItem& item, int itemId)
500 {
501         return InsertItemAt(GetGroupCount(), item, itemId);
502 }
503
504 result
505 _ExpandableListImpl::InsertItemAt(int mainIndex, const CustomListItem& item, int itemId)
506 {
507         result r = E_SUCCESS;
508
509         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex <= GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
510
511         item.__pCustomListItemImpl->itemId = itemId;
512
513         Boolean* pIsExpanded = new Boolean(false);
514         SysTryReturn(NID_UI_CTRL, pIsExpanded, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
515
516         __groupExpandStateList.InsertAt(*pIsExpanded, mainIndex);
517
518         r = InsertIntoItemsList(item, mainIndex, -1);
519         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
520
521         r = GetCore().RefreshTableView(mainIndex, -1, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
522         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
523
524         if (GetCore().GetFirstDrawnFlag() == false)
525         {
526                 SetItemExpanded(mainIndex, false);
527         }
528
529         return E_SUCCESS;
530
531 CATCH:
532         RemoveFromItemsList(mainIndex, -1);
533         __groupExpandStateList.RemoveAt(mainIndex, true);
534
535         return E_SYSTEM;
536 }
537
538 result
539 _ExpandableListImpl::AddSubItem(int mainIndex, const CustomListItem& item, int itemId)
540 {
541         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex <= GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
542
543         return InsertSubItemAt(mainIndex, GetSubItemCountAt(mainIndex), item, itemId);
544 }
545
546 result
547 _ExpandableListImpl::InsertSubItemAt(int mainIndex, int subIndex, const CustomListItem& item, int itemId)
548 {
549         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex <= GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d.", mainIndex);
550
551         SysTryReturnResult(NID_UI_CTRL, (subIndex >= 0 && subIndex <= GetSubItemCount(mainIndex)), E_INVALID_ARG, "Invalid argument used. subIndex = %d.", subIndex);
552
553         item.__pCustomListItemImpl->itemId = itemId;
554
555         result r = E_SUCCESS;
556
557         r = InsertIntoItemsList(item, mainIndex, subIndex);
558         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to insert item");
559
560         r = GetCore().RefreshTableView(mainIndex, subIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
561         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
562
563         return E_SUCCESS;
564
565 CATCH:
566         RemoveFromItemsList(mainIndex, subIndex);
567         return E_SYSTEM;
568 }
569
570 int
571 _ExpandableListImpl::GetItemCount(void) const
572 {
573         return GetGroupCount();
574 }
575
576 int
577 _ExpandableListImpl::GetSubItemCount(int mainIndex) const
578 {
579         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d.", mainIndex);
580
581         return GetSubItemCountAt(mainIndex);
582 }
583
584 result
585 _ExpandableListImpl::SetItemAt(int mainIndex, const CustomListItem& item, int itemId)
586 {
587         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
588
589         SysTryReturnResult(NID_UI_CTRL, (IsItemNew(item) == true), E_SYSTEM, "[E_SYSTEM] A system error has occurred. The item already exists.");
590
591         result r = E_SUCCESS;
592         item.__pCustomListItemImpl->itemId = itemId;
593
594         r = SetInItemsList(item, mainIndex, -1);
595         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
596
597         _TableViewItemUpdateParams updateParams;
598         updateParams.pItem = const_cast<CustomListItem*>(&item);
599         updateParams.isDividerEnabled = _isDividerEnabled;
600         updateParams.pCheckBitmaps = _pCheckBitmaps;
601         updateParams.annexStyle = _annexStyle;
602
603         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
604         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "A system error has occurred. Failed to refresh an item.");
605
606         return E_SUCCESS;
607 }
608
609 result
610 _ExpandableListImpl::RemoveItemAt(int mainIndex)
611 {
612         result r = E_SUCCESS;
613
614         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d.", mainIndex);
615
616         r = RemoveFromSubItemsList(mainIndex);
617         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
618
619         r = RemoveFromItemsList(mainIndex, -1);
620         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
621
622         __groupExpandStateList.RemoveAt(mainIndex, true);
623
624         __directDelete = true;
625
626         r = GetCore().RefreshTableView(mainIndex, -1, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
627
628         __directDelete = false;
629
630         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
631
632         return E_SUCCESS;
633 }
634
635 result
636 _ExpandableListImpl::SetSubItemAt(int mainIndex, int subIndex, const CustomListItem& item, int itemId)
637 {
638         result r = E_SUCCESS;
639
640         SysTryReturn(NID_UI_CTRL, ((mainIndex >= 0) && (mainIndex < GetGroupCount())), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
641
642         _TableViewGroupItemData* pGroupItem = GetTableViewGroupItemAt(mainIndex);
643         SysTryReturn(NID_UI_CTRL, pGroupItem, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get GroupItem at %d index.", mainIndex);
644
645         SysTryReturn(NID_UI_CTRL, ((subIndex >= 0) && (subIndex < GetSubItemCountAt(mainIndex))), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. subIndex = %d", subIndex);
646
647         item.__pCustomListItemImpl->itemId = itemId;
648
649         CustomListItem* pOldItem = GetCustomListItemAt(mainIndex, subIndex);
650         SysTryReturnResult(NID_UI_CTRL, pOldItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at mainIndex(%d), subIndex(%d).", mainIndex, subIndex);
651         SysTryReturnResult(NID_UI_CTRL, pOldItem->__pCustomListItemImpl, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at mainIndex(%d), subIndex(%d).", mainIndex, subIndex);
652
653         item.__pCustomListItemImpl->__pTableViewItemData = pOldItem->__pCustomListItemImpl->__pTableViewItemData;
654
655         r = SetInItemsList(item, mainIndex, subIndex);
656         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to update an item.");
657
658         _TableViewItemUpdateParams updateParams;
659         updateParams.pItem = const_cast<CustomListItem*>(&item);
660         updateParams.isDividerEnabled = _isDividerEnabled;
661         updateParams.pCheckBitmaps = _pCheckBitmaps;
662         updateParams.annexStyle = _annexStyle;
663
664         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
665         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to refresh an item.");
666
667         r = GetCore().RefreshTableView(mainIndex, subIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
668         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "Item not inserted successFully.");
669
670         return r;
671 }
672
673 result
674 _ExpandableListImpl::RemoveSubItemAt(int mainIndex, int subIndex)
675 {
676         result r = E_SUCCESS;
677
678         SysTryReturn(NID_UI_CTRL, ((mainIndex >= 0) && (mainIndex < GetGroupCount())), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
679
680         SysTryReturn(NID_UI_CTRL, ((subIndex >= 0) && (subIndex < GetSubItemCount(mainIndex))), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. subIndex = %d", subIndex);
681
682         r = RemoveFromItemsList(mainIndex, subIndex);
683         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to remove item.");
684
685         __directDelete = true;
686
687         r = GetCore().RefreshTableView(mainIndex, subIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
688
689         __directDelete = false;
690
691         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to remove item.");
692
693         if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_MARK || _annexStyle == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING)
694         {
695                 int checkedCount = GetCheckedItemCount(mainIndex);
696
697                 if (checkedCount == 0)
698                 {
699                         _CheckElementModel* pGroupCheckElement = GetCheckElementAt(mainIndex, -1);
700                         SysTryReturnResult(NID_UI_CTRL, pGroupCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at %d index.", mainIndex);
701
702                         pGroupCheckElement->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
703
704                         DrawItem(mainIndex, -1);
705                 }
706         }
707
708         return E_SUCCESS;
709 }
710
711 result
712 _ExpandableListImpl::RemoveAllSubItemsAt(int mainIndex)
713 {
714         result r = E_SUCCESS;
715
716         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d.", mainIndex);
717
718         int count = GetSubItemCountAt(mainIndex);
719         for (int index = 0; index < count; index++)
720         {
721                 r = RemoveSubItemAt(mainIndex, 0);
722         }
723
724         return r;
725 }
726
727 result
728 _ExpandableListImpl::RemoveAllItems(void)
729 {
730         result r = E_SUCCESS;
731         result finalResult = E_SUCCESS;
732
733         int count = GetGroupCount();
734         for (int index = count - 1; index >= 0; index--)
735         {
736                 r = RemoveItemAt(index);
737
738                 if (r != E_SUCCESS)
739                 {
740                         finalResult = r;
741                         SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Item at %d index not removed successfully", index);
742                         index++;
743                 }
744         }
745         return finalResult;
746 }
747
748 bool
749 _ExpandableListImpl::IsItemChecked(int groupIndex, int subIndex) const
750 {
751         if (subIndex == -1)
752         {
753                 return IsItemChecked(groupIndex);
754         }
755         else
756         {
757                 return IsSubItemChecked(groupIndex, subIndex);
758         }
759 }
760
761 bool
762 _ExpandableListImpl::IsItemChecked(int mainIndex) const
763 {
764         SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. list style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL.");
765
766         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()),
767                         false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
768
769         const _CheckElementModel* pCheckElement = GetCheckElementAt(mainIndex, -1);
770         SysTryReturn(NID_UI_CTRL, pCheckElement, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get checkElement at mainIndex(%d).", mainIndex);
771
772         return (bool)pCheckElement->GetCheckBoxStatus();
773 }
774
775 int
776 _ExpandableListImpl::GetFirstCheckedItemIndex(void) const
777 {
778         SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), INVALID_INDEX, INVALID_INDEX, "[INVALID_INDEX] List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
779
780         int count  = GetGroupCount();
781         for (int index = 0; index < count; index++)
782         {
783                 if (IsItemChecked(index))
784                         return index;
785         }
786         return INVALID_INDEX;
787 }
788
789 int
790 _ExpandableListImpl::GetItemIdAt(int mainIndex) const
791 {
792         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
793
794         const CustomListItem* pCustomListItem = GetCustomListItemAt(mainIndex, -1);
795         SysTryReturn(NID_UI_CTRL, pCustomListItem, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at mainIndex(%d).", mainIndex);
796
797         return pCustomListItem->__pCustomListItemImpl->itemId;
798 }
799
800 int
801 _ExpandableListImpl::GetItemIndexFromItemId(int itemId) const
802 {
803         int count  = GetGroupCount();
804         for (int index = 0; index < count; index++)
805         {
806                 const CustomListItem* pCustomListItem = GetCustomListItemAt(index, -1);
807                 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);
808
809                 if (itemId == pCustomListItem->__pCustomListItemImpl->itemId)
810                         return index;
811         }
812         return INVALID_INDEX;
813 }
814
815 int
816 _ExpandableListImpl::GetSubItemIdAt(int mainIndex, int subIndex) const
817 {
818         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
819
820         SysTryReturn(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)),     INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. subIndex = %d", subIndex);
821
822         const CustomListItem* pCustomListItem = GetCustomListItemAt(mainIndex, subIndex);
823         SysTryReturn(NID_UI_CTRL, pCustomListItem, INVALID_INDEX, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at mainIndex(%d), subIndex(%d).", mainIndex, subIndex);
824
825         return pCustomListItem->__pCustomListItemImpl->itemId;
826 }
827
828 result
829 _ExpandableListImpl::SetItemExpanded(int mainIndex, bool expand)
830 {
831         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
832
833         Boolean* pIsExpanded = new Boolean(expand);
834         SysTryReturn(NID_UI_CTRL, pIsExpanded, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
835
836         __groupExpandStateList.SetAt(*pIsExpanded, mainIndex, true);
837
838         if (GetCore().GetFirstDrawnFlag() || (GetCore().IsGroupExpanded(mainIndex) == expand))
839         {
840                 return E_SUCCESS;
841         }
842
843         result r = E_SUCCESS;
844
845         _TableViewGroupItemData* pTableViewGroupItemData = GetTableViewGroupItemAt(mainIndex);
846         SysTryReturn(NID_UI_CTRL, pTableViewGroupItemData, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get item at %d mainIndex.", mainIndex);
847
848         Label* pArrowLabel = dynamic_cast<Label*>(pTableViewGroupItemData->GetControl(ARROW_ELEMENT_NAME));
849         SysTryReturn(NID_UI_CTRL, pArrowLabel, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get arrow icon.");
850
851         if (expand)
852         {
853                 r = GetCore().ExpandGroup(mainIndex);
854                 pArrowLabel->SetBackgroundBitmap(*__pClosedImage);
855         }
856         else
857         {
858                 r = GetCore().CollapseGroup(mainIndex);
859                 pArrowLabel->SetBackgroundBitmap(*__pOpenedImage);
860         }
861
862         pArrowLabel->Invalidate(true);
863
864         return r;
865 }
866
867 result
868 _ExpandableListImpl::SetItemEnabled(int mainIndex, bool enable)
869 {
870         result r = E_SUCCESS;
871
872         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
873
874         _CheckElementModel* pCheckElement = GetCheckElementAt(mainIndex, -1);
875         SysTryReturnResult(NID_UI_CTRL, pCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d).", mainIndex);
876
877         if (pCheckElement)
878         {
879                 if (enable)
880                 {
881                         if (pCheckElement->GetCheckBoxStatus() == CHECK_BOX_DISABLED)
882                         {
883                                 pCheckElement->SetCheckBoxStatus(CHECK_BOX_CHECKED);
884                         }
885                 }
886                 else
887                 {
888                         if (pCheckElement->GetCheckBoxStatus() == CHECK_BOX_CHECKED)
889                         {
890                                 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_MARK)
891                                 {
892                                         pCheckElement->SetCheckBoxStatus(CHECK_BOX_DISABLED);
893                                 }
894                         }
895                 }
896         }
897
898         r = GetCore().SetItemEnabled(mainIndex, -1, enable);
899         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
900
901         return r;
902 }
903
904 bool
905 _ExpandableListImpl::IsItemEnabled(int mainIndex) const
906 {
907         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
908
909         return GetCore().IsItemEnabled(mainIndex, -1);
910 }
911
912 result
913 _ExpandableListImpl::SetSubItemEnabled(int mainIndex, int subIndex, bool enable)
914 {
915         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex(%d)", mainIndex);
916         SysTryReturnResult(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), E_INVALID_ARG, "Invalid argument used. subIndex(%d)", subIndex);
917
918         result r = E_SUCCESS;
919
920         _CheckElementModel* pCheckElement = GetCheckElementAt(mainIndex, subIndex);
921         SysTryReturnResult(NID_UI_CTRL, pCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d) subIndex(%d).", mainIndex, subIndex);
922
923         if (pCheckElement)
924         {
925                 if (enable)
926                 {
927                         if (pCheckElement->GetCheckBoxStatus() == CHECK_BOX_DISABLED)
928                         {
929                                 pCheckElement->SetCheckBoxStatus(CHECK_BOX_CHECKED);
930                         }
931                 }
932                 else
933                 {
934                         if (pCheckElement->GetCheckBoxStatus() == CHECK_BOX_CHECKED)
935                         {
936                                 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_MARK)
937                                 {
938                                         pCheckElement->SetCheckBoxStatus(CHECK_BOX_DISABLED);
939                                 }
940                         }
941                 }
942         }
943
944         r = GetCore().SetItemEnabled(mainIndex, subIndex, enable);
945         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
946
947         return r;
948 }
949
950 bool
951 _ExpandableListImpl::IsSubItemEnabled(int mainIndex, int subIndex) const
952 {
953         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
954
955         SysTryReturn(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. subIndex = %d", subIndex);
956
957         return GetCore().IsItemEnabled(mainIndex, subIndex);
958 }
959
960 result
961 _ExpandableListImpl::SetItemChecked(int groupIndex, int itemIndex, bool check)
962 {
963         if (itemIndex == -1)
964         {
965                 return SetItemChecked(groupIndex, check);
966         }
967         else
968         {
969                 return SetSubItemChecked(groupIndex, itemIndex, check);
970         }
971 }
972
973 result
974 _ExpandableListImpl::SetItemChecked(int mainIndex, bool check)
975 {
976         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
977
978         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "A system error has occurred. The List Style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
979
980         SysTryReturnResult(NID_UI_CTRL, (IsItemEnabled(mainIndex)), E_SYSTEM, "A system error has occurred. The item is not enabled at mainIndex %d.", mainIndex);
981
982         if (IsItemChecked(mainIndex) == check)
983         {
984                 return E_SUCCESS;
985         }
986
987         _CheckElementModel* pCheckElement = GetCheckElementAt(mainIndex, -1);
988         SysTryReturnResult(NID_UI_CTRL, pCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d)", mainIndex);
989
990         if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
991         {
992                 if (_currentRadioGroupIndex != -1)
993                 {
994                         _CheckElementModel* pOldSubCheckElement = GetCheckElementAt(_currentRadioGroupIndex, _currentRadioIndex);
995                         SysTryReturnResult(NID_UI_CTRL, pOldSubCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d) subIndex(%d).", _currentRadioGroupIndex, _currentRadioIndex);
996
997                         pOldSubCheckElement->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
998
999                         DrawItem(_currentRadioGroupIndex, _currentRadioIndex);
1000                 }
1001
1002                 _currentRadioGroupIndex = (check == true) ? mainIndex : -1;
1003                 pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
1004                 _currentRadioIndex = -1;
1005
1006                 return E_SUCCESS;
1007         }
1008
1009         int subCount = GetSubItemCountAt(mainIndex);
1010
1011         if (subCount == 0)
1012         {
1013                 pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
1014         }
1015         else
1016         {
1017                 for (int subItemCount = 0; subItemCount < subCount; subItemCount++)
1018                 {
1019                         SetSubItemChecked(mainIndex, subItemCount, check);
1020                 }
1021         }
1022
1023         return E_SUCCESS;
1024 }
1025
1026 result
1027 _ExpandableListImpl::SetSubItemCheckedRadio(int mainIndex, int subIndex, bool check)
1028 {
1029         if (_currentRadioGroupIndex != -1)
1030         {
1031                 _CheckElementModel* pOldSubCheckElement = GetCheckElementAt(_currentRadioGroupIndex, _currentRadioIndex);
1032                 SysTryReturnResult(NID_UI_CTRL, pOldSubCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d) subIndex(%d).", _currentRadioGroupIndex, _currentRadioIndex);
1033
1034                 pOldSubCheckElement->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
1035
1036                 DrawItem(_currentRadioGroupIndex, _currentRadioIndex);
1037         }
1038
1039         if (check)
1040         {
1041                 _currentRadioGroupIndex = mainIndex;
1042                 _currentRadioIndex = subIndex;
1043         }
1044         else
1045         {
1046                 _currentRadioGroupIndex = -1;
1047                 _currentRadioIndex = -1;
1048         }
1049
1050         _CheckElementModel* pSubCheckElement = GetCheckElementAt(mainIndex, subIndex);
1051         SysTryReturnResult(NID_UI_CTRL, pSubCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d) subIndex(%d).", mainIndex, subIndex);
1052
1053         pSubCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
1054
1055         DrawItem(mainIndex, subIndex);
1056
1057         return E_SUCCESS;
1058 }
1059
1060 result
1061 _ExpandableListImpl::SetSubItemCheckedMarkOnOff(int mainIndex, int subIndex, bool check)
1062 {
1063         _CheckElementModel* pCheckElement = GetCheckElementAt(mainIndex, subIndex);
1064         SysTryReturnResult(NID_UI_CTRL, pCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d) subIndex(%d).", mainIndex, subIndex);
1065
1066         pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
1067
1068         _CheckElementModel* pGroupCheckElement = GetCheckElementAt(mainIndex, -1);
1069         SysTryReturnResult(NID_UI_CTRL, pGroupCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d).", mainIndex);
1070
1071         if ((check) || (GetCheckedItemCountAt(mainIndex) > 0))
1072         {
1073                 pGroupCheckElement->SetCheckBoxStatus(CHECK_BOX_CHECKED);
1074         }
1075         else
1076         {
1077                 pGroupCheckElement->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
1078         }
1079
1080         DrawItem(mainIndex, -1);
1081         DrawItem(mainIndex, subIndex);
1082
1083         return E_SUCCESS;
1084 }
1085
1086 result
1087 _ExpandableListImpl::SetSubItemChecked(int mainIndex, int subIndex, bool check)
1088 {
1089         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1090
1091         SysTryReturnResult(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), E_INVALID_ARG, "Invalid argument used. subIndex = %d", subIndex);
1092
1093         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "A system error has occurred. The List Style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
1094
1095         if (IsSubItemChecked(mainIndex, subIndex) == check)
1096         {
1097                 return E_SUCCESS;
1098         }
1099
1100         if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
1101         {
1102                 return SetSubItemCheckedRadio(mainIndex, subIndex, check);
1103         }
1104         else
1105         {
1106                 return SetSubItemCheckedMarkOnOff(mainIndex, subIndex, check);
1107         }
1108 }
1109
1110 int
1111 _ExpandableListImpl::GetCheckedItemCountAt(int mainIndex) const
1112 {
1113         int totalSubItemCount = GetSubItemCountAt(mainIndex);
1114         int count = 0;
1115
1116         for (int index = 0; index < totalSubItemCount; index++)
1117         {
1118                 if (IsSubItemChecked(mainIndex, index) == true)
1119                 {
1120                         count++;
1121                 }
1122         }
1123
1124         return count;
1125 }
1126
1127 bool
1128 _ExpandableListImpl::IsSubItemChecked(int mainIndex, int subIndex) const
1129 {
1130         SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. list style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL.");
1131
1132         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1133
1134         SysTryReturn(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. subIndex = %d", subIndex);
1135
1136         const _CheckElementModel* pCheckElement = GetCheckElementAt(mainIndex, subIndex);
1137         SysTryReturn(NID_UI_CTRL, pCheckElement, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get checkElement at mainIndex(%d) subIndex(%d).", mainIndex, subIndex);
1138
1139         return (bool)pCheckElement->GetCheckBoxStatus();
1140 }
1141
1142 result
1143 _ExpandableListImpl::SetAllSubItemsChecked(int mainIndex, bool check)
1144 {
1145         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1146
1147         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "A system error has occurred. The List Style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
1148         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_RADIO), E_SYSTEM, "A system error has occurred. The List Style should not be TABLE_VIEW_ANNEX_STYLE_RADIO");
1149
1150         int totalSubItemCount = GetSubItemCountAt(mainIndex);
1151         result r = E_SUCCESS;
1152
1153         for (int subItemCount = 0; subItemCount < totalSubItemCount; subItemCount++)
1154         {
1155                 r = SetSubItemChecked(mainIndex, subItemCount, check);
1156                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
1157         }
1158
1159         return E_SUCCESS;
1160 }
1161
1162 result
1163 _ExpandableListImpl::RemoveAllCheckedSubItemsAt(int mainIndex)
1164 {
1165         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1166
1167         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "A system error has occurred. The List Style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
1168
1169         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_RADIO), E_SYSTEM, "A system error has occurred. The List Style should not be TABLE_VIEW_ANNEX_STYLE_RADIO");
1170
1171         result r = E_SUCCESS;
1172         int totalSubItemCount = GetSubItemCountAt(mainIndex);
1173
1174         for (int subItemCount = 0; subItemCount < totalSubItemCount; subItemCount++)
1175         {
1176                 bool isChecked = IsSubItemChecked(mainIndex, subItemCount);
1177
1178                 if (isChecked)
1179                 {
1180                         r = RemoveSubItemAt(mainIndex, subItemCount);
1181                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to remove item");
1182                 }
1183         }
1184
1185         return E_SUCCESS;
1186 }
1187
1188 int
1189 _ExpandableListImpl::GetFirstCheckedSubItemIndex(int mainIndex) const
1190 {
1191         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");
1192
1193         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1194
1195         int totalSubItemCount = GetSubItemCountAt(mainIndex);
1196
1197         for (int subItemCount = 0; subItemCount < totalSubItemCount; subItemCount++)
1198         {
1199                 if (IsSubItemChecked(mainIndex, subItemCount))
1200                 {
1201                         return subItemCount;
1202                 }
1203         }
1204
1205         return INVALID_INDEX;
1206 }
1207
1208 int
1209 _ExpandableListImpl::GetLastCheckedItemIndex(void) const
1210 {
1211         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");
1212
1213         int count = GetGroupCount();
1214
1215         for (int index = count - 1; index >= 0; index--)
1216         {
1217                 if (IsItemChecked(index))
1218                 {
1219                         return index;
1220                 }
1221         }
1222
1223         return INVALID_INDEX;
1224 }
1225
1226 int
1227 _ExpandableListImpl::GetLastCheckedSubItemIndex(int mainIndex) const
1228 {
1229         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");
1230
1231         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1232
1233         int count = GetSubItemCountAt(mainIndex);
1234
1235         for (int index = count - 1; index >= 0; index--)
1236         {
1237                 if (IsSubItemChecked(mainIndex, index))
1238                 {
1239                         return index;
1240                 }
1241         }
1242         return INVALID_INDEX;
1243 }
1244
1245 int
1246 _ExpandableListImpl::GetNextCheckedItemIndexAfter(int mainIndex) const
1247 {
1248         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");
1249
1250         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1251
1252         for (int index = mainIndex+1; index < GetGroupCount(); index++)
1253         {
1254                 if (IsItemChecked(index))
1255                 {
1256                         return index;
1257                 }
1258         }
1259
1260         return INVALID_INDEX;
1261 }
1262
1263 int
1264 _ExpandableListImpl::GetNextCheckedSubItemIndexAfter(int mainIndex, int subIndex) const
1265 {
1266         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");
1267
1268         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1269         SysTryReturn(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. subIndex = %d", subIndex);
1270
1271         int count = GetSubItemCountAt(mainIndex);
1272
1273         for (int index = subIndex + 1; index < count; index++)
1274         {
1275                 if (IsSubItemChecked(mainIndex, index))
1276                 {
1277                         return index;
1278                 }
1279         }
1280
1281         return INVALID_INDEX;
1282 }
1283
1284 result
1285 _ExpandableListImpl::GetSubItemIndexFromItemId(int itemId, int& mainIndex, int& subIndex) const
1286 {
1287         mainIndex = INVALID_INDEX;
1288         subIndex = INVALID_INDEX;
1289
1290         for (int index = 0; index < GetGroupCount(); index++)
1291         {
1292                 for (int count = 0; count < GetSubItemCountAt(index); count++)
1293                 {
1294                         const CustomListItem* pCustomListItem = GetCustomListItemAt(index, count);
1295                         SysTryReturnResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "A system error has occurred. Failed to get an item at mainIndex(%d) subIndex(%d).", index, count);
1296
1297                         SysTryReturnResult(NID_UI_CTRL, pCustomListItem->__pCustomListItemImpl, E_SYSTEM, "A system error has occurred. Failed to get an item at mainIndex(%d) subIndex(%d).", index, count);
1298
1299                         if (itemId == pCustomListItem->__pCustomListItemImpl->itemId)
1300                         {
1301                                 mainIndex = index;
1302                                 subIndex = count;
1303                                 return E_SUCCESS;
1304                         }
1305                 }
1306         }
1307
1308         return E_OBJ_NOT_FOUND;
1309 }
1310
1311 result
1312 _ExpandableListImpl::ScrollToBottom(void)
1313 {
1314         result r = E_SUCCESS;
1315
1316         int lastGroupIndex = GetGroupCount() - 1;
1317         int lastItemIndex = GetSubItemCountAt(lastGroupIndex) - 1;
1318
1319         r = GetCore().SetBottomDrawnItemIndex(lastGroupIndex, lastItemIndex);
1320         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1321
1322         GetCore().Draw();
1323
1324         return E_SUCCESS;
1325 }
1326 result
1327 _ExpandableListImpl::ScrollToTop(void)
1328 {
1329         result r = E_SUCCESS;
1330
1331         r = GetCore().SetTopDrawnItemIndex(0, -1);
1332         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1333         SetLastResult(E_SUCCESS);
1334
1335         GetCore().Draw();
1336
1337         return r;
1338 }
1339
1340 result
1341 _ExpandableListImpl::ScrollToTop(int mainIndex, int subIndex)
1342 {
1343         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1344         SysTryReturnResult(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), E_INVALID_ARG, "Invalid argument used. subIndex = %d", subIndex);
1345         result r = E_SUCCESS;
1346
1347         r = GetCore().SetTopDrawnItemIndex(mainIndex, subIndex);
1348         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1349
1350         GetCore().Draw();
1351
1352         return r;
1353 }
1354
1355 result
1356 _ExpandableListImpl::ScrollToTop(int mainIndex)
1357 {
1358         SysTryReturn(NID_UI_CTRL, ((mainIndex < GetGroupCount()) && (mainIndex >= 0)), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d.", mainIndex);
1359
1360         result r = E_SUCCESS;
1361
1362         r = GetCore().SetTopDrawnItemIndex(mainIndex, -1);
1363         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1364
1365         GetCore().Draw();
1366
1367         return r;
1368 }
1369
1370 void
1371 _ExpandableListImpl::SetBgColor(const Color& color)
1372 {
1373         GetCore().SetBackgroundColor(color);
1374         return;
1375 }
1376
1377 result
1378 _ExpandableListImpl::RefreshItem(int mainIndex)
1379 {
1380         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d.", mainIndex);
1381
1382         int topGroupIndex = -1;
1383         int bottomGroupIndex = -1;
1384         int itemIndex = -1;
1385
1386         GetCore().GetTopDrawnItemIndex(topGroupIndex, itemIndex);
1387         GetCore().GetBottomDrawnItemIndex(bottomGroupIndex, itemIndex);
1388
1389         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= topGroupIndex && mainIndex <= bottomGroupIndex), E_INVALID_OPERATION, "Index should be within drawn item range %d.", mainIndex);
1390
1391         result r = E_SUCCESS;
1392
1393         int count = GetSubItemCountAt(mainIndex);
1394         for (int indexItem = 0; indexItem < count; indexItem++)
1395         {
1396                 r = RefreshSubItem(mainIndex, indexItem);
1397                 if (r != E_SUCCESS)
1398                 {
1399                         SysLog(NID_UI_CTRL, "Not able to refresh item with index %d %d.", mainIndex, indexItem);
1400                 }
1401         }
1402
1403         return E_SUCCESS;
1404 }
1405
1406 result
1407 _ExpandableListImpl::RefreshSubItem(int mainIndex, int subIndex)
1408 {
1409         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1410         SysTryReturnResult(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), E_INVALID_ARG, "Invalid argument used. subIndex = %d", subIndex);
1411
1412         int topItemIndex = -1;
1413         int bottomItemIndex = -1;
1414         int groupItemIndex = -1;
1415
1416         GetCore().GetTopDrawnItemIndex(groupItemIndex, topItemIndex);
1417         GetCore().GetBottomDrawnItemIndex(groupItemIndex, bottomItemIndex);
1418
1419         SysTryReturnResult(NID_UI_CTRL, (subIndex >= topItemIndex && subIndex <= bottomItemIndex), E_INVALID_OPERATION,
1420                         "Index should be within drawn item range %d.", subIndex);
1421
1422         result r = E_SUCCESS;
1423
1424         CustomListItem* pCustomListItem = GetCustomListItemAt(mainIndex, subIndex);
1425         SysTryReturn(NID_UI_CTRL, pCustomListItem, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at mainIndex(%d) subIndex(%d).", mainIndex, subIndex);
1426
1427         _TableViewItemUpdateParams updateParams;
1428         updateParams.pItem = pCustomListItem;
1429         updateParams.isDividerEnabled = _isDividerEnabled;
1430         updateParams.pCheckBitmaps = _pCheckBitmaps;
1431         updateParams.annexStyle = _annexStyle;
1432
1433         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
1434         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "A system error has occurred. Failed to refresh an item.");
1435
1436         _TableViewItemData* pTableViewItemData = pCustomListItem->__pCustomListItemImpl->__pTableViewItemData;
1437         SysTryReturn(NID_UI_CTRL, pTableViewItemData, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at mainIndex(%d) subIndex(%d).", mainIndex, subIndex);
1438
1439         pTableViewItemData->Invalidate(true);
1440
1441         return E_SUCCESS;
1442 }
1443
1444 int
1445 _ExpandableListImpl::GetCheckedItemCount(int mainIndex)
1446 {
1447         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), 0, E_INVALID_ARG, "[E_INVALID_ARG] The groupIndex %d is invalid", mainIndex);
1448
1449         _TableViewGroupItemData* pGroupItem = GetTableViewGroupItemAt(mainIndex);
1450         SysTryReturn(NID_UI_CTRL, pGroupItem, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get GroupItem at %d index.", mainIndex);
1451
1452         int checkedCount = 0;
1453         int subItemCount = GetSubItemCountAt(mainIndex);
1454
1455         for (int itemCount = 0; itemCount < subItemCount; itemCount++)
1456         {
1457                 if (IsSubItemChecked(mainIndex, itemCount) == true)
1458                 {
1459                         checkedCount++;
1460                 }
1461         }
1462
1463         return checkedCount;
1464 }
1465
1466 bool
1467 _ExpandableListImpl::IsItemExpanded(int mainIndex) const
1468 {
1469         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1470
1471         if (GetCore().GetFirstDrawnFlag())
1472         {
1473                 Boolean* pIsExpanded = dynamic_cast<Boolean*>(const_cast<Object*>(__groupExpandStateList.GetAt(mainIndex)));
1474                 SysTryReturn(NID_UI_CTRL, pIsExpanded, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get expanded state at index(%d).", mainIndex);
1475
1476                 return pIsExpanded->ToBool();
1477
1478         }
1479
1480         return (GetCore().IsGroupExpanded(mainIndex));
1481 }
1482
1483 void
1484 _ExpandableListImpl::OnTableViewItemStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1485 {
1486         return;
1487 }
1488
1489 void
1490 _ExpandableListImpl::OnTableViewContextItemActivationStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pContextItem, bool activated)
1491 {
1492         return;
1493 }
1494
1495 void
1496 _ExpandableListImpl::OnTableViewItemReordered(_TableView& tableView, int itemIndexFrom, int itemIndexTo)
1497 {
1498         return;
1499 }
1500
1501 void
1502 _ExpandableListImpl::OnGroupedTableViewGroupItemStateChanged(_TableView& tableView, int groupIndex, _TableViewItem* pItem, TableViewItemStatus status)
1503 {
1504         CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, -1);
1505         SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", groupIndex);
1506
1507         CustomListItemStatus customListItemStatus = CUSTOM_LIST_ITEM_STATUS_NORMAL;
1508         ItemStatus itemStatus = ITEM_HIGHLIGHTED;
1509
1510         switch (status)
1511         {
1512         case TABLE_VIEW_ITEM_STATUS_SELECTED:
1513                 itemStatus = ITEM_SELECTED;
1514                 customListItemStatus = CUSTOM_LIST_ITEM_STATUS_SELECTED;
1515                 break;
1516         case TABLE_VIEW_ITEM_STATUS_HIGHLIGHTED:
1517                 itemStatus = ITEM_HIGHLIGHTED;
1518                 customListItemStatus = CUSTOM_LIST_ITEM_STATUS_FOCUSED;
1519                 break;
1520         case TABLE_VIEW_ITEM_STATUS_CHECKED:
1521                 itemStatus = ITEM_CHECKED;
1522                 break;
1523         case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
1524                 itemStatus = ITEM_UNCHECKED;
1525                 break;
1526         default:
1527                 SetLastResult(E_SYSTEM);
1528                 return;
1529         }
1530
1531         LinkedList* pElements = &pCustomListItem->__pCustomListItemImpl->elements;
1532         _ElementBaseModel* pElementBase = null;
1533
1534         for (int i = 0; i < pElements->GetCount(); i++)
1535         {
1536                 pElementBase = dynamic_cast<_ElementBaseModel*>(pElements->GetAt(i));
1537                 SysTryReturnVoidResult(NID_UI_CTRL, (pElementBase != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get valid element at index %d.", i);
1538
1539                 if (pElementBase->_elementType != LIST_ITEM_ELEMENT_TYPE_CHECKBOX)
1540                 {
1541                         pElementBase->HandleElementEvent(customListItemStatus);
1542                 }
1543         }
1544
1545         if ((!_isDividerEnabled) && (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL))
1546         {
1547                 bool isChecked = false;
1548                 isChecked = IsItemChecked(groupIndex);
1549
1550                 if (isChecked)
1551                 {
1552                         itemStatus = ITEM_UNCHECKED;
1553                 }
1554                 else
1555                 {
1556                         itemStatus = ITEM_CHECKED;
1557                 }
1558
1559                 SetItemChecked(groupIndex, !isChecked);
1560         }
1561
1562         ProcessItemStateChange(groupIndex, -1, itemStatus);
1563
1564         return;
1565 }
1566
1567
1568 void
1569 _ExpandableListImpl::OnGroupedTableViewItemStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1570 {
1571         CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, itemIndex);
1572         SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at groupIndex(%d), itemIndex(%d).", groupIndex, itemIndex);
1573
1574         CustomListItemStatus customListItemStatus = CUSTOM_LIST_ITEM_STATUS_NORMAL;
1575         ItemStatus itemStatus = ITEM_HIGHLIGHTED;
1576         result r = E_SUCCESS;
1577
1578         switch (status)
1579         {
1580         case TABLE_VIEW_ITEM_STATUS_SELECTED:
1581                 itemStatus = ITEM_SELECTED;
1582                 customListItemStatus = CUSTOM_LIST_ITEM_STATUS_SELECTED;
1583                 break;
1584         case TABLE_VIEW_ITEM_STATUS_HIGHLIGHTED:
1585                 itemStatus = ITEM_HIGHLIGHTED;
1586                 customListItemStatus = CUSTOM_LIST_ITEM_STATUS_FOCUSED;
1587                 break;
1588         case TABLE_VIEW_ITEM_STATUS_CHECKED:
1589                 itemStatus = ITEM_CHECKED;
1590                 break;
1591         case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
1592                 itemStatus = ITEM_UNCHECKED;
1593                 break;
1594         default:
1595                 SetLastResult(E_SYSTEM);
1596                 break;
1597         }
1598
1599         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[E_SYSTEM] A system error has occurred. ListItemStatus is invalid");
1600
1601         LinkedList* pElements = &pCustomListItem->__pCustomListItemImpl->elements;
1602         _ElementBaseModel* pElementBase = null;
1603
1604         for (int i = 0; i < pElements->GetCount(); i++)
1605         {
1606                 pElementBase = dynamic_cast<_ElementBaseModel*>(pElements->GetAt(i));
1607                 SysTryReturnVoidResult(NID_UI_CTRL, (pElementBase != null), E_SYSTEM, "Invalid element.");
1608
1609                 if (pElementBase->_elementType != LIST_ITEM_ELEMENT_TYPE_CHECKBOX)
1610                 {
1611                         pElementBase->HandleElementEvent(customListItemStatus);
1612                 }
1613         }
1614
1615         if ((!_isDividerEnabled) && (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL))
1616         {
1617                 bool isChecked = false;
1618                 isChecked = IsSubItemChecked(groupIndex, itemIndex);
1619
1620                 if (isChecked)
1621                 {
1622                         itemStatus = ITEM_UNCHECKED;
1623                 }
1624                 else
1625                 {
1626                         itemStatus = ITEM_CHECKED;
1627                 }
1628
1629                 SetSubItemChecked(groupIndex, itemIndex, !isChecked);
1630         }
1631
1632         ProcessItemStateChange(groupIndex, itemIndex, itemStatus);
1633
1634         return;
1635 }
1636
1637 void
1638 _ExpandableListImpl::OnGroupedTableViewContextItemActivationStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
1639 {
1640         return;
1641 }
1642
1643 void
1644 _ExpandableListImpl::OnGroupedTableViewItemReordered(_TableView& tableView, int groupIndexFrom, int itemIndexFrom, int groupIndexTo, int itemIndexTo)
1645 {
1646         return;
1647 }
1648
1649 void
1650 _ExpandableListImpl::OnSectionTableViewItemStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1651 {
1652         return;
1653 }
1654
1655 void
1656 _ExpandableListImpl::OnSectionTableViewContextItemActivationStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
1657 {
1658         return;
1659 }
1660
1661 void
1662 _ExpandableListImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
1663 {
1664         return;
1665 }
1666
1667 void
1668 _ExpandableListImpl::OnTouchPressed (const Control &source, const Point &currentPosition, const TouchEventInfo &touchInfo)
1669 {
1670         Label* pArrowLabel = dynamic_cast<Label*>(const_cast<Control*>(&source));
1671
1672         if (pArrowLabel)
1673         {
1674                 _TableViewGroupItemData* pTableViewGroupItemData = dynamic_cast<_TableViewGroupItemData*>(pArrowLabel->GetParent());
1675                 SysTryReturnVoidResult(NID_UI_CTRL, (pTableViewGroupItemData != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get arrow icon.");
1676
1677                 if (GetCore().IsGroupExpanded(pTableViewGroupItemData->groupIndex))
1678                 {
1679                         GetCore().CollapseGroup(pTableViewGroupItemData->groupIndex);
1680                         pArrowLabel->SetBackgroundBitmap(*__pOpenedImage);
1681                 }
1682                 else
1683                 {
1684                         GetCore().ExpandGroup(pTableViewGroupItemData->groupIndex);
1685                         pArrowLabel->SetBackgroundBitmap(*__pClosedImage);
1686                 }
1687
1688                 pArrowLabel->Invalidate(true);
1689         }
1690         else
1691         {
1692                 _ListBaseImpl::OnTouchPressed(source, currentPosition, touchInfo);
1693         }
1694         return;
1695 }
1696
1697 void
1698 _ExpandableListImpl::ProcessItemStateChange(int mainIndex, int subIndex, int elementId, ItemStatus itemStatus)
1699 {
1700         int itemId = -1;
1701         if (subIndex == -1 )
1702         {
1703                 itemId = GetItemIdAt(mainIndex);
1704         }
1705         else
1706         {
1707                 itemId = GetSubItemIdAt(mainIndex, subIndex);
1708         }
1709
1710         _ListListener* pListenerList = null;
1711         IExpandableItemEventListener* pEventListener = null;
1712
1713         for (int listenerCount = 0; listenerCount < __itemListenersList.GetCount(); listenerCount++)
1714         {
1715                 pListenerList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
1716                 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerList != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get ListListener");
1717
1718                 pEventListener = dynamic_cast<IExpandableItemEventListener*>(pListenerList->pListener);
1719                 SysTryReturnVoidResult(NID_UI_CTRL, (pEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get EventListener");
1720
1721                 pEventListener->OnItemStateChanged(GetPublic(), mainIndex, subIndex, itemId, elementId, itemStatus);
1722         }
1723         SetLastResult(E_SUCCESS);
1724         return;
1725 }
1726
1727 void
1728 _ExpandableListImpl::ProcessItemStateChange(int mainIndex, int subIndex, ItemStatus itemStatus)
1729 {
1730         int itemId = -1;
1731         if (subIndex == -1 )
1732         {
1733                 itemId = GetItemIdAt(mainIndex);
1734         }
1735         else
1736         {
1737                 itemId = GetSubItemIdAt(mainIndex, subIndex);
1738         }
1739
1740         _ListListener* pListenerList = null;
1741         IExpandableItemEventListener* pEventListener = null;
1742
1743         for (int listenerCount = 0; listenerCount < __itemListenersList.GetCount(); listenerCount++)
1744         {
1745                 pListenerList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
1746                 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerList != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get ListListener");
1747
1748                 pEventListener = dynamic_cast<IExpandableItemEventListener*>(pListenerList->pListener);
1749                 SysTryReturnVoidResult(NID_UI_CTRL, (pEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get EventListener");
1750
1751                 pEventListener->OnItemStateChanged(GetPublic(), mainIndex, subIndex, itemId, itemStatus);
1752         }
1753         SetLastResult(E_SUCCESS);
1754         return;
1755 }
1756
1757 void
1758 _ExpandableListImpl::OnDraw(void)
1759 {
1760         if (GetCore().GetFirstDrawnFlag())
1761         {
1762                 _ListBaseImpl::OnDraw();
1763
1764                 int mainItemCount = GetGroupCount();
1765
1766                 for (int mainIndex = 0; mainIndex < mainItemCount; mainIndex++)
1767                 {
1768                         Boolean* pIsExpanded = dynamic_cast<Boolean*>(__groupExpandStateList.GetAt(mainIndex));
1769                         SysTryReturnVoidResult(NID_UI_CTRL, pIsExpanded, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get expanded state at index(%d).", mainIndex);
1770
1771                         if (!pIsExpanded->ToBool())
1772                         {
1773                                 SetItemExpanded(mainIndex, false);
1774                         }
1775                 }
1776
1777                 GetCore().UpdateTableView();
1778         }
1779         else
1780         {
1781                 _ListBaseImpl::OnDraw();
1782         }
1783
1784         return;
1785 }
1786
1787 void
1788 _ExpandableListImpl::DeleteExpandStateFlag(Object* pObj)
1789 {
1790         Boolean* pExpanded = null;
1791         pExpanded = dynamic_cast<Boolean*>(pObj);
1792         delete pExpanded;
1793         return;
1794 }
1795
1796 class _ExpandableListMaker
1797         : public _UiBuilderControlMaker
1798 {
1799 public:
1800         _ExpandableListMaker(_UiBuilder* uibuilder)
1801                 : _UiBuilderControlMaker(uibuilder){};
1802         virtual ~_ExpandableListMaker(){};
1803         static _UiBuilderControlMaker*
1804         GetInstance(_UiBuilder* uibuilder)
1805         {
1806                 _ExpandableListMaker* pExpandableListMaker = new (std::nothrow) _ExpandableListMaker(uibuilder);
1807
1808                 return pExpandableListMaker;
1809         };
1810 protected:
1811         virtual Control*
1812         Make(_UiBuilderControl* pControl)
1813         {
1814                 result r = E_SYSTEM;
1815                 _UiBuilderControlLayout* pControlProperty = null;
1816                 ExpandableList* pExpandableList = null;
1817                 Rectangle rect;
1818                 Rectangle rectMin;
1819                 Dimension dimMin;
1820                 CustomListStyle style = CUSTOM_LIST_STYLE_NORMAL;
1821                 Tizen::Base::String elementString;
1822                 bool isItemDivider = true;
1823                 Color color;
1824
1825                 GetProperty(pControl, &pControlProperty);
1826                 if (pControlProperty == null)
1827                 {
1828                         return null;
1829                 }
1830
1831                 pExpandableList = new (std::nothrow) ExpandableList();
1832                 if (pExpandableList == null)
1833                 {
1834                         return null;
1835                 }
1836
1837                 rect = pControlProperty->GetRect();
1838                 Tizen::Base::String styleString;
1839                 styleString = pControlProperty->GetStyle();
1840
1841                 if (styleString.Equals(L"CUSTOM_LIST_STYLE_NORMAL", false))
1842                 {
1843                         style = CUSTOM_LIST_STYLE_NORMAL;
1844                 }
1845                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO", false))
1846                 {
1847                         style = CUSTOM_LIST_STYLE_RADIO;
1848                 }
1849                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER", false))
1850                 {
1851                         style = CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER;
1852                 }
1853                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK", false))
1854                 {
1855                         style = CUSTOM_LIST_STYLE_MARK;
1856                 }
1857                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER", false))
1858                 {
1859                         style = CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER;
1860                 }
1861                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF", false))
1862                 {
1863                         style = CUSTOM_LIST_STYLE_ONOFF;
1864                 }
1865                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER", false))
1866                 {
1867                         style = CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER;
1868                 }
1869                 else
1870                 {
1871                         style = CUSTOM_LIST_STYLE_NORMAL;
1872                 }
1873
1874                 if (pControl->GetElement(L"itemDivider", elementString))
1875                 {
1876                         if (elementString.Equals(L"true", false))
1877                         {
1878                                 isItemDivider = true;
1879                         }
1880                         else
1881                         {
1882                                 isItemDivider = false;
1883                         }
1884                 }
1885
1886                 r = pExpandableList->Construct(rect, style, isItemDivider);
1887                 if (r != E_SUCCESS)
1888                 {
1889                         delete pExpandableList;
1890                         return null;
1891                 }
1892
1893                 if (pControl->GetElement(L"textOfEmptyList", elementString))
1894                 {
1895                         pExpandableList->SetTextOfEmptyList(elementString);
1896                 }
1897
1898                 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
1899                 {
1900                         ConvertStringToColor(elementString, color);
1901                         pExpandableList->SetTextColorOfEmptyList(color);
1902                 }
1903                 GET_DIMENSION_CONFIG(LIST::LIST_MIN_SIZE, _CONTROL_ORIENTATION_PORTRAIT, dimMin);
1904                 rectMin = (pControl->GetAttribute(0))->GetRect();
1905                 (pControl->GetAttribute(0))->SetRect(rectMin.x, rectMin.y, dimMin.width, dimMin.height);
1906
1907                 GET_DIMENSION_CONFIG(LIST::LIST_MIN_SIZE, _CONTROL_ORIENTATION_LANDSCAPE, dimMin);
1908                 rectMin = (pControl->GetAttribute(1))->GetRect();
1909                 (pControl->GetAttribute(1))->SetRect(rectMin.x, rectMin.y, dimMin.width, dimMin.height);
1910
1911                 return pExpandableList;
1912         }
1913
1914 private:
1915 };
1916
1917 _ExpandableListRegister::_ExpandableListRegister()
1918 {
1919         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1920
1921         if (pUiBuilderControlTableManager)
1922         {
1923                 pUiBuilderControlTableManager->RegisterControl(L"ExpandableList", _ExpandableListMaker::GetInstance);
1924         }
1925 }
1926 _ExpandableListRegister::~_ExpandableListRegister()
1927 {
1928         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1929
1930         if (pUiBuilderControlTableManager)
1931         {
1932                 pUiBuilderControlTableManager->UnregisterControl(L"ExpandableList");
1933         }
1934 }
1935 static _ExpandableListRegister ExpandableListRegisterToUiBuilder;
1936 }}} //Tizen::Ui::Controls