[SDL_Tizen] Add rotation feature
[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 static TizenKeyboard tizen_keyboard;
33
34 void
35 _ecore_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, void *event_info)
36 {
37     char *commit_str = (char *)event_info;
38     SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "commit string : %s\n", commit_str);
39     SDL_SendKeyboardText(commit_str);
40     return;
41 }
42
43 void
44 _ecore_imf_event_state_change_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, int value)
45 {
46     //ECORE_IMF_INPUT_PANEL_STATE_SHOW : 0
47     //ECORE_IMF_INPUT_PANEL_STATE_HIDE : 1
48     SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Keyboard State  : %d\n", value);
49     return;
50 }
51
52 void Tizen_InitKeyboard(_THIS)
53 {
54     //TODO : need the ref count
55     if (tizen_keyboard.imf_context) return;
56
57     ecore_imf_init();
58
59     memset(&tizen_keyboard, 0, sizeof(tizen_keyboard));
60
61     const char *default_id = ecore_imf_context_default_id_get();
62     if (!default_id)
63       {
64          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't create ecore_imf_context\n");
65          return;
66       }
67
68     tizen_keyboard.imf_context = ecore_imf_context_add(default_id);
69
70     SDL_Window *window = _this->windows;
71     SDL_WindowData *wind = window->driverdata;
72
73     ecore_imf_context_client_window_set(tizen_keyboard.imf_context, (void*)wind->id);
74
75     ecore_imf_context_event_callback_add(tizen_keyboard.imf_context, ECORE_IMF_CALLBACK_COMMIT , _ecore_imf_event_commit_cb, NULL);
76     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);
77
78     ecore_imf_context_cursor_position_set(tizen_keyboard.imf_context, 0);
79     ecore_imf_context_focus_out(tizen_keyboard.imf_context);
80     ecore_imf_context_input_panel_hide(tizen_keyboard.imf_context);
81
82 }
83
84 void Tizen_FiniKeyboard(void)
85 {
86     if(tizen_keyboard.imf_context == NULL)
87         return;
88
89     ecore_imf_context_del(tizen_keyboard.imf_context);
90     tizen_keyboard.imf_context = NULL;
91
92     ecore_imf_shutdown();
93 }
94
95 void
96 Tizen_StartTextInput(_THIS)
97 {
98     if (!_this) {
99         SDL_SetError("Video subsystem must be initialized");
100         return;
101     }
102
103     if(tizen_keyboard.imf_context == NULL)
104       Tizen_InitKeyboard(_this);
105
106     Tizen_ShowScreenKeyboard(_this, NULL);
107 }
108
109
110 void
111 Tizen_StopTextInput(_THIS)
112 {
113    if (!_this) return;
114    if (tizen_keyboard.imf_context)
115      {
116         Tizen_HideScreenKeyboard(_this, _this->windows);
117      }
118 }
119
120 void Tizen_SetTextInputRect(void)
121 {
122 }
123
124
125 SDL_bool
126 Tizen_HasScreenKeyboardSupport(_THIS)
127 {
128     return SDL_TRUE;
129 }
130
131
132 void
133 Tizen_ShowScreenKeyboard(_THIS, SDL_Window * window)
134 {
135     if (!tizen_keyboard.imf_context)
136           return;
137
138     ecore_imf_context_focus_in(tizen_keyboard.imf_context);
139     ecore_imf_context_input_panel_show(tizen_keyboard.imf_context);
140 }
141
142 void
143 Tizen_HideScreenKeyboard(_THIS, SDL_Window * window)
144 {
145     if (!tizen_keyboard.imf_context)
146           return;
147
148     ecore_imf_context_focus_out(tizen_keyboard.imf_context);
149     ecore_imf_context_input_panel_hide(tizen_keyboard.imf_context);
150 }
151
152 SDL_bool
153 Tizen_IsScreenKeyboardShown(_THIS, SDL_Window * window)
154 {
155     if (!tizen_keyboard.imf_context)
156           return SDL_FALSE;
157     //EAPI Ecore_IMF_Input_Panel_State  ecore_imf_context_input_panel_state_get (Ecore_IMF_Context *ctx)
158     return ecore_imf_context_input_panel_state_get(tizen_keyboard.imf_context);
159 }