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 #[deprecated]
19 #[doc(alias = "NSPopoverAppearanceMinimal")]
20 pub const Minimal: Self = Self(0);
21 /// The popover will draw with a HUD appearance.
22 #[deprecated]
23 #[doc(alias = "NSPopoverAppearanceHUD")]
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"))]
66unsafe impl NSAccessibility for NSPopover {}
67
68#[cfg(all(feature = "NSAccessibilityProtocols", feature = "NSResponder"))]
69unsafe impl NSAccessibilityElementProtocol for NSPopover {}
70
71#[cfg(all(feature = "NSAppearance", feature = "NSResponder"))]
72unsafe impl NSAppearanceCustomization for NSPopover {}
73
74#[cfg(feature = "NSResponder")]
75unsafe impl NSCoding for NSPopover {}
76
77#[cfg(feature = "NSResponder")]
78unsafe impl NSObjectProtocol for NSPopover {}
79
80#[cfg(feature = "NSResponder")]
81impl NSPopover {
82 extern_methods!(
83 #[unsafe(method(init))]
84 #[unsafe(method_family = init)]
85 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
86
87 #[unsafe(method(initWithCoder:))]
88 #[unsafe(method_family = init)]
89 pub unsafe fn initWithCoder(
90 this: Allocated<Self>,
91 coder: &NSCoder,
92 ) -> Option<Retained<Self>>;
93
94 #[unsafe(method(delegate))]
95 #[unsafe(method_family = none)]
96 pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn NSPopoverDelegate>>>;
97
98 /// This is a [weak property][objc2::topics::weak_property].
99 /// Setter for [`delegate`][Self::delegate].
100 #[unsafe(method(setDelegate:))]
101 #[unsafe(method_family = none)]
102 pub unsafe fn setDelegate(&self, delegate: Option<&ProtocolObject<dyn NSPopoverDelegate>>);
103
104 #[cfg(feature = "NSAppearance")]
105 /// The appearance of the popover. The popover's contentView will inherit this appearance. The default effective appearance is the NSAppearanceNameVibrantLight appearance.
106 /// If nil is set, nil will be returned, and the effective appearance will return to the default.
107 /// To prevent conflicts with the previous appearance property, this is only available for apps that target 10.10 and higher.
108 #[unsafe(method(appearance))]
109 #[unsafe(method_family = none)]
110 pub unsafe fn appearance(&self) -> Option<Retained<NSAppearance>>;
111
112 #[cfg(feature = "NSAppearance")]
113 /// Setter for [`appearance`][Self::appearance].
114 #[unsafe(method(setAppearance:))]
115 #[unsafe(method_family = none)]
116 pub unsafe fn setAppearance(&self, appearance: Option<&NSAppearance>);
117
118 #[cfg(feature = "NSAppearance")]
119 #[unsafe(method(effectiveAppearance))]
120 #[unsafe(method_family = none)]
121 pub unsafe fn effectiveAppearance(&self) -> Retained<NSAppearance>;
122
123 #[unsafe(method(behavior))]
124 #[unsafe(method_family = none)]
125 pub unsafe fn behavior(&self) -> NSPopoverBehavior;
126
127 /// Setter for [`behavior`][Self::behavior].
128 #[unsafe(method(setBehavior:))]
129 #[unsafe(method_family = none)]
130 pub unsafe fn setBehavior(&self, behavior: NSPopoverBehavior);
131
132 #[unsafe(method(animates))]
133 #[unsafe(method_family = none)]
134 pub unsafe fn animates(&self) -> bool;
135
136 /// Setter for [`animates`][Self::animates].
137 #[unsafe(method(setAnimates:))]
138 #[unsafe(method_family = none)]
139 pub unsafe fn setAnimates(&self, animates: bool);
140
141 #[cfg(feature = "NSViewController")]
142 #[unsafe(method(contentViewController))]
143 #[unsafe(method_family = none)]
144 pub unsafe fn contentViewController(&self) -> Option<Retained<NSViewController>>;
145
146 #[cfg(feature = "NSViewController")]
147 /// Setter for [`contentViewController`][Self::contentViewController].
148 #[unsafe(method(setContentViewController:))]
149 #[unsafe(method_family = none)]
150 pub unsafe fn setContentViewController(
151 &self,
152 content_view_controller: Option<&NSViewController>,
153 );
154
155 #[unsafe(method(contentSize))]
156 #[unsafe(method_family = none)]
157 pub unsafe fn contentSize(&self) -> NSSize;
158
159 /// Setter for [`contentSize`][Self::contentSize].
160 #[unsafe(method(setContentSize:))]
161 #[unsafe(method_family = none)]
162 pub unsafe fn setContentSize(&self, content_size: NSSize);
163
164 #[unsafe(method(isShown))]
165 #[unsafe(method_family = none)]
166 pub unsafe fn isShown(&self) -> bool;
167
168 /// Returns
169 /// `YES`if the window is detached to an implicitly created detached window,
170 /// `NO`otherwise. This method does not apply when the popover is detached to a window returned with
171 /// `-detachableWindowForPopover:.`
172 #[unsafe(method(isDetached))]
173 #[unsafe(method_family = none)]
174 pub unsafe fn isDetached(&self) -> bool;
175
176 #[unsafe(method(positioningRect))]
177 #[unsafe(method_family = none)]
178 pub unsafe fn positioningRect(&self) -> NSRect;
179
180 /// Setter for [`positioningRect`][Self::positioningRect].
181 #[unsafe(method(setPositioningRect:))]
182 #[unsafe(method_family = none)]
183 pub unsafe fn setPositioningRect(&self, positioning_rect: NSRect);
184
185 #[unsafe(method(hasFullSizeContent))]
186 #[unsafe(method_family = none)]
187 pub unsafe fn hasFullSizeContent(&self) -> bool;
188
189 /// Setter for [`hasFullSizeContent`][Self::hasFullSizeContent].
190 #[unsafe(method(setHasFullSizeContent:))]
191 #[unsafe(method_family = none)]
192 pub unsafe fn setHasFullSizeContent(&self, has_full_size_content: bool);
193
194 #[cfg(feature = "NSView")]
195 /// Shows the popover anchored to the specified view.
196 ///
197 /// The popover will animate onscreen and eventually animate offscreen when it is closed (unless the property `animates` is set to `NO`).
198 ///
199 /// - Parameters:
200 /// - 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`.
201 /// - positioningView: The view relative to which the popover should be positioned. Causes the method to raise `NSInvalidArgumentException` if `nil`.
202 /// - 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.
203 ///
204 /// - 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.
205 ///
206 /// - 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.
207 #[unsafe(method(showRelativeToRect:ofView:preferredEdge:))]
208 #[unsafe(method_family = none)]
209 pub unsafe fn showRelativeToRect_ofView_preferredEdge(
210 &self,
211 positioning_rect: NSRect,
212 positioning_view: &NSView,
213 preferred_edge: NSRectEdge,
214 );
215
216 #[cfg(feature = "NSToolbarItem")]
217 /// Shows the popover positioned relative to
218 /// `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
219 /// `-showRelativeToRect:ofView:preferredEdge:`for the popover behavior.
220 ///
221 /// This method will throw an
222 /// `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.
223 #[unsafe(method(showRelativeToToolbarItem:))]
224 #[unsafe(method_family = none)]
225 pub unsafe fn showRelativeToToolbarItem(&self, toolbar_item: &NSToolbarItem);
226
227 #[unsafe(method(performClose:))]
228 #[unsafe(method_family = none)]
229 pub unsafe fn performClose(&self, sender: Option<&AnyObject>);
230
231 #[unsafe(method(close))]
232 #[unsafe(method_family = none)]
233 pub unsafe fn close(&self);
234 );
235}
236
237/// Methods declared on superclass `NSObject`.
238#[cfg(feature = "NSResponder")]
239impl NSPopover {
240 extern_methods!(
241 #[unsafe(method(new))]
242 #[unsafe(method_family = new)]
243 pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
244 );
245}
246
247extern "C" {
248 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverclosereasonkey?language=objc)
249 pub static NSPopoverCloseReasonKey: &'static NSString;
250}
251
252/// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverclosereasonvalue?language=objc)
253// NS_TYPED_ENUM
254pub type NSPopoverCloseReasonValue = NSString;
255
256extern "C" {
257 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverclosereasonstandard?language=objc)
258 pub static NSPopoverCloseReasonStandard: &'static NSPopoverCloseReasonValue;
259}
260
261extern "C" {
262 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverclosereasondetachtowindow?language=objc)
263 pub static NSPopoverCloseReasonDetachToWindow: &'static NSPopoverCloseReasonValue;
264}
265
266extern "C" {
267 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverwillshownotification?language=objc)
268 pub static NSPopoverWillShowNotification: &'static NSNotificationName;
269}
270
271extern "C" {
272 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverdidshownotification?language=objc)
273 pub static NSPopoverDidShowNotification: &'static NSNotificationName;
274}
275
276extern "C" {
277 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverwillclosenotification?language=objc)
278 pub static NSPopoverWillCloseNotification: &'static NSNotificationName;
279}
280
281extern "C" {
282 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverdidclosenotification?language=objc)
283 pub static NSPopoverDidCloseNotification: &'static NSNotificationName;
284}
285
286extern_protocol!(
287 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nspopoverdelegate?language=objc)
288 pub unsafe trait NSPopoverDelegate: NSObjectProtocol + MainThreadOnly {
289 #[cfg(feature = "NSResponder")]
290 /// The popover invokes this method on its delegate whenever it is about to close to give the delegate a chance to veto the close.
291 /// If the delegate does not implement this method,
292 /// `-popoverShouldClose:`will also be invoked on the popover to allow the popover to veto the close.
293 ///
294 /// Returns: Return YES if the popover should close, NO otherwise.
295 #[optional]
296 #[unsafe(method(popoverShouldClose:))]
297 #[unsafe(method_family = none)]
298 unsafe fn popoverShouldClose(&self, popover: &NSPopover) -> bool;
299
300 #[cfg(feature = "NSResponder")]
301 /// Return
302 /// `YES`to allow the popover to detach from its positioning view. Return
303 /// `NO`if it should not. If this method is not implemented, the default behavior is
304 /// `NO.`If this method returns YES, and
305 /// `-detachableWindowForPopover:`is not implemented or returns nil, a detachable window will be created with the popover’s
306 /// `contentViewController.`This implicit detached window will have the same appearance as the popover. If the
307 /// `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
308 /// `-popoverDidDetach:`on the delegate. Once the detached popover is closed, PopoverShould/Will/DidClose delegate calls and notifications will be sent with the reason
309 /// `NSPopoverCloseReasonStandard.`
310 /// Parameter `popover`: The popover that may be detached
311 ///
312 /// Returns: YES if the popover should detach, whether to a custom window or the implicitly detached window. NO if not.
313 #[optional]
314 #[unsafe(method(popoverShouldDetach:))]
315 #[unsafe(method_family = none)]
316 unsafe fn popoverShouldDetach(&self, popover: &NSPopover) -> bool;
317
318 #[cfg(feature = "NSResponder")]
319 /// 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
320 /// `-detachableWindowForPopover:.`
321 /// Parameter `popover`: The popover that detached from its anchor view and is not closing.
322 #[optional]
323 #[unsafe(method(popoverDidDetach:))]
324 #[unsafe(method_family = none)]
325 unsafe fn popoverDidDetach(&self, popover: &NSPopover);
326
327 #[cfg(all(feature = "NSResponder", feature = "NSWindow"))]
328 /// 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
329 /// `-popoverShouldDetach:`needs to be implemented.
330 /// 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.
331 /// Not implementing this method, and just returning YES to
332 /// `-popoverShouldDetach:`is recommended over providing a custom window.
333 /// If
334 /// `-popoverShouldDetach:`is not overridden or returns NO, this method will not be called and the popover will not be detachable.
335 ///
336 /// Parameter `popover`: The popover that is being detached
337 ///
338 /// Returns: The custom window to detach to.
339 #[optional]
340 #[unsafe(method(detachableWindowForPopover:))]
341 #[unsafe(method_family = none)]
342 unsafe fn detachableWindowForPopover(
343 &self,
344 popover: &NSPopover,
345 ) -> Option<Retained<NSWindow>>;
346
347 /// Invoked on the delegate when the NSPopoverWillShowNotification notification is sent. This method will also be invoked on the popover.
348 #[optional]
349 #[unsafe(method(popoverWillShow:))]
350 #[unsafe(method_family = none)]
351 unsafe fn popoverWillShow(&self, notification: &NSNotification);
352
353 /// Invoked on the delegate when the NSPopoverDidShowNotification notification is sent. This method will also be invoked on the popover.
354 #[optional]
355 #[unsafe(method(popoverDidShow:))]
356 #[unsafe(method_family = none)]
357 unsafe fn popoverDidShow(&self, notification: &NSNotification);
358
359 /// Invoked on the delegate when the NSPopoverWillCloseNotification notification is sent. This method will also be invoked on the popover.
360 #[optional]
361 #[unsafe(method(popoverWillClose:))]
362 #[unsafe(method_family = none)]
363 unsafe fn popoverWillClose(&self, notification: &NSNotification);
364
365 /// Invoked on the delegate when the NSPopoverDidCloseNotification notification is sent. This method will also be invoked on the popover.
366 #[optional]
367 #[unsafe(method(popoverDidClose:))]
368 #[unsafe(method_family = none)]
369 unsafe fn popoverDidClose(&self, notification: &NSNotification);
370 }
371);