Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrlGroupedTableView.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
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                 FUiCtrlGroupedTableView.cpp
20 * @brief                This is the implementation file for GroupedTableView class.
21 *
22 * This header file contains the implementation of GroupedTableView class.
23 */
24
25 #include <FUiContainer.h>
26 #include <FUiCtrlGroupedTableView.h>
27 #include <FUiCtrlIGroupedTableViewItemProvider.h>
28 #include <FUiCtrlIGroupedTableViewItemProviderF.h>
29 #include <FUiCtrlIGroupedTableViewItemEventListener.h>
30 #include "FUiCtrl_TableViewImpl.h"
31 #include "FUi_CoordinateSystemUtils.h"
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Graphics;
35
36 namespace Tizen { namespace Ui { namespace Controls
37 {
38
39 ////////////////////////////////////////////////////////////////////////////////
40 /// GroupedTableView class
41
42 GroupedTableView::GroupedTableView(void)
43 {
44 }
45
46 GroupedTableView::~GroupedTableView(void)
47 {
48 }
49
50 result
51 GroupedTableView::Construct(const Tizen::Graphics::Rectangle& rect, bool itemDivider, TableViewScrollBarStyle scrollStyle)
52 {
53         result r = E_SUCCESS;
54
55         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
56         SysAssertf(pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
57
58         pImpl = _TableViewImpl::CreateTableViewImplN(this, _CoordinateSystemUtils::ConvertToFloat(rect), TABLE_VIEW_STYLE_GROUPED, itemDivider, scrollStyle);
59
60         r = GetLastResult();
61         SysTryReturn(NID_UI_CTRL, pImpl != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
62
63         _pControlImpl = pImpl;
64
65         r = SetBounds(rect);
66         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
67
68         return E_SUCCESS;
69
70 CATCH:
71         Control::Dispose();
72
73         return r;
74 }
75
76 result
77 GroupedTableView::Construct(const Tizen::Graphics::FloatRectangle& rect, bool itemDivider, TableViewScrollBarStyle scrollStyle)
78 {
79         result r = E_SUCCESS;
80
81         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
82         SysAssertf(pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
83
84         pImpl = _TableViewImpl::CreateTableViewImplN(this, rect, TABLE_VIEW_STYLE_GROUPED, itemDivider, scrollStyle);
85
86         r = GetLastResult();
87         SysTryReturn(NID_UI_CTRL, pImpl != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
88
89         _pControlImpl = pImpl;
90
91         r = SetBounds(rect);
92         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating", GetErrorMessage(r));
93
94         return E_SUCCESS;
95
96 CATCH:
97         Control::Dispose();
98
99         return r;
100 }
101
102 void
103 GroupedTableView::SetItemProvider(IGroupedTableViewItemProvider* pProvider)
104 {
105         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
106         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
107
108         pImpl->SetGroupedStyleItemProvider(pProvider);
109 }
110
111 void
112 GroupedTableView::SetItemProviderF(IGroupedTableViewItemProviderF* pProvider)
113 {
114         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
115         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
116
117         pImpl->SetGroupedStyleItemProviderF(pProvider);
118 }
119
120 result
121 GroupedTableView::AddGroupedTableViewItemEventListener(IGroupedTableViewItemEventListener& listener)
122 {
123         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
124         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
125
126         return pImpl->AddGroupedTableViewItemEventListener(listener);
127 }
128
129 result
130 GroupedTableView::RemoveGroupedTableViewItemEventListener(IGroupedTableViewItemEventListener& listener)
131 {
132         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
133         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
134
135         return pImpl->RemoveGroupedTableViewItemEventListener(listener);
136 }
137
138 result
139 GroupedTableView::AddFastScrollListener(IFastScrollListener& listener)
140 {
141         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
142         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
143
144         return pImpl->AddFastScrollListener(listener);
145 }
146
147 result
148 GroupedTableView::RemoveFastScrollListener(IFastScrollListener& listener)
149 {
150         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
151         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
152
153         return pImpl->RemoveFastScrollListener(listener);
154 }
155
156 result
157 GroupedTableView::AddScrollEventListener(IScrollEventListener& listener)
158 {
159         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
160         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
161
162         return pImpl->AddScrollEventListener(listener);
163 }
164
165 result
166 GroupedTableView::RemoveScrollEventListener(IScrollEventListener& listener)
167 {
168         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
169         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
170
171         return pImpl->RemoveScrollEventListener(listener);
172 }
173
174 result
175 GroupedTableView::AddScrollEventListener(IScrollEventListenerF& listener)
176 {
177         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
178         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
179
180         return pImpl->AddScrollEventListener(listener);
181 }
182
183 result
184 GroupedTableView::RemoveScrollEventListener(IScrollEventListenerF& listener)
185 {
186         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
187         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
188
189         return pImpl->RemoveScrollEventListener(listener);
190 }
191
192 void
193 GroupedTableView::SetCollapseByPinchGestureEnabled(bool enable)
194 {
195
196         //TODO : seperate
197 }
198
199 bool
200 GroupedTableView::IsCollapseByPinchGestureEnabled(void) const
201 {
202         //TODO : seperate
203         return false;
204 }
205
206 result
207 GroupedTableView::SetFastScrollIndex(const String& text, bool useSearchIcon)
208 {
209         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
210         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
211
212         return pImpl->SetFastScrollIndex(text, useSearchIcon);
213 }
214
215 result
216 GroupedTableView::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
217 {
218         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
219         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
220
221         return pImpl->GetTopDrawnItemIndex(groupIndex, itemIndex);
222 }
223
224 result
225 GroupedTableView::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
226 {
227         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
228         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
229
230
231         return pImpl->GetBottomDrawnItemIndex(groupIndex, itemIndex);
232 }
233
234 result
235 GroupedTableView::SetItemChecked(int groupIndex, int itemIndex, bool check)
236 {
237         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
238         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
239
240         return pImpl->SetItemChecked(groupIndex, itemIndex, check);
241 }
242
243 bool
244 GroupedTableView::IsItemChecked(int groupIndex, int itemIndex) const
245 {
246         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
247         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
248
249         return pImpl->IsItemChecked(groupIndex, itemIndex);
250 }
251
252 result
253 GroupedTableView::SetItemEnabled(int groupIndex, int itemIndex, bool enable)
254 {
255         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
256         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
257
258         return pImpl->SetItemEnabled(groupIndex, itemIndex, enable);
259 }
260
261 bool
262 GroupedTableView::IsItemEnabled(int groupIndex, int itemIndex) const
263 {
264         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
265         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
266
267         return pImpl->IsItemEnabled(groupIndex, itemIndex);
268 }
269
270 int
271 GroupedTableView::GetGroupCount(void) const
272 {
273         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
274         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
275
276         return pImpl->GetGroupCount();
277 }
278
279 int
280 GroupedTableView::GetItemCountAt(int groupIndex) const
281 {
282         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
283         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
284
285         return pImpl->GetItemCountAt(groupIndex);
286 }
287
288 result
289 GroupedTableView::RefreshItem(int groupIndex, int itemIndex, TableViewRefreshType type)
290 {
291         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
292         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
293
294         return pImpl->RefreshTableView(groupIndex, itemIndex, type);
295 }
296
297 result
298 GroupedTableView::RefreshAllItems(void)
299 {
300         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
301         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
302
303         return pImpl->RefreshAllItems();
304 }
305
306 void
307 GroupedTableView::UpdateTableView(void)
308 {
309         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
310         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
311
312         pImpl->UpdateTableView();
313 }
314
315 void
316 GroupedTableView::GetItemIndexFromPosition(const Tizen::Graphics::Point& position, int& groupIndex, int& itemIndex) const
317 {
318         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
319         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
320
321         pImpl->GetItemIndexFromPosition(position, groupIndex, itemIndex);
322 }
323
324 void
325 GroupedTableView::GetItemIndexFromPosition(const Tizen::Graphics::FloatPoint& position, int& groupIndex, int& itemIndex) const
326 {
327         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
328         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
329
330         pImpl->GetItemIndexFromPosition(position, groupIndex, itemIndex);
331 }
332
333 void
334 GroupedTableView::SetItemDividerColor(const Color& color)
335 {
336         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
337         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
338
339         pImpl->SetItemDividerColor(color);
340 }
341
342 Color
343 GroupedTableView::GetItemDividerColor(void) const
344 {
345         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
346         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
347
348         return pImpl->GetItemDividerColor();
349 }
350
351 void
352 GroupedTableView::SetBackgroundColor(const Color& color)
353 {
354         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
355         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
356
357         pImpl->SetBackgroundColor(color);
358
359         return;
360 }
361
362 Color
363 GroupedTableView::GetBackgroundColor(void) const
364 {
365         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
366         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
367
368         return pImpl->GetBackgroundColor();
369 }
370
371 result
372 GroupedTableView::ExpandGroup(int groupIndex)
373 {
374         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
375         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
376
377         return pImpl->ExpandGroup(groupIndex);
378 }
379
380 result
381 GroupedTableView::CollapseGroup(int groupIndex)
382 {
383         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
384         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
385
386         return pImpl->CollapseGroup(groupIndex);
387 }
388
389 result
390 GroupedTableView::ExpandAllGroups(void)
391 {
392         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
393         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
394
395         return pImpl->ExpandAllGroup();
396 }
397
398 result
399 GroupedTableView::CollapseAllGroups(void)
400 {
401         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
402         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
403
404         return pImpl->CollapseAllGroup();
405 }
406
407 bool
408 GroupedTableView::IsGroupExpanded(int groupIndex) const
409 {
410         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
411         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
412
413         return pImpl->IsGroupExpanded(groupIndex);
414 }
415
416 void
417 GroupedTableView::SetGroupedLookEnabled(bool enable)
418 {
419         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
420         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
421
422         pImpl->SetGroupedLookEnabled(enable);
423 }
424
425 bool
426 GroupedTableView::IsGroupedLookEnabled(void) const
427 {
428         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
429         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
430
431         return pImpl->IsGroupedLookEnabled();
432 }
433
434 result
435 GroupedTableView::ScrollToItem(int groupIndex, int itemIndex, TableViewScrollItemAlignment itemAlignment)
436 {
437         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
438         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
439
440         result r = pImpl->ScrollToItem(groupIndex, itemIndex, itemAlignment);
441         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
442
443         return r;
444 }
445
446 result
447 GroupedTableView::ScrollByPixel(int pixel)
448 {
449         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
450         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
451
452         result r = pImpl->ScrollByPixel(_CoordinateSystemUtils::ConvertToFloat(pixel));
453         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
454
455         return r;
456 }
457
458 result
459 GroupedTableView::ScrollByPixel(float pixel)
460 {
461         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
462         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
463
464         result r = pImpl->ScrollByPixel(pixel);
465         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
466
467         return r;
468 }
469
470 int
471 GroupedTableView::GetCurrentScrollPosition(void) const
472 {
473         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
474         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
475
476         return _CoordinateSystemUtils::ConvertToInteger(pImpl->GetCurrentScrollPosition());
477 }
478
479 float
480 GroupedTableView::GetCurrentScrollPositionF(void) const
481 {
482         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
483         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
484
485         return pImpl->GetCurrentScrollPosition();
486 }
487
488 void
489 GroupedTableView::SetScrollInputMode(ScrollInputMode mode)
490 {
491         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
492         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
493
494         pImpl->SetScrollInputMode(mode);
495 }
496
497 ScrollInputMode
498 GroupedTableView::GetScrollInputMode(void) const
499 {
500         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
501         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
502
503         return pImpl->GetScrollInputMode();
504 }
505
506 //void
507 //GroupedTableView::BeginReorderingMode(void)
508 //{
509 //      _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
510 //      SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
511 //
512 //      pImpl->BeginReorderingMode();
513 //}
514 //
515 //void
516 //GroupedTableView::EndReorderingMode(void)
517 //{
518 //      _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
519 //      SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
520 //
521 //      pImpl->EndReorderingMode();
522 //}
523 //
524 //bool
525 //GroupedTableView::IsInReorderingMode(void) const
526 //{
527 //      const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
528 //      SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
529 //
530 //      return pImpl->IsInReorderingMode();
531 //}
532
533 void
534 GroupedTableView::SetScrollEnabled(bool enable)
535 {
536         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
537         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
538
539         pImpl->SetScrollEnabled(enable);
540 }
541
542 bool
543 GroupedTableView::IsScrollEnabled(void) const
544 {
545         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
546         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
547
548         return pImpl->IsScrollEnabled();
549 }
550
551 void
552 GroupedTableView::BeginReorderingMode(void)
553 {
554         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
555         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
556
557         pImpl->BeginReorderingMode();
558 }
559
560 void
561 GroupedTableView::EndReorderingMode(void)
562 {
563         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
564         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
565
566         pImpl->EndReorderingMode();
567 }
568
569 bool
570 GroupedTableView::IsInReorderingMode(void) const
571 {
572         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
573         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
574
575         return pImpl->IsInReorderingMode();
576 }
577
578 result
579 GroupedTableView::OpenContextItem(int groupIndex, int itemIndex)
580 {
581         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
582         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
583
584         return pImpl->OpenContextItem(groupIndex, itemIndex);
585 }
586
587 result
588 GroupedTableView::CloseContextItem(int groupIndex, int itemIndex)
589 {
590         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
591         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
592
593         return pImpl->CloseContextItem(groupIndex, itemIndex);
594 }
595
596 bool
597 GroupedTableView::IsContextItemOpened(int groupIndex, int itemIndex) const
598 {
599         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
600         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
601
602         return pImpl->IsContextItemOpened(groupIndex, itemIndex);
603 }
604
605 }}} //Tizen::Ui::Controls