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
331unsafe impl NSObjectProtocol for NSWritingToolsCoordinator {}
332
333impl NSWritingToolsCoordinator {
334    extern_methods!(
335        /// A Boolean value that indicates whether Writing Tools features are
336        /// currently available.
337        ///
338        /// The value of this property is `true` when Writing Tools features are
339        /// available, and `false` when they aren’t. Writing Tools support might
340        /// be unavailable because of device constraints or because the system isn’t
341        /// ready to process Writing Tools requests.
342        #[unsafe(method(isWritingToolsAvailable))]
343        #[unsafe(method_family = none)]
344        pub unsafe fn isWritingToolsAvailable(mtm: MainThreadMarker) -> bool;
345
346        /// Creates a writing tools coordinator and assigns the specified
347        /// delegate object to it.
348        ///
349        /// - Parameters:
350        /// - delegate: An object capable of handling Writing Tools interactions
351        /// for your view. The delegate must be able to modify your view’s text
352        /// storage and refresh the view’s layout and appearance.
353        ///
354        /// Create the coordinator object during your view’s initialization, and assign
355        /// the object to your view. Assign the coordinator to the ``NSView/writingToolsCoordinator``
356        /// property of your view.
357        #[unsafe(method(initWithDelegate:))]
358        #[unsafe(method_family = init)]
359        pub unsafe fn initWithDelegate(
360            this: Allocated<Self>,
361            delegate: Option<&ProtocolObject<dyn NSWritingToolsCoordinatorDelegate>>,
362        ) -> Retained<Self>;
363
364        /// The object that handles Writing Tools interactions for your view.
365        ///
366        /// Specify this object at initialization time when creating your `NSWritingToolsCoordinator`
367        /// object. The object must adopt the ``NSWritingToolsCoordinator/Delegate``
368        /// protocol, and be capable of modifying your view’s text storage and
369        /// refreshing the view’s layout and appearance.
370        #[unsafe(method(delegate))]
371        #[unsafe(method_family = none)]
372        pub unsafe fn delegate(
373            &self,
374        ) -> Option<Retained<ProtocolObject<dyn NSWritingToolsCoordinatorDelegate>>>;
375
376        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
377        /// The view that currently uses the writing tools coordinator.
378        ///
379        /// Use this property to refer to the view that currently owns the coordinator
380        /// object. The system updates this property automatically when you assign the
381        /// coordinator to the ``NSView/writingToolsCoordinator`` property of your view.
382        /// The value of this property is `nil` if there is no associated view.
383        #[unsafe(method(view))]
384        #[unsafe(method_family = none)]
385        pub unsafe fn view(&self) -> Option<Retained<NSView>>;
386
387        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
388        /// The view that Writing Tools uses to display visual effects during
389        /// the text-rewriting process.
390        ///
391        /// Writing Tools uses the view in this property to host the visual effects
392        /// it creates when making interactive changes to your view’s content.
393        /// These visual effects let people know the state of the text and provide
394        /// feedback about what’s happening to it. Set this property to a subview
395        /// that sits visually above, and covers, all of the text in your custom
396        /// text view. If you don’t assign a value to this property, the coordinator
397        /// places its own effect view in front of the subviews in your custom view.
398        /// The default value of this property is `nil`.
399        ///
400        /// If you display your view’s text using multiple text containers, implement the
401        /// ``NSWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:singleContainerSubrangesOf:in:)``
402        /// method to request multiple previews.
403        #[unsafe(method(effectContainerView))]
404        #[unsafe(method_family = none)]
405        pub unsafe fn effectContainerView(&self) -> Option<Retained<NSView>>;
406
407        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
408        /// This is a [weak property][objc2::topics::weak_property].
409        /// Setter for [`effectContainerView`][Self::effectContainerView].
410        #[unsafe(method(setEffectContainerView:))]
411        #[unsafe(method_family = none)]
412        pub unsafe fn setEffectContainerView(&self, effect_container_view: Option<&NSView>);
413
414        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
415        /// The view that Writing Tools uses to display background decorations
416        /// such as proofreading marks.
417        ///
418        /// Writing Tools uses the view in this property to host proofreading marks
419        /// and other visual elements that show any suggested changes. Set this
420        /// property to a subview situated visibly below the text in your custom
421        /// text view. It's also satisfactory to place this view visually in front
422        /// of the text. Make sure the size of the view is big enough to
423        /// cover all of the affected text. If you don’t assign a value to this
424        /// property, the coordinator places its own decoration view behind the subviews
425        /// in your custom view. The default value of this property is `nil`.
426        ///
427        /// If you display your view’s text using multiple text containers, implement the
428        /// ``NSWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:singleContainerSubrangesOf:in:)``
429        /// and ``NSWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:decorationContainerViewFor:in:)``
430        /// methods to provide separate decoration views for each container.
431        #[unsafe(method(decorationContainerView))]
432        #[unsafe(method_family = none)]
433        pub unsafe fn decorationContainerView(&self) -> Option<Retained<NSView>>;
434
435        #[cfg(all(feature = "NSResponder", feature = "NSView"))]
436        /// This is a [weak property][objc2::topics::weak_property].
437        /// Setter for [`decorationContainerView`][Self::decorationContainerView].
438        #[unsafe(method(setDecorationContainerView:))]
439        #[unsafe(method_family = none)]
440        pub unsafe fn setDecorationContainerView(&self, decoration_container_view: Option<&NSView>);
441
442        /// The current level of Writing Tools activity in your view.
443        ///
444        /// Use this property to determine when Writing Tools is actively making
445        /// changes to your view. During the course of Writing Tools interactions,
446        /// the system reports state changes to the delegate’s
447        /// ``NSWritingToolsCoordinator/Delegate/writingToolsCoordinator(_:willChangeTo:completion:)``
448        /// method and updates this property accordingly.
449        #[unsafe(method(state))]
450        #[unsafe(method_family = none)]
451        pub unsafe fn state(&self) -> NSWritingToolsCoordinatorState;
452
453        /// Stops the current Writing Tools operation and dismisses the system UI.
454        ///
455        /// Call this method to abort the current Writing Tools operation. This
456        /// method dismisses the system’s Writing Tools UI and stops any in-flight
457        /// interactions with your view. This method does not undo any changes that
458        /// Writing Tools already made to your view’s content.
459        #[unsafe(method(stopWritingTools))]
460        #[unsafe(method_family = none)]
461        pub unsafe fn stopWritingTools(&self);
462
463        #[cfg(feature = "NSTextCheckingClient")]
464        /// The level of Writing Tools support you want the system to provide
465        /// for your view.
466        ///
467        /// Use this property to request an inline or panel-based experience,
468        /// or to disable Writing Tools for your view altogether. The default
469        /// value of this property is ``NSWritingToolsBehavior/default``.
470        #[unsafe(method(preferredBehavior))]
471        #[unsafe(method_family = none)]
472        pub unsafe fn preferredBehavior(&self) -> NSWritingToolsBehavior;
473
474        #[cfg(feature = "NSTextCheckingClient")]
475        /// Setter for [`preferredBehavior`][Self::preferredBehavior].
476        #[unsafe(method(setPreferredBehavior:))]
477        #[unsafe(method_family = none)]
478        pub unsafe fn setPreferredBehavior(&self, preferred_behavior: NSWritingToolsBehavior);
479
480        #[cfg(feature = "NSTextCheckingClient")]
481        /// The actual level of Writing Tools support the system provides for your view.
482        ///
483        /// The system chooses this value based on the device capabilities, and takes
484        /// the value in the ``preferredBehavior`` property into consideration when
485        /// making the choice. The value in this property is never the default option,
486        /// and is instead one of the specific options such as ``NSWritingToolsBehavior/none``,
487        /// ``NSWritingToolsBehavior/limited``, or ``NSWritingToolsBehavior/complete``.
488        #[unsafe(method(behavior))]
489        #[unsafe(method_family = none)]
490        pub unsafe fn behavior(&self) -> NSWritingToolsBehavior;
491
492        #[cfg(feature = "NSTextCheckingClient")]
493        /// The type of content you allow Writing Tools to generate for your custom
494        /// text view.
495        ///
496        /// Writing Tools can create plain text or rich text, and it can format text
497        /// using lists or tables as needed. If your view doesn’t support specific
498        /// types of content, specify the types you do support in this property.
499        /// The default value of this property is ``NSWritingToolsResult/default``,
500        /// which lets the system determine the type of content to generate.
501        #[unsafe(method(preferredResultOptions))]
502        #[unsafe(method_family = none)]
503        pub unsafe fn preferredResultOptions(&self) -> NSWritingToolsResultOptions;
504
505        #[cfg(feature = "NSTextCheckingClient")]
506        /// Setter for [`preferredResultOptions`][Self::preferredResultOptions].
507        #[unsafe(method(setPreferredResultOptions:))]
508        #[unsafe(method_family = none)]
509        pub unsafe fn setPreferredResultOptions(
510            &self,
511            preferred_result_options: NSWritingToolsResultOptions,
512        );
513
514        #[cfg(feature = "NSTextCheckingClient")]
515        /// The type of content the system generates for your custom text view.
516        ///
517        /// This property contains the set of options that Writing Tools outputs
518        /// for your view. Writing Tools takes the value in the
519        /// ``NSWritingToolsCoordinator/preferredResultOptions`` property into
520        /// consideration when determining this value.
521        #[unsafe(method(resultOptions))]
522        #[unsafe(method_family = none)]
523        pub unsafe fn resultOptions(&self) -> NSWritingToolsResultOptions;
524
525        /// Informs the coordinator about changes your app made to the text
526        /// in the specified context object.
527        ///
528        /// - Parameters:
529        /// - range: The range of text to replace. This range is relative to
530        /// the starting location of the specified context object’s text in
531        /// your view’s text storage. If you initialized the context object
532        /// with the entire contents of your view’s text storage, specify the
533        /// range of text you’re replacing in your text storage. However, if
534        /// you initialized the context object with only a portion of your
535        /// view’s text, specify a range that is relative to the starting
536        /// location of the context object’s text.
537        /// - replacementText: The text that replaces the previous content in
538        /// `range`. Specify an empty string to delete the text in the specified range.
539        /// - reason: The reason you updated the text.
540        /// - contextID: The unique identifier of the context object that
541        /// contains the text you modified.
542        ///
543        /// If you make any changes to the text Writing Tools is evaluating, call
544        /// this method to report those changes to your view’s coordinator object.
545        /// You might make changes in response to an undo command or when someone
546        /// types into the same part of your view’s text. Calling this method
547        /// keeps the coordinator object informed of any changes, and ensures
548        /// it delivers accurate information to its delegate. In response, the
549        /// coordinator refreshes previews and other information related to your
550        /// view. If the scope of the update is significantly large, the coordinator
551        /// can optionally cancel the Writing Tools session altogether.
552        ///
553        /// Use this method to report changes that precisely intersect your context
554        /// object’s text. The first time you call this method for a context object,
555        /// report changes only to the original attributed string in that object.
556        /// If you call this method more than once, report changes to the newly
557        /// modified version of that string. Don’t use this method to report changes
558        /// to text that comes before or after the context object. If you make
559        /// changes before your context object, report those changes separately using the
560        /// ``updateForReflowedTextInContextWithIdentifier(_:)`` method.
561        ///
562        /// > Warning: Failure to call this method for a change can cause Writing Tools
563        /// to deliver inaccurate information to your delegate and lead to data loss.
564        #[unsafe(method(updateRange:withText:reason:forContextWithIdentifier:))]
565        #[unsafe(method_family = none)]
566        pub unsafe fn updateRange_withText_reason_forContextWithIdentifier(
567            &self,
568            range: NSRange,
569            replacement_text: &NSAttributedString,
570            reason: NSWritingToolsCoordinatorTextUpdateReason,
571            context_id: &NSUUID,
572        );
573
574        /// Informs the coordinator that a change occurred to the view or its text
575        /// that requires a layout update.
576        ///
577        /// - Parameters:
578        /// - contextID: The unique identifier of the context object affected
579        /// by the change. Pass the identifier for the context object that comes
580        /// after the changes.
581        ///
582        /// Use this method to inform Writing Tools when the geometry of your view
583        /// changes, or when the text that precedes one of your context objects changes.
584        /// Changes to the view’s geometry or text can affect the flow of any remaining
585        /// text, and require a layout update. Writing Tools uses this method to
586        /// refresh any layout-dependent information it’s currently tracking. For
587        /// example, it uses it to refresh the location of proofreading marks it’s
588        /// displaying in your view.
589        ///
590        /// If a text change affects the text inside a context object, call the
591        /// ``updateRange(_:with:reason:forContextWithIdentifier:)`` method to report
592        /// that change instead.
593        #[unsafe(method(updateForReflowedTextInContextWithIdentifier:))]
594        #[unsafe(method_family = none)]
595        pub unsafe fn updateForReflowedTextInContextWithIdentifier(&self, context_id: &NSUUID);
596    );
597}
598
599/// Methods declared on superclass `NSObject`.
600impl NSWritingToolsCoordinator {
601    extern_methods!(
602        #[unsafe(method(init))]
603        #[unsafe(method_family = init)]
604        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
605
606        #[unsafe(method(new))]
607        #[unsafe(method_family = new)]
608        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
609    );
610}
611
612extern_protocol!(
613    /// An interface that you use to manage interactions between Writing Tools
614    /// and your custom text view.
615    ///
616    /// Adopt the `NSWritingToolsCoordinator.Delegate` protocol in the type you
617    /// use to manage your custom text view. When you add a ``NSWritingToolsCoordinator``
618    /// object to your view, the coordinator uses this protocol to communicate
619    /// with that view. The protocol lets Writing Tools fetch your view’s text,
620    /// report suggested changes back to your view, and deliver visual feedback
621    /// when Writing Tools features are active. Make sure the type that adopts
622    /// this protocol has access to your view’s text storage and can perform
623    /// relevant tasks on behalf of the view.
624    ///
625    /// Writing Tools expects you to call the provided handler blocks at the end
626    /// of your delegate methods. It’s crucial that you execute these blocks in a
627    /// timely manner to allow Writing Tools to perform subsequent tasks. For example,
628    /// Writing Tools waits for you to execute the handlers for animation-related methods
629    /// before moving on to the next stage of the animations.
630    ///
631    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nswritingtoolscoordinatordelegate?language=objc)
632    pub unsafe trait NSWritingToolsCoordinatorDelegate: NSObjectProtocol {
633        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
634        /// Asks your delegate to provide the text to evaluate during the Writing Tools
635        /// operation.
636        ///
637        /// - Parameters:
638        /// - writingToolsCoordinator: The coordinator object requesting information
639        /// from your custom view.
640        /// - scope: The amount of text the coordinator requested. Use this property
641        /// to determine if Writing Tools is evaluating all of your text or only a subset.
642        /// - completion: A completion block to execute with the required information.
643        /// You must execute this block once at end of your method's implementation.
644        /// The block has no return value and takes an array of
645        /// ``NSWritingToolsCoordinator/Context`` objects that contain the requested information.
646        ///
647        /// At the start of every operation, the ``NSWritingToolsCoordinator`` object calls
648        /// this method to request the text to evaluate. Use this method to create one or
649        /// more ``NSWritingToolsCoordinator/Context`` objects with your view’s text.
650        /// Create only one ``NSWritingToolsCoordinator/Context`` object if your view has
651        /// only one text storage object. If your view contains multiple text storage objects,
652        /// create separate ``NSWritingToolsCoordinator/Context`` objects for each
653        /// text storage object. Writing Tools returns updates for each context object
654        /// separately, making it easier for you to incorporate changes into the correct
655        /// text storage object. Don’t create multiple context objects if your view has
656        /// only one text storage object.
657        ///
658        /// The `scope` parameter tells you what content Writing Tools expects you to provide
659        /// in your context object. For example, Writing Tools expects you to provide the
660        /// selected text when the parameter contains the ``NSWritingToolsCoordinator/ContextScope/userSelection``
661        /// option. When Writing Tools requests a subset of your overall text, include
662        /// some of the surrounding text in your context object too. Writing Tools can
663        /// use the extra text you provide to improve the results of its evaluation. For
664        /// example, it might use an entire paragraph, instead of only the selected sentence,
665        /// to evaluate ways to rewrite that sentence. It’s best to include the text up
666        /// to the nearest paragraph boundary before and after the selection. If you
667        /// include extra text in your context object, set the ``NSWritingToolsCoordinator/Context/range``
668        /// property to the range of the selected text.
669        ///
670        /// > Note: When a context object stores only a subset of your view’s text, record
671        /// additional information to map the location of that text to the correct location
672        /// in your view’s text storage. Keep that information up-to-date throughout the
673        /// Writing Tools session.
674        ///
675        /// Pass the context objects you create to the provided completion handler before
676        /// your method returns. Writing Tools waits for you to call the completion
677        /// handler before proceeding with the operation.
678        #[unsafe(method(writingToolsCoordinator:requestsContextsForScope:completion:))]
679        #[unsafe(method_family = none)]
680        unsafe fn writingToolsCoordinator_requestsContextsForScope_completion(
681            &self,
682            writing_tools_coordinator: &NSWritingToolsCoordinator,
683            scope: NSWritingToolsCoordinatorContextScope,
684            completion: &block2::Block<dyn Fn(NonNull<NSArray<NSWritingToolsCoordinatorContext>>)>,
685        );
686
687        #[cfg(all(
688            feature = "NSWritingToolsCoordinatorAnimationParameters",
689            feature = "NSWritingToolsCoordinatorContext",
690            feature = "block2"
691        ))]
692        /// Tells the delegate that there are text changes to incorporate into the view.
693        ///
694        /// - Parameters:
695        /// - writingToolsCoordinator: The coordinator object providing the changes
696        /// to your custom view.
697        /// - range: A range of text to update. This range is relative to the text
698        /// in your context object, and it’s your responsibility to match that location
699        /// to the correct location in your text storage. If you initialized the
700        /// context object with the entire contents of your view’s text storage,
701        /// you can use `range` as-is to access that text storage. However, if you
702        /// initialized the context object with only a portion of your view’s text,
703        /// add the starting location of your context object’s text to this value
704        /// to get the correct range for that text storage.
705        /// - context: The context object that contains the original text to modify.
706        /// Use this object to locate the correct text storage object for your view.
707        /// - replacementText: The text to insert in place of the current text at `range`.
708        /// You can insert this text as-is, insert a modified version of this string,
709        /// or reject the replacement text altogether.
710        /// - reason: The type of replacement Writing Tools performs. This parameter
711        /// indicates whether Writing Tools is replacing the text with or without animations.
712        /// - animationParameters: The animation parameters for any interactive changes,
713        /// or `nil` if the changes aren’t interactive. Use this object to create any
714        /// additional animations for the system to run alongside the changes Writing Tools
715        /// makes. For example, use it to update other views that contain related information.
716        /// - completion: A completion handler to execute with the results of the operation.
717        /// The handler has no return value and takes an optional attributed string as
718        /// a parameter. If you incorporate the replacement text, either as-is or with
719        /// modifications, pass the actual string you incorporated to the completion
720        /// block. If you reject the suggested change and leave the original text
721        /// unchanged, specify `nil` for this parameter.
722        ///
723        /// Use this method to update your view’s text storage with the proposed changes.
724        /// Writing Tools can call this method multiple times during the course of a
725        /// session to notify you of changes to different ranges of text. Incorporate
726        /// the changes into your view’s text storage and notify your layout manager
727        /// so it can refresh the view.
728        ///
729        /// > Important: When integrating changes, remember to update `range.location` as needed
730        /// to get the correct location in your view’s text storage.
731        ///
732        /// Remove the text in the appropriate range of your text storage, and replace
733        /// it with the contents of `replacementText`. When you finish, call the completion
734        /// handler and pass in the replacement text you inserted. If you change the
735        /// string in `replacementText` before incorporating it into your text storage,
736        /// return your modified string instead. Returning the string lets Writing Tools
737        /// track any alterations you made to it. You can also pass `nil` to the
738        /// completion handler if you don’t incorporate the replacement text.
739        ///
740        /// For interactive changes, Writing Tools works with your delegate to animate
741        /// the removal of the old text and the insertion of any replacement text. If
742        /// you need to modify other parts of your interface to reflect the changes,
743        /// use the provided ``NSWritingToolsCoordinator/AnimationParameters`` object
744        /// to create additional animations to run at the same time as the system-provided animations.
745        #[unsafe(method(writingToolsCoordinator:replaceRange:inContext:proposedText:reason:animationParameters:completion:))]
746        #[unsafe(method_family = none)]
747        unsafe fn writingToolsCoordinator_replaceRange_inContext_proposedText_reason_animationParameters_completion(
748            &self,
749            writing_tools_coordinator: &NSWritingToolsCoordinator,
750            range: NSRange,
751            context: &NSWritingToolsCoordinatorContext,
752            replacement_text: &NSAttributedString,
753            reason: NSWritingToolsCoordinatorTextReplacementReason,
754            animation_parameters: Option<&NSWritingToolsCoordinatorAnimationParameters>,
755            completion: &block2::Block<dyn Fn(*mut NSAttributedString)>,
756        );
757
758        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
759        /// Asks the delegate to update your view’s current text selection.
760        ///
761        /// - Parameters:
762        /// - writingToolsCoordinator: The coordinator object making the change
763        /// to your view.
764        /// - ranges: One or more ranges of text to select. Each range is relative
765        /// to the text in your context object, and it’s your responsibility to
766        /// match each location to the correct location in your text storage. If
767        /// you initialized the context object with the entire contents of your
768        /// view’s text storage, you can use the ranges as-is to access that text
769        /// storage. However, if you initialized the context object with only a
770        /// portion of your view’s text, add the starting location of your context
771        /// object’s text to each value to get the correct range for that text storage.
772        /// - context: The context object you use to identify the associated text storage.
773        /// - completion: The completion handler to execute when your delegate finishes updating
774        /// the selection. The handler has no parameters or return value. You must
775        /// call this handler at some point during the implementation of your method.
776        ///
777        /// As Writing Tools suggests changes to your view’s text, it calls this method
778        /// to update the text selection accordingly. Use this method to update the
779        /// current selection in your view’s text storage. When you finish making the
780        /// changes, call the provided completion block to let Writing Tools know you’re finished.
781        #[unsafe(method(writingToolsCoordinator:selectRanges:inContext:completion:))]
782        #[unsafe(method_family = none)]
783        unsafe fn writingToolsCoordinator_selectRanges_inContext_completion(
784            &self,
785            writing_tools_coordinator: &NSWritingToolsCoordinator,
786            ranges: &NSArray<NSValue>,
787            context: &NSWritingToolsCoordinatorContext,
788            completion: &block2::Block<dyn Fn()>,
789        );
790
791        #[cfg(feature = "block2")]
792        /// Asks the delegate to provide the location of the character at the
793        /// specified point in your view’s coordinate system.
794        ///
795        /// - Parameters:
796        /// - writingToolsCoordinator: The coordinator object requesting
797        /// information from your custom view.
798        /// - point: A point in your view’s coordinate space. Find the
799        /// location of the text under this point, if any.
800        /// - completion: A handler to execute with the required information.
801        /// This handler has no return value and takes an
802        /// <doc
803        /// ://com.apple.documentation/documentation/foundation/nsrange>
804        /// and
805        /// <doc
806        /// ://com.apple.documentation/documentation/foundation/uuid>
807        /// as parameters. Set the range to the character’s location in one of your
808        /// ``NSWritingToolsCoordinator/Context`` objects, which you specify using
809        /// the
810        /// <doc
811        /// ://com.apple.documentation/documentation/foundation/uuid> parameter.
812        /// You must call this handler at some point during your method’s implementation.
813        ///
814        /// When someone interacts with your view during a proofreading operation, Writing Tools
815        /// calls this method to get the location of the interaction. If the interaction
816        /// occurs in the text of one of your ``NSWritingToolsCoordinator/Context`` objects,
817        /// configure an
818        /// <doc
819        /// ://com.apple.documentation/documentation/foundation/nsrange>
820        /// with the character’s location in that context object and a length of `1`. If
821        /// the interaction occurs outside of the text of your context objects, configure
822        /// the range with a location of `NSNotFound`.
823        ///
824        /// When specifying the location of a character in your context object, provide a
825        /// location relative to the start of your context object’s text. The first character
826        /// in a context object’s text is always at location `0`, and it’s your responsibility
827        /// to track the location of the context object’s text in your text storage object.
828        /// When the context object’s text begins in the middle of your text storage,
829        /// subtract the starting location of the context object’s text from the location
830        /// you specify in your range value. For example, if the context object’s text
831        /// starts at character `100` in your text storage, and an interaction occurs
832        /// with the character at location `102`, specify a range with a location of
833        /// `2` and a length of `1`.
834        #[unsafe(method(writingToolsCoordinator:requestsRangeInContextWithIdentifierForPoint:completion:))]
835        #[unsafe(method_family = none)]
836        unsafe fn writingToolsCoordinator_requestsRangeInContextWithIdentifierForPoint_completion(
837            &self,
838            writing_tools_coordinator: &NSWritingToolsCoordinator,
839            point: NSPoint,
840            completion: &block2::Block<dyn Fn(NSRange, NonNull<NSUUID>)>,
841        );
842
843        #[cfg(all(
844            feature = "NSBezierPath",
845            feature = "NSWritingToolsCoordinatorContext",
846            feature = "block2"
847        ))]
848        /// Asks the delegate to provide the bounding paths for the specified
849        /// text in your view.
850        ///
851        /// - Parameters:
852        /// - writingToolsCoordinator: The coordinator object requesting information
853        /// from your custom view.
854        /// - range: The range of text to evaluate. This range is relative to the
855        /// text in your context object, and it’s your responsibility to match that
856        /// location to the correct location in your text storage. If you initialized
857        /// the context object with the entire contents of your view’s text storage,
858        /// you can use `range` as-is to access that text storage. However, if you
859        /// initialized the context object with only a portion of your view’s text,
860        /// add the starting location of your context object’s text to this value to
861        /// get the correct range for that text storage.
862        /// - context: The context object with the target text. Use this object to
863        /// find the text in your view’s text storage.
864        /// - completion: A handler to execute with the required information. The
865        /// handler has no return value and takes an array of Bezier paths as a
866        /// parameter. You must call this handler at some point during your method’s implementation.
867        ///
868        /// After applying proofreading marks to your view’s text, Writing Tools lets
869        /// the person accept or reject individual suggestions. To facilitate interactions,
870        /// the coordinator asks your delegate to provide one or more Bezier paths that
871        /// surround those proofreading suggestions. For each distinct range of text
872        /// with a suggestion, it calls this method to get the Bezier paths that surround
873        /// the corresponding text.
874        ///
875        /// After you determine the location of the specified range of text in your view’s
876        /// text storage, find the rectangle around that text. If you're using TextKit, call the
877        /// <doc
878        /// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager/3809995-enumeratetextsegments>
879        /// method of your view’s
880        /// <doc
881        /// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager>
882        /// to compute the selection rectangles for that text. That method finds the text
883        /// segments that contain the text and returns the frame rectangle for each one.
884        /// Create a Bezier path for each rectangle, and convert the coordinates of each path
885        /// to the coordinate space of the view in your coordinator's ``NSWritingToolsCoordinator/decorationContainerView``
886        /// property. Pass the resulting paths to the completion handler.
887        #[unsafe(method(writingToolsCoordinator:requestsBoundingBezierPathsForRange:inContext:completion:))]
888        #[unsafe(method_family = none)]
889        unsafe fn writingToolsCoordinator_requestsBoundingBezierPathsForRange_inContext_completion(
890            &self,
891            writing_tools_coordinator: &NSWritingToolsCoordinator,
892            range: NSRange,
893            context: &NSWritingToolsCoordinatorContext,
894            completion: &block2::Block<dyn Fn(NonNull<NSArray<NSBezierPath>>)>,
895        );
896
897        #[cfg(all(
898            feature = "NSBezierPath",
899            feature = "NSWritingToolsCoordinatorContext",
900            feature = "block2"
901        ))]
902        /// Asks the delegate to provide an underline shape for the specified text
903        /// during a proofreading session.
904        ///
905        /// - Parameters:
906        /// - writingToolsCoordinator: The coordinator object requesting information
907        /// from your custom view.
908        /// - range: The range of text to evaluate. This range is relative to the
909        /// text in your context object, and it’s your responsibility to match that
910        /// location to the correct location in your text storage. If you initialized
911        /// the context object with the entire contents of your view’s text storage,
912        /// you can use `range` as-is to access that text storage. However, if you
913        /// initialized the context object with only a portion of your view’s text,
914        /// add the starting location of your context object’s text to this value
915        /// to get the correct range for that text storage.
916        /// - context: The context object with the target text. Use this object to
917        /// find the text in your view’s text storage.
918        /// - completion: A handler to execute with the required information. The
919        /// handler has no return value and takes an array of Bezier paths as a
920        /// parameter. You must call this handler at some point during your method’s implementation.
921        ///
922        /// When applying proofreading marks to your view’s content, the coordinator
923        /// calls this method to retrieve a shape to draw under the specified text.
924        /// You provide the shape using one or more Bezier paths, and the coordinator
925        /// draws and animates that shape during the proofreading session.
926        ///
927        /// After you determine the location of the specified range of text in your
928        /// view’s text storage, find the rectangle around that text. If you're using
929        /// TextKit, you can call the
930        /// <doc
931        /// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager/3809995-enumeratetextsegments>
932        /// method of your view’s
933        /// <doc
934        /// ://com.apple.documentation/documentation/uikit/nstextlayoutmanager>
935        /// to get the rectangles for a range of text. Convert the coordinates of each rectangle
936        /// to the coordinate space of the view in your coordinator's ``NSWritingToolsCoordinator/decorationContainerView``
937        /// property. Use those rectangles to create the Bezier paths for your text.
938        /// For example, you might create a path with a straight or wavy line at the
939        /// bottom of the rectangle.
940        #[unsafe(method(writingToolsCoordinator:requestsUnderlinePathsForRange:inContext:completion:))]
941        #[unsafe(method_family = none)]
942        unsafe fn writingToolsCoordinator_requestsUnderlinePathsForRange_inContext_completion(
943            &self,
944            writing_tools_coordinator: &NSWritingToolsCoordinator,
945            range: NSRange,
946            context: &NSWritingToolsCoordinatorContext,
947            completion: &block2::Block<dyn Fn(NonNull<NSArray<NSBezierPath>>)>,
948        );
949
950        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
951        /// Prepare for animations for the content that Writing Tools is evaluating.
952        ///
953        /// - Parameters:
954        /// - writingToolsCoordinator: The coordinator object notifying you that
955        /// animations are about to begin.
956        /// - textAnimation: The type of animation Writing Tools is preparing.
957        /// - range: The range of text affected by the animation. This range is
958        /// relative to the text in your context object, and it’s your responsibility
959        /// to match that location to the correct location in your text storage.
960        /// If you initialized the context object with the entire contents of your
961        /// view’s text storage, you can use `range` as-is to access that text
962        /// storage. However, if you initialized the context object with only a portion
963        /// of your view’s text, add the starting location of your context object’s
964        /// text to this value to get the correct range for that text storage.
965        /// - context: The context object that contains the original text. Use this
966        /// object to fetch the current text, and to match that text to your underlying
967        /// text storage.
968        /// - completion: A completion handler to execute when you are done. The handler
969        /// has no return value and takes no parameters. You must call this handler
970        /// at some point during your implementation.
971        ///
972        /// During an interactive evaluation of your view’s text, Writing Tools creates
973        /// different animations to provide feedback on what’s happening. For example, it
974        /// creates an ``NSWritingToolsCoordinator/TextAnimation/anticipate`` animation to
975        /// let people know the system is evaluating the text. The `textAnimation` parameter
976        /// tells you what type of animation to prepare for.
977        ///
978        /// Use this method to prepare for the system-provided animations of your view’s
979        /// content. For interactive animations, hide the text in the specified range temporarily
980        /// while the system animations run. For non-interactive animations, dim the text
981        /// for the duration of the animation to indicate it’s not editable. For animations
982        /// to remove or insert text, you can also use this method to set up animations
983        /// to reflow your view’s content to match the changes. At the end of a given animation,
984        /// use your delegate’s ``writingToolsCoordinator(_:finish:for:in:completion:)``
985        /// method to undo any changes you make to your content.
986        ///
987        /// For a single animation type, the system calls this method, followed sequentially
988        /// by the ``writingToolsCoordinator(_:previewFor:range:context:completion:)``
989        /// and ``writingToolsCoordinator(_:finish:for:in:completion:)``
990        /// methods. Each method executes asynchronously, but the system calls the next
991        /// method in the sequence only after you call the completion handler of the previous
992        /// method. However, multiple animations can run simultaneously, so check the
993        /// `textAnimation` and `range` parameters to differentiate sequences.
994        #[unsafe(method(writingToolsCoordinator:prepareForTextAnimation:forRange:inContext:completion:))]
995        #[unsafe(method_family = none)]
996        unsafe fn writingToolsCoordinator_prepareForTextAnimation_forRange_inContext_completion(
997            &self,
998            writing_tools_coordinator: &NSWritingToolsCoordinator,
999            text_animation: NSWritingToolsCoordinatorTextAnimation,
1000            range: NSRange,
1001            context: &NSWritingToolsCoordinatorContext,
1002            completion: &block2::Block<dyn Fn()>,
1003        );
1004
1005        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
1006        /// Asks the delegate for a preview image and layout information for the
1007        /// specified text.
1008        ///
1009        /// - Parameters:
1010        /// - writingToolsCoordinator: The coordinator object notifying you that
1011        /// animations are about to begin.
1012        /// - textAnimation: The type of animation Writing Tools is preparing.
1013        /// - range: The range of text that requires a preview image. This range
1014        /// is relative to the text in your context object, and it’s your responsibility
1015        /// to match that location to the correct location in your text storage.
1016        /// If you initialized the context object with the entire contents of
1017        /// your view’s text storage, you can use `range` as-is to access that
1018        /// text storage. However, if you initialized the context object with only
1019        /// a portion of your view’s text, add the starting location of your
1020        /// context object’s text to this value to get the correct range for that
1021        /// text storage.
1022        /// - context: The context object that contains the original text. Use this
1023        /// object to fetch the current text, and to match that text to your
1024        /// underlying text storage.
1025        /// - completion: A completion handler to execute when you are done. The
1026        /// handler has no return value and takes an ``NSTextPreview`` object
1027        /// as a parameter. You must call this handler at some point during your implementation.
1028        ///
1029        /// During an interactive evaluation of your view’s text, Writing Tools creates
1030        /// different animations to provide feedback on what’s happening. As part of
1031        /// the preparation for those animations, Writing Tools asks you to provide
1032        /// a preview of the affected content in your view. Writing Tools uses this
1033        /// preview to build and execute the animations in the view stored in the
1034        /// ``NSWritingToolsCoordinator/effectContainerView`` property of the coordinator object.
1035        ///
1036        /// To build a preview of your content in macOS, render the specified range of text
1037        /// into an image with a transparent background and use that image to create your
1038        /// ``NSTextPreview`` object directly. Set the ``NSTextPreview/presentationFrame``
1039        /// property to the rectangle in your view’s coordinate space that contains the
1040        /// text you captured. Set the ``NSTextPreview/candidateRects`` property to the
1041        /// selection rectangles for the text, which you get from your view’s layout manager.
1042        /// Writing Tools uses this information to place your image directly above the text in your view.
1043        ///
1044        /// For a single animation type, the system calls the
1045        /// ``writingToolsCoordinator(_:prepareFor:range:context:completion:)``
1046        /// method, followed sequentially by this method and then the
1047        /// ``writingToolsCoordinator(_:finish:for:in:completion:)``
1048        /// method. Each method executes asynchronously, but the system calls the next
1049        /// method in the sequence only after you call the completion handler of the
1050        /// previous method. However, multiple animations can run simultaneously, so
1051        /// check the `textAnimation` parameter to differentiate sequences.
1052        #[unsafe(method(writingToolsCoordinator:requestsPreviewForTextAnimation:ofRange:inContext:completion:))]
1053        #[unsafe(method_family = none)]
1054        unsafe fn writingToolsCoordinator_requestsPreviewForTextAnimation_ofRange_inContext_completion(
1055            &self,
1056            writing_tools_coordinator: &NSWritingToolsCoordinator,
1057            text_animation: NSWritingToolsCoordinatorTextAnimation,
1058            range: NSRange,
1059            context: &NSWritingToolsCoordinatorContext,
1060            completion: &block2::Block<dyn Fn(*mut NSArray<NSTextPreview>)>,
1061        );
1062
1063        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
1064        /// Asks the delegate for a preview image and layout information for the
1065        /// specified text.
1066        ///
1067        /// - Parameters:
1068        /// - writingToolsCoordinator: The coordinator object notifying you that
1069        /// animations are about to begin.
1070        /// - rect: The portion of your view that contains the requested text. This rectangle is in the view’s coordinate system.
1071        /// - context: The context object that contains the original text. Use this
1072        /// object to fetch the current text, and to match that text to your
1073        /// underlying text storage.
1074        /// - completion: A completion handler to execute when you are done. The
1075        /// handler has no return value and takes an ``NSTextPreview`` object
1076        /// as a parameter. You must call this handler at some point during your implementation.
1077        ///
1078        /// During an interactive evaluation of your view’s text, Writing Tools creates
1079        /// different animations to provide feedback on what’s happening. As part of
1080        /// the preparation for those animations, Writing Tools asks you to provide
1081        /// a preview of the affected content in your view. Writing Tools uses this
1082        /// preview to build and execute the animations in the view stored in the
1083        /// ``NSWritingToolsCoordinator/effectContainerView`` property of the coordinator object.
1084        ///
1085        /// To build a preview of your content in macOS, render the requested portion
1086        /// of your view into an image with a transparent background and use that image
1087        /// to create your ``NSTextPreview`` object directly. Set the ``NSTextPreview/presentationFrame``
1088        /// property to the specified rectangle. Set the ``NSTextPreview/candidateRects``
1089        /// property to the selection rectangles for the associated text, which you get
1090        /// from your view’s layout manager. Writing Tools uses this information to
1091        /// place your image directly above the text in your view.
1092        ///
1093        /// For a single animation type, the system calls the
1094        /// ``writingToolsCoordinator(_:prepareFor:range:context:completion:)``
1095        /// method, followed sequentially by this method and then the
1096        /// ``writingToolsCoordinator(_:finish:for:in:completion:)``
1097        /// method. Each method executes asynchronously, but the system calls the next
1098        /// method in the sequence only after you call the completion handler of the
1099        /// previous method. However, multiple animations can run simultaneously, so
1100        /// check the `textAnimation` parameter to differentiate sequences.
1101        #[unsafe(method(writingToolsCoordinator:requestsPreviewForRect:inContext:completion:))]
1102        #[unsafe(method_family = none)]
1103        unsafe fn writingToolsCoordinator_requestsPreviewForRect_inContext_completion(
1104            &self,
1105            writing_tools_coordinator: &NSWritingToolsCoordinator,
1106            rect: NSRect,
1107            context: &NSWritingToolsCoordinatorContext,
1108            completion: &block2::Block<dyn Fn(*mut NSTextPreview)>,
1109        );
1110
1111        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
1112        /// Asks the delegate to clean up any state related to the specified
1113        /// Writing Tools animation.
1114        ///
1115        /// - Parameters:
1116        /// - writingToolsCoordinator: The coordinator object notifying you
1117        /// that animations are about to begin.
1118        /// - textAnimation: The type of animation Writing Tools finished.
1119        /// - range: The range of text that finished animating. This range is
1120        /// relative to the text in your context object, and it’s your responsibility
1121        /// to match that location to the correct location in your text storage.
1122        /// If you initialized the context object with the entire contents of
1123        /// your view’s text storage, you can use `range` as-is to access that
1124        /// text storage. However, if you initialized the context object with
1125        /// only a portion of your view’s text, add the starting location of
1126        /// your context object’s text to this value to get the correct range
1127        /// for that text storage.
1128        /// - context: The context object that contains the original text.
1129        /// - completion: A completion handler to execute when you are done.
1130        /// The handler has no return value and takes no parameters. You must
1131        /// call this handler at some point during your implementation.
1132        ///
1133        /// Use this method to clean up any data structures you created to support
1134        /// the specified type of Writing Tools animation. You can also use this
1135        /// method to restore the visibility of any text you hid previously. When
1136        /// you finish your cleanup work, call the completion handler to notify Writing Tools.
1137        ///
1138        /// Writing Tools calls this method only after previous calls to the
1139        /// ``writingToolsCoordinator(_:prepareFor:range:context:completion:)``
1140        /// and ``writingToolsCoordinator(_:previewFor:range:context:completion:)``
1141        /// methods for the same animation type. However, Writing Tools can interleave
1142        /// calls to this method with calls to prepare an animation of a different
1143        /// type. In your implementation of this method, make sure the actions you
1144        /// take don’t interfere with other in-flight animations.
1145        #[unsafe(method(writingToolsCoordinator:finishTextAnimation:forRange:inContext:completion:))]
1146        #[unsafe(method_family = none)]
1147        unsafe fn writingToolsCoordinator_finishTextAnimation_forRange_inContext_completion(
1148            &self,
1149            writing_tools_coordinator: &NSWritingToolsCoordinator,
1150            text_animation: NSWritingToolsCoordinatorTextAnimation,
1151            range: NSRange,
1152            context: &NSWritingToolsCoordinatorContext,
1153            completion: &block2::Block<dyn Fn()>,
1154        );
1155
1156        #[cfg(all(feature = "NSWritingToolsCoordinatorContext", feature = "block2"))]
1157        /// Asks the delegate to divide the specified range of text into the separate
1158        /// containers that render that text.
1159        ///
1160        /// - Parameters:
1161        /// - writingToolsCoordinator: The coordinator object requesting information
1162        /// from your custom view.
1163        /// - range: The range of text to consider in the specified `context` object.
1164        /// The location value of this range is relative to the beginning of the text
1165        /// in your context object, and it’s your responsibility to match that location
1166        /// to the correct location in your text storage. If you initialized the
1167        /// context object with the entire contents of your view’s text storage,
1168        /// you can use `range` as-is to access that text storage. However, if you
1169        /// initialized the context object with only a portion of your view’s text,
1170        /// add the starting location of your context object’s text to this value
1171        /// to get the correct range for that text storage.
1172        /// - context: The context object that contains the text to consider. Use this
1173        /// object to locate the appropriate text storage object for your view.
1174        /// - completion: A completion handler to execute when you are done. The handler
1175        /// has no return value and takes an array of
1176        /// <doc
1177        /// ://com.apple.documentation/documentation/foundation/nsvalue>
1178        /// types, each of which contains an
1179        /// <doc
1180        /// ://com.apple.documentation/documentation/foundation/nsrange>.
1181        /// The union of the ranges you pass to this handler must equal all of the
1182        /// text in `range`. The order of the ranges in the array must be sequential,
1183        /// with each new range's starting location coming after the previous one.
1184        /// There must also not be any gaps or overlap between ranges.
1185        /// You must call this handler at some point during your implementation.
1186        ///
1187        /// If your view uses multiple ``NSTextContainer`` objects to draw text in different
1188        /// regions, use this method to tell Writing Tools about the containers that display
1189        /// the specified text. In your implementation, subdivide `range` to create one new
1190        /// range for each portion of text that resides in a different container object.
1191        /// For example, if the text in `range` is split between two containers, provide
1192        /// two new
1193        /// <doc
1194        /// ://com.apple.documentation/documentation/foundation/nsrange> types
1195        /// that reflect the portion of the total text in each container. If `range` resides completely
1196        /// within one container, call the completion handler with `range` as the only value
1197        /// in the array.
1198        ///
1199        /// When configuring animations for your view, Writing Tools asks your delegate to
1200        /// provide separate previews for each of your view’s container object. Specifically,
1201        /// it calls your delegate’s ``writingToolsCoordinator(_:previewFor:range:context:completion:)``
1202        /// method separately for each range of text you return in the completion handler.
1203        /// Your implementation of that method must create a preview suitable for animating
1204        /// the content from the underlying text container.
1205        #[optional]
1206        #[unsafe(method(writingToolsCoordinator:requestsSingleContainerSubrangesOfRange:inContext:completion:))]
1207        #[unsafe(method_family = none)]
1208        unsafe fn writingToolsCoordinator_requestsSingleContainerSubrangesOfRange_inContext_completion(
1209            &self,
1210            writing_tools_coordinator: &NSWritingToolsCoordinator,
1211            range: NSRange,
1212            context: &NSWritingToolsCoordinatorContext,
1213            completion: &block2::Block<dyn Fn(NonNull<NSArray<NSValue>>)>,
1214        );
1215
1216        #[cfg(all(
1217            feature = "NSResponder",
1218            feature = "NSView",
1219            feature = "NSWritingToolsCoordinatorContext",
1220            feature = "block2"
1221        ))]
1222        /// Asks the delegate to provide a decoration view for the specified range of text.
1223        ///
1224        /// - Parameters:
1225        /// - writingToolsCoordinator: The coordinator object requesting information
1226        /// from your custom view.
1227        /// - range: The range of text to consider in the specified `context` object.
1228        /// The location value of this range is relative to the beginning of the text
1229        /// in your context object, and it’s your responsibility to match that location
1230        /// to the correct location in your text storage. If you initialized the
1231        /// context object with the entire contents of your view’s text storage, you
1232        /// can use `range` as-is to access that text storage. However, if you initialized
1233        /// the context object with only a portion of your view’s text, add the starting
1234        /// location of your context object’s text to this value to get the correct
1235        /// range for that text storage.
1236        /// - context: The context object that contains the text to consider. Use this
1237        /// object to locate the appropriate text storage object for your view.
1238        /// - completion: A completion handler to execute when you are done. The handler
1239        /// has no return value and takes an ``NSView`` object as a parameter. You must call
1240        /// this handler at some point during your implementation.
1241        ///
1242        /// If your view uses multiple ``NSTextContainer`` objects to draw text in different
1243        /// regions, use this method to provide Writing Tools with the view to use for the
1244        /// specified range of text. After calling your delegate’s ``writingToolsCoordinator(_:singleContainerSubrangesOf:in:)``
1245        /// method, Writing Tools calls this method for each subrange of text you provided.
1246        /// Find or provide a view situated visibly below the specified text in your text
1247        /// view. It's also satisfactory to provide a view that’s visually in front of the
1248        /// text. Writing Tools uses the provided view to host any proofreading marks for
1249        /// the specified range of text.
1250        ///
1251        /// If your view has only one text container, use the coordinator’s ``NSWritingToolsCoordinator/decorationContainerView``
1252        /// property to specify the view to use for proofreading marks.
1253        #[optional]
1254        #[unsafe(method(writingToolsCoordinator:requestsDecorationContainerViewForRange:inContext:completion:))]
1255        #[unsafe(method_family = none)]
1256        unsafe fn writingToolsCoordinator_requestsDecorationContainerViewForRange_inContext_completion(
1257            &self,
1258            writing_tools_coordinator: &NSWritingToolsCoordinator,
1259            range: NSRange,
1260            context: &NSWritingToolsCoordinatorContext,
1261            completion: &block2::Block<dyn Fn(NonNull<NSView>)>,
1262        );
1263
1264        #[cfg(feature = "block2")]
1265        /// Notifies your delegate of relevant state changes when Writing Tools
1266        /// is running in your view.
1267        ///
1268        /// - Parameters:
1269        /// - writingToolsCoordinator: The coordinator object providing
1270        /// information to your custom view.
1271        /// - state: The new state for the Writing Tools session. For information
1272        /// about the possible states, see ``NSWritingToolsCoordinator/State``.
1273        /// - text: The current text for your context object.
1274        /// - reason: The reason for the state change.
1275        /// - context: The context object that contains the original text for
1276        /// Writing Tools to evaluate.
1277        /// - completion: A handler to execute when your delegate finishes processing
1278        /// the change of state. The handler has no parameters or return value. You
1279        /// must call this handler at some point during the implementation of your method.
1280        ///
1281        /// Use state transitions to perform actions related to your view or text storage.
1282        /// When Writing Tools is active, it updates its state to indicate what task
1283        /// it’s currently performing. Writing Tools starts in the ``NSWritingToolsCoordinator/State/inactive``
1284        /// state and moves to other states as it presents UI and starts interacting with
1285        /// your view’s content. For example, it moves to the ``NSWritingToolsCoordinator/State/interactiveUpdating``
1286        /// state when it’s making changes to your view’s text storage.
1287        #[optional]
1288        #[unsafe(method(writingToolsCoordinator:willChangeToState:completion:))]
1289        #[unsafe(method_family = none)]
1290        unsafe fn writingToolsCoordinator_willChangeToState_completion(
1291            &self,
1292            writing_tools_coordinator: &NSWritingToolsCoordinator,
1293            new_state: NSWritingToolsCoordinatorState,
1294            completion: &block2::Block<dyn Fn()>,
1295        );
1296    }
1297);
1298
1299extern_class!(
1300    /// A snapshot of the text in your view, which the system uses to create
1301    /// user-visible effects.
1302    ///
1303    /// An `NSTextPreview` object provides a static image of your view’s text
1304    /// content that the system can use to create animations. You provide preview
1305    /// objects in response to system requests, such as ones from Writing Tools.
1306    /// In addition to creating an image of your view’s text, you also specify
1307    /// the location of that text in your view’s frame rectangle. When creating
1308    /// animations, the system places the image on top of your view’s content
1309    /// and animates changes to the image instead of to your view.
1310    ///
1311    /// Create an `NSTextPreview` object in response to specific system requests.
1312    /// Create an image with a transparent background and render your view’s text
1313    /// into the image using the current text attributes. Construct your `NSTextPreview`
1314    /// object with both the image and the frame rectangle that represents the
1315    /// location of the rendered text in your view’s coordinate system. To highlight
1316    /// specific portions of text, instead of all the text in the image, provide
1317    /// a set of candidate rectangles with the locations of the text you want to highlight.
1318    ///
1319    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextpreview?language=objc)
1320    #[unsafe(super(NSObject))]
1321    #[thread_kind = MainThreadOnly]
1322    #[derive(Debug, PartialEq, Eq, Hash)]
1323    pub struct NSTextPreview;
1324);
1325
1326unsafe impl NSObjectProtocol for NSTextPreview {}
1327
1328impl NSTextPreview {
1329    extern_methods!(
1330        #[cfg(feature = "objc2-core-graphics")]
1331        #[cfg(target_vendor = "apple")]
1332        /// Creates a text preview using the specified image and rectangles that indicate
1333        /// the portions of text to highlight.
1334        ///
1335        /// - Parameters:
1336        /// - snapshotImage: An image that contains the requested text from your view.
1337        /// Create the image using a transparent background and the current rendering
1338        /// attributes for your text.
1339        /// - presentationFrame: A rectangle in the coordinate space of your text view.
1340        /// The system uses this rectangle to place your image precisely over your
1341        /// view’s actual text. Set its size to the size of your snapshot image, and
1342        /// set its origin to the point that allows the system to place your image
1343        /// directly over the text.
1344        /// - candidateRects: An array of
1345        /// <doc
1346        /// ://com.apple.documentation/documentation/foundation/nsvalue>
1347        /// objects, each of which contains an
1348        /// <doc
1349        /// ://com.apple.documentation/documentation/foundation/nsrect>
1350        /// in the coordinate space of your text view. Each rectangle contains a
1351        /// bounding rectangle for text that is part of the preview. When applying
1352        /// visual effects, the system adds highlights only to the text in the specified rectangles.
1353        #[unsafe(method(initWithSnapshotImage:presentationFrame:candidateRects:))]
1354        #[unsafe(method_family = init)]
1355        pub unsafe fn initWithSnapshotImage_presentationFrame_candidateRects(
1356            this: Allocated<Self>,
1357            snapshot_image: &CGImage,
1358            presentation_frame: NSRect,
1359            candidate_rects: &NSArray<NSValue>,
1360        ) -> Retained<Self>;
1361
1362        #[cfg(feature = "objc2-core-graphics")]
1363        #[cfg(target_vendor = "apple")]
1364        /// Creates a text preview using the specified image.
1365        ///
1366        /// - Parameters:
1367        /// - snapshotImage: An image that contains the requested text from your view.
1368        /// Create the image using a transparent background and the current rendering
1369        /// attributes for your text.
1370        /// - presentationFrame: A rectangle in your frame’s coordinate space. The
1371        /// system uses this rectangle to place your image precisely over your view’s
1372        /// actual text. Set its size to the size of your snapshot image, and set its
1373        /// origin to the point that allows the system to place your image directly over the text.
1374        #[unsafe(method(initWithSnapshotImage:presentationFrame:))]
1375        #[unsafe(method_family = init)]
1376        pub unsafe fn initWithSnapshotImage_presentationFrame(
1377            this: Allocated<Self>,
1378            snapshot_image: &CGImage,
1379            presentation_frame: NSRect,
1380        ) -> Retained<Self>;
1381
1382        #[unsafe(method(init))]
1383        #[unsafe(method_family = init)]
1384        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
1385
1386        #[cfg(feature = "objc2-core-graphics")]
1387        #[cfg(target_vendor = "apple")]
1388        /// The image that contains the requested text from your view.
1389        ///
1390        /// You specify this image at initialization time. The system uses it to
1391        /// implement any visual effects involving your view’s text. Create the image
1392        /// with your text on a transparent background.
1393        #[unsafe(method(previewImage))]
1394        #[unsafe(method_family = none)]
1395        pub unsafe fn previewImage(&self) -> Retained<CGImage>;
1396
1397        /// The frame rectangle that places the preview image directly over the
1398        /// matching text.
1399        ///
1400        /// You specify this value at initialization time. The system uses it to
1401        /// position the preview image over the text in your view. Make sure the
1402        /// frame rectangle is in your view's coordinate space.
1403        #[unsafe(method(presentationFrame))]
1404        #[unsafe(method_family = none)]
1405        pub unsafe fn presentationFrame(&self) -> NSRect;
1406
1407        /// Rectangles that define the specific portions of text to highlight.
1408        ///
1409        /// At initialization time, you set this property to an array of
1410        /// <doc
1411        /// ://com.apple.documentation/documentation/foundation/nsvalue> objects,
1412        /// each of which contains an
1413        /// <doc
1414        /// ://com.apple.documentation/documentation/foundation/nsrect>
1415        /// in the coordinate space of the target view. Each rectangle contains a bounding
1416        /// rectangle for text that is part of the preview. When applying visual effects,
1417        /// the system adds highlights only to the text in the specified rectangles.
1418        #[unsafe(method(candidateRects))]
1419        #[unsafe(method_family = none)]
1420        pub unsafe fn candidateRects(&self) -> Retained<NSArray<NSValue>>;
1421    );
1422}
1423
1424/// Methods declared on superclass `NSObject`.
1425impl NSTextPreview {
1426    extern_methods!(
1427        #[unsafe(method(new))]
1428        #[unsafe(method_family = new)]
1429        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
1430    );
1431}