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 <boost/bind.hpp>
23 #include <dali/public-api/object/base-object.h>
24 #include <dali/integration-api/debug.h>
25 #include <dali/integration-api/events/key-event-integ.h>
36 class ImfManager : public Dali::BaseObject
39 typedef Dali::ImfManager::ImfManagerSignalV2 ImfManagerSignalV2;
40 typedef Dali::ImfManager::ImfEventSignalV2 ImfEventSignalV2;
43 static Dali::ImfManager Get();
45 ImfManager( /* Ecore_X_Window ecoreXwin */ );
46 void ConnectCallbacks();
47 void DisconnectCallbacks();
52 bool RestoreAfterFocusLost() const;
53 void SetRestoreAferFocusLost( bool toggle );
54 void NotifyCursorPosition();
55 int GetCursorPosition();
56 void SetCursorPosition( unsigned int cursorPosition );
57 void SetSurroundingText( std::string text );
58 std::string GetSurroundingText();
61 ImfManagerSignalV2& ActivatedSignal() { return mActivatedSignalV2; }
62 ImfEventSignalV2& EventReceivedSignal() { return mEventSignalV2; }
65 virtual ~ImfManager();
68 void CreateContext( /*Ecore_X_Window ecoreXwin*/ );
73 ImfManager( const ImfManager& );
74 ImfManager& operator=( ImfManager& );
77 int mIMFCursorPosition;
78 std::string mSurroundingText;
79 bool mRestoreAfterFocusLost:1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
80 bool mIdleCallbackConnected:1; ///< Whether the idle callback is already connected.
82 std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
83 ImfManagerSignalV2 mActivatedSignalV2;
84 ImfEventSignalV2 mEventSignalV2;
87 static Dali::ImfManager mToolkitImfManager;
91 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
93 Dali::ImfManager actualImfManager = ImfManager::Get();
95 BaseObject& handle = actualImfManager.GetBaseObject();
96 return static_cast<Internal::Adaptor::ImfManager&>(handle);
99 inline static const Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
101 Dali::ImfManager actualImfManager = ImfManager::Get();
103 const BaseObject& handle = imfManager.GetBaseObject();
104 return static_cast<const Internal::Adaptor::ImfManager&>(handle);
109 Dali::ImfManager Dali::Internal::Adaptor::ImfManager::mToolkitImfManager;
111 Dali::ImfManager ImfManager::Get()
113 Dali::ImfManager manager;
115 if( ! mToolkitImfManager )
117 mToolkitImfManager = Dali::ImfManager( new Dali::Internal::Adaptor::ImfManager() );
119 return mToolkitImfManager;
122 ImfManager::ImfManager( /*Ecore_X_Window ecoreXwin*/ )
123 : mIMFCursorPosition( 0 ),
124 mSurroundingText(""),
125 mRestoreAfterFocusLost( false ),
126 mIdleCallbackConnected( false ),
129 CreateContext( /*ecoreXwin*/ );
133 ImfManager::~ImfManager()
135 DisconnectCallbacks();
139 void ImfManager::CreateContext( /*Ecore_X_Window ecoreXwin*/ )
143 void ImfManager::DeleteContext()
147 // Callbacks for predicitive text support.
148 void ImfManager::ConnectCallbacks()
152 void ImfManager::DisconnectCallbacks()
156 void ImfManager::Activate()
160 void ImfManager::Deactivate()
164 void ImfManager::Reset()
168 bool ImfManager::RestoreAfterFocusLost() const
170 return mRestoreAfterFocusLost;
173 void ImfManager::SetRestoreAferFocusLost( bool toggle )
175 mRestoreAfterFocusLost = toggle;
178 void ImfManager::NotifyCursorPosition()
182 int ImfManager::GetCursorPosition()
184 return mIMFCursorPosition;
187 void ImfManager::SetCursorPosition( unsigned int cursorPosition )
189 mIMFCursorPosition = ( int )cursorPosition;
192 void ImfManager::SetSurroundingText( std::string text )
194 mSurroundingText = text;
197 std::string ImfManager::GetSurroundingText()
199 return mSurroundingText;
207 /********************************************************************************/
208 /********************************* PUBLIC CLASS *******************************/
209 /********************************************************************************/
211 ImfManager::ImfManager()
215 ImfManager::~ImfManager()
219 ImfManager ImfManager::Get()
221 return Internal::Adaptor::ImfManager::Get();
224 ImfContext ImfManager::GetContext()
229 void ImfManager::Activate()
231 Internal::Adaptor::ImfManager::GetImplementation(*this).Activate();
234 void ImfManager::Deactivate()
236 Internal::Adaptor::ImfManager::GetImplementation(*this).Deactivate();
239 bool ImfManager::RestoreAfterFocusLost() const
241 return Internal::Adaptor::ImfManager::GetImplementation(*this).RestoreAfterFocusLost();
244 void ImfManager::SetRestoreAferFocusLost( bool toggle )
246 Internal::Adaptor::ImfManager::GetImplementation(*this).SetRestoreAferFocusLost( toggle );
249 void ImfManager::Reset()
251 Internal::Adaptor::ImfManager::GetImplementation(*this).Reset();
254 void ImfManager::NotifyCursorPosition()
256 Internal::Adaptor::ImfManager::GetImplementation(*this).NotifyCursorPosition();
259 void ImfManager::SetCursorPosition( unsigned int SetCursorPosition )
261 Internal::Adaptor::ImfManager::GetImplementation(*this).SetCursorPosition( SetCursorPosition );
264 int ImfManager::GetCursorPosition()
266 return Internal::Adaptor::ImfManager::GetImplementation(*this).GetCursorPosition();
269 void ImfManager::SetSurroundingText( std::string text )
271 Internal::Adaptor::ImfManager::GetImplementation(*this).SetSurroundingText( text );
274 std::string ImfManager::GetSurroundingText()
276 return Internal::Adaptor::ImfManager::GetImplementation(*this).GetSurroundingText();
279 ImfManager::ImfManagerSignalV2& ImfManager::ActivatedSignal()
281 return Internal::Adaptor::ImfManager::GetImplementation(*this).ActivatedSignal();
284 ImfManager::ImfEventSignalV2& ImfManager::EventReceivedSignal()
286 return Internal::Adaptor::ImfManager::GetImplementation(*this).EventReceivedSignal();
289 ImfManager::ImfManager(Internal::Adaptor::ImfManager *impl)