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/devel-api/common/singleton-service.h>
\r
25 #include <dali/integration-api/debug.h>
\r
27 // INTERNAL INCLUDES
\r
28 #include <dali/public-api/adaptor-framework/key.h>
\r
29 #include <dali/integration-api/adaptor-framework/adaptor.h>
\r
30 #include <dali/internal/adaptor/common/adaptor-impl.h>
\r
31 #include <dali/internal/input/common/key-impl.h>
\r
32 #include <dali/internal/input/common/virtual-keyboard-impl.h>
\r
33 #include <dali/internal/system/common/locale-utils.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
75 actor.OnStageSignal().Connect( this, &InputMethodContextWin::OnStaged );
\r
78 InputMethodContextWin::~InputMethodContextWin()
\r
83 void InputMethodContextWin::Initialize()
\r
85 CreateContext( mWin32Window );
\r
89 void InputMethodContextWin::CreateContext( WinWindowHandle winHandle )
\r
91 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::CreateContext\n" );
\r
94 void InputMethodContextWin::DeleteContext()
\r
96 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::DeleteContext\n" );
\r
99 // Callbacks for predicitive text support.
\r
100 void InputMethodContextWin::ConnectCallbacks()
\r
104 void InputMethodContextWin::DisconnectCallbacks()
\r
108 void InputMethodContextWin::Activate()
\r
110 // Reset mIdleCallbackConnected
\r
111 mIdleCallbackConnected = false;
\r
114 void InputMethodContextWin::Deactivate()
\r
116 mIdleCallbackConnected = false;
\r
119 void InputMethodContextWin::Reset()
\r
121 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::Reset\n" );
\r
124 ImfContext* InputMethodContextWin::GetContext()
\r
126 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetContext\n" );
\r
131 bool InputMethodContextWin::RestoreAfterFocusLost() const
\r
133 return mRestoreAfterFocusLost;
\r
136 void InputMethodContextWin::SetRestoreAfterFocusLost( bool toggle )
\r
138 mRestoreAfterFocusLost = toggle;
\r
142 * Called when an InputMethodContext Pre-Edit changed event is received.
\r
143 * We are still predicting what the user is typing. The latest string is what the InputMethodContext module thinks
\r
144 * the user wants to type.
\r
146 void InputMethodContextWin::PreEditChanged( void*, ImfContext* imfContext, void* eventInfo )
\r
148 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::PreEditChanged\n" );
\r
151 void InputMethodContextWin::CommitReceived( void*, ImfContext* imfContext, void* eventInfo )
\r
153 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::CommitReceived\n" );
\r
155 if ( Dali::Adaptor::IsAvailable() )
\r
157 const std::string keyString( static_cast<char*>( eventInfo ) );
\r
159 Dali::InputMethodContext handle( this );
\r
160 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::COMMIT, keyString, 0, 0 );
\r
161 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
\r
163 if( callbackData.update )
\r
165 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
\r
167 NotifyCursorPosition();
\r
173 * Called when an InputMethodContext retrieve surround event is received.
\r
174 * Here the InputMethodContext module wishes to know the string we are working with and where within the string the cursor is
\r
175 * We need to signal the application to tell us this information.
\r
177 bool InputMethodContextWin::RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition )
\r
179 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::RetrieveSurrounding\n" );
\r
181 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0 );
\r
182 Dali::InputMethodContext handle( this );
\r
183 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
\r
185 if( callbackData.update )
\r
189 *text = strdup( callbackData.currentText.c_str() );
\r
192 if( cursorPosition )
\r
194 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
\r
195 *cursorPosition = mIMFCursorPosition;
\r
203 * Called when an InputMethodContext delete surrounding event is received.
\r
204 * Here we tell the application that it should delete a certain range.
\r
206 void InputMethodContextWin::DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo )
\r
208 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::DeleteSurrounding\n" );
\r
211 void InputMethodContextWin::NotifyCursorPosition()
\r
213 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::NotifyCursorPosition\n" );
\r
216 void InputMethodContextWin::SetCursorPosition( unsigned int cursorPosition )
\r
218 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetCursorPosition\n" );
\r
220 mIMFCursorPosition = static_cast<int>( cursorPosition );
\r
223 unsigned int InputMethodContextWin::GetCursorPosition() const
\r
225 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetCursorPosition\n" );
\r
227 return static_cast<unsigned int>( mIMFCursorPosition );
\r
230 void InputMethodContextWin::SetSurroundingText( const std::string& text )
\r
232 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetSurroundingText\n" );
\r
234 mSurroundingText = text;
\r
237 const std::string& InputMethodContextWin::GetSurroundingText() const
\r
239 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetSurroundingText\n" );
\r
241 return mSurroundingText;
\r
244 void InputMethodContextWin::NotifyTextInputMultiLine( bool multiLine )
\r
248 Dali::InputMethodContext::TextDirection InputMethodContextWin::GetTextDirection()
\r
250 Dali::InputMethodContext::TextDirection direction ( Dali::InputMethodContext::LeftToRight );
\r
255 Rect<int> InputMethodContextWin::GetInputMethodArea()
\r
257 int xPos, yPos, width, height;
\r
259 width = height = xPos = yPos = 0;
\r
261 return Rect<int>(xPos,yPos,width,height);
\r
264 void InputMethodContextWin::ApplyOptions( const InputMethodOptions& options )
\r
266 using namespace Dali::InputMethod::Category;
\r
270 if ( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) )
\r
273 if ( mOptions.CompareAndSet(BUTTON_ACTION, options, index) )
\r
276 if ( mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index) )
\r
279 if ( mOptions.CompareAndSet(VARIATION, options, index) )
\r
284 void InputMethodContextWin::SetInputPanelData( const std::string& data )
\r
286 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelData\n" );
\r
289 void InputMethodContextWin::GetInputPanelData( std::string& data )
\r
291 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelData\n" );
\r
294 Dali::InputMethodContext::State InputMethodContextWin::GetInputPanelState()
\r
296 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelState\n" );
\r
297 return Dali::InputMethodContext::DEFAULT;
\r
300 void InputMethodContextWin::SetReturnKeyState( bool visible )
\r
302 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetReturnKeyState\n" );
\r
305 void InputMethodContextWin::AutoEnableInputPanel( bool enabled )
\r
307 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::AutoEnableInputPanel\n" );
\r
310 void InputMethodContextWin::ShowInputPanel()
\r
312 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::ShowInputPanel\n" );
\r
315 void InputMethodContextWin::HideInputPanel()
\r
317 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::HideInputPanel\n" );
\r
320 Dali::InputMethodContext::KeyboardType InputMethodContextWin::GetKeyboardType()
\r
322 return Dali::InputMethodContext::KeyboardType::SOFTWARE_KEYBOARD;
\r
325 std::string InputMethodContextWin::GetInputPanelLocale()
\r
327 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelLocale\n" );
\r
329 std::string locale = "";
\r
333 void InputMethodContextWin::SetContentMIMETypes( const std::string& mimeTypes )
\r
335 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetContentMIMETypes\n" );
\r
338 bool InputMethodContextWin::FilterEventKey( const Dali::KeyEvent& keyEvent )
\r
340 bool eventHandled( false );
\r
342 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ))
\r
344 //check whether it's key down or key up event
\r
345 if ( keyEvent.state == KeyEvent::Down )
\r
347 eventHandled = ProcessEventKeyDown( keyEvent );
\r
349 else if ( keyEvent.state == KeyEvent::Up )
\r
351 eventHandled = ProcessEventKeyUp( keyEvent );
\r
355 return eventHandled;
\r
358 void InputMethodContextWin::SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language )
\r
360 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelLanguage\n" );
\r
363 Dali::InputMethodContext::InputPanelLanguage InputMethodContextWin::GetInputPanelLanguage() const
\r
365 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelLanguage\n" );
\r
366 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
\r
369 void InputMethodContextWin::SetInputPanelPosition( unsigned int x, unsigned int y )
\r
371 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelPosition\n" );
\r
374 void InputMethodContextWin::GetPreeditStyle( Dali::InputMethodContext::PreEditAttributeDataContainer& attrs ) const
\r
376 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetPreeditStyle\n" );
\r
377 attrs = mPreeditAttrs;
\r
380 bool InputMethodContextWin::ProcessEventKeyDown( const KeyEvent& keyEvent )
\r
382 bool eventHandled( false );
\r
383 return eventHandled;
\r
386 bool InputMethodContextWin::ProcessEventKeyUp( const KeyEvent& keyEvent )
\r
388 bool eventHandled( false );
\r
389 return eventHandled;
\r
392 void InputMethodContextWin::OnStaged( Dali::Actor actor )
\r
394 WinWindowHandle winWindow( AnyCast< WinWindowHandle >( Dali::Integration::SceneHolder::Get( actor ).GetNativeHandle() ) );
\r
396 if( mWin32Window != winWindow )
\r
398 mWin32Window = winWindow;
\r