2 * Copyright (c) 2017 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 <dali/internal/input/common/virtual-keyboard-impl.h>
24 #include <dali/integration-api/debug.h>
27 // Ecore is littered with C style cast
28 #pragma GCC diagnostic push
29 #pragma GCC diagnostic ignored "-Wold-style-cast"
30 #include <dali/internal/input/tizen-wayland/ecore-virtual-keyboard.h>
31 #include <dali/integration-api/adaptor.h>
32 #include <dali/internal/system/common/locale-utils.h>
33 #include <dali/internal/input/common/imf-manager-impl.h>
44 namespace VirtualKeyboard
49 #if defined(DEBUG_ENABLED)
50 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VIRTUAL_KEYBOARD");
53 #define TOKEN_STRING(x) #x
55 //forward declarations
56 void InputPanelGeometryChangedCallback ( void *data, Ecore_IMF_Context *context, int value );
57 void InputPanelLanguageChangeCallback( void* data, Ecore_IMF_Context* context, int value );
60 Dali::VirtualKeyboard::StatusSignalType gKeyboardStatusSignal;
61 Dali::VirtualKeyboard::VoidSignalType gKeyboardResizeSignal;
62 Dali::VirtualKeyboard::VoidSignalType gKeyboardLanguageChangedSignal;
64 void InputPanelStateChangeCallback( void* data, Ecore_IMF_Context* context, int value )
68 case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
70 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB ECORE_IMF_INPUT_PANEL_STATE_SHOW\n" );
72 gKeyboardStatusSignal.Emit( true );
77 case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
79 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB ECORE_IMF_INPUT_PANEL_STATE_HIDE\n" );
81 gKeyboardStatusSignal.Emit( false );
86 case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:
95 void InputPanelLanguageChangeCallback( void* data, Ecore_IMF_Context* context, int value )
97 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB InputPanelLanguageChangeCallback\n" );
99 // Emit the signal that the language has changed
100 gKeyboardLanguageChangedSignal.Emit();
103 void InputPanelGeometryChangedCallback ( void *data, Ecore_IMF_Context *context, int value )
105 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB InputPanelGeometryChangedCallback\n" );
107 // Emit signal that the keyboard is resized
108 gKeyboardResizeSignal.Emit();
111 } // unnamed namespace
113 void ConnectCallbacks( Ecore_IMF_Context *imfContext )
117 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB ConnectPanelCallbacks\n" );
119 ecore_imf_context_input_panel_event_callback_add( imfContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, InputPanelStateChangeCallback, NULL );
120 ecore_imf_context_input_panel_event_callback_add( imfContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, InputPanelLanguageChangeCallback, NULL );
121 ecore_imf_context_input_panel_event_callback_add( imfContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, InputPanelGeometryChangedCallback, NULL );
125 void DisconnectCallbacks( Ecore_IMF_Context *imfContext )
129 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB DisconnectPanelCallbacks\n" );
131 ecore_imf_context_input_panel_event_callback_del( imfContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, InputPanelStateChangeCallback );
132 ecore_imf_context_input_panel_event_callback_del( imfContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, InputPanelLanguageChangeCallback );
133 ecore_imf_context_input_panel_event_callback_del( imfContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, InputPanelGeometryChangedCallback );
139 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: Show() is deprecated and will be removed from next release. Use ImfManager.Activate() instead.\n" );
141 Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) to show the keyboard
145 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
149 ecore_imf_context_input_panel_show( imfContext );
156 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: Hide() is deprecated and will be removed from next release. Use ImfManager.Deactivate() instead.\n" );
158 if( ImfManager::IsAvailable() /* We do not want to create an ImfManager instance*/ )
160 Dali::ImfManager imfManager = ImfManager::Get();
161 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
165 ecore_imf_context_input_panel_hide( imfContext );
172 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: IsVisible() is deprecated and will be removed from next release.\n" );
174 if( ImfManager::IsAvailable() /* We do not want to create an ImfManager instance */ )
176 DALI_LOG_INFO( gLogFilter, Debug::General, "IMF IsVisible\n" );
178 Dali::ImfManager imfManager = ImfManager::Get();
179 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
183 if (ecore_imf_context_input_panel_state_get(imfContext) == ECORE_IMF_INPUT_PANEL_STATE_SHOW ||
184 ecore_imf_context_input_panel_state_get(imfContext) == ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW)
194 void ApplySettings( const Property::Map& settingsMap )
196 using namespace InputMethod; // Allows exclusion of namespace in TOKEN_STRING.
198 for ( unsigned int i = 0, count = settingsMap.Count(); i < count; ++i )
200 Property::Key key = settingsMap.GetKeyAt( i );
201 if( key.type == Property::Key::INDEX )
206 Property::Value item = settingsMap.GetValue(i);
208 if ( key == TOKEN_STRING( ACTION_BUTTON ) )
210 if ( item.GetType() == Property::INTEGER )
212 int value = item.Get< int >();
213 VirtualKeyboard::SetReturnKeyType( static_cast<InputMethod::ActionButton>(value) );
218 DALI_LOG_INFO( gLogFilter, Debug::General, "Provided Settings Key not supported\n" );
223 void EnablePrediction(const bool enable)
225 Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) when enabling prediction
229 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
233 ecore_imf_context_prediction_allow_set( imfContext, (enable)? EINA_TRUE : EINA_FALSE);
238 bool IsPredictionEnabled()
240 if ( ImfManager::IsAvailable() /* We do not want to create an instance of ImfManger */ )
242 Dali::ImfManager imfManager = ImfManager::Get();
243 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
247 // predictive text is enabled.
248 if ( ecore_imf_context_input_panel_enabled_get( imfContext ) == EINA_TRUE )
258 Rect<int> GetSizeAndPosition()
260 int xPos, yPos, width, height;
262 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: GetSizeAndPosition() is deprecated and will be removed from next release. Use ImfManager.GetInputMethodArea() instead.\n" );
264 width = height = xPos = yPos = 0;
265 Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) as we may need to do some size related setup in the application
269 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
273 ecore_imf_context_input_panel_geometry_get(imfContext, &xPos, &yPos, &width, &height);
277 DALI_LOG_WARNING("VKB Unable to get IMF Context so GetSize unavailable\n");
278 // return 0 as real size unknown.
282 return Rect<int>(xPos,yPos,width,height);
285 Dali::VirtualKeyboard::StatusSignalType& StatusChangedSignal()
287 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: StatusChangedSignal() is deprecated and will be removed from next release. Use ImfManager.StatusChangedSignal() instead.\n" );
289 Dali::ImfManager imfManager = ImfManager::Get();
290 return imfManager.StatusChangedSignal();
293 Dali::VirtualKeyboard::KeyboardResizedSignalType& ResizedSignal()
295 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: ResizedSignal() is deprecated and will be removed from next release. Use ImfManager.ResizedSignal() instead.\n" );
297 Dali::ImfManager imfManager = ImfManager::Get();
298 return imfManager.ResizedSignal();
301 Dali::VirtualKeyboard::LanguageChangedSignalType& LanguageChangedSignal()
303 DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: LanguageChangedSignal() is deprecated and will be removed from next release. Use ImfManager.LanguageChangedSignal() instead.\n" );
305 Dali::ImfManager imfManager = ImfManager::Get();
306 return imfManager.LanguageChangedSignal();
309 Dali::VirtualKeyboard::TextDirection GetTextDirection()
311 Dali::VirtualKeyboard::TextDirection direction ( Dali::VirtualKeyboard::LeftToRight );
313 if ( ImfManager::IsAvailable() /* We do not want to create an instance of ImfManager */ )
315 Dali::ImfManager imfManager = ImfManager::Get();
319 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>(ImfManager::GetImplementation( imfManager ).GetContext());
323 char* locale( NULL );
324 ecore_imf_context_input_panel_language_locale_get( imfContext, &locale );
328 direction = static_cast< Dali::VirtualKeyboard::TextDirection >( Locale::GetDirection( std::string( locale ) ) );
337 } // namespace VirtualKeyboard
339 } // namespace Adaptor
341 } // namespace Internal
345 #pragma GCC diagnostic pop