objc2-app-kit 0.3.2

Bindings to the AppKit framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;
use objc2_foundation::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextlayoutmanagersegmenttype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTextLayoutManagerSegmentType(pub NSInteger);
impl NSTextLayoutManagerSegmentType {
    #[doc(alias = "NSTextLayoutManagerSegmentTypeStandard")]
    pub const Standard: Self = Self(0);
    #[doc(alias = "NSTextLayoutManagerSegmentTypeSelection")]
    pub const Selection: Self = Self(1);
    #[doc(alias = "NSTextLayoutManagerSegmentTypeHighlight")]
    pub const Highlight: Self = Self(2);
}

unsafe impl Encode for NSTextLayoutManagerSegmentType {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for NSTextLayoutManagerSegmentType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextlayoutmanagersegmentoptions?language=objc)
// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTextLayoutManagerSegmentOptions(pub NSUInteger);
bitflags::bitflags! {
    impl NSTextLayoutManagerSegmentOptions: NSUInteger {
        #[doc(alias = "NSTextLayoutManagerSegmentOptionsNone")]
        const None = 0;
        #[doc(alias = "NSTextLayoutManagerSegmentOptionsRangeNotRequired")]
        const RangeNotRequired = 1<<0;
        #[doc(alias = "NSTextLayoutManagerSegmentOptionsMiddleFragmentsExcluded")]
        const MiddleFragmentsExcluded = 1<<1;
        #[doc(alias = "NSTextLayoutManagerSegmentOptionsHeadSegmentExtended")]
        const HeadSegmentExtended = 1<<2;
        #[doc(alias = "NSTextLayoutManagerSegmentOptionsTailSegmentExtended")]
        const TailSegmentExtended = 1<<3;
        #[doc(alias = "NSTextLayoutManagerSegmentOptionsUpstreamAffinity")]
        const UpstreamAffinity = 1<<4;
    }
}

unsafe impl Encode for NSTextLayoutManagerSegmentOptions {
    const ENCODING: Encoding = NSUInteger::ENCODING;
}

unsafe impl RefEncode for NSTextLayoutManagerSegmentOptions {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextlayoutmanager?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSTextLayoutManager;
);

extern_conformance!(
    unsafe impl NSCoding for NSTextLayoutManager {}
);

extern_conformance!(
    unsafe impl NSObjectProtocol for NSTextLayoutManager {}
);

extern_conformance!(
    unsafe impl NSSecureCoding for NSTextLayoutManager {}
);

#[cfg(feature = "NSTextSelectionNavigation")]
extern_conformance!(
    unsafe impl NSTextSelectionDataSource for NSTextLayoutManager {}
);

impl NSTextLayoutManager {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        /// # Safety
        ///
        /// `coder` possibly has further requirements.
        #[unsafe(method(initWithCoder:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithCoder(
            this: Allocated<Self>,
            coder: &NSCoder,
        ) -> Option<Retained<Self>>;

        #[unsafe(method(delegate))]
        #[unsafe(method_family = none)]
        pub fn delegate(&self)
            -> Option<Retained<ProtocolObject<dyn NSTextLayoutManagerDelegate>>>;

        /// Setter for [`delegate`][Self::delegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setDelegate:))]
        #[unsafe(method_family = none)]
        pub fn setDelegate(
            &self,
            delegate: Option<&ProtocolObject<dyn NSTextLayoutManagerDelegate>>,
        );

        #[unsafe(method(usesFontLeading))]
        #[unsafe(method_family = none)]
        pub fn usesFontLeading(&self) -> bool;

        /// Setter for [`usesFontLeading`][Self::usesFontLeading].
        #[unsafe(method(setUsesFontLeading:))]
        #[unsafe(method_family = none)]
        pub fn setUsesFontLeading(&self, uses_font_leading: bool);

        #[unsafe(method(limitsLayoutForSuspiciousContents))]
        #[unsafe(method_family = none)]
        pub fn limitsLayoutForSuspiciousContents(&self) -> bool;

        /// Setter for [`limitsLayoutForSuspiciousContents`][Self::limitsLayoutForSuspiciousContents].
        #[unsafe(method(setLimitsLayoutForSuspiciousContents:))]
        #[unsafe(method_family = none)]
        pub fn setLimitsLayoutForSuspiciousContents(
            &self,
            limits_layout_for_suspicious_contents: bool,
        );

        #[unsafe(method(usesHyphenation))]
        #[unsafe(method_family = none)]
        pub fn usesHyphenation(&self) -> bool;

        /// Setter for [`usesHyphenation`][Self::usesHyphenation].
        #[unsafe(method(setUsesHyphenation:))]
        #[unsafe(method_family = none)]
        pub fn setUsesHyphenation(&self, uses_hyphenation: bool);

        /// Specifies the behavior for resolving ``NSTextAlignment.natural`` to the visual alignment.
        ///
        /// 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.
        /// The default value is ``true``.
        #[unsafe(method(resolvesNaturalAlignmentWithBaseWritingDirection))]
        #[unsafe(method_family = none)]
        pub fn resolvesNaturalAlignmentWithBaseWritingDirection(&self) -> bool;

        /// Setter for [`resolvesNaturalAlignmentWithBaseWritingDirection`][Self::resolvesNaturalAlignmentWithBaseWritingDirection].
        #[unsafe(method(setResolvesNaturalAlignmentWithBaseWritingDirection:))]
        #[unsafe(method_family = none)]
        pub fn setResolvesNaturalAlignmentWithBaseWritingDirection(
            &self,
            resolves_natural_alignment_with_base_writing_direction: bool,
        );

        #[cfg(feature = "NSTextContentManager")]
        #[unsafe(method(textContentManager))]
        #[unsafe(method_family = none)]
        pub fn textContentManager(&self) -> Option<Retained<NSTextContentManager>>;

        #[cfg(feature = "NSTextContentManager")]
        #[unsafe(method(replaceTextContentManager:))]
        #[unsafe(method_family = none)]
        pub fn replaceTextContentManager(&self, text_content_manager: &NSTextContentManager);

        #[cfg(feature = "NSTextContainer")]
        #[unsafe(method(textContainer))]
        #[unsafe(method_family = none)]
        pub fn textContainer(&self) -> Option<Retained<NSTextContainer>>;

        #[cfg(feature = "NSTextContainer")]
        /// Setter for [`textContainer`][Self::textContainer].
        #[unsafe(method(setTextContainer:))]
        #[unsafe(method_family = none)]
        pub fn setTextContainer(&self, text_container: Option<&NSTextContainer>);

        #[cfg(feature = "objc2-core-foundation")]
        #[unsafe(method(usageBoundsForTextContainer))]
        #[unsafe(method_family = none)]
        pub fn usageBoundsForTextContainer(&self) -> CGRect;

        #[cfg(feature = "NSTextViewportLayoutController")]
        #[unsafe(method(textViewportLayoutController))]
        #[unsafe(method_family = none)]
        pub fn textViewportLayoutController(&self) -> Retained<NSTextViewportLayoutController>;

        #[unsafe(method(layoutQueue))]
        #[unsafe(method_family = none)]
        pub fn layoutQueue(&self) -> Option<Retained<NSOperationQueue>>;

        /// Setter for [`layoutQueue`][Self::layoutQueue].
        ///
        /// # Safety
        ///
        /// `layout_queue` possibly has additional threading requirements.
        #[unsafe(method(setLayoutQueue:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setLayoutQueue(&self, layout_queue: Option<&NSOperationQueue>);

        #[cfg(feature = "NSTextRange")]
        #[unsafe(method(ensureLayoutForRange:))]
        #[unsafe(method_family = none)]
        pub fn ensureLayoutForRange(&self, range: &NSTextRange);

        #[cfg(feature = "objc2-core-foundation")]
        #[unsafe(method(ensureLayoutForBounds:))]
        #[unsafe(method_family = none)]
        pub fn ensureLayoutForBounds(&self, bounds: CGRect);

        #[cfg(feature = "NSTextRange")]
        #[unsafe(method(invalidateLayoutForRange:))]
        #[unsafe(method_family = none)]
        pub fn invalidateLayoutForRange(&self, range: &NSTextRange);

        #[cfg(all(feature = "NSTextLayoutFragment", feature = "objc2-core-foundation"))]
        #[unsafe(method(textLayoutFragmentForPosition:))]
        #[unsafe(method_family = none)]
        pub fn textLayoutFragmentForPosition(
            &self,
            position: CGPoint,
        ) -> Option<Retained<NSTextLayoutFragment>>;

        #[cfg(all(feature = "NSTextLayoutFragment", feature = "NSTextRange"))]
        #[unsafe(method(textLayoutFragmentForLocation:))]
        #[unsafe(method_family = none)]
        pub fn textLayoutFragmentForLocation(
            &self,
            location: &ProtocolObject<dyn NSTextLocation>,
        ) -> Option<Retained<NSTextLayoutFragment>>;

        #[cfg(all(
            feature = "NSTextLayoutFragment",
            feature = "NSTextRange",
            feature = "block2"
        ))]
        #[unsafe(method(enumerateTextLayoutFragmentsFromLocation:options:usingBlock:))]
        #[unsafe(method_family = none)]
        pub fn enumerateTextLayoutFragmentsFromLocation_options_usingBlock(
            &self,
            location: Option<&ProtocolObject<dyn NSTextLocation>>,
            options: NSTextLayoutFragmentEnumerationOptions,
            block: &block2::DynBlock<dyn Fn(NonNull<NSTextLayoutFragment>) -> Bool + '_>,
        ) -> Option<Retained<ProtocolObject<dyn NSTextLocation>>>;

        #[cfg(feature = "NSTextSelection")]
        #[unsafe(method(textSelections))]
        #[unsafe(method_family = none)]
        pub fn textSelections(&self) -> Retained<NSArray<NSTextSelection>>;

        #[cfg(feature = "NSTextSelection")]
        /// Setter for [`textSelections`][Self::textSelections].
        #[unsafe(method(setTextSelections:))]
        #[unsafe(method_family = none)]
        pub fn setTextSelections(&self, text_selections: &NSArray<NSTextSelection>);

        #[cfg(feature = "NSTextSelectionNavigation")]
        #[unsafe(method(textSelectionNavigation))]
        #[unsafe(method_family = none)]
        pub fn textSelectionNavigation(&self) -> Retained<NSTextSelectionNavigation>;

        #[cfg(feature = "NSTextSelectionNavigation")]
        /// Setter for [`textSelectionNavigation`][Self::textSelectionNavigation].
        #[unsafe(method(setTextSelectionNavigation:))]
        #[unsafe(method_family = none)]
        pub fn setTextSelectionNavigation(
            &self,
            text_selection_navigation: &NSTextSelectionNavigation,
        );

        #[cfg(all(feature = "NSTextRange", feature = "block2"))]
        #[unsafe(method(enumerateRenderingAttributesFromLocation:reverse:usingBlock:))]
        #[unsafe(method_family = none)]
        pub fn enumerateRenderingAttributesFromLocation_reverse_usingBlock(
            &self,
            location: &ProtocolObject<dyn NSTextLocation>,
            reverse: bool,
            block: &block2::DynBlock<
                dyn Fn(
                        NonNull<NSTextLayoutManager>,
                        NonNull<NSDictionary<NSAttributedStringKey, AnyObject>>,
                        NonNull<NSTextRange>,
                    ) -> Bool
                    + '_,
            >,
        );

        #[cfg(feature = "NSTextRange")]
        /// # Safety
        ///
        /// `rendering_attributes` generic should be of the correct type.
        #[unsafe(method(setRenderingAttributes:forTextRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setRenderingAttributes_forTextRange(
            &self,
            rendering_attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
            text_range: &NSTextRange,
        );

        #[cfg(feature = "NSTextRange")]
        /// # Safety
        ///
        /// `value` should be of the correct type.
        #[unsafe(method(addRenderingAttribute:value:forTextRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addRenderingAttribute_value_forTextRange(
            &self,
            rendering_attribute: &NSAttributedStringKey,
            value: Option<&AnyObject>,
            text_range: &NSTextRange,
        );

        #[cfg(feature = "NSTextRange")]
        #[unsafe(method(removeRenderingAttribute:forTextRange:))]
        #[unsafe(method_family = none)]
        pub fn removeRenderingAttribute_forTextRange(
            &self,
            rendering_attribute: &NSAttributedStringKey,
            text_range: &NSTextRange,
        );

        #[cfg(feature = "NSTextRange")]
        #[unsafe(method(invalidateRenderingAttributesForTextRange:))]
        #[unsafe(method_family = none)]
        pub fn invalidateRenderingAttributesForTextRange(&self, text_range: &NSTextRange);

        #[cfg(all(feature = "NSTextLayoutFragment", feature = "block2"))]
        /// # Safety
        ///
        /// - The returned block's argument 1 must be a valid pointer.
        /// - The returned block's argument 2 must be a valid pointer.
        #[unsafe(method(renderingAttributesValidator))]
        #[unsafe(method_family = none)]
        pub unsafe fn renderingAttributesValidator(
            &self,
        ) -> *mut block2::DynBlock<
            dyn Fn(NonNull<NSTextLayoutManager>, NonNull<NSTextLayoutFragment>),
        >;

        #[cfg(all(feature = "NSTextLayoutFragment", feature = "block2"))]
        /// Setter for [`renderingAttributesValidator`][Self::renderingAttributesValidator].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setRenderingAttributesValidator:))]
        #[unsafe(method_family = none)]
        pub fn setRenderingAttributesValidator(
            &self,
            rendering_attributes_validator: Option<
                &block2::DynBlock<
                    dyn Fn(NonNull<NSTextLayoutManager>, NonNull<NSTextLayoutFragment>),
                >,
            >,
        );

        #[unsafe(method(linkRenderingAttributes))]
        #[unsafe(method_family = none)]
        pub fn linkRenderingAttributes() -> Retained<NSDictionary<NSAttributedStringKey, AnyObject>>;

        #[cfg(feature = "NSTextRange")]
        /// # Safety
        ///
        /// `link` should be of the correct type.
        #[unsafe(method(renderingAttributesForLink:atLocation:))]
        #[unsafe(method_family = none)]
        pub unsafe fn renderingAttributesForLink_atLocation(
            &self,
            link: &AnyObject,
            location: &ProtocolObject<dyn NSTextLocation>,
        ) -> Retained<NSDictionary<NSAttributedStringKey, AnyObject>>;

        #[cfg(all(
            feature = "NSTextContainer",
            feature = "NSTextRange",
            feature = "block2",
            feature = "objc2-core-foundation"
        ))]
        #[unsafe(method(enumerateTextSegmentsInRange:type:options:usingBlock:))]
        #[unsafe(method_family = none)]
        pub fn enumerateTextSegmentsInRange_type_options_usingBlock(
            &self,
            text_range: &NSTextRange,
            r#type: NSTextLayoutManagerSegmentType,
            options: NSTextLayoutManagerSegmentOptions,
            block: &block2::DynBlock<
                dyn Fn(*mut NSTextRange, CGRect, CGFloat, NonNull<NSTextContainer>) -> Bool + '_,
            >,
        );

        #[cfg(all(feature = "NSTextElement", feature = "NSTextRange"))]
        #[unsafe(method(replaceContentsInRange:withTextElements:))]
        #[unsafe(method_family = none)]
        pub fn replaceContentsInRange_withTextElements(
            &self,
            range: &NSTextRange,
            text_elements: &NSArray<NSTextElement>,
        );

        #[cfg(feature = "NSTextRange")]
        #[unsafe(method(replaceContentsInRange:withAttributedString:))]
        #[unsafe(method_family = none)]
        pub fn replaceContentsInRange_withAttributedString(
            &self,
            range: &NSTextRange,
            attributed_string: &NSAttributedString,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl NSTextLayoutManager {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

impl DefaultRetained for NSTextLayoutManager {
    #[inline]
    fn default_retained() -> Retained<Self> {
        Self::new()
    }
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstextlayoutmanagerdelegate?language=objc)
    pub unsafe trait NSTextLayoutManagerDelegate: NSObjectProtocol {
        #[cfg(all(
            feature = "NSTextElement",
            feature = "NSTextLayoutFragment",
            feature = "NSTextRange"
        ))]
        #[optional]
        #[unsafe(method(textLayoutManager:textLayoutFragmentForLocation:inTextElement:))]
        #[unsafe(method_family = none)]
        fn textLayoutManager_textLayoutFragmentForLocation_inTextElement(
            &self,
            text_layout_manager: &NSTextLayoutManager,
            location: &ProtocolObject<dyn NSTextLocation>,
            text_element: &NSTextElement,
        ) -> Retained<NSTextLayoutFragment>;

        #[cfg(feature = "NSTextRange")]
        #[optional]
        #[unsafe(method(textLayoutManager:shouldBreakLineBeforeLocation:hyphenating:))]
        #[unsafe(method_family = none)]
        fn textLayoutManager_shouldBreakLineBeforeLocation_hyphenating(
            &self,
            text_layout_manager: &NSTextLayoutManager,
            location: &ProtocolObject<dyn NSTextLocation>,
            hyphenating: bool,
        ) -> bool;

        #[cfg(feature = "NSTextRange")]
        /// # Safety
        ///
        /// - `link` should be of the correct type.
        /// - `rendering_attributes` generic should be of the correct type.
        #[optional]
        #[unsafe(method(textLayoutManager:renderingAttributesForLink:atLocation:defaultAttributes:))]
        #[unsafe(method_family = none)]
        unsafe fn textLayoutManager_renderingAttributesForLink_atLocation_defaultAttributes(
            &self,
            text_layout_manager: &NSTextLayoutManager,
            link: &AnyObject,
            location: &ProtocolObject<dyn NSTextLocation>,
            rendering_attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
        ) -> Option<Retained<NSDictionary<NSAttributedStringKey, AnyObject>>>;
    }
);