Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_GroupedListImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19 * @file         FUiCtrl_GroupedListImpl.cpp
20 * @brief        This file contains implementation of _GroupedListImpl class
21 */
22
23 #include <FUiCtrlCustomListItem.h>
24 #include <FUiCtrlCustomListItemFormat.h>
25 #include <FBaseSysLog.h>
26 #include <FGrp_BitmapImpl.h>
27 #include "FUiCtrl_CustomListItemFormatImpl.h"
28 #include "FUiCtrl_CustomListItemImpl.h"
29 #include "FUiCtrl_GroupedListImpl.h"
30 #include "FUiCtrl_ListItemBaseImpl.h"
31 #include "FUiCtrl_CustomListElements.h"
32 #include "FUiCtrl_FastScroll.h"
33 #include "FUiCtrl_FastScrollIndex.h"
34 #include "FUiCtrl_ListListener.h"
35
36 #include "FUi_UiBuilder.h"
37 #include "FUi_ResourceSizeInfo.h"
38 #include "FUi_ResourceManager.h"
39
40 using namespace Tizen::Base;
41 using namespace Tizen::Graphics;
42 using namespace Tizen::Base::Collection;
43 using namespace Tizen::Base::Utility;
44
45
46 namespace Tizen { namespace Ui { namespace Controls
47 {
48
49 static const int ID_FORMAT_STRING = 1;
50 static const int ID_FORMAT_MARGIN = 2;
51
52 _GroupedListItemDataProvider::_GroupedListItemDataProvider(_GroupedListImpl* pGroupedListImpl)
53 {
54         __pList = pGroupedListImpl;
55 }
56
57 _GroupedListItemDataProvider::~_GroupedListItemDataProvider(void)
58 {
59 }
60
61 int
62 _GroupedListItemDataProvider::GetGroupCount()
63 {
64         SysTryReturn(NID_UI_CTRL, __pList, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Item provider not constructed properly.");
65         return __pList->GetGroupCount();
66 }
67
68 int
69 _GroupedListItemDataProvider::GetItemCount(int groupIndex)
70 {
71         SysTryReturn(NID_UI_CTRL, __pList, 0, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Item provider not constructed properly.");
72
73         return __pList->GetSubItemCountAt(groupIndex);
74 }
75
76 TableViewGroupItem*
77 _GroupedListItemDataProvider::CreateGroupItem(int groupIndex, int itemWidth)
78 {
79         result r = E_SUCCESS;
80
81         _TableViewItemParams tableViewItemParams;
82         tableViewItemParams.pItem = __pList->GetCustomListItemAt(groupIndex, -1);
83         tableViewItemParams.width = itemWidth;
84         tableViewItemParams.itemId = -1;
85         tableViewItemParams.groupIndex = groupIndex;
86         tableViewItemParams.itemIndex = -1;
87         tableViewItemParams.isDividerEnabled = false;
88         tableViewItemParams.pCheckBitmaps = null;
89         tableViewItemParams.annexStyle = __pList->_annexStyle;
90
91         r = _CustomListItemImpl::CreateTableViewItem(tableViewItemParams);
92         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
93
94         return __pList->GetTableViewGroupItemAt(groupIndex);
95 }
96
97 TableViewItem*
98 _GroupedListItemDataProvider::CreateItem(int groupIndex, int itemIndex, int itemWidth)
99 {
100         result r = E_SUCCESS;
101
102         CustomListItem* pCustomListItem = __pList->GetCustomListItemAt(groupIndex, itemIndex);
103         SysTryReturn(NID_UI_CTRL, pCustomListItem, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", itemIndex);
104
105         _TableViewItemParams tableViewItemParams;
106         tableViewItemParams.pItem = pCustomListItem;
107         tableViewItemParams.width = itemWidth;
108         tableViewItemParams.itemId = pCustomListItem->__pCustomListItemImpl->itemId;
109         tableViewItemParams.groupIndex = groupIndex;
110         tableViewItemParams.itemIndex = itemIndex;
111         tableViewItemParams.isDividerEnabled = __pList->_isDividerEnabled;
112         tableViewItemParams.pCheckBitmaps = __pList->_pCheckBitmaps;
113         tableViewItemParams.annexStyle = __pList->_annexStyle;
114
115         r = _CustomListItemImpl::CreateTableViewItem(tableViewItemParams);
116         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
117
118         pCustomListItem->__pCustomListItemImpl->__pTableViewItemData->AddTouchEventListener(*__pList);
119
120         TableViewItem* pItem = pCustomListItem->__pCustomListItemImpl->__pTableViewItemData;
121         pItem->SetBackgroundColor(__pList->__bgColor);
122
123         return pItem;
124 }
125
126 int
127 _GroupedListItemDataProvider::GetDefaultGroupItemHeight(void)
128 {
129         return __pList->__groupItemHeight;
130 }
131
132 int
133 _GroupedListItemDataProvider::GetDefaultItemHeight(void)
134 {
135         CustomListItem* pItem = __pList->GetCustomListItemAt(0, 0);
136
137         if (pItem)
138         {
139                 return pItem->__pCustomListItemImpl->height;
140         }
141         else
142         {
143                 return __pList->_defaultItemHeight;
144         }
145 }
146
147 bool
148 _GroupedListItemDataProvider::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
149 {
150         delete pItem;
151
152         if (__pList->__directDelete == false)
153         {
154                 CustomListItem* pCustomListItem = __pList->GetCustomListItemAt(groupIndex, -1);
155                 pCustomListItem->__pCustomListItemImpl->__pTableViewGroupItemData = null;
156         }
157
158         return true;
159 }
160
161 bool
162 _GroupedListItemDataProvider::IsReorderable(int groupIndexFrom, int groupIndexTo)
163 {
164         return false;
165 }
166
167 bool
168 _GroupedListItemDataProvider::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
169 {
170         delete pItem;
171
172         if (__pList->__directDelete == false)
173         {
174                 CustomListItem* pCustomListItem = __pList->GetCustomListItemAt(groupIndex, itemIndex);
175                 pCustomListItem->__pCustomListItemImpl->__pTableViewItemData = null;
176         }
177
178         return true;
179 }
180
181 void
182 _GroupedListItemDataProvider::UpdateGroupItem(int groupIndex, TableViewGroupItem* pItem)
183 {
184 }
185
186 void
187 _GroupedListItemDataProvider::UpdateItem(int groupIndex, int itemIndex, TableViewItem* pItem)
188 {
189         CustomListItem* pCustomListItem = __pList->GetCustomListItemAt(groupIndex, itemIndex);
190         SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d, %d).", groupIndex, itemIndex);
191
192         _TableViewItemUpdateParams updateParams;
193         updateParams.pItem = pCustomListItem;
194         updateParams.isDividerEnabled = __pList->_isDividerEnabled;
195         updateParams.pCheckBitmaps = __pList->_pCheckBitmaps;
196         updateParams.annexStyle = __pList->_annexStyle;
197
198         result r = E_SUCCESS;
199
200         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
201         SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to refresh an item.");
202
203         pItem->SetEnabled(true);
204 }
205
206 _GroupedListImpl*
207 _GroupedListImpl::GetInstance(GroupedList& groupedList)
208 {
209         return static_cast<_GroupedListImpl*>(groupedList._pControlImpl);
210 }
211
212 const _GroupedListImpl*
213 _GroupedListImpl::GetInstance(const GroupedList& groupedList)
214 {
215         return static_cast<const _GroupedListImpl*>(groupedList._pControlImpl);
216 }
217
218 _GroupedListImpl::_GroupedListImpl(Control* pList, _TableView* pCore)
219         : _ListBaseImpl(pList, pCore)
220         , __pItemProvider(null)
221         , __pItemListener(null)
222         , __groupItemHeight(0)
223         , __groupItemTextFont(0)
224         , __directDelete(false)
225         , __pItemFormat(null)
226 {
227 }
228
229 _GroupedListImpl::~_GroupedListImpl(void)
230 {
231         int count = GetItemCount();
232
233         for (int index = 0; index < count; index++)
234         {
235                 RemoveFromSubItemsList(index);
236         }
237
238         RemoveAllFromItemsList();
239
240         __itemListenersList.RemoveAll(true);
241         __fastScrollListenersList.RemoveAll(true);
242
243         delete __pItemProvider;
244
245         delete __pItemFormat;
246 }
247
248 const char*
249 _GroupedListImpl::GetPublicClassName(void) const
250 {
251         return "GroupedList";
252 }
253
254 const GroupedList&
255 _GroupedListImpl::GetPublic(void) const
256 {
257         return static_cast<const GroupedList&>(_ControlImpl::GetPublic());
258 }
259
260 GroupedList&
261 _GroupedListImpl::GetPublic(void)
262 {
263         return static_cast<GroupedList&>(_ControlImpl::GetPublic());
264 }
265
266 const _TableView&
267 _GroupedListImpl::GetCore(void) const
268 {
269         return static_cast<const _TableView&>(_ControlImpl::GetCore());
270 }
271
272 _TableView&
273 _GroupedListImpl::GetCore(void)
274 {
275         return static_cast<_TableView&>(_ControlImpl::GetCore());
276 }
277
278 _GroupedListImpl*
279 _GroupedListImpl::CreateGroupedListImplN(GroupedList* pControl, const Rectangle& bounds, bool itemDivider, bool fastScroll)
280 {
281         result r = E_SUCCESS;
282         _TableView* pCore = null;
283         _GroupedListImpl* pImpl = null;
284
285         r = GET_SIZE_INFO(GroupedList).CheckInitialSizeValid(Dimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
286         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
287
288         if(fastScroll == true)
289         {
290                 pCore = _TableView::CreateTableViewN(TABLE_VIEW_STYLE_GROUPED, itemDivider, TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL);
291         }
292         else
293         {
294                 pCore = _TableView::CreateTableViewN(TABLE_VIEW_STYLE_GROUPED, itemDivider, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
295         }
296
297         r = GetLastResult();
298         SysTryReturn(NID_UI_CTRL, pCore, null, r, "[%s] Propagating.", GetErrorMessage(r));
299
300         pImpl = new (std::nothrow) _GroupedListImpl(pControl, pCore);
301         SysTryCatch(NID_UI_CTRL, pImpl, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
302
303         r = pImpl->InitializeBoundsProperties(GET_SIZE_INFO(GroupedList), bounds, pCore->GetOrientation());
304         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
305
306         pCore->SetItemDividerEnabled(itemDivider);
307
308         return pImpl;
309
310 CATCH:
311         delete pCore;
312         pCore = null;
313
314         delete pImpl;
315         pImpl = null;
316
317         return null;
318 }
319
320 result
321 _GroupedListImpl::AddGroupedItemEventListener(const IGroupedItemEventListener& listener)
322 {
323         _ListListener* pListenerData = new (std::nothrow) _ListListener();
324
325         SysTryReturn(NID_UI_CTRL, pListenerData, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
326
327         pListenerData->pListener = const_cast<IGroupedItemEventListener*>(&listener);
328         __itemListenersList.Add(*pListenerData);
329
330         return E_SUCCESS;
331 }
332
333 result
334 _GroupedListImpl::RemoveGroupedItemEventListener(const IGroupedItemEventListener& listener)
335 {
336         _ListListener* pListenerData = null;
337         int count = __itemListenersList.GetCount();
338         result r = E_SYSTEM;
339
340         for (int listenerCount = 0; listenerCount < count; listenerCount++)
341         {
342                 pListenerData = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
343
344                 if ((pListenerData != null) && (pListenerData->pListener == &listener))
345                 {
346                         r = E_SUCCESS;
347                         __itemListenersList.RemoveAt(listenerCount, true);
348                         break;
349                 }
350         }
351
352         return r;
353 }
354
355 result
356 _GroupedListImpl::AddFastScrollEventListener(const IFastScrollEventListener& listener)
357 {
358         _ListListener* pListenerData = new (std::nothrow) _ListListener();
359
360         SysTryReturn(NID_UI_CTRL, pListenerData, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
361
362         pListenerData->pListener = const_cast<IFastScrollEventListener*>(&listener);
363         __fastScrollListenersList.Add(*pListenerData);
364
365         return E_SUCCESS;
366 }
367
368 result
369 _GroupedListImpl::RemoveFastScrollEventListener(const IFastScrollEventListener& listener)
370 {
371         _ListListener* pListenerData = null;
372         int count = __fastScrollListenersList.GetCount();
373
374         for (int listenerCount = 0; listenerCount < count; listenerCount++)
375         {
376                 pListenerData = dynamic_cast<_ListListener*>(__fastScrollListenersList.GetAt(listenerCount));
377
378                 if ((pListenerData != null) && (pListenerData->pListener == &listener))
379                 {
380                         __fastScrollListenersList.RemoveAt(listenerCount, true);
381                         break;
382                 }
383         }
384         return E_SUCCESS;
385 }
386
387 result
388 _GroupedListImpl::Initialize(void)
389 {
390         __pItemProvider = new (std::nothrow) _GroupedListItemDataProvider(this);
391         SysTryReturn(NID_UI_CTRL, (__pItemProvider != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
392
393         TableViewStyle style = GetCore().GetTableViewStyle();
394         SysTryReturn(NID_UI_CTRL, style == TABLE_VIEW_STYLE_GROUPED, E_INVALID_OPERATION, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The style of TableView is not TABLE_VIEW_STYLE_GROUPED");
395
396         _TableViewItemProvider* pItemProvider = _TableViewItemProvider::CreateTableViewItemProviderN(style);
397         SysTryReturn(NID_UI_CTRL, pItemProvider != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
398
399         result r = pItemProvider->SetGroupedStyleItemProvider(__pItemProvider);
400         if (r != E_SUCCESS)
401         {
402                 delete pItemProvider;
403                 SysTryReturn(NID_UI_CTRL, false, r, r, "[%s] Propagating.", GetErrorMessage(r));
404         }
405
406         r = GetCore().SetItemProvider(pItemProvider);
407         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
408
409         r = GetCore().AddGroupedTableViewItemEventListener(*this);
410         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
411
412         if (GetCore().GetScrollStyle() == TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL)
413         {
414                 r = GetCore().AddFastScrollListener(*this);
415                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
416         }
417
418         GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_DEFAULT_HEIGHT, GetCore().GetOrientation(), __groupItemHeight);
419         GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_DEFAULT_FONT_SIZE, GetCore().GetOrientation(), __groupItemTextFont);
420
421         __pItemFormat = new (std::nothrow) CustomListItemFormat();
422         SysTryReturn(NID_UI_CTRL, __pItemFormat, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
423
424         __pItemFormat->Construct();
425
426         int leftMargin = 0;
427         GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_INDEX_BAR_LEFT_MARGIN, GetCore().GetOrientation(), leftMargin);
428
429         __pItemFormat->AddElement(ID_FORMAT_MARGIN, Rectangle(0, 0, leftMargin, __groupItemHeight), __groupItemTextFont);
430         __pItemFormat->AddElement(ID_FORMAT_STRING, Rectangle(leftMargin, 0, GetCore().GetBounds().width, __groupItemHeight), __groupItemTextFont);
431
432         __pItemFormat->SetElementEventEnabled(ID_FORMAT_MARGIN, true);
433         __pItemFormat->SetElementEventEnabled(ID_FORMAT_STRING, true);
434
435         return r;
436 }
437
438 result
439 _GroupedListImpl::AddGroup(const String& text, const Bitmap* pBackgroundBitmap, int groupId)
440 {
441         return InsertGroupAt(GetGroupCount(), text, pBackgroundBitmap, groupId);
442 }
443
444 result
445 _GroupedListImpl::AddItem(int groupIndex, const CustomListItem& item, int itemId)
446 {
447         SysTryReturnResult(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
448                                 E_INVALID_ARG, "Invalid argument used. groupIndex = %d", groupIndex);
449
450         return InsertItemAt(groupIndex, GetSubItemCountAt(groupIndex), item, itemId);
451 }
452
453 result
454 _GroupedListImpl::SetItemAt(int groupIndex, int itemIndex, const CustomListItem& item, int itemId)
455 {
456         result r = E_SUCCESS;
457
458         SysTryReturnResult(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
459                                 E_INVALID_ARG, "Invalid argument used. groupIndex = %d", groupIndex);
460
461         SysTryReturnResult(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < GetSubItemCountAt(groupIndex))),
462                                 E_INVALID_ARG, "Invalid argument used. groupIndex = %d", itemIndex);
463
464         SysTryReturnResult(NID_UI_CTRL, (IsItemNew(item) == true), E_SYSTEM, "A system error has occurred. The item already exists.");
465
466         CustomListItem* pOldCustomListItem = GetCustomListItemAt(groupIndex, itemIndex);
467         SysTryReturnResult(NID_UI_CTRL, pOldCustomListItem, E_SYSTEM, "A system error has occurred. Failed to get old CustomListItem");
468
469         _CheckElementModel* pOldCheckElement = GetCheckElementAt(groupIndex, itemIndex);
470         _CheckElementModel* pNewCheckElement = item.__pCustomListItemImpl->GetCheckElement();
471
472         if (pNewCheckElement && pOldCheckElement)
473         {
474                 pNewCheckElement->SetCheckBoxStatus(pOldCheckElement->GetCheckBoxStatus());
475         }
476
477         item.__pCustomListItemImpl->__pTableViewItemData = pOldCustomListItem->__pCustomListItemImpl->__pTableViewItemData;
478         item.__pCustomListItemImpl->itemId = itemId;
479
480         _TableViewGroupItemData* pGroupItem = GetTableViewGroupItemAt(groupIndex);
481         SysTryReturn(NID_UI_CTRL, pGroupItem, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get GroupItem at %d index.", groupIndex);
482
483         r = SetInItemsList(item, groupIndex, itemIndex);
484         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "A system error has occurred. Failed to insert an item.");
485
486         r = GetCore().RefreshTableView(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
487         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "A system error has occurred. Failed to insert an item.");
488
489         return r;
490 }
491
492 result
493 _GroupedListImpl::InsertGroupAt(int groupIndex, const String& text, const Bitmap* pBackgroundBitmap, int groupId)
494 {
495         result r = E_SUCCESS;
496
497         SysTryReturn(NID_UI_CTRL, (groupIndex >= 0 && groupIndex <= GetGroupCount()),
498                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
499
500         CustomListItem* pCustomListItem = new (std::nothrow) CustomListItem();
501         SysTryReturn(NID_UI_CTRL, pCustomListItem, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
502
503         pCustomListItem->Construct(__groupItemHeight);
504         pCustomListItem->SetItemFormat(*__pItemFormat);
505         pCustomListItem->SetElement(ID_FORMAT_STRING, text);
506         pCustomListItem->SetElement(ID_FORMAT_MARGIN, "");
507
508         if (pBackgroundBitmap != null)
509         {
510                 pCustomListItem->SetNormalItemBackgroundBitmap(*pBackgroundBitmap);
511         }
512
513         pCustomListItem->__pCustomListItemImpl->itemId = groupId;
514
515         r = InsertIntoItemsList(*pCustomListItem, groupIndex, -1);
516         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
517
518         r = GetCore().RefreshTableView(groupIndex, -1, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
519         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
520
521         return r;
522 }
523
524 result
525 _GroupedListImpl::SetGroupAt(int groupIndex, const String& text, const Bitmap* pBackgroundBitmap, int groupId)
526 {
527         result r = E_SUCCESS;
528
529         SysTryReturn(NID_UI_CTRL, (groupIndex >= 0 && groupIndex < GetGroupCount()),
530                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
531
532         CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, -1);
533         SysTryReturn(NID_UI_CTRL, (pCustomListItem), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
534
535         _CustomListItemImpl* pCustomListItemImpl = pCustomListItem->__pCustomListItemImpl;
536         SysTryReturn(NID_UI_CTRL, (pCustomListItemImpl), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
537
538         pCustomListItem->SetElement(ID_FORMAT_STRING, text);
539         if (pBackgroundBitmap != null)
540         {
541                 pCustomListItem->SetNormalItemBackgroundBitmap(*pBackgroundBitmap);
542         }
543
544         pCustomListItemImpl->itemId = groupId;
545
546         _TableViewItemUpdateParams updateParams;
547         updateParams.pItem = pCustomListItem;
548         updateParams.isDividerEnabled = _isDividerEnabled;
549         updateParams.pCheckBitmaps = _pCheckBitmaps;
550         updateParams.annexStyle = _annexStyle;
551
552         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
553         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "A system error has occurred. Failed to refresh an item.");
554
555         return r;
556 }
557
558 result
559 _GroupedListImpl::InsertItemAt(int groupIndex, int itemIndex, const CustomListItem& item, int itemId)
560 {
561         result r = E_SUCCESS;
562
563         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
564                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
565
566         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex <= GetSubItemCountAt(groupIndex))),
567                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d", itemIndex);
568
569         item.__pCustomListItemImpl->itemId = itemId;
570
571         r = InsertIntoItemsList(item, groupIndex, itemIndex);
572         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
573
574         r = GetCore().RefreshTableView(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
575         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
576
577         return r;
578 }
579
580 result
581 _GroupedListImpl::RemoveItemAt(int groupIndex, int itemIndex)
582 {
583         int count = GetGroupCount();
584         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < count)),
585                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
586
587         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < GetSubItemCountAt(groupIndex))),
588                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d", itemIndex);
589
590         result r = E_SUCCESS;
591
592         __directDelete = true;
593
594         r = GetCore().RefreshTableView(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
595
596         __directDelete = false;
597
598         if (r != E_SUCCESS)
599         {
600                 r = RemoveFromItemsList(groupIndex, itemIndex);
601                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to remove item.");
602         }
603
604         return r;
605 }
606
607 result
608 _GroupedListImpl::RemoveAllItemsAt(int groupIndex)
609 {
610         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
611                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
612
613         result r = E_SUCCESS;
614
615         int count = GetSubItemCountAt(groupIndex) - 1;
616         for (int index = count; index >= 0; index--)
617         {
618                 r = RemoveItemAt(groupIndex, 0);
619         }
620
621         return r;
622 }
623
624 result
625 _GroupedListImpl::RemoveGroupAt(int groupIndex)
626 {
627         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
628                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
629
630         result r = E_SUCCESS;
631
632         r = RemoveFromSubItemsList(groupIndex);
633         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
634
635         r = RemoveFromItemsList(groupIndex, -1);
636         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
637
638         __directDelete = true;
639
640         r = GetCore().RefreshTableView(groupIndex, -1, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
641         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
642
643         __directDelete = false;
644
645         return E_SUCCESS;
646 }
647
648 result
649 _GroupedListImpl::RemoveAllGroups(void)
650 {
651         result r = E_SUCCESS;
652         int count = GetGroupCount();
653
654         for (int groupIndex = (count - 1); groupIndex >= 0; groupIndex--)
655         {
656                 r = RemoveGroupAt(groupIndex);
657         }
658
659         return r;
660 }
661
662 result
663 _GroupedListImpl::RemoveAllItems(void)
664 {
665         result r = E_SUCCESS;
666         int count = GetGroupCount();
667
668         for (int groupIndex = count - 1; groupIndex >= 0; groupIndex--)
669         {
670                 r = RemoveAllItemsAt(groupIndex);
671         }
672
673         return r;
674 }
675
676 result
677 _GroupedListImpl::SetItemEnabled(int groupIndex, int itemIndex, bool enable)
678 {
679         int count = GetGroupCount();
680         SysTryReturnResult(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < count)), E_INVALID_ARG, "Invalid argument used. groupIndex = %d.", groupIndex);
681
682         SysTryReturnResult(NID_UI_CTRL, (itemIndex >= 0 && itemIndex < GetSubItemCountAt(groupIndex)), E_INVALID_ARG, "Invalid argument used. itemIndex(%d)", itemIndex);
683
684         _CheckElementModel* pCheckElementModel = GetCheckElementAt(groupIndex, itemIndex);
685
686         if (pCheckElementModel)
687         {
688                 if (enable)
689                 {
690                         if (pCheckElementModel->GetCheckBoxStatus() == CHECK_BOX_DISABLED)
691                         {
692                                 pCheckElementModel->SetCheckBoxStatus(CHECK_BOX_CHECKED);
693                         }
694                 }
695                 else
696                 {
697                         if (pCheckElementModel->GetCheckBoxStatus() == CHECK_BOX_CHECKED)
698                         {
699                                 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_MARK)
700                                 {
701                                         pCheckElementModel->SetCheckBoxStatus(CHECK_BOX_DISABLED);
702                                 }
703                         }
704                 }
705         }
706
707         result r = E_SUCCESS;
708
709         r = GetCore().SetItemEnabled(groupIndex, itemIndex, enable);
710         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
711
712         DrawItem(groupIndex, itemIndex);
713
714         return r;
715 }
716
717 bool
718 _GroupedListImpl::IsItemEnabled(int groupIndex, int itemIndex) const
719 {
720         return GetCore().IsItemEnabled(groupIndex, itemIndex);
721 }
722
723 result
724 _GroupedListImpl::SetItemChecked(int groupIndex, int itemIndex, bool check)
725 {
726         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "A system error has occurred. List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
727
728         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
729                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
730
731         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < GetSubItemCountAt(groupIndex))),
732                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d", itemIndex);
733
734         SysTryReturn(NID_UI_CTRL, (IsItemEnabled(groupIndex, itemIndex) == true),
735                                 E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The List item is not enabled at index %d %d.", groupIndex, itemIndex);
736
737         if (IsItemChecked(groupIndex, itemIndex) == check)
738         {
739                 return E_SUCCESS;
740         }
741
742         _CheckElementModel* pCheckElement = GetCheckElementAt(groupIndex, itemIndex);
743         SysTryReturnResult(NID_UI_CTRL, (pCheckElement != null), E_SYSTEM, "A system error has occurred. Checkbox element not created");
744
745         if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
746         {
747                 if (check)
748                 {
749                         if (_currentRadioGroupIndex != -1)
750                         {
751                                 _CheckElementModel* pOldCheckElement = GetCheckElementAt(_currentRadioGroupIndex, _currentRadioIndex);
752                                 SysTryReturnResult(NID_UI_CTRL, (pOldCheckElement != null), E_SYSTEM, "A system error has occurred. Checkbox element not created");
753
754                                 pOldCheckElement->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
755
756                                 DrawItem(_currentRadioGroupIndex, _currentRadioIndex);
757                         }
758
759                         _currentRadioGroupIndex = groupIndex;
760                         _currentRadioIndex = itemIndex;
761
762                 }
763                 else
764                 {
765                         _currentRadioGroupIndex = -1;
766                         _currentRadioIndex = -1;
767                 }
768         }
769
770         pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
771
772         GetCore().Draw();
773
774         return E_SUCCESS;
775 }
776
777 bool
778 _GroupedListImpl::IsItemChecked(int groupIndex, int itemIndex) const
779 {
780         SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL),
781                                 false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL.");
782
783         const _CheckElementModel* pCheckElement = GetCheckElementAt(groupIndex, itemIndex);
784         SysTryReturn(NID_UI_CTRL, pCheckElement, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. CheckElement is not constructed properly.");
785
786         return (bool)pCheckElement->GetCheckBoxStatus();
787 }
788
789 result
790 _GroupedListImpl::SetAllItemsChecked(int groupIndex, bool check)
791 {
792         SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The List Style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
793         SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_RADIO), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The List Style should not be TABLE_VIEW_ANNEX_STYLE_RADIO");
794
795         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
796                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
797
798         _CheckElementModel* pCheckElement = null;
799
800         int groupItemCount = GetSubItemCountAt(groupIndex);
801         for (int indexItem = 0; indexItem < groupItemCount; indexItem++)
802         {
803                 pCheckElement = GetCheckElementAt(groupIndex, indexItem);
804                 SysTryReturnResult(NID_UI_CTRL, (pCheckElement != null), E_SYSTEM, "A system error has occurred. Checkbox element not created.");
805
806                 pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
807         }
808
809         return E_SUCCESS;
810 }
811
812 result
813 _GroupedListImpl::RemoveAllCheckedItems(void)
814 {
815         SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The List Style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
816         SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_RADIO), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The List Style should not be TABLE_VIEW_ANNEX_STYLE_RADIO");
817
818         int count = GetGroupCount();
819
820         for (int groupIndex = (count - 1); groupIndex >= 0; groupIndex--)
821         {
822                 if (RemoveAllCheckedItemsAt(groupIndex) != E_SUCCESS)
823                 {
824                         SysLog(NID_UI_CTRL, "Checked item with groupIndex=%d not removed successfully.", groupIndex);
825                 }
826         }
827
828         return E_SUCCESS;
829 }
830
831 result
832 _GroupedListImpl::RemoveAllCheckedItemsAt(int groupIndex)
833 {
834         result r = E_SUCCESS;
835
836         SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The List Style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
837         SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_RADIO), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The List Style should not be TABLE_VIEW_ANNEX_STYLE_RADIO");
838
839         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
840                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
841
842         int count = GetSubItemCountAt(groupIndex);
843         for (int itemIndex = (count - 1) ; itemIndex >= 0; itemIndex--)
844         {
845                 if (IsItemChecked(groupIndex, itemIndex))
846                 {
847                         r = RemoveItemAt(groupIndex, itemIndex);
848                         if (r != E_SUCCESS)
849                         {
850                                 SysLog(NID_UI_CTRL, "Checked item with index %d %d not removed successfully.", groupIndex, itemIndex);
851                         }
852                 }
853         }
854
855         return r;
856 }
857
858 result
859 _GroupedListImpl::GetFirstCheckedItemIndex(int& groupIndex, int& itemIndex) const
860 {
861         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
862
863         groupIndex = -1;
864         itemIndex = -1;
865         int count = GetGroupCount();
866         for (int indexGroup = 0; indexGroup < count; indexGroup++)
867         {
868                 int subItemCount =  GetSubItemCountAt(indexGroup);
869
870                 for (int indexItem = 0; indexItem < subItemCount; indexItem++)
871                 {
872                         if (IsItemChecked(indexGroup, indexItem))
873                         {
874                                 itemIndex = indexItem;
875                                 groupIndex = indexGroup;
876                                 return E_SUCCESS;
877                         }
878                 }
879         }
880
881         return E_SYSTEM;
882 }
883
884 result
885 _GroupedListImpl::GetLastCheckedItemIndex(int& groupIndex, int& itemIndex) const
886 {
887         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
888
889         groupIndex = -1;
890         itemIndex = -1;
891         int count = GetGroupCount();
892
893         for (int indexGroup = count - 1; indexGroup >= 0; indexGroup--)
894         {
895                 int subItemCount = GetSubItemCountAt(indexGroup);
896
897                 for (int indexItem = subItemCount - 1; indexItem >= 0; indexItem--)
898                 {
899                         if (IsItemChecked(indexGroup, indexItem))
900                         {
901                                 itemIndex = indexItem;
902                                 groupIndex = indexGroup;
903                                 return E_SUCCESS;
904                         }
905                 }
906         }
907
908         return E_SYSTEM;
909 }
910
911 result
912 _GroupedListImpl::GetNextCheckedItemIndexAfter(int& groupIndex, int& itemIndex) const
913 {
914         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
915
916         int count = GetGroupCount();
917
918         int subItemCount = GetSubItemCountAt(groupIndex);
919
920         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < count)),
921                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
922
923         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < subItemCount)),
924                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d.", itemIndex);
925
926         SysTryReturn(NID_UI_CTRL, (!((groupIndex == (count - 1)) && (itemIndex == (subItemCount - 1)))),
927                                         E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Input item is last item of last group")
928
929         int itemStart = 0;
930
931         for (int indexGroup = groupIndex; indexGroup < count; indexGroup++)
932         {
933                 if (indexGroup == groupIndex)
934                 {
935                         itemStart = itemIndex + 1;
936                 }
937                 else
938                 {
939                         itemStart = 0;
940                 }
941
942                 subItemCount = GetSubItemCountAt(groupIndex);
943                 for (int indexItem = itemStart; indexItem < subItemCount; indexItem++)
944                 {
945                         if (IsItemChecked(indexGroup, indexItem))
946                         {
947                                 itemIndex = indexItem;
948                                 groupIndex = indexGroup;
949                                 return E_SUCCESS;
950                         }
951                 }
952         }
953
954         return E_SYSTEM;
955 }
956
957 int
958 _GroupedListImpl::GetGroupIndexFromGroupId(int groupId) const
959 {
960         int count = GetGroupCount();
961
962         for (int indexGroup = 0; indexGroup < count; indexGroup++)
963         {
964                 const CustomListItem* pCustomListItem = GetCustomListItemAt(indexGroup, -1);
965                 SysTryReturn(NID_UI_CTRL, pCustomListItem, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", indexGroup);
966
967                 if (pCustomListItem->__pCustomListItemImpl->itemId == groupId)
968                 {
969                         return indexGroup;
970                 }
971         }
972         SetLastResult(E_SUCCESS);
973         return -1;
974 }
975
976 result
977 _GroupedListImpl::GetItemIndexFromItemId(int itemId, int& groupIndex, int& itemIndex) const
978 {
979         groupIndex = -1;
980         itemIndex = -1;
981
982         int count = GetGroupCount();
983
984         for (int indexGroup = 0; indexGroup < count; indexGroup++)
985         {
986                 int subItemCount = GetSubItemCountAt(indexGroup);
987                 for (int indexItem = 0; indexItem < subItemCount; indexItem++)
988                 {
989                         const CustomListItem* pSubListItem = GetCustomListItemAt(indexGroup, indexItem);
990                         SysTryReturn(NID_UI_CTRL, pSubListItem, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", indexItem);
991
992                         if (pSubListItem->__pCustomListItemImpl->itemId == itemId)
993                         {
994                                 itemIndex = indexItem;
995                                 groupIndex = indexGroup;
996                                 return E_SUCCESS;
997                         }
998                 }
999         }
1000
1001         return E_SYSTEM;
1002 }
1003
1004 void
1005 _GroupedListImpl::ScrollToBottom(void)
1006 {
1007         int lastGroupIndex = GetGroupCount() - 1;
1008         int lastItemIndex = GetSubItemCountAt(lastGroupIndex) - 1;
1009
1010         GetCore().SetBottomDrawnItemIndex(lastGroupIndex, lastItemIndex);
1011         GetCore().Draw();
1012
1013         return;
1014 }
1015 void
1016 _GroupedListImpl::ScrollToTop(void)
1017 {
1018         GetCore().SetTopDrawnItemIndex(0, -1);
1019
1020         GetCore().Draw();
1021
1022         return;
1023 }
1024
1025 result
1026 _GroupedListImpl::ScrollToTop(int groupIndex)
1027 {
1028         SysTryReturn(NID_UI_CTRL, ((groupIndex < GetGroupCount()) && (groupIndex >= 0)),
1029                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
1030
1031         result r = E_SUCCESS;
1032
1033         r = GetCore().SetTopDrawnItemIndex(groupIndex, -1);
1034         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1035
1036         GetCore().Draw();
1037
1038         return r;
1039 }
1040
1041 result
1042 _GroupedListImpl::ScrollToTop(int groupIndex, int itemIndex)
1043 {
1044         SysTryReturn(NID_UI_CTRL, ((groupIndex < GetGroupCount()) && (groupIndex >= 0)),
1045                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
1046
1047         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < GetSubItemCountAt(groupIndex))),
1048                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d.", itemIndex);
1049
1050         result r = E_SUCCESS;
1051
1052         r = GetCore().SetTopDrawnItemIndex(groupIndex, itemIndex);
1053         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1054
1055         GetCore().Draw();
1056
1057         return r;
1058 }
1059
1060 result
1061 _GroupedListImpl::RefreshGroup(int groupIndex)
1062 {
1063         result r = E_SUCCESS;
1064
1065         SysTryReturn(NID_UI_CTRL, ((groupIndex < GetGroupCount()) && (groupIndex >= 0)),
1066                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
1067
1068         int count = GetSubItemCountAt(groupIndex);
1069         for (int indexItem = 0; indexItem < count; indexItem++)
1070         {
1071                 r = RefreshItem(groupIndex, indexItem);
1072                 if (r != E_SUCCESS)
1073                 {
1074                         SysLog(NID_UI_CTRL, "Not able to refresh item with index %d %d.", groupIndex, indexItem);
1075                 }
1076         }
1077
1078         return E_SUCCESS;
1079 }
1080
1081 result
1082 _GroupedListImpl::RefreshItem(int groupIndex, int itemIndex)
1083 {
1084         SysTryReturn(NID_UI_CTRL, ((groupIndex < GetGroupCount()) && (groupIndex >= 0)),
1085                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
1086
1087         result r = E_SUCCESS;
1088
1089         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < GetSubItemCountAt(groupIndex))),
1090                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d.", itemIndex);
1091
1092         int topItemIndex = -1;
1093         int bottomItemIndex = -1;
1094         int groupItemIndex = -1;
1095
1096         GetCore().GetTopDrawnItemIndex(groupItemIndex, topItemIndex);
1097         GetCore().GetBottomDrawnItemIndex(groupItemIndex, bottomItemIndex);
1098
1099         SysTryReturnResult(NID_UI_CTRL, (itemIndex >= topItemIndex && itemIndex <= bottomItemIndex), E_INVALID_OPERATION,
1100                                           "Index should be within drawn item range %d.", itemIndex);
1101
1102         _TableViewItemUpdateParams updateParams;
1103         updateParams.pItem = GetCustomListItemAt(groupIndex, itemIndex);
1104         updateParams.isDividerEnabled = _isDividerEnabled;
1105         updateParams.pCheckBitmaps = _pCheckBitmaps;
1106         updateParams.annexStyle = _annexStyle;
1107
1108         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
1109         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "A system error has occurred. Failed to refresh an item.");
1110
1111         DrawItem(groupIndex, itemIndex);
1112
1113         return E_SUCCESS;
1114 }
1115
1116 int
1117 _GroupedListImpl::GetGroupIdAt(int groupIndex) const
1118 {
1119         SysTryReturn(NID_UI_CTRL, ((groupIndex < GetGroupCount()) && (groupIndex >= 0)),
1120                                 -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
1121
1122         const CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, -1);
1123         SysTryReturn(NID_UI_CTRL, pCustomListItem, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", groupIndex);
1124
1125         SysTryReturn(NID_UI_CTRL, pCustomListItem->__pCustomListItemImpl, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", groupIndex);
1126
1127         return pCustomListItem->__pCustomListItemImpl->itemId;
1128 }
1129
1130 int
1131 _GroupedListImpl::GetItemIdAt(int groupIndex, int itemIndex) const
1132 {
1133         int count = GetGroupCount();
1134         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < count)),
1135                                 -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
1136
1137         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < GetSubItemCountAt(groupIndex))),
1138                                 -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d.", itemIndex);
1139
1140         const CustomListItem* pItem = GetCustomListItemAt(groupIndex, itemIndex);
1141         SysTryReturn(NID_UI_CTRL, pItem, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d %d).", groupIndex, itemIndex);
1142
1143         return pItem->__pCustomListItemImpl->itemId;
1144 }
1145
1146 void
1147 _GroupedListImpl::SetListBackgroundColor(const Color& bgColor)
1148 {
1149         GetCore().SetBackgroundColor(bgColor);
1150         return;
1151 }
1152
1153 void
1154 _GroupedListImpl::OnTableViewItemStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1155 {
1156         return;
1157 }
1158
1159 void
1160 _GroupedListImpl::OnTableViewContextItemActivationStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pContextItem, bool activated)
1161 {
1162         return;
1163 }
1164
1165 void
1166 _GroupedListImpl::OnTableViewItemReordered(_TableView& tableView, int itemIndexFrom, int itemIndexTo)
1167 {
1168         return;
1169 }
1170
1171 void
1172 _GroupedListImpl::OnGroupedTableViewGroupItemStateChanged(_TableView& tableView, int groupIndex, _TableViewItem* pItem, TableViewItemStatus status)
1173 {
1174         return;
1175 }
1176
1177 void
1178 _GroupedListImpl::OnGroupedTableViewItemStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1179 {
1180         CustomListItemStatus customListItemStatus = CUSTOM_LIST_ITEM_STATUS_NORMAL;
1181         ItemStatus itemStatus = ITEM_HIGHLIGHTED;
1182
1183         switch (status)
1184         {
1185         case TABLE_VIEW_ITEM_STATUS_SELECTED:
1186                 itemStatus = ITEM_SELECTED;
1187                 customListItemStatus = CUSTOM_LIST_ITEM_STATUS_SELECTED;
1188                 break;
1189         case TABLE_VIEW_ITEM_STATUS_HIGHLIGHTED:
1190                 itemStatus = ITEM_HIGHLIGHTED;
1191                 customListItemStatus = CUSTOM_LIST_ITEM_STATUS_FOCUSED;
1192                 break;
1193         case TABLE_VIEW_ITEM_STATUS_CHECKED:
1194                 itemStatus = ITEM_CHECKED;
1195                 break;
1196         case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
1197                 itemStatus = ITEM_UNCHECKED;
1198                 break;
1199         default:
1200                 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. item status is invalid(%d).", status);
1201                 SetLastResult(E_SYSTEM);
1202                 return;
1203         }
1204
1205         CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, itemIndex);
1206         SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", itemIndex);
1207
1208         LinkedList* pElements = &pCustomListItem->__pCustomListItemImpl->elements;
1209         _ElementBaseModel* pElementBase = null;
1210
1211         for (int i = 0; i < pElements->GetCount(); i++)
1212         {
1213                 pElementBase = dynamic_cast<_ElementBaseModel*>(pElements->GetAt(i));
1214                 SysTryReturnVoidResult(NID_UI_CTRL, (pElementBase != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get valid element at index %d.", i);
1215
1216                 if ((_isDividerEnabled && pElementBase->_elementType != LIST_ITEM_ELEMENT_TYPE_CHECKBOX) || (!_isDividerEnabled))
1217                 {
1218                         pElementBase->HandleElementEvent(customListItemStatus);
1219                 }
1220         }
1221
1222         if ((!_isDividerEnabled) && (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL))
1223         {
1224                 bool isChecked = IsItemChecked(groupIndex, itemIndex);
1225
1226                 if (isChecked)
1227                 {
1228                         itemStatus = ITEM_UNCHECKED;
1229                 }
1230                 else
1231                 {
1232                         itemStatus = ITEM_CHECKED;
1233                 }
1234
1235                 SetItemChecked(groupIndex, itemIndex, !isChecked);
1236         }
1237
1238         ProcessItemStateChange(groupIndex, itemIndex, itemStatus);
1239
1240         GetCore().Draw();
1241         return;
1242 }
1243
1244 void
1245 _GroupedListImpl::OnGroupedTableViewContextItemActivationStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
1246 {
1247         return;
1248 }
1249
1250 void
1251 _GroupedListImpl::OnGroupedTableViewItemReordered(_TableView& tableView, int groupIndexFrom, int itemIndexFrom, int groupIndexTo, int itemIndexTo)
1252 {
1253         return;
1254 }
1255
1256 void
1257 _GroupedListImpl::OnSectionTableViewItemStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1258 {
1259         return;
1260 }
1261
1262 void
1263 _GroupedListImpl::OnSectionTableViewContextItemActivationStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
1264 {
1265         return;
1266 }
1267
1268 void
1269 _GroupedListImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
1270 {
1271         return;
1272 }
1273
1274 void
1275 _GroupedListImpl::ProcessItemStateChange(int groupIndex, int itemIndex, int elementId, ItemStatus itemStatus)
1276 {
1277         int itemId = GetItemIdAt(groupIndex, itemIndex);
1278         _ListListener* pListenerData = null;
1279         IGroupedItemEventListener* pGroupedItemEventListener = null;
1280         int count = __itemListenersList.GetCount();
1281
1282         for (int listenerCount = 0; listenerCount < count; listenerCount++)
1283         {
1284                 pListenerData = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
1285                 if (pListenerData != null)
1286                 {
1287                         pGroupedItemEventListener = dynamic_cast<IGroupedItemEventListener*>(pListenerData->pListener);
1288                         SysTryReturnVoidResult(NID_UI_CTRL, (pGroupedItemEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get EventListener");
1289
1290                         pGroupedItemEventListener->OnItemStateChanged(GetPublic(), groupIndex, itemIndex, itemId, elementId, itemStatus);
1291                 }
1292         }
1293
1294         return;
1295 }
1296
1297 void
1298 _GroupedListImpl::ProcessItemStateChange(int groupIndex, int itemIndex, ItemStatus itemStatus)
1299 {
1300         int itemId = GetItemIdAt(groupIndex, itemIndex);
1301         _ListListener* pListenerData = null;
1302         IGroupedItemEventListener* pGroupedItemEventListener = null;
1303         int count = __itemListenersList.GetCount();
1304
1305         for (int listenerCount = 0; listenerCount < count; listenerCount++)
1306         {
1307                 pListenerData = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
1308                 if (pListenerData != null)
1309                 {
1310                         pGroupedItemEventListener = dynamic_cast<IGroupedItemEventListener*>(pListenerData->pListener);
1311                         SysTryReturnVoidResult(NID_UI_CTRL, (pGroupedItemEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get EventListener");
1312                         pGroupedItemEventListener->OnItemStateChanged(GetPublic(), groupIndex, itemIndex, itemId, itemStatus);
1313                 }
1314         }
1315         SetLastResult(E_SUCCESS);
1316         return;
1317 }
1318
1319 void
1320 _GroupedListImpl::OnUiFastScrollIndexSelected(_Control& source, _FastScrollIndex& index)
1321 {
1322         _ListListener* pListenerData = null;
1323         IFastScrollEventListener* pFastScrollListener = null;
1324         int listenerCount = __fastScrollListenersList.GetCount();
1325
1326         for (int listenerIndex = 0; listenerIndex < listenerCount; listenerIndex++)
1327         {
1328                 pListenerData = dynamic_cast<_ListListener*>(__fastScrollListenersList.GetAt(listenerIndex));
1329                 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerData != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get ScrollEventListener");
1330
1331                 pFastScrollListener = dynamic_cast<IFastScrollEventListener*>(pListenerData->pListener);
1332                 SysTryReturnVoidResult(NID_UI_CTRL, (pFastScrollListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get ScrollEventListener");
1333
1334                 wchar_t mch = L' ';
1335                 String* pIndexText = index.GetIndexText();
1336                 if (pIndexText != null)
1337                 {
1338                         pIndexText->GetCharAt(0, mch);
1339                 }
1340                 const Control& control = GetPublic();
1341                 _FastScrollIndex* __pMainIndex = index.GetParentIndex();
1342                 if (__pMainIndex == GetCore().GetFastScrollBar()->GetIndex())
1343                 {
1344                         Character mainIndex(mch);
1345                         pFastScrollListener->OnMainIndexChanged(control, mainIndex);
1346                 }
1347                 else
1348                 {
1349                         Character subIndex(mch);
1350                         pIndexText = __pMainIndex->GetIndexText();
1351                         if (pIndexText != null)
1352                         {
1353                                 pIndexText->GetCharAt(0, mch);
1354                                 Character mainIndex(mch);
1355                                 pFastScrollListener->OnSubIndexChanged(control, mainIndex, subIndex);
1356                         }
1357                 }
1358         }
1359         SetLastResult(E_SUCCESS);
1360         return;
1361 }
1362
1363
1364 void
1365 _GroupedListImpl::OnBoundsChanged(void)
1366 {
1367         GetCore().OnBoundsChanged();
1368         return;
1369 }
1370
1371 result
1372 _GroupedListImpl::SetFastScrollMainIndex(const String& text)
1373 {
1374         SysTryReturn(NID_UI_CTRL, (text.GetLength() > 0), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Empty string");
1375
1376         result r = GetCore().SetFastScrollIndex(text, false);
1377         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
1378
1379         __mainIndexText = text;
1380
1381         return E_SUCCESS;
1382 }
1383
1384 result
1385 _GroupedListImpl::SetFastScrollSubIndex(const String& text, FastScrollIndexDigit indexDigit)
1386 {
1387         SysTryReturn(NID_UI_CTRL, (text.GetLength() > 0), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Empty string");
1388
1389         SysTryReturn(NID_UI_CTRL, (indexDigit == SCROLL_INDEX_DIGIT_NUM_1), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. indexDigit is not SCROLL_INDEX_DIGIT_NUM_1");
1390
1391         _FastScroll* pFastScroll = GetCore().GetFastScrollBar();
1392         SysTryReturn(NID_UI_CTRL, pFastScroll, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. FastScroll doesn't exist.");
1393
1394         SysTryReturn(NID_UI_CTRL, (__mainIndexText.GetLength() > 0), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Main index of the fast scroll isn't set");
1395
1396         _FastScrollIndex* pRootIndex = pFastScroll->GetIndex();
1397         SysTryReturn(NID_UI_CTRL, pRootIndex, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. RootIndex doesn't exist.");
1398
1399         int subIndexDigit = 1 ;
1400         String delim(L",");
1401         StringTokenizer strTok(text, delim);
1402         String token;
1403         int i = 0;
1404
1405         while (strTok.HasMoreTokens())
1406         {
1407                 strTok.GetNextToken(token);
1408                 _FastScrollIndex* pSecondaryIndex = pRootIndex->GetChildIndex(i++);
1409                 if (pSecondaryIndex != null)
1410                 {
1411                         pSecondaryIndex->AddChildTextIndexArray(0, token.GetPointer(), subIndexDigit, token.GetLength());
1412                 }
1413         }
1414         pFastScroll->UpdateIndex();
1415
1416         return E_SUCCESS;
1417 }
1418
1419 class _GroupedListMaker
1420         : public _UiBuilderControlMaker
1421 {
1422 public:
1423         _GroupedListMaker(_UiBuilder* uibuilder)
1424                 : _UiBuilderControlMaker(uibuilder){};
1425         virtual ~_GroupedListMaker(){};
1426         static _UiBuilderControlMaker*
1427         GetInstance(_UiBuilder* uibuilder)
1428         {
1429                 _GroupedListMaker* pGroupedListMaker = new (std::nothrow) _GroupedListMaker(uibuilder);
1430                 return pGroupedListMaker;
1431         };
1432 protected:
1433         virtual Tizen::Ui::Control*
1434         Make(_UiBuilderControl* pControl)
1435         {
1436                 result r = E_SYSTEM;
1437                 _UiBuilderControlLayout* pControlProperty = null;
1438                 GroupedList* pGroupedList = null;
1439                 Rectangle rect;
1440                 Rectangle rectMin;
1441                 Dimension dimMin;
1442
1443                 Tizen::Base::String elementString;
1444                 CustomListStyle style = CUSTOM_LIST_STYLE_NORMAL;
1445                 bool isItemDivider = true;
1446                 bool isFastScroll = false;
1447                 Color color;
1448
1449                 GetProperty(pControl, &pControlProperty);
1450                 if (pControlProperty == null)
1451                 {
1452                         return null;
1453                 }
1454
1455                 pGroupedList = new (std::nothrow) GroupedList();
1456                 if (pGroupedList == null)
1457                 {
1458                         return null;
1459                 }
1460
1461                 rect = pControlProperty->GetRect();
1462
1463                 Tizen::Base::String styleString;
1464                 styleString = pControlProperty->GetStyle();
1465
1466                 if (styleString.Equals(L"CUSTOM_LIST_STYLE_NORMAL", false))
1467                 {
1468                         style = CUSTOM_LIST_STYLE_NORMAL;
1469                 }
1470                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO", false))
1471                 {
1472                         style = CUSTOM_LIST_STYLE_RADIO;
1473                 }
1474                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER", false))
1475                 {
1476                         style = CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER;
1477                 }
1478                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK", false))
1479                 {
1480                         style = CUSTOM_LIST_STYLE_MARK;
1481                 }
1482                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER", false))
1483                 {
1484                         style = CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER;
1485                 }
1486                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF", false))
1487                 {
1488                         style = CUSTOM_LIST_STYLE_ONOFF;
1489                 }
1490                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER", false))
1491                 {
1492                         style = CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER;
1493                 }
1494                 else
1495                 {
1496                         style = CUSTOM_LIST_STYLE_NORMAL;
1497                 }
1498
1499                 //Construct
1500                 if (pControl->GetElement("itemDivider", elementString))
1501                 {
1502                         if (elementString.Equals(L"true", false))
1503                         {
1504                                 isItemDivider = true;
1505                         }
1506                         else
1507                         {
1508                                 isItemDivider = false;
1509                         }
1510                 }
1511
1512                 if (pControl->GetElement("fastScroll", elementString))
1513                 {
1514                         if (elementString.Equals(L"true", false))
1515                         {
1516                                 isFastScroll = true;
1517                         }
1518                         else
1519                         {
1520                                 isFastScroll = false;
1521                         }
1522                 }
1523
1524                 r = pGroupedList->Construct(rect, style, isItemDivider, isFastScroll);
1525                 if (r != E_SUCCESS)
1526                 {
1527                         delete pGroupedList;
1528                         return null;
1529                 }
1530
1531                 if (pControl->GetElement("textOfEmptyList", elementString))
1532                 {
1533                         pGroupedList->SetTextOfEmptyList(elementString);
1534                 }
1535
1536                 if (pControl->GetElement("colorOfEmptyListText", elementString))
1537                 {
1538                         ConvertStringToColor(elementString, color);
1539                         pGroupedList->SetTextColorOfEmptyList(color);
1540                 }
1541
1542                 GET_DIMENSION_CONFIG(LIST::GROUPEDLIST_MIN_SIZE, _CONTROL_ORIENTATION_PORTRAIT, dimMin);
1543                 rectMin = (pControl->GetAttribute(0))->GetRect();
1544                 (pControl->GetAttribute(0))->SetRect(rectMin.x, rectMin.y, dimMin.width, dimMin.height);
1545
1546                 GET_DIMENSION_CONFIG(LIST::GROUPEDLIST_MIN_SIZE, _CONTROL_ORIENTATION_LANDSCAPE, dimMin);
1547                 rectMin = (pControl->GetAttribute(1))->GetRect();
1548                 (pControl->GetAttribute(1))->SetRect(rectMin.x, rectMin.y, dimMin.width, dimMin.height);
1549
1550                 return pGroupedList;
1551         }
1552
1553 private:
1554 };
1555
1556 _GroupedListRegister::_GroupedListRegister()
1557 {
1558         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1559         if (pUiBuilderControlTableManager)
1560         {
1561                 pUiBuilderControlTableManager->RegisterControl(L"GroupedList", _GroupedListMaker::GetInstance);
1562         }
1563 }
1564 _GroupedListRegister::~_GroupedListRegister()
1565 {
1566         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1567         if (pUiBuilderControlTableManager)
1568         {
1569                 pUiBuilderControlTableManager->UnregisterControl(L"GroupedList");
1570         }
1571 }
1572 static _GroupedListRegister GroupedListRegisterToUiBuilder;
1573 }}} //Tizen::Ui::Controls