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