Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_ListViewImpl.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_ListViewImpl.cpp
20  * @brief   This is the implementation file for _ListViewImpl class.
21  *
22  * This file contains the implementation of _ListViewImpl class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FGrp_TextTextSimple.h>
27 #include "FApp_AppInfo.h"
28 #include "FUi_ResourceManager.h"
29 #include "FUi_TouchManager.h"
30 #include "FUi_UiBuilder.h"
31 #include "FUiCtrl_FastScrollEvent.h"
32 #include "FUiCtrl_FastScrollEventArg.h"
33 #include "FUiCtrl_Label.h"
34 #include "FUiCtrl_ListItemEvent.h"
35 #include "FUiCtrl_ListItemEventArg.h"
36 #include "FUiCtrl_ListViewImpl.h"
37 #include "FUiCtrl_ListViewItem.h"
38 #include "FUiCtrl_ListViewItemProviderAdaptor.h"
39 #include "FUiCtrl_PublicLinkEvent.h"
40 #include "FUiCtrl_ScrollEvent.h"
41 #include "FUiCtrl_ScrollEventArg.h"
42
43 #ifdef MEMORY_LEAK_CHECK
44 #include "mem_leak_check.h"
45 #endif
46
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Collection;
49 using namespace Tizen::Base::Runtime;
50 using namespace Tizen::Graphics;
51 using namespace Tizen::Graphics::_Text;
52
53 namespace Tizen { namespace Ui { namespace Controls
54 {
55
56 _ListViewImpl*
57 _ListViewImpl::GetInstance(ListView& listView)
58 {
59         return static_cast<_ListViewImpl*>(listView._pControlImpl);
60 }
61
62 const _ListViewImpl*
63 _ListViewImpl::GetInstance(const ListView& listView)
64 {
65         return static_cast<const _ListViewImpl*>(listView._pControlImpl);
66 }
67
68 _ListViewImpl::_ListViewImpl(ListView* pList, _TableView* pCore)
69         : _ControlImpl(pList, pCore)
70         , __pListItemEvent(null)
71         , __pLinkEvent(null)
72         , __pScrollEvent(null)
73         , __pFastScrollEvent(null)
74         , __pEmptyBitmap(null)
75         , __pEmptyText(null)
76         , __redrawListView(true)
77         , __pItemNeedsLazyDeletion(null)
78         , __pItemSwept(null)
79 {
80         GET_COLOR_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_NORMAL, __emptyTextColor);
81 }
82
83 _ListViewImpl::~_ListViewImpl()
84 {
85         if (__pListItemEvent != null)
86         {
87                 //__pListItemEvent->RemoveListener(*this);
88
89                 delete __pListItemEvent;
90                 __pListItemEvent = null;
91         }
92
93         if (__pLinkEvent != null)
94         {
95                 //__pLinkEvent->RemoveListener(*this);
96
97                 delete __pLinkEvent;
98                 __pLinkEvent = null;
99         }
100
101         if (__pScrollEvent != null)
102         {
103                 //__pScrollEvent->RemoveListener(*this);
104
105                 delete __pScrollEvent;
106                 __pScrollEvent = null;
107         }
108
109         if (__pFastScrollEvent != null)
110         {
111                 //__pFastScrollEvent->RemoveListener(*this);
112
113                 delete __pFastScrollEvent;
114                 __pFastScrollEvent = null;
115         }
116
117         if (__pEmptyBitmap != null)
118         {
119                 GetCore().DetachChild(*__pEmptyBitmap);
120
121                 delete __pEmptyBitmap;
122                 __pEmptyBitmap = null;
123         }
124
125         if (__pEmptyText != null)
126         {
127                 GetCore().DetachChild(*__pEmptyText);
128
129                 delete __pEmptyText;
130                 __pEmptyText = null;
131         }
132 }
133
134 const char*
135 _ListViewImpl::GetPublicClassName(void) const
136 {
137         return "Controls::ListView";
138 }
139
140 const ListView&
141 _ListViewImpl::GetPublic(void) const
142 {
143         return static_cast <const ListView&>(_ControlImpl::GetPublic());
144 }
145
146 ListView&
147 _ListViewImpl::GetPublic(void)
148 {
149         return static_cast <ListView&>(_ControlImpl::GetPublic());
150 }
151
152 const _TableView&
153 _ListViewImpl::GetCore(void) const
154 {
155         return static_cast <const _TableView&>(_ControlImpl::GetCore());
156 }
157
158 _TableView&
159 _ListViewImpl::GetCore(void)
160 {
161         return static_cast <_TableView&>(_ControlImpl::GetCore());
162 }
163
164 _ListViewImpl*
165 _ListViewImpl::CreateListViewImplN(ListView* pControl, bool itemDivider, ListScrollStyle scrollStyle)
166 {
167         result r = E_SUCCESS;
168         TableViewScrollBarStyle scrollBarStyle;
169
170         switch (scrollStyle)
171         {
172         case SCROLL_STYLE_FADE_OUT:
173                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT;
174                 break;
175         case SCROLL_STYLE_FIXED:
176                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FIXED;
177                 break;
178         case SCROLL_STYLE_FAST_SCROLL:
179                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL;
180                 break;
181         case SCROLL_STYLE_JUMP_TO_TOP:
182                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_JUMP_TO_TOP;
183                 break;
184         case SCROLL_STYLE_THUMB:
185                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_THUMB;
186                 break;
187         default:
188                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_NONE;
189                 break;
190         }
191
192         _TableView* pCore = _TableView::CreateTableViewN(TABLE_VIEW_STYLE_SIMPLE, itemDivider, scrollBarStyle);
193
194         SysTryReturn(NID_UI_CTRL, (pCore != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
195
196         _ListViewImpl* pImpl = new (std::nothrow) _ListViewImpl(pControl, pCore);
197
198         r = CheckConstruction(pCore, pImpl);
199         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), null, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
200
201         return pImpl;
202 }
203
204 result
205 _ListViewImpl::SetItemProvider(IListViewItemProvider& provider)
206 {
207         result r = E_SUCCESS;
208
209         _ListViewItemProviderAdaptor* pProviderAdaptor =
210                         static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
211
212         if (pProviderAdaptor == null)
213         {
214                 pProviderAdaptor = new (std::nothrow) _ListViewItemProviderAdaptor(provider);
215                 SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
216                                         "[E_OUT_OF_MEMORY] The memory is insufficient.");
217
218                 pProviderAdaptor->SetListViewItemEventListener(*this);
219
220                 r = pProviderAdaptor->SetListWidth(GetCore().GetBounds().width);
221                 GetCore().SetItemProviderAdaptor(pProviderAdaptor);
222         }
223         else
224         {
225                 pProviderAdaptor->SetItemProvider(provider);
226                 r = pProviderAdaptor->SetListWidth(GetCore().GetBounds().width);
227
228                 UpdateList();
229         }
230
231         __redrawListView = true;
232
233         SetLastResultReturn(r);
234 }
235
236 void
237 _ListViewImpl::AddListViewItemEventListener(IListViewItemEventListener& listener)
238 {
239         result r = E_SUCCESS;
240
241         if (__pListItemEvent == null)
242         {
243                 __pListItemEvent = new (std::nothrow) _ListItemEvent();
244                 SysTryReturnVoidResult(NID_UI_CTRL, (__pListItemEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
245
246                 r = __pListItemEvent->Construct(GetPublic(), CLASSNAME_LISTVIEW);
247                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Item Event.");
248         }
249
250         __pListItemEvent->AddListener(listener);
251
252         r = GetCore().AddTableViewItemEventListener(*this);
253
254         SetLastResult(r);
255 }
256
257 void
258 _ListViewImpl::RemoveListViewItemEventListener(IListViewItemEventListener& listener)
259 {
260         result r = E_SUCCESS;
261
262         if (__pListItemEvent != null)
263         {
264                 r = __pListItemEvent->RemoveListener(listener);
265         }
266
267         SetLastResult(r);
268 }
269
270 void
271 _ListViewImpl::AddFastScrollListener(IFastScrollListener& listener)
272 {
273         result r = E_SUCCESS;
274
275         if (__pFastScrollEvent == null)
276         {
277                 __pFastScrollEvent = new (std::nothrow) _FastScrollEvent();
278                 SysTryReturnVoidResult(NID_UI_CTRL, (__pFastScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
279
280                 r = __pFastScrollEvent->Construct(GetPublic());
281                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct FastScroll Event.");
282         }
283
284         __pFastScrollEvent->AddListener(listener);
285
286         r = GetCore().AddFastScrollListener(*this);
287
288         SetLastResult(r);
289 }
290
291 void
292 _ListViewImpl::RemoveFastScrollListener(IFastScrollListener& listener)
293 {
294         result r = E_SUCCESS;
295
296         if (__pFastScrollEvent != null)
297         {
298                 r = __pFastScrollEvent->RemoveListener(listener);
299         }
300
301         SetLastResult(r);
302 }
303
304 void
305 _ListViewImpl::AddScrollEventListener(IScrollEventListener& listener)
306 {
307         result r = E_SUCCESS;
308
309         if (__pScrollEvent == null)
310         {
311                 __pScrollEvent = new (std::nothrow) _ScrollEvent();
312                 SysTryReturnVoidResult(NID_UI_CTRL, (__pScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
313
314                 r = __pScrollEvent->Construct(GetPublic());
315                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Scroll Event.");
316         }
317
318         __pScrollEvent->AddListener(listener);
319
320         GetCore().AddScrollEventListener(*this);
321
322         SetLastResult(r);
323 }
324
325 void
326 _ListViewImpl::RemoveScrollEventListener(IScrollEventListener& listener)
327 {
328         result r = E_SUCCESS;
329
330         if (__pScrollEvent != null)
331         {
332                 r = __pScrollEvent->RemoveListener(listener);
333         }
334
335         SetLastResult(r);
336 }
337
338 void
339 _ListViewImpl::AddUiLinkEventListener(const IUiLinkEventListener& listener)
340 {
341         result r = E_SUCCESS;
342
343         if (__pLinkEvent == null)
344         {
345                 __pLinkEvent = _PublicLinkEvent::CreateInstanceN(GetPublic());
346                 SysTryReturnVoidResult(NID_UI_CTRL, (__pLinkEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
347         }
348
349         r = __pLinkEvent->AddListener(listener);
350
351         SetLastResult(r);
352 }
353
354
355 void
356 _ListViewImpl::RemoveUiLinkEventListener(const IUiLinkEventListener& listener)
357 {
358         result r = E_SUCCESS;
359
360         if (__pLinkEvent != null)
361         {
362                 r = __pLinkEvent->RemoveListener(listener);
363         }
364
365         SetLastResult(r);
366 }
367
368 result
369 _ListViewImpl::SetSweepEnabled(bool enable)
370 {
371         GetCore().SetSweepEnabled(enable);
372
373         SetLastResultReturn(E_SUCCESS);
374 }
375
376 result
377 _ListViewImpl::SetFastScrollIndex(const String& text, bool useSearchIcon)
378 {
379         result r = GetCore().SetFastScrollIndex(text, useSearchIcon);
380         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS) || (r == E_SYSTEM), E_INVALID_STATE, E_INVALID_STATE,
381                         "[E_INVALID_STATE] This instance is in an invalid state.");
382
383         SetLastResultReturn(r);
384 }
385
386 int
387 _ListViewImpl::GetTopDrawnItemIndex(void) const
388 {
389         int groupIndex = -1;
390         int itemIndex = -1;
391
392         GetCore().GetTopDrawnItemIndex(groupIndex, itemIndex);
393
394         return itemIndex;
395 }
396
397 int
398 _ListViewImpl::GetBottomDrawnItemIndex(void) const
399 {
400         int groupIndex = -1;
401         int itemIndex = -1;
402
403         GetCore().GetBottomDrawnItemIndex(groupIndex, itemIndex);
404
405         return itemIndex;
406 }
407
408 result
409 _ListViewImpl::ScrollToItem(int index, ListScrollItemAlignment itemAlignment)
410 {
411         result r = E_SUCCESS;
412
413         if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_TOP)
414         {
415                 r = GetCore().SetTopDrawnItemIndex(0, index);
416         }
417         else if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_BOTTOM)
418         {
419                 r = GetCore().SetBottomDrawnItemIndex(0, index);
420         }
421         else
422         {
423                 SysTryReturn(NID_UI_CTRL, false, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
424                                          "[E_OUT_OF_RANGE] The specified itemAlignment is out of range.");
425         }
426
427         SetLastResultReturn(r);
428 }
429
430 result
431 _ListViewImpl::SetItemChecked(int index, bool check)
432 {
433         return GetCore().SetItemChecked(0, index, check);
434 }
435
436 bool
437 _ListViewImpl::IsItemChecked(int index) const
438 {
439         return GetCore().IsItemChecked(0, index);
440 }
441
442 result
443 _ListViewImpl::SetItemEnabled(int index, bool enable)
444 {
445         return GetCore().SetItemEnabled(0, index, enable);
446 }
447
448 bool
449 _ListViewImpl::IsItemEnabled(int index) const
450 {
451         return GetCore().IsItemEnabled(0, index);
452 }
453
454 int
455 _ListViewImpl::GetItemCount(void) const
456 {
457         return GetCore().GetItemCountAt(0);
458 }
459
460 result
461 _ListViewImpl::ShowItemDescriptionText(int index)
462 {
463         return SetItemDescriptionTextShowState(index, true);
464 }
465
466 result
467 _ListViewImpl::HideItemDescriptionText(int index)
468 {
469         return SetItemDescriptionTextShowState(index, false);
470 }
471
472 result
473 _ListViewImpl::SetItemDescriptionTextShowState(int index, bool show)
474 {
475         result r = E_SUCCESS;
476
477         SysTryReturn(NID_UI_CTRL, (index >= 0) && (index < GetItemCount()), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
478                         "[E_OUT_OF_RANGE] The specified index is out of range.");
479
480         _ListViewItemProviderAdaptor* pProviderAdaptor =
481                         static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
482         SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] _ListItemProviderAdaptor is not set.");
483
484         // Save description text show state to provider adaptor
485         pProviderAdaptor->SetDescriptionTextShowState(index, show);
486
487         if (GetCore().FindItem(0, index) != null)
488         {
489                 r = GetCore().RefreshTableView(0, index, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
490         }
491
492         SetLastResultReturn(r);
493 }
494
495 result
496 _ListViewImpl::RefreshList(int index, ListRefreshType type)
497 {
498         result r = E_SUCCESS;
499
500         int itemCount = GetCore().GetItemCountAt(0);
501
502         if ((index < 0) || (index > itemCount) ||
503                 ((type != LIST_REFRESH_TYPE_ITEM_ADD) && (index == itemCount)))
504         {
505                 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
506                 return E_OUT_OF_RANGE;
507         }
508
509         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, index));
510
511         // for lazy delete item
512         if ((__pItemNeedsLazyDeletion != null) && (type != LIST_REFRESH_TYPE_ITEM_ADD))
513         {
514                 if (__pItemNeedsLazyDeletion == pListViewItem)
515                 {
516                         _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
517
518                         if (pProviderAdaptor != null)
519                         {
520                                 pProviderAdaptor->SetItemNeedsLazyDeletion(__pItemNeedsLazyDeletion);
521                         }
522                 }
523         }
524
525         if ((__pItemSwept != null) && (type != LIST_REFRESH_TYPE_ITEM_ADD))
526         {
527                 if (__pItemSwept == pListViewItem)
528                 {
529                         GetCore().ResetSweepItem();
530                 }
531         }
532
533         if (type == LIST_REFRESH_TYPE_ITEM_MODIFY)
534         {
535                 int topGroupIndex = -1;
536                 int topItemIndex = -1;
537                 int bottomGroupIndex = -1;
538                 int bottomItemIndex = -1;
539
540                 GetCore().GetFirstLoadedItemIndex(topGroupIndex, topItemIndex);
541                 GetCore().GetLastLoadedItemIndex(bottomGroupIndex, bottomItemIndex);
542
543                 if ((topItemIndex <= index) && (bottomItemIndex >= index))
544                 {
545                         TableViewItemDrawingStatus itemDrawingStatus = TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL;
546                         bool itemSelected = false;
547                         Point touchPosition(-1, -1);
548
549                         if (pListViewItem != null)
550                         {
551                                 itemDrawingStatus = pListViewItem->GetDrawingStatus();
552                                 itemSelected = pListViewItem->GetSelectionState();
553                                 touchPosition = pListViewItem->GetLastTouchPressedPosition();
554
555                                 pListViewItem = null;
556                         }
557
558                         GetCore().UnloadItem(0, index);
559                         GetCore().LoadItem(0, index);
560
561                         pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, index));
562
563                         if ((pListViewItem != null) && (itemDrawingStatus != TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL))
564                         {
565                                 pListViewItem->SetDrawingStatus(itemDrawingStatus);
566                                 pListViewItem->SetSelectionState(itemSelected);
567                                 pListViewItem->SetLastTouchPressedPosition(touchPosition);
568
569                                 // for create Annex
570                                 pListViewItem->Draw();
571                                 pListViewItem->Show();
572
573                                 _Control* target = static_cast<_Control*>(pListViewItem);
574
575                                 for (int i = 0; i < pListViewItem->GetChildCount(); i++)
576                                 {
577                                         if (pListViewItem->GetChild(i)->GetBounds().Contains(touchPosition))
578                                         {
579                                                 target = pListViewItem->GetChild(i);
580                                         }
581                                 }
582
583                                 if (target != null)
584                                 {
585                                         target->SetChangingEventTarget(true);
586                                 }
587                                 else
588                                 {
589                                         pListViewItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
590                                         pListViewItem->SetSelectionState(false);
591                                 }
592                         }
593                 }
594                 else
595                 {
596                         // not yet loaded item
597                         SetLastResultReturn(r);
598                 }
599         }
600         else
601         {
602                 r = GetCore().RefreshTableView(0, index, static_cast<TableViewRefreshType>(type));
603         }
604
605         CheckEmptyListShowState();
606
607         Draw();
608         Show();
609
610         SetLastResultReturn(r);
611 }
612
613 result
614 _ListViewImpl::RefreshList(int index, int elementId)
615 {
616         if ((index < 0) || (index >= GetCore().GetItemCountAt(0)))
617         {
618                 return E_OUT_OF_RANGE;
619         }
620
621         result r = E_SUCCESS;
622         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, index));
623
624         if (pListViewItem != null)
625         {
626                 r = (pListViewItem->RefreshElement(elementId)) ? E_SUCCESS : E_OUT_OF_RANGE;
627         }
628
629         SetLastResultReturn(r);
630 }
631
632 result
633 _ListViewImpl::UpdateList(void)
634 {
635         // for lazy delete item
636         if (__pItemNeedsLazyDeletion != null)
637         {
638                 _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
639
640                 if (pProviderAdaptor != null)
641                 {
642                         pProviderAdaptor->SetItemNeedsLazyDeletion(__pItemNeedsLazyDeletion);
643                 }
644         }
645
646         result r = GetCore().UpdateTableView();
647
648         CheckEmptyListShowState();
649
650         Invalidate(true);
651
652         // API versioning for initial Show() operation
653         if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
654         {
655                 Show();
656         }
657
658         SetLastResultReturn(r);
659 }
660
661 int
662 _ListViewImpl::GetItemIndexFromPosition(const Point& position) const
663 {
664         int groupIndex = -1;
665         int itemIndex = -1;
666
667         GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
668
669         return itemIndex;
670 }
671
672 result
673 _ListViewImpl::GetItemIndexFromPosition(const Point& position, int& itemIndex, int& elementId) const
674 {
675         int groupIndex = -1;
676         elementId = -1;
677
678         result r =  GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
679         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] There is no item at the specified position.");
680
681         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
682
683         if (pListViewItem != null)
684         {
685                 Point originPosition = pListViewItem->GetPosition();
686                 originPosition.y -= GetCore().GetScrollPosition();
687
688                 elementId = pListViewItem->GetElementIdFromPosition(Point(position.x - originPosition.x, position.y - originPosition.y));
689         }
690
691         SetLastResultReturn(r);
692 }
693
694 result
695 _ListViewImpl::SetItemDividerColor(const Color& color)
696 {
697         return GetCore().SetItemDividerColor(color);
698 }
699
700 Color
701 _ListViewImpl::GetItemDividerColor(void) const
702 {
703         return GetCore().GetItemDividerColor();
704 }
705
706 void
707 _ListViewImpl::AdjustLayoutOfEmptyList(void)
708 {
709         Dimension listDimension = GetCore().GetSize();
710         Dimension emptyBitmap;
711         Dimension emptyText;
712         Point bitmapPos;
713         Point textPos;
714         int totalHeight = 0;
715
716         if (__pEmptyBitmap != null)
717         {
718                 emptyBitmap = __pEmptyBitmap->GetSize();
719         }
720         if (__pEmptyText != null)
721         {
722                 emptyText = __pEmptyText->GetSize();
723         }
724
725         totalHeight = emptyBitmap.height + emptyText.height;
726
727         if ((__pEmptyBitmap != null) && (__pEmptyText != null) && (totalHeight < listDimension.height))
728         {
729                 bitmapPos.x = ((listDimension.width == emptyBitmap.width) ? 0 : (listDimension.width - emptyBitmap.width) / 2);
730                 bitmapPos.y = (listDimension.height - totalHeight) / 2;
731
732                 textPos.x = ((listDimension.width == emptyText.width) ? 0 : (listDimension.width - emptyText.width) / 2);
733                 textPos.y = bitmapPos.y + emptyBitmap.height;
734         }
735         else
736         {
737                 if (__pEmptyBitmap != null)
738                 {
739                         bitmapPos.x = ((listDimension.width == emptyBitmap.width) ? 0 : (listDimension.width - emptyBitmap.width) / 2);
740                         bitmapPos.y = ((listDimension.height == emptyBitmap.height) ? 0 : (listDimension.height - emptyBitmap.height) / 2);
741                 }
742
743                 if (__pEmptyText != null)
744                 {
745                         textPos.x = ((listDimension.width == emptyText.width) ? 0 : (listDimension.width - emptyText.width) / 2);
746                         textPos.y = ((listDimension.height == emptyText.height) ? 0 : (listDimension.height - emptyText.height) / 2);
747                 }
748         }
749
750         if (__pEmptyBitmap != null)
751         {
752                 __pEmptyBitmap->SetPosition(bitmapPos);
753         }
754         if (__pEmptyText != null)
755         {
756                 __pEmptyText->SetPosition(textPos);
757         }
758
759         CheckEmptyListShowState();
760 }
761
762 void
763 _ListViewImpl::CheckEmptyListShowState(void)
764 {
765         bool isEmpty = (GetItemCount() <= 0);
766
767         if (__pEmptyBitmap != null)
768         {
769                 __pEmptyBitmap->SetVisibleState(isEmpty);
770         }
771         if (__pEmptyText != null)
772         {
773                 __pEmptyText->SetVisibleState(isEmpty);
774         }
775 }
776
777 result
778 _ListViewImpl::SetBitmapOfEmptyList(const Bitmap* pBitmap)
779 {
780         if (pBitmap == null)
781         {
782                 if (__pEmptyBitmap != null)
783                 {
784                         GetCore().DetachChild(*__pEmptyBitmap);
785
786                         delete __pEmptyBitmap;
787                         __pEmptyBitmap = null;
788                 }
789         }
790         else
791         {
792                 if (__pEmptyBitmap == null)
793                 {
794                         __pEmptyBitmap = _Label::CreateLabelN();
795                         SysTryReturn(NID_UI_CTRL, (__pEmptyBitmap != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
796
797                         __pEmptyBitmap->SetVisibleState(false);
798                         __pEmptyBitmap->SetMargin(0, 0);
799
800                         GetCore().AttachChild(*__pEmptyBitmap);
801                 }
802
803                 Dimension bitmapSize(pBitmap->GetWidth(), pBitmap->GetHeight());
804                 Dimension listDimension = GetCore().GetSize();
805                 Dimension labelDimension;
806
807                 labelDimension.width = ((listDimension.width < bitmapSize.width) ? listDimension.width : bitmapSize.width);
808                 labelDimension.height = ((listDimension.height < bitmapSize.height) ? listDimension.height : bitmapSize.height);
809
810                 __pEmptyBitmap->SetSize(labelDimension);
811                 __pEmptyBitmap->SetBackgroundColor(Color(0, 0, 0, 0));
812                 __pEmptyBitmap->SetBackgroundBitmap(*pBitmap);
813         }
814
815         AdjustLayoutOfEmptyList();
816
817         SetLastResultReturn(E_SUCCESS);
818 }
819
820 result
821 _ListViewImpl::SetTextOfEmptyList(const String& text)
822 {
823         if (text.IsEmpty())
824         {
825                 if (__pEmptyText != null)
826                 {
827                         GetCore().DetachChild(*__pEmptyText);
828
829                         delete __pEmptyText;
830                         __pEmptyText = null;
831                 }
832         }
833         else
834         {
835                 if (__pEmptyText == null)
836                 {
837                         __pEmptyText = _Label::CreateLabelN();
838                         SysTryReturn(NID_UI_CTRL, (__pEmptyText != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
839
840                         __pEmptyText->SetVisibleState(false);
841                         __pEmptyText->SetMargin(0, 0);
842
843                         GetCore().AttachChild(*__pEmptyText);
844                 }
845
846                 TextObject* pText = new (std::nothrow) TextObject;
847                 SysTryReturn(NID_UI_CTRL, (pText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
848
849                 pText->Construct();
850
851                 TextSimple* pSimpleText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(text.GetPointer()), text.GetLength());
852                 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
853
854                 pText->AppendElement(*pSimpleText);
855
856                 int textSize = 0;
857                 GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, textSize);
858
859                 Font font;
860                 font.Construct(GetFont(), FONT_STYLE_PLAIN, textSize);
861                 pText->SetFont(&font, 0, pText->GetTextLength());
862
863                 Dimension listDimension = GetCore().GetSize();
864
865                 pText->SetBounds(Rectangle(0, 0, listDimension.width, 1));
866                 pText->Compose();
867
868                 Dimension labelDimension = pText->GetTextExtent(0, pText->GetTextLength());
869                 labelDimension.height = pText->GetTotalHeight();
870
871                 if (labelDimension.width > listDimension.width)
872                 {
873                         pText->SetBounds(Rectangle(0, 0, listDimension.width, 1));
874                         pText->Compose();
875
876                         int labelHeight = pText->GetTotalHeight();
877
878                         labelDimension.width = listDimension.width;
879                         labelDimension.height = ((listDimension.height < labelHeight) ? listDimension.height : labelHeight);
880                 }
881
882                 delete pText;
883
884                 __pEmptyText->SetSize(labelDimension);
885                 __pEmptyText->SetBackgroundColor(Color(0, 0, 0, 0));
886                 __pEmptyText->SetTextColor(__emptyTextColor);
887                 __pEmptyText->SetTextConfig(textSize, LABEL_TEXT_STYLE_NORMAL);
888                 __pEmptyText->SetText(text);
889         }
890
891         AdjustLayoutOfEmptyList();
892
893         SetLastResultReturn(E_SUCCESS);
894 }
895
896 String
897 _ListViewImpl::GetTextOfEmptyList(void) const
898 {
899         return ((__pEmptyText != null) ? __pEmptyText->GetText() : String());
900 }
901
902 result
903 _ListViewImpl::SetTextColorOfEmptyList(const Color& color)
904 {
905         __emptyTextColor = color;
906
907         if (__pEmptyText != null)
908         {
909                 __pEmptyText->SetTextColor(color);
910         }
911
912         SetLastResultReturn(E_SUCCESS);
913 }
914
915 Color
916 _ListViewImpl::GetTextColorOfEmptyList(void) const
917 {
918         return __emptyTextColor;
919 }
920
921 result
922 _ListViewImpl::SetListBackgroundColor(const Color& color)
923 {
924         SetBackgroundColor(color);
925
926         SetLastResultReturn(E_SUCCESS);
927 }
928
929 result
930 _ListViewImpl::SetBackgroundBitmap(const Bitmap* pBitmap)
931 {
932         GetCore().SetBackgroundBitmap(const_cast<Bitmap*>(pBitmap));
933         GetCore().SetBackgroundBitmapStretch(true);
934
935         SetLastResultReturn(E_SUCCESS);
936 }
937
938 result
939 _ListViewImpl::BeginReorderingMode(void)
940 {
941         result r = GetCore().SetReorderModeEnabled(true);
942
943         SetLastResultReturn(r);
944 }
945
946 result
947 _ListViewImpl::EndReorderingMode(void)
948 {
949         result r = GetCore().SetReorderModeEnabled(false);
950
951         SetLastResultReturn(r);
952 }
953
954 bool
955 _ListViewImpl::IsInReorderingMode(void) const
956 {
957         return GetCore().IsReorderModeEnabled();
958 }
959
960 void
961 _ListViewImpl::OnListViewContextItemStateChanged(_Control& source, int groupIndex, int itemIndex, int elementId,
962                 ListContextItemStatus status)
963 {
964         if (__pListItemEvent != null)
965         {
966                 GetCore().ResetSweepItem();
967
968                 __pItemNeedsLazyDeletion = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
969
970                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, elementId, 0, 0, NOTIFY_TYPE_SELCTED_CONTEXT_ITEM);
971                 __pListItemEvent->Fire(*pArg);
972
973                 __pItemNeedsLazyDeletion = null;
974         }
975 }
976
977 void
978 _ListViewImpl::OnListViewItemLongPressed(_Control& source, int groupIndex, int itemIndex, int elementId)
979 {
980         if (__pListItemEvent != null)
981         {
982                 __pItemNeedsLazyDeletion = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
983
984                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, elementId, 0, 0, NOTIFY_TYPE_LONG_PRESSED_ITEM);
985                 __pListItemEvent->Fire(*pArg);
986
987                 __pItemNeedsLazyDeletion = null;
988         }
989 }
990
991 void
992 _ListViewImpl::OnTableViewItemStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
993 {
994         if (__pListItemEvent != null)
995         {
996                 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(pItem);
997
998                 __pItemNeedsLazyDeletion = pListViewItem;
999
1000                 if (pListViewItem != null)
1001                 {
1002                         _ListViewItemStateChangedInfo itemInfo;
1003                         pListViewItem->GetLastStateChangedInfo(itemInfo);
1004
1005                         if ((__pLinkEvent != null) && (itemInfo.pUiLinkInfo != null))
1006                         {
1007                                 IEventArg* pLinkEventArg = _PublicLinkEvent::CreateLinkEventArgN(itemInfo.pUiLinkInfo->textInfo,
1008                                                                                                                                                                  itemInfo.pUiLinkInfo->linkType,
1009                                                                                                                                                                  itemInfo.pUiLinkInfo->linkInfo);
1010
1011                                 SysTryReturnVoidResult(NID_UI_CTRL, (pLinkEventArg != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _LinkEventArg.");
1012                                 __pLinkEvent->Fire(*pLinkEventArg);
1013
1014                         }
1015                         else
1016                         {
1017                                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, itemInfo.elementId, 0, 0, static_cast<NotifyType>(status));
1018                                 __pListItemEvent->Fire(*pArg);
1019                         }
1020
1021                         pListViewItem->ClearLastStateChangedInfo();
1022                 }
1023
1024                 __pItemNeedsLazyDeletion = null;
1025         }
1026 }
1027
1028 void
1029 _ListViewImpl::OnTableViewContextItemActivationStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pContextItem, bool activated)
1030 {
1031         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1032
1033         if (pListViewItem != null)
1034         {
1035                 __pItemSwept = (activated ? pListViewItem : null);
1036
1037                 pListViewItem->SetContextItemActivationState(activated);
1038         }
1039 }
1040
1041 void
1042 _ListViewImpl::OnTableViewItemReordered(_TableView& tableView, int itemIndexFrom, int itemIndexTo)
1043 {
1044         if (__pListItemEvent != null)
1045         {
1046                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndexFrom, itemIndexTo, 0, 0, NOTIFY_TYPE_REORDERED_ITEM);
1047                 __pListItemEvent->Fire(*pArg);
1048         }
1049 }
1050
1051 void
1052 _ListViewImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
1053 {
1054         if (__pListItemEvent != null)
1055         {
1056                 __pItemNeedsLazyDeletion = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1057
1058                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, direction, 0, 0, NOTIFY_TYPE_SWEPT_ITEM);
1059                 __pListItemEvent->Fire(*pArg);
1060
1061                 __pItemNeedsLazyDeletion = null;
1062         }
1063 }
1064
1065 void
1066 _ListViewImpl::OnScrollEndReached(_Control& source, ScrollEndEvent type)
1067 {
1068         if (__pScrollEvent != null)
1069         {
1070                 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), type);
1071                 result r = GetLastResult();
1072                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1073
1074                 __pScrollEvent->Fire(*pEventArg);
1075         }
1076 }
1077
1078 void
1079 _ListViewImpl::OnScrollPositionChanged(_Control& source, int scrollPos)
1080 {
1081         if (__pScrollEvent != null)
1082         {
1083                 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), scrollPos);
1084                 result r = GetLastResult();
1085                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1086
1087                 __pScrollEvent->Fire(*pEventArg);
1088         }
1089 }
1090
1091 void
1092 _ListViewImpl::OnScrollStopped(_Control& source)
1093 {
1094         if (__pScrollEvent != null)
1095         {
1096                 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic());
1097                 result r = GetLastResult();
1098                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1099
1100                 __pScrollEvent->Fire(*pEventArg);
1101         }
1102 }
1103
1104 void
1105 _ListViewImpl::OnUiFastScrollIndexSelected(_Control& source, _FastScrollIndex& index)
1106 {
1107         if (__pFastScrollEvent != null)
1108         {
1109                 String* pIndexText = index.GetIndexText();
1110                 if (pIndexText != null)
1111                 {
1112                         _FastScrollEventArg* pEventArg = new (std::nothrow) _FastScrollEventArg(GetPublic(), *pIndexText);
1113                         __pFastScrollEvent->Fire(*pEventArg);
1114                 }
1115         }
1116 }
1117
1118 void
1119 _ListViewImpl::OnDraw(void)
1120 {
1121         _ControlImpl::OnDraw();
1122
1123         if (__redrawListView)
1124         {
1125                 CheckEmptyListShowState();
1126                 __redrawListView = false;
1127         }
1128 }
1129
1130 void
1131 _ListViewImpl::OnBoundsChanged(void)
1132 {
1133         _ControlImpl::OnBoundsChanged();
1134
1135         if (__pEmptyBitmap != null)
1136         {
1137                 SetBitmapOfEmptyList(__pEmptyBitmap->GetBackgroundBitmap());
1138         }
1139         if (__pEmptyText != null)
1140         {
1141                 SetTextOfEmptyList(__pEmptyText->GetText());
1142         }
1143
1144         _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1145
1146         if (pProviderAdaptor != null)
1147         {
1148                 pProviderAdaptor->SetListWidth(GetCore().GetBounds().width);
1149         }
1150 }
1151
1152 void
1153 _ListViewImpl::OnFontChanged(Font* pFont)
1154 {
1155         String fontName = GetFont();
1156         _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1157
1158         if (__pEmptyText != null)
1159         {
1160                 __pEmptyText->SetFont(fontName);
1161                 SetTextOfEmptyList(__pEmptyText->GetText());
1162         }
1163
1164         if (pProviderAdaptor != null)
1165         {
1166                 pProviderAdaptor->SetItemFont(fontName);
1167         }
1168
1169         int firstGroup = -1;
1170         int firstItem = -1;
1171         int lastGroup = -1;
1172         int lastItem = -1;
1173         int currentItem = -1;
1174         int lastItemInGroup = -1;
1175
1176         GetCore().GetFirstLoadedItemIndex(firstGroup, firstItem);
1177         GetCore().GetLastLoadedItemIndex(lastGroup, lastItem);
1178
1179         for (int i = firstGroup; i <= lastGroup; i++)
1180         {
1181                 currentItem = ((i == firstGroup) ? firstItem : -1);
1182                 lastItemInGroup = ((i == lastGroup) ? lastItem : GetCore().GetItemCountAt(i));
1183
1184                 for (; currentItem <= lastItemInGroup; currentItem++)
1185                 {
1186                         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(i, currentItem));
1187
1188                         if (pListViewItem != null)
1189                         {
1190                                 pListViewItem->SetFont(fontName);
1191                         }
1192                 }
1193         }
1194 }
1195
1196 void
1197 _ListViewImpl::OnFontInfoRequested(unsigned long& style, int& size)
1198 {
1199         int textSize = 0;
1200         GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, textSize);
1201
1202         style = FONT_STYLE_PLAIN;
1203         size = textSize;
1204 }
1205
1206 bool
1207 _ListViewImpl::OnTouchPressed(const _ControlImpl& source, const _TouchInfo& touchinfo)
1208 {
1209         FirePublicTouchEvent(touchinfo);
1210         return false;
1211 }
1212
1213 bool
1214 _ListViewImpl::OnTouchReleased(const _ControlImpl& source, const _TouchInfo& touchinfo)
1215 {
1216         FirePublicTouchEvent(touchinfo);
1217         return false;
1218 }
1219
1220 bool
1221 _ListViewImpl::OnTouchMoved(const _ControlImpl& source, const _TouchInfo& touchinfo)
1222 {
1223         FirePublicTouchEvent(touchinfo);
1224         return false;
1225 }
1226
1227 bool
1228 _ListViewImpl::OnTouchCanceled(const _ControlImpl& source, const _TouchInfo& touchinfo)
1229 {
1230         FirePublicTouchEvent(touchinfo);
1231         return false;
1232 }
1233
1234 void
1235 _ListViewImpl::FirePublicTouchEvent(const _TouchInfo& touchInfo)
1236 {
1237         _TouchManager* pTouchManager = _TouchManager::GetInstance();
1238         SysTryReturnVoidResult(NID_UI, pTouchManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1239
1240         TouchEventInfo publicTouchInfo;
1241
1242         _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
1243         SysTryReturnVoidResult(NID_UI, pEventArg, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1244
1245         publicTouchInfo.Construct(*pEventArg);
1246
1247         _Control* pDraggedControl = pTouchManager->GetTouchControlSource();
1248
1249         IEnumeratorT<IEventListener*>* pEnumerator = GetTouchEventListener()->GetEnumeratorN();
1250         if (pEnumerator)
1251         {
1252                 while (pEnumerator->MoveNext() == E_SUCCESS)
1253                 {
1254                         IEventListener* pListener = null;
1255                         pEnumerator->GetCurrent(pListener);
1256
1257                         ITouchEventListener* pTouchEventListener = dynamic_cast <ITouchEventListener*>(pListener);
1258                         if (pTouchEventListener)
1259                         {
1260                                 FirePublicListener(*pTouchEventListener, publicTouchInfo);
1261
1262                                 if (touchInfo.GetTouchStatus() == _TOUCH_RELEASED)
1263                                 {
1264                                         if (pDraggedControl == null)    //if exist dragged control, don't send focus event
1265                                         {
1266                                                 FireFocusListener(*pTouchEventListener, publicTouchInfo);
1267                                         }
1268                                 }
1269                                 else if (touchInfo.GetTouchStatus() == _TOUCH_MOVED)
1270                                 {
1271                                         FireFocusListener(*pTouchEventListener, publicTouchInfo);
1272                                 }
1273                         }
1274                 }
1275
1276                 delete pEnumerator;
1277         }
1278
1279         delete pEventArg;
1280 }
1281
1282 void
1283 _ListViewImpl::FirePublicListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
1284 {
1285         switch (touchEventInfo.GetTouchStatus())
1286         {
1287         case TOUCH_PRESSED:
1288                 listener.OnTouchPressed(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1289                 break;
1290         case TOUCH_LONG_PRESSED:
1291                 listener.OnTouchLongPressed(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1292                 break;
1293         case TOUCH_RELEASED:
1294                 listener.OnTouchReleased(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1295                 break;
1296         case TOUCH_MOVED:
1297                 listener.OnTouchMoved(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1298                 break;
1299         case TOUCH_DOUBLE_PRESSED:
1300                 listener.OnTouchDoublePressed(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1301                 break;
1302         case TOUCH_FOCUS_IN:
1303                 listener.OnTouchFocusIn(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1304                 break;
1305         case TOUCH_FOCUS_OUT:
1306                 listener.OnTouchFocusOut(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1307                 break;
1308         case TOUCH_CANCELED:
1309                 listener.OnTouchCanceled(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1310                 break;
1311         default:
1312                 break;
1313         }
1314 }
1315
1316 void
1317 _ListViewImpl::FireFocusListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
1318 {
1319         _ControlManager* pControlManager = _ControlManager::GetInstance();
1320         SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1321
1322         _TouchManager* pTouchManager = _TouchManager::GetInstance();
1323         SysTryReturnVoidResult(NID_UI, pTouchManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1324
1325         Point screenPoint(pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).x,
1326                                           pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).y);
1327
1328         _Control* pTouchedControl = pControlManager->GetTopmostTouchedControl(screenPoint);
1329         SysTryReturnVoidResult(NID_UI, pTouchedControl, E_INVALID_CONDITION, "[E_INVALID_CONDITION] pTouchedControl is null.");
1330
1331         if (pTouchManager->GetFocusedControlSource() != pTouchedControl)
1332         {
1333                 if (&(GetCore()) != pTouchedControl)
1334                 {
1335                         if (pTouchManager->GetFocusedControlSource() == &(GetCore()))
1336                         {
1337                                 listener.OnTouchFocusOut(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1338                         }
1339                 }
1340                 else
1341                 {
1342                         listener.OnTouchFocusIn(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1343                 }
1344
1345                 pTouchManager->SetFocusedControlSource(*pTouchedControl);
1346         }
1347 }
1348
1349 _TouchEventArg*
1350 _ListViewImpl::GetTouchEventArgN(const _TouchInfo& touchInfo)
1351 {
1352         Point startPoint;
1353
1354         _TouchEventArg* pEventArg = new (std::nothrow) _TouchEventArg(GetPublic(), touchInfo.GetTouchStatus());
1355         SysTryReturn(NID_UI, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1356
1357         _TouchManager* pTouchManager = _TouchManager::GetInstance();
1358         SysTryCatch(NID_UI, pTouchManager, , E_SYSTEM, "[E_SYSTEM] System error occurred.");
1359
1360         startPoint.SetPosition(pTouchManager->GetStartPoint(touchInfo.GetPointId()).x - GetCore().GetAbsoluteBounds().x,
1361                                                    pTouchManager->GetStartPoint(touchInfo.GetPointId()).y - GetCore().GetAbsoluteBounds().y);
1362
1363         pEventArg->SetTouchPosition(touchInfo.GetPointId(), startPoint.x, startPoint.y,
1364                         touchInfo.GetCurrentPosition().x, touchInfo.GetCurrentPosition().y);
1365
1366         // need to flick distance setting
1367
1368         return pEventArg;
1369
1370 CATCH:
1371         delete pEventArg;
1372         return null;
1373 }
1374
1375 class _ListViewMaker
1376         : public _UiBuilderControlMaker
1377 {
1378 public:
1379         _ListViewMaker(_UiBuilder* uibuilder)
1380                 : _UiBuilderControlMaker(uibuilder){};
1381
1382         virtual ~_ListViewMaker(){};
1383
1384         static _UiBuilderControlMaker*
1385         GetInstance(_UiBuilder* uibuilder)
1386         {
1387                 _ListViewMaker* pListViewMaker = new (std::nothrow) _ListViewMaker(uibuilder);
1388                 return pListViewMaker;
1389         };
1390
1391 protected:
1392         virtual Control*
1393         Make(_UiBuilderControl* pControl)
1394         {
1395                 result r = E_SYSTEM;
1396                 _UiBuilderControlLayout* pControlProperty = null;
1397                 ListView* pListView = null;
1398                 Rectangle rect;
1399                 String elementString;
1400
1401                 bool hasItemDivider = true;
1402                 bool hasFastScroll = false;
1403                 int opacity = 100;
1404                 bool isSweepEnabled = false;
1405                 Color color;
1406
1407                 GetProperty(pControl, &pControlProperty);
1408                 if (pControlProperty == null)
1409                 {
1410                         return null;
1411                 }
1412
1413                 pListView = new (std::nothrow) ListView();
1414                 if (pListView == null)
1415                 {
1416                         return null;
1417                 }
1418
1419                 rect = pControlProperty->GetRect();
1420                 //Construct
1421                 if (pControl->GetElement(L"itemDivider", elementString))
1422                 {
1423                         if (elementString.Equals(L"true", false))
1424                         {
1425                                 hasItemDivider = true;
1426                         }
1427                         else
1428                         {
1429                                 hasItemDivider = false;
1430                         }
1431                 }
1432
1433                 if (pControl->GetElement(L"fastScroll", elementString))
1434                 {
1435                         if (elementString.Equals(L"true", false))
1436                         {
1437                                 hasFastScroll = true;
1438                         }
1439                         else
1440                         {
1441                                 hasFastScroll = false;
1442                         }
1443                 }
1444
1445                 r = pListView->Construct(rect, hasItemDivider, hasFastScroll);
1446                 if (r != E_SUCCESS)
1447                 {
1448                         delete pListView;
1449                         pListView = null;
1450
1451                         return null;
1452                 }
1453
1454                 // Set BackgroundsBitmap
1455                 if (pControl->GetElement("backgroundBitmapPath", elementString))
1456                 {
1457                         Bitmap* pBackgroundBitmap = null;
1458                         pBackgroundBitmap = LoadBitmapN(elementString);
1459                         if (pBackgroundBitmap != null)
1460                         {
1461                                 pListView->SetBackgroundBitmap(pBackgroundBitmap);
1462                                 delete pBackgroundBitmap;
1463                                 pBackgroundBitmap = null;
1464                         }
1465                 }
1466
1467                 // Set Empty List
1468                 if (pControl->GetElement(L"textOfEmptyList", elementString))
1469                 {
1470                         pListView->SetTextOfEmptyList(elementString);
1471                 }
1472
1473                 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
1474                 {
1475                         ConvertStringToColor(elementString, color);
1476                         pListView->SetTextColorOfEmptyList(color);
1477                 }
1478
1479                 if (pControl->GetElement(L"bitmapPathOfEmptyList", elementString))
1480                 {
1481                         Bitmap* pBackgroundBitmap = null;
1482                         pBackgroundBitmap = LoadBitmapN(elementString); //__image->DecodeN(path,BITMAP_PIXEL_FORMAT_RGB565);
1483                         if (pBackgroundBitmap != null)
1484                         {
1485                                 pListView->SetBitmapOfEmptyList(pBackgroundBitmap);
1486
1487                                 delete pBackgroundBitmap;
1488                                 pBackgroundBitmap = null;
1489                         }
1490                 }
1491
1492                 if (pControl->GetElement(L"backgroundColorOpacity", elementString) || pControl->GetElement(L"BGColorOpacity", elementString))
1493                 {
1494                         Base::Integer::Parse(elementString, opacity);
1495                 }
1496
1497                 if (pControl->GetElement(L"backgroundColor", elementString) || pControl->GetElement(L"BGColor", elementString))
1498                 {
1499                         ConvertStringToColor32(elementString, opacity, color);
1500                         pListView->SetBackgroundColor(color);
1501                 }
1502
1503                 if (pControl->GetElement(L"itemDividerColor", elementString))
1504                 {
1505                         ConvertStringToColor(elementString, color);
1506                         pListView->SetItemDividerColor(color);
1507                 }
1508
1509                 if (pControl->GetElement(L"sweepEnabled", elementString))
1510                 {
1511                         if (elementString.Equals(L"true", false))
1512                         {
1513                                 isSweepEnabled = true;
1514                         }
1515                         else
1516                         {
1517                                 isSweepEnabled = false;
1518                         }
1519
1520                         pListView->SetSweepEnabled(isSweepEnabled);
1521                 }
1522
1523                 return pListView;
1524         }
1525
1526 private:
1527 }; // _ListViewMaker
1528
1529 _ListViewRegister::_ListViewRegister()
1530 {
1531           _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1532           pUiBuilderControlTableManager->RegisterControl(L"ListView", _ListViewMaker::GetInstance);
1533 }
1534
1535 _ListViewRegister::~_ListViewRegister()
1536 {
1537           _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1538           pUiBuilderControlTableManager->UnregisterControl(L"ListView");
1539 }
1540
1541 static _ListViewRegister ListViewRegisterToUIbuilder;
1542 }}} // Tizen::Ui::Controls
1543