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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-graphics")]
#[cfg(target_vendor = "apple")]
use objc2_core_graphics::*;
use objc2_foundation::*;
use crate::*;
/// Constants that specify the reason you updated your view’s content
/// outside of the Writing Tools workflow.
///
/// If you modify your view’s text storage while Writing Tools is active,
/// report those changes to your ``NSWritingToolsCoordinator`` object
/// so it can track them correctly. Call the
/// ``NSWritingToolsCoordinator/updateRange(_:with:reason:forContextWithIdentifier:)``
/// method to report changes that occur inside one of your context objects. Call the
/// ``NSWritingToolsCoordinator/updateForReflowedTextInContextWithIdentifier(_:)``
/// method for changes that affect the layout of your text, such as text insertions
/// before a context object or changes to your view’s frame rectangle.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatortextupdatereason?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSWritingToolsCoordinatorTextUpdateReason(pub NSInteger);
impl NSWritingToolsCoordinatorTextUpdateReason {
/// An operation that involved a person editing the text in your view.
///
/// Specify this option when the changes come from the text input system.
#[doc(alias = "NSWritingToolsCoordinatorTextUpdateReasonTyping")]
pub const Typing: Self = Self(0);
/// An operation that changed the view’s text as part of an undo or
/// redo command.
///
/// Specify this option when an undo or redo command initiated the
/// change to your view.
#[doc(alias = "NSWritingToolsCoordinatorTextUpdateReasonUndoRedo")]
pub const UndoRedo: Self = Self(1);
}
unsafe impl Encode for NSWritingToolsCoordinatorTextUpdateReason {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for NSWritingToolsCoordinatorTextUpdateReason {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// The states that indicate the current activity, if any, Writing Tools
/// is performing in your view.
///
/// Making changes to your view requires several different levels of
/// interaction. Initially, Writing Tools displays its UI and collects
/// information about what the person wants to do. When the person selects
/// an operation, Writing Tools sends the relevant details to a large language
/// model (LLM) and processes the results. It then works with the custom view to
/// integrate any changes into the view’s text storage. During each
/// of these activities, the coordinator reflects what’s happening in
/// its ``NSWritingToolsCoordinator/state`` property. You can use
/// the current state as a guide to making decisions in other parts of your view.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatorstate?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSWritingToolsCoordinatorState(pub NSInteger);
impl NSWritingToolsCoordinatorState {
/// A state that indicates Writing Tools isn’t currently performing
/// any work on your view’s content.
///
/// The coordinator starts in the `inactive` state, and transitions
/// immediately to the ``noninteractive`` or ``interactiveResting``
/// state when someone chooses an option from the Writing Tools UI.
/// After the coordinator finishes incorporating any changes for the
/// current operation, it returns to the `inactive` state and waits
/// for the person to choose a different option or dismiss the Writing Tools UI.
#[doc(alias = "NSWritingToolsCoordinatorStateInactive")]
pub const Inactive: Self = Self(0);
/// A state that indicates Writing Tools is handling interactions in
/// the system UI, instead of in your view.
///
/// Writing Tools transitions to this state when the coordinator uses
/// the ``NSWritingToolsBehavior/limited`` experience or when someone chooses an
/// option that displays its results in the Writing Tools UI. When
/// the person accepts the changes from the tool or dismisses the
/// Writing Tools UI, the coordinator returns to the ``inactive``
/// state. If the person discards the change and selects a tool with
/// an interactive experience instead, the coordinator transitions
/// to the ``interactiveResting`` state.
#[doc(alias = "NSWritingToolsCoordinatorStateNoninteractive")]
pub const Noninteractive: Self = Self(1);
/// A state that indicates Writing Tools is in the resting state
/// for an inline editing experience.
///
/// When someone initially selects a tool with an interactive experience,
/// the coordinator transitions briefly to this state and starts the
/// operation. The coordinator transitions swiftly to the ``interactiveStreaming``
/// state when it submits the request and delivers the results to your
/// view. When it finishes delivering the results, it transitions back
/// to the `interactiveResting` state and awaits further commands. If
/// the person accepts the changes or dismisses the Writing Tools UI,
/// the coordinator transitions from this state to the ``inactive`` state.
#[doc(alias = "NSWritingToolsCoordinatorStateInteractiveResting")]
pub const InteractiveResting: Self = Self(2);
/// A state that indicates Writing Tools is processing a request and
/// incorporating changes interactively into your view.
///
/// The coordinator transitions swiftly from the ``interactiveResting``
/// state to this state at the start of an operation. In this state,
/// the coordinator submits the request for processing and delivers
/// the results back to your view. When the coordinator finishes delivering
/// the results, it transitions back to the ``interactiveResting`` state.
#[doc(alias = "NSWritingToolsCoordinatorStateInteractiveStreaming")]
pub const InteractiveStreaming: Self = Self(3);
}
unsafe impl Encode for NSWritingToolsCoordinatorState {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for NSWritingToolsCoordinatorState {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// Options that indicate whether Writing Tools is animating changes to
/// your view’s text.
///
/// During an operation, Writing Tools delivers replacement text to the
/// delegate of the active ``NSWritingToolsCoordinator`` object. Depending
/// on the configured experience for your view, it delivers these changes
/// as either interactive or noninteractive replacements. For interactive
/// replacements, Writing Tools animates the change automatically and provides
/// you with the information you need to perform any related animations.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatortextreplacementreason?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSWritingToolsCoordinatorTextReplacementReason(pub NSInteger);
impl NSWritingToolsCoordinatorTextReplacementReason {
/// An option to animate the replacement of text in your view.
///
/// When Writing Tools requests an interactive change in your delegate’s
/// ``NSWritingToolsCoordinator/writingToolsCoordinator(_:replaceRange:inContext:proposedText:reason:animationParameters:completion:)``
/// method, it passes a valid set of animation parameters to that method.
/// Update your view’s text storage and use the provided ``NSWritingToolsCoordinator/AnimationParameters``
/// type to create any view-specific animations you need to support the
/// animated replacement of the text.
#[doc(alias = "NSWritingToolsCoordinatorTextReplacementReasonInteractive")]
pub const Interactive: Self = Self(0);
/// An option to replace the text in your view without animating the change.
///
/// When Writing Tools requests a noninteractive change in your delegate’s
/// ``NSWritingToolsCoordinator/writingToolsCoordinator(_:replaceRange:inContext:proposedText:reason:animationParameters:completion:)``
/// method, update your view’s text storage without animating the change.
#[doc(alias = "NSWritingToolsCoordinatorTextReplacementReasonNoninteractive")]
pub const Noninteractive: Self = Self(1);
}
unsafe impl Encode for NSWritingToolsCoordinatorTextReplacementReason {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for NSWritingToolsCoordinatorTextReplacementReason {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// Options that indicate how much of your content Writing Tools requested.
///
/// At the start of any Writing Tools interaction, you provide the text for
/// the system to evaluate from your ``NS/UIWritingToolsCoordinator/Delegate``
/// object. The request for your content comes with a scope constant that
/// indicates how much of your view’s text to provide.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatorcontextscope?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSWritingToolsCoordinatorContextScope(pub NSInteger);
impl NSWritingToolsCoordinatorContextScope {
/// An option to provide only the view’s currently selected text.
///
/// With this option, include the selected text in your context object,
/// along with some additional text before and after the selection. When
/// performing changes inline with your view’s content, Writing Tools
/// applies animations only to the selected text.
#[doc(alias = "NSWritingToolsCoordinatorContextScopeUserSelection")]
pub const UserSelection: Self = Self(0);
/// An option to provide all of your view’s text.
///
/// With this option, include all of the text your view manages. If your
/// view has multiple text storage objects, create a separate context object
/// for each one.
#[doc(alias = "NSWritingToolsCoordinatorContextScopeFullDocument")]
pub const FullDocument: Self = Self(1);
/// An option to provide only the text in the currently visible portion
/// of your view.
///
/// With this option, include only the currently visible text, along with
/// some additional text before and after the visible text.
#[doc(alias = "NSWritingToolsCoordinatorContextScopeVisibleArea")]
pub const VisibleArea: Self = Self(2);
}
unsafe impl Encode for NSWritingToolsCoordinatorContextScope {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for NSWritingToolsCoordinatorContextScope {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
/// Use the `NSWritingToolsCoordinator.TextAnimation` constants to determine
/// the type of animation that is occurring. During an interactive change to
/// your view, Writing Tools creates animations to provide feedback about what’s
/// happening. During the setup for each animation, Writing Tools reports the
/// type of animation to the coordinator’s delegate, so that you can perform
/// additional actions related to that animation. For example, during an insertion
/// animation, you might animate changes to other views in your interface.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatortextanimation?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSWritingToolsCoordinatorTextAnimation(pub NSInteger);
impl NSWritingToolsCoordinatorTextAnimation {
/// The animation that Writing Tools performs when waiting to receive
/// results from the large language model.
///
/// This type of animation applies a visual effect to the text that
/// Writing Tools is evaluating. When preparing for this animation, hide
/// the text that Writing Tools is about to evaluate. In the same space
/// where that text appears, Writing Tools displays a preview image that
/// you provide and animates changes to that image.
#[doc(alias = "NSWritingToolsCoordinatorTextAnimationAnticipate")]
pub const Anticipate: Self = Self(0);
/// The animation that Writing Tools performs when removing text from your view.
///
/// This type of animation shows the removal of text from your view. When
/// preparing for this animation, hide the text in the provided range if
/// you haven’t already. If you support animating the reflow of your view’s
/// text, you can also prepare any other animations you need. Writing Tools
/// uses a preview object you provide to animate the removal of the text.
#[doc(alias = "NSWritingToolsCoordinatorTextAnimationRemove")]
pub const Remove: Self = Self(1);
/// The animation that Writing Tools performs when inserting text into your view.
///
/// This type of animation shows the insertion of text to your view. When preparing
/// for this animation, hide the text in the provided range if you haven’t
/// already. If you support animating the reflow of your view’s text, you can
/// also prepare any other animations you need. Writing Tools uses a preview
/// object you provide to animate the insertion of the text.
#[doc(alias = "NSWritingToolsCoordinatorTextAnimationInsert")]
pub const Insert: Self = Self(2);
/// The animation effect that Writing Tools performs when the view is waiting
/// for results, but the system isn’t actively evaluating the text.
///
/// When Writing Tools isn’t actively evaluating your text, it creates this animation.
/// When preparing for this animation, display the text in the specified range
/// with a foreground color of 50% grey.
#[doc(alias = "NSWritingToolsCoordinatorTextAnimationAnticipateInactive")]
pub const AnticipateInactive: Self = Self(8);
/// The animation effect that Writing Tools performs on text situated after
/// the insertion point.
///
/// When Writing Tools inserts text at a given location, it creates an animation
/// to make room for the new text. When preparing for this animation, hide the
/// text between the insertion point and the end of your text storage. When
/// finishing the animation, show the text again.
#[doc(alias = "NSWritingToolsCoordinatorTextAnimationTranslate")]
pub const Translate: Self = Self(9);
}
unsafe impl Encode for NSWritingToolsCoordinatorTextAnimation {
const ENCODING: Encoding = NSInteger::ENCODING;
}
unsafe impl RefEncode for NSWritingToolsCoordinatorTextAnimation {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_class!(
/// An object that manages interactions between Writing Tools and
/// your custom text view.
///
/// Add a `NSWritingToolsCoordinator` object to a custom view when you
/// want to add Writing Tools support to that view. The coordinator manages
/// interactions between your view and the Writing Tools UI and back-end
/// capabilities. When creating a coordinator, you supply a delegate object
/// to respond to requests from the system and provide needed information.
/// Your delegate delivers your view’s text to Writing Tools, incorporates
/// suggested changes back into your text storage, and supports the animations
/// that Writing Tools creates to show the state of an operation.
///
/// Create the `NSWritingToolsCoordinator` object when setting up your UI, and
/// initialize it with a custom object that adopts the ``NSWritingToolsCoordinator/Delegate``
/// protocol. Add the coordinator to the ``NSView/writingToolsCoordinator`` property
/// of your view. When a coordinator is present on a view, the system adds UI elements
/// to initiate Writing Tools operations.
///
/// When defining the delegate, choose an object from your app that has access
/// to your view and its text storage. You can adopt the ``NSWritingToolsCoordinator/Delegate``
/// protocol in the view itself, or in another type that your view uses to
/// manage content. During the interactions with Writing Tools, the delegate
/// gets and sets the contents of the view’s text storage and supports Writing Tools behaviors.
///
/// > Note: You don’t need to create an `NSWritingToolsCoordinator` object
/// if you display text using a
/// <doc
/// ://com.apple.documentation/documentation/uikit/uitextview>,
/// ``NSTextField``,
/// ``NSTextView``,
/// <doc
/// ://com.apple.documentation/documentation/swiftui/textfield>, or
/// <doc
/// ://com.apple.documentation/documentation/swiftui/texteditor> view.
/// Those views already include the required support to handle Writing Tools
/// interactions.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinator?language=objc)
#[unsafe(super(NSObject))]
#[thread_kind = MainThreadOnly]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct NSWritingToolsCoordinator;
);
extern_conformance!(
unsafe impl NSObjectProtocol for NSWritingToolsCoordinator {}
);
impl NSWritingToolsCoordinator {
extern_methods!(
/// A Boolean value that indicates whether Writing Tools features are
/// currently available.
///
/// The value of this property is `true` when Writing Tools features are
/// available, and `false` when they aren’t. Writing Tools support might
/// be unavailable because of device constraints or because the system isn’t
/// ready to process Writing Tools requests.
#[unsafe(method(isWritingToolsAvailable))]
#[unsafe(method_family = none)]
pub fn isWritingToolsAvailable(mtm: MainThreadMarker) -> bool;
/// Creates a writing tools coordinator and assigns the specified
/// delegate object to it.
///
/// - Parameters:
/// - delegate: An object capable of handling Writing Tools interactions
/// for your view. The delegate must be able to modify your view’s text
/// storage and refresh the view’s layout and appearance.
///
/// Create the coordinator object during your view’s initialization, and assign
/// the object to your view. Assign the coordinator to the ``NSView/writingToolsCoordinator``
/// property of your view.
#[unsafe(method(initWithDelegate:))]
#[unsafe(method_family = init)]
pub fn initWithDelegate(
this: Allocated<Self>,
delegate: Option<&ProtocolObject<dyn NSWritingToolsCoordinatorDelegate>>,
) -> Retained<Self>;
/// The object that handles Writing Tools interactions for your view.
///
/// Specify this object at initialization time when creating your `NSWritingToolsCoordinator`
/// object. The object must adopt the ``NSWritingToolsCoordinator/Delegate``
/// protocol, and be capable of modifying your view’s text storage and
/// refreshing the view’s layout and appearance.
#[unsafe(method(delegate))]
#[unsafe(method_family = none)]
pub fn delegate(
&self,
) -> Option<Retained<ProtocolObject<dyn NSWritingToolsCoordinatorDelegate>>>;
#[cfg(all(feature = "NSResponder", feature = "NSView"))]
/// The view that currently uses the writing tools coordinator.
///
/// Use this property to refer to the view that currently owns the coordinator
/// object. The system updates this property automatically when you assign the
/// coordinator to the ``NSView/writingToolsCoordinator`` property of your view.
/// The value of this property is `nil` if there is no associated view.
#[unsafe(method(view))]
#[unsafe(method_family = none)]
pub fn view(&self) -> Option<Retained<NSView>>;
#[cfg(all(feature = "NSResponder", feature = "NSView"))]
/// The view that Writing Tools uses to display visual effects during
/// the text-rewriting process.
///
/// Writing Tools uses the view in this property to host the visual effects
/// it creates when making interactive changes to your view’s content.
/// These visual effects let people know the state of the text and provide
/// feedback about what’s happening to it. Set this property to a subview
/// that sits visually above, and covers, all of the text in your custom
/// text view. If you don’t assign a value to this property, the coordinator
/// places its own effect view in front of the subviews in your custom view.
/// The default value of this property is `nil`.
///
/// If you display your view’s text using multiple text containers, implement the
/// ``NSWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:singleContainerSubrangesOf:in:)``
/// method to request multiple previews.
#[unsafe(method(effectContainerView))]
#[unsafe(method_family = none)]
pub fn effectContainerView(&self) -> Option<Retained<NSView>>;
#[cfg(all(feature = "NSResponder", feature = "NSView"))]
/// Setter for [`effectContainerView`][Self::effectContainerView].
///
/// This is a [weak property][objc2::topics::weak_property].
#[unsafe(method(setEffectContainerView:))]
#[unsafe(method_family = none)]
pub fn setEffectContainerView(&self, effect_container_view: Option<&NSView>);
#[cfg(all(feature = "NSResponder", feature = "NSView"))]
/// The view that Writing Tools uses to display background decorations
/// such as proofreading marks.
///
/// Writing Tools uses the view in this property to host proofreading marks
/// and other visual elements that show any suggested changes. Set this
/// property to a subview situated visibly below the text in your custom
/// text view. It's also satisfactory to place this view visually in front
/// of the text. Make sure the size of the view is big enough to
/// cover all of the affected text. If you don’t assign a value to this
/// property, the coordinator places its own decoration view behind the subviews
/// in your custom view. The default value of this property is `nil`.
///
/// If you display your view’s text using multiple text containers, implement the
/// ``NSWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:singleContainerSubrangesOf:in:)``
/// and ``NSWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:decorationContainerViewFor:in:)``
/// methods to provide separate decoration views for each container.
#[unsafe(method(decorationContainerView))]
#[unsafe(method_family = none)]
pub fn decorationContainerView(&self) -> Option<Retained<NSView>>;
#[cfg(all(feature = "NSResponder", feature = "NSView"))]
/// Setter for [`decorationContainerView`][Self::decorationContainerView].
///
/// This is a [weak property][objc2::topics::weak_property].
#[unsafe(method(setDecorationContainerView:))]
#[unsafe(method_family = none)]
pub fn setDecorationContainerView(&self, decoration_container_view: Option<&NSView>);
/// The current level of Writing Tools activity in your view.
///
/// Use this property to determine when Writing Tools is actively making
/// changes to your view. During the course of Writing Tools interactions,
/// the system reports state changes to the delegate’s
/// ``NSWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:willChangeTo:completion:)``
/// method and updates this property accordingly.
#[unsafe(method(state))]
#[unsafe(method_family = none)]
pub fn state(&self) -> NSWritingToolsCoordinatorState;
/// Stops the current Writing Tools operation and dismisses the system UI.
///
/// Call this method to abort the current Writing Tools operation. This
/// method dismisses the system’s Writing Tools UI and stops any in-flight
/// interactions with your view. This method does not undo any changes that
/// Writing Tools already made to your view’s content.
#[unsafe(method(stopWritingTools))]
#[unsafe(method_family = none)]
pub fn stopWritingTools(&self);
#[cfg(feature = "NSTextCheckingClient")]
/// The level of Writing Tools support you want the system to provide
/// for your view.
///
/// Use this property to request an inline or panel-based experience,
/// or to disable Writing Tools for your view altogether. The default
/// value of this property is ``NSWritingToolsBehavior/default``.
#[unsafe(method(preferredBehavior))]
#[unsafe(method_family = none)]
pub fn preferredBehavior(&self) -> NSWritingToolsBehavior;
#[cfg(feature = "NSTextCheckingClient")]
/// Setter for [`preferredBehavior`][Self::preferredBehavior].
#[unsafe(method(setPreferredBehavior:))]
#[unsafe(method_family = none)]
pub fn setPreferredBehavior(&self, preferred_behavior: NSWritingToolsBehavior);
#[cfg(feature = "NSTextCheckingClient")]
/// The actual level of Writing Tools support the system provides for your view.
///
/// The system chooses this value based on the device capabilities, and takes
/// the value in the ``preferredBehavior`` property into consideration when
/// making the choice. The value in this property is never the default option,
/// and is instead one of the specific options such as ``NSWritingToolsBehavior/none``,
/// ``NSWritingToolsBehavior/limited``, or ``NSWritingToolsBehavior/complete``.
#[unsafe(method(behavior))]
#[unsafe(method_family = none)]
pub fn behavior(&self) -> NSWritingToolsBehavior;
#[cfg(feature = "NSTextCheckingClient")]
/// The type of content you allow Writing Tools to generate for your custom
/// text view.
///
/// Writing Tools can create plain text or rich text, and it can format text
/// using lists or tables as needed. If your view doesn’t support specific
/// types of content, specify the types you do support in this property.
/// The default value of this property is ``NSWritingToolsResult/default``,
/// which lets the system determine the type of content to generate.
#[unsafe(method(preferredResultOptions))]
#[unsafe(method_family = none)]
pub fn preferredResultOptions(&self) -> NSWritingToolsResultOptions;
#[cfg(feature = "NSTextCheckingClient")]
/// Setter for [`preferredResultOptions`][Self::preferredResultOptions].
#[unsafe(method(setPreferredResultOptions:))]
#[unsafe(method_family = none)]
pub fn setPreferredResultOptions(
&self,
preferred_result_options: NSWritingToolsResultOptions,
);
#[cfg(feature = "NSTextCheckingClient")]
/// The type of content the system generates for your custom text view.
///
/// This property contains the set of options that Writing Tools outputs
/// for your view. Writing Tools takes the value in the
/// ``NSWritingToolsCoordinator/preferredResultOptions`` property into
/// consideration when determining this value.
#[unsafe(method(resultOptions))]
#[unsafe(method_family = none)]
pub fn resultOptions(&self) -> NSWritingToolsResultOptions;
#[unsafe(method(includesTextListMarkers))]
#[unsafe(method_family = none)]
pub fn includesTextListMarkers(&self) -> bool;
/// Setter for [`includesTextListMarkers`][Self::includesTextListMarkers].
#[unsafe(method(setIncludesTextListMarkers:))]
#[unsafe(method_family = none)]
pub fn setIncludesTextListMarkers(&self, includes_text_list_markers: bool);
/// Informs the coordinator about changes your app made to the text
/// in the specified context object.
///
/// - Parameters:
/// - range: The range of text to replace. This range is relative to
/// the starting location of the specified context object’s text in
/// your view’s text storage. If you initialized the context object
/// with the entire contents of your view’s text storage, specify the
/// range of text you’re replacing in your text storage. However, if
/// you initialized the context object with only a portion of your
/// view’s text, specify a range that is relative to the starting
/// location of the context object’s text.
/// - replacementText: The text that replaces the previous content in
/// `range`. Specify an empty string to delete the text in the specified range.
/// - reason: The reason you updated the text.
/// - contextID: The unique identifier of the context object that
/// contains the text you modified.
///
/// If you make any changes to the text Writing Tools is evaluating, call
/// this method to report those changes to your view’s coordinator object.
/// You might make changes in response to an undo command or when someone
/// types into the same part of your view’s text. Calling this method
/// keeps the coordinator object informed of any changes, and ensures
/// it delivers accurate information to its delegate. In response, the
/// coordinator refreshes previews and other information related to your
/// view. If the scope of the update is significantly large, the coordinator
/// can optionally cancel the Writing Tools session altogether.
///
/// Use this method to report changes that precisely intersect your context
/// object’s text. The first time you call this method for a context object,
/// report changes only to the original attributed string in that object.
/// If you call this method more than once, report changes to the newly
/// modified version of that string. Don’t use this method to report changes
/// to text that comes before or after the context object. If you make
/// changes before your context object, report those changes separately using the
/// ``updateForReflowedTextInContextWithIdentifier(_:)`` method.
///
/// > Warning: Failure to call this method for a change can cause Writing Tools
/// to deliver inaccurate information to your delegate and lead to data loss.
#[unsafe(method(updateRange:withText:reason:forContextWithIdentifier:))]
#[unsafe(method_family = none)]
pub fn updateRange_withText_reason_forContextWithIdentifier(
&self,
range: NSRange,
replacement_text: &NSAttributedString,
reason: NSWritingToolsCoordinatorTextUpdateReason,
context_id: &NSUUID,
);
/// Informs the coordinator that a change occurred to the view or its text
/// that requires a layout update.
///
/// - Parameters:
/// - contextID: The unique identifier of the context object affected
/// by the change. Pass the identifier for the context object that comes
/// after the changes.
///
/// Use this method to inform Writing Tools when the geometry of your view
/// changes, or when the text that precedes one of your context objects changes.
/// Changes to the view’s geometry or text can affect the flow of any remaining
/// text, and require a layout update. Writing Tools uses this method to
/// refresh any layout-dependent information it’s currently tracking. For
/// example, it uses it to refresh the location of proofreading marks it’s
/// displaying in your view.
///
/// If a text change affects the text inside a context object, call the
/// ``updateRange(_:with:reason:forContextWithIdentifier:)`` method to report
/// that change instead.
#[unsafe(method(updateForReflowedTextInContextWithIdentifier:))]
#[unsafe(method_family = none)]
pub fn updateForReflowedTextInContextWithIdentifier(&self, context_id: &NSUUID);
);
}
/// Methods declared on superclass `NSObject`.
impl NSWritingToolsCoordinator {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub fn new(mtm: MainThreadMarker) -> Retained<Self>;
);
}
extern_protocol!(
/// An interface that you use to manage interactions between Writing Tools
/// and your custom text view.
///
/// Adopt the `NSWritingToolsCoordinator.Delegate` protocol in the type you
/// use to manage your custom text view. When you add a ``NSWritingToolsCoordinator``
/// object to your view, the coordinator uses this protocol to communicate
/// with that view. The protocol lets Writing Tools fetch your view’s text,
/// report suggested changes back to your view, and deliver visual feedback
/// when Writing Tools features are active. Make sure the type that adopts
/// this protocol has access to your view’s text storage and can perform
/// relevant tasks on behalf of the view.
///
/// Writing Tools expects you to call the provided handler blocks at the end
/// of your delegate methods. It’s crucial that you execute these blocks in a
/// timely manner to allow Writing Tools to perform subsequent tasks. For example,
/// Writing Tools waits for you to execute the handlers for animation-related methods
/// before moving on to the next stage of the animations.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatordelegate?language=objc)
pub unsafe trait NSWritingToolsCoordinatorDelegate: NSObjectProtocol {
#[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
/// Asks your delegate to provide the text to evaluate during the Writing Tools
/// operation.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object requesting information
/// from your custom view.
/// - scope: The amount of text the coordinator requested. Use this property
/// to determine if Writing Tools is evaluating all of your text or only a subset.
/// - completion: A completion block to execute with the required information.
/// You must execute this block once at end of your method's implementation.
/// The block has no return value and takes an array of
/// ``NSWritingToolsCoordinator/Context`` objects that contain the requested information.
///
/// At the start of every operation, the ``NSWritingToolsCoordinator`` object calls
/// this method to request the text to evaluate. Use this method to create one or
/// more ``NSWritingToolsCoordinator/Context`` objects with your view’s text.
/// Create only one ``NSWritingToolsCoordinator/Context`` object if your view has
/// only one text storage object. If your view contains multiple text storage objects,
/// create separate ``NSWritingToolsCoordinator/Context`` objects for each
/// text storage object. Writing Tools returns updates for each context object
/// separately, making it easier for you to incorporate changes into the correct
/// text storage object. Don’t create multiple context objects if your view has
/// only one text storage object.
///
/// The `scope` parameter tells you what content Writing Tools expects you to provide
/// in your context object. For example, Writing Tools expects you to provide the
/// selected text when the parameter contains the ``NSWritingToolsCoordinator/ContextScope/userSelection``
/// option. When Writing Tools requests a subset of your overall text, include
/// some of the surrounding text in your context object too. Writing Tools can
/// use the extra text you provide to improve the results of its evaluation. For
/// example, it might use an entire paragraph, instead of only the selected sentence,
/// to evaluate ways to rewrite that sentence. It’s best to include the text up
/// to the nearest paragraph boundary before and after the selection. If you
/// include extra text in your context object, set the ``NSWritingToolsCoordinator/Context/range``
/// property to the range of the selected text.
///
/// > Note: When a context object stores only a subset of your view’s text, record
/// additional information to map the location of that text to the correct location
/// in your view’s text storage. Keep that information up-to-date throughout the
/// Writing Tools session.
///
/// Pass the context objects you create to the provided completion handler before
/// your method returns. Writing Tools waits for you to call the completion
/// handler before proceeding with the operation.
#[unsafe(method(writingToolsCoordinator:requestsContextsForScope:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_requestsContextsForScope_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
scope: NSWritingToolsCoordinatorContextScope,
completion: &block2::DynBlock<
dyn Fn(NonNull<NSArray<NSWritingToolsCoordinatorContext>>),
>,
);
#[cfg(all(
feature = "NSWritingToolsCoordinatorAnimationParameters",
feature = "NSWritingToolsCoordinatorContext",
feature = "block2"
))]
/// Tells the delegate that there are text changes to incorporate into the view.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object providing the changes
/// to your custom view.
/// - range: A range of text to update. This range is relative to the text
/// in your context object, and it’s your responsibility to match that location
/// to the correct location in your text storage. If you initialized the
/// context object with the entire contents of your view’s text storage,
/// you can use `range` as-is to access that text storage. However, if you
/// initialized the context object with only a portion of your view’s text,
/// add the starting location of your context object’s text to this value
/// to get the correct range for that text storage.
/// - context: The context object that contains the original text to modify.
/// Use this object to locate the correct text storage object for your view.
/// - replacementText: The text to insert in place of the current text at `range`.
/// You can insert this text as-is, insert a modified version of this string,
/// or reject the replacement text altogether.
/// - reason: The type of replacement Writing Tools performs. This parameter
/// indicates whether Writing Tools is replacing the text with or without animations.
/// - animationParameters: The animation parameters for any interactive changes,
/// or `nil` if the changes aren’t interactive. Use this object to create any
/// additional animations for the system to run alongside the changes Writing Tools
/// makes. For example, use it to update other views that contain related information.
/// - completion: A completion handler to execute with the results of the operation.
/// The handler has no return value and takes an optional attributed string as
/// a parameter. If you incorporate the replacement text, either as-is or with
/// modifications, pass the actual string you incorporated to the completion
/// block. If you reject the suggested change and leave the original text
/// unchanged, specify `nil` for this parameter.
///
/// Use this method to update your view’s text storage with the proposed changes.
/// Writing Tools can call this method multiple times during the course of a
/// session to notify you of changes to different ranges of text. Incorporate
/// the changes into your view’s text storage and notify your layout manager
/// so it can refresh the view.
///
/// > Important: When integrating changes, remember to update `range.location` as needed
/// to get the correct location in your view’s text storage.
///
/// Remove the text in the appropriate range of your text storage, and replace
/// it with the contents of `replacementText`. When you finish, call the completion
/// handler and pass in the replacement text you inserted. If you change the
/// string in `replacementText` before incorporating it into your text storage,
/// return your modified string instead. Returning the string lets Writing Tools
/// track any alterations you made to it. You can also pass `nil` to the
/// completion handler if you don’t incorporate the replacement text.
///
/// For interactive changes, Writing Tools works with your delegate to animate
/// the removal of the old text and the insertion of any replacement text. If
/// you need to modify other parts of your interface to reflect the changes,
/// use the provided ``NSWritingToolsCoordinator/AnimationParameters`` object
/// to create additional animations to run at the same time as the system-provided animations.
#[unsafe(method(writingToolsCoordinator:replaceRange:inContext:proposedText:reason:animationParameters:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_replaceRange_inContext_proposedText_reason_animationParameters_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
range: NSRange,
context: &NSWritingToolsCoordinatorContext,
replacement_text: &NSAttributedString,
reason: NSWritingToolsCoordinatorTextReplacementReason,
animation_parameters: Option<&NSWritingToolsCoordinatorAnimationParameters>,
completion: &block2::DynBlock<dyn Fn(*mut NSAttributedString)>,
);
#[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
/// Asks the delegate to update your view’s current text selection.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object making the change
/// to your view.
/// - ranges: One or more ranges of text to select. Each range is relative
/// to the text in your context object, and it’s your responsibility to
/// match each location to the correct location in your text storage. If
/// you initialized the context object with the entire contents of your
/// view’s text storage, you can use the ranges as-is to access that text
/// storage. However, if you initialized the context object with only a
/// portion of your view’s text, add the starting location of your context
/// object’s text to each value to get the correct range for that text storage.
/// - context: The context object you use to identify the associated text storage.
/// - completion: The completion handler to execute when your delegate finishes updating
/// the selection. The handler has no parameters or return value. You must
/// call this handler at some point during the implementation of your method.
///
/// As Writing Tools suggests changes to your view’s text, it calls this method
/// to update the text selection accordingly. Use this method to update the
/// current selection in your view’s text storage. When you finish making the
/// changes, call the provided completion block to let Writing Tools know you’re finished.
#[unsafe(method(writingToolsCoordinator:selectRanges:inContext:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_selectRanges_inContext_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
ranges: &NSArray<NSValue>,
context: &NSWritingToolsCoordinatorContext,
completion: &block2::DynBlock<dyn Fn()>,
);
#[cfg(all(
feature = "NSBezierPath",
feature = "NSWritingToolsCoordinatorContext",
feature = "block2"
))]
/// Asks the delegate to provide the bounding paths for the specified
/// text in your view.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object requesting information
/// from your custom view.
/// - range: The range of text to evaluate. This range is relative to the
/// text in your context object, and it’s your responsibility to match that
/// location to the correct location in your text storage. If you initialized
/// the context object with the entire contents of your view’s text storage,
/// you can use `range` as-is to access that text storage. However, if you
/// initialized the context object with only a portion of your view’s text,
/// add the starting location of your context object’s text to this value to
/// get the correct range for that text storage.
/// - context: The context object with the target text. Use this object to
/// find the text in your view’s text storage.
/// - completion: A handler to execute with the required information. The
/// handler has no return value and takes an array of Bezier paths as a
/// parameter. You must call this handler at some point during your method’s implementation.
///
/// After applying proofreading marks to your view’s text, Writing Tools lets
/// the person accept or reject individual suggestions. To facilitate interactions,
/// the coordinator asks your delegate to provide one or more Bezier paths that
/// surround those proofreading suggestions. For each distinct range of text
/// with a suggestion, it calls this method to get the Bezier paths that surround
/// the corresponding text.
///
/// After you determine the location of the specified range of text in your view’s
/// text storage, find the rectangle around that text. If you're using TextKit, call the
/// <doc
/// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager/3809995-enumeratetextsegments>
/// method of your view’s
/// <doc
/// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager>
/// to compute the selection rectangles for that text. That method finds the text
/// segments that contain the text and returns the frame rectangle for each one.
/// Create a Bezier path for each rectangle, and convert the coordinates of each path
/// to the coordinate space of the view in your coordinator's ``NSWritingToolsCoordinator/decorationContainerView``
/// property. Pass the resulting paths to the completion handler.
#[unsafe(method(writingToolsCoordinator:requestsBoundingBezierPathsForRange:inContext:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_requestsBoundingBezierPathsForRange_inContext_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
range: NSRange,
context: &NSWritingToolsCoordinatorContext,
completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<NSBezierPath>>)>,
);
#[cfg(all(
feature = "NSBezierPath",
feature = "NSWritingToolsCoordinatorContext",
feature = "block2"
))]
/// Asks the delegate to provide an underline shape for the specified text
/// during a proofreading session.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object requesting information
/// from your custom view.
/// - range: The range of text to evaluate. This range is relative to the
/// text in your context object, and it’s your responsibility to match that
/// location to the correct location in your text storage. If you initialized
/// the context object with the entire contents of your view’s text storage,
/// you can use `range` as-is to access that text storage. However, if you
/// initialized the context object with only a portion of your view’s text,
/// add the starting location of your context object’s text to this value
/// to get the correct range for that text storage.
/// - context: The context object with the target text. Use this object to
/// find the text in your view’s text storage.
/// - completion: A handler to execute with the required information. The
/// handler has no return value and takes an array of Bezier paths as a
/// parameter. You must call this handler at some point during your method’s implementation.
///
/// When applying proofreading marks to your view’s content, the coordinator
/// calls this method to retrieve a shape to draw under the specified text.
/// You provide the shape using one or more Bezier paths, and the coordinator
/// draws and animates that shape during the proofreading session.
///
/// After you determine the location of the specified range of text in your
/// view’s text storage, find the rectangle around that text. If you're using
/// TextKit, you can call the
/// <doc
/// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager/3809995-enumeratetextsegments>
/// method of your view’s
/// <doc
/// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager>
/// to get the rectangles for a range of text. Convert the coordinates of each rectangle
/// to the coordinate space of the view in your coordinator's ``NSWritingToolsCoordinator/decorationContainerView``
/// property. Use those rectangles to create the Bezier paths for your text.
/// For example, you might create a path with a straight or wavy line at the
/// bottom of the rectangle.
#[unsafe(method(writingToolsCoordinator:requestsUnderlinePathsForRange:inContext:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_requestsUnderlinePathsForRange_inContext_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
range: NSRange,
context: &NSWritingToolsCoordinatorContext,
completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<NSBezierPath>>)>,
);
#[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
/// Prepare for animations for the content that Writing Tools is evaluating.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object notifying you that
/// animations are about to begin.
/// - textAnimation: The type of animation Writing Tools is preparing.
/// - range: The range of text affected by the animation. This range is
/// relative to the text in your context object, and it’s your responsibility
/// to match that location to the correct location in your text storage.
/// If you initialized the context object with the entire contents of your
/// view’s text storage, you can use `range` as-is to access that text
/// storage. However, if you initialized the context object with only a portion
/// of your view’s text, add the starting location of your context object’s
/// text to this value to get the correct range for that text storage.
/// - context: The context object that contains the original text. Use this
/// object to fetch the current text, and to match that text to your underlying
/// text storage.
/// - completion: A completion handler to execute when you are done. The handler
/// has no return value and takes no parameters. You must call this handler
/// at some point during your implementation.
///
/// During an interactive evaluation of your view’s text, Writing Tools creates
/// different animations to provide feedback on what’s happening. For example, it
/// creates an ``NSWritingToolsCoordinator/TextAnimation/anticipate`` animation to
/// let people know the system is evaluating the text. The `textAnimation` parameter
/// tells you what type of animation to prepare for.
///
/// Use this method to prepare for the system-provided animations of your view’s
/// content. For interactive animations, hide the text in the specified range temporarily
/// while the system animations run. For non-interactive animations, dim the text
/// for the duration of the animation to indicate it’s not editable. For animations
/// to remove or insert text, you can also use this method to set up animations
/// to reflow your view’s content to match the changes. At the end of a given animation,
/// use your delegate’s ``writingToolsCoordinator(_:finish:for:in:completion:)``
/// method to undo any changes you make to your content.
///
/// For a single animation type, the system calls this method, followed sequentially
/// by the ``writingToolsCoordinator(_:previewFor:range:context:completion:)``
/// and ``writingToolsCoordinator(_:finish:for:in:completion:)``
/// methods. Each method executes asynchronously, but the system calls the next
/// method in the sequence only after you call the completion handler of the previous
/// method. However, multiple animations can run simultaneously, so check the
/// `textAnimation` and `range` parameters to differentiate sequences.
#[unsafe(method(writingToolsCoordinator:prepareForTextAnimation:forRange:inContext:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_prepareForTextAnimation_forRange_inContext_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
text_animation: NSWritingToolsCoordinatorTextAnimation,
range: NSRange,
context: &NSWritingToolsCoordinatorContext,
completion: &block2::DynBlock<dyn Fn()>,
);
#[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
/// Asks the delegate for a preview image and layout information for the
/// specified text.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object notifying you that
/// animations are about to begin.
/// - textAnimation: The type of animation Writing Tools is preparing.
/// - range: The range of text that requires a preview image. This range
/// is relative to the text in your context object, and it’s your responsibility
/// to match that location to the correct location in your text storage.
/// If you initialized the context object with the entire contents of
/// your view’s text storage, you can use `range` as-is to access that
/// text storage. However, if you initialized the context object with only
/// a portion of your view’s text, add the starting location of your
/// context object’s text to this value to get the correct range for that
/// text storage.
/// - context: The context object that contains the original text. Use this
/// object to fetch the current text, and to match that text to your
/// underlying text storage.
/// - completion: A completion handler to execute when you are done. The
/// handler has no return value and takes an ``NSTextPreview`` object
/// as a parameter. You must call this handler at some point during your implementation.
///
/// During an interactive evaluation of your view’s text, Writing Tools creates
/// different animations to provide feedback on what’s happening. As part of
/// the preparation for those animations, Writing Tools asks you to provide
/// a preview of the affected content in your view. Writing Tools uses this
/// preview to build and execute the animations in the view stored in the
/// ``NSWritingToolsCoordinator/effectContainerView`` property of the coordinator object.
///
/// To build a preview of your content in macOS, render the specified range of text
/// into an image with a transparent background and use that image to create your
/// ``NSTextPreview`` object directly. Set the ``NSTextPreview/presentationFrame``
/// property to the rectangle in your view’s coordinate space that contains the
/// text you captured. Set the ``NSTextPreview/candidateRects`` property to the
/// selection rectangles for the text, which you get from your view’s layout manager.
/// Writing Tools uses this information to place your image directly above the text in your view.
///
/// For a single animation type, the system calls the
/// ``writingToolsCoordinator(_:prepareFor:range:context:completion:)``
/// method, followed sequentially by this method and then the
/// ``writingToolsCoordinator(_:finish:for:in:completion:)``
/// method. Each method executes asynchronously, but the system calls the next
/// method in the sequence only after you call the completion handler of the
/// previous method. However, multiple animations can run simultaneously, so
/// check the `textAnimation` parameter to differentiate sequences.
#[unsafe(method(writingToolsCoordinator:requestsPreviewForTextAnimation:ofRange:inContext:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_requestsPreviewForTextAnimation_ofRange_inContext_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
text_animation: NSWritingToolsCoordinatorTextAnimation,
range: NSRange,
context: &NSWritingToolsCoordinatorContext,
completion: &block2::DynBlock<dyn Fn(*mut NSArray<NSTextPreview>)>,
);
#[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
/// Asks the delegate for a preview image and layout information for the
/// specified text.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object notifying you that
/// animations are about to begin.
/// - rect: The portion of your view that contains the requested text. This rectangle is in the view’s coordinate system.
/// - context: The context object that contains the original text. Use this
/// object to fetch the current text, and to match that text to your
/// underlying text storage.
/// - completion: A completion handler to execute when you are done. The
/// handler has no return value and takes an ``NSTextPreview`` object
/// as a parameter. You must call this handler at some point during your implementation.
///
/// During an interactive evaluation of your view’s text, Writing Tools creates
/// different animations to provide feedback on what’s happening. As part of
/// the preparation for those animations, Writing Tools asks you to provide
/// a preview of the affected content in your view. Writing Tools uses this
/// preview to build and execute the animations in the view stored in the
/// ``NSWritingToolsCoordinator/effectContainerView`` property of the coordinator object.
///
/// To build a preview of your content in macOS, render the requested portion
/// of your view into an image with a transparent background and use that image
/// to create your ``NSTextPreview`` object directly. Set the ``NSTextPreview/presentationFrame``
/// property to the specified rectangle. Set the ``NSTextPreview/candidateRects``
/// property to the selection rectangles for the associated text, which you get
/// from your view’s layout manager. Writing Tools uses this information to
/// place your image directly above the text in your view.
///
/// For a single animation type, the system calls the
/// ``writingToolsCoordinator(_:prepareFor:range:context:completion:)``
/// method, followed sequentially by this method and then the
/// ``writingToolsCoordinator(_:finish:for:in:completion:)``
/// method. Each method executes asynchronously, but the system calls the next
/// method in the sequence only after you call the completion handler of the
/// previous method. However, multiple animations can run simultaneously, so
/// check the `textAnimation` parameter to differentiate sequences.
#[unsafe(method(writingToolsCoordinator:requestsPreviewForRect:inContext:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_requestsPreviewForRect_inContext_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
rect: NSRect,
context: &NSWritingToolsCoordinatorContext,
completion: &block2::DynBlock<dyn Fn(*mut NSTextPreview)>,
);
#[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
/// Asks the delegate to clean up any state related to the specified
/// Writing Tools animation.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object notifying you
/// that animations are about to begin.
/// - textAnimation: The type of animation Writing Tools finished.
/// - range: The range of text that finished animating. This range is
/// relative to the text in your context object, and it’s your responsibility
/// to match that location to the correct location in your text storage.
/// If you initialized the context object with the entire contents of
/// your view’s text storage, you can use `range` as-is to access that
/// text storage. However, if you initialized the context object with
/// only a portion of your view’s text, add the starting location of
/// your context object’s text to this value to get the correct range
/// for that text storage.
/// - context: The context object that contains the original text.
/// - completion: A completion handler to execute when you are done.
/// The handler has no return value and takes no parameters. You must
/// call this handler at some point during your implementation.
///
/// Use this method to clean up any data structures you created to support
/// the specified type of Writing Tools animation. You can also use this
/// method to restore the visibility of any text you hid previously. When
/// you finish your cleanup work, call the completion handler to notify Writing Tools.
///
/// Writing Tools calls this method only after previous calls to the
/// ``writingToolsCoordinator(_:prepareFor:range:context:completion:)``
/// and ``writingToolsCoordinator(_:previewFor:range:context:completion:)``
/// methods for the same animation type. However, Writing Tools can interleave
/// calls to this method with calls to prepare an animation of a different
/// type. In your implementation of this method, make sure the actions you
/// take don’t interfere with other in-flight animations.
#[unsafe(method(writingToolsCoordinator:finishTextAnimation:forRange:inContext:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_finishTextAnimation_forRange_inContext_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
text_animation: NSWritingToolsCoordinatorTextAnimation,
range: NSRange,
context: &NSWritingToolsCoordinatorContext,
completion: &block2::DynBlock<dyn Fn()>,
);
#[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
/// Asks the delegate to divide the specified range of text into the separate
/// containers that render that text.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object requesting information
/// from your custom view.
/// - range: The range of text to consider in the specified `context` object.
/// The location value of this range is relative to the beginning of the text
/// in your context object, and it’s your responsibility to match that location
/// to the correct location in your text storage. If you initialized the
/// context object with the entire contents of your view’s text storage,
/// you can use `range` as-is to access that text storage. However, if you
/// initialized the context object with only a portion of your view’s text,
/// add the starting location of your context object’s text to this value
/// to get the correct range for that text storage.
/// - context: The context object that contains the text to consider. Use this
/// object to locate the appropriate text storage object for your view.
/// - completion: A completion handler to execute when you are done. The handler
/// has no return value and takes an array of
/// <doc
/// ://com.apple.documentation/documentation/foundation/nsvalue>
/// types, each of which contains an
/// <doc
/// ://com.apple.documentation/documentation/foundation/nsrange>.
/// The union of the ranges you pass to this handler must equal all of the
/// text in `range`. The order of the ranges in the array must be sequential,
/// with each new range's starting location coming after the previous one.
/// There must also not be any gaps or overlap between ranges.
/// You must call this handler at some point during your implementation.
///
/// If your view uses multiple ``NSTextContainer`` objects to draw text in different
/// regions, use this method to tell Writing Tools about the containers that display
/// the specified text. In your implementation, subdivide `range` to create one new
/// range for each portion of text that resides in a different container object.
/// For example, if the text in `range` is split between two containers, provide
/// two new
/// <doc
/// ://com.apple.documentation/documentation/foundation/nsrange> types
/// that reflect the portion of the total text in each container. If `range` resides completely
/// within one container, call the completion handler with `range` as the only value
/// in the array.
///
/// When configuring animations for your view, Writing Tools asks your delegate to
/// provide separate previews for each of your view’s container object. Specifically,
/// it calls your delegate’s ``writingToolsCoordinator(_:previewFor:range:context:completion:)``
/// method separately for each range of text you return in the completion handler.
/// Your implementation of that method must create a preview suitable for animating
/// the content from the underlying text container.
#[optional]
#[unsafe(method(writingToolsCoordinator:requestsSingleContainerSubrangesOfRange:inContext:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_requestsSingleContainerSubrangesOfRange_inContext_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
range: NSRange,
context: &NSWritingToolsCoordinatorContext,
completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<NSValue>>)>,
);
#[cfg(all(
feature = "NSResponder",
feature = "NSView",
feature = "NSWritingToolsCoordinatorContext",
feature = "block2"
))]
/// Asks the delegate to provide a decoration view for the specified range of text.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object requesting information
/// from your custom view.
/// - range: The range of text to consider in the specified `context` object.
/// The location value of this range is relative to the beginning of the text
/// in your context object, and it’s your responsibility to match that location
/// to the correct location in your text storage. If you initialized the
/// context object with the entire contents of your view’s text storage, you
/// can use `range` as-is to access that text storage. However, if you initialized
/// the context object with only a portion of your view’s text, add the starting
/// location of your context object’s text to this value to get the correct
/// range for that text storage.
/// - context: The context object that contains the text to consider. Use this
/// object to locate the appropriate text storage object for your view.
/// - completion: A completion handler to execute when you are done. The handler
/// has no return value and takes an ``NSView`` object as a parameter. You must call
/// this handler at some point during your implementation.
///
/// If your view uses multiple ``NSTextContainer`` objects to draw text in different
/// regions, use this method to provide Writing Tools with the view to use for the
/// specified range of text. After calling your delegate’s ``writingToolsCoordinator(_:singleContainerSubrangesOf:in:)``
/// method, Writing Tools calls this method for each subrange of text you provided.
/// Find or provide a view situated visibly below the specified text in your text
/// view. It's also satisfactory to provide a view that’s visually in front of the
/// text. Writing Tools uses the provided view to host any proofreading marks for
/// the specified range of text.
///
/// If your view has only one text container, use the coordinator’s ``NSWritingToolsCoordinator/decorationContainerView``
/// property to specify the view to use for proofreading marks.
#[optional]
#[unsafe(method(writingToolsCoordinator:requestsDecorationContainerViewForRange:inContext:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_requestsDecorationContainerViewForRange_inContext_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
range: NSRange,
context: &NSWritingToolsCoordinatorContext,
completion: &block2::DynBlock<dyn Fn(NonNull<NSView>)>,
);
#[cfg(feature = "block2")]
/// Notifies your delegate of relevant state changes when Writing Tools
/// is running in your view.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object providing
/// information to your custom view.
/// - state: The new state for the Writing Tools session. For information
/// about the possible states, see ``NSWritingToolsCoordinator/State``.
/// - text: The current text for your context object.
/// - reason: The reason for the state change.
/// - context: The context object that contains the original text for
/// Writing Tools to evaluate.
/// - completion: A handler to execute when your delegate finishes processing
/// the change of state. The handler has no parameters or return value. You
/// must call this handler at some point during the implementation of your method.
///
/// Use state transitions to perform actions related to your view or text storage.
/// When Writing Tools is active, it updates its state to indicate what task
/// it’s currently performing. Writing Tools starts in the ``NSWritingToolsCoordinator/State/inactive``
/// state and moves to other states as it presents UI and starts interacting with
/// your view’s content. For example, it moves to the ``NSWritingToolsCoordinator/State/interactiveUpdating``
/// state when it’s making changes to your view’s text storage.
#[optional]
#[unsafe(method(writingToolsCoordinator:willChangeToState:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_willChangeToState_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
new_state: NSWritingToolsCoordinatorState,
completion: &block2::DynBlock<dyn Fn()>,
);
#[cfg(feature = "block2")]
/// Asks the delegate to provide the location of the character at the
/// specified point in your view’s coordinate system.
///
/// - Parameters:
/// - writingToolsCoordinator: The coordinator object requesting
/// information from your custom view.
/// - point: A point in your view’s coordinate space. Find the
/// location of the text under this point, if any.
/// - completion: A handler to execute with the required information.
/// This handler has no return value and takes an
/// <doc
/// ://com.apple.documentation/documentation/foundation/nsrange>
/// and
/// <doc
/// ://com.apple.documentation/documentation/foundation/uuid>
/// as parameters. Set the range to the character’s location in one of your
/// ``NSWritingToolsCoordinator/Context`` objects, which you specify using
/// the
/// <doc
/// ://com.apple.documentation/documentation/foundation/uuid> parameter.
/// You must call this handler at some point during your method’s implementation.
///
/// When someone interacts with your view during a proofreading operation, Writing Tools
/// calls this method to get the location of the interaction. If the interaction
/// occurs in the text of one of your ``NSWritingToolsCoordinator/Context`` objects,
/// configure an
/// <doc
/// ://com.apple.documentation/documentation/foundation/nsrange>
/// with the character’s location in that context object and a length of `1`. If
/// the interaction occurs outside of the text of your context objects, configure
/// the range with a location of `NSNotFound`.
///
/// When specifying the location of a character in your context object, provide a
/// location relative to the start of your context object’s text. The first character
/// in a context object’s text is always at location `0`, and it’s your responsibility
/// to track the location of the context object’s text in your text storage object.
/// When the context object’s text begins in the middle of your text storage,
/// subtract the starting location of the context object’s text from the location
/// you specify in your range value. For example, if the context object’s text
/// starts at character `100` in your text storage, and an interaction occurs
/// with the character at location `102`, specify a range with a location of
/// `2` and a length of `1`.
#[deprecated = "In macOS 15.4 and later, NSWritingToolsCoordinator automatically determines the location of the character at the specified point in your view's coordinate system and no longer calls this method."]
#[optional]
#[unsafe(method(writingToolsCoordinator:requestsRangeInContextWithIdentifierForPoint:completion:))]
#[unsafe(method_family = none)]
fn writingToolsCoordinator_requestsRangeInContextWithIdentifierForPoint_completion(
&self,
writing_tools_coordinator: &NSWritingToolsCoordinator,
point: NSPoint,
completion: &block2::DynBlock<dyn Fn(NSRange, NonNull<NSUUID>)>,
);
}
);
extern_class!(
/// A snapshot of the text in your view, which the system uses to create
/// user-visible effects.
///
/// An `NSTextPreview` object provides a static image of your view’s text
/// content that the system can use to create animations. You provide preview
/// objects in response to system requests, such as ones from Writing Tools.
/// In addition to creating an image of your view’s text, you also specify
/// the location of that text in your view’s frame rectangle. When creating
/// animations, the system places the image on top of your view’s content
/// and animates changes to the image instead of to your view.
///
/// Create an `NSTextPreview` object in response to specific system requests.
/// Create an image with a transparent background and render your view’s text
/// into the image using the current text attributes. Construct your `NSTextPreview`
/// object with both the image and the frame rectangle that represents the
/// location of the rendered text in your view’s coordinate system. To highlight
/// specific portions of text, instead of all the text in the image, provide
/// a set of candidate rectangles with the locations of the text you want to highlight.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextpreview?language=objc)
#[unsafe(super(NSObject))]
#[thread_kind = MainThreadOnly]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct NSTextPreview;
);
extern_conformance!(
unsafe impl NSObjectProtocol for NSTextPreview {}
);
impl NSTextPreview {
extern_methods!(
#[cfg(feature = "objc2-core-graphics")]
#[cfg(target_vendor = "apple")]
/// Creates a text preview using the specified image and rectangles that indicate
/// the portions of text to highlight.
///
/// - Parameters:
/// - snapshotImage: An image that contains the requested text from your view.
/// Create the image using a transparent background and the current rendering
/// attributes for your text.
/// - presentationFrame: A rectangle in the coordinate space of your text view.
/// The system uses this rectangle to place your image precisely over your
/// view’s actual text. Set its size to the size of your snapshot image, and
/// set its origin to the point that allows the system to place your image
/// directly over the text.
/// - candidateRects: An array of
/// <doc
/// ://com.apple.documentation/documentation/foundation/nsvalue>
/// objects, each of which contains an
/// <doc
/// ://com.apple.documentation/documentation/foundation/nsrect>
/// in the coordinate space of your text view. Each rectangle contains a
/// bounding rectangle for text that is part of the preview. When applying
/// visual effects, the system adds highlights only to the text in the specified rectangles.
#[unsafe(method(initWithSnapshotImage:presentationFrame:candidateRects:))]
#[unsafe(method_family = init)]
pub fn initWithSnapshotImage_presentationFrame_candidateRects(
this: Allocated<Self>,
snapshot_image: &CGImage,
presentation_frame: NSRect,
candidate_rects: &NSArray<NSValue>,
) -> Retained<Self>;
#[cfg(feature = "objc2-core-graphics")]
#[cfg(target_vendor = "apple")]
/// Creates a text preview using the specified image.
///
/// - Parameters:
/// - snapshotImage: An image that contains the requested text from your view.
/// Create the image using a transparent background and the current rendering
/// attributes for your text.
/// - presentationFrame: A rectangle in your frame’s coordinate space. The
/// system uses this rectangle to place your image precisely over your view’s
/// actual text. Set its size to the size of your snapshot image, and set its
/// origin to the point that allows the system to place your image directly over the text.
#[unsafe(method(initWithSnapshotImage:presentationFrame:))]
#[unsafe(method_family = init)]
pub fn initWithSnapshotImage_presentationFrame(
this: Allocated<Self>,
snapshot_image: &CGImage,
presentation_frame: NSRect,
) -> Retained<Self>;
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
#[cfg(feature = "objc2-core-graphics")]
#[cfg(target_vendor = "apple")]
/// The image that contains the requested text from your view.
///
/// You specify this image at initialization time. The system uses it to
/// implement any visual effects involving your view’s text. Create the image
/// with your text on a transparent background.
#[unsafe(method(previewImage))]
#[unsafe(method_family = none)]
pub fn previewImage(&self) -> Retained<CGImage>;
/// The frame rectangle that places the preview image directly over the
/// matching text.
///
/// You specify this value at initialization time. The system uses it to
/// position the preview image over the text in your view. Make sure the
/// frame rectangle is in your view's coordinate space.
#[unsafe(method(presentationFrame))]
#[unsafe(method_family = none)]
pub fn presentationFrame(&self) -> NSRect;
/// Rectangles that define the specific portions of text to highlight.
///
/// At initialization time, you set this property to an array of
/// <doc
/// ://com.apple.documentation/documentation/foundation/nsvalue> objects,
/// each of which contains an
/// <doc
/// ://com.apple.documentation/documentation/foundation/nsrect>
/// in the coordinate space of the target view. Each rectangle contains a bounding
/// rectangle for text that is part of the preview. When applying visual effects,
/// the system adds highlights only to the text in the specified rectangles.
#[unsafe(method(candidateRects))]
#[unsafe(method_family = none)]
pub fn candidateRects(&self) -> Retained<NSArray<NSValue>>;
);
}
/// Methods declared on superclass `NSObject`.
impl NSTextPreview {
extern_methods!(
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
);
}