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
12pub const NSAttachmentCharacter: c_uint = 0xFFFC;
14
15extern_protocol!(
16 pub unsafe trait NSTextAttachmentLayout: NSObjectProtocol {
18 #[cfg(all(
19 feature = "NSImage",
20 feature = "NSTextContainer",
21 feature = "NSTextRange",
22 feature = "objc2-core-foundation"
23 ))]
24 #[unsafe(method(imageForBounds:attributes:location:textContainer:))]
28 #[unsafe(method_family = none)]
29 unsafe fn imageForBounds_attributes_location_textContainer(
30 &self,
31 bounds: CGRect,
32 attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
33 location: &ProtocolObject<dyn NSTextLocation>,
34 text_container: Option<&NSTextContainer>,
35 ) -> Option<Retained<NSImage>>;
36
37 #[cfg(all(
38 feature = "NSTextContainer",
39 feature = "NSTextRange",
40 feature = "objc2-core-foundation"
41 ))]
42 #[unsafe(method(attachmentBoundsForAttributes:location:textContainer:proposedLineFragment:position:))]
46 #[unsafe(method_family = none)]
47 unsafe fn attachmentBoundsForAttributes_location_textContainer_proposedLineFragment_position(
48 &self,
49 attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
50 location: &ProtocolObject<dyn NSTextLocation>,
51 text_container: Option<&NSTextContainer>,
52 proposed_line_fragment: CGRect,
53 position: CGPoint,
54 ) -> CGRect;
55
56 #[cfg(all(
57 feature = "NSResponder",
58 feature = "NSTextContainer",
59 feature = "NSTextRange",
60 feature = "NSView"
61 ))]
62 #[unsafe(method(viewProviderForParentView:location:textContainer:))]
63 #[unsafe(method_family = none)]
64 fn viewProviderForParentView_location_textContainer(
65 &self,
66 parent_view: Option<&NSView>,
67 location: &ProtocolObject<dyn NSTextLocation>,
68 text_container: Option<&NSTextContainer>,
69 ) -> Option<Retained<NSTextAttachmentViewProvider>>;
70 }
71);
72
73extern_class!(
74 #[unsafe(super(NSObject))]
76 #[derive(Debug, PartialEq, Eq, Hash)]
77 pub struct NSTextAttachment;
78);
79
80extern_conformance!(
81 unsafe impl NSCoding for NSTextAttachment {}
82);
83
84extern_conformance!(
85 unsafe impl NSObjectProtocol for NSTextAttachment {}
86);
87
88extern_conformance!(
89 unsafe impl NSSecureCoding for NSTextAttachment {}
90);
91
92extern_conformance!(
93 unsafe impl NSTextAttachmentLayout for NSTextAttachment {}
94);
95
96impl NSTextAttachment {
97 extern_methods!(
98 #[unsafe(method(initWithData:ofType:))]
100 #[unsafe(method_family = init)]
101 pub fn initWithData_ofType(
102 this: Allocated<Self>,
103 content_data: Option<&NSData>,
104 uti: Option<&NSString>,
105 ) -> Retained<Self>;
106
107 #[unsafe(method(initWithFileWrapper:))]
108 #[unsafe(method_family = init)]
109 pub fn initWithFileWrapper(
110 this: Allocated<Self>,
111 file_wrapper: Option<&NSFileWrapper>,
112 ) -> Retained<Self>;
113
114 #[unsafe(method(contents))]
116 #[unsafe(method_family = none)]
117 pub fn contents(&self) -> Option<Retained<NSData>>;
118
119 #[unsafe(method(setContents:))]
123 #[unsafe(method_family = none)]
124 pub fn setContents(&self, contents: Option<&NSData>);
125
126 #[unsafe(method(fileType))]
127 #[unsafe(method_family = none)]
128 pub fn fileType(&self) -> Option<Retained<NSString>>;
129
130 #[unsafe(method(setFileType:))]
134 #[unsafe(method_family = none)]
135 pub fn setFileType(&self, file_type: Option<&NSString>);
136
137 #[cfg(feature = "NSImage")]
138 #[unsafe(method(image))]
140 #[unsafe(method_family = none)]
141 pub fn image(&self) -> Option<Retained<NSImage>>;
142
143 #[cfg(feature = "NSImage")]
144 #[unsafe(method(setImage:))]
146 #[unsafe(method_family = none)]
147 pub fn setImage(&self, image: Option<&NSImage>);
148
149 #[cfg(feature = "objc2-core-foundation")]
150 #[unsafe(method(bounds))]
151 #[unsafe(method_family = none)]
152 pub fn bounds(&self) -> CGRect;
153
154 #[cfg(feature = "objc2-core-foundation")]
155 #[unsafe(method(setBounds:))]
157 #[unsafe(method_family = none)]
158 pub fn setBounds(&self, bounds: CGRect);
159
160 #[unsafe(method(fileWrapper))]
162 #[unsafe(method_family = none)]
163 pub fn fileWrapper(&self) -> Option<Retained<NSFileWrapper>>;
164
165 #[unsafe(method(setFileWrapper:))]
167 #[unsafe(method_family = none)]
168 pub fn setFileWrapper(&self, file_wrapper: Option<&NSFileWrapper>);
169
170 #[cfg(feature = "NSTextAttachmentCell")]
171 #[unsafe(method(attachmentCell))]
172 #[unsafe(method_family = none)]
173 pub fn attachmentCell(
174 &self,
175 ) -> Option<Retained<ProtocolObject<dyn NSTextAttachmentCellProtocol>>>;
176
177 #[cfg(feature = "NSTextAttachmentCell")]
178 #[unsafe(method(setAttachmentCell:))]
180 #[unsafe(method_family = none)]
181 pub fn setAttachmentCell(
182 &self,
183 attachment_cell: Option<&ProtocolObject<dyn NSTextAttachmentCellProtocol>>,
184 );
185
186 #[cfg(feature = "objc2-core-foundation")]
187 #[unsafe(method(lineLayoutPadding))]
188 #[unsafe(method_family = none)]
189 pub fn lineLayoutPadding(&self) -> CGFloat;
190
191 #[cfg(feature = "objc2-core-foundation")]
192 #[unsafe(method(setLineLayoutPadding:))]
194 #[unsafe(method_family = none)]
195 pub fn setLineLayoutPadding(&self, line_layout_padding: CGFloat);
196
197 #[unsafe(method(textAttachmentViewProviderClassForFileType:))]
198 #[unsafe(method_family = none)]
199 pub fn textAttachmentViewProviderClassForFileType(
200 file_type: &NSString,
201 ) -> Option<&'static AnyClass>;
202
203 #[unsafe(method(registerTextAttachmentViewProviderClass:forFileType:))]
207 #[unsafe(method_family = none)]
208 pub unsafe fn registerTextAttachmentViewProviderClass_forFileType(
209 text_attachment_view_provider_class: &AnyClass,
210 file_type: &NSString,
211 );
212
213 #[unsafe(method(allowsTextAttachmentView))]
214 #[unsafe(method_family = none)]
215 pub fn allowsTextAttachmentView(&self) -> bool;
216
217 #[unsafe(method(setAllowsTextAttachmentView:))]
219 #[unsafe(method_family = none)]
220 pub fn setAllowsTextAttachmentView(&self, allows_text_attachment_view: bool);
221
222 #[unsafe(method(usesTextAttachmentView))]
223 #[unsafe(method_family = none)]
224 pub fn usesTextAttachmentView(&self) -> bool;
225 );
226}
227
228impl NSTextAttachment {
230 extern_methods!(
231 #[unsafe(method(init))]
232 #[unsafe(method_family = init)]
233 pub fn init(this: Allocated<Self>) -> Retained<Self>;
234
235 #[unsafe(method(new))]
236 #[unsafe(method_family = new)]
237 pub fn new() -> Retained<Self>;
238 );
239}
240
241impl DefaultRetained for NSTextAttachment {
242 #[inline]
243 fn default_retained() -> Retained<Self> {
244 Self::new()
245 }
246}
247
248mod private_NSAttributedStringAttachmentConveniences {
249 pub trait Sealed {}
250}
251
252pub unsafe trait NSAttributedStringAttachmentConveniences:
254 ClassType + Sized + private_NSAttributedStringAttachmentConveniences::Sealed
255{
256 extern_methods!(
257 #[unsafe(method(attributedStringWithAttachment:))]
258 #[unsafe(method_family = none)]
259 fn attributedStringWithAttachment(
260 attachment: &NSTextAttachment,
261 ) -> Retained<NSAttributedString>;
262
263 #[unsafe(method(attributedStringWithAttachment:attributes:))]
267 #[unsafe(method_family = none)]
268 unsafe fn attributedStringWithAttachment_attributes(
269 attachment: &NSTextAttachment,
270 attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
271 ) -> Retained<Self>;
272 );
273}
274
275impl private_NSAttributedStringAttachmentConveniences::Sealed for NSAttributedString {}
276unsafe impl NSAttributedStringAttachmentConveniences for NSAttributedString {}
277
278extern_class!(
279 #[unsafe(super(NSObject))]
281 #[derive(Debug, PartialEq, Eq, Hash)]
282 pub struct NSTextAttachmentViewProvider;
283);
284
285extern_conformance!(
286 unsafe impl NSObjectProtocol for NSTextAttachmentViewProvider {}
287);
288
289impl NSTextAttachmentViewProvider {
290 extern_methods!(
291 #[cfg(all(
292 feature = "NSResponder",
293 feature = "NSTextLayoutManager",
294 feature = "NSTextRange",
295 feature = "NSView"
296 ))]
297 #[unsafe(method(initWithTextAttachment:parentView:textLayoutManager:location:))]
298 #[unsafe(method_family = init)]
299 pub fn initWithTextAttachment_parentView_textLayoutManager_location(
300 this: Allocated<Self>,
301 text_attachment: &NSTextAttachment,
302 parent_view: Option<&NSView>,
303 text_layout_manager: Option<&NSTextLayoutManager>,
304 location: &ProtocolObject<dyn NSTextLocation>,
305 ) -> Retained<Self>;
306
307 #[unsafe(method(init))]
308 #[unsafe(method_family = init)]
309 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
310
311 #[unsafe(method(new))]
312 #[unsafe(method_family = new)]
313 pub unsafe fn new() -> Retained<Self>;
314
315 #[unsafe(method(textAttachment))]
316 #[unsafe(method_family = none)]
317 pub fn textAttachment(&self) -> Option<Retained<NSTextAttachment>>;
318
319 #[cfg(feature = "NSTextLayoutManager")]
320 #[unsafe(method(textLayoutManager))]
321 #[unsafe(method_family = none)]
322 pub fn textLayoutManager(&self) -> Option<Retained<NSTextLayoutManager>>;
323
324 #[cfg(feature = "NSTextRange")]
325 #[unsafe(method(location))]
326 #[unsafe(method_family = none)]
327 pub fn location(&self) -> Retained<ProtocolObject<dyn NSTextLocation>>;
328
329 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
330 #[unsafe(method(view))]
331 #[unsafe(method_family = none)]
332 pub fn view(&self, mtm: MainThreadMarker) -> Option<Retained<NSView>>;
333
334 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
335 #[unsafe(method(setView:))]
337 #[unsafe(method_family = none)]
338 pub fn setView(&self, view: Option<&NSView>);
339
340 #[unsafe(method(loadView))]
341 #[unsafe(method_family = none)]
342 pub fn loadView(&self);
343
344 #[unsafe(method(tracksTextAttachmentViewBounds))]
345 #[unsafe(method_family = none)]
346 pub fn tracksTextAttachmentViewBounds(&self) -> bool;
347
348 #[unsafe(method(setTracksTextAttachmentViewBounds:))]
350 #[unsafe(method_family = none)]
351 pub fn setTracksTextAttachmentViewBounds(&self, tracks_text_attachment_view_bounds: bool);
352
353 #[cfg(all(
354 feature = "NSTextContainer",
355 feature = "NSTextRange",
356 feature = "objc2-core-foundation"
357 ))]
358 #[unsafe(method(attachmentBoundsForAttributes:location:textContainer:proposedLineFragment:position:))]
362 #[unsafe(method_family = none)]
363 pub unsafe fn attachmentBoundsForAttributes_location_textContainer_proposedLineFragment_position(
364 &self,
365 attributes: &NSDictionary<NSAttributedStringKey, AnyObject>,
366 location: &ProtocolObject<dyn NSTextLocation>,
367 text_container: Option<&NSTextContainer>,
368 proposed_line_fragment: CGRect,
369 position: CGPoint,
370 ) -> CGRect;
371 );
372}
373
374mod private_NSMutableAttributedStringAttachmentConveniences {
375 pub trait Sealed {}
376}
377
378pub unsafe trait NSMutableAttributedStringAttachmentConveniences:
380 ClassType + Sized + private_NSMutableAttributedStringAttachmentConveniences::Sealed
381{
382 extern_methods!(
383 #[unsafe(method(updateAttachmentsFromPath:))]
384 #[unsafe(method_family = none)]
385 fn updateAttachmentsFromPath(&self, path: &NSString);
386 );
387}
388
389impl private_NSMutableAttributedStringAttachmentConveniences::Sealed for NSMutableAttributedString {}
390unsafe impl NSMutableAttributedStringAttachmentConveniences for NSMutableAttributedString {}
391
392extern_protocol!(
393 pub unsafe trait NSTextAttachmentContainer: NSObjectProtocol {
395 #[cfg(all(
396 feature = "NSImage",
397 feature = "NSTextContainer",
398 feature = "objc2-core-foundation"
399 ))]
400 #[unsafe(method(imageForBounds:textContainer:characterIndex:))]
401 #[unsafe(method_family = none)]
402 fn imageForBounds_textContainer_characterIndex(
403 &self,
404 image_bounds: CGRect,
405 text_container: Option<&NSTextContainer>,
406 char_index: NSUInteger,
407 ) -> Option<Retained<NSImage>>;
408
409 #[cfg(all(feature = "NSTextContainer", feature = "objc2-core-foundation"))]
410 #[unsafe(method(attachmentBoundsForTextContainer:proposedLineFragment:glyphPosition:characterIndex:))]
411 #[unsafe(method_family = none)]
412 fn attachmentBoundsForTextContainer_proposedLineFragment_glyphPosition_characterIndex(
413 &self,
414 text_container: Option<&NSTextContainer>,
415 line_frag: CGRect,
416 position: CGPoint,
417 char_index: NSUInteger,
418 ) -> CGRect;
419 }
420);
421
422impl NSTextAttachment {
424 extern_methods!();
425}
426
427extern_conformance!(
428 unsafe impl NSTextAttachmentContainer for NSTextAttachment {}
429);