diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index eb18857..79ce1c3 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -14,7 +14,7 @@ default-target = "x86_64-apple-darwin" [dependencies] block = "0.1" -bitflags = "1.0" +bitflags = "2" libc = "0.2" core-foundation = { default-features = false, path = "../core-foundation", version = "0.10" } core-graphics-types = { default-features = false, path = "../core-graphics-types", version = "0.2" } diff --git a/cocoa-foundation/src/foundation.rs b/cocoa-foundation/src/foundation.rs index 881b2c6..6fcc2a9 100644 --- a/cocoa-foundation/src/foundation.rs +++ b/cocoa-foundation/src/foundation.rs @@ -613,6 +613,7 @@ impl NSDictionary for id { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSEnumerationOptions: libc::c_ulonglong { const NSEnumerationConcurrent = 1 << 0; const NSEnumerationReverse = 1 << 1; @@ -792,6 +793,7 @@ impl NSRunLoop for id { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSURLBookmarkCreationOptions: NSUInteger { const NSURLBookmarkCreationPreferFileIDResolution = 1 << 8; const NSURLBookmarkCreationMinimalBookmark = 1 << 9; @@ -804,6 +806,7 @@ bitflags! { pub type NSURLBookmarkFileCreationOptions = NSURLBookmarkCreationOptions; bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSURLBookmarkResolutionOptions: NSUInteger { const NSURLBookmarkResolutionWithoutUI = 1 << 8; const NSURLBookmarkResolutionWithoutMounting = 1 << 9; @@ -1590,6 +1593,7 @@ impl NSData for id { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSDataReadingOptions: libc::c_ulonglong { const NSDataReadingMappedIfSafe = 1 << 0; const NSDataReadingUncached = 1 << 1; @@ -1598,6 +1602,7 @@ bitflags! { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSDataBase64EncodingOptions: libc::c_ulonglong { const NSDataBase64Encoding64CharacterLineLength = 1 << 0; const NSDataBase64Encoding76CharacterLineLength = 1 << 1; @@ -1607,12 +1612,14 @@ bitflags! { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSDataBase64DecodingOptions: libc::c_ulonglong { const NSDataBase64DecodingIgnoreUnknownCharacters = 1 << 0; } } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSDataWritingOptions: libc::c_ulonglong { const NSDataWritingAtomic = 1 << 0; const NSDataWritingWithoutOverwriting = 1 << 1; @@ -1620,6 +1627,7 @@ bitflags! { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSDataSearchOptions: libc::c_ulonglong { const NSDataSearchBackwards = 1 << 0; const NSDataSearchAnchored = 1 << 1; diff --git a/cocoa/Cargo.toml b/cocoa/Cargo.toml index 10df0cf..70ead63 100644 --- a/cocoa/Cargo.toml +++ b/cocoa/Cargo.toml @@ -14,7 +14,7 @@ default-target = "x86_64-apple-darwin" [dependencies] block = "0.1" -bitflags = "1.0" +bitflags = "2" libc = "0.2" cocoa-foundation = { default-features = false, path = "../cocoa-foundation", version = "0.2" } core-foundation = { default-features = false, path = "../core-foundation", version = "0.10" } diff --git a/cocoa/src/appkit.rs b/cocoa/src/appkit.rs index dca1baf..72d8da2 100644 --- a/cocoa/src/appkit.rs +++ b/cocoa/src/appkit.rs @@ -184,6 +184,7 @@ pub enum NSApplicationTerminateReply { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSApplicationPresentationOptions : NSUInteger { const NSApplicationPresentationDefault = 0; const NSApplicationPresentationAutoHideDock = 1 << 0; @@ -202,6 +203,7 @@ bitflags! { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSWindowStyleMask: NSUInteger { const NSBorderlessWindowMask = 0; const NSTitledWindowMask = 1 << 0; @@ -251,6 +253,7 @@ pub enum NSWindowToolbarStyle { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSWindowOrderingMode: NSInteger { const NSWindowAbove = 1; const NSWindowBelow = -1; @@ -259,6 +262,7 @@ bitflags! { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSAlignmentOptions: libc::c_ulonglong { const NSAlignMinXInward = 1 << 0; const NSAlignMinYInward = 1 << 1; @@ -279,18 +283,18 @@ bitflags! { const NSAlignWidthNearest = 1 << 20; const NSAlignHeightNearest = 1 << 21; const NSAlignRectFlipped = 1 << 63; - const NSAlignAllEdgesInward = NSAlignmentOptions::NSAlignMinXInward.bits - | NSAlignmentOptions::NSAlignMaxXInward.bits - | NSAlignmentOptions::NSAlignMinYInward.bits - | NSAlignmentOptions::NSAlignMaxYInward.bits; - const NSAlignAllEdgesOutward = NSAlignmentOptions::NSAlignMinXOutward.bits - | NSAlignmentOptions::NSAlignMaxXOutward.bits - | NSAlignmentOptions::NSAlignMinYOutward.bits - | NSAlignmentOptions::NSAlignMaxYOutward.bits; - const NSAlignAllEdgesNearest = NSAlignmentOptions::NSAlignMinXNearest.bits - | NSAlignmentOptions::NSAlignMaxXNearest.bits - | NSAlignmentOptions::NSAlignMinYNearest.bits - | NSAlignmentOptions::NSAlignMaxYNearest.bits; + const NSAlignAllEdgesInward = NSAlignmentOptions::NSAlignMinXInward.bits() + | NSAlignmentOptions::NSAlignMaxXInward.bits() + | NSAlignmentOptions::NSAlignMinYInward.bits() + | NSAlignmentOptions::NSAlignMaxYInward.bits(); + const NSAlignAllEdgesOutward = NSAlignmentOptions::NSAlignMinXOutward.bits() + | NSAlignmentOptions::NSAlignMaxXOutward.bits() + | NSAlignmentOptions::NSAlignMinYOutward.bits() + | NSAlignmentOptions::NSAlignMaxYOutward.bits(); + const NSAlignAllEdgesNearest = NSAlignmentOptions::NSAlignMinXNearest.bits() + | NSAlignmentOptions::NSAlignMaxXNearest.bits() + | NSAlignmentOptions::NSAlignMinYNearest.bits() + | NSAlignmentOptions::NSAlignMaxYNearest.bits(); } } @@ -578,7 +582,7 @@ impl NSApplication for id { } unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions) -> BOOL { - msg_send![self, setPresentationOptions:options.bits] + msg_send![self, setPresentationOptions:options.bits()] } unsafe fn presentationOptions_(self) -> NSApplicationPresentationOptions { @@ -1041,6 +1045,7 @@ impl NSMenuItem for id { pub type NSWindowDepth = libc::c_int; bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSWindowCollectionBehavior: NSUInteger { const NSWindowCollectionBehaviorDefault = 0; const NSWindowCollectionBehaviorCanJoinAllSpaces = 1 << 0; @@ -1059,6 +1064,7 @@ bitflags! { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSWindowOcclusionState: NSUInteger { const NSWindowOcclusionStateVisible = 1 << 1; } @@ -1351,7 +1357,7 @@ impl NSWindow for id { defer: BOOL, ) -> id { msg_send![self, initWithContentRect:rect - styleMask:style.bits + styleMask:style.bits() backing:backing as NSUInteger defer:defer] } @@ -1365,7 +1371,7 @@ impl NSWindow for id { screen: id, ) -> id { msg_send![self, initWithContentRect:rect - styleMask:style.bits + styleMask:style.bits() backing:backing as NSUInteger defer:defer screen:screen] @@ -1378,7 +1384,7 @@ impl NSWindow for id { } unsafe fn setStyleMask_(self, styleMask: NSWindowStyleMask) { - msg_send![self, setStyleMask:styleMask.bits] + msg_send![self, setStyleMask:styleMask.bits()] } unsafe fn toggleFullScreen_(self, sender: id) { @@ -1507,7 +1513,7 @@ impl NSWindow for id { windowFrame: NSRect, windowStyle: NSWindowStyleMask, ) -> NSRect { - msg_send![self, contentRectForFrameRect:windowFrame styleMask:windowStyle.bits] + msg_send![self, contentRectForFrameRect:windowFrame styleMask:windowStyle.bits()] } unsafe fn frameRectForContentRect_styleMask_( @@ -1515,7 +1521,7 @@ impl NSWindow for id { windowContentRect: NSRect, windowStyle: NSWindowStyleMask, ) -> NSRect { - msg_send![self, frameRectForContentRect:windowContentRect styleMask:windowStyle.bits] + msg_send![self, frameRectForContentRect:windowContentRect styleMask:windowStyle.bits()] } unsafe fn minFrameWidthWithTitle_styleMask_( @@ -1523,7 +1529,7 @@ impl NSWindow for id { windowTitle: id, windowStyle: NSWindowStyleMask, ) -> CGFloat { - msg_send![self, minFrameWidthWithTitle:windowTitle styleMask:windowStyle.bits] + msg_send![self, minFrameWidthWithTitle:windowTitle styleMask:windowStyle.bits()] } unsafe fn contentRectForFrameRect_(self, windowFrame: NSRect) -> NSRect { @@ -2517,6 +2523,7 @@ impl NSOpenGLContext for id { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSEventSwipeTrackingOptions: NSUInteger { const NSEventSwipeTrackingLockDirection = 0x1 << 0; const NSEventSwipeTrackingClampGestureAmount = 0x1 << 1; @@ -2531,6 +2538,7 @@ pub enum NSEventGestureAxis { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSEventPhase: NSUInteger { const NSEventPhaseNone = 0; const NSEventPhaseBegan = 0x1 << 0; @@ -2543,15 +2551,16 @@ bitflags! { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSTouchPhase: NSUInteger { const NSTouchPhaseBegan = 1 << 0; const NSTouchPhaseMoved = 1 << 1; const NSTouchPhaseStationary = 1 << 2; const NSTouchPhaseEnded = 1 << 3; const NSTouchPhaseCancelled = 1 << 4; - const NSTouchPhaseTouching = NSTouchPhase::NSTouchPhaseBegan.bits - | NSTouchPhase::NSTouchPhaseMoved.bits - | NSTouchPhase::NSTouchPhaseStationary.bits; + const NSTouchPhaseTouching = NSTouchPhase::NSTouchPhaseBegan.bits() + | NSTouchPhase::NSTouchPhaseMoved.bits() + | NSTouchPhase::NSTouchPhaseStationary.bits(); const NSTouchPhaseAny = !0; // NSUIntegerMax } } @@ -2592,6 +2601,7 @@ pub enum NSEventType { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSEventMask: libc::c_ulonglong { const NSLeftMouseDownMask = 1 << NSLeftMouseDown as libc::c_ulonglong; const NSLeftMouseUpMask = 1 << NSLeftMouseUp as libc::c_ulonglong; @@ -2628,13 +2638,12 @@ bitflags! { impl NSEventMask { pub fn from_type(ty: NSEventType) -> NSEventMask { - NSEventMask { - bits: 1 << ty as libc::c_ulonglong, - } + NSEventMask::from_bits_truncate(1 << ty as libc::c_ulonglong) } } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NSEventModifierFlags: NSUInteger { const NSAlphaShiftKeyMask = 1 << 16; const NSShiftKeyMask = 1 << 17; diff --git a/cocoa/src/quartzcore.rs b/cocoa/src/quartzcore.rs index eaf525c..5d7bb93 100644 --- a/cocoa/src/quartzcore.rs +++ b/cocoa/src/quartzcore.rs @@ -1176,6 +1176,7 @@ impl Filter { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct EdgeAntialiasingMask: u32 { const LEFT_EDGE = 1 << 0; // kCALayerLeftEdge const RIGHT_EDGE = 1 << 1; // kCALayerRightEdge @@ -1185,6 +1186,7 @@ bitflags! { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct CornerMask: NSUInteger { const MIN_X_MIN_Y_CORNER = 1 << 0; // kCALayerMinXMinYCorner const MAX_X_MIN_Y_CORNER = 1 << 1; // kCALayerMaxXMinYCorner @@ -1194,6 +1196,7 @@ bitflags! { } bitflags! { + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct AutoresizingMask: u32 { const NOT_SIZABLE = 0; // kCALayerNotSizable const MIN_X_MARGIN = 1 << 0; // kCALayerMinXMargin diff --git a/core-graphics-types/Cargo.toml b/core-graphics-types/Cargo.toml index 041693c..98e3f6a 100644 --- a/core-graphics-types/Cargo.toml +++ b/core-graphics-types/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0" edition = "2018" [dependencies] -bitflags = "1.0" +bitflags = "2" core-foundation = { default-features = false, path = "../core-foundation", version = "0.10" } libc = "0.2" diff --git a/core-graphics/Cargo.toml b/core-graphics/Cargo.toml index 34218a5..2d56d53 100644 --- a/core-graphics/Cargo.toml +++ b/core-graphics/Cargo.toml @@ -16,7 +16,7 @@ highsierra = [] link = ["core-foundation/link", "core-graphics-types/link"] [dependencies] -bitflags = "1.0" +bitflags = "2" core-foundation = { default-features = false, path = "../core-foundation", version = "0.10" } core-graphics-types = { default-features = false, path = "../core-graphics-types", version = "0.2" } foreign-types = "0.5.0" diff --git a/core-graphics/src/event.rs b/core-graphics/src/event.rs index 7305576..02024de 100644 --- a/core-graphics/src/event.rs +++ b/core-graphics/src/event.rs @@ -18,6 +18,7 @@ bitflags! { /// /// [Ref](http://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-700/IOHIDSystem/IOKit/hidsystem/IOLLEvent.h) #[repr(C)] + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct CGEventFlags: u64 { const CGEventFlagNull = 0; diff --git a/core-graphics/src/gradient.rs b/core-graphics/src/gradient.rs index b3bdcb6..a70fa19 100644 --- a/core-graphics/src/gradient.rs +++ b/core-graphics/src/gradient.rs @@ -21,6 +21,7 @@ use libc::size_t; bitflags! { #[repr(C)] + #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct CGGradientDrawingOptions: u32 { const CGGradientDrawsBeforeStartLocation = (1 << 0); const CGGradientDrawsAfterEndLocation = (1 << 1);