#include "SDL_log.h"
#include "../../events/SDL_keyboard_c.h"
-/*
- 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;
}
+void Tizen_SetKeymap()
+{
+ SDL_Keycode keymap[SDL_NUM_SCANCODES];
+
+ /* Add default scancode to key mapping */
+ SDL_GetDefaultKeymap(keymap);
+ SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
+}
+
void Tizen_InitKeyboard(_THIS)
{
+ //TODO : need the ref count
+ if (tizen_keyboard.imf_context) return;
+
ecore_imf_init();
- memset(&keyboard, 0, sizeof(keyboard));
+ memset(&tizen_keyboard, 0, sizeof(tizen_keyboard));
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;
+ }
- keyboard.imf_context = ecore_imf_context_add(default_id);
+ tizen_keyboard.imf_context = ecore_imf_context_add(default_id);
SDL_Window *window = _this->windows;
SDL_WindowData *wind = window->driverdata;
- ecore_imf_context_client_window_set(keyboard.imf_context, (void*)wind->id);
+ ecore_imf_context_client_window_set(tizen_keyboard.imf_context, (void*)wind->id);
- ecore_imf_context_event_callback_add(keyboard.imf_context, ECORE_IMF_CALLBACK_COMMIT , _ecore_imf_event_commit_cb, NULL);
- ecore_imf_context_input_panel_event_callback_add (keyboard.imf_context, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _ecore_imf_event_state_change_cb, NULL);
+ 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(keyboard.imf_context, 0);
- ecore_imf_context_focus_out(keyboard.imf_context);
- ecore_imf_context_input_panel_hide(keyboard.imf_context);
+ ecore_imf_context_cursor_position_set(tizen_keyboard.imf_context, 0);
+ ecore_imf_context_focus_out(tizen_keyboard.imf_context);
+ ecore_imf_context_input_panel_hide(tizen_keyboard.imf_context);
+
+ Tizen_SetKeymap();
}
void Tizen_FiniKeyboard(void)
{
- if(keyboard.imf_context == NULL)
+ if(tizen_keyboard.imf_context == NULL)
return;
- ecore_imf_context_del(keyboard.imf_context);
- keyboard.imf_context = NULL;
+ 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;
ecore_imf_shutdown();
}
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(keyboard.imf_context == NULL)
+ 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)
{
if (!_this) return;
- if (keyboard.imf_context)
+ if (tizen_keyboard.imf_context)
{
Tizen_HideScreenKeyboard(_this, _this->windows);
}
{
}
-
SDL_bool
Tizen_HasScreenKeyboardSupport(_THIS)
{
return SDL_TRUE;
}
-
void
Tizen_ShowScreenKeyboard(_THIS, SDL_Window * window)
{
- if (!keyboard.imf_context)
+ SDL_WindowData *wind = window->driverdata;
+ if (!tizen_keyboard.imf_context)
return;
- ecore_imf_context_focus_in(keyboard.imf_context);
- ecore_imf_context_input_panel_show(keyboard.imf_context);
+ 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
Tizen_HideScreenKeyboard(_THIS, SDL_Window * window)
{
- if (!keyboard.imf_context)
+ if (!tizen_keyboard.imf_context)
return;
- ecore_imf_context_focus_out(keyboard.imf_context);
- ecore_imf_context_input_panel_hide(keyboard.imf_context);
+ ecore_imf_context_focus_out(tizen_keyboard.imf_context);
+ ecore_imf_context_input_panel_hide(tizen_keyboard.imf_context);
}
SDL_bool
Tizen_IsScreenKeyboardShown(_THIS, SDL_Window * window)
{
- if (!keyboard.imf_context)
+ if (!tizen_keyboard.imf_context)
return SDL_FALSE;
//EAPI Ecore_IMF_Input_Panel_State ecore_imf_context_input_panel_state_get (Ecore_IMF_Context *ctx)
- return ecore_imf_context_input_panel_state_get(keyboard.imf_context);
+ return ecore_imf_context_input_panel_state_get(tizen_keyboard.imf_context);
}