1use 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#[repr(transparent)]
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub struct NSTextSelectionNavigationDirection(pub NSInteger);
17impl NSTextSelectionNavigationDirection {
18 #[doc(alias = "NSTextSelectionNavigationDirectionForward")]
19 pub const Forward: Self = Self(0);
20 #[doc(alias = "NSTextSelectionNavigationDirectionBackward")]
21 pub const Backward: Self = Self(1);
22 #[doc(alias = "NSTextSelectionNavigationDirectionRight")]
23 pub const Right: Self = Self(2);
24 #[doc(alias = "NSTextSelectionNavigationDirectionLeft")]
25 pub const Left: Self = Self(3);
26 #[doc(alias = "NSTextSelectionNavigationDirectionUp")]
27 pub const Up: Self = Self(4);
28 #[doc(alias = "NSTextSelectionNavigationDirectionDown")]
29 pub const Down: Self = Self(5);
30}
31
32unsafe impl Encode for NSTextSelectionNavigationDirection {
33 const ENCODING: Encoding = NSInteger::ENCODING;
34}
35
36unsafe impl RefEncode for NSTextSelectionNavigationDirection {
37 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
38}
39
40#[repr(transparent)]
43#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
44pub struct NSTextSelectionNavigationDestination(pub NSInteger);
45impl NSTextSelectionNavigationDestination {
46 #[doc(alias = "NSTextSelectionNavigationDestinationCharacter")]
47 pub const Character: Self = Self(0);
48 #[doc(alias = "NSTextSelectionNavigationDestinationWord")]
49 pub const Word: Self = Self(1);
50 #[doc(alias = "NSTextSelectionNavigationDestinationLine")]
51 pub const Line: Self = Self(2);
52 #[doc(alias = "NSTextSelectionNavigationDestinationSentence")]
53 pub const Sentence: Self = Self(3);
54 #[doc(alias = "NSTextSelectionNavigationDestinationParagraph")]
55 pub const Paragraph: Self = Self(4);
56 #[doc(alias = "NSTextSelectionNavigationDestinationContainer")]
57 pub const Container: Self = Self(5);
58 #[doc(alias = "NSTextSelectionNavigationDestinationDocument")]
59 pub const Document: Self = Self(6);
60}
61
62unsafe impl Encode for NSTextSelectionNavigationDestination {
63 const ENCODING: Encoding = NSInteger::ENCODING;
64}
65
66unsafe impl RefEncode for NSTextSelectionNavigationDestination {
67 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
68}
69
70#[repr(transparent)]
73#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
74pub struct NSTextSelectionNavigationModifier(pub NSUInteger);
75bitflags::bitflags! {
76 impl NSTextSelectionNavigationModifier: NSUInteger {
77 #[doc(alias = "NSTextSelectionNavigationModifierExtend")]
78 const Extend = 1<<0;
79 #[doc(alias = "NSTextSelectionNavigationModifierVisual")]
80 const Visual = 1<<1;
81 #[doc(alias = "NSTextSelectionNavigationModifierMultiple")]
82 const Multiple = 1<<2;
83 }
84}
85
86unsafe impl Encode for NSTextSelectionNavigationModifier {
87 const ENCODING: Encoding = NSUInteger::ENCODING;
88}
89
90unsafe impl RefEncode for NSTextSelectionNavigationModifier {
91 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
92}
93
94#[repr(transparent)]
97#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
98pub struct NSTextSelectionNavigationWritingDirection(pub NSInteger);
99impl NSTextSelectionNavigationWritingDirection {
100 #[doc(alias = "NSTextSelectionNavigationWritingDirectionLeftToRight")]
101 pub const LeftToRight: Self = Self(0);
102 #[doc(alias = "NSTextSelectionNavigationWritingDirectionRightToLeft")]
103 pub const RightToLeft: Self = Self(1);
104}
105
106unsafe impl Encode for NSTextSelectionNavigationWritingDirection {
107 const ENCODING: Encoding = NSInteger::ENCODING;
108}
109
110unsafe impl RefEncode for NSTextSelectionNavigationWritingDirection {
111 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
112}
113
114#[repr(transparent)]
117#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
118pub struct NSTextSelectionNavigationLayoutOrientation(pub NSInteger);
119impl NSTextSelectionNavigationLayoutOrientation {
120 #[doc(alias = "NSTextSelectionNavigationLayoutOrientationHorizontal")]
121 pub const Horizontal: Self = Self(0);
122 #[doc(alias = "NSTextSelectionNavigationLayoutOrientationVertical")]
123 pub const Vertical: Self = Self(1);
124}
125
126unsafe impl Encode for NSTextSelectionNavigationLayoutOrientation {
127 const ENCODING: Encoding = NSInteger::ENCODING;
128}
129
130unsafe impl RefEncode for NSTextSelectionNavigationLayoutOrientation {
131 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
132}
133
134extern_class!(
135 #[unsafe(super(NSObject))]
137 #[derive(Debug, PartialEq, Eq, Hash)]
138 pub struct NSTextSelectionNavigation;
139);
140
141extern_conformance!(
142 unsafe impl NSObjectProtocol for NSTextSelectionNavigation {}
143);
144
145impl NSTextSelectionNavigation {
146 extern_methods!(
147 #[unsafe(method(initWithDataSource:))]
148 #[unsafe(method_family = init)]
149 pub unsafe fn initWithDataSource(
150 this: Allocated<Self>,
151 data_source: &ProtocolObject<dyn NSTextSelectionDataSource>,
152 ) -> Retained<Self>;
153
154 #[unsafe(method(new))]
155 #[unsafe(method_family = new)]
156 pub unsafe fn new() -> Retained<Self>;
157
158 #[unsafe(method(init))]
159 #[unsafe(method_family = init)]
160 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
161
162 #[unsafe(method(textSelectionDataSource))]
163 #[unsafe(method_family = none)]
164 pub unsafe fn textSelectionDataSource(
165 &self,
166 ) -> Option<Retained<ProtocolObject<dyn NSTextSelectionDataSource>>>;
167
168 #[unsafe(method(allowsNonContiguousRanges))]
169 #[unsafe(method_family = none)]
170 pub unsafe fn allowsNonContiguousRanges(&self) -> bool;
171
172 #[unsafe(method(setAllowsNonContiguousRanges:))]
174 #[unsafe(method_family = none)]
175 pub unsafe fn setAllowsNonContiguousRanges(&self, allows_non_contiguous_ranges: bool);
176
177 #[unsafe(method(rotatesCoordinateSystemForLayoutOrientation))]
178 #[unsafe(method_family = none)]
179 pub unsafe fn rotatesCoordinateSystemForLayoutOrientation(&self) -> bool;
180
181 #[unsafe(method(setRotatesCoordinateSystemForLayoutOrientation:))]
183 #[unsafe(method_family = none)]
184 pub unsafe fn setRotatesCoordinateSystemForLayoutOrientation(
185 &self,
186 rotates_coordinate_system_for_layout_orientation: bool,
187 );
188
189 #[unsafe(method(flushLayoutCache))]
190 #[unsafe(method_family = none)]
191 pub unsafe fn flushLayoutCache(&self);
192
193 #[cfg(feature = "NSTextSelection")]
194 #[unsafe(method(destinationSelectionForTextSelection:direction:destination:extending:confined:))]
195 #[unsafe(method_family = none)]
196 pub unsafe fn destinationSelectionForTextSelection_direction_destination_extending_confined(
197 &self,
198 text_selection: &NSTextSelection,
199 direction: NSTextSelectionNavigationDirection,
200 destination: NSTextSelectionNavigationDestination,
201 extending: bool,
202 confined: bool,
203 ) -> Option<Retained<NSTextSelection>>;
204
205 #[cfg(all(
206 feature = "NSTextRange",
207 feature = "NSTextSelection",
208 feature = "objc2-core-foundation"
209 ))]
210 #[unsafe(method(textSelectionsInteractingAtPoint:inContainerAtLocation:anchors:modifiers:selecting:bounds:))]
211 #[unsafe(method_family = none)]
212 pub unsafe fn textSelectionsInteractingAtPoint_inContainerAtLocation_anchors_modifiers_selecting_bounds(
213 &self,
214 point: CGPoint,
215 container_location: &ProtocolObject<dyn NSTextLocation>,
216 anchors: &NSArray<NSTextSelection>,
217 modifiers: NSTextSelectionNavigationModifier,
218 selecting: bool,
219 bounds: CGRect,
220 ) -> Retained<NSArray<NSTextSelection>>;
221
222 #[cfg(feature = "NSTextSelection")]
223 #[unsafe(method(textSelectionForSelectionGranularity:enclosingTextSelection:))]
224 #[unsafe(method_family = none)]
225 pub unsafe fn textSelectionForSelectionGranularity_enclosingTextSelection(
226 &self,
227 selection_granularity: NSTextSelectionGranularity,
228 text_selection: &NSTextSelection,
229 ) -> Retained<NSTextSelection>;
230
231 #[cfg(all(
232 feature = "NSTextRange",
233 feature = "NSTextSelection",
234 feature = "objc2-core-foundation"
235 ))]
236 #[unsafe(method(textSelectionForSelectionGranularity:enclosingPoint:inContainerAtLocation:))]
237 #[unsafe(method_family = none)]
238 pub unsafe fn textSelectionForSelectionGranularity_enclosingPoint_inContainerAtLocation(
239 &self,
240 selection_granularity: NSTextSelectionGranularity,
241 point: CGPoint,
242 location: &ProtocolObject<dyn NSTextLocation>,
243 ) -> Option<Retained<NSTextSelection>>;
244
245 #[cfg(all(feature = "NSTextRange", feature = "NSTextSelection"))]
246 #[unsafe(method(resolvedInsertionLocationForTextSelection:writingDirection:))]
247 #[unsafe(method_family = none)]
248 pub unsafe fn resolvedInsertionLocationForTextSelection_writingDirection(
249 &self,
250 text_selection: &NSTextSelection,
251 writing_direction: NSTextSelectionNavigationWritingDirection,
252 ) -> Option<Retained<ProtocolObject<dyn NSTextLocation>>>;
253
254 #[cfg(all(feature = "NSTextRange", feature = "NSTextSelection"))]
255 #[unsafe(method(deletionRangesForTextSelection:direction:destination:allowsDecomposition:))]
256 #[unsafe(method_family = none)]
257 pub unsafe fn deletionRangesForTextSelection_direction_destination_allowsDecomposition(
258 &self,
259 text_selection: &NSTextSelection,
260 direction: NSTextSelectionNavigationDirection,
261 destination: NSTextSelectionNavigationDestination,
262 allows_decomposition: bool,
263 ) -> Retained<NSArray<NSTextRange>>;
264 );
265}
266
267extern_protocol!(
268 pub unsafe trait NSTextSelectionDataSource: NSObjectProtocol {
270 #[cfg(feature = "NSTextRange")]
271 #[unsafe(method(documentRange))]
272 #[unsafe(method_family = none)]
273 unsafe fn documentRange(&self) -> Retained<NSTextRange>;
274
275 #[cfg(all(feature = "NSTextRange", feature = "block2"))]
276 #[unsafe(method(enumerateSubstringsFromLocation:options:usingBlock:))]
277 #[unsafe(method_family = none)]
278 unsafe fn enumerateSubstringsFromLocation_options_usingBlock(
279 &self,
280 location: &ProtocolObject<dyn NSTextLocation>,
281 options: NSStringEnumerationOptions,
282 block: &block2::DynBlock<
283 dyn Fn(*mut NSString, NonNull<NSTextRange>, *mut NSTextRange, NonNull<Bool>) + '_,
284 >,
285 );
286
287 #[cfg(all(feature = "NSTextRange", feature = "NSTextSelection"))]
288 #[unsafe(method(textRangeForSelectionGranularity:enclosingLocation:))]
289 #[unsafe(method_family = none)]
290 unsafe fn textRangeForSelectionGranularity_enclosingLocation(
291 &self,
292 selection_granularity: NSTextSelectionGranularity,
293 location: &ProtocolObject<dyn NSTextLocation>,
294 ) -> Option<Retained<NSTextRange>>;
295
296 #[cfg(feature = "NSTextRange")]
297 #[unsafe(method(locationFromLocation:withOffset:))]
298 #[unsafe(method_family = none)]
299 unsafe fn locationFromLocation_withOffset(
300 &self,
301 location: &ProtocolObject<dyn NSTextLocation>,
302 offset: NSInteger,
303 ) -> Option<Retained<ProtocolObject<dyn NSTextLocation>>>;
304
305 #[cfg(feature = "NSTextRange")]
306 #[unsafe(method(offsetFromLocation:toLocation:))]
307 #[unsafe(method_family = none)]
308 unsafe fn offsetFromLocation_toLocation(
309 &self,
310 from: &ProtocolObject<dyn NSTextLocation>,
311 to: &ProtocolObject<dyn NSTextLocation>,
312 ) -> NSInteger;
313
314 #[cfg(feature = "NSTextRange")]
315 #[unsafe(method(baseWritingDirectionAtLocation:))]
316 #[unsafe(method_family = none)]
317 unsafe fn baseWritingDirectionAtLocation(
318 &self,
319 location: &ProtocolObject<dyn NSTextLocation>,
320 ) -> NSTextSelectionNavigationWritingDirection;
321
322 #[cfg(all(
323 feature = "NSTextRange",
324 feature = "block2",
325 feature = "objc2-core-foundation"
326 ))]
327 #[unsafe(method(enumerateCaretOffsetsInLineFragmentAtLocation:usingBlock:))]
328 #[unsafe(method_family = none)]
329 unsafe fn enumerateCaretOffsetsInLineFragmentAtLocation_usingBlock(
330 &self,
331 location: &ProtocolObject<dyn NSTextLocation>,
332 block: &block2::DynBlock<
333 dyn Fn(CGFloat, NonNull<ProtocolObject<dyn NSTextLocation>>, Bool, NonNull<Bool>)
334 + '_,
335 >,
336 );
337
338 #[cfg(all(feature = "NSTextRange", feature = "objc2-core-foundation"))]
339 #[unsafe(method(lineFragmentRangeForPoint:inContainerAtLocation:))]
340 #[unsafe(method_family = none)]
341 unsafe fn lineFragmentRangeForPoint_inContainerAtLocation(
342 &self,
343 point: CGPoint,
344 location: &ProtocolObject<dyn NSTextLocation>,
345 ) -> Option<Retained<NSTextRange>>;
346
347 #[cfg(all(feature = "NSTextRange", feature = "block2"))]
348 #[optional]
349 #[unsafe(method(enumerateContainerBoundariesFromLocation:reverse:usingBlock:))]
350 #[unsafe(method_family = none)]
351 unsafe fn enumerateContainerBoundariesFromLocation_reverse_usingBlock(
352 &self,
353 location: &ProtocolObject<dyn NSTextLocation>,
354 reverse: bool,
355 block: &block2::DynBlock<
356 dyn Fn(NonNull<ProtocolObject<dyn NSTextLocation>>, NonNull<Bool>) + '_,
357 >,
358 );
359
360 #[cfg(feature = "NSTextRange")]
361 #[optional]
362 #[unsafe(method(textLayoutOrientationAtLocation:))]
363 #[unsafe(method_family = none)]
364 unsafe fn textLayoutOrientationAtLocation(
365 &self,
366 location: &ProtocolObject<dyn NSTextLocation>,
367 ) -> NSTextSelectionNavigationLayoutOrientation;
368 }
369);