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::StatusSignalV2 gKeyboardStatusSignalV2;
57 Dali::VirtualKeyboard::VoidSignalV2 gKeyboardResizeSignalV2;
58 Dali::VirtualKeyboard::VoidSignalV2 gKeyboardLanguageChangedSignalV2;
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 gKeyboardStatusSignalV2.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 gKeyboardStatusSignalV2.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 gKeyboardLanguageChangedSignalV2.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 gKeyboardResizeSignalV2.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 if( Dali::Adaptor::IsAvailable() )
139 Dali::ImfManager imfManager = ImfManager::Get();
140 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
144 ecore_imf_context_input_panel_show( imfContext );
151 if( Dali::Adaptor::IsAvailable() )
153 Dali::ImfManager imfManager = ImfManager::Get();
154 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
158 ecore_imf_context_input_panel_hide( imfContext );
165 if( Dali::Adaptor::IsAvailable() )
167 DALI_LOG_INFO( gLogFilter, Debug::General, "IsVisible\n" );
169 Dali::ImfManager imfManager = ImfManager::Get();
170 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
174 if (ecore_imf_context_input_panel_state_get(imfContext) == ECORE_IMF_INPUT_PANEL_STATE_SHOW ||
175 ecore_imf_context_input_panel_state_get(imfContext) == ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW)
185 void SetReturnKeyType( Dali::VirtualKeyboard::ReturnKeyType type )
187 if ( Dali::Adaptor::IsAvailable() )
189 Dali::ImfManager imfManager = ImfManager::Get();
190 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
194 DALI_LOG_INFO( gLogFilter, Debug::General, "VKB Retrun key type is changed[%d]\n", type );
196 gReturnKeyType = type;
197 ecore_imf_context_input_panel_return_key_type_set( imfContext, static_cast<Ecore_IMF_Input_Panel_Return_Key_Type>( type ) );
202 Dali::VirtualKeyboard::ReturnKeyType GetReturnKeyType()
204 return gReturnKeyType;
207 void EnablePrediction(const bool enable)
209 if ( Dali::Adaptor::IsAvailable() )
211 Dali::ImfManager imfManager = ImfManager::Get();
212 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
216 ecore_imf_context_prediction_allow_set( imfContext, (enable)? EINA_TRUE : EINA_FALSE);
221 bool IsPredictionEnabled()
223 if ( Dali::Adaptor::IsAvailable() )
225 Dali::ImfManager imfManager = ImfManager::Get();
226 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
230 // predictive text is enabled.
231 if ( ecore_imf_context_input_panel_enabled_get( imfContext ) == EINA_TRUE )
241 Rect<int> GetSizeAndPosition()
243 int xPos, yPos, width, height;
245 width = height = xPos = yPos = 0;
246 if ( Dali::Adaptor::IsAvailable() )
248 Dali::ImfManager imfManager = ImfManager::Get();
249 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
253 ecore_imf_context_input_panel_geometry_get(imfContext, &xPos, &yPos, &width, &height);
257 DALI_LOG_WARNING("VKB Unable to get IMF Context so GetSize unavailable\n");
258 // return 0 as real size unknown.
262 return Rect<int>(xPos,yPos,width,height);
265 Dali::VirtualKeyboard::StatusSignalV2& StatusChangedSignal()
267 return gKeyboardStatusSignalV2;
270 Dali::VirtualKeyboard::VoidSignalV2& ResizedSignal()
272 return gKeyboardResizeSignalV2;
275 Dali::VirtualKeyboard::VoidSignalV2& LanguageChangedSignal()
277 return gKeyboardLanguageChangedSignalV2;
280 Dali::VirtualKeyboard::TextDirection GetTextDirection()
282 Dali::VirtualKeyboard::TextDirection direction ( Dali::VirtualKeyboard::LeftToRight );
284 if ( Dali::Adaptor::IsAvailable() )
286 Dali::ImfManager imfManager = ImfManager::Get();
290 Ecore_IMF_Context* imfContext = reinterpret_cast<Ecore_IMF_Context*>( imfManager.GetContext() );
294 char* locale( NULL );
295 ecore_imf_context_input_panel_language_locale_get( imfContext, &locale );
299 direction = Locale::GetTextDirection( std::string( locale ) );
308 } // namespace VirtualKeyboard
310 } // namespace Adaptor
312 } // namespace Internal