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_InputPad.cpp
20 * @brief This is the implementation file for the _InputPad class.
23 #include <FBaseColIEnumeratorT.h>
25 #include "FUiCtrl_InputPad.h"
26 #include "FUiCtrl_InputPadPresenter.h"
27 #include "FUi_AccessibilityContainer.h"
28 #include "FUi_AccessibilityElement.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Ui;
35 const int INPUTPAD_BUTTON_MAX = 12;
37 namespace Tizen { namespace Ui { namespace Controls
40 _InputPad::_InputPad(void)
41 : __pInputPadPresenter(null)
46 _InputPad::~_InputPad(void)
48 delete __pInputPadPresenter;
49 __pInputPadPresenter = null;
51 RemoveAllAccessibilityElement();
57 _InputPad::Construct(const Rectangle& bounds)
61 if(likely((_AccessibilityManager::IsActivated())))
63 InitializeAccessebilityElementMonthNames();
68 __pInputPadPresenter = new (std::nothrow) _InputPadPresenter(this);
69 SysTryReturnResult(NID_UI_CTRL, __pInputPadPresenter, E_OUT_OF_MEMORY, "Memory allocation failed.");
71 r = __pInputPadPresenter->Construct(bounds);
72 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM,
73 "[E_SYSTEM] A system error has occurred. Failed to construct the instance of presenter for Inputpad");
77 if(likely((_AccessibilityManager::IsActivated())))
79 if (GetAccessibilityContainer() != null)
81 GetAccessibilityContainer()->Activate(true);
90 delete __pInputPadPresenter;
91 __pInputPadPresenter = null;
97 _InputPad::SetInputPadEventListener(const _IInputPadEventListener& listener)
101 SysAssertf((__pInputPadPresenter != null), "The instance of InputpadPresenter is not yet constructed.");
103 __pInputPadPresenter->SetInputPadEventListener(listener);
109 _InputPad::SetInputPadStyle(const _InputPadStyle style)
111 SysTryReturnVoidResult(NID_UI_CTRL, (style >= INPUTPAD_STYLE_NORMAL), E_INVALID_ARG,
112 "[E_INVALID_ARG] Invalid argument(s) is used. The style provided is not present in the _InputPadStyle list.");
114 SysTryReturnVoidResult(NID_UI_CTRL, (style < INPUTPAD_STYLE_MAX), E_INVALID_ARG,
115 "[E_INVALID_ARG] Invalid argument(s) is used. The style provided is not a valid _InputPadStyle value.");
117 if (style == __pInputPadPresenter->GetInputPadStyle())
119 if (HasAccessibilityElement() == true)
126 RemoveAllAccessibilityElement();
129 __pInputPadPresenter->SetInputPadStyle(style);
130 SetAllAccessibilityElement();
136 _InputPad::GetAccessebilityElementMonthName(int number)
138 SysTryReturn(NID_UI_CTRL, (number >= 0), __pMonthNames[0], E_SYSTEM,
139 "[E_SYSTEM] A system error has occurred. Failed to get the month name.");
141 return __pMonthNames[number];
145 _InputPad::SetFont(Font* pFont)
147 __pInputPadPresenter->SetFont(pFont);
153 _InputPad::OnBoundsChanged(void)
155 if (__pInputPadPresenter != null)
157 __pInputPadPresenter->LoadProperties(GetOrientation());
158 SetBoundsAllAccessibilityElement();
165 _InputPad::OnDraw(void)
167 __pInputPadPresenter->Draw();
173 _InputPad::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
175 return __pInputPadPresenter->OnTouchPressed(source, touchinfo);
179 _InputPad::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
181 return __pInputPadPresenter->OnTouchReleased(source, touchinfo);
185 _InputPad::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
187 return __pInputPadPresenter->OnTouchCanceled(source, touchinfo);
191 _InputPad::OnChangeLayout(_ControlOrientation orientation)
193 if (__pInputPadPresenter != null)
195 __pInputPadPresenter->EnableLayoutChangedFlag();
196 __pInputPadPresenter->LoadProperties(orientation);
197 __pInputPadPresenter->SetInputPadStyle(__pInputPadPresenter->GetInputPadStyle());
198 SetBoundsAllAccessibilityElement();
205 _InputPad::HasAccessibilityElement(void)
207 return __accessibilityElements.GetCount() > 0;
211 _InputPad::SetAllAccessibilityElement(void)
213 if(likely(!(_AccessibilityManager::IsActivated())))
218 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
219 if (pContainer != null)
221 pContainer->RemoveAllElement();
223 for (int index = 0; index < INPUTPAD_BUTTON_MAX; index++)
225 int returnValue = __pInputPadPresenter->GetReturnValue(index);
226 if (returnValue >= 0)
228 _AccessibilityElement* pElement = new _AccessibilityElement(true);
229 if (pElement != null)
231 if (__pInputPadPresenter->GetInputPadStyle() == INPUTPAD_STYLE_ALPHA)
233 pElement->SetLabel(__pMonthNames[index]);
237 pElement->SetLabel(Integer::ToString(returnValue));
239 pElement->SetTrait(ACCESSIBILITY_TRAITS_NONE);
240 // pElement->SetTrait(ACCESSIBILITY_TRAITS_INPUTPAD);
241 pElement->SetBounds(__pInputPadPresenter->GetButtonBounds(index));
242 pContainer->AddElement(*pElement);
243 __accessibilityElements.Add(pElement);
253 _InputPad::SetBoundsAllAccessibilityElement(void)
255 if(likely(!(_AccessibilityManager::IsActivated())))
260 _AccessibilityElement* pElement = null;
261 IEnumeratorT<_AccessibilityElement*>* pEnumerator = __accessibilityElements.GetEnumeratorN();
263 while (pEnumerator->MoveNext() == E_SUCCESS)
265 if (pEnumerator->GetCurrent(pElement) == E_SUCCESS)
267 while (__pInputPadPresenter->GetReturnValue(index) < 0)
271 pElement->SetBounds(__pInputPadPresenter->GetButtonBounds(index));
281 _InputPad::RemoveAllAccessibilityElement(void)
283 if(likely(!(_AccessibilityManager::IsActivated())))
288 _AccessibilityElement* pElement = null;
289 while (HasAccessibilityElement() == true)
291 if ((__accessibilityElements.GetAt(0, pElement)) == E_SUCCESS)
293 __accessibilityElements.RemoveAt(0);
294 pElement->GetParent()->RemoveElement(*pElement);
298 __accessibilityElements.RemoveAt(0);
306 _InputPad::InitializeAccessebilityElementMonthNames(void)
308 __pMonthNames[0] = L"January";
309 __pMonthNames[1] = L"February";
310 __pMonthNames[2] = L"March";
311 __pMonthNames[3] = L"April";
312 __pMonthNames[4] = L"May";
313 __pMonthNames[5] = L"June";
314 __pMonthNames[6] = L"July";
315 __pMonthNames[7] = L"August";
316 __pMonthNames[8] = L"September";
317 __pMonthNames[9] = L"October";
318 __pMonthNames[10] = L"November";
319 __pMonthNames[11] = L"December";
324 }}} // Tizen::Ui::Controls