Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrlTableView.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                 FUiCtrlTableView.cpp
20 * @brief                This is the implementation file for TableView class.
21 *
22 * This header file contains the implementation of TableView class.
23 */
24
25 #include <FUiContainer.h>
26 #include <FUiCtrlTableView.h>
27 #include <FUiCtrlITableViewItemProvider.h>
28 #include <FUiCtrlITableViewItemProviderF.h>
29 #include <FUiCtrlITableViewItemEventListener.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 /// TableView class
41
42 TableView::TableView(void)
43 {
44 }
45
46 TableView::~TableView(void)
47 {
48 }
49
50 result
51 TableView::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_SIMPLE, 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 TableView::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_SIMPLE, 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 TableView::SetItemProvider(ITableViewItemProvider* pProvider)
104 {
105         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
106         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
107
108         pImpl->SetSimpleStyleItemProvider(pProvider);
109 }
110
111 void
112 TableView::SetItemProviderF(ITableViewItemProviderF* pProvider)
113 {
114         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
115         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
116
117         pImpl->SetSimpleStyleItemProviderF(pProvider);
118 }
119
120 result
121 TableView::AddTableViewItemEventListener(ITableViewItemEventListener& 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->AddTableViewItemEventListener(listener);
127 }
128
129 result
130 TableView::RemoveTableViewItemEventListener(ITableViewItemEventListener& 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->RemoveTableViewItemEventListener(listener);
136 }
137
138 result
139 TableView::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 TableView::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 TableView::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 TableView::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 TableView::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 TableView::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 result
193 TableView::SetFastScrollIndex(const String& text, bool useSearchIcon)
194 {
195         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
196         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
197
198         return pImpl->SetFastScrollIndex(text, useSearchIcon);
199 }
200
201 int
202 TableView::GetTopDrawnItemIndex(void) const
203 {
204         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
205         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
206
207         int itemIndex = -1;
208         int groupIndex = -1;
209         pImpl->GetTopDrawnItemIndex(groupIndex, itemIndex);
210
211         return itemIndex;
212 }
213
214 int
215 TableView::GetBottomDrawnItemIndex(void) const
216 {
217         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
218         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
219
220         int itemIndex = -1;
221         int groupIndex = -1;
222         pImpl->GetBottomDrawnItemIndex(groupIndex, itemIndex);
223
224         return itemIndex;
225 }
226
227 result
228 TableView::ScrollToItem(int itemIndex, TableViewScrollItemAlignment itemAlignment)
229 {
230         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
231         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
232
233         result r = pImpl->ScrollToItem(0, itemIndex, itemAlignment);
234         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
235
236         return r;
237 }
238
239 result
240 TableView::SetItemChecked(int itemIndex, bool check)
241 {
242         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
243         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
244
245         return pImpl->SetItemChecked(0, itemIndex, check);
246 }
247
248 bool
249 TableView::IsItemChecked(int itemIndex) const
250 {
251         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
252         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
253
254         return pImpl->IsItemChecked(0, itemIndex);
255 }
256
257 result
258 TableView::SetItemEnabled(int itemIndex, bool enable)
259 {
260         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
261         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
262
263         return pImpl->SetItemEnabled(0, itemIndex, enable);
264 }
265
266 bool
267 TableView::IsItemEnabled(int itemIndex) const
268 {
269         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
270         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
271
272         return pImpl->IsItemEnabled(0, itemIndex);
273 }
274
275 int
276 TableView::GetItemCount(void) const
277 {
278         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
279         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
280
281         return pImpl->GetItemCountAt(0);
282 }
283
284 result
285 TableView::RefreshItem(int itemIndex, TableViewRefreshType type)
286 {
287         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
288         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
289
290         return pImpl->RefreshTableView(0, itemIndex, type);
291 }
292
293 result
294 TableView::RefreshAllItems(void)
295 {
296         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
297         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
298
299         return pImpl->RefreshAllItems();
300 }
301
302 void
303 TableView::UpdateTableView(void)
304 {
305         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
306         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
307
308         pImpl->UpdateTableView();
309 }
310
311 int
312 TableView::GetItemIndexFromPosition(const Point& position) const
313 {
314         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
315         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
316
317         int itemIndex = -1;
318         int groupIndex = -1;
319
320         pImpl->GetItemIndexFromPosition(position, groupIndex, itemIndex);
321
322         return itemIndex;
323 }
324
325 int
326 TableView::GetItemIndexFromPosition(const Tizen::Graphics::FloatPoint& position) const
327 {
328         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
329         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
330
331         int itemIndex = -1;
332         int groupIndex = -1;
333
334         pImpl->GetItemIndexFromPosition(position, groupIndex, itemIndex);
335
336         return itemIndex;
337 }
338
339
340 void
341 TableView::SetItemDividerColor(const Color& color)
342 {
343         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
344         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
345
346         pImpl->SetItemDividerColor(color);
347 }
348
349 Color
350 TableView::GetItemDividerColor(void) const
351 {
352         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
353         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
354
355         return pImpl->GetItemDividerColor();
356 }
357
358 void
359 TableView::SetBackgroundColor(const Color& color)
360 {
361         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
362         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
363
364         pImpl->SetBackgroundColor(color);
365
366         return;
367 }
368
369 Color
370 TableView::GetBackgroundColor(void) const
371 {
372         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
373         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
374
375         return pImpl->GetBackgroundColor();
376 }
377
378 void
379 TableView::BeginReorderingMode(void)
380 {
381         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
382         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
383
384         pImpl->BeginReorderingMode();
385 }
386
387 void
388 TableView::EndReorderingMode(void)
389 {
390         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
391         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
392
393         pImpl->EndReorderingMode();
394 }
395
396 bool
397 TableView::IsInReorderingMode(void) const
398 {
399         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
400         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
401
402         return pImpl->IsInReorderingMode();
403 }
404
405 result
406 TableView::ScrollByPixel(int pixel)
407 {
408         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
409         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
410
411         result r = pImpl->ScrollByPixel(_CoordinateSystemUtils::ConvertToFloat(pixel));
412         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
413
414         return r;
415 }
416
417 result
418 TableView::ScrollByPixel(float pixel)
419 {
420         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
421         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
422
423         result r = pImpl->ScrollByPixel(pixel);
424         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
425
426         return r;
427 }
428
429 int
430 TableView::GetCurrentScrollPosition(void) const
431 {
432         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
433         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
434
435         return _CoordinateSystemUtils::ConvertToInteger(pImpl->GetCurrentScrollPosition());
436 }
437
438 float
439 TableView::GetCurrentScrollPositionF(void) const
440 {
441         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
442         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
443
444         return pImpl->GetCurrentScrollPosition();
445 }
446
447
448 void
449 TableView::SetScrollEnabled(bool enable)
450 {
451         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
452         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
453
454          pImpl->SetScrollEnabled(enable);
455
456         return;
457 }
458
459 bool
460 TableView::IsScrollEnabled(void) const
461 {
462         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
463         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
464
465         return pImpl->IsScrollEnabled();
466 }
467
468 void
469 TableView::SetScrollInputMode(ScrollInputMode mode)
470 {
471         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
472         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
473
474         pImpl->SetScrollInputMode(mode);
475 }
476
477 ScrollInputMode
478 TableView::GetScrollInputMode(void) const
479 {
480         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
481         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
482
483         return pImpl->GetScrollInputMode();
484 }
485
486 result
487 TableView::OpenContextItem(int itemIndex)
488 {
489         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
490         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
491
492         return pImpl->OpenContextItem(0, itemIndex);
493 }
494
495 result
496 TableView::CloseContextItem(int itemIndex)
497 {
498         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
499         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
500
501         return pImpl->CloseContextItem(0, itemIndex);
502 }
503
504 bool
505 TableView::IsContextItemOpened(int itemIndex) const
506 {
507         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
508         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
509
510         return pImpl->IsContextItemOpened(0, itemIndex);
511 }
512
513 }}} //Tizen::Ui::Controls