2 * Copyright (c) 2018 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/adaptor-framework/key.h>
\r
24 #include <dali/public-api/object/type-registry.h>
\r
25 #include <dali/integration-api/debug.h>
\r
27 // INTERNAL INCLUDES
\r
28 #include <dali/integration-api/adaptor.h>
\r
29 #include <dali/internal/adaptor/common/adaptor-impl.h>
\r
30 #include <dali/internal/system/common/locale-utils.h>
\r
31 #include <dali/internal/system/common/singleton-service-impl.h>
\r
32 #include <dali/internal/input/common/virtual-keyboard-impl.h>
\r
33 #include <dali/internal/input/common/key-impl.h>
\r
44 InputMethodContextPtr InputMethodContextWin::New()
\r
46 InputMethodContextPtr manager;
\r
48 if ( Adaptor::IsAvailable() )
\r
50 // Create instance and register singleton only if the adaptor is available
\r
51 Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
\r
52 Any nativeWindow = adaptorImpl.GetNativeWindowHandle();
\r
54 // The Win_Window_Handle needs to use the InputMethodContext.
\r
55 // Only when the render surface is window, we can get the Win_Window_Handle.
\r
56 WinWindowHandle winWindow( AnyCast<WinWindowHandle>(nativeWindow) );
\r
59 manager = new InputMethodContextWin( winWindow );
\r
63 DALI_LOG_ERROR("Failed to get native window handle\n");
\r
70 void InputMethodContextWin::Finalize()
\r
74 InputMethodContextWin::InputMethodContextWin( WinWindowHandle winWindow )
\r
75 : mWin32Window( winWindow ),
\r
76 mIMFCursorPosition( 0 ),
\r
78 mRestoreAfterFocusLost( false ),
\r
79 mIdleCallbackConnected( false )
\r
83 InputMethodContextWin::~InputMethodContextWin()
\r
88 void InputMethodContextWin::Initialize()
\r
90 CreateContext( mWin32Window );
\r
94 void InputMethodContextWin::CreateContext( WinWindowHandle winHandle )
\r
96 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::CreateContext\n" );
\r
99 void InputMethodContextWin::DeleteContext()
\r
101 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::DeleteContext\n" );
\r
104 // Callbacks for predicitive text support.
\r
105 void InputMethodContextWin::ConnectCallbacks()
\r
109 void InputMethodContextWin::DisconnectCallbacks()
\r
113 void InputMethodContextWin::Activate()
\r
115 // Reset mIdleCallbackConnected
\r
116 mIdleCallbackConnected = false;
\r
119 void InputMethodContextWin::Deactivate()
\r
121 mIdleCallbackConnected = false;
\r
124 void InputMethodContextWin::Reset()
\r
126 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::Reset\n" );
\r
129 ImfContext* InputMethodContextWin::GetContext()
\r
131 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetContext\n" );
\r
136 bool InputMethodContextWin::RestoreAfterFocusLost() const
\r
138 return mRestoreAfterFocusLost;
\r
141 void InputMethodContextWin::SetRestoreAfterFocusLost( bool toggle )
\r
143 mRestoreAfterFocusLost = toggle;
\r
147 * Called when an InputMethodContext Pre-Edit changed event is received.
\r
148 * We are still predicting what the user is typing. The latest string is what the InputMethodContext module thinks
\r
149 * the user wants to type.
\r
151 void InputMethodContextWin::PreEditChanged( void*, ImfContext* imfContext, void* eventInfo )
\r
153 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::PreEditChanged\n" );
\r
156 void InputMethodContextWin::CommitReceived( void*, ImfContext* imfContext, void* eventInfo )
\r
158 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::CommitReceived\n" );
\r
160 if ( Dali::Adaptor::IsAvailable() )
\r
162 const std::string keyString( static_cast<char*>( eventInfo ) );
\r
164 Dali::InputMethodContext handle( this );
\r
165 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::COMMIT, keyString, 0, 0 );
\r
166 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
\r
168 if( callbackData.update )
\r
170 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
\r
172 NotifyCursorPosition();
\r
178 * Called when an InputMethodContext retrieve surround event is received.
\r
179 * Here the InputMethodContext module wishes to know the string we are working with and where within the string the cursor is
\r
180 * We need to signal the application to tell us this information.
\r
182 bool InputMethodContextWin::RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition )
\r
184 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::RetrieveSurrounding\n" );
\r
186 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0 );
\r
187 Dali::InputMethodContext handle( this );
\r
188 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
\r
190 if( callbackData.update )
\r
194 *text = strdup( callbackData.currentText.c_str() );
\r
197 if( cursorPosition )
\r
199 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
\r
200 *cursorPosition = mIMFCursorPosition;
\r
208 * Called when an InputMethodContext delete surrounding event is received.
\r
209 * Here we tell the application that it should delete a certain range.
\r
211 void InputMethodContextWin::DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo )
\r
213 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::DeleteSurrounding\n" );
\r
216 void InputMethodContextWin::NotifyCursorPosition()
\r
218 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::NotifyCursorPosition\n" );
\r
221 void InputMethodContextWin::SetCursorPosition( unsigned int cursorPosition )
\r
223 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetCursorPosition\n" );
\r
225 mIMFCursorPosition = static_cast<int>( cursorPosition );
\r
228 unsigned int InputMethodContextWin::GetCursorPosition() const
\r
230 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetCursorPosition\n" );
\r
232 return static_cast<unsigned int>( mIMFCursorPosition );
\r
235 void InputMethodContextWin::SetSurroundingText( const std::string& text )
\r
237 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetSurroundingText\n" );
\r
239 mSurroundingText = text;
\r
242 const std::string& InputMethodContextWin::GetSurroundingText() const
\r
244 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetSurroundingText\n" );
\r
246 return mSurroundingText;
\r
249 void InputMethodContextWin::NotifyTextInputMultiLine( bool multiLine )
\r
253 Dali::InputMethodContext::TextDirection InputMethodContextWin::GetTextDirection()
\r
255 Dali::InputMethodContext::TextDirection direction ( Dali::InputMethodContext::LeftToRight );
\r
260 Rect<int> InputMethodContextWin::GetInputMethodArea()
\r
262 int xPos, yPos, width, height;
\r
264 width = height = xPos = yPos = 0;
\r
266 return Rect<int>(xPos,yPos,width,height);
\r
269 void InputMethodContextWin::ApplyOptions( const InputMethodOptions& options )
\r
271 using namespace Dali::InputMethod::Category;
\r
275 if ( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) )
\r
278 if ( mOptions.CompareAndSet(BUTTON_ACTION, options, index) )
\r
281 if ( mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index) )
\r
284 if ( mOptions.CompareAndSet(VARIATION, options, index) )
\r
289 void InputMethodContextWin::SetInputPanelData( const std::string& data )
\r
291 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelData\n" );
\r
294 void InputMethodContextWin::GetInputPanelData( std::string& data )
\r
296 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelData\n" );
\r
299 Dali::InputMethodContext::State InputMethodContextWin::GetInputPanelState()
\r
301 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelState\n" );
\r
302 return Dali::InputMethodContext::DEFAULT;
\r
305 void InputMethodContextWin::SetReturnKeyState( bool visible )
\r
307 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetReturnKeyState\n" );
\r
310 void InputMethodContextWin::AutoEnableInputPanel( bool enabled )
\r
312 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::AutoEnableInputPanel\n" );
\r
315 void InputMethodContextWin::ShowInputPanel()
\r
317 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::ShowInputPanel\n" );
\r
320 void InputMethodContextWin::HideInputPanel()
\r
322 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::HideInputPanel\n" );
\r
325 Dali::InputMethodContext::KeyboardType InputMethodContextWin::GetKeyboardType()
\r
327 return Dali::InputMethodContext::KeyboardType::SOFTWARE_KEYBOARD;
\r
330 std::string InputMethodContextWin::GetInputPanelLocale()
\r
332 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelLocale\n" );
\r
334 std::string locale = "";
\r
338 void InputMethodContextWin::SetContentMIMETypes( const std::string& mimeTypes )
\r
340 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetContentMIMETypes\n" );
\r
343 bool InputMethodContextWin::FilterEventKey( const Dali::KeyEvent& keyEvent )
\r
345 bool eventHandled( false );
\r
347 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ))
\r
349 //check whether it's key down or key up event
\r
350 if ( keyEvent.state == KeyEvent::Down )
\r
352 eventHandled = ProcessEventKeyDown( keyEvent );
\r
354 else if ( keyEvent.state == KeyEvent::Up )
\r
356 eventHandled = ProcessEventKeyUp( keyEvent );
\r
360 return eventHandled;
\r
363 void InputMethodContextWin::SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language )
\r
365 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelLanguage\n" );
\r
368 Dali::InputMethodContext::InputPanelLanguage InputMethodContextWin::GetInputPanelLanguage() const
\r
370 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelLanguage\n" );
\r
371 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
\r
374 bool InputMethodContextWin::ProcessEventKeyDown( const KeyEvent& keyEvent )
\r
376 bool eventHandled( false );
\r
377 return eventHandled;
\r
380 bool InputMethodContextWin::ProcessEventKeyUp( const KeyEvent& keyEvent )
\r
382 bool eventHandled( false );
\r
383 return eventHandled;
\r