rust_macios/appkit/
ns_window.rs

1use block::{ConcreteBlock, IntoConcreteBlock, RcBlock};
2use objc::{
3    class, msg_send,
4    runtime::{Class, Object},
5    sel, sel_impl,
6};
7use objc_id::ShareId;
8
9use crate::{
10    core_graphics::{CGFloat, CGPoint, CGSize},
11    foundation::{
12        Int, NSAlignmentOptions, NSArray, NSData, NSDictionary, NSNumber, NSPoint, NSRect,
13        NSRectEdge, NSSize, NSString, NSTimeInterval, UInt,
14    },
15    objective_c_runtime::{
16        id, nil,
17        traits::{FromId, PNSObject, ToId},
18    },
19    utils::to_bool,
20};
21
22use super::{
23    ns_window_delegate::{register_window_class_with_delegate, PNSWindowDelegate},
24    INSResponder, INSViewController, NSBackingStoreType, NSButton, NSColor, NSColorSpace,
25    NSDeviceDescriptionKey, NSDockTile, NSImage, NSModalResponse, NSScreen,
26    NSTitlebarSeparatorStyle, NSToolbar, NSUserInterfaceLayoutDirection, NSViewController,
27    NSWindowButton, NSWindowCollectionBehavior, NSWindowDepth, NSWindowFrameAutosaveName,
28    NSWindowLevel, NSWindowNumberListOptions, NSWindowOcclusionState, NSWindowOrderingMode,
29    NSWindowPersistableFrameDescriptor, NSWindowSharingType, NSWindowStyleMask,
30    NSWindowTitleVisibility, NSWindowToolbarStyle,
31};
32
33pub(crate) static NSWINDOW_DELEGATE_PTR: &str = "RUST_NSWindowDelegate";
34
35/// A config for a window.
36#[derive(Debug)]
37pub struct WindowConfig {
38    /// The style the window should have.
39    pub style: UInt,
40
41    /// The initial dimensions for the window.
42    pub initial_dimensions: NSRect,
43
44    /// When true, the window server defers creating the window device
45    /// until the window is moved onscreen. All display messages sent to
46    /// the window or its views are postponed until the window is created,
47    /// just before it’s moved onscreen.
48    pub defer: bool,
49
50    /// The style of the toolbar
51    pub toolbar_style: NSWindowToolbarStyle,
52}
53
54impl Default for WindowConfig {
55    fn default() -> Self {
56        let mut config = WindowConfig {
57            style: 0,
58            initial_dimensions: NSRect {
59                origin: CGPoint { x: 100., y: 100. },
60                size: CGSize {
61                    width: 1024.,
62                    height: 768.,
63                },
64            },
65            defer: true,
66            toolbar_style: NSWindowToolbarStyle::Automatic,
67        };
68
69        config.set_styles(&[
70            NSWindowStyleMask::Resizable,
71            NSWindowStyleMask::Miniaturizable,
72            NSWindowStyleMask::UnifiedTitleAndToolbar,
73            NSWindowStyleMask::Closable,
74            NSWindowStyleMask::Titled,
75            NSWindowStyleMask::FullSizeContentView,
76        ]);
77
78        config
79    }
80}
81
82impl WindowConfig {
83    /// Given a set of styles, converts them to `NSUInteger` and sets them on the
84    /// window config.
85    pub fn set_styles(&mut self, styles: &[NSWindowStyleMask]) {
86        let mut style: UInt = 0;
87
88        for mask in styles {
89            let i = *mask as UInt;
90            style |= i;
91        }
92
93        self.style = style;
94    }
95
96    /// Set the initial dimensions of this window.
97    pub fn set_initial_dimensions(&mut self, top: f64, left: f64, width: f64, height: f64) {
98        self.initial_dimensions = NSRect {
99            origin: CGPoint { x: left, y: top },
100            size: CGSize { width, height },
101        };
102    }
103
104    /// Sets the toolbar style of this window.
105    pub fn set_toolbar_style(&mut self, style: NSWindowToolbarStyle) {
106        self.toolbar_style = style;
107    }
108}
109
110/// A `Window` represents your way of interacting with an `NSWindow`. It wraps the various moving
111/// pieces to enable you to focus on reacting to lifecycle methods and doing your thing.
112#[derive(Debug)]
113pub struct NSWindow<T = ()> {
114    /// Represents an `NS/UIWindow` in the Objective-C runtime.
115    pub ptr: ShareId<Object>,
116
117    /// A delegate for this window.
118    pub delegate: Option<Box<T>>,
119}
120
121impl Default for NSWindow {
122    fn default() -> Self {
123        NSWindow::new(WindowConfig::default())
124    }
125}
126
127impl NSWindow {
128    /// Constructs a new `NSWindow`
129    pub fn new(config: WindowConfig) -> NSWindow {
130        unsafe {
131            NSWindow::<()>::tm_set_allows_automatic_window_tabbing(false);
132
133            let alloc: id = msg_send![class!(NSWindow), alloc];
134
135            let dimensions: NSRect = config.initial_dimensions;
136
137            let mut window = NSWindow::from_id(alloc);
138
139            window = window.im_init_with_content_rect_style_mask_backing_defer(
140                dimensions,
141                config.style,
142                NSBackingStoreType::Buffered,
143                config.defer,
144            );
145
146            window = window.autorelease();
147
148            window.ip_set_released_when_closed(false);
149            window.ip_set_restorable(false);
150
151            let toolbar_style = config.toolbar_style;
152
153            window.ip_set_toolbar_style(toolbar_style);
154
155            window
156        }
157    }
158
159    /// Allocates a new `Window`
160    fn alloc<T>() -> Self
161    where
162        T: PNSWindowDelegate + 'static,
163    {
164        let objc = unsafe {
165            let class = register_window_class_with_delegate::<T>();
166            let alloc: id = msg_send![class, alloc];
167            ShareId::from_ptr(alloc)
168        };
169
170        NSWindow {
171            ptr: objc,
172            delegate: None,
173        }
174    }
175
176    fn autorelease(&self) -> Self {
177        unsafe { msg_send![&*self.ptr, autorelease] }
178    }
179}
180
181impl<T> NSWindow<T>
182where
183    T: PNSWindowDelegate + 'static,
184{
185    /// Constructs a new NSWindow with a `config`
186    pub fn with(config: WindowConfig, delegate: T) -> Self {
187        let mut window = NSWindow::alloc::<T>();
188        let mut delegate = Box::new(delegate);
189
190        let objc = unsafe {
191            NSWindow::<()>::tm_set_allows_automatic_window_tabbing(false);
192
193            let dimensions: NSRect = config.initial_dimensions;
194
195            window = window.im_init_with_content_rect_style_mask_backing_defer(
196                dimensions,
197                config.style,
198                NSBackingStoreType::Buffered,
199                config.defer,
200            );
201
202            let delegate_ptr: *const T = &*delegate;
203            let ptr: id = msg_send![&*window.ptr, self];
204
205            (*ptr).set_ivar(NSWINDOW_DELEGATE_PTR, delegate_ptr as usize);
206
207            let mut window = NSWindow::from_id(ptr);
208
209            window = window.autorelease();
210
211            window.ip_set_released_when_closed(false);
212
213            window.ip_set_delegate(msg_send![&*window.ptr, self]);
214            window.ip_set_restorable(false);
215
216            window.ip_set_toolbar_style(config.toolbar_style);
217
218            window
219        };
220
221        {
222            delegate.did_load(NSWindow {
223                delegate: None,
224                ptr: objc.ptr.clone(),
225            });
226        }
227
228        NSWindow {
229            ptr: objc.ptr.clone(),
230            delegate: Some(delegate),
231        }
232    }
233}
234
235impl<T> NSWindow<T> {
236    /// Sets the string that appears in the title bar of the window or the path to the represented file.
237    pub fn set_title<S>(&self, title: S)
238    where
239        S: Into<NSString>,
240    {
241        self.ip_set_title(title.into())
242    }
243
244    /// Sets a value that indicates the visibility of the window’s title and title bar buttons.
245    pub fn set_title_visibility(&mut self, visibility: NSWindowTitleVisibility) {
246        self.ip_set_title_visibility(visibility)
247    }
248
249    /// Sets a Boolean value that indicates whether the window is movable by clicking and dragging anywhere in its background.
250    pub fn set_movable_by_background(&mut self, movable: bool) {
251        self.ip_set_movable_by_window_background(movable)
252    }
253
254    /// Sets a Boolean value that indicates whether the title bar draws its background.
255    pub fn set_titlebar_appears_transparent(&mut self, transparent: bool) {
256        self.ip_set_titlebar_appears_transparent(transparent)
257    }
258
259    /// Sets the name AppKit uses to automatically save the window’s frame rectangle data in the defaults system.
260    pub fn set_autosave_name<S>(&self, name: S) -> bool
261    where
262        S: Into<NSString>,
263    {
264        self.im_set_frame_autosave_name(name.into())
265    }
266
267    /// Sets the size of the window’s content view to a given size, which is expressed in the window’s base coordinate system.
268    pub fn set_content_size(&self, size: NSSize) {
269        self.im_set_content_size(size);
270    }
271
272    /// Sets the minimum size of the window’s content view in the window’s base coordinate system.
273    pub fn set_minimum_content_size(&self, size: NSSize) {
274        self.ip_set_content_min_size(size);
275    }
276
277    /// Sets the minimum size to which the window’s frame (including its title bar) can be sized.
278    pub fn set_maximum_content_size(&self, size: NSSize) {
279        self.ip_set_content_max_size(size);
280    }
281
282    /// Sets the minimum size this window can shrink to.
283    pub fn set_minimum_size<F: Into<f64>>(&self, size: NSSize) {
284        self.ip_set_min_size(size)
285    }
286
287    /// Toggles the visibility of the window’s toolbar.
288    pub fn toggle_toolbar_shown(&self) {
289        self.ip_toggle_toolbar_shown(nil)
290    }
291
292    /// Sets a Boolean value that indicates whether the toolbar control button is displayed.
293    pub fn set_shows_toolbar_button(&self, shows: bool) {
294        self.ip_set_shows_toolbar_button(shows);
295    }
296
297    /// Removes the window from the screen.
298    pub fn close(&self) {
299        self.im_close()
300    }
301
302    /// Takes the window into or out of fullscreen mode,
303    pub fn toggle_full_screen(&self, sender: id) {
304        self.im_toggle_full_screen(sender)
305    }
306
307    /// A Boolean value that indicates whether the window is opaque.
308    pub fn is_opaque(&self) -> bool {
309        self.ip_is_opaque()
310    }
311
312    /// A Boolean value that indicates whether the window is minimized.
313    pub fn miniaturized(&self) -> bool {
314        self.ip_miniaturized()
315    }
316
317    /// Removes the window from the screen list and displays the minimized window in the Dock.
318    pub fn miniaturize(&self, sender: id) {
319        self.im_miniaturize(sender)
320    }
321
322    /// De-minimizes the window.
323    pub fn deminiaturize(&self, sender: id) {
324        self.im_deminiaturize(sender)
325    }
326
327    /// Runs the Print panel, and if the user chooses an option other than canceling, prints the window (its frame view and all subviews).
328    pub fn print(&self, sender: id) {
329        self.im_print(sender)
330    }
331
332    /// A Boolean value that indicates whether the window is on the currently active space.
333    pub fn is_on_active_space(&self) -> bool {
334        self.ip_is_on_active_space()
335    }
336
337    /// A Boolean value that indicates whether the window is visible onscreen (even when it’s obscured by other windows).
338    pub fn is_visible(&self) -> bool {
339        self.ip_visible()
340    }
341
342    /// A Boolean value that indicates whether the window is the key window for the application.
343    pub fn is_key_window(&self) -> bool {
344        self.ip_key_window()
345    }
346
347    /// A Boolean value that indicates whether the window can become the key window.
348    pub fn can_become_key_window(&self) -> bool {
349        self.ip_can_become_key_window()
350    }
351
352    /// Makes the window the key window.
353    pub fn make_key_window(&self) {
354        self.im_make_key_window()
355    }
356
357    /// Moves the window to the front of the screen list, within its level, and makes it the key window; that is, it shows the window.
358    pub fn make_key_and_order_front(&self, sender: id) {
359        self.im_make_key_and_order_front(sender)
360    }
361
362    /// A Boolean value that indicates whether the window is the application’s main window.
363    pub fn main_window(&self) -> bool {
364        self.ip_main_window()
365    }
366
367    /// A Boolean value that indicates whether the window can become the application’s main window.
368    pub fn can_become_main_window(&self) -> bool {
369        self.ip_can_become_main_window()
370    }
371
372    /// Set whether this window should be excluded from the top-level "Windows" menu.
373    pub fn set_excluded_from_windows_menu(&self, excluded: bool) {
374        self.ip_set_excluded_from_windows_menu(excluded)
375    }
376
377    /// Sets the type of separator that the app displays between the title bar and content of a window.
378    pub fn set_titlebar_separator_style(&self, style: NSTitlebarSeparatorStyle) {
379        self.ip_set_titlebar_separator_style(style)
380    }
381
382    /// The backing scale factor.
383    pub fn backing_scale_factor(&self) -> f64 {
384        self.ip_backing_scale_factor()
385    }
386
387    /// Starts a document-modal session and presents—or queues for presentation—a sheet.
388    pub fn begin_sheet_completion_handler<F, W>(&self, window: &NSWindow<W>, completion: F)
389    where
390        F: IntoConcreteBlock<(NSModalResponse,), Ret = ()> + 'static,
391        W: PNSWindowDelegate + 'static,
392    {
393        let block = ConcreteBlock::new(completion);
394        let block = block.copy();
395
396        self.im_begin_sheet_completion_handler(window, block)
397    }
398
399    /// Ends a document-modal session and dismisses the specified sheet.
400    pub fn end_sheet<W>(&self, window: &NSWindow<W>)
401    where
402        W: PNSWindowDelegate + 'static,
403    {
404        self.im_end_sheet(window);
405    }
406}
407
408impl<T> PNSObject for NSWindow<T> {
409    fn m_class<'a>() -> &'a Class {
410        class!(NSWindow)
411    }
412
413    fn m_self(&self) -> id {
414        unsafe { msg_send![&*self.ptr, self] }
415    }
416}
417
418impl<T> INSResponder for NSWindow<T> {}
419
420/// A window that an app displays on the screen.
421pub trait INSWindow: INSResponder {
422    /* Creating a Window
423     */
424
425    /// Creates a titled window that contains the specified content view controller.
426    fn tm_window_with_content_view_controller<V>(content_view_controller: V) -> Self
427    where
428        Self: Sized + FromId,
429        V: INSViewController,
430    {
431        unsafe {
432            Self::from_id(msg_send![
433                Self::m_class(),
434                windowWithContentViewController: content_view_controller
435            ])
436        }
437    }
438
439    /// Initializes the window with the specified values.
440    fn im_init_with_content_rect_style_mask_backing_defer(
441        &self,
442        content_rect: NSRect,
443        style: UInt,
444        backing_store_type: NSBackingStoreType,
445        flag: bool,
446    ) -> Self
447    where
448        Self: Sized + FromId,
449    {
450        unsafe {
451            Self::from_id(msg_send![
452                self.m_self(),
453                initWithContentRect: content_rect
454                styleMask: style
455                backing: backing_store_type
456                defer: flag
457            ])
458        }
459    }
460
461    /// Initializes an allocated window with the specified values.
462    fn im_init_with_content_rect_style_mask_backing_defer_screen(
463        &self,
464        content_rect: NSRect,
465        style: UInt,
466        backing_store_type: NSBackingStoreType,
467        flag: bool,
468        screen: NSScreen,
469    ) -> Self
470    where
471        Self: Sized + FromId,
472    {
473        unsafe {
474            Self::from_id(msg_send![
475                self.m_self(),
476                initWithContentRect: content_rect
477                styleMask: style
478                backing: backing_store_type
479                defer: flag
480                screen: screen
481            ])
482        }
483    }
484
485    /* Managing the Window's Behavior
486     */
487
488    /// The window’s delegate.
489    fn ip_delegate(&self) -> id {
490        unsafe { msg_send![self.m_self(), delegate] }
491    }
492
493    /// Sets the window’s delegate.
494    ///
495    /// # Arguments
496    ///
497    /// * `delegate` - The delegate object.
498    fn ip_set_delegate(&self, delegate: NSWindow) {
499        unsafe { msg_send![self.m_self(), setDelegate: delegate] }
500    }
501
502    /* Configuring the Window's Appearance
503     */
504
505    /// The main content view controller for the window.
506    fn ip_content_view_controller(&self) -> NSViewController {
507        unsafe { msg_send![self.m_self(), contentViewController] }
508    }
509
510    /* Configuring the Window's Appearance
511     */
512
513    /// Flags that describe the window’s current style, such as if it’s resizable or in full-screen mode.
514    fn ip_style_mask(&self) -> NSWindowStyleMask {
515        unsafe { msg_send![self.m_self(), styleMask] }
516    }
517
518    /// Sets the flags that describe the window’s current style, such as if it’s resizable or in full-screen mode.
519    ///
520    /// # Arguments
521    ///
522    /// * `style_mask` - The flags that describe the window’s current style, such as if it’s resizable or in full-screen mode.
523    fn ip_set_style_mask(&mut self, style_mask: NSWindowStyleMask) {
524        unsafe { msg_send![self.m_self(), setStyleMask: style_mask] }
525    }
526
527    /// Takes the window into or out of fullscreen mode,
528    fn im_toggle_full_screen(&self, sender: id) {
529        unsafe { msg_send![self.m_self(), toggleFullScreen: sender] }
530    }
531
532    /// A Boolean value that indicates whether the window is able to receive keyboard and mouse events even when some other window is being run modally.
533    fn ip_works_when_modal(&self) -> bool {
534        unsafe { to_bool(msg_send![self.m_self(), worksWhenModal]) }
535    }
536
537    /// The window’s alpha value.
538    fn ip_alpha_value(&self) -> CGFloat {
539        unsafe { msg_send![self.m_self(), alphaValue] }
540    }
541
542    /// Sets the window’s alpha value.
543    ///
544    /// # Arguments
545    ///
546    /// * `value` - The window’s alpha value.
547    fn ip_set_alpha_value(&mut self, value: CGFloat) {
548        unsafe { msg_send![self.m_self(), setAlphaValue: value] }
549    }
550
551    /// The color of the window’s background.
552    fn ip_background_color(&self) -> NSColor {
553        unsafe { NSColor::from_id(msg_send![self.m_self(), backgroundColor]) }
554    }
555
556    /// Sets the color of the window’s background.
557    ///
558    /// # Arguments
559    ///
560    /// * `color` - The color of the window’s background.
561    fn ip_set_background_color(&mut self, color: NSColor) {
562        unsafe { msg_send![self.m_self(), setBackgroundColor: color] }
563    }
564
565    /// The window’s color space.
566    fn ip_color_space(&self) -> NSColorSpace {
567        unsafe { NSColorSpace::from_id(msg_send![self.m_self(), colorSpace]) }
568    }
569
570    /// Sets the window’s color space.
571    ///
572    /// # Arguments
573    ///
574    /// * `color_space` - The window’s color space.
575    fn ip_set_color_space(&mut self, color_space: NSColorSpace) {
576        unsafe { msg_send![self.m_self(), setColorSpace: color_space] }
577    }
578
579    /// Sets a Boolean value that indicates whether the window’s depth limit can change to match the depth of the screen it’s on.
580    fn im_set_dynamic_depth_limit(&self, flag: bool) {
581        unsafe { msg_send![self.m_self(), setDynamicDepthLimit: flag] }
582    }
583
584    /// A Boolean value that indicates whether the window can hide when its application becomes hidden.
585    fn ip_can_hide(&self) -> bool {
586        unsafe { to_bool(msg_send![self.m_self(), canHide]) }
587    }
588
589    /// Sets a Boolean value that indicates whether the window can hide when its application becomes hidden.
590    ///
591    /// # Arguments
592    ///
593    /// * `flag` - A Boolean value that indicates whether the window can hide when its application becomes hidden.
594    fn ip_set_can_hide(&mut self, flag: bool) {
595        unsafe { msg_send![self.m_self(), setCanHide: flag] }
596    }
597
598    /// A Boolean value that indicates whether the window is on the currently active space.
599    fn ip_is_on_active_space(&self) -> bool {
600        unsafe { to_bool(msg_send![self.m_self(), isOnActiveSpace]) }
601    }
602
603    /// A Boolean value that indicates whether the window is removed from the screen when its application becomes inactive.
604    fn ip_hides_on_deactivate(&self) -> bool {
605        unsafe { to_bool(msg_send![self.m_self(), hidesOnDeactivate]) }
606    }
607
608    /// Sets a Boolean value that indicates whether the window is removed from the screen when its application becomes inactive.
609    ///
610    /// # Arguments
611    ///
612    /// * `flag` - A Boolean value that indicates whether the window is removed from the screen when its application becomes inactive.
613    fn ip_set_hides_on_deactivate(&mut self, flag: bool) {
614        unsafe { msg_send![self.m_self(), setHidesOnDeactivate: flag] }
615    }
616
617    /// A value that identifies the window’s behavior in window collections.
618    fn ip_collection_behavior(&self) -> NSWindowCollectionBehavior {
619        unsafe { msg_send![self.m_self(), collectionBehavior] }
620    }
621
622    /// A Boolean value that indicates whether the window is opaque.
623    fn ip_is_opaque(&self) -> bool {
624        unsafe { to_bool(msg_send![self.m_self(), isOpaque]) }
625    }
626
627    /// Sets a Boolean value that indicates whether the window is opaque.
628    ///
629    /// # Arguments
630    ///
631    /// * `flag` - A Boolean value that indicates whether the window is opaque.
632    fn ip_set_opaque(&mut self, flag: bool) {
633        unsafe { msg_send![self.m_self(), setOpaque: flag] }
634    }
635
636    /// A Boolean value that indicates whether the window has a shadow.
637    fn ip_has_shadow(&self) -> bool {
638        unsafe { to_bool(msg_send![self.m_self(), hasShadow]) }
639    }
640
641    /// Sets a Boolean value that indicates whether the window has a shadow.
642    ///
643    /// # Arguments
644    ///
645    /// * `flag` - A Boolean value that indicates whether the window has a shadow.
646    fn ip_set_has_shadow(&mut self, flag: bool) {
647        unsafe { msg_send![self.m_self(), setHasShadow: flag] }
648    }
649
650    /// Invalidates the window shadow so that it is recomputed based on the current window shape.
651    fn im_invalidate_shadow(&self) {
652        unsafe { msg_send![self.m_self(), invalidateShadow] }
653    }
654
655    /// Indicates whether the window calculates the thickness of a given border automatically.
656    fn im_autorecalculates_content_border_thickness_for_edge(&self, edge: NSRectEdge) -> bool {
657        unsafe {
658            to_bool(msg_send![
659                self.m_self(),
660                autorecalculatesContentBorderThicknessForEdge: edge
661            ])
662        }
663    }
664
665    /// Specifies whether the window calculates the thickness of a given border automatically.
666    ///
667    /// # Arguments
668    ///
669    /// * `flag` - A Boolean value that indicates whether the window calculates the thickness of a given border automatically.
670    /// * `edge` - The edge of the window for which to set the autorecalculates content border thickness value.
671    fn im_set_autorecalculates_content_border_thickness_for_edge(
672        &self,
673        flag: bool,
674        edge: NSRectEdge,
675    ) {
676        unsafe {
677            msg_send![self.m_self(), setAutorecalculatesContentBorderThickness: flag forEdge: edge]
678        }
679    }
680
681    /// Indicates the thickness of a given border of the window.
682    ///
683    /// # Arguments
684    ///
685    /// * `edge` - The edge of the window for which to return the thickness.
686    fn im_content_border_thickness_for_edge(&self, edge: NSRectEdge) -> CGFloat {
687        unsafe { msg_send![self.m_self(), contentBorderThicknessForEdge: edge] }
688    }
689
690    /// Specifies the thickness of a given border of the window.
691    ///
692    /// # Arguments
693    ///
694    /// * `thickness` - The thickness of the border.
695    /// * `edge` - The edge of the window for which to set the thickness.
696    fn im_set_content_border_thickness_for_edge(&self, thickness: CGFloat, edge: NSRectEdge) {
697        unsafe { msg_send![self.m_self(), setContentBorderThickness: thickness forEdge: edge] }
698    }
699
700    /// A Boolean value that indicates whether the window prevents application termination when modal.
701    fn ip_prevents_application_termination(&self) -> bool {
702        unsafe {
703            to_bool(msg_send![
704                self.m_self(),
705                preventsApplicationTerminationWhenModal
706            ])
707        }
708    }
709
710    /// An object that the window inherits its appearance from.
711    fn ip_appearance_source(&self) -> id {
712        unsafe { msg_send![self.m_self(), appearanceSource] }
713    }
714
715    /* Accessing Window Information
716     */
717
718    /// The depth limit of the window.
719    fn ip_depth_limit(&self) -> NSWindowDepth {
720        unsafe { msg_send![self.m_self(), depthLimit] }
721    }
722
723    /// Sets the depth limit of the window.
724    ///
725    /// # Arguments
726    ///
727    /// * `depth` - The depth limit of the window.
728    fn ip_set_depth_limit(&mut self, depth: NSWindowDepth) {
729        unsafe { msg_send![self.m_self(), setDepthLimit: depth] }
730    }
731
732    /// A Boolean value that indicates whether the window’s depth limit can change to match the depth of the screen it’s on.
733    fn ip_has_dynamic_depth_limit(&self) -> bool {
734        unsafe { to_bool(msg_send![self.m_self(), hasDynamicDepthLimit]) }
735    }
736
737    /// Returns the default depth limit for instances of NSWindow.
738    fn tp_default_depth_limit() -> NSWindowDepth {
739        unsafe { msg_send![Self::m_class(), defaultDepthLimit] }
740    }
741
742    /// The window number of the window’s window device.
743    fn ip_window_number(&self) -> Int {
744        unsafe { msg_send![self.m_self(), windowNumber] }
745    }
746
747    /// Returns the window numbers for all visible windows satisfying the specified options.
748    fn tm_window_numbers_with_options(options: NSWindowNumberListOptions) -> NSArray<NSNumber> {
749        unsafe {
750            NSArray::from_id(msg_send![
751                Self::m_class(),
752                windowNumbersWithOptions: options
753            ])
754        }
755    }
756
757    /// A dictionary containing information about the window’s resolution, such as color, depth, and so on.
758    fn ip_device_description(&self) -> NSDictionary<NSDeviceDescriptionKey, id> {
759        unsafe { NSDictionary::from_id(msg_send![self.m_self(), deviceDescription]) }
760    }
761
762    /// A Boolean value that indicates whether the window can be displayed at the login window.
763    fn ip_can_become_visible_without_login(&self) -> bool {
764        unsafe { to_bool(msg_send![self.m_self(), canBecomeVisibleWithoutLogin]) }
765    }
766
767    /// A Boolean value that indicates the level of access other processes have to the window’s content.
768    fn ip_sharing_type(&self) -> NSWindowSharingType {
769        unsafe { msg_send![self.m_self(), sharingType] }
770    }
771
772    /// The window’s backing store type.
773    fn ip_backing_type(&self) -> NSBackingStoreType {
774        unsafe { msg_send![self.m_self(), backingType] }
775    }
776
777    /* Getting Layout Information
778     */
779
780    /// Returns the content rectangle used by a window with a given frame rectangle and window style.
781    ///
782    /// # Arguments
783    ///
784    /// * `frame` - The frame rectangle of the window.
785    /// * `style` - The window style.
786    fn tm_content_rect_for_frame_rect_style_mask(
787        frame: NSRect,
788        style: NSWindowStyleMask,
789    ) -> NSRect {
790        unsafe { msg_send![Self::m_class(), contentRectForFrameRect: frame styleMask: style] }
791    }
792
793    /// Returns the frame rectangle used by a window with a given content rectangle and window style.
794    ///
795    /// # Arguments
796    ///
797    /// * `content` - The content rectangle of the window.
798    /// * `style` - The window style.
799    fn tm_frame_rect_for_content_rect_style_mask(
800        content: NSRect,
801        style: NSWindowStyleMask,
802    ) -> NSRect {
803        unsafe { msg_send![Self::m_class(), frameRectForContentRect: content styleMask: style] }
804    }
805
806    /// Returns the minimum width a window’s frame rectangle must have for it to display a title, with a given window style.
807    ///
808    /// # Arguments
809    ///
810    /// * `title` - The title of the window.
811    /// * `style` - The window style.
812    fn tm_min_frame_width_with_title_style_mask(title: &str, style: NSWindowStyleMask) -> CGFloat {
813        unsafe { msg_send![Self::m_class(), minFrameWidthWithTitle: title styleMask: style] }
814    }
815
816    /// Returns the window’s content rectangle with a given frame rectangle.
817    ///
818    /// # Arguments
819    ///
820    /// * `frame` - The frame rectangle of the window.
821    fn im_content_rect_for_frame_rect(&self, frame: NSRect) -> NSRect {
822        unsafe { msg_send![self.m_self(), contentRectForFrameRect: frame] }
823    }
824
825    /// Returns the window’s frame rectangle with a given content rectangle.
826    fn im_frame_rect_for_content_rectim_frame_rect_for_content_rect(
827        &self,
828        content: NSRect,
829    ) -> NSRect {
830        unsafe { msg_send![self.m_self(), frameRectForContentRect: content] }
831    }
832
833    /* Managing Sheets
834     */
835
836    /// The sheet attached to the window.
837    fn ip_attached_sheet(&self) -> NSWindow {
838        unsafe { NSWindow::from_id(msg_send![self.m_self(), attachedSheet]) }
839    }
840
841    /// The sheet attached to the window.
842    fn ip_sheet(&mut self) -> bool {
843        unsafe { to_bool(msg_send![self.m_self(), isSheet]) }
844    }
845
846    /// Starts a document-modal session and presents—or queues for presentation—a sheet.
847    ///
848    /// # Arguments
849    ///
850    /// * `sheet` - The sheet to present.
851    /// * `handler` - The handler to call when the sheet's modal session ends.
852    fn im_begin_sheet_completion_handler<W>(
853        &self,
854        sheet: &NSWindow<W>,
855        handler: RcBlock<(NSModalResponse,), ()>,
856    ) where
857        W: PNSWindowDelegate + 'static,
858    {
859        unsafe { msg_send![self.m_self(), beginSheet: sheet completionHandler: handler] }
860    }
861
862    /// Starts a document-modal session and presents the specified critical sheet.
863    ///
864    /// # Arguments
865    ///
866    /// * `sheet` - The sheet to present.
867    /// * `handler` - The handler to call when the sheet's modal session ends.
868    fn im_begin_critical_sheet_completion_handler(
869        &self,
870        sheet: NSWindow,
871        handler: RcBlock<NSModalResponse, ()>,
872    ) {
873        unsafe { msg_send![self.m_self(), beginCriticalSheet: sheet completionHandler: handler] }
874    }
875
876    /// Ends a document-modal session and dismisses the specified sheet.
877    ///
878    /// # Arguments
879    ///
880    /// * `sheet` - The sheet to dismiss.
881    fn im_end_sheet<W>(&self, sheet: &NSWindow<W>)
882    where
883        W: PNSWindowDelegate + 'static,
884    {
885        unsafe { msg_send![self.m_self(), endSheet: sheet] }
886    }
887
888    /// Ends a document-modal session and dismisses the specified sheet.
889    ///
890    /// # Arguments
891    ///
892    /// * `sheet` - The sheet to dismiss.
893    /// * `code` - The return code of the sheet.
894    fn im_end_sheet_with_return_code(&self, sheet: NSWindow, code: NSModalResponse) {
895        unsafe { msg_send![self.m_self(), endSheet: sheet returnCode: code] }
896    }
897
898    /// The window to which the sheet is attached.
899    fn ip_sheet_parent(&self) -> NSWindow {
900        unsafe { NSWindow::from_id(msg_send![self.m_self(), sheetParent]) }
901    }
902
903    /// An array of the sheets currently attached to the window.
904    fn ip_sheets(&self) -> NSArray<NSWindow> {
905        unsafe { NSArray::from_id(msg_send![self.m_self(), sheets]) }
906    }
907
908    /*Sizing Windows
909     */
910
911    /// The window’s frame rectangle in screen coordinates, including the title bar.
912    fn ip_frame(&self) -> NSRect {
913        unsafe { msg_send![self.m_self(), frame] }
914    }
915
916    /// Positions the bottom-left corner of the window’s frame rectangle at a given point in screen coordinates.
917    ///
918    /// # Arguments
919    ///
920    /// * `point` - The point at which to position the bottom-left corner of the window’s frame rectangle.
921    fn im_set_frame_origin(&self, point: NSPoint) {
922        unsafe { msg_send![self.m_self(), setFrameOrigin: point] }
923    }
924
925    /// Positions the top-left corner of the window’s frame rectangle at a given point in screen coordinates.
926    ///
927    /// # Arguments
928    ///
929    /// * `point` - The point at which to position the top-left corner of the window’s frame rectangle.
930    fn im_set_frame_top_left_point(&self, point: NSPoint) {
931        unsafe { msg_send![self.m_self(), setFrameTopLeftPoint: point] }
932    }
933
934    /// Modifies and returns a frame rectangle so that its top edge lies on a specific screen.
935    ///
936    /// # Arguments
937    ///
938    /// * `frame` - The frame rectangle to modify.
939    /// * `screen` - The screen on which to position the top edge of the frame rectangle.
940    fn im_constrain_frame_rect_to_screen(&self, frame: NSRect, screen: NSScreen) -> NSRect {
941        unsafe { msg_send![self.m_self(), constrainFrameRect: frame toScreen: screen] }
942    }
943
944    /// Positions the window’s top-left to a given point.
945    ///
946    /// # Arguments
947    ///
948    /// * `point` - The point at which to position the top-left corner of the window.
949    fn im_cascade_top_left_from_point(&self, point: NSPoint) {
950        unsafe { msg_send![self.m_self(), cascadeTopLeftFromPoint: point] }
951    }
952
953    /// Sets the origin and size of the window’s frame rectangle according to a given frame rectangle, thereby setting its position and size onscreen.
954    ///
955    /// # Arguments
956    ///
957    /// * `frame` - The frame rectangle to set.
958    /// * `flag` - When `true` the window sends a `displayIfNeeded` message down its view hierarchy, thus redrawing all views.
959    fn im_set_frame_display(&self, frame: NSRect, flag: bool) {
960        unsafe { msg_send![self.m_self(), setFrame: frame display: flag] }
961    }
962
963    /// Sets the origin and size of the window’s frame rectangle, with optional animation, according to a given frame rectangle, thereby setting its position and size onscreen.
964    ///
965    /// # Arguments
966    ///
967    /// * `frame` - The frame rectangle to set.
968    /// * `flag` - When `true` the window sends a `displayIfNeeded` message down its view hierarchy, thus redrawing all views.
969    /// * `animate` - `true` to perform the animation, whose duration is specified by `animation_resize_time`
970    fn im_set_frame_display_animate(&self, frame: NSRect, flag: bool, animate: bool) {
971        unsafe { msg_send![self.m_self(), setFrame: frame display: flag animate: animate] }
972    }
973
974    /// Specifies the duration of a smooth frame-size change.
975    fn im_animation_resize_time(&self, frame: NSRect) -> NSTimeInterval {
976        unsafe { msg_send![self.m_self(), animationResizeTime: frame] }
977    }
978
979    /// The window’s aspect ratio, which constrains the size of its frame rectangle to integral multiples of this ratio when the user resizes it.
980    fn ip_aspect_ratio(&self) -> NSSize {
981        unsafe { msg_send![self.m_self(), aspectRatio] }
982    }
983
984    /// Sets the window’s aspect ratio.
985    ///
986    /// # Arguments
987    ///
988    /// * `ratio` - The aspect ratio to set.
989    fn ip_set_aspect_ratio(&self, ratio: NSSize) {
990        unsafe { msg_send![self.m_self(), setAspectRatio: ratio] }
991    }
992
993    /// The minimum size to which the window’s frame (including its title bar) can be sized.
994    fn ip_min_size(&self) -> NSSize {
995        unsafe { msg_send![self.m_self(), minSize] }
996    }
997
998    /// Sets the minimum size to which the window’s frame (including its title bar) can be sized.
999    ///
1000    /// # Arguments
1001    ///
1002    /// * `size` - The minimum size to which the window’s frame (including its title bar) can be sized.
1003    fn ip_set_min_size(&self, size: NSSize) {
1004        unsafe { msg_send![self.m_self(), setMinSize: size] }
1005    }
1006
1007    /// The maximum size to which the window’s frame (including its title bar) can be sized.
1008    fn ip_max_size(&self) -> NSSize {
1009        unsafe { msg_send![self.m_self(), maxSize] }
1010    }
1011
1012    /// Sets the maximum size to which the window’s frame (including its title bar) can be sized.
1013    ///
1014    /// # Arguments
1015    ///
1016    /// * `size` - The maximum size to which the window’s frame (including its title bar) can be sized.
1017    fn ip_set_max_size(&self, size: NSSize) {
1018        unsafe { msg_send![self.m_self(), setMaxSize: size] }
1019    }
1020
1021    /// A Boolean value that indicates whether the window is in a zoomed state.
1022    fn ip_zoomed(&self) -> bool {
1023        unsafe { msg_send![self.m_self(), isZoomed] }
1024    }
1025
1026    /// This action method simulates the user clicking the zoom box by momentarily highlighting the button and then zooming the window.
1027    fn im_perform_zoom(&self, sender: id) {
1028        unsafe { msg_send![self.m_self(), performZoom: sender] }
1029    }
1030
1031    /// Toggles the size and location of the window between its standard state (which the application provides as the best size to display the window’s data) and its user state (a new size and location the user may have set by moving or resizing the window).
1032    fn im_zoom(&self, sender: id) {
1033        unsafe { msg_send![self.m_self(), zoom: sender] }
1034    }
1035
1036    /// The window’s resizing increments.
1037    fn ip_resize_increments(&self) -> NSSize {
1038        unsafe { msg_send![self.m_self(), resizeIncrements] }
1039    }
1040
1041    /// Sets the window’s resizing increments.
1042    ///
1043    /// # Arguments
1044    ///
1045    /// * `increments` - The resizing increments to set.
1046    fn ip_set_resize_increments(&self, increments: NSSize) {
1047        unsafe { msg_send![self.m_self(), setResizeIncrements: increments] }
1048    }
1049
1050    /// A Boolean value that indicates whether the window tries to optimize user-initiated resize operations by preserving the content of views that have not changed.
1051    fn ip_preserves_content_during_live_resize(&self) -> bool {
1052        unsafe { msg_send![self.m_self(), preservesContentDuringLiveResize] }
1053    }
1054
1055    /// Sets whether the window tries to optimize user-initiated resize operations by preserving the content of views that have not changed.
1056    ///
1057    /// # Arguments
1058    ///
1059    /// * `flag` - `true` to optimize user-initiated resize operations by preserving the content of views that have not changed.
1060    fn ip_set_preserves_content_during_live_resize(&self, flag: bool) {
1061        unsafe { msg_send![self.m_self(), setPreservesContentDuringLiveResize: flag] }
1062    }
1063
1064    /// A Boolean value that indicates whether the window is being resized by the user.
1065    fn ip_in_live_resize(&self) -> bool {
1066        unsafe { msg_send![self.m_self(), inLiveResize] }
1067    }
1068
1069    /// Sets a Boolean value that indicates whether the window is being resized by the user.
1070    ///
1071    /// # Arguments
1072    ///
1073    /// * `flag` - `true` if the window is being resized by the user.
1074    fn ip_set_in_live_resize(&self, flag: bool) {
1075        unsafe { msg_send![self.m_self(), setInLiveResize: flag] }
1076    }
1077
1078    /* Sizing Content
1079     */
1080
1081    /// The window’s content aspect ratio.
1082    fn ip_content_aspect_ratio(&self) -> NSSize {
1083        unsafe { msg_send![self.m_self(), contentAspectRatio] }
1084    }
1085
1086    /// Sets the window’s content aspect ratio.
1087    ///
1088    /// # Arguments
1089    ///
1090    /// * `content_aspect_ratio` - The window’s content aspect ratio.
1091    fn ip_set_content_aspect_ratio(&self, size: NSSize) {
1092        unsafe { msg_send![self.m_self(), setContentAspectRatio: size] }
1093    }
1094
1095    /// The minimum size of the window’s content view in the window’s base coordinate system.
1096    fn ip_content_min_size(&self) -> NSSize {
1097        unsafe { msg_send![self.m_self(), contentMinSize] }
1098    }
1099
1100    /// Sets the minimum size of the window’s content view in the window’s base coordinate system.
1101    ///
1102    /// # Arguments
1103    ///
1104    /// * `content_min_size` - The minimum size of the window’s content view in the window’s base coordinate system.
1105    fn ip_set_content_min_size(&self, content_min_size: NSSize) {
1106        unsafe { msg_send![self.m_self(), setContentMinSize: content_min_size] }
1107    }
1108
1109    /// Sets the size of the window’s content view to a given size, which is expressed in the window’s base coordinate system.
1110    ///
1111    /// # Arguments
1112    ///
1113    /// * `content_size` - The size of the window’s content view in the window’s base coordinate system.
1114    fn im_set_content_size(&self, size: NSSize) {
1115        unsafe { msg_send![self.m_self(), setContentSize: size] }
1116    }
1117
1118    /// The maximum size of the window’s content view in the window’s base coordinate system.
1119    fn ip_content_max_size(&self) -> NSSize {
1120        unsafe { msg_send![self.m_self(), contentMaxSize] }
1121    }
1122
1123    /// Sets the maximum size of the window’s content view in the window’s base coordinate system.
1124    ///
1125    /// # Arguments
1126    ///
1127    /// * `content_max_size` - The maximum size of the window’s content view in the window’s base coordinate system.
1128    fn ip_set_content_max_size(&self, size: NSSize) {
1129        unsafe { msg_send![self.m_self(), setContentMaxSize: size] }
1130    }
1131
1132    /// The window’s content-view resizing increments.
1133    fn ip_content_resize_increments(&self) -> NSSize {
1134        unsafe { msg_send![self.m_self(), contentResizeIncrements] }
1135    }
1136
1137    /// Sets the window’s content-view resizing increments.
1138    ///
1139    /// # Arguments
1140    ///
1141    /// * `content_resize_increments` - The window’s content-view resizing increments.
1142    fn ip_set_content_resize_increments(&self, content_resize_increments: NSSize) {
1143        unsafe {
1144            msg_send![
1145                self.m_self(),
1146                setContentResizeIncrements: content_resize_increments
1147            ]
1148        }
1149    }
1150
1151    /// A value used by Auto Layout constraints to automatically bind to the value of contentLayoutRect.
1152    fn ip_content_layout_guide(&self) -> id {
1153        unsafe { msg_send![self.m_self(), contentLayoutGuide] }
1154    }
1155
1156    /// Sets a value used by Auto Layout constraints to automatically bind to the value of contentLayoutRect.
1157    ///
1158    /// # Arguments
1159    ///
1160    /// * `content_layout_guide` - A value used by Auto Layout constraints to automatically bind to the value of contentLayoutRect.
1161    fn ip_set_content_layout_guide(&self, content_layout_guide: id) {
1162        unsafe { msg_send![self.m_self(), setContentLayoutGuide: content_layout_guide] }
1163    }
1164
1165    /// The area inside the window that is for non-obscured content, in window coordinates.
1166    fn ip_content_layout_rect(&self) -> NSRect {
1167        unsafe { msg_send![self.m_self(), contentLayoutRect] }
1168    }
1169
1170    /// Sets the area inside the window that is for non-obscured content, in window coordinates.
1171    ///
1172    /// # Arguments
1173    ///
1174    /// * `content_layout_rect` - The area inside the window that is for non-obscured content, in window coordinates.
1175    fn ip_set_content_layout_rect(&self, content_layout_rect: NSRect) {
1176        unsafe { msg_send![self.m_self(), setContentLayoutRect: content_layout_rect] }
1177    }
1178
1179    /// A maximum size that is used to determine if a window can fit when it is in full screen in a tile.
1180    fn ip_full_screen_tile_size(&self) -> NSSize {
1181        unsafe { msg_send![self.m_self(), fullScreenTileSize] }
1182    }
1183
1184    /// Sets a maximum size that is used to determine if a window can fit when it is in full screen in a tile.
1185    ///
1186    /// # Arguments
1187    ///
1188    /// * `full_screen_tile_size` - A maximum size that is used to determine if a window can fit when it is in full screen in a tile.
1189    fn ip_set_full_screen_tile_size(&self, size: NSSize) {
1190        unsafe { msg_send![self.m_self(), setFullScreenTileSize: size] }
1191    }
1192
1193    /// A minimum size that is used to determine if a window can fit when it is in full screen in a tile.
1194    fn ip_full_screen_tile_content_size(&self) -> NSSize {
1195        unsafe { msg_send![self.m_self(), fullScreenTileContentSize] }
1196    }
1197
1198    /// Sets a minimum size that is used to determine if a window can fit when it is in full screen in a tile.
1199    ///
1200    /// # Arguments
1201    ///
1202    /// * `full_screen_tile_content_size` - A minimum size that is used to determine if a window can fit when it is in full screen in a tile.
1203    fn ip_set_full_screen_tile_content_size(&self, size: NSSize) {
1204        unsafe { msg_send![self.m_self(), setFullScreenTileContentSize: size] }
1205    }
1206
1207    /* Managing Window Layers
1208     */
1209
1210    /// Removes the window from the screen list, which hides the window.
1211    fn im_order_out(&self, sender: id) {
1212        unsafe { msg_send![self.m_self(), orderOut: sender] }
1213    }
1214
1215    /// Moves the window to the back of its level in the screen list, without changing either the key window or the main window.
1216    fn im_order_back(&self, sender: id) {
1217        unsafe { msg_send![self.m_self(), orderBack: sender] }
1218    }
1219
1220    /// Moves the window to the front of its level in the screen list, without changing either the key window or the main window.
1221    fn im_order_front(&self, sender: id) {
1222        unsafe { msg_send![self.m_self(), orderFront: sender] }
1223    }
1224
1225    /// Moves the window to the front of its level, even if its application isn’t active, without changing either the key window or the main window.
1226    fn im_order_front_regardless(&self) {
1227        unsafe { msg_send![self.m_self(), orderFrontRegardless] }
1228    }
1229
1230    /// Repositions the window’s window device in the window server’s screen list.
1231    fn im_order_window_relative_to(&self, place: NSWindowOrderingMode, other: Int) {
1232        unsafe { msg_send![self.m_self(), orderWindow: place relativeTo: other] }
1233    }
1234
1235    /// The window level of the window.
1236    fn ip_window_level(&self) -> NSWindowLevel {
1237        unsafe { msg_send![self.m_self(), windowLevel] }
1238    }
1239
1240    /// Sets the window level of the window.
1241    ///
1242    /// # Arguments
1243    ///
1244    /// * `level` - The window level of the window.
1245    fn ip_set_window_level(&self, level: NSWindowLevel) {
1246        unsafe { msg_send![self.m_self(), setWindowLevel: level] }
1247    }
1248
1249    /* Managing Window Visibility and Occlusion State
1250     */
1251
1252    /// A Boolean value that indicates whether the window is visible onscreen (even when it’s obscured by other windows).
1253    fn ip_visible(&self) -> bool {
1254        unsafe { msg_send![self.m_self(), isVisible] }
1255    }
1256
1257    /// The occlusion state of the window.
1258    fn ip_occlusion_state(&self) -> NSWindowOcclusionState {
1259        unsafe { msg_send![self.m_self(), occlusionState] }
1260    }
1261
1262    /* Managing Window Frames in User Defaults
1263     */
1264
1265    /// Removes the frame data stored under a given name from the application’s user defaults.
1266    ///
1267    /// # Arguments
1268    ///
1269    /// * `name` - The name of the frame data to remove.
1270    fn tm_remove_frame_using_name(name: &NSWindowFrameAutosaveName) {
1271        unsafe { msg_send![Self::m_class(), removeFrameUsingName: name] }
1272    }
1273
1274    /// Sets the window’s frame rectangle by reading the rectangle data stored under a given name from the defaults system.
1275    fn im_set_frame_using_name(&self, name: NSWindowFrameAutosaveName) -> bool {
1276        unsafe { msg_send![self.m_self(), setFrameUsingName: name] }
1277    }
1278
1279    /// Sets the window’s frame rectangle by reading the rectangle data stored under a given name from the defaults system. Can operate on non-resizable windows.
1280    fn im_set_frame_using_name_force(&self, name: NSWindowFrameAutosaveName, force: bool) -> bool {
1281        unsafe { msg_send![self.m_self(), setFrameUsingName:name force:force] }
1282    }
1283
1284    /// Saves the window’s frame rectangle in the user defaults system under a given name.
1285    fn im_save_frame_using_name(&self, name: NSWindowFrameAutosaveName) {
1286        unsafe { msg_send![self.m_self(), saveFrameUsingName: name] }
1287    }
1288
1289    /// Sets the name AppKit uses to automatically save the window’s frame rectangle data in the defaults system.
1290    fn im_set_frame_autosave_name(&self, name: NSWindowFrameAutosaveName) -> bool {
1291        unsafe { to_bool(msg_send![self.m_self(), setFrameAutosaveName: name]) }
1292    }
1293
1294    /// The name used to automatically save the window’s frame rectangle data in the defaults system.
1295    fn ip_frame_autosave_name(&self) -> NSWindowFrameAutosaveName {
1296        unsafe { msg_send![self.m_self(), frameAutosaveName] }
1297    }
1298
1299    /// A string representation of the window’s frame rectangle.
1300    fn ip_string_with_saved_frame(&self) -> NSWindowPersistableFrameDescriptor {
1301        unsafe { msg_send![self.m_self(), stringWithSavedFrame] }
1302    }
1303
1304    /// Sets the window’s frame rectangle from a given string representation.
1305    fn im_set_frame_from_string(&self, string: NSWindowPersistableFrameDescriptor) {
1306        unsafe { msg_send![self.m_self(), setFrameFromString: string] }
1307    }
1308
1309    /* Managing Key Status
1310     */
1311
1312    /// A Boolean value that indicates whether the window is the key window for the application.
1313    fn ip_key_window(&self) -> bool {
1314        unsafe { msg_send![self.m_self(), isKeyWindow] }
1315    }
1316
1317    /// A Boolean value that indicates whether the window can become the key window.
1318    fn ip_can_become_key_window(&self) -> bool {
1319        unsafe { msg_send![self.m_self(), canBecomeKeyWindow] }
1320    }
1321
1322    /// Makes the window the key window.
1323    fn im_make_key_window(&self) {
1324        unsafe { msg_send![self.m_self(), makeKeyWindow] }
1325    }
1326
1327    /// Moves the window to the front of the screen list, within its level, and makes it the key window; that is, it shows the window.
1328    fn im_make_key_and_order_front(&self, sender: id) {
1329        unsafe { msg_send![self.m_self(), makeKeyAndOrderFront: sender] }
1330    }
1331
1332    /// Informs the window that it has become the key window.
1333    fn im_become_key_window(&self) {
1334        unsafe { msg_send![self.m_self(), becomeKeyWindow] }
1335    }
1336
1337    /// Resigns the window’s key window status.
1338    fn im_resign_key_window(&self) {
1339        unsafe { msg_send![self.m_self(), resignKeyWindow] }
1340    }
1341
1342    /* Managing Main Status
1343     */
1344
1345    /// A Boolean value that indicates whether the window is the application’s main window.
1346    fn ip_main_window(&self) -> bool {
1347        unsafe { msg_send![self.m_self(), isMainWindow] }
1348    }
1349
1350    /// A Boolean value that indicates whether the window can become the application’s main window.
1351    fn ip_can_become_main_window(&self) -> bool {
1352        unsafe { msg_send![self.m_self(), canBecomeMainWindow] }
1353    }
1354
1355    /// Makes the window the main window.
1356    fn im_make_main_window(&self) {
1357        unsafe { msg_send![self.m_self(), makeMainWindow] }
1358    }
1359
1360    /// Informs the window that it has become the main window.
1361    fn im_become_main_window(&self) {
1362        unsafe { msg_send![self.m_self(), becomeMainWindow] }
1363    }
1364
1365    /// Resigns the window’s main window status.
1366    fn im_resign_main_window(&self) {
1367        unsafe { msg_send![self.m_self(), resignMainWindow] }
1368    }
1369
1370    /// The window’s toolbar.
1371    fn ip_toolbar(&self) -> NSToolbar {
1372        unsafe { msg_send![self.m_self(), toolbar] }
1373    }
1374
1375    /// Sets the window’s toolbar.
1376    ///
1377    /// # Arguments
1378    ///
1379    /// * `toolbar` - The window’s toolbar.
1380    fn ip_set_toolbar(&self, toolbar: NSToolbar) {
1381        unsafe { msg_send![self.m_self(), setToolbar: toolbar] }
1382    }
1383
1384    /// Toggles the visibility of the window’s toolbar.
1385    fn ip_toggle_toolbar_shown(&self, sender: id) {
1386        unsafe { msg_send![self.m_self(), toggleToolbarShown: sender] }
1387    }
1388
1389    /// Presents the toolbar customization user interface.
1390    fn ip_run_toolbar_customization_palette(&self, sender: id) {
1391        unsafe { msg_send![self.m_self(), runToolbarCustomizationPalette: sender] }
1392    }
1393
1394    /* Managing Attached Windows
1395     */
1396
1397    /// An array of the window’s attached child windows.
1398    fn ip_child_windows(&self) -> id {
1399        unsafe { msg_send![self.m_self(), childWindows] }
1400    }
1401
1402    /// Attaches a child window to the window.
1403    fn add_child_window_ordered(&self, child: id, order: NSWindowOrderingMode) {
1404        unsafe { msg_send![self.m_self(), addChildWindow: child ordered: order] }
1405    }
1406
1407    /// Detaches a given child window from the window.
1408    fn remove_child_window(&self, child: id) {
1409        unsafe { msg_send![self.m_self(), removeChildWindow: child] }
1410    }
1411
1412    /// The parent window to which the window is attached as a child.
1413    fn ip_parent_window(&self) -> id {
1414        unsafe { msg_send![self.m_self(), parentWindow] }
1415    }
1416
1417    /* Managing the Window Menu
1418     */
1419
1420    /// A Boolean value that indicates whether the window is excluded from the application’s Windows menu.
1421    fn ip_excluded_from_windows_menu(&self) -> bool {
1422        unsafe { msg_send![self.m_self(), isExcludedFromWindowsMenu] }
1423    }
1424
1425    /// Sets a Boolean value that indicates whether the window is excluded from the application’s Windows menu.
1426    ///
1427    /// # Arguments
1428    ///
1429    /// * `flag` - A Boolean value that indicates whether the window is excluded from the application’s Windows menu.
1430    fn ip_set_excluded_from_windows_menu(&self, flag: bool) {
1431        unsafe { msg_send![self.m_self(), setExcludedFromWindowsMenu: flag] }
1432    }
1433
1434    /* Managing Cursor Rectangles
1435     */
1436
1437    /// A Boolean value that indicates whether the window’s cursor rectangles are enabled.
1438    fn ip_are_cursor_rects_enabled(&self) -> bool {
1439        unsafe { msg_send![self.m_self(), areCursorRectsEnabled] }
1440    }
1441
1442    /// Reenables cursor rectangle management within the window after a disableCursorRects message.
1443    fn im_enable_cursor_rects(&self) {
1444        unsafe { msg_send![self.m_self(), enableCursorRects] }
1445    }
1446
1447    /// Disables all cursor rectangle management within the window.
1448    fn im_disable_cursor_rects(&self) {
1449        unsafe { msg_send![self.m_self(), disableCursorRects] }
1450    }
1451
1452    /// Invalidates all cursor rectangles in the window.
1453    fn im_discard_cursor_rects(&self, view: id) {
1454        unsafe { msg_send![self.m_self(), discardCursorRectsForView: view] }
1455    }
1456
1457    /// Clears the window’s cursor rectangles and the cursor rectangles of the NSView objects in its view hierarchy.
1458    fn im_reset_cursor_rects(&self) {
1459        unsafe { msg_send![self.m_self(), resetCursorRects] }
1460    }
1461
1462    /* Managing Title Bars
1463     */
1464
1465    /// Returns a new instance of a given standard window button, sized appropriately for a given window style.
1466    fn tm_standard_window_button_for_style_mask(
1467        &self,
1468        b: NSWindowButton,
1469        style: NSWindowStyleMask,
1470    ) -> NSButton {
1471        unsafe {
1472            NSButton::from_id(
1473                msg_send![Self::m_class(), standardWindowButton: b forStyleMask: style],
1474            )
1475        }
1476    }
1477
1478    /// Returns the window button of a given window button kind in the window’s view hierarchy.
1479    fn ip_standard_window_button(&self, b: NSWindowButton) -> NSButton {
1480        unsafe { msg_send![self.m_self(), standardWindowButton: b] }
1481    }
1482
1483    /// A Boolean value that indicates whether the toolbar control button is currently displayed.
1484    fn ip_shows_toolbar_button(&self) -> bool {
1485        unsafe { msg_send![self.m_self(), showsToolbarButton] }
1486    }
1487
1488    /// Sets a Boolean value that indicates whether the toolbar control button is displayed.
1489    ///
1490    /// # Arguments
1491    ///
1492    /// * `flag` - A Boolean value that indicates whether the toolbar control button is displayed.
1493    fn ip_set_shows_toolbar_button(&self, flag: bool) {
1494        unsafe { msg_send![self.m_self(), setShowsToolbarButton: flag] }
1495    }
1496
1497    /// A Boolean value that indicates whether the title bar draws its background.
1498    fn ip_titlebar_appears_transparent(&self) -> bool {
1499        unsafe { msg_send![self.m_self(), titlebarAppearsTransparent] }
1500    }
1501
1502    /// Sets a Boolean value that indicates whether the title bar draws its background.
1503    ///
1504    /// # Arguments
1505    ///
1506    /// * `flag` - A Boolean value that indicates whether the title bar draws its background.
1507    fn ip_set_titlebar_appears_transparent(&self, flag: bool) {
1508        unsafe { msg_send![self.m_self(), setTitlebarAppearsTransparent: flag] }
1509    }
1510
1511    /// The style that determines the appearance and location of the toolbar in relation to the title bar.
1512    fn ip_toolbar_style(&self) -> NSWindowToolbarStyle {
1513        unsafe { msg_send![self.m_self(), toolbarStyle] }
1514    }
1515
1516    /// Sets the style that determines the appearance and location of the toolbar in relation to the title bar.
1517    ///
1518    /// # Arguments
1519    ///
1520    /// * `style` - The style that determines the appearance and location of the toolbar in relation to the title bar.
1521    fn ip_set_toolbar_style(&self, style: NSWindowToolbarStyle) {
1522        unsafe { msg_send![self.m_self(), setToolbarStyle: style] }
1523    }
1524
1525    /// The type of separator that the app displays between the title bar and content of a window.
1526    fn ip_titlebar_separator_style(&self) -> NSTitlebarSeparatorStyle {
1527        unsafe { msg_send![self.m_self(), titlebarSeparatorStyle] }
1528    }
1529
1530    /// Sets the type of separator that the app displays between the title bar and content of a window.
1531    ///
1532    /// # Arguments
1533    ///
1534    /// * `style` - The type of separator that the app displays between the title bar and content of a window.
1535    fn ip_set_titlebar_separator_style(&self, style: NSTitlebarSeparatorStyle) {
1536        unsafe { msg_send![self.m_self(), setTitlebarSeparatorStyle: style] }
1537    }
1538
1539    /// The direction the window’s title bar lays text out, either left to right or right to left.
1540    fn ip_titlebar_layout_direction(&self) -> NSUserInterfaceLayoutDirection {
1541        unsafe { msg_send![self.m_self(), titlebarLayoutDirection] }
1542    }
1543
1544    /* Managing Window Tabs
1545     */
1546
1547    /// A Boolean value that indicates whether the app can automatically organize windows into tabs.
1548    fn tp_allows_automatic_window_tabbing() -> bool {
1549        unsafe { to_bool(msg_send![Self::m_class(), allowsAutomaticWindowTabbing]) }
1550    }
1551
1552    /// Sets a Boolean value that indicates whether the app can automatically organize windows into tabs.
1553    fn tm_set_allows_automatic_window_tabbing(allows_automatic_window_tabbing: bool) {
1554        unsafe {
1555            msg_send![
1556                Self::m_class(),
1557                setAllowsAutomaticWindowTabbing: allows_automatic_window_tabbing
1558            ]
1559        }
1560    }
1561
1562    /* Converting Coordinates
1563     */
1564
1565    /// The backing scale factor.
1566    fn ip_backing_scale_factor(&self) -> CGFloat {
1567        unsafe { msg_send![self.m_self(), backingScaleFactor] }
1568    }
1569
1570    /// Returns a backing store pixel-aligned rectangle in window coordinates.
1571    fn im_backing_aligned_rect_options(&self, options: NSAlignmentOptions) -> NSRect {
1572        unsafe { msg_send![self.m_self(), backingAlignedRect: options] }
1573    }
1574
1575    /// Converts a rectangle from its pixel-aligned backing store coordinate system to the window’s coordinate system.
1576    fn im_convert_rect_from_backing(&self, rect: NSRect) -> NSRect {
1577        unsafe { msg_send![self.m_self(), convertRectFromBacking: rect] }
1578    }
1579
1580    /// Converts a rectangle from the screen coordinate system to the window’s coordinate system.
1581    fn im_convert_rect_from_screen(&self, rect: NSRect) -> NSRect {
1582        unsafe { msg_send![self.m_self(), convertRectFromScreen: rect] }
1583    }
1584
1585    /// Converts a point from its pixel-aligned backing store coordinate system to the window’s coordinate system.
1586    fn im_convert_point_from_backing(&self, point: NSPoint) -> NSPoint {
1587        unsafe { msg_send![self.m_self(), convertPointFromBacking: point] }
1588    }
1589
1590    /// Converts a point from the screen coordinate system to the window’s coordinate system.
1591    fn im_convert_point_from_screen(&self, point: NSPoint) -> NSPoint {
1592        unsafe { msg_send![self.m_self(), convertPointFromScreen: point] }
1593    }
1594
1595    /// Converts a rectangle from the window’s coordinate system to its pixel-aligned backing store coordinate system.
1596    fn im_convert_rect_to_backing(&self, rect: NSRect) -> NSRect {
1597        unsafe { msg_send![self.m_self(), convertRectToBacking: rect] }
1598    }
1599
1600    /// Converts a rectangle to the screen coordinate system from the window’s coordinate system.
1601    fn im_convert_rect_to_screen(&self, rect: NSRect) -> NSRect {
1602        unsafe { msg_send![self.m_self(), convertRectToScreen: rect] }
1603    }
1604
1605    /// Converts a point from the window’s coordinate system to its pixel-aligned backing store coordinate system.
1606    fn im_convert_point_to_backing(&self, point: NSPoint) -> NSPoint {
1607        unsafe { msg_send![self.m_self(), convertPointToBacking: point] }
1608    }
1609
1610    /// Converts a point to the screen coordinate system from the window’s coordinate system.
1611    fn im_convert_point_to_screen(&self, point: NSPoint) -> NSPoint {
1612        unsafe { msg_send![self.m_self(), convertPointToScreen: point] }
1613    }
1614
1615    /* Managing Titles
1616     */
1617
1618    /// The string that appears in the title bar of the window or the path to the represented file.
1619    fn ip_title(&self) -> NSString {
1620        unsafe { NSString::from_id(msg_send![self.m_self(), title]) }
1621    }
1622
1623    /// Sets the string that appears in the title bar of the window or the path to the represented file.
1624    ///
1625    /// # Arguments
1626    ///
1627    /// * `title` - The string that appears in the title bar of the window or the path to the represented file.
1628    fn ip_set_title(&self, title: NSString) {
1629        unsafe { msg_send![self.m_self(), setTitle: title] }
1630    }
1631
1632    /// A secondary line of text that appears in the title bar of the window.
1633    fn ip_subtitle(&self) -> NSString {
1634        unsafe { NSString::from_id(msg_send![self.m_self(), subtitle]) }
1635    }
1636
1637    /// Sets a secondary line of text that appears in the title bar of the window.
1638    ///
1639    /// # Arguments
1640    ///
1641    /// * `subtitle` - A secondary line of text that appears in the title bar of the window.
1642    fn ip_set_subtitle(&self, subtitle: NSString) {
1643        unsafe { msg_send![self.m_self(), setSubtitle: subtitle] }
1644    }
1645
1646    /// A value that indicates the visibility of the window’s title and title bar buttons.
1647    fn ip_title_visibility(&self) -> NSWindowTitleVisibility {
1648        unsafe { msg_send![self.m_self(), titleVisibility] }
1649    }
1650
1651    /// Sets a value that indicates the visibility of the window’s title and title bar buttons.
1652    ///
1653    /// # Arguments
1654    ///
1655    /// * `title_visibility` - A value that indicates the visibility of the window’s title and title bar buttons.
1656    fn ip_set_title_visibility(&self, title_visibility: NSWindowTitleVisibility) {
1657        unsafe { msg_send![self.m_self(), setTitleVisibility: title_visibility] }
1658    }
1659
1660    /// Sets a given path as the window’s title, formatting it as a file-system path, and records this path as the window’s associated file.
1661    fn im_set_title_with_represented_filename(&self, path: NSString) {
1662        unsafe { msg_send![self.m_self(), setTitleWithRepresentedFilename: path] }
1663    }
1664
1665    /// The path to the file of the window’s represented file.
1666    fn ip_represented_filename(&self) -> NSString {
1667        unsafe { NSString::from_id(msg_send![self.m_self(), representedFilename]) }
1668    }
1669
1670    /// Sets the path to the file of the window’s represented file.
1671    ///
1672    /// # Arguments
1673    ///
1674    /// * `represented_filename` - The path to the file of the window’s represented file.
1675    fn ip_set_represented_filename(&self, represented_filename: NSString) {
1676        unsafe { msg_send![self.m_self(), setRepresentedFilename: represented_filename] }
1677    }
1678
1679    /* Accessing Screen Information
1680     */
1681
1682    /// The screen the window is on.
1683    fn ip_screen(&self) -> NSScreen {
1684        unsafe { NSScreen::from_id(msg_send![self.m_self(), screen]) }
1685    }
1686
1687    /// The deepest screen the window is on (it may be split over several screens).
1688    fn ip_deepest_screen(&self) -> NSScreen {
1689        unsafe { NSScreen::from_id(msg_send![self.m_self(), deepestScreen]) }
1690    }
1691
1692    /// A Boolean value that indicates whether the window context should be updated when the screen profile changes or when the window moves to a different screen.
1693    fn ip_displays_when_screen_profile_changes(&self) -> bool {
1694        unsafe { to_bool(msg_send![self.m_self(), displaysWhenScreenProfileChanges]) }
1695    }
1696
1697    /// A Boolean value that indicates whether the window is movable by clicking and dragging anywhere in its background.
1698    fn ip_movable_by_window_background(&self) -> bool {
1699        unsafe { to_bool(msg_send![self.m_self(), movableByWindowBackground]) }
1700    }
1701
1702    /// Sets a Boolean value that indicates whether the window is movable by clicking and dragging anywhere in its background.
1703    ///
1704    /// # Arguments
1705    ///
1706    /// * `movable_by_window_background` - A Boolean value that indicates whether the window is movable by clicking and dragging anywhere in its background.
1707    fn ip_set_movable_by_window_background(&self, movable_by_window_background: bool) {
1708        unsafe {
1709            msg_send![
1710                self.m_self(),
1711                setMovableByWindowBackground: movable_by_window_background
1712            ]
1713        }
1714    }
1715
1716    /// A Boolean value that indicates whether the window can be dragged by clicking in its title bar or background.
1717    fn ip_movable(&self) -> bool {
1718        unsafe { to_bool(msg_send![self.m_self(), isMovable]) }
1719    }
1720
1721    /// Sets a Boolean value that indicates whether the window can be dragged by clicking in its title bar or background.
1722    ///
1723    /// # Arguments
1724    ///
1725    /// * `movable` - A Boolean value that indicates whether the window can be dragged by clicking in its title bar or background.
1726    fn ip_set_movable(&self, movable: bool) {
1727        unsafe { msg_send![self.m_self(), setMovable: movable] }
1728    }
1729
1730    /// Sets the window’s location to the center of the screen.
1731    fn im_center(&self) {
1732        unsafe { msg_send![self.m_self(), center] }
1733    }
1734
1735    /* Closing Windows
1736     */
1737
1738    /// Simulates the user clicking the close button by momentarily highlighting the button and then closing the window.
1739    fn im_perform_close(&self, sender: id) {
1740        unsafe { msg_send![self.m_self(), performClose: sender] }
1741    }
1742
1743    /// Removes the window from the screen.
1744    fn im_close(&self) {
1745        unsafe { msg_send![self.m_self(), close] }
1746    }
1747
1748    /// A Boolean value that indicates whether the window is released when it receives the close message.
1749    fn ip_released_when_closed(&self) -> bool {
1750        unsafe { to_bool(msg_send![self.m_self(), isReleasedWhenClosed]) }
1751    }
1752
1753    /// Sets a Boolean value that indicates whether the window is released when it receives the close message.
1754    fn ip_set_released_when_closed(&self, released_when_closed: bool) {
1755        unsafe { msg_send![self.m_self(), setReleasedWhenClosed: released_when_closed] }
1756    }
1757
1758    /* Minimizing Windows
1759     */
1760
1761    /// A Boolean value that indicates whether the window is minimized.
1762    fn ip_miniaturized(&self) -> bool {
1763        unsafe { to_bool(msg_send![self.m_self(), isMiniaturized]) }
1764    }
1765
1766    /// Simulates the user clicking the minimize button by momentarily highlighting the button, then minimizing the window.
1767    fn im_perform_miniaturize(&self, sender: id) {
1768        unsafe { msg_send![self.m_self(), performMiniaturize: sender] }
1769    }
1770
1771    /// Removes the window from the screen list and displays the minimized window in the Dock.
1772    fn im_miniaturize(&self, sender: id) {
1773        unsafe { msg_send![self.m_self(), miniaturize: sender] }
1774    }
1775
1776    /// De-minimizes the window.
1777    fn im_deminiaturize(&self, sender: id) {
1778        unsafe { msg_send![self.m_self(), deminiaturize: sender] }
1779    }
1780
1781    /// The custom miniaturized window image of the window.
1782    fn ip_miniwindow_image(&self) -> NSImage {
1783        unsafe { NSImage::from_id(msg_send![self.m_self(), miniwindowImage]) }
1784    }
1785
1786    /// The title displayed in the window’s minimized window.
1787    fn ip_miniwindow_title(&self) -> NSString {
1788        unsafe { NSString::from_id(msg_send![self.m_self(), miniwindowTitle]) }
1789    }
1790
1791    /* Getting the Dock Tile
1792     */
1793
1794    /// The application’s Dock tile.
1795    fn ip_dock_tile(&self) -> NSDockTile {
1796        unsafe { NSDockTile::from_id(msg_send![self.m_self(), dockTile]) }
1797    }
1798
1799    /* Printing Windows
1800     */
1801
1802    /// Runs the Print panel, and if the user chooses an option other than canceling, prints the window (its frame view and all subviews).
1803    fn im_print(&self, sender: id) {
1804        unsafe { msg_send![self.m_self(), print: sender] }
1805    }
1806
1807    /// Returns EPS data that draws the region of the window within a given rectangle.
1808    fn im_data_with_esp_inside_rect(&self, rect: NSRect) -> NSData {
1809        unsafe { NSData::from_id(msg_send![self.m_self(), dataWithEPSInsideRect: rect]) }
1810    }
1811
1812    /// Returns PDF data that draws the region of the window within a given rectangle.
1813    fn im_data_with_pdf_inside_rect(&self, rect: NSRect) -> NSData {
1814        unsafe { NSData::from_id(msg_send![self.m_self(), dataWithPDFInsideRect: rect]) }
1815    }
1816
1817    /* Handling Window Restoration
1818     */
1819
1820    /// A Boolean value indicating whether the window configuration is preserved between application launches.
1821    fn ip_restorable(&self) -> bool {
1822        unsafe { to_bool(msg_send![self.m_self(), isRestorable]) }
1823    }
1824
1825    /// Sets a Boolean value indicating whether the window configuration is preserved between application launches.
1826    ///
1827    /// # Arguments
1828    ///
1829    /// * `restorable` - A Boolean value indicating whether the window configuration is preserved between application launches.
1830    fn ip_set_restorable(&self, restorable: bool) {
1831        unsafe { msg_send![self.m_self(), setRestorable: restorable] }
1832    }
1833
1834    /// Disables snapshot restoration.
1835    fn im_disable_snapshot_restoration(&self) {
1836        unsafe { msg_send![self.m_self(), disableSnapshotRestoration] }
1837    }
1838
1839    /// Enables snapshot restoration.
1840    fn im_enable_snapshot_restoration(&self) {
1841        unsafe { msg_send![self.m_self(), enableSnapshotRestoration] }
1842    }
1843}
1844
1845impl<T> INSWindow for NSWindow<T> {}
1846
1847impl<T> ToId for NSWindow<T> {
1848    fn to_id(self) -> id {
1849        unsafe { msg_send![&*self.ptr, self] }
1850    }
1851}
1852
1853impl<T> FromId for NSWindow<T> {
1854    unsafe fn from_id(id: id) -> Self {
1855        Self {
1856            ptr: ShareId::from_ptr(id),
1857            delegate: None,
1858        }
1859    }
1860}
1861
1862impl<T> Clone for NSWindow<T>
1863where
1864    T: Clone,
1865{
1866    fn clone(&self) -> Self {
1867        Self {
1868            ptr: self.ptr.clone(),
1869            delegate: self.delegate.clone(),
1870        }
1871    }
1872}
1873
1874impl<T> Drop for NSWindow<T> {
1875    fn drop(&mut self) {
1876        if self.delegate.is_some() {
1877            unsafe {
1878                self.ip_set_delegate(NSWindow::from_id(nil));
1879            }
1880        }
1881    }
1882}