Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrlGallery.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        FUiCtrlGallery.cpp
19  * @brief       This file contains implementation of Gallery class.
20  *
21  * This header file contains the declarations of the Gallery class and its helper classes.
22  */
23
24 //Includes
25 #include <FUiCtrlGallery.h>
26 #include "FUiCtrl_GalleryImpl.h"
27
28 using namespace Tizen::Graphics;
29 using namespace Tizen::Base;
30 using namespace Tizen::Ui::Effects;
31
32 namespace Tizen { namespace Ui { namespace Controls {
33
34 Gallery::Gallery(void)
35 {
36         // Do nothing
37 }
38
39 Gallery::~Gallery(void)
40 {
41 }
42
43 result
44 Gallery::Construct(const Rectangle& rect)
45 {
46         SysAssertf(_GalleryImpl::GetInstance(*this) == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
47
48         _GalleryImpl* pGalleryImpl = _GalleryImpl::CreateGalleryImplN(this);
49         result r = GetLastResult();
50         SysTryCatch(NID_UI_CTRL, r != E_OUT_OF_MEMORY, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
51         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
52
53         _pControlImpl = pGalleryImpl;
54
55         r = Control::SetBounds(rect);
56         SysTryCatch(NID_UI_CTRL, r != E_INVALID_ARG, , E_INVALID_ARG, "[E_INVALID_ARG] The specified input parameter is invalid.");
57         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
58
59         return r;
60
61 CATCH:
62         delete pGalleryImpl;
63         _pControlImpl = null;
64         return r;
65 }
66
67 result
68 Gallery::SetItemProvider(IGalleryItemProvider &provider)
69 {
70         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
71         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
72
73         result r = pGalleryImpl->SetItemProvider(provider);
74
75         return r;
76 }
77
78 void
79 Gallery::AddGalleryEventListener(IGalleryEventListener &listener)
80 {
81         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
82         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
83
84         pGalleryImpl->AddGalleryEventListener(listener);
85         result r = GetLastResult();
86         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
87 }
88
89 void
90 Gallery::RemoveGalleryEventListener(IGalleryEventListener &listener)
91 {
92         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
93         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
94
95         pGalleryImpl->RemoveGalleryEventListener(listener);
96         result r = GetLastResult();
97         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
98 }
99
100 int
101 Gallery::GetCurrentItemIndex(void) const
102 {
103         const _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
104         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
105
106         int currentItemIndex = pGalleryImpl->GetCurrentItemIndex();
107
108         return currentItemIndex;
109 }
110
111 result
112 Gallery::SetCurrentItemIndex(int index)
113 {
114         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
115         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
116
117         result r = pGalleryImpl->SetCurrentItemIndex(index);
118         SysTryReturn(NID_UI_CTRL, r != E_OUT_OF_RANGE, r, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified %d index is out of range.", index);
119         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
120
121         return r;
122 }
123
124 int
125 Gallery::GetItemCount(void) const
126 {
127         const _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
128         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
129
130         int itemCount = pGalleryImpl->GetItemCount();
131         return itemCount;
132 }
133
134 result
135 Gallery::RefreshGallery(int itemIndex, GalleryRefreshType type)
136 {
137         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
138         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
139
140         result r = pGalleryImpl->RefreshGallery(itemIndex, type);
141         SysTryReturn(NID_UI_CTRL, r != E_OUT_OF_RANGE, r, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The specified %d index is out of range.", itemIndex);
142         SysTryReturn(NID_UI_CTRL, r != E_INVALID_OPERATION, r, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The current state of the instance prohibits the execution of the specified operation.");
143         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
144
145         return r;
146 }
147
148 result
149 Gallery::UpdateGallery(void)
150 {
151         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
152         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
153
154         result r = pGalleryImpl->UpdateGallery();
155         SysTryReturn(NID_UI_CTRL, r != E_INVALID_OPERATION, r, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The current state of the instance prohibits the execution of the specified operation.");
156         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
157
158         return r;
159 }
160
161 result
162 Gallery::SetTextOfEmptyGallery(const String &text)
163 {
164         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
165         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
166
167         result r = pGalleryImpl->SetTextOfEmptyGallery(text);
168         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
169
170         return r;
171 }
172
173 String
174 Gallery::GetTextOfEmptyGallery(void) const
175 {
176         const _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
177         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
178
179         String textOfEmptyGallery = pGalleryImpl->GetTextOfEmptyGallery();
180         result r = GetLastResult();
181         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, textOfEmptyGallery, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
182
183         return textOfEmptyGallery;
184 }
185
186 result
187 Gallery::SetBitmapOfEmptyGallery(const Bitmap* pBitmap)
188 {
189         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
190         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
191
192         result r = pGalleryImpl->SetBitmapOfEmptyGallery(pBitmap);
193         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
194
195         return r;
196 }
197
198 result
199 Gallery::SetSlideShowAnimation(GalleryAnimation animation)
200 {
201         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
202         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
203
204         result r = pGalleryImpl->SetSlideShowAnimation(animation);
205         SysTryReturn(NID_UI_CTRL, r != E_UNSUPPORTED_OPERATION, r, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] This operation is not supported.");
206         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
207
208         return r;
209 }
210
211 GalleryAnimation
212 Gallery::GetSlideShowAnimation(void) const
213 {
214         const _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
215         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
216
217         GalleryAnimation slideShowAnimation = pGalleryImpl->GetSlideShowAnimation();
218         result r = GetLastResult();
219         SysTryReturn(NID_UI_CTRL, r != E_UNSUPPORTED_OPERATION, slideShowAnimation, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] This operation is not supported.");
220         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, slideShowAnimation, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
221
222         return slideShowAnimation;
223 }
224
225 result
226 Gallery::SetSlideShowAnimationDuration(int duration)
227 {
228         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
229         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
230
231         result r = pGalleryImpl->SetSlideShowAnimationDuration(duration);
232         SysTryReturn(NID_UI_CTRL, r != E_OUT_OF_RANGE, r, E_OUT_OF_RANGE, "The specified %d duration is out of the possible duration range.", duration);
233         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
234
235         return r;
236 }
237
238 int
239 Gallery::GetSlideShowAnimationDuration(void) const
240 {
241         const _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
242         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
243
244         int slideShowAnimationDuration = pGalleryImpl->GetSlideShowAnimationDuration();
245         result r = GetLastResult();
246         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, slideShowAnimationDuration, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
247
248         return slideShowAnimationDuration;
249 }
250
251 result
252 Gallery::SetSlideShowViewDuration(int duration)
253 {
254         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
255         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
256
257         result r = pGalleryImpl->SetSlideShowViewDuration(duration);
258         SysTryReturn(NID_UI_CTRL, r != E_OUT_OF_RANGE, r, E_OUT_OF_RANGE, "The specified %d duration is out of the possible duration range.", duration);
259         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
260
261         return r;
262 }
263
264 int
265 Gallery::GetSlideShowViewDuration(void) const
266 {
267         const _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
268         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
269
270         int slideShowViewDuration = pGalleryImpl->GetSlideShowViewDuration();
271         result r = GetLastResult();
272         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, slideShowViewDuration, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
273
274         return slideShowViewDuration;
275 }
276
277 result
278 Gallery::StartSlideShow(bool repeat)
279 {
280         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
281         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
282
283         result r = pGalleryImpl->StartSlideShow(repeat);
284         SysTryReturn(NID_UI_CTRL, r != E_INVALID_OPERATION, r, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The current state of the instance prohibits the execution of the specified operation.");
285         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
286
287         return r;
288 }
289
290 result
291 Gallery::StopSlideShow(void) const
292 {
293         const _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
294         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
295
296         result r = pGalleryImpl->StopSlideShow();
297         SysTryReturn(NID_UI_CTRL, r != E_INVALID_OPERATION, r, E_INVALID_OPERATION, "[E_INVALID_OPERATION] The current state of the instance prohibits the execution of the specified operation.");
298         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
299
300         return r;
301 }
302
303 bool
304 Gallery::IsSlideShowStarted(void) const
305 {
306         const _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
307         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
308
309         bool slideShowStarted = pGalleryImpl->IsSlideShowStarted();
310         result r = GetLastResult();
311         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, slideShowStarted, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
312
313         return slideShowStarted;
314 }
315
316 result
317 Gallery::SetZoomingEnabled(bool enable)
318 {
319         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
320         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
321
322         result r = pGalleryImpl->SetZoomingEnabled(enable);
323         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
324
325         return r;
326 }
327
328 bool
329 Gallery::IsZoomingEnabled(void) const
330 {
331         const _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
332         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
333
334         bool zoomingEnable = pGalleryImpl->IsZoomingEnabled();
335         result r = GetLastResult();
336         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, zoomingEnable, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
337
338         return zoomingEnable;
339 }
340
341 result
342 Gallery::SetBackgroundColor(const Color& color)
343 {
344         _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
345         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
346
347         Color tempColor = color;
348         tempColor.SetAlpha(255);
349         pGalleryImpl->SetBackgroundColor(tempColor);
350         result r = GetLastResult();
351         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
352
353         return r;
354 }
355
356 Color
357 Gallery::GetBackgroundColor(void) const
358 {
359         const _GalleryImpl* pGalleryImpl = _GalleryImpl::GetInstance(*this);
360         SysAssertf(pGalleryImpl != null, "Not yet constructed. Construct() should be called before use.");
361
362         Color backgroundColor = pGalleryImpl->GetBackgroundColor();
363         return backgroundColor;
364 }
365
366 }}} // Tizen::Ui::Controls