2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUiCtrl_ListViewImpl.cpp
20 * @brief This is the implementation file for _ListViewImpl class.
22 * This file contains the implementation of _ListViewImpl class.
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"
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 "FUiCtrl_FastScrollEvent.h"
40 #include "FUiCtrl_FastScrollEventArg.h"
41 #include "FUiCtrl_Label.h"
42 #include "FUiCtrl_ListItemEvent.h"
43 #include "FUiCtrl_ListItemEventArg.h"
44 #include "FUiCtrl_ListViewImpl.h"
45 #include "FUiCtrl_ListViewItem.h"
46 #include "FUiCtrl_ListViewItemProviderAdaptor.h"
47 #include "FUiCtrl_PublicLinkEvent.h"
48 #include "FUiCtrl_ScrollEvent.h"
49 #include "FUiCtrl_ScrollEventArg.h"
51 using namespace Tizen::Base;
52 using namespace Tizen::Base::Collection;
53 using namespace Tizen::Base::Runtime;
54 using namespace Tizen::Base::Utility;
55 using namespace Tizen::Graphics;
56 using namespace Tizen::Graphics::_Text;
58 namespace Tizen { namespace Ui { namespace Controls
61 class _ListViewImpl::_ListViewPropagatedTouchEventListener
62 : public Tizen::Ui::_IPropagatedTouchEventListener
63 , public Tizen::Ui::_ITouchLongPressGestureEventListener
67 _ListViewPropagatedTouchEventListener(_ListViewImpl& impl)
69 , __core(impl.GetCore())
70 , __public(impl.GetPublic())
71 , __oldPreviousPressedTime(0)
72 , __previousPressedTime(0)
73 , __currentPressedTime(0)
74 , __previousPressedPoint(0.0f, 0.0f)
75 , __currentPressedPoint(0.0f, 0.0f)
76 , __pLongPressedGesture(null)
78 __pTouchManager = _TouchManager::GetInstance();
79 SysTryReturnVoidResult(NID_UI_CTRL, (__pTouchManager != null), E_SYSTEM, "[E_SYSTEM] System error occurred.");
81 // Add _TouchLongPressGestureDetector
82 __pLongPressedGesture = new (std::nothrow) _TouchLongPressGestureDetector();
83 SysTryReturnVoidResult(NID_UI_CTRL, (__pLongPressedGesture != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
85 __core.AddGestureDetector(*__pLongPressedGesture);
86 result r = __pLongPressedGesture->AddGestureListener(*this);
87 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] propagating.", GetErrorMessage(r));
90 virtual ~_ListViewPropagatedTouchEventListener(void)
92 if (__pLongPressedGesture != null)
94 __pLongPressedGesture->RemoveGestureListener(*this);
95 __core.RemoveGestureDetector(*__pLongPressedGesture);
97 delete __pLongPressedGesture;
98 __pLongPressedGesture = null;
102 virtual bool OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
104 return __impl.CallOnTouchPressed(source, touchInfo);
107 virtual bool OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
109 return __impl.CallOnTouchReleased(source, touchInfo);
112 virtual bool OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
114 return __impl.CallOnTouchMoved(source, touchInfo);
117 virtual bool OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
119 return __impl.CallOnTouchCanceled(source, touchInfo);
122 virtual _UiTouchEventDelivery OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
124 _UiTouchEventDelivery isFiltered = _UI_TOUCH_EVENT_DELIVERY_NO;
125 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
127 if (pListener != null)
129 Control& control = __impl.GetPublic();
131 TouchEventInfo publicTouchInfo;
133 _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
134 SysTryReturn(NID_UI, pEventArg, _UI_TOUCH_EVENT_DELIVERY_YES, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
136 publicTouchInfo.Construct(*pEventArg);
144 if (pListener->OnTouchPressed(control, publicTouchInfo) == true)
146 return _UI_TOUCH_EVENT_DELIVERY_NO;
150 // public TouchEventListener
151 if (ProcessTouchEventListener(touchInfo) == true)
153 return _UI_TOUCH_EVENT_DELIVERY_NO;
156 if (__core.Equals(source))
158 return _UI_TOUCH_EVENT_DELIVERY_NO;
161 isFiltered = __impl.OnPreviewTouchPressed(__impl, touchInfo);
162 if (isFiltered == _UI_TOUCH_EVENT_DELIVERY_NO)
164 return _UI_TOUCH_EVENT_DELIVERY_NO;
167 isFiltered = __core.OnPreviewTouchPressed(source, touchInfo);
172 virtual _UiTouchEventDelivery OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
174 _UiTouchEventDelivery isFiltered = _UI_TOUCH_EVENT_DELIVERY_NO;
175 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
177 if (pListener != null)
179 Control& control = __impl.GetPublic();
181 TouchEventInfo publicTouchInfo;
183 _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
184 SysTryReturn(NID_UI, pEventArg, _UI_TOUCH_EVENT_DELIVERY_YES, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
186 publicTouchInfo.Construct(*pEventArg);
194 if (pListener->OnTouchReleased(control, publicTouchInfo) == true)
196 return _UI_TOUCH_EVENT_DELIVERY_NO;
200 // public TouchEventListener
201 if (ProcessTouchEventListener(touchInfo) == true)
203 return _UI_TOUCH_EVENT_DELIVERY_NO;
206 if (__core.Equals(source))
208 return _UI_TOUCH_EVENT_DELIVERY_NO;
211 isFiltered = __impl.OnPreviewTouchReleased(__impl, touchInfo);
212 if (isFiltered == _UI_TOUCH_EVENT_DELIVERY_NO)
214 return _UI_TOUCH_EVENT_DELIVERY_NO;
217 isFiltered = __core.OnPreviewTouchReleased(source, touchInfo);
222 virtual _UiTouchEventDelivery OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
224 _UiTouchEventDelivery isFiltered = _UI_TOUCH_EVENT_DELIVERY_NO;
225 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
227 if (pListener != null)
229 Control& control = __impl.GetPublic();
231 TouchEventInfo publicTouchInfo;
233 _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
234 SysTryReturn(NID_UI, pEventArg, _UI_TOUCH_EVENT_DELIVERY_YES, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
236 publicTouchInfo.Construct(*pEventArg);
244 if (pListener->OnTouchMoved(control, publicTouchInfo) == true)
246 return _UI_TOUCH_EVENT_DELIVERY_NO;
250 // public TouchEventListener
251 if (ProcessTouchEventListener(touchInfo) == true)
253 return _UI_TOUCH_EVENT_DELIVERY_NO;
256 if (__core.Equals(source))
258 return _UI_TOUCH_EVENT_DELIVERY_NO;
261 isFiltered = __impl.OnPreviewTouchMoved(__impl, touchInfo);
262 if (isFiltered == _UI_TOUCH_EVENT_DELIVERY_NO)
264 return _UI_TOUCH_EVENT_DELIVERY_NO;
267 isFiltered = __core.OnPreviewTouchMoved(source, touchInfo);
272 virtual _UiTouchEventDelivery OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
274 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
276 if (pListener != null)
278 Control& control = __impl.GetPublic();
280 TouchEventInfo publicTouchInfo;
282 _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
283 SysTryReturn(NID_UI, pEventArg, _UI_TOUCH_EVENT_DELIVERY_YES, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory shortage.");
285 publicTouchInfo.Construct(*pEventArg);
293 if (pListener->OnTouchCanceled(control, publicTouchInfo) == true)
295 return _UI_TOUCH_EVENT_DELIVERY_NO;
299 // public TouchEventListener
300 if (ProcessTouchEventListener(touchInfo) == true)
302 return _UI_TOUCH_EVENT_DELIVERY_NO;
305 return _UI_TOUCH_EVENT_DELIVERY_YES;
308 virtual void OnTouchPressHandled(const _Control& source)
310 __impl.OnTouchPressHandled(source);
313 virtual void OnTouchReleaseHandled(const _Control& source)
315 __impl.OnTouchReleaseHandled(source);
318 virtual void OnTouchMoveHandled(const _Control& source)
320 __impl.OnTouchMoveHandled(source);
323 virtual void OnTouchCancelHandled(const _Control& source)
325 __impl.OnTouchCancelHandled(source);
328 bool OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
330 bool filtered = ProcessTouchEventListener();
334 __impl.FireListViewItemLongPressedEvent();
340 bool OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
347 bool ProcessTouchEventListener(const _TouchInfo& touchInfo)
349 bool filtered = false;
351 if (touchInfo.GetTouchStatus() == _TOUCH_PRESSED)
353 filtered = ProcessTouchDoublePressed(touchInfo);
358 ProcessTouchEvent(touchInfo);
361 filtered = __impl.IsInputEventConsumed();
365 __impl.ResetInputEventConsumed();
371 bool ProcessTouchEventListener(void)
373 // for TouchLongPressed
374 _TouchInfo touchInfo(0, _TOUCH_LONG_PRESSED, __currentPressedPoint, false, 0);
376 return ProcessTouchEventListener(touchInfo);
379 void ProcessTouchEvent(const _TouchInfo& touchInfo)
381 TouchEventInfo publicTouchInfo;
383 _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
384 SysTryReturnVoidResult(NID_UI, pEventArg, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
386 publicTouchInfo.Construct(*pEventArg);
388 _Control* pDraggedControl = __pTouchManager->GetTouchControlSource();
390 IEnumeratorT<IEventListener*>* pEnumerator = __impl.GetTouchEventListener()->GetEnumeratorN();
393 while (pEnumerator->MoveNext() == E_SUCCESS)
395 IEventListener* pListener = null;
396 pEnumerator->GetCurrent(pListener);
398 ITouchEventListener* pTouchEventListener = dynamic_cast <ITouchEventListener*>(pListener);
399 if (pTouchEventListener != null)
401 FirePublicListener(*pTouchEventListener, publicTouchInfo);
403 if (touchInfo.GetTouchStatus() == _TOUCH_RELEASED)
405 if (pDraggedControl == null) //if exist dragged control, don't send focus event
407 FireFocusListener(*pTouchEventListener, publicTouchInfo);
410 else if (touchInfo.GetTouchStatus() == _TOUCH_MOVED)
412 FireFocusListener(*pTouchEventListener, publicTouchInfo);
423 bool ProcessTouchDoublePressed(const _TouchInfo& touchinfo)
425 if (__pTouchManager->GetPointCount() == 1)
427 __oldPreviousPressedTime = __previousPressedTime;
428 __previousPressedTime = __currentPressedTime;
429 __currentPressedTime = touchinfo.GetTimeStamp();
430 __previousPressedPoint.x = __currentPressedPoint.x;
431 __previousPressedPoint.y = __currentPressedPoint.y;
432 __currentPressedPoint.x = touchinfo.GetCurrentPosition().x;
433 __currentPressedPoint.y = touchinfo.GetCurrentPosition().y;
435 if (Math::Abs(__previousPressedTime - __currentPressedTime) < DOUBLE_PRESS_TIME)
437 if (Math::Abs(__previousPressedTime - __oldPreviousPressedTime) > DOUBLE_PRESS_TIME)
439 if ((Math::Abs(__previousPressedPoint.x - __currentPressedPoint.x) < DOUBLE_PRESS_MOVE_ALLOWANCE)
440 && (Math::Abs(__previousPressedPoint.y - __currentPressedPoint.y) < DOUBLE_PRESS_MOVE_ALLOWANCE))
442 _TouchInfo touchInfo(0, _TOUCH_DOUBLE_PRESSED, __currentPressedPoint, false, 0);
443 ProcessTouchEvent(touchInfo);
454 void FirePublicListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
456 switch (touchEventInfo.GetTouchStatus())
459 listener.OnTouchPressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
461 case TOUCH_LONG_PRESSED:
462 listener.OnTouchLongPressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
465 listener.OnTouchReleased(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
468 listener.OnTouchMoved(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
470 case TOUCH_DOUBLE_PRESSED:
471 listener.OnTouchDoublePressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
474 listener.OnTouchFocusIn(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
476 case TOUCH_FOCUS_OUT:
477 listener.OnTouchFocusOut(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
480 listener.OnTouchCanceled(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
487 void FireFocusListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
489 _ControlManager* pControlManager = _ControlManager::GetInstance();
490 SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
492 Point screenPoint(__pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).x,
493 __pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).y);
495 _Control* pTouchedControl = pControlManager->GetTopmostTouchedControl(screenPoint);
496 SysTryReturnVoidResult(NID_UI, pTouchedControl, E_INVALID_CONDITION, "[E_INVALID_CONDITION] pTouchedControl is null.");
498 if (__pTouchManager->GetFocusedControlSource() != pTouchedControl)
500 if (&(__core) != pTouchedControl)
502 if (__pTouchManager->GetFocusedControlSource() == &(__core))
504 listener.OnTouchFocusOut(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
509 listener.OnTouchFocusIn(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
512 __pTouchManager->SetFocusedControlSource(*pTouchedControl);
516 _TouchEventArg* GetTouchEventArgN(const _TouchInfo& touchInfo)
518 FloatPoint startPoint;
520 _TouchEventArg* pEventArg = new (std::nothrow) _TouchEventArg(__public, touchInfo.GetTouchStatus());
521 SysTryReturn(NID_UI, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
523 startPoint.SetPosition(__pTouchManager->GetStartPoint(touchInfo.GetPointId()).x - __core.GetAbsoluteBoundsF().x,
524 __pTouchManager->GetStartPoint(touchInfo.GetPointId()).y - __core.GetAbsoluteBoundsF().y);
526 pEventArg->SetTouchPosition(touchInfo.GetPointId(), startPoint.x, startPoint.y,
527 touchInfo.GetCurrentPosition().x, touchInfo.GetCurrentPosition().y);
529 // need to flick distance setting
535 static const int DOUBLE_PRESS_TIME = 500;
536 static const int DOUBLE_PRESS_MOVE_ALLOWANCE = 10;
538 _ListViewImpl& __impl;
541 _TouchManager* __pTouchManager;
543 unsigned int __oldPreviousPressedTime;
544 unsigned int __previousPressedTime;
545 unsigned int __currentPressedTime;
546 Tizen::Graphics::FloatPoint __previousPressedPoint;
547 Tizen::Graphics::FloatPoint __currentPressedPoint;
548 _TouchLongPressGestureDetector* __pLongPressedGesture;
552 _ListViewImpl::GetInstance(ListView& listView)
554 return static_cast<_ListViewImpl*>(listView._pControlImpl);
558 _ListViewImpl::GetInstance(const ListView& listView)
560 return static_cast<const _ListViewImpl*>(listView._pControlImpl);
563 _ListViewImpl::_ListViewImpl(ListView* pList, _TableView* pCore)
564 : _ControlImpl(pList, pCore)
565 , __pListItemEvent(null)
567 , __pScrollEvent(null)
568 , __pFastScrollEvent(null)
569 , __pEmptyBitmap(null)
571 , __pAccessibilityElement(null)
572 , __redrawListView(true)
573 , __isOrientationChanged(false)
574 , __needReloadItems(false)
575 , __pPropagatedTouchEventListener(null)
577 GET_COLOR_CONFIG(TABLEVIEW::EMPTY_CONTENTS_TEXT_NORMAL, __emptyTextColor);
580 _ListViewImpl::~_ListViewImpl()
582 delete __pListItemEvent;
583 __pListItemEvent = null;
588 delete __pScrollEvent;
589 __pScrollEvent = null;
591 delete __pFastScrollEvent;
592 __pFastScrollEvent = null;
594 if (__pEmptyBitmap != null)
596 GetCore().DetachChild(*__pEmptyBitmap);
598 delete __pEmptyBitmap;
599 __pEmptyBitmap = null;
602 if (__pEmptyText != null)
604 GetCore().DetachChild(*__pEmptyText);
610 _AccessibilityContainer* pContainer = GetCore().GetAccessibilityContainer();
612 if ((__pAccessibilityElement != null) && (pContainer != null))
614 pContainer->RemoveElement(__pAccessibilityElement);
617 delete __pPropagatedTouchEventListener;
618 __pPropagatedTouchEventListener = null;
622 _ListViewImpl::GetPublicClassName(void) const
624 return "Tizen::Ui::Controls::ListView";
628 _ListViewImpl::GetPublic(void) const
630 return static_cast <const ListView&>(_ControlImpl::GetPublic());
634 _ListViewImpl::GetPublic(void)
636 return static_cast <ListView&>(_ControlImpl::GetPublic());
640 _ListViewImpl::GetCore(void) const
642 return static_cast <const _TableView&>(_ControlImpl::GetCore());
646 _ListViewImpl::GetCore(void)
648 return static_cast <_TableView&>(_ControlImpl::GetCore());
652 _ListViewImpl::CreateListViewImplN(ListView* pControl, bool itemDivider, ListScrollStyle scrollStyle)
654 result r = E_SUCCESS;
655 TableViewScrollBarStyle scrollBarStyle;
659 case SCROLL_STYLE_FADE_OUT:
660 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT;
663 case SCROLL_STYLE_FIXED:
664 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FIXED;
667 case SCROLL_STYLE_FAST_SCROLL:
668 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL;
671 case SCROLL_STYLE_JUMP_TO_TOP:
672 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_JUMP_TO_TOP;
675 case SCROLL_STYLE_THUMB:
676 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_THUMB;
679 case SCROLL_STYLE_FAST_SCROLL_FIXED:
680 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED;
684 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_NONE;
688 _TableView* pCore = _TableView::CreateTableViewN(TABLE_VIEW_STYLE_SIMPLE, itemDivider, scrollBarStyle);
690 SysTryReturn(NID_UI_CTRL, (pCore != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
692 _ListViewImpl* pImpl = new (std::nothrow) _ListViewImpl(pControl, pCore);
694 r = CheckConstruction(pCore, pImpl);
695 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), null, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
697 pImpl->__pPropagatedTouchEventListener = new (std::nothrow) _ListViewPropagatedTouchEventListener(*pImpl);
699 if (pImpl->__pPropagatedTouchEventListener != null)
701 pCore->SetPropagatedTouchEventListener(pImpl->__pPropagatedTouchEventListener);
708 _ListViewImpl::SetItemProvider(IListViewItemProvider& provider)
710 result r = E_SUCCESS;
712 _ListViewItemProviderAdaptor* pProviderAdaptor =
713 static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
715 if (pProviderAdaptor != null)
717 IListViewItemProvider* pProvider = pProviderAdaptor->GetItemProvider();
718 if (&provider == pProvider)
724 if (pProviderAdaptor == null)
726 pProviderAdaptor = new (std::nothrow) _ListViewItemProviderAdaptor(provider);
727 SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
728 "[E_OUT_OF_MEMORY] The memory is insufficient.");
730 pProviderAdaptor->SetListViewItemEventListener(*this);
732 r = pProviderAdaptor->SetListWidth(GetBoundsF().width);
733 GetCore().SetItemProviderAdaptor(pProviderAdaptor);
737 pProviderAdaptor->SetItemProvider(provider);
738 r = pProviderAdaptor->SetListWidth(GetBoundsF().width);
743 __redrawListView = true;
745 SetLastResultReturn(r);
749 _ListViewImpl::SetItemProvider(IListViewItemProviderF& provider)
752 result r = E_SUCCESS;
754 _ListViewItemProviderAdaptor* pProviderAdaptor =
755 static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
757 if (pProviderAdaptor != null)
759 IListViewItemProviderF* pProvider = pProviderAdaptor->GetItemProviderF();
760 if (&provider == pProvider)
766 if (pProviderAdaptor == null)
768 pProviderAdaptor = new (std::nothrow) _ListViewItemProviderAdaptor(provider);
769 SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
770 "[E_OUT_OF_MEMORY] The memory is insufficient.");
772 pProviderAdaptor->SetListViewItemEventListener(*this);
774 r = pProviderAdaptor->SetListWidth(GetBoundsF().width);
775 GetCore().SetItemProviderAdaptor(pProviderAdaptor);
779 pProviderAdaptor->SetItemProvider(provider);
780 r = pProviderAdaptor->SetListWidth(GetBoundsF().width);
785 __redrawListView = true;
787 SetLastResultReturn(r);
793 _ListViewImpl::AddListViewItemEventListener(IListViewItemEventListener& listener)
795 result r = E_SUCCESS;
797 if (__pListItemEvent == null)
799 __pListItemEvent = new (std::nothrow) _ListItemEvent();
800 SysTryReturnVoidResult(NID_UI_CTRL, (__pListItemEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
802 r = __pListItemEvent->Construct(GetPublic(), CLASSNAME_LISTVIEW);
803 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Item Event.");
806 __pListItemEvent->AddListener(listener);
808 r = GetCore().AddTableViewItemEventListener(*this);
814 _ListViewImpl::RemoveListViewItemEventListener(IListViewItemEventListener& listener)
816 result r = E_SUCCESS;
818 if (__pListItemEvent != null)
820 r = __pListItemEvent->RemoveListener(listener);
827 _ListViewImpl::AddFastScrollListener(IFastScrollListener& listener)
829 result r = E_SUCCESS;
831 if (__pFastScrollEvent == null)
833 __pFastScrollEvent = new (std::nothrow) _FastScrollEvent();
834 SysTryReturnVoidResult(NID_UI_CTRL, (__pFastScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
836 r = __pFastScrollEvent->Construct(GetPublic());
837 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct FastScroll Event.");
840 __pFastScrollEvent->AddListener(listener);
842 r = GetCore().AddFastScrollListener(*this);
848 _ListViewImpl::RemoveFastScrollListener(IFastScrollListener& listener)
850 result r = E_SUCCESS;
852 if (__pFastScrollEvent != null)
854 r = __pFastScrollEvent->RemoveListener(listener);
861 _ListViewImpl::AddScrollEventListener(IScrollEventListener& listener)
863 result r = E_SUCCESS;
865 if (__pScrollEvent == null)
867 __pScrollEvent = new (std::nothrow) _ScrollEvent();
868 SysTryReturnVoidResult(NID_UI_CTRL, (__pScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
870 r = __pScrollEvent->Construct(GetPublic());
871 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Scroll Event.");
874 __pScrollEvent->AddListener(listener);
876 GetCore().AddScrollEventListener(*this);
882 _ListViewImpl::AddScrollEventListener(IScrollEventListenerF& listener)
884 result r = E_SUCCESS;
886 if (__pScrollEvent == null)
888 __pScrollEvent = new (std::nothrow) _ScrollEvent();
889 SysTryReturnVoidResult(NID_UI_CTRL, (__pScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
891 r = __pScrollEvent->Construct(GetPublic());
892 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Scroll Event.");
895 __pScrollEvent->AddListener(listener);
897 GetCore().AddScrollEventListener(*this);
903 _ListViewImpl::RemoveScrollEventListener(IScrollEventListener& listener)
905 result r = E_SUCCESS;
907 if (__pScrollEvent != null)
909 r = __pScrollEvent->RemoveListener(listener);
916 _ListViewImpl::RemoveScrollEventListener(IScrollEventListenerF& listener)
918 result r = E_SUCCESS;
920 if (__pScrollEvent != null)
922 r = __pScrollEvent->RemoveListener(listener);
929 _ListViewImpl::AddUiLinkEventListener(const IUiLinkEventListener& listener)
931 result r = E_SUCCESS;
933 if (__pLinkEvent == null)
935 __pLinkEvent = _PublicLinkEvent::CreateInstanceN(GetPublic());
936 SysTryReturnVoidResult(NID_UI_CTRL, (__pLinkEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
939 r = __pLinkEvent->AddListener(listener);
946 _ListViewImpl::RemoveUiLinkEventListener(const IUiLinkEventListener& listener)
948 result r = E_SUCCESS;
950 if (__pLinkEvent != null)
952 r = __pLinkEvent->RemoveListener(listener);
959 _ListViewImpl::SetSweepEnabled(bool enable)
961 GetCore().SetSweepEnabled(enable);
963 SetLastResultReturn(E_SUCCESS);
967 _ListViewImpl::SetFastScrollIndex(const String& text, bool useSearchIcon)
969 result r = GetCore().SetFastScrollIndex(text, useSearchIcon);
970 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS) || (r == E_SYSTEM), E_INVALID_STATE, E_INVALID_STATE,
971 "[E_INVALID_STATE] This instance is in an invalid state.");
973 SetLastResultReturn(r);
977 _ListViewImpl::GetTopDrawnItemIndex(void) const
982 GetCore().GetTopDrawnItemIndex(groupIndex, itemIndex);
988 _ListViewImpl::GetBottomDrawnItemIndex(void) const
993 GetCore().GetBottomDrawnItemIndex(groupIndex, itemIndex);
999 _ListViewImpl::ScrollToItem(int index, ListScrollItemAlignment itemAlignment)
1001 result r = E_SUCCESS;
1003 if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_TOP)
1005 r = GetCore().SetTopDrawnItemIndex(0, index);
1007 else if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_BOTTOM)
1009 r = GetCore().SetBottomDrawnItemIndex(0, index);
1013 SysTryReturn(NID_UI_CTRL, false, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1014 "[E_OUT_OF_RANGE] The specified itemAlignment is out of range.");
1017 SetLastResultReturn(r);
1021 _ListViewImpl::SetItemChecked(int index, bool check)
1023 return GetCore().SetItemChecked(0, index, check);
1027 _ListViewImpl::IsItemChecked(int index) const
1029 return GetCore().IsItemChecked(0, index);
1033 _ListViewImpl::SetItemEnabled(int index, bool enable)
1035 return GetCore().SetItemEnabled(0, index, enable);
1039 _ListViewImpl::IsItemEnabled(int index) const
1041 return GetCore().IsItemEnabled(0, index);
1045 _ListViewImpl::GetItemCount(void) const
1047 return GetCore().GetItemCountAt(0);
1051 _ListViewImpl::ShowItemDescriptionText(int index)
1053 return SetItemDescriptionTextShowState(index, true);
1057 _ListViewImpl::HideItemDescriptionText(int index)
1059 return SetItemDescriptionTextShowState(index, false);
1063 _ListViewImpl::SetItemDescriptionTextShowState(int index, bool show)
1065 result r = E_SUCCESS;
1067 SysTryReturn(NID_UI_CTRL, (index >= 0) && (index < GetItemCount()), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
1068 "[E_OUT_OF_RANGE] The specified index is out of range.");
1070 _ListViewItemProviderAdaptor* pProviderAdaptor =
1071 static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1072 SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] _ListItemProviderAdaptor is not set.");
1074 // Save description text show state to provider adaptor
1075 pProviderAdaptor->SetDescriptionTextShowState(index, show);
1077 if (GetCore().FindItem(0, index) != null)
1079 r = GetCore().RefreshTableView(0, index, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1082 SetLastResultReturn(r);
1086 _ListViewImpl::RefreshList(int index, ListRefreshType type)
1088 result r = E_SUCCESS;
1090 if (__needReloadItems)
1095 int itemCount = GetCore().GetItemCountAt(0);
1097 if ((index < 0) || (index > itemCount) || ((type != LIST_REFRESH_TYPE_ITEM_ADD) && (index == itemCount)))
1099 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
1100 return E_OUT_OF_RANGE;
1103 if (type == LIST_REFRESH_TYPE_ITEM_MODIFY)
1105 if (IsContextItemOpened(index))
1107 CloseContextItem(index);
1110 int topGroupIndex = -1;
1111 int topItemIndex = -1;
1112 int bottomGroupIndex = -1;
1113 int bottomItemIndex = -1;
1115 GetCore().GetFirstLoadedItemIndex(topGroupIndex, topItemIndex);
1116 GetCore().GetLastLoadedItemIndex(bottomGroupIndex, bottomItemIndex);
1118 if ((topItemIndex <= index) && (bottomItemIndex >= index))
1120 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, index));
1121 _ListViewItemStatus itemStatus;
1122 memset(&itemStatus, 0, sizeof(_ListViewItemStatus));
1123 bool needChangeEventTarget = false;
1125 if (pListViewItem != null && pListViewItem->IsItemSelected())
1127 needChangeEventTarget = true;
1130 if (needChangeEventTarget && (pListViewItem != null))
1132 pListViewItem->GetCurrentStatus(itemStatus);
1133 pListViewItem = null;
1137 GetCore().UnloadItem(0, index);
1139 pListViewItem = static_cast<_ListViewItem*>(GetCore().LoadItem(0, index));
1141 if (needChangeEventTarget && (pListViewItem != null))
1143 pListViewItem->SetCurrentStatus(itemStatus);
1145 _Control* pTarget = static_cast<_Control*>(pListViewItem);
1147 for (int i = 0; i < pListViewItem->GetChildCount(); i++)
1149 if (pListViewItem->GetChild(i)->GetBoundsF().Contains(itemStatus.currentTouchPosition))
1151 pTarget = pListViewItem->GetChild(i);
1155 // change touch event target
1156 pTarget->SetChangingEventTarget(true);
1157 _TouchManager::GetInstance()->SetChangedTouchableTarget(pTarget);
1162 // not yet loaded item
1163 SetLastResultReturn(r);
1168 r = GetCore().RefreshTableView(0, index, static_cast<TableViewRefreshType>(type));
1171 CheckEmptyListShowState();
1176 SetLastResultReturn(r);
1180 _ListViewImpl::RefreshList(int index, int elementId)
1182 if ((index < 0) || (index >= GetCore().GetItemCountAt(0)))
1184 return E_OUT_OF_RANGE;
1187 result r = E_SUCCESS;
1188 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, index));
1190 if (pListViewItem != null)
1192 r = (pListViewItem->RefreshElement(elementId)) ? E_SUCCESS : E_OUT_OF_RANGE;
1195 SetLastResultReturn(r);
1199 _ListViewImpl::UpdateList(void)
1201 __needReloadItems = true;
1203 result r = GetCore().UpdateTableView();
1205 CheckEmptyListShowState();
1209 // API versioning for initial Show() operation
1210 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
1215 __needReloadItems = false;
1217 SetLastResultReturn(r);
1221 _ListViewImpl::SetItemNeedsLazyDeletion(_ListViewItem* pItem)
1223 _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1225 if (pProviderAdaptor != null)
1227 pProviderAdaptor->SetItemNeedsLazyDeletion(pItem);
1232 _ListViewImpl::GetItemIndexFromPosition(const FloatPoint& position) const
1234 int groupIndex = -1;
1237 GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
1243 _ListViewImpl::GetItemIndexFromPosition(const FloatPoint& position, int& itemIndex, int& elementId) const
1245 int groupIndex = -1;
1248 result r = GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
1249 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] There is no item at the specified position.");
1251 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1253 if (pListViewItem != null)
1255 FloatPoint originPosition = pListViewItem->GetPositionF();
1256 originPosition.y -= GetCore().GetScrollPosition();
1258 elementId = pListViewItem->GetElementIdFromPosition(FloatPoint(position.x - originPosition.x, position.y - originPosition.y));
1261 SetLastResultReturn(r);
1265 _ListViewImpl::SetItemDividerColor(const Color& color)
1267 return GetCore().SetItemDividerColor(color);
1271 _ListViewImpl::GetItemDividerColor(void) const
1273 return GetCore().GetItemDividerColor();
1277 _ListViewImpl::AdjustLayoutOfEmptyList(void)
1279 FloatDimension listDimension = GetCore().GetSizeF();
1280 FloatDimension emptyBitmap;
1281 FloatDimension emptyText;
1282 FloatPoint bitmapPos;
1284 float totalHeight = 0.0f;
1285 float horizontalSpacing = 0.0f;
1287 if (__pEmptyBitmap != null)
1289 emptyBitmap = __pEmptyBitmap->GetSizeF();
1292 if (__pEmptyText != null)
1294 emptyText = __pEmptyText->GetSizeF();
1296 if (__pEmptyBitmap != null)
1298 GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_HORIZONTAL_SPACING, _CONTROL_ORIENTATION_PORTRAIT, horizontalSpacing);
1302 totalHeight = emptyBitmap.height + horizontalSpacing + emptyText.height;
1304 if ((__pEmptyBitmap != null) && (__pEmptyText != null) && (totalHeight < listDimension.height))
1306 bitmapPos.x = ((_FloatCompare(listDimension.width, emptyBitmap.width)) ? 0.0f : (listDimension.width - emptyBitmap.width) / 2.0f);
1307 bitmapPos.y = (listDimension.height - totalHeight) / 2.0f;
1309 textPos.x = ((_FloatCompare(listDimension.width, emptyText.width)) ? 0.0f : (listDimension.width - emptyText.width) / 2.0f);
1310 textPos.y = bitmapPos.y + emptyBitmap.height + horizontalSpacing;
1314 if (__pEmptyBitmap != null)
1316 bitmapPos.x = ((_FloatCompare(listDimension.width, emptyBitmap.width)) ? 0.0f : (listDimension.width - emptyBitmap.width) / 2.0f);
1317 bitmapPos.y = ((listDimension.height <= totalHeight) ? 0.0f : (listDimension.height - totalHeight) / 2.0f);
1320 if (__pEmptyText != null)
1322 textPos.x = ((_FloatCompare(listDimension.width, emptyText.width)) ? 0.0f : (listDimension.width - emptyText.width) / 2.0f);
1323 textPos.y = ((listDimension.height <= totalHeight ) ? (bitmapPos.y + emptyBitmap.height + horizontalSpacing) : (listDimension.height - totalHeight) / 2.0f);
1327 if (__pEmptyBitmap != null)
1329 __pEmptyBitmap->SetPosition(bitmapPos);
1331 if (__pEmptyText != null)
1333 __pEmptyText->SetPosition(textPos);
1336 CheckEmptyListShowState();
1341 _ListViewImpl::CheckEmptyListShowState(void)
1343 bool isEmpty = (GetItemCount() <= 0);
1345 if (__pEmptyBitmap != null)
1347 __pEmptyBitmap->SetVisibleState(isEmpty);
1349 if (__pEmptyText != null)
1351 __pEmptyText->SetVisibleState(isEmpty);
1354 _AccessibilityContainer* pContainer = GetCore().GetAccessibilityContainer();
1356 if (_AccessibilityManager::IsActivated() && (pContainer != null))
1360 if (__pAccessibilityElement == null)
1362 __pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
1364 SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityElement != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1366 __pAccessibilityElement->SetName(L"ListView");
1368 pContainer->RemoveAllElement();
1369 pContainer->AddElement(*__pAccessibilityElement);
1372 Rectangle bounds = GetBounds();
1373 __pAccessibilityElement->SetBounds(Rectangle(0, 0, bounds.width, bounds.height));
1375 String accessibilityLable;
1377 if (__pEmptyBitmap != null)
1379 __pEmptyBitmap->GetAccessibilityContainer()->Activate(false);
1381 accessibilityLable += L"Image, ";
1383 if (__pEmptyText != null)
1385 __pEmptyText->GetAccessibilityContainer()->Activate(false);
1387 accessibilityLable += __pEmptyText->GetText();
1388 accessibilityLable += L", ";
1391 accessibilityLable += L"No items";
1393 __pAccessibilityElement->SetLabel(accessibilityLable);
1397 if (__pAccessibilityElement != null)
1399 if (pContainer->RemoveElement(*__pAccessibilityElement) != E_SUCCESS)
1401 delete __pAccessibilityElement;
1403 __pAccessibilityElement = null;
1410 _ListViewImpl::SetBitmapOfEmptyList(const Bitmap* pBitmap)
1412 if (pBitmap == null)
1414 if (__pEmptyBitmap != null)
1416 GetCore().DetachChild(*__pEmptyBitmap);
1418 delete __pEmptyBitmap;
1419 __pEmptyBitmap = null;
1424 if (__pEmptyBitmap == null)
1426 __pEmptyBitmap = _Label::CreateLabelN();
1427 SysTryReturn(NID_UI_CTRL, (__pEmptyBitmap != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1429 __pEmptyBitmap->SetVisibleState(false);
1430 __pEmptyBitmap->SetMargin(0.0f, 0.0f);
1432 GetCore().AttachChild(*__pEmptyBitmap);
1435 __pEmptyBitmap->SetSize(FloatDimension(pBitmap->GetWidthF(), pBitmap->GetHeightF()));
1436 __pEmptyBitmap->SetBackgroundColor(Color(0, 0, 0, 0));
1437 __pEmptyBitmap->SetBackgroundBitmap(*pBitmap);
1440 AdjustLayoutOfEmptyList();
1442 SetLastResultReturn(E_SUCCESS);
1446 _ListViewImpl::SetTextOfEmptyList(const String& text)
1450 if (__pEmptyText != null)
1452 GetCore().DetachChild(*__pEmptyText);
1454 delete __pEmptyText;
1455 __pEmptyText = null;
1460 if (__pEmptyText == null)
1462 __pEmptyText = _Label::CreateLabelN();
1463 SysTryReturn(NID_UI_CTRL, (__pEmptyText != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1465 __pEmptyText->SetVisibleState(false);
1466 __pEmptyText->SetMargin(0.0f, 0.0f);
1468 GetCore().AttachChild(*__pEmptyText);
1471 TextObject* pText = new (std::nothrow) TextObject;
1472 SysTryReturn(NID_UI_CTRL, (pText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1476 TextSimple* pSimpleText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(text.GetPointer()), text.GetLength());
1477 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1479 pText->AppendElement(*pSimpleText);
1481 float textSize = 0.0f;
1482 GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, textSize);
1485 font.Construct(GetFont(), FONT_STYLE_PLAIN, textSize);
1486 pText->SetFont(&font, 0, pText->GetTextLength());
1488 FloatDimension listDimension = GetCore().GetSizeF();
1490 pText->SetBounds(FloatRectangle(0.0f, 0.0f, listDimension.width, 1.0f));
1493 FloatDimension labelDimension = pText->GetTextExtentF(0, pText->GetTextLength());
1494 labelDimension.height = pText->GetTotalHeightF();
1496 if (labelDimension.width > listDimension.width)
1498 pText->SetBounds(FloatRectangle(0.0f, 0.0f, listDimension.width, 1.0f));
1501 float labelHeight = pText->GetTotalHeightF();
1503 labelDimension.width = listDimension.width;
1504 labelDimension.height = ((listDimension.height < labelHeight) ? listDimension.height : labelHeight);
1509 __pEmptyText->SetSize(labelDimension);
1510 __pEmptyText->SetBackgroundColor(Color(0, 0, 0, 0));
1511 __pEmptyText->SetMargin(0.0f, 0.0f, 0.0f, 0.0f);
1512 __pEmptyText->SetTextColor(__emptyTextColor);
1513 __pEmptyText->SetTextConfig(textSize, LABEL_TEXT_STYLE_NORMAL);
1514 __pEmptyText->SetText(text);
1517 AdjustLayoutOfEmptyList();
1519 SetLastResultReturn(E_SUCCESS);
1523 _ListViewImpl::GetTextOfEmptyList(void) const
1525 return ((__pEmptyText != null) ? __pEmptyText->GetText() : String());
1529 _ListViewImpl::SetTextColorOfEmptyList(const Color& color)
1531 __emptyTextColor = color;
1533 if (__pEmptyText != null)
1535 __pEmptyText->SetTextColor(color);
1538 SetLastResultReturn(E_SUCCESS);
1542 _ListViewImpl::GetTextColorOfEmptyList(void) const
1544 return __emptyTextColor;
1548 _ListViewImpl::SetListBackgroundColor(const Color& color)
1550 SetBackgroundColor(color);
1552 SetLastResultReturn(E_SUCCESS);
1556 _ListViewImpl::SetBackgroundBitmap(const Bitmap* pBitmap)
1558 GetCore().SetBackgroundBitmap(const_cast<Bitmap*>(pBitmap));
1559 GetCore().SetBackgroundBitmapStretch(true);
1561 SetLastResultReturn(E_SUCCESS);
1565 _ListViewImpl::BeginReorderingMode(void)
1567 result r = GetCore().SetReorderModeEnabled(true);
1569 SetLastResultReturn(r);
1573 _ListViewImpl::EndReorderingMode(void)
1575 result r = GetCore().SetReorderModeEnabled(false);
1577 SetLastResultReturn(r);
1581 _ListViewImpl::IsInReorderingMode(void) const
1583 return GetCore().IsReorderModeEnabled();
1587 _ListViewImpl::SetScrollInputMode(ScrollInputMode mode)
1589 GetCore().SetScrollInputMode(mode);
1593 _ListViewImpl::GetScrollInputMode(void) const
1595 return GetCore().GetScrollInputMode();
1599 _ListViewImpl::OpenContextItem(int itemIndex)
1601 return GetCore().OpenContextItem(0, itemIndex);
1605 _ListViewImpl::CloseContextItem(int itemIndex)
1607 return GetCore().CloseContextItem(0, itemIndex);
1611 _ListViewImpl::IsContextItemOpened(int itemIndex) const
1613 return GetCore().IsContextItemOpened(0, itemIndex);
1617 _ListViewImpl::OnListViewContextItemStateChanged(_Control& source, int groupIndex, int itemIndex, int elementId,
1618 ListContextItemStatus status)
1620 if (__pListItemEvent != null)
1622 CloseContextItem(itemIndex);
1624 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1626 SetItemNeedsLazyDeletion(pListViewItem);
1628 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, elementId, 0, 0, NOTIFY_TYPE_SELCTED_CONTEXT_ITEM);
1629 __pListItemEvent->Fire(*pArg);
1631 SetItemNeedsLazyDeletion(null);
1636 _ListViewImpl::OnTableViewItemStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1638 if (__pListItemEvent != null)
1640 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(pItem);
1642 if (pListViewItem != null)
1644 SetItemNeedsLazyDeletion(pListViewItem);
1646 _ListViewItemStateChangedInfo itemInfo;
1647 pListViewItem->GetLastStateChangedInfo(itemInfo);
1649 if ((__pLinkEvent != null) && (itemInfo.pUiLinkInfo != null))
1651 IEventArg* pLinkEventArg = _PublicLinkEvent::CreateLinkEventArgN(itemInfo.pUiLinkInfo->textInfo,
1652 itemInfo.pUiLinkInfo->linkType, itemInfo.pUiLinkInfo->linkInfo);
1654 SysTryReturnVoidResult(NID_UI_CTRL, (pLinkEventArg != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _LinkEventArg.");
1655 __pLinkEvent->Fire(*pLinkEventArg);
1660 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, itemInfo.elementId, 0, 0, static_cast<NotifyType>(status));
1661 __pListItemEvent->Fire(*pArg);
1664 pListViewItem->ClearLastStateChangedInfo();
1666 SetItemNeedsLazyDeletion(null);
1672 _ListViewImpl::OnTableViewContextItemActivationStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pContextItem, bool activated)
1674 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1676 if (pListViewItem != null)
1678 pListViewItem->SetContextItemActivationState(activated);
1683 _ListViewImpl::OnTableViewItemReordered(_TableView& tableView, int itemIndexFrom, int itemIndexTo)
1685 if (__pListItemEvent != null)
1687 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndexFrom, itemIndexTo, 0, 0, NOTIFY_TYPE_REORDERED_ITEM);
1688 __pListItemEvent->Fire(*pArg);
1693 _ListViewImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
1695 if (__pListItemEvent != null)
1697 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1699 SetItemNeedsLazyDeletion(pListViewItem);
1701 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, direction, 0, 0, NOTIFY_TYPE_SWEPT_ITEM);
1702 __pListItemEvent->Fire(*pArg);
1704 SetItemNeedsLazyDeletion(null);
1709 _ListViewImpl::OnScrollEndReached(_Control& source, ScrollEndEvent type)
1711 if (__pScrollEvent != null)
1713 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), type);
1714 result r = GetLastResult();
1715 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1717 __pScrollEvent->Fire(*pEventArg);
1722 _ListViewImpl::OnScrollPositionChanged(_Control& source, float scrollPosition)
1724 if (__pScrollEvent != null)
1726 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), scrollPosition);
1727 result r = GetLastResult();
1728 SysTryReturnVoidResult(NID_UI_CTRL, (pEventArg != null), r, "[%s] Propagating.", GetErrorMessage(r));
1730 __pScrollEvent->Fire(*pEventArg);
1735 _ListViewImpl::OnScrollStopped(_Control& source)
1737 if (__pScrollEvent != null)
1739 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic());
1740 result r = GetLastResult();
1741 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1743 __pScrollEvent->Fire(*pEventArg);
1748 _ListViewImpl::OnUiFastScrollIndexSelected(_Control& source, _FastScrollIndex& index)
1750 if (__pFastScrollEvent != null)
1752 String* pIndexText = index.GetIndexText();
1753 if (pIndexText != null)
1755 _FastScrollEventArg* pEventArg = new (std::nothrow) _FastScrollEventArg(GetPublic(), *pIndexText);
1756 __pFastScrollEvent->Fire(*pEventArg);
1762 _ListViewImpl::OnDraw(void)
1764 _ControlImpl::OnDraw();
1766 if (__redrawListView)
1768 CheckEmptyListShowState();
1769 __redrawListView = false;
1774 _ListViewImpl::OnChangeLayout(_ControlOrientation orientation)
1776 __isOrientationChanged = true;
1778 _ControlImpl::OnChangeLayout(orientation);
1782 _ListViewImpl::OnBoundsChanged(void)
1784 _ControlImpl::OnBoundsChanged();
1786 if (__pEmptyBitmap != null)
1788 SetBitmapOfEmptyList(__pEmptyBitmap->GetBackgroundBitmap());
1790 if (__pEmptyText != null)
1792 SetTextOfEmptyList(__pEmptyText->GetText());
1795 if (__isOrientationChanged)
1797 __isOrientationChanged = false;
1803 _ListViewImpl::OnFontChanged(Font* pFont)
1805 String fontName = GetFont();
1806 _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1808 if (__pEmptyText != null)
1810 __pEmptyText->SetFont(fontName);
1811 SetTextOfEmptyList(__pEmptyText->GetText());
1814 if (pProviderAdaptor != null)
1816 pProviderAdaptor->SetItemFont(fontName);
1819 int firstGroup = -1;
1824 GetCore().GetFirstLoadedItemIndex(firstGroup, firstItem);
1825 GetCore().GetLastLoadedItemIndex(lastGroup, lastItem);
1827 firstItem = ((firstItem == -1) ? 0 : firstItem);
1829 for (int i = firstItem; i <= lastItem; i++)
1831 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, i));
1833 if (pListViewItem != null)
1835 pListViewItem->SetFont(fontName);
1841 _ListViewImpl::OnFontInfoRequested(unsigned long& style, int& size)
1843 float textSize = 0.0f;
1844 OnFontInfoRequested(style, textSize);
1846 size = _CoordinateSystemUtils::ConvertToInteger(textSize);
1850 _ListViewImpl::OnFontInfoRequested(unsigned long& style, float& size)
1852 GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, size);
1853 style = FONT_STYLE_PLAIN;
1857 _ListViewImpl::GetCurrentTouchPosition(void)
1859 FloatPoint currentTouchPos = _TouchManager::GetInstance()->GetScreenPoint(0);
1860 FloatRectangle bounds = GetCore().GetAbsoluteBoundsF();
1862 currentTouchPos.x -= bounds.x;
1863 currentTouchPos.y -= bounds.y;
1865 return currentTouchPos;
1869 _ListViewImpl::OnTouchEventListenerAdded(void)
1875 _ListViewImpl::OnTouchEventListenerRemoved(void)
1881 _ListViewImpl::FireListViewItemLongPressedEvent(void)
1883 if (__pListItemEvent != null)
1888 if (GetItemIndexFromPosition(GetCurrentTouchPosition(), itemIndex, elementId) == E_SUCCESS)
1890 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1892 if ((pListViewItem != null) && (!pListViewItem->IsContextItem()))
1894 SetItemNeedsLazyDeletion(pListViewItem);
1896 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, elementId, 0, 0, NOTIFY_TYPE_LONG_PRESSED_ITEM);
1897 __pListItemEvent->Fire(*pArg);
1899 SetItemNeedsLazyDeletion(null);
1905 class _ListViewMaker
1906 : public _UiBuilderControlMaker
1909 _ListViewMaker(_UiBuilder* uibuilder)
1910 : _UiBuilderControlMaker(uibuilder){};
1912 virtual ~_ListViewMaker(){};
1914 static _UiBuilderControlMaker*
1915 GetInstance(_UiBuilder* uibuilder)
1917 _ListViewMaker* pListViewMaker = new (std::nothrow) _ListViewMaker(uibuilder);
1918 return pListViewMaker;
1923 Make(_UiBuilderControl* pControl)
1925 result r = E_SYSTEM;
1926 _UiBuilderControlLayout* pControlProperty = null;
1927 ListView* pListView = null;
1928 FloatRectangle rect;
1929 String elementString;
1931 ListScrollStyle scrollStyle = SCROLL_STYLE_FADE_OUT;
1932 ScrollInputMode scrollInputMode = SCROLL_INPUT_MODE_ALLOW_ANY_DIRECTION;
1934 bool hasItemDivider = true;
1936 bool isSweepEnabled = false;
1939 GetProperty(pControl, &pControlProperty);
1940 if (pControlProperty == null)
1945 pListView = new (std::nothrow) ListView();
1946 if (pListView == null)
1951 rect = pControlProperty->GetRectF();
1954 if (pControl->GetElement(L"itemDivider", elementString))
1956 if (elementString.Equals(L"true", false))
1958 hasItemDivider = true;
1962 hasItemDivider = false;
1966 if (pControl->GetElement(L"listScrollStyle", elementString))
1968 if (elementString.Equals(L"SCROLL_STYLE_FIXED", false))
1970 scrollStyle = SCROLL_STYLE_FIXED;
1972 else if (elementString.Equals(L"SCROLL_STYLE_FAST_SCROLL", false))
1974 scrollStyle = SCROLL_STYLE_FAST_SCROLL;
1976 else if (elementString.Equals(L"SCROLL_STYLE_JUMP_TO_TOP", false))
1978 scrollStyle = SCROLL_STYLE_JUMP_TO_TOP;
1980 else if (elementString.Equals(L"SCROLL_STYLE_THUMB", false))
1982 scrollStyle = SCROLL_STYLE_THUMB;
1985 else if (pControl->GetElement(L"fastScroll", elementString))
1987 if (elementString.Equals(L"true", false))
1989 scrollStyle = SCROLL_STYLE_FAST_SCROLL;
1993 r = pListView->Construct(rect, hasItemDivider, scrollStyle);
1994 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
1996 // Set BackgroundsBitmap
1997 if (pControl->GetElement("backgroundBitmapPath", elementString))
1999 Bitmap* pBackgroundBitmap = null;
2000 pBackgroundBitmap = LoadBitmapN(elementString);
2001 if (pBackgroundBitmap != null)
2003 r = pListView->SetBackgroundBitmap(pBackgroundBitmap);
2004 delete pBackgroundBitmap;
2005 pBackgroundBitmap = null;
2007 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2012 if (pControl->GetElement(L"textOfEmptyList", elementString))
2014 r = pListView->SetTextOfEmptyList(elementString);
2015 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2018 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
2020 ConvertStringToColor(elementString, color);
2021 r = pListView->SetTextColorOfEmptyList(color);
2022 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2025 if (pControl->GetElement(L"bitmapPathOfEmptyList", elementString))
2027 Bitmap* pBackgroundBitmap = null;
2028 pBackgroundBitmap = LoadBitmapN(elementString); //__image->DecodeN(path,BITMAP_PIXEL_FORMAT_RGB565);
2029 if (pBackgroundBitmap != null)
2031 r = pListView->SetBitmapOfEmptyList(pBackgroundBitmap);
2032 delete pBackgroundBitmap;
2033 pBackgroundBitmap = null;
2035 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2039 if (pControl->GetElement(L"backgroundColorOpacity", elementString) || pControl->GetElement(L"BGColorOpacity", elementString))
2041 Base::Integer::Parse(elementString, opacity);
2044 if (pControl->GetElement(L"backgroundColor", elementString) || pControl->GetElement(L"BGColor", elementString))
2046 ConvertStringToColor32(elementString, opacity, color);
2047 r = pListView->SetBackgroundColor(color);
2048 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2051 if (pControl->GetElement(L"itemDividerColor", elementString))
2053 ConvertStringToColor(elementString, color);
2054 r = pListView->SetItemDividerColor(color);
2055 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2058 if (pControl->GetElement(L"sweepEnabled", elementString))
2060 if (elementString.Equals(L"true", false))
2062 isSweepEnabled = true;
2066 isSweepEnabled = false;
2069 r = pListView->SetSweepEnabled(isSweepEnabled);
2070 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2073 // scroll Input Mode
2074 if (pControl->GetElement(L"scrollInputMode", elementString))
2076 if (elementString.Equals(L"SCROLL_INPUT_MODE_RESTRICT_TO_INITIAL_DIRECTION", false))
2078 scrollInputMode = SCROLL_INPUT_MODE_RESTRICT_TO_INITIAL_DIRECTION;
2081 pListView->SetScrollInputMode(scrollInputMode);
2092 }; // _ListViewMaker
2094 _ListViewRegister::_ListViewRegister()
2096 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
2097 pUiBuilderControlTableManager->RegisterControl(L"ListView", _ListViewMaker::GetInstance);
2100 _ListViewRegister::~_ListViewRegister()
2102 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
2103 pUiBuilderControlTableManager->UnregisterControl(L"ListView");
2106 static _ListViewRegister ListViewRegisterToUIbuilder;
2107 }}} // Tizen::Ui::Controls