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 "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"
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;
59 namespace Tizen { namespace Ui { namespace Controls
62 class _ListViewImpl::_ListViewPropagatedTouchEventListener
63 : public Tizen::Ui::_IPropagatedTouchEventListener
64 , public Tizen::Ui::_ITouchLongPressGestureEventListener
68 _ListViewPropagatedTouchEventListener(_ListViewImpl& 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)
79 __pTouchManager = _TouchManager::GetInstance();
80 SysTryReturnVoidResult(NID_UI_CTRL, (__pTouchManager != null), E_SYSTEM, "[E_SYSTEM] System error occurred.");
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.");
86 __core.AddGestureDetector(*__pLongPressedGesture);
87 result r = __pLongPressedGesture->AddGestureListener(*this);
88 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] propagating.", GetErrorMessage(r));
91 virtual ~_ListViewPropagatedTouchEventListener(void)
93 if (__pLongPressedGesture != null)
95 __pLongPressedGesture->RemoveGestureListener(*this);
96 __core.RemoveGestureDetector(*__pLongPressedGesture);
98 delete __pLongPressedGesture;
99 __pLongPressedGesture = null;
103 virtual bool OnTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
105 return __impl.CallOnTouchPressed(source, touchInfo);
108 virtual bool OnTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
110 return __impl.CallOnTouchReleased(source, touchInfo);
113 virtual bool OnTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
115 return __impl.CallOnTouchMoved(source, touchInfo);
118 virtual bool OnTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
120 return __impl.CallOnTouchCanceled(source, touchInfo);
123 virtual _UiTouchEventDelivery OnPreviewTouchPressed(const _Control& source, const _TouchInfo& touchInfo)
125 _UiTouchEventDelivery isFiltered = _UI_TOUCH_EVENT_DELIVERY_NO;
126 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
128 if (pListener != null)
130 Control& control = __impl.GetPublic();
132 TouchEventInfo publicTouchInfo;
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.");
137 publicTouchInfo.Construct(*pEventArg);
145 if (pListener->OnTouchPressed(control, publicTouchInfo) == true)
147 return _UI_TOUCH_EVENT_DELIVERY_NO;
151 // public TouchEventListener
152 if (ProcessTouchEventListener(touchInfo) == true)
154 return _UI_TOUCH_EVENT_DELIVERY_NO;
157 if (__core.Equals(source))
159 return _UI_TOUCH_EVENT_DELIVERY_NO;
162 isFiltered = __impl.OnPreviewTouchPressed(__impl, touchInfo);
163 if (isFiltered == _UI_TOUCH_EVENT_DELIVERY_NO)
165 return _UI_TOUCH_EVENT_DELIVERY_NO;
168 isFiltered = __core.OnPreviewTouchPressed(source, touchInfo);
173 virtual _UiTouchEventDelivery OnPreviewTouchReleased(const _Control& source, const _TouchInfo& touchInfo)
175 _UiTouchEventDelivery isFiltered = _UI_TOUCH_EVENT_DELIVERY_NO;
176 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
178 if (pListener != null)
180 Control& control = __impl.GetPublic();
182 TouchEventInfo publicTouchInfo;
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.");
187 publicTouchInfo.Construct(*pEventArg);
195 if (pListener->OnTouchReleased(control, publicTouchInfo) == true)
197 return _UI_TOUCH_EVENT_DELIVERY_NO;
201 // public TouchEventListener
202 if (ProcessTouchEventListener(touchInfo) == true)
204 return _UI_TOUCH_EVENT_DELIVERY_NO;
207 if (__core.Equals(source))
209 return _UI_TOUCH_EVENT_DELIVERY_NO;
212 isFiltered = __impl.OnPreviewTouchReleased(__impl, touchInfo);
213 if (isFiltered == _UI_TOUCH_EVENT_DELIVERY_NO)
215 return _UI_TOUCH_EVENT_DELIVERY_NO;
218 isFiltered = __core.OnPreviewTouchReleased(source, touchInfo);
223 virtual _UiTouchEventDelivery OnPreviewTouchMoved(const _Control& source, const _TouchInfo& touchInfo)
225 _UiTouchEventDelivery isFiltered = _UI_TOUCH_EVENT_DELIVERY_NO;
226 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
228 if (pListener != null)
230 Control& control = __impl.GetPublic();
232 TouchEventInfo publicTouchInfo;
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.");
237 publicTouchInfo.Construct(*pEventArg);
245 if (pListener->OnTouchMoved(control, publicTouchInfo) == true)
247 return _UI_TOUCH_EVENT_DELIVERY_NO;
251 // public TouchEventListener
252 if (ProcessTouchEventListener(touchInfo) == true)
254 return _UI_TOUCH_EVENT_DELIVERY_NO;
257 if (__core.Equals(source))
259 return _UI_TOUCH_EVENT_DELIVERY_NO;
262 isFiltered = __impl.OnPreviewTouchMoved(__impl, touchInfo);
263 if (isFiltered == _UI_TOUCH_EVENT_DELIVERY_NO)
265 return _UI_TOUCH_EVENT_DELIVERY_NO;
268 isFiltered = __core.OnPreviewTouchMoved(source, touchInfo);
273 virtual _UiTouchEventDelivery OnPreviewTouchCanceled(const _Control& source, const _TouchInfo& touchInfo)
275 IPropagatedTouchEventListener* pListener = __impl.GetPublicPropagatedTouchEventListener();
277 if (pListener != null)
279 Control& control = __impl.GetPublic();
281 TouchEventInfo publicTouchInfo;
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.");
286 publicTouchInfo.Construct(*pEventArg);
294 if (pListener->OnTouchCanceled(control, publicTouchInfo) == true)
296 return _UI_TOUCH_EVENT_DELIVERY_NO;
300 // public TouchEventListener
301 if (ProcessTouchEventListener(touchInfo) == true)
303 return _UI_TOUCH_EVENT_DELIVERY_NO;
306 return _UI_TOUCH_EVENT_DELIVERY_YES;
309 virtual void OnTouchPressHandled(const _Control& source)
311 __impl.OnTouchPressHandled(source);
314 virtual void OnTouchReleaseHandled(const _Control& source)
316 __impl.OnTouchReleaseHandled(source);
319 virtual void OnTouchMoveHandled(const _Control& source)
321 __impl.OnTouchMoveHandled(source);
324 virtual void OnTouchCancelHandled(const _Control& source)
326 __impl.OnTouchCancelHandled(source);
329 bool OnLongPressGestureDetected(_TouchLongPressGestureDetector& gesture)
331 bool filtered = ProcessTouchEventListener();
335 __impl.FireListViewItemLongPressedEvent();
341 bool OnLongPressGestureCanceled(_TouchLongPressGestureDetector& gesture)
348 bool ProcessTouchEventListener(const _TouchInfo& touchInfo)
350 bool filtered = false;
352 if (touchInfo.GetTouchStatus() == _TOUCH_PRESSED)
354 filtered = ProcessTouchDoublePressed(touchInfo);
359 ProcessTouchEvent(touchInfo);
362 filtered = __impl.IsInputEventConsumed();
366 __impl.ResetInputEventConsumed();
372 bool ProcessTouchEventListener(void)
374 // for TouchLongPressed
375 _TouchInfo touchInfo(0, _TOUCH_LONG_PRESSED, __currentPressedPoint, false, 0);
377 return ProcessTouchEventListener(touchInfo);
380 void ProcessTouchEvent(const _TouchInfo& touchInfo)
382 TouchEventInfo publicTouchInfo;
384 _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
385 SysTryReturnVoidResult(NID_UI, pEventArg, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
387 publicTouchInfo.Construct(*pEventArg);
389 _Control* pDraggedControl = __pTouchManager->GetTouchControlSource();
391 IEnumeratorT<IEventListener*>* pEnumerator = __impl.GetTouchEventListener()->GetEnumeratorN();
394 while (pEnumerator->MoveNext() == E_SUCCESS)
396 IEventListener* pListener = null;
397 pEnumerator->GetCurrent(pListener);
399 ITouchEventListener* pTouchEventListener = dynamic_cast <ITouchEventListener*>(pListener);
400 if (pTouchEventListener != null)
402 FirePublicListener(*pTouchEventListener, publicTouchInfo);
404 if (touchInfo.GetTouchStatus() == _TOUCH_RELEASED)
406 if (pDraggedControl == null) //if exist dragged control, don't send focus event
408 FireFocusListener(*pTouchEventListener, publicTouchInfo);
411 else if (touchInfo.GetTouchStatus() == _TOUCH_MOVED)
413 FireFocusListener(*pTouchEventListener, publicTouchInfo);
424 bool ProcessTouchDoublePressed(const _TouchInfo& touchinfo)
426 if (__pTouchManager->GetPointCount() == 1)
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;
436 if (Math::Abs(__previousPressedTime - __currentPressedTime) < DOUBLE_PRESS_TIME)
438 if (Math::Abs(__previousPressedTime - __oldPreviousPressedTime) > DOUBLE_PRESS_TIME)
440 if ((Math::Abs(__previousPressedPoint.x - __currentPressedPoint.x) < DOUBLE_PRESS_MOVE_ALLOWANCE)
441 && (Math::Abs(__previousPressedPoint.y - __currentPressedPoint.y) < DOUBLE_PRESS_MOVE_ALLOWANCE))
443 _TouchInfo touchInfo(0, _TOUCH_DOUBLE_PRESSED, __currentPressedPoint, false, 0);
444 ProcessTouchEvent(touchInfo);
455 void FirePublicListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
457 switch (touchEventInfo.GetTouchStatus())
460 listener.OnTouchPressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
462 case TOUCH_LONG_PRESSED:
463 listener.OnTouchLongPressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
466 listener.OnTouchReleased(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
469 listener.OnTouchMoved(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
471 case TOUCH_DOUBLE_PRESSED:
472 listener.OnTouchDoublePressed(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
475 listener.OnTouchFocusIn(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
477 case TOUCH_FOCUS_OUT:
478 listener.OnTouchFocusOut(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
481 listener.OnTouchCanceled(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
488 void FireFocusListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
490 _ControlManager* pControlManager = _ControlManager::GetInstance();
491 SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
493 Point screenPoint(__pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).x,
494 __pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).y);
496 _Control* pTouchedControl = pControlManager->GetTopmostTouchedControl(screenPoint);
497 SysTryReturnVoidResult(NID_UI, pTouchedControl, E_INVALID_CONDITION, "[E_INVALID_CONDITION] pTouchedControl is null.");
499 if (__pTouchManager->GetFocusedControlSource() != pTouchedControl)
501 if (&(__core) != pTouchedControl)
503 if (__pTouchManager->GetFocusedControlSource() == &(__core))
505 listener.OnTouchFocusOut(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
510 listener.OnTouchFocusIn(__public, touchEventInfo.GetCurrentPosition(), touchEventInfo);
513 __pTouchManager->SetFocusedControlSource(*pTouchedControl);
517 _TouchEventArg* GetTouchEventArgN(const _TouchInfo& touchInfo)
519 FloatPoint startPoint;
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.");
524 startPoint.SetPosition(__pTouchManager->GetStartPoint(touchInfo.GetPointId()).x - __core.GetAbsoluteBoundsF(true).x,
525 __pTouchManager->GetStartPoint(touchInfo.GetPointId()).y - __core.GetAbsoluteBoundsF(true).y);
527 pEventArg->SetTouchPosition(touchInfo.GetPointId(), startPoint.x, startPoint.y,
528 touchInfo.GetCurrentPosition().x, touchInfo.GetCurrentPosition().y);
530 // need to flick distance setting
536 static const int DOUBLE_PRESS_TIME = 500;
537 static const int DOUBLE_PRESS_MOVE_ALLOWANCE = 10;
539 _ListViewImpl& __impl;
542 _TouchManager* __pTouchManager;
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;
553 _ListViewImpl::GetInstance(ListView& listView)
555 return static_cast<_ListViewImpl*>(listView._pControlImpl);
559 _ListViewImpl::GetInstance(const ListView& listView)
561 return static_cast<const _ListViewImpl*>(listView._pControlImpl);
564 _ListViewImpl::_ListViewImpl(ListView* pList, _TableView* pCore)
565 : _ControlImpl(pList, pCore)
566 , __pListItemEvent(null)
568 , __pScrollEvent(null)
569 , __pFastScrollEvent(null)
570 , __pEmptyBitmap(null)
572 , __pAccessibilityElement(null)
573 , __redrawListView(true)
574 , __isOrientationChanged(false)
575 , __needReloadItems(false)
576 , __pPropagatedTouchEventListener(null)
578 GET_COLOR_CONFIG(TABLEVIEW::EMPTY_CONTENTS_TEXT_NORMAL, __emptyTextColor);
581 _ListViewImpl::~_ListViewImpl()
583 delete __pListItemEvent;
584 __pListItemEvent = null;
589 delete __pScrollEvent;
590 __pScrollEvent = null;
592 delete __pFastScrollEvent;
593 __pFastScrollEvent = null;
595 if (__pEmptyBitmap != null)
597 GetCore().DetachChild(*__pEmptyBitmap);
599 delete __pEmptyBitmap;
600 __pEmptyBitmap = null;
603 if (__pEmptyText != null)
605 GetCore().DetachChild(*__pEmptyText);
611 _AccessibilityContainer* pContainer = GetCore().GetAccessibilityContainer();
613 if ((__pAccessibilityElement != null) && (pContainer != null))
615 pContainer->RemoveElement(__pAccessibilityElement);
618 delete __pPropagatedTouchEventListener;
619 __pPropagatedTouchEventListener = null;
623 _ListViewImpl::GetPublicClassName(void) const
625 return "Tizen::Ui::Controls::ListView";
629 _ListViewImpl::GetPublic(void) const
631 return static_cast <const ListView&>(_ControlImpl::GetPublic());
635 _ListViewImpl::GetPublic(void)
637 return static_cast <ListView&>(_ControlImpl::GetPublic());
641 _ListViewImpl::GetCore(void) const
643 return static_cast <const _TableView&>(_ControlImpl::GetCore());
647 _ListViewImpl::GetCore(void)
649 return static_cast <_TableView&>(_ControlImpl::GetCore());
653 _ListViewImpl::CreateListViewImplN(ListView* pControl, bool itemDivider, ListScrollStyle scrollStyle)
655 result r = E_SUCCESS;
656 TableViewScrollBarStyle scrollBarStyle;
660 case SCROLL_STYLE_FADE_OUT:
661 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT;
664 case SCROLL_STYLE_FIXED:
665 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FIXED;
668 case SCROLL_STYLE_FAST_SCROLL:
669 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL;
672 case SCROLL_STYLE_JUMP_TO_TOP:
673 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_JUMP_TO_TOP;
676 case SCROLL_STYLE_THUMB:
677 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_THUMB;
680 case SCROLL_STYLE_FAST_SCROLL_FIXED:
681 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL_FIXED;
685 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_NONE;
689 _TableView* pCore = _TableView::CreateTableViewN(TABLE_VIEW_STYLE_SIMPLE, itemDivider, scrollBarStyle);
691 SysTryReturn(NID_UI_CTRL, (pCore != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
693 _ListViewImpl* pImpl = new (std::nothrow) _ListViewImpl(pControl, pCore);
695 r = CheckConstruction(pCore, pImpl);
696 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), null, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
698 pImpl->__pPropagatedTouchEventListener = new (std::nothrow) _ListViewPropagatedTouchEventListener(*pImpl);
700 if (pImpl->__pPropagatedTouchEventListener != null)
702 pCore->SetPropagatedTouchEventListener(pImpl->__pPropagatedTouchEventListener);
709 _ListViewImpl::SetItemProvider(IListViewItemProvider& provider)
711 result r = E_SUCCESS;
713 _ListViewItemProviderAdaptor* pProviderAdaptor =
714 static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
716 if (pProviderAdaptor != null)
718 IListViewItemProvider* pProvider = pProviderAdaptor->GetItemProvider();
719 if (&provider == pProvider)
725 if (pProviderAdaptor == null)
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.");
731 pProviderAdaptor->SetListViewItemEventListener(*this);
733 r = pProviderAdaptor->SetListWidth(GetBoundsF().width);
734 GetCore().SetItemProviderAdaptor(pProviderAdaptor);
738 pProviderAdaptor->SetItemProvider(provider);
739 r = pProviderAdaptor->SetListWidth(GetBoundsF().width);
744 __redrawListView = true;
746 SetLastResultReturn(r);
750 _ListViewImpl::SetItemProvider(IListViewItemProviderF& provider)
753 result r = E_SUCCESS;
755 _ListViewItemProviderAdaptor* pProviderAdaptor =
756 static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
758 if (pProviderAdaptor != null)
760 IListViewItemProviderF* pProvider = pProviderAdaptor->GetItemProviderF();
761 if (&provider == pProvider)
767 if (pProviderAdaptor == null)
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.");
773 pProviderAdaptor->SetListViewItemEventListener(*this);
775 r = pProviderAdaptor->SetListWidth(GetBoundsF().width);
776 GetCore().SetItemProviderAdaptor(pProviderAdaptor);
780 pProviderAdaptor->SetItemProvider(provider);
781 r = pProviderAdaptor->SetListWidth(GetBoundsF().width);
786 __redrawListView = true;
788 SetLastResultReturn(r);
794 _ListViewImpl::AddListViewItemEventListener(IListViewItemEventListener& listener)
796 result r = E_SUCCESS;
798 if (__pListItemEvent == null)
800 __pListItemEvent = new (std::nothrow) _ListItemEvent();
801 SysTryReturnVoidResult(NID_UI_CTRL, (__pListItemEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
803 r = __pListItemEvent->Construct(GetPublic(), CLASSNAME_LISTVIEW);
804 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Item Event.");
807 __pListItemEvent->AddListener(listener);
809 r = GetCore().AddTableViewItemEventListener(*this);
815 _ListViewImpl::RemoveListViewItemEventListener(IListViewItemEventListener& listener)
817 result r = E_SUCCESS;
819 if (__pListItemEvent != null)
821 r = __pListItemEvent->RemoveListener(listener);
828 _ListViewImpl::AddFastScrollListener(IFastScrollListener& listener)
830 result r = E_SUCCESS;
832 if (__pFastScrollEvent == null)
834 __pFastScrollEvent = new (std::nothrow) _FastScrollEvent();
835 SysTryReturnVoidResult(NID_UI_CTRL, (__pFastScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
837 r = __pFastScrollEvent->Construct(GetPublic());
838 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct FastScroll Event.");
841 __pFastScrollEvent->AddListener(listener);
843 r = GetCore().AddFastScrollListener(*this);
849 _ListViewImpl::RemoveFastScrollListener(IFastScrollListener& listener)
851 result r = E_SUCCESS;
853 if (__pFastScrollEvent != null)
855 r = __pFastScrollEvent->RemoveListener(listener);
862 _ListViewImpl::AddScrollEventListener(IScrollEventListener& listener)
864 result r = E_SUCCESS;
866 if (__pScrollEvent == null)
868 __pScrollEvent = new (std::nothrow) _ScrollEvent();
869 SysTryReturnVoidResult(NID_UI_CTRL, (__pScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
871 r = __pScrollEvent->Construct(GetPublic());
872 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Scroll Event.");
875 __pScrollEvent->AddListener(listener);
877 GetCore().AddScrollEventListener(*this);
883 _ListViewImpl::AddScrollEventListener(IScrollEventListenerF& listener)
885 result r = E_SUCCESS;
887 if (__pScrollEvent == null)
889 __pScrollEvent = new (std::nothrow) _ScrollEvent();
890 SysTryReturnVoidResult(NID_UI_CTRL, (__pScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
892 r = __pScrollEvent->Construct(GetPublic());
893 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Scroll Event.");
896 __pScrollEvent->AddListener(listener);
898 GetCore().AddScrollEventListener(*this);
904 _ListViewImpl::RemoveScrollEventListener(IScrollEventListener& listener)
906 result r = E_SUCCESS;
908 if (__pScrollEvent != null)
910 r = __pScrollEvent->RemoveListener(listener);
917 _ListViewImpl::RemoveScrollEventListener(IScrollEventListenerF& listener)
919 result r = E_SUCCESS;
921 if (__pScrollEvent != null)
923 r = __pScrollEvent->RemoveListener(listener);
930 _ListViewImpl::AddUiLinkEventListener(const IUiLinkEventListener& listener)
932 result r = E_SUCCESS;
934 if (__pLinkEvent == null)
936 __pLinkEvent = _PublicLinkEvent::CreateInstanceN(GetPublic());
937 SysTryReturnVoidResult(NID_UI_CTRL, (__pLinkEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
940 r = __pLinkEvent->AddListener(listener);
947 _ListViewImpl::RemoveUiLinkEventListener(const IUiLinkEventListener& listener)
949 result r = E_SUCCESS;
951 if (__pLinkEvent != null)
953 r = __pLinkEvent->RemoveListener(listener);
960 _ListViewImpl::SetSweepEnabled(bool enable)
962 GetCore().SetSweepEnabled(enable);
964 SetLastResultReturn(E_SUCCESS);
968 _ListViewImpl::SetFastScrollIndex(const String& text, bool useSearchIcon)
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.");
974 SetLastResultReturn(r);
978 _ListViewImpl::GetTopDrawnItemIndex(void) const
980 result r = E_SUCCESS;
984 r = GetCore().GetTopDrawnItemIndex(groupIndex, itemIndex);
991 _ListViewImpl::GetBottomDrawnItemIndex(void) const
993 result r = E_SUCCESS;
997 r = GetCore().GetBottomDrawnItemIndex(groupIndex, itemIndex);
1004 _ListViewImpl::ScrollToItem(int index, ListScrollItemAlignment itemAlignment)
1006 result r = E_SUCCESS;
1008 if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_TOP)
1010 r = GetCore().SetTopDrawnItemIndex(0, index);
1012 else if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_BOTTOM)
1014 r = GetCore().SetBottomDrawnItemIndex(0, index);
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.");
1022 SetLastResultReturn(r);
1026 _ListViewImpl::SetItemChecked(int index, bool check)
1028 return GetCore().SetItemChecked(0, index, check);
1032 _ListViewImpl::IsItemChecked(int index) const
1034 return GetCore().IsItemChecked(0, index);
1038 _ListViewImpl::SetItemEnabled(int index, bool enable)
1040 return GetCore().SetItemEnabled(0, index, enable);
1044 _ListViewImpl::IsItemEnabled(int index) const
1046 return GetCore().IsItemEnabled(0, index);
1050 _ListViewImpl::GetItemCount(void) const
1052 return GetCore().GetItemCountAt(0);
1056 _ListViewImpl::ShowItemDescriptionText(int index)
1058 return SetItemDescriptionTextShowState(index, true);
1062 _ListViewImpl::HideItemDescriptionText(int index)
1064 return SetItemDescriptionTextShowState(index, false);
1068 _ListViewImpl::SetItemDescriptionTextShowState(int index, bool show)
1070 result r = E_SUCCESS;
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.");
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.");
1079 // Save description text show state to provider adaptor
1080 pProviderAdaptor->SetDescriptionTextShowState(index, show);
1082 if (GetCore().FindItem(0, index) != null)
1084 r = GetCore().RefreshTableView(0, index, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1087 SetLastResultReturn(r);
1091 _ListViewImpl::RefreshList(int index, ListRefreshType type)
1093 result r = E_SUCCESS;
1095 if (__needReloadItems)
1100 int itemCount = GetCore().GetItemCountAt(0);
1102 if ((index < 0) || (index > itemCount) || ((type != LIST_REFRESH_TYPE_ITEM_ADD) && (index == itemCount)))
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;
1108 if (type == LIST_REFRESH_TYPE_ITEM_MODIFY)
1110 if (IsContextItemOpened(index))
1112 CloseContextItem(index);
1115 int topGroupIndex = -1;
1116 int topItemIndex = -1;
1117 int bottomGroupIndex = -1;
1118 int bottomItemIndex = -1;
1120 GetCore().GetFirstLoadedItemIndex(topGroupIndex, topItemIndex);
1121 GetCore().GetLastLoadedItemIndex(bottomGroupIndex, bottomItemIndex);
1123 if ((topItemIndex <= index) && (bottomItemIndex >= index))
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;
1131 if (pListViewItem != null && pListViewItem->IsItemSelected())
1133 needChangeEventTarget = true;
1136 if (pListViewItem != null && pListViewItem->IsFocusModeStateEnabled()
1137 && pListViewItem->IsFocused() && pListViewItem->GetRootWindow() && pListViewItem->GetRootWindow()->IsActivated())
1142 if (needChangeEventTarget && (pListViewItem != null))
1144 pListViewItem->GetCurrentStatus(itemStatus);
1145 pListViewItem = null;
1149 GetCore().UnloadItem(0, index);
1151 pListViewItem = static_cast<_ListViewItem*>(GetCore().LoadItem(0, index));
1153 if (needChangeEventTarget && (pListViewItem != null))
1155 pListViewItem->SetCurrentStatus(itemStatus);
1157 _Control* pTarget = static_cast<_Control*>(pListViewItem);
1159 for (int i = 0; i < pListViewItem->GetChildCount(); i++)
1161 if (pListViewItem->GetChild(i)->GetBoundsF().Contains(itemStatus.currentTouchPosition))
1163 pTarget = pListViewItem->GetChild(i);
1167 // change touch event target
1168 pTarget->SetChangingEventTarget(true);
1169 _TouchManager::GetInstance()->SetChangedTouchableTarget(pTarget);
1172 if (itemFocused && pListViewItem && pListViewItem->IsFocusable()
1173 && pListViewItem->GetEnableState() && pListViewItem->GetVisibleState())
1175 pListViewItem->SetFocused(true);
1176 pListViewItem->DrawFocus();
1181 // not yet loaded item
1182 SetLastResultReturn(r);
1187 r = GetCore().RefreshTableView(0, index, static_cast<TableViewRefreshType>(type));
1190 CheckEmptyListShowState();
1195 SetLastResultReturn(r);
1199 _ListViewImpl::RefreshList(int index, int elementId)
1201 if ((index < 0) || (index >= GetCore().GetItemCountAt(0)))
1203 return E_OUT_OF_RANGE;
1206 result r = E_SUCCESS;
1207 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, index));
1209 if (pListViewItem != null)
1211 r = (pListViewItem->RefreshElement(elementId)) ? E_SUCCESS : E_OUT_OF_RANGE;
1214 SetLastResultReturn(r);
1218 _ListViewImpl::UpdateList(bool isRestoreAnnexFocusValue)
1220 __needReloadItems = true;
1222 result r = GetCore().UpdateTableView(isRestoreAnnexFocusValue);
1224 CheckEmptyListShowState();
1228 // API versioning for initial Show() operation
1229 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
1234 __needReloadItems = false;
1236 SetLastResultReturn(r);
1240 _ListViewImpl::SetItemNeedsLazyDeletion(_ListViewItem* pItem)
1242 _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1244 if (pProviderAdaptor != null)
1246 pProviderAdaptor->SetItemNeedsLazyDeletion(pItem);
1251 _ListViewImpl::GetItemIndexFromPosition(const FloatPoint& position) const
1253 int groupIndex = -1;
1256 GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
1262 _ListViewImpl::GetItemIndexFromPosition(const FloatPoint& position, int& itemIndex, int& elementId) const
1264 int groupIndex = -1;
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.");
1270 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1272 if (pListViewItem != null)
1274 FloatPoint originPosition = pListViewItem->GetPositionF();
1275 originPosition.y -= GetCore().GetScrollPosition();
1277 elementId = pListViewItem->GetElementIdFromPosition(FloatPoint(position.x - originPosition.x, position.y - originPosition.y));
1280 SetLastResultReturn(r);
1284 _ListViewImpl::SetItemDividerColor(const Color& color)
1286 return GetCore().SetItemDividerColor(color);
1290 _ListViewImpl::GetItemDividerColor(void) const
1292 return GetCore().GetItemDividerColor();
1296 _ListViewImpl::AdjustLayoutOfEmptyList(void)
1298 FloatDimension listDimension = GetCore().GetSizeF();
1299 FloatDimension emptyBitmap;
1300 FloatDimension emptyText;
1301 FloatPoint bitmapPos;
1303 float totalHeight = 0.0f;
1304 float horizontalSpacing = 0.0f;
1306 if (__pEmptyBitmap != null)
1308 emptyBitmap = __pEmptyBitmap->GetSizeF();
1311 if (__pEmptyText != null)
1313 emptyText = __pEmptyText->GetSizeF();
1315 if (__pEmptyBitmap != null)
1317 GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_HORIZONTAL_SPACING, _CONTROL_ORIENTATION_PORTRAIT, horizontalSpacing);
1321 totalHeight = emptyBitmap.height + horizontalSpacing + emptyText.height;
1323 if ((__pEmptyBitmap != null) && (__pEmptyText != null) && (totalHeight < listDimension.height))
1325 bitmapPos.x = ((_FloatCompare(listDimension.width, emptyBitmap.width)) ? 0.0f : (listDimension.width - emptyBitmap.width) / 2.0f);
1326 bitmapPos.y = (listDimension.height - totalHeight) / 2.0f;
1328 textPos.x = ((_FloatCompare(listDimension.width, emptyText.width)) ? 0.0f : (listDimension.width - emptyText.width) / 2.0f);
1329 textPos.y = bitmapPos.y + emptyBitmap.height + horizontalSpacing;
1333 if (__pEmptyBitmap != null)
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);
1339 if (__pEmptyText != null)
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);
1346 if (__pEmptyBitmap != null)
1348 __pEmptyBitmap->SetPosition(bitmapPos);
1350 if (__pEmptyText != null)
1352 __pEmptyText->SetPosition(textPos);
1355 CheckEmptyListShowState();
1360 _ListViewImpl::CheckEmptyListShowState(void)
1362 bool isEmpty = (GetItemCount() <= 0);
1364 if (__pEmptyBitmap != null)
1366 __pEmptyBitmap->SetVisibleState(isEmpty);
1368 if (__pEmptyText != null)
1370 __pEmptyText->SetVisibleState(isEmpty);
1373 _AccessibilityContainer* pContainer = GetCore().GetAccessibilityContainer();
1375 if (_AccessibilityManager::IsActivated() && (pContainer != null))
1379 if (__pAccessibilityElement == null)
1381 __pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
1383 SysTryReturnVoidResult(NID_UI_CTRL, (__pAccessibilityElement != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1385 __pAccessibilityElement->SetName(L"ListView");
1387 pContainer->RemoveAllElement();
1388 pContainer->AddElement(*__pAccessibilityElement);
1391 Rectangle bounds = GetBounds();
1392 __pAccessibilityElement->SetBounds(Rectangle(0, 0, bounds.width, bounds.height));
1394 String accessibilityLable;
1396 if (__pEmptyBitmap != null)
1398 __pEmptyBitmap->GetAccessibilityContainer()->Activate(false);
1400 accessibilityLable += L"Image, ";
1402 if (__pEmptyText != null)
1404 __pEmptyText->GetAccessibilityContainer()->Activate(false);
1406 accessibilityLable += __pEmptyText->GetText();
1407 accessibilityLable += L", ";
1410 accessibilityLable += L"No items";
1412 __pAccessibilityElement->SetLabel(accessibilityLable);
1416 if (__pAccessibilityElement != null)
1418 if (pContainer->RemoveElement(*__pAccessibilityElement) != E_SUCCESS)
1420 delete __pAccessibilityElement;
1422 __pAccessibilityElement = null;
1429 _ListViewImpl::SetBitmapOfEmptyList(const Bitmap* pBitmap)
1431 if (pBitmap == null)
1433 if (__pEmptyBitmap != null)
1435 GetCore().DetachChild(*__pEmptyBitmap);
1437 delete __pEmptyBitmap;
1438 __pEmptyBitmap = null;
1443 if (__pEmptyBitmap == null)
1445 __pEmptyBitmap = _Label::CreateLabelN();
1446 SysTryReturn(NID_UI_CTRL, (__pEmptyBitmap != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1448 __pEmptyBitmap->SetVisibleState(false);
1449 __pEmptyBitmap->SetMargin(0.0f, 0.0f);
1451 GetCore().AttachChild(*__pEmptyBitmap);
1454 __pEmptyBitmap->SetSize(FloatDimension(pBitmap->GetWidthF(), pBitmap->GetHeightF()));
1455 __pEmptyBitmap->SetBackgroundColor(Color(0, 0, 0, 0));
1456 __pEmptyBitmap->SetBackgroundBitmap(*pBitmap);
1459 AdjustLayoutOfEmptyList();
1461 SetLastResultReturn(E_SUCCESS);
1465 _ListViewImpl::SetTextOfEmptyList(const String& text)
1469 if (__pEmptyText != null)
1471 GetCore().DetachChild(*__pEmptyText);
1473 delete __pEmptyText;
1474 __pEmptyText = null;
1479 if (__pEmptyText == null)
1481 __pEmptyText = _Label::CreateLabelN();
1482 SysTryReturn(NID_UI_CTRL, (__pEmptyText != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1484 __pEmptyText->SetVisibleState(false);
1485 __pEmptyText->SetMargin(0.0f, 0.0f);
1487 GetCore().AttachChild(*__pEmptyText);
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()));
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()));
1498 pText->AppendElement(*pSimpleText);
1500 float textSize = 0.0f;
1501 GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, textSize);
1504 font.Construct(GetFont(), FONT_STYLE_PLAIN, textSize);
1505 pText->SetFont(&font, 0, pText->GetTextLength());
1507 FloatDimension listDimension = GetCore().GetSizeF();
1509 pText->SetBounds(FloatRectangle(0.0f, 0.0f, listDimension.width, 1.0f));
1512 FloatDimension labelDimension = pText->GetTextExtentF(0, pText->GetTextLength());
1513 labelDimension.height = pText->GetTotalHeightF();
1515 if (labelDimension.width > listDimension.width)
1517 pText->SetBounds(FloatRectangle(0.0f, 0.0f, listDimension.width, 1.0f));
1520 float labelHeight = pText->GetTotalHeightF();
1522 labelDimension.width = listDimension.width;
1523 labelDimension.height = ((listDimension.height < labelHeight) ? listDimension.height : labelHeight);
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);
1536 AdjustLayoutOfEmptyList();
1538 SetLastResultReturn(E_SUCCESS);
1542 _ListViewImpl::GetTextOfEmptyList(void) const
1544 return ((__pEmptyText != null) ? __pEmptyText->GetText() : String());
1548 _ListViewImpl::SetTextColorOfEmptyList(const Color& color)
1550 __emptyTextColor = color;
1552 if (__pEmptyText != null)
1554 __pEmptyText->SetTextColor(color);
1557 SetLastResultReturn(E_SUCCESS);
1561 _ListViewImpl::GetTextColorOfEmptyList(void) const
1563 return __emptyTextColor;
1567 _ListViewImpl::SetListBackgroundColor(const Color& color)
1569 SetBackgroundColor(color);
1571 SetLastResultReturn(E_SUCCESS);
1575 _ListViewImpl::SetBackgroundBitmap(const Bitmap* pBitmap)
1577 GetCore().SetBackgroundBitmap(const_cast<Bitmap*>(pBitmap));
1578 GetCore().SetBackgroundBitmapStretch(true);
1580 SetLastResultReturn(E_SUCCESS);
1584 _ListViewImpl::BeginReorderingMode(void)
1586 result r = GetCore().SetReorderModeEnabled(true);
1588 SetLastResultReturn(r);
1592 _ListViewImpl::EndReorderingMode(void)
1594 result r = GetCore().SetReorderModeEnabled(false);
1596 SetLastResultReturn(r);
1600 _ListViewImpl::IsInReorderingMode(void) const
1602 return GetCore().IsReorderModeEnabled();
1606 _ListViewImpl::SetScrollInputMode(ScrollInputMode mode)
1608 GetCore().SetScrollInputMode(mode);
1612 _ListViewImpl::GetScrollInputMode(void) const
1614 return GetCore().GetScrollInputMode();
1618 _ListViewImpl::OpenContextItem(int itemIndex)
1620 return GetCore().OpenContextItem(0, itemIndex);
1624 _ListViewImpl::CloseContextItem(int itemIndex)
1626 return GetCore().CloseContextItem(0, itemIndex);
1630 _ListViewImpl::IsContextItemOpened(int itemIndex) const
1632 return GetCore().IsContextItemOpened(0, itemIndex);
1636 _ListViewImpl::OnListViewContextItemStateChanged(_Control& source, int groupIndex, int itemIndex, int elementId,
1637 ListContextItemStatus status)
1639 if (__pListItemEvent != null)
1641 CloseContextItem(itemIndex);
1643 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1645 SetItemNeedsLazyDeletion(pListViewItem);
1647 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, elementId, 0, 0, NOTIFY_TYPE_SELCTED_CONTEXT_ITEM);
1648 __pListItemEvent->Fire(*pArg);
1650 SetItemNeedsLazyDeletion(null);
1655 _ListViewImpl::OnTableViewItemStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
1657 if (__pListItemEvent != null)
1659 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(pItem);
1661 if (pListViewItem != null)
1663 SetItemNeedsLazyDeletion(pListViewItem);
1665 _ListViewItemStateChangedInfo itemInfo;
1666 pListViewItem->GetLastStateChangedInfo(itemInfo);
1668 if ((__pLinkEvent != null) && (itemInfo.pUiLinkInfo != null))
1670 IEventArg* pLinkEventArg = _PublicLinkEvent::CreateLinkEventArgN(itemInfo.pUiLinkInfo->textInfo,
1671 itemInfo.pUiLinkInfo->linkType, itemInfo.pUiLinkInfo->linkInfo);
1673 SysTryReturnVoidResult(NID_UI_CTRL, (pLinkEventArg != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _LinkEventArg.");
1674 __pLinkEvent->Fire(*pLinkEventArg);
1679 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, itemInfo.elementId, 0, 0, static_cast<NotifyType>(status));
1680 __pListItemEvent->Fire(*pArg);
1683 pListViewItem->ClearLastStateChangedInfo();
1685 SetItemNeedsLazyDeletion(null);
1691 _ListViewImpl::OnTableViewContextItemActivationStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pContextItem, bool activated)
1693 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1695 if (pListViewItem != null)
1697 pListViewItem->SetContextItemActivationState(activated);
1702 _ListViewImpl::OnTableViewItemReordered(_TableView& tableView, int itemIndexFrom, int itemIndexTo)
1704 if (__pListItemEvent != null)
1706 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndexFrom, itemIndexTo, 0, 0, NOTIFY_TYPE_REORDERED_ITEM);
1707 __pListItemEvent->Fire(*pArg);
1712 _ListViewImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
1714 if (__pListItemEvent != null)
1716 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1718 SetItemNeedsLazyDeletion(pListViewItem);
1720 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, direction, 0, 0, NOTIFY_TYPE_SWEPT_ITEM);
1721 __pListItemEvent->Fire(*pArg);
1723 SetItemNeedsLazyDeletion(null);
1728 _ListViewImpl::OnScrollEndReached(_Control& source, ScrollEndEvent type)
1730 if (__pScrollEvent != null)
1732 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), type);
1733 result r = GetLastResult();
1734 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1736 __pScrollEvent->Fire(*pEventArg);
1741 _ListViewImpl::OnScrollPositionChanged(_Control& source, float scrollPosition)
1743 if (__pScrollEvent != null)
1745 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), scrollPosition);
1746 result r = GetLastResult();
1747 SysTryReturnVoidResult(NID_UI_CTRL, (pEventArg != null), r, "[%s] Propagating.", GetErrorMessage(r));
1749 __pScrollEvent->Fire(*pEventArg);
1754 _ListViewImpl::OnScrollStopped(_Control& source)
1756 if (__pScrollEvent != null)
1758 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic());
1759 result r = GetLastResult();
1760 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1762 __pScrollEvent->Fire(*pEventArg);
1767 _ListViewImpl::OnUiFastScrollIndexSelected(_Control& source, _FastScrollIndex& index)
1769 if (__pFastScrollEvent != null)
1771 String* pIndexText = index.GetIndexText();
1772 if (pIndexText != null)
1774 _FastScrollEventArg* pEventArg = new (std::nothrow) _FastScrollEventArg(GetPublic(), *pIndexText);
1775 __pFastScrollEvent->Fire(*pEventArg);
1781 _ListViewImpl::OnDraw(void)
1783 _ControlImpl::OnDraw();
1785 if (__redrawListView)
1787 CheckEmptyListShowState();
1788 __redrawListView = false;
1793 _ListViewImpl::OnChangeLayout(_ControlOrientation orientation)
1795 __isOrientationChanged = true;
1797 if (GetCore().IsFocusModeStateEnabled() && GetCore().GetRootWindow() && GetCore().GetRootWindow()->IsActivated())
1799 GetCore().SetFocusDuringOrientationChange();
1802 _ControlImpl::OnChangeLayout(orientation);
1806 _ListViewImpl::OnBoundsChanged(void)
1808 _ControlImpl::OnBoundsChanged();
1810 if (__pEmptyBitmap != null)
1812 SetBitmapOfEmptyList(__pEmptyBitmap->GetBackgroundBitmap());
1814 if (__pEmptyText != null)
1816 SetTextOfEmptyList(__pEmptyText->GetText());
1819 if (__isOrientationChanged)
1821 __isOrientationChanged = false;
1823 if (GetCore().IsTableViewFocused() && GetCore().IsFocusModeStateEnabled()
1824 && GetCore().GetRootWindow() && GetCore().GetRootWindow()->IsActivated())
1837 _ListViewImpl::OnFontChanged(Font* pFont)
1839 String fontName = GetFont();
1840 _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1842 if (__pEmptyText != null)
1844 __pEmptyText->SetFont(fontName);
1845 SetTextOfEmptyList(__pEmptyText->GetText());
1848 if (pProviderAdaptor != null)
1850 pProviderAdaptor->SetItemFont(fontName);
1853 int firstGroup = -1;
1858 GetCore().GetFirstLoadedItemIndex(firstGroup, firstItem);
1859 GetCore().GetLastLoadedItemIndex(lastGroup, lastItem);
1861 firstItem = ((firstItem == -1) ? 0 : firstItem);
1863 for (int i = firstItem; i <= lastItem; i++)
1865 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, i));
1867 if (pListViewItem != null)
1869 pListViewItem->SetFont(fontName);
1875 _ListViewImpl::OnFontInfoRequested(unsigned long& style, int& size)
1877 float textSize = 0.0f;
1878 OnFontInfoRequested(style, textSize);
1880 size = _CoordinateSystemUtils::ConvertToInteger(textSize);
1884 _ListViewImpl::OnFontInfoRequested(unsigned long& style, float& size)
1886 GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, size);
1887 style = FONT_STYLE_PLAIN;
1891 _ListViewImpl::GetCurrentTouchPosition(void)
1893 FloatPoint currentTouchPos = _TouchManager::GetInstance()->GetScreenPoint(0);
1894 FloatRectangle bounds = GetCore().GetAbsoluteBoundsF(true);
1896 currentTouchPos.x -= bounds.x;
1897 currentTouchPos.y -= bounds.y;
1899 return currentTouchPos;
1903 _ListViewImpl::OnTouchEventListenerAdded(void)
1909 _ListViewImpl::OnTouchEventListenerRemoved(void)
1915 _ListViewImpl::FireListViewItemLongPressedEvent(void)
1917 if (__pListItemEvent != null)
1922 if (GetItemIndexFromPosition(GetCurrentTouchPosition(), itemIndex, elementId) == E_SUCCESS)
1924 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1926 if ((pListViewItem != null) && (!pListViewItem->IsContextItem()))
1928 SetItemNeedsLazyDeletion(pListViewItem);
1930 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, elementId, 0, 0, NOTIFY_TYPE_LONG_PRESSED_ITEM);
1931 __pListItemEvent->Fire(*pArg);
1933 SetItemNeedsLazyDeletion(null);
1939 class _ListViewMaker
1940 : public _UiBuilderControlMaker
1943 _ListViewMaker(_UiBuilder* uibuilder)
1944 : _UiBuilderControlMaker(uibuilder){};
1946 virtual ~_ListViewMaker(){};
1948 static _UiBuilderControlMaker*
1949 GetInstance(_UiBuilder* uibuilder)
1951 _ListViewMaker* pListViewMaker = new (std::nothrow) _ListViewMaker(uibuilder);
1952 return pListViewMaker;
1957 Make(_UiBuilderControl* pControl)
1959 result r = E_SYSTEM;
1960 _UiBuilderControlLayout* pControlProperty = null;
1961 ListView* pListView = null;
1962 FloatRectangle rect;
1963 String elementString;
1965 ListScrollStyle scrollStyle = SCROLL_STYLE_FADE_OUT;
1966 ScrollInputMode scrollInputMode = SCROLL_INPUT_MODE_ALLOW_ANY_DIRECTION;
1968 bool hasItemDivider = true;
1970 bool isSweepEnabled = false;
1973 GetProperty(pControl, &pControlProperty);
1974 if (pControlProperty == null)
1979 pListView = new (std::nothrow) ListView();
1980 if (pListView == null)
1985 rect = pControlProperty->GetRectF();
1988 if (pControl->GetElement(L"itemDivider", elementString))
1990 if (elementString.Equals(L"true", false))
1992 hasItemDivider = true;
1996 hasItemDivider = false;
2000 if (pControl->GetElement(L"listScrollStyle", elementString))
2002 if (elementString.Equals(L"SCROLL_STYLE_FIXED", false))
2004 scrollStyle = SCROLL_STYLE_FIXED;
2006 else if (elementString.Equals(L"SCROLL_STYLE_FAST_SCROLL", false))
2008 scrollStyle = SCROLL_STYLE_FAST_SCROLL;
2010 else if (elementString.Equals(L"SCROLL_STYLE_JUMP_TO_TOP", false))
2012 scrollStyle = SCROLL_STYLE_JUMP_TO_TOP;
2014 else if (elementString.Equals(L"SCROLL_STYLE_THUMB", false))
2016 scrollStyle = SCROLL_STYLE_THUMB;
2019 else if (pControl->GetElement(L"fastScroll", elementString))
2021 if (elementString.Equals(L"true", false))
2023 scrollStyle = SCROLL_STYLE_FAST_SCROLL;
2027 r = pListView->Construct(rect, hasItemDivider, scrollStyle);
2028 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2030 // Set BackgroundsBitmap
2031 if (pControl->GetElement("backgroundBitmapPath", elementString))
2033 Bitmap* pBackgroundBitmap = null;
2034 pBackgroundBitmap = LoadBitmapN(elementString);
2035 if (pBackgroundBitmap != null)
2037 r = pListView->SetBackgroundBitmap(pBackgroundBitmap);
2038 delete pBackgroundBitmap;
2039 pBackgroundBitmap = null;
2041 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2046 if (pControl->GetElement(L"textOfEmptyList", elementString))
2048 r = pListView->SetTextOfEmptyList(elementString);
2049 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2052 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
2054 ConvertStringToColor(elementString, color);
2055 r = pListView->SetTextColorOfEmptyList(color);
2056 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2059 if (pControl->GetElement(L"bitmapPathOfEmptyList", elementString))
2061 Bitmap* pBackgroundBitmap = null;
2062 pBackgroundBitmap = LoadBitmapN(elementString); //__image->DecodeN(path,BITMAP_PIXEL_FORMAT_RGB565);
2063 if (pBackgroundBitmap != null)
2065 r = pListView->SetBitmapOfEmptyList(pBackgroundBitmap);
2066 delete pBackgroundBitmap;
2067 pBackgroundBitmap = null;
2069 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2073 if (pControl->GetElement(L"backgroundColorOpacity", elementString) || pControl->GetElement(L"BGColorOpacity", elementString))
2075 Base::Integer::Parse(elementString, opacity);
2078 if (pControl->GetElement(L"backgroundColor", elementString) || pControl->GetElement(L"BGColor", elementString))
2080 ConvertStringToColor32(elementString, opacity, color);
2081 r = pListView->SetBackgroundColor(color);
2082 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2085 if (pControl->GetElement(L"itemDividerColor", elementString))
2087 ConvertStringToColor(elementString, color);
2088 r = pListView->SetItemDividerColor(color);
2089 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2092 if (pControl->GetElement(L"sweepEnabled", elementString))
2094 if (elementString.Equals(L"true", false))
2096 isSweepEnabled = true;
2100 isSweepEnabled = false;
2103 r = pListView->SetSweepEnabled(isSweepEnabled);
2104 SysTryCatch(NID_UI, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
2107 // scroll Input Mode
2108 if (pControl->GetElement(L"scrollInputMode", elementString))
2110 if (elementString.Equals(L"SCROLL_INPUT_MODE_RESTRICT_TO_INITIAL_DIRECTION", false))
2112 scrollInputMode = SCROLL_INPUT_MODE_RESTRICT_TO_INITIAL_DIRECTION;
2115 pListView->SetScrollInputMode(scrollInputMode);
2126 }; // _ListViewMaker
2128 _ListViewRegister::_ListViewRegister()
2130 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
2131 pUiBuilderControlTableManager->RegisterControl(L"ListView", _ListViewMaker::GetInstance);
2134 _ListViewRegister::~_ListViewRegister()
2136 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
2137 pUiBuilderControlTableManager->UnregisterControl(L"ListView");
2140 static _ListViewRegister ListViewRegisterToUIbuilder;
2141 }}} // Tizen::Ui::Controls