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( Dali::Actor actor )
\r
46 InputMethodContextPtr manager;
\r
48 if ( actor && Adaptor::IsAvailable() )
\r
50 manager = new InputMethodContextWin( actor );
\r
56 void InputMethodContextWin::Finalize()
\r
60 InputMethodContextWin::InputMethodContextWin( Dali::Actor actor )
\r
61 : mWin32Window( 0 ),
\r
62 mIMFCursorPosition( 0 ),
\r
64 mRestoreAfterFocusLost( false ),
\r
65 mIdleCallbackConnected( false ),
\r
66 mPreeditType( Dali::InputMethodContext::PreeditStyle::NONE )
\r
69 actor.OnStageSignal().Connect( this, &InputMethodContextWin::OnStaged );
\r
72 InputMethodContextWin::~InputMethodContextWin()
\r
77 void InputMethodContextWin::Initialize()
\r
79 CreateContext( mWin32Window );
\r
83 void InputMethodContextWin::CreateContext( WinWindowHandle winHandle )
\r
85 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::CreateContext\n" );
\r
88 void InputMethodContextWin::DeleteContext()
\r
90 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::DeleteContext\n" );
\r
93 // Callbacks for predicitive text support.
\r
94 void InputMethodContextWin::ConnectCallbacks()
\r
98 void InputMethodContextWin::DisconnectCallbacks()
\r
102 void InputMethodContextWin::Activate()
\r
104 // Reset mIdleCallbackConnected
\r
105 mIdleCallbackConnected = false;
\r
108 void InputMethodContextWin::Deactivate()
\r
110 mIdleCallbackConnected = false;
\r
113 void InputMethodContextWin::Reset()
\r
115 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::Reset\n" );
\r
118 ImfContext* InputMethodContextWin::GetContext()
\r
120 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetContext\n" );
\r
125 bool InputMethodContextWin::RestoreAfterFocusLost() const
\r
127 return mRestoreAfterFocusLost;
\r
130 void InputMethodContextWin::SetRestoreAfterFocusLost( bool toggle )
\r
132 mRestoreAfterFocusLost = toggle;
\r
136 * Called when an InputMethodContext Pre-Edit changed event is received.
\r
137 * We are still predicting what the user is typing. The latest string is what the InputMethodContext module thinks
\r
138 * the user wants to type.
\r
140 void InputMethodContextWin::PreEditChanged( void*, ImfContext* imfContext, void* eventInfo )
\r
142 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::PreEditChanged\n" );
\r
145 void InputMethodContextWin::CommitReceived( void*, ImfContext* imfContext, void* eventInfo )
\r
147 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::CommitReceived\n" );
\r
149 if ( Dali::Adaptor::IsAvailable() )
\r
151 const std::string keyString( static_cast<char*>( eventInfo ) );
\r
153 Dali::InputMethodContext handle( this );
\r
154 Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::COMMIT, keyString, 0, 0 );
\r
155 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );
\r
157 if( callbackData.update )
\r
159 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
\r
161 NotifyCursorPosition();
\r
167 * Called when an InputMethodContext retrieve surround event is received.
\r
168 * Here the InputMethodContext module wishes to know the string we are working with and where within the string the cursor is
\r
169 * We need to signal the application to tell us this information.
\r
171 bool InputMethodContextWin::RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition )
\r
173 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::RetrieveSurrounding\n" );
\r
175 Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0 );
\r
176 Dali::InputMethodContext handle( this );
\r
177 Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );
\r
179 if( callbackData.update )
\r
183 *text = strdup( callbackData.currentText.c_str() );
\r
186 if( cursorPosition )
\r
188 mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );
\r
189 *cursorPosition = mIMFCursorPosition;
\r
197 * Called when an InputMethodContext delete surrounding event is received.
\r
198 * Here we tell the application that it should delete a certain range.
\r
200 void InputMethodContextWin::DeleteSurrounding( void* data, ImfContext* imfContext, void* eventInfo )
\r
202 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::DeleteSurrounding\n" );
\r
205 void InputMethodContextWin::NotifyCursorPosition()
\r
207 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::NotifyCursorPosition\n" );
\r
210 void InputMethodContextWin::SetCursorPosition( unsigned int cursorPosition )
\r
212 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetCursorPosition\n" );
\r
214 mIMFCursorPosition = static_cast<int>( cursorPosition );
\r
217 unsigned int InputMethodContextWin::GetCursorPosition() const
\r
219 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetCursorPosition\n" );
\r
221 return static_cast<unsigned int>( mIMFCursorPosition );
\r
224 void InputMethodContextWin::SetSurroundingText( const std::string& text )
\r
226 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetSurroundingText\n" );
\r
228 mSurroundingText = text;
\r
231 const std::string& InputMethodContextWin::GetSurroundingText() const
\r
233 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetSurroundingText\n" );
\r
235 return mSurroundingText;
\r
238 void InputMethodContextWin::NotifyTextInputMultiLine( bool multiLine )
\r
242 Dali::InputMethodContext::TextDirection InputMethodContextWin::GetTextDirection()
\r
244 Dali::InputMethodContext::TextDirection direction ( Dali::InputMethodContext::LeftToRight );
\r
249 Rect<int> InputMethodContextWin::GetInputMethodArea()
\r
251 int xPos, yPos, width, height;
\r
253 width = height = xPos = yPos = 0;
\r
255 return Rect<int>(xPos,yPos,width,height);
\r
258 void InputMethodContextWin::ApplyOptions( const InputMethodOptions& options )
\r
260 using namespace Dali::InputMethod::Category;
\r
264 if ( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) )
\r
267 if ( mOptions.CompareAndSet(BUTTON_ACTION, options, index) )
\r
270 if ( mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index) )
\r
273 if ( mOptions.CompareAndSet(VARIATION, options, index) )
\r
278 void InputMethodContextWin::SetInputPanelData( const std::string& data )
\r
280 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelData\n" );
\r
283 void InputMethodContextWin::GetInputPanelData( std::string& data )
\r
285 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelData\n" );
\r
288 Dali::InputMethodContext::State InputMethodContextWin::GetInputPanelState()
\r
290 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelState\n" );
\r
291 return Dali::InputMethodContext::DEFAULT;
\r
294 void InputMethodContextWin::SetReturnKeyState( bool visible )
\r
296 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetReturnKeyState\n" );
\r
299 void InputMethodContextWin::AutoEnableInputPanel( bool enabled )
\r
301 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::AutoEnableInputPanel\n" );
\r
304 void InputMethodContextWin::ShowInputPanel()
\r
306 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::ShowInputPanel\n" );
\r
309 void InputMethodContextWin::HideInputPanel()
\r
311 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::HideInputPanel\n" );
\r
314 Dali::InputMethodContext::KeyboardType InputMethodContextWin::GetKeyboardType()
\r
316 return Dali::InputMethodContext::KeyboardType::SOFTWARE_KEYBOARD;
\r
319 std::string InputMethodContextWin::GetInputPanelLocale()
\r
321 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelLocale\n" );
\r
323 std::string locale = "";
\r
327 void InputMethodContextWin::SetContentMIMETypes( const std::string& mimeTypes )
\r
329 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetContentMIMETypes\n" );
\r
332 bool InputMethodContextWin::FilterEventKey( const Dali::KeyEvent& keyEvent )
\r
334 bool eventHandled( false );
\r
336 if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ))
\r
338 //check whether it's key down or key up event
\r
339 if ( keyEvent.state == KeyEvent::Down )
\r
341 eventHandled = ProcessEventKeyDown( keyEvent );
\r
343 else if ( keyEvent.state == KeyEvent::Up )
\r
345 eventHandled = ProcessEventKeyUp( keyEvent );
\r
349 return eventHandled;
\r
352 void InputMethodContextWin::SetInputPanelLanguage( Dali::InputMethodContext::InputPanelLanguage language )
\r
354 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelLanguage\n" );
\r
357 Dali::InputMethodContext::InputPanelLanguage InputMethodContextWin::GetInputPanelLanguage() const
\r
359 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelLanguage\n" );
\r
360 return Dali::InputMethodContext::InputPanelLanguage::AUTOMATIC;
\r
363 void InputMethodContextWin::SetInputPanelPosition( unsigned int x, unsigned int y )
\r
365 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelPosition\n" );
\r
368 Dali::InputMethodContext::PreeditStyle InputMethodContextWin::GetPreeditStyle() const
\r
370 DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetPreeditStyle\n" );
\r
371 return mPreeditType;
\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
386 void InputMethodContextWin::OnStaged( Dali::Actor actor )
\r
388 WinWindowHandle winWindow( AnyCast< WinWindowHandle >( Dali::Integration::SceneHolder::Get( actor ).GetNativeHandle() ) );
\r
390 if( mWin32Window != winWindow )
\r
392 mWin32Window = winWindow;
\r