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;
41 static Dali::ImfManager Get();
43 ImfManager( /* Ecore_X_Window ecoreXwin */ );
44 void ConnectCallbacks();
45 void DisconnectCallbacks();
50 bool RestoreAfterFocusLost() const;
51 void SetRestoreAfterFocusLost( bool toggle );
52 void NotifyCursorPosition();
53 void SetCursorPosition( unsigned int cursorPosition );
54 unsigned int GetCursorPosition() const;
55 void SetSurroundingText( const std::string& text );
56 const std::string& GetSurroundingText() const;
59 ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
60 ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
63 virtual ~ImfManager();
66 void CreateContext( /*Ecore_X_Window ecoreXwin*/ );
71 ImfManager( const ImfManager& );
72 ImfManager& operator=( ImfManager& );
75 int mIMFCursorPosition;
76 std::string mSurroundingText;
77 bool mRestoreAfterFocusLost:1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
78 bool mIdleCallbackConnected:1; ///< Whether the idle callback is already connected.
80 ImfManagerSignalType mActivatedSignal;
81 ImfEventSignalType mEventSignal;
84 static Dali::ImfManager mToolkitImfManager;
88 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
90 Dali::ImfManager actualImfManager = ImfManager::Get();
92 BaseObject& handle = actualImfManager.GetBaseObject();
93 return static_cast<Internal::Adaptor::ImfManager&>(handle);
96 inline static const Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
98 Dali::ImfManager actualImfManager = ImfManager::Get();
100 const BaseObject& handle = imfManager.GetBaseObject();
101 return static_cast<const Internal::Adaptor::ImfManager&>(handle);
106 Dali::ImfManager Dali::Internal::Adaptor::ImfManager::mToolkitImfManager;
108 Dali::ImfManager ImfManager::Get()
110 Dali::ImfManager manager;
112 if( ! mToolkitImfManager )
114 mToolkitImfManager = Dali::ImfManager( new Dali::Internal::Adaptor::ImfManager() );
116 return mToolkitImfManager;
119 ImfManager::ImfManager( /*Ecore_X_Window ecoreXwin*/ )
120 : mIMFCursorPosition( 0 ),
122 mRestoreAfterFocusLost( false ),
123 mIdleCallbackConnected( false )
125 CreateContext( /*ecoreXwin*/ );
129 ImfManager::~ImfManager()
131 DisconnectCallbacks();
135 void ImfManager::CreateContext( /*Ecore_X_Window ecoreXwin*/ )
139 void ImfManager::DeleteContext()
143 // Callbacks for predicitive text support.
144 void ImfManager::ConnectCallbacks()
148 void ImfManager::DisconnectCallbacks()
152 void ImfManager::Activate()
156 void ImfManager::Deactivate()
160 void ImfManager::Reset()
164 bool ImfManager::RestoreAfterFocusLost() const
166 return mRestoreAfterFocusLost;
169 void ImfManager::SetRestoreAfterFocusLost( bool toggle )
171 mRestoreAfterFocusLost = toggle;
174 void ImfManager::NotifyCursorPosition()
178 void ImfManager::SetCursorPosition( unsigned int cursorPosition )
180 mIMFCursorPosition = static_cast< int >( cursorPosition );
183 unsigned int ImfManager::GetCursorPosition() const
185 return static_cast<unsigned int>( mIMFCursorPosition );
188 void ImfManager::SetSurroundingText( const std::string& text )
190 mSurroundingText = text;
193 const std::string& ImfManager::GetSurroundingText() const
195 return mSurroundingText;
203 /********************************************************************************/
204 /********************************* PUBLIC CLASS *******************************/
205 /********************************************************************************/
207 ImfManager::ImfManager()
211 ImfManager::~ImfManager()
215 ImfManager ImfManager::Get()
217 return Internal::Adaptor::ImfManager::Get();
220 void ImfManager::Activate()
222 Internal::Adaptor::ImfManager::GetImplementation(*this).Activate();
225 void ImfManager::Deactivate()
227 Internal::Adaptor::ImfManager::GetImplementation(*this).Deactivate();
230 bool ImfManager::RestoreAfterFocusLost() const
232 return Internal::Adaptor::ImfManager::GetImplementation(*this).RestoreAfterFocusLost();
235 void ImfManager::SetRestoreAfterFocusLost( bool toggle )
237 Internal::Adaptor::ImfManager::GetImplementation(*this).SetRestoreAfterFocusLost( toggle );
240 void ImfManager::Reset()
242 Internal::Adaptor::ImfManager::GetImplementation(*this).Reset();
245 void ImfManager::NotifyCursorPosition()
247 Internal::Adaptor::ImfManager::GetImplementation(*this).NotifyCursorPosition();
250 void ImfManager::SetCursorPosition( unsigned int SetCursorPosition )
252 Internal::Adaptor::ImfManager::GetImplementation(*this).SetCursorPosition( SetCursorPosition );
255 unsigned int ImfManager::GetCursorPosition() const
257 return Internal::Adaptor::ImfManager::GetImplementation(*this).GetCursorPosition();
260 void ImfManager::SetSurroundingText( const std::string& text )
262 Internal::Adaptor::ImfManager::GetImplementation(*this).SetSurroundingText( text );
265 const std::string& ImfManager::GetSurroundingText() const
267 return Internal::Adaptor::ImfManager::GetImplementation(*this).GetSurroundingText();
270 ImfManager::ImfManagerSignalType& ImfManager::ActivatedSignal()
272 return Internal::Adaptor::ImfManager::GetImplementation(*this).ActivatedSignal();
275 ImfManager::ImfEventSignalType& ImfManager::EventReceivedSignal()
277 return Internal::Adaptor::ImfManager::GetImplementation(*this).EventReceivedSignal();
280 ImfManager::ImfManager(Internal::Adaptor::ImfManager *impl)