Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Implement NSWindowStyleMask as bitflags #160

Merged
merged 4 commits into from Mar 22, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 34 additions & 34 deletions src/appkit.rs
Expand Up @@ -20,7 +20,6 @@ pub use core_graphics::geometry::CGPoint;

pub use self::NSApplicationActivationPolicy::*;
pub use self::NSApplicationActivationOptions::*;
pub use self::NSWindowMask::*;
pub use self::NSBackingStoreType::*;
pub use self::NSOpenGLPixelFormatAttribute::*;
pub use self::NSOpenGLPFAOpenGLProfiles::*;
Expand Down Expand Up @@ -141,22 +140,22 @@ pub enum NSApplicationTerminateReply {
NSTerminateLater = 2,
}

#[repr(u64)]
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum NSWindowMask {
NSBorderlessWindowMask = 0,
NSTitledWindowMask = 1 << 0,
NSClosableWindowMask = 1 << 1,
NSMiniaturizableWindowMask = 1 << 2,
NSResizableWindowMask = 1 << 3,
bitflags! {
pub flags NSWindowMask: NSUInteger {
const NSBorderlessWindowMask = 0,
const NSTitledWindowMask = 1 << 0,
const NSClosableWindowMask = 1 << 1,
const NSMiniaturizableWindowMask = 1 << 2,
const NSResizableWindowMask = 1 << 3,

NSTexturedBackgroundWindowMask = 1 << 8,
const NSTexturedBackgroundWindowMask = 1 << 8,

NSUnifiedTitleAndToolbarWindowMask = 1 << 12,
const NSUnifiedTitleAndToolbarWindowMask = 1 << 12,

NSFullScreenWindowMask = 1 << 14,
const NSFullScreenWindowMask = 1 << 14,

NSFullSizeContentViewWindowMask = 1 << 15
const NSFullSizeContentViewWindowMask = 1 << 15
}
}

#[repr(u64)]
Expand Down Expand Up @@ -799,19 +798,19 @@ pub trait NSWindow {
// Creating Windows
unsafe fn initWithContentRect_styleMask_backing_defer_(self,
rect: NSRect,
style: NSUInteger,
style: NSWindowMask,
backing: NSBackingStoreType,
defer: BOOL) -> id;
unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self,
rect: NSRect,
style: NSUInteger,
style: NSWindowMask,
backing: NSBackingStoreType,
defer: BOOL,
screen: id) -> id;

// Configuring Windows
unsafe fn styleMask(self) -> NSUInteger;
unsafe fn setStyleMask_(self, styleMask: NSUInteger);
unsafe fn styleMask(self) -> NSWindowMask;
unsafe fn setStyleMask_(self, styleMask: NSWindowMask);
unsafe fn toggleFullScreen_(self, sender: id);
unsafe fn worksWhenModal(self) -> BOOL;
unsafe fn alphaValue(self) -> CGFloat;
Expand Down Expand Up @@ -846,9 +845,9 @@ pub trait NSWindow {
// TODO: Accessing Window Information

// Getting Layout Information
unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSUInteger) -> NSRect;
unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSUInteger) -> NSRect;
unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSUInteger) -> CGFloat;
unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSWindowMask) -> NSRect;
unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSWindowMask) -> NSRect;
unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSWindowMask) -> CGFloat;
unsafe fn contentRectForFrameRect_(self, windowFrame: NSRect) -> NSRect;
unsafe fn frameRectForContentRect_(self, windowContent: NSRect) -> NSRect;

Expand Down Expand Up @@ -1025,36 +1024,37 @@ impl NSWindow for id {

unsafe fn initWithContentRect_styleMask_backing_defer_(self,
rect: NSRect,
style: NSUInteger,
style: NSWindowMask,
backing: NSBackingStoreType,
defer: BOOL) -> id {
msg_send![self, initWithContentRect:rect
styleMask:style
styleMask:style.bits
backing:backing as NSUInteger
defer:defer]
}

unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self,
rect: NSRect,
style: NSUInteger,
style: NSWindowMask,
backing: NSBackingStoreType,
defer: BOOL,
screen: id) -> id {
msg_send![self, initWithContentRect:rect
styleMask:style
styleMask:style.bits
backing:backing as NSUInteger
defer:defer
screen:screen]
}

// Configuring Windows

unsafe fn styleMask(self) -> NSUInteger {
msg_send![self, styleMask]
unsafe fn styleMask(self) -> NSWindowMask {
let styleMask = msg_send![self, styleMask];
styleMask
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that this works as written. Doesn't this need to call NSWindowMask::from_bits or from_bits_truncate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from_bits_truncate would add a nice validity check. I'll add that in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also renamed NSWindowMask to NSWindowStyleMask to match AppKit.

}

unsafe fn setStyleMask_(self, styleMask: NSUInteger) {
msg_send![self, setStyleMask:styleMask]
unsafe fn setStyleMask_(self, styleMask: NSWindowMask) {
msg_send![self, setStyleMask:styleMask.bits]
}

unsafe fn toggleFullScreen_(self, sender: id) {
Expand Down Expand Up @@ -1176,16 +1176,16 @@ impl NSWindow for id {

// Getting Layout Information

unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSUInteger) -> NSRect {
msg_send![self, contentRectForFrameRect:windowFrame styleMask:windowStyle]
unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSWindowMask) -> NSRect {
msg_send![self, contentRectForFrameRect:windowFrame styleMask:windowStyle.bits]
}

unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSUInteger) -> NSRect {
msg_send![self, frameRectForContentRect:windowContentRect styleMask:windowStyle]
unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSWindowMask) -> NSRect {
msg_send![self, frameRectForContentRect:windowContentRect styleMask:windowStyle.bits]
}

unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSUInteger) -> CGFloat {
msg_send![self, minFrameWidthWithTitle:windowTitle styleMask:windowStyle]
unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSWindowMask) -> CGFloat {
msg_send![self, minFrameWidthWithTitle:windowTitle styleMask:windowStyle.bits]
}

unsafe fn contentRectForFrameRect_(self, windowFrame: NSRect) -> NSRect {
Expand Down