objc2_app_kit/generated/
NSWritingToolsCoordinator.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-graphics")]
7#[cfg(target_vendor = "apple")]
8use objc2_core_graphics::*;
9use objc2_foundation::*;
10
11use crate::*;
12
13/// Constants that specify the reason you updated your view’s content
14/// outside of the Writing Tools workflow.
15///
16/// If you modify your view’s text storage while Writing Tools is active,
17/// report those changes to your ``NSWritingToolsCoordinator`` object
18/// so it can track them correctly. Call the
19/// ``NSWritingToolsCoordinator/updateRange(_:with:reason:forContextWithIdentifier:)``
20/// method to report changes that occur inside one of your context objects. Call the
21/// ``NSWritingToolsCoordinator/updateForReflowedTextInContextWithIdentifier(_:)``
22/// method for changes that affect the layout of your text, such as text insertions
23/// before a context object or changes to your view’s frame rectangle.
24///
25/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatortextupdatereason?language=objc)
26// NS_ENUM
27#[repr(transparent)]
28#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
29pub struct NSWritingToolsCoordinatorTextUpdateReason(pub NSInteger);
30impl NSWritingToolsCoordinatorTextUpdateReason {
31    /// An operation that involved a person editing the text in your view.
32    ///
33    /// Specify this option when the changes come from the text input system.
34    #[doc(alias = "NSWritingToolsCoordinatorTextUpdateReasonTyping")]
35    pub const Typing: Self = Self(0);
36    /// An operation that changed the view’s text as part of an undo or
37    /// redo command.
38    ///
39    /// Specify this option when an undo or redo command initiated the
40    /// change to your view.
41    #[doc(alias = "NSWritingToolsCoordinatorTextUpdateReasonUndoRedo")]
42    pub const UndoRedo: Self = Self(1);
43}
44
45unsafe impl Encode for NSWritingToolsCoordinatorTextUpdateReason {
46    const ENCODING: Encoding = NSInteger::ENCODING;
47}
48
49unsafe impl RefEncode for NSWritingToolsCoordinatorTextUpdateReason {
50    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
51}
52
53/// The states that indicate the current activity, if any, Writing Tools
54/// is performing in your view.
55///
56/// Making changes to your view requires several different levels of
57/// interaction. Initially, Writing Tools displays its UI and collects
58/// information about what the person wants to do. When the person selects
59/// an operation, Writing Tools sends the relevant details to a large language
60/// model (LLM) and processes the results. It then works with the custom view to
61/// integrate any changes into the view’s text storage. During each
62/// of these activities, the coordinator reflects what’s happening in
63/// its ``NSWritingToolsCoordinator/state`` property. You can use
64/// the current state as a guide to making decisions in other parts of your view.
65///
66/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatorstate?language=objc)
67// NS_ENUM
68#[repr(transparent)]
69#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
70pub struct NSWritingToolsCoordinatorState(pub NSInteger);
71impl NSWritingToolsCoordinatorState {
72    /// A state that indicates Writing Tools isn’t currently performing
73    /// any work on your view’s content.
74    ///
75    /// The coordinator starts in the `inactive` state, and transitions
76    /// immediately to the ``noninteractive`` or ``interactiveResting``
77    /// state when someone chooses an option from the Writing Tools UI.
78    /// After the coordinator finishes incorporating any changes for the
79    /// current operation, it returns to the `inactive` state and waits
80    /// for the person to choose a different option or dismiss the Writing Tools UI.
81    #[doc(alias = "NSWritingToolsCoordinatorStateInactive")]
82    pub const Inactive: Self = Self(0);
83    /// A state that indicates Writing Tools is handling interactions in
84    /// the system UI, instead of in your view.
85    ///
86    /// Writing Tools transitions to this state when the coordinator uses
87    /// the ``NSWritingToolsBehavior/limited`` experience or when someone chooses an
88    /// option that displays its results in the Writing Tools UI. When
89    /// the person accepts the changes from the tool or dismisses the
90    /// Writing Tools UI, the coordinator returns to the ``inactive``
91    /// state. If the person discards the change and selects a tool with
92    /// an interactive experience instead, the coordinator transitions
93    /// to the ``interactiveResting`` state.
94    #[doc(alias = "NSWritingToolsCoordinatorStateNoninteractive")]
95    pub const Noninteractive: Self = Self(1);
96    /// A state that indicates Writing Tools is in the resting state
97    /// for an inline editing experience.
98    ///
99    /// When someone initially selects a tool with an interactive experience,
100    /// the coordinator transitions briefly to this state and starts the
101    /// operation. The coordinator transitions swiftly to the ``interactiveStreaming``
102    /// state when it submits the request and delivers the results to your
103    /// view. When it finishes delivering the results, it transitions back
104    /// to the `interactiveResting` state and awaits further commands. If
105    /// the person accepts the changes or dismisses the Writing Tools UI,
106    /// the coordinator transitions from this state to the ``inactive`` state.
107    #[doc(alias = "NSWritingToolsCoordinatorStateInteractiveResting")]
108    pub const InteractiveResting: Self = Self(2);
109    /// A state that indicates Writing Tools is processing a request and
110    /// incorporating changes interactively into your view.
111    ///
112    /// The coordinator transitions swiftly from the ``interactiveResting``
113    /// state to this state at the start of an operation. In this state,
114    /// the coordinator submits the request for processing and delivers
115    /// the results back to your view. When the coordinator finishes delivering
116    /// the results, it transitions back to the ``interactiveResting`` state.
117    #[doc(alias = "NSWritingToolsCoordinatorStateInteractiveStreaming")]
118    pub const InteractiveStreaming: Self = Self(3);
119}
120
121unsafe impl Encode for NSWritingToolsCoordinatorState {
122    const ENCODING: Encoding = NSInteger::ENCODING;
123}
124
125unsafe impl RefEncode for NSWritingToolsCoordinatorState {
126    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
127}
128
129/// Options that indicate whether Writing Tools is animating changes to
130/// your view’s text.
131///
132/// During an operation, Writing Tools delivers replacement text to the
133/// delegate of the active ``NSWritingToolsCoordinator`` object. Depending
134/// on the configured experience for your view, it delivers these changes
135/// as either interactive or noninteractive replacements. For interactive
136/// replacements, Writing Tools animates the change automatically and provides
137/// you with the information you need to perform any related animations.
138///
139/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatortextreplacementreason?language=objc)
140// NS_ENUM
141#[repr(transparent)]
142#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
143pub struct NSWritingToolsCoordinatorTextReplacementReason(pub NSInteger);
144impl NSWritingToolsCoordinatorTextReplacementReason {
145    /// An option to animate the replacement of text in your view.
146    ///
147    /// When Writing Tools requests an interactive change in your delegate’s
148    /// ``NSWritingToolsCoordinator/writingToolsCoordinator(_:replaceRange:inContext:proposedText:reason:animationParameters:completion:)``
149    /// method, it passes a valid set of animation parameters to that method.
150    /// Update your view’s text storage and use the provided ``NSWritingToolsCoordinator/AnimationParameters``
151    /// type to create any view-specific animations you need to support the
152    /// animated replacement of the text.
153    #[doc(alias = "NSWritingToolsCoordinatorTextReplacementReasonInteractive")]
154    pub const Interactive: Self = Self(0);
155    /// An option to replace the text in your view without animating the change.
156    ///
157    /// When Writing Tools requests a noninteractive change in your delegate’s
158    /// ``NSWritingToolsCoordinator/writingToolsCoordinator(_:replaceRange:inContext:proposedText:reason:animationParameters:completion:)``
159    /// method, update your view’s text storage without animating the change.
160    #[doc(alias = "NSWritingToolsCoordinatorTextReplacementReasonNoninteractive")]
161    pub const Noninteractive: Self = Self(1);
162}
163
164unsafe impl Encode for NSWritingToolsCoordinatorTextReplacementReason {
165    const ENCODING: Encoding = NSInteger::ENCODING;
166}
167
168unsafe impl RefEncode for NSWritingToolsCoordinatorTextReplacementReason {
169    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
170}
171
172/// Options that indicate how much of your content Writing Tools requested.
173///
174/// At the start of any Writing Tools interaction, you provide the text for
175/// the system to evaluate from your ``NS/UIWritingToolsCoordinator/Delegate``
176/// object. The request for your content comes with a scope constant that
177/// indicates how much of your view’s text to provide.
178///
179/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatorcontextscope?language=objc)
180// NS_ENUM
181#[repr(transparent)]
182#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
183pub struct NSWritingToolsCoordinatorContextScope(pub NSInteger);
184impl NSWritingToolsCoordinatorContextScope {
185    /// An option to provide only the view’s currently selected text.
186    ///
187    /// With this option, include the selected text in your context object,
188    /// along with some additional text before and after the selection. When
189    /// performing changes inline with your view’s content, Writing Tools
190    /// applies animations only to the selected text.
191    #[doc(alias = "NSWritingToolsCoordinatorContextScopeUserSelection")]
192    pub const UserSelection: Self = Self(0);
193    /// An option to provide all of your view’s text.
194    ///
195    /// With this option, include all of the text your view manages. If your
196    /// view has multiple text storage objects, create a separate context object
197    /// for each one.
198    #[doc(alias = "NSWritingToolsCoordinatorContextScopeFullDocument")]
199    pub const FullDocument: Self = Self(1);
200    /// An option to provide only the text in the currently visible portion
201    /// of your view.
202    ///
203    /// With this option, include only the currently visible text, along with
204    /// some additional text before and after the visible text.
205    #[doc(alias = "NSWritingToolsCoordinatorContextScopeVisibleArea")]
206    pub const VisibleArea: Self = Self(2);
207}
208
209unsafe impl Encode for NSWritingToolsCoordinatorContextScope {
210    const ENCODING: Encoding = NSInteger::ENCODING;
211}
212
213unsafe impl RefEncode for NSWritingToolsCoordinatorContextScope {
214    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
215}
216
217/// Use the `NSWritingToolsCoordinator.TextAnimation` constants to determine
218/// the type of animation that is occurring. During an interactive change to
219/// your view, Writing Tools creates animations to provide feedback about what’s
220/// happening. During the setup for each animation, Writing Tools reports the
221/// type of animation to the coordinator’s delegate, so that you can perform
222/// additional actions related to that animation. For example, during an insertion
223/// animation, you might animate changes to other views in your interface.
224///
225/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatortextanimation?language=objc)
226// NS_ENUM
227#[repr(transparent)]
228#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
229pub struct NSWritingToolsCoordinatorTextAnimation(pub NSInteger);
230impl NSWritingToolsCoordinatorTextAnimation {
231    /// The animation that Writing Tools performs when waiting to receive
232    /// results from the large language model.
233    ///
234    /// This type of animation applies a visual effect to the text that
235    /// Writing Tools is evaluating. When preparing for this animation, hide
236    /// the text that Writing Tools is about to evaluate. In the same space
237    /// where that text appears, Writing Tools displays a preview image that
238    /// you provide and animates changes to that image.
239    #[doc(alias = "NSWritingToolsCoordinatorTextAnimationAnticipate")]
240    pub const Anticipate: Self = Self(0);
241    /// The animation that Writing Tools performs when removing text from your view.
242    ///
243    /// This type of animation shows the removal of text from your view. When
244    /// preparing for this animation, hide the text in the provided range if
245    /// you haven’t already. If you support animating the reflow of your view’s
246    /// text, you can also prepare any other animations you need. Writing Tools
247    /// uses a preview object you provide to animate the removal of the text.
248    #[doc(alias = "NSWritingToolsCoordinatorTextAnimationRemove")]
249    pub const Remove: Self = Self(1);
250    /// The animation that Writing Tools performs when inserting text into your view.
251    ///
252    /// This type of animation shows the insertion of text to your view. When preparing
253    /// for this animation, hide the text in the provided range if you haven’t
254    /// already. If you support animating the reflow of your view’s text, you can
255    /// also prepare any other animations you need. Writing Tools uses a preview
256    /// object you provide to animate the insertion of the text.
257    #[doc(alias = "NSWritingToolsCoordinatorTextAnimationInsert")]
258    pub const Insert: Self = Self(2);
259    /// The animation effect that Writing Tools performs when the view is waiting
260    /// for results, but the system isn’t actively evaluating the text.
261    ///
262    /// When Writing Tools isn’t actively evaluating your text, it creates this animation.
263    /// When preparing for this animation, display the text in the specified range
264    /// with a foreground color of 50% grey.
265    #[doc(alias = "NSWritingToolsCoordinatorTextAnimationAnticipateInactive")]
266    pub const AnticipateInactive: Self = Self(8);
267    /// The animation effect that Writing Tools performs on text situated after
268    /// the insertion point.
269    ///
270    /// When Writing Tools inserts text at a given location, it creates an animation
271    /// to make room for the new text. When preparing for this animation, hide the
272    /// text between the insertion point and the end of your text storage. When
273    /// finishing the animation, show the text again.
274    #[doc(alias = "NSWritingToolsCoordinatorTextAnimationTranslate")]
275    pub const Translate: Self = Self(9);
276}
277
278unsafe impl Encode for NSWritingToolsCoordinatorTextAnimation {
279    const ENCODING: Encoding = NSInteger::ENCODING;
280}
281
282unsafe impl RefEncode for NSWritingToolsCoordinatorTextAnimation {
283    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
284}
285
286extern_class!(
287    /// An object that manages interactions between Writing Tools and
288    /// your custom text view.
289    ///
290    /// Add a `NSWritingToolsCoordinator` object to a custom view when you
291    /// want to add Writing Tools support to that view. The coordinator manages
292    /// interactions between your view and the Writing Tools UI and back-end
293    /// capabilities. When creating a coordinator, you supply a delegate object
294    /// to respond to requests from the system and provide needed information.
295    /// Your delegate delivers your view’s text to Writing Tools, incorporates
296    /// suggested changes back into your text storage, and supports the animations
297    /// that Writing Tools creates to show the state of an operation.
298    ///
299    /// Create the `NSWritingToolsCoordinator` object when setting up your UI, and
300    /// initialize it with a custom object that adopts the ``NSWritingToolsCoordinator/Delegate``
301    /// protocol. Add the coordinator to the ``NSView/writingToolsCoordinator`` property
302    /// of your view. When a coordinator is present on a view, the system adds UI elements
303    /// to initiate Writing Tools operations.
304    ///
305    /// When defining the delegate, choose an object from your app that has access
306    /// to your view and its text storage. You can adopt the ``NSWritingToolsCoordinator/Delegate``
307    /// protocol in the view itself, or in another type that your view uses to
308    /// manage content. During the interactions with Writing Tools, the delegate
309    /// gets and sets the contents of the view’s text storage and supports Writing Tools behaviors.
310    ///
311    /// > Note: You don’t need to create an `NSWritingToolsCoordinator`  object
312    /// if you display text using a
313    /// <doc
314    /// ://com.apple.documentation/documentation/uikit/uitextview>,
315    /// ``NSTextField``,
316    /// ``NSTextView``,
317    /// <doc
318    /// ://com.apple.documentation/documentation/swiftui/textfield>, or
319    /// <doc
320    /// ://com.apple.documentation/documentation/swiftui/texteditor> view.
321    /// Those views already include the required support to handle Writing Tools
322    /// interactions.
323    ///
324    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinator?language=objc)
325    #[unsafe(super(NSObject))]
326    #[thread_kind = MainThreadOnly]
327    #[derive(Debug, PartialEq, Eq, Hash)]
328    pub struct NSWritingToolsCoordinator;
329);
330
331extern_conformance!(
332    unsafe impl NSObjectProtocol for NSWritingToolsCoordinator {}
333);
334
335impl NSWritingToolsCoordinator {
336    extern_methods!(
337        /// A Boolean value that indicates whether Writing Tools features are
338        /// currently available.
339        ///
340        /// The value of this property is `true` when Writing Tools features are
341        /// available, and `false` when they aren’t. Writing Tools support might
342        /// be unavailable because of device constraints or because the system isn’t
343        /// ready to process Writing Tools requests.
344        #[unsafe(method(isWritingToolsAvailable))]
345        #[unsafe(method_family = none)]
346        pub unsafe fn isWritingToolsAvailable(mtm: MainThreadMarker) -> bool;
347
348        /// Creates a writing tools coordinator and assigns the specified
349        /// delegate object to it.
350        ///
351        /// - Parameters:
352        /// - delegate: An object capable of handling Writing Tools interactions
353        /// for your view. The delegate must be able to modify your view’s text
354        /// storage and refresh the view’s layout and appearance.
355        ///
356        /// Create the coordinator object during your view’s initialization, and assign
357        /// the object to your view. Assign the coordinator to the ``NSView/writingToolsCoordinator``
358        /// property of your view.
359        #[unsafe(method(initWithDelegate:))]
360        #[unsafe(method_family = init)]
361        pub unsafe fn initWithDelegate(
362            this: Allocated<Self>,
363            delegate: Option<&ProtocolObject<dyn NSWritingToolsCoordinatorDelegate>>,
364        ) -> Retained<Self>;
365
366        /// The object that handles Writing Tools interactions for your view.
367        ///
368        /// Specify this object at initialization time when creating your `NSWritingToolsCoordinator`
369        /// object. The object must adopt the ``NSWritingToolsCoordinator/Delegate``
370        /// protocol, and be capable of modifying your view’s text storage and
371        /// refreshing the view’s layout and appearance.
372        #[unsafe(method(delegate))]
373        #[unsafe(method_family = none)]
374        pub unsafe fn delegate(
375            &self,
376        ) -> Option<Retained<ProtocolObject<dyn NSWritingToolsCoordinatorDelegate>>>;
377
378        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
379        /// The view that currently uses the writing tools coordinator.
380        ///
381        /// Use this property to refer to the view that currently owns the coordinator
382        /// object. The system updates this property automatically when you assign the
383        /// coordinator to the ``NSView/writingToolsCoordinator`` property of your view.
384        /// The value of this property is `nil` if there is no associated view.
385        #[unsafe(method(view))]
386        #[unsafe(method_family = none)]
387        pub unsafe fn view(&self) -> Option<Retained<NSView>>;
388
389        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
390        /// The view that Writing Tools uses to display visual effects during
391        /// the text-rewriting process.
392        ///
393        /// Writing Tools uses the view in this property to host the visual effects
394        /// it creates when making interactive changes to your view’s content.
395        /// These visual effects let people know the state of the text and provide
396        /// feedback about what’s happening to it. Set this property to a subview
397        /// that sits visually above, and covers, all of the text in your custom
398        /// text view. If you don’t assign a value to this property, the coordinator
399        /// places its own effect view in front of the subviews in your custom view.
400        /// The default value of this property is `nil`.
401        ///
402        /// If you display your view’s text using multiple text containers, implement the
403        /// ``NSWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:singleContainerSubrangesOf:in:)``
404        /// method to request multiple previews.
405        #[unsafe(method(effectContainerView))]
406        #[unsafe(method_family = none)]
407        pub unsafe fn effectContainerView(&self) -> Option<Retained<NSView>>;
408
409        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
410        /// This is a [weak property][objc2::topics::weak_property].
411        /// Setter for [`effectContainerView`][Self::effectContainerView].
412        #[unsafe(method(setEffectContainerView:))]
413        #[unsafe(method_family = none)]
414        pub unsafe fn setEffectContainerView(&self, effect_container_view: Option<&NSView>);
415
416        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
417        /// The view that Writing Tools uses to display background decorations
418        /// such as proofreading marks.
419        ///
420        /// Writing Tools uses the view in this property to host proofreading marks
421        /// and other visual elements that show any suggested changes. Set this
422        /// property to a subview situated visibly below the text in your custom
423        /// text view. It's also satisfactory to place this view visually in front
424        /// of the text. Make sure the size of the view is big enough to
425        /// cover all of the affected text. If you don’t assign a value to this
426        /// property, the coordinator places its own decoration view behind the subviews
427        /// in your custom view. The default value of this property is `nil`.
428        ///
429        /// If you display your view’s text using multiple text containers, implement the
430        /// ``NSWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:singleContainerSubrangesOf:in:)``
431        /// and ``NSWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:decorationContainerViewFor:in:)``
432        /// methods to provide separate decoration views for each container.
433        #[unsafe(method(decorationContainerView))]
434        #[unsafe(method_family = none)]
435        pub unsafe fn decorationContainerView(&self) -> Option<Retained<NSView>>;
436
437        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
438        /// This is a [weak property][objc2::topics::weak_property].
439        /// Setter for [`decorationContainerView`][Self::decorationContainerView].
440        #[unsafe(method(setDecorationContainerView:))]
441        #[unsafe(method_family = none)]
442        pub unsafe fn setDecorationContainerView(&self, decoration_container_view: Option<&NSView>);
443
444        /// The current level of Writing Tools activity in your view.
445        ///
446        /// Use this property to determine when Writing Tools is actively making
447        /// changes to your view. During the course of Writing Tools interactions,
448        /// the system reports state changes to the delegate’s
449        /// ``NSWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:willChangeTo:completion:)``
450        /// method and updates this property accordingly.
451        #[unsafe(method(state))]
452        #[unsafe(method_family = none)]
453        pub unsafe fn state(&self) -> NSWritingToolsCoordinatorState;
454
455        /// Stops the current Writing Tools operation and dismisses the system UI.
456        ///
457        /// Call this method to abort the current Writing Tools operation. This
458        /// method dismisses the system’s Writing Tools UI and stops any in-flight
459        /// interactions with your view. This method does not undo any changes that
460        /// Writing Tools already made to your view’s content.
461        #[unsafe(method(stopWritingTools))]
462        #[unsafe(method_family = none)]
463        pub unsafe fn stopWritingTools(&self);
464
465        #[cfg(feature = "NSTextCheckingClient")]
466        /// The level of Writing Tools support you want the system to provide
467        /// for your view.
468        ///
469        /// Use this property to request an inline or panel-based experience,
470        /// or to disable Writing Tools for your view altogether. The default
471        /// value of this property is ``NSWritingToolsBehavior/default``.
472        #[unsafe(method(preferredBehavior))]
473        #[unsafe(method_family = none)]
474        pub unsafe fn preferredBehavior(&self) -> NSWritingToolsBehavior;
475
476        #[cfg(feature = "NSTextCheckingClient")]
477        /// Setter for [`preferredBehavior`][Self::preferredBehavior].
478        #[unsafe(method(setPreferredBehavior:))]
479        #[unsafe(method_family = none)]
480        pub unsafe fn setPreferredBehavior(&self, preferred_behavior: NSWritingToolsBehavior);
481
482        #[cfg(feature = "NSTextCheckingClient")]
483        /// The actual level of Writing Tools support the system provides for your view.
484        ///
485        /// The system chooses this value based on the device capabilities, and takes
486        /// the value in the ``preferredBehavior`` property into consideration when
487        /// making the choice. The value in this property is never the default option,
488        /// and is instead one of the specific options such as ``NSWritingToolsBehavior/none``,
489        /// ``NSWritingToolsBehavior/limited``, or ``NSWritingToolsBehavior/complete``.
490        #[unsafe(method(behavior))]
491        #[unsafe(method_family = none)]
492        pub unsafe fn behavior(&self) -> NSWritingToolsBehavior;
493
494        #[cfg(feature = "NSTextCheckingClient")]
495        /// The type of content you allow Writing Tools to generate for your custom
496        /// text view.
497        ///
498        /// Writing Tools can create plain text or rich text, and it can format text
499        /// using lists or tables as needed. If your view doesn’t support specific
500        /// types of content, specify the types you do support in this property.
501        /// The default value of this property is ``NSWritingToolsResult/default``,
502        /// which lets the system determine the type of content to generate.
503        #[unsafe(method(preferredResultOptions))]
504        #[unsafe(method_family = none)]
505        pub unsafe fn preferredResultOptions(&self) -> NSWritingToolsResultOptions;
506
507        #[cfg(feature = "NSTextCheckingClient")]
508        /// Setter for [`preferredResultOptions`][Self::preferredResultOptions].
509        #[unsafe(method(setPreferredResultOptions:))]
510        #[unsafe(method_family = none)]
511        pub unsafe fn setPreferredResultOptions(
512            &self,
513            preferred_result_options: NSWritingToolsResultOptions,
514        );
515
516        #[cfg(feature = "NSTextCheckingClient")]
517        /// The type of content the system generates for your custom text view.
518        ///
519        /// This property contains the set of options that Writing Tools outputs
520        /// for your view. Writing Tools takes the value in the
521        /// ``NSWritingToolsCoordinator/preferredResultOptions`` property into
522        /// consideration when determining this value.
523        #[unsafe(method(resultOptions))]
524        #[unsafe(method_family = none)]
525        pub unsafe fn resultOptions(&self) -> NSWritingToolsResultOptions;
526
527        /// Informs the coordinator about changes your app made to the text
528        /// in the specified context object.
529        ///
530        /// - Parameters:
531        /// - range: The range of text to replace. This range is relative to
532        /// the starting location of the specified context object’s text in
533        /// your view’s text storage. If you initialized the context object
534        /// with the entire contents of your view’s text storage, specify the
535        /// range of text you’re replacing in your text storage. However, if
536        /// you initialized the context object with only a portion of your
537        /// view’s text, specify a range that is relative to the starting
538        /// location of the context object’s text.
539        /// - replacementText: The text that replaces the previous content in
540        /// `range`. Specify an empty string to delete the text in the specified range.
541        /// - reason: The reason you updated the text.
542        /// - contextID: The unique identifier of the context object that
543        /// contains the text you modified.
544        ///
545        /// If you make any changes to the text Writing Tools is evaluating, call
546        /// this method to report those changes to your view’s coordinator object.
547        /// You might make changes in response to an undo command or when someone
548        /// types into the same part of your view’s text. Calling this method
549        /// keeps the coordinator object informed of any changes, and ensures
550        /// it delivers accurate information to its delegate. In response, the
551        /// coordinator refreshes previews and other information related to your
552        /// view. If the scope of the update is significantly large, the coordinator
553        /// can optionally cancel the Writing Tools session altogether.
554        ///
555        /// Use this method to report changes that precisely intersect your context
556        /// object’s text. The first time you call this method for a context object,
557        /// report changes only to the original attributed string in that object.
558        /// If you call this method more than once, report changes to the newly
559        /// modified version of that string. Don’t use this method to report changes
560        /// to text that comes before or after the context object. If you make
561        /// changes before your context object, report those changes separately using the
562        /// ``updateForReflowedTextInContextWithIdentifier(_:)`` method.
563        ///
564        /// > Warning: Failure to call this method for a change can cause Writing Tools
565        /// to deliver inaccurate information to your delegate and lead to data loss.
566        #[unsafe(method(updateRange:withText:reason:forContextWithIdentifier:))]
567        #[unsafe(method_family = none)]
568        pub unsafe fn updateRange_withText_reason_forContextWithIdentifier(
569            &self,
570            range: NSRange,
571            replacement_text: &NSAttributedString,
572            reason: NSWritingToolsCoordinatorTextUpdateReason,
573            context_id: &NSUUID,
574        );
575
576        /// Informs the coordinator that a change occurred to the view or its text
577        /// that requires a layout update.
578        ///
579        /// - Parameters:
580        /// - contextID: The unique identifier of the context object affected
581        /// by the change. Pass the identifier for the context object that comes
582        /// after the changes.
583        ///
584        /// Use this method to inform Writing Tools when the geometry of your view
585        /// changes, or when the text that precedes one of your context objects changes.
586        /// Changes to the view’s geometry or text can affect the flow of any remaining
587        /// text, and require a layout update. Writing Tools uses this method to
588        /// refresh any layout-dependent information it’s currently tracking. For
589        /// example, it uses it to refresh the location of proofreading marks it’s
590        /// displaying in your view.
591        ///
592        /// If a text change affects the text inside a context object, call the
593        /// ``updateRange(_:with:reason:forContextWithIdentifier:)`` method to report
594        /// that change instead.
595        #[unsafe(method(updateForReflowedTextInContextWithIdentifier:))]
596        #[unsafe(method_family = none)]
597        pub unsafe fn updateForReflowedTextInContextWithIdentifier(&self, context_id: &NSUUID);
598    );
599}
600
601/// Methods declared on superclass `NSObject`.
602impl NSWritingToolsCoordinator {
603    extern_methods!(
604        #[unsafe(method(init))]
605        #[unsafe(method_family = init)]
606        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
607
608        #[unsafe(method(new))]
609        #[unsafe(method_family = new)]
610        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
611    );
612}
613
614extern_protocol!(
615    /// An interface that you use to manage interactions between Writing Tools
616    /// and your custom text view.
617    ///
618    /// Adopt the `NSWritingToolsCoordinator.Delegate` protocol in the type you
619    /// use to manage your custom text view. When you add a ``NSWritingToolsCoordinator``
620    /// object to your view, the coordinator uses this protocol to communicate
621    /// with that view. The protocol lets Writing Tools fetch your view’s text,
622    /// report suggested changes back to your view, and deliver visual feedback
623    /// when Writing Tools features are active. Make sure the type that adopts
624    /// this protocol has access to your view’s text storage and can perform
625    /// relevant tasks on behalf of the view.
626    ///
627    /// Writing Tools expects you to call the provided handler blocks at the end
628    /// of your delegate methods. It’s crucial that you execute these blocks in a
629    /// timely manner to allow Writing Tools to perform subsequent tasks. For example,
630    /// Writing Tools waits for you to execute the handlers for animation-related methods
631    /// before moving on to the next stage of the animations.
632    ///
633    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatordelegate?language=objc)
634    pub unsafe trait NSWritingToolsCoordinatorDelegate: NSObjectProtocol {
635        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
636        /// Asks your delegate to provide the text to evaluate during the Writing Tools
637        /// operation.
638        ///
639        /// - Parameters:
640        /// - writingToolsCoordinator: The coordinator object requesting information
641        /// from your custom view.
642        /// - scope: The amount of text the coordinator requested. Use this property
643        /// to determine if Writing Tools is evaluating all of your text or only a subset.
644        /// - completion: A completion block to execute with the required information.
645        /// You must execute this block once at end of your method's implementation.
646        /// The block has no return value and takes an array of
647        /// ``NSWritingToolsCoordinator/Context`` objects that contain the requested information.
648        ///
649        /// At the start of every operation, the ``NSWritingToolsCoordinator`` object calls
650        /// this method to request the text to evaluate. Use this method to create one or
651        /// more ``NSWritingToolsCoordinator/Context`` objects with your view’s text.
652        /// Create only one ``NSWritingToolsCoordinator/Context`` object if your view has
653        /// only one text storage object. If your view contains multiple text storage objects,
654        /// create separate ``NSWritingToolsCoordinator/Context`` objects for each
655        /// text storage object. Writing Tools returns updates for each context object
656        /// separately, making it easier for you to incorporate changes into the correct
657        /// text storage object. Don’t create multiple context objects if your view has
658        /// only one text storage object.
659        ///
660        /// The `scope` parameter tells you what content Writing Tools expects you to provide
661        /// in your context object. For example, Writing Tools expects you to provide the
662        /// selected text when the parameter contains the ``NSWritingToolsCoordinator/ContextScope/userSelection``
663        /// option. When Writing Tools requests a subset of your overall text, include
664        /// some of the surrounding text in your context object too. Writing Tools can
665        /// use the extra text you provide to improve the results of its evaluation. For
666        /// example, it might use an entire paragraph, instead of only the selected sentence,
667        /// to evaluate ways to rewrite that sentence. It’s best to include the text up
668        /// to the nearest paragraph boundary before and after the selection. If you
669        /// include extra text in your context object, set the ``NSWritingToolsCoordinator/Context/range``
670        /// property to the range of the selected text.
671        ///
672        /// > Note: When a context object stores only a subset of your view’s text, record
673        /// additional information to map the location of that text to the correct location
674        /// in your view’s text storage. Keep that information up-to-date throughout the
675        /// Writing Tools session.
676        ///
677        /// Pass the context objects you create to the provided completion handler before
678        /// your method returns. Writing Tools waits for you to call the completion
679        /// handler before proceeding with the operation.
680        #[unsafe(method(writingToolsCoordinator:requestsContextsForScope:completion:))]
681        #[unsafe(method_family = none)]
682        unsafe fn writingToolsCoordinator_requestsContextsForScope_completion(
683            &self,
684            writing_tools_coordinator: &NSWritingToolsCoordinator,
685            scope: NSWritingToolsCoordinatorContextScope,
686            completion: &block2::DynBlock<
687                dyn Fn(NonNull<NSArray<NSWritingToolsCoordinatorContext>>),
688            >,
689        );
690
691        #[cfg(all(
692            feature = "NSWritingToolsCoordinatorAnimationParameters",
693            feature = "NSWritingToolsCoordinatorContext",
694            feature = "block2"
695        ))]
696        /// Tells the delegate that there are text changes to incorporate into the view.
697        ///
698        /// - Parameters:
699        /// - writingToolsCoordinator: The coordinator object providing the changes
700        /// to your custom view.
701        /// - range: A range of text to update. This range is relative to the text
702        /// in your context object, and it’s your responsibility to match that location
703        /// to the correct location in your text storage. If you initialized the
704        /// context object with the entire contents of your view’s text storage,
705        /// you can use `range` as-is to access that text storage. However, if you
706        /// initialized the context object with only a portion of your view’s text,
707        /// add the starting location of your context object’s text to this value
708        /// to get the correct range for that text storage.
709        /// - context: The context object that contains the original text to modify.
710        /// Use this object to locate the correct text storage object for your view.
711        /// - replacementText: The text to insert in place of the current text at `range`.
712        /// You can insert this text as-is, insert a modified version of this string,
713        /// or reject the replacement text altogether.
714        /// - reason: The type of replacement Writing Tools performs. This parameter
715        /// indicates whether Writing Tools is replacing the text with or without animations.
716        /// - animationParameters: The animation parameters for any interactive changes,
717        /// or `nil` if the changes aren’t interactive. Use this object to create any
718        /// additional animations for the system to run alongside the changes Writing Tools
719        /// makes. For example, use it to update other views that contain related information.
720        /// - completion: A completion handler to execute with the results of the operation.
721        /// The handler has no return value and takes an optional attributed string as
722        /// a parameter. If you incorporate the replacement text, either as-is or with
723        /// modifications, pass the actual string you incorporated to the completion
724        /// block. If you reject the suggested change and leave the original text
725        /// unchanged, specify `nil` for this parameter.
726        ///
727        /// Use this method to update your view’s text storage with the proposed changes.
728        /// Writing Tools can call this method multiple times during the course of a
729        /// session to notify you of changes to different ranges of text. Incorporate
730        /// the changes into your view’s text storage and notify your layout manager
731        /// so it can refresh the view.
732        ///
733        /// > Important: When integrating changes, remember to update `range.location` as needed
734        /// to get the correct location in your view’s text storage.
735        ///
736        /// Remove the text in the appropriate range of your text storage, and replace
737        /// it with the contents of `replacementText`. When you finish, call the completion
738        /// handler and pass in the replacement text you inserted. If you change the
739        /// string in `replacementText` before incorporating it into your text storage,
740        /// return your modified string instead. Returning the string lets Writing Tools
741        /// track any alterations you made to it. You can also pass `nil` to the
742        /// completion handler if you don’t incorporate the replacement text.
743        ///
744        /// For interactive changes, Writing Tools works with your delegate to animate
745        /// the removal of the old text and the insertion of any replacement text. If
746        /// you need to modify other parts of your interface to reflect the changes,
747        /// use the provided ``NSWritingToolsCoordinator/AnimationParameters`` object
748        /// to create additional animations to run at the same time as the system-provided animations.
749        #[unsafe(method(writingToolsCoordinator:replaceRange:inContext:proposedText:reason:animationParameters:completion:))]
750        #[unsafe(method_family = none)]
751        unsafe fn writingToolsCoordinator_replaceRange_inContext_proposedText_reason_animationParameters_completion(
752            &self,
753            writing_tools_coordinator: &NSWritingToolsCoordinator,
754            range: NSRange,
755            context: &NSWritingToolsCoordinatorContext,
756            replacement_text: &NSAttributedString,
757            reason: NSWritingToolsCoordinatorTextReplacementReason,
758            animation_parameters: Option<&NSWritingToolsCoordinatorAnimationParameters>,
759            completion: &block2::DynBlock<dyn Fn(*mut NSAttributedString)>,
760        );
761
762        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
763        /// Asks the delegate to update your view’s current text selection.
764        ///
765        /// - Parameters:
766        /// - writingToolsCoordinator: The coordinator object making the change
767        /// to your view.
768        /// - ranges: One or more ranges of text to select. Each range is relative
769        /// to the text in your context object, and it’s your responsibility to
770        /// match each location to the correct location in your text storage. If
771        /// you initialized the context object with the entire contents of your
772        /// view’s text storage, you can use the ranges as-is to access that text
773        /// storage. However, if you initialized the context object with only a
774        /// portion of your view’s text, add the starting location of your context
775        /// object’s text to each value to get the correct range for that text storage.
776        /// - context: The context object you use to identify the associated text storage.
777        /// - completion: The completion handler to execute when your delegate finishes updating
778        /// the selection. The handler has no parameters or return value. You must
779        /// call this handler at some point during the implementation of your method.
780        ///
781        /// As Writing Tools suggests changes to your view’s text, it calls this method
782        /// to update the text selection accordingly. Use this method to update the
783        /// current selection in your view’s text storage. When you finish making the
784        /// changes, call the provided completion block to let Writing Tools know you’re finished.
785        #[unsafe(method(writingToolsCoordinator:selectRanges:inContext:completion:))]
786        #[unsafe(method_family = none)]
787        unsafe fn writingToolsCoordinator_selectRanges_inContext_completion(
788            &self,
789            writing_tools_coordinator: &NSWritingToolsCoordinator,
790            ranges: &NSArray<NSValue>,
791            context: &NSWritingToolsCoordinatorContext,
792            completion: &block2::DynBlock<dyn Fn()>,
793        );
794
795        #[cfg(all(
796            feature = "NSBezierPath",
797            feature = "NSWritingToolsCoordinatorContext",
798            feature = "block2"
799        ))]
800        /// Asks the delegate to provide the bounding paths for the specified
801        /// text in your view.
802        ///
803        /// - Parameters:
804        /// - writingToolsCoordinator: The coordinator object requesting information
805        /// from your custom view.
806        /// - range: The range of text to evaluate. This range is relative to the
807        /// text in your context object, and it’s your responsibility to match that
808        /// location to the correct location in your text storage. If you initialized
809        /// the context object with the entire contents of your view’s text storage,
810        /// you can use `range` as-is to access that text storage. However, if you
811        /// initialized the context object with only a portion of your view’s text,
812        /// add the starting location of your context object’s text to this value to
813        /// get the correct range for that text storage.
814        /// - context: The context object with the target text. Use this object to
815        /// find the text in your view’s text storage.
816        /// - completion: A handler to execute with the required information. The
817        /// handler has no return value and takes an array of Bezier paths as a
818        /// parameter. You must call this handler at some point during your method’s implementation.
819        ///
820        /// After applying proofreading marks to your view’s text, Writing Tools lets
821        /// the person accept or reject individual suggestions. To facilitate interactions,
822        /// the coordinator asks your delegate to provide one or more Bezier paths that
823        /// surround those proofreading suggestions. For each distinct range of text
824        /// with a suggestion, it calls this method to get the Bezier paths that surround
825        /// the corresponding text.
826        ///
827        /// After you determine the location of the specified range of text in your view’s
828        /// text storage, find the rectangle around that text. If you're using TextKit, call the
829        /// <doc
830        /// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager/3809995-enumeratetextsegments>
831        /// method of your view’s
832        /// <doc
833        /// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager>
834        /// to compute the selection rectangles for that text. That method finds the text
835        /// segments that contain the text and returns the frame rectangle for each one.
836        /// Create a Bezier path for each rectangle, and convert the coordinates of each path
837        /// to the coordinate space of the view in your coordinator's ``NSWritingToolsCoordinator/decorationContainerView``
838        /// property. Pass the resulting paths to the completion handler.
839        #[unsafe(method(writingToolsCoordinator:requestsBoundingBezierPathsForRange:inContext:completion:))]
840        #[unsafe(method_family = none)]
841        unsafe fn writingToolsCoordinator_requestsBoundingBezierPathsForRange_inContext_completion(
842            &self,
843            writing_tools_coordinator: &NSWritingToolsCoordinator,
844            range: NSRange,
845            context: &NSWritingToolsCoordinatorContext,
846            completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<NSBezierPath>>)>,
847        );
848
849        #[cfg(all(
850            feature = "NSBezierPath",
851            feature = "NSWritingToolsCoordinatorContext",
852            feature = "block2"
853        ))]
854        /// Asks the delegate to provide an underline shape for the specified text
855        /// during a proofreading session.
856        ///
857        /// - Parameters:
858        /// - writingToolsCoordinator: The coordinator object requesting information
859        /// from your custom view.
860        /// - range: The range of text to evaluate. This range is relative to the
861        /// text in your context object, and it’s your responsibility to match that
862        /// location to the correct location in your text storage. If you initialized
863        /// the context object with the entire contents of your view’s text storage,
864        /// you can use `range` as-is to access that text storage. However, if you
865        /// initialized the context object with only a portion of your view’s text,
866        /// add the starting location of your context object’s text to this value
867        /// to get the correct range for that text storage.
868        /// - context: The context object with the target text. Use this object to
869        /// find the text in your view’s text storage.
870        /// - completion: A handler to execute with the required information. The
871        /// handler has no return value and takes an array of Bezier paths as a
872        /// parameter. You must call this handler at some point during your method’s implementation.
873        ///
874        /// When applying proofreading marks to your view’s content, the coordinator
875        /// calls this method to retrieve a shape to draw under the specified text.
876        /// You provide the shape using one or more Bezier paths, and the coordinator
877        /// draws and animates that shape during the proofreading session.
878        ///
879        /// After you determine the location of the specified range of text in your
880        /// view’s text storage, find the rectangle around that text. If you're using
881        /// TextKit, you can call the
882        /// <doc
883        /// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager/3809995-enumeratetextsegments>
884        /// method of your view’s
885        /// <doc
886        /// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager>
887        /// to get the rectangles for a range of text. Convert the coordinates of each rectangle
888        /// to the coordinate space of the view in your coordinator's ``NSWritingToolsCoordinator/decorationContainerView``
889        /// property. Use those rectangles to create the Bezier paths for your text.
890        /// For example, you might create a path with a straight or wavy line at the
891        /// bottom of the rectangle.
892        #[unsafe(method(writingToolsCoordinator:requestsUnderlinePathsForRange:inContext:completion:))]
893        #[unsafe(method_family = none)]
894        unsafe fn writingToolsCoordinator_requestsUnderlinePathsForRange_inContext_completion(
895            &self,
896            writing_tools_coordinator: &NSWritingToolsCoordinator,
897            range: NSRange,
898            context: &NSWritingToolsCoordinatorContext,
899            completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<NSBezierPath>>)>,
900        );
901
902        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
903        /// Prepare for animations for the content that Writing Tools is evaluating.
904        ///
905        /// - Parameters:
906        /// - writingToolsCoordinator: The coordinator object notifying you that
907        /// animations are about to begin.
908        /// - textAnimation: The type of animation Writing Tools is preparing.
909        /// - range: The range of text affected by the animation. This range is
910        /// relative to the text in your context object, and it’s your responsibility
911        /// to match that location to the correct location in your text storage.
912        /// If you initialized the context object with the entire contents of your
913        /// view’s text storage, you can use `range` as-is to access that text
914        /// storage. However, if you initialized the context object with only a portion
915        /// of your view’s text, add the starting location of your context object’s
916        /// text to this value to get the correct range for that text storage.
917        /// - context: The context object that contains the original text. Use this
918        /// object to fetch the current text, and to match that text to your underlying
919        /// text storage.
920        /// - completion: A completion handler to execute when you are done. The handler
921        /// has no return value and takes no parameters. You must call this handler
922        /// at some point during your implementation.
923        ///
924        /// During an interactive evaluation of your view’s text, Writing Tools creates
925        /// different animations to provide feedback on what’s happening. For example, it
926        /// creates an ``NSWritingToolsCoordinator/TextAnimation/anticipate`` animation to
927        /// let people know the system is evaluating the text. The `textAnimation` parameter
928        /// tells you what type of animation to prepare for.
929        ///
930        /// Use this method to prepare for the system-provided animations of your view’s
931        /// content. For interactive animations, hide the text in the specified range temporarily
932        /// while the system animations run. For non-interactive animations, dim the text
933        /// for the duration of the animation to indicate it’s not editable. For animations
934        /// to remove or insert text, you can also use this method to set up animations
935        /// to reflow your view’s content to match the changes. At the end of a given animation,
936        /// use your delegate’s ``writingToolsCoordinator(_:finish:for:in:completion:)``
937        /// method to undo any changes you make to your content.
938        ///
939        /// For a single animation type, the system calls this method, followed sequentially
940        /// by the ``writingToolsCoordinator(_:previewFor:range:context:completion:)``
941        /// and ``writingToolsCoordinator(_:finish:for:in:completion:)``
942        /// methods. Each method executes asynchronously, but the system calls the next
943        /// method in the sequence only after you call the completion handler of the previous
944        /// method. However, multiple animations can run simultaneously, so check the
945        /// `textAnimation` and `range` parameters to differentiate sequences.
946        #[unsafe(method(writingToolsCoordinator:prepareForTextAnimation:forRange:inContext:completion:))]
947        #[unsafe(method_family = none)]
948        unsafe fn writingToolsCoordinator_prepareForTextAnimation_forRange_inContext_completion(
949            &self,
950            writing_tools_coordinator: &NSWritingToolsCoordinator,
951            text_animation: NSWritingToolsCoordinatorTextAnimation,
952            range: NSRange,
953            context: &NSWritingToolsCoordinatorContext,
954            completion: &block2::DynBlock<dyn Fn()>,
955        );
956
957        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
958        /// Asks the delegate for a preview image and layout information for the
959        /// specified text.
960        ///
961        /// - Parameters:
962        /// - writingToolsCoordinator: The coordinator object notifying you that
963        /// animations are about to begin.
964        /// - textAnimation: The type of animation Writing Tools is preparing.
965        /// - range: The range of text that requires a preview image. This range
966        /// is relative to the text in your context object, and it’s your responsibility
967        /// to match that location to the correct location in your text storage.
968        /// If you initialized the context object with the entire contents of
969        /// your view’s text storage, you can use `range` as-is to access that
970        /// text storage. However, if you initialized the context object with only
971        /// a portion of your view’s text, add the starting location of your
972        /// context object’s text to this value to get the correct range for that
973        /// text storage.
974        /// - context: The context object that contains the original text. Use this
975        /// object to fetch the current text, and to match that text to your
976        /// underlying text storage.
977        /// - completion: A completion handler to execute when you are done. The
978        /// handler has no return value and takes an ``NSTextPreview`` object
979        /// as a parameter. You must call this handler at some point during your implementation.
980        ///
981        /// During an interactive evaluation of your view’s text, Writing Tools creates
982        /// different animations to provide feedback on what’s happening. As part of
983        /// the preparation for those animations, Writing Tools asks you to provide
984        /// a preview of the affected content in your view. Writing Tools uses this
985        /// preview to build and execute the animations in the view stored in the
986        /// ``NSWritingToolsCoordinator/effectContainerView`` property of the coordinator object.
987        ///
988        /// To build a preview of your content in macOS, render the specified range of text
989        /// into an image with a transparent background and use that image to create your
990        /// ``NSTextPreview`` object directly. Set the ``NSTextPreview/presentationFrame``
991        /// property to the rectangle in your view’s coordinate space that contains the
992        /// text you captured. Set the ``NSTextPreview/candidateRects`` property to the
993        /// selection rectangles for the text, which you get from your view’s layout manager.
994        /// Writing Tools uses this information to place your image directly above the text in your view.
995        ///
996        /// For a single animation type, the system calls the
997        /// ``writingToolsCoordinator(_:prepareFor:range:context:completion:)``
998        /// method, followed sequentially by this method and then the
999        /// ``writingToolsCoordinator(_:finish:for:in:completion:)``
1000        /// method. Each method executes asynchronously, but the system calls the next
1001        /// method in the sequence only after you call the completion handler of the
1002        /// previous method. However, multiple animations can run simultaneously, so
1003        /// check the `textAnimation` parameter to differentiate sequences.
1004        #[unsafe(method(writingToolsCoordinator:requestsPreviewForTextAnimation:ofRange:inContext:completion:))]
1005        #[unsafe(method_family = none)]
1006        unsafe fn writingToolsCoordinator_requestsPreviewForTextAnimation_ofRange_inContext_completion(
1007            &self,
1008            writing_tools_coordinator: &NSWritingToolsCoordinator,
1009            text_animation: NSWritingToolsCoordinatorTextAnimation,
1010            range: NSRange,
1011            context: &NSWritingToolsCoordinatorContext,
1012            completion: &block2::DynBlock<dyn Fn(*mut NSArray<NSTextPreview>)>,
1013        );
1014
1015        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
1016        /// Asks the delegate for a preview image and layout information for the
1017        /// specified text.
1018        ///
1019        /// - Parameters:
1020        /// - writingToolsCoordinator: The coordinator object notifying you that
1021        /// animations are about to begin.
1022        /// - rect: The portion of your view that contains the requested text. This rectangle is in the view’s coordinate system.
1023        /// - context: The context object that contains the original text. Use this
1024        /// object to fetch the current text, and to match that text to your
1025        /// underlying text storage.
1026        /// - completion: A completion handler to execute when you are done. The
1027        /// handler has no return value and takes an ``NSTextPreview`` object
1028        /// as a parameter. You must call this handler at some point during your implementation.
1029        ///
1030        /// During an interactive evaluation of your view’s text, Writing Tools creates
1031        /// different animations to provide feedback on what’s happening. As part of
1032        /// the preparation for those animations, Writing Tools asks you to provide
1033        /// a preview of the affected content in your view. Writing Tools uses this
1034        /// preview to build and execute the animations in the view stored in the
1035        /// ``NSWritingToolsCoordinator/effectContainerView`` property of the coordinator object.
1036        ///
1037        /// To build a preview of your content in macOS, render the requested portion
1038        /// of your view into an image with a transparent background and use that image
1039        /// to create your ``NSTextPreview`` object directly. Set the ``NSTextPreview/presentationFrame``
1040        /// property to the specified rectangle. Set the ``NSTextPreview/candidateRects``
1041        /// property to the selection rectangles for the associated text, which you get
1042        /// from your view’s layout manager. Writing Tools uses this information to
1043        /// place your image directly above the text in your view.
1044        ///
1045        /// For a single animation type, the system calls the
1046        /// ``writingToolsCoordinator(_:prepareFor:range:context:completion:)``
1047        /// method, followed sequentially by this method and then the
1048        /// ``writingToolsCoordinator(_:finish:for:in:completion:)``
1049        /// method. Each method executes asynchronously, but the system calls the next
1050        /// method in the sequence only after you call the completion handler of the
1051        /// previous method. However, multiple animations can run simultaneously, so
1052        /// check the `textAnimation` parameter to differentiate sequences.
1053        #[unsafe(method(writingToolsCoordinator:requestsPreviewForRect:inContext:completion:))]
1054        #[unsafe(method_family = none)]
1055        unsafe fn writingToolsCoordinator_requestsPreviewForRect_inContext_completion(
1056            &self,
1057            writing_tools_coordinator: &NSWritingToolsCoordinator,
1058            rect: NSRect,
1059            context: &NSWritingToolsCoordinatorContext,
1060            completion: &block2::DynBlock<dyn Fn(*mut NSTextPreview)>,
1061        );
1062
1063        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
1064        /// Asks the delegate to clean up any state related to the specified
1065        /// Writing Tools animation.
1066        ///
1067        /// - Parameters:
1068        /// - writingToolsCoordinator: The coordinator object notifying you
1069        /// that animations are about to begin.
1070        /// - textAnimation: The type of animation Writing Tools finished.
1071        /// - range: The range of text that finished animating. This range is
1072        /// relative to the text in your context object, and it’s your responsibility
1073        /// to match that location to the correct location in your text storage.
1074        /// If you initialized the context object with the entire contents of
1075        /// your view’s text storage, you can use `range` as-is to access that
1076        /// text storage. However, if you initialized the context object with
1077        /// only a portion of your view’s text, add the starting location of
1078        /// your context object’s text to this value to get the correct range
1079        /// for that text storage.
1080        /// - context: The context object that contains the original text.
1081        /// - completion: A completion handler to execute when you are done.
1082        /// The handler has no return value and takes no parameters. You must
1083        /// call this handler at some point during your implementation.
1084        ///
1085        /// Use this method to clean up any data structures you created to support
1086        /// the specified type of Writing Tools animation. You can also use this
1087        /// method to restore the visibility of any text you hid previously. When
1088        /// you finish your cleanup work, call the completion handler to notify Writing Tools.
1089        ///
1090        /// Writing Tools calls this method only after previous calls to the
1091        /// ``writingToolsCoordinator(_:prepareFor:range:context:completion:)``
1092        /// and ``writingToolsCoordinator(_:previewFor:range:context:completion:)``
1093        /// methods for the same animation type. However, Writing Tools can interleave
1094        /// calls to this method with calls to prepare an animation of a different
1095        /// type. In your implementation of this method, make sure the actions you
1096        /// take don’t interfere with other in-flight animations.
1097        #[unsafe(method(writingToolsCoordinator:finishTextAnimation:forRange:inContext:completion:))]
1098        #[unsafe(method_family = none)]
1099        unsafe fn writingToolsCoordinator_finishTextAnimation_forRange_inContext_completion(
1100            &self,
1101            writing_tools_coordinator: &NSWritingToolsCoordinator,
1102            text_animation: NSWritingToolsCoordinatorTextAnimation,
1103            range: NSRange,
1104            context: &NSWritingToolsCoordinatorContext,
1105            completion: &block2::DynBlock<dyn Fn()>,
1106        );
1107
1108        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
1109        /// Asks the delegate to divide the specified range of text into the separate
1110        /// containers that render that text.
1111        ///
1112        /// - Parameters:
1113        /// - writingToolsCoordinator: The coordinator object requesting information
1114        /// from your custom view.
1115        /// - range: The range of text to consider in the specified `context` object.
1116        /// The location value of this range is relative to the beginning of the text
1117        /// in your context object, and it’s your responsibility to match that location
1118        /// to the correct location in your text storage. If you initialized the
1119        /// context object with the entire contents of your view’s text storage,
1120        /// you can use `range` as-is to access that text storage. However, if you
1121        /// initialized the context object with only a portion of your view’s text,
1122        /// add the starting location of your context object’s text to this value
1123        /// to get the correct range for that text storage.
1124        /// - context: The context object that contains the text to consider. Use this
1125        /// object to locate the appropriate text storage object for your view.
1126        /// - completion: A completion handler to execute when you are done. The handler
1127        /// has no return value and takes an array of
1128        /// <doc
1129        /// ://com.apple.documentation/documentation/foundation/nsvalue>
1130        /// types, each of which contains an
1131        /// <doc
1132        /// ://com.apple.documentation/documentation/foundation/nsrange>.
1133        /// The union of the ranges you pass to this handler must equal all of the
1134        /// text in `range`. The order of the ranges in the array must be sequential,
1135        /// with each new range's starting location coming after the previous one.
1136        /// There must also not be any gaps or overlap between ranges.
1137        /// You must call this handler at some point during your implementation.
1138        ///
1139        /// If your view uses multiple ``NSTextContainer`` objects to draw text in different
1140        /// regions, use this method to tell Writing Tools about the containers that display
1141        /// the specified text. In your implementation, subdivide `range` to create one new
1142        /// range for each portion of text that resides in a different container object.
1143        /// For example, if the text in `range` is split between two containers, provide
1144        /// two new
1145        /// <doc
1146        /// ://com.apple.documentation/documentation/foundation/nsrange> types
1147        /// that reflect the portion of the total text in each container. If `range` resides completely
1148        /// within one container, call the completion handler with `range` as the only value
1149        /// in the array.
1150        ///
1151        /// When configuring animations for your view, Writing Tools asks your delegate to
1152        /// provide separate previews for each of your view’s container object. Specifically,
1153        /// it calls your delegate’s ``writingToolsCoordinator(_:previewFor:range:context:completion:)``
1154        /// method separately for each range of text you return in the completion handler.
1155        /// Your implementation of that method must create a preview suitable for animating
1156        /// the content from the underlying text container.
1157        #[optional]
1158        #[unsafe(method(writingToolsCoordinator:requestsSingleContainerSubrangesOfRange:inContext:completion:))]
1159        #[unsafe(method_family = none)]
1160        unsafe fn writingToolsCoordinator_requestsSingleContainerSubrangesOfRange_inContext_completion(
1161            &self,
1162            writing_tools_coordinator: &NSWritingToolsCoordinator,
1163            range: NSRange,
1164            context: &NSWritingToolsCoordinatorContext,
1165            completion: &block2::DynBlock<dyn Fn(NonNull<NSArray<NSValue>>)>,
1166        );
1167
1168        #[cfg(all(
1169            feature = "NSResponder",
1170            feature = "NSView",
1171            feature = "NSWritingToolsCoordinatorContext",
1172            feature = "block2"
1173        ))]
1174        /// Asks the delegate to provide a decoration view for the specified range of text.
1175        ///
1176        /// - Parameters:
1177        /// - writingToolsCoordinator: The coordinator object requesting information
1178        /// from your custom view.
1179        /// - range: The range of text to consider in the specified `context` object.
1180        /// The location value of this range is relative to the beginning of the text
1181        /// in your context object, and it’s your responsibility to match that location
1182        /// to the correct location in your text storage. If you initialized the
1183        /// context object with the entire contents of your view’s text storage, you
1184        /// can use `range` as-is to access that text storage. However, if you initialized
1185        /// the context object with only a portion of your view’s text, add the starting
1186        /// location of your context object’s text to this value to get the correct
1187        /// range for that text storage.
1188        /// - context: The context object that contains the text to consider. Use this
1189        /// object to locate the appropriate text storage object for your view.
1190        /// - completion: A completion handler to execute when you are done. The handler
1191        /// has no return value and takes an ``NSView`` object as a parameter. You must call
1192        /// this handler at some point during your implementation.
1193        ///
1194        /// If your view uses multiple ``NSTextContainer`` objects to draw text in different
1195        /// regions, use this method to provide Writing Tools with the view to use for the
1196        /// specified range of text. After calling your delegate’s ``writingToolsCoordinator(_:singleContainerSubrangesOf:in:)``
1197        /// method, Writing Tools calls this method for each subrange of text you provided.
1198        /// Find or provide a view situated visibly below the specified text in your text
1199        /// view. It's also satisfactory to provide a view that’s visually in front of the
1200        /// text. Writing Tools uses the provided view to host any proofreading marks for
1201        /// the specified range of text.
1202        ///
1203        /// If your view has only one text container, use the coordinator’s ``NSWritingToolsCoordinator/decorationContainerView``
1204        /// property to specify the view to use for proofreading marks.
1205        #[optional]
1206        #[unsafe(method(writingToolsCoordinator:requestsDecorationContainerViewForRange:inContext:completion:))]
1207        #[unsafe(method_family = none)]
1208        unsafe fn writingToolsCoordinator_requestsDecorationContainerViewForRange_inContext_completion(
1209            &self,
1210            writing_tools_coordinator: &NSWritingToolsCoordinator,
1211            range: NSRange,
1212            context: &NSWritingToolsCoordinatorContext,
1213            completion: &block2::DynBlock<dyn Fn(NonNull<NSView>)>,
1214        );
1215
1216        #[cfg(feature = "block2")]
1217        /// Notifies your delegate of relevant state changes when Writing Tools
1218        /// is running in your view.
1219        ///
1220        /// - Parameters:
1221        /// - writingToolsCoordinator: The coordinator object providing
1222        /// information to your custom view.
1223        /// - state: The new state for the Writing Tools session. For information
1224        /// about the possible states, see ``NSWritingToolsCoordinator/State``.
1225        /// - text: The current text for your context object.
1226        /// - reason: The reason for the state change.
1227        /// - context: The context object that contains the original text for
1228        /// Writing Tools to evaluate.
1229        /// - completion: A handler to execute when your delegate finishes processing
1230        /// the change of state. The handler has no parameters or return value. You
1231        /// must call this handler at some point during the implementation of your method.
1232        ///
1233        /// Use state transitions to perform actions related to your view or text storage.
1234        /// When Writing Tools is active, it updates its state to indicate what task
1235        /// it’s currently performing. Writing Tools starts in the ``NSWritingToolsCoordinator/State/inactive``
1236        /// state and moves to other states as it presents UI and starts interacting with
1237        /// your view’s content. For example, it moves to the ``NSWritingToolsCoordinator/State/interactiveUpdating``
1238        /// state when it’s making changes to your view’s text storage.
1239        #[optional]
1240        #[unsafe(method(writingToolsCoordinator:willChangeToState:completion:))]
1241        #[unsafe(method_family = none)]
1242        unsafe fn writingToolsCoordinator_willChangeToState_completion(
1243            &self,
1244            writing_tools_coordinator: &NSWritingToolsCoordinator,
1245            new_state: NSWritingToolsCoordinatorState,
1246            completion: &block2::DynBlock<dyn Fn()>,
1247        );
1248
1249        #[cfg(feature = "block2")]
1250        /// Asks the delegate to provide the location of the character at the
1251        /// specified point in your view’s coordinate system.
1252        ///
1253        /// - Parameters:
1254        /// - writingToolsCoordinator: The coordinator object requesting
1255        /// information from your custom view.
1256        /// - point: A point in your view’s coordinate space. Find the
1257        /// location of the text under this point, if any.
1258        /// - completion: A handler to execute with the required information.
1259        /// This handler has no return value and takes an
1260        /// <doc
1261        /// ://com.apple.documentation/documentation/foundation/nsrange>
1262        /// and
1263        /// <doc
1264        /// ://com.apple.documentation/documentation/foundation/uuid>
1265        /// as parameters. Set the range to the character’s location in one of your
1266        /// ``NSWritingToolsCoordinator/Context`` objects, which you specify using
1267        /// the
1268        /// <doc
1269        /// ://com.apple.documentation/documentation/foundation/uuid> parameter.
1270        /// You must call this handler at some point during your method’s implementation.
1271        ///
1272        /// When someone interacts with your view during a proofreading operation, Writing Tools
1273        /// calls this method to get the location of the interaction. If the interaction
1274        /// occurs in the text of one of your ``NSWritingToolsCoordinator/Context`` objects,
1275        /// configure an
1276        /// <doc
1277        /// ://com.apple.documentation/documentation/foundation/nsrange>
1278        /// with the character’s location in that context object and a length of `1`. If
1279        /// the interaction occurs outside of the text of your context objects, configure
1280        /// the range with a location of `NSNotFound`.
1281        ///
1282        /// When specifying the location of a character in your context object, provide a
1283        /// location relative to the start of your context object’s text. The first character
1284        /// in a context object’s text is always at location `0`, and it’s your responsibility
1285        /// to track the location of the context object’s text in your text storage object.
1286        /// When the context object’s text begins in the middle of your text storage,
1287        /// subtract the starting location of the context object’s text from the location
1288        /// you specify in your range value. For example, if the context object’s text
1289        /// starts at character `100` in your text storage, and an interaction occurs
1290        /// with the character at location `102`, specify a range with a location of
1291        /// `2` and a length of `1`.
1292        #[deprecated = "Not used anymore"]
1293        #[optional]
1294        #[unsafe(method(writingToolsCoordinator:requestsRangeInContextWithIdentifierForPoint:completion:))]
1295        #[unsafe(method_family = none)]
1296        unsafe fn writingToolsCoordinator_requestsRangeInContextWithIdentifierForPoint_completion(
1297            &self,
1298            writing_tools_coordinator: &NSWritingToolsCoordinator,
1299            point: NSPoint,
1300            completion: &block2::DynBlock<dyn Fn(NSRange, NonNull<NSUUID>)>,
1301        );
1302    }
1303);
1304
1305extern_class!(
1306    /// A snapshot of the text in your view, which the system uses to create
1307    /// user-visible effects.
1308    ///
1309    /// An `NSTextPreview` object provides a static image of your view’s text
1310    /// content that the system can use to create animations. You provide preview
1311    /// objects in response to system requests, such as ones from Writing Tools.
1312    /// In addition to creating an image of your view’s text, you also specify
1313    /// the location of that text in your view’s frame rectangle. When creating
1314    /// animations, the system places the image on top of your view’s content
1315    /// and animates changes to the image instead of to your view.
1316    ///
1317    /// Create an `NSTextPreview` object in response to specific system requests.
1318    /// Create an image with a transparent background and render your view’s text
1319    /// into the image using the current text attributes. Construct your `NSTextPreview`
1320    /// object with both the image and the frame rectangle that represents the
1321    /// location of the rendered text in your view’s coordinate system. To highlight
1322    /// specific portions of text, instead of all the text in the image, provide
1323    /// a set of candidate rectangles with the locations of the text you want to highlight.
1324    ///
1325    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextpreview?language=objc)
1326    #[unsafe(super(NSObject))]
1327    #[thread_kind = MainThreadOnly]
1328    #[derive(Debug, PartialEq, Eq, Hash)]
1329    pub struct NSTextPreview;
1330);
1331
1332extern_conformance!(
1333    unsafe impl NSObjectProtocol for NSTextPreview {}
1334);
1335
1336impl NSTextPreview {
1337    extern_methods!(
1338        #[cfg(feature = "objc2-core-graphics")]
1339        #[cfg(target_vendor = "apple")]
1340        /// Creates a text preview using the specified image and rectangles that indicate
1341        /// the portions of text to highlight.
1342        ///
1343        /// - Parameters:
1344        /// - snapshotImage: An image that contains the requested text from your view.
1345        /// Create the image using a transparent background and the current rendering
1346        /// attributes for your text.
1347        /// - presentationFrame: A rectangle in the coordinate space of your text view.
1348        /// The system uses this rectangle to place your image precisely over your
1349        /// view’s actual text. Set its size to the size of your snapshot image, and
1350        /// set its origin to the point that allows the system to place your image
1351        /// directly over the text.
1352        /// - candidateRects: An array of
1353        /// <doc
1354        /// ://com.apple.documentation/documentation/foundation/nsvalue>
1355        /// objects, each of which contains an
1356        /// <doc
1357        /// ://com.apple.documentation/documentation/foundation/nsrect>
1358        /// in the coordinate space of your text view. Each rectangle contains a
1359        /// bounding rectangle for text that is part of the preview. When applying
1360        /// visual effects, the system adds highlights only to the text in the specified rectangles.
1361        #[unsafe(method(initWithSnapshotImage:presentationFrame:candidateRects:))]
1362        #[unsafe(method_family = init)]
1363        pub unsafe fn initWithSnapshotImage_presentationFrame_candidateRects(
1364            this: Allocated<Self>,
1365            snapshot_image: &CGImage,
1366            presentation_frame: NSRect,
1367            candidate_rects: &NSArray<NSValue>,
1368        ) -> Retained<Self>;
1369
1370        #[cfg(feature = "objc2-core-graphics")]
1371        #[cfg(target_vendor = "apple")]
1372        /// Creates a text preview using the specified image.
1373        ///
1374        /// - Parameters:
1375        /// - snapshotImage: An image that contains the requested text from your view.
1376        /// Create the image using a transparent background and the current rendering
1377        /// attributes for your text.
1378        /// - presentationFrame: A rectangle in your frame’s coordinate space. The
1379        /// system uses this rectangle to place your image precisely over your view’s
1380        /// actual text. Set its size to the size of your snapshot image, and set its
1381        /// origin to the point that allows the system to place your image directly over the text.
1382        #[unsafe(method(initWithSnapshotImage:presentationFrame:))]
1383        #[unsafe(method_family = init)]
1384        pub unsafe fn initWithSnapshotImage_presentationFrame(
1385            this: Allocated<Self>,
1386            snapshot_image: &CGImage,
1387            presentation_frame: NSRect,
1388        ) -> Retained<Self>;
1389
1390        #[unsafe(method(init))]
1391        #[unsafe(method_family = init)]
1392        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1393
1394        #[cfg(feature = "objc2-core-graphics")]
1395        #[cfg(target_vendor = "apple")]
1396        /// The image that contains the requested text from your view.
1397        ///
1398        /// You specify this image at initialization time. The system uses it to
1399        /// implement any visual effects involving your view’s text. Create the image
1400        /// with your text on a transparent background.
1401        #[unsafe(method(previewImage))]
1402        #[unsafe(method_family = none)]
1403        pub unsafe fn previewImage(&self) -> Retained<CGImage>;
1404
1405        /// The frame rectangle that places the preview image directly over the
1406        /// matching text.
1407        ///
1408        /// You specify this value at initialization time. The system uses it to
1409        /// position the preview image over the text in your view. Make sure the
1410        /// frame rectangle is in your view's coordinate space.
1411        #[unsafe(method(presentationFrame))]
1412        #[unsafe(method_family = none)]
1413        pub unsafe fn presentationFrame(&self) -> NSRect;
1414
1415        /// Rectangles that define the specific portions of text to highlight.
1416        ///
1417        /// At initialization time, you set this property to an array of
1418        /// <doc
1419        /// ://com.apple.documentation/documentation/foundation/nsvalue> objects,
1420        /// each of which contains an
1421        /// <doc
1422        /// ://com.apple.documentation/documentation/foundation/nsrect>
1423        /// in the coordinate space of the target view. Each rectangle contains a bounding
1424        /// rectangle for text that is part of the preview. When applying visual effects,
1425        /// the system adds highlights only to the text in the specified rectangles.
1426        #[unsafe(method(candidateRects))]
1427        #[unsafe(method_family = none)]
1428        pub unsafe fn candidateRects(&self) -> Retained<NSArray<NSValue>>;
1429    );
1430}
1431
1432/// Methods declared on superclass `NSObject`.
1433impl NSTextPreview {
1434    extern_methods!(
1435        #[unsafe(method(new))]
1436        #[unsafe(method_family = new)]
1437        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
1438    );
1439}