Merge pull request #39 from DavidPartouche/NSScreen

NSScreen
This commit is contained in:
Brendan Zabarauskas
2014-11-18 00:04:27 +11:00
2 changed files with 21 additions and 1 deletions
+16 -1
View File
@@ -9,7 +9,7 @@
#![allow(non_upper_case_globals)]
use base::{id, msg_send, class, selector};
use base::{id, msg_send, msg_send_stret, class, selector};
use base::{SEL, NSInteger, NSUInteger};
use libc;
@@ -272,6 +272,8 @@ pub enum NSEventModifierFlags {
NSDeviceIndependentModifierFlagsMask = 0xffff0000,
}
pub static NSMainMenuWindowLevel: libc::int32_t = 24;
pub trait NSAutoreleasePool {
unsafe fn new(_: Self) -> id {
msg_send()(class("NSAutoreleasePool"), selector("new"))
@@ -927,3 +929,16 @@ impl NSEvent for id {
msg_send()(self, selector("modifierFlags"))
}
}
pub trait NSScreen {
unsafe fn mainScreen(_: Self) -> id {
msg_send()(class("NSScreen"), selector("mainScreen"))
}
unsafe fn frame(self) -> NSRect;
}
impl NSScreen for id {
unsafe fn frame(self) -> NSRect {
msg_send_stret()(self, selector("frame"))
}
}
+5
View File
@@ -46,6 +46,7 @@ extern {
-> Class;
pub fn objc_getClass(name: *const libc::c_char) -> id;
pub fn objc_msgSend(theReceiver: id, theSelector: SEL, ...) -> id;
pub fn objc_msgSend_stret(theReceiver: id, theSelector: SEL, ...);
pub fn objc_registerClassPair(cls: Class);
pub fn sel_registerName(name: *const libc::c_char) -> SEL;
}
@@ -55,6 +56,10 @@ pub unsafe fn msg_send<T>() -> extern fn(theReceiver: id, theSelector: SEL, ...)
mem::transmute(objc_msgSend)
}
pub unsafe fn msg_send_stret<T>() -> extern fn(theReceiver: id, theSelector: 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) -> id {