Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_GalleryPresenter.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 <FBaseRtTimer.h>
19 #include <FBaseSysLog.h>
20 #include "FUi_Math.h"
21 #include "FUi_ResourceManager.h"
22 #include "FUiCtrl_GalleryPresenter.h"
23 #include "FUiCtrl_GalleryModel.h"
24 #include "FUiCtrl_GalleryItemProvider.h"
25 #include "FUiCtrl_GalleryCoreEvent.h"
26 #include "FUiCtrl_GalleryCoreEventArg.h"
27 #include "FUiCtrl_GalleryImageReader.h"
28 #include "FUiCtrl_GalleryViewEventHandler.h"
29 #include "FUiCtrl_IGalleryCoreEventListener.h"
30 #include "FUiCtrl_IGalleryRenderer.h"
31 #include "FUiCtrl_GalleryBitmap.h"
32 #include "FUiCtrl_GalleryViewEvent.h"
33 #include "FUiAnim_VisualElement.h"
34
35
36 using namespace Tizen::Base;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui;
39
40 namespace Tizen { namespace Ui { namespace Controls {
41
42 namespace
43 {
44
45 const int DEFAULT_ITEM_SPACING = 30;
46
47 const int DEFAULT_ANIMATION_DURATION = 3000;
48 const int MIN_ANIMATION_DURATION = 300;
49 const int MAX_ANIMATION_DURATION = 20000;
50 const int DEFAULT_VIEW_DURATION = 10;
51 const int MIN_VIEW_DURATION = 10;
52 const int FIRST_SLIDE_SHOW_DURATION = 1;
53
54 const int PARTIAL_CANVAS = 0;
55 } // unnamed namespace
56
57 IMPLEMENT_PROPERTY(_GalleryPresenter);
58
59 _GalleryPresenter::_GalleryPresenter(_IGalleryRenderer& galleryRenderer)
60         : __galleryRenderer(galleryRenderer)
61         , __pGalleryViewEventHandler(null)
62         , __pGalleryCoreEvent(null)
63         , __pGalleryItemProvider(null)
64         , __pGalleryModel(null)
65         , __pGalleryImageReader(null)
66         , __pEmptyGalleryImage(null)
67         , __emptyText(L"")
68         , __slideShowAnimationDuration(DEFAULT_ANIMATION_DURATION)
69         , __slideShowViewDuration(DEFAULT_VIEW_DURATION)
70         , __gallerySlideShowType(GALLERY_SLIDESHOW_DISSOLVE)
71         , __currentItemIndex(NO_CURRENT_IMAGE)
72         , __slideShowRepeat(false)
73         , __slideShowStarted(false)
74         , __zoomingEnabled(true)
75         , __pSlideShowTimer(null)
76         , __slideShowPlayCount(0)
77         , __itemSpacing(DEFAULT_ITEM_SPACING)
78         , __pItemToCanvas(null)
79         , __fittingType(GALLERY_FITTING_TYPE_FIT)
80         , __verticalAlignment(GALLERY_VERTICAL_ALIGN_MIDDLE)
81         , __horizontalAlignment(GALLERY_HORIZONTAL_ALIGN_CENTER)
82         , __emptyFontSize(0)
83         , __emptyFontStyle(FONT_STYLE_PLAIN)
84 {
85         AddPropertyChangeEventListener(*this);
86 }
87
88 _GalleryPresenter::~_GalleryPresenter(void)
89 {
90         delete __pGalleryViewEventHandler;
91         delete __pGalleryImageReader;
92         delete __pGalleryModel;
93         delete __pGalleryItemProvider;
94         delete __pGalleryCoreEvent;
95         delete __pEmptyGalleryImage;
96         delete[] __pItemToCanvas;
97         delete __pSlideShowTimer;
98         __pSlideShowTimer = null;
99 }
100
101 _GalleryPresenter*
102 _GalleryPresenter::CreateGalleryPresenterN(_IGalleryRenderer& galleryRenderer, _GalleryItemProviderAdaptorImpl* pGalleryItemProviderAdaptor)
103 {
104         _GalleryPresenter* pPresenter = new (std::nothrow) _GalleryPresenter(galleryRenderer);
105         SysTryReturn(NID_UI_CTRL, pPresenter != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
106
107         result r = pPresenter->Construct(pGalleryItemProviderAdaptor);
108         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
109
110         SetLastResult(E_SUCCESS);
111         return pPresenter;
112
113 CATCH:
114         delete pPresenter;
115
116         return null;
117 }
118
119 result
120 _GalleryPresenter::Construct(_GalleryItemProviderAdaptorImpl* pGalleryItemProviderAdaptor)
121 {
122         SetLastResult(E_SUCCESS);
123
124         result r = E_SUCCESS;
125
126         __pGalleryCoreEvent = new (std::nothrow) _GalleryCoreEvent();
127         SysTryCatch(NID_UI_CTRL, __pGalleryCoreEvent != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
128
129         __pGalleryItemProvider = new (std::nothrow) _GalleryItemProvider(*__pGalleryCoreEvent, pGalleryItemProviderAdaptor);
130         SysTryCatch(NID_UI_CTRL, __pGalleryItemProvider != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
131
132         __pGalleryModel = _GalleryModel::CreateGalleryModelN(*__pGalleryItemProvider);
133         SysTryCatch(NID_UI_CTRL, __pGalleryModel != null, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
134
135         __pGalleryImageReader = new (std::nothrow) _GalleryImageReader(*__pGalleryModel);
136         SysTryCatch(NID_UI_CTRL, __pGalleryImageReader != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
137
138         __pItemToCanvas = new(std::nothrow) int[MAX_CANVAS_COUNT];
139         SysTryCatch(NID_UI_CTRL, __pItemToCanvas != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
140         memset(__pItemToCanvas, -1, sizeof(int) * MAX_CANVAS_COUNT);
141
142         r = __galleryRenderer.SetCanvasMaxCount(MAX_CANVAS_COUNT);
143         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
144
145         r = __galleryRenderer.EnableEmptyView();
146         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
147
148         GET_STRING_CONFIG(IDS_COM_BODY_NO_IMAGES, __emptyText);
149         r = __galleryRenderer.SetEmptyText(__emptyText);
150         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
151
152         __pGalleryViewEventHandler = new (std::nothrow) _GalleryViewEventHandler(*this, __galleryRenderer, *__pGalleryImageReader);
153         SysTryCatch(NID_UI_CTRL, __pGalleryViewEventHandler != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
154
155         r = __pGalleryViewEventHandler->Construct();
156         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
157
158         SetFontStyle(FONT_STYLE_PLAIN);
159         SetFontSize(32);
160
161         return E_SUCCESS;
162
163 CATCH:
164         delete __pGalleryViewEventHandler;
165         delete __pGalleryImageReader;
166         delete __pGalleryModel;
167         delete __pGalleryItemProvider;
168         delete __pGalleryCoreEvent;
169         delete[] __pItemToCanvas;
170
171         return r;
172 }
173
174 int
175 _GalleryPresenter::GetCurrentItemIndex(void) const
176 {
177         return __currentItemIndex;
178 }
179
180 result
181 _GalleryPresenter::SetCurrentItemIndex(int index, bool eventFire)
182 {
183         SysTryReturn(NID_UI_CTRL, index < __pGalleryModel->GetItemCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
184                         "[E_OUT_OF_RANGE] The argument(%d) is out of range.", index);
185
186         if (__currentItemIndex != NO_CURRENT_IMAGE && __currentItemIndex != index)
187         {
188                 __currentItemIndex = index;
189                 if (eventFire == true)
190                 {
191                         ChangedItem();
192                 }
193         }
194         else
195         {
196                 __currentItemIndex = index;
197         }
198
199         __pGalleryViewEventHandler->SetZoomFlag(false);
200
201         return E_SUCCESS;
202 }
203
204 result
205 _GalleryPresenter::SetCurrentItem(int index)
206 {
207         SysTryReturn(NID_UI_CTRL, index >=0 && index < __pGalleryModel->GetItemCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
208                                         "[E_OUT_OF_RANGE] The argument(%d) is out of range.", index);
209
210         int oldCurrentCanvasIndex = 0;
211         result r = E_SUCCESS;
212
213         if (index == __currentItemIndex)
214         {
215                 return E_SUCCESS;
216         }
217
218         if (__currentItemIndex != NO_CURRENT_IMAGE)
219         {
220                 oldCurrentCanvasIndex = SearchCanvasIndex(__currentItemIndex);
221                 SysTryReturn(NID_UI_CTRL, oldCurrentCanvasIndex != NOT_EXIST_CANVAS, E_SYSTEM, E_SYSTEM,
222                                         "[E_SYSTEM] The canvas of %d item is not exist.", oldCurrentCanvasIndex);
223
224                 if (__currentItemIndex > index)
225                 {
226                         Rectangle rect = __galleryRenderer.GetViewRect();
227                         rect.x = rect.width;
228                         r = __galleryRenderer.SetCanvasBounds(oldCurrentCanvasIndex, rect);
229                 }
230                 else if (__currentItemIndex < index)
231                 {
232                         Rectangle rect = __galleryRenderer.GetViewRect();
233                         rect.x = -rect.width;
234                         r = __galleryRenderer.SetCanvasBounds(oldCurrentCanvasIndex, rect);
235                 }
236
237                 r = __galleryRenderer.SetCanvasVisibility(oldCurrentCanvasIndex, false);
238                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
239         }
240
241         int newCurrentCanvasIndex = SearchCanvasIndex(index);
242         if (newCurrentCanvasIndex == NOT_EXIST_CANVAS)
243         {
244                 r = SetCanvasImage(index);
245                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
246                 newCurrentCanvasIndex = SearchCanvasIndex(index);
247         }
248         r = __galleryRenderer.SetCanvasBounds(newCurrentCanvasIndex, __galleryRenderer.GetViewRect());
249         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
250
251         r = __galleryRenderer.SetCanvasVisibility(newCurrentCanvasIndex, true);
252         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
253
254         r = SetCurrentItemIndex(index);
255         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
256
257         //RefreshView();
258
259         return E_SUCCESS;
260
261 CATCH:
262         result resultValue = __galleryRenderer.SetCanvasVisibility(oldCurrentCanvasIndex, true);
263         if (resultValue != E_SUCCESS)
264         {
265                 SysLog(NID_UI_CTRL, "[%s] Failed to setting of canvas visibility.", GetErrorMessage(resultValue));
266         }
267
268         return r;
269 }
270
271 int
272 _GalleryPresenter::GetItemCount(void) const
273 {
274         return __pGalleryModel->GetItemCount();
275 }
276
277 void
278 _GalleryPresenter::SetItemSpacing(int spacing)
279 {
280         __itemSpacing = spacing;
281 }
282 int
283 _GalleryPresenter::GetItemSpacing(void) const
284 {
285         return __itemSpacing;
286 }
287
288 _GallerySlideShowType
289 _GalleryPresenter::GetSlideShowType(void) const
290 {
291         return __gallerySlideShowType;
292 }
293
294 result
295 _GalleryPresenter::SetSlideShowType(_GallerySlideShowType slideShowType)
296 {
297         SysTryReturn(NID_UI_CTRL, slideShowType >= GALLERY_SLIDESHOW_DISSOLVE && slideShowType <= GALLERY_SLIDESHOW_PAGE,
298                                 E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The animation argument(%d) is out of range", slideShowType);
299
300         __gallerySlideShowType = slideShowType;
301
302         return E_SUCCESS;
303 }
304
305 int
306 _GalleryPresenter::GetSlideShowAnimationDuration(void) const
307 {
308         Variant variant = GetProperty("slideShowAnimationDuration");
309         return variant.ToInt();
310 }
311
312 result
313 _GalleryPresenter::SetSlideShowAnimationDuration(int duration)
314 {
315         SysTryReturn(NID_UI_CTRL, duration >= MIN_ANIMATION_DURATION && duration <= MAX_ANIMATION_DURATION,
316                         E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The argument(%d) is out of range.", duration);
317
318         return SetProperty("slideShowAnimationDuration", Variant(duration));
319 }
320
321 int
322 _GalleryPresenter::GetSlideShowViewDuration(void) const
323 {
324         Variant variant = GetProperty("slideShowViewDuration");
325         return variant.ToInt();
326 }
327
328 result
329 _GalleryPresenter::SetSlideShowViewDuration(int duration)
330 {
331         SysTryReturn(NID_UI_CTRL, duration >= MIN_VIEW_DURATION, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
332                         "[E_OUT_OF_RANGE] The argument(%d) is out of range.", duration);
333
334         return SetProperty("slideShowViewDuration", Variant(duration));
335 }
336
337 result
338 _GalleryPresenter::StartSlideShow(bool repeat)
339 {
340         SysTryReturn(NID_UI_CTRL, __pSlideShowTimer == null, E_INVALID_OPERATION, E_INVALID_OPERATION,
341                         "[E_INVALID_OPERATION] Slide show is already started");
342
343         if (GetItemCount() == 0)
344         {
345                 return E_SUCCESS;
346         }
347
348         __slideShowRepeat = repeat;
349         __slideShowPlayCount = GetItemCount() - 1;
350
351         result r = StartSlideShowTimer(GetSlideShowViewDuration());
352         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
353
354         _GalleryCoreEventArg* pArg = new(std::nothrow) _GalleryCoreEventArg(GALLERY_CORE_EVENT_SLIDE_SHOW_STARTED);
355         __pGalleryCoreEvent->Fire(*pArg);
356
357         return E_SUCCESS;
358 }
359
360 result
361 _GalleryPresenter::StopSlideShow(void)
362 {
363         SysTryReturn(NID_UI_CTRL, __pSlideShowTimer != null, E_INVALID_OPERATION, E_INVALID_OPERATION,
364                         "[E_INVALID_OPERATION] Slide show is already stopped");
365
366         StopSlideShowTimer();
367         __galleryRenderer.StopAllCanvasAnimation();
368
369         result r = __pGalleryViewEventHandler->SetVisibleCanvas();
370         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
371
372         _GalleryCoreEventArg* pArg = new(std::nothrow) _GalleryCoreEventArg(GALLERY_CORE_EVENT_SLIDE_SHOW_STOPPED);
373         __pGalleryCoreEvent->Fire(*pArg);
374
375         r = __galleryRenderer.RefreshView();
376         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
377
378         return E_SUCCESS;
379 }
380
381 String
382 _GalleryPresenter::GetTextOfEmptyGallery(void) const
383 {
384         Variant variant = GetProperty("textOfEmptyGallery");
385         return variant.ToString();
386 }
387
388 result
389 _GalleryPresenter::SetTextOfEmptyGallery(const String& text)
390 {
391         result r = __galleryRenderer.SetEmptyText(text);
392         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
393
394         return SetProperty("textOfEmptyGallery", Variant(text));
395 }
396
397 result
398 _GalleryPresenter::SetBitmapOfEmptyGallery(const _GalleryBitmap* pBitmap)
399 {
400         result r = __galleryRenderer.SetEmptyImage(pBitmap);
401         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
402
403         __pEmptyGalleryImage = const_cast <_GalleryBitmap*>(pBitmap);
404
405         return E_SUCCESS;
406 }
407
408 bool
409 _GalleryPresenter::IsSlideShowStarted(void) const
410 {
411         return __pSlideShowTimer != null ? true : false;
412 }
413
414 result
415 _GalleryPresenter::SetZoomingEnabled(bool enable)
416 {
417         return SetProperty("zoomingEnabled", Variant(enable));
418 }
419
420 bool
421 _GalleryPresenter::IsZoomingEnabled(void) const
422 {
423         Variant variant = GetProperty("zoomingEnabled");
424
425         return variant.ToBool();
426 }
427
428 bool
429 _GalleryPresenter::PostEvent(_GalleryViewEvent& event)
430 {
431         bool slideShowStarted = false;
432         if (__pSlideShowTimer != null && event.GetEventType() != GALLERY_VIEW_EVENT_BOUNDS_CHANGED)
433         {
434                 result r = StopSlideShow();
435                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
436                 slideShowStarted = true;
437         }
438
439         if (GetItemCount() == 0)
440         {
441                 if (event.GetEventType() == GALLERY_VIEW_EVENT_BOUNDS_CHANGED)
442                 {
443                         return OnBoundsChanged();
444                 }
445                 //SetLastResult(E_SUCCESS);
446                 return true;
447         }
448
449         switch (event.GetEventType())
450         {
451         case GALLERY_VIEW_EVENT_TOUCH_PRESSED:
452         {
453                 if (slideShowStarted == true)
454                 {
455                         result r = __pGalleryViewEventHandler->SetVisibleCanvas();
456                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
457                         return true;
458                 }
459                 return __pGalleryViewEventHandler->OnTouchPressed(*(event.GetEventInfo()));
460         }
461
462         case GALLERY_VIEW_EVENT_TOUCH_RELEASED:
463                 return __pGalleryViewEventHandler->OnTouchReleased(*(event.GetEventInfo()));
464
465         case GALLERY_VIEW_EVENT_TOUCH_DOUBLE_PRESSED:
466                 __galleryRenderer.SetCanvasVisibility(PARTIAL_CANVAS, false);
467                 return __pGalleryViewEventHandler->OnTouchDoublePressed(*(event.GetEventInfo()));
468
469         case GALLERY_VIEW_EVENT_TOUCH_MOVED:
470                 __galleryRenderer.SetCanvasVisibility(PARTIAL_CANVAS, false);
471                 return __pGalleryViewEventHandler->OnTouchMoved(*(event.GetEventInfo()));
472
473         case GALLERY_VIEW_EVENT_TOUCH_PINCH_ZOOM:
474                 return __pGalleryViewEventHandler->OnTouchPinchZoom(*(event.GetEventInfo()));
475
476         case GALLERY_VIEW_EVENT_TOUCH_FLICK:
477                 //__galleryRenderer.SetCanvasVisibility(PARTIAL_CANVAS, false);
478                 return __pGalleryViewEventHandler->OnTouchFlicked(*(event.GetEventInfo()));
479
480         case GALLERY_VIEW_EVENT_BOUNDS_CHANGED:
481                 return OnBoundsChanged();
482
483         default:
484                 SysTryReturn(NID_UI_CTRL, false, false, E_INVALID_ARG,
485                                         "[E_INVALID_ARG] The event type(%d) is invalid type", event.GetEventType());
486         }
487
488         //SetLastResult(E_SUCCESS);
489         return true;
490 }
491
492 bool
493 _GalleryPresenter::OnBoundsChanged(void)
494 {
495         int itemIndex = -1;
496         result r = E_SUCCESS;
497
498         r = __galleryRenderer.InitializeCanvasBounds();
499         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
500
501         if (GetItemCount() > 0)
502         {
503                 for (int canvasIndex = PARTIAL_CANVAS + 1; canvasIndex < MAX_CANVAS_COUNT; canvasIndex++)
504                 {
505                         itemIndex = __pItemToCanvas[canvasIndex];
506                         if (itemIndex != NOT_EXIST_CANVAS)
507                         {
508                                 r = __galleryRenderer.SetCanvasImage(canvasIndex, __pGalleryImageReader->GetItemImage(itemIndex)
509                                                 , __verticalAlignment, __horizontalAlignment, __fittingType);
510                                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
511                         }
512                 }
513         }
514         else
515         {
516                 r = __galleryRenderer.EnableEmptyView();
517                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
518                 SetLastResult(E_SUCCESS);
519                 return true;
520         }
521
522         int currentItemIndex = GetCurrentItemIndex();
523         int currentCanvasIndex = SearchCanvasIndex(currentItemIndex);
524         int nextItemIndex = GetCurrentItemIndex() + 1;
525         if (nextItemIndex >= GetItemCount())
526         {
527                 nextItemIndex = 0;
528         }
529         int nextCanvasIndex = SearchCanvasIndex(nextItemIndex);
530
531         r = __galleryRenderer.SetCanvasShowState(currentCanvasIndex, true);
532         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
533
534         if (__pSlideShowTimer != null && __slideShowStarted == true)
535         {
536                 r = __galleryRenderer.SetCanvasShowState(nextCanvasIndex, true);
537                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
538         }
539         else
540         {
541                 __galleryRenderer.GalleryBoundsChanged(currentCanvasIndex);
542                 Rectangle canvasBounds = __galleryRenderer.GetCanvasBounds(currentCanvasIndex);
543                 Rectangle imageBounds = __galleryRenderer.GetCanvasImageBounds(currentCanvasIndex);
544                 __pGalleryViewEventHandler->CorrectCanvasPosition(canvasBounds, imageBounds);
545                 r = __galleryRenderer.SetCanvasBounds(currentCanvasIndex, canvasBounds);
546                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
547
548                 r = __pGalleryViewEventHandler->AlignCanvas(false);
549                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
550         }
551
552         SetLastResult(E_SUCCESS);
553
554         return true;
555 }
556
557 void
558 _GalleryPresenter::OnDraw(void)
559 {
560         result r = E_SUCCESS;
561
562         if (GetItemCount() > 0 && GetCurrentItemIndex() == NO_CURRENT_IMAGE)
563         {
564                 r = SetCurrentItem(0);
565                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
566         }
567
568         r = __galleryRenderer.Draw();
569         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
570
571         SetLastResult(E_SUCCESS);
572 }
573
574 result
575 _GalleryPresenter::SetCoreEventListener(const _IGalleryCoreEventListener& coreEventListener)
576 {
577         return __pGalleryCoreEvent->AddListener(coreEventListener);
578 }
579
580 result
581 _GalleryPresenter::RemoveCoreEventListener(const _IGalleryCoreEventListener& coreEventListener)
582 {
583         return __pGalleryCoreEvent->RemoveListener(coreEventListener);
584 }
585
586 bool
587 _GalleryPresenter::ClickedItem(void)
588 {
589         _GalleryCoreEventArg* pArg = new(std::nothrow) _GalleryCoreEventArg(GALLERY_CORE_EVENT_ITEM_CLICKED, __currentItemIndex);
590         return __pGalleryCoreEvent->Fire(*pArg);
591 }
592
593 bool
594 _GalleryPresenter::ChangedItem(void)
595 {
596         if (__currentItemIndex == NO_CURRENT_IMAGE)
597         {
598                 return true;
599         }
600
601         _GalleryCoreEventArg* pArg = new(std::nothrow) _GalleryCoreEventArg(GALLERY_CORE_EVENT_CURRENT_ITEM_CHANGED, __currentItemIndex);
602         return __pGalleryCoreEvent->Fire(*pArg);
603 }
604
605 result
606 _GalleryPresenter::RequestToLoadItem(int itemIndex)
607 {
608         result r = __pGalleryModel->RequestToLoadItem(itemIndex);
609         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
610         SortItemToCanvasIndex(itemIndex, true);
611
612         if (GetItemCount() == 1)
613         {
614                 r = __galleryRenderer.DisableEmptyView();
615                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
616
617                 r = SetCurrentItem(itemIndex);
618                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
619         }
620
621         r = __galleryRenderer.RefreshView();
622         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
623
624         return E_SUCCESS;
625 }
626
627 result
628 _GalleryPresenter::RequestToUnloadItem(int itemIndex)
629 {
630         result r = __pGalleryModel->RequestToUnloadItem(itemIndex);
631         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
632
633         int canvasIndex = SearchCanvasIndex(itemIndex);
634         if (canvasIndex != NOT_EXIST_CANVAS)
635         {
636                 __galleryRenderer.SetCanvasVisibility(canvasIndex, false);
637                 __pItemToCanvas[canvasIndex] = NOT_USED_CANVAS;
638         }
639         SortItemToCanvasIndex(itemIndex, false);
640
641         if (GetItemCount() == 0)
642         {
643                 r = SetCurrentItemIndex(NO_CURRENT_IMAGE);
644                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
645
646                 r = __galleryRenderer.EnableEmptyView();
647                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
648         }
649         else
650         {
651                 if (itemIndex < GetItemCount())
652                 {
653                         r = SetCanvasImage(itemIndex);
654                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
655
656                         int canvasIndex = SearchCanvasIndex(itemIndex);
657                         SysTryReturn(NID_UI_CTRL, canvasIndex != NOT_EXIST_CANVAS, E_SYSTEM, E_SYSTEM,
658                                                         "[E_SYSTEM] Failed to search canvas");
659
660                         r = __galleryRenderer.SetCanvasVisibility(canvasIndex, true);
661                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
662                 }
663                 else
664                 {
665                         r = SetCurrentItem(itemIndex - 1);
666                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
667                 }
668         }
669
670         r = __galleryRenderer.RefreshView();
671         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
672
673         return E_SUCCESS;
674 }
675
676 result
677 _GalleryPresenter::RequestToUnloadAllItems(void)
678 {
679         result r = __pGalleryModel->RequestToUnloadAllItems();
680         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
681
682         for (int i = 0; i < MAX_CANVAS_COUNT; i++)
683         {
684                 __pItemToCanvas[i] = NOT_USED_CANVAS;
685         }
686
687         r = SetCurrentItemIndex(NO_CURRENT_IMAGE);
688         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
689
690         r = __galleryRenderer.EnableEmptyView();
691         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
692
693         //r = __galleryRenderer.RefreshView();
694         //SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
695
696         return E_SUCCESS;
697 }
698
699 result
700 _GalleryPresenter::RequestToUpdateItem(int itemIndex)
701 {
702         result r = __pGalleryModel->RequestToUpdateItem(itemIndex);
703         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
704
705         int canvasIndex = SearchCanvasIndex(itemIndex);
706         if (itemIndex == GetCurrentItemIndex())
707         {
708                 _GalleryBitmap* pImage = __pGalleryImageReader->GetItemImage(itemIndex);
709                 r = GetLastResult();
710                 SysTryReturn(NID_UI_CTRL, pImage != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
711
712                 r = __galleryRenderer.SetCanvasImage(canvasIndex, (const _GalleryBitmap*)pImage
713                                 , __verticalAlignment, __horizontalAlignment, __fittingType);
714                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
715         }
716         else if (canvasIndex != NOT_EXIST_CANVAS)
717         {
718                 __pItemToCanvas[canvasIndex] = NOT_USED_CANVAS;
719         }
720
721         r = __galleryRenderer.RefreshView();
722         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
723
724         return E_SUCCESS;
725 }
726
727 result
728 _GalleryPresenter::RequestToUpdateAllItems(void)
729 {
730         result r = __pGalleryModel->RequestToUpdateAllItems();
731         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
732
733         r = __galleryRenderer.ResetAllCanvas();
734         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
735
736         for (int i = 0; i < MAX_CANVAS_COUNT; i++)
737         {
738                 __pItemToCanvas[i] = NOT_USED_CANVAS;
739         }
740
741         int itemCount = GetItemCount();
742         if (itemCount > 0)
743         {
744                 r = __galleryRenderer.DisableEmptyView();
745                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
746
747                 if (GetCurrentItemIndex() != NO_CURRENT_IMAGE)
748                 {
749                         r = SetCanvasImage(GetCurrentItemIndex());
750                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
751
752                         r = __galleryRenderer.SetCanvasVisibility(SearchCanvasIndex(GetCurrentItemIndex()), true);
753                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
754                 }
755                 else
756                 {
757                         r = SetCurrentItem(0);
758                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
759
760                         r = __galleryRenderer.SetCanvasVisibility(SearchCanvasIndex(0), true);
761                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
762                 }
763         }
764         else
765         {
766                 r = __galleryRenderer.EnableEmptyView();
767                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
768         }
769
770         //r = __galleryRenderer.RefreshView();
771         //SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
772
773         return E_SUCCESS;
774 }
775
776 result
777 _GalleryPresenter::RequestToUpdateItemCount(void)
778 {
779         __pGalleryModel->UpdateItemCount();
780
781         return E_SUCCESS;
782 }
783
784 void
785 _GalleryPresenter::OnTimerExpired(Runtime::Timer& timer)
786 {
787         result r = E_SUCCESS;
788         if (&timer == __pSlideShowTimer)
789         {
790                 r = PlaySlideShow();
791                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
792         }
793         SetLastResult(E_SUCCESS);
794 }
795
796 void
797 _GalleryPresenter::OnTransitionCancel(void)
798 {
799         __slideShowStarted = false;
800         int endItemIndex = __currentItemIndex + 1;
801         if (GetItemCount() > 0)
802         {
803                 endItemIndex = endItemIndex % GetItemCount();
804         }
805         else
806         {
807                 endItemIndex = 0;
808         }
809
810         result r = SetCurrentItemIndex(endItemIndex);
811         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
812
813         StopSlideShowTimer();
814 }
815
816 void
817 _GalleryPresenter::OnTransitionCompleted(void)
818 {
819         __slideShowStarted = false;
820         if (__slideShowPlayCount > 0 || __slideShowRepeat == true)
821         {
822                 StartSlideShowTimer(GetSlideShowViewDuration());
823         }
824         else
825         {
826                 result r = StopSlideShow();
827                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
828         }
829
830         int endItemIndex = __currentItemIndex + 1;
831         if (GetItemCount() > 0)
832         {
833                 endItemIndex = endItemIndex % GetItemCount();
834         }
835         else
836         {
837                 endItemIndex = 0;
838         }
839
840         result r = SetCurrentItemIndex(endItemIndex);
841         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
842
843         SetLastResult(E_SUCCESS);
844 }
845
846 void
847 _GalleryPresenter::OnCanvasAnimationCancel(void)
848 {
849 }
850
851 void
852 _GalleryPresenter::OnCanvasAnimationCompleted(void)
853 {
854 }
855
856 void
857 _GalleryPresenter::OnCanvasAnimationStarted(void)
858 {
859         __slideShowStarted = true;
860 }
861
862 result
863 _GalleryPresenter::SetCanvasImage(int itemIndex)
864 {
865         SysTryReturn(NID_UI_CTRL, itemIndex >= 0, E_INVALID_ARG, E_INVALID_ARG,
866                                         "[E_INVALID_ARG] The argument(%d) is negative value.", itemIndex);
867         SysTryReturn(NID_UI_CTRL, itemIndex >=0 && itemIndex < __pGalleryModel->GetItemCount(),
868                                         E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The argument(%d) is out of range.", itemIndex);
869
870         if (SearchCanvasIndex(itemIndex) != NOT_EXIST_CANVAS)
871         {
872                 return E_SUCCESS;
873         }
874
875         int emptyCanvasIndex = GetEmptyCanvasIndex();
876         if (emptyCanvasIndex == NOT_EXIST_CANVAS)
877         {
878                 emptyCanvasIndex = ClearCanvasIndex(__currentItemIndex);
879         }
880
881         _GalleryBitmap* pImage = __pGalleryImageReader->GetItemImage(itemIndex);
882         result r = GetLastResult();
883         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
884
885         __pItemToCanvas[emptyCanvasIndex] = itemIndex;
886         r = __galleryRenderer.SetCanvasImage(emptyCanvasIndex, (const _GalleryBitmap*)pImage
887                         , __verticalAlignment, __horizontalAlignment, __fittingType);
888         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
889
890         Rectangle bounds = __galleryRenderer.GetViewRect();
891         r = __galleryRenderer.SetCanvasBounds(emptyCanvasIndex, bounds);
892         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
893
894         r = __galleryRenderer.SetCanvasVisibility(emptyCanvasIndex, false);
895         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
896
897         return E_SUCCESS;
898 }
899
900 result
901 _GalleryPresenter::SetPartialCanvasImage(void)
902 {
903         SysTryReturn(NID_UI_CTRL, __currentItemIndex >= 0, E_INVALID_ARG, E_INVALID_ARG,
904                                 "[E_INVALID_ARG] The argument(%d) is negative value.", __currentItemIndex);
905
906         if (__galleryRenderer.IsCanvasVisibility(PARTIAL_CANVAS) == true)
907         {
908                 return E_SUCCESS;
909         }
910
911         int currentCanvasIndex = SearchCanvasIndex(__currentItemIndex);
912         Rectangle canvasBounds = __galleryRenderer.GetCanvasBounds(currentCanvasIndex);
913         Rectangle imageBounds = __galleryRenderer.GetCanvasImageBounds(currentCanvasIndex);
914         Rectangle viewBounds = __galleryRenderer.GetViewRect();
915
916         if (imageBounds.width < viewBounds.width)
917         {
918                 imageBounds.x -= (viewBounds.width - imageBounds.width) / 2;
919         }
920
921         if (imageBounds.height < viewBounds.height)
922         {
923                 imageBounds.y -= (viewBounds.height - imageBounds.height) / 2;
924         }
925
926         canvasBounds.x = _Abs(-canvasBounds.x - imageBounds.x);
927         canvasBounds.y = _Abs(-canvasBounds.y - imageBounds.y);
928         canvasBounds.width = viewBounds.width < imageBounds.width ? viewBounds.width : imageBounds.width;
929         canvasBounds.height = viewBounds.height < imageBounds.height ? viewBounds.height : imageBounds.height;
930
931         //Dimension size(canvasBounds.width, canvasBounds.height);
932         Dimension size(imageBounds.width, imageBounds.height);
933
934         _GalleryBitmap* pImage = __pGalleryImageReader->GetPartialImageFromFileN(__currentItemIndex, canvasBounds, size);
935         SysTryReturn(NID_UI_CTRL, pImage != null, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
936
937         __pItemToCanvas[PARTIAL_CANVAS] = __currentItemIndex;
938         result r = __galleryRenderer.SetCanvasImage(PARTIAL_CANVAS, (const _GalleryBitmap*)pImage
939                         , GALLERY_VERTICAL_ALIGN_MIDDLE, GALLERY_HORIZONTAL_ALIGN_CENTER,  __fittingType);
940         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
941
942         r = __galleryRenderer.SetCanvasBounds(PARTIAL_CANVAS, viewBounds);
943         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
944
945         r = __galleryRenderer.SetCanvasVisibility(PARTIAL_CANVAS, true);
946         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
947
948         delete pImage;
949
950         return E_SUCCESS;
951 CATCH:
952         delete pImage;
953
954         return r;
955 }
956
957 int
958 _GalleryPresenter::SearchCanvasIndex(int itemIndex)
959 {
960         if (itemIndex == NO_CURRENT_IMAGE)
961         {
962                 return NOT_EXIST_CANVAS;
963         }
964
965         for (int i = 1; i < MAX_CANVAS_COUNT; i++)
966         {
967                 if (__pItemToCanvas[i] == itemIndex)
968                 {
969                         return i;
970                 }
971         }
972
973         return NOT_EXIST_CANVAS;
974 }
975
976 int
977 _GalleryPresenter::GetEmptyCanvasIndex(void) const
978 {
979         for (int i = 1; i < MAX_CANVAS_COUNT; i++)
980         {
981                 if (__pItemToCanvas[i] == NOT_USED_CANVAS)
982                 {
983                         return i;
984                 }
985         }
986         return NOT_EXIST_CANVAS;
987 }
988
989 result
990 _GalleryPresenter::SetCanvasIndex(int canvasIndex, int itemIndex)
991 {
992         SysTryReturn(NID_UI_CTRL, canvasIndex >= 0, E_INVALID_ARG, E_INVALID_ARG,
993                                         "[E_INVALID_ARG] The argument(%d) is negative value.", canvasIndex);
994         SysTryReturn(NID_UI_CTRL, canvasIndex > 0 && canvasIndex < MAX_CANVAS_COUNT, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
995                                         "[E_OUT_OF_RANGE] The canvas index(%d) is out of range", canvasIndex);
996         SysTryReturn(NID_UI_CTRL, itemIndex >= 0, E_INVALID_ARG, E_INVALID_ARG,
997                                         "[E_INVALID_ARG] The argument(%d) is negative value.", itemIndex);
998         SysTryReturn(NID_UI_CTRL, itemIndex >=0 && itemIndex < __pGalleryModel->GetItemCount(), E_OUT_OF_RANGE, E_OUT_OF_RANGE,
999                         "[E_OUT_OF_RANGE] The argument(%d) is out of range.", itemIndex);
1000
1001         if (__pItemToCanvas[canvasIndex] == NOT_USED_CANVAS)
1002         {
1003                 __pItemToCanvas[canvasIndex] = itemIndex;
1004         }
1005         else
1006         {
1007                 SysTryReturn(NID_UI_CTRL, false, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The canvas index(%d) is used.", canvasIndex);
1008         }
1009
1010         return E_SUCCESS;
1011 }
1012
1013 int
1014 _GalleryPresenter::ClearCanvasIndex(int currentItemIndex)
1015 {
1016         SysTryReturn(NID_UI_CTRL, currentItemIndex >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The argument(%d) is negative value.", currentItemIndex);
1017
1018         int clearCanvasIndex = 1;
1019         int maxAbsValue = 0;
1020         int absValue = 0;
1021
1022         for (int i = 1; i < MAX_CANVAS_COUNT; i++)
1023         {
1024                 absValue = _Abs(currentItemIndex - __pItemToCanvas[i]);
1025                 if (absValue > maxAbsValue)
1026                 {
1027                         maxAbsValue = absValue;
1028                         clearCanvasIndex = i;
1029                 }
1030         }
1031         __pItemToCanvas[clearCanvasIndex] = NOT_USED_CANVAS;
1032
1033         SetLastResult(E_SUCCESS);
1034         return clearCanvasIndex;
1035 }
1036
1037 void
1038 _GalleryPresenter::SortItemToCanvasIndex(int itemIndex, bool add)
1039 {
1040         if (add == true)
1041         {
1042                 for (int i = 0; i < MAX_CANVAS_COUNT; i++)
1043                 {
1044                         if (__pItemToCanvas[i] >= itemIndex)
1045                         {
1046                                 __pItemToCanvas[i]++;
1047                         }
1048                 }
1049         }
1050         else
1051         {
1052                 for (int i = 0; i < MAX_CANVAS_COUNT; i++)
1053                 {
1054                         if (__pItemToCanvas[i] > itemIndex)
1055                         {
1056                                 __pItemToCanvas[i]--;
1057                         }
1058                 }
1059         }
1060 }
1061
1062 result
1063 _GalleryPresenter::StartSlideShowTimer(int duration)
1064 {
1065         result r = E_SUCCESS;
1066         if (__pSlideShowTimer != null)
1067         {
1068                 delete __pSlideShowTimer;
1069                 __pSlideShowTimer = null;
1070         }
1071
1072         __pSlideShowTimer = new(std::nothrow) Runtime::Timer();
1073         SysTryCatch(NID_UI_CTRL, __pSlideShowTimer != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1074
1075         r = __pSlideShowTimer->Construct(*this);
1076         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1077
1078         __pSlideShowTimer->Start(duration);
1079         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1080
1081         return E_SUCCESS;
1082
1083 CATCH:
1084         delete __pSlideShowTimer;
1085         __pSlideShowTimer = null;
1086
1087         return GetLastResult();
1088 }
1089
1090 void
1091 _GalleryPresenter::StopSlideShowTimer(void)
1092 {
1093         delete __pSlideShowTimer;
1094         __pSlideShowTimer = null;
1095
1096         __slideShowRepeat = false;
1097         __slideShowPlayCount = 0;
1098 }
1099
1100 result
1101 _GalleryPresenter::PlaySlideShow(void)
1102 {
1103         int startCanvasIndex = SearchCanvasIndex(__currentItemIndex);
1104         SysTryReturn(NID_UI_CTRL, startCanvasIndex != NOT_EXIST_CANVAS, E_SYSTEM, E_SYSTEM,
1105                                 "[E_SYSTEM] The current item not exist.");
1106
1107         int endItemIndex = __currentItemIndex + 1;
1108         if (endItemIndex >= GetItemCount())
1109         {
1110                 endItemIndex = 0;
1111         }
1112
1113         result r = __galleryRenderer.SetCanvasVisibility(PARTIAL_CANVAS, false);
1114         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1115
1116         r = __galleryRenderer.SetCanvasVisibility(startCanvasIndex, true);
1117         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1118
1119         int endCanvasIndex = SearchCanvasIndex(endItemIndex);
1120         if (endCanvasIndex == NOT_EXIST_CANVAS)
1121         {
1122                 r = SetCanvasImage(endItemIndex);
1123                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1124                 endCanvasIndex = SearchCanvasIndex(endItemIndex);
1125         }
1126
1127         _GalleryTransitionType transition = static_cast<_GalleryTransitionType>(GetSlideShowType());
1128         _GalleryAnimationTiming animation = {__slideShowAnimationDuration, GALLERY_ANIMATION_TIMING_FUNC_EASEOUT};
1129         r = __galleryRenderer.SetCanvasVisibility(endCanvasIndex, true);
1130         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1131
1132         r = __galleryRenderer.RunCanvasTransition(startCanvasIndex, endCanvasIndex, transition, &animation);
1133         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1134
1135         if (__slideShowRepeat == false)
1136         {
1137                 __slideShowPlayCount--;
1138         }
1139
1140         r = __galleryRenderer.RefreshView();
1141         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1142
1143         return E_SUCCESS;
1144 }
1145
1146 // property access
1147 Variant
1148 _GalleryPresenter::GetPropertySlideShowViewDuration(void) const
1149 {
1150         return Variant(__slideShowViewDuration);
1151 }
1152
1153 result
1154 _GalleryPresenter::SetPropertySlideShowViewDuration(const Variant& variant)
1155 {
1156         __slideShowViewDuration = variant.ToInt();
1157
1158         return E_SUCCESS;
1159 }
1160
1161 Variant
1162 _GalleryPresenter::GetPropertySlideShowAnimationDuration(void) const
1163 {
1164         return Variant(__slideShowAnimationDuration);
1165 }
1166
1167 result
1168 _GalleryPresenter::SetPropertySlideShowAnimationDuration(const Variant& variant)
1169 {
1170         __slideShowAnimationDuration = variant.ToInt();
1171
1172         return E_SUCCESS;
1173 }
1174
1175 Variant
1176 _GalleryPresenter::GetPropertyTextOfEmptyGallery(void) const
1177 {
1178         return Variant(__emptyText);
1179 }
1180
1181 result
1182 _GalleryPresenter::SetPropertyTextOfEmptyGallery(const Variant& variant)
1183 {
1184         __emptyText = variant.ToString();
1185
1186         return E_SUCCESS;
1187 }
1188
1189 Variant
1190 _GalleryPresenter::GetPropertyZoomingEnabled(void) const
1191 {
1192         return Variant(__zoomingEnabled);
1193 }
1194
1195 result
1196 _GalleryPresenter::SetPropertyZoomingEnabled(const Variant& variant)
1197 {
1198         __zoomingEnabled = variant.ToBool();
1199
1200         return E_SUCCESS;
1201 }
1202
1203 void
1204 _GalleryPresenter::OnPropertyChanging(_PropertyBase& source, const String& name,
1205                                                                                                                         const Variant& oldProperty, const Variant& newProperty)
1206 {
1207 }
1208
1209 void
1210 _GalleryPresenter::OnPropertyChanged(_PropertyBase& source, const String& name,
1211                                                                                                                         const Variant& oldProperty, const Variant& newProperty)
1212 {
1213 }
1214
1215 void
1216 _GalleryPresenter::SetFontSize(int size)
1217 {
1218         __emptyFontSize = size;
1219 }
1220
1221 int
1222 _GalleryPresenter::GetFontSize(void) const
1223 {
1224         return __emptyFontSize;
1225 }
1226
1227 void
1228 _GalleryPresenter::SetFontStyle(FontStyle style)
1229 {
1230         __emptyFontStyle = style;
1231 }
1232
1233 FontStyle
1234 _GalleryPresenter::GetFontStyle(void) const
1235 {
1236         return __emptyFontStyle;
1237 }
1238
1239 void
1240 _GalleryPresenter::OnFontInfoRequested(unsigned long& style, int& size)
1241 {
1242         style = GetFontStyle();
1243         size = GetFontSize();
1244 }
1245
1246 void
1247 _GalleryPresenter::OnFontChanged(void)
1248 {
1249         if (GetItemCount() == 0)
1250         {
1251                 result r = __galleryRenderer.EnableEmptyView();
1252                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1253         }
1254 }
1255
1256 }}} // Tizen::Ui::Controls