Tizen 2.1 base
[framework/osp/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 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                 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 <FUiCtrlITableViewItemEventListener.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 /// TableView class
39
40 TableView::TableView(void)
41 {
42 }
43
44 TableView::~TableView(void)
45 {
46 }
47
48 result
49 TableView::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_SIMPLE, 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 TableView::SetItemProvider(ITableViewItemProvider* pProvider)
76 {
77         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
78         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
79
80         pImpl->SetSimpleStyleItemProvider(pProvider);
81 }
82
83 result
84 TableView::AddTableViewItemEventListener(ITableViewItemEventListener& listener)
85 {
86         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
87         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
88
89         return pImpl->AddTableViewItemEventListener(listener);
90 }
91
92 result
93 TableView::RemoveTableViewItemEventListener(ITableViewItemEventListener& listener)
94 {
95         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
96         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
97
98         return pImpl->RemoveTableViewItemEventListener(listener);
99 }
100
101 result
102 TableView::AddFastScrollListener(IFastScrollListener& listener)
103 {
104         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
105         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
106
107         return pImpl->AddFastScrollListener(listener);
108 }
109
110 result
111 TableView::RemoveFastScrollListener(IFastScrollListener& listener)
112 {
113         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
114         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
115
116         return pImpl->RemoveFastScrollListener(listener);
117 }
118
119 result
120 TableView::AddScrollEventListener(IScrollEventListener& listener)
121 {
122         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
123         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
124
125         return pImpl->AddScrollEventListener(listener);
126 }
127
128 result
129 TableView::RemoveScrollEventListener(IScrollEventListener& listener)
130 {
131         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
132         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
133
134         return pImpl->RemoveScrollEventListener(listener);
135 }
136
137 result
138 TableView::SetFastScrollIndex(const String& text, bool useSearchIcon)
139 {
140         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
141         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
142
143         return pImpl->SetFastScrollIndex(text, useSearchIcon);
144 }
145
146 int
147 TableView::GetTopDrawnItemIndex(void) const
148 {
149         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
150         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
151
152         int itemIndex = -1;
153         int groupIndex = -1;
154         pImpl->GetTopDrawnItemIndex(groupIndex, itemIndex);
155
156         return itemIndex;
157 }
158
159 int
160 TableView::GetBottomDrawnItemIndex(void) const
161 {
162         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
163         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
164
165         int itemIndex = -1;
166         int groupIndex = -1;
167         pImpl->GetBottomDrawnItemIndex(groupIndex, itemIndex);
168
169         return itemIndex;
170 }
171
172 result
173 TableView::ScrollToItem(int itemIndex, TableViewScrollItemAlignment itemAlignment)
174 {
175         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
176         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
177
178         result r = pImpl->ScrollToItem(0, itemIndex, itemAlignment);
179         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
180
181         return r;
182 }
183
184 result
185 TableView::SetItemChecked(int itemIndex, bool check)
186 {
187         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
188         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
189
190         return pImpl->SetItemChecked(0, itemIndex, check);
191 }
192
193 bool
194 TableView::IsItemChecked(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->IsItemChecked(0, itemIndex);
200 }
201
202 result
203 TableView::SetItemEnabled(int itemIndex, bool enable)
204 {
205         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
206         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
207
208         return pImpl->SetItemEnabled(0, itemIndex, enable);
209 }
210
211 bool
212 TableView::IsItemEnabled(int itemIndex) 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->IsItemEnabled(0, itemIndex);
218 }
219
220 int
221 TableView::GetItemCount(void) const
222 {
223         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
224         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
225
226         return pImpl->GetItemCountAt(0);
227 }
228
229 result
230 TableView::RefreshItem(int itemIndex, TableViewRefreshType type)
231 {
232         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
233         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
234
235         return pImpl->RefreshTableView(0, itemIndex, type);
236 }
237
238 void
239 TableView::UpdateTableView(void)
240 {
241         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
242         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
243
244         pImpl->UpdateTableView();
245 }
246
247 int
248 TableView::GetItemIndexFromPosition(const Point& position) const
249 {
250         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
251         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
252
253         int itemIndex = -1;
254         int groupIndex = -1;
255
256         pImpl->GetItemIndexFromPosition(position, groupIndex, itemIndex);
257
258         return itemIndex;
259 }
260
261 void
262 TableView::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 TableView::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 TableView::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 TableView::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 void
300 TableView::BeginReorderingMode(void)
301 {
302         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
303         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
304
305         pImpl->BeginReorderingMode();
306 }
307
308 void
309 TableView::EndReorderingMode(void)
310 {
311         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
312         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
313
314         pImpl->EndReorderingMode();
315 }
316
317 bool
318 TableView::IsInReorderingMode(void) const
319 {
320         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
321         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
322
323         return pImpl->IsInReorderingMode();
324 }
325
326 result
327 TableView::ScrollByPixel(int scrollDistance)
328 {
329         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
330         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
331
332         result r = pImpl->ScrollByPixel(scrollDistance);
333         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
334
335         return r;
336 }
337
338 int
339 TableView::GetCurrentScrollPosition(void) const
340 {
341         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
342         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
343
344         return pImpl->GetCurrentScrollPosition();
345 }
346
347 void
348 TableView::SetScrollEnabled(bool enable)
349 {
350         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
351         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
352
353          pImpl->SetScrollEnabled(enable);
354
355         return;
356 }
357
358 bool
359 TableView::IsScrollEnabled(void) const
360 {
361         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
362         SysAssertf(pImpl != null, "Not yet constructed. Construct() should be called before use.");
363
364         return pImpl->IsScrollEnabled();
365 }
366
367 void
368 TableView::SetScrollInputMode(ScrollInputMode mode)
369 {
370         _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
371         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
372
373         pImpl->SetScrollInputMode(mode);
374 }
375
376 ScrollInputMode
377 TableView::GetScrollInputMode(void) const
378 {
379         const _TableViewImpl* pImpl = _TableViewImpl::GetInstance(*this);
380         SysAssertf(pImpl != null, "Not-yet constructed! Construct() should be called before use.");
381
382         return pImpl->GetScrollInputMode();
383 }
384
385
386 }}} //Tizen::Ui::Controls