Merge "Adding multi-window support to DumpVeLayout()" into tizen_2.1
[platform/framework/native/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 _ExpandableListArrowBitmap::_ExpandableListArrowBitmap(void)
252         : __pNormalBitmap(null)
253         , __pEffectBitmap(null)
254 {
255 }
256
257 _ExpandableListArrowBitmap::~_ExpandableListArrowBitmap(void)
258 {
259 }
260
261 void
262 _ExpandableListArrowBitmap::SetBitmap(const Bitmap &pNormalBitmap, const Bitmap *pEffectBitmap)
263 {
264         __pNormalBitmap = &pNormalBitmap;
265         __pEffectBitmap = pEffectBitmap;
266
267         return;
268 }
269
270 result
271 _ExpandableListArrowBitmap::OnDraw(void)
272 {
273         SysTryReturn(NID_UI_CTRL, (__pNormalBitmap), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Normal Arrow bitmap is null.");
274
275         result r = E_SUCCESS;
276
277         Canvas* pCanvas = null;
278         pCanvas = GetCanvasN();
279
280         r  = GetLastResult();
281         SysTryReturn(NID_UI_CTRL, (pCanvas != null), r, r, "[%s] Propagating.", GetErrorMessage(r));
282
283         const Rectangle bounds = GetBounds();
284
285         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pNormalBitmap))
286         {
287                 r = pCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, bounds.width, bounds.height), *__pNormalBitmap);
288         }
289         else
290         {
291                 r = pCanvas->DrawBitmap(Rectangle(0, 0, bounds.width, bounds.height), *__pNormalBitmap);
292         }
293
294         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
295
296         if (__pEffectBitmap != null)
297         {
298                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pEffectBitmap))
299                 {
300                         r = pCanvas->DrawNinePatchedBitmap(Rectangle(0, 0, bounds.width, bounds.height), *__pEffectBitmap);
301                 }
302
303                 else
304                 {
305                         r = pCanvas->DrawBitmap(Rectangle(0, 0, bounds.width, bounds.height), *__pEffectBitmap);
306                 }
307
308                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
309         }
310
311         delete pCanvas;
312         return E_SUCCESS;
313
314 CATCH:
315         delete pCanvas;
316         return E_SYSTEM;
317 }
318
319 _ExpandableListImpl*
320 _ExpandableListImpl::GetInstance(ExpandableList& expandableList)
321 {
322         return static_cast<_ExpandableListImpl*>(expandableList._pControlImpl);
323 }
324
325 const _ExpandableListImpl*
326 _ExpandableListImpl::GetInstance(const ExpandableList& expandableList)
327 {
328         return static_cast<const _ExpandableListImpl*>(expandableList._pControlImpl);
329 }
330
331 _ExpandableListImpl::_ExpandableListImpl(Control* pList, _TableView* pCore)
332         : _ListBaseImpl(pList, pCore)
333         , __pOpenedImage(null)
334         , __pClosedImage(null)
335         , __pEffectClosedImage(null)
336         , __pEffectOpenedImage(null)
337         , __pItemProvider(null)
338         , __directDelete(false)
339         , __groupExpandStateList(DeleteExpandStateFlag)
340 {
341 }
342
343 _ExpandableListImpl::~_ExpandableListImpl(void)
344 {
345         GetCore().SetItemProvider(null);
346
347         int count = GetItemCount();
348
349         for (int index = 0; index < count; index++)
350         {
351                 RemoveFromSubItemsList(index);
352         }
353
354         RemoveAllFromItemsList();
355
356         __groupExpandStateList.RemoveAll(true);
357
358         __itemListenersList.RemoveAll(true);
359
360         delete __pOpenedImage;
361         __pOpenedImage = null;
362
363         delete __pClosedImage;
364         __pClosedImage = null;
365
366         delete __pItemProvider;
367         __pItemProvider = null;
368
369         delete __pEffectOpenedImage;
370         __pEffectOpenedImage = null;
371
372         delete __pEffectClosedImage;
373         __pEffectClosedImage = null;
374
375         delete __pOpenedDisabledImage;
376         __pOpenedDisabledImage = null;
377
378         delete __pOpenedPressedImage;
379         __pOpenedPressedImage = null;
380
381         delete __pClosedDisabledImage;
382         __pClosedDisabledImage = null;
383
384         delete __pClosedPressedImage;
385         __pClosedPressedImage = null;
386
387 }
388
389 const char*
390 _ExpandableListImpl::GetPublicClassName(void) const
391 {
392         return "ExpandableList";
393 }
394
395 const ExpandableList&
396 _ExpandableListImpl::GetPublic(void) const
397 {
398         return static_cast<const ExpandableList&>(_ControlImpl::GetPublic());
399 }
400
401 ExpandableList&
402 _ExpandableListImpl::GetPublic(void)
403 {
404         return static_cast<ExpandableList&>(_ControlImpl::GetPublic());
405 }
406
407 const _TableView&
408 _ExpandableListImpl::GetCore(void) const
409 {
410         return static_cast<const _TableView&>(_ControlImpl::GetCore());
411 }
412
413 _TableView&
414 _ExpandableListImpl::GetCore(void)
415 {
416         return static_cast<_TableView&>(_ControlImpl::GetCore());
417 }
418
419 _ExpandableListImpl*
420 _ExpandableListImpl::CreateExpandableListImplN(ExpandableList* pControl, const Rectangle& bounds, bool itemDivider)
421 {
422         result r = E_SUCCESS;
423
424         r = GET_SIZE_INFO(ExpandableList).CheckInitialSizeValid(Dimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
425         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
426
427         _TableView* pCore = _TableView::CreateTableViewN(TABLE_VIEW_STYLE_GROUPED, true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
428
429         r = GetLastResult();
430         SysTryReturn(NID_UI_CTRL, pCore, null, r, "[%s] Propagating.", GetErrorMessage(r));
431
432         _ExpandableListImpl* pImpl = new (std::nothrow) _ExpandableListImpl(pControl, pCore);
433         SysTryCatch(NID_UI_CTRL, pImpl, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
434
435         pCore->SetItemDividerEnabled(itemDivider);
436
437         r = pCore->SetScrollStyle(TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
438         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
439         ClearLastResult();
440
441         return pImpl;
442
443 CATCH:
444         delete pCore;
445         delete pImpl;
446         return null;
447 }
448
449 result
450 _ExpandableListImpl::UpdateBounds(const Rectangle& rect)
451 {
452         result r = E_SUCCESS;
453
454         r = InitializeBoundsProperties(GET_SIZE_INFO(CustomList), rect, GetCore().GetOrientation());
455         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
456
457         return E_SUCCESS;
458 }
459
460 result
461 _ExpandableListImpl::Initialize(void)
462 {
463         result r = E_SUCCESS;
464
465         __pItemProvider = new (std::nothrow) _ExpandableListItemDataProvider(this);
466         SysTryReturnResult(NID_UI_CTRL, (__pItemProvider != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
467
468         TableViewStyle style = GetCore().GetTableViewStyle();
469         SysTryReturnResult(NID_UI_CTRL, style == TABLE_VIEW_STYLE_GROUPED, E_INVALID_OPERATION, "The style of TableView is not TABLE_VIEW_STYLE_GROUPED");
470
471         _TableViewItemProvider* pItemProvider = _TableViewItemProvider::CreateTableViewItemProviderN(style);
472         SysTryReturnResult(NID_UI_CTRL, pItemProvider != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
473
474         r = pItemProvider->SetGroupedStyleItemProvider(__pItemProvider);
475
476         if (r != E_SUCCESS)
477         {
478                 delete pItemProvider;
479                 SysTryReturn(NID_UI_CTRL, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
480         }
481
482         r = GetCore().SetItemProvider(pItemProvider);
483         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
484
485         r = GetCore().AddGroupedTableViewItemEventListener(*this);
486         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
487
488         r = LoadArrowBitmap();
489         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
490
491         GET_COLOR_CONFIG(LIST::EXPANDABLELIST_SUB_ITEM_BG_COLOR, __subItemBgColor);
492
493         return r;
494 }
495
496 result
497 _ExpandableListImpl::CreateArrowIcon(int groupIndex)
498 {
499         int size = __pOpenedImage->GetWidth();
500         result r = E_SUCCESS;
501
502         bool isEnabled = true;
503
504         isEnabled = IsItemEnabled(groupIndex);
505
506         _TableViewGroupItemData* pTableViewGroupItemData = GetTableViewGroupItemAt(groupIndex);
507         SysTryReturnResult(NID_UI_CTRL, pTableViewGroupItemData, E_SYSTEM, "A system error has occurred. Failed to get GroupItemData at %d index.", groupIndex);
508
509         _ExpandableListArrowBitmap* pArrowIcon = null;
510         pArrowIcon = dynamic_cast<_ExpandableListArrowBitmap*>(pTableViewGroupItemData->GetControl(ARROW_ELEMENT_NAME));
511
512         if (pArrowIcon == null)
513         {
514                 _ExpandableListArrowBitmap* pArrowIcon = new (std::nothrow) _ExpandableListArrowBitmap();
515                 SysTryReturn(NID_UI_CTRL, pArrowIcon, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
516
517                 r = pArrowIcon->Construct(Rectangle((GetCore().GetBounds().width - (size + _EXPANDABLE_ARROW_X_POSITION)), _EXPANDABLE_ARROW_Y_POSITION, size, size), GROUP_STYLE_NONE);
518                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
519
520                 pArrowIcon->SetName(ARROW_ELEMENT_NAME);
521
522                 Boolean* pIsExpanded = dynamic_cast<Boolean*>(const_cast<Object*>(__groupExpandStateList.GetAt(groupIndex)));
523                 bool isCustomBitmap = false;
524                 if (isEnabled)
525                 {
526                         if (pIsExpanded && pIsExpanded->ToBool())
527                         {
528                                 isCustomBitmap = IS_CUSTOM_BITMAP(LIST::BUTTON_EXPAND_GROUP);
529                                 if (isCustomBitmap)
530                                 {
531                                         pArrowIcon->SetBitmap(*__pClosedImage);
532                                 }
533                                 else
534                                 {
535                                         pArrowIcon->SetBitmap(*__pClosedImage, __pEffectClosedImage);
536                                 }
537                         }
538                         else
539                         {
540                                 isCustomBitmap = IS_CUSTOM_BITMAP(LIST::BUTTON_COLLAPSE_GROUP);
541
542                                 if (isCustomBitmap)
543                                 {
544                                         pArrowIcon->SetBitmap(*__pOpenedImage);
545                                 }
546                                 else
547                                 {
548                                         pArrowIcon->SetBitmap(*__pOpenedImage, __pEffectOpenedImage);
549                                 }
550
551                         }
552                 }
553                 else
554                 {
555                         if (pIsExpanded && pIsExpanded->ToBool())
556                         {
557                                 isCustomBitmap = IS_CUSTOM_BITMAP(LIST::BUTTON_EXPAND_GROUP);
558                                 if (isCustomBitmap)
559                                 {
560                                         pArrowIcon->SetBitmap(*__pClosedDisabledImage);
561                                 }
562                                 else
563                                 {
564                                         pArrowIcon->SetBitmap(*__pClosedDisabledImage, __pEffectClosedImage);
565                                 }
566                         }
567                         else
568                         {
569                                 isCustomBitmap = IS_CUSTOM_BITMAP(LIST::BUTTON_COLLAPSE_GROUP);
570
571                                 if (isCustomBitmap)
572                                 {
573                                         pArrowIcon->SetBitmap(*__pOpenedDisabledImage);
574                                 }
575                                 else
576                                 {
577                                         pArrowIcon->SetBitmap(*__pOpenedDisabledImage, __pEffectOpenedImage);
578                                 }
579                         }
580                 }
581
582                 pArrowIcon->AddTouchEventListener(*this);
583
584                 pTableViewGroupItemData->AddControl(*pArrowIcon);
585                 pTableViewGroupItemData->SetIndividualSelectionEnabled(pArrowIcon, true);
586         }
587
588         return E_SUCCESS;
589 }
590
591 result
592 _ExpandableListImpl::LoadArrowBitmap(void)
593 {
594         result r = E_SUCCESS;
595         Bitmap* pTempBitmap = null;
596         Color normalColor;
597         Color disabledColor;
598         Color pressedColor;
599
600         GET_COLOR_CONFIG(TABLEVIEW::EXPANDABLE_ARROW_NORMAL, normalColor);
601         GET_COLOR_CONFIG(TABLEVIEW::EXPANDABLE_ARROW_DISABLED, disabledColor);
602         GET_COLOR_CONFIG(TABLEVIEW::EXPANDABLE_ARROW_PRESSED, pressedColor);
603
604         r = GET_BITMAP_CONFIG_N(LIST::BUTTON_COLLAPSE_GROUP, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
605         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Failed to fetch Arrow Bitmap");
606         __pOpenedImage = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), normalColor);
607         __pOpenedDisabledImage = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), disabledColor);
608         __pOpenedPressedImage = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), pressedColor);
609
610         delete pTempBitmap;
611         pTempBitmap = null;
612
613         r = GET_BITMAP_CONFIG_N(LIST::BUTTON_EXPAND_GROUP, BITMAP_PIXEL_FORMAT_ARGB8888, pTempBitmap);
614         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Failed to fetch Arrow Bitmap");
615         __pClosedImage = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), normalColor);
616         __pClosedDisabledImage = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), disabledColor);
617         __pClosedPressedImage = _BitmapImpl::GetColorReplacedBitmapN(*pTempBitmap, Color::GetColor(COLOR_ID_MAGENTA), pressedColor);
618
619         delete pTempBitmap;
620         pTempBitmap = null;
621
622         r = GET_BITMAP_CONFIG_N(TABLEVIEW::BUTTON_EXPAND_CLOSED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pEffectOpenedImage);
623         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Failed to fetch Arrow effect Bitmap");
624
625         r = GET_BITMAP_CONFIG_N(TABLEVIEW::BUTTON_EXPAND_OPENED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pEffectClosedImage);
626         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Failed to fetch Arrow effect Bitmap");
627
628         return r;
629 }
630
631 result
632 _ExpandableListImpl::AddExpandableItemEventListener(const IExpandableItemEventListener& listener)
633 {
634         _ListListener* pListenersList = new (std::nothrow) _ListListener();
635
636         SysTryReturn(NID_UI_CTRL, pListenersList, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
637
638         pListenersList->pListener = const_cast<IExpandableItemEventListener*>(&listener);
639         __itemListenersList.Add(*pListenersList);
640
641         return E_SUCCESS;
642 }
643
644 result
645 _ExpandableListImpl::RemoveExpandableItemEventListener(const IExpandableItemEventListener& listener)
646 {
647         _ListListener* pListenersList = null;
648         result r = E_SYSTEM;
649         int count = __itemListenersList.GetCount();
650
651         for (int listenerCount = 0; listenerCount < count; listenerCount++)
652         {
653                 pListenersList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
654
655                 if ((pListenersList != null) && (pListenersList->pListener == &listener))
656                 {
657                         r = E_SUCCESS;
658                         __itemListenersList.RemoveAt(listenerCount, true);
659                         break;
660                 }
661         }
662
663         return r;
664 }
665
666 result
667 _ExpandableListImpl::AddItem(const CustomListItem& item, int itemId)
668 {
669         return InsertItemAt(GetGroupCount(), item, itemId);
670 }
671
672 result
673 _ExpandableListImpl::InsertItemAt(int mainIndex, const CustomListItem& item, int itemId)
674 {
675         result r = E_SUCCESS;
676
677         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex <= GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
678
679         item.__pCustomListItemImpl->itemId = itemId;
680
681         Boolean* pIsExpanded = new Boolean(false);
682         SysTryReturn(NID_UI_CTRL, pIsExpanded, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
683
684         __groupExpandStateList.InsertAt(*pIsExpanded, mainIndex);
685
686         r = InsertIntoItemsList(item, mainIndex, -1);
687         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
688
689         r = GetCore().RefreshTableView(mainIndex, -1, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
690         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
691
692         if (GetCore().GetFirstDrawnFlag() == false)
693         {
694                 SetItemExpanded(mainIndex, false);
695         }
696
697         return E_SUCCESS;
698
699 CATCH:
700         RemoveFromItemsList(mainIndex, -1);
701         __groupExpandStateList.RemoveAt(mainIndex, true);
702
703         return E_SYSTEM;
704 }
705
706 result
707 _ExpandableListImpl::AddSubItem(int mainIndex, const CustomListItem& item, int itemId)
708 {
709         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex <= GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
710
711         return InsertSubItemAt(mainIndex, GetSubItemCountAt(mainIndex), item, itemId);
712 }
713
714 result
715 _ExpandableListImpl::InsertSubItemAt(int mainIndex, int subIndex, const CustomListItem& item, int itemId)
716 {
717         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex <= GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d.", mainIndex);
718
719         SysTryReturnResult(NID_UI_CTRL, (subIndex >= 0 && subIndex <= GetSubItemCount(mainIndex)), E_INVALID_ARG, "Invalid argument used. subIndex = %d.", subIndex);
720
721         item.__pCustomListItemImpl->itemId = itemId;
722
723         result r = E_SUCCESS;
724
725         r = InsertIntoItemsList(item, mainIndex, subIndex);
726         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to insert item");
727
728         r = GetCore().RefreshTableView(mainIndex, subIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
729         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
730
731         return E_SUCCESS;
732
733 CATCH:
734         RemoveFromItemsList(mainIndex, subIndex);
735         return E_SYSTEM;
736 }
737
738 int
739 _ExpandableListImpl::GetItemCount(void) const
740 {
741         return GetGroupCount();
742 }
743
744 int
745 _ExpandableListImpl::GetSubItemCount(int mainIndex) const
746 {
747         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d.", mainIndex);
748
749         return GetSubItemCountAt(mainIndex);
750 }
751
752 result
753 _ExpandableListImpl::SetItemAt(int mainIndex, const CustomListItem& item, int itemId)
754 {
755         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
756
757         SysTryReturnResult(NID_UI_CTRL, (IsItemNew(item) == true), E_SYSTEM, "[E_SYSTEM] A system error has occurred. The item already exists.");
758
759         result r = E_SUCCESS;
760         item.__pCustomListItemImpl->itemId = itemId;
761
762         r = SetInItemsList(item, mainIndex, -1);
763         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
764
765         _TableViewItemUpdateParams updateParams;
766         updateParams.pItem = const_cast<CustomListItem*>(&item);
767         updateParams.isDividerEnabled = _isDividerEnabled;
768         updateParams.pCheckBitmaps = _pCheckBitmaps;
769         updateParams.annexStyle = _annexStyle;
770
771         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
772         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "A system error has occurred. Failed to refresh an item.");
773
774         return E_SUCCESS;
775 }
776
777 result
778 _ExpandableListImpl::RemoveItemAt(int mainIndex)
779 {
780         result r = E_SUCCESS;
781
782         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d.", mainIndex);
783
784         r = RemoveFromSubItemsList(mainIndex);
785         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
786
787         r = RemoveFromItemsList(mainIndex, -1);
788         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
789
790         __groupExpandStateList.RemoveAt(mainIndex, true);
791
792         __directDelete = true;
793
794         r = GetCore().RefreshTableView(mainIndex, -1, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
795
796         __directDelete = false;
797
798         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
799
800         return E_SUCCESS;
801 }
802
803 result
804 _ExpandableListImpl::SetSubItemAt(int mainIndex, int subIndex, const CustomListItem& item, int itemId)
805 {
806         result r = E_SUCCESS;
807
808         SysTryReturn(NID_UI_CTRL, ((mainIndex >= 0) && (mainIndex < GetGroupCount())), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
809
810         _TableViewGroupItemData* pGroupItem = GetTableViewGroupItemAt(mainIndex);
811         SysTryReturn(NID_UI_CTRL, pGroupItem, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get GroupItem at %d index.", mainIndex);
812
813         SysTryReturn(NID_UI_CTRL, ((subIndex >= 0) && (subIndex < GetSubItemCountAt(mainIndex))), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. subIndex = %d", subIndex);
814
815         item.__pCustomListItemImpl->itemId = itemId;
816
817         CustomListItem* pOldItem = GetCustomListItemAt(mainIndex, subIndex);
818         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);
819         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);
820
821         item.__pCustomListItemImpl->__pTableViewItemData = pOldItem->__pCustomListItemImpl->__pTableViewItemData;
822
823         r = SetInItemsList(item, mainIndex, subIndex);
824         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to update an item.");
825
826         _TableViewItemUpdateParams updateParams;
827         updateParams.pItem = const_cast<CustomListItem*>(&item);
828         updateParams.isDividerEnabled = _isDividerEnabled;
829         updateParams.pCheckBitmaps = _pCheckBitmaps;
830         updateParams.annexStyle = _annexStyle;
831
832         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
833         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to refresh an item.");
834
835         r = GetCore().RefreshTableView(mainIndex, subIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
836         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "Item not inserted successFully.");
837
838         return r;
839 }
840
841 result
842 _ExpandableListImpl::RemoveSubItemAt(int mainIndex, int subIndex)
843 {
844         result r = E_SUCCESS;
845
846         SysTryReturn(NID_UI_CTRL, ((mainIndex >= 0) && (mainIndex < GetGroupCount())), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
847
848         SysTryReturn(NID_UI_CTRL, ((subIndex >= 0) && (subIndex < GetSubItemCount(mainIndex))), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. subIndex = %d", subIndex);
849
850         r = RemoveFromItemsList(mainIndex, subIndex);
851         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to remove item.");
852
853         __directDelete = true;
854
855         r = GetCore().RefreshTableView(mainIndex, subIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
856
857         __directDelete = false;
858
859         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to remove item.");
860
861         if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_MARK || _annexStyle == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING)
862         {
863                 int checkedCount = GetCheckedItemCount(mainIndex);
864
865                 if (checkedCount == 0)
866                 {
867                         _CheckElementModel* pGroupCheckElement = GetCheckElementAt(mainIndex, -1);
868                         SysTryReturnResult(NID_UI_CTRL, pGroupCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at %d index.", mainIndex);
869
870                         pGroupCheckElement->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
871
872                         DrawItem(mainIndex, -1);
873                 }
874         }
875
876         return E_SUCCESS;
877 }
878
879 result
880 _ExpandableListImpl::RemoveAllSubItemsAt(int mainIndex)
881 {
882         result r = E_SUCCESS;
883
884         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d.", mainIndex);
885
886         int count = GetSubItemCountAt(mainIndex);
887         for (int index = 0; index < count; index++)
888         {
889                 r = RemoveSubItemAt(mainIndex, 0);
890         }
891
892         return r;
893 }
894
895 result
896 _ExpandableListImpl::RemoveAllItems(void)
897 {
898         result r = E_SUCCESS;
899         result finalResult = E_SUCCESS;
900
901         int count = GetGroupCount();
902         for (int index = count - 1; index >= 0; index--)
903         {
904                 r = RemoveItemAt(index);
905
906                 if (r != E_SUCCESS)
907                 {
908                         finalResult = r;
909                         SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. Item at %d index not removed successfully", index);
910                         index++;
911                 }
912         }
913         return finalResult;
914 }
915
916 bool
917 _ExpandableListImpl::IsItemChecked(int groupIndex, int subIndex) const
918 {
919         if (subIndex == -1)
920         {
921                 return IsItemChecked(groupIndex);
922         }
923         else
924         {
925                 return IsSubItemChecked(groupIndex, subIndex);
926         }
927 }
928
929 bool
930 _ExpandableListImpl::IsItemChecked(int mainIndex) const
931 {
932         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.");
933
934         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()),
935                         false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
936
937         const _CheckElementModel* pCheckElement = GetCheckElementAt(mainIndex, -1);
938         SysTryReturn(NID_UI_CTRL, pCheckElement, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get checkElement at mainIndex(%d).", mainIndex);
939
940         return (bool)pCheckElement->GetCheckBoxStatus();
941 }
942
943 int
944 _ExpandableListImpl::GetFirstCheckedItemIndex(void) const
945 {
946         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");
947
948         int count  = GetGroupCount();
949         for (int index = 0; index < count; index++)
950         {
951                 if (IsItemChecked(index))
952                         return index;
953         }
954         return INVALID_INDEX;
955 }
956
957 int
958 _ExpandableListImpl::GetItemIdAt(int mainIndex) const
959 {
960         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
961
962         const CustomListItem* pCustomListItem = GetCustomListItemAt(mainIndex, -1);
963         SysTryReturn(NID_UI_CTRL, pCustomListItem, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at mainIndex(%d).", mainIndex);
964
965         return pCustomListItem->__pCustomListItemImpl->itemId;
966 }
967
968 int
969 _ExpandableListImpl::GetItemIndexFromItemId(int itemId) const
970 {
971         int count  = GetGroupCount();
972         for (int index = 0; index < count; index++)
973         {
974                 const CustomListItem* pCustomListItem = GetCustomListItemAt(index, -1);
975                 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);
976
977                 if (itemId == pCustomListItem->__pCustomListItemImpl->itemId)
978                         return index;
979         }
980         return INVALID_INDEX;
981 }
982
983 int
984 _ExpandableListImpl::GetSubItemIdAt(int mainIndex, int subIndex) const
985 {
986         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
987
988         SysTryReturn(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)),     INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. subIndex = %d", subIndex);
989
990         const CustomListItem* pCustomListItem = GetCustomListItemAt(mainIndex, subIndex);
991         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);
992
993         return pCustomListItem->__pCustomListItemImpl->itemId;
994 }
995
996 result
997 _ExpandableListImpl::SetItemExpanded(int mainIndex, bool expand)
998 {
999         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1000
1001         Boolean* pIsExpanded = new Boolean(expand);
1002         SysTryReturn(NID_UI_CTRL, pIsExpanded, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1003
1004         __groupExpandStateList.SetAt(*pIsExpanded, mainIndex, true);
1005
1006         if (GetCore().GetFirstDrawnFlag() || (GetCore().IsGroupExpanded(mainIndex) == expand))
1007         {
1008                 return E_SUCCESS;
1009         }
1010
1011         result r = E_SUCCESS;
1012
1013         _TableViewGroupItemData* pTableViewGroupItemData = GetTableViewGroupItemAt(mainIndex);
1014         SysTryReturn(NID_UI_CTRL, pTableViewGroupItemData, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get item at %d mainIndex.", mainIndex);
1015
1016         _ExpandableListArrowBitmap* pArrowIcon = dynamic_cast<_ExpandableListArrowBitmap*>(pTableViewGroupItemData->GetControl(ARROW_ELEMENT_NAME));
1017         SysTryReturn(NID_UI_CTRL, pArrowIcon, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get arrow icon.");
1018
1019         bool isCustomBitmap = false;
1020
1021         if (expand)
1022         {
1023                 r = GetCore().ExpandGroup(mainIndex);
1024
1025                 isCustomBitmap = IS_CUSTOM_BITMAP(LIST::BUTTON_EXPAND_GROUP);
1026
1027                 if (isCustomBitmap)
1028                 {
1029                         pArrowIcon->SetBitmap(*__pClosedImage);
1030                 }
1031                 else
1032                 {
1033                         pArrowIcon->SetBitmap(*__pClosedImage, __pEffectClosedImage);
1034                 }
1035         }
1036         else
1037         {
1038                 r = GetCore().CollapseGroup(mainIndex);
1039
1040                 isCustomBitmap = IS_CUSTOM_BITMAP(LIST::BUTTON_COLLAPSE_GROUP);
1041
1042                 if (isCustomBitmap)
1043                 {
1044                         pArrowIcon->SetBitmap(*__pOpenedImage);
1045                 }
1046                 else
1047                 {
1048                         pArrowIcon->SetBitmap(*__pOpenedImage, __pEffectOpenedImage);
1049                 }
1050         }
1051
1052         pArrowIcon->Invalidate(true);
1053
1054         return r;
1055 }
1056
1057 result
1058 _ExpandableListImpl::SetItemEnabled(int mainIndex, bool enable)
1059 {
1060         result r = E_SUCCESS;
1061
1062         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1063
1064         _CheckElementModel* pCheckElement = GetCheckElementAt(mainIndex, -1);
1065         SysTryReturnResult(NID_UI_CTRL, pCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d).", mainIndex);
1066
1067         if (pCheckElement)
1068         {
1069                 if (enable)
1070                 {
1071                         if (pCheckElement->GetCheckBoxStatus() == CHECK_BOX_DISABLED)
1072                         {
1073                                 pCheckElement->SetCheckBoxStatus(CHECK_BOX_CHECKED);
1074                         }
1075                 }
1076                 else
1077                 {
1078                         if (pCheckElement->GetCheckBoxStatus() == CHECK_BOX_CHECKED)
1079                         {
1080                                 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_MARK)
1081                                 {
1082                                         pCheckElement->SetCheckBoxStatus(CHECK_BOX_DISABLED);
1083                                 }
1084                         }
1085                 }
1086         }
1087
1088         r = GetCore().SetItemEnabled(mainIndex, -1, enable);
1089         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
1090
1091         return r;
1092 }
1093
1094 bool
1095 _ExpandableListImpl::IsItemEnabled(int mainIndex) const
1096 {
1097         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1098
1099         return GetCore().IsItemEnabled(mainIndex, -1);
1100 }
1101
1102 result
1103 _ExpandableListImpl::SetSubItemEnabled(int mainIndex, int subIndex, bool enable)
1104 {
1105         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex(%d)", mainIndex);
1106         SysTryReturnResult(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), E_INVALID_ARG, "Invalid argument used. subIndex(%d)", subIndex);
1107
1108         result r = E_SUCCESS;
1109
1110         _CheckElementModel* pCheckElement = GetCheckElementAt(mainIndex, subIndex);
1111         SysTryReturnResult(NID_UI_CTRL, pCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d) subIndex(%d).", mainIndex, subIndex);
1112
1113         if (pCheckElement)
1114         {
1115                 if (enable)
1116                 {
1117                         if (pCheckElement->GetCheckBoxStatus() == CHECK_BOX_DISABLED)
1118                         {
1119                                 pCheckElement->SetCheckBoxStatus(CHECK_BOX_CHECKED);
1120                         }
1121                 }
1122                 else
1123                 {
1124                         if (pCheckElement->GetCheckBoxStatus() == CHECK_BOX_CHECKED)
1125                         {
1126                                 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_MARK)
1127                                 {
1128                                         pCheckElement->SetCheckBoxStatus(CHECK_BOX_DISABLED);
1129                                 }
1130                         }
1131                 }
1132         }
1133
1134         r = GetCore().SetItemEnabled(mainIndex, subIndex, enable);
1135         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
1136
1137         return r;
1138 }
1139
1140 bool
1141 _ExpandableListImpl::IsSubItemEnabled(int mainIndex, int subIndex) const
1142 {
1143         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1144
1145         SysTryReturn(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. subIndex = %d", subIndex);
1146
1147         return GetCore().IsItemEnabled(mainIndex, subIndex);
1148 }
1149
1150 result
1151 _ExpandableListImpl::SetItemChecked(int groupIndex, int itemIndex, bool check)
1152 {
1153         if (itemIndex == -1)
1154         {
1155                 return SetItemChecked(groupIndex, check);
1156         }
1157         else
1158         {
1159                 return SetSubItemChecked(groupIndex, itemIndex, check);
1160         }
1161 }
1162
1163 result
1164 _ExpandableListImpl::SetItemChecked(int mainIndex, bool check)
1165 {
1166         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1167
1168         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");
1169
1170         SysTryReturnResult(NID_UI_CTRL, (IsItemEnabled(mainIndex)), E_SYSTEM, "A system error has occurred. The item is not enabled at mainIndex %d.", mainIndex);
1171
1172         if (IsItemChecked(mainIndex) == check)
1173         {
1174                 return E_SUCCESS;
1175         }
1176
1177         _CheckElementModel* pCheckElement = GetCheckElementAt(mainIndex, -1);
1178         SysTryReturnResult(NID_UI_CTRL, pCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d)", mainIndex);
1179
1180         if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
1181         {
1182                 if (_currentRadioGroupIndex != -1)
1183                 {
1184                         _CheckElementModel* pOldSubCheckElement = GetCheckElementAt(_currentRadioGroupIndex, _currentRadioIndex);
1185                         SysTryReturnResult(NID_UI_CTRL, pOldSubCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d) subIndex(%d).", _currentRadioGroupIndex, _currentRadioIndex);
1186
1187                         pOldSubCheckElement->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
1188
1189                         DrawItem(_currentRadioGroupIndex, _currentRadioIndex);
1190                 }
1191
1192                 _currentRadioGroupIndex = (check == true) ? mainIndex : -1;
1193                 pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
1194                 _currentRadioIndex = -1;
1195
1196                 return E_SUCCESS;
1197         }
1198
1199         int subCount = GetSubItemCountAt(mainIndex);
1200
1201         if (subCount == 0)
1202         {
1203                 pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
1204         }
1205         else
1206         {
1207                 for (int subItemCount = 0; subItemCount < subCount; subItemCount++)
1208                 {
1209                         SetSubItemChecked(mainIndex, subItemCount, check);
1210                 }
1211         }
1212
1213         return E_SUCCESS;
1214 }
1215
1216 result
1217 _ExpandableListImpl::SetSubItemCheckedRadio(int mainIndex, int subIndex, bool check)
1218 {
1219         if (_currentRadioGroupIndex != -1)
1220         {
1221                 _CheckElementModel* pOldSubCheckElement = GetCheckElementAt(_currentRadioGroupIndex, _currentRadioIndex);
1222                 SysTryReturnResult(NID_UI_CTRL, pOldSubCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d) subIndex(%d).", _currentRadioGroupIndex, _currentRadioIndex);
1223
1224                 pOldSubCheckElement->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
1225
1226                 DrawItem(_currentRadioGroupIndex, _currentRadioIndex);
1227         }
1228
1229         if (check)
1230         {
1231                 _currentRadioGroupIndex = mainIndex;
1232                 _currentRadioIndex = subIndex;
1233         }
1234         else
1235         {
1236                 _currentRadioGroupIndex = -1;
1237                 _currentRadioIndex = -1;
1238         }
1239
1240         _CheckElementModel* pSubCheckElement = GetCheckElementAt(mainIndex, subIndex);
1241         SysTryReturnResult(NID_UI_CTRL, pSubCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d) subIndex(%d).", mainIndex, subIndex);
1242
1243         pSubCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
1244
1245         DrawItem(mainIndex, subIndex);
1246
1247         return E_SUCCESS;
1248 }
1249
1250 result
1251 _ExpandableListImpl::SetSubItemCheckedMarkOnOff(int mainIndex, int subIndex, bool check)
1252 {
1253         _CheckElementModel* pCheckElement = GetCheckElementAt(mainIndex, subIndex);
1254         SysTryReturnResult(NID_UI_CTRL, pCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d) subIndex(%d).", mainIndex, subIndex);
1255
1256         pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
1257
1258         _CheckElementModel* pGroupCheckElement = GetCheckElementAt(mainIndex, -1);
1259         SysTryReturnResult(NID_UI_CTRL, pGroupCheckElement, E_SYSTEM, "A system error has occurred. Failed to get checkElement at mainIndex(%d).", mainIndex);
1260
1261         if ((check) || (GetCheckedItemCountAt(mainIndex) > 0))
1262         {
1263                 pGroupCheckElement->SetCheckBoxStatus(CHECK_BOX_CHECKED);
1264         }
1265         else
1266         {
1267                 pGroupCheckElement->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
1268         }
1269
1270         DrawItem(mainIndex, -1);
1271         DrawItem(mainIndex, subIndex);
1272
1273         return E_SUCCESS;
1274 }
1275
1276 result
1277 _ExpandableListImpl::SetSubItemChecked(int mainIndex, int subIndex, bool check)
1278 {
1279         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1280
1281         SysTryReturnResult(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), E_INVALID_ARG, "Invalid argument used. subIndex = %d", subIndex);
1282
1283         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");
1284
1285         if (IsSubItemChecked(mainIndex, subIndex) == check)
1286         {
1287                 return E_SUCCESS;
1288         }
1289
1290         if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
1291         {
1292                 return SetSubItemCheckedRadio(mainIndex, subIndex, check);
1293         }
1294         else
1295         {
1296                 return SetSubItemCheckedMarkOnOff(mainIndex, subIndex, check);
1297         }
1298 }
1299
1300 int
1301 _ExpandableListImpl::GetCheckedItemCountAt(int mainIndex) const
1302 {
1303         int totalSubItemCount = GetSubItemCountAt(mainIndex);
1304         int count = 0;
1305
1306         for (int index = 0; index < totalSubItemCount; index++)
1307         {
1308                 if (IsSubItemChecked(mainIndex, index) == true)
1309                 {
1310                         count++;
1311                 }
1312         }
1313
1314         return count;
1315 }
1316
1317 bool
1318 _ExpandableListImpl::IsSubItemChecked(int mainIndex, int subIndex) const
1319 {
1320         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.");
1321
1322         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1323
1324         SysTryReturn(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. subIndex = %d", subIndex);
1325
1326         const _CheckElementModel* pCheckElement = GetCheckElementAt(mainIndex, subIndex);
1327         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);
1328
1329         return (bool)pCheckElement->GetCheckBoxStatus();
1330 }
1331
1332 result
1333 _ExpandableListImpl::SetAllSubItemsChecked(int mainIndex, bool check)
1334 {
1335         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1336
1337         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");
1338         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");
1339
1340         int totalSubItemCount = GetSubItemCountAt(mainIndex);
1341         result r = E_SUCCESS;
1342
1343         for (int subItemCount = 0; subItemCount < totalSubItemCount; subItemCount++)
1344         {
1345                 r = SetSubItemChecked(mainIndex, subItemCount, check);
1346                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
1347         }
1348
1349         return E_SUCCESS;
1350 }
1351
1352 result
1353 _ExpandableListImpl::RemoveAllCheckedSubItemsAt(int mainIndex)
1354 {
1355         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1356
1357         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");
1358
1359         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");
1360
1361         result r = E_SUCCESS;
1362         int totalSubItemCount = GetSubItemCountAt(mainIndex);
1363
1364         for (int subItemCount = 0; subItemCount < totalSubItemCount; subItemCount++)
1365         {
1366                 bool isChecked = IsSubItemChecked(mainIndex, subItemCount);
1367
1368                 if (isChecked)
1369                 {
1370                         r = RemoveSubItemAt(mainIndex, subItemCount);
1371                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to remove item");
1372                 }
1373         }
1374
1375         return E_SUCCESS;
1376 }
1377
1378 int
1379 _ExpandableListImpl::GetFirstCheckedSubItemIndex(int mainIndex) const
1380 {
1381         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");
1382
1383         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1384
1385         int totalSubItemCount = GetSubItemCountAt(mainIndex);
1386
1387         for (int subItemCount = 0; subItemCount < totalSubItemCount; subItemCount++)
1388         {
1389                 if (IsSubItemChecked(mainIndex, subItemCount))
1390                 {
1391                         return subItemCount;
1392                 }
1393         }
1394
1395         return INVALID_INDEX;
1396 }
1397
1398 int
1399 _ExpandableListImpl::GetLastCheckedItemIndex(void) const
1400 {
1401         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");
1402
1403         int count = GetGroupCount();
1404
1405         for (int index = count - 1; index >= 0; index--)
1406         {
1407                 if (IsItemChecked(index))
1408                 {
1409                         return index;
1410                 }
1411         }
1412
1413         return INVALID_INDEX;
1414 }
1415
1416 int
1417 _ExpandableListImpl::GetLastCheckedSubItemIndex(int mainIndex) const
1418 {
1419         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");
1420
1421         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1422
1423         int count = GetSubItemCountAt(mainIndex);
1424
1425         for (int index = count - 1; index >= 0; index--)
1426         {
1427                 if (IsSubItemChecked(mainIndex, index))
1428                 {
1429                         return index;
1430                 }
1431         }
1432         return INVALID_INDEX;
1433 }
1434
1435 int
1436 _ExpandableListImpl::GetNextCheckedItemIndexAfter(int mainIndex) const
1437 {
1438         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");
1439
1440         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1441
1442         for (int index = mainIndex+1; index < GetGroupCount(); index++)
1443         {
1444                 if (IsItemChecked(index))
1445                 {
1446                         return index;
1447                 }
1448         }
1449
1450         return INVALID_INDEX;
1451 }
1452
1453 int
1454 _ExpandableListImpl::GetNextCheckedSubItemIndexAfter(int mainIndex, int subIndex) const
1455 {
1456         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");
1457
1458         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1459         SysTryReturn(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), INVALID_INDEX, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. subIndex = %d", subIndex);
1460
1461         int count = GetSubItemCountAt(mainIndex);
1462
1463         for (int index = subIndex + 1; index < count; index++)
1464         {
1465                 if (IsSubItemChecked(mainIndex, index))
1466                 {
1467                         return index;
1468                 }
1469         }
1470
1471         return INVALID_INDEX;
1472 }
1473
1474 result
1475 _ExpandableListImpl::GetSubItemIndexFromItemId(int itemId, int& mainIndex, int& subIndex) const
1476 {
1477         mainIndex = INVALID_INDEX;
1478         subIndex = INVALID_INDEX;
1479
1480         for (int index = 0; index < GetGroupCount(); index++)
1481         {
1482                 for (int count = 0; count < GetSubItemCountAt(index); count++)
1483                 {
1484                         const CustomListItem* pCustomListItem = GetCustomListItemAt(index, count);
1485                         SysTryReturnResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "A system error has occurred. Failed to get an item at mainIndex(%d) subIndex(%d).", index, count);
1486
1487                         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);
1488
1489                         if (itemId == pCustomListItem->__pCustomListItemImpl->itemId)
1490                         {
1491                                 mainIndex = index;
1492                                 subIndex = count;
1493                                 return E_SUCCESS;
1494                         }
1495                 }
1496         }
1497
1498         return E_OBJ_NOT_FOUND;
1499 }
1500
1501 result
1502 _ExpandableListImpl::ScrollToBottom(void)
1503 {
1504         result r = E_SUCCESS;
1505
1506         int lastGroupIndex = GetGroupCount() - 1;
1507         int lastItemIndex = GetSubItemCountAt(lastGroupIndex) - 1;
1508
1509         r = GetCore().SetBottomDrawnItemIndex(lastGroupIndex, lastItemIndex);
1510         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1511
1512         GetCore().Draw();
1513
1514         return E_SUCCESS;
1515 }
1516 result
1517 _ExpandableListImpl::ScrollToTop(void)
1518 {
1519         result r = E_SUCCESS;
1520
1521         r = GetCore().SetTopDrawnItemIndex(0, -1);
1522         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
1523         SetLastResult(E_SUCCESS);
1524
1525         GetCore().Draw();
1526
1527         return r;
1528 }
1529
1530 result
1531 _ExpandableListImpl::ScrollToTop(int mainIndex, int subIndex)
1532 {
1533         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1534         SysTryReturnResult(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), E_INVALID_ARG, "Invalid argument used. subIndex = %d", subIndex);
1535         result r = E_SUCCESS;
1536
1537         r = GetCore().SetTopDrawnItemIndex(mainIndex, subIndex);
1538         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1539
1540         GetCore().Draw();
1541
1542         return r;
1543 }
1544
1545 result
1546 _ExpandableListImpl::ScrollToTop(int mainIndex)
1547 {
1548         SysTryReturn(NID_UI_CTRL, ((mainIndex < GetGroupCount()) && (mainIndex >= 0)), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d.", mainIndex);
1549
1550         result r = E_SUCCESS;
1551
1552         r = GetCore().SetTopDrawnItemIndex(mainIndex, -1);
1553         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1554
1555         GetCore().Draw();
1556
1557         return r;
1558 }
1559
1560 void
1561 _ExpandableListImpl::SetBgColor(const Color& color)
1562 {
1563         GetCore().SetBackgroundColor(color);
1564         return;
1565 }
1566
1567 result
1568 _ExpandableListImpl::RefreshItem(int mainIndex)
1569 {
1570         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d.", mainIndex);
1571
1572         int topGroupIndex = -1;
1573         int bottomGroupIndex = -1;
1574         int itemIndex = -1;
1575
1576         GetCore().GetTopDrawnItemIndex(topGroupIndex, itemIndex);
1577         GetCore().GetBottomDrawnItemIndex(bottomGroupIndex, itemIndex);
1578
1579         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= topGroupIndex && mainIndex <= bottomGroupIndex), E_INVALID_OPERATION, "Index should be within drawn item range %d.", mainIndex);
1580
1581         result r = E_SUCCESS;
1582
1583         int count = GetSubItemCountAt(mainIndex);
1584         for (int indexItem = 0; indexItem < count; indexItem++)
1585         {
1586                 r = RefreshSubItem(mainIndex, indexItem);
1587                 if (r != E_SUCCESS)
1588                 {
1589                         SysLog(NID_UI_CTRL, "Not able to refresh item with index %d %d.", mainIndex, indexItem);
1590                 }
1591         }
1592
1593         return E_SUCCESS;
1594 }
1595
1596 result
1597 _ExpandableListImpl::RefreshSubItem(int mainIndex, int subIndex)
1598 {
1599         SysTryReturnResult(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), E_INVALID_ARG, "Invalid argument used. mainIndex = %d", mainIndex);
1600         SysTryReturnResult(NID_UI_CTRL, (subIndex >= 0 && subIndex < GetSubItemCount(mainIndex)), E_INVALID_ARG, "Invalid argument used. subIndex = %d", subIndex);
1601
1602         int topItemIndex = -1;
1603         int bottomItemIndex = -1;
1604         int groupItemIndex = -1;
1605
1606         GetCore().GetTopDrawnItemIndex(groupItemIndex, topItemIndex);
1607         GetCore().GetBottomDrawnItemIndex(groupItemIndex, bottomItemIndex);
1608
1609         SysTryReturnResult(NID_UI_CTRL, (subIndex >= topItemIndex && subIndex <= bottomItemIndex), E_INVALID_OPERATION,
1610                         "Index should be within drawn item range %d.", subIndex);
1611
1612         result r = E_SUCCESS;
1613
1614         CustomListItem* pCustomListItem = GetCustomListItemAt(mainIndex, subIndex);
1615         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);
1616
1617         _TableViewItemUpdateParams updateParams;
1618         updateParams.pItem = pCustomListItem;
1619         updateParams.isDividerEnabled = _isDividerEnabled;
1620         updateParams.pCheckBitmaps = _pCheckBitmaps;
1621         updateParams.annexStyle = _annexStyle;
1622
1623         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
1624         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "A system error has occurred. Failed to refresh an item.");
1625
1626         _TableViewItemData* pTableViewItemData = pCustomListItem->__pCustomListItemImpl->__pTableViewItemData;
1627         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);
1628
1629         pTableViewItemData->Invalidate(true);
1630
1631         return E_SUCCESS;
1632 }
1633
1634 int
1635 _ExpandableListImpl::GetCheckedItemCount(int mainIndex)
1636 {
1637         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), 0, E_INVALID_ARG, "[E_INVALID_ARG] The groupIndex %d is invalid", mainIndex);
1638
1639         _TableViewGroupItemData* pGroupItem = GetTableViewGroupItemAt(mainIndex);
1640         SysTryReturn(NID_UI_CTRL, pGroupItem, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get GroupItem at %d index.", mainIndex);
1641
1642         int checkedCount = 0;
1643         int subItemCount = GetSubItemCountAt(mainIndex);
1644
1645         for (int itemCount = 0; itemCount < subItemCount; itemCount++)
1646         {
1647                 if (IsSubItemChecked(mainIndex, itemCount) == true)
1648                 {
1649                         checkedCount++;
1650                 }
1651         }
1652
1653         return checkedCount;
1654 }
1655
1656 bool
1657 _ExpandableListImpl::IsItemExpanded(int mainIndex) const
1658 {
1659         SysTryReturn(NID_UI_CTRL, (mainIndex >= 0 && mainIndex < GetGroupCount()), false, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. mainIndex = %d", mainIndex);
1660
1661         if (GetCore().GetFirstDrawnFlag())
1662         {
1663                 Boolean* pIsExpanded = dynamic_cast<Boolean*>(const_cast<Object*>(__groupExpandStateList.GetAt(mainIndex)));
1664                 SysTryReturn(NID_UI_CTRL, pIsExpanded, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get expanded state at index(%d).", mainIndex);
1665
1666                 return pIsExpanded->ToBool();
1667         }
1668
1669         return (GetCore().IsGroupExpanded(mainIndex));
1670 }
1671
1672 void
1673 _ExpandableListImpl::OnTableViewItemStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1674 {
1675         return;
1676 }
1677
1678 void
1679 _ExpandableListImpl::OnTableViewContextItemActivationStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pContextItem, bool activated)
1680 {
1681         return;
1682 }
1683
1684 void
1685 _ExpandableListImpl::OnTableViewItemReordered(_TableView& tableView, int itemIndexFrom, int itemIndexTo)
1686 {
1687         return;
1688 }
1689
1690 void
1691 _ExpandableListImpl::OnGroupedTableViewGroupItemStateChanged(_TableView& tableView, int groupIndex, _TableViewItem* pItem, TableViewItemStatus status)
1692 {
1693         CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, -1);
1694         SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", groupIndex);
1695
1696         CustomListItemStatus customListItemStatus = CUSTOM_LIST_ITEM_STATUS_NORMAL;
1697         ItemStatus itemStatus = ITEM_HIGHLIGHTED;
1698
1699         switch (status)
1700         {
1701         case TABLE_VIEW_ITEM_STATUS_SELECTED:
1702                 itemStatus = ITEM_SELECTED;
1703                 customListItemStatus = CUSTOM_LIST_ITEM_STATUS_SELECTED;
1704                 break;
1705         case TABLE_VIEW_ITEM_STATUS_HIGHLIGHTED:
1706                 itemStatus = ITEM_HIGHLIGHTED;
1707                 customListItemStatus = CUSTOM_LIST_ITEM_STATUS_FOCUSED;
1708                 break;
1709         case TABLE_VIEW_ITEM_STATUS_CHECKED:
1710                 itemStatus = ITEM_CHECKED;
1711                 break;
1712         case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
1713                 itemStatus = ITEM_UNCHECKED;
1714                 break;
1715         default:
1716                 SetLastResult(E_SYSTEM);
1717                 return;
1718         }
1719
1720         LinkedList* pElements = &pCustomListItem->__pCustomListItemImpl->elements;
1721         _ElementBaseModel* pElementBase = null;
1722
1723         for (int i = 0; i < pElements->GetCount(); i++)
1724         {
1725                 pElementBase = dynamic_cast<_ElementBaseModel*>(pElements->GetAt(i));
1726                 SysTryReturnVoidResult(NID_UI_CTRL, (pElementBase != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get valid element at index %d.", i);
1727
1728                 if (pElementBase->_elementType != LIST_ITEM_ELEMENT_TYPE_CHECKBOX)
1729                 {
1730                         pElementBase->HandleElementEvent(customListItemStatus);
1731                 }
1732         }
1733
1734         if ((!_isDividerEnabled) && (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL))
1735         {
1736                 bool isChecked = false;
1737                 isChecked = IsItemChecked(groupIndex);
1738
1739                 if (isChecked)
1740                 {
1741                         itemStatus = ITEM_UNCHECKED;
1742                 }
1743                 else
1744                 {
1745                         itemStatus = ITEM_CHECKED;
1746                 }
1747
1748                 SetItemChecked(groupIndex, !isChecked);
1749         }
1750
1751         ProcessItemStateChange(groupIndex, -1, itemStatus);
1752
1753         return;
1754 }
1755
1756
1757 void
1758 _ExpandableListImpl::OnGroupedTableViewItemStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1759 {
1760         CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, itemIndex);
1761         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);
1762
1763         CustomListItemStatus customListItemStatus = CUSTOM_LIST_ITEM_STATUS_NORMAL;
1764         ItemStatus itemStatus = ITEM_HIGHLIGHTED;
1765         result r = E_SUCCESS;
1766
1767         switch (status)
1768         {
1769         case TABLE_VIEW_ITEM_STATUS_SELECTED:
1770                 itemStatus = ITEM_SELECTED;
1771                 customListItemStatus = CUSTOM_LIST_ITEM_STATUS_SELECTED;
1772                 break;
1773         case TABLE_VIEW_ITEM_STATUS_HIGHLIGHTED:
1774                 itemStatus = ITEM_HIGHLIGHTED;
1775                 customListItemStatus = CUSTOM_LIST_ITEM_STATUS_FOCUSED;
1776                 break;
1777         case TABLE_VIEW_ITEM_STATUS_CHECKED:
1778                 itemStatus = ITEM_CHECKED;
1779                 break;
1780         case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
1781                 itemStatus = ITEM_UNCHECKED;
1782                 break;
1783         default:
1784                 SetLastResult(E_SYSTEM);
1785                 break;
1786         }
1787
1788         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[E_SYSTEM] A system error has occurred. ListItemStatus is invalid");
1789
1790         LinkedList* pElements = &pCustomListItem->__pCustomListItemImpl->elements;
1791         _ElementBaseModel* pElementBase = null;
1792
1793         for (int i = 0; i < pElements->GetCount(); i++)
1794         {
1795                 pElementBase = dynamic_cast<_ElementBaseModel*>(pElements->GetAt(i));
1796                 SysTryReturnVoidResult(NID_UI_CTRL, (pElementBase != null), E_SYSTEM, "Invalid element.");
1797
1798                 if (pElementBase->_elementType != LIST_ITEM_ELEMENT_TYPE_CHECKBOX)
1799                 {
1800                         pElementBase->HandleElementEvent(customListItemStatus);
1801                 }
1802         }
1803
1804         if ((!_isDividerEnabled) && (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL))
1805         {
1806                 bool isChecked = false;
1807                 isChecked = IsSubItemChecked(groupIndex, itemIndex);
1808
1809                 if (isChecked)
1810                 {
1811                         itemStatus = ITEM_UNCHECKED;
1812                 }
1813                 else
1814                 {
1815                         itemStatus = ITEM_CHECKED;
1816                 }
1817
1818                 SetSubItemChecked(groupIndex, itemIndex, !isChecked);
1819         }
1820
1821         ProcessItemStateChange(groupIndex, itemIndex, itemStatus);
1822
1823         return;
1824 }
1825
1826 void
1827 _ExpandableListImpl::OnGroupedTableViewContextItemActivationStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
1828 {
1829         return;
1830 }
1831
1832 void
1833 _ExpandableListImpl::OnGroupedTableViewItemReordered(_TableView& tableView, int groupIndexFrom, int itemIndexFrom, int groupIndexTo, int itemIndexTo)
1834 {
1835         return;
1836 }
1837
1838 void
1839 _ExpandableListImpl::OnSectionTableViewItemStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1840 {
1841         return;
1842 }
1843
1844 void
1845 _ExpandableListImpl::OnSectionTableViewContextItemActivationStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
1846 {
1847         return;
1848 }
1849
1850 void
1851 _ExpandableListImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
1852 {
1853         return;
1854 }
1855
1856 void
1857 _ExpandableListImpl::OnTouchPressed (const Control &source, const Point &currentPosition, const TouchEventInfo &touchInfo)
1858 {
1859         _ExpandableListArrowBitmap* pArrowIcon = dynamic_cast<_ExpandableListArrowBitmap*>(const_cast<Control*>(&source));
1860
1861         if (pArrowIcon != null)
1862         {
1863                 _TableViewGroupItemData* pTableViewGroupItemData = dynamic_cast<_TableViewGroupItemData*>(pArrowIcon->GetParent());
1864                 SysTryReturnVoidResult(NID_UI_CTRL, (pTableViewGroupItemData != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get arrow icon.");
1865
1866                 bool isCustomBitmap = false;
1867
1868                 if (GetCore().IsGroupExpanded(pTableViewGroupItemData->groupIndex))
1869                 {
1870                         GetCore().CollapseGroup(pTableViewGroupItemData->groupIndex);
1871
1872                         isCustomBitmap = IS_CUSTOM_BITMAP(LIST::BUTTON_COLLAPSE_GROUP);
1873                         if (isCustomBitmap)
1874                         {
1875                                 pArrowIcon->SetBitmap(*__pOpenedPressedImage);
1876                         }
1877                         else
1878                         {
1879                                 pArrowIcon->SetBitmap(*__pOpenedPressedImage, __pEffectOpenedImage);
1880                         }
1881                 }
1882                 else
1883                 {
1884                         GetCore().ExpandGroup(pTableViewGroupItemData->groupIndex);
1885
1886                         isCustomBitmap = IS_CUSTOM_BITMAP(LIST::BUTTON_EXPAND_GROUP);
1887
1888                         if (isCustomBitmap)
1889                         {
1890                                 pArrowIcon->SetBitmap(*__pClosedPressedImage);
1891                         }
1892                         else
1893                         {
1894                                 pArrowIcon->SetBitmap(*__pClosedPressedImage, __pEffectClosedImage);
1895                         }
1896                 }
1897
1898                 pArrowIcon->Invalidate(true);
1899         }
1900         else
1901         {
1902                 _ListBaseImpl::OnTouchPressed(source, currentPosition, touchInfo);
1903         }
1904         return;
1905 }
1906
1907 void
1908 _ExpandableListImpl::OnTouchReleased (const Control &source, const Point &currentPosition, const TouchEventInfo &touchInfo)
1909 {
1910         _ExpandableListArrowBitmap* pArrowIcon = dynamic_cast<_ExpandableListArrowBitmap*>(const_cast<Control*>(&source));
1911
1912         if (pArrowIcon != null)
1913         {
1914                 _TableViewGroupItemData* pTableViewGroupItemData = dynamic_cast<_TableViewGroupItemData*>(pArrowIcon->GetParent());
1915                 SysTryReturnVoidResult(NID_UI_CTRL, (pTableViewGroupItemData != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get arrow icon.");
1916
1917                 bool isCustomBitmap = false;
1918
1919                 if (GetCore().IsGroupExpanded(pTableViewGroupItemData->groupIndex))
1920                 {
1921                         isCustomBitmap = IS_CUSTOM_BITMAP(LIST::BUTTON_COLLAPSE_GROUP);
1922                         if (isCustomBitmap)
1923                         {
1924                                 pArrowIcon->SetBitmap(*__pClosedImage);
1925                         }
1926                         else
1927                         {
1928                                 pArrowIcon->SetBitmap(*__pClosedImage, __pEffectClosedImage);
1929                         }
1930                 }
1931                 else
1932                 {
1933                         isCustomBitmap = IS_CUSTOM_BITMAP(LIST::BUTTON_EXPAND_GROUP);
1934
1935                         if (isCustomBitmap)
1936                         {
1937                                 pArrowIcon->SetBitmap(*__pOpenedImage);
1938                         }
1939                         else
1940                         {
1941                                 pArrowIcon->SetBitmap(*__pOpenedImage, __pEffectOpenedImage);
1942                         }
1943                 }
1944
1945                 pArrowIcon->Invalidate(true);
1946         }
1947         else
1948         {
1949                 _ListBaseImpl::OnTouchReleased(source, currentPosition, touchInfo);
1950         }
1951         return;
1952 }
1953
1954 void
1955 _ExpandableListImpl::ProcessItemStateChange(int mainIndex, int subIndex, int elementId, ItemStatus itemStatus)
1956 {
1957         int itemId = -1;
1958         if (subIndex == -1)
1959         {
1960                 itemId = GetItemIdAt(mainIndex);
1961         }
1962         else
1963         {
1964                 itemId = GetSubItemIdAt(mainIndex, subIndex);
1965         }
1966
1967         _ListListener* pListenerList = null;
1968         IExpandableItemEventListener* pEventListener = null;
1969
1970         for (int listenerCount = 0; listenerCount < __itemListenersList.GetCount(); listenerCount++)
1971         {
1972                 pListenerList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
1973                 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerList != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get ListListener");
1974
1975                 pEventListener = dynamic_cast<IExpandableItemEventListener*>(pListenerList->pListener);
1976                 SysTryReturnVoidResult(NID_UI_CTRL, (pEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get EventListener");
1977
1978                 pEventListener->OnItemStateChanged(GetPublic(), mainIndex, subIndex, itemId, elementId, itemStatus);
1979         }
1980         SetLastResult(E_SUCCESS);
1981         return;
1982 }
1983
1984 void
1985 _ExpandableListImpl::ProcessItemStateChange(int mainIndex, int subIndex, ItemStatus itemStatus)
1986 {
1987         int itemId = -1;
1988         if (subIndex == -1 )
1989         {
1990                 itemId = GetItemIdAt(mainIndex);
1991         }
1992         else
1993         {
1994                 itemId = GetSubItemIdAt(mainIndex, subIndex);
1995         }
1996
1997         _ListListener* pListenerList = null;
1998         IExpandableItemEventListener* pEventListener = null;
1999
2000         for (int listenerCount = 0; listenerCount < __itemListenersList.GetCount(); listenerCount++)
2001         {
2002                 pListenerList = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
2003                 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerList != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get ListListener");
2004
2005                 pEventListener = dynamic_cast<IExpandableItemEventListener*>(pListenerList->pListener);
2006                 SysTryReturnVoidResult(NID_UI_CTRL, (pEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get EventListener");
2007
2008                 pEventListener->OnItemStateChanged(GetPublic(), mainIndex, subIndex, itemId, itemStatus);
2009         }
2010         SetLastResult(E_SUCCESS);
2011         return;
2012 }
2013
2014 void
2015 _ExpandableListImpl::OnDraw(void)
2016 {
2017         if (GetCore().GetFirstDrawnFlag())
2018         {
2019                 _ListBaseImpl::OnDraw();
2020
2021                 int mainItemCount = GetGroupCount();
2022
2023                 for (int mainIndex = 0; mainIndex < mainItemCount; mainIndex++)
2024                 {
2025                         Boolean* pIsExpanded = dynamic_cast<Boolean*>(__groupExpandStateList.GetAt(mainIndex));
2026                         SysTryReturnVoidResult(NID_UI_CTRL, pIsExpanded, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get expanded state at index(%d).", mainIndex);
2027
2028                         if (!pIsExpanded->ToBool())
2029                         {
2030                                 SetItemExpanded(mainIndex, false);
2031                         }
2032                 }
2033
2034                 GetCore().UpdateTableView();
2035         }
2036         else
2037         {
2038                 _ListBaseImpl::OnDraw();
2039         }
2040
2041         return;
2042 }
2043
2044 void
2045 _ExpandableListImpl::DeleteExpandStateFlag(Object* pObj)
2046 {
2047         Boolean* pExpanded = null;
2048         pExpanded = dynamic_cast<Boolean*>(pObj);
2049         delete pExpanded;
2050         return;
2051 }
2052
2053 void
2054 _ExpandableListImpl::OnBoundsChanged(void)
2055 {
2056         int mainCount = GetGroupCount();
2057         result r = E_SUCCESS;
2058
2059         for (int mainIndex = 0; mainIndex < mainCount; mainIndex++)
2060         {
2061                 _TableViewGroupItemData* pTableViewGroupItemData = GetTableViewGroupItemAt(mainIndex);
2062                 SysTryReturnVoidResult(NID_UI_CTRL, pTableViewGroupItemData, E_SYSTEM, "A system error has occurred. Failed to get GroupItemData at %d index.", mainIndex);
2063
2064                 _ExpandableListArrowBitmap* pArrowLabel = dynamic_cast<_ExpandableListArrowBitmap*>(pTableViewGroupItemData->GetControl(ARROW_ELEMENT_NAME));
2065
2066                 if (pArrowLabel)
2067                 {
2068                         pTableViewGroupItemData->RemoveControl(*pArrowLabel);
2069                 }
2070
2071                 r = CreateArrowIcon(mainIndex);
2072                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to Create Arrow Icon at %d index.", mainIndex);
2073         }
2074
2075         _ListBaseImpl::OnBoundsChanged();
2076 }
2077
2078 class _ExpandableListMaker
2079         : public _UiBuilderControlMaker
2080 {
2081 public:
2082         _ExpandableListMaker(_UiBuilder* uibuilder)
2083                 : _UiBuilderControlMaker(uibuilder){};
2084         virtual ~_ExpandableListMaker(){};
2085         static _UiBuilderControlMaker*
2086         GetInstance(_UiBuilder* uibuilder)
2087         {
2088                 _ExpandableListMaker* pExpandableListMaker = new (std::nothrow) _ExpandableListMaker(uibuilder);
2089
2090                 return pExpandableListMaker;
2091         };
2092 protected:
2093         virtual Control*
2094         Make(_UiBuilderControl* pControl)
2095         {
2096                 result r = E_SYSTEM;
2097                 _UiBuilderControlLayout* pControlProperty = null;
2098                 ExpandableList* pExpandableList = null;
2099                 Rectangle rect;
2100                 Rectangle rectMin;
2101                 Dimension dimMin;
2102                 CustomListStyle style = CUSTOM_LIST_STYLE_NORMAL;
2103                 Tizen::Base::String elementString;
2104                 bool isItemDivider = true;
2105                 Color color;
2106
2107                 GetProperty(pControl, &pControlProperty);
2108                 if (pControlProperty == null)
2109                 {
2110                         return null;
2111                 }
2112
2113                 pExpandableList = new (std::nothrow) ExpandableList();
2114                 if (pExpandableList == null)
2115                 {
2116                         return null;
2117                 }
2118
2119                 rect = pControlProperty->GetRect();
2120                 Tizen::Base::String styleString;
2121                 styleString = pControlProperty->GetStyle();
2122
2123                 if (styleString.Equals(L"CUSTOM_LIST_STYLE_NORMAL", false))
2124                 {
2125                         style = CUSTOM_LIST_STYLE_NORMAL;
2126                 }
2127                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO", false))
2128                 {
2129                         style = CUSTOM_LIST_STYLE_RADIO;
2130                 }
2131                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER", false))
2132                 {
2133                         style = CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER;
2134                 }
2135                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK", false))
2136                 {
2137                         style = CUSTOM_LIST_STYLE_MARK;
2138                 }
2139                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER", false))
2140                 {
2141                         style = CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER;
2142                 }
2143                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF", false))
2144                 {
2145                         style = CUSTOM_LIST_STYLE_ONOFF;
2146                 }
2147                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER", false))
2148                 {
2149                         style = CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER;
2150                 }
2151                 else
2152                 {
2153                         style = CUSTOM_LIST_STYLE_NORMAL;
2154                 }
2155
2156                 if (pControl->GetElement(L"itemDivider", elementString))
2157                 {
2158                         if (elementString.Equals(L"true", false))
2159                         {
2160                                 isItemDivider = true;
2161                         }
2162                         else
2163                         {
2164                                 isItemDivider = false;
2165                         }
2166                 }
2167
2168                 r = pExpandableList->Construct(rect, style, isItemDivider);
2169                 if (r != E_SUCCESS)
2170                 {
2171                         delete pExpandableList;
2172                         return null;
2173                 }
2174
2175                 if (pControl->GetElement(L"textOfEmptyList", elementString))
2176                 {
2177                         pExpandableList->SetTextOfEmptyList(elementString);
2178                 }
2179
2180                 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
2181                 {
2182                         ConvertStringToColor(elementString, color);
2183                         pExpandableList->SetTextColorOfEmptyList(color);
2184                 }
2185                 GET_DIMENSION_CONFIG(LIST::LIST_MIN_SIZE, _CONTROL_ORIENTATION_PORTRAIT, dimMin);
2186                 rectMin = (pControl->GetAttribute(0))->GetRect();
2187                 (pControl->GetAttribute(0))->SetRect(rectMin.x, rectMin.y, dimMin.width, dimMin.height);
2188
2189                 GET_DIMENSION_CONFIG(LIST::LIST_MIN_SIZE, _CONTROL_ORIENTATION_LANDSCAPE, dimMin);
2190                 rectMin = (pControl->GetAttribute(1))->GetRect();
2191                 (pControl->GetAttribute(1))->SetRect(rectMin.x, rectMin.y, dimMin.width, dimMin.height);
2192
2193                 return pExpandableList;
2194         }
2195
2196 private:
2197 };
2198
2199 _ExpandableListRegister::_ExpandableListRegister()
2200 {
2201         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
2202
2203         if (pUiBuilderControlTableManager)
2204         {
2205                 pUiBuilderControlTableManager->RegisterControl(L"ExpandableList", _ExpandableListMaker::GetInstance);
2206         }
2207 }
2208 _ExpandableListRegister::~_ExpandableListRegister()
2209 {
2210         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
2211
2212         if (pUiBuilderControlTableManager)
2213         {
2214                 pUiBuilderControlTableManager->UnregisterControl(L"ExpandableList");
2215         }
2216 }
2217 static _ExpandableListRegister ExpandableListRegisterToUiBuilder;
2218 }}} //Tizen::Ui::Controls