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