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