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
//! 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 NSTextSelectionGranularity(pub NSInteger);
impl NSTextSelectionGranularity {
    #[doc(alias = "NSTextSelectionGranularityCharacter")]
    pub const Character: Self = Self(0);
    #[doc(alias = "NSTextSelectionGranularityWord")]
    pub const Word: Self = Self(1);
    #[doc(alias = "NSTextSelectionGranularityParagraph")]
    pub const Paragraph: Self = Self(2);
    #[doc(alias = "NSTextSelectionGranularityLine")]
    pub const Line: Self = Self(3);
    #[doc(alias = "NSTextSelectionGranularitySentence")]
    pub const Sentence: Self = Self(4);
}

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

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

// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct NSTextSelectionAffinity(pub NSInteger);
impl NSTextSelectionAffinity {
    #[doc(alias = "NSTextSelectionAffinityUpstream")]
    pub const Upstream: Self = Self(0);
    #[doc(alias = "NSTextSelectionAffinityDownstream")]
    pub const Downstream: Self = Self(1);
}

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

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

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

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

unsafe impl NSCoding for NSTextSelection {}

unsafe impl NSObjectProtocol for NSTextSelection {}

unsafe impl NSSecureCoding for NSTextSelection {}

extern_methods!(
    unsafe impl NSTextSelection {
        #[cfg(feature = "NSTextRange")]
        #[method_id(@__retain_semantics Init initWithRanges:affinity:granularity:)]
        pub unsafe fn initWithRanges_affinity_granularity(
            this: Allocated<Self>,
            text_ranges: &NSArray<NSTextRange>,
            affinity: NSTextSelectionAffinity,
            granularity: NSTextSelectionGranularity,
        ) -> Retained<Self>;

        #[method_id(@__retain_semantics Init initWithCoder:)]
        pub unsafe fn initWithCoder(
            this: Allocated<Self>,
            coder: &NSCoder,
        ) -> Option<Retained<Self>>;

        #[cfg(feature = "NSTextRange")]
        #[method_id(@__retain_semantics Init initWithRange:affinity:granularity:)]
        pub unsafe fn initWithRange_affinity_granularity(
            this: Allocated<Self>,
            range: &NSTextRange,
            affinity: NSTextSelectionAffinity,
            granularity: NSTextSelectionGranularity,
        ) -> Retained<Self>;

        #[cfg(feature = "NSTextRange")]
        #[method_id(@__retain_semantics Init initWithLocation:affinity:)]
        pub unsafe fn initWithLocation_affinity(
            this: Allocated<Self>,
            location: &ProtocolObject<dyn NSTextLocation>,
            affinity: NSTextSelectionAffinity,
        ) -> Retained<Self>;

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

        #[cfg(feature = "NSTextRange")]
        #[method_id(@__retain_semantics Other textRanges)]
        pub unsafe fn textRanges(&self) -> Retained<NSArray<NSTextRange>>;

        #[method(granularity)]
        pub unsafe fn granularity(&self) -> NSTextSelectionGranularity;

        #[method(affinity)]
        pub unsafe fn affinity(&self) -> NSTextSelectionAffinity;

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

        #[method(anchorPositionOffset)]
        pub unsafe fn anchorPositionOffset(&self) -> CGFloat;

        #[method(setAnchorPositionOffset:)]
        pub unsafe fn setAnchorPositionOffset(&self, anchor_position_offset: CGFloat);

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

        #[method(setLogical:)]
        pub unsafe fn setLogical(&self, logical: bool);

        #[cfg(feature = "NSTextRange")]
        #[method_id(@__retain_semantics Other secondarySelectionLocation)]
        pub unsafe fn secondarySelectionLocation(
            &self,
        ) -> Option<Retained<ProtocolObject<dyn NSTextLocation>>>;

        #[cfg(feature = "NSTextRange")]
        #[method(setSecondarySelectionLocation:)]
        pub unsafe fn setSecondarySelectionLocation(
            &self,
            secondary_selection_location: Option<&ProtocolObject<dyn NSTextLocation>>,
        );

        #[method_id(@__retain_semantics Other typingAttributes)]
        pub unsafe fn typingAttributes(
            &self,
        ) -> Retained<NSDictionary<NSAttributedStringKey, AnyObject>>;

        #[method(setTypingAttributes:)]
        pub unsafe fn setTypingAttributes(
            &self,
            typing_attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
        );

        #[cfg(feature = "NSTextRange")]
        #[method_id(@__retain_semantics Other textSelectionWithTextRanges:)]
        pub unsafe fn textSelectionWithTextRanges(
            &self,
            text_ranges: &NSArray<NSTextRange>,
        ) -> Retained<NSTextSelection>;
    }
);

extern_methods!(
    /// Methods declared on superclass `NSObject`
    unsafe impl NSTextSelection {
        #[method_id(@__retain_semantics New new)]
        pub unsafe fn new() -> Retained<Self>;
    }
);