Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_InputPad.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_InputPad.cpp
20  * @brief               This is the implementation file for the _InputPad class.
21  */
22
23 #include <FBaseColIEnumeratorT.h>
24
25 #include "FUiCtrl_InputPad.h"
26 #include "FUiCtrl_InputPadPresenter.h"
27 #include "FUi_AccessibilityContainer.h"
28 #include "FUi_AccessibilityElement.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Graphics;
33 using namespace Tizen::Ui;
34
35 const int INPUTPAD_BUTTON_MAX = 12;
36
37 namespace Tizen { namespace Ui { namespace Controls
38 {
39
40 _InputPad::_InputPad(void)
41         : __pInputPadPresenter(null)
42 {
43         ClearLastResult();
44 }
45
46 _InputPad::~_InputPad(void)
47 {
48         delete __pInputPadPresenter;
49         __pInputPadPresenter = null;
50
51         RemoveAllAccessibilityElement();
52
53         ClearLastResult();
54 }
55
56 result
57 _InputPad::Construct(const FloatRectangle& bounds)
58 {
59         result r = E_SUCCESS;
60
61         SetBounds(bounds);
62
63         __pInputPadPresenter = new (std::nothrow) _InputPadPresenter(this);
64         SysTryReturnResult(NID_UI_CTRL, __pInputPadPresenter, E_OUT_OF_MEMORY, "Memory allocation failed.");
65
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");
69
70         AcquireHandle();
71
72         if(likely((_AccessibilityManager::IsActivated())))
73         {
74                 _AccessibilityContainer* pContainer = GetAccessibilityContainer();
75                 if (pContainer != null)
76                 {
77                         InitializeAccessibilityElementMonthNames();
78                         pContainer->SetPriority(ACCESSIBILITY_PRIORITY_KEYPAD);
79                         pContainer->Activate(true);
80                 }
81         }
82
83         ClearLastResult();
84
85         return r;
86
87 CATCH:
88         delete __pInputPadPresenter;
89         __pInputPadPresenter = null;
90
91         return r;
92 }
93
94 result
95 _InputPad::SetInputPadEventListener(const _IInputPadEventListener& listener)
96 {
97         ClearLastResult();
98
99         SysAssertf((__pInputPadPresenter != null), "The instance of InputpadPresenter is not yet constructed.");
100
101         __pInputPadPresenter->SetInputPadEventListener(listener);
102
103         return E_SUCCESS;
104 }
105
106 void
107 _InputPad::SetInputPadStyle(const _InputPadStyle style)
108 {
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.");
111
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.");
114
115         if (style == __pInputPadPresenter->GetInputPadStyle())
116         {
117                 if (HasAccessibilityElement() == true)
118                 {
119                         return;
120                 }
121         }
122         else
123         {
124                 RemoveAllAccessibilityElement();
125         }
126
127         __pInputPadPresenter->SetInputPadStyle(style);
128         SetAllAccessibilityElement();
129
130         return;
131 }
132
133 String&
134 _InputPad::GetAccessibilityElementMonthName(int number)
135 {
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.");
138
139         return __pMonthNames[number];
140 }
141
142 void
143 _InputPad::SetFont(Font* pFont)
144 {
145         __pInputPadPresenter->SetFont(pFont);
146
147         return;
148 }
149
150 void
151 _InputPad::OnBoundsChanged(void)
152 {
153         if (__pInputPadPresenter != null)
154         {
155                 __pInputPadPresenter->LoadProperties(GetOrientation());
156                 SetBoundsAllAccessibilityElement();
157         }
158
159         return;
160 }
161
162 void
163 _InputPad::OnDraw(void)
164 {
165         __pInputPadPresenter->Draw();
166
167         return;
168 }
169
170 bool
171 _InputPad::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
172 {
173         return __pInputPadPresenter->OnTouchPressed(source, touchinfo);
174 }
175
176 bool
177 _InputPad::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
178 {
179         return __pInputPadPresenter->OnTouchReleased(source, touchinfo);
180 }
181
182 bool
183 _InputPad::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
184 {
185         return __pInputPadPresenter->OnTouchCanceled(source, touchinfo);
186 }
187
188 void
189 _InputPad::OnChangeLayout(_ControlOrientation orientation)
190 {
191         if (__pInputPadPresenter != null)
192         {
193                 __pInputPadPresenter->EnableLayoutChangedFlag();
194                 __pInputPadPresenter->LoadProperties(orientation);
195                 __pInputPadPresenter->SetInputPadStyle(__pInputPadPresenter->GetInputPadStyle());
196                 SetBoundsAllAccessibilityElement();
197         }
198
199         return;
200 }
201
202 bool
203 _InputPad::HasAccessibilityElement(void)
204 {
205         return __accessibilityElements.GetCount() > 0;
206 }
207
208 void
209 _InputPad::SetAllAccessibilityElement(void)
210 {
211         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
212         if (pContainer != null)
213         {
214                 pContainer->RemoveAllElement();
215
216                 for (int index = 0; index < INPUTPAD_BUTTON_MAX; index++)
217                 {
218                         int returnValue = __pInputPadPresenter->GetReturnValue(index);
219                         if (returnValue >= 0)
220                         {
221                                 _AccessibilityElement* pElement = new _AccessibilityElement(true);
222                                 if (pElement != null)
223                                 {
224                                         if (__pInputPadPresenter->GetInputPadStyle() == INPUTPAD_STYLE_ALPHA)
225                                         {
226                                                 pElement->SetLabel(__pMonthNames[index]);
227                                         }
228                                         else
229                                         {
230                                                 pElement->SetLabel(Integer::ToString(returnValue));
231                                         }
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);
237                                 }
238                         }
239                 }
240         }
241
242         return;
243 }
244
245 void
246 _InputPad::SetBoundsAllAccessibilityElement(void)
247 {
248         if(likely(!(_AccessibilityManager::IsActivated())))
249         {
250                 return;
251         }
252
253         _AccessibilityElement* pElement = null;
254         IEnumeratorT<_AccessibilityElement*>* pEnumerator = __accessibilityElements.GetEnumeratorN();
255         int index = 0;
256         while (pEnumerator->MoveNext() == E_SUCCESS)
257         {
258                 if (pEnumerator->GetCurrent(pElement) == E_SUCCESS)
259                 {
260                         while (__pInputPadPresenter->GetReturnValue(index) < 0)
261                         {
262                                 index++;
263                         }
264                         pElement->SetBounds(__pInputPadPresenter->GetButtonBounds(index));
265                 }
266                 index++;
267         }
268         delete pEnumerator;
269
270         return;
271 }
272
273 void
274 _InputPad::RemoveAllAccessibilityElement(void)
275 {
276         _AccessibilityElement* pElement = null;
277         while (HasAccessibilityElement() == true)
278         {
279                 if ((__accessibilityElements.GetAt(0, pElement)) == E_SUCCESS)
280                 {
281                         __accessibilityElements.RemoveAt(0);
282                         pElement->GetParent()->RemoveElement(*pElement);
283                 }
284                 else
285                 {
286                         __accessibilityElements.RemoveAt(0);
287                 }
288         }
289
290         return;
291 }
292
293 void
294 _InputPad::InitializeAccessibilityElementMonthNames(void)
295 {
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";
308
309         return;
310 }
311
312 }}} // Tizen::Ui::Controls