2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
23 #include "../../SDL_internal.h"
25 #include "SDL_tizenkeyboard.h"
27 #include "../../events/SDL_keyboard_c.h"
30 TizenKeyboard tizen_keyboard;
33 _ecore_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, void *event_info)
35 char *commit_str = (char *)event_info;
36 SDL_SendKeyboardText(commit_str);
41 _ecore_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx, void *event_info EINA_UNUSED)
45 Ecore_IMF_Context *imf_context = ctx;
47 // get preedit string and attributes
48 ecore_imf_context_preedit_string_with_attributes_get(imf_context, &preedit_string, NULL, &cursor_pos);
50 SDL_SendEditingText(preedit_string, 0, cursor_pos);
55 _ecore_imf_event_state_change_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, int value)
57 //ECORE_IMF_INPUT_PANEL_STATE_SHOW : 0
58 //ECORE_IMF_INPUT_PANEL_STATE_HIDE : 1
62 void Tizen_SetKeymap()
64 SDL_Keycode keymap[SDL_NUM_SCANCODES];
66 /* Add default scancode to key mapping */
67 SDL_GetDefaultKeymap(keymap);
68 SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
71 void Tizen_InitKeyboard(_THIS)
73 //TODO : need the ref count
74 if (tizen_keyboard.imf_context) return;
78 memset(&tizen_keyboard, 0, sizeof(tizen_keyboard));
80 const char *default_id = ecore_imf_context_default_id_get();
83 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Can't create ecore_imf_context\n");
87 tizen_keyboard.imf_context = ecore_imf_context_add(default_id);
89 SDL_Window *window = _this->windows;
90 SDL_WindowData *wind = window->driverdata;
92 ecore_imf_context_client_window_set(tizen_keyboard.imf_context, (void*)wind->id);
94 ecore_imf_context_event_callback_add(tizen_keyboard.imf_context, ECORE_IMF_CALLBACK_COMMIT , _ecore_imf_event_commit_cb, NULL);
96 ecore_imf_context_event_callback_add(tizen_keyboard.imf_context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _ecore_imf_event_preedit_changed_cb, NULL);
98 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);
100 ecore_imf_context_cursor_position_set(tizen_keyboard.imf_context, 0);
101 ecore_imf_context_focus_out(tizen_keyboard.imf_context);
102 ecore_imf_context_input_panel_hide(tizen_keyboard.imf_context);
108 void Tizen_FiniKeyboard(void)
110 if(tizen_keyboard.imf_context == NULL)
113 ecore_imf_context_del(tizen_keyboard.imf_context);
114 tizen_keyboard.imf_context = NULL;
116 ecore_imf_shutdown();
120 Tizen_StartTextInput(_THIS)
125 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Video subsystem must be initialized");
129 if(tizen_keyboard.imf_context == NULL)
130 Tizen_InitKeyboard(_this);
132 window = SDL_GetKeyboardFocus();
134 SDL_LogError(SDL_LOG_CATEGORY_ASSERT, "Keyboard focused window is NULL");
137 Tizen_ShowScreenKeyboard(_this, window);
142 Tizen_StopTextInput(_THIS)
145 if (tizen_keyboard.imf_context)
147 Tizen_HideScreenKeyboard(_this, _this->windows);
151 void Tizen_SetTextInputRect(void)
157 Tizen_HasScreenKeyboardSupport(_THIS)
164 Tizen_ShowScreenKeyboard(_THIS, SDL_Window * window)
166 SDL_WindowData *wind = window->driverdata;
167 if (!tizen_keyboard.imf_context)
170 ecore_imf_context_focus_in(tizen_keyboard.imf_context);
171 ecore_imf_context_input_panel_show(tizen_keyboard.imf_context);
172 ecore_imf_context_client_window_set(tizen_keyboard.imf_context, (void*)wind->id);
176 Tizen_HideScreenKeyboard(_THIS, SDL_Window * window)
178 if (!tizen_keyboard.imf_context)
181 ecore_imf_context_focus_out(tizen_keyboard.imf_context);
182 ecore_imf_context_input_panel_hide(tizen_keyboard.imf_context);
186 Tizen_IsScreenKeyboardShown(_THIS, SDL_Window * window)
188 if (!tizen_keyboard.imf_context)
190 //EAPI Ecore_IMF_Input_Panel_State ecore_imf_context_input_panel_state_get (Ecore_IMF_Context *ctx)
191 return ecore_imf_context_input_panel_state_get(tizen_keyboard.imf_context);