objc2_app_kit/generated/NSSharingService.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::*;
6#[cfg(feature = "objc2-cloud-kit")]
7#[cfg(target_vendor = "apple")]
8use objc2_cloud_kit::*;
9use objc2_foundation::*;
10
11use crate::*;
12
13/// Built-in sharing services
14///
15/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicename?language=objc)
16// NS_TYPED_EXTENSIBLE_ENUM
17pub type NSSharingServiceName = NSString;
18
19extern "C" {
20 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamecomposeemail?language=objc)
21 pub static NSSharingServiceNameComposeEmail: &'static NSSharingServiceName;
22}
23
24extern "C" {
25 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamecomposemessage?language=objc)
26 pub static NSSharingServiceNameComposeMessage: &'static NSSharingServiceName;
27}
28
29extern "C" {
30 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamesendviaairdrop?language=objc)
31 pub static NSSharingServiceNameSendViaAirDrop: &'static NSSharingServiceName;
32}
33
34extern "C" {
35 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenameaddtosafarireadinglist?language=objc)
36 pub static NSSharingServiceNameAddToSafariReadingList: &'static NSSharingServiceName;
37}
38
39extern "C" {
40 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenameaddtoiphoto?language=objc)
41 pub static NSSharingServiceNameAddToIPhoto: &'static NSSharingServiceName;
42}
43
44extern "C" {
45 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenameaddtoaperture?language=objc)
46 pub static NSSharingServiceNameAddToAperture: &'static NSSharingServiceName;
47}
48
49extern "C" {
50 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenameuseasdesktoppicture?language=objc)
51 pub static NSSharingServiceNameUseAsDesktopPicture: &'static NSSharingServiceName;
52}
53
54extern "C" {
55 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamepostonfacebook?language=objc)
56 #[deprecated = "This service is no longer included with the system."]
57 pub static NSSharingServiceNamePostOnFacebook: &'static NSSharingServiceName;
58}
59
60extern "C" {
61 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamepostontwitter?language=objc)
62 #[deprecated = "This service is no longer included with the system."]
63 pub static NSSharingServiceNamePostOnTwitter: &'static NSSharingServiceName;
64}
65
66extern "C" {
67 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamepostonsinaweibo?language=objc)
68 #[deprecated = "This service is no longer included with the system."]
69 pub static NSSharingServiceNamePostOnSinaWeibo: &'static NSSharingServiceName;
70}
71
72extern "C" {
73 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamepostontencentweibo?language=objc)
74 #[deprecated = "This service is no longer included with the system."]
75 pub static NSSharingServiceNamePostOnTencentWeibo: &'static NSSharingServiceName;
76}
77
78extern "C" {
79 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamepostonlinkedin?language=objc)
80 #[deprecated = "This service is no longer included with the system."]
81 pub static NSSharingServiceNamePostOnLinkedIn: &'static NSSharingServiceName;
82}
83
84extern "C" {
85 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenameuseastwitterprofileimage?language=objc)
86 #[deprecated = "This service is no longer included with the system."]
87 pub static NSSharingServiceNameUseAsTwitterProfileImage: &'static NSSharingServiceName;
88}
89
90extern "C" {
91 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenameuseasfacebookprofileimage?language=objc)
92 #[deprecated = "This service is no longer included with the system."]
93 pub static NSSharingServiceNameUseAsFacebookProfileImage: &'static NSSharingServiceName;
94}
95
96extern "C" {
97 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenameuseaslinkedinprofileimage?language=objc)
98 #[deprecated = "This service is no longer included with the system."]
99 pub static NSSharingServiceNameUseAsLinkedInProfileImage: &'static NSSharingServiceName;
100}
101
102extern "C" {
103 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamepostimageonflickr?language=objc)
104 #[deprecated = "This service is no longer included with the system."]
105 pub static NSSharingServiceNamePostImageOnFlickr: &'static NSSharingServiceName;
106}
107
108extern "C" {
109 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamepostvideoonvimeo?language=objc)
110 #[deprecated = "This service is no longer included with the system."]
111 pub static NSSharingServiceNamePostVideoOnVimeo: &'static NSSharingServiceName;
112}
113
114extern "C" {
115 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamepostvideoonyouku?language=objc)
116 #[deprecated = "This service is no longer included with the system."]
117 pub static NSSharingServiceNamePostVideoOnYouku: &'static NSSharingServiceName;
118}
119
120extern "C" {
121 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamepostvideoontudou?language=objc)
122 #[deprecated = "This service is no longer included with the system."]
123 pub static NSSharingServiceNamePostVideoOnTudou: &'static NSSharingServiceName;
124}
125
126extern "C" {
127 /// This service differs from other NSSharingServices in that it allows the user to establish a persistent sharing session for the specified items with potentially many participants, instead of sending a copy of the items. You can invoke this service with an NSItemProvider that has registered a CKShare
128 /// &
129 /// CKContainer via either -registerCloudKitShare:container: or -registerCloudKitShareWithPreparationHandler:. (Registering other types on the same provider to enable other sharing services is allowed.)
130 ///
131 /// When performed, this service gives the user the opportunity to invite participants and start sharing. If the content is already shared, the service instead allows the user to view or modify participation or stop sharing. To detect changes the service makes to the CKShare, implement -sharingService:didSaveShare: and -sharingService:didStopSharing:.
132 ///
133 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicenamecloudsharing?language=objc)
134 pub static NSSharingServiceNameCloudSharing: &'static NSSharingServiceName;
135}
136
137extern_class!(
138 /// NSSharingService can be used to share items to different kinds of local and remote services. Items are objects which respond to the NSPasteboardWriting protocol, like NSURL, NSImage or NSString. If an NSURL is a file URL (point to a video for example), then the content of the file will be shared. If the URL is remote, then the URL itself will be shared.
139 ///
140 /// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservice?language=objc)
141 #[unsafe(super(NSObject))]
142 #[derive(Debug, PartialEq, Eq, Hash)]
143 pub struct NSSharingService;
144);
145
146extern_conformance!(
147 unsafe impl NSObjectProtocol for NSSharingService {}
148);
149
150impl NSSharingService {
151 extern_methods!(
152 #[unsafe(method(delegate))]
153 #[unsafe(method_family = none)]
154 pub fn delegate(
155 &self,
156 mtm: MainThreadMarker,
157 ) -> Option<Retained<ProtocolObject<dyn NSSharingServiceDelegate>>>;
158
159 /// Setter for [`delegate`][Self::delegate].
160 ///
161 /// This is a [weak property][objc2::topics::weak_property].
162 #[unsafe(method(setDelegate:))]
163 #[unsafe(method_family = none)]
164 pub fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSSharingServiceDelegate>>);
165
166 #[unsafe(method(title))]
167 #[unsafe(method_family = none)]
168 pub fn title(&self) -> Retained<NSString>;
169
170 #[cfg(feature = "NSImage")]
171 #[unsafe(method(image))]
172 #[unsafe(method_family = none)]
173 pub fn image(&self) -> Retained<NSImage>;
174
175 #[cfg(feature = "NSImage")]
176 #[unsafe(method(alternateImage))]
177 #[unsafe(method_family = none)]
178 pub fn alternateImage(&self) -> Option<Retained<NSImage>>;
179
180 /// Title of the service in the Share menu. Can be modified.
181 #[unsafe(method(menuItemTitle))]
182 #[unsafe(method_family = none)]
183 pub fn menuItemTitle(&self) -> Retained<NSString>;
184
185 /// Setter for [`menuItemTitle`][Self::menuItemTitle].
186 ///
187 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
188 #[unsafe(method(setMenuItemTitle:))]
189 #[unsafe(method_family = none)]
190 pub fn setMenuItemTitle(&self, menu_item_title: &NSString);
191
192 /// NSArray of NSString objects representing handles (example: email adresses)
193 #[unsafe(method(recipients))]
194 #[unsafe(method_family = none)]
195 pub fn recipients(&self) -> Option<Retained<NSArray<NSString>>>;
196
197 /// Setter for [`recipients`][Self::recipients].
198 ///
199 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
200 #[unsafe(method(setRecipients:))]
201 #[unsafe(method_family = none)]
202 pub fn setRecipients(&self, recipients: Option<&NSArray<NSString>>);
203
204 #[unsafe(method(subject))]
205 #[unsafe(method_family = none)]
206 pub fn subject(&self) -> Option<Retained<NSString>>;
207
208 /// Setter for [`subject`][Self::subject].
209 ///
210 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
211 #[unsafe(method(setSubject:))]
212 #[unsafe(method_family = none)]
213 pub fn setSubject(&self, subject: Option<&NSString>);
214
215 /// Message body as string
216 #[unsafe(method(messageBody))]
217 #[unsafe(method_family = none)]
218 pub fn messageBody(&self) -> Option<Retained<NSString>>;
219
220 /// URL to access the post on Facebook, Twitter, Sina Weibo, etc. (also known as permalink)
221 #[unsafe(method(permanentLink))]
222 #[unsafe(method_family = none)]
223 pub fn permanentLink(&self) -> Option<Retained<NSURL>>;
224
225 /// Account name used for sending on Twitter or Sina Weibo
226 #[unsafe(method(accountName))]
227 #[unsafe(method_family = none)]
228 pub fn accountName(&self) -> Option<Retained<NSString>>;
229
230 /// NSArray of NSURL objects representing the files that were shared
231 #[unsafe(method(attachmentFileURLs))]
232 #[unsafe(method_family = none)]
233 pub fn attachmentFileURLs(&self) -> Option<Retained<NSArray<NSURL>>>;
234
235 /// Returns a list of NSSharingServices which could share all the provided items together. sharingServicesForItems can be used to build a custom UI, or to populate a contextual NSMenu.
236 /// The items represent the objects to be shared and must conform to the
237 /// <NSPasteboardWriting
238 /// > protocol or be an NSItemProvider or an NSDocument. (e.g. NSString, NSImage, NSURL, etc.)
239 ///
240 /// # Safety
241 ///
242 /// `items` generic should be of the correct type.
243 #[deprecated = "Use -[NSSharingServicePicker standardShareMenuItem] instead."]
244 #[unsafe(method(sharingServicesForItems:))]
245 #[unsafe(method_family = none)]
246 pub unsafe fn sharingServicesForItems(
247 items: &NSArray,
248 ) -> Retained<NSArray<NSSharingService>>;
249
250 /// Returns an NSSharingService representing one of the built-in services.
251 #[unsafe(method(sharingServiceNamed:))]
252 #[unsafe(method_family = none)]
253 pub fn sharingServiceNamed(
254 service_name: &NSSharingServiceName,
255 ) -> Option<Retained<NSSharingService>>;
256
257 #[cfg(all(feature = "NSImage", feature = "block2"))]
258 /// Creates a custom NSSharingService object. Custom sharing services can be added to the NSSharingServicePicker with the sharingServicePicker:sharingServicesForItems:proposedSharingServices: delegate method.
259 #[unsafe(method(initWithTitle:image:alternateImage:handler:))]
260 #[unsafe(method_family = init)]
261 pub fn initWithTitle_image_alternateImage_handler(
262 this: Allocated<Self>,
263 title: &NSString,
264 image: &NSImage,
265 alternate_image: Option<&NSImage>,
266 block: &block2::DynBlock<dyn Fn()>,
267 ) -> Retained<Self>;
268
269 /// Use -initWithTitle:image:alternateImage:handler: instead
270 #[unsafe(method(init))]
271 #[unsafe(method_family = init)]
272 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
273
274 /// Returns whether a service can do something with all the provided items. This can be used to validate a custom UI such as a dedicated Twitter button. If items is nil, the method will return YES when the service is configured. Therefore you could call it once at launch time with nil items to check whether to display the button or not, and then with real items to enable and disable the button depending on the context or selection.
275 ///
276 /// The items represent the objects to be shared and must conform to the
277 /// <NSPasteboardWriting
278 /// > protocol or be an NSItemProvider or an NSDocument. (e.g. NSString, NSImage, NSURL, etc.)
279 ///
280 /// # Safety
281 ///
282 /// `items` generic should be of the correct type.
283 #[unsafe(method(canPerformWithItems:))]
284 #[unsafe(method_family = none)]
285 pub unsafe fn canPerformWithItems(&self, items: Option<&NSArray>) -> bool;
286
287 /// Manually performs the service on the provided items. In most cases this will display a sharing window.
288 ///
289 /// The items represent the objects to be shared and must conform to the
290 /// <NSPasteboardWriting
291 /// > protocol or be an NSItemProvider or an NSDocument. (e.g. NSString, NSImage, NSURL, etc.)
292 ///
293 /// # Safety
294 ///
295 /// `items` generic should be of the correct type.
296 #[unsafe(method(performWithItems:))]
297 #[unsafe(method_family = none)]
298 pub unsafe fn performWithItems(&self, items: &NSArray);
299 );
300}
301
302/// Methods declared on superclass `NSObject`.
303impl NSSharingService {
304 extern_methods!(
305 #[unsafe(method(new))]
306 #[unsafe(method_family = new)]
307 pub unsafe fn new() -> Retained<Self>;
308 );
309}
310
311/// Use the sharing scope to specify the nature of the things you are sharing.
312///
313/// The sharing scope can be modified from the default value of NSSharingContentScopeItem by setting a different value in the out parameter in sharingService:sourceWindowForShareItems:sharingContentScope:.
314///
315/// See also [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingcontentscope?language=objc)
316// NS_ENUM
317#[repr(transparent)]
318#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
319pub struct NSSharingContentScope(pub NSInteger);
320impl NSSharingContentScope {
321 /// NSSharingContentScopeItem: use when sharing a clearly identified item, e.g. a file represented by its icon.
322 #[doc(alias = "NSSharingContentScopeItem")]
323 pub const Item: Self = Self(0);
324 /// NSSharingContentScopePartial: use when sharing a portion of a more global content, e.g. part of a webpage
325 #[doc(alias = "NSSharingContentScopePartial")]
326 pub const Partial: Self = Self(1);
327 /// NSSharingContentScopeFull: use when sharing the whole content of the current document, e.g. the url of the webpage
328 #[doc(alias = "NSSharingContentScopeFull")]
329 pub const Full: Self = Self(2);
330}
331
332unsafe impl Encode for NSSharingContentScope {
333 const ENCODING: Encoding = NSInteger::ENCODING;
334}
335
336unsafe impl RefEncode for NSSharingContentScope {
337 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
338}
339
340extern_protocol!(
341 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicedelegate?language=objc)
342 pub unsafe trait NSSharingServiceDelegate: NSObjectProtocol + MainThreadOnly {
343 /// # Safety
344 ///
345 /// `items` generic should be of the correct type.
346 #[optional]
347 #[unsafe(method(sharingService:willShareItems:))]
348 #[unsafe(method_family = none)]
349 unsafe fn sharingService_willShareItems(
350 &self,
351 sharing_service: &NSSharingService,
352 items: &NSArray,
353 );
354
355 /// # Safety
356 ///
357 /// `items` generic should be of the correct type.
358 #[optional]
359 #[unsafe(method(sharingService:didFailToShareItems:error:))]
360 #[unsafe(method_family = none)]
361 unsafe fn sharingService_didFailToShareItems_error(
362 &self,
363 sharing_service: &NSSharingService,
364 items: &NSArray,
365 error: &NSError,
366 );
367
368 /// # Safety
369 ///
370 /// `items` generic should be of the correct type.
371 #[optional]
372 #[unsafe(method(sharingService:didShareItems:))]
373 #[unsafe(method_family = none)]
374 unsafe fn sharingService_didShareItems(
375 &self,
376 sharing_service: &NSSharingService,
377 items: &NSArray,
378 );
379
380 /// # Safety
381 ///
382 /// `item` should be of the correct type.
383 #[optional]
384 #[unsafe(method(sharingService:sourceFrameOnScreenForShareItem:))]
385 #[unsafe(method_family = none)]
386 unsafe fn sharingService_sourceFrameOnScreenForShareItem(
387 &self,
388 sharing_service: &NSSharingService,
389 item: &AnyObject,
390 ) -> NSRect;
391
392 #[cfg(feature = "NSImage")]
393 /// When non-nil, the image returned would be used for the transitioning animation. When nil, the transitioning animation is disabled.
394 ///
395 /// # Safety
396 ///
397 /// - `item` should be of the correct type.
398 /// - `content_rect` must be a valid pointer.
399 #[optional]
400 #[unsafe(method(sharingService:transitionImageForShareItem:contentRect:))]
401 #[unsafe(method_family = none)]
402 unsafe fn sharingService_transitionImageForShareItem_contentRect(
403 &self,
404 sharing_service: &NSSharingService,
405 item: &AnyObject,
406 content_rect: NonNull<NSRect>,
407 ) -> Option<Retained<NSImage>>;
408
409 #[cfg(all(feature = "NSResponder", feature = "NSWindow"))]
410 /// # Safety
411 ///
412 /// - `items` generic should be of the correct type.
413 /// - `sharing_content_scope` must be a valid pointer.
414 #[optional]
415 #[unsafe(method(sharingService:sourceWindowForShareItems:sharingContentScope:))]
416 #[unsafe(method_family = none)]
417 unsafe fn sharingService_sourceWindowForShareItems_sharingContentScope(
418 &self,
419 sharing_service: &NSSharingService,
420 items: &NSArray,
421 sharing_content_scope: NonNull<NSSharingContentScope>,
422 ) -> Option<Retained<NSWindow>>;
423
424 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
425 /// The following method is invoked when the service is performed and wants to display its contents in a popover. The delegate should return the view that will act as the anchor of the popover, along with the target rectangle within the bounds of that view and preferred edge of that rectangle for the popover to appear. The delegate may also return nil, indicating that there is no anchoring view currently available, in which case the service may attempt to display the service via some other means.
426 ///
427 /// The service named NSSharingServiceNameCloudSharing prefers to display itself using a popover anchored to an "Add People" or "Share" button. If no such button is available or visible, return nil.
428 ///
429 /// # Safety
430 ///
431 /// - `positioning_rect` must be a valid pointer.
432 /// - `preferred_edge` must be a valid pointer.
433 #[optional]
434 #[unsafe(method(anchoringViewForSharingService:showRelativeToRect:preferredEdge:))]
435 #[unsafe(method_family = none)]
436 unsafe fn anchoringViewForSharingService_showRelativeToRect_preferredEdge(
437 &self,
438 sharing_service: &NSSharingService,
439 positioning_rect: NonNull<NSRect>,
440 preferred_edge: NonNull<NSRectEdge>,
441 ) -> Option<Retained<NSView>>;
442 }
443);
444
445/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nscloudkitsharingserviceoptions?language=objc)
446// NS_OPTIONS
447#[repr(transparent)]
448#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
449pub struct NSCloudKitSharingServiceOptions(pub NSUInteger);
450bitflags::bitflags! {
451 impl NSCloudKitSharingServiceOptions: NSUInteger {
452/// Allow the user to configure the share with the standard set of options.
453 #[doc(alias = "NSCloudKitSharingServiceStandard")]
454 const Standard = 0;
455/// The user is allowed to share publicly.
456 #[doc(alias = "NSCloudKitSharingServiceAllowPublic")]
457 const AllowPublic = 1<<0;
458/// The user is allowed to share privately.
459 #[doc(alias = "NSCloudKitSharingServiceAllowPrivate")]
460 const AllowPrivate = 1<<1;
461/// The user is allowed to grant participants read-only permissions.
462 #[doc(alias = "NSCloudKitSharingServiceAllowReadOnly")]
463 const AllowReadOnly = 1<<4;
464/// The user is allowed to grant participants read/write permissions.
465 #[doc(alias = "NSCloudKitSharingServiceAllowReadWrite")]
466 const AllowReadWrite = 1<<5;
467 }
468}
469
470unsafe impl Encode for NSCloudKitSharingServiceOptions {
471 const ENCODING: Encoding = NSUInteger::ENCODING;
472}
473
474unsafe impl RefEncode for NSCloudKitSharingServiceOptions {
475 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
476}
477
478extern_protocol!(
479 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nscloudsharingservicedelegate?language=objc)
480 pub unsafe trait NSCloudSharingServiceDelegate: NSSharingServiceDelegate {
481 /// When an NSSharingServiceNameCloudSharing sharing service is dismissed it will invoke this method on the delegate, with an error if there was any. If the delegate implements this method, NSSharingServiceNameCloudSharing will not send -sharingService:didFailToShareItems:error: or -sharingService:didShareItems:.
482 ///
483 /// # Safety
484 ///
485 /// `items` generic should be of the correct type.
486 #[optional]
487 #[unsafe(method(sharingService:didCompleteForItems:error:))]
488 #[unsafe(method_family = none)]
489 unsafe fn sharingService_didCompleteForItems_error(
490 &self,
491 sharing_service: &NSSharingService,
492 items: &NSArray,
493 error: Option<&NSError>,
494 );
495
496 /// The options returned by this method describe how the user is allowed to configure the share: whether the share is public or private, and whether participants have read-only or read/write permissions. If this method is not implemented, NSCloudKitSharingServiceStandard is assumed.
497 #[optional]
498 #[unsafe(method(optionsForSharingService:shareProvider:))]
499 #[unsafe(method_family = none)]
500 fn optionsForSharingService_shareProvider(
501 &self,
502 cloud_kit_sharing_service: &NSSharingService,
503 provider: &NSItemProvider,
504 ) -> NSCloudKitSharingServiceOptions;
505
506 #[cfg(feature = "objc2-cloud-kit")]
507 #[cfg(target_vendor = "apple")]
508 /// When an NSSharingServiceNameCloudSharing sharing service successfully saves modifications to the CKShare, it will invoke this method on the delegate with the last-known state of the CKShare on the server.
509 #[optional]
510 #[unsafe(method(sharingService:didSaveShare:))]
511 #[unsafe(method_family = none)]
512 fn sharingService_didSaveShare(&self, sharing_service: &NSSharingService, share: &CKShare);
513
514 #[cfg(feature = "objc2-cloud-kit")]
515 #[cfg(target_vendor = "apple")]
516 /// When an NSSharingServiceNameCloudSharing sharing service stops sharing it will delete the CKShare from the server, then invoke this method on the delegate with the last-known state of the CKShare.
517 #[optional]
518 #[unsafe(method(sharingService:didStopSharing:))]
519 #[unsafe(method_family = none)]
520 fn sharingService_didStopSharing(
521 &self,
522 sharing_service: &NSSharingService,
523 share: &CKShare,
524 );
525 }
526);
527
528mod private_NSItemProviderNSCloudKitSharing {
529 pub trait Sealed {}
530}
531
532/// Category "NSCloudKitSharing" on [`NSItemProvider`].
533#[doc(alias = "NSCloudKitSharing")]
534pub unsafe trait NSItemProviderNSCloudKitSharing:
535 ClassType + Sized + private_NSItemProviderNSCloudKitSharing::Sealed
536{
537 extern_methods!(
538 #[cfg(all(feature = "block2", feature = "objc2-cloud-kit"))]
539 #[cfg(target_vendor = "apple")]
540 /// Use this method when you want to share a collection of CKRecords but don't currently have a CKShare. When the preparationHandler is called, you should create a new CKShare with the appropriate root CKRecord. After ensuring the share and all records have been saved to the server, invoke the preparationCompletionHandler with either the resulting CKShare and its CKContainer, or an NSError if saving failed. Invoking the service with a CKShare registered with this method will prompt the user to start sharing.
541 ///
542 /// # Safety
543 ///
544 /// - `preparation_handler` block's argument block's argument 1 must be a valid pointer or null.
545 /// - `preparation_handler` block's argument block's argument 2 must be a valid pointer or null.
546 /// - `preparation_handler` block's argument block's argument 3 must be a valid pointer or null.
547 #[unsafe(method(registerCloudKitShareWithPreparationHandler:))]
548 #[unsafe(method_family = none)]
549 unsafe fn registerCloudKitShareWithPreparationHandler(
550 &self,
551 preparation_handler: &block2::DynBlock<
552 dyn Fn(
553 NonNull<block2::DynBlock<dyn Fn(*mut CKShare, *mut CKContainer, *mut NSError)>>,
554 ),
555 >,
556 );
557
558 #[cfg(feature = "objc2-cloud-kit")]
559 #[cfg(target_vendor = "apple")]
560 /// Use this method when you have a CKShare that is already saved to the server. Invoking the service with a CKShare registerd with this method will allow the owner to make modifications to the share settings, or will allow a participant to view the share settings.
561 #[unsafe(method(registerCloudKitShare:container:))]
562 #[unsafe(method_family = none)]
563 fn registerCloudKitShare_container(&self, share: &CKShare, container: &CKContainer);
564 );
565}
566
567impl private_NSItemProviderNSCloudKitSharing::Sealed for NSItemProvider {}
568unsafe impl NSItemProviderNSCloudKitSharing for NSItemProvider {}
569
570extern_class!(
571 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicepicker?language=objc)
572 #[unsafe(super(NSObject))]
573 #[derive(Debug, PartialEq, Eq, Hash)]
574 pub struct NSSharingServicePicker;
575);
576
577extern_conformance!(
578 unsafe impl NSObjectProtocol for NSSharingServicePicker {}
579);
580
581impl NSSharingServicePicker {
582 extern_methods!(
583 #[unsafe(method(delegate))]
584 #[unsafe(method_family = none)]
585 pub fn delegate(
586 &self,
587 ) -> Option<Retained<ProtocolObject<dyn NSSharingServicePickerDelegate>>>;
588
589 /// Setter for [`delegate`][Self::delegate].
590 ///
591 /// This is a [weak property][objc2::topics::weak_property].
592 #[unsafe(method(setDelegate:))]
593 #[unsafe(method_family = none)]
594 pub fn setDelegate(
595 &self,
596 delegate: Option<&ProtocolObject<dyn NSSharingServicePickerDelegate>>,
597 );
598
599 /// Returns a new picker. The items represent the objects to be shared and must conform to the
600 /// <NSPasteboardWriting
601 /// > protocol or be an NSItemProvider or an NSDocument. (e.g. NSString, NSImage, NSURL, etc.)
602 ///
603 /// # Safety
604 ///
605 /// `items` generic should be of the correct type.
606 #[unsafe(method(initWithItems:))]
607 #[unsafe(method_family = init)]
608 pub unsafe fn initWithItems(this: Allocated<Self>, items: &NSArray) -> Retained<Self>;
609
610 /// Use initWithItems: instead.
611 #[unsafe(method(init))]
612 #[unsafe(method_family = init)]
613 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
614
615 #[cfg(all(feature = "NSResponder", feature = "NSView"))]
616 /// Shows the picker, populated with sharing services related to the instance items. When the user selects one of the sharing services, the sharing service will be performed. Note that this method must be called on mouseDown.
617 #[unsafe(method(showRelativeToRect:ofView:preferredEdge:))]
618 #[unsafe(method_family = none)]
619 pub fn showRelativeToRect_ofView_preferredEdge(
620 &self,
621 rect: NSRect,
622 view: &NSView,
623 preferred_edge: NSRectEdge,
624 );
625
626 /// Closes the picker UI. `-[NSSharingServicePickerDelegate sharingServicePicker:didChooseSharingService:]` will be invoked if `delegate` is set, with a `nil` service.
627 #[unsafe(method(close))]
628 #[unsafe(method_family = none)]
629 pub fn close(&self);
630
631 #[cfg(feature = "NSMenuItem")]
632 /// Returns a menu item suitable to display the picker for the given items.
633 #[unsafe(method(standardShareMenuItem))]
634 #[unsafe(method_family = none)]
635 pub fn standardShareMenuItem(&self, mtm: MainThreadMarker) -> Retained<NSMenuItem>;
636 );
637}
638
639/// Methods declared on superclass `NSObject`.
640impl NSSharingServicePicker {
641 extern_methods!(
642 #[unsafe(method(new))]
643 #[unsafe(method_family = new)]
644 pub unsafe fn new() -> Retained<Self>;
645 );
646}
647
648extern_protocol!(
649 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssharingservicepickerdelegate?language=objc)
650 pub unsafe trait NSSharingServicePickerDelegate: NSObjectProtocol {
651 /// Allows the delegate to customize exactly what appears in the sharing service picker by reordering or removing the services before the picker is presented. It's possible to add custom services by mutating the proposedSharingServices array and adding new NSSharingService instances:
652 ///
653 /// ```objc
654 /// NSMutableArray *sharingServices = [proposedServices mutableCopy];
655 /// NSSharingService * customService = [[NSSharingService alloc] initWithTitle:
656 /// "
657 /// Service Title"
658 /// image:image alternateImage:alternateImage
659 /// handler:^{ [self doCustomServiceWithItems:items]; } ];
660 /// [sharingServices addObject:customService];
661 /// return [sharingServices autorelease];
662 /// ```
663 /// The items represent the objects to be shared and must conform to the
664 /// <NSPasteboardWriting
665 /// > protocol or be an NSItemProvider or an NSDocument. (e.g. NSString, NSImage, NSURL, etc.)
666 ///
667 /// # Safety
668 ///
669 /// `items` generic should be of the correct type.
670 #[optional]
671 #[unsafe(method(sharingServicePicker:sharingServicesForItems:proposedSharingServices:))]
672 #[unsafe(method_family = none)]
673 unsafe fn sharingServicePicker_sharingServicesForItems_proposedSharingServices(
674 &self,
675 sharing_service_picker: &NSSharingServicePicker,
676 items: &NSArray,
677 proposed_services: &NSArray<NSSharingService>,
678 ) -> Retained<NSArray<NSSharingService>>;
679
680 /// Sent when the user has selected a service and the picker is about to execute it.
681 #[optional]
682 #[unsafe(method(sharingServicePicker:delegateForSharingService:))]
683 #[unsafe(method_family = none)]
684 fn sharingServicePicker_delegateForSharingService(
685 &self,
686 sharing_service_picker: &NSSharingServicePicker,
687 sharing_service: &NSSharingService,
688 mtm: MainThreadMarker,
689 ) -> Option<Retained<ProtocolObject<dyn NSSharingServiceDelegate>>>;
690
691 /// Sent when the user has selected a service and before it is executed. Service will be nil if the picker was dismissed.
692 #[optional]
693 #[unsafe(method(sharingServicePicker:didChooseSharingService:))]
694 #[unsafe(method_family = none)]
695 fn sharingServicePicker_didChooseSharingService(
696 &self,
697 sharing_service_picker: &NSSharingServicePicker,
698 service: Option<&NSSharingService>,
699 );
700
701 #[cfg(feature = "NSSharingCollaborationModeRestriction")]
702 /// Used to specify the case where the share picker should not support some modes of sharing even if they are supported by the items being shared.
703 /// Disabling all possible modes at the same time is not supported behavior.
704 #[optional]
705 #[unsafe(method(sharingServicePickerCollaborationModeRestrictions:))]
706 #[unsafe(method_family = none)]
707 fn sharingServicePickerCollaborationModeRestrictions(
708 &self,
709 sharing_service_picker: &NSSharingServicePicker,
710 ) -> Option<Retained<NSArray<NSSharingCollaborationModeRestriction>>>;
711 }
712);