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>
24 #include <dali/integration-api/events/key-event-integ.h>
35 class ImfManager : public Dali::BaseObject
38 typedef Dali::ImfManager::ImfManagerSignalType ImfManagerSignalType;
39 typedef Dali::ImfManager::ImfEventSignalType ImfEventSignalType;
42 static Dali::ImfManager Get();
44 ImfManager( /* Ecore_X_Window ecoreXwin */ );
45 void ConnectCallbacks();
46 void DisconnectCallbacks();
51 bool RestoreAfterFocusLost() const;
52 void SetRestoreAfterFocusLost( bool toggle );
53 void NotifyCursorPosition();
54 int GetCursorPosition();
55 void SetCursorPosition( unsigned int cursorPosition );
56 void SetSurroundingText( std::string text );
57 std::string GetSurroundingText();
60 ImfManagerSignalType& ActivatedSignal() { return mActivatedSignal; }
61 ImfEventSignalType& EventReceivedSignal() { return mEventSignal; }
64 virtual ~ImfManager();
67 void CreateContext( /*Ecore_X_Window ecoreXwin*/ );
72 ImfManager( const ImfManager& );
73 ImfManager& operator=( ImfManager& );
76 int mIMFCursorPosition;
77 std::string mSurroundingText;
78 bool mRestoreAfterFocusLost:1; ///< Whether the keyboard needs to be restored (activated ) after focus regained.
79 bool mIdleCallbackConnected:1; ///< Whether the idle callback is already connected.
81 std::vector<Dali::Integration::KeyEvent> mKeyEvents; ///< Stores key events to be sent from idle call-back.
82 ImfManagerSignalType mActivatedSignal;
83 ImfEventSignalType mEventSignal;
86 static Dali::ImfManager mToolkitImfManager;
90 inline static Internal::Adaptor::ImfManager& GetImplementation(Dali::ImfManager& imfManager)
92 Dali::ImfManager actualImfManager = ImfManager::Get();
94 BaseObject& handle = actualImfManager.GetBaseObject();
95 return static_cast<Internal::Adaptor::ImfManager&>(handle);
98 inline static const Internal::Adaptor::ImfManager& GetImplementation(const Dali::ImfManager& imfManager)
100 Dali::ImfManager actualImfManager = ImfManager::Get();
102 const BaseObject& handle = imfManager.GetBaseObject();
103 return static_cast<const Internal::Adaptor::ImfManager&>(handle);
108 Dali::ImfManager Dali::Internal::Adaptor::ImfManager::mToolkitImfManager;
110 Dali::ImfManager ImfManager::Get()
112 Dali::ImfManager manager;
114 if( ! mToolkitImfManager )
116 mToolkitImfManager = Dali::ImfManager( new Dali::Internal::Adaptor::ImfManager() );
118 return mToolkitImfManager;
121 ImfManager::ImfManager( /*Ecore_X_Window ecoreXwin*/ )
122 : mIMFCursorPosition( 0 ),
123 mSurroundingText(""),
124 mRestoreAfterFocusLost( false ),
125 mIdleCallbackConnected( false ),
128 CreateContext( /*ecoreXwin*/ );
132 ImfManager::~ImfManager()
134 DisconnectCallbacks();
138 void ImfManager::CreateContext( /*Ecore_X_Window ecoreXwin*/ )
142 void ImfManager::DeleteContext()
146 // Callbacks for predicitive text support.
147 void ImfManager::ConnectCallbacks()
151 void ImfManager::DisconnectCallbacks()
155 void ImfManager::Activate()
159 void ImfManager::Deactivate()
163 void ImfManager::Reset()
167 bool ImfManager::RestoreAfterFocusLost() const
169 return mRestoreAfterFocusLost;
172 void ImfManager::SetRestoreAfterFocusLost( bool toggle )
174 mRestoreAfterFocusLost = toggle;
177 void ImfManager::NotifyCursorPosition()
181 int ImfManager::GetCursorPosition()
183 return mIMFCursorPosition;
186 void ImfManager::SetCursorPosition( unsigned int cursorPosition )
188 mIMFCursorPosition = ( int )cursorPosition;
191 void ImfManager::SetSurroundingText( std::string text )
193 mSurroundingText = text;
196 std::string ImfManager::GetSurroundingText()
198 return mSurroundingText;
206 /********************************************************************************/
207 /********************************* PUBLIC CLASS *******************************/
208 /********************************************************************************/
210 ImfManager::ImfManager()
214 ImfManager::~ImfManager()
218 ImfManager ImfManager::Get()
220 return Internal::Adaptor::ImfManager::Get();
223 ImfContext ImfManager::GetContext()
228 void ImfManager::Activate()
230 Internal::Adaptor::ImfManager::GetImplementation(*this).Activate();
233 void ImfManager::Deactivate()
235 Internal::Adaptor::ImfManager::GetImplementation(*this).Deactivate();
238 bool ImfManager::RestoreAfterFocusLost() const
240 return Internal::Adaptor::ImfManager::GetImplementation(*this).RestoreAfterFocusLost();
243 void ImfManager::SetRestoreAfterFocusLost( bool toggle )
245 Internal::Adaptor::ImfManager::GetImplementation(*this).SetRestoreAfterFocusLost( toggle );
248 void ImfManager::Reset()
250 Internal::Adaptor::ImfManager::GetImplementation(*this).Reset();
253 void ImfManager::NotifyCursorPosition()
255 Internal::Adaptor::ImfManager::GetImplementation(*this).NotifyCursorPosition();
258 void ImfManager::SetCursorPosition( unsigned int SetCursorPosition )
260 Internal::Adaptor::ImfManager::GetImplementation(*this).SetCursorPosition( SetCursorPosition );
263 int ImfManager::GetCursorPosition()
265 return Internal::Adaptor::ImfManager::GetImplementation(*this).GetCursorPosition();
268 void ImfManager::SetSurroundingText( std::string text )
270 Internal::Adaptor::ImfManager::GetImplementation(*this).SetSurroundingText( text );
273 std::string ImfManager::GetSurroundingText()
275 return Internal::Adaptor::ImfManager::GetImplementation(*this).GetSurroundingText();
278 ImfManager::ImfManagerSignalType& ImfManager::ActivatedSignal()
280 return Internal::Adaptor::ImfManager::GetImplementation(*this).ActivatedSignal();
283 ImfManager::ImfEventSignalType& ImfManager::EventReceivedSignal()
285 return Internal::Adaptor::ImfManager::GetImplementation(*this).EventReceivedSignal();
288 ImfManager::ImfManager(Internal::Adaptor::ImfManager *impl)