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.
18 * @file FUiCtrl_KeypadImpl.cpp
19 * @brief This file contains implementation of _KeypadImpl class
21 * This file contains implementation of _KeypadImpl class.
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"
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Runtime;
32 using namespace Tizen::Ui;
33 using namespace Tizen::Ui::Controls;
35 namespace Tizen { namespace Ui { namespace Controls
39 _KeypadImpl::GetInstance(Keypad& keypad)
41 return (static_cast<_KeypadImpl*> (keypad._pControlImpl));
45 _KeypadImpl::GetInstance(const Keypad& keypad)
47 return (static_cast<const _KeypadImpl*> (keypad._pControlImpl));
50 _KeypadImpl::_KeypadImpl(Keypad* pPublic, _Keypad* pCore)
51 : _WindowImpl(pPublic, pCore)
55 , __pPublicTextEvent(null)
57 __keypadStyleInfo.keypadStyle = KEYPAD_STYLE_NORMAL;
58 __keypadStyleInfo.textPredictionEnabled = false;
59 __keypadStyleInfo.isNormalNumberStyle = false;
60 __keypadStyleInfo.enterActionEnabled = true;
61 __keypadStyleInfo.isLowerCaseModeEnabled = false;
64 _KeypadImpl::~_KeypadImpl(void)
66 if (__pPublicTextEvent)
68 delete __pPublicTextEvent;
69 __pPublicTextEvent = null;
74 _KeypadImpl::CreateKeypadImplN(Keypad* pControl)
78 _Keypad* pCore = null;
80 pCore = _Keypad::CreateKeypadN();
81 SysTryReturn(NID_UI_CTRL, pCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
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));
91 _KeypadImpl::GetPublicClassName(void) const
93 return "Tizen::Ui::Controls::Keypad";
97 _KeypadImpl::GetPublic(void) const
99 return static_cast <const Keypad&>(_ControlImpl::GetPublic());
103 _KeypadImpl::GetPublic(void)
105 return static_cast <Keypad&>(_ControlImpl::GetPublic());
109 _KeypadImpl::GetCore(void) const
111 return static_cast <const _Keypad&>(_ControlImpl::GetCore());
115 _KeypadImpl::GetCore(void)
117 return static_cast <_Keypad&>(_ControlImpl::GetCore());
121 _KeypadImpl::Initialize(KeypadStyle keypadStyle, KeypadInputModeCategory category, int limitLength, bool enabledTextPrediction)
123 result r = E_SUCCESS;
126 __keypadStyleInfo.keypadStyle = keypadStyle;
127 __keypadStyleInfo.textPredictionEnabled = enabledTextPrediction;
128 if ((keypadStyle == KEYPAD_STYLE_NORMAL) && (category & (KEYPAD_MODE_NUMERIC | KEYPAD_MODE_SYMBOL)))
130 __keypadStyleInfo.isNormalNumberStyle = true;
134 __keypadStyleInfo.isNormalNumberStyle = false;
137 __limitLength = limitLength;
139 __pKeypad->SetResizable(false);
140 __pKeypad->SetMovable(false);
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.");
146 r = __pKeypad->AddTextEventListener(*this);
147 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
153 _KeypadImpl::SetTextPredictionEnabled(bool enable)
155 __keypadStyleInfo.textPredictionEnabled = enable;
159 _KeypadImpl::IsTextPredictionEnabled(void) const
161 return __keypadStyleInfo.textPredictionEnabled;
165 _KeypadImpl::SetSingleLineEnabled(bool enabled)
169 if ((__keypadStyleInfo.keypadStyle == KEYPAD_STYLE_PASSWORD) && (enabled == false))
171 SysLogException(NID_UI_CTRL, E_UNSUPPORTED_OPERATION, "[E_UNSUPPORTED_OPERATION] The password style can't support multiline.");
172 return E_UNSUPPORTED_OPERATION;
174 SysTryReturnResult(NID_UI_CTRL, __pKeypad->IsActivated() == false, E_INVALID_OPERATION, "Keypad is already shown.");
176 Variant var(enabled);
177 return __pKeypad->SetPropertySingleLineEnabled(var);
181 _KeypadImpl::IsSingleLineEnabled(void) const
184 return __pKeypad->GetPropertySingleLineEnabled().ToBool();
188 _KeypadImpl::AddTextEventListener(ITextEventListener& listener)
191 return __pPublicTextEvent->AddListener(listener);
195 _KeypadImpl::RemoveTextEventListener(ITextEventListener& listener)
198 return __pPublicTextEvent->RemoveListener(listener);
202 _KeypadImpl::OnAttachedToMainTree(void)
206 result r = E_SUCCESS;
207 int editStyle = EDIT_STYLE_NORMAL;
209 if (IsSingleLineEnabled())
211 editStyle |= EDIT_STYLE_SINGLE_LINE;
214 if (__keypadStyleInfo.keypadStyle == KEYPAD_STYLE_PASSWORD)
216 editStyle |= EDIT_STYLE_PASSWORD | EDIT_STYLE_SINGLE_LINE;
219 String text = GetText();
221 r = __pKeypad->Initialize(editStyle, __keypadStyleInfo, __limitLength, null);
222 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
227 r = _WindowImpl::OnAttachedToMainTree();
228 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
234 _KeypadImpl::GetText(void) const
238 return __pKeypad->GetPropertyText().ToString();
242 _KeypadImpl::SetText(const String& text)
247 __pKeypad->SetPropertyText(var);
252 _KeypadImpl::OnTextValueChanged(const _Control& source)
254 IEventArg* pEventArg = _PublicTextEvent::CreateTextEventArgN(TEXT_EVENT_CHANGED);
257 __pPublicTextEvent->Fire(*pEventArg);
262 _KeypadImpl::OnTextValueChangeCanceled(const _Control& source)
264 IEventArg* pEventArg = _PublicTextEvent::CreateTextEventArgN(TEXT_EVENT_CANCELED);
267 __pPublicTextEvent->Fire(*pEventArg);
271 }}} // Tizen::Ui::Controls