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>
26 #include <dali/integration-api/debug.h>
29 #include <locale-utils.h>
30 #include <imf-manager-impl.h>
42 namespace VirtualKeyboard
47 #if defined(DEBUG_ENABLED)
48 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Verbose, false, "LOG_VIRTUAL_KEYBOARD");
51 //forward declarations
52 void InputPanelGeometryChangedCallback ( void *data, Ecore_IMF_Context *context, int value );
53 void InputPanelLanguageChangeCallback( void* data, Ecore_IMF_Context* context, int value );
56 Dali::VirtualKeyboard::StatusSignalType gKeyboardStatusSignal;
57 Dali::VirtualKeyboard::VoidSignalType gKeyboardResizeSignal;
58 Dali::VirtualKeyboard::VoidSignalType gKeyboardLanguageChangedSignal;
60 Dali::VirtualKeyboard::ReturnKeyType gReturnKeyType = Dali::VirtualKeyboard::DEFAULT; // the currently used return key type.
62 void InputPanelStateChangeCallback( void* data, Ecore_IMF_Context* context, int value )
66 case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
68 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB ECORE_IMF_INPUT_PANEL_STATE_SHOW\n" );
70 gKeyboardStatusSignal.Emit( true );
75 case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
77 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB ECORE_IMF_INPUT_PANEL_STATE_HIDE\n" );
79 gKeyboardStatusSignal.Emit( false );
84 case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:
93 void InputPanelLanguageChangeCallback( void* data, Ecore_IMF_Context* context, int value )
95 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB InputPanelLanguageChangeCallback" );
97 // Emit the signal that the language has changed
98 gKeyboardLanguageChangedSignal.Emit();
101 void InputPanelGeometryChangedCallback ( void *data, Ecore_IMF_Context *context, int value )
103 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB InputPanelGeometryChangedCallback\n" );
105 // Emit signal that the keyboard is resized
106 gKeyboardResizeSignal.Emit();
109 } // unnamed namespace
111 void ConnectCallbacks( Ecore_IMF_Context *imfContext )
115 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB ConnectPanelCallbacks\n" );
117 ecore_imf_context_input_panel_event_callback_add( imfContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, InputPanelStateChangeCallback, NULL );
118 ecore_imf_context_input_panel_event_callback_add( imfContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, InputPanelLanguageChangeCallback, NULL );
119 ecore_imf_context_input_panel_event_callback_add( imfContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, InputPanelGeometryChangedCallback, NULL );
123 void DisconnectCallbacks( Ecore_IMF_Context *imfContext )
127 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB DisconnectPanelCallbacks\n" );
129 ecore_imf_context_input_panel_event_callback_del( imfContext, ECORE_IMF_INPUT_PANEL_STATE_EVENT, InputPanelStateChangeCallback );
130 ecore_imf_context_input_panel_event_callback_del( imfContext, ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT, InputPanelLanguageChangeCallback );
131 ecore_imf_context_input_panel_event_callback_del( imfContext, ECORE_IMF_INPUT_PANEL_GEOMETRY_EVENT, InputPanelGeometryChangedCallback );
137 Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) to show the keyboard
138 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
142 ecore_imf_context_input_panel_show( imfContext );
148 if( ImfManager::IsAvailable() /* We do not want to create an ImfManager instance*/ )
150 Dali::ImfManager imfManager = ImfManager::Get();
151 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
155 ecore_imf_context_input_panel_hide( imfContext );
162 if( ImfManager::IsAvailable() /* We do not want to create an ImfManager instance */ )
164 DALI_LOG_INFO( gLogFilter, Debug::General, "IsVisible\n" );
166 Dali::ImfManager imfManager = ImfManager::Get();
167 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
171 if (ecore_imf_context_input_panel_state_get(imfContext) == ECORE_IMF_INPUT_PANEL_STATE_SHOW ||
172 ecore_imf_context_input_panel_state_get(imfContext) == ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW)
182 void SetReturnKeyType( Dali::VirtualKeyboard::ReturnKeyType type )
184 Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) when setting values
185 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
189 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB Retrun key type is changed[%d]\n", type );
191 gReturnKeyType = type;
192 ecore_imf_context_input_panel_return_key_type_set( imfContext, static_cast<Ecore_IMF_Input_Panel_Return_Key_Type>( type ) );
196 Dali::VirtualKeyboard::ReturnKeyType GetReturnKeyType()
198 return gReturnKeyType;
201 void EnablePrediction(const bool enable)
203 Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) when enabling prediction
204 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
208 ecore_imf_context_prediction_allow_set( imfContext, (enable)? EINA_TRUE : EINA_FALSE);
212 bool IsPredictionEnabled()
214 if ( ImfManager::IsAvailable() /* We do not want to create an instance of ImfManger */ )
216 Dali::ImfManager imfManager = ImfManager::Get();
217 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
221 // predictive text is enabled.
222 if ( ecore_imf_context_input_panel_enabled_get( imfContext ) == EINA_TRUE )
232 Rect<int> GetSizeAndPosition()
234 int xPos, yPos, width, height;
236 width = height = xPos = yPos = 0;
237 Dali::ImfManager imfManager = ImfManager::Get(); // Create ImfManager instance (if required) as we may need to do some size related setup in the application
238 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
242 ecore_imf_context_input_panel_geometry_get(imfContext, &xPos, &yPos, &width, &height);
246 DALI_LOG_WARNING("VKB Unable to get IMF Context so GetSize unavailable\n");
247 // return 0 as real size unknown.
250 return Rect<int>(xPos,yPos,width,height);
253 Dali::VirtualKeyboard::StatusSignalType& StatusChangedSignal()
255 return gKeyboardStatusSignal;
258 Dali::VirtualKeyboard::VoidSignalType& ResizedSignal()
260 return gKeyboardResizeSignal;
263 Dali::VirtualKeyboard::VoidSignalType& LanguageChangedSignal()
265 return gKeyboardLanguageChangedSignal;
268 Dali::VirtualKeyboard::TextDirection GetTextDirection()
270 Dali::VirtualKeyboard::TextDirection direction ( Dali::VirtualKeyboard::LeftToRight );
272 if ( ImfManager::IsAvailable() /* We do not want to create an instance of ImfManager */ )
274 Dali::ImfManager imfManager = ImfManager::Get();
278 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
282 char* locale( NULL );
283 ecore_imf_context_input_panel_language_locale_get( imfContext, &locale );
287 direction = Locale::GetTextDirection( std::string( locale ) );
296 } // namespace VirtualKeyboard
298 } // namespace Adaptor
300 } // namespace Internal