2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
19 #include <dali/internal/input/windows/input-method-context-impl-win.h>
\r
21 // EXTERNAL INCLUDES
\r
22 #include <dali/public-api/events/key-event.h>
\r
23 #include <dali/public-api/object/type-registry.h>
\r
24 #include <dali/integration-api/debug.h>
\r
26 // INTERNAL INCLUDES
\r
27 #include <dali/public-api/adaptor-framework/key.h>
\r
28 #include <dali/integration-api/adaptor-framework/adaptor.h>
\r
29 #include <dali/internal/adaptor/common/adaptor-impl.h>
\r
30 #include <dali/internal/input/common/key-impl.h>
\r
31 #include <dali/internal/input/common/virtual-keyboard-impl.h>
\r
32 #include <dali/internal/system/common/locale-utils.h>
\r
33 #include <dali/internal/system/common/singleton-service-impl.h>
\r
46 #if defined(DEBUG_ENABLED)
\r
47 Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_INPUT_METHOD_CONTEXT" );
\r
51 InputMethodContextPtr InputMethodContextWin::New( Dali::Actor actor )
\r
53 InputMethodContextPtr manager;
\r
55 if ( actor && Adaptor::IsAvailable() )
\r
57 manager = new InputMethodContextWin( actor );
\r
63 void InputMethodContextWin::Finalize()
\r
67 InputMethodContextWin::InputMethodContextWin( Dali::Actor actor )
\r
68 : mWin32Window( 0 ),
\r
69 mIMFCursorPosition( 0 ),
\r
71 mRestoreAfterFocusLost( false ),
\r
72 mIdleCallbackConnected( false ),
\r
73 mPreeditType( Dali::InputMethodContext::PreeditStyle::NONE )
\r
76 actor.OnStageSignal().Connect( this, &InputMethodContextWin::OnStaged );
\r
79 InputMethodContextWin::~InputMethodContextWin()
\r
84 void InputMethodContextWin::Initialize()
\r
86 CreateContext( mWin32Window );
\r
90 void InputMethodContextWin::CreateContext( WinWindowHandle winHandle )
\r
92 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::CreateContext\n" );
\r
95 void InputMethodContextWin::DeleteContext()
\r
97 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::DeleteContext\n" );
\r
100 // Callbacks for predicitive text support.
\r
101 void InputMethodContextWin::ConnectCallbacks()
\r
105 void InputMethodContextWin::DisconnectCallbacks()
\r
109 void InputMethodContextWin::Activate()
\r
111 // Reset mIdleCallbackConnected
\r
112 mIdleCallbackConnected = false;
\r
115 void InputMethodContextWin::Deactivate()
\r
117 mIdleCallbackConnected = false;
\r
120 void InputMethodContextWin::Reset()
\r
122 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::Reset\n" );
\r
125 ImfContext* InputMethodContextWin::GetContext()
\r
127 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetContext\n" );
\r
132 bool InputMethodContextWin::RestoreAfterFocusLost() const
\r
134 return mRestoreAfterFocusLost;
\r
137 void InputMethodContextWin::SetRestoreAfterFocusLost( bool toggle )
\r
139 mRestoreAfterFocusLost = toggle;
\r
143 * Called when an InputMethodContext Pre-Edit changed event is received.
\r
144 * We are still predicting what the user is typing. The latest string is what the InputMethodContext module thinks
\r
145 * the user wants to type.
\r
147 void InputMethodContextWin::PreEditChanged( void*, ImfContext* imfContext, void* eventInfo )
\r
149 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::PreEditChanged\n" );
\r
152 void InputMethodContextWin::CommitReceived( void*, ImfContext* imfContext, void* eventInfo )
\r
154 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::CommitReceived\n" );
\r
156 if ( Dali::Adaptor::IsAvailable() )
\r
158 const std::string keyString( static_cast<char*>( eventInfo ) );
\r
160 Dali::InputMethodContext handle( this );
\r
161 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::COMMIT, keyString, 0, 0 );
\r
162 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
\r
164 if( callbackData.update )
\r
166 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
\r
168 NotifyCursorPosition();
\r
174 * Called when an InputMethodContext retrieve surround event is received.
\r
175 * Here the InputMethodContext module wishes to know the string we are working with and where within the string the cursor is
\r
176 * We need to signal the application to tell us this information.
\r
178 bool InputMethodContextWin::RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition )
\r
180 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::RetrieveSurrounding\n" );
\r
182 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0 );
\r
183 Dali::InputMethodContext handle( this );
\r
184 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
\r
186 if( callbackData.update )
\r
190 *text = strdup( callbackData.currentText.c_str() );
\r
193 if( cursorPosition )
\r
195 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
\r
196 *cursorPosition = mIMFCursorPosition;
\r
204 * Called when an InputMethodContext delete surrounding event is received.
\r
205 * Here we tell the application that it should delete a certain range.
\r
207 void InputMethodContextWin::DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo )
\r
209 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::DeleteSurrounding\n" );
\r
212 void InputMethodContextWin::NotifyCursorPosition()
\r
214 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::NotifyCursorPosition\n" );
\r
217 void InputMethodContextWin::SetCursorPosition( unsigned int cursorPosition )
\r
219 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetCursorPosition\n" );
\r
221 mIMFCursorPosition = static_cast<int>( cursorPosition );
\r
224 unsigned int InputMethodContextWin::GetCursorPosition() const
\r
226 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetCursorPosition\n" );
\r
228 return static_cast<unsigned int>( mIMFCursorPosition );
\r
231 void InputMethodContextWin::SetSurroundingText( const std::string& text )
\r
233 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetSurroundingText\n" );
\r
235 mSurroundingText = text;
\r
238 const std::string& InputMethodContextWin::GetSurroundingText() const
\r
240 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetSurroundingText\n" );
\r
242 return mSurroundingText;
\r
245 void InputMethodContextWin::NotifyTextInputMultiLine( bool multiLine )
\r
249 Dali::InputMethodContext::TextDirection InputMethodContextWin::GetTextDirection()
\r
251 Dali::InputMethodContext::TextDirection direction ( Dali::InputMethodContext::LeftToRight );
\r
256 Rect<int> InputMethodContextWin::GetInputMethodArea()
\r
258 int xPos, yPos, width, height;
\r
260 width = height = xPos = yPos = 0;
\r
262 return Rect<int>(xPos,yPos,width,height);
\r
265 void InputMethodContextWin::ApplyOptions( const InputMethodOptions& options )
\r
267 using namespace Dali::InputMethod::Category;
\r
271 if ( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) )
\r
274 if ( mOptions.CompareAndSet(BUTTON_ACTION, options, index) )
\r
277 if ( mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index) )
\r
280 if ( mOptions.CompareAndSet(VARIATION, options, index) )
\r
285 void InputMethodContextWin::SetInputPanelData( const std::string& data )
\r
287 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelData\n" );
\r
290 void InputMethodContextWin::GetInputPanelData( std::string& data )
\r
292 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelData\n" );
\r
295 Dali::InputMethodContext::State InputMethodContextWin::GetInputPanelState()
\r
297 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelState\n" );
\r
298 return Dali::InputMethodContext::DEFAULT;
\r
301 void InputMethodContextWin::SetReturnKeyState( bool visible )
\r
303 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetReturnKeyState\n" );
\r
306 void InputMethodContextWin::AutoEnableInputPanel( bool enabled )
\r
308 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::AutoEnableInputPanel\n" );
\r
311 void InputMethodContextWin::ShowInputPanel()
\r
313 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::ShowInputPanel\n" );
\r
316 void InputMethodContextWin::HideInputPanel()
\r
318 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::HideInputPanel\n" );
\r
321 Dali::InputMethodContext::KeyboardType InputMethodContextWin::GetKeyboardType()
\r
323 return Dali::InputMethodContext::KeyboardType::SOFTWARE_KEYBOARD;
\r
326 std::string InputMethodContextWin::GetInputPanelLocale()
\r
328 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelLocale\n" );
\r
330 std::string locale = "";
\r
334 void InputMethodContextWin::SetContentMIMETypes( const std::string& mimeTypes )
\r
336 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetContentMIMETypes\n" );
\r
339 bool InputMethodContextWin::FilterEventKey( const Dali::KeyEvent& keyEvent )
\r
341 bool eventHandled( false );
\r
343 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ))
\r
345 //check whether it's key down or key up event
\r
346 if ( keyEvent.state == KeyEvent::Down )
\r
348 eventHandled = ProcessEventKeyDown( keyEvent );
\r
350 else if ( keyEvent.state == KeyEvent::Up )
\r
352 eventHandled = ProcessEventKeyUp( keyEvent );
\r
356 return eventHandled;
\r
359 void InputMethodContextWin::SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language )
\r
361 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelLanguage\n" );
\r
364 Dali::InputMethodContext::InputPanelLanguage InputMethodContextWin::GetInputPanelLanguage() const
\r
366 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelLanguage\n" );
\r
367 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
\r
370 void InputMethodContextWin::SetInputPanelPosition( unsigned int x, unsigned int y )
\r
372 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelPosition\n" );
\r
375 Dali::InputMethodContext::PreeditStyle InputMethodContextWin::GetPreeditStyle() const
\r
377 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetPreeditStyle\n" );
\r
378 return mPreeditType;
\r
381 bool InputMethodContextWin::ProcessEventKeyDown( const KeyEvent& keyEvent )
\r
383 bool eventHandled( false );
\r
384 return eventHandled;
\r
387 bool InputMethodContextWin::ProcessEventKeyUp( const KeyEvent& keyEvent )
\r
389 bool eventHandled( false );
\r
390 return eventHandled;
\r
393 void InputMethodContextWin::OnStaged( Dali::Actor actor )
\r
395 WinWindowHandle winWindow( AnyCast< WinWindowHandle >( Dali::Integration::SceneHolder::Get( actor ).GetNativeHandle() ) );
\r
397 if( mWin32Window != winWindow )
\r
399 mWin32Window = winWindow;
\r