2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
17 #include <FUiCtrlGallery.h>
18 #include <FUiCtrlIGalleryItemProvider.h>
19 #include <FUiCtrlIGalleryEventListener.h>
20 #include <FGrp_BitmapImpl.h>
21 #include "FUi_UiBuilder.h"
22 #include "FUiCtrl_Gallery.h"
23 #include "FUiCtrl_GalleryImpl.h"
24 #include "FUiCtrl_GalleryBitmap.h"
25 #include "FUiCtrl_GalleryItemProviderAdaptorImpl.h"
26 #include "FUiCtrl_GalleryCoreEventListener.h"
27 #include "FUiCtrl_GalleryImplEvent.h"
29 using namespace Tizen::Base;
30 using namespace Tizen::Graphics;
31 using namespace Tizen::Ui;
32 using namespace Tizen::Ui::Effects;
34 namespace Tizen { namespace Ui { namespace Controls {
40 ConvertEnum(GalleryAnimation var)
44 case GALLERY_ANIMATION_PAGE:
45 return GALLERY_SLIDESHOW_PAGE;
47 case GALLERY_ANIMATION_DISSOLVE:
48 return GALLERY_SLIDESHOW_DISSOLVE;
50 case GALLERY_ANIMATION_ZOOM:
51 return GALLERY_SLIDESHOW_ZOOM;
54 return (_GallerySlideShowType)-1;
59 ConvertEnum(_GallerySlideShowType var)
63 case GALLERY_SLIDESHOW_PAGE:
64 return GALLERY_ANIMATION_PAGE;
66 case GALLERY_SLIDESHOW_DISSOLVE:
67 return GALLERY_ANIMATION_DISSOLVE;
69 case GALLERY_SLIDESHOW_ZOOM:
70 return GALLERY_ANIMATION_ZOOM;
73 return (GalleryAnimation)-1;
77 } // unnamed namespace
79 _GalleryImpl::_GalleryImpl(Gallery* pGallery, _Gallery* pCore, _GalleryImplEvent* pImplEvent,
80 _GalleryCoreEventListener* pCoreEventListener, _GalleryItemProviderAdaptorImpl* pGalleryItemProviderAdaptor)
81 : _ControlImpl(pGallery, pCore)
82 , __pImplEvent(pImplEvent)
83 , __pCoreEventListener(pCoreEventListener)
84 , __pGalleryItemProviderAdaptor(pGalleryItemProviderAdaptor)
88 _GalleryImpl::~_GalleryImpl(void)
90 RequestToUnloadAllItems();
93 delete __pCoreEventListener;
94 delete __pGalleryItemProviderAdaptor;
98 _GalleryImpl::CreateGalleryImplN(Gallery* pGallery)
100 SysTryReturn(NID_UI_CTRL, pGallery != null, null, E_INVALID_ARG, "[E_INVALID_ARG] pGallery is null.");
102 _GalleryCoreEventListener* pCoreEventListener = null;
103 _GalleryItemProviderAdaptorImpl* pGalleryItemProviderAdaptor = null;
104 _Gallery* pCore = null;
105 _GalleryImpl* pImpl = null;
106 result r = E_SUCCESS;
108 _GalleryImplEvent* pImplEvent = new (std::nothrow) _GalleryImplEvent();
109 SysTryCatch(NID_UI_CTRL, pImplEvent != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
111 pCoreEventListener = new (std::nothrow) _GalleryCoreEventListener(*pImplEvent);
112 SysTryCatch(NID_UI_CTRL, pCoreEventListener != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
114 pGalleryItemProviderAdaptor = new (std::nothrow) _GalleryItemProviderAdaptorImpl();
115 SysTryCatch(NID_UI_CTRL, pGalleryItemProviderAdaptor != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
117 pCore = _Gallery::CreateGalleryN(pGalleryItemProviderAdaptor);
118 SysTryCatch(NID_UI_CTRL, pCore != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
120 r = pCore->SetCoreEventListener(*pCoreEventListener);
121 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
123 pImpl = new (std::nothrow) _GalleryImpl(pGallery, pCore, pImplEvent, pCoreEventListener, pGalleryItemProviderAdaptor);
124 SysTryCatch(NID_UI_CTRL, pImpl != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
127 SetLastResult(E_SUCCESS);
131 delete pCoreEventListener;
140 _GalleryImpl::GetPublicClassName(void) const
142 return "Control::Gallery";
146 _GalleryImpl::GetPublic(void) const
148 return static_cast<const Gallery&>(_ControlImpl::GetPublic());
152 _GalleryImpl::GetPublic(void)
154 return static_cast<Gallery&>(_ControlImpl::GetPublic());
158 _GalleryImpl::GetCore(void) const
160 return static_cast<const _Gallery&>(_ControlImpl::GetCore());
164 _GalleryImpl::GetCore(void)
166 return static_cast<_Gallery&>(_ControlImpl::GetCore());
170 _GalleryImpl::AddGalleryEventListener(IGalleryEventListener& listener)
172 result r = __pImplEvent->AddListener(listener);
173 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
175 SetLastResult(E_SUCCESS);
179 _GalleryImpl::RemoveGalleryEventListener(IGalleryEventListener& listener)
181 result r = __pImplEvent->RemoveListener(listener);
182 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
184 SetLastResult(E_SUCCESS);
188 _GalleryImpl::SetItemProvider(IGalleryItemProvider& provider)
190 __pGalleryItemProviderAdaptor->SetGalleryItemProvider(provider);
192 return GetCore().RequestToUpdateAllItems();
196 _GalleryImpl::SetCurrentItemIndex(int index)
198 SysTryReturn(NID_UI_CTRL, __pGalleryItemProviderAdaptor->HasGalleryItemProvider() == true, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
199 "[E_OUT_OF_RANGE] Item provider is null");
201 return GetCore().SetCurrentItemIndex(index);
205 _GalleryImpl::GetCurrentItemIndex(void) const
207 return GetCore().GetCurrentItemIndex();
211 _GalleryImpl::SetZoomingEnabled(bool enable)
213 return GetCore().SetZoomingEnabled(enable);
217 _GalleryImpl::IsZoomingEnabled(void) const
219 return GetCore().IsZoomingEnabled();
223 _GalleryImpl::SetTextOfEmptyGallery(const String& text)
225 return GetCore().SetTextOfEmptyGallery(text);
229 _GalleryImpl::GetTextOfEmptyGallery(void) const
231 return GetCore().GetTextOfEmptyGallery();
235 _GalleryImpl::SetBitmapOfEmptyGallery(const Bitmap* pBitmap)
237 _GalleryBitmap* pGalleryBitmap = _GalleryBitmap::CreateGalleryBitmapN(const_cast<Bitmap*>(pBitmap));
238 SysTryReturn(NID_UI_CTRL, pGalleryBitmap != null, GetLastResult(), GetLastResult(),
239 "[%s] Propagating.", GetErrorMessage(GetLastResult()));
241 return GetCore().SetBitmapOfEmptyGallery(pGalleryBitmap);
245 _GalleryImpl::SetSlideShowAnimation(GalleryAnimation animation)
247 _GallerySlideShowType slideShowType = ConvertEnum(animation);
249 SysTryReturn(NID_UI_CTRL, slideShowType != -1, E_INVALID_ARG, E_INVALID_ARG,
250 "[E_INVALID_ARG] The animation argument(%d) is invalid argument.", animation);
252 return GetCore().SetSlideShowType(slideShowType);
256 _GalleryImpl::GetSlideShowAnimation(void) const
258 return ConvertEnum(GetCore().GetSlideShowType());
262 _GalleryImpl::SetSlideShowAnimationDuration(int duration)
264 return GetCore().SetSlideShowAnimationDuration(duration);
268 _GalleryImpl::GetSlideShowAnimationDuration(void) const
270 return GetCore().GetSlideShowAnimationDuration();
274 _GalleryImpl::SetSlideShowViewDuration(int duration)
276 return GetCore().SetSlideShowViewDuration(duration);
280 _GalleryImpl::GetSlideShowViewDuration(void) const
282 return GetCore().GetSlideShowViewDuration();
286 _GalleryImpl::StartSlideShow(bool repeat)
288 return GetCore().StartSlideShow(repeat);
292 _GalleryImpl::StopSlideShow(void) const
294 _Gallery* pCore = const_cast<_Gallery*>(&GetCore()); // ???
296 return pCore->StopSlideShow();
300 _GalleryImpl::IsSlideShowStarted(void) const
302 return GetCore().IsSlideShowStarted();
306 _GalleryImpl::GetItemCount(void) const
308 return GetCore().GetItemCount();
312 _GalleryImpl::RefreshGallery(int itemIndex, GalleryRefreshType type)
314 SysTryReturn(NID_UI_CTRL, __pGalleryItemProviderAdaptor->HasGalleryItemProvider() == true, E_INVALID_OPERATION, E_INVALID_OPERATION,
315 "[E_INVALID_OPERATION] Item provider is null");
319 case GALLERY_REFRESH_TYPE_ITEM_ADD:
320 return GetCore().RequestToLoadItem(itemIndex);
321 case GALLERY_REFRESH_TYPE_ITEM_REMOVE:
322 return GetCore().RequestToUnloadItem(itemIndex);
323 case GALLERY_REFRESH_TYPE_ITEM_MODIFY:
324 return GetCore().RequestToUpdateItem(itemIndex);
326 SysTryReturn(NID_UI_CTRL, false, E_INVALID_ARG, E_INVALID_ARG,
327 "[E_INVALID_ARG] The refresh type(%d) is invalid type.", type);
335 _GalleryImpl::UpdateGallery(void)
337 SysTryReturn(NID_UI_CTRL, __pGalleryItemProviderAdaptor->HasGalleryItemProvider() == true, E_INVALID_OPERATION, E_INVALID_OPERATION,
338 "[E_INVALID_OPERATION] Item provider is null");
340 result r = GetCore().RequestToUpdateAllItems();
341 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
347 _GalleryImpl::RequestToUnloadAllItems(void)
349 result r = GetCore().RequestToUnloadAllItems();
350 SysAssert(r == E_SUCCESS);
354 _GalleryImpl::SetEffect(Effect* pEffect)
356 GetCore().SetEffect(pEffect);
360 _GalleryImpl::GetEffect(void)
362 return GetCore().GetEffect();
366 _GalleryImpl::GetInstance(Gallery& gallery)
368 return static_cast<_GalleryImpl*> (gallery._pControlImpl);
372 _GalleryImpl::GetInstance(const Gallery& gallery)
374 return static_cast<const _GalleryImpl*> (gallery._pControlImpl);
379 : public _UiBuilderControlMaker
382 _GalleryMaker(_UiBuilder* uibuilder)
383 : _UiBuilderControlMaker(uibuilder) {};
384 virtual ~_GalleryMaker() {};
385 static _UiBuilderControlMaker*
386 GetInstance(_UiBuilder* uibuilder)
388 _GalleryMaker* pListViewMaker = new (std::nothrow) _GalleryMaker(uibuilder);
389 return pListViewMaker;
393 Make(_UiBuilderControl* pControl)
396 _UiBuilderControlLayout* pControlProperty = null;
397 Gallery* pGallery = null;
399 Tizen::Base::String elementString;
400 int currentIndex = 0;
403 bool isZoomingEnabled = true;
405 GetProperty(pControl, &pControlProperty);
406 if (pControlProperty == null)
411 pGallery = new (std::nothrow) Gallery();
412 if (pGallery == null)
417 rect = pControlProperty->GetRectF();
419 r = pGallery->Construct(rect);
426 if (pControl->GetElement(L"backgroundColor", elementString) || pControl->GetElement(L"BGColor", elementString))
428 ConvertStringToColor32(elementString, 100, color);
429 r = pGallery->SetBackgroundColor(color);
437 if (pControl->GetElement(L"bitmapPathOfEmptyGallery", elementString))
439 Bitmap* pBackgroundBitmap = null;
440 pBackgroundBitmap = LoadBitmapN(elementString); //__image->DecodeN(path,BITMAP_PIXEL_FORMAT_RGB565);
441 if (pBackgroundBitmap != null)
443 r = pGallery->SetBitmapOfEmptyGallery(pBackgroundBitmap);
446 delete pBackgroundBitmap;
450 delete pBackgroundBitmap;
454 if (pControl->GetElement(L"currentItemIndex", elementString))
456 Base::Integer::Parse(elementString, currentIndex);
457 r = pGallery->SetCurrentItemIndex(currentIndex);
465 if (pControl->GetElement(L"slideShowAnimation", elementString))
467 GalleryAnimation animation = GALLERY_ANIMATION_DISSOLVE;
468 if (elementString.Equals(L"GALLERY_ANIMATION_PAGE", false))
470 animation = GALLERY_ANIMATION_PAGE;
472 else if (elementString.Equals(L"GALLERY_ANIMATION_ZOOM", false))
474 animation = GALLERY_ANIMATION_ZOOM;
477 r = pGallery->SetSlideShowAnimation(animation);
485 if (pControl->GetElement(L"slideShowAnimationDuration", elementString))
487 Base::Integer::Parse(elementString, duration);
488 r = pGallery->SetSlideShowAnimationDuration(duration);
496 if (pControl->GetElement(L"slideShowViewDuration", elementString))
498 Base::Integer::Parse(elementString, duration);
499 r = pGallery->SetSlideShowViewDuration(duration);
507 if (pControl->GetElement(L"textOfEmptyGallery", elementString))
509 r = pGallery->SetTextOfEmptyGallery(elementString);
517 if (pControl->GetElement(L"zoomingEnabled", elementString))
520 if (elementString.Equals(L"true", false))
522 isZoomingEnabled = true;
526 isZoomingEnabled = false;
529 r = pGallery->SetZoomingEnabled(isZoomingEnabled);
543 _GalleryRegister::_GalleryRegister(void)
545 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
546 pUiBuilderControlTableManager->RegisterControl(L"Gallery", _GalleryMaker::GetInstance);
548 _GalleryRegister::~_GalleryRegister(void)
550 _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
551 pUiBuilderControlTableManager->UnregisterControl(L"Gallery");
553 static _GalleryRegister GalleryRegisterToUiBuilder;