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