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