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