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 NSTextLayoutManagerSegmentType(pub NSInteger);
17impl NSTextLayoutManagerSegmentType {
18 #[doc(alias = "NSTextLayoutManagerSegmentTypeStandard")]
19 pub const Standard: Self = Self(0);
20 #[doc(alias = "NSTextLayoutManagerSegmentTypeSelection")]
21 pub const Selection: Self = Self(1);
22 #[doc(alias = "NSTextLayoutManagerSegmentTypeHighlight")]
23 pub const Highlight: Self = Self(2);
24}
25
26unsafe impl Encode for NSTextLayoutManagerSegmentType {
27 const ENCODING: Encoding = NSInteger::ENCODING;
28}
29
30unsafe impl RefEncode for NSTextLayoutManagerSegmentType {
31 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
32}
33
34#[repr(transparent)]
37#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
38pub struct NSTextLayoutManagerSegmentOptions(pub NSUInteger);
39bitflags::bitflags! {
40 impl NSTextLayoutManagerSegmentOptions: NSUInteger {
41 #[doc(alias = "NSTextLayoutManagerSegmentOptionsNone")]
42 const None = 0;
43 #[doc(alias = "NSTextLayoutManagerSegmentOptionsRangeNotRequired")]
44 const RangeNotRequired = 1<<0;
45 #[doc(alias = "NSTextLayoutManagerSegmentOptionsMiddleFragmentsExcluded")]
46 const MiddleFragmentsExcluded = 1<<1;
47 #[doc(alias = "NSTextLayoutManagerSegmentOptionsHeadSegmentExtended")]
48 const HeadSegmentExtended = 1<<2;
49 #[doc(alias = "NSTextLayoutManagerSegmentOptionsTailSegmentExtended")]
50 const TailSegmentExtended = 1<<3;
51 #[doc(alias = "NSTextLayoutManagerSegmentOptionsUpstreamAffinity")]
52 const UpstreamAffinity = 1<<4;
53 }
54}
55
56unsafe impl Encode for NSTextLayoutManagerSegmentOptions {
57 const ENCODING: Encoding = NSUInteger::ENCODING;
58}
59
60unsafe impl RefEncode for NSTextLayoutManagerSegmentOptions {
61 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
62}
63
64extern_class!(
65 #[unsafe(super(NSObject))]
67 #[derive(Debug, PartialEq, Eq, Hash)]
68 pub struct NSTextLayoutManager;
69);
70
71extern_conformance!(
72 unsafe impl NSCoding for NSTextLayoutManager {}
73);
74
75extern_conformance!(
76 unsafe impl NSObjectProtocol for NSTextLayoutManager {}
77);
78
79extern_conformance!(
80 unsafe impl NSSecureCoding for NSTextLayoutManager {}
81);
82
83#[cfg(feature = "NSTextSelectionNavigation")]
84extern_conformance!(
85 unsafe impl NSTextSelectionDataSource for NSTextLayoutManager {}
86);
87
88impl NSTextLayoutManager {
89 extern_methods!(
90 #[unsafe(method(init))]
91 #[unsafe(method_family = init)]
92 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
93
94 #[unsafe(method(initWithCoder:))]
95 #[unsafe(method_family = init)]
96 pub unsafe fn initWithCoder(
97 this: Allocated<Self>,
98 coder: &NSCoder,
99 ) -> Option<Retained<Self>>;
100
101 #[unsafe(method(delegate))]
102 #[unsafe(method_family = none)]
103 pub unsafe fn delegate(
104 &self,
105 ) -> Option<Retained<ProtocolObject<dyn NSTextLayoutManagerDelegate>>>;
106
107 #[unsafe(method(setDelegate:))]
110 #[unsafe(method_family = none)]
111 pub unsafe fn setDelegate(
112 &self,
113 delegate: Option<&ProtocolObject<dyn NSTextLayoutManagerDelegate>>,
114 );
115
116 #[unsafe(method(usesFontLeading))]
117 #[unsafe(method_family = none)]
118 pub unsafe fn usesFontLeading(&self) -> bool;
119
120 #[unsafe(method(setUsesFontLeading:))]
122 #[unsafe(method_family = none)]
123 pub unsafe fn setUsesFontLeading(&self, uses_font_leading: bool);
124
125 #[unsafe(method(limitsLayoutForSuspiciousContents))]
126 #[unsafe(method_family = none)]
127 pub unsafe fn limitsLayoutForSuspiciousContents(&self) -> bool;
128
129 #[unsafe(method(setLimitsLayoutForSuspiciousContents:))]
131 #[unsafe(method_family = none)]
132 pub unsafe fn setLimitsLayoutForSuspiciousContents(
133 &self,
134 limits_layout_for_suspicious_contents: bool,
135 );
136
137 #[unsafe(method(usesHyphenation))]
138 #[unsafe(method_family = none)]
139 pub unsafe fn usesHyphenation(&self) -> bool;
140
141 #[unsafe(method(setUsesHyphenation:))]
143 #[unsafe(method_family = none)]
144 pub unsafe fn setUsesHyphenation(&self, uses_hyphenation: bool);
145
146 #[cfg(feature = "NSTextContentManager")]
147 #[unsafe(method(textContentManager))]
148 #[unsafe(method_family = none)]
149 pub unsafe fn textContentManager(&self) -> Option<Retained<NSTextContentManager>>;
150
151 #[cfg(feature = "NSTextContentManager")]
152 #[unsafe(method(replaceTextContentManager:))]
153 #[unsafe(method_family = none)]
154 pub unsafe fn replaceTextContentManager(&self, text_content_manager: &NSTextContentManager);
155
156 #[cfg(feature = "NSTextContainer")]
157 #[unsafe(method(textContainer))]
158 #[unsafe(method_family = none)]
159 pub unsafe fn textContainer(&self) -> Option<Retained<NSTextContainer>>;
160
161 #[cfg(feature = "NSTextContainer")]
162 #[unsafe(method(setTextContainer:))]
164 #[unsafe(method_family = none)]
165 pub unsafe fn setTextContainer(&self, text_container: Option<&NSTextContainer>);
166
167 #[cfg(feature = "objc2-core-foundation")]
168 #[unsafe(method(usageBoundsForTextContainer))]
169 #[unsafe(method_family = none)]
170 pub unsafe fn usageBoundsForTextContainer(&self) -> CGRect;
171
172 #[cfg(feature = "NSTextViewportLayoutController")]
173 #[unsafe(method(textViewportLayoutController))]
174 #[unsafe(method_family = none)]
175 pub unsafe fn textViewportLayoutController(
176 &self,
177 ) -> Retained<NSTextViewportLayoutController>;
178
179 #[unsafe(method(layoutQueue))]
180 #[unsafe(method_family = none)]
181 pub unsafe fn layoutQueue(&self) -> Option<Retained<NSOperationQueue>>;
182
183 #[unsafe(method(setLayoutQueue:))]
185 #[unsafe(method_family = none)]
186 pub unsafe fn setLayoutQueue(&self, layout_queue: Option<&NSOperationQueue>);
187
188 #[cfg(feature = "NSTextRange")]
189 #[unsafe(method(ensureLayoutForRange:))]
190 #[unsafe(method_family = none)]
191 pub unsafe fn ensureLayoutForRange(&self, range: &NSTextRange);
192
193 #[cfg(feature = "objc2-core-foundation")]
194 #[unsafe(method(ensureLayoutForBounds:))]
195 #[unsafe(method_family = none)]
196 pub unsafe fn ensureLayoutForBounds(&self, bounds: CGRect);
197
198 #[cfg(feature = "NSTextRange")]
199 #[unsafe(method(invalidateLayoutForRange:))]
200 #[unsafe(method_family = none)]
201 pub unsafe fn invalidateLayoutForRange(&self, range: &NSTextRange);
202
203 #[cfg(all(feature = "NSTextLayoutFragment", feature = "objc2-core-foundation"))]
204 #[unsafe(method(textLayoutFragmentForPosition:))]
205 #[unsafe(method_family = none)]
206 pub unsafe fn textLayoutFragmentForPosition(
207 &self,
208 position: CGPoint,
209 ) -> Option<Retained<NSTextLayoutFragment>>;
210
211 #[cfg(all(feature = "NSTextLayoutFragment", feature = "NSTextRange"))]
212 #[unsafe(method(textLayoutFragmentForLocation:))]
213 #[unsafe(method_family = none)]
214 pub unsafe fn textLayoutFragmentForLocation(
215 &self,
216 location: &ProtocolObject<dyn NSTextLocation>,
217 ) -> Option<Retained<NSTextLayoutFragment>>;
218
219 #[cfg(all(
220 feature = "NSTextLayoutFragment",
221 feature = "NSTextRange",
222 feature = "block2"
223 ))]
224 #[unsafe(method(enumerateTextLayoutFragmentsFromLocation:options:usingBlock:))]
225 #[unsafe(method_family = none)]
226 pub unsafe fn enumerateTextLayoutFragmentsFromLocation_options_usingBlock(
227 &self,
228 location: Option<&ProtocolObject<dyn NSTextLocation>>,
229 options: NSTextLayoutFragmentEnumerationOptions,
230 block: &block2::DynBlock<dyn Fn(NonNull<NSTextLayoutFragment>) -> Bool + '_>,
231 ) -> Option<Retained<ProtocolObject<dyn NSTextLocation>>>;
232
233 #[cfg(feature = "NSTextSelection")]
234 #[unsafe(method(textSelections))]
235 #[unsafe(method_family = none)]
236 pub unsafe fn textSelections(&self) -> Retained<NSArray<NSTextSelection>>;
237
238 #[cfg(feature = "NSTextSelection")]
239 #[unsafe(method(setTextSelections:))]
241 #[unsafe(method_family = none)]
242 pub unsafe fn setTextSelections(&self, text_selections: &NSArray<NSTextSelection>);
243
244 #[cfg(feature = "NSTextSelectionNavigation")]
245 #[unsafe(method(textSelectionNavigation))]
246 #[unsafe(method_family = none)]
247 pub unsafe fn textSelectionNavigation(&self) -> Retained<NSTextSelectionNavigation>;
248
249 #[cfg(feature = "NSTextSelectionNavigation")]
250 #[unsafe(method(setTextSelectionNavigation:))]
252 #[unsafe(method_family = none)]
253 pub unsafe fn setTextSelectionNavigation(
254 &self,
255 text_selection_navigation: &NSTextSelectionNavigation,
256 );
257
258 #[cfg(all(feature = "NSTextRange", feature = "block2"))]
259 #[unsafe(method(enumerateRenderingAttributesFromLocation:reverse:usingBlock:))]
260 #[unsafe(method_family = none)]
261 pub unsafe fn enumerateRenderingAttributesFromLocation_reverse_usingBlock(
262 &self,
263 location: &ProtocolObject<dyn NSTextLocation>,
264 reverse: bool,
265 block: &block2::DynBlock<
266 dyn Fn(
267 NonNull<NSTextLayoutManager>,
268 NonNull<NSDictionary<NSAttributedStringKey, AnyObject>>,
269 NonNull<NSTextRange>,
270 ) -> Bool
271 + '_,
272 >,
273 );
274
275 #[cfg(feature = "NSTextRange")]
276 #[unsafe(method(setRenderingAttributes:forTextRange:))]
277 #[unsafe(method_family = none)]
278 pub unsafe fn setRenderingAttributes_forTextRange(
279 &self,
280 rendering_attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
281 text_range: &NSTextRange,
282 );
283
284 #[cfg(feature = "NSTextRange")]
285 #[unsafe(method(addRenderingAttribute:value:forTextRange:))]
286 #[unsafe(method_family = none)]
287 pub unsafe fn addRenderingAttribute_value_forTextRange(
288 &self,
289 rendering_attribute: &NSAttributedStringKey,
290 value: Option<&AnyObject>,
291 text_range: &NSTextRange,
292 );
293
294 #[cfg(feature = "NSTextRange")]
295 #[unsafe(method(removeRenderingAttribute:forTextRange:))]
296 #[unsafe(method_family = none)]
297 pub unsafe fn removeRenderingAttribute_forTextRange(
298 &self,
299 rendering_attribute: &NSAttributedStringKey,
300 text_range: &NSTextRange,
301 );
302
303 #[cfg(feature = "NSTextRange")]
304 #[unsafe(method(invalidateRenderingAttributesForTextRange:))]
305 #[unsafe(method_family = none)]
306 pub unsafe fn invalidateRenderingAttributesForTextRange(&self, text_range: &NSTextRange);
307
308 #[cfg(all(feature = "NSTextLayoutFragment", feature = "block2"))]
309 #[unsafe(method(renderingAttributesValidator))]
310 #[unsafe(method_family = none)]
311 pub unsafe fn renderingAttributesValidator(
312 &self,
313 ) -> *mut block2::DynBlock<
314 dyn Fn(NonNull<NSTextLayoutManager>, NonNull<NSTextLayoutFragment>),
315 >;
316
317 #[cfg(all(feature = "NSTextLayoutFragment", feature = "block2"))]
318 #[unsafe(method(setRenderingAttributesValidator:))]
320 #[unsafe(method_family = none)]
321 pub unsafe fn setRenderingAttributesValidator(
322 &self,
323 rendering_attributes_validator: Option<
324 &block2::DynBlock<
325 dyn Fn(NonNull<NSTextLayoutManager>, NonNull<NSTextLayoutFragment>),
326 >,
327 >,
328 );
329
330 #[unsafe(method(linkRenderingAttributes))]
331 #[unsafe(method_family = none)]
332 pub unsafe fn linkRenderingAttributes(
333 ) -> Retained<NSDictionary<NSAttributedStringKey, AnyObject>>;
334
335 #[cfg(feature = "NSTextRange")]
336 #[unsafe(method(renderingAttributesForLink:atLocation:))]
337 #[unsafe(method_family = none)]
338 pub unsafe fn renderingAttributesForLink_atLocation(
339 &self,
340 link: &AnyObject,
341 location: &ProtocolObject<dyn NSTextLocation>,
342 ) -> Retained<NSDictionary<NSAttributedStringKey, AnyObject>>;
343
344 #[cfg(all(
345 feature = "NSTextContainer",
346 feature = "NSTextRange",
347 feature = "block2",
348 feature = "objc2-core-foundation"
349 ))]
350 #[unsafe(method(enumerateTextSegmentsInRange:type:options:usingBlock:))]
351 #[unsafe(method_family = none)]
352 pub unsafe fn enumerateTextSegmentsInRange_type_options_usingBlock(
353 &self,
354 text_range: &NSTextRange,
355 r#type: NSTextLayoutManagerSegmentType,
356 options: NSTextLayoutManagerSegmentOptions,
357 block: &block2::DynBlock<
358 dyn Fn(*mut NSTextRange, CGRect, CGFloat, NonNull<NSTextContainer>) -> Bool + '_,
359 >,
360 );
361
362 #[cfg(all(feature = "NSTextElement", feature = "NSTextRange"))]
363 #[unsafe(method(replaceContentsInRange:withTextElements:))]
364 #[unsafe(method_family = none)]
365 pub unsafe fn replaceContentsInRange_withTextElements(
366 &self,
367 range: &NSTextRange,
368 text_elements: &NSArray<NSTextElement>,
369 );
370
371 #[cfg(feature = "NSTextRange")]
372 #[unsafe(method(replaceContentsInRange:withAttributedString:))]
373 #[unsafe(method_family = none)]
374 pub unsafe fn replaceContentsInRange_withAttributedString(
375 &self,
376 range: &NSTextRange,
377 attributed_string: &NSAttributedString,
378 );
379 );
380}
381
382impl NSTextLayoutManager {
384 extern_methods!(
385 #[unsafe(method(new))]
386 #[unsafe(method_family = new)]
387 pub unsafe fn new() -> Retained<Self>;
388 );
389}
390
391extern_protocol!(
392 pub unsafe trait NSTextLayoutManagerDelegate: NSObjectProtocol {
394 #[cfg(all(
395 feature = "NSTextElement",
396 feature = "NSTextLayoutFragment",
397 feature = "NSTextRange"
398 ))]
399 #[optional]
400 #[unsafe(method(textLayoutManager:textLayoutFragmentForLocation:inTextElement:))]
401 #[unsafe(method_family = none)]
402 unsafe fn textLayoutManager_textLayoutFragmentForLocation_inTextElement(
403 &self,
404 text_layout_manager: &NSTextLayoutManager,
405 location: &ProtocolObject<dyn NSTextLocation>,
406 text_element: &NSTextElement,
407 ) -> Retained<NSTextLayoutFragment>;
408
409 #[cfg(feature = "NSTextRange")]
410 #[optional]
411 #[unsafe(method(textLayoutManager:shouldBreakLineBeforeLocation:hyphenating:))]
412 #[unsafe(method_family = none)]
413 unsafe fn textLayoutManager_shouldBreakLineBeforeLocation_hyphenating(
414 &self,
415 text_layout_manager: &NSTextLayoutManager,
416 location: &ProtocolObject<dyn NSTextLocation>,
417 hyphenating: bool,
418 ) -> bool;
419
420 #[cfg(feature = "NSTextRange")]
421 #[optional]
422 #[unsafe(method(textLayoutManager:renderingAttributesForLink:atLocation:defaultAttributes:))]
423 #[unsafe(method_family = none)]
424 unsafe fn textLayoutManager_renderingAttributesForLink_atLocation_defaultAttributes(
425 &self,
426 text_layout_manager: &NSTextLayoutManager,
427 link: &AnyObject,
428 location: &ProtocolObject<dyn NSTextLocation>,
429 rendering_attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
430 ) -> Option<Retained<NSDictionary<NSAttributedStringKey, AnyObject>>>;
431 }
432);