Tizen 2.1 base
[framework/osp/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_ResourceManager.h"
27 #include "FUiCtrl_DateTimeUtils.h"
28 #include "FUiCtrl_DateTimeBar.h"
29 #include "FUiCtrl_DateTimeBarPresenter.h"
30
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Runtime;
35 using namespace Tizen::Graphics::_Text;
36
37 const int UPDATE_ITEM_COUNT = 3;
38
39 namespace Tizen { namespace Ui { namespace Controls
40 {
41
42 _DateTimeBarPresenter::_DateTimeBarPresenter(_DateTimeBar* pDateTimeBar)
43         : __pDateTimeBar(pDateTimeBar)
44         , __pDateTimeBarModel(null)
45         , __currentPoint(Point(0, 0))
46         , __isTouchMoved(false)
47         , __touchMoveHandled(false)
48         , __distance(0)
49         , __pFlickAnimationTimer(null)
50         , __flickAnimation()
51         , __selectedText(L"")
52         , __bodyAreaBounds(Rectangle())
53         , __arrowAreaBounds(Rectangle())
54         , __windowAreaBounds(Rectangle())
55         , __pBgColorReplacementBitmap(null)
56         , __pArrowColorReplacementBitmap(null)
57         , __isInitialAnimation(false)
58         , __initialAnimationValue(0)
59         , __pFont(null)
60 {
61 }
62
63 _DateTimeBarPresenter::~_DateTimeBarPresenter(void)
64 {
65         delete __pDateTimeBarModel;
66         __pDateTimeBarModel = 0;
67
68         delete __pBgColorReplacementBitmap;
69         __pBgColorReplacementBitmap = null;
70
71         delete __pArrowColorReplacementBitmap;
72         __pArrowColorReplacementBitmap = null;
73
74         delete __pFlickAnimationTimer;
75         __pFlickAnimationTimer = null;
76
77         delete __pFont;
78         __pFont = null;
79 }
80
81 _DateTimeBarPresenter*
82 _DateTimeBarPresenter::CreateInstanceN(_DateTimeBar& dateTimeBar)
83 {
84         result r = E_SUCCESS;
85
86         _DateTimeBarPresenter* pDateTimeBarPresenter = new (std::nothrow) _DateTimeBarPresenter(&dateTimeBar);
87         SysTryReturn(NID_UI_CTRL, pDateTimeBarPresenter, null, E_OUT_OF_MEMORY,
88                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
89
90         pDateTimeBarPresenter->__pDateTimeBarModel = _DateTimeBarModel::CreateInstanceN();
91         r = GetLastResult();
92         SysTryCatch(NID_UI_CTRL, pDateTimeBarPresenter->__pDateTimeBarModel, , r,
93                         "[%s] Propagating.", GetErrorMessage(r));
94
95         r = GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_WIDTH, dateTimeBar.GetOrientation(), pDateTimeBarPresenter->__arrowAreaBounds.width);
96         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get arrow width from resource.", GetErrorMessage(r));
97
98         r = GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, dateTimeBar.GetOrientation(), pDateTimeBarPresenter->__arrowAreaBounds.height);
99         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get arrow height from resource.", GetErrorMessage(r));
100
101         r = pDateTimeBarPresenter->LoadResource();
102         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to load the resources.", GetErrorMessage(r));
103
104         return pDateTimeBarPresenter;
105
106 CATCH:
107         delete pDateTimeBarPresenter;
108
109         return null;
110 }
111
112 void
113 _DateTimeBarPresenter::AddFlickAnimationInfo()
114 {
115         __flickAnimation.SetSensitivity(FLICK_ANIMATION_FPS_DATE_TIME_BAR, FLICK_ANIMATION_SENSITIVITY_DATE_TIME_BAR);
116         __flickAnimation.SetDirection(FD_HORIZONTAL);
117 }
118
119 result
120 _DateTimeBarPresenter::LoadResource(void)
121 {
122         result r = E_SUCCESS;
123         Color bgBitmapColor;
124         Bitmap* pBackgroundNormalBitmap = null;
125
126         r = GET_BITMAP_CONFIG_N(DATETIMEBAR::TIMEPICKERBAR_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pBackgroundNormalBitmap);
127         SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
128
129         GET_COLOR_CONFIG(DATETIMEBAR::BG_NORMAL, bgBitmapColor);
130         __pBgColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pBackgroundNormalBitmap,
131                                                                            Color::GetColor(COLOR_ID_MAGENTA), bgBitmapColor);
132         SysTryCatch(NID_UI_CTRL, __pBgColorReplacementBitmap != null, r = GetLastResult(), GetLastResult(), "[%s] Propagating.",
133                     GetErrorMessage(GetLastResult()));
134
135         r = LoadArrowBitmap();
136         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to load resources.", GetErrorMessage(r));
137
138         delete pBackgroundNormalBitmap;
139         pBackgroundNormalBitmap = null;
140
141         AddFlickAnimationInfo();
142
143         return r;
144
145 CATCH:
146
147         delete pBackgroundNormalBitmap;
148         pBackgroundNormalBitmap = null;
149
150         delete __pBgColorReplacementBitmap;
151         __pBgColorReplacementBitmap = null;
152
153         return r;
154 }
155
156 result
157 _DateTimeBarPresenter::LoadArrowBitmap(void)
158 {
159         result r = E_SUCCESS;
160         Color arrowColor;
161         Bitmap* pArrowNormalBitmap = null;
162
163         GET_COLOR_CONFIG(DATETIMEBAR::BG_NORMAL, arrowColor);
164
165         if (__pDateTimeBar->GetAlignment() == DATETIME_BAR_ALIGN_DOWN)
166         {
167                 r = GET_BITMAP_CONFIG_N(DATETIMEBAR::TAIL_DOWN, BITMAP_PIXEL_FORMAT_ARGB8888, pArrowNormalBitmap);
168                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
169         }
170         else
171         {
172                 r = GET_BITMAP_CONFIG_N(DATETIMEBAR::TAIL_UP, BITMAP_PIXEL_FORMAT_ARGB8888, pArrowNormalBitmap);
173                 SysTryReturn(NID_UI_CTRL, (r == E_SUCCESS), r, r, "[%s] Propagating.", GetErrorMessage(r));
174         }
175
176         if (__pArrowColorReplacementBitmap != null)
177         {
178                 delete __pArrowColorReplacementBitmap;
179                 __pArrowColorReplacementBitmap = null;
180         }
181
182         __pArrowColorReplacementBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pArrowNormalBitmap,
183                                                                                 Color::GetColor(COLOR_ID_MAGENTA), arrowColor);
184         SysTryCatch(NID_UI_CTRL, __pArrowColorReplacementBitmap != null, r = GetLastResult(), GetLastResult(), "[%s] Propagating.",
185                         GetErrorMessage(GetLastResult()));
186
187         delete pArrowNormalBitmap;
188         pArrowNormalBitmap = null;
189
190         return r;
191
192 CATCH:
193
194         delete pArrowNormalBitmap;
195         pArrowNormalBitmap = null;
196
197         delete __pArrowColorReplacementBitmap;
198         __pArrowColorReplacementBitmap = null;
199
200         return r;
201 }
202
203 result
204 _DateTimeBarPresenter::Draw(void)
205 {
206         result r = E_SUCCESS;
207
208         Canvas* pCanvas = __pDateTimeBar->GetCanvasN();
209         SysAssertf((pCanvas != null), "Failed to get canvas.");
210
211         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
212
213         r = pCanvas->Clear();
214         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
215
216         r = DrawBackground(*pCanvas);
217         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
218
219         r = DrawArrow(*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         delete pCanvas;
226         return r;
227
228 CATCH:
229         delete pCanvas;
230         return r;
231 }
232
233 result
234 _DateTimeBarPresenter::DrawItem(Canvas& canvas)
235 {
236         result r = E_SUCCESS;
237
238         Rectangle clientBounds = canvas.GetBounds();
239
240         _DateTimeBarItem* pDrawItem = null;
241         Rectangle itemBounds(0, 0, 0, 0);
242
243         String drawText;
244         Rectangle textAreaBounds(0, 0, 0, 0);
245
246         Color textColor;
247         GET_COLOR_CONFIG(DATETIMEBAR::TEXT_NORMAL, textColor);
248
249         Color textPressedColor;
250         GET_COLOR_CONFIG(DATETIMEBAR::TEXT_PRESSED, textPressedColor);
251
252         _DateTimeBarItemStatus itemStatus = DATETIMEBAR_ITEM_STATUS_NORMAL;
253
254         int itemCount = GetItemCount();
255
256         RefreshAccessibilityElement();
257
258         for (int i = __pDateTimeBarModel->GetFirstDrawnItemIndex(); i < itemCount; i++)
259         {
260                 pDrawItem = __pDateTimeBarModel->GetItemAt(i);
261                 if (pDrawItem == null)
262                 {
263                         break;
264                 }
265
266                 itemBounds = pDrawItem->GetBounds();
267
268                 if (itemBounds.x + itemBounds.width <= 0)
269                 {
270                         continue;
271                 }
272
273                 textAreaBounds = Rectangle(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height);
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                 int 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(textAreaBounds);
316                 pTextObject->Draw(*_CanvasImpl::GetInstance(canvas));
317
318                 delete pTextObject;
319
320                 if ((textAreaBounds.x + textAreaBounds.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         Rectangle bodyAreaBounds = GetBodyBounds();
335
336         if (__pBgColorReplacementBitmap != null)
337         {
338                 if (__pBgColorReplacementBitmap->IsNinePatchedBitmap())
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         Rectangle arrowAreaBounds = GetArrowBounds();
364
365         if (__pArrowColorReplacementBitmap != null)
366         {
367                 if (__pArrowColorReplacementBitmap->IsNinePatchedBitmap())
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 Point& point) const
397 {
398         Rectangle clientBounds = __pDateTimeBar->GetBounds();
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         int startX = 0;
409
410         while (pItem != null)
411         {
412                 Rectangle 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 int
508 _DateTimeBarPresenter::GetItemWidth(void) const
509 {
510         result r = E_SUCCESS;
511
512         _DateTimeId boxId = __pDateTimeBar->GetSelectedBoxId();
513
514         int itemWidth = 0;
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                 Dimension textArea;
529
530                 int 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 int
558 _DateTimeBarPresenter::GetFontSize(void) const
559 {
560         int fontSize = 0;
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 int
580 _DateTimeBarPresenter::GetLeftRightMargin(void) const
581 {
582         int leftRightMargin = 0;
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 int
602 _DateTimeBarPresenter::GetItemMargin(void) const
603 {
604         int margin = 0;
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(int distance)
625 {
626         int index = 0;
627
628         _DateTimeBarItem* pItem = null;
629         pItem = __pDateTimeBarModel->GetItemAt(index);
630
631         while (pItem != null)
632         {
633                 Rectangle 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         int startPosition = 0;
683         int itemWidth = GetItemWidth();
684         int itemMargin = GetItemMargin();
685
686         startPosition = (GetWindowBounds().width) / 2;
687         startPosition = startPosition + (itemWidth / 2) + 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         int itemWidth = GetItemWidth();
735         int 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         Rectangle windowAreaBounds = Rectangle(0, 0, 0, 0);
840         Rectangle bodyAreaBounds = Rectangle(0, 0, 0, 0);
841         Rectangle arrowAreaBounds = Rectangle(0, 0, 0, 0);
842
843         Rectangle parentWindowBounds = __pDateTimeBar->GetParentWindowBounds();
844         int itemHeight = 0;
845
846         arrowAreaBounds = GetArrowBounds();
847
848         Point arrowPosition;
849
850         GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_HEIGHT, orientation, arrowAreaBounds.height);
851         GET_SHAPE_CONFIG(DATETIMEBAR::ARROW_WIDTH, orientation, arrowAreaBounds.width);
852
853         GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, orientation, itemHeight);
854
855         bodyAreaBounds.width = parentWindowBounds.width;
856         bodyAreaBounds.height = itemHeight;
857
858         bodyAreaBounds.x = 0;
859         Point tempPoint = __pDateTimeBar->GetPosition();
860         windowAreaBounds.x = tempPoint.x;
861
862         if (__pDateTimeBar->GetAlignment() == DATETIME_BAR_ALIGN_DOWN)
863         {
864                 bodyAreaBounds.y = arrowAreaBounds.height;
865                 arrowAreaBounds.y = 0;
866                 windowAreaBounds.y = tempPoint.y - arrowAreaBounds.height;
867         }
868         else
869         {
870                 arrowAreaBounds.y = bodyAreaBounds.height;
871                 bodyAreaBounds.y = 0;
872                 windowAreaBounds.y = tempPoint.y;
873         }
874
875         windowAreaBounds.width = bodyAreaBounds.width;
876         windowAreaBounds.height = bodyAreaBounds.height + arrowAreaBounds.height;
877
878         SetBodyBounds(bodyAreaBounds);
879         SetArrowBounds(arrowAreaBounds);
880         SetWindowBounds(windowAreaBounds);
881         __pDateTimeBar->SetMovable(true);
882         __pDateTimeBar->SetResizable(true);
883         __pDateTimeBar->SetBounds(windowAreaBounds);
884         __pDateTimeBar->SetMovable(false);
885         __pDateTimeBar->SetResizable(false);
886
887         return E_SUCCESS;
888 }
889
890 void
891 _DateTimeBarPresenter::SetBodyBounds(const Rectangle& bounds)
892 {
893         __bodyAreaBounds = bounds;
894         return;
895 }
896
897 Rectangle
898 _DateTimeBarPresenter::GetBodyBounds(void) const
899 {
900         return __bodyAreaBounds;
901 }
902
903 void
904 _DateTimeBarPresenter::SetArrowBounds(const Rectangle& bounds)
905 {
906         __arrowAreaBounds = bounds;
907         return;
908 }
909
910 Rectangle
911 _DateTimeBarPresenter::GetArrowBounds(void) const
912 {
913         return __arrowAreaBounds;
914 }
915
916 void
917 _DateTimeBarPresenter::SetWindowBounds(const Rectangle& bounds)
918 {
919         __windowAreaBounds = bounds;
920         return;
921 }
922
923 Rectangle
924 _DateTimeBarPresenter::GetWindowBounds(void) const
925 {
926         return __windowAreaBounds;
927 }
928
929 bool
930 _DateTimeBarPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
931 {
932         if (&source != __pDateTimeBar)
933         {
934                 return false;
935         }
936
937         if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false)
938         {
939                 return false;
940         }
941
942         if (__isFlickEnabled)
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->Draw();
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         int index = GetItemIndexFromPosition(touchinfo.GetCurrentPosition());
972         bool isEventFire = true;
973
974         if (index != -1 && __isTouchMoved == false && __isFlickEnabled == false)
975         {
976                 SetItemStatus(index, DATETIMEBAR_ITEM_STATUS_SELECTED);
977                 __pDateTimeBarModel->SetFirstDrawnItemIndex(index);
978         }
979         else
980         {
981                 isEventFire = false;
982         }
983
984         __isTouchMoved = false;
985         __distance = 0;
986
987         __pDateTimeBar->Draw();
988
989         if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false)
990         {
991                 __pDateTimeBar->Close();
992                 ResetFlickAnimationTimer();
993                 return false;
994         }
995
996         if (isEventFire == true)
997         {
998                 int index = GetFirstDrawnItemIndex();
999
1000                 _DateTimeBarItem* pItem = null;
1001
1002                 if (index >= 0)
1003                 {
1004                         pItem = GetItemAt(index);
1005                 }
1006
1007                 if (pItem != null)
1008                 {
1009                         __pDateTimeBar->Close();
1010
1011                         __pDateTimeBar->FireActionEvent(pItem->GetActionId());
1012
1013                         if (__pDateTimeBar->GetSelectedBoxId() >= DATETIME_ID_YEAR && __pDateTimeBar->GetSelectedBoxId() <= DATETIME_ID_DAY)
1014                         {
1015                                 __pDateTimeBar->FireDateTimeChangeEvent(DATE_INTERNAL_CHANGE_SAVED);
1016                         }
1017                         else if (__pDateTimeBar->GetSelectedBoxId() >= DATETIME_ID_HOUR && __pDateTimeBar->GetSelectedBoxId() <= DATETIME_ID_MINUTE)
1018                         {
1019                                 __pDateTimeBar->FireDateTimeChangeEvent(TIME_INTERNAL_CHANGE_SAVED);
1020                         }
1021                 }
1022         }
1023
1024         return true;
1025 }
1026
1027 bool
1028 _DateTimeBarPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
1029 {
1030         if (&source != __pDateTimeBar)
1031         {
1032                 return false;
1033         }
1034
1035         if (GetBodyBounds().Contains(touchinfo.GetCurrentPosition()) == false || __touchMoveHandled == true)
1036         {
1037                 return false;
1038         }
1039
1040         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1041
1042         __isTouchMoved = true;
1043
1044         Dimension screen(0, 0);
1045         GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, orientation, screen);
1046
1047         const int _BOUNDARY_X_POSITION = screen.width * 2;
1048         int distance = (touchinfo.GetCurrentPosition()).x - __currentPoint.x;
1049
1050         _DateTimeBarItem* pItem = null;
1051
1052         Rectangle itemBounds;
1053
1054         bool needItem = false;
1055         int updateItemCount = 1;
1056
1057         if (distance > 0)
1058         {
1059                 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1060
1061                 if (pItem == null)
1062                 {
1063                         return true;
1064                 }
1065
1066                 itemBounds = pItem->GetBounds();
1067
1068                 __distance += distance;
1069
1070                 if (__distance > itemBounds.width / 2)
1071                 {
1072                         needItem = true;
1073                         if (__distance > itemBounds.width)
1074                         {
1075                                 updateItemCount = UPDATE_ITEM_COUNT;
1076                         }
1077                 }
1078                 if (needItem == true)
1079                 {
1080                         while (updateItemCount > 0)
1081                         {
1082                                 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1083                                 if (pItem == null)
1084                                 {
1085                                         break;
1086                                 }
1087
1088                                 int actionId = pItem->GetActionId() - 1;
1089
1090                                 if (__pDateTimeBarModel->GetMinimumValue() > actionId)
1091                                 {
1092                                         actionId = __pDateTimeBarModel->GetMaximumValue();
1093                                 }
1094
1095                                 if (pItem->GetBounds().x > _BOUNDARY_X_POSITION * -1)
1096                                 {
1097                                         if (InsertItem(0, actionId) == E_SUCCESS)
1098                                         {
1099                                                 SetFirstDrawnItemIndex(0);
1100                                         }
1101                                 }
1102
1103                                 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1104                                 {
1105                                         DeleteItem(GetItemCount() - 1);
1106                                 }
1107
1108                                 updateItemCount--;
1109                         }
1110                         __distance = 0;
1111                 }
1112         }
1113         else
1114         {
1115                 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1116                 if (pItem == null)
1117                 {
1118                         return true;
1119                 }
1120
1121                 itemBounds = pItem->GetBounds();
1122
1123                 __distance += distance;
1124
1125                 if (__distance * -1 > itemBounds.width / 2)
1126                 {
1127                         needItem = true;
1128                         if (__distance * -1 > itemBounds.width)
1129                         {
1130                                 updateItemCount = UPDATE_ITEM_COUNT;
1131                         }
1132                         __distance = 0;
1133                 }
1134
1135                 if (needItem == true)
1136                 {
1137                         while (updateItemCount > 0)
1138                         {
1139                                 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1140                                 if (pItem == null)
1141                                 {
1142                                         break;
1143                                 }
1144
1145                                 int actionId = pItem->GetActionId() + 1;
1146
1147                                 if (__pDateTimeBarModel->GetMaximumValue() < actionId)
1148                                 {
1149                                         actionId = __pDateTimeBarModel->GetMinimumValue();
1150                                 }
1151
1152                                 if (pItem->GetBounds().x < _BOUNDARY_X_POSITION)
1153                                 {
1154                                         AddItem(actionId);
1155                                 }
1156
1157                                 if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1158                                 {
1159                                         DeleteItem(0);
1160                                         SetFirstDrawnItemIndex(0);
1161                                 }
1162                                 updateItemCount--;
1163                         }
1164                 }
1165         }
1166
1167         __currentPoint = touchinfo.GetCurrentPosition();
1168
1169         AdjustItemPosition(distance);
1170
1171         __pDateTimeBar->Draw();
1172
1173         return true;
1174 }
1175
1176 bool
1177 _DateTimeBarPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
1178 {
1179         if (&source != __pDateTimeBar)
1180         {
1181                 return false;
1182         }
1183
1184         __isTouchMoved = false;
1185         __distance = 0;
1186
1187         __pDateTimeBar->Draw();
1188
1189         return true;
1190 }
1191
1192 result
1193 _DateTimeBarPresenter::LoadItems()
1194 {
1195         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1196
1197         Dimension screen(0, 0);
1198         GET_DIMENSION_CONFIG(DATETIMEBAR::DEFAULT_SIZE, orientation, screen);
1199
1200         const int _BOUNDARY_X_POSITION = screen.width * 2;
1201
1202         _DateTimeBarItem* pItem = null;
1203
1204         Rectangle itemBounds;
1205
1206         int updateItemCount = UPDATE_ITEM_COUNT;
1207
1208         if (__distance > 0)
1209         {
1210                 pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1211
1212                 if (pItem == null)
1213                 {
1214                         return true;
1215                 }
1216
1217
1218                 while (updateItemCount > 0)
1219                 {
1220                         pItem = __pDateTimeBarModel->GetItemAt(GetFirstDrawnItemIndex());
1221                         if (pItem == null)
1222                         {
1223                                 break;
1224                         }
1225
1226                         int actionId = pItem->GetActionId() - 1;
1227
1228                         if (__pDateTimeBarModel->GetMinimumValue() > actionId)
1229                         {
1230                                 actionId = __pDateTimeBarModel->GetMaximumValue();
1231                         }
1232
1233                         if (pItem->GetBounds().x > _BOUNDARY_X_POSITION * -1)
1234                         {
1235                                 if (InsertItem(0, actionId) == E_SUCCESS)
1236                                 {
1237                                         SetFirstDrawnItemIndex(0);
1238                                 }
1239                         }
1240
1241                         if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1242                         {
1243                                 DeleteItem(GetItemCount() - 1);
1244                         }
1245                         updateItemCount--;
1246                 }
1247
1248         }
1249         else
1250         {
1251                 pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1252                 if (pItem == null)
1253                 {
1254                         return true;
1255                 }
1256
1257
1258                 while (updateItemCount > 0)
1259                 {
1260                         pItem = __pDateTimeBarModel->GetItemAt(GetItemCount() - 1);
1261                         if (pItem == null)
1262                         {
1263                                 break;
1264                         }
1265
1266                         int actionId = pItem->GetActionId() + 1;
1267
1268                         if (__pDateTimeBarModel->GetMaximumValue() < actionId)
1269                         {
1270                                 actionId = __pDateTimeBarModel->GetMinimumValue();
1271                         }
1272
1273                         if (pItem->GetBounds().x < _BOUNDARY_X_POSITION)
1274                         {
1275                                 AddItem(actionId);
1276                         }
1277
1278                         if (GetItemCount() >= __pDateTimeBarModel->GetMaxCachingSize())
1279                         {
1280                                 DeleteItem(0);
1281                                 SetFirstDrawnItemIndex(0);
1282                         }
1283                         updateItemCount--;
1284                 }
1285         }
1286
1287         return true;
1288 }
1289
1290 bool
1291 _DateTimeBarPresenter::OnFlickGestureDetected(int distanceX,int distanceY,int duration)
1292 {
1293         __isFlickEnabled = true;
1294         __isInitialAnimation = false;
1295
1296         int velX = 0;
1297         int velY = 0;
1298
1299         __flickAnimation.CalculateInitializeVelocity(distanceX, 0, duration, &velX, &velY);
1300         __flickAnimation.InitializeFlickAmount(velX);
1301
1302         StartFlickAnimationTimer();
1303         return true;
1304 }
1305
1306 void
1307 _DateTimeBarPresenter::StartFlickAnimation(void)
1308 {
1309         int moveX = 0;
1310         int moveY = 0;
1311
1312         __flickAnimation.CalculateNextMove(&moveX, &moveY);
1313
1314         __distance = moveX;
1315         if (moveX != 0)
1316         {
1317                 StartFlickAnimationTimer();
1318         }
1319
1320         LoadItems();
1321         AdjustItemPosition(__distance);
1322         Draw();
1323         return;
1324 }
1325
1326 void
1327 _DateTimeBarPresenter::StartAnimationEffect(void)
1328 {
1329         __isInitialAnimation = true;
1330         __distance = -10;
1331
1332         if (__initialAnimationValue >= 0 )
1333         {
1334                 __initialAnimationValue = __initialAnimationValue + __distance;
1335                 StartFlickAnimationTimer();
1336
1337                 LoadItems();
1338                 AdjustItemPosition(__distance);
1339                 Draw();
1340         }
1341         else
1342         {
1343                 __initialAnimationValue = 0;
1344                 __isInitialAnimation = false;
1345                 ResetFlickAnimationTimer();
1346                 ValidateAndAdjustStartPosition();
1347         }
1348
1349         return;
1350 }
1351
1352 result
1353 _DateTimeBarPresenter::StartFlickAnimationTimer(void)
1354 {
1355         result r = E_SUCCESS;
1356
1357         if (__pFlickAnimationTimer == null)
1358         {
1359                 __pFlickAnimationTimer = new (std::nothrow) Timer;
1360                 SysTryReturn(NID_UI_CTRL, (__pFlickAnimationTimer != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create timer.");
1361
1362                 r = __pFlickAnimationTimer->Construct(*this);
1363                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1364         }
1365         else
1366         {
1367                 __pFlickAnimationTimer->Cancel();
1368         }
1369
1370         r = __pFlickAnimationTimer->Start(FLICK_ANIMATION_TIMER_PERIOD);
1371         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1372
1373         return r;
1374
1375 CATCH:
1376         ResetFlickAnimationTimer();
1377         return r;
1378 }
1379
1380 result
1381 _DateTimeBarPresenter::ResetFlickAnimationTimer(void)
1382 {
1383         if (__pFlickAnimationTimer)
1384         {
1385                 delete __pFlickAnimationTimer;
1386                 __pFlickAnimationTimer = null;
1387         }
1388
1389         __isFlickEnabled = false;
1390         return E_SUCCESS;
1391 }
1392
1393 void
1394 _DateTimeBarPresenter::OnTimerExpired(Timer& timer)
1395 {
1396         if (&timer == __pFlickAnimationTimer)
1397         {
1398                 if (__isInitialAnimation)
1399                 {
1400                         StartAnimationEffect();
1401                 }
1402                 else
1403                 {
1404                         StartFlickAnimation();
1405                 }
1406         }
1407         return;
1408 }
1409
1410 void
1411 _DateTimeBarPresenter::ValidateAndAdjustStartPosition(void)
1412 {
1413         int index = -1;
1414         int adjustPosition = 0;
1415         int leftMargin =  GetLeftRightMargin();
1416         Rectangle bodyBounds = GetBodyBounds();
1417
1418         index = GetItemIndexFromPosition(Point(GetLeftRightMargin() + GetItemMargin(), bodyBounds.y + (bodyBounds.height / 2)));
1419
1420         if (index == -1)
1421         {
1422                 return;
1423         }
1424
1425         _DateTimeBarItem* pDrawItem = null;
1426         pDrawItem = __pDateTimeBarModel->GetItemAt(index);
1427
1428         if (pDrawItem == null)
1429         {
1430                 return;
1431         }
1432
1433         if (pDrawItem->GetBounds().x > 0 && pDrawItem->GetBounds().x < leftMargin)
1434         {
1435                 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1436         }
1437         else if (pDrawItem->GetBounds().x < 0)
1438         {
1439                 pDrawItem = __pDateTimeBarModel->GetItemAt(index + 1);
1440                 if (pDrawItem == null)
1441                 {
1442                         return;
1443                 }
1444                 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1445         }
1446         else if (pDrawItem->GetBounds().x > leftMargin)
1447         {
1448                 adjustPosition = leftMargin - pDrawItem->GetBounds().x;
1449         }
1450
1451         AdjustItemPosition(adjustPosition);
1452         Draw();
1453         return;
1454 }
1455
1456 void
1457 _DateTimeBarPresenter::SetInitialAnimationValue(int animationValue)
1458 {
1459         __initialAnimationValue = animationValue;
1460         return;
1461 }
1462
1463 void
1464 _DateTimeBarPresenter::SetFont(Font& pFont)
1465 {
1466         delete __pFont;
1467         __pFont = null;
1468
1469         __pFont = _FontImpl::CloneN(pFont);
1470         SysTryReturnVoidResult(NID_UI_CTRL, (__pFont != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1471
1472         return;
1473 }
1474
1475 bool
1476 _DateTimeBarPresenter::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1477 {
1478         __distance = (GetItemWidth() + GetItemMargin()) * (-1);
1479
1480         if (element.GetBounds().x + element.GetBounds().width > GetWindowBounds().width)
1481         {
1482                 AdjustItemPosition(__distance);
1483                 Draw();
1484         }
1485         return true;
1486 }
1487
1488 bool
1489 _DateTimeBarPresenter::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
1490 {
1491         __distance = (GetItemWidth() + GetItemMargin());
1492
1493         if (element.GetBounds().x < GetWindowBounds().x)
1494         {
1495                 AdjustItemPosition(__distance);
1496                 Draw();
1497         }
1498         return true;
1499 }
1500
1501 void
1502 _DateTimeBarPresenter::OnTouchMoveHandled(const Tizen::Ui::_Control& control)
1503 {
1504         __touchMoveHandled = true;
1505
1506         __isTouchMoved = false;
1507         __distance = 0;
1508
1509         __pDateTimeBar->Draw();
1510 }
1511
1512 void
1513 _DateTimeBarPresenter::RefreshAccessibilityElement(void)
1514 {
1515         __pDateTimeBar->RemoveAllAccessibilityElement();
1516
1517         for (int index = 0; index < __pDateTimeBarModel->GetItemCount(); index++)
1518         {
1519                 _DateTimeBarItem* pItem = __pDateTimeBarModel->GetItemAt(index);
1520
1521                 if (pItem != null)
1522                 {
1523                         if (__pDateTimeBar->GetSelectedBoxId() == DATETIME_ID_MONTH)
1524                         {
1525                                 __pDateTimeBar->AddAccessibilityElement(pItem->GetBounds(), __pDateTimeBar->GetMonthValue(pItem->GetActionId()));
1526                         }
1527                         else
1528                         {
1529                                 __pDateTimeBar->AddAccessibilityElement(pItem->GetBounds(), pItem->GetText());
1530                         }
1531                 }
1532         }
1533
1534         return;
1535 }
1536
1537 }}} // Tizen::Ui::Controls