Fixes in EditDate / EditTime w.r.t OnActivation /
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_DateTimeBarPresenter.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
18 /**
19  * @file                FUiCtrl_DateTimeBarPresenter.cpp
20  * @brief               This is the implementation file for the _DateTimeBarPresenter class.
21  */
22
23 #include <FGrp_BitmapImpl.h>
24 #include <FGrp_FontImpl.h>
25 #include <FGrp_TextTextSimple.h>
26 #include "FUi_CoordinateSystemUtils.h"
27 #include "FUi_ResourceManager.h"
28 #include "FUiCtrl_DateTimeUtils.h"
29 #include "FUiCtrl_DateTimeBar.h"
30 #include "FUiCtrl_DateTimeBarPresenter.h"
31
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Runtime;
36 using namespace Tizen::Graphics::_Text;
37
38 const int UPDATE_ITEM_COUNT = 3;
39
40 namespace Tizen { namespace Ui { namespace Controls
41 {
42
43 _DateTimeBarPresenter::_DateTimeBarPresenter(_DateTimeBar* pDateTimeBar)
44         : __pDateTimeBar(pDateTimeBar)
45         , __pDateTimeBarModel(null)
46         , __currentPoint(FloatPoint(0.0f, 0.0f))
47         , __isTouchMoved(false)
48         , __touchMoveHandled(false)
49         , __isFlickEnabled(true)
50         , __isFlickInProgress(false)
51         , __distance(0.0f)
52         , __pFlickAnimationTimer(null)
53         , __flickAnimation()
54         , __selectedText(L"")
55         , __bodyAreaBounds(FloatRectangle())
56         , __arrowAreaBounds(FloatRectangle())
57         , __windowAreaBounds(FloatRectangle())
58         , __pBgColorReplacementBitmap(null)
59         , __pArrowColorReplacementBitmap(null)
60         , __isInitialAnimation(false)
61         , __initialAnimationValue(0.0f)
62         , __pFont(null)
63 {
64 }
65
66 _DateTimeBarPresenter::~_DateTimeBarPresenter(void)
67 {
68         delete __pDateTimeBarModel;
69         __pDateTimeBarModel = 0;
70
71         delete __pBgColorReplacementBitmap;
72         __pBgColorReplacementBitmap = null;
73
74         delete __pArrowColorReplacementBitmap;
75         __pArrowColorReplacementBitmap = null;
76
77         delete __pFlickAnimationTimer;
78         __pFlickAnimationTimer = null;
79
80         delete __pFont;
81         __pFont = null;
82 }
83
84 _DateTimeBarPresenter*
85 _DateTimeBarPresenter::CreateInstanceN(_DateTimeBar& dateTimeBar)
86 {
87         result r = E_SUCCESS;
88
89         _DateTimeBarPresenter* pDateTimeBarPresenter = new (std::nothrow) _DateTimeBarPresenter(&dateTimeBar);
90         SysTryReturn(NID_UI_CTRL, pDateTimeBarPresenter, null, E_OUT_OF_MEMORY,
91                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
92
93         pDateTimeBarPresenter->__pDateTimeBarModel = _DateTimeBarModel::CreateInstanceN();
94         r = GetLastResult();
95         SysTryCatch(NID_UI_CTRL, pDateTimeBarPresenter->__pDateTimeBarModel, , r,
96                         "[%s] Propagating.", GetErrorMessage(r));
97
98         r = GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_WIDTH, dateTimeBar.GetOrientation(), pDateTimeBarPresenter->__arrowAreaBounds.width);
99         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get arrow width from resource.", GetErrorMessage(r));
100
101         r = GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, dateTimeBar.GetOrientation(), pDateTimeBarPresenter->__arrowAreaBounds.height);
102         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get arrow height from resource.", GetErrorMessage(r));
103
104         r = pDateTimeBarPresenter->LoadResource();
105         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to load the resources.", GetErrorMessage(r));
106
107         return pDateTimeBarPresenter;
108
109 CATCH:
110         delete pDateTimeBarPresenter;
111
112         return null;
113 }
114
115 void
116 _DateTimeBarPresenter::AddFlickAnimationInfo()
117 {
118         __flickAnimation.SetSensitivity(FLICK_ANIMATION_FPS_DATE_TIME_BAR, FLICK_ANIMATION_SENSITIVITY_DATE_TIME_BAR);
119         __flickAnimation.SetDirection(FD_HORIZONTAL);
120 }
121
122 result
123 _DateTimeBarPresenter::LoadResource(void)
124 {
125         result r = E_SUCCESS;
126         Color bgBitmapColor;
127         Bitmap* pBackgroundNormalBitmap = null;
128
129         r = GET_BITMAP_CONFIG_N(DATETIMEBAR::TIMEPICKERBAR_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBackgroundNormalBitmap);
130         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
131
132         GET_COLOR_CONFIG(DATETIMEBAR::BG_NORMAL, bgBitmapColor);
133         __pBgColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundNormalBitmap,
134                                                                            Color::GetColor(COLOR_ID_MAGENTA), bgBitmapColor);
135         SysTryCatch(NID_UI_CTRL, __pBgColorReplacementBitmap != null, r = GetLastResult(), GetLastResult(), "[%s] Propagating.",
136                     GetErrorMessage(GetLastResult()));
137
138         r = LoadArrowBitmap();
139         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to load resources.", GetErrorMessage(r));
140
141         delete pBackgroundNormalBitmap;
142         pBackgroundNormalBitmap = null;
143
144         AddFlickAnimationInfo();
145
146         return r;
147
148 CATCH:
149
150         delete pBackgroundNormalBitmap;
151         pBackgroundNormalBitmap = null;
152
153         delete __pBgColorReplacementBitmap;
154         __pBgColorReplacementBitmap = null;
155
156         return r;
157 }
158
159 result
160 _DateTimeBarPresenter::LoadArrowBitmap(void)
161 {
162         result r = E_SUCCESS;
163         Color arrowColor;
164         Bitmap* pArrowNormalBitmap = null;
165
166         GET_COLOR_CONFIG(DATETIMEBAR::BG_NORMAL, arrowColor);
167
168         if (__pDateTimeBar->GetAlignment() == DATETIME_BAR_ALIGN_DOWN)
169         {
170                 r = GET_BITMAP_CONFIG_N(DATETIMEBAR::TAIL_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888, pArrowNormalBitmap);
171                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
172         }
173         else
174         {
175                 r = GET_BITMAP_CONFIG_N(DATETIMEBAR::TAIL_UP, BITMAP_PIXEL_FORMAT_ARGB8888, pArrowNormalBitmap);
176                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
177         }
178
179         if (__pArrowColorReplacementBitmap != null)
180         {
181                 delete __pArrowColorReplacementBitmap;
182                 __pArrowColorReplacementBitmap = null;
183         }
184
185         __pArrowColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pArrowNormalBitmap,
186                                                                                 Color::GetColor(COLOR_ID_MAGENTA), arrowColor);
187         SysTryCatch(NID_UI_CTRL, __pArrowColorReplacementBitmap != null, r = GetLastResult(), GetLastResult(), "[%s] Propagating.",
188                         GetErrorMessage(GetLastResult()));
189
190         delete pArrowNormalBitmap;
191         pArrowNormalBitmap = null;
192
193         return r;
194
195 CATCH:
196
197         delete pArrowNormalBitmap;
198         pArrowNormalBitmap = null;
199
200         delete __pArrowColorReplacementBitmap;
201         __pArrowColorReplacementBitmap = null;
202
203         return r;
204 }
205
206 result
207 _DateTimeBarPresenter::Draw(void)
208 {
209         result r = E_SUCCESS;
210
211         Canvas* pCanvas = __pDateTimeBar->GetCanvasN();
212         SysAssertf((pCanvas != null), "Failed to get canvas.");
213
214         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
215
216         r = pCanvas->Clear();
217         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
218
219         r = DrawBackground(*pCanvas);
220         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
221
222         r = DrawItem(*pCanvas);
223         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
224
225         r = DrawArrow(*pCanvas);
226         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
227
228         delete pCanvas;
229         return r;
230
231 CATCH:
232         delete pCanvas;
233         return r;
234 }
235
236 result
237 _DateTimeBarPresenter::DrawItem(Canvas& canvas)
238 {
239         result r = E_SUCCESS;
240
241         FloatRectangle clientBounds = canvas.GetBoundsF();
242
243         _DateTimeBarItem* pDrawItem = null;
244         FloatRectangle itemBounds(0.0f, 0.0f, 0.0f, 0.0f);
245
246         String drawText;
247
248         Color textColor;
249         GET_COLOR_CONFIG(DATETIMEBAR::TEXT_NORMAL, textColor);
250
251         Color textPressedColor;
252         GET_COLOR_CONFIG(DATETIMEBAR::TEXT_PRESSED, textPressedColor);
253
254         _DateTimeBarItemStatus itemStatus = DATETIMEBAR_ITEM_STATUS_NORMAL;
255
256         int itemCount = GetItemCount();
257
258         RefreshAccessibilityElement();
259
260         for (int i = __pDateTimeBarModel->GetFirstDrawnItemIndex(); i < itemCount; i++)
261         {
262                 pDrawItem = __pDateTimeBarModel->GetItemAt(i);
263                 if (pDrawItem == null)
264                 {
265                         break;
266                 }
267
268                 itemBounds = pDrawItem->GetBounds();
269
270                 if (itemBounds.x + itemBounds.width <= 0)
271                 {
272                         continue;
273                 }
274
275                 drawText = pDrawItem->GetText();
276
277                 if (drawText.CompareTo(__selectedText) == 0)
278                 {
279                         pDrawItem->SetStatus(DATETIMEBAR_ITEM_STATUS_SELECTED);
280                 }
281
282                 itemStatus = pDrawItem->GetStatus();
283
284                 float fontSize = GetFontSize();
285
286                 TextSimple* pSimpleText = null;
287                 TextObject* pTextObject = new (std::nothrow) TextObject;
288                 SysTryReturn(NID_UI_CTRL, (pTextObject != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
289
290                 pTextObject->Construct();
291                 pSimpleText = new (std::nothrow)TextSimple((const_cast <wchar_t*>(drawText.GetPointer())), drawText.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
292                 pTextObject->AppendElement(*pSimpleText);
293
294                 pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
295                 pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_NONE);
296                 pTextObject->SetAction(TEXT_OBJECT_ACTION_TYPE_ABBREV);
297
298                 SysAssertf(__pFont != null, "Font instance is null");
299
300                 if (itemStatus == DATETIMEBAR_ITEM_STATUS_SELECTED)
301                 {
302                         (_FontImpl::GetInstance(*__pFont))->SetSize(fontSize);
303                         (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_BOLD);
304                         pTextObject->SetFont(__pFont, 0, pTextObject->GetTextLength());
305                         pTextObject->SetForegroundColor(textPressedColor, 0, pTextObject->GetTextLength());
306                 }
307                 else
308                 {
309                         (_FontImpl::GetInstance(*__pFont))->SetSize(fontSize);
310                         (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
311                         pTextObject->SetFont(__pFont, 0, pTextObject->GetTextLength());
312                         pTextObject->SetForegroundColor(textColor, 0, pTextObject->GetTextLength());
313                 }
314
315                 pTextObject->SetBounds(itemBounds);
316                 pTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
317
318                 delete pTextObject;
319
320                 if ((itemBounds.x + itemBounds.width + GetLeftRightMargin()) >= clientBounds.width)
321                 {
322                         break;
323                 }
324         }
325
326         return r;
327 }
328
329 result
330 _DateTimeBarPresenter::DrawBackground(Canvas& canvas)
331 {
332         result r = E_SUCCESS;
333
334         FloatRectangle bodyAreaBounds = GetBodyBounds();
335
336         if (__pBgColorReplacementBitmap != null)
337         {
338                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pBgColorReplacementBitmap))
339                 {
340                         r = canvas.DrawNinePatchedBitmap(bodyAreaBounds, *__pBgColorReplacementBitmap);
341                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
342                 }
343                 else
344                 {
345                         r = canvas.DrawBitmap(bodyAreaBounds, *__pBgColorReplacementBitmap);
346                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
347                 }
348         }
349
350         else
351         {
352                 r = canvas.DrawRectangle(bodyAreaBounds);
353                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
354         }
355
356         return r;
357 }
358
359 result
360 _DateTimeBarPresenter::DrawArrow(Canvas& canvas)
361 {
362         result r = E_SUCCESS;
363         FloatRectangle arrowAreaBounds = GetArrowBounds();
364
365         if (__pArrowColorReplacementBitmap != null)
366         {
367                 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(*__pArrowColorReplacementBitmap))
368                 {
369                         r = canvas.DrawNinePatchedBitmap(arrowAreaBounds, *__pArrowColorReplacementBitmap);
370                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
371                 }
372                 else
373                 {
374                         r = canvas.DrawBitmap(arrowAreaBounds, *__pArrowColorReplacementBitmap);
375                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
376                 }
377         }
378
379         return r;
380 }
381
382 void
383 _DateTimeBarPresenter::SetItemSelected(int index)
384 {
385         __pDateTimeBarModel->SetSelectedItemIndex(index);
386         return;
387 }
388
389 int
390 _DateTimeBarPresenter::GetSelectedItemIndex(void) const
391 {
392         return __pDateTimeBarModel->GetSelectedItemIndex();
393 }
394
395 int
396 _DateTimeBarPresenter::GetItemIndexFromPosition(const FloatPoint& point) const
397 {
398         FloatRectangle clientBounds = __pDateTimeBar->GetBoundsF();
399
400         if (point.x > clientBounds.width
401                 || point.y > clientBounds.height)
402         {
403                 return -1;
404         }
405
406         int itemIndex = __pDateTimeBarModel->GetFirstDrawnItemIndex();
407         _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(itemIndex);
408         float startX = 0.0f;
409
410         while (pItem != null)
411         {
412                 FloatRectangle itemBounds = pItem->GetBounds();
413
414                 if (itemBounds.x > clientBounds.x)
415                 {
416                         if (itemIndex == __pDateTimeBarModel->GetFirstDrawnItemIndex())
417                         {
418                                 startX = itemBounds.x;
419                         }
420
421                         itemBounds.x -= startX;
422                 }
423
424                 if (itemBounds.Contains(point) == true)
425                 {
426                         return itemIndex;
427                 }
428
429                 itemIndex++;
430
431                 if (itemIndex == GetItemCount())
432                 {
433                         break;
434                 }
435
436                 pItem = __pDateTimeBarModel->GetItemAt(itemIndex);
437         }
438
439         return -1;
440 }
441
442 result
443 _DateTimeBarPresenter::SetItemStatus(int index, _DateTimeBarItemStatus status)
444 {
445         _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
446         SysTryReturn(NID_UI_CTRL, pItem, E_SYSTEM, E_SYSTEM,
447                  "[E_SYSTEM] A system error has occurred. Failed to get _DateTimeBarItem at index (%d).", index);
448
449         if (status != DATETIMEBAR_ITEM_STATUS_NORMAL)
450         {
451                 __pDateTimeBarModel->SetSelectedItemIndex(index);
452         }
453         pItem->SetStatus(status);
454
455         return E_SUCCESS;
456 }
457
458 _DateTimeBarItemStatus
459 _DateTimeBarPresenter::GetItemStatus(int index) const
460 {
461         _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
462         SysTryReturn(NID_UI_CTRL, pItem, DATETIMEBAR_ITEM_STATUS_NORMAL, E_SYSTEM,
463                  "[E_SYSTEM] A system error has occurred. Failed to get _DateTimeBarItem at index (%d).", index);
464
465         return pItem->GetStatus();
466 }
467
468 int
469 _DateTimeBarPresenter::GetFirstDrawnItemIndex(void) const
470 {
471         return __pDateTimeBarModel->GetFirstDrawnItemIndex();
472 }
473
474 void
475 _DateTimeBarPresenter::SetFirstDrawnItemIndex(int index)
476 {
477         __pDateTimeBarModel->SetFirstDrawnItemIndex(index);
478         return;
479 }
480
481 int
482 _DateTimeBarPresenter::GetMinimumValue(void) const
483 {
484         return __pDateTimeBarModel->GetMinimumValue();
485 }
486
487 void
488 _DateTimeBarPresenter::SetMinimumValue(int minValue)
489 {
490         __pDateTimeBarModel->SetMinimumValue(minValue);
491         return;
492 }
493
494 int
495 _DateTimeBarPresenter::GetMaximumValue(void) const
496 {
497         return __pDateTimeBarModel->GetMaximumValue();
498 }
499
500 void
501 _DateTimeBarPresenter::SetMaximumValue(int maxValue)
502 {
503         __pDateTimeBarModel->SetMaximumValue(maxValue);
504         return;
505 }
506
507 float
508 _DateTimeBarPresenter::GetItemWidth(void) const
509 {
510         result r = E_SUCCESS;
511
512         _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
513
514         float itemWidth = 0.0f;
515
516         if (boxId == DATETIME_ID_YEAR)
517         {
518                 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
519         }
520         else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
521         {
522                 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
523         }
524         else if (boxId == DATETIME_ID_MONTH)
525         {
526                 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
527
528                 FloatDimension textArea;
529
530                 float fontSize = 0;
531                 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_FONT_SIZE, __pDateTimeBar->GetOrientation(), fontSize);
532
533                 SysAssertf(__pFont != null, "Font instance is null");
534
535                 (_FontImpl::GetInstance(*__pFont))->SetSize(fontSize);
536                 (_FontImpl::GetInstance(*__pFont))->SetStyle(FONT_STYLE_PLAIN);
537
538                 for (int i = DATETIME_MONTH_MIN; i <= DATETIME_MONTH_MAX; i++)
539                 {
540                         String string;
541                         _DateTimeUtils dateTimeUtils;
542                         string = dateTimeUtils.GetMonthString(i);
543
544                         r = __pFont->GetTextExtent(string, string.GetLength(), textArea);
545                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
546
547                         if (textArea.width > itemWidth)
548                         {
549                                 itemWidth = textArea.width;
550                         }
551                 }
552         }
553
554         return itemWidth;
555 }
556
557 float
558 _DateTimeBarPresenter::GetFontSize(void) const
559 {
560         float fontSize = 0.0f;
561         _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
562
563         if (boxId == DATETIME_ID_YEAR)
564         {
565                 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_FONT_SIZE, _ControlManager::GetInstance()->GetOrientation(), fontSize);
566         }
567         else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
568         {
569                 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_FONT_SIZE, _ControlManager::GetInstance()->GetOrientation(), fontSize);
570         }
571         else if (boxId == DATETIME_ID_MONTH)
572         {
573                 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_FONT_SIZE, _ControlManager::GetInstance()->GetOrientation(), fontSize);
574         }
575
576         return fontSize;
577 }
578
579 float
580 _DateTimeBarPresenter::GetLeftRightMargin(void) const
581 {
582         float leftRightMargin = 0.0f;
583         _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
584
585         if (boxId == DATETIME_ID_YEAR)
586         {
587                 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_LEFT_RIGHT_MARGIN, _ControlManager::GetInstance()->GetOrientation(), leftRightMargin);
588         }
589         else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
590         {
591                 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_LEFT_RIGHT_MARGIN, _ControlManager::GetInstance()->GetOrientation(), leftRightMargin);
592         }
593         else if (boxId == DATETIME_ID_MONTH)
594         {
595                 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_LEFT_RIGHT_MARGIN, _ControlManager::GetInstance()->GetOrientation(), leftRightMargin);
596         }
597
598         return leftRightMargin;
599 }
600
601 float
602 _DateTimeBarPresenter::GetItemMargin(void) const
603 {
604         float margin = 0.0f;
605         _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
606
607         if (boxId == DATETIME_ID_YEAR)
608         {
609                 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_ITEM_MARGIN, _ControlManager::GetInstance()->GetOrientation(), margin);
610         }
611         else if (boxId == DATETIME_ID_DAY || boxId == DATETIME_ID_HOUR || boxId == DATETIME_ID_MINUTE)
612         {
613                 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_ITEM_MARGIN, _ControlManager::GetInstance()->GetOrientation(), margin);
614         }
615         else if (boxId == DATETIME_ID_MONTH)
616         {
617                 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_ITEM_MARGIN, _ControlManager::GetInstance()->GetOrientation(), margin);
618         }
619
620         return margin;
621 }
622
623 result
624 _DateTimeBarPresenter::AdjustItemPosition(float distance)
625 {
626         int index = 0;
627
628         _DateTimeBarItem* pItem = null;
629         pItem = __pDateTimeBarModel->GetItemAt(index);
630
631         while (pItem != null)
632         {
633                 FloatRectangle bounds = pItem->GetBounds();
634                 bounds.x += distance;
635                 pItem->SetBounds(bounds);
636                 index++;
637
638                 if (index == GetItemCount())
639                 {
640                         break;
641                 }
642
643                 pItem = __pDateTimeBarModel->GetItemAt(index);
644         }
645
646         return E_SUCCESS;
647 }
648
649 String
650 _DateTimeBarPresenter::GetDisplayedText(int value) const
651 {
652         String string;
653
654         if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_MONTH)
655         {
656                 String monthString;
657                 _DateTimeUtils dateTimeUtils;
658                 monthString = dateTimeUtils.GetMonthString(value);
659                 string.Append(monthString);
660         }
661         else if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_YEAR)
662         {
663                 string.Format(10, L"%04d", value);
664         }
665         else
666         {
667                 string.Format(10, L"%02d", value);
668         }
669
670         return string;
671 }
672
673 result
674 _DateTimeBarPresenter::AddItems(int actionId)
675 {
676         result r = E_SUCCESS;
677         int cachingSize = __pDateTimeBarModel->GetMaxCachingSize() / 2;
678
679         int firstDrawItemIndex = cachingSize;
680
681         int value = actionId;
682         float startPosition = 0.0f;
683         float itemWidth = GetItemWidth();
684         float itemMargin = GetItemMargin();
685
686         startPosition = (GetWindowBounds().width) / 2.0f;
687         startPosition = startPosition + (itemWidth / 2.0f) + itemMargin;
688         __pDateTimeBarModel->SetItemStartPosition(startPosition);
689
690         while (cachingSize > 0)
691         {
692                 String string;
693
694                 string = GetDisplayedText(value);
695
696                 r = __pDateTimeBarModel->AddItem(string, value, __pDateTimeBar->GetAlignment(), itemWidth, itemMargin);
697                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
698
699                 cachingSize--;
700
701                 value++;
702
703                 if (__pDateTimeBarModel->GetMaximumValue() < value)
704                 {
705                         value = __pDateTimeBarModel->GetMinimumValue();
706                 }
707         }
708
709         r = InsertItems(actionId -1);
710         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
711
712         _DateTimeBarItem* pItem = null;
713         pItem = GetItemAt(firstDrawItemIndex);
714
715         if (pItem != null)
716         {
717                 __selectedText.Clear();
718                 __selectedText.Append(pItem->GetText().GetPointer());
719         }
720
721         SetItemStatus(firstDrawItemIndex, DATETIMEBAR_ITEM_STATUS_SELECTED);
722
723         return r;
724 }
725
726 result
727 _DateTimeBarPresenter::InsertItems(int actionId)
728 {
729         result r = E_SUCCESS;
730
731         int cachingSize = __pDateTimeBarModel->GetMaxCachingSize() / 2;
732
733         int value = actionId;
734         float itemWidth = GetItemWidth();
735         float itemMargin = GetItemMargin();
736
737         while (cachingSize > 0)
738         {
739                 String string;
740
741                 if (value < __pDateTimeBarModel->GetMinimumValue())
742                 {
743                         value = __pDateTimeBarModel->GetMaximumValue();
744                 }
745
746                 string = GetDisplayedText(value);
747                 r = __pDateTimeBarModel->InsertItemAt(0, string, value, __pDateTimeBar->GetAlignment(), itemWidth, itemMargin);
748                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
749
750                 cachingSize--;
751
752                 value--;
753         }
754
755         return r;
756 }
757
758 result
759 _DateTimeBarPresenter::InsertItem(int index, int actionId)
760 {
761         result r = E_SUCCESS;
762
763         String string;
764
765         string = GetDisplayedText(actionId);
766
767         r = __pDateTimeBarModel->InsertItemAt(index, string, actionId, __pDateTimeBar->GetAlignment(), GetItemWidth(), GetItemMargin());
768         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
769
770         return r;
771 }
772
773 result
774 _DateTimeBarPresenter::AddItem(int actionId)
775 {
776         result r = E_SUCCESS;
777
778         String string;
779
780         string = GetDisplayedText(actionId);
781
782         r = __pDateTimeBarModel->AddItem(string, actionId, __pDateTimeBar->GetAlignment(), GetItemWidth(), GetItemMargin());
783         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
784
785         return r;
786 }
787
788 result
789 _DateTimeBarPresenter::DeleteItem(int index)
790 {
791         int itemCount = GetItemCount();
792
793         SysTryReturn(NID_UI_CTRL, itemCount > 0, E_INVALID_ARG, E_INVALID_ARG,
794                         "[E_INVALID_ARG] Invalid argument is used. index = %d", index);
795
796         SysTryReturn(NID_UI_CTRL, index < itemCount, E_INVALID_ARG, E_INVALID_ARG,
797                         "[E_INVALID_ARG] Invalid argument is used. index = %d", index);
798
799         SysTryReturn(NID_UI_CTRL, index >= 0, E_INVALID_ARG, E_INVALID_ARG,
800                         "[E_INVALID_ARG] Invalid argument is used. index = %d", index);
801
802         result r = E_SUCCESS;
803
804         r = __pDateTimeBarModel->RemoveItemAt(index);
805         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
806
807         return r;
808 }
809
810 result
811 _DateTimeBarPresenter::RemoveAllItems(void)
812 {
813         SysTryReturn(NID_UI_CTRL, GetItemCount() > 0, E_INVALID_OPERATION, E_INVALID_OPERATION,
814                                 "[E_INVALID_OPERATION] Items count is zero.");
815
816         result r = E_SUCCESS;
817
818         __pDateTimeBarModel->RemoveAllItems();
819
820         return r;
821 }
822
823 int
824 _DateTimeBarPresenter::GetItemCount(void) const
825 {
826         return __pDateTimeBarModel->GetItemCount();
827 }
828
829 _DateTimeBarItem*
830 _DateTimeBarPresenter::GetItemAt(int index) const
831 {
832         return __pDateTimeBarModel->GetItemAt(index);
833 }
834
835 result
836 _DateTimeBarPresenter::CalculateWindowBounds(void)
837 {
838         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
839         FloatRectangle windowAreaBounds = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
840         FloatRectangle bodyAreaBounds = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
841         FloatRectangle arrowAreaBounds = FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f);
842
843         FloatRectangle parentWindowBounds = __pDateTimeBar->GetParentWindowBounds();
844
845         arrowAreaBounds = GetArrowBounds();
846
847         Point arrowPosition;
848
849         GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, orientation, arrowAreaBounds.height);
850         GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_WIDTH, orientation, arrowAreaBounds.width);
851         GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, orientation, bodyAreaBounds.height);
852
853         bodyAreaBounds.width = parentWindowBounds.width;
854
855         bodyAreaBounds.x = 0.0f;
856         FloatPoint tempPoint = __pDateTimeBar->GetPositionF();
857         windowAreaBounds.x = tempPoint.x;
858
859         if (__pDateTimeBar->GetAlignment() == DATETIME_BAR_ALIGN_DOWN)
860         {
861                 bodyAreaBounds.y = arrowAreaBounds.height;
862                 arrowAreaBounds.y = 0.0f;
863                 windowAreaBounds.y = tempPoint.y - arrowAreaBounds.height;
864         }
865         else
866         {
867                 arrowAreaBounds.y = bodyAreaBounds.height;
868                 bodyAreaBounds.y = 0.0f;
869                 windowAreaBounds.y = tempPoint.y;
870         }
871
872         windowAreaBounds.width = bodyAreaBounds.width;
873         windowAreaBounds.height = bodyAreaBounds.height + arrowAreaBounds.height;
874
875         SetBodyBounds(bodyAreaBounds);
876         SetArrowBounds(arrowAreaBounds);
877         SetWindowBounds(windowAreaBounds);
878         __pDateTimeBar->SetMovable(true);
879         __pDateTimeBar->SetResizable(true);
880         __pDateTimeBar->SetBounds(windowAreaBounds);
881         __pDateTimeBar->SetMovable(false);
882         __pDateTimeBar->SetResizable(false);
883
884         return E_SUCCESS;
885 }
886
887 void
888 _DateTimeBarPresenter::SetBodyBounds(const FloatRectangle& bounds)
889 {
890         __bodyAreaBounds = bounds;
891         return;
892 }
893
894 FloatRectangle
895 _DateTimeBarPresenter::GetBodyBounds(void) const
896 {
897         return __bodyAreaBounds;
898 }
899
900 void
901 _DateTimeBarPresenter::SetArrowBounds(const FloatRectangle& bounds)
902 {
903         __arrowAreaBounds = bounds;
904         return;
905 }
906
907 FloatRectangle
908 _DateTimeBarPresenter::GetArrowBounds(void) const
909 {
910         return __arrowAreaBounds;
911 }
912
913 void
914 _DateTimeBarPresenter::SetWindowBounds(const FloatRectangle& bounds)
915 {
916         __windowAreaBounds = bounds;
917         return;
918 }
919
920 FloatRectangle
921 _DateTimeBarPresenter::GetWindowBounds(void) const
922 {
923         return __windowAreaBounds;
924 }
925
926 bool
927 _DateTimeBarPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
928 {
929         if (&source != __pDateTimeBar)
930         {
931                 return false;
932         }
933
934         __isFlickEnabled = true;
935
936         if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false)
937         {
938                 __isFlickEnabled = false;
939                 return true;
940         }
941
942         if (__isFlickInProgress)
943         {
944                 ResetFlickAnimationTimer();
945         }
946
947         __touchMoveHandled = false;
948
949         __currentPoint = touchinfo.GetCurrentPosition();
950
951         int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
952
953         if (index == -1)
954         {
955                 return true;
956         }
957
958         __pDateTimeBar->Invalidate();
959
960         return true;
961 }
962
963 bool
964 _DateTimeBarPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
965 {
966         if (&source != __pDateTimeBar)
967         {
968                 return false;
969         }
970
971         if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false && !__isFlickInProgress && !__isTouchMoved)
972         {
973                 __isTouchMoved = false;
974                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
975                 __pDateTimeBar->SetVisibleState(false);
976                 __pDateTimeBar->Close();
977                 ResetFlickAnimationTimer();
978                 return true;
979         }
980
981         int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
982         bool isEventFire = true;
983
984         if (index != -1 && __isTouchMoved == false && __isFlickInProgress == false)
985         {
986                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
987                 SetItemStatus(index, DATETIMEBAR_ITEM_STATUS_SELECTED);
988                 __pDateTimeBarModel->SetFirstDrawnItemIndex(index);
989         }
990         else
991         {
992                 isEventFire = false;
993         }
994
995         __isTouchMoved = false;
996         __distance = 0.0f;
997
998         __pDateTimeBar->Invalidate();
999
1000         if (isEventFire == true)
1001         {
1002                 int index = GetFirstDrawnItemIndex();
1003
1004                 _DateTimeBarItem* pItem = null;
1005
1006                 if (index >= 0)
1007                 {
1008                         pItem = GetItemAt(index);
1009                 }
1010
1011                 if (pItem != null)
1012                 {
1013                         __pDateTimeBar->SetVisibleState(false);
1014                         __pDateTimeBar->Close();
1015
1016                         __pDateTimeBar->FireActionEvent(pItem->GetActionId());
1017
1018                         if (__pDateTimeBar->GetSelectedBoxId() >= DATETIME_ID_YEAR && __pDateTimeBar->GetSelectedBoxId() <= DATETIME_ID_DAY)
1019                         {
1020                                 __pDateTimeBar->FireDateTimeChangeEvent(DATE_INTERNAL_CHANGE_SAVED);
1021                         }
1022                         else if (__pDateTimeBar->GetSelectedBoxId() >= DATETIME_ID_HOUR && __pDateTimeBar->GetSelectedBoxId() <= DATETIME_ID_MINUTE)
1023                         {
1024                                 __pDateTimeBar->FireDateTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1025                         }
1026                 }
1027         }
1028
1029         return true;
1030 }
1031
1032 bool
1033 _DateTimeBarPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1034 {
1035         if (&source != __pDateTimeBar)
1036         {
1037                 return false;
1038         }
1039
1040         if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false || __touchMoveHandled == true)
1041         {
1042                 return true;
1043         }
1044
1045         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1046
1047         __isTouchMoved = true;
1048
1049         FloatDimension screen(0.0f, 0.0f);
1050         GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, orientation, screen);
1051
1052         const float _BOUNDARY_X_POSITION = screen.width * 2.0f;
1053         float distance = touchinfo.GetCurrentPosition().x - __currentPoint.x;
1054
1055         _DateTimeBarItem* pItem = null;
1056
1057         FloatRectangle itemBounds;
1058
1059         bool needItem = false;
1060         int updateItemCount = 1;
1061
1062         if (distance > 0.0f)
1063         {
1064                 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1065
1066                 if (pItem == null)
1067                 {
1068                         return true;
1069                 }
1070
1071                 itemBounds = pItem->GetBounds();
1072
1073                 __distance += distance;
1074
1075                 if (__distance > itemBounds.width / 2.0f)
1076                 {
1077                         needItem = true;
1078                         if (__distance > itemBounds.width)
1079                         {
1080                                 updateItemCount = UPDATE_ITEM_COUNT;
1081                         }
1082                 }
1083                 if (needItem == true)
1084                 {
1085                         while (updateItemCount > 0)
1086                         {
1087                                 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1088                                 if (pItem == null)
1089                                 {
1090                                         break;
1091                                 }
1092
1093                                 int actionId = pItem->GetActionId() - 1;
1094
1095                                 if (__pDateTimeBarModel->GetMinimumValue() > actionId)
1096                                 {
1097                                         actionId = __pDateTimeBarModel->GetMaximumValue();
1098                                 }
1099
1100                                 if (pItem->GetBounds().x > _BOUNDARY_X_POSITION * -1.0f)
1101                                 {
1102                                         if (InsertItem(0, actionId) == E_SUCCESS)
1103                                         {
1104                                                 SetFirstDrawnItemIndex(0);
1105                                         }
1106                                 }
1107
1108                                 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1109                                 {
1110                                         DeleteItem(GetItemCount() - 1);
1111                                 }
1112
1113                                 updateItemCount--;
1114                         }
1115                         __distance = 0.0f;
1116                 }
1117         }
1118         else
1119         {
1120                 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1121                 if (pItem == null)
1122                 {
1123                         return true;
1124                 }
1125
1126                 itemBounds = pItem->GetBounds();
1127
1128                 __distance += distance;
1129
1130                 if (__distance * -1.0f > itemBounds.width / 2.0f)
1131                 {
1132                         needItem = true;
1133                         if (__distance * -1.0f > itemBounds.width)
1134                         {
1135                                 updateItemCount = UPDATE_ITEM_COUNT;
1136                         }
1137                         __distance = 0.0f;
1138                 }
1139
1140                 if (needItem == true)
1141                 {
1142                         while (updateItemCount > 0)
1143                         {
1144                                 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1145                                 if (pItem == null)
1146                                 {
1147                                         break;
1148                                 }
1149
1150                                 int actionId = pItem->GetActionId() + 1;
1151
1152                                 if (__pDateTimeBarModel->GetMaximumValue() < actionId)
1153                                 {
1154                                         actionId = __pDateTimeBarModel->GetMinimumValue();
1155                                 }
1156
1157                                 if (pItem->GetBounds().x < _BOUNDARY_X_POSITION)
1158                                 {
1159                                         AddItem(actionId);
1160                                 }
1161
1162                                 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1163                                 {
1164                                         DeleteItem(0);
1165                                         SetFirstDrawnItemIndex(0);
1166                                 }
1167                                 updateItemCount--;
1168                         }
1169                 }
1170         }
1171
1172         __currentPoint = touchinfo.GetCurrentPosition();
1173
1174         AdjustItemPosition(distance);
1175
1176         __pDateTimeBar->Invalidate();
1177
1178         return true;
1179 }
1180
1181 bool
1182 _DateTimeBarPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1183 {
1184         if (&source != __pDateTimeBar)
1185         {
1186                 return false;
1187         }
1188
1189         __isTouchMoved = false;
1190         __distance = 0.0f;
1191
1192         __pDateTimeBar->Invalidate();
1193
1194         return true;
1195 }
1196
1197 result
1198 _DateTimeBarPresenter::LoadItems()
1199 {
1200         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1201
1202         FloatDimension screen(0.0f, 0.0f);
1203         GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, orientation, screen);
1204
1205         const float _BOUNDARY_X_POSITION = screen.width * 2.0f;
1206
1207         _DateTimeBarItem* pItem = null;
1208
1209         Rectangle itemBounds;
1210
1211         int updateItemCount = UPDATE_ITEM_COUNT;
1212
1213         if (__distance > 0.0f)
1214         {
1215                 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1216
1217                 if (pItem == null)
1218                 {
1219                         return true;
1220                 }
1221
1222
1223                 while (updateItemCount > 0)
1224                 {
1225                         pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1226                         if (pItem == null)
1227                         {
1228                                 break;
1229                         }
1230
1231                         int actionId = pItem->GetActionId() - 1;
1232
1233                         if (__pDateTimeBarModel->GetMinimumValue() > actionId)
1234                         {
1235                                 actionId = __pDateTimeBarModel->GetMaximumValue();
1236                         }
1237
1238                         if (pItem->GetBounds().x > _BOUNDARY_X_POSITION * -1)
1239                         {
1240                                 if (InsertItem(0, actionId) == E_SUCCESS)
1241                                 {
1242                                         SetFirstDrawnItemIndex(0);
1243                                 }
1244                         }
1245
1246                         if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1247                         {
1248                                 DeleteItem(GetItemCount() - 1);
1249                         }
1250                         updateItemCount--;
1251                 }
1252
1253         }
1254         else
1255         {
1256                 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1257                 if (pItem == null)
1258                 {
1259                         return true;
1260                 }
1261
1262
1263                 while (updateItemCount > 0)
1264                 {
1265                         pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1266                         if (pItem == null)
1267                         {
1268                                 break;
1269                         }
1270
1271                         int actionId = pItem->GetActionId() + 1;
1272
1273                         if (__pDateTimeBarModel->GetMaximumValue() < actionId)
1274                         {
1275                                 actionId = __pDateTimeBarModel->GetMinimumValue();
1276                         }
1277
1278                         if (pItem->GetBounds().x < _BOUNDARY_X_POSITION)
1279                         {
1280                                 AddItem(actionId);
1281                         }
1282
1283                         if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1284                         {
1285                                 DeleteItem(0);
1286                                 SetFirstDrawnItemIndex(0);
1287                         }
1288                         updateItemCount--;
1289                 }
1290         }
1291
1292         return true;
1293 }
1294
1295 bool
1296 _DateTimeBarPresenter::OnFlickGestureDetected(int distanceX,int distanceY,int duration)
1297 {
1298         if (!__isFlickEnabled)
1299         {
1300                 return false;
1301         }
1302
1303         __isFlickInProgress = true;
1304         __isInitialAnimation = false;
1305
1306         int velX = 0;
1307         int velY = 0;
1308
1309         __flickAnimation.CalculateInitializeVelocity(distanceX, 0, duration, &velX, &velY);
1310         __flickAnimation.InitializeFlickAmount(velX);
1311
1312         StartFlickAnimationTimer();
1313         return true;
1314 }
1315
1316 void
1317 _DateTimeBarPresenter::StartFlickAnimation(void)
1318 {
1319         int moveX = 0;
1320         int moveY = 0;
1321
1322         __flickAnimation.CalculateNextMove(&moveX, &moveY);
1323
1324         __distance = _CoordinateSystemUtils::ConvertToFloat(moveX);
1325         if (moveX != 0)
1326         {
1327                 StartFlickAnimationTimer();
1328         }
1329
1330         LoadItems();
1331         AdjustItemPosition(__distance);
1332         Draw();
1333         return;
1334 }
1335
1336 void
1337 _DateTimeBarPresenter::StartAnimationEffect(void)
1338 {
1339         __isInitialAnimation = true;
1340         __distance = -10.0f;
1341
1342         if (__initialAnimationValue >= 0.0f )
1343         {
1344                 __initialAnimationValue = __initialAnimationValue + __distance;
1345                 StartFlickAnimationTimer();
1346
1347                 LoadItems();
1348                 AdjustItemPosition(__distance);
1349                 Draw();
1350         }
1351         else
1352         {
1353                 __initialAnimationValue = 0.0f;
1354                 __isInitialAnimation = false;
1355                 ResetFlickAnimationTimer();
1356                 ValidateAndAdjustStartPosition();
1357         }
1358
1359         return;
1360 }
1361
1362 result
1363 _DateTimeBarPresenter::StartFlickAnimationTimer(void)
1364 {
1365         result r = E_SUCCESS;
1366
1367         if (__pFlickAnimationTimer == null)
1368         {
1369                 __pFlickAnimationTimer = new (std::nothrow) Timer;
1370                 SysTryReturn(NID_UI_CTRL, (__pFlickAnimationTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create timer.");
1371
1372                 r = __pFlickAnimationTimer->Construct(*this);
1373                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1374         }
1375         else
1376         {
1377                 __pFlickAnimationTimer->Cancel();
1378         }
1379
1380         r = __pFlickAnimationTimer->Start(FLICK_ANIMATION_TIMER_PERIOD);
1381         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1382
1383         return r;
1384
1385 CATCH:
1386         ResetFlickAnimationTimer();
1387         return r;
1388 }
1389
1390 result
1391 _DateTimeBarPresenter::ResetFlickAnimationTimer(void)
1392 {
1393         if (__pFlickAnimationTimer)
1394         {
1395                 delete __pFlickAnimationTimer;
1396                 __pFlickAnimationTimer = null;
1397         }
1398
1399         __isFlickInProgress = false;
1400         return E_SUCCESS;
1401 }
1402
1403 void
1404 _DateTimeBarPresenter::OnTimerExpired(Timer& timer)
1405 {
1406         __isFlickInProgress = false;
1407         if (&timer == __pFlickAnimationTimer)
1408         {
1409                 if (__isInitialAnimation)
1410                 {
1411                         StartAnimationEffect();
1412                 }
1413                 else
1414                 {
1415                         StartFlickAnimation();
1416                 }
1417         }
1418         return;
1419 }
1420
1421 void
1422 _DateTimeBarPresenter::ValidateAndAdjustStartPosition(void)
1423 {
1424         int index = -1;
1425         float adjustPosition = 0.0f;
1426         float leftMargin =  GetLeftRightMargin();
1427         FloatRectangle bodyBounds = GetBodyBounds();
1428
1429         index = GetItemIndexFromPosition(FloatPoint(GetLeftRightMargin() + GetItemMargin(), bodyBounds.y + (bodyBounds.height / 2.0f)));
1430
1431         if (index == -1)
1432         {
1433                 return;
1434         }
1435
1436         _DateTimeBarItem* pDrawItem = null;
1437         pDrawItem = __pDateTimeBarModel->GetItemAt(index);
1438
1439         if (pDrawItem == null)
1440         {
1441                 return;
1442         }
1443
1444         if (pDrawItem->GetBounds().x > 0.0f && pDrawItem->GetBounds().x < leftMargin)
1445         {
1446                 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1447         }
1448         else if (pDrawItem->GetBounds().x < 0.0f)
1449         {
1450                 pDrawItem = __pDateTimeBarModel->GetItemAt(index + 1);
1451                 if (pDrawItem == null)
1452                 {
1453                         return;
1454                 }
1455                 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1456         }
1457         else if (pDrawItem->GetBounds().x > leftMargin)
1458         {
1459                 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1460         }
1461
1462         AdjustItemPosition(adjustPosition);
1463         Draw();
1464         return;
1465 }
1466
1467 void
1468 _DateTimeBarPresenter::SetInitialAnimationValue(float animationValue)
1469 {
1470         __initialAnimationValue = animationValue;
1471         return;
1472 }
1473
1474 void
1475 _DateTimeBarPresenter::SetFont(Font& pFont)
1476 {
1477         delete __pFont;
1478         __pFont = null;
1479
1480         __pFont = _FontImpl::CloneN(pFont);
1481         SysTryReturnVoidResult(NID_UI_CTRL, (__pFont != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1482
1483         return;
1484 }
1485
1486 bool
1487 _DateTimeBarPresenter::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1488 {
1489         __distance = (GetItemWidth() + GetItemMargin()) * (-1.0f);
1490
1491         if (element.GetBounds().x + element.GetBounds().width > GetWindowBounds().width)
1492         {
1493                 AdjustItemPosition(__distance);
1494                 Draw();
1495         }
1496         return true;
1497 }
1498
1499 bool
1500 _DateTimeBarPresenter::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1501 {
1502         __distance = (GetItemWidth() + GetItemMargin());
1503
1504         if (element.GetBounds().x < GetWindowBounds().x)
1505         {
1506                 AdjustItemPosition(__distance);
1507                 Draw();
1508         }
1509         return true;
1510 }
1511
1512 void
1513 _DateTimeBarPresenter::OnTouchMoveHandled(const Tizen::Ui::_Control& control)
1514 {
1515         __touchMoveHandled = true;
1516
1517         __isTouchMoved = false;
1518         __distance = 0.0f;
1519
1520         __pDateTimeBar->Invalidate();
1521
1522         return;
1523 }
1524
1525 void
1526 _DateTimeBarPresenter::RefreshAccessibilityElement(void)
1527 {
1528         __pDateTimeBar->RemoveAllAccessibilityElement();
1529
1530         for (int index = 0; index < __pDateTimeBarModel->GetItemCount(); index++)
1531         {
1532                 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
1533
1534                 if (pItem != null)
1535                 {
1536                         if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_MONTH)
1537                         {
1538                                 __pDateTimeBar->AddAccessibilityElement(pItem->GetBounds(), __pDateTimeBar->GetMonthValue(pItem->GetActionId()));
1539                         }
1540                         else
1541                         {
1542                                 __pDateTimeBar->AddAccessibilityElement(pItem->GetBounds(), pItem->GetText());
1543                         }
1544                 }
1545         }
1546
1547         return;
1548 }
1549
1550 }}} // Tizen::Ui::Controls