2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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 <FBaseString.h>
18 #include <FGrpColor.h>
19 #include "FUi_TouchFlickGestureDetector.h"
20 #include "FUi_TouchTapGestureDetector.h"
21 #include "FUi_TouchPinchGestureDetector.h"
22 #include "FUiCtrl_Gallery.h"
23 #include "FUiCtrl_GalleryBitmap.h"
24 #include "FUiCtrl_GalleryPresenter.h"
25 #include "FUiCtrl_GalleryRenderer.h"
26 #include "FUiCtrl_GalleryRendererNotification.h"
27 #include "FUiCtrl_GalleryViewEventInfo.h"
28 #include "FUiCtrl_GalleryViewEvent.h"
29 #include "FUiCtrl_IGalleryCoreEventListener.h"
30 #include "FUiCtrl_IGalleryRendererNotiListener.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Ui::Effects;
36 namespace Tizen { namespace Ui { namespace Controls {
38 _Gallery::_Gallery(void)
41 , __modelInitialized(false)
46 _Gallery::~_Gallery(void)
48 result r = __flickGesture.RemoveGestureListener(*this);
55 r = RemoveGestureDetector(__flickGesture);
62 r = __tapGesture.RemoveGestureListener(*this);
69 r = RemoveGestureDetector(__tapGesture);
76 r = __pinchGesture.RemoveGestureListener(*this);
83 r = RemoveGestureDetector(__pinchGesture);
95 _Gallery::CreateGalleryN(_GalleryItemProviderAdaptorImpl* pGalleryItemProviderAdaptor)
100 _Gallery* pGallery = new (std::nothrow) _Gallery();
101 SysTryCatch(NID_UI_CTRL, pGallery != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _Gallery.");
103 r = pGallery->Construct(pGalleryItemProviderAdaptor);
104 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
106 SetLastResult(E_SUCCESS);
117 _Gallery::Construct(_GalleryItemProviderAdaptorImpl* pGalleryItemProviderAdaptor)
119 result r = E_SUCCESS;
120 _GalleryRenderer* pRenderer = null;
121 _GalleryPresenter* pPresenter = null;
123 pRenderer = _GalleryRenderer::CreateGalleryRendererN((Tizen::Ui::_Control&)*this);
124 SysTryCatch(NID_UI_CTRL, pRenderer != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to create the _GalleryRenderer.");
126 pPresenter = _GalleryPresenter::CreateGalleryPresenterN((_IGalleryRenderer&)*pRenderer, pGalleryItemProviderAdaptor);
127 SysTryCatch(NID_UI_CTRL, pPresenter != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to create the _GalleryPresenter.");
129 r = pRenderer->AddNotiListener(*pPresenter);
130 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
134 r = __flickGesture.AddGestureListener(*this);
135 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
137 r = _Control::AddGestureDetector(__flickGesture);
138 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
140 r = __tapGesture.AddGestureListener(*this);
141 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
143 __tapGesture.SetTapCount(2);
144 r = _Control::AddGestureDetector(__tapGesture);
145 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
147 SetMultiTouchEnabled(true);
148 r = _Control::AddGestureDetector(__pinchGesture);
149 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
151 r = __pinchGesture.AddGestureListener(*this);
152 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
154 SetRenderer((_GalleryRenderer &)*pRenderer);
155 SetPresenter((_GalleryPresenter &)*pPresenter);
168 _Gallery::SetTextOfEmptyGallery(const String& text)
170 return GetPresenter().SetTextOfEmptyGallery(text);
174 _Gallery::GetTextOfEmptyGallery(void) const
176 return GetPresenter().GetTextOfEmptyGallery();
180 _Gallery::SetBitmapOfEmptyGallery(const _GalleryBitmap* pBitmap)
182 return GetPresenter().SetBitmapOfEmptyGallery(pBitmap);
186 _Gallery::SetCoreEventListener(const _IGalleryCoreEventListener& coreEventListener)
188 return GetPresenter().SetCoreEventListener(coreEventListener);
192 _Gallery::RemoveCoreEventListener(const _IGalleryCoreEventListener& coreEventListener)
194 return GetPresenter().RemoveCoreEventListener(coreEventListener);
198 _Gallery::SetZoomingEnabled(bool enable)
200 return GetPresenter().SetZoomingEnabled(enable);
204 _Gallery::IsZoomingEnabled(void) const
206 return GetPresenter().IsZoomingEnabled();
210 _Gallery::SetSlideShowType(_GallerySlideShowType slideShowType)
212 return GetPresenter().SetSlideShowType(slideShowType);
215 _GallerySlideShowType
216 _Gallery::GetSlideShowType(void) const
218 return GetPresenter().GetSlideShowType();
222 _Gallery::SetSlideShowAnimationDuration(int duration)
224 return GetPresenter().SetSlideShowAnimationDuration(duration);
228 _Gallery::GetSlideShowAnimationDuration(void) const
230 return GetPresenter().GetSlideShowAnimationDuration();
234 _Gallery::SetSlideShowViewDuration(int duration)
236 return GetPresenter().SetSlideShowViewDuration(duration);
240 _Gallery::GetSlideShowViewDuration(void) const
242 return GetPresenter().GetSlideShowViewDuration();
246 _Gallery::StartSlideShow(bool repeat)
248 return GetPresenter().StartSlideShow(repeat);
252 _Gallery::StopSlideShow(void)
254 return GetPresenter().StopSlideShow();
258 _Gallery::IsSlideShowStarted(void) const
260 return GetPresenter().IsSlideShowStarted();
265 _Gallery::SetCurrentItemIndex(int itemIndex)
267 return GetPresenter().SetCurrentItem(itemIndex);
271 _Gallery::GetCurrentItemIndex(void) const
273 return GetPresenter().GetCurrentItemIndex();
277 _Gallery::GetItemCount(void) const
279 return GetPresenter().GetItemCount();
283 _Gallery::RequestToLoadItem(int itemIndex)
285 SysTryReturnResult(NID_UI_CTRL, __modelInitialized == true, E_INVALID_OPERATION, "Does not call to first draw.");
286 return GetPresenter().RequestToLoadItem(itemIndex);
290 _Gallery::RequestToUnloadItem(int itemIndex)
292 SysTryReturnResult(NID_UI_CTRL, __modelInitialized == true, E_INVALID_OPERATION, "Does not call to first draw.");
293 return GetPresenter().RequestToUnloadItem(itemIndex);
297 _Gallery::RequestToUnloadAllItems(void)
299 return GetPresenter().RequestToUnloadAllItems();
303 _Gallery::RequestToUpdateItem(int itemIndex)
305 SysTryReturnResult(NID_UI_CTRL, __modelInitialized == true, E_INVALID_OPERATION, "Does not call to first draw.");
306 return GetPresenter().RequestToUpdateItem(itemIndex);
310 _Gallery::RequestToUpdateAllItems(void)
312 return GetPresenter().RequestToUpdateAllItems();
316 _Gallery::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
318 _GalleryViewEventInfo viewEventInfo;
321 gesture.GetDistance(distanceX, distanceY);
322 Point flickPoint(distanceX, distanceY);
324 viewEventInfo.SetFlickPosition(flickPoint);
325 viewEventInfo.SetFlicked(true);
326 viewEventInfo.SetFlickTime(gesture.GetDuration());
327 _GalleryViewEvent viewEvent(GALLERY_VIEW_EVENT_TOUCH_FLICK, &viewEventInfo);
328 bool r = GetPresenter().PostEvent(viewEvent);
329 SysTryReturn(NID_UI_CTRL, r == true, true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
335 _Gallery::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
341 _Gallery::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
344 Tizen::Ui::_TouchInfo touchInfo(0, _TOUCH_DOUBLE_PRESSED, pos, false, 0);
345 _GalleryViewEventInfo viewEventInfo(touchInfo);
346 _GalleryViewEvent viewEvent(GALLERY_VIEW_EVENT_TOUCH_DOUBLE_PRESSED, &viewEventInfo);
348 bool r = GetPresenter().PostEvent(viewEvent);
349 SysTryReturn(NID_UI_CTRL, r == true, true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
355 _Gallery::OnTapGestureCanceled(_TouchTapGestureDetector& gesture)
361 _Gallery::OnPinchGestureStarted(_TouchPinchGestureDetector& gesture)
363 //return OnPinchGestureChanged(gesture);
368 _Gallery::OnPinchGestureChanged(_TouchPinchGestureDetector& gesture)
370 _GalleryViewEventInfo viewEventInfo;
371 viewEventInfo.SetPinchCenterPosition(gesture.GetCenterPoint());
372 viewEventInfo.SetPinchArea(gesture.GetScale());
373 _GalleryViewEvent viewEvent(GALLERY_VIEW_EVENT_TOUCH_PINCH_ZOOM, &viewEventInfo);
374 bool r = GetPresenter().PostEvent(viewEvent);
375 SysTryReturn(NID_UI_CTRL, r == true, true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
380 _Gallery::OnPinchGestureFinished(_TouchPinchGestureDetector& gesture)
382 //return OnPinchGestureChanged(gesture);
387 _Gallery::OnPinchGestureCanceled(_TouchPinchGestureDetector& gesture)
392 // Touch Event Callbacks
394 _Gallery::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
396 _GalleryViewEventInfo viewEventInfo(const_cast <_TouchInfo&>(touchinfo));
397 _GalleryViewEvent viewEvent(GALLERY_VIEW_EVENT_TOUCH_PRESSED, &viewEventInfo);
399 return GetPresenter().PostEvent(viewEvent);
403 _Gallery::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
405 _GalleryViewEventInfo viewEventInfo(const_cast <_TouchInfo&>(touchinfo));
406 _GalleryViewEvent viewEvent(GALLERY_VIEW_EVENT_TOUCH_RELEASED, &viewEventInfo);
408 return GetPresenter().PostEvent(viewEvent);
412 _Gallery::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
414 _GalleryViewEventInfo viewEventInfo(const_cast <_TouchInfo&>(touchinfo));
415 _GalleryViewEvent viewEvent(GALLERY_VIEW_EVENT_TOUCH_MOVED, &viewEventInfo);
417 bool r = GetPresenter().PostEvent(viewEvent);
418 SysTryReturn(NID_UI_CTRL, r == true, true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(r));
420 SetLastResult(E_SUCCESS);
426 _Gallery::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
431 // Windowing Event Callbacks
433 _Gallery::OnDraw(void)
435 if (__modelInitialized == false)
437 //GetPresenter().RequestToUpdateItemCount();
438 __modelInitialized = true;
441 GetPresenter().OnDraw();
445 _Gallery::OnBoundsChanged(void)
447 // GetRenderer().OnBoundsChanged();
448 _GalleryViewEventInfo viewEventInfo;
449 _GalleryViewEvent viewEvent(GALLERY_VIEW_EVENT_BOUNDS_CHANGED, &viewEventInfo);
451 bool r = GetPresenter().PostEvent(viewEvent);
452 SysTryReturnVoidResult(NID_UI_CTRL, r == true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
456 _Gallery::OnFontInfoRequested(unsigned long& style, int& size)
458 GetPresenter().OnFontInfoRequested(style, size);
462 _Gallery::OnFontChanged(Font* pFont)
464 GetPresenter().OnFontChanged();
468 _Gallery::SetEffect(Effect* pEffect)
470 GetRenderer().SetEffect(pEffect);
474 _Gallery::GetEffect(void)
476 return GetRenderer().GetEffect();
479 }}} // Tizen::Ui::Controls