objc2_app_kit/generated/
NSPasteboardItem.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
10extern_class!(
11    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarditem?language=objc)
12    #[unsafe(super(NSObject))]
13    #[derive(Debug, PartialEq, Eq, Hash)]
14    pub struct NSPasteboardItem;
15);
16
17extern_conformance!(
18    unsafe impl NSObjectProtocol for NSPasteboardItem {}
19);
20
21#[cfg(feature = "NSPasteboard")]
22extern_conformance!(
23    unsafe impl NSPasteboardReading for NSPasteboardItem {}
24);
25
26#[cfg(feature = "NSPasteboard")]
27extern_conformance!(
28    unsafe impl NSPasteboardWriting for NSPasteboardItem {}
29);
30
31impl NSPasteboardItem {
32    extern_methods!(
33        #[cfg(feature = "NSPasteboard")]
34        #[unsafe(method(types))]
35        #[unsafe(method_family = none)]
36        pub fn types(&self) -> Retained<NSArray<NSPasteboardType>>;
37
38        #[cfg(feature = "NSPasteboard")]
39        #[unsafe(method(availableTypeFromArray:))]
40        #[unsafe(method_family = none)]
41        pub fn availableTypeFromArray(
42            &self,
43            types: &NSArray<NSPasteboardType>,
44        ) -> Option<Retained<NSPasteboardType>>;
45
46        #[cfg(feature = "NSPasteboard")]
47        #[unsafe(method(setDataProvider:forTypes:))]
48        #[unsafe(method_family = none)]
49        pub fn setDataProvider_forTypes(
50            &self,
51            data_provider: &ProtocolObject<dyn NSPasteboardItemDataProvider>,
52            types: &NSArray<NSPasteboardType>,
53        ) -> bool;
54
55        #[cfg(feature = "NSPasteboard")]
56        #[unsafe(method(setData:forType:))]
57        #[unsafe(method_family = none)]
58        pub fn setData_forType(&self, data: &NSData, r#type: &NSPasteboardType) -> bool;
59
60        #[cfg(feature = "NSPasteboard")]
61        #[unsafe(method(setString:forType:))]
62        #[unsafe(method_family = none)]
63        pub fn setString_forType(&self, string: &NSString, r#type: &NSPasteboardType) -> bool;
64
65        #[cfg(feature = "NSPasteboard")]
66        /// # Safety
67        ///
68        /// `property_list` should be of the correct type.
69        #[unsafe(method(setPropertyList:forType:))]
70        #[unsafe(method_family = none)]
71        pub unsafe fn setPropertyList_forType(
72            &self,
73            property_list: &AnyObject,
74            r#type: &NSPasteboardType,
75        ) -> bool;
76
77        #[cfg(feature = "NSPasteboard")]
78        #[unsafe(method(dataForType:))]
79        #[unsafe(method_family = none)]
80        pub fn dataForType(&self, r#type: &NSPasteboardType) -> Option<Retained<NSData>>;
81
82        #[cfg(feature = "NSPasteboard")]
83        #[unsafe(method(stringForType:))]
84        #[unsafe(method_family = none)]
85        pub fn stringForType(&self, r#type: &NSPasteboardType) -> Option<Retained<NSString>>;
86
87        #[cfg(feature = "NSPasteboard")]
88        #[unsafe(method(propertyListForType:))]
89        #[unsafe(method_family = none)]
90        pub fn propertyListForType(&self, r#type: &NSPasteboardType)
91            -> Option<Retained<AnyObject>>;
92
93        #[cfg(all(feature = "NSPasteboard", feature = "block2"))]
94        /// Determines whether this pasteboard item matches the specified patterns, without notifying the person using the app.
95        ///
96        /// This method only gives an indication of whether a 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.
97        ///
98        /// The following example shows how to use this method to find email and postal addresses in each item on the pasteboard:
99        ///
100        /// ```obj-c
101        /// NSArray
102        /// <NSPasteboardItem
103        /// *> *items = NSPasteboard.generalPasteboard.pasteboardItems;
104        /// __block NSUInteger idx = 0;
105        /// for (NSPasteboardItem *item in items) {
106        /// NSUInteger itemIndex = idx++;
107        /// [item
108        /// detectPatternsForPatterns:[NSSet setWithArray:
109        /// @
110        /// [NSPasteboardDetectionPatternEmailAddress,
111        /// NSPasteboardDetectionPatternPostalAddress]]
112        /// completionHandler:^(NSSet
113        /// <NSPasteboardDetectionPattern
114        /// > *matchedPatterns, NSError *error) {
115        /// if (error) {
116        /// NSLog(
117        /// "
118        /// Item %lu: Error: %
119        /// "
120        /// , itemIndex, error);
121        /// return;
122        /// }
123        /// BOOL matchedEmail = [matchedPatterns containsObject:NSPasteboardDetectionPatternEmailAddress];
124        /// BOOL matchedPostal = [matchedPatterns containsObject: NSPasteboardDetectionPatternPostalAddress];
125        /// if (matchedEmail) {
126        /// NSLog(
127        /// "
128        /// Item %lu - Email address(es) detected", itemIndex);
129        /// }
130        /// if (matchedPostal) {
131        /// NSLog(
132        /// "
133        /// Item %lu - Postal address(es) detected", itemIndex);
134        /// }
135        /// if (!matchedEmail
136        /// &
137        /// &
138        /// !matchedPostal) {
139        /// NSLog(
140        /// "
141        /// Item %lu - Matched neither email nor postal addresses.", itemIndex);
142        /// }
143        /// }];
144        /// }
145        /// ```
146        ///
147        /// - Parameters:
148        /// - patterns: The patterns to detect on the pasteboard item.
149        /// - completionHandler: A block that the system invokes after detecting patterns on the pasteboard item. The block receives either a set with the patterns the system finds on the pasteboard item or an error if detection fails.
150        #[unsafe(method(detectPatternsForPatterns:completionHandler:))]
151        #[unsafe(method_family = none)]
152        pub fn detectPatternsForPatterns_completionHandler(
153            &self,
154            patterns: &NSSet<NSPasteboardDetectionPattern>,
155            completion_handler: &block2::DynBlock<
156                dyn Fn(*mut NSSet<NSPasteboardDetectionPattern>, *mut NSError),
157            >,
158        );
159
160        #[cfg(all(feature = "NSPasteboard", feature = "block2"))]
161        /// Determines whether this pasteboard item matches the specified patterns, reading the contents if it finds a match.
162        ///
163        /// For details about the types returned for each pattern, see ``NSPasteboardDetectionPattern``.
164        ///
165        /// The following example shows how to use this method to find web URLs and web search terms in each item on the pasteboard:
166        ///
167        /// ```obj-c
168        /// NSArray
169        /// <NSPasteboardItem
170        /// *> *items = NSPasteboard.generalPasteboard.pasteboardItems;
171        /// __block NSUInteger idx = 0;
172        /// for (NSPasteboardItem *item in items) {
173        /// NSUInteger itemIndex = idx++;
174        /// [item
175        /// detectValuesForPatterns:[NSSet setWithArray:
176        /// @
177        /// [NSPasteboardDetectionPatternProbableWebSearch,
178        /// NSPasteboardDetectionPatternProbableWebURL]]
179        /// completionHandler:^(NSDictionary
180        /// <NSPasteboardDetectionPattern
181        /// , id> *patternValues, NSError *error) {
182        /// if (error) {
183        /// NSLog(
184        /// "
185        /// Item %lu: Error: %
186        /// "
187        /// , itemIndex, error);
188        /// return;
189        /// }
190        /// NSString *searchString = (NSString*)patternValues[NSPasteboardDetectionPatternProbableWebSearch];
191        /// NSString *urlString = (NSString*)patternValues[NSPasteboardDetectionPatternProbableWebURL] ;
192        /// if (searchString != nil) {
193        /// NSLog(
194        /// "
195        /// Item %lu - Web search retrieved: %
196        /// "
197        /// , itemIndex, searchString);
198        /// }
199        /// if (urlString != nil) {
200        /// NSLog(
201        /// "
202        /// Item %lu - Web URL retrieved: %
203        /// "
204        /// , itemIndex, urlString);
205        /// }
206        /// if (searchString == nil
207        /// &
208        /// &
209        /// urlString == nil) {
210        /// NSLog(
211        /// "
212        /// Item %lu - No web patterns retrieved.", itemIndex);
213        /// }
214        /// }];
215        /// }
216        /// ```
217        ///
218        /// > 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.
219        ///
220        /// - Parameters:
221        /// - patterns: The patterns to detect on the pasteboard item.
222        /// - completionHandler: A block the system invokes after detecting patterns on the pasteboard item. The block returns either a dictionary with the patterns the system finds on the pasteboard item or an error if detection fails. The dictionary keys specify the matched patterns, and the values specify the corresponding content of the pasteboard.
223        #[unsafe(method(detectValuesForPatterns:completionHandler:))]
224        #[unsafe(method_family = none)]
225        pub fn detectValuesForPatterns_completionHandler(
226            &self,
227            patterns: &NSSet<NSPasteboardDetectionPattern>,
228            completion_handler: &block2::DynBlock<
229                dyn Fn(*mut NSDictionary<NSPasteboardDetectionPattern, AnyObject>, *mut NSError),
230            >,
231        );
232
233        #[cfg(all(feature = "NSPasteboard", feature = "block2"))]
234        /// Determines available metadata from the specified metadata types for this pasteboard item, without notifying the person using the app.
235        ///
236        /// 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.
237        ///
238        /// For details about the metadata returned for each type, see ``NSPasteboardMetadataType``.
239        ///
240        /// The following example shows how to iterate over each pasteboard item and, if the item is a URL that points to a file, get its content type with this method:
241        ///
242        /// ```obj-c
243        /// NSArray
244        /// <NSPasteboardItem
245        /// *> *items = NSPasteboard.generalPasteboard.pasteboardItems;
246        /// __block NSUInteger idx = 0;
247        /// for (NSPasteboardItem *item in items) {
248        /// NSUInteger itemIndex = idx++;
249        /// [item
250        /// detectMetadataForTypes:[NSSet setWithArray:
251        /// @
252        /// [NSPasteboardMetadataTypeContentType]]
253        /// completionHandler:^(NSDictionary
254        /// <NSPasteboardMetadataType
255        /// , id> *metadata, NSError *error) {
256        /// if (error) {
257        /// NSLog(
258        /// "
259        /// Item %lu - Error: %
260        /// "
261        /// , itemIndex, error);
262        /// return;
263        /// }
264        /// UTType *contentType = (UTType*)metadata[NSPasteboardMetadataTypeContentType];
265        /// if (contentType) {
266        /// NSLog(
267        /// "
268        /// Item %lu - Content type is: %
269        /// "
270        /// , itemIndex, contentType.identifier);
271        /// } else {
272        /// NSLog(
273        /// "
274        /// Item %lu - Couldn't get content type", itemIndex);
275        /// }
276        /// }];
277        /// }
278        /// ```
279        ///
280        /// - Parameters:
281        /// - types: The metadata types to detect on the pasteboard item.
282        /// - completionHandler: A block the system invokes after detecting metadata on the pasteboard item. The block receives either a dictionary with the metadata types the system finds on the pasteboard item or an error if detection fails. The dictionary keys specify the matched metadata types, and the values specify the corresponding metadata.
283        #[unsafe(method(detectMetadataForTypes:completionHandler:))]
284        #[unsafe(method_family = none)]
285        pub fn detectMetadataForTypes_completionHandler(
286            &self,
287            types: &NSSet<NSPasteboardMetadataType>,
288            completion_handler: &block2::DynBlock<
289                dyn Fn(*mut NSDictionary<NSPasteboardMetadataType, AnyObject>, *mut NSError),
290            >,
291        );
292    );
293}
294
295/// Methods declared on superclass `NSObject`.
296impl NSPasteboardItem {
297    extern_methods!(
298        #[unsafe(method(init))]
299        #[unsafe(method_family = init)]
300        pub fn init(this: Allocated<Self>) -> Retained<Self>;
301
302        #[unsafe(method(new))]
303        #[unsafe(method_family = new)]
304        pub fn new() -> Retained<Self>;
305    );
306}
307
308impl DefaultRetained for NSPasteboardItem {
309    #[inline]
310    fn default_retained() -> Retained<Self> {
311        Self::new()
312    }
313}
314
315extern_protocol!(
316    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspasteboarditemdataprovider?language=objc)
317    pub unsafe trait NSPasteboardItemDataProvider: NSObjectProtocol {
318        #[cfg(feature = "NSPasteboard")]
319        #[unsafe(method(pasteboard:item:provideDataForType:))]
320        #[unsafe(method_family = none)]
321        fn pasteboard_item_provideDataForType(
322            &self,
323            pasteboard: Option<&NSPasteboard>,
324            item: &NSPasteboardItem,
325            r#type: &NSPasteboardType,
326        );
327
328        #[cfg(feature = "NSPasteboard")]
329        #[optional]
330        #[unsafe(method(pasteboardFinishedWithDataProvider:))]
331        #[unsafe(method_family = none)]
332        fn pasteboardFinishedWithDataProvider(&self, pasteboard: &NSPasteboard);
333    }
334);