• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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
16import hilog from '@ohos.hilog'
17import { AsyncCallback } from "@ohos.base"
18import { BusinessError } from "@ohos.base"
19
20export namespace pointer {
21  loadLibrary("ani_pointer");
22
23  export native function setPointerStyleInner(windowId: number, pointerStyle: PointerStyle): int;
24
25  export enum PointerStyle {
26    DEFAULT,
27    EAST,
28    WEST,
29    SOUTH,
30    NORTH,
31
32    /**
33     * East-west arrow
34     *
35     * @syscap SystemCapability.MultimodalInput.Input.Pointer
36     * @since 9
37     */
38    WEST_EAST,
39
40    /**
41     * North-south arrow
42     *
43     * @syscap SystemCapability.MultimodalInput.Input.Pointer
44     * @since 9
45     */
46    NORTH_SOUTH,
47
48    /**
49     * North-east arrow
50     *
51     * @syscap SystemCapability.MultimodalInput.Input.Pointer
52     * @since 9
53     */
54    NORTH_EAST,
55
56    /**
57     * North-west arrow
58     *
59     * @syscap SystemCapability.MultimodalInput.Input.Pointer
60     * @since 9
61     */
62    NORTH_WEST,
63
64    /**
65     * South-east arrow
66     *
67     * @syscap SystemCapability.MultimodalInput.Input.Pointer
68     * @since 9
69     */
70    SOUTH_EAST,
71
72    /**
73     * South-west arrow
74     *
75     * @syscap SystemCapability.MultimodalInput.Input.Pointer
76     * @since 9
77     */
78    SOUTH_WEST,
79
80    /**
81     * Northeast and southwest adjustment
82     *
83     * @syscap SystemCapability.MultimodalInput.Input.Pointer
84     * @since 9
85     */
86    NORTH_EAST_SOUTH_WEST,
87
88    /**
89     * Northwest and southeast adjustment
90     *
91     * @syscap SystemCapability.MultimodalInput.Input.Pointer
92     * @since 9
93     */
94    NORTH_WEST_SOUTH_EAST,
95
96    /**
97     * Cross (accurate selection)
98     *
99     * @syscap SystemCapability.MultimodalInput.Input.Pointer
100     * @since 9
101     */
102    CROSS,
103
104    /**
105     * Copy
106     *
107     * @syscap SystemCapability.MultimodalInput.Input.Pointer
108     * @since 9
109     */
110    CURSOR_COPY,
111
112    /**
113     * Forbid
114     *
115     * @syscap SystemCapability.MultimodalInput.Input.Pointer
116     * @since 9
117     */
118    CURSOR_FORBID,
119
120    /**
121     * Sucker
122     *
123     * @syscap SystemCapability.MultimodalInput.Input.Pointer
124     * @since 9
125     */
126    COLOR_SUCKER,
127
128    /**
129     * Grabbing hand
130     *
131     * @syscap SystemCapability.MultimodalInput.Input.Pointer
132     * @since 9
133     */
134    HAND_GRABBING,
135
136    /**
137     * Opening hand
138     *
139     * @syscap SystemCapability.MultimodalInput.Input.Pointer
140     * @since 9
141     */
142    HAND_OPEN,
143
144    /**
145     * Hand-shaped pointer
146     *
147     * @syscap SystemCapability.MultimodalInput.Input.Pointer
148     * @since 9
149     */
150    HAND_POINTING,
151
152    /**
153     * Help
154     *
155     * @syscap SystemCapability.MultimodalInput.Input.Pointer
156     * @since 9
157     */
158    HELP,
159
160    /**
161     * Move
162     *
163     * @syscap SystemCapability.MultimodalInput.Input.Pointer
164     * @since 9
165     */
166    MOVE,
167
168    /**
169     * Left and right resizing
170     *
171     * @syscap SystemCapability.MultimodalInput.Input.Pointer
172     * @since 9
173     */
174    RESIZE_LEFT_RIGHT,
175
176    /**
177     * Up and down resizing
178     *
179     * @syscap SystemCapability.MultimodalInput.Input.Pointer
180     * @since 9
181     */
182    RESIZE_UP_DOWN,
183
184    /**
185     * Screenshot crosshair
186     *
187     * @syscap SystemCapability.MultimodalInput.Input.Pointer
188     * @since 9
189     */
190    SCREENSHOT_CHOOSE,
191
192    /**
193     * Screenshot
194     *
195     * @syscap SystemCapability.MultimodalInput.Input.Pointer
196     * @since 9
197     */
198    SCREENSHOT_CURSOR,
199
200    /**
201     * Text selection
202     *
203     * @syscap SystemCapability.MultimodalInput.Input.Pointer
204     * @since 9
205     */
206    TEXT_CURSOR,
207
208    /**
209     * Zoom in
210     *
211     * @syscap SystemCapability.MultimodalInput.Input.Pointer
212     * @since 9
213     */
214    ZOOM_IN,
215
216    /**
217     * Zoom out
218     *
219     * @syscap SystemCapability.MultimodalInput.Input.Pointer
220     * @since 9
221     */
222    ZOOM_OUT,
223
224    /**
225     * Scrolling east
226     *
227     * @syscap SystemCapability.MultimodalInput.Input.Pointer
228     * @since 9
229     */
230    MIDDLE_BTN_EAST,
231
232    /**
233     * Scrolling west
234     *
235     * @syscap SystemCapability.MultimodalInput.Input.Pointer
236     * @since 9
237     */
238    MIDDLE_BTN_WEST,
239
240    /**
241     * Scrolling south
242     *
243     * @syscap SystemCapability.MultimodalInput.Input.Pointer
244     * @since 9
245     */
246    MIDDLE_BTN_SOUTH,
247
248    /**
249     * Scrolling north
250     *
251     * @syscap SystemCapability.MultimodalInput.Input.Pointer
252     * @since 9
253     */
254    MIDDLE_BTN_NORTH,
255
256    /**
257     * Scrolling north and south
258     *
259     * @syscap SystemCapability.MultimodalInput.Input.Pointer
260     * @since 9
261     */
262    MIDDLE_BTN_NORTH_SOUTH,
263
264    /**
265     * Scrolling northeast
266     *
267     * @syscap SystemCapability.MultimodalInput.Input.Pointer
268     * @since 9
269     */
270    MIDDLE_BTN_NORTH_EAST,
271
272    /**
273     * Scrolling northwest
274     *
275     * @syscap SystemCapability.MultimodalInput.Input.Pointer
276     * @since 9
277     */
278    MIDDLE_BTN_NORTH_WEST,
279
280    /**
281     * Scrolling southeast
282     *
283     * @syscap SystemCapability.MultimodalInput.Input.Pointer
284     * @since 9
285     */
286    MIDDLE_BTN_SOUTH_EAST,
287
288    /**
289     * Scrolling southwest
290     *
291     * @syscap SystemCapability.MultimodalInput.Input.Pointer
292     * @since 9
293     */
294    MIDDLE_BTN_SOUTH_WEST,
295
296    /**
297     * Moving as a cone in four directions
298     *
299     * @syscap SystemCapability.MultimodalInput.Input.Pointer
300     * @since 9
301     */
302    MIDDLE_BTN_NORTH_SOUTH_WEST_EAST,
303
304    /**
305     * Horizontal text selection
306     *
307     * @syscap SystemCapability.MultimodalInput.Input.Pointer
308     * @since 10
309     */
310    HORIZONTAL_TEXT_CURSOR,
311
312    /**
313     * Precise selection
314     *
315     * @syscap SystemCapability.MultimodalInput.Input.Pointer
316     * @since 10
317     */
318    CURSOR_CROSS,
319
320    /**
321     * Cursor with circle style
322     *
323     * @syscap SystemCapability.MultimodalInput.Input.Pointer
324     * @since 10
325     */
326    CURSOR_CIRCLE,
327
328    /**
329     * Loading state with dynamic cursor
330     *
331     * @syscap SystemCapability.MultimodalInput.Input.Pointer
332     * @since 10
333     */
334    /**
335     * Loading state with dynamic cursor
336     *
337     * @syscap SystemCapability.MultimodalInput.Input.Pointer
338     * @atomicservice
339     * @since 12
340     */
341    LOADING,
342
343    /**
344     * Running state with dynamic cursor
345     *
346     * @syscap SystemCapability.MultimodalInput.Input.Pointer
347     * @since 10
348     */
349    /**
350     * Running state with dynamic cursor
351     *
352     * @syscap SystemCapability.MultimodalInput.Input.Pointer
353     * @atomicservice
354     * @since 12
355     */
356    RUNNING,
357
358    /**
359     * Scrolling east and west
360     *
361     * @syscap SystemCapability.MultimodalInput.Input.Pointer
362     * @since 16
363     */
364    MIDDLE_BTN_EAST_WEST
365  }
366
367  export function setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback<void>): void {
368    let p1 = taskpool.execute(setPointerStyleInner, windowId, pointerStyle);
369      p1.then((data: NullishType) => {
370        let ret =  data as int;
371        hilog.info(0x0000, 'pointer', "setPointerStyleInner callback then. ret is " + ret);
372        let err : BusinessError<void>
373        callback(err, undefined);
374      }).catch((error: NullishType) => {
375        let err =  error as BusinessError<void>;
376        hilog.info(0x0000, 'pointer', "setPointerStyleInner err is " + err);
377        callback(err, undefined);
378      });
379  }
380
381  export function setPointerStyle(windowId: number, pointerStyle: PointerStyle): Promise<void> {
382    let p = new Promise<void>((resolve: (v: undefined) => void,
383        reject: (error: Object) => void) : void => {
384        let p1 = taskpool.execute(setPointerStyleInner, windowId, pointerStyle);
385          p1.then((e :NullishType) : void=>{
386            let r = e as int;
387            hilog.info(0x0000, 'pointer', "setPointerStyleInner Promise, ret is: " + r);
388            resolve(undefined);
389        }).catch((err: Error) : void => {
390          reject(err);
391        });
392      });
393      return p;
394  }
395
396  export function setPointerStyleSync(windowId: number, pointerStyle: PointerStyle): void {
397    setPointerStyleInner(windowId, pointerStyle);
398  }
399}