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