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