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