Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlListView.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FUiCtrlListView.cpp
20  * @brief       This is the implementation file for ListView class.
21  *
22  * This file contains the implementation of ListView class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlListView.h>
27 #include "FUiCtrl_ListViewImpl.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31
32 namespace Tizen { namespace Ui { namespace Controls
33 {
34
35 ListView::ListView(void)
36 {
37 }
38
39 ListView::~ListView(void)
40 {
41 }
42
43 result
44 ListView::Construct(const Rectangle& rect, bool itemDivider, bool fastScroll)
45 {
46         result r = E_SUCCESS;
47
48         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
49         SysAssertf(pImpl == null,
50                                   "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
51
52         if (fastScroll == true)
53         {
54                 pImpl = _ListViewImpl::CreateListViewImplN(this, itemDivider, SCROLL_STYLE_FAST_SCROLL);
55         }
56         else
57         {
58                 pImpl = _ListViewImpl::CreateListViewImplN(this, itemDivider, SCROLL_STYLE_FADE_OUT);
59         }
60         SysTryReturn(NID_UI_CTRL, pImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
61
62         _pControlImpl = pImpl;
63         r = Control::SetBounds(rect.x, rect.y, rect.width, rect.height);
64         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
65
66         return E_SUCCESS;
67
68 CATCH:
69         Control::Dispose();
70
71         return r;
72 }
73
74 result
75 ListView::Construct(const Rectangle& rect, bool itemDivider, ListScrollStyle scrollStyle)
76 {
77         result r = E_SUCCESS;
78
79         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
80         SysAssertf(pImpl == null,
81                                   "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
82
83         pImpl = _ListViewImpl::CreateListViewImplN(this, itemDivider, scrollStyle);
84         SysTryReturn(NID_UI_CTRL, pImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
85
86         _pControlImpl = pImpl;
87         r = Control::SetBounds(rect.x, rect.y, rect.width, rect.height);
88         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
89
90         return E_SUCCESS;
91
92 CATCH:
93         Control::Dispose();
94
95         return r;
96 }
97
98 result
99 ListView::SetItemProvider(IListViewItemProvider& provider)
100 {
101         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
102         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
103
104         return pImpl->SetItemProvider(provider);
105 }
106
107 void
108 ListView::AddListViewItemEventListener(IListViewItemEventListener& listener)
109 {
110         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
111         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
112
113         pImpl->AddListViewItemEventListener(listener);
114         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
115 }
116
117 void
118 ListView::RemoveListViewItemEventListener(IListViewItemEventListener& listener)
119 {
120         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
121         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
122
123         pImpl->RemoveListViewItemEventListener(listener);
124         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
125 }
126
127 void
128 ListView::AddFastScrollListener(IFastScrollListener& listener)
129 {
130         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
131         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
132
133         pImpl->AddFastScrollListener(listener);
134         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
135 }
136
137 void
138 ListView::RemoveFastScrollListener(IFastScrollListener& listener)
139 {
140         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
141         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
142
143         pImpl->RemoveFastScrollListener(listener);
144         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
145 }
146
147 void
148 ListView::AddScrollEventListener(IScrollEventListener& listener)
149 {
150         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
151         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
152
153         pImpl->AddScrollEventListener(listener);
154         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
155 }
156
157 void
158 ListView::RemoveScrollEventListener(IScrollEventListener& listener)
159 {
160         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
161         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
162
163         pImpl->RemoveScrollEventListener(listener);
164         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
165 }
166
167 void
168 ListView::AddUiLinkEventListener(IUiLinkEventListener& listener)
169 {
170         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
171         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
172
173         pImpl->AddUiLinkEventListener(listener);
174         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
175 }
176
177 void
178 ListView::RemoveUiLinkEventListener(IUiLinkEventListener& listener)
179 {
180         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
181         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
182
183         pImpl->RemoveUiLinkEventListener(listener);
184         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
185 }
186
187 result
188 ListView::SetSweepEnabled(bool enable)
189 {
190         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
191         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
192
193         return pImpl->SetSweepEnabled(enable);
194 }
195
196 result
197 ListView::SetFastScrollIndex(const String& text, bool useSearchIcon)
198 {
199         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
200         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
201
202         return pImpl->SetFastScrollIndex(text, useSearchIcon);
203 }
204
205 int
206 ListView::GetTopDrawnItemIndex(void) const
207 {
208         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
209         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
210
211         return pImpl->GetTopDrawnItemIndex();
212 }
213
214 int
215 ListView::GetBottomDrawnItemIndex(void) const
216 {
217         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
218         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
219
220         return pImpl->GetBottomDrawnItemIndex();
221 }
222
223 result
224 ListView::ScrollToItem(int index)
225 {
226         return ScrollToItem(index, LIST_SCROLL_ITEM_ALIGNMENT_TOP);
227 }
228
229 result
230 ListView::ScrollToItem(int index, ListScrollItemAlignment itemAlignment)
231 {
232         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
233         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
234
235         return pImpl->ScrollToItem(index, itemAlignment);
236 }
237
238 result
239 ListView::SetItemChecked(int index, bool check)
240 {
241         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
242         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
243
244         return pImpl->SetItemChecked(index, check);
245 }
246
247 bool
248 ListView::IsItemChecked(int index) const
249 {
250         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
251         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
252
253         return pImpl->IsItemChecked(index);
254 }
255
256 result
257 ListView::SetItemEnabled(int index, bool enable)
258 {
259         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
260         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
261
262         return pImpl->SetItemEnabled(index, enable);
263 }
264
265 bool
266 ListView::IsItemEnabled(int index) const
267 {
268         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
269         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
270
271         return pImpl->IsItemEnabled(index);
272 }
273
274 int
275 ListView::GetItemCount(void) const
276 {
277         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
278         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
279
280         return pImpl->GetItemCount();
281 }
282
283 result
284 ListView::ShowItemDescriptionText(int index)
285 {
286         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
287         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
288
289         return pImpl->ShowItemDescriptionText(index);
290 }
291
292 result
293 ListView::HideItemDescriptionText(int index)
294 {
295         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
296         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
297
298         return pImpl->HideItemDescriptionText(index);
299 }
300
301 result
302 ListView::RefreshList(int index, ListRefreshType type)
303 {
304         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
305         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
306
307         return pImpl->RefreshList(index, type);
308 }
309
310 result
311 ListView::RefreshList(int index, int elementId)
312 {
313         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
314         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
315
316         return pImpl->RefreshList(index, elementId);
317 }
318
319 result
320 ListView::UpdateList(void)
321 {
322         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
323         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
324
325         return pImpl->UpdateList();
326 }
327
328 int
329 ListView::GetItemIndexFromPosition(int x, int y) const
330 {
331         return GetItemIndexFromPosition(Point(x, y));
332 }
333
334 int
335 ListView::GetItemIndexFromPosition(const Point& position) const
336 {
337         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
338         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
339
340         return pImpl->GetItemIndexFromPosition(position);
341 }
342
343 result
344 ListView::GetItemIndexFromPosition(int x, int y, int& itemIndex, int& elementId) const
345 {
346         return GetItemIndexFromPosition(Point(x, y), itemIndex, elementId);
347 }
348
349 result
350 ListView::GetItemIndexFromPosition(const Point& position, int& itemIndex, int& elementId) const
351 {
352         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
353         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
354
355         return pImpl->GetItemIndexFromPosition(position, itemIndex, elementId);
356 }
357
358 result
359 ListView::SetItemDividerColor(const Color& color)
360 {
361         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
362         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
363
364         return pImpl->SetItemDividerColor(color);
365 }
366
367 Color
368 ListView::GetItemDividerColor(void) const
369 {
370         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
371         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
372
373         return pImpl->GetItemDividerColor();
374 }
375
376 result
377 ListView::SetBackgroundColor(const Color& color)
378 {
379         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
380         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
381
382         pImpl->SetListBackgroundColor(color);
383
384         return E_SUCCESS;
385 }
386
387 Color
388 ListView::GetBackgroundColor(void) const
389 {
390         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
391         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
392
393         return pImpl->GetBackgroundColor();
394 }
395
396 result
397 ListView::SetBackgroundBitmap(const Bitmap* pBitmap)
398 {
399         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
400         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
401
402         return pImpl->SetBackgroundBitmap(pBitmap);
403 }
404
405 result
406 ListView::SetBitmapOfEmptyList(const Bitmap* pBitmap)
407 {
408         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
409         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
410
411         return pImpl->SetBitmapOfEmptyList(pBitmap);
412 }
413
414 result
415 ListView::SetTextOfEmptyList(const String& text)
416 {
417         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
418         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
419
420         return pImpl->SetTextOfEmptyList(text);
421 }
422
423 String
424 ListView::GetTextOfEmptyList(void) const
425 {
426         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
427         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
428
429         return pImpl->GetTextOfEmptyList();
430 }
431
432 result
433 ListView::SetTextColorOfEmptyList(const Color& color)
434 {
435         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
436         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
437
438         return pImpl->SetTextColorOfEmptyList(color);
439 }
440
441 Color
442 ListView::GetTextColorOfEmptyList(void) const
443 {
444         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
445         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
446
447         return pImpl->GetTextColorOfEmptyList();
448 }
449
450 result
451 ListView::BeginReorderingMode(void)
452 {
453         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
454         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
455
456         return pImpl->BeginReorderingMode();
457 }
458
459 result
460 ListView::EndReorderingMode(void)
461 {
462         _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
463         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
464
465         return pImpl->EndReorderingMode();
466 }
467
468 bool
469 ListView::IsInReorderingMode(void) const
470 {
471         const _ListViewImpl* pImpl = _ListViewImpl::GetInstance(*this);
472         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
473
474         return pImpl->IsInReorderingMode();
475 }
476
477 }}} // Controls