objc2_app_kit/generated/NSPasteboard.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtype?language=objc)
11// NS_TYPED_EXTENSIBLE_ENUM
12pub type NSPasteboardType = NSString;
13
14extern "C" {
15 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypestring?language=objc)
16 pub static NSPasteboardTypeString: &'static NSPasteboardType;
17}
18
19extern "C" {
20 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypepdf?language=objc)
21 pub static NSPasteboardTypePDF: &'static NSPasteboardType;
22}
23
24extern "C" {
25 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypetiff?language=objc)
26 pub static NSPasteboardTypeTIFF: &'static NSPasteboardType;
27}
28
29extern "C" {
30 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypepng?language=objc)
31 pub static NSPasteboardTypePNG: &'static NSPasteboardType;
32}
33
34extern "C" {
35 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypertf?language=objc)
36 pub static NSPasteboardTypeRTF: &'static NSPasteboardType;
37}
38
39extern "C" {
40 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypertfd?language=objc)
41 pub static NSPasteboardTypeRTFD: &'static NSPasteboardType;
42}
43
44extern "C" {
45 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypehtml?language=objc)
46 pub static NSPasteboardTypeHTML: &'static NSPasteboardType;
47}
48
49extern "C" {
50 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypetabulartext?language=objc)
51 pub static NSPasteboardTypeTabularText: &'static NSPasteboardType;
52}
53
54extern "C" {
55 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypefont?language=objc)
56 pub static NSPasteboardTypeFont: &'static NSPasteboardType;
57}
58
59extern "C" {
60 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtyperuler?language=objc)
61 pub static NSPasteboardTypeRuler: &'static NSPasteboardType;
62}
63
64extern "C" {
65 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypecolor?language=objc)
66 pub static NSPasteboardTypeColor: &'static NSPasteboardType;
67}
68
69extern "C" {
70 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypesound?language=objc)
71 pub static NSPasteboardTypeSound: &'static NSPasteboardType;
72}
73
74extern "C" {
75 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypemultipletextselection?language=objc)
76 pub static NSPasteboardTypeMultipleTextSelection: &'static NSPasteboardType;
77}
78
79extern "C" {
80 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypetextfinderoptions?language=objc)
81 pub static NSPasteboardTypeTextFinderOptions: &'static NSPasteboardType;
82}
83
84extern "C" {
85 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypeurl?language=objc)
86 pub static NSPasteboardTypeURL: &'static NSPasteboardType;
87}
88
89extern "C" {
90 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypefileurl?language=objc)
91 pub static NSPasteboardTypeFileURL: &'static NSPasteboardType;
92}
93
94/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardname?language=objc)
95// NS_TYPED_EXTENSIBLE_ENUM
96pub type NSPasteboardName = NSString;
97
98extern "C" {
99 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardnamegeneral?language=objc)
100 pub static NSPasteboardNameGeneral: &'static NSPasteboardName;
101}
102
103extern "C" {
104 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardnamefont?language=objc)
105 pub static NSPasteboardNameFont: &'static NSPasteboardName;
106}
107
108extern "C" {
109 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardnameruler?language=objc)
110 pub static NSPasteboardNameRuler: &'static NSPasteboardName;
111}
112
113extern "C" {
114 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardnamefind?language=objc)
115 pub static NSPasteboardNameFind: &'static NSPasteboardName;
116}
117
118extern "C" {
119 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardnamedrag?language=objc)
120 pub static NSPasteboardNameDrag: &'static NSPasteboardName;
121}
122
123/// A value indicating pasteboard access behavior.
124///
125/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardaccessbehavior?language=objc)
126// NS_ENUM
127#[repr(transparent)]
128#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
129pub struct NSPasteboardAccessBehavior(pub NSInteger);
130impl NSPasteboardAccessBehavior {
131 /// The default behavior for the General pasteboard is to ask upon programmatic access. All other pasteboards default to always allow access.
132 /// If an app has never triggered a pasteboard access alert, its General pasteboard will report `.default` behavior. Such an app is not shown in the corresponding System Settings pane.
133 /// Once programmatic pasteboard access triggers the first pasteboard access alert, the state automatically changes to `.ask`. At this point the app starts being shown in System Settings, where the user can toggle the behavior between `.ask`, `.alwaysAllow`, and `.alwaysDeny`.
134 #[doc(alias = "NSPasteboardAccessBehaviorDefault")]
135 pub const Default: Self = Self(0);
136 /// The system will notify the user and ask for permission before granting pasteboard access. However, access that is both user originated and paste related will always be allowed, and will not result in a notification. The app is listed in the corresponding System Settings pane.
137 #[doc(alias = "NSPasteboardAccessBehaviorAsk")]
138 pub const Ask: Self = Self(1);
139 /// The system will automatically allow all pasteboard access, without notifying the user. The app is listed in the corresponding System Settings pane.
140 #[doc(alias = "NSPasteboardAccessBehaviorAlwaysAllow")]
141 pub const AlwaysAllow: Self = Self(2);
142 /// The system will automatically deny all pasteboard access, without notifying the user. However, access that is both user originated and paste related will always be allowed, and will not result in a notification. The app is listed in the corresponding System Settings pane.
143 #[doc(alias = "NSPasteboardAccessBehaviorAlwaysDeny")]
144 pub const AlwaysDeny: Self = Self(3);
145}
146
147unsafe impl Encode for NSPasteboardAccessBehavior {
148 const ENCODING: Encoding = NSInteger::ENCODING;
149}
150
151unsafe impl RefEncode for NSPasteboardAccessBehavior {
152 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
153}
154
155/// A pattern to detect on the pasteboard, such as a URL, text, or a number.
156///
157/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpattern?language=objc)
158// NS_TYPED_ENUM
159pub type NSPasteboardDetectionPattern = NSString;
160
161extern "C" {
162 /// A pattern that indicates the pasteboard detects a string that consists of a web URL.
163 ///
164 /// Returns: NSString value, suitable for implementing "Paste and Go"
165 ///
166 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternprobableweburl?language=objc)
167 pub static NSPasteboardDetectionPatternProbableWebURL: &'static NSPasteboardDetectionPattern;
168}
169
170extern "C" {
171 /// A pattern that indicates the pasteboard detects a string suitable for use as a web search term.
172 ///
173 /// Returns: NSString value, suitable for implementing "Paste and Search"
174 ///
175 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternprobablewebsearch?language=objc)
176 pub static NSPasteboardDetectionPatternProbableWebSearch: &'static NSPasteboardDetectionPattern;
177}
178
179extern "C" {
180 /// A pattern that indicates the pasteboard detects a string that consists of a numeric value.
181 ///
182 /// Returns: NSNumber value
183 ///
184 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternnumber?language=objc)
185 pub static NSPasteboardDetectionPatternNumber: &'static NSPasteboardDetectionPattern;
186}
187
188extern "C" {
189 /// A pattern that indicates the pasteboard detects a string that contains a URL.
190 ///
191 /// Returns: array of DDMatchLink values
192 ///
193 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternlink?language=objc)
194 pub static NSPasteboardDetectionPatternLink: &'static NSPasteboardDetectionPattern;
195}
196
197extern "C" {
198 /// A pattern that indicates the pasteboard detects a string that contains a phone number.
199 ///
200 /// Returns: array of DDMatchPhoneNumber values
201 ///
202 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternphonenumber?language=objc)
203 pub static NSPasteboardDetectionPatternPhoneNumber: &'static NSPasteboardDetectionPattern;
204}
205
206extern "C" {
207 /// A pattern that indicates the pasteboard detects a string that contains an email address.
208 ///
209 /// Returns: array of DDMatchEmailAddress values
210 ///
211 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternemailaddress?language=objc)
212 pub static NSPasteboardDetectionPatternEmailAddress: &'static NSPasteboardDetectionPattern;
213}
214
215extern "C" {
216 /// A pattern that indicates the pasteboard detects a string that contains a postal address.
217 ///
218 /// Returns: array of DDMatchPostalAddress values
219 ///
220 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternpostaladdress?language=objc)
221 pub static NSPasteboardDetectionPatternPostalAddress: &'static NSPasteboardDetectionPattern;
222}
223
224extern "C" {
225 /// A pattern that indicates the pasteboard detects a string that contains a calendar event.
226 ///
227 /// Returns: array of DDMatchCalendarEvent values
228 ///
229 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatterncalendarevent?language=objc)
230 pub static NSPasteboardDetectionPatternCalendarEvent: &'static NSPasteboardDetectionPattern;
231}
232
233extern "C" {
234 /// A pattern that indicates the pasteboard detects a string that contains a parcel tracking number and carrier.
235 ///
236 /// Returns: array of DDMatchShipmentTrackingNumber values
237 ///
238 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternshipmenttrackingnumber?language=objc)
239 pub static NSPasteboardDetectionPatternShipmentTrackingNumber:
240 &'static NSPasteboardDetectionPattern;
241}
242
243extern "C" {
244 /// A pattern that indicates the pasteboard detects a string that contains a flight number.
245 ///
246 /// Returns: array of DDMatchFlightNumber values
247 ///
248 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternflightnumber?language=objc)
249 pub static NSPasteboardDetectionPatternFlightNumber: &'static NSPasteboardDetectionPattern;
250}
251
252extern "C" {
253 /// A pattern that indicates the pasteboard detects a string that contains an amount of money.
254 ///
255 /// Returns: array of DDMatchMoneyAmount values
256 ///
257 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarddetectionpatternmoneyamount?language=objc)
258 pub static NSPasteboardDetectionPatternMoneyAmount: &'static NSPasteboardDetectionPattern;
259}
260
261/// A metadata type to detect on the pasteboard.
262///
263/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardmetadatatype?language=objc)
264// NS_TYPED_ENUM
265pub type NSPasteboardMetadataType = NSString;
266
267extern "C" {
268 /// A metadata type that returns the content type if the pasteboard detects a reference to a file.
269 ///
270 /// Returns: UTType value for the detected content type of the file URL, if a file URL type is present.
271 ///
272 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardmetadatatypecontenttype?language=objc)
273 pub static NSPasteboardMetadataTypeContentType: &'static NSPasteboardMetadataType;
274}
275
276/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardcontentsoptions?language=objc)
277// NS_OPTIONS
278#[repr(transparent)]
279#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
280pub struct NSPasteboardContentsOptions(pub NSUInteger);
281bitflags::bitflags! {
282 impl NSPasteboardContentsOptions: NSUInteger {
283 #[doc(alias = "NSPasteboardContentsCurrentHostOnly")]
284 const CurrentHostOnly = 1<<0;
285 }
286}
287
288unsafe impl Encode for NSPasteboardContentsOptions {
289 const ENCODING: Encoding = NSUInteger::ENCODING;
290}
291
292unsafe impl RefEncode for NSPasteboardContentsOptions {
293 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
294}
295
296/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardreadingoptionkey?language=objc)
297// NS_TYPED_ENUM
298pub type NSPasteboardReadingOptionKey = NSString;
299
300extern "C" {
301 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardurlreadingfileurlsonlykey?language=objc)
302 pub static NSPasteboardURLReadingFileURLsOnlyKey: &'static NSPasteboardReadingOptionKey;
303}
304
305extern "C" {
306 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardurlreadingcontentsconformtotypeskey?language=objc)
307 pub static NSPasteboardURLReadingContentsConformToTypesKey:
308 &'static NSPasteboardReadingOptionKey;
309}
310
311extern_class!(
312 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboard?language=objc)
313 #[unsafe(super(NSObject))]
314 #[derive(Debug, PartialEq, Eq, Hash)]
315 pub struct NSPasteboard;
316);
317
318extern_conformance!(
319 unsafe impl NSObjectProtocol for NSPasteboard {}
320);
321
322impl NSPasteboard {
323 extern_methods!(
324 #[unsafe(method(generalPasteboard))]
325 #[unsafe(method_family = none)]
326 pub fn generalPasteboard() -> Retained<NSPasteboard>;
327
328 #[unsafe(method(pasteboardWithName:))]
329 #[unsafe(method_family = none)]
330 pub fn pasteboardWithName(name: &NSPasteboardName) -> Retained<NSPasteboard>;
331
332 #[unsafe(method(pasteboardWithUniqueName))]
333 #[unsafe(method_family = none)]
334 pub fn pasteboardWithUniqueName() -> Retained<NSPasteboard>;
335
336 #[unsafe(method(name))]
337 #[unsafe(method_family = none)]
338 pub fn name(&self) -> Retained<NSPasteboardName>;
339
340 #[unsafe(method(changeCount))]
341 #[unsafe(method_family = none)]
342 pub fn changeCount(&self) -> NSInteger;
343
344 /// The current pasteboard access behavior. The user can customize this behavior per-app in System Settings for any app that has triggered a pasteboard access alert in the past.
345 #[unsafe(method(accessBehavior))]
346 #[unsafe(method_family = none)]
347 pub fn accessBehavior(&self) -> NSPasteboardAccessBehavior;
348
349 #[unsafe(method(prepareForNewContentsWithOptions:))]
350 #[unsafe(method_family = none)]
351 pub fn prepareForNewContentsWithOptions(
352 &self,
353 options: NSPasteboardContentsOptions,
354 ) -> NSInteger;
355
356 #[unsafe(method(clearContents))]
357 #[unsafe(method_family = none)]
358 pub fn clearContents(&self) -> NSInteger;
359
360 #[unsafe(method(writeObjects:))]
361 #[unsafe(method_family = none)]
362 pub fn writeObjects(
363 &self,
364 objects: &NSArray<ProtocolObject<dyn NSPasteboardWriting>>,
365 ) -> bool;
366
367 /// # Safety
368 ///
369 /// - `class_array` generic probably has further requirements.
370 /// - `options` generic should be of the correct type.
371 #[unsafe(method(readObjectsForClasses:options:))]
372 #[unsafe(method_family = none)]
373 pub unsafe fn readObjectsForClasses_options(
374 &self,
375 class_array: &NSArray<AnyClass>,
376 options: Option<&NSDictionary<NSPasteboardReadingOptionKey, AnyObject>>,
377 ) -> Option<Retained<NSArray>>;
378
379 #[cfg(feature = "NSPasteboardItem")]
380 #[unsafe(method(pasteboardItems))]
381 #[unsafe(method_family = none)]
382 pub fn pasteboardItems(&self) -> Option<Retained<NSArray<NSPasteboardItem>>>;
383
384 #[cfg(feature = "NSPasteboardItem")]
385 #[unsafe(method(indexOfPasteboardItem:))]
386 #[unsafe(method_family = none)]
387 pub fn indexOfPasteboardItem(&self, pasteboard_item: &NSPasteboardItem) -> NSUInteger;
388
389 #[unsafe(method(canReadItemWithDataConformingToTypes:))]
390 #[unsafe(method_family = none)]
391 pub fn canReadItemWithDataConformingToTypes(&self, types: &NSArray<NSString>) -> bool;
392
393 /// # Safety
394 ///
395 /// - `class_array` generic probably has further requirements.
396 /// - `options` generic should be of the correct type.
397 #[unsafe(method(canReadObjectForClasses:options:))]
398 #[unsafe(method_family = none)]
399 pub unsafe fn canReadObjectForClasses_options(
400 &self,
401 class_array: &NSArray<AnyClass>,
402 options: Option<&NSDictionary<NSPasteboardReadingOptionKey, AnyObject>>,
403 ) -> bool;
404
405 /// # Safety
406 ///
407 /// `new_owner` should be of the correct type.
408 #[unsafe(method(declareTypes:owner:))]
409 #[unsafe(method_family = none)]
410 pub unsafe fn declareTypes_owner(
411 &self,
412 new_types: &NSArray<NSPasteboardType>,
413 new_owner: Option<&AnyObject>,
414 ) -> NSInteger;
415
416 /// # Safety
417 ///
418 /// `new_owner` should be of the correct type.
419 #[unsafe(method(addTypes:owner:))]
420 #[unsafe(method_family = none)]
421 pub unsafe fn addTypes_owner(
422 &self,
423 new_types: &NSArray<NSPasteboardType>,
424 new_owner: Option<&AnyObject>,
425 ) -> NSInteger;
426
427 #[unsafe(method(types))]
428 #[unsafe(method_family = none)]
429 pub fn types(&self) -> Option<Retained<NSArray<NSPasteboardType>>>;
430
431 #[unsafe(method(availableTypeFromArray:))]
432 #[unsafe(method_family = none)]
433 pub fn availableTypeFromArray(
434 &self,
435 types: &NSArray<NSPasteboardType>,
436 ) -> Option<Retained<NSPasteboardType>>;
437
438 #[unsafe(method(setData:forType:))]
439 #[unsafe(method_family = none)]
440 pub fn setData_forType(&self, data: Option<&NSData>, data_type: &NSPasteboardType) -> bool;
441
442 /// # Safety
443 ///
444 /// `plist` should be of the correct type.
445 #[unsafe(method(setPropertyList:forType:))]
446 #[unsafe(method_family = none)]
447 pub unsafe fn setPropertyList_forType(
448 &self,
449 plist: &AnyObject,
450 data_type: &NSPasteboardType,
451 ) -> bool;
452
453 #[unsafe(method(setString:forType:))]
454 #[unsafe(method_family = none)]
455 pub fn setString_forType(&self, string: &NSString, data_type: &NSPasteboardType) -> bool;
456
457 #[unsafe(method(dataForType:))]
458 #[unsafe(method_family = none)]
459 pub fn dataForType(&self, data_type: &NSPasteboardType) -> Option<Retained<NSData>>;
460
461 #[unsafe(method(propertyListForType:))]
462 #[unsafe(method_family = none)]
463 pub fn propertyListForType(
464 &self,
465 data_type: &NSPasteboardType,
466 ) -> Option<Retained<AnyObject>>;
467
468 #[unsafe(method(stringForType:))]
469 #[unsafe(method_family = none)]
470 pub fn stringForType(&self, data_type: &NSPasteboardType) -> Option<Retained<NSString>>;
471
472 #[cfg(feature = "block2")]
473 /// Determines whether the first pasteboard item matches the specified patterns, without notifying the person using the app.
474 ///
475 /// This method only gives an indication of whether the first pasteboard item matches a particular pattern, and doesn’t allow the app to access the item's contents. As a result, the system doesn’t notify the person using the app about reading the contents of the pasteboard.
476 ///
477 /// The following example shows how to use this method to find email and postal addresses in the first pasteboard item:
478 ///
479 /// ```obj-c
480 /// [NSPasteboard.generalPasteboard
481 /// detectPatternsForPatterns:[NSSet setWithArray:
482 /// @
483 /// [NSPasteboardDetectionPatternEmailAddress,
484 /// NSPasteboardDetectionPatternPostalAddress]]
485 /// completionHandler:^(NSSet
486 /// <NSPasteboardDetectionPattern
487 /// > *matchedPatterns, NSError *error) {
488 /// if (error) {
489 /// NSLog(
490 /// "
491 /// Error: %
492 /// "
493 /// , error);
494 /// return;
495 /// }
496 /// BOOL matchedEmail = [matchedPatterns containsObject:NSPasteboardDetectionPatternEmailAddress];
497 /// BOOL matchedPostal = [matchedPatterns containsObject: NSPasteboardDetectionPatternPostalAddress];
498 /// if (matchedEmail) {
499 /// NSLog(
500 /// "
501 /// Email address(es) detected");
502 /// }
503 /// if (matchedPostal) {
504 /// NSLog(
505 /// "
506 /// Postal address(es) detected");
507 /// }
508 /// if (!matchedEmail
509 /// &
510 /// &
511 /// !matchedPostal) {
512 /// NSLog(
513 /// "
514 /// Matched neither email nor postal addresses.");
515 /// }
516 /// }];
517 /// ```
518 ///
519 /// - Parameters:
520 /// - patterns: The patterns to detect on the pasteboard.
521 /// - completionHandler: A block the system invokes after detecting patterns on the pasteboard. The block receives either a set with the patterns the system finds on the pasteboard or an error if detection fails.
522 #[unsafe(method(detectPatternsForPatterns:completionHandler:))]
523 #[unsafe(method_family = none)]
524 pub fn detectPatternsForPatterns_completionHandler(
525 &self,
526 patterns: &NSSet<NSPasteboardDetectionPattern>,
527 completion_handler: &block2::DynBlock<
528 dyn Fn(*mut NSSet<NSPasteboardDetectionPattern>, *mut NSError),
529 >,
530 );
531
532 #[cfg(feature = "block2")]
533 /// Determines whether the first pasteboard item matches the specified patterns, reading the contents if it finds a match.
534 ///
535 /// For details about the types returned for each pattern, see ``NSPasteboardDetectionPattern``.
536 ///
537 /// The following example shows how to use this method to find web URLs and web search terms in the first pasteboard item:
538 ///
539 /// ```obj-c
540 /// [NSPasteboard.generalPasteboard
541 /// detectValuesForPatterns:[NSSet setWithArray:
542 /// @
543 /// [NSPasteboardDetectionPatternProbableWebSearch,
544 /// NSPasteboardDetectionPatternProbableWebURL]]
545 /// completionHandler:^(NSDictionary
546 /// <NSPasteboardDetectionPattern
547 /// , id> *patternValues, NSError *error) {
548 /// if (error) {
549 /// NSLog(
550 /// "
551 /// Error: %
552 /// "
553 /// , error);
554 /// return;
555 /// }
556 /// NSString *searchString = (NSString*)patternValues[NSPasteboardDetectionPatternProbableWebSearch];
557 /// NSString *urlString = (NSString*)patternValues[NSPasteboardDetectionPatternProbableWebURL] ;
558 /// if (searchString != nil) {
559 /// NSLog(
560 /// "
561 /// Web search retrieved: %
562 /// "
563 /// , searchString);
564 /// }
565 /// if (urlString != nil) {
566 /// NSLog(
567 /// "
568 /// Web URL retrieved: %
569 /// "
570 /// , urlString);
571 /// }
572 /// if (searchString == nil
573 /// &
574 /// &
575 /// urlString == nil) {
576 /// NSLog(
577 /// "
578 /// No web patterns retrieved.");
579 /// }
580 /// }];
581 /// ```
582 ///
583 /// > Important: If the system finds a match when calling this method, the system informs the person using the app that the app is trying to read the contents of the pasteboard. If the person denies access to the pasteboard, the completion handler receives an error.
584 ///
585 /// - Parameters:
586 /// - patterns: The patterns to detect on the pasteboard.
587 /// - completionHandler: A block the system invokes after detecting patterns on the pasteboard. The block returns either a dictionary with the patterns the system finds on the pasteboard or an error if detection fails. The dictionary keys specify the matched patterns and the values specify the corresponding content of the pasteboard.
588 #[unsafe(method(detectValuesForPatterns:completionHandler:))]
589 #[unsafe(method_family = none)]
590 pub fn detectValuesForPatterns_completionHandler(
591 &self,
592 patterns: &NSSet<NSPasteboardDetectionPattern>,
593 completion_handler: &block2::DynBlock<
594 dyn Fn(*mut NSDictionary<NSPasteboardDetectionPattern, AnyObject>, *mut NSError),
595 >,
596 );
597
598 #[cfg(feature = "block2")]
599 /// Determines available metadata from the specified metadata types for the first pasteboard item, without notifying the person using the app.
600 ///
601 /// This method only gives access to limited types of metadata and doesn’t allow the app to access the contents. As a result, the system doesn’t notify the person using the app about reading the contents of the pasteboard.
602 ///
603 /// For details about the metadata returned for each type, see ``NSPasteboardMetadataType``.
604 ///
605 /// The following example shows how to use this method to find the content type of a file reference in the first item on the pasteboard:
606 ///
607 /// ```obj-c
608 /// [NSPasteboard.generalPasteboard
609 /// detectMetadataForTypes:[NSSet setWithArray:
610 /// @
611 /// [NSPasteboardMetadataTypeContentType]]
612 /// completionHandler:^(NSDictionary
613 /// <NSPasteboardMetadataType
614 /// , id> *metadata, NSError *error) {
615 /// if (error) {
616 /// NSLog(
617 /// "
618 /// Error: %
619 /// "
620 /// , error);
621 /// return;
622 /// }
623 /// UTType *contentType = (UTType*)metadata[NSPasteboardMetadataTypeContentType];
624 /// if (contentType) {
625 /// NSLog(
626 /// "
627 /// Content type is: %
628 /// "
629 /// , contentType.identifier);
630 /// } else {
631 /// NSLog(
632 /// "
633 /// Couldn't get content type");
634 /// }
635 /// }];
636 /// ```
637 ///
638 /// - Parameters:
639 /// - types: The metadata types to detect on the pasteboard.
640 /// - completionHandler: A block the system invokes after detecting metadata on the pasteboard. The block receives either a dictionary with the metadata types the system finds on the pasteboard or an error if detection fails. The dictionary keys specify the matched metadata types and the values specify the corresponding metadata.
641 #[unsafe(method(detectMetadataForTypes:completionHandler:))]
642 #[unsafe(method_family = none)]
643 pub fn detectMetadataForTypes_completionHandler(
644 &self,
645 types: &NSSet<NSPasteboardMetadataType>,
646 completion_handler: &block2::DynBlock<
647 dyn Fn(*mut NSDictionary<NSPasteboardMetadataType, AnyObject>, *mut NSError),
648 >,
649 );
650 );
651}
652
653/// Methods declared on superclass `NSObject`.
654impl NSPasteboard {
655 extern_methods!(
656 #[unsafe(method(init))]
657 #[unsafe(method_family = init)]
658 pub fn init(this: Allocated<Self>) -> Retained<Self>;
659
660 #[unsafe(method(new))]
661 #[unsafe(method_family = new)]
662 pub fn new() -> Retained<Self>;
663 );
664}
665
666impl DefaultRetained for NSPasteboard {
667 #[inline]
668 fn default_retained() -> Retained<Self> {
669 Self::new()
670 }
671}
672
673/// FilterServices.
674impl NSPasteboard {
675 extern_methods!(
676 #[unsafe(method(typesFilterableTo:))]
677 #[unsafe(method_family = none)]
678 pub fn typesFilterableTo(r#type: &NSPasteboardType) -> Retained<NSArray<NSPasteboardType>>;
679
680 #[unsafe(method(pasteboardByFilteringFile:))]
681 #[unsafe(method_family = none)]
682 pub fn pasteboardByFilteringFile(filename: &NSString) -> Retained<NSPasteboard>;
683
684 #[unsafe(method(pasteboardByFilteringData:ofType:))]
685 #[unsafe(method_family = none)]
686 pub fn pasteboardByFilteringData_ofType(
687 data: &NSData,
688 r#type: &NSPasteboardType,
689 ) -> Retained<NSPasteboard>;
690
691 #[unsafe(method(pasteboardByFilteringTypesInPasteboard:))]
692 #[unsafe(method_family = none)]
693 pub fn pasteboardByFilteringTypesInPasteboard(
694 pboard: &NSPasteboard,
695 ) -> Retained<NSPasteboard>;
696 );
697}
698
699extern_protocol!(
700 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypeowner?language=objc)
701 pub unsafe trait NSPasteboardTypeOwner: NSObjectProtocol {
702 #[unsafe(method(pasteboard:provideDataForType:))]
703 #[unsafe(method_family = none)]
704 fn pasteboard_provideDataForType(&self, sender: &NSPasteboard, r#type: &NSPasteboardType);
705
706 #[optional]
707 #[unsafe(method(pasteboardChangedOwner:))]
708 #[unsafe(method_family = none)]
709 fn pasteboardChangedOwner(&self, sender: &NSPasteboard);
710 }
711);
712
713/// * NSPasteboardWriting and NSPasteboardReading Protocols **
714///
715/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardwritingoptions?language=objc)
716// NS_OPTIONS
717#[repr(transparent)]
718#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
719pub struct NSPasteboardWritingOptions(pub NSUInteger);
720bitflags::bitflags! {
721 impl NSPasteboardWritingOptions: NSUInteger {
722 #[doc(alias = "NSPasteboardWritingPromised")]
723 const Promised = 1<<9;
724 }
725}
726
727unsafe impl Encode for NSPasteboardWritingOptions {
728 const ENCODING: Encoding = NSUInteger::ENCODING;
729}
730
731unsafe impl RefEncode for NSPasteboardWritingOptions {
732 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
733}
734
735extern_protocol!(
736 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardwriting?language=objc)
737 pub unsafe trait NSPasteboardWriting: NSObjectProtocol {
738 #[unsafe(method(writableTypesForPasteboard:))]
739 #[unsafe(method_family = none)]
740 fn writableTypesForPasteboard(
741 &self,
742 pasteboard: &NSPasteboard,
743 ) -> Retained<NSArray<NSPasteboardType>>;
744
745 #[optional]
746 #[unsafe(method(writingOptionsForType:pasteboard:))]
747 #[unsafe(method_family = none)]
748 fn writingOptionsForType_pasteboard(
749 &self,
750 r#type: &NSPasteboardType,
751 pasteboard: &NSPasteboard,
752 ) -> NSPasteboardWritingOptions;
753
754 #[unsafe(method(pasteboardPropertyListForType:))]
755 #[unsafe(method_family = none)]
756 fn pasteboardPropertyListForType(
757 &self,
758 r#type: &NSPasteboardType,
759 ) -> Option<Retained<AnyObject>>;
760 }
761);
762
763/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardreadingoptions?language=objc)
764// NS_OPTIONS
765#[repr(transparent)]
766#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
767pub struct NSPasteboardReadingOptions(pub NSUInteger);
768bitflags::bitflags! {
769 impl NSPasteboardReadingOptions: NSUInteger {
770 #[doc(alias = "NSPasteboardReadingAsData")]
771 const AsData = 0;
772 #[doc(alias = "NSPasteboardReadingAsString")]
773 const AsString = 1<<0;
774 #[doc(alias = "NSPasteboardReadingAsPropertyList")]
775 const AsPropertyList = 1<<1;
776 #[doc(alias = "NSPasteboardReadingAsKeyedArchive")]
777 const AsKeyedArchive = 1<<2;
778 }
779}
780
781unsafe impl Encode for NSPasteboardReadingOptions {
782 const ENCODING: Encoding = NSUInteger::ENCODING;
783}
784
785unsafe impl RefEncode for NSPasteboardReadingOptions {
786 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
787}
788
789extern_protocol!(
790 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardreading?language=objc)
791 pub unsafe trait NSPasteboardReading: NSObjectProtocol {
792 #[unsafe(method(readableTypesForPasteboard:))]
793 #[unsafe(method_family = none)]
794 fn readableTypesForPasteboard(
795 pasteboard: &NSPasteboard,
796 ) -> Retained<NSArray<NSPasteboardType>>;
797
798 #[optional]
799 #[unsafe(method(readingOptionsForType:pasteboard:))]
800 #[unsafe(method_family = none)]
801 fn readingOptionsForType_pasteboard(
802 r#type: &NSPasteboardType,
803 pasteboard: &NSPasteboard,
804 ) -> NSPasteboardReadingOptions;
805
806 /// # Safety
807 ///
808 /// `property_list` should be of the correct type.
809 #[optional]
810 #[unsafe(method(initWithPasteboardPropertyList:ofType:))]
811 #[unsafe(method_family = init)]
812 unsafe fn initWithPasteboardPropertyList_ofType(
813 this: Allocated<Self>,
814 property_list: &AnyObject,
815 r#type: &NSPasteboardType,
816 ) -> Option<Retained<Self>>;
817 }
818);
819
820mod private_NSURLNSPasteboardSupport {
821 pub trait Sealed {}
822}
823
824/// Category "NSPasteboardSupport" on [`NSURL`].
825#[doc(alias = "NSPasteboardSupport")]
826pub unsafe trait NSURLNSPasteboardSupport:
827 ClassType + Sized + private_NSURLNSPasteboardSupport::Sealed
828{
829 extern_methods!(
830 #[unsafe(method(URLFromPasteboard:))]
831 #[unsafe(method_family = none)]
832 fn URLFromPasteboard(paste_board: &NSPasteboard) -> Option<Retained<NSURL>>;
833
834 #[unsafe(method(writeToPasteboard:))]
835 #[unsafe(method_family = none)]
836 fn writeToPasteboard(&self, paste_board: &NSPasteboard);
837 );
838}
839
840impl private_NSURLNSPasteboardSupport::Sealed for NSURL {}
841unsafe impl NSURLNSPasteboardSupport for NSURL {}
842
843extern_conformance!(
844 unsafe impl NSPasteboardReading for NSURL {}
845);
846
847extern_conformance!(
848 unsafe impl NSPasteboardWriting for NSURL {}
849);
850
851extern_conformance!(
852 unsafe impl NSPasteboardReading for NSString {}
853);
854
855extern_conformance!(
856 unsafe impl NSPasteboardWriting for NSString {}
857);
858
859/// NSFileContents.
860///
861/// * File Contents **
862impl NSPasteboard {
863 extern_methods!(
864 #[unsafe(method(writeFileContents:))]
865 #[unsafe(method_family = none)]
866 pub fn writeFileContents(&self, filename: &NSString) -> bool;
867
868 #[unsafe(method(readFileContentsType:toFile:))]
869 #[unsafe(method_family = none)]
870 pub fn readFileContentsType_toFile(
871 &self,
872 r#type: Option<&NSPasteboardType>,
873 filename: &NSString,
874 ) -> Option<Retained<NSString>>;
875
876 #[unsafe(method(writeFileWrapper:))]
877 #[unsafe(method_family = none)]
878 pub fn writeFileWrapper(&self, wrapper: &NSFileWrapper) -> bool;
879
880 #[unsafe(method(readFileWrapper))]
881 #[unsafe(method_family = none)]
882 pub fn readFileWrapper(&self) -> Option<Retained<NSFileWrapper>>;
883 );
884}
885
886extern "C" {
887 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfilecontentspboardtype?language=objc)
888 pub static NSFileContentsPboardType: &'static NSPasteboardType;
889}
890
891#[inline]
892pub extern "C-unwind" fn NSCreateFilenamePboardType(
893 file_type: &NSString,
894) -> Option<Retained<NSPasteboardType>> {
895 extern "C-unwind" {
896 fn NSCreateFilenamePboardType(file_type: &NSString) -> *mut NSPasteboardType;
897 }
898 let ret = unsafe { NSCreateFilenamePboardType(file_type) };
899 unsafe { Retained::from_raw(ret) }
900}
901
902#[inline]
903pub extern "C-unwind" fn NSCreateFileContentsPboardType(
904 file_type: &NSString,
905) -> Option<Retained<NSPasteboardType>> {
906 extern "C-unwind" {
907 fn NSCreateFileContentsPboardType(file_type: &NSString) -> *mut NSPasteboardType;
908 }
909 let ret = unsafe { NSCreateFileContentsPboardType(file_type) };
910 unsafe { Retained::from_raw(ret) }
911}
912
913#[inline]
914pub extern "C-unwind" fn NSGetFileType(
915 pboard_type: &NSPasteboardType,
916) -> Option<Retained<NSString>> {
917 extern "C-unwind" {
918 fn NSGetFileType(pboard_type: &NSPasteboardType) -> *mut NSString;
919 }
920 let ret = unsafe { NSGetFileType(pboard_type) };
921 unsafe { Retained::retain_autoreleased(ret) }
922}
923
924#[inline]
925pub extern "C-unwind" fn NSGetFileTypes(
926 pboard_types: &NSArray<NSPasteboardType>,
927) -> Option<Retained<NSArray<NSString>>> {
928 extern "C-unwind" {
929 fn NSGetFileTypes(pboard_types: &NSArray<NSPasteboardType>) -> *mut NSArray<NSString>;
930 }
931 let ret = unsafe { NSGetFileTypes(pboard_types) };
932 unsafe { Retained::retain_autoreleased(ret) }
933}
934
935extern "C" {
936 /// * Deprecated **
937 ///
938 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nsstringpboardtype?language=objc)
939 #[deprecated]
940 pub static NSStringPboardType: &'static NSPasteboardType;
941}
942
943extern "C" {
944 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfilenamespboardtype?language=objc)
945 #[deprecated = "Create multiple pasteboard items with NSPasteboardTypeFileURL or kUTTypeFileURL instead"]
946 pub static NSFilenamesPboardType: &'static NSPasteboardType;
947}
948
949extern "C" {
950 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstiffpboardtype?language=objc)
951 #[deprecated]
952 pub static NSTIFFPboardType: &'static NSPasteboardType;
953}
954
955extern "C" {
956 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsrtfpboardtype?language=objc)
957 #[deprecated]
958 pub static NSRTFPboardType: &'static NSPasteboardType;
959}
960
961extern "C" {
962 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nstabulartextpboardtype?language=objc)
963 #[deprecated]
964 pub static NSTabularTextPboardType: &'static NSPasteboardType;
965}
966
967extern "C" {
968 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfontpboardtype?language=objc)
969 #[deprecated]
970 pub static NSFontPboardType: &'static NSPasteboardType;
971}
972
973extern "C" {
974 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsrulerpboardtype?language=objc)
975 #[deprecated]
976 pub static NSRulerPboardType: &'static NSPasteboardType;
977}
978
979extern "C" {
980 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nscolorpboardtype?language=objc)
981 #[deprecated]
982 pub static NSColorPboardType: &'static NSPasteboardType;
983}
984
985extern "C" {
986 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsrtfdpboardtype?language=objc)
987 #[deprecated]
988 pub static NSRTFDPboardType: &'static NSPasteboardType;
989}
990
991extern "C" {
992 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nshtmlpboardtype?language=objc)
993 #[deprecated]
994 pub static NSHTMLPboardType: &'static NSPasteboardType;
995}
996
997extern "C" {
998 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsurlpboardtype?language=objc)
999 #[deprecated]
1000 pub static NSURLPboardType: &'static NSPasteboardType;
1001}
1002
1003extern "C" {
1004 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspdfpboardtype?language=objc)
1005 #[deprecated]
1006 pub static NSPDFPboardType: &'static NSPasteboardType;
1007}
1008
1009extern "C" {
1010 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsmultipletextselectionpboardtype?language=objc)
1011 #[deprecated]
1012 pub static NSMultipleTextSelectionPboardType: &'static NSPasteboardType;
1013}
1014
1015extern "C" {
1016 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspostscriptpboardtype?language=objc)
1017 #[deprecated]
1018 pub static NSPostScriptPboardType: &'static NSPasteboardType;
1019}
1020
1021extern "C" {
1022 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsvcardpboardtype?language=objc)
1023 #[deprecated]
1024 pub static NSVCardPboardType: &'static NSPasteboardType;
1025}
1026
1027extern "C" {
1028 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsinktextpboardtype?language=objc)
1029 #[deprecated]
1030 pub static NSInkTextPboardType: &'static NSPasteboardType;
1031}
1032
1033extern "C" {
1034 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfilespromisepboardtype?language=objc)
1035 #[deprecated]
1036 pub static NSFilesPromisePboardType: &'static NSPasteboardType;
1037}
1038
1039extern "C" {
1040 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboardtypefindpanelsearchoptions?language=objc)
1041 #[deprecated]
1042 pub static NSPasteboardTypeFindPanelSearchOptions: &'static NSPasteboardType;
1043}
1044
1045extern "C" {
1046 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsgeneralpboard?language=objc)
1047 #[deprecated]
1048 pub static NSGeneralPboard: &'static NSPasteboardName;
1049}
1050
1051extern "C" {
1052 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfontpboard?language=objc)
1053 #[deprecated]
1054 pub static NSFontPboard: &'static NSPasteboardName;
1055}
1056
1057extern "C" {
1058 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsrulerpboard?language=objc)
1059 #[deprecated]
1060 pub static NSRulerPboard: &'static NSPasteboardName;
1061}
1062
1063extern "C" {
1064 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsfindpboard?language=objc)
1065 #[deprecated]
1066 pub static NSFindPboard: &'static NSPasteboardName;
1067}
1068
1069extern "C" {
1070 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsdragpboard?language=objc)
1071 #[deprecated]
1072 pub static NSDragPboard: &'static NSPasteboardName;
1073}
1074
1075extern "C" {
1076 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspictpboardtype?language=objc)
1077 #[deprecated]
1078 pub static NSPICTPboardType: &'static NSPasteboardType;
1079}