Fix conversion warnings for event refactor
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / tizen-wayland / ecore-virtual-keyboard.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/input/common/virtual-keyboard-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <algorithm>
23
24 #include <dali/integration-api/debug.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/internal/input/tizen-wayland/ecore-virtual-keyboard.h>
28 #include <dali/integration-api/adaptor.h>
29 #include <dali/internal/system/common/locale-utils.h>
30 #include <dali/internal/input/common/input-method-context-impl.h>
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 namespace Adaptor
39 {
40
41 namespace VirtualKeyboard
42 {
43
44 namespace
45 {
46 #if defined(DEBUG_ENABLED)
47 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VIRTUAL_KEYBOARD");
48 #endif
49
50 #define TOKEN_STRING(x) #x
51
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 );
55
56 // Signals
57 Dali::VirtualKeyboard::StatusSignalType gKeyboardStatusSignal;
58 Dali::VirtualKeyboard::VoidSignalType   gKeyboardResizeSignal;
59 Dali::VirtualKeyboard::VoidSignalType   gKeyboardLanguageChangedSignal;
60
61 void InputPanelStateChangeCallback( void* data, Ecore_IMF_Context* context, int value )
62 {
63   switch (value)
64   {
65     case ECORE_IMF_INPUT_PANEL_STATE_SHOW:
66     {
67       DALI_LOG_INFO( gLogFilter, Debug::General, "VKB ECORE_IMF_INPUT_PANEL_STATE_SHOW\n" );
68
69       gKeyboardStatusSignal.Emit( true );
70
71       break;
72     }
73
74     case ECORE_IMF_INPUT_PANEL_STATE_HIDE:
75     {
76       DALI_LOG_INFO( gLogFilter, Debug::General, "VKB ECORE_IMF_INPUT_PANEL_STATE_HIDE\n" );
77
78       gKeyboardStatusSignal.Emit( false );
79
80       break;
81     }
82
83     case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:
84     default:
85     {
86       // Do nothing
87       break;
88     }
89   }
90 }
91
92 void InputPanelLanguageChangeCallback( void* data, Ecore_IMF_Context* context, int value )
93 {
94   DALI_LOG_INFO( gLogFilter, Debug::General, "VKB InputPanelLanguageChangeCallback\n" );
95
96   // Emit the signal that the language has changed
97   gKeyboardLanguageChangedSignal.Emit();
98 }
99
100 void InputPanelGeometryChangedCallback ( void *data, Ecore_IMF_Context *context, int value )
101 {
102   DALI_LOG_INFO( gLogFilter, Debug::General, "VKB InputPanelGeometryChangedCallback\n" );
103
104   // Emit signal that the keyboard is resized
105   gKeyboardResizeSignal.Emit();
106 }
107
108 } // unnamed namespace
109
110 void ConnectCallbacks( Ecore_IMF_Context *imfContext )
111 {
112   if( imfContext )
113   {
114     DALI_LOG_INFO( gLogFilter, Debug::General, "VKB ConnectPanelCallbacks\n" );
115
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 );
119   }
120 }
121
122 void DisconnectCallbacks( Ecore_IMF_Context *imfContext )
123 {
124   if( imfContext )
125   {
126     DALI_LOG_INFO( gLogFilter, Debug::General, "VKB DisconnectPanelCallbacks\n" );
127
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 );
131   }
132 }
133
134 void Show()
135 {
136   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: Show() is deprecated and will be removed from next release. Use InputMethodContext.Activate() instead.\n" );
137 }
138
139 void Hide()
140 {
141   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: Hide() is deprecated and will be removed from next release. Use InputMethodContext.Deactivate() instead.\n" );
142 }
143
144 bool IsVisible()
145 {
146   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: IsVisible() is deprecated and will be removed from next release.\n" );
147   return false;
148 }
149
150 void ApplySettings( const Property::Map& settingsMap )
151 {
152   using namespace InputMethod; // Allows exclusion of namespace in TOKEN_STRING.
153
154   for ( unsigned long i = 0, count = settingsMap.Count(); i < count; ++i )
155   {
156     Property::Key key = settingsMap.GetKeyAt( i );
157     if( key.type == Property::Key::INDEX )
158     {
159       continue;
160     }
161
162     Property::Value item = settingsMap.GetValue(i);
163
164     if ( key == TOKEN_STRING( BUTTON_ACTION ) )
165     {
166       if ( item.GetType() == Property::INTEGER )
167       {
168         int value = item.Get< int >();
169         VirtualKeyboard::SetReturnKeyType( static_cast<InputMethod::ButtonAction::Type>(value) );
170       }
171     }
172     else
173     {
174       DALI_LOG_INFO( gLogFilter, Debug::General, "Provided Settings Key not supported\n" );
175     }
176   }
177 }
178
179 void EnablePrediction(const bool enable)
180 {
181 }
182
183 bool IsPredictionEnabled()
184 {
185   return false;
186 }
187
188 Rect<int> GetSizeAndPosition()
189 {
190   int xPos, yPos, width, height;
191
192   DALI_LOG_WARNING_NOFN("DEPRECATION WARNING: GetSizeAndPosition() is deprecated and will be removed from next release. Use InputMethodContext.GetInputMethodArea() instead.\n" );
193
194   width = height = xPos = yPos = 0;
195   return Rect<int>(xPos,yPos,width,height);
196 }
197
198 Dali::VirtualKeyboard::TextDirection GetTextDirection()
199 {
200   Dali::VirtualKeyboard::TextDirection direction ( Dali::VirtualKeyboard::LeftToRight );
201   return direction;
202 }
203
204 } // namespace VirtualKeyboard
205
206 } // namespace Adaptor
207
208 } // namespace Internal
209
210 } // namespace Dali