2 * Copyright (c) 2014 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 "virtual-keyboard-impl.h"
24 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/integration-api/debug.h>
29 #include <locale-utils.h>
30 #include <imf-manager-impl.h>
41 namespace VirtualKeyboard
46 #if defined(DEBUG_ENABLED)
47 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VIRTUAL_KEYBOARD");
50 #define TOKEN_STRING(x) #x
52 //forward declarations
53 void InputPanelGeometryChangedCallback ( void *data, Ecore_IMF_Context *context, int value );
54 void InputPanelLanguageChangeCallback( void* data, Ecore_IMF_Context* context, int value );
57 Dali::VirtualKeyboard::StatusSignalType gKeyboardStatusSignal;
58 Dali::VirtualKeyboard::VoidSignalType gKeyboardResizeSignal;
59 Dali::VirtualKeyboard::VoidSignalType gKeyboardLanguageChangedSignal;
61 void InputPanelStateChangeCallback( void* data, Ecore_IMF_Context* context, int value )
65 case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
67 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB ECORE_IMF_INPUT_PANEL_STATE_SHOW\n" );
69 gKeyboardStatusSignal.Emit( true );
74 case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
76 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB ECORE_IMF_INPUT_PANEL_STATE_HIDE\n" );
78 gKeyboardStatusSignal.Emit( false );
83 case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:
92 void InputPanelLanguageChangeCallback( void* data, Ecore_IMF_Context* context, int value )
94 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB InputPanelLanguageChangeCallback" );
96 // Emit the signal that the language has changed
97 gKeyboardLanguageChangedSignal.Emit();
100 void InputPanelGeometryChangedCallback ( void *data, Ecore_IMF_Context *context, int value )
102 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB InputPanelGeometryChangedCallback\n" );
104 // Emit signal that the keyboard is resized
105 gKeyboardResizeSignal.Emit();
108 } // unnamed namespace
110 void ConnectCallbacks( Ecore_IMF_Context *imfContext )
114 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB ConnectPanelCallbacks\n" );
116 ecore_imf_context_input_panel_event_callback_add( imfContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, InputPanelStateChangeCallback, NULL );
117 ecore_imf_context_input_panel_event_callback_add( imfContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, InputPanelLanguageChangeCallback, NULL );
118 ecore_imf_context_input_panel_event_callback_add( imfContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, InputPanelGeometryChangedCallback, NULL );
122 void DisconnectCallbacks( Ecore_IMF_Context *imfContext )
126 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB DisconnectPanelCallbacks\n" );
128 ecore_imf_context_input_panel_event_callback_del( imfContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, InputPanelStateChangeCallback );
129 ecore_imf_context_input_panel_event_callback_del( imfContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, InputPanelLanguageChangeCallback );
130 ecore_imf_context_input_panel_event_callback_del( imfContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, InputPanelGeometryChangedCallback );
136 Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) to show the keyboard
137 Ecore_IMF_Context* imfContext = NULL;
141 imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
145 ecore_imf_context_input_panel_show( imfContext );
152 if( ImfManager::IsAvailable() /* We do not want to create an ImfManager instance*/ )
154 Dali::ImfManager imfManager = ImfManager::Get();
155 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
159 ecore_imf_context_input_panel_hide( imfContext );
166 if( ImfManager::IsAvailable() /* We do not want to create an ImfManager instance */ )
168 DALI_LOG_INFO( gLogFilter, Debug::General, "IMF IsVisible\n" );
170 Dali::ImfManager imfManager = ImfManager::Get();
171 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
175 if (ecore_imf_context_input_panel_state_get(imfContext) == ECORE_IMF_INPUT_PANEL_STATE_SHOW ||
176 ecore_imf_context_input_panel_state_get(imfContext) == ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW)
186 void ApplySettings( const Property::Map& settingsMap )
188 using namespace InputMethod; // Allows exclusion of namespace in TOKEN_STRING.
190 for ( unsigned int i = 0, count = settingsMap.Count(); i < count; ++i )
192 std::string key = settingsMap.GetKey( i );
193 Property::Value item = settingsMap.GetValue(i);
195 if ( key == TOKEN_STRING( ACTION_BUTTON ) )
197 if ( item.GetType() == Property::INTEGER )
199 int value = item.Get< int >();
200 VirtualKeyboard::SetReturnKeyType( static_cast<InputMethod::ActionButton>(value) );
205 DALI_LOG_INFO( gLogFilter, Debug::General, "Provided Settings Key not supported\n" );
210 void EnablePrediction(const bool enable)
212 Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) when enabling prediction
213 Ecore_IMF_Context* imfContext = NULL;
217 imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
221 ecore_imf_context_prediction_allow_set( imfContext, (enable)? EINA_TRUE : EINA_FALSE);
226 bool IsPredictionEnabled()
228 if ( ImfManager::IsAvailable() /* We do not want to create an instance of ImfManger */ )
230 Dali::ImfManager imfManager = ImfManager::Get();
231 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
235 // predictive text is enabled.
236 if ( ecore_imf_context_input_panel_enabled_get( imfContext ) == EINA_TRUE )
246 Rect<int> GetSizeAndPosition()
248 int xPos, yPos, width, height;
250 width = height = xPos = yPos = 0;
251 Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) as we may need to do some size related setup in the application
252 Ecore_IMF_Context* imfContext = NULL;
256 imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
260 ecore_imf_context_input_panel_geometry_get(imfContext, &xPos, &yPos, &width, &height);
264 DALI_LOG_WARNING("VKB Unable to get IMF Context so GetSize unavailable\n");
265 // return 0 as real size unknown.
269 return Rect<int>(xPos,yPos,width,height);
272 Dali::VirtualKeyboard::StatusSignalType& StatusChangedSignal()
274 return gKeyboardStatusSignal;
277 Dali::VirtualKeyboard::VoidSignalType& ResizedSignal()
279 return gKeyboardResizeSignal;
282 Dali::VirtualKeyboard::VoidSignalType& LanguageChangedSignal()
284 return gKeyboardLanguageChangedSignal;
287 Dali::VirtualKeyboard::TextDirection GetTextDirection()
289 Dali::VirtualKeyboard::TextDirection direction ( Dali::VirtualKeyboard::LeftToRight );
291 if ( ImfManager::IsAvailable() /* We do not want to create an instance of ImfManager */ )
293 Dali::ImfManager imfManager = ImfManager::Get();
297 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
301 char* locale( NULL );
302 ecore_imf_context_input_panel_language_locale_get( imfContext, &locale );
306 direction = Locale::GetTextDirection( std::string( locale ) );
315 } // namespace VirtualKeyboard
317 } // namespace Adaptor
319 } // namespace Internal