Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlGroupedListView.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        FUiCtrlGroupedListView.cpp
20  * @brief       This is the implementation file for GroupedListView class.
21  *
22  * This header file contains the implementation of GroupedListView class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlGroupedListView.h>
27 #include "FUiCtrl_GroupedListViewImpl.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31
32 namespace Tizen { namespace Ui { namespace Controls
33 {
34
35 GroupedListView::GroupedListView(void)
36 {
37 }
38
39 GroupedListView::~GroupedListView(void)
40 {
41 }
42
43 result
44 GroupedListView::Construct(const Rectangle& rect, GroupedListViewStyle style, bool itemDivider, bool fastScroll)
45 {
46         result r = E_SUCCESS;
47
48         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::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 = _GroupedListViewImpl::CreateGroupedListViewImplN(this, style, itemDivider, SCROLL_STYLE_FAST_SCROLL);
55         }
56         else
57         {
58                 pImpl = _GroupedListViewImpl::CreateGroupedListViewImplN(this, style, 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
64         r = Control::SetBounds(rect.x, rect.y, rect.width, rect.height);
65         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
66
67         return E_SUCCESS;
68
69 CATCH:
70         Control::Dispose();
71         return r;
72 }
73
74 result
75 GroupedListView::Construct(const Rectangle& rect, GroupedListViewStyle style, bool itemDivider, ListScrollStyle scrollStyle)
76 {
77         result r = E_SUCCESS;
78
79         SysAssertf((_GroupedListViewImpl::GetInstance(*this) == null),
80                                   "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
81
82         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::CreateGroupedListViewImplN(this, style, itemDivider, scrollStyle);
83         SysTryReturn(NID_UI_CTRL, (pImpl != null), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
84
85         _pControlImpl = pImpl;
86
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 r;
91
92 CATCH:
93         Control::Dispose();
94         return r;
95 }
96
97 result
98 GroupedListView::SetItemProvider(IGroupedListViewItemProvider& provider)
99 {
100         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
101         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
102
103         return pImpl->SetItemProvider(provider);
104 }
105
106 void
107 GroupedListView::AddGroupedListViewItemEventListener(IGroupedListViewItemEventListener& listener)
108 {
109         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
110         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
111
112         pImpl->AddGroupedListViewItemEventListener(listener);
113         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
114 }
115
116 void
117 GroupedListView::RemoveGroupedListViewItemEventListener(IGroupedListViewItemEventListener& listener)
118 {
119         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
120         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
121
122         pImpl->RemoveGroupedListViewItemEventListener(listener);
123         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
124 }
125
126 void
127 GroupedListView::AddFastScrollListener(IFastScrollListener& listener)
128 {
129         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
130         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
131
132         pImpl->AddFastScrollListener(listener);
133         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
134 }
135
136 void
137 GroupedListView::RemoveFastScrollListener(IFastScrollListener& listener)
138 {
139         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
140         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
141
142         pImpl->RemoveFastScrollListener(listener);
143         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
144 }
145
146 void
147 GroupedListView::AddScrollEventListener(IScrollEventListener& listener)
148 {
149         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
150         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
151
152         pImpl->AddScrollEventListener(listener);
153         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
154 }
155
156 void
157 GroupedListView::RemoveScrollEventListener(IScrollEventListener& listener)
158 {
159         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
160         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
161
162         pImpl->RemoveScrollEventListener(listener);
163         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
164 }
165
166 void
167 GroupedListView::AddUiLinkEventListener(IUiLinkEventListener& listener)
168 {
169         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
170         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
171
172         pImpl->AddUiLinkEventListener(listener);
173         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
174 }
175
176 void
177 GroupedListView::RemoveUiLinkEventListener(IUiLinkEventListener& listener)
178 {
179         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
180         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
181
182         pImpl->RemoveUiLinkEventListener(listener);
183         SysTryReturnVoidResult(NID_UI_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
184 }
185
186 result
187 GroupedListView::SetSweepEnabled(bool enable)
188 {
189         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
190         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
191
192         return pImpl->SetSweepEnabled(enable);
193 }
194
195 result
196 GroupedListView::SetFastScrollIndex(const String& text, bool useSearchIcon)
197 {
198         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
199         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
200
201         return pImpl->SetFastScrollIndex(text, useSearchIcon);
202 }
203
204 result
205 GroupedListView::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
206 {
207         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
208         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
209
210         return pImpl->GetTopDrawnItemIndex(groupIndex, itemIndex);
211 }
212
213 result
214 GroupedListView::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
215 {
216         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
217         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
218
219         return pImpl->GetBottomDrawnItemIndex(groupIndex, itemIndex);
220 }
221
222 result
223 GroupedListView::ScrollToItem(int groupIndex, int itemIndex)
224 {
225         return ScrollToItem(groupIndex, itemIndex, LIST_SCROLL_ITEM_ALIGNMENT_TOP);
226 }
227
228 result
229 GroupedListView::ScrollToItem(int groupIndex, int itemIndex, ListScrollItemAlignment itemAlignment)
230 {
231         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
232         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
233
234         return pImpl->ScrollToItem(groupIndex, itemIndex, itemAlignment);
235 }
236
237 result
238 GroupedListView::SetItemChecked(int groupIndex, int itemIndex, bool check)
239 {
240         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
241         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
242
243         return pImpl->SetItemChecked(groupIndex, itemIndex, check);
244 }
245
246 bool
247 GroupedListView::IsItemChecked(int groupIndex, int itemIndex) const
248 {
249         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
250         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
251
252         return pImpl->IsItemChecked(groupIndex, itemIndex);
253 }
254
255 result
256 GroupedListView::SetItemEnabled(int groupIndex, int itemIndex, bool enable)
257 {
258         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
259         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
260
261         return pImpl->SetItemEnabled(groupIndex, itemIndex, enable);
262 }
263
264 bool
265 GroupedListView::IsItemEnabled(int groupIndex, int itemIndex) const
266 {
267         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
268         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
269
270         return pImpl->IsItemEnabled(groupIndex, itemIndex);
271 }
272
273 int
274 GroupedListView::GetGroupCount(void) const
275 {
276         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
277         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
278
279         return pImpl->GetGroupCount();
280 }
281
282 int
283 GroupedListView::GetItemCountAt(int groupIndex) const
284 {
285         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
286         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
287
288         return pImpl->GetItemCountAt(groupIndex);
289 }
290
291 result
292 GroupedListView::ShowItemDescriptionText(int groupIndex, int itemIndex)
293 {
294         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
295         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
296
297         return pImpl->ShowItemDescriptionText(groupIndex, itemIndex);
298 }
299
300 result
301 GroupedListView::HideItemDescriptionText(int groupIndex, int itemIndex)
302 {
303         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
304         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
305
306         return pImpl->HideItemDescriptionText(groupIndex, itemIndex);
307 }
308
309 result
310 GroupedListView::RefreshList(int groupIndex, int itemIndex, ListRefreshType type)
311 {
312         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
313         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
314
315         return pImpl->RefreshList(groupIndex, itemIndex, type);
316 }
317
318 result
319 GroupedListView::RefreshList(int groupIndex, int itemIndex, int elementId)
320 {
321         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
322         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
323
324         return pImpl->RefreshList(groupIndex, itemIndex, elementId);
325 }
326
327 result
328 GroupedListView::UpdateList(void)
329 {
330         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
331         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
332
333         return pImpl->UpdateList();
334 }
335
336 result
337 GroupedListView::GetItemIndexFromPosition(int x, int y, int& groupIndex, int& itemIndex) const
338 {
339         return GetItemIndexFromPosition(Point(x, y), groupIndex, itemIndex);
340 }
341
342 result
343 GroupedListView::GetItemIndexFromPosition(const Point& position, int& groupIndex, int& itemIndex) const
344 {
345         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
346         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
347
348         return pImpl->GetItemIndexFromPosition(position, groupIndex, itemIndex);
349 }
350
351 result
352 GroupedListView::GetItemIndexFromPosition(int x, int y, int& groupIndex, int& itemIndex, int& elementId) const
353 {
354         return GetItemIndexFromPosition(Point(x, y), groupIndex, itemIndex, elementId);
355 }
356
357 result
358 GroupedListView::GetItemIndexFromPosition(const Point& position, int& groupIndex, int& itemIndex, int& elementId) const
359 {
360         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
361         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
362
363         return pImpl->GetItemIndexFromPosition(position, groupIndex, itemIndex, elementId);
364 }
365
366 result
367 GroupedListView::SetSectionColor(const Color& color)
368 {
369         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
370         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
371
372         return pImpl->SetSectionColor(color);
373 }
374
375 Color
376 GroupedListView::GetSectionColor(void) const
377 {
378         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
379         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
380
381         return pImpl->GetSectionColor();
382 }
383
384 result
385 GroupedListView::SetItemDividerColor(const Color& color)
386 {
387         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
388         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
389
390         return pImpl->SetItemDividerColor(color);
391 }
392
393 Color
394 GroupedListView::GetItemDividerColor(void) const
395 {
396         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
397         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
398
399         return pImpl->GetItemDividerColor();
400 }
401
402 result
403 GroupedListView::SetBackgroundColor(const Color& color)
404 {
405         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
406         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
407
408         pImpl->SetListBackgroundColor(color);
409
410         return E_SUCCESS;
411 }
412
413 Color
414 GroupedListView::GetBackgroundColor(void) const
415 {
416         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
417         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
418
419         return pImpl->GetBackgroundColor();
420 }
421
422 result
423 GroupedListView::SetBackgroundBitmap(const Bitmap* pBitmap)
424 {
425         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
426         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
427
428         return pImpl->SetBackgroundBitmap(pBitmap);
429 }
430
431 result
432 GroupedListView::SetBitmapOfEmptyList(const Bitmap* pBitmap)
433 {
434         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
435         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
436
437         return pImpl->SetBitmapOfEmptyList(pBitmap);
438 }
439
440 result
441 GroupedListView::SetTextOfEmptyList(const String& text)
442 {
443         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
444         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
445
446         return pImpl->SetTextOfEmptyList(text);
447 }
448
449 String
450 GroupedListView::GetTextOfEmptyList(void) const
451 {
452         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
453         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
454
455         return pImpl->GetTextOfEmptyList();
456 }
457
458 result
459 GroupedListView::SetTextColorOfEmptyList(const Color& color)
460 {
461         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
462         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
463
464         return pImpl->SetTextColorOfEmptyList(color);
465 }
466
467 Color
468 GroupedListView::GetTextColorOfEmptyList(void) const
469 {
470         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
471         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
472
473         return pImpl->GetTextColorOfEmptyList();
474 }
475
476 result
477 GroupedListView::ExpandGroup(int groupIndex)
478 {
479         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
480         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
481
482         return pImpl->ExpandGroup(groupIndex);
483 }
484
485 result
486 GroupedListView::CollapseGroup(int groupIndex)
487 {
488         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
489         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
490
491         return pImpl->CollapseGroup(groupIndex);
492 }
493
494 bool
495 GroupedListView::IsGroupExpanded(int groupIndex) const
496 {
497         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
498         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
499
500         return pImpl->IsGroupExpanded(groupIndex);
501 }
502
503 result
504 GroupedListView::BeginReorderingMode(void)
505 {
506         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
507         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
508
509         return pImpl->BeginReorderingMode();
510 }
511
512 result
513 GroupedListView::EndReorderingMode(void)
514 {
515         _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
516         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
517
518         return pImpl->EndReorderingMode();
519 }
520
521 bool
522 GroupedListView::IsInReorderingMode(void) const
523 {
524         const _GroupedListViewImpl* pImpl = _GroupedListViewImpl::GetInstance(*this);
525         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
526
527         return pImpl->IsInReorderingMode();
528 }
529
530 }}} //Tizen::Ui::Controls