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
//! 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::*;
use objc2_foundation::*;

use crate::*;

/// Direction to search for an NSAccessibilityCustomRotorItemResult.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsaccessibilitycustomrotorsearchdirection?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSAccessibilityCustomRotorSearchDirection(pub NSInteger);
impl NSAccessibilityCustomRotorSearchDirection {
    #[doc(alias = "NSAccessibilityCustomRotorSearchDirectionPrevious")]
    pub const Previous: Self = Self(0);
    #[doc(alias = "NSAccessibilityCustomRotorSearchDirectionNext")]
    pub const Next: Self = Self(1);
}

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

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

/// Use NSAccessibilityCustomRotorType when providing results for the
/// following types. This allows assistive technologies to assign keyboard
/// commands and gestures for these common search types.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsaccessibilitycustomrotortype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSAccessibilityCustomRotorType(pub NSInteger);
impl NSAccessibilityCustomRotorType {
    #[doc(alias = "NSAccessibilityCustomRotorTypeCustom")]
    pub const Custom: Self = Self(0);
    #[doc(alias = "NSAccessibilityCustomRotorTypeAny")]
    pub const Any: Self = Self(1);
    #[doc(alias = "NSAccessibilityCustomRotorTypeAnnotation")]
    pub const Annotation: Self = Self(2);
    #[doc(alias = "NSAccessibilityCustomRotorTypeBoldText")]
    pub const BoldText: Self = Self(3);
    #[doc(alias = "NSAccessibilityCustomRotorTypeHeading")]
    pub const Heading: Self = Self(4);
    #[doc(alias = "NSAccessibilityCustomRotorTypeHeadingLevel1")]
    pub const HeadingLevel1: Self = Self(5);
    #[doc(alias = "NSAccessibilityCustomRotorTypeHeadingLevel2")]
    pub const HeadingLevel2: Self = Self(6);
    #[doc(alias = "NSAccessibilityCustomRotorTypeHeadingLevel3")]
    pub const HeadingLevel3: Self = Self(7);
    #[doc(alias = "NSAccessibilityCustomRotorTypeHeadingLevel4")]
    pub const HeadingLevel4: Self = Self(8);
    #[doc(alias = "NSAccessibilityCustomRotorTypeHeadingLevel5")]
    pub const HeadingLevel5: Self = Self(9);
    #[doc(alias = "NSAccessibilityCustomRotorTypeHeadingLevel6")]
    pub const HeadingLevel6: Self = Self(10);
    #[doc(alias = "NSAccessibilityCustomRotorTypeImage")]
    pub const Image: Self = Self(11);
    #[doc(alias = "NSAccessibilityCustomRotorTypeItalicText")]
    pub const ItalicText: Self = Self(12);
    #[doc(alias = "NSAccessibilityCustomRotorTypeLandmark")]
    pub const Landmark: Self = Self(13);
    #[doc(alias = "NSAccessibilityCustomRotorTypeLink")]
    pub const Link: Self = Self(14);
    #[doc(alias = "NSAccessibilityCustomRotorTypeList")]
    pub const List: Self = Self(15);
    #[doc(alias = "NSAccessibilityCustomRotorTypeMisspelledWord")]
    pub const MisspelledWord: Self = Self(16);
    #[doc(alias = "NSAccessibilityCustomRotorTypeTable")]
    pub const Table: Self = Self(17);
    #[doc(alias = "NSAccessibilityCustomRotorTypeTextField")]
    pub const TextField: Self = Self(18);
    #[doc(alias = "NSAccessibilityCustomRotorTypeUnderlinedText")]
    pub const UnderlinedText: Self = Self(19);
    #[doc(alias = "NSAccessibilityCustomRotorTypeVisitedLink")]
    pub const VisitedLink: Self = Self(20);
    #[doc(alias = "NSAccessibilityCustomRotorTypeAudiograph")]
    pub const Audiograph: Self = Self(21);
}

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

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

extern_class!(
    /// NSAccessibilityCustomRotors allow assistive technologies, like
    /// VoiceOver, to search applications for content related to the given label.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsaccessibilitycustomrotor?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSAccessibilityCustomRotor;
);

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

impl NSAccessibilityCustomRotor {
    extern_methods!(
        /// Convenience initializer that uses
        /// NSAccessibilityCustomRotorTypeCustom as the default rotor type. Use this
        /// initializer for custom rotors that are not one of the common types.
        #[unsafe(method(initWithLabel:itemSearchDelegate:))]
        #[unsafe(method_family = init)]
        pub fn initWithLabel_itemSearchDelegate(
            this: Allocated<Self>,
            label: &NSString,
            item_search_delegate: &ProtocolObject<dyn NSAccessibilityCustomRotorItemSearchDelegate>,
        ) -> Retained<Self>;

        /// Convenience initializer for custom rotors that use a common type
        /// such as links, headings, etc. A default label will be provided.
        #[unsafe(method(initWithRotorType:itemSearchDelegate:))]
        #[unsafe(method_family = init)]
        pub fn initWithRotorType_itemSearchDelegate(
            this: Allocated<Self>,
            rotor_type: NSAccessibilityCustomRotorType,
            item_search_delegate: &ProtocolObject<dyn NSAccessibilityCustomRotorItemSearchDelegate>,
        ) -> Retained<Self>;

        /// The rotor type to provide results for.
        ///
        /// The default type is NSAccessibilityCustomRotorTypeCustom, unless
        /// the rotor type was specified in the initializer.
        #[unsafe(method(type))]
        #[unsafe(method_family = none)]
        pub fn r#type(&self) -> NSAccessibilityCustomRotorType;

        /// Setter for [`type`][Self::type].
        #[unsafe(method(setType:))]
        #[unsafe(method_family = none)]
        pub fn setType(&self, r#type: NSAccessibilityCustomRotorType);

        /// The localized label assistive technologies will use to describe
        /// the custom rotor.
        ///
        /// The label is only used when the rotor type is
        /// NSAccessibilityCustomRotorTypeCustom since a default is provided
        /// for all other types.
        #[unsafe(method(label))]
        #[unsafe(method_family = none)]
        pub fn label(&self) -> Retained<NSString>;

        /// Setter for [`label`][Self::label].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setLabel:))]
        #[unsafe(method_family = none)]
        pub fn setLabel(&self, label: &NSString);

        /// The itemSearchDelegate will be asked to find the next item result
        /// after performing a search with the given search parameters.
        #[unsafe(method(itemSearchDelegate))]
        #[unsafe(method_family = none)]
        pub fn itemSearchDelegate(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn NSAccessibilityCustomRotorItemSearchDelegate>>>;

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

        #[cfg(feature = "NSAccessibilityProtocols")]
        /// Provide an item load delegate if the rotor vends item results that
        /// do not have a backing UI element yet. The loader will be asked to load an
        /// element via the accessibilityElementWithToken protocol method when the
        /// item result is selected by an assistive client. Applications can use the
        /// item result's token to determine which item to return.
        #[unsafe(method(itemLoadingDelegate))]
        #[unsafe(method_family = none)]
        pub fn itemLoadingDelegate(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn NSAccessibilityElementLoading>>>;

        #[cfg(feature = "NSAccessibilityProtocols")]
        /// Setter for [`itemLoadingDelegate`][Self::itemLoadingDelegate].
        ///
        /// This is a [weak property][objc2::topics::weak_property].
        #[unsafe(method(setItemLoadingDelegate:))]
        #[unsafe(method_family = none)]
        pub fn setItemLoadingDelegate(
            &self,
            item_loading_delegate: Option<&ProtocolObject<dyn NSAccessibilityElementLoading>>,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl NSAccessibilityCustomRotor {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

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

extern_class!(
    /// NSAccessibilityCustomRotorSearchParameters is a container for
    /// search parameters. It should be examined to determine the next matching
    /// NSAccessibilityCustomRotorItemResult.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsaccessibilitycustomrotorsearchparameters?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSAccessibilityCustomRotorSearchParameters;
);

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

impl NSAccessibilityCustomRotorSearchParameters {
    extern_methods!(
        /// The currentItem determines where the search will start from. If
        /// it is nil, the search should begin from, and include, the first or last
        /// item, depending on which search direction is used (e.g. search direction
        /// next will return the first item and previous will return the last item).
        #[unsafe(method(currentItem))]
        #[unsafe(method_family = none)]
        pub fn currentItem(&self) -> Option<Retained<NSAccessibilityCustomRotorItemResult>>;

        /// Setter for [`currentItem`][Self::currentItem].
        #[unsafe(method(setCurrentItem:))]
        #[unsafe(method_family = none)]
        pub fn setCurrentItem(&self, current_item: Option<&NSAccessibilityCustomRotorItemResult>);

        /// Either NSAccessibilityCustomRotorSearchDirectionPrevious or
        /// NSAccessibilityCustomRotorSearchDirectionNext.
        #[unsafe(method(searchDirection))]
        #[unsafe(method_family = none)]
        pub fn searchDirection(&self) -> NSAccessibilityCustomRotorSearchDirection;

        /// Setter for [`searchDirection`][Self::searchDirection].
        #[unsafe(method(setSearchDirection:))]
        #[unsafe(method_family = none)]
        pub fn setSearchDirection(
            &self,
            search_direction: NSAccessibilityCustomRotorSearchDirection,
        );

        /// A string of text to filter the results against. This is used to get
        /// type-ahead results. For example, given a list of primary colors and filter
        /// text "Re", color item "Red" would be returned as a result.
        #[unsafe(method(filterString))]
        #[unsafe(method_family = none)]
        pub fn filterString(&self) -> Retained<NSString>;

        /// Setter for [`filterString`][Self::filterString].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setFilterString:))]
        #[unsafe(method_family = none)]
        pub fn setFilterString(&self, filter_string: &NSString);
    );
}

/// Methods declared on superclass `NSObject`.
impl NSAccessibilityCustomRotorSearchParameters {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub fn new() -> Retained<Self>;
    );
}

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

extern_class!(
    /// NSAccessibilityCustomRotorItemResults are the objects returned
    /// to assistive technologies that match a search parameter criteria.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsaccessibilitycustomrotoritemresult?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSAccessibilityCustomRotorItemResult;
);

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

impl NSAccessibilityCustomRotorItemResult {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

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

        #[cfg(feature = "NSAccessibilityProtocols")]
        /// Creates an item result with a given target element. Assistive
        /// technologies may try to set accessibility focus on the element.
        #[unsafe(method(initWithTargetElement:))]
        #[unsafe(method_family = init)]
        pub fn initWithTargetElement(
            this: Allocated<Self>,
            target_element: &ProtocolObject<dyn NSAccessibilityElementProtocol>,
        ) -> Retained<Self>;

        #[cfg(feature = "NSAccessibilityConstants")]
        /// Creates an item result with a given item load token and custom label.
        /// Use this initializer if the application has not yet loaded the element
        /// backing the item result.
        ///
        /// # Safety
        ///
        /// `item_loading_token` should be of the correct type.
        #[unsafe(method(initWithItemLoadingToken:customLabel:))]
        #[unsafe(method_family = init)]
        pub unsafe fn initWithItemLoadingToken_customLabel(
            this: Allocated<Self>,
            item_loading_token: &NSAccessibilityLoadingToken,
            custom_label: &NSString,
        ) -> Retained<Self>;

        #[cfg(feature = "NSAccessibilityProtocols")]
        /// A target element references an element that will be messaged for
        /// other accessibility properties. If it is not nil, assistive technologies
        /// may try to set accessibility focus on it.
        #[unsafe(method(targetElement))]
        #[unsafe(method_family = none)]
        pub fn targetElement(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn NSAccessibilityElementProtocol>>>;

        #[cfg(feature = "NSAccessibilityConstants")]
        /// Provide an item load token if the application has not yet
        /// loaded the element backing the item result. Application can use the token
        /// to determine which item to return.
        #[unsafe(method(itemLoadingToken))]
        #[unsafe(method_family = none)]
        pub fn itemLoadingToken(&self) -> Option<Retained<NSAccessibilityLoadingToken>>;

        /// For text-based elements such as an NSTextView, this is an NSRange
        /// that specifies the area of interest. If the target range has NSNotFound
        /// for the location, the search should begin from the first or last character
        /// of the text element, depending on the search direction.
        #[unsafe(method(targetRange))]
        #[unsafe(method_family = none)]
        pub fn targetRange(&self) -> NSRange;

        /// Setter for [`targetRange`][Self::targetRange].
        #[unsafe(method(setTargetRange:))]
        #[unsafe(method_family = none)]
        pub fn setTargetRange(&self, target_range: NSRange);

        /// A localized label that can be used instead of the default item
        /// label to describe the item result.
        ///
        /// Required if using the loader-based initializer. Optional otherwise.
        #[unsafe(method(customLabel))]
        #[unsafe(method_family = none)]
        pub fn customLabel(&self) -> Option<Retained<NSString>>;

        /// Setter for [`customLabel`][Self::customLabel].
        ///
        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
        #[unsafe(method(setCustomLabel:))]
        #[unsafe(method_family = none)]
        pub fn setCustomLabel(&self, custom_label: Option<&NSString>);
    );
}

extern_protocol!(
    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsaccessibilitycustomrotoritemsearchdelegate?language=objc)
    pub unsafe trait NSAccessibilityCustomRotorItemSearchDelegate: NSObjectProtocol {
        /// Returns the found NSAccessibilityCustomRotorItemResult after
        /// performing a search with the given search parameters.
        #[unsafe(method(rotor:resultForSearchParameters:))]
        #[unsafe(method_family = none)]
        fn rotor_resultForSearchParameters(
            &self,
            rotor: &NSAccessibilityCustomRotor,
            search_parameters: &NSAccessibilityCustomRotorSearchParameters,
        ) -> Option<Retained<NSAccessibilityCustomRotorItemResult>>;
    }
);