2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
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 <FGrp_TextTextSimple.h>
27 #include "FApp_AppInfo.h"
28 #include "FUi_ResourceManager.h"
29 #include "FUi_TouchManager.h"
30 #include "FUi_UiBuilder.h"
31 #include "FUiCtrl_FastScrollEvent.h"
32 #include "FUiCtrl_FastScrollEventArg.h"
33 #include "FUiCtrl_Label.h"
34 #include "FUiCtrl_ListItemEvent.h"
35 #include "FUiCtrl_ListItemEventArg.h"
36 #include "FUiCtrl_ListViewImpl.h"
37 #include "FUiCtrl_ListViewItem.h"
38 #include "FUiCtrl_ListViewItemProviderAdaptor.h"
39 #include "FUiCtrl_PublicLinkEvent.h"
40 #include "FUiCtrl_ScrollEvent.h"
41 #include "FUiCtrl_ScrollEventArg.h"
43 #ifdef MEMORY_LEAK_CHECK
44 #include "mem_leak_check.h"
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Collection;
49 using namespace Tizen::Base::Runtime;
50 using namespace Tizen::Graphics;
51 using namespace Tizen::Graphics::_Text;
53 namespace Tizen { namespace Ui { namespace Controls
57 _ListViewImpl::GetInstance(ListView& listView)
59 return static_cast<_ListViewImpl*>(listView._pControlImpl);
63 _ListViewImpl::GetInstance(const ListView& listView)
65 return static_cast<const _ListViewImpl*>(listView._pControlImpl);
68 _ListViewImpl::_ListViewImpl(ListView* pList, _TableView* pCore)
69 : _ControlImpl(pList, pCore)
70 , __pListItemEvent(null)
72 , __pScrollEvent(null)
73 , __pFastScrollEvent(null)
74 , __pEmptyBitmap(null)
76 , __redrawListView(true)
77 , __pItemNeedsLazyDeletion(null)
80 GET_COLOR_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_NORMAL, __emptyTextColor);
83 _ListViewImpl::~_ListViewImpl()
85 if (__pListItemEvent != null)
87 //__pListItemEvent->RemoveListener(*this);
89 delete __pListItemEvent;
90 __pListItemEvent = null;
93 if (__pLinkEvent != null)
95 //__pLinkEvent->RemoveListener(*this);
101 if (__pScrollEvent != null)
103 //__pScrollEvent->RemoveListener(*this);
105 delete __pScrollEvent;
106 __pScrollEvent = null;
109 if (__pFastScrollEvent != null)
111 //__pFastScrollEvent->RemoveListener(*this);
113 delete __pFastScrollEvent;
114 __pFastScrollEvent = null;
117 if (__pEmptyBitmap != null)
119 GetCore().DetachChild(*__pEmptyBitmap);
121 delete __pEmptyBitmap;
122 __pEmptyBitmap = null;
125 if (__pEmptyText != null)
127 GetCore().DetachChild(*__pEmptyText);
135 _ListViewImpl::GetPublicClassName(void) const
137 return "Controls::ListView";
141 _ListViewImpl::GetPublic(void) const
143 return static_cast <const ListView&>(_ControlImpl::GetPublic());
147 _ListViewImpl::GetPublic(void)
149 return static_cast <ListView&>(_ControlImpl::GetPublic());
153 _ListViewImpl::GetCore(void) const
155 return static_cast <const _TableView&>(_ControlImpl::GetCore());
159 _ListViewImpl::GetCore(void)
161 return static_cast <_TableView&>(_ControlImpl::GetCore());
165 _ListViewImpl::CreateListViewImplN(ListView* pControl, bool itemDivider, ListScrollStyle scrollStyle)
167 result r = E_SUCCESS;
168 TableViewScrollBarStyle scrollBarStyle;
172 case SCROLL_STYLE_FADE_OUT:
173 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT;
175 case SCROLL_STYLE_FIXED:
176 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FIXED;
178 case SCROLL_STYLE_FAST_SCROLL:
179 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_FAST_SCROLL;
181 case SCROLL_STYLE_JUMP_TO_TOP:
182 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_JUMP_TO_TOP;
184 case SCROLL_STYLE_THUMB:
185 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_THUMB;
188 scrollBarStyle = TABLE_VIEW_SCROLL_BAR_STYLE_NONE;
192 _TableView* pCore = _TableView::CreateTableViewN(TABLE_VIEW_STYLE_SIMPLE, itemDivider, scrollBarStyle);
194 SysTryReturn(NID_UI_CTRL, (pCore != null), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
196 _ListViewImpl* pImpl = new (std::nothrow) _ListViewImpl(pControl, pCore);
198 r = CheckConstruction(pCore, pImpl);
199 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), null, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
205 _ListViewImpl::SetItemProvider(IListViewItemProvider& provider)
207 result r = E_SUCCESS;
209 _ListViewItemProviderAdaptor* pProviderAdaptor =
210 static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
212 if (pProviderAdaptor == null)
214 pProviderAdaptor = new (std::nothrow) _ListViewItemProviderAdaptor(provider);
215 SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
216 "[E_OUT_OF_MEMORY] The memory is insufficient.");
218 pProviderAdaptor->SetListViewItemEventListener(*this);
220 r = pProviderAdaptor->SetListWidth(GetCore().GetBounds().width);
221 GetCore().SetItemProviderAdaptor(pProviderAdaptor);
225 pProviderAdaptor->SetItemProvider(provider);
226 r = pProviderAdaptor->SetListWidth(GetCore().GetBounds().width);
231 __redrawListView = true;
233 SetLastResultReturn(r);
237 _ListViewImpl::AddListViewItemEventListener(IListViewItemEventListener& listener)
239 result r = E_SUCCESS;
241 if (__pListItemEvent == null)
243 __pListItemEvent = new (std::nothrow) _ListItemEvent();
244 SysTryReturnVoidResult(NID_UI_CTRL, (__pListItemEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
246 r = __pListItemEvent->Construct(GetPublic(), CLASSNAME_LISTVIEW);
247 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Item Event.");
250 __pListItemEvent->AddListener(listener);
252 r = GetCore().AddTableViewItemEventListener(*this);
258 _ListViewImpl::RemoveListViewItemEventListener(IListViewItemEventListener& listener)
260 result r = E_SUCCESS;
262 if (__pListItemEvent != null)
264 r = __pListItemEvent->RemoveListener(listener);
271 _ListViewImpl::AddFastScrollListener(IFastScrollListener& listener)
273 result r = E_SUCCESS;
275 if (__pFastScrollEvent == null)
277 __pFastScrollEvent = new (std::nothrow) _FastScrollEvent();
278 SysTryReturnVoidResult(NID_UI_CTRL, (__pFastScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
280 r = __pFastScrollEvent->Construct(GetPublic());
281 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct FastScroll Event.");
284 __pFastScrollEvent->AddListener(listener);
286 r = GetCore().AddFastScrollListener(*this);
292 _ListViewImpl::RemoveFastScrollListener(IFastScrollListener& listener)
294 result r = E_SUCCESS;
296 if (__pFastScrollEvent != null)
298 r = __pFastScrollEvent->RemoveListener(listener);
305 _ListViewImpl::AddScrollEventListener(IScrollEventListener& listener)
307 result r = E_SUCCESS;
309 if (__pScrollEvent == null)
311 __pScrollEvent = new (std::nothrow) _ScrollEvent();
312 SysTryReturnVoidResult(NID_UI_CTRL, (__pScrollEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
314 r = __pScrollEvent->Construct(GetPublic());
315 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, "[E_SYSTEM] Unable to construct Scroll Event.");
318 __pScrollEvent->AddListener(listener);
320 GetCore().AddScrollEventListener(*this);
326 _ListViewImpl::RemoveScrollEventListener(IScrollEventListener& listener)
328 result r = E_SUCCESS;
330 if (__pScrollEvent != null)
332 r = __pScrollEvent->RemoveListener(listener);
339 _ListViewImpl::AddUiLinkEventListener(const IUiLinkEventListener& listener)
341 result r = E_SUCCESS;
343 if (__pLinkEvent == null)
345 __pLinkEvent = _PublicLinkEvent::CreateInstanceN(GetPublic());
346 SysTryReturnVoidResult(NID_UI_CTRL, (__pLinkEvent != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
349 r = __pLinkEvent->AddListener(listener);
356 _ListViewImpl::RemoveUiLinkEventListener(const IUiLinkEventListener& listener)
358 result r = E_SUCCESS;
360 if (__pLinkEvent != null)
362 r = __pLinkEvent->RemoveListener(listener);
369 _ListViewImpl::SetSweepEnabled(bool enable)
371 GetCore().SetSweepEnabled(enable);
373 SetLastResultReturn(E_SUCCESS);
377 _ListViewImpl::SetFastScrollIndex(const String& text, bool useSearchIcon)
379 result r = GetCore().SetFastScrollIndex(text, useSearchIcon);
380 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS) || (r == E_SYSTEM), E_INVALID_STATE, E_INVALID_STATE,
381 "[E_INVALID_STATE] This instance is in an invalid state.");
383 SetLastResultReturn(r);
387 _ListViewImpl::GetTopDrawnItemIndex(void) const
392 GetCore().GetTopDrawnItemIndex(groupIndex, itemIndex);
398 _ListViewImpl::GetBottomDrawnItemIndex(void) const
403 GetCore().GetBottomDrawnItemIndex(groupIndex, itemIndex);
409 _ListViewImpl::ScrollToItem(int index, ListScrollItemAlignment itemAlignment)
411 result r = E_SUCCESS;
413 if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_TOP)
415 r = GetCore().SetTopDrawnItemIndex(0, index);
417 else if (itemAlignment == LIST_SCROLL_ITEM_ALIGNMENT_BOTTOM)
419 r = GetCore().SetBottomDrawnItemIndex(0, index);
423 SysTryReturn(NID_UI_CTRL, false, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
424 "[E_OUT_OF_RANGE] The specified itemAlignment is out of range.");
427 SetLastResultReturn(r);
431 _ListViewImpl::SetItemChecked(int index, bool check)
433 return GetCore().SetItemChecked(0, index, check);
437 _ListViewImpl::IsItemChecked(int index) const
439 return GetCore().IsItemChecked(0, index);
443 _ListViewImpl::SetItemEnabled(int index, bool enable)
445 return GetCore().SetItemEnabled(0, index, enable);
449 _ListViewImpl::IsItemEnabled(int index) const
451 return GetCore().IsItemEnabled(0, index);
455 _ListViewImpl::GetItemCount(void) const
457 return GetCore().GetItemCountAt(0);
461 _ListViewImpl::ShowItemDescriptionText(int index)
463 return SetItemDescriptionTextShowState(index, true);
467 _ListViewImpl::HideItemDescriptionText(int index)
469 return SetItemDescriptionTextShowState(index, false);
473 _ListViewImpl::SetItemDescriptionTextShowState(int index, bool show)
475 result r = E_SUCCESS;
477 SysTryReturn(NID_UI_CTRL, (index >= 0) && (index < GetItemCount()), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
478 "[E_OUT_OF_RANGE] The specified index is out of range.");
480 _ListViewItemProviderAdaptor* pProviderAdaptor =
481 static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
482 SysTryReturn(NID_UI_CTRL, (pProviderAdaptor != null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] _ListItemProviderAdaptor is not set.");
484 // Save description text show state to provider adaptor
485 pProviderAdaptor->SetDescriptionTextShowState(index, show);
487 if (GetCore().FindItem(0, index) != null)
489 r = GetCore().RefreshTableView(0, index, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
492 SetLastResultReturn(r);
496 _ListViewImpl::RefreshList(int index, ListRefreshType type)
498 result r = E_SUCCESS;
500 int itemCount = GetCore().GetItemCountAt(0);
502 if ((index < 0) || (index > itemCount) ||
503 ((type != LIST_REFRESH_TYPE_ITEM_ADD) && (index == itemCount)))
505 SysLogException(NID_UI_CTRL, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
506 return E_OUT_OF_RANGE;
509 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, index));
511 // for lazy delete item
512 if ((__pItemNeedsLazyDeletion != null) && (type != LIST_REFRESH_TYPE_ITEM_ADD))
514 if (__pItemNeedsLazyDeletion == pListViewItem)
516 _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
518 if (pProviderAdaptor != null)
520 pProviderAdaptor->SetItemNeedsLazyDeletion(__pItemNeedsLazyDeletion);
525 if ((__pItemSwept != null) && (type != LIST_REFRESH_TYPE_ITEM_ADD))
527 if (__pItemSwept == pListViewItem)
529 GetCore().ResetSweepItem();
533 if (type == LIST_REFRESH_TYPE_ITEM_MODIFY)
535 int topGroupIndex = -1;
536 int topItemIndex = -1;
537 int bottomGroupIndex = -1;
538 int bottomItemIndex = -1;
540 GetCore().GetFirstLoadedItemIndex(topGroupIndex, topItemIndex);
541 GetCore().GetLastLoadedItemIndex(bottomGroupIndex, bottomItemIndex);
543 if ((topItemIndex <= index) && (bottomItemIndex >= index))
545 TableViewItemDrawingStatus itemDrawingStatus = TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL;
546 bool itemSelected = false;
547 Point touchPosition(-1, -1);
549 if (pListViewItem != null)
551 itemDrawingStatus = pListViewItem->GetDrawingStatus();
552 itemSelected = pListViewItem->GetSelectionState();
553 touchPosition = pListViewItem->GetLastTouchPressedPosition();
555 pListViewItem = null;
558 GetCore().UnloadItem(0, index);
559 GetCore().LoadItem(0, index);
561 pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, index));
563 if ((pListViewItem != null) && (itemDrawingStatus != TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL))
565 pListViewItem->SetDrawingStatus(itemDrawingStatus);
566 pListViewItem->SetSelectionState(itemSelected);
567 pListViewItem->SetLastTouchPressedPosition(touchPosition);
570 pListViewItem->Draw();
571 pListViewItem->Show();
573 _Control* target = static_cast<_Control*>(pListViewItem);
575 for (int i = 0; i < pListViewItem->GetChildCount(); i++)
577 if (pListViewItem->GetChild(i)->GetBounds().Contains(touchPosition))
579 target = pListViewItem->GetChild(i);
585 target->SetChangingEventTarget(true);
589 pListViewItem->SetDrawingStatus(TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
590 pListViewItem->SetSelectionState(false);
596 // not yet loaded item
597 SetLastResultReturn(r);
602 r = GetCore().RefreshTableView(0, index, static_cast<TableViewRefreshType>(type));
605 CheckEmptyListShowState();
610 SetLastResultReturn(r);
614 _ListViewImpl::RefreshList(int index, int elementId)
616 if ((index < 0) || (index >= GetCore().GetItemCountAt(0)))
618 return E_OUT_OF_RANGE;
621 result r = E_SUCCESS;
622 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, index));
624 if (pListViewItem != null)
626 r = (pListViewItem->RefreshElement(elementId)) ? E_SUCCESS : E_OUT_OF_RANGE;
629 SetLastResultReturn(r);
633 _ListViewImpl::UpdateList(void)
635 // for lazy delete item
636 if (__pItemNeedsLazyDeletion != null)
638 _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
640 if (pProviderAdaptor != null)
642 pProviderAdaptor->SetItemNeedsLazyDeletion(__pItemNeedsLazyDeletion);
646 result r = GetCore().UpdateTableView();
648 CheckEmptyListShowState();
652 // API versioning for initial Show() operation
653 if (Tizen::App::_AppInfo::GetApiVersion() == _API_VERSION_2_0 && Tizen::App::_AppInfo::IsOspCompat())
658 SetLastResultReturn(r);
662 _ListViewImpl::GetItemIndexFromPosition(const Point& position) const
667 GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
673 _ListViewImpl::GetItemIndexFromPosition(const Point& position, int& itemIndex, int& elementId) const
678 result r = GetCore().GetItemIndexFromPosition(position, groupIndex, itemIndex);
679 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] There is no item at the specified position.");
681 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
683 if (pListViewItem != null)
685 Point originPosition = pListViewItem->GetPosition();
686 originPosition.y -= GetCore().GetScrollPosition();
688 elementId = pListViewItem->GetElementIdFromPosition(Point(position.x - originPosition.x, position.y - originPosition.y));
691 SetLastResultReturn(r);
695 _ListViewImpl::SetItemDividerColor(const Color& color)
697 return GetCore().SetItemDividerColor(color);
701 _ListViewImpl::GetItemDividerColor(void) const
703 return GetCore().GetItemDividerColor();
707 _ListViewImpl::AdjustLayoutOfEmptyList(void)
709 Dimension listDimension = GetCore().GetSize();
710 Dimension emptyBitmap;
716 if (__pEmptyBitmap != null)
718 emptyBitmap = __pEmptyBitmap->GetSize();
720 if (__pEmptyText != null)
722 emptyText = __pEmptyText->GetSize();
725 totalHeight = emptyBitmap.height + emptyText.height;
727 if ((__pEmptyBitmap != null) && (__pEmptyText != null) && (totalHeight < listDimension.height))
729 bitmapPos.x = ((listDimension.width == emptyBitmap.width) ? 0 : (listDimension.width - emptyBitmap.width) / 2);
730 bitmapPos.y = (listDimension.height - totalHeight) / 2;
732 textPos.x = ((listDimension.width == emptyText.width) ? 0 : (listDimension.width - emptyText.width) / 2);
733 textPos.y = bitmapPos.y + emptyBitmap.height;
737 if (__pEmptyBitmap != null)
739 bitmapPos.x = ((listDimension.width == emptyBitmap.width) ? 0 : (listDimension.width - emptyBitmap.width) / 2);
740 bitmapPos.y = ((listDimension.height == emptyBitmap.height) ? 0 : (listDimension.height - emptyBitmap.height) / 2);
743 if (__pEmptyText != null)
745 textPos.x = ((listDimension.width == emptyText.width) ? 0 : (listDimension.width - emptyText.width) / 2);
746 textPos.y = ((listDimension.height == emptyText.height) ? 0 : (listDimension.height - emptyText.height) / 2);
750 if (__pEmptyBitmap != null)
752 __pEmptyBitmap->SetPosition(bitmapPos);
754 if (__pEmptyText != null)
756 __pEmptyText->SetPosition(textPos);
759 CheckEmptyListShowState();
763 _ListViewImpl::CheckEmptyListShowState(void)
765 bool isEmpty = (GetItemCount() <= 0);
767 if (__pEmptyBitmap != null)
769 __pEmptyBitmap->SetVisibleState(isEmpty);
771 if (__pEmptyText != null)
773 __pEmptyText->SetVisibleState(isEmpty);
778 _ListViewImpl::SetBitmapOfEmptyList(const Bitmap* pBitmap)
782 if (__pEmptyBitmap != null)
784 GetCore().DetachChild(*__pEmptyBitmap);
786 delete __pEmptyBitmap;
787 __pEmptyBitmap = null;
792 if (__pEmptyBitmap == null)
794 __pEmptyBitmap = _Label::CreateLabelN();
795 SysTryReturn(NID_UI_CTRL, (__pEmptyBitmap != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
797 __pEmptyBitmap->SetVisibleState(false);
798 __pEmptyBitmap->SetMargin(0, 0);
800 GetCore().AttachChild(*__pEmptyBitmap);
803 Dimension bitmapSize(pBitmap->GetWidth(), pBitmap->GetHeight());
804 Dimension listDimension = GetCore().GetSize();
805 Dimension labelDimension;
807 labelDimension.width = ((listDimension.width < bitmapSize.width) ? listDimension.width : bitmapSize.width);
808 labelDimension.height = ((listDimension.height < bitmapSize.height) ? listDimension.height : bitmapSize.height);
810 __pEmptyBitmap->SetSize(labelDimension);
811 __pEmptyBitmap->SetBackgroundColor(Color(0, 0, 0, 0));
812 __pEmptyBitmap->SetBackgroundBitmap(*pBitmap);
815 AdjustLayoutOfEmptyList();
817 SetLastResultReturn(E_SUCCESS);
821 _ListViewImpl::SetTextOfEmptyList(const String& text)
825 if (__pEmptyText != null)
827 GetCore().DetachChild(*__pEmptyText);
835 if (__pEmptyText == null)
837 __pEmptyText = _Label::CreateLabelN();
838 SysTryReturn(NID_UI_CTRL, (__pEmptyText != null), E_SYSTEM, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
840 __pEmptyText->SetVisibleState(false);
841 __pEmptyText->SetMargin(0, 0);
843 GetCore().AttachChild(*__pEmptyText);
846 TextObject* pText = new (std::nothrow) TextObject;
847 SysTryReturn(NID_UI_CTRL, (pText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
851 TextSimple* pSimpleText = new (std::nothrow) TextSimple(const_cast <wchar_t*>(text.GetPointer()), text.GetLength());
852 SysTryReturn(NID_UI_CTRL, (pSimpleText != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
854 pText->AppendElement(*pSimpleText);
857 GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, textSize);
860 font.Construct(GetFont(), FONT_STYLE_PLAIN, textSize);
861 pText->SetFont(&font, 0, pText->GetTextLength());
863 Dimension listDimension = GetCore().GetSize();
865 pText->SetBounds(Rectangle(0, 0, listDimension.width, 1));
868 Dimension labelDimension = pText->GetTextExtent(0, pText->GetTextLength());
869 labelDimension.height = pText->GetTotalHeight();
871 if (labelDimension.width > listDimension.width)
873 pText->SetBounds(Rectangle(0, 0, listDimension.width, 1));
876 int labelHeight = pText->GetTotalHeight();
878 labelDimension.width = listDimension.width;
879 labelDimension.height = ((listDimension.height < labelHeight) ? listDimension.height : labelHeight);
884 __pEmptyText->SetSize(labelDimension);
885 __pEmptyText->SetBackgroundColor(Color(0, 0, 0, 0));
886 __pEmptyText->SetTextColor(__emptyTextColor);
887 __pEmptyText->SetTextConfig(textSize, LABEL_TEXT_STYLE_NORMAL);
888 __pEmptyText->SetText(text);
891 AdjustLayoutOfEmptyList();
893 SetLastResultReturn(E_SUCCESS);
897 _ListViewImpl::GetTextOfEmptyList(void) const
899 return ((__pEmptyText != null) ? __pEmptyText->GetText() : String());
903 _ListViewImpl::SetTextColorOfEmptyList(const Color& color)
905 __emptyTextColor = color;
907 if (__pEmptyText != null)
909 __pEmptyText->SetTextColor(color);
912 SetLastResultReturn(E_SUCCESS);
916 _ListViewImpl::GetTextColorOfEmptyList(void) const
918 return __emptyTextColor;
922 _ListViewImpl::SetListBackgroundColor(const Color& color)
924 SetBackgroundColor(color);
926 SetLastResultReturn(E_SUCCESS);
930 _ListViewImpl::SetBackgroundBitmap(const Bitmap* pBitmap)
932 GetCore().SetBackgroundBitmap(const_cast<Bitmap*>(pBitmap));
933 GetCore().SetBackgroundBitmapStretch(true);
935 SetLastResultReturn(E_SUCCESS);
939 _ListViewImpl::BeginReorderingMode(void)
941 result r = GetCore().SetReorderModeEnabled(true);
943 SetLastResultReturn(r);
947 _ListViewImpl::EndReorderingMode(void)
949 result r = GetCore().SetReorderModeEnabled(false);
951 SetLastResultReturn(r);
955 _ListViewImpl::IsInReorderingMode(void) const
957 return GetCore().IsReorderModeEnabled();
961 _ListViewImpl::OnListViewContextItemStateChanged(_Control& source, int groupIndex, int itemIndex, int elementId,
962 ListContextItemStatus status)
964 if (__pListItemEvent != null)
966 GetCore().ResetSweepItem();
968 __pItemNeedsLazyDeletion = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
970 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, elementId, 0, 0, NOTIFY_TYPE_SELCTED_CONTEXT_ITEM);
971 __pListItemEvent->Fire(*pArg);
973 __pItemNeedsLazyDeletion = null;
978 _ListViewImpl::OnListViewItemLongPressed(_Control& source, int groupIndex, int itemIndex, int elementId)
980 if (__pListItemEvent != null)
982 __pItemNeedsLazyDeletion = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
984 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, elementId, 0, 0, NOTIFY_TYPE_LONG_PRESSED_ITEM);
985 __pListItemEvent->Fire(*pArg);
987 __pItemNeedsLazyDeletion = null;
992 _ListViewImpl::OnTableViewItemStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pItem, TableViewItemStatus status)
994 if (__pListItemEvent != null)
996 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(pItem);
998 __pItemNeedsLazyDeletion = pListViewItem;
1000 if (pListViewItem != null)
1002 _ListViewItemStateChangedInfo itemInfo;
1003 pListViewItem->GetLastStateChangedInfo(itemInfo);
1005 if ((__pLinkEvent != null) && (itemInfo.pUiLinkInfo != null))
1007 IEventArg* pLinkEventArg = _PublicLinkEvent::CreateLinkEventArgN(itemInfo.pUiLinkInfo->textInfo,
1008 itemInfo.pUiLinkInfo->linkType,
1009 itemInfo.pUiLinkInfo->linkInfo);
1011 SysTryReturnVoidResult(NID_UI_CTRL, (pLinkEventArg != null), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _LinkEventArg.");
1012 __pLinkEvent->Fire(*pLinkEventArg);
1017 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, itemInfo.elementId, 0, 0, static_cast<NotifyType>(status));
1018 __pListItemEvent->Fire(*pArg);
1021 pListViewItem->ClearLastStateChangedInfo();
1024 __pItemNeedsLazyDeletion = null;
1029 _ListViewImpl::OnTableViewContextItemActivationStateChanged(_TableView& tableView, int itemIndex, _TableViewItem* pContextItem, bool activated)
1031 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1033 if (pListViewItem != null)
1035 __pItemSwept = (activated ? pListViewItem : null);
1037 pListViewItem->SetContextItemActivationState(activated);
1042 _ListViewImpl::OnTableViewItemReordered(_TableView& tableView, int itemIndexFrom, int itemIndexTo)
1044 if (__pListItemEvent != null)
1046 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndexFrom, itemIndexTo, 0, 0, NOTIFY_TYPE_REORDERED_ITEM);
1047 __pListItemEvent->Fire(*pArg);
1052 _ListViewImpl::OnTableViewItemSwept(_TableView& tableView, int groupIndex, int itemIndex, TableViewSweepDirection direction)
1054 if (__pListItemEvent != null)
1056 __pItemNeedsLazyDeletion = static_cast<_ListViewItem*>(GetCore().FindItem(0, itemIndex));
1058 _ListItemEventArg* pArg = new (std::nothrow) _ListItemEventArg(itemIndex, direction, 0, 0, NOTIFY_TYPE_SWEPT_ITEM);
1059 __pListItemEvent->Fire(*pArg);
1061 __pItemNeedsLazyDeletion = null;
1066 _ListViewImpl::OnScrollEndReached(_Control& source, ScrollEndEvent type)
1068 if (__pScrollEvent != null)
1070 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), type);
1071 result r = GetLastResult();
1072 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1074 __pScrollEvent->Fire(*pEventArg);
1079 _ListViewImpl::OnScrollPositionChanged(_Control& source, int scrollPos)
1081 if (__pScrollEvent != null)
1083 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic(), scrollPos);
1084 result r = GetLastResult();
1085 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1087 __pScrollEvent->Fire(*pEventArg);
1092 _ListViewImpl::OnScrollStopped(_Control& source)
1094 if (__pScrollEvent != null)
1096 _ScrollEventArg* pEventArg = _ScrollEventArg::GetScrollEventArgN(GetPublic());
1097 result r = GetLastResult();
1098 SysTryReturnVoidResult(NID_UI_CTRL, (r == E_SUCCESS), r, "[%s] Propagating.", GetErrorMessage(r));
1100 __pScrollEvent->Fire(*pEventArg);
1105 _ListViewImpl::OnUiFastScrollIndexSelected(_Control& source, _FastScrollIndex& index)
1107 if (__pFastScrollEvent != null)
1109 String* pIndexText = index.GetIndexText();
1110 if (pIndexText != null)
1112 _FastScrollEventArg* pEventArg = new (std::nothrow) _FastScrollEventArg(GetPublic(), *pIndexText);
1113 __pFastScrollEvent->Fire(*pEventArg);
1119 _ListViewImpl::OnDraw(void)
1121 _ControlImpl::OnDraw();
1123 if (__redrawListView)
1125 CheckEmptyListShowState();
1126 __redrawListView = false;
1131 _ListViewImpl::OnBoundsChanged(void)
1133 _ControlImpl::OnBoundsChanged();
1135 if (__pEmptyBitmap != null)
1137 SetBitmapOfEmptyList(__pEmptyBitmap->GetBackgroundBitmap());
1139 if (__pEmptyText != null)
1141 SetTextOfEmptyList(__pEmptyText->GetText());
1144 _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1146 if (pProviderAdaptor != null)
1148 pProviderAdaptor->SetListWidth(GetCore().GetBounds().width);
1153 _ListViewImpl::OnFontChanged(Font* pFont)
1155 String fontName = GetFont();
1156 _ListViewItemProviderAdaptor* pProviderAdaptor = static_cast <_ListViewItemProviderAdaptor*>(GetCore().GetItemProviderAdaptor());
1158 if (__pEmptyText != null)
1160 __pEmptyText->SetFont(fontName);
1161 SetTextOfEmptyList(__pEmptyText->GetText());
1164 if (pProviderAdaptor != null)
1166 pProviderAdaptor->SetItemFont(fontName);
1169 int firstGroup = -1;
1173 int currentItem = -1;
1174 int lastItemInGroup = -1;
1176 GetCore().GetFirstLoadedItemIndex(firstGroup, firstItem);
1177 GetCore().GetLastLoadedItemIndex(lastGroup, lastItem);
1179 for (int i = firstGroup; i <= lastGroup; i++)
1181 currentItem = ((i == firstGroup) ? firstItem : -1);
1182 lastItemInGroup = ((i == lastGroup) ? lastItem : GetCore().GetItemCountAt(i));
1184 for (; currentItem <= lastItemInGroup; currentItem++)
1186 _ListViewItem* pListViewItem = static_cast<_ListViewItem*>(GetCore().FindItem(i, currentItem));
1188 if (pListViewItem != null)
1190 pListViewItem->SetFont(fontName);
1197 _ListViewImpl::OnFontInfoRequested(unsigned long& style, int& size)
1200 GET_SHAPE_CONFIG(LISTVIEW::EMPTY_LIST_TEXT_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, textSize);
1202 style = FONT_STYLE_PLAIN;
1207 _ListViewImpl::OnTouchPressed(const _ControlImpl& source, const _TouchInfo& touchinfo)
1209 FirePublicTouchEvent(touchinfo);
1214 _ListViewImpl::OnTouchReleased(const _ControlImpl& source, const _TouchInfo& touchinfo)
1216 FirePublicTouchEvent(touchinfo);
1221 _ListViewImpl::OnTouchMoved(const _ControlImpl& source, const _TouchInfo& touchinfo)
1223 FirePublicTouchEvent(touchinfo);
1228 _ListViewImpl::OnTouchCanceled(const _ControlImpl& source, const _TouchInfo& touchinfo)
1230 FirePublicTouchEvent(touchinfo);
1235 _ListViewImpl::FirePublicTouchEvent(const _TouchInfo& touchInfo)
1237 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1238 SysTryReturnVoidResult(NID_UI, pTouchManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1240 TouchEventInfo publicTouchInfo;
1242 _TouchEventArg* pEventArg = GetTouchEventArgN(touchInfo);
1243 SysTryReturnVoidResult(NID_UI, pEventArg, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1245 publicTouchInfo.Construct(*pEventArg);
1247 _Control* pDraggedControl = pTouchManager->GetTouchControlSource();
1249 IEnumeratorT<IEventListener*>* pEnumerator = GetTouchEventListener()->GetEnumeratorN();
1252 while (pEnumerator->MoveNext() == E_SUCCESS)
1254 IEventListener* pListener = null;
1255 pEnumerator->GetCurrent(pListener);
1257 ITouchEventListener* pTouchEventListener = dynamic_cast <ITouchEventListener*>(pListener);
1258 if (pTouchEventListener)
1260 FirePublicListener(*pTouchEventListener, publicTouchInfo);
1262 if (touchInfo.GetTouchStatus() == _TOUCH_RELEASED)
1264 if (pDraggedControl == null) //if exist dragged control, don't send focus event
1266 FireFocusListener(*pTouchEventListener, publicTouchInfo);
1269 else if (touchInfo.GetTouchStatus() == _TOUCH_MOVED)
1271 FireFocusListener(*pTouchEventListener, publicTouchInfo);
1283 _ListViewImpl::FirePublicListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
1285 switch (touchEventInfo.GetTouchStatus())
1288 listener.OnTouchPressed(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1290 case TOUCH_LONG_PRESSED:
1291 listener.OnTouchLongPressed(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1293 case TOUCH_RELEASED:
1294 listener.OnTouchReleased(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1297 listener.OnTouchMoved(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1299 case TOUCH_DOUBLE_PRESSED:
1300 listener.OnTouchDoublePressed(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1302 case TOUCH_FOCUS_IN:
1303 listener.OnTouchFocusIn(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1305 case TOUCH_FOCUS_OUT:
1306 listener.OnTouchFocusOut(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1308 case TOUCH_CANCELED:
1309 listener.OnTouchCanceled(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1317 _ListViewImpl::FireFocusListener(ITouchEventListener& listener, const TouchEventInfo& touchEventInfo)
1319 _ControlManager* pControlManager = _ControlManager::GetInstance();
1320 SysTryReturnVoidResult(NID_UI, pControlManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1322 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1323 SysTryReturnVoidResult(NID_UI, pTouchManager, E_SYSTEM, "[E_SYSTEM] System error occurred.");
1325 Point screenPoint(pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).x,
1326 pTouchManager->GetScreenPoint(touchEventInfo.GetPointId()).y);
1328 _Control* pTouchedControl = pControlManager->GetTopmostTouchedControl(screenPoint);
1329 SysTryReturnVoidResult(NID_UI, pTouchedControl, E_INVALID_CONDITION, "[E_INVALID_CONDITION] pTouchedControl is null.");
1331 if (pTouchManager->GetFocusedControlSource() != pTouchedControl)
1333 if (&(GetCore()) != pTouchedControl)
1335 if (pTouchManager->GetFocusedControlSource() == &(GetCore()))
1337 listener.OnTouchFocusOut(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1342 listener.OnTouchFocusIn(GetPublic(), touchEventInfo.GetCurrentPosition(), touchEventInfo);
1345 pTouchManager->SetFocusedControlSource(*pTouchedControl);
1350 _ListViewImpl::GetTouchEventArgN(const _TouchInfo& touchInfo)
1354 _TouchEventArg* pEventArg = new (std::nothrow) _TouchEventArg(GetPublic(), touchInfo.GetTouchStatus());
1355 SysTryReturn(NID_UI, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
1357 _TouchManager* pTouchManager = _TouchManager::GetInstance();
1358 SysTryCatch(NID_UI, pTouchManager, , E_SYSTEM, "[E_SYSTEM] System error occurred.");
1360 startPoint.SetPosition(pTouchManager->GetStartPoint(touchInfo.GetPointId()).x - GetCore().GetAbsoluteBounds().x,
1361 pTouchManager->GetStartPoint(touchInfo.GetPointId()).y - GetCore().GetAbsoluteBounds().y);
1363 pEventArg->SetTouchPosition(touchInfo.GetPointId(), startPoint.x, startPoint.y,
1364 touchInfo.GetCurrentPosition().x, touchInfo.GetCurrentPosition().y);
1366 // need to flick distance setting
1375 class _ListViewMaker
1376 : public _UiBuilderControlMaker
1379 _ListViewMaker(_UiBuilder* uibuilder)
1380 : _UiBuilderControlMaker(uibuilder){};
1382 virtual ~_ListViewMaker(){};
1384 static _UiBuilderControlMaker*
1385 GetInstance(_UiBuilder* uibuilder)
1387 _ListViewMaker* pListViewMaker = new (std::nothrow) _ListViewMaker(uibuilder);
1388 return pListViewMaker;
1393 Make(_UiBuilderControl* pControl)
1395 result r = E_SYSTEM;
1396 _UiBuilderControlLayout* pControlProperty = null;
1397 ListView* pListView = null;
1399 String elementString;
1401 bool hasItemDivider = true;
1402 bool hasFastScroll = false;
1404 bool isSweepEnabled = false;
1407 GetProperty(pControl, &pControlProperty);
1408 if (pControlProperty == null)
1413 pListView = new (std::nothrow) ListView();
1414 if (pListView == null)
1419 rect = pControlProperty->GetRect();
1421 if (pControl->GetElement(L"itemDivider", elementString))
1423 if (elementString.Equals(L"true", false))
1425 hasItemDivider = true;
1429 hasItemDivider = false;
1433 if (pControl->GetElement(L"fastScroll", elementString))
1435 if (elementString.Equals(L"true", false))
1437 hasFastScroll = true;
1441 hasFastScroll = false;
1445 r = pListView->Construct(rect, hasItemDivider, hasFastScroll);
1454 // Set BackgroundsBitmap
1455 if (pControl->GetElement("backgroundBitmapPath", elementString))
1457 Bitmap* pBackgroundBitmap = null;
1458 pBackgroundBitmap = LoadBitmapN(elementString);
1459 if (pBackgroundBitmap != null)
1461 pListView->SetBackgroundBitmap(pBackgroundBitmap);
1462 delete pBackgroundBitmap;
1463 pBackgroundBitmap = null;
1468 if (pControl->GetElement(L"textOfEmptyList", elementString))
1470 pListView->SetTextOfEmptyList(elementString);
1473 if (pControl->GetElement(L"colorOfEmptyListText", elementString))
1475 ConvertStringToColor(elementString, color);
1476 pListView->SetTextColorOfEmptyList(color);
1479 if (pControl->GetElement(L"bitmapPathOfEmptyList", elementString))
1481 Bitmap* pBackgroundBitmap = null;
1482 pBackgroundBitmap = LoadBitmapN(elementString); //__image->DecodeN(path,BITMAP_PIXEL_FORMAT_RGB565);
1483 if (pBackgroundBitmap != null)
1485 pListView->SetBitmapOfEmptyList(pBackgroundBitmap);
1487 delete pBackgroundBitmap;
1488 pBackgroundBitmap = null;
1492 if (pControl->GetElement(L"backgroundColorOpacity", elementString) || pControl->GetElement(L"BGColorOpacity", elementString))
1494 Base::Integer::Parse(elementString, opacity);
1497 if (pControl->GetElement(L"backgroundColor", elementString) || pControl->GetElement(L"BGColor", elementString))
1499 ConvertStringToColor32(elementString, opacity, color);
1500 pListView->SetBackgroundColor(color);
1503 if (pControl->GetElement(L"itemDividerColor", elementString))
1505 ConvertStringToColor(elementString, color);
1506 pListView->SetItemDividerColor(color);
1509 if (pControl->GetElement(L"sweepEnabled", elementString))
1511 if (elementString.Equals(L"true", false))
1513 isSweepEnabled = true;
1517 isSweepEnabled = false;
1520 pListView->SetSweepEnabled(isSweepEnabled);
1527 }; // _ListViewMaker
1529 _ListViewRegister::_ListViewRegister()
1531 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1532 pUiBuilderControlTableManager->RegisterControl(L"ListView", _ListViewMaker::GetInstance);
1535 _ListViewRegister::~_ListViewRegister()
1537 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
1538 pUiBuilderControlTableManager->UnregisterControl(L"ListView");
1541 static _ListViewRegister ListViewRegisterToUIbuilder;
1542 }}} // Tizen::Ui::Controls