Add new APIs to support Korean input
[platform/core/uifw/libscl-ui-nui.git] / capi / src / cscl-ui-inputmethod.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <dlog.h>
18 #include <tizen.h>
19 #include <inputmethod.h>
20 #include <inputmethod_internal.h>
21 #include "cscl-ui-inputmethod.h"
22
23 #ifdef LOG_TAG
24 #undef LOG_TAG
25 #endif
26 #define LOG_TAG "CSCLUINUI"
27
28 static scl_process_key_event_with_imengine_cb g_process_key_event_with_imengine_cb = NULL;
29 static void *g_process_key_event_with_imengine_cb_data = NULL;
30
31 EXPORT_API int scl_set_imengine(const char *engine_id)
32 {
33     int ret = IME_ERROR_NONE;
34     ret = ime_set_imengine(engine_id);
35
36     LOGD("engine_id : %s, ret : %d", engine_id, ret);
37     return ret;
38 }
39
40 EXPORT_API int scl_flush_imengine()
41 {
42     int ret = IME_ERROR_NONE;
43     ret = ime_flush_imengine();
44
45     LOGD("ret : %d", ret);
46     return ret;
47 }
48
49 EXPORT_API int scl_reset_imengine()
50 {
51     int ret = IME_ERROR_NONE;
52     ret = ime_reset_imengine();
53
54     LOGD("ret : %d", ret);
55     return ret;
56 }
57
58 EXPORT_API int scl_send_imengine_event(int command, uint32_t value)
59 {
60     int ret = IME_ERROR_NONE;
61     ret = ime_send_imengine_event(command, value);
62
63     LOGD("command : %d, value : %d, ret : %d", command, value, ret);
64     return ret;
65 }
66
67 EXPORT_API int scl_set_engine_loader_flag(bool flag)
68 {
69     int ret = IME_ERROR_NONE;
70     ret = ime_set_engine_loader_flag(flag);
71
72     LOGD("flag : %d, ret : %d", flag, ret);
73     return ret;
74 }
75
76 static void ime_app_process_key_event_with_imengine_cb(scim::KeyEvent &key, uint32_t serial, void *user_data)
77 {
78     LOGD("process_key_event_with_imengine = key : %p, serial : %d", &key, serial);
79     if (g_process_key_event_with_imengine_cb) {
80         g_process_key_event_with_imengine_cb(key.code, key.mask, key.layout, key.dev_class, key.dev_subclass, (key.dev_name).c_str(), serial, user_data);
81     }
82 }
83
84 EXPORT_API int scl_set_process_key_event_with_imengine_cb(scl_process_key_event_with_imengine_cb callback, void *user_data)
85 {
86     int ret = IME_ERROR_NONE;
87
88     g_process_key_event_with_imengine_cb = callback;
89     g_process_key_event_with_imengine_cb_data = user_data;
90
91     ret = ime_event_set_process_key_event_with_imengine_cb(ime_app_process_key_event_with_imengine_cb, user_data);
92
93     return ret;
94 }