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