1use objc::{msg_send, runtime::Class, sel, sel_impl};
2
3use super::{interface_impl, ns_pasteboard_item::NSPasteboardItem};
4
5use crate::{
6 foundation::{Int, NSArray, NSData, NSDictionary, NSFileWrapper, NSString, UInt},
7 object,
8 objective_c_runtime::{
9 id,
10 traits::{FromId, PNSObject},
11 },
12 utils::{to_bool, to_optional},
13};
14
15pub type NSPasteboardType = NSString;
16
17extern "C" {
18 pub static NSPasteboardTypeURL: NSPasteboardType;
23
24 pub static NSPasteboardTypeColor: NSPasteboardType;
26
27 pub static NSFileContentsPboardType: NSPasteboardType;
29
30 pub static NSPasteboardTypeFileURL: NSPasteboardType;
32
33 pub static NSFindPanelSearchOptionsPboardType: NSPasteboardType;
35
36 pub static NSPasteboardTypeFont: NSPasteboardType;
38
39 pub static NSPasteboardTypeHTML: NSPasteboardType;
41
42 pub static NSPasteboardTypeMultipleTextSelection: NSPasteboardType;
44
45 pub static NSPasteboardTypePDF: NSPasteboardType;
47
48 pub static NSPasteboardTypePNG: NSPasteboardType;
50
51 pub static NSPasteboardTypeRTF: NSPasteboardType;
53
54 pub static NSPasteboardTypeRTFD: NSPasteboardType;
56
57 pub static NSPasteboardTypeRuler: NSPasteboardType;
59
60 pub static NSPasteboardTypeSound: NSPasteboardType;
62
63 pub static NSPasteboardTypeString: NSPasteboardType;
65
66 pub static NSPasteboardTypeTabularText: NSPasteboardType;
68
69 pub static NSPasteboardTypeTextFinderOptions: NSPasteboardType;
71
72 pub static NSPasteboardTypeTIFF: NSPasteboardType;
74
75}
76
77pub type NSPasteboardTypeFindPanelSearchOptionKey = NSString;
79
80extern "C" {
81 pub static NSFindPanelCaseInsensitiveSearch: NSPasteboardTypeFindPanelSearchOptionKey;
83
84 pub static NSFindPanelSubstringMatch: NSPasteboardTypeFindPanelSearchOptionKey;
86}
87
88pub type NSPasteboardTypeTextFinderOptionKey = NSString;
90
91extern "C" {
92 pub static NSTextFinderCaseInsensitiveKey: NSPasteboardTypeTextFinderOptionKey;
94
95 pub static NSTextFinderMatchingTypeKey: NSPasteboardTypeTextFinderOptionKey;
97}
98
99pub type NSPasteboardName = NSString;
101
102extern "C" {
103 pub static NSPasteboardNameDrag: NSPasteboardName;
108
109 pub static NSPasteboardNameFind: NSPasteboardName;
111
112 pub static NSPasteboardNameFont: NSPasteboardName;
114
115 pub static NSNSPasteboardNameGeneral: NSPasteboardName;
117
118 pub static NSPasteboardNameRuler: NSPasteboardName;
120}
121
122pub type NSPasteboardReadingOptionKey = NSString;
124
125extern "C" {
126 pub static NSPasteboardURLReadingContentsConformToTypesKey: NSPasteboardReadingOptionKey;
128
129 pub static staticNSPasteboardURLReadingFileURLsOnlyKey: NSPasteboardReadingOptionKey;
130}
131
132#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
134#[repr(u64)]
135pub enum NSPasteboardReadingOptions {
136 AsData = 0,
137 AsString = 1 << 0,
138 AsPropertyList = 1 << 1,
139 AsKeyedArchive = 1 << 2,
140}
141
142#[repr(u32)]
144pub enum NSPasteboardContentsOptions {
145 CurrentHostOnly = 1,
146}
147
148object! {
149 unsafe pub struct NSPasteboard;
151}
152
153#[interface_impl(NSObject)]
154impl NSPasteboard {
155 #[property]
160 pub fn general_pasteboard() -> NSPasteboard {
161 unsafe { NSPasteboard::from_id(msg_send![Self::m_class(), generalPasteboard]) }
162 }
163
164 #[method]
166 pub fn pasteboard_by_filtering_data_of_type(
167 data: NSData,
168 r#type: NSPasteboardType,
169 ) -> NSPasteboard {
170 unsafe {
171 NSPasteboard::from_id(
172 msg_send![Self::m_class(), pasteboardByFilteringData: data ofType: r#type],
173 )
174 }
175 }
176
177 #[method]
179 pub fn pasteboard_by_filtering_file(filename: NSString) -> NSPasteboard {
180 unsafe {
181 NSPasteboard::from_id(msg_send![
182 Self::m_class(),
183 pasteboardByFilteringFile: filename
184 ])
185 }
186 }
187
188 #[method]
190 pub fn pasteboard_by_filtering_types_in_pasteboard(pboard: NSPasteboard) -> NSPasteboard {
191 unsafe {
192 NSPasteboard::from_id(msg_send![
193 Self::m_class(),
194 pasteboardByFilteringTypesInPasteboard: pboard
195 ])
196 }
197 }
198
199 #[method]
201 pub fn pasteboard_with_name(name: NSPasteboardName) -> NSPasteboard {
202 unsafe { NSPasteboard::from_id(msg_send![Self::m_class(), pasteboardWithName: name]) }
203 }
204
205 #[method]
207 pub fn pasteboard_with_unique_name() -> NSPasteboard {
208 unsafe { NSPasteboard::from_id(msg_send![Self::m_class(), pasteboardWithUniqueName]) }
209 }
210
211 #[method]
213 pub fn release_globally(&self) {
214 unsafe { msg_send![self.m_self(), releaseGlobally] }
215 }
216
217 #[method]
222 pub fn clear_contents(&mut self) -> Int {
223 unsafe { msg_send![self.m_self(), clearContents] }
224 }
225
226 #[method]
228 pub fn write_objects(&mut self, objects: NSArray<id>) -> bool {
229 unsafe { to_bool(msg_send![self.m_self(), writeObjects: objects]) }
230 }
231
232 #[method]
234 pub fn set_data_for_type(&mut self, data: NSData, data_type: NSPasteboardType) -> bool {
235 unsafe { to_bool(msg_send![self.m_self(), setData: data forType: data_type]) }
236 }
237
238 #[method]
240 pub fn set_property_list_for_type(&mut self, plist: id, data_type: NSPasteboardType) -> bool {
241 unsafe { to_bool(msg_send![self.m_self(), setPropertyList: plist forType: data_type]) }
242 }
243
244 #[method]
246 pub fn set_string_for_type(&mut self, string: NSString, data_type: NSPasteboardType) -> bool {
247 unsafe { to_bool(msg_send![self.m_self(), setString: string forType: data_type]) }
248 }
249
250 #[method]
255 pub fn read_objects_for_classes_options(
256 &self,
257 class_array: NSArray<Class>,
258 options: NSDictionary<NSPasteboardReadingOptionKey, id>,
259 ) -> Option<NSArray<id>> {
260 unsafe {
261 to_optional(
262 msg_send![self.m_self(), readObjectsForClasses: class_array options: options],
263 )
264 }
265 }
266
267 #[property]
269 pub fn pasteboard_items(&self) -> Option<NSArray<NSPasteboardItem>> {
270 unsafe { to_optional(msg_send![self.m_self(), pasteboardItems]) }
271 }
272
273 #[method]
275 pub fn index_of_pasteboard_item(&self, pasteboard_item: NSPasteboardItem) -> UInt {
276 unsafe { msg_send![self.m_self(), indexOfPasteboardItem: pasteboard_item] }
277 }
278
279 #[method]
281 pub fn data_for_type(&self, data_type: NSPasteboardType) -> Option<NSData> {
282 unsafe { to_optional(msg_send![self.m_self(), dataForType: data_type]) }
283 }
284
285 #[method]
287 pub fn property_list_for_type(&self, data_type: NSPasteboardType) -> Option<id> {
288 unsafe {
289 let ptr: id = msg_send![self.m_self(), propertyListForType: data_type];
290
291 if ptr.is_null() {
292 None
293 } else {
294 Some(ptr)
295 }
296 }
297 }
298
299 #[method]
301 pub fn string_for_type(&self, data_type: NSPasteboardType) -> Option<NSString> {
302 unsafe { to_optional(msg_send![self.m_self(), stringForType: data_type]) }
303 }
304
305 #[method]
307 pub fn available_type_from_array(
308 &self,
309 types: NSArray<NSPasteboardType>,
310 ) -> Option<NSPasteboardType> {
311 unsafe { to_optional(msg_send![self.m_self(), availableTypeFromArray: types]) }
312 }
313
314 #[method]
316 pub fn can_read_item_with_data_conforming_to_types(&self, types: NSArray<NSString>) -> bool {
317 unsafe {
318 to_bool(msg_send![
319 self.m_self(),
320 canReadItemWithDataConformingToTypes: types
321 ])
322 }
323 }
324
325 #[method]
327 pub fn can_read_object_for_classes_options(
328 &self,
329 class_array: NSArray<Class>,
330 options: NSDictionary<NSPasteboardReadingOptionKey, id>,
331 ) -> bool {
332 unsafe {
333 to_bool(msg_send![self.m_self(), canReadObjectForClasses: class_array options: options])
334 }
335 }
336
337 #[property]
339 pub fn types(&self) -> Option<NSArray<NSPasteboardType>> {
340 unsafe { to_optional(msg_send![self.m_self(), types]) }
341 }
342
343 #[method]
345 pub fn types_filterable_to(r#type: NSPasteboardType) -> NSArray<NSPasteboardType> {
346 unsafe { NSArray::from_id(msg_send![Self::m_class(), typesFilterableTo: r#type]) }
347 }
348
349 #[method]
354 pub fn prepare_for_new_contents_with_options(
355 &self,
356 options: NSPasteboardContentsOptions,
357 ) -> Int {
358 unsafe { msg_send![self.m_self(), prepareForNewContentsWithOptions: options] }
359 }
360
361 #[property]
366 pub fn name(&self) -> NSPasteboardName {
367 unsafe { NSPasteboardName::from_id(msg_send![self.m_self(), name]) }
368 }
369
370 #[property]
372 pub fn change_count(&self) -> Int {
373 unsafe { msg_send![self.m_self(), changeCount] }
374 }
375
376 #[method]
381 pub fn declare_types_owner(&self, new_types: NSArray<NSPasteboardType>, new_owner: id) -> Int {
382 unsafe { msg_send![self.m_self(), declareTypes: new_types owner: new_owner ] }
383 }
384
385 #[method]
387 pub fn add_types_owner(&mut self, new_types: NSArray<NSPasteboardType>, new_owner: id) -> Int {
388 unsafe { msg_send![self.m_self(), addTypes: new_types owner: new_owner] }
389 }
390
391 #[method]
393 pub fn write_file_contents(&mut self, filename: NSString) -> bool {
394 unsafe { to_bool(msg_send![self.m_self(), writeFileContents: filename]) }
395 }
396
397 #[method]
399 pub fn write_file_wrapper(&mut self, wrapper: NSFileWrapper) -> bool {
400 unsafe { to_bool(msg_send![self.m_self(), writeFileWrapper: wrapper]) }
401 }
402
403 #[method]
408 pub fn read_file_contents_type_to_file(
409 &self,
410 r#type: NSPasteboardType,
411 filename: NSString,
412 ) -> Option<NSString> {
413 unsafe {
414 to_optional(msg_send![
415 self.m_self(),
416 readFileContentsType: r#type
417 toFile: filename
418 ])
419 }
420 }
421
422 #[method]
424 pub fn read_file_wrapper(&self) -> Option<NSFileWrapper> {
425 unsafe { to_optional(msg_send![self.m_self(), readFileWrapper]) }
426 }
427}