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