7c09270d4cd26996595928dc5d5120717296a88f
[platform/core/uifw/dali-adaptor.git] / dali / internal / input / windows / input-method-context-impl-win.cpp
1 /*\r
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  *\r
16  */\r
17 \r
18 // CLASS HEADER\r
19 #include <dali/internal/input/windows/input-method-context-impl-win.h>\r
20 \r
21 // EXTERNAL INCLUDES\r
22 //#include <Ecore_IMF.h>\r
23 //#include <Ecore_Input.h>\r
24 #include <dali/public-api/events/key-event.h>\r
25 #include <dali/public-api/adaptor-framework/key.h>\r
26 #include <dali/public-api/object/type-registry.h>\r
27 #include <dali/integration-api/debug.h>\r
28 \r
29 // INTERNAL INCLUDES\r
30 #include <dali/integration-api/adaptor.h>\r
31 #include <dali/internal/adaptor/common/adaptor-impl.h>\r
32 #include <dali/internal/system/common/locale-utils.h>\r
33 #include <dali/internal/system/common/singleton-service-impl.h>\r
34 #include <dali/internal/input/common/virtual-keyboard-impl.h>\r
35 #include <dali/internal/input/common/key-impl.h>\r
36 // Ecore is littered with C style cast\r
37 #pragma GCC diagnostic push\r
38 #pragma GCC diagnostic ignored "-Wold-style-cast"\r
39 //#include <dali/internal/input/tizen-wayland/ecore-virtual-keyboard.h>\r
40 \r
41 namespace Dali\r
42 {\r
43 \r
44 namespace Internal\r
45 {\r
46 \r
47 namespace Adaptor\r
48 {\r
49 \r
50 namespace\r
51 {\r
52 #if defined(DEBUG_ENABLED)\r
53 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_INPUT_METHOD_CONTEXT");\r
54 #endif\r
55 \r
56 // Currently this code is internal to dali/dali/internal/event/text/utf8.h but should be made Public and used from there instead.\r
57 size_t Utf8SequenceLength(const unsigned char leadByte)\r
58 {\r
59   size_t length = 0;\r
60 \r
61   if ((leadByte & 0x80) == 0 )          //ASCII character (lead bit zero)\r
62   {\r
63     length = 1;\r
64   }\r
65   else if (( leadByte & 0xe0 ) == 0xc0 ) //110x xxxx\r
66   {\r
67     length = 2;\r
68   }\r
69   else if (( leadByte & 0xf0 ) == 0xe0 ) //1110 xxxx\r
70   {\r
71     length = 3;\r
72   }\r
73   else if (( leadByte & 0xf8 ) == 0xf0 ) //1111 0xxx\r
74   {\r
75     length = 4;\r
76   }\r
77 \r
78   return length;\r
79 }\r
80 //\r
81 //// Static function calls used by ecore 'c' style callback registration\r
82 //void Commit( void *data, Ecore_IMF_Context *imfContext, void *event_info )\r
83 //{\r
84 //  if ( data )\r
85 //  {\r
86 //    InputMethodContextWin* inputMethodContext = reinterpret_cast< InputMethodContextWin* > ( data );\r
87 //    inputMethodContext->CommitReceived( data, imfContext, event_info );\r
88 //  }\r
89 //}\r
90 //\r
91 //void PreEdit( void *data, Ecore_IMF_Context *imfContext, void *event_info )\r
92 //{\r
93 //  if ( data )\r
94 //  {\r
95 //    InputMethodContextWin* inputMethodContext = reinterpret_cast< InputMethodContextWin* > ( data );\r
96 //    inputMethodContext->PreEditChanged( data, imfContext, event_info );\r
97 //  }\r
98 //}\r
99 //\r
100 //Eina_Bool ImfRetrieveSurrounding(void *data, Ecore_IMF_Context *imfContext, char** text, int* cursorPosition )\r
101 //{\r
102 //  if ( data )\r
103 //  {\r
104 //    InputMethodContextWin* inputMethodContext = reinterpret_cast< InputMethodContextWin* > ( data );\r
105 //    return inputMethodContext->RetrieveSurrounding( data, imfContext, text, cursorPosition );\r
106 //  }\r
107 //  else\r
108 //  {\r
109 //    return false;\r
110 //  }\r
111 //}\r
112 //\r
113 ///**\r
114 // * Called when an InputMethodContext delete surrounding event is received.\r
115 // * Here we tell the application that it should delete a certain range.\r
116 // */\r
117 //void ImfDeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *event_info )\r
118 //{\r
119 //  if ( data )\r
120 //  {\r
121 //    InputMethodContextWin* inputMethodContext = reinterpret_cast< InputMethodContextWin* > ( data );\r
122 //    inputMethodContext->DeleteSurrounding( data, imfContext, event_info );\r
123 //  }\r
124 //}\r
125 \r
126 } // unnamed namespace\r
127 \r
128 InputMethodContextPtr InputMethodContextWin::New()\r
129 {\r
130   InputMethodContextPtr manager;\r
131 \r
132   if ( Adaptor::IsAvailable() )\r
133   {\r
134     // Create instance and register singleton only if the adaptor is available\r
135     Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );\r
136     Any nativeWindow = adaptorImpl.GetNativeWindowHandle();\r
137 \r
138     // The Win_Window_Handle needs to use the InputMethodContext.\r
139     // Only when the render surface is window, we can get the Win_Window_Handle.\r
140     Win_Window_Handle winWindow( AnyCast<Win_Window_Handle>(nativeWindow) );\r
141     if ( winWindow )\r
142     {\r
143       // If we fail to get Win_Window_Handle, we can't use the InputMethodContext correctly.\r
144       // Thus you have to call "ecore_imf_context_client_window_set" somewhere.\r
145       // In EvasPlugIn, this function is called in EvasPlugin::ConnectEcoreEvent().\r
146 \r
147       manager = new InputMethodContextWin( winWindow );\r
148     }\r
149     else\r
150     {\r
151       DALI_LOG_ERROR("Failed to get native window handle\n");\r
152     }\r
153   }\r
154 \r
155   return manager;\r
156 }\r
157 \r
158 void InputMethodContextWin::Finalize()\r
159 {\r
160   //DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::Finalize\n" );\r
161   //VirtualKeyboard::DisconnectCallbacks( mIMFContext );\r
162   //DisconnectCallbacks();\r
163   //DeleteContext();\r
164 }\r
165 \r
166 InputMethodContextWin::InputMethodContextWin( Win_Window_Handle winWindow )\r
167 : mWin32Window( winWindow ),\r
168   mIMFCursorPosition( 0 ),\r
169   mSurroundingText(),\r
170   mRestoreAfterFocusLost( false ),\r
171   mIdleCallbackConnected( false )\r
172 {\r
173   //ecore_imf_init();\r
174 }\r
175 \r
176 InputMethodContextWin::~InputMethodContextWin()\r
177 {\r
178   Finalize();\r
179   //ecore_imf_shutdown();\r
180 }\r
181 \r
182 void InputMethodContextWin::Initialize()\r
183 {\r
184   CreateContext( mWin32Window );\r
185   ConnectCallbacks();\r
186   //VirtualKeyboard::ConnectCallbacks( mIMFContext );\r
187 }\r
188 \r
189 void InputMethodContextWin::CreateContext( Win_Window_Handle ecoreXwin )\r
190 {\r
191   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::CreateContext\n" );\r
192 \r
193   //const char *contextId = ecore_imf_context_default_id_get();\r
194   //if( contextId )\r
195   //{\r
196   //  mIMFContext = ecore_imf_context_add( contextId );\r
197 \r
198   //  if( mIMFContext )\r
199   //  {\r
200   //    if( ecoreXwin )\r
201   //    {\r
202   //      ecore_imf_context_client_window_set( mIMFContext, reinterpret_cast<void*>( ecoreXwin ) );\r
203   //    }\r
204   //  }\r
205   //  else\r
206   //  {\r
207   //    DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");\r
208   //  }\r
209   //}\r
210   //else\r
211   //{\r
212   //  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContext Unable to get IMFContext\n");\r
213   //}\r
214 }\r
215 \r
216 void InputMethodContextWin::DeleteContext()\r
217 {\r
218   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::DeleteContext\n" );\r
219 \r
220   //if ( mIMFContext )\r
221   //{\r
222   //  ecore_imf_context_del( mIMFContext );\r
223   //  mIMFContext = NULL;\r
224   //}\r
225 }\r
226 \r
227 // Callbacks for predicitive text support.\r
228 void InputMethodContextWin::ConnectCallbacks()\r
229 {\r
230   //if ( mIMFContext )\r
231   //{\r
232   //  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::ConnectCallbacks\n" );\r
233 \r
234   //  ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED,    PreEdit,    this );\r
235   //  ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_COMMIT,             Commit,     this );\r
236   //  ecore_imf_context_event_callback_add( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding, this );\r
237 \r
238   //  ecore_imf_context_retrieve_surrounding_callback_set( mIMFContext, ImfRetrieveSurrounding, this);\r
239   //}\r
240 }\r
241 \r
242 void InputMethodContextWin::DisconnectCallbacks()\r
243 {\r
244   //if ( mIMFContext )\r
245   //{\r
246   //  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::DisconnectCallbacks\n" );\r
247 \r
248   //  ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_PREEDIT_CHANGED,    PreEdit );\r
249   //  ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_COMMIT,             Commit );\r
250   //  ecore_imf_context_event_callback_del( mIMFContext, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, ImfDeleteSurrounding );\r
251 \r
252   //  // We do not need to unset the retrieve surrounding callback.\r
253   //}\r
254 }\r
255 \r
256 void InputMethodContextWin::Activate()\r
257 {\r
258   // Reset mIdleCallbackConnected\r
259   mIdleCallbackConnected = false;\r
260 \r
261   //if ( mIMFContext )\r
262   //{\r
263   //  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::Activate\n" );\r
264 \r
265   //  ecore_imf_context_focus_in( mIMFContext );\r
266 \r
267   //  // emit keyboard activated signal\r
268   //  Dali::InputMethodContext handle( this );\r
269   //  mActivatedSignal.Emit( handle );\r
270   //}\r
271 }\r
272 \r
273 void InputMethodContextWin::Deactivate()\r
274 {\r
275   //if( mIMFContext )\r
276   //{\r
277   //  DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::Deactivate\n" );\r
278 \r
279   //  Reset();\r
280   //  ecore_imf_context_focus_out( mIMFContext );\r
281   //}\r
282 \r
283   // Reset mIdleCallbackConnected\r
284   mIdleCallbackConnected = false;\r
285 }\r
286 \r
287 void InputMethodContextWin::Reset()\r
288 {\r
289   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::Reset\n" );\r
290 \r
291   //if ( mIMFContext )\r
292   //{\r
293   //  ecore_imf_context_reset( mIMFContext );\r
294   //}\r
295 }\r
296 \r
297 ImfContext* InputMethodContextWin::GetContext()\r
298 {\r
299   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetContext\n" );\r
300 \r
301   //return mIMFContext;\r
302   return NULL;\r
303 }\r
304 \r
305 bool InputMethodContextWin::RestoreAfterFocusLost() const\r
306 {\r
307   return mRestoreAfterFocusLost;\r
308 }\r
309 \r
310 void InputMethodContextWin::SetRestoreAfterFocusLost( bool toggle )\r
311 {\r
312   mRestoreAfterFocusLost = toggle;\r
313 }\r
314 \r
315 /**\r
316  * Called when an InputMethodContext Pre-Edit changed event is received.\r
317  * We are still predicting what the user is typing.  The latest string is what the InputMethodContext module thinks\r
318  * the user wants to type.\r
319  */\r
320 void InputMethodContextWin::PreEditChanged( void*, ImfContext* imfContext, void* event_info )\r
321 {\r
322   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::PreEditChanged\n" );\r
323 //  auto context = reinterpret_cast<Ecore_IMF_Context*>(imfContext);\r
324 //\r
325 //  char* preEditString( NULL );\r
326 //  int cursorPosition( 0 );\r
327 //  Eina_List* attrs = NULL;\r
328 //  Eina_List* l = NULL;\r
329 //\r
330 //  Ecore_IMF_Preedit_Attr* attr;\r
331 //\r
332 //  // Retrieves attributes as well as the string the cursor position offset from start of pre-edit string.\r
333 //  // the attributes (attrs) is used in languages that use the soft arrows keys to insert characters into a current pre-edit string.\r
334 //  ecore_imf_context_preedit_string_with_attributes_get( context, &preEditString, &attrs, &cursorPosition );\r
335 //\r
336 //  if ( attrs )\r
337 //  {\r
338 //    // iterate through the list of attributes getting the type, start and end position.\r
339 //    for ( l = attrs, (attr =  static_cast<Ecore_IMF_Preedit_Attr*>( eina_list_data_get(l) ) ); l; l = eina_list_next(l), ( attr = static_cast<Ecore_IMF_Preedit_Attr*>( eina_list_data_get(l) ) ))\r
340 //    {\r
341 //#ifdef DALI_PROFILE_UBUNTU\r
342 //      if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3 ) // (Ecore_IMF)\r
343 //#else // DALI_PROFILE_UBUNTU\r
344 //      if ( attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB4 ) // (Ecore_IMF)\r
345 //#endif // DALI_PROFILE_UBUNTU\r
346 //      {\r
347 //        // check first byte so know how many bytes a character is represented by as keyboard returns cursor position in bytes. Which is different for some languages.\r
348 //\r
349 //        size_t visualCharacterIndex = 0;\r
350 //        size_t byteIndex = 0;\r
351 //\r
352 //        // iterate through null terminated string checking each character's position against the given byte position ( attr->end_index ).\r
353 //        const char leadByte = preEditString[byteIndex];\r
354 //        while( leadByte != '\0' )\r
355 //        {\r
356 //          // attr->end_index is provided as a byte position not character and we need to know the character position.\r
357 //          const size_t currentSequenceLength = Utf8SequenceLength( leadByte ); // returns number of bytes used to represent character.\r
358 //          if ( byteIndex == attr->end_index )\r
359 //          {\r
360 //            cursorPosition = visualCharacterIndex;\r
361 //            break;\r
362 //            // end loop as found cursor position that matches byte position\r
363 //          }\r
364 //          else\r
365 //          {\r
366 //            byteIndex += currentSequenceLength; // jump to next character\r
367 //            visualCharacterIndex++;  // increment character count so we know our position for when we get a match\r
368 //          }\r
369 //\r
370 //          DALI_ASSERT_DEBUG( visualCharacterIndex < strlen( preEditString ));\r
371 //        }\r
372 //      }\r
373 //    }\r
374 //  }\r
375 \r
376   //if ( Dali::Adaptor::IsAvailable() )\r
377   //{\r
378   //  Dali::InputMethodContext handle( this );\r
379   //  Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::PRE_EDIT, preEditString, cursorPosition, 0 );\r
380   //  Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );\r
381 \r
382   //  if( callbackData.update )\r
383   //  {\r
384   //    mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );\r
385 \r
386   //    NotifyCursorPosition();\r
387   //  }\r
388 \r
389   //  if( callbackData.preeditResetRequired )\r
390   //  {\r
391   //    Reset();\r
392   //  }\r
393   //}\r
394   //free( preEditString );\r
395 }\r
396 \r
397 void InputMethodContextWin::CommitReceived( void*, ImfContext* imfContext, void* event_info )\r
398 {\r
399   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::CommitReceived\n" );\r
400 \r
401   if ( Dali::Adaptor::IsAvailable() )\r
402   {\r
403     const std::string keyString( static_cast<char*>( event_info ) );\r
404 \r
405     Dali::InputMethodContext handle( this );\r
406     Dali::InputMethodContext::EventData eventData( Dali::InputMethodContext::COMMIT, keyString, 0, 0 );\r
407     Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, eventData );\r
408 \r
409     if( callbackData.update )\r
410     {\r
411       mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );\r
412 \r
413       NotifyCursorPosition();\r
414     }\r
415   }\r
416 }\r
417 \r
418 /**\r
419  * Called when an InputMethodContext retrieve surround event is received.\r
420  * Here the InputMethodContext module wishes to know the string we are working with and where within the string the cursor is\r
421  * We need to signal the application to tell us this information.\r
422  */\r
423 bool InputMethodContextWin::RetrieveSurrounding( void* data, ImfContext* imfContext, char** text, int* cursorPosition )\r
424 {\r
425   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::RetrieveSurrounding\n" );\r
426 \r
427   Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::GET_SURROUNDING, std::string(), 0, 0 );\r
428   Dali::InputMethodContext handle( this );\r
429   Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );\r
430 \r
431   if( callbackData.update )\r
432   {\r
433     if( text )\r
434     {\r
435       *text = strdup( callbackData.currentText.c_str() );\r
436     }\r
437 \r
438     if( cursorPosition )\r
439     {\r
440       mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );\r
441       *cursorPosition = mIMFCursorPosition;\r
442     }\r
443   }\r
444 \r
445   //return EINA_TRUE;\r
446   return true;\r
447 }\r
448 \r
449 /**\r
450  * Called when an InputMethodContext delete surrounding event is received.\r
451  * Here we tell the application that it should delete a certain range.\r
452  */\r
453 void InputMethodContextWin::DeleteSurrounding( void* data, ImfContext* imfContext, void* event_info )\r
454 {\r
455   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::DeleteSurrounding\n" );\r
456 \r
457   //if( Dali::Adaptor::IsAvailable() )\r
458   //{\r
459   //  Ecore_IMF_Event_Delete_Surrounding* deleteSurroundingEvent = static_cast<Ecore_IMF_Event_Delete_Surrounding*>( event_info );\r
460 \r
461   //  Dali::InputMethodContext::EventData imfData( Dali::InputMethodContext::DELETE_SURROUNDING, std::string(), deleteSurroundingEvent->offset, deleteSurroundingEvent->n_chars );\r
462   //  Dali::InputMethodContext handle( this );\r
463   //  Dali::InputMethodContext::CallbackData callbackData = mEventSignal.Emit( handle, imfData );\r
464 \r
465   //  if( callbackData.update )\r
466   //  {\r
467   //    mIMFCursorPosition = static_cast<int>( callbackData.cursorPosition );\r
468 \r
469   //    NotifyCursorPosition();\r
470   //  }\r
471   //}\r
472 }\r
473 \r
474 void InputMethodContextWin::NotifyCursorPosition()\r
475 {\r
476   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::NotifyCursorPosition\n" );\r
477 \r
478   //if( mIMFContext )\r
479   //{\r
480   //  ecore_imf_context_cursor_position_set( mIMFContext, mIMFCursorPosition );\r
481   //}\r
482 }\r
483 \r
484 void InputMethodContextWin::SetCursorPosition( unsigned int cursorPosition )\r
485 {\r
486   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetCursorPosition\n" );\r
487 \r
488   mIMFCursorPosition = static_cast<int>( cursorPosition );\r
489 }\r
490 \r
491 unsigned int InputMethodContextWin::GetCursorPosition() const\r
492 {\r
493   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetCursorPosition\n" );\r
494 \r
495   return static_cast<unsigned int>( mIMFCursorPosition );\r
496 }\r
497 \r
498 void InputMethodContextWin::SetSurroundingText( const std::string& text )\r
499 {\r
500   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetSurroundingText\n" );\r
501 \r
502   mSurroundingText = text;\r
503 }\r
504 \r
505 const std::string& InputMethodContextWin::GetSurroundingText() const\r
506 {\r
507   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetSurroundingText\n" );\r
508 \r
509   return mSurroundingText;\r
510 }\r
511 \r
512 void InputMethodContextWin::NotifyTextInputMultiLine( bool multiLine )\r
513 {\r
514 }\r
515 \r
516 Dali::InputMethodContext::TextDirection InputMethodContextWin::GetTextDirection()\r
517 {\r
518   Dali::InputMethodContext::TextDirection direction ( Dali::InputMethodContext::LeftToRight );\r
519 \r
520     //if ( mIMFContext )\r
521     //{\r
522     //  char* locale( NULL );\r
523     //  ecore_imf_context_input_panel_language_locale_get( mIMFContext, &locale );\r
524 \r
525     //  if ( locale )\r
526     //  {\r
527     //    direction = static_cast< Dali::InputMethodContext::TextDirection >( Locale::GetDirection( std::string( locale ) ) );\r
528     //    free( locale );\r
529     //  }\r
530     //}\r
531 \r
532   return direction;\r
533 }\r
534 \r
535 Rect<int> InputMethodContextWin::GetInputMethodArea()\r
536 {\r
537   int xPos, yPos, width, height;\r
538 \r
539   width = height = xPos = yPos = 0;\r
540 \r
541   //if( mIMFContext )\r
542   //{\r
543   //  ecore_imf_context_input_panel_geometry_get( mIMFContext, &xPos, &yPos, &width, &height );\r
544   //}\r
545   //else\r
546   //{\r
547   //  DALI_LOG_WARNING("VKB Unable to get InputMethodContext Context so GetSize unavailable\n");\r
548   //}\r
549 \r
550   return Rect<int>(xPos,yPos,width,height);\r
551 }\r
552 \r
553 void InputMethodContextWin::ApplyOptions( const InputMethodOptions& options )\r
554 {\r
555   using namespace Dali::InputMethod::Category;\r
556 \r
557   int index;\r
558 \r
559   //if (mIMFContext == NULL)\r
560   //{\r
561   //  DALI_LOG_WARNING("VKB Unable to excute ApplyOptions with Null ImfContext\n");\r
562   //  return;\r
563   //}\r
564 \r
565   if ( mOptions.CompareAndSet(PANEL_LAYOUT, options, index) )\r
566   {\r
567   }\r
568   if ( mOptions.CompareAndSet(BUTTON_ACTION, options, index) )\r
569   {\r
570   }\r
571   if ( mOptions.CompareAndSet(AUTO_CAPITALIZE, options, index) )\r
572   {\r
573   }\r
574   if ( mOptions.CompareAndSet(VARIATION, options, index) )\r
575   {\r
576   }\r
577 }\r
578 \r
579 void InputMethodContextWin::SetInputPanelData( const std::string& data )\r
580 {\r
581   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetInputPanelData\n" );\r
582 \r
583   //if( mIMFContext )\r
584   //{\r
585   //  int length = data.length();\r
586   //  ecore_imf_context_input_panel_imdata_set( mIMFContext, data.c_str(), length );\r
587   //}\r
588 }\r
589 \r
590 void InputMethodContextWin::GetInputPanelData( std::string& data )\r
591 {\r
592   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelData\n" );\r
593 \r
594   //if( mIMFContext )\r
595   //{\r
596   //  int length = 4096; // The max length is 4096 bytes\r
597   //  Dali::Vector< char > buffer;\r
598   //  buffer.Resize( length );\r
599   //  ecore_imf_context_input_panel_imdata_get( mIMFContext, &buffer[0], &length );\r
600   //  data = std::string( buffer.Begin(), buffer.End() );\r
601   //}\r
602 }\r
603 \r
604 Dali::InputMethodContext::State InputMethodContextWin::GetInputPanelState()\r
605 {\r
606   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelState\n" );\r
607 \r
608   //if( mIMFContext )\r
609   //{\r
610   //  int value;\r
611   //  value = ecore_imf_context_input_panel_state_get( mIMFContext );\r
612 \r
613   //  switch (value)\r
614   //  {\r
615   //    case ECORE_IMF_INPUT_PANEL_STATE_SHOW:\r
616   //    {\r
617   //      return Dali::InputMethodContext::SHOW;\r
618   //      break;\r
619   //    }\r
620 \r
621   //    case ECORE_IMF_INPUT_PANEL_STATE_HIDE:\r
622   //    {\r
623   //      return Dali::InputMethodContext::HIDE;\r
624   //      break;\r
625   //    }\r
626 \r
627   //    case ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW:\r
628   //    {\r
629   //      return Dali::InputMethodContext::WILL_SHOW;\r
630   //      break;\r
631   //    }\r
632 \r
633   //    default:\r
634   //    {\r
635   //      return Dali::InputMethodContext::DEFAULT;\r
636   //    }\r
637   //  }\r
638   //}\r
639   return Dali::InputMethodContext::DEFAULT;\r
640 }\r
641 \r
642 void InputMethodContextWin::SetReturnKeyState( bool visible )\r
643 {\r
644   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::SetReturnKeyState\n" );\r
645 \r
646   //if( mIMFContext )\r
647   //{\r
648   //  ecore_imf_context_input_panel_return_key_disabled_set( mIMFContext, !visible );\r
649   //}\r
650 }\r
651 \r
652 void InputMethodContextWin::AutoEnableInputPanel( bool enabled )\r
653 {\r
654   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::AutoEnableInputPanel\n" );\r
655 \r
656   //if( mIMFContext )\r
657   //{\r
658   //  ecore_imf_context_input_panel_enabled_set( mIMFContext, enabled );\r
659   //}\r
660 }\r
661 \r
662 void InputMethodContextWin::ShowInputPanel()\r
663 {\r
664   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::ShowInputPanel\n" );\r
665 \r
666   //if( mIMFContext )\r
667   //{\r
668   //  ecore_imf_context_input_panel_show( mIMFContext );\r
669   //}\r
670 }\r
671 \r
672 void InputMethodContextWin::HideInputPanel()\r
673 {\r
674   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::HideInputPanel\n" );\r
675 \r
676   //if( mIMFContext )\r
677   //{\r
678   //  ecore_imf_context_input_panel_hide( mIMFContext );\r
679   //}\r
680 }\r
681 \r
682 Dali::InputMethodContext::KeyboardType InputMethodContextWin::GetKeyboardType()\r
683 {\r
684   return Dali::InputMethodContext::KeyboardType::SOFTWARE_KEYBOARD;\r
685 }\r
686 \r
687 std::string InputMethodContextWin::GetInputPanelLocale()\r
688 {\r
689   DALI_LOG_INFO( gLogFilter, Debug::General, "InputMethodContextWin::GetInputPanelLocale\n" );\r
690 \r
691   std::string locale = "";\r
692 \r
693   //if( mIMFContext )\r
694   //{\r
695   //  char* value = NULL;\r
696   //  ecore_imf_context_input_panel_language_locale_get( mIMFContext, &value );\r
697 \r
698   //  if( value )\r
699   //  {\r
700   //    std::string valueCopy( value );\r
701   //    locale = valueCopy;\r
702 \r
703   //    // The locale string retrieved must be freed with free().\r
704   //    free( value );\r
705   //  }\r
706   //}\r
707   return locale;\r
708 }\r
709 \r
710 bool InputMethodContextWin::FilterEventKey( const Dali::KeyEvent& keyEvent )\r
711 {\r
712   bool eventHandled( false );\r
713 \r
714   // If a device key then skip ecore_imf_context_filter_event.\r
715   if ( ! KeyLookup::IsDeviceButton( keyEvent.keyPressedName.c_str() ))\r
716   {\r
717     //check whether it's key down or key up event\r
718     if ( keyEvent.state == KeyEvent::Down )\r
719     {\r
720       eventHandled = ProcessEventKeyDown( keyEvent );\r
721     }\r
722     else if ( keyEvent.state == KeyEvent::Up )\r
723     {\r
724       eventHandled = ProcessEventKeyUp( keyEvent );\r
725     }\r
726   }\r
727 \r
728   return eventHandled;\r
729 }\r
730 \r
731 bool InputMethodContextWin::ProcessEventKeyDown( const KeyEvent& keyEvent )\r
732 {\r
733   bool eventHandled( false );\r
734 //  if ( mIMFContext )\r
735 //  {\r
736 //    // We're consuming key down event so we have to pass to InputMethodContext so that it can parse it as well.\r
737 //    Ecore_IMF_Event_Key_Down ecoreKeyDownEvent;\r
738 //    ecoreKeyDownEvent.keyname = keyEvent.keyPressedName.c_str();\r
739 //    ecoreKeyDownEvent.key = keyEvent.keyPressedName.c_str();\r
740 //    ecoreKeyDownEvent.string = keyEvent.keyPressed.c_str();\r
741 //    ecoreKeyDownEvent.compose = keyEvent.GetCompose().c_str();\r
742 //    ecoreKeyDownEvent.timestamp = keyEvent.time;\r
743 //    ecoreKeyDownEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );\r
744 //    ecoreKeyDownEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );\r
745 //#ifdef ECORE_IMF_1_13\r
746 //    ecoreKeyDownEvent.dev_name  = "";\r
747 //    ecoreKeyDownEvent.dev_class = ECORE_IMF_DEVICE_CLASS_KEYBOARD;\r
748 //    ecoreKeyDownEvent.dev_subclass = ECORE_IMF_DEVICE_SUBCLASS_NONE;\r
749 //#endif // ECORE_IMF_1_13\r
750 //\r
751 //    // If the device is IME and the focused key is the direction keys, then we should send a key event to move a key cursor.\r
752 //    if ((keyEvent.GetDeviceName() == "ime") && ((!strncmp(keyEvent.keyPressedName.c_str(), "Left", 4)) ||\r
753 //                                   (!strncmp(keyEvent.keyPressedName.c_str(), "Right", 5)) ||\r
754 //                                   (!strncmp(keyEvent.keyPressedName.c_str(), "Up", 2)) ||\r
755 //                                   (!strncmp(keyEvent.keyPressedName.c_str(), "Down", 4))))\r
756 //    {\r
757 //      eventHandled = 0;\r
758 //    }\r
759 //    else\r
760 //    {\r
761 //      eventHandled = ecore_imf_context_filter_event(mIMFContext,\r
762 //                                                    ECORE_IMF_EVENT_KEY_DOWN,\r
763 //                                                    (Ecore_IMF_Event *) &ecoreKeyDownEvent);\r
764 //    }\r
765 //\r
766 //    // If the event has not been handled by InputMethodContext then check if we should reset our IMFcontext\r
767 //    if (!eventHandled)\r
768 //    {\r
769 //      if (!strcmp(keyEvent.keyPressedName.c_str(), "Escape") ||\r
770 //          !strcmp(keyEvent.keyPressedName.c_str(), "Return") ||\r
771 //          !strcmp(keyEvent.keyPressedName.c_str(), "KP_Enter"))\r
772 //      {\r
773 //        ecore_imf_context_reset(mIMFContext);\r
774 //      }\r
775 //    }\r
776 //  }\r
777   return eventHandled;\r
778 }\r
779 \r
780 bool InputMethodContextWin::ProcessEventKeyUp( const KeyEvent& keyEvent )\r
781 {\r
782   bool eventHandled( false );\r
783 //  if( mIMFContext )\r
784 //  {\r
785 //    // We're consuming key up event so we have to pass to InputMethodContext so that it can parse it as well.\r
786 //    Ecore_IMF_Event_Key_Up ecoreKeyUpEvent;\r
787 //    ecoreKeyUpEvent.keyname = keyEvent.keyPressedName.c_str();\r
788 //    ecoreKeyUpEvent.key = keyEvent.keyPressedName.c_str();\r
789 //    ecoreKeyUpEvent.string = keyEvent.keyPressed.c_str();\r
790 //    ecoreKeyUpEvent.compose = keyEvent.GetCompose().c_str();\r
791 //    ecoreKeyUpEvent.timestamp = keyEvent.time;\r
792 //    ecoreKeyUpEvent.modifiers = EcoreInputModifierToEcoreIMFModifier( keyEvent.keyModifier );\r
793 //    ecoreKeyUpEvent.locks = EcoreInputModifierToEcoreIMFLock( keyEvent.keyModifier );\r
794 //#ifdef ECORE_IMF_1_13\r
795 //    ecoreKeyUpEvent.dev_name  = "";\r
796 //#endif // ECORE_IMF_1_13\r
797 //\r
798 //    eventHandled = ecore_imf_context_filter_event(mIMFContext,\r
799 //                                                  ECORE_IMF_EVENT_KEY_UP,\r
800 //                                                  (Ecore_IMF_Event *) &ecoreKeyUpEvent);\r
801 //  }\r
802   return eventHandled;\r
803 }\r
804 \r
805 //Ecore_IMF_Keyboard_Modifiers InputMethodContextWin::EcoreInputModifierToEcoreIMFModifier( unsigned int ecoreModifier )\r
806 //{\r
807 //  unsigned int modifier( ECORE_IMF_KEYBOARD_MODIFIER_NONE );  // If no other matches returns NONE.\r
808 //\r
809 //  if ( ecoreModifier & ECORE_EVENT_MODIFIER_SHIFT )  // enums from ecore_input/Ecore_Input.h\r
810 //  {\r
811 //    modifier |= ECORE_IMF_KEYBOARD_MODIFIER_SHIFT;  // enums from ecore_imf/ecore_imf.h\r
812 //  }\r
813 //\r
814 //  if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALT )\r
815 //  {\r
816 //    modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALT;\r
817 //  }\r
818 //\r
819 //  if ( ecoreModifier & ECORE_EVENT_MODIFIER_CTRL )\r
820 //  {\r
821 //    modifier |= ECORE_IMF_KEYBOARD_MODIFIER_CTRL;\r
822 //  }\r
823 //\r
824 //  if ( ecoreModifier & ECORE_EVENT_MODIFIER_WIN )\r
825 //  {\r
826 //    modifier |= ECORE_IMF_KEYBOARD_MODIFIER_WIN;\r
827 //  }\r
828 //\r
829 //  if ( ecoreModifier & ECORE_EVENT_MODIFIER_ALTGR )\r
830 //  {\r
831 //    modifier |= ECORE_IMF_KEYBOARD_MODIFIER_ALTGR;\r
832 //  }\r
833 //\r
834 //  return static_cast<Ecore_IMF_Keyboard_Modifiers>( modifier );\r
835 //}\r
836 //\r
837 //Ecore_IMF_Keyboard_Locks InputMethodContextWin::EcoreInputModifierToEcoreIMFLock( unsigned int modifier )\r
838 //{\r
839 //    unsigned int lock( ECORE_IMF_KEYBOARD_LOCK_NONE ); // If no other matches, returns NONE.\r
840 //\r
841 //    if( modifier & ECORE_EVENT_LOCK_NUM )\r
842 //    {\r
843 //      lock |= ECORE_IMF_KEYBOARD_LOCK_NUM; // Num lock is active.\r
844 //    }\r
845 //\r
846 //    if( modifier & ECORE_EVENT_LOCK_CAPS )\r
847 //    {\r
848 //      lock |= ECORE_IMF_KEYBOARD_LOCK_CAPS; // Caps lock is active.\r
849 //    }\r
850 //\r
851 //    if( modifier & ECORE_EVENT_LOCK_SCROLL )\r
852 //    {\r
853 //      lock |= ECORE_IMF_KEYBOARD_LOCK_SCROLL; // Scroll lock is active.\r
854 //    }\r
855 //\r
856 //    return static_cast<Ecore_IMF_Keyboard_Locks>( lock );\r
857 //}\r
858 \r
859 } // Adaptor\r
860 \r
861 } // Internal\r
862 \r
863 } // Dali\r
864 \r
865 #pragma GCC diagnostic pop\r