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>
24 #include <dali/dali.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/integration-api/events/key-event-integ.h>
37 class ImfManager : public Dali::BaseObject
40 typedef Dali::ImfManager::ImfManagerSignalV2 ImfManagerSignalV2;
41 typedef Dali::ImfManager::ImfEventSignalV2 ImfEventSignalV2;
44 static Dali::ImfManager Get();
46 ImfManager( /* Ecore_X_Window ecoreXwin */ );
47 void ConnectCallbacks();
48 void DisconnectCallbacks();
53 bool RestoreAfterFocusLost() const;
54 void SetRestoreAferFocusLost( bool toggle );
55 void NotifyCursorPosition();
56 int GetCursorPosition();
57 void SetCursorPosition( unsigned int cursorPosition );
58 void SetSurroundingText( std::string text );
59 std::string GetSurroundingText();
62 ImfManagerSignalV2& ActivatedSignal() { return mActivatedSignalV2; }
63 ImfEventSignalV2& EventReceivedSignal() { return mEventSignalV2; }
66 virtual ~ImfManager();
69 void CreateContext( /*Ecore_X_Window ecoreXwin*/ );
74 ImfManager( const ImfManager& );
75 ImfManager& operator=( ImfManager& );
78 int mIMFCursorPosition;
79 std::string mSurroundingText;
80 bool mRestoreAfterFocusLost:1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
81 bool mIdleCallbackConnected:1; ///< Whether the idle callback is already connected.
83 std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
84 ImfManagerSignalV2 mActivatedSignalV2;
85 ImfEventSignalV2 mEventSignalV2;
88 static Dali::ImfManager mToolkitImfManager;
92 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
94 Dali::ImfManager actualImfManager = ImfManager::Get();
96 BaseObject& handle = actualImfManager.GetBaseObject();
97 return static_cast<Internal::Adaptor::ImfManager&>(handle);
100 inline static const Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
102 Dali::ImfManager actualImfManager = ImfManager::Get();
104 const BaseObject& handle = imfManager.GetBaseObject();
105 return static_cast<const Internal::Adaptor::ImfManager&>(handle);
110 Dali::ImfManager Dali::Internal::Adaptor::ImfManager::mToolkitImfManager;
112 Dali::ImfManager ImfManager::Get()
114 Dali::ImfManager manager;
116 if( ! mToolkitImfManager )
118 mToolkitImfManager = Dali::ImfManager( new Dali::Internal::Adaptor::ImfManager() );
120 return mToolkitImfManager;
123 ImfManager::ImfManager( /*Ecore_X_Window ecoreXwin*/ )
124 : mIMFCursorPosition( 0 ),
125 mSurroundingText(""),
126 mRestoreAfterFocusLost( false ),
127 mIdleCallbackConnected( false ),
130 CreateContext( /*ecoreXwin*/ );
134 ImfManager::~ImfManager()
136 DisconnectCallbacks();
140 void ImfManager::CreateContext( /*Ecore_X_Window ecoreXwin*/ )
144 void ImfManager::DeleteContext()
148 // Callbacks for predicitive text support.
149 void ImfManager::ConnectCallbacks()
153 void ImfManager::DisconnectCallbacks()
157 void ImfManager::Activate()
161 void ImfManager::Deactivate()
165 void ImfManager::Reset()
169 bool ImfManager::RestoreAfterFocusLost() const
171 return mRestoreAfterFocusLost;
174 void ImfManager::SetRestoreAferFocusLost( bool toggle )
176 mRestoreAfterFocusLost = toggle;
179 void ImfManager::NotifyCursorPosition()
183 int ImfManager::GetCursorPosition()
185 return mIMFCursorPosition;
188 void ImfManager::SetCursorPosition( unsigned int cursorPosition )
190 mIMFCursorPosition = ( int )cursorPosition;
193 void ImfManager::SetSurroundingText( std::string text )
195 mSurroundingText = text;
198 std::string ImfManager::GetSurroundingText()
200 return mSurroundingText;
208 /********************************************************************************/
209 /********************************* PUBLIC CLASS *******************************/
210 /********************************************************************************/
212 ImfManager::ImfManager()
216 ImfManager::~ImfManager()
220 ImfManager ImfManager::Get()
222 return Internal::Adaptor::ImfManager::Get();
225 ImfContext ImfManager::GetContext()
230 void ImfManager::Activate()
232 Internal::Adaptor::ImfManager::GetImplementation(*this).Activate();
235 void ImfManager::Deactivate()
237 Internal::Adaptor::ImfManager::GetImplementation(*this).Deactivate();
240 bool ImfManager::RestoreAfterFocusLost() const
242 return Internal::Adaptor::ImfManager::GetImplementation(*this).RestoreAfterFocusLost();
245 void ImfManager::SetRestoreAferFocusLost( bool toggle )
247 Internal::Adaptor::ImfManager::GetImplementation(*this).SetRestoreAferFocusLost( toggle );
250 void ImfManager::Reset()
252 Internal::Adaptor::ImfManager::GetImplementation(*this).Reset();
255 void ImfManager::NotifyCursorPosition()
257 Internal::Adaptor::ImfManager::GetImplementation(*this).NotifyCursorPosition();
260 void ImfManager::SetCursorPosition( unsigned int SetCursorPosition )
262 Internal::Adaptor::ImfManager::GetImplementation(*this).SetCursorPosition( SetCursorPosition );
265 int ImfManager::GetCursorPosition()
267 return Internal::Adaptor::ImfManager::GetImplementation(*this).GetCursorPosition();
270 void ImfManager::SetSurroundingText( std::string text )
272 Internal::Adaptor::ImfManager::GetImplementation(*this).SetSurroundingText( text );
275 std::string ImfManager::GetSurroundingText()
277 return Internal::Adaptor::ImfManager::GetImplementation(*this).GetSurroundingText();
280 ImfManager::ImfManagerSignalV2& ImfManager::ActivatedSignal()
282 return Internal::Adaptor::ImfManager::GetImplementation(*this).ActivatedSignal();
285 ImfManager::ImfEventSignalV2& ImfManager::EventReceivedSignal()
287 return Internal::Adaptor::ImfManager::GetImplementation(*this).EventReceivedSignal();
290 ImfManager::ImfManager(Internal::Adaptor::ImfManager *impl)