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