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