Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_DateTimeBar.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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_DateTimeBar.cpp
20  * @brief               This is the implementation file for the _DateTimeBar class.
21  */
22
23 #include <FUiAnimVisualElementAnimationGroup.h>
24 #include <FUiAnimVisualElementPropertyAnimation.h>
25 #include "FUiAnim_VisualElement.h"
26 #include "FUi_AccessibilityContainer.h"
27 #include "FUi_AccessibilityElement.h"
28 #include "FUi_ResourceManager.h"
29 #include "FUiCtrl_DateTimeBar.h"
30 #include "FUiCtrl_DateTimeBarPresenter.h"
31 #include "FUiCtrl_ActionEvent.h"
32 #include "FUiCtrl_Frame.h"
33 #include "FUiCtrl_Form.h"
34 #include "FUi_CoordinateSystemUtils.h"
35
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Media;
38 using namespace Tizen::Base;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::Ui::Animations;
41
42 namespace Tizen { namespace Ui { namespace Controls
43 {
44 _DateTimeBar::_DateTimeBar(void)
45         : __pDateTimeBarPresenter(null)
46         , __pActionEvent(null)
47         , __selectedBoxId(DATETIME_ID_NONE)
48         , __alignment(DATETIME_BAR_ALIGN_DOWN)
49         , __pDateTimeChangeEvent(null)
50         , __pGestureFlick(null)
51         , __parentWindowBounds(0.0f, 0.0f, 0.0f, 0.0f)
52         , __pOwner(null)
53         , __accessibilityFocusOutIndex(-1)
54         , __isAnimating(false)
55 {
56
57 }
58
59 _DateTimeBar::~_DateTimeBar(void)
60 {
61         ReleaseTouchCapture();
62
63         if (GetVisualElement())
64         {
65                 GetVisualElement()->RemoveAllAnimations();
66         }
67
68         if (__pDateTimeChangeEvent != null)
69         {
70                 delete __pDateTimeChangeEvent;
71                 __pDateTimeChangeEvent = null;
72         }
73
74         if (__pActionEvent)
75         {
76                 delete __pActionEvent;
77                 __pActionEvent = null;
78         }
79
80         delete __pDateTimeBarPresenter;
81         __pDateTimeBarPresenter = null;
82
83         delete __pGestureFlick;
84         __pGestureFlick = null;
85
86         RemoveAllAccessibilityElement();
87
88         ClearLastResult();
89 }
90
91 _DateTimeBar*
92 _DateTimeBar::CreateDateTimeBarN(_Control& owner)
93 {
94         result r = E_SUCCESS;
95         ClearLastResult();
96
97         _DateTimeBar* pDateTimeBar = new (std::nothrow) _DateTimeBar;
98         SysTryReturn(NID_UI_CTRL, pDateTimeBar != null, null, E_OUT_OF_MEMORY,
99                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
100
101         r = pDateTimeBar->CreateRootVisualElement();
102         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
103
104         pDateTimeBar->__pOwner = &owner;
105
106         pDateTimeBar->__pDateTimeBarPresenter = _DateTimeBarPresenter::CreateInstanceN(*pDateTimeBar);
107         r = GetLastResult();
108         SysTryCatch(NID_UI_CTRL, pDateTimeBar->__pDateTimeBarPresenter != null, , r,
109                         "[%s] Propagating.", GetErrorMessage(r));
110
111         pDateTimeBar->__pDateTimeChangeEvent = new (std::nothrow) _DateTimeChangeEvent(*pDateTimeBar);
112         SysTryCatch(NID_UI_CTRL, (pDateTimeBar->__pDateTimeChangeEvent != null), , E_OUT_OF_MEMORY,
113                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
114
115         pDateTimeBar->AcquireHandle();
116
117         if (pDateTimeBar->GetVisualElement() != null)
118         {
119                 pDateTimeBar->GetVisualElement()->SetSurfaceOpaque(false);
120         }
121
122         pDateTimeBar->__pGestureFlick = new (std::nothrow) _TouchFlickGestureDetector();
123         SysTryCatch(NID_UI_CTRL, (pDateTimeBar->__pGestureFlick != null), , E_OUT_OF_MEMORY,
124                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
125
126         pDateTimeBar->AddGestureDetector(*(pDateTimeBar->__pGestureFlick));
127         SysTryCatch(NID_UI_CTRL, (GetLastResult() == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
128
129         r = pDateTimeBar->__pGestureFlick->AddGestureListener(*pDateTimeBar);
130         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
131
132         pDateTimeBar->InitializeAccessibilityElement();
133         return pDateTimeBar;
134
135 CATCH:
136         delete pDateTimeBar;
137         return null;
138 }
139
140 result
141 _DateTimeBar::SetPositionAndAlignment(const FloatPoint& point, _DateTimeBarAlignment alignment)
142 {
143         ClearLastResult();
144
145         result r = E_SUCCESS;
146         SetAlignment(alignment);
147
148         r = __pDateTimeBarPresenter->LoadArrowBitmap();
149         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
150
151         float height = 0.0f;
152
153         r = GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, GetOrientation(), height);
154         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
155
156         SetMovable(true);
157         SetResizable(true);
158
159         if (alignment == DATETIME_BAR_ALIGN_DOWN)
160         {
161                 SetPosition(FloatPoint(point.x, point.y));
162
163         }
164         else
165         {
166                 SetPosition(FloatPoint(point.x, point.y - height));
167         }
168
169         __pDateTimeBarPresenter->CalculateWindowBounds();
170
171         return r;
172 }
173
174 _DateTimeBarAlignment
175 _DateTimeBar::GetAlignment(void) const
176 {
177         return __alignment;
178 }
179
180 void
181 _DateTimeBar::SetAlignment(_DateTimeBarAlignment alignment)
182 {
183         __alignment = alignment;
184         return;
185 }
186
187 void
188 _DateTimeBar::OnDraw(void)
189 {
190         ClearLastResult();
191
192         __pDateTimeBarPresenter->Draw();
193         return;
194 }
195
196 result
197 _DateTimeBar::RemoveAllItems(void)
198 {
199         ClearLastResult();
200
201         result r = E_SUCCESS;
202
203         r = __pDateTimeBarPresenter->RemoveAllItems();
204         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
205
206         return r;
207 }
208
209 result
210 _DateTimeBar::SetInitialValue(int minValue, int maxValue, int displayValue, _DateTimeId boxId)
211 {
212         ClearLastResult();
213
214         result r = E_SUCCESS;
215
216         SetSelectedBoxId(boxId);
217
218         __pDateTimeBarPresenter->SetMinimumValue(minValue);
219         __pDateTimeBarPresenter->SetMaximumValue(maxValue);
220
221         r = __pDateTimeBarPresenter->AddItems(displayValue);
222         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
223
224         return r;
225 }
226
227 _DateTimeId
228 _DateTimeBar::GetSelectedBoxId(void) const
229 {
230         return __selectedBoxId;
231 }
232
233 void
234 _DateTimeBar::SetSelectedBoxId(_DateTimeId boxId)
235 {
236         __selectedBoxId = boxId;
237         return;
238 }
239
240
241 void
242 _DateTimeBar::InitializeAccessibilityElement(void)
243 {
244
245         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
246
247         if (pContainer)
248         {
249                 pContainer->Activate(true);
250                 pContainer->AddListener(*this);
251         }
252
253         return;
254 }
255
256 int
257 _DateTimeBar::GetItemCount(void) const
258 {
259         ClearLastResult();
260
261         return __pDateTimeBarPresenter->GetItemCount();
262 }
263
264 result
265 _DateTimeBar::AddActionEventListener(const _IActionEventListener& listener)
266 {
267         ClearLastResult();
268
269         result r = E_SUCCESS;
270
271         if (__pActionEvent == null)
272         {
273                 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
274                 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_SYSTEM, E_SYSTEM,
275                                         "[%s] Propagating.", GetErrorMessage(r));
276         }
277         r = __pActionEvent->AddListener(listener);
278         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
279
280         return r;
281 }
282
283 result
284 _DateTimeBar::RemoveActionEventListener(const _IActionEventListener& listener)
285 {
286         ClearLastResult();
287
288         result r = E_OBJ_NOT_FOUND;
289
290         if (__pActionEvent)
291         {
292                 r = __pActionEvent->RemoveListener(listener);
293         }
294
295         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
296
297         return r;
298 }
299
300 result
301 _DateTimeBar::AddDateTimeChangeEventListener(const _IDateTimeChangeEventListener& listener)
302 {
303         ClearLastResult();
304
305         return __pDateTimeChangeEvent->AddListener(listener);
306 }
307
308 result
309 _DateTimeBar::RemoveDateTimeChangeEventListener(const _IDateTimeChangeEventListener& listener)
310 {
311         ClearLastResult();
312
313         return __pDateTimeChangeEvent->RemoveListener(listener);
314 }
315
316 result
317 _DateTimeBar::FireDateTimeChangeEvent(_DateTimeChangeStatus status)
318 {
319         ClearLastResult();
320
321         _DateTimeChangeEventArg* pDateTimeEventArg = new (std::nothrow) _DateTimeChangeEventArg(status);
322         SysTryReturn(NID_UI_CTRL, (pDateTimeEventArg != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
323                         "[E_OUT_OF_MEMORY] Memory allocation failed.");
324
325         __pDateTimeChangeEvent->Fire(*pDateTimeEventArg);
326
327         return E_SUCCESS;
328 }
329
330 result
331 _DateTimeBar::FireActionEvent(int actionId)
332 {
333         ClearLastResult();
334
335         if (__pActionEvent)
336         {
337                 Tizen::Base::Runtime::IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(actionId);
338                 result r = GetLastResult();
339                 SysTryReturn(NID_UI_CTRL, pEventArg, false, r, "[%s] Propagating.", GetErrorMessage(r));
340
341                 __pActionEvent->Fire(*pEventArg);
342         }
343
344         return E_SUCCESS;
345 }
346
347 result
348 _DateTimeBar::CalculateArrowBounds(const FloatRectangle& bounds)
349 {
350         ClearLastResult();
351
352         FloatRectangle arrowBounds(0.0f, 0.0f, 0.0f, 0.0f);
353
354         arrowBounds = __pDateTimeBarPresenter->GetArrowBounds();
355         arrowBounds.x = bounds.x + (bounds.width / 2.0f) - (arrowBounds.width / 2.0f);
356         arrowBounds.x -= __pDateTimeBarPresenter->GetWindowBounds().x;
357
358         __pDateTimeBarPresenter->SetArrowBounds(arrowBounds);
359
360         return E_SUCCESS;
361 }
362
363 bool
364 _DateTimeBar::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
365 {
366         ClearLastResult();
367         if (__isAnimating)
368         {
369                 return true;
370         }
371
372         return __pDateTimeBarPresenter->OnTouchPressed(source, touchinfo);
373 }
374
375 bool
376 _DateTimeBar::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
377 {
378         ClearLastResult();
379         if (__isAnimating)
380         {
381                 return true;
382         }
383
384         return __pDateTimeBarPresenter->OnTouchReleased(source, touchinfo);
385 }
386
387 bool
388 _DateTimeBar::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
389 {
390         ClearLastResult();
391         if (__isAnimating)
392         {
393                 return true;
394         }
395
396         return __pDateTimeBarPresenter->OnTouchMoved(source, touchinfo);
397 }
398
399 bool
400 _DateTimeBar::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
401 {
402         ClearLastResult();
403
404         return __pDateTimeBarPresenter->OnTouchCanceled(source, touchinfo);
405 }
406
407 bool
408 _DateTimeBar::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
409 {
410         int xDistance = 0;
411         int yDistance = 0;
412         gesture.GetDistance(xDistance, yDistance);
413         int duration = gesture.GetDuration();
414         return __pDateTimeBarPresenter->OnFlickGestureDetected(xDistance, yDistance, duration);
415 }
416
417 bool
418 _DateTimeBar::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
419 {
420    return false;
421 }
422
423 void
424 _DateTimeBar::OnTouchMoveHandled(const Tizen::Ui::_Control& control)
425 {
426         ClearLastResult();
427
428         return __pDateTimeBarPresenter->OnTouchMoveHandled(control);
429 }
430
431 result
432 _DateTimeBar::OnAttachedToMainTree(void)
433 {
434         SetOwner(__pOwner);
435
436         return _Window::OnAttachedToMainTree();
437 }
438
439 result
440 _DateTimeBar::OnDetachingFromMainTree(void)
441 {
442         return _Window::OnDetachingFromMainTree();
443 }
444
445 void
446 _DateTimeBar::OnActivated(void)
447 {
448         VisualElement* pVisualElement = null;
449         VisualElementAnimation *pAnimation = null;
450
451         pVisualElement = GetVisualElement();
452         SysTryReturnVoidResult(NID_UI_CTRL, pVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element.");
453         pAnimation = CreateAnimationN(*pVisualElement, true);
454         SysTryReturnVoidResult(NID_UI_CTRL, pAnimation != null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
455         pVisualElement->AddAnimation(L"BarOpenAnimation", *pAnimation);
456         delete pAnimation;
457
458         SetTouchCapture(true, true);
459
460         return _Window::OnActivated();
461 }
462
463 void
464 _DateTimeBar::OnDeactivated(void)
465 {
466         ReleaseTouchCapture();
467
468         return _Window::OnDeactivated();
469 }
470
471 void
472 _DateTimeBar::AddAccessibilityElement(const FloatRectangle& itemBounds, const String& itemText)
473 {
474         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
475         SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
476
477         _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
478         SysTryReturnVoidResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
479
480         String labelText = itemText;
481         pAccessibilityElement->SetBounds(itemBounds);
482         pAccessibilityElement->SetLabel(labelText);
483         pAccessibilityElement->SetTraitWithStringId(GetAccessibilityTraitValue());
484         pContainer->AddElement(*pAccessibilityElement);
485         __accessibilityElements.Add(pAccessibilityElement);
486
487         return;
488 }
489
490 void
491 _DateTimeBar::InsertAccessibilityElementAt(int index, const FloatRectangle& itemBounds, const String& itemText)
492 {
493         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
494         SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
495
496         _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
497         SysTryReturnVoidResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
498
499         String labelText = itemText;
500         pAccessibilityElement->SetBounds(itemBounds);
501         pAccessibilityElement->SetLabel(labelText);
502         pAccessibilityElement->SetTraitWithStringId(GetAccessibilityTraitValue());
503         pContainer->InsertElement(*pAccessibilityElement, index);
504         __accessibilityElements.InsertAt(pAccessibilityElement, index);
505
506         return;
507 }
508
509 void
510 _DateTimeBar::RemoveAccessibilityElementAt(int index)
511 {
512         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
513         SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
514
515         _AccessibilityElement* pAccessibilityElement = null;
516
517         if (__accessibilityElements.GetAt(index, pAccessibilityElement) == E_SUCCESS)
518         {
519                 __accessibilityElements.RemoveAt(index);
520                 pContainer->RemoveElement(*pAccessibilityElement);
521         }
522
523         return;
524 }
525
526 void
527 _DateTimeBar::RemoveAllAccessibilityElement(void)
528 {
529         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
530         SysTryReturnVoidResult(NID_UI_CTRL, (pContainer != null), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
531
532         _AccessibilityElement* pAccessibilityElement = null;
533
534         while (__accessibilityElements.GetCount() > 0)
535         {
536                 if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS)
537                 {
538                         __accessibilityElements.RemoveAt(0);
539                         pContainer->RemoveElement(*pAccessibilityElement);
540                 }
541         }
542
543         return;
544 }
545
546 const char*
547 _DateTimeBar::GetAccessibilityTraitValue() const
548 {
549         const char* ACCESSIBILITY_TRAITS_DAY = "IDS_TPLATFORM_BODY_DAY_LC";
550         const char* ACCESSIBILITY_TRAITS_MONTH = "IDS_TPLATFORM_BODY_MONTH_LC";
551         const char* ACCESSIBILITY_TRAITS_YEAR = "IDS_TPLATFORM_BODY_YEAR_LC";
552         const char* ACCESSIBILITY_TRAITS_HOUR = "IDS_TPLATFORM_BODY_HOUR_LC";
553         const char* ACCESSIBILITY_TRAITS_MINUTE = "IDS_TPLATFORM_BODY_MINUTE_LC";
554         char* traitsValue = null;
555
556         if (GetSelectedBoxId() == DATETIME_ID_DAY)
557         {
558                 traitsValue = const_cast<char*>(ACCESSIBILITY_TRAITS_DAY);
559         }
560         else if (GetSelectedBoxId() == DATETIME_ID_MONTH)
561         {
562                 traitsValue = const_cast<char*>(ACCESSIBILITY_TRAITS_MONTH);
563         }
564         else if (GetSelectedBoxId() == DATETIME_ID_YEAR)
565         {
566                 traitsValue = const_cast<char*>(ACCESSIBILITY_TRAITS_YEAR);
567         }
568         else if (GetSelectedBoxId() == DATETIME_ID_HOUR)
569         {
570                 traitsValue = const_cast<char*>(ACCESSIBILITY_TRAITS_HOUR);
571         }
572         else if (GetSelectedBoxId() == DATETIME_ID_MINUTE)
573         {
574                 traitsValue = const_cast<char*>(ACCESSIBILITY_TRAITS_MINUTE);
575         }
576
577         return traitsValue;
578 }
579
580 String
581 _DateTimeBar::GetMonthValue(int month) const
582 {
583         String monthValue;
584
585         switch (month)
586         {
587         case 1:
588                 monthValue = L"January";
589                 break;
590         case 2:
591                 monthValue = L"February";
592                 break;
593         case 3:
594                 monthValue = L"March";
595                 break;
596         case 4:
597                 monthValue = L"April";
598                 break;
599         case 5:
600                 monthValue = L"May";
601                 break;
602         case 6:
603                 monthValue = L"June";
604                 break;
605         case 7:
606                 monthValue = L"July";
607                 break;
608         case 8:
609                 monthValue = L"August";
610                 break;
611         case 9:
612                 monthValue = L"September";
613                 break;
614         case 10:
615                 monthValue = L"October";
616                 break;
617         case 11:
618                 monthValue = L"November";
619                 break;
620         case 12:
621                 monthValue = L"December";
622                 break;
623         default:
624                 monthValue = L"";
625         }
626
627         return monthValue;
628 }
629
630 void
631 _DateTimeBar::SetFont(Font& pFont)
632 {
633         __pDateTimeBarPresenter->SetFont(pFont);
634
635         return;
636 }
637
638 void
639 _DateTimeBar::SetParentWindowBounds(FloatRectangle& parentWindowBounds)
640 {
641         __parentWindowBounds = parentWindowBounds;
642         return;
643 }
644
645 FloatRectangle
646 _DateTimeBar::GetParentWindowBounds() const
647 {
648         return __parentWindowBounds;
649 }
650
651 void
652 _DateTimeBar::RefreshItems(void)
653 {
654         float itemWidth = 0;
655
656         if (GetSelectedBoxId() == DATETIME_ID_MONTH)
657         {
658                 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
659         }
660         else if (GetSelectedBoxId() == DATETIME_ID_YEAR)
661         {
662                 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
663         }
664         else
665         {
666                 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
667         }
668
669         __pDateTimeBarPresenter->SetInitialAnimationValue(itemWidth);
670
671         __pDateTimeBarPresenter->StartAnimationEffect();
672
673         if (unlikely((_AccessibilityManager::IsActivated())))
674         {
675                 _AccessibilityElement* pAccessibilityElement = GetAccessibilityElementAt(__pDateTimeBarPresenter->GetSelectedItemIndex() - 1);
676
677                 if (pAccessibilityElement != null)
678                 {
679                         _AccessibilityManager::GetInstance()->SetGlobalFocusedElement(*pAccessibilityElement);
680                 }
681         }
682
683         return;
684 }
685
686 bool
687 _DateTimeBar::OnFocusGained(const _Control& control)
688 {
689         __pDateTimeBarPresenter->ChangeFocusStatus();
690         __pDateTimeBarPresenter->SetFocusedItemBounds();
691         __pDateTimeBarPresenter->SetItemFocused(true);
692
693         return true;
694 }
695
696 bool
697 _DateTimeBar::OnFocusLost(const _Control& control)
698 {
699         __pDateTimeBarPresenter->SetItemFocused(false);
700         return true;
701 }
702
703 void
704 _DateTimeBar::OnFocusModeStateChanged(void)
705 {
706         __pDateTimeBarPresenter->FocusModeChanged();
707         Invalidate();
708         return;
709 }
710
711 void
712 _DateTimeBar::OnDrawFocus(void)
713 {
714         return;
715 }
716
717 bool
718 _DateTimeBar::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
719 {
720         return __pDateTimeBarPresenter->OnKeyPressed(source,keyInfo);
721 }
722
723 bool
724 _DateTimeBar::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
725 {
726         return __pDateTimeBarPresenter->OnKeyReleased(source,keyInfo);
727 }
728
729 bool
730 _DateTimeBar::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
731 {
732         return __pDateTimeBarPresenter->OnAccessibilityFocusMovedNext(control, element);
733 }
734
735 bool
736 _DateTimeBar::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
737 {
738         return __pDateTimeBarPresenter->OnAccessibilityFocusMovedPrevious(control, element);
739 }
740
741 bool
742 _DateTimeBar::OnAccessibilityReadingElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
743 {
744         return false;
745 }
746
747 bool
748 _DateTimeBar::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
749 {
750         return false;
751 }
752
753 bool
754 _DateTimeBar::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
755 {
756         if (__accessibilityFocusOutIndex == -1)
757         {
758                 return false;
759         }
760
761         float itemWidth = 0;
762
763         if (GetSelectedBoxId() == DATETIME_ID_MONTH)
764         {
765                 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
766         }
767         else if (GetSelectedBoxId() == DATETIME_ID_YEAR)
768         {
769                 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
770         }
771         else
772         {
773                 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
774         }
775
776         _AccessibilityElement* pFocusInAccessibilityElement = null;
777
778         int focusInIndex = GetIndexFromAccessibilityElementPoint(FloatPoint(element.GetBounds().x, element.GetBounds().y));
779
780         pFocusInAccessibilityElement = GetAccessibilityElementAt(focusInIndex);
781
782         if (__accessibilityFocusOutIndex < focusInIndex)
783         {
784                 if (pFocusInAccessibilityElement != null && (pFocusInAccessibilityElement->GetBounds().x + pFocusInAccessibilityElement->GetBounds().width >
785                 __pDateTimeBarPresenter->GetWindowBounds().x + __pDateTimeBarPresenter->GetWindowBounds().width))
786                 {
787                         __pDateTimeBarPresenter->MoveNext();
788
789                 }
790         }
791         else if (__accessibilityFocusOutIndex > focusInIndex)
792         {
793                 if (pFocusInAccessibilityElement != null && pFocusInAccessibilityElement->GetBounds().x < 0)
794                 {
795                         __pDateTimeBarPresenter->MovePrevious();
796                 }
797         }
798
799         return false;
800 }
801
802 bool
803 _DateTimeBar::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
804 {
805         __accessibilityFocusOutIndex = GetIndexFromAccessibilityElementPoint(FloatPoint(element.GetBounds().x, element.GetBounds().y));
806
807         return false;
808 }
809
810 bool
811 _DateTimeBar::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
812 {
813         return false;
814 }
815
816 bool
817 _DateTimeBar::OnAccessibilityValueIncreased(const Tizen::Ui::_AccessibilityContainer&, const Tizen::Ui::_AccessibilityElement&)
818 {
819         return false;
820 }
821
822 bool
823 _DateTimeBar::OnAccessibilityValueDecreased(const Tizen::Ui::_AccessibilityContainer&, const Tizen::Ui::_AccessibilityElement&)
824 {
825         return false;
826 }
827
828 _AccessibilityElement*
829 _DateTimeBar::GetAccessibilityElementAt(int index) const
830 {
831         result r = E_SUCCESS;
832         _AccessibilityElement* pAccessibilityElement = null;
833
834         r = __accessibilityElements.GetAt(index, pAccessibilityElement);
835         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
836
837         return pAccessibilityElement;
838 }
839
840 int
841 _DateTimeBar::GetIndexFromAccessibilityElementPoint(const FloatPoint& point) const
842 {
843         _AccessibilityElement* pAccessibilityElement = null;
844
845         for (int index = __accessibilityElements.GetCount() -1; index >= 0; index--)
846         {
847                 if ((__accessibilityElements.GetAt(index, pAccessibilityElement)) == E_SUCCESS)
848                 {
849                         if (pAccessibilityElement->GetBounds().Contains(point))
850                         {
851                                 return index;
852                         }
853                 }
854         }
855
856         return -1;
857 }
858
859 VisualElementAnimationGroup*
860 _DateTimeBar::CreateAnimationN(VisualElement& source, bool open)
861 {
862         FloatRectangle startValue = source.GetBounds();
863         VisualElementAnimationGroup* pAnimationGroup = new (std::nothrow) VisualElementAnimationGroup();
864         SysTryReturn(NID_UI_CTRL, pAnimationGroup, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
865
866         VisualElementPropertyAnimation* pOpacityAnimation = null;
867         VisualElementPropertyAnimation* pBoundsAnimation = null;
868         String* pUserData = null;
869
870         pAnimationGroup->SetDuration(ANIMATION_DURATION);
871
872         pOpacityAnimation = new (std::nothrow) VisualElementPropertyAnimation();
873         SysTryCatch(NID_UI_CTRL, (pOpacityAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
874
875         pOpacityAnimation->SetPropertyName("opacity");
876
877         if (open)
878         {
879                 pUserData = new (std::nothrow) String(L"BarOpenAnimation");
880                 SysTryCatch(NID_UI_CTRL, pUserData, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
881
882                 pOpacityAnimation->SetStartValue(Variant(0.0f));
883                 pOpacityAnimation->SetEndValue(Variant(1.0f));
884         }
885         else
886         {
887                 pUserData = new (std::nothrow) String(L"BarCloseAnimation");
888                 SysTryCatch(NID_UI_CTRL, pUserData, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
889
890                 pOpacityAnimation->SetStartValue(Variant(1.0f));
891                 pOpacityAnimation->SetEndValue(Variant(0.0f));
892         }
893         pOpacityAnimation->SetDuration(ANIMATION_DURATION);
894         pAnimationGroup->AddAnimation(*pOpacityAnimation);
895         delete pOpacityAnimation;
896         pOpacityAnimation = null;
897
898         pBoundsAnimation = new (std::nothrow) VisualElementPropertyAnimation();
899         SysTryCatch(NID_UI_CTRL, (pBoundsAnimation != null), , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
900
901         pBoundsAnimation->SetPropertyName(L"bounds.position");
902         startValue.y = startValue.y - POSITION_ANIMATION_VALUE;
903
904         if (open)
905         {
906                 pBoundsAnimation->SetStartValue(Variant(FloatPoint(startValue.x, startValue.y)));
907                 pBoundsAnimation->SetEndValue(Variant(FloatPoint(source.GetBounds().x, source.GetBounds().y)));
908                 pBoundsAnimation->SetUserData((void*)(pUserData));
909         }
910         else
911         {
912                 pBoundsAnimation->SetStartValue(Variant(FloatPoint(source.GetBounds().x, source.GetBounds().y)));
913                 pBoundsAnimation->SetEndValue(Variant(FloatPoint(startValue.x, startValue.y)));
914                 pBoundsAnimation->SetUserData((void*)(pUserData));
915         }
916         pBoundsAnimation->SetDuration(ANIMATION_DURATION);
917         pBoundsAnimation->SetVisualElementAnimationStatusEventListener(this);
918         pAnimationGroup->AddAnimation(*pBoundsAnimation);
919         delete pBoundsAnimation;
920         pBoundsAnimation = null;
921
922         return pAnimationGroup;
923
924 CATCH:
925         delete pAnimationGroup;
926         delete pOpacityAnimation;
927         delete pUserData;
928         return null;
929 }
930
931 void
932 _DateTimeBar::CloseDateTimeBar()
933 {
934         VisualElement* pVisualElement = null;
935         VisualElementAnimation *pAnimation = null;
936
937         __isAnimating = true;
938         pVisualElement = GetVisualElement();
939         SysTryReturnVoidResult(NID_UI_CTRL, pVisualElement != null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get visual element.");
940         pAnimation = CreateAnimationN(*pVisualElement, false);
941         SysTryReturnVoidResult(NID_UI_CTRL, pAnimation != null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
942         pVisualElement->AddAnimation(L"BarCloseAnimation", *pAnimation);
943
944         delete pAnimation;
945 }
946
947 void
948 _DateTimeBar::OnVisualElementAnimationFinished (const VisualElementAnimation &animation, const String &keyName, VisualElement &target, bool completedNormally)
949 {
950         String* pUserData = (String*) animation.GetUserData();
951
952         if ((pUserData != null) && (*pUserData == String(L"BarOpenAnimation")))
953         {
954                 RefreshItems();
955         }
956         else if ((pUserData != null) && (*pUserData == String(L"BarCloseAnimation")))
957         {
958                 FloatRectangle bounds = target.GetBounds();
959                 bounds.y = bounds.y + POSITION_ANIMATION_VALUE;
960                 SetVisibleState(false);
961                 Close();
962                 target.SetBounds(bounds);
963         }
964         __isAnimating = false;
965
966         delete pUserData;
967 }
968
969 }}} // Tizen::Ui::Controls