Fork for IVI: mesa fixing
[profile/ivi/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 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                 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 <FUiCtrlIGroupedTableViewItemEventListener.h>
29 #include "FUiCtrl_TableViewImpl.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Graphics;
33
34 namespace Tizen { namespace Ui { namespace Controls
35 {
36
37 ////////////////////////////////////////////////////////////////////////////////
38 /// GroupedTableView class
39
40 GroupedTableView::GroupedTableView(void)
41 {
42 }
43
44 GroupedTableView::~GroupedTableView(void)
45 {
46 }
47
48 result
49 GroupedTableView::Construct(const Tizen::Graphics::Rectangle& rect, bool itemDivider, TableViewScrollBarStyle scrollStyle)
50 {
51         result r = E_SUCCESS;
52
53         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
54         SysAssertf(pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
55
56         pImpl = _TableViewImpl::CreateTableViewImplN(this, rect, TABLE_VIEW_STYLE_GROUPED, itemDivider, scrollStyle);
57
58         r = GetLastResult();
59         SysTryReturn(NID_UI_CTRL, pImpl != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
60
61         _pControlImpl = pImpl;
62
63         r = SetBounds(rect);
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 void
75 GroupedTableView::SetItemProvider(IGroupedTableViewItemProvider* pProvider)
76 {
77         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
78         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
79
80         pImpl->SetGroupedStyleItemProvider(pProvider);
81 }
82
83
84 result
85 GroupedTableView::AddGroupedTableViewItemEventListener(IGroupedTableViewItemEventListener& listener)
86 {
87         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
88         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
89
90         return pImpl->AddGroupedTableViewItemEventListener(listener);
91 }
92
93 result
94 GroupedTableView::RemoveGroupedTableViewItemEventListener(IGroupedTableViewItemEventListener& listener)
95 {
96         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
97         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
98
99         return pImpl->RemoveGroupedTableViewItemEventListener(listener);
100 }
101
102 result
103 GroupedTableView::AddFastScrollListener(IFastScrollListener& listener)
104 {
105         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
106         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
107
108         return pImpl->AddFastScrollListener(listener);
109 }
110
111 result
112 GroupedTableView::RemoveFastScrollListener(IFastScrollListener& listener)
113 {
114         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
115         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
116
117         return pImpl->RemoveFastScrollListener(listener);
118 }
119
120 result
121 GroupedTableView::AddScrollEventListener(IScrollEventListener& 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->AddScrollEventListener(listener);
127 }
128
129 result
130 GroupedTableView::RemoveScrollEventListener(IScrollEventListener& 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->RemoveScrollEventListener(listener);
136 }
137
138 void
139 GroupedTableView::SetCollapseByPinchGestureEnabled(bool enable)
140 {
141
142         //TODO : seperate
143 }
144
145 bool
146 GroupedTableView::IsCollapseByPinchGestureEnabled(void) const
147 {
148         //TODO : seperate
149         return false;
150 }
151
152 result
153 GroupedTableView::SetFastScrollIndex(const String& text, bool useSearchIcon)
154 {
155         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
156         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
157
158         return pImpl->SetFastScrollIndex(text, useSearchIcon);
159 }
160
161 result
162 GroupedTableView::GetTopDrawnItemIndex(int& groupIndex, int& itemIndex) const
163 {
164         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
165         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
166
167         return pImpl->GetTopDrawnItemIndex(groupIndex, itemIndex);
168 }
169
170 result
171 GroupedTableView::GetBottomDrawnItemIndex(int& groupIndex, int& itemIndex) const
172 {
173         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
174         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
175
176
177         return pImpl->GetBottomDrawnItemIndex(groupIndex, itemIndex);
178 }
179
180 result
181 GroupedTableView::SetItemChecked(int groupIndex, int itemIndex, bool check)
182 {
183         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
184         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
185
186         return pImpl->SetItemChecked(groupIndex, itemIndex, check);
187 }
188
189 bool
190 GroupedTableView::IsItemChecked(int groupIndex, int itemIndex) const
191 {
192         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
193         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
194
195         return pImpl->IsItemChecked(groupIndex, itemIndex);
196 }
197
198 result
199 GroupedTableView::SetItemEnabled(int groupIndex, int itemIndex, bool enable)
200 {
201         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
202         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
203
204         return pImpl->SetItemEnabled(groupIndex, itemIndex, enable);
205 }
206
207 bool
208 GroupedTableView::IsItemEnabled(int groupIndex, int itemIndex) const
209 {
210         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
211         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
212
213         return pImpl->IsItemEnabled(groupIndex, itemIndex);
214 }
215
216 int
217 GroupedTableView::GetGroupCount(void) const
218 {
219         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
220         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
221
222         return pImpl->GetGroupCount();
223 }
224
225 int
226 GroupedTableView::GetItemCountAt(int groupIndex) const
227 {
228         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
229         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
230
231         return pImpl->GetItemCountAt(groupIndex);
232 }
233
234 result
235 GroupedTableView::RefreshItem(int groupIndex, int itemIndex, TableViewRefreshType type)
236 {
237         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
238         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
239
240         return pImpl->RefreshTableView(groupIndex, itemIndex, type);
241 }
242
243 void
244 GroupedTableView::UpdateTableView(void)
245 {
246         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
247         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
248
249         pImpl->UpdateTableView();
250 }
251
252 void
253 GroupedTableView::GetItemIndexFromPosition(const Tizen::Graphics::Point& position, int& groupIndex, int& itemIndex) const
254 {
255         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
256         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
257
258         pImpl->GetItemIndexFromPosition(position, groupIndex, itemIndex);
259 }
260
261 void
262 GroupedTableView::SetItemDividerColor(const Color& color)
263 {
264         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
265         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
266
267         pImpl->SetItemDividerColor(color);
268 }
269
270 Color
271 GroupedTableView::GetItemDividerColor(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->GetItemDividerColor();
277 }
278
279 void
280 GroupedTableView::SetBackgroundColor(const Color& color)
281 {
282         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
283         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
284
285         pImpl->SetBackgroundColor(color);
286
287         return;
288 }
289
290 Color
291 GroupedTableView::GetBackgroundColor(void) const
292 {
293         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
294         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
295
296         return pImpl->GetBackgroundColor();
297 }
298
299 result
300 GroupedTableView::ExpandGroup(int groupIndex)
301 {
302         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
303         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
304
305         return pImpl->ExpandGroup(groupIndex);
306 }
307
308 result
309 GroupedTableView::CollapseGroup(int groupIndex)
310 {
311         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
312         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
313
314         return pImpl->CollapseGroup(groupIndex);
315 }
316
317 void
318 GroupedTableView::ExpandAllGroup(void)
319 {
320         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
321         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
322
323         pImpl->ExpandAllGroup();
324 }
325
326 void
327 GroupedTableView::CollapseAllGroup(void)
328 {
329         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
330         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
331
332         pImpl->CollapseAllGroup();
333 }
334
335 bool
336 GroupedTableView::IsGroupExpanded(int groupIndex) const
337 {
338         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
339         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
340
341         return pImpl->IsGroupExpanded(groupIndex);
342 }
343
344 void
345 GroupedTableView::SetGroupedLookEnabled(bool enable)
346 {
347         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
348         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
349
350         pImpl->SetGroupedLookEnabled(enable);
351 }
352
353 bool
354 GroupedTableView::IsGroupedLookEnabled(void) const
355 {
356         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
357         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
358
359         return pImpl->IsGroupedLookEnabled();
360 }
361
362 result
363 GroupedTableView::ScrollToItem(int groupIndex, int itemIndex, TableViewScrollItemAlignment itemAlignment)
364 {
365         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
366         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
367
368         result r = pImpl->ScrollToItem(groupIndex, itemIndex, itemAlignment);
369         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
370
371         return r;
372 }
373
374 result
375 GroupedTableView::ScrollByPixel(int scrollDistance)
376 {
377         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
378         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
379
380         result r = pImpl->ScrollByPixel(scrollDistance);
381         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
382
383         return r;
384 }
385
386 void
387 GroupedTableView::SetScrollInputMode(ScrollInputMode mode)
388 {
389         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
390         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
391
392         pImpl->SetScrollInputMode(mode);
393 }
394
395 ScrollInputMode
396 GroupedTableView::GetScrollInputMode(void) const
397 {
398         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
399         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
400
401         return pImpl->GetScrollInputMode();
402 }
403
404 //void
405 //GroupedTableView::BeginReorderingMode(void)
406 //{
407 //      _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
408 //      SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
409 //
410 //      pImpl->BeginReorderingMode();
411 //}
412 //
413 //void
414 //GroupedTableView::EndReorderingMode(void)
415 //{
416 //      _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
417 //      SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
418 //
419 //      pImpl->EndReorderingMode();
420 //}
421 //
422 //bool
423 //GroupedTableView::IsInReorderingMode(void) const
424 //{
425 //      const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
426 //      SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
427 //
428 //      return pImpl->IsInReorderingMode();
429 //}
430
431 int
432 GroupedTableView::GetCurrentScrollPosition(void) const
433 {
434         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
435         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
436
437         return pImpl->GetCurrentScrollPosition();
438 }
439
440 void
441 GroupedTableView::SetScrollEnabled(bool enable)
442 {
443         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
444         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
445
446          pImpl->SetScrollEnabled(enable);
447
448         return;
449 }
450
451 bool
452 GroupedTableView::IsScrollEnabled(void) const
453 {
454         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
455         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
456
457         return pImpl->IsScrollEnabled();
458 }
459
460 }}} //Tizen::Ui::Controls