From 3c737a9f1663a190942ce0424ecbe706ca2d6315 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 10 Feb 2015 20:05:18 +1100 Subject: [PATCH 01/76] Fix NSOpenGLContext init methods These are instance methods, not class methods --- src/appkit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 45855d7..5b5fb3c 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1341,11 +1341,11 @@ impl NSOpenGLContext for id { // Context Creation unsafe fn initWithFormat_shareContext_(self, format: id /* (NSOpenGLPixelFormat *) */, shareContext: id /* (NSOpenGLContext *) */) -> id /* (instancetype) */ { - msg_send()(class("NSOpenGLContext"), selector("initWithFormat:shareContext:"), format, shareContext) + msg_send()(self, selector("initWithFormat:shareContext:"), format, shareContext) } unsafe fn initWithCGLContextObj_(self, context: CGLContextObj) -> id /* (instancetype) */ { - msg_send()(class("NSOpenGLContext"), selector("initWithCGLContextObj:"), context) + msg_send()(self, selector("initWithCGLContextObj:"), context) } // Managing the Current Context From 549f168f26ad736d95bf4758e7cd0fff271ee094 Mon Sep 17 00:00:00 2001 From: Ivan Ukhov Date: Tue, 10 Feb 2015 21:27:30 +0100 Subject: [PATCH 02/76] Fix letter case in NSEventMask --- src/appkit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 5b5fb3c..1b57c4c 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1516,7 +1516,7 @@ bitflags! { const NSFlagsChangedMask = 1 << NSFlagsChanged as libc::c_ulonglong, const NSAppKitDefinedMask = 1 << NSAppKitDefined as libc::c_ulonglong, const NSSystemDefinedMask = 1 << NSSystemDefined as libc::c_ulonglong, - const NSAPplicationDefinedMask = 1 << NSApplicationDefined as libc::c_ulonglong, + const NSApplicationDefinedMask = 1 << NSApplicationDefined as libc::c_ulonglong, const NSPeriodicMask = 1 << NSPeriodic as libc::c_ulonglong, const NSCursorUpdateMask = 1 << NSCursorUpdate as libc::c_ulonglong, const NSScrollWheelMask = 1 << NSScrollWheel as libc::c_ulonglong, @@ -1525,7 +1525,7 @@ bitflags! { const NSOtherMouseDownMask = 1 << NSOtherMouseDown as libc::c_ulonglong, const NSOtherMouseUpMask = 1 << NSOtherMouseUp as libc::c_ulonglong, const NSOtherMouseDraggedMask = 1 << NSOtherMouseDragged as libc::c_ulonglong, - const NSEventMaskgesture = 1 << NSEventTypeGesture as libc::c_ulonglong, + const NSEventMaskGesture = 1 << NSEventTypeGesture as libc::c_ulonglong, const NSEventMaskSwipe = 1 << NSEventTypeSwipe as libc::c_ulonglong, const NSEventMaskRotate = 1 << NSEventTypeRotate as libc::c_ulonglong, const NSEventMaskBeginGesture = 1 << NSEventTypeBeginGesture as libc::c_ulonglong, From d7e68cf6bb3edaf9740cf8f6076bfa2a0d32a134 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Wed, 18 Feb 2015 14:39:15 +1000 Subject: [PATCH 03/76] Fix an osx internal assertion in NSWindow - ensure the C string is null terminated. --- src/appkit.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 1b57c4c..939c10e 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -22,6 +22,8 @@ pub use self::NSEventType::*; pub use self::NSEventMask::*; pub use self::NSEventModifierFlags::*; +use std::ffi::CString; + #[cfg(target_pointer_width = "32")] pub type CGFloat = f32; #[cfg(target_pointer_width = "64")] @@ -1201,14 +1203,14 @@ pub trait NSString { msg_send()(class("NSString"), selector("alloc")) } - unsafe fn initWithUTF8String_(self, c_string: *const u8) -> id; + unsafe fn initWithUTF8String_(self, c_string: *const i8) -> id; unsafe fn stringByAppendingString_(self, other: id) -> id; unsafe fn init_str(self, string: &str) -> Self; unsafe fn UTF8String(self) -> *const libc::c_char; } impl NSString for id { - unsafe fn initWithUTF8String_(self, c_string: *const u8) -> id { + unsafe fn initWithUTF8String_(self, c_string: *const i8) -> id { msg_send()(self, selector("initWithUTF8String:"), c_string as id) } @@ -1217,7 +1219,8 @@ impl NSString for id { } unsafe fn init_str(self, string: &str) -> id { - self.initWithUTF8String_(string.as_ptr()) + let cstring = CString::from_slice(string.as_bytes()); + self.initWithUTF8String_(cstring.as_ptr()) } unsafe fn UTF8String(self) -> *const libc::c_char { From b8a33f19a1420013871c3c87572753d6b185e1fa Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 20 Feb 2015 22:17:53 -0800 Subject: [PATCH 04/76] Use `objc_msgSend_fpret` for `backingStoreFactor`. This mistake led to a bizarre chain reaction in Servo that ultimately led to a hang only when optimization was enabled. --- src/appkit.rs | 4 ++-- src/base.rs | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 939c10e..5321697 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -9,7 +9,7 @@ #![allow(non_upper_case_globals)] -use base::{id, msg_send, msg_send_stret, class, selector}; +use base::{id, msg_send, msg_send_fpret, msg_send_stret, class, selector}; use base::{BOOL, SEL, NSInteger, NSUInteger}; use libc; @@ -1054,7 +1054,7 @@ impl NSWindow for id { // Converting Coordinates unsafe fn backingScaleFactor(self) -> CGFloat { - msg_send()(self, selector("backingScaleFactor")) + msg_send_fpret()(self, selector("backingScaleFactor")) } unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect { diff --git a/src/base.rs b/src/base.rs index a7d389e..56fd90c 100644 --- a/src/base.rs +++ b/src/base.rs @@ -159,7 +159,7 @@ extern { pub fn objc_loadWeak(location: *mut id) -> id; pub fn objc_storeWeak(location: *mut id, obj: id) -> id; pub fn objc_msgSend(target: id, selector: SEL, ...) -> id; - pub fn objc_msgSend_ftret(target: id, selector: SEL, ...) -> libc::c_double; + pub fn objc_msgSend_fpret(target: id, selector: SEL, ...) -> libc::c_double; pub fn objc_msgSend_stret(target: id, selector: SEL, ...); pub fn objc_msgSendSuper(sup: *mut objc_super, op: SEL, ...) -> id; pub fn objc_msgSendSuper_stret(sup: *mut objc_super, op: SEL, ...); @@ -242,6 +242,11 @@ pub unsafe fn msg_send() -> extern fn(target: id, selector: SEL, ...) -> T { mem::transmute(objc_msgSend) } +/// Returns an Objective-C message send function that returns a floating-point type. +pub unsafe fn msg_send_fpret() -> extern fn(target: id, selector: SEL, ...) -> T { + mem::transmute(objc_msgSend_fpret) +} + /// Returns an Objective-C message send function that returns a type `T`, where `T` is a struct /// with the attribute `#[repr(C)]`. pub unsafe fn msg_send_stret() -> extern fn(target: id, selector: SEL, ...) -> T { From 55cae60f78fae777be614d0071830c15a47605f0 Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Sun, 22 Feb 2015 16:11:19 +1100 Subject: [PATCH 05/76] Fixed runtime error in example by removing unnecessary null terminator --- examples/hello_world.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index d05000e..2ff9436 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -23,12 +23,12 @@ fn main() { // create Application menu let app_menu = NSMenu::new(nil).autorelease(); - let quit_prefix = NSString::alloc(nil).init_str("Quit \0"); + let quit_prefix = NSString::alloc(nil).init_str("Quit"); let quit_title = quit_prefix.stringByAppendingString_( NSProcessInfo::processInfo(nil).processName() ); let quit_action = selector("terminate:"); - let quit_key = NSString::alloc(nil).init_str("q\0"); + let quit_key = NSString::alloc(nil).init_str("q"); let quit_item = NSMenuItem::alloc(nil).initWithTitle_action_keyEquivalent_( quit_title, quit_action, @@ -46,7 +46,7 @@ fn main() { ).autorelease(); window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); window.center(); - let title = NSString::alloc(nil).init_str("Hello World!\0"); + let title = NSString::alloc(nil).init_str("Hello World!"); window.setTitle_(title); window.makeKeyAndOrderFront_(nil); From 2e4e155aedafeb18606d569bca609e4a4649ee66 Mon Sep 17 00:00:00 2001 From: Hyeon Kim Date: Fri, 27 Feb 2015 09:39:45 +0900 Subject: [PATCH 06/76] Fix compile error 'NSEventMask', 'NSEventModifierFlags' are not module, so commands like below is not valid anymore. pub use self::NSEventMask::*; pub use self::NSEventModifierFlags::*; --- src/appkit.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 5321697..a912712 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -19,8 +19,6 @@ pub use self::NSBackingStoreType::*; pub use self::NSOpenGLPixelFormatAttribute::*; pub use self::NSOpenGLPFAOpenGLProfiles::*; pub use self::NSEventType::*; -pub use self::NSEventMask::*; -pub use self::NSEventModifierFlags::*; use std::ffi::CString; From c0e12fdccf40323c27221193f7b229db419a19bb Mon Sep 17 00:00:00 2001 From: Hyeon Kim Date: Fri, 27 Feb 2015 10:03:15 +0900 Subject: [PATCH 07/76] Fix compile warning 1. You don't need `#![feature(hash)]` anymore. 2. `CString::from_slice` is deprecated now. --- src/appkit.rs | 2 +- src/base.rs | 4 ++-- src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index a912712..986799b 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1217,7 +1217,7 @@ impl NSString for id { } unsafe fn init_str(self, string: &str) -> id { - let cstring = CString::from_slice(string.as_bytes()); + let cstring = CString::new(string).unwrap(); self.initWithUTF8String_(cstring.as_ptr()) } diff --git a/src/base.rs b/src/base.rs index 56fd90c..69c9483 100644 --- a/src/base.rs +++ b/src/base.rs @@ -256,7 +256,7 @@ pub unsafe fn msg_send_stret() -> extern fn(target: id, selector: SEL, ...) - /// A convenience method to convert the name of a class to the class object itself. #[inline] pub fn class(name: &str) -> Class { - let name_c_str = ffi::CString::from_slice(name.as_bytes()); + let name_c_str = ffi::CString::new(name).unwrap(); unsafe { objc_getClass(name_c_str.as_ptr()) } @@ -265,7 +265,7 @@ pub fn class(name: &str) -> Class { /// A convenience method to convert the name of a selector to the selector object. #[inline] pub fn selector(name: &str) -> SEL { - let name_c_str = ffi::CString::from_slice(name.as_bytes()); + let name_c_str = ffi::CString::new(name).unwrap(); unsafe { sel_registerName(name_c_str.as_ptr()) } diff --git a/src/lib.rs b/src/lib.rs index 2e2a48f..d9dad34 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ #![crate_type = "rlib"] #![allow(missing_copy_implementations, non_snake_case)] -#![feature(std_misc, hash)] +#![feature(std_misc)] #[macro_use] extern crate bitflags; From e3f85ff51c5f262629ea5467430418ed87016cc4 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Fri, 6 Mar 2015 16:12:58 -0700 Subject: [PATCH 08/76] Use objc_msgSend_fpret consistently. --- src/appkit.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 986799b..42db41f 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -659,7 +659,7 @@ impl NSWindow for id { } unsafe fn alphaValue(self) -> CGFloat { - msg_send()(self, selector("alphaValue")) + msg_send_fpret()(self, selector("alphaValue")) } unsafe fn setAlphaValue_(self, windowAlpha: CGFloat) { @@ -742,7 +742,7 @@ impl NSWindow for id { } unsafe fn contentBorderThicknessForEdge_(self, edge: NSRectEdge) -> CGFloat { - msg_send()(self, selector("contentBorderThicknessForEdge:"), edge) + msg_send_fpret()(self, selector("contentBorderThicknessForEdge:"), edge) } unsafe fn setContentBorderThickness_forEdge_(self, borderThickness: CGFloat, edge: NSRectEdge) { @@ -778,7 +778,7 @@ impl NSWindow for id { } unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSUInteger) -> CGFloat { - msg_send()(self, selector("minFrameWidthWithTitle:styleMask:"), windowTitle, windowStyle) + msg_send_fpret()(self, selector("minFrameWidthWithTitle:styleMask:"), windowTitle, windowStyle) } unsafe fn contentRectForFrameRect_(self, windowFrame: NSRect) -> NSRect { @@ -2056,15 +2056,15 @@ impl NSEvent for id { // Getting Scroll Wheel Event Information unsafe fn deltaX(self) -> CGFloat { - msg_send()(self, selector("deltaX")) + msg_send_fpret()(self, selector("deltaX")) } unsafe fn deltaY(self) -> CGFloat { - msg_send()(self, selector("deltaY")) + msg_send_fpret()(self, selector("deltaY")) } unsafe fn deltaZ(self) -> CGFloat { - msg_send()(self, selector("deltaZ")) + msg_send_fpret()(self, selector("deltaZ")) } // Getting Tablet Proximity Information @@ -2156,7 +2156,7 @@ impl NSEvent for id { // Getting Touch and Gesture Information unsafe fn magnification(self) -> CGFloat { - msg_send()(self, selector("magnification")) + msg_send_fpret()(self, selector("magnification")) } unsafe fn touchesMatchingPhase_inView_(self, phase: NSTouchPhase, view: id /* (NSView *) */) -> id /* (NSSet *) */ { @@ -2183,11 +2183,11 @@ impl NSEvent for id { } unsafe fn scrollingDeltaX(self) -> CGFloat { - msg_send()(self, selector("scrollingDeltaX")) + msg_send_fpret()(self, selector("scrollingDeltaX")) } unsafe fn scrollingDeltaY(self) -> CGFloat { - msg_send()(self, selector("scrollingDeltaY")) + msg_send_fpret()(self, selector("scrollingDeltaY")) } unsafe fn momentumPhase(self) -> NSEventPhase { @@ -2280,7 +2280,7 @@ impl NSScreen for id { } unsafe fn backingScaleFactor(self) -> CGFloat { - msg_send()(self, selector("backingScaleFactor")) + msg_send_fpret()(self, selector("backingScaleFactor")) } unsafe fn convertRectFromBacking_(self, aRect: NSRect) -> NSRect { From 621242eb227cad581a78f8ccd8f1908b92f73647 Mon Sep 17 00:00:00 2001 From: Coeuvre Wong Date: Thu, 19 Mar 2015 09:21:51 +0800 Subject: [PATCH 09/76] Added more methods --- src/appkit.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 42db41f..265f776 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -112,6 +112,13 @@ pub enum NSApplicationActivationPolicy { NSApplicationActivationPolicyERROR = -1 } +#[repr(u64)] +pub enum NSApplicationTerminateReply { + NSTerminateCancel = 0, + NSTerminateNow = 1, + NSTerminateLater = 2, +} + #[repr(u64)] pub enum NSWindowMask { NSBorderlessWindowMask = 0, @@ -297,6 +304,7 @@ pub trait NSApplication { dequeue: BOOL) -> id; unsafe fn sendEvent_(self, an_event: id); unsafe fn postEvent_atStart_(self, anEvent: id, flag: BOOL); + unsafe fn stop_(self, sender: id); } impl NSApplication for id { @@ -336,6 +344,10 @@ impl NSApplication for id { unsafe fn postEvent_atStart_(self, anEvent: id, flag: BOOL) { msg_send()(self, selector("postEvent:atStart:"), anEvent, flag as libc::c_int) } + + unsafe fn stop_(self, sender: id) { + msg_send()(self, selector("stop:"), sender) + } } pub trait NSMenu { @@ -475,6 +487,7 @@ pub trait NSWindow { 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 aspectRatio(self) -> NSSize; unsafe fn setAspectRatio_(self, aspectRatio: NSSize); @@ -827,6 +840,10 @@ impl NSWindow for id { msg_send()(self, selector("cascadeTopLeftFromPoint:"), topLeft) } + unsafe fn setFrame_display_(self, windowFrame: NSRect, display: BOOL) { + msg_send()(self, selector("setFrame:display:"), windowFrame, display as libc::c_int) + } + unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: BOOL) { msg_send()(self, selector("setFrame:displayViews:"), windowFrame, display as libc::c_int) } @@ -1277,6 +1294,8 @@ pub trait NSOpenGLView { unsafe fn initWithFrame_pixelFormat_(self, frameRect: NSRect, format: id) -> id; unsafe fn display_(self); + unsafe fn setOpenGLContext_(self, context: id); + unsafe fn setPixelFormat_(self, pixelformat: id); } impl NSOpenGLView for id { @@ -1287,6 +1306,14 @@ impl NSOpenGLView for id { unsafe fn display_(self) { msg_send()(self, selector("display")) } + + unsafe fn setOpenGLContext_(self, context: id) { + msg_send()(self, selector("setOpenGLContext:"), context) + } + + unsafe fn setPixelFormat_(self, pixelformat: id) { + msg_send()(self, selector("setPixelFormat:"), pixelformat) + } } pub trait NSOpenGLPixelFormat { From 2ba1ebbb368507ac4ecda7a59d1a462227fa37bf Mon Sep 17 00:00:00 2001 From: Steven Sheldon Date: Mon, 16 Feb 2015 11:37:09 -0800 Subject: [PATCH 10/76] Use objc crate for runtime functions. --- Cargo.toml | 1 + src/appkit.rs | 634 +++++++++++++++++++++++++------------------------- src/base.rs | 273 +--------------------- src/lib.rs | 3 + 4 files changed, 329 insertions(+), 582 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9643938..31d279c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,4 @@ crate-type = ["rlib"] [dependencies] bitflags = "0.1" libc = "*" +objc = "0.1" diff --git a/src/appkit.rs b/src/appkit.rs index 265f776..89b6cef 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -9,7 +9,7 @@ #![allow(non_upper_case_globals)] -use base::{id, msg_send, msg_send_fpret, msg_send_stret, class, selector}; +use base::{id, class}; use base::{BOOL, SEL, NSInteger, NSUInteger}; use libc; @@ -103,7 +103,7 @@ extern { } pub unsafe fn NSApp() -> id { - msg_send()(class("NSApplication"), selector("sharedApplication")) + msg_send![class("NSApplication"), sharedApplication] } #[repr(i64)] @@ -254,7 +254,7 @@ pub static NSMainMenuWindowLevel: libc::int32_t = 24; pub trait NSAutoreleasePool { unsafe fn new(_: Self) -> id { - msg_send()(class("NSAutoreleasePool"), selector("new")) + msg_send![class("NSAutoreleasePool"), new] } unsafe fn autorelease(self) -> Self; @@ -263,17 +263,17 @@ pub trait NSAutoreleasePool { impl NSAutoreleasePool for id { unsafe fn autorelease(self) -> id { - msg_send()(self, selector("autorelease")) + msg_send![self, autorelease] } unsafe fn drain(self) { - msg_send()(self, selector("drain")) + msg_send![self, drain] } } pub trait NSProcessInfo { unsafe fn processInfo(_: Self) -> id { - msg_send()(class("NSProcessInfo"), selector("processInfo")) + msg_send![class("NSProcessInfo"), processInfo] } unsafe fn processName(self) -> id; @@ -281,7 +281,7 @@ pub trait NSProcessInfo { impl NSProcessInfo for id { unsafe fn processName(self) -> id { - msg_send()(self, selector("processName")) + msg_send![self, processName] } } @@ -289,7 +289,7 @@ pub type NSTimeInterval = libc::c_double; pub trait NSApplication { unsafe fn sharedApplication(_: Self) -> id { - msg_send()(class("NSApplication"), selector("sharedApplication")) + msg_send![class("NSApplication"), sharedApplication] } unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL; @@ -309,23 +309,23 @@ pub trait NSApplication { impl NSApplication for id { unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL { - msg_send()(self, selector("setActivationPolicy:"), policy as NSInteger) + msg_send![self, setActivationPolicy:policy as NSInteger] } unsafe fn setMainMenu_(self, menu: id) { - msg_send()(self, selector("setMainMenu:"), menu) + msg_send![self, setMainMenu:menu] } unsafe fn activateIgnoringOtherApps_(self, ignore: BOOL) { - msg_send()(self, selector("activateIgnoringOtherApps:"), ignore as libc::c_int) + msg_send![self, activateIgnoringOtherApps:ignore as libc::c_int] } unsafe fn run(self) { - msg_send()(self, selector("run")) + msg_send![self, run] } unsafe fn finishLaunching(self) { - msg_send()(self, selector("finishLaunching")) + msg_send![self, finishLaunching] } unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, @@ -333,26 +333,28 @@ impl NSApplication for id { expiration: id, in_mode: id, dequeue: BOOL) -> id { - msg_send()(self, selector("nextEventMatchingMask:untilDate:inMode:dequeue:"), - mask, expiration, in_mode, dequeue as libc::c_int) + msg_send![self, nextEventMatchingMask:mask + untilDate:expiration + inMode:in_mode + dequeue:dequeue as libc::c_int] } unsafe fn sendEvent_(self, an_event: id) { - msg_send()(self, selector("sendEvent:"), an_event) + msg_send![self, sendEvent:an_event] } unsafe fn postEvent_atStart_(self, anEvent: id, flag: BOOL) { - msg_send()(self, selector("postEvent:atStart:"), anEvent, flag as libc::c_int) + msg_send![self, postEvent:anEvent atStart:flag as libc::c_int] } unsafe fn stop_(self, sender: id) { - msg_send()(self, selector("stop:"), sender) + msg_send![self, stop:sender] } } pub trait NSMenu { unsafe fn new(_: Self) -> id { - msg_send()(class("NSMenu"), selector("new")) + msg_send![class("NSMenu"), new] } unsafe fn addItem_(self, menu_item: id); @@ -360,17 +362,17 @@ pub trait NSMenu { impl NSMenu for id { unsafe fn addItem_(self, menu_item: id) { - msg_send()(self, selector("addItem:"), menu_item) + msg_send![self, addItem:menu_item] } } pub trait NSMenuItem { unsafe fn alloc(_: Self) -> id { - msg_send()(class("NSMenuItem"), selector("alloc")) + msg_send![class("NSMenuItem"), alloc] } unsafe fn new(_: Self) -> id { - msg_send()(class("NSMenuItem"), selector("new")) + msg_send![class("NSMenuItem"), new] } unsafe fn initWithTitle_action_keyEquivalent_(self, title: id, action: SEL, key: id) -> id; @@ -379,11 +381,11 @@ pub trait NSMenuItem { impl NSMenuItem for id { unsafe fn initWithTitle_action_keyEquivalent_(self, title: id, action: SEL, key: id) -> id { - msg_send()(self, selector("initWithTitle:action:keyEquivalent:"), title, action, key) + msg_send![self, initWithTitle:title action:action keyEquivalent:key] } unsafe fn setSubmenu_(self, submenu: id) { - msg_send()(self, selector("setSubmenu:"), submenu) + msg_send![self, setSubmenu:submenu] } } @@ -415,7 +417,7 @@ bitflags! { pub trait NSWindow { unsafe fn alloc(_: Self) -> id { - msg_send()(class("NSWindow"), selector("alloc")) + msg_send![class("NSWindow"), alloc] } // Creating Windows @@ -639,8 +641,10 @@ impl NSWindow for id { style: NSUInteger, backing: NSBackingStoreType, defer: BOOL) -> id { - msg_send()(self, selector("initWithContentRect:styleMask:backing:defer:"), - rect, style, backing as NSUInteger, defer as libc::c_int) + msg_send![self, initWithContentRect:rect + styleMask:style + backing:backing as NSUInteger + defer:defer as libc::c_int] } unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self, @@ -649,133 +653,136 @@ impl NSWindow for id { backing: NSBackingStoreType, defer: BOOL, screen: id) -> id { - msg_send()(self, selector("initWithContentRect:styleMask:backing:defer:"), - rect, style, backing as NSUInteger, defer as libc::c_int, screen) + msg_send![self, initWithContentRect:rect + styleMask:style + backing:backing as NSUInteger + defer:defer as libc::c_int + screen:screen] } // Configuring Windows unsafe fn styleMask(self) -> NSUInteger { - msg_send()(self, selector("styleMask")) + msg_send![self, styleMask] } unsafe fn setStyleMask_(self, styleMask: NSUInteger) { - msg_send()(self, selector("setStyleMask:"), styleMask) + msg_send![self, setStyleMask:styleMask] } unsafe fn toggleFullScreen_(self, sender: id) { - msg_send()(self, selector("toggleFullScreen:"), sender) + msg_send![self, toggleFullScreen:sender] } unsafe fn worksWhenModal(self) -> BOOL { - msg_send()(self, selector("worksWhenModal")) + msg_send![self, worksWhenModal] } unsafe fn alphaValue(self) -> CGFloat { - msg_send_fpret()(self, selector("alphaValue")) + msg_send![self, alphaValue] } unsafe fn setAlphaValue_(self, windowAlpha: CGFloat) { - msg_send()(self, selector("setAlphaValue:"), windowAlpha) + msg_send![self, setAlphaValue:windowAlpha] } unsafe fn backgroundColor(self) -> id { - msg_send()(self, selector("backgroundColor")) + msg_send![self, backgroundColor] } unsafe fn setBackgroundColor_(self, color: id) { - msg_send()(self, selector("setBackgroundColor:"), color) + msg_send![self, setBackgroundColor:color] } unsafe fn colorSpace(self) -> id { - msg_send()(self, selector("colorSpace")) + msg_send![self, colorSpace] } unsafe fn setColorSpace_(self, colorSpace: id) { - msg_send()(self, selector("setColorSpace:"), colorSpace) + msg_send![self, setColorSpace:colorSpace] } unsafe fn contentView(self) -> id { - msg_send()(self, selector("contentView")) + msg_send![self, contentView] } unsafe fn setContentView_(self, view: id) { - msg_send()(self, selector("setContentView:"), view) + msg_send![self, setContentView:view] } unsafe fn canHide(self) -> BOOL { - msg_send()(self, selector("canHide")) + msg_send![self, canHide] } unsafe fn setCanHide_(self, canHide: BOOL) { - msg_send()(self, selector("setCanHide:"), canHide as libc::c_int) + msg_send![self, setCanHide:canHide as libc::c_int] } unsafe fn hidesOnDeactivate(self) -> BOOL { - msg_send()(self, selector("hidesOnDeactivate")) + msg_send![self, hidesOnDeactivate] } unsafe fn setHidesOnDeactivate_(self, hideOnDeactivate: BOOL) { - msg_send()(self, selector("setHidesOnDeactivate:"), hideOnDeactivate as libc::c_int) + msg_send![self, setHidesOnDeactivate:hideOnDeactivate as libc::c_int] } unsafe fn collectionBehavior(self) -> NSWindowCollectionBehavior { - msg_send()(self, selector("collectionBehavior")) + msg_send![self, collectionBehavior] } unsafe fn setCollectionBehavior_(self, collectionBehavior: NSWindowCollectionBehavior) { - msg_send()(self, selector("setCollectionBehavior:"), collectionBehavior) + msg_send![self, setCollectionBehavior:collectionBehavior] } unsafe fn setOpaque_(self, opaque: BOOL) { - msg_send()(self, selector("setOpaque:"), opaque as libc::c_int) + msg_send![self, setOpaque:opaque as libc::c_int] } unsafe fn hasShadow(self) -> BOOL { - msg_send()(self, selector("hasShadow")) + msg_send![self, hasShadow] } unsafe fn setHasShadow_(self, hasShadow: BOOL) { - msg_send()(self, selector("setHasShadow:"), hasShadow as libc::c_int) + msg_send![self, setHasShadow:hasShadow as libc::c_int] } unsafe fn invalidateShadow(self) { - msg_send()(self, selector("invalidateShadow")) + msg_send![self, invalidateShadow] } unsafe fn autorecalculatesContentBorderThicknessForEdge_(self, edge: NSRectEdge) -> BOOL { - msg_send()(self, selector("autorecalculatesContentBorderThicknessForEdge:"), edge) + msg_send![self, autorecalculatesContentBorderThicknessForEdge:edge] } unsafe fn setAutorecalculatesContentBorderThickness_forEdge_(self, autorecalculateContentBorderThickness: BOOL, edge: NSRectEdge) -> BOOL { - msg_send()(self, selector("setAutorecalculatesContentBorderThickness:forEdge:"), - autorecalculateContentBorderThickness as libc::c_int, edge) + msg_send![self, setAutorecalculatesContentBorderThickness: + autorecalculateContentBorderThickness as libc::c_int forEdge:edge] } unsafe fn contentBorderThicknessForEdge_(self, edge: NSRectEdge) -> CGFloat { - msg_send_fpret()(self, selector("contentBorderThicknessForEdge:"), edge) + msg_send![self, contentBorderThicknessForEdge:edge] } unsafe fn setContentBorderThickness_forEdge_(self, borderThickness: CGFloat, edge: NSRectEdge) { - msg_send()(self, selector("setContentBorderThickness:forEdge:"), borderThickness, edge) + msg_send![self, setContentBorderThickness:borderThickness forEdge:edge] } unsafe fn delegate(self) -> id { - msg_send()(self, selector("delegate")) + msg_send![self, delegate] } unsafe fn setDelegate_(self, delegate: id) { - msg_send()(self, selector("setDelegate:"), delegate) + msg_send![self, setDelegate:delegate] } unsafe fn preventsApplicationTerminationWhenModal(self) -> BOOL { - msg_send()(self, selector("preventsApplicationTerminationWhenModal")) + msg_send![self, preventsApplicationTerminationWhenModal] } unsafe fn setPreventsApplicationTerminationWhenModal_(self, flag: BOOL) { - msg_send()(self, selector("setPreventsApplicationTerminationWhenModal:"), flag as libc::c_int) + msg_send![self, setPreventsApplicationTerminationWhenModal:flag as libc::c_int] } // TODO: Accessing Window Information @@ -783,37 +790,37 @@ impl NSWindow for id { // Getting Layout Information unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSUInteger) -> NSRect { - msg_send_stret()(self, selector("contentRectForFrameRect:styleMask:"), windowFrame, windowStyle) + msg_send![self, contentRectForFrameRect:windowFrame styleMask:windowStyle] } unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSUInteger) -> NSRect { - msg_send_stret()(self, selector("frameRectForContentRect:styleMask:"), windowContentRect, windowStyle) + msg_send![self, frameRectForContentRect:windowContentRect styleMask:windowStyle] } unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSUInteger) -> CGFloat { - msg_send_fpret()(self, selector("minFrameWidthWithTitle:styleMask:"), windowTitle, windowStyle) + msg_send![self, minFrameWidthWithTitle:windowTitle styleMask:windowStyle] } unsafe fn contentRectForFrameRect_(self, windowFrame: NSRect) -> NSRect { - msg_send_stret()(self, selector("contentRectForFrameRect:"), windowFrame) + msg_send![self, contentRectForFrameRect:windowFrame] } unsafe fn frameRectForContentRect_(self, windowContent: NSRect) -> NSRect { - msg_send_stret()(self, selector("frameRectForContentRect:"), windowContent) + msg_send![self, frameRectForContentRect:windowContent] } // Managing Windows unsafe fn drawers(self) -> id { - msg_send()(self, selector("drawers")) + msg_send![self, drawers] } unsafe fn windowController(self) -> id { - msg_send()(self, selector("windowController")) + msg_send![self, windowController] } unsafe fn setWindowController_(self, windowController: id) { - msg_send()(self, selector("setWindowController:"), windowController) + msg_send![self, setWindowController:windowController] } // TODO: Managing Sheets @@ -821,201 +828,201 @@ impl NSWindow for id { // Sizing Windows unsafe fn frame(self) -> NSRect { - msg_send_stret()(self, selector("frame")) + msg_send![self, frame] } unsafe fn setFrameOrigin_(self, point: NSPoint) { - msg_send()(self, selector("setFrameOrigin:"), point) + msg_send![self, setFrameOrigin:point] } unsafe fn setFrameTopLeftPoint_(self, point: NSPoint) { - msg_send()(self, selector("setFrameTopLeftPoint:"), point) + msg_send![self, setFrameTopLeftPoint:point] } unsafe fn constrainFrameRect_toScreen_(self, frameRect: NSRect, screen: id) { - msg_send()(self, selector("constrainFrameRect:toScreen:"), frameRect, screen) + msg_send![self, constrainFrameRect:frameRect toScreen:screen] } unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint { - msg_send()(self, selector("cascadeTopLeftFromPoint:"), topLeft) + msg_send![self, cascadeTopLeftFromPoint:topLeft] } unsafe fn setFrame_display_(self, windowFrame: NSRect, display: BOOL) { - msg_send()(self, selector("setFrame:display:"), windowFrame, display as libc::c_int) + msg_send![self, setFrame:windowFrame display:display as libc::c_int] } unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: BOOL) { - msg_send()(self, selector("setFrame:displayViews:"), windowFrame, display as libc::c_int) + msg_send![self, setFrame:windowFrame displayViews:display as libc::c_int] } unsafe fn aspectRatio(self) -> NSSize { - msg_send()(self, selector("aspectRatio")) + msg_send![self, aspectRatio] } unsafe fn setAspectRatio_(self, aspectRatio: NSSize) { - msg_send()(self, selector("setAspectRatio:"), aspectRatio) + msg_send![self, setAspectRatio:aspectRatio] } unsafe fn minSize(self) -> NSSize { - msg_send()(self, selector("minSize")) + msg_send![self, minSize] } unsafe fn setMinSize_(self, minSize: NSSize) { - msg_send()(self, selector("setMinSize:"), minSize) + msg_send![self, setMinSize:minSize] } unsafe fn maxSize(self) -> NSSize { - msg_send()(self, selector("maxSize")) + msg_send![self, maxSize] } unsafe fn setMaxSize_(self, maxSize: NSSize) { - msg_send()(self, selector("setMaxSize:"), maxSize) + msg_send![self, setMaxSize:maxSize] } unsafe fn performZoom_(self, sender: id) { - msg_send()(self, selector("performZoom:"), sender) + msg_send![self, performZoom:sender] } unsafe fn zoom_(self, sender: id) { - msg_send()(self, selector("zoom:"), sender) + msg_send![self, zoom:sender] } unsafe fn resizeFlags(self) -> NSInteger { - msg_send()(self, selector("resizeFlags")) + msg_send![self, resizeFlags] } unsafe fn showsResizeIndicator(self) -> BOOL { - msg_send()(self, selector("showsResizeIndicator")) + msg_send![self, showsResizeIndicator] } unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: BOOL) { - msg_send()(self, selector("setShowsResizeIndicator:"), showsResizeIndicator as libc::c_int) + msg_send![self, setShowsResizeIndicator:showsResizeIndicator as libc::c_int] } unsafe fn resizeIncrements(self) -> NSSize { - msg_send()(self, selector("resizeIncrements")) + msg_send![self, resizeIncrements] } unsafe fn setResizeIncrements_(self, resizeIncrements: NSSize) { - msg_send()(self, selector("setResizeIncrements:"), resizeIncrements) + msg_send![self, setResizeIncrements:resizeIncrements] } unsafe fn preservesContentDuringLiveResize(self) -> BOOL { - msg_send()(self, selector("preservesContentDuringLiveResize")) + msg_send![self, preservesContentDuringLiveResize] } unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: BOOL) { - msg_send()(self, selector("setPreservesContentDuringLiveResize:"), preservesContentDuringLiveResize as libc::c_int) + msg_send![self, setPreservesContentDuringLiveResize:preservesContentDuringLiveResize as libc::c_int] } unsafe fn inLiveResize(self) -> BOOL { - msg_send()(self, selector("inLiveResize")) + msg_send![self, inLiveResize] } // Sizing Content unsafe fn contentAspectRatio(self) -> NSSize { - msg_send_stret()(self, selector("contentAspectRatio")) + msg_send![self, contentAspectRatio] } unsafe fn setContentAspectRatio_(self, contentAspectRatio: NSSize) { - msg_send()(self, selector("setContentAspectRatio:"), contentAspectRatio) + msg_send![self, setContentAspectRatio:contentAspectRatio] } unsafe fn contentMinSize(self) -> NSSize { - msg_send_stret()(self, selector("contentMinSize")) + msg_send![self, contentMinSize] } unsafe fn setContentMinSize_(self, contentMinSize: NSSize) { - msg_send()(self, selector("setContentMinSize:"), contentMinSize) + msg_send![self, setContentMinSize:contentMinSize] } unsafe fn contentSize(self) -> NSSize { - msg_send_stret()(self, selector("contentSize")) + msg_send![self, contentSize] } unsafe fn setContentSize_(self, contentSize: NSSize) { - msg_send()(self, selector("setContentSize:"), contentSize) + msg_send![self, setContentSize:contentSize] } unsafe fn contentMaxSize(self) -> NSSize { - msg_send_stret()(self, selector("contentMaxSize")) + msg_send![self, contentMaxSize] } unsafe fn setContentMaxSize_(self, contentMaxSize: NSSize) { - msg_send()(self, selector("setContentMaxSize:"), contentMaxSize) + msg_send![self, setContentMaxSize:contentMaxSize] } unsafe fn contentResizeIncrements(self) -> NSSize { - msg_send_stret()(self, selector("contentResizeIncrements")) + msg_send![self, contentResizeIncrements] } unsafe fn setContentResizeIncrements_(self, contentResizeIncrements: NSSize) { - msg_send()(self, selector("setContentResizeIncrements:"), contentResizeIncrements) + msg_send![self, setContentResizeIncrements:contentResizeIncrements] } // Managing Window Visibility and Occlusion State unsafe fn isVisible(self) -> BOOL { - msg_send()(self, selector("isVisible")) + msg_send![self, isVisible] } unsafe fn occlusionState(self) -> NSWindowOcclusionState { - msg_send()(self, selector("occlusionState")) + msg_send![self, occlusionState] } // Managing Window Layers unsafe fn orderOut_(self, sender: id) { - msg_send()(self, selector("orderOut:"), sender) + msg_send![self, orderOut:sender] } unsafe fn orderBack_(self, sender: id) { - msg_send()(self, selector("orderBack:"), sender) + msg_send![self, orderBack:sender] } unsafe fn orderFront_(self, sender: id) { - msg_send()(self, selector("orderFront:"), sender) + msg_send![self, orderFront:sender] } unsafe fn orderFrontRegardless(self) { - msg_send()(self, selector("orderFrontRegardless")) + msg_send![self, orderFrontRegardless] } unsafe fn orderFrontWindow_relativeTo_(self, ordering_mode: NSWindowOrderingMode, other_window_number: NSInteger) { - msg_send()(self, selector("orderWindow:relativeTo:"), ordering_mode, other_window_number) + msg_send![self, orderWindow:ordering_mode relativeTo:other_window_number] } unsafe fn level(self) -> NSInteger { - msg_send()(self, selector("level")) + msg_send![self, level] } unsafe fn setLevel_(self, level: NSInteger) { - msg_send()(self, selector("setLevel:"), level) + msg_send![self, setLevel:level] } // Managing Key Status unsafe fn canBecomeKeyWindow(self) -> BOOL { - msg_send()(self, selector("canBecomeKeyWindow")) + msg_send![self, canBecomeKeyWindow] } unsafe fn makeKeyWindow(self) { - msg_send()(self, selector("makeKeyWindow")) + msg_send![self, makeKeyWindow] } unsafe fn makeKeyAndOrderFront_(self, sender: id) { - msg_send()(self, selector("makeKeyAndOrderFront:"), sender) + msg_send![self, makeKeyAndOrderFront:sender] } // Managing Main Status unsafe fn canBecomeMainWindow(self) -> BOOL { - msg_send()(self, selector("canBecomeMainWindow")) + msg_send![self, canBecomeMainWindow] } unsafe fn makeMainWindow(self) { - msg_send()(self, selector("makeMainWindow")) + msg_send![self, makeMainWindow] } // TODO: Managing Toolbars @@ -1034,174 +1041,173 @@ impl NSWindow for id { // Handling Keyboard Events unsafe fn keyDown_(self, event: id) { - msg_send()(self, selector("keyDown:"), event) + msg_send![self, keyDown:event] } // Handling Mouse Events unsafe fn acceptsMouseMovedEvents(self) -> BOOL { - msg_send()(self, selector("acceptsMouseMovedEvents")) + msg_send![self, acceptsMouseMovedEvents] } unsafe fn ignoresMouseEvents(self) -> BOOL { - msg_send()(self, selector("ignoresMouseEvents")) + msg_send![self, ignoresMouseEvents] } unsafe fn setIgnoresMouseEvents_(self, ignoreMouseEvents: BOOL) { - msg_send()(self, selector("setIgnoresMouseEvents:"), ignoreMouseEvents as libc::c_int) + msg_send![self, setIgnoresMouseEvents:ignoreMouseEvents as libc::c_int] } unsafe fn mouseLocationOutsideOfEventStream(self) -> NSPoint { - msg_send()(self, selector("mouseLocationOutsideOfEventStream")) + msg_send![self, mouseLocationOutsideOfEventStream] } unsafe fn setAcceptsMouseMovedEvents_(self, acceptMouseMovedEvents: BOOL) { - msg_send()(self, selector("setAcceptsMouseMovedEvents:"), acceptMouseMovedEvents as libc::c_int) + msg_send![self, setAcceptsMouseMovedEvents:acceptMouseMovedEvents as libc::c_int] } unsafe fn windowNumberAtPoint_belowWindowWithWindowNumber_(self, point: NSPoint, windowNumber: NSInteger) -> NSInteger { - msg_send()(self, selector("windowNumberAtPoint:belowWindowWithWindowNumber:"), - point, windowNumber) + msg_send![self, windowNumberAtPoint:point belowWindowWithWindowNumber:windowNumber] } // Converting Coordinates unsafe fn backingScaleFactor(self) -> CGFloat { - msg_send_fpret()(self, selector("backingScaleFactor")) + msg_send![self, backingScaleFactor] } unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect { - msg_send_stret()(self, selector("backingAlignedRect:options:"), rect, options) + msg_send![self, backingAlignedRect:rect options:options] } unsafe fn convertRectFromBacking_(self, rect: NSRect) -> NSRect { - msg_send_stret()(self, selector("convertRectFromBacking:"), rect) + msg_send![self, convertRectFromBacking:rect] } unsafe fn convertRectToBacking_(self, rect: NSRect) -> NSRect { - msg_send_stret()(self, selector("convertRectToBacking:"), rect) + msg_send![self, convertRectToBacking:rect] } unsafe fn convertRectToScreen_(self, rect: NSRect) -> NSRect { - msg_send_stret()(self, selector("convertRectToScreen:"), rect) + msg_send![self, convertRectToScreen:rect] } unsafe fn convertRectFromScreen_(self, rect: NSRect) -> NSRect { - msg_send_stret()(self, selector("convertRectFromScreen:"), rect) + msg_send![self, convertRectFromScreen:rect] } // Accessing Edited Status unsafe fn setDocumentEdited_(self, documentEdited: BOOL) { - msg_send()(self, selector("setDocumentEdited:"), documentEdited as libc::c_int) + msg_send![self, setDocumentEdited:documentEdited as libc::c_int] } // Managing Titles unsafe fn title(self) -> id { - msg_send()(self, selector("title")) + msg_send![self, title] } unsafe fn setTitle_(self, title: id) { - msg_send()(self, selector("setTitle:"), title) + msg_send![self, setTitle:title] } unsafe fn setTitleWithRepresentedFilename_(self, filePath: id) { - msg_send()(self, selector("setTitleWithRepresentedFilename:"), filePath) + msg_send![self, setTitleWithRepresentedFilename:filePath] } unsafe fn representedFilename(self) -> id { - msg_send()(self, selector("representedFilename")) + msg_send![self, representedFilename] } unsafe fn setRepresentedFilename_(self, filePath: id) { - msg_send()(self, selector("setRepresentedFilename:"), filePath) + msg_send![self, setRepresentedFilename:filePath] } unsafe fn representedURL(self) -> id { - msg_send()(self, selector("representedURL")) + msg_send![self, representedURL] } unsafe fn setRepresentedURL_(self, representedURL: id) { - msg_send()(self, selector("setRepresentedURL:"), representedURL) + msg_send![self, setRepresentedURL:representedURL] } // Accessing Screen Information unsafe fn screen(self) -> id { - msg_send()(self, selector("screen")) + msg_send![self, screen] } unsafe fn deepestScreen(self) -> id { - msg_send()(self, selector("deepestScreen")) + msg_send![self, deepestScreen] } unsafe fn displaysWhenScreenProfileChanges(self) -> BOOL { - msg_send()(self, selector("displaysWhenScreenProfileChanges")) + msg_send![self, displaysWhenScreenProfileChanges] } unsafe fn setDisplaysWhenScreenProfileChanges_(self, displaysWhenScreenProfileChanges: BOOL) { - msg_send()(self, selector("setDisplaysWhenScreenProfileChanges:"), displaysWhenScreenProfileChanges as libc::c_int) + msg_send![self, setDisplaysWhenScreenProfileChanges:displaysWhenScreenProfileChanges as libc::c_int] } // Moving Windows unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: BOOL) { - msg_send()(self, selector("setMovableByWindowBackground:"), movableByWindowBackground as libc::c_int) + msg_send![self, setMovableByWindowBackground:movableByWindowBackground as libc::c_int] } unsafe fn setMovable_(self, movable: BOOL) { - msg_send()(self, selector("setMovable:"), movable as libc::c_int) + msg_send![self, setMovable:movable as libc::c_int] } unsafe fn center(self) { - msg_send()(self, selector("center")) + msg_send![self, center] } // Closing Windows unsafe fn performClose_(self, sender: id) { - msg_send()(self, selector("performClose:"), sender) + msg_send![self, performClose:sender] } unsafe fn close(self) { - msg_send()(self, selector("close")) + msg_send![self, close] } unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: BOOL) { - msg_send()(self, selector("setReleasedWhenClosed:"), releasedWhenClosed as libc::c_int) + msg_send![self, setReleasedWhenClosed:releasedWhenClosed as libc::c_int] } // Minimizing Windows unsafe fn performMiniaturize_(self, sender: id) { - msg_send()(self, selector("performMiniaturize:"), sender) + msg_send![self, performMiniaturize:sender] } unsafe fn miniaturize_(self, sender: id) { - msg_send()(self, selector("miniaturize:"), sender) + msg_send![self, miniaturize:sender] } unsafe fn deminiaturize_(self, sender: id) { - msg_send()(self, selector("deminiaturize:"), sender) + msg_send![self, deminiaturize:sender] } unsafe fn miniwindowImage(self) -> id { - msg_send()(self, selector("miniwindowImage")) + msg_send![self, miniwindowImage] } unsafe fn setMiniwindowImage_(self, miniwindowImage: id) { - msg_send()(self, selector("setMiniwindowImage:"), miniwindowImage) + msg_send![self, setMiniwindowImage:miniwindowImage] } unsafe fn miniwindowTitle(self) -> id { - msg_send()(self, selector("miniwindowTitle")) + msg_send![self, miniwindowTitle] } unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id) { - msg_send()(self, selector("setMiniwindowTitle:"), miniwindowTitle) + msg_send![self, setMiniwindowTitle:miniwindowTitle] } // TODO: Getting the Dock Tile @@ -1215,7 +1221,7 @@ impl NSWindow for id { pub trait NSString { unsafe fn alloc(_: Self) -> id { - msg_send()(class("NSString"), selector("alloc")) + msg_send![class("NSString"), alloc] } unsafe fn initWithUTF8String_(self, c_string: *const i8) -> id; @@ -1226,11 +1232,11 @@ pub trait NSString { impl NSString for id { unsafe fn initWithUTF8String_(self, c_string: *const i8) -> id { - msg_send()(self, selector("initWithUTF8String:"), c_string as id) + msg_send![self, initWithUTF8String:c_string as id] } unsafe fn stringByAppendingString_(self, other: id) -> id { - msg_send()(self, selector("stringByAppendingString:"), other) + msg_send![self, stringByAppendingString:other] } unsafe fn init_str(self, string: &str) -> id { @@ -1239,13 +1245,13 @@ impl NSString for id { } unsafe fn UTF8String(self) -> *const libc::c_char { - msg_send()(self, selector("UTF8String")) + msg_send![self, UTF8String] } } pub trait NSView { unsafe fn alloc(_: Self) -> id { - msg_send()(class("NSView"), selector("alloc")) + msg_send![class("NSView"), alloc] } unsafe fn init(self) -> id; @@ -1259,37 +1265,37 @@ pub trait NSView { impl NSView for id { unsafe fn init(self) -> id { - msg_send()(self, selector("init")) + msg_send![self, init] } unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { - msg_send()(self, selector("initWithFrame:"), frameRect) + msg_send![self, initWithFrame:frameRect] } unsafe fn bounds(self) -> NSRect { - msg_send_stret()(self, selector("bounds")) + msg_send![self, bounds] } unsafe fn frame(self) -> NSRect { - msg_send_stret()(self, selector("frame")) + msg_send![self, frame] } unsafe fn display_(self) { - msg_send()(self, selector("display")) + msg_send![self, display] } unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: BOOL) { - msg_send()(self, selector("setWantsBestResolutionOpenGLSurface:"), flag as libc::c_int) + msg_send![self, setWantsBestResolutionOpenGLSurface:flag as libc::c_int] } unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint { - msg_send()(self, selector("convertPoint:fromView:"), point, view) + msg_send![self, convertPoint:point fromView:view] } } pub trait NSOpenGLView { unsafe fn alloc(_: Self) -> id { - msg_send()(class("NSOpenGLView"), selector("alloc")) + msg_send![class("NSOpenGLView"), alloc] } unsafe fn initWithFrame_pixelFormat_(self, frameRect: NSRect, format: id) -> id; @@ -1300,25 +1306,25 @@ pub trait NSOpenGLView { impl NSOpenGLView for id { unsafe fn initWithFrame_pixelFormat_(self, frameRect: NSRect, format: id) -> id { - msg_send()(self, selector("initWithFrame:pixelFormat:"), frameRect, format) + msg_send![self, initWithFrame:frameRect pixelFormat:format] } unsafe fn display_(self) { - msg_send()(self, selector("display")) + msg_send![self, display] } unsafe fn setOpenGLContext_(self, context: id) { - msg_send()(self, selector("setOpenGLContext:"), context) + msg_send![self, setOpenGLContext:context] } unsafe fn setPixelFormat_(self, pixelformat: id) { - msg_send()(self, selector("setPixelFormat:"), pixelformat) + msg_send![self, setPixelFormat:pixelformat] } } pub trait NSOpenGLPixelFormat { unsafe fn alloc(_: Self) -> id { - msg_send()(class("NSOpenGLPixelFormat"), selector("alloc")) + msg_send![class("NSOpenGLPixelFormat"), alloc] } unsafe fn initWithAttributes_(self, attributes: &[u32]) -> id; @@ -1326,13 +1332,13 @@ pub trait NSOpenGLPixelFormat { impl NSOpenGLPixelFormat for id { unsafe fn initWithAttributes_(self, attributes: &[u32]) -> id { - msg_send()(self, selector("initWithAttributes:"), attributes) + msg_send![self, initWithAttributes:attributes] } } pub trait NSOpenGLContext { unsafe fn alloc(_: Self) -> id { - msg_send()(class("NSOpenGLContext"), selector("alloc")) + msg_send![class("NSOpenGLContext"), alloc] } // Context Creation @@ -1369,85 +1375,85 @@ impl NSOpenGLContext for id { // Context Creation unsafe fn initWithFormat_shareContext_(self, format: id /* (NSOpenGLPixelFormat *) */, shareContext: id /* (NSOpenGLContext *) */) -> id /* (instancetype) */ { - msg_send()(self, selector("initWithFormat:shareContext:"), format, shareContext) + msg_send![self, initWithFormat:format shareContext:shareContext] } unsafe fn initWithCGLContextObj_(self, context: CGLContextObj) -> id /* (instancetype) */ { - msg_send()(self, selector("initWithCGLContextObj:"), context) + msg_send![self, initWithCGLContextObj:context] } // Managing the Current Context unsafe fn clearCurrentContext(_: Self) { - msg_send()(class("NSOpenGLContext"), selector("clearCurrentContext")) + msg_send![class("NSOpenGLContext"), clearCurrentContext] } unsafe fn currentContext(_: Self) -> id /* (NSOpenGLContext *) */ { - msg_send()(class("NSOpenGLContext"), selector("currentContext")) + msg_send![class("NSOpenGLContext"), currentContext] } unsafe fn makeCurrentContext(self) { - msg_send()(self, selector("makeCurrentContext")) + msg_send![self, makeCurrentContext] } // Drawable Object Management unsafe fn setView_(self, view: id /* (NSView *) */) { - msg_send()(self, selector("setView:"), view) + msg_send![self, setView:view] } unsafe fn view(self) -> id /* (NSView *) */ { - msg_send()(self, selector("view")) + msg_send![self, view] } unsafe fn clearDrawable(self) { - msg_send()(self, selector("clearDrawable")) + msg_send![self, clearDrawable] } unsafe fn update(self) { - msg_send()(self, selector("update")) + msg_send![self, update] } // Flushing the Drawing Buffer unsafe fn flushBuffer(self) { - msg_send()(self, selector("flushBuffer")) + msg_send![self, flushBuffer] } // Context Parameter Handling unsafe fn setValues_forParameter_(self, vals: *const GLint, param: NSOpenGLContextParameter) { - msg_send()(self, selector("setValues:forParameter:"), vals, param) + msg_send![self, setValues:vals forParameter:param] } unsafe fn getValues_forParameter_(self, vals: *mut GLint, param: NSOpenGLContextParameter) { - msg_send()(self, selector("getValues:forParameter:"), vals, param) + msg_send![self, getValues:vals forParameter:param] } // Working with Virtual Screens unsafe fn setCurrentVirtualScreen_(self, screen: GLint) { - msg_send()(self, selector("setCurrentVirtualScreen:"), screen) + msg_send![self, setCurrentVirtualScreen:screen] } unsafe fn currentVirtualScreen(self) -> GLint { - msg_send()(self, selector("currentVirtualScreen")) + msg_send![self, currentVirtualScreen] } // Getting the CGL Context Object unsafe fn CGLContextObj(self) -> CGLContextObj { - msg_send()(self, selector("CGLContextObj")) + msg_send![self, CGLContextObj] } } pub trait NSDate { unsafe fn distantPast(_: Self) -> id { - msg_send()(class("NSDate"), selector("distantPast")) + msg_send![class("NSDate"), distantPast] } unsafe fn distantFuture(_: Self) -> id { - msg_send()(class("NSDate"), selector("distantFuture")) + msg_send![class("NSDate"), distantFuture] } } @@ -1696,6 +1702,7 @@ pub trait NSEvent { modifierFlags: NSEventModifierFlags, timestamp: NSTimeInterval, windowNumber: NSInteger, + context: id /* (NSGraphicsContext *) */, characters: id /* (NSString *) */, unmodCharacters: id /* (NSString *) */, repeatKey: BOOL, @@ -1841,23 +1848,22 @@ impl NSEvent for id { modifierFlags: NSEventModifierFlags, timestamp: NSTimeInterval, windowNumber: NSInteger, + context: id /* (NSGraphicsContext *) */, characters: id /* (NSString *) */, unmodCharacters: id /* (NSString *) */, repeatKey: BOOL, code: libc::c_ushort) -> id /* (NSEvent *) */ { - msg_send()(class("NSEvent"), - selector("keyEventWithType:location:modifierFlags:timestamp:windowNumber:\ - context:characters:charactersIgnoringModifiers:isARepeat:keyCode:"), - eventType, - location, - modifierFlags, - timestamp, - windowNumber, - characters, - unmodCharacters, - repeatKey as libc::c_int, - code as libc::c_int) + msg_send![class("NSEvent"), keyEventWithType:eventType + location:location + modifierFlags:modifierFlags + timestamp:timestamp + windowNumber:windowNumber + context:context + characters:characters + charactersIgnoringModifiers:unmodCharacters + isARepeat:repeatKey as libc::c_int + keyCode:code as libc::c_int] } unsafe fn mouseEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_clickCount_pressure_( @@ -1872,18 +1878,15 @@ impl NSEvent for id { clickCount: NSInteger, pressure: libc::c_float) -> id /* (NSEvent *) */ { - msg_send()(class("NSEvent"), - selector("mouseEventWithType:location:modifierFlags:timestamp:windowNumber:\ - context:eventNumber:clickCount:pressure:"), - eventType, - location, - modifierFlags, - timestamp, - windowNumber, - context, - eventNumber, - clickCount, - pressure as libc::c_double) + msg_send![class("NSEvent"), mouseEventWithType:eventType + location:location + modifierFlags:modifierFlags + timestamp:timestamp + windowNumber:windowNumber + context:context + eventNumber:eventNumber + clickCount:clickCount + pressure:pressure as libc::c_double] } unsafe fn enterExitEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_trackingNumber_userData_( @@ -1898,18 +1901,15 @@ impl NSEvent for id { trackingNumber: NSInteger, userData: *mut libc::c_void) -> id /* (NSEvent *) */ { - msg_send()(class("NSEvent"), - selector("enterExitEventWithType:location:modifierFlags:timestamp:windowNumber:\ - context:eventNumber:trackingNumber:userData:"), - eventType, - location, - modifierFlags, - timestamp, - windowNumber, - context, - eventNumber, - trackingNumber, - userData) + msg_send![class("NSEvent"), enterExitEventWithType:eventType + location:location + modifierFlags:modifierFlags + timestamp:timestamp + windowNumber:windowNumber + context:context + eventNumber:eventNumber + trackingNumber:trackingNumber + userData:userData] } unsafe fn otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_( @@ -1924,66 +1924,62 @@ impl NSEvent for id { data1: NSInteger, data2: NSInteger) -> id /* (NSEvent *) */ { - msg_send()(class("NSEvent"), - selector("otherEventWithType:location:modifierFlags:timestamp:windowNumber:\ - context:subtype:data1:data2:"), - eventType, - location, - modifierFlags, - modifierFlags, - timestamp, - windowNumber, - context, - subtype, - data1, - data2) + msg_send![class("NSEvent"), otherEventWithType:eventType + location:location + modifierFlags:modifierFlags + timestamp:timestamp + windowNumber:windowNumber + context:context + subtype:subtype + data1:data1 + data2:data2] } unsafe fn eventWithEventRef_(_: Self, eventRef: *const libc::c_void) -> id { - msg_send()(class("NSEvent"), selector("eventWithEventRef:"), eventRef) + msg_send![class("NSEvent"), eventWithEventRef:eventRef] } unsafe fn eventWithCGEvent_(_: Self, cgEvent: *mut libc::c_void /* CGEventRef */) -> id { - msg_send()(class("NSEvent"), selector("eventWithCGEvent:"), cgEvent) + msg_send![class("NSEvent"), eventWithCGEvent:cgEvent] } // Getting General Event Information unsafe fn context(self) -> id /* (NSGraphicsContext *) */ { - msg_send()(self, selector("context")) + msg_send![self, context] } unsafe fn locationInWindow(self) -> NSPoint { - msg_send()(self, selector("locationInWindow")) + msg_send![self, locationInWindow] } unsafe fn modifierFlags(self) -> NSEventModifierFlags { - msg_send()(self, selector("modifierFlags")) + msg_send![self, modifierFlags] } unsafe fn timestamp(self) -> NSTimeInterval { - msg_send()(self, selector("timestamp")) + msg_send![self, timestamp] } // NOTE: renamed from `- type` due to Rust keyword collision unsafe fn eventType(self) -> NSEventType { - msg_send()(self, selector("type")) + msg_send![self, type] } unsafe fn window(self) -> id /* (NSWindow *) */ { - msg_send()(self, selector("window")) + msg_send![self, window] } unsafe fn windowNumber(self) -> NSInteger { - msg_send()(self, selector("windowNumber")) + msg_send![self, windowNumber] } unsafe fn eventRef(self) -> *const libc::c_void { - msg_send()(self, selector("eventRef")) + msg_send![self, eventRef] } unsafe fn CGEvent(self) -> *mut libc::c_void /* CGEventRef */ { - msg_send()(self, selector("CGEvent")) + msg_send![self, CGEvent] } // Getting Key Event Information @@ -1991,207 +1987,207 @@ impl NSEvent for id { // NOTE: renamed from `+ modifierFlags` due to conflict with `- modifierFlags` unsafe fn currentModifierFlags(_: Self) -> NSEventModifierFlags { - msg_send()(class("NSEvent"), selector("currentModifierFlags")) + msg_send![class("NSEvent"), currentModifierFlags] } unsafe fn keyRepeatDelay(_: Self) -> NSTimeInterval { - msg_send()(class("NSEvent"), selector("keyRepeatDelay")) + msg_send![class("NSEvent"), keyRepeatDelay] } unsafe fn keyRepeatInterval(_: Self) -> NSTimeInterval { - msg_send()(class("NSEvent"), selector("keyRepeatInterval")) + msg_send![class("NSEvent"), keyRepeatInterval] } unsafe fn characters(self) -> id /* (NSString *) */ { - msg_send()(self, selector("characters")) + msg_send![self, characters] } unsafe fn charactersIgnoringModifiers(self) -> id /* (NSString *) */ { - msg_send()(self, selector("charactersIgnoringModifiers")) + msg_send![self, charactersIgnoringModifiers] } unsafe fn keyCode(self) -> libc::c_ushort { - msg_send()(self, selector("keyCode")) + msg_send![self, keyCode] } // Getting Mouse Event Information unsafe fn pressedMouseButtons(_: Self) -> NSUInteger { - msg_send()(class("NSEvent"), selector("pressedMouseButtons")) + msg_send![class("NSEvent"), pressedMouseButtons] } unsafe fn doubleClickInterval(_: Self) -> NSTimeInterval { - msg_send()(class("NSEvent"), selector("doubleClickInterval")) + msg_send![class("NSEvent"), doubleClickInterval] } unsafe fn mouseLocation(_: Self) -> NSPoint { - msg_send()(class("NSEvent"), selector("mouseLocation")) + msg_send![class("NSEvent"), mouseLocation] } unsafe fn buttonNumber(self) -> NSInteger { - msg_send()(self, selector("buttonNumber")) + msg_send![self, buttonNumber] } unsafe fn clickCount(self) -> NSInteger { - msg_send()(self, selector("clickCount")) + msg_send![self, clickCount] } unsafe fn pressure(self) -> libc::c_float { - msg_send()(self, selector("pressure")) + msg_send![self, pressure] } unsafe fn setMouseCoalescingEnabled_(_: Self, flag: BOOL) { - msg_send()(class("NSEvent"), selector("setMouseCoalescingEnabled:"), flag as libc::c_int) + msg_send![class("NSEvent"), setMouseCoalescingEnabled:flag as libc::c_int] } unsafe fn isMouseCoalescingEnabled(_: Self) -> BOOL { - msg_send()(class("NSEvent"), selector("isMouseCoalescingEnabled")) + msg_send![class("NSEvent"), isMouseCoalescingEnabled] } // Getting Mouse-Tracking Event Information unsafe fn eventNumber(self) -> NSInteger { - msg_send()(self, selector("eventNumber")) + msg_send![self, eventNumber] } unsafe fn trackingNumber(self) -> NSInteger { - msg_send()(self, selector("trackingNumber")) + msg_send![self, trackingNumber] } unsafe fn trackingArea(self) -> id /* (NSTrackingArea *) */ { - msg_send()(self, selector("trackingArea")) + msg_send![self, trackingArea] } unsafe fn userData(self) -> *const libc::c_void { - msg_send()(self, selector("userData")) + msg_send![self, userData] } // Getting Custom Event Information unsafe fn data1(self) -> NSInteger { - msg_send()(self, selector("data1")) + msg_send![self, data1] } unsafe fn data2(self) -> NSInteger { - msg_send()(self, selector("data2")) + msg_send![self, data2] } unsafe fn subtype(self) -> NSEventSubtype { - msg_send()(self, selector("subtype")) + msg_send![self, subtype] } // Getting Scroll Wheel Event Information unsafe fn deltaX(self) -> CGFloat { - msg_send_fpret()(self, selector("deltaX")) + msg_send![self, deltaX] } unsafe fn deltaY(self) -> CGFloat { - msg_send_fpret()(self, selector("deltaY")) + msg_send![self, deltaY] } unsafe fn deltaZ(self) -> CGFloat { - msg_send_fpret()(self, selector("deltaZ")) + msg_send![self, deltaZ] } // Getting Tablet Proximity Information unsafe fn capabilityMask(self) -> NSUInteger { - msg_send()(self, selector("capabilityMask")) + msg_send![self, capabilityMask] } unsafe fn deviceID(self) -> NSUInteger { - msg_send()(self, selector("deviceID")) + msg_send![self, deviceID] } unsafe fn pointingDeviceID(self) -> NSUInteger { - msg_send()(self, selector("pointingDeviceID")) + msg_send![self, pointingDeviceID] } unsafe fn pointingDeviceSerialNumber(self) -> NSUInteger { - msg_send()(self, selector("pointingDeviceSerialNumber")) + msg_send![self, pointingDeviceSerialNumber] } unsafe fn pointingDeviceType(self) -> NSPointingDeviceType { - msg_send()(self, selector("pointingDeviceType")) + msg_send![self, pointingDeviceType] } unsafe fn systemTabletID(self) -> NSUInteger { - msg_send()(self, selector("systemTabletID")) + msg_send![self, systemTabletID] } unsafe fn tabletID(self) -> NSUInteger { - msg_send()(self, selector("tabletID")) + msg_send![self, tabletID] } unsafe fn uniqueID(self) -> libc::c_ulonglong { - msg_send()(self, selector("uniqueID")) + msg_send![self, uniqueID] } unsafe fn vendorID(self) -> NSUInteger { - msg_send()(self, selector("vendorID")) + msg_send![self, vendorID] } unsafe fn vendorPointingDeviceType(self) -> NSUInteger { - msg_send()(self, selector("vendorPointingDeviceType")) + msg_send![self, vendorPointingDeviceType] } // Getting Tablet Pointing Information unsafe fn absoluteX(self) -> NSInteger { - msg_send()(self, selector("absoluteX")) + msg_send![self, absoluteX] } unsafe fn absoluteY(self) -> NSInteger { - msg_send()(self, selector("absoluteY")) + msg_send![self, absoluteY] } unsafe fn absoluteZ(self) -> NSInteger { - msg_send()(self, selector("absoluteZ")) + msg_send![self, absoluteZ] } unsafe fn buttonMask(self) -> NSEventButtonMask { - msg_send()(self, selector("buttonMask")) + msg_send![self, buttonMask] } unsafe fn rotation(self) -> libc::c_float { - msg_send()(self, selector("rotation")) + msg_send![self, rotation] } unsafe fn tangentialPressure(self) -> libc::c_float { - msg_send()(self, selector("tangentialPressure")) + msg_send![self, tangentialPressure] } unsafe fn tilt(self) -> NSPoint { - msg_send()(self, selector("tilt")) + msg_send![self, tilt] } unsafe fn vendorDefined(self) -> id { - msg_send()(self, selector("vendorDefined")) + msg_send![self, vendorDefined] } // Requesting and Stopping Periodic Events unsafe fn startPeriodicEventsAfterDelay_withPeriod_(_: Self, delaySeconds: NSTimeInterval, periodSeconds: NSTimeInterval) { - msg_send()(class("NSEvent"), selector("startPeriodicEventsAfterDelay:withPeriod:"), delaySeconds, periodSeconds) + msg_send![class("NSEvent"), startPeriodicEventsAfterDelay:delaySeconds withPeriod:periodSeconds] } unsafe fn stopPeriodicEvents(_: Self) { - msg_send()(class("NSEvent"), selector("stopPeriodicEvents")) + msg_send![class("NSEvent"), stopPeriodicEvents] } // Getting Touch and Gesture Information unsafe fn magnification(self) -> CGFloat { - msg_send_fpret()(self, selector("magnification")) + msg_send![self, magnification] } unsafe fn touchesMatchingPhase_inView_(self, phase: NSTouchPhase, view: id /* (NSView *) */) -> id /* (NSSet *) */ { - msg_send()(self, selector("touchesMatchingPhase:inView:"), phase, view) + msg_send![self, touchesMatchingPhase:phase inView:view] } unsafe fn isSwipeTrackingFromScrollEventsEnabled(_: Self) -> BOOL { - msg_send()(class("NSEvent"), selector("isSwipeTrackingFromScrollEventsEnabled")) + msg_send![class("NSEvent"), isSwipeTrackingFromScrollEventsEnabled] } // Monitoring Application Events @@ -2200,36 +2196,36 @@ impl NSEvent for id { // TODO: addLocalMonitorForEventsMatchingMask_handler_ (unsure how to bind to blocks) unsafe fn removeMonitor_(_: Self, eventMonitor: id) { - msg_send()(class("NSEvent"), selector("removeMonitor:"), eventMonitor) + msg_send![class("NSEvent"), removeMonitor:eventMonitor] } // Scroll Wheel and Flick Events unsafe fn hasPreciseScrollingDeltas(self) -> BOOL { - msg_send()(self, selector("hasPreciseScrollingDeltas")) + msg_send![self, hasPreciseScrollingDeltas] } unsafe fn scrollingDeltaX(self) -> CGFloat { - msg_send_fpret()(self, selector("scrollingDeltaX")) + msg_send![self, scrollingDeltaX] } unsafe fn scrollingDeltaY(self) -> CGFloat { - msg_send_fpret()(self, selector("scrollingDeltaY")) + msg_send![self, scrollingDeltaY] } unsafe fn momentumPhase(self) -> NSEventPhase { - msg_send()(self, selector("momentumPhase")) + msg_send![self, momentumPhase] } unsafe fn phase(self) -> NSEventPhase { - msg_send()(self, selector("phase")) + msg_send![self, phase] } // TODO: trackSwipeEventWithOptions_dampenAmountThresholdMin_max_usingHandler_ (unsure how to bind to blocks) // Converting a Mouse Event’s Position into a Sprite Kit Node’s Coordinate Space unsafe fn locationInNode_(self, node: id /* (SKNode *) */) -> CGPoint { - msg_send_stret()(self, selector("locationInNode:"), node) + msg_send![self, locationInNode:node] } } @@ -2259,62 +2255,62 @@ impl NSScreen for id { // Getting NSScreen Objects unsafe fn mainScreen(_: Self) -> id /* (NSScreen *) */ { - msg_send()(class("NSScreen"), selector("mainScreen")) + msg_send![class("NSScreen"), mainScreen] } unsafe fn deepestScreen(_: Self) -> id /* (NSScreen *) */ { - msg_send()(class("NSScreen"), selector("deepestScreen")) + msg_send![class("NSScreen"), deepestScreen] } unsafe fn screens(_: Self) -> id /* (NSArray *) */ { - msg_send()(class("NSScreen"), selector("screens")) + msg_send![class("NSScreen"), screens] } // Getting Screen Information unsafe fn depth(self) -> NSWindowDepth { - msg_send()(self, selector("depth")) + msg_send![self, depth] } unsafe fn frame(self) -> NSRect { - msg_send_stret()(self, selector("frame")) + msg_send![self, frame] } unsafe fn supportedWindowDepths(self) -> *const NSWindowDepth { - msg_send()(self, selector("supportedWindowDepths")) + msg_send![self, supportedWindowDepths] } unsafe fn deviceDescription(self) -> id /* (NSDictionary *) */ { - msg_send()(self, selector("deviceDescription")) + msg_send![self, deviceDescription] } unsafe fn visibleFrame(self) -> NSRect { - msg_send_stret()(self, selector("visibleFrame")) + msg_send![self, visibleFrame] } unsafe fn colorSpace(self) -> id /* (NSColorSpace *) */ { - msg_send()(self, selector("colorSpace")) + msg_send![self, colorSpace] } unsafe fn screensHaveSeparateSpaces(_: Self) -> BOOL { - msg_send()(class("NSScreen"), selector("screensHaveSeparateSpaces")) + msg_send![class("NSScreen"), screensHaveSeparateSpaces] } // Screen Backing Coordinate Conversion unsafe fn backingAlignedRect_options_(self, aRect: NSRect, options: NSAlignmentOptions) -> NSRect { - msg_send_stret()(self, selector("backingAlignedRect:options:"), aRect, options) + msg_send![self, backingAlignedRect:aRect options:options] } unsafe fn backingScaleFactor(self) -> CGFloat { - msg_send_fpret()(self, selector("backingScaleFactor")) + msg_send![self, backingScaleFactor] } unsafe fn convertRectFromBacking_(self, aRect: NSRect) -> NSRect { - msg_send_stret()(self, selector("convertRectFromBacking:"), aRect) + msg_send![self, convertRectFromBacking:aRect] } unsafe fn convertRectToBacking_(self, aRect: NSRect) -> NSRect { - msg_send_stret()(self, selector("convertRectToBacking:"), aRect) + msg_send![self, convertRectToBacking:aRect] } } diff --git a/src/base.rs b/src/base.rs index 69c9483..11737dc 100644 --- a/src/base.rs +++ b/src/base.rs @@ -8,22 +8,15 @@ // except according to those terms. use libc; -use std::ffi; +use objc::runtime; use std::mem; -pub type Category = libc::intptr_t; -pub type Class = libc::intptr_t; +pub use objc::runtime::{BOOL, NO, YES}; + +pub type Class = *mut runtime::Class; #[allow(non_camel_case_types)] -pub type id = libc::intptr_t; -pub type IMP = extern "C" fn(id, SEL) -> id; -pub type Ivar = libc::intptr_t; -pub type Method = libc::intptr_t; -#[allow(non_camel_case_types)] -pub type objc_AssociationPolicy = libc::intptr_t; -#[allow(non_camel_case_types)] -pub type objc_property_t = libc::intptr_t; -pub type Protocol = libc::intptr_t; -pub type SEL = libc::intptr_t; +pub type id = *mut runtime::Object; +pub type SEL = runtime::Sel; #[cfg(target_pointer_width = "32")] pub type NSInteger = libc::c_int; @@ -36,278 +29,32 @@ pub type NSInteger = libc::c_long; pub type NSUInteger = libc::c_ulong; #[allow(non_upper_case_globals)] -pub const nil: id = 0; +pub const nil: id = 0 as id; #[allow(non_upper_case_globals)] pub const Nil: Class = 0 as Class; -pub type BOOL = libc::c_schar; -pub const NO: BOOL = 0; -pub const YES: BOOL = 1; - -#[allow(non_camel_case_types, missing_copy_implementations)] -#[repr(C)] -pub struct objc_method_description { - name: SEL, - types: *mut libc::c_char, -} - -#[allow(non_camel_case_types, missing_copy_implementations)] -#[repr(C)] -pub struct objc_property_attribute_t { - name: *const libc::c_char, - value: *const libc::c_char, -} - -#[allow(non_camel_case_types, missing_copy_implementations)] -#[repr(C)] -pub struct objc_super { - receiver: id, - cls: Class, - super_class: Class, -} - -#[link(name = "objc")] -extern { - pub fn class_addProperty(cls: Class, - name: *const libc::c_char, - attributes: *const objc_property_attribute_t, - attributeCount: libc::uint32_t) -> BOOL; - pub fn class_addProtocol(cls: Class, protocol: *mut Protocol) -> BOOL; - pub fn class_addMethod(cls: Class, name: SEL, imp: IMP, types: *const libc::c_char) -> BOOL; - pub fn class_addIvar(cls: Class, - name: *const libc::c_char, - size: libc::size_t, - alignment: libc::uint8_t, - types: *const libc::c_char) -> BOOL; - pub fn class_conformsToProtocol(cls: Class, protocol: *mut Protocol) -> BOOL; - pub fn class_copyIvarList(cls: Class, outCount: *mut libc::uint32_t) -> *mut Ivar; - pub fn class_copyMethodList(cls: Class, outCount: *mut libc::uint32_t) -> *mut Method; - pub fn class_copyPropertyList(cls: Class, - outCount: *mut libc::uint32_t) -> *mut objc_property_t; - pub fn class_copyProtocolList(cls: Class, outCount: *mut libc::uint32_t) -> *mut *mut Protocol; - pub fn class_createInstance(cls: Class, extraBytes: libc::size_t) -> id; - pub fn class_getClassMethod(cls: Class, name: SEL) -> Method; - pub fn class_getFutureClass(name: *const libc::c_char) -> Class; - pub fn class_getIvarLayout(cls: Class) -> *const libc::uint8_t; - pub fn class_getImageName(cls: Class) -> *const libc::c_char; - pub fn class_getInstanceMethod(cls: Class, name: SEL) -> Method; - pub fn class_getInstanceSize(cls: Class) -> libc::size_t; - pub fn class_getInstanceVariable(cls: Class, name: *const libc::c_char) -> Ivar; - pub fn class_getMethodImplementation(cls: Class, name: SEL) -> IMP; - pub fn class_getMethodImplementation_stret(cls: Class, name: SEL) -> IMP; - pub fn class_getName(cls: Class) -> *const libc::c_char; - pub fn class_getProperty(cls: Class, name: *const libc::c_char) -> objc_property_t; - pub fn class_getSuperclass(cls: Class) -> Class; - pub fn class_getVersion(cls: Class) -> libc::int32_t; - pub fn class_getWeakIvarLayout(cls: Class) -> *const libc::uint8_t; - pub fn class_isMetaClass(cls: Class) -> BOOL; - pub fn class_replaceMethod(cls: Class, name: SEL, imp: IMP, types: *const libc::c_char) -> IMP; - pub fn class_replaceProperty(cls: Class, - name: *const libc::c_char, - attributes: *const objc_property_attribute_t, - attributeCount: libc::uint32_t); - pub fn class_respondsToSelector(cls: Class, sel: SEL) -> BOOL; - pub fn class_setFutureClass(cls: Class, name: *const libc::c_char); - pub fn class_setIvarLayout(cls: Class, layout: *const libc::uint8_t); - pub fn class_setSuperclass(cls: Class, newSuper: Class); - pub fn class_setWeakIvarLayout(cls: Class, layout: *const libc::uint8_t); - pub fn class_setVersion(cls: Class, name: libc::int32_t); - pub fn imp_getBlock(imp: IMP) -> id; - pub fn imp_implementationWithBlock(block: id) -> IMP; - pub fn imp_removeBlock(imp: IMP) -> BOOL; - pub fn ivar_getName(ivar: Ivar) -> *const libc::c_char; - pub fn ivar_getOffset(ivar: Ivar) -> libc::ptrdiff_t; - pub fn ivar_getTypeEncoding(ivar: Ivar) -> *const libc::c_char; - pub fn method_copyArgumentType(m: Method, index: libc::uint32_t) -> *mut libc::c_char; - pub fn method_copyReturnType(m: Method) -> *mut libc::c_char; - pub fn method_getArgumentType(m: Method, - index: libc::uint32_t, - dst: *mut libc::c_char, - dst_len: libc::size_t); - pub fn method_getDescription(m: Method) -> *mut objc_method_description; - pub fn method_exchangeImplementations(m1: Method, m2: Method); - pub fn method_getImplementation(m: Method) -> IMP; - pub fn method_getName(m: Method) -> SEL; - pub fn method_getNumberOfArguments(m: Method) -> libc::uint32_t; - pub fn method_getReturnType(m: Method, dst: *mut libc::c_char, dst_len: libc::size_t); - pub fn method_getTypeEncoding(m: Method) -> *const libc::c_char; - pub fn method_invoke(receiver: id, m: Method, ...) -> id; - pub fn method_invoke_stret(receiver: id, m: Method, ...); - pub fn method_setImplementation(m: Method, imp: IMP) -> IMP; - pub fn objc_allocateClassPair(superclass: Class, - name: *const libc::c_char, - extraBytes: libc::size_t) -> Class; - pub fn objc_allocateProtocol(name: *const libc::c_char) -> *mut Protocol; - pub fn objc_constructInstance(cls: Class, bytes: *mut libc::c_void) -> id; - pub fn objc_copyClassList(outCount: *mut libc::uint32_t) -> *mut Class; - pub fn objc_copyClassNamesForImage(image: *const libc::c_char, - outCount: *mut libc::uint32_t) -> *const *const libc::c_char; - pub fn objc_copyImageNames(outCount: *mut libc::uint32_t) -> *const *const libc::c_char; - pub fn objc_copyProtocolList(outCount: *mut libc::uint32_t) -> *mut *mut Protocol; - pub fn objc_destructInstance(obj: id) -> *mut libc::c_void; - pub fn objc_disposeClassPair(cls: Class); - pub fn objc_duplicateClass(original: Class, - name: *const libc::c_char, - extraBytes: libc::size_t) -> Class; - pub fn objc_enumerationMutation(obj: id); - pub fn objc_getAssociatedObject(object: id, key: *const libc::c_void) -> id; - pub fn objc_getClass(name: *const libc::c_char) -> Class; - pub fn objc_getClassList(buffer: *mut Class, bufferCount: libc::int32_t) -> libc::int32_t; - pub fn objc_getMetaClass(name: *const libc::c_char) -> Class; - pub fn objc_getProtocol(name: *const libc::c_char) -> *mut Protocol; - pub fn objc_getRequiredClass(name: *const libc::c_char) -> Class; - pub fn objc_loadWeak(location: *mut id) -> id; - pub fn objc_storeWeak(location: *mut id, obj: id) -> id; - pub fn objc_msgSend(target: id, selector: SEL, ...) -> id; - pub fn objc_msgSend_fpret(target: id, selector: SEL, ...) -> libc::c_double; - pub fn objc_msgSend_stret(target: id, selector: SEL, ...); - pub fn objc_msgSendSuper(sup: *mut objc_super, op: SEL, ...) -> id; - pub fn objc_msgSendSuper_stret(sup: *mut objc_super, op: SEL, ...); - pub fn objc_registerClassPair(cls: Class); - pub fn objc_registerProtocol(proto: *mut Protocol); - pub fn objc_removeAssociatedObjects(object: id); - pub fn objc_setAssociatedObject(object: id, - key: *const libc::c_void, - value: id, - policy: objc_AssociationPolicy); - pub fn objc_setEnumerationMutationHandler(handler: extern fn (id)); - pub fn object_copy(obj: id, size: libc::size_t) -> id; - pub fn object_dispose(obj: id) -> id; - pub fn object_getClass(obj: id) -> Class; - pub fn object_getClassName(obj: id) -> *const libc::c_char; - pub fn object_getIndexedIvars(obj: id) -> *mut libc::c_void; - pub fn object_getInstanceVariable(obj: id, - name: *const libc::c_char, - outValue: *mut *mut libc::c_void); - pub fn object_getIvar(obj: id, ivar: Ivar) -> id; - pub fn object_setClass(obj: id, cls: Class) -> Class; - pub fn object_setInstanceVariable(obj: id, - name: *const libc::c_char, - value: *mut libc::c_void); - pub fn object_setIvar(obj: id, ivar: Ivar, value: id); - pub fn protocol_addMethodDescription(proto: *mut Protocol, - name: SEL, - types: *const libc::c_char, - isRequiredMethod: BOOL, - isInstanceMethod: BOOL); - pub fn protocol_addProperty(proto: *mut Protocol, - name: *const libc::c_char, - attributes: *const objc_property_attribute_t, - attributeCount: libc::uint32_t, - isRequiredMethod: BOOL, - isInstanceMethod: BOOL); - pub fn protocol_addProtocol(proto: *mut Protocol, addition: *mut Protocol); - pub fn protocol_conformsToProtocol(proto: *mut Protocol, other: *mut Protocol) -> BOOL; - pub fn protocol_copyMethodDescriptionList(proto: *mut Protocol, - isRequiredMethod: BOOL, - isInstanceMethod: BOOL, - outCount: *mut libc::uint32_t - ) -> *mut objc_method_description; - pub fn protocol_copyPropertyList(proto: *mut Protocol, - outCount: *mut libc::uint32_t) -> *mut objc_property_t; - pub fn protocol_copyProtocolList(proto: *mut Protocol, - outCount: *mut libc::uint32_t) -> *mut *mut Protocol; - pub fn protocol_getMethodDescription(proto: *mut Protocol, - name: SEL, - isRequiredMethod: BOOL, - isInstanceMethod: BOOL) -> objc_method_description; - pub fn protocol_getProperty(proto: *mut Protocol, - name: *const libc::c_char, - isRequiredMethod: BOOL, - isInstanceMethod: BOOL) -> objc_property_t; - pub fn protocol_getName(proto: *mut Protocol) -> *const libc::c_char; - pub fn protocol_isEqual(proto: *mut Protocol, other: *mut Protocol) -> BOOL; - pub fn property_copyAttributeList(property: objc_property_t, - outCount: *mut libc::uint32_t - ) -> *mut objc_property_attribute_t; - pub fn property_copyAttributeValue(property: objc_property_t, - attributeName: *const libc::c_char) -> *mut libc::c_char; - pub fn property_getAttributes(property: objc_property_t) -> *const libc::c_char; - pub fn property_getName(property: objc_property_t) -> *const libc::c_char; - pub fn sel_getName(sel: SEL) -> *const libc::c_char; - pub fn sel_getUid(string: *const libc::c_char) -> SEL; - pub fn sel_isEqual(lhs: SEL, rhs: SEL) -> BOOL; - pub fn sel_registerName(name: *const libc::c_char) -> SEL; -} - -/// Returns an Objective-C message send function that returns a type `T`. -/// -/// # Example -/// -/// ``` -/// # use cocoa::base::{class, selector, msg_send, nil}; -/// assert!(unsafe { msg_send()(class("NSObject"), selector("class")) } != nil); -/// ``` -pub unsafe fn msg_send() -> extern fn(target: id, selector: SEL, ...) -> T { - mem::transmute(objc_msgSend) -} - -/// Returns an Objective-C message send function that returns a floating-point type. -pub unsafe fn msg_send_fpret() -> extern fn(target: id, selector: SEL, ...) -> T { - mem::transmute(objc_msgSend_fpret) -} - -/// Returns an Objective-C message send function that returns a type `T`, where `T` is a struct -/// with the attribute `#[repr(C)]`. -pub unsafe fn msg_send_stret() -> extern fn(target: id, selector: SEL, ...) -> T { - mem::transmute(objc_msgSend_stret) -} - /// A convenience method to convert the name of a class to the class object itself. #[inline] pub fn class(name: &str) -> Class { - let name_c_str = ffi::CString::new(name).unwrap(); unsafe { - objc_getClass(name_c_str.as_ptr()) + mem::transmute(runtime::Class::get(name)) } } /// A convenience method to convert the name of a selector to the selector object. #[inline] pub fn selector(name: &str) -> SEL { - let name_c_str = ffi::CString::new(name).unwrap(); - unsafe { - sel_registerName(name_c_str.as_ptr()) - } + runtime::Sel::register(name) } #[cfg(test)] mod test { - use libc; - use std::ffi; use super::*; #[test] pub fn test_nsapp() { unsafe { - let _nsApp: id = msg_send()(class("NSApplication"), selector("sharedApplication")); - } - } - - #[test] - pub fn test_custom_obj() { - extern fn MyObject_doSomething(this: id, _: SEL) -> id { - println!("doSomething"); - return this; - } - - let ns_object = class("NSObject"); - let name_c_str = ffi::CString::from_slice("MyObject".as_bytes()); - let my_object = unsafe { - objc_allocateClassPair(ns_object, name_c_str.as_ptr(), 0 as libc::size_t) - }; - - let doSomething = selector("doSomething"); - let types_c_str = ffi::CString::from_slice("@@:".as_bytes()); - unsafe { - let _ = class_addMethod(my_object, doSomething, MyObject_doSomething, - types_c_str.as_ptr()); - - objc_registerClassPair(my_object); - - let mut obj: id = msg_send()(my_object, selector("alloc")); - obj = msg_send()(obj, selector("init")); - let _: () = msg_send()(obj, selector("doSomething")); + let _nsApp: id = msg_send![class("NSApplication"), sharedApplication]; } } } diff --git a/src/lib.rs b/src/lib.rs index d9dad34..6f22b89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,9 @@ #[macro_use] extern crate bitflags; extern crate libc; +#[cfg(target_os="macos")] +#[macro_use] +extern crate objc; #[cfg(target_os="macos")] pub mod appkit; From 0dbaa0502ce38fca43f0f66472adb3be733af458 Mon Sep 17 00:00:00 2001 From: Steven Sheldon Date: Sat, 7 Mar 2015 16:13:41 -0800 Subject: [PATCH 11/76] Removed incorrect casts. --- src/appkit.rs | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 89b6cef..477048d 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -317,7 +317,7 @@ impl NSApplication for id { } unsafe fn activateIgnoringOtherApps_(self, ignore: BOOL) { - msg_send![self, activateIgnoringOtherApps:ignore as libc::c_int] + msg_send![self, activateIgnoringOtherApps:ignore] } unsafe fn run(self) { @@ -336,7 +336,7 @@ impl NSApplication for id { msg_send![self, nextEventMatchingMask:mask untilDate:expiration inMode:in_mode - dequeue:dequeue as libc::c_int] + dequeue:dequeue] } unsafe fn sendEvent_(self, an_event: id) { @@ -344,7 +344,7 @@ impl NSApplication for id { } unsafe fn postEvent_atStart_(self, anEvent: id, flag: BOOL) { - msg_send![self, postEvent:anEvent atStart:flag as libc::c_int] + msg_send![self, postEvent:anEvent atStart:flag] } unsafe fn stop_(self, sender: id) { @@ -644,7 +644,7 @@ impl NSWindow for id { msg_send![self, initWithContentRect:rect styleMask:style backing:backing as NSUInteger - defer:defer as libc::c_int] + defer:defer] } unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self, @@ -656,7 +656,7 @@ impl NSWindow for id { msg_send![self, initWithContentRect:rect styleMask:style backing:backing as NSUInteger - defer:defer as libc::c_int + defer:defer screen:screen] } @@ -715,7 +715,7 @@ impl NSWindow for id { } unsafe fn setCanHide_(self, canHide: BOOL) { - msg_send![self, setCanHide:canHide as libc::c_int] + msg_send![self, setCanHide:canHide] } unsafe fn hidesOnDeactivate(self) -> BOOL { @@ -723,7 +723,7 @@ impl NSWindow for id { } unsafe fn setHidesOnDeactivate_(self, hideOnDeactivate: BOOL) { - msg_send![self, setHidesOnDeactivate:hideOnDeactivate as libc::c_int] + msg_send![self, setHidesOnDeactivate:hideOnDeactivate] } unsafe fn collectionBehavior(self) -> NSWindowCollectionBehavior { @@ -735,7 +735,7 @@ impl NSWindow for id { } unsafe fn setOpaque_(self, opaque: BOOL) { - msg_send![self, setOpaque:opaque as libc::c_int] + msg_send![self, setOpaque:opaque] } unsafe fn hasShadow(self) -> BOOL { @@ -743,7 +743,7 @@ impl NSWindow for id { } unsafe fn setHasShadow_(self, hasShadow: BOOL) { - msg_send![self, setHasShadow:hasShadow as libc::c_int] + msg_send![self, setHasShadow:hasShadow] } unsafe fn invalidateShadow(self) { @@ -758,7 +758,7 @@ impl NSWindow for id { autorecalculateContentBorderThickness: BOOL, edge: NSRectEdge) -> BOOL { msg_send![self, setAutorecalculatesContentBorderThickness: - autorecalculateContentBorderThickness as libc::c_int forEdge:edge] + autorecalculateContentBorderThickness forEdge:edge] } unsafe fn contentBorderThicknessForEdge_(self, edge: NSRectEdge) -> CGFloat { @@ -782,7 +782,7 @@ impl NSWindow for id { } unsafe fn setPreventsApplicationTerminationWhenModal_(self, flag: BOOL) { - msg_send![self, setPreventsApplicationTerminationWhenModal:flag as libc::c_int] + msg_send![self, setPreventsApplicationTerminationWhenModal:flag] } // TODO: Accessing Window Information @@ -848,11 +848,11 @@ impl NSWindow for id { } unsafe fn setFrame_display_(self, windowFrame: NSRect, display: BOOL) { - msg_send![self, setFrame:windowFrame display:display as libc::c_int] + msg_send![self, setFrame:windowFrame display:display] } unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: BOOL) { - msg_send![self, setFrame:windowFrame displayViews:display as libc::c_int] + msg_send![self, setFrame:windowFrame displayViews:display] } unsafe fn aspectRatio(self) -> NSSize { @@ -896,7 +896,7 @@ impl NSWindow for id { } unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: BOOL) { - msg_send![self, setShowsResizeIndicator:showsResizeIndicator as libc::c_int] + msg_send![self, setShowsResizeIndicator:showsResizeIndicator] } unsafe fn resizeIncrements(self) -> NSSize { @@ -912,7 +912,7 @@ impl NSWindow for id { } unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: BOOL) { - msg_send![self, setPreservesContentDuringLiveResize:preservesContentDuringLiveResize as libc::c_int] + msg_send![self, setPreservesContentDuringLiveResize:preservesContentDuringLiveResize] } unsafe fn inLiveResize(self) -> BOOL { @@ -1055,7 +1055,7 @@ impl NSWindow for id { } unsafe fn setIgnoresMouseEvents_(self, ignoreMouseEvents: BOOL) { - msg_send![self, setIgnoresMouseEvents:ignoreMouseEvents as libc::c_int] + msg_send![self, setIgnoresMouseEvents:ignoreMouseEvents] } unsafe fn mouseLocationOutsideOfEventStream(self) -> NSPoint { @@ -1063,7 +1063,7 @@ impl NSWindow for id { } unsafe fn setAcceptsMouseMovedEvents_(self, acceptMouseMovedEvents: BOOL) { - msg_send![self, setAcceptsMouseMovedEvents:acceptMouseMovedEvents as libc::c_int] + msg_send![self, setAcceptsMouseMovedEvents:acceptMouseMovedEvents] } unsafe fn windowNumberAtPoint_belowWindowWithWindowNumber_(self, @@ -1101,7 +1101,7 @@ impl NSWindow for id { // Accessing Edited Status unsafe fn setDocumentEdited_(self, documentEdited: BOOL) { - msg_send![self, setDocumentEdited:documentEdited as libc::c_int] + msg_send![self, setDocumentEdited:documentEdited] } // Managing Titles @@ -1149,17 +1149,17 @@ impl NSWindow for id { } unsafe fn setDisplaysWhenScreenProfileChanges_(self, displaysWhenScreenProfileChanges: BOOL) { - msg_send![self, setDisplaysWhenScreenProfileChanges:displaysWhenScreenProfileChanges as libc::c_int] + msg_send![self, setDisplaysWhenScreenProfileChanges:displaysWhenScreenProfileChanges] } // Moving Windows unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: BOOL) { - msg_send![self, setMovableByWindowBackground:movableByWindowBackground as libc::c_int] + msg_send![self, setMovableByWindowBackground:movableByWindowBackground] } unsafe fn setMovable_(self, movable: BOOL) { - msg_send![self, setMovable:movable as libc::c_int] + msg_send![self, setMovable:movable] } unsafe fn center(self) { @@ -1177,7 +1177,7 @@ impl NSWindow for id { } unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: BOOL) { - msg_send![self, setReleasedWhenClosed:releasedWhenClosed as libc::c_int] + msg_send![self, setReleasedWhenClosed:releasedWhenClosed] } // Minimizing Windows @@ -1285,7 +1285,7 @@ impl NSView for id { } unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: BOOL) { - msg_send![self, setWantsBestResolutionOpenGLSurface:flag as libc::c_int] + msg_send![self, setWantsBestResolutionOpenGLSurface:flag] } unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint { @@ -1862,8 +1862,8 @@ impl NSEvent for id { context:context characters:characters charactersIgnoringModifiers:unmodCharacters - isARepeat:repeatKey as libc::c_int - keyCode:code as libc::c_int] + isARepeat:repeatKey + keyCode:code] } unsafe fn mouseEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_clickCount_pressure_( @@ -1886,7 +1886,7 @@ impl NSEvent for id { context:context eventNumber:eventNumber clickCount:clickCount - pressure:pressure as libc::c_double] + pressure:pressure] } unsafe fn enterExitEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_trackingNumber_userData_( @@ -2037,7 +2037,7 @@ impl NSEvent for id { } unsafe fn setMouseCoalescingEnabled_(_: Self, flag: BOOL) { - msg_send![class("NSEvent"), setMouseCoalescingEnabled:flag as libc::c_int] + msg_send![class("NSEvent"), setMouseCoalescingEnabled:flag] } unsafe fn isMouseCoalescingEnabled(_: Self) -> BOOL { From 89f0929acff02bbd0da38d2dbe51ab9bbf3bcf6b Mon Sep 17 00:00:00 2001 From: Steven Sheldon Date: Thu, 26 Mar 2015 22:18:45 -0700 Subject: [PATCH 12/76] Split a foundation mod from appkit. --- examples/hello_world.rs | 8 +- src/appkit.rs | 148 +----------------------------------- src/base.rs | 11 --- src/foundation.rs | 163 ++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 2 + 5 files changed, 172 insertions(+), 160 deletions(-) create mode 100644 src/foundation.rs diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 2ff9436..3af32d6 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,11 +1,11 @@ extern crate cocoa; -use cocoa::base::{NSUInteger, selector, nil, YES, NO}; -use cocoa::appkit::{NSApp, NSRect, NSPoint, NSSize, - NSAutoreleasePool, NSProcessInfo, +use cocoa::base::{selector, nil, YES, NO}; +use cocoa::foundation::{NSUInteger, NSRect, NSPoint, NSSize, + NSAutoreleasePool, NSProcessInfo, NSString}; +use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, NSTitledWindowMask, NSBackingStoreBuffered, - NSString, NSMenu, NSMenuItem}; fn main() { diff --git a/src/appkit.rs b/src/appkit.rs index 477048d..15d6f63 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -9,8 +9,9 @@ #![allow(non_upper_case_globals)] -use base::{id, class}; -use base::{BOOL, SEL, NSInteger, NSUInteger}; +use base::{id, class, BOOL, SEL}; +use foundation::{NSInteger, NSUInteger, NSTimeInterval, + NSPoint, NSSize, NSRect, NSRectEdge}; use libc; pub use self::NSApplicationActivationPolicy::*; @@ -20,8 +21,6 @@ pub use self::NSOpenGLPixelFormatAttribute::*; pub use self::NSOpenGLPFAOpenGLProfiles::*; pub use self::NSEventType::*; -use std::ffi::CString; - #[cfg(target_pointer_width = "32")] pub type CGFloat = f32; #[cfg(target_pointer_width = "64")] @@ -37,71 +36,9 @@ pub struct CGPoint { pub y: CGFloat, } -#[repr(C)] -pub struct NSPoint { - pub x: f64, - pub y: f64, -} - -impl NSPoint { - #[inline] - pub fn new(x: f64, y: f64) -> NSPoint { - NSPoint { - x: x, - y: y, - } - } -} - -#[repr(C)] -pub struct NSSize { - pub width: f64, - pub height: f64, -} - -impl NSSize { - #[inline] - pub fn new(width: f64, height: f64) -> NSSize { - NSSize { - width: width, - height: height, - } - } -} - -#[repr(C)] -pub struct NSRect { - pub origin: NSPoint, - pub size: NSSize, -} - -impl NSRect { - #[inline] - pub fn new(origin: NSPoint, size: NSSize) -> NSRect { - NSRect { - origin: origin, - size: size - } - } -} - -// Same as CGRectEdge -#[repr(u32)] -pub enum NSRectEdge { - NSRectMinXEdge, - NSRectMinYEdge, - NSRectMaxXEdge, - NSRectMaxYEdge, -} - #[link(name = "AppKit", kind = "framework")] extern {} -#[link(name = "Foundation", kind = "framework")] -extern { - pub static NSDefaultRunLoopMode: id; -} - pub unsafe fn NSApp() -> id { msg_send![class("NSApplication"), sharedApplication] } @@ -252,41 +189,6 @@ pub enum NSOpenGLContextParameter { pub static NSMainMenuWindowLevel: libc::int32_t = 24; -pub trait NSAutoreleasePool { - unsafe fn new(_: Self) -> id { - msg_send![class("NSAutoreleasePool"), new] - } - - unsafe fn autorelease(self) -> Self; - unsafe fn drain(self); -} - -impl NSAutoreleasePool for id { - unsafe fn autorelease(self) -> id { - msg_send![self, autorelease] - } - - unsafe fn drain(self) { - msg_send![self, drain] - } -} - -pub trait NSProcessInfo { - unsafe fn processInfo(_: Self) -> id { - msg_send![class("NSProcessInfo"), processInfo] - } - - unsafe fn processName(self) -> id; -} - -impl NSProcessInfo for id { - unsafe fn processName(self) -> id { - msg_send![self, processName] - } -} - -pub type NSTimeInterval = libc::c_double; - pub trait NSApplication { unsafe fn sharedApplication(_: Self) -> id { msg_send![class("NSApplication"), sharedApplication] @@ -1219,36 +1121,6 @@ impl NSWindow for id { // TODO: Constraint-Based Layouts } -pub trait NSString { - unsafe fn alloc(_: Self) -> id { - msg_send![class("NSString"), alloc] - } - - unsafe fn initWithUTF8String_(self, c_string: *const i8) -> id; - unsafe fn stringByAppendingString_(self, other: id) -> id; - unsafe fn init_str(self, string: &str) -> Self; - unsafe fn UTF8String(self) -> *const libc::c_char; -} - -impl NSString for id { - unsafe fn initWithUTF8String_(self, c_string: *const i8) -> id { - msg_send![self, initWithUTF8String:c_string as id] - } - - unsafe fn stringByAppendingString_(self, other: id) -> id { - msg_send![self, stringByAppendingString:other] - } - - unsafe fn init_str(self, string: &str) -> id { - let cstring = CString::new(string).unwrap(); - self.initWithUTF8String_(cstring.as_ptr()) - } - - unsafe fn UTF8String(self) -> *const libc::c_char { - msg_send![self, UTF8String] - } -} - pub trait NSView { unsafe fn alloc(_: Self) -> id { msg_send![class("NSView"), alloc] @@ -1447,20 +1319,6 @@ impl NSOpenGLContext for id { } } -pub trait NSDate { - unsafe fn distantPast(_: Self) -> id { - msg_send![class("NSDate"), distantPast] - } - - unsafe fn distantFuture(_: Self) -> id { - msg_send![class("NSDate"), distantFuture] - } -} - -impl NSDate for id { - -} - bitflags! { flags NSEventSwipeTrackingOptions: NSUInteger { const NSEventSwipeTrackingLockDirection = 0x1 << 0, diff --git a/src/base.rs b/src/base.rs index 11737dc..f8546be 100644 --- a/src/base.rs +++ b/src/base.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use libc; use objc::runtime; use std::mem; @@ -18,16 +17,6 @@ pub type Class = *mut runtime::Class; pub type id = *mut runtime::Object; pub type SEL = runtime::Sel; -#[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; - #[allow(non_upper_case_globals)] pub const nil: id = 0 as id; #[allow(non_upper_case_globals)] diff --git a/src/foundation.rs b/src/foundation.rs new file mode 100644 index 0000000..babc187 --- /dev/null +++ b/src/foundation.rs @@ -0,0 +1,163 @@ +// Copyright 2013 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use base::{id, class}; +use libc; +use std::ffi::CString; + +#[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; + +#[repr(C)] +pub struct NSPoint { + pub x: f64, + pub y: f64, +} + +impl NSPoint { + #[inline] + pub fn new(x: f64, y: f64) -> NSPoint { + NSPoint { + x: x, + y: y, + } + } +} + +#[repr(C)] +pub struct NSSize { + pub width: f64, + pub height: f64, +} + +impl NSSize { + #[inline] + pub fn new(width: f64, height: f64) -> NSSize { + NSSize { + width: width, + height: height, + } + } +} + +#[repr(C)] +pub struct NSRect { + pub origin: NSPoint, + pub size: NSSize, +} + +impl NSRect { + #[inline] + pub fn new(origin: NSPoint, size: NSSize) -> NSRect { + NSRect { + origin: origin, + size: size + } + } +} + +// Same as CGRectEdge +#[repr(u32)] +pub enum NSRectEdge { + NSRectMinXEdge, + NSRectMinYEdge, + NSRectMaxXEdge, + NSRectMaxYEdge, +} + +#[link(name = "Foundation", kind = "framework")] +extern { + pub static NSDefaultRunLoopMode: id; +} + +pub trait NSAutoreleasePool { + unsafe fn new(_: Self) -> id { + msg_send![class("NSAutoreleasePool"), new] + } + + unsafe fn autorelease(self) -> Self; + unsafe fn drain(self); +} + +impl NSAutoreleasePool for id { + unsafe fn autorelease(self) -> id { + msg_send![self, autorelease] + } + + unsafe fn drain(self) { + msg_send![self, drain] + } +} + +pub trait NSProcessInfo { + unsafe fn processInfo(_: Self) -> id { + msg_send![class("NSProcessInfo"), processInfo] + } + + unsafe fn processName(self) -> id; +} + +impl NSProcessInfo for id { + unsafe fn processName(self) -> id { + msg_send![self, processName] + } +} + +pub type NSTimeInterval = libc::c_double; + +pub trait NSString { + unsafe fn alloc(_: Self) -> id { + msg_send![class("NSString"), alloc] + } + + unsafe fn initWithUTF8String_(self, c_string: *const i8) -> id; + unsafe fn stringByAppendingString_(self, other: id) -> id; + unsafe fn init_str(self, string: &str) -> Self; + unsafe fn UTF8String(self) -> *const libc::c_char; +} + +impl NSString for id { + unsafe fn initWithUTF8String_(self, c_string: *const i8) -> id { + msg_send![self, initWithUTF8String:c_string as id] + } + + unsafe fn stringByAppendingString_(self, other: id) -> id { + msg_send![self, stringByAppendingString:other] + } + + unsafe fn init_str(self, string: &str) -> id { + let cstring = CString::new(string).unwrap(); + self.initWithUTF8String_(cstring.as_ptr()) + } + + unsafe fn UTF8String(self) -> *const libc::c_char { + msg_send![self, UTF8String] + } +} + +pub trait NSDate { + unsafe fn distantPast(_: Self) -> id { + msg_send![class("NSDate"), distantPast] + } + + unsafe fn distantFuture(_: Self) -> id { + msg_send![class("NSDate"), distantFuture] + } +} + +impl NSDate for id { + +} diff --git a/src/lib.rs b/src/lib.rs index 6f22b89..79a6377 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,3 +24,5 @@ extern crate objc; pub mod appkit; #[cfg(target_os="macos")] pub mod base; +#[cfg(target_os="macos")] +pub mod foundation; From a67cc837b55bb79037c1f7f54fe9330af5695d32 Mon Sep 17 00:00:00 2001 From: Steven Sheldon Date: Sat, 28 Mar 2015 13:31:16 -0700 Subject: [PATCH 13/76] Remove unused std_misc feature. --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 79a6377..33aac8b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,8 +10,7 @@ #![crate_name = "cocoa"] #![crate_type = "rlib"] -#![allow(missing_copy_implementations, non_snake_case)] -#![feature(std_misc)] +#![allow(non_snake_case)] #[macro_use] extern crate bitflags; From 8f7351571f439a352c1600b2d415d8a4b3b6f1a5 Mon Sep 17 00:00:00 2001 From: Steven Sheldon Date: Thu, 2 Apr 2015 08:59:57 -0700 Subject: [PATCH 14/76] Fixed overflow in NSTouchPhase definition. --- src/appkit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appkit.rs b/src/appkit.rs index 15d6f63..8cdd2d9 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1355,7 +1355,7 @@ bitflags! { const NSTouchPhaseTouching = NSTouchPhaseBegan.bits | NSTouchPhaseMoved.bits | NSTouchPhaseStationary.bits, - const NSTouchPhaseAny = 0 - 1, // NSUIntegerMax + const NSTouchPhaseAny = !0, // NSUIntegerMax } } From b78a1b828cad2feeda71e46f9bd53706f4ccc671 Mon Sep 17 00:00:00 2001 From: Felix Kaaman Date: Thu, 30 Apr 2015 10:40:11 +0200 Subject: [PATCH 15/76] Add remaining functions to NSOpenGLPixelFormat --- src/appkit.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 8cdd2d9..ed0ca51 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1199,13 +1199,33 @@ pub trait NSOpenGLPixelFormat { msg_send![class("NSOpenGLPixelFormat"), alloc] } + // Creating an NSOpenGLPixelFormat Object + unsafe fn initWithAttributes_(self, attributes: &[u32]) -> id; + + // Managing the Pixel Format + + unsafe fn getValues_forAttribute_forVirtualScreen_(self, val: *mut GLint, attrib: NSOpenGLPixelFormatAttribute, screen: GLint); + unsafe fn numberOfVirtualScreens(self) -> GLint; + } impl NSOpenGLPixelFormat for id { + // Creating an NSOpenGLPixelFormat Object + unsafe fn initWithAttributes_(self, attributes: &[u32]) -> id { msg_send![self, initWithAttributes:attributes] } + + // 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] + } + + unsafe fn numberOfVirtualScreens(self) -> GLint { + msg_send![self, numberOfVirtualScreens] + } } pub trait NSOpenGLContext { From 27a09caba9a3e934aa57ea4d13156df94530c959 Mon Sep 17 00:00:00 2001 From: Felix Kaaman Date: Sun, 24 May 2015 15:09:17 +0200 Subject: [PATCH 16/76] Add `NSAppKitVersionNumber` --- src/appkit.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/appkit.rs b/src/appkit.rs index ed0ca51..135fae5 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -37,7 +37,35 @@ pub struct CGPoint { } #[link(name = "AppKit", kind = "framework")] -extern {} +extern { + pub static NSAppKitVersionNumber: f64; +} + +pub const NSAppKitVersionNumber10_0: f64 = 577.0; +pub const NSAppKitVersionNumber10_1: f64 = 620.0; +pub const NSAppKitVersionNumber10_2: f64 = 663.0; +pub const NSAppKitVersionNumber10_2_3: f64 = 663.6; +pub const NSAppKitVersionNumber10_3: f64 = 743.0; +pub const NSAppKitVersionNumber10_3_2: f64 = 743.14; +pub const NSAppKitVersionNumber10_3_3: f64 = 743.2; +pub const NSAppKitVersionNumber10_3_5: f64 = 743.24; +pub const NSAppKitVersionNumber10_3_7: f64 = 743.33; +pub const NSAppKitVersionNumber10_3_9: f64 = 743.36; +pub const NSAppKitVersionNumber10_4: f64 = 824.0; +pub const NSAppKitVersionNumber10_4_1: f64 = 824.1; +pub const NSAppKitVersionNumber10_4_3: f64 = 824.23; +pub const NSAppKitVersionNumber10_4_4: f64 = 824.33; +pub const NSAppKitVersionNumber10_4_7: f64 = 824.41; +pub const NSAppKitVersionNumber10_5: f64 = 949.0; +pub const NSAppKitVersionNumber10_5_2: f64 = 949.27; +pub const NSAppKitVersionNumber10_5_3: f64 = 949.33; +pub const NSAppKitVersionNumber10_6: f64 = 1038.0; +pub const NSAppKitVersionNumber10_7: f64 = 1138.0; +pub const NSAppKitVersionNumber10_7_2: f64 = 1138.23; +pub const NSAppKitVersionNumber10_7_3: f64 = 1138.32; +pub const NSAppKitVersionNumber10_7_4: f64 = 1138.47; +pub const NSAppKitVersionNumber10_8: f64 = 1187.0; +pub const NSAppKitVersionNumber10_9: f64 = 1265.0; pub unsafe fn NSApp() -> id { msg_send![class("NSApplication"), sharedApplication] From f85d87826e15f29a3f60110d4fcb9d6c4a105277 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Wed, 3 Jun 2015 10:49:18 -0600 Subject: [PATCH 17/76] Minor cleanups. --- configure | 4 ---- src/lib.rs | 4 ---- 2 files changed, 8 deletions(-) delete mode 100755 configure diff --git a/configure b/configure deleted file mode 100755 index 62a0f4c..0000000 --- a/configure +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -SRCDIR="$(cd $(dirname $0) && pwd)" -sed "s#%VPATH%#${SRCDIR}#" ${SRCDIR}/Makefile.in > Makefile diff --git a/src/lib.rs b/src/lib.rs index 33aac8b..426a41a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,13 +15,9 @@ #[macro_use] extern crate bitflags; extern crate libc; -#[cfg(target_os="macos")] #[macro_use] extern crate objc; -#[cfg(target_os="macos")] pub mod appkit; -#[cfg(target_os="macos")] pub mod base; -#[cfg(target_os="macos")] pub mod foundation; From dbb91b9e50efdd64b4fa654dd1302d92ac898568 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Wed, 3 Jun 2015 11:59:01 -0600 Subject: [PATCH 18/76] Added more metadata for crates.io publish. --- Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 31d279c..3d8b835 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,11 @@ [package] name = "cocoa" +description = "Bindings to Cocoa for OS X" +homepage = "https://github.com/servo/rust-cocoa" +repository = "https://github.com/servo/rust-cocoa" version = "0.1.1" authors = ["The Servo Project Developers"] -license = "MIT" +license = "MIT / Apache 2.0" [lib] name = "cocoa" From e55a8b7fe46f488587b2fbbcc897ac5ae39e0276 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Wed, 3 Jun 2015 14:44:49 -0600 Subject: [PATCH 19/76] Use correct shorthand for apache license since Cargo checks this. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3d8b835..4fa557d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ homepage = "https://github.com/servo/rust-cocoa" repository = "https://github.com/servo/rust-cocoa" version = "0.1.1" authors = ["The Servo Project Developers"] -license = "MIT / Apache 2.0" +license = "MIT / Apache-2.0" [lib] name = "cocoa" From 8f278a74efc4b14901636524e3e0ba0fa893d176 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Wed, 3 Jun 2015 21:43:09 -0600 Subject: [PATCH 20/76] Bring repo and package naming in line with Rust conventions. --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4fa557d..3bc874a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "cocoa" description = "Bindings to Cocoa for OS X" -homepage = "https://github.com/servo/rust-cocoa" -repository = "https://github.com/servo/rust-cocoa" -version = "0.1.1" +homepage = "https://github.com/servo/cocoa-rs" +repository = "https://github.com/servo/cocoa-rs" +version = "0.1.2" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From 297a2bf7491a73b4a3762a77d28f3b2432a084aa Mon Sep 17 00:00:00 2001 From: Steven Sheldon Date: Sat, 6 Jun 2015 01:12:05 -0700 Subject: [PATCH 21/76] Add core-graphics dependency. --- Cargo.toml | 1 + src/appkit.rs | 14 +++----------- src/lib.rs | 1 + 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3bc874a..3e1cd44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,5 @@ crate-type = ["rlib"] [dependencies] bitflags = "0.1" libc = "*" +core-graphics = "*" objc = "0.1" diff --git a/src/appkit.rs b/src/appkit.rs index 135fae5..3f13bd1 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -14,6 +14,9 @@ use foundation::{NSInteger, NSUInteger, NSTimeInterval, NSPoint, NSSize, NSRect, NSRectEdge}; use libc; +pub use core_graphics::base::CGFloat; +pub use core_graphics::geometry::CGPoint; + pub use self::NSApplicationActivationPolicy::*; pub use self::NSWindowMask::*; pub use self::NSBackingStoreType::*; @@ -21,21 +24,10 @@ pub use self::NSOpenGLPixelFormatAttribute::*; pub use self::NSOpenGLPFAOpenGLProfiles::*; pub use self::NSEventType::*; -#[cfg(target_pointer_width = "32")] -pub type CGFloat = f32; -#[cfg(target_pointer_width = "64")] -pub type CGFloat = f64; - pub type CGLContextObj = *mut libc::c_void; pub type GLint = libc::int32_t; -#[repr(C)] -pub struct CGPoint { - pub x: CGFloat, - pub y: CGFloat, -} - #[link(name = "AppKit", kind = "framework")] extern { pub static NSAppKitVersionNumber: f64; diff --git a/src/lib.rs b/src/lib.rs index 426a41a..5c3e062 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ #[macro_use] extern crate bitflags; extern crate libc; +extern crate core_graphics; #[macro_use] extern crate objc; From d9d30643acd91c86a9ec3dbc57c0246e3ceb88d3 Mon Sep 17 00:00:00 2001 From: Felix Kaaman Date: Mon, 29 Jun 2015 09:23:48 +0200 Subject: [PATCH 22/76] Add various methods related to menubars --- src/appkit.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 3f13bd1..7ce0b6f 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -216,6 +216,7 @@ pub trait NSApplication { unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL; unsafe fn setMainMenu_(self, menu: id); + unsafe fn setServicesMenu_(self, menu: id); unsafe fn activateIgnoringOtherApps_(self, ignore: BOOL); unsafe fn run(self); unsafe fn finishLaunching(self); @@ -238,6 +239,10 @@ impl NSApplication for id { msg_send![self, setMainMenu:menu] } + unsafe fn setServicesMenu_(self, menu: id) { + msg_send![self, setServicesMenu:menu] + } + unsafe fn activateIgnoringOtherApps_(self, ignore: BOOL) { msg_send![self, activateIgnoringOtherApps:ignore] } @@ -279,13 +284,24 @@ pub trait NSMenu { msg_send![class("NSMenu"), new] } + 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; } impl NSMenu for id { + unsafe fn setAutoenablesItems(self, state: BOOL) { + msg_send![self, setAutoenablesItems: state] + } + unsafe fn addItem_(self, menu_item: id) { msg_send![self, addItem:menu_item] } + + unsafe fn addItemWithTitle_action_keyEquivalent(self, title: id, action: SEL, key: id) -> id { + msg_send![self, addItemWithTitle:title action:action keyEquivalent:key] + } } pub trait NSMenuItem { @@ -297,7 +313,12 @@ pub trait NSMenuItem { msg_send![class("NSMenuItem"), new] } + unsafe fn separatorItem(_: Self) -> id { + msg_send![class("NSMenuItem"), separatorItem] + } + unsafe fn initWithTitle_action_keyEquivalent_(self, title: id, action: SEL, key: id) -> id; + unsafe fn setKeyEquivalentModifierMask_(self, mask: NSEventModifierFlags); unsafe fn setSubmenu_(self, submenu: id); } @@ -306,6 +327,10 @@ impl NSMenuItem for id { msg_send![self, initWithTitle:title action:action keyEquivalent:key] } + unsafe fn setKeyEquivalentModifierMask_(self, mask: NSEventModifierFlags) { + msg_send![self, setKeyEquivalentModifierMask:mask] + } + unsafe fn setSubmenu_(self, submenu: id) { msg_send![self, setSubmenu:submenu] } From c927576e8ba803be78be3c60f9abfcc57b0c86c2 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sun, 5 Jul 2015 22:32:19 +0200 Subject: [PATCH 23/76] Unpin the bitflags dependency. It causes Servo to depend on two versions of the bitflags crate (0.1 and 0.2). --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3e1cd44..35a02eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ name = "cocoa" crate-type = ["rlib"] [dependencies] -bitflags = "0.1" +bitflags = "*" libc = "*" core-graphics = "*" objc = "0.1" From af7b70751d812386c92b25f079b8904addd26963 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 10 Mar 2015 21:25:03 +0530 Subject: [PATCH 24/76] Travisify --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3800523 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +os: osx + +language: rust +sudo: false + +branches: + except: + - master + +notifications: + webhooks: http://build.servo.org:54856/travis From aff6c3d5db40af6de6b154cc34b0437fad89cc68 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Fri, 24 Jul 2015 14:14:58 -0700 Subject: [PATCH 25/76] Bump version to 0.1.3 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 35a02eb..9c65bcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.1.2" +version = "0.1.3" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From fd19702e84b22d697dc1cfb0fd49138ff4e14034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20G=C3=A9nier?= Date: Sat, 12 Sep 2015 13:10:01 -0400 Subject: [PATCH 26/76] Add responder management to NSWindow. --- src/appkit.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 3f13bd1..d60a2a1 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -478,7 +478,13 @@ pub trait NSWindow { // TODO: Managing Title Bars // TODO: Managing Tooltips // TODO: Handling Events - // TODO: Managing Responders + + // Managing Responders + unsafe fn initialFirstResponder(self) -> id; + unsafe fn firstResponder(self) -> id; + unsafe fn setInitialFirstResponder_(self, responder: id); + unsafe fn makeFirstResponder_(self, responder: id) -> BOOL; + // TODO: Managing the Key View Loop // Handling Keyboard Events @@ -957,7 +963,25 @@ impl NSWindow for id { // TODO: Managing Title Bars // TODO: Managing Tooltips // TODO: Handling Events - // TODO: Managing Responders + + // Managing Responders + + unsafe fn initialFirstResponder(self) -> id { + msg_send![self, initialFirstResponder] + } + + unsafe fn firstResponder(self) -> id { + msg_send![self, firstResponder] + } + + unsafe fn setInitialFirstResponder_(self, responder: id) { + msg_send![self, setInitialFirstResponder:responder] + } + + unsafe fn makeFirstResponder_(self, responder: id) -> BOOL { + msg_send![self, makeFirstResponder:responder] + } + // TODO: Managing the Key View Loop // Handling Keyboard Events From 06d64a18c84d934c007e4642205d3c4292578512 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Mon, 21 Sep 2015 11:28:11 +0200 Subject: [PATCH 27/76] Add support for titleVisibility and titlebarAppearsTransparent --- src/appkit.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/appkit.rs b/src/appkit.rs index 3f13bd1..919caa8 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -88,7 +88,15 @@ pub enum NSWindowMask { NSUnifiedTitleAndToolbarWindowMask = 1 << 12, - NSFullScreenWindowMask = 1 << 14 + NSFullScreenWindowMask = 1 << 14, + + NSFullSizeContentViewWindowMask = 1 << 15 +} + +#[repr(u64)] +pub enum NSWindowTitleVisibility { + NSWindowTitleVisible = 0, + NSWindowTitleHidden = 1 } #[repr(u64)] @@ -516,6 +524,8 @@ pub trait NSWindow { 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 representedFilename(self) -> id; unsafe fn setRepresentedFilename_(self, filePath: id); unsafe fn representedURL(self) -> id; @@ -1040,6 +1050,14 @@ impl NSWindow for id { msg_send![self, setTitleWithRepresentedFilename:filePath] } + unsafe fn setTitleVisibility_(self, visibility: NSWindowTitleVisibility) { + msg_send![self, setTitleVisibility:visibility] + } + + unsafe fn setTitlebarAppearsTransparent_(self, transparent: BOOL) { + msg_send![self, setTitlebarAppearsTransparent:transparent] + } + unsafe fn representedFilename(self) -> id { msg_send![self, representedFilename] } From 99cf2944cb08237c79acbd9e03e62751e075438b Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Tue, 22 Sep 2015 09:27:53 +0200 Subject: [PATCH 28/76] add addSubview method --- src/appkit.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 919caa8..b3acf76 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1171,6 +1171,7 @@ pub trait NSView { unsafe fn display_(self); unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: BOOL); unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint; + unsafe fn addSubview_(self, view: id); } impl NSView for id { @@ -1201,6 +1202,11 @@ impl NSView for id { unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint { msg_send![self, convertPoint:point fromView:view] } + + unsafe fn addSubview_(self, view: id) { + msg_send![self, addSubview:view] + } + } pub trait NSOpenGLView { From a22b035d91b5a994be4394c0325582e510afeba6 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Tue, 22 Sep 2015 17:25:21 +0200 Subject: [PATCH 29/76] Bump version to 0.1.4 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 9c65bcd..7d19ade 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.1.3" +version = "0.1.4" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From b82bcbe5c50b17d08a6d57a7198a0aa4fa65788e Mon Sep 17 00:00:00 2001 From: "Rob.Gowin" Date: Tue, 22 Sep 2015 22:34:31 -0500 Subject: [PATCH 30/76] Added NSRunningApplication and two associated functions. Added ability to call [[NSRunningApplication currentApplication] activateWithOptions: NSApplicationActivateIgnoringOtherApps] which is used in the example to fix the missing menu bar when the example app starts. --- src/appkit.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index b7afaf6..b4cf9a0 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -18,6 +18,7 @@ pub use core_graphics::base::CGFloat; pub use core_graphics::geometry::CGPoint; pub use self::NSApplicationActivationPolicy::*; +pub use self::NSApplicationActivationOptions::*; pub use self::NSWindowMask::*; pub use self::NSBackingStoreType::*; pub use self::NSOpenGLPixelFormatAttribute::*; @@ -69,6 +70,12 @@ pub enum NSApplicationActivationPolicy { NSApplicationActivationPolicyERROR = -1 } +#[repr(u64)] +pub enum NSApplicationActivationOptions { + NSApplicationActivateAllWindows = 1 << 0, + NSApplicationActivateIgnoringOtherApps = 1 << 1 +} + #[repr(u64)] pub enum NSApplicationTerminateReply { NSTerminateCancel = 0, @@ -287,6 +294,19 @@ impl NSApplication for id { } } +pub trait NSRunningApplication { + unsafe fn currentApplication(_: Self) -> id { + msg_send![class("NSRunningApplication"), currentApplication] + } + unsafe fn activateWithOptions_(self, options: NSApplicationActivationOptions) -> BOOL; +} + +impl NSRunningApplication for id { + unsafe fn activateWithOptions_(self, options: NSApplicationActivationOptions) -> BOOL { + msg_send![self, activateWithOptions:options as NSUInteger] + } +} + pub trait NSMenu { unsafe fn new(_: Self) -> id { msg_send![class("NSMenu"), new] From d56b150d2d5fafba71055880cd50cd7e84180248 Mon Sep 17 00:00:00 2001 From: "Rob.Gowin" Date: Tue, 22 Sep 2015 22:35:20 -0500 Subject: [PATCH 31/76] Activate the example app via NSRunningApplication This fixes #98, at least on my Yosemite machine. --- examples/hello_world.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 3af32d6..6c6124e 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,12 +1,13 @@ extern crate cocoa; -use cocoa::base::{selector, nil, YES, NO}; +use cocoa::base::{selector, nil, /*YES, */ NO}; use cocoa::foundation::{NSUInteger, NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSString}; use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, NSTitledWindowMask, NSBackingStoreBuffered, - NSMenu, NSMenuItem}; + NSMenu, NSMenuItem, NSRunningApplication, + NSApplicationActivateIgnoringOtherApps}; fn main() { unsafe { @@ -49,8 +50,8 @@ fn main() { let title = NSString::alloc(nil).init_str("Hello World!"); window.setTitle_(title); window.makeKeyAndOrderFront_(nil); - - app.activateIgnoringOtherApps_(YES); + let current_app = NSRunningApplication::currentApplication(nil); + current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); app.run(); } } From d694e3b80105f48bd715e0770ceaee983bf66ae2 Mon Sep 17 00:00:00 2001 From: Rob Gowin Date: Wed, 23 Sep 2015 07:05:29 -0500 Subject: [PATCH 32/76] Delete no longer used value --- examples/hello_world.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 6c6124e..831e43f 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,6 +1,6 @@ extern crate cocoa; -use cocoa::base::{selector, nil, /*YES, */ NO}; +use cocoa::base::{selector, nil, NO}; use cocoa::foundation::{NSUInteger, NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSString}; use cocoa::appkit::{NSApp, From bd8a1dc64b9a7e785244902d7f700e7a9ddfd871 Mon Sep 17 00:00:00 2001 From: Jonathan Anderson Date: Wed, 23 Sep 2015 12:13:42 -0230 Subject: [PATCH 33/76] Bump version number Expose recent `NSRunningApplication` changes to Cargo. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7d19ade..db3f924 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.1.4" +version = "0.1.5" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From e8d5c36740de27f83a01b41c896cbb8bf2d8ff45 Mon Sep 17 00:00:00 2001 From: Mathieu Rheaume Date: Mon, 28 Sep 2015 02:42:22 -0400 Subject: [PATCH 34/76] Implement NSString Len + init_str use initWithBytes:length:encoding --- src/foundation.rs | 19 +++++++++------ tests/foundation.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 tests/foundation.rs diff --git a/src/foundation.rs b/src/foundation.rs index babc187..1840f26 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -9,7 +9,6 @@ use base::{id, class}; use libc; -use std::ffi::CString; #[cfg(target_pointer_width = "32")] pub type NSInteger = libc::c_int; @@ -21,6 +20,8 @@ pub type NSInteger = libc::c_long; #[cfg(target_pointer_width = "64")] pub type NSUInteger = libc::c_ulong; +const UTF8_ENCODING: usize = 4; + #[repr(C)] pub struct NSPoint { pub x: f64, @@ -123,24 +124,26 @@ pub trait NSString { msg_send![class("NSString"), alloc] } - unsafe fn initWithUTF8String_(self, c_string: *const i8) -> id; unsafe fn stringByAppendingString_(self, other: id) -> id; unsafe fn init_str(self, string: &str) -> Self; unsafe fn UTF8String(self) -> *const libc::c_char; + unsafe fn len(self) -> usize; } impl NSString for id { - unsafe fn initWithUTF8String_(self, c_string: *const i8) -> id { - msg_send![self, initWithUTF8String:c_string as id] - } - unsafe fn stringByAppendingString_(self, other: id) -> id { msg_send![self, stringByAppendingString:other] } unsafe fn init_str(self, string: &str) -> id { - let cstring = CString::new(string).unwrap(); - self.initWithUTF8String_(cstring.as_ptr()) + return msg_send![self, + initWithBytes:string.as_ptr() + length:string.len() + encoding:UTF8_ENCODING as id]; + } + + unsafe fn len(self) -> usize { + msg_send![self, lengthOfBytesUsingEncoding:UTF8_ENCODING] } unsafe fn UTF8String(self) -> *const libc::c_char { diff --git a/tests/foundation.rs b/tests/foundation.rs new file mode 100644 index 0000000..c4f9130 --- /dev/null +++ b/tests/foundation.rs @@ -0,0 +1,59 @@ +extern crate cocoa; + +#[cfg(test)] +mod foundation { + mod nsstring { + use cocoa::foundation::{NSString}; + use cocoa::base::{nil}; + use std::slice; + use std::str; + + #[test] + fn test_utf8() { + let expected = "Iñtërnâtiônàlizætiøn"; + unsafe { + let built = NSString::alloc(nil).init_str(expected); + let bytes = built.UTF8String() as *const u8; + let objc_string = str::from_utf8(slice::from_raw_parts(bytes, built.len())).unwrap(); + assert!(objc_string.len() == expected.len()); + assert!(objc_string == expected); + } + } + + #[test] + fn test_string() { + let expected = "Hello World!"; + unsafe { + let built = NSString::alloc(nil).init_str(expected); + let bytes = built.UTF8String() as *const u8; + let objc_string = str::from_utf8(slice::from_raw_parts(bytes, built.len())).unwrap(); + assert!(objc_string.len() == expected.len()); + assert!(objc_string == expected); + } + } + + #[test] + fn test_length() { + let expected = "Hello!"; + unsafe { + let built = NSString::alloc(nil).init_str(expected); + assert!(built.len() == expected.len()); + } + } + + #[test] + fn test_append_by_appending_string() { + let initial_str = "Iñtërnâtiônàlizætiøn"; + let to_append = "_more_strings"; + let expected = concat!("Iñtërnâtiônàlizætiøn", "_more_strings"); + unsafe { + let built = NSString::alloc(nil).init_str(initial_str); + let built_to_append = NSString::alloc(nil).init_str(to_append); + let append_string = built.stringByAppendingString_(built_to_append); + let bytes = append_string.UTF8String() as *const u8; + let objc_string = str::from_utf8(slice::from_raw_parts(bytes, append_string.len())).unwrap(); + assert!(objc_string == expected); + } + } + } +} From cb2842a171c3123fcae67ba90ea33fbc2536afa4 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 3 Nov 2015 15:09:37 -0800 Subject: [PATCH 35/76] Upgrade to libc 0.2 --- Cargo.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index db3f924..d6e7f11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.1.5" +version = "0.2.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -12,7 +12,7 @@ name = "cocoa" crate-type = ["rlib"] [dependencies] -bitflags = "*" -libc = "*" -core-graphics = "*" -objc = "0.1" +bitflags = "0.3" +libc = "0.2" +core-graphics = "0.2" +objc = "0.1.8" From fe8cc9fcdfb8c5181aba77a038b3efb0a69e84c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20G=C3=A9nier?= Date: Mon, 16 Nov 2015 21:53:18 -0500 Subject: [PATCH 36/76] Implement objc::Encode for NSRect. --- src/foundation.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/foundation.rs b/src/foundation.rs index 1840f26..155d7b9 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -9,6 +9,7 @@ use base::{id, class}; use libc; +use objc; #[cfg(target_pointer_width = "32")] pub type NSInteger = libc::c_int; @@ -38,6 +39,15 @@ impl NSPoint { } } +unsafe impl objc::Encode for NSPoint { + fn encode() -> objc::Encoding { + let encoding = format!("{{CGPoint={}{}}}", + f64::encode().as_str(), + f64::encode().as_str()); + unsafe { objc::Encoding::from_str(&encoding) } + } +} + #[repr(C)] pub struct NSSize { pub width: f64, @@ -54,6 +64,15 @@ impl NSSize { } } +unsafe impl objc::Encode for NSSize { + fn encode() -> objc::Encoding { + let encoding = format!("{{CGSize={}{}}}", + f64::encode().as_str(), + f64::encode().as_str()); + unsafe { objc::Encoding::from_str(&encoding) } + } +} + #[repr(C)] pub struct NSRect { pub origin: NSPoint, @@ -70,6 +89,15 @@ impl NSRect { } } +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) } + } +} + // Same as CGRectEdge #[repr(u32)] pub enum NSRectEdge { From 08eaff8efa28a0e591221373b5e1d00cd2704a98 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Tue, 17 Nov 2015 12:29:53 -0700 Subject: [PATCH 37/76] Bump version for publish. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d6e7f11..cad2b3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.2.0" +version = "0.2.1" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From c21f19bba228967ea4719de6226ad99bde7910b1 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Fri, 27 Nov 2015 10:25:47 -0500 Subject: [PATCH 38/76] Add various initializing methods for NSString, NSArray, and NSValue. --- Cargo.toml | 2 +- src/foundation.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cad2b3f..8fb5d5b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.2.1" +version = "0.2.2" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" diff --git a/src/foundation.rs b/src/foundation.rs index 155d7b9..d0a1184 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use base::{id, class}; +use base::{id, class, BOOL, nil}; use libc; use objc; @@ -147,6 +147,47 @@ impl NSProcessInfo for id { pub type NSTimeInterval = libc::c_double; +pub trait NSValue { + unsafe fn valueWithPoint(_: Self, point: NSPoint) -> id { + msg_send![class("NSValue"), valueWithPoint:point] + } + + unsafe fn valueWithSize(_: Self, size: NSSize) -> id { + msg_send![class("NSValue"), valueWithSize:size] + } +} + +impl NSValue for id { +} + +pub trait NSArray { + unsafe fn array(_: Self) -> id { + msg_send![class("NSArray"), array] + } + + unsafe fn arrayWithObjects(_: Self, objects: &[id]) -> id { + msg_send![class("NSArray"), arrayWithObjects:objects.as_ptr() + count:objects.len()] + } + + unsafe fn arrayWithObject(_: Self, object: id) -> id { + msg_send![class("NSArray"), arrayWithObject:object] + } + + unsafe fn arrayByAddingObjectFromArray(self, object: id) -> id; + unsafe fn arrayByAddingObjectsFromArray(self, objects: id) -> id; +} + +impl NSArray for id { + unsafe fn arrayByAddingObjectFromArray(self, object: id) -> id { + msg_send![self, arrayByAddingObjectFromArray:object] + } + + unsafe fn arrayByAddingObjectsFromArray(self, objects: id) -> id { + msg_send![self, arrayByAddingObjectsFromArray:objects] + } +} + pub trait NSString { unsafe fn alloc(_: Self) -> id { msg_send![class("NSString"), alloc] @@ -156,9 +197,16 @@ pub trait NSString { 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; } 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 != 0 + } + unsafe fn stringByAppendingString_(self, other: id) -> id { msg_send![self, stringByAppendingString:other] } From a96019726c177ccb250c4b64e08ff2bf16896af7 Mon Sep 17 00:00:00 2001 From: hc Date: Fri, 29 Jan 2016 12:19:51 -0500 Subject: [PATCH 39/76] init status bar button (icon) the minimum to get a status bar button (icon) to appear --- src/appkit.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index b4cf9a0..0106102 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -67,6 +67,7 @@ pub unsafe fn NSApp() -> id { #[repr(i64)] pub enum NSApplicationActivationPolicy { NSApplicationActivationPolicyRegular = 0, + NSApplicationActivationPolicyAccessory = 1, NSApplicationActivationPolicyERROR = -1 } @@ -294,7 +295,7 @@ impl NSApplication for id { } } -pub trait NSRunningApplication { +pub trait NSRunningApplication { unsafe fn currentApplication(_: Self) -> id { msg_send![class("NSRunningApplication"), currentApplication] } @@ -1312,7 +1313,7 @@ pub trait NSOpenGLPixelFormat { msg_send![class("NSOpenGLPixelFormat"), alloc] } - // Creating an NSOpenGLPixelFormat Object + // Creating an NSOpenGLPixelFormat Object unsafe fn initWithAttributes_(self, attributes: &[u32]) -> id; @@ -1324,7 +1325,7 @@ pub trait NSOpenGLPixelFormat { } impl NSOpenGLPixelFormat for id { - // Creating an NSOpenGLPixelFormat Object + // Creating an NSOpenGLPixelFormat Object unsafe fn initWithAttributes_(self, attributes: &[u32]) -> id { msg_send![self, initWithAttributes:attributes] @@ -2305,3 +2306,54 @@ impl NSScreen for id { msg_send![self, convertRectToBacking:aRect] } } + +pub trait NSImage { + unsafe fn alloc(_: Self) -> id { + msg_send![class("NSImage"), alloc] + } + + unsafe fn initByReferencingFile_(self, file_path: id /* (NSString *) */) -> id; +} + +impl NSImage for id { + unsafe fn initByReferencingFile_(self, file_path: id /* (NSString *) */) -> id { + msg_send![self, initByReferencingFile:file_path] + } +} + +pub trait NSButton { + unsafe fn setImage_(self, img: id /* (NSImage *) */); +} + +impl NSButton for id { + unsafe fn setImage_(self, img: id /* (NSImage *) */) { + msg_send![self, setImage:img] + } +} + +pub trait NSStatusItem { + unsafe fn button(self) -> id /* (NSStatusBarButton *) */; +} + +impl NSStatusItem for id { + unsafe fn button(self) -> id /* (NSStatusBarButton *) */ { + msg_send![self, button] + } +} + +pub const NSVariableStatusItemLength: CGFloat = -1.0; +pub const NSSquareStatusItemLength: CGFloat = -2.0; + +pub trait NSStatusBar { + unsafe fn systemStatusBar(_: Self) -> id { + msg_send![class("NSStatusBar"), systemStatusBar] + } + + unsafe fn statusItemWithLength_(self, length: CGFloat) -> id /* (NSStatusItem *) */; +} + +impl NSStatusBar for id { + unsafe fn statusItemWithLength_(self, length: CGFloat) -> id /* (NSStatusItem *) */ { + msg_send![self, statusItemWithLength:length] + } +} From 94efc59d57967e2f856340c84d3d4a804b7f2769 Mon Sep 17 00:00:00 2001 From: hc Date: Fri, 29 Jan 2016 21:04:49 -0500 Subject: [PATCH 40/76] NSStatusItem NSStatusItem fully implemented --- src/appkit.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 0106102..7394d0a 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -2331,18 +2331,43 @@ impl NSButton for id { } } +pub const NSVariableStatusItemLength: CGFloat = -1.0; +pub const NSSquareStatusItemLength: CGFloat = -2.0; + pub trait NSStatusItem { + unsafe fn statusBar(self) -> id /* (NSStatusBar *) */; unsafe fn button(self) -> id /* (NSStatusBarButton *) */; + unsafe fn menu(self) -> id; + unsafe fn setMenu_(self, menu: id); + unsafe fn length(self) -> CGFloat; + unsafe fn setLength(self, length: CGFloat); } impl NSStatusItem for id { + unsafe fn statusBar(self) -> id /* (NSStatusBar *) */ { + msg_send![self, statusBar] + } + unsafe fn button(self) -> id /* (NSStatusBarButton *) */ { msg_send![self, button] } -} -pub const NSVariableStatusItemLength: CGFloat = -1.0; -pub const NSSquareStatusItemLength: CGFloat = -2.0; + unsafe fn menu(self) -> id { + msg_send![self, menu] + } + + unsafe fn setMenu_(self, menu: id) { + msg_send![self, setMenu:menu] + } + + unsafe fn length(self) -> CGFloat { + msg_send![self, length] + } + + unsafe fn setLength(self, length: CGFloat) { + msg_send![self, setLength: length] + } +} pub trait NSStatusBar { unsafe fn systemStatusBar(_: Self) -> id { From 5d3fd956073904f085355c8e3aeaf8844754d400 Mon Sep 17 00:00:00 2001 From: hc Date: Fri, 29 Jan 2016 21:06:46 -0500 Subject: [PATCH 41/76] forgot _ for NSStatusItem setLength whoops forget to add _ for setLength --- src/appkit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 7394d0a..e536c06 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -2340,7 +2340,7 @@ pub trait NSStatusItem { unsafe fn menu(self) -> id; unsafe fn setMenu_(self, menu: id); unsafe fn length(self) -> CGFloat; - unsafe fn setLength(self, length: CGFloat); + unsafe fn setLength_(self, length: CGFloat); } impl NSStatusItem for id { @@ -2364,7 +2364,7 @@ impl NSStatusItem for id { msg_send![self, length] } - unsafe fn setLength(self, length: CGFloat) { + unsafe fn setLength_(self, length: CGFloat) { msg_send![self, setLength: length] } } From 36f4d4cab304b5750b394f4189a2322b83cc8d85 Mon Sep 17 00:00:00 2001 From: hc Date: Fri, 29 Jan 2016 21:29:53 -0500 Subject: [PATCH 42/76] NSStatusBar mostly complete, missing `thickness` property, unsure how to access this property --- src/appkit.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index e536c06..81c3d10 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -2375,10 +2375,20 @@ pub trait NSStatusBar { } unsafe fn statusItemWithLength_(self, length: CGFloat) -> id /* (NSStatusItem *) */; + unsafe fn removeStatusItem_(self, item: id /* (NSStatusItem *) */); + unsafe fn isVertical(self) -> BOOL; } impl NSStatusBar for id { unsafe fn statusItemWithLength_(self, length: CGFloat) -> id /* (NSStatusItem *) */ { msg_send![self, statusItemWithLength:length] } + + unsafe fn removeStatusItem_(self, item: id /* (NSStatusItem *) */) { + msg_send![self, removeStatusItem:item] + } + + unsafe fn isVertical(self) -> BOOL { + msg_send![self, isVertical] + } } From 20c994ecaab4afb844474b4ddebb9cd28a3c0f0e Mon Sep 17 00:00:00 2001 From: hc Date: Fri, 29 Jan 2016 22:22:01 -0500 Subject: [PATCH 43/76] NSImage methods and version bump added some methods to NSImage and version bump to 0.2.3 --- Cargo.toml | 2 +- src/appkit.rs | 43 +++++++++++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8fb5d5b..ab607f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.2.2" +version = "0.2.3" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" diff --git a/src/appkit.rs b/src/appkit.rs index 81c3d10..b3f8efb 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -2307,20 +2307,6 @@ impl NSScreen for id { } } -pub trait NSImage { - unsafe fn alloc(_: Self) -> id { - msg_send![class("NSImage"), alloc] - } - - unsafe fn initByReferencingFile_(self, file_path: id /* (NSString *) */) -> id; -} - -impl NSImage for id { - unsafe fn initByReferencingFile_(self, file_path: id /* (NSString *) */) -> id { - msg_send![self, initByReferencingFile:file_path] - } -} - pub trait NSButton { unsafe fn setImage_(self, img: id /* (NSImage *) */); } @@ -2331,6 +2317,35 @@ impl NSButton for id { } } +pub trait NSImage { + unsafe fn alloc(_: Self) -> id { + msg_send![class("NSImage"), alloc] + } + + unsafe fn initByReferencingFile_(self, file_name: id /* (NSString *) */) -> id; + unsafe fn initWithContentsOfFile_(self, file_name: id /* (NSString *) */) -> id; + unsafe fn name(self) -> id /* (NSString *) */; + unsafe fn setName_(self, name: id /* (NSString *) */) -> BOOL; +} + +impl NSImage for id { + unsafe fn initByReferencingFile_(self, file_name: id /* (NSString *) */) -> id { + msg_send![self, initByReferencingFile:file_name] + } + + unsafe fn initWithContentsOfFile_(self, file_name: id /* (NSString *) */) -> id { + msg_send![self, initWithContentsOfFile:file_name] + } + + unsafe fn name(self) -> id /* (NSString *) */ { + msg_send![self, name] + } + + unsafe fn setName_(self, name: id /* (NSString *) */) -> BOOL { + msg_send![self, setName:name] + } +} + pub const NSVariableStatusItemLength: CGFloat = -1.0; pub const NSSquareStatusItemLength: CGFloat = -2.0; From 3d09c6517af1f54591f4ecc753a2f884f7cb0f12 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 3 Feb 2016 14:15:18 -0800 Subject: [PATCH 44/76] Add a binding to -[NSView superview]. --- src/appkit.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index b3f8efb..83f6644 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1242,6 +1242,7 @@ pub trait NSView { 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; } impl NSView for id { @@ -1277,6 +1278,9 @@ impl NSView for id { msg_send![self, addSubview:view] } + unsafe fn superview(self) -> id { + msg_send![self, superview] + } } pub trait NSOpenGLView { From bf4879fa0015186638fb3750cb342d7bf45994d0 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 3 Feb 2016 14:53:27 -0800 Subject: [PATCH 45/76] Add bindings to -[NSWindow standardWindowButton:] and -[NSView removeFromSuperview]. --- src/appkit.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 83f6644..71020fc 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -223,6 +223,18 @@ pub enum NSOpenGLContextParameter { NSOpenGLCPMPSwapsInFlight = 315, } +#[repr(u64)] +#[derive(Copy, Clone, PartialEq)] +pub enum NSWindowButton { + NSWindowCloseButton = 0, + NSWindowMiniaturizeButton = 1, + NSWindowZoomButton = 2, + NSWindowToolbarButton = 3, + NSWindowDocumentIconButton = 4, + NSWindowDocumentVersionsButton = 6, + NSWindowFullScreenButton = 7, +} + pub static NSMainMenuWindowLevel: libc::int32_t = 24; pub trait NSApplication { @@ -529,7 +541,10 @@ pub trait NSWindow { // TODO: Managing Field Editors // TODO: Managing the Window Menu // TODO: Managing Cursor Rectangles - // TODO: Managing Title Bars + + // Managing Title Bars + unsafe fn standardWindowButton_(self, windowButtonKind: NSWindowButton) -> id; + // TODO: Managing Tooltips // TODO: Handling Events @@ -1016,7 +1031,13 @@ impl NSWindow for id { // TODO: Managing Field Editors // TODO: Managing the Window Menu // TODO: Managing Cursor Rectangles - // TODO: Managing Title Bars + + // Managing Title Bars + + unsafe fn standardWindowButton_(self, windowButtonKind: NSWindowButton) -> id { + msg_send![self, standardWindowButton:windowButtonKind] + } + // TODO: Managing Tooltips // TODO: Handling Events @@ -1243,6 +1264,7 @@ pub trait NSView { 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); } impl NSView for id { @@ -1281,6 +1303,10 @@ impl NSView for id { unsafe fn superview(self) -> id { msg_send![self, superview] } + + unsafe fn removeFromSuperview(self) { + msg_send![self, removeFromSuperview] + } } pub trait NSOpenGLView { From f21ffe6dc104e699ce6cacb5d6167207acf0d2dd Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Tue, 16 Feb 2016 13:09:30 +0100 Subject: [PATCH 46/76] add NSEventTypePressure event type --- src/appkit.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 71020fc..d68dae8 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1523,6 +1523,7 @@ bitflags! { } } +#[derive(Debug)] #[repr(u64)] // NSUInteger pub enum NSEventType { NSLeftMouseDown = 1, @@ -1554,6 +1555,7 @@ pub enum NSEventType { NSEventTypeRotate = 18, NSEventTypeBeginGesture = 19, NSEventTypeEndGesture = 20, + NSEventTypePressure = 34, } bitflags! { @@ -1586,6 +1588,7 @@ bitflags! { const NSEventMaskRotate = 1 << NSEventTypeRotate as libc::c_ulonglong, const NSEventMaskBeginGesture = 1 << NSEventTypeBeginGesture as libc::c_ulonglong, const NSEventMaskEndGesture = 1 << NSEventTypeEndGesture as libc::c_ulonglong, + const NSEventMaskPressure = 1 << NSEventTypePressure as libc::c_ulonglong, const NSAnyEventMask = 0xffffffff, } } @@ -1793,6 +1796,7 @@ pub trait NSEvent { unsafe fn buttonNumber(self) -> NSInteger; 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; @@ -2058,6 +2062,10 @@ impl NSEvent for id { msg_send![self, pressure] } + unsafe fn stage(self) -> NSInteger{ + msg_send![self, stage] + } + unsafe fn setMouseCoalescingEnabled_(_: Self, flag: BOOL) { msg_send![class("NSEvent"), setMouseCoalescingEnabled:flag] } From d9cf770a3cbea3ef566ec477c60c826df64a92cc Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Wed, 17 Feb 2016 04:42:29 +0100 Subject: [PATCH 47/76] version bump --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ab607f4..cc9626a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.2.3" +version = "0.2.4" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From f10177fcb2bc8f23e77c14d77fe06cb828102477 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 27 Feb 2016 10:59:41 -0500 Subject: [PATCH 48/76] Remove now default 'sudo: false' `sudo: false` is now default on Travis CI --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3800523..e5763ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ os: osx language: rust -sudo: false branches: except: From e403c78feeb1d8b958e7e8eea0a3e9038a81f2be Mon Sep 17 00:00:00 2001 From: Felix Kaaman Date: Fri, 26 Feb 2016 16:32:12 +0100 Subject: [PATCH 49/76] Add NSView functions --- src/appkit.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index d68dae8..ee0567b 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1265,6 +1265,11 @@ pub trait NSView { unsafe fn addSubview_(self, view: id); unsafe fn superview(self) -> id; unsafe fn removeFromSuperview(self); + + unsafe fn wantsLayer(self) -> BOOL; + unsafe fn setWantsLayer(self, wantsLayer: BOOL); + unsafe fn layer(self) -> id; + unsafe fn setLayer(self, layer: id); } impl NSView for id { @@ -1307,6 +1312,22 @@ impl NSView for id { unsafe fn removeFromSuperview(self) { msg_send![self, removeFromSuperview] } + + unsafe fn wantsLayer(self) -> BOOL { + msg_send![self, wantsLayer] + } + + unsafe fn setWantsLayer(self, wantsLayer: BOOL) { + msg_send![self, setWantsLayer:wantsLayer] + } + + unsafe fn layer(self) -> id { + msg_send![self, layer] + } + + unsafe fn setLayer(self, layer: id) { + msg_send![self, setLayer:layer] + } } pub trait NSOpenGLView { From ff18c50631293ab6a341d3c948f4e68e5f59cd16 Mon Sep 17 00:00:00 2001 From: Felix Kaaman Date: Sat, 27 Feb 2016 21:27:34 +0100 Subject: [PATCH 50/76] Add NSRange --- src/foundation.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/foundation.rs b/src/foundation.rs index d0a1184..262bc6d 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -89,6 +89,22 @@ impl NSRect { } } +#[repr(C)] +pub struct NSRange { + pub location: NSUInteger, + pub length: NSUInteger, +} + +impl NSRange { + #[inline] + pub fn new(location: NSUInteger, length: NSUInteger) -> NSRange { + NSRange { + location: location, + length: length + } + } +} + unsafe impl objc::Encode for NSRect { fn encode() -> objc::Encoding { let encoding = format!("{{CGRect={}{}}}", From 26d7978a136b739fe150c2cbba37d66944c05cc4 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 9 Mar 2016 16:54:43 +0100 Subject: [PATCH 51/76] Allow core-graphics 0.3 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cc9626a..bb6d584 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.2.4" +version = "0.2.5" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -14,5 +14,5 @@ crate-type = ["rlib"] [dependencies] bitflags = "0.3" libc = "0.2" -core-graphics = "0.2" +core-graphics = ">=0.2, <0.4" objc = "0.1.8" From 18fd63a5761dcf6876d879821ae00b08306eed58 Mon Sep 17 00:00:00 2001 From: Steven Sheldon Date: Sun, 20 Mar 2016 15:44:59 -0700 Subject: [PATCH 52/76] Update objc to 0.2 and bump cocoa to 0.3. --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bb6d584..1e63c9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.2.5" +version = "0.3.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -15,4 +15,4 @@ crate-type = ["rlib"] bitflags = "0.3" libc = "0.2" core-graphics = ">=0.2, <0.4" -objc = "0.1.8" +objc = "0.2" From d874e1d9d8f2b005ba469cb6ae9dd3043120ddda Mon Sep 17 00:00:00 2001 From: Conrad Kramer Date: Tue, 15 Mar 2016 01:45:32 -0700 Subject: [PATCH 53/76] Added basic NSFastEnumeration implementation --- src/foundation.rs | 74 +++++++++++++++++++++++++++++++++++++++++++++ tests/foundation.rs | 42 +++++++++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/src/foundation.rs b/src/foundation.rs index 262bc6d..7f1a357 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -7,6 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::ptr; use base::{id, class, BOOL, nil}; use libc; use objc; @@ -256,3 +257,76 @@ pub trait NSDate { impl NSDate for id { } + +#[repr(C)] +struct NSFastEnumerationState { + pub state: libc::c_ulong, + pub items_ptr: *mut id, + pub mutations_ptr: *mut libc::c_ulong, + pub extra: [libc::c_ulong; 5] +} + +const NS_FAST_ENUM_BUF_SIZE: usize = 16; + +pub struct NSFastIterator { + state: NSFastEnumerationState, + buffer: [id; NS_FAST_ENUM_BUF_SIZE], + mut_val: Option, + len: usize, + idx: usize, + object: id +} + +impl Iterator for NSFastIterator { + type Item = id; + + 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] + }; + self.idx = 0; + } + + let new_mut = unsafe { + *self.state.mutations_ptr + }; + + if let Some(old_mut) = self.mut_val { + assert!(old_mut == new_mut, "The collection was mutated while being enumerated"); + } + + if self.idx < self.len { + let object = unsafe { + *self.state.items_ptr.offset(self.idx as isize) + }; + self.mut_val = Some(new_mut); + self.idx += 1; + Some(object) + } else { + None + } + } +} + +pub trait NSFastEnumeration { + unsafe fn iter(self) -> NSFastIterator; +} + +impl NSFastEnumeration for id { + unsafe fn iter(self) -> NSFastIterator { + NSFastIterator { + state: NSFastEnumerationState { + state: 0, + items_ptr: ptr::null_mut(), + mutations_ptr: ptr::null_mut(), + extra: [0; 5] + }, + buffer: [nil; NS_FAST_ENUM_BUF_SIZE], + mut_val: None, + len: 0, + idx: 0, + object: self + } + } +} diff --git a/tests/foundation.rs b/tests/foundation.rs index c4f9130..af6fbc5 100644 --- a/tests/foundation.rs +++ b/tests/foundation.rs @@ -1,3 +1,5 @@ +#[macro_use] +extern crate objc; extern crate cocoa; #[cfg(test)] @@ -56,4 +58,44 @@ mod foundation { } } } + + mod nsfastenumeration { + use std::str; + use std::slice; + use cocoa::foundation::{NSString, NSFastEnumeration}; + use cocoa::base::{id, nil}; + + #[test] + fn test_iter() { + unsafe { + let string = NSString::alloc(nil).init_str("this is a test string"); + let separator = NSString::alloc(nil).init_str(" "); + let components: id = msg_send![string, componentsSeparatedByString:separator]; + + let combined = components.iter() + .map(|s| { + let bytes = s.UTF8String() as *const u8; + str::from_utf8(slice::from_raw_parts(bytes, s.len())).unwrap() + }) + .fold(String::new(), |mut acc, s| { acc.push_str(s); acc }); + + assert_eq!(combined, "thisisateststring"); + } + } + + #[test] + #[should_panic] + fn test_mutation() { + unsafe { + let string = NSString::alloc(nil).init_str("this is a test string"); + let separator = NSString::alloc(nil).init_str(" "); + let components: id = msg_send![string, componentsSeparatedByString:separator]; + let mut_components: id = msg_send![components, mutableCopy]; + let mut iter = mut_components.iter(); + iter.next(); + msg_send![mut_components, removeObjectAtIndex:1]; + iter.next(); + } + } + } } From f03749824460fd09d4509a69fd22604890d49895 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Thu, 28 Apr 2016 10:35:50 -0400 Subject: [PATCH 54/76] Add `NSApplicationActivationPolicyProhibited`. https://developer.apple.com/library/mac/documentation/AppKit/Reference/NSRunningApplication_Class/#//apple_ref/c/tdef/NSApplicationActivationPolicy --- Cargo.toml | 2 +- src/appkit.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1e63c9f..1a48196 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.3.0" +version = "0.3.1" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" diff --git a/src/appkit.rs b/src/appkit.rs index ee0567b..fcdbd41 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -68,6 +68,7 @@ pub unsafe fn NSApp() -> id { pub enum NSApplicationActivationPolicy { NSApplicationActivationPolicyRegular = 0, NSApplicationActivationPolicyAccessory = 1, + NSApplicationActivationPolicyProhibited = 2, NSApplicationActivationPolicyERROR = -1 } From 976e6dbc70f2131f19d34abf66b0abb4e46f81ba Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Thu, 28 Apr 2016 19:15:23 -0400 Subject: [PATCH 55/76] Derive common traits for AppKit integer repr enums. --- Cargo.toml | 2 +- src/appkit.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1a48196..06fd47e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.3.1" +version = "0.3.2" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" diff --git a/src/appkit.rs b/src/appkit.rs index fcdbd41..bc98506 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -65,6 +65,7 @@ pub unsafe fn NSApp() -> id { } #[repr(i64)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum NSApplicationActivationPolicy { NSApplicationActivationPolicyRegular = 0, NSApplicationActivationPolicyAccessory = 1, @@ -73,12 +74,14 @@ pub enum NSApplicationActivationPolicy { } #[repr(u64)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum NSApplicationActivationOptions { NSApplicationActivateAllWindows = 1 << 0, NSApplicationActivateIgnoringOtherApps = 1 << 1 } #[repr(u64)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum NSApplicationTerminateReply { NSTerminateCancel = 0, NSTerminateNow = 1, @@ -86,6 +89,7 @@ pub enum NSApplicationTerminateReply { } #[repr(u64)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum NSWindowMask { NSBorderlessWindowMask = 0, NSTitledWindowMask = 1 << 0, @@ -103,12 +107,14 @@ pub enum NSWindowMask { } #[repr(u64)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum NSWindowTitleVisibility { NSWindowTitleVisible = 0, NSWindowTitleHidden = 1 } #[repr(u64)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum NSBackingStoreType { NSBackingStoreRetained = 0, NSBackingStoreNonretained = 1, @@ -160,6 +166,7 @@ bitflags! { } #[repr(u64)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum NSOpenGLPixelFormatAttribute { NSOpenGLPFAAllRenderers = 1, NSOpenGLPFATripleBuffer = 3, @@ -204,6 +211,7 @@ pub enum NSOpenGLPixelFormatAttribute { #[repr(u64)] #[allow(non_camel_case_types)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum NSOpenGLPFAOpenGLProfiles { NSOpenGLProfileVersionLegacy = 0x1000, NSOpenGLProfileVersion3_2Core = 0x3200, @@ -211,6 +219,7 @@ pub enum NSOpenGLPFAOpenGLProfiles { } #[repr(u64)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum NSOpenGLContextParameter { NSOpenGLCPSwapInterval = 222, NSOpenGLCPSurfaceOrder = 235, @@ -225,7 +234,7 @@ pub enum NSOpenGLContextParameter { } #[repr(u64)] -#[derive(Copy, Clone, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum NSWindowButton { NSWindowCloseButton = 0, NSWindowMiniaturizeButton = 1, @@ -1545,7 +1554,7 @@ bitflags! { } } -#[derive(Debug)] +#[derive(Clone, Copy, Debug, PartialEq)] #[repr(u64)] // NSUInteger pub enum NSEventType { NSLeftMouseDown = 1, From f461b65edadb74e2b0a7d51a2e3dbca43f5ddaad Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 9 May 2016 11:01:02 -0700 Subject: [PATCH 56/76] Add autosizing-related methods and constants to `NSView`. --- src/appkit.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index bc98506..d82ed4d 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1275,6 +1275,7 @@ pub trait NSView { 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); @@ -1323,6 +1324,10 @@ impl NSView for id { msg_send![self, removeFromSuperview] } + unsafe fn setAutoresizingMask_(self, autoresizingMask: NSAutoresizingMaskOptions) { + msg_send![self, setAutoresizingMask:autoresizingMask] + } + unsafe fn wantsLayer(self) -> BOOL { msg_send![self, wantsLayer] } @@ -1340,6 +1345,16 @@ impl NSView for id { } } +pub type NSAutoresizingMaskOptions = u64; + +pub const NSViewNotSizable: u64 = 0; +pub const NSViewMinXMargin: u64 = 1; +pub const NSViewWidthSizable: u64 = 2; +pub const NSViewMaxXMargin: u64 = 4; +pub const NSViewMinYMargin: u64 = 8; +pub const NSViewHeightSizable: u64 = 16; +pub const NSViewMaxYMargin: u64 = 32; + pub trait NSOpenGLView { unsafe fn alloc(_: Self) -> id { msg_send![class("NSOpenGLView"), alloc] From 2028cee801ebcd77fd13729931313beca237335a Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 9 May 2016 11:02:38 -0700 Subject: [PATCH 57/76] Add the venerable `NSRectFill`. --- src/appkit.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index d82ed4d..0ef6324 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -2491,3 +2491,8 @@ impl NSStatusBar for id { msg_send![self, isVertical] } } + +extern { + pub fn NSRectFill(rect: NSRect); +} + From e1ac9a38217e650d0d0964f3225118be3095f8ff Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 10 May 2016 18:05:22 -0700 Subject: [PATCH 58/76] Add `-[NSApplication setApplicationIconImage:]` and `-[NSImage isValid]`. These are useful for setting icons. --- src/appkit.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 0ef6324..5596dcf 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -266,6 +266,7 @@ pub trait NSApplication { unsafe fn sendEvent_(self, an_event: id); unsafe fn postEvent_atStart_(self, anEvent: id, flag: BOOL); unsafe fn stop_(self, sender: id); + unsafe fn setApplicationIconImage_(self, image: id); } impl NSApplication for id { @@ -315,6 +316,10 @@ impl NSApplication for id { unsafe fn stop_(self, sender: id) { msg_send![self, stop:sender] } + + unsafe fn setApplicationIconImage_(self, icon: id) { + msg_send![self, setApplicationIconImage:icon] + } } pub trait NSRunningApplication { @@ -2410,6 +2415,7 @@ pub trait NSImage { unsafe fn initWithContentsOfFile_(self, file_name: id /* (NSString *) */) -> id; unsafe fn name(self) -> id /* (NSString *) */; unsafe fn setName_(self, name: id /* (NSString *) */) -> BOOL; + unsafe fn isValid(self) -> BOOL; } impl NSImage for id { @@ -2428,6 +2434,10 @@ impl NSImage for id { unsafe fn setName_(self, name: id /* (NSString *) */) -> BOOL { msg_send![self, setName:name] } + + unsafe fn isValid(self) -> BOOL { + msg_send![self, isValid] + } } pub const NSVariableStatusItemLength: CGFloat = -1.0; From 7aa45dc0a5b9035af83c80d1bf1be2c32526619d Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 12 May 2016 16:36:10 -0700 Subject: [PATCH 59/76] Add bindings for a few more menu-related functions. Bindings added include: * `-[NSApplication mainMenu]` * `-[NSApplication setWindowsMenu:]` * `+[NSMenu alloc]` * `-[NSMenu initWithTitle:]` * `-[NSMenu itemAtIndex:]` --- src/appkit.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 5596dcf..bccd2fc 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -252,9 +252,11 @@ pub trait NSApplication { msg_send![class("NSApplication"), sharedApplication] } + unsafe fn mainMenu(self) -> id; unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL; 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 run(self); unsafe fn finishLaunching(self); @@ -270,6 +272,10 @@ pub trait NSApplication { } impl NSApplication for id { + unsafe fn mainMenu(self) -> id { + msg_send![self, mainMenu] + } + unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL { msg_send![self, setActivationPolicy:policy as NSInteger] } @@ -282,6 +288,10 @@ impl NSApplication for id { msg_send![self, setServicesMenu:menu] } + unsafe fn setWindowsMenu_(self, menu: id) { + msg_send![self, setWindowsMenu:menu] + } + unsafe fn activateIgnoringOtherApps_(self, ignore: BOOL) { msg_send![self, activateIgnoringOtherApps:ignore] } @@ -336,17 +346,27 @@ impl NSRunningApplication for id { } pub trait NSMenu { + unsafe fn alloc(_: Self) -> id { + msg_send![class("NSMenu"), alloc] + } + unsafe fn new(_: Self) -> id { msg_send![class("NSMenu"), new] } + unsafe fn initWithTitle_(self, title: id /* NSString */) -> id; 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; + unsafe fn itemAtIndex_(self, index: NSInteger) -> id; } impl NSMenu for id { + unsafe fn initWithTitle_(self, title: id /* NSString */) -> id { + msg_send![self, initWithTitle:title] + } + unsafe fn setAutoenablesItems(self, state: BOOL) { msg_send![self, setAutoenablesItems: state] } @@ -358,6 +378,10 @@ 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] } + + unsafe fn itemAtIndex_(self, index: NSInteger) -> id { + msg_send![self, itemAtIndex:index] + } } pub trait NSMenuItem { From c33a483f855ff0ec2967aaf216858376c20bee63 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 12 May 2016 17:04:44 -0700 Subject: [PATCH 60/76] 0.3.3 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 06fd47e..94d375e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.3.2" +version = "0.3.3" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From 20b52d82c492bcc25cb80369ad83752fd87d08df Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 15 May 2016 12:06:35 +0200 Subject: [PATCH 61/76] Update bitflags to 0.7 --- Cargo.toml | 4 ++-- src/appkit.rs | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 06fd47e..798ffcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.3.2" +version = "0.3.3" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -12,7 +12,7 @@ name = "cocoa" crate-type = ["rlib"] [dependencies] -bitflags = "0.3" +bitflags = "0.7" libc = "0.2" core-graphics = ">=0.2, <0.4" objc = "0.2" diff --git a/src/appkit.rs b/src/appkit.rs index bc98506..99c293c 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -122,7 +122,7 @@ pub enum NSBackingStoreType { } bitflags! { - flags NSWindowOrderingMode: NSInteger { + pub flags NSWindowOrderingMode: NSInteger { const NSWindowAbove = 1, const NSWindowBelow = -1, const NSWindowOut = 0, @@ -130,7 +130,7 @@ bitflags! { } bitflags! { - flags NSAlignmentOptions: libc::c_ulonglong { + pub flags NSAlignmentOptions: libc::c_ulonglong { const NSAlignMinXInward = 1 << 0, const NSAlignMinYInward = 1 << 1, const NSAlignMaxXInward = 1 << 2, @@ -390,7 +390,7 @@ impl NSMenuItem for id { pub type NSWindowDepth = libc::c_int; bitflags! { - flags NSWindowCollectionBehavior: NSUInteger { + pub flags NSWindowCollectionBehavior: NSUInteger { const NSWindowCollectionBehaviorDefault = 0, const NSWindowCollectionBehaviorCanJoinAllSpaces = 1 << 0, const NSWindowCollectionBehaviorMoveToActiveSpace = 1 << 1, @@ -408,7 +408,7 @@ bitflags! { } bitflags! { - flags NSWindowOcclusionState: NSUInteger { + pub flags NSWindowOcclusionState: NSUInteger { const NSWindowOcclusionStateVisible = 1 << 1 } } @@ -1515,7 +1515,7 @@ impl NSOpenGLContext for id { } bitflags! { - flags NSEventSwipeTrackingOptions: NSUInteger { + pub flags NSEventSwipeTrackingOptions: NSUInteger { const NSEventSwipeTrackingLockDirection = 0x1 << 0, const NSEventSwipeTrackingClampGestureAmount = 0x1 << 1, } @@ -1529,7 +1529,7 @@ pub enum NSEventGestureAxis { } bitflags! { - flags NSEventPhase: NSUInteger { + pub flags NSEventPhase: NSUInteger { const NSEventPhaseNone = 0, const NSEventPhaseBegan = 0x1 << 0, const NSEventPhaseStationary = 0x1 << 1, @@ -1541,7 +1541,7 @@ bitflags! { } bitflags! { - flags NSTouchPhase: NSUInteger { + pub flags NSTouchPhase: NSUInteger { const NSTouchPhaseBegan = 1 << 0, const NSTouchPhaseMoved = 1 << 1, const NSTouchPhaseStationary = 1 << 2, @@ -1590,7 +1590,7 @@ pub enum NSEventType { } bitflags! { - flags NSEventMask: libc::c_ulonglong { + pub flags NSEventMask: libc::c_ulonglong { const NSLeftMouseDownMask = 1 << NSLeftMouseDown as libc::c_ulonglong, const NSLeftMouseUpMask = 1 << NSLeftMouseUp as libc::c_ulonglong, const NSRightMouseDownMask = 1 << NSRightMouseDown as libc::c_ulonglong, @@ -1631,7 +1631,7 @@ impl NSEventMask { } bitflags! { - flags NSEventModifierFlags: NSUInteger { + pub flags NSEventModifierFlags: NSUInteger { const NSAlphaShiftKeyMask = 1 << 16, const NSShiftKeyMask = 1 << 17, const NSControlKeyMask = 1 << 18, From 7094f6bf63dccc3bd00beae2af1354f34bb95fd4 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 15 May 2016 12:34:08 +0200 Subject: [PATCH 62/76] Bump to 0.3.4 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 798ffcc..4524f47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.3.3" +version = "0.3.4" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From 127f5ded12243e21ed6e73c0b60fdaae1dfff6bd Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 16 May 2016 16:14:34 +0200 Subject: [PATCH 63/76] Bump to 0.4.0 Version 0.3.4 should be yanked because bitflags >= 0.6 is incompatible with Rust <1.8 and this breaks downstream crates. Unfortunately, we can't depend on bitflags >=0.5, <0.8 because it doesn't compile with bitflags 0.5-6 because of https://github.com/rust-lang-nursery/bitflags/issues/39. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4524f47..2c76213 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.3.4" +version = "0.4.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From 5fef233f6490b92b7862a5de7e728dc71579c54c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 16 May 2016 11:24:02 -0700 Subject: [PATCH 64/76] 0.4.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2c76213..812f487 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.4.0" +version = "0.4.1" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From 37b5ce61132890abdcc99f34968d6fd6e64e9140 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 27 May 2016 13:25:32 -0700 Subject: [PATCH 65/76] Add bindings to `NSInsetRect` and `NSRectToCGRect`, and make various geometry types copyable. --- src/foundation.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/foundation.rs b/src/foundation.rs index 7f1a357..0d9e813 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -7,8 +7,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::mem; use std::ptr; use base::{id, class, BOOL, nil}; +use core_graphics::base::CGFloat; +use core_graphics::geometry::CGRect; use libc; use objc; @@ -25,6 +28,7 @@ pub type NSUInteger = libc::c_ulong; const UTF8_ENCODING: usize = 4; #[repr(C)] +#[derive(Copy, Clone)] pub struct NSPoint { pub x: f64, pub y: f64, @@ -50,6 +54,7 @@ unsafe impl objc::Encode for NSPoint { } #[repr(C)] +#[derive(Copy, Clone)] pub struct NSSize { pub width: f64, pub height: f64, @@ -75,6 +80,7 @@ unsafe impl objc::Encode for NSSize { } #[repr(C)] +#[derive(Copy, Clone)] pub struct NSRect { pub origin: NSPoint, pub size: NSSize, @@ -88,6 +94,20 @@ impl NSRect { size: size } } + + #[inline] + pub fn as_CGRect(&self) -> &CGRect { + unsafe { + mem::transmute::<&NSRect, &CGRect>(self) + } + } + + #[inline] + pub fn inset(&self, x: CGFloat, y: CGFloat) -> NSRect { + unsafe { + NSInsetRect(*self, x, y) + } + } } #[repr(C)] @@ -330,3 +350,9 @@ impl NSFastEnumeration for id { } } } + +#[link(name = "Foundation", kind = "framework")] +extern { + fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect; +} + From 32de713f332d5be660260c4764202a17ca4c256f Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 2 Jun 2016 15:29:24 -0700 Subject: [PATCH 66/76] 0.4.2 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 812f487..5e05126 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.4.1" +version = "0.4.2" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From ccf5a63e8cdecc5759d3acae042a72a3ec273722 Mon Sep 17 00:00:00 2001 From: "E. Dunham" Date: Mon, 6 Jun 2016 23:01:19 -0700 Subject: [PATCH 67/76] add README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..3024bde --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +Cocoa-rs +-------- + +This crate provides Rust bindings to Cocoa for OSX. It's dual-licensed MIT / +Apache 2.0. If you'd like to help improve cocoa-rs, check out [the Servo +contributing guide](https://github.com/servo/servo/blob/master/CONTRIBUTING.md)! From 44d37445155efdc0f56d4cc0296de6a02ce3d4dc Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 7 Jun 2016 22:01:21 -0700 Subject: [PATCH 68/76] appkit: Lengthen `NSAnyEventMask` to (-1 as u64) rather than (-1 as u32), to fix the problem whereby windows don't reappear and don't appear on top on startup. The window restoration feature in Mac OS X from Lion onward prevents windows from appearing until restoration is complete and the app is launched. Internally, the persistent UI restorer detects the app launch by listening to the Carbon event `kAEOpenApplication`, which, as an Apple event, has the event class `kEventClassAppleEvent`. Like `-[NSApplication run]` does, Glutin uses the method `-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]` to pump the application event loop. The event mask provided is an `NSEventMask`; events that do not match this mask are filtered out. When pumping the Carbon event loop, the Cocoa framework internally converts this `NSEventMask` to a Carbon event mask. The logic to perform this conversion proceeds in two steps: 1. If the provided `NSEventMask` is exactly equal to `NSAnyEventMask`, then the rest of the logic is skipped and the resulting Carbon event mask is a null mask--i.e. a mask that matches all events. 2. Otherwise, the framework constructs a blank Carbon mask--that is, a mask that matches no events at all. The various bits of the `NSEventMask` are examined, translated to their Carbon equivalents, and added to the mask. Then that Carbon mask is returned. In Glutin prior to this patch, our definition of `NSAnyEventMask` was a mask that effectively matched all events but was not equal to the real `NSAnyEventMask` that, for example, `-[NSApplication run]` supplies to `-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]`. This means that our code causes the system to take path (2) above, whereas standard Cocoa apps take path (1). Now it might seem that these paths are equivalent, but in fact they are very different. This is because *there are classes of Carbon events that do not correspond to Cocoa events selectable via `NSEventMask`*. One of these Carbon-only event types is Apple events. This fact is what made Glutin apps prior to this patch go wrong. The Carbon framework would deliver the `kAEOpenApplication` event to the application, but it was always masked out and ignored because the `NSEventMask` we supplied to `-[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]` did not translate to a Carbon event mask that included Apple events. This, in turn, caused the persistent UI restorer to never notice that the app finished launching. Thus the flag that inhibited windows from appearing would never be cleared, and all windows would end up invisible. This patch fixes the issue by lengthening `NSAnyEventMask` to its true 64-bit value, allowing the expected Carbon event filter to be used during app startup and enabling the app startup event to be handled properly. --- src/appkit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appkit.rs b/src/appkit.rs index 68d675a..3189b50 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1664,7 +1664,7 @@ bitflags! { const NSEventMaskBeginGesture = 1 << NSEventTypeBeginGesture as libc::c_ulonglong, const NSEventMaskEndGesture = 1 << NSEventTypeEndGesture as libc::c_ulonglong, const NSEventMaskPressure = 1 << NSEventTypePressure as libc::c_ulonglong, - const NSAnyEventMask = 0xffffffff, + const NSAnyEventMask = 0xffffffffffffffff, } } From 9c1ae89a9e9dbabae9df1e91917214ed05b46388 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 8 Jun 2016 10:30:12 -0700 Subject: [PATCH 69/76] 0.4.3 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5e05126..0b1cdf0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.4.2" +version = "0.4.3" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From 866cdb1ec834aae4d1a71ca414238dc6777f5bac Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 10 Jun 2016 18:34:41 -0700 Subject: [PATCH 70/76] Add bindings for `+[NSRunLoop currentRunLoop]` and `-[NSRunLoop performSelector:target:argument:order:modes:]` --- src/foundation.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/foundation.rs b/src/foundation.rs index 0d9e813..ce3dc19 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -9,7 +9,7 @@ use std::mem; use std::ptr; -use base::{id, class, BOOL, nil}; +use base::{id, class, BOOL, SEL, nil}; use core_graphics::base::CGFloat; use core_graphics::geometry::CGRect; use libc; @@ -356,3 +356,33 @@ extern { fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect; } +pub trait NSRunLoop { + unsafe fn currentRunLoop() -> Self; + + unsafe fn performSelector_target_argument_order_modes_(self, + aSelector: SEL, + target: id, + anArgument: id, + order: NSUInteger, + modes: id); +} + +impl NSRunLoop for id { + unsafe fn currentRunLoop() -> id { + msg_send![class("NSRunLoop"), currentRunLoop] + } + + unsafe fn performSelector_target_argument_order_modes_(self, + aSelector: SEL, + target: id, + anArgument: id, + order: NSUInteger, + modes: id) { + msg_send![self, performSelector:aSelector + target:target + argument:anArgument + order:order + modes:modes] + } +} + From daac2c1cc1f274e13b240c3cdabfa15382469671 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 10 Jun 2016 18:41:45 -0700 Subject: [PATCH 71/76] 0.4.4 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0b1cdf0..8351272 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "cocoa" description = "Bindings to Cocoa for OS X" homepage = "https://github.com/servo/cocoa-rs" repository = "https://github.com/servo/cocoa-rs" -version = "0.4.3" +version = "0.4.4" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From a7b905f26321db62bbdc0ee9334b5dda064db0be Mon Sep 17 00:00:00 2001 From: mitchmindtree Date: Fri, 24 Jun 2016 15:48:16 +1000 Subject: [PATCH 72/76] Add missing cocoa Data Type constants --- src/appkit.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 3189b50..fdf0fa0 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -32,6 +32,42 @@ pub type GLint = libc::int32_t; #[link(name = "AppKit", kind = "framework")] extern { pub static NSAppKitVersionNumber: f64; + + // Types for Standard Data - OS X v10.6 and later. (NSString *const) + pub static NSPasteboardTypeString: id; + pub static NSPasteboardTypePDF: id; + pub static NSPasteboardTypeTIFF: id; + pub static NSPasteboardTypePNG: id; + pub static NSPasteboardTypeRTF: id; + pub static NSPasteboardTypeRTFD: id; + pub static NSPasteboardTypeHTML: id; + pub static NSPasteboardTypeTabularText: id; + pub static NSPasteboardTypeFont: id; + pub static NSPasteboardTypeRuler: id; + pub static NSPasteboardTypeColor: id; + pub static NSPasteboardTypeSound: id; + pub static NSPasteboardTypeMultipleTextSelection: id; + pub static NSPasteboardTypeFindPanelSearchOptions: id; + + // Types for Standard Data - OS X v10.5 and earlier. (NSString *) + pub static NSStringPboardType: id; + pub static NSFilenamesPboardType: id; + pub static NSPostScriptPboardType: id; + pub static NSTIFFPboardType: id; + pub static NSRTFPboardType: id; + pub static NSTabularTextPboardType: id; + pub static NSFontPboardType: id; + pub static NSRulerPboardType: id; + pub static NSFileContentsPboardType: id; + pub static NSColorPboardType: id; + pub static NSRTFDPboardType: id; + pub static NSHTMLPboardType: id; + pub static NSPICTPboardType: id; + pub static NSURLPboardType: id; + pub static NSPDFPboardType: id; + pub static NSVCardPboardType: id; + pub static NSFilesPromisePboardType: id; + pub static NSMultipleTextSelectionPboardType: id; } pub const NSAppKitVersionNumber10_0: f64 = 577.0; From 6367782ef83763de1505bca85d24f31bf4cff975 Mon Sep 17 00:00:00 2001 From: George Burton Date: Thu, 30 Jun 2016 22:54:55 +0100 Subject: [PATCH 73/76] Add NSPasteboard, NSPasteboardItem, NSPasteboardReading, NSPasteboardWriting, NSPasteboardReadingOptions, NSPasteboardWriting options, and various other constants --- src/appkit.rs | 290 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 290 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index fdf0fa0..4dd6cce 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -68,6 +68,17 @@ extern { pub static NSVCardPboardType: id; pub static NSFilesPromisePboardType: id; pub static NSMultipleTextSelectionPboardType: id; + + // Names of provided pasteboards. (NSString *) + pub static NSGeneralPboard: id; + pub static NSFontPboard: id; + pub static NSRulerPboard: id; + pub static NSFindPboard: id; + pub static NSDragPboard: id; + + // Pasteboard reading options - OS X v10.6 and later. (NSString *) + pub static NSPasteboardURLReadingFileURLsOnlyKey: id; + pub static NSPasteboardURLReadingContentsConformToTypesKey: id; } pub const NSAppKitVersionNumber10_0: f64 = 577.0; @@ -381,6 +392,285 @@ impl NSRunningApplication for id { } } +pub trait NSPasteboard { + unsafe fn generalPasteboard(_: Self) -> id { + msg_send![class("NSPasteboard"), generalPasteboard] + } + + unsafe fn pasteboardByFilteringData_ofType(_: Self, data: id, _type: id) -> id { + msg_send![class("NSPasteboard"), pasteboardByFilteringData:data ofType:_type] + } + + unsafe fn pasteboardByFilteringFile(_: Self, file: id) -> id { + msg_send![class("NSPasteboard"), pasteboardByFilteringFile:file] + } + + unsafe fn pasteboardByFilteringTypesInPasteboard(_: Self, pboard: id) -> id { + msg_send![class("NSPasteboard"), pasteboardByFilteringTypesInPasteboard:pboard] + } + + unsafe fn pasteboardWithName(_: Self, name: id) -> id { + msg_send![class("NSPasteboard"), pasteboardWithName:name] + } + + unsafe fn pasteboardWithUniqueName(_: Self) -> id { + msg_send![class("NSPasteboard"), pasteboardWithUniqueName] + } + + unsafe fn releaseGlobally(self); + + unsafe fn clearContents(self) -> NSInteger; + unsafe fn writeObjects(self, objects: id) -> BOOL; + unsafe fn sendData_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; + unsafe fn indexOfPasteboardItem(self, pasteboardItem: id) -> NSInteger; + unsafe fn dataForType(self, dataType: id) -> id; + unsafe fn propertyListForType(self, dataType: id) -> id; + 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 types(self) -> id; + unsafe fn typesFilterableTo(_: Self, _type: id) -> id { + msg_send![class("NSPasteboard"), typesFilterableTo:_type] + } + + unsafe fn name(self) -> id; + unsafe fn changeCount(self) -> NSInteger; + + 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 readFileContentsType_toFile(self, _type: id, filename: id) -> id; + unsafe fn readFileWrapper(self) -> id; +} + +impl NSPasteboard for id { + unsafe fn releaseGlobally(self) { + msg_send![self, releaseGlobally]; + } + + unsafe fn clearContents(self) -> NSInteger { + msg_send![self, clearContents] + } + + unsafe fn writeObjects(self, objects: id) -> BOOL { + msg_send![self, writeObjects:objects] + } + + unsafe fn sendData_forType(self, data: id, dataType: id) -> BOOL { + msg_send![self, sendData:data 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 readObjectsForClasses_options(self, classArray: id, options: id) -> id { + msg_send![self, readObjectsForClasses:classArray options:options] + } + + unsafe fn pasteboardItems(self) -> id { + msg_send![self, pasteboardItems] + } + + unsafe fn indexOfPasteboardItem(self, pasteboardItem: id) -> NSInteger { + msg_send![self, indexOfPasteboardItem:pasteboardItem] + } + + unsafe fn dataForType(self, dataType: id) -> id { + msg_send![self, dataForType:dataType] + } + + unsafe fn propertyListForType(self, dataType: id) -> id { + msg_send![self, propertyListForType:dataType] + } + + unsafe fn stringForType(self, dataType: id) -> id { + msg_send![self, stringForType:dataType] + } + + unsafe fn availableTypeFromArray(self, types: id) -> id { + msg_send![self, availableTypeFromArray:types] + } + + 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 types(self) -> id { + msg_send![self, types] + } + + unsafe fn name(self) -> id { + msg_send![self, name] + } + + unsafe fn changeCount(self) -> NSInteger { + msg_send![self, changeCount] + } + + unsafe fn declareTypes_owner(self, newTypes: id, newOwner: id) -> NSInteger { + msg_send![self, declareTypes:newTypes owner:newOwner] + } + + unsafe fn addTypes_owner(self, newTypes: id, newOwner: id) -> NSInteger { + msg_send![self, addTypes:newTypes owner:newOwner] + } + + unsafe fn writeFileContents(self, filename: id) -> BOOL { + msg_send![self, writeFileContents:filename] + } + + 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] + } + + unsafe fn readFileWrapper(self) -> id { + msg_send![self, readFileWrapper] + } + +} + +pub trait NSPasteboardItem { + 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 dataForType(self, _type: id) -> id; + unsafe fn stringForType(self, _type: id) -> id; + unsafe fn propertyListForType(self, _type: id) -> id; +} + +impl NSPasteboardItem for id { + unsafe fn types(self) -> id { + msg_send![self, 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 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 dataForType(self, _type: id) -> id { + msg_send![self, dataForType:_type] + } + + unsafe fn stringForType(self, _type: id) -> id { + msg_send![self, stringForType:_type] + } + + unsafe fn propertyListForType(self, _type: id) -> id { + msg_send![self, propertyListForType:_type] + } +} + +pub trait NSPasteboardItemDataProvider { + unsafe fn pasteboard_item_provideDataForType(self, pasteboard: id, item: id, _type: id); + unsafe fn pasteboardFinishedWithDataProvider(self, pasteboard: id); +} + +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] + } + + unsafe fn pasteboardFinishedWithDataProvider(self, pasteboard: id) { + msg_send![self, pasteboardFinishedWithDataProvider:pasteboard] + } +} + +pub trait NSPasteboardWriting { + unsafe fn writableTypesForPasteboard(self, pasteboard: id) -> id; + unsafe fn writingOptionsForType_pasteboard(self, _type: id, pasteboard: id) -> NSPasteboardWritingOptions; + + unsafe fn pasteboardPropertyListForType(self, _type: id) -> id; +} + +impl NSPasteboardWriting for id { + unsafe fn writableTypesForPasteboard(self, pasteboard: id) -> id { + msg_send![self, writableTypesForPasteboard:pasteboard] + } + + unsafe fn writingOptionsForType_pasteboard(self, _type: id, pasteboard: id) -> NSPasteboardWritingOptions { + msg_send![self, writingOptionsForType:_type pasteboard:pasteboard] + } + + unsafe fn pasteboardPropertyListForType(self, _type: id) -> id { + msg_send![self, pasteboardPropertyListForType:_type] + } +} + +pub trait NSPasteboardReading { + unsafe fn initWithPasteboardPropertyList_ofType(self, propertyList: id, _type: id) -> id; + + unsafe fn readableTypesForPasteboard(self, pasteboard: id) -> id; + unsafe fn readingOptionsForType_pasteboard(self, _type: id, pasteboard: id) -> NSPasteboardReadingOptions; +} + +impl NSPasteboardReading for id { + unsafe fn initWithPasteboardPropertyList_ofType(self, propertyList: id, _type: id) -> id { + msg_send![self, initWithPasteboardPropertyList:propertyList ofType:_type] + } + + unsafe fn readableTypesForPasteboard(self, pasteboard: id) -> id { + let class: id = msg_send![self, class]; + msg_send![class, readableTypesForPasteboard:pasteboard] + } + unsafe fn readingOptionsForType_pasteboard(self, _type: id, pasteboard: id) -> NSPasteboardReadingOptions { + let class: id = msg_send![self, class]; + msg_send![class, readingOptionsForType:_type pasteboard:pasteboard] + } +} + +#[repr(u64)] +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum NSPasteboardReadingOptions { + NSPasteboardReadingAsData = 0, + NSPasteboardReadingAsString = 1 << 0, + NSPasteboardReadingAsPropertyList = 1 << 1, + NSPasteboardReadingAsKeyedArchive = 1 << 2 +} + +#[repr(u64)] +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum NSPasteboardWritingOptions { + NSPasteboardWritingPromised = 1 << 9, +} + pub trait NSMenu { unsafe fn alloc(_: Self) -> id { msg_send![class("NSMenu"), alloc] From 3c86fc88bb59ec80797e50b04979a77f9d0c0240 Mon Sep 17 00:00:00 2001 From: George Burton Date: Sun, 3 Jul 2016 21:45:03 +0100 Subject: [PATCH 74/76] Add NSData and associated constants --- Cargo.toml | 1 + src/foundation.rs | 233 ++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + 3 files changed, 235 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 8351272..2459ad0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ name = "cocoa" crate-type = ["rlib"] [dependencies] +block = "0.1" bitflags = "0.7" libc = "0.2" core-graphics = ">=0.2, <0.4" diff --git a/src/foundation.rs b/src/foundation.rs index ce3dc19..d2bcbee 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -7,9 +7,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![allow(non_upper_case_globals)] + use std::mem; use std::ptr; use base::{id, class, BOOL, SEL, nil}; +use block::Block; use core_graphics::base::CGFloat; use core_graphics::geometry::CGRect; use libc; @@ -386,3 +389,233 @@ impl NSRunLoop for id { } } +pub trait NSData { + unsafe fn data(_: Self) -> id { + msg_send![class("NSData"), data] + } + + unsafe fn dataWithBytes_length_(_: Self, bytes: *const libc::c_void, length: NSUInteger) -> id { + msg_send![class("NSData"), dataWithBytes:bytes length:length] + } + + unsafe fn dataWithBytesNoCopy_length_(_: Self, bytes: *const libc::c_void, length: NSUInteger) -> id { + msg_send![class("NSData"), dataWithBytesNoCopy:bytes length:length] + } + + unsafe fn dataWithBytesNoCopy_length_freeWhenDone_(_: Self, bytes: *const libc::c_void, + length: NSUInteger, freeWhenDone: BOOL) -> id { + msg_send![class("NSData"), dataWithBytesNoCopy:bytes length:length freeWhenDone:freeWhenDone] + } + + unsafe fn dataWithContentsOfFile_(_: Self, path: id) -> id { + msg_send![class("NSData"), dataWithContentsOfFile:path] + } + + unsafe fn dataWithContentsOfFile_options_error_(_: Self, path: id, mask: NSDataReadingOptions, + errorPtr: *mut id) -> id { + msg_send![class("NSData"), dataWithContentsOfFile:path options:mask error:errorPtr] + } + + unsafe fn dataWithContentsOfURL_(_: Self, aURL: id) -> id { + msg_send![class("NSData"), dataWithContentsOfURL:aURL] + } + + unsafe fn dataWithContentsOfURL_options_error_(_: Self, aURL: id, mask: NSDataReadingOptions, + errorPtr: *mut id) -> id { + msg_send![class("NSData"), dataWithContentsOfURL:aURL options:mask error:errorPtr] + } + + unsafe fn dataWithData_(_: Self, aData: id) -> id { + msg_send![class("NSData"), dataWithData:aData] + } + + unsafe fn initWithBase64EncodedData_options_(self, base64Data: id, options: NSDataBase64DecodingOptions) + -> id; + unsafe fn initWithBase64EncodedString_options_(self, base64String: id, options: NSDataBase64DecodingOptions) + -> id; + unsafe fn initWithBytes_length_(self, bytes: *const libc::c_void, length: NSUInteger) -> id; + unsafe fn initWithBytesNoCopy_length_(self, bytes: *const libc::c_void, length: NSUInteger) -> id; + unsafe fn initWithBytesNoCopy_length_deallocator_(self, bytes: *const libc::c_void, length: NSUInteger, + deallocator: *mut Block<(*const libc::c_void, NSUInteger), ()>) + -> id; + unsafe fn initWithBytesNoCopy_length_freeWhenDone_(self, bytes: *const libc::c_void, + 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; + unsafe fn initWithContentsOfURL_(self, aURL: id) -> id; + unsafe fn initWithContentsOfURL_options_error_(self, aURL: id, mask: NSDataReadingOptions, errorPtr: *mut id) + -> id; + unsafe fn initWithData_(self, data: id) -> id; + + unsafe fn bytes(self) -> *const libc::c_void; + unsafe fn description(self) -> id; + unsafe fn enumerateByteRangesUsingBlock_(self, block: *mut Block<(*const libc::c_void, NSRange, *mut BOOL), ()>); + unsafe fn getBytes_length_(self, buffer: *mut libc::c_void, length: NSUInteger); + unsafe fn getBytes_range_(self, buffer: *mut libc::c_void, range: NSRange); + unsafe fn subdataWithRange_(self, range: NSRange) -> id; + unsafe fn rangeOfData_options_range_(self, dataToFind: id, options: NSDataSearchOptions, searchRange: NSRange) + -> NSRange; + + unsafe fn base64EncodedDataWithOptions_(self, options: NSDataBase64EncodingOptions) -> id; + unsafe fn base64EncodedStringWithOptions_(self, options: NSDataBase64EncodingOptions) -> id; + + 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; +} + +impl NSData for id { + unsafe fn initWithBase64EncodedData_options_(self, base64Data: id, options: NSDataBase64DecodingOptions) + -> id { + msg_send![self, initWithBase64EncodedData:base64Data options:options] + } + + unsafe fn initWithBase64EncodedString_options_(self, base64String: id, options: NSDataBase64DecodingOptions) + -> id { + msg_send![self, initWithBase64EncodedString:base64String options:options] + } + + unsafe fn initWithBytes_length_(self, bytes: *const libc::c_void, length: NSUInteger) -> id { + msg_send![self,initWithBytes:bytes length:length] + } + + unsafe fn initWithBytesNoCopy_length_(self, bytes: *const libc::c_void, length: NSUInteger) -> id { + msg_send![self, initWithBytesNoCopy:bytes length:length] + } + + unsafe fn initWithBytesNoCopy_length_deallocator_(self, bytes: *const libc::c_void, length: NSUInteger, + deallocator: *mut Block<(*const libc::c_void, NSUInteger), ()>) + -> id { + msg_send![self, initWithBytesNoCopy:bytes length:length deallocator:deallocator] + } + + unsafe fn initWithBytesNoCopy_length_freeWhenDone_(self, bytes: *const libc::c_void, + length: NSUInteger, freeWhenDone: BOOL) -> id { + msg_send![self, initWithBytesNoCopy:bytes length:length freeWhenDone:freeWhenDone] + } + + unsafe fn initWithContentsOfFile_(self, path: id) -> id { + msg_send![self, initWithContentsOfFile:path] + } + + unsafe fn initWithContentsOfFile_options_error(self, path: id, mask: NSDataReadingOptions, errorPtr: *mut id) + -> id { + msg_send![self, initWithContentsOfFile:path options:mask error:errorPtr] + } + + unsafe fn initWithContentsOfURL_(self, aURL: id) -> id { + msg_send![self, initWithContentsOfURL:aURL] + } + + unsafe fn initWithContentsOfURL_options_error_(self, aURL: id, mask: NSDataReadingOptions, errorPtr: *mut id) + -> id { + msg_send![self, initWithContentsOfURL:aURL options:mask error:errorPtr] + } + + unsafe fn initWithData_(self, data: id) -> id { + msg_send![self, initWithData:data] + } + + unsafe fn bytes(self) -> *const libc::c_void { + msg_send![self, bytes] + } + + unsafe fn description(self) -> id { + msg_send![self, description] + } + + unsafe fn enumerateByteRangesUsingBlock_(self, block: *mut Block<(*const libc::c_void, NSRange, *mut BOOL), ()>) { + msg_send![self, enumerateByteRangesUsingBlock:block] + } + + unsafe fn getBytes_length_(self, buffer: *mut libc::c_void, length: NSUInteger) { + msg_send![self, getBytes:buffer length:length] + } + + unsafe fn getBytes_range_(self, buffer: *mut libc::c_void, range: NSRange) { + msg_send![self, getBytes:buffer range:range] + } + + unsafe fn subdataWithRange_(self, range: NSRange) -> id { + msg_send![self, subdataWithRange:range] + } + + unsafe fn rangeOfData_options_range_(self, dataToFind: id, options: NSDataSearchOptions, searchRange: NSRange) + -> NSRange { + msg_send![self, rangeOfData:dataToFind options:options range:searchRange] + } + + unsafe fn base64EncodedDataWithOptions_(self, options: NSDataBase64EncodingOptions) -> id { + msg_send![self, base64EncodedDataWithOptions:options] + } + + unsafe fn base64EncodedStringWithOptions_(self, options: NSDataBase64EncodingOptions) -> id { + msg_send![self, base64EncodedStringWithOptions:options] + } + + unsafe fn isEqualToData_(self, otherData: id) -> id { + msg_send![self, isEqualToData:otherData] + } + + unsafe fn length(self) -> NSUInteger { + msg_send![self, length] + } + + 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 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] + } +} + +bitflags! { + pub flags NSDataReadingOptions: libc::c_ulonglong { + const NSDataReadingMappedIfSafe = 1 << 0, + const NSDataReadingUncached = 1 << 1, + const NSDataReadingMappedAlways = 1 << 3 + } +} + +bitflags! { + pub flags NSDataBase64EncodingOptions: libc::c_ulonglong { + const NSDataBase64Encoding64CharacterLineLength = 1 << 0, + const NSDataBase64Encoding76CharacterLineLength = 1 << 1, + const NSDataBase64EncodingEndLineWithCarriageReturn = 1 << 4, + const NSDataBase64EncodingEndLineWithLineFeed = 1 << 5 + } +} + +bitflags! { + pub flags NSDataBase64DecodingOptions: libc::c_ulonglong { + const NSDataBase64DecodingIgnoreUnknownCharacters = 1 << 0 + } +} + +bitflags! { + pub flags NSDataWritingOptions: libc::c_ulonglong { + const NSDataWritingAtomic = 1 << 0, + const NSDataWritingWithoutOverwriting = 1 << 1 + } +} + +bitflags! { + pub flags NSDataSearchOptions: libc::c_ulonglong { + const NSDataSearchBackwards = 1 << 0, + const NSDataSearchAnchored = 1 << 1 + } +} diff --git a/src/lib.rs b/src/lib.rs index 5c3e062..d414970 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ #![allow(non_snake_case)] +extern crate block; #[macro_use] extern crate bitflags; extern crate libc; From 575fd9ea9235974145ac179e6634828e35b4251b Mon Sep 17 00:00:00 2001 From: George Burton Date: Thu, 7 Jul 2016 18:18:58 +0100 Subject: [PATCH 75/76] Add NSSound --- src/appkit.rs | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 4dd6cce..9072b80 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -68,6 +68,7 @@ extern { pub static NSVCardPboardType: id; pub static NSFilesPromisePboardType: id; pub static NSMultipleTextSelectionPboardType: id; + pub static NSSoundPboardType: id; // Names of provided pasteboards. (NSString *) pub static NSGeneralPboard: id; @@ -2790,6 +2791,112 @@ impl NSImage for id { } } +pub trait NSSound { + 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 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 playbackDeviceIdentifier(self) -> id; + unsafe fn delegate(self) -> id; + + unsafe fn soundUnfilteredTypes(_: Self) -> id { + msg_send![class("NSSound"), soundUnfilteredTypes] + } + + unsafe fn soundNamed_(_: Self, soundName: id) -> id { + msg_send![class("NSSound"), soundNamed:soundName] + } + + 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 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 initWithContentsOfURL_withReference_(self, fileUrl: id, byRef: BOOL) -> id { + msg_send![self, initWithContentsOfURL:fileUrl withReference:byRef] + } + + unsafe fn initWithData_(self, audioData: id) -> id { + msg_send![self, initWithData:audioData] + } + + unsafe fn initWithPasteboard_(self, pasteboard: id) -> id { + msg_send![self, initWithPasteboard:pasteboard] + } + + unsafe fn name(self) -> id { + msg_send![self, name] + } + + unsafe fn volume(self) -> f32 { + msg_send![self, volume] + } + + unsafe fn currentTime(self) -> NSTimeInterval { + msg_send![self, currentTime] + } + + unsafe fn loops(self) -> BOOL { + msg_send![self, loops] + } + + unsafe fn playbackDeviceIdentifier(self) -> id { + msg_send![self, playbackDeviceIdentifier] + } + + unsafe fn delegate(self) -> id { + msg_send![self, delegate] + } + + unsafe fn duration(self) -> NSTimeInterval { + msg_send![self, duration] + } + + unsafe fn playing(self) -> BOOL { + msg_send![self, playing] + } + + unsafe fn pause(self) -> BOOL { + msg_send![self, pause] + } + + unsafe fn play(self) -> BOOL { + msg_send![self, play] + } + + unsafe fn resume(self) -> BOOL { + msg_send![self, resume] + } + + unsafe fn stop(self) -> BOOL { + msg_send![self, stop] + } + + unsafe fn writeToPasteboard_(self, pasteboard: id) { + msg_send![self, writeToPasteboard:pasteboard] + } +} + pub const NSVariableStatusItemLength: CGFloat = -1.0; pub const NSSquareStatusItemLength: CGFloat = -2.0; From 0b4616d1c3543e969fded27b51ad6ca507ae5cfc Mon Sep 17 00:00:00 2001 From: George Burton Date: Sun, 10 Jul 2016 10:35:14 +0100 Subject: [PATCH 76/76] Add more NSImage methods, and add associated enums + string constants --- src/appkit.rs | 376 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 376 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 9072b80..a8336c9 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -10,6 +10,7 @@ #![allow(non_upper_case_globals)] use base::{id, class, BOOL, SEL}; +use block::Block; use foundation::{NSInteger, NSUInteger, NSTimeInterval, NSPoint, NSSize, NSRect, NSRectEdge}; use libc; @@ -2764,9 +2765,80 @@ pub trait NSImage { unsafe fn initByReferencingFile_(self, file_name: id /* (NSString *) */) -> id; unsafe fn initWithContentsOfFile_(self, file_name: id /* (NSString *) */) -> id; + unsafe fn initWithData_(self, data: id /* (NSData *) */) -> id; + 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>); + unsafe fn initWithSize_(self, aSize: NSSize) -> id; + + unsafe fn imageNamed_(_: Self, name: id /* (NSString *) */) -> id { + msg_send![class("NSImage"), imageNamed:name] + } + unsafe fn name(self) -> id /* (NSString *) */; unsafe fn setName_(self, name: id /* (NSString *) */) -> BOOL; + + unsafe fn size(self) -> NSSize; + unsafe fn template(self) -> BOOL; + + unsafe fn canInitWithPasteboard_(self, pasteboard: id /* (NSPasteboard *) */) -> BOOL; + unsafe fn imageTypes(self) -> id /* (NSArray ) */; + unsafe fn imageUnfilteredTypes(self) -> id /* (NSArray ) */; + + unsafe fn addRepresentation_(self, imageRep: id /* (NSImageRep *) */); + unsafe fn addRepresentations_(self, imageReps: id /* (NSArray *) */); + unsafe fn representations(self) -> id /* (NSArray *) */; + unsafe fn removeRepresentation_(self, imageRep: id /* (NSImageRep *) */); + unsafe fn bestRepresentationForRect_context_hints_(self, rect: NSRect, + 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 drawInRect_(self, rect: NSRect); + unsafe fn drawAtPoint_fromRect_operation_fraction_(self, point: NSPoint, srcRect: NSRect, + op: NSCompositingOperation, delta: CGFloat); + 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, + hints: id /* (NSDictionary *) */); + unsafe fn drawRepresentation_inRect_(self, imageRep: id /* (NSImageRep *) */, dstRect: NSRect); + unsafe fn isValid(self) -> BOOL; + unsafe fn backgroundColor(self) -> id /* (NSColor *) */; + + unsafe fn lockFocus(self); + unsafe fn lockFocusFlipped_(self, flipped: BOOL); + unsafe fn unlockFocus(self); + + unsafe fn alignmentRect(self) -> NSRect; + + unsafe fn cacheMode(self) -> NSImageCacheMode; + unsafe fn recache(self); + + unsafe fn delegate(self) -> id /* (id *) */; + + unsafe fn TIFFRepresentation(self) -> id /* (NSData *) */; + unsafe fn TIFFRepresentationUsingCompression_factor_(self, comp: NSTIFFCompression, aFloat: f32) + -> id /* (NSData *) */; + + unsafe fn cancelIncrementalLoad(self); + + unsafe fn hitTestRect_withImageDestinationRect_context_hints_flipped_(self, testRectDestSpace: NSRect, + imageRectDestSpace: NSRect, referenceContext: id /* (NSGraphicsContext *) */, + 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; } impl NSImage for id { @@ -2778,6 +2850,30 @@ impl NSImage for id { msg_send![self, initWithContentsOfFile:file_name] } + unsafe fn initWithData_(self, data: id /* (NSData *) */) -> id { + msg_send![self, initWithData:data] + } + + unsafe fn initWithDataIgnoringOrientation_(self, data: id /* (NSData *) */) -> id { + msg_send![self, initWithDataIgnoringOrientation:data] + } + + unsafe fn initWithPasteboard_(self, pasteboard: id /* (NSPasteboard *) */) -> id { + msg_send![self, initWithPasteboard:pasteboard] + } + + unsafe fn initWithSize_flipped_drawingHandler_(self, size: NSSize, + drawingHandlerShouldBeCalledWithFlippedContext: BOOL, + drawingHandler: *mut Block<(NSRect,), BOOL>) { + msg_send![self, initWithSize:size + flipped:drawingHandlerShouldBeCalledWithFlippedContext + drawingHandler:drawingHandler] + } + + unsafe fn initWithSize_(self, aSize: NSSize) -> id { + msg_send![self, initWithSize:aSize] + } + unsafe fn name(self) -> id /* (NSString *) */ { msg_send![self, name] } @@ -2786,9 +2882,289 @@ impl NSImage for id { msg_send![self, setName:name] } + unsafe fn size(self) -> NSSize { + msg_send![self, size] + } + + unsafe fn template(self) -> BOOL { + msg_send![self, template] + } + + unsafe fn canInitWithPasteboard_(self, pasteboard: id /* (NSPasteboard *) */) -> BOOL { + msg_send![self, canInitWithPasteboard:pasteboard] + } + + unsafe fn imageTypes(self) -> id /* (NSArray ) */ { + msg_send![self, imageTypes] + } + + unsafe fn imageUnfilteredTypes(self) -> id /* (NSArray ) */ { + msg_send![self, imageUnfilteredTypes] + } + + unsafe fn addRepresentation_(self, imageRep: id /* (NSImageRep *) */) { + msg_send![self, addRepresentation:imageRep] + } + + unsafe fn addRepresentations_(self, imageReps: id /* (NSArray *) */) { + msg_send![self, addRepresentations:imageReps] + } + + unsafe fn representations(self) -> id /* (NSArray *) */ { + msg_send![self, representations] + } + + unsafe fn removeRepresentation_(self, imageRep: id /* (NSImageRep *) */) { + msg_send![self, removeRepresentation:imageRep] + } + + unsafe fn bestRepresentationForRect_context_hints_(self, rect: NSRect, + referenceContext: id /* (NSGraphicsContext *) */, + hints: id /* (NSDictionary *) */) + -> id /* (NSImageRep *) */ { + msg_send![self, bestRepresentationForRect:rect context:referenceContext hints:hints] + } + + unsafe fn prefersColorMatch(self) -> BOOL { + msg_send![self, prefersColorMatch] + } + + unsafe fn usesEPSOnResolutionMismatch(self) -> BOOL { + msg_send![self, usesEPSOnResolutionMismatch] + } + + unsafe fn matchesOnMultipleResolution(self) -> BOOL { + msg_send![self, matchesOnMultipleResolution] + } + + unsafe fn drawInRect_(self, rect: NSRect) { + msg_send![self, drawInRect:rect] + } + + 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] + } + + 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] + } + + unsafe fn drawInRect_fromRect_operation_fraction_respectFlipped_hints_(self, dstSpacePortionRect: NSRect, + srcSpacePortionRect: NSRect, op: NSCompositingOperation, delta: CGFloat, respectContextIsFlipped: BOOL, + hints: id /* (NSDictionary *) */) { + 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] + } + unsafe fn isValid(self) -> BOOL { msg_send![self, isValid] } + + unsafe fn backgroundColor(self) -> id /* (NSColor *) */ { + msg_send![self, backgroundColor] + } + + unsafe fn lockFocus(self) { + msg_send![self, lockFocus] + } + + unsafe fn lockFocusFlipped_(self, flipped: BOOL) { + msg_send![self, lockFocusFlipped:flipped] + } + + unsafe fn unlockFocus(self) { + msg_send![self, unlockFocus] + } + + unsafe fn alignmentRect(self) -> NSRect { + msg_send![self, alignmentRect] + } + + unsafe fn cacheMode(self) -> NSImageCacheMode { + msg_send![self, cacheMode] + } + + unsafe fn recache(self) { + msg_send![self, recache] + } + + unsafe fn delegate(self) -> id /* (id *) */ { + msg_send![self, delegate] + } + + unsafe fn TIFFRepresentation(self) -> id /* (NSData *) */ { + msg_send![self, TIFFRepresentation] + } + + unsafe fn TIFFRepresentationUsingCompression_factor_(self, comp: NSTIFFCompression, aFloat: f32) + -> id /* (NSData *) */ { + msg_send![self, TIFFRepresentationUsingCompression:comp factor:aFloat] + } + + unsafe fn cancelIncrementalLoad(self) { + msg_send![self, cancelIncrementalLoad] + } + + 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 + flipped:flipped] + } + + unsafe fn accessibilityDescription(self) -> id /* (NSString *) */ { + msg_send![self, accessibilityDescription] + } + + unsafe fn layerContentsForContentsScale_(self, layerContentsScale: CGFloat) -> id /* (id) */ { + msg_send![self, layerContentsForContentsScale:layerContentsScale] + } + + unsafe fn recommendedLayerContentsScale_(self, preferredContentsScale: CGFloat) -> CGFloat { + msg_send![self, recommendedLayerContentsScale:preferredContentsScale] + } + + unsafe fn matchesOnlyOnBestFittingAxis(self) -> BOOL { + msg_send![self, matchesOnlyOnBestFittingAxis] + } +} + +#[link(name = "AppKit", kind = "framework")] +extern { + // Image hints (NSString* const) + pub static NSImageHintCTM: id; + pub static NSImageHintInterpolation: id; + + // System image names (NSString const*) + pub static NSImageNameQuickLookTemplate: id; + pub static NSImageNameBluetoothTemplate: id; + pub static NSImageNameIChatTheaterTemplate: id; + pub static NSImageNameSlideshowTemplate: id; + pub static NSImageNameActionTemplate: id; + pub static NSImageNameSmartBadgeTemplate: id; + pub static NSImageNamePathTemplate: id; + pub static NSImageNameInvalidDataFreestandingTemplate: id; + pub static NSImageNameLockLockedTemplate: id; + pub static NSImageNameLockUnlockedTemplate: id; + pub static NSImageNameGoRightTemplate: id; + pub static NSImageNameGoLeftTemplate: id; + pub static NSImageNameRightFacingTriangleTemplate: id; + pub static NSImageNameLeftFacingTriangleTemplate: id; + pub static NSImageNameAddTemplate: id; + pub static NSImageNameRemoveTemplate: id; + pub static NSImageNameRevealFreestandingTemplate: id; + pub static NSImageNameFollowLinkFreestandingTemplate: id; + pub static NSImageNameEnterFullScreenTemplate: id; + pub static NSImageNameExitFullScreenTemplate: id; + pub static NSImageNameStopProgressTemplate: id; + pub static NSImageNameStopProgressFreestandingTemplate: id; + pub static NSImageNameRefreshTemplate: id; + pub static NSImageNameRefreshFreestandingTemplate: id; + + pub static NSImageNameMultipleDocuments: id; + + pub static NSImageNameUser: id; + pub static NSImageNameUserGroup: id; + pub static NSImageNameEveryone: id; + pub static NSImageNameUserGuest: id; + + pub static NSImageNameBonjour: id; + pub static NSImageNameDotMac: id; + pub static NSImageNameComputer: id; + pub static NSImageNameFolderBurnable: id; + pub static NSImageNameFolderSmart: id; + pub static NSImageNameNetwork: id; + + pub static NSImageNameUserAccounts: id; + pub static NSImageNamePreferencesGeneral: id; + pub static NSImageNameAdvanced: id; + pub static NSImageNameInfo: id; + pub static NSImageNameFontPanel: id; + pub static NSImageNameColorPanel: id; + pub static NSImageNameFolder: id; + pub static NSImageNameTrashEmpty: id; + pub static NSImageNameTrashFull: id; + pub static NSImageNameHomeTemplate: id; + pub static NSImageNameBookmarksTemplate: id; + pub static NSImageNameCaution: id; + pub static NSImageNameStatusAvailable: id; + pub static NSImageNameStatusPartiallyAvailable: id; + pub static NSImageNameStatusUnavailable: id; + pub static NSImageNameStatusNone: id; + pub static NSImageNameApplicationIcon: id; + pub static NSImageNameMenuOnStateTemplate: id; + pub static NSImageNameMenuMixedStateTemplate: id; + pub static NSImageNameMobileMe: id; + + pub static NSImageNameIconViewTemplate: id; + pub static NSImageNameListViewTemplate: id; + pub static NSImageNameColumnViewTemplate: id; + pub static NSImageNameFlowViewTemplate: id; + pub static NSImageNameShareTemplate: id; +} + +#[repr(usize)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum NSCompositingOperation { + NSCompositeClear = 0, + NSCompositeCopy = 1, + NSCompositeSourceOver = 2, + NSCompositeSourceIn = 3, + NSCompositeSourceOut = 4, + NSCompositeSourceAtop = 5, + NSCompositeDestinationOver = 6, + NSCompositeDestinationIn = 7, + NSCompositeDestinationOut = 8, + NSCompositeDestinationAtop = 9, + NSCompositeXOR = 10, + NSCompositePlusDarker = 11, + NSCompositeHighlight = 12, + NSCompositePlusLighter = 13 +} + +#[repr(usize)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum NSImageCacheMode { + NSImageCacheDefault, + NSImageCacheAlways, + NSImageCacheBySize, + NSImageCacheNever +} + +#[repr(usize)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum NSTIFFCompression { + NSTIFFCompressionNone = 1, + NSTIFFCompressionCCITTFAX3 = 3, + NSTIFFCompressionCCITTFAX4 = 4, + NSTIFFCompressionLZW = 5, + NSTIFFCompressionJPEG = 6, + NSTIFFCompressionNEXT = 32766, + NSTIFFCompressionPackBits = 32773, + NSTIFFCompressionOldJPEG = 32865 +} + +#[repr(usize)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum NSImageLoadStatus { + NSImageLoadStatusCompleted, + NSImageLoadStatusCancelled, + NSImageLoadStatusInvalidData, + NSImageLoadStatusUnexpectedEOF, + NSImageLoadStatusReadError } pub trait NSSound {