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#[derive(Debug)]
37pub struct WindowConfig {
38 pub style: UInt,
40
41 pub initial_dimensions: NSRect,
43
44 pub defer: bool,
49
50 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 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 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 pub fn set_toolbar_style(&mut self, style: NSWindowToolbarStyle) {
106 self.toolbar_style = style;
107 }
108}
109
110#[derive(Debug)]
113pub struct NSWindow<T = ()> {
114 pub ptr: ShareId<Object>,
116
117 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 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 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 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 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 pub fn set_title_visibility(&mut self, visibility: NSWindowTitleVisibility) {
246 self.ip_set_title_visibility(visibility)
247 }
248
249 pub fn set_movable_by_background(&mut self, movable: bool) {
251 self.ip_set_movable_by_window_background(movable)
252 }
253
254 pub fn set_titlebar_appears_transparent(&mut self, transparent: bool) {
256 self.ip_set_titlebar_appears_transparent(transparent)
257 }
258
259 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 pub fn set_content_size(&self, size: NSSize) {
269 self.im_set_content_size(size);
270 }
271
272 pub fn set_minimum_content_size(&self, size: NSSize) {
274 self.ip_set_content_min_size(size);
275 }
276
277 pub fn set_maximum_content_size(&self, size: NSSize) {
279 self.ip_set_content_max_size(size);
280 }
281
282 pub fn set_minimum_size<F: Into<f64>>(&self, size: NSSize) {
284 self.ip_set_min_size(size)
285 }
286
287 pub fn toggle_toolbar_shown(&self) {
289 self.ip_toggle_toolbar_shown(nil)
290 }
291
292 pub fn set_shows_toolbar_button(&self, shows: bool) {
294 self.ip_set_shows_toolbar_button(shows);
295 }
296
297 pub fn close(&self) {
299 self.im_close()
300 }
301
302 pub fn toggle_full_screen(&self, sender: id) {
304 self.im_toggle_full_screen(sender)
305 }
306
307 pub fn is_opaque(&self) -> bool {
309 self.ip_is_opaque()
310 }
311
312 pub fn miniaturized(&self) -> bool {
314 self.ip_miniaturized()
315 }
316
317 pub fn miniaturize(&self, sender: id) {
319 self.im_miniaturize(sender)
320 }
321
322 pub fn deminiaturize(&self, sender: id) {
324 self.im_deminiaturize(sender)
325 }
326
327 pub fn print(&self, sender: id) {
329 self.im_print(sender)
330 }
331
332 pub fn is_on_active_space(&self) -> bool {
334 self.ip_is_on_active_space()
335 }
336
337 pub fn is_visible(&self) -> bool {
339 self.ip_visible()
340 }
341
342 pub fn is_key_window(&self) -> bool {
344 self.ip_key_window()
345 }
346
347 pub fn can_become_key_window(&self) -> bool {
349 self.ip_can_become_key_window()
350 }
351
352 pub fn make_key_window(&self) {
354 self.im_make_key_window()
355 }
356
357 pub fn make_key_and_order_front(&self, sender: id) {
359 self.im_make_key_and_order_front(sender)
360 }
361
362 pub fn main_window(&self) -> bool {
364 self.ip_main_window()
365 }
366
367 pub fn can_become_main_window(&self) -> bool {
369 self.ip_can_become_main_window()
370 }
371
372 pub fn set_excluded_from_windows_menu(&self, excluded: bool) {
374 self.ip_set_excluded_from_windows_menu(excluded)
375 }
376
377 pub fn set_titlebar_separator_style(&self, style: NSTitlebarSeparatorStyle) {
379 self.ip_set_titlebar_separator_style(style)
380 }
381
382 pub fn backing_scale_factor(&self) -> f64 {
384 self.ip_backing_scale_factor()
385 }
386
387 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 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
420pub trait INSWindow: INSResponder {
422 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 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 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 fn ip_delegate(&self) -> id {
490 unsafe { msg_send![self.m_self(), delegate] }
491 }
492
493 fn ip_set_delegate(&self, delegate: NSWindow) {
499 unsafe { msg_send![self.m_self(), setDelegate: delegate] }
500 }
501
502 fn ip_content_view_controller(&self) -> NSViewController {
507 unsafe { msg_send![self.m_self(), contentViewController] }
508 }
509
510 fn ip_style_mask(&self) -> NSWindowStyleMask {
515 unsafe { msg_send![self.m_self(), styleMask] }
516 }
517
518 fn ip_set_style_mask(&mut self, style_mask: NSWindowStyleMask) {
524 unsafe { msg_send![self.m_self(), setStyleMask: style_mask] }
525 }
526
527 fn im_toggle_full_screen(&self, sender: id) {
529 unsafe { msg_send![self.m_self(), toggleFullScreen: sender] }
530 }
531
532 fn ip_works_when_modal(&self) -> bool {
534 unsafe { to_bool(msg_send![self.m_self(), worksWhenModal]) }
535 }
536
537 fn ip_alpha_value(&self) -> CGFloat {
539 unsafe { msg_send![self.m_self(), alphaValue] }
540 }
541
542 fn ip_set_alpha_value(&mut self, value: CGFloat) {
548 unsafe { msg_send![self.m_self(), setAlphaValue: value] }
549 }
550
551 fn ip_background_color(&self) -> NSColor {
553 unsafe { NSColor::from_id(msg_send![self.m_self(), backgroundColor]) }
554 }
555
556 fn ip_set_background_color(&mut self, color: NSColor) {
562 unsafe { msg_send![self.m_self(), setBackgroundColor: color] }
563 }
564
565 fn ip_color_space(&self) -> NSColorSpace {
567 unsafe { NSColorSpace::from_id(msg_send![self.m_self(), colorSpace]) }
568 }
569
570 fn ip_set_color_space(&mut self, color_space: NSColorSpace) {
576 unsafe { msg_send![self.m_self(), setColorSpace: color_space] }
577 }
578
579 fn im_set_dynamic_depth_limit(&self, flag: bool) {
581 unsafe { msg_send![self.m_self(), setDynamicDepthLimit: flag] }
582 }
583
584 fn ip_can_hide(&self) -> bool {
586 unsafe { to_bool(msg_send![self.m_self(), canHide]) }
587 }
588
589 fn ip_set_can_hide(&mut self, flag: bool) {
595 unsafe { msg_send![self.m_self(), setCanHide: flag] }
596 }
597
598 fn ip_is_on_active_space(&self) -> bool {
600 unsafe { to_bool(msg_send![self.m_self(), isOnActiveSpace]) }
601 }
602
603 fn ip_hides_on_deactivate(&self) -> bool {
605 unsafe { to_bool(msg_send![self.m_self(), hidesOnDeactivate]) }
606 }
607
608 fn ip_set_hides_on_deactivate(&mut self, flag: bool) {
614 unsafe { msg_send![self.m_self(), setHidesOnDeactivate: flag] }
615 }
616
617 fn ip_collection_behavior(&self) -> NSWindowCollectionBehavior {
619 unsafe { msg_send![self.m_self(), collectionBehavior] }
620 }
621
622 fn ip_is_opaque(&self) -> bool {
624 unsafe { to_bool(msg_send![self.m_self(), isOpaque]) }
625 }
626
627 fn ip_set_opaque(&mut self, flag: bool) {
633 unsafe { msg_send![self.m_self(), setOpaque: flag] }
634 }
635
636 fn ip_has_shadow(&self) -> bool {
638 unsafe { to_bool(msg_send![self.m_self(), hasShadow]) }
639 }
640
641 fn ip_set_has_shadow(&mut self, flag: bool) {
647 unsafe { msg_send![self.m_self(), setHasShadow: flag] }
648 }
649
650 fn im_invalidate_shadow(&self) {
652 unsafe { msg_send![self.m_self(), invalidateShadow] }
653 }
654
655 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 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 fn im_content_border_thickness_for_edge(&self, edge: NSRectEdge) -> CGFloat {
687 unsafe { msg_send![self.m_self(), contentBorderThicknessForEdge: edge] }
688 }
689
690 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 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 fn ip_appearance_source(&self) -> id {
712 unsafe { msg_send![self.m_self(), appearanceSource] }
713 }
714
715 fn ip_depth_limit(&self) -> NSWindowDepth {
720 unsafe { msg_send![self.m_self(), depthLimit] }
721 }
722
723 fn ip_set_depth_limit(&mut self, depth: NSWindowDepth) {
729 unsafe { msg_send![self.m_self(), setDepthLimit: depth] }
730 }
731
732 fn ip_has_dynamic_depth_limit(&self) -> bool {
734 unsafe { to_bool(msg_send![self.m_self(), hasDynamicDepthLimit]) }
735 }
736
737 fn tp_default_depth_limit() -> NSWindowDepth {
739 unsafe { msg_send![Self::m_class(), defaultDepthLimit] }
740 }
741
742 fn ip_window_number(&self) -> Int {
744 unsafe { msg_send![self.m_self(), windowNumber] }
745 }
746
747 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 fn ip_device_description(&self) -> NSDictionary<NSDeviceDescriptionKey, id> {
759 unsafe { NSDictionary::from_id(msg_send![self.m_self(), deviceDescription]) }
760 }
761
762 fn ip_can_become_visible_without_login(&self) -> bool {
764 unsafe { to_bool(msg_send![self.m_self(), canBecomeVisibleWithoutLogin]) }
765 }
766
767 fn ip_sharing_type(&self) -> NSWindowSharingType {
769 unsafe { msg_send![self.m_self(), sharingType] }
770 }
771
772 fn ip_backing_type(&self) -> NSBackingStoreType {
774 unsafe { msg_send![self.m_self(), backingType] }
775 }
776
777 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 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 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 fn im_content_rect_for_frame_rect(&self, frame: NSRect) -> NSRect {
822 unsafe { msg_send![self.m_self(), contentRectForFrameRect: frame] }
823 }
824
825 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 fn ip_attached_sheet(&self) -> NSWindow {
838 unsafe { NSWindow::from_id(msg_send![self.m_self(), attachedSheet]) }
839 }
840
841 fn ip_sheet(&mut self) -> bool {
843 unsafe { to_bool(msg_send![self.m_self(), isSheet]) }
844 }
845
846 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 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 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 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 fn ip_sheet_parent(&self) -> NSWindow {
900 unsafe { NSWindow::from_id(msg_send![self.m_self(), sheetParent]) }
901 }
902
903 fn ip_sheets(&self) -> NSArray<NSWindow> {
905 unsafe { NSArray::from_id(msg_send![self.m_self(), sheets]) }
906 }
907
908 fn ip_frame(&self) -> NSRect {
913 unsafe { msg_send![self.m_self(), frame] }
914 }
915
916 fn im_set_frame_origin(&self, point: NSPoint) {
922 unsafe { msg_send![self.m_self(), setFrameOrigin: point] }
923 }
924
925 fn im_set_frame_top_left_point(&self, point: NSPoint) {
931 unsafe { msg_send![self.m_self(), setFrameTopLeftPoint: point] }
932 }
933
934 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 fn im_cascade_top_left_from_point(&self, point: NSPoint) {
950 unsafe { msg_send![self.m_self(), cascadeTopLeftFromPoint: point] }
951 }
952
953 fn im_set_frame_display(&self, frame: NSRect, flag: bool) {
960 unsafe { msg_send![self.m_self(), setFrame: frame display: flag] }
961 }
962
963 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 fn im_animation_resize_time(&self, frame: NSRect) -> NSTimeInterval {
976 unsafe { msg_send![self.m_self(), animationResizeTime: frame] }
977 }
978
979 fn ip_aspect_ratio(&self) -> NSSize {
981 unsafe { msg_send![self.m_self(), aspectRatio] }
982 }
983
984 fn ip_set_aspect_ratio(&self, ratio: NSSize) {
990 unsafe { msg_send![self.m_self(), setAspectRatio: ratio] }
991 }
992
993 fn ip_min_size(&self) -> NSSize {
995 unsafe { msg_send![self.m_self(), minSize] }
996 }
997
998 fn ip_set_min_size(&self, size: NSSize) {
1004 unsafe { msg_send![self.m_self(), setMinSize: size] }
1005 }
1006
1007 fn ip_max_size(&self) -> NSSize {
1009 unsafe { msg_send![self.m_self(), maxSize] }
1010 }
1011
1012 fn ip_set_max_size(&self, size: NSSize) {
1018 unsafe { msg_send![self.m_self(), setMaxSize: size] }
1019 }
1020
1021 fn ip_zoomed(&self) -> bool {
1023 unsafe { msg_send![self.m_self(), isZoomed] }
1024 }
1025
1026 fn im_perform_zoom(&self, sender: id) {
1028 unsafe { msg_send![self.m_self(), performZoom: sender] }
1029 }
1030
1031 fn im_zoom(&self, sender: id) {
1033 unsafe { msg_send![self.m_self(), zoom: sender] }
1034 }
1035
1036 fn ip_resize_increments(&self) -> NSSize {
1038 unsafe { msg_send![self.m_self(), resizeIncrements] }
1039 }
1040
1041 fn ip_set_resize_increments(&self, increments: NSSize) {
1047 unsafe { msg_send![self.m_self(), setResizeIncrements: increments] }
1048 }
1049
1050 fn ip_preserves_content_during_live_resize(&self) -> bool {
1052 unsafe { msg_send![self.m_self(), preservesContentDuringLiveResize] }
1053 }
1054
1055 fn ip_set_preserves_content_during_live_resize(&self, flag: bool) {
1061 unsafe { msg_send![self.m_self(), setPreservesContentDuringLiveResize: flag] }
1062 }
1063
1064 fn ip_in_live_resize(&self) -> bool {
1066 unsafe { msg_send![self.m_self(), inLiveResize] }
1067 }
1068
1069 fn ip_set_in_live_resize(&self, flag: bool) {
1075 unsafe { msg_send![self.m_self(), setInLiveResize: flag] }
1076 }
1077
1078 fn ip_content_aspect_ratio(&self) -> NSSize {
1083 unsafe { msg_send![self.m_self(), contentAspectRatio] }
1084 }
1085
1086 fn ip_set_content_aspect_ratio(&self, size: NSSize) {
1092 unsafe { msg_send![self.m_self(), setContentAspectRatio: size] }
1093 }
1094
1095 fn ip_content_min_size(&self) -> NSSize {
1097 unsafe { msg_send![self.m_self(), contentMinSize] }
1098 }
1099
1100 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 fn im_set_content_size(&self, size: NSSize) {
1115 unsafe { msg_send![self.m_self(), setContentSize: size] }
1116 }
1117
1118 fn ip_content_max_size(&self) -> NSSize {
1120 unsafe { msg_send![self.m_self(), contentMaxSize] }
1121 }
1122
1123 fn ip_set_content_max_size(&self, size: NSSize) {
1129 unsafe { msg_send![self.m_self(), setContentMaxSize: size] }
1130 }
1131
1132 fn ip_content_resize_increments(&self) -> NSSize {
1134 unsafe { msg_send![self.m_self(), contentResizeIncrements] }
1135 }
1136
1137 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 fn ip_content_layout_guide(&self) -> id {
1153 unsafe { msg_send![self.m_self(), contentLayoutGuide] }
1154 }
1155
1156 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 fn ip_content_layout_rect(&self) -> NSRect {
1167 unsafe { msg_send![self.m_self(), contentLayoutRect] }
1168 }
1169
1170 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 fn ip_full_screen_tile_size(&self) -> NSSize {
1181 unsafe { msg_send![self.m_self(), fullScreenTileSize] }
1182 }
1183
1184 fn ip_set_full_screen_tile_size(&self, size: NSSize) {
1190 unsafe { msg_send![self.m_self(), setFullScreenTileSize: size] }
1191 }
1192
1193 fn ip_full_screen_tile_content_size(&self) -> NSSize {
1195 unsafe { msg_send![self.m_self(), fullScreenTileContentSize] }
1196 }
1197
1198 fn ip_set_full_screen_tile_content_size(&self, size: NSSize) {
1204 unsafe { msg_send![self.m_self(), setFullScreenTileContentSize: size] }
1205 }
1206
1207 fn im_order_out(&self, sender: id) {
1212 unsafe { msg_send![self.m_self(), orderOut: sender] }
1213 }
1214
1215 fn im_order_back(&self, sender: id) {
1217 unsafe { msg_send![self.m_self(), orderBack: sender] }
1218 }
1219
1220 fn im_order_front(&self, sender: id) {
1222 unsafe { msg_send![self.m_self(), orderFront: sender] }
1223 }
1224
1225 fn im_order_front_regardless(&self) {
1227 unsafe { msg_send![self.m_self(), orderFrontRegardless] }
1228 }
1229
1230 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 fn ip_window_level(&self) -> NSWindowLevel {
1237 unsafe { msg_send![self.m_self(), windowLevel] }
1238 }
1239
1240 fn ip_set_window_level(&self, level: NSWindowLevel) {
1246 unsafe { msg_send![self.m_self(), setWindowLevel: level] }
1247 }
1248
1249 fn ip_visible(&self) -> bool {
1254 unsafe { msg_send![self.m_self(), isVisible] }
1255 }
1256
1257 fn ip_occlusion_state(&self) -> NSWindowOcclusionState {
1259 unsafe { msg_send![self.m_self(), occlusionState] }
1260 }
1261
1262 fn tm_remove_frame_using_name(name: &NSWindowFrameAutosaveName) {
1271 unsafe { msg_send![Self::m_class(), removeFrameUsingName: name] }
1272 }
1273
1274 fn im_set_frame_using_name(&self, name: NSWindowFrameAutosaveName) -> bool {
1276 unsafe { msg_send![self.m_self(), setFrameUsingName: name] }
1277 }
1278
1279 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 fn im_save_frame_using_name(&self, name: NSWindowFrameAutosaveName) {
1286 unsafe { msg_send![self.m_self(), saveFrameUsingName: name] }
1287 }
1288
1289 fn im_set_frame_autosave_name(&self, name: NSWindowFrameAutosaveName) -> bool {
1291 unsafe { to_bool(msg_send![self.m_self(), setFrameAutosaveName: name]) }
1292 }
1293
1294 fn ip_frame_autosave_name(&self) -> NSWindowFrameAutosaveName {
1296 unsafe { msg_send![self.m_self(), frameAutosaveName] }
1297 }
1298
1299 fn ip_string_with_saved_frame(&self) -> NSWindowPersistableFrameDescriptor {
1301 unsafe { msg_send![self.m_self(), stringWithSavedFrame] }
1302 }
1303
1304 fn im_set_frame_from_string(&self, string: NSWindowPersistableFrameDescriptor) {
1306 unsafe { msg_send![self.m_self(), setFrameFromString: string] }
1307 }
1308
1309 fn ip_key_window(&self) -> bool {
1314 unsafe { msg_send![self.m_self(), isKeyWindow] }
1315 }
1316
1317 fn ip_can_become_key_window(&self) -> bool {
1319 unsafe { msg_send![self.m_self(), canBecomeKeyWindow] }
1320 }
1321
1322 fn im_make_key_window(&self) {
1324 unsafe { msg_send![self.m_self(), makeKeyWindow] }
1325 }
1326
1327 fn im_make_key_and_order_front(&self, sender: id) {
1329 unsafe { msg_send![self.m_self(), makeKeyAndOrderFront: sender] }
1330 }
1331
1332 fn im_become_key_window(&self) {
1334 unsafe { msg_send![self.m_self(), becomeKeyWindow] }
1335 }
1336
1337 fn im_resign_key_window(&self) {
1339 unsafe { msg_send![self.m_self(), resignKeyWindow] }
1340 }
1341
1342 fn ip_main_window(&self) -> bool {
1347 unsafe { msg_send![self.m_self(), isMainWindow] }
1348 }
1349
1350 fn ip_can_become_main_window(&self) -> bool {
1352 unsafe { msg_send![self.m_self(), canBecomeMainWindow] }
1353 }
1354
1355 fn im_make_main_window(&self) {
1357 unsafe { msg_send![self.m_self(), makeMainWindow] }
1358 }
1359
1360 fn im_become_main_window(&self) {
1362 unsafe { msg_send![self.m_self(), becomeMainWindow] }
1363 }
1364
1365 fn im_resign_main_window(&self) {
1367 unsafe { msg_send![self.m_self(), resignMainWindow] }
1368 }
1369
1370 fn ip_toolbar(&self) -> NSToolbar {
1372 unsafe { msg_send![self.m_self(), toolbar] }
1373 }
1374
1375 fn ip_set_toolbar(&self, toolbar: NSToolbar) {
1381 unsafe { msg_send![self.m_self(), setToolbar: toolbar] }
1382 }
1383
1384 fn ip_toggle_toolbar_shown(&self, sender: id) {
1386 unsafe { msg_send![self.m_self(), toggleToolbarShown: sender] }
1387 }
1388
1389 fn ip_run_toolbar_customization_palette(&self, sender: id) {
1391 unsafe { msg_send![self.m_self(), runToolbarCustomizationPalette: sender] }
1392 }
1393
1394 fn ip_child_windows(&self) -> id {
1399 unsafe { msg_send![self.m_self(), childWindows] }
1400 }
1401
1402 fn add_child_window_ordered(&self, child: id, order: NSWindowOrderingMode) {
1404 unsafe { msg_send![self.m_self(), addChildWindow: child ordered: order] }
1405 }
1406
1407 fn remove_child_window(&self, child: id) {
1409 unsafe { msg_send![self.m_self(), removeChildWindow: child] }
1410 }
1411
1412 fn ip_parent_window(&self) -> id {
1414 unsafe { msg_send![self.m_self(), parentWindow] }
1415 }
1416
1417 fn ip_excluded_from_windows_menu(&self) -> bool {
1422 unsafe { msg_send![self.m_self(), isExcludedFromWindowsMenu] }
1423 }
1424
1425 fn ip_set_excluded_from_windows_menu(&self, flag: bool) {
1431 unsafe { msg_send![self.m_self(), setExcludedFromWindowsMenu: flag] }
1432 }
1433
1434 fn ip_are_cursor_rects_enabled(&self) -> bool {
1439 unsafe { msg_send![self.m_self(), areCursorRectsEnabled] }
1440 }
1441
1442 fn im_enable_cursor_rects(&self) {
1444 unsafe { msg_send![self.m_self(), enableCursorRects] }
1445 }
1446
1447 fn im_disable_cursor_rects(&self) {
1449 unsafe { msg_send![self.m_self(), disableCursorRects] }
1450 }
1451
1452 fn im_discard_cursor_rects(&self, view: id) {
1454 unsafe { msg_send![self.m_self(), discardCursorRectsForView: view] }
1455 }
1456
1457 fn im_reset_cursor_rects(&self) {
1459 unsafe { msg_send![self.m_self(), resetCursorRects] }
1460 }
1461
1462 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 fn ip_standard_window_button(&self, b: NSWindowButton) -> NSButton {
1480 unsafe { msg_send![self.m_self(), standardWindowButton: b] }
1481 }
1482
1483 fn ip_shows_toolbar_button(&self) -> bool {
1485 unsafe { msg_send![self.m_self(), showsToolbarButton] }
1486 }
1487
1488 fn ip_set_shows_toolbar_button(&self, flag: bool) {
1494 unsafe { msg_send![self.m_self(), setShowsToolbarButton: flag] }
1495 }
1496
1497 fn ip_titlebar_appears_transparent(&self) -> bool {
1499 unsafe { msg_send![self.m_self(), titlebarAppearsTransparent] }
1500 }
1501
1502 fn ip_set_titlebar_appears_transparent(&self, flag: bool) {
1508 unsafe { msg_send![self.m_self(), setTitlebarAppearsTransparent: flag] }
1509 }
1510
1511 fn ip_toolbar_style(&self) -> NSWindowToolbarStyle {
1513 unsafe { msg_send![self.m_self(), toolbarStyle] }
1514 }
1515
1516 fn ip_set_toolbar_style(&self, style: NSWindowToolbarStyle) {
1522 unsafe { msg_send![self.m_self(), setToolbarStyle: style] }
1523 }
1524
1525 fn ip_titlebar_separator_style(&self) -> NSTitlebarSeparatorStyle {
1527 unsafe { msg_send![self.m_self(), titlebarSeparatorStyle] }
1528 }
1529
1530 fn ip_set_titlebar_separator_style(&self, style: NSTitlebarSeparatorStyle) {
1536 unsafe { msg_send![self.m_self(), setTitlebarSeparatorStyle: style] }
1537 }
1538
1539 fn ip_titlebar_layout_direction(&self) -> NSUserInterfaceLayoutDirection {
1541 unsafe { msg_send![self.m_self(), titlebarLayoutDirection] }
1542 }
1543
1544 fn tp_allows_automatic_window_tabbing() -> bool {
1549 unsafe { to_bool(msg_send![Self::m_class(), allowsAutomaticWindowTabbing]) }
1550 }
1551
1552 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 fn ip_backing_scale_factor(&self) -> CGFloat {
1567 unsafe { msg_send![self.m_self(), backingScaleFactor] }
1568 }
1569
1570 fn im_backing_aligned_rect_options(&self, options: NSAlignmentOptions) -> NSRect {
1572 unsafe { msg_send![self.m_self(), backingAlignedRect: options] }
1573 }
1574
1575 fn im_convert_rect_from_backing(&self, rect: NSRect) -> NSRect {
1577 unsafe { msg_send![self.m_self(), convertRectFromBacking: rect] }
1578 }
1579
1580 fn im_convert_rect_from_screen(&self, rect: NSRect) -> NSRect {
1582 unsafe { msg_send![self.m_self(), convertRectFromScreen: rect] }
1583 }
1584
1585 fn im_convert_point_from_backing(&self, point: NSPoint) -> NSPoint {
1587 unsafe { msg_send![self.m_self(), convertPointFromBacking: point] }
1588 }
1589
1590 fn im_convert_point_from_screen(&self, point: NSPoint) -> NSPoint {
1592 unsafe { msg_send![self.m_self(), convertPointFromScreen: point] }
1593 }
1594
1595 fn im_convert_rect_to_backing(&self, rect: NSRect) -> NSRect {
1597 unsafe { msg_send![self.m_self(), convertRectToBacking: rect] }
1598 }
1599
1600 fn im_convert_rect_to_screen(&self, rect: NSRect) -> NSRect {
1602 unsafe { msg_send![self.m_self(), convertRectToScreen: rect] }
1603 }
1604
1605 fn im_convert_point_to_backing(&self, point: NSPoint) -> NSPoint {
1607 unsafe { msg_send![self.m_self(), convertPointToBacking: point] }
1608 }
1609
1610 fn im_convert_point_to_screen(&self, point: NSPoint) -> NSPoint {
1612 unsafe { msg_send![self.m_self(), convertPointToScreen: point] }
1613 }
1614
1615 fn ip_title(&self) -> NSString {
1620 unsafe { NSString::from_id(msg_send![self.m_self(), title]) }
1621 }
1622
1623 fn ip_set_title(&self, title: NSString) {
1629 unsafe { msg_send![self.m_self(), setTitle: title] }
1630 }
1631
1632 fn ip_subtitle(&self) -> NSString {
1634 unsafe { NSString::from_id(msg_send![self.m_self(), subtitle]) }
1635 }
1636
1637 fn ip_set_subtitle(&self, subtitle: NSString) {
1643 unsafe { msg_send![self.m_self(), setSubtitle: subtitle] }
1644 }
1645
1646 fn ip_title_visibility(&self) -> NSWindowTitleVisibility {
1648 unsafe { msg_send![self.m_self(), titleVisibility] }
1649 }
1650
1651 fn ip_set_title_visibility(&self, title_visibility: NSWindowTitleVisibility) {
1657 unsafe { msg_send![self.m_self(), setTitleVisibility: title_visibility] }
1658 }
1659
1660 fn im_set_title_with_represented_filename(&self, path: NSString) {
1662 unsafe { msg_send![self.m_self(), setTitleWithRepresentedFilename: path] }
1663 }
1664
1665 fn ip_represented_filename(&self) -> NSString {
1667 unsafe { NSString::from_id(msg_send![self.m_self(), representedFilename]) }
1668 }
1669
1670 fn ip_set_represented_filename(&self, represented_filename: NSString) {
1676 unsafe { msg_send![self.m_self(), setRepresentedFilename: represented_filename] }
1677 }
1678
1679 fn ip_screen(&self) -> NSScreen {
1684 unsafe { NSScreen::from_id(msg_send![self.m_self(), screen]) }
1685 }
1686
1687 fn ip_deepest_screen(&self) -> NSScreen {
1689 unsafe { NSScreen::from_id(msg_send![self.m_self(), deepestScreen]) }
1690 }
1691
1692 fn ip_displays_when_screen_profile_changes(&self) -> bool {
1694 unsafe { to_bool(msg_send![self.m_self(), displaysWhenScreenProfileChanges]) }
1695 }
1696
1697 fn ip_movable_by_window_background(&self) -> bool {
1699 unsafe { to_bool(msg_send![self.m_self(), movableByWindowBackground]) }
1700 }
1701
1702 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 fn ip_movable(&self) -> bool {
1718 unsafe { to_bool(msg_send![self.m_self(), isMovable]) }
1719 }
1720
1721 fn ip_set_movable(&self, movable: bool) {
1727 unsafe { msg_send![self.m_self(), setMovable: movable] }
1728 }
1729
1730 fn im_center(&self) {
1732 unsafe { msg_send![self.m_self(), center] }
1733 }
1734
1735 fn im_perform_close(&self, sender: id) {
1740 unsafe { msg_send![self.m_self(), performClose: sender] }
1741 }
1742
1743 fn im_close(&self) {
1745 unsafe { msg_send![self.m_self(), close] }
1746 }
1747
1748 fn ip_released_when_closed(&self) -> bool {
1750 unsafe { to_bool(msg_send![self.m_self(), isReleasedWhenClosed]) }
1751 }
1752
1753 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 fn ip_miniaturized(&self) -> bool {
1763 unsafe { to_bool(msg_send![self.m_self(), isMiniaturized]) }
1764 }
1765
1766 fn im_perform_miniaturize(&self, sender: id) {
1768 unsafe { msg_send![self.m_self(), performMiniaturize: sender] }
1769 }
1770
1771 fn im_miniaturize(&self, sender: id) {
1773 unsafe { msg_send![self.m_self(), miniaturize: sender] }
1774 }
1775
1776 fn im_deminiaturize(&self, sender: id) {
1778 unsafe { msg_send![self.m_self(), deminiaturize: sender] }
1779 }
1780
1781 fn ip_miniwindow_image(&self) -> NSImage {
1783 unsafe { NSImage::from_id(msg_send![self.m_self(), miniwindowImage]) }
1784 }
1785
1786 fn ip_miniwindow_title(&self) -> NSString {
1788 unsafe { NSString::from_id(msg_send![self.m_self(), miniwindowTitle]) }
1789 }
1790
1791 fn ip_dock_tile(&self) -> NSDockTile {
1796 unsafe { NSDockTile::from_id(msg_send![self.m_self(), dockTile]) }
1797 }
1798
1799 fn im_print(&self, sender: id) {
1804 unsafe { msg_send![self.m_self(), print: sender] }
1805 }
1806
1807 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 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 fn ip_restorable(&self) -> bool {
1822 unsafe { to_bool(msg_send![self.m_self(), isRestorable]) }
1823 }
1824
1825 fn ip_set_restorable(&self, restorable: bool) {
1831 unsafe { msg_send![self.m_self(), setRestorable: restorable] }
1832 }
1833
1834 fn im_disable_snapshot_restoration(&self) {
1836 unsafe { msg_send![self.m_self(), disableSnapshotRestoration] }
1837 }
1838
1839 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}