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 */
OH_CursorInfo_Create(double left,double top,double width,double height)20 InputMethod_CursorInfo *OH_CursorInfo_Create(double left, double top, double width, double height)
21 {
22     return new InputMethod_CursorInfo({ left, top, width, height });
23 }
OH_CursorInfo_Destroy(InputMethod_CursorInfo * cursorInfo)24 void OH_CursorInfo_Destroy(InputMethod_CursorInfo *cursorInfo)
25 {
26     if (cursorInfo == nullptr) {
27         return;
28     }
29     delete cursorInfo;
30 }
31 
OH_CursorInfo_SetRect(InputMethod_CursorInfo * cursorInfo,double left,double top,double width,double height)32 InputMethod_ErrorCode OH_CursorInfo_SetRect(
33     InputMethod_CursorInfo *cursorInfo, double left, double top, double width, double height)
34 {
35     if (cursorInfo == nullptr) {
36         IMSA_HILOGE("cursorInfo is nullptr");
37         return IME_ERR_NULL_POINTER;
38     }
39     cursorInfo->left = left;
40     cursorInfo->top = top;
41     cursorInfo->width = width;
42     cursorInfo->height = height;
43     return IME_ERR_OK;
44 }
45 
OH_CursorInfo_GetRect(InputMethod_CursorInfo * cursorInfo,double * left,double * top,double * width,double * height)46 InputMethod_ErrorCode OH_CursorInfo_GetRect(
47     InputMethod_CursorInfo *cursorInfo, double *left, double *top, double *width, double *height)
48 {
49     if (cursorInfo == nullptr) {
50         IMSA_HILOGE("cursorInfo is nullptr");
51         return IME_ERR_NULL_POINTER;
52     }
53     if (left == nullptr || top == nullptr || width == nullptr || height == nullptr) {
54         IMSA_HILOGE("invalid parameter");
55         return IME_ERR_NULL_POINTER;
56     }
57     *left = cursorInfo->left;
58     *top = cursorInfo->top;
59     *width = cursorInfo->width;
60     *height = cursorInfo->height;
61     return IME_ERR_OK;
62 }
63 #ifdef __cplusplus
64 }
65 #endif /* __cplusplus */