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 FUiCtrlListView.cpp
20 * @brief This is the implementation file for ListView class.
22 * This file contains the implementation of ListView class.
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlListView.h>
27 #include "FUiCtrl_ListViewImpl.h"
28 #include "FUi_CoordinateSystemUtils.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Graphics;
33 namespace Tizen { namespace Ui { namespace Controls
36 ListView::ListView(void)
40 ListView::~ListView(void)
45 ListView::Construct(const Rectangle& rect, bool itemDivider, bool fastScroll)
49 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
50 SysAssertf(pImpl == null,
51 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
53 if (fastScroll == true)
55 pImpl = _ListViewImpl::CreateListViewImplN(this, itemDivider, SCROLL_STYLE_FAST_SCROLL);
59 pImpl = _ListViewImpl::CreateListViewImplN(this, itemDivider, SCROLL_STYLE_FADE_OUT);
61 SysTryReturn(NID_UI_CTRL, pImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
63 _pControlImpl = pImpl;
64 r = Control::SetBounds(_CoordinateSystemUtils::ConvertToFloat(rect));
65 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
76 ListView::Construct(const Rectangle& rect, bool itemDivider, ListScrollStyle scrollStyle)
80 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
81 SysAssertf(pImpl == null,
82 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
84 pImpl = _ListViewImpl::CreateListViewImplN(this, itemDivider, scrollStyle);
85 SysTryReturn(NID_UI_CTRL, pImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
87 _pControlImpl = pImpl;
88 r = Control::SetBounds(_CoordinateSystemUtils::ConvertToFloat(rect));
89 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
100 ListView::Construct(const FloatRectangle& rect, bool itemDivider, ListScrollStyle scrollStyle)
102 result r = E_SUCCESS;
104 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
105 SysAssertf(pImpl == null,
106 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
108 pImpl = _ListViewImpl::CreateListViewImplN(this, itemDivider, scrollStyle);
109 SysTryReturn(NID_UI_CTRL, pImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
111 _pControlImpl = pImpl;
112 r = Control::SetBounds(rect);
113 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
124 ListView::SetItemProvider(IListViewItemProvider& provider)
126 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
127 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
129 return pImpl->SetItemProvider(provider);
133 ListView::SetItemProvider(IListViewItemProviderF& provider)
135 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
136 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
138 return pImpl->SetItemProvider(provider);
142 ListView::AddListViewItemEventListener(IListViewItemEventListener& listener)
144 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
145 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
147 pImpl->AddListViewItemEventListener(listener);
148 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
152 ListView::RemoveListViewItemEventListener(IListViewItemEventListener& listener)
154 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
155 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
157 pImpl->RemoveListViewItemEventListener(listener);
158 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
162 ListView::AddFastScrollListener(IFastScrollListener& listener)
164 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
165 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
167 pImpl->AddFastScrollListener(listener);
168 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
172 ListView::RemoveFastScrollListener(IFastScrollListener& listener)
174 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
175 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
177 pImpl->RemoveFastScrollListener(listener);
178 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
182 ListView::AddScrollEventListener(IScrollEventListener& listener)
184 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
185 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
187 pImpl->AddScrollEventListener(listener);
188 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
192 ListView::AddScrollEventListener(IScrollEventListenerF& listener)
194 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
195 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
197 pImpl->AddScrollEventListener(listener);
198 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
202 ListView::RemoveScrollEventListener(IScrollEventListener& listener)
204 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
205 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
207 pImpl->RemoveScrollEventListener(listener);
208 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
212 ListView::RemoveScrollEventListener(IScrollEventListenerF& listener)
214 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
215 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
217 pImpl->RemoveScrollEventListener(listener);
218 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
222 ListView::AddUiLinkEventListener(IUiLinkEventListener& listener)
224 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
225 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
227 pImpl->AddUiLinkEventListener(listener);
228 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
232 ListView::RemoveUiLinkEventListener(IUiLinkEventListener& listener)
234 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
235 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
237 pImpl->RemoveUiLinkEventListener(listener);
238 SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
242 ListView::SetSweepEnabled(bool enable)
244 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
245 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
247 return pImpl->SetSweepEnabled(enable);
251 ListView::SetFastScrollIndex(const String& text, bool useSearchIcon)
253 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
254 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
256 return pImpl->SetFastScrollIndex(text, useSearchIcon);
260 ListView::GetTopDrawnItemIndex(void) const
262 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
263 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
265 return pImpl->GetTopDrawnItemIndex();
269 ListView::GetBottomDrawnItemIndex(void) const
271 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
272 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
274 return pImpl->GetBottomDrawnItemIndex();
278 ListView::ScrollToItem(int index)
280 return ScrollToItem(index, LIST_SCROLL_ITEM_ALIGNMENT_TOP);
284 ListView::ScrollToItem(int index, ListScrollItemAlignment itemAlignment)
286 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
287 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
289 return pImpl->ScrollToItem(index, itemAlignment);
293 ListView::SetItemChecked(int index, bool check)
295 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
296 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
298 return pImpl->SetItemChecked(index, check);
302 ListView::IsItemChecked(int index) const
304 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
305 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
307 return pImpl->IsItemChecked(index);
311 ListView::SetItemEnabled(int index, bool enable)
313 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
314 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
316 return pImpl->SetItemEnabled(index, enable);
320 ListView::IsItemEnabled(int index) const
322 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
323 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
325 return pImpl->IsItemEnabled(index);
329 ListView::GetItemCount(void) const
331 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
332 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
334 return pImpl->GetItemCount();
338 ListView::ShowItemDescriptionText(int index)
340 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
341 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
343 return pImpl->ShowItemDescriptionText(index);
347 ListView::HideItemDescriptionText(int index)
349 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
350 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
352 return pImpl->HideItemDescriptionText(index);
356 ListView::RefreshList(int index, ListRefreshType type)
358 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
359 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
361 return pImpl->RefreshList(index, type);
365 ListView::RefreshList(int index, int elementId)
367 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
368 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
370 return pImpl->RefreshList(index, elementId);
374 ListView::UpdateList(void)
376 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
377 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
379 return pImpl->UpdateList();
383 ListView::GetItemIndexFromPosition(int x, int y) const
385 return GetItemIndexFromPosition(Point(x, y));
389 ListView::GetItemIndexFromPosition(float x, float y) const
391 return GetItemIndexFromPosition(FloatPoint(x, y));
395 ListView::GetItemIndexFromPosition(const Point& position) const
397 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
398 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
400 return pImpl->GetItemIndexFromPosition(_CoordinateSystemUtils::ConvertToFloat(position));
404 ListView::GetItemIndexFromPosition(const FloatPoint& position) const
406 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
407 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
409 return pImpl->GetItemIndexFromPosition(position);
413 ListView::GetItemIndexFromPosition(int x, int y, int& itemIndex, int& elementId) const
415 return GetItemIndexFromPosition(Point(x, y), itemIndex, elementId);
419 ListView::GetItemIndexFromPosition(float x, float y, int& itemIndex, int& elementId) const
421 return GetItemIndexFromPosition(FloatPoint(x, y), itemIndex, elementId);
425 ListView::GetItemIndexFromPosition(const Point& position, int& itemIndex, int& elementId) const
427 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
428 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
430 return pImpl->GetItemIndexFromPosition(_CoordinateSystemUtils::ConvertToFloat(position), itemIndex, elementId);
434 ListView::GetItemIndexFromPosition(const FloatPoint& position, int& itemIndex, int& elementId) const
436 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
437 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
439 return pImpl->GetItemIndexFromPosition(position, itemIndex, elementId);
443 ListView::SetItemDividerColor(const Color& color)
445 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
446 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
448 return pImpl->SetItemDividerColor(color);
452 ListView::GetItemDividerColor(void) const
454 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
455 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
457 return pImpl->GetItemDividerColor();
461 ListView::SetBackgroundColor(const Color& color)
463 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
464 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
466 pImpl->SetListBackgroundColor(color);
472 ListView::GetBackgroundColor(void) const
474 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
475 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
477 return pImpl->GetBackgroundColor();
481 ListView::SetBackgroundBitmap(const Bitmap* pBitmap)
483 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
484 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
486 return pImpl->SetBackgroundBitmap(pBitmap);
490 ListView::SetBitmapOfEmptyList(const Bitmap* pBitmap)
492 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
493 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
495 return pImpl->SetBitmapOfEmptyList(pBitmap);
499 ListView::SetTextOfEmptyList(const String& text)
501 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
502 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
504 return pImpl->SetTextOfEmptyList(text);
508 ListView::GetTextOfEmptyList(void) const
510 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
511 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
513 return pImpl->GetTextOfEmptyList();
517 ListView::SetTextColorOfEmptyList(const Color& color)
519 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
520 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
522 return pImpl->SetTextColorOfEmptyList(color);
526 ListView::GetTextColorOfEmptyList(void) const
528 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
529 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
531 return pImpl->GetTextColorOfEmptyList();
535 ListView::BeginReorderingMode(void)
537 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
538 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
540 return pImpl->BeginReorderingMode();
544 ListView::EndReorderingMode(void)
546 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
547 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
549 return pImpl->EndReorderingMode();
553 ListView::IsInReorderingMode(void) const
555 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
556 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
558 return pImpl->IsInReorderingMode();
562 ListView::SetScrollInputMode(ScrollInputMode mode)
564 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
565 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
567 pImpl->SetScrollInputMode(mode);
571 ListView::GetScrollInputMode(void) const
573 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
574 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
576 return pImpl->GetScrollInputMode();
580 ListView::OpenContextItem(int itemIndex)
582 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
583 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
585 return pImpl->OpenContextItem(itemIndex);
589 ListView::CloseContextItem(int itemIndex)
591 _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
592 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
594 return pImpl->CloseContextItem(itemIndex);
598 ListView::IsContextItemOpened(int itemIndex) const
600 const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
601 SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
603 return pImpl->IsContextItemOpened(itemIndex);