2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "toolkit-imf-manager.h"
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/integration-api/debug.h>
34 class ImfManager : public Dali::BaseObject
37 typedef Dali::ImfManager::ImfManagerSignalType ImfManagerSignalType;
38 typedef Dali::ImfManager::ImfEventSignalType ImfEventSignalType;
39 typedef Dali::ImfManager::StatusSignalType ImfStatusSignalType;
40 typedef Dali::ImfManager::VoidSignalType ImfVoidSignalType;
43 static Dali::ImfManager Get();
45 ImfManager( /* Ecore_X_Window ecoreXwin */ );
46 void ConnectCallbacks();
47 void DisconnectCallbacks();
52 bool RestoreAfterFocusLost() const;
53 void SetRestoreAfterFocusLost( bool toggle );
54 void NotifyCursorPosition();
55 void SetCursorPosition( unsigned int cursorPosition );
56 unsigned int GetCursorPosition() const;
57 void SetSurroundingText( const std::string& text );
58 const std::string& GetSurroundingText() const;
59 void ApplyOptions( const InputMethodOptions& options );
62 ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
63 ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
64 ImfStatusSignalType& StatusChangedSignal() { return mKeyboardStatusSignal; }
65 ImfVoidSignalType& ResizedSignal() { return mKeyboardResizeSignal; }
66 ImfVoidSignalType& LanguageChangedSignal() { return mKeyboardLanguageChangedSignal; }
69 virtual ~ImfManager();
72 void CreateContext( /*Ecore_X_Window ecoreXwin*/ );
77 ImfManager( const ImfManager& );
78 ImfManager& operator=( ImfManager& );
81 int mIMFCursorPosition;
82 std::string mSurroundingText;
83 bool mRestoreAfterFocusLost:1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
84 bool mIdleCallbackConnected:1; ///< Whether the idle callback is already connected.
85 InputMethodOptions mOptions;
87 ImfManagerSignalType mActivatedSignal;
88 ImfEventSignalType mEventSignal;
89 ImfStatusSignalType mKeyboardStatusSignal;
90 ImfVoidSignalType mKeyboardResizeSignal;
91 ImfVoidSignalType mKeyboardLanguageChangedSignal;
93 static Dali::ImfManager mToolkitImfManager;
97 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
99 Dali::ImfManager actualImfManager = ImfManager::Get();
101 BaseObject& handle = actualImfManager.GetBaseObject();
102 return static_cast<Internal::Adaptor::ImfManager&>(handle);
105 inline static const Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
107 Dali::ImfManager actualImfManager = ImfManager::Get();
109 const BaseObject& handle = imfManager.GetBaseObject();
110 return static_cast<const Internal::Adaptor::ImfManager&>(handle);
115 Dali::ImfManager Dali::Internal::Adaptor::ImfManager::mToolkitImfManager;
117 Dali::ImfManager ImfManager::Get()
119 Dali::ImfManager manager;
121 if( ! mToolkitImfManager )
123 mToolkitImfManager = Dali::ImfManager( new Dali::Internal::Adaptor::ImfManager() );
125 return mToolkitImfManager;
128 ImfManager::ImfManager( /*Ecore_X_Window ecoreXwin*/ )
129 : mIMFCursorPosition( 0 ),
131 mRestoreAfterFocusLost( false ),
132 mIdleCallbackConnected( false )
134 CreateContext( /*ecoreXwin*/ );
138 ImfManager::~ImfManager()
140 DisconnectCallbacks();
144 void ImfManager::CreateContext( /*Ecore_X_Window ecoreXwin*/ )
148 void ImfManager::DeleteContext()
152 // Callbacks for predicitive text support.
153 void ImfManager::ConnectCallbacks()
157 void ImfManager::DisconnectCallbacks()
161 void ImfManager::Activate()
165 void ImfManager::Deactivate()
169 void ImfManager::Reset()
173 bool ImfManager::RestoreAfterFocusLost() const
175 return mRestoreAfterFocusLost;
178 void ImfManager::SetRestoreAfterFocusLost( bool toggle )
180 mRestoreAfterFocusLost = toggle;
183 void ImfManager::NotifyCursorPosition()
187 void ImfManager::SetCursorPosition( unsigned int cursorPosition )
189 mIMFCursorPosition = static_cast< int >( cursorPosition );
192 unsigned int ImfManager::GetCursorPosition() const
194 return static_cast<unsigned int>( mIMFCursorPosition );
197 void ImfManager::SetSurroundingText( const std::string& text )
199 mSurroundingText = text;
202 const std::string& ImfManager::GetSurroundingText() const
204 return mSurroundingText;
207 void ImfManager::ApplyOptions( const InputMethodOptions& options )
216 /********************************************************************************/
217 /********************************* PUBLIC CLASS *******************************/
218 /********************************************************************************/
220 ImfManager::ImfManager()
224 ImfManager::~ImfManager()
228 ImfManager ImfManager::Get()
230 return Internal::Adaptor::ImfManager::Get();
233 void ImfManager::Activate()
235 Internal::Adaptor::ImfManager::GetImplementation(*this).Activate();
238 void ImfManager::Deactivate()
240 Internal::Adaptor::ImfManager::GetImplementation(*this).Deactivate();
243 bool ImfManager::RestoreAfterFocusLost() const
245 return Internal::Adaptor::ImfManager::GetImplementation(*this).RestoreAfterFocusLost();
248 void ImfManager::SetRestoreAfterFocusLost( bool toggle )
250 Internal::Adaptor::ImfManager::GetImplementation(*this).SetRestoreAfterFocusLost( toggle );
253 void ImfManager::Reset()
255 Internal::Adaptor::ImfManager::GetImplementation(*this).Reset();
258 void ImfManager::NotifyCursorPosition()
260 Internal::Adaptor::ImfManager::GetImplementation(*this).NotifyCursorPosition();
263 void ImfManager::SetCursorPosition( unsigned int SetCursorPosition )
265 Internal::Adaptor::ImfManager::GetImplementation(*this).SetCursorPosition( SetCursorPosition );
268 unsigned int ImfManager::GetCursorPosition() const
270 return Internal::Adaptor::ImfManager::GetImplementation(*this).GetCursorPosition();
273 void ImfManager::SetSurroundingText( const std::string& text )
275 Internal::Adaptor::ImfManager::GetImplementation(*this).SetSurroundingText( text );
278 const std::string& ImfManager::GetSurroundingText() const
280 return Internal::Adaptor::ImfManager::GetImplementation(*this).GetSurroundingText();
283 void ImfManager::NotifyTextInputMultiLine( bool multiLine )
287 void ImfManager::ApplyOptions( const InputMethodOptions& options )
289 Internal::Adaptor::ImfManager::GetImplementation(*this).ApplyOptions( options );
292 ImfManager::ImfManagerSignalType& ImfManager::ActivatedSignal()
294 return Internal::Adaptor::ImfManager::GetImplementation(*this).ActivatedSignal();
297 ImfManager::ImfEventSignalType& ImfManager::EventReceivedSignal()
299 return Internal::Adaptor::ImfManager::GetImplementation(*this).EventReceivedSignal();
302 ImfManager::StatusSignalType& ImfManager::StatusChangedSignal()
304 return Internal::Adaptor::ImfManager::GetImplementation(*this).StatusChangedSignal();
307 ImfManager::VoidSignalType& ImfManager::ResizedSignal()
309 return Internal::Adaptor::ImfManager::GetImplementation(*this).ResizedSignal();
312 ImfManager::VoidSignalType& ImfManager::LanguageChangedSignal()
314 return Internal::Adaptor::ImfManager::GetImplementation(*this).LanguageChangedSignal();
317 ImfManager::ImfManager(Internal::Adaptor::ImfManager *impl)