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