Revert " modify license, permission and remove ^M char"
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_GalleryRenderer.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 #include <FBaseErrors.h>
18 #include <FBaseSysLog.h>
19 #include <FGrpFloatMatrix4.h>
20 #include <FGrpCanvas.h>
21 #include <FUiVariant.h>
22 #include <FUiEffects.h>
23 #include <FUiAnimVisualElementAnimation.h>
24 #include <FUiCtrlGallery.h>
25 #include <FGrp_BitmapImpl.h>
26 #include <FGrp_CanvasImpl.h>
27 #include <FGrp_TextTextObject.h>
28 #include <FGrp_TextTextSimple.h>
29 #include "FUi_Control.h"
30 #include "FUi_CoordinateSystemUtils.h"
31 #include "FUi_ResourceManager.h"
32 #include "FUiAnim_MatrixUtil.h"
33 #include "FUiAnim_VisualElement.h"
34 #include "FUiCtrl_GalleryImpl.h"
35 #include "FUiCtrl_GalleryRenderer.h"
36 #include "FUiCtrl_GalleryBitmap.h"
37 #include "FUiCtrl_GalleryCanvasManager.h"
38 #include "FUiCtrl_GalleryCanvas.h"
39 #include "FUiCtrl_GalleryRendererNotifier.h"
40 #include "FUiCtrl_GalleryRendererNotification.h"
41 #include "FUiCtrl_IGalleryRendererNotiListener.h"
42
43
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Runtime;
46 using namespace Tizen::Base::Collection;
47 using namespace Tizen::Graphics;
48 using namespace Tizen::Ui;
49 using namespace Tizen::Ui::Animations;
50 using namespace Tizen::Ui::Effects;
51 using namespace Tizen::Graphics::_Text;
52
53 namespace Tizen { namespace Ui { namespace Controls {
54
55 namespace
56 {
57
58 const int GALLERY_CANVAS_INITIAL_MAX_COUNT = 5;
59 const int GALLERY_ZOOM_TRANSITION_ZOOM_FACTOR = 10;
60
61 } // unnamed namespace
62
63 _GalleryRenderer*
64 _GalleryRenderer::CreateGalleryRendererN(_Control& control)
65 {
66         result r = E_SUCCESS;
67
68         _GalleryRenderer* pRenderer = new (std::nothrow) _GalleryRenderer();
69         SysTryCatch(NID_UI_CTRL, pRenderer != null, , E_OUT_OF_MEMORY,
70                                         "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _GalleryRenderer.");
71
72         r = pRenderer->Construct(control);
73         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
74
75         SetLastResult(E_SUCCESS);
76
77         return pRenderer;
78
79 CATCH:
80         delete pRenderer;
81
82         return null;
83 }
84
85 result
86 _GalleryRenderer::AddNotiListener(const _IGalleryRendererNotiListener& notiListener)
87 {
88         return GetRendererNotifier().AddListener((const IEventListener&)notiListener);
89 }
90
91 result
92 _GalleryRenderer::RemoveNotiListener(const _IGalleryRendererNotiListener& notiListener)
93 {
94         return GetRendererNotifier().RemoveListener((const IEventListener&)notiListener);
95 }
96
97 result
98 _GalleryRenderer::SetCanvasMaxCount(int maxCount)
99 {
100         result r = E_SUCCESS;
101         _GalleryCanvasManager& canvasManager = GetCanvasManager();
102         FloatRectangle viewRect = GetViewRect();
103
104         r = canvasManager.ResetCanvasManager(maxCount + 1, viewRect);
105         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
106
107         SetEmptyCanvasIndex(maxCount);
108
109         return E_SUCCESS;
110 }
111
112 int
113 _GalleryRenderer::GetCanvasMaxCount(void) const
114 {
115         return GetCanvasManager().GetCanvasCount();
116 }
117
118 result
119 _GalleryRenderer::SetCanvasVisibility(int canvasIndex, bool visibility)
120 {
121         _GalleryCanvas* pCanvas = GetCanvasManager().GetCanvas(canvasIndex);
122         result r = GetLastResult();
123         SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
124
125         pCanvas->GetFrameVisualElement().SetImplicitAnimationEnabled(false);
126
127         if (visibility == true)
128         {
129                 r = pCanvas->GetFrameVisualElement().SetZOrderGroup(1000);
130                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
131
132                 pCanvas->GetFrameVisualElement().SetOpacity(1.0);
133         }
134         else
135         {
136                 r = pCanvas->GetFrameVisualElement().SetZOrderGroup(0);
137                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
138         }
139
140         return pCanvas->SetVisibility(visibility);
141 }
142 result
143 _GalleryRenderer::SetCanvasShowState(int canvasIndex, bool showState)
144 {
145         _GalleryCanvas* pCanvas = GetCanvasManager().GetCanvas(canvasIndex);
146         result r = GetLastResult();
147         SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
148
149         return pCanvas->SetVisibility(showState);
150 }
151
152 bool
153 _GalleryRenderer::IsCanvasVisibility(int canvasIndex) const
154 {
155         _GalleryCanvas* pCanvas = GetCanvasManager().GetCanvas(canvasIndex);
156         SysTryReturn(NID_UI_CTRL, pCanvas != null, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
157
158         return pCanvas->IsVisibility();
159 }
160
161 FloatRectangle
162 _GalleryRenderer::GetViewRect(void) const
163 {
164         FloatRectangle rect = GetCanvasManager().GetRootCanvas().GetBounds();
165         rect.x = 0.0;
166         rect.y = 0.0;
167         return rect;
168 }
169
170 result
171 _GalleryRenderer::SetEmptyImage(const _GalleryBitmap* pImage)
172 {
173         _GalleryCanvas* pCanvas = GetCanvasManager().GetCanvas(GetEmptyCanvasIndex());
174         result r = GetLastResult();
175         SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
176
177         r = pCanvas->SetImage(pImage, GetViewRect(), GALLERY_FITTING_TYPE_NONE);
178         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
179
180         return E_SUCCESS;
181
182         return E_SUCCESS;
183 }
184
185 result
186 _GalleryRenderer::SetEmptyText(const String& pText)
187 {
188         __emptyString = pText;
189
190         return E_SUCCESS;
191 }
192
193 result
194 _GalleryRenderer::EnableEmptyView(void)
195 {
196         __showEmptyImage = true;
197         __needDrawEmptyCanvas = true;
198
199         return E_SUCCESS;
200 }
201
202 result
203 _GalleryRenderer::DisableEmptyView(void)
204 {
205         result r = SetCanvasVisibility(GetEmptyCanvasIndex(), false);
206         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
207
208         __showEmptyImage = false;
209         __needDrawEmptyCanvas = false;
210
211         return E_SUCCESS;
212 }
213
214 result
215 _GalleryRenderer::SetCanvasImage(int canvasIndex, const _GalleryBitmap* pImage
216                 , _GalleryVerticalAlignment imageVerticalAlignment, _GalleryHorizontalAlignment imageHorizontalAlignment
217                 , _GalleryFittingType fittingType)
218 {
219         _GalleryCanvas* pCanvas = GetCanvasManager().GetCanvas(canvasIndex);
220         result r = GetLastResult();
221         SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
222
223         pCanvas->SetImageAlignment(imageVerticalAlignment, imageHorizontalAlignment);
224         r = pCanvas->SetImage(pImage, GetViewRect(), fittingType);
225         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
226
227         return E_SUCCESS;
228 }
229
230 result
231 _GalleryRenderer::SetCanvasBounds(int canvasIndex, const FloatRectangle& bounds,
232                                                                 const _GalleryAnimationTiming* pAnimation)
233 {
234         _GalleryCanvas* pCanvas = GetCanvasManager().GetCanvas(canvasIndex);
235         result r = GetLastResult();
236         SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
237
238         _VisualElement& visualElement = pCanvas->GetImageVisualElement();
239         _VisualElement& frameVisualElement = pCanvas->GetFrameVisualElement();
240         frameVisualElement.SetImplicitAnimationEnabled(false);
241
242         FloatMatrix4 endMatrix;
243         endMatrix.SetAsIdentity();
244
245         float translateX = bounds.x;
246         float translateY = bounds.y;
247
248         FloatRectangle viewRect = GetViewRect();
249         FloatRectangle imageBounds = pCanvas->GetOriginalImageBounds();
250         if (bounds.width != viewRect.width)
251         {
252                 float factor = (float)bounds.width / (float)(viewRect.width);
253                 translateX = translateX - (imageBounds.width / 2 + imageBounds.x) + ((imageBounds.width / 2 + imageBounds.x) * factor);
254                 translateY = translateY - (imageBounds.height / 2 + imageBounds.y) + ((imageBounds.height / 2 + imageBounds.y) * factor);
255                 endMatrix.SetAsIdentity();
256                 _MatrixUtilTranslate(endMatrix, translateX, translateY, 0);
257                 _MatrixUtilScale(endMatrix, factor, factor, 1);
258                 pCanvas->SetCanvasFactor(factor);
259                 pCanvas->SetClippingOfFrameVisualElement(false);
260         }
261         else
262         {
263                 //_MatrixUtilTranslate(endMatrix, translateX, translateY, 0);
264                 pCanvas->SetCanvasFactor(1.0f);
265                 pCanvas->SetClippingOfFrameVisualElement(true);
266         }
267
268         r = SetCanvasImageBounds(canvasIndex, bounds);
269         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
270
271         if (pAnimation != null)
272         {
273                 visualElement.SetImplicitAnimationEnabled(true);
274                 frameVisualElement.SetImplicitAnimationEnabled(true);
275                 AddAnimationCount();
276
277                 GetAnimationDelegator().SetGalleryAnimationTiming(*pAnimation);
278
279                 r = visualElement.SetTransformMatrix(endMatrix);
280                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
281                 __animationRunning = true;
282
283                 pCanvas->SetBounds(bounds);
284
285                 visualElement.SetImplicitAnimationEnabled(false);
286                 frameVisualElement.SetImplicitAnimationEnabled(false);
287         }
288         else
289         {
290                 visualElement.RemoveAllAnimations();
291
292                 if (GetAnimationCount() != 0)
293                 {
294                         ResetAnimationCount();
295                         OnAnimationCancel();
296                 }
297
298                 visualElement.SetImplicitAnimationEnabled(false);
299
300                 r = visualElement.SetTransformMatrix(endMatrix);
301                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
302
303                 pCanvas->SetBounds(bounds);
304         }
305
306         FloatPoint anchor;
307         imageBounds = pCanvas->GetImageBounds();
308         anchor.x = (-bounds.x + (GetViewRect().width / 2)) / bounds.width;
309         anchor.y = (-bounds.y + (GetViewRect().height / 2)) / bounds.height;
310         pCanvas->SetImageAnchor(anchor);
311
312         return E_SUCCESS;
313 }
314
315 FloatRectangle
316 _GalleryRenderer::GetCanvasBounds(int canvasIndex) const
317 {
318         _GalleryCanvas* pCanvas = GetCanvasManager().GetCanvas(canvasIndex);
319         SysTryReturn(NID_UI_CTRL, pCanvas != null, FloatRectangle(-1, -1, -1, -1), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
320
321         SetLastResult(E_SUCCESS);
322
323         return pCanvas->GetBounds();
324 }
325
326 FloatRectangle
327 _GalleryRenderer::GetCanvasAlignBoundary(int canvasIndex) const
328 {
329         _GalleryCanvas* pCanvas = GetCanvasManager().GetCanvas(canvasIndex);
330         SysTryReturn(NID_UI_CTRL, pCanvas != null, FloatRectangle(-1, -1, -1, -1), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
331
332         SetLastResult(E_SUCCESS);
333
334         FloatRectangle alignBoundary = pCanvas->GetAlignBoundary();
335         if (alignBoundary.width == -1 || alignBoundary.width < GetViewRect().width)
336         {
337                 alignBoundary = GetViewRect();
338         }
339
340         return alignBoundary;
341 }
342
343 result
344 _GalleryRenderer::SetCanvasImageBounds(int canvasIndex, const FloatRectangle& bounds)
345 {
346         _GalleryCanvas* pCanvas = GetCanvasManager().GetCanvas(canvasIndex);
347         result r = GetLastResult();
348         SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
349         pCanvas->SetImageBounds(bounds);
350
351         return E_SUCCESS;
352 }
353
354 FloatRectangle
355 _GalleryRenderer::GetCanvasImageBounds(int canvasIndex) const
356 {
357         _GalleryCanvas* pCanvas = GetCanvasManager().GetCanvas(canvasIndex);
358         SysTryReturn(NID_UI_CTRL, pCanvas != null, FloatRectangle(-1, -1, -1, -1), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
359
360         SetLastResult(E_SUCCESS);
361
362         return pCanvas->GetImageBounds();
363 }
364
365 result
366 _GalleryRenderer::RunCanvasTransition(int startCanvasIndex, int endCanvasIndex, _GalleryTransitionType transition,
367                                                                         const _GalleryAnimationTiming* pAnimation)
368 {
369         result r = E_SUCCESS;
370         ResetAnimationCount();
371
372         _GalleryCanvas* pCanvas = null;
373         for (int i = 0; i < GetCanvasManager().GetCanvasCount(); i++)
374         {
375                 pCanvas = GetCanvasManager().GetCanvas(i);
376                 r = GetLastResult();
377                 SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
378                 pCanvas->SetVisibility(false);
379         }
380
381         pCanvas = GetCanvasManager().GetCanvas(startCanvasIndex);
382         r = GetLastResult();
383         SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
384
385         r = pCanvas->SetVisibility(true);
386         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
387
388         pCanvas = GetCanvasManager().GetCanvas(endCanvasIndex);
389         r = GetLastResult();
390         SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
391
392         r = pCanvas->SetVisibility(true);
393         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
394
395         switch (transition)
396         {
397         case GALLERY_TRANSITION_DISSOLVE:
398                 r = RunDissolveTransition(startCanvasIndex, endCanvasIndex, pAnimation);
399                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
400                 break;
401         case GALLERY_TRANSITION_ZOOM:
402                 r = RunZoomTransition(startCanvasIndex, endCanvasIndex, pAnimation);
403                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
404                 break;
405         case GALLERY_TRANSITION_PAGE:
406                 r = RunPageTransition(startCanvasIndex, endCanvasIndex, pAnimation);
407                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
408                 break;
409         default:
410                 break;
411         }
412
413         return E_SUCCESS;
414 }
415
416 void
417 _GalleryRenderer::StopAllCanvasAnimation(void)
418 {
419         StopAllAnimation();
420
421         SetLastResult(E_SUCCESS);
422         return;
423 }
424
425 bool
426 _GalleryRenderer::IsRunningCanvasTransition(void) const
427 {
428         bool returnValue = (GetSlideShowPlayType() == GALLERY_SLIDESHOW_NONE && __animationRunning == false);
429
430         return returnValue;
431 }
432
433 bool
434 _GalleryRenderer::IsRunningCanvasAnimation(void) const
435 {
436         return __animationRunning;
437 }
438
439 bool
440 _GalleryRenderer::IsExposed(void) const
441 {
442         return false;
443 }
444
445 result
446 _GalleryRenderer::RefreshView(void)
447 {
448         return GetCanvasManager().GetRootCanvas().RefreshCanvas();
449 }
450
451 result
452 _GalleryRenderer::ReleaseAllCanvasResource(void)
453 {
454         return GetCanvasManager().ReleaseAllCanvasResource();
455 }
456
457 result
458 _GalleryRenderer::ResetAllCanvas(void)
459 {
460         FloatRectangle viewRect = GetViewRect();
461         result r = GetCanvasManager().ResetAllCanvas(viewRect);
462         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
463
464         return E_SUCCESS;
465 }
466
467 result
468 _GalleryRenderer::InitializeCanvasBounds(void)
469 {
470         int canvasCount = GetCanvasManager().GetCanvasCount();
471         _GalleryCanvas* pCanvas = null;
472         FloatRectangle bounds = GetViewRect();
473         result r = E_SUCCESS;
474         for (int canvasIndex = 0; canvasIndex < canvasCount; canvasIndex++)
475         {
476                 pCanvas = GetCanvasManager().GetCanvas(canvasIndex);
477                 r = GetLastResult();
478                 SysTryReturn(NID_UI_CTRL, pCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
479
480                 r = pCanvas->SetBounds(bounds);
481                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
482
483                 r = pCanvas->SetVisibility(false);
484                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
485         }
486
487         return E_SUCCESS;
488 }
489
490
491 result
492 _GalleryRenderer::Draw(void)
493 {
494         result r = E_SUCCESS;
495         if (__showEmptyImage == true)
496         {
497                 r = ShowEmptyImageAndText();
498                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
499                 SysLog(NID_UI_CTRL, "There is no image in gallery.");
500         }
501         else
502         {
503                 r = GetCanvasManager().LoadAllCanvasImage();
504                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
505         }
506
507         return E_SUCCESS;
508 }
509
510 void
511 _GalleryRenderer::GalleryBoundsChanged(int currentCanvasIndex)
512 {
513         _GalleryCanvas* pCanvas = null;
514         result r = E_SUCCESS;
515
516         pCanvas = GetCanvasManager().GetCanvas(currentCanvasIndex);
517         SysTryReturnVoidResult(NID_UI_CTRL, pCanvas != null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
518
519         float factor = pCanvas->GetCanvasFactor();
520         FloatRectangle bounds = pCanvas->GetBounds();
521         bounds.width *= factor;
522         bounds.height *= factor;
523
524         if (bounds.width != GetViewRect().width)
525         {
526                 bounds.x = -(pCanvas->GetImageAnchor().x * bounds.width - GetViewRect().width / 2);
527                 bounds.y = -(pCanvas->GetImageAnchor().y * bounds.height - GetViewRect().height / 2);
528
529                 r = pCanvas->GetFrameVisualElement().SetBounds(FloatRectangle(0.0f, 0.0f, bounds.width, bounds.height));
530                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
531                 pCanvas->SetImageBounds(bounds);
532
533                 r = pCanvas->SetBounds(bounds);
534                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
535         }
536
537         SetLastResult(E_SUCCESS);
538         return;
539 }
540
541 void
542 _GalleryRenderer::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
543 {
544         _GalleryRendererNotification* pRendererNotifier = new (std::nothrow)_GalleryRendererNotification(GALLERY_RENDERER_NOTI_CANVAS_ANIMATION_STARTED);
545         SysTryReturnVoidResult(NID_UI_CTRL, pRendererNotifier != null, E_OUT_OF_MEMORY,
546                                                 "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _GalleryRendererNotification.");
547         GetRendererNotifier().Fire(*pRendererNotifier);
548 }
549
550 void
551 _GalleryRenderer::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
552 {
553         return;
554 }
555
556 void
557 _GalleryRenderer::OnVisualElementAnimationFinished(const VisualElementAnimation& animation,
558                                                                                                         const String& keyName,
559                                                                                                         VisualElement& target,
560                                                                                                         bool completedNormally)
561 {
562         _GalleryRendererNotification* pRendererNotifier = null;
563
564         if (completedNormally == true)
565         {
566                 ReleaseAnimationCount();
567                 if (GetSlideShowPlayType() == GALLERY_SLIDESHOW_NONE)
568                 {
569                         if (GetAnimationCount() == 0)
570                         {
571                                 pRendererNotifier = new (std::nothrow)_GalleryRendererNotification(GALLERY_RENDERER_NOTI_CANVAS_ANIMATION_COMPLETED);
572                                 SysTryReturnVoidResult(NID_UI_CTRL, pRendererNotifier != null, E_OUT_OF_MEMORY,
573                                                                         "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _GalleryRendererNotification.");
574                                 GetRendererNotifier().Fire(*pRendererNotifier);
575                                 __animationRunning = false;
576                         }
577                 }
578                 else
579                 {
580                         if (GetAnimationCount() == 0)
581                         {
582                                 SetSlideShowPlayType(GALLERY_SLIDESHOW_NONE);
583                                 pRendererNotifier = new (std::nothrow)_GalleryRendererNotification(GALLERY_RENDERER_NOTI_TRANSITION_COMPLETED);
584                                 SysTryReturnVoidResult(NID_UI_CTRL, pRendererNotifier != null, E_OUT_OF_MEMORY,
585                                                                                 "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _GalleryRendererNotification.");
586
587                                 GetRendererNotifier().Fire(*pRendererNotifier);
588                         }
589                 }
590         }
591         else
592         {
593                 if (GetSlideShowPlayType() != GALLERY_SLIDESHOW_NONE)
594                 {
595                         SetSlideShowPlayType(GALLERY_SLIDESHOW_NONE);
596                         pRendererNotifier = new (std::nothrow)_GalleryRendererNotification(GALLERY_RENDERER_NOTI_TRANSITION_CANCEL);
597                         SysTryReturnVoidResult(NID_UI_CTRL, pRendererNotifier != null, E_OUT_OF_MEMORY,
598                                                                         "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _GalleryRendererNotification.");
599
600                         GetRendererNotifier().Fire(*pRendererNotifier);
601                 }
602         }
603
604         SetLastResult(E_SUCCESS);
605         return;
606 }
607
608 _GalleryRenderer::_GalleryRenderer(void)
609         : __pControl(null)
610         , __pCanvasManager(null)
611         , __pRendererNotifyer(null)
612         , __pGalleryAnimationDelegator(null)
613         , __emptyString(L"")
614         , __emptyCanvasIndex(-1)
615         , __slideShowAnimationCount(0)
616         , __slideShowPlayType(GALLERY_SLIDESHOW_NONE)
617         , __showEmptyImage(true)
618         , __animationRunning(false)
619         , __needDrawEmptyCanvas(true)
620         , __startCanvasOfPageCurling(-1)
621         , __endCanvasOfPageCurling(-1)
622         , __pEffect(null)
623         , __pTransparentBitmap(null)
624         , __pPageCurlingBitmap(null)
625 {
626         GET_COLOR_CONFIG(GALLERY::EMPTY_TEXT_NORMAL, __emptyTextColor);
627 }
628
629 _GalleryRenderer::~_GalleryRenderer(void)
630 {
631         StopAllAnimation();
632
633         if (GetEffect() != null)
634         {
635                 EffectManager::GetInstance()->DestroyEffect(*__pEffect);
636                 EffectManager::DestroyInstance();
637                 __pEffect = null;
638         }
639
640         delete __pCanvasManager;
641         delete __pGalleryAnimationDelegator;
642         delete __pRendererNotifyer;
643         delete __pTransparentBitmap;
644         delete __pPageCurlingBitmap;
645 }
646
647 result
648 _GalleryRenderer::Construct(_Control& control)
649 {
650         result r = E_SUCCESS;
651         _GalleryRendererNotifier* pRendererNotifier = null;
652         _GalleryCanvasManager* pCanvasManager = null;
653         _GalleryAnimationProvider* pVEDelegator = null;
654         FloatRectangle initialCanvasBounds = control.GetBoundsF();
655
656         pRendererNotifier = new (std::nothrow) _GalleryRendererNotifier();
657         SysTryCatch(NID_UI_CTRL, pRendererNotifier != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
658
659         r = pRendererNotifier->Construct();
660         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
661
662         pVEDelegator = new (std::nothrow) _GalleryAnimationProvider();
663         SysTryCatch(NID_UI_CTRL, pRendererNotifier != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
664
665         pCanvasManager = _GalleryCanvasManager::CreateCanvasManagerN(control, GALLERY_CANVAS_INITIAL_MAX_COUNT, initialCanvasBounds, pVEDelegator);
666         SysTryCatch(NID_UI_CTRL, pCanvasManager != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
667
668         SetControl(control);
669         SetRendererNotifier(*pRendererNotifier);
670         SetCanvasManager(*pCanvasManager);
671         SetAnimationDelegator(*pVEDelegator);
672
673         GetAnimationDelegator().SetAnimationDelegator(this);
674
675         return E_SUCCESS;
676
677 CATCH:
678         delete pRendererNotifier;
679         delete pVEDelegator;
680
681         return r;
682 }
683
684 result
685 _GalleryRenderer::ShowEmptyImageAndText(void)
686 {
687         Canvas* pEmptyCanvas = null;
688         FloatDimension textDimension(0, 0);
689         Font* pFont = null;
690         TextObject* pTextObject = null;
691         result r = E_SUCCESS;
692
693         if (__needDrawEmptyCanvas == true)
694         {
695                 _GalleryCanvas* pEmptyGalleryCanvas = GetCanvasManager().GetCanvas(GetEmptyCanvasIndex());
696                 r = GetLastResult();
697                 SysTryReturn(NID_UI_CTRL, pEmptyGalleryCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
698
699                 r = pEmptyGalleryCanvas->SetBounds(GetViewRect());
700                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
701
702                 // text
703                 if (__emptyString.GetLength() != 0)
704                 {
705                         pFont = GetControl().GetFallbackFont();
706                         SysTryCatch(NID_UI_CTRL, pFont != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
707
708                         pFont->GetTextExtent(__emptyString, __emptyString.GetLength(), textDimension);
709
710                         pTextObject = new (std::nothrow) TextObject;
711                         SysTryCatch(NID_UI_CTRL, pTextObject != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
712
713                         pTextObject->Construct();//(const_cast<wchar_t*>(__emptyString.GetPointer())), __emptyString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
714                         TextSimple* pSimpleText = new (std::nothrow)TextSimple((const_cast<wchar_t*>(__emptyString.GetPointer())), __emptyString.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
715                         pTextObject->AppendElement(*pSimpleText);
716
717                         pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
718                         pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
719                         pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
720                         pTextObject->SetFont(pFont, 0, pTextObject->GetTextLength());
721                         textDimension = pTextObject->GetTextExtentF(0, pTextObject->GetTextLength());
722
723                         if (textDimension.width > GetViewRect().width)
724                         {
725                                 textDimension.width = GetViewRect().width;
726                         }
727                         pTextObject->SetForegroundColor(__emptyTextColor, 0, pTextObject->GetTextLength());
728                 }
729
730                 FloatPoint imagePosition(0, 0);
731                 FloatPoint textPosition(0, 0);
732                 FloatDimension imageSize(0, 0);
733                 FloatRectangle visualElementBounds(0, 0, 0, 0);
734                 _GalleryBitmap* pImage = pEmptyGalleryCanvas->GetImage();
735                 if (pImage != null)
736                 {
737                         imageSize = pImage->GetSize();
738                 }
739
740                 if (imageSize.width >= textDimension.width)
741                 {
742                         visualElementBounds.x = GetViewRect().width - imageSize.width;
743                         visualElementBounds.width = imageSize.width;
744                         if (imageSize.width != textDimension.width)
745                         {
746                                 textPosition.x = (imageSize.width - textDimension.width) / 2;
747                         }
748                 }
749                 else
750                 {
751                         visualElementBounds.x = GetViewRect().width - textDimension.width;
752                         visualElementBounds.width = textDimension.width;
753                         imagePosition.x = (textDimension.width - imageSize.width) / 2;
754                 }
755                 visualElementBounds.height = imageSize.height + textDimension.height;
756                 visualElementBounds.y = GetViewRect().height - visualElementBounds.height;
757
758                 visualElementBounds.x = visualElementBounds.x / 2;
759                 visualElementBounds.y = visualElementBounds.y / 2;
760
761                 pEmptyGalleryCanvas->SetVisualElementBounds(visualElementBounds);
762
763                 FloatRectangle imageBounds(imagePosition.x, imagePosition.y, imageSize.width, imageSize.height);
764                 pEmptyGalleryCanvas->SetImageBounds(imageBounds);
765
766                 if (pImage != null || __emptyString.GetLength() != 0)
767                 {
768                         pEmptyCanvas = pEmptyGalleryCanvas->GetImageVisualElement().GetCanvasN();
769                         r = GetLastResult();
770                         SysTryCatch(NID_UI_CTRL, pEmptyCanvas != null, , r, "[%s] Propagating.", GetErrorMessage(r));
771
772                         Color color(0, 0, 0, 0);
773                         pEmptyCanvas->SetBackgroundColor(color);
774
775                         r = pEmptyCanvas->Clear();
776                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
777
778                         if (pImage != null)
779                         {
780                                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*(pImage->GetInternalBitmap())))
781                                 {
782                                         FloatDimension size = pImage->GetSize();
783                                         FloatRectangle rect(imagePosition.x, imagePosition.y, size.width, size.height);
784                                         r = pEmptyCanvas->DrawNinePatchedBitmap(rect, *pImage->GetInternalBitmap());
785                                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
786                                 }
787                                 else
788                                 {
789                                         r = pEmptyCanvas->DrawBitmap(imagePosition, *pImage->GetInternalBitmap());
790                                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
791                                 }
792                         }
793
794                         textPosition.y = imageBounds.y + imageBounds.height;
795                         if (pTextObject != null)
796                         {
797                                 pTextObject->SetBounds(FloatRectangle(textPosition.x, textPosition.y, textDimension.width, textDimension.height));
798                                 pTextObject->Draw(*_CanvasImpl::GetInstance(*pEmptyCanvas));
799
800                                 delete pTextObject;
801                                 pTextObject = null;
802                         }
803                 }
804
805                 r = pEmptyGalleryCanvas->GetImageVisualElement().SetFlushNeeded();
806                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
807
808                 delete pEmptyCanvas;
809
810                 r = pEmptyGalleryCanvas->SetVisibility(true);
811                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
812
813                 __needDrawEmptyCanvas = false;
814         }
815
816         return E_SUCCESS;
817
818 CATCH:
819         delete pTextObject;
820         delete pEmptyCanvas;
821
822         return r;
823 }
824
825 result
826 _GalleryRenderer::RunDissolveTransition(int startCanvasIndex, int endCanvasIndex, const _GalleryAnimationTiming* pAnimation)
827 {
828         SysTryReturn(NID_UI_CTRL, pAnimation != null, E_INVALID_ARG, E_INVALID_ARG,
829                                 "[E_INVALID_ARG] The gallery animation timing is null");
830
831         FloatRectangle viewBounds = GetViewRect();
832         result r = SetCanvasBounds(endCanvasIndex, viewBounds);
833         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
834
835         _GalleryCanvas* pStartCanvas = GetCanvasManager().GetCanvas(startCanvasIndex);
836         r = GetLastResult();
837         SysTryReturn(NID_UI_CTRL, pStartCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
838
839         _GalleryCanvas* pEndCanvas = GetCanvasManager().GetCanvas(endCanvasIndex);
840         r = GetLastResult();
841         SysTryReturn(NID_UI_CTRL, pEndCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
842
843         _VisualElement& startVisualElement = pStartCanvas->GetFrameVisualElement();
844         r = startVisualElement.SetZOrder(&pEndCanvas->GetFrameVisualElement(), true);
845         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
846
847         startVisualElement.SetImplicitAnimationEnabled(true);
848
849         GetAnimationDelegator().SetGalleryAnimationTiming(*pAnimation);
850         startVisualElement.SetOpacity(0.0f);
851         AddAnimationCount();
852
853         startVisualElement.SetImplicitAnimationEnabled(false);
854
855         pEndCanvas->GetFrameVisualElement().SetOpacity(0.0f);
856
857         pEndCanvas->GetFrameVisualElement().SetImplicitAnimationEnabled(true);
858
859         pEndCanvas->GetFrameVisualElement().SetOpacity(1.0f);
860         //AddAnimationCount();
861
862         pEndCanvas->GetFrameVisualElement().SetImplicitAnimationEnabled(false);
863
864         SetSlideShowPlayType(GALLERY_SLIDESHOW_DISSOLVE);
865
866         return E_SUCCESS;
867 }
868
869 result
870 _GalleryRenderer::RunZoomTransition(int startCanvasIndex, int endCanvasIndex, const _GalleryAnimationTiming* pAnimation)
871 {
872         result r = RunDissolveTransition(startCanvasIndex, endCanvasIndex, pAnimation);
873         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
874
875         FloatRectangle viewRect = GetViewRect();
876         FloatRectangle zoomBounds = viewRect;
877         zoomBounds.width *= GALLERY_ZOOM_TRANSITION_ZOOM_FACTOR;
878         zoomBounds.height *= GALLERY_ZOOM_TRANSITION_ZOOM_FACTOR;
879         zoomBounds.x = -(viewRect.width / 2 * (GALLERY_ZOOM_TRANSITION_ZOOM_FACTOR - 1));
880         zoomBounds.y = -(viewRect.height / 2 * (GALLERY_ZOOM_TRANSITION_ZOOM_FACTOR - 1));
881
882         r = SetCanvasBounds(startCanvasIndex, zoomBounds, pAnimation);
883         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
884
885         //AddAnimationCount();
886
887         SetSlideShowPlayType(GALLERY_SLIDESHOW_ZOOM);
888
889         return E_SUCCESS;
890 }
891
892 result
893 _GalleryRenderer::RunPageTransition(int startCanvasIndex, int endCanvasIndex, const _GalleryAnimationTiming* pAnimation)
894 {
895         SysTryReturn(NID_UI_CTRL, pAnimation != null, E_INVALID_ARG, E_INVALID_ARG,
896                                 "[E_INVALID_ARG] The gallery animation timing is null");
897
898         result r = E_SUCCESS;
899         Effect* pEffect = null;
900         if (GetEffect() == null)
901         {
902                 pEffect = EffectManager::GetInstance()->CreateEffect(L"/usr/share/osp/effects/gallery_page_curling.eff");
903                 r = GetLastResult();
904                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
905
906                 _GalleryImpl* pImpl = static_cast<_GalleryImpl*>(__pControl->GetUserData());
907                 Gallery& pPublic = pImpl->GetPublic();
908                 r = pEffect->SetRenderTarget(&pPublic);
909                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
910
911                 SetEffect(pEffect);
912                 r = GetLastResult();
913                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
914
915                 pEffect = null;
916         }
917
918         SetStartCanvasOfPageCurling(startCanvasIndex);
919         SetEndCanvasOfPageCurling(endCanvasIndex);
920
921         r = SetCanvasBounds(startCanvasIndex, GetViewRect());
922         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
923
924         r = SetCanvasVisibility(startCanvasIndex, false);
925         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
926
927         r = SetCanvasVisibility(endCanvasIndex, false);
928         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
929
930         r = __pEffect->Start();
931         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
932
933         SetSlideShowPlayType(GALLERY_SLIDESHOW_PAGE);
934
935         return E_SUCCESS;
936
937 CATCH:
938         if (pEffect != null)
939         {
940                 EffectManager::GetInstance()->DestroyEffect(*pEffect);
941                 pEffect = null;
942         }
943         if (__pEffect != null)
944         {
945                 EffectManager::GetInstance()->DestroyEffect(*__pEffect);
946                 __pEffect = null;
947         }
948         EffectManager::DestroyInstance();
949
950         return r;
951 }
952
953 void
954 _GalleryRenderer::OnAnimationCancel(void)
955 {
956         _GalleryRendererNotification* pRendererNoti = new (std::nothrow)_GalleryRendererNotification(GALLERY_RENDERER_NOTI_CANVAS_ANIMATION_CANCEL);
957         SysTryReturnVoidResult(NID_UI_CTRL, pRendererNoti != null, E_OUT_OF_MEMORY,
958                                                         "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _GalleryRendererNotification.");
959
960         GetRendererNotifier().Fire(*pRendererNoti);
961
962         SetLastResult(E_SUCCESS);
963         return;
964 }
965
966 void
967 _GalleryRenderer::SetControl(_Control& control)
968 {
969         __pControl = &control;
970         return;
971 }
972
973 _Control&
974 _GalleryRenderer::GetControl(void) const
975 {
976         return *__pControl;
977 }
978
979 void
980 _GalleryRenderer::SetCanvasManager(_GalleryCanvasManager& canvasManager)
981 {
982         __pCanvasManager = &canvasManager;
983         return;
984 }
985
986 _GalleryCanvasManager&
987 _GalleryRenderer::GetCanvasManager(void) const
988 {
989         return (_GalleryCanvasManager&)*__pCanvasManager;
990 }
991
992 void
993 _GalleryRenderer::SetRendererNotifier(_GalleryRendererNotifier& rendererNotifier)
994 {
995         __pRendererNotifyer = &rendererNotifier;
996         return;
997 }
998
999 _GalleryRendererNotifier&
1000 _GalleryRenderer::GetRendererNotifier(void) const
1001 {
1002         return (_GalleryRendererNotifier&)*__pRendererNotifyer;
1003 }
1004
1005 void
1006 _GalleryRenderer::SetAnimationDelegator(_GalleryAnimationProvider& galleryVEDelegator)
1007 {
1008         __pGalleryAnimationDelegator = &galleryVEDelegator;
1009         return;
1010 }
1011
1012 _GalleryAnimationProvider&
1013 _GalleryRenderer::GetAnimationDelegator(void) const
1014 {
1015         return *__pGalleryAnimationDelegator;
1016 }
1017
1018 void
1019 _GalleryRenderer::SetEmptyCanvasIndex(int emptyCanvasIndex)
1020 {
1021         __emptyCanvasIndex = emptyCanvasIndex;
1022         return;
1023 }
1024
1025 int
1026 _GalleryRenderer::GetEmptyCanvasIndex(void) const
1027 {
1028         return __emptyCanvasIndex;
1029 }
1030
1031 void
1032 _GalleryRenderer::SetSlideShowPlayType(_GallerySlideShowType slideShowType)
1033 {
1034         __slideShowPlayType = slideShowType;
1035         return;
1036 }
1037
1038 _GallerySlideShowType
1039 _GalleryRenderer::GetSlideShowPlayType(void) const
1040 {
1041         return __slideShowPlayType;
1042 }
1043
1044 void
1045 _GalleryRenderer::AddAnimationCount(void)
1046 {
1047         __slideShowAnimationCount++;
1048         return;
1049 }
1050
1051 void
1052 _GalleryRenderer::ReleaseAnimationCount(void)
1053 {
1054         __slideShowAnimationCount--;
1055         return;
1056 }
1057
1058 void
1059 _GalleryRenderer::ResetAnimationCount(void)
1060 {
1061         __slideShowAnimationCount = 0;
1062         return;
1063 }
1064
1065 int
1066 _GalleryRenderer::GetAnimationCount(void) const
1067 {
1068         return __slideShowAnimationCount;
1069 }
1070
1071 void
1072 _GalleryRenderer::StopAllAnimation(void)
1073 {
1074         _GalleryCanvas* pCanvas = null;
1075         int canvasCount = GetCanvasManager().GetCanvasCount();
1076         result r = E_SUCCESS;
1077         for (int i = 0; i < canvasCount; i++)
1078         {
1079                 pCanvas = GetCanvasManager().GetCanvas(i);
1080                 r = GetLastResult();
1081                 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas != null, r, "[%s] Propagating.", GetErrorMessage(r));
1082
1083                 pCanvas->GetImageVisualElement().RemoveAllAnimations();
1084                 pCanvas->GetFrameVisualElement().RemoveAllAnimations();
1085         }
1086
1087         Canvas* pRootCanvas = null;
1088         Effect* pEffect = __pEffect;
1089         if (__pEffect != null)
1090         {
1091                 __pEffect = null;
1092                 if (pEffect->IsRunning() == true)
1093                 {
1094                         r = pEffect->Stop();
1095                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1096                 }
1097
1098                 EffectManager::GetInstance()->DestroyEffect(*pEffect);
1099                 EffectManager::DestroyInstance();
1100                 pEffect = null;
1101
1102                 pRootCanvas = GetCanvasManager().GetRootCanvas().GetImageVisualElement()->GetCanvasN();
1103                 r = GetLastResult();
1104                 SysTryReturnVoidResult(NID_UI_CTRL, pRootCanvas != null, r, "[%s] Propagating.", GetErrorMessage(r));
1105
1106                 pRootCanvas->SetBackgroundColor(GetCanvasManager().GetRootCanvas().GetBackgroundColor());
1107                 r = pRootCanvas->Clear();
1108                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1109
1110                 delete pRootCanvas;
1111
1112                 r = Draw();
1113                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1114         }
1115         ResetAnimationCount();
1116
1117         SetLastResult(E_SUCCESS);
1118         return;
1119
1120 CATCH:
1121         if (pEffect != null)
1122         {
1123                 EffectManager::GetInstance()->DestroyEffect(*pEffect);
1124                 EffectManager::DestroyInstance();
1125                 pEffect = null;
1126         }
1127
1128         delete pRootCanvas;
1129 }
1130
1131 // 3d effect listener
1132 void
1133 _GalleryRenderer::OnEffectStarted(Effect& effect)
1134 {
1135 }
1136
1137 void
1138 _GalleryRenderer::OnEffectFinished(Effect& effect, EffectResult effectResult, const IList& lastShownBitmapIds)
1139 {
1140         FloatRectangle viewBounds = GetViewRect();
1141         int endCanvasIndex = GetEndCanvasOfPageCurling();
1142         result r = SetCanvasBounds(endCanvasIndex, viewBounds);
1143         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1144
1145         int startCanvasIndex = GetStartCanvasOfPageCurling();
1146         r = SetCanvasVisibility(startCanvasIndex, false);
1147         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1148
1149         delete __pTransparentBitmap;
1150         __pTransparentBitmap = null;
1151
1152         delete __pPageCurlingBitmap;
1153         __pPageCurlingBitmap = null;
1154
1155         _GalleryRendererNotification* pRendererNotifier = null;
1156         if (effectResult == EFFECT_RESULT_FINISHED)
1157         {
1158                 pRendererNotifier = new (std::nothrow)_GalleryRendererNotification(GALLERY_RENDERER_NOTI_TRANSITION_COMPLETED);
1159                 SysTryReturnVoidResult(NID_UI_CTRL, pRendererNotifier != null, E_OUT_OF_MEMORY,
1160                                         "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _GalleryRendererNotification.");
1161                 GetRendererNotifier().FireAsync(*pRendererNotifier);
1162         }
1163         else
1164         {
1165                 pRendererNotifier = new (std::nothrow)_GalleryRendererNotification(GALLERY_RENDERER_NOTI_TRANSITION_CANCEL);
1166                 SysTryReturnVoidResult(NID_UI_CTRL, pRendererNotifier != null, E_OUT_OF_MEMORY,
1167                                         "[E_OUT_OF_MEMORY] Failed to allocate the memory for the _GalleryRendererNotification.");
1168                 GetRendererNotifier().Fire(*pRendererNotifier);
1169         }
1170
1171         SetSlideShowPlayType(GALLERY_SLIDESHOW_NONE);
1172         ResetAnimationCount();
1173 }
1174
1175 // 3d effect provider
1176 result
1177 _GalleryRenderer::SetBitmap(Effect& effect, long bitmapId)
1178 {
1179         int startCanvasIndex = GetStartCanvasOfPageCurling();
1180         int endCanvasIndex = GetEndCanvasOfPageCurling();
1181
1182         _GalleryCanvas* pStartCanvas = GetCanvasManager().GetCanvas(startCanvasIndex);
1183         result r = GetLastResult();
1184         SysTryReturn(NID_UI_CTRL, pStartCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
1185
1186         _GalleryCanvas* pEndCanvas = GetCanvasManager().GetCanvas(endCanvasIndex);
1187         r = GetLastResult();
1188         SysTryReturn(NID_UI_CTRL, pEndCanvas != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
1189
1190         if (bitmapId == 0)
1191         {
1192                 Canvas pageCurlingCanvas;
1193                 r = pageCurlingCanvas.Construct(GetViewRect());
1194                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1195
1196                 pageCurlingCanvas.SetBackgroundColor(__pControl->GetBackgroundColor());
1197                 r = GetLastResult();
1198                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1199
1200                 r = pageCurlingCanvas.Clear();
1201                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1202
1203                 FloatRectangle imageBounds = pStartCanvas->GetImageBounds();
1204                 r = pageCurlingCanvas.DrawBitmap(imageBounds, *pStartCanvas->GetImage()->GetInternalBitmap());
1205                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1206
1207                 __pPageCurlingBitmap = new (std::nothrow) Bitmap();
1208                 SysTryReturn(NID_UI_CTRL, __pPageCurlingBitmap != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1209
1210                 r = __pPageCurlingBitmap->Construct(pageCurlingCanvas, GetViewRect());
1211                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1212
1213                 effect.SetBitmap(bitmapId, *__pPageCurlingBitmap);
1214         }
1215         else if (bitmapId == 1)
1216         {
1217                 Canvas transparentCanvas;
1218                 r = transparentCanvas.Construct(GetViewRect());
1219                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1220
1221                 transparentCanvas.SetBackgroundColor(__pControl->GetBackgroundColor());
1222                 r = GetLastResult();
1223                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1224
1225                 r = transparentCanvas.Clear();
1226                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1227
1228                 FloatRectangle imageBounds = pEndCanvas->GetImageBounds();
1229                 r = transparentCanvas.DrawBitmap(imageBounds, *pEndCanvas->GetImage()->GetInternalBitmap());
1230                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1231
1232                 __pTransparentBitmap = new (std::nothrow) Bitmap();
1233                 SysTryReturn(NID_UI_CTRL, __pTransparentBitmap != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1234
1235                 r = __pTransparentBitmap->Construct(transparentCanvas, GetViewRect());
1236
1237                 //r = __pTransparentBitmap->Construct(viewBounds);
1238                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1239
1240                 effect.SetBitmap(bitmapId, *__pTransparentBitmap);
1241         }
1242
1243         return E_SUCCESS;
1244 }
1245
1246 void
1247 _GalleryRenderer::SetStartCanvasOfPageCurling(int startCanvasIndex)
1248 {
1249         __startCanvasOfPageCurling = startCanvasIndex;
1250 }
1251
1252 int
1253 _GalleryRenderer::GetStartCanvasOfPageCurling(void)
1254 {
1255         return __startCanvasOfPageCurling;
1256 }
1257
1258 void
1259 _GalleryRenderer::SetEndCanvasOfPageCurling(int endCanvasIndex)
1260 {
1261         __endCanvasOfPageCurling = endCanvasIndex;
1262 }
1263
1264 int
1265 _GalleryRenderer::GetEndCanvasOfPageCurling(void)
1266 {
1267         return __endCanvasOfPageCurling;
1268 }
1269
1270 void
1271 _GalleryRenderer::SetEffect(Effect* pEffect)
1272 {
1273         SysTryReturnVoidResult(NID_UI_CTRL, pEffect != null, E_INVALID_ARG, "[E_INVALID_ARG] The effect object is null.");
1274
1275         pEffect->SetEffectEventListener(this);
1276         result r = GetLastResult();
1277         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1278
1279         pEffect->SetResourceProvider(this);
1280         r = GetLastResult();
1281         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1282
1283         __pEffect = pEffect;
1284
1285         SetLastResult(E_SUCCESS);
1286 }
1287
1288 Tizen::Ui::Effects::Effect*
1289 _GalleryRenderer::GetEffect(void)
1290 {
1291         return __pEffect;
1292 }
1293
1294 }}} // Tizen::Ui::Controls
1295