Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlSectionTableView.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                 FUiCtrlSectionTableView.cpp
20 * @brief                This is the implementation file for SectionTableView class.
21 *
22 * This header file contains the implementation of SectionTableView class.
23 */
24
25 #include <FUiContainer.h>
26 #include <FUiCtrlSectionTableView.h>
27 #include <FUiCtrlISectionTableViewItemProvider.h>
28 #include <FUiCtrlISectionTableViewItemEventListener.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 /// SectionTableView class
39
40 SectionTableView::SectionTableView(void)
41 {
42 }
43
44 SectionTableView::~SectionTableView(void)
45 {
46 }
47
48 result
49 SectionTableView::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_SECTION, 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 SectionTableView::SetItemProvider(ISectionTableViewItemProvider* pProvider)
76 {
77         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
78         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
79
80         pImpl->SetSectionStyleItemProvider(pProvider);
81 }
82
83
84 result
85 SectionTableView::AddSectionTableViewItemEventListener(ISectionTableViewItemEventListener& 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->AddSectionTableViewItemEventListener(listener);
91 }
92
93 result
94 SectionTableView::RemoveSectionTableViewItemEventListener(ISectionTableViewItemEventListener& 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->RemoveSectionTableViewItemEventListener(listener);
100 }
101
102 result
103 SectionTableView::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 SectionTableView::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 SectionTableView::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 SectionTableView::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 result
139 SectionTableView::SetFastScrollIndex(const String& text, bool useSearchIcon)
140 {
141         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
142         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
143
144         return pImpl->SetFastScrollIndex(text, useSearchIcon);
145 }
146
147 result
148 SectionTableView::GetTopDrawnItemIndex(int& sectionIndex, int& itemIndex) const
149 {
150         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
151         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
152
153         return pImpl->GetTopDrawnItemIndex(sectionIndex, itemIndex);
154 }
155
156 result
157 SectionTableView::GetBottomDrawnItemIndex(int& sectionIndex, int& itemIndex) const
158 {
159         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
160         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
161
162
163         return pImpl->GetBottomDrawnItemIndex(sectionIndex, itemIndex);
164 }
165
166 result
167 SectionTableView::SetItemChecked(int sectionIndex, int itemIndex, bool check)
168 {
169         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
170         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
171
172         return pImpl->SetItemChecked(sectionIndex, itemIndex, check);
173 }
174
175 bool
176 SectionTableView::IsItemChecked(int sectionIndex, int itemIndex) const
177 {
178         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
179         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
180
181         return pImpl->IsItemChecked(sectionIndex, itemIndex);
182 }
183
184 result
185 SectionTableView::SetItemEnabled(int sectionIndex, int itemIndex, bool enable)
186 {
187         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
188         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
189
190         return pImpl->SetItemEnabled(sectionIndex, itemIndex, enable);
191 }
192
193 bool
194 SectionTableView::IsItemEnabled(int sectionIndex, int itemIndex) const
195 {
196         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
197         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
198
199         return pImpl->IsItemEnabled(sectionIndex, itemIndex);
200 }
201
202 int
203 SectionTableView::GetSectionCount(void) const
204 {
205         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
206         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
207
208         return pImpl->GetGroupCount();
209 }
210
211 int
212 SectionTableView::GetItemCountAt(int sectionIndex) const
213 {
214         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
215         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
216
217         return pImpl->GetItemCountAt(sectionIndex);
218 }
219
220 result
221 SectionTableView::RefreshItem(int sectionIndex, int itemIndex, TableViewRefreshType type)
222 {
223         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
224         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
225
226         return pImpl->RefreshTableView(sectionIndex, itemIndex, type);
227 }
228
229 void
230 SectionTableView::UpdateTableView(void)
231 {
232         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
233         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
234
235         pImpl->UpdateTableView();
236 }
237
238 result
239 SectionTableView::GetItemIndexFromPosition(const Tizen::Graphics::Point& position, int& sectionIndex, int& itemIndex) const
240 {
241         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
242         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
243
244         return pImpl->GetItemIndexFromPosition(position, sectionIndex, itemIndex);
245 }
246
247 void
248 SectionTableView::SetSectionColor(const Color& color)
249 {
250         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
251         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
252
253         pImpl->SetSectionColor(color);
254 }
255
256 Color
257 SectionTableView::GetSectionColor(void) const
258 {
259         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
260         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
261
262         return pImpl->GetSectionColor();
263 }
264
265 void
266 SectionTableView::SetItemDividerColor(const Color& color)
267 {
268         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
269         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
270
271         pImpl->SetItemDividerColor(color);
272 }
273
274 Color
275 SectionTableView::GetItemDividerColor(void) const
276 {
277         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
278         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
279
280         return pImpl->GetItemDividerColor();
281 }
282
283 void
284 SectionTableView::SetBackgroundColor(const Color& color)
285 {
286         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
287         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
288
289         pImpl->SetBackgroundColor(color);
290
291         return;
292 }
293
294 Color
295 SectionTableView::GetBackgroundColor(void) const
296 {
297         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
298         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
299
300         return pImpl->GetBackgroundColor();
301 }
302
303 void
304 SectionTableView::SetGroupedLookEnabled(bool enable)
305 {
306         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
307         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
308
309         pImpl->SetGroupedLookEnabled(enable);
310 }
311
312 bool
313 SectionTableView::IsGroupedLookEnabled(void) const
314 {
315         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
316         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
317
318         return pImpl->IsGroupedLookEnabled();
319 }
320
321 result
322 SectionTableView::ScrollToItem(int sectionIndex, int itemIndex, TableViewScrollItemAlignment itemAlignment)
323 {
324         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
325         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
326
327         result r = pImpl->ScrollToItem(sectionIndex, itemIndex, itemAlignment);
328         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
329
330         return r;
331 }
332
333 result
334 SectionTableView::ScrollByPixel(int scrollDistance)
335 {
336         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
337         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
338
339         result r = pImpl->ScrollByPixel(scrollDistance);
340         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
341
342         return r;
343 }
344
345 int
346 SectionTableView::GetCurrentScrollPosition(void) const
347 {
348         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
349         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
350
351         return pImpl->GetCurrentScrollPosition();
352 }
353
354 void
355 SectionTableView::SetScrollEnabled(bool enable)
356 {
357         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
358         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
359
360          pImpl->SetScrollEnabled(enable);
361
362         return;
363 }
364
365 bool
366 SectionTableView::IsScrollEnabled(void) const
367 {
368         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
369         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
370
371         return pImpl->IsScrollEnabled();
372 }
373
374 void
375 SectionTableView::SetScrollInputMode(ScrollInputMode mode)
376 {
377         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
378         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
379
380         pImpl->SetScrollInputMode(mode);
381 }
382
383 ScrollInputMode
384 SectionTableView::GetScrollInputMode(void) const
385 {
386         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
387         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
388
389         return pImpl->GetScrollInputMode();
390 }
391
392 }}} //Tizen::Ui::Controls