2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
19 * @file FUiCtrl_DateTimeBar.cpp
20 * @brief This is the implementation file for the _DateTimeBar class.
23 #include "FUiAnim_VisualElement.h"
24 #include "FUi_AccessibilityContainer.h"
25 #include "FUi_AccessibilityElement.h"
26 #include "FUi_ResourceManager.h"
27 #include "FUiCtrl_DateTimeBar.h"
28 #include "FUiCtrl_DateTimeBarPresenter.h"
29 #include "FUiCtrl_ActionEvent.h"
30 #include "FUiCtrl_Frame.h"
31 #include "FUiCtrl_Form.h"
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Media;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Ui::Animations;
39 namespace Tizen { namespace Ui { namespace Controls
41 _DateTimeBar::_DateTimeBar(void)
42 : __pDateTimeBarPresenter(null)
43 , __pActionEvent(null)
44 , __selectedBoxId(DATETIME_ID_NONE)
45 , __alignment(DATETIME_BAR_ALIGN_DOWN)
46 , __pDateTimeChangeEvent(null)
47 , __pGestureFlick(null)
48 , __parentWindowBounds(0, 0, 0, 0)
53 _DateTimeBar::~_DateTimeBar(void)
55 if (__pDateTimeChangeEvent != null)
57 delete __pDateTimeChangeEvent;
58 __pDateTimeChangeEvent = null;
63 delete __pActionEvent;
64 __pActionEvent = null;
67 delete __pDateTimeBarPresenter;
68 __pDateTimeBarPresenter = null;
70 delete __pGestureFlick;
71 __pGestureFlick = null;
73 RemoveAllAccessibilityElement();
79 _DateTimeBar::CreateDateTimeBarN(void)
84 _DateTimeBar* pDateTimeBar = new (std::nothrow) _DateTimeBar;
85 SysTryReturn(NID_UI_CTRL, pDateTimeBar != null, null, E_OUT_OF_MEMORY,
86 "[E_OUT_OF_MEMORY] Memory allocation failed.");
88 #if defined(MULTI_WINDOW)
89 r = pDateTimeBar->CreateRootVisualElement();
90 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
93 pDateTimeBar->__pDateTimeBarPresenter = _DateTimeBarPresenter::CreateInstanceN(*pDateTimeBar);
95 SysTryCatch(NID_UI_CTRL, pDateTimeBar->__pDateTimeBarPresenter != null, , r,
96 "[%s] Propagating.", GetErrorMessage(r));
98 pDateTimeBar->__pDateTimeChangeEvent = new (std::nothrow) _DateTimeChangeEvent(*pDateTimeBar);
99 SysTryCatch(NID_UI_CTRL, (pDateTimeBar->__pDateTimeChangeEvent != null), , E_OUT_OF_MEMORY,
100 "[E_OUT_OF_MEMORY] Memory allocation failed.");
102 pDateTimeBar->AcquireHandle();
104 if (pDateTimeBar->GetVisualElement() != null)
106 pDateTimeBar->GetVisualElement()->SetSurfaceOpaque(false);
109 pDateTimeBar->__pGestureFlick = new (std::nothrow) _TouchFlickGestureDetector();
110 SysTryCatch(NID_UI_CTRL, (pDateTimeBar->__pGestureFlick != null), , E_OUT_OF_MEMORY,
111 "[E_OUT_OF_MEMORY] Memory allocation failed.");
113 pDateTimeBar->AddGestureDetector(*(pDateTimeBar->__pGestureFlick));
114 SysTryCatch(NID_UI_CTRL, (GetLastResult() == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
116 r = pDateTimeBar->__pGestureFlick->AddGestureListener(*pDateTimeBar);
117 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
119 pDateTimeBar->InitializeAccessibilityElement();
128 _DateTimeBar::SetPositionAndAlignment(const Point& point, _DateTimeBarAlignment alignment)
132 result r = E_SUCCESS;
133 SetAlignment(alignment);
135 r = __pDateTimeBarPresenter->LoadArrowBitmap();
136 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
140 r = GET_SHAPE_CONFIG(DATETIMEBAR::ITEM_HEIGHT, GetOrientation(), height);
141 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
146 if (alignment == DATETIME_BAR_ALIGN_DOWN)
148 SetPosition(Point(point.x, point.y));
153 SetPosition(Point(point.x, point.y - height));
156 __pDateTimeBarPresenter->CalculateWindowBounds();
161 _DateTimeBarAlignment
162 _DateTimeBar::GetAlignment(void) const
168 _DateTimeBar::SetAlignment(_DateTimeBarAlignment alignment)
170 __alignment = alignment;
175 _DateTimeBar::OnDraw(void)
179 __pDateTimeBarPresenter->Draw();
184 _DateTimeBar::RemoveAllItems(void)
188 result r = E_SUCCESS;
190 r = __pDateTimeBarPresenter->RemoveAllItems();
191 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
197 _DateTimeBar::SetInitialValue(int minValue, int maxValue, int displayValue, _DateTimeId boxId)
201 result r = E_SUCCESS;
203 SetSelectedBoxId(boxId);
205 __pDateTimeBarPresenter->SetMinimumValue(minValue);
206 __pDateTimeBarPresenter->SetMaximumValue(maxValue);
208 r = __pDateTimeBarPresenter->AddItems(displayValue);
209 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
215 _DateTimeBar::GetSelectedBoxId(void) const
217 return __selectedBoxId;
221 _DateTimeBar::SetSelectedBoxId(_DateTimeId boxId)
223 __selectedBoxId = boxId;
229 _DateTimeBar::InitializeAccessibilityElement(void)
231 if (likely(!(_AccessibilityManager::IsActivated())))
236 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
240 pContainer->Activate(true);
241 pContainer->AddListener(*this);
248 _DateTimeBar::GetItemCount(void) const
252 return __pDateTimeBarPresenter->GetItemCount();
256 _DateTimeBar::AddActionEventListener(const _IActionEventListener& listener)
260 result r = E_SUCCESS;
262 if (__pActionEvent == null)
264 __pActionEvent = _ActionEvent::CreateInstanceN(*this);
265 SysTryReturn(NID_UI_CTRL, __pActionEvent != null, E_SYSTEM, E_SYSTEM,
266 "[%s] Propagating.", GetErrorMessage(r));
268 r = __pActionEvent->AddListener(listener);
269 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
275 _DateTimeBar::RemoveActionEventListener(const _IActionEventListener& listener)
279 result r = E_OBJ_NOT_FOUND;
283 r = __pActionEvent->RemoveListener(listener);
286 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
292 _DateTimeBar::AddDateTimeChangeEventListener(const _IDateTimeChangeEventListener& listener)
296 return __pDateTimeChangeEvent->AddListener(listener);
300 _DateTimeBar::RemoveDateTimeChangeEventListener(const _IDateTimeChangeEventListener& listener)
304 return __pDateTimeChangeEvent->RemoveListener(listener);
308 _DateTimeBar::FireDateTimeChangeEvent(_DateTimeChangeStatus status)
312 _DateTimeChangeEventArg* pDateTimeEventArg = new (std::nothrow) _DateTimeChangeEventArg(status);
313 SysTryReturn(NID_UI_CTRL, (pDateTimeEventArg != null), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
314 "[E_OUT_OF_MEMORY] Memory allocation failed.");
316 __pDateTimeChangeEvent->Fire(*pDateTimeEventArg);
322 _DateTimeBar::FireActionEvent(int actionId)
328 Tizen::Base::Runtime::IEventArg* pEventArg = _ActionEvent::CreateActionEventArgN(actionId);
329 result r = GetLastResult();
330 SysTryReturn(NID_UI_CTRL, pEventArg, false, r, "[%s] Propagating.", GetErrorMessage(r));
332 __pActionEvent->Fire(*pEventArg);
339 _DateTimeBar::CalculateArrowBounds(const Rectangle& bounds)
343 Rectangle arrowBounds(0, 0, 0, 0);
345 arrowBounds = __pDateTimeBarPresenter->GetArrowBounds();
346 arrowBounds.x = bounds.x + (bounds.width / 2) - (arrowBounds.width / 2);
347 arrowBounds.x -= __pDateTimeBarPresenter->GetWindowBounds().x;
349 __pDateTimeBarPresenter->SetArrowBounds(arrowBounds);
355 _DateTimeBar::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
359 return __pDateTimeBarPresenter->OnTouchPressed(source, touchinfo);
363 _DateTimeBar::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
367 return __pDateTimeBarPresenter->OnTouchReleased(source, touchinfo);
371 _DateTimeBar::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
375 return __pDateTimeBarPresenter->OnTouchMoved(source, touchinfo);
379 _DateTimeBar::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
383 return __pDateTimeBarPresenter->OnTouchCanceled(source, touchinfo);
387 _DateTimeBar::OnFlickGestureDetected(_TouchFlickGestureDetector& gesture)
391 gesture.GetDistance(xDistance, yDistance);
392 int duration = gesture.GetDuration();
394 return __pDateTimeBarPresenter->OnFlickGestureDetected(xDistance, yDistance, duration);
398 _DateTimeBar::OnFlickGestureCanceled(_TouchFlickGestureDetector& gesture)
404 _DateTimeBar::OnTouchMoveHandled(const Tizen::Ui::_Control& control)
408 return __pDateTimeBarPresenter->OnTouchMoveHandled(control);
412 _DateTimeBar::OnAttachingToMainTree(const _Control* pParent)
414 if (GetOwner() == null)
416 _Frame* pFrame = dynamic_cast<_Frame*>(_ControlManager::GetInstance()->GetCurrentFrame());
417 SysTryReturn(NID_UI_CTRL, pFrame != null, E_SYSTEM,
418 E_SYSTEM, "[E_SYSTEM] This instance is not constructed.");
420 _Form* pForm = pFrame->GetCurrentForm();
431 return _Window::OnAttachingToMainTree(pParent);
435 _DateTimeBar::OnAttachedToMainTree(void)
437 _Window::OnAttachedToMainTree();
442 _DateTimeBar::OnDetachingFromMainTree(void)
444 return _Window::OnDetachingFromMainTree();
448 _DateTimeBar::OnActivated(void)
450 _Window::OnActivated();
454 if (GetSelectedBoxId() == DATETIME_ID_MONTH)
456 GET_SHAPE_CONFIG(DATETIMEBAR::MONTH_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
458 else if (GetSelectedBoxId() == DATETIME_ID_YEAR)
460 GET_SHAPE_CONFIG(DATETIMEBAR::YEAR_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
464 GET_SHAPE_CONFIG(DATETIMEBAR::DAY_ITEM_WIDTH, _ControlManager::GetInstance()->GetOrientation(), itemWidth);
467 __pDateTimeBarPresenter->SetInitialAnimationValue(itemWidth);
469 __pDateTimeBarPresenter->StartAnimationEffect();
476 _DateTimeBar::OnDeactivated(void)
478 ReleaseTouchCapture();
479 _Window::OnDeactivated();
484 _DateTimeBar::AddAccessibilityElement(const Rectangle& itemBounds, const Tizen::Base::String& itemText)
486 if (likely(!(_AccessibilityManager::IsActivated())))
491 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
494 _AccessibilityElement* pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
495 SysTryReturnVoidResult(NID_UI_CTRL, pAccessibilityElement != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
497 String labelText = itemText;
498 pAccessibilityElement->SetBounds(itemBounds);
499 pAccessibilityElement->SetLabel(labelText);
500 pAccessibilityElement->SetTrait(GetAccessibilityTraitValue());
501 pContainer->AddElement(*pAccessibilityElement);
502 __accessibilityElements.Add(pAccessibilityElement);
509 _DateTimeBar::RemoveAllAccessibilityElement(void)
511 if (likely(!(_AccessibilityManager::IsActivated())))
516 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
518 if (pContainer == null)
523 _AccessibilityElement* pAccessibilityElement = null;
525 while (__accessibilityElements.GetCount() > 0)
527 if ((__accessibilityElements.GetAt(0, pAccessibilityElement)) == E_SUCCESS)
529 __accessibilityElements.RemoveAt(0);
530 pContainer->RemoveElement(*pAccessibilityElement);
534 __accessibilityElements.RemoveAt(0);
542 _DateTimeBar::GetAccessibilityTraitValue()
544 AccessibilityTraits traitsValue = ACCESSIBILITY_TRAITS_NONE;
546 if (GetSelectedBoxId() == DATETIME_ID_DAY)
548 traitsValue = ACCESSIBILITY_TRAITS_DAY;
550 else if (GetSelectedBoxId() == DATETIME_ID_MONTH)
552 traitsValue = ACCESSIBILITY_TRAITS_MONTH;
554 else if (GetSelectedBoxId() == DATETIME_ID_YEAR)
556 traitsValue = ACCESSIBILITY_TRAITS_YEAR;
558 else if (GetSelectedBoxId() == DATETIME_ID_HOUR)
560 traitsValue = ACCESSIBILITY_TRAITS_HOUR;
562 else if (GetSelectedBoxId() == DATETIME_ID_MINUTE)
564 traitsValue = ACCESSIBILITY_TRAITS_MINUTE;
571 _DateTimeBar::GetMonthValue(int month) const
578 monthValue = L"January";
581 monthValue = L"February";
584 monthValue = L"March";
587 monthValue = L"April";
593 monthValue = L"June";
596 monthValue = L"July";
599 monthValue = L"August";
602 monthValue = L"September";
605 monthValue = L"October";
608 monthValue = L"November";
611 monthValue = L"December";
621 _DateTimeBar::SetFont(Font& pFont)
623 __pDateTimeBarPresenter->SetFont(pFont);
629 _DateTimeBar::SetParentWindowBounds(Rectangle& parentWindowBounds)
631 __parentWindowBounds = parentWindowBounds;
636 _DateTimeBar::GetParentWindowBounds() const
638 return __parentWindowBounds;
642 _DateTimeBar::OnAccessibilityFocusMovedNext(const _AccessibilityContainer& control, const _AccessibilityElement& element)
644 return __pDateTimeBarPresenter->OnAccessibilityFocusMovedNext(control, element);
648 _DateTimeBar::OnAccessibilityFocusMovedPrevious(const _AccessibilityContainer& control, const _AccessibilityElement& element)
650 return __pDateTimeBarPresenter->OnAccessibilityFocusMovedPrevious(control, element);
654 _DateTimeBar::OnAccessibilityReadElement(const _AccessibilityContainer& control, const _AccessibilityElement& element)
660 _DateTimeBar::OnAccessibilityFocusIn(const _AccessibilityContainer& control, const _AccessibilityElement& element)
666 _DateTimeBar::OnAccessibilityFocusOut(const _AccessibilityContainer& control, const _AccessibilityElement& element)
672 _DateTimeBar::OnAccessibilityActionPerformed(const _AccessibilityContainer& control, const _AccessibilityElement& element)
678 _DateTimeBar::OnAccessibilityValueIncreased(const Tizen::Ui::_AccessibilityContainer&, const Tizen::Ui::_AccessibilityElement&)
684 _DateTimeBar::OnAccessibilityValueDecreased(const Tizen::Ui::_AccessibilityContainer&, const Tizen::Ui::_AccessibilityElement&)
689 }}} // Tizen::Ui::Controls