Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlIconList.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  * @file        FUiCtrlIconList.cpp
19  * @brief       This is the implementation file for FUiCtrlIconList class
20  *
21  * This file contains the implementation of FUiCtrlIconList class
22  */
23
24 #include <FUiCtrlIconList.h>
25 #include <FBaseSysLog.h>
26 #include "FUiCtrl_IconListImpl.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Ui::Controls;
31 using namespace Tizen::Graphics;
32
33 namespace Tizen { namespace Ui { namespace Controls
34 {
35
36 IconList::IconList(void)
37 {
38 }
39
40 IconList::~IconList(void)
41 {
42 }
43
44 result
45 IconList::Construct(const Rectangle& rect, IconListStyle style, int itemWidth, int itemHeight)
46 {
47         result r = E_SUCCESS;
48
49         SysAssertf((_IconListImpl::GetInstance(*this) == null),
50                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
51
52         _IconListImpl* pImpl = _IconListImpl::CreateIconListImplN(this);
53         r = GetLastResult();
54         SysTryReturn(NID_UI_CTRL, pImpl, r, r, "[%s] Propagating.", GetErrorMessage(r));
55
56         _pControlImpl = pImpl;
57
58         r = Control::SetBounds(rect.x, rect.y, rect.width, rect.height);
59         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "Internal Error");
60
61         // Set Initial Parameters
62
63         r = pImpl->SetIconListStyle(style);
64         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "Internal Error");
65
66         r = pImpl->InitializeIconList(itemWidth, itemHeight);
67         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "Internal Error");
68
69         r = pImpl->SetItemProvider();
70         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "Internal Error");
71
72         r = pImpl->SetListener();
73         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "Internal Error");
74
75         r = pImpl->SetNonSlidable();
76         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "Internal Error");
77
78         return E_SUCCESS;
79
80 CATCH:
81         Dispose();
82         return r;
83 }
84
85 void
86 IconList::AddItemEventListener(IItemEventListener& listener)
87 {
88         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
89         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
90
91         pImpl->AddItemEventListener(listener);
92 }
93
94 void
95 IconList::RemoveItemEventListener(IItemEventListener& listener)
96 {
97         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
98         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
99
100         pImpl->RemoveItemEventListener(listener);
101 }
102
103 void
104 IconList::SetBackgroundBitmap(const Bitmap& bitmap)
105 {
106         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
107         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
108
109         pImpl->SetBackgroundBitmap(bitmap);
110
111 }
112
113 result
114 IconList::SetMargin(int topMargin, int leftMargin)
115 {
116         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
117         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
118
119         return pImpl->SetMargin(topMargin, leftMargin);
120 }
121
122 int
123 IconList::GetTopMargin(void) const
124 {
125         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
126         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
127
128         return pImpl->GetTopMargin();
129 }
130
131 int
132 IconList::GetLeftMargin(void) const
133 {
134         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
135         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
136
137         return pImpl->GetLeftMargin();
138 }
139
140 result
141 IconList::AddItem(const String* pText, const Bitmap* pNormalBitmap, const Bitmap* pFocusedBitmap, int itemId)
142 {
143         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
144         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
145
146         return pImpl->AddItem(pText, pNormalBitmap, pFocusedBitmap, itemId);
147 }
148
149 result
150 IconList::InsertItemAt(int index, const String* pText, const Bitmap* pNormalBitmap, const Bitmap* pFocusedBitmap, int itemId)
151 {
152         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
153         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
154
155         return pImpl->InsertItemAt(index, pText, pNormalBitmap, pFocusedBitmap, itemId);
156 }
157
158 result
159 IconList::SetItemAt(int index, const String* pText, const Bitmap* pNormalBitmap, const Bitmap* pFocusedBitmap, int itemId)
160 {
161         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
162         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
163
164         return pImpl->SetItemAt(index, pText, pNormalBitmap, pFocusedBitmap, itemId);
165 }
166
167 result
168 IconList::RemoveItemAt(int index)
169 {
170         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
171         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
172
173         return pImpl->RemoveItemAt(index);
174 }
175
176 result
177 IconList::RemoveAllItems(void)
178 {
179         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
180         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
181
182         return pImpl->RemoveAllItems();
183 }
184
185 int
186 IconList::GetColumnCount(void) const
187 {
188         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
189         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
190
191         return pImpl->GetColumnCount();
192 }
193
194 int
195 IconList::GetItemCount(void) const
196 {
197         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
198         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
199
200         return pImpl->GetItemCount();
201 }
202
203 result
204 IconList::SetItemChecked(int index, bool check)
205 {
206         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
207         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
208
209         return pImpl->SetItemChecked(index, check);
210 }
211
212 bool
213 IconList::IsItemChecked(int index) const
214 {
215         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
216         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
217
218         return pImpl->IsItemChecked(index);
219 }
220
221 result
222 IconList::SetAllItemsChecked(bool check)
223 {
224         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
225         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
226
227         return pImpl->SetAllItemsChecked(check);
228 }
229
230 result
231 IconList::RemoveAllCheckedItems(void)
232 {
233         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
234         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
235
236         return pImpl->RemoveAllCheckedItems();
237 }
238
239 int
240 IconList::GetFirstCheckedItemIndex(void) const
241 {
242         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
243         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
244
245         return pImpl->GetFirstCheckedItemIndex();
246 }
247
248 int
249 IconList::GetLastCheckedItemIndex(void) const
250 {
251         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
252         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
253
254         return pImpl->GetLastCheckedItemIndex();
255 }
256
257 int
258 IconList::GetNextCheckedItemIndexAfter(int index) const
259 {
260         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
261         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
262
263         return pImpl->GetNextCheckedItemIndexAfter(index);
264 }
265
266 int
267 IconList::GetItemIndexFromPosition(int x, int y) const
268 {
269         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
270         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
271
272         return pImpl->GetItemIndexFromPosition(Point(x, y));
273 }
274
275 int
276 IconList::GetItemIndexFromPosition(const Point& position) const
277 {
278         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
279         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
280
281         return pImpl->GetItemIndexFromPosition(position);
282 }
283
284 void
285 IconList::SetTextHorizontalAlignment(HorizontalAlignment alignment)
286 {
287         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
288         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
289
290         return pImpl->SetTextHorizontalAlignment(alignment);
291 }
292
293 void
294 IconList::SetTextVerticalAlignment(VerticalAlignment alignment)
295 {
296         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
297         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
298
299         return pImpl->SetTextVerticalAlignment(alignment);
300 }
301
302 HorizontalAlignment
303 IconList::GetTextHorizontalAlignment(void) const
304 {
305         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
306         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
307
308         return pImpl->GetTextHorizontalAlignment();
309 }
310
311 VerticalAlignment
312 IconList::GetTextVerticalAlignment(void) const
313 {
314         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
315         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
316
317         return pImpl->GetTextVerticalAlignment();
318 }
319
320 void
321 IconList::SetBackgroundColor(const Color& color)
322 {
323         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
324         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
325
326         pImpl->SetBackgroundColor(color);
327 }
328
329 void
330 IconList::SetTextOfEmptyList(const String& text)
331 {
332         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
333         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
334
335         pImpl->SetTextOfEmptyList(text);
336 }
337
338 void
339 IconList::SetTextColorOfEmptyList(const Color& color)
340 {
341         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
342         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
343
344         pImpl->SetTextColorOfEmptyList(color);
345 }
346
347 Color
348 IconList::GetTextColorOfEmptyList(void) const
349 {
350         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
351         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
352
353         return pImpl->GetTextColorOfEmptyList();
354 }
355
356 void
357 IconList::SetItemTextColor(const Color& textColor)
358 {
359         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
360         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
361
362         pImpl->SetItemTextColor(textColor);
363 }
364
365 Color
366 IconList::GetItemTextColor(void) const
367 {
368         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
369         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
370
371         return pImpl->GetItemTextColor();
372
373 }
374
375 void
376 IconList::SetTextSize(int size)
377 {
378         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
379         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
380
381         pImpl->SetTextSize(size);
382 }
383
384 int
385 IconList::GetTextSize(void) const
386 {
387         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
388         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
389
390         return pImpl->GetTextSize();
391 }
392
393 int
394 IconList::GetItemIndexFromItemId(int itemId) const
395 {
396         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
397         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
398
399         return pImpl->GetItemIndexFromItemId(itemId);
400 }
401
402 int
403 IconList::GetItemIdAt(int index) const
404 {
405         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
406         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
407
408         return pImpl->GetItemIdAt(index);
409 }
410
411 void
412 IconList::SetCheckBoxPosition(IconListCheckBoxPosition position)
413 {
414         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
415         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
416
417         pImpl->SetCheckBoxPosition(position);
418 }
419
420 IconListCheckBoxPosition
421 IconList::GetCheckBoxPosition(void) const
422 {
423         const _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
424         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
425
426         return pImpl->GetCheckBoxPosition();
427 }
428
429 void
430 IconList::SetFocusAnimationEnabled(bool enable)
431 {
432         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
433         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
434
435         pImpl->SetFocusAnimationEnabled(enable);
436 }
437
438 void
439 IconList::ScrollToBottom(void)
440 {
441         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
442         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
443
444         return pImpl->ScrollToBottom();
445 }
446
447 void
448 IconList::ScrollToTop(void)
449 {
450         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
451         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
452
453         return pImpl->ScrollToTop();
454 }
455
456 result
457 IconList::ScrollToTop(int itemIndex)
458 {
459         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
460         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
461
462         return pImpl->ScrollToTop(itemIndex);
463 }
464
465 result
466 IconList::RefreshItem(int index)
467 {
468         _IconListImpl* pImpl = _IconListImpl::GetInstance(*this);
469         SysAssertf(pImpl, "Not yet constructed. Construct() should be called before use.");
470
471         return pImpl->RefreshItem(index);
472 }
473
474 }}} // Tizen::Ui::Controls