diff --git a/cocoa-foundation/Cargo.toml b/cocoa-foundation/Cargo.toml index 3cedaf174..44a4083b3 100644 --- a/cocoa-foundation/Cargo.toml +++ b/cocoa-foundation/Cargo.toml @@ -12,10 +12,11 @@ license = "MIT / Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block = "0.1" +block = { version = "=0.2.0-alpha.6", package = "block2" } bitflags = "1.0" libc = "0.2" core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } foreign-types = "0.3" -objc = "0.2.3" +objc2 = { version = "=0.3.0-beta.2" } +objc2-encode = { version = "=2.0.0-pre.2" } diff --git a/cocoa-foundation/src/base.rs b/cocoa-foundation/src/base.rs index 028205e89..3530c8a3b 100644 --- a/cocoa-foundation/src/base.rs +++ b/cocoa-foundation/src/base.rs @@ -7,9 +7,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use objc::runtime; +use objc2::runtime; -pub use objc::runtime::{BOOL, NO, YES}; +#[allow(deprecated)] +pub use objc2::runtime::{BOOL, NO, YES}; pub type Class = *mut runtime::Class; #[allow(non_camel_case_types)] diff --git a/cocoa-foundation/src/foundation.rs b/cocoa-foundation/src/foundation.rs index b9ca8b02e..7db7b6aad 100644 --- a/cocoa-foundation/src/foundation.rs +++ b/cocoa-foundation/src/foundation.rs @@ -11,22 +11,14 @@ use std::ptr; use std::os::raw::c_void; -use base::{id, BOOL, NO, SEL, nil}; +use base::{id, SEL, nil}; +use objc2::runtime::Bool; use block::Block; use libc; +use objc2_encode::{Encode, Encoding, RefEncode}; +pub use objc2::ffi::{NSInteger, NSUInteger, NSIntegerMax}; -#[cfg(target_pointer_width = "32")] -pub type NSInteger = libc::c_int; -#[cfg(target_pointer_width = "32")] -pub type NSUInteger = libc::c_uint; - -#[cfg(target_pointer_width = "64")] -pub type NSInteger = libc::c_long; -#[cfg(target_pointer_width = "64")] -pub type NSUInteger = libc::c_ulong; - -pub const NSIntegerMax: NSInteger = NSInteger::max_value(); pub const NSNotFound: NSInteger = NSIntegerMax; const UTF8_ENCODING: usize = 4; @@ -37,7 +29,7 @@ mod macos { use base::id; use core_graphics_types::base::CGFloat; use core_graphics_types::geometry::CGRect; - use objc; + use objc2_encode::{Encode, Encoding}; #[repr(C)] #[derive(Copy, Clone)] @@ -56,13 +48,9 @@ mod macos { } } - unsafe impl objc::Encode for NSPoint { - fn encode() -> objc::Encoding { - let encoding = format!("{{CGPoint={}{}}}", - CGFloat::encode().as_str(), - CGFloat::encode().as_str()); - unsafe { objc::Encoding::from_str(&encoding) } - } + unsafe impl Encode for NSPoint { + const ENCODING: Encoding = + Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFloat::ENCODING]); } #[repr(C)] @@ -82,13 +70,9 @@ mod macos { } } - unsafe impl objc::Encode for NSSize { - fn encode() -> objc::Encoding { - let encoding = format!("{{CGSize={}{}}}", - CGFloat::encode().as_str(), - CGFloat::encode().as_str()); - unsafe { objc::Encoding::from_str(&encoding) } - } + unsafe impl Encode for NSSize { + const ENCODING: Encoding = + Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]); } #[repr(C)] @@ -122,13 +106,9 @@ mod macos { } } - unsafe impl objc::Encode for NSRect { - fn encode() -> objc::Encoding { - let encoding = format!("{{CGRect={}{}}}", - NSPoint::encode().as_str(), - NSSize::encode().as_str()); - unsafe { objc::Encoding::from_str(&encoding) } - } + unsafe impl Encode for NSRect { + const ENCODING: Encoding = + Encoding::Struct("CGRect", &[NSPoint::ENCODING, NSSize::ENCODING]); } // Same as CGRectEdge @@ -140,6 +120,8 @@ mod macos { NSRectMaxYEdge, } + impl_Encode!(NSRectEdge, u32); + #[link(name = "Foundation", kind = "framework")] extern { fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect; @@ -169,6 +151,11 @@ pub struct NSRange { pub length: NSUInteger, } +unsafe impl Encode for NSRange { + const ENCODING: Encoding = + Encoding::Struct("_NSRange", &[NSUInteger::ENCODING, NSUInteger::ENCODING]); +} + impl NSRange { #[inline] pub fn new(location: NSUInteger, length: NSUInteger) -> NSRange { @@ -212,6 +199,17 @@ pub struct NSOperatingSystemVersion { pub patchVersion: NSUInteger, } +unsafe impl Encode for NSOperatingSystemVersion { + const ENCODING: Encoding = Encoding::Struct( + "NSOperatingSystemVersion", + &[ + NSUInteger::ENCODING, + NSUInteger::ENCODING, + NSUInteger::ENCODING, + ], + ); +} + impl NSOperatingSystemVersion { #[inline] pub fn new(majorVersion: NSUInteger, minorVersion: NSUInteger, patchVersion: NSUInteger) -> NSOperatingSystemVersion { @@ -261,7 +259,7 @@ pub trait NSArray: Sized { } unsafe fn arrayWithObjects(_: Self, objects: &[id]) -> id { - msg_send![class!(NSArray), arrayWithObjects:objects.as_ptr() + msg_send![class!(NSArray), arrayWithObjects:objects.as_ptr(), count:objects.len()] } @@ -318,15 +316,15 @@ pub trait NSDictionary: Sized { } unsafe fn dictionaryWithObject_forKey_(_: Self, anObject: id, aKey: id) -> id { - msg_send![class!(NSDictionary), dictionaryWithObject:anObject forKey:aKey] + msg_send![class!(NSDictionary), dictionaryWithObject: anObject, forKey: aKey] } unsafe fn dictionaryWithObjects_forKeys_(_: Self, objects: id, keys: id) -> id { - msg_send![class!(NSDictionary), dictionaryWithObjects:objects forKeys:keys] + msg_send![class!(NSDictionary), dictionaryWithObjects: objects, forKeys: keys] } unsafe fn dictionaryWithObjects_forKeys_count_(_: Self, objects: *const id, keys: *const id, count: NSUInteger) -> id { - msg_send![class!(NSDictionary), dictionaryWithObjects:objects forKeys:keys count:count] + msg_send![class!(NSDictionary), dictionaryWithObjects: objects, forKeys: keys, count: count] } unsafe fn dictionaryWithObjectsAndKeys_(_: Self, firstObject: id) -> id { @@ -337,7 +335,7 @@ pub trait NSDictionary: Sized { unsafe fn initWithContentsOfFile_(self, path: id) -> id; unsafe fn initWithContentsOfURL_(self, aURL: id) -> id; unsafe fn initWithDictionary_(self, otherDicitonary: id) -> id; - unsafe fn initWithDictionary_copyItems_(self, otherDicitonary: id, flag: BOOL) -> id; + unsafe fn initWithDictionary_copyItems_(self, otherDicitonary: id, flag: bool) -> id; unsafe fn initWithObjects_forKeys_(self, objects: id, keys: id) -> id; unsafe fn initWithObjects_forKeys_count_(self, objects: id, keys: id, count: NSUInteger) -> id; unsafe fn initWithObjectsAndKeys_(self, firstObject: id) -> id; @@ -348,7 +346,7 @@ pub trait NSDictionary: Sized { unsafe fn count(self) -> NSUInteger; - unsafe fn isEqualToDictionary_(self, otherDictionary: id) -> BOOL; + unsafe fn isEqualToDictionary_(self, otherDictionary: id) -> bool; unsafe fn allKeys(self) -> id; unsafe fn allKeysForObject_(self, anObject: id) -> id; @@ -360,27 +358,27 @@ pub trait NSDictionary: Sized { unsafe fn keyEnumerator(self) -> id; unsafe fn objectEnumerator(self) -> id; - unsafe fn enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut BOOL), ()>); + unsafe fn enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut Bool), ()>); unsafe fn enumerateKeysAndObjectsWithOptions_usingBlock_(self, opts: NSEnumerationOptions, - block: *mut Block<(id, id, *mut BOOL), ()>); + block: *mut Block<(id, id, *mut Bool), ()>); unsafe fn keysSortedByValueUsingSelector_(self, comparator: SEL) -> id; unsafe fn keysSortedByValueUsingComparator_(self, cmptr: NSComparator) -> id; unsafe fn keysSortedByValueWithOptions_usingComparator_(self, opts: NSEnumerationOptions, cmptr: NSComparator) -> id; - unsafe fn keysOfEntriesPassingTest_(self, predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id; + unsafe fn keysOfEntriesPassingTest_(self, predicate: *mut Block<(id, id, *mut Bool), Bool>) -> id; unsafe fn keysOfEntriesWithOptions_PassingTest_(self, opts: NSEnumerationOptions, - predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id; + predicate: *mut Block<(id, id, *mut Bool), Bool>) -> id; - unsafe fn writeToFile_atomically_(self, path: id, flag: BOOL) -> BOOL; - unsafe fn writeToURL_atomically_(self, aURL: id, flag: BOOL) -> BOOL; + unsafe fn writeToFile_atomically_(self, path: id, flag: bool) -> bool; + unsafe fn writeToURL_atomically_(self, aURL: id, flag: bool) -> bool; unsafe fn fileCreationDate(self) -> id; - unsafe fn fileExtensionHidden(self) -> BOOL; + unsafe fn fileExtensionHidden(self) -> bool; unsafe fn fileGroupOwnerAccountID(self) -> id; unsafe fn fileGroupOwnerAccountName(self) -> id; - unsafe fn fileIsAppendOnly(self) -> BOOL; - unsafe fn fileIsImmutable(self) -> BOOL; + unsafe fn fileIsAppendOnly(self) -> bool; + unsafe fn fileIsImmutable(self) -> bool; unsafe fn fileModificationDate(self) -> id; unsafe fn fileOwnerAccountID(self) -> id; unsafe fn fileOwnerAccountName(self) -> id; @@ -413,16 +411,16 @@ impl NSDictionary for id { msg_send![self, initWithDictionary:otherDictionary] } - unsafe fn initWithDictionary_copyItems_(self, otherDictionary: id, flag: BOOL) -> id { - msg_send![self, initWithDictionary:otherDictionary copyItems:flag] + unsafe fn initWithDictionary_copyItems_(self, otherDictionary: id, flag: bool) -> id { + msg_send![self, initWithDictionary: otherDictionary, copyItems: flag] } unsafe fn initWithObjects_forKeys_(self, objects: id, keys: id) -> id { - msg_send![self, initWithObjects:objects forKeys:keys] + msg_send![self, initWithObjects: objects, forKeys: keys] } unsafe fn initWithObjects_forKeys_count_(self, objects: id, keys: id, count: NSUInteger) -> id { - msg_send![self, initWithObjects:objects forKeys:keys count:count] + msg_send![self, initWithObjects: objects, forKeys: keys, count: count] } unsafe fn initWithObjectsAndKeys_(self, firstObject: id) -> id { @@ -433,7 +431,7 @@ impl NSDictionary for id { msg_send![self, count] } - unsafe fn isEqualToDictionary_(self, otherDictionary: id) -> BOOL { + unsafe fn isEqualToDictionary_(self, otherDictionary: id) -> bool { msg_send![self, isEqualToDictionary:otherDictionary] } @@ -458,7 +456,7 @@ impl NSDictionary for id { } unsafe fn objectsForKeys_notFoundMarker_(self, keys: id, anObject: id) -> id { - msg_send![self, objectsForKeys:keys notFoundMarker:anObject] + msg_send![self, objectsForKeys: keys, notFoundMarker: anObject] } unsafe fn valueForKey_(self, key: id) -> id { @@ -473,13 +471,13 @@ impl NSDictionary for id { msg_send![self, objectEnumerator] } - unsafe fn enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut BOOL), ()>) { + unsafe fn enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut Bool), ()>) { msg_send![self, enumerateKeysAndObjectsUsingBlock:block] } unsafe fn enumerateKeysAndObjectsWithOptions_usingBlock_(self, opts: NSEnumerationOptions, - block: *mut Block<(id, id, *mut BOOL), ()>) { - msg_send![self, enumerateKeysAndObjectsWithOptions:opts usingBlock:block] + block: *mut Block<(id, id, *mut Bool), ()>) { + msg_send![self, enumerateKeysAndObjectsWithOptions:opts, usingBlock:block] } unsafe fn keysSortedByValueUsingSelector_(self, comparator: SEL) -> id { @@ -491,32 +489,32 @@ impl NSDictionary for id { } unsafe fn keysSortedByValueWithOptions_usingComparator_(self, opts: NSEnumerationOptions, cmptr: NSComparator) -> id { - let rv: id = msg_send![self, keysSortedByValueWithOptions:opts usingComparator:cmptr]; + let rv: id = msg_send![self, keysSortedByValueWithOptions:opts, usingComparator:cmptr]; rv } - unsafe fn keysOfEntriesPassingTest_(self, predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id { + unsafe fn keysOfEntriesPassingTest_(self, predicate: *mut Block<(id, id, *mut Bool), Bool>) -> id { msg_send![self, keysOfEntriesPassingTest:predicate] } unsafe fn keysOfEntriesWithOptions_PassingTest_(self, opts: NSEnumerationOptions, - predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id { - msg_send![self, keysOfEntriesWithOptions:opts PassingTest:predicate] + predicate: *mut Block<(id, id, *mut Bool), Bool>) -> id { + msg_send![self, keysOfEntriesWithOptions:opts, PassingTest:predicate] } - unsafe fn writeToFile_atomically_(self, path: id, flag: BOOL) -> BOOL { - msg_send![self, writeToFile:path atomically:flag] + unsafe fn writeToFile_atomically_(self, path: id, flag: bool) -> bool { + msg_send![self, writeToFile:path, atomically: flag] } - unsafe fn writeToURL_atomically_(self, aURL: id, flag: BOOL) -> BOOL { - msg_send![self, writeToURL:aURL atomically:flag] + unsafe fn writeToURL_atomically_(self, aURL: id, flag: bool) -> bool { + msg_send![self, writeToURL: aURL, atomically: flag] } unsafe fn fileCreationDate(self) -> id { msg_send![self, fileCreationDate] } - unsafe fn fileExtensionHidden(self) -> BOOL { + unsafe fn fileExtensionHidden(self) -> bool { msg_send![self, fileExtensionHidden] } @@ -528,11 +526,11 @@ impl NSDictionary for id { msg_send![self, fileGroupOwnerAccountName] } - unsafe fn fileIsAppendOnly(self) -> BOOL { + unsafe fn fileIsAppendOnly(self) -> bool { msg_send![self, fileIsAppendOnly] } - unsafe fn fileIsImmutable(self) -> BOOL { + unsafe fn fileIsImmutable(self) -> bool { msg_send![self, fileIsImmutable] } @@ -581,7 +579,7 @@ impl NSDictionary for id { } unsafe fn descriptionWithLocale_indent_(self, locale: id, indent: NSUInteger) -> id { - msg_send![self, descriptionWithLocale:locale indent:indent] + msg_send![self, descriptionWithLocale:locale, indent:indent] } } @@ -592,6 +590,8 @@ bitflags! { } } +impl_Encode!(NSEnumerationOptions, libc::c_ulonglong); + pub type NSComparator = *mut Block<(id, id), NSComparisonResult>; #[repr(isize)] @@ -602,6 +602,8 @@ pub enum NSComparisonResult { NSOrderedDescending = 1 } +impl_Encode!(NSComparisonResult, isize); + pub trait NSString: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSString), alloc] @@ -611,15 +613,14 @@ pub trait NSString: Sized { unsafe fn init_str(self, string: &str) -> Self; unsafe fn UTF8String(self) -> *const libc::c_char; unsafe fn len(self) -> usize; - unsafe fn isEqualToString(self, &str) -> bool; + unsafe fn isEqualToString(self, _: &str) -> bool; unsafe fn substringWithRange(self, range: NSRange) -> id; } impl NSString for id { unsafe fn isEqualToString(self, other: &str) -> bool { let other = NSString::alloc(nil).init_str(other); - let rv: BOOL = msg_send![self, isEqualToString:other]; - rv != NO + msg_send![self, isEqualToString: other] } unsafe fn stringByAppendingString_(self, other: id) -> id { @@ -627,10 +628,12 @@ impl NSString for id { } unsafe fn init_str(self, string: &str) -> id { - return msg_send![self, - initWithBytes:string.as_ptr() - length:string.len() - encoding:UTF8_ENCODING as id]; + msg_send![ + self, + initWithBytes: string.as_ptr() as *const c_void, + length: string.len(), + encoding: UTF8_ENCODING, + ] } unsafe fn len(self) -> usize { @@ -668,6 +671,22 @@ struct NSFastEnumerationState { pub extra: [libc::c_ulong; 5] } +unsafe impl Encode for NSFastEnumerationState { + const ENCODING: Encoding = Encoding::Struct( + "?", + &[ + libc::c_ulong::ENCODING, + Encoding::Pointer(&Encoding::Object), + Encoding::Pointer(&libc::c_ulong::ENCODING), + Encoding::Array(5, &libc::c_ulong::ENCODING), + ], + ); +} + +unsafe impl RefEncode for NSFastEnumerationState { + const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING); +} + const NS_FAST_ENUM_BUF_SIZE: usize = 16; pub struct NSFastIterator { @@ -676,7 +695,7 @@ pub struct NSFastIterator { mut_val: Option, len: usize, idx: usize, - object: id + object: id, } impl Iterator for NSFastIterator { @@ -685,7 +704,7 @@ impl Iterator for NSFastIterator { fn next(&mut self) -> Option { if self.idx >= self.len { self.len = unsafe { - msg_send![self.object, countByEnumeratingWithState:&mut self.state objects:self.buffer.as_mut_ptr() count:NS_FAST_ENUM_BUF_SIZE] + msg_send![self.object, countByEnumeratingWithState:&mut self.state, objects:self.buffer.as_mut_ptr(), count:NS_FAST_ENUM_BUF_SIZE] }; self.idx = 0; } @@ -755,10 +774,10 @@ impl NSRunLoop for id { anArgument: id, order: NSUInteger, modes: id) { - msg_send![self, performSelector:aSelector - target:target - argument:anArgument - order:order + msg_send![self, performSelector:aSelector, + target:target, + argument:anArgument, + order:order, modes:modes] } } @@ -773,6 +792,8 @@ bitflags! { } } +impl_Encode!(NSURLBookmarkCreationOptions, NSUInteger); + pub type NSURLBookmarkFileCreationOptions = NSURLBookmarkCreationOptions; bitflags! { @@ -783,6 +804,7 @@ bitflags! { } } +impl_Encode!(NSURLBookmarkResolutionOptions, NSUInteger); pub trait NSURL: Sized { unsafe fn alloc(_: Self) -> id; @@ -791,18 +813,18 @@ pub trait NSURL: Sized { unsafe fn initWithString_(self, string: id) -> id; unsafe fn URLWithString_relativeToURL_(_:Self, string: id, url: id) -> id; unsafe fn initWithString_relativeToURL_(self, string: id, url: id) -> id; - unsafe fn fileURLWithPath_isDirectory_(_:Self, path: id, is_dir: BOOL) -> id; - unsafe fn initFileURLWithPath_isDirectory_(self, path: id, is_dir: BOOL) -> id; + unsafe fn fileURLWithPath_isDirectory_(_:Self, path: id, is_dir: bool) -> id; + unsafe fn initFileURLWithPath_isDirectory_(self, path: id, is_dir: bool) -> id; unsafe fn fileURLWithPath_relativeToURL_(_:Self, path: id, url: id) -> id; unsafe fn initFileURLWithPath_relativeToURL_(self, path: id, url: id) -> id; - unsafe fn fileURLWithPath_isDirectory_relativeToURL_(_:Self, path: id, is_dir: BOOL, url: id) -> id; - unsafe fn initFileURLWithPath_isDirectory_relativeToURL_(self, path: id, is_dir: BOOL, url: id) -> id; + unsafe fn fileURLWithPath_isDirectory_relativeToURL_(_:Self, path: id, is_dir: bool, url: id) -> id; + unsafe fn initFileURLWithPath_isDirectory_relativeToURL_(self, path: id, is_dir: bool, url: id) -> id; unsafe fn fileURLWithPath_(_:Self, path: id) -> id; unsafe fn initFileURLWithPath_(self, path: id) -> id; unsafe fn fileURLWithPathComponents_(_:Self, path_components: id /* (NSArray*) */) -> id; unsafe fn URLByResolvingAliasFileAtURL_options_error_(_:Self, url: id, options: NSURLBookmarkResolutionOptions, error: *mut id /* (NSError _Nullable) */) -> id; - unsafe fn URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(_:Self, data: id /* (NSData) */, options: NSURLBookmarkResolutionOptions, relative_to_url: id, is_stale: *mut BOOL, error: *mut id /* (NSError _Nullable) */) -> id; - unsafe fn initByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(self, data: id /* (NSData) */, options: NSURLBookmarkResolutionOptions, relative_to_url: id, is_stale: *mut BOOL, error: *mut id /* (NSError _Nullable) */) -> id; + unsafe fn URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(_:Self, data: id /* (NSData) */, options: NSURLBookmarkResolutionOptions, relative_to_url: id, is_stale: *mut Bool, error: *mut id /* (NSError _Nullable) */) -> id; + unsafe fn initByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(self, data: id /* (NSData) */, options: NSURLBookmarkResolutionOptions, relative_to_url: id, is_stale: *mut Bool, error: *mut id /* (NSError _Nullable) */) -> id; // unsafe fn fileURLWithFileSystemRepresentation_isDirectory_relativeToURL_ // unsafe fn getFileSystemRepresentation_maxLength_ // unsafe fn initFileURLWithFileSystemRepresentation_isDirectory_relativeToURL_ @@ -812,11 +834,11 @@ pub trait NSURL: Sized { unsafe fn initWithDataRepresentation_relativeToURL_(self, data: id /* (NSData) */, url: id) -> id; unsafe fn dataRepresentation(self) -> id /* (NSData) */; - unsafe fn isEqual_(self, id: id) -> BOOL; + unsafe fn isEqual_(self, id: id) -> bool; - unsafe fn checkResourceIsReachableAndReturnError_(self, error: id /* (NSError _Nullable) */) -> BOOL; - unsafe fn isFileReferenceURL(self) -> BOOL; - unsafe fn isFileURL(self) -> BOOL; + unsafe fn checkResourceIsReachableAndReturnError_(self, error: id /* (NSError _Nullable) */) -> bool; + unsafe fn isFileReferenceURL(self) -> bool; + unsafe fn isFileURL(self) -> bool; unsafe fn absoluteString(self) -> id /* (NSString) */; unsafe fn absoluteURL(self) -> id /* (NSURL) */; @@ -851,19 +873,19 @@ pub trait NSURL: Sized { unsafe fn filePathURL(self) -> id; unsafe fn fileReferenceURL(self) -> id; unsafe fn URLByAppendingPathComponent_(self, path_component: id /* (NSString) */) -> id; - unsafe fn URLByAppendingPathComponent_isDirectory_(self, path_component: id /* (NSString) */, is_dir: BOOL) -> id; + unsafe fn URLByAppendingPathComponent_isDirectory_(self, path_component: id /* (NSString) */, is_dir: bool) -> id; unsafe fn URLByAppendingPathExtension_(self, extension: id /* (NSString) */) -> id; unsafe fn URLByDeletingLastPathComponent(self) -> id; unsafe fn URLByDeletingPathExtension(self) -> id; unsafe fn URLByResolvingSymlinksInPath(self) -> id; unsafe fn URLByStandardizingPath(self) -> id; - unsafe fn hasDirectoryPath(self) -> BOOL; + unsafe fn hasDirectoryPath(self) -> bool; unsafe fn bookmarkDataWithContentsOfURL_error_(_:Self, url: id, error: id /* (NSError _Nullable) */) -> id /* (NSData) */; unsafe fn bookmarkDataWithOptions_includingResourceValuesForKeys_relativeToURL_error_(self, options: NSURLBookmarkCreationOptions, resource_value_for_keys: id /* (NSArray) */, relative_to_url: id, error: id /* (NSError _Nullable) */) -> id /* (NSData) */; // unsafe fn resourceValuesForKeys_fromBookmarkData_ unsafe fn writeBookmarkData_toURL_options_error_(_:Self, data: id /* (NSData) */, to_url: id, options: NSURLBookmarkFileCreationOptions, error: id /* (NSError _Nullable) */) -> id; - unsafe fn startAccessingSecurityScopedResource(self) -> BOOL; + unsafe fn startAccessingSecurityScopedResource(self) -> bool; unsafe fn stopAccessingSecurityScopedResource(self); unsafe fn NSURLBookmarkFileCreationOptions(self) -> NSURLBookmarkFileCreationOptions; unsafe fn NSURLBookmarkCreationOptions(self) -> NSURLBookmarkCreationOptions; @@ -889,28 +911,28 @@ impl NSURL for id { msg_send![self, initWithString:string] } unsafe fn URLWithString_relativeToURL_(_:Self, string: id, url: id) -> id { - msg_send![class!(NSURL), URLWithString: string relativeToURL:url] + msg_send![class!(NSURL), URLWithString: string, relativeToURL: url] } unsafe fn initWithString_relativeToURL_(self, string: id, url: id) -> id { - msg_send![self, initWithString:string relativeToURL:url] + msg_send![self, initWithString:string, relativeToURL:url] } - unsafe fn fileURLWithPath_isDirectory_(_:Self, path: id, is_dir: BOOL) -> id { - msg_send![class!(NSURL), fileURLWithPath:path isDirectory:is_dir] + unsafe fn fileURLWithPath_isDirectory_(_:Self, path: id, is_dir: bool) -> id { + msg_send![class!(NSURL), fileURLWithPath: path, isDirectory: is_dir] } - unsafe fn initFileURLWithPath_isDirectory_(self, path: id, is_dir: BOOL) -> id { - msg_send![self, initFileURLWithPath:path isDirectory:is_dir] + unsafe fn initFileURLWithPath_isDirectory_(self, path: id, is_dir: bool) -> id { + msg_send![self, initFileURLWithPath: path, isDirectory: is_dir] } unsafe fn fileURLWithPath_relativeToURL_(_:Self, path: id, url: id) -> id { - msg_send![class!(NSURL), fileURLWithPath:path relativeToURL:url] + msg_send![class!(NSURL), fileURLWithPath:path, relativeToURL:url] } unsafe fn initFileURLWithPath_relativeToURL_(self, path: id, url: id) -> id { - msg_send![self, initFileURLWithPath:path relativeToURL:url] + msg_send![self, initFileURLWithPath:path, relativeToURL:url] } - unsafe fn fileURLWithPath_isDirectory_relativeToURL_(_:Self, path: id, is_dir: BOOL, url: id) -> id { - msg_send![class!(NSURL), fileURLWithPath:path isDirectory:is_dir relativeToURL:url] + unsafe fn fileURLWithPath_isDirectory_relativeToURL_(_:Self, path: id, is_dir: bool, url: id) -> id { + msg_send![class!(NSURL), fileURLWithPath: path, isDirectory: is_dir, relativeToURL: url] } - unsafe fn initFileURLWithPath_isDirectory_relativeToURL_(self, path: id, is_dir: BOOL, url: id) -> id { - msg_send![self, initFileURLWithPath:path isDirectory:is_dir relativeToURL:url] + unsafe fn initFileURLWithPath_isDirectory_relativeToURL_(self, path: id, is_dir: bool, url: id) -> id { + msg_send![self, initFileURLWithPath: path, isDirectory: is_dir, relativeToURL: url] } unsafe fn fileURLWithPath_(_:Self, path: id) -> id { msg_send![class!(NSURL), fileURLWithPath:path] @@ -922,44 +944,44 @@ impl NSURL for id { msg_send![class!(NSURL), fileURLWithPathComponents:path_components] } unsafe fn URLByResolvingAliasFileAtURL_options_error_(_:Self, url: id, options: NSURLBookmarkResolutionOptions, error: *mut id /* (NSError _Nullable) */) -> id { - msg_send![class!(NSURL), URLByResolvingAliasFileAtURL:url options:options error:error] + msg_send![class!(NSURL), URLByResolvingAliasFileAtURL: url, options: options, error: error] } - unsafe fn URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(_:Self, data: id /* (NSData) */, options: NSURLBookmarkResolutionOptions, relative_to_url: id, is_stale: *mut BOOL, error: *mut id /* (NSError _Nullable) */) -> id { - msg_send![class!(NSURL), URLByResolvingBookmarkData:data options:options relativeToURL:relative_to_url bookmarkDataIsStale:is_stale error:error] + unsafe fn URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(_:Self, data: id /* (NSData) */, options: NSURLBookmarkResolutionOptions, relative_to_url: id, is_stale: *mut Bool, error: *mut id /* (NSError _Nullable) */) -> id { + msg_send![class!(NSURL), URLByResolvingBookmarkData: data, options: options, relativeToURL: relative_to_url, bookmarkDataIsStale: is_stale, error: error] } - unsafe fn initByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(self, data: id /* (NSData) */, options: NSURLBookmarkResolutionOptions, relative_to_url: id, is_stale: *mut BOOL, error: *mut id /* (NSError _Nullable) */) -> id { - msg_send![self, initByResolvingBookmarkData:data options:options relativeToURL:relative_to_url bookmarkDataIsStale:is_stale error:error] + unsafe fn initByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error_(self, data: id /* (NSData) */, options: NSURLBookmarkResolutionOptions, relative_to_url: id, is_stale: *mut Bool, error: *mut id /* (NSError _Nullable) */) -> id { + msg_send![self, initByResolvingBookmarkData: data, options: options, relativeToURL: relative_to_url, bookmarkDataIsStale: is_stale, error: error] } // unsafe fn fileURLWithFileSystemRepresentation_isDirectory_relativeToURL_ // unsafe fn getFileSystemRepresentation_maxLength_ // unsafe fn initFileURLWithFileSystemRepresentation_isDirectory_relativeToURL_ unsafe fn absoluteURLWithDataRepresentation_relativeToURL_(_:Self, data: id /* (NSData) */, url: id) -> id { - msg_send![class!(NSURL), absoluteURLWithDataRepresentation:data relativeToURL:url] + msg_send![class!(NSURL), absoluteURLWithDataRepresentation:data, relativeToURL:url] } unsafe fn initAbsoluteURLWithDataRepresentation_relativeToURL_(self, data: id /* (NSData) */, url: id) -> id { - msg_send![self, initAbsoluteURLWithDataRepresentation:data relativeToURL:url] + msg_send![self, initAbsoluteURLWithDataRepresentation:data, relativeToURL:url] } unsafe fn URLWithDataRepresentation_relativeToURL_(_:Self, data: id /* (NSData) */, url: id) -> id { - msg_send![class!(NSURL), URLWithDataRepresentation:data relativeToURL:url] + msg_send![class!(NSURL), URLWithDataRepresentation:data, relativeToURL:url] } unsafe fn initWithDataRepresentation_relativeToURL_(self, data: id /* (NSData) */, url: id) -> id { - msg_send![self, initWithDataRepresentation:data relativeToURL:url] + msg_send![self, initWithDataRepresentation:data, relativeToURL:url] } unsafe fn dataRepresentation(self) -> id /* (NSData) */ { msg_send![self, dataRepresentation] } - unsafe fn isEqual_(self, id: id) -> BOOL { + unsafe fn isEqual_(self, id: id) -> bool { msg_send![self, isEqual:id] } - unsafe fn checkResourceIsReachableAndReturnError_(self, error: id /* (NSError _Nullable) */) -> BOOL { + unsafe fn checkResourceIsReachableAndReturnError_(self, error: id /* (NSError _Nullable) */) -> bool { msg_send![self, checkResourceIsReachableAndReturnError:error] } - unsafe fn isFileReferenceURL(self) -> BOOL { + unsafe fn isFileReferenceURL(self) -> bool { msg_send![self, isFileReferenceURL] } - unsafe fn isFileURL(self) -> BOOL { + unsafe fn isFileURL(self) -> bool { msg_send![self, isFileURL] } @@ -1042,8 +1064,8 @@ impl NSURL for id { unsafe fn URLByAppendingPathComponent_(self, path_component: id /* (NSString) */) -> id { msg_send![self, URLByAppendingPathComponent:path_component] } - unsafe fn URLByAppendingPathComponent_isDirectory_(self, path_component: id /* (NSString) */, is_dir: BOOL) -> id { - msg_send![self, URLByAppendingPathComponent:path_component isDirectory:is_dir] + unsafe fn URLByAppendingPathComponent_isDirectory_(self, path_component: id /* (NSString) */, is_dir: bool) -> id { + msg_send![self, URLByAppendingPathComponent:path_component, isDirectory: is_dir] } unsafe fn URLByAppendingPathExtension_(self, extension: id /* (NSString) */) -> id { msg_send![self, URLByAppendingPathExtension:extension] @@ -1060,21 +1082,21 @@ impl NSURL for id { unsafe fn URLByStandardizingPath(self) -> id { msg_send![self, URLByStandardizingPath] } - unsafe fn hasDirectoryPath(self) -> BOOL { + unsafe fn hasDirectoryPath(self) -> bool { msg_send![self, hasDirectoryPath] } unsafe fn bookmarkDataWithContentsOfURL_error_(_:Self, url: id, error: id /* (NSError _Nullable) */) -> id /* (NSData) */ { - msg_send![class!(NSURL), bookmarkDataWithContentsOfURL:url error:error] + msg_send![class!(NSURL), bookmarkDataWithContentsOfURL:url, error:error] } unsafe fn bookmarkDataWithOptions_includingResourceValuesForKeys_relativeToURL_error_(self, options: NSURLBookmarkCreationOptions, resource_value_for_keys: id /* (NSArray) */, relative_to_url: id, error: id /* (NSError _Nullable) */) -> id /* (NSData) */ { - msg_send![self, bookmarkDataWithOptions:options includingResourceValuesForKeys:resource_value_for_keys relativeToURL:relative_to_url error:error] + msg_send![self, bookmarkDataWithOptions:options, includingResourceValuesForKeys:resource_value_for_keys, relativeToURL:relative_to_url, error:error] } // unsafe fn resourceValuesForKeys_fromBookmarkData_ unsafe fn writeBookmarkData_toURL_options_error_(_:Self, data: id /* (NSData) */, to_url: id, options: NSURLBookmarkFileCreationOptions, error: id /* (NSError _Nullable) */) -> id { - msg_send![class!(NSURL), writeBookmarkData:data toURL:to_url options:options error:error] + msg_send![class!(NSURL), writeBookmarkData:data, toURL:to_url, options:options, error:error] } - unsafe fn startAccessingSecurityScopedResource(self) -> BOOL { + unsafe fn startAccessingSecurityScopedResource(self) -> bool { msg_send![self, startAccessingSecurityScopedResource] } unsafe fn stopAccessingSecurityScopedResource(self) { @@ -1104,7 +1126,7 @@ pub trait NSBundle: Sized { unsafe fn loadNibNamed_owner_topLevelObjects_(self, name: id /* NSString */, owner: id, - topLevelObjects: *mut id /* NSArray */) -> BOOL; + topLevelObjects: *mut id /* NSArray */) -> bool; unsafe fn bundleIdentifier(self) -> id /* NSString */; @@ -1119,9 +1141,9 @@ impl NSBundle for id { unsafe fn loadNibNamed_owner_topLevelObjects_(self, name: id /* NSString */, owner: id, - topLevelObjects: *mut id /* NSArray* */) -> BOOL { - msg_send![self, loadNibNamed:name - owner:owner + topLevelObjects: *mut id /* NSArray* */) -> bool { + msg_send![self, loadNibNamed:name, + owner:owner, topLevelObjects:topLevelObjects] } @@ -1140,16 +1162,16 @@ pub trait NSData: Sized { } unsafe fn dataWithBytes_length_(_: Self, bytes: *const c_void, length: NSUInteger) -> id { - msg_send![class!(NSData), dataWithBytes:bytes length:length] + msg_send![class!(NSData), dataWithBytes:bytes, length:length] } unsafe fn dataWithBytesNoCopy_length_(_: Self, bytes: *const c_void, length: NSUInteger) -> id { - msg_send![class!(NSData), dataWithBytesNoCopy:bytes length:length] + msg_send![class!(NSData), dataWithBytesNoCopy:bytes, length:length] } unsafe fn dataWithBytesNoCopy_length_freeWhenDone_(_: Self, bytes: *const c_void, - length: NSUInteger, freeWhenDone: BOOL) -> id { - msg_send![class!(NSData), dataWithBytesNoCopy:bytes length:length freeWhenDone:freeWhenDone] + length: NSUInteger, freeWhenDone: bool) -> id { + msg_send![class!(NSData), dataWithBytesNoCopy: bytes, length: length, freeWhenDone: freeWhenDone] } unsafe fn dataWithContentsOfFile_(_: Self, path: id) -> id { @@ -1158,7 +1180,7 @@ pub trait NSData: Sized { unsafe fn dataWithContentsOfFile_options_error_(_: Self, path: id, mask: NSDataReadingOptions, errorPtr: *mut id) -> id { - msg_send![class!(NSData), dataWithContentsOfFile:path options:mask error:errorPtr] + msg_send![class!(NSData), dataWithContentsOfFile: path, options: mask, error: errorPtr] } unsafe fn dataWithContentsOfURL_(_: Self, aURL: id) -> id { @@ -1167,7 +1189,7 @@ pub trait NSData: Sized { unsafe fn dataWithContentsOfURL_options_error_(_: Self, aURL: id, mask: NSDataReadingOptions, errorPtr: *mut id) -> id { - msg_send![class!(NSData), dataWithContentsOfURL:aURL options:mask error:errorPtr] + msg_send![class!(NSData), dataWithContentsOfURL: aURL, options: mask, error: errorPtr] } unsafe fn dataWithData_(_: Self, aData: id) -> id { @@ -1184,7 +1206,7 @@ pub trait NSData: Sized { deallocator: *mut Block<(*const c_void, NSUInteger), ()>) -> id; unsafe fn initWithBytesNoCopy_length_freeWhenDone_(self, bytes: *const c_void, - length: NSUInteger, freeWhenDone: BOOL) -> id; + length: NSUInteger, freeWhenDone: bool) -> id; unsafe fn initWithContentsOfFile_(self, path: id) -> id; unsafe fn initWithContentsOfFile_options_error(self, path: id, mask: NSDataReadingOptions, errorPtr: *mut id) -> id; @@ -1195,7 +1217,7 @@ pub trait NSData: Sized { unsafe fn bytes(self) -> *const c_void; unsafe fn description(self) -> id; - unsafe fn enumerateByteRangesUsingBlock_(self, block: *mut Block<(*const c_void, NSRange, *mut BOOL), ()>); + unsafe fn enumerateByteRangesUsingBlock_(self, block: *mut Block<(*const c_void, NSRange, *mut Bool), ()>); unsafe fn getBytes_length_(self, buffer: *mut c_void, length: NSUInteger); unsafe fn getBytes_range_(self, buffer: *mut c_void, range: NSRange); unsafe fn subdataWithRange_(self, range: NSRange) -> id; @@ -1208,40 +1230,40 @@ pub trait NSData: Sized { unsafe fn isEqualToData_(self, otherData: id) -> id; unsafe fn length(self) -> NSUInteger; - unsafe fn writeToFile_atomically_(self, path: id, atomically: BOOL) -> BOOL; - unsafe fn writeToFile_options_error_(self, path: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL; - unsafe fn writeToURL_atomically_(self, aURL: id, atomically: BOOL) -> BOOL; - unsafe fn writeToURL_options_error_(self, aURL: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL; + unsafe fn writeToFile_atomically_(self, path: id, atomically: bool) -> bool; + unsafe fn writeToFile_options_error_(self, path: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> bool; + unsafe fn writeToURL_atomically_(self, aURL: id, atomically: bool) -> bool; + unsafe fn writeToURL_options_error_(self, aURL: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> bool; } impl NSData for id { unsafe fn initWithBase64EncodedData_options_(self, base64Data: id, options: NSDataBase64DecodingOptions) -> id { - msg_send![self, initWithBase64EncodedData:base64Data options:options] + msg_send![self, initWithBase64EncodedData: base64Data, options: options] } unsafe fn initWithBase64EncodedString_options_(self, base64String: id, options: NSDataBase64DecodingOptions) -> id { - msg_send![self, initWithBase64EncodedString:base64String options:options] + msg_send![self, initWithBase64EncodedString: base64String, options: options] } unsafe fn initWithBytes_length_(self, bytes: *const c_void, length: NSUInteger) -> id { - msg_send![self,initWithBytes:bytes length:length] + msg_send![self, initWithBytes: bytes, length: length] } unsafe fn initWithBytesNoCopy_length_(self, bytes: *const c_void, length: NSUInteger) -> id { - msg_send![self, initWithBytesNoCopy:bytes length:length] + msg_send![self, initWithBytesNoCopy: bytes, length: length] } unsafe fn initWithBytesNoCopy_length_deallocator_(self, bytes: *const c_void, length: NSUInteger, deallocator: *mut Block<(*const c_void, NSUInteger), ()>) -> id { - msg_send![self, initWithBytesNoCopy:bytes length:length deallocator:deallocator] + msg_send![self, initWithBytesNoCopy: bytes, length: length, deallocator: deallocator] } unsafe fn initWithBytesNoCopy_length_freeWhenDone_(self, bytes: *const c_void, - length: NSUInteger, freeWhenDone: BOOL) -> id { - msg_send![self, initWithBytesNoCopy:bytes length:length freeWhenDone:freeWhenDone] + length: NSUInteger, freeWhenDone: bool) -> id { + msg_send![self, initWithBytesNoCopy: bytes, length: length, freeWhenDone: freeWhenDone] } unsafe fn initWithContentsOfFile_(self, path: id) -> id { @@ -1250,7 +1272,7 @@ impl NSData for id { unsafe fn initWithContentsOfFile_options_error(self, path: id, mask: NSDataReadingOptions, errorPtr: *mut id) -> id { - msg_send![self, initWithContentsOfFile:path options:mask error:errorPtr] + msg_send![self, initWithContentsOfFile: path, options: mask, error: errorPtr] } unsafe fn initWithContentsOfURL_(self, aURL: id) -> id { @@ -1259,7 +1281,7 @@ impl NSData for id { unsafe fn initWithContentsOfURL_options_error_(self, aURL: id, mask: NSDataReadingOptions, errorPtr: *mut id) -> id { - msg_send![self, initWithContentsOfURL:aURL options:mask error:errorPtr] + msg_send![self, initWithContentsOfURL: aURL, options: mask, error: errorPtr] } unsafe fn initWithData_(self, data: id) -> id { @@ -1274,16 +1296,16 @@ impl NSData for id { msg_send![self, description] } - unsafe fn enumerateByteRangesUsingBlock_(self, block: *mut Block<(*const c_void, NSRange, *mut BOOL), ()>) { + unsafe fn enumerateByteRangesUsingBlock_(self, block: *mut Block<(*const c_void, NSRange, *mut Bool), ()>) { msg_send![self, enumerateByteRangesUsingBlock:block] } unsafe fn getBytes_length_(self, buffer: *mut c_void, length: NSUInteger) { - msg_send![self, getBytes:buffer length:length] + msg_send![self, getBytes: buffer, length: length] } unsafe fn getBytes_range_(self, buffer: *mut c_void, range: NSRange) { - msg_send![self, getBytes:buffer range:range] + msg_send![self, getBytes: buffer, range: range] } unsafe fn subdataWithRange_(self, range: NSRange) -> id { @@ -1292,7 +1314,7 @@ impl NSData for id { unsafe fn rangeOfData_options_range_(self, dataToFind: id, options: NSDataSearchOptions, searchRange: NSRange) -> NSRange { - msg_send![self, rangeOfData:dataToFind options:options range:searchRange] + msg_send![self, rangeOfData: dataToFind, options: options, range: searchRange] } unsafe fn base64EncodedDataWithOptions_(self, options: NSDataBase64EncodingOptions) -> id { @@ -1311,20 +1333,20 @@ impl NSData for id { msg_send![self, length] } - unsafe fn writeToFile_atomically_(self, path: id, atomically: BOOL) -> BOOL { - msg_send![self, writeToFile:path atomically:atomically] + unsafe fn writeToFile_atomically_(self, path: id, atomically: bool) -> bool { + msg_send![self, writeToFile: path, atomically: atomically] } - unsafe fn writeToFile_options_error_(self, path: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL { - msg_send![self, writeToFile:path options:mask error:errorPtr] + unsafe fn writeToFile_options_error_(self, path: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> bool { + msg_send![self, writeToFile: path, options: mask, error: errorPtr] } - unsafe fn writeToURL_atomically_(self, aURL: id, atomically: BOOL) -> BOOL { - msg_send![self, writeToURL:aURL atomically:atomically] + unsafe fn writeToURL_atomically_(self, aURL: id, atomically: bool) -> bool { + msg_send![self, writeToURL: aURL, atomically: atomically] } - unsafe fn writeToURL_options_error_(self, aURL: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> BOOL { - msg_send![self, writeToURL:aURL options:mask error:errorPtr] + unsafe fn writeToURL_options_error_(self, aURL: id, mask: NSDataWritingOptions, errorPtr: *mut id) -> bool { + msg_send![self, writeToURL: aURL, options: mask, error: errorPtr] } } @@ -1336,6 +1358,8 @@ bitflags! { } } +impl_Encode!(NSDataReadingOptions, libc::c_ulonglong); + bitflags! { pub struct NSDataBase64EncodingOptions: libc::c_ulonglong { const NSDataBase64Encoding64CharacterLineLength = 1 << 0; @@ -1345,12 +1369,16 @@ bitflags! { } } +impl_Encode!(NSDataBase64EncodingOptions, libc::c_ulonglong); + bitflags! { pub struct NSDataBase64DecodingOptions: libc::c_ulonglong { const NSDataBase64DecodingIgnoreUnknownCharacters = 1 << 0; } } +impl_Encode!(NSDataBase64DecodingOptions, libc::c_ulonglong); + bitflags! { pub struct NSDataWritingOptions: libc::c_ulonglong { const NSDataWritingAtomic = 1 << 0; @@ -1358,6 +1386,8 @@ bitflags! { } } +impl_Encode!(NSDataWritingOptions, libc::c_ulonglong); + bitflags! { pub struct NSDataSearchOptions: libc::c_ulonglong { const NSDataSearchBackwards = 1 << 0; @@ -1365,11 +1395,13 @@ bitflags! { } } +impl_Encode!(NSDataSearchOptions, libc::c_ulonglong); + pub trait NSUserDefaults { unsafe fn standardUserDefaults() -> Self; - unsafe fn setBool_forKey_(self, value: BOOL, key: id); - unsafe fn bool_forKey_(self, key: id) -> BOOL; + unsafe fn setBool_forKey_(self, value: bool, key: id); + unsafe fn bool_forKey_(self, key: id) -> bool; unsafe fn removeObject_forKey_(self, key: id); } @@ -1379,11 +1411,11 @@ impl NSUserDefaults for id { msg_send![class!(NSUserDefaults), standardUserDefaults] } - unsafe fn setBool_forKey_(self, value: BOOL, key: id) { - msg_send![self, setBool:value forKey:key] + unsafe fn setBool_forKey_(self, value: bool, key: id) { + msg_send![self, setBool: value, forKey: key] } - unsafe fn bool_forKey_(self, key: id) -> BOOL { + unsafe fn bool_forKey_(self, key: id) -> bool { msg_send![self, boolForKey: key] } diff --git a/cocoa-foundation/src/lib.rs b/cocoa-foundation/src/lib.rs index 6a23ccb88..a22b62694 100644 --- a/cocoa-foundation/src/lib.rs +++ b/cocoa-foundation/src/lib.rs @@ -16,8 +16,20 @@ extern crate core_foundation; extern crate core_graphics_types; extern crate foreign_types; extern crate libc; +pub extern crate objc2_encode; #[macro_use] -extern crate objc; +extern crate objc2; + +pub use objc2_encode as __objc2_encode; + +#[macro_export] +macro_rules! impl_Encode { + ($t:ty, $delegation:ty) => { + unsafe impl $crate::__objc2_encode::Encode for $t { + const ENCODING: $crate::__objc2_encode::Encoding = <$delegation>::ENCODING; + } + } +} pub mod base; pub mod foundation; diff --git a/cocoa-foundation/tests/foundation.rs b/cocoa-foundation/tests/foundation.rs index ab6401bbb..e0a0de9c9 100644 --- a/cocoa-foundation/tests/foundation.rs +++ b/cocoa-foundation/tests/foundation.rs @@ -1,5 +1,5 @@ #[macro_use] -extern crate objc; +extern crate objc2; extern crate block; extern crate cocoa_foundation; @@ -160,16 +160,18 @@ mod foundation { } // First test cocoa sorting... - let mut comparator = ConcreteBlock::new(|s0: id, s1: id| { + let comparator = ConcreteBlock::new(|s0: id, s1: id| { match compare_function(&s0, &s1) { Ordering::Less => NSComparisonResult::NSOrderedAscending, Ordering::Equal => NSComparisonResult::NSOrderedSame, Ordering::Greater => NSComparisonResult::NSOrderedDescending, } }); + let comparator_ptr: *const _ = &*comparator; + let comparator_ptr = comparator_ptr as *mut _; let associated_iter = keys.iter().zip(objects.iter()); - for (k_id, (k, v)) in dict.keysSortedByValueUsingComparator_(&mut *comparator) + for (k_id, (k, v)) in dict.keysSortedByValueUsingComparator_(comparator_ptr) .iter() .zip(associated_iter) { assert!(k_id.isEqualToString(k)); diff --git a/cocoa/Cargo.toml b/cocoa/Cargo.toml index 8746773ee..9510cea47 100644 --- a/cocoa/Cargo.toml +++ b/cocoa/Cargo.toml @@ -12,11 +12,12 @@ license = "MIT / Apache-2.0" default-target = "x86_64-apple-darwin" [dependencies] -block = "0.1" +block = { version = "=0.2.0-alpha.6", package = "block2" } bitflags = "1.0" libc = "0.2" cocoa-foundation = { path = "../cocoa-foundation", version = "0.1" } core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics = { path = "../core-graphics", version = "0.22" } foreign-types = "0.3" -objc = "0.2.3" +objc2 = { version = "=0.3.0-beta.2" } +objc2-encode = { version = "=2.0.0-pre.2" } diff --git a/cocoa/examples/color.rs b/cocoa/examples/color.rs index af31514dd..f8140ce44 100644 --- a/cocoa/examples/color.rs +++ b/cocoa/examples/color.rs @@ -1,6 +1,6 @@ extern crate cocoa; -use cocoa::base::{selector, id, nil, NO}; +use cocoa::base::{selector, id, nil}; use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSString}; @@ -78,7 +78,7 @@ unsafe fn create_window(title: id, color: id) -> id { NSWindowStyleMask::NSMiniaturizableWindowMask | NSWindowStyleMask::NSUnifiedTitleAndToolbarWindowMask, NSBackingStoreType::NSBackingStoreBuffered, - NO + false ).autorelease(); window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); diff --git a/cocoa/examples/fullscreen.rs b/cocoa/examples/fullscreen.rs index c826a29ae..ad97e2629 100644 --- a/cocoa/examples/fullscreen.rs +++ b/cocoa/examples/fullscreen.rs @@ -2,9 +2,9 @@ extern crate cocoa; extern crate core_graphics; #[macro_use] -extern crate objc; +extern crate objc2; -use cocoa::base::{selector, nil, NO, id}; +use cocoa::base::{selector, nil, id}; use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSString, NSUInteger}; use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, @@ -14,8 +14,8 @@ use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, use core_graphics::display::CGDisplay; -use objc::runtime::{Object, Sel}; -use objc::declare::ClassDecl; +use objc2::runtime::{Object, Sel}; +use objc2::declare::ClassBuilder; fn main() { unsafe { @@ -45,7 +45,7 @@ fn main() { // Create NSWindowDelegate let superclass = class!(NSObject); - let mut decl = ClassDecl::new("MyWindowDelegate", superclass).unwrap(); + let mut decl = ClassBuilder::new("MyWindowDelegate", superclass).unwrap(); extern fn will_use_fillscreen_presentation_options(_: &Object, _: Sel, _: id, _: NSUInteger) -> NSUInteger { // Set initial presentation options for fullscreen @@ -65,11 +65,11 @@ fn main() { } decl.add_method(sel!(window:willUseFullScreenPresentationOptions:), - will_use_fillscreen_presentation_options as extern fn(&Object, Sel, id, NSUInteger) -> NSUInteger); + will_use_fillscreen_presentation_options as extern fn(_, _, _, _) -> _); decl.add_method(sel!(windowWillEnterFullScreen:), - window_entering_fullscreen as extern fn(&Object, Sel, id)); + window_entering_fullscreen as extern fn(_, _, _)); decl.add_method(sel!(windowDidEnterFullScreen:), - window_entering_fullscreen as extern fn(&Object, Sel, id)); + window_entering_fullscreen as extern fn(_, _, _)); let delegate_class = decl.register(); let delegate_object = msg_send![delegate_class, new]; @@ -81,7 +81,7 @@ fn main() { .initWithContentRect_styleMask_backing_defer_(NSRect::new(NSPoint::new(0., 0.), size), NSWindowStyleMask::NSTitledWindowMask, NSBackingStoreBuffered, - NO) + false) .autorelease(); window.setDelegate_(delegate_object); let title = NSString::alloc(nil).init_str("Fullscreen!"); diff --git a/cocoa/examples/hello_world.rs b/cocoa/examples/hello_world.rs index 4d5c1b08c..d135d27f4 100644 --- a/cocoa/examples/hello_world.rs +++ b/cocoa/examples/hello_world.rs @@ -1,6 +1,6 @@ extern crate cocoa; -use cocoa::base::{selector, nil, NO}; +use cocoa::base::{selector, nil}; use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSString}; use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, @@ -39,7 +39,7 @@ fn main() { NSSize::new(200., 200.)), NSWindowStyleMask::NSTitledWindowMask, NSBackingStoreBuffered, - NO) + false) .autorelease(); window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); window.center(); diff --git a/cocoa/examples/tab_view.rs b/cocoa/examples/tab_view.rs index 985487f75..f9a2c6d39 100644 --- a/cocoa/examples/tab_view.rs +++ b/cocoa/examples/tab_view.rs @@ -1,6 +1,6 @@ extern crate cocoa; -use cocoa::base::{selector, id, nil, NO}; +use cocoa::base::{selector, id, nil}; use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, @@ -71,7 +71,7 @@ unsafe fn create_app(title: id, content: id) -> id { NSWindowStyleMask::NSMiniaturizableWindowMask | NSWindowStyleMask::NSUnifiedTitleAndToolbarWindowMask, NSBackingStoreType::NSBackingStoreBuffered, - NO + false ).autorelease(); window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); window.center(); diff --git a/cocoa/src/appkit.rs b/cocoa/src/appkit.rs index 51429e8e0..8001c8405 100644 --- a/cocoa/src/appkit.rs +++ b/cocoa/src/appkit.rs @@ -9,10 +9,11 @@ #![allow(non_upper_case_globals)] -use base::{id, BOOL, SEL}; +use base::{id, SEL}; use block::Block; use foundation::{NSInteger, NSUInteger, NSTimeInterval, NSPoint, NSSize, NSRect, NSRange, NSRectEdge}; +use objc2::runtime::Bool; use libc; pub use core_graphics::base::CGFloat; @@ -167,6 +168,8 @@ pub enum NSApplicationActivationPolicy { NSApplicationActivationPolicyERROR = -1 } +impl_Encode!(NSApplicationActivationPolicy, i64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSApplicationActivationOptions { @@ -174,6 +177,8 @@ pub enum NSApplicationActivationOptions { NSApplicationActivateIgnoringOtherApps = 1 << 1 } +impl_Encode!(NSApplicationActivationOptions, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSApplicationTerminateReply { @@ -182,6 +187,8 @@ pub enum NSApplicationTerminateReply { NSTerminateLater = 2, } +impl_Encode!(NSApplicationTerminateReply, u64); + bitflags! { pub struct NSApplicationPresentationOptions : NSUInteger { const NSApplicationPresentationDefault = 0; @@ -200,6 +207,8 @@ bitflags! { } } +impl_Encode!(NSApplicationPresentationOptions, NSUInteger); + bitflags! { pub struct NSWindowStyleMask: NSUInteger { const NSBorderlessWindowMask = 0; @@ -218,6 +227,8 @@ bitflags! { } } +impl_Encode!(NSWindowStyleMask, NSUInteger); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSWindowTitleVisibility { @@ -225,6 +236,8 @@ pub enum NSWindowTitleVisibility { NSWindowTitleHidden = 1 } +impl_Encode!(NSWindowTitleVisibility, u64); + #[repr(i64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSWindowTabbingMode { @@ -233,6 +246,8 @@ pub enum NSWindowTabbingMode { NSWindowTabbingModePreferred = 2 } +impl_Encode!(NSWindowTabbingMode, i64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSBackingStoreType { @@ -241,6 +256,8 @@ pub enum NSBackingStoreType { NSBackingStoreBuffered = 2 } +impl_Encode!(NSBackingStoreType, u64); + bitflags! { pub struct NSWindowOrderingMode: NSInteger { const NSWindowAbove = 1; @@ -249,6 +266,8 @@ bitflags! { } } +impl_Encode!(NSWindowOrderingMode, NSInteger); + bitflags! { pub struct NSAlignmentOptions: libc::c_ulonglong { const NSAlignMinXInward = 1 << 0; @@ -285,6 +304,8 @@ bitflags! { } } +impl_Encode!(NSAlignmentOptions, libc::c_ulonglong); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSOpenGLPixelFormatAttribute { @@ -329,6 +350,8 @@ pub enum NSOpenGLPixelFormatAttribute { NSOpenGLPFAVirtualScreenCount = 128, } +impl_Encode!(NSOpenGLPixelFormatAttribute, u64); + #[repr(u64)] #[allow(non_camel_case_types)] #[derive(Clone, Copy, Debug, PartialEq)] @@ -338,6 +361,8 @@ pub enum NSOpenGLPFAOpenGLProfiles { NSOpenGLProfileVersion4_1Core = 0x4100, } +impl_Encode!(NSOpenGLPFAOpenGLProfiles, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSOpenGLContextParameter { @@ -353,6 +378,8 @@ pub enum NSOpenGLContextParameter { NSOpenGLCPMPSwapsInFlight = 315, } +impl_Encode!(NSOpenGLContextParameter, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSWindowButton { @@ -365,6 +392,8 @@ pub enum NSWindowButton { NSWindowFullScreenButton = 7, } +impl_Encode!(NSWindowButton, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSBezelStyle { @@ -382,6 +411,8 @@ pub enum NSBezelStyle { NSRoundedDisclosureBezelStyle = 14, } +impl_Encode!(NSBezelStyle, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSRequestUserAttentionType { @@ -389,6 +420,8 @@ pub enum NSRequestUserAttentionType { NSInformationalRequest = 10, } +impl_Encode!(NSRequestUserAttentionType, u64); + pub static NSMainMenuWindowLevel: i32 = 24; pub trait NSApplication: Sized { @@ -397,22 +430,22 @@ pub trait NSApplication: Sized { } unsafe fn mainMenu(self) -> id; - unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL; - unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions) -> BOOL; + unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> bool; + unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions) -> bool; unsafe fn presentationOptions_(self) -> NSApplicationPresentationOptions; unsafe fn setMainMenu_(self, menu: id); unsafe fn setServicesMenu_(self, menu: id); unsafe fn setWindowsMenu_(self, menu: id); - unsafe fn activateIgnoringOtherApps_(self, ignore: BOOL); + unsafe fn activateIgnoringOtherApps_(self, ignore: bool); unsafe fn run(self); unsafe fn finishLaunching(self); unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, mask: NSUInteger, expiration: id, in_mode: id, - dequeue: BOOL) -> id; + dequeue: bool) -> id; unsafe fn sendEvent_(self, an_event: id); - unsafe fn postEvent_atStart_(self, anEvent: id, flag: BOOL); + unsafe fn postEvent_atStart_(self, anEvent: id, flag: bool); unsafe fn stop_(self, sender: id); unsafe fn setApplicationIconImage_(self, image: id); unsafe fn requestUserAttention_(self, requestType: NSRequestUserAttentionType); @@ -423,11 +456,11 @@ impl NSApplication for id { msg_send![self, mainMenu] } - unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL { + unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> bool { msg_send![self, setActivationPolicy:policy as NSInteger] } - unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions) -> BOOL { + unsafe fn setPresentationOptions_(self, options: NSApplicationPresentationOptions) -> bool { msg_send![self, setPresentationOptions:options.bits] } @@ -448,8 +481,8 @@ impl NSApplication for id { msg_send![self, setWindowsMenu:menu] } - unsafe fn activateIgnoringOtherApps_(self, ignore: BOOL) { - msg_send![self, activateIgnoringOtherApps:ignore] + unsafe fn activateIgnoringOtherApps_(self, ignore: bool) { + msg_send![self, activateIgnoringOtherApps: ignore] } unsafe fn run(self) { @@ -464,10 +497,10 @@ impl NSApplication for id { mask: NSUInteger, expiration: id, in_mode: id, - dequeue: BOOL) -> id { - msg_send![self, nextEventMatchingMask:mask - untilDate:expiration - inMode:in_mode + dequeue: bool) -> id { + msg_send![self, nextEventMatchingMask:mask, + untilDate:expiration, + inMode:in_mode, dequeue:dequeue] } @@ -475,8 +508,8 @@ impl NSApplication for id { msg_send![self, sendEvent:an_event] } - unsafe fn postEvent_atStart_(self, anEvent: id, flag: BOOL) { - msg_send![self, postEvent:anEvent atStart:flag] + unsafe fn postEvent_atStart_(self, anEvent: id, flag: bool) { + msg_send![self, postEvent: anEvent, atStart: flag] } unsafe fn stop_(self, sender: id) { @@ -497,7 +530,7 @@ pub trait NSRunningApplication: Sized { msg_send![class!(NSRunningApplication), currentApplication] } - unsafe fn activateWithOptions_(self, options: NSApplicationActivationOptions) -> BOOL; + unsafe fn activateWithOptions_(self, options: NSApplicationActivationOptions) -> bool; unsafe fn runningApplicationWithProcessIdentifier(_: Self, pid: libc::pid_t) -> id { msg_send![class!(NSRunningApplication), runningApplicationWithProcessIdentifier:pid] @@ -505,7 +538,7 @@ pub trait NSRunningApplication: Sized { } impl NSRunningApplication for id { - unsafe fn activateWithOptions_(self, options: NSApplicationActivationOptions) -> BOOL { + unsafe fn activateWithOptions_(self, options: NSApplicationActivationOptions) -> bool { msg_send![self, activateWithOptions:options as NSUInteger] } } @@ -516,7 +549,7 @@ pub trait NSPasteboard: Sized { } unsafe fn pasteboardByFilteringData_ofType(_: Self, data: id, _type: id) -> id { - msg_send![class!(NSPasteboard), pasteboardByFilteringData:data ofType:_type] + msg_send![class!(NSPasteboard), pasteboardByFilteringData:data, ofType:_type] } unsafe fn pasteboardByFilteringFile(_: Self, file: id) -> id { @@ -538,10 +571,10 @@ pub trait NSPasteboard: Sized { unsafe fn releaseGlobally(self); unsafe fn clearContents(self) -> NSInteger; - unsafe fn writeObjects(self, objects: id) -> BOOL; - unsafe fn setData_forType(self, data: id, dataType: id) -> BOOL; - unsafe fn setPropertyList_forType(self, plist: id, dataType: id) -> BOOL; - unsafe fn setString_forType(self, string: id, dataType: id) -> BOOL; + unsafe fn writeObjects(self, objects: id) -> bool; + unsafe fn setData_forType(self, data: id, dataType: id) -> bool; + unsafe fn setPropertyList_forType(self, plist: id, dataType: id) -> bool; + unsafe fn setString_forType(self, string: id, dataType: id) -> bool; unsafe fn readObjectsForClasses_options(self, classArray: id, options: id) -> id; unsafe fn pasteboardItems(self) -> id; @@ -551,8 +584,8 @@ pub trait NSPasteboard: Sized { unsafe fn stringForType(self, dataType: id) -> id; unsafe fn availableTypeFromArray(self, types: id) -> id; - unsafe fn canReadItemWithDataConformingToTypes(self, types: id) -> BOOL; - unsafe fn canReadObjectForClasses_options(self, classArray: id, options: id) -> BOOL; + unsafe fn canReadItemWithDataConformingToTypes(self, types: id) -> bool; + unsafe fn canReadObjectForClasses_options(self, classArray: id, options: id) -> bool; unsafe fn types(self) -> id; unsafe fn typesFilterableTo(_: Self, _type: id) -> id { msg_send![class!(NSPasteboard), typesFilterableTo:_type] @@ -563,8 +596,8 @@ pub trait NSPasteboard: Sized { unsafe fn declareTypes_owner(self, newTypes: id, newOwner: id) -> NSInteger; unsafe fn addTypes_owner(self, newTypes: id, newOwner: id) -> NSInteger; - unsafe fn writeFileContents(self, filename: id) -> BOOL; - unsafe fn writeFileWrapper(self, wrapper: id) -> BOOL; + unsafe fn writeFileContents(self, filename: id) -> bool; + unsafe fn writeFileWrapper(self, wrapper: id) -> bool; unsafe fn readFileContentsType_toFile(self, _type: id, filename: id) -> id; unsafe fn readFileWrapper(self) -> id; @@ -579,24 +612,24 @@ impl NSPasteboard for id { msg_send![self, clearContents] } - unsafe fn writeObjects(self, objects: id) -> BOOL { + unsafe fn writeObjects(self, objects: id) -> bool { msg_send![self, writeObjects:objects] } - unsafe fn setData_forType(self, data: id, dataType: id) -> BOOL { - msg_send![self, setData:data forType:dataType] + unsafe fn setData_forType(self, data: id, dataType: id) -> bool { + msg_send![self, setData: data, forType: dataType] } - unsafe fn setPropertyList_forType(self, plist: id, dataType: id) -> BOOL { - msg_send![self, setPropertyList:plist forType:dataType] + unsafe fn setPropertyList_forType(self, plist: id, dataType: id) -> bool { + msg_send![self, setPropertyList: plist, forType: dataType] } - unsafe fn setString_forType(self, string: id, dataType: id) -> BOOL { - msg_send![self, setString:string forType:dataType] + unsafe fn setString_forType(self, string: id, dataType: id) -> bool { + msg_send![self, setString: string, forType: dataType] } unsafe fn readObjectsForClasses_options(self, classArray: id, options: id) -> id { - msg_send![self, readObjectsForClasses:classArray options:options] + msg_send![self, readObjectsForClasses: classArray, options: options] } unsafe fn pasteboardItems(self) -> id { @@ -623,12 +656,12 @@ impl NSPasteboard for id { msg_send![self, availableTypeFromArray:types] } - unsafe fn canReadItemWithDataConformingToTypes(self, types: id) -> BOOL { + unsafe fn canReadItemWithDataConformingToTypes(self, types: id) -> bool { msg_send![self, canReadItemWithDataConformingToTypes:types] } - unsafe fn canReadObjectForClasses_options(self, classArray: id, options: id) -> BOOL { - msg_send![self, canReadObjectForClasses:classArray options:options] + unsafe fn canReadObjectForClasses_options(self, classArray: id, options: id) -> bool { + msg_send![self, canReadObjectForClasses: classArray, options: options] } unsafe fn types(self) -> id { @@ -644,23 +677,23 @@ impl NSPasteboard for id { } unsafe fn declareTypes_owner(self, newTypes: id, newOwner: id) -> NSInteger { - msg_send![self, declareTypes:newTypes owner:newOwner] + msg_send![self, declareTypes: newTypes, owner: newOwner] } unsafe fn addTypes_owner(self, newTypes: id, newOwner: id) -> NSInteger { - msg_send![self, addTypes:newTypes owner:newOwner] + msg_send![self, addTypes: newTypes, owner: newOwner] } - unsafe fn writeFileContents(self, filename: id) -> BOOL { + unsafe fn writeFileContents(self, filename: id) -> bool { msg_send![self, writeFileContents:filename] } - unsafe fn writeFileWrapper(self, wrapper: id) -> BOOL { + unsafe fn writeFileWrapper(self, wrapper: id) -> bool { msg_send![self, writeFileWrapper:wrapper] } unsafe fn readFileContentsType_toFile(self, _type: id, filename: id) -> id { - msg_send![self, readFileContentsType:_type toFile:filename] + msg_send![self, readFileContentsType: _type, toFile: filename] } unsafe fn readFileWrapper(self) -> id { @@ -672,10 +705,10 @@ impl NSPasteboard for id { pub trait NSPasteboardItem: Sized { unsafe fn types(self) -> id; - unsafe fn setDataProvider_forTypes(self, dataProvider: id, types: id) -> BOOL; - unsafe fn setData_forType(self, data: id, _type: id) -> BOOL; - unsafe fn setString_forType(self, string: id, _type: id) -> BOOL; - unsafe fn setPropertyList_forType(self, propertyList: id, _type: id) -> BOOL; + unsafe fn setDataProvider_forTypes(self, dataProvider: id, types: id) -> bool; + unsafe fn setData_forType(self, data: id, _type: id) -> bool; + unsafe fn setString_forType(self, string: id, _type: id) -> bool; + unsafe fn setPropertyList_forType(self, propertyList: id, _type: id) -> bool; unsafe fn dataForType(self, _type: id) -> id; unsafe fn stringForType(self, _type: id) -> id; @@ -687,20 +720,20 @@ impl NSPasteboardItem for id { msg_send![self, types] } - unsafe fn setDataProvider_forTypes(self, dataProvider: id, types: id) -> BOOL { - msg_send![self, setDataProvider:dataProvider forTypes:types] + unsafe fn setDataProvider_forTypes(self, dataProvider: id, types: id) -> bool { + msg_send![self, setDataProvider: dataProvider, forTypes: types] } - unsafe fn setData_forType(self, data: id, _type: id) -> BOOL { - msg_send![self, setData:data forType:_type] + unsafe fn setData_forType(self, data: id, _type: id) -> bool { + msg_send![self, setData: data, forType: _type] } - unsafe fn setString_forType(self, string: id, _type: id) -> BOOL { - msg_send![self, setString:string forType:_type] + unsafe fn setString_forType(self, string: id, _type: id) -> bool { + msg_send![self, setString: string, forType: _type] } - unsafe fn setPropertyList_forType(self, propertyList: id, _type: id) -> BOOL { - msg_send![self, setPropertyList:propertyList forType:_type] + unsafe fn setPropertyList_forType(self, propertyList: id, _type: id) -> bool { + msg_send![self, setPropertyList: propertyList, forType: _type] } unsafe fn dataForType(self, _type: id) -> id { @@ -723,7 +756,7 @@ pub trait NSPasteboardItemDataProvider: Sized { impl NSPasteboardItemDataProvider for id { unsafe fn pasteboard_item_provideDataForType(self, pasteboard: id, item: id, _type: id) { - msg_send![self, pasteboard:pasteboard item:item provideDataForType:_type] + msg_send![self, pasteboard: pasteboard, item: item, provideDataForType: _type] } unsafe fn pasteboardFinishedWithDataProvider(self, pasteboard: id) { @@ -744,7 +777,7 @@ impl NSPasteboardWriting for id { } unsafe fn writingOptionsForType_pasteboard(self, _type: id, pasteboard: id) -> NSPasteboardWritingOptions { - msg_send![self, writingOptionsForType:_type pasteboard:pasteboard] + msg_send![self, writingOptionsForType: _type, pasteboard: pasteboard] } unsafe fn pasteboardPropertyListForType(self, _type: id) -> id { @@ -761,7 +794,7 @@ pub trait NSPasteboardReading: Sized { impl NSPasteboardReading for id { unsafe fn initWithPasteboardPropertyList_ofType(self, propertyList: id, _type: id) -> id { - msg_send![self, initWithPasteboardPropertyList:propertyList ofType:_type] + msg_send![self, initWithPasteboardPropertyList: propertyList, ofType: _type] } unsafe fn readableTypesForPasteboard(self, pasteboard: id) -> id { @@ -770,7 +803,7 @@ impl NSPasteboardReading for id { } unsafe fn readingOptionsForType_pasteboard(self, _type: id, pasteboard: id) -> NSPasteboardReadingOptions { let class: id = msg_send![self, class]; - msg_send![class, readingOptionsForType:_type pasteboard:pasteboard] + msg_send![class, readingOptionsForType: _type, pasteboard: pasteboard] } } @@ -783,12 +816,16 @@ pub enum NSPasteboardReadingOptions { NSPasteboardReadingAsKeyedArchive = 1 << 2 } +impl_Encode!(NSPasteboardReadingOptions, u64); + #[repr(u64)] #[derive(Clone, Copy, Debug, PartialEq)] pub enum NSPasteboardWritingOptions { NSPasteboardWritingPromised = 1 << 9, } +impl_Encode!(NSPasteboardWritingOptions, u64); + pub trait NSMenu: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSMenu), alloc] @@ -799,7 +836,7 @@ pub trait NSMenu: Sized { } unsafe fn initWithTitle_(self, title: id /* NSString */) -> id; - unsafe fn setAutoenablesItems(self, state: BOOL); + unsafe fn setAutoenablesItems(self, state: bool); unsafe fn addItem_(self, menu_item: id); unsafe fn addItemWithTitle_action_keyEquivalent(self, title: id, action: SEL, key: id) -> id; @@ -811,7 +848,7 @@ impl NSMenu for id { msg_send![self, initWithTitle:title] } - unsafe fn setAutoenablesItems(self, state: BOOL) { + unsafe fn setAutoenablesItems(self, state: bool) { msg_send![self, setAutoenablesItems: state] } @@ -820,7 +857,7 @@ impl NSMenu for id { } unsafe fn addItemWithTitle_action_keyEquivalent(self, title: id, action: SEL, key: id) -> id { - msg_send![self, addItemWithTitle:title action:action keyEquivalent:key] + msg_send![self, addItemWithTitle: title, action: action, keyEquivalent: key] } unsafe fn itemAtIndex_(self, index: NSInteger) -> id { @@ -849,7 +886,7 @@ pub trait NSMenuItem: Sized { impl NSMenuItem for id { unsafe fn initWithTitle_action_keyEquivalent_(self, title: id, action: SEL, key: id) -> id { - msg_send![self, initWithTitle:title action:action keyEquivalent:key] + msg_send![self, initWithTitle: title, action: action, keyEquivalent: key] } unsafe fn setKeyEquivalentModifierMask_(self, mask: NSEventModifierFlags) { @@ -885,12 +922,16 @@ bitflags! { } } +impl_Encode!(NSWindowCollectionBehavior, NSUInteger); + bitflags! { pub struct NSWindowOcclusionState: NSUInteger { const NSWindowOcclusionStateVisible = 1 << 1; } } +impl_Encode!(NSWindowOcclusionState, NSUInteger); + pub trait NSWindow: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSWindow), alloc] @@ -901,19 +942,19 @@ pub trait NSWindow: Sized { rect: NSRect, style: NSWindowStyleMask, backing: NSBackingStoreType, - defer: BOOL) -> id; + defer: bool) -> id; unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self, rect: NSRect, style: NSWindowStyleMask, backing: NSBackingStoreType, - defer: BOOL, + defer: bool, screen: id) -> id; // Configuring Windows unsafe fn styleMask(self) -> NSWindowStyleMask; unsafe fn setStyleMask_(self, styleMask: NSWindowStyleMask); unsafe fn toggleFullScreen_(self, sender: id); - unsafe fn worksWhenModal(self) -> BOOL; + unsafe fn worksWhenModal(self) -> bool; unsafe fn alphaValue(self) -> CGFloat; unsafe fn setAlphaValue_(self, windowAlpha: CGFloat); unsafe fn backgroundColor(self) -> id; @@ -922,26 +963,26 @@ pub trait NSWindow: Sized { unsafe fn setColorSpace_(self, colorSpace: id); unsafe fn contentView(self) -> id; unsafe fn setContentView_(self, view: id); - unsafe fn canHide(self) -> BOOL; - unsafe fn setCanHide_(self, canHide: BOOL); - unsafe fn hidesOnDeactivate(self) -> BOOL; - unsafe fn setHidesOnDeactivate_(self, hideOnDeactivate: BOOL); + unsafe fn canHide(self) -> bool; + unsafe fn setCanHide_(self, canHide: bool); + unsafe fn hidesOnDeactivate(self) -> bool; + unsafe fn setHidesOnDeactivate_(self, hideOnDeactivate: bool); unsafe fn collectionBehavior(self) -> NSWindowCollectionBehavior; unsafe fn setCollectionBehavior_(self, collectionBehavior: NSWindowCollectionBehavior); - unsafe fn setOpaque_(self, opaque: BOOL); - unsafe fn hasShadow(self) -> BOOL; - unsafe fn setHasShadow_(self, hasShadow: BOOL); + unsafe fn setOpaque_(self, opaque: bool); + unsafe fn hasShadow(self) -> bool; + unsafe fn setHasShadow_(self, hasShadow: bool); unsafe fn invalidateShadow(self); - unsafe fn autorecalculatesContentBorderThicknessForEdge_(self, edge: NSRectEdge) -> BOOL; + unsafe fn autorecalculatesContentBorderThicknessForEdge_(self, edge: NSRectEdge) -> bool; unsafe fn setAutorecalculatesContentBorderThickness_forEdge_(self, - autorecalculateContentBorderThickness: BOOL, - edge: NSRectEdge) -> BOOL; + autorecalculateContentBorderThickness: bool, + edge: NSRectEdge) -> bool; unsafe fn contentBorderThicknessForEdge_(self, edge: NSRectEdge) -> CGFloat; unsafe fn setContentBorderThickness_forEdge_(self, borderThickness: CGFloat, edge: NSRectEdge); unsafe fn delegate(self) -> id; unsafe fn setDelegate_(self, delegate: id); - unsafe fn preventsApplicationTerminationWhenModal(self) -> BOOL; - unsafe fn setPreventsApplicationTerminationWhenModal_(self, flag: BOOL); + unsafe fn preventsApplicationTerminationWhenModal(self) -> bool; + unsafe fn setPreventsApplicationTerminationWhenModal_(self, flag: bool); // TODO: Accessing Window Information @@ -965,8 +1006,8 @@ pub trait NSWindow: Sized { unsafe fn setFrameTopLeftPoint_(self, point: NSPoint); unsafe fn constrainFrameRect_toScreen_(self, frameRect: NSRect, screen: id); unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint; - unsafe fn setFrame_display_(self, windowFrame: NSRect, display: BOOL); - unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: BOOL); + unsafe fn setFrame_display_(self, windowFrame: NSRect, display: bool); + unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: bool); unsafe fn aspectRatio(self) -> NSSize; unsafe fn setAspectRatio_(self, aspectRatio: NSSize); unsafe fn minSize(self) -> NSSize; @@ -976,13 +1017,13 @@ pub trait NSWindow: Sized { unsafe fn performZoom_(self, sender: id); unsafe fn zoom_(self, sender: id); unsafe fn resizeFlags(self) -> NSInteger; - unsafe fn showsResizeIndicator(self) -> BOOL; - unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: BOOL); + unsafe fn showsResizeIndicator(self) -> bool; + unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: bool); unsafe fn resizeIncrements(self) -> NSSize; unsafe fn setResizeIncrements_(self, resizeIncrements: NSSize); - unsafe fn preservesContentDuringLiveResize(self) -> BOOL; - unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: BOOL); - unsafe fn inLiveResize(self) -> BOOL; + unsafe fn preservesContentDuringLiveResize(self) -> bool; + unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: bool); + unsafe fn inLiveResize(self) -> bool; // Sizing Content unsafe fn contentAspectRatio(self) -> NSSize; @@ -997,7 +1038,7 @@ pub trait NSWindow: Sized { unsafe fn setContentResizeIncrements_(self, contentResizeIncrements: NSSize); // Managing Window Visibility and Occlusion State - unsafe fn isVisible(self) -> BOOL; // NOTE: Deprecated in 10.9 + unsafe fn isVisible(self) -> bool; // NOTE: Deprecated in 10.9 unsafe fn occlusionState(self) -> NSWindowOcclusionState; // Managing Window Layers @@ -1010,15 +1051,15 @@ pub trait NSWindow: Sized { unsafe fn setLevel_(self, level: NSInteger); // Managing Key Status - unsafe fn isKeyWindow(self) -> BOOL; - unsafe fn canBecomeKeyWindow(self) -> BOOL; + unsafe fn isKeyWindow(self) -> bool; + unsafe fn canBecomeKeyWindow(self) -> bool; unsafe fn makeKeyWindow(self); unsafe fn makeKeyAndOrderFront_(self, sender: id); // skipped: becomeKeyWindow (should not be invoked directly, according to Apple's documentation) // skipped: resignKeyWindow (should not be invoked directly, according to Apple's documentation) // Managing Main Status - unsafe fn canBecomeMainWindow(self) -> BOOL; + unsafe fn canBecomeMainWindow(self) -> bool; unsafe fn makeMainWindow(self); // skipped: becomeMainWindow (should not be invoked directly, according to Apple's documentation) // skipped: resignMainWindow (should not be invoked directly, according to Apple's documentation) @@ -1039,8 +1080,8 @@ pub trait NSWindow: Sized { unsafe fn standardWindowButton_(self, windowButtonKind: NSWindowButton) -> id; // Managing Window Tabs - unsafe fn allowsAutomaticWindowTabbing(_: Self) -> BOOL; - unsafe fn setAllowsAutomaticWindowTabbing_(_: Self, allowsAutomaticWindowTabbing: BOOL); + unsafe fn allowsAutomaticWindowTabbing(_: Self) -> bool; + unsafe fn setAllowsAutomaticWindowTabbing_(_: Self, allowsAutomaticWindowTabbing: bool); unsafe fn tabbingIdentifier(self) -> id; unsafe fn tabbingMode(self) -> NSWindowTabbingMode; unsafe fn setTabbingMode_(self, tabbingMode: NSWindowTabbingMode); @@ -1054,7 +1095,7 @@ pub trait NSWindow: Sized { unsafe fn initialFirstResponder(self) -> id; unsafe fn firstResponder(self) -> id; unsafe fn setInitialFirstResponder_(self, responder: id); - unsafe fn makeFirstResponder_(self, responder: id) -> BOOL; + unsafe fn makeFirstResponder_(self, responder: id) -> bool; // TODO: Managing the Key View Loop @@ -1062,11 +1103,11 @@ pub trait NSWindow: Sized { unsafe fn keyDown_(self, event: id); // Handling Mouse Events - unsafe fn acceptsMouseMovedEvents(self) -> BOOL; - unsafe fn ignoresMouseEvents(self) -> BOOL; - unsafe fn setIgnoresMouseEvents_(self, ignoreMouseEvents: BOOL); + unsafe fn acceptsMouseMovedEvents(self) -> bool; + unsafe fn ignoresMouseEvents(self) -> bool; + unsafe fn setIgnoresMouseEvents_(self, ignoreMouseEvents: bool); unsafe fn mouseLocationOutsideOfEventStream(self) -> NSPoint; - unsafe fn setAcceptsMouseMovedEvents_(self, acceptMouseMovedEvents: BOOL); + unsafe fn setAcceptsMouseMovedEvents_(self, acceptMouseMovedEvents: bool); unsafe fn windowNumberAtPoint_belowWindowWithWindowNumber_(_: Self, point: NSPoint, windowNumber: NSInteger) -> NSInteger; @@ -1087,15 +1128,15 @@ pub trait NSWindow: Sized { unsafe fn convertRectFromScreen_(self, rect: NSRect) -> NSRect; // Accessing Edited Status - unsafe fn isDocumentEdited(self) -> BOOL; - unsafe fn setDocumentEdited_(self, documentEdited: BOOL); + unsafe fn isDocumentEdited(self) -> bool; + unsafe fn setDocumentEdited_(self, documentEdited: bool); // Managing Titles unsafe fn title(self) -> id; unsafe fn setTitle_(self, title: id); unsafe fn setTitleWithRepresentedFilename_(self, filePath: id); unsafe fn setTitleVisibility_(self, visibility: NSWindowTitleVisibility); - unsafe fn setTitlebarAppearsTransparent_(self, transparent: BOOL); + unsafe fn setTitlebarAppearsTransparent_(self, transparent: bool); unsafe fn representedFilename(self) -> id; unsafe fn setRepresentedFilename_(self, filePath: id); unsafe fn representedURL(self) -> id; @@ -1104,18 +1145,18 @@ pub trait NSWindow: Sized { // Accessing Screen Information unsafe fn screen(self) -> id; unsafe fn deepestScreen(self) -> id; - unsafe fn displaysWhenScreenProfileChanges(self) -> BOOL; - unsafe fn setDisplaysWhenScreenProfileChanges_(self, displaysWhenScreenProfileChanges: BOOL); + unsafe fn displaysWhenScreenProfileChanges(self) -> bool; + unsafe fn setDisplaysWhenScreenProfileChanges_(self, displaysWhenScreenProfileChanges: bool); // Moving Windows - unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: BOOL); - unsafe fn setMovable_(self, movable: BOOL); + unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: bool); + unsafe fn setMovable_(self, movable: bool); unsafe fn center(self); // Closing Windows unsafe fn performClose_(self, sender: id); unsafe fn close(self); - unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: BOOL); + unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: bool); // Minimizing Windows unsafe fn performMiniaturize_(self, sender: id); @@ -1142,10 +1183,10 @@ impl NSWindow for id { rect: NSRect, style: NSWindowStyleMask, backing: NSBackingStoreType, - defer: BOOL) -> id { - msg_send![self, initWithContentRect:rect - styleMask:style.bits - backing:backing as NSUInteger + defer: bool) -> id { + msg_send![self, initWithContentRect:rect, + styleMask:style.bits, + backing:backing as NSUInteger, defer:defer] } @@ -1153,12 +1194,12 @@ impl NSWindow for id { rect: NSRect, style: NSWindowStyleMask, backing: NSBackingStoreType, - defer: BOOL, + defer: bool, screen: id) -> id { - msg_send![self, initWithContentRect:rect - styleMask:style.bits - backing:backing as NSUInteger - defer:defer + msg_send![self, initWithContentRect:rect, + styleMask:style.bits, + backing:backing as NSUInteger, + defer:defer, screen:screen] } @@ -1176,7 +1217,7 @@ impl NSWindow for id { msg_send![self, toggleFullScreen:sender] } - unsafe fn worksWhenModal(self) -> BOOL { + unsafe fn worksWhenModal(self) -> bool { msg_send![self, worksWhenModal] } @@ -1212,20 +1253,20 @@ impl NSWindow for id { msg_send![self, setContentView:view] } - unsafe fn canHide(self) -> BOOL { + unsafe fn canHide(self) -> bool { msg_send![self, canHide] } - unsafe fn setCanHide_(self, canHide: BOOL) { - msg_send![self, setCanHide:canHide] + unsafe fn setCanHide_(self, canHide: bool) { + msg_send![self, setCanHide: canHide] } - unsafe fn hidesOnDeactivate(self) -> BOOL { + unsafe fn hidesOnDeactivate(self) -> bool { msg_send![self, hidesOnDeactivate] } - unsafe fn setHidesOnDeactivate_(self, hideOnDeactivate: BOOL) { - msg_send![self, setHidesOnDeactivate:hideOnDeactivate] + unsafe fn setHidesOnDeactivate_(self, hideOnDeactivate: bool) { + msg_send![self, setHidesOnDeactivate: hideOnDeactivate] } unsafe fn collectionBehavior(self) -> NSWindowCollectionBehavior { @@ -1236,31 +1277,31 @@ impl NSWindow for id { msg_send![self, setCollectionBehavior:collectionBehavior] } - unsafe fn setOpaque_(self, opaque: BOOL) { - msg_send![self, setOpaque:opaque] + unsafe fn setOpaque_(self, opaque: bool) { + msg_send![self, setOpaque: opaque] } - unsafe fn hasShadow(self) -> BOOL { + unsafe fn hasShadow(self) -> bool { msg_send![self, hasShadow] } - unsafe fn setHasShadow_(self, hasShadow: BOOL) { - msg_send![self, setHasShadow:hasShadow] + unsafe fn setHasShadow_(self, hasShadow: bool) { + msg_send![self, setHasShadow: hasShadow] } unsafe fn invalidateShadow(self) { msg_send![self, invalidateShadow] } - unsafe fn autorecalculatesContentBorderThicknessForEdge_(self, edge: NSRectEdge) -> BOOL { + unsafe fn autorecalculatesContentBorderThicknessForEdge_(self, edge: NSRectEdge) -> bool { msg_send![self, autorecalculatesContentBorderThicknessForEdge:edge] } unsafe fn setAutorecalculatesContentBorderThickness_forEdge_(self, - autorecalculateContentBorderThickness: BOOL, - edge: NSRectEdge) -> BOOL { + autorecalculateContentBorderThickness: bool, + edge: NSRectEdge) -> bool { msg_send![self, setAutorecalculatesContentBorderThickness: - autorecalculateContentBorderThickness forEdge:edge] + autorecalculateContentBorderThickness, forEdge:edge] } unsafe fn contentBorderThicknessForEdge_(self, edge: NSRectEdge) -> CGFloat { @@ -1268,7 +1309,7 @@ impl NSWindow for id { } unsafe fn setContentBorderThickness_forEdge_(self, borderThickness: CGFloat, edge: NSRectEdge) { - msg_send![self, setContentBorderThickness:borderThickness forEdge:edge] + msg_send![self, setContentBorderThickness:borderThickness, forEdge:edge] } unsafe fn delegate(self) -> id { @@ -1279,12 +1320,12 @@ impl NSWindow for id { msg_send![self, setDelegate:delegate] } - unsafe fn preventsApplicationTerminationWhenModal(self) -> BOOL { + unsafe fn preventsApplicationTerminationWhenModal(self) -> bool { msg_send![self, preventsApplicationTerminationWhenModal] } - unsafe fn setPreventsApplicationTerminationWhenModal_(self, flag: BOOL) { - msg_send![self, setPreventsApplicationTerminationWhenModal:flag] + unsafe fn setPreventsApplicationTerminationWhenModal_(self, flag: bool) { + msg_send![self, setPreventsApplicationTerminationWhenModal: flag] } // TODO: Accessing Window Information @@ -1292,15 +1333,15 @@ impl NSWindow for id { // Getting Layout Information unsafe fn contentRectForFrameRect_styleMask_(self, 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_(self, 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_(self, 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 { @@ -1342,19 +1383,19 @@ impl NSWindow for id { } unsafe fn constrainFrameRect_toScreen_(self, frameRect: NSRect, screen: id) { - msg_send![self, constrainFrameRect:frameRect toScreen:screen] + msg_send![self, constrainFrameRect: frameRect, toScreen: screen] } unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint { msg_send![self, cascadeTopLeftFromPoint:topLeft] } - unsafe fn setFrame_display_(self, windowFrame: NSRect, display: BOOL) { - msg_send![self, setFrame:windowFrame display:display] + unsafe fn setFrame_display_(self, windowFrame: NSRect, display: bool) { + msg_send![self, setFrame: windowFrame, display: display] } - unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: BOOL) { - msg_send![self, setFrame:windowFrame displayViews:display] + unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: bool) { + msg_send![self, setFrame: windowFrame, displayViews: display] } unsafe fn aspectRatio(self) -> NSSize { @@ -1393,12 +1434,12 @@ impl NSWindow for id { msg_send![self, resizeFlags] } - unsafe fn showsResizeIndicator(self) -> BOOL { + unsafe fn showsResizeIndicator(self) -> bool { msg_send![self, showsResizeIndicator] } - unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: BOOL) { - msg_send![self, setShowsResizeIndicator:showsResizeIndicator] + unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: bool) { + msg_send![self, setShowsResizeIndicator: showsResizeIndicator] } unsafe fn resizeIncrements(self) -> NSSize { @@ -1409,15 +1450,15 @@ impl NSWindow for id { msg_send![self, setResizeIncrements:resizeIncrements] } - unsafe fn preservesContentDuringLiveResize(self) -> BOOL { + unsafe fn preservesContentDuringLiveResize(self) -> bool { msg_send![self, preservesContentDuringLiveResize] } - unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: BOOL) { - msg_send![self, setPreservesContentDuringLiveResize:preservesContentDuringLiveResize] + unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: bool) { + msg_send![self, setPreservesContentDuringLiveResize: preservesContentDuringLiveResize] } - unsafe fn inLiveResize(self) -> BOOL { + unsafe fn inLiveResize(self) -> bool { msg_send![self, inLiveResize] } @@ -1465,7 +1506,7 @@ impl NSWindow for id { // Managing Window Visibility and Occlusion State - unsafe fn isVisible(self) -> BOOL { + unsafe fn isVisible(self) -> bool { msg_send![self, isVisible] } @@ -1492,7 +1533,7 @@ impl NSWindow for id { } unsafe fn orderFrontWindow_relativeTo_(self, ordering_mode: NSWindowOrderingMode, other_window_number: NSInteger) { - msg_send![self, orderWindow:ordering_mode relativeTo:other_window_number] + msg_send![self, orderWindow: ordering_mode, relativeTo: other_window_number] } unsafe fn level(self) -> NSInteger { @@ -1505,11 +1546,11 @@ impl NSWindow for id { // Managing Key Status - unsafe fn isKeyWindow(self) -> BOOL { + unsafe fn isKeyWindow(self) -> bool { msg_send![self, isKeyWindow] } - unsafe fn canBecomeKeyWindow(self) -> BOOL { + unsafe fn canBecomeKeyWindow(self) -> bool { msg_send![self, canBecomeKeyWindow] } @@ -1523,7 +1564,7 @@ impl NSWindow for id { // Managing Main Status - unsafe fn canBecomeMainWindow(self) -> BOOL { + unsafe fn canBecomeMainWindow(self) -> bool { msg_send![self, canBecomeMainWindow] } @@ -1559,12 +1600,12 @@ impl NSWindow for id { } // Managing Window Tabs - unsafe fn allowsAutomaticWindowTabbing(_: Self) -> BOOL { + unsafe fn allowsAutomaticWindowTabbing(_: Self) -> bool { msg_send![class!(NSWindow), allowsAutomaticWindowTabbing] } - unsafe fn setAllowsAutomaticWindowTabbing_(_: Self, allowsAutomaticWindowTabbing: BOOL) { - msg_send![class!(NSWindow), setAllowsAutomaticWindowTabbing:allowsAutomaticWindowTabbing] + unsafe fn setAllowsAutomaticWindowTabbing_(_: Self, allowsAutomaticWindowTabbing: bool) { + msg_send![class!(NSWindow), setAllowsAutomaticWindowTabbing: allowsAutomaticWindowTabbing] } unsafe fn tabbingIdentifier(self) -> id { @@ -1580,7 +1621,7 @@ impl NSWindow for id { } unsafe fn addTabbedWindow_ordered_(self, window: id, ordering_mode: NSWindowOrderingMode) { - msg_send![self, addTabbedWindow:window ordered: ordering_mode] + msg_send![self, addTabbedWindow: window, ordered: ordering_mode] } unsafe fn toggleTabBar_(self, sender: id) { @@ -1603,7 +1644,7 @@ impl NSWindow for id { msg_send![self, setInitialFirstResponder:responder] } - unsafe fn makeFirstResponder_(self, responder: id) -> BOOL { + unsafe fn makeFirstResponder_(self, responder: id) -> bool { msg_send![self, makeFirstResponder:responder] } @@ -1617,30 +1658,30 @@ impl NSWindow for id { // Handling Mouse Events - unsafe fn acceptsMouseMovedEvents(self) -> BOOL { + unsafe fn acceptsMouseMovedEvents(self) -> bool { msg_send![self, acceptsMouseMovedEvents] } - unsafe fn ignoresMouseEvents(self) -> BOOL { + unsafe fn ignoresMouseEvents(self) -> bool { msg_send![self, ignoresMouseEvents] } - unsafe fn setIgnoresMouseEvents_(self, ignoreMouseEvents: BOOL) { - msg_send![self, setIgnoresMouseEvents:ignoreMouseEvents] + unsafe fn setIgnoresMouseEvents_(self, ignoreMouseEvents: bool) { + msg_send![self, setIgnoresMouseEvents: ignoreMouseEvents] } unsafe fn mouseLocationOutsideOfEventStream(self) -> NSPoint { msg_send![self, mouseLocationOutsideOfEventStream] } - unsafe fn setAcceptsMouseMovedEvents_(self, acceptMouseMovedEvents: BOOL) { - msg_send![self, setAcceptsMouseMovedEvents:acceptMouseMovedEvents] + unsafe fn setAcceptsMouseMovedEvents_(self, acceptMouseMovedEvents: bool) { + msg_send![self, setAcceptsMouseMovedEvents: acceptMouseMovedEvents] } unsafe fn windowNumberAtPoint_belowWindowWithWindowNumber_(_: Self, point: NSPoint, windowNumber: NSInteger) -> NSInteger { - msg_send![class!(NSWindow), windowNumberAtPoint:point belowWindowWithWindowNumber:windowNumber] + msg_send![class!(NSWindow), windowNumberAtPoint: point, belowWindowWithWindowNumber: windowNumber] } // Converting Coordinates @@ -1650,7 +1691,7 @@ impl NSWindow for id { } unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect { - msg_send![self, backingAlignedRect:rect options:options] + msg_send![self, backingAlignedRect: rect, options: options] } unsafe fn convertRectFromBacking_(self, rect: NSRect) -> NSRect { @@ -1671,12 +1712,12 @@ impl NSWindow for id { // Accessing Edited Status - unsafe fn isDocumentEdited(self) -> BOOL { + unsafe fn isDocumentEdited(self) -> bool { msg_send![self, isDocumentEdited] } - unsafe fn setDocumentEdited_(self, documentEdited: BOOL) { - msg_send![self, setDocumentEdited:documentEdited] + unsafe fn setDocumentEdited_(self, documentEdited: bool) { + msg_send![self, setDocumentEdited: documentEdited] } // Managing Titles @@ -1697,8 +1738,8 @@ impl NSWindow for id { msg_send![self, setTitleVisibility:visibility] } - unsafe fn setTitlebarAppearsTransparent_(self, transparent: BOOL) { - msg_send![self, setTitlebarAppearsTransparent:transparent] + unsafe fn setTitlebarAppearsTransparent_(self, transparent: bool) { + msg_send![self, setTitlebarAppearsTransparent: transparent] } unsafe fn representedFilename(self) -> id { @@ -1727,22 +1768,22 @@ impl NSWindow for id { msg_send![self, deepestScreen] } - unsafe fn displaysWhenScreenProfileChanges(self) -> BOOL { + unsafe fn displaysWhenScreenProfileChanges(self) -> bool { msg_send![self, displaysWhenScreenProfileChanges] } - unsafe fn setDisplaysWhenScreenProfileChanges_(self, displaysWhenScreenProfileChanges: BOOL) { - msg_send![self, setDisplaysWhenScreenProfileChanges:displaysWhenScreenProfileChanges] + unsafe fn setDisplaysWhenScreenProfileChanges_(self, displaysWhenScreenProfileChanges: bool) { + msg_send![self, setDisplaysWhenScreenProfileChanges: displaysWhenScreenProfileChanges] } // Moving Windows - unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: BOOL) { - msg_send![self, setMovableByWindowBackground:movableByWindowBackground] + unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: bool) { + msg_send![self, setMovableByWindowBackground: movableByWindowBackground] } - unsafe fn setMovable_(self, movable: BOOL) { - msg_send![self, setMovable:movable] + unsafe fn setMovable_(self, movable: bool) { + msg_send![self, setMovable: movable] } unsafe fn center(self) { @@ -1759,8 +1800,8 @@ impl NSWindow for id { msg_send![self, close] } - unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: BOOL) { - msg_send![self, setReleasedWhenClosed:releasedWhenClosed] + unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: bool) { + msg_send![self, setReleasedWhenClosed: releasedWhenClosed] } // Minimizing Windows @@ -1809,33 +1850,33 @@ pub trait NSPanel: Sized { // NSPanel subclasses NSWindow, hence we only add the added methods // https://developer.apple.com/documentation/appkit/nspanel - unsafe fn setBecomesKeyOnlyIfNeeded(self, becomesKeyOnlyIfNeeded: BOOL); - unsafe fn becomesKeyOnlyIfNeeded(self) -> BOOL; - unsafe fn setFloatingPanel(self, floatingPanel: BOOL); - unsafe fn floatingPanel(self) -> BOOL; - unsafe fn setWorksWhenModal(self, worksWithPanel: BOOL); + unsafe fn setBecomesKeyOnlyIfNeeded(self, becomesKeyOnlyIfNeeded: bool); + unsafe fn becomesKeyOnlyIfNeeded(self) -> bool; + unsafe fn setFloatingPanel(self, floatingPanel: bool); + unsafe fn floatingPanel(self) -> bool; + unsafe fn setWorksWhenModal(self, worksWithPanel: bool); } impl NSPanel for id { // NSPanel subclasses NSWindow, hence we only add the added methods // https://developer.apple.com/documentation/appkit/nspanel - unsafe fn setBecomesKeyOnlyIfNeeded(self, becomesKeyOnlyIfNeeded: BOOL) { + unsafe fn setBecomesKeyOnlyIfNeeded(self, becomesKeyOnlyIfNeeded: bool) { msg_send![self, setBecomesKeyOnlyIfNeeded: becomesKeyOnlyIfNeeded] } - unsafe fn becomesKeyOnlyIfNeeded(self) -> BOOL { + unsafe fn becomesKeyOnlyIfNeeded(self) -> bool { msg_send![self, becomesKeyOnlyIfNeeded] } - unsafe fn setFloatingPanel(self, floatingPanel: BOOL) { + unsafe fn setFloatingPanel(self, floatingPanel: bool) { msg_send![self, setFloatingPanel: floatingPanel] } - unsafe fn floatingPanel(self) -> BOOL { + unsafe fn floatingPanel(self) -> bool { msg_send![self, isFloatingPanel] } - unsafe fn setWorksWhenModal(self, worksWhenModal: BOOL) { + unsafe fn setWorksWhenModal(self, worksWhenModal: bool) { msg_send![self, setWorksWhenModal: worksWhenModal] } } @@ -1847,13 +1888,15 @@ pub enum NSModalResponse { NSModalResponseCancel = 0, } +impl_Encode!(NSModalResponse, i64); + pub trait NSSavePanel: Sized { unsafe fn savePanel(_: Self) -> id { msg_send![class!(NSSavePanel), savePanel] } unsafe fn setDirectoryURL(self, url: id); - unsafe fn setCanCreateDirectories(self, canCreateDirectories: BOOL); + unsafe fn setCanCreateDirectories(self, canCreateDirectories: bool); unsafe fn URL(self) -> id; unsafe fn runModal(self) -> NSModalResponse; } @@ -1863,7 +1906,7 @@ impl NSSavePanel for id { msg_send![self, setDirectoryURL: url] } - unsafe fn setCanCreateDirectories(self, canCreateDirectories: BOOL) { + unsafe fn setCanCreateDirectories(self, canCreateDirectories: bool) { msg_send![self, setCanCreateDirectories: canCreateDirectories] } @@ -1881,27 +1924,27 @@ pub trait NSOpenPanel: NSSavePanel { msg_send![class!(NSOpenPanel), openPanel] } - unsafe fn setCanChooseFiles_(self, canChooseFiles: BOOL); - unsafe fn setCanChooseDirectories_(self, canChooseDirectories: BOOL); - unsafe fn setResolvesAliases_(self, resolvesAliases: BOOL); - unsafe fn setAllowsMultipleSelection_(self, allowsMultipleSelection: BOOL); + unsafe fn setCanChooseFiles_(self, canChooseFiles: bool); + unsafe fn setCanChooseDirectories_(self, canChooseDirectories: bool); + unsafe fn setResolvesAliases_(self, resolvesAliases: bool); + unsafe fn setAllowsMultipleSelection_(self, allowsMultipleSelection: bool); unsafe fn URLs(self) -> id; } impl NSOpenPanel for id { - unsafe fn setCanChooseFiles_(self, canChooseFiles: BOOL) { + unsafe fn setCanChooseFiles_(self, canChooseFiles: bool) { msg_send![self, setCanChooseFiles: canChooseFiles] } - unsafe fn setCanChooseDirectories_(self, canChooseDirectories: BOOL) { + unsafe fn setCanChooseDirectories_(self, canChooseDirectories: bool) { msg_send![self, setCanChooseDirectories: canChooseDirectories] } - unsafe fn setResolvesAliases_(self, resolvesAliases: BOOL) { + unsafe fn setResolvesAliases_(self, resolvesAliases: bool) { msg_send![self, setResolvesAliases: resolvesAliases] } - unsafe fn setAllowsMultipleSelection_(self, allowsMultipleSelection: BOOL) { + unsafe fn setAllowsMultipleSelection_(self, allowsMultipleSelection: bool) { msg_send![self, setAllowsMultipleSelection: allowsMultipleSelection] } @@ -1927,6 +1970,8 @@ pub enum NSViewLayerContentsPlacement { NSViewLayerContentsPlacementTopLeft = 11, } +impl_Encode!(NSViewLayerContentsPlacement, usize); + pub trait NSView: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSView), alloc] @@ -1939,15 +1984,15 @@ pub trait NSView: Sized { unsafe fn setFrameSize(self, frameSize: NSSize); unsafe fn setFrameOrigin(self, frameOrigin: NSPoint); unsafe fn display_(self); - unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: BOOL); + unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: bool); unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint; unsafe fn addSubview_(self, view: id); unsafe fn superview(self) -> id; unsafe fn removeFromSuperview(self); unsafe fn setAutoresizingMask_(self, autoresizingMask: NSAutoresizingMaskOptions); - unsafe fn wantsLayer(self) -> BOOL; - unsafe fn setWantsLayer(self, wantsLayer: BOOL); + unsafe fn wantsLayer(self) -> bool; + unsafe fn setWantsLayer(self, wantsLayer: bool); unsafe fn layer(self) -> id; unsafe fn setLayer(self, layer: id); @@ -1988,12 +2033,12 @@ impl NSView for id { msg_send![self, display] } - unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: BOOL) { - msg_send![self, setWantsBestResolutionOpenGLSurface:flag] + unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: bool) { + msg_send![self, setWantsBestResolutionOpenGLSurface: flag] } unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint { - msg_send![self, convertPoint:point fromView:view] + msg_send![self, convertPoint: point, fromView: view] } unsafe fn addSubview_(self, view: id) { @@ -2012,12 +2057,12 @@ impl NSView for id { msg_send![self, setAutoresizingMask:autoresizingMask] } - unsafe fn wantsLayer(self) -> BOOL { + unsafe fn wantsLayer(self) -> bool { msg_send![self, wantsLayer] } - unsafe fn setWantsLayer(self, wantsLayer: BOOL) { - msg_send![self, setWantsLayer:wantsLayer] + unsafe fn setWantsLayer(self, wantsLayer: bool) { + msg_send![self, setWantsLayer: wantsLayer] } unsafe fn layer(self) -> id { @@ -2072,7 +2117,7 @@ pub trait NSOpenGLView: Sized { impl NSOpenGLView for id { unsafe fn initWithFrame_pixelFormat_(self, frameRect: NSRect, format: id) -> id { - msg_send![self, initWithFrame:frameRect pixelFormat:format] + msg_send![self, initWithFrame: frameRect, pixelFormat: format] } unsafe fn display_(self) { @@ -2108,13 +2153,13 @@ impl NSOpenGLPixelFormat for id { // Creating an NSOpenGLPixelFormat Object unsafe fn initWithAttributes_(self, attributes: &[u32]) -> id { - msg_send![self, initWithAttributes:attributes] + msg_send![self, initWithAttributes:attributes.as_ptr()] } // Managing the Pixel Format unsafe fn getValues_forAttribute_forVirtualScreen_(self, val: *mut GLint, attrib: NSOpenGLPixelFormatAttribute, screen: GLint) { - msg_send![self, getValues:val forAttribute:attrib forVirtualScreen:screen] + msg_send![self, getValues: val, forAttribute: attrib, forVirtualScreen:screen] } unsafe fn numberOfVirtualScreens(self) -> GLint { @@ -2161,7 +2206,7 @@ impl NSOpenGLContext for id { // Context Creation unsafe fn initWithFormat_shareContext_(self, format: id /* (NSOpenGLPixelFormat *) */, shareContext: id /* (NSOpenGLContext *) */) -> id /* (instancetype) */ { - msg_send![self, initWithFormat:format shareContext:shareContext] + msg_send![self, initWithFormat: format, shareContext: shareContext] } unsafe fn initWithCGLContextObj_(self, context: CGLContextObj) -> id /* (instancetype) */ { @@ -2209,11 +2254,11 @@ impl NSOpenGLContext for id { // Context Parameter Handling unsafe fn setValues_forParameter_(self, vals: *const GLint, param: NSOpenGLContextParameter) { - msg_send![self, setValues:vals forParameter:param] + msg_send![self, setValues: vals, forParameter: param] } unsafe fn getValues_forParameter_(self, vals: *mut GLint, param: NSOpenGLContextParameter) { - msg_send![self, getValues:vals forParameter:param] + msg_send![self, getValues: vals, forParameter: param] } // Working with Virtual Screens @@ -2240,6 +2285,8 @@ bitflags! { } } +impl_Encode!(NSEventSwipeTrackingOptions, NSUInteger); + #[repr(i64)] // NSInteger pub enum NSEventGestureAxis { NSEventGestureAxisNone = 0, @@ -2247,6 +2294,8 @@ pub enum NSEventGestureAxis { NSEventGestureAxisVertical, } +impl_Encode!(NSEventGestureAxis, i64); + bitflags! { pub struct NSEventPhase: NSUInteger { const NSEventPhaseNone = 0; @@ -2259,6 +2308,8 @@ bitflags! { } } +impl_Encode!(NSEventPhase, NSUInteger); + bitflags! { pub struct NSTouchPhase: NSUInteger { const NSTouchPhaseBegan = 1 << 0; @@ -2273,6 +2324,8 @@ bitflags! { } } +impl_Encode!(NSTouchPhase, NSUInteger); + #[derive(Clone, Copy, Debug, PartialEq)] #[repr(u64)] // NSUInteger pub enum NSEventType { @@ -2308,6 +2361,8 @@ pub enum NSEventType { NSEventTypePressure = 34, } +impl_Encode!(NSEventType, u64); + bitflags! { pub struct NSEventMask: libc::c_ulonglong { const NSLeftMouseDownMask = 1 << NSLeftMouseDown as libc::c_ulonglong; @@ -2343,6 +2398,8 @@ bitflags! { } } +impl_Encode!(NSEventMask, libc::c_ulonglong); + impl NSEventMask { pub fn from_type(ty: NSEventType) -> NSEventMask { NSEventMask { bits: 1 << ty as libc::c_ulonglong } @@ -2363,8 +2420,11 @@ bitflags! { } } -// Not sure of the type here +impl_Encode!(NSEventModifierFlags, NSUInteger); + +#[repr(usize)] // NSUInteger pub enum NSPointingDeviceType { + __Unknown = 0, // TODO: Not sure what these values are // NSUnknownPointingDevice = NX_TABLET_POINTER_UNKNOWN, // NSPenPointingDevice = NX_TABLET_POINTER_PEN, @@ -2372,14 +2432,19 @@ pub enum NSPointingDeviceType { // NSEraserPointingDevice = NX_TABLET_POINTER_ERASER, } -// Not sure of the type here +impl_Encode!(NSPointingDeviceType, usize); + +#[repr(usize)] // NSUInteger pub enum NSEventButtonMask { + __Unknown = 0, // TODO: Not sure what these values are // NSPenTipMask = NX_TABLET_BUTTON_PENTIPMASK, // NSPenLowerSideMask = NX_TABLET_BUTTON_PENLOWERSIDEMASK, // NSPenUpperSideMask = NX_TABLET_BUTTON_PENUPPERSIDEMASK, } +impl_Encode!(NSEventButtonMask, usize); + #[repr(i16)] pub enum NSEventSubtype { // TODO: Not sure what these values are @@ -2395,6 +2460,8 @@ pub enum NSEventSubtype { NSAWTEventType = 16, } +impl_Encode!(NSEventSubtype, i16); + pub const NSUpArrowFunctionKey: libc::c_ushort = 0xF700; pub const NSDownArrowFunctionKey: libc::c_ushort = 0xF701; pub const NSLeftArrowFunctionKey: libc::c_ushort = 0xF702; @@ -2480,7 +2547,7 @@ pub trait NSEvent: Sized { context: id /* (NSGraphicsContext *) */, characters: id /* (NSString *) */, unmodCharacters: id /* (NSString *) */, - repeatKey: BOOL, + repeatKey: bool, code: libc::c_ushort) -> id /* (NSEvent *) */; unsafe fn mouseEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_clickCount_pressure_( _: Self, @@ -2538,7 +2605,7 @@ pub trait NSEvent: Sized { unsafe fn characters(self) -> id /* (NSString *) */; unsafe fn charactersIgnoringModifiers(self) -> id /* (NSString *) */; unsafe fn keyCode(self) -> libc::c_ushort; - unsafe fn isARepeat(self) -> BOOL; + unsafe fn isARepeat(self) -> bool; // Getting Mouse Event Information unsafe fn pressedMouseButtons(_: Self) -> NSUInteger; @@ -2548,8 +2615,8 @@ pub trait NSEvent: Sized { unsafe fn clickCount(self) -> NSInteger; unsafe fn pressure(self) -> libc::c_float; unsafe fn stage(self) -> NSInteger; - unsafe fn setMouseCoalescingEnabled_(_: Self, flag: BOOL); - unsafe fn isMouseCoalescingEnabled(_: Self) -> BOOL; + unsafe fn setMouseCoalescingEnabled_(_: Self, flag: bool); + unsafe fn isMouseCoalescingEnabled(_: Self) -> bool; // Getting Mouse-Tracking Event Information unsafe fn eventNumber(self) -> NSInteger; @@ -2596,7 +2663,7 @@ pub trait NSEvent: Sized { // Getting Touch and Gesture Information unsafe fn magnification(self) -> CGFloat; unsafe fn touchesMatchingPhase_inView_(self, phase: NSTouchPhase, view: id /* (NSView *) */) -> id /* (NSSet *) */; - unsafe fn isSwipeTrackingFromScrollEventsEnabled(_: Self) -> BOOL; + unsafe fn isSwipeTrackingFromScrollEventsEnabled(_: Self) -> bool; // Monitoring Application Events // TODO: addGlobalMonitorForEventsMatchingMask_handler_ (unsure how to bind to blocks) @@ -2604,7 +2671,7 @@ pub trait NSEvent: Sized { unsafe fn removeMonitor_(_: Self, eventMonitor: id); // Scroll Wheel and Flick Events - unsafe fn hasPreciseScrollingDeltas(self) -> BOOL; + unsafe fn hasPreciseScrollingDeltas(self) -> bool; unsafe fn scrollingDeltaX(self) -> CGFloat; unsafe fn scrollingDeltaY(self) -> CGFloat; unsafe fn momentumPhase(self) -> NSEventPhase; @@ -2628,18 +2695,18 @@ impl NSEvent for id { context: id /* (NSGraphicsContext *) */, characters: id /* (NSString *) */, unmodCharacters: id /* (NSString *) */, - repeatKey: BOOL, + repeatKey: bool, code: libc::c_ushort) -> id /* (NSEvent *) */ { - msg_send![class!(NSEvent), keyEventWithType:eventType - location:location - modifierFlags:modifierFlags - timestamp:timestamp - windowNumber:windowNumber - context:context - characters:characters - charactersIgnoringModifiers:unmodCharacters - isARepeat:repeatKey + msg_send![class!(NSEvent), keyEventWithType:eventType, + location:location, + modifierFlags:modifierFlags, + timestamp:timestamp, + windowNumber:windowNumber, + context:context, + characters:characters, + charactersIgnoringModifiers:unmodCharacters, + isARepeat:repeatKey, keyCode:code] } @@ -2655,14 +2722,14 @@ impl NSEvent for id { clickCount: NSInteger, pressure: libc::c_float) -> id /* (NSEvent *) */ { - msg_send![class!(NSEvent), mouseEventWithType:eventType - location:location - modifierFlags:modifierFlags - timestamp:timestamp - windowNumber:windowNumber - context:context - eventNumber:eventNumber - clickCount:clickCount + msg_send![class!(NSEvent), mouseEventWithType:eventType, + location:location, + modifierFlags:modifierFlags, + timestamp:timestamp, + windowNumber:windowNumber, + context:context, + eventNumber:eventNumber, + clickCount:clickCount, pressure:pressure] } @@ -2678,14 +2745,14 @@ impl NSEvent for id { trackingNumber: NSInteger, userData: *mut c_void) -> id /* (NSEvent *) */ { - msg_send![class!(NSEvent), enterExitEventWithType:eventType - location:location - modifierFlags:modifierFlags - timestamp:timestamp - windowNumber:windowNumber - context:context - eventNumber:eventNumber - trackingNumber:trackingNumber + msg_send![class!(NSEvent), enterExitEventWithType:eventType, + location:location, + modifierFlags:modifierFlags, + timestamp:timestamp, + windowNumber:windowNumber, + context:context, + eventNumber:eventNumber, + trackingNumber:trackingNumber, userData:userData] } @@ -2701,14 +2768,14 @@ impl NSEvent for id { data1: NSInteger, data2: NSInteger) -> id /* (NSEvent *) */ { - msg_send![class!(NSEvent), otherEventWithType:eventType - location:location - modifierFlags:modifierFlags - timestamp:timestamp - windowNumber:windowNumber - context:context - subtype:subtype - data1:data1 + msg_send![class!(NSEvent), otherEventWithType:eventType, + location:location, + modifierFlags:modifierFlags, + timestamp:timestamp, + windowNumber:windowNumber, + context:context, + subtype:subtype, + data1:data1, data2:data2] } @@ -2787,7 +2854,7 @@ impl NSEvent for id { msg_send![self, keyCode] } - unsafe fn isARepeat(self) -> BOOL { + unsafe fn isARepeat(self) -> bool { msg_send![self, isARepeat] } @@ -2821,11 +2888,11 @@ impl NSEvent for id { msg_send![self, stage] } - unsafe fn setMouseCoalescingEnabled_(_: Self, flag: BOOL) { - msg_send![class!(NSEvent), setMouseCoalescingEnabled:flag] + unsafe fn setMouseCoalescingEnabled_(_: Self, flag: bool) { + msg_send![class!(NSEvent), setMouseCoalescingEnabled: flag] } - unsafe fn isMouseCoalescingEnabled(_: Self) -> BOOL { + unsafe fn isMouseCoalescingEnabled(_: Self) -> bool { msg_send![class!(NSEvent), isMouseCoalescingEnabled] } @@ -2954,7 +3021,7 @@ impl NSEvent for id { // Requesting and Stopping Periodic Events unsafe fn startPeriodicEventsAfterDelay_withPeriod_(_: Self, delaySeconds: NSTimeInterval, periodSeconds: NSTimeInterval) { - msg_send![class!(NSEvent), startPeriodicEventsAfterDelay:delaySeconds withPeriod:periodSeconds] + msg_send![class!(NSEvent), startPeriodicEventsAfterDelay: delaySeconds, withPeriod: periodSeconds] } unsafe fn stopPeriodicEvents(_: Self) { @@ -2968,10 +3035,10 @@ impl NSEvent for id { } unsafe fn touchesMatchingPhase_inView_(self, phase: NSTouchPhase, view: id /* (NSView *) */) -> id /* (NSSet *) */ { - msg_send![self, touchesMatchingPhase:phase inView:view] + msg_send![self, touchesMatchingPhase: phase, inView: view] } - unsafe fn isSwipeTrackingFromScrollEventsEnabled(_: Self) -> BOOL { + unsafe fn isSwipeTrackingFromScrollEventsEnabled(_: Self) -> bool { msg_send![class!(NSEvent), isSwipeTrackingFromScrollEventsEnabled] } @@ -2986,7 +3053,7 @@ impl NSEvent for id { // Scroll Wheel and Flick Events - unsafe fn hasPreciseScrollingDeltas(self) -> BOOL { + unsafe fn hasPreciseScrollingDeltas(self) -> bool { msg_send![self, hasPreciseScrollingDeltas] } @@ -3027,7 +3094,7 @@ pub trait NSScreen: Sized { unsafe fn deviceDescription(self) -> id /* (NSDictionary *) */; unsafe fn visibleFrame(self) -> NSRect; unsafe fn colorSpace(self) -> id /* (NSColorSpace *) */; - unsafe fn screensHaveSeparateSpaces(_: Self) -> BOOL; + unsafe fn screensHaveSeparateSpaces(_: Self) -> bool; // Screen Backing Coordinate Conversion unsafe fn backingAlignedRect_options_(self, aRect: NSRect, options: NSAlignmentOptions) -> NSRect; @@ -3077,14 +3144,14 @@ impl NSScreen for id { msg_send![self, colorSpace] } - unsafe fn screensHaveSeparateSpaces(_: Self) -> BOOL { + unsafe fn screensHaveSeparateSpaces(_: Self) -> bool { msg_send![class!(NSScreen), screensHaveSeparateSpaces] } // Screen Backing Coordinate Conversion unsafe fn backingAlignedRect_options_(self, aRect: NSRect, options: NSAlignmentOptions) -> NSRect { - msg_send![self, backingAlignedRect:aRect options:options] + msg_send![self, backingAlignedRect: aRect, options: options] } unsafe fn backingScaleFactor(self) -> CGFloat { @@ -3106,19 +3173,19 @@ pub trait NSControl: Sized { msg_send![class!(NSControl), alloc] } unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; - unsafe fn isEnabled_(self) -> BOOL; - unsafe fn setEnabled_(self, enabled: BOOL) -> BOOL; + unsafe fn isEnabled_(self) -> bool; + unsafe fn setEnabled_(self, enabled: bool) -> bool; } impl NSControl for id { unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { msg_send![self, initWithFrame:frameRect] } - unsafe fn isEnabled_(self) -> BOOL { + unsafe fn isEnabled_(self) -> bool { msg_send![self, isEnabled] } - unsafe fn setEnabled_(self, enabled: BOOL) -> BOOL { - msg_send![self, setEnabled:enabled] + unsafe fn setEnabled_(self, enabled: bool) -> bool { + msg_send![self, setEnabled: enabled] } } @@ -3148,7 +3215,7 @@ pub trait NSButton: Sized { } unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; unsafe fn setTarget_(self, target: id /* Instance */); - unsafe fn setAction_(self, selector: objc::runtime::Sel /* (Instance *) */); + unsafe fn setAction_(self, selector: objc2::runtime::Sel /* (Instance *) */); } impl NSButton for id { @@ -3168,7 +3235,7 @@ impl NSButton for id { msg_send![self, setTarget:target] } - unsafe fn setAction_(self, selector: objc::runtime::Sel /* (Instance method *) */) { + unsafe fn setAction_(self, selector: objc2::runtime::Sel /* (Instance method *) */) { msg_send![self, setAction:selector] } } @@ -3184,8 +3251,8 @@ pub trait NSImage: Sized { unsafe fn initWithDataIgnoringOrientation_(self, data: id /* (NSData *) */) -> id; unsafe fn initWithPasteboard_(self, pasteboard: id /* (NSPasteboard *) */) -> id; unsafe fn initWithSize_flipped_drawingHandler_(self, size: NSSize, - drawingHandlerShouldBeCalledWithFlippedContext: BOOL, - drawingHandler: *mut Block<(NSRect,), BOOL>); + drawingHandlerShouldBeCalledWithFlippedContext: bool, + drawingHandler: *mut Block<(NSRect,), Bool>); unsafe fn initWithSize_(self, aSize: NSSize) -> id; unsafe fn imageNamed_(_: Self, name: id /* (NSString *) */) -> id { @@ -3193,12 +3260,12 @@ pub trait NSImage: Sized { } unsafe fn name(self) -> id /* (NSString *) */; - unsafe fn setName_(self, name: id /* (NSString *) */) -> BOOL; + unsafe fn setName_(self, name: id /* (NSString *) */) -> bool; unsafe fn size(self) -> NSSize; - unsafe fn template(self) -> BOOL; + unsafe fn template(self) -> bool; - unsafe fn canInitWithPasteboard_(self, pasteboard: id /* (NSPasteboard *) */) -> BOOL; + unsafe fn canInitWithPasteboard_(self, pasteboard: id /* (NSPasteboard *) */) -> bool; unsafe fn imageTypes(self) -> id /* (NSArray ) */; unsafe fn imageUnfilteredTypes(self) -> id /* (NSArray ) */; @@ -3210,9 +3277,9 @@ pub trait NSImage: Sized { referenceContext: id /* (NSGraphicsContext *) */, hints: id /* (NSDictionary *) */) -> id /* (NSImageRep *) */; - unsafe fn prefersColorMatch(self) -> BOOL; - unsafe fn usesEPSOnResolutionMismatch(self) -> BOOL; - unsafe fn matchesOnMultipleResolution(self) -> BOOL; + unsafe fn prefersColorMatch(self) -> bool; + unsafe fn usesEPSOnResolutionMismatch(self) -> bool; + unsafe fn matchesOnMultipleResolution(self) -> bool; unsafe fn drawInRect_(self, rect: NSRect); unsafe fn drawAtPoint_fromRect_operation_fraction_(self, point: NSPoint, srcRect: NSRect, @@ -3220,15 +3287,15 @@ pub trait NSImage: Sized { unsafe fn drawInRect_fromRect_operation_fraction_(self, dstRect: NSRect, srcRect: NSRect, op: NSCompositingOperation, delta: CGFloat); unsafe fn drawInRect_fromRect_operation_fraction_respectFlipped_hints_(self, dstSpacePortionRect: NSRect, - srcSpacePortionRect: NSRect, op: NSCompositingOperation, delta: CGFloat, respectContextIsFlipped: BOOL, + srcSpacePortionRect: NSRect, op: NSCompositingOperation, delta: CGFloat, respectContextIsFlipped: bool, hints: id /* (NSDictionary *) */); unsafe fn drawRepresentation_inRect_(self, imageRep: id /* (NSImageRep *) */, dstRect: NSRect); - unsafe fn isValid(self) -> BOOL; + unsafe fn isValid(self) -> bool; unsafe fn backgroundColor(self) -> id /* (NSColor *) */; unsafe fn lockFocus(self); - unsafe fn lockFocusFlipped_(self, flipped: BOOL); + unsafe fn lockFocusFlipped_(self, flipped: bool); unsafe fn unlockFocus(self); unsafe fn alignmentRect(self) -> NSRect; @@ -3246,14 +3313,14 @@ pub trait NSImage: Sized { unsafe fn hitTestRect_withImageDestinationRect_context_hints_flipped_(self, testRectDestSpace: NSRect, imageRectDestSpace: NSRect, referenceContext: id /* (NSGraphicsContext *) */, - hints: id /* (NSDictionary *) */, flipped: BOOL) -> BOOL; + hints: id /* (NSDictionary *) */, flipped: bool) -> bool; unsafe fn accessibilityDescription(self) -> id /* (NSString *) */; unsafe fn layerContentsForContentsScale_(self, layerContentsScale: CGFloat) -> id /* (id) */; unsafe fn recommendedLayerContentsScale_(self, preferredContentsScale: CGFloat) -> CGFloat; - unsafe fn matchesOnlyOnBestFittingAxis(self) -> BOOL; + unsafe fn matchesOnlyOnBestFittingAxis(self) -> bool; } impl NSImage for id { @@ -3278,10 +3345,10 @@ impl NSImage for id { } unsafe fn initWithSize_flipped_drawingHandler_(self, size: NSSize, - drawingHandlerShouldBeCalledWithFlippedContext: BOOL, - drawingHandler: *mut Block<(NSRect,), BOOL>) { - msg_send![self, initWithSize:size - flipped:drawingHandlerShouldBeCalledWithFlippedContext + drawingHandlerShouldBeCalledWithFlippedContext: bool, + drawingHandler: *mut Block<(NSRect,), Bool>) { + msg_send![self, initWithSize:size, + flipped:drawingHandlerShouldBeCalledWithFlippedContext, drawingHandler:drawingHandler] } @@ -3293,7 +3360,7 @@ impl NSImage for id { msg_send![self, name] } - unsafe fn setName_(self, name: id /* (NSString *) */) -> BOOL { + unsafe fn setName_(self, name: id /* (NSString *) */) -> bool { msg_send![self, setName:name] } @@ -3301,11 +3368,11 @@ impl NSImage for id { msg_send![self, size] } - unsafe fn template(self) -> BOOL { + unsafe fn template(self) -> bool { msg_send![self, template] } - unsafe fn canInitWithPasteboard_(self, pasteboard: id /* (NSPasteboard *) */) -> BOOL { + unsafe fn canInitWithPasteboard_(self, pasteboard: id /* (NSPasteboard *) */) -> bool { msg_send![self, canInitWithPasteboard:pasteboard] } @@ -3337,18 +3404,18 @@ impl NSImage for id { referenceContext: id /* (NSGraphicsContext *) */, hints: id /* (NSDictionary *) */) -> id /* (NSImageRep *) */ { - msg_send![self, bestRepresentationForRect:rect context:referenceContext hints:hints] + msg_send![self, bestRepresentationForRect: rect, context: referenceContext, hints: hints] } - unsafe fn prefersColorMatch(self) -> BOOL { + unsafe fn prefersColorMatch(self) -> bool { msg_send![self, prefersColorMatch] } - unsafe fn usesEPSOnResolutionMismatch(self) -> BOOL { + unsafe fn usesEPSOnResolutionMismatch(self) -> bool { msg_send![self, usesEPSOnResolutionMismatch] } - unsafe fn matchesOnMultipleResolution(self) -> BOOL { + unsafe fn matchesOnMultipleResolution(self) -> bool { msg_send![self, matchesOnMultipleResolution] } @@ -3358,30 +3425,30 @@ impl NSImage for id { unsafe fn drawAtPoint_fromRect_operation_fraction_(self, point: NSPoint, srcRect: NSRect, op: NSCompositingOperation, delta: CGFloat) { - msg_send![self, drawAtPoint:point fromRect:srcRect operation:op fraction:delta] + msg_send![self, drawAtPoint: point, fromRect: srcRect, operation: op, fraction: delta] } unsafe fn drawInRect_fromRect_operation_fraction_(self, dstRect: NSRect, srcRect: NSRect, op: NSCompositingOperation, delta: CGFloat) { - msg_send![self, drawInRect:dstRect fromRect:srcRect operation:op fraction:delta] + msg_send![self, drawInRect: dstRect, fromRect: srcRect, operation: op, fraction: delta] } unsafe fn drawInRect_fromRect_operation_fraction_respectFlipped_hints_(self, dstSpacePortionRect: NSRect, - srcSpacePortionRect: NSRect, op: NSCompositingOperation, delta: CGFloat, respectContextIsFlipped: BOOL, + srcSpacePortionRect: NSRect, op: NSCompositingOperation, delta: CGFloat, respectContextIsFlipped: bool, hints: id /* (NSDictionary *) */) { - msg_send![self, drawInRect:dstSpacePortionRect - fromRect:srcSpacePortionRect - operation:op - fraction:delta - respectFlipped:respectContextIsFlipped + msg_send![self, drawInRect:dstSpacePortionRect, + fromRect:srcSpacePortionRect, + operation:op, + fraction:delta, + respectFlipped:respectContextIsFlipped, hints:hints] } unsafe fn drawRepresentation_inRect_(self, imageRep: id /* (NSImageRep *) */, dstRect: NSRect) { - msg_send![self, drawRepresentation:imageRep inRect:dstRect] + msg_send![self, drawRepresentation: imageRep, inRect: dstRect] } - unsafe fn isValid(self) -> BOOL { + unsafe fn isValid(self) -> bool { msg_send![self, isValid] } @@ -3393,8 +3460,8 @@ impl NSImage for id { msg_send![self, lockFocus] } - unsafe fn lockFocusFlipped_(self, flipped: BOOL) { - msg_send![self, lockFocusFlipped:flipped] + unsafe fn lockFocusFlipped_(self, flipped: bool) { + msg_send![self, lockFocusFlipped: flipped] } unsafe fn unlockFocus(self) { @@ -3423,7 +3490,7 @@ impl NSImage for id { unsafe fn TIFFRepresentationUsingCompression_factor_(self, comp: NSTIFFCompression, aFloat: f32) -> id /* (NSData *) */ { - msg_send![self, TIFFRepresentationUsingCompression:comp factor:aFloat] + msg_send![self, TIFFRepresentationUsingCompression: comp, factor: aFloat] } unsafe fn cancelIncrementalLoad(self) { @@ -3432,11 +3499,11 @@ impl NSImage for id { unsafe fn hitTestRect_withImageDestinationRect_context_hints_flipped_(self, testRectDestSpace: NSRect, imageRectDestSpace: NSRect, referenceContext: id /* (NSGraphicsContext *) */, - hints: id /* (NSDictionary *) */, flipped: BOOL) -> BOOL { - msg_send![self, hitTestRect:testRectDestSpace - withImageDestinationRect:imageRectDestSpace - context:referenceContext - hints:hints + hints: id /* (NSDictionary *) */, flipped: bool) -> bool { + msg_send![self, hitTestRect:testRectDestSpace, + withImageDestinationRect:imageRectDestSpace, + context:referenceContext, + hints:hints, flipped:flipped] } @@ -3452,7 +3519,7 @@ impl NSImage for id { msg_send![self, recommendedLayerContentsScale:preferredContentsScale] } - unsafe fn matchesOnlyOnBestFittingAxis(self) -> BOOL { + unsafe fn matchesOnlyOnBestFittingAxis(self) -> bool { msg_send![self, matchesOnlyOnBestFittingAxis] } } @@ -3550,6 +3617,8 @@ pub enum NSCompositingOperation { NSCompositePlusLighter = 13 } +impl_Encode!(NSCompositingOperation, usize); + #[repr(usize)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum NSImageCacheMode { @@ -3559,6 +3628,8 @@ pub enum NSImageCacheMode { NSImageCacheNever } +impl_Encode!(NSImageCacheMode, usize); + #[repr(usize)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum NSTIFFCompression { @@ -3572,6 +3643,8 @@ pub enum NSTIFFCompression { NSTIFFCompressionOldJPEG = 32865 } +impl_Encode!(NSTIFFCompression, usize); + #[repr(usize)] #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum NSImageLoadStatus { @@ -3582,20 +3655,22 @@ pub enum NSImageLoadStatus { NSImageLoadStatusReadError } +impl_Encode!(NSImageLoadStatus, usize); + pub trait NSSound: Sized { - unsafe fn canInitWithPasteboard_(_: Self, pasteboard: id) -> BOOL { + unsafe fn canInitWithPasteboard_(_: Self, pasteboard: id) -> bool { msg_send![class!(NSSound), canInitWithPasteboard:pasteboard] } - unsafe fn initWithContentsOfFile_withReference_(self, filepath: id, byRef: BOOL) -> id; - unsafe fn initWithContentsOfURL_withReference_(self, fileUrl: id, byRef: BOOL) -> id; + unsafe fn initWithContentsOfFile_withReference_(self, filepath: id, byRef: bool) -> id; + unsafe fn initWithContentsOfURL_withReference_(self, fileUrl: id, byRef: bool) -> id; unsafe fn initWithData_(self, audioData: id) -> id; unsafe fn initWithPasteboard_(self, pasteboard: id) -> id; unsafe fn name(self) -> id; unsafe fn volume(self) -> f32; unsafe fn currentTime(self) -> NSTimeInterval; - unsafe fn loops(self) -> BOOL; + unsafe fn loops(self) -> bool; unsafe fn playbackDeviceIdentifier(self) -> id; unsafe fn delegate(self) -> id; @@ -3609,22 +3684,22 @@ pub trait NSSound: Sized { unsafe fn duration(self) -> NSTimeInterval; - unsafe fn playing(self) -> BOOL; - unsafe fn pause(self) -> BOOL; - unsafe fn play(self) -> BOOL; - unsafe fn resume(self) -> BOOL; - unsafe fn stop(self) -> BOOL; + unsafe fn playing(self) -> bool; + unsafe fn pause(self) -> bool; + unsafe fn play(self) -> bool; + unsafe fn resume(self) -> bool; + unsafe fn stop(self) -> bool; unsafe fn writeToPasteboard_(self, pasteboard: id); } impl NSSound for id { - unsafe fn initWithContentsOfFile_withReference_(self, filepath: id, byRef: BOOL) -> id { - msg_send![self, initWithContentsOfFile:filepath withReference:byRef] + unsafe fn initWithContentsOfFile_withReference_(self, filepath: id, byRef: bool) -> id { + msg_send![self, initWithContentsOfFile: filepath, withReference: byRef] } - unsafe fn initWithContentsOfURL_withReference_(self, fileUrl: id, byRef: BOOL) -> id { - msg_send![self, initWithContentsOfURL:fileUrl withReference:byRef] + unsafe fn initWithContentsOfURL_withReference_(self, fileUrl: id, byRef: bool) -> id { + msg_send![self, initWithContentsOfURL: fileUrl, withReference: byRef] } unsafe fn initWithData_(self, audioData: id) -> id { @@ -3647,7 +3722,7 @@ impl NSSound for id { msg_send![self, currentTime] } - unsafe fn loops(self) -> BOOL { + unsafe fn loops(self) -> bool { msg_send![self, loops] } @@ -3663,23 +3738,23 @@ impl NSSound for id { msg_send![self, duration] } - unsafe fn playing(self) -> BOOL { + unsafe fn playing(self) -> bool { msg_send![self, playing] } - unsafe fn pause(self) -> BOOL { + unsafe fn pause(self) -> bool { msg_send![self, pause] } - unsafe fn play(self) -> BOOL { + unsafe fn play(self) -> bool { msg_send![self, play] } - unsafe fn resume(self) -> BOOL { + unsafe fn resume(self) -> bool { msg_send![self, resume] } - unsafe fn stop(self) -> BOOL { + unsafe fn stop(self) -> bool { msg_send![self, stop] } @@ -3733,7 +3808,7 @@ pub trait NSStatusBar: Sized { unsafe fn statusItemWithLength_(self, length: CGFloat) -> id /* (NSStatusItem *) */; unsafe fn removeStatusItem_(self, item: id /* (NSStatusItem *) */); - unsafe fn isVertical(self) -> BOOL; + unsafe fn isVertical(self) -> bool; } impl NSStatusBar for id { @@ -3745,7 +3820,7 @@ impl NSStatusBar for id { msg_send![self, removeStatusItem:item] } - unsafe fn isVertical(self) -> BOOL { + unsafe fn isVertical(self) -> bool { msg_send![self, isVertical] } } @@ -3759,7 +3834,7 @@ pub trait NSTextField: Sized { msg_send![class!(NSTextField), alloc] } unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; - unsafe fn setEditable_(self, editable: BOOL); + unsafe fn setEditable_(self, editable: bool); unsafe fn setStringValue_(self, label: id /* NSString */); } @@ -3767,8 +3842,8 @@ impl NSTextField for id { unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { msg_send![self, initWithFrame:frameRect] } - unsafe fn setEditable_(self, editable: BOOL) { - msg_send![self, setEditable:editable] + unsafe fn setEditable_(self, editable: bool) { + msg_send![self, setEditable: editable] } unsafe fn setStringValue_(self, label: id) { msg_send![self, setStringValue:label] @@ -3786,6 +3861,8 @@ pub enum NSTabViewType { NSNoTabsNoBorder = 6 } +impl_Encode!(NSTabViewType, u64); + pub trait NSTabView: Sized { unsafe fn new(_: Self) -> id { msg_send![class!(NSTabView), new] @@ -3815,14 +3892,14 @@ pub trait NSTabView: Sized { unsafe fn setTabViewType_(self,tabViewType: NSTabViewType); unsafe fn controlTint(self) -> id; unsafe fn setControlTint_(self,controlTint:id); - unsafe fn drawsBackground(self) -> BOOL; - unsafe fn setDrawsBackground_(self,drawsBackground:BOOL); + unsafe fn drawsBackground(self) -> bool; + unsafe fn setDrawsBackground_(self,drawsBackground: bool); unsafe fn minimumSize(self) -> id; unsafe fn contentRect(self) -> id; unsafe fn controlSize(self) -> id; unsafe fn setControlSize_(self,controlSize:id); - unsafe fn allowsTruncatedLabels(self) -> BOOL; - unsafe fn setAllowsTruncatedLabels_(self, allowTruncatedLabels:BOOL); + unsafe fn allowsTruncatedLabels(self) -> bool; + unsafe fn setAllowsTruncatedLabels_(self, allowTruncatedLabels: bool); unsafe fn setDelegate_(self, delegate:id); unsafe fn delegate(self) -> id; unsafe fn tabViewAtPoint_(self, point:id) -> id; @@ -3837,7 +3914,7 @@ impl NSTabView for id { msg_send![self, addTabViewItem:tabViewItem] } unsafe fn insertTabViewItem_atIndex_(self, tabViewItem: id,index:NSInteger) { - msg_send![self, addTabViewItem:tabViewItem atIndex:index] + msg_send![self, addTabViewItem: tabViewItem, atIndex: index] } unsafe fn removeTabViewItem_(self,tabViewItem:id){ msg_send![self, removeTabViewItem:tabViewItem] @@ -3915,11 +3992,11 @@ impl NSTabView for id { msg_send![self, setControlTint:controlTint] } - unsafe fn drawsBackground(self) -> BOOL{ + unsafe fn drawsBackground(self) -> bool { msg_send![self, drawsBackground] } - unsafe fn setDrawsBackground_(self,drawsBackground:BOOL){ - msg_send![self, setDrawsBackground:drawsBackground as libc::c_int] + unsafe fn setDrawsBackground_(self, drawsBackground: bool) { + msg_send![self, setDrawsBackground: drawsBackground] } unsafe fn minimumSize(self) -> id{ @@ -3935,11 +4012,11 @@ impl NSTabView for id { msg_send![self, setControlSize:controlSize] } - unsafe fn allowsTruncatedLabels(self) -> BOOL{ + unsafe fn allowsTruncatedLabels(self) -> bool { msg_send![self, allowsTruncatedLabels] } - unsafe fn setAllowsTruncatedLabels_(self, allowTruncatedLabels:BOOL){ - msg_send![self, setAllowsTruncatedLabels:allowTruncatedLabels as libc::c_int] + unsafe fn setAllowsTruncatedLabels_(self, allowTruncatedLabels: bool) { + msg_send![self, setAllowsTruncatedLabels: allowTruncatedLabels] } unsafe fn setDelegate_(self, delegate:id){ @@ -3961,6 +4038,8 @@ pub enum NSTabState { NSPressedTab = 2 } +impl_Encode!(NSTabState, u64); + pub trait NSTabViewItem: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class!(NSTabViewItem), alloc] @@ -3970,10 +4049,10 @@ pub trait NSTabViewItem: Sized { } unsafe fn initWithIdentifier_(self, identifier:id) -> id; - unsafe fn drawLabel_inRect_(self,shouldTruncateLabel:BOOL,labelRect:NSRect); + unsafe fn drawLabel_inRect_(self, shouldTruncateLabel: bool, labelRect:NSRect); unsafe fn label(self) -> id; unsafe fn setLabel_(self,label:id); - unsafe fn sizeOfLabel_(self, computeMin:BOOL); + unsafe fn sizeOfLabel_(self, computeMin: bool); unsafe fn tabState(self) -> NSTabState; unsafe fn identifier(self)-> id; unsafe fn setIdentifier_(self,identifier:id); @@ -3993,8 +4072,8 @@ impl NSTabViewItem for id { msg_send![self, initWithIdentifier:identifier] } - unsafe fn drawLabel_inRect_(self, shouldTruncateLabel:BOOL,labelRect:NSRect){ - msg_send![self, drawLabel:shouldTruncateLabel as libc::c_int inRect:labelRect] + unsafe fn drawLabel_inRect_(self, shouldTruncateLabel: bool, labelRect: NSRect) { + msg_send![self, drawLabel: shouldTruncateLabel, inRect: labelRect] } unsafe fn label(self)->id{ @@ -4004,8 +4083,8 @@ impl NSTabViewItem for id { msg_send![self, setLabel:label] } - unsafe fn sizeOfLabel_(self,computeMin:BOOL){ - msg_send![self, sizeOfLabel:computeMin as libc::c_int] + unsafe fn sizeOfLabel_(self, computeMin: bool) { + msg_send![self, sizeOfLabel: computeMin] } unsafe fn tabState(self) -> NSTabState{ @@ -4190,19 +4269,19 @@ impl NSColor for id { msg_send![class!(NSColor), clearColor] } unsafe fn colorWithRed_green_blue_alpha_(_:Self, r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) -> id { - msg_send![class!(NSColor), colorWithRed:r green:g blue:b alpha:a] + msg_send![class!(NSColor), colorWithRed: r, green: g, blue: b, alpha: a] } unsafe fn colorWithSRGBRed_green_blue_alpha_(_:Self, r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) -> id { - msg_send![class!(NSColor), colorWithSRGBRed:r green:g blue:b alpha:a] + msg_send![class!(NSColor), colorWithSRGBRed: r, green: g, blue: b, alpha: a] } unsafe fn colorWithDeviceRed_green_blue_alpha_(_:Self, r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) -> id { - msg_send![class!(NSColor), colorWithDeviceRed:r green:g blue:b alpha:a] + msg_send![class!(NSColor), colorWithDeviceRed: r, green: g, blue: b, alpha: a] } unsafe fn colorWithDisplayP3Red_green_blue_alpha_(_:Self, r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) -> id { - msg_send![class!(NSColor), colorWithDisplayP3Red:r green:g blue:b alpha:a] + msg_send![class!(NSColor), colorWithDisplayP3Red: r, green: g, blue: b, alpha: a] } unsafe fn colorWithCalibratedRed_green_blue_alpha_(_:Self, r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat) -> id { - msg_send![class!(NSColor), colorWithCalibratedRed:r green:g blue:b alpha:a] + msg_send![class!(NSColor), colorWithCalibratedRed: r, green: g, blue: b, alpha: a] } unsafe fn colorUsingColorSpace_(self, color_space: id) -> id { @@ -4255,8 +4334,8 @@ pub trait NSToolbar: Sized { unsafe fn init_(self) -> id /* NSToolbar */; unsafe fn initWithIdentifier_(self, identifier: id) -> id /* NSToolbar */; - unsafe fn showsBaselineSeparator(self) -> BOOL; - unsafe fn setShowsBaselineSeparator_(self, value: BOOL); + unsafe fn showsBaselineSeparator(self) -> bool; + unsafe fn setShowsBaselineSeparator_(self, value: bool); } impl NSToolbar for id { @@ -4268,12 +4347,12 @@ impl NSToolbar for id { msg_send![self, initWithIdentifier:identifier] } - unsafe fn showsBaselineSeparator(self) -> BOOL { + unsafe fn showsBaselineSeparator(self) -> bool { msg_send![self, showsBaselineSeparator] } - unsafe fn setShowsBaselineSeparator_(self, value: BOOL) { - msg_send![self, setShowsBaselineSeparator:value] + unsafe fn setShowsBaselineSeparator_(self, value: bool) { + msg_send![self, setShowsBaselineSeparator: value] } } @@ -4287,7 +4366,7 @@ pub trait NSSpellChecker : Sized { stringToCheck: id, startingOffset: NSInteger, language: id, - wrapFlag: BOOL, + wrapFlag: bool, tag: NSInteger) -> (NSRange, NSInteger); unsafe fn uniqueSpellDocumentTag(_: Self) -> NSInteger; unsafe fn closeSpellDocumentWithTag(self, tag: NSInteger); @@ -4302,7 +4381,7 @@ impl NSSpellChecker for id { unsafe fn checkSpellingOfString_startingAt(self, stringToCheck: id, startingOffset: NSInteger) -> NSRange { - msg_send![self, checkSpellingOfString:stringToCheck startingAt:startingOffset] + msg_send![self, checkSpellingOfString: stringToCheck, startingAt: startingOffset] } unsafe fn checkSpellingOfString_startingAt_language_wrap_inSpellDocumentWithTag_wordCount( @@ -4310,16 +4389,17 @@ impl NSSpellChecker for id { stringToCheck: id, startingOffset: NSInteger, language: id, - wrapFlag: BOOL, + wrapFlag: bool, tag: NSInteger) -> (NSRange, NSInteger) { let mut wordCount = 0; - let range = msg_send![self, - checkSpellingOfString:stringToCheck - startingAt:startingOffset - language:language - wrap:wrapFlag - inSpellDocumentWithTag:tag - wordCount:&mut wordCount + let range = msg_send![ + self, + checkSpellingOfString:stringToCheck, + startingAt:startingOffset, + language:language, + wrap:wrapFlag, + inSpellDocumentWithTag:tag, + wordCount:&mut wordCount, ]; (range, wordCount) } @@ -4333,7 +4413,7 @@ impl NSSpellChecker for id { } unsafe fn ignoreWord_inSpellDocumentWithTag(self, wordToIgnore: id, tag: NSInteger) { - msg_send![self, ignoreWord:wordToIgnore inSpellDocumentWithTag:tag] + msg_send![self, ignoreWord: wordToIgnore, inSpellDocumentWithTag: tag] } } @@ -4347,7 +4427,7 @@ pub trait NSNib: Sized { impl NSNib for id { unsafe fn initWithNibNamed_bundle_(self, name: id, bundle: id) -> id { - msg_send![self, initWithNibNamed:name bundle:bundle] + msg_send![self, initWithNibNamed: name, bundle: bundle] } } diff --git a/cocoa/src/lib.rs b/cocoa/src/lib.rs index afc053a7d..bbc1ce8cf 100644 --- a/cocoa/src/lib.rs +++ b/cocoa/src/lib.rs @@ -17,11 +17,13 @@ extern crate block; extern crate bitflags; extern crate core_foundation; extern crate core_graphics; +#[macro_use] extern crate cocoa_foundation; extern crate foreign_types; extern crate libc; +extern crate objc2_encode; #[macro_use] -extern crate objc; +extern crate objc2; #[cfg(target_os = "macos")] pub mod appkit; diff --git a/cocoa/src/macros.rs b/cocoa/src/macros.rs index 77c6a16d3..e98be3d45 100644 --- a/cocoa/src/macros.rs +++ b/cocoa/src/macros.rs @@ -13,12 +13,12 @@ /// # Example with NSWindowDelegate /// ``` no_run /// #[macro_use] extern crate cocoa; -/// #[macro_use] extern crate objc; +/// #[macro_use] extern crate objc2; /// /// use cocoa::appkit::NSWindow; /// use cocoa::base::{id, nil}; /// -/// use objc::runtime::{Object, Sel}; +/// use objc2::runtime::{Object, Sel}; /// /// # fn main() { /// unsafe { @@ -33,7 +33,7 @@ /// /// my_window.setDelegate_(delegate!("MyWindowDelegate", { /// window: id = my_window, // Declare instance variable(s) -/// (onWindowWillEnterFullscreen:) => on_enter_fullscreen as extern fn(&Object, Sel, id) // Declare function(s) +/// (onWindowWillEnterFullscreen:) => on_enter_fullscreen as extern fn(_, _, _) // Declare function(s) /// })); /// } /// # } @@ -57,7 +57,7 @@ macro_rules! delegate { $( ($($sel:ident :)+) => $func:expr),* } ) => ({ - let mut decl = objc::declare::ClassDecl::new($name, class!(NSObject)).unwrap(); + let mut decl = objc2::declare::ClassBuilder::new($name, class!(NSObject)).unwrap(); $( decl.add_ivar::<$var_type>(stringify!($var)); diff --git a/cocoa/src/quartzcore.rs b/cocoa/src/quartzcore.rs index 5a63f4acd..438c57402 100644 --- a/cocoa/src/quartzcore.rs +++ b/cocoa/src/quartzcore.rs @@ -25,7 +25,7 @@ use std::ops::Mul; use std::ptr; use appkit::CGLContextObj; -use base::{BOOL, id, nil, YES}; +use base::{id, nil}; use foundation::NSUInteger; // CABase.h @@ -40,6 +40,8 @@ pub fn current_media_time() -> CFTimeInterval { pub struct CALayer(id); +impl_Encode!(CALayer, id); + unsafe impl Send for CALayer {} unsafe impl Sync for CALayer {} @@ -106,16 +108,14 @@ impl CALayer { #[inline] pub fn needs_display_for_key(key: &CFString) -> bool { unsafe { - let flag: BOOL = msg_send![class!(CALayer), needsDisplayForKey:(key.as_CFTypeRef())]; - flag == YES + msg_send![class!(CALayer), needsDisplayForKey:(key.as_CFTypeRef())] } } #[inline] pub fn should_archive_value_for_key(key: &CFString) -> bool { unsafe { - let flag: BOOL = msg_send![class!(CALayer), shouldArchiveValueForKey:(key.as_CFTypeRef())]; - flag == YES + msg_send![class!(CALayer), shouldArchiveValueForKey:(key.as_CFTypeRef())] } } @@ -234,53 +234,49 @@ impl CALayer { #[inline] pub fn is_hidden(&self) -> bool { unsafe { - let flag: BOOL = msg_send![self.id(), isHidden]; - flag == YES + msg_send![self.id(), isHidden] } } #[inline] pub fn set_hidden(&self, hidden: bool) { unsafe { - msg_send![self.id(), setHidden:hidden as BOOL] + msg_send![self.id(), setHidden: hidden] } } #[inline] pub fn is_double_sided(&self) -> bool { unsafe { - let flag: BOOL = msg_send![self.id(), isDoubleSided]; - flag == YES + msg_send![self.id(), isDoubleSided] } } #[inline] pub fn set_double_sided(&self, double_sided: bool) { unsafe { - msg_send![self.id(), setDoubleSided:double_sided as BOOL] + msg_send![self.id(), setDoubleSided: double_sided] } } #[inline] pub fn is_geometry_flipped(&self) -> bool { unsafe { - let flag: BOOL = msg_send![self.id(), isGeometryFlipped]; - flag == YES + msg_send![self.id(), isGeometryFlipped] } } #[inline] pub fn set_geometry_flipped(&self, geometry_flipped: bool) { unsafe { - msg_send![self.id(), setGeometryFlipped:geometry_flipped as BOOL] + msg_send![self.id(), setGeometryFlipped: geometry_flipped] } } #[inline] pub fn contents_are_flipped(&self) -> bool { unsafe { - let flag: BOOL = msg_send![self.id(), contentsAreFlipped]; - flag == YES + msg_send![self.id(), contentsAreFlipped] } } @@ -321,28 +317,28 @@ impl CALayer { #[inline] pub fn insert_sublayer_at_index(&self, sublayer: &CALayer, index: u32) { unsafe { - msg_send![self.id(), insertSublayer:sublayer.id() atIndex:index] + msg_send![self.id(), insertSublayer: sublayer.id(), atIndex: index] } } #[inline] pub fn insert_sublayer_below(&self, sublayer: &CALayer, sibling: &CALayer) { unsafe { - msg_send![self.id(), insertSublayer:sublayer.id() below:sibling.id()] + msg_send![self.id(), insertSublayer: sublayer.id(), below: sibling.id()] } } #[inline] pub fn insert_sublayer_above(&self, sublayer: &CALayer, sibling: &CALayer) { unsafe { - msg_send![self.id(), insertSublayer:sublayer.id() above:sibling.id()] + msg_send![self.id(), insertSublayer: sublayer.id(), above: sibling.id()] } } #[inline] pub fn replace_sublayer_with(&self, old_layer: &CALayer, new_layer: &CALayer) { unsafe { - msg_send![self.id(), replaceSublayer:old_layer.id() with:new_layer.id()] + msg_send![self.id(), replaceSublayer: old_layer.id(), with: new_layer.id()] } } @@ -385,15 +381,14 @@ impl CALayer { #[inline] pub fn masks_to_bounds(&self) -> bool { unsafe { - let flag: BOOL = msg_send![self.id(), masksToBounds]; - flag == YES + msg_send![self.id(), masksToBounds] } } #[inline] pub fn set_masks_to_bounds(&self, flag: bool) { unsafe { - msg_send![self.id(), setMasksToBounds:flag as BOOL] + msg_send![self.id(), setMasksToBounds: flag] } } @@ -404,7 +399,7 @@ impl CALayer { None => nil, Some(ref layer) => layer.id(), }; - msg_send![self.id(), convertPoint:*point fromLayer:layer] + msg_send![self.id(), convertPoint: *point, fromLayer: layer] } } @@ -415,7 +410,7 @@ impl CALayer { None => nil, Some(ref layer) => layer.id(), }; - msg_send![self.id(), convertPoint:*point toLayer:layer] + msg_send![self.id(), convertPoint: *point, toLayer: layer] } } @@ -426,7 +421,7 @@ impl CALayer { None => nil, Some(ref layer) => layer.id(), }; - msg_send![self.id(), convertRect:*rect fromLayer:layer] + msg_send![self.id(), convertRect: *rect, fromLayer: layer] } } @@ -437,7 +432,7 @@ impl CALayer { None => nil, Some(ref layer) => layer.id(), }; - msg_send![self.id(), convertRect:*rect toLayer:layer] + msg_send![self.id(), convertRect: *rect, toLayer: layer] } } @@ -449,7 +444,7 @@ impl CALayer { None => nil, Some(ref layer) => layer.id(), }; - msg_send![self.id(), convertTime:time fromLayer:layer] + msg_send![self.id(), convertTime: time, fromLayer: layer] } } @@ -461,7 +456,7 @@ impl CALayer { None => nil, Some(ref layer) => layer.id(), }; - msg_send![self.id(), convertTime:time toLayer:layer] + msg_send![self.id(), convertTime: time, toLayer: layer] } } @@ -480,8 +475,7 @@ impl CALayer { #[inline] pub fn contains_point(&self, point: &CGPoint) -> bool { unsafe { - let result: BOOL = msg_send![self.id(), containsPoint:*point]; - result == YES + msg_send![self.id(), containsPoint:*point] } } @@ -620,15 +614,14 @@ impl CALayer { #[inline] pub fn is_opaque(&self) -> bool { unsafe { - let flag: BOOL = msg_send![self.id(), isOpaque]; - flag == YES + msg_send![self.id(), isOpaque] } } #[inline] pub fn set_opaque(&self, opaque: bool) { unsafe { - msg_send![self.id(), setOpaque:opaque as BOOL] + msg_send![self.id(), setOpaque: opaque] } } @@ -656,8 +649,7 @@ impl CALayer { #[inline] pub fn needs_display(&self) -> bool { unsafe { - let flag: BOOL = msg_send![self.id(), needsDisplay]; - flag == YES + msg_send![self.id(), needsDisplay] } } @@ -671,30 +663,28 @@ impl CALayer { #[inline] pub fn needs_display_on_bounds_change(&self) -> bool { unsafe { - let flag: BOOL = msg_send![self.id(), needsDisplayOnBoundsChange]; - flag == YES + msg_send![self.id(), needsDisplayOnBoundsChange] } } #[inline] pub fn set_needs_display_on_bounds_change(&self, flag: bool) { unsafe { - msg_send![self.id(), setNeedsDisplayOnBoundsChange:flag as BOOL] + msg_send![self.id(), setNeedsDisplayOnBoundsChange: flag] } } #[inline] pub fn draws_asynchronously(&self) -> bool { unsafe { - let flag: BOOL = msg_send![self.id(), drawsAsynchronously]; - flag == YES + msg_send![self.id(), drawsAsynchronously] } } #[inline] pub fn set_draws_asynchronously(&self, flag: bool) { unsafe { - msg_send![self.id(), setDrawsAsynchronously:flag as BOOL] + msg_send![self.id(), setDrawsAsynchronously: flag] } } @@ -881,15 +871,14 @@ impl CALayer { #[inline] pub fn should_rasterize(&self) -> bool { unsafe { - let flag: BOOL = msg_send![self.id(), shouldRasterize]; - flag == YES + msg_send![self.id(), shouldRasterize] } } #[inline] pub fn set_should_rasterize(&self, flag: bool) { unsafe { - msg_send![self.id(), setShouldRasterize:(flag as BOOL)] + msg_send![self.id(), setShouldRasterize: flag] } } @@ -1042,8 +1031,7 @@ impl CALayer { #[inline] pub fn needs_layout(&self) -> bool { unsafe { - let flag: BOOL = msg_send![self.id(), needsLayout]; - flag == YES + msg_send![self.id(), needsLayout] } } @@ -1096,13 +1084,13 @@ impl CALayer { #[inline] pub fn actions(&self) -> CFDictionary { unsafe { - msg_send![self.id(), actions] + CFDictionary::wrap_under_get_rule(msg_send![self.id(), actions]) } } #[inline] pub unsafe fn set_actions(&self, actions: CFDictionary) { - msg_send![self.id(), setActions:actions] + msg_send![self.id(), setActions: actions.as_concrete_TypeRef()] } // TODO(pcwalton): Wrap `CAAnimation`. @@ -1113,7 +1101,7 @@ impl CALayer { Some(ref for_key) => for_key.as_CFTypeRef(), None => ptr::null(), }; - msg_send![self.id(), addAnimation:animation forKey:for_key] + msg_send![self.id(), addAnimation: animation, forKey: for_key] } #[inline] @@ -1216,7 +1204,7 @@ impl CALayer { #[inline] pub fn set_contents_opaque(&self, opaque: bool) { unsafe { - msg_send![self.id(), setContentsOpaque:opaque as BOOL] + msg_send![self.id(), setContentsOpaque: opaque] } } } @@ -1372,6 +1360,8 @@ bitflags! { pub struct CARenderer(id); +impl_Encode!(CARenderer, id); + unsafe impl Send for CARenderer {} unsafe impl Sync for CARenderer {} @@ -1411,7 +1401,7 @@ impl CARenderer { let options: CFDictionary = CFDictionary::from_CFType_pairs(&pairs); let renderer: id = - msg_send![class!(CARenderer), rendererWithCGLContext:context + msg_send![class!(CARenderer), rendererWithCGLContext:context, options:options.as_CFTypeRef()]; debug_assert!(renderer != nil); CARenderer(renderer) @@ -1434,8 +1424,8 @@ impl CARenderer { let options: CFDictionary = CFDictionary::from_CFType_pairs(&pairs); let renderer: id = - msg_send![class!(CARenderer), rendererWithMTLTexture:metal_texture - options:options.as_CFTypeRef()]; + msg_send![class!(CARenderer), rendererWithMTLTexture: metal_texture, + options: options.as_CFTypeRef()]; debug_assert!(renderer != nil); CARenderer(renderer) } @@ -1480,7 +1470,7 @@ impl CARenderer { #[inline] pub fn begin_frame_at(&self, time: CFTimeInterval, timestamp: Option<&CVTimeStamp>) { unsafe { - msg_send![self.id(), beginFrameAtTime:time timeStamp:timestamp] + msg_send![self.id(), beginFrameAtTime: time, timeStamp: timestamp] } } @@ -1531,10 +1521,11 @@ impl CARenderer { // really just a module. pub mod transaction { use block::{Block, ConcreteBlock, IntoConcreteBlock, RcBlock}; + use core_foundation::base::TCFType; use core_foundation::date::CFTimeInterval; use core_foundation::string::CFString; - use base::{BOOL, YES, id}; + use base::id; #[inline] pub fn begin() { @@ -1600,15 +1591,14 @@ pub mod transaction { #[inline] pub fn disable_actions() -> bool { unsafe { - let flag: BOOL = msg_send![class!(CATransaction), disableActions]; - flag == YES + msg_send![class!(CATransaction), disableActions] } } #[inline] pub fn set_disable_actions(flag: bool) { unsafe { - msg_send![class!(CATransaction), setDisableActions:flag as BOOL] + msg_send![class!(CATransaction), setDisableActions: flag] } } @@ -1627,7 +1617,7 @@ pub mod transaction { #[inline] pub fn set_completion_block(block: ConcreteBlock<(), (), F>) - where F: 'static + IntoConcreteBlock<(), Ret = ()> { + where F: 'static + IntoConcreteBlock<(), Output = ()> { unsafe { let block = block.copy(); msg_send![class!(CATransaction), setCompletionBlock:&*block] @@ -1638,7 +1628,7 @@ pub mod transaction { pub fn value_for_key(key: &str) -> id { unsafe { let key: CFString = CFString::from(key); - msg_send![class!(CATransaction), valueForKey:key] + msg_send![class!(CATransaction), valueForKey: key.as_concrete_TypeRef()] } } @@ -1646,7 +1636,7 @@ pub mod transaction { pub fn set_value_for_key(value: id, key: &str) { unsafe { let key: CFString = CFString::from(key); - msg_send![class!(CATransaction), setValue:value forKey:key] + msg_send![class!(CATransaction), setValue: value, forKey: key.as_concrete_TypeRef()] } } } @@ -1662,6 +1652,10 @@ pub struct CATransform3D { pub m41: CGFloat, pub m42: CGFloat, pub m43: CGFloat, pub m44: CGFloat, } +unsafe impl ::objc2_encode::Encode for CATransform3D { + const ENCODING: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Array(16, &CGFloat::ENCODING); +} + impl PartialEq for CATransform3D { #[inline] fn eq(&self, other: &CATransform3D) -> bool { @@ -1814,6 +1808,28 @@ pub struct CVTimeStamp { pub reserved: u64, } +unsafe impl ::objc2_encode::Encode for CVTimeStamp { + const ENCODING: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Struct( + "CVTimeStamp", + &[ + u32::ENCODING, + i32::ENCODING, + i64::ENCODING, + u64::ENCODING, + f64::ENCODING, + i64::ENCODING, + CVSMPTETime::ENCODING, + u64::ENCODING, + u64::ENCODING, + ], + ); +} + +unsafe impl ::objc2_encode::RefEncode for CVTimeStamp { + const ENCODING_REF: ::objc2_encode::Encoding = + ::objc2_encode::Encoding::Pointer(&::ENCODING); +} + pub type CVTimeStampFlags = u64; pub const kCVTimeStampVideoTimeValid: CVTimeStampFlags = 1 << 0; @@ -1842,6 +1858,23 @@ pub struct CVSMPTETime { pub frames: i16, } +unsafe impl ::objc2_encode::Encode for CVSMPTETime { + const ENCODING: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Struct( + "CVSMPTETime", + &[ + i16::ENCODING, + i16::ENCODING, + u32::ENCODING, + u32::ENCODING, + u32::ENCODING, + i16::ENCODING, + i16::ENCODING, + i16::ENCODING, + i16::ENCODING, + ], + ); +} + pub type CVSMPTETimeType = u32; pub const kCVSMPTETimeType24: CVSMPTETimeType = 0; diff --git a/core-foundation-sys/Cargo.toml b/core-foundation-sys/Cargo.toml index 6bbbc6ab3..a11c41889 100644 --- a/core-foundation-sys/Cargo.toml +++ b/core-foundation-sys/Cargo.toml @@ -8,6 +8,7 @@ authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" [dependencies] +objc2-encode = { version = "=2.0.0-pre.2" } [features] mac_os_10_7_support = [] # backwards compatibility diff --git a/core-foundation-sys/src/array.rs b/core-foundation-sys/src/array.rs index c73896125..f899432fb 100644 --- a/core-foundation-sys/src/array.rs +++ b/core-foundation-sys/src/array.rs @@ -35,6 +35,10 @@ pub struct __CFArray(c_void); pub type CFArrayRef = *const __CFArray; pub type CFMutableArrayRef = *mut __CFArray; +unsafe impl ::objc2_encode::RefEncode for __CFArray { + const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Object; +} + extern { /* * CFArray.h diff --git a/core-foundation-sys/src/attributed_string.rs b/core-foundation-sys/src/attributed_string.rs index c91bf5be3..8101c6bc8 100644 --- a/core-foundation-sys/src/attributed_string.rs +++ b/core-foundation-sys/src/attributed_string.rs @@ -18,6 +18,10 @@ pub struct __CFAttributedString(c_void); pub type CFAttributedStringRef = *const __CFAttributedString; pub type CFMutableAttributedStringRef = *const __CFAttributedString; +unsafe impl ::objc2_encode::RefEncode for __CFAttributedString { + const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Object; +} + extern { /* CFAttributedString */ diff --git a/core-foundation-sys/src/dictionary.rs b/core-foundation-sys/src/dictionary.rs index d10e9c120..d88d33e52 100644 --- a/core-foundation-sys/src/dictionary.rs +++ b/core-foundation-sys/src/dictionary.rs @@ -47,6 +47,10 @@ pub struct __CFDictionary(c_void); pub type CFDictionaryRef = *const __CFDictionary; pub type CFMutableDictionaryRef = *mut __CFDictionary; +unsafe impl ::objc2_encode::RefEncode for __CFDictionary { + const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Object; +} + extern { /* * CFDictionary.h diff --git a/core-foundation-sys/src/lib.rs b/core-foundation-sys/src/lib.rs index 48c08878b..d655964af 100644 --- a/core-foundation-sys/src/lib.rs +++ b/core-foundation-sys/src/lib.rs @@ -10,6 +10,8 @@ #![cfg_attr(all(feature="mac_os_10_7_support", feature="mac_os_10_8_features"), feature(linkage))] // back-compat requires weak linkage +extern crate objc2_encode; + // Link to CoreFoundation on any Apple device. // // We don't use `target_vendor` since that is going to be deprecated: diff --git a/core-foundation-sys/src/string.rs b/core-foundation-sys/src/string.rs index d4f655078..ab1eddf38 100644 --- a/core-foundation-sys/src/string.rs +++ b/core-foundation-sys/src/string.rs @@ -192,6 +192,10 @@ pub struct __CFString(c_void); pub type CFStringRef = *const __CFString; +unsafe impl ::objc2_encode::RefEncode for __CFString { + const ENCODING_REF: ::objc2_encode::Encoding = ::objc2_encode::Encoding::Object; +} + extern { /* * CFString.h diff --git a/core-graphics-types/Cargo.toml b/core-graphics-types/Cargo.toml index baf273d9b..668336123 100644 --- a/core-graphics-types/Cargo.toml +++ b/core-graphics-types/Cargo.toml @@ -12,6 +12,7 @@ bitflags = "1.0" core-foundation = { path = "../core-foundation", version = "0.9" } foreign-types = "0.3.0" libc = "0.2" +objc2-encode = { version = "=2.0.0-pre.2" } [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" diff --git a/core-graphics-types/src/base.rs b/core-graphics-types/src/base.rs index d5efc3b62..0add1e6b3 100644 --- a/core-graphics-types/src/base.rs +++ b/core-graphics-types/src/base.rs @@ -26,7 +26,7 @@ pub type CGFloat = libc::c_double; #[cfg(not(target_pointer_width = "64"))] pub type CGFloat = libc::c_float; -pub type CGError = libc::int32_t; +pub type CGError = i32; pub type CGGlyph = libc::c_ushort; diff --git a/core-graphics-types/src/geometry.rs b/core-graphics-types/src/geometry.rs index 906c605ec..8b0f7e205 100644 --- a/core-graphics-types/src/geometry.rs +++ b/core-graphics-types/src/geometry.rs @@ -10,6 +10,7 @@ use base::CGFloat; use core_foundation::base::TCFType; use core_foundation::dictionary::CFDictionary; +use objc2_encode::{Encode, Encoding}; pub const CG_ZERO_POINT: CGPoint = CGPoint { x: 0.0, @@ -39,6 +40,11 @@ pub struct CGSize { pub height: CGFloat, } +unsafe impl Encode for CGSize { + const ENCODING: Encoding = + Encoding::Struct("CGSize", &[CGFloat::ENCODING, CGFloat::ENCODING]); +} + impl CGSize { #[inline] pub fn new(width: CGFloat, height: CGFloat) -> CGSize { @@ -63,6 +69,11 @@ pub struct CGPoint { pub y: CGFloat, } +unsafe impl Encode for CGPoint { + const ENCODING: Encoding = + Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFloat::ENCODING]); +} + impl CGPoint { #[inline] pub fn new(x: CGFloat, y: CGFloat) -> CGPoint { @@ -87,6 +98,11 @@ pub struct CGRect { pub size: CGSize } +unsafe impl Encode for CGRect { + const ENCODING: Encoding = + Encoding::Struct("CGRect", &[CGPoint::ENCODING, CGSize::ENCODING]); +} + impl CGRect { #[inline] pub fn new(origin: &CGPoint, size: &CGSize) -> CGRect { @@ -151,6 +167,20 @@ pub struct CGAffineTransform { pub ty: CGFloat, } +unsafe impl Encode for CGAffineTransform { + const ENCODING: Encoding = Encoding::Struct( + "CGAffineTransform", + &[ + CGFloat::ENCODING, + CGFloat::ENCODING, + CGFloat::ENCODING, + CGFloat::ENCODING, + CGFloat::ENCODING, + CGFloat::ENCODING, + ] + ); +} + impl CGAffineTransform { #[inline] pub fn new( diff --git a/core-graphics-types/src/lib.rs b/core-graphics-types/src/lib.rs index f34bf0120..057cc389b 100644 --- a/core-graphics-types/src/lib.rs +++ b/core-graphics-types/src/lib.rs @@ -9,6 +9,7 @@ extern crate libc; extern crate core_foundation; +extern crate objc2_encode; pub mod base; pub mod geometry; diff --git a/core-graphics/Cargo.toml b/core-graphics/Cargo.toml index 79b0eb266..2de8a6101 100644 --- a/core-graphics/Cargo.toml +++ b/core-graphics/Cargo.toml @@ -18,6 +18,7 @@ core-foundation = { path = "../core-foundation", version = "0.9" } core-graphics-types = { path = "../core-graphics-types", version = "0.1" } foreign-types = "0.3.0" libc = "0.2" +objc2-encode = { version = "=2.0.0-pre.2" } [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" diff --git a/core-graphics/src/event.rs b/core-graphics/src/event.rs index 8cf9c6262..bc01b8ad2 100644 --- a/core-graphics/src/event.rs +++ b/core-graphics/src/event.rs @@ -505,7 +505,7 @@ impl<'tap_life> CGEventTap<'tap_life> { callback_ref: Box::from_raw(cbr), }) } else { - Box::from_raw(cbr); + let _ = Box::from_raw(cbr); Err(()) } } diff --git a/core-graphics/src/lib.rs b/core-graphics/src/lib.rs index 5238774e7..4886465c7 100644 --- a/core-graphics/src/lib.rs +++ b/core-graphics/src/lib.rs @@ -8,6 +8,7 @@ // except according to those terms. extern crate libc; +extern crate objc2_encode; #[macro_use] extern crate core_foundation; diff --git a/core-graphics/src/sys.rs b/core-graphics/src/sys.rs index 85df442d5..a96f3053d 100644 --- a/core-graphics/src/sys.rs +++ b/core-graphics/src/sys.rs @@ -1,11 +1,17 @@ use std::os::raw::c_void; +use objc2_encode::{Encoding, RefEncode}; + pub enum CGImage {} pub type CGImageRef = *mut CGImage; #[repr(C)] pub struct __CGColor(c_void); +unsafe impl RefEncode for __CGColor { + const ENCODING_REF: Encoding = Encoding::Unknown; +} + pub type CGColorRef = *const __CGColor; pub enum CGColorSpace {} @@ -14,6 +20,10 @@ pub type CGColorSpaceRef = *mut CGColorSpace; pub enum CGPath {} pub type CGPathRef = *mut CGPath; +unsafe impl RefEncode for CGPath { + const ENCODING_REF: Encoding = Encoding::Unknown; +} + pub enum CGDataProvider {} pub type CGDataProviderRef = *mut CGDataProvider; @@ -23,6 +33,10 @@ pub type CGFontRef = *mut CGFont; pub enum CGContext {} pub type CGContextRef = *mut CGContext; +unsafe impl RefEncode for CGContext { + const ENCODING_REF: Encoding = Encoding::Unknown; +} + pub enum CGGradient {} pub type CGGradientRef = *mut CGGradient; diff --git a/core-text/src/font.rs b/core-text/src/font.rs index 87a8a5309..beb70b30f 100644 --- a/core-text/src/font.rs +++ b/core-text/src/font.rs @@ -193,7 +193,7 @@ pub fn new_from_name(name: &str, pt_size: f64) -> Result { } pub fn new_ui_font_for_language(ui_type: CTFontUIFontType, - size: f64, + size: CGFloat, language: Option) -> CTFont { unsafe {