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
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use objc2::__framework_prelude::*;
use objc2_foundation::*;

use crate::*;

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTextSelectionNavigationDirection(pub NSInteger);
impl NSTextSelectionNavigationDirection {
    #[doc(alias = "NSTextSelectionNavigationDirectionForward")]
    pub const Forward: Self = Self(0);
    #[doc(alias = "NSTextSelectionNavigationDirectionBackward")]
    pub const Backward: Self = Self(1);
    #[doc(alias = "NSTextSelectionNavigationDirectionRight")]
    pub const Right: Self = Self(2);
    #[doc(alias = "NSTextSelectionNavigationDirectionLeft")]
    pub const Left: Self = Self(3);
    #[doc(alias = "NSTextSelectionNavigationDirectionUp")]
    pub const Up: Self = Self(4);
    #[doc(alias = "NSTextSelectionNavigationDirectionDown")]
    pub const Down: Self = Self(5);
}

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

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

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTextSelectionNavigationDestination(pub NSInteger);
impl NSTextSelectionNavigationDestination {
    #[doc(alias = "NSTextSelectionNavigationDestinationCharacter")]
    pub const Character: Self = Self(0);
    #[doc(alias = "NSTextSelectionNavigationDestinationWord")]
    pub const Word: Self = Self(1);
    #[doc(alias = "NSTextSelectionNavigationDestinationLine")]
    pub const Line: Self = Self(2);
    #[doc(alias = "NSTextSelectionNavigationDestinationSentence")]
    pub const Sentence: Self = Self(3);
    #[doc(alias = "NSTextSelectionNavigationDestinationParagraph")]
    pub const Paragraph: Self = Self(4);
    #[doc(alias = "NSTextSelectionNavigationDestinationContainer")]
    pub const Container: Self = Self(5);
    #[doc(alias = "NSTextSelectionNavigationDestinationDocument")]
    pub const Document: Self = Self(6);
}

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

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

// NS_OPTIONS
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTextSelectionNavigationModifier(pub NSUInteger);
bitflags::bitflags! {
    impl NSTextSelectionNavigationModifier: NSUInteger {
        #[doc(alias = "NSTextSelectionNavigationModifierExtend")]
        const Extend = 1<<0;
        #[doc(alias = "NSTextSelectionNavigationModifierVisual")]
        const Visual = 1<<1;
        #[doc(alias = "NSTextSelectionNavigationModifierMultiple")]
        const Multiple = 1<<2;
    }
}

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

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

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTextSelectionNavigationWritingDirection(pub NSInteger);
impl NSTextSelectionNavigationWritingDirection {
    #[doc(alias = "NSTextSelectionNavigationWritingDirectionLeftToRight")]
    pub const LeftToRight: Self = Self(0);
    #[doc(alias = "NSTextSelectionNavigationWritingDirectionRightToLeft")]
    pub const RightToLeft: Self = Self(1);
}

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

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

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTextSelectionNavigationLayoutOrientation(pub NSInteger);
impl NSTextSelectionNavigationLayoutOrientation {
    #[doc(alias = "NSTextSelectionNavigationLayoutOrientationHorizontal")]
    pub const Horizontal: Self = Self(0);
    #[doc(alias = "NSTextSelectionNavigationLayoutOrientationVertical")]
    pub const Vertical: Self = Self(1);
}

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

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

extern_class!(
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct NSTextSelectionNavigation;

    unsafe impl ClassType for NSTextSelectionNavigation {
        type Super = NSObject;
        type Mutability = InteriorMutable;
    }
);

unsafe impl NSObjectProtocol for NSTextSelectionNavigation {}

extern_methods!(
    unsafe impl NSTextSelectionNavigation {
        #[method_id(@__retain_semantics Init initWithDataSource:)]
        pub unsafe fn initWithDataSource(
            this: Allocated<Self>,
            data_source: &ProtocolObject<dyn NSTextSelectionDataSource>,
        ) -> Retained<Self>;

        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new() -> Retained<Self>;

        #[method_id(@__retain_semantics Init init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[method_id(@__retain_semantics Other textSelectionDataSource)]
        pub unsafe fn textSelectionDataSource(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn NSTextSelectionDataSource>>>;

        #[method(allowsNonContiguousRanges)]
        pub unsafe fn allowsNonContiguousRanges(&self) -> bool;

        #[method(setAllowsNonContiguousRanges:)]
        pub unsafe fn setAllowsNonContiguousRanges(&self, allows_non_contiguous_ranges: bool);

        #[method(rotatesCoordinateSystemForLayoutOrientation)]
        pub unsafe fn rotatesCoordinateSystemForLayoutOrientation(&self) -> bool;

        #[method(setRotatesCoordinateSystemForLayoutOrientation:)]
        pub unsafe fn setRotatesCoordinateSystemForLayoutOrientation(
            &self,
            rotates_coordinate_system_for_layout_orientation: bool,
        );

        #[method(flushLayoutCache)]
        pub unsafe fn flushLayoutCache(&self);

        #[cfg(feature = "NSTextSelection")]
        #[method_id(@__retain_semantics Other destinationSelectionForTextSelection:direction:destination:extending:confined:)]
        pub unsafe fn destinationSelectionForTextSelection_direction_destination_extending_confined(
            &self,
            text_selection: &NSTextSelection,
            direction: NSTextSelectionNavigationDirection,
            destination: NSTextSelectionNavigationDestination,
            extending: bool,
            confined: bool,
        ) -> Option<Retained<NSTextSelection>>;

        #[cfg(all(feature = "NSTextRange", feature = "NSTextSelection"))]
        #[method_id(@__retain_semantics Other textSelectionsInteractingAtPoint:inContainerAtLocation:anchors:modifiers:selecting:bounds:)]
        pub unsafe fn textSelectionsInteractingAtPoint_inContainerAtLocation_anchors_modifiers_selecting_bounds(
            &self,
            point: CGPoint,
            container_location: &ProtocolObject<dyn NSTextLocation>,
            anchors: &NSArray<NSTextSelection>,
            modifiers: NSTextSelectionNavigationModifier,
            selecting: bool,
            bounds: CGRect,
        ) -> Retained<NSArray<NSTextSelection>>;

        #[cfg(feature = "NSTextSelection")]
        #[method_id(@__retain_semantics Other textSelectionForSelectionGranularity:enclosingTextSelection:)]
        pub unsafe fn textSelectionForSelectionGranularity_enclosingTextSelection(
            &self,
            selection_granularity: NSTextSelectionGranularity,
            text_selection: &NSTextSelection,
        ) -> Retained<NSTextSelection>;

        #[cfg(all(feature = "NSTextRange", feature = "NSTextSelection"))]
        #[method_id(@__retain_semantics Other textSelectionForSelectionGranularity:enclosingPoint:inContainerAtLocation:)]
        pub unsafe fn textSelectionForSelectionGranularity_enclosingPoint_inContainerAtLocation(
            &self,
            selection_granularity: NSTextSelectionGranularity,
            point: CGPoint,
            location: &ProtocolObject<dyn NSTextLocation>,
        ) -> Option<Retained<NSTextSelection>>;

        #[cfg(all(feature = "NSTextRange", feature = "NSTextSelection"))]
        #[method_id(@__retain_semantics Other resolvedInsertionLocationForTextSelection:writingDirection:)]
        pub unsafe fn resolvedInsertionLocationForTextSelection_writingDirection(
            &self,
            text_selection: &NSTextSelection,
            writing_direction: NSTextSelectionNavigationWritingDirection,
        ) -> Option<Retained<ProtocolObject<dyn NSTextLocation>>>;

        #[cfg(all(feature = "NSTextRange", feature = "NSTextSelection"))]
        #[method_id(@__retain_semantics Other deletionRangesForTextSelection:direction:destination:allowsDecomposition:)]
        pub unsafe fn deletionRangesForTextSelection_direction_destination_allowsDecomposition(
            &self,
            text_selection: &NSTextSelection,
            direction: NSTextSelectionNavigationDirection,
            destination: NSTextSelectionNavigationDestination,
            allows_decomposition: bool,
        ) -> Retained<NSArray<NSTextRange>>;
    }
);

extern_protocol!(
    pub unsafe trait NSTextSelectionDataSource: NSObjectProtocol {
        #[cfg(feature = "NSTextRange")]
        #[method_id(@__retain_semantics Other documentRange)]
        unsafe fn documentRange(&self) -> Retained<NSTextRange>;

        #[cfg(all(feature = "NSTextRange", feature = "block2"))]
        #[method(enumerateSubstringsFromLocation:options:usingBlock:)]
        unsafe fn enumerateSubstringsFromLocation_options_usingBlock(
            &self,
            location: &ProtocolObject<dyn NSTextLocation>,
            options: NSStringEnumerationOptions,
            block: &block2::Block<
                dyn Fn(*mut NSString, NonNull<NSTextRange>, *mut NSTextRange, NonNull<Bool>) + '_,
            >,
        );

        #[cfg(all(feature = "NSTextRange", feature = "NSTextSelection"))]
        #[method_id(@__retain_semantics Other textRangeForSelectionGranularity:enclosingLocation:)]
        unsafe fn textRangeForSelectionGranularity_enclosingLocation(
            &self,
            selection_granularity: NSTextSelectionGranularity,
            location: &ProtocolObject<dyn NSTextLocation>,
        ) -> Option<Retained<NSTextRange>>;

        #[cfg(feature = "NSTextRange")]
        #[method_id(@__retain_semantics Other locationFromLocation:withOffset:)]
        unsafe fn locationFromLocation_withOffset(
            &self,
            location: &ProtocolObject<dyn NSTextLocation>,
            offset: NSInteger,
        ) -> Option<Retained<ProtocolObject<dyn NSTextLocation>>>;

        #[cfg(feature = "NSTextRange")]
        #[method(offsetFromLocation:toLocation:)]
        unsafe fn offsetFromLocation_toLocation(
            &self,
            from: &ProtocolObject<dyn NSTextLocation>,
            to: &ProtocolObject<dyn NSTextLocation>,
        ) -> NSInteger;

        #[cfg(feature = "NSTextRange")]
        #[method(baseWritingDirectionAtLocation:)]
        unsafe fn baseWritingDirectionAtLocation(
            &self,
            location: &ProtocolObject<dyn NSTextLocation>,
        ) -> NSTextSelectionNavigationWritingDirection;

        #[cfg(all(feature = "NSTextRange", feature = "block2"))]
        #[method(enumerateCaretOffsetsInLineFragmentAtLocation:usingBlock:)]
        unsafe fn enumerateCaretOffsetsInLineFragmentAtLocation_usingBlock(
            &self,
            location: &ProtocolObject<dyn NSTextLocation>,
            block: &block2::Block<
                dyn Fn(CGFloat, NonNull<ProtocolObject<dyn NSTextLocation>>, Bool, NonNull<Bool>)
                    + '_,
            >,
        );

        #[cfg(feature = "NSTextRange")]
        #[method_id(@__retain_semantics Other lineFragmentRangeForPoint:inContainerAtLocation:)]
        unsafe fn lineFragmentRangeForPoint_inContainerAtLocation(
            &self,
            point: CGPoint,
            location: &ProtocolObject<dyn NSTextLocation>,
        ) -> Option<Retained<NSTextRange>>;

        #[cfg(all(feature = "NSTextRange", feature = "block2"))]
        #[optional]
        #[method(enumerateContainerBoundariesFromLocation:reverse:usingBlock:)]
        unsafe fn enumerateContainerBoundariesFromLocation_reverse_usingBlock(
            &self,
            location: &ProtocolObject<dyn NSTextLocation>,
            reverse: bool,
            block: &block2::Block<
                dyn Fn(NonNull<ProtocolObject<dyn NSTextLocation>>, NonNull<Bool>) + '_,
            >,
        );

        #[cfg(feature = "NSTextRange")]
        #[optional]
        #[method(textLayoutOrientationAtLocation:)]
        unsafe fn textLayoutOrientationAtLocation(
            &self,
            location: &ProtocolObject<dyn NSTextLocation>,
        ) -> NSTextSelectionNavigationLayoutOrientation;
    }

    unsafe impl ProtocolType for dyn NSTextSelectionDataSource {}
);