Merge "[SDL Tizen] Add vulkan feature to SDL." into tizen
[platform/upstream/SDL.git] / src / video / tizen / SDL_tizenkeyboard.c
1 /*
2   Simple DirectMedia Layer
3   Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4   Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
5
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.
9
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:
13
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.
21 */
22
23 #include "../../SDL_internal.h"
24
25 #include "SDL_tizenkeyboard.h"
26 #include "SDL_log.h"
27 #include "../../events/SDL_keyboard_c.h"
28
29 /*
30     Tizen Keyboard
31 */
32
33 void
34 _ecore_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, void *event_info)
35 {
36     char *commit_str = (char *)event_info;
37     SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "commit string : %s\n", commit_str);
38     SDL_SendKeyboardText(commit_str);
39     return;
40 }
41
42 void
43 _ecore_imf_event_state_change_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, int value)
44 {
45     //ECORE_IMF_INPUT_PANEL_STATE_SHOW : 0
46     //ECORE_IMF_INPUT_PANEL_STATE_HIDE : 1
47     SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Keyboard State  : %d\n", value);
48     return;
49 }
50
51 void Tizen_InitKeyboard(_THIS)
52 {
53     ecore_imf_init();
54
55     memset(&keyboard, 0, sizeof(keyboard));
56
57     const char *default_id = ecore_imf_context_default_id_get();
58     if (!default_id)
59       {
60          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't create ecore_imf_context\n");
61          return;
62       }
63
64     keyboard.imf_context = ecore_imf_context_add(default_id);
65
66     SDL_Window *window = _this->windows;
67     SDL_WindowData *wind = window->driverdata;
68
69     ecore_imf_context_client_window_set(keyboard.imf_context, (void*)wind->id);
70
71     ecore_imf_context_event_callback_add(keyboard.imf_context, ECORE_IMF_CALLBACK_COMMIT , _ecore_imf_event_commit_cb, NULL);
72     ecore_imf_context_input_panel_event_callback_add (keyboard.imf_context, ECORE_IMF_INPUT_PANEL_STATE_EVENT, _ecore_imf_event_state_change_cb, NULL);
73
74     ecore_imf_context_cursor_position_set(keyboard.imf_context, 0);
75     ecore_imf_context_focus_out(keyboard.imf_context);
76     ecore_imf_context_input_panel_hide(keyboard.imf_context);
77
78 }
79
80 void Tizen_FiniKeyboard(void)
81 {
82     if(keyboard.imf_context == NULL)
83         return;
84
85     ecore_imf_context_del(keyboard.imf_context);
86     keyboard.imf_context = NULL;
87
88     ecore_imf_shutdown();
89 }
90
91 void
92 Tizen_StartTextInput(_THIS)
93 {
94     if (!_this) {
95         SDL_SetError("Video subsystem must be initialized");
96         return;
97     }
98
99     if(keyboard.imf_context == NULL)
100       Tizen_InitKeyboard(_this);
101
102     Tizen_ShowScreenKeyboard(_this, NULL);
103 }
104
105
106 void
107 Tizen_StopTextInput(_THIS)
108 {
109    if (!_this) return;
110    if (keyboard.imf_context)
111      {
112         Tizen_HideScreenKeyboard(_this, _this->windows);
113      }
114 }
115
116 void Tizen_SetTextInputRect(void)
117 {
118 }
119
120
121 SDL_bool
122 Tizen_HasScreenKeyboardSupport(_THIS)
123 {
124     return SDL_TRUE;
125 }
126
127
128 void
129 Tizen_ShowScreenKeyboard(_THIS, SDL_Window * window)
130 {
131     if (!keyboard.imf_context)
132           return;
133
134     ecore_imf_context_focus_in(keyboard.imf_context);
135     ecore_imf_context_input_panel_show(keyboard.imf_context);
136 }
137
138 void
139 Tizen_HideScreenKeyboard(_THIS, SDL_Window * window)
140 {
141     if (!keyboard.imf_context)
142           return;
143
144     ecore_imf_context_focus_out(keyboard.imf_context);
145     ecore_imf_context_input_panel_hide(keyboard.imf_context);
146 }
147
148 SDL_bool
149 Tizen_IsScreenKeyboardShown(_THIS, SDL_Window * window)
150 {
151     if (!keyboard.imf_context)
152           return SDL_FALSE;
153     //EAPI Ecore_IMF_Input_Panel_State  ecore_imf_context_input_panel_state_get (Ecore_IMF_Context *ctx)
154     return ecore_imf_context_input_panel_state_get(keyboard.imf_context);
155 }