2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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 FloatRectangle& bounds)
63 __pInputPadPresenter = new (std::nothrow) _InputPadPresenter(this);
64 SysTryReturnResult(NID_UI_CTRL, __pInputPadPresenter, E_OUT_OF_MEMORY, "Memory allocation failed.");
66 r = __pInputPadPresenter->Construct(bounds);
67 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM,
68 "[E_SYSTEM] A system error has occurred. Failed to construct the instance of presenter for Inputpad");
72 if(likely((_AccessibilityManager::IsActivated())))
74 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
75 if (pContainer != null)
77 InitializeAccessibilityElementMonthNames();
78 pContainer->SetPriority(ACCESSIBILITY_PRIORITY_KEYPAD);
79 pContainer->Activate(true);
88 delete __pInputPadPresenter;
89 __pInputPadPresenter = null;
95 _InputPad::SetInputPadEventListener(const _IInputPadEventListener& listener)
99 SysAssertf((__pInputPadPresenter != null), "The instance of InputpadPresenter is not yet constructed.");
101 __pInputPadPresenter->SetInputPadEventListener(listener);
107 _InputPad::SetInputPadStyle(const _InputPadStyle style)
109 SysTryReturnVoidResult(NID_UI_CTRL, (style >= INPUTPAD_STYLE_NORMAL), E_INVALID_ARG,
110 "[E_INVALID_ARG] Invalid argument(s) is used. The style provided is not present in the _InputPadStyle list.");
112 SysTryReturnVoidResult(NID_UI_CTRL, (style < INPUTPAD_STYLE_MAX), E_INVALID_ARG,
113 "[E_INVALID_ARG] Invalid argument(s) is used. The style provided is not a valid _InputPadStyle value.");
115 if (style == __pInputPadPresenter->GetInputPadStyle())
117 if (HasAccessibilityElement() == true)
124 RemoveAllAccessibilityElement();
127 __pInputPadPresenter->SetInputPadStyle(style);
128 SetAllAccessibilityElement();
134 _InputPad::GetAccessibilityElementMonthName(int number)
136 SysTryReturn(NID_UI_CTRL, (number >= 0), __pMonthNames[0], E_SYSTEM,
137 "[E_SYSTEM] A system error has occurred. Failed to get the month name.");
139 return __pMonthNames[number];
143 _InputPad::SetFont(Font* pFont)
145 __pInputPadPresenter->SetFont(pFont);
151 _InputPad::OnBoundsChanged(void)
153 if (__pInputPadPresenter != null)
155 __pInputPadPresenter->LoadProperties(GetOrientation());
156 SetBoundsAllAccessibilityElement();
163 _InputPad::OnDraw(void)
165 __pInputPadPresenter->Draw();
171 _InputPad::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
173 return __pInputPadPresenter->OnTouchPressed(source, touchinfo);
177 _InputPad::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
179 return __pInputPadPresenter->OnTouchReleased(source, touchinfo);
183 _InputPad::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
185 return __pInputPadPresenter->OnTouchCanceled(source, touchinfo);
189 _InputPad::OnChangeLayout(_ControlOrientation orientation)
191 if (__pInputPadPresenter != null)
193 __pInputPadPresenter->EnableLayoutChangedFlag();
194 __pInputPadPresenter->LoadProperties(orientation);
195 __pInputPadPresenter->SetInputPadStyle(__pInputPadPresenter->GetInputPadStyle());
196 SetBoundsAllAccessibilityElement();
203 _InputPad::HasAccessibilityElement(void)
205 return __accessibilityElements.GetCount() > 0;
209 _InputPad::SetAllAccessibilityElement(void)
211 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
212 if (pContainer != null)
214 pContainer->RemoveAllElement();
216 for (int index = 0; index < INPUTPAD_BUTTON_MAX; index++)
218 int returnValue = __pInputPadPresenter->GetReturnValue(index);
219 if (returnValue >= 0)
221 _AccessibilityElement* pElement = new _AccessibilityElement(true);
222 if (pElement != null)
224 if (__pInputPadPresenter->GetInputPadStyle() == INPUTPAD_STYLE_ALPHA)
226 pElement->SetLabel(__pMonthNames[index]);
230 pElement->SetLabel(Integer::ToString(returnValue));
232 pElement->SetTrait(ACCESSIBILITY_TRAITS_NONE);
233 // pElement->SetTrait(ACCESSIBILITY_TRAITS_INPUTPAD);
234 pElement->SetBounds(__pInputPadPresenter->GetButtonBounds(index));
235 pContainer->AddElement(*pElement);
236 __accessibilityElements.Add(pElement);
246 _InputPad::SetBoundsAllAccessibilityElement(void)
248 if(likely(!(_AccessibilityManager::IsActivated())))
253 _AccessibilityElement* pElement = null;
254 IEnumeratorT<_AccessibilityElement*>* pEnumerator = __accessibilityElements.GetEnumeratorN();
256 while (pEnumerator->MoveNext() == E_SUCCESS)
258 if (pEnumerator->GetCurrent(pElement) == E_SUCCESS)
260 while (__pInputPadPresenter->GetReturnValue(index) < 0)
264 pElement->SetBounds(__pInputPadPresenter->GetButtonBounds(index));
274 _InputPad::RemoveAllAccessibilityElement(void)
276 _AccessibilityElement* pElement = null;
277 while (HasAccessibilityElement() == true)
279 if ((__accessibilityElements.GetAt(0, pElement)) == E_SUCCESS)
281 __accessibilityElements.RemoveAt(0);
282 pElement->GetParent()->RemoveElement(*pElement);
286 __accessibilityElements.RemoveAt(0);
294 _InputPad::InitializeAccessibilityElementMonthNames(void)
296 __pMonthNames[0] = L"January";
297 __pMonthNames[1] = L"February";
298 __pMonthNames[2] = L"March";
299 __pMonthNames[3] = L"April";
300 __pMonthNames[4] = L"May";
301 __pMonthNames[5] = L"June";
302 __pMonthNames[6] = L"July";
303 __pMonthNames[7] = L"August";
304 __pMonthNames[8] = L"September";
305 __pMonthNames[9] = L"October";
306 __pMonthNames[10] = L"November";
307 __pMonthNames[11] = L"December";
312 }}} // Tizen::Ui::Controls