[SDL_Tizen] delete ecore_imf_callback
[platform/upstream/SDL.git] / src / video / tizen / SDL_tizenkeyboard.c
old mode 100644 (file)
new mode 100755 (executable)
index 3af43bf..801c923
 #include "SDL_log.h"
 #include "../../events/SDL_keyboard_c.h"
 
-/*
-    Tizen Keyboard
-*/
-static TizenKeyboard tizen_keyboard;
+/* Tizen Keyboard */
+TizenKeyboard tizen_keyboard;
 
 void
 _ecore_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, void *event_info)
 {
     char *commit_str = (char *)event_info;
-    SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "commit string : %s\n", commit_str);
     SDL_SendKeyboardText(commit_str);
     return;
 }
 
 void
+_ecore_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx, void *event_info EINA_UNUSED)
+{
+    char *preedit_string;
+    int cursor_pos;
+    Ecore_IMF_Context *imf_context = ctx;
+
+    // get preedit string and attributes
+    ecore_imf_context_preedit_string_with_attributes_get(imf_context, &preedit_string, NULL, &cursor_pos);
+
+    SDL_SendEditingText(preedit_string, 0, cursor_pos);
+    free(preedit_string);
+}
+
+void
 _ecore_imf_event_state_change_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, int value)
 {
     //ECORE_IMF_INPUT_PANEL_STATE_SHOW : 0
     //ECORE_IMF_INPUT_PANEL_STATE_HIDE : 1
-    SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Keyboard State  : %d\n", value);
     return;
 }
 
@@ -69,10 +79,10 @@ void Tizen_InitKeyboard(_THIS)
 
     const char *default_id = ecore_imf_context_default_id_get();
     if (!default_id)
-      {
-         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't create ecore_imf_context\n");
-         return;
-      }
+    {
+        SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Can't create ecore_imf_context\n");
+        return;
+    }
 
     tizen_keyboard.imf_context = ecore_imf_context_add(default_id);
 
@@ -82,6 +92,7 @@ void Tizen_InitKeyboard(_THIS)
     ecore_imf_context_client_window_set(tizen_keyboard.imf_context, (void*)wind->id);
 
     ecore_imf_context_event_callback_add(tizen_keyboard.imf_context, ECORE_IMF_CALLBACK_COMMIT , _ecore_imf_event_commit_cb, NULL);
+    ecore_imf_context_event_callback_add(tizen_keyboard.imf_context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _ecore_imf_event_preedit_changed_cb, NULL);
     ecore_imf_context_input_panel_event_callback_add (tizen_keyboard.imf_context, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _ecore_imf_event_state_change_cb, NULL);
 
     ecore_imf_context_cursor_position_set(tizen_keyboard.imf_context, 0);
@@ -97,6 +108,10 @@ void Tizen_FiniKeyboard(void)
     if(tizen_keyboard.imf_context == NULL)
         return;
 
+    ecore_imf_context_event_callback_del(tizen_keyboard.imf_context, ECORE_IMF_CALLBACK_COMMIT, _ecore_imf_event_commit_cb);
+    ecore_imf_context_event_callback_del(tizen_keyboard.imf_context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _ecore_imf_event_preedit_changed_cb);
+    ecore_imf_context_input_panel_event_callback_del(tizen_keyboard.imf_context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _ecore_imf_event_preedit_changed_cb);
+
     ecore_imf_context_del(tizen_keyboard.imf_context);
     tizen_keyboard.imf_context = NULL;
 
@@ -106,18 +121,24 @@ void Tizen_FiniKeyboard(void)
 void
 Tizen_StartTextInput(_THIS)
 {
+    SDL_Window *window;
+
     if (!_this) {
-        SDL_SetError("Video subsystem must be initialized");
+        SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Video subsystem must be initialized");
         return;
     }
 
     if(tizen_keyboard.imf_context == NULL)
       Tizen_InitKeyboard(_this);
 
-    Tizen_ShowScreenKeyboard(_this, NULL);
+    window = SDL_GetKeyboardFocus();
+    if(!window){
+       SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Keyboard focused window is NULL");
+       return;
+    }
+    Tizen_ShowScreenKeyboard(_this, window);
 }
 
-
 void
 Tizen_StopTextInput(_THIS)
 {
@@ -132,22 +153,22 @@ void Tizen_SetTextInputRect(void)
 {
 }
 
-
 SDL_bool
 Tizen_HasScreenKeyboardSupport(_THIS)
 {
     return SDL_TRUE;
 }
 
-
 void
 Tizen_ShowScreenKeyboard(_THIS, SDL_Window * window)
 {
+    SDL_WindowData *wind = window->driverdata;
     if (!tizen_keyboard.imf_context)
           return;
 
     ecore_imf_context_focus_in(tizen_keyboard.imf_context);
     ecore_imf_context_input_panel_show(tizen_keyboard.imf_context);
+    ecore_imf_context_client_window_set(tizen_keyboard.imf_context, (void*)wind->id);
 }
 
 void