Revert " modify license, permission and remove ^M char"
[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 #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         _CheckElementModel* pCheckElementModel = GetCheckElementAt(-1, index);
738
739         if (pCheckElementModel)
740         {
741                 if (enable)
742                 {
743                         if (pCheckElementModel->GetCheckBoxStatus() == CHECK_BOX_DISABLED)
744                         {
745                                 pCheckElementModel->SetCheckBoxStatus(CHECK_BOX_CHECKED);
746                         }
747                 }
748                 else
749                 {
750                         if (pCheckElementModel->GetCheckBoxStatus() == CHECK_BOX_CHECKED)
751                         {
752                                 if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_MARK)
753                                 {
754                                         pCheckElementModel->SetCheckBoxStatus(CHECK_BOX_DISABLED);
755                                 }
756                         }
757                 }
758         }
759
760         r = GetCore().SetItemEnabled(0, index, enable);
761         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
762
763         DrawItem(-1, index);
764
765         return r;
766 }
767
768 bool
769 _ListImpl::IsItemEnabled(int index) const
770 {
771         return GetCore().IsItemEnabled(0, index);
772 }
773
774 void
775 _ListImpl::SetFocusedItemBackgroundBitmap(const Bitmap& bitmap)
776 {
777         __pFocusedBgBitmap = const_cast<Bitmap*>(&bitmap);
778         SysTryReturnVoidResult(NID_UI_CTRL, __pFocusedBgBitmap, E_SYSTEM,
779                         "[E_SYSTEM] A system error has occurred. Failed to get the Bitmap");
780         SetBitmap(TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED, bitmap);
781
782         return;
783 }
784
785 void
786 _ListImpl::SetHighlightedItemBackgroundBitmap(const Bitmap& bitmap)
787 {
788         __pHighlightedBgBitmap = const_cast<Bitmap*>(&bitmap);
789         SysTryReturnVoidResult(NID_UI_CTRL, __pHighlightedBgBitmap, E_SYSTEM,
790                         "[E_SYSTEM] A system error has occurred. Failed to get the Bitmap");
791         SetBitmap(TABLE_VIEW_ITEM_DRAWING_STATUS_HIGHLIGHTED, bitmap);
792
793         return;
794 }
795
796 void
797 _ListImpl::SetNormalItemBackgroundBitmap(const Bitmap& bitmap)
798 {
799         __pNormalBgBitmap = const_cast<Bitmap*>(&bitmap);
800         SysTryReturnVoidResult(NID_UI_CTRL, __pNormalBgBitmap, E_SYSTEM,
801                         "[E_SYSTEM] A system error has occurred. Failed to get the Bitmap");
802         SetBitmap(TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL, bitmap);
803
804         return;
805 }
806
807 void
808 _ListImpl::SetItemTextColor(ListItemText textIndex, const Color& textColor)
809 {
810         int elementId = -1;
811
812         SysTryReturnVoidResult(NID_UI_CTRL, (__listItemFormat != LIST_ITEM_SINGLE_IMAGE), E_SYSTEM,
813                         "[E_SYSTEM] A system error has occurred. The current value of ListItemFormat is invalid.");
814
815         switch (textIndex)
816         {
817         case LIST_ITEM_TEXT1:
818                 __text1Color.SetRGB32(textColor.GetRGB32(), textColor.GetAlpha());
819                 elementId = ID_FORMAT_TEXT1;
820                 break;
821
822         case LIST_ITEM_TEXT2:
823                 SysTryReturnVoidResult(NID_UI_CTRL, (__listItemFormat > LIST_ITEM_SINGLE_IMAGE_TEXT_IMAGE), E_SYSTEM,
824                                 "[E_SYSTEM] A system error has occurred. The current value of ListItemFormat is invalid.");
825                 __text2Color.SetRGB32(textColor.GetRGB32(), textColor.GetAlpha());
826                 elementId = ID_FORMAT_TEXT2;
827                 break;
828
829         default:
830                 SysTryReturnVoidResult(NID_UI_CTRL, (false), E_SYSTEM,
831                                 "[E_SYSTEM] A system error has occurred. The current value of ListItemText is invalid.");
832         }
833
834         Rectangle text1Rect;
835         Rectangle text2Rect;
836         Rectangle img1Rect;
837         Rectangle img2Rect;
838
839         GetElementRects(text1Rect, text2Rect, img1Rect, img2Rect);
840
841         switch (textIndex)
842         {
843         case LIST_ITEM_TEXT1:
844                 __pItemFormat->AddElement(elementId, text1Rect, 38, __text1Color, __text1Color, __text1Color);
845                 break;
846
847         case LIST_ITEM_TEXT2:
848                 __pItemFormat->AddElement(elementId, text2Rect, 38, __text2Color, __text2Color, __text2Color);
849                 break;
850         }
851
852         int count = GetItemCount();
853         for (int index = 0; index < count; index++)
854         {
855                 Refresh(index);
856         }
857
858         return;
859 }
860
861 Color
862 _ListImpl::GetItemTextColor(ListItemText textIndex) const
863 {
864         if (textIndex == LIST_ITEM_TEXT1)
865         {
866                 return __text1Color;
867         }
868         else if(textIndex == LIST_ITEM_TEXT2)
869         {
870                 return __text2Color;
871         }
872         else
873         {
874                 SysLog(NID_UI_CTRL, "[E_SYSTEM] A system error has occurred. The current value of ListItemText is invalid.");
875         }
876
877         return Color();
878 }
879
880 void
881 _ListImpl::EnableTextSlide(ListItemText textIndex)
882 {
883         int elementId = -1;
884         switch (textIndex)
885         {
886         case LIST_ITEM_TEXT1:
887                 __text1SlideEnabled = true;
888                 elementId = ID_FORMAT_TEXT1;
889                 break;
890
891         case LIST_ITEM_TEXT2:
892                 __text2SlideEnabled = true;
893                 elementId = ID_FORMAT_TEXT2;
894                 break;
895
896         default:
897                 break;
898         }
899         SysTryReturnVoidResult(NID_UI_CTRL, (elementId != -1), E_SYSTEM,
900                         "[E_SYSTEM] A system error has occurred. The ListItemText is invalid.");
901
902         int maxCount = GetItemCount();
903
904         for (int itemCount = 0; itemCount < maxCount; itemCount++)
905         {
906                 CustomListItem* pItem = GetCustomListItemAt(-1, itemCount);
907                 SysTryReturnVoidResult(NID_UI_CTRL, (pItem), E_SYSTEM,
908                                         "[E_SYSTEM] A system error has occurred. Failed to get item at %d.", itemCount);
909
910                 _CustomListItemImpl *pItemImpl = pItem->__pCustomListItemImpl;
911                 SysTryReturnVoidResult(NID_UI_CTRL, (pItemImpl), E_SYSTEM,
912                                                         "[E_SYSTEM] A system error has occurred. Failed to get item at %d.", itemCount);
913
914                 pItemImpl->SetTextSliding(elementId, true);
915         }
916
917         return;
918 }
919
920 void
921 _ListImpl::DisableTextSlide(void)
922 {
923         __text1SlideEnabled = false;
924         __text2SlideEnabled = false;
925
926         int maxCount = GetItemCount();
927
928         for (int itemCount = 0; itemCount < maxCount; itemCount++)
929         {
930                 CustomListItem* pItem = GetCustomListItemAt(-1, itemCount);
931                 SysTryReturnVoidResult(NID_UI_CTRL, (pItem), E_SYSTEM,
932                                         "[E_SYSTEM] A system error has occurred. Failed to get item at %d.", itemCount);
933
934                 _CustomListItemImpl *pItemImpl = pItem->__pCustomListItemImpl;
935                 SysTryReturnVoidResult(NID_UI_CTRL, (pItemImpl), E_SYSTEM,
936                                                         "[E_SYSTEM] A system error has occurred. Failed to get item at %d.", itemCount);
937
938                 pItemImpl->SetTextSliding(ID_FORMAT_TEXT1, false);
939                 pItemImpl->SetTextSliding(ID_FORMAT_TEXT2, false);
940         }
941
942         return;
943 }
944
945 int
946 _ListImpl::GetItemHeight(void) const
947 {
948         if (__listItemFormat < LIST_ITEM_DOUBLE_IMAGE_TEXT_FULLTEXT)
949         {
950                 return __row1Height;
951         }
952
953         return __row1Height + __row2Height;
954 }
955
956 int
957 _ListImpl::GetRow1Height(void) const
958 {
959         return __row1Height;
960 }
961
962 int
963 _ListImpl::GetRow2Height(void) const
964 {
965         return __row2Height;
966 }
967
968 int
969 _ListImpl::GetColumn1Width(void) const
970 {
971         return __column1Width;
972 }
973
974 int
975 _ListImpl::GetColumn2Width(void) const
976 {
977         return __column2Width;
978 }
979
980 result
981 _ListImpl::SetRow1Height(int row1Height)
982 {
983         __row1Height = row1Height;
984         if (GetCore().GetFirstDrawnFlag() == false)
985         {
986                 return ReDrawList();
987         }
988
989         return E_SUCCESS;
990 }
991
992 result
993 _ListImpl::SetRow2Height(int row2Height)
994 {
995         if (__listItemFormat < LIST_ITEM_DOUBLE_IMAGE_TEXT_FULLTEXT)
996         {
997                 __row2Height = 0;
998         }
999         else
1000         {
1001                 __row2Height = row2Height;
1002                 if (GetCore().GetFirstDrawnFlag() == false)
1003                 {
1004                         return ReDrawList();
1005                 }
1006         }
1007
1008         return E_SUCCESS;
1009 }
1010
1011 result
1012 _ListImpl::SetColumn1Width(int column1Width)
1013 {
1014         __column1Width = column1Width;
1015         if (GetCore().GetFirstDrawnFlag() == false)
1016         {
1017                 return ReDrawList();
1018         }
1019
1020         return E_SUCCESS;
1021 }
1022
1023 result
1024 _ListImpl::SetColumn2Width(int column2Width)
1025 {
1026         __column2Width = column2Width;
1027         if (GetCore().GetFirstDrawnFlag() == false)
1028         {
1029                 return ReDrawList();
1030         }
1031
1032         return E_SUCCESS;
1033 }
1034
1035
1036 result
1037 _ListImpl::SetItemChecked(int index, bool check)
1038 {
1039         SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), E_SYSTEM,
1040                         "A system error has occurred. The current value of index(%d) is invalid.", index);
1041
1042         SysTryReturnResult(NID_UI_CTRL, (__listStyle != LIST_STYLE_NORMAL), E_SYSTEM,
1043                         "A system error has occurred. List style should not be LIST_STYLE_NORMAL");
1044         SysTryReturnResult(NID_UI_CTRL, (__listStyle != LIST_STYLE_NUMBER), E_SYSTEM,
1045                         "A system error has occurred. List style should not be LIST_STYLE_NUMBER");
1046
1047         if (IsItemChecked(index) == check)
1048         {
1049                 return E_SUCCESS;
1050         }
1051
1052         SysTryReturnResult(NID_UI_CTRL, (IsItemEnabled(index)), E_SYSTEM,
1053                         "A system error has occurred. The List item is not enabled at index(%d).", index);
1054
1055         _CheckElementModel* pCheckElementModel = GetCheckElementAt(-1, index);
1056         SysTryReturnResult(NID_UI_CTRL, pCheckElementModel, E_SYSTEM,
1057                         "A system error has occurred. _CheckElementModel instance is null.");
1058
1059         if (_annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
1060         {
1061                 if (check)
1062                 {
1063                         if (_currentRadioIndex != -1)
1064                         {
1065                                 _CheckElementModel* pOldCheckElementModel = GetCheckElementAt(-1, _currentRadioIndex);
1066                                 SysTryReturnResult(NID_UI_CTRL, pOldCheckElementModel, E_SYSTEM,
1067                                                 "A system error has occurred. _CheckElementModel instance is null.");
1068
1069                                 pOldCheckElementModel->SetCheckBoxStatus(CHECK_BOX_UNCHECKED);
1070                                 DrawItem(-1, _currentRadioIndex);
1071                         }
1072                         _currentRadioIndex = index;
1073                 }
1074                 else
1075                 {
1076                         _currentRadioIndex = -1;
1077                 }
1078         }
1079
1080         pCheckElementModel->SetCheckBoxStatus((_CheckBoxBitmapType)check);
1081
1082         DrawItem(-1, index);
1083
1084         return E_SUCCESS;
1085 }
1086
1087 bool
1088 _ListImpl::IsItemChecked(int index) const
1089 {
1090         SysTryReturn(NID_UI_CTRL, (__listStyle != LIST_STYLE_NORMAL), false, E_SYSTEM,
1091                         "[E_SYSTEM] A system error has occurred. List style should not be LIST_STYLE_NORMAL.");
1092         SysTryReturn(NID_UI_CTRL, (__listStyle != LIST_STYLE_NUMBER), false, E_SYSTEM,
1093                         "[E_SYSTEM]  A system error has occurred. List style should not be LIST_STYLE_NUMBER.");
1094
1095         SysTryReturn(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
1096                         false, E_INVALID_ARG, "[E_INVALID_ARG] The current value of index(%d) is invalid.", index);
1097
1098         const _CheckElementModel* pCheckElement = GetCheckElementAt(-1, index);
1099         SysTryReturn(NID_UI_CTRL, pCheckElement, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. CheckElement is not constructed properly.");
1100
1101         return (bool)pCheckElement->GetCheckBoxStatus();
1102 }
1103
1104 result
1105 _ListImpl::SetAllItemsChecked(bool check)
1106 {
1107         SysTryReturnResult(NID_UI_CTRL, (__listStyle != LIST_STYLE_NORMAL), E_SYSTEM,
1108                         "A system error has occurred. List style should not be LIST_STYLE_NORMAL");
1109         SysTryReturnResult(NID_UI_CTRL, (__listStyle != LIST_STYLE_NUMBER), E_SYSTEM,
1110                         "A system error has occurred. List style should not be LIST_STYLE_NUMBER");
1111         SysTryReturnResult(NID_UI_CTRL, (__listStyle != LIST_STYLE_RADIO), E_SYSTEM,
1112                         "A system error has occurred. List style should not be LIST_STYLE_RADIO");
1113         SysTryReturnResult(NID_UI_CTRL, (__listStyle != LIST_STYLE_RADIO_WITH_DIVIDER), E_SYSTEM,
1114                         "A system error has occurred. List style should not be LIST_STYLE_RADIO_WITH_DIVIDER");
1115
1116         _CheckElementModel* pCheckElement = null;
1117
1118         for (int index = 0; index < GetItemCount(); index++)
1119         {
1120                 if (IsItemEnabled(index))
1121                 {
1122                         pCheckElement = GetCheckElementAt(-1, index);
1123                         SysTryReturnResult(NID_UI_CTRL, (pCheckElement != null), E_SYSTEM,
1124                                         "A system error has occurred. _CheckElementModel instance is null.");
1125
1126                         pCheckElement->SetCheckBoxStatus((_CheckBoxBitmapType)check);
1127                 }
1128         }
1129
1130         GetCore().Draw();
1131
1132         return E_SUCCESS;
1133 }
1134
1135 result
1136 _ListImpl::RemoveAllCheckedItems(void)
1137 {
1138         SysTryReturnResult(NID_UI_CTRL, (__listStyle != LIST_STYLE_NORMAL), E_SYSTEM,
1139                         "A system error has occurred. List style should not be LIST_STYLE_NORMAL");
1140         SysTryReturnResult(NID_UI_CTRL, (__listStyle != LIST_STYLE_NUMBER), E_SYSTEM,
1141                         "A system error has occurred. List style should not be LIST_STYLE_NUMBER");
1142         SysTryReturnResult(NID_UI_CTRL, (__listStyle != LIST_STYLE_RADIO), E_SYSTEM,
1143                         "A system error has occurred. List style should not be LIST_STYLE_RADIO");
1144         SysTryReturnResult(NID_UI_CTRL, (__listStyle != LIST_STYLE_RADIO_WITH_DIVIDER), E_SYSTEM,
1145                         "A system error has occurred. List style should not be LIST_STYLE_RADIO_WITH_DIVIDER");
1146
1147         result r = E_SUCCESS;
1148         result finalResult = E_SUCCESS;
1149
1150         for (int index = GetItemCount() -1; index >= 0; index--)
1151         {
1152                 if (IsItemChecked(index))
1153                 {
1154                         r = RemoveItemAt(index);
1155
1156                         if (r != E_SUCCESS)
1157                         {
1158                                 finalResult = r;
1159                                 SysLog(NID_UI_CTRL, "[%s] Item at index(%d) is not removed successfully.", GetErrorMessage(r), index);
1160                         }
1161                 }
1162         }
1163
1164         return finalResult;
1165 }
1166
1167 int
1168 _ListImpl::GetFirstCheckedItemIndex(void) const
1169 {
1170         SysTryReturn(NID_UI_CTRL, (__listStyle != LIST_STYLE_NORMAL), INVALID_INDEX, E_SYSTEM,
1171                         "[E_SYSTEM] A system error has occurred. List style should not be LIST_STYLE_NORMAL.");
1172         SysTryReturn(NID_UI_CTRL, (__listStyle != LIST_STYLE_NUMBER), INVALID_INDEX, E_SYSTEM,
1173                         "[E_SYSTEM] A system error has occurred. List style should not be LIST_STYLE_NUMBER.");
1174
1175         for (int index = 0; index < GetItemCount(); index++)
1176         {
1177                 if (IsItemChecked(index))
1178                 {
1179                         SetLastResult(E_SUCCESS);
1180                         return index;
1181                 }
1182         }
1183         SetLastResult(E_SUCCESS);
1184         return INVALID_INDEX;
1185 }
1186
1187 int
1188 _ListImpl::GetLastCheckedItemIndex(void) const
1189 {
1190         SysTryReturn(NID_UI_CTRL, (__listStyle != LIST_STYLE_NORMAL), INVALID_INDEX, E_SYSTEM,
1191                         "[E_SYSTEM] A system error has occurred. List style should not be LIST_STYLE_NORMAL.");
1192         SysTryReturn(NID_UI_CTRL, (__listStyle != LIST_STYLE_NUMBER), INVALID_INDEX, E_SYSTEM,
1193                         "[E_SYSTEM] A system error has occurred. List style should not be LIST_STYLE_NUMBER.");
1194
1195         for (int index = GetItemCount() - 1; index >= 0; index--)
1196         {
1197         if (IsItemChecked(index))
1198         {
1199                 SetLastResult(E_SUCCESS);
1200                 return index;
1201         }
1202         }
1203         SetLastResult(E_SUCCESS);
1204
1205         return INVALID_INDEX;
1206 }
1207
1208 int
1209 _ListImpl::GetNextCheckedItemIndexAfter(int index) const
1210 {
1211         SysTryReturn(NID_UI_CTRL, (__listStyle != LIST_STYLE_NORMAL), INVALID_INDEX, E_SYSTEM,
1212                         "[E_SYSTEM] A system error has occurred. List style should not be LIST_STYLE_NORMAL.");
1213         SysTryReturn(NID_UI_CTRL, (__listStyle != LIST_STYLE_NUMBER), INVALID_INDEX, E_SYSTEM,
1214                         "[E_SYSTEM] A system error has occurred. List style should not be LIST_STYLE_NUMBER.");
1215
1216         SysTryReturn(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), INVALID_INDEX, E_SYSTEM,
1217                         "[E_SYSTEM] A system error has occurred. The current value of index(%d) is invalid.") ;
1218
1219         for (int itemCount = index + 1; itemCount < GetItemCount(); itemCount++)
1220         {
1221                 if (IsItemChecked(itemCount))
1222                 {
1223                         SetLastResult(E_SUCCESS);
1224                         return itemCount;
1225                 }
1226         }
1227         SetLastResult(E_SUCCESS);
1228
1229         return INVALID_INDEX;
1230 }
1231
1232 int
1233 _ListImpl::GetItemIndexFromItemId(int itemId) const
1234 {
1235         for (int index = 0; index < GetItemCount(); index++)
1236         {
1237                 const CustomListItem* pCustomListItem = GetCustomListItemAt(-1, index);
1238                 SysTryReturn(NID_UI_CTRL, pCustomListItem, INVALID_INDEX, E_SYSTEM,
1239                                 "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", index);
1240
1241                 if (pCustomListItem->__pCustomListItemImpl->itemId == itemId)
1242                 {
1243                         SetLastResult(E_SUCCESS);
1244                         return index;
1245                 }
1246         }
1247
1248         SetLastResult(E_SUCCESS);
1249
1250         return INVALID_INDEX;
1251 }
1252
1253 int
1254 _ListImpl::GetItemIdAt(int index) const
1255 {
1256         SysTryReturn(NID_UI_CTRL, (index >= 0 && index < GetItemCount()),
1257                         -1, E_INVALID_ARG, "[E_INVALID_ARG] The current value of index(%d) is invalid.", index);
1258
1259         const CustomListItem* pCustomListItem = GetCustomListItemAt(-1, index);
1260         SysTryReturn(NID_UI_CTRL, pCustomListItem, -1, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get an item at index(%d).", index);
1261
1262         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);
1263
1264         SetLastResult(E_SUCCESS);
1265         return pCustomListItem->__pCustomListItemImpl->itemId;
1266 }
1267
1268 void
1269 _ListImpl::ScrollToBottom(void)
1270 {
1271         result r = E_SUCCESS;
1272
1273         GetCore().SetBottomDrawnItemIndex(0, GetItemCount() - 1);
1274         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1275
1276         SetLastResult(E_SUCCESS);
1277         GetCore().Draw();
1278
1279         return;
1280 }
1281
1282 void
1283 _ListImpl::ScrollToTop(void)
1284 {
1285         result r = E_SUCCESS;
1286         r = GetCore().SetTopDrawnItemIndex(0,0);
1287         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1288
1289         SetLastResult(E_SUCCESS);
1290         GetCore().Draw();
1291
1292         return;
1293 }
1294
1295 result
1296 _ListImpl::ScrollToTop(int index)
1297 {
1298         SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), E_INVALID_ARG, "The current value of index(%d) is invalid.", index);
1299
1300         result r = GetCore().SetTopDrawnItemIndex(0, index);
1301         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
1302
1303         GetCore().Draw();
1304
1305         return r;
1306 }
1307
1308 result
1309 _ListImpl::RefreshItem(int index)
1310 {
1311         SysTryReturnResult(NID_UI_CTRL, (index >= 0 && index < GetItemCount()), E_INVALID_ARG, "The current value of index(%d) is invalid.", index);
1312
1313         int topItemIndex = -1;
1314         int bottomItemIndex = -1;
1315         int groupIndex = -1;
1316
1317         GetCore().GetTopDrawnItemIndex(groupIndex, topItemIndex);
1318         GetCore().GetBottomDrawnItemIndex(groupIndex, bottomItemIndex);
1319
1320         SysTryReturnResult(NID_UI_CTRL, (index >= topItemIndex && index <= bottomItemIndex), E_INVALID_OPERATION,
1321                         "Index(%d) should be within drawn item range.", index);
1322
1323         result r = E_SUCCESS;
1324
1325         _TableViewItemUpdateParams updateParams;
1326         updateParams.pItem = GetCustomListItemAt(-1, index);
1327         updateParams.isDividerEnabled = _isDividerEnabled;
1328         updateParams.pCheckBitmaps = _pCheckBitmaps;
1329         updateParams.annexStyle = _annexStyle;
1330
1331         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
1332         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
1333                         "A system error has occurred. Failed to refresh an item.");
1334
1335         DrawItem(-1, index);
1336
1337         return E_SUCCESS;
1338 }
1339
1340 CustomListItem*
1341 _ListImpl::GetNewItemN(const String* pText1, const String* pText2, const Bitmap* pBitmap1, const Bitmap* pBitmap2, int itemId, int index)
1342 {
1343         SysTryReturn(NID_UI_CTRL, __pItemFormat, null, E_SYSTEM,
1344                         "[E_SYSTEM] A system error has occurred. Item Format must not be null.");
1345         Dimension listSize = GetCore().GetSize();
1346         Rectangle text1Rect;
1347         Rectangle text2Rect;
1348         Rectangle img1Rect;
1349         Rectangle img2Rect;
1350
1351         GetElementRects(text1Rect, text2Rect, img1Rect, img2Rect);
1352
1353         CustomListItem* pItem = new (std::nothrow) CustomListItem();
1354         SysTryReturn(NID_UI_CTRL, pItem, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1355
1356         pItem->Construct(GetItemHeight());
1357         pItem->SetItemFormat(*__pItemFormat);
1358         pItem->__pCustomListItemImpl->itemId = itemId;
1359
1360         if ((pText1 != null) && (text1Rect.x > 0))
1361         {
1362                 pItem->SetElement(ID_FORMAT_TEXT1, *pText1);
1363                 pItem->__pCustomListItemImpl->SetTextSliding(ID_FORMAT_TEXT1, __text1SlideEnabled);
1364         }
1365
1366         if ((pBitmap1 != null) && (img1Rect.x > 0))
1367         {
1368                 pItem->SetElement(ID_FORMAT_IMAGE1, *pBitmap1, pBitmap1);
1369         }
1370
1371         if ((pText2 != null) && (text2Rect.x > 0))
1372         {
1373                 pItem->SetElement(ID_FORMAT_TEXT2, *pText2);
1374                 pItem->__pCustomListItemImpl->SetTextSliding(ID_FORMAT_TEXT2, __text2SlideEnabled);
1375         }
1376
1377         if ((pBitmap2 != null) && (img2Rect.x > 0))
1378         {
1379                 pItem->SetElement(ID_FORMAT_IMAGE2, *pBitmap2, pBitmap2);
1380         }
1381
1382         _NumberElement *pNumberElement = null;
1383
1384         if (__listStyle == LIST_STYLE_NUMBER)
1385         {
1386                 pNumberElement = new (std::nothrow) _NumberElement();
1387                 SysTryReturn(NID_UI_CTRL, pNumberElement, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1388                 pNumberElement->index = index + 1;
1389                 __pNumberElements->InsertAt(*pNumberElement, index);
1390                 pItem->SetElement(ID_FORMAT_NUMBER, *(dynamic_cast<ICustomListElement*>(pNumberElement)));
1391         }
1392
1393         if (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL)
1394         {
1395                 pItem->SetCheckBox(ID_FORMAT_CHECK);
1396         }
1397
1398         return pItem;
1399 }
1400
1401 void
1402 _ListImpl::GetItemMargins(int& leftMargin, int& numberStyleMargin, int& dividerMargin, int& lowerMargin, int& upperMargin)
1403 {
1404         if (__listStyle == LIST_STYLE_NUMBER)
1405         {
1406                 GET_SHAPE_CONFIG(LIST::LIST_ITEM_NUMBER_STYLE_MARGIN, GetCore().GetOrientation(), numberStyleMargin);
1407         }
1408
1409         if (__isCheckStyle)
1410         {
1411                 GET_SHAPE_CONFIG(LIST::LIST_ITEM_DIVIDER_MARGIN, GetCore().GetOrientation(), dividerMargin);
1412         }
1413
1414         GET_SHAPE_CONFIG(LIST::LIST_ITEM_LEFT_MARGIN, GetCore().GetOrientation(), leftMargin);
1415         GET_SHAPE_CONFIG(LIST::LIST_ITEM_LOWER_MARGIN, GetCore().GetOrientation(), lowerMargin);
1416         GET_SHAPE_CONFIG(LIST::LIST_ITEM_UPPER_MARGIN, GetCore().GetOrientation(), upperMargin);
1417 }
1418
1419 void
1420 _ListImpl::GetElementRects(Rectangle& text1Rect, Rectangle& text2Rect, Rectangle& img1Rect, Rectangle& img2Rect)
1421 {
1422         Dimension listSize = GetCore().GetSize();
1423
1424         int leftMargin = 0;
1425         int numberStyleMargin = 0;
1426         int dividerMargin = 0;
1427         int lowerMargin = 0;
1428         int upperMargin = 0;
1429
1430         GetItemMargins(leftMargin, numberStyleMargin, dividerMargin, lowerMargin, upperMargin);
1431
1432         switch (__listItemFormat)
1433         {
1434         case LIST_ITEM_SINGLE_IMAGE:
1435
1436                 img1Rect.x = leftMargin + numberStyleMargin;
1437                 img1Rect.y = upperMargin;
1438                 img1Rect.width = __column1Width - dividerMargin;
1439                 img1Rect.height = __row1Height - lowerMargin;
1440
1441                 break;
1442
1443         case LIST_ITEM_SINGLE_TEXT:
1444
1445                 text1Rect.x = leftMargin + numberStyleMargin;
1446                 text1Rect.y = upperMargin;
1447                 text1Rect.width = __column1Width - dividerMargin - text1Rect.x;
1448                 text1Rect.height = __row1Height - lowerMargin;
1449
1450                 break;
1451
1452         case LIST_ITEM_SINGLE_IMAGE_TEXT:
1453
1454                 img1Rect.x = leftMargin + numberStyleMargin;
1455                 img1Rect.y = upperMargin;
1456                 img1Rect.width = __column1Width;
1457                 img1Rect.height = __row1Height - lowerMargin;
1458
1459                 text1Rect.x = __column1Width + leftMargin + numberStyleMargin;
1460                 text1Rect.y = upperMargin;
1461                 text1Rect.width = (__column1Width + __column2Width + dividerMargin <= listSize.width) ? (__column2Width) : (__column2Width - dividerMargin);
1462                 text1Rect.height = __row1Height - lowerMargin;
1463
1464                 break;
1465
1466         case LIST_ITEM_SINGLE_TEXT_IMAGE:
1467
1468                 img1Rect.x = __column1Width + leftMargin + numberStyleMargin;
1469                 img1Rect.y = upperMargin;
1470                 img1Rect.width = __column1Width;
1471                 img1Rect.height = __row1Height - lowerMargin;
1472
1473                 text1Rect.x = leftMargin + numberStyleMargin;
1474                 text1Rect.y = upperMargin;
1475                 text1Rect.width = (__column1Width + __column2Width + dividerMargin <= listSize.width) ? (__column2Width) : (__column2Width - dividerMargin);
1476                 text1Rect.height = __row1Height - lowerMargin;
1477
1478                 break;
1479
1480         case LIST_ITEM_SINGLE_IMAGE_TEXT_IMAGE:
1481
1482                 img1Rect.x = leftMargin + numberStyleMargin;
1483                 img1Rect.y = upperMargin;
1484                 img1Rect.width = __column1Width;
1485                 img1Rect.height = __row1Height - lowerMargin;
1486
1487                 text1Rect.x = __column1Width + leftMargin + numberStyleMargin;
1488                 text1Rect.y = upperMargin;
1489                 text1Rect.width = __column2Width;
1490                 text1Rect.height = __row1Height - lowerMargin;
1491
1492                 img2Rect.x = text1Rect.x + __column2Width;
1493                 img2Rect.y = upperMargin;
1494                 img2Rect.width = (__column1Width + __column2Width + dividerMargin <= listSize.width) ? (__column2Width) : (__column2Width - dividerMargin);
1495                 img2Rect.height = __row1Height - lowerMargin;
1496
1497                 break;
1498
1499         case LIST_ITEM_DOUBLE_IMAGE_TEXT_FULLTEXT:
1500
1501                 img1Rect.x = leftMargin + numberStyleMargin;
1502                 img1Rect.y = upperMargin;
1503                 img1Rect.width = __column1Width;
1504                 img1Rect.height = __row1Height - lowerMargin;
1505
1506                 text1Rect.x = __column1Width + leftMargin + numberStyleMargin;
1507                 text1Rect.y = upperMargin;
1508                 text1Rect.width = (__column1Width + __column2Width + dividerMargin <= listSize.width) ? (__column2Width) : (__column2Width - dividerMargin);
1509                 text1Rect.height = __row1Height - lowerMargin;
1510
1511                 text2Rect.x = leftMargin + numberStyleMargin;
1512                 text2Rect.y = __row1Height;
1513                 text2Rect.width = __column1Width;
1514                 text2Rect.height = __row2Height - lowerMargin;
1515
1516                 break;
1517
1518         case LIST_ITEM_DOUBLE_FULLTEXT_IMAGE_TEXT:
1519
1520                 img1Rect.x = leftMargin + numberStyleMargin;
1521                 img1Rect.y = __row1Height;
1522                 img1Rect.width = __column1Width;
1523                 img1Rect.height = __row2Height;
1524
1525                 text1Rect.x = __column1Width + leftMargin + numberStyleMargin;
1526                 text1Rect.y = __row1Height;
1527                 text1Rect.width = (__column1Width + __column2Width + dividerMargin <= listSize.width) ? (__column2Width) : (__column2Width - dividerMargin);
1528                 text1Rect.height = __row2Height;
1529
1530                 text2Rect.x = leftMargin + numberStyleMargin;
1531                 text2Rect.y = upperMargin;
1532                 text2Rect.width = __column1Width;
1533                 text2Rect.height = __row1Height - lowerMargin;
1534
1535                 break;
1536
1537         case LIST_ITEM_DOUBLE_TEXT_IMAGE_FULLTEXT:
1538
1539                 img1Rect.x = __column1Width + leftMargin + numberStyleMargin;
1540                 img1Rect.y = upperMargin;
1541                 img1Rect.width = (__column1Width + __column2Width + dividerMargin <= listSize.width) ? (__column2Width) : (__column2Width - dividerMargin);
1542                 img1Rect.height = __row1Height - lowerMargin;
1543
1544                 text1Rect.x = leftMargin + numberStyleMargin;
1545                 text1Rect.y = upperMargin;
1546                 text1Rect.width = __column1Width;
1547                 text1Rect.height = __row1Height - lowerMargin;
1548
1549                 text2Rect.x = leftMargin + numberStyleMargin;
1550                 text2Rect.y = __row1Height;
1551                 text2Rect.width = __column1Width;
1552                 text2Rect.height = __row2Height;
1553
1554                 break;
1555
1556         case LIST_ITEM_DOUBLE_FULLTEXT_TEXT_IMAGE:
1557
1558                 img1Rect.x = __column1Width + leftMargin + numberStyleMargin;
1559                 img1Rect.y = __row1Height;
1560                 img1Rect.width = (__column1Width + __column2Width + dividerMargin <= listSize.width) ? (__column2Width) : (__column2Width - dividerMargin);
1561                 img1Rect.height = __row2Height;
1562
1563                 text1Rect.x = leftMargin + numberStyleMargin;
1564                 text1Rect.y = __row1Height;
1565                 text1Rect.width = __column1Width;
1566                 text1Rect.height = __row2Height;
1567
1568                 text2Rect.x = leftMargin + numberStyleMargin;
1569                 text2Rect.y = upperMargin;
1570                 text2Rect.width = __column1Width;
1571                 text2Rect.height = __row1Height - lowerMargin;
1572
1573                 break;
1574
1575         case LIST_ITEM_DOUBLE_IMAGE_TEXT_TEXT:
1576
1577                 img1Rect.x = leftMargin + numberStyleMargin;
1578                 img1Rect.y = upperMargin;
1579                 img1Rect.width = __column1Width;
1580                 img1Rect.height = __row1Height + __row2Height - lowerMargin;
1581
1582                 text1Rect.x = __column1Width + leftMargin + numberStyleMargin;
1583                 text1Rect.y = upperMargin;
1584                 text1Rect.width = (__column1Width + __column2Width + dividerMargin <= listSize.width) ? (__column2Width) : (__column2Width - dividerMargin);
1585                 text1Rect.height = __row1Height - lowerMargin;
1586
1587                 text2Rect.x = __column1Width + leftMargin + numberStyleMargin;
1588                 text2Rect.y = __row1Height;
1589                 text2Rect.width = (__column1Width + __column2Width + dividerMargin <= listSize.width) ? (__column2Width) : (__column2Width - dividerMargin);
1590                 text2Rect.height = __row2Height;
1591
1592                 break;
1593
1594         case LIST_ITEM_DOUBLE_TEXT_TEXT_IMAGE:
1595
1596                 img1Rect.x = __column1Width + leftMargin + numberStyleMargin;
1597                 img1Rect.y = upperMargin;
1598                 img1Rect.width = (__column1Width + __column2Width + dividerMargin <= listSize.width) ? (__column2Width) : (__column2Width - dividerMargin);
1599                 img1Rect.height = __row1Height + __row2Height - lowerMargin;
1600
1601                 text1Rect.x = leftMargin + numberStyleMargin;
1602                 text1Rect.y = upperMargin;
1603                 text1Rect.width = __column1Width;
1604                 text1Rect.height = __row2Height - lowerMargin;
1605
1606                 text2Rect.x = leftMargin + numberStyleMargin;
1607                 text2Rect.y = __row1Height;
1608                 text2Rect.width = __column1Width;
1609                 text2Rect.height = __row1Height;
1610
1611                 break;
1612         }
1613 }
1614
1615 result
1616 _ListImpl::ReDrawList(void)
1617 {
1618         Rectangle text1Rect;
1619         Rectangle text2Rect;
1620         Rectangle img1Rect;
1621         Rectangle img2Rect;
1622         int groupIndex = -1;
1623         int currIndex = -1;
1624
1625         GetTopDrawnItemIndex(groupIndex, currIndex);
1626
1627         GetElementRects(text1Rect, text2Rect, img1Rect, img2Rect);
1628
1629         int textSize = 0;
1630         int listStyleNumberX = 0;
1631         int listStyleNumberWidth = 0;
1632         int listStyleNumberHeight = 0;
1633         int checkItemWidth = 0;
1634         int checkItemHeight = 0;
1635
1636         GET_SHAPE_CONFIG(LIST::LIST_ITEM_TEXT_SIZE, GetCore().GetOrientation(), textSize);
1637
1638         GET_SHAPE_CONFIG(LIST::LIST_STYLE_NUMBER_X, GetCore().GetOrientation(), listStyleNumberX);
1639         GET_SHAPE_CONFIG(LIST::LIST_STYLE_NUMBER_WIDTH, GetCore().GetOrientation(), listStyleNumberWidth);
1640         GET_SHAPE_CONFIG(LIST::LIST_STYLE_NUMBER_HEIGHT, GetCore().GetOrientation(), listStyleNumberHeight);
1641
1642         GET_SHAPE_CONFIG(LIST::LIST_CHECK_ITEM_WIDTH, GetCore().GetOrientation(), checkItemWidth);
1643         GET_SHAPE_CONFIG(LIST::LIST_CHECK_ITEM_HEIGHT, GetCore().GetOrientation(), checkItemHeight);
1644
1645         if (text1Rect.x > 0)
1646         {
1647                 __pItemFormat->AddElement(ID_FORMAT_TEXT1, text1Rect);
1648                 __pItemFormat->SetElementEventEnabled(ID_FORMAT_TEXT1, false);
1649         }
1650
1651         if (img1Rect.x > 0)
1652         {
1653                 __pItemFormat->AddElement(ID_FORMAT_IMAGE1, img1Rect);
1654                 __pItemFormat->SetElementEventEnabled(ID_FORMAT_IMAGE1, false);
1655         }
1656
1657         if (text2Rect.x > 0)
1658         {
1659                 __pItemFormat->AddElement(ID_FORMAT_TEXT2, text2Rect);
1660                 __pItemFormat->SetElementEventEnabled(ID_FORMAT_TEXT2, false);
1661         }
1662
1663         if (img2Rect.x > 0)
1664         {
1665                 __pItemFormat->AddElement(ID_FORMAT_IMAGE2, img2Rect);
1666                 __pItemFormat->SetElementEventEnabled(ID_FORMAT_IMAGE2, false);
1667         }
1668
1669         if (__listStyle == LIST_STYLE_NUMBER)
1670         {
1671                 __pItemFormat->AddElement(ID_FORMAT_NUMBER, Rectangle(listStyleNumberX, GetItemHeight()/2 - 15, listStyleNumberWidth, listStyleNumberHeight));
1672                 __pItemFormat->SetElementEventEnabled(ID_FORMAT_NUMBER, false);
1673         }
1674
1675         if (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL)
1676         {
1677                 __pItemFormat->AddElement(ID_FORMAT_CHECK, Rectangle(GetCore().GetBounds().width - 60, GetItemHeight()/2 - 25 , checkItemWidth , checkItemHeight));
1678                 __pItemFormat->SetElementEventEnabled(ID_FORMAT_CHECK, true);
1679         }
1680
1681         int count = GetItemCount();
1682         result r = E_SUCCESS;
1683
1684         for (int index = 0; index < count; index++)
1685         {
1686                 Refresh(index);
1687
1688                 r = GetCore().RefreshTableView(0, index, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1689                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM, "[%s] Propagating.",GetErrorMessage(r));
1690         }
1691
1692         ScrollToTop(currIndex);
1693         SetLastResult(E_SUCCESS);
1694
1695         return E_SUCCESS;
1696 }
1697
1698 void
1699 _ListImpl::SetBitmap(TableViewItemDrawingStatus itemStatus, const Bitmap& bitmap)
1700 {
1701         _TableViewItemData* pItem = null;
1702
1703         int groupIndex = -1;
1704         int topIndex = -1;
1705         int bottomIndex = -1;
1706
1707         GetTopDrawnItemIndex(groupIndex, topIndex);
1708         GetBottomDrawnItemIndex(groupIndex, bottomIndex);
1709
1710         int count = GetItemCount();
1711         for (int itemIndex = 0; itemIndex < count; itemIndex++)
1712         {
1713                 pItem = GetTableViewItemAt(-1, itemIndex);
1714                 SysTryReturnVoidResult(NID_UI_CTRL, pItem, E_SYSTEM,
1715                                 "[E_SYSTEM] A system error has occurred. _TableViewItemData instance is null.");
1716
1717                 pItem->SetBackgroundBitmap(&bitmap, itemStatus);
1718                 if (itemIndex >= topIndex && itemIndex <= bottomIndex)
1719                 {
1720                         pItem->Invalidate(true);
1721                 }
1722         }
1723 }
1724
1725 result
1726 _ListImpl::UpdateNumbers(int index)
1727 {
1728         SysTryReturnResult(NID_UI_CTRL, __listStyle == LIST_STYLE_NUMBER, E_SYSTEM,
1729                         "A system error has occurred. The current value of list style is invalid.");
1730
1731         SysTryReturnResult(NID_UI_CTRL, __pNumberElements != null, E_SYSTEM,
1732                         "A system error has occured. Failed to update numbers");
1733
1734         _NumberElement* pNumberElement = null;
1735         int count = __pNumberElements->GetCount();
1736
1737         for (int itemIndex = index + 1; itemIndex < count; itemIndex++)
1738         {
1739                 pNumberElement = dynamic_cast<_NumberElement*>(__pNumberElements->GetAt(itemIndex));
1740                 SysTryReturnResult(NID_UI_CTRL, pNumberElement, E_SYSTEM,
1741                                 "A system error has occurred. Failed to get _NumberElement instance at index(%d).", index);
1742                 pNumberElement->index = itemIndex + 1;
1743
1744                 CustomListItem* pCustomListItem = GetCustomListItemAt(-1, itemIndex);
1745                 SysTryReturnResult(NID_UI_CTRL, pCustomListItem, E_SYSTEM,
1746                                 "A system error has occurred. Failed to get an item at index(%d).", itemIndex);
1747
1748                 pCustomListItem->SetElement(ID_FORMAT_NUMBER, *(dynamic_cast<ICustomListElement*>(pNumberElement)));
1749         }
1750
1751         return E_SUCCESS;
1752 }
1753
1754 result
1755 _ListImpl::Refresh(int index)
1756 {
1757         result r = E_SUCCESS;
1758
1759         _TableViewItemUpdateParams updateParams;
1760         updateParams.pItem = GetCustomListItemAt(-1, index);
1761         updateParams.isDividerEnabled = _isDividerEnabled;
1762         updateParams.pCheckBitmaps = _pCheckBitmaps;
1763         updateParams.annexStyle = _annexStyle;
1764
1765         r = _CustomListItemImpl::UpdateTableViewItem(updateParams);
1766         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM,
1767                         "A system error has occurred. Failed to refresh an item.");
1768
1769         DrawItem(-1, index);
1770
1771         return E_SUCCESS;
1772 }
1773
1774 bool
1775 _ListImpl::IsItemChecked(int groupIndex, int subIndex) const
1776 {
1777         return IsItemChecked(subIndex);
1778 }
1779
1780 result
1781 _ListImpl::SetItemChecked(int groupIndex, int itemIndex, bool check)
1782 {
1783         return SetItemChecked(itemIndex, check);
1784 }
1785
1786 void
1787 _ListImpl::OnTableViewItemStateChanged(Tizen::Ui::Controls::_TableView& tableView, int itemIndex, Tizen::Ui::Controls::_TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
1788 {
1789         ItemStatus itemStatus = ITEM_HIGHLIGHTED;
1790
1791         switch (status)
1792         {
1793         case TABLE_VIEW_ITEM_STATUS_SELECTED:
1794                 itemStatus = ITEM_SELECTED;
1795                 break;
1796         case TABLE_VIEW_ITEM_STATUS_HIGHLIGHTED:
1797                 itemStatus = ITEM_HIGHLIGHTED;
1798                 break;
1799         case TABLE_VIEW_ITEM_STATUS_CHECKED:
1800                 itemStatus = ITEM_CHECKED;
1801                 break;
1802         case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
1803                 itemStatus = ITEM_UNCHECKED;
1804                 break;
1805         default:
1806                 SetLastResult(E_SYSTEM);
1807                 break;
1808         }
1809
1810         if ((!_isDividerEnabled) && (_annexStyle != TABLE_VIEW_ANNEX_STYLE_NORMAL))
1811         {
1812                 bool isChecked = IsItemChecked(itemIndex);
1813
1814                 if (isChecked)
1815                 {
1816                         itemStatus = ITEM_UNCHECKED;
1817                 }
1818                 else
1819                 {
1820                         itemStatus = ITEM_CHECKED;
1821                 }
1822
1823                 SetItemChecked(itemIndex, !isChecked);
1824         }
1825
1826         ProcessItemStateChange(-1, itemIndex, itemStatus);
1827
1828         return;
1829 }
1830
1831 void
1832 _ListImpl::OnTableViewItemReordered(Tizen::Ui::Controls::_TableView& tableView, int itemIndexFrom, int itemIndexTo)
1833 {
1834
1835 }
1836
1837 void
1838 _ListImpl::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::_TableView& tableView, int itemIndex, Tizen::Ui::Controls::_TableViewItem* pContextItem, bool activated)
1839 {
1840
1841 }
1842
1843 void
1844 _ListImpl::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::_TableView& tableView, int groupIndex, Tizen::Ui::Controls::_TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
1845 {
1846
1847 }
1848
1849 void
1850 _ListImpl::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::_TableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::_TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
1851 {
1852
1853 }
1854
1855 void
1856 _ListImpl::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::_TableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::_TableViewItem* pContextItem, bool activated)
1857 {
1858
1859 }
1860
1861 void
1862 _ListImpl::OnGroupedTableViewItemReordered(Tizen::Ui::Controls::_TableView& tableView, int groupIndexFrom, int itemIndexFrom, int groupIndexTo, int itemIndexTo)
1863 {
1864 }
1865
1866 void
1867 _ListImpl::OnSectionTableViewItemStateChanged(Tizen::Ui::Controls::_TableView& tableView, int sectionIndex, int itemIndex, Tizen::Ui::Controls::_TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
1868 {
1869
1870 }
1871
1872 void
1873 _ListImpl::OnTableViewItemSwept(Tizen::Ui::Controls::_TableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewSweepDirection direction)
1874 {
1875
1876 }
1877
1878 void
1879 _ListImpl::OnSectionTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::_TableView& tableView, int sectionIndex, int itemIndex, Tizen::Ui::Controls::_TableViewItem* pContextItem, bool activated)
1880 {
1881
1882 }
1883
1884 void
1885 _ListImpl::ProcessItemStateChange(int groupIndex, int itemIndex, ItemStatus itemStatus)
1886 {
1887         int itemId = GetItemIdAt(itemIndex);
1888
1889         _ListListener* pListenerList = null;
1890         IItemEventListener* pEventListener = null;
1891
1892         int count = __itemListeners.GetCount();
1893         for (int listenerCount = 0; listenerCount < count; listenerCount++)
1894         {
1895                 pListenerList = dynamic_cast<_ListListener*>(__itemListeners.GetAt(listenerCount));
1896                 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerList != null), E_SYSTEM,
1897                                 "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
1898
1899                 pEventListener = dynamic_cast<IItemEventListener*>(pListenerList->pListener);
1900                 SysTryReturnVoidResult(NID_UI_CTRL, (pEventListener != null), E_SYSTEM,
1901                                 "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
1902
1903                 pEventListener->OnItemStateChanged(GetPublic(), itemIndex, itemId, itemStatus);
1904         }
1905         SetLastResult(E_SUCCESS);
1906
1907         return;
1908 }
1909
1910 void
1911 _ListImpl::ProcessItemStateChange(int groupIndex, int itemIndex, int elementId, ItemStatus itemStatus)
1912 {
1913         int itemId = GetItemIdAt(itemIndex);
1914
1915         _ListListener* pListenerList = null;
1916         IItemEventListener* pEventListener = null;
1917
1918         int count = __itemListeners.GetCount();
1919         for (int listenerCount = 0; listenerCount < count; listenerCount++)
1920         {
1921                 pListenerList = dynamic_cast<_ListListener*>(__itemListeners.GetAt(listenerCount));
1922                 SysTryReturnVoidResult(NID_UI_CTRL, (pListenerList != null), E_SYSTEM,
1923                                 "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
1924
1925                 pEventListener = dynamic_cast<IItemEventListener*>(pListenerList->pListener);
1926                 SysTryReturnVoidResult(NID_UI_CTRL, (pEventListener != null), E_SYSTEM,
1927                                 "[E_SYSTEM] A system error has occurred. Failed to get Listener.");
1928
1929                 pEventListener->OnItemStateChanged(GetPublic(), itemIndex, itemId, itemStatus);
1930         }
1931         SetLastResult(E_SUCCESS);
1932
1933         return;
1934 }
1935
1936
1937
1938 class _ListMaker
1939         : public _UiBuilderControlMaker
1940 {
1941 public:
1942         _ListMaker(_UiBuilder* uibuilder)
1943                 : _UiBuilderControlMaker(uibuilder){};
1944         virtual ~_ListMaker(){};
1945         static _UiBuilderControlMaker*
1946         GetInstance(_UiBuilder* uibuilder)
1947         {
1948                 _ListMaker* pListMaker = new (std::nothrow) _ListMaker(uibuilder);
1949                 return pListMaker;
1950         };
1951 protected:
1952         virtual Control*
1953         Make(_UiBuilderControl* pControl)
1954         {
1955                 result r = E_SYSTEM;
1956                 _UiBuilderControlLayout* pControlProperty = null;
1957                 List* pList = null;
1958                 Rectangle rect;
1959                 Rectangle rectMin;
1960                 Dimension dimMin;
1961                 Tizen::Base::String elementString;
1962                 int tempRow1Height = 0;
1963                 int tempRow2Height = 0;
1964                 int tempColumn1Width = 0;
1965                 int tempColumn2Width = 0;
1966
1967                 ListStyle style = LIST_STYLE_NORMAL;
1968                 ListItemFormat format = LIST_ITEM_SINGLE_TEXT;
1969                 Color color;
1970
1971                 GetProperty(pControl, &pControlProperty);
1972                 if (pControlProperty == null)
1973                 {
1974                         return null;
1975                 }
1976
1977                 pList = new (std::nothrow) List();
1978                 if (pList == null)
1979                 {
1980                         return null;
1981                 }
1982
1983                 rect = pControlProperty->GetRect();
1984
1985                 if (pControl->GetElement(L"ListItemFormat", elementString))
1986                 {
1987                         if (elementString.Equals(L"LIST_ITEM_SINGLE_IMAGE", false))
1988                         {
1989                                 format = LIST_ITEM_SINGLE_IMAGE;
1990                         }
1991                         else if (elementString.Equals(L"LIST_ITEM_SINGLE_TEXT", false))
1992                         {
1993                                 format = LIST_ITEM_SINGLE_TEXT;
1994                         }
1995                         else if (elementString.Equals(L"LIST_ITEM_SINGLE_IMAGE_TEXT", false))
1996                         {
1997                                 format = LIST_ITEM_SINGLE_IMAGE_TEXT;
1998                         }
1999                         else if (elementString.Equals(L"LIST_ITEM_SINGLE_TEXT_IMAGE", false))
2000                         {
2001                                 format = LIST_ITEM_SINGLE_TEXT_IMAGE;
2002                         }
2003                         else if (elementString.Equals(L"LIST_ITEM_SINGLE_IMAGE_TEXT_IMAGE", false))
2004                         {
2005                                 format = LIST_ITEM_SINGLE_IMAGE_TEXT_IMAGE;
2006                         }
2007                         else if (elementString.Equals(L"LIST_ITEM_DOUBLE_IMAGE_TEXT_FULLTEXT", false))
2008                         {
2009                                 format = LIST_ITEM_DOUBLE_IMAGE_TEXT_FULLTEXT;
2010                         }
2011                         else if (elementString.Equals(L"LIST_ITEM_DOUBLE_FULLTEXT_IMAGE_TEXT", false))
2012                         {
2013                                 format = LIST_ITEM_DOUBLE_FULLTEXT_IMAGE_TEXT;
2014                         }
2015                         else if (elementString.Equals(L"LIST_ITEM_DOUBLE_TEXT_IMAGE_FULLTEXT", false))
2016                         {
2017                                 format = LIST_ITEM_DOUBLE_TEXT_IMAGE_FULLTEXT;
2018                         }
2019                         else if (elementString.Equals(L"LIST_ITEM_DOUBLE_FULLTEXT_TEXT_IMAGE", false))
2020                         {
2021                                 format = LIST_ITEM_DOUBLE_FULLTEXT_TEXT_IMAGE;
2022                         }
2023                         else if (elementString.Equals(L"LIST_ITEM_DOUBLE_IMAGE_TEXT_TEXT", false))
2024                         {
2025                                 format = LIST_ITEM_DOUBLE_IMAGE_TEXT_TEXT;
2026                         }
2027                         else if (elementString.Equals(L"LIST_ITEM_DOUBLE_TEXT_TEXT_IMAGE", false))
2028                         {
2029                                 format = LIST_ITEM_DOUBLE_TEXT_TEXT_IMAGE;
2030                         }
2031                         else
2032                         {
2033                                 format = LIST_ITEM_SINGLE_TEXT;
2034                         }
2035                 }
2036
2037                 if (pControl->GetElement(L"line1Height", elementString) || pControl->GetElement(L"row1Height", elementString))
2038                 {
2039                         Base::Integer::Parse(elementString, tempRow1Height);
2040                 }
2041
2042                 if ((pControl->GetElement(L"line2Height", elementString) || pControl->GetElement(L"row2Height", elementString)) && (format > 4))
2043                 {
2044                         Base::Integer::Parse(elementString,tempRow2Height);
2045                 }
2046                 else
2047                 {
2048                         tempRow2Height = 0;
2049                 }
2050
2051                 if (pControl->GetElement(L"column1Width", elementString))
2052                 {
2053                         Base::Integer::Parse(elementString,tempColumn1Width);
2054                 }
2055
2056                 if ((pControl->GetElement(L"column2Width", elementString)) && (format > 1))
2057                 {
2058                         Base::Integer::Parse(elementString,tempColumn2Width);
2059                 }
2060                 else
2061                 {
2062                         tempColumn2Width = 0;
2063                 }
2064
2065                 Tizen::Base::String styleString;
2066                 styleString = pControlProperty->GetStyle();
2067
2068                 if (styleString.Equals(L"LIST_STYLE_NORMAL", false))
2069                 {
2070                         style = LIST_STYLE_NORMAL;
2071                 }
2072                 else if (styleString.Equals(L"LIST_STYLE_NUMBER", false))
2073                 {
2074                         style = LIST_STYLE_NUMBER;
2075                 }
2076                 else if (styleString.Equals(L"LIST_STYLE_RADIO", false))
2077                 {
2078                         style = LIST_STYLE_RADIO;
2079                 }
2080                 else if (styleString.Equals(L"LIST_STYLE_RADIO_WITH_DIVIDER", false))
2081                 {
2082                         style = LIST_STYLE_RADIO_WITH_DIVIDER;
2083                 }
2084                 else if (styleString.Equals(L"LIST_STYLE_MARK_WITH_DIVIDER", false))
2085                 {
2086                         style = LIST_STYLE_MARK_WITH_DIVIDER;
2087                 }
2088                 else if (styleString.Equals(L"LIST_STYLE_ONOFF_WITH_DIVIDER", false))
2089                 {
2090                         style = LIST_STYLE_ONOFF_WITH_DIVIDER;
2091                 }
2092                 else if (styleString.Equals(L"LIST_STYLE_MARK", false))
2093                 {
2094                         style = LIST_STYLE_MARK;
2095                 }
2096                 else if (styleString.Equals(L"LIST_STYLE_ONOFF", false))
2097                 {
2098                         style = LIST_STYLE_ONOFF;
2099                 }
2100                 else
2101                 {
2102                         style = LIST_STYLE_NORMAL;
2103                 }
2104
2105                 if (tempRow1Height < 0 || tempRow1Height > ((Tizen::Ui::Control*) GetContainer())->GetBounds().height)
2106                 {
2107                         tempRow1Height = ((Tizen::Ui::Control*) GetContainer())->GetBounds().height >> 2;
2108                 }
2109                 if (tempRow2Height < 0 || tempRow2Height > ((Tizen::Ui::Control*) GetContainer())->GetBounds().height)
2110                 {
2111                         tempRow2Height = ((Tizen::Ui::Control*) GetContainer())->GetBounds().height >> 2;
2112                 }
2113                 if (tempColumn1Width < 0 || tempColumn1Width > ((Tizen::Ui::Control*) GetContainer())->GetBounds().width)
2114                 {
2115                         tempColumn1Width = ((Tizen::Ui::Control*) GetContainer())->GetBounds().width >> 2;
2116                 }
2117                 if (tempColumn2Width < 0 || tempColumn2Width > ((Tizen::Ui::Control*) GetContainer())->GetBounds().width)
2118                 {
2119                         tempColumn2Width = ((Tizen::Ui::Control*) GetContainer())->GetBounds().width >> 2;
2120                 }
2121
2122                 r = pList->Construct(rect, style, format, tempRow1Height, tempRow2Height, tempColumn1Width, tempColumn2Width);
2123                 if (r != E_SUCCESS)
2124                 {
2125                         delete pList;
2126                         return null;
2127                 }
2128
2129                 if (pControl->GetElement(L"textOfEmptyList", elementString))
2130                 {
2131                         pList->SetTextOfEmptyList(elementString);
2132                 }
2133
2134                 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
2135                 {
2136                         ConvertStringToColor(elementString, color);
2137                         pList->SetTextColorOfEmptyList(color);
2138                 }
2139
2140                 GET_DIMENSION_CONFIG(LIST::LIST_MIN_SIZE, _CONTROL_ORIENTATION_PORTRAIT, dimMin);
2141                 rectMin = (pControl->GetAttribute(0))->GetRect();
2142                 (pControl->GetAttribute(0))->SetRect(rectMin.x, rectMin.y, dimMin.width, dimMin.height);
2143
2144                 GET_DIMENSION_CONFIG(LIST::LIST_MIN_SIZE, _CONTROL_ORIENTATION_LANDSCAPE, dimMin);
2145                 rectMin = (pControl->GetAttribute(1))->GetRect();
2146                 (pControl->GetAttribute(1))->SetRect(rectMin.x, rectMin.y, dimMin.width, dimMin.height);
2147
2148                 return pList;
2149         }
2150
2151 private:
2152 };
2153
2154 _ListRegister::_ListRegister()
2155 {
2156         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
2157         if (pUiBuilderControlTableManager)
2158         {
2159                 pUiBuilderControlTableManager->RegisterControl(L"List", _ListMaker::GetInstance);
2160         }
2161 }
2162 _ListRegister::~_ListRegister()
2163 {
2164         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
2165         if (pUiBuilderControlTableManager)
2166         {
2167                 pUiBuilderControlTableManager->UnregisterControl(L"List");
2168         }
2169 }
2170
2171 static _ListRegister ListRegisterToUiBuilder;
2172 }}} // Tizen::Ui::Controls