1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "global.h"
16 #include "native_inputmethod_types.h"
17 #ifdef __cplusplus
18 extern "C" {
19 #endif /* __cplusplus */
20
OH_TextConfig_Create(void)21 InputMethod_TextConfig *OH_TextConfig_Create(void)
22 {
23 return new InputMethod_TextConfig();
24 }
OH_TextConfig_Destroy(InputMethod_TextConfig * config)25 void OH_TextConfig_Destroy(InputMethod_TextConfig *config)
26 {
27 if (config == nullptr) {
28 IMSA_HILOGE("config is nullptr");
29 return;
30 }
31
32 delete config;
33 }
OH_TextConfig_SetInputType(InputMethod_TextConfig * config,InputMethod_TextInputType inputType)34 InputMethod_ErrorCode OH_TextConfig_SetInputType(InputMethod_TextConfig *config, InputMethod_TextInputType inputType)
35 {
36 if (config == nullptr) {
37 IMSA_HILOGE("config is nullptr");
38 return IME_ERR_NULL_POINTER;
39 }
40 config->inputType = inputType;
41 return IME_ERR_OK;
42 }
OH_TextConfig_SetEnterKeyType(InputMethod_TextConfig * config,InputMethod_EnterKeyType enterKeyType)43 InputMethod_ErrorCode OH_TextConfig_SetEnterKeyType(
44 InputMethod_TextConfig *config, InputMethod_EnterKeyType enterKeyType)
45 {
46 if (config == nullptr) {
47 IMSA_HILOGE("config is nullptr");
48 return IME_ERR_NULL_POINTER;
49 }
50
51 config->enterKeyType = enterKeyType;
52 return IME_ERR_OK;
53 }
OH_TextConfig_SetPreviewTextSupport(InputMethod_TextConfig * config,bool supported)54 InputMethod_ErrorCode OH_TextConfig_SetPreviewTextSupport(InputMethod_TextConfig *config, bool supported)
55 {
56 if (config == nullptr) {
57 IMSA_HILOGE("config is nullptr");
58 return IME_ERR_NULL_POINTER;
59 }
60 config->previewTextSupported = supported;
61 return IME_ERR_OK;
62 }
63
OH_TextConfig_SetSelection(InputMethod_TextConfig * config,int32_t start,int32_t end)64 InputMethod_ErrorCode OH_TextConfig_SetSelection(InputMethod_TextConfig *config, int32_t start, int32_t end)
65 {
66 if (config == nullptr) {
67 IMSA_HILOGE("config is nullptr");
68 return IME_ERR_NULL_POINTER;
69 }
70 config->selectionStart = start;
71 config->selectionEnd = end;
72 return IME_ERR_OK;
73 }
OH_TextConfig_SetWindowId(InputMethod_TextConfig * config,int32_t windowId)74 InputMethod_ErrorCode OH_TextConfig_SetWindowId(InputMethod_TextConfig *config, int32_t windowId)
75 {
76 if (config == nullptr) {
77 IMSA_HILOGE("config is nullptr");
78 return IME_ERR_NULL_POINTER;
79 }
80
81 config->windowId = windowId;
82 return IME_ERR_OK;
83 }
84
OH_TextConfig_GetInputType(InputMethod_TextConfig * config,InputMethod_TextInputType * inputType)85 InputMethod_ErrorCode OH_TextConfig_GetInputType(InputMethod_TextConfig *config, InputMethod_TextInputType *inputType)
86 {
87 if (config == nullptr) {
88 IMSA_HILOGE("config is nullptr");
89 return IME_ERR_NULL_POINTER;
90 }
91 if (inputType == nullptr) {
92 IMSA_HILOGE("inputType is nullptr");
93 return IME_ERR_NULL_POINTER;
94 }
95 *inputType = config->inputType;
96 return IME_ERR_OK;
97 }
98
OH_TextConfig_GetEnterKeyType(InputMethod_TextConfig * config,InputMethod_EnterKeyType * enterKeyType)99 InputMethod_ErrorCode OH_TextConfig_GetEnterKeyType(
100 InputMethod_TextConfig *config, InputMethod_EnterKeyType *enterKeyType)
101 {
102 if (config == nullptr) {
103 IMSA_HILOGE("config is nullptr");
104 return IME_ERR_NULL_POINTER;
105 }
106 if (enterKeyType == nullptr) {
107 IMSA_HILOGE("enterKeyType is nullptr");
108 return IME_ERR_NULL_POINTER;
109 }
110 *enterKeyType = config->enterKeyType;
111 return IME_ERR_OK;
112 }
113
OH_TextConfig_IsPreviewTextSupported(InputMethod_TextConfig * config,bool * supported)114 InputMethod_ErrorCode OH_TextConfig_IsPreviewTextSupported(InputMethod_TextConfig *config, bool *supported)
115 {
116 if (config == nullptr) {
117 IMSA_HILOGE("config is nullptr");
118 return IME_ERR_NULL_POINTER;
119 }
120 if (supported == nullptr) {
121 IMSA_HILOGE("supported is nullptr");
122 return IME_ERR_NULL_POINTER;
123 }
124 *supported = config->previewTextSupported;
125 return IME_ERR_OK;
126 }
127
OH_TextConfig_GetCursorInfo(InputMethod_TextConfig * config,InputMethod_CursorInfo ** cursorInfo)128 InputMethod_ErrorCode OH_TextConfig_GetCursorInfo(InputMethod_TextConfig *config, InputMethod_CursorInfo **cursorInfo)
129 {
130 if (config == nullptr) {
131 IMSA_HILOGE("config is nullptr");
132 return IME_ERR_NULL_POINTER;
133 }
134 if (cursorInfo == nullptr) {
135 IMSA_HILOGE("cursorInfo is nullptr");
136 return IME_ERR_NULL_POINTER;
137 }
138 *cursorInfo = &config->cursorInfo;
139 return IME_ERR_OK;
140 }
141
OH_TextConfig_GetTextAvoidInfo(InputMethod_TextConfig * config,InputMethod_TextAvoidInfo ** avoidInfo)142 InputMethod_ErrorCode OH_TextConfig_GetTextAvoidInfo(
143 InputMethod_TextConfig *config, InputMethod_TextAvoidInfo **avoidInfo)
144 {
145 if (config == nullptr) {
146 IMSA_HILOGE("config is nullptr");
147 return IME_ERR_NULL_POINTER;
148 }
149 if (avoidInfo == nullptr) {
150 IMSA_HILOGE("avoidInfo is nullptr");
151 return IME_ERR_NULL_POINTER;
152 }
153 *avoidInfo = &config->avoidInfo;
154 return IME_ERR_OK;
155 }
156
OH_TextConfig_GetSelection(InputMethod_TextConfig * config,int32_t * start,int32_t * end)157 InputMethod_ErrorCode OH_TextConfig_GetSelection(InputMethod_TextConfig *config, int32_t *start, int32_t *end)
158 {
159 if (config == nullptr) {
160 IMSA_HILOGE("config is nullptr");
161 return IME_ERR_NULL_POINTER;
162 }
163 if (start == nullptr) {
164 IMSA_HILOGE("start is nullptr");
165 return IME_ERR_NULL_POINTER;
166 }
167 if (end == nullptr) {
168 IMSA_HILOGE("end is nullptr");
169 return IME_ERR_NULL_POINTER;
170 }
171 *start = config->selectionStart;
172 *end = config->selectionEnd;
173 return IME_ERR_OK;
174 }
175
OH_TextConfig_GetWindowId(InputMethod_TextConfig * config,int32_t * windowId)176 InputMethod_ErrorCode OH_TextConfig_GetWindowId(InputMethod_TextConfig *config, int32_t *windowId)
177 {
178 if (config == nullptr) {
179 IMSA_HILOGE("config is nullptr");
180 return IME_ERR_NULL_POINTER;
181 }
182 if (windowId == nullptr) {
183 IMSA_HILOGE("windowId is nullptr");
184 return IME_ERR_NULL_POINTER;
185 }
186 *windowId = config->windowId;
187 return IME_ERR_OK;
188 }
189 #ifdef __cplusplus
190 }
191 #endif /* __cplusplus */