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