Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / controls / FUiCtrl_KeypadImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
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 * @file                 FUiCtrl_KeypadImpl.cpp
19 * @brief                This file contains implementation of _KeypadImpl class
20 *
21 * This file contains implementation of _KeypadImpl class.
22 */
23
24 #include "FUi_ControlImplManager.h"
25 #include "FUiCtrl_Edit.h"
26 #include "FUiCtrl_KeypadImpl.h"
27 #include "FUiCtrl_Keypad.h"
28 #include "FUiCtrl_PublicTextEvent.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Runtime;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
34
35 namespace Tizen { namespace Ui { namespace Controls
36 {
37
38 _KeypadImpl*
39 _KeypadImpl::GetInstance(Keypad& keypad)
40 {
41         return (static_cast<_KeypadImpl*> (keypad._pControlImpl));
42 }
43
44 const _KeypadImpl*
45 _KeypadImpl::GetInstance(const Keypad& keypad)
46 {
47         return (static_cast<const _KeypadImpl*> (keypad._pControlImpl));
48 }
49
50 _KeypadImpl::_KeypadImpl(Keypad* pPublic, _Keypad* pCore)
51         : _WindowImpl(pPublic, pCore)
52         , __pKeypad(pCore)
53         , __limitLength(0)
54         , __pTextEvent(null)
55         , __pPublicTextEvent(null)
56 {
57         __keypadStyleInfo.keypadStyle = KEYPAD_STYLE_NORMAL;
58         __keypadStyleInfo.textPredictionEnabled = false;
59         __keypadStyleInfo.isNormalNumberStyle = false;
60         __keypadStyleInfo.enterActionEnabled = true;
61         __keypadStyleInfo.isLowerCaseModeEnabled = false;
62 }
63
64 _KeypadImpl::~_KeypadImpl(void)
65 {
66         if (__pPublicTextEvent)
67         {
68                 delete __pPublicTextEvent;
69                 __pPublicTextEvent = null;
70         }
71 }
72
73 _KeypadImpl*
74 _KeypadImpl::CreateKeypadImplN(Keypad* pControl)
75 {
76         ClearLastResult();
77         result r = E_SUCCESS;
78         _Keypad* pCore = null;
79
80         pCore = _Keypad::CreateKeypadN();
81         SysTryReturn(NID_UI_CTRL, pCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
82
83         _KeypadImpl* pImpl = new (std::nothrow) _KeypadImpl(pControl, pCore);
84         r = CheckConstruction(pCore, pImpl);
85         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
86
87         return pImpl;
88 }
89
90 const char*
91 _KeypadImpl::GetPublicClassName(void) const
92 {
93         return "Tizen::Ui::Controls::Keypad";
94 }
95
96 const Keypad&
97 _KeypadImpl::GetPublic(void) const
98 {
99         return static_cast <const Keypad&>(_ControlImpl::GetPublic());
100 }
101
102 Keypad&
103 _KeypadImpl::GetPublic(void)
104 {
105         return static_cast <Keypad&>(_ControlImpl::GetPublic());
106 }
107
108 const _Keypad&
109 _KeypadImpl::GetCore(void) const
110 {
111         return static_cast <const _Keypad&>(_ControlImpl::GetCore());
112 }
113
114 _Keypad&
115 _KeypadImpl::GetCore(void)
116 {
117         return static_cast <_Keypad&>(_ControlImpl::GetCore());
118 }
119
120 result
121 _KeypadImpl::Initialize(KeypadStyle keypadStyle, KeypadInputModeCategory category, int limitLength, bool enabledTextPrediction)
122 {
123         result r = E_SUCCESS;
124         ClearLastResult();
125
126         __keypadStyleInfo.keypadStyle = keypadStyle;
127         __keypadStyleInfo.textPredictionEnabled = enabledTextPrediction;
128         if ((keypadStyle == KEYPAD_STYLE_NORMAL) && (category & (KEYPAD_MODE_NUMERIC | KEYPAD_MODE_SYMBOL)))
129         {
130                 __keypadStyleInfo.isNormalNumberStyle = true;
131         }
132         else
133         {
134                 __keypadStyleInfo.isNormalNumberStyle = false;
135         }
136
137         __limitLength = limitLength;
138
139         __pKeypad->SetResizable(false);
140         __pKeypad->SetMovable(false);
141
142         SysTryReturn(NID_UI_CTRL, (__pPublicTextEvent == null), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] This instance is already constructed.");
143         __pPublicTextEvent = _PublicTextEvent::CreateInstanceN(GetPublic());
144         SysTryReturn(NID_UI_CTRL, __pPublicTextEvent, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] System error occurred.");
145
146         r = __pKeypad->AddTextEventListener(*this);
147         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
148
149         return r;
150 }
151
152 void
153 _KeypadImpl::SetTextPredictionEnabled(bool enable)
154 {
155         __keypadStyleInfo.textPredictionEnabled = enable;
156 }
157
158 bool
159 _KeypadImpl::IsTextPredictionEnabled(void) const
160 {
161         return __keypadStyleInfo.textPredictionEnabled;
162 }
163
164 result
165 _KeypadImpl::SetSingleLineEnabled(bool enabled)
166 {
167         ClearLastResult();
168
169         if ((__keypadStyleInfo.keypadStyle == KEYPAD_STYLE_PASSWORD) && (enabled == false))
170         {
171                 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] The password style can't support multiline.");
172                 return E_UNSUPPORTED_OPERATION;
173         }
174         SysTryReturnResult(NID_UI_CTRL, __pKeypad->IsActivated() == false, E_INVALID_OPERATION, "Keypad is already shown.");
175
176         Variant var(enabled);
177         return __pKeypad->SetPropertySingleLineEnabled(var);
178 }
179
180 bool
181 _KeypadImpl::IsSingleLineEnabled(void) const
182 {
183         ClearLastResult();
184         return __pKeypad->GetPropertySingleLineEnabled().ToBool();
185 }
186
187 result
188 _KeypadImpl::AddTextEventListener(ITextEventListener& listener)
189 {
190         ClearLastResult();
191         return __pPublicTextEvent->AddListener(listener);
192 }
193
194 result
195 _KeypadImpl::RemoveTextEventListener(ITextEventListener& listener)
196 {
197         ClearLastResult();
198         return __pPublicTextEvent->RemoveListener(listener);
199 }
200
201 result
202 _KeypadImpl::OnAttachedToMainTree(void)
203 {
204         ClearLastResult();
205
206         result r = E_SUCCESS;
207         int editStyle = EDIT_STYLE_NORMAL;
208
209         if (IsSingleLineEnabled())
210         {
211                 editStyle |= EDIT_STYLE_SINGLE_LINE;
212         }
213
214         if (__keypadStyleInfo.keypadStyle == KEYPAD_STYLE_PASSWORD)
215         {
216                 editStyle |= EDIT_STYLE_PASSWORD | EDIT_STYLE_SINGLE_LINE;
217         }
218
219         String text = GetText();
220
221         r = __pKeypad->Initialize(editStyle, __keypadStyleInfo, __limitLength, null);
222         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
223
224
225         SetText(text);
226
227         r = _WindowImpl::OnAttachedToMainTree();
228         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
229
230         return r;
231 }
232
233 String
234 _KeypadImpl::GetText(void) const
235 {
236         ClearLastResult();
237
238         return __pKeypad->GetPropertyText().ToString();
239 }
240
241 void
242 _KeypadImpl::SetText(const String& text)
243 {
244         ClearLastResult();
245
246         Variant var(text);
247         __pKeypad->SetPropertyText(var);
248         return;
249 }
250
251 void
252 _KeypadImpl::OnTextValueChanged(const _Control& source)
253 {
254         IEventArg* pEventArg = _PublicTextEvent::CreateTextEventArgN(TEXT_EVENT_CHANGED);
255         if (pEventArg)
256         {
257                 __pPublicTextEvent->Fire(*pEventArg);
258         }
259 }
260
261 void
262 _KeypadImpl::OnTextValueChangeCanceled(const _Control& source)
263 {
264         IEventArg* pEventArg = _PublicTextEvent::CreateTextEventArgN(TEXT_EVENT_CANCELED);
265         if (pEventArg)
266         {
267                 __pPublicTextEvent->Fire(*pEventArg);
268         }
269 }
270
271 }}} // Tizen::Ui::Controls