modify Klockwork bug
[platform/framework/native/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 Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FUiCtrl_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 <FApp_AppInfo.h>
27 #include <FGrp_TextTextSimple.h>
28 #include "FUi_AccessibilityContainer.h"
29 #include "FUi_AccessibilityElement.h"
30 #include "FUi_AccessibilityManager.h"
31 #include "FUi_CoordinateSystemUtils.h"
32 #include "FUi_Math.h"
33 #include "FUi_ITouchLongPressGestureEventListener.h"
34 #include "FUi_ResourceManager.h"
35 #include "FUi_TouchEventArg.h"
36 #include "FUi_TouchLongPressGestureDetector.h"
37 #include "FUi_TouchManager.h"
38 #include "FUi_UiBuilder.h"
39 #include "FUi_Window.h"
40 #include "FUiCtrl_FastScrollEvent.h"
41 #include "FUiCtrl_FastScrollEventArg.h"
42 #include "FUiCtrl_Label.h"
43 #include "FUiCtrl_ListItemEvent.h"
44 #include "FUiCtrl_ListItemEventArg.h"
45 #include "FUiCtrl_ListViewImpl.h"
46 #include "FUiCtrl_ListViewItem.h"
47 #include "FUiCtrl_ListViewItemProviderAdaptor.h"
48 #include "FUiCtrl_PublicLinkEvent.h"
49 #include "FUiCtrl_ScrollEvent.h"
50 #include "FUiCtrl_ScrollEventArg.h"
51
52 using namespace Tizen::Base;
53 using namespace Tizen::Base::Collection;
54 using namespace Tizen::Base::Runtime;
55 using namespace Tizen::Base::Utility;
56 using namespace Tizen::Graphics;
57 using namespace Tizen::Graphics::_Text;
58
59 namespace Tizen { namespace Ui { namespace Controls
60 {
61
62 class _ListViewImpl::_ListViewPropagatedTouchEventListener
63         : public Tizen::Ui::_IPropagatedTouchEventListener
64         , public Tizen::Ui::_ITouchLongPressGestureEventListener
65 {
66 public:
67
68         _ListViewPropagatedTouchEventListener(_ListViewImpl& impl)
69                 : __impl(impl)
70                 , __core(impl.GetCore())
71                 , __public(impl.GetPublic())
72                 , __oldPreviousPressedTime(0)
73                 , __previousPressedTime(0)
74                 , __currentPressedTime(0)
75                 , __previousPressedPoint(0.0f, 0.0f)
76                 , __currentPressedPoint(0.0f, 0.0f)
77                 , __pLongPressedGesture(null)
78         {
79                 __pTouchManager = _TouchManager::GetInstance();
80                 SysTryReturnVoidResult(NID_UI_CTRL, (__pTouchManager != null), E_SYSTEM, "[E_SYSTEM] System error occurred.");
81
82                 // Add _TouchLongPressGestureDetector
83                 __pLongPressedGesture = new (std::nothrow) _TouchLongPressGestureDetector();
84                 SysTryReturnVoidResult(NID_UI_CTRL, (__pLongPressedGesture != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
85
86                 __core.AddGestureDetector(*__pLongPressedGesture);
87                 result r = __pLongPressedGesture->AddGestureListener(*this);
88                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] propagating.", GetErrorMessage(r));
89         }
90
91         virtual ~_ListViewPropagatedTouchEventListener(void)
92         {
93                 if (__pLongPressedGesture != null)
94                 {
95                         __pLongPressedGesture->RemoveGestureListener(*this);
96                         __core.RemoveGestureDetector(*__pLongPressedGesture);
97
98                         delete __pLongPressedGesture;
99                         __pLongPressedGesture = null;
100                 }
101         }
102
103         virtual bool OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
104         {
105                 return __impl.CallOnTouchPressed(source, touchInfo);
106         }
107
108         virtual bool OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
109         {
110                 return __impl.CallOnTouchReleased(source, touchInfo);
111         }
112
113         virtual bool OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
114         {
115                 return __impl.CallOnTouchMoved(source, touchInfo);
116         }
117
118         virtual bool OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
119         {
120                 return __impl.CallOnTouchCanceled(source, touchInfo);
121         }
122
123         virtual _UiTouchEventDelivery OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
124         {
125                 _UiTouchEventDelivery isFiltered = _UI_TOUCH_EVENT_DELIVERY_NO;
126                 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
127
128                 if (pListener != null)
129                 {
130                         Control& control = __impl.GetPublic();
131
132                         TouchEventInfo publicTouchInfo;
133
134                         _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
135                         SysTryReturn(NID_UI, pEventArg, _UI_TOUCH_EVENT_DELIVERY_YES, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
136
137                         publicTouchInfo.Construct(*pEventArg);
138
139                         if (pEventArg)
140                         {
141                                 delete pEventArg;
142                                 pEventArg = null;
143                         }
144
145                         if (pListener->OnTouchPressed(control, publicTouchInfo) == true)
146                         {
147                                 return _UI_TOUCH_EVENT_DELIVERY_NO;
148                         }
149                 }
150
151                 // public TouchEventListener
152                 if (ProcessTouchEventListener(touchInfo) == true)
153                 {
154                         return _UI_TOUCH_EVENT_DELIVERY_NO;
155                 }
156
157                 if (__core.Equals(source))
158                 {
159                         return _UI_TOUCH_EVENT_DELIVERY_NO;
160                 }
161
162                 isFiltered = __impl.OnPreviewTouchPressed(__impl, touchInfo);
163                 if (isFiltered == _UI_TOUCH_EVENT_DELIVERY_NO)
164                 {
165                         return _UI_TOUCH_EVENT_DELIVERY_NO;
166                 }
167
168                 isFiltered = __core.OnPreviewTouchPressed(source, touchInfo);
169
170                 return isFiltered;
171         }
172
173         virtual _UiTouchEventDelivery OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
174         {
175                 _UiTouchEventDelivery isFiltered = _UI_TOUCH_EVENT_DELIVERY_NO;
176                 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
177
178                 if (pListener != null)
179                 {
180                         Control& control = __impl.GetPublic();
181
182                         TouchEventInfo publicTouchInfo;
183
184                         _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
185                         SysTryReturn(NID_UI, pEventArg, _UI_TOUCH_EVENT_DELIVERY_YES, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
186
187                         publicTouchInfo.Construct(*pEventArg);
188
189                         if (pEventArg)
190                         {
191                                 delete pEventArg;
192                                 pEventArg = null;
193                         }
194
195                         if (pListener->OnTouchReleased(control, publicTouchInfo) == true)
196                         {
197                                 return _UI_TOUCH_EVENT_DELIVERY_NO;
198                         }
199                 }
200
201                 // public TouchEventListener
202                 if (ProcessTouchEventListener(touchInfo) == true)
203                 {
204                         return _UI_TOUCH_EVENT_DELIVERY_NO;
205                 }
206
207                 if (__core.Equals(source))
208                 {
209                         return _UI_TOUCH_EVENT_DELIVERY_NO;
210                 }
211
212                 isFiltered = __impl.OnPreviewTouchReleased(__impl, touchInfo);
213                 if (isFiltered == _UI_TOUCH_EVENT_DELIVERY_NO)
214                 {
215                         return _UI_TOUCH_EVENT_DELIVERY_NO;
216                 }
217
218                 isFiltered = __core.OnPreviewTouchReleased(source, touchInfo);
219
220                 return isFiltered;
221         }
222
223         virtual _UiTouchEventDelivery OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
224         {
225                 _UiTouchEventDelivery isFiltered = _UI_TOUCH_EVENT_DELIVERY_NO;
226                 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
227
228                 if (pListener != null)
229                 {
230                         Control& control = __impl.GetPublic();
231
232                         TouchEventInfo publicTouchInfo;
233
234                         _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
235                         SysTryReturn(NID_UI, pEventArg, _UI_TOUCH_EVENT_DELIVERY_YES, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
236
237                         publicTouchInfo.Construct(*pEventArg);
238
239                         if (pEventArg)
240                         {
241                                 delete pEventArg;
242                                 pEventArg = null;
243                         }
244
245                         if (pListener->OnTouchMoved(control, publicTouchInfo) == true)
246                         {
247                                 return _UI_TOUCH_EVENT_DELIVERY_NO;
248                         }
249                 }
250
251                 // public TouchEventListener
252                 if (ProcessTouchEventListener(touchInfo) == true)
253                 {
254                         return _UI_TOUCH_EVENT_DELIVERY_NO;
255                 }
256
257                 if (__core.Equals(source))
258                 {
259                         return _UI_TOUCH_EVENT_DELIVERY_NO;
260                 }
261
262                 isFiltered = __impl.OnPreviewTouchMoved(__impl, touchInfo);
263                 if (isFiltered == _UI_TOUCH_EVENT_DELIVERY_NO)
264                 {
265                         return _UI_TOUCH_EVENT_DELIVERY_NO;
266                 }
267
268                 isFiltered = __core.OnPreviewTouchMoved(source, touchInfo);
269
270                 return isFiltered;
271         }
272
273         virtual _UiTouchEventDelivery OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
274         {
275                 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
276
277                 if (pListener != null)
278                 {
279                         Control& control = __impl.GetPublic();
280
281                         TouchEventInfo publicTouchInfo;
282
283                         _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
284                         SysTryReturn(NID_UI, pEventArg, _UI_TOUCH_EVENT_DELIVERY_YES, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
285
286                         publicTouchInfo.Construct(*pEventArg);
287
288                         if (pEventArg)
289                         {
290                                 delete pEventArg;
291                                 pEventArg = null;
292                         }
293
294                         if (pListener->OnTouchCanceled(control, publicTouchInfo) == true)
295                         {
296                                 return _UI_TOUCH_EVENT_DELIVERY_NO;
297                         }
298                 }
299
300                 // public TouchEventListener
301                 if (ProcessTouchEventListener(touchInfo) == true)
302                 {
303                         return _UI_TOUCH_EVENT_DELIVERY_NO;
304                 }
305
306                 return _UI_TOUCH_EVENT_DELIVERY_YES;
307         }
308
309         virtual void OnTouchPressHandled(const _Control& source)
310         {
311                 __impl.OnTouchPressHandled(source);
312         }
313
314         virtual void OnTouchReleaseHandled(const _Control& source)
315         {
316                 __impl.OnTouchReleaseHandled(source);
317         }
318
319         virtual void OnTouchMoveHandled(const _Control& source)
320         {
321                 __impl.OnTouchMoveHandled(source);
322         }
323
324         virtual void OnTouchCancelHandled(const _Control& source)
325         {
326                 __impl.OnTouchCancelHandled(source);
327         }
328
329         bool OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
330         {
331                 bool filtered = ProcessTouchEventListener();
332
333                 if (!filtered)
334                 {
335                         __impl.FireListViewItemLongPressedEvent();
336                 }
337
338                 return filtered;
339         }
340
341         bool OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
342         {
343                 return false;
344         }
345
346 private:
347
348         bool ProcessTouchEventListener(const _TouchInfo& touchInfo)
349         {
350                 bool filtered = false;
351
352                 if (touchInfo.GetTouchStatus() == _TOUCH_PRESSED)
353                 {
354                         filtered = ProcessTouchDoublePressed(touchInfo);
355                 }
356
357                 if (!filtered)
358                 {
359                         ProcessTouchEvent(touchInfo);
360                 }
361
362                 filtered = __impl.IsInputEventConsumed();
363
364                 if (filtered)
365                 {
366                         __impl.ResetInputEventConsumed();
367                 }
368
369                 return filtered;
370         }
371
372         bool ProcessTouchEventListener(void)
373         {
374                 // for TouchLongPressed
375                 _TouchInfo touchInfo(0, _TOUCH_LONG_PRESSED, __currentPressedPoint, false, 0);
376
377                 return ProcessTouchEventListener(touchInfo);
378         }
379
380         void ProcessTouchEvent(const _TouchInfo& touchInfo)
381         {
382                 TouchEventInfo publicTouchInfo;
383
384                 _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
385                 SysTryReturnVoidResult(NID_UI, pEventArg, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
386
387                 publicTouchInfo.Construct(*pEventArg);
388
389                 _Control* pDraggedControl = __pTouchManager->GetTouchControlSource();
390
391                 IEnumeratorT<IEventListener*>* pEnumerator = __impl.GetTouchEventListener()->GetEnumeratorN();
392                 if (pEnumerator)
393                 {
394                         while (pEnumerator->MoveNext() == E_SUCCESS)
395                         {
396                                 IEventListener* pListener = null;
397                                 pEnumerator->GetCurrent(pListener);
398
399                                 ITouchEventListener* pTouchEventListener = dynamic_cast <ITouchEventListener*>(pListener);
400                                 if (pTouchEventListener != null)
401                                 {
402                                         FirePublicListener(*pTouchEventListener, publicTouchInfo);
403
404                                         if (touchInfo.GetTouchStatus() == _TOUCH_RELEASED)
405                                         {
406                                                 if (pDraggedControl == null)    //if exist dragged control, don't send focus event
407                                                 {
408                                                         FireFocusListener(*pTouchEventListener, publicTouchInfo);
409                                                 }
410                                         }
411                                         else if (touchInfo.GetTouchStatus() == _TOUCH_MOVED)
412                                         {
413                                                 FireFocusListener(*pTouchEventListener, publicTouchInfo);
414                                         }
415                                 }
416                         }
417
418                         delete pEnumerator;
419                 }
420
421                 delete pEventArg;
422         }
423
424         bool ProcessTouchDoublePressed(const _TouchInfo& touchinfo)
425         {
426                 if (__pTouchManager->GetPointCount() == 1)
427                 {
428                         __oldPreviousPressedTime = __previousPressedTime;
429                         __previousPressedTime = __currentPressedTime;
430                         __currentPressedTime = touchinfo.GetTimeStamp();
431                         __previousPressedPoint.x = __currentPressedPoint.x;
432                         __previousPressedPoint.y = __currentPressedPoint.y;
433                         __currentPressedPoint.x = touchinfo.GetCurrentPosition().x;
434                         __currentPressedPoint.y = touchinfo.GetCurrentPosition().y;
435
436                         if (Math::Abs(__previousPressedTime - __currentPressedTime) < DOUBLE_PRESS_TIME)
437                         {
438                                 if (Math::Abs(__previousPressedTime - __oldPreviousPressedTime) > DOUBLE_PRESS_TIME)
439                                 {
440                                         if ((Math::Abs(__previousPressedPoint.x - __currentPressedPoint.x) < DOUBLE_PRESS_MOVE_ALLOWANCE)
441                                                 && (Math::Abs(__previousPressedPoint.y - __currentPressedPoint.y) < DOUBLE_PRESS_MOVE_ALLOWANCE))
442                                         {
443                                                 _TouchInfo touchInfo(0, _TOUCH_DOUBLE_PRESSED, __currentPressedPoint, false, 0);
444                                                 ProcessTouchEvent(touchInfo);
445
446                                                 return true;
447                                         }
448                                 }
449                         }
450                 }
451
452                 return false;
453         }
454
455         void FirePublicListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
456         {
457                 switch (touchEventInfo.GetTouchStatus())
458                 {
459                 case TOUCH_PRESSED:
460                         listener.OnTouchPressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
461                         break;
462                 case TOUCH_LONG_PRESSED:
463                         listener.OnTouchLongPressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
464                         break;
465                 case TOUCH_RELEASED:
466                         listener.OnTouchReleased(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
467                         break;
468                 case TOUCH_MOVED:
469                         listener.OnTouchMoved(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
470                         break;
471                 case TOUCH_DOUBLE_PRESSED:
472                         listener.OnTouchDoublePressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
473                         break;
474                 case TOUCH_FOCUS_IN:
475                         listener.OnTouchFocusIn(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
476                         break;
477                 case TOUCH_FOCUS_OUT:
478                         listener.OnTouchFocusOut(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
479                         break;
480                 case TOUCH_CANCELED:
481                         listener.OnTouchCanceled(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
482                         break;
483                 default:
484                         break;
485                 }
486         }
487
488         void FireFocusListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
489         {
490                 _ControlManager* pControlManager = _ControlManager::GetInstance();
491                 SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
492
493                 Point screenPoint(__pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).x,
494                                                   __pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).y);
495
496                 _Control* pTouchedControl = pControlManager->GetTopmostTouchedControl(screenPoint);
497                 SysTryReturnVoidResult(NID_UI, pTouchedControl, E_INVALID_CONDITION, "[E_INVALID_CONDITION] pTouchedControl is null.");
498
499                 if (__pTouchManager->GetFocusedControlSource() != pTouchedControl)
500                 {
501                         if (&(__core) != pTouchedControl)
502                         {
503                                 if (__pTouchManager->GetFocusedControlSource() == &(__core))
504                                 {
505                                         listener.OnTouchFocusOut(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
506                                 }
507                         }
508                         else
509                         {
510                                 listener.OnTouchFocusIn(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
511                         }
512
513                         __pTouchManager->SetFocusedControlSource(*pTouchedControl);
514                 }
515         }
516
517         _TouchEventArg* GetTouchEventArgN(const _TouchInfo& touchInfo)
518         {
519                 FloatPoint startPoint;
520
521                 _TouchEventArg* pEventArg = new (std::nothrow) _TouchEventArg(__public, touchInfo.GetTouchStatus());
522                 SysTryReturn(NID_UI, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
523
524                 startPoint.SetPosition(__pTouchManager->GetStartPoint(touchInfo.GetPointId()).x - __core.GetAbsoluteBoundsF(true).x,
525                                                         __pTouchManager->GetStartPoint(touchInfo.GetPointId()).y - __core.GetAbsoluteBoundsF(true).y);
526
527                 pEventArg->SetTouchPosition(touchInfo.GetPointId(), startPoint.x, startPoint.y,
528                                                                         touchInfo.GetCurrentPosition().x, touchInfo.GetCurrentPosition().y);
529
530                 // need to flick distance setting
531
532                 return pEventArg;
533         }
534
535 private:
536         static const int DOUBLE_PRESS_TIME = 500;
537         static const int DOUBLE_PRESS_MOVE_ALLOWANCE = 10;
538
539         _ListViewImpl& __impl;
540         _Control& __core;
541         Control& __public;
542         _TouchManager* __pTouchManager;
543
544         unsigned int __oldPreviousPressedTime;
545         unsigned int __previousPressedTime;
546         unsigned int __currentPressedTime;
547         Tizen::Graphics::FloatPoint __previousPressedPoint;
548         Tizen::Graphics::FloatPoint __currentPressedPoint;
549         _TouchLongPressGestureDetector* __pLongPressedGesture;
550 };
551
552 _ListViewImpl*
553 _ListViewImpl::GetInstance(ListView& listView)
554 {
555         return static_cast<_ListViewImpl*>(listView._pControlImpl);
556 }
557
558 const _ListViewImpl*
559 _ListViewImpl::GetInstance(const ListView& listView)
560 {
561         return static_cast<const _ListViewImpl*>(listView._pControlImpl);
562 }
563
564 _ListViewImpl::_ListViewImpl(ListView* pList, _TableView* pCore)
565         : _ControlImpl(pList, pCore)
566         , __pListItemEvent(null)
567         , __pLinkEvent(null)
568         , __pScrollEvent(null)
569         , __pFastScrollEvent(null)
570         , __pEmptyBitmap(null)
571         , __pEmptyText(null)
572         , __pAccessibilityElement(null)
573         , __redrawListView(true)
574         , __isOrientationChanged(false)
575         , __needReloadItems(false)
576         , __pPropagatedTouchEventListener(null)
577 {
578         GET_COLOR_CONFIG(TABLEVIEW::EMPTY_CONTENTS_TEXT_NORMAL, __emptyTextColor);
579 }
580
581 _ListViewImpl::~_ListViewImpl()
582 {
583         delete __pListItemEvent;
584         __pListItemEvent = null;
585
586         delete __pLinkEvent;
587         __pLinkEvent = null;
588
589         delete __pScrollEvent;
590         __pScrollEvent = null;
591
592         delete __pFastScrollEvent;
593         __pFastScrollEvent = null;
594
595         if (__pEmptyBitmap != null)
596         {
597                 GetCore().DetachChild(*__pEmptyBitmap);
598
599                 delete __pEmptyBitmap;
600                 __pEmptyBitmap = null;
601         }
602
603         if (__pEmptyText != null)
604         {
605                 GetCore().DetachChild(*__pEmptyText);
606
607                 delete __pEmptyText;
608                 __pEmptyText = null;
609         }
610
611         _AccessibilityContainer* pContainer = GetCore().GetAccessibilityContainer();
612
613         if ((__pAccessibilityElement != null) && (pContainer != null))
614         {
615                 pContainer->RemoveElement(__pAccessibilityElement);
616         }
617
618         delete __pPropagatedTouchEventListener;
619         __pPropagatedTouchEventListener = null;
620 }
621
622 const char*
623 _ListViewImpl::GetPublicClassName(void) const
624 {
625         return "Tizen::Ui::Controls::ListView";
626 }
627
628 const ListView&
629 _ListViewImpl::GetPublic(void) const
630 {
631         return static_cast <const ListView&>(_ControlImpl::GetPublic());
632 }
633
634 ListView&
635 _ListViewImpl::GetPublic(void)
636 {
637         return static_cast <ListView&>(_ControlImpl::GetPublic());
638 }
639
640 const _TableView&
641 _ListViewImpl::GetCore(void) const
642 {
643         return static_cast <const _TableView&>(_ControlImpl::GetCore());
644 }
645
646 _TableView&
647 _ListViewImpl::GetCore(void)
648 {
649         return static_cast <_TableView&>(_ControlImpl::GetCore());
650 }
651
652 _ListViewImpl*
653 _ListViewImpl::CreateListViewImplN(ListView* pControl, bool itemDivider, ListScrollStyle scrollStyle)
654 {
655         result r = E_SUCCESS;
656         TableViewScrollBarStyle scrollBarStyle;
657
658         switch (scrollStyle)
659         {
660         case SCROLL_STYLE_FADE_OUT:
661                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT;
662                 break;
663
664         case SCROLL_STYLE_FIXED:
665                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FIXED;
666                 break;
667
668         case SCROLL_STYLE_FAST_SCROLL:
669                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL;
670                 break;
671
672         case SCROLL_STYLE_JUMP_TO_TOP:
673                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_JUMP_TO_TOP;
674                 break;
675
676         case SCROLL_STYLE_THUMB:
677                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_THUMB;
678                 break;
679
680         case SCROLL_STYLE_FAST_SCROLL_FIXED:
681                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED;
682                 break;
683
684         default:
685                 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_NONE;
686                 break;
687         }
688
689         _TableView* pCore = _TableView::CreateTableViewN(TABLE_VIEW_STYLE_SIMPLE, itemDivider, scrollBarStyle);
690
691         SysTryReturn(NID_UI_CTRL, (pCore != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
692
693         _ListViewImpl* pImpl = new (std::nothrow) _ListViewImpl(pControl, pCore);
694
695         r = CheckConstruction(pCore, pImpl);
696         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), null, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
697
698         pImpl->__pPropagatedTouchEventListener = new (std::nothrow) _ListViewPropagatedTouchEventListener(*pImpl);
699
700         if (pImpl->__pPropagatedTouchEventListener != null)
701         {
702                 pCore->SetPropagatedTouchEventListener(pImpl->__pPropagatedTouchEventListener);
703         }
704
705         return pImpl;
706 }
707
708 result
709 _ListViewImpl::SetItemProvider(IListViewItemProvider& provider)
710 {
711         result r = E_SUCCESS;
712
713         _ListViewItemProviderAdaptor* pProviderAdaptor =
714                         static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
715
716         if (pProviderAdaptor != null)
717         {
718                 IListViewItemProvider* pProvider = pProviderAdaptor->GetItemProvider();
719                 if (&provider == pProvider)
720                 {
721                         return r;
722                 }
723         }
724
725         if (pProviderAdaptor == null)
726         {
727                 pProviderAdaptor = new (std::nothrow) _ListViewItemProviderAdaptor(provider);
728                 SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
729                                 "[E_OUT_OF_MEMORY] Memory allocation failed.");
730
731                 pProviderAdaptor->SetListViewItemEventListener(*this);
732
733                 r = pProviderAdaptor->SetListWidth(GetBoundsF().width);
734                 GetCore().SetItemProviderAdaptor(pProviderAdaptor);
735         }
736         else
737         {
738                 pProviderAdaptor->SetItemProvider(provider);
739                 r = pProviderAdaptor->SetListWidth(GetBoundsF().width);
740
741                 UpdateList();
742         }
743
744         __redrawListView = true;
745
746         SetLastResultReturn(r);
747 }
748
749 result
750 _ListViewImpl::SetItemProvider(IListViewItemProviderF& provider)
751 {
752         // hmkim
753         result r = E_SUCCESS;
754
755         _ListViewItemProviderAdaptor* pProviderAdaptor =
756                         static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
757
758         if (pProviderAdaptor != null)
759         {
760                 IListViewItemProviderF* pProvider = pProviderAdaptor->GetItemProviderF();
761                 if (&provider == pProvider)
762                 {
763                         return r;
764                 }
765         }
766
767         if (pProviderAdaptor == null)
768         {
769                 pProviderAdaptor = new (std::nothrow) _ListViewItemProviderAdaptor(provider);
770                 SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
771                                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
772
773                 pProviderAdaptor->SetListViewItemEventListener(*this);
774
775                 r = pProviderAdaptor->SetListWidth(GetBoundsF().width);
776                 GetCore().SetItemProviderAdaptor(pProviderAdaptor);
777         }
778         else
779         {
780                 pProviderAdaptor->SetItemProvider(provider);
781                 r = pProviderAdaptor->SetListWidth(GetBoundsF().width);
782
783                 UpdateList();
784         }
785
786         __redrawListView = true;
787
788         SetLastResultReturn(r);
789
790         return E_SUCCESS;
791 }
792
793 void
794 _ListViewImpl::AddListViewItemEventListener(IListViewItemEventListener& listener)
795 {
796         result r = E_SUCCESS;
797
798         if (__pListItemEvent == null)
799         {
800                 __pListItemEvent = new (std::nothrow) _ListItemEvent();
801                 SysTryReturnVoidResult(NID_UI_CTRL, (__pListItemEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
802
803                 r = __pListItemEvent->Construct(GetPublic(), CLASSNAME_LISTVIEW);
804                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Item Event.");
805         }
806
807         __pListItemEvent->AddListener(listener);
808
809         r = GetCore().AddTableViewItemEventListener(*this);
810
811         SetLastResult(r);
812 }
813
814 void
815 _ListViewImpl::RemoveListViewItemEventListener(IListViewItemEventListener& listener)
816 {
817         result r = E_SUCCESS;
818
819         if (__pListItemEvent != null)
820         {
821                 r = __pListItemEvent->RemoveListener(listener);
822         }
823
824         SetLastResult(r);
825 }
826
827 void
828 _ListViewImpl::AddFastScrollListener(IFastScrollListener& listener)
829 {
830         result r = E_SUCCESS;
831
832         if (__pFastScrollEvent == null)
833         {
834                 __pFastScrollEvent = new (std::nothrow) _FastScrollEvent();
835                 SysTryReturnVoidResult(NID_UI_CTRL, (__pFastScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
836
837                 r = __pFastScrollEvent->Construct(GetPublic());
838                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct FastScroll Event.");
839         }
840
841         __pFastScrollEvent->AddListener(listener);
842
843         r = GetCore().AddFastScrollListener(*this);
844
845         SetLastResult(r);
846 }
847
848 void
849 _ListViewImpl::RemoveFastScrollListener(IFastScrollListener& listener)
850 {
851         result r = E_SUCCESS;
852
853         if (__pFastScrollEvent != null)
854         {
855                 r = __pFastScrollEvent->RemoveListener(listener);
856         }
857
858         SetLastResult(r);
859 }
860
861 void
862 _ListViewImpl::AddScrollEventListener(IScrollEventListener& listener)
863 {
864         result r = E_SUCCESS;
865
866         if (__pScrollEvent == null)
867         {
868                 __pScrollEvent = new (std::nothrow) _ScrollEvent();
869                 SysTryReturnVoidResult(NID_UI_CTRL, (__pScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
870
871                 r = __pScrollEvent->Construct(GetPublic());
872                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Scroll Event.");
873         }
874
875         __pScrollEvent->AddListener(listener);
876
877         GetCore().AddScrollEventListener(*this);
878
879         SetLastResult(r);
880 }
881
882 void
883 _ListViewImpl::AddScrollEventListener(IScrollEventListenerF& listener)
884 {
885         result r = E_SUCCESS;
886
887         if (__pScrollEvent == null)
888         {
889                 __pScrollEvent = new (std::nothrow) _ScrollEvent();
890                 SysTryReturnVoidResult(NID_UI_CTRL, (__pScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
891
892                 r = __pScrollEvent->Construct(GetPublic());
893                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Scroll Event.");
894         }
895
896         __pScrollEvent->AddListener(listener);
897
898         GetCore().AddScrollEventListener(*this);
899
900         SetLastResult(r);
901 }
902
903 void
904 _ListViewImpl::RemoveScrollEventListener(IScrollEventListener& listener)
905 {
906         result r = E_SUCCESS;
907
908         if (__pScrollEvent != null)
909         {
910                 r = __pScrollEvent->RemoveListener(listener);
911         }
912
913         SetLastResult(r);
914 }
915
916 void
917 _ListViewImpl::RemoveScrollEventListener(IScrollEventListenerF& listener)
918 {
919         result r = E_SUCCESS;
920
921         if (__pScrollEvent != null)
922         {
923                 r = __pScrollEvent->RemoveListener(listener);
924         }
925
926         SetLastResult(r);
927 }
928
929 void
930 _ListViewImpl::AddUiLinkEventListener(const IUiLinkEventListener& listener)
931 {
932         result r = E_SUCCESS;
933
934         if (__pLinkEvent == null)
935         {
936                 __pLinkEvent = _PublicLinkEvent::CreateInstanceN(GetPublic());
937                 SysTryReturnVoidResult(NID_UI_CTRL, (__pLinkEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
938         }
939
940         r = __pLinkEvent->AddListener(listener);
941
942         SetLastResult(r);
943 }
944
945
946 void
947 _ListViewImpl::RemoveUiLinkEventListener(const IUiLinkEventListener& listener)
948 {
949         result r = E_SUCCESS;
950
951         if (__pLinkEvent != null)
952         {
953                 r = __pLinkEvent->RemoveListener(listener);
954         }
955
956         SetLastResult(r);
957 }
958
959 result
960 _ListViewImpl::SetSweepEnabled(bool enable)
961 {
962         GetCore().SetSweepEnabled(enable);
963
964         SetLastResultReturn(E_SUCCESS);
965 }
966
967 result
968 _ListViewImpl::SetFastScrollIndex(const String& text, bool useSearchIcon)
969 {
970         result r = GetCore().SetFastScrollIndex(text, useSearchIcon);
971         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS) || (r == E_SYSTEM), E_INVALID_STATE, E_INVALID_STATE,
972                         "[E_INVALID_STATE] This instance is in an invalid state.");
973
974         SetLastResultReturn(r);
975 }
976
977 int
978 _ListViewImpl::GetTopDrawnItemIndex(void) const
979 {
980         result r = E_SUCCESS;
981         int groupIndex = -1;
982         int itemIndex = -1;
983
984         r = GetCore().GetTopDrawnItemIndex(groupIndex, itemIndex);
985         SetLastResult(r);
986
987         return itemIndex;
988 }
989
990 int
991 _ListViewImpl::GetBottomDrawnItemIndex(void) const
992 {
993         result r = E_SUCCESS;
994         int groupIndex = -1;
995         int itemIndex = -1;
996
997         r = GetCore().GetBottomDrawnItemIndex(groupIndex, itemIndex);
998         SetLastResult(r);
999
1000         return itemIndex;
1001 }
1002
1003 result
1004 _ListViewImpl::ScrollToItem(int index, ListScrollItemAlignment itemAlignment)
1005 {
1006         result r = E_SUCCESS;
1007
1008         if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_TOP)
1009         {
1010                 r = GetCore().SetTopDrawnItemIndex(0, index);
1011         }
1012         else if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_BOTTOM)
1013         {
1014                 r = GetCore().SetBottomDrawnItemIndex(0, index);
1015         }
1016         else
1017         {
1018                 SysTryReturn(NID_UI_CTRL, false, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1019                                 "[E_OUT_OF_RANGE] The specified itemAlignment is out of range.");
1020         }
1021
1022         SetLastResultReturn(r);
1023 }
1024
1025 result
1026 _ListViewImpl::SetItemChecked(int index, bool check)
1027 {
1028         return GetCore().SetItemChecked(0, index, check);
1029 }
1030
1031 bool
1032 _ListViewImpl::IsItemChecked(int index) const
1033 {
1034         return GetCore().IsItemChecked(0, index);
1035 }
1036
1037 result
1038 _ListViewImpl::SetItemEnabled(int index, bool enable)
1039 {
1040         return GetCore().SetItemEnabled(0, index, enable);
1041 }
1042
1043 bool
1044 _ListViewImpl::IsItemEnabled(int index) const
1045 {
1046         return GetCore().IsItemEnabled(0, index);
1047 }
1048
1049 int
1050 _ListViewImpl::GetItemCount(void) const
1051 {
1052         return GetCore().GetItemCountAt(0);
1053 }
1054
1055 result
1056 _ListViewImpl::ShowItemDescriptionText(int index)
1057 {
1058         return SetItemDescriptionTextShowState(index, true);
1059 }
1060
1061 result
1062 _ListViewImpl::HideItemDescriptionText(int index)
1063 {
1064         return SetItemDescriptionTextShowState(index, false);
1065 }
1066
1067 result
1068 _ListViewImpl::SetItemDescriptionTextShowState(int index, bool show)
1069 {
1070         result r = E_SUCCESS;
1071
1072         SysTryReturn(NID_UI_CTRL, (index >= 0) && (index < GetItemCount()), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1073                         "[E_OUT_OF_RANGE] The specified index is out of range.");
1074
1075         _ListViewItemProviderAdaptor* pProviderAdaptor =
1076                         static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1077         SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] _ListItemProviderAdaptor is not set.");
1078
1079         // Save description text show state to provider adaptor
1080         pProviderAdaptor->SetDescriptionTextShowState(index, show);
1081
1082         if (GetCore().FindItem(0, index) != null)
1083         {
1084                 r = GetCore().RefreshTableView(0, index, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1085         }
1086
1087         SetLastResultReturn(r);
1088 }
1089
1090 result
1091 _ListViewImpl::RefreshList(int index, ListRefreshType type)
1092 {
1093         result r = E_SUCCESS;
1094
1095         if (__needReloadItems)
1096         {
1097                 return r;
1098         }
1099
1100         int itemCount = GetCore().GetItemCountAt(0);
1101
1102         if ((index < 0) || (index > itemCount) || ((type != LIST_REFRESH_TYPE_ITEM_ADD) && (index == itemCount)))
1103         {
1104                 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
1105                 return E_OUT_OF_RANGE;
1106         }
1107
1108         if (type == LIST_REFRESH_TYPE_ITEM_MODIFY)
1109         {
1110                 if (IsContextItemOpened(index))
1111                 {
1112                         CloseContextItem(index);
1113                 }
1114
1115                 int topGroupIndex = -1;
1116                 int topItemIndex = -1;
1117                 int bottomGroupIndex = -1;
1118                 int bottomItemIndex = -1;
1119
1120                 GetCore().GetFirstLoadedItemIndex(topGroupIndex, topItemIndex);
1121                 GetCore().GetLastLoadedItemIndex(bottomGroupIndex, bottomItemIndex);
1122
1123                 if ((topItemIndex <= index) && (bottomItemIndex >= index))
1124                 {
1125                         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, index));
1126                         _ListViewItemStatus itemStatus;
1127                         memset(&itemStatus, 0, sizeof(_ListViewItemStatus));
1128                         bool needChangeEventTarget = false;
1129                         bool itemFocused = false;
1130
1131                         if (pListViewItem != null && pListViewItem->IsItemSelected())
1132                         {
1133                                 needChangeEventTarget = true;
1134                         }
1135
1136                         if (pListViewItem != null && pListViewItem->IsFocusModeStateEnabled()
1137                                         && pListViewItem->IsFocused() && pListViewItem->GetRootWindow() && pListViewItem->GetRootWindow()->IsActivated())
1138                         {
1139                                 itemFocused = true;
1140                         }
1141
1142                         if (needChangeEventTarget && (pListViewItem != null))
1143                         {
1144                                 pListViewItem->GetCurrentStatus(itemStatus);
1145                                 pListViewItem = null;
1146                         }
1147
1148                         // item unload
1149                         GetCore().UnloadItem(0, index);
1150                         // item load
1151                         pListViewItem = static_cast<_ListViewItem*>(GetCore().LoadItem(0, index));
1152
1153                         if (needChangeEventTarget && (pListViewItem != null))
1154                         {
1155                                 pListViewItem->SetCurrentStatus(itemStatus);
1156
1157                                 _Control* pTarget = static_cast<_Control*>(pListViewItem);
1158
1159                                 for (int i = 0; i < pListViewItem->GetChildCount(); i++)
1160                                 {
1161                                         if (pListViewItem->GetChild(i)->GetBoundsF().Contains(itemStatus.currentTouchPosition))
1162                                         {
1163                                                 pTarget = pListViewItem->GetChild(i);
1164                                         }
1165                                 }
1166
1167                                 // change touch event target
1168                                 pTarget->SetChangingEventTarget(true);
1169                                 _TouchManager::GetInstance()->SetChangedTouchableTarget(pTarget);
1170                         }
1171
1172                         if (itemFocused && pListViewItem && pListViewItem->IsFocusable()
1173                                         && pListViewItem->GetEnableState() && pListViewItem->GetVisibleState())
1174                         {
1175                                 pListViewItem->SetFocused(true);
1176                                 pListViewItem->DrawFocus();
1177                         }
1178                 }
1179                 else
1180                 {
1181                         // not yet loaded item
1182                         SetLastResultReturn(r);
1183                 }
1184         }
1185         else
1186         {
1187                 r = GetCore().RefreshTableView(0, index, static_cast<TableViewRefreshType>(type));
1188         }
1189
1190         CheckEmptyListShowState();
1191
1192         Draw();
1193         Show();
1194
1195         SetLastResultReturn(r);
1196 }
1197
1198 result
1199 _ListViewImpl::RefreshList(int index, int elementId)
1200 {
1201         if ((index < 0) || (index >= GetCore().GetItemCountAt(0)))
1202         {
1203                 return E_OUT_OF_RANGE;
1204         }
1205
1206         result r = E_SUCCESS;
1207         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, index));
1208
1209         if (pListViewItem != null)
1210         {
1211                 r = (pListViewItem->RefreshElement(elementId)) ? E_SUCCESS : E_OUT_OF_RANGE;
1212         }
1213
1214         SetLastResultReturn(r);
1215 }
1216
1217 result
1218 _ListViewImpl::UpdateList(bool isRestoreAnnexFocusValue)
1219 {
1220         __needReloadItems = true;
1221
1222         result r = GetCore().UpdateTableView(isRestoreAnnexFocusValue);
1223
1224         CheckEmptyListShowState();
1225
1226         Invalidate(true);
1227
1228         // API versioning for initial Show() operation
1229         if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
1230         {
1231                 Show();
1232         }
1233
1234         __needReloadItems = false;
1235
1236         SetLastResultReturn(r);
1237 }
1238
1239 void
1240 _ListViewImpl::SetItemNeedsLazyDeletion(_ListViewItem* pItem)
1241 {
1242         _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1243
1244         if (pProviderAdaptor != null)
1245         {
1246                 pProviderAdaptor->SetItemNeedsLazyDeletion(pItem);
1247         }
1248 }
1249
1250 int
1251 _ListViewImpl::GetItemIndexFromPosition(const FloatPoint& position) const
1252 {
1253         int groupIndex = -1;
1254         int itemIndex = -1;
1255
1256         GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
1257
1258         return itemIndex;
1259 }
1260
1261 result
1262 _ListViewImpl::GetItemIndexFromPosition(const FloatPoint& position, int& itemIndex, int& elementId) const
1263 {
1264         int groupIndex = -1;
1265         elementId = -1;
1266
1267         result r =  GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
1268         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] There is no item at the specified position.");
1269
1270         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1271
1272         if (pListViewItem != null)
1273         {
1274                 FloatPoint originPosition = pListViewItem->GetPositionF();
1275                 originPosition.y -= GetCore().GetScrollPosition();
1276
1277                 elementId = pListViewItem->GetElementIdFromPosition(FloatPoint(position.x - originPosition.x, position.y - originPosition.y));
1278         }
1279
1280         SetLastResultReturn(r);
1281 }
1282
1283 result
1284 _ListViewImpl::SetItemDividerColor(const Color& color)
1285 {
1286         return GetCore().SetItemDividerColor(color);
1287 }
1288
1289 Color
1290 _ListViewImpl::GetItemDividerColor(void) const
1291 {
1292         return GetCore().GetItemDividerColor();
1293 }
1294
1295 void
1296 _ListViewImpl::AdjustLayoutOfEmptyList(void)
1297 {
1298         FloatDimension listDimension = GetCore().GetSizeF();
1299         FloatDimension emptyBitmap;
1300         FloatDimension emptyText;
1301         FloatPoint bitmapPos;
1302         FloatPoint textPos;
1303         float totalHeight = 0.0f;
1304         float horizontalSpacing = 0.0f;
1305
1306         if (__pEmptyBitmap != null)
1307         {
1308                 emptyBitmap = __pEmptyBitmap->GetSizeF();
1309         }
1310
1311         if (__pEmptyText != null)
1312         {
1313                 emptyText = __pEmptyText->GetSizeF();
1314
1315                 if (__pEmptyBitmap != null)
1316                 {
1317                         GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_HORIZONTAL_SPACING, _CONTROL_ORIENTATION_PORTRAIT, horizontalSpacing);
1318                 }
1319         }
1320
1321         totalHeight = emptyBitmap.height + horizontalSpacing + emptyText.height;
1322
1323         if ((__pEmptyBitmap != null) && (__pEmptyText != null) && (totalHeight < listDimension.height))
1324         {
1325                 bitmapPos.x = ((_FloatCompare(listDimension.width, emptyBitmap.width)) ? 0.0f : (listDimension.width - emptyBitmap.width) / 2.0f);
1326                 bitmapPos.y = (listDimension.height - totalHeight) / 2.0f;
1327
1328                 textPos.x = ((_FloatCompare(listDimension.width, emptyText.width)) ? 0.0f : (listDimension.width - emptyText.width) / 2.0f);
1329                 textPos.y = bitmapPos.y + emptyBitmap.height + horizontalSpacing;
1330         }
1331         else
1332         {
1333                 if (__pEmptyBitmap != null)
1334                 {
1335                         bitmapPos.x = ((_FloatCompare(listDimension.width, emptyBitmap.width)) ? 0.0f : (listDimension.width - emptyBitmap.width) / 2.0f);
1336                         bitmapPos.y = ((listDimension.height <= totalHeight) ? 0.0f : (listDimension.height - totalHeight) / 2.0f);
1337                 }
1338
1339                 if (__pEmptyText != null)
1340                 {
1341                         textPos.x = ((_FloatCompare(listDimension.width, emptyText.width)) ? 0.0f : (listDimension.width - emptyText.width) / 2.0f);
1342                         textPos.y = ((listDimension.height <= totalHeight) ? (bitmapPos.y + emptyBitmap.height + horizontalSpacing) : (listDimension.height - totalHeight) / 2.0f);
1343                 }
1344         }
1345
1346         if (__pEmptyBitmap != null)
1347         {
1348                 __pEmptyBitmap->SetPosition(bitmapPos);
1349         }
1350         if (__pEmptyText != null)
1351         {
1352                 __pEmptyText->SetPosition(textPos);
1353         }
1354
1355         CheckEmptyListShowState();
1356         Invalidate(true);
1357 }
1358
1359 void
1360 _ListViewImpl::CheckEmptyListShowState(void)
1361 {
1362         bool isEmpty = (GetItemCount() <= 0);
1363
1364         if (__pEmptyBitmap != null)
1365         {
1366                 __pEmptyBitmap->SetVisibleState(isEmpty);
1367         }
1368         if (__pEmptyText != null)
1369         {
1370                 __pEmptyText->SetVisibleState(isEmpty);
1371         }
1372
1373         _AccessibilityContainer* pContainer = GetCore().GetAccessibilityContainer();
1374
1375         if (_AccessibilityManager::IsActivated() && (pContainer != null))
1376         {
1377                 if (isEmpty)
1378                 {
1379                         if (__pAccessibilityElement == null)
1380                         {
1381                                 __pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
1382
1383                                 SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityElement != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1384
1385                                 __pAccessibilityElement->SetName(L"ListView");
1386
1387                                 pContainer->RemoveAllElement();
1388                                 pContainer->AddElement(*__pAccessibilityElement);
1389                         }
1390
1391                         Rectangle bounds = GetBounds();
1392                         __pAccessibilityElement->SetBounds(Rectangle(0, 0, bounds.width, bounds.height));
1393
1394                         String accessibilityLable;
1395
1396                         if (__pEmptyBitmap != null)
1397                         {
1398                                 __pEmptyBitmap->GetAccessibilityContainer()->Activate(false);
1399
1400                                 accessibilityLable += L"Image, ";
1401                         }
1402                         if (__pEmptyText != null)
1403                         {
1404                                 __pEmptyText->GetAccessibilityContainer()->Activate(false);
1405
1406                                 accessibilityLable += __pEmptyText->GetText();
1407                                 accessibilityLable += L", ";
1408                         }
1409
1410                         accessibilityLable += L"No items";
1411
1412                         __pAccessibilityElement->SetLabel(accessibilityLable);
1413                 }
1414                 else
1415                 {
1416                         if (__pAccessibilityElement != null)
1417                         {
1418                                 if (pContainer->RemoveElement(*__pAccessibilityElement) != E_SUCCESS)
1419                                 {
1420                                         delete __pAccessibilityElement;
1421                                 }
1422                                 __pAccessibilityElement = null;
1423                         }
1424                 }
1425         }
1426 }
1427
1428 result
1429 _ListViewImpl::SetBitmapOfEmptyList(const Bitmap* pBitmap)
1430 {
1431         if (pBitmap == null)
1432         {
1433                 if (__pEmptyBitmap != null)
1434                 {
1435                         GetCore().DetachChild(*__pEmptyBitmap);
1436
1437                         delete __pEmptyBitmap;
1438                         __pEmptyBitmap = null;
1439                 }
1440         }
1441         else
1442         {
1443                 if (__pEmptyBitmap == null)
1444                 {
1445                         __pEmptyBitmap = _Label::CreateLabelN();
1446                         SysTryReturn(NID_UI_CTRL, (__pEmptyBitmap != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1447
1448                         __pEmptyBitmap->SetVisibleState(false);
1449                         __pEmptyBitmap->SetMargin(0.0f, 0.0f);
1450
1451                         GetCore().AttachChild(*__pEmptyBitmap);
1452                 }
1453
1454                 __pEmptyBitmap->SetSize(FloatDimension(pBitmap->GetWidthF(), pBitmap->GetHeightF()));
1455                 __pEmptyBitmap->SetBackgroundColor(Color(0, 0, 0, 0));
1456                 __pEmptyBitmap->SetBackgroundBitmap(*pBitmap);
1457         }
1458
1459         AdjustLayoutOfEmptyList();
1460
1461         SetLastResultReturn(E_SUCCESS);
1462 }
1463
1464 result
1465 _ListViewImpl::SetTextOfEmptyList(const String& text)
1466 {
1467         if (text.IsEmpty())
1468         {
1469                 if (__pEmptyText != null)
1470                 {
1471                         GetCore().DetachChild(*__pEmptyText);
1472
1473                         delete __pEmptyText;
1474                         __pEmptyText = null;
1475                 }
1476         }
1477         else
1478         {
1479                 if (__pEmptyText == null)
1480                 {
1481                         __pEmptyText = _Label::CreateLabelN();
1482                         SysTryReturn(NID_UI_CTRL, (__pEmptyText != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1483
1484                         __pEmptyText->SetVisibleState(false);
1485                         __pEmptyText->SetMargin(0.0f, 0.0f);
1486
1487                         GetCore().AttachChild(*__pEmptyText);
1488                 }
1489
1490                 TextObject* pText = new (std::nothrow) TextObject;
1491                 SysTryReturn(NID_UI_CTRL, (pText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1492
1493                 pText->Construct();
1494
1495                 TextSimple* pSimpleText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(text.GetPointer()), text.GetLength());
1496                 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1497
1498                 pText->AppendElement(*pSimpleText);
1499
1500                 float textSize = 0.0f;
1501                 GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, textSize);
1502
1503                 Font font;
1504                 font.Construct(GetFont(), FONT_STYLE_PLAIN, textSize);
1505                 pText->SetFont(&font, 0, pText->GetTextLength());
1506
1507                 FloatDimension listDimension = GetCore().GetSizeF();
1508
1509                 pText->SetBounds(FloatRectangle(0.0f, 0.0f, listDimension.width, 1.0f));
1510                 pText->Compose();
1511
1512                 FloatDimension labelDimension = pText->GetTextExtentF(0, pText->GetTextLength());
1513                 labelDimension.height = pText->GetTotalHeightF();
1514
1515                 if (labelDimension.width > listDimension.width)
1516                 {
1517                         pText->SetBounds(FloatRectangle(0.0f, 0.0f, listDimension.width, 1.0f));
1518                         pText->Compose();
1519
1520                         float labelHeight = pText->GetTotalHeightF();
1521
1522                         labelDimension.width = listDimension.width;
1523                         labelDimension.height = ((listDimension.height < labelHeight) ? listDimension.height : labelHeight);
1524                 }
1525
1526                 delete pText;
1527
1528                 __pEmptyText->SetSize(labelDimension);
1529                 __pEmptyText->SetBackgroundColor(Color(0, 0, 0, 0));
1530                 __pEmptyText->SetMargin(0.0f, 0.0f, 0.0f, 0.0f);
1531                 __pEmptyText->SetTextColor(__emptyTextColor);
1532                 __pEmptyText->SetTextConfig(textSize, LABEL_TEXT_STYLE_NORMAL);
1533                 __pEmptyText->SetText(text);
1534         }
1535
1536         AdjustLayoutOfEmptyList();
1537
1538         SetLastResultReturn(E_SUCCESS);
1539 }
1540
1541 String
1542 _ListViewImpl::GetTextOfEmptyList(void) const
1543 {
1544         return ((__pEmptyText != null) ? __pEmptyText->GetText() : String());
1545 }
1546
1547 result
1548 _ListViewImpl::SetTextColorOfEmptyList(const Color& color)
1549 {
1550         __emptyTextColor = color;
1551
1552         if (__pEmptyText != null)
1553         {
1554                 __pEmptyText->SetTextColor(color);
1555         }
1556
1557         SetLastResultReturn(E_SUCCESS);
1558 }
1559
1560 Color
1561 _ListViewImpl::GetTextColorOfEmptyList(void) const
1562 {
1563         return __emptyTextColor;
1564 }
1565
1566 result
1567 _ListViewImpl::SetListBackgroundColor(const Color& color)
1568 {
1569         SetBackgroundColor(color);
1570
1571         SetLastResultReturn(E_SUCCESS);
1572 }
1573
1574 result
1575 _ListViewImpl::SetBackgroundBitmap(const Bitmap* pBitmap)
1576 {
1577         GetCore().SetBackgroundBitmap(const_cast<Bitmap*>(pBitmap));
1578         GetCore().SetBackgroundBitmapStretch(true);
1579
1580         SetLastResultReturn(E_SUCCESS);
1581 }
1582
1583 result
1584 _ListViewImpl::BeginReorderingMode(void)
1585 {
1586         result r = GetCore().SetReorderModeEnabled(true);
1587
1588         SetLastResultReturn(r);
1589 }
1590
1591 result
1592 _ListViewImpl::EndReorderingMode(void)
1593 {
1594         result r = GetCore().SetReorderModeEnabled(false);
1595
1596         SetLastResultReturn(r);
1597 }
1598
1599 bool
1600 _ListViewImpl::IsInReorderingMode(void) const
1601 {
1602         return GetCore().IsReorderModeEnabled();
1603 }
1604
1605 void
1606 _ListViewImpl::SetScrollInputMode(ScrollInputMode mode)
1607 {
1608         GetCore().SetScrollInputMode(mode);
1609 }
1610
1611 ScrollInputMode
1612 _ListViewImpl::GetScrollInputMode(void) const
1613 {
1614         return GetCore().GetScrollInputMode();
1615 }
1616
1617 result
1618 _ListViewImpl::OpenContextItem(int itemIndex)
1619 {
1620         return GetCore().OpenContextItem(0, itemIndex);
1621 }
1622
1623 result
1624 _ListViewImpl::CloseContextItem(int itemIndex)
1625 {
1626         return GetCore().CloseContextItem(0, itemIndex);
1627 }
1628
1629 bool
1630 _ListViewImpl::IsContextItemOpened(int itemIndex) const
1631 {
1632         return GetCore().IsContextItemOpened(0, itemIndex);
1633 }
1634
1635 void
1636 _ListViewImpl::OnListViewContextItemStateChanged(_Control& source, int groupIndex, int itemIndex, int elementId,
1637                 ListContextItemStatus status)
1638 {
1639         if (__pListItemEvent != null)
1640         {
1641                 CloseContextItem(itemIndex);
1642
1643                 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1644
1645                 SetItemNeedsLazyDeletion(pListViewItem);
1646
1647                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, elementId, 0, 0, NOTIFY_TYPE_SELCTED_CONTEXT_ITEM);
1648                 __pListItemEvent->Fire(*pArg);
1649
1650                 SetItemNeedsLazyDeletion(null);
1651         }
1652 }
1653
1654 void
1655 _ListViewImpl::OnTableViewItemStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1656 {
1657         if (__pListItemEvent != null)
1658         {
1659                 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(pItem);
1660
1661                 if (pListViewItem != null)
1662                 {
1663                         SetItemNeedsLazyDeletion(pListViewItem);
1664
1665                         _ListViewItemStateChangedInfo itemInfo;
1666                         pListViewItem->GetLastStateChangedInfo(itemInfo);
1667
1668                         if ((__pLinkEvent != null) && (itemInfo.pUiLinkInfo != null))
1669                         {
1670                                 IEventArg* pLinkEventArg = _PublicLinkEvent::CreateLinkEventArgN(itemInfo.pUiLinkInfo->textInfo,
1671                                                 itemInfo.pUiLinkInfo->linkType, itemInfo.pUiLinkInfo->linkInfo);
1672
1673                                 SysTryReturnVoidResult(NID_UI_CTRL, (pLinkEventArg != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _LinkEventArg.");
1674                                 __pLinkEvent->Fire(*pLinkEventArg);
1675
1676                         }
1677                         else
1678                         {
1679                                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, itemInfo.elementId, 0, 0, static_cast<NotifyType>(status));
1680                                 __pListItemEvent->Fire(*pArg);
1681                         }
1682
1683                         pListViewItem->ClearLastStateChangedInfo();
1684
1685                         SetItemNeedsLazyDeletion(null);
1686                 }
1687         }
1688 }
1689
1690 void
1691 _ListViewImpl::OnTableViewContextItemActivationStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pContextItem, bool activated)
1692 {
1693         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1694
1695         if (pListViewItem != null)
1696         {
1697                 pListViewItem->SetContextItemActivationState(activated);
1698         }
1699 }
1700
1701 void
1702 _ListViewImpl::OnTableViewItemReordered(_TableView& tableView, int itemIndexFrom, int itemIndexTo)
1703 {
1704         if (__pListItemEvent != null)
1705         {
1706                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndexFrom, itemIndexTo, 0, 0, NOTIFY_TYPE_REORDERED_ITEM);
1707                 __pListItemEvent->Fire(*pArg);
1708         }
1709 }
1710
1711 void
1712 _ListViewImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
1713 {
1714         if (__pListItemEvent != null)
1715         {
1716                 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1717
1718                 SetItemNeedsLazyDeletion(pListViewItem);
1719
1720                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, direction, 0, 0, NOTIFY_TYPE_SWEPT_ITEM);
1721                 __pListItemEvent->Fire(*pArg);
1722
1723                 SetItemNeedsLazyDeletion(null);
1724         }
1725 }
1726
1727 void
1728 _ListViewImpl::OnScrollEndReached(_Control& source, ScrollEndEvent type)
1729 {
1730         if (__pScrollEvent != null)
1731         {
1732                 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), type);
1733                 result r = GetLastResult();
1734                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1735
1736                 __pScrollEvent->Fire(*pEventArg);
1737         }
1738 }
1739
1740 void
1741 _ListViewImpl::OnScrollPositionChanged(_Control& source, float scrollPosition)
1742 {
1743         if (__pScrollEvent != null)
1744         {
1745                 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), scrollPosition);
1746                 result r = GetLastResult();
1747                 SysTryReturnVoidResult(NID_UI_CTRL, (pEventArg != null), r, "[%s] Propagating.", GetErrorMessage(r));
1748
1749                 __pScrollEvent->Fire(*pEventArg);
1750         }
1751 }
1752
1753 void
1754 _ListViewImpl::OnScrollStopped(_Control& source)
1755 {
1756         if (__pScrollEvent != null)
1757         {
1758                 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic());
1759                 result r = GetLastResult();
1760                 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1761
1762                 __pScrollEvent->Fire(*pEventArg);
1763         }
1764 }
1765
1766 void
1767 _ListViewImpl::OnUiFastScrollIndexSelected(_Control& source, _FastScrollIndex& index)
1768 {
1769         if (__pFastScrollEvent != null)
1770         {
1771                 String* pIndexText = index.GetIndexText();
1772                 if (pIndexText != null)
1773                 {
1774                         _FastScrollEventArg* pEventArg = new (std::nothrow) _FastScrollEventArg(GetPublic(), *pIndexText);
1775                         __pFastScrollEvent->Fire(*pEventArg);
1776                 }
1777         }
1778 }
1779
1780 void
1781 _ListViewImpl::OnDraw(void)
1782 {
1783         _ControlImpl::OnDraw();
1784
1785         if (__redrawListView)
1786         {
1787                 CheckEmptyListShowState();
1788                 __redrawListView = false;
1789         }
1790 }
1791
1792 void
1793 _ListViewImpl::OnChangeLayout(_ControlOrientation orientation)
1794 {
1795         __isOrientationChanged = true;
1796
1797         if (GetCore().IsFocusModeStateEnabled() && GetCore().GetRootWindow() && GetCore().GetRootWindow()->IsActivated())
1798         {
1799                 GetCore().SetFocusDuringOrientationChange();
1800         }
1801
1802         _ControlImpl::OnChangeLayout(orientation);
1803 }
1804
1805 void
1806 _ListViewImpl::OnBoundsChanged(void)
1807 {
1808         _ControlImpl::OnBoundsChanged();
1809
1810         if (__pEmptyBitmap != null)
1811         {
1812                 SetBitmapOfEmptyList(__pEmptyBitmap->GetBackgroundBitmap());
1813         }
1814         if (__pEmptyText != null)
1815         {
1816                 SetTextOfEmptyList(__pEmptyText->GetText());
1817         }
1818
1819         if (__isOrientationChanged)
1820         {
1821                 __isOrientationChanged = false;
1822
1823                 if (GetCore().IsTableViewFocused() && GetCore().IsFocusModeStateEnabled()
1824                                 && GetCore().GetRootWindow() && GetCore().GetRootWindow()->IsActivated())
1825                 {
1826                         UpdateList(true);
1827                 }
1828                 else
1829                 {
1830                         UpdateList();
1831                 }
1832
1833         }
1834 }
1835
1836 void
1837 _ListViewImpl::OnFontChanged(Font* pFont)
1838 {
1839         String fontName = GetFont();
1840         _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1841
1842         if (__pEmptyText != null)
1843         {
1844                 __pEmptyText->SetFont(fontName);
1845                 SetTextOfEmptyList(__pEmptyText->GetText());
1846         }
1847
1848         if (pProviderAdaptor != null)
1849         {
1850                 pProviderAdaptor->SetItemFont(fontName);
1851         }
1852
1853         int firstGroup = -1;
1854         int firstItem = -1;
1855         int lastGroup = -1;
1856         int lastItem = -1;
1857
1858         GetCore().GetFirstLoadedItemIndex(firstGroup, firstItem);
1859         GetCore().GetLastLoadedItemIndex(lastGroup, lastItem);
1860
1861         firstItem = ((firstItem == -1) ?  0 : firstItem);
1862
1863         for (int i = firstItem; i <= lastItem; i++)
1864         {
1865                 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, i));
1866
1867                 if (pListViewItem != null)
1868                 {
1869                         pListViewItem->SetFont(fontName);
1870                 }
1871         }
1872 }
1873
1874 void
1875 _ListViewImpl::OnFontInfoRequested(unsigned long& style, int& size)
1876 {
1877         float textSize = 0.0f;
1878         OnFontInfoRequested(style, textSize);
1879
1880         size = _CoordinateSystemUtils::ConvertToInteger(textSize);
1881 }
1882
1883 void
1884 _ListViewImpl::OnFontInfoRequested(unsigned long& style, float& size)
1885 {
1886         GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, size);
1887         style = FONT_STYLE_PLAIN;
1888 }
1889
1890 FloatPoint
1891 _ListViewImpl::GetCurrentTouchPosition(void)
1892 {
1893         FloatPoint currentTouchPos = _TouchManager::GetInstance()->GetScreenPoint(0);
1894         FloatRectangle bounds = GetCore().GetAbsoluteBoundsF(true);
1895
1896         currentTouchPos.x -= bounds.x;
1897         currentTouchPos.y -= bounds.y;
1898
1899         return currentTouchPos;
1900 }
1901
1902 result
1903 _ListViewImpl::OnTouchEventListenerAdded(void)
1904 {
1905         return E_SUCCESS;
1906 }
1907
1908 result
1909 _ListViewImpl::OnTouchEventListenerRemoved(void)
1910 {
1911         return E_SUCCESS;
1912 }
1913
1914 void
1915 _ListViewImpl::FireListViewItemLongPressedEvent(void)
1916 {
1917         if (__pListItemEvent != null)
1918         {
1919                 int itemIndex = -1;
1920                 int elementId = -1;
1921
1922                 if (GetItemIndexFromPosition(GetCurrentTouchPosition(), itemIndex, elementId) == E_SUCCESS)
1923                 {
1924                         _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1925
1926                         if ((pListViewItem != null) && (!pListViewItem->IsContextItem()))
1927                         {
1928                                 SetItemNeedsLazyDeletion(pListViewItem);
1929
1930                                 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, elementId, 0, 0, NOTIFY_TYPE_LONG_PRESSED_ITEM);
1931                                 __pListItemEvent->Fire(*pArg);
1932
1933                                 SetItemNeedsLazyDeletion(null);
1934                         }
1935                 }
1936         }
1937 }
1938
1939 class _ListViewMaker
1940         : public _UiBuilderControlMaker
1941 {
1942 public:
1943         _ListViewMaker(_UiBuilder* uibuilder)
1944                 : _UiBuilderControlMaker(uibuilder){};
1945
1946         virtual ~_ListViewMaker(){};
1947
1948         static _UiBuilderControlMaker*
1949         GetInstance(_UiBuilder* uibuilder)
1950         {
1951                 _ListViewMaker* pListViewMaker = new (std::nothrow) _ListViewMaker(uibuilder);
1952                 return pListViewMaker;
1953         };
1954
1955 protected:
1956         virtual Control*
1957         Make(_UiBuilderControl* pControl)
1958         {
1959                 result r = E_SYSTEM;
1960                 _UiBuilderControlLayout* pControlProperty = null;
1961                 ListView* pListView = null;
1962                 FloatRectangle rect;
1963                 String elementString;
1964
1965                 ListScrollStyle scrollStyle = SCROLL_STYLE_FADE_OUT;
1966                 ScrollInputMode scrollInputMode = SCROLL_INPUT_MODE_ALLOW_ANY_DIRECTION;
1967
1968                 bool hasItemDivider = true;
1969                 int opacity = 100;
1970                 bool isSweepEnabled = false;
1971                 Color color;
1972
1973                 GetProperty(pControl, &pControlProperty);
1974                 if (pControlProperty == null)
1975                 {
1976                         return null;
1977                 }
1978
1979                 pListView = new (std::nothrow) ListView();
1980                 if (pListView == null)
1981                 {
1982                         return null;
1983                 }
1984
1985                 rect = pControlProperty->GetRectF();
1986
1987                 //Construct
1988                 if (pControl->GetElement(L"itemDivider", elementString))
1989                 {
1990                         if (elementString.Equals(L"true", false))
1991                         {
1992                                 hasItemDivider = true;
1993                         }
1994                         else
1995                         {
1996                                 hasItemDivider = false;
1997                         }
1998                 }
1999
2000                 if (pControl->GetElement(L"listScrollStyle", elementString))
2001                 {
2002                         if (elementString.Equals(L"SCROLL_STYLE_FIXED", false))
2003                         {
2004                                 scrollStyle = SCROLL_STYLE_FIXED;
2005                         }
2006                         else if (elementString.Equals(L"SCROLL_STYLE_FAST_SCROLL", false))
2007                         {
2008                                 scrollStyle = SCROLL_STYLE_FAST_SCROLL;
2009                         }
2010                         else if (elementString.Equals(L"SCROLL_STYLE_JUMP_TO_TOP", false))
2011                         {
2012                                 scrollStyle = SCROLL_STYLE_JUMP_TO_TOP;
2013                         }
2014                         else if (elementString.Equals(L"SCROLL_STYLE_THUMB", false))
2015                         {
2016                                 scrollStyle = SCROLL_STYLE_THUMB;
2017                         }
2018                 }
2019                 else if (pControl->GetElement(L"fastScroll", elementString))
2020                 {
2021                         if (elementString.Equals(L"true", false))
2022                         {
2023                                 scrollStyle = SCROLL_STYLE_FAST_SCROLL;
2024                         }
2025                 }
2026
2027                 r = pListView->Construct(rect, hasItemDivider, scrollStyle);
2028                 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2029
2030                 // Set BackgroundsBitmap
2031                 if (pControl->GetElement("backgroundBitmapPath", elementString))
2032                 {
2033                         Bitmap* pBackgroundBitmap = null;
2034                         pBackgroundBitmap = LoadBitmapN(elementString);
2035                         if (pBackgroundBitmap != null)
2036                         {
2037                                 r = pListView->SetBackgroundBitmap(pBackgroundBitmap);
2038                                 delete pBackgroundBitmap;
2039                                 pBackgroundBitmap = null;
2040
2041                                 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2042                         }
2043                 }
2044
2045                 // Set Empty List
2046                 if (pControl->GetElement(L"textOfEmptyList", elementString))
2047                 {
2048                         r = pListView->SetTextOfEmptyList(elementString);
2049                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2050                 }
2051
2052                 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
2053                 {
2054                         ConvertStringToColor(elementString, color);
2055                         r = pListView->SetTextColorOfEmptyList(color);
2056                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2057                 }
2058
2059                 if (pControl->GetElement(L"bitmapPathOfEmptyList", elementString))
2060                 {
2061                         Bitmap* pBackgroundBitmap = null;
2062                         pBackgroundBitmap = LoadBitmapN(elementString); //__image->DecodeN(path,BITMAP_PIXEL_FORMAT_RGB565);
2063                         if (pBackgroundBitmap != null)
2064                         {
2065                                 r = pListView->SetBitmapOfEmptyList(pBackgroundBitmap);
2066                                 delete pBackgroundBitmap;
2067                                 pBackgroundBitmap = null;
2068
2069                                 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2070                         }
2071                 }
2072
2073                 if (pControl->GetElement(L"backgroundColorOpacity", elementString) || pControl->GetElement(L"BGColorOpacity", elementString))
2074                 {
2075                         Base::Integer::Parse(elementString, opacity);
2076                 }
2077
2078                 if (pControl->GetElement(L"backgroundColor", elementString) || pControl->GetElement(L"BGColor", elementString))
2079                 {
2080                         ConvertStringToColor32(elementString, opacity, color);
2081                         r = pListView->SetBackgroundColor(color);
2082                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2083                 }
2084
2085                 if (pControl->GetElement(L"itemDividerColor", elementString))
2086                 {
2087                         ConvertStringToColor(elementString, color);
2088                         r = pListView->SetItemDividerColor(color);
2089                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2090                 }
2091
2092                 if (pControl->GetElement(L"sweepEnabled", elementString))
2093                 {
2094                         if (elementString.Equals(L"true", false))
2095                         {
2096                                 isSweepEnabled = true;
2097                         }
2098                         else
2099                         {
2100                                 isSweepEnabled = false;
2101                         }
2102
2103                         r = pListView->SetSweepEnabled(isSweepEnabled);
2104                         SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2105                 }
2106
2107                 // scroll Input Mode
2108                 if (pControl->GetElement(L"scrollInputMode", elementString))
2109                 {
2110                         if (elementString.Equals(L"SCROLL_INPUT_MODE_RESTRICT_TO_INITIAL_DIRECTION", false))
2111                         {
2112                                 scrollInputMode = SCROLL_INPUT_MODE_RESTRICT_TO_INITIAL_DIRECTION;
2113                         }
2114
2115                         pListView->SetScrollInputMode(scrollInputMode);
2116                 }
2117
2118                 return pListView;
2119
2120         CATCH:
2121                 delete pListView;
2122                 return null;
2123         }
2124
2125 private:
2126 }; // _ListViewMaker
2127
2128 _ListViewRegister::_ListViewRegister()
2129 {
2130           _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
2131           pUiBuilderControlTableManager->RegisterControl(L"ListView", _ListViewMaker::GetInstance);
2132 }
2133
2134 _ListViewRegister::~_ListViewRegister()
2135 {
2136           _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
2137           pUiBuilderControlTableManager->UnregisterControl(L"ListView");
2138 }
2139
2140 static _ListViewRegister ListViewRegisterToUIbuilder;
2141 }}} // Tizen::Ui::Controls