Repository navigation
Expand file tree
/
Copy pathnativeapi.gen.go
More file actions
6207 lines (5401 loc) · 214 KB
/
Copy pathnativeapi.gen.go
File metadata and controls
6207 lines (5401 loc) · 214 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// AUTO-GENERATED. DO NOT EDIT.
// Code generated by ./codegen. DO NOT EDIT.
// Any manual changes WILL BE LOST when this file is regenerated.
package nativeapi
/*
#include "bridge.gen.h"
*/
import "C"
import (
"runtime/cgo"
"unsafe"
)
// ClipboardData holds the native ClipboardData value.
type ClipboardData struct {
Text *string
HTML *string
Image *Image
FilePaths []string
}
func fromCClipboardData(raw C.native_clipboard_data_t) ClipboardData {
return ClipboardData{
Text: optionalStringFromC(raw.text),
HTML: optionalStringFromC(raw.html),
Image: wrapImage(uint64(C.native_handle_retain(raw.image)), false),
FilePaths: stringsFromC(raw.file_paths),
}
}
func toCClipboardData(value ClipboardData) (C.native_clipboard_data_t, func()) {
var raw C.native_clipboard_data_t
var cleanup []func()
var cField0 *C.char
if value.Text != nil {
cField0 = C.CString(*value.Text)
cleanup = append(cleanup, func() { C.free(unsafe.Pointer(cField0)) })
}
raw.text = cField0
var cField1 *C.char
if value.HTML != nil {
cField1 = C.CString(*value.HTML)
cleanup = append(cleanup, func() { C.free(unsafe.Pointer(cField1)) })
}
raw.html = cField1
raw.image = C.native_image_t(value.Image.nativeHandleValue())
cField3, cField3Cleanup := stringsToC(value.FilePaths)
cleanup = append(cleanup, func() { cField3Cleanup() })
raw.file_paths = cField3
return raw, func() {
for i := len(cleanup) - 1; i >= 0; i-- {
cleanup[i]()
}
}
}
// ClipboardEventType identifies the active event variant.
type ClipboardEventType int32
const (
ClipboardEventChanged ClipboardEventType = 0
)
// ClipboardEvent copies an event payload. Handle fields are borrowed until the callback returns.
// Only fields belonging to Type are populated.
type ClipboardEvent struct {
Type ClipboardEventType
}
func fromCClipboardEvent(raw *C.native_clipboard_event_t) ClipboardEvent {
value := ClipboardEvent{Type: ClipboardEventType(raw._type)}
switch value.Type {
case ClipboardEventChanged:
}
return value
}
//export goEvent_native_clipboard_event_t
func goEvent_native_clipboard_event_t(handle C.uintptr_t, event *C.native_clipboard_event_t) {
cgo.Handle(handle).Value().(func(ClipboardEvent))(fromCClipboardEvent(event))
}
type clipboard struct{}
// Clipboard provides access to the native Clipboard singleton.
// It has no owned handle and does not need to be released.
var Clipboard = clipboard{}
// IsSupported invokes the native IsSupported operation.
func (c clipboard) IsSupported() bool {
result := C.native_clipboard_is_supported()
return bool(result)
}
// IsChangeMonitoringSupported invokes the native IsChangeMonitoringSupported operation.
func (c clipboard) IsChangeMonitoringSupported() bool {
result := C.native_clipboard_is_change_monitoring_supported()
return bool(result)
}
// Read invokes the native Read operation.
func (c clipboard) Read(callback func(bool, ClipboardData)) {
var cArg0Fn C.native_clipboard_read_callback_t
var cArg0Data unsafe.Pointer
var cArg0Release C.native_release_user_data_t
if callback != nil {
cArg0Data = newCallback(callback)
cArg0Fn = C.native_clipboard_read_callback_t(C.go_get_native_clipboard_read_callback_t())
cArg0Release = C.native_release_user_data_t(C.go_get_release_callback())
}
C.native_clipboard_read(cArg0Fn, cArg0Data, cArg0Release)
}
// ReadText invokes the native ReadText operation.
func (c clipboard) ReadText(callback func(bool, *string)) {
var cArg0Fn C.native_clipboard_read_text_callback_t
var cArg0Data unsafe.Pointer
var cArg0Release C.native_release_user_data_t
if callback != nil {
cArg0Data = newCallback(callback)
cArg0Fn = C.native_clipboard_read_text_callback_t(C.go_get_native_clipboard_read_text_callback_t())
cArg0Release = C.native_release_user_data_t(C.go_get_release_callback())
}
C.native_clipboard_read_text(cArg0Fn, cArg0Data, cArg0Release)
}
// ReadHTML invokes the native ReadHtml operation.
func (c clipboard) ReadHTML(callback func(bool, *string)) {
var cArg0Fn C.native_clipboard_read_html_callback_t
var cArg0Data unsafe.Pointer
var cArg0Release C.native_release_user_data_t
if callback != nil {
cArg0Data = newCallback(callback)
cArg0Fn = C.native_clipboard_read_html_callback_t(C.go_get_native_clipboard_read_html_callback_t())
cArg0Release = C.native_release_user_data_t(C.go_get_release_callback())
}
C.native_clipboard_read_html(cArg0Fn, cArg0Data, cArg0Release)
}
// ReadImage invokes the native ReadImage operation.
func (c clipboard) ReadImage(callback func(bool, *Image)) {
var cArg0Fn C.native_clipboard_read_image_callback_t
var cArg0Data unsafe.Pointer
var cArg0Release C.native_release_user_data_t
if callback != nil {
cArg0Data = newCallback(callback)
cArg0Fn = C.native_clipboard_read_image_callback_t(C.go_get_native_clipboard_read_image_callback_t())
cArg0Release = C.native_release_user_data_t(C.go_get_release_callback())
}
C.native_clipboard_read_image(cArg0Fn, cArg0Data, cArg0Release)
}
// ReadFilePaths invokes the native ReadFilePaths operation.
func (c clipboard) ReadFilePaths(callback func(bool, []string)) {
var cArg0Fn C.native_clipboard_read_file_paths_callback_t
var cArg0Data unsafe.Pointer
var cArg0Release C.native_release_user_data_t
if callback != nil {
cArg0Data = newCallback(callback)
cArg0Fn = C.native_clipboard_read_file_paths_callback_t(C.go_get_native_clipboard_read_file_paths_callback_t())
cArg0Release = C.native_release_user_data_t(C.go_get_release_callback())
}
C.native_clipboard_read_file_paths(cArg0Fn, cArg0Data, cArg0Release)
}
// Write invokes the native Write operation.
// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
func (c clipboard) Write(data ClipboardData) error {
if !validClipboardOptionalText(data.Text) || !validClipboardOptionalText(data.HTML) || !validClipboardPaths(data.FilePaths) {
return ErrOperationFailed
}
cArg0, cArg0Cleanup := toCClipboardData(data)
defer cArg0Cleanup()
result := C.native_clipboard_write(cArg0)
if !bool(result) {
return nativeError("Clipboard.Write")
}
return nil
}
// WriteText invokes the native WriteText operation.
// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
func (c clipboard) WriteText(text string) error {
if !validClipboardText(text) {
return ErrOperationFailed
}
cArg0 := C.CString(text)
defer C.free(unsafe.Pointer(cArg0))
result := C.native_clipboard_write_text(cArg0)
if !bool(result) {
return nativeError("Clipboard.WriteText")
}
return nil
}
// WriteHTML invokes the native WriteHtml operation.
// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
func (c clipboard) WriteHTML(html string) error {
if !validClipboardText(html) {
return ErrOperationFailed
}
cArg0 := C.CString(html)
defer C.free(unsafe.Pointer(cArg0))
result := C.native_clipboard_write_html(cArg0)
if !bool(result) {
return nativeError("Clipboard.WriteHTML")
}
return nil
}
// WriteImage invokes the native WriteImage operation.
// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
func (c clipboard) WriteImage(image *Image) error {
result := C.native_clipboard_write_image(C.native_image_t(image.nativeHandleValue()))
if !bool(result) {
return nativeError("Clipboard.WriteImage")
}
return nil
}
// WriteFilePaths invokes the native WriteFilePaths operation.
// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
func (c clipboard) WriteFilePaths(filePaths []string) error {
if !validClipboardPaths(filePaths) {
return ErrOperationFailed
}
cArg0, cArg0Cleanup := stringsToC(filePaths)
defer cArg0Cleanup()
result := C.native_clipboard_write_file_paths(cArg0)
if !bool(result) {
return nativeError("Clipboard.WriteFilePaths")
}
return nil
}
// Clear invokes the native Clear operation.
// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
func (c clipboard) Clear() error {
result := C.native_clipboard_clear()
if !bool(result) {
return nativeError("Clipboard.Clear")
}
return nil
}
// IsMonitoring invokes the native IsMonitoring operation.
func (c clipboard) IsMonitoring() bool {
result := C.native_clipboard_is_monitoring()
return bool(result)
}
// AddListener invokes callback synchronously on the native UI thread.
// Remove the listener before releasing its owner. A nil callback is invalid.
func (c clipboard) AddListener(callback func(ClipboardEvent)) (ListenerID, error) {
if callback == nil {
return 0, invalidArgument("Clipboard.AddListener")
}
data := newCallback(callback)
id := C.native_clipboard_add_listener(C.native_clipboard_event_callback_t(C.go_get_native_clipboard_event_callback_t()), data, C.native_release_user_data_t(C.go_get_release_callback()))
if id == 0 {
return 0, nativeError("Clipboard.AddListener")
}
return ListenerID(id), nil
}
// RemoveListener unregisters id; an unknown id returns an error.
func (c clipboard) RemoveListener(id ListenerID) error {
if !bool(C.native_clipboard_remove_listener(C.native_listener_id_t(id))) {
return nativeError("Clipboard.RemoveListener")
}
return nil
}
// Point holds the native Point value.
type Point struct {
X float64
Y float64
}
func fromCPoint(raw C.native_point_t) Point {
return Point{
X: float64(raw.x),
Y: float64(raw.y),
}
}
func toCPoint(value Point) (C.native_point_t, func()) {
var raw C.native_point_t
var cleanup []func()
raw.x = C.double(value.X)
raw.y = C.double(value.Y)
return raw, func() {
for i := len(cleanup) - 1; i >= 0; i-- {
cleanup[i]()
}
}
}
// Size holds the native Size value.
type Size struct {
Width float64
Height float64
}
func fromCSize(raw C.native_size_t) Size {
return Size{
Width: float64(raw.width),
Height: float64(raw.height),
}
}
func toCSize(value Size) (C.native_size_t, func()) {
var raw C.native_size_t
var cleanup []func()
raw.width = C.double(value.Width)
raw.height = C.double(value.Height)
return raw, func() {
for i := len(cleanup) - 1; i >= 0; i-- {
cleanup[i]()
}
}
}
// Rectangle holds the native Rectangle value.
type Rectangle struct {
X float64
Y float64
Width float64
Height float64
}
func fromCRectangle(raw C.native_rectangle_t) Rectangle {
return Rectangle{
X: float64(raw.x),
Y: float64(raw.y),
Width: float64(raw.width),
Height: float64(raw.height),
}
}
func toCRectangle(value Rectangle) (C.native_rectangle_t, func()) {
var raw C.native_rectangle_t
var cleanup []func()
raw.x = C.double(value.X)
raw.y = C.double(value.Y)
raw.width = C.double(value.Width)
raw.height = C.double(value.Height)
return raw, func() {
for i := len(cleanup) - 1; i >= 0; i-- {
cleanup[i]()
}
}
}
// EdgeInsets holds the native EdgeInsets value.
type EdgeInsets struct {
Top float64
Right float64
Bottom float64
Left float64
}
func fromCEdgeInsets(raw C.native_edge_insets_t) EdgeInsets {
return EdgeInsets{
Top: float64(raw.top),
Right: float64(raw.right),
Bottom: float64(raw.bottom),
Left: float64(raw.left),
}
}
func toCEdgeInsets(value EdgeInsets) (C.native_edge_insets_t, func()) {
var raw C.native_edge_insets_t
var cleanup []func()
raw.top = C.double(value.Top)
raw.right = C.double(value.Right)
raw.bottom = C.double(value.Bottom)
raw.left = C.double(value.Left)
return raw, func() {
for i := len(cleanup) - 1; i >= 0; i-- {
cleanup[i]()
}
}
}
// EdgeInsetsAll invokes the native All operation.
func EdgeInsetsAll(value float64) EdgeInsets {
result := C.native_edge_insets_all(C.double(value))
return fromCEdgeInsets(result)
}
// EdgeInsetsSymmetric invokes the native Symmetric operation.
func EdgeInsetsSymmetric(vertical, horizontal float64) EdgeInsets {
result := C.native_edge_insets_symmetric(C.double(vertical), C.double(horizontal))
return fromCEdgeInsets(result)
}
// Color holds the native Color value.
type Color struct {
R uint8
G uint8
B uint8
A uint8
}
func fromCColor(raw C.native_color_t) Color {
return Color{
R: uint8(raw.r),
G: uint8(raw.g),
B: uint8(raw.b),
A: uint8(raw.a),
}
}
func toCColor(value Color) (C.native_color_t, func()) {
var raw C.native_color_t
var cleanup []func()
raw.r = C.uchar(value.R)
raw.g = C.uchar(value.G)
raw.b = C.uchar(value.B)
raw.a = C.uchar(value.A)
return raw, func() {
for i := len(cleanup) - 1; i >= 0; i-- {
cleanup[i]()
}
}
}
// ColorFromRGBA invokes the native FromRGBA operation.
func ColorFromRGBA(red, green, blue, alpha uint8) Color {
result := C.native_color_from_rgba(C.uchar(red), C.uchar(green), C.uchar(blue), C.uchar(alpha))
return fromCColor(result)
}
// ColorFromHex invokes the native FromHex operation.
func ColorFromHex(hex string) Color {
cArg0 := C.CString(hex)
defer C.free(unsafe.Pointer(cArg0))
result := C.native_color_from_hex(cArg0)
return fromCColor(result)
}
// ToRGBA invokes the native ToRGBA operation.
func (c Color) ToRGBA() uint32 {
cSelf, cSelfCleanup := toCColor(c)
defer cSelfCleanup()
result := C.native_color_to_rgba(cSelf)
return uint32(result)
}
// ToARGB invokes the native ToARGB operation.
func (c Color) ToARGB() uint32 {
cSelf, cSelfCleanup := toCColor(c)
defer cSelfCleanup()
result := C.native_color_to_argb(cSelf)
return uint32(result)
}
// ColorTransparent is the native transparent value.
var ColorTransparent = fromCColor(C.NATIVE_COLOR_TRANSPARENT)
// ColorBlack is the native black value.
var ColorBlack = fromCColor(C.NATIVE_COLOR_BLACK)
// ColorWhite is the native white value.
var ColorWhite = fromCColor(C.NATIVE_COLOR_WHITE)
// ColorRed is the native red value.
var ColorRed = fromCColor(C.NATIVE_COLOR_RED)
// ColorGreen is the native green value.
var ColorGreen = fromCColor(C.NATIVE_COLOR_GREEN)
// ColorBlue is the native blue value.
var ColorBlue = fromCColor(C.NATIVE_COLOR_BLUE)
// ColorYellow is the native yellow value.
var ColorYellow = fromCColor(C.NATIVE_COLOR_YELLOW)
// ColorCyan is the native cyan value.
var ColorCyan = fromCColor(C.NATIVE_COLOR_CYAN)
// ColorMagenta is the native magenta value.
var ColorMagenta = fromCColor(C.NATIVE_COLOR_MAGENTA)
// ModifierKey represents native ModifierKey values.
type ModifierKey int32
const (
ModifierKeyNone ModifierKey = 0
ModifierKeyShift ModifierKey = 1
ModifierKeyCtrl ModifierKey = 2
ModifierKeyAlt ModifierKey = 4
ModifierKeyMeta ModifierKey = 8
ModifierKeyFn ModifierKey = 16
ModifierKeyCapsLock ModifierKey = 32
ModifierKeyNumLock ModifierKey = 64
ModifierKeyScrollLock ModifierKey = 128
)
// KeyboardAccelerator holds the native KeyboardAccelerator value.
type KeyboardAccelerator struct {
Modifiers ModifierKey
Key string
}
func fromCKeyboardAccelerator(raw C.native_keyboard_accelerator_t) KeyboardAccelerator {
return KeyboardAccelerator{
Modifiers: ModifierKey(raw.modifiers),
Key: C.GoString(raw.key),
}
}
func toCKeyboardAccelerator(value KeyboardAccelerator) (C.native_keyboard_accelerator_t, func()) {
var raw C.native_keyboard_accelerator_t
var cleanup []func()
raw.modifiers = C.native_modifier_key_t(value.Modifiers)
cField1 := C.CString(value.Key)
cleanup = append(cleanup, func() { C.free(unsafe.Pointer(cField1)) })
raw.key = cField1
return raw, func() {
for i := len(cleanup) - 1; i >= 0; i-- {
cleanup[i]()
}
}
}
// String invokes the native ToString operation.
func (ka KeyboardAccelerator) String() string {
cSelf, cSelfCleanup := toCKeyboardAccelerator(ka)
defer cSelfCleanup()
result := C.native_keyboard_accelerator_to_string(cSelf)
defer C.free_c_str(result)
return C.GoString(result)
}
// IsEmpty invokes the native IsEmpty operation.
func (ka KeyboardAccelerator) IsEmpty() bool {
cSelf, cSelfCleanup := toCKeyboardAccelerator(ka)
defer cSelfCleanup()
result := C.native_keyboard_accelerator_is_empty(cSelf)
return bool(result)
}
// KeyboardEventType identifies the active event variant.
type KeyboardEventType int32
const (
KeyboardEventKeyPressed KeyboardEventType = 0
KeyboardEventKeyReleased KeyboardEventType = 1
KeyboardEventModifierKeysChanged KeyboardEventType = 2
)
// KeyboardEvent copies an event payload. Handle fields are borrowed until the callback returns.
// Only fields belonging to Type are populated.
type KeyboardEvent struct {
Type KeyboardEventType
Keycode int32
ModifierKeys uint32
}
func fromCKeyboardEvent(raw *C.native_keyboard_event_t) KeyboardEvent {
value := KeyboardEvent{Type: KeyboardEventType(raw._type)}
value.Keycode = int32(raw.keycode)
switch value.Type {
case KeyboardEventKeyPressed:
case KeyboardEventKeyReleased:
case KeyboardEventModifierKeysChanged:
value.ModifierKeys = uint32(C.go_native_keyboard_event_t_modifier_keys_changed_ModifierKeys(raw))
}
return value
}
//export goEvent_native_keyboard_event_t
func goEvent_native_keyboard_event_t(handle C.uintptr_t, event *C.native_keyboard_event_t) {
cgo.Handle(handle).Value().(func(KeyboardEvent))(fromCKeyboardEvent(event))
}
// EventDecision owns a native handle. Call Release on the UI thread when done.
// Copies share ownership state; borrowed event handles must not outlive their callback.
type EventDecision struct{ *nativeHandle }
func wrapEventDecision(value uint64, borrowed bool) *EventDecision {
if value == 0 {
return nil
}
return wrapEventDecisionState(&nativeHandle{value: value, borrowed: borrowed})
}
func wrapEventDecisionState(state *nativeHandle) *EventDecision {
return &EventDecision{state}
}
func (ed *EventDecision) nativeHandleValue() uint64 {
if ed == nil || ed.nativeHandle == nil {
return 0
}
return ed.nativeHandle.nativeHandleValue()
}
// Release drops this owned reference. Repeated calls and nil receivers are safe.
func (ed *EventDecision) Release() {
if ed.nativeHandleValue() == 0 || ed.borrowed {
return
}
C.native_event_decision_free(C.native_event_decision_t(ed.value))
ed.value = 0
}
// Accept invokes the native Accept operation.
// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
func (ed *EventDecision) Accept() error {
result := C.native_event_decision_accept(C.native_event_decision_t(ed.nativeHandleValue()))
if !bool(result) {
return nativeError("EventDecision.Accept")
}
return nil
}
// Cancel invokes the native Cancel operation.
// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
func (ed *EventDecision) Cancel() error {
result := C.native_event_decision_cancel(C.native_event_decision_t(ed.nativeHandleValue()))
if !bool(result) {
return nativeError("EventDecision.Cancel")
}
return nil
}
// IsPending invokes the native IsPending operation.
func (ed *EventDecision) IsPending() bool {
result := C.native_event_decision_is_pending(C.native_event_decision_t(ed.nativeHandleValue()))
return bool(result)
}
// EventRequest owns a native handle. Call Release on the UI thread when done.
// Copies share ownership state; borrowed event handles must not outlive their callback.
type EventRequest struct{ *nativeHandle }
func wrapEventRequest(value uint64, borrowed bool) *EventRequest {
if value == 0 {
return nil
}
return wrapEventRequestState(&nativeHandle{value: value, borrowed: borrowed})
}
func wrapEventRequestState(state *nativeHandle) *EventRequest {
return &EventRequest{state}
}
func (er *EventRequest) nativeHandleValue() uint64 {
if er == nil || er.nativeHandle == nil {
return 0
}
return er.nativeHandle.nativeHandleValue()
}
// Release drops this owned reference. Repeated calls and nil receivers are safe.
func (er *EventRequest) Release() {
if er.nativeHandleValue() == 0 || er.borrowed {
return
}
C.native_event_request_free(C.native_event_request_t(er.value))
er.value = 0
}
// IsCancelable invokes the native IsCancelable operation.
func (er *EventRequest) IsCancelable() bool {
result := C.native_event_request_is_cancelable(C.native_event_request_t(er.nativeHandleValue()))
return bool(result)
}
// IsCancelled invokes the native IsCancelled operation.
func (er *EventRequest) IsCancelled() bool {
result := C.native_event_request_is_cancelled(C.native_event_request_t(er.nativeHandleValue()))
return bool(result)
}
// IsPending invokes the native IsPending operation.
func (er *EventRequest) IsPending() bool {
result := C.native_event_request_is_pending(C.native_event_request_t(er.nativeHandleValue()))
return bool(result)
}
// Cancel invokes the native Cancel operation.
// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
func (er *EventRequest) Cancel() error {
result := C.native_event_request_cancel(C.native_event_request_t(er.nativeHandleValue()))
if !bool(result) {
return nativeError("EventRequest.Cancel")
}
return nil
}
// Defer invokes the native Defer operation.
// The returned reference is owned; nil means no object is available.
func (er *EventRequest) Defer() *EventDecision {
result := C.native_event_request_defer(C.native_event_request_t(er.nativeHandleValue()))
return wrapEventDecision(uint64(result), false)
}
// Placement represents native Placement values.
type Placement int32
const (
PlacementTop Placement = 0
PlacementTopStart Placement = 1
PlacementTopEnd Placement = 2
PlacementRight Placement = 3
PlacementRightStart Placement = 4
PlacementRightEnd Placement = 5
PlacementBottom Placement = 6
PlacementBottomStart Placement = 7
PlacementBottomEnd Placement = 8
PlacementLeft Placement = 9
PlacementLeftStart Placement = 10
PlacementLeftEnd Placement = 11
)
// DialogModality represents native DialogModality values.
type DialogModality int32
const (
DialogModalityNone DialogModality = 0
DialogModalityApplication DialogModality = 1
DialogModalityWindow DialogModality = 2
)
type accessibilityManager struct{}
// AccessibilityManager provides access to the native AccessibilityManager singleton.
// It has no owned handle and does not need to be released.
var AccessibilityManager = accessibilityManager{}
// Enable invokes the native Enable operation.
func (am accessibilityManager) Enable() {
C.native_accessibility_manager_enable()
}
// IsEnabled invokes the native IsEnabled operation.
func (am accessibilityManager) IsEnabled() bool {
result := C.native_accessibility_manager_is_enabled()
return bool(result)
}
// DisplayID identifies a native object.
type DisplayID uint32
// DisplayOrientation represents native DisplayOrientation values.
type DisplayOrientation int32
const (
DisplayOrientationPortrait DisplayOrientation = 0
DisplayOrientationLandscape DisplayOrientation = 90
DisplayOrientationPortraitFlipped DisplayOrientation = 180
DisplayOrientationLandscapeFlipped DisplayOrientation = 270
)
// DisplayEventType identifies the active event variant.
type DisplayEventType int32
const (
DisplayEventAdded DisplayEventType = 0
DisplayEventRemoved DisplayEventType = 1
DisplayEventChanged DisplayEventType = 2
)
// DisplayEvent copies an event payload. Handle fields are borrowed until the callback returns.
// Only fields belonging to Type are populated.
type DisplayEvent struct {
Type DisplayEventType
Display *Display
}
func fromCDisplayEvent(raw *C.native_display_event_t) DisplayEvent {
value := DisplayEvent{Type: DisplayEventType(raw._type)}
value.Display = wrapDisplay(uint64(raw.display), true)
switch value.Type {
case DisplayEventAdded:
case DisplayEventRemoved:
case DisplayEventChanged:
}
return value
}
//export goEvent_native_display_event_t
func goEvent_native_display_event_t(handle C.uintptr_t, event *C.native_display_event_t) {
cgo.Handle(handle).Value().(func(DisplayEvent))(fromCDisplayEvent(event))
}
// Display owns a native handle. Call Release on the UI thread when done.
// Copies share ownership state; borrowed event handles must not outlive their callback.
type Display struct{ *nativeHandle }
func wrapDisplay(value uint64, borrowed bool) *Display {
if value == 0 {
return nil
}
return wrapDisplayState(&nativeHandle{value: value, borrowed: borrowed})
}
func wrapDisplayState(state *nativeHandle) *Display {
return &Display{state}
}
func (d *Display) nativeHandleValue() uint64 {
if d == nil || d.nativeHandle == nil {
return 0
}
return d.nativeHandle.nativeHandleValue()
}
// Release drops this owned reference. Repeated calls and nil receivers are safe.
func (d *Display) Release() {
if d.nativeHandleValue() == 0 || d.borrowed {
return
}
C.native_display_free(C.native_display_t(d.value))
d.value = 0
}
// NewDisplayFromNative creates an owned Display.
// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
func NewDisplayFromNative(display unsafe.Pointer) (*Display, error) {
result := C.native_display_create(display)
if result == 0 {
return nil, nativeError("NewDisplayFromNative")
}
return wrapDisplay(uint64(result), false), nil
}
// ID invokes the native GetId operation.
func (d *Display) ID() DisplayID {
result := C.native_display_get_id(C.native_display_t(d.nativeHandleValue()))
return DisplayID(result)
}
// Name invokes the native GetName operation.
func (d *Display) Name() string {
result := C.native_display_get_name(C.native_display_t(d.nativeHandleValue()))
defer C.free_c_str(result)
return C.GoString(result)
}
// Position invokes the native GetPosition operation.
func (d *Display) Position() Point {
result := C.native_display_get_position(C.native_display_t(d.nativeHandleValue()))
return fromCPoint(result)
}
// Size invokes the native GetSize operation.
func (d *Display) Size() Size {
result := C.native_display_get_size(C.native_display_t(d.nativeHandleValue()))
return fromCSize(result)
}
// WorkArea invokes the native GetWorkArea operation.
func (d *Display) WorkArea() Rectangle {
result := C.native_display_get_work_area(C.native_display_t(d.nativeHandleValue()))
return fromCRectangle(result)
}
// ScaleFactor invokes the native GetScaleFactor operation.
func (d *Display) ScaleFactor() float64 {
result := C.native_display_get_scale_factor(C.native_display_t(d.nativeHandleValue()))
return float64(result)
}
// IsPrimary invokes the native IsPrimary operation.
func (d *Display) IsPrimary() bool {
result := C.native_display_is_primary(C.native_display_t(d.nativeHandleValue()))
return bool(result)
}
// Orientation invokes the native GetOrientation operation.
func (d *Display) Orientation() DisplayOrientation {
result := C.native_display_get_orientation(C.native_display_t(d.nativeHandleValue()))
return DisplayOrientation(result)
}
// RefreshRate invokes the native GetRefreshRate operation.
func (d *Display) RefreshRate() int32 {
result := C.native_display_get_refresh_rate(C.native_display_t(d.nativeHandleValue()))
return int32(result)
}
// BitDepth invokes the native GetBitDepth operation.
func (d *Display) BitDepth() int32 {
result := C.native_display_get_bit_depth(C.native_display_t(d.nativeHandleValue()))
return int32(result)
}
// NativeObject returns a borrowed platform pointer.
func (d *Display) NativeObject() unsafe.Pointer {
return C.native_display_get_native_object(C.native_display_t(d.nativeHandleValue()))
}
type displayManager struct{}
// DisplayManager provides access to the native DisplayManager singleton.
// It has no owned handle and does not need to be released.
var DisplayManager = displayManager{}
// All invokes the native GetAll operation.
func (dm displayManager) All() []*Display {
result := C.native_display_manager_get_all()
defer C.native_display_list_release(&result)
return listDisplayFromC(result, false)
}
// Primary invokes the native GetPrimary operation.
// The returned reference is owned; nil means no object is available.
func (dm displayManager) Primary() *Display {
result := C.native_display_manager_get_primary()
return wrapDisplay(uint64(result), false)
}
// CursorPosition invokes the native GetCursorPosition operation.
func (dm displayManager) CursorPosition() Point {
result := C.native_display_manager_get_cursor_position()
return fromCPoint(result)
}
// AddListener invokes callback synchronously on the native UI thread.
// Remove the listener before releasing its owner. A nil callback is invalid.
func (dm displayManager) AddListener(callback func(DisplayEvent)) (ListenerID, error) {
if callback == nil {
return 0, invalidArgument("DisplayManager.AddListener")
}
data := newCallback(callback)
id := C.native_display_manager_add_listener(C.native_display_event_callback_t(C.go_get_native_display_event_callback_t()), data, C.native_release_user_data_t(C.go_get_release_callback()))
if id == 0 {
return 0, nativeError("DisplayManager.AddListener")
}
return ListenerID(id), nil
}
// RemoveListener unregisters id; an unknown id returns an error.
func (dm displayManager) RemoveListener(id ListenerID) error {
if !bool(C.native_display_manager_remove_listener(C.native_listener_id_t(id))) {
return nativeError("DisplayManager.RemoveListener")
}
return nil
}
// URLOpenErrorCode represents native UrlOpenErrorCode values.
type URLOpenErrorCode int32
const (
URLOpenErrorCodeNone URLOpenErrorCode = 0
URLOpenErrorCodeInvalidURLEmpty URLOpenErrorCode = 1
URLOpenErrorCodeInvalidURLMissingScheme URLOpenErrorCode = 2
URLOpenErrorCodeInvalidURLUnsupportedScheme URLOpenErrorCode = 3
URLOpenErrorCodeUnsupportedPlatform URLOpenErrorCode = 4
URLOpenErrorCodeInvocationFailed URLOpenErrorCode = 5
)
// URLOpenResult holds the native UrlOpenResult value.
type URLOpenResult struct {
Success bool
ErrorCode URLOpenErrorCode
ErrorMessage string
}
func fromCURLOpenResult(raw C.native_url_open_result_t) URLOpenResult {
return URLOpenResult{
Success: bool(raw.success),
ErrorCode: URLOpenErrorCode(raw.error_code),
ErrorMessage: C.GoString(raw.error_message),
}
}
func toCURLOpenResult(value URLOpenResult) (C.native_url_open_result_t, func()) {
var raw C.native_url_open_result_t
var cleanup []func()
raw.success = C.bool(value.Success)
raw.error_code = C.native_url_open_error_code_t(value.ErrorCode)
cField2 := C.CString(value.ErrorMessage)
cleanup = append(cleanup, func() { C.free(unsafe.Pointer(cField2)) })
raw.error_message = cField2
return raw, func() {
for i := len(cleanup) - 1; i >= 0; i-- {
cleanup[i]()
}
}
}
type urlOpener struct{}
// URLOpener provides access to the native URLOpener singleton.
// It has no owned handle and does not need to be released.
var URLOpener = urlOpener{}
// IsSupported invokes the native IsSupported operation.
func (uo urlOpener) IsSupported() bool {
result := C.native_url_opener_is_supported()
return bool(result)
}
// CanOpen invokes the native CanOpen operation.
func (uo urlOpener) CanOpen(url string) bool {
cArg0 := C.CString(url)
defer C.free(unsafe.Pointer(cArg0))
result := C.native_url_opener_can_open(cArg0)
return bool(result)
}
// Open invokes the native Open operation.
func (uo urlOpener) Open(url string) URLOpenResult {
cArg0 := C.CString(url)
defer C.free(unsafe.Pointer(cArg0))
result := C.native_url_opener_open(cArg0)