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/**
16 * @addtogroup InputMethod
17 * @{
18 *
19 * @brief InputMethod provides functions to use input methods and develop input methods.
20 *
21 * @since 12
22 */
23
24/**
25 * @file inputmethod_text_config_capi.h
26 *
27 * @brief Provides functions to manage the text configuration.
28 *
29 * @library libohinputmethod.so
30 * @kit IMEKit
31 * @syscap SystemCapability.MiscServices.InputMethodFramework
32 * @since 12
33 * @version 1.0
34 */
35#ifndef OHOS_INPUTMETHOD_TEXT_CONFIG_CAPI_H
36#define OHOS_INPUTMETHOD_TEXT_CONFIG_CAPI_H
37#include <stdint.h>
38
39#include "inputmethod_cursor_info_capi.h"
40#include "inputmethod_text_avoid_info_capi.h"
41#include "inputmethod_types_capi.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif /* __cplusplus */
46/**
47 * @brief Define the InputMethod_TextConfig structure type.
48 *
49 * The configuration of the text editor.
50 *
51 * @since 12
52 */
53typedef struct InputMethod_TextConfig InputMethod_TextConfig;
54
55/**
56 * @brief Create a new {@link InputMethod_TextConfig} instance.
57 *
58 * @return If the creation succeeds, a pointer to the newly created {@link InputMethod_TextConfig}
59 * instance is returned. If the creation fails, NULL is returned, possible cause is insufficient memory.
60 * @since 12
61 */
62InputMethod_TextConfig *OH_TextConfig_Create(void);
63/**
64 * @brief Destroy a {@link InputMethod_TextConfig} instance.
65 *
66 * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be destroyed.
67 * @since 12
68 */
69void OH_TextConfig_Destroy(InputMethod_TextConfig *config);
70
71/**
72 * @brief Set input type into TextConfig.
73 *
74 * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be set.
75 * @param inputType The text input type of text Editor, which is defined in {@link InputMethod_TextInputType}.
76 * @return Returns a specific error code.
77 *     {@link IME_ERR_OK} - success.
78 *     {@link IME_ERR_NULL_POINTER} - unexpected null pointer.
79 * Specific error codes can be referenced {@link InputMethod_ErrorCode}.
80 * @since 12
81 */
82InputMethod_ErrorCode OH_TextConfig_SetInputType(InputMethod_TextConfig *config, InputMethod_TextInputType inputType);
83/**
84 * @brief Set enter key type into TextConfig.
85 *
86 * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be set.
87 * @param enterKeyType The enter key type of text Editor, which is defined in {@link InputMethod_EnterKeyType}.
88 * @return Returns a specific error code.
89 *     {@link IME_ERR_OK} - success.
90 *     {@link IME_ERR_NULL_POINTER} - unexpected null pointer.
91 * Specific error codes can be referenced {@link InputMethod_ErrorCode}.
92 * @since 12
93 */
94InputMethod_ErrorCode OH_TextConfig_SetEnterKeyType(
95    InputMethod_TextConfig *config, InputMethod_EnterKeyType enterKeyType);
96/**
97 * @brief Set preview text support into TextConfig.
98 *
99 * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be set.
100 * @param supported Indicates whether the preview text is supported.
101 * @return Returns a specific error code.
102 *     {@link IME_ERR_OK} - success.
103 *     {@link IME_ERR_NULL_POINTER} - unexpected null pointer.
104 * Specific error codes can be referenced {@link InputMethod_ErrorCode}.
105 * @since 12
106 */
107InputMethod_ErrorCode OH_TextConfig_SetPreviewTextSupport(InputMethod_TextConfig *config, bool supported);
108/**
109 * @brief Set selection into TextConfig.
110 *
111 * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be set.
112 * @param start The start position of selection.
113 * @param end The end position of selection.
114 * @return Returns a specific error code.
115 *     {@link IME_ERR_OK} - success.
116 *     {@link IME_ERR_NULL_POINTER} - unexpected null pointer.
117 * Specific error codes can be referenced {@link InputMethod_ErrorCode}.
118 * @since 12
119 */
120InputMethod_ErrorCode OH_TextConfig_SetSelection(InputMethod_TextConfig *config, int32_t start, int32_t end);
121/**
122 * @brief Set window id into TextConfig.
123 *
124 * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be set.
125 * @param windowId The window ID of the application currently bound to the input method.
126 * @return Returns a specific error code.
127 *     {@link IME_ERR_OK} - success.
128 *     {@link IME_ERR_NULL_POINTER} - unexpected null pointer.
129 * Specific error codes can be referenced {@link InputMethod_ErrorCode}.
130 * @since 12
131 */
132InputMethod_ErrorCode OH_TextConfig_SetWindowId(InputMethod_TextConfig *config, int32_t windowId);
133
134/**
135 * @brief Get input type from TextConfig
136 *
137 * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be get from.
138 * @param inputType Represents a pointer to an {@link InputMethod_TextInputType} instance.
139 *     The text input type of text Editor
140 * @return Returns a specific error code.
141 *     {@link IME_ERR_OK} - success.
142 *     {@link IME_ERR_NULL_POINTER} - unexpected null pointer.
143 * Specific error codes can be referenced {@link InputMethod_ErrorCode}.
144 * @since 12
145 */
146InputMethod_ErrorCode OH_TextConfig_GetInputType(InputMethod_TextConfig *config, InputMethod_TextInputType *inputType);
147/**
148 * @brief Get enter key type from TextConfig
149 *
150 * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be get from.
151 * @param enterKeyType Represents a pointer to an {@link InputMethod_EnterKeyType} instance.
152 *     Indicates the enter key type of text Editor
153 * @return Returns a specific error code.
154 *     {@link IME_ERR_OK} - success.
155 *     {@link IME_ERR_NULL_POINTER} - unexpected null pointer.
156 * Specific error codes can be referenced {@link InputMethod_ErrorCode}.
157 * @since 12
158 */
159InputMethod_ErrorCode OH_TextConfig_GetEnterKeyType(
160    InputMethod_TextConfig *config, InputMethod_EnterKeyType *enterKeyType);
161/**
162 * @brief Get is preview text supported from TextConfig.
163 *
164 * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be get from.
165 * @param supported Indicates whether the preview text is supported.
166 * @return Returns a specific error code.
167 *     {@link IME_ERR_OK} - success.
168 *     {@link IME_ERR_NULL_POINTER} - unexpected null pointer.
169 * Specific error codes can be referenced {@link InputMethod_ErrorCode}.
170 * @since 12
171 */
172InputMethod_ErrorCode OH_TextConfig_IsPreviewTextSupported(InputMethod_TextConfig *config, bool *supported);
173/**
174 * @brief Get cursor info from TextConfig.
175 *
176 * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be get from.
177 * @param cursorInfo Represents a pointer to an {@link InputMethod_CursorInfo} instance.
178 * @return Returns a specific error code.
179 *     {@link IME_ERR_OK} - success.
180 *     {@link IME_ERR_NULL_POINTER} - unexpected null pointer.
181 * Specific error codes can be referenced {@link InputMethod_ErrorCode}.
182 * @since 12
183 */
184InputMethod_ErrorCode OH_TextConfig_GetCursorInfo(InputMethod_TextConfig *config, InputMethod_CursorInfo **cursorInfo);
185
186/**
187 * @brief Get text avoid information from text configuration.
188 *
189 * @param config Indicates the text configuration.
190 * @param avoidInfo Indicates the text avoid information.
191 * @return Returns a specific error code.
192 *     {@link IME_ERR_OK} - success.
193 *     {@link IME_ERR_NULL_POINTER} - unexpected null pointer.
194 * Specific error codes can be referenced {@link InputMethod_ErrorCode}.
195 *@since 12
196 */
197InputMethod_ErrorCode OH_TextConfig_GetTextAvoidInfo(
198    InputMethod_TextConfig *config, InputMethod_TextAvoidInfo **avoidInfo);
199
200/**
201 * @brief Get selection from TextConfig.
202 *
203 * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be get from.
204 * @param start Represents selection start position.
205 * @param end Represents selection end position.
206 * @return Returns a specific error code.
207 *     {@link IME_ERR_OK} - success.
208 *     {@link IME_ERR_NULL_POINTER} - unexpected null pointer.
209 * Specific error codes can be referenced {@link InputMethod_ErrorCode}.
210 * @since 12
211 */
212InputMethod_ErrorCode OH_TextConfig_GetSelection(InputMethod_TextConfig *config, int32_t *start, int32_t *end);
213/**
214 * @brief Get window id from TextConfig.
215 *
216 * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be get from.
217 * @param windowId The window ID of the application currently bound to the input method.
218 * @return Returns a specific error code.
219 *     {@link IME_ERR_OK} - success.
220 *     {@link IME_ERR_NULL_POINTER} - unexpected null pointer.
221 * Specific error codes can be referenced {@link InputMethod_ErrorCode}.
222 * @since 12
223 */
224InputMethod_ErrorCode OH_TextConfig_GetWindowId(InputMethod_TextConfig *config, int32_t *windowId);
225#ifdef __cplusplus
226}
227#endif /* __cplusplus */
228/** @} */
229#endif // OHOS_INPUTMETHOD_TEXT_CONFIG_CAPI_H