1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10pub type NSPasteboardType = NSString;
13
14extern "C" {
15 pub static NSPasteboardTypeString: &'static NSPasteboardType;
17}
18
19extern "C" {
20 pub static NSPasteboardTypePDF: &'static NSPasteboardType;
22}
23
24extern "C" {
25 pub static NSPasteboardTypeTIFF: &'static NSPasteboardType;
27}
28
29extern "C" {
30 pub static NSPasteboardTypePNG: &'static NSPasteboardType;
32}
33
34extern "C" {
35 pub static NSPasteboardTypeRTF: &'static NSPasteboardType;
37}
38
39extern "C" {
40 pub static NSPasteboardTypeRTFD: &'static NSPasteboardType;
42}
43
44extern "C" {
45 pub static NSPasteboardTypeHTML: &'static NSPasteboardType;
47}
48
49extern "C" {
50 pub static NSPasteboardTypeTabularText: &'static NSPasteboardType;
52}
53
54extern "C" {
55 pub static NSPasteboardTypeFont: &'static NSPasteboardType;
57}
58
59extern "C" {
60 pub static NSPasteboardTypeRuler: &'static NSPasteboardType;
62}
63
64extern "C" {
65 pub static NSPasteboardTypeColor: &'static NSPasteboardType;
67}
68
69extern "C" {
70 pub static NSPasteboardTypeSound: &'static NSPasteboardType;
72}
73
74extern "C" {
75 pub static NSPasteboardTypeMultipleTextSelection: &'static NSPasteboardType;
77}
78
79extern "C" {
80 pub static NSPasteboardTypeTextFinderOptions: &'static NSPasteboardType;
82}
83
84extern "C" {
85 pub static NSPasteboardTypeURL: &'static NSPasteboardType;
87}
88
89extern "C" {
90 pub static NSPasteboardTypeFileURL: &'static NSPasteboardType;
92}
93
94pub type NSPasteboardName = NSString;
97
98extern "C" {
99 pub static NSPasteboardNameGeneral: &'static NSPasteboardName;
101}
102
103extern "C" {
104 pub static NSPasteboardNameFont: &'static NSPasteboardName;
106}
107
108extern "C" {
109 pub static NSPasteboardNameRuler: &'static NSPasteboardName;
111}
112
113extern "C" {
114 pub static NSPasteboardNameFind: &'static NSPasteboardName;
116}
117
118extern "C" {
119 pub static NSPasteboardNameDrag: &'static NSPasteboardName;
121}
122
123#[repr(transparent)]
126#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
127pub struct NSPasteboardContentsOptions(pub NSUInteger);
128bitflags::bitflags! {
129 impl NSPasteboardContentsOptions: NSUInteger {
130 #[doc(alias = "NSPasteboardContentsCurrentHostOnly")]
131 const CurrentHostOnly = 1<<0;
132 }
133}
134
135unsafe impl Encode for NSPasteboardContentsOptions {
136 const ENCODING: Encoding = NSUInteger::ENCODING;
137}
138
139unsafe impl RefEncode for NSPasteboardContentsOptions {
140 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
141}
142
143pub type NSPasteboardReadingOptionKey = NSString;
146
147extern "C" {
148 pub static NSPasteboardURLReadingFileURLsOnlyKey: &'static NSPasteboardReadingOptionKey;
150}
151
152extern "C" {
153 pub static NSPasteboardURLReadingContentsConformToTypesKey:
155 &'static NSPasteboardReadingOptionKey;
156}
157
158extern_class!(
159 #[unsafe(super(NSObject))]
161 #[derive(Debug, PartialEq, Eq, Hash)]
162 pub struct NSPasteboard;
163);
164
165unsafe impl NSObjectProtocol for NSPasteboard {}
166
167impl NSPasteboard {
168 extern_methods!(
169 #[unsafe(method(generalPasteboard))]
170 #[unsafe(method_family = none)]
171 pub unsafe fn generalPasteboard() -> Retained<NSPasteboard>;
172
173 #[unsafe(method(pasteboardWithName:))]
174 #[unsafe(method_family = none)]
175 pub unsafe fn pasteboardWithName(name: &NSPasteboardName) -> Retained<NSPasteboard>;
176
177 #[unsafe(method(pasteboardWithUniqueName))]
178 #[unsafe(method_family = none)]
179 pub unsafe fn pasteboardWithUniqueName() -> Retained<NSPasteboard>;
180
181 #[unsafe(method(name))]
182 #[unsafe(method_family = none)]
183 pub unsafe fn name(&self) -> Retained<NSPasteboardName>;
184
185 #[unsafe(method(changeCount))]
186 #[unsafe(method_family = none)]
187 pub unsafe fn changeCount(&self) -> NSInteger;
188
189 #[unsafe(method(prepareForNewContentsWithOptions:))]
190 #[unsafe(method_family = none)]
191 pub unsafe fn prepareForNewContentsWithOptions(
192 &self,
193 options: NSPasteboardContentsOptions,
194 ) -> NSInteger;
195
196 #[unsafe(method(clearContents))]
197 #[unsafe(method_family = none)]
198 pub unsafe fn clearContents(&self) -> NSInteger;
199
200 #[unsafe(method(writeObjects:))]
201 #[unsafe(method_family = none)]
202 pub unsafe fn writeObjects(
203 &self,
204 objects: &NSArray<ProtocolObject<dyn NSPasteboardWriting>>,
205 ) -> bool;
206
207 #[unsafe(method(readObjectsForClasses:options:))]
208 #[unsafe(method_family = none)]
209 pub unsafe fn readObjectsForClasses_options(
210 &self,
211 class_array: &NSArray<AnyClass>,
212 options: Option<&NSDictionary<NSPasteboardReadingOptionKey, AnyObject>>,
213 ) -> Option<Retained<NSArray>>;
214
215 #[cfg(feature = "NSPasteboardItem")]
216 #[unsafe(method(pasteboardItems))]
217 #[unsafe(method_family = none)]
218 pub unsafe fn pasteboardItems(&self) -> Option<Retained<NSArray<NSPasteboardItem>>>;
219
220 #[cfg(feature = "NSPasteboardItem")]
221 #[unsafe(method(indexOfPasteboardItem:))]
222 #[unsafe(method_family = none)]
223 pub unsafe fn indexOfPasteboardItem(
224 &self,
225 pasteboard_item: &NSPasteboardItem,
226 ) -> NSUInteger;
227
228 #[unsafe(method(canReadItemWithDataConformingToTypes:))]
229 #[unsafe(method_family = none)]
230 pub unsafe fn canReadItemWithDataConformingToTypes(
231 &self,
232 types: &NSArray<NSString>,
233 ) -> bool;
234
235 #[unsafe(method(canReadObjectForClasses:options:))]
236 #[unsafe(method_family = none)]
237 pub unsafe fn canReadObjectForClasses_options(
238 &self,
239 class_array: &NSArray<AnyClass>,
240 options: Option<&NSDictionary<NSPasteboardReadingOptionKey, AnyObject>>,
241 ) -> bool;
242
243 #[unsafe(method(declareTypes:owner:))]
244 #[unsafe(method_family = none)]
245 pub unsafe fn declareTypes_owner(
246 &self,
247 new_types: &NSArray<NSPasteboardType>,
248 new_owner: Option<&AnyObject>,
249 ) -> NSInteger;
250
251 #[unsafe(method(addTypes:owner:))]
252 #[unsafe(method_family = none)]
253 pub unsafe fn addTypes_owner(
254 &self,
255 new_types: &NSArray<NSPasteboardType>,
256 new_owner: Option<&AnyObject>,
257 ) -> NSInteger;
258
259 #[unsafe(method(types))]
260 #[unsafe(method_family = none)]
261 pub unsafe fn types(&self) -> Option<Retained<NSArray<NSPasteboardType>>>;
262
263 #[unsafe(method(availableTypeFromArray:))]
264 #[unsafe(method_family = none)]
265 pub unsafe fn availableTypeFromArray(
266 &self,
267 types: &NSArray<NSPasteboardType>,
268 ) -> Option<Retained<NSPasteboardType>>;
269
270 #[unsafe(method(setData:forType:))]
271 #[unsafe(method_family = none)]
272 pub unsafe fn setData_forType(
273 &self,
274 data: Option<&NSData>,
275 data_type: &NSPasteboardType,
276 ) -> bool;
277
278 #[unsafe(method(setPropertyList:forType:))]
279 #[unsafe(method_family = none)]
280 pub unsafe fn setPropertyList_forType(
281 &self,
282 plist: &AnyObject,
283 data_type: &NSPasteboardType,
284 ) -> bool;
285
286 #[unsafe(method(setString:forType:))]
287 #[unsafe(method_family = none)]
288 pub unsafe fn setString_forType(
289 &self,
290 string: &NSString,
291 data_type: &NSPasteboardType,
292 ) -> bool;
293
294 #[unsafe(method(dataForType:))]
295 #[unsafe(method_family = none)]
296 pub unsafe fn dataForType(&self, data_type: &NSPasteboardType) -> Option<Retained<NSData>>;
297
298 #[unsafe(method(propertyListForType:))]
299 #[unsafe(method_family = none)]
300 pub fn propertyListForType(
301 &self,
302 data_type: &NSPasteboardType,
303 ) -> Option<Retained<AnyObject>>;
304
305 #[unsafe(method(stringForType:))]
306 #[unsafe(method_family = none)]
307 pub unsafe fn stringForType(
308 &self,
309 data_type: &NSPasteboardType,
310 ) -> Option<Retained<NSString>>;
311 );
312}
313
314impl NSPasteboard {
316 extern_methods!(
317 #[unsafe(method(init))]
318 #[unsafe(method_family = init)]
319 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
320
321 #[unsafe(method(new))]
322 #[unsafe(method_family = new)]
323 pub unsafe fn new() -> Retained<Self>;
324 );
325}
326
327impl NSPasteboard {
329 extern_methods!(
330 #[unsafe(method(typesFilterableTo:))]
331 #[unsafe(method_family = none)]
332 pub unsafe fn typesFilterableTo(
333 r#type: &NSPasteboardType,
334 ) -> Retained<NSArray<NSPasteboardType>>;
335
336 #[unsafe(method(pasteboardByFilteringFile:))]
337 #[unsafe(method_family = none)]
338 pub unsafe fn pasteboardByFilteringFile(filename: &NSString) -> Retained<NSPasteboard>;
339
340 #[unsafe(method(pasteboardByFilteringData:ofType:))]
341 #[unsafe(method_family = none)]
342 pub unsafe fn pasteboardByFilteringData_ofType(
343 data: &NSData,
344 r#type: &NSPasteboardType,
345 ) -> Retained<NSPasteboard>;
346
347 #[unsafe(method(pasteboardByFilteringTypesInPasteboard:))]
348 #[unsafe(method_family = none)]
349 pub unsafe fn pasteboardByFilteringTypesInPasteboard(
350 pboard: &NSPasteboard,
351 ) -> Retained<NSPasteboard>;
352 );
353}
354
355extern_protocol!(
356 pub unsafe trait NSPasteboardTypeOwner: NSObjectProtocol {
358 #[unsafe(method(pasteboard:provideDataForType:))]
359 #[unsafe(method_family = none)]
360 unsafe fn pasteboard_provideDataForType(
361 &self,
362 sender: &NSPasteboard,
363 r#type: &NSPasteboardType,
364 );
365
366 #[optional]
367 #[unsafe(method(pasteboardChangedOwner:))]
368 #[unsafe(method_family = none)]
369 unsafe fn pasteboardChangedOwner(&self, sender: &NSPasteboard);
370 }
371);
372
373#[repr(transparent)]
378#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
379pub struct NSPasteboardWritingOptions(pub NSUInteger);
380bitflags::bitflags! {
381 impl NSPasteboardWritingOptions: NSUInteger {
382 #[doc(alias = "NSPasteboardWritingPromised")]
383 const Promised = 1<<9;
384 }
385}
386
387unsafe impl Encode for NSPasteboardWritingOptions {
388 const ENCODING: Encoding = NSUInteger::ENCODING;
389}
390
391unsafe impl RefEncode for NSPasteboardWritingOptions {
392 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
393}
394
395extern_protocol!(
396 pub unsafe trait NSPasteboardWriting: NSObjectProtocol {
398 #[unsafe(method(writableTypesForPasteboard:))]
399 #[unsafe(method_family = none)]
400 unsafe fn writableTypesForPasteboard(
401 &self,
402 pasteboard: &NSPasteboard,
403 ) -> Retained<NSArray<NSPasteboardType>>;
404
405 #[optional]
406 #[unsafe(method(writingOptionsForType:pasteboard:))]
407 #[unsafe(method_family = none)]
408 unsafe fn writingOptionsForType_pasteboard(
409 &self,
410 r#type: &NSPasteboardType,
411 pasteboard: &NSPasteboard,
412 ) -> NSPasteboardWritingOptions;
413
414 #[unsafe(method(pasteboardPropertyListForType:))]
415 #[unsafe(method_family = none)]
416 unsafe fn pasteboardPropertyListForType(
417 &self,
418 r#type: &NSPasteboardType,
419 ) -> Option<Retained<AnyObject>>;
420 }
421);
422
423#[repr(transparent)]
426#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
427pub struct NSPasteboardReadingOptions(pub NSUInteger);
428bitflags::bitflags! {
429 impl NSPasteboardReadingOptions: NSUInteger {
430 #[doc(alias = "NSPasteboardReadingAsData")]
431 const AsData = 0;
432 #[doc(alias = "NSPasteboardReadingAsString")]
433 const AsString = 1<<0;
434 #[doc(alias = "NSPasteboardReadingAsPropertyList")]
435 const AsPropertyList = 1<<1;
436 #[doc(alias = "NSPasteboardReadingAsKeyedArchive")]
437 const AsKeyedArchive = 1<<2;
438 }
439}
440
441unsafe impl Encode for NSPasteboardReadingOptions {
442 const ENCODING: Encoding = NSUInteger::ENCODING;
443}
444
445unsafe impl RefEncode for NSPasteboardReadingOptions {
446 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
447}
448
449extern_protocol!(
450 pub unsafe trait NSPasteboardReading: NSObjectProtocol {
452 #[unsafe(method(readableTypesForPasteboard:))]
453 #[unsafe(method_family = none)]
454 unsafe fn readableTypesForPasteboard(
455 pasteboard: &NSPasteboard,
456 ) -> Retained<NSArray<NSPasteboardType>>;
457
458 #[optional]
459 #[unsafe(method(readingOptionsForType:pasteboard:))]
460 #[unsafe(method_family = none)]
461 unsafe fn readingOptionsForType_pasteboard(
462 r#type: &NSPasteboardType,
463 pasteboard: &NSPasteboard,
464 ) -> NSPasteboardReadingOptions;
465
466 #[optional]
467 #[unsafe(method(initWithPasteboardPropertyList:ofType:))]
468 #[unsafe(method_family = init)]
469 unsafe fn initWithPasteboardPropertyList_ofType(
470 this: Allocated<Self>,
471 property_list: &AnyObject,
472 r#type: &NSPasteboardType,
473 ) -> Option<Retained<Self>>;
474 }
475);
476
477mod private_NSURLNSPasteboardSupport {
478 pub trait Sealed {}
479}
480
481#[doc(alias = "NSPasteboardSupport")]
483pub unsafe trait NSURLNSPasteboardSupport:
484 ClassType + Sized + private_NSURLNSPasteboardSupport::Sealed
485{
486 extern_methods!(
487 #[unsafe(method(URLFromPasteboard:))]
488 #[unsafe(method_family = none)]
489 unsafe fn URLFromPasteboard(paste_board: &NSPasteboard) -> Option<Retained<NSURL>>;
490
491 #[unsafe(method(writeToPasteboard:))]
492 #[unsafe(method_family = none)]
493 unsafe fn writeToPasteboard(&self, paste_board: &NSPasteboard);
494 );
495}
496
497impl private_NSURLNSPasteboardSupport::Sealed for NSURL {}
498unsafe impl NSURLNSPasteboardSupport for NSURL {}
499
500unsafe impl NSPasteboardReading for NSURL {}
501
502unsafe impl NSPasteboardWriting for NSURL {}
503
504unsafe impl NSPasteboardReading for NSString {}
505
506unsafe impl NSPasteboardWriting for NSString {}
507
508impl NSPasteboard {
511 extern_methods!(
512 #[unsafe(method(writeFileContents:))]
513 #[unsafe(method_family = none)]
514 pub unsafe fn writeFileContents(&self, filename: &NSString) -> bool;
515
516 #[unsafe(method(readFileContentsType:toFile:))]
517 #[unsafe(method_family = none)]
518 pub unsafe fn readFileContentsType_toFile(
519 &self,
520 r#type: Option<&NSPasteboardType>,
521 filename: &NSString,
522 ) -> Option<Retained<NSString>>;
523
524 #[unsafe(method(writeFileWrapper:))]
525 #[unsafe(method_family = none)]
526 pub unsafe fn writeFileWrapper(&self, wrapper: &NSFileWrapper) -> bool;
527
528 #[unsafe(method(readFileWrapper))]
529 #[unsafe(method_family = none)]
530 pub unsafe fn readFileWrapper(&self) -> Option<Retained<NSFileWrapper>>;
531 );
532}
533
534extern "C" {
535 pub static NSFileContentsPboardType: &'static NSPasteboardType;
537}
538
539#[inline]
540pub unsafe extern "C-unwind" fn NSCreateFilenamePboardType(
541 file_type: &NSString,
542) -> Option<Retained<NSPasteboardType>> {
543 extern "C-unwind" {
544 fn NSCreateFilenamePboardType(file_type: &NSString) -> *mut NSPasteboardType;
545 }
546 let ret = unsafe { NSCreateFilenamePboardType(file_type) };
547 unsafe { Retained::from_raw(ret) }
548}
549
550#[inline]
551pub unsafe extern "C-unwind" fn NSCreateFileContentsPboardType(
552 file_type: &NSString,
553) -> Option<Retained<NSPasteboardType>> {
554 extern "C-unwind" {
555 fn NSCreateFileContentsPboardType(file_type: &NSString) -> *mut NSPasteboardType;
556 }
557 let ret = unsafe { NSCreateFileContentsPboardType(file_type) };
558 unsafe { Retained::from_raw(ret) }
559}
560
561#[inline]
562pub unsafe extern "C-unwind" fn NSGetFileType(
563 pboard_type: &NSPasteboardType,
564) -> Option<Retained<NSString>> {
565 extern "C-unwind" {
566 fn NSGetFileType(pboard_type: &NSPasteboardType) -> *mut NSString;
567 }
568 let ret = unsafe { NSGetFileType(pboard_type) };
569 unsafe { Retained::retain_autoreleased(ret) }
570}
571
572#[inline]
573pub unsafe extern "C-unwind" fn NSGetFileTypes(
574 pboard_types: &NSArray<NSPasteboardType>,
575) -> Option<Retained<NSArray<NSString>>> {
576 extern "C-unwind" {
577 fn NSGetFileTypes(pboard_types: &NSArray<NSPasteboardType>) -> *mut NSArray<NSString>;
578 }
579 let ret = unsafe { NSGetFileTypes(pboard_types) };
580 unsafe { Retained::retain_autoreleased(ret) }
581}
582
583extern "C" {
584 pub static NSStringPboardType: &'static NSPasteboardType;
588}
589
590extern "C" {
591 pub static NSFilenamesPboardType: &'static NSPasteboardType;
593}
594
595extern "C" {
596 pub static NSTIFFPboardType: &'static NSPasteboardType;
598}
599
600extern "C" {
601 pub static NSRTFPboardType: &'static NSPasteboardType;
603}
604
605extern "C" {
606 pub static NSTabularTextPboardType: &'static NSPasteboardType;
608}
609
610extern "C" {
611 pub static NSFontPboardType: &'static NSPasteboardType;
613}
614
615extern "C" {
616 pub static NSRulerPboardType: &'static NSPasteboardType;
618}
619
620extern "C" {
621 pub static NSColorPboardType: &'static NSPasteboardType;
623}
624
625extern "C" {
626 pub static NSRTFDPboardType: &'static NSPasteboardType;
628}
629
630extern "C" {
631 pub static NSHTMLPboardType: &'static NSPasteboardType;
633}
634
635extern "C" {
636 pub static NSURLPboardType: &'static NSPasteboardType;
638}
639
640extern "C" {
641 pub static NSPDFPboardType: &'static NSPasteboardType;
643}
644
645extern "C" {
646 pub static NSMultipleTextSelectionPboardType: &'static NSPasteboardType;
648}
649
650extern "C" {
651 pub static NSPostScriptPboardType: &'static NSPasteboardType;
653}
654
655extern "C" {
656 pub static NSVCardPboardType: &'static NSPasteboardType;
658}
659
660extern "C" {
661 pub static NSInkTextPboardType: &'static NSPasteboardType;
663}
664
665extern "C" {
666 pub static NSFilesPromisePboardType: &'static NSPasteboardType;
668}
669
670extern "C" {
671 pub static NSPasteboardTypeFindPanelSearchOptions: &'static NSPasteboardType;
673}
674
675extern "C" {
676 pub static NSGeneralPboard: &'static NSPasteboardName;
678}
679
680extern "C" {
681 pub static NSFontPboard: &'static NSPasteboardName;
683}
684
685extern "C" {
686 pub static NSRulerPboard: &'static NSPasteboardName;
688}
689
690extern "C" {
691 pub static NSFindPboard: &'static NSPasteboardName;
693}
694
695extern "C" {
696 pub static NSDragPboard: &'static NSPasteboardName;
698}
699
700extern "C" {
701 pub static NSPICTPboardType: &'static NSPasteboardType;
703}