remove APIs to apply [ACR][03/30][Remove] Remove APIs in Tizen::Ui namespace
[platform/framework/native/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         Color groupTextColor = Color(0);
428         GET_SHAPE_CONFIG(TABLEVIEW::GROUPITEM_INDEX_BAR_LEFT_MARGIN, GetCore().GetOrientation(), leftMargin);
429         GET_COLOR_CONFIG(TABLEVIEW::GROUPITEM_TEXT_NORMAL, groupTextColor);
430
431         __pItemFormat->AddElement(ID_FORMAT_MARGIN, Rectangle(0, 0, leftMargin, __groupItemHeight), __groupItemTextFont);
432         __pItemFormat->AddElement(ID_FORMAT_STRING, Rectangle(leftMargin, 0, GetCore().GetBounds().width, __groupItemHeight),
433                         __groupItemTextFont, groupTextColor, groupTextColor);
434
435         __pItemFormat->SetElementEventEnabled(ID_FORMAT_MARGIN, true);
436         __pItemFormat->SetElementEventEnabled(ID_FORMAT_STRING, true);
437
438         return r;
439 }
440
441 result
442 _GroupedListImpl::AddGroup(const String& text, const Bitmap* pBackgroundBitmap, int groupId)
443 {
444         return InsertGroupAt(GetGroupCount(), text, pBackgroundBitmap, groupId);
445 }
446
447 result
448 _GroupedListImpl::AddItem(int groupIndex, const CustomListItem& item, int itemId)
449 {
450         SysTryReturnResult(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
451                                 E_INVALID_ARG, "Invalid argument used. groupIndex = %d", groupIndex);
452
453         return InsertItemAt(groupIndex, GetSubItemCountAt(groupIndex), item, itemId);
454 }
455
456 result
457 _GroupedListImpl::SetItemAt(int groupIndex, int itemIndex, const CustomListItem& item, int itemId)
458 {
459         result r = E_SUCCESS;
460
461         SysTryReturnResult(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
462                                 E_INVALID_ARG, "Invalid argument used. groupIndex = %d", groupIndex);
463
464         SysTryReturnResult(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < GetSubItemCountAt(groupIndex))),
465                                 E_INVALID_ARG, "Invalid argument used. groupIndex = %d", itemIndex);
466
467         SysTryReturnResult(NID_UI_CTRL, (IsItemNew(item) == true), E_SYSTEM, "A system error has occurred. The item already exists.");
468
469         CustomListItem* pOldCustomListItem = GetCustomListItemAt(groupIndex, itemIndex);
470         SysTryReturnResult(NID_UI_CTRL, pOldCustomListItem, E_SYSTEM, "A system error has occurred. Failed to get old CustomListItem");
471
472         _CheckElementModel* pOldCheckElement = GetCheckElementAt(groupIndex, itemIndex);
473         _CheckElementModel* pNewCheckElement = item.__pCustomListItemImpl->GetCheckElement();
474
475         if (pNewCheckElement && pOldCheckElement)
476         {
477                 pNewCheckElement->SetCheckBoxStatus(pOldCheckElement->GetCheckBoxStatus());
478         }
479
480         item.__pCustomListItemImpl->__pTableViewItemData = pOldCustomListItem->__pCustomListItemImpl->__pTableViewItemData;
481         item.__pCustomListItemImpl->itemId = itemId;
482
483         _TableViewGroupItemData* pGroupItem = GetTableViewGroupItemAt(groupIndex);
484         SysTryReturn(NID_UI_CTRL, pGroupItem, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get GroupItem at %d index.", groupIndex);
485
486         r = SetInItemsList(item, groupIndex, itemIndex);
487         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "A system error has occurred. Failed to insert an item.");
488
489         r = GetCore().RefreshTableView(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
490         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "A system error has occurred. Failed to insert an item.");
491
492         return r;
493 }
494
495 result
496 _GroupedListImpl::InsertGroupAt(int groupIndex, const String& text, const Bitmap* pBackgroundBitmap, int groupId)
497 {
498         result r = E_SUCCESS;
499
500         SysTryReturn(NID_UI_CTRL, (groupIndex >= 0 && groupIndex <= GetGroupCount()),
501                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
502
503         CustomListItem* pCustomListItem = new (std::nothrow) CustomListItem();
504         SysTryReturn(NID_UI_CTRL, pCustomListItem, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
505
506         pCustomListItem->Construct(__groupItemHeight);
507         pCustomListItem->SetItemFormat(*__pItemFormat);
508         pCustomListItem->SetElement(ID_FORMAT_STRING, text);
509         pCustomListItem->SetElement(ID_FORMAT_MARGIN, "");
510
511         if (pBackgroundBitmap != null)
512         {
513                 pCustomListItem->SetNormalItemBackgroundBitmap(*pBackgroundBitmap);
514         }
515
516         pCustomListItem->__pCustomListItemImpl->itemId = groupId;
517
518         r = InsertIntoItemsList(*pCustomListItem, groupIndex, -1);
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         if (GetCore().GetFirstDrawnFlag() == false)
522         {
523                 r = GetCore().RefreshTableView(groupIndex, -1, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
524                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
525         }
526
527         return r;
528 }
529
530 result
531 _GroupedListImpl::SetGroupAt(int groupIndex, const String& text, const Bitmap* pBackgroundBitmap, int groupId)
532 {
533         result r = E_SUCCESS;
534
535         SysTryReturn(NID_UI_CTRL, (groupIndex >= 0 && groupIndex < GetGroupCount()),
536                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
537
538         CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, -1);
539         SysTryReturn(NID_UI_CTRL, (pCustomListItem), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
540
541         _CustomListItemImpl* pCustomListItemImpl = pCustomListItem->__pCustomListItemImpl;
542         SysTryReturn(NID_UI_CTRL, (pCustomListItemImpl), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
543
544         pCustomListItem->SetElement(ID_FORMAT_STRING, text);
545         if (pBackgroundBitmap != null)
546         {
547                 pCustomListItem->SetNormalItemBackgroundBitmap(*pBackgroundBitmap);
548         }
549
550         pCustomListItemImpl->itemId = groupId;
551
552         _TableViewItemUpdateParams updateParams;
553         updateParams.pItem = pCustomListItem;
554         updateParams.isDividerEnabled = _isDividerEnabled;
555         updateParams.pCheckBitmaps = _pCheckBitmaps;
556         updateParams.annexStyle = _annexStyle;
557
558         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
559         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "A system error has occurred. Failed to refresh an item.");
560
561         return r;
562 }
563
564 result
565 _GroupedListImpl::InsertItemAt(int groupIndex, int itemIndex, const CustomListItem& item, int itemId)
566 {
567         result r = E_SUCCESS;
568
569         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
570                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
571
572         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex <= GetSubItemCountAt(groupIndex))),
573                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d", itemIndex);
574
575         item.__pCustomListItemImpl->itemId = itemId;
576
577         r = InsertIntoItemsList(item, groupIndex, itemIndex);
578         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
579
580         r = GetCore().RefreshTableView(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
581         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to insert an item.");
582
583         return r;
584 }
585
586 result
587 _GroupedListImpl::RemoveItemAt(int groupIndex, int itemIndex)
588 {
589         int count = GetGroupCount();
590         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < count)),
591                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
592
593         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < GetSubItemCountAt(groupIndex))),
594                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d", itemIndex);
595
596         result r = E_SUCCESS;
597
598         r = RemoveFromItemsList(groupIndex, itemIndex);
599         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to remove item.");
600
601         __directDelete = true;
602
603         r = GetCore().RefreshTableView(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
604
605         __directDelete = false;
606
607         return r;
608 }
609
610 result
611 _GroupedListImpl::RemoveAllItemsAt(int groupIndex)
612 {
613         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
614                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
615
616         result r = E_SUCCESS;
617
618         int count = GetSubItemCountAt(groupIndex) - 1;
619         for (int index = count; index >= 0; index--)
620         {
621                 r = RemoveItemAt(groupIndex, 0);
622         }
623
624         return r;
625 }
626
627 result
628 _GroupedListImpl::RemoveGroupAt(int groupIndex)
629 {
630         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
631                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
632
633         result r = E_SUCCESS;
634
635         r = RemoveFromSubItemsList(groupIndex);
636         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
637
638         r = RemoveFromItemsList(groupIndex, -1);
639         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
640
641         __directDelete = true;
642
643         r = GetCore().RefreshTableView(groupIndex, -1, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
644         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
645
646         __directDelete = false;
647
648         return E_SUCCESS;
649 }
650
651 result
652 _GroupedListImpl::RemoveAllGroups(void)
653 {
654         result r = E_SUCCESS;
655         int count = GetGroupCount();
656
657         for (int groupIndex = (count - 1); groupIndex >= 0; groupIndex--)
658         {
659                 r = RemoveGroupAt(groupIndex);
660         }
661
662         return r;
663 }
664
665 result
666 _GroupedListImpl::RemoveAllItems(void)
667 {
668         result r = E_SUCCESS;
669         int count = GetGroupCount();
670
671         for (int groupIndex = count - 1; groupIndex >= 0; groupIndex--)
672         {
673                 r = RemoveAllItemsAt(groupIndex);
674         }
675
676         return r;
677 }
678
679 result
680 _GroupedListImpl::SetItemEnabled(int groupIndex, int itemIndex, bool enable)
681 {
682         int count = GetGroupCount();
683         SysTryReturnResult(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < count)), E_INVALID_ARG, "Invalid argument used. groupIndex = %d.", groupIndex);
684
685         SysTryReturnResult(NID_UI_CTRL, (itemIndex >= 0 && itemIndex < GetSubItemCountAt(groupIndex)), E_INVALID_ARG, "Invalid argument used. itemIndex(%d)", itemIndex);
686
687         _CheckElementModel* pCheckElementModel = GetCheckElementAt(groupIndex, itemIndex);
688
689         if (pCheckElementModel)
690         {
691                 if (enable)
692                 {
693                         if (pCheckElementModel->GetCheckBoxStatus() == CHECK_BOX_DISABLED)
694                         {
695                                 pCheckElementModel->SetCheckBoxStatus(CHECK_BOX_CHECKED);
696                         }
697                 }
698                 else
699                 {
700                         if (pCheckElementModel->GetCheckBoxStatus() == CHECK_BOX_CHECKED)
701                         {
702                                 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_MARK)
703                                 {
704                                         pCheckElementModel->SetCheckBoxStatus(CHECK_BOX_DISABLED);
705                                 }
706                         }
707                 }
708         }
709
710         result r = E_SUCCESS;
711
712         r = GetCore().SetItemEnabled(groupIndex, itemIndex, enable);
713         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
714
715         DrawItem(groupIndex, itemIndex);
716
717         return r;
718 }
719
720 bool
721 _GroupedListImpl::IsItemEnabled(int groupIndex, int itemIndex) const
722 {
723         return GetCore().IsItemEnabled(groupIndex, itemIndex);
724 }
725
726 result
727 _GroupedListImpl::SetItemChecked(int groupIndex, int itemIndex, bool check)
728 {
729         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");
730
731         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
732                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
733
734         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < GetSubItemCountAt(groupIndex))),
735                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d", itemIndex);
736
737         SysTryReturn(NID_UI_CTRL, (IsItemEnabled(groupIndex, itemIndex) == true),
738                                 E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. The List item is not enabled at index %d %d.", groupIndex, itemIndex);
739
740         if (IsItemChecked(groupIndex, itemIndex) == check)
741         {
742                 return E_SUCCESS;
743         }
744
745         _CheckElementModel* pCheckElement = GetCheckElementAt(groupIndex, itemIndex);
746         SysTryReturnResult(NID_UI_CTRL, (pCheckElement != null), E_SYSTEM, "A system error has occurred. Checkbox element not created");
747
748         if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
749         {
750                 if (check)
751                 {
752                         if (_currentRadioGroupIndex != -1)
753                         {
754                                 _CheckElementModel* pOldCheckElement = GetCheckElementAt(_currentRadioGroupIndex, _currentRadioIndex);
755                                 SysTryReturnResult(NID_UI_CTRL, (pOldCheckElement != null), E_SYSTEM, "A system error has occurred. Checkbox element not created");
756
757                                 pOldCheckElement->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
758
759                                 DrawItem(_currentRadioGroupIndex, _currentRadioIndex);
760                         }
761
762                         _currentRadioGroupIndex = groupIndex;
763                         _currentRadioIndex = itemIndex;
764
765                 }
766                 else
767                 {
768                         _currentRadioGroupIndex = -1;
769                         _currentRadioIndex = -1;
770                 }
771         }
772
773         pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
774
775         GetCore().Draw();
776
777         return E_SUCCESS;
778 }
779
780 bool
781 _GroupedListImpl::IsItemChecked(int groupIndex, int itemIndex) const
782 {
783         SysTryReturn(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL),
784                                 false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL.");
785
786         const _CheckElementModel* pCheckElement = GetCheckElementAt(groupIndex, itemIndex);
787         SysTryReturn(NID_UI_CTRL, pCheckElement, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. CheckElement is not constructed properly.");
788
789         return (bool)pCheckElement->GetCheckBoxStatus();
790 }
791
792 result
793 _GroupedListImpl::SetAllItemsChecked(int groupIndex, bool check)
794 {
795         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");
796         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");
797
798         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
799                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
800
801         _CheckElementModel* pCheckElement = null;
802
803         int groupItemCount = GetSubItemCountAt(groupIndex);
804         for (int indexItem = 0; indexItem < groupItemCount; indexItem++)
805         {
806                 pCheckElement = GetCheckElementAt(groupIndex, indexItem);
807                 SysTryReturnResult(NID_UI_CTRL, (pCheckElement != null), E_SYSTEM, "A system error has occurred. Checkbox element not created.");
808
809                 pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
810         }
811
812         return E_SUCCESS;
813 }
814
815 result
816 _GroupedListImpl::RemoveAllCheckedItems(void)
817 {
818         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");
819         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");
820
821         int count = GetGroupCount();
822
823         for (int groupIndex = (count - 1); groupIndex >= 0; groupIndex--)
824         {
825                 if (RemoveAllCheckedItemsAt(groupIndex) != E_SUCCESS)
826                 {
827                         SysLog(NID_UI_CTRL, "Checked item with groupIndex=%d not removed successfully.", groupIndex);
828                 }
829         }
830
831         return E_SUCCESS;
832 }
833
834 result
835 _GroupedListImpl::RemoveAllCheckedItemsAt(int groupIndex)
836 {
837         result r = E_SUCCESS;
838
839         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");
840         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");
841
842         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < GetGroupCount())),
843                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d", groupIndex);
844
845         int count = GetSubItemCountAt(groupIndex);
846         for (int itemIndex = (count - 1) ; itemIndex >= 0; itemIndex--)
847         {
848                 if (IsItemChecked(groupIndex, itemIndex))
849                 {
850                         r = RemoveItemAt(groupIndex, itemIndex);
851                         if (r != E_SUCCESS)
852                         {
853                                 SysLog(NID_UI_CTRL, "Checked item with index %d %d not removed successfully.", groupIndex, itemIndex);
854                         }
855                 }
856         }
857
858         return r;
859 }
860
861 result
862 _GroupedListImpl::GetFirstCheckedItemIndex(int& groupIndex, int& itemIndex) const
863 {
864         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
865
866         groupIndex = -1;
867         itemIndex = -1;
868         int count = GetGroupCount();
869         for (int indexGroup = 0; indexGroup < count; indexGroup++)
870         {
871                 int subItemCount =  GetSubItemCountAt(indexGroup);
872
873                 for (int indexItem = 0; indexItem < subItemCount; indexItem++)
874                 {
875                         if (IsItemChecked(indexGroup, indexItem))
876                         {
877                                 itemIndex = indexItem;
878                                 groupIndex = indexGroup;
879                                 return E_SUCCESS;
880                         }
881                 }
882         }
883
884         return E_SYSTEM;
885 }
886
887 result
888 _GroupedListImpl::GetLastCheckedItemIndex(int& groupIndex, int& itemIndex) const
889 {
890         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
891
892         groupIndex = -1;
893         itemIndex = -1;
894         int count = GetGroupCount();
895
896         for (int indexGroup = count - 1; indexGroup >= 0; indexGroup--)
897         {
898                 int subItemCount = GetSubItemCountAt(indexGroup);
899
900                 for (int indexItem = subItemCount - 1; indexItem >= 0; indexItem--)
901                 {
902                         if (IsItemChecked(indexGroup, indexItem))
903                         {
904                                 itemIndex = indexItem;
905                                 groupIndex = indexGroup;
906                                 return E_SUCCESS;
907                         }
908                 }
909         }
910
911         return E_SYSTEM;
912 }
913
914 result
915 _GroupedListImpl::GetNextCheckedItemIndexAfter(int& groupIndex, int& itemIndex) const
916 {
917         SysTryReturnResult(NID_UI_CTRL, (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL), E_SYSTEM, "List style should not be TABLE_VIEW_ANNEX_STYLE_NORMAL");
918
919         int count = GetGroupCount();
920
921         int subItemCount = GetSubItemCountAt(groupIndex);
922
923         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < count)),
924                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
925
926         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < subItemCount)),
927                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d.", itemIndex);
928
929         SysTryReturn(NID_UI_CTRL, (!((groupIndex == (count - 1)) && (itemIndex == (subItemCount - 1)))),
930                                         E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Input item is last item of last group")
931
932         int itemStart = 0;
933
934         for (int indexGroup = groupIndex; indexGroup < count; indexGroup++)
935         {
936                 if (indexGroup == groupIndex)
937                 {
938                         itemStart = itemIndex + 1;
939                 }
940                 else
941                 {
942                         itemStart = 0;
943                 }
944
945                 subItemCount = GetSubItemCountAt(groupIndex);
946                 for (int indexItem = itemStart; indexItem < subItemCount; indexItem++)
947                 {
948                         if (IsItemChecked(indexGroup, indexItem))
949                         {
950                                 itemIndex = indexItem;
951                                 groupIndex = indexGroup;
952                                 return E_SUCCESS;
953                         }
954                 }
955         }
956
957         return E_SYSTEM;
958 }
959
960 int
961 _GroupedListImpl::GetGroupIndexFromGroupId(int groupId) const
962 {
963         int count = GetGroupCount();
964
965         for (int indexGroup = 0; indexGroup < count; indexGroup++)
966         {
967                 const CustomListItem* pCustomListItem = GetCustomListItemAt(indexGroup, -1);
968                 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);
969
970                 if (pCustomListItem->__pCustomListItemImpl->itemId == groupId)
971                 {
972                         return indexGroup;
973                 }
974         }
975         SetLastResult(E_SUCCESS);
976         return -1;
977 }
978
979 result
980 _GroupedListImpl::GetItemIndexFromItemId(int itemId, int& groupIndex, int& itemIndex) const
981 {
982         groupIndex = -1;
983         itemIndex = -1;
984
985         int count = GetGroupCount();
986
987         for (int indexGroup = 0; indexGroup < count; indexGroup++)
988         {
989                 int subItemCount = GetSubItemCountAt(indexGroup);
990                 for (int indexItem = 0; indexItem < subItemCount; indexItem++)
991                 {
992                         const CustomListItem* pSubListItem = GetCustomListItemAt(indexGroup, indexItem);
993                         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);
994
995                         if (pSubListItem->__pCustomListItemImpl->itemId == itemId)
996                         {
997                                 itemIndex = indexItem;
998                                 groupIndex = indexGroup;
999                                 return E_SUCCESS;
1000                         }
1001                 }
1002         }
1003
1004         return E_SYSTEM;
1005 }
1006
1007 void
1008 _GroupedListImpl::ScrollToBottom(void)
1009 {
1010         int lastGroupIndex = GetGroupCount() - 1;
1011         int lastItemIndex = GetSubItemCountAt(lastGroupIndex) - 1;
1012
1013         GetCore().SetBottomDrawnItemIndex(lastGroupIndex, lastItemIndex);
1014         GetCore().Draw();
1015
1016         return;
1017 }
1018 void
1019 _GroupedListImpl::ScrollToTop(void)
1020 {
1021         GetCore().SetTopDrawnItemIndex(0, -1);
1022
1023         GetCore().Draw();
1024
1025         return;
1026 }
1027
1028 result
1029 _GroupedListImpl::ScrollToTop(int groupIndex)
1030 {
1031         SysTryReturn(NID_UI_CTRL, ((groupIndex < GetGroupCount()) && (groupIndex >= 0)),
1032                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
1033
1034         result r = E_SUCCESS;
1035
1036         r = GetCore().SetTopDrawnItemIndex(groupIndex, -1);
1037         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1038
1039         GetCore().Draw();
1040
1041         return r;
1042 }
1043
1044 result
1045 _GroupedListImpl::ScrollToTop(int groupIndex, int itemIndex)
1046 {
1047         SysTryReturn(NID_UI_CTRL, ((groupIndex < GetGroupCount()) && (groupIndex >= 0)),
1048                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
1049
1050         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < GetSubItemCountAt(groupIndex))),
1051                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d.", itemIndex);
1052
1053         result r = E_SUCCESS;
1054
1055         r = GetCore().SetTopDrawnItemIndex(groupIndex, itemIndex);
1056         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1057
1058         GetCore().Draw();
1059
1060         return r;
1061 }
1062
1063 result
1064 _GroupedListImpl::RefreshGroup(int groupIndex)
1065 {
1066         result r = E_SUCCESS;
1067
1068         SysTryReturn(NID_UI_CTRL, ((groupIndex < GetGroupCount()) && (groupIndex >= 0)),
1069                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
1070
1071         int count = GetSubItemCountAt(groupIndex);
1072         for (int indexItem = 0; indexItem < count; indexItem++)
1073         {
1074                 r = RefreshItem(groupIndex, indexItem);
1075                 if (r != E_SUCCESS)
1076                 {
1077                         SysLog(NID_UI_CTRL, "Not able to refresh item with index %d %d.", groupIndex, indexItem);
1078                 }
1079         }
1080
1081         return E_SUCCESS;
1082 }
1083
1084 result
1085 _GroupedListImpl::RefreshItem(int groupIndex, int itemIndex)
1086 {
1087         SysTryReturn(NID_UI_CTRL, ((groupIndex < GetGroupCount()) && (groupIndex >= 0)),
1088                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
1089
1090         result r = E_SUCCESS;
1091
1092         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < GetSubItemCountAt(groupIndex))),
1093                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d.", itemIndex);
1094
1095         int topItemIndex = -1;
1096         int bottomItemIndex = -1;
1097         int groupItemIndex = -1;
1098
1099         GetCore().GetTopDrawnItemIndex(groupItemIndex, topItemIndex);
1100         GetCore().GetBottomDrawnItemIndex(groupItemIndex, bottomItemIndex);
1101
1102         SysTryReturnResult(NID_UI_CTRL, (itemIndex >= topItemIndex && itemIndex <= bottomItemIndex), E_INVALID_OPERATION,
1103                                           "Index should be within drawn item range %d.", itemIndex);
1104
1105         _TableViewItemUpdateParams updateParams;
1106         updateParams.pItem = GetCustomListItemAt(groupIndex, itemIndex);
1107         updateParams.isDividerEnabled = _isDividerEnabled;
1108         updateParams.pCheckBitmaps = _pCheckBitmaps;
1109         updateParams.annexStyle = _annexStyle;
1110
1111         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
1112         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "A system error has occurred. Failed to refresh an item.");
1113
1114         DrawItem(groupIndex, itemIndex);
1115
1116         return E_SUCCESS;
1117 }
1118
1119 int
1120 _GroupedListImpl::GetGroupIdAt(int groupIndex) const
1121 {
1122         SysTryReturn(NID_UI_CTRL, ((groupIndex < GetGroupCount()) && (groupIndex >= 0)),
1123                                 -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
1124
1125         const CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, -1);
1126         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);
1127
1128         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);
1129
1130         return pCustomListItem->__pCustomListItemImpl->itemId;
1131 }
1132
1133 int
1134 _GroupedListImpl::GetItemIdAt(int groupIndex, int itemIndex) const
1135 {
1136         int count = GetGroupCount();
1137         SysTryReturn(NID_UI_CTRL, ((groupIndex >= 0) && (groupIndex < count)),
1138                                 -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. groupIndex = %d.", groupIndex);
1139
1140         SysTryReturn(NID_UI_CTRL, ((itemIndex >= 0) && (itemIndex < GetSubItemCountAt(groupIndex))),
1141                                 -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument used. itemIndex = %d.", itemIndex);
1142
1143         const CustomListItem* pItem = GetCustomListItemAt(groupIndex, itemIndex);
1144         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);
1145
1146         return pItem->__pCustomListItemImpl->itemId;
1147 }
1148
1149 void
1150 _GroupedListImpl::SetListBackgroundColor(const Color& bgColor)
1151 {
1152         GetCore().SetBackgroundColor(bgColor);
1153         return;
1154 }
1155
1156 void
1157 _GroupedListImpl::OnTableViewItemStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1158 {
1159         return;
1160 }
1161
1162 void
1163 _GroupedListImpl::OnTableViewContextItemActivationStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pContextItem, bool activated)
1164 {
1165         return;
1166 }
1167
1168 void
1169 _GroupedListImpl::OnTableViewItemReordered(_TableView& tableView, int itemIndexFrom, int itemIndexTo)
1170 {
1171         return;
1172 }
1173
1174 void
1175 _GroupedListImpl::OnGroupedTableViewGroupItemStateChanged(_TableView& tableView, int groupIndex, _TableViewItem* pItem, TableViewItemStatus status)
1176 {
1177         return;
1178 }
1179
1180 void
1181 _GroupedListImpl::OnGroupedTableViewItemStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1182 {
1183         CustomListItemStatus customListItemStatus = CUSTOM_LIST_ITEM_STATUS_NORMAL;
1184         ItemStatus itemStatus = ITEM_HIGHLIGHTED;
1185
1186         switch (status)
1187         {
1188         case TABLE_VIEW_ITEM_STATUS_SELECTED:
1189                 itemStatus = ITEM_SELECTED;
1190                 customListItemStatus = CUSTOM_LIST_ITEM_STATUS_SELECTED;
1191                 break;
1192         case TABLE_VIEW_ITEM_STATUS_HIGHLIGHTED:
1193                 itemStatus = ITEM_HIGHLIGHTED;
1194                 customListItemStatus = CUSTOM_LIST_ITEM_STATUS_FOCUSED;
1195                 break;
1196         case TABLE_VIEW_ITEM_STATUS_CHECKED:
1197                 itemStatus = ITEM_CHECKED;
1198                 break;
1199         case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
1200                 itemStatus = ITEM_UNCHECKED;
1201                 break;
1202         default:
1203                 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. item status is invalid(%d).", status);
1204                 SetLastResult(E_SYSTEM);
1205                 return;
1206         }
1207
1208         CustomListItem* pCustomListItem = GetCustomListItemAt(groupIndex, itemIndex);
1209         SysTryReturnVoidResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", itemIndex);
1210
1211         LinkedList* pElements = &pCustomListItem->__pCustomListItemImpl->elements;
1212         _ElementBaseModel* pElementBase = null;
1213
1214         for (int i = 0; i < pElements->GetCount(); i++)
1215         {
1216                 pElementBase = dynamic_cast<_ElementBaseModel*>(pElements->GetAt(i));
1217                 SysTryReturnVoidResult(NID_UI_CTRL, (pElementBase != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get valid element at index %d.", i);
1218
1219                 if ((_isDividerEnabled && pElementBase->_elementType != LIST_ITEM_ELEMENT_TYPE_CHECKBOX) || (!_isDividerEnabled))
1220                 {
1221                         pElementBase->HandleElementEvent(customListItemStatus);
1222                 }
1223         }
1224
1225         if ((!_isDividerEnabled) && (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL))
1226         {
1227                 bool isChecked = IsItemChecked(groupIndex, itemIndex);
1228
1229                 if (isChecked)
1230                 {
1231                         itemStatus = ITEM_UNCHECKED;
1232                 }
1233                 else
1234                 {
1235                         itemStatus = ITEM_CHECKED;
1236                 }
1237
1238                 SetItemChecked(groupIndex, itemIndex, !isChecked);
1239         }
1240
1241         ProcessItemStateChange(groupIndex, itemIndex, itemStatus);
1242
1243         GetCore().Draw();
1244         return;
1245 }
1246
1247 void
1248 _GroupedListImpl::OnGroupedTableViewContextItemActivationStateChanged(_TableView& tableView, int groupIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
1249 {
1250         return;
1251 }
1252
1253 void
1254 _GroupedListImpl::OnGroupedTableViewItemReordered(_TableView& tableView, int groupIndexFrom, int itemIndexFrom, int groupIndexTo, int itemIndexTo)
1255 {
1256         return;
1257 }
1258
1259 void
1260 _GroupedListImpl::OnSectionTableViewItemStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1261 {
1262         return;
1263 }
1264
1265 void
1266 _GroupedListImpl::OnSectionTableViewContextItemActivationStateChanged(_TableView& tableView, int sectionIndex, int itemIndex, _TableViewItem* pContextItem, bool activated)
1267 {
1268         return;
1269 }
1270
1271 void
1272 _GroupedListImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
1273 {
1274         return;
1275 }
1276
1277 void
1278 _GroupedListImpl::ProcessItemStateChange(int groupIndex, int itemIndex, int elementId, ItemStatus itemStatus)
1279 {
1280         int itemId = GetItemIdAt(groupIndex, itemIndex);
1281         _ListListener* pListenerData = null;
1282         IGroupedItemEventListener* pGroupedItemEventListener = null;
1283         int count = __itemListenersList.GetCount();
1284
1285         for (int listenerCount = 0; listenerCount < count; listenerCount++)
1286         {
1287                 pListenerData = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
1288                 if (pListenerData != null)
1289                 {
1290                         pGroupedItemEventListener = dynamic_cast<IGroupedItemEventListener*>(pListenerData->pListener);
1291                         SysTryReturnVoidResult(NID_UI_CTRL, (pGroupedItemEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get EventListener");
1292
1293                         pGroupedItemEventListener->OnItemStateChanged(GetPublic(), groupIndex, itemIndex, itemId, elementId, itemStatus);
1294                 }
1295         }
1296
1297         return;
1298 }
1299
1300 void
1301 _GroupedListImpl::ProcessItemStateChange(int groupIndex, int itemIndex, ItemStatus itemStatus)
1302 {
1303         int itemId = GetItemIdAt(groupIndex, itemIndex);
1304         _ListListener* pListenerData = null;
1305         IGroupedItemEventListener* pGroupedItemEventListener = null;
1306         int count = __itemListenersList.GetCount();
1307
1308         for (int listenerCount = 0; listenerCount < count; listenerCount++)
1309         {
1310                 pListenerData = dynamic_cast<_ListListener*>(__itemListenersList.GetAt(listenerCount));
1311                 if (pListenerData != null)
1312                 {
1313                         pGroupedItemEventListener = dynamic_cast<IGroupedItemEventListener*>(pListenerData->pListener);
1314                         SysTryReturnVoidResult(NID_UI_CTRL, (pGroupedItemEventListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get EventListener");
1315                         pGroupedItemEventListener->OnItemStateChanged(GetPublic(), groupIndex, itemIndex, itemId, itemStatus);
1316                 }
1317         }
1318         SetLastResult(E_SUCCESS);
1319         return;
1320 }
1321
1322 void
1323 _GroupedListImpl::OnUiFastScrollIndexSelected(_Control& source, _FastScrollIndex& index)
1324 {
1325         _ListListener* pListenerData = null;
1326         IFastScrollEventListener* pFastScrollListener = null;
1327         int listenerCount = __fastScrollListenersList.GetCount();
1328
1329         for (int listenerIndex = 0; listenerIndex < listenerCount; listenerIndex++)
1330         {
1331                 pListenerData = dynamic_cast<_ListListener*>(__fastScrollListenersList.GetAt(listenerIndex));
1332                 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerData != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get ScrollEventListener");
1333
1334                 pFastScrollListener = dynamic_cast<IFastScrollEventListener*>(pListenerData->pListener);
1335                 SysTryReturnVoidResult(NID_UI_CTRL, (pFastScrollListener != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get ScrollEventListener");
1336
1337                 wchar_t mch = L' ';
1338                 String* pIndexText = index.GetIndexText();
1339                 if (pIndexText != null)
1340                 {
1341                         pIndexText->GetCharAt(0, mch);
1342                 }
1343                 const Control& control = GetPublic();
1344                 _FastScrollIndex* __pMainIndex = index.GetParentIndex();
1345                 if (__pMainIndex == GetCore().GetFastScrollBar()->GetIndex())
1346                 {
1347                         Character mainIndex(mch);
1348                         pFastScrollListener->OnMainIndexChanged(control, mainIndex);
1349                 }
1350         }
1351         SetLastResult(E_SUCCESS);
1352         return;
1353 }
1354
1355
1356 void
1357 _GroupedListImpl::OnBoundsChanged(void)
1358 {
1359         GetCore().OnBoundsChanged();
1360         return;
1361 }
1362
1363 result
1364 _GroupedListImpl::SetFastScrollMainIndex(const String& text)
1365 {
1366         SysTryReturn(NID_UI_CTRL, (text.GetLength() > 0), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Empty string");
1367
1368         result r = GetCore().SetFastScrollIndex(text, false);
1369         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
1370
1371         __mainIndexText = text;
1372
1373         return E_SUCCESS;
1374 }
1375
1376 class _GroupedListMaker
1377         : public _UiBuilderControlMaker
1378 {
1379 public:
1380         _GroupedListMaker(_UiBuilder* uibuilder)
1381                 : _UiBuilderControlMaker(uibuilder){};
1382         virtual ~_GroupedListMaker(){};
1383         static _UiBuilderControlMaker*
1384         GetInstance(_UiBuilder* uibuilder)
1385         {
1386                 _GroupedListMaker* pGroupedListMaker = new (std::nothrow) _GroupedListMaker(uibuilder);
1387                 return pGroupedListMaker;
1388         };
1389 protected:
1390         virtual Tizen::Ui::Control*
1391         Make(_UiBuilderControl* pControl)
1392         {
1393                 result r = E_SYSTEM;
1394                 _UiBuilderControlLayout* pControlProperty = null;
1395                 GroupedList* pGroupedList = null;
1396                 Rectangle rect;
1397                 Rectangle rectMin;
1398                 Dimension dimMin;
1399
1400                 Tizen::Base::String elementString;
1401                 CustomListStyle style = CUSTOM_LIST_STYLE_NORMAL;
1402                 bool isItemDivider = true;
1403                 bool isFastScroll = false;
1404                 Color color;
1405
1406                 GetProperty(pControl, &pControlProperty);
1407                 if (pControlProperty == null)
1408                 {
1409                         return null;
1410                 }
1411
1412                 pGroupedList = new (std::nothrow) GroupedList();
1413                 if (pGroupedList == null)
1414                 {
1415                         return null;
1416                 }
1417
1418                 rect = pControlProperty->GetRect();
1419
1420                 Tizen::Base::String styleString;
1421                 styleString = pControlProperty->GetStyle();
1422
1423                 if (styleString.Equals(L"CUSTOM_LIST_STYLE_NORMAL", false))
1424                 {
1425                         style = CUSTOM_LIST_STYLE_NORMAL;
1426                 }
1427                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO", false))
1428                 {
1429                         style = CUSTOM_LIST_STYLE_RADIO;
1430                 }
1431                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER", false))
1432                 {
1433                         style = CUSTOM_LIST_STYLE_RADIO_WITH_DIVIDER;
1434                 }
1435                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK", false))
1436                 {
1437                         style = CUSTOM_LIST_STYLE_MARK;
1438                 }
1439                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER", false))
1440                 {
1441                         style = CUSTOM_LIST_STYLE_MARK_WITH_DIVIDER;
1442                 }
1443                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF", false))
1444                 {
1445                         style = CUSTOM_LIST_STYLE_ONOFF;
1446                 }
1447                 else if (styleString.Equals(L"CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER", false))
1448                 {
1449                         style = CUSTOM_LIST_STYLE_ONOFF_WITH_DIVIDER;
1450                 }
1451                 else
1452                 {
1453                         style = CUSTOM_LIST_STYLE_NORMAL;
1454                 }
1455
1456                 //Construct
1457                 if (pControl->GetElement("itemDivider", elementString))
1458                 {
1459                         if (elementString.Equals(L"true", false))
1460                         {
1461                                 isItemDivider = true;
1462                         }
1463                         else
1464                         {
1465                                 isItemDivider = false;
1466                         }
1467                 }
1468
1469                 if (pControl->GetElement("fastScroll", elementString))
1470                 {
1471                         if (elementString.Equals(L"true", false))
1472                         {
1473                                 isFastScroll = true;
1474                         }
1475                         else
1476                         {
1477                                 isFastScroll = false;
1478                         }
1479                 }
1480
1481                 r = pGroupedList->Construct(rect, style, isItemDivider, isFastScroll);
1482                 if (r != E_SUCCESS)
1483                 {
1484                         delete pGroupedList;
1485                         return null;
1486                 }
1487
1488                 if (pControl->GetElement("textOfEmptyList", elementString))
1489                 {
1490                         pGroupedList->SetTextOfEmptyList(elementString);
1491                 }
1492
1493                 if (pControl->GetElement("colorOfEmptyListText", elementString))
1494                 {
1495                         ConvertStringToColor(elementString, color);
1496                         pGroupedList->SetTextColorOfEmptyList(color);
1497                 }
1498
1499                 GET_DIMENSION_CONFIG(LIST::GROUPEDLIST_MIN_SIZE, _CONTROL_ORIENTATION_PORTRAIT, dimMin);
1500                 rectMin = (pControl->GetAttribute(0))->GetRect();
1501                 (pControl->GetAttribute(0))->SetRect(rectMin.x, rectMin.y, dimMin.width, dimMin.height);
1502
1503                 GET_DIMENSION_CONFIG(LIST::GROUPEDLIST_MIN_SIZE, _CONTROL_ORIENTATION_LANDSCAPE, dimMin);
1504                 rectMin = (pControl->GetAttribute(1))->GetRect();
1505                 (pControl->GetAttribute(1))->SetRect(rectMin.x, rectMin.y, dimMin.width, dimMin.height);
1506
1507                 return pGroupedList;
1508         }
1509
1510 private:
1511 };
1512
1513 _GroupedListRegister::_GroupedListRegister()
1514 {
1515         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1516         if (pUiBuilderControlTableManager)
1517         {
1518                 pUiBuilderControlTableManager->RegisterControl(L"GroupedList", _GroupedListMaker::GetInstance);
1519         }
1520 }
1521 _GroupedListRegister::~_GroupedListRegister()
1522 {
1523         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1524         if (pUiBuilderControlTableManager)
1525         {
1526                 pUiBuilderControlTableManager->UnregisterControl(L"GroupedList");
1527         }
1528 }
1529 static _GroupedListRegister GroupedListRegisterToUiBuilder;
1530 }}} //Tizen::Ui::Controls