objc2_app_kit/generated/
NSTextLayoutManager.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-foundation")]
7use objc2_core_foundation::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextlayoutmanagersegmenttype?language=objc)
13// NS_ENUM
14#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct NSTextLayoutManagerSegmentType(pub NSInteger);
17impl NSTextLayoutManagerSegmentType {
18    #[doc(alias = "NSTextLayoutManagerSegmentTypeStandard")]
19    pub const Standard: Self = Self(0);
20    #[doc(alias = "NSTextLayoutManagerSegmentTypeSelection")]
21    pub const Selection: Self = Self(1);
22    #[doc(alias = "NSTextLayoutManagerSegmentTypeHighlight")]
23    pub const Highlight: Self = Self(2);
24}
25
26unsafe impl Encode for NSTextLayoutManagerSegmentType {
27    const ENCODING: Encoding = NSInteger::ENCODING;
28}
29
30unsafe impl RefEncode for NSTextLayoutManagerSegmentType {
31    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
32}
33
34/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextlayoutmanagersegmentoptions?language=objc)
35// NS_OPTIONS
36#[repr(transparent)]
37#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
38pub struct NSTextLayoutManagerSegmentOptions(pub NSUInteger);
39bitflags::bitflags! {
40    impl NSTextLayoutManagerSegmentOptions: NSUInteger {
41        #[doc(alias = "NSTextLayoutManagerSegmentOptionsNone")]
42        const None = 0;
43        #[doc(alias = "NSTextLayoutManagerSegmentOptionsRangeNotRequired")]
44        const RangeNotRequired = 1<<0;
45        #[doc(alias = "NSTextLayoutManagerSegmentOptionsMiddleFragmentsExcluded")]
46        const MiddleFragmentsExcluded = 1<<1;
47        #[doc(alias = "NSTextLayoutManagerSegmentOptionsHeadSegmentExtended")]
48        const HeadSegmentExtended = 1<<2;
49        #[doc(alias = "NSTextLayoutManagerSegmentOptionsTailSegmentExtended")]
50        const TailSegmentExtended = 1<<3;
51        #[doc(alias = "NSTextLayoutManagerSegmentOptionsUpstreamAffinity")]
52        const UpstreamAffinity = 1<<4;
53    }
54}
55
56unsafe impl Encode for NSTextLayoutManagerSegmentOptions {
57    const ENCODING: Encoding = NSUInteger::ENCODING;
58}
59
60unsafe impl RefEncode for NSTextLayoutManagerSegmentOptions {
61    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
62}
63
64extern_class!(
65    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextlayoutmanager?language=objc)
66    #[unsafe(super(NSObject))]
67    #[derive(Debug, PartialEq, Eq, Hash)]
68    pub struct NSTextLayoutManager;
69);
70
71extern_conformance!(
72    unsafe impl NSCoding for NSTextLayoutManager {}
73);
74
75extern_conformance!(
76    unsafe impl NSObjectProtocol for NSTextLayoutManager {}
77);
78
79extern_conformance!(
80    unsafe impl NSSecureCoding for NSTextLayoutManager {}
81);
82
83#[cfg(feature = "NSTextSelectionNavigation")]
84extern_conformance!(
85    unsafe impl NSTextSelectionDataSource for NSTextLayoutManager {}
86);
87
88impl NSTextLayoutManager {
89    extern_methods!(
90        #[unsafe(method(init))]
91        #[unsafe(method_family = init)]
92        pub fn init(this: Allocated<Self>) -> Retained<Self>;
93
94        /// # Safety
95        ///
96        /// `coder` possibly has further requirements.
97        #[unsafe(method(initWithCoder:))]
98        #[unsafe(method_family = init)]
99        pub unsafe fn initWithCoder(
100            this: Allocated<Self>,
101            coder: &NSCoder,
102        ) -> Option<Retained<Self>>;
103
104        #[unsafe(method(delegate))]
105        #[unsafe(method_family = none)]
106        pub fn delegate(&self)
107            -> Option<Retained<ProtocolObject<dyn NSTextLayoutManagerDelegate>>>;
108
109        /// Setter for [`delegate`][Self::delegate].
110        ///
111        /// This is a [weak property][objc2::topics::weak_property].
112        #[unsafe(method(setDelegate:))]
113        #[unsafe(method_family = none)]
114        pub fn setDelegate(
115            &self,
116            delegate: Option<&ProtocolObject<dyn NSTextLayoutManagerDelegate>>,
117        );
118
119        #[unsafe(method(usesFontLeading))]
120        #[unsafe(method_family = none)]
121        pub fn usesFontLeading(&self) -> bool;
122
123        /// Setter for [`usesFontLeading`][Self::usesFontLeading].
124        #[unsafe(method(setUsesFontLeading:))]
125        #[unsafe(method_family = none)]
126        pub fn setUsesFontLeading(&self, uses_font_leading: bool);
127
128        #[unsafe(method(limitsLayoutForSuspiciousContents))]
129        #[unsafe(method_family = none)]
130        pub fn limitsLayoutForSuspiciousContents(&self) -> bool;
131
132        /// Setter for [`limitsLayoutForSuspiciousContents`][Self::limitsLayoutForSuspiciousContents].
133        #[unsafe(method(setLimitsLayoutForSuspiciousContents:))]
134        #[unsafe(method_family = none)]
135        pub fn setLimitsLayoutForSuspiciousContents(
136            &self,
137            limits_layout_for_suspicious_contents: bool,
138        );
139
140        #[unsafe(method(usesHyphenation))]
141        #[unsafe(method_family = none)]
142        pub fn usesHyphenation(&self) -> bool;
143
144        /// Setter for [`usesHyphenation`][Self::usesHyphenation].
145        #[unsafe(method(setUsesHyphenation:))]
146        #[unsafe(method_family = none)]
147        pub fn setUsesHyphenation(&self, uses_hyphenation: bool);
148
149        /// Specifies the behavior for resolving ``NSTextAlignment.natural`` to the visual alignment.
150        ///
151        /// When set to ``true``, the resolved visual alignment is determined by the resolved base writing direction; otherwise, it is using the user’s preferred language.
152        /// The default value is ``true``.
153        #[unsafe(method(resolvesNaturalAlignmentWithBaseWritingDirection))]
154        #[unsafe(method_family = none)]
155        pub fn resolvesNaturalAlignmentWithBaseWritingDirection(&self) -> bool;
156
157        /// Setter for [`resolvesNaturalAlignmentWithBaseWritingDirection`][Self::resolvesNaturalAlignmentWithBaseWritingDirection].
158        #[unsafe(method(setResolvesNaturalAlignmentWithBaseWritingDirection:))]
159        #[unsafe(method_family = none)]
160        pub fn setResolvesNaturalAlignmentWithBaseWritingDirection(
161            &self,
162            resolves_natural_alignment_with_base_writing_direction: bool,
163        );
164
165        #[cfg(feature = "NSTextContentManager")]
166        #[unsafe(method(textContentManager))]
167        #[unsafe(method_family = none)]
168        pub fn textContentManager(&self) -> Option<Retained<NSTextContentManager>>;
169
170        #[cfg(feature = "NSTextContentManager")]
171        #[unsafe(method(replaceTextContentManager:))]
172        #[unsafe(method_family = none)]
173        pub fn replaceTextContentManager(&self, text_content_manager: &NSTextContentManager);
174
175        #[cfg(feature = "NSTextContainer")]
176        #[unsafe(method(textContainer))]
177        #[unsafe(method_family = none)]
178        pub fn textContainer(&self) -> Option<Retained<NSTextContainer>>;
179
180        #[cfg(feature = "NSTextContainer")]
181        /// Setter for [`textContainer`][Self::textContainer].
182        #[unsafe(method(setTextContainer:))]
183        #[unsafe(method_family = none)]
184        pub fn setTextContainer(&self, text_container: Option<&NSTextContainer>);
185
186        #[cfg(feature = "objc2-core-foundation")]
187        #[unsafe(method(usageBoundsForTextContainer))]
188        #[unsafe(method_family = none)]
189        pub fn usageBoundsForTextContainer(&self) -> CGRect;
190
191        #[cfg(feature = "NSTextViewportLayoutController")]
192        #[unsafe(method(textViewportLayoutController))]
193        #[unsafe(method_family = none)]
194        pub fn textViewportLayoutController(&self) -> Retained<NSTextViewportLayoutController>;
195
196        #[unsafe(method(layoutQueue))]
197        #[unsafe(method_family = none)]
198        pub fn layoutQueue(&self) -> Option<Retained<NSOperationQueue>>;
199
200        /// Setter for [`layoutQueue`][Self::layoutQueue].
201        ///
202        /// # Safety
203        ///
204        /// `layout_queue` possibly has additional threading requirements.
205        #[unsafe(method(setLayoutQueue:))]
206        #[unsafe(method_family = none)]
207        pub unsafe fn setLayoutQueue(&self, layout_queue: Option<&NSOperationQueue>);
208
209        #[cfg(feature = "NSTextRange")]
210        #[unsafe(method(ensureLayoutForRange:))]
211        #[unsafe(method_family = none)]
212        pub fn ensureLayoutForRange(&self, range: &NSTextRange);
213
214        #[cfg(feature = "objc2-core-foundation")]
215        #[unsafe(method(ensureLayoutForBounds:))]
216        #[unsafe(method_family = none)]
217        pub fn ensureLayoutForBounds(&self, bounds: CGRect);
218
219        #[cfg(feature = "NSTextRange")]
220        #[unsafe(method(invalidateLayoutForRange:))]
221        #[unsafe(method_family = none)]
222        pub fn invalidateLayoutForRange(&self, range: &NSTextRange);
223
224        #[cfg(all(feature = "NSTextLayoutFragment", feature = "objc2-core-foundation"))]
225        #[unsafe(method(textLayoutFragmentForPosition:))]
226        #[unsafe(method_family = none)]
227        pub fn textLayoutFragmentForPosition(
228            &self,
229            position: CGPoint,
230        ) -> Option<Retained<NSTextLayoutFragment>>;
231
232        #[cfg(all(feature = "NSTextLayoutFragment", feature = "NSTextRange"))]
233        #[unsafe(method(textLayoutFragmentForLocation:))]
234        #[unsafe(method_family = none)]
235        pub fn textLayoutFragmentForLocation(
236            &self,
237            location: &ProtocolObject<dyn NSTextLocation>,
238        ) -> Option<Retained<NSTextLayoutFragment>>;
239
240        #[cfg(all(
241            feature = "NSTextLayoutFragment",
242            feature = "NSTextRange",
243            feature = "block2"
244        ))]
245        #[unsafe(method(enumerateTextLayoutFragmentsFromLocation:options:usingBlock:))]
246        #[unsafe(method_family = none)]
247        pub fn enumerateTextLayoutFragmentsFromLocation_options_usingBlock(
248            &self,
249            location: Option<&ProtocolObject<dyn NSTextLocation>>,
250            options: NSTextLayoutFragmentEnumerationOptions,
251            block: &block2::DynBlock<dyn Fn(NonNull<NSTextLayoutFragment>) -> Bool + '_>,
252        ) -> Option<Retained<ProtocolObject<dyn NSTextLocation>>>;
253
254        #[cfg(feature = "NSTextSelection")]
255        #[unsafe(method(textSelections))]
256        #[unsafe(method_family = none)]
257        pub fn textSelections(&self) -> Retained<NSArray<NSTextSelection>>;
258
259        #[cfg(feature = "NSTextSelection")]
260        /// Setter for [`textSelections`][Self::textSelections].
261        #[unsafe(method(setTextSelections:))]
262        #[unsafe(method_family = none)]
263        pub fn setTextSelections(&self, text_selections: &NSArray<NSTextSelection>);
264
265        #[cfg(feature = "NSTextSelectionNavigation")]
266        #[unsafe(method(textSelectionNavigation))]
267        #[unsafe(method_family = none)]
268        pub fn textSelectionNavigation(&self) -> Retained<NSTextSelectionNavigation>;
269
270        #[cfg(feature = "NSTextSelectionNavigation")]
271        /// Setter for [`textSelectionNavigation`][Self::textSelectionNavigation].
272        #[unsafe(method(setTextSelectionNavigation:))]
273        #[unsafe(method_family = none)]
274        pub fn setTextSelectionNavigation(
275            &self,
276            text_selection_navigation: &NSTextSelectionNavigation,
277        );
278
279        #[cfg(all(feature = "NSTextRange", feature = "block2"))]
280        #[unsafe(method(enumerateRenderingAttributesFromLocation:reverse:usingBlock:))]
281        #[unsafe(method_family = none)]
282        pub fn enumerateRenderingAttributesFromLocation_reverse_usingBlock(
283            &self,
284            location: &ProtocolObject<dyn NSTextLocation>,
285            reverse: bool,
286            block: &block2::DynBlock<
287                dyn Fn(
288                        NonNull<NSTextLayoutManager>,
289                        NonNull<NSDictionary<NSAttributedStringKey, AnyObject>>,
290                        NonNull<NSTextRange>,
291                    ) -> Bool
292                    + '_,
293            >,
294        );
295
296        #[cfg(feature = "NSTextRange")]
297        /// # Safety
298        ///
299        /// `rendering_attributes` generic should be of the correct type.
300        #[unsafe(method(setRenderingAttributes:forTextRange:))]
301        #[unsafe(method_family = none)]
302        pub unsafe fn setRenderingAttributes_forTextRange(
303            &self,
304            rendering_attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
305            text_range: &NSTextRange,
306        );
307
308        #[cfg(feature = "NSTextRange")]
309        /// # Safety
310        ///
311        /// `value` should be of the correct type.
312        #[unsafe(method(addRenderingAttribute:value:forTextRange:))]
313        #[unsafe(method_family = none)]
314        pub unsafe fn addRenderingAttribute_value_forTextRange(
315            &self,
316            rendering_attribute: &NSAttributedStringKey,
317            value: Option<&AnyObject>,
318            text_range: &NSTextRange,
319        );
320
321        #[cfg(feature = "NSTextRange")]
322        #[unsafe(method(removeRenderingAttribute:forTextRange:))]
323        #[unsafe(method_family = none)]
324        pub fn removeRenderingAttribute_forTextRange(
325            &self,
326            rendering_attribute: &NSAttributedStringKey,
327            text_range: &NSTextRange,
328        );
329
330        #[cfg(feature = "NSTextRange")]
331        #[unsafe(method(invalidateRenderingAttributesForTextRange:))]
332        #[unsafe(method_family = none)]
333        pub fn invalidateRenderingAttributesForTextRange(&self, text_range: &NSTextRange);
334
335        #[cfg(all(feature = "NSTextLayoutFragment", feature = "block2"))]
336        /// # Safety
337        ///
338        /// - The returned block's argument 1 must be a valid pointer.
339        /// - The returned block's argument 2 must be a valid pointer.
340        #[unsafe(method(renderingAttributesValidator))]
341        #[unsafe(method_family = none)]
342        pub unsafe fn renderingAttributesValidator(
343            &self,
344        ) -> *mut block2::DynBlock<
345            dyn Fn(NonNull<NSTextLayoutManager>, NonNull<NSTextLayoutFragment>),
346        >;
347
348        #[cfg(all(feature = "NSTextLayoutFragment", feature = "block2"))]
349        /// Setter for [`renderingAttributesValidator`][Self::renderingAttributesValidator].
350        ///
351        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
352        #[unsafe(method(setRenderingAttributesValidator:))]
353        #[unsafe(method_family = none)]
354        pub fn setRenderingAttributesValidator(
355            &self,
356            rendering_attributes_validator: Option<
357                &block2::DynBlock<
358                    dyn Fn(NonNull<NSTextLayoutManager>, NonNull<NSTextLayoutFragment>),
359                >,
360            >,
361        );
362
363        #[unsafe(method(linkRenderingAttributes))]
364        #[unsafe(method_family = none)]
365        pub fn linkRenderingAttributes() -> Retained<NSDictionary<NSAttributedStringKey, AnyObject>>;
366
367        #[cfg(feature = "NSTextRange")]
368        /// # Safety
369        ///
370        /// `link` should be of the correct type.
371        #[unsafe(method(renderingAttributesForLink:atLocation:))]
372        #[unsafe(method_family = none)]
373        pub unsafe fn renderingAttributesForLink_atLocation(
374            &self,
375            link: &AnyObject,
376            location: &ProtocolObject<dyn NSTextLocation>,
377        ) -> Retained<NSDictionary<NSAttributedStringKey, AnyObject>>;
378
379        #[cfg(all(
380            feature = "NSTextContainer",
381            feature = "NSTextRange",
382            feature = "block2",
383            feature = "objc2-core-foundation"
384        ))]
385        #[unsafe(method(enumerateTextSegmentsInRange:type:options:usingBlock:))]
386        #[unsafe(method_family = none)]
387        pub fn enumerateTextSegmentsInRange_type_options_usingBlock(
388            &self,
389            text_range: &NSTextRange,
390            r#type: NSTextLayoutManagerSegmentType,
391            options: NSTextLayoutManagerSegmentOptions,
392            block: &block2::DynBlock<
393                dyn Fn(*mut NSTextRange, CGRect, CGFloat, NonNull<NSTextContainer>) -> Bool + '_,
394            >,
395        );
396
397        #[cfg(all(feature = "NSTextElement", feature = "NSTextRange"))]
398        #[unsafe(method(replaceContentsInRange:withTextElements:))]
399        #[unsafe(method_family = none)]
400        pub fn replaceContentsInRange_withTextElements(
401            &self,
402            range: &NSTextRange,
403            text_elements: &NSArray<NSTextElement>,
404        );
405
406        #[cfg(feature = "NSTextRange")]
407        #[unsafe(method(replaceContentsInRange:withAttributedString:))]
408        #[unsafe(method_family = none)]
409        pub fn replaceContentsInRange_withAttributedString(
410            &self,
411            range: &NSTextRange,
412            attributed_string: &NSAttributedString,
413        );
414    );
415}
416
417/// Methods declared on superclass `NSObject`.
418impl NSTextLayoutManager {
419    extern_methods!(
420        #[unsafe(method(new))]
421        #[unsafe(method_family = new)]
422        pub fn new() -> Retained<Self>;
423    );
424}
425
426impl DefaultRetained for NSTextLayoutManager {
427    #[inline]
428    fn default_retained() -> Retained<Self> {
429        Self::new()
430    }
431}
432
433extern_protocol!(
434    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextlayoutmanagerdelegate?language=objc)
435    pub unsafe trait NSTextLayoutManagerDelegate: NSObjectProtocol {
436        #[cfg(all(
437            feature = "NSTextElement",
438            feature = "NSTextLayoutFragment",
439            feature = "NSTextRange"
440        ))]
441        #[optional]
442        #[unsafe(method(textLayoutManager:textLayoutFragmentForLocation:inTextElement:))]
443        #[unsafe(method_family = none)]
444        fn textLayoutManager_textLayoutFragmentForLocation_inTextElement(
445            &self,
446            text_layout_manager: &NSTextLayoutManager,
447            location: &ProtocolObject<dyn NSTextLocation>,
448            text_element: &NSTextElement,
449        ) -> Retained<NSTextLayoutFragment>;
450
451        #[cfg(feature = "NSTextRange")]
452        #[optional]
453        #[unsafe(method(textLayoutManager:shouldBreakLineBeforeLocation:hyphenating:))]
454        #[unsafe(method_family = none)]
455        fn textLayoutManager_shouldBreakLineBeforeLocation_hyphenating(
456            &self,
457            text_layout_manager: &NSTextLayoutManager,
458            location: &ProtocolObject<dyn NSTextLocation>,
459            hyphenating: bool,
460        ) -> bool;
461
462        #[cfg(feature = "NSTextRange")]
463        /// # Safety
464        ///
465        /// - `link` should be of the correct type.
466        /// - `rendering_attributes` generic should be of the correct type.
467        #[optional]
468        #[unsafe(method(textLayoutManager:renderingAttributesForLink:atLocation:defaultAttributes:))]
469        #[unsafe(method_family = none)]
470        unsafe fn textLayoutManager_renderingAttributesForLink_atLocation_defaultAttributes(
471            &self,
472            text_layout_manager: &NSTextLayoutManager,
473            link: &AnyObject,
474            location: &ProtocolObject<dyn NSTextLocation>,
475            rendering_attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
476        ) -> Option<Retained<NSDictionary<NSAttributedStringKey, AnyObject>>>;
477    }
478);