objc2_app_kit/generated/
NSPopover.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/nspopoverappearance?language=objc)
11// NS_ENUM
12#[deprecated]
13#[repr(transparent)]
14#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
15pub struct NSPopoverAppearance(pub NSInteger);
16impl NSPopoverAppearance {
17    /// The popover will use the default, light content appearance.
18    #[doc(alias = "NSPopoverAppearanceMinimal")]
19    #[deprecated]
20    pub const Minimal: Self = Self(0);
21    /// The popover will draw with a HUD appearance.
22    #[doc(alias = "NSPopoverAppearanceHUD")]
23    #[deprecated]
24    pub const HUD: Self = Self(1);
25}
26
27unsafe impl Encode for NSPopoverAppearance {
28    const ENCODING: Encoding = NSInteger::ENCODING;
29}
30
31unsafe impl RefEncode for NSPopoverAppearance {
32    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
33}
34
35/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverbehavior?language=objc)
36// NS_ENUM
37#[repr(transparent)]
38#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
39pub struct NSPopoverBehavior(pub NSInteger);
40impl NSPopoverBehavior {
41    #[doc(alias = "NSPopoverBehaviorApplicationDefined")]
42    pub const ApplicationDefined: Self = Self(0);
43    #[doc(alias = "NSPopoverBehaviorTransient")]
44    pub const Transient: Self = Self(1);
45    #[doc(alias = "NSPopoverBehaviorSemitransient")]
46    pub const Semitransient: Self = Self(2);
47}
48
49unsafe impl Encode for NSPopoverBehavior {
50    const ENCODING: Encoding = NSInteger::ENCODING;
51}
52
53unsafe impl RefEncode for NSPopoverBehavior {
54    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
55}
56
57extern_class!(
58    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopover?language=objc)
59    #[unsafe(super(NSResponder, NSObject))]
60    #[derive(Debug, PartialEq, Eq, Hash)]
61    #[cfg(feature = "NSResponder")]
62    pub struct NSPopover;
63);
64
65#[cfg(all(feature = "NSAccessibilityProtocols", feature = "NSResponder"))]
66extern_conformance!(
67    unsafe impl NSAccessibility for NSPopover {}
68);
69
70#[cfg(all(feature = "NSAccessibilityProtocols", feature = "NSResponder"))]
71extern_conformance!(
72    unsafe impl NSAccessibilityElementProtocol for NSPopover {}
73);
74
75#[cfg(all(feature = "NSAppearance", feature = "NSResponder"))]
76extern_conformance!(
77    unsafe impl NSAppearanceCustomization for NSPopover {}
78);
79
80#[cfg(feature = "NSResponder")]
81extern_conformance!(
82    unsafe impl NSCoding for NSPopover {}
83);
84
85#[cfg(feature = "NSResponder")]
86extern_conformance!(
87    unsafe impl NSObjectProtocol for NSPopover {}
88);
89
90#[cfg(feature = "NSResponder")]
91impl NSPopover {
92    extern_methods!(
93        #[unsafe(method(init))]
94        #[unsafe(method_family = init)]
95        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
96
97        #[unsafe(method(initWithCoder:))]
98        #[unsafe(method_family = init)]
99        pub unsafe fn initWithCoder(
100            this: Allocated<Self>,
101            coder: &NSCoder,
102        ) -> Option<Retained<Self>>;
103
104        #[unsafe(method(delegate))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSPopoverDelegate>>>;
107
108        /// This is a [weak property][objc2::topics::weak_property].
109        /// Setter for [`delegate`][Self::delegate].
110        #[unsafe(method(setDelegate:))]
111        #[unsafe(method_family = none)]
112        pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSPopoverDelegate>>);
113
114        #[cfg(feature = "NSAppearance")]
115        /// The appearance of the popover. The popover's contentView will inherit this appearance. The default effective appearance is the NSAppearanceNameVibrantLight appearance.
116        /// If nil is set, nil will be returned, and the effective appearance will return to the default.
117        /// To prevent conflicts with the previous appearance property, this is only available for apps that target 10.10 and higher.
118        #[unsafe(method(appearance))]
119        #[unsafe(method_family = none)]
120        pub unsafe fn appearance(&self) -> Option<Retained<NSAppearance>>;
121
122        #[cfg(feature = "NSAppearance")]
123        /// Setter for [`appearance`][Self::appearance].
124        #[unsafe(method(setAppearance:))]
125        #[unsafe(method_family = none)]
126        pub unsafe fn setAppearance(&self, appearance: Option<&NSAppearance>);
127
128        #[cfg(feature = "NSAppearance")]
129        #[unsafe(method(effectiveAppearance))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn effectiveAppearance(&self) -> Retained<NSAppearance>;
132
133        #[unsafe(method(behavior))]
134        #[unsafe(method_family = none)]
135        pub unsafe fn behavior(&self) -> NSPopoverBehavior;
136
137        /// Setter for [`behavior`][Self::behavior].
138        #[unsafe(method(setBehavior:))]
139        #[unsafe(method_family = none)]
140        pub unsafe fn setBehavior(&self, behavior: NSPopoverBehavior);
141
142        #[unsafe(method(animates))]
143        #[unsafe(method_family = none)]
144        pub unsafe fn animates(&self) -> bool;
145
146        /// Setter for [`animates`][Self::animates].
147        #[unsafe(method(setAnimates:))]
148        #[unsafe(method_family = none)]
149        pub unsafe fn setAnimates(&self, animates: bool);
150
151        #[cfg(feature = "NSViewController")]
152        #[unsafe(method(contentViewController))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn contentViewController(&self) -> Option<Retained<NSViewController>>;
155
156        #[cfg(feature = "NSViewController")]
157        /// Setter for [`contentViewController`][Self::contentViewController].
158        #[unsafe(method(setContentViewController:))]
159        #[unsafe(method_family = none)]
160        pub unsafe fn setContentViewController(
161            &self,
162            content_view_controller: Option<&NSViewController>,
163        );
164
165        #[unsafe(method(contentSize))]
166        #[unsafe(method_family = none)]
167        pub unsafe fn contentSize(&self) -> NSSize;
168
169        /// Setter for [`contentSize`][Self::contentSize].
170        #[unsafe(method(setContentSize:))]
171        #[unsafe(method_family = none)]
172        pub unsafe fn setContentSize(&self, content_size: NSSize);
173
174        #[unsafe(method(isShown))]
175        #[unsafe(method_family = none)]
176        pub unsafe fn isShown(&self) -> bool;
177
178        /// Returns
179        /// `YES`if the window is detached to an implicitly created detached window,
180        /// `NO`otherwise. This method does not apply when the popover is detached to a window returned with
181        /// `-detachableWindowForPopover:.`
182        #[unsafe(method(isDetached))]
183        #[unsafe(method_family = none)]
184        pub unsafe fn isDetached(&self) -> bool;
185
186        #[unsafe(method(positioningRect))]
187        #[unsafe(method_family = none)]
188        pub unsafe fn positioningRect(&self) -> NSRect;
189
190        /// Setter for [`positioningRect`][Self::positioningRect].
191        #[unsafe(method(setPositioningRect:))]
192        #[unsafe(method_family = none)]
193        pub unsafe fn setPositioningRect(&self, positioning_rect: NSRect);
194
195        #[unsafe(method(hasFullSizeContent))]
196        #[unsafe(method_family = none)]
197        pub unsafe fn hasFullSizeContent(&self) -> bool;
198
199        /// Setter for [`hasFullSizeContent`][Self::hasFullSizeContent].
200        #[unsafe(method(setHasFullSizeContent:))]
201        #[unsafe(method_family = none)]
202        pub unsafe fn setHasFullSizeContent(&self, has_full_size_content: bool);
203
204        #[cfg(feature = "NSView")]
205        /// Shows the popover anchored to the specified view.
206        ///
207        /// The popover will animate onscreen and eventually animate offscreen when it is closed (unless the property `animates` is set to `NO`).
208        ///
209        /// - Parameters:
210        /// - positioningRect: The rectangle within `positioningView` relative to which the popover should be positioned. Normally set to the bounds of `positioningView`. May be an empty rectangle, which will default to the bounds of `positioningView`.
211        /// - positioningView: The view relative to which the popover should be positioned. Causes the method to raise `NSInvalidArgumentException` if `nil`.
212        /// - preferredEdge: The edge of `positioningView` the popover should prefer to be anchored to (respects to the `-isFlipped` state of `positioningView`). The current (but not guaranteed) behavior is that AppKit will place the anchor towards the `preferredEdge` of the `positioningRect` unless such a placement would cause the popover not to fit on the screen of `positioningView`. If the anchor cannot be placed towards the `preferredEdge`, AppKit will (in the current implementation) attempt to place the anchor on the opposite side of the `positioningRect`. If that cannot be done, AppKit will attempt to place the anchor on a remaining side of the popover, and failing that will center the popover on the screen, causing it to (at least temporarily) lose its anchor.
213        ///
214        /// - Note: This method will throw a `NSInvalidArgumentException` if view is `nil` or if `view` is not in a window, or if the popover’s behavior is `NSPopoverBehaviorSemitransient` and the popover’s `positioningView` is in a popover or child window. It will throw a `NSInternalInconsistencyException` if the popover’s  content view controller (or the view controller’s view) is `nil`. If the popover is already being shown, this method will update to be associated with the new `view` and `positioningRect` passed.
215        ///
216        /// - Note: If the positioning view isn’t visible (its window isn’t visible, or the positioning rect is outside of its visible rect), this method does nothing.
217        #[unsafe(method(showRelativeToRect:ofView:preferredEdge:))]
218        #[unsafe(method_family = none)]
219        pub unsafe fn showRelativeToRect_ofView_preferredEdge(
220            &self,
221            positioning_rect: NSRect,
222            positioning_view: &NSView,
223            preferred_edge: NSRectEdge,
224        );
225
226        #[cfg(feature = "NSToolbarItem")]
227        /// Shows the popover positioned relative to
228        /// `toolbarItem`. When the item is in the overflow menu, the popover will be presented from another appropriate affordance in the window. See the comments in
229        /// `-showRelativeToRect:ofView:preferredEdge:`for the popover behavior.
230        ///
231        /// This method will throw an
232        /// `NSInvalidArgumentException`if it cannot locate the toolbar item. This could happen because the item is not in a toolbar, or because the toolbar is not in a window.
233        #[unsafe(method(showRelativeToToolbarItem:))]
234        #[unsafe(method_family = none)]
235        pub unsafe fn showRelativeToToolbarItem(&self, toolbar_item: &NSToolbarItem);
236
237        #[unsafe(method(performClose:))]
238        #[unsafe(method_family = none)]
239        pub unsafe fn performClose(&self, sender: Option<&AnyObject>);
240
241        #[unsafe(method(close))]
242        #[unsafe(method_family = none)]
243        pub unsafe fn close(&self);
244    );
245}
246
247/// Methods declared on superclass `NSObject`.
248#[cfg(feature = "NSResponder")]
249impl NSPopover {
250    extern_methods!(
251        #[unsafe(method(new))]
252        #[unsafe(method_family = new)]
253        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
254    );
255}
256
257extern "C" {
258    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverclosereasonkey?language=objc)
259    pub static NSPopoverCloseReasonKey: &'static NSString;
260}
261
262/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverclosereasonvalue?language=objc)
263// NS_TYPED_ENUM
264pub type NSPopoverCloseReasonValue = NSString;
265
266extern "C" {
267    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverclosereasonstandard?language=objc)
268    pub static NSPopoverCloseReasonStandard: &'static NSPopoverCloseReasonValue;
269}
270
271extern "C" {
272    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverclosereasondetachtowindow?language=objc)
273    pub static NSPopoverCloseReasonDetachToWindow: &'static NSPopoverCloseReasonValue;
274}
275
276extern "C" {
277    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverwillshownotification?language=objc)
278    pub static NSPopoverWillShowNotification: &'static NSNotificationName;
279}
280
281extern "C" {
282    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverdidshownotification?language=objc)
283    pub static NSPopoverDidShowNotification: &'static NSNotificationName;
284}
285
286extern "C" {
287    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverwillclosenotification?language=objc)
288    pub static NSPopoverWillCloseNotification: &'static NSNotificationName;
289}
290
291extern "C" {
292    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverdidclosenotification?language=objc)
293    pub static NSPopoverDidCloseNotification: &'static NSNotificationName;
294}
295
296extern_protocol!(
297    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverdelegate?language=objc)
298    pub unsafe trait NSPopoverDelegate: NSObjectProtocol + MainThreadOnly {
299        #[cfg(feature = "NSResponder")]
300        /// The popover invokes this method on its delegate whenever it is about to close to give the delegate a chance to veto the close.
301        /// If the delegate does not implement this method,
302        /// `-popoverShouldClose:`will also be invoked on the popover to allow the popover to veto the close.
303        ///
304        /// Returns: Return YES if the popover should close, NO otherwise.
305        #[optional]
306        #[unsafe(method(popoverShouldClose:))]
307        #[unsafe(method_family = none)]
308        unsafe fn popoverShouldClose(&self, popover: &NSPopover) -> bool;
309
310        #[cfg(feature = "NSResponder")]
311        /// Return
312        /// `YES`to allow the popover to detach from its positioning view. Return
313        /// `NO`if it should not. If this method is not implemented, the default behavior is
314        /// `NO.`If this method returns YES, and
315        /// `-detachableWindowForPopover:`is not implemented or returns nil, a detachable window will be created with the popover’s
316        /// `contentViewController.`This implicit detached window will have the same appearance as the popover. If the
317        /// `contentViewController`has a title, it will be bound to and displayed as the title of the detached window. Upon being released in a detached state, the popover will call
318        /// `-popoverDidDetach:`on the delegate. Once the detached popover is closed, PopoverShould/Will/DidClose delegate calls and notifications will be sent with the reason
319        /// `NSPopoverCloseReasonStandard.`
320        /// Parameter `popover`: The popover that may be detached
321        ///
322        /// Returns: YES if the popover should detach, whether to a custom window or the implicitly detached window. NO if not.
323        #[optional]
324        #[unsafe(method(popoverShouldDetach:))]
325        #[unsafe(method_family = none)]
326        unsafe fn popoverShouldDetach(&self, popover: &NSPopover) -> bool;
327
328        #[cfg(feature = "NSResponder")]
329        /// This is called when the popover has been released in an implicitly detached state, i.e. not when detached to a custom window returned from
330        /// `-detachableWindowForPopover:.`
331        /// Parameter `popover`: The popover that detached from its anchor view and is not closing.
332        #[optional]
333        #[unsafe(method(popoverDidDetach:))]
334        #[unsafe(method_family = none)]
335        unsafe fn popoverDidDetach(&self, popover: &NSPopover);
336
337        #[cfg(all(feature = "NSResponder", feature = "NSWindow"))]
338        /// Return a custom window to which the popover should be detached. This should be used when the content of the detached window is wanted to be different from the content of the popover. If the same content should be used in the detached window, only
339        /// `-popoverShouldDetach:`needs to be implemented.
340        /// If implementing this method, you should not remove the popover's content view as part of your implementation of this method. The popover and the detachable window may be shown at the same time and therefore cannot share a content view (or a content view controller).  If the popover and the detachable window should have the same content, you should define the content in a separate nib file and use a view controller to instantiate separate copies of the content for the popover and the detachable window.  The popover will animate to appear as though it morphs into the detachable window (unless the animates property is set to NO.  The exact animation used is not guaranteed).  Subclasses of NSPopover may also implement this method, in which case the subclass method will be invoked only if the delegate does not implement the method.
341        /// Not implementing this method, and just returning YES to
342        /// `-popoverShouldDetach:`is recommended over providing a custom window.
343        /// If
344        /// `-popoverShouldDetach:`is not overridden or returns NO, this method will not be called and the popover will not be detachable.
345        ///
346        /// Parameter `popover`: The popover that is being detached
347        ///
348        /// Returns: The custom window to detach to.
349        #[optional]
350        #[unsafe(method(detachableWindowForPopover:))]
351        #[unsafe(method_family = none)]
352        unsafe fn detachableWindowForPopover(
353            &self,
354            popover: &NSPopover,
355        ) -> Option<Retained<NSWindow>>;
356
357        /// Invoked on the delegate when the NSPopoverWillShowNotification notification is sent.  This method will also be invoked on the popover.
358        #[optional]
359        #[unsafe(method(popoverWillShow:))]
360        #[unsafe(method_family = none)]
361        unsafe fn popoverWillShow(&self, notification: &NSNotification);
362
363        /// Invoked on the delegate when the NSPopoverDidShowNotification notification is sent.  This method will also be invoked on the popover.
364        #[optional]
365        #[unsafe(method(popoverDidShow:))]
366        #[unsafe(method_family = none)]
367        unsafe fn popoverDidShow(&self, notification: &NSNotification);
368
369        /// Invoked on the delegate when the NSPopoverWillCloseNotification notification is sent.  This method will also be invoked on the popover.
370        #[optional]
371        #[unsafe(method(popoverWillClose:))]
372        #[unsafe(method_family = none)]
373        unsafe fn popoverWillClose(&self, notification: &NSNotification);
374
375        /// Invoked on the delegate when the NSPopoverDidCloseNotification notification is sent.  This method will also be invoked on the popover.
376        #[optional]
377        #[unsafe(method(popoverDidClose:))]
378        #[unsafe(method_family = none)]
379        unsafe fn popoverDidClose(&self, notification: &NSNotification);
380    }
381);