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 FUiInputConnection.h
20 * @brief This is the header file for the %InputConnection class.
22 * This header file contains the declarations of the %InputConnection class.
25 #ifndef _FUI_INPUT_CONNECTION_H_
26 #define _FUI_INPUT_CONNECTION_H_
28 #include <FGrpFloatRectangle.h>
29 #include <FGrpRectangle.h>
30 #include <FUiIInputConnectionEventListener.h>
31 #include <FUiIInputConnectionEventListenerF.h>
32 #include <FUiIInputConnectionProvider.h>
33 #include <FUiInputConnectionTypes.h>
35 namespace Tizen { namespace Ui {
37 class _InputConnectionImpl;
42 * @class InputConnection
43 * @brief This is the header file for the %InputConnection class.
44 * This header file contains the declarations of the %InputConnection class.
47 * @final This class is not intended for extension.
49 * The following examples demonstrate how to use the %InputConnection class.
51 * This is a simple editor that uses an %InputConnection.
55 // Sample code for EditorSample.h
57 #include <FUiInputConnection.h>
58 #include <FUiIInputConnectionEventListener.h>
60 namespace Tizen { namespace Ui {
63 public Tizen::Ui::Controls::Form,
64 public Tizen::Ui::ITouchEventListener,
65 public Tizen::Ui::IInputConnectionEventListener,
66 public Tizen::Ui::IInputConnectionProvider,
67 public Tizen::Ui::IFocusEventListener,
68 public Tizen::Ui::IPropagatedKeyEventListener
74 bool Initialize(void);
75 virtual result OnInitializing();
79 virtual void OnInputConnectionPanelShowStateChanged(Tizen::Ui::InputConnection& source, Tizen::Ui::InputPanelShowState showState){};
80 virtual void OnInputConnectionPanelLanguageChanged(Tizen::Ui::InputConnection& source, Tizen::Locales::LanguageCode language){};
81 virtual void OnInputConnectionPanelBoundsChanged(Tizen::Ui::InputConnection& source, const Tizen::Graphics::Rectangle& bounds){};
82 virtual void OnInputConnectionTextPredictionShowStateChanged(Tizen::Ui::InputConnection& source, bool isShown){};
83 virtual void OnInputConnectionTextPredictionBoundsChanged(Tizen::Ui::InputConnection& source, const Tizen::Graphics::Rectangle& bounds){};
84 virtual void OnInputConnectionTextCommitted(Tizen::Ui::InputConnection& source, const Tizen::Base::String& committedText);
85 virtual void OnInputConnectionComposingTextChanged(Tizen::Ui::InputConnection& source, const Tizen::Base::String& preEditText, int cursorPosition){};
86 virtual void DeleteSurroundingText(Tizen::Ui::InputConnection& source, int offset, int chars){};
87 virtual void GetPreviousText(Tizen::Ui::InputConnection& source, Tizen::Base::String& text, int& cursorPosition){};
89 virtual void OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo & touchInfo){};
90 virtual void OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
91 virtual void OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo){};
92 virtual void OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo){};
93 virtual void OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo){};
95 virtual void OnFocusGained(const Tizen::Ui::Control& source);
96 virtual void OnFocusLost(const Tizen::Ui::Control& source);
98 virtual bool OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo) {return false;};
99 virtual bool OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo) {return false;};
100 virtual bool OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo) {return false;};
101 virtual bool OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo) {return false;};
103 InputConnection* __pImf;
105 Tizen::Ui::Controls::Button* __pButton;
113 // Sample code for EditorSample.cpp
114 #include "EditorSample.h"
116 using namespace Tizen::Graphics;
117 using namespace Tizen::Ui;
118 using namespace Tizen::Ui::Controls;
121 EditorSample::Initialize(void)
123 Construct(FORM_STYLE_NORMAL);
128 EditorSample::OnInputConnectionTextCommitted(InputConnection& source, const Tizen::Base::String& committedText)
130 __pButton->SetText(committedText);
131 __pButton->Invalidate(true);
135 EditorSample::OnInitializing()
137 result r = E_SUCCESS;
140 __pButton = new (std::nothrow) Button();
141 __pButton->Construct(FloatRectangle(180.0f, 200.0f, 360.0f, 200.0f), L"Text Display");
142 __pButton->SetFocusable(true);
143 __pButton->AddFocusEventListener(*this);
144 __pButton->AddTouchEventListener(*this);
145 __pButton->SetPropagatedKeyEventListener(this);
146 AddControl(__pButton);
148 __bindStatus = false;
150 // Creates an instance of InputConnection
151 __pImf = new (std::nothrow) InputConnection();
152 __pImf->Construct(__pButton, *this, *this);
158 EditorSample::ShowKeypad()
160 result r = E_SUCCESS;
164 __pImf->BindInputMethod();
166 __pImf->ShowInputPanel();
173 EditorSample::HideKeypad()
175 result r = E_SUCCESS;
177 if (__bindStatus != false)
179 __pImf->HideInputPanel();
180 __pImf->UnbindInputMethod();
181 __bindStatus = false;
188 EditorSample::OnTouchReleased(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
193 __pButton->SetFocus();
202 EditorSample::OnFocusGained(const Tizen::Ui::Control& source)
208 EditorSample::OnFocusLost(const Tizen::Ui::Control& source)
216 class _OSP_EXPORT_ InputConnection
217 : public Tizen::Base::Object
221 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
225 InputConnection(void);
228 * This destructor overrides Tizen::Base::Object::~Object().
232 virtual ~InputConnection(void);
235 * Initializes this instance of %InputConnection with the specified parameter.
238 * @return An error code
239 * @param[in] pControl The source object for connecting the Input Method.
240 * @param[in] listener An instance of the %IInputConnectionEventListener for processing the event
241 * @param[in] provider The %InputConnection provider
242 * @exception E_SUCCESS The method is successful.
243 * @exception E_INVALID_ARG A specified input parameter is invalid.
244 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
246 result Construct(const Control* pControl, IInputConnectionEventListener& listener, IInputConnectionProvider& provider);
249 * Initializes this instance of %InputConnection with a specified parameter.
253 * @return An error code
254 * @param[in] pControl The source object for connecting the Input Method
255 * @param[in] listener An instance of %IInputConnectionEventListenerF for processing the event
256 * @param[in] provider The %InputConnection provider
257 * @exception E_SUCCESS The method is successful.
258 * @exception E_INVALID_ARG A specified input parameter is invalid.
259 * @exception E_SYSTEM The method cannot proceed due to a severe system error.
261 result Construct(const Control* pControl, IInputConnectionEventListenerF& listener, IInputConnectionProvider& provider);
264 * Binds the %InputConnection to the current active Input Method
267 * @return An error code
268 * @exception E_SUCCESS The method is successful.
269 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation.
270 * @see UnbindInputMethod()
271 * @remarks This method should be called when the %Control object has the input focus.
273 result BindInputMethod(void);
276 * Unbinds the %InputConnection from the current active Input Method. It will no longer be valid for the Input Method.
279 * @see BindInputMethod()
281 void UnbindInputMethod(void);
284 * Asks the current active Input Method to show the Input Panel which contains the keyboard.
287 * @return An error code
288 * @exception E_SUCCESS The method is successful.
289 * @exception E_INVALID_STATE This exception is thrown when BindInputMethod() is not called before calling this method.
290 * @see HideInputPanel()
292 result ShowInputPanel(void);
295 * Asks the current active Input Method to hide the active Input Panel which contains the keyboard.
298 * @return An error code
299 * @exception E_SUCCESS The method is successful.
300 * @exception E_INVALID_STATE This exception is thrown when BindInputMethod() is not called before calling this method.
301 * @see ShowInputPanel()
303 result HideInputPanel(void);
306 * Sets the style of the current active Input Panel.
309 * @param[in] style The style of the Input Panel.
310 * @remarks This method may not work, depending on the current active Input Method.
312 void SetInputPanelStyle(InputPanelStyle style);
315 * Sets the auto-capitalization mode.
318 * @param[in] autoCapitalizationMode The auto-capitalization mode.
319 * @remarks This method may not work, depending on the current active Input Method.
321 void SetAutoCapitalizationMode(AutoCapitalizationMode autoCapitalizationMode);
324 * Finishes text composition.
325 * This will typically cause the Input Method to exit the composing state.
328 * @return An error code
329 * @exception E_SUCCESS The method is successful.
330 * @exception E_INVALID_STATE This exception is thrown when BindInputMethod() is not called before calling this method.
332 result FinishTextComposition(void);
335 * Sets the type of ActionKey.
338 * @param[in] inputPanelAction The InputPanel action
339 * @remarks This method may not work, depending on the current active Input Method.
341 void SetInputPanelAction(InputPanelAction inputPanelAction);
344 * Enables or disables the ActionKey.
347 * @param[in] enable Set to @c true to enable the ActionKey, @n
349 * @remarks This method may not work, depending on the current active Input Method.
351 void SetInputPanelActionEnabled(bool enable);
354 * Sets the language of the current active Input Panel.
357 * @param[in] languageCode The language to set
358 * @exception E_SUCCESS The method is successful.
359 * @exception E_OUT_OF_MEMORY The memory is insufficient.
360 * @remarks This method may not work, depending on the current active Input Method.
362 result SetInputPanelLanguage(Tizen::Locales::LanguageCode languageCode);
365 * Sets the cursor at the specified position.
369 * @return An error code
370 * @param[in] position The cursor position that is to set
371 * @exception E_SUCCESS The method is successful.
372 * @exception E_INVALID_ARG The specified input parameter is invalid.
373 * @exception E_INVALID_STATE This exception is thrown when BindInputMethod() is not called before calling this method.
375 result SetCursorPosition(int position);
378 * Sets the bounds of the cursor.
382 * @return An error code
383 * @param[in] rect The rectangle to set
384 * @exception E_SUCCESS The method is successful.
385 * @exception E_INVALID_ARG The specified input parameter is invalid.
386 * @exception E_INVALID_STATE This exception is thrown when BindInputMethod() is not called before calling this method.
388 result SetCursorBounds(const Tizen::Graphics::Rectangle& rect);
391 * Sets the bounds of the cursor.
395 * @return An error code
396 * @param[in] rect The rectangle to set
397 * @exception E_SUCCESS The method is successful.
398 * @exception E_INVALID_ARG The specified input parameter is invalid.
399 * @exception E_INVALID_STATE This exception is thrown when BindInputMethod() is not called before calling this method.
401 result SetCursorBounds(const Tizen::Graphics::FloatRectangle& rect);
404 * Gets the bounds of the current active Input Panel.
407 * @return An instance of the rectangle that represents the position of the top-left corner,
408 * the width, and the height of the Input Panel.
409 * @exception E_SUCCESS The method is successful.
410 * @exception E_INVALID_STATE This exception is thrown when BindInputMethod() is not called before calling this method.
411 * @remarks The specific error code can be accessed using the GetLastResult() method.
413 Tizen::Graphics::Rectangle GetInputPanelBounds(void) const;
416 * Gets the bounds of the current active Input Panel.
420 * @return An instance of the rectangle that represents the position of the top-left corner,
421 * the width, and the height of the Input Panel
422 * @exception E_SUCCESS The method is successful.
423 * @exception E_INVALID_STATE This exception is thrown when BindInputMethod() is not called before calling this method.
424 * @remarks The specific error code can be accessed using the GetLastResult() method.
426 Tizen::Graphics::FloatRectangle GetInputPanelBoundsF(void) const;
429 * Enables or disables text prediction.
432 * @param[in] enable Set to @c true to enable text prediction, @n
434 * @remarks This method may not work, depending on the current active Input Method.
436 void SetTextPredictionEnabled(bool enable);
439 * Sends opaque command to the input method.
443 * @param[in] command The opaque command
444 * @remarks This method can be used to provide domain-specific features that are only known between certain input methods and their clients.
445 * This method may not work, depending on the active Input Method.
447 void SendOpaqueCommand (const Tizen::Base::String& command);
451 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
455 InputConnection(const InputConnection& rhs);
458 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
462 InputConnection& operator=(const InputConnection& rhs);
465 friend class _InputConnectionImpl;
466 _InputConnectionImpl* __pInputConnectionImpl;
468 }; // InputConnection
472 #endif // _FUI_INPUT_CONNECTION_H_