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