1 /*
2 * Copyright (c) 2021-2022 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 #include "native_interface_xcomponent.h"
17
18 #include "frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h"
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
OH_NativeXComponent_GetXComponentId(OH_NativeXComponent * component,char * id,uint64_t * size)24 int32_t OH_NativeXComponent_GetXComponentId(OH_NativeXComponent* component, char* id, uint64_t* size)
25 {
26 if ((component == nullptr) || (id == nullptr) || (size == nullptr)) {
27 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
28 }
29 if (((*size) == 0) || ((*size) > (OH_XCOMPONENT_ID_LEN_MAX + 1))) {
30 LOGE("The referenced value of 'size' should be in the range (0, OH_XCOMPONENT_ID_LEN_MAX + 1]");
31 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
32 }
33 return component->GetXComponentId(id, size);
34 }
35
OH_NativeXComponent_GetXComponentSize(OH_NativeXComponent * component,const void * window,uint64_t * width,uint64_t * height)36 int32_t OH_NativeXComponent_GetXComponentSize(
37 OH_NativeXComponent* component, const void* window, uint64_t* width, uint64_t* height)
38 {
39 if ((component == nullptr) || (window == nullptr) || (width == nullptr) || (height == nullptr)) {
40 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
41 }
42 return component->GetXComponentSize(window, width, height);
43 }
44
OH_NativeXComponent_GetXComponentOffset(OH_NativeXComponent * component,const void * window,double * x,double * y)45 int32_t OH_NativeXComponent_GetXComponentOffset(
46 OH_NativeXComponent* component, const void* window, double* x, double* y)
47 {
48 if ((component == nullptr) || (window == nullptr) || (x == nullptr) || (y == nullptr)) {
49 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
50 }
51 return component->GetXComponentOffset(window, x, y);
52 }
53
OH_NativeXComponent_GetTouchEvent(OH_NativeXComponent * component,const void * window,OH_NativeXComponent_TouchEvent * touchEvent)54 int32_t OH_NativeXComponent_GetTouchEvent(
55 OH_NativeXComponent* component, const void* window, OH_NativeXComponent_TouchEvent* touchEvent)
56 {
57 if ((component == nullptr) || (window == nullptr) || (touchEvent == nullptr)) {
58 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
59 }
60 return component->GetTouchEvent(window, touchEvent);
61 }
62
OH_NativeXComponent_GetTouchPointToolType(OH_NativeXComponent * component,uint32_t pointIndex,OH_NativeXComponent_TouchPointToolType * toolType)63 int32_t OH_NativeXComponent_GetTouchPointToolType(OH_NativeXComponent* component, uint32_t pointIndex,
64 OH_NativeXComponent_TouchPointToolType* toolType)
65 {
66 if ((component == nullptr) || (toolType == nullptr)) {
67 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
68 }
69 return component->GetToolType(pointIndex, toolType);
70 }
71
OH_NativeXComponent_GetTouchPointTiltX(OH_NativeXComponent * component,uint32_t pointIndex,float * tiltX)72 int32_t OH_NativeXComponent_GetTouchPointTiltX(OH_NativeXComponent* component, uint32_t pointIndex, float* tiltX)
73 {
74 if ((component == nullptr) || (tiltX == nullptr)) {
75 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
76 }
77 return component->GetTiltX(pointIndex, tiltX);
78 }
79
OH_NativeXComponent_GetTouchPointTiltY(OH_NativeXComponent * component,uint32_t pointIndex,float * tiltY)80 int32_t OH_NativeXComponent_GetTouchPointTiltY(OH_NativeXComponent* component, uint32_t pointIndex, float* tiltY)
81 {
82 if ((component == nullptr) || (tiltY == nullptr)) {
83 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
84 }
85 return component->GetTiltY(pointIndex, tiltY);
86 }
87
OH_NativeXComponent_GetMouseEvent(OH_NativeXComponent * component,const void * window,OH_NativeXComponent_MouseEvent * mouseEvent)88 int32_t OH_NativeXComponent_GetMouseEvent(
89 OH_NativeXComponent* component, const void* window, OH_NativeXComponent_MouseEvent* mouseEvent)
90 {
91 if ((component == nullptr) || (window == nullptr) || (mouseEvent == nullptr)) {
92 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
93 }
94 return component->GetMouseEvent(window, mouseEvent);
95 }
96
OH_NativeXComponent_RegisterCallback(OH_NativeXComponent * component,OH_NativeXComponent_Callback * callback)97 int32_t OH_NativeXComponent_RegisterCallback(OH_NativeXComponent* component, OH_NativeXComponent_Callback* callback)
98 {
99 if ((component == nullptr) || (callback == nullptr)) {
100 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
101 }
102 return component->RegisterCallback(callback);
103 }
104
OH_NativeXComponent_RegisterMouseEventCallback(OH_NativeXComponent * component,OH_NativeXComponent_MouseEvent_Callback * callback)105 int32_t OH_NativeXComponent_RegisterMouseEventCallback(
106 OH_NativeXComponent* component, OH_NativeXComponent_MouseEvent_Callback* callback)
107 {
108 if ((component == nullptr) || (callback == nullptr)) {
109 return OH_NATIVEXCOMPONENT_RESULT_BAD_PARAMETER;
110 }
111 return component->RegisterMouseEventCallback(callback);
112 }
113
114 #ifdef __cplusplus
115 };
116 #endif
117