From a39122e02618bde882c48ed2e6fba66c2ffbabe0 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 27 Mar 2012 15:43:50 -0700 Subject: [PATCH 001/249] Initial commit --- appkit.rs | 6 ++++++ base.rs | 22 ++++++++++++++++++++++ cocoa.rc | 14 ++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 appkit.rs create mode 100644 base.rs create mode 100644 cocoa.rc diff --git a/appkit.rs b/appkit.rs new file mode 100644 index 0000000..1ef1132 --- /dev/null +++ b/appkit.rs @@ -0,0 +1,6 @@ +#[nolink] +#[link_args="-framework AppKit"] +native mod appkit { + fn NSBeep(); +} + diff --git a/base.rs b/base.rs new file mode 100644 index 0000000..8004d58 --- /dev/null +++ b/base.rs @@ -0,0 +1,22 @@ +use std; + +type id = libc::intptr_t; +type SEL = libc::intptr_t; + +const nil : id = 0 as id; + +native mod objc { + fn objc_getClass(name : *libc::c_char) -> id; + fn objc_msgSend(theReceiver : id, theSelector : SEL) -> id; + fn sel_registerName(name : *libc::c_char) -> SEL; +} + +#[test] +fn test_nsapp() { + let klass = str::as_c_str("NSApplication") { |s| objc::objc_getClass(s) }; + let sel = str::as_c_str("sharedApplication") { |s| objc::sel_registerName(s) }; + let nsapp = objc::objc_msgSend(klass, sel); + + io::println(#fmt("nsapp: %d", (nsapp as int))); +} + diff --git a/cocoa.rc b/cocoa.rc new file mode 100644 index 0000000..cbaa591 --- /dev/null +++ b/cocoa.rc @@ -0,0 +1,14 @@ +#[link(name = "cocoa", + vers = "0.1", + uuid = "5b7b7262-780d-465d-892c-15eab956dedc", + url = "http://github.com/pcwalton/cocoa")]; + +#[comment = "The Servo Parallel Browser Project"]; +#[license = "MIT"]; +#[crate_type = "lib"]; + +use std; + +mod appkit; +mod base; + From 837254a65e57581833f32fb2c2dbd339c5d22733 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 4 Apr 2012 19:48:53 -0700 Subject: [PATCH 002/249] NSApp testcase --- appkit.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/appkit.rs b/appkit.rs index 1ef1132..54a31b0 100644 --- a/appkit.rs +++ b/appkit.rs @@ -1,6 +1,14 @@ +import base::objc; + #[nolink] #[link_args="-framework AppKit"] native mod appkit { fn NSBeep(); } +fn NSApp() -> base::id { + let klass = str::as_c_str("NSApplication") { |s| objc::objc_getClass(s) }; + let sel = str::as_c_str("sharedApplication") { |s| objc::sel_registerName(s) }; + ret objc::objc_msgSend(klass, sel); +} + From 4ab5011d84ab431a86d85691b1d9cced941c216f Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 9 Apr 2012 16:42:46 -0700 Subject: [PATCH 003/249] Introduce stub Foundation support --- base.rs | 10 ++++++++-- cocoa.rc | 1 + foundation.rs | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 foundation.rs diff --git a/base.rs b/base.rs index 8004d58..8ad520f 100644 --- a/base.rs +++ b/base.rs @@ -13,8 +13,14 @@ native mod objc { #[test] fn test_nsapp() { - let klass = str::as_c_str("NSApplication") { |s| objc::objc_getClass(s) }; - let sel = str::as_c_str("sharedApplication") { |s| objc::sel_registerName(s) }; + let klass = str::as_c_str("NSApplication") { |s| + objc::objc_getClass(s) + }; + + let sel = str::as_c_str("sharedApplication") { |s| + objc::sel_registerName(s) + }; + let nsapp = objc::objc_msgSend(klass, sel); io::println(#fmt("nsapp: %d", (nsapp as int))); diff --git a/cocoa.rc b/cocoa.rc index cbaa591..16ebb76 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -11,4 +11,5 @@ use std; mod appkit; mod base; +mod foundation; diff --git a/foundation.rs b/foundation.rs new file mode 100644 index 0000000..b5b2d76 --- /dev/null +++ b/foundation.rs @@ -0,0 +1,23 @@ +import base::objc; + +#[nolink] +#[link_args="-framework Foundation"] +native mod foundation { +} + +enum NSAutoreleasePool { + NSAutoreleasePool_priv(base::id) +} + +fn NSAutoreleasePool() -> base::id { + let klass = str::as_c_str("NSAutoreleasePool") { |s| + objc::objc_getClass(s) + }; + + let alloc_sel = str::as_c_str("alloc") { |s| objc::sel_registerName(s) }; + let init_sel = str::as_c_str("init") { |s| objc::sel_registerName(s) }; + + let pool = objc::objc_msgSend(klass, alloc_sel); + ret objc::objc_msgSend(pool, init_sel); +} + From c1aa849cf5b5c9b667fbb9aafdfd4314eedd6bb4 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 9 Apr 2012 18:18:20 -0700 Subject: [PATCH 004/249] Add the ability to create classes and implement methods --- base.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/base.rs b/base.rs index 8ad520f..4d30981 100644 --- a/base.rs +++ b/base.rs @@ -1,13 +1,23 @@ use std; type id = libc::intptr_t; +type Class = libc::intptr_t; +type IMP = *u8; type SEL = libc::intptr_t; const nil : id = 0 as id; native mod objc { + fn class_addMethod(cls : Class, + name : SEL, + imp : IMP, + types : *libc::c_char) -> bool; + fn objc_allocateClassPair(superclass : Class, + name : *libc::c_char, + extraBytes : libc::size_t) -> Class; fn objc_getClass(name : *libc::c_char) -> id; fn objc_msgSend(theReceiver : id, theSelector : SEL) -> id; + fn objc_registerClassPair(cls : Class); fn sel_registerName(name : *libc::c_char) -> SEL; } @@ -26,3 +36,33 @@ fn test_nsapp() { io::println(#fmt("nsapp: %d", (nsapp as int))); } +#[test] +fn test_custom_obj() { + crust fn MyObject_doSomething(this : id, _sel : SEL) -> id { + io::println("doSomething"); + ret this; + } + + let NSObject = str::as_c_str("NSObject") { |s| + objc::objc_getClass(s) + }; + let MyObject = str::as_c_str("MyObject") { |s| + objc::objc_allocateClassPair(NSObject, s, 0 as libc::size_t) + }; + let doSomething = str::as_c_str("doSomething") { |s| + objc::sel_registerName(s) + }; + let _ = str::as_c_str("@@:") { |types| + objc::class_addMethod(MyObject, doSomething, MyObject_doSomething, + types) + }; + objc::objc_registerClassPair(MyObject); + + let alloc = str::as_c_str("alloc") { |s| objc::sel_registerName(s) }; + let init = str::as_c_str("init") { |s| objc::sel_registerName(s) }; + + let mut obj = objc::objc_msgSend(MyObject, alloc); + obj = objc::objc_msgSend(obj, init); + objc::objc_msgSend(obj, doSomething); +} + From da80902a003eb141eeb5c79621b87573338872c7 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 18 Apr 2012 15:24:45 -0700 Subject: [PATCH 005/249] Various hackage for servo integration --- .gitignore | 9 +++++++++ Makefile | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d62b97d --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*~ +*# +*.o +*.so +*.dylib +*.dSYM +*.dll +*.dummy +cocoa-test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f588b6c --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +RUSTC ?= rustc +RUSTFLAGS ?= + +RUST_SRC = $(shell find . -type f -name '*.rs') + +.PHONY: all +all: libcocoa.dummy + +libcocoa.dummy: cocoa.rc $(RUST_SRC) + $(RUSTC) $(RUSTFLAGS) $< -o $@ + touch $@ + +cocoa-test: cocoa.rc $(RUST_SRC) + $(RUSTC) $(RUSTFLAGS) $< -o $@ --test + +check: cocoa-test + ./cocoa-test + +.PHONY: clean +clean: + rm -f cocoa-test *.so *.dylib *.dll *.dummy From 0f0f4aeff308b95b356ac35ed8cce532100c4560 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 18 Apr 2012 19:14:58 -0700 Subject: [PATCH 006/249] Add msgSend1Id wrapper method for msgSend --- .gitignore | 1 + Makefile | 14 +++++++++++--- cocoa.rc | 1 - cocoa.rs | 10 ++++++++++ msgsend.c | 11 +++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 cocoa.rs create mode 100644 msgsend.c diff --git a/.gitignore b/.gitignore index d62b97d..ef1d883 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *~ *# *.o +*.a *.so *.dylib *.dSYM diff --git a/Makefile b/Makefile index f588b6c..2471ee3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ +CC ?= gcc RUSTC ?= rustc +AR ?= ar RUSTFLAGS ?= RUST_SRC = $(shell find . -type f -name '*.rs') @@ -6,16 +8,22 @@ RUST_SRC = $(shell find . -type f -name '*.rs') .PHONY: all all: libcocoa.dummy -libcocoa.dummy: cocoa.rc $(RUST_SRC) +libcocoa.dummy: cocoa.rc $(RUST_SRC) libmsgsend.a $(RUSTC) $(RUSTFLAGS) $< -o $@ touch $@ -cocoa-test: cocoa.rc $(RUST_SRC) +cocoa-test: cocoa.rc $(RUST_SRC) libmsgsend.a $(RUSTC) $(RUSTFLAGS) $< -o $@ --test +libmsgsend.a: msgsend.o + $(AR) rcs libmsgsend.a msgsend.o + +msgsend.o: msgsend.c + $(CC) $< -o $@ -c + check: cocoa-test ./cocoa-test .PHONY: clean clean: - rm -f cocoa-test *.so *.dylib *.dll *.dummy + rm -f cocoa-test *.a *.o *.so *.dylib *.dll *.dummy diff --git a/cocoa.rc b/cocoa.rc index 16ebb76..ad3d0b2 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -12,4 +12,3 @@ use std; mod appkit; mod base; mod foundation; - diff --git a/cocoa.rs b/cocoa.rs new file mode 100644 index 0000000..c3ccc37 --- /dev/null +++ b/cocoa.rs @@ -0,0 +1,10 @@ + +fn msgSend1Id(theReceiver: base::id, theSelector: base::SEL, id: base::id) { + msgsend::msgSend1IdHACK(theReceiver, theSelector, id); +} + +#[link_args = "-L . -lmsgsend"] +#[nolink] +native mod msgsend { + fn msgSend1IdHACK(theReceiver: base::id, theSelector: base::SEL, id: base::id); +} diff --git a/msgsend.c b/msgsend.c new file mode 100644 index 0000000..ee2a586 --- /dev/null +++ b/msgsend.c @@ -0,0 +1,11 @@ +#include +#include + +void +msgSend1IdHACK(id theReceiver, SEL theSender, id id) { + printf("msgSend1IdHACK\n"); + printf("%ld\n", theReceiver); + printf("%ld\n", theSender); + printf("%ld\n", id); + objc_msgSend(theReceiver, theSender, id); +} From 9a43115ca9f5309543f0646252a3d420fdd40628 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 18 Apr 2012 19:25:01 -0700 Subject: [PATCH 007/249] Remove some debug logging --- msgsend.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/msgsend.c b/msgsend.c index ee2a586..a803f78 100644 --- a/msgsend.c +++ b/msgsend.c @@ -3,9 +3,5 @@ void msgSend1IdHACK(id theReceiver, SEL theSender, id id) { - printf("msgSend1IdHACK\n"); - printf("%ld\n", theReceiver); - printf("%ld\n", theSender); - printf("%ld\n", id); objc_msgSend(theReceiver, theSender, id); } From ee0008f3e3adc815d45130d79d7d5d6d64d3a40b Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 23 Apr 2012 15:42:22 -0700 Subject: [PATCH 008/249] More bindings --- base.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/base.rs b/base.rs index 4d30981..d0b1ec6 100644 --- a/base.rs +++ b/base.rs @@ -4,6 +4,7 @@ type id = libc::intptr_t; type Class = libc::intptr_t; type IMP = *u8; type SEL = libc::intptr_t; +type Ivar = libc::intptr_t; const nil : id = 0 as id; @@ -12,6 +13,17 @@ native mod objc { name : SEL, imp : IMP, types : *libc::c_char) -> bool; + fn class_addIvar(cls : Class, + name : *libc::c_char, + size : libc::size_t, + alignment: u8, + types: *libc::c_char) -> bool; + fn object_setInstanceVariable(obj : id, + name : *libc::c_char, + value : *libc::c_void); + fn object_getInstanceVariable(obj : id, + name : *libc::c_char, + outValue : **libc::c_void); fn objc_allocateClassPair(superclass : Class, name : *libc::c_char, extraBytes : libc::size_t) -> Class; From 366431264d713b9587fdd4e7e57e4e2afe7f3160 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 3 May 2012 16:08:55 -0700 Subject: [PATCH 009/249] -L., not -L . --- cocoa.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocoa.rs b/cocoa.rs index c3ccc37..0275e83 100644 --- a/cocoa.rs +++ b/cocoa.rs @@ -3,7 +3,7 @@ fn msgSend1Id(theReceiver: base::id, theSelector: base::SEL, id: base::id) { msgsend::msgSend1IdHACK(theReceiver, theSelector, id); } -#[link_args = "-L . -lmsgsend"] +#[link_args = "-L. -lmsgsend"] #[nolink] native mod msgsend { fn msgSend1IdHACK(theReceiver: base::id, theSelector: base::SEL, id: base::id); From 6652463211a99704dda956a0fbe0f42bcfb76987 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 5 May 2012 15:00:31 -0700 Subject: [PATCH 010/249] Support out-of-tree builds --- .gitignore | 1 + Makefile => Makefile.in | 4 +++- configure | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) rename Makefile => Makefile.in (86%) create mode 100644 configure diff --git a/.gitignore b/.gitignore index ef1d883..5f68b7f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ *.dll *.dummy cocoa-test +build diff --git a/Makefile b/Makefile.in similarity index 86% rename from Makefile rename to Makefile.in index 2471ee3..69a0f60 100644 --- a/Makefile +++ b/Makefile.in @@ -1,9 +1,11 @@ +VPATH=%VPATH% + CC ?= gcc RUSTC ?= rustc AR ?= ar RUSTFLAGS ?= -RUST_SRC = $(shell find . -type f -name '*.rs') +RUST_SRC = $(shell find $(VPATH)/. -type f -name '*.rs') .PHONY: all all: libcocoa.dummy diff --git a/configure b/configure new file mode 100644 index 0000000..8c2715b --- /dev/null +++ b/configure @@ -0,0 +1,3 @@ +#!/bin/bash + +sed "s/%VPATH%/`dirname $0`/" `dirname $0`/Makefile.in > Makefile From d529e0802bf40bc8c0bd2015c7877cceb387b073 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 5 May 2012 15:11:08 -0700 Subject: [PATCH 011/249] Make configure executable --- configure | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 configure diff --git a/configure b/configure old mode 100644 new mode 100755 From cff7503084162cc68598e059fa46ec634bc994fe Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 5 May 2012 15:26:05 -0700 Subject: [PATCH 012/249] More build fixes --- configure | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 8c2715b..62a0f4c 100755 --- a/configure +++ b/configure @@ -1,3 +1,4 @@ #!/bin/bash -sed "s/%VPATH%/`dirname $0`/" `dirname $0`/Makefile.in > Makefile +SRCDIR="$(cd $(dirname $0) && pwd)" +sed "s#%VPATH%#${SRCDIR}#" ${SRCDIR}/Makefile.in > Makefile From 478f61bb68feea43c22c9b88f52393ea15908dae Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 31 May 2012 15:26:15 -0700 Subject: [PATCH 013/249] Add some CoreGraphics bindings --- cg.rs | 19 +++++++++++++++++++ cocoa.rc | 1 + 2 files changed, 20 insertions(+) create mode 100644 cg.rs diff --git a/cg.rs b/cg.rs new file mode 100644 index 0000000..0634ed3 --- /dev/null +++ b/cg.rs @@ -0,0 +1,19 @@ +// FIXME: Should be bindgenned + +import libc::{c_void, c_char, size_t}; + +#[nolink] +native mod cg { + fn CGDataProviderCreateWithFilename(filename: *c_char) -> CGDataProviderRef; + fn CGDataProviderCreateWithData(info: *c_void, + data: *c_void, + size: size_t, + releaseData: CGDataProviderReleaseDataCallback + ) -> CGDataProviderRef; + fn CGDataProviderRelease(provider: CGDataProviderRef); + fn CGFontCreateWithDataProvider(provider: CGDataProviderRef) -> CGFontRef; +} + +type CGFontRef = *c_void; +type CGDataProviderRef = *c_void; +type CGDataProviderReleaseDataCallback = *c_void; \ No newline at end of file diff --git a/cocoa.rc b/cocoa.rc index ad3d0b2..dba06c0 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -12,3 +12,4 @@ use std; mod appkit; mod base; mod foundation; +mod cg; \ No newline at end of file From a326b982dfde133ea558a1025deb9c14d88265d2 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 16 Jun 2012 18:17:40 -0700 Subject: [PATCH 014/249] Add binding for CGFontRelease --- cg.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cg.rs b/cg.rs index 0634ed3..94409db 100644 --- a/cg.rs +++ b/cg.rs @@ -12,6 +12,7 @@ native mod cg { ) -> CGDataProviderRef; fn CGDataProviderRelease(provider: CGDataProviderRef); fn CGFontCreateWithDataProvider(provider: CGDataProviderRef) -> CGFontRef; + fn CGFontRelease(font: CGFontRef); } type CGFontRef = *c_void; From 2764790c7956b789af13f35568f3096b698cb501 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 4 Jul 2012 17:19:04 -0400 Subject: [PATCH 015/249] Update for recent rust syntax changes. --- appkit.rs | 6 +++--- base.rs | 32 ++++++++++++++++---------------- cg.rs | 2 +- cocoa.rs | 2 +- foundation.rs | 10 +++++----- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/appkit.rs b/appkit.rs index 54a31b0..3eae4dc 100644 --- a/appkit.rs +++ b/appkit.rs @@ -2,13 +2,13 @@ import base::objc; #[nolink] #[link_args="-framework AppKit"] -native mod appkit { +extern mod appkit { fn NSBeep(); } fn NSApp() -> base::id { - let klass = str::as_c_str("NSApplication") { |s| objc::objc_getClass(s) }; - let sel = str::as_c_str("sharedApplication") { |s| objc::sel_registerName(s) }; + let klass = str::as_c_str("NSApplication", |s| objc::objc_getClass(s)); + let sel = str::as_c_str("sharedApplication", |s| objc::sel_registerName(s)); ret objc::objc_msgSend(klass, sel); } diff --git a/base.rs b/base.rs index d0b1ec6..f25f2e6 100644 --- a/base.rs +++ b/base.rs @@ -8,7 +8,7 @@ type Ivar = libc::intptr_t; const nil : id = 0 as id; -native mod objc { +extern mod objc { fn class_addMethod(cls : Class, name : SEL, imp : IMP, @@ -35,13 +35,13 @@ native mod objc { #[test] fn test_nsapp() { - let klass = str::as_c_str("NSApplication") { |s| + let klass = str::as_c_str("NSApplication", |s| objc::objc_getClass(s) - }; + ); - let sel = str::as_c_str("sharedApplication") { |s| + let sel = str::as_c_str("sharedApplication", |s| objc::sel_registerName(s) - }; + ); let nsapp = objc::objc_msgSend(klass, sel); @@ -50,28 +50,28 @@ fn test_nsapp() { #[test] fn test_custom_obj() { - crust fn MyObject_doSomething(this : id, _sel : SEL) -> id { + extern fn MyObject_doSomething(this : id, _sel : SEL) -> id { io::println("doSomething"); ret this; } - let NSObject = str::as_c_str("NSObject") { |s| + let NSObject = str::as_c_str("NSObject", |s| objc::objc_getClass(s) - }; - let MyObject = str::as_c_str("MyObject") { |s| + ); + let MyObject = str::as_c_str("MyObject", |s| objc::objc_allocateClassPair(NSObject, s, 0 as libc::size_t) - }; - let doSomething = str::as_c_str("doSomething") { |s| + ); + let doSomething = str::as_c_str("doSomething", |s| objc::sel_registerName(s) - }; - let _ = str::as_c_str("@@:") { |types| + ); + let _ = str::as_c_str("@@:", |types| objc::class_addMethod(MyObject, doSomething, MyObject_doSomething, types) - }; + ); objc::objc_registerClassPair(MyObject); - let alloc = str::as_c_str("alloc") { |s| objc::sel_registerName(s) }; - let init = str::as_c_str("init") { |s| objc::sel_registerName(s) }; + let alloc = str::as_c_str("alloc", |s| objc::sel_registerName(s)); + let init = str::as_c_str("init", |s| objc::sel_registerName(s)); let mut obj = objc::objc_msgSend(MyObject, alloc); obj = objc::objc_msgSend(obj, init); diff --git a/cg.rs b/cg.rs index 94409db..055f4d9 100644 --- a/cg.rs +++ b/cg.rs @@ -3,7 +3,7 @@ import libc::{c_void, c_char, size_t}; #[nolink] -native mod cg { +extern mod cg { fn CGDataProviderCreateWithFilename(filename: *c_char) -> CGDataProviderRef; fn CGDataProviderCreateWithData(info: *c_void, data: *c_void, diff --git a/cocoa.rs b/cocoa.rs index 0275e83..8e65e03 100644 --- a/cocoa.rs +++ b/cocoa.rs @@ -5,6 +5,6 @@ fn msgSend1Id(theReceiver: base::id, theSelector: base::SEL, id: base::id) { #[link_args = "-L. -lmsgsend"] #[nolink] -native mod msgsend { +extern mod msgsend { fn msgSend1IdHACK(theReceiver: base::id, theSelector: base::SEL, id: base::id); } diff --git a/foundation.rs b/foundation.rs index b5b2d76..650d1a1 100644 --- a/foundation.rs +++ b/foundation.rs @@ -2,7 +2,7 @@ import base::objc; #[nolink] #[link_args="-framework Foundation"] -native mod foundation { +extern mod foundation { } enum NSAutoreleasePool { @@ -10,12 +10,12 @@ enum NSAutoreleasePool { } fn NSAutoreleasePool() -> base::id { - let klass = str::as_c_str("NSAutoreleasePool") { |s| + let klass = str::as_c_str("NSAutoreleasePool", |s| objc::objc_getClass(s) - }; + ); - let alloc_sel = str::as_c_str("alloc") { |s| objc::sel_registerName(s) }; - let init_sel = str::as_c_str("init") { |s| objc::sel_registerName(s) }; + let alloc_sel = str::as_c_str("alloc", |s| objc::sel_registerName(s)); + let init_sel = str::as_c_str("init", |s| objc::sel_registerName(s)); let pool = objc::objc_msgSend(klass, alloc_sel); ret objc::objc_msgSend(pool, init_sel); From eef4feecb4f9446acbcec7599ea653ab7bbb854f Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 19 Jul 2012 10:22:43 -0700 Subject: [PATCH 016/249] Fix strings --- appkit.rs | 4 ++-- foundation.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/appkit.rs b/appkit.rs index 3eae4dc..9ddb5f6 100644 --- a/appkit.rs +++ b/appkit.rs @@ -7,8 +7,8 @@ extern mod appkit { } fn NSApp() -> base::id { - let klass = str::as_c_str("NSApplication", |s| objc::objc_getClass(s)); - let sel = str::as_c_str("sharedApplication", |s| objc::sel_registerName(s)); + let klass = str::as_c_str(~"NSApplication", |s| objc::objc_getClass(s)); + let sel = str::as_c_str(~"sharedApplication", |s| objc::sel_registerName(s)); ret objc::objc_msgSend(klass, sel); } diff --git a/foundation.rs b/foundation.rs index 650d1a1..243e08f 100644 --- a/foundation.rs +++ b/foundation.rs @@ -10,12 +10,12 @@ enum NSAutoreleasePool { } fn NSAutoreleasePool() -> base::id { - let klass = str::as_c_str("NSAutoreleasePool", |s| + let klass = str::as_c_str(~"NSAutoreleasePool", |s| objc::objc_getClass(s) ); - let alloc_sel = str::as_c_str("alloc", |s| objc::sel_registerName(s)); - let init_sel = str::as_c_str("init", |s| objc::sel_registerName(s)); + let alloc_sel = str::as_c_str(~"alloc", |s| objc::sel_registerName(s)); + let init_sel = str::as_c_str(~"init", |s| objc::sel_registerName(s)); let pool = objc::objc_msgSend(klass, alloc_sel); ret objc::objc_msgSend(pool, init_sel); From b2350cf5b339c1fabce7d66486255df4e97881cc Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sat, 21 Jul 2012 08:01:29 -0700 Subject: [PATCH 017/249] Fix syntax in tests --- base.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/base.rs b/base.rs index f25f2e6..c986dec 100644 --- a/base.rs +++ b/base.rs @@ -35,17 +35,17 @@ extern mod objc { #[test] fn test_nsapp() { - let klass = str::as_c_str("NSApplication", |s| + let klass = str::as_c_str(~"NSApplication", |s| objc::objc_getClass(s) ); - let sel = str::as_c_str("sharedApplication", |s| + let sel = str::as_c_str(~"sharedApplication", |s| objc::sel_registerName(s) ); let nsapp = objc::objc_msgSend(klass, sel); - io::println(#fmt("nsapp: %d", (nsapp as int))); + io::println(#fmt(~"nsapp: %d", (nsapp as int))); } #[test] @@ -55,23 +55,23 @@ fn test_custom_obj() { ret this; } - let NSObject = str::as_c_str("NSObject", |s| + let NSObject = str::as_c_str(~"NSObject", |s| objc::objc_getClass(s) ); - let MyObject = str::as_c_str("MyObject", |s| + let MyObject = str::as_c_str(~"MyObject", |s| objc::objc_allocateClassPair(NSObject, s, 0 as libc::size_t) ); - let doSomething = str::as_c_str("doSomething", |s| + let doSomething = str::as_c_str(~"doSomething", |s| objc::sel_registerName(s) ); - let _ = str::as_c_str("@@:", |types| + let _ = str::as_c_str(~"@@:", |types| objc::class_addMethod(MyObject, doSomething, MyObject_doSomething, types) ); objc::objc_registerClassPair(MyObject); - let alloc = str::as_c_str("alloc", |s| objc::sel_registerName(s)); - let init = str::as_c_str("init", |s| objc::sel_registerName(s)); + let alloc = str::as_c_str(~"alloc", |s| objc::sel_registerName(s)); + let init = str::as_c_str(~"init", |s| objc::sel_registerName(s)); let mut obj = objc::objc_msgSend(MyObject, alloc); obj = objc::objc_msgSend(obj, init); From 02a70fd86daa067dbe50ee3a6de343470cb6d2e6 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sat, 21 Jul 2012 09:17:04 -0700 Subject: [PATCH 018/249] Fix botched fmt --- base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base.rs b/base.rs index c986dec..ead4fc9 100644 --- a/base.rs +++ b/base.rs @@ -45,7 +45,7 @@ fn test_nsapp() { let nsapp = objc::objc_msgSend(klass, sel); - io::println(#fmt(~"nsapp: %d", (nsapp as int))); + io::println(#fmt("nsapp: %d", (nsapp as int))); } #[test] From c9d18ab67e0862c5f5f500000faf6f544c1a4de4 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Sat, 21 Jul 2012 09:29:56 -0700 Subject: [PATCH 019/249] Fix ~ --- base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base.rs b/base.rs index ead4fc9..08441ce 100644 --- a/base.rs +++ b/base.rs @@ -51,7 +51,7 @@ fn test_nsapp() { #[test] fn test_custom_obj() { extern fn MyObject_doSomething(this : id, _sel : SEL) -> id { - io::println("doSomething"); + io::println(~"doSomething"); ret this; } From 715dc9d33a94f172686adac4f31257448a81009a Mon Sep 17 00:00:00 2001 From: Donovan Preston Date: Tue, 7 Aug 2012 08:17:57 -0400 Subject: [PATCH 020/249] Change ret to return to get it to compile again. --- appkit.rs | 2 +- base.rs | 2 +- foundation.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/appkit.rs b/appkit.rs index 9ddb5f6..40306d9 100644 --- a/appkit.rs +++ b/appkit.rs @@ -9,6 +9,6 @@ extern mod appkit { fn NSApp() -> base::id { let klass = str::as_c_str(~"NSApplication", |s| objc::objc_getClass(s)); let sel = str::as_c_str(~"sharedApplication", |s| objc::sel_registerName(s)); - ret objc::objc_msgSend(klass, sel); + return objc::objc_msgSend(klass, sel); } diff --git a/base.rs b/base.rs index 08441ce..971bb57 100644 --- a/base.rs +++ b/base.rs @@ -52,7 +52,7 @@ fn test_nsapp() { fn test_custom_obj() { extern fn MyObject_doSomething(this : id, _sel : SEL) -> id { io::println(~"doSomething"); - ret this; + return this; } let NSObject = str::as_c_str(~"NSObject", |s| diff --git a/foundation.rs b/foundation.rs index 243e08f..1e1c133 100644 --- a/foundation.rs +++ b/foundation.rs @@ -18,6 +18,6 @@ fn NSAutoreleasePool() -> base::id { let init_sel = str::as_c_str(~"init", |s| objc::sel_registerName(s)); let pool = objc::objc_msgSend(klass, alloc_sel); - ret objc::objc_msgSend(pool, init_sel); + return objc::objc_msgSend(pool, init_sel); } From 8a44a579cf421b6bc7a97b1c1e81bd9ede5d84a4 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Tue, 11 Sep 2012 14:54:04 -0700 Subject: [PATCH 021/249] s/import/use/g; fix class method syntax --- appkit.rs | 2 +- cg.rs | 2 +- foundation.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/appkit.rs b/appkit.rs index 40306d9..c1b9529 100644 --- a/appkit.rs +++ b/appkit.rs @@ -1,4 +1,4 @@ -import base::objc; +use base::objc; #[nolink] #[link_args="-framework AppKit"] diff --git a/cg.rs b/cg.rs index 055f4d9..5d2185e 100644 --- a/cg.rs +++ b/cg.rs @@ -1,6 +1,6 @@ // FIXME: Should be bindgenned -import libc::{c_void, c_char, size_t}; +use libc::{c_void, c_char, size_t}; #[nolink] extern mod cg { diff --git a/foundation.rs b/foundation.rs index 1e1c133..1b6015d 100644 --- a/foundation.rs +++ b/foundation.rs @@ -1,4 +1,4 @@ -import base::objc; +use base::objc; #[nolink] #[link_args="-framework Foundation"] From 5019635e3f44851c08716bd44b70229b2d625aa7 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 13 Sep 2012 16:18:28 -0700 Subject: [PATCH 022/249] Fixes for language changes --- cocoa.rc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocoa.rc b/cocoa.rc index dba06c0..6d72732 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -7,9 +7,9 @@ #[license = "MIT"]; #[crate_type = "lib"]; -use std; +extern mod std; mod appkit; mod base; mod foundation; -mod cg; \ No newline at end of file +mod cg; From c68809f9e959c285f53cab6746fc36251c67284b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 27 Sep 2012 10:21:52 -0700 Subject: [PATCH 023/249] De-export --- appkit.rs | 4 ++-- base.rs | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/appkit.rs b/appkit.rs index c1b9529..6a75dfe 100644 --- a/appkit.rs +++ b/appkit.rs @@ -2,11 +2,11 @@ use base::objc; #[nolink] #[link_args="-framework AppKit"] -extern mod appkit { +pub extern mod appkit { fn NSBeep(); } -fn NSApp() -> base::id { +pub fn NSApp() -> base::id { let klass = str::as_c_str(~"NSApplication", |s| objc::objc_getClass(s)); let sel = str::as_c_str(~"sharedApplication", |s| objc::sel_registerName(s)); return objc::objc_msgSend(klass, sel); diff --git a/base.rs b/base.rs index 971bb57..fde4100 100644 --- a/base.rs +++ b/base.rs @@ -1,14 +1,14 @@ use std; -type id = libc::intptr_t; -type Class = libc::intptr_t; -type IMP = *u8; -type SEL = libc::intptr_t; -type Ivar = libc::intptr_t; +pub type id = libc::intptr_t; +pub type Class = libc::intptr_t; +pub type IMP = *u8; +pub type SEL = libc::intptr_t; +pub type Ivar = libc::intptr_t; -const nil : id = 0 as id; +pub const nil : id = 0 as id; -extern mod objc { +pub extern mod objc { fn class_addMethod(cls : Class, name : SEL, imp : IMP, @@ -17,7 +17,7 @@ extern mod objc { name : *libc::c_char, size : libc::size_t, alignment: u8, - types: *libc::c_char) -> bool; + types: *libc::c_char) -> bool; fn object_setInstanceVariable(obj : id, name : *libc::c_char, value : *libc::c_void); @@ -34,7 +34,7 @@ extern mod objc { } #[test] -fn test_nsapp() { +pub fn test_nsapp() { let klass = str::as_c_str(~"NSApplication", |s| objc::objc_getClass(s) ); @@ -49,7 +49,7 @@ fn test_nsapp() { } #[test] -fn test_custom_obj() { +pub fn test_custom_obj() { extern fn MyObject_doSomething(this : id, _sel : SEL) -> id { io::println(~"doSomething"); return this; From 15ff4a2fb4a0cd9ab18c714528eb5d4d65bb8008 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 27 Sep 2012 10:21:52 -0700 Subject: [PATCH 024/249] De-export more --- cg.rs | 24 ++++++++++++------------ cocoa.rc | 8 ++++---- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cg.rs b/cg.rs index 5d2185e..a7258ca 100644 --- a/cg.rs +++ b/cg.rs @@ -4,17 +4,17 @@ use libc::{c_void, c_char, size_t}; #[nolink] extern mod cg { - fn CGDataProviderCreateWithFilename(filename: *c_char) -> CGDataProviderRef; - fn CGDataProviderCreateWithData(info: *c_void, - data: *c_void, - size: size_t, - releaseData: CGDataProviderReleaseDataCallback - ) -> CGDataProviderRef; - fn CGDataProviderRelease(provider: CGDataProviderRef); - fn CGFontCreateWithDataProvider(provider: CGDataProviderRef) -> CGFontRef; - fn CGFontRelease(font: CGFontRef); + pub fn CGDataProviderCreateWithFilename(filename: *c_char) -> CGDataProviderRef; + pub fn CGDataProviderCreateWithData(info: *c_void, + data: *c_void, + size: size_t, + releaseData: CGDataProviderReleaseDataCallback + ) -> CGDataProviderRef; + pub fn CGDataProviderRelease(provider: CGDataProviderRef); + pub fn CGFontCreateWithDataProvider(provider: CGDataProviderRef) -> CGFontRef; + pub fn CGFontRelease(font: CGFontRef); } -type CGFontRef = *c_void; -type CGDataProviderRef = *c_void; -type CGDataProviderReleaseDataCallback = *c_void; \ No newline at end of file +pub type CGFontRef = *c_void; +pub type CGDataProviderRef = *c_void; +pub type CGDataProviderReleaseDataCallback = *c_void; diff --git a/cocoa.rc b/cocoa.rc index 6d72732..072e5f1 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -9,7 +9,7 @@ extern mod std; -mod appkit; -mod base; -mod foundation; -mod cg; +pub mod appkit; +pub mod base; +pub mod foundation; +pub mod cg; From 7dff0d5d6dc40e53989f0db94df74be79bda91c9 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 4 Oct 2012 15:23:09 -0700 Subject: [PATCH 025/249] Update for language changes --- cg.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cg.rs b/cg.rs index a7258ca..2495b60 100644 --- a/cg.rs +++ b/cg.rs @@ -3,7 +3,7 @@ use libc::{c_void, c_char, size_t}; #[nolink] -extern mod cg { +pub extern mod cg { pub fn CGDataProviderCreateWithFilename(filename: *c_char) -> CGDataProviderRef; pub fn CGDataProviderCreateWithData(info: *c_void, data: *c_void, From 0503ea12c3bfa33a829b9c9c309fac471663e185 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Fri, 19 Oct 2012 13:28:17 -0700 Subject: [PATCH 026/249] Remove CG from rust-cocoa. It's now in rust-core-graphics. --- cg.rs | 20 -------------------- cocoa.rc | 2 +- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 cg.rs diff --git a/cg.rs b/cg.rs deleted file mode 100644 index 2495b60..0000000 --- a/cg.rs +++ /dev/null @@ -1,20 +0,0 @@ -// FIXME: Should be bindgenned - -use libc::{c_void, c_char, size_t}; - -#[nolink] -pub extern mod cg { - pub fn CGDataProviderCreateWithFilename(filename: *c_char) -> CGDataProviderRef; - pub fn CGDataProviderCreateWithData(info: *c_void, - data: *c_void, - size: size_t, - releaseData: CGDataProviderReleaseDataCallback - ) -> CGDataProviderRef; - pub fn CGDataProviderRelease(provider: CGDataProviderRef); - pub fn CGFontCreateWithDataProvider(provider: CGDataProviderRef) -> CGFontRef; - pub fn CGFontRelease(font: CGFontRef); -} - -pub type CGFontRef = *c_void; -pub type CGDataProviderRef = *c_void; -pub type CGDataProviderReleaseDataCallback = *c_void; diff --git a/cocoa.rc b/cocoa.rc index 072e5f1..7ddf26f 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -12,4 +12,4 @@ extern mod std; pub mod appkit; pub mod base; pub mod foundation; -pub mod cg; + From 20a8547fdc8a2f1d64f2b33b56335262335bba0e Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 1 Nov 2012 18:58:05 -0700 Subject: [PATCH 027/249] Include CFLAGS --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 69a0f60..3e14b39 100644 --- a/Makefile.in +++ b/Makefile.in @@ -21,7 +21,7 @@ libmsgsend.a: msgsend.o $(AR) rcs libmsgsend.a msgsend.o msgsend.o: msgsend.c - $(CC) $< -o $@ -c + $(CC) $(CFLAGS) $< -o $@ -c check: cocoa-test ./cocoa-test From 8366d38b751fa1952ebe85c531c5249d3439a339 Mon Sep 17 00:00:00 2001 From: "Brian J. Burg" Date: Thu, 8 Nov 2012 10:53:02 -0800 Subject: [PATCH 028/249] 'make check' should remove test products. --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 3e14b39..28a11c7 100644 --- a/Makefile.in +++ b/Makefile.in @@ -28,4 +28,4 @@ check: cocoa-test .PHONY: clean clean: - rm -f cocoa-test *.a *.o *.so *.dylib *.dll *.dummy + rm -f cocoa-test *.a *.o *.so *.dylib *.dll *.dummy cocoa-test From e4afef45bb91bf78589b3f02f4ee0411f85d86c5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 13 Dec 2012 18:38:36 -0800 Subject: [PATCH 029/249] Update for language changes --- base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base.rs b/base.rs index fde4100..107158a 100644 --- a/base.rs +++ b/base.rs @@ -45,7 +45,7 @@ pub fn test_nsapp() { let nsapp = objc::objc_msgSend(klass, sel); - io::println(#fmt("nsapp: %d", (nsapp as int))); + io::println(fmt!("nsapp: %d", (nsapp as int))); } #[test] From b108b2b8d4a53ef1d9720dfc484b971d19f9817d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 20 Jan 2013 18:50:06 -0800 Subject: [PATCH 030/249] Rust upgrade --- appkit.rs | 1 + foundation.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/appkit.rs b/appkit.rs index 6a75dfe..56a694d 100644 --- a/appkit.rs +++ b/appkit.rs @@ -1,4 +1,5 @@ use base::objc; +use base; #[nolink] #[link_args="-framework AppKit"] diff --git a/foundation.rs b/foundation.rs index 1b6015d..16ddada 100644 --- a/foundation.rs +++ b/foundation.rs @@ -1,4 +1,5 @@ use base::objc; +use base; #[nolink] #[link_args="-framework Foundation"] From c6dc3d8b0a3b94b7134213a4d01599484d4a8927 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 30 Jan 2013 14:33:03 -0800 Subject: [PATCH 031/249] Rust upgrade --- appkit.rs | 6 +++--- foundation.rs | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/appkit.rs b/appkit.rs index 56a694d..052c98e 100644 --- a/appkit.rs +++ b/appkit.rs @@ -8,8 +8,8 @@ pub extern mod appkit { } pub fn NSApp() -> base::id { - let klass = str::as_c_str(~"NSApplication", |s| objc::objc_getClass(s)); - let sel = str::as_c_str(~"sharedApplication", |s| objc::sel_registerName(s)); - return objc::objc_msgSend(klass, sel); + let klass = str::as_c_str(~"NSApplication", |s| unsafe { objc::objc_getClass(s) } ); + let sel = str::as_c_str(~"sharedApplication", |s| unsafe { objc::sel_registerName(s) } ); + return unsafe { objc::objc_msgSend(klass, sel) }; } diff --git a/foundation.rs b/foundation.rs index 16ddada..ae4b0d7 100644 --- a/foundation.rs +++ b/foundation.rs @@ -11,14 +11,16 @@ enum NSAutoreleasePool { } fn NSAutoreleasePool() -> base::id { - let klass = str::as_c_str(~"NSAutoreleasePool", |s| + let klass = str::as_c_str(~"NSAutoreleasePool", |s| unsafe { objc::objc_getClass(s) - ); + }); - let alloc_sel = str::as_c_str(~"alloc", |s| objc::sel_registerName(s)); - let init_sel = str::as_c_str(~"init", |s| objc::sel_registerName(s)); + let alloc_sel = str::as_c_str(~"alloc", |s| unsafe { objc::sel_registerName(s) } ); + let init_sel = str::as_c_str(~"init", |s| unsafe { objc::sel_registerName(s) } ); - let pool = objc::objc_msgSend(klass, alloc_sel); - return objc::objc_msgSend(pool, init_sel); + unsafe { + let pool = objc::objc_msgSend(klass, alloc_sel); + return objc::objc_msgSend(pool, init_sel); + } } From bf9e050161c55ce06f8e7491e15ceff06079d937 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 7 Feb 2013 12:12:07 -0800 Subject: [PATCH 032/249] Update for language changes --- appkit.rs | 8 +++++--- foundation.rs | 16 ++++++++-------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/appkit.rs b/appkit.rs index 052c98e..b4ad91a 100644 --- a/appkit.rs +++ b/appkit.rs @@ -8,8 +8,10 @@ pub extern mod appkit { } pub fn NSApp() -> base::id { - let klass = str::as_c_str(~"NSApplication", |s| unsafe { objc::objc_getClass(s) } ); - let sel = str::as_c_str(~"sharedApplication", |s| unsafe { objc::sel_registerName(s) } ); - return unsafe { objc::objc_msgSend(klass, sel) }; + unsafe { + let klass = str::as_c_str(~"NSApplication", |s| objc::objc_getClass(s)); + let sel = str::as_c_str(~"sharedApplication", |s| objc::sel_registerName(s)); + objc::objc_msgSend(klass, sel) + } } diff --git a/foundation.rs b/foundation.rs index ae4b0d7..58b3641 100644 --- a/foundation.rs +++ b/foundation.rs @@ -11,16 +11,16 @@ enum NSAutoreleasePool { } fn NSAutoreleasePool() -> base::id { - let klass = str::as_c_str(~"NSAutoreleasePool", |s| unsafe { - objc::objc_getClass(s) - }); - - let alloc_sel = str::as_c_str(~"alloc", |s| unsafe { objc::sel_registerName(s) } ); - let init_sel = str::as_c_str(~"init", |s| unsafe { objc::sel_registerName(s) } ); - unsafe { + let klass = str::as_c_str(~"NSAutoreleasePool", |s| + objc::objc_getClass(s) + ); + + let alloc_sel = str::as_c_str(~"alloc", |s| objc::sel_registerName(s)); + let init_sel = str::as_c_str(~"init", |s| objc::sel_registerName(s)); + let pool = objc::objc_msgSend(klass, alloc_sel); - return objc::objc_msgSend(pool, init_sel); + objc::objc_msgSend(pool, init_sel) } } From c8cf6f388da1446b267014154b36af85a752a438 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 14 Feb 2013 12:57:51 -0800 Subject: [PATCH 033/249] Update tests for language changes --- base.rs | 52 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/base.rs b/base.rs index 107158a..bc020ee 100644 --- a/base.rs +++ b/base.rs @@ -36,16 +36,21 @@ pub extern mod objc { #[test] pub fn test_nsapp() { let klass = str::as_c_str(~"NSApplication", |s| - objc::objc_getClass(s) + unsafe { + objc::objc_getClass(s) + } ); let sel = str::as_c_str(~"sharedApplication", |s| - objc::sel_registerName(s) + unsafe { + objc::sel_registerName(s) + } ); - let nsapp = objc::objc_msgSend(klass, sel); - - io::println(fmt!("nsapp: %d", (nsapp as int))); + unsafe { + let nsapp = objc::objc_msgSend(klass, sel); + io::println(fmt!("nsapp: %d", (nsapp as int))); + } } #[test] @@ -56,25 +61,40 @@ pub fn test_custom_obj() { } let NSObject = str::as_c_str(~"NSObject", |s| - objc::objc_getClass(s) + unsafe { + objc::objc_getClass(s) + } ); let MyObject = str::as_c_str(~"MyObject", |s| - objc::objc_allocateClassPair(NSObject, s, 0 as libc::size_t) + unsafe { + objc::objc_allocateClassPair(NSObject, s, 0 as libc::size_t) + } ); let doSomething = str::as_c_str(~"doSomething", |s| - objc::sel_registerName(s) + unsafe { + objc::sel_registerName(s) + } ); let _ = str::as_c_str(~"@@:", |types| - objc::class_addMethod(MyObject, doSomething, MyObject_doSomething, - types) + unsafe { + objc::class_addMethod(MyObject, + doSomething, + MyObject_doSomething, + types) + } ); - objc::objc_registerClassPair(MyObject); - let alloc = str::as_c_str(~"alloc", |s| objc::sel_registerName(s)); - let init = str::as_c_str(~"init", |s| objc::sel_registerName(s)); + unsafe { + objc::objc_registerClassPair(MyObject); + } - let mut obj = objc::objc_msgSend(MyObject, alloc); - obj = objc::objc_msgSend(obj, init); - objc::objc_msgSend(obj, doSomething); + let alloc = str::as_c_str(~"alloc", |s| unsafe { objc::sel_registerName(s) }); + let init = str::as_c_str(~"init", |s| unsafe { objc::sel_registerName(s) }); + + unsafe { + let mut obj = objc::objc_msgSend(MyObject, alloc); + obj = objc::objc_msgSend(obj, init); + objc::objc_msgSend(obj, doSomething); + } } From 66a77c2e423581d87e67a63fdc3a141b23b249f1 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 28 Mar 2013 09:17:11 -0600 Subject: [PATCH 034/249] Update to rust 0.6 and remove unused imports. --- base.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/base.rs b/base.rs index bc020ee..9731fef 100644 --- a/base.rs +++ b/base.rs @@ -1,12 +1,10 @@ -use std; - pub type id = libc::intptr_t; pub type Class = libc::intptr_t; pub type IMP = *u8; pub type SEL = libc::intptr_t; pub type Ivar = libc::intptr_t; -pub const nil : id = 0 as id; +pub static nil : id = 0 as id; pub extern mod objc { fn class_addMethod(cls : Class, From 12a7bb3fde3941be1050d46c495fb0fb23aa1880 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 3 Apr 2013 18:16:49 -0700 Subject: [PATCH 035/249] Add license --- COPYING | 5 ++ LICENSE-APACHE | 201 +++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE-MIT | 25 ++++++ 3 files changed, 231 insertions(+) create mode 100644 COPYING create mode 100644 LICENSE-APACHE create mode 100644 LICENSE-MIT diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..8b7291a --- /dev/null +++ b/COPYING @@ -0,0 +1,5 @@ +Licensed under the Apache License, Version 2.0 or the MIT license +, at your +option. All files in the project carrying such notice may not be +copied, modified, or distributed except according to those terms. diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..16fe87b --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..807526f --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2012-2013 Mozilla Foundation + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. From 48cddf0880c5e19dcefd284980c744802bdc3c75 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 4 Apr 2013 19:12:07 -0700 Subject: [PATCH 036/249] Add license headers --- COPYING => COPYRIGHT | 0 appkit.rs | 9 +++++++++ base.rs | 9 +++++++++ cocoa.rc | 9 +++++++++ cocoa.rs | 9 +++++++++ foundation.rs | 9 +++++++++ msgsend.c | 9 +++++++++ 7 files changed, 54 insertions(+) rename COPYING => COPYRIGHT (100%) diff --git a/COPYING b/COPYRIGHT similarity index 100% rename from COPYING rename to COPYRIGHT diff --git a/appkit.rs b/appkit.rs index b4ad91a..ef6ed57 100644 --- a/appkit.rs +++ b/appkit.rs @@ -1,3 +1,12 @@ +// 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::objc; use base; diff --git a/base.rs b/base.rs index 9731fef..16d40b3 100644 --- a/base.rs +++ b/base.rs @@ -1,3 +1,12 @@ +// 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. + pub type id = libc::intptr_t; pub type Class = libc::intptr_t; pub type IMP = *u8; diff --git a/cocoa.rc b/cocoa.rc index 7ddf26f..90d4c0d 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -1,3 +1,12 @@ +// 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. + #[link(name = "cocoa", vers = "0.1", uuid = "5b7b7262-780d-465d-892c-15eab956dedc", diff --git a/cocoa.rs b/cocoa.rs index 8e65e03..3e5038b 100644 --- a/cocoa.rs +++ b/cocoa.rs @@ -1,3 +1,12 @@ +// 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. + fn msgSend1Id(theReceiver: base::id, theSelector: base::SEL, id: base::id) { msgsend::msgSend1IdHACK(theReceiver, theSelector, id); diff --git a/foundation.rs b/foundation.rs index 58b3641..4b08785 100644 --- a/foundation.rs +++ b/foundation.rs @@ -1,3 +1,12 @@ +// 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::objc; use base; diff --git a/msgsend.c b/msgsend.c index a803f78..526fed0 100644 --- a/msgsend.c +++ b/msgsend.c @@ -1,3 +1,12 @@ +// 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. + #include #include From 43d30dfc5db1a467b5dc64e889ce43fc82cd2248 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 13 May 2013 21:11:52 -0700 Subject: [PATCH 037/249] Add many new methods, sufficient to get rust-alert working --- Makefile.in | 2 +- appkit.rs | 42 +++++++++++++++-- base.rs | 126 ++++++++++++++++++++++++++++++++++++++++++-------- cocoa.rs | 10 ---- foundation.rs | 11 ++--- msgsend.c | 16 ------- msgsend.m | 42 +++++++++++++++++ 7 files changed, 194 insertions(+), 55 deletions(-) delete mode 100644 msgsend.c create mode 100644 msgsend.m diff --git a/Makefile.in b/Makefile.in index 28a11c7..9c8ba7c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -20,7 +20,7 @@ cocoa-test: cocoa.rc $(RUST_SRC) libmsgsend.a libmsgsend.a: msgsend.o $(AR) rcs libmsgsend.a msgsend.o -msgsend.o: msgsend.c +msgsend.o: msgsend.m $(CC) $(CFLAGS) $< -o $@ -c check: cocoa-test diff --git a/appkit.rs b/appkit.rs index ef6ed57..8a983a7 100644 --- a/appkit.rs +++ b/appkit.rs @@ -7,9 +7,43 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use base::objc; use base; +pub type CGFloat = f32; + +pub struct NSPoint { + x: float, + y: float, +} + +impl NSPoint { + pub fn new(x: float, y: float) -> NSPoint { + NSPoint { + x: x, + y: y, + } + } +} + +pub struct NSSize { + width: float, + height: float, +} + +impl NSSize { + pub fn new(width: float, height: float) -> NSSize { + NSSize { + width: width, + height: height, + } + } +} + +pub struct NSRect { + origin: NSPoint, + size: NSSize, +} + #[nolink] #[link_args="-framework AppKit"] pub extern mod appkit { @@ -18,9 +52,9 @@ pub extern mod appkit { pub fn NSApp() -> base::id { unsafe { - let klass = str::as_c_str(~"NSApplication", |s| objc::objc_getClass(s)); - let sel = str::as_c_str(~"sharedApplication", |s| objc::sel_registerName(s)); - objc::objc_msgSend(klass, sel) + let klass = str::as_c_str(~"NSApplication", |s| base::objc_getClass(s)); + let sel = str::as_c_str(~"sharedApplication", |s| base::sel_registerName(s)); + base::objc_msgSend(klass, sel) } } diff --git a/base.rs b/base.rs index 16d40b3..577c808 100644 --- a/base.rs +++ b/base.rs @@ -7,6 +7,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use appkit::NSRect; + +use core::libc::c_long; + pub type id = libc::intptr_t; pub type Class = libc::intptr_t; pub type IMP = *u8; @@ -15,11 +19,8 @@ pub type Ivar = libc::intptr_t; pub static nil : id = 0 as id; -pub extern mod objc { - fn class_addMethod(cls : Class, - name : SEL, - imp : IMP, - types : *libc::c_char) -> bool; +pub extern { + fn class_addMethod(cls: Class, name: SEL, imp: IMP, types: *libc::c_char) -> bool; fn class_addIvar(cls : Class, name : *libc::c_char, size : libc::size_t, @@ -44,18 +45,18 @@ pub extern mod objc { pub fn test_nsapp() { let klass = str::as_c_str(~"NSApplication", |s| unsafe { - objc::objc_getClass(s) + objc_getClass(s) } ); let sel = str::as_c_str(~"sharedApplication", |s| unsafe { - objc::sel_registerName(s) + sel_registerName(s) } ); unsafe { - let nsapp = objc::objc_msgSend(klass, sel); + let nsapp = objc_msgSend(klass, sel); io::println(fmt!("nsapp: %d", (nsapp as int))); } } @@ -69,22 +70,22 @@ pub fn test_custom_obj() { let NSObject = str::as_c_str(~"NSObject", |s| unsafe { - objc::objc_getClass(s) + objc_getClass(s) } ); let MyObject = str::as_c_str(~"MyObject", |s| unsafe { - objc::objc_allocateClassPair(NSObject, s, 0 as libc::size_t) + objc_allocateClassPair(NSObject, s, 0 as libc::size_t) } ); let doSomething = str::as_c_str(~"doSomething", |s| unsafe { - objc::sel_registerName(s) + sel_registerName(s) } ); let _ = str::as_c_str(~"@@:", |types| unsafe { - objc::class_addMethod(MyObject, + class_addMethod(MyObject, doSomething, MyObject_doSomething, types) @@ -92,16 +93,105 @@ pub fn test_custom_obj() { ); unsafe { - objc::objc_registerClassPair(MyObject); + objc_registerClassPair(MyObject); } - let alloc = str::as_c_str(~"alloc", |s| unsafe { objc::sel_registerName(s) }); - let init = str::as_c_str(~"init", |s| unsafe { objc::sel_registerName(s) }); + let alloc = str::as_c_str(~"alloc", |s| unsafe { sel_registerName(s) }); + let init = str::as_c_str(~"init", |s| unsafe { sel_registerName(s) }); unsafe { - let mut obj = objc::objc_msgSend(MyObject, alloc); - obj = objc::objc_msgSend(obj, init); - objc::objc_msgSend(obj, doSomething); + let mut obj = objc_msgSend(MyObject, alloc); + obj = objc_msgSend(obj, init); + objc_msgSend(obj, doSomething); } } +/// Invokes the given selector, which must have the signature: +/// +/// id f(); +pub fn msg_send_id(theReceiver: id, theSelector: SEL) -> id { + unsafe { + invoke_msg_id(theReceiver, theSelector) + } +} + +/// Invokes the given selector, which must have the signature: +/// +/// id f(NSRect a); +pub fn msg_send_id_NSRect(theReceiver: id, theSelector: SEL, a: NSRect) -> id { + unsafe { + invoke_msg_id_NSRect(theReceiver, theSelector, &a) + } +} + +/// Invokes the given selector, which must have the signature: +/// +/// id f(id a, id b, id c, id e, id f); +pub fn msg_send_id_id_id_id_id_id(theReceiver: id, + theSelector: SEL, + a: id, + b: id, + c: id, + d: id, + e: id) + -> id { + unsafe { + invoke_msg_id_id_id_id_id_id(theReceiver, theSelector, a, b, c, d, e) + } +} + +/// Invokes the given selector, which must have the signature: +/// +/// long f(); +pub fn msg_send_long(theReceiver: id, theSelector: SEL) -> c_long { + unsafe { + invoke_msg_long(theReceiver, theSelector) + } +} + +/// Invokes the given selector, which must have the signature: +/// +/// void f(); +pub fn msg_send_void(theReceiver: id, theSelector: SEL) { + unsafe { + invoke_msg_void(theReceiver, theSelector) + } +} + +/// Invokes the given selector, which must have the signature: +/// +/// void f(BOOL a); +pub fn msg_send_void_bool(theReceiver: id, theSelector: SEL, a: bool) { + unsafe { + invoke_msg_void_bool(theReceiver, theSelector, a) + } +} + +/// Invokes the given selector, which must have the signature: +/// +/// void f(id a); +pub fn msg_send_void_id(theReceiver: id, theSelector: SEL, a: id) { + unsafe { + invoke_msg_void_id(theReceiver, theSelector, a) + } +} + +#[link_args = "-L. -lmsgsend"] +#[nolink] +extern { + fn invoke_msg_id(theReceiver: id, theSelector: SEL) -> id; + fn invoke_msg_id_id_id_id_id_id(theReceiver: id, + theSelector: SEL, + a: id, + b: id, + c: id, + d: id, + e: id) + -> id; + fn invoke_msg_id_NSRect(theReceiver: id, theSelector: SEL, a: &NSRect) -> id; + fn invoke_msg_long(theReceiver: id, theSelector: SEL) -> c_long; + fn invoke_msg_void(theReceiver: id, theSelector: SEL); + fn invoke_msg_void_bool(theReceiver: id, theSelector: SEL, a: bool); + fn invoke_msg_void_id(theReceiver: id, theSelector: SEL, a: id); +} + diff --git a/cocoa.rs b/cocoa.rs index 3e5038b..d679c8d 100644 --- a/cocoa.rs +++ b/cocoa.rs @@ -7,13 +7,3 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - -fn msgSend1Id(theReceiver: base::id, theSelector: base::SEL, id: base::id) { - msgsend::msgSend1IdHACK(theReceiver, theSelector, id); -} - -#[link_args = "-L. -lmsgsend"] -#[nolink] -extern mod msgsend { - fn msgSend1IdHACK(theReceiver: base::id, theSelector: base::SEL, id: base::id); -} diff --git a/foundation.rs b/foundation.rs index 4b08785..b064484 100644 --- a/foundation.rs +++ b/foundation.rs @@ -7,7 +7,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use base::objc; use base; #[nolink] @@ -22,14 +21,14 @@ enum NSAutoreleasePool { fn NSAutoreleasePool() -> base::id { unsafe { let klass = str::as_c_str(~"NSAutoreleasePool", |s| - objc::objc_getClass(s) + base::objc_getClass(s) ); - let alloc_sel = str::as_c_str(~"alloc", |s| objc::sel_registerName(s)); - let init_sel = str::as_c_str(~"init", |s| objc::sel_registerName(s)); + let alloc_sel = str::as_c_str(~"alloc", |s| base::sel_registerName(s)); + let init_sel = str::as_c_str(~"init", |s| base::sel_registerName(s)); - let pool = objc::objc_msgSend(klass, alloc_sel); - objc::objc_msgSend(pool, init_sel) + let pool = base::objc_msgSend(klass, alloc_sel); + base::objc_msgSend(pool, init_sel) } } diff --git a/msgsend.c b/msgsend.c deleted file mode 100644 index 526fed0..0000000 --- a/msgsend.c +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -#include -#include - -void -msgSend1IdHACK(id theReceiver, SEL theSender, id id) { - objc_msgSend(theReceiver, theSender, id); -} diff --git a/msgsend.m b/msgsend.m new file mode 100644 index 0000000..6203ed2 --- /dev/null +++ b/msgsend.m @@ -0,0 +1,42 @@ +// 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. + +#include +#include +#include +#include + +id invoke_msg_id(id theReceiver, SEL theSelector) { + return objc_msgSend(theReceiver, theSelector); +} + +id invoke_msg_id_NSRect(id theReceiver, SEL theSelector, NSRect *rect) { + return objc_msgSend(theReceiver, theSelector, *rect); +} + +id invoke_msg_id_id_id_id_id_id(id theReceiver, SEL theSelector, id a, id b, id c, id d, id e) { + return objc_msgSend(theReceiver, theSelector, a, b, c, d, e); +} + +long invoke_msg_long(id theReceiver, SEL theSelector) { + return (long)objc_msgSend(theReceiver, theSelector); +} + +void invoke_msg_void(id theReceiver, SEL theSelector) { + objc_msgSend(theReceiver, theSelector); +} + +void invoke_msg_void_bool(id theReceiver, SEL theSelector, bool a) { + objc_msgSend(theReceiver, theSelector, a); +} + +void invoke_msg_void_id(id theReceiver, SEL theSelector, id id) { + objc_msgSend(theReceiver, theSelector, id); +} + From ff8e2a63938ded5d2688619680a981c73d25080d Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 5 Jun 2013 21:38:26 -0700 Subject: [PATCH 038/249] Add msgSend for doubles --- Makefile.in | 3 ++- base.rs | 10 ++++++++++ msgsend.m | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 9c8ba7c..dc8b5cc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,9 +1,10 @@ VPATH=%VPATH% -CC ?= gcc +CC=gcc RUSTC ?= rustc AR ?= ar RUSTFLAGS ?= +CFLAGS=-Wall RUST_SRC = $(shell find $(VPATH)/. -type f -name '*.rs') diff --git a/base.rs b/base.rs index 577c808..dab80fb 100644 --- a/base.rs +++ b/base.rs @@ -106,6 +106,15 @@ pub fn test_custom_obj() { } } +/// Invokes the given selector, which must have the signature: +/// +/// double f(); +pub fn msg_send_double(theReceiver: id, theSelector: SEL) -> f64 { + unsafe { + invoke_msg_double(theReceiver, theSelector) + } +} + /// Invokes the given selector, which must have the signature: /// /// id f(); @@ -179,6 +188,7 @@ pub fn msg_send_void_id(theReceiver: id, theSelector: SEL, a: id) { #[link_args = "-L. -lmsgsend"] #[nolink] extern { + fn invoke_msg_double(theReceiver: id, theSelector: SEL) -> f64; fn invoke_msg_id(theReceiver: id, theSelector: SEL) -> id; fn invoke_msg_id_id_id_id_id_id(theReceiver: id, theSelector: SEL, diff --git a/msgsend.m b/msgsend.m index 6203ed2..413b0aa 100644 --- a/msgsend.m +++ b/msgsend.m @@ -9,9 +9,15 @@ #include #include +#include #include #include +double invoke_msg_double(id theReceiver, SEL theSelector) { + double (*f)(id self, SEL op, ...) = (void *)objc_msgSend_fpret; + return f(theReceiver, theSelector); +} + id invoke_msg_id(id theReceiver, SEL theSelector) { return objc_msgSend(theReceiver, theSelector); } From 3ef4cf7fdaaaa51026ec546a71426ff03a0899fd Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 25 Jun 2013 19:44:47 -0700 Subject: [PATCH 039/249] Update for language changes --- appkit.rs | 7 ++++--- base.rs | 5 ++++- foundation.rs | 9 +++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/appkit.rs b/appkit.rs index 8a983a7..03a3705 100644 --- a/appkit.rs +++ b/appkit.rs @@ -8,6 +8,7 @@ // except according to those terms. use base; +use std::str; pub type CGFloat = f32; @@ -46,14 +47,14 @@ pub struct NSRect { #[nolink] #[link_args="-framework AppKit"] -pub extern mod appkit { +extern { fn NSBeep(); } pub fn NSApp() -> base::id { unsafe { - let klass = str::as_c_str(~"NSApplication", |s| base::objc_getClass(s)); - let sel = str::as_c_str(~"sharedApplication", |s| base::sel_registerName(s)); + let klass = str::as_c_str("NSApplication", |s| base::objc_getClass(s)); + let sel = str::as_c_str("sharedApplication", |s| base::sel_registerName(s)); base::objc_msgSend(klass, sel) } } diff --git a/base.rs b/base.rs index dab80fb..e14b94a 100644 --- a/base.rs +++ b/base.rs @@ -9,7 +9,10 @@ use appkit::NSRect; -use core::libc::c_long; +use std::libc; +use std::libc::c_long; +use std::io; +use std::str; pub type id = libc::intptr_t; pub type Class = libc::intptr_t; diff --git a/foundation.rs b/foundation.rs index b064484..d4344ce 100644 --- a/foundation.rs +++ b/foundation.rs @@ -8,10 +8,11 @@ // except according to those terms. use base; +use std::str; #[nolink] #[link_args="-framework Foundation"] -extern mod foundation { +extern { } enum NSAutoreleasePool { @@ -20,12 +21,12 @@ enum NSAutoreleasePool { fn NSAutoreleasePool() -> base::id { unsafe { - let klass = str::as_c_str(~"NSAutoreleasePool", |s| + let klass = str::as_c_str("NSAutoreleasePool", |s| base::objc_getClass(s) ); - let alloc_sel = str::as_c_str(~"alloc", |s| base::sel_registerName(s)); - let init_sel = str::as_c_str(~"init", |s| base::sel_registerName(s)); + let alloc_sel = str::as_c_str("alloc", |s| base::sel_registerName(s)); + let init_sel = str::as_c_str("init", |s| base::sel_registerName(s)); let pool = base::objc_msgSend(klass, alloc_sel); base::objc_msgSend(pool, init_sel) From aa25cbe911c9105da50efb71e87cdf7eeeee78e9 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Mon, 8 Jul 2013 10:45:25 -0600 Subject: [PATCH 040/249] Warning police. --- base.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/base.rs b/base.rs index e14b94a..cdc0dd7 100644 --- a/base.rs +++ b/base.rs @@ -11,8 +11,6 @@ use appkit::NSRect; use std::libc; use std::libc::c_long; -use std::io; -use std::str; pub type id = libc::intptr_t; pub type Class = libc::intptr_t; @@ -20,7 +18,7 @@ pub type IMP = *u8; pub type SEL = libc::intptr_t; pub type Ivar = libc::intptr_t; -pub static nil : id = 0 as id; +pub static NIL : id = 0 as id; pub extern { fn class_addMethod(cls: Class, name: SEL, imp: IMP, types: *libc::c_char) -> bool; From 9d6ec435b194db0313e104a9e9d3b81b916dfd22 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Mon, 8 Jul 2013 22:03:42 -0600 Subject: [PATCH 041/249] Update tests for latest Rust. --- base.rs | 114 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 60 insertions(+), 54 deletions(-) diff --git a/base.rs b/base.rs index cdc0dd7..079c5a7 100644 --- a/base.rs +++ b/base.rs @@ -42,68 +42,74 @@ pub extern { fn sel_registerName(name : *libc::c_char) -> SEL; } -#[test] -pub fn test_nsapp() { - let klass = str::as_c_str(~"NSApplication", |s| +#[cfg(test)] +mod test { + use std::{str,io,libc}; + use super::*; + + #[test] + pub fn test_nsapp() { + let klass = str::as_c_str("NSApplication", |s| + unsafe { + objc_getClass(s) + } + ); + + let sel = str::as_c_str("sharedApplication", |s| + unsafe { + sel_registerName(s) + } + ); + unsafe { - objc_getClass(s) + let nsapp = objc_msgSend(klass, sel); + io::println(fmt!("nsapp: %d", (nsapp as int))); } - ); - - let sel = str::as_c_str(~"sharedApplication", |s| - unsafe { - sel_registerName(s) - } - ); - - unsafe { - let nsapp = objc_msgSend(klass, sel); - io::println(fmt!("nsapp: %d", (nsapp as int))); - } -} - -#[test] -pub fn test_custom_obj() { - extern fn MyObject_doSomething(this : id, _sel : SEL) -> id { - io::println(~"doSomething"); - return this; } - let NSObject = str::as_c_str(~"NSObject", |s| - unsafe { - objc_getClass(s) + #[test] + pub fn test_custom_obj() { + extern fn MyObject_doSomething(this : id, _sel : SEL) -> id { + io::println("doSomething"); + return this; } - ); - let MyObject = str::as_c_str(~"MyObject", |s| - unsafe { - objc_allocateClassPair(NSObject, s, 0 as libc::size_t) - } - ); - let doSomething = str::as_c_str(~"doSomething", |s| - unsafe { - sel_registerName(s) - } - ); - let _ = str::as_c_str(~"@@:", |types| - unsafe { - class_addMethod(MyObject, - doSomething, - MyObject_doSomething, - types) - } - ); - unsafe { - objc_registerClassPair(MyObject); - } + let NSObject = str::as_c_str("NSObject", |s| + unsafe { + objc_getClass(s) + } + ); + let MyObject = str::as_c_str("MyObject", |s| + unsafe { + objc_allocateClassPair(NSObject, s, 0 as libc::size_t) + } + ); + let doSomething = str::as_c_str("doSomething", |s| + unsafe { + sel_registerName(s) + } + ); + let _ = str::as_c_str("@@:", |types| + unsafe { + class_addMethod(MyObject, + doSomething, + MyObject_doSomething, + types) + } + ); - let alloc = str::as_c_str(~"alloc", |s| unsafe { sel_registerName(s) }); - let init = str::as_c_str(~"init", |s| unsafe { sel_registerName(s) }); + unsafe { + objc_registerClassPair(MyObject); + } - unsafe { - let mut obj = objc_msgSend(MyObject, alloc); - obj = objc_msgSend(obj, init); - objc_msgSend(obj, doSomething); + let alloc = str::as_c_str("alloc", |s| unsafe { sel_registerName(s) }); + let init = str::as_c_str("init", |s| unsafe { sel_registerName(s) }); + + unsafe { + let mut obj = objc_msgSend(MyObject, alloc); + obj = objc_msgSend(obj, init); + objc_msgSend(obj, doSomething); + } } } From d6db464799cdeea8af9c965127cc59e8b42d034c Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 15 Aug 2013 18:46:06 -0600 Subject: [PATCH 042/249] Upgrade to latest rust. --- appkit.rs | 5 ++--- base.rs | 2 +- foundation.rs | 9 ++++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/appkit.rs b/appkit.rs index 03a3705..356a878 100644 --- a/appkit.rs +++ b/appkit.rs @@ -8,7 +8,6 @@ // except according to those terms. use base; -use std::str; pub type CGFloat = f32; @@ -53,8 +52,8 @@ extern { pub fn NSApp() -> base::id { unsafe { - let klass = str::as_c_str("NSApplication", |s| base::objc_getClass(s)); - let sel = str::as_c_str("sharedApplication", |s| base::sel_registerName(s)); + let klass = do "NSApplicatoin".to_c_str().with_ref |s| { base::objc_getClass(s) }; + let sel = do "sharedApplication".to_c_str().with_ref |s| { base::sel_registerName(s) }; base::objc_msgSend(klass, sel) } } diff --git a/base.rs b/base.rs index 079c5a7..bb13bf3 100644 --- a/base.rs +++ b/base.rs @@ -20,7 +20,7 @@ pub type Ivar = libc::intptr_t; pub static NIL : id = 0 as id; -pub extern { +extern { fn class_addMethod(cls: Class, name: SEL, imp: IMP, types: *libc::c_char) -> bool; fn class_addIvar(cls : Class, name : *libc::c_char, diff --git a/foundation.rs b/foundation.rs index d4344ce..a7f7a8a 100644 --- a/foundation.rs +++ b/foundation.rs @@ -8,7 +8,6 @@ // except according to those terms. use base; -use std::str; #[nolink] #[link_args="-framework Foundation"] @@ -21,12 +20,12 @@ enum NSAutoreleasePool { fn NSAutoreleasePool() -> base::id { unsafe { - let klass = str::as_c_str("NSAutoreleasePool", |s| + let klass = do "NSAutoreleasePool".to_c_str().with_ref |s| { base::objc_getClass(s) - ); + }; - let alloc_sel = str::as_c_str("alloc", |s| base::sel_registerName(s)); - let init_sel = str::as_c_str("init", |s| base::sel_registerName(s)); + let alloc_sel = do "alloc".to_c_str().with_ref |s| { base::sel_registerName(s) }; + let init_sel = do "init".to_c_str().with_ref |s| { base::sel_registerName(s) }; let pool = base::objc_msgSend(klass, alloc_sel); base::objc_msgSend(pool, init_sel) From a109ebc6589f57442cdfba491b0166bf90222a94 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Fri, 16 Aug 2013 11:00:32 -0600 Subject: [PATCH 043/249] More rust updates. --- Makefile.in | 2 +- base.rs | 76 ++++++++++++++++++++++++++++------------------------- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/Makefile.in b/Makefile.in index dc8b5cc..63a4e08 100644 --- a/Makefile.in +++ b/Makefile.in @@ -12,7 +12,7 @@ RUST_SRC = $(shell find $(VPATH)/. -type f -name '*.rs') all: libcocoa.dummy libcocoa.dummy: cocoa.rc $(RUST_SRC) libmsgsend.a - $(RUSTC) $(RUSTFLAGS) $< -o $@ + $(RUSTC) $(RUSTFLAGS) $< touch $@ cocoa-test: cocoa.rc $(RUST_SRC) libmsgsend.a diff --git a/base.rs b/base.rs index bb13bf3..db59f43 100644 --- a/base.rs +++ b/base.rs @@ -44,22 +44,22 @@ extern { #[cfg(test)] mod test { - use std::{str,io,libc}; + use std::{io, libc}; use super::*; #[test] pub fn test_nsapp() { - let klass = str::as_c_str("NSApplication", |s| - unsafe { - objc_getClass(s) - } - ); + let klass = do "NSApplication".to_c_str().with_ref |s| { + unsafe { + objc_getClass(s) + } + }; - let sel = str::as_c_str("sharedApplication", |s| - unsafe { - sel_registerName(s) - } - ); + let sel = do "sharedApplication".to_c_str().with_ref |s| { + unsafe { + sel_registerName(s) + } + }; unsafe { let nsapp = objc_msgSend(klass, sel); @@ -74,36 +74,40 @@ mod test { return this; } - let NSObject = str::as_c_str("NSObject", |s| - unsafe { - objc_getClass(s) - } - ); - let MyObject = str::as_c_str("MyObject", |s| - unsafe { - objc_allocateClassPair(NSObject, s, 0 as libc::size_t) - } - ); - let doSomething = str::as_c_str("doSomething", |s| - unsafe { - sel_registerName(s) - } - ); - let _ = str::as_c_str("@@:", |types| - unsafe { - class_addMethod(MyObject, - doSomething, - MyObject_doSomething, - types) - } - ); + let NSObject = do "NSObject".to_c_str().with_ref |s| { + unsafe { + objc_getClass(s) + } + }; + let MyObject = do "MyObject".to_c_str().with_ref |s| { + unsafe { + objc_allocateClassPair(NSObject, s, 0 as libc::size_t) + } + }; + let doSomething = do "doSomething".to_c_str().with_ref |s| { + unsafe { + sel_registerName(s) + } + }; + let _ = do "@@:".to_c_str().with_ref |types| { + unsafe { + class_addMethod(MyObject, + doSomething, + MyObject_doSomething, + types) + } + }; unsafe { objc_registerClassPair(MyObject); } - let alloc = str::as_c_str("alloc", |s| unsafe { sel_registerName(s) }); - let init = str::as_c_str("init", |s| unsafe { sel_registerName(s) }); + let alloc = do "alloc".to_c_str().with_ref |s| { + unsafe { sel_registerName(s) } + }; + let init = do "init".to_c_str().with_ref |s| { + unsafe { sel_registerName(s) } + }; unsafe { let mut obj = objc_msgSend(MyObject, alloc); From 0290c1608784e2dd7a227d3f198039fc1b3b9f1d Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Fri, 16 Aug 2013 12:14:35 -0600 Subject: [PATCH 044/249] Switch from -o to --out-dir. --- Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.in b/Makefile.in index 63a4e08..1884257 100644 --- a/Makefile.in +++ b/Makefile.in @@ -12,11 +12,11 @@ RUST_SRC = $(shell find $(VPATH)/. -type f -name '*.rs') all: libcocoa.dummy libcocoa.dummy: cocoa.rc $(RUST_SRC) libmsgsend.a - $(RUSTC) $(RUSTFLAGS) $< + $(RUSTC) $(RUSTFLAGS) $< --out-dir . touch $@ cocoa-test: cocoa.rc $(RUST_SRC) libmsgsend.a - $(RUSTC) $(RUSTFLAGS) $< -o $@ --test + $(RUSTC) $(RUSTFLAGS) $< --out-dir . --test libmsgsend.a: msgsend.o $(AR) rcs libmsgsend.a msgsend.o From ea0cb0722c33f65feaa3704b2013f049e8df02d5 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Fri, 16 Aug 2013 14:46:53 -0700 Subject: [PATCH 045/249] Revert to using -o for tests --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 1884257..c336356 100644 --- a/Makefile.in +++ b/Makefile.in @@ -16,7 +16,7 @@ libcocoa.dummy: cocoa.rc $(RUST_SRC) libmsgsend.a touch $@ cocoa-test: cocoa.rc $(RUST_SRC) libmsgsend.a - $(RUSTC) $(RUSTFLAGS) $< --out-dir . --test + $(RUSTC) $(RUSTFLAGS) $< -o $@ --test libmsgsend.a: msgsend.o $(AR) rcs libmsgsend.a msgsend.o From fcc8d5865e0002d8d75f1098e956c120d8131c8d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 29 Aug 2013 15:33:11 -0700 Subject: [PATCH 046/249] Update for language changes --- appkit.rs | 1 + base.rs | 12 +++++++++++- foundation.rs | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/appkit.rs b/appkit.rs index 356a878..eebaeae 100644 --- a/appkit.rs +++ b/appkit.rs @@ -50,6 +50,7 @@ extern { fn NSBeep(); } +#[fixed_stack_segment] pub fn NSApp() -> base::id { unsafe { let klass = do "NSApplicatoin".to_c_str().with_ref |s| { base::objc_getClass(s) }; diff --git a/base.rs b/base.rs index db59f43..99edf37 100644 --- a/base.rs +++ b/base.rs @@ -14,7 +14,7 @@ use std::libc::c_long; pub type id = libc::intptr_t; pub type Class = libc::intptr_t; -pub type IMP = *u8; +pub type IMP = extern "C" fn(id, SEL) -> id; pub type SEL = libc::intptr_t; pub type Ivar = libc::intptr_t; @@ -48,6 +48,7 @@ mod test { use super::*; #[test] + #[fixed_stack_segment] pub fn test_nsapp() { let klass = do "NSApplication".to_c_str().with_ref |s| { unsafe { @@ -68,6 +69,7 @@ mod test { } #[test] + #[fixed_stack_segment] pub fn test_custom_obj() { extern fn MyObject_doSomething(this : id, _sel : SEL) -> id { io::println("doSomething"); @@ -120,6 +122,7 @@ mod test { /// Invokes the given selector, which must have the signature: /// /// double f(); +#[fixed_stack_segment] pub fn msg_send_double(theReceiver: id, theSelector: SEL) -> f64 { unsafe { invoke_msg_double(theReceiver, theSelector) @@ -129,6 +132,7 @@ pub fn msg_send_double(theReceiver: id, theSelector: SEL) -> f64 { /// Invokes the given selector, which must have the signature: /// /// id f(); +#[fixed_stack_segment] pub fn msg_send_id(theReceiver: id, theSelector: SEL) -> id { unsafe { invoke_msg_id(theReceiver, theSelector) @@ -138,6 +142,7 @@ pub fn msg_send_id(theReceiver: id, theSelector: SEL) -> id { /// Invokes the given selector, which must have the signature: /// /// id f(NSRect a); +#[fixed_stack_segment] pub fn msg_send_id_NSRect(theReceiver: id, theSelector: SEL, a: NSRect) -> id { unsafe { invoke_msg_id_NSRect(theReceiver, theSelector, &a) @@ -147,6 +152,7 @@ pub fn msg_send_id_NSRect(theReceiver: id, theSelector: SEL, a: NSRect) -> id { /// Invokes the given selector, which must have the signature: /// /// id f(id a, id b, id c, id e, id f); +#[fixed_stack_segment] pub fn msg_send_id_id_id_id_id_id(theReceiver: id, theSelector: SEL, a: id, @@ -163,6 +169,7 @@ pub fn msg_send_id_id_id_id_id_id(theReceiver: id, /// Invokes the given selector, which must have the signature: /// /// long f(); +#[fixed_stack_segment] pub fn msg_send_long(theReceiver: id, theSelector: SEL) -> c_long { unsafe { invoke_msg_long(theReceiver, theSelector) @@ -172,6 +179,7 @@ pub fn msg_send_long(theReceiver: id, theSelector: SEL) -> c_long { /// Invokes the given selector, which must have the signature: /// /// void f(); +#[fixed_stack_segment] pub fn msg_send_void(theReceiver: id, theSelector: SEL) { unsafe { invoke_msg_void(theReceiver, theSelector) @@ -181,6 +189,7 @@ pub fn msg_send_void(theReceiver: id, theSelector: SEL) { /// Invokes the given selector, which must have the signature: /// /// void f(BOOL a); +#[fixed_stack_segment] pub fn msg_send_void_bool(theReceiver: id, theSelector: SEL, a: bool) { unsafe { invoke_msg_void_bool(theReceiver, theSelector, a) @@ -190,6 +199,7 @@ pub fn msg_send_void_bool(theReceiver: id, theSelector: SEL, a: bool) { /// Invokes the given selector, which must have the signature: /// /// void f(id a); +#[fixed_stack_segment] pub fn msg_send_void_id(theReceiver: id, theSelector: SEL, a: id) { unsafe { invoke_msg_void_id(theReceiver, theSelector, a) diff --git a/foundation.rs b/foundation.rs index a7f7a8a..415ad81 100644 --- a/foundation.rs +++ b/foundation.rs @@ -18,6 +18,7 @@ enum NSAutoreleasePool { NSAutoreleasePool_priv(base::id) } +#[fixed_stack_segment] fn NSAutoreleasePool() -> base::id { unsafe { let klass = do "NSAutoreleasePool".to_c_str().with_ref |s| { From 457352328e9165df0b04a5fb6fb369841601b179 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 3 Oct 2013 15:18:38 -0700 Subject: [PATCH 047/249] Update for language changes --- appkit.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/appkit.rs b/appkit.rs index eebaeae..a8f358a 100644 --- a/appkit.rs +++ b/appkit.rs @@ -12,12 +12,12 @@ use base; pub type CGFloat = f32; pub struct NSPoint { - x: float, - y: float, + x: f64, + y: f64, } impl NSPoint { - pub fn new(x: float, y: float) -> NSPoint { + pub fn new(x: f64, y: f64) -> NSPoint { NSPoint { x: x, y: y, @@ -26,12 +26,12 @@ impl NSPoint { } pub struct NSSize { - width: float, - height: float, + width: f64, + height: f64, } impl NSSize { - pub fn new(width: float, height: float) -> NSSize { + pub fn new(width: f64, height: f64) -> NSSize { NSSize { width: width, height: height, From 30b6fb887ff0e1c4accfc84a804f1a9010a327ba Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Tue, 15 Oct 2013 18:20:26 -0600 Subject: [PATCH 048/249] Upgrad Rust. --- base.rs | 36 ++++++++++++++++++------------------ cocoa.rc | 2 ++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/base.rs b/base.rs index 99edf37..dffec2d 100644 --- a/base.rs +++ b/base.rs @@ -21,25 +21,25 @@ pub type Ivar = libc::intptr_t; pub static NIL : id = 0 as id; extern { - fn class_addMethod(cls: Class, name: SEL, imp: IMP, types: *libc::c_char) -> bool; - fn class_addIvar(cls : Class, - name : *libc::c_char, - size : libc::size_t, - alignment: u8, - types: *libc::c_char) -> bool; - fn object_setInstanceVariable(obj : id, + pub fn class_addMethod(cls: Class, name: SEL, imp: IMP, types: *libc::c_char) -> bool; + pub fn class_addIvar(cls : Class, + name : *libc::c_char, + size : libc::size_t, + alignment: u8, + types: *libc::c_char) -> bool; + pub fn object_setInstanceVariable(obj : id, + name : *libc::c_char, + value : *libc::c_void); + pub fn object_getInstanceVariable(obj : id, + name : *libc::c_char, + outValue : **libc::c_void); + pub fn objc_allocateClassPair(superclass : Class, name : *libc::c_char, - value : *libc::c_void); - fn object_getInstanceVariable(obj : id, - name : *libc::c_char, - outValue : **libc::c_void); - fn objc_allocateClassPair(superclass : Class, - name : *libc::c_char, - extraBytes : libc::size_t) -> Class; - fn objc_getClass(name : *libc::c_char) -> id; - fn objc_msgSend(theReceiver : id, theSelector : SEL) -> id; - fn objc_registerClassPair(cls : Class); - fn sel_registerName(name : *libc::c_char) -> SEL; + extraBytes : libc::size_t) -> Class; + pub fn objc_getClass(name : *libc::c_char) -> id; + pub fn objc_msgSend(theReceiver : id, theSelector : SEL) -> id; + pub fn objc_registerClassPair(cls : Class); + pub fn sel_registerName(name : *libc::c_char) -> SEL; } #[cfg(test)] diff --git a/cocoa.rc b/cocoa.rc index 90d4c0d..0308434 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -16,6 +16,8 @@ #[license = "MIT"]; #[crate_type = "lib"]; +#[feature(globs)]; + extern mod std; pub mod appkit; From 8bf095df6b2a0950da51236cd29a3dececde3927 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Mon, 28 Oct 2013 20:08:55 -0700 Subject: [PATCH 049/249] fmt! -> format! --- base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base.rs b/base.rs index dffec2d..c1e0d36 100644 --- a/base.rs +++ b/base.rs @@ -64,7 +64,7 @@ mod test { unsafe { let nsapp = objc_msgSend(klass, sel); - io::println(fmt!("nsapp: %d", (nsapp as int))); + io::println(format!("nsapp: {:d}", (nsapp as int))); } } From aeb2040fa5f7f1ca8bafdf88df253693ba18415b Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 31 Oct 2013 14:16:23 -0600 Subject: [PATCH 050/249] Remove use of std::io. --- base.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/base.rs b/base.rs index c1e0d36..673207f 100644 --- a/base.rs +++ b/base.rs @@ -44,7 +44,7 @@ extern { #[cfg(test)] mod test { - use std::{io, libc}; + use std::libc; use super::*; #[test] @@ -64,7 +64,7 @@ mod test { unsafe { let nsapp = objc_msgSend(klass, sel); - io::println(format!("nsapp: {:d}", (nsapp as int))); + println!("nsapp: {:d}", (nsapp as int)); } } @@ -72,7 +72,7 @@ mod test { #[fixed_stack_segment] pub fn test_custom_obj() { extern fn MyObject_doSomething(this : id, _sel : SEL) -> id { - io::println("doSomething"); + println!("doSomething"); return this; } From 00afc2926bdcf9085a7002fa3fe97708dd86984f Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 1 Nov 2013 20:35:06 -0700 Subject: [PATCH 051/249] Introduce a more convenient notation and embrace dynamic typing. This commit changes the way Objective-C is handled in Rust. Objective-C is fundamentally a dynamically typed system and I feel there is little point in going against that trend. So the only type of an Objective-C object is now `id`. By embracing dynamic typing, we get much cleaner APIs. Before this change, one had to use `sel_registerName` and friends in order to invoke simple Objective-C selectors. Now one can simply say things like: let run_loop = "NSRunLoop".send("alloc", ()).send("init", ()); --- appkit.rs | 10 +- base.rs | 356 ++++++++++++++++++++++++++++---------------------- cocoa.rc | 1 - cocoa.rs | 9 -- foundation.rs | 35 ----- 5 files changed, 203 insertions(+), 208 deletions(-) delete mode 100644 cocoa.rs delete mode 100644 foundation.rs diff --git a/appkit.rs b/appkit.rs index a8f358a..5a34d3a 100644 --- a/appkit.rs +++ b/appkit.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use base; +use base::{ObjCMethodCall, id}; pub type CGFloat = f32; @@ -51,11 +51,7 @@ extern { } #[fixed_stack_segment] -pub fn NSApp() -> base::id { - unsafe { - let klass = do "NSApplicatoin".to_c_str().with_ref |s| { base::objc_getClass(s) }; - let sel = do "sharedApplication".to_c_str().with_ref |s| { base::sel_registerName(s) }; - base::objc_msgSend(klass, sel) - } +pub unsafe fn NSApp() -> id { + "NSApplication".send("sharedApplication", ()) } diff --git a/base.rs b/base.rs index 673207f..706f25f 100644 --- a/base.rs +++ b/base.rs @@ -9,39 +9,205 @@ use appkit::NSRect; +use std::libc::{c_double, c_long}; use std::libc; -use std::libc::c_long; -pub type id = libc::intptr_t; pub type Class = libc::intptr_t; pub type IMP = extern "C" fn(id, SEL) -> id; -pub type SEL = libc::intptr_t; pub type Ivar = libc::intptr_t; +pub type SEL = libc::intptr_t; +pub type id = libc::intptr_t; -pub static NIL : id = 0 as id; +pub static nil: id = 0 as id; extern { pub fn class_addMethod(cls: Class, name: SEL, imp: IMP, types: *libc::c_char) -> bool; - pub fn class_addIvar(cls : Class, - name : *libc::c_char, - size : libc::size_t, + pub fn class_addIvar(cls: Class, + name: *libc::c_char, + size: libc::size_t, alignment: u8, - types: *libc::c_char) -> bool; - pub fn object_setInstanceVariable(obj : id, - name : *libc::c_char, - value : *libc::c_void); - pub fn object_getInstanceVariable(obj : id, - name : *libc::c_char, - outValue : **libc::c_void); - pub fn objc_allocateClassPair(superclass : Class, - name : *libc::c_char, - extraBytes : libc::size_t) -> Class; - pub fn objc_getClass(name : *libc::c_char) -> id; - pub fn objc_msgSend(theReceiver : id, theSelector : SEL) -> id; - pub fn objc_registerClassPair(cls : Class); - pub fn sel_registerName(name : *libc::c_char) -> SEL; + types: *libc::c_char) + -> bool; + pub fn object_setInstanceVariable(obj: id, name: *libc::c_char, value: *libc::c_void); + pub fn object_getInstanceVariable(obj: id, name: *libc::c_char, outValue: **libc::c_void); + pub fn objc_allocateClassPair(superclass: Class, name: *libc::c_char, extraBytes: libc::size_t) + -> Class; + pub fn objc_getClass(name: *libc::c_char) -> id; + pub fn objc_msgSend(theReceiver: id, theSelector: SEL) -> id; + pub fn objc_registerClassPair(cls: Class); + pub fn sel_registerName(name: *libc::c_char) -> SEL; } +/// A convenience method to convert the name of a class to the class object itself. +#[inline] +#[fixed_stack_segment] +pub fn class(name: &str) -> id { + unsafe { + name.to_c_str().with_ref(|c_string| objc_getClass(c_string)) + } +} + +/// A convenience method to convert the name of a selector to the selector object. +#[inline] +#[fixed_stack_segment] +pub fn selector(name: &str) -> SEL { + unsafe { + name.to_c_str().with_ref(|c_string| sel_registerName(c_string)) + } +} + +/// A trait that allows syntax like: +/// +/// let string = "NSString".send("alloc").send("initWithCString:", "Hello world!"); +pub trait ObjCMethodCall { + unsafe fn send(self, selector: S, args: A) -> id; + unsafe fn send_double(self, selector: S, args: A) + -> c_double; + unsafe fn send_long(self, selector: S, args: A) -> c_long; + unsafe fn send_void(self, selector: S, args: A); +} + +impl ObjCMethodCall for id { + unsafe fn send(self, selector: S, args: A) -> id { + args.send_args(self, selector.as_selector()) + } + unsafe fn send_double(self, selector: S, args: A) + -> c_double { + args.send_double_args(self, selector.as_selector()) + } + unsafe fn send_long(self, selector: S, args: A) + -> c_long { + args.send_long_args(self, selector.as_selector()) + } + unsafe fn send_void(self, selector: S, args: A) { + args.send_void_args(self, selector.as_selector()) + } +} + +/// A convenience implementation that allows methods on class names to be called directly, as in: +/// +/// "NSString".send("alloc") +impl<'self> ObjCMethodCall for &'self str { + unsafe fn send(self, selector: S, args: A) -> id { + args.send_args(class(self), selector.as_selector()) + } + unsafe fn send_double(self, selector: S, args: A) + -> c_double { + args.send_double_args(class(self), selector.as_selector()) + } + unsafe fn send_long(self, selector: S, args: A) + -> c_long { + args.send_long_args(class(self), selector.as_selector()) + } + unsafe fn send_void(self, selector: S, args: A) { + args.send_void_args(class(self), selector.as_selector()) + } +} + +/// A trait that allows C strings to be used as selectors without having to convert them first. +pub trait ObjCSelector { + fn as_selector(self) -> SEL; +} + +impl<'self> ObjCSelector for &'self str { + #[inline] + #[fixed_stack_segment] + fn as_selector(self) -> SEL { + // TODO(pcwalton): Cache somehow. + unsafe { + self.to_c_str().with_ref(|c_string| sel_registerName(c_string)) + } + } +} + +impl ObjCSelector for SEL { + #[inline] + fn as_selector(self) -> SEL { + self + } +} + +/// Traits that simulate variadic parameters for convenience when sending messages. +trait ObjCMethodArgs { + unsafe fn send_args(self, receiver: id, selector: SEL) -> id; +} +trait ObjCMethodDoubleArgs { + unsafe fn send_double_args(self, receiver: id, selector: SEL) -> c_double; +} +trait ObjCMethodLongArgs { + unsafe fn send_long_args(self, receiver: id, selector: SEL) -> c_long; +} +trait ObjCMethodVoidArgs { + unsafe fn send_void_args(self, receiver: id, selector: SEL); +} + +impl ObjCMethodArgs for () { + #[inline] + #[fixed_stack_segment] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + invoke_msg_id(receiver, selector) + } +} + +impl ObjCMethodArgs for (id, id, id, id, id) { + #[inline] + #[fixed_stack_segment] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second, third, fourth, fifth) = self; + invoke_msg_id_id_id_id_id_id(receiver, selector, first, second, third, fourth, fifth) + } +} + +impl ObjCMethodArgs for NSRect { + #[inline] + #[fixed_stack_segment] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + invoke_msg_id_NSRect(receiver, selector, &self) + } +} + +impl ObjCMethodDoubleArgs for () { + #[inline] + #[fixed_stack_segment] + unsafe fn send_double_args(self, receiver: id, selector: SEL) -> f64 { + invoke_msg_double(receiver, selector) + } +} + +impl ObjCMethodLongArgs for () { + #[inline] + #[fixed_stack_segment] + unsafe fn send_long_args(self, receiver: id, selector: SEL) -> c_long { + invoke_msg_long(receiver, selector) + } +} + +impl ObjCMethodVoidArgs for () { + #[inline] + #[fixed_stack_segment] + unsafe fn send_void_args(self, receiver: id, selector: SEL) { + invoke_msg_void(receiver, selector) + } +} + +impl ObjCMethodVoidArgs for bool { + #[inline] + #[fixed_stack_segment] + unsafe fn send_void_args(self, receiver: id, selector: SEL) { + invoke_msg_void_bool(receiver, selector, self) + } +} + +impl ObjCMethodVoidArgs for id { + #[inline] + #[fixed_stack_segment] + unsafe fn send_void_args(self, receiver: id, selector: SEL) { + invoke_msg_void_id(receiver, selector, self) + } +} + +/// A trait that simulates variadic parameters for method calls. + #[cfg(test)] mod test { use std::libc; @@ -50,159 +216,37 @@ mod test { #[test] #[fixed_stack_segment] pub fn test_nsapp() { - let klass = do "NSApplication".to_c_str().with_ref |s| { - unsafe { - objc_getClass(s) - } - }; - - let sel = do "sharedApplication".to_c_str().with_ref |s| { - unsafe { - sel_registerName(s) - } - }; - unsafe { - let nsapp = objc_msgSend(klass, sel); - println!("nsapp: {:d}", (nsapp as int)); + let nsApp = "NSApplication".send("sharedApplication", ()); } } #[test] #[fixed_stack_segment] pub fn test_custom_obj() { - extern fn MyObject_doSomething(this : id, _sel : SEL) -> id { - println!("doSomething"); + extern fn MyObject_doSomething(this: id, _: SEL) -> id { + println("doSomething"); return this; } - let NSObject = do "NSObject".to_c_str().with_ref |s| { - unsafe { - objc_getClass(s) - } - }; + let NSObject = class("NSObject"); let MyObject = do "MyObject".to_c_str().with_ref |s| { unsafe { objc_allocateClassPair(NSObject, s, 0 as libc::size_t) } }; - let doSomething = do "doSomething".to_c_str().with_ref |s| { - unsafe { - sel_registerName(s) - } - }; - let _ = do "@@:".to_c_str().with_ref |types| { - unsafe { - class_addMethod(MyObject, - doSomething, - MyObject_doSomething, - types) - } - }; - unsafe { + let doSomething = selector("doSomething"); + let _ = do "@@:".to_c_str().with_ref |types| { + class_addMethod(MyObject, doSomething, MyObject_doSomething, types) + }; + objc_registerClassPair(MyObject); + + let mut obj: id = MyObject.send("alloc", ()); + obj = obj.send("init", ()); + obj.send_void("doSomething", ()); } - - let alloc = do "alloc".to_c_str().with_ref |s| { - unsafe { sel_registerName(s) } - }; - let init = do "init".to_c_str().with_ref |s| { - unsafe { sel_registerName(s) } - }; - - unsafe { - let mut obj = objc_msgSend(MyObject, alloc); - obj = objc_msgSend(obj, init); - objc_msgSend(obj, doSomething); - } - } -} - -/// Invokes the given selector, which must have the signature: -/// -/// double f(); -#[fixed_stack_segment] -pub fn msg_send_double(theReceiver: id, theSelector: SEL) -> f64 { - unsafe { - invoke_msg_double(theReceiver, theSelector) - } -} - -/// Invokes the given selector, which must have the signature: -/// -/// id f(); -#[fixed_stack_segment] -pub fn msg_send_id(theReceiver: id, theSelector: SEL) -> id { - unsafe { - invoke_msg_id(theReceiver, theSelector) - } -} - -/// Invokes the given selector, which must have the signature: -/// -/// id f(NSRect a); -#[fixed_stack_segment] -pub fn msg_send_id_NSRect(theReceiver: id, theSelector: SEL, a: NSRect) -> id { - unsafe { - invoke_msg_id_NSRect(theReceiver, theSelector, &a) - } -} - -/// Invokes the given selector, which must have the signature: -/// -/// id f(id a, id b, id c, id e, id f); -#[fixed_stack_segment] -pub fn msg_send_id_id_id_id_id_id(theReceiver: id, - theSelector: SEL, - a: id, - b: id, - c: id, - d: id, - e: id) - -> id { - unsafe { - invoke_msg_id_id_id_id_id_id(theReceiver, theSelector, a, b, c, d, e) - } -} - -/// Invokes the given selector, which must have the signature: -/// -/// long f(); -#[fixed_stack_segment] -pub fn msg_send_long(theReceiver: id, theSelector: SEL) -> c_long { - unsafe { - invoke_msg_long(theReceiver, theSelector) - } -} - -/// Invokes the given selector, which must have the signature: -/// -/// void f(); -#[fixed_stack_segment] -pub fn msg_send_void(theReceiver: id, theSelector: SEL) { - unsafe { - invoke_msg_void(theReceiver, theSelector) - } -} - -/// Invokes the given selector, which must have the signature: -/// -/// void f(BOOL a); -#[fixed_stack_segment] -pub fn msg_send_void_bool(theReceiver: id, theSelector: SEL, a: bool) { - unsafe { - invoke_msg_void_bool(theReceiver, theSelector, a) - } -} - -/// Invokes the given selector, which must have the signature: -/// -/// void f(id a); -#[fixed_stack_segment] -pub fn msg_send_void_id(theReceiver: id, theSelector: SEL, a: id) { - unsafe { - invoke_msg_void_id(theReceiver, theSelector, a) } } diff --git a/cocoa.rc b/cocoa.rc index 0308434..325b2c2 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -22,5 +22,4 @@ extern mod std; pub mod appkit; pub mod base; -pub mod foundation; diff --git a/cocoa.rs b/cocoa.rs deleted file mode 100644 index d679c8d..0000000 --- a/cocoa.rs +++ /dev/null @@ -1,9 +0,0 @@ -// 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. - diff --git a/foundation.rs b/foundation.rs deleted file mode 100644 index 415ad81..0000000 --- a/foundation.rs +++ /dev/null @@ -1,35 +0,0 @@ -// 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; - -#[nolink] -#[link_args="-framework Foundation"] -extern { -} - -enum NSAutoreleasePool { - NSAutoreleasePool_priv(base::id) -} - -#[fixed_stack_segment] -fn NSAutoreleasePool() -> base::id { - unsafe { - let klass = do "NSAutoreleasePool".to_c_str().with_ref |s| { - base::objc_getClass(s) - }; - - let alloc_sel = do "alloc".to_c_str().with_ref |s| { base::sel_registerName(s) }; - let init_sel = do "init".to_c_str().with_ref |s| { base::sel_registerName(s) }; - - let pool = base::objc_msgSend(klass, alloc_sel); - base::objc_msgSend(pool, init_sel) - } -} - From 85ea35e67f7072826d5234ecaf158f2d435ad8fc Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 19 Dec 2013 09:44:43 -0700 Subject: [PATCH 052/249] Upgrade to latest Rust. --- appkit.rs | 8 ++------ base.rs | 30 ++++++++---------------------- cocoa.rc | 7 ++----- 3 files changed, 12 insertions(+), 33 deletions(-) diff --git a/appkit.rs b/appkit.rs index 5a34d3a..1b4c59b 100644 --- a/appkit.rs +++ b/appkit.rs @@ -44,13 +44,9 @@ pub struct NSRect { size: NSSize, } -#[nolink] -#[link_args="-framework AppKit"] -extern { - fn NSBeep(); -} +#[link(name = "AppKit", kind = "framework")] +extern {} -#[fixed_stack_segment] pub unsafe fn NSApp() -> id { "NSApplication".send("sharedApplication", ()) } diff --git a/base.rs b/base.rs index 706f25f..4d8c4b4 100644 --- a/base.rs +++ b/base.rs @@ -40,7 +40,6 @@ extern { /// A convenience method to convert the name of a class to the class object itself. #[inline] -#[fixed_stack_segment] pub fn class(name: &str) -> id { unsafe { name.to_c_str().with_ref(|c_string| objc_getClass(c_string)) @@ -49,7 +48,6 @@ pub fn class(name: &str) -> id { /// A convenience method to convert the name of a selector to the selector object. #[inline] -#[fixed_stack_segment] pub fn selector(name: &str) -> SEL { unsafe { name.to_c_str().with_ref(|c_string| sel_registerName(c_string)) @@ -87,7 +85,7 @@ impl ObjCMethodCall for id { /// A convenience implementation that allows methods on class names to be called directly, as in: /// /// "NSString".send("alloc") -impl<'self> ObjCMethodCall for &'self str { +impl<'a> ObjCMethodCall for &'a str { unsafe fn send(self, selector: S, args: A) -> id { args.send_args(class(self), selector.as_selector()) } @@ -109,9 +107,8 @@ pub trait ObjCSelector { fn as_selector(self) -> SEL; } -impl<'self> ObjCSelector for &'self str { +impl<'a> ObjCSelector for &'a str { #[inline] - #[fixed_stack_segment] fn as_selector(self) -> SEL { // TODO(pcwalton): Cache somehow. unsafe { @@ -143,7 +140,6 @@ trait ObjCMethodVoidArgs { impl ObjCMethodArgs for () { #[inline] - #[fixed_stack_segment] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { invoke_msg_id(receiver, selector) } @@ -151,7 +147,6 @@ impl ObjCMethodArgs for () { impl ObjCMethodArgs for (id, id, id, id, id) { #[inline] - #[fixed_stack_segment] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { let (first, second, third, fourth, fifth) = self; invoke_msg_id_id_id_id_id_id(receiver, selector, first, second, third, fourth, fifth) @@ -160,7 +155,6 @@ impl ObjCMethodArgs for (id, id, id, id, id) { impl ObjCMethodArgs for NSRect { #[inline] - #[fixed_stack_segment] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { invoke_msg_id_NSRect(receiver, selector, &self) } @@ -168,7 +162,6 @@ impl ObjCMethodArgs for NSRect { impl ObjCMethodDoubleArgs for () { #[inline] - #[fixed_stack_segment] unsafe fn send_double_args(self, receiver: id, selector: SEL) -> f64 { invoke_msg_double(receiver, selector) } @@ -176,7 +169,6 @@ impl ObjCMethodDoubleArgs for () { impl ObjCMethodLongArgs for () { #[inline] - #[fixed_stack_segment] unsafe fn send_long_args(self, receiver: id, selector: SEL) -> c_long { invoke_msg_long(receiver, selector) } @@ -184,7 +176,6 @@ impl ObjCMethodLongArgs for () { impl ObjCMethodVoidArgs for () { #[inline] - #[fixed_stack_segment] unsafe fn send_void_args(self, receiver: id, selector: SEL) { invoke_msg_void(receiver, selector) } @@ -192,7 +183,6 @@ impl ObjCMethodVoidArgs for () { impl ObjCMethodVoidArgs for bool { #[inline] - #[fixed_stack_segment] unsafe fn send_void_args(self, receiver: id, selector: SEL) { invoke_msg_void_bool(receiver, selector, self) } @@ -200,7 +190,6 @@ impl ObjCMethodVoidArgs for bool { impl ObjCMethodVoidArgs for id { #[inline] - #[fixed_stack_segment] unsafe fn send_void_args(self, receiver: id, selector: SEL) { invoke_msg_void_id(receiver, selector, self) } @@ -214,15 +203,13 @@ mod test { use super::*; #[test] - #[fixed_stack_segment] pub fn test_nsapp() { unsafe { - let nsApp = "NSApplication".send("sharedApplication", ()); + let _nsApp = "NSApplication".send("sharedApplication", ()); } } #[test] - #[fixed_stack_segment] pub fn test_custom_obj() { extern fn MyObject_doSomething(this: id, _: SEL) -> id { println("doSomething"); @@ -230,16 +217,16 @@ mod test { } let NSObject = class("NSObject"); - let MyObject = do "MyObject".to_c_str().with_ref |s| { + let MyObject = "MyObject".to_c_str().with_ref(|s| { unsafe { objc_allocateClassPair(NSObject, s, 0 as libc::size_t) } - }; + }); unsafe { let doSomething = selector("doSomething"); - let _ = do "@@:".to_c_str().with_ref |types| { + let _ = "@@:".to_c_str().with_ref(|types| { class_addMethod(MyObject, doSomething, MyObject_doSomething, types) - }; + }); objc_registerClassPair(MyObject); @@ -250,8 +237,7 @@ mod test { } } -#[link_args = "-L. -lmsgsend"] -#[nolink] +#[link(name = "msgsend")] extern { fn invoke_msg_double(theReceiver: id, theSelector: SEL) -> f64; fn invoke_msg_id(theReceiver: id, theSelector: SEL) -> id; diff --git a/cocoa.rc b/cocoa.rc index 325b2c2..6a6f751 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -7,14 +7,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[link(name = "cocoa", - vers = "0.1", - uuid = "5b7b7262-780d-465d-892c-15eab956dedc", - url = "http://github.com/pcwalton/cocoa")]; +#[crate_id = "github.com/mozilla-servo/rust-cocoa#cocoa:0.1"]; +#[crate_type = "lib"]; #[comment = "The Servo Parallel Browser Project"]; #[license = "MIT"]; -#[crate_type = "lib"]; #[feature(globs)]; From 4246e7de27461a2077e81c416ef1c4cda0a51d87 Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Tue, 4 Mar 2014 08:39:21 -0800 Subject: [PATCH 053/249] Rust upgrade --- cocoa.rc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocoa.rc b/cocoa.rc index 6a6f751..d3e0182 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -15,7 +15,7 @@ #[feature(globs)]; -extern mod std; +extern crate std; pub mod appkit; pub mod base; From 514cb9208f36b8399c0951ca0ebe964b64a309c5 Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Thu, 13 Mar 2014 19:32:17 -0500 Subject: [PATCH 054/249] Rust make check fix --- base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base.rs b/base.rs index 4d8c4b4..35ce3e2 100644 --- a/base.rs +++ b/base.rs @@ -212,7 +212,7 @@ mod test { #[test] pub fn test_custom_obj() { extern fn MyObject_doSomething(this: id, _: SEL) -> id { - println("doSomething"); + println!("doSomething"); return this; } From 9762797c18243a82bddb58ff2fdb8e1af1076e2d Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Wed, 19 Mar 2014 13:50:00 -0500 Subject: [PATCH 055/249] Clean rlib files --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index c336356..f9f4b61 100644 --- a/Makefile.in +++ b/Makefile.in @@ -29,4 +29,4 @@ check: cocoa-test .PHONY: clean clean: - rm -f cocoa-test *.a *.o *.so *.dylib *.dll *.dummy cocoa-test + rm -f cocoa-test *.a *.o *.so *.dylib *.rlib *.dll *.dummy cocoa-test From 488bde06d8c9c06743805007be096cdf2c6a4a6b Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Fri, 4 Apr 2014 09:52:12 -0500 Subject: [PATCH 056/249] Generate both dylib and rlib for rustup --- cocoa.rc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cocoa.rc b/cocoa.rc index d3e0182..d80c437 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -9,6 +9,8 @@ #[crate_id = "github.com/mozilla-servo/rust-cocoa#cocoa:0.1"]; #[crate_type = "lib"]; +#[crate_type = "dylib"]; +#[crate_type = "rlib"]; #[comment = "The Servo Parallel Browser Project"]; #[license = "MIT"]; From 8b56cec370eb33a2d86981268455a78302a3c224 Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Fri, 11 Apr 2014 18:49:01 -0500 Subject: [PATCH 057/249] Fix merge conflict --- base.rs | 4 ++-- cocoa.rc | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/base.rs b/base.rs index 35ce3e2..bada9d9 100644 --- a/base.rs +++ b/base.rs @@ -9,8 +9,8 @@ use appkit::NSRect; -use std::libc::{c_double, c_long}; -use std::libc; +use libc::{c_double, c_long}; +use libc; pub type Class = libc::intptr_t; pub type IMP = extern "C" fn(id, SEL) -> id; diff --git a/cocoa.rc b/cocoa.rc index d80c437..6598ff6 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -7,16 +7,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[crate_id = "github.com/mozilla-servo/rust-cocoa#cocoa:0.1"]; -#[crate_type = "lib"]; -#[crate_type = "dylib"]; -#[crate_type = "rlib"]; +#![crate_id = "github.com/mozilla-servo/rust-cocoa#cocoa:0.1"] +#![crate_type = "lib"] +#![crate_type = "dylib"] +#![crate_type = "rlib"] -#[comment = "The Servo Parallel Browser Project"]; -#[license = "MIT"]; +#![comment = "The Servo Parallel Browser Project"] +#![license = "MIT"] -#[feature(globs)]; +#![feature(globs)] +extern crate libc; extern crate std; pub mod appkit; From 8f0ebc072b91137eda32934bc2a99ade2c13559d Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Fri, 11 Apr 2014 19:04:11 -0500 Subject: [PATCH 058/249] Fix cross-crate visibility --- appkit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appkit.rs b/appkit.rs index 1b4c59b..46d3c1d 100644 --- a/appkit.rs +++ b/appkit.rs @@ -40,8 +40,8 @@ impl NSSize { } pub struct NSRect { - origin: NSPoint, - size: NSSize, + pub origin: NSPoint, + pub size: NSSize, } #[link(name = "AppKit", kind = "framework")] From 4b4cdd20f386cf4a2aebeee90b6ad35abf15d132 Mon Sep 17 00:00:00 2001 From: Lars Bergstrom Date: Fri, 25 Apr 2014 16:29:49 -0500 Subject: [PATCH 059/249] Fix tests for rust upgrade --- base.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base.rs b/base.rs index bada9d9..945fa71 100644 --- a/base.rs +++ b/base.rs @@ -199,7 +199,7 @@ impl ObjCMethodVoidArgs for id { #[cfg(test)] mod test { - use std::libc; + use libc; use super::*; #[test] From c0036e25bbff4cc9f2100b344c37e50a0201a966 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Sat, 31 May 2014 23:25:59 -0600 Subject: [PATCH 060/249] Upgrade Rust. --- base.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/base.rs b/base.rs index 945fa71..be897a2 100644 --- a/base.rs +++ b/base.rs @@ -16,6 +16,7 @@ pub type Class = libc::intptr_t; pub type IMP = extern "C" fn(id, SEL) -> id; pub type Ivar = libc::intptr_t; pub type SEL = libc::intptr_t; +#[allow(non_camel_case_types)] pub type id = libc::intptr_t; pub static nil: id = 0 as id; @@ -216,21 +217,21 @@ mod test { return this; } - let NSObject = class("NSObject"); - let MyObject = "MyObject".to_c_str().with_ref(|s| { + let ns_object = class("NSObject"); + let my_object = "MyObject".to_c_str().with_ref(|s| { unsafe { - objc_allocateClassPair(NSObject, s, 0 as libc::size_t) + objc_allocateClassPair(ns_object, s, 0 as libc::size_t) } }); unsafe { let doSomething = selector("doSomething"); let _ = "@@:".to_c_str().with_ref(|types| { - class_addMethod(MyObject, doSomething, MyObject_doSomething, types) + class_addMethod(my_object, doSomething, MyObject_doSomething, types) }); - objc_registerClassPair(MyObject); + objc_registerClassPair(my_object); - let mut obj: id = MyObject.send("alloc", ()); + let mut obj: id = my_object.send("alloc", ()); obj = obj.send("init", ()); obj.send_void("doSomething", ()); } From c70a1902bad7afd6eebdec22bbcb18ac9bbc513f Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Fri, 27 Jun 2014 12:26:31 -0600 Subject: [PATCH 061/249] Warning police. --- appkit.rs | 2 ++ cocoa.rc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/appkit.rs b/appkit.rs index 46d3c1d..4af0c96 100644 --- a/appkit.rs +++ b/appkit.rs @@ -11,6 +11,7 @@ use base::{ObjCMethodCall, id}; pub type CGFloat = f32; +#[allow(dead_code)] pub struct NSPoint { x: f64, y: f64, @@ -25,6 +26,7 @@ impl NSPoint { } } +#[allow(dead_code)] pub struct NSSize { width: f64, height: f64, diff --git a/cocoa.rc b/cocoa.rc index 6598ff6..f22381d 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -17,6 +17,8 @@ #![feature(globs)] +#![allow(non_snake_case_functions)] + extern crate libc; extern crate std; From 49c7f86370a65c7fbd407d6b2500071e43f8bc63 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 24 Jul 2014 21:10:02 -0600 Subject: [PATCH 062/249] Update Rust. --- base.rs | 36 ++++++++++++++++-------------------- cocoa.rc | 4 +--- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/base.rs b/base.rs index be897a2..80a99cc 100644 --- a/base.rs +++ b/base.rs @@ -22,28 +22,28 @@ pub type id = libc::intptr_t; pub static nil: id = 0 as id; extern { - pub fn class_addMethod(cls: Class, name: SEL, imp: IMP, types: *libc::c_char) -> bool; + pub fn class_addMethod(cls: Class, name: SEL, imp: IMP, types: *const libc::c_char) -> bool; pub fn class_addIvar(cls: Class, - name: *libc::c_char, + name: *const libc::c_char, size: libc::size_t, alignment: u8, - types: *libc::c_char) + types: *const libc::c_char) -> bool; - pub fn object_setInstanceVariable(obj: id, name: *libc::c_char, value: *libc::c_void); - pub fn object_getInstanceVariable(obj: id, name: *libc::c_char, outValue: **libc::c_void); - pub fn objc_allocateClassPair(superclass: Class, name: *libc::c_char, extraBytes: libc::size_t) + pub fn object_setInstanceVariable(obj: id, name: *const libc::c_char, value: *mut libc::c_void); + pub fn object_getInstanceVariable(obj: id, name: *const libc::c_char, outValue: *mut *mut libc::c_void); + pub fn objc_allocateClassPair(superclass: Class, name: *const libc::c_char, extraBytes: libc::size_t) -> Class; - pub fn objc_getClass(name: *libc::c_char) -> id; + pub fn objc_getClass(name: *const libc::c_char) -> id; pub fn objc_msgSend(theReceiver: id, theSelector: SEL) -> id; pub fn objc_registerClassPair(cls: Class); - pub fn sel_registerName(name: *libc::c_char) -> SEL; + pub fn sel_registerName(name: *const libc::c_char) -> SEL; } /// A convenience method to convert the name of a class to the class object itself. #[inline] pub fn class(name: &str) -> id { unsafe { - name.to_c_str().with_ref(|c_string| objc_getClass(c_string)) + objc_getClass(name.to_c_str().as_ptr()) } } @@ -51,7 +51,7 @@ pub fn class(name: &str) -> id { #[inline] pub fn selector(name: &str) -> SEL { unsafe { - name.to_c_str().with_ref(|c_string| sel_registerName(c_string)) + sel_registerName(name.to_c_str().as_ptr()) } } @@ -113,7 +113,7 @@ impl<'a> ObjCSelector for &'a str { fn as_selector(self) -> SEL { // TODO(pcwalton): Cache somehow. unsafe { - self.to_c_str().with_ref(|c_string| sel_registerName(c_string)) + sel_registerName(self.to_c_str().as_ptr()) } } } @@ -218,16 +218,12 @@ mod test { } let ns_object = class("NSObject"); - let my_object = "MyObject".to_c_str().with_ref(|s| { - unsafe { - objc_allocateClassPair(ns_object, s, 0 as libc::size_t) - } - }); + let my_object = unsafe { + objc_allocateClassPair(ns_object, "MyObject".to_c_str().as_ptr(), 0 as libc::size_t) + }; unsafe { let doSomething = selector("doSomething"); - let _ = "@@:".to_c_str().with_ref(|types| { - class_addMethod(my_object, doSomething, MyObject_doSomething, types) - }); + let _ = class_addMethod(my_object, doSomething, MyObject_doSomething, "@@:".to_c_str().as_ptr()); objc_registerClassPair(my_object); @@ -238,7 +234,7 @@ mod test { } } -#[link(name = "msgsend")] +#[link(name = "msgsend", kind = "static")] extern { fn invoke_msg_double(theReceiver: id, theSelector: SEL) -> f64; fn invoke_msg_id(theReceiver: id, theSelector: SEL) -> id; diff --git a/cocoa.rc b/cocoa.rc index f22381d..b0bede1 100644 --- a/cocoa.rc +++ b/cocoa.rc @@ -7,9 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![crate_id = "github.com/mozilla-servo/rust-cocoa#cocoa:0.1"] -#![crate_type = "lib"] -#![crate_type = "dylib"] +#![crate_name = "cocoa"] #![crate_type = "rlib"] #![comment = "The Servo Parallel Browser Project"] From f24aa3e1c845db32f0a9ed336453b22bfc63b7f2 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Mon, 11 Aug 2014 18:37:04 -0600 Subject: [PATCH 063/249] Fixes for building 32bit. --- Makefile.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.in b/Makefile.in index f9f4b61..378ddfc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,10 +1,10 @@ VPATH=%VPATH% -CC=gcc +CC ?= gcc RUSTC ?= rustc AR ?= ar RUSTFLAGS ?= -CFLAGS=-Wall +CFLAGS += -Wall RUST_SRC = $(shell find $(VPATH)/. -type f -name '*.rs') From 55a92e9985b8eee4f90e168ea9736dba9b2fd09d Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Mon, 25 Aug 2014 18:26:08 -0600 Subject: [PATCH 064/249] Cargoify rust-cocoa This must build on non-mac platform too, since Cargo doesn't have support for conditional dependencies yet. --- .gitignore | 2 ++ Cargo.toml | 12 ++++++++++++ Makefile.in | 6 +++--- makefile.msgsend | 20 ++++++++++++++++++++ appkit.rs => src/appkit.rs | 0 base.rs => src/base.rs | 0 cocoa.rc => src/lib.rs | 2 ++ msgsend.m => src/msgsend.m | 0 8 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 Cargo.toml create mode 100644 makefile.msgsend rename appkit.rs => src/appkit.rs (100%) rename base.rs => src/base.rs (100%) rename cocoa.rc => src/lib.rs (92%) rename msgsend.m => src/msgsend.m (100%) diff --git a/.gitignore b/.gitignore index 5f68b7f..e04cf59 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ *.dummy cocoa-test build +/target +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f90a3b1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] + +name = "cocoa" +version = "0.1.0" +authors = ["The Servo Project Developers"] + +build = "make -f makefile.msgsend" + +[lib] + +name = "cocoa" +crate-type = ["rlib"] diff --git a/Makefile.in b/Makefile.in index 378ddfc..6552cdd 100644 --- a/Makefile.in +++ b/Makefile.in @@ -6,16 +6,16 @@ AR ?= ar RUSTFLAGS ?= CFLAGS += -Wall -RUST_SRC = $(shell find $(VPATH)/. -type f -name '*.rs') +RUST_SRC = $(shell find $(VPATH)/src -type f -name '*.rs') .PHONY: all all: libcocoa.dummy -libcocoa.dummy: cocoa.rc $(RUST_SRC) libmsgsend.a +libcocoa.dummy: src/lib.rs $(RUST_SRC) libmsgsend.a $(RUSTC) $(RUSTFLAGS) $< --out-dir . touch $@ -cocoa-test: cocoa.rc $(RUST_SRC) libmsgsend.a +cocoa-test: src/lib.rs $(RUST_SRC) libmsgsend.a $(RUSTC) $(RUSTFLAGS) $< -o $@ --test libmsgsend.a: msgsend.o diff --git a/makefile.msgsend b/makefile.msgsend new file mode 100644 index 0000000..e76812a --- /dev/null +++ b/makefile.msgsend @@ -0,0 +1,20 @@ +CC ?= gcc +AR ?= ar +CFLAGS += -Wall + +.PHONY : all +ifeq (darwin,$(findstring darwin,$(TARGET))) + +all: $(OUT_DIR)/libmsgsend.a + +$(OUT_DIR)/libmsgsend.a: $(OUT_DIR)/msgsend.o + $(AR) rcs $(OUT_DIR)/libmsgsend.a $(OUT_DIR)/msgsend.o + +$(OUT_DIR)/msgsend.o: src/msgsend.m + $(CC) $(CFLAGS) $< -o $@ -c + +else + +all: + +endif diff --git a/appkit.rs b/src/appkit.rs similarity index 100% rename from appkit.rs rename to src/appkit.rs diff --git a/base.rs b/src/base.rs similarity index 100% rename from base.rs rename to src/base.rs diff --git a/cocoa.rc b/src/lib.rs similarity index 92% rename from cocoa.rc rename to src/lib.rs index b0bede1..c07bc78 100644 --- a/cocoa.rc +++ b/src/lib.rs @@ -20,6 +20,8 @@ extern crate libc; extern crate std; +#[cfg(target_os="macos")] pub mod appkit; +#[cfg(target_os="macos")] pub mod base; diff --git a/msgsend.m b/src/msgsend.m similarity index 100% rename from msgsend.m rename to src/msgsend.m From 835b416c72cdc42a6d5cbbf4cf1e2f0dd687f4f2 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Mon, 25 Aug 2014 22:35:56 -0600 Subject: [PATCH 065/249] Fix Makefile omission post-Cargoification --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 6552cdd..877d281 100644 --- a/Makefile.in +++ b/Makefile.in @@ -21,7 +21,7 @@ cocoa-test: src/lib.rs $(RUST_SRC) libmsgsend.a libmsgsend.a: msgsend.o $(AR) rcs libmsgsend.a msgsend.o -msgsend.o: msgsend.m +msgsend.o: src/msgsend.m $(CC) $(CFLAGS) $< -o $@ -c check: cocoa-test From b7fef8665d6d3fa12326663651d0bd0b51eb4e6d Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Tue, 16 Sep 2014 11:33:53 -0700 Subject: [PATCH 066/249] Rust upgrade --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index c07bc78..f1485b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,6 @@ #![allow(non_snake_case_functions)] extern crate libc; -extern crate std; #[cfg(target_os="macos")] pub mod appkit; From 8cda2336fce1a20b2b4da47c8b2d3bc448ad3ee6 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Fri, 19 Sep 2014 09:57:33 -0700 Subject: [PATCH 067/249] Make invoke_msg bindings public for rust-alert --- src/base.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/base.rs b/src/base.rs index 80a99cc..c882c34 100644 --- a/src/base.rs +++ b/src/base.rs @@ -236,20 +236,20 @@ mod test { #[link(name = "msgsend", kind = "static")] extern { - fn invoke_msg_double(theReceiver: id, theSelector: SEL) -> f64; - fn invoke_msg_id(theReceiver: id, theSelector: SEL) -> id; - fn invoke_msg_id_id_id_id_id_id(theReceiver: id, - theSelector: SEL, - a: id, - b: id, - c: id, - d: id, - e: id) - -> id; - fn invoke_msg_id_NSRect(theReceiver: id, theSelector: SEL, a: &NSRect) -> id; - fn invoke_msg_long(theReceiver: id, theSelector: SEL) -> c_long; - fn invoke_msg_void(theReceiver: id, theSelector: SEL); - fn invoke_msg_void_bool(theReceiver: id, theSelector: SEL, a: bool); - fn invoke_msg_void_id(theReceiver: id, theSelector: SEL, a: id); + pub fn invoke_msg_double(theReceiver: id, theSelector: SEL) -> f64; + pub fn invoke_msg_id(theReceiver: id, theSelector: SEL) -> id; + pub fn invoke_msg_id_id_id_id_id_id(theReceiver: id, + theSelector: SEL, + a: id, + b: id, + c: id, + d: id, + e: id) + -> id; + pub fn invoke_msg_id_NSRect(theReceiver: id, theSelector: SEL, a: &NSRect) -> id; + pub fn invoke_msg_long(theReceiver: id, theSelector: SEL) -> c_long; + pub fn invoke_msg_void(theReceiver: id, theSelector: SEL); + pub fn invoke_msg_void_bool(theReceiver: id, theSelector: SEL, a: bool); + pub fn invoke_msg_void_id(theReceiver: id, theSelector: SEL, a: id); } From be0f6bd4d70cb8ca31c6a8ee9be4f630f9e221ee Mon Sep 17 00:00:00 2001 From: Alex Chandel Date: Wed, 17 Sep 2014 15:18:57 -0400 Subject: [PATCH 068/249] Added hello_world example, expanded appkit This commit adds a Hello World program, which creates and displays a minimalist Cocoa app with a Menu Bar, a Quit menu, and a Window. It also wraps the Cocoa methods used in hello_world in static functions in appkit, inside separate modules for different classes. Later on, Cocoa methods could be implemented as traits on `id` if that turns out to be easier. --- examples/hello_world.rs | 58 ++++++++++++++ src/appkit.rs | 168 ++++++++++++++++++++++++++++++++++++++-- src/base.rs | 114 +++++++++++++++++++++++++-- src/lib.rs | 2 +- src/msgsend.m | 22 ++++++ 5 files changed, 349 insertions(+), 15 deletions(-) create mode 100644 examples/hello_world.rs diff --git a/examples/hello_world.rs b/examples/hello_world.rs new file mode 100644 index 0000000..252f5b2 --- /dev/null +++ b/examples/hello_world.rs @@ -0,0 +1,58 @@ +extern crate cocoa; + +use cocoa::base::{NSUInteger, nil, ObjCSelector}; +use cocoa::appkit::{NSApp, NSRect, NSPoint, NSSize, + NSProcessInfo, + NSApplication, NSApplicationActivationPolicyRegular, + NSWindow, NSTitledWindowMask, NSBackingStoreBuffered, + NSString, + NSMenu, NSMenuItem}; + +fn main() { + unsafe { + let app = NSApp(); + NSApplication::setActivationPolicy_(app, NSApplicationActivationPolicyRegular); + + // create Menu Bar + let menubar = NSMenu::new(); + let app_menu_item = NSMenuItem::new(); + NSMenu::addItem_(menubar, app_menu_item); + NSApplication::setMainMenu_(app, menubar); + + // create Application menu + let app_menu = NSMenu::new(); + let app_name = NSProcessInfo::processName(NSProcessInfo::processInfo()); + let quit_prefix = NSString::from_str("Quit \0"); + let quit_title = NSString::stringByAppendingString_( + quit_prefix, + app_name + ); + let quit_action = "terminate:".as_selector(); + let quit_key = NSString::from_str("q\0"); + let quit_item = NSMenuItem::initWithTitle_action_keyEquivalent_( + NSMenuItem::alloc(), + quit_title, + quit_action, + quit_key + ); + NSMenu::addItem_(app_menu, quit_item); + NSMenuItem::setSubmenu_(app_menu_item, app_menu); + + // create Window + let window = NSWindow::initWithContentRect_styleMask_backing_defer_( + NSWindow::alloc(), + NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), + NSTitledWindowMask as NSUInteger, + NSBackingStoreBuffered, + false + ); + // segfaults in invoke_msg_NSPoint_NSPoint(): + // NSWindow::cascadeTopLeftFromPoint_(window, NSPoint::new(20., 20.)); + let title = NSString::from_str("Hello World!\0"); + NSWindow::setTitle_(window, title); + NSWindow::makeKeyAndOrderFront_(window, nil); + + NSApplication::activateIgnoringOtherApps_(app, true); + NSApplication::run(app); + } +} diff --git a/src/appkit.rs b/src/appkit.rs index 4af0c96..6b83714 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -11,13 +11,14 @@ use base::{ObjCMethodCall, id}; pub type CGFloat = f32; -#[allow(dead_code)] +#[repr(C)] pub struct NSPoint { - x: f64, - y: f64, + pub x: f64, + pub y: f64, } impl NSPoint { + #[inline] pub fn new(x: f64, y: f64) -> NSPoint { NSPoint { x: x, @@ -26,13 +27,14 @@ impl NSPoint { } } -#[allow(dead_code)] +#[repr(C)] pub struct NSSize { - width: f64, - height: f64, + pub width: f64, + pub height: f64, } impl NSSize { + #[inline] pub fn new(width: f64, height: f64) -> NSSize { NSSize { width: width, @@ -41,11 +43,22 @@ impl NSSize { } } +#[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 + } + } +} + #[link(name = "AppKit", kind = "framework")] extern {} @@ -53,3 +66,146 @@ pub unsafe fn NSApp() -> id { "NSApplication".send("sharedApplication", ()) } +#[repr(i64)] +pub enum NSApplicationActivationPolicy { + NSApplicationActivationPolicyRegular = 0, + NSApplicationActivationPolicyERROR = -1 +} + +#[repr(u64)] +pub enum NSWindowMask { + NSBorderlessWindowMask = 0, + NSTitledWindowMask = 1 << 0, + NSClosableWindowMask = 1 << 1, + NSMiniaturizableWindowMask = 1 << 2, + NSResizableWindowMask = 1 << 3, + + NSTexturedBackgroundWindowMask = 1 << 8, + + NSUnifiedTitleAndToolbarWindowMask = 1 << 12, + + NSFullScreenWindowMask = 1 << 14 +} + +#[repr(u64)] +pub enum NSBackingStoreType { + NSBackingStoreRetained = 0, + NSBackingStoreNonretained = 1, + NSBackingStoreBuffered = 2 +} + +pub mod NSProcessInfo { + use base::{id, ObjCMethodCall}; + + pub unsafe fn processInfo() -> id { + "NSProcessInfo".send("processInfo", ()) + } + + pub unsafe fn processName(this: id) -> id { + this.send("processName", ()) + } +} + +pub mod NSApplication { + use base::{id, NSInteger, ObjCMethodCall}; + use appkit::NSApplicationActivationPolicy; + + pub unsafe fn setActivationPolicy_(this: id, policy: NSApplicationActivationPolicy) -> bool { + this.send_bool("setActivationPolicy:", policy as NSInteger) + } + + pub unsafe fn setMainMenu_(this: id, menu: id) { + this.send_void("setMainMenu:", menu) + } + + pub unsafe fn activateIgnoringOtherApps_(this: id, ignore: bool) { + this.send_void("activateIgnoringOtherApps:", ignore); + } + + pub unsafe fn run(this: id) { + this.send_void("run", ()); + } +} + +pub mod NSMenu { + use base::{id, ObjCMethodCall}; + + pub unsafe fn new() -> id { + "NSMenu".send("new", ()) + } + + pub unsafe fn addItem_(this: id, menu_item: id) { + this.send_void("addItem:", menu_item) + } +} + +pub mod NSMenuItem { + use base::{id, ObjCMethodCall, SEL}; + + pub unsafe fn alloc() -> id { + "NSMenuItem".send("alloc", ()) + } + + pub unsafe fn new() -> id { + "NSMenuItem".send("new", ()) + } + + pub unsafe fn initWithTitle_action_keyEquivalent_(this: id, title: id, action: SEL, key: id) -> id { + this.send("initWithTitle:action:keyEquivalent:", (title, action, key)) + } + + pub unsafe fn setSubmenu_(this: id, submenu: id) { + this.send_void("setSubmenu:", submenu) + } +} + +pub mod NSWindow { + use base::{id, NSUInteger, ObjCMethodCall}; + use appkit::{NSRect, NSPoint, NSBackingStoreType}; + + pub unsafe fn alloc() -> id { + "NSWindow".send("alloc", ()) + } + + pub unsafe fn initWithContentRect_styleMask_backing_defer_(this: id, + rect: NSRect, + style: NSUInteger, + backing: NSBackingStoreType, + defer: bool) -> id { + this.send("initWithContentRect:styleMask:backing:defer:", + (rect, style, backing as NSUInteger, defer)) + } + + pub unsafe fn cascadeTopLeftFromPoint_(this: id, top_left: NSPoint) -> NSPoint { + this.send_point("cascadeTopLeftFromPoint:", top_left) + } + + pub unsafe fn setTitle_(this: id, title: id) { + this.send_void("setTitle:", title); + } + + pub unsafe fn makeKeyAndOrderFront_(this: id, sender: id) { + this.send_void("makeKeyAndOrderFront:", sender) + } +} + +pub mod NSString { + use base::{id, ObjCMethodCall}; + + pub unsafe fn alloc() -> id { + "NSString".send("alloc", ()) + } + + pub unsafe fn initWithUTF8String_(this: id, c_string: *const u8) -> id { + this.send("initWithUTF8String:", c_string as id) + } + + pub unsafe fn stringByAppendingString_(this: id, other: id) -> id { + this.send("stringByAppendingString:", other) + } + + pub unsafe fn from_str(string: &str) -> id { + initWithUTF8String_(alloc(), string.as_ptr()) + } +} + diff --git a/src/base.rs b/src/base.rs index c882c34..62c4e7b 100644 --- a/src/base.rs +++ b/src/base.rs @@ -7,9 +7,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use appkit::NSRect; +use appkit::{NSRect, NSPoint}; -use libc::{c_double, c_long}; +use libc::{c_double, c_long, c_ulong, c_char}; use libc; pub type Class = libc::intptr_t; @@ -19,6 +19,16 @@ pub type SEL = libc::intptr_t; #[allow(non_camel_case_types)] pub type id = libc::intptr_t; +#[cfg(target_word_size = "32")] +pub type NSInteger = libc::c_int; +#[cfg(target_word_size = "32")] +pub type NSUInteger = libc::c_uint; + +#[cfg(target_word_size = "64")] +pub type NSInteger = libc::c_long; +#[cfg(target_word_size = "64")] +pub type NSUInteger = libc::c_ulong; + pub static nil: id = 0 as id; extern { @@ -57,50 +67,81 @@ pub fn selector(name: &str) -> SEL { /// A trait that allows syntax like: /// -/// let string = "NSString".send("alloc").send("initWithCString:", "Hello world!"); +/// let string = "NSString".send("alloc").send("initWithUTF8String:", "Hello world!"); pub trait ObjCMethodCall { unsafe fn send(self, selector: S, args: A) -> id; unsafe fn send_double(self, selector: S, args: A) -> c_double; unsafe fn send_long(self, selector: S, args: A) -> c_long; unsafe fn send_void(self, selector: S, args: A); + unsafe fn send_bool(self, selector: S, args: A) -> bool; + unsafe fn send_point(self, selector: S, args: A) -> NSPoint; + } impl ObjCMethodCall for id { + #[inline] unsafe fn send(self, selector: S, args: A) -> id { args.send_args(self, selector.as_selector()) } + #[inline] unsafe fn send_double(self, selector: S, args: A) -> c_double { args.send_double_args(self, selector.as_selector()) } + #[inline] unsafe fn send_long(self, selector: S, args: A) -> c_long { args.send_long_args(self, selector.as_selector()) } + #[inline] unsafe fn send_void(self, selector: S, args: A) { args.send_void_args(self, selector.as_selector()) } + #[inline] + unsafe fn send_bool(self, selector: S, args: A) + -> bool { + args.send_bool_args(self, selector.as_selector()) + } + #[inline] + unsafe fn send_point(self, selector: S, args: A) + -> NSPoint { + args.send_point_args(self, selector.as_selector()) + } } /// A convenience implementation that allows methods on class names to be called directly, as in: -/// +/// /// "NSString".send("alloc") impl<'a> ObjCMethodCall for &'a str { + #[inline] unsafe fn send(self, selector: S, args: A) -> id { args.send_args(class(self), selector.as_selector()) } + #[inline] unsafe fn send_double(self, selector: S, args: A) -> c_double { args.send_double_args(class(self), selector.as_selector()) } + #[inline] unsafe fn send_long(self, selector: S, args: A) -> c_long { args.send_long_args(class(self), selector.as_selector()) } + #[inline] unsafe fn send_void(self, selector: S, args: A) { args.send_void_args(class(self), selector.as_selector()) } + #[inline] + unsafe fn send_bool(self, selector: S, args: A) + -> bool { + args.send_bool_args(class(self), selector.as_selector()) + } + #[inline] + unsafe fn send_point(self, selector: S, args: A) + -> NSPoint { + args.send_point_args(class(self), selector.as_selector()) + } } /// A trait that allows C strings to be used as selectors without having to convert them first. @@ -138,6 +179,12 @@ trait ObjCMethodLongArgs { trait ObjCMethodVoidArgs { unsafe fn send_void_args(self, receiver: id, selector: SEL); } +trait ObjCMethodBoolArgs { + unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool; +} +trait ObjCMethodPointArgs { + unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint; +} impl ObjCMethodArgs for () { #[inline] @@ -146,11 +193,10 @@ impl ObjCMethodArgs for () { } } -impl ObjCMethodArgs for (id, id, id, id, id) { +impl ObjCMethodArgs for id { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - let (first, second, third, fourth, fifth) = self; - invoke_msg_id_id_id_id_id_id(receiver, selector, first, second, third, fourth, fifth) + invoke_msg_id_id(receiver, selector, self) } } @@ -161,6 +207,30 @@ impl ObjCMethodArgs for NSRect { } } +impl ObjCMethodArgs for (id, SEL, id) { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second, third) = self; + invoke_msg_id_id_SEL_id(receiver, selector, first, second, third) + } +} + +impl ObjCMethodArgs for (NSRect, c_ulong, c_ulong, bool) { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second, third, fourth) = self; + invoke_msg_id_NSRect_ulong_ulong_bool(receiver, selector, first, second, third, fourth) + } +} + +impl ObjCMethodArgs for (id, id, id, id, id) { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second, third, fourth, fifth) = self; + invoke_msg_id_id_id_id_id_id(receiver, selector, first, second, third, fourth, fifth) + } +} + impl ObjCMethodDoubleArgs for () { #[inline] unsafe fn send_double_args(self, receiver: id, selector: SEL) -> f64 { @@ -196,6 +266,24 @@ impl ObjCMethodVoidArgs for id { } } +impl ObjCMethodBoolArgs for c_long { + #[inline] + unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool { + invoke_msg_bool_long(receiver, selector, self) + } +} + +impl ObjCMethodPointArgs for NSPoint { + #[inline] + unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint { + println!("before"); + let stret: NSPoint = NSPoint::new(0., 0.); + invoke_msg_NSPoint_NSPoint(&stret, receiver, selector, self); + println!("after"); + stret + } +} + /// A trait that simulates variadic parameters for method calls. #[cfg(test)] @@ -238,6 +326,15 @@ mod test { extern { pub fn invoke_msg_double(theReceiver: id, theSelector: SEL) -> f64; pub fn invoke_msg_id(theReceiver: id, theSelector: SEL) -> id; + pub fn invoke_msg_id_id(theReceiver: id, theSelector: SEL, a: id) -> id; + pub fn invoke_msg_id_NSRect(theReceiver: id, theSelector: SEL, a: &NSRect) -> id; + pub fn invoke_msg_id_id_SEL_id(theReceiver: id, theSelector: SEL, a: id, b: SEL, c: id) -> id; + pub fn invoke_msg_id_NSRect_ulong_ulong_bool(theReceiver: id, + theSelector: SEL, + a: NSRect, + b: c_ulong, + c: c_ulong, + d: bool) -> id; pub fn invoke_msg_id_id_id_id_id_id(theReceiver: id, theSelector: SEL, a: id, @@ -246,10 +343,11 @@ extern { d: id, e: id) -> id; - pub fn invoke_msg_id_NSRect(theReceiver: id, theSelector: SEL, a: &NSRect) -> id; pub fn invoke_msg_long(theReceiver: id, theSelector: SEL) -> c_long; pub fn invoke_msg_void(theReceiver: id, theSelector: SEL); pub fn invoke_msg_void_bool(theReceiver: id, theSelector: SEL, a: bool); pub fn invoke_msg_void_id(theReceiver: id, theSelector: SEL, a: id); + pub fn invoke_msg_bool_long(theReceiver: id, theSelector: SEL, a: c_long) -> bool; + pub fn invoke_msg_NSPoint_NSPoint(stretAddr: &NSPoint, theReceiver: id, theSelector: SEL, a: NSPoint); } diff --git a/src/lib.rs b/src/lib.rs index f1485b5..d6e3ab5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,7 @@ #![feature(globs)] -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] extern crate libc; diff --git a/src/msgsend.m b/src/msgsend.m index 413b0aa..69cfaae 100644 --- a/src/msgsend.m +++ b/src/msgsend.m @@ -22,14 +22,26 @@ id invoke_msg_id(id theReceiver, SEL theSelector) { return objc_msgSend(theReceiver, theSelector); } +id invoke_msg_id_id(id theReceiver, SEL theSelector, id a) { + return objc_msgSend(theReceiver, theSelector, a); +} + id invoke_msg_id_NSRect(id theReceiver, SEL theSelector, NSRect *rect) { return objc_msgSend(theReceiver, theSelector, *rect); } +id invoke_msg_id_id_SEL_id(id theReceiver, SEL theSelector, id a, SEL b, id c) { + return objc_msgSend(theReceiver, theSelector, a, b, c); +} + id invoke_msg_id_id_id_id_id_id(id theReceiver, SEL theSelector, id a, id b, id c, id d, id e) { return objc_msgSend(theReceiver, theSelector, a, b, c, d, e); } +id invoke_msg_id_NSRect_ulong_ulong_bool(id theReceiver, SEL theSelector, NSRect a, unsigned long b, unsigned long c, bool d) { + return objc_msgSend(theReceiver, theSelector, a, b, c, d); +} + long invoke_msg_long(id theReceiver, SEL theSelector) { return (long)objc_msgSend(theReceiver, theSelector); } @@ -46,3 +58,13 @@ void invoke_msg_void_id(id theReceiver, SEL theSelector, id id) { objc_msgSend(theReceiver, theSelector, id); } +char invoke_msg_bool_long(id theReceiver, SEL theSelector, long a) { + return objc_msgSend(theReceiver, theSelector, a); +} + +/** segfaults */ +void invoke_msg_NSPoint_NSPoint(NSPoint *stretAddr, id theReceiver, SEL theSelector, NSPoint point) { + void (*s)(void *ret, id self, SEL op, ...) = (void *)objc_msgSend_stret; + return s((void *)stretAddr, theReceiver, theSelector, point); +} + From 1c0bcd8fa631fce193c0479ee552bf20a5513446 Mon Sep 17 00:00:00 2001 From: Alex Chandel Date: Wed, 17 Sep 2014 15:25:59 -0400 Subject: [PATCH 069/249] Provide NSWindow -(void)center This is to demonstrate moving the window in hello_world.rs as an alternative to cascadeTopLeftFromPoint. --- examples/hello_world.rs | 3 ++- src/appkit.rs | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 252f5b2..d51c1af 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -46,8 +46,9 @@ fn main() { NSBackingStoreBuffered, false ); - // segfaults in invoke_msg_NSPoint_NSPoint(): + // this segfaults in invoke_msg_NSPoint_NSPoint(): // NSWindow::cascadeTopLeftFromPoint_(window, NSPoint::new(20., 20.)); + NSWindow::center(window); let title = NSString::from_str("Hello World!\0"); NSWindow::setTitle_(window, title); NSWindow::makeKeyAndOrderFront_(window, nil); diff --git a/src/appkit.rs b/src/appkit.rs index 6b83714..6490e3f 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -187,6 +187,10 @@ pub mod NSWindow { pub unsafe fn makeKeyAndOrderFront_(this: id, sender: id) { this.send_void("makeKeyAndOrderFront:", sender) } + + pub unsafe fn center(this: id) { + this.send_void("center", ()) + } } pub mod NSString { From b14fa888cf4564b869f0d5203d2c3ae468cd8bf4 Mon Sep 17 00:00:00 2001 From: Alex Chandel Date: Thu, 18 Sep 2014 02:24:28 -0400 Subject: [PATCH 070/249] Switch class implementation to traits/impls. --- examples/hello_world.rs | 48 ++++++------ src/appkit.rs | 166 +++++++++++++++++++++++++--------------- 2 files changed, 127 insertions(+), 87 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index d51c1af..a65b5d9 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -2,7 +2,7 @@ extern crate cocoa; use cocoa::base::{NSUInteger, nil, ObjCSelector}; use cocoa::appkit::{NSApp, NSRect, NSPoint, NSSize, - NSProcessInfo, + NSAutoreleasePool, NSProcessInfo, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, NSTitledWindowMask, NSBackingStoreBuffered, NSString, @@ -10,37 +10,35 @@ use cocoa::appkit::{NSApp, NSRect, NSPoint, NSSize, fn main() { unsafe { + let pool = NSAutoreleasePool::new(nil); + let app = NSApp(); - NSApplication::setActivationPolicy_(app, NSApplicationActivationPolicyRegular); + app.setActivationPolicy_(NSApplicationActivationPolicyRegular); // create Menu Bar - let menubar = NSMenu::new(); - let app_menu_item = NSMenuItem::new(); - NSMenu::addItem_(menubar, app_menu_item); - NSApplication::setMainMenu_(app, menubar); + let menubar = NSMenu::new(nil); + let app_menu_item = NSMenuItem::new(nil); + menubar.addItem_(app_menu_item); + app.setMainMenu_(menubar); // create Application menu - let app_menu = NSMenu::new(); - let app_name = NSProcessInfo::processName(NSProcessInfo::processInfo()); - let quit_prefix = NSString::from_str("Quit \0"); - let quit_title = NSString::stringByAppendingString_( - quit_prefix, - app_name + let app_menu = NSMenu::new(nil); + let quit_prefix = NSString::alloc(nil).init_str("Quit \0"); + let quit_title = quit_prefix.stringByAppendingString_( + NSProcessInfo::processInfo(nil).processName() ); let quit_action = "terminate:".as_selector(); - let quit_key = NSString::from_str("q\0"); - let quit_item = NSMenuItem::initWithTitle_action_keyEquivalent_( - NSMenuItem::alloc(), + let quit_key = NSString::alloc(nil).init_str("q\0"); + let quit_item = NSMenuItem::alloc(nil).initWithTitle_action_keyEquivalent_( quit_title, quit_action, quit_key ); - NSMenu::addItem_(app_menu, quit_item); - NSMenuItem::setSubmenu_(app_menu_item, app_menu); + app_menu.addItem_(quit_item); + app_menu_item.setSubmenu_(app_menu); // create Window - let window = NSWindow::initWithContentRect_styleMask_backing_defer_( - NSWindow::alloc(), + let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_( NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), NSTitledWindowMask as NSUInteger, NSBackingStoreBuffered, @@ -48,12 +46,12 @@ fn main() { ); // this segfaults in invoke_msg_NSPoint_NSPoint(): // NSWindow::cascadeTopLeftFromPoint_(window, NSPoint::new(20., 20.)); - NSWindow::center(window); - let title = NSString::from_str("Hello World!\0"); - NSWindow::setTitle_(window, title); - NSWindow::makeKeyAndOrderFront_(window, nil); + window.center(); + let title = NSString::alloc(nil).init_str("Hello World!\0"); + window.setTitle_(title); + window.makeKeyAndOrderFront_(nil); - NSApplication::activateIgnoringOtherApps_(app, true); - NSApplication::run(app); + app.activateIgnoringOtherApps_(true); + app.run(); } } diff --git a/src/appkit.rs b/src/appkit.rs index 6490e3f..ff613e0 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use base::{ObjCMethodCall, id}; +use base::{ObjCMethodCall, id, SEL, nil, NSInteger, NSUInteger}; pub type CGFloat = f32; @@ -94,122 +94,164 @@ pub enum NSBackingStoreType { NSBackingStoreBuffered = 2 } -pub mod NSProcessInfo { - use base::{id, ObjCMethodCall}; +pub trait NSAutoreleasePool { + unsafe fn new(_: Self) -> id { + "NSAutoreleasePool".send("new", ()) + } - pub unsafe fn processInfo() -> id { + unsafe fn autorelease(self) -> Self; +} + +impl NSAutoreleasePool for id { + unsafe fn autorelease(self) -> id { + self.send("autorelease", ()) + } +} + +pub trait NSProcessInfo { + unsafe fn processInfo(_: Self) -> id { "NSProcessInfo".send("processInfo", ()) } - pub unsafe fn processName(this: id) -> id { - this.send("processName", ()) + unsafe fn processName(self) -> id; +} + +impl NSProcessInfo for id { + unsafe fn processName(self) -> id { + self.send("processName", ()) } } -pub mod NSApplication { - use base::{id, NSInteger, ObjCMethodCall}; - use appkit::NSApplicationActivationPolicy; - - pub unsafe fn setActivationPolicy_(this: id, policy: NSApplicationActivationPolicy) -> bool { - this.send_bool("setActivationPolicy:", policy as NSInteger) +pub trait NSApplication { + unsafe fn sharedApplication(_: Self) -> id { + "NSApplication".send("sharedApplication", ()) } - pub unsafe fn setMainMenu_(this: id, menu: id) { - this.send_void("setMainMenu:", menu) + unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> bool; + unsafe fn setMainMenu_(self, menu: id); + unsafe fn activateIgnoringOtherApps_(self, ignore: bool); + unsafe fn run(self); +} + +impl NSApplication for id { + unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> bool { + self.send_bool("setActivationPolicy:", policy as NSInteger) } - pub unsafe fn activateIgnoringOtherApps_(this: id, ignore: bool) { - this.send_void("activateIgnoringOtherApps:", ignore); + unsafe fn setMainMenu_(self, menu: id) { + self.send_void("setMainMenu:", menu) } - pub unsafe fn run(this: id) { - this.send_void("run", ()); + unsafe fn activateIgnoringOtherApps_(self, ignore: bool) { + self.send_void("activateIgnoringOtherApps:", ignore); + } + + unsafe fn run(self) { + self.send_void("run", ()); } } -pub mod NSMenu { - use base::{id, ObjCMethodCall}; - - pub unsafe fn new() -> id { +pub trait NSMenu { + unsafe fn new(_: Self) -> id { "NSMenu".send("new", ()) } - pub unsafe fn addItem_(this: id, menu_item: id) { - this.send_void("addItem:", menu_item) + unsafe fn addItem_(self, menu_item: id); +} + +impl NSMenu for id { + unsafe fn addItem_(self, menu_item: id) { + self.send_void("addItem:", menu_item) } } -pub mod NSMenuItem { - use base::{id, ObjCMethodCall, SEL}; - - pub unsafe fn alloc() -> id { +pub trait NSMenuItem { + unsafe fn alloc(_: Self) -> id { "NSMenuItem".send("alloc", ()) } - pub unsafe fn new() -> id { + unsafe fn new(_: Self) -> id { "NSMenuItem".send("new", ()) } - pub unsafe fn initWithTitle_action_keyEquivalent_(this: id, title: id, action: SEL, key: id) -> id { - this.send("initWithTitle:action:keyEquivalent:", (title, action, key)) + unsafe fn initWithTitle_action_keyEquivalent_(self, title: id, action: SEL, key: id) -> id; + unsafe fn setSubmenu_(self, submenu: id); +} + +impl NSMenuItem for id { + unsafe fn initWithTitle_action_keyEquivalent_(self, title: id, action: SEL, key: id) -> id { + self.send("initWithTitle:action:keyEquivalent:", (title, action, key)) } - pub unsafe fn setSubmenu_(this: id, submenu: id) { - this.send_void("setSubmenu:", submenu) + unsafe fn setSubmenu_(self, submenu: id) { + self.send_void("setSubmenu:", submenu) } } -pub mod NSWindow { - use base::{id, NSUInteger, ObjCMethodCall}; - use appkit::{NSRect, NSPoint, NSBackingStoreType}; - - pub unsafe fn alloc() -> id { +pub trait NSWindow { + unsafe fn alloc(_: Self) -> id { "NSWindow".send("alloc", ()) } - pub unsafe fn initWithContentRect_styleMask_backing_defer_(this: id, - rect: NSRect, - style: NSUInteger, - backing: NSBackingStoreType, - defer: bool) -> id { - this.send("initWithContentRect:styleMask:backing:defer:", + unsafe fn initWithContentRect_styleMask_backing_defer_(self, + rect: NSRect, + style: NSUInteger, + backing: NSBackingStoreType, + defer: bool) -> id; + unsafe fn cascadeTopLeftFromPoint_(self, top_left: NSPoint) -> NSPoint; + unsafe fn setTitle_(self, title: id); + unsafe fn makeKeyAndOrderFront_(self, sender: id); + unsafe fn center(self); +} + +impl NSWindow for id { + unsafe fn initWithContentRect_styleMask_backing_defer_(self, + rect: NSRect, + style: NSUInteger, + backing: NSBackingStoreType, + defer: bool) -> id { + self.send("initWithContentRect:styleMask:backing:defer:", (rect, style, backing as NSUInteger, defer)) } - pub unsafe fn cascadeTopLeftFromPoint_(this: id, top_left: NSPoint) -> NSPoint { - this.send_point("cascadeTopLeftFromPoint:", top_left) + unsafe fn cascadeTopLeftFromPoint_(self, top_left: NSPoint) -> NSPoint { + self.send_point("cascadeTopLeftFromPoint:", top_left) } - pub unsafe fn setTitle_(this: id, title: id) { - this.send_void("setTitle:", title); + unsafe fn setTitle_(self, title: id) { + self.send_void("setTitle:", title); } - pub unsafe fn makeKeyAndOrderFront_(this: id, sender: id) { - this.send_void("makeKeyAndOrderFront:", sender) + unsafe fn makeKeyAndOrderFront_(self, sender: id) { + self.send_void("makeKeyAndOrderFront:", sender) } - pub unsafe fn center(this: id) { - this.send_void("center", ()) + unsafe fn center(self) { + self.send_void("center", ()) } } -pub mod NSString { - use base::{id, ObjCMethodCall}; - - pub unsafe fn alloc() -> id { +pub trait NSString { + unsafe fn alloc(_: Self) -> id { "NSString".send("alloc", ()) } - pub unsafe fn initWithUTF8String_(this: id, c_string: *const u8) -> id { - this.send("initWithUTF8String:", c_string as id) + unsafe fn initWithUTF8String_(self, c_string: *const u8) -> id; + unsafe fn stringByAppendingString_(self, other: id) -> id; + unsafe fn init_str(self, string: &str) -> Self; +} + +impl NSString for id { + unsafe fn initWithUTF8String_(self, c_string: *const u8) -> id { + self.send("initWithUTF8String:", c_string as id) } - pub unsafe fn stringByAppendingString_(this: id, other: id) -> id { - this.send("stringByAppendingString:", other) + unsafe fn stringByAppendingString_(self, other: id) -> id { + self.send("stringByAppendingString:", other) } - pub unsafe fn from_str(string: &str) -> id { - initWithUTF8String_(alloc(), string.as_ptr()) + unsafe fn init_str(self, string: &str) -> id { + self.initWithUTF8String_(string.as_ptr()) } } From 86144041e5793ee58e5b76390d9c02fb2ad55f5c Mon Sep 17 00:00:00 2001 From: Justin Grimes Date: Thu, 18 Sep 2014 20:09:57 -0400 Subject: [PATCH 071/249] Fixed segfaul with invoke_msg_NSPoint_NSPoint. The issue was using objc_msgSend_stret instead of objc_msgSend. --- examples/hello_world.rs | 4 ++-- src/base.rs | 8 ++------ src/msgsend.m | 7 +++---- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index a65b5d9..85ae6b6 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -44,8 +44,8 @@ fn main() { NSBackingStoreBuffered, false ); - // this segfaults in invoke_msg_NSPoint_NSPoint(): - // NSWindow::cascadeTopLeftFromPoint_(window, NSPoint::new(20., 20.)); + + window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); window.center(); let title = NSString::alloc(nil).init_str("Hello World!\0"); window.setTitle_(title); diff --git a/src/base.rs b/src/base.rs index 62c4e7b..8185433 100644 --- a/src/base.rs +++ b/src/base.rs @@ -276,11 +276,7 @@ impl ObjCMethodBoolArgs for c_long { impl ObjCMethodPointArgs for NSPoint { #[inline] unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint { - println!("before"); - let stret: NSPoint = NSPoint::new(0., 0.); - invoke_msg_NSPoint_NSPoint(&stret, receiver, selector, self); - println!("after"); - stret + invoke_msg_NSPoint_NSPoint(receiver, selector, self) } } @@ -348,6 +344,6 @@ extern { pub fn invoke_msg_void_bool(theReceiver: id, theSelector: SEL, a: bool); pub fn invoke_msg_void_id(theReceiver: id, theSelector: SEL, a: id); pub fn invoke_msg_bool_long(theReceiver: id, theSelector: SEL, a: c_long) -> bool; - pub fn invoke_msg_NSPoint_NSPoint(stretAddr: &NSPoint, theReceiver: id, theSelector: SEL, a: NSPoint); + pub fn invoke_msg_NSPoint_NSPoint(theReceiver: id, theSelector: SEL, a: NSPoint) -> NSPoint; } diff --git a/src/msgsend.m b/src/msgsend.m index 69cfaae..f368c8c 100644 --- a/src/msgsend.m +++ b/src/msgsend.m @@ -62,9 +62,8 @@ char invoke_msg_bool_long(id theReceiver, SEL theSelector, long a) { return objc_msgSend(theReceiver, theSelector, a); } -/** segfaults */ -void invoke_msg_NSPoint_NSPoint(NSPoint *stretAddr, id theReceiver, SEL theSelector, NSPoint point) { - void (*s)(void *ret, id self, SEL op, ...) = (void *)objc_msgSend_stret; - return s((void *)stretAddr, theReceiver, theSelector, point); +NSPoint invoke_msg_NSPoint_NSPoint(id theReceiver, SEL theSelector, NSPoint point) { + NSPoint (*f)(id self, SEL op, NSPoint p) = (NSPoint *)objc_msgSend; + return f(theReceiver, theSelector, point); } From 01d8c72f325d3d532e93412a0e6a786025d9f174 Mon Sep 17 00:00:00 2001 From: Alex Chandel Date: Fri, 19 Sep 2014 03:22:00 -0400 Subject: [PATCH 072/249] Use autorelease in hello_world --- examples/hello_world.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 85ae6b6..165a827 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -16,13 +16,13 @@ fn main() { app.setActivationPolicy_(NSApplicationActivationPolicyRegular); // create Menu Bar - let menubar = NSMenu::new(nil); - let app_menu_item = NSMenuItem::new(nil); + let menubar = NSMenu::new(nil).autorelease(); + let app_menu_item = NSMenuItem::new(nil).autorelease(); menubar.addItem_(app_menu_item); app.setMainMenu_(menubar); // create Application menu - let app_menu = NSMenu::new(nil); + let app_menu = NSMenu::new(nil).autorelease(); let quit_prefix = NSString::alloc(nil).init_str("Quit \0"); let quit_title = quit_prefix.stringByAppendingString_( NSProcessInfo::processInfo(nil).processName() @@ -33,7 +33,7 @@ fn main() { quit_title, quit_action, quit_key - ); + ).autorelease(); app_menu.addItem_(quit_item); app_menu_item.setSubmenu_(app_menu); @@ -43,8 +43,7 @@ fn main() { NSTitledWindowMask as NSUInteger, NSBackingStoreBuffered, false - ); - + ).autorelease(); window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); window.center(); let title = NSString::alloc(nil).init_str("Hello World!\0"); From acb9b4efc70c3f285057c2aee774f38f81a1b98d Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sat, 27 Sep 2014 10:25:40 +0100 Subject: [PATCH 073/249] Upgrade to rustc d2b30f7d3 2014-09-23 --- src/base.rs | 8 ++++---- src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/base.rs b/src/base.rs index c882c34..527dd24 100644 --- a/src/base.rs +++ b/src/base.rs @@ -126,16 +126,16 @@ impl ObjCSelector for SEL { } /// Traits that simulate variadic parameters for convenience when sending messages. -trait ObjCMethodArgs { +pub trait ObjCMethodArgs { unsafe fn send_args(self, receiver: id, selector: SEL) -> id; } -trait ObjCMethodDoubleArgs { +pub trait ObjCMethodDoubleArgs { unsafe fn send_double_args(self, receiver: id, selector: SEL) -> c_double; } -trait ObjCMethodLongArgs { +pub trait ObjCMethodLongArgs { unsafe fn send_long_args(self, receiver: id, selector: SEL) -> c_long; } -trait ObjCMethodVoidArgs { +pub trait ObjCMethodVoidArgs { unsafe fn send_void_args(self, receiver: id, selector: SEL); } diff --git a/src/lib.rs b/src/lib.rs index f1485b5..d6e3ab5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,7 @@ #![feature(globs)] -#![allow(non_snake_case_functions)] +#![allow(non_snake_case)] extern crate libc; From 24e7b38bc66fae8cc2413dc6bf6b358c43fde42a Mon Sep 17 00:00:00 2001 From: doug Date: Sat, 18 Oct 2014 12:50:16 +0800 Subject: [PATCH 074/249] Makes traits public to fix the build --- src/base.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base.rs b/src/base.rs index 948595a..bed0e60 100644 --- a/src/base.rs +++ b/src/base.rs @@ -179,10 +179,10 @@ pub trait ObjCMethodLongArgs { pub trait ObjCMethodVoidArgs { unsafe fn send_void_args(self, receiver: id, selector: SEL); } -trait ObjCMethodBoolArgs { +pub trait ObjCMethodBoolArgs { unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool; } -trait ObjCMethodPointArgs { +pub trait ObjCMethodPointArgs { unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint; } From ab69c4a3d2ae17285136a8e861a8a545555d85fc Mon Sep 17 00:00:00 2001 From: doug Date: Sat, 18 Oct 2014 12:51:22 +0800 Subject: [PATCH 075/249] bump version number --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f90a3b1..5d83122 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cocoa" -version = "0.1.0" +version = "0.1.1" authors = ["The Servo Project Developers"] build = "make -f makefile.msgsend" From 3614ac893bc03cfb1a8e9ea4a88f23e163b5c75c Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 10 Nov 2014 22:16:17 +1100 Subject: [PATCH 076/249] Add window layer and coordinate methods --- src/appkit.rs | 125 +++++++++++++++++++++++++++++++++++++++++++++++++- src/base.rs | 105 +++++++++++++++++++++++++++++++++++++++++- src/msgsend.m | 34 +++++++++++++- 3 files changed, 260 insertions(+), 4 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index ff613e0..ef242d5 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -7,9 +7,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use base::{ObjCMethodCall, id, SEL, nil, NSInteger, NSUInteger}; +#![allow(non_upper_case_globals)] +use base::{ObjCMethodCall, id, SEL, nil, NSInteger, NSUInteger}; +use libc; + +#[cfg(target_word_size = "32")] pub type CGFloat = f32; +#[cfg(target_word_size = "64")] +pub type CGFloat = f64; #[repr(C)] pub struct NSPoint { @@ -94,6 +100,50 @@ pub enum NSBackingStoreType { NSBackingStoreBuffered = 2 } +bitflags! { + flags NSWindowOrderingMode: NSInteger { + const NSWindowAbove = 1, + const NSWindowBelow = -1, + const NSWindowOut = 0, + } +} + +bitflags! { + flags NSAlignmentOptions: libc::c_ulonglong { + const NSAlignMinXInward = 1 << 0, + const NSAlignMinYInward = 1 << 1, + const NSAlignMaxXInward = 1 << 2, + const NSAlignMaxYInward = 1 << 3, + const NSAlignWidthInward = 1 << 4, + const NSAlignHeightInward = 1 << 5, + const NSAlignMinXOutward = 1 << 8, + const NSAlignMinYOutward = 1 << 9, + const NSAlignMaxXOutward = 1 << 10, + const NSAlignMaxYOutward = 1 << 11, + const NSAlignWidthOutward = 1 << 12, + const NSAlignHeightOutward = 1 << 13, + const NSAlignMinXNearest = 1 << 16, + const NSAlignMinYNearest = 1 << 17, + const NSAlignMaxXNearest = 1 << 18, + const NSAlignMaxYNearest = 1 << 19, + const NSAlignWidthNearest = 1 << 20, + const NSAlignHeightNearest = 1 << 21, + const NSAlignRectFlipped = 1 << 63, + const NSAlignAllEdgesInward = NSAlignMinXInward.bits + | NSAlignMaxXInward.bits + | NSAlignMinYInward.bits + | NSAlignMaxYInward.bits, + const NSAlignAllEdgesOutward = NSAlignMinXOutward.bits + | NSAlignMaxXOutward.bits + | NSAlignMinYOutward.bits + | NSAlignMaxYOutward.bits, + const NSAlignAllEdgesNearest = NSAlignMinXNearest.bits + | NSAlignMaxXNearest.bits + | NSAlignMinYNearest.bits + | NSAlignMaxYNearest.bits, + } +} + pub trait NSAutoreleasePool { unsafe fn new(_: Self) -> id { "NSAutoreleasePool".send("new", ()) @@ -202,6 +252,23 @@ pub trait NSWindow { unsafe fn setTitle_(self, title: id); unsafe fn makeKeyAndOrderFront_(self, sender: id); unsafe fn center(self); + + // Managing Window Layers + unsafe fn orderOut_(self, sender: id); + unsafe fn orderBack_(self, sender: id); + unsafe fn orderFront_(self, sender: id); + unsafe fn orderFrontRegardless(self); + unsafe fn orderFrontWindow_relativeTo_(self, orderingMode: NSWindowOrderingMode, otherWindowNumber: NSInteger); + unsafe fn level(self) -> NSInteger; + unsafe fn setLevel_(self, level: NSInteger); + + // Converting Coordinates + unsafe fn backingScaleFactor(self) -> CGFloat; + unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect; + unsafe fn convertRectFromBacking_(self, rect: NSRect) -> NSRect; + unsafe fn convertRectToBacking_(self, rect: NSRect) -> NSRect; + unsafe fn convertRectToScreen_(self, rect: NSRect) -> NSRect; + unsafe fn convertRectFromScreen_(self, rect: NSRect) -> NSRect; } impl NSWindow for id { @@ -229,6 +296,62 @@ impl NSWindow for id { unsafe fn center(self) { self.send_void("center", ()) } + + // Managing Window Layers + + unsafe fn orderOut_(self, sender: id) { + self.send_void("orderOut:", sender); + } + + unsafe fn orderBack_(self, sender: id) { + self.send_void("orderBack:", sender); + } + + unsafe fn orderFront_(self, sender: id) { + self.send_void("orderFront:", sender); + } + + unsafe fn orderFrontRegardless(self) { + self.send_void("orderFrontRegardless", ()); + } + + unsafe fn orderFrontWindow_relativeTo_(self, ordering_mode: NSWindowOrderingMode, other_window_number: NSInteger) { + self.send_void("orderWindow:relativeTo:", (ordering_mode, other_window_number)); + } + + unsafe fn level(self) -> NSInteger { + self.send_integer("level", ()) + } + + unsafe fn setLevel_(self, level: NSInteger) { + self.send_void("setLevel:", level); + } + + // Converting Coordinates + + unsafe fn backingScaleFactor(self) -> CGFloat { + self.send_float("backingScaleFactor", ()) + } + + unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect { + self.send_rect("backingAlignedRect:options:", (rect, options)) + } + + unsafe fn convertRectFromBacking_(self, rect: NSRect) -> NSRect { + self.send_rect("convertRectFromBacking:", rect) + } + + unsafe fn convertRectToBacking_(self, rect: NSRect) -> NSRect { + self.send_rect("convertRectToBacking:", rect) + } + + unsafe fn convertRectToScreen_(self, rect: NSRect) -> NSRect { + self.send_rect("convertRectToScreen:", rect) + } + + unsafe fn convertRectFromScreen_(self, rect: NSRect) -> NSRect { + self.send_rect("convertRectFromScreen:", rect) + } } pub trait NSString { diff --git a/src/base.rs b/src/base.rs index bed0e60..e8f5978 100644 --- a/src/base.rs +++ b/src/base.rs @@ -7,7 +7,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use appkit::{NSRect, NSPoint}; +use appkit::{CGFloat, NSRect, NSPoint}; +use appkit::{NSWindowOrderingMode, NSAlignmentOptions}; use libc::{c_double, c_long, c_ulong, c_char}; use libc; @@ -75,8 +76,10 @@ pub trait ObjCMethodCall { unsafe fn send_long(self, selector: S, args: A) -> c_long; unsafe fn send_void(self, selector: S, args: A); unsafe fn send_bool(self, selector: S, args: A) -> bool; + unsafe fn send_float(self, selector: S, args: A) -> CGFloat; + unsafe fn send_integer(self, selector: S, args: A) -> NSInteger; unsafe fn send_point(self, selector: S, args: A) -> NSPoint; - + unsafe fn send_rect(self, selector: S, args: A) -> NSRect; } impl ObjCMethodCall for id { @@ -104,10 +107,25 @@ impl ObjCMethodCall for id { args.send_bool_args(self, selector.as_selector()) } #[inline] + unsafe fn send_float(self, selector: S, args: A) + -> CGFloat { + args.send_float_args(self, selector.as_selector()) + } + #[inline] + unsafe fn send_integer(self, selector: S, args: A) + -> NSInteger { + args.send_integer_args(self, selector.as_selector()) + } + #[inline] unsafe fn send_point(self, selector: S, args: A) -> NSPoint { args.send_point_args(self, selector.as_selector()) } + #[inline] + unsafe fn send_rect(self, selector: S, args: A) + -> NSRect { + args.send_rect_args(self, selector.as_selector()) + } } /// A convenience implementation that allows methods on class names to be called directly, as in: @@ -138,10 +156,25 @@ impl<'a> ObjCMethodCall for &'a str { args.send_bool_args(class(self), selector.as_selector()) } #[inline] + unsafe fn send_float(self, selector: S, args: A) + -> CGFloat { + args.send_float_args(class(self), selector.as_selector()) + } + #[inline] + unsafe fn send_integer(self, selector: S, args: A) + -> NSInteger { + args.send_integer_args(class(self), selector.as_selector()) + } + #[inline] unsafe fn send_point(self, selector: S, args: A) -> NSPoint { args.send_point_args(class(self), selector.as_selector()) } + #[inline] + unsafe fn send_rect(self, selector: S, args: A) + -> NSRect { + args.send_rect_args(class(self), selector.as_selector()) + } } /// A trait that allows C strings to be used as selectors without having to convert them first. @@ -182,9 +215,18 @@ pub trait ObjCMethodVoidArgs { pub trait ObjCMethodBoolArgs { unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool; } +pub trait ObjCMethodFloatArgs { + unsafe fn send_float_args(self, receiver: id, selector: SEL) -> CGFloat; +} +pub trait ObjCMethodIntegerArgs { + unsafe fn send_integer_args(self, receiver: id, selector: SEL) -> NSInteger; +} pub trait ObjCMethodPointArgs { unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint; } +pub trait ObjCMethodRectArgs { + unsafe fn send_rect_args(self, receiver: id, selector: SEL) -> NSRect; +} impl ObjCMethodArgs for () { #[inline] @@ -266,6 +308,22 @@ impl ObjCMethodVoidArgs for id { } } +// Conflicts with id... should id be a newtype? - bjz +// impl ObjCMethodVoidArgs for NSInteger { +// #[inline] +// unsafe fn send_void_args(self, receiver: id, selector: SEL) { +// invoke_msg_void_NSInteger(receiver, selector, self) +// } +// } + +impl ObjCMethodVoidArgs for (NSWindowOrderingMode, NSInteger) { + #[inline] + unsafe fn send_void_args(self, receiver: id, selector: SEL) { + let (first, second) = self; + invoke_msg_void_NSWindowOrderingMode_NSInteger(receiver, selector, first, second) + } +} + impl ObjCMethodBoolArgs for c_long { #[inline] unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool { @@ -273,6 +331,20 @@ impl ObjCMethodBoolArgs for c_long { } } +impl ObjCMethodFloatArgs for () { + #[inline] + unsafe fn send_float_args(self, receiver: id, selector: SEL) -> CGFloat { + invoke_msg_CGFloat(receiver, selector) + } +} + +impl ObjCMethodIntegerArgs for () { + #[inline] + unsafe fn send_integer_args(self, receiver: id, selector: SEL) -> NSInteger { + invoke_msg_NSInteger(receiver, selector) + } +} + impl ObjCMethodPointArgs for NSPoint { #[inline] unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint { @@ -280,6 +352,28 @@ impl ObjCMethodPointArgs for NSPoint { } } +impl ObjCMethodRectArgs for () { + #[inline] + unsafe fn send_rect_args(self, receiver: id, selector: SEL) -> NSRect { + invoke_msg_NSRect(receiver, selector) + } +} + +impl ObjCMethodRectArgs for (NSRect, NSAlignmentOptions) { + #[inline] + unsafe fn send_rect_args(self, receiver: id, selector: SEL) -> NSRect { + let (first, second) = self; + invoke_msg_NSRect_NSAlignmentOptions(receiver, selector, first, second) + } +} + +impl ObjCMethodRectArgs for NSRect { + #[inline] + unsafe fn send_rect_args(self, receiver: id, selector: SEL) -> NSRect { + invoke_msg_NSRect_NSRect(receiver, selector, self) + } +} + /// A trait that simulates variadic parameters for method calls. #[cfg(test)] @@ -339,11 +433,18 @@ extern { d: id, e: id) -> id; + pub fn invoke_msg_NSInteger(theReceiver: id, theSelector: SEL) -> NSInteger; pub fn invoke_msg_long(theReceiver: id, theSelector: SEL) -> c_long; pub fn invoke_msg_void(theReceiver: id, theSelector: SEL); pub fn invoke_msg_void_bool(theReceiver: id, theSelector: SEL, a: bool); pub fn invoke_msg_void_id(theReceiver: id, theSelector: SEL, a: id); + pub fn invoke_msg_void_NSInteger(theReceiver: id, theSelector: SEL, a: NSInteger); + pub fn invoke_msg_void_NSWindowOrderingMode_NSInteger(theReceiver: id, theSelector: SEL, a: NSWindowOrderingMode, b: NSInteger); pub fn invoke_msg_bool_long(theReceiver: id, theSelector: SEL, a: c_long) -> bool; + pub fn invoke_msg_CGFloat(theReceiver: id, theSelector: SEL) -> CGFloat; pub fn invoke_msg_NSPoint_NSPoint(theReceiver: id, theSelector: SEL, a: NSPoint) -> NSPoint; + pub fn invoke_msg_NSRect(theReceiver: id, theSelector: SEL) -> NSRect; + pub fn invoke_msg_NSRect_NSAlignmentOptions(theReceiver: id, theSelector: SEL, a: NSRect, b: NSAlignmentOptions) -> NSRect; + pub fn invoke_msg_NSRect_NSRect(theReceiver: id, theSelector: SEL, a: NSRect) -> NSRect; } diff --git a/src/msgsend.m b/src/msgsend.m index f368c8c..811bfb8 100644 --- a/src/msgsend.m +++ b/src/msgsend.m @@ -42,6 +42,11 @@ id invoke_msg_id_NSRect_ulong_ulong_bool(id theReceiver, SEL theSelector, NSRect return objc_msgSend(theReceiver, theSelector, a, b, c, d); } +NSInteger invoke_msg_NSInteger(id theReceiver, SEL theSelector) { + NSInteger (*f)(id self, SEL op) = (void *)objc_msgSend; + return f(theReceiver, theSelector); +} + long invoke_msg_long(id theReceiver, SEL theSelector) { return (long)objc_msgSend(theReceiver, theSelector); } @@ -58,12 +63,39 @@ void invoke_msg_void_id(id theReceiver, SEL theSelector, id id) { objc_msgSend(theReceiver, theSelector, id); } +void invoke_msg_void_NSInteger(id theReceiver, SEL theSelector, NSInteger a) { + objc_msgSend(theReceiver, theSelector, a); +} + +void invoke_msg_void_NSWindowOrderingMode_NSInteger(id theReceiver, SEL theSelector, NSWindowOrderingMode a, NSInteger b) { + objc_msgSend(theReceiver, theSelector, a, b); +} + char invoke_msg_bool_long(id theReceiver, SEL theSelector, long a) { return objc_msgSend(theReceiver, theSelector, a); } +CGFloat invoke_msg_CGFloat(id theReceiver, SEL theSelector) { + CGFloat (*f)(id self, SEL op) = (void *)objc_msgSend; + return f(theReceiver, theSelector); +} + NSPoint invoke_msg_NSPoint_NSPoint(id theReceiver, SEL theSelector, NSPoint point) { - NSPoint (*f)(id self, SEL op, NSPoint p) = (NSPoint *)objc_msgSend; + NSPoint (*f)(id self, SEL op, NSPoint p) = (void *)objc_msgSend; return f(theReceiver, theSelector, point); } +NSRect invoke_msg_NSRect(id theReceiver, SEL theSelector) { + NSRect (*f)(id self, SEL op) = (void *)objc_msgSend; + return f(theReceiver, theSelector); +} + +NSRect invoke_msg_NSRect_NSAlignmentOptions(id theReceiver, SEL theSelector, NSRect rect, NSAlignmentOptions options) { + NSRect (*f)(id self, SEL op, NSRect r, NSAlignmentOptions opts) = (void *)objc_msgSend; + return f(theReceiver, theSelector, rect, options); +} + +NSRect invoke_msg_NSRect_NSRect(id theReceiver, SEL theSelector, NSRect rect) { + NSRect (*f)(id self, SEL op, NSRect r) = (void *)objc_msgSend; + return f(theReceiver, theSelector, rect); +} From 05ed03136b86d6a575eec153201ab8bb072039d7 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 10 Nov 2014 22:56:44 +1100 Subject: [PATCH 077/249] Add window size methods --- src/appkit.rs | 111 +++++++++++++++++++++++++++++++++++++++++++++++--- src/base.rs | 57 +++++++++++++++++++++++++- src/msgsend.m | 25 +++++++++++- 3 files changed, 185 insertions(+), 8 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index ef242d5..4d73054 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -248,11 +248,34 @@ pub trait NSWindow { style: NSUInteger, backing: NSBackingStoreType, defer: bool) -> id; - unsafe fn cascadeTopLeftFromPoint_(self, top_left: NSPoint) -> NSPoint; unsafe fn setTitle_(self, title: id); unsafe fn makeKeyAndOrderFront_(self, sender: id); unsafe fn center(self); + // Sizing Windows + unsafe fn frame(self) -> NSRect; + unsafe fn setFrameOrigin_(self, point: NSPoint); + unsafe fn setFrameTopLeftPoint_(self, point: NSPoint); + // skipped: constrainFrameRect_toScreen_ + unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint; + unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: bool); + unsafe fn aspectRatio(self) -> NSSize; + unsafe fn setAspectRatio_(self, aspectRatio: NSSize); + unsafe fn minSize(self) -> NSSize; + unsafe fn setMinSize_(self, minSize: NSSize); + unsafe fn maxSize(self) -> NSSize; + unsafe fn setMaxSize_(self, maxSize: NSSize); + unsafe fn performZoom_(self, sender: id); + unsafe fn zoom_(self, sender: id); + // skipped: resizeFlags + unsafe fn showsResizeIndicator(self) -> bool; + unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: bool); + unsafe fn resizeIncrements(self) -> NSSize; + unsafe fn setResizeIncrements_(self, resizeIncrements: NSSize); + unsafe fn preservesContentDuringLiveResize(self) -> bool; + unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: bool); + unsafe fn inLiveResize(self) -> bool; + // Managing Window Layers unsafe fn orderOut_(self, sender: id); unsafe fn orderBack_(self, sender: id); @@ -281,10 +304,6 @@ impl NSWindow for id { (rect, style, backing as NSUInteger, defer)) } - unsafe fn cascadeTopLeftFromPoint_(self, top_left: NSPoint) -> NSPoint { - self.send_point("cascadeTopLeftFromPoint:", top_left) - } - unsafe fn setTitle_(self, title: id) { self.send_void("setTitle:", title); } @@ -297,6 +316,88 @@ impl NSWindow for id { self.send_void("center", ()) } + // Sizing Windows + + unsafe fn frame(self) -> NSRect { + self.send_rect("frame", ()) + } + + unsafe fn setFrameOrigin_(self, point: NSPoint) { + self.send_void("setFrameOrigin:", point); + } + + unsafe fn setFrameTopLeftPoint_(self, point: NSPoint) { + self.send_void("setFrameTopLeftPoint:", point); + } + + unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint { + self.send_point("cascadeTopLeftFromPoint:", topLeft) + } + + unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: bool) { + self.send_void("setFrame:displayViews:", (windowFrame, display)); + } + + unsafe fn aspectRatio(self) -> NSSize { + self.send_size("aspectRatio", ()) + } + + unsafe fn setAspectRatio_(self, aspectRatio: NSSize) { + self.send_void("setAspectRatio:", aspectRatio); + } + + unsafe fn minSize(self) -> NSSize { + self.send_size("minSize", ()) + } + + unsafe fn setMinSize_(self, minSize: NSSize) { + self.send_void("setMinSize:", minSize); + } + + unsafe fn maxSize(self) -> NSSize { + self.send_size("maxSize", ()) + } + + unsafe fn setMaxSize_(self, maxSize: NSSize) { + self.send_void("setMaxSize:", maxSize); + } + + unsafe fn performZoom_(self, sender: id) { + self.send_void("performZoom:", sender); + } + + unsafe fn zoom_(self, sender: id) { + self.send_void("zoom:", sender); + } + + unsafe fn showsResizeIndicator(self) -> bool { + self.send_bool("showsResizeIndicator", ()) + } + + unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: bool) { + self.send_void("setShowsResizeIndicator:", showsResizeIndicator) + } + + unsafe fn resizeIncrements(self) -> NSSize { + self.send_size("resizeIncrements", ()) + } + + unsafe fn setResizeIncrements_(self, resizeIncrements: NSSize) { + self.send_void("setResizeIncrements:", resizeIncrements); + } + + unsafe fn preservesContentDuringLiveResize(self) -> bool { + self.send_bool("preservesContentDuringLiveResize", ()) + } + + unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: bool) { + self.send_void("setPreservesContentDuringLiveResize:", preservesContentDuringLiveResize) + } + + unsafe fn inLiveResize(self) -> bool { + self.send_bool("inLiveResize", ()) + } + // Managing Window Layers unsafe fn orderOut_(self, sender: id) { diff --git a/src/base.rs b/src/base.rs index e8f5978..3e9f559 100644 --- a/src/base.rs +++ b/src/base.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use appkit::{CGFloat, NSRect, NSPoint}; +use appkit::{CGFloat, NSPoint, NSRect, NSSize}; use appkit::{NSWindowOrderingMode, NSAlignmentOptions}; use libc::{c_double, c_long, c_ulong, c_char}; @@ -80,6 +80,7 @@ pub trait ObjCMethodCall { unsafe fn send_integer(self, selector: S, args: A) -> NSInteger; unsafe fn send_point(self, selector: S, args: A) -> NSPoint; unsafe fn send_rect(self, selector: S, args: A) -> NSRect; + unsafe fn send_size(self, selector: S, args: A) -> NSSize; } impl ObjCMethodCall for id { @@ -126,6 +127,11 @@ impl ObjCMethodCall for id { -> NSRect { args.send_rect_args(self, selector.as_selector()) } + #[inline] + unsafe fn send_size(self, selector: S, args: A) + -> NSSize { + args.send_size_args(self, selector.as_selector()) + } } /// A convenience implementation that allows methods on class names to be called directly, as in: @@ -175,6 +181,11 @@ impl<'a> ObjCMethodCall for &'a str { -> NSRect { args.send_rect_args(class(self), selector.as_selector()) } + #[inline] + unsafe fn send_size(self, selector: S, args: A) + -> NSSize { + args.send_size_args(class(self), selector.as_selector()) + } } /// A trait that allows C strings to be used as selectors without having to convert them first. @@ -227,6 +238,9 @@ pub trait ObjCMethodPointArgs { pub trait ObjCMethodRectArgs { unsafe fn send_rect_args(self, receiver: id, selector: SEL) -> NSRect; } +pub trait ObjCMethodSizeArgs { + unsafe fn send_size_args(self, receiver: id, selector: SEL) -> NSSize; +} impl ObjCMethodArgs for () { #[inline] @@ -316,6 +330,28 @@ impl ObjCMethodVoidArgs for id { // } // } +impl ObjCMethodVoidArgs for NSPoint { + #[inline] + unsafe fn send_void_args(self, receiver: id, selector: SEL) { + invoke_msg_void_NSPoint(receiver, selector, self) + } +} + +impl ObjCMethodVoidArgs for NSSize { + #[inline] + unsafe fn send_void_args(self, receiver: id, selector: SEL) { + invoke_msg_void_NSSize(receiver, selector, self) + } +} + +impl ObjCMethodVoidArgs for (NSRect, bool) { + #[inline] + unsafe fn send_void_args(self, receiver: id, selector: SEL) { + let (first, second) = self; + invoke_msg_void_NSRect_bool(receiver, selector, first, second) + } +} + impl ObjCMethodVoidArgs for (NSWindowOrderingMode, NSInteger) { #[inline] unsafe fn send_void_args(self, receiver: id, selector: SEL) { @@ -324,6 +360,13 @@ impl ObjCMethodVoidArgs for (NSWindowOrderingMode, NSInteger) { } } +impl ObjCMethodBoolArgs for () { + #[inline] + unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool { + invoke_msg_bool(receiver, selector) + } +} + impl ObjCMethodBoolArgs for c_long { #[inline] unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool { @@ -374,6 +417,13 @@ impl ObjCMethodRectArgs for NSRect { } } +impl ObjCMethodSizeArgs for () { + #[inline] + unsafe fn send_size_args(self, receiver: id, selector: SEL) -> NSSize { + invoke_msg_NSSize(receiver, selector) + } +} + /// A trait that simulates variadic parameters for method calls. #[cfg(test)] @@ -439,12 +489,17 @@ extern { pub fn invoke_msg_void_bool(theReceiver: id, theSelector: SEL, a: bool); pub fn invoke_msg_void_id(theReceiver: id, theSelector: SEL, a: id); pub fn invoke_msg_void_NSInteger(theReceiver: id, theSelector: SEL, a: NSInteger); + pub fn invoke_msg_void_NSPoint(theReceiver: id, theSelector: SEL, a: NSPoint); + pub fn invoke_msg_void_NSSize(theReceiver: id, theSelector: SEL, a: NSSize); + pub fn invoke_msg_void_NSRect_bool(theReceiver: id, theSelector: SEL, a: NSRect, b: bool); pub fn invoke_msg_void_NSWindowOrderingMode_NSInteger(theReceiver: id, theSelector: SEL, a: NSWindowOrderingMode, b: NSInteger); + pub fn invoke_msg_bool(theReceiver: id, theSelector: SEL) -> bool; pub fn invoke_msg_bool_long(theReceiver: id, theSelector: SEL, a: c_long) -> bool; pub fn invoke_msg_CGFloat(theReceiver: id, theSelector: SEL) -> CGFloat; pub fn invoke_msg_NSPoint_NSPoint(theReceiver: id, theSelector: SEL, a: NSPoint) -> NSPoint; pub fn invoke_msg_NSRect(theReceiver: id, theSelector: SEL) -> NSRect; pub fn invoke_msg_NSRect_NSAlignmentOptions(theReceiver: id, theSelector: SEL, a: NSRect, b: NSAlignmentOptions) -> NSRect; pub fn invoke_msg_NSRect_NSRect(theReceiver: id, theSelector: SEL, a: NSRect) -> NSRect; + pub fn invoke_msg_NSSize(theReceiver: id, theSelector: SEL) -> NSSize; } diff --git a/src/msgsend.m b/src/msgsend.m index 811bfb8..75f9f96 100644 --- a/src/msgsend.m +++ b/src/msgsend.m @@ -67,12 +67,28 @@ void invoke_msg_void_NSInteger(id theReceiver, SEL theSelector, NSInteger a) { objc_msgSend(theReceiver, theSelector, a); } +void invoke_msg_void_NSPoint(id theReceiver, SEL theSelector, NSPoint a) { + objc_msgSend(theReceiver, theSelector, a); +} + +void invoke_msg_void_NSSize(id theReceiver, SEL theSelector, NSSize a) { + objc_msgSend(theReceiver, theSelector, a); +} + +void invoke_msg_void_NSRect_bool(id theReceiver, SEL theSelector, NSRect a, bool b) { + objc_msgSend(theReceiver, theSelector, a, b); +} + void invoke_msg_void_NSWindowOrderingMode_NSInteger(id theReceiver, SEL theSelector, NSWindowOrderingMode a, NSInteger b) { objc_msgSend(theReceiver, theSelector, a, b); } -char invoke_msg_bool_long(id theReceiver, SEL theSelector, long a) { - return objc_msgSend(theReceiver, theSelector, a); +bool invoke_msg_bool(id theReceiver, SEL theSelector) { + return objc_msgSend(theReceiver, theSelector); +} + +bool invoke_msg_bool_long(id theReceiver, SEL theSelector, long a) { + return objc_msgSend(theReceiver, theSelector, a); } CGFloat invoke_msg_CGFloat(id theReceiver, SEL theSelector) { @@ -99,3 +115,8 @@ NSRect invoke_msg_NSRect_NSRect(id theReceiver, SEL theSelector, NSRect rect) { NSRect (*f)(id self, SEL op, NSRect r) = (void *)objc_msgSend; return f(theReceiver, theSelector, rect); } + +NSSize invoke_msg_NSSize(id theReceiver, SEL theSelector) { + NSSize (*f)(id self, SEL op) = (void *)objc_msgSend; + return f(theReceiver, theSelector); +} From f1b204126857cfb8a44b2575e979461460e001dc Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 10 Nov 2014 23:04:56 +1100 Subject: [PATCH 078/249] Add title management methods --- src/appkit.rs | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 4d73054..519531b 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -248,7 +248,6 @@ pub trait NSWindow { style: NSUInteger, backing: NSBackingStoreType, defer: bool) -> id; - unsafe fn setTitle_(self, title: id); unsafe fn makeKeyAndOrderFront_(self, sender: id); unsafe fn center(self); @@ -292,6 +291,15 @@ pub trait NSWindow { unsafe fn convertRectToBacking_(self, rect: NSRect) -> NSRect; unsafe fn convertRectToScreen_(self, rect: NSRect) -> NSRect; unsafe fn convertRectFromScreen_(self, rect: NSRect) -> NSRect; + + // Managing Titles + unsafe fn title(self) -> id; + unsafe fn setTitle_(self, title: id); + unsafe fn setTitleWithRepresentedFilename_(self, filePath: id); + unsafe fn representedFilename(self) -> id; + unsafe fn setRepresentedFilename_(self, filePath: id); + // skipped: representedURL + // skipped: setRepresentedURL_ } impl NSWindow for id { @@ -304,10 +312,6 @@ impl NSWindow for id { (rect, style, backing as NSUInteger, defer)) } - unsafe fn setTitle_(self, title: id) { - self.send_void("setTitle:", title); - } - unsafe fn makeKeyAndOrderFront_(self, sender: id) { self.send_void("makeKeyAndOrderFront:", sender) } @@ -453,6 +457,28 @@ impl NSWindow for id { unsafe fn convertRectFromScreen_(self, rect: NSRect) -> NSRect { self.send_rect("convertRectFromScreen:", rect) } + + // Managing Titles + + unsafe fn title(self) -> id { + self.send("title", ()) + } + + unsafe fn setTitle_(self, title: id) { + self.send_void("setTitle:", title); + } + + unsafe fn setTitleWithRepresentedFilename_(self, filePath: id) { + self.send_void("setTitleWithRepresentedFilename:", filePath); + } + + unsafe fn representedFilename(self) -> id { + self.send("representedFilename", ()) + } + + unsafe fn setRepresentedFilename_(self, filePath: id) { + self.send_void("setRepresentedFilename:", filePath); + } } pub trait NSString { From 63f42655931042f4dcb6947fb5a01897f604517f Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 10 Nov 2014 23:24:44 +1100 Subject: [PATCH 079/249] Add window movement methods --- src/appkit.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 519531b..89342eb 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -249,7 +249,6 @@ pub trait NSWindow { backing: NSBackingStoreType, defer: bool) -> id; unsafe fn makeKeyAndOrderFront_(self, sender: id); - unsafe fn center(self); // Sizing Windows unsafe fn frame(self) -> NSRect; @@ -300,6 +299,11 @@ pub trait NSWindow { unsafe fn setRepresentedFilename_(self, filePath: id); // skipped: representedURL // skipped: setRepresentedURL_ + + // Moving Windows + unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: bool); + unsafe fn setMovable_(self, movable: bool); + unsafe fn center(self); } impl NSWindow for id { @@ -316,10 +320,6 @@ impl NSWindow for id { self.send_void("makeKeyAndOrderFront:", sender) } - unsafe fn center(self) { - self.send_void("center", ()) - } - // Sizing Windows unsafe fn frame(self) -> NSRect { @@ -479,6 +479,20 @@ impl NSWindow for id { unsafe fn setRepresentedFilename_(self, filePath: id) { self.send_void("setRepresentedFilename:", filePath); } + + // Moving Windows + + unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: bool) { + self.send_void("setMovableByWindowBackground:", movableByWindowBackground); + } + + unsafe fn setMovable_(self, movable: bool) { + self.send_void("setMovable:", movable); + } + + unsafe fn center(self) { + self.send_void("center", ()); + } } pub trait NSString { From c82326fc1af781de2dc53f192e75dec9c5525870 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 10 Nov 2014 23:31:51 +1100 Subject: [PATCH 080/249] Add window close methods --- src/appkit.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 89342eb..141522b 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -304,6 +304,11 @@ pub trait NSWindow { unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: bool); unsafe fn setMovable_(self, movable: bool); unsafe fn center(self); + + // Closing Windows + unsafe fn performClose_(self, sender: id); + unsafe fn close(self); + unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: bool); } impl NSWindow for id { @@ -493,6 +498,20 @@ impl NSWindow for id { unsafe fn center(self) { self.send_void("center", ()); } + + // Closing Windows + + unsafe fn performClose_(self, sender: id) { + self.send_void("performClose:", sender); + } + + unsafe fn close(self) { + self.send_void("close", ()); + } + + unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: bool) { + self.send_void("setReleasedWhenClosed:", releasedWhenClosed); + } } pub trait NSString { From ed90a72ba043f0312cbce9c5bd529f6bb43a7665 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 10 Nov 2014 23:39:25 +1100 Subject: [PATCH 081/249] Add winidow minimization methods --- src/appkit.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 141522b..c73799d 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -309,6 +309,15 @@ pub trait NSWindow { unsafe fn performClose_(self, sender: id); unsafe fn close(self); unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: bool); + + // Minimizing Windows + unsafe fn performMiniaturize_(self, sender: id); + unsafe fn miniaturize_(self, sender: id); + unsafe fn deminiaturize_(self, sender: id); + // skipped: miniwindowImage + // skipped: setMiniwindowImage + unsafe fn miniwindowTitle(self) -> id; + unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id); } impl NSWindow for id { @@ -512,6 +521,28 @@ impl NSWindow for id { unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: bool) { self.send_void("setReleasedWhenClosed:", releasedWhenClosed); } + + // Minimizing Windows + + unsafe fn performMiniaturize_(self, sender: id) { + self.send_void("performMiniaturize:", sender); + } + + unsafe fn miniaturize_(self, sender: id) { + self.send_void("miniaturize:", sender); + } + + unsafe fn deminiaturize_(self, sender: id) { + self.send_void("deminiaturize:", sender); + } + + unsafe fn miniwindowTitle(self) -> id { + self.send("miniwindowTitle", ()) + } + + unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id) { + self.send_void("setMiniwindowTitle:", miniwindowTitle); + } } pub trait NSString { From d7ea3c627af2749824a029fa62fa34f2c5204ee6 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 10 Nov 2014 23:42:34 +1100 Subject: [PATCH 082/249] Add window edit status method --- src/appkit.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index c73799d..59cf905 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -291,6 +291,9 @@ pub trait NSWindow { unsafe fn convertRectToScreen_(self, rect: NSRect) -> NSRect; unsafe fn convertRectFromScreen_(self, rect: NSRect) -> NSRect; + // Accessing Edited Status + unsafe fn setDocumentEdited_(self, documentEdited: bool); + // Managing Titles unsafe fn title(self) -> id; unsafe fn setTitle_(self, title: id); @@ -472,6 +475,12 @@ impl NSWindow for id { self.send_rect("convertRectFromScreen:", rect) } + // Accessing Edited Status + + unsafe fn setDocumentEdited_(self, documentEdited: bool) { + self.send_void("setDocumentEdited:", documentEdited); + } + // Managing Titles unsafe fn title(self) -> id { From c59bce4bf0e8f242851dcccdc2a1110511cd6910 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 10 Nov 2014 23:50:18 +1100 Subject: [PATCH 083/249] Add window key status methods --- src/appkit.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 59cf905..fb4ac78 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -248,7 +248,6 @@ pub trait NSWindow { style: NSUInteger, backing: NSBackingStoreType, defer: bool) -> id; - unsafe fn makeKeyAndOrderFront_(self, sender: id); // Sizing Windows unsafe fn frame(self) -> NSRect; @@ -283,6 +282,13 @@ pub trait NSWindow { unsafe fn level(self) -> NSInteger; unsafe fn setLevel_(self, level: NSInteger); + // Managing Key Status + unsafe fn canBecomeKeyWindow(self) -> bool; + unsafe fn makeKeyWindow(self); + unsafe fn makeKeyAndOrderFront_(self, sender: id); + // skipped: becomeKeyWindow (should not be invoked directly, according to Apple's documentation) + // skipped: resignKeyWindow (should not be invoked directly, according to Apple's documentation) + // Converting Coordinates unsafe fn backingScaleFactor(self) -> CGFloat; unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect; @@ -333,10 +339,6 @@ impl NSWindow for id { (rect, style, backing as NSUInteger, defer)) } - unsafe fn makeKeyAndOrderFront_(self, sender: id) { - self.send_void("makeKeyAndOrderFront:", sender) - } - // Sizing Windows unsafe fn frame(self) -> NSRect { @@ -449,6 +451,20 @@ impl NSWindow for id { self.send_void("setLevel:", level); } + // Managing Key Status + + unsafe fn canBecomeKeyWindow(self) -> bool { + self.send_bool("canBecomeKeyWindow", ()) + } + + unsafe fn makeKeyWindow(self) { + self.send_void("makeKeyWindow", ()); + } + + unsafe fn makeKeyAndOrderFront_(self, sender: id) { + self.send_void("makeKeyAndOrderFront:", sender); + } + // Converting Coordinates unsafe fn backingScaleFactor(self) -> CGFloat { From 7e0355954485527deda272cb3464f3a38adfdeba Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 10 Nov 2014 23:52:06 +1100 Subject: [PATCH 084/249] Add window main status methods --- src/appkit.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index fb4ac78..488e78d 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -289,6 +289,12 @@ pub trait NSWindow { // skipped: becomeKeyWindow (should not be invoked directly, according to Apple's documentation) // skipped: resignKeyWindow (should not be invoked directly, according to Apple's documentation) + // Managing Main Status + unsafe fn canBecomeMainWindow(self) -> bool; + unsafe fn makeMainWindow(self); + // skipped: becomeMainWindow (should not be invoked directly, according to Apple's documentation) + // skipped: resignMainWindow (should not be invoked directly, according to Apple's documentation) + // Converting Coordinates unsafe fn backingScaleFactor(self) -> CGFloat; unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect; @@ -465,6 +471,16 @@ impl NSWindow for id { self.send_void("makeKeyAndOrderFront:", sender); } + // Managing Main Status + + unsafe fn canBecomeMainWindow(self) -> bool { + self.send_bool("canBecomeMainWindow", ()) + } + + unsafe fn makeMainWindow(self) { + self.send_void("makeMainWindow", ()); + } + // Converting Coordinates unsafe fn backingScaleFactor(self) -> CGFloat { From 0c58565978198c2aff697651427374de7f6f28b4 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 11 Nov 2014 00:59:47 +1100 Subject: [PATCH 085/249] Remove msgsend.m --- Cargo.toml | 2 - Makefile.in | 32 ------------- makefile.msgsend | 20 -------- src/base.rs | 101 +++++++++++++-------------------------- src/msgsend.m | 122 ----------------------------------------------- 5 files changed, 33 insertions(+), 244 deletions(-) delete mode 100644 Makefile.in delete mode 100644 makefile.msgsend delete mode 100644 src/msgsend.m diff --git a/Cargo.toml b/Cargo.toml index 5d83122..5036575 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,6 @@ name = "cocoa" version = "0.1.1" authors = ["The Servo Project Developers"] -build = "make -f makefile.msgsend" - [lib] name = "cocoa" diff --git a/Makefile.in b/Makefile.in deleted file mode 100644 index 877d281..0000000 --- a/Makefile.in +++ /dev/null @@ -1,32 +0,0 @@ -VPATH=%VPATH% - -CC ?= gcc -RUSTC ?= rustc -AR ?= ar -RUSTFLAGS ?= -CFLAGS += -Wall - -RUST_SRC = $(shell find $(VPATH)/src -type f -name '*.rs') - -.PHONY: all -all: libcocoa.dummy - -libcocoa.dummy: src/lib.rs $(RUST_SRC) libmsgsend.a - $(RUSTC) $(RUSTFLAGS) $< --out-dir . - touch $@ - -cocoa-test: src/lib.rs $(RUST_SRC) libmsgsend.a - $(RUSTC) $(RUSTFLAGS) $< -o $@ --test - -libmsgsend.a: msgsend.o - $(AR) rcs libmsgsend.a msgsend.o - -msgsend.o: src/msgsend.m - $(CC) $(CFLAGS) $< -o $@ -c - -check: cocoa-test - ./cocoa-test - -.PHONY: clean -clean: - rm -f cocoa-test *.a *.o *.so *.dylib *.rlib *.dll *.dummy cocoa-test diff --git a/makefile.msgsend b/makefile.msgsend deleted file mode 100644 index e76812a..0000000 --- a/makefile.msgsend +++ /dev/null @@ -1,20 +0,0 @@ -CC ?= gcc -AR ?= ar -CFLAGS += -Wall - -.PHONY : all -ifeq (darwin,$(findstring darwin,$(TARGET))) - -all: $(OUT_DIR)/libmsgsend.a - -$(OUT_DIR)/libmsgsend.a: $(OUT_DIR)/msgsend.o - $(AR) rcs $(OUT_DIR)/libmsgsend.a $(OUT_DIR)/msgsend.o - -$(OUT_DIR)/msgsend.o: src/msgsend.m - $(CC) $(CFLAGS) $< -o $@ -c - -else - -all: - -endif diff --git a/src/base.rs b/src/base.rs index 3e9f559..6becd4f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -13,6 +13,8 @@ use appkit::{NSWindowOrderingMode, NSAlignmentOptions}; use libc::{c_double, c_long, c_ulong, c_char}; use libc; +use std::mem; + pub type Class = libc::intptr_t; pub type IMP = extern "C" fn(id, SEL) -> id; pub type Ivar = libc::intptr_t; @@ -45,11 +47,16 @@ extern { pub fn objc_allocateClassPair(superclass: Class, name: *const libc::c_char, extraBytes: libc::size_t) -> Class; pub fn objc_getClass(name: *const libc::c_char) -> id; - pub fn objc_msgSend(theReceiver: id, theSelector: SEL) -> id; + pub fn objc_msgSend(theReceiver: id, theSelector: SEL, ...) -> id; pub fn objc_registerClassPair(cls: Class); pub fn sel_registerName(name: *const libc::c_char) -> SEL; } +/// Returns an Objective-C message send function that returns a type `T`. +pub unsafe fn msg_send() -> extern fn(theReceiver: id, theSelector: SEL, ...) -> T { + mem::transmute(objc_msgSend) +} + /// A convenience method to convert the name of a class to the class object itself. #[inline] pub fn class(name: &str) -> id { @@ -245,21 +252,21 @@ pub trait ObjCMethodSizeArgs { impl ObjCMethodArgs for () { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - invoke_msg_id(receiver, selector) + msg_send()(receiver, selector) } } impl ObjCMethodArgs for id { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - invoke_msg_id_id(receiver, selector, self) + msg_send()(receiver, selector, self) } } impl ObjCMethodArgs for NSRect { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - invoke_msg_id_NSRect(receiver, selector, &self) + msg_send()(receiver, selector, &self) } } @@ -267,7 +274,7 @@ impl ObjCMethodArgs for (id, SEL, id) { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { let (first, second, third) = self; - invoke_msg_id_id_SEL_id(receiver, selector, first, second, third) + msg_send()(receiver, selector, first, second, third) } } @@ -275,7 +282,7 @@ impl ObjCMethodArgs for (NSRect, c_ulong, c_ulong, bool) { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { let (first, second, third, fourth) = self; - invoke_msg_id_NSRect_ulong_ulong_bool(receiver, selector, first, second, third, fourth) + msg_send()(receiver, selector, first, second, third, fourth as libc::c_int) } } @@ -283,42 +290,42 @@ impl ObjCMethodArgs for (id, id, id, id, id) { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { let (first, second, third, fourth, fifth) = self; - invoke_msg_id_id_id_id_id_id(receiver, selector, first, second, third, fourth, fifth) + msg_send()(receiver, selector, first, second, third, fourth, fifth) } } impl ObjCMethodDoubleArgs for () { #[inline] unsafe fn send_double_args(self, receiver: id, selector: SEL) -> f64 { - invoke_msg_double(receiver, selector) + msg_send()(receiver, selector) } } impl ObjCMethodLongArgs for () { #[inline] unsafe fn send_long_args(self, receiver: id, selector: SEL) -> c_long { - invoke_msg_long(receiver, selector) + msg_send()(receiver, selector) } } impl ObjCMethodVoidArgs for () { #[inline] unsafe fn send_void_args(self, receiver: id, selector: SEL) { - invoke_msg_void(receiver, selector) + msg_send()(receiver, selector) } } impl ObjCMethodVoidArgs for bool { #[inline] unsafe fn send_void_args(self, receiver: id, selector: SEL) { - invoke_msg_void_bool(receiver, selector, self) + msg_send()(receiver, selector, self as libc::c_int) } } impl ObjCMethodVoidArgs for id { #[inline] unsafe fn send_void_args(self, receiver: id, selector: SEL) { - invoke_msg_void_id(receiver, selector, self) + msg_send()(receiver, selector, self) } } @@ -326,21 +333,21 @@ impl ObjCMethodVoidArgs for id { // impl ObjCMethodVoidArgs for NSInteger { // #[inline] // unsafe fn send_void_args(self, receiver: id, selector: SEL) { -// invoke_msg_void_NSInteger(receiver, selector, self) +// msg_send()(receiver, selector, self); // } // } impl ObjCMethodVoidArgs for NSPoint { #[inline] unsafe fn send_void_args(self, receiver: id, selector: SEL) { - invoke_msg_void_NSPoint(receiver, selector, self) + msg_send()(receiver, selector, self) } } impl ObjCMethodVoidArgs for NSSize { #[inline] unsafe fn send_void_args(self, receiver: id, selector: SEL) { - invoke_msg_void_NSSize(receiver, selector, self) + msg_send()(receiver, selector, self) } } @@ -348,7 +355,7 @@ impl ObjCMethodVoidArgs for (NSRect, bool) { #[inline] unsafe fn send_void_args(self, receiver: id, selector: SEL) { let (first, second) = self; - invoke_msg_void_NSRect_bool(receiver, selector, first, second) + msg_send()(receiver, selector, first, second as libc::c_int) } } @@ -356,49 +363,49 @@ impl ObjCMethodVoidArgs for (NSWindowOrderingMode, NSInteger) { #[inline] unsafe fn send_void_args(self, receiver: id, selector: SEL) { let (first, second) = self; - invoke_msg_void_NSWindowOrderingMode_NSInteger(receiver, selector, first, second) + msg_send()(receiver, selector, first, second) } } impl ObjCMethodBoolArgs for () { #[inline] unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool { - invoke_msg_bool(receiver, selector) + msg_send()(receiver, selector) } } impl ObjCMethodBoolArgs for c_long { #[inline] unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool { - invoke_msg_bool_long(receiver, selector, self) + msg_send()(receiver, selector, self) } } impl ObjCMethodFloatArgs for () { #[inline] unsafe fn send_float_args(self, receiver: id, selector: SEL) -> CGFloat { - invoke_msg_CGFloat(receiver, selector) + msg_send()(receiver, selector) } } impl ObjCMethodIntegerArgs for () { #[inline] unsafe fn send_integer_args(self, receiver: id, selector: SEL) -> NSInteger { - invoke_msg_NSInteger(receiver, selector) + msg_send()(receiver, selector) } } impl ObjCMethodPointArgs for NSPoint { #[inline] unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint { - invoke_msg_NSPoint_NSPoint(receiver, selector, self) + msg_send()(receiver, selector, self) } } impl ObjCMethodRectArgs for () { #[inline] unsafe fn send_rect_args(self, receiver: id, selector: SEL) -> NSRect { - invoke_msg_NSRect(receiver, selector) + msg_send()(receiver, selector) } } @@ -406,21 +413,21 @@ impl ObjCMethodRectArgs for (NSRect, NSAlignmentOptions) { #[inline] unsafe fn send_rect_args(self, receiver: id, selector: SEL) -> NSRect { let (first, second) = self; - invoke_msg_NSRect_NSAlignmentOptions(receiver, selector, first, second) + msg_send()(receiver, selector, first, second) } } impl ObjCMethodRectArgs for NSRect { #[inline] unsafe fn send_rect_args(self, receiver: id, selector: SEL) -> NSRect { - invoke_msg_NSRect_NSRect(receiver, selector, self) + msg_send()(receiver, selector, self) } } impl ObjCMethodSizeArgs for () { #[inline] unsafe fn send_size_args(self, receiver: id, selector: SEL) -> NSSize { - invoke_msg_NSSize(receiver, selector) + msg_send()(receiver, selector) } } @@ -461,45 +468,3 @@ mod test { } } } - -#[link(name = "msgsend", kind = "static")] -extern { - pub fn invoke_msg_double(theReceiver: id, theSelector: SEL) -> f64; - pub fn invoke_msg_id(theReceiver: id, theSelector: SEL) -> id; - pub fn invoke_msg_id_id(theReceiver: id, theSelector: SEL, a: id) -> id; - pub fn invoke_msg_id_NSRect(theReceiver: id, theSelector: SEL, a: &NSRect) -> id; - pub fn invoke_msg_id_id_SEL_id(theReceiver: id, theSelector: SEL, a: id, b: SEL, c: id) -> id; - pub fn invoke_msg_id_NSRect_ulong_ulong_bool(theReceiver: id, - theSelector: SEL, - a: NSRect, - b: c_ulong, - c: c_ulong, - d: bool) -> id; - pub fn invoke_msg_id_id_id_id_id_id(theReceiver: id, - theSelector: SEL, - a: id, - b: id, - c: id, - d: id, - e: id) - -> id; - pub fn invoke_msg_NSInteger(theReceiver: id, theSelector: SEL) -> NSInteger; - pub fn invoke_msg_long(theReceiver: id, theSelector: SEL) -> c_long; - pub fn invoke_msg_void(theReceiver: id, theSelector: SEL); - pub fn invoke_msg_void_bool(theReceiver: id, theSelector: SEL, a: bool); - pub fn invoke_msg_void_id(theReceiver: id, theSelector: SEL, a: id); - pub fn invoke_msg_void_NSInteger(theReceiver: id, theSelector: SEL, a: NSInteger); - pub fn invoke_msg_void_NSPoint(theReceiver: id, theSelector: SEL, a: NSPoint); - pub fn invoke_msg_void_NSSize(theReceiver: id, theSelector: SEL, a: NSSize); - pub fn invoke_msg_void_NSRect_bool(theReceiver: id, theSelector: SEL, a: NSRect, b: bool); - pub fn invoke_msg_void_NSWindowOrderingMode_NSInteger(theReceiver: id, theSelector: SEL, a: NSWindowOrderingMode, b: NSInteger); - pub fn invoke_msg_bool(theReceiver: id, theSelector: SEL) -> bool; - pub fn invoke_msg_bool_long(theReceiver: id, theSelector: SEL, a: c_long) -> bool; - pub fn invoke_msg_CGFloat(theReceiver: id, theSelector: SEL) -> CGFloat; - pub fn invoke_msg_NSPoint_NSPoint(theReceiver: id, theSelector: SEL, a: NSPoint) -> NSPoint; - pub fn invoke_msg_NSRect(theReceiver: id, theSelector: SEL) -> NSRect; - pub fn invoke_msg_NSRect_NSAlignmentOptions(theReceiver: id, theSelector: SEL, a: NSRect, b: NSAlignmentOptions) -> NSRect; - pub fn invoke_msg_NSRect_NSRect(theReceiver: id, theSelector: SEL, a: NSRect) -> NSRect; - pub fn invoke_msg_NSSize(theReceiver: id, theSelector: SEL) -> NSSize; -} - diff --git a/src/msgsend.m b/src/msgsend.m deleted file mode 100644 index 75f9f96..0000000 --- a/src/msgsend.m +++ /dev/null @@ -1,122 +0,0 @@ -// 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. - -#include -#include -#include -#include -#include - -double invoke_msg_double(id theReceiver, SEL theSelector) { - double (*f)(id self, SEL op, ...) = (void *)objc_msgSend_fpret; - return f(theReceiver, theSelector); -} - -id invoke_msg_id(id theReceiver, SEL theSelector) { - return objc_msgSend(theReceiver, theSelector); -} - -id invoke_msg_id_id(id theReceiver, SEL theSelector, id a) { - return objc_msgSend(theReceiver, theSelector, a); -} - -id invoke_msg_id_NSRect(id theReceiver, SEL theSelector, NSRect *rect) { - return objc_msgSend(theReceiver, theSelector, *rect); -} - -id invoke_msg_id_id_SEL_id(id theReceiver, SEL theSelector, id a, SEL b, id c) { - return objc_msgSend(theReceiver, theSelector, a, b, c); -} - -id invoke_msg_id_id_id_id_id_id(id theReceiver, SEL theSelector, id a, id b, id c, id d, id e) { - return objc_msgSend(theReceiver, theSelector, a, b, c, d, e); -} - -id invoke_msg_id_NSRect_ulong_ulong_bool(id theReceiver, SEL theSelector, NSRect a, unsigned long b, unsigned long c, bool d) { - return objc_msgSend(theReceiver, theSelector, a, b, c, d); -} - -NSInteger invoke_msg_NSInteger(id theReceiver, SEL theSelector) { - NSInteger (*f)(id self, SEL op) = (void *)objc_msgSend; - return f(theReceiver, theSelector); -} - -long invoke_msg_long(id theReceiver, SEL theSelector) { - return (long)objc_msgSend(theReceiver, theSelector); -} - -void invoke_msg_void(id theReceiver, SEL theSelector) { - objc_msgSend(theReceiver, theSelector); -} - -void invoke_msg_void_bool(id theReceiver, SEL theSelector, bool a) { - objc_msgSend(theReceiver, theSelector, a); -} - -void invoke_msg_void_id(id theReceiver, SEL theSelector, id id) { - objc_msgSend(theReceiver, theSelector, id); -} - -void invoke_msg_void_NSInteger(id theReceiver, SEL theSelector, NSInteger a) { - objc_msgSend(theReceiver, theSelector, a); -} - -void invoke_msg_void_NSPoint(id theReceiver, SEL theSelector, NSPoint a) { - objc_msgSend(theReceiver, theSelector, a); -} - -void invoke_msg_void_NSSize(id theReceiver, SEL theSelector, NSSize a) { - objc_msgSend(theReceiver, theSelector, a); -} - -void invoke_msg_void_NSRect_bool(id theReceiver, SEL theSelector, NSRect a, bool b) { - objc_msgSend(theReceiver, theSelector, a, b); -} - -void invoke_msg_void_NSWindowOrderingMode_NSInteger(id theReceiver, SEL theSelector, NSWindowOrderingMode a, NSInteger b) { - objc_msgSend(theReceiver, theSelector, a, b); -} - -bool invoke_msg_bool(id theReceiver, SEL theSelector) { - return objc_msgSend(theReceiver, theSelector); -} - -bool invoke_msg_bool_long(id theReceiver, SEL theSelector, long a) { - return objc_msgSend(theReceiver, theSelector, a); -} - -CGFloat invoke_msg_CGFloat(id theReceiver, SEL theSelector) { - CGFloat (*f)(id self, SEL op) = (void *)objc_msgSend; - return f(theReceiver, theSelector); -} - -NSPoint invoke_msg_NSPoint_NSPoint(id theReceiver, SEL theSelector, NSPoint point) { - NSPoint (*f)(id self, SEL op, NSPoint p) = (void *)objc_msgSend; - return f(theReceiver, theSelector, point); -} - -NSRect invoke_msg_NSRect(id theReceiver, SEL theSelector) { - NSRect (*f)(id self, SEL op) = (void *)objc_msgSend; - return f(theReceiver, theSelector); -} - -NSRect invoke_msg_NSRect_NSAlignmentOptions(id theReceiver, SEL theSelector, NSRect rect, NSAlignmentOptions options) { - NSRect (*f)(id self, SEL op, NSRect r, NSAlignmentOptions opts) = (void *)objc_msgSend; - return f(theReceiver, theSelector, rect, options); -} - -NSRect invoke_msg_NSRect_NSRect(id theReceiver, SEL theSelector, NSRect rect) { - NSRect (*f)(id self, SEL op, NSRect r) = (void *)objc_msgSend; - return f(theReceiver, theSelector, rect); -} - -NSSize invoke_msg_NSSize(id theReceiver, SEL theSelector) { - NSSize (*f)(id self, SEL op) = (void *)objc_msgSend; - return f(theReceiver, theSelector); -} From ce40173504e895c3ccdc01662c56f3bcb678a44a Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 11 Nov 2014 01:17:10 +1100 Subject: [PATCH 086/249] Fix doc tests --- src/base.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/base.rs b/src/base.rs index 6becd4f..47eef81 100644 --- a/src/base.rs +++ b/src/base.rs @@ -75,7 +75,13 @@ pub fn selector(name: &str) -> SEL { /// A trait that allows syntax like: /// -/// let string = "NSString".send("alloc").send("initWithUTF8String:", "Hello world!"); +/// ~~~rust +/// # use cocoa::base::{ObjCMethodCall, id}; +/// # unsafe { +/// let string = "NSString".send("alloc", ()) +/// .send("initWithUTF8String:", "Hello world!".as_ptr() as id); +/// # } +/// ~~~ pub trait ObjCMethodCall { unsafe fn send(self, selector: S, args: A) -> id; unsafe fn send_double(self, selector: S, args: A) @@ -143,7 +149,12 @@ impl ObjCMethodCall for id { /// A convenience implementation that allows methods on class names to be called directly, as in: /// -/// "NSString".send("alloc") +/// ~~~rust +/// # use cocoa::base::ObjCMethodCall; +/// # unsafe { +/// "NSString".send("alloc", ()) +/// # }; +/// ~~~ impl<'a> ObjCMethodCall for &'a str { #[inline] unsafe fn send(self, selector: S, args: A) -> id { From 494693673378da8db4085a575494f952e3fef4b2 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 11 Nov 2014 01:19:30 +1100 Subject: [PATCH 087/249] Eliminate some warnings --- examples/hello_world.rs | 2 +- src/appkit.rs | 2 +- src/base.rs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 165a827..37b10dd 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -10,7 +10,7 @@ use cocoa::appkit::{NSApp, NSRect, NSPoint, NSSize, fn main() { unsafe { - let pool = NSAutoreleasePool::new(nil); + let _pool = NSAutoreleasePool::new(nil); let app = NSApp(); app.setActivationPolicy_(NSApplicationActivationPolicyRegular); diff --git a/src/appkit.rs b/src/appkit.rs index 488e78d..9779604 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -9,7 +9,7 @@ #![allow(non_upper_case_globals)] -use base::{ObjCMethodCall, id, SEL, nil, NSInteger, NSUInteger}; +use base::{ObjCMethodCall, id, SEL, NSInteger, NSUInteger}; use libc; #[cfg(target_word_size = "32")] diff --git a/src/base.rs b/src/base.rs index 47eef81..13e09da 100644 --- a/src/base.rs +++ b/src/base.rs @@ -32,7 +32,8 @@ pub type NSInteger = libc::c_long; #[cfg(target_word_size = "64")] pub type NSUInteger = libc::c_ulong; -pub static nil: id = 0 as id; +#[allow(non_upper_case_globals)] +pub const nil: id = 0; extern { pub fn class_addMethod(cls: Class, name: SEL, imp: IMP, types: *const libc::c_char) -> bool; From 51a5137a202ec7edfca73cd45edbbf9cfc22908e Mon Sep 17 00:00:00 2001 From: David Partouche Date: Sat, 4 Oct 2014 15:39:00 +0200 Subject: [PATCH 088/249] Added some functions and types used for glutin --- src/appkit.rs | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/base.rs | 31 +++++++ 2 files changed, 255 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 9779604..bcd8366 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -68,6 +68,11 @@ impl NSRect { #[link(name = "AppKit", kind = "framework")] extern {} +#[link(name = "Foundation", kind = "framework")] +extern { + pub static NSDefaultRunLoopMode: id; +} + pub unsafe fn NSApp() -> id { "NSApplication".send("sharedApplication", ()) } @@ -142,6 +147,114 @@ bitflags! { | NSAlignMinYNearest.bits | NSAlignMaxYNearest.bits, } + +#[repr(u64)] +pub enum NSOpenGLPixelFormatAttribute { + NSOpenGLPFAAllRenderers = 1, + NSOpenGLPFATripleBuffer = 3, + NSOpenGLPFADoubleBuffer = 5, + NSOpenGLPFAStereo = 6, + NSOpenGLPFAAuxBuffers = 7, + NSOpenGLPFAColorSize = 8, + NSOpenGLPFAAlphaSize = 11, + NSOpenGLPFADepthSize = 12, + NSOpenGLPFAStencilSize = 13, + NSOpenGLPFAAccumSize = 14, + NSOpenGLPFAMinimumPolicy = 51, + NSOpenGLPFAMaximumPolicy = 52, + NSOpenGLPFAOffScreen = 53, + NSOpenGLPFAFullScreen = 54, + NSOpenGLPFASampleBuffers = 55, + NSOpenGLPFASamples = 56, + NSOpenGLPFAAuxDepthStencil = 57, + NSOpenGLPFAColorFloat = 58, + NSOpenGLPFAMultisample = 59, + NSOpenGLPFASupersample = 60, + NSOpenGLPFASampleAlpha = 61, + NSOpenGLPFARendererID = 70, + NSOpenGLPFASingleRenderer = 71, + NSOpenGLPFANoRecovery = 72, + NSOpenGLPFAAccelerated = 73, + NSOpenGLPFAClosestPolicy = 74, + NSOpenGLPFARobust = 75, + NSOpenGLPFABackingStore = 76, + NSOpenGLPFAMPSafe = 78, + NSOpenGLPFAWindow = 80, + NSOpenGLPFAMultiScreen = 81, + NSOpenGLPFACompliant = 83, + NSOpenGLPFAScreenMask = 84, + NSOpenGLPFAPixelBuffer = 90, + NSOpenGLPFARemotePixelBuffer = 91, + NSOpenGLPFAAllowOfflineRenderers = 96, + NSOpenGLPFAAcceleratedCompute = 97, + NSOpenGLPFAOpenGLProfile = 99, + NSOpenGLPFAVirtualScreenCount = 128, +} + +#[repr(u64)] +pub enum NSEventType { + NSLeftMouseDown = 1, + NSLeftMouseUp = 2, + NSRightMouseDown = 3, + NSRightMouseUp = 4, + NSMouseMoved = 5, + NSLeftMouseDragged = 6, + NSRightMouseDragged = 7, + NSMouseEntered = 8, + NSMouseExited = 9, + NSKeyDown = 10, + NSKeyUp = 11, + NSFlagsChanged = 12, + NSAppKitDefined = 13, + NSSystemDefined = 14, + NSApplicationDefined = 15, + NSPeriodic = 16, + NSCursorUpdate = 17, + NSScrollWheel = 22, + NSTabletPoint = 23, + NSTabletProximity = 24, + NSOtherMouseDown = 25, + NSOtherMouseUp = 26, + NSOtherMouseDragged = 27, + NSEventTypeGesture = 29, + NSEventTypeMagnify = 30, + NSEventTypeSwipe = 31, + NSEventTypeRotate = 18, + NSEventTypeBeginGesture = 19, + NSEventTypeEndGesture = 20, +} + +#[repr(u64)] +pub enum NSEventMask { + NSLeftMouseDownMask = 1 << NSLeftMouseDown as uint, + NSLeftMouseUpMask = 1 << NSLeftMouseUp as uint, + NSRightMouseDownMask = 1 << NSRightMouseDown as uint, + NSRightMouseUpMask = 1 << NSRightMouseUp as uint, + NSMouseMovedMask = 1 << NSMouseMoved as uint, + NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged as uint, + NSRightMouseDraggedMask = 1 << NSRightMouseDragged as uint, + NSMouseEnteredMask = 1 << NSMouseEntered as uint, + NSMouseExitedMask = 1 << NSMouseExited as uint, + NSKeyDownMask = 1 << NSKeyDown as uint, + NSKeyUpMask = 1 << NSKeyUp as uint, + NSFlagsChangedMask = 1 << NSFlagsChanged as uint, + NSAppKitDefinedMask = 1 << NSAppKitDefined as uint, + NSSystemDefinedMask = 1 << NSSystemDefined as uint, + NSAPplicationDefinedMask = 1 << NSApplicationDefined as uint, + NSPeriodicMask = 1 << NSPeriodic as uint, + NSCursorUpdateMask = 1 << NSCursorUpdate as uint, + NSScrollWheelMask = 1 << NSScrollWheel as uint, + NSTabletPointMask = 1 << NSTabletPoint as uint, + NSTabletProximityMask = 1 << NSTabletProximity as uint, + NSOtherMouseDownMask = 1 << NSOtherMouseDown as uint, + NSOtherMouseUpMask = 1 << NSOtherMouseUp as uint, + NSOtherMouseDraggedMask = 1 << NSOtherMouseDragged as uint, + NSEventMaskgesture = 1 << NSEventTypeGesture as uint, + NSEventMaskSwipe = 1 << NSEventTypeSwipe as uint, + NSEventMaskRotate = 1 << NSEventTypeRotate as uint, + NSEventMaskBeginGesture = 1 << NSEventTypeBeginGesture as uint, + NSEventMaskEndGesture = 1 << NSEventTypeEndGesture as uint, + NSAnyEventMask = 0xffffffff, } pub trait NSAutoreleasePool { @@ -181,6 +294,9 @@ pub trait NSApplication { unsafe fn setMainMenu_(self, menu: id); unsafe fn activateIgnoringOtherApps_(self, ignore: bool); unsafe fn run(self); + unsafe fn finishLaunching(self); + unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, mask: NSUInteger, expiration: id, in_mode: id, dequeue: bool) -> id; + unsafe fn sendEvent_(self, an_event: id); } impl NSApplication for id { @@ -199,6 +315,18 @@ impl NSApplication for id { unsafe fn run(self) { self.send_void("run", ()); } + + unsafe fn finishLaunching(self) { + self.send_void("finishLaunching", ()) + } + + unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, mask: NSUInteger, expiration: id, in_mode: id, dequeue: bool) -> id { + self.send("nextEventMatchingMask:untilDate:inMode:dequeue:", (mask, expiration, in_mode, dequeue)) + } + + unsafe fn sendEvent_(self, an_event: id) { + self.send_void("sendEvent:", an_event) + } } pub trait NSMenu { @@ -333,6 +461,8 @@ pub trait NSWindow { // skipped: setMiniwindowImage unsafe fn miniwindowTitle(self) -> id; unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id); + + unsafe fn setContentView(self, view: id); } impl NSWindow for id { @@ -584,6 +714,10 @@ impl NSWindow for id { unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id) { self.send_void("setMiniwindowTitle:", miniwindowTitle); } + + unsafe fn setContentView(self, view: id) { + self.send_void("setContentView:", view) + } } pub trait NSString { @@ -610,3 +744,93 @@ impl NSString for id { } } +pub trait NSView { + unsafe fn alloc(_: Self) -> id { + "NSView".send("alloc", ()) + } + + unsafe fn init(self) -> id; + unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; + unsafe fn display_(self); + unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: bool); +} + +impl NSView for id { + unsafe fn init(self) -> id { + self.send("init", ()) + } + + unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { + self.send("initWithFrame:", frameRect) + } + + unsafe fn display_(self) { + self.send_void("display", ()) + } + + unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: bool) { + self.send_void("setWantsBestResolutionOpenGLSurface:", flag) + } +} + +pub trait NSOpenGLView { + unsafe fn alloc(_: Self) -> id { + "NSOpenGLView".send("alloc", ()) + } + + unsafe fn initWithFrame_pixelFormat_(self, frameRect: NSRect, format: id) -> id; + unsafe fn display_(self); +} + +impl NSOpenGLView for id { + unsafe fn initWithFrame_pixelFormat_(self, frameRect: NSRect, format: id) -> id { + self.send("initWithFrame:pixelFormat:", (frameRect, format)) + } + + unsafe fn display_(self) { + self.send_void("display", ()) + } +} + +pub trait NSOpenGLPixelFormat { + unsafe fn alloc(_: Self) -> id { + "NSOpenGLPixelFormat".send("alloc", ()) + } + + unsafe fn initWithAttributes_(self, attributes: &[uint]) -> id; +} + +impl NSOpenGLPixelFormat for id { + unsafe fn initWithAttributes_(self, attributes: &[uint]) -> id { + self.send("initWithAttributes:", attributes) + } +} + +pub trait NSOpenGLContext { + unsafe fn alloc(_: Self) -> id { + "NSOpenGLContext".send("alloc", ()) + } + + unsafe fn initWithFormat_shareContext_(self, format: id, shareContext: id) -> id; + unsafe fn setView_(self, view: id); + unsafe fn makeCurrentContext(self); + unsafe fn flushBuffer(self); +} + +impl NSOpenGLContext for id { + unsafe fn initWithFormat_shareContext_(self, format: id, shareContext: id) -> id { + self.send("initWithFormat:shareContext:", (format, shareContext)) + } + + unsafe fn setView_(self, view: id) { + self.send_void("setView:", view) + } + + unsafe fn makeCurrentContext(self) { + self.send_void("makeCurrentContext", ()) + } + + unsafe fn flushBuffer(self) { + self.send_void("flushBuffer", ()) + } +} diff --git a/src/base.rs b/src/base.rs index 13e09da..e75e53f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -306,6 +306,37 @@ impl ObjCMethodArgs for (id, id, id, id, id) { } } +impl ObjCMethodArgs for (NSRect, id) { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second) = self; + invoke_msg_id_NSRect_id(receiver, selector, first, second) + } +} + +impl<'a> ObjCMethodArgs for &'a [uint] { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + invoke_msg_id_array(receiver, selector, self) + } +} + +impl ObjCMethodArgs for (id, id) { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second) = self; + invoke_msg_id_id_id(receiver, selector, first, second) + } +} + +impl ObjCMethodArgs for (NSUInteger, id, id, bool) { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second, third, fourth) = self; + invoke_msg_id_NSUInteger_id_id_bool(receiver, selector, first, second, third, fourth) + } +} + impl ObjCMethodDoubleArgs for () { #[inline] unsafe fn send_double_args(self, receiver: id, selector: SEL) -> f64 { From 36966ddf740404410260a6e49b5dab98dee4bf8f Mon Sep 17 00:00:00 2001 From: David Partouche Date: Sat, 4 Oct 2014 21:57:33 +0200 Subject: [PATCH 089/249] Added some functions and types used for glutin --- src/appkit.rs | 19 ++++++++++++++++--- src/base.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index bcd8366..ec106bb 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -295,7 +295,11 @@ pub trait NSApplication { unsafe fn activateIgnoringOtherApps_(self, ignore: bool); unsafe fn run(self); unsafe fn finishLaunching(self); - unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, mask: NSUInteger, expiration: id, in_mode: id, dequeue: bool) -> id; + unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, + mask: NSUInteger, + expiration: id, + in_mode: id, + dequeue: bool) -> id; unsafe fn sendEvent_(self, an_event: id); } @@ -320,8 +324,13 @@ impl NSApplication for id { self.send_void("finishLaunching", ()) } - unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, mask: NSUInteger, expiration: id, in_mode: id, dequeue: bool) -> id { - self.send("nextEventMatchingMask:untilDate:inMode:dequeue:", (mask, expiration, in_mode, dequeue)) + unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, + mask: NSUInteger, + expiration: id, + in_mode: id, + dequeue: bool) -> id { + self.send("nextEventMatchingMask:untilDate:inMode:dequeue:", + (mask, expiration, in_mode, dequeue)) } unsafe fn sendEvent_(self, an_event: id) { @@ -718,6 +727,10 @@ impl NSWindow for id { unsafe fn setContentView(self, view: id) { self.send_void("setContentView:", view) } + + unsafe fn setContentView(self, view: id) { + self.send_void("setContentView:", view) + } } pub trait NSString { diff --git a/src/base.rs b/src/base.rs index e75e53f..7c00cf1 100644 --- a/src/base.rs +++ b/src/base.rs @@ -337,6 +337,37 @@ impl ObjCMethodArgs for (NSUInteger, id, id, bool) { } } +impl ObjCMethodArgs for (NSRect, id) { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second) = self; + invoke_msg_id_NSRect_id(receiver, selector, first, second) + } +} + +impl<'a> ObjCMethodArgs for &'a [uint] { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + invoke_msg_id_array(receiver, selector, self) + } +} + +impl ObjCMethodArgs for (id, id) { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second) = self; + invoke_msg_id_id_id(receiver, selector, first, second) + } +} + +impl ObjCMethodArgs for (NSUInteger, id, id, bool) { + #[inline] + unsafe fn send_args(self, receiver: id, selector: SEL) -> id { + let (first, second, third, fourth) = self; + invoke_msg_id_NSUInteger_id_id_bool(receiver, selector, first, second, third, fourth) + } +} + impl ObjCMethodDoubleArgs for () { #[inline] unsafe fn send_double_args(self, receiver: id, selector: SEL) -> f64 { From b821489e9b5cb00ee7c82d79658f0ed2ddbf3426 Mon Sep 17 00:00:00 2001 From: David Partouche Date: Mon, 6 Oct 2014 16:16:16 +0200 Subject: [PATCH 090/249] Added NSDate and NSEvent functions to handle events in the glutin crate --- src/appkit.rs | 24 ++++++++++++++++++++++++ src/base.rs | 18 +++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/appkit.rs b/src/appkit.rs index ec106bb..53e9e5c 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -847,3 +847,27 @@ impl NSOpenGLContext for id { self.send_void("flushBuffer", ()) } } + +pub trait NSDate { + unsafe fn distantPast(_: Self) -> id { + "NSDate".send("distantPast", ()) + } + + unsafe fn distantFuture(_: Self) -> id { + "NSDate".send("distantFuture", ()) + } +} + +impl NSDate for id { + +} + +pub trait NSEvent { + unsafe fn get_type(self) -> NSEventType; +} + +impl NSEvent for id { + unsafe fn get_type(self) -> NSEventType { + self.send_event("type", ()) + } +} diff --git a/src/base.rs b/src/base.rs index 7c00cf1..685cdb9 100644 --- a/src/base.rs +++ b/src/base.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use appkit::{CGFloat, NSPoint, NSRect, NSSize}; +use appkit::{CGFloat, NSPoint, NSRect, NSSize, NSEventType}; use appkit::{NSWindowOrderingMode, NSAlignmentOptions}; use libc::{c_double, c_long, c_ulong, c_char}; @@ -95,6 +95,7 @@ pub trait ObjCMethodCall { unsafe fn send_point(self, selector: S, args: A) -> NSPoint; unsafe fn send_rect(self, selector: S, args: A) -> NSRect; unsafe fn send_size(self, selector: S, args: A) -> NSSize; + unsafe fn send_event(self, selector: S, args: A) -> NSEventType; } impl ObjCMethodCall for id { @@ -145,6 +146,9 @@ impl ObjCMethodCall for id { unsafe fn send_size(self, selector: S, args: A) -> NSSize { args.send_size_args(self, selector.as_selector()) + unsafe fn send_event(self, selector: S, args: A) + -> NSEventType { + args.send_event_args(self, selector.as_selector()) } } @@ -204,6 +208,9 @@ impl<'a> ObjCMethodCall for &'a str { unsafe fn send_size(self, selector: S, args: A) -> NSSize { args.send_size_args(class(self), selector.as_selector()) + unsafe fn send_event(self, selector: S, args: A) + -> NSEventType { + args.send_event_args(class(self), selector.as_selector()) } } @@ -259,6 +266,8 @@ pub trait ObjCMethodRectArgs { } pub trait ObjCMethodSizeArgs { unsafe fn send_size_args(self, receiver: id, selector: SEL) -> NSSize; +pub trait ObjCMethodEventArgs { + unsafe fn send_event_args(self, receiver: id, selector: SEL) -> NSEventType; } impl ObjCMethodArgs for () { @@ -505,6 +514,13 @@ impl ObjCMethodSizeArgs for () { } } +impl ObjCMethodEventArgs for () { + #[inline] + unsafe fn send_event_args(self, receiver: id, selector: SEL) -> NSEventType { + invoke_msg_NSEventType(receiver, selector) + } +} + /// A trait that simulates variadic parameters for method calls. #[cfg(test)] From f9f7161c4cff4132e2010b0151a46078deba4b78 Mon Sep 17 00:00:00 2001 From: David Partouche Date: Sat, 11 Oct 2014 11:33:22 +0200 Subject: [PATCH 091/249] Added some functions used for mouse events --- src/appkit.rs | 19 +++++++++++++++++-- src/base.rs | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 53e9e5c..00e017d 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -471,7 +471,8 @@ pub trait NSWindow { unsafe fn miniwindowTitle(self) -> id; unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id); - unsafe fn setContentView(self, view: id); + unsafe fn setContentView_(self, view: id); + unsafe fn setAcceptsMouseMovedEvents_(self, accept: bool); } impl NSWindow for id { @@ -728,9 +729,13 @@ impl NSWindow for id { self.send_void("setContentView:", view) } - unsafe fn setContentView(self, view: id) { + unsafe fn setContentView_(self, view: id) { self.send_void("setContentView:", view) } + + unsafe fn setAcceptsMouseMovedEvents_(self, accept: bool) { + self.send_void("setAcceptsMouseMovedEvents:", accept); + } } pub trait NSString { @@ -766,6 +771,7 @@ pub trait NSView { unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; unsafe fn display_(self); unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: bool); + unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint; } impl NSView for id { @@ -784,6 +790,10 @@ impl NSView for id { unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: bool) { self.send_void("setWantsBestResolutionOpenGLSurface:", flag) } + + unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint { + self.send_point("convertPoint:fromView:", (point, view)) + } } pub trait NSOpenGLView { @@ -864,10 +874,15 @@ impl NSDate for id { pub trait NSEvent { unsafe fn get_type(self) -> NSEventType; + unsafe fn locationInWindow(self) -> NSPoint; } impl NSEvent for id { unsafe fn get_type(self) -> NSEventType { self.send_event("type", ()) } + + unsafe fn locationInWindow(self) -> NSPoint { + self.send_point("locationInWindow", ()) + } } diff --git a/src/base.rs b/src/base.rs index 685cdb9..965e128 100644 --- a/src/base.rs +++ b/src/base.rs @@ -514,6 +514,13 @@ impl ObjCMethodSizeArgs for () { } } +impl ObjCMethodPointArgs for () { + #[inline] + unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint { + invoke_msg_id_NSPoint(receiver, selector) + } +} + impl ObjCMethodEventArgs for () { #[inline] unsafe fn send_event_args(self, receiver: id, selector: SEL) -> NSEventType { @@ -521,6 +528,13 @@ impl ObjCMethodEventArgs for () { } } +impl ObjCMethodPointArgs for (NSPoint, id) { + #[inline] + unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint { + let (first, second) = self; + invoke_msg_NSPoint_NSPoint_id(receiver, selector, first, second) + } +} /// A trait that simulates variadic parameters for method calls. #[cfg(test)] From f3a488d98af771e997ba1382bacca6f66f4ab95e Mon Sep 17 00:00:00 2001 From: David Partouche Date: Sun, 12 Oct 2014 20:09:48 +0200 Subject: [PATCH 092/249] Added more NSEvent functions for glutin --- src/appkit.rs | 30 ++++++++++++++++++++++++++++ src/base.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/appkit.rs b/src/appkit.rs index 00e017d..62eca8f 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -224,6 +224,16 @@ pub enum NSEventType { NSEventTypeEndGesture = 20, } +#[repr(u64)] +pub enum NSEventSubtype { + NSWindowExposedEventType = 0, + NSApplicationActivatedEventType = 1, + NSApplicationDeactivatedEventType = 2, + NSWindowMovedEventType = 4, + NSScreenChangedEventType = 8, + NSAWTEventType = 16, +} + #[repr(u64)] pub enum NSEventMask { NSLeftMouseDownMask = 1 << NSLeftMouseDown as uint, @@ -473,6 +483,7 @@ pub trait NSWindow { unsafe fn setContentView_(self, view: id); unsafe fn setAcceptsMouseMovedEvents_(self, accept: bool); + unsafe fn isVisible(self) -> bool; } impl NSWindow for id { @@ -736,6 +747,10 @@ impl NSWindow for id { unsafe fn setAcceptsMouseMovedEvents_(self, accept: bool) { self.send_void("setAcceptsMouseMovedEvents:", accept); } + + unsafe fn isVisible(self) -> bool { + self.send_bool("isVisible", ()) + } } pub trait NSString { @@ -746,6 +761,7 @@ pub trait NSString { unsafe fn initWithUTF8String_(self, c_string: *const u8) -> 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 { @@ -760,6 +776,10 @@ impl NSString for id { unsafe fn init_str(self, string: &str) -> id { self.initWithUTF8String_(string.as_ptr()) } + + unsafe fn UTF8String(self) -> *const libc::c_char { + self.send_string("UTF8String", ()) + } } pub trait NSView { @@ -874,7 +894,9 @@ impl NSDate for id { pub trait NSEvent { unsafe fn get_type(self) -> NSEventType; + unsafe fn get_subtype(self) -> NSEventSubtype; unsafe fn locationInWindow(self) -> NSPoint; + unsafe fn characters(self) -> id; } impl NSEvent for id { @@ -882,7 +904,15 @@ impl NSEvent for id { self.send_event("type", ()) } + unsafe fn get_subtype(self) -> NSEventSubtype { + self.send_eventSubtype("subtype", ()) + } + unsafe fn locationInWindow(self) -> NSPoint { self.send_point("locationInWindow", ()) } + + unsafe fn characters(self) -> id { + self.send("characters", ()) + } } diff --git a/src/base.rs b/src/base.rs index 965e128..47d1ef3 100644 --- a/src/base.rs +++ b/src/base.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use appkit::{CGFloat, NSPoint, NSRect, NSSize, NSEventType}; +use appkit::{CGFloat, NSPoint, NSRect, NSSize, NSEventType, NSEventSubtype}; use appkit::{NSWindowOrderingMode, NSAlignmentOptions}; use libc::{c_double, c_long, c_ulong, c_char}; @@ -96,6 +96,8 @@ pub trait ObjCMethodCall { unsafe fn send_rect(self, selector: S, args: A) -> NSRect; unsafe fn send_size(self, selector: S, args: A) -> NSSize; unsafe fn send_event(self, selector: S, args: A) -> NSEventType; + unsafe fn send_eventSubtype(self, selector: S, args: A) -> NSEventSubtype; + unsafe fn send_string(self, selector: S, args: A) -> *const libc::c_char; } impl ObjCMethodCall for id { @@ -150,6 +152,16 @@ impl ObjCMethodCall for id { -> NSEventType { args.send_event_args(self, selector.as_selector()) } + #[inline] + unsafe fn send_eventSubtype(self, selector: S, args: A) + -> NSEventSubtype { + args.send_eventSubtype_args(self, selector.as_selector()) + } + #[inline] + unsafe fn send_string(self, selector: S, args: A) + -> *const libc::c_char { + args.send_string_args(self, selector.as_selector()) + } } /// A convenience implementation that allows methods on class names to be called directly, as in: @@ -212,6 +224,16 @@ impl<'a> ObjCMethodCall for &'a str { -> NSEventType { args.send_event_args(class(self), selector.as_selector()) } + #[inline] + unsafe fn send_eventSubtype(self, selector: S, args: A) + -> NSEventSubtype { + args.send_eventSubtype_args(class(self), selector.as_selector()) + } + #[inline] + unsafe fn send_string(self, selector: S, args: A) + -> *const libc::c_char { + args.send_string_args(class(self), selector.as_selector()) + } } /// A trait that allows C strings to be used as selectors without having to convert them first. @@ -270,6 +292,14 @@ pub trait ObjCMethodEventArgs { unsafe fn send_event_args(self, receiver: id, selector: SEL) -> NSEventType; } +pub trait ObjCMethodEventSubtypeArgs { + unsafe fn send_eventSubtype_args(self, receiver: id, selector: SEL) -> NSEventSubtype; +} + +pub trait ObjCMethodStringArgs { + unsafe fn send_string_args(self, receiver: id, selector: SEL) -> *const libc::c_char; +} + impl ObjCMethodArgs for () { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { @@ -457,6 +487,13 @@ impl ObjCMethodBoolArgs for () { } } +impl ObjCMethodBoolArgs for () { + #[inline] + unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool { + invoke_msg_bool(receiver, selector) + } +} + impl ObjCMethodBoolArgs for c_long { #[inline] unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool { @@ -535,6 +572,21 @@ impl ObjCMethodPointArgs for (NSPoint, id) { invoke_msg_NSPoint_NSPoint_id(receiver, selector, first, second) } } + +impl ObjCMethodEventSubtypeArgs for () { + #[inline] + unsafe fn send_eventSubtype_args(self, receiver: id, selector: SEL) -> NSEventSubtype { + invoke_msg_NSEventSubtype(receiver, selector) + } +} + +impl ObjCMethodStringArgs for () { + #[inline] + unsafe fn send_string_args(self, receiver: id, selector: SEL) -> *const libc::c_char { + invoke_msg_string(receiver, selector) + } +} + /// A trait that simulates variadic parameters for method calls. #[cfg(test)] From 51d6a9b463bc950d9c8e095e83f99a3f50890995 Mon Sep 17 00:00:00 2001 From: David Partouche Date: Wed, 15 Oct 2014 11:43:06 +0200 Subject: [PATCH 093/249] Added more functions to grab NSEvent keycodes --- src/appkit.rs | 28 ++++++++++++++++++++++++++++ src/base.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 62eca8f..093ce51 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -267,6 +267,19 @@ pub enum NSEventMask { NSAnyEventMask = 0xffffffff, } +#[repr(u64)] +pub enum NSEventModifierFlags { + NSAlphaShiftKeyMask = 1 << 16, + NSShiftKeyMask = 1 << 17, + NSControlKeyMask = 1 << 18, + NSAlternateKeyMask = 1 << 19, + NSCommandKeyMask = 1 << 20, + NSNumericPadKeyMask = 1 << 21, + NSHelpKeyMask = 1 << 22, + NSFunctionKeyMask = 1 << 23, + NSDeviceIndependentModifierFlagsMask = 0xffff0000, +} + pub trait NSAutoreleasePool { unsafe fn new(_: Self) -> id { "NSAutoreleasePool".send("new", ()) @@ -897,6 +910,9 @@ pub trait NSEvent { unsafe fn get_subtype(self) -> NSEventSubtype; unsafe fn locationInWindow(self) -> NSPoint; unsafe fn characters(self) -> id; + unsafe fn charactersIgnoringModifiers(self) -> id; + unsafe fn keycode(self) -> libc::c_ushort; + unsafe fn modifierFlags(self) -> NSUInteger; } impl NSEvent for id { @@ -915,4 +931,16 @@ impl NSEvent for id { unsafe fn characters(self) -> id { self.send("characters", ()) } + + unsafe fn charactersIgnoringModifiers(self) -> id { + self.send("charactersIgnoringModifiers", ()) + } + + unsafe fn keycode(self) -> libc::c_ushort { + self.send_ushort("keyCode", ()) + } + + unsafe fn modifierFlags(self) -> NSUInteger { + self.send_NSUInteger("modifierFlags", ()) + } } diff --git a/src/base.rs b/src/base.rs index 47d1ef3..7003334 100644 --- a/src/base.rs +++ b/src/base.rs @@ -98,6 +98,8 @@ pub trait ObjCMethodCall { unsafe fn send_event(self, selector: S, args: A) -> NSEventType; unsafe fn send_eventSubtype(self, selector: S, args: A) -> NSEventSubtype; unsafe fn send_string(self, selector: S, args: A) -> *const libc::c_char; + unsafe fn send_ushort(self, selector: S, args: A) -> libc::c_ushort; + unsafe fn send_NSUInteger(self, selector: S, args: A) -> NSUInteger; } impl ObjCMethodCall for id { @@ -162,6 +164,16 @@ impl ObjCMethodCall for id { -> *const libc::c_char { args.send_string_args(self, selector.as_selector()) } + #[inline] + unsafe fn send_ushort(self, selector: S, args: A) + -> libc::c_ushort { + args.send_ushort_args(self, selector.as_selector()) + } + #[inline] + unsafe fn send_NSUInteger(self, selector: S, args: A) + -> NSUInteger { + args.send_NSUInteger_args(self, selector.as_selector()) + } } /// A convenience implementation that allows methods on class names to be called directly, as in: @@ -234,6 +246,16 @@ impl<'a> ObjCMethodCall for &'a str { -> *const libc::c_char { args.send_string_args(class(self), selector.as_selector()) } + #[inline] + unsafe fn send_ushort(self, selector: S, args: A) + -> libc::c_ushort { + args.send_ushort_args(class(self), selector.as_selector()) + } + #[inline] + unsafe fn send_NSUInteger(self, selector: S, args: A) + -> NSUInteger { + args.send_NSUInteger_args(class(self), selector.as_selector()) + } } /// A trait that allows C strings to be used as selectors without having to convert them first. @@ -300,6 +322,14 @@ pub trait ObjCMethodStringArgs { unsafe fn send_string_args(self, receiver: id, selector: SEL) -> *const libc::c_char; } +pub trait ObjCMethodUShortArgs { + unsafe fn send_ushort_args(self, received: id, selector: SEL) -> libc::c_ushort; +} + +pub trait ObjCMethodNSUIntegerArgs { + unsafe fn send_NSUInteger_args(self, received: id, selector: SEL) -> NSUInteger; +} + impl ObjCMethodArgs for () { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { @@ -587,6 +617,20 @@ impl ObjCMethodStringArgs for () { } } +impl ObjCMethodUShortArgs for () { + #[inline] + unsafe fn send_ushort_args(self, receiver: id, selector: SEL) -> libc::c_ushort { + invoke_msg_ushort(receiver, selector) + } +} + +impl ObjCMethodNSUIntegerArgs for () { + #[inline] + unsafe fn send_NSUInteger_args(self, receiver: id, selector: SEL) -> NSUInteger { + invoke_msg_NSUInteger(receiver, selector) + } +} + /// A trait that simulates variadic parameters for method calls. #[cfg(test)] From 27b53079569c715c563f9b027e02528111ab37f8 Mon Sep 17 00:00:00 2001 From: David Partouche Date: Mon, 10 Nov 2014 18:42:21 +0100 Subject: [PATCH 094/249] Fixed some merge issues --- src/appkit.rs | 5 +--- src/base.rs | 65 +++++++++++++-------------------------------------- 2 files changed, 17 insertions(+), 53 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 093ce51..5202bde 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -147,6 +147,7 @@ bitflags! { | NSAlignMinYNearest.bits | NSAlignMaxYNearest.bits, } +} #[repr(u64)] pub enum NSOpenGLPixelFormatAttribute { @@ -749,10 +750,6 @@ impl NSWindow for id { self.send_void("setMiniwindowTitle:", miniwindowTitle); } - unsafe fn setContentView(self, view: id) { - self.send_void("setContentView:", view) - } - unsafe fn setContentView_(self, view: id) { self.send_void("setContentView:", view) } diff --git a/src/base.rs b/src/base.rs index 7003334..9e464f0 100644 --- a/src/base.rs +++ b/src/base.rs @@ -150,6 +150,8 @@ impl ObjCMethodCall for id { unsafe fn send_size(self, selector: S, args: A) -> NSSize { args.send_size_args(self, selector.as_selector()) + } + #[inline] unsafe fn send_event(self, selector: S, args: A) -> NSEventType { args.send_event_args(self, selector.as_selector()) @@ -232,6 +234,8 @@ impl<'a> ObjCMethodCall for &'a str { unsafe fn send_size(self, selector: S, args: A) -> NSSize { args.send_size_args(class(self), selector.as_selector()) + } + #[inline] unsafe fn send_event(self, selector: S, args: A) -> NSEventType { args.send_event_args(class(self), selector.as_selector()) @@ -310,6 +314,7 @@ pub trait ObjCMethodRectArgs { } pub trait ObjCMethodSizeArgs { unsafe fn send_size_args(self, receiver: id, selector: SEL) -> NSSize; +} pub trait ObjCMethodEventArgs { unsafe fn send_event_args(self, receiver: id, selector: SEL) -> NSEventType; } @@ -379,14 +384,14 @@ impl ObjCMethodArgs for (NSRect, id) { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { let (first, second) = self; - invoke_msg_id_NSRect_id(receiver, selector, first, second) + msg_send()(receiver, selector, first, second) } } impl<'a> ObjCMethodArgs for &'a [uint] { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - invoke_msg_id_array(receiver, selector, self) + msg_send()(receiver, selector, self) } } @@ -394,7 +399,7 @@ impl ObjCMethodArgs for (id, id) { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { let (first, second) = self; - invoke_msg_id_id_id(receiver, selector, first, second) + msg_send()(receiver, selector, first, second) } } @@ -402,38 +407,7 @@ impl ObjCMethodArgs for (NSUInteger, id, id, bool) { #[inline] unsafe fn send_args(self, receiver: id, selector: SEL) -> id { let (first, second, third, fourth) = self; - invoke_msg_id_NSUInteger_id_id_bool(receiver, selector, first, second, third, fourth) - } -} - -impl ObjCMethodArgs for (NSRect, id) { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - let (first, second) = self; - invoke_msg_id_NSRect_id(receiver, selector, first, second) - } -} - -impl<'a> ObjCMethodArgs for &'a [uint] { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - invoke_msg_id_array(receiver, selector, self) - } -} - -impl ObjCMethodArgs for (id, id) { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - let (first, second) = self; - invoke_msg_id_id_id(receiver, selector, first, second) - } -} - -impl ObjCMethodArgs for (NSUInteger, id, id, bool) { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - let (first, second, third, fourth) = self; - invoke_msg_id_NSUInteger_id_id_bool(receiver, selector, first, second, third, fourth) + msg_send()(receiver, selector, first, second, third, fourth as libc::c_int) } } @@ -517,13 +491,6 @@ impl ObjCMethodBoolArgs for () { } } -impl ObjCMethodBoolArgs for () { - #[inline] - unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool { - invoke_msg_bool(receiver, selector) - } -} - impl ObjCMethodBoolArgs for c_long { #[inline] unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool { @@ -584,14 +551,14 @@ impl ObjCMethodSizeArgs for () { impl ObjCMethodPointArgs for () { #[inline] unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint { - invoke_msg_id_NSPoint(receiver, selector) + msg_send()(receiver, selector) } } impl ObjCMethodEventArgs for () { #[inline] unsafe fn send_event_args(self, receiver: id, selector: SEL) -> NSEventType { - invoke_msg_NSEventType(receiver, selector) + msg_send()(receiver, selector) } } @@ -599,35 +566,35 @@ impl ObjCMethodPointArgs for (NSPoint, id) { #[inline] unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint { let (first, second) = self; - invoke_msg_NSPoint_NSPoint_id(receiver, selector, first, second) + msg_send()(receiver, selector, first, second) } } impl ObjCMethodEventSubtypeArgs for () { #[inline] unsafe fn send_eventSubtype_args(self, receiver: id, selector: SEL) -> NSEventSubtype { - invoke_msg_NSEventSubtype(receiver, selector) + msg_send()(receiver, selector) } } impl ObjCMethodStringArgs for () { #[inline] unsafe fn send_string_args(self, receiver: id, selector: SEL) -> *const libc::c_char { - invoke_msg_string(receiver, selector) + msg_send()(receiver, selector) } } impl ObjCMethodUShortArgs for () { #[inline] unsafe fn send_ushort_args(self, receiver: id, selector: SEL) -> libc::c_ushort { - invoke_msg_ushort(receiver, selector) + msg_send()(receiver, selector) } } impl ObjCMethodNSUIntegerArgs for () { #[inline] unsafe fn send_NSUInteger_args(self, receiver: id, selector: SEL) -> NSUInteger { - invoke_msg_NSUInteger(receiver, selector) + msg_send()(receiver, selector) } } From ad2f33054e67c98bb0fc2892b34bdda738ffff64 Mon Sep 17 00:00:00 2001 From: David Partouche Date: Mon, 10 Nov 2014 18:52:21 +0100 Subject: [PATCH 095/249] Removed NSEventSubtype, as it's only available from 10.10 --- src/appkit.rs | 15 --------------- src/base.rs | 24 +----------------------- 2 files changed, 1 insertion(+), 38 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 5202bde..062efdd 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -225,16 +225,6 @@ pub enum NSEventType { NSEventTypeEndGesture = 20, } -#[repr(u64)] -pub enum NSEventSubtype { - NSWindowExposedEventType = 0, - NSApplicationActivatedEventType = 1, - NSApplicationDeactivatedEventType = 2, - NSWindowMovedEventType = 4, - NSScreenChangedEventType = 8, - NSAWTEventType = 16, -} - #[repr(u64)] pub enum NSEventMask { NSLeftMouseDownMask = 1 << NSLeftMouseDown as uint, @@ -904,7 +894,6 @@ impl NSDate for id { pub trait NSEvent { unsafe fn get_type(self) -> NSEventType; - unsafe fn get_subtype(self) -> NSEventSubtype; unsafe fn locationInWindow(self) -> NSPoint; unsafe fn characters(self) -> id; unsafe fn charactersIgnoringModifiers(self) -> id; @@ -917,10 +906,6 @@ impl NSEvent for id { self.send_event("type", ()) } - unsafe fn get_subtype(self) -> NSEventSubtype { - self.send_eventSubtype("subtype", ()) - } - unsafe fn locationInWindow(self) -> NSPoint { self.send_point("locationInWindow", ()) } diff --git a/src/base.rs b/src/base.rs index 9e464f0..a069e1c 100644 --- a/src/base.rs +++ b/src/base.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use appkit::{CGFloat, NSPoint, NSRect, NSSize, NSEventType, NSEventSubtype}; +use appkit::{CGFloat, NSPoint, NSRect, NSSize, NSEventType}; use appkit::{NSWindowOrderingMode, NSAlignmentOptions}; use libc::{c_double, c_long, c_ulong, c_char}; @@ -96,7 +96,6 @@ pub trait ObjCMethodCall { unsafe fn send_rect(self, selector: S, args: A) -> NSRect; unsafe fn send_size(self, selector: S, args: A) -> NSSize; unsafe fn send_event(self, selector: S, args: A) -> NSEventType; - unsafe fn send_eventSubtype(self, selector: S, args: A) -> NSEventSubtype; unsafe fn send_string(self, selector: S, args: A) -> *const libc::c_char; unsafe fn send_ushort(self, selector: S, args: A) -> libc::c_ushort; unsafe fn send_NSUInteger(self, selector: S, args: A) -> NSUInteger; @@ -157,11 +156,6 @@ impl ObjCMethodCall for id { args.send_event_args(self, selector.as_selector()) } #[inline] - unsafe fn send_eventSubtype(self, selector: S, args: A) - -> NSEventSubtype { - args.send_eventSubtype_args(self, selector.as_selector()) - } - #[inline] unsafe fn send_string(self, selector: S, args: A) -> *const libc::c_char { args.send_string_args(self, selector.as_selector()) @@ -241,11 +235,6 @@ impl<'a> ObjCMethodCall for &'a str { args.send_event_args(class(self), selector.as_selector()) } #[inline] - unsafe fn send_eventSubtype(self, selector: S, args: A) - -> NSEventSubtype { - args.send_eventSubtype_args(class(self), selector.as_selector()) - } - #[inline] unsafe fn send_string(self, selector: S, args: A) -> *const libc::c_char { args.send_string_args(class(self), selector.as_selector()) @@ -319,10 +308,6 @@ pub trait ObjCMethodEventArgs { unsafe fn send_event_args(self, receiver: id, selector: SEL) -> NSEventType; } -pub trait ObjCMethodEventSubtypeArgs { - unsafe fn send_eventSubtype_args(self, receiver: id, selector: SEL) -> NSEventSubtype; -} - pub trait ObjCMethodStringArgs { unsafe fn send_string_args(self, receiver: id, selector: SEL) -> *const libc::c_char; } @@ -570,13 +555,6 @@ impl ObjCMethodPointArgs for (NSPoint, id) { } } -impl ObjCMethodEventSubtypeArgs for () { - #[inline] - unsafe fn send_eventSubtype_args(self, receiver: id, selector: SEL) -> NSEventSubtype { - msg_send()(receiver, selector) - } -} - impl ObjCMethodStringArgs for () { #[inline] unsafe fn send_string_args(self, receiver: id, selector: SEL) -> *const libc::c_char { From 274a5f9e872f3a20ba6dbabb2580d99656eaa4e3 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 11 Nov 2014 12:08:44 +1100 Subject: [PATCH 096/249] Remove method traits --- examples/hello_world.rs | 4 +- src/appkit.rs | 221 ++++++++--------- src/base.rs | 517 +--------------------------------------- 3 files changed, 118 insertions(+), 624 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 37b10dd..7449401 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,6 +1,6 @@ extern crate cocoa; -use cocoa::base::{NSUInteger, nil, ObjCSelector}; +use cocoa::base::{NSUInteger, selector, nil}; use cocoa::appkit::{NSApp, NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSApplication, NSApplicationActivationPolicyRegular, @@ -27,7 +27,7 @@ fn main() { let quit_title = quit_prefix.stringByAppendingString_( NSProcessInfo::processInfo(nil).processName() ); - let quit_action = "terminate:".as_selector(); + let quit_action = selector("terminate:"); let quit_key = NSString::alloc(nil).init_str("q\0"); let quit_item = NSMenuItem::alloc(nil).initWithTitle_action_keyEquivalent_( quit_title, diff --git a/src/appkit.rs b/src/appkit.rs index 062efdd..008de23 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -9,7 +9,8 @@ #![allow(non_upper_case_globals)] -use base::{ObjCMethodCall, id, SEL, NSInteger, NSUInteger}; +use base::{id, msg_send, class, selector}; +use base::{SEL, NSInteger, NSUInteger}; use libc; #[cfg(target_word_size = "32")] @@ -74,7 +75,7 @@ extern { } pub unsafe fn NSApp() -> id { - "NSApplication".send("sharedApplication", ()) + msg_send()(class("NSApplication"), selector("sharedApplication")) } #[repr(i64)] @@ -273,7 +274,7 @@ pub enum NSEventModifierFlags { pub trait NSAutoreleasePool { unsafe fn new(_: Self) -> id { - "NSAutoreleasePool".send("new", ()) + msg_send()(class("NSAutoreleasePool"), selector("new")) } unsafe fn autorelease(self) -> Self; @@ -281,13 +282,13 @@ pub trait NSAutoreleasePool { impl NSAutoreleasePool for id { unsafe fn autorelease(self) -> id { - self.send("autorelease", ()) + msg_send()(self, selector("autorelease")) } } pub trait NSProcessInfo { unsafe fn processInfo(_: Self) -> id { - "NSProcessInfo".send("processInfo", ()) + msg_send()(class("NSProcessInfo"), selector("processInfo")) } unsafe fn processName(self) -> id; @@ -295,13 +296,13 @@ pub trait NSProcessInfo { impl NSProcessInfo for id { unsafe fn processName(self) -> id { - self.send("processName", ()) + msg_send()(self, selector("processName")) } } pub trait NSApplication { unsafe fn sharedApplication(_: Self) -> id { - "NSApplication".send("sharedApplication", ()) + msg_send()(class("NSApplication"), selector("sharedApplication")) } unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> bool; @@ -319,23 +320,23 @@ pub trait NSApplication { impl NSApplication for id { unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> bool { - self.send_bool("setActivationPolicy:", policy as NSInteger) + msg_send()(self, selector("setActivationPolicy:"), policy as NSInteger) } unsafe fn setMainMenu_(self, menu: id) { - self.send_void("setMainMenu:", menu) + msg_send()(self, selector("setMainMenu:"), menu) } unsafe fn activateIgnoringOtherApps_(self, ignore: bool) { - self.send_void("activateIgnoringOtherApps:", ignore); + msg_send()(self, selector("activateIgnoringOtherApps:"), ignore as libc::c_int) } unsafe fn run(self) { - self.send_void("run", ()); + msg_send()(self, selector("run")) } unsafe fn finishLaunching(self) { - self.send_void("finishLaunching", ()) + msg_send()(self, selector("finishLaunching")) } unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, @@ -343,18 +344,18 @@ impl NSApplication for id { expiration: id, in_mode: id, dequeue: bool) -> id { - self.send("nextEventMatchingMask:untilDate:inMode:dequeue:", - (mask, expiration, in_mode, dequeue)) + msg_send()(self, selector("nextEventMatchingMask:untilDate:inMode:dequeue:"), + mask, expiration, in_mode, dequeue as libc::c_int) } unsafe fn sendEvent_(self, an_event: id) { - self.send_void("sendEvent:", an_event) + msg_send()(self, selector("sendEvent:"), an_event) } } pub trait NSMenu { unsafe fn new(_: Self) -> id { - "NSMenu".send("new", ()) + msg_send()(class("NSMenu"), selector("new")) } unsafe fn addItem_(self, menu_item: id); @@ -362,17 +363,17 @@ pub trait NSMenu { impl NSMenu for id { unsafe fn addItem_(self, menu_item: id) { - self.send_void("addItem:", menu_item) + msg_send()(self, selector("addItem:"), menu_item) } } pub trait NSMenuItem { unsafe fn alloc(_: Self) -> id { - "NSMenuItem".send("alloc", ()) + msg_send()(class("NSMenuItem"), selector("alloc")) } unsafe fn new(_: Self) -> id { - "NSMenuItem".send("new", ()) + msg_send()(class("NSMenuItem"), selector("new")) } unsafe fn initWithTitle_action_keyEquivalent_(self, title: id, action: SEL, key: id) -> id; @@ -381,17 +382,17 @@ pub trait NSMenuItem { impl NSMenuItem for id { unsafe fn initWithTitle_action_keyEquivalent_(self, title: id, action: SEL, key: id) -> id { - self.send("initWithTitle:action:keyEquivalent:", (title, action, key)) + msg_send()(self, selector("initWithTitle:action:keyEquivalent:"), title, action, key) } unsafe fn setSubmenu_(self, submenu: id) { - self.send_void("setSubmenu:", submenu) + msg_send()(self, selector("setSubmenu:"), submenu) } } pub trait NSWindow { unsafe fn alloc(_: Self) -> id { - "NSWindow".send("alloc", ()) + msg_send()(class("NSWindow"), selector("alloc")) } unsafe fn initWithContentRect_styleMask_backing_defer_(self, @@ -496,266 +497,266 @@ impl NSWindow for id { style: NSUInteger, backing: NSBackingStoreType, defer: bool) -> id { - self.send("initWithContentRect:styleMask:backing:defer:", - (rect, style, backing as NSUInteger, defer)) + msg_send()(self, selector("initWithContentRect:styleMask:backing:defer:"), + rect, style, backing as NSUInteger, defer as libc::c_int) } // Sizing Windows unsafe fn frame(self) -> NSRect { - self.send_rect("frame", ()) + msg_send()(self, selector("frame")) } unsafe fn setFrameOrigin_(self, point: NSPoint) { - self.send_void("setFrameOrigin:", point); + msg_send()(self, selector("setFrameOrigin:"), point) } unsafe fn setFrameTopLeftPoint_(self, point: NSPoint) { - self.send_void("setFrameTopLeftPoint:", point); + msg_send()(self, selector("setFrameTopLeftPoint:"), point) } unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint { - self.send_point("cascadeTopLeftFromPoint:", topLeft) + msg_send()(self, selector("cascadeTopLeftFromPoint:"), topLeft) } unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: bool) { - self.send_void("setFrame:displayViews:", (windowFrame, display)); + msg_send()(self, selector("setFrame:displayViews:"), windowFrame, display as libc::c_int) } unsafe fn aspectRatio(self) -> NSSize { - self.send_size("aspectRatio", ()) + msg_send()(self, selector("aspectRatio")) } unsafe fn setAspectRatio_(self, aspectRatio: NSSize) { - self.send_void("setAspectRatio:", aspectRatio); + msg_send()(self, selector("setAspectRatio:"), aspectRatio) } unsafe fn minSize(self) -> NSSize { - self.send_size("minSize", ()) + msg_send()(self, selector("minSize")) } unsafe fn setMinSize_(self, minSize: NSSize) { - self.send_void("setMinSize:", minSize); + msg_send()(self, selector("setMinSize:"), minSize) } unsafe fn maxSize(self) -> NSSize { - self.send_size("maxSize", ()) + msg_send()(self, selector("maxSize")) } unsafe fn setMaxSize_(self, maxSize: NSSize) { - self.send_void("setMaxSize:", maxSize); + msg_send()(self, selector("setMaxSize:"), maxSize) } unsafe fn performZoom_(self, sender: id) { - self.send_void("performZoom:", sender); + msg_send()(self, selector("performZoom:"), sender) } unsafe fn zoom_(self, sender: id) { - self.send_void("zoom:", sender); + msg_send()(self, selector("zoom:"), sender) } unsafe fn showsResizeIndicator(self) -> bool { - self.send_bool("showsResizeIndicator", ()) + msg_send()(self, selector("showsResizeIndicator")) } unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: bool) { - self.send_void("setShowsResizeIndicator:", showsResizeIndicator) + msg_send()(self, selector("setShowsResizeIndicator:"), showsResizeIndicator as libc::c_int) } unsafe fn resizeIncrements(self) -> NSSize { - self.send_size("resizeIncrements", ()) + msg_send()(self, selector("resizeIncrements")) } unsafe fn setResizeIncrements_(self, resizeIncrements: NSSize) { - self.send_void("setResizeIncrements:", resizeIncrements); + msg_send()(self, selector("setResizeIncrements:"), resizeIncrements) } unsafe fn preservesContentDuringLiveResize(self) -> bool { - self.send_bool("preservesContentDuringLiveResize", ()) + msg_send()(self, selector("preservesContentDuringLiveResize")) } unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: bool) { - self.send_void("setPreservesContentDuringLiveResize:", preservesContentDuringLiveResize) + msg_send()(self, selector("setPreservesContentDuringLiveResize:"), preservesContentDuringLiveResize as libc::c_int) } unsafe fn inLiveResize(self) -> bool { - self.send_bool("inLiveResize", ()) + msg_send()(self, selector("inLiveResize")) } // Managing Window Layers unsafe fn orderOut_(self, sender: id) { - self.send_void("orderOut:", sender); + msg_send()(self, selector("orderOut:"), sender) } unsafe fn orderBack_(self, sender: id) { - self.send_void("orderBack:", sender); + msg_send()(self, selector("orderBack:"), sender) } unsafe fn orderFront_(self, sender: id) { - self.send_void("orderFront:", sender); + msg_send()(self, selector("orderFront:"), sender) } unsafe fn orderFrontRegardless(self) { - self.send_void("orderFrontRegardless", ()); + msg_send()(self, selector("orderFrontRegardless")) } unsafe fn orderFrontWindow_relativeTo_(self, ordering_mode: NSWindowOrderingMode, other_window_number: NSInteger) { - self.send_void("orderWindow:relativeTo:", (ordering_mode, other_window_number)); + msg_send()(self, selector("orderWindow:relativeTo:"), ordering_mode, other_window_number) } unsafe fn level(self) -> NSInteger { - self.send_integer("level", ()) + msg_send()(self, selector("level")) } unsafe fn setLevel_(self, level: NSInteger) { - self.send_void("setLevel:", level); + msg_send()(self, selector("setLevel:"), level) } // Managing Key Status unsafe fn canBecomeKeyWindow(self) -> bool { - self.send_bool("canBecomeKeyWindow", ()) + msg_send()(self, selector("canBecomeKeyWindow")) } unsafe fn makeKeyWindow(self) { - self.send_void("makeKeyWindow", ()); + msg_send()(self, selector("makeKeyWindow")) } unsafe fn makeKeyAndOrderFront_(self, sender: id) { - self.send_void("makeKeyAndOrderFront:", sender); + msg_send()(self, selector("makeKeyAndOrderFront:"), sender) } // Managing Main Status unsafe fn canBecomeMainWindow(self) -> bool { - self.send_bool("canBecomeMainWindow", ()) + msg_send()(self, selector("canBecomeMainWindow")) } unsafe fn makeMainWindow(self) { - self.send_void("makeMainWindow", ()); + msg_send()(self, selector("makeMainWindow")) } // Converting Coordinates unsafe fn backingScaleFactor(self) -> CGFloat { - self.send_float("backingScaleFactor", ()) + msg_send()(self, selector("backingScaleFactor")) } unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect { - self.send_rect("backingAlignedRect:options:", (rect, options)) + msg_send()(self, selector("backingAlignedRect:options:"), rect, options) } unsafe fn convertRectFromBacking_(self, rect: NSRect) -> NSRect { - self.send_rect("convertRectFromBacking:", rect) + msg_send()(self, selector("convertRectFromBacking:"), rect) } unsafe fn convertRectToBacking_(self, rect: NSRect) -> NSRect { - self.send_rect("convertRectToBacking:", rect) + msg_send()(self, selector("convertRectToBacking:"), rect) } unsafe fn convertRectToScreen_(self, rect: NSRect) -> NSRect { - self.send_rect("convertRectToScreen:", rect) + msg_send()(self, selector("convertRectToScreen:"), rect) } unsafe fn convertRectFromScreen_(self, rect: NSRect) -> NSRect { - self.send_rect("convertRectFromScreen:", rect) + msg_send()(self, selector("convertRectFromScreen:"), rect) } // Accessing Edited Status unsafe fn setDocumentEdited_(self, documentEdited: bool) { - self.send_void("setDocumentEdited:", documentEdited); + msg_send()(self, selector("setDocumentEdited:"), documentEdited as libc::c_int) } // Managing Titles unsafe fn title(self) -> id { - self.send("title", ()) + msg_send()(self, selector("title")) } unsafe fn setTitle_(self, title: id) { - self.send_void("setTitle:", title); + msg_send()(self, selector("setTitle:"), title) } unsafe fn setTitleWithRepresentedFilename_(self, filePath: id) { - self.send_void("setTitleWithRepresentedFilename:", filePath); + msg_send()(self, selector("setTitleWithRepresentedFilename:"), filePath) } unsafe fn representedFilename(self) -> id { - self.send("representedFilename", ()) + msg_send()(self, selector("representedFilename")) } unsafe fn setRepresentedFilename_(self, filePath: id) { - self.send_void("setRepresentedFilename:", filePath); + msg_send()(self, selector("setRepresentedFilename:"), filePath) } // Moving Windows unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: bool) { - self.send_void("setMovableByWindowBackground:", movableByWindowBackground); + msg_send()(self, selector("setMovableByWindowBackground:"), movableByWindowBackground as libc::c_int) } unsafe fn setMovable_(self, movable: bool) { - self.send_void("setMovable:", movable); + msg_send()(self, selector("setMovable:"), movable as libc::c_int) } unsafe fn center(self) { - self.send_void("center", ()); + msg_send()(self, selector("center")) } // Closing Windows unsafe fn performClose_(self, sender: id) { - self.send_void("performClose:", sender); + msg_send()(self, selector("performClose:"), sender) } unsafe fn close(self) { - self.send_void("close", ()); + msg_send()(self, selector("close")) } unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: bool) { - self.send_void("setReleasedWhenClosed:", releasedWhenClosed); + msg_send()(self, selector("setReleasedWhenClosed:"), releasedWhenClosed as libc::c_int) } // Minimizing Windows unsafe fn performMiniaturize_(self, sender: id) { - self.send_void("performMiniaturize:", sender); + msg_send()(self, selector("performMiniaturize:"), sender) } unsafe fn miniaturize_(self, sender: id) { - self.send_void("miniaturize:", sender); + msg_send()(self, selector("miniaturize:"), sender) } unsafe fn deminiaturize_(self, sender: id) { - self.send_void("deminiaturize:", sender); + msg_send()(self, selector("deminiaturize:"), sender) } unsafe fn miniwindowTitle(self) -> id { - self.send("miniwindowTitle", ()) + msg_send()(self, selector("miniwindowTitle")) } unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id) { - self.send_void("setMiniwindowTitle:", miniwindowTitle); + msg_send()(self, selector("setMiniwindowTitle:"), miniwindowTitle) } unsafe fn setContentView_(self, view: id) { - self.send_void("setContentView:", view) + msg_send()(self, selector("setContentView:"), view) } unsafe fn setAcceptsMouseMovedEvents_(self, accept: bool) { - self.send_void("setAcceptsMouseMovedEvents:", accept); + msg_send()(self, selector("setAcceptsMouseMovedEvents:"), accept as libc::c_int) } unsafe fn isVisible(self) -> bool { - self.send_bool("isVisible", ()) + msg_send()(self, selector("isVisible")) } } pub trait NSString { unsafe fn alloc(_: Self) -> id { - "NSString".send("alloc", ()) + msg_send()(class("NSString"), selector("alloc")) } unsafe fn initWithUTF8String_(self, c_string: *const u8) -> id; @@ -766,11 +767,11 @@ pub trait NSString { impl NSString for id { unsafe fn initWithUTF8String_(self, c_string: *const u8) -> id { - self.send("initWithUTF8String:", c_string as id) + msg_send()(self, selector("initWithUTF8String:"), c_string as id) } unsafe fn stringByAppendingString_(self, other: id) -> id { - self.send("stringByAppendingString:", other) + msg_send()(self, selector("stringByAppendingString:"), other) } unsafe fn init_str(self, string: &str) -> id { @@ -778,13 +779,13 @@ impl NSString for id { } unsafe fn UTF8String(self) -> *const libc::c_char { - self.send_string("UTF8String", ()) + msg_send()(self, selector("UTF8String")) } } pub trait NSView { unsafe fn alloc(_: Self) -> id { - "NSView".send("alloc", ()) + msg_send()(class("NSView"), selector("alloc")) } unsafe fn init(self) -> id; @@ -796,29 +797,29 @@ pub trait NSView { impl NSView for id { unsafe fn init(self) -> id { - self.send("init", ()) + msg_send()(self, selector("init")) } unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { - self.send("initWithFrame:", frameRect) + msg_send()(self, selector("initWithFrame:"), frameRect) } unsafe fn display_(self) { - self.send_void("display", ()) + msg_send()(self, selector("display")) } unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: bool) { - self.send_void("setWantsBestResolutionOpenGLSurface:", flag) + msg_send()(self, selector("setWantsBestResolutionOpenGLSurface:"), flag as libc::c_int) } unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint { - self.send_point("convertPoint:fromView:", (point, view)) + msg_send()(self, selector("convertPoint:fromView:"), point, view) } } pub trait NSOpenGLView { unsafe fn alloc(_: Self) -> id { - "NSOpenGLView".send("alloc", ()) + msg_send()(class("NSOpenGLView"), selector("alloc")) } unsafe fn initWithFrame_pixelFormat_(self, frameRect: NSRect, format: id) -> id; @@ -827,17 +828,17 @@ pub trait NSOpenGLView { impl NSOpenGLView for id { unsafe fn initWithFrame_pixelFormat_(self, frameRect: NSRect, format: id) -> id { - self.send("initWithFrame:pixelFormat:", (frameRect, format)) + msg_send()(self, selector("initWithFrame:pixelFormat:"), frameRect, format) } unsafe fn display_(self) { - self.send_void("display", ()) + msg_send()(self, selector("display")) } } pub trait NSOpenGLPixelFormat { unsafe fn alloc(_: Self) -> id { - "NSOpenGLPixelFormat".send("alloc", ()) + msg_send()(class("NSOpenGLPixelFormat"), selector("alloc")) } unsafe fn initWithAttributes_(self, attributes: &[uint]) -> id; @@ -845,13 +846,13 @@ pub trait NSOpenGLPixelFormat { impl NSOpenGLPixelFormat for id { unsafe fn initWithAttributes_(self, attributes: &[uint]) -> id { - self.send("initWithAttributes:", attributes) + msg_send()(self, selector("initWithAttributes:"), attributes) } } pub trait NSOpenGLContext { unsafe fn alloc(_: Self) -> id { - "NSOpenGLContext".send("alloc", ()) + msg_send()(class("NSOpenGLContext"), selector("alloc")) } unsafe fn initWithFormat_shareContext_(self, format: id, shareContext: id) -> id; @@ -862,29 +863,29 @@ pub trait NSOpenGLContext { impl NSOpenGLContext for id { unsafe fn initWithFormat_shareContext_(self, format: id, shareContext: id) -> id { - self.send("initWithFormat:shareContext:", (format, shareContext)) + msg_send()(self, selector("initWithFormat:shareContext:"), format, shareContext) } unsafe fn setView_(self, view: id) { - self.send_void("setView:", view) + msg_send()(self, selector("setView:"), view) } unsafe fn makeCurrentContext(self) { - self.send_void("makeCurrentContext", ()) + msg_send()(self, selector("makeCurrentContext")) } unsafe fn flushBuffer(self) { - self.send_void("flushBuffer", ()) + msg_send()(self, selector("flushBuffer")) } } pub trait NSDate { unsafe fn distantPast(_: Self) -> id { - "NSDate".send("distantPast", ()) + msg_send()(class("NSDate"), selector("distantPast")) } unsafe fn distantFuture(_: Self) -> id { - "NSDate".send("distantFuture", ()) + msg_send()(class("NSDate"), selector("distantFuture")) } } @@ -903,26 +904,26 @@ pub trait NSEvent { impl NSEvent for id { unsafe fn get_type(self) -> NSEventType { - self.send_event("type", ()) + msg_send()(self, selector("type")) } unsafe fn locationInWindow(self) -> NSPoint { - self.send_point("locationInWindow", ()) + msg_send()(self, selector("locationInWindow")) } unsafe fn characters(self) -> id { - self.send("characters", ()) + msg_send()(self, selector("characters")) } unsafe fn charactersIgnoringModifiers(self) -> id { - self.send("charactersIgnoringModifiers", ()) + msg_send()(self, selector("charactersIgnoringModifiers")) } unsafe fn keycode(self) -> libc::c_ushort { - self.send_ushort("keyCode", ()) + msg_send()(self, selector("keyCode")) } unsafe fn modifierFlags(self) -> NSUInteger { - self.send_NSUInteger("modifierFlags", ()) + msg_send()(self, selector("modifierFlags")) } } diff --git a/src/base.rs b/src/base.rs index a069e1c..c7c0568 100644 --- a/src/base.rs +++ b/src/base.rs @@ -7,10 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use appkit::{CGFloat, NSPoint, NSRect, NSSize, NSEventType}; -use appkit::{NSWindowOrderingMode, NSAlignmentOptions}; - -use libc::{c_double, c_long, c_ulong, c_char}; +use libc::{c_long, c_ulong, c_char}; use libc; use std::mem; @@ -74,510 +71,6 @@ pub fn selector(name: &str) -> SEL { } } -/// A trait that allows syntax like: -/// -/// ~~~rust -/// # use cocoa::base::{ObjCMethodCall, id}; -/// # unsafe { -/// let string = "NSString".send("alloc", ()) -/// .send("initWithUTF8String:", "Hello world!".as_ptr() as id); -/// # } -/// ~~~ -pub trait ObjCMethodCall { - unsafe fn send(self, selector: S, args: A) -> id; - unsafe fn send_double(self, selector: S, args: A) - -> c_double; - unsafe fn send_long(self, selector: S, args: A) -> c_long; - unsafe fn send_void(self, selector: S, args: A); - unsafe fn send_bool(self, selector: S, args: A) -> bool; - unsafe fn send_float(self, selector: S, args: A) -> CGFloat; - unsafe fn send_integer(self, selector: S, args: A) -> NSInteger; - unsafe fn send_point(self, selector: S, args: A) -> NSPoint; - unsafe fn send_rect(self, selector: S, args: A) -> NSRect; - unsafe fn send_size(self, selector: S, args: A) -> NSSize; - unsafe fn send_event(self, selector: S, args: A) -> NSEventType; - unsafe fn send_string(self, selector: S, args: A) -> *const libc::c_char; - unsafe fn send_ushort(self, selector: S, args: A) -> libc::c_ushort; - unsafe fn send_NSUInteger(self, selector: S, args: A) -> NSUInteger; -} - -impl ObjCMethodCall for id { - #[inline] - unsafe fn send(self, selector: S, args: A) -> id { - args.send_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_double(self, selector: S, args: A) - -> c_double { - args.send_double_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_long(self, selector: S, args: A) - -> c_long { - args.send_long_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_void(self, selector: S, args: A) { - args.send_void_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_bool(self, selector: S, args: A) - -> bool { - args.send_bool_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_float(self, selector: S, args: A) - -> CGFloat { - args.send_float_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_integer(self, selector: S, args: A) - -> NSInteger { - args.send_integer_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_point(self, selector: S, args: A) - -> NSPoint { - args.send_point_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_rect(self, selector: S, args: A) - -> NSRect { - args.send_rect_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_size(self, selector: S, args: A) - -> NSSize { - args.send_size_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_event(self, selector: S, args: A) - -> NSEventType { - args.send_event_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_string(self, selector: S, args: A) - -> *const libc::c_char { - args.send_string_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_ushort(self, selector: S, args: A) - -> libc::c_ushort { - args.send_ushort_args(self, selector.as_selector()) - } - #[inline] - unsafe fn send_NSUInteger(self, selector: S, args: A) - -> NSUInteger { - args.send_NSUInteger_args(self, selector.as_selector()) - } -} - -/// A convenience implementation that allows methods on class names to be called directly, as in: -/// -/// ~~~rust -/// # use cocoa::base::ObjCMethodCall; -/// # unsafe { -/// "NSString".send("alloc", ()) -/// # }; -/// ~~~ -impl<'a> ObjCMethodCall for &'a str { - #[inline] - unsafe fn send(self, selector: S, args: A) -> id { - args.send_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_double(self, selector: S, args: A) - -> c_double { - args.send_double_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_long(self, selector: S, args: A) - -> c_long { - args.send_long_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_void(self, selector: S, args: A) { - args.send_void_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_bool(self, selector: S, args: A) - -> bool { - args.send_bool_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_float(self, selector: S, args: A) - -> CGFloat { - args.send_float_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_integer(self, selector: S, args: A) - -> NSInteger { - args.send_integer_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_point(self, selector: S, args: A) - -> NSPoint { - args.send_point_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_rect(self, selector: S, args: A) - -> NSRect { - args.send_rect_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_size(self, selector: S, args: A) - -> NSSize { - args.send_size_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_event(self, selector: S, args: A) - -> NSEventType { - args.send_event_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_string(self, selector: S, args: A) - -> *const libc::c_char { - args.send_string_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_ushort(self, selector: S, args: A) - -> libc::c_ushort { - args.send_ushort_args(class(self), selector.as_selector()) - } - #[inline] - unsafe fn send_NSUInteger(self, selector: S, args: A) - -> NSUInteger { - args.send_NSUInteger_args(class(self), selector.as_selector()) - } -} - -/// A trait that allows C strings to be used as selectors without having to convert them first. -pub trait ObjCSelector { - fn as_selector(self) -> SEL; -} - -impl<'a> ObjCSelector for &'a str { - #[inline] - fn as_selector(self) -> SEL { - // TODO(pcwalton): Cache somehow. - unsafe { - sel_registerName(self.to_c_str().as_ptr()) - } - } -} - -impl ObjCSelector for SEL { - #[inline] - fn as_selector(self) -> SEL { - self - } -} - -/// Traits that simulate variadic parameters for convenience when sending messages. -pub trait ObjCMethodArgs { - unsafe fn send_args(self, receiver: id, selector: SEL) -> id; -} -pub trait ObjCMethodDoubleArgs { - unsafe fn send_double_args(self, receiver: id, selector: SEL) -> c_double; -} -pub trait ObjCMethodLongArgs { - unsafe fn send_long_args(self, receiver: id, selector: SEL) -> c_long; -} -pub trait ObjCMethodVoidArgs { - unsafe fn send_void_args(self, receiver: id, selector: SEL); -} -pub trait ObjCMethodBoolArgs { - unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool; -} -pub trait ObjCMethodFloatArgs { - unsafe fn send_float_args(self, receiver: id, selector: SEL) -> CGFloat; -} -pub trait ObjCMethodIntegerArgs { - unsafe fn send_integer_args(self, receiver: id, selector: SEL) -> NSInteger; -} -pub trait ObjCMethodPointArgs { - unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint; -} -pub trait ObjCMethodRectArgs { - unsafe fn send_rect_args(self, receiver: id, selector: SEL) -> NSRect; -} -pub trait ObjCMethodSizeArgs { - unsafe fn send_size_args(self, receiver: id, selector: SEL) -> NSSize; -} -pub trait ObjCMethodEventArgs { - unsafe fn send_event_args(self, receiver: id, selector: SEL) -> NSEventType; -} - -pub trait ObjCMethodStringArgs { - unsafe fn send_string_args(self, receiver: id, selector: SEL) -> *const libc::c_char; -} - -pub trait ObjCMethodUShortArgs { - unsafe fn send_ushort_args(self, received: id, selector: SEL) -> libc::c_ushort; -} - -pub trait ObjCMethodNSUIntegerArgs { - unsafe fn send_NSUInteger_args(self, received: id, selector: SEL) -> NSUInteger; -} - -impl ObjCMethodArgs for () { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodArgs for id { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - msg_send()(receiver, selector, self) - } -} - -impl ObjCMethodArgs for NSRect { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - msg_send()(receiver, selector, &self) - } -} - -impl ObjCMethodArgs for (id, SEL, id) { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - let (first, second, third) = self; - msg_send()(receiver, selector, first, second, third) - } -} - -impl ObjCMethodArgs for (NSRect, c_ulong, c_ulong, bool) { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - let (first, second, third, fourth) = self; - msg_send()(receiver, selector, first, second, third, fourth as libc::c_int) - } -} - -impl ObjCMethodArgs for (id, id, id, id, id) { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - let (first, second, third, fourth, fifth) = self; - msg_send()(receiver, selector, first, second, third, fourth, fifth) - } -} - -impl ObjCMethodArgs for (NSRect, id) { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - let (first, second) = self; - msg_send()(receiver, selector, first, second) - } -} - -impl<'a> ObjCMethodArgs for &'a [uint] { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - msg_send()(receiver, selector, self) - } -} - -impl ObjCMethodArgs for (id, id) { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - let (first, second) = self; - msg_send()(receiver, selector, first, second) - } -} - -impl ObjCMethodArgs for (NSUInteger, id, id, bool) { - #[inline] - unsafe fn send_args(self, receiver: id, selector: SEL) -> id { - let (first, second, third, fourth) = self; - msg_send()(receiver, selector, first, second, third, fourth as libc::c_int) - } -} - -impl ObjCMethodDoubleArgs for () { - #[inline] - unsafe fn send_double_args(self, receiver: id, selector: SEL) -> f64 { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodLongArgs for () { - #[inline] - unsafe fn send_long_args(self, receiver: id, selector: SEL) -> c_long { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodVoidArgs for () { - #[inline] - unsafe fn send_void_args(self, receiver: id, selector: SEL) { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodVoidArgs for bool { - #[inline] - unsafe fn send_void_args(self, receiver: id, selector: SEL) { - msg_send()(receiver, selector, self as libc::c_int) - } -} - -impl ObjCMethodVoidArgs for id { - #[inline] - unsafe fn send_void_args(self, receiver: id, selector: SEL) { - msg_send()(receiver, selector, self) - } -} - -// Conflicts with id... should id be a newtype? - bjz -// impl ObjCMethodVoidArgs for NSInteger { -// #[inline] -// unsafe fn send_void_args(self, receiver: id, selector: SEL) { -// msg_send()(receiver, selector, self); -// } -// } - -impl ObjCMethodVoidArgs for NSPoint { - #[inline] - unsafe fn send_void_args(self, receiver: id, selector: SEL) { - msg_send()(receiver, selector, self) - } -} - -impl ObjCMethodVoidArgs for NSSize { - #[inline] - unsafe fn send_void_args(self, receiver: id, selector: SEL) { - msg_send()(receiver, selector, self) - } -} - -impl ObjCMethodVoidArgs for (NSRect, bool) { - #[inline] - unsafe fn send_void_args(self, receiver: id, selector: SEL) { - let (first, second) = self; - msg_send()(receiver, selector, first, second as libc::c_int) - } -} - -impl ObjCMethodVoidArgs for (NSWindowOrderingMode, NSInteger) { - #[inline] - unsafe fn send_void_args(self, receiver: id, selector: SEL) { - let (first, second) = self; - msg_send()(receiver, selector, first, second) - } -} - -impl ObjCMethodBoolArgs for () { - #[inline] - unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodBoolArgs for c_long { - #[inline] - unsafe fn send_bool_args(self, receiver: id, selector: SEL) -> bool { - msg_send()(receiver, selector, self) - } -} - -impl ObjCMethodFloatArgs for () { - #[inline] - unsafe fn send_float_args(self, receiver: id, selector: SEL) -> CGFloat { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodIntegerArgs for () { - #[inline] - unsafe fn send_integer_args(self, receiver: id, selector: SEL) -> NSInteger { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodPointArgs for NSPoint { - #[inline] - unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint { - msg_send()(receiver, selector, self) - } -} - -impl ObjCMethodRectArgs for () { - #[inline] - unsafe fn send_rect_args(self, receiver: id, selector: SEL) -> NSRect { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodRectArgs for (NSRect, NSAlignmentOptions) { - #[inline] - unsafe fn send_rect_args(self, receiver: id, selector: SEL) -> NSRect { - let (first, second) = self; - msg_send()(receiver, selector, first, second) - } -} - -impl ObjCMethodRectArgs for NSRect { - #[inline] - unsafe fn send_rect_args(self, receiver: id, selector: SEL) -> NSRect { - msg_send()(receiver, selector, self) - } -} - -impl ObjCMethodSizeArgs for () { - #[inline] - unsafe fn send_size_args(self, receiver: id, selector: SEL) -> NSSize { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodPointArgs for () { - #[inline] - unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodEventArgs for () { - #[inline] - unsafe fn send_event_args(self, receiver: id, selector: SEL) -> NSEventType { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodPointArgs for (NSPoint, id) { - #[inline] - unsafe fn send_point_args(self, receiver: id, selector: SEL) -> NSPoint { - let (first, second) = self; - msg_send()(receiver, selector, first, second) - } -} - -impl ObjCMethodStringArgs for () { - #[inline] - unsafe fn send_string_args(self, receiver: id, selector: SEL) -> *const libc::c_char { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodUShortArgs for () { - #[inline] - unsafe fn send_ushort_args(self, receiver: id, selector: SEL) -> libc::c_ushort { - msg_send()(receiver, selector) - } -} - -impl ObjCMethodNSUIntegerArgs for () { - #[inline] - unsafe fn send_NSUInteger_args(self, receiver: id, selector: SEL) -> NSUInteger { - msg_send()(receiver, selector) - } -} - -/// A trait that simulates variadic parameters for method calls. - #[cfg(test)] mod test { use libc; @@ -586,7 +79,7 @@ mod test { #[test] pub fn test_nsapp() { unsafe { - let _nsApp = "NSApplication".send("sharedApplication", ()); + let _nsApp: id = msg_send()(class("NSApplication"), selector("sharedApplication")); } } @@ -607,9 +100,9 @@ mod test { objc_registerClassPair(my_object); - let mut obj: id = my_object.send("alloc", ()); - obj = obj.send("init", ()); - obj.send_void("doSomething", ()); + let mut obj: id = msg_send()(my_object, selector("alloc")); + obj = msg_send()(obj, selector("init")); + let _: () = msg_send()(obj, selector("doSomething")); } } } From 5de9d1742d9d615ac7ff0d0f70822fce0fe72de7 Mon Sep 17 00:00:00 2001 From: David Partouche Date: Tue, 11 Nov 2014 17:24:12 +0100 Subject: [PATCH 097/249] Added NSScreen class --- src/appkit.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 008de23..860803d 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -927,3 +927,16 @@ impl NSEvent for id { msg_send()(self, selector("modifierFlags")) } } + +pub trait NSScreen { + unsafe fn mainScreen(_: Self) -> id { + "NSScreen".send("mainScreen", ()) + } + unsafe fn frame(self) -> NSRect; +} + +impl NSScreen for id { + unsafe fn frame(self) -> NSRect { + self.send_rect("frame", ()) + } +} From 54ea87fdc8a0cc9f2bebc3e99fdadffd213a77fb Mon Sep 17 00:00:00 2001 From: David Partouche Date: Tue, 11 Nov 2014 17:29:07 +0100 Subject: [PATCH 098/249] Added a window level static --- src/appkit.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 860803d..93e09f7 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -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")) From 0a951a6cdd5f1a175b929754c134f9443b105642 Mon Sep 17 00:00:00 2001 From: David Partouche Date: Tue, 11 Nov 2014 23:54:39 +0100 Subject: [PATCH 099/249] Forgot to switch to the new msg_send system --- src/appkit.rs | 6 +++--- src/base.rs | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 93e09f7..db144f7 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -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; @@ -932,13 +932,13 @@ impl NSEvent for id { pub trait NSScreen { unsafe fn mainScreen(_: Self) -> id { - "NSScreen".send("mainScreen", ()) + msg_send()(class("NSScreen"), selector("mainScreen")) } unsafe fn frame(self) -> NSRect; } impl NSScreen for id { unsafe fn frame(self) -> NSRect { - self.send_rect("frame", ()) + msg_send_stret()(self, selector("frame")) } } diff --git a/src/base.rs b/src/base.rs index c7c0568..18cb03f 100644 --- a/src/base.rs +++ b/src/base.rs @@ -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() -> extern fn(theReceiver: id, theSelector: SEL, ...) mem::transmute(objc_msgSend) } +pub unsafe fn msg_send_stret() -> 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 { From 75c3dd504990c90077d7f71e0e716f7bf0c806be Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Wed, 19 Nov 2014 15:40:03 +1000 Subject: [PATCH 100/249] Add accessors for bounds and frame to NSView. --- src/appkit.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/appkit.rs b/src/appkit.rs index db144f7..3cbf220 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -506,7 +506,7 @@ impl NSWindow for id { // Sizing Windows unsafe fn frame(self) -> NSRect { - msg_send()(self, selector("frame")) + msg_send_stret()(self, selector("frame")) } unsafe fn setFrameOrigin_(self, point: NSPoint) { @@ -792,6 +792,8 @@ pub trait NSView { unsafe fn init(self) -> id; unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; + unsafe fn bounds(self) -> NSRect; + unsafe fn frame(self) -> NSRect; unsafe fn display_(self); unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: bool); unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint; @@ -806,6 +808,14 @@ impl NSView for id { msg_send()(self, selector("initWithFrame:"), frameRect) } + unsafe fn bounds(self) -> NSRect { + msg_send_stret()(self, selector("bounds")) + } + + unsafe fn frame(self) -> NSRect { + msg_send_stret()(self, selector("frame")) + } + unsafe fn display_(self) { msg_send()(self, selector("display")) } From 7ebdf43e43b02e5ca06edb1b9b985479dc7564aa Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Thu, 20 Nov 2014 00:19:46 +1100 Subject: [PATCH 101/249] Update for enum namespacing --- src/appkit.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 3cbf220..585e285 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -13,6 +13,14 @@ use base::{id, msg_send, msg_send_stret, class, selector}; use base::{SEL, NSInteger, NSUInteger}; use libc; +pub use self::NSApplicationActivationPolicy::*; +pub use self::NSWindowMask::*; +pub use self::NSBackingStoreType::*; +pub use self::NSOpenGLPixelFormatAttribute::*; +pub use self::NSEventType::*; +pub use self::NSEventMask::*; +pub use self::NSEventModifierFlags::*; + #[cfg(target_word_size = "32")] pub type CGFloat = f32; #[cfg(target_word_size = "64")] From e29a43a6c5f4aa26f202aa5f84165d6d0d1d6e99 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 21 Nov 2014 00:03:50 -0800 Subject: [PATCH 102/249] appkit: Add some methods useful for waking up event loops from other threads --- src/appkit.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 3cbf220..3486bf5 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -280,12 +280,17 @@ pub trait NSAutoreleasePool { } unsafe fn autorelease(self) -> Self; + unsafe fn drain(self); } impl NSAutoreleasePool for id { unsafe fn autorelease(self) -> id { msg_send()(self, selector("autorelease")) } + + unsafe fn drain(self) { + msg_send()(self, selector("drain")) + } } pub trait NSProcessInfo { @@ -302,6 +307,8 @@ impl NSProcessInfo for id { } } +pub type NSTimeInterval = libc::c_double; + pub trait NSApplication { unsafe fn sharedApplication(_: Self) -> id { msg_send()(class("NSApplication"), selector("sharedApplication")) @@ -318,6 +325,7 @@ pub trait NSApplication { in_mode: id, dequeue: bool) -> id; unsafe fn sendEvent_(self, an_event: id); + unsafe fn postEvent_atStart_(self, anEvent: id, flag: bool); } impl NSApplication for id { @@ -353,6 +361,10 @@ impl NSApplication for id { unsafe fn sendEvent_(self, an_event: id) { msg_send()(self, selector("sendEvent:"), an_event) } + + unsafe fn postEvent_atStart_(self, anEvent: id, flag: bool) { + msg_send()(self, selector("postEvent:atStart:"), anEvent, flag as libc::c_int) + } } pub trait NSMenu { @@ -906,6 +918,19 @@ impl NSDate for id { } pub trait NSEvent { + unsafe fn + otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2( + _: Self, + ty: NSEventType, + location: NSPoint, + modifierFlags: NSUInteger, + timestamp: NSTimeInterval, + windowNumber: NSInteger, + context: *mut libc::c_void, + subtype: libc::c_short, + data1: NSInteger, + data2: NSInteger) + -> id; unsafe fn get_type(self) -> NSEventType; unsafe fn locationInWindow(self) -> NSPoint; unsafe fn characters(self) -> id; @@ -915,6 +940,33 @@ pub trait NSEvent { } impl NSEvent for id { + unsafe fn + otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2( + _: id, + ty: NSEventType, + location: NSPoint, + modifierFlags: NSUInteger, + timestamp: NSTimeInterval, + windowNumber: NSInteger, + context: *mut libc::c_void, + subtype: libc::c_short, + data1: NSInteger, + data2: NSInteger) + -> id { + msg_send()(class("NSEvent"), + selector("otherEventWithType:location:modifierFlags:timestamp:windowNumber:\ + context:subtype:data1:data2:"), + ty, + location, + modifierFlags, + timestamp, + windowNumber, + context, + subtype as libc::c_int, + data1, + data2) + } + unsafe fn get_type(self) -> NSEventType { msg_send()(self, selector("type")) } From 43783e50fcd9532e85b07e1d519b36d77e92a07c Mon Sep 17 00:00:00 2001 From: David Partouche Date: Wed, 26 Nov 2014 14:31:58 +0100 Subject: [PATCH 103/249] Added the option to set context parameter values to an NSOpenGLContext --- src/appkit.rs | 77 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 6920d1b..f37d095 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -26,6 +26,8 @@ pub type CGFloat = f32; #[cfg(target_word_size = "64")] pub type CGFloat = f64; +pub type GLint = libc::int32_t; + #[repr(C)] pub struct NSPoint { pub x: f64, @@ -201,6 +203,20 @@ pub enum NSOpenGLPixelFormatAttribute { NSOpenGLPFAVirtualScreenCount = 128, } +#[repr(u64)] +pub enum NSOpenGLContextParameter { + NSOpenGLCPSwapInterval = 222, + NSOpenGLCPSurfaceOrder = 235, + NSOpenGLCPSurfaceOpacity = 236, + NSOpenGLCPSurfaceBackingSize = 304, + NSOpenGLCPReclaimResources = 308, + NSOpenGLCPCurrentRendererID = 309, + NSOpenGLCPGPUVertexProcessing = 310, + NSOpenGLCPGPUFragmentProcessing = 311, + NSOpenGLCPHasDrawable = 314, + NSOpenGLCPMPSwapsInFlight = 315, +} + #[repr(u64)] pub enum NSEventType { NSLeftMouseDown = 1, @@ -236,34 +252,34 @@ pub enum NSEventType { #[repr(u64)] pub enum NSEventMask { - NSLeftMouseDownMask = 1 << NSLeftMouseDown as uint, - NSLeftMouseUpMask = 1 << NSLeftMouseUp as uint, - NSRightMouseDownMask = 1 << NSRightMouseDown as uint, - NSRightMouseUpMask = 1 << NSRightMouseUp as uint, - NSMouseMovedMask = 1 << NSMouseMoved as uint, - NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged as uint, - NSRightMouseDraggedMask = 1 << NSRightMouseDragged as uint, - NSMouseEnteredMask = 1 << NSMouseEntered as uint, - NSMouseExitedMask = 1 << NSMouseExited as uint, - NSKeyDownMask = 1 << NSKeyDown as uint, - NSKeyUpMask = 1 << NSKeyUp as uint, - NSFlagsChangedMask = 1 << NSFlagsChanged as uint, - NSAppKitDefinedMask = 1 << NSAppKitDefined as uint, - NSSystemDefinedMask = 1 << NSSystemDefined as uint, - NSAPplicationDefinedMask = 1 << NSApplicationDefined as uint, - NSPeriodicMask = 1 << NSPeriodic as uint, - NSCursorUpdateMask = 1 << NSCursorUpdate as uint, - NSScrollWheelMask = 1 << NSScrollWheel as uint, - NSTabletPointMask = 1 << NSTabletPoint as uint, - NSTabletProximityMask = 1 << NSTabletProximity as uint, - NSOtherMouseDownMask = 1 << NSOtherMouseDown as uint, - NSOtherMouseUpMask = 1 << NSOtherMouseUp as uint, - NSOtherMouseDraggedMask = 1 << NSOtherMouseDragged as uint, - NSEventMaskgesture = 1 << NSEventTypeGesture as uint, - NSEventMaskSwipe = 1 << NSEventTypeSwipe as uint, - NSEventMaskRotate = 1 << NSEventTypeRotate as uint, - NSEventMaskBeginGesture = 1 << NSEventTypeBeginGesture as uint, - NSEventMaskEndGesture = 1 << NSEventTypeEndGesture as uint, + NSLeftMouseDownMask = 1 << NSEventType::NSLeftMouseDown as uint, + NSLeftMouseUpMask = 1 << NSEventType::NSLeftMouseUp as uint, + NSRightMouseDownMask = 1 << NSEventType::NSRightMouseDown as uint, + NSRightMouseUpMask = 1 << NSEventType::NSRightMouseUp as uint, + NSMouseMovedMask = 1 << NSEventType::NSMouseMoved as uint, + NSLeftMouseDraggedMask = 1 << NSEventType::NSLeftMouseDragged as uint, + NSRightMouseDraggedMask = 1 << NSEventType::NSRightMouseDragged as uint, + NSMouseEnteredMask = 1 << NSEventType::NSMouseEntered as uint, + NSMouseExitedMask = 1 << NSEventType::NSMouseExited as uint, + NSKeyDownMask = 1 << NSEventType::NSKeyDown as uint, + NSKeyUpMask = 1 << NSEventType::NSKeyUp as uint, + NSFlagsChangedMask = 1 << NSEventType::NSFlagsChanged as uint, + NSAppKitDefinedMask = 1 << NSEventType::NSAppKitDefined as uint, + NSSystemDefinedMask = 1 << NSEventType::NSSystemDefined as uint, + NSAPplicationDefinedMask = 1 << NSEventType::NSApplicationDefined as uint, + NSPeriodicMask = 1 << NSEventType::NSPeriodic as uint, + NSCursorUpdateMask = 1 << NSEventType::NSCursorUpdate as uint, + NSScrollWheelMask = 1 << NSEventType::NSScrollWheel as uint, + NSTabletPointMask = 1 << NSEventType::NSTabletPoint as uint, + NSTabletProximityMask = 1 << NSEventType::NSTabletProximity as uint, + NSOtherMouseDownMask = 1 << NSEventType::NSOtherMouseDown as uint, + NSOtherMouseUpMask = 1 << NSEventType::NSOtherMouseUp as uint, + NSOtherMouseDraggedMask = 1 << NSEventType::NSOtherMouseDragged as uint, + NSEventMaskgesture = 1 << NSEventType::NSEventTypeGesture as uint, + NSEventMaskSwipe = 1 << NSEventType::NSEventTypeSwipe as uint, + NSEventMaskRotate = 1 << NSEventType::NSEventTypeRotate as uint, + NSEventMaskBeginGesture = 1 << NSEventType::NSEventTypeBeginGesture as uint, + NSEventMaskEndGesture = 1 << NSEventType::NSEventTypeEndGesture as uint, NSAnyEventMask = 0xffffffff, } @@ -891,6 +907,7 @@ pub trait NSOpenGLContext { unsafe fn setView_(self, view: id); unsafe fn makeCurrentContext(self); unsafe fn flushBuffer(self); + unsafe fn setValues_forParameter_(self, vals: *const GLint, param: NSOpenGLContextParameter); } impl NSOpenGLContext for id { @@ -909,6 +926,10 @@ impl NSOpenGLContext for id { unsafe fn flushBuffer(self) { msg_send()(self, selector("flushBuffer")) } + + unsafe fn setValues_forParameter_(self, vals: *const GLint, param: NSOpenGLContextParameter) { + msg_send()(self, selector("setValues:forParameter:"), vals, param) + } } pub trait NSDate { From b43d03fb9af0bd2762682d6a4ffdbe05b73fecf5 Mon Sep 17 00:00:00 2001 From: David Partouche Date: Wed, 26 Nov 2014 14:50:52 +0100 Subject: [PATCH 104/249] Fixed merge issue --- src/appkit.rs | 56 +++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index f37d095..c955857 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -252,34 +252,34 @@ pub enum NSEventType { #[repr(u64)] pub enum NSEventMask { - NSLeftMouseDownMask = 1 << NSEventType::NSLeftMouseDown as uint, - NSLeftMouseUpMask = 1 << NSEventType::NSLeftMouseUp as uint, - NSRightMouseDownMask = 1 << NSEventType::NSRightMouseDown as uint, - NSRightMouseUpMask = 1 << NSEventType::NSRightMouseUp as uint, - NSMouseMovedMask = 1 << NSEventType::NSMouseMoved as uint, - NSLeftMouseDraggedMask = 1 << NSEventType::NSLeftMouseDragged as uint, - NSRightMouseDraggedMask = 1 << NSEventType::NSRightMouseDragged as uint, - NSMouseEnteredMask = 1 << NSEventType::NSMouseEntered as uint, - NSMouseExitedMask = 1 << NSEventType::NSMouseExited as uint, - NSKeyDownMask = 1 << NSEventType::NSKeyDown as uint, - NSKeyUpMask = 1 << NSEventType::NSKeyUp as uint, - NSFlagsChangedMask = 1 << NSEventType::NSFlagsChanged as uint, - NSAppKitDefinedMask = 1 << NSEventType::NSAppKitDefined as uint, - NSSystemDefinedMask = 1 << NSEventType::NSSystemDefined as uint, - NSAPplicationDefinedMask = 1 << NSEventType::NSApplicationDefined as uint, - NSPeriodicMask = 1 << NSEventType::NSPeriodic as uint, - NSCursorUpdateMask = 1 << NSEventType::NSCursorUpdate as uint, - NSScrollWheelMask = 1 << NSEventType::NSScrollWheel as uint, - NSTabletPointMask = 1 << NSEventType::NSTabletPoint as uint, - NSTabletProximityMask = 1 << NSEventType::NSTabletProximity as uint, - NSOtherMouseDownMask = 1 << NSEventType::NSOtherMouseDown as uint, - NSOtherMouseUpMask = 1 << NSEventType::NSOtherMouseUp as uint, - NSOtherMouseDraggedMask = 1 << NSEventType::NSOtherMouseDragged as uint, - NSEventMaskgesture = 1 << NSEventType::NSEventTypeGesture as uint, - NSEventMaskSwipe = 1 << NSEventType::NSEventTypeSwipe as uint, - NSEventMaskRotate = 1 << NSEventType::NSEventTypeRotate as uint, - NSEventMaskBeginGesture = 1 << NSEventType::NSEventTypeBeginGesture as uint, - NSEventMaskEndGesture = 1 << NSEventType::NSEventTypeEndGesture as uint, + NSLeftMouseDownMask = 1 << NSLeftMouseDown as uint, + NSLeftMouseUpMask = 1 << NSLeftMouseUp as uint, + NSRightMouseDownMask = 1 << NSRightMouseDown as uint, + NSRightMouseUpMask = 1 << NSRightMouseUp as uint, + NSMouseMovedMask = 1 << NSMouseMoved as uint, + NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged as uint, + NSRightMouseDraggedMask = 1 << NSRightMouseDragged as uint, + NSMouseEnteredMask = 1 << NSMouseEntered as uint, + NSMouseExitedMask = 1 << NSMouseExited as uint, + NSKeyDownMask = 1 << NSKeyDown as uint, + NSKeyUpMask = 1 << NSKeyUp as uint, + NSFlagsChangedMask = 1 << NSFlagsChanged as uint, + NSAppKitDefinedMask = 1 << NSAppKitDefined as uint, + NSSystemDefinedMask = 1 << NSSystemDefined as uint, + NSAPplicationDefinedMask = 1 << NSApplicationDefined as uint, + NSPeriodicMask = 1 << NSPeriodic as uint, + NSCursorUpdateMask = 1 << NSCursorUpdate as uint, + NSScrollWheelMask = 1 << NSScrollWheel as uint, + NSTabletPointMask = 1 << NSTabletPoint as uint, + NSTabletProximityMask = 1 << NSTabletProximity as uint, + NSOtherMouseDownMask = 1 << NSOtherMouseDown as uint, + NSOtherMouseUpMask = 1 << NSOtherMouseUp as uint, + NSOtherMouseDraggedMask = 1 << NSOtherMouseDragged as uint, + NSEventMaskgesture = 1 << NSEventTypeGesture as uint, + NSEventMaskSwipe = 1 << NSEventTypeSwipe as uint, + NSEventMaskRotate = 1 << NSEventTypeRotate as uint, + NSEventMaskBeginGesture = 1 << NSEventTypeBeginGesture as uint, + NSEventMaskEndGesture = 1 << NSEventTypeEndGesture as uint, NSAnyEventMask = 0xffffffff, } From d55dd11e778c94180adb25170866c16f6fe0a920 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Thu, 18 Dec 2014 14:54:47 +1000 Subject: [PATCH 105/249] Add method to get scroll delta from NSEvent. --- src/appkit.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index c955857..2ab9db5 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -966,6 +966,7 @@ pub trait NSEvent { unsafe fn charactersIgnoringModifiers(self) -> id; unsafe fn keycode(self) -> libc::c_ushort; unsafe fn modifierFlags(self) -> NSUInteger; + unsafe fn scrollingDeltaY(self) -> CGFloat; } impl NSEvent for id { @@ -1019,6 +1020,10 @@ impl NSEvent for id { unsafe fn modifierFlags(self) -> NSUInteger { msg_send()(self, selector("modifierFlags")) } + + unsafe fn scrollingDeltaY(self) -> CGFloat { + msg_send()(self, selector("scrollingDeltaY")) + } } pub trait NSScreen { From 5303c54297ff93ef2c989d431108012747794924 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Tue, 23 Dec 2014 14:02:22 +1000 Subject: [PATCH 106/249] Use correct msg send function to fix segfault. --- src/appkit.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 2ab9db5..4f637dd 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -682,23 +682,23 @@ impl NSWindow for id { } unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect { - msg_send()(self, selector("backingAlignedRect:options:"), rect, options) + msg_send_stret()(self, selector("backingAlignedRect:options:"), rect, options) } unsafe fn convertRectFromBacking_(self, rect: NSRect) -> NSRect { - msg_send()(self, selector("convertRectFromBacking:"), rect) + msg_send_stret()(self, selector("convertRectFromBacking:"), rect) } unsafe fn convertRectToBacking_(self, rect: NSRect) -> NSRect { - msg_send()(self, selector("convertRectToBacking:"), rect) + msg_send_stret()(self, selector("convertRectToBacking:"), rect) } unsafe fn convertRectToScreen_(self, rect: NSRect) -> NSRect { - msg_send()(self, selector("convertRectToScreen:"), rect) + msg_send_stret()(self, selector("convertRectToScreen:"), rect) } unsafe fn convertRectFromScreen_(self, rect: NSRect) -> NSRect { - msg_send()(self, selector("convertRectFromScreen:"), rect) + msg_send_stret()(self, selector("convertRectFromScreen:"), rect) } // Accessing Edited Status From fc1f0360f9ef383f2aa7f7fae84fefdb65156561 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Wed, 24 Dec 2014 05:27:41 +1000 Subject: [PATCH 107/249] Fix more obj-c method calls. --- src/appkit.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 4f637dd..68c9afe 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -554,7 +554,7 @@ impl NSWindow for id { } unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint { - msg_send()(self, selector("cascadeTopLeftFromPoint:"), topLeft) + msg_send_stret()(self, selector("cascadeTopLeftFromPoint:"), topLeft) } unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: bool) { @@ -562,7 +562,7 @@ impl NSWindow for id { } unsafe fn aspectRatio(self) -> NSSize { - msg_send()(self, selector("aspectRatio")) + msg_send_stret()(self, selector("aspectRatio")) } unsafe fn setAspectRatio_(self, aspectRatio: NSSize) { @@ -570,7 +570,7 @@ impl NSWindow for id { } unsafe fn minSize(self) -> NSSize { - msg_send()(self, selector("minSize")) + msg_send_stret()(self, selector("minSize")) } unsafe fn setMinSize_(self, minSize: NSSize) { @@ -578,7 +578,7 @@ impl NSWindow for id { } unsafe fn maxSize(self) -> NSSize { - msg_send()(self, selector("maxSize")) + msg_send_stret()(self, selector("maxSize")) } unsafe fn setMaxSize_(self, maxSize: NSSize) { @@ -602,7 +602,7 @@ impl NSWindow for id { } unsafe fn resizeIncrements(self) -> NSSize { - msg_send()(self, selector("resizeIncrements")) + msg_send_stret()(self, selector("resizeIncrements")) } unsafe fn setResizeIncrements_(self, resizeIncrements: NSSize) { @@ -861,7 +861,7 @@ impl NSView for id { } unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint { - msg_send()(self, selector("convertPoint:fromView:"), point, view) + msg_send_stret()(self, selector("convertPoint:fromView:"), point, view) } } @@ -1002,7 +1002,7 @@ impl NSEvent for id { } unsafe fn locationInWindow(self) -> NSPoint { - msg_send()(self, selector("locationInWindow")) + msg_send_stret()(self, selector("locationInWindow")) } unsafe fn characters(self) -> id { From 45cef1badf65a4cd993d61969b7a1385d4bbead3 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Wed, 24 Dec 2014 07:51:57 +1000 Subject: [PATCH 108/249] Revert "Fix more obj-c method calls." This reverts commit fc1f0360f9ef383f2aa7f7fae84fefdb65156561. --- src/appkit.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 68c9afe..4f637dd 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -554,7 +554,7 @@ impl NSWindow for id { } unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint { - msg_send_stret()(self, selector("cascadeTopLeftFromPoint:"), topLeft) + msg_send()(self, selector("cascadeTopLeftFromPoint:"), topLeft) } unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: bool) { @@ -562,7 +562,7 @@ impl NSWindow for id { } unsafe fn aspectRatio(self) -> NSSize { - msg_send_stret()(self, selector("aspectRatio")) + msg_send()(self, selector("aspectRatio")) } unsafe fn setAspectRatio_(self, aspectRatio: NSSize) { @@ -570,7 +570,7 @@ impl NSWindow for id { } unsafe fn minSize(self) -> NSSize { - msg_send_stret()(self, selector("minSize")) + msg_send()(self, selector("minSize")) } unsafe fn setMinSize_(self, minSize: NSSize) { @@ -578,7 +578,7 @@ impl NSWindow for id { } unsafe fn maxSize(self) -> NSSize { - msg_send_stret()(self, selector("maxSize")) + msg_send()(self, selector("maxSize")) } unsafe fn setMaxSize_(self, maxSize: NSSize) { @@ -602,7 +602,7 @@ impl NSWindow for id { } unsafe fn resizeIncrements(self) -> NSSize { - msg_send_stret()(self, selector("resizeIncrements")) + msg_send()(self, selector("resizeIncrements")) } unsafe fn setResizeIncrements_(self, resizeIncrements: NSSize) { @@ -861,7 +861,7 @@ impl NSView for id { } unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint { - msg_send_stret()(self, selector("convertPoint:fromView:"), point, view) + msg_send()(self, selector("convertPoint:fromView:"), point, view) } } @@ -1002,7 +1002,7 @@ impl NSEvent for id { } unsafe fn locationInWindow(self) -> NSPoint { - msg_send_stret()(self, selector("locationInWindow")) + msg_send()(self, selector("locationInWindow")) } unsafe fn characters(self) -> id { From f04542effc208a9c49c929bb2af5c27ee4eea91d Mon Sep 17 00:00:00 2001 From: Patrick Horlebein Date: Mon, 29 Dec 2014 12:36:46 +0100 Subject: [PATCH 109/249] Added NSOpenGLPFAOpenGLProfile values --- src/appkit.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 4f637dd..b390a67 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -17,6 +17,7 @@ pub use self::NSApplicationActivationPolicy::*; pub use self::NSWindowMask::*; pub use self::NSBackingStoreType::*; pub use self::NSOpenGLPixelFormatAttribute::*; +pub use self::NSOpenGLPFAOpenGLProfiles::*; pub use self::NSEventType::*; pub use self::NSEventMask::*; pub use self::NSEventModifierFlags::*; @@ -203,6 +204,14 @@ pub enum NSOpenGLPixelFormatAttribute { NSOpenGLPFAVirtualScreenCount = 128, } +#[repr(u64)] +#[allow(non_camel_case_types)] +pub enum NSOpenGLPFAOpenGLProfiles { + NSOpenGLProfileVersionLegacy = 0x1000, + NSOpenGLProfileVersion3_2Core = 0x3200, + NSOpenGLProfileVersion4_1Core = 0x4100, +} + #[repr(u64)] pub enum NSOpenGLContextParameter { NSOpenGLCPSwapInterval = 222, From 9f9705df628259f5ec7f167d95dcc621f61231ed Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 4 Jan 2015 17:44:19 +0200 Subject: [PATCH 110/249] Fix build failure with latest Rust nightly --- src/base.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/base.rs b/src/base.rs index 18cb03f..cfef973 100644 --- a/src/base.rs +++ b/src/base.rs @@ -10,6 +10,7 @@ use libc::{c_long, c_ulong, c_char}; use libc; +use std::c_str::ToCStr; use std::mem; pub type Class = libc::intptr_t; @@ -79,6 +80,7 @@ pub fn selector(name: &str) -> SEL { #[cfg(test)] mod test { use libc; + use std::c_str::ToCStr; use super::*; #[test] From 4996cf5ab21a972758bf818d84d61d4c2c6591cf Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 4 Jan 2015 17:59:59 +0200 Subject: [PATCH 111/249] Fix dangling pointer with `to_c_str().as_mut_ptr()` --- src/base.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/base.rs b/src/base.rs index 18cb03f..3b9f82c 100644 --- a/src/base.rs +++ b/src/base.rs @@ -63,16 +63,18 @@ pub unsafe fn msg_send_stret() -> extern fn(theReceiver: id, theSelector: SEL /// A convenience method to convert the name of a class to the class object itself. #[inline] pub fn class(name: &str) -> id { + let name_c_str = name.to_c_str(); unsafe { - objc_getClass(name.to_c_str().as_ptr()) + objc_getClass(name_c_str.as_ptr()) } } /// 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 = name.to_c_str(); unsafe { - sel_registerName(name.to_c_str().as_ptr()) + sel_registerName(name_c_str.as_ptr()) } } @@ -96,12 +98,16 @@ mod test { } let ns_object = class("NSObject"); + let name_c_str = "MyObject".to_c_str(); let my_object = unsafe { - objc_allocateClassPair(ns_object, "MyObject".to_c_str().as_ptr(), 0 as libc::size_t) + objc_allocateClassPair(ns_object, name_c_str.as_ptr(), 0 as libc::size_t) }; + + let doSomething = selector("doSomething"); + let types_c_str = "@@:".to_c_str(); unsafe { - let doSomething = selector("doSomething"); - let _ = class_addMethod(my_object, doSomething, MyObject_doSomething, "@@:".to_c_str().as_ptr()); + let _ = class_addMethod(my_object, doSomething, MyObject_doSomething, + types_c_str.as_ptr()); objc_registerClassPair(my_object); From 604141a324b26410456783bda47664e8c422e499 Mon Sep 17 00:00:00 2001 From: Sam Ward Date: Fri, 9 Jan 2015 21:55:07 -0800 Subject: [PATCH 112/249] Update for 1.0.0-alpha compatibility --- src/appkit.rs | 60 +++++++++++++++++++++++++-------------------------- src/base.rs | 14 ++++++------ src/lib.rs | 3 --- 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index b390a67..4f1b326 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -261,34 +261,34 @@ pub enum NSEventType { #[repr(u64)] pub enum NSEventMask { - NSLeftMouseDownMask = 1 << NSLeftMouseDown as uint, - NSLeftMouseUpMask = 1 << NSLeftMouseUp as uint, - NSRightMouseDownMask = 1 << NSRightMouseDown as uint, - NSRightMouseUpMask = 1 << NSRightMouseUp as uint, - NSMouseMovedMask = 1 << NSMouseMoved as uint, - NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged as uint, - NSRightMouseDraggedMask = 1 << NSRightMouseDragged as uint, - NSMouseEnteredMask = 1 << NSMouseEntered as uint, - NSMouseExitedMask = 1 << NSMouseExited as uint, - NSKeyDownMask = 1 << NSKeyDown as uint, - NSKeyUpMask = 1 << NSKeyUp as uint, - NSFlagsChangedMask = 1 << NSFlagsChanged as uint, - NSAppKitDefinedMask = 1 << NSAppKitDefined as uint, - NSSystemDefinedMask = 1 << NSSystemDefined as uint, - NSAPplicationDefinedMask = 1 << NSApplicationDefined as uint, - NSPeriodicMask = 1 << NSPeriodic as uint, - NSCursorUpdateMask = 1 << NSCursorUpdate as uint, - NSScrollWheelMask = 1 << NSScrollWheel as uint, - NSTabletPointMask = 1 << NSTabletPoint as uint, - NSTabletProximityMask = 1 << NSTabletProximity as uint, - NSOtherMouseDownMask = 1 << NSOtherMouseDown as uint, - NSOtherMouseUpMask = 1 << NSOtherMouseUp as uint, - NSOtherMouseDraggedMask = 1 << NSOtherMouseDragged as uint, - NSEventMaskgesture = 1 << NSEventTypeGesture as uint, - NSEventMaskSwipe = 1 << NSEventTypeSwipe as uint, - NSEventMaskRotate = 1 << NSEventTypeRotate as uint, - NSEventMaskBeginGesture = 1 << NSEventTypeBeginGesture as uint, - NSEventMaskEndGesture = 1 << NSEventTypeEndGesture as uint, + NSLeftMouseDownMask = 1 << NSLeftMouseDown as u32, + NSLeftMouseUpMask = 1 << NSLeftMouseUp as u32, + NSRightMouseDownMask = 1 << NSRightMouseDown as u32, + NSRightMouseUpMask = 1 << NSRightMouseUp as u32, + NSMouseMovedMask = 1 << NSMouseMoved as u32, + NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged as u32, + NSRightMouseDraggedMask = 1 << NSRightMouseDragged as u32, + NSMouseEnteredMask = 1 << NSMouseEntered as u32, + NSMouseExitedMask = 1 << NSMouseExited as u32, + NSKeyDownMask = 1 << NSKeyDown as u32, + NSKeyUpMask = 1 << NSKeyUp as u32, + NSFlagsChangedMask = 1 << NSFlagsChanged as u32, + NSAppKitDefinedMask = 1 << NSAppKitDefined as u32, + NSSystemDefinedMask = 1 << NSSystemDefined as u32, + NSAPplicationDefinedMask = 1 << NSApplicationDefined as u32, + NSPeriodicMask = 1 << NSPeriodic as u32, + NSCursorUpdateMask = 1 << NSCursorUpdate as u32, + NSScrollWheelMask = 1 << NSScrollWheel as u32, + NSTabletPointMask = 1 << NSTabletPoint as u32, + NSTabletProximityMask = 1 << NSTabletProximity as u32, + NSOtherMouseDownMask = 1 << NSOtherMouseDown as u32, + NSOtherMouseUpMask = 1 << NSOtherMouseUp as u32, + NSOtherMouseDraggedMask = 1 << NSOtherMouseDragged as u32, + NSEventMaskgesture = 1 << NSEventTypeGesture as u32, + NSEventMaskSwipe = 1 << NSEventTypeSwipe as u32, + NSEventMaskRotate = 1 << NSEventTypeRotate as u32, + NSEventMaskBeginGesture = 1 << NSEventTypeBeginGesture as u32, + NSEventMaskEndGesture = 1 << NSEventTypeEndGesture as u32, NSAnyEventMask = 0xffffffff, } @@ -898,11 +898,11 @@ pub trait NSOpenGLPixelFormat { msg_send()(class("NSOpenGLPixelFormat"), selector("alloc")) } - unsafe fn initWithAttributes_(self, attributes: &[uint]) -> id; + unsafe fn initWithAttributes_(self, attributes: &[u32]) -> id; } impl NSOpenGLPixelFormat for id { - unsafe fn initWithAttributes_(self, attributes: &[uint]) -> id { + unsafe fn initWithAttributes_(self, attributes: &[u32]) -> id { msg_send()(self, selector("initWithAttributes:"), attributes) } } diff --git a/src/base.rs b/src/base.rs index 530dbb3..58d53c1 100644 --- a/src/base.rs +++ b/src/base.rs @@ -7,10 +7,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use libc::{c_long, c_ulong, c_char}; +use libc::c_char; use libc; -use std::c_str::ToCStr; +use std::ffi::CString; use std::mem; pub type Class = libc::intptr_t; @@ -64,7 +64,7 @@ pub unsafe fn msg_send_stret() -> extern fn(theReceiver: id, theSelector: SEL /// A convenience method to convert the name of a class to the class object itself. #[inline] pub fn class(name: &str) -> id { - let name_c_str = name.to_c_str(); + let name_c_str = CString::from_slice(name.as_bytes()); unsafe { objc_getClass(name_c_str.as_ptr()) } @@ -73,7 +73,7 @@ pub fn class(name: &str) -> id { /// 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 = name.to_c_str(); + let name_c_str = CString::from_slice(name.as_bytes()); unsafe { sel_registerName(name_c_str.as_ptr()) } @@ -82,7 +82,7 @@ pub fn selector(name: &str) -> SEL { #[cfg(test)] mod test { use libc; - use std::c_str::ToCStr; + use std::ffi::CString; use super::*; #[test] @@ -100,13 +100,13 @@ mod test { } let ns_object = class("NSObject"); - let name_c_str = "MyObject".to_c_str(); + let name_c_str = 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 = "@@:".to_c_str(); + let types_c_str = CString::from_slice("@@:".as_bytes()); unsafe { let _ = class_addMethod(my_object, doSomething, MyObject_doSomething, types_c_str.as_ptr()); diff --git a/src/lib.rs b/src/lib.rs index d6e3ab5..ff84c99 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,8 +13,6 @@ #![comment = "The Servo Parallel Browser Project"] #![license = "MIT"] -#![feature(globs)] - #![allow(non_snake_case)] extern crate libc; @@ -23,4 +21,3 @@ extern crate libc; pub mod appkit; #[cfg(target_os="macos")] pub mod base; - From 816fa02a28fb566a2061e5d9b392a8eeab737e5a Mon Sep 17 00:00:00 2001 From: Sam Ward Date: Sat, 10 Jan 2015 12:00:31 -0800 Subject: [PATCH 113/249] Change NSEventMask enum to 32 bit representation --- src/appkit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appkit.rs b/src/appkit.rs index 4f1b326..50f61a4 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -259,7 +259,7 @@ pub enum NSEventType { NSEventTypeEndGesture = 20, } -#[repr(u64)] +#[repr(u32)] pub enum NSEventMask { NSLeftMouseDownMask = 1 << NSLeftMouseDown as u32, NSLeftMouseUpMask = 1 << NSLeftMouseUp as u32, From d44a1b8520ddc12e825e028866fa252d6f7aa637 Mon Sep 17 00:00:00 2001 From: Sam Ward Date: Sun, 11 Jan 2015 16:19:57 -0800 Subject: [PATCH 114/249] Replace target_word_size with target_pointer_width --- src/appkit.rs | 4 ++-- src/base.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 50f61a4..327714b 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -22,9 +22,9 @@ pub use self::NSEventType::*; pub use self::NSEventMask::*; pub use self::NSEventModifierFlags::*; -#[cfg(target_word_size = "32")] +#[cfg(target_pointer_width = "32")] pub type CGFloat = f32; -#[cfg(target_word_size = "64")] +#[cfg(target_pointer_width = "64")] pub type CGFloat = f64; pub type GLint = libc::int32_t; diff --git a/src/base.rs b/src/base.rs index 58d53c1..1e9a306 100644 --- a/src/base.rs +++ b/src/base.rs @@ -20,14 +20,14 @@ pub type SEL = libc::intptr_t; #[allow(non_camel_case_types)] pub type id = libc::intptr_t; -#[cfg(target_word_size = "32")] +#[cfg(target_pointer_width = "32")] pub type NSInteger = libc::c_int; -#[cfg(target_word_size = "32")] +#[cfg(target_pointer_width = "32")] pub type NSUInteger = libc::c_uint; -#[cfg(target_word_size = "64")] +#[cfg(target_pointer_width = "64")] pub type NSInteger = libc::c_long; -#[cfg(target_word_size = "64")] +#[cfg(target_pointer_width = "64")] pub type NSUInteger = libc::c_ulong; #[allow(non_upper_case_globals)] From 84a405ba9ff2a79d507dc6ee1ea3cf9bf48706d1 Mon Sep 17 00:00:00 2001 From: Ivan Ukhov Date: Tue, 20 Jan 2015 15:50:35 +0100 Subject: [PATCH 115/249] Update to Rust 1.0 Alpha --- Cargo.toml | 3 +-- src/lib.rs | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5036575..ae2a1bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,9 @@ [package] - name = "cocoa" version = "0.1.1" authors = ["The Servo Project Developers"] +license = "MIT" [lib] - name = "cocoa" crate-type = ["rlib"] diff --git a/src/lib.rs b/src/lib.rs index ff84c99..746ad48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,10 +10,7 @@ #![crate_name = "cocoa"] #![crate_type = "rlib"] -#![comment = "The Servo Parallel Browser Project"] -#![license = "MIT"] - -#![allow(non_snake_case)] +#![allow(missing_copy_implementations, non_snake_case, unstable)] extern crate libc; From 3372dec93a12fdbfa0df11d5a64700e2e3898da7 Mon Sep 17 00:00:00 2001 From: Ivan Ukhov Date: Tue, 20 Jan 2015 15:50:49 +0100 Subject: [PATCH 116/249] Update to Rust Nightly --- Cargo.toml | 3 +++ src/lib.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index ae2a1bf..de25f59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,6 @@ license = "MIT" [lib] name = "cocoa" crate-type = ["rlib"] + +[dependencies] +bitflags = "0.1" diff --git a/src/lib.rs b/src/lib.rs index 746ad48..9fd21ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,8 @@ #![allow(missing_copy_implementations, non_snake_case, unstable)] +#[macro_use] +extern crate bitflags; extern crate libc; #[cfg(target_os="macos")] From 67dc6b7c8bc680c4c8e6220cfff349acf7c45457 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Fri, 23 Jan 2015 22:42:51 +1100 Subject: [PATCH 117/249] Add Nil --- src/base.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/base.rs b/src/base.rs index 1e9a306..10842e9 100644 --- a/src/base.rs +++ b/src/base.rs @@ -32,6 +32,8 @@ pub type NSUInteger = libc::c_ulong; #[allow(non_upper_case_globals)] pub const nil: id = 0; +#[allow(non_upper_case_globals)] +pub const Nil: Class = 0 as Class; extern { pub fn class_addMethod(cls: Class, name: SEL, imp: IMP, types: *const libc::c_char) -> bool; From 90d66dc8a00ffc74da3aaed638781845b151926f Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Fri, 23 Jan 2015 22:43:49 +1100 Subject: [PATCH 118/249] Use faithful BOOL type in bindings --- examples/hello_world.rs | 6 +-- src/appkit.rs | 82 ++++++++++++++++++++--------------------- src/base.rs | 5 +++ 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 7449401..d05000e 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,6 +1,6 @@ extern crate cocoa; -use cocoa::base::{NSUInteger, selector, nil}; +use cocoa::base::{NSUInteger, selector, nil, YES, NO}; use cocoa::appkit::{NSApp, NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSApplication, NSApplicationActivationPolicyRegular, @@ -42,7 +42,7 @@ fn main() { NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), NSTitledWindowMask as NSUInteger, NSBackingStoreBuffered, - false + NO ).autorelease(); window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); window.center(); @@ -50,7 +50,7 @@ fn main() { window.setTitle_(title); window.makeKeyAndOrderFront_(nil); - app.activateIgnoringOtherApps_(true); + app.activateIgnoringOtherApps_(YES); app.run(); } } diff --git a/src/appkit.rs b/src/appkit.rs index 327714b..b7e5d61 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -10,7 +10,7 @@ #![allow(non_upper_case_globals)] use base::{id, msg_send, msg_send_stret, class, selector}; -use base::{SEL, NSInteger, NSUInteger}; +use base::{BOOL, SEL, NSInteger, NSUInteger}; use libc; pub use self::NSApplicationActivationPolicy::*; @@ -347,22 +347,22 @@ pub trait NSApplication { msg_send()(class("NSApplication"), selector("sharedApplication")) } - unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> bool; + unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL; unsafe fn setMainMenu_(self, menu: id); - unsafe fn activateIgnoringOtherApps_(self, ignore: bool); + unsafe fn activateIgnoringOtherApps_(self, ignore: BOOL); unsafe fn run(self); unsafe fn finishLaunching(self); unsafe fn nextEventMatchingMask_untilDate_inMode_dequeue_(self, mask: NSUInteger, expiration: id, in_mode: id, - dequeue: bool) -> id; + dequeue: BOOL) -> id; unsafe fn sendEvent_(self, an_event: id); - unsafe fn postEvent_atStart_(self, anEvent: id, flag: bool); + unsafe fn postEvent_atStart_(self, anEvent: id, flag: BOOL); } impl NSApplication for id { - unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> bool { + unsafe fn setActivationPolicy_(self, policy: NSApplicationActivationPolicy) -> BOOL { msg_send()(self, selector("setActivationPolicy:"), policy as NSInteger) } @@ -370,7 +370,7 @@ impl NSApplication for id { msg_send()(self, selector("setMainMenu:"), menu) } - unsafe fn activateIgnoringOtherApps_(self, ignore: bool) { + unsafe fn activateIgnoringOtherApps_(self, ignore: BOOL) { msg_send()(self, selector("activateIgnoringOtherApps:"), ignore as libc::c_int) } @@ -386,7 +386,7 @@ impl NSApplication for id { mask: NSUInteger, expiration: id, in_mode: id, - dequeue: bool) -> id { + dequeue: BOOL) -> id { msg_send()(self, selector("nextEventMatchingMask:untilDate:inMode:dequeue:"), mask, expiration, in_mode, dequeue as libc::c_int) } @@ -395,7 +395,7 @@ impl NSApplication for id { msg_send()(self, selector("sendEvent:"), an_event) } - unsafe fn postEvent_atStart_(self, anEvent: id, flag: bool) { + unsafe fn postEvent_atStart_(self, anEvent: id, flag: BOOL) { msg_send()(self, selector("postEvent:atStart:"), anEvent, flag as libc::c_int) } } @@ -446,7 +446,7 @@ pub trait NSWindow { rect: NSRect, style: NSUInteger, backing: NSBackingStoreType, - defer: bool) -> id; + defer: BOOL) -> id; // Sizing Windows unsafe fn frame(self) -> NSRect; @@ -454,7 +454,7 @@ pub trait NSWindow { unsafe fn setFrameTopLeftPoint_(self, point: NSPoint); // skipped: constrainFrameRect_toScreen_ unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint; - unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: bool); + unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: BOOL); unsafe fn aspectRatio(self) -> NSSize; unsafe fn setAspectRatio_(self, aspectRatio: NSSize); unsafe fn minSize(self) -> NSSize; @@ -464,13 +464,13 @@ pub trait NSWindow { unsafe fn performZoom_(self, sender: id); unsafe fn zoom_(self, sender: id); // skipped: resizeFlags - unsafe fn showsResizeIndicator(self) -> bool; - unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: bool); + unsafe fn showsResizeIndicator(self) -> BOOL; + unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: BOOL); unsafe fn resizeIncrements(self) -> NSSize; unsafe fn setResizeIncrements_(self, resizeIncrements: NSSize); - unsafe fn preservesContentDuringLiveResize(self) -> bool; - unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: bool); - unsafe fn inLiveResize(self) -> bool; + unsafe fn preservesContentDuringLiveResize(self) -> BOOL; + unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: BOOL); + unsafe fn inLiveResize(self) -> BOOL; // Managing Window Layers unsafe fn orderOut_(self, sender: id); @@ -482,14 +482,14 @@ pub trait NSWindow { unsafe fn setLevel_(self, level: NSInteger); // Managing Key Status - unsafe fn canBecomeKeyWindow(self) -> bool; + unsafe fn canBecomeKeyWindow(self) -> BOOL; unsafe fn makeKeyWindow(self); unsafe fn makeKeyAndOrderFront_(self, sender: id); // skipped: becomeKeyWindow (should not be invoked directly, according to Apple's documentation) // skipped: resignKeyWindow (should not be invoked directly, according to Apple's documentation) // Managing Main Status - unsafe fn canBecomeMainWindow(self) -> bool; + unsafe fn canBecomeMainWindow(self) -> BOOL; unsafe fn makeMainWindow(self); // skipped: becomeMainWindow (should not be invoked directly, according to Apple's documentation) // skipped: resignMainWindow (should not be invoked directly, according to Apple's documentation) @@ -503,7 +503,7 @@ pub trait NSWindow { unsafe fn convertRectFromScreen_(self, rect: NSRect) -> NSRect; // Accessing Edited Status - unsafe fn setDocumentEdited_(self, documentEdited: bool); + unsafe fn setDocumentEdited_(self, documentEdited: BOOL); // Managing Titles unsafe fn title(self) -> id; @@ -515,14 +515,14 @@ pub trait NSWindow { // skipped: setRepresentedURL_ // Moving Windows - unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: bool); - unsafe fn setMovable_(self, movable: bool); + unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: BOOL); + unsafe fn setMovable_(self, movable: BOOL); unsafe fn center(self); // Closing Windows unsafe fn performClose_(self, sender: id); unsafe fn close(self); - unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: bool); + unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: BOOL); // Minimizing Windows unsafe fn performMiniaturize_(self, sender: id); @@ -534,8 +534,8 @@ pub trait NSWindow { unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id); unsafe fn setContentView_(self, view: id); - unsafe fn setAcceptsMouseMovedEvents_(self, accept: bool); - unsafe fn isVisible(self) -> bool; + unsafe fn setAcceptsMouseMovedEvents_(self, accept: BOOL); + unsafe fn isVisible(self) -> BOOL; } impl NSWindow for id { @@ -543,7 +543,7 @@ impl NSWindow for id { rect: NSRect, style: NSUInteger, backing: NSBackingStoreType, - defer: bool) -> id { + defer: BOOL) -> id { msg_send()(self, selector("initWithContentRect:styleMask:backing:defer:"), rect, style, backing as NSUInteger, defer as libc::c_int) } @@ -566,7 +566,7 @@ impl NSWindow for id { msg_send()(self, selector("cascadeTopLeftFromPoint:"), topLeft) } - unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: bool) { + unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: BOOL) { msg_send()(self, selector("setFrame:displayViews:"), windowFrame, display as libc::c_int) } @@ -602,11 +602,11 @@ impl NSWindow for id { msg_send()(self, selector("zoom:"), sender) } - unsafe fn showsResizeIndicator(self) -> bool { + unsafe fn showsResizeIndicator(self) -> BOOL { msg_send()(self, selector("showsResizeIndicator")) } - unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: bool) { + unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: BOOL) { msg_send()(self, selector("setShowsResizeIndicator:"), showsResizeIndicator as libc::c_int) } @@ -618,15 +618,15 @@ impl NSWindow for id { msg_send()(self, selector("setResizeIncrements:"), resizeIncrements) } - unsafe fn preservesContentDuringLiveResize(self) -> bool { + unsafe fn preservesContentDuringLiveResize(self) -> BOOL { msg_send()(self, selector("preservesContentDuringLiveResize")) } - unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: bool) { + unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: BOOL) { msg_send()(self, selector("setPreservesContentDuringLiveResize:"), preservesContentDuringLiveResize as libc::c_int) } - unsafe fn inLiveResize(self) -> bool { + unsafe fn inLiveResize(self) -> BOOL { msg_send()(self, selector("inLiveResize")) } @@ -662,7 +662,7 @@ impl NSWindow for id { // Managing Key Status - unsafe fn canBecomeKeyWindow(self) -> bool { + unsafe fn canBecomeKeyWindow(self) -> BOOL { msg_send()(self, selector("canBecomeKeyWindow")) } @@ -676,7 +676,7 @@ impl NSWindow for id { // Managing Main Status - unsafe fn canBecomeMainWindow(self) -> bool { + unsafe fn canBecomeMainWindow(self) -> BOOL { msg_send()(self, selector("canBecomeMainWindow")) } @@ -712,7 +712,7 @@ impl NSWindow for id { // Accessing Edited Status - unsafe fn setDocumentEdited_(self, documentEdited: bool) { + unsafe fn setDocumentEdited_(self, documentEdited: BOOL) { msg_send()(self, selector("setDocumentEdited:"), documentEdited as libc::c_int) } @@ -740,11 +740,11 @@ impl NSWindow for id { // Moving Windows - unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: bool) { + unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: BOOL) { msg_send()(self, selector("setMovableByWindowBackground:"), movableByWindowBackground as libc::c_int) } - unsafe fn setMovable_(self, movable: bool) { + unsafe fn setMovable_(self, movable: BOOL) { msg_send()(self, selector("setMovable:"), movable as libc::c_int) } @@ -762,7 +762,7 @@ impl NSWindow for id { msg_send()(self, selector("close")) } - unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: bool) { + unsafe fn setReleasedWhenClosed_(self, releasedWhenClosed: BOOL) { msg_send()(self, selector("setReleasedWhenClosed:"), releasedWhenClosed as libc::c_int) } @@ -792,11 +792,11 @@ impl NSWindow for id { msg_send()(self, selector("setContentView:"), view) } - unsafe fn setAcceptsMouseMovedEvents_(self, accept: bool) { + unsafe fn setAcceptsMouseMovedEvents_(self, accept: BOOL) { msg_send()(self, selector("setAcceptsMouseMovedEvents:"), accept as libc::c_int) } - unsafe fn isVisible(self) -> bool { + unsafe fn isVisible(self) -> BOOL { msg_send()(self, selector("isVisible")) } } @@ -840,7 +840,7 @@ pub trait NSView { unsafe fn bounds(self) -> NSRect; unsafe fn frame(self) -> NSRect; unsafe fn display_(self); - unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: bool); + unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: BOOL); unsafe fn convertPoint_fromView_(self, point: NSPoint, view: id) -> NSPoint; } @@ -865,7 +865,7 @@ impl NSView for id { msg_send()(self, selector("display")) } - unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: bool) { + unsafe fn setWantsBestResolutionOpenGLSurface_(self, flag: BOOL) { msg_send()(self, selector("setWantsBestResolutionOpenGLSurface:"), flag as libc::c_int) } diff --git a/src/base.rs b/src/base.rs index 10842e9..8be58e6 100644 --- a/src/base.rs +++ b/src/base.rs @@ -35,6 +35,11 @@ pub const nil: id = 0; #[allow(non_upper_case_globals)] pub const Nil: Class = 0 as Class; +pub type BOOL = libc::c_schar; + +pub const YES: BOOL = 1; +pub const NO: BOOL = 0; + extern { pub fn class_addMethod(cls: Class, name: SEL, imp: IMP, types: *const libc::c_char) -> bool; pub fn class_addIvar(cls: Class, From 807beb8dcfcee385b7b9ad08749dcfbcbe79257d Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sat, 24 Jan 2015 23:27:45 +1100 Subject: [PATCH 119/249] Add lots of missing window methods --- src/appkit.rs | 403 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 381 insertions(+), 22 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index b7e5d61..c77df19 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -77,6 +77,15 @@ impl NSRect { } } +// Same as CGRectEdge +#[repr(u32)] +pub enum NSRectEdge { + NSRectMinXEdge, + NSRectMinYEdge, + NSRectMaxXEdge, + NSRectMaxYEdge, +} + #[link(name = "AppKit", kind = "framework")] extern {} @@ -437,22 +446,87 @@ impl NSMenuItem for id { } } +bitflags! { + flags NSWindowCollectionBehavior: NSUInteger { + const NSWindowCollectionBehaviorDefault = 0, + const NSWindowCollectionBehaviorCanJoinAllSpaces = 1 << 0, + const NSWindowCollectionBehaviorMoveToActiveSpace = 1 << 1, + + const NSWindowCollectionBehaviorManaged = 1 << 2, + const NSWindowCollectionBehaviorTransient = 1 << 3, + const NSWindowCollectionBehaviorStationary = 1 << 4, + + const NSWindowCollectionBehaviorParticipatesInCycle = 1 << 5, + const NSWindowCollectionBehaviorIgnoresCycle = 1 << 6, + + const NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7, + const NSWindowCollectionBehaviorFullScreenAuxiliary = 1 << 8, + } +} + +bitflags! { + flags NSWindowOcclusionState: NSUInteger { + const NSWindowOcclusionStateVisible = 1 << 1 + } +} + pub trait NSWindow { unsafe fn alloc(_: Self) -> id { msg_send()(class("NSWindow"), selector("alloc")) } + // Creating Windows unsafe fn initWithContentRect_styleMask_backing_defer_(self, rect: NSRect, style: NSUInteger, backing: NSBackingStoreType, defer: BOOL) -> id; + unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self, + rect: NSRect, + style: NSUInteger, + backing: NSBackingStoreType, + defer: BOOL, + screen: id) -> id; + + // Configuring Windows + unsafe fn styleMask(self) -> NSUInteger; + unsafe fn setStyleMask_(self, styleMask: NSUInteger); + unsafe fn toggleFullScreen_(self, sender: id); + unsafe fn worksWhenModal(self) -> BOOL; + unsafe fn alphaValue(self) -> CGFloat; + unsafe fn setAlphaValue_(self, windowAlpha: CGFloat); + unsafe fn backgroundColor(self) -> id; + unsafe fn setBackgroundColor_(self, color: id); + unsafe fn colorSpace(self) -> id; + unsafe fn setColorSpace_(self, colorSpace: id); + unsafe fn contentView(self) -> id; + unsafe fn setContentView_(self, view: id); + unsafe fn canHide(self) -> BOOL; + unsafe fn setCanHide_(self, canHide: BOOL); + unsafe fn hidesOnDeactivate(self) -> BOOL; + unsafe fn setHidesOnDeactivate_(self, hideOnDeactivate: BOOL); + unsafe fn collectionBehavior(self) -> NSWindowCollectionBehavior; + unsafe fn setCollectionBehavior_(self, collectionBehavior: NSWindowCollectionBehavior); + unsafe fn setOpaque_(self, opaque: BOOL); + unsafe fn hasShadow(self) -> BOOL; + unsafe fn setHasShadow_(self, hasShadow: BOOL); + unsafe fn invalidateShadow(self); + unsafe fn autorecalculatesContentBorderThicknessForEdge_(self, edge: NSRectEdge) -> BOOL; + unsafe fn setAutorecalculatesContentBorderThickness_forEdge_(self, + autorecalculateContentBorderThickness: BOOL, + edge: NSRectEdge) -> BOOL; + unsafe fn contentBorderThicknessForEdge_(self, edge: NSRectEdge) -> CGFloat; + unsafe fn setContentBorderThickness_forEdge_(self, borderThickness: CGFloat, edge: NSRectEdge); + unsafe fn delegate(self) -> id; + unsafe fn setDelegate_(self, delegate: id); + unsafe fn preventsApplicationTerminationWhenModal(self) -> BOOL; + unsafe fn setPreventsApplicationTerminationWhenModal_(self, flag: BOOL); // Sizing Windows unsafe fn frame(self) -> NSRect; unsafe fn setFrameOrigin_(self, point: NSPoint); unsafe fn setFrameTopLeftPoint_(self, point: NSPoint); - // skipped: constrainFrameRect_toScreen_ + unsafe fn constrainFrameRect_toScreen_(self, frameRect: NSRect, screen: id); unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint; unsafe fn setFrame_displayViews_(self, windowFrame: NSRect, display: BOOL); unsafe fn aspectRatio(self) -> NSSize; @@ -463,7 +537,7 @@ pub trait NSWindow { unsafe fn setMaxSize_(self, maxSize: NSSize); unsafe fn performZoom_(self, sender: id); unsafe fn zoom_(self, sender: id); - // skipped: resizeFlags + unsafe fn resizeFlags(self) -> NSInteger; unsafe fn showsResizeIndicator(self) -> BOOL; unsafe fn setShowsResizeIndicator_(self, showsResizeIndicator: BOOL); unsafe fn resizeIncrements(self) -> NSSize; @@ -472,6 +546,22 @@ pub trait NSWindow { unsafe fn setPreservesContentDuringLiveResize_(self, preservesContentDuringLiveResize: BOOL); unsafe fn inLiveResize(self) -> BOOL; + // Sizing Content + unsafe fn contentAspectRatio(self) -> NSSize; + unsafe fn setContentAspectRatio_(self, contentAspectRatio: NSSize); + unsafe fn contentMinSize(self) -> NSSize; + unsafe fn setContentMinSize_(self, contentMinSize: NSSize); + unsafe fn contentSize(self) -> NSSize; + unsafe fn setContentSize_(self, contentSize: NSSize); + unsafe fn contentMaxSize(self) -> NSSize; + unsafe fn setContentMaxSize_(self, contentMaxSize: NSSize); + unsafe fn contentResizeIncrements(self) -> NSSize; + unsafe fn setContentResizeIncrements_(self, contentResizeIncrements: NSSize); + + // Managing Window Visibility and Occlusion State + unsafe fn isVisible(self) -> BOOL; // NOTE: Deprecated in 10.9 + unsafe fn occlusionState(self) -> NSWindowOcclusionState; + // Managing Window Layers unsafe fn orderOut_(self, sender: id); unsafe fn orderBack_(self, sender: id); @@ -494,6 +584,19 @@ pub trait NSWindow { // skipped: becomeMainWindow (should not be invoked directly, according to Apple's documentation) // skipped: resignMainWindow (should not be invoked directly, according to Apple's documentation) + // Handling Keyboard Events + unsafe fn keyDown_(self, event: id); + + // Handling Mouse Events + unsafe fn acceptsMouseMovedEvents(self) -> BOOL; + unsafe fn ignoresMouseEvents(self) -> BOOL; + unsafe fn setIgnoresMouseEvents_(self, ignoreMouseEvents: BOOL); + unsafe fn mouseLocationOutsideOfEventStream(self) -> NSPoint; + unsafe fn setAcceptsMouseMovedEvents_(self, acceptMouseMovedEvents: BOOL); + unsafe fn windowNumberAtPoint_belowWindowWithWindowNumber_(self, + point: NSPoint, + windowNumber: NSInteger) -> NSInteger; + // Converting Coordinates unsafe fn backingScaleFactor(self) -> CGFloat; unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect; @@ -511,8 +614,14 @@ pub trait NSWindow { unsafe fn setTitleWithRepresentedFilename_(self, filePath: id); unsafe fn representedFilename(self) -> id; unsafe fn setRepresentedFilename_(self, filePath: id); - // skipped: representedURL - // skipped: setRepresentedURL_ + unsafe fn representedURL(self) -> id; + unsafe fn setRepresentedURL_(self, representedURL: id); + + // Accessing Screen Information + unsafe fn screen(self) -> id; + unsafe fn deepestScreen(self) -> id; + unsafe fn displaysWhenScreenProfileChanges(self) -> BOOL; + unsafe fn setDisplaysWhenScreenProfileChanges_(self, displaysWhenScreenProfileChanges: BOOL); // Moving Windows unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: BOOL); @@ -528,17 +637,15 @@ pub trait NSWindow { unsafe fn performMiniaturize_(self, sender: id); unsafe fn miniaturize_(self, sender: id); unsafe fn deminiaturize_(self, sender: id); - // skipped: miniwindowImage - // skipped: setMiniwindowImage + unsafe fn miniwindowImage(self) -> id; + unsafe fn setMiniwindowImage_(self, miniwindowImage: id); unsafe fn miniwindowTitle(self) -> id; unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id); - - unsafe fn setContentView_(self, view: id); - unsafe fn setAcceptsMouseMovedEvents_(self, accept: BOOL); - unsafe fn isVisible(self) -> BOOL; } impl NSWindow for id { + // Creating Windows + unsafe fn initWithContentRect_styleMask_backing_defer_(self, rect: NSRect, style: NSUInteger, @@ -548,6 +655,141 @@ impl NSWindow for id { rect, style, backing as NSUInteger, defer as libc::c_int) } + unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self, + rect: NSRect, + style: NSUInteger, + 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) + } + + // Configuring Windows + + unsafe fn styleMask(self) -> NSUInteger { + msg_send()(self, selector("styleMask")) + } + + unsafe fn setStyleMask_(self, styleMask: NSUInteger) { + msg_send()(self, selector("setStyleMask:"), styleMask) + } + + unsafe fn toggleFullScreen_(self, sender: id) { + msg_send()(self, selector("toggleFullScreen:"), sender) + } + + unsafe fn worksWhenModal(self) -> BOOL { + msg_send()(self, selector("worksWhenModal")) + } + + unsafe fn alphaValue(self) -> CGFloat { + msg_send()(self, selector("alphaValue")) + } + + unsafe fn setAlphaValue_(self, windowAlpha: CGFloat) { + msg_send()(self, selector("setAlphaValue:"), windowAlpha) + } + + unsafe fn backgroundColor(self) -> id { + msg_send()(self, selector("backgroundColor")) + } + + unsafe fn setBackgroundColor_(self, color: id) { + msg_send()(self, selector("setBackgroundColor:"), color) + } + + unsafe fn colorSpace(self) -> id { + msg_send()(self, selector("colorSpace")) + } + + unsafe fn setColorSpace_(self, colorSpace: id) { + msg_send()(self, selector("setColorSpace:"), colorSpace) + } + + unsafe fn contentView(self) -> id { + msg_send()(self, selector("contentView")) + } + + unsafe fn setContentView_(self, view: id) { + msg_send()(self, selector("setContentView:"), view) + } + + unsafe fn canHide(self) -> BOOL { + msg_send()(self, selector("canHide")) + } + + unsafe fn setCanHide_(self, canHide: BOOL) { + msg_send()(self, selector("setCanHide:"), canHide as libc::c_int) + } + + unsafe fn hidesOnDeactivate(self) -> BOOL { + msg_send()(self, selector("hidesOnDeactivate")) + } + + unsafe fn setHidesOnDeactivate_(self, hideOnDeactivate: BOOL) { + msg_send()(self, selector("setHidesOnDeactivate:"), hideOnDeactivate as libc::c_int) + } + + unsafe fn collectionBehavior(self) -> NSWindowCollectionBehavior { + msg_send()(self, selector("collectionBehavior")) + } + + unsafe fn setCollectionBehavior_(self, collectionBehavior: NSWindowCollectionBehavior) { + msg_send()(self, selector("setCollectionBehavior:"), collectionBehavior) + } + + unsafe fn setOpaque_(self, opaque: BOOL) { + msg_send()(self, selector("setOpaque:"), opaque as libc::c_int) + } + + unsafe fn hasShadow(self) -> BOOL { + msg_send()(self, selector("hasShadow")) + } + + unsafe fn setHasShadow_(self, hasShadow: BOOL) { + msg_send()(self, selector("setHasShadow:"), hasShadow as libc::c_int) + } + + unsafe fn invalidateShadow(self) { + msg_send()(self, selector("invalidateShadow")) + } + + unsafe fn autorecalculatesContentBorderThicknessForEdge_(self, edge: NSRectEdge) -> BOOL { + msg_send()(self, selector("autorecalculatesContentBorderThicknessForEdge:"), edge) + } + + unsafe fn setAutorecalculatesContentBorderThickness_forEdge_(self, + autorecalculateContentBorderThickness: BOOL, + edge: NSRectEdge) -> BOOL { + msg_send()(self, selector("setAutorecalculatesContentBorderThickness:forEdge:"), + autorecalculateContentBorderThickness as libc::c_int, edge) + } + + unsafe fn contentBorderThicknessForEdge_(self, edge: NSRectEdge) -> CGFloat { + msg_send()(self, selector("contentBorderThicknessForEdge:"), edge) + } + + unsafe fn setContentBorderThickness_forEdge_(self, borderThickness: CGFloat, edge: NSRectEdge) { + msg_send()(self, selector("setContentBorderThickness:forEdge:"), borderThickness, edge) + } + + unsafe fn delegate(self) -> id { + msg_send()(self, selector("delegate")) + } + + unsafe fn setDelegate_(self, delegate: id) { + msg_send()(self, selector("setDelegate:"), delegate) + } + + unsafe fn preventsApplicationTerminationWhenModal(self) -> BOOL { + msg_send()(self, selector("preventsApplicationTerminationWhenModal")) + } + + unsafe fn setPreventsApplicationTerminationWhenModal_(self, flag: BOOL) { + msg_send()(self, selector("setPreventsApplicationTerminationWhenModal:"), flag as libc::c_int) + } + // Sizing Windows unsafe fn frame(self) -> NSRect { @@ -562,6 +804,10 @@ impl NSWindow for id { msg_send()(self, selector("setFrameTopLeftPoint:"), point) } + unsafe fn constrainFrameRect_toScreen_(self, frameRect: NSRect, screen: id) { + msg_send()(self, selector("constrainFrameRect:toScreen:"), frameRect, screen) + } + unsafe fn cascadeTopLeftFromPoint_(self, topLeft: NSPoint) -> NSPoint { msg_send()(self, selector("cascadeTopLeftFromPoint:"), topLeft) } @@ -602,6 +848,10 @@ impl NSWindow for id { msg_send()(self, selector("zoom:"), sender) } + unsafe fn resizeFlags(self) -> NSInteger { + msg_send()(self, selector("resizeFlags")) + } + unsafe fn showsResizeIndicator(self) -> BOOL { msg_send()(self, selector("showsResizeIndicator")) } @@ -630,6 +880,58 @@ impl NSWindow for id { msg_send()(self, selector("inLiveResize")) } + // Sizing Content + + unsafe fn contentAspectRatio(self) -> NSSize { + msg_send_stret()(self, selector("contentAspectRatio")) + } + + unsafe fn setContentAspectRatio_(self, contentAspectRatio: NSSize) { + msg_send()(self, selector("setContentAspectRatio:"), contentAspectRatio) + } + + unsafe fn contentMinSize(self) -> NSSize { + msg_send_stret()(self, selector("contentMinSize")) + } + + unsafe fn setContentMinSize_(self, contentMinSize: NSSize) { + msg_send()(self, selector("setContentMinSize:"), contentMinSize) + } + + unsafe fn contentSize(self) -> NSSize { + msg_send_stret()(self, selector("contentSize")) + } + + unsafe fn setContentSize_(self, contentSize: NSSize) { + msg_send()(self, selector("setContentSize:"), contentSize) + } + + unsafe fn contentMaxSize(self) -> NSSize { + msg_send_stret()(self, selector("contentMaxSize")) + } + + unsafe fn setContentMaxSize_(self, contentMaxSize: NSSize) { + msg_send()(self, selector("setContentMaxSize:"), contentMaxSize) + } + + unsafe fn contentResizeIncrements(self) -> NSSize { + msg_send_stret()(self, selector("contentResizeIncrements")) + } + + unsafe fn setContentResizeIncrements_(self, contentResizeIncrements: NSSize) { + msg_send()(self, selector("setContentResizeIncrements:"), contentResizeIncrements) + } + + // Managing Window Visibility and Occlusion State + + unsafe fn isVisible(self) -> BOOL { + msg_send()(self, selector("isVisible")) + } + + unsafe fn occlusionState(self) -> NSWindowOcclusionState { + msg_send()(self, selector("occlusionState")) + } + // Managing Window Layers unsafe fn orderOut_(self, sender: id) { @@ -684,6 +986,41 @@ impl NSWindow for id { msg_send()(self, selector("makeMainWindow")) } + // Handling Keyboard Events + + unsafe fn keyDown_(self, event: id) { + msg_send()(self, selector("keyDown:"), event) + } + + // Handling Mouse Events + + unsafe fn acceptsMouseMovedEvents(self) -> BOOL { + msg_send()(self, selector("acceptsMouseMovedEvents")) + } + + unsafe fn ignoresMouseEvents(self) -> BOOL { + msg_send()(self, selector("ignoresMouseEvents")) + } + + unsafe fn setIgnoresMouseEvents_(self, ignoreMouseEvents: BOOL) { + msg_send()(self, selector("setIgnoresMouseEvents:"), ignoreMouseEvents as libc::c_int) + } + + unsafe fn mouseLocationOutsideOfEventStream(self) -> NSPoint { + msg_send_stret()(self, selector("mouseLocationOutsideOfEventStream")) + } + + unsafe fn setAcceptsMouseMovedEvents_(self, acceptMouseMovedEvents: BOOL) { + msg_send()(self, selector("setAcceptsMouseMovedEvents:"), acceptMouseMovedEvents as libc::c_int) + } + + unsafe fn windowNumberAtPoint_belowWindowWithWindowNumber_(self, + point: NSPoint, + windowNumber: NSInteger) -> NSInteger { + msg_send()(self, selector("windowNumberAtPoint:belowWindowWithWindowNumber:"), + point, windowNumber) + } + // Converting Coordinates unsafe fn backingScaleFactor(self) -> CGFloat { @@ -738,6 +1075,32 @@ impl NSWindow for id { msg_send()(self, selector("setRepresentedFilename:"), filePath) } + unsafe fn representedURL(self) -> id { + msg_send()(self, selector("representedURL")) + } + + unsafe fn setRepresentedURL_(self, representedURL: id) { + msg_send()(self, selector("setRepresentedURL:"), representedURL) + } + + // Accessing Screen Information + + unsafe fn screen(self) -> id { + msg_send()(self, selector("screen")) + } + + unsafe fn deepestScreen(self) -> id { + msg_send()(self, selector("deepestScreen")) + } + + unsafe fn displaysWhenScreenProfileChanges(self) -> BOOL { + msg_send()(self, selector("displaysWhenScreenProfileChanges")) + } + + unsafe fn setDisplaysWhenScreenProfileChanges_(self, displaysWhenScreenProfileChanges: BOOL) { + msg_send()(self, selector("setDisplaysWhenScreenProfileChanges:"), displaysWhenScreenProfileChanges as libc::c_int) + } + // Moving Windows unsafe fn setMovableByWindowBackground_(self, movableByWindowBackground: BOOL) { @@ -780,6 +1143,14 @@ impl NSWindow for id { msg_send()(self, selector("deminiaturize:"), sender) } + unsafe fn miniwindowImage(self) -> id { + msg_send()(self, selector("miniwindowImage")) + } + + unsafe fn setMiniwindowImage_(self, miniwindowImage: id) { + msg_send()(self, selector("setMiniwindowImage:"), miniwindowImage) + } + unsafe fn miniwindowTitle(self) -> id { msg_send()(self, selector("miniwindowTitle")) } @@ -787,18 +1158,6 @@ impl NSWindow for id { unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id) { msg_send()(self, selector("setMiniwindowTitle:"), miniwindowTitle) } - - unsafe fn setContentView_(self, view: id) { - msg_send()(self, selector("setContentView:"), view) - } - - unsafe fn setAcceptsMouseMovedEvents_(self, accept: BOOL) { - msg_send()(self, selector("setAcceptsMouseMovedEvents:"), accept as libc::c_int) - } - - unsafe fn isVisible(self) -> BOOL { - msg_send()(self, selector("isVisible")) - } } pub trait NSString { From 6f624568245e92600f951529386a5a8bdf0408ac Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 26 Jan 2015 13:12:45 +1100 Subject: [PATCH 120/249] More NSWindow methods added --- src/appkit.rs | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index c77df19..8b611d5 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -522,6 +522,22 @@ pub trait NSWindow { unsafe fn preventsApplicationTerminationWhenModal(self) -> BOOL; unsafe fn setPreventsApplicationTerminationWhenModal_(self, flag: BOOL); + // TODO: Accessing Window Information + + // Getting Layout Information + unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSUInteger) -> NSRect; + unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSUInteger) -> NSRect; + unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSUInteger) -> CGFloat; + unsafe fn contentRectForFrameRect_(self, windowFrame: NSRect) -> NSRect; + unsafe fn frameRectForContentRect_(self, windowContent: NSRect) -> NSRect; + + // Managing Windows + unsafe fn drawers(self) -> id; + unsafe fn windowController(self) -> id; + unsafe fn setWindowController_(self, windowController: id); + + // TODO: Managing Sheets + // Sizing Windows unsafe fn frame(self) -> NSRect; unsafe fn setFrameOrigin_(self, point: NSPoint); @@ -584,6 +600,19 @@ pub trait NSWindow { // skipped: becomeMainWindow (should not be invoked directly, according to Apple's documentation) // skipped: resignMainWindow (should not be invoked directly, according to Apple's documentation) + // TODO: Managing Toolbars + // TODO: Managing Attached Windows + // TODO: Managing Window Buffers + // TODO: Managing Default Buttons + // TODO: Managing Field Editors + // TODO: Managing the Window Menu + // TODO: Managing Cursor Rectangles + // TODO: Managing Title Bars + // TODO: Managing Tooltips + // TODO: Handling Events + // TODO: Managing Responders + // TODO: Managing the Key View Loop + // Handling Keyboard Events unsafe fn keyDown_(self, event: id); @@ -597,6 +626,13 @@ pub trait NSWindow { point: NSPoint, windowNumber: NSInteger) -> NSInteger; + // TODO: Handling Window Restoration + // TODO: Bracketing Drawing Operations + // TODO: Drawing Windows + // TODO: Window Animation + // TODO: Updating Windows + // TODO: Dragging Items + // Converting Coordinates unsafe fn backingScaleFactor(self) -> CGFloat; unsafe fn backingAlignedRect_options_(self, rect: NSRect, options: NSAlignmentOptions) -> NSRect; @@ -641,6 +677,14 @@ pub trait NSWindow { unsafe fn setMiniwindowImage_(self, miniwindowImage: id); unsafe fn miniwindowTitle(self) -> id; unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id); + + // TODO: Getting the Dock Tile + // TODO: Printing Windows + // TODO: Providing Services + // TODO: Working with Carbon + // TODO: Triggering Constraint-Based Layout + // TODO: Debugging Constraint-Based Layout + // TODO: Constraint-Based Layouts } impl NSWindow for id { @@ -790,6 +834,46 @@ impl NSWindow for id { msg_send()(self, selector("setPreventsApplicationTerminationWhenModal:"), flag as libc::c_int) } + // TODO: Accessing Window Information + + // Getting Layout Information + + unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSUInteger) -> NSRect { + msg_send_stret()(self, selector("contentRectForFrameRect:styleMask:"), windowFrame, windowStyle) + } + + unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSUInteger) -> NSRect { + msg_send_stret()(self, selector("frameRectForContentRect:styleMask:"), windowContentRect, windowStyle) + } + + unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSUInteger) -> CGFloat { + msg_send()(self, selector("minFrameWidthWithTitle:styleMask:"), windowTitle, windowStyle) + } + + unsafe fn contentRectForFrameRect_(self, windowFrame: NSRect) -> NSRect { + msg_send_stret()(self, selector("contentRectForFrameRect:"), windowFrame) + } + + unsafe fn frameRectForContentRect_(self, windowContent: NSRect) -> NSRect { + msg_send_stret()(self, selector("frameRectForContentRect:"), windowContent) + } + + // Managing Windows + + unsafe fn drawers(self) -> id { + msg_send()(self, selector("drawers")) + } + + unsafe fn windowController(self) -> id { + msg_send()(self, selector("windowController")) + } + + unsafe fn setWindowController_(self, windowController: id) { + msg_send()(self, selector("setWindowController:"), windowController) + } + + // TODO: Managing Sheets + // Sizing Windows unsafe fn frame(self) -> NSRect { @@ -986,6 +1070,19 @@ impl NSWindow for id { msg_send()(self, selector("makeMainWindow")) } + // TODO: Managing Toolbars + // TODO: Managing Attached Windows + // TODO: Managing Window Buffers + // TODO: Managing Default Buttons + // TODO: Managing Field Editors + // TODO: Managing the Window Menu + // TODO: Managing Cursor Rectangles + // TODO: Managing Title Bars + // TODO: Managing Tooltips + // TODO: Handling Events + // TODO: Managing Responders + // TODO: Managing the Key View Loop + // Handling Keyboard Events unsafe fn keyDown_(self, event: id) { @@ -1158,6 +1255,14 @@ impl NSWindow for id { unsafe fn setMiniwindowTitle_(self, miniwindowTitle: id) { msg_send()(self, selector("setMiniwindowTitle:"), miniwindowTitle) } + + // TODO: Getting the Dock Tile + // TODO: Printing Windows + // TODO: Providing Services + // TODO: Working with Carbon + // TODO: Triggering Constraint-Based Layout + // TODO: Debugging Constraint-Based Layout + // TODO: Constraint-Based Layouts } pub trait NSString { From 78509d02d8cc29bc33ab9d06ca54a6c24ea3c532 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 26 Jan 2015 20:16:41 +1100 Subject: [PATCH 121/249] Add missing NSEvent methods --- src/appkit.rs | 869 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 747 insertions(+), 122 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 8b611d5..984022b 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -29,6 +29,12 @@ pub type CGFloat = f64; pub type GLint = libc::int32_t; +#[repr(C)] +pub struct CGPoint { + pub x: CGFloat, + pub y: CGFloat, +} + #[repr(C)] pub struct NSPoint { pub x: f64, @@ -235,85 +241,6 @@ pub enum NSOpenGLContextParameter { NSOpenGLCPMPSwapsInFlight = 315, } -#[repr(u64)] -pub enum NSEventType { - NSLeftMouseDown = 1, - NSLeftMouseUp = 2, - NSRightMouseDown = 3, - NSRightMouseUp = 4, - NSMouseMoved = 5, - NSLeftMouseDragged = 6, - NSRightMouseDragged = 7, - NSMouseEntered = 8, - NSMouseExited = 9, - NSKeyDown = 10, - NSKeyUp = 11, - NSFlagsChanged = 12, - NSAppKitDefined = 13, - NSSystemDefined = 14, - NSApplicationDefined = 15, - NSPeriodic = 16, - NSCursorUpdate = 17, - NSScrollWheel = 22, - NSTabletPoint = 23, - NSTabletProximity = 24, - NSOtherMouseDown = 25, - NSOtherMouseUp = 26, - NSOtherMouseDragged = 27, - NSEventTypeGesture = 29, - NSEventTypeMagnify = 30, - NSEventTypeSwipe = 31, - NSEventTypeRotate = 18, - NSEventTypeBeginGesture = 19, - NSEventTypeEndGesture = 20, -} - -#[repr(u32)] -pub enum NSEventMask { - NSLeftMouseDownMask = 1 << NSLeftMouseDown as u32, - NSLeftMouseUpMask = 1 << NSLeftMouseUp as u32, - NSRightMouseDownMask = 1 << NSRightMouseDown as u32, - NSRightMouseUpMask = 1 << NSRightMouseUp as u32, - NSMouseMovedMask = 1 << NSMouseMoved as u32, - NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged as u32, - NSRightMouseDraggedMask = 1 << NSRightMouseDragged as u32, - NSMouseEnteredMask = 1 << NSMouseEntered as u32, - NSMouseExitedMask = 1 << NSMouseExited as u32, - NSKeyDownMask = 1 << NSKeyDown as u32, - NSKeyUpMask = 1 << NSKeyUp as u32, - NSFlagsChangedMask = 1 << NSFlagsChanged as u32, - NSAppKitDefinedMask = 1 << NSAppKitDefined as u32, - NSSystemDefinedMask = 1 << NSSystemDefined as u32, - NSAPplicationDefinedMask = 1 << NSApplicationDefined as u32, - NSPeriodicMask = 1 << NSPeriodic as u32, - NSCursorUpdateMask = 1 << NSCursorUpdate as u32, - NSScrollWheelMask = 1 << NSScrollWheel as u32, - NSTabletPointMask = 1 << NSTabletPoint as u32, - NSTabletProximityMask = 1 << NSTabletProximity as u32, - NSOtherMouseDownMask = 1 << NSOtherMouseDown as u32, - NSOtherMouseUpMask = 1 << NSOtherMouseUp as u32, - NSOtherMouseDraggedMask = 1 << NSOtherMouseDragged as u32, - NSEventMaskgesture = 1 << NSEventTypeGesture as u32, - NSEventMaskSwipe = 1 << NSEventTypeSwipe as u32, - NSEventMaskRotate = 1 << NSEventTypeRotate as u32, - NSEventMaskBeginGesture = 1 << NSEventTypeBeginGesture as u32, - NSEventMaskEndGesture = 1 << NSEventTypeEndGesture as u32, - NSAnyEventMask = 0xffffffff, -} - -#[repr(u64)] -pub enum NSEventModifierFlags { - NSAlphaShiftKeyMask = 1 << 16, - NSShiftKeyMask = 1 << 17, - NSControlKeyMask = 1 << 18, - NSAlternateKeyMask = 1 << 19, - NSCommandKeyMask = 1 << 20, - NSNumericPadKeyMask = 1 << 21, - NSHelpKeyMask = 1 << 22, - NSFunctionKeyMask = 1 << 23, - NSDeviceIndependentModifierFlagsMask = 0xffff0000, -} - pub static NSMainMenuWindowLevel: libc::int32_t = 24; pub trait NSAutoreleasePool { @@ -1419,84 +1346,782 @@ impl NSDate for id { } +bitflags! { + flags NSEventSwipeTrackingOptions: NSUInteger { + const NSEventSwipeTrackingLockDirection = 0x1 << 0, + const NSEventSwipeTrackingClampGestureAmount = 0x1 << 1, + } +} + +#[repr(i64)] // NSInteger +pub enum NSEventGestureAxis { + NSEventGestureAxisNone = 0, + NSEventGestureAxisHorizontal, + NSEventGestureAxisVertical, +} + +bitflags! { + flags NSEventPhase: NSUInteger { + const NSEventPhaseNone = 0, + const NSEventPhaseBegan = 0x1 << 0, + const NSEventPhaseStationary = 0x1 << 1, + const NSEventPhaseChanged = 0x1 << 2, + const NSEventPhaseEnded = 0x1 << 3, + const NSEventPhaseCancelled = 0x1 << 4, + const NSEventPhaseMayBegin = 0x1 << 5, + } +} + +bitflags! { + flags NSTouchPhase: NSUInteger { + const NSTouchPhaseBegan = 1 << 0, + const NSTouchPhaseMoved = 1 << 1, + const NSTouchPhaseStationary = 1 << 2, + const NSTouchPhaseEnded = 1 << 3, + const NSTouchPhaseCancelled = 1 << 4, + const NSTouchPhaseTouching = NSTouchPhaseBegan.bits + | NSTouchPhaseMoved.bits + | NSTouchPhaseStationary.bits, + const NSTouchPhaseAny = 0 - 1, // NSUIntegerMax + } +} + +#[repr(u64)] // NSUInteger +pub enum NSEventType { + NSLeftMouseDown = 1, + NSLeftMouseUp = 2, + NSRightMouseDown = 3, + NSRightMouseUp = 4, + NSMouseMoved = 5, + NSLeftMouseDragged = 6, + NSRightMouseDragged = 7, + NSMouseEntered = 8, + NSMouseExited = 9, + NSKeyDown = 10, + NSKeyUp = 11, + NSFlagsChanged = 12, + NSAppKitDefined = 13, + NSSystemDefined = 14, + NSApplicationDefined = 15, + NSPeriodic = 16, + NSCursorUpdate = 17, + NSScrollWheel = 22, + NSTabletPoint = 23, + NSTabletProximity = 24, + NSOtherMouseDown = 25, + NSOtherMouseUp = 26, + NSOtherMouseDragged = 27, + NSEventTypeGesture = 29, + NSEventTypeMagnify = 30, + NSEventTypeSwipe = 31, + NSEventTypeRotate = 18, + NSEventTypeBeginGesture = 19, + NSEventTypeEndGesture = 20, +} + +bitflags! { + 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, + const NSRightMouseUpMask = 1 << NSRightMouseUp as libc::c_ulonglong, + const NSMouseMovedMask = 1 << NSMouseMoved as libc::c_ulonglong, + const NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged as libc::c_ulonglong, + const NSRightMouseDraggedMask = 1 << NSRightMouseDragged as libc::c_ulonglong, + const NSMouseEnteredMask = 1 << NSMouseEntered as libc::c_ulonglong, + const NSMouseExitedMask = 1 << NSMouseExited as libc::c_ulonglong, + const NSKeyDownMask = 1 << NSKeyDown as libc::c_ulonglong, + const NSKeyUpMask = 1 << NSKeyUp as libc::c_ulonglong, + 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 NSPeriodicMask = 1 << NSPeriodic as libc::c_ulonglong, + const NSCursorUpdateMask = 1 << NSCursorUpdate as libc::c_ulonglong, + const NSScrollWheelMask = 1 << NSScrollWheel as libc::c_ulonglong, + const NSTabletPointMask = 1 << NSTabletPoint as libc::c_ulonglong, + const NSTabletProximityMask = 1 << NSTabletProximity as libc::c_ulonglong, + 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 NSEventMaskSwipe = 1 << NSEventTypeSwipe as libc::c_ulonglong, + 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 NSAnyEventMask = 0xffffffff, + } +} + +impl NSEventMask { + pub fn from_type(ty: NSEventType) -> NSEventMask { + NSEventMask { bits: 1 << ty as libc::c_ulonglong } + } +} + +bitflags! { + flags NSEventModifierFlags: NSUInteger { + const NSAlphaShiftKeyMask = 1 << 16, + const NSShiftKeyMask = 1 << 17, + const NSControlKeyMask = 1 << 18, + const NSAlternateKeyMask = 1 << 19, + const NSCommandKeyMask = 1 << 20, + const NSNumericPadKeyMask = 1 << 21, + const NSHelpKeyMask = 1 << 22, + const NSFunctionKeyMask = 1 << 23, + const NSDeviceIndependentModifierFlagsMask = 0xffff0000, + } +} + +// Not sure of the type here +pub enum NSPointingDeviceType { + // TODO: Not sure what these values are + // NSUnknownPointingDevice = NX_TABLET_POINTER_UNKNOWN, + // NSPenPointingDevice = NX_TABLET_POINTER_PEN, + // NSCursorPointingDevice = NX_TABLET_POINTER_CURSOR, + // NSEraserPointingDevice = NX_TABLET_POINTER_ERASER, +} + +// Not sure of the type here +pub enum NSEventButtonMask { + // TODO: Not sure what these values are + // NSPenTipMask = NX_TABLET_BUTTON_PENTIPMASK, + // NSPenLowerSideMask = NX_TABLET_BUTTON_PENLOWERSIDEMASK, + // NSPenUpperSideMask = NX_TABLET_BUTTON_PENUPPERSIDEMASK, +} + +#[repr(i16)] +pub enum NSEventSubtype { + // TODO: Not sure what these values are + // NSMouseEventSubtype = NX_SUBTYPE_DEFAULT, + // NSTabletPointEventSubtype = NX_SUBTYPE_TABLET_POINT, + // NSTabletProximityEventSubtype = NX_SUBTYPE_TABLET_PROXIMITY + // NSTouchEventSubtype = NX_SUBTYPE_MOUSE_TOUCH, + NSWindowExposedEventType = 0, + NSApplicationActivatedEventType = 1, + NSApplicationDeactivatedEventType = 2, + NSWindowMovedEventType = 4, + NSScreenChangedEventType = 8, + NSAWTEventType = 16, +} + +pub const NSUpArrowFunctionKey: libc::c_ushort = 0xF700; +pub const NSDownArrowFunctionKey: libc::c_ushort = 0xF701; +pub const NSLeftArrowFunctionKey: libc::c_ushort = 0xF702; +pub const NSRightArrowFunctionKey: libc::c_ushort = 0xF703; +pub const NSF1FunctionKey: libc::c_ushort = 0xF704; +pub const NSF2FunctionKey: libc::c_ushort = 0xF705; +pub const NSF3FunctionKey: libc::c_ushort = 0xF706; +pub const NSF4FunctionKey: libc::c_ushort = 0xF707; +pub const NSF5FunctionKey: libc::c_ushort = 0xF708; +pub const NSF6FunctionKey: libc::c_ushort = 0xF709; +pub const NSF7FunctionKey: libc::c_ushort = 0xF70A; +pub const NSF8FunctionKey: libc::c_ushort = 0xF70B; +pub const NSF9FunctionKey: libc::c_ushort = 0xF70C; +pub const NSF10FunctionKey: libc::c_ushort = 0xF70D; +pub const NSF11FunctionKey: libc::c_ushort = 0xF70E; +pub const NSF12FunctionKey: libc::c_ushort = 0xF70F; +pub const NSF13FunctionKey: libc::c_ushort = 0xF710; +pub const NSF14FunctionKey: libc::c_ushort = 0xF711; +pub const NSF15FunctionKey: libc::c_ushort = 0xF712; +pub const NSF16FunctionKey: libc::c_ushort = 0xF713; +pub const NSF17FunctionKey: libc::c_ushort = 0xF714; +pub const NSF18FunctionKey: libc::c_ushort = 0xF715; +pub const NSF19FunctionKey: libc::c_ushort = 0xF716; +pub const NSF20FunctionKey: libc::c_ushort = 0xF717; +pub const NSF21FunctionKey: libc::c_ushort = 0xF718; +pub const NSF22FunctionKey: libc::c_ushort = 0xF719; +pub const NSF23FunctionKey: libc::c_ushort = 0xF71A; +pub const NSF24FunctionKey: libc::c_ushort = 0xF71B; +pub const NSF25FunctionKey: libc::c_ushort = 0xF71C; +pub const NSF26FunctionKey: libc::c_ushort = 0xF71D; +pub const NSF27FunctionKey: libc::c_ushort = 0xF71E; +pub const NSF28FunctionKey: libc::c_ushort = 0xF71F; +pub const NSF29FunctionKey: libc::c_ushort = 0xF720; +pub const NSF30FunctionKey: libc::c_ushort = 0xF721; +pub const NSF31FunctionKey: libc::c_ushort = 0xF722; +pub const NSF32FunctionKey: libc::c_ushort = 0xF723; +pub const NSF33FunctionKey: libc::c_ushort = 0xF724; +pub const NSF34FunctionKey: libc::c_ushort = 0xF725; +pub const NSF35FunctionKey: libc::c_ushort = 0xF726; +pub const NSInsertFunctionKey: libc::c_ushort = 0xF727; +pub const NSDeleteFunctionKey: libc::c_ushort = 0xF728; +pub const NSHomeFunctionKey: libc::c_ushort = 0xF729; +pub const NSBeginFunctionKey: libc::c_ushort = 0xF72A; +pub const NSEndFunctionKey: libc::c_ushort = 0xF72B; +pub const NSPageUpFunctionKey: libc::c_ushort = 0xF72C; +pub const NSPageDownFunctionKey: libc::c_ushort = 0xF72D; +pub const NSPrintScreenFunctionKey: libc::c_ushort = 0xF72E; +pub const NSScrollLockFunctionKey: libc::c_ushort = 0xF72F; +pub const NSPauseFunctionKey: libc::c_ushort = 0xF730; +pub const NSSysReqFunctionKey: libc::c_ushort = 0xF731; +pub const NSBreakFunctionKey: libc::c_ushort = 0xF732; +pub const NSResetFunctionKey: libc::c_ushort = 0xF733; +pub const NSStopFunctionKey: libc::c_ushort = 0xF734; +pub const NSMenuFunctionKey: libc::c_ushort = 0xF735; +pub const NSUserFunctionKey: libc::c_ushort = 0xF736; +pub const NSSystemFunctionKey: libc::c_ushort = 0xF737; +pub const NSPrintFunctionKey: libc::c_ushort = 0xF738; +pub const NSClearLineFunctionKey: libc::c_ushort = 0xF739; +pub const NSClearDisplayFunctionKey: libc::c_ushort = 0xF73A; +pub const NSInsertLineFunctionKey: libc::c_ushort = 0xF73B; +pub const NSDeleteLineFunctionKey: libc::c_ushort = 0xF73C; +pub const NSInsertCharFunctionKey: libc::c_ushort = 0xF73D; +pub const NSDeleteCharFunctionKey: libc::c_ushort = 0xF73E; +pub const NSPrevFunctionKey: libc::c_ushort = 0xF73F; +pub const NSNextFunctionKey: libc::c_ushort = 0xF740; +pub const NSSelectFunctionKey: libc::c_ushort = 0xF741; +pub const NSExecuteFunctionKey: libc::c_ushort = 0xF742; +pub const NSUndoFunctionKey: libc::c_ushort = 0xF743; +pub const NSRedoFunctionKey: libc::c_ushort = 0xF744; +pub const NSFindFunctionKey: libc::c_ushort = 0xF745; +pub const NSHelpFunctionKey: libc::c_ushort = 0xF746; +pub const NSModeSwitchFunctionKey: libc::c_ushort = 0xF747; + pub trait NSEvent { - unsafe fn - otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2( - _: Self, - ty: NSEventType, - location: NSPoint, - modifierFlags: NSUInteger, - timestamp: NSTimeInterval, - windowNumber: NSInteger, - context: *mut libc::c_void, - subtype: libc::c_short, - data1: NSInteger, - data2: NSInteger) - -> id; - unsafe fn get_type(self) -> NSEventType; + // Creating Events + unsafe fn keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_( + _: Self, + eventType: NSEventType, + location: NSPoint, + modifierFlags: NSEventModifierFlags, + timestamp: NSTimeInterval, + windowNumber: NSInteger, + characters: id /* (NSString *) */, + unmodCharacters: id /* (NSString *) */, + repeatKey: BOOL, + code: libc::c_ushort) -> id /* (NSEvent *) */; + unsafe fn mouseEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_clickCount_pressure_( + _: Self, + eventType: NSEventType, + location: NSPoint, + modifierFlags: NSEventModifierFlags, + timestamp: NSTimeInterval, + windowNumber: NSInteger, + context: id /* (NSGraphicsContext *) */, + eventNumber: NSInteger, + clickCount: NSInteger, + pressure: libc::c_float) -> id /* (NSEvent *) */; + unsafe fn enterExitEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_trackingNumber_userData_( + _: Self, + eventType: NSEventType, + location: NSPoint, + modifierFlags: NSEventModifierFlags, + timestamp: NSTimeInterval, + windowNumber: NSInteger, + context: id /* (NSGraphicsContext *) */, + eventNumber: NSInteger, + trackingNumber: NSInteger, + userData: *mut libc::c_void) -> id /* (NSEvent *) */; + unsafe fn otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_( + _: Self, + eventType: NSEventType, + location: NSPoint, + modifierFlags: NSEventModifierFlags, + timestamp: NSTimeInterval, + windowNumber: NSInteger, + context: id /* (NSGraphicsContext *) */, + subtype: NSEventSubtype, + data1: NSInteger, + data2: NSInteger) -> id /* (NSEvent *) */; + unsafe fn eventWithEventRef_(_: Self, eventRef: *const libc::c_void) -> id; + unsafe fn eventWithCGEvent_(_: Self, cgEvent: *mut libc::c_void /* CGEventRef */) -> id; + + // Getting General Event Information + unsafe fn context(self) -> id /* (NSGraphicsContext *) */; unsafe fn locationInWindow(self) -> NSPoint; - unsafe fn characters(self) -> id; - unsafe fn charactersIgnoringModifiers(self) -> id; - unsafe fn keycode(self) -> libc::c_ushort; - unsafe fn modifierFlags(self) -> NSUInteger; + unsafe fn modifierFlags(self) -> NSEventModifierFlags; + unsafe fn timestamp(self) -> NSTimeInterval; + // NOTE: renamed from `- type` due to Rust keyword collision + unsafe fn event_type(self) -> NSEventType; + unsafe fn window(self) -> id /* (NSWindow *) */; + unsafe fn windowNumber(self) -> NSInteger; + unsafe fn eventRef(self) -> *const libc::c_void; + unsafe fn CGEvent(self) -> *mut libc::c_void /* CGEventRef */; + + // Getting Key Event Information + // NOTE: renamed from `+ modifierFlags` due to conflict with `- modifierFlags` + unsafe fn currentModifierFlags(_: Self) -> NSEventModifierFlags; + unsafe fn keyRepeatDelay(_: Self) -> NSTimeInterval; + unsafe fn keyRepeatInterval(_: Self) -> NSTimeInterval; + unsafe fn characters(self) -> id /* (NSString *) */; + unsafe fn charactersIgnoringModifiers(self) -> id /* (NSString *) */; + unsafe fn keyCode(self) -> libc::c_ushort; + + // Getting Mouse Event Information + unsafe fn pressedMouseButtons(_: Self) -> NSUInteger; + unsafe fn doubleClickInterval(_: Self) -> NSTimeInterval; + unsafe fn mouseLocation(_: Self) -> NSPoint; + unsafe fn buttonNumber(self) -> NSInteger; + unsafe fn clickCount(self) -> NSInteger; + unsafe fn pressure(self) -> libc::c_float; + unsafe fn setMouseCoalescingEnabled_(_: Self, flag: BOOL); + unsafe fn isMouseCoalescingEnabled(_: Self) -> BOOL; + + // Getting Mouse-Tracking Event Information + unsafe fn eventNumber(self) -> NSInteger; + unsafe fn trackingNumber(self) -> NSInteger; + unsafe fn trackingArea(self) -> id /* (NSTrackingArea *) */; + unsafe fn userData(self) -> *const libc::c_void; + + // Getting Custom Event Information + unsafe fn data1(self) -> NSInteger; + unsafe fn data2(self) -> NSInteger; + unsafe fn subtype(self) -> NSEventSubtype; + + // Getting Scroll Wheel Event Information + unsafe fn deltaX(self) -> CGFloat; + unsafe fn deltaY(self) -> CGFloat; + unsafe fn deltaZ(self) -> CGFloat; + + // Getting Tablet Proximity Information + unsafe fn capabilityMask(self) -> NSUInteger; + unsafe fn deviceID(self) -> NSUInteger; + unsafe fn pointingDeviceID(self) -> NSUInteger; + unsafe fn pointingDeviceSerialNumber(self) -> NSUInteger; + unsafe fn pointingDeviceType(self) -> NSPointingDeviceType; + unsafe fn systemTabletID(self) -> NSUInteger; + unsafe fn tabletID(self) -> NSUInteger; + unsafe fn uniqueID(self) -> libc::c_ulonglong; + unsafe fn vendorID(self) -> NSUInteger; + unsafe fn vendorPointingDeviceType(self) -> NSUInteger; + + // Getting Tablet Pointing Information + unsafe fn absoluteX(self) -> NSInteger; + unsafe fn absoluteY(self) -> NSInteger; + unsafe fn absoluteZ(self) -> NSInteger; + unsafe fn buttonMask(self) -> NSEventButtonMask; + unsafe fn rotation(self) -> libc::c_float; + unsafe fn tangentialPressure(self) -> libc::c_float; + unsafe fn tilt(self) -> NSPoint; + unsafe fn vendorDefined(self) -> id; + + // Requesting and Stopping Periodic Events + unsafe fn startPeriodicEventsAfterDelay_withPeriod_(_: Self, delaySeconds: NSTimeInterval, periodSeconds: NSTimeInterval); + unsafe fn stopPeriodicEvents(_: Self); + + // Getting Touch and Gesture Information + unsafe fn magnification(self) -> CGFloat; + unsafe fn touchesMatchingPhase_inView_(self, phase: NSTouchPhase, view: id /* (NSView *) */) -> id /* (NSSet *) */; + unsafe fn isSwipeTrackingFromScrollEventsEnabled(_: Self) -> BOOL; + + // Monitoring Application Events + // TODO: addGlobalMonitorForEventsMatchingMask_handler_ (unsure how to bind to blocks) + // TODO: addLocalMonitorForEventsMatchingMask_handler_ (unsure how to bind to blocks) + unsafe fn removeMonitor_(_: Self, eventMonitor: id); + + // Scroll Wheel and Flick Events + unsafe fn hasPreciseScrollingDeltas(self) -> BOOL; + unsafe fn scrollingDeltaX(self) -> CGFloat; unsafe fn scrollingDeltaY(self) -> CGFloat; + unsafe fn momentumPhase(self) -> NSEventPhase; + unsafe fn phase(self) -> NSEventPhase; + // 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; } impl NSEvent for id { - unsafe fn - otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2( - _: id, - ty: NSEventType, - location: NSPoint, - modifierFlags: NSUInteger, - timestamp: NSTimeInterval, - windowNumber: NSInteger, - context: *mut libc::c_void, - subtype: libc::c_short, - data1: NSInteger, - data2: NSInteger) - -> id { + // Creating Events + + unsafe fn keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_( + _: Self, + eventType: NSEventType, + location: NSPoint, + modifierFlags: NSEventModifierFlags, + timestamp: NSTimeInterval, + windowNumber: NSInteger, + characters: id /* (NSString *) */, + unmodCharacters: id /* (NSString *) */, + repeatKey: BOOL, + code: libc::c_ushort) -> id /* (NSEvent *) */ + { msg_send()(class("NSEvent"), - selector("otherEventWithType:location:modifierFlags:timestamp:windowNumber:\ - context:subtype:data1:data2:"), - ty, + 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) + } + + unsafe fn mouseEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_clickCount_pressure_( + _: Self, + eventType: NSEventType, + location: NSPoint, + modifierFlags: NSEventModifierFlags, + timestamp: NSTimeInterval, + windowNumber: NSInteger, + context: id /* (NSGraphicsContext *) */, + eventNumber: NSInteger, + 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, - subtype as libc::c_int, + eventNumber, + clickCount, + pressure as libc::c_double) + } + + unsafe fn enterExitEventWithType_location_modifierFlags_timestamp_windowNumber_context_eventNumber_trackingNumber_userData_( + _: Self, + eventType: NSEventType, + location: NSPoint, + modifierFlags: NSEventModifierFlags, + timestamp: NSTimeInterval, + windowNumber: NSInteger, + context: id /* (NSGraphicsContext *) */, + eventNumber: NSInteger, + 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) + } + + unsafe fn otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_( + _: Self, + eventType: NSEventType, + location: NSPoint, + modifierFlags: NSEventModifierFlags, + timestamp: NSTimeInterval, + windowNumber: NSInteger, + context: id /* (NSGraphicsContext *) */, + subtype: NSEventSubtype, + 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) } - unsafe fn get_type(self) -> NSEventType { - msg_send()(self, selector("type")) + unsafe fn eventWithEventRef_(_: Self, eventRef: *const libc::c_void) -> id { + msg_send()(class("NSEvent"), selector("eventWithEventRef:"), eventRef) + } + + unsafe fn eventWithCGEvent_(_: Self, cgEvent: *mut libc::c_void /* CGEventRef */) -> id { + msg_send()(class("NSEvent"), selector("eventWithCGEvent:"), cgEvent) + } + + // Getting General Event Information + + unsafe fn context(self) -> id /* (NSGraphicsContext *) */ { + msg_send()(self, selector("context")) } unsafe fn locationInWindow(self) -> NSPoint { - msg_send()(self, selector("locationInWindow")) + msg_send_stret()(self, selector("locationInWindow")) } - unsafe fn characters(self) -> id { + unsafe fn modifierFlags(self) -> NSEventModifierFlags { + msg_send()(self, selector("modifierFlags")) + } + + unsafe fn timestamp(self) -> NSTimeInterval { + msg_send()(self, selector("timestamp")) + } + // NOTE: renamed from `- type` due to Rust keyword collision + + unsafe fn event_type(self) -> NSEventType { + msg_send()(self, selector("event_type")) + } + + unsafe fn window(self) -> id /* (NSWindow *) */ { + msg_send()(self, selector("window")) + } + + unsafe fn windowNumber(self) -> NSInteger { + msg_send()(self, selector("windowNumber")) + } + + unsafe fn eventRef(self) -> *const libc::c_void { + msg_send()(self, selector("eventRef")) + } + + unsafe fn CGEvent(self) -> *mut libc::c_void /* CGEventRef */ { + msg_send()(self, selector("CGEvent")) + } + + // Getting Key Event Information + + // NOTE: renamed from `+ modifierFlags` due to conflict with `- modifierFlags` + + unsafe fn currentModifierFlags(_: Self) -> NSEventModifierFlags { + msg_send()(class("NSEvent"), selector("currentModifierFlags")) + } + + unsafe fn keyRepeatDelay(_: Self) -> NSTimeInterval { + msg_send()(class("NSEvent"), selector("keyRepeatDelay")) + } + + unsafe fn keyRepeatInterval(_: Self) -> NSTimeInterval { + msg_send()(class("NSEvent"), selector("keyRepeatInterval")) + } + + unsafe fn characters(self) -> id /* (NSString *) */ { msg_send()(self, selector("characters")) } - unsafe fn charactersIgnoringModifiers(self) -> id { + unsafe fn charactersIgnoringModifiers(self) -> id /* (NSString *) */ { msg_send()(self, selector("charactersIgnoringModifiers")) } - unsafe fn keycode(self) -> libc::c_ushort { + unsafe fn keyCode(self) -> libc::c_ushort { msg_send()(self, selector("keyCode")) } - unsafe fn modifierFlags(self) -> NSUInteger { - msg_send()(self, selector("modifierFlags")) + // Getting Mouse Event Information + + unsafe fn pressedMouseButtons(_: Self) -> NSUInteger { + msg_send()(class("NSEvent"), selector("pressedMouseButtons")) + } + + unsafe fn doubleClickInterval(_: Self) -> NSTimeInterval { + msg_send()(class("NSEvent"), selector("doubleClickInterval")) + } + + unsafe fn mouseLocation(_: Self) -> NSPoint { + msg_send_stret()(class("NSEvent"), selector("mouseLocation")) + } + + unsafe fn buttonNumber(self) -> NSInteger { + msg_send()(self, selector("buttonNumber")) + } + + unsafe fn clickCount(self) -> NSInteger { + msg_send()(self, selector("clickCount")) + } + + unsafe fn pressure(self) -> libc::c_float { + msg_send()(self, selector("pressure")) + } + + unsafe fn setMouseCoalescingEnabled_(_: Self, flag: BOOL) { + msg_send()(class("NSEvent"), selector("setMouseCoalescingEnabled:"), flag as libc::c_int) + } + + unsafe fn isMouseCoalescingEnabled(_: Self) -> BOOL { + msg_send()(class("NSEvent"), selector("isMouseCoalescingEnabled")) + } + + // Getting Mouse-Tracking Event Information + + unsafe fn eventNumber(self) -> NSInteger { + msg_send()(self, selector("eventNumber")) + } + + unsafe fn trackingNumber(self) -> NSInteger { + msg_send()(self, selector("trackingNumber")) + } + + unsafe fn trackingArea(self) -> id /* (NSTrackingArea *) */ { + msg_send()(self, selector("trackingArea")) + } + + unsafe fn userData(self) -> *const libc::c_void { + msg_send()(self, selector("userData")) + } + + // Getting Custom Event Information + + unsafe fn data1(self) -> NSInteger { + msg_send()(self, selector("data1")) + } + + unsafe fn data2(self) -> NSInteger { + msg_send()(self, selector("data2")) + } + + unsafe fn subtype(self) -> NSEventSubtype { + msg_send()(self, selector("subtype")) + } + + // Getting Scroll Wheel Event Information + + unsafe fn deltaX(self) -> CGFloat { + msg_send()(self, selector("deltaX")) + } + + unsafe fn deltaY(self) -> CGFloat { + msg_send()(self, selector("deltaY")) + } + + unsafe fn deltaZ(self) -> CGFloat { + msg_send()(self, selector("deltaZ")) + } + + // Getting Tablet Proximity Information + + unsafe fn capabilityMask(self) -> NSUInteger { + msg_send()(self, selector("capabilityMask")) + } + + unsafe fn deviceID(self) -> NSUInteger { + msg_send()(self, selector("deviceID")) + } + + unsafe fn pointingDeviceID(self) -> NSUInteger { + msg_send()(self, selector("pointingDeviceID")) + } + + unsafe fn pointingDeviceSerialNumber(self) -> NSUInteger { + msg_send()(self, selector("pointingDeviceSerialNumber")) + } + + unsafe fn pointingDeviceType(self) -> NSPointingDeviceType { + msg_send()(self, selector("pointingDeviceType")) + } + + unsafe fn systemTabletID(self) -> NSUInteger { + msg_send()(self, selector("systemTabletID")) + } + + unsafe fn tabletID(self) -> NSUInteger { + msg_send()(self, selector("tabletID")) + } + + unsafe fn uniqueID(self) -> libc::c_ulonglong { + msg_send()(self, selector("uniqueID")) + } + + unsafe fn vendorID(self) -> NSUInteger { + msg_send()(self, selector("vendorID")) + } + + unsafe fn vendorPointingDeviceType(self) -> NSUInteger { + msg_send()(self, selector("vendorPointingDeviceType")) + } + + // Getting Tablet Pointing Information + + unsafe fn absoluteX(self) -> NSInteger { + msg_send()(self, selector("absoluteX")) + } + + unsafe fn absoluteY(self) -> NSInteger { + msg_send()(self, selector("absoluteY")) + } + + unsafe fn absoluteZ(self) -> NSInteger { + msg_send()(self, selector("absoluteZ")) + } + + unsafe fn buttonMask(self) -> NSEventButtonMask { + msg_send()(self, selector("buttonMask")) + } + + unsafe fn rotation(self) -> libc::c_float { + msg_send()(self, selector("rotation")) + } + + unsafe fn tangentialPressure(self) -> libc::c_float { + msg_send()(self, selector("tangentialPressure")) + } + + unsafe fn tilt(self) -> NSPoint { + msg_send_stret()(self, selector("tilt")) + } + + unsafe fn vendorDefined(self) -> id { + msg_send()(self, selector("vendorDefined")) + } + + // Requesting and Stopping Periodic Events + + unsafe fn startPeriodicEventsAfterDelay_withPeriod_(_: Self, delaySeconds: NSTimeInterval, periodSeconds: NSTimeInterval) { + msg_send()(class("NSEvent"), selector("startPeriodicEventsAfterDelay:withPeriod:"), delaySeconds, periodSeconds) + } + + unsafe fn stopPeriodicEvents(_: Self) { + msg_send()(class("NSEvent"), selector("stopPeriodicEvents")) + } + + // Getting Touch and Gesture Information + + unsafe fn magnification(self) -> CGFloat { + msg_send()(self, selector("magnification")) + } + + unsafe fn touchesMatchingPhase_inView_(self, phase: NSTouchPhase, view: id /* (NSView *) */) -> id /* (NSSet *) */ { + msg_send()(self, selector("touchesMatchingPhase:inView:"), phase, view) + } + + unsafe fn isSwipeTrackingFromScrollEventsEnabled(_: Self) -> BOOL { + msg_send()(class("NSEvent"), selector("isSwipeTrackingFromScrollEventsEnabled")) + } + + // Monitoring Application Events + + // TODO: addGlobalMonitorForEventsMatchingMask_handler_ (unsure how to bind to blocks) + // TODO: addLocalMonitorForEventsMatchingMask_handler_ (unsure how to bind to blocks) + + unsafe fn removeMonitor_(_: Self, eventMonitor: id) { + msg_send()(class("NSEvent"), selector("removeMonitor:"), eventMonitor) + } + + // Scroll Wheel and Flick Events + + unsafe fn hasPreciseScrollingDeltas(self) -> BOOL { + msg_send()(self, selector("hasPreciseScrollingDeltas")) + } + + unsafe fn scrollingDeltaX(self) -> CGFloat { + msg_send()(self, selector("scrollingDeltaX")) } unsafe fn scrollingDeltaY(self) -> CGFloat { msg_send()(self, selector("scrollingDeltaY")) } + + unsafe fn momentumPhase(self) -> NSEventPhase { + msg_send()(self, selector("momentumPhase")) + } + + unsafe fn phase(self) -> NSEventPhase { + msg_send()(self, selector("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) + } } pub trait NSScreen { From e11ad6e5250c02b82c0c4c10b9e4b7302d49db9d Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 26 Jan 2015 20:40:18 +1100 Subject: [PATCH 122/249] Add NSScreen methods --- src/appkit.rs | 81 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 984022b..a0daac7 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -373,6 +373,8 @@ impl NSMenuItem for id { } } +pub type NSWindowDepth = libc::c_int; + bitflags! { flags NSWindowCollectionBehavior: NSUInteger { const NSWindowCollectionBehaviorDefault = 0, @@ -2125,14 +2127,87 @@ impl NSEvent for id { } pub trait NSScreen { - unsafe fn mainScreen(_: Self) -> id { - msg_send()(class("NSScreen"), selector("mainScreen")) - } + // Getting NSScreen Objects + unsafe fn mainScreen(_: Self) -> id /* (NSScreen *) */; + unsafe fn deepestScreen(_: Self) -> id /* (NSScreen *) */; + unsafe fn screens(_: Self) -> id /* (NSArray *) */; + + // Getting Screen Information + unsafe fn depth(self) -> NSWindowDepth; unsafe fn frame(self) -> NSRect; + unsafe fn supportedWindowDepths(self) -> *const NSWindowDepth; + unsafe fn deviceDescription(self) -> id /* (NSDictionary *) */; + unsafe fn visibleFrame(self) -> NSRect; + unsafe fn colorSpace(self) -> id /* (NSColorSpace *) */; + unsafe fn screensHaveSeparateSpaces(_: Self) -> BOOL; + + // Screen Backing Coordinate Conversion + unsafe fn backingAlignedRect_options_(self, aRect: NSRect, options: NSAlignmentOptions) -> NSRect; + unsafe fn backingScaleFactor(self) -> CGFloat; + unsafe fn convertRectFromBacking_(self, aRect: NSRect) -> NSRect; + unsafe fn convertRectToBacking_(self, aRect: NSRect) -> NSRect; } impl NSScreen for id { + // Getting NSScreen Objects + + unsafe fn mainScreen(_: Self) -> id /* (NSScreen *) */ { + msg_send()(class("NSScreen"), selector("mainScreen")) + } + + unsafe fn deepestScreen(_: Self) -> id /* (NSScreen *) */ { + msg_send()(class("NSScreen"), selector("deepestScreen")) + } + + unsafe fn screens(_: Self) -> id /* (NSArray *) */ { + msg_send()(class("NSScreen"), selector("screens")) + } + + // Getting Screen Information + + unsafe fn depth(self) -> NSWindowDepth { + msg_send()(self, selector("depth")) + } + unsafe fn frame(self) -> NSRect { msg_send_stret()(self, selector("frame")) } + + unsafe fn supportedWindowDepths(self) -> *const NSWindowDepth { + msg_send()(self, selector("supportedWindowDepths")) + } + + unsafe fn deviceDescription(self) -> id /* (NSDictionary *) */ { + msg_send()(self, selector("deviceDescription")) + } + + unsafe fn visibleFrame(self) -> NSRect { + msg_send_stret()(self, selector("visibleFrame")) + } + + unsafe fn colorSpace(self) -> id /* (NSColorSpace *) */ { + msg_send()(self, selector("colorSpace")) + } + + unsafe fn screensHaveSeparateSpaces(_: Self) -> BOOL { + msg_send()(class("NSScreen"), selector("screensHaveSeparateSpaces")) + } + + // Screen Backing Coordinate Conversion + + unsafe fn backingAlignedRect_options_(self, aRect: NSRect, options: NSAlignmentOptions) -> NSRect { + msg_send_stret()(self, selector("backingAlignedRect:options:"), aRect, options) + } + + unsafe fn backingScaleFactor(self) -> CGFloat { + msg_send()(self, selector("backingScaleFactor")) + } + + unsafe fn convertRectFromBacking_(self, aRect: NSRect) -> NSRect { + msg_send_stret()(self, selector("convertRectFromBacking:"), aRect) + } + + unsafe fn convertRectToBacking_(self, aRect: NSRect) -> NSRect { + msg_send_stret()(self, selector("convertRectToBacking:"), aRect) + } } From 9b440504558ce13daad100e5e730f4eec47ac7c3 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Thu, 29 Jan 2015 21:24:27 +1100 Subject: [PATCH 123/249] Use standard indentation --- src/appkit.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index a0daac7..22c4192 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -86,10 +86,10 @@ impl NSRect { // Same as CGRectEdge #[repr(u32)] pub enum NSRectEdge { - NSRectMinXEdge, - NSRectMinYEdge, - NSRectMaxXEdge, - NSRectMaxYEdge, + NSRectMinXEdge, + NSRectMinYEdge, + NSRectMaxXEdge, + NSRectMaxYEdge, } #[link(name = "AppKit", kind = "framework")] @@ -1357,9 +1357,9 @@ bitflags! { #[repr(i64)] // NSInteger pub enum NSEventGestureAxis { - NSEventGestureAxisNone = 0, - NSEventGestureAxisHorizontal, - NSEventGestureAxisVertical, + NSEventGestureAxisNone = 0, + NSEventGestureAxisHorizontal, + NSEventGestureAxisVertical, } bitflags! { From d298baced60c0972a0ec56924c2bb4848413eeb9 Mon Sep 17 00:00:00 2001 From: Rafael Barbosa Date: Sun, 1 Feb 2015 19:04:35 +0000 Subject: [PATCH 124/249] first method bindings for NSTabView and NSTabViewItem --- examples/tab_view.rs | 85 ++++++++++++++++++++++++++++++++++++++++++++ src/appkit.rs | 53 +++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 examples/tab_view.rs diff --git a/examples/tab_view.rs b/examples/tab_view.rs new file mode 100644 index 0000000..6bad430 --- /dev/null +++ b/examples/tab_view.rs @@ -0,0 +1,85 @@ +extern crate cocoa; + +use cocoa::base::{NSUInteger, selector, nil, YES, NO}; +use cocoa::appkit::{NSApp, NSRect, NSPoint, NSSize, + NSAutoreleasePool, NSProcessInfo, + NSApplication, NSApplicationActivationPolicyRegular, + NSWindow, NSTitledWindowMask, NSBackingStoreBuffered, + NSClosableWindowMask,NSResizableWindowMask,NSMiniaturizableWindowMask,NSUnifiedTitleAndToolbarWindowMask, + NSString, + NSMenu, NSMenuItem, + NSTabView, NSTabViewItem}; + + +fn main() { + unsafe { + + // create a tab View + let tab_view = NSTabView::new(nil).initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.))); + + // create a tab view item + let tab_view_item = NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView1\0")); + + tab_view_item.setLabel_(NSString::alloc(nil).init_str("Tab view item 1 \0")); + tab_view.addTabViewItem_(tab_view_item); + + //create a second tab view item + let tab_view_item2 = NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView2\0")); + + tab_view_item2.setLabel_(NSString::alloc(nil).init_str("Tab view item 2 \0")); + tab_view.addTabViewItem_(tab_view_item2); + + //Create the app and set the content. + let app = create_app(NSString::alloc(nil).init_str("Tab View\0"),tab_view); + app.run(); + } +} + +unsafe fn create_app(title:i64,content:i64) -> i64{ + let _pool = NSAutoreleasePool::new(nil); + + let app = NSApp(); + app.setActivationPolicy_(NSApplicationActivationPolicyRegular); + + // create Menu Bar + let menubar = NSMenu::new(nil).autorelease(); + let app_menu_item = NSMenuItem::new(nil).autorelease(); + menubar.addItem_(app_menu_item); + app.setMainMenu_(menubar); + + // create Application menu + let app_menu = NSMenu::new(nil).autorelease(); + let quit_prefix = NSString::alloc(nil).init_str("Quit \0"); + 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_item = NSMenuItem::alloc(nil).initWithTitle_action_keyEquivalent_( + quit_title, + quit_action, + quit_key + ).autorelease(); + app_menu.addItem_(quit_item); + app_menu_item.setSubmenu_(app_menu); + + // create Window + let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_( + NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), + NSTitledWindowMask as NSUInteger | NSClosableWindowMask as NSUInteger | NSResizableWindowMask as NSUInteger | NSMiniaturizableWindowMask as NSUInteger | NSUnifiedTitleAndToolbarWindowMask as NSUInteger, + NSBackingStoreBuffered, + NO + ).autorelease(); + window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); + window.center(); + + window.setTitle_(title); + window.makeKeyAndOrderFront_(nil); + + window.setContentView_(content); + + app.activateIgnoringOtherApps_(YES); + return app; +} + + diff --git a/src/appkit.rs b/src/appkit.rs index 22c4192..2471c9f 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -2211,3 +2211,56 @@ impl NSScreen for id { msg_send_stret()(self, selector("convertRectToBacking:"), aRect) } } + +pub trait NSTabView { + unsafe fn new(_: Self) -> id { + msg_send()(class("NSTabView"), selector("new")) + } + unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; + unsafe fn addTabViewItem_(self, tab_view_item: id); + unsafe fn insertTabViewItem_atIndex_(self,tab_view_item:id, index:NSInteger); + unsafe fn removeTabViewItem_(self,tab_view_item:id); +} + +impl NSTabView for id { + + unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { + msg_send()(self, selector("initWithFrame:"), frameRect) + } + + unsafe fn addTabViewItem_(self, tab_view_item: id) { + msg_send()(self, selector("addTabViewItem:"), tab_view_item) + } + unsafe fn insertTabViewItem_atIndex_(self, tab_view_item: id,index:NSInteger) { + msg_send()(self, selector("addTabViewItem:atIndex:"), tab_view_item,index) + } + unsafe fn removeTabViewItem_(self,tab_view_item:id){ + msg_send()(self, selector("removeTabViewItem:"), tab_view_item) + } + +} + +pub trait NSTabViewItem { + unsafe fn alloc(_: Self) -> id { + msg_send()(class("NSTabViewItem"), selector("alloc")) + } + + unsafe fn new(_: Self) -> id { + msg_send()(class("NSTabViewItem"), selector("new")) + } + + + unsafe fn initWithIdentifier_(self, identifier:id) -> id; + unsafe fn setLabel_(self,label:id); +} + +impl NSTabViewItem for id { + + unsafe fn initWithIdentifier_(self, identifier: id) -> id { + msg_send()(self, selector("initWithIdentifier:"), identifier) + } + + unsafe fn setLabel_(self,label : id){ + msg_send()(self, selector("setLabel:"), label) + } +} \ No newline at end of file From 7f9b8db9ae6946799645dfa772b7f19fa3f2ea3a Mon Sep 17 00:00:00 2001 From: Rafael Barbosa Date: Sun, 1 Feb 2015 23:23:27 +0000 Subject: [PATCH 125/249] added a few more methods to NSTabView and all the methods to NSTabViewItem --- examples/tab_view.rs | 4 +- src/appkit.rs | 201 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+), 1 deletion(-) diff --git a/examples/tab_view.rs b/examples/tab_view.rs index 6bad430..726a1fd 100644 --- a/examples/tab_view.rs +++ b/examples/tab_view.rs @@ -8,7 +8,7 @@ use cocoa::appkit::{NSApp, NSRect, NSPoint, NSSize, NSClosableWindowMask,NSResizableWindowMask,NSMiniaturizableWindowMask,NSUnifiedTitleAndToolbarWindowMask, NSString, NSMenu, NSMenuItem, - NSTabView, NSTabViewItem}; + NSTabView, NSTabViewItem,NSTabViewType}; fn main() { @@ -17,6 +17,8 @@ fn main() { // create a tab View let tab_view = NSTabView::new(nil).initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.))); + tab_view.setTabViewType_(NSTabViewType::NSBottomTabsBezelBorder); + // create a tab view item let tab_view_item = NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView1\0")); diff --git a/src/appkit.rs b/src/appkit.rs index 2471c9f..ea6f6f6 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -2212,6 +2212,17 @@ impl NSScreen for id { } } +#[repr(u64)] +pub enum NSTabViewType { + NSTopTabsBezelBorder = 0, + NSLeftTabsBezelBorder = 1, + NSBottomTabsBezelBorder = 2, + NSRightTabsBezelBorder = 3, + NSNoTabsBezelBorder = 4, + NSNoTabsLineBorder = 5, + NSNoTabsNoBorder = 6 +} + pub trait NSTabView { unsafe fn new(_: Self) -> id { msg_send()(class("NSTabView"), selector("new")) @@ -2220,6 +2231,42 @@ pub trait NSTabView { unsafe fn addTabViewItem_(self, tab_view_item: id); unsafe fn insertTabViewItem_atIndex_(self,tab_view_item:id, index:NSInteger); unsafe fn removeTabViewItem_(self,tab_view_item:id); + + unsafe fn indexOfTabViewItem_(self, tab_view_item:id) -> id; + unsafe fn indexOfTabViewItemWithIdentifier_(self,identifier:id) -> id; + unsafe fn numberOfTabViewItems(self) -> id; + unsafe fn tabViewItemAtIndex_(self,index:id)->id; + + unsafe fn tabViewItems(self)->id; + + unsafe fn selectFirstTabViewItem_(self,sender:id); + unsafe fn selectLastTabViewItem_(self,sender:id); + unsafe fn selectNextTabViewItem_(self, sender:id); + unsafe fn selectPreviousTabViewItem_(self,sender:id); + unsafe fn selectTabViewItem_(self,tab_view_item:id); + unsafe fn selectTabViewItemAtIndex_(self,index:id); + unsafe fn selectTabViewItemWithIdentifier_(self,identifier:id); + unsafe fn selectedTabViewItem(self) -> id; + unsafe fn takeSelectedTabViewItemFromSender_(self,sender:id); + + unsafe fn font(self)->id; + unsafe fn setFont_(self, font:id); + + unsafe fn tabViewType(self)->NSTabViewType; + unsafe fn setTabViewType_(self,tabViewType: NSTabViewType); + + /*unsafe fn controlTint(self)->id; + unsafe fn setControlTint_(self,controlTint:id); + + unsafe fn drawsBackground(self)->BOOL; + unsafe fn setDrawsBackground_(self,drawsBackground:BOOL); + + unsafe fn minimumSize(self) -> id; + unsafe fn contentRect(self) -> id; + unsafe fn controlSize(self) -> id; + unsafe fn setControlSize_(self,controlSize:id); + */ + } impl NSTabView for id { @@ -2238,6 +2285,78 @@ impl NSTabView for id { msg_send()(self, selector("removeTabViewItem:"), tab_view_item) } + unsafe fn indexOfTabViewItem_(self, tab_view_item:id) -> id{ + msg_send()(self,selector("indexOfTabViewItem:"),tab_view_item) + } + + unsafe fn indexOfTabViewItemWithIdentifier_(self,identifier:id) -> id{ + msg_send()(self,selector("indexOfTabViewItemWithIdentifier:"),identifier) + } + unsafe fn numberOfTabViewItems(self) -> id{ + msg_send()(self,selector("numberOfTabViewItems")) + } + + unsafe fn tabViewItemAtIndex_(self,index:id)->id{ + msg_send()(self,selector("tabViewItemAtIndex:"),index) + } + + unsafe fn tabViewItems(self)->id{ + msg_send()(self,selector("tabViewItems")) + } + + unsafe fn selectFirstTabViewItem_(self,sender:id){ + msg_send()(self,selector("selectFirstTabViewItem:"),sender) + } + + unsafe fn selectLastTabViewItem_(self,sender:id){ + msg_send()(self,selector("selectLastTabViewItem:"),sender) + } + unsafe fn selectNextTabViewItem_(self, sender:id){ + msg_send()(self,selector("selectNextTabViewItem:"),sender) + } + unsafe fn selectPreviousTabViewItem_(self,sender:id){ + msg_send()(self,selector("selectPreviousTabViewItem:"),sender) + } + + unsafe fn selectTabViewItem_(self,tab_view_item:id){ + msg_send()(self,selector("selectTabViewItem:"),tab_view_item) + } + + unsafe fn selectTabViewItemAtIndex_(self,index:id){ + msg_send()(self,selector("selectTabViewItemAtIndex:"),index) + } + unsafe fn selectTabViewItemWithIdentifier_(self,identifier:id){ + msg_send()(self,selector("selectTabViewItemWithIdentifier:"),identifier) + } + unsafe fn selectedTabViewItem(self) -> id{ + msg_send()(self,selector("selectedTabViewItem")) + } + unsafe fn takeSelectedTabViewItemFromSender_(self,sender:id){ + msg_send()(self,selector("takeSelectedTabViewItemFromSender:"),sender) + } + + unsafe fn font(self)->id{ + msg_send()(self,selector("font")) + } + + unsafe fn setFont_(self, font:id){ + msg_send()(self,selector("setFont:"),font) + } + + unsafe fn tabViewType(self)->NSTabViewType{ + msg_send()(self,selector("tabViewType")) + } + unsafe fn setTabViewType_(self,tabViewType: NSTabViewType){ + msg_send()(self,selector("setTabViewType:"),tabViewType) + } + +} + +#[repr(u64)] +pub enum NSTabState { + NSSelectedTab = 0, + NSBackgroundTab = 1, + NSPressedTab = 2 } pub trait NSTabViewItem { @@ -2251,7 +2370,30 @@ pub trait NSTabViewItem { unsafe fn initWithIdentifier_(self, identifier:id) -> id; + + unsafe fn drawLabel_inRect_(self,shouldTruncateLabel:BOOL,labelRect:NSRect); + unsafe fn label(self) -> id; unsafe fn setLabel_(self,label:id); + unsafe fn sizeOfLabel_(self, computeMin:BOOL); + + unsafe fn tabState(self) -> NSTabState; + + unsafe fn identifier(self)-> id; + unsafe fn setIdentifier_(self,identifier:id); + + unsafe fn color(self)-> id; + unsafe fn setColor_(self,color:id); + + unsafe fn view(self) -> id; + unsafe fn setView_(self, view:id); + + unsafe fn initialFirstResponder(self)->id; + unsafe fn setInitialFirstResponder_(self,initialFirstResponder:id); + + unsafe fn tabView(self) -> id; + + unsafe fn tooltip(self) -> id; + unsafe fn setTooltip_(self,toolTip:id); } impl NSTabViewItem for id { @@ -2260,7 +2402,66 @@ impl NSTabViewItem for id { msg_send()(self, selector("initWithIdentifier:"), identifier) } + unsafe fn drawLabel_inRect_(self, shouldTruncateLabel:BOOL,labelRect:NSRect){ + msg_send()(self,selector("drawLabel:inRect:"),shouldTruncateLabel as libc::c_int,labelRect) + } + + unsafe fn label(self)->id{ + msg_send()(self, selector("label")) + } unsafe fn setLabel_(self,label : id){ msg_send()(self, selector("setLabel:"), label) } + + unsafe fn sizeOfLabel_(self,computeMin:BOOL){ + msg_send()(self,selector("sizeOfLabel:"),computeMin as libc::c_int) + } + + unsafe fn tabState(self) -> NSTabState{ + msg_send()(self,selector("tabState")) + } + + unsafe fn identifier(self)-> id { + msg_send()(self,selector("identifier")) + } + + unsafe fn setIdentifier_(self,identifier:id){ + msg_send()(self,selector("identifier:"),identifier) + } + + unsafe fn color(self)-> id{ + msg_send()(self,selector("color")) + } + + unsafe fn setColor_(self,color:id){ + msg_send()(self,selector("color:"),color) + } + + unsafe fn view(self) -> id { + msg_send()(self,selector("view")) + } + + unsafe fn setView_(self, view:id){ + msg_send()(self,selector("setView:"),view) + } + + unsafe fn initialFirstResponder(self)->id{ + msg_send()(self,selector("initialFirstResponder")) + } + + unsafe fn setInitialFirstResponder_(self,initialFirstResponder:id){ + msg_send()(self,selector("setInitialFirstResponder:"),initialFirstResponder) + } + + unsafe fn tabView(self) -> id{ + msg_send()(self,selector("tabView")) + } + + unsafe fn tooltip(self) -> id{ + msg_send()(self,selector("tooltip")) + } + + unsafe fn setTooltip_(self,toolTip:id){ + msg_send()(self,selector("setTooltip:"),toolTip) + } } \ No newline at end of file From cab89193ad9175d770c8747dfb91b547119cff8d Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 4 Feb 2015 07:58:02 +1100 Subject: [PATCH 126/249] Use correct msg_send function --- src/appkit.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 22c4192..5cbc58c 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1033,7 +1033,7 @@ impl NSWindow for id { } unsafe fn mouseLocationOutsideOfEventStream(self) -> NSPoint { - msg_send_stret()(self, selector("mouseLocationOutsideOfEventStream")) + msg_send()(self, selector("mouseLocationOutsideOfEventStream")) } unsafe fn setAcceptsMouseMovedEvents_(self, acceptMouseMovedEvents: BOOL) { @@ -1847,7 +1847,7 @@ impl NSEvent for id { } unsafe fn locationInWindow(self) -> NSPoint { - msg_send_stret()(self, selector("locationInWindow")) + msg_send()(self, selector("locationInWindow")) } unsafe fn modifierFlags(self) -> NSEventModifierFlags { @@ -1918,7 +1918,7 @@ impl NSEvent for id { } unsafe fn mouseLocation(_: Self) -> NSPoint { - msg_send_stret()(class("NSEvent"), selector("mouseLocation")) + msg_send()(class("NSEvent"), selector("mouseLocation")) } unsafe fn buttonNumber(self) -> NSInteger { @@ -2056,7 +2056,7 @@ impl NSEvent for id { } unsafe fn tilt(self) -> NSPoint { - msg_send_stret()(self, selector("tilt")) + msg_send()(self, selector("tilt")) } unsafe fn vendorDefined(self) -> id { From 9b542ec8c3a00d38c6caef379c8e262b249139e8 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 4 Feb 2015 07:58:36 +1100 Subject: [PATCH 127/249] Use correct selector name --- src/appkit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appkit.rs b/src/appkit.rs index 5cbc58c..52b65fd 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1860,7 +1860,7 @@ impl NSEvent for id { // NOTE: renamed from `- type` due to Rust keyword collision unsafe fn event_type(self) -> NSEventType { - msg_send()(self, selector("event_type")) + msg_send()(self, selector("type")) } unsafe fn window(self) -> id /* (NSWindow *) */ { From 5c2a2b2a9ecdb1c91db5ba24dacfbdc5686f2967 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 4 Feb 2015 07:58:54 +1100 Subject: [PATCH 128/249] Use consistent naming style --- src/appkit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 52b65fd..b73efe0 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1635,7 +1635,7 @@ pub trait NSEvent { unsafe fn modifierFlags(self) -> NSEventModifierFlags; unsafe fn timestamp(self) -> NSTimeInterval; // NOTE: renamed from `- type` due to Rust keyword collision - unsafe fn event_type(self) -> NSEventType; + unsafe fn eventType(self) -> NSEventType; unsafe fn window(self) -> id /* (NSWindow *) */; unsafe fn windowNumber(self) -> NSInteger; unsafe fn eventRef(self) -> *const libc::c_void; @@ -1859,7 +1859,7 @@ impl NSEvent for id { } // NOTE: renamed from `- type` due to Rust keyword collision - unsafe fn event_type(self) -> NSEventType { + unsafe fn eventType(self) -> NSEventType { msg_send()(self, selector("type")) } From cbab45e9086082fc5d5ee0ea0c3ecf67b46aaeec Mon Sep 17 00:00:00 2001 From: tomaka Date: Fri, 6 Feb 2015 20:36:34 +0100 Subject: [PATCH 129/249] Use libc from crates.io --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index de25f59..9643938 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,4 @@ crate-type = ["rlib"] [dependencies] bitflags = "0.1" +libc = "*" From 1f7d210a01f7e1aa2590f70b0b469f3b6b58bb0e Mon Sep 17 00:00:00 2001 From: Rafael Barbosa Date: Sat, 7 Feb 2015 22:36:57 +0000 Subject: [PATCH 130/249] Modified the tab_view example --- examples/tab_view.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/tab_view.rs b/examples/tab_view.rs index 726a1fd..6bad430 100644 --- a/examples/tab_view.rs +++ b/examples/tab_view.rs @@ -8,7 +8,7 @@ use cocoa::appkit::{NSApp, NSRect, NSPoint, NSSize, NSClosableWindowMask,NSResizableWindowMask,NSMiniaturizableWindowMask,NSUnifiedTitleAndToolbarWindowMask, NSString, NSMenu, NSMenuItem, - NSTabView, NSTabViewItem,NSTabViewType}; + NSTabView, NSTabViewItem}; fn main() { @@ -17,8 +17,6 @@ fn main() { // create a tab View let tab_view = NSTabView::new(nil).initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.))); - tab_view.setTabViewType_(NSTabViewType::NSBottomTabsBezelBorder); - // create a tab view item let tab_view_item = NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView1\0")); From 750666e1c92ee297d6b2b25e4c2e5979fa3cb400 Mon Sep 17 00:00:00 2001 From: Rafael Barbosa Date: Sat, 7 Feb 2015 22:42:07 +0000 Subject: [PATCH 131/249] corrected naming style --- src/appkit.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 6c2d7fe..3e7e898 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -2228,11 +2228,11 @@ pub trait NSTabView { msg_send()(class("NSTabView"), selector("new")) } unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; - unsafe fn addTabViewItem_(self, tab_view_item: id); - unsafe fn insertTabViewItem_atIndex_(self,tab_view_item:id, index:NSInteger); - unsafe fn removeTabViewItem_(self,tab_view_item:id); + unsafe fn addTabViewItem_(self, tabViewItem: id); + unsafe fn insertTabViewItem_atIndex_(self,tabViewItem:id, index:NSInteger); + unsafe fn removeTabViewItem_(self,tabViewItem:id); - unsafe fn indexOfTabViewItem_(self, tab_view_item:id) -> id; + unsafe fn indexOfTabViewItem_(self, tabViewItem:id) -> id; unsafe fn indexOfTabViewItemWithIdentifier_(self,identifier:id) -> id; unsafe fn numberOfTabViewItems(self) -> id; unsafe fn tabViewItemAtIndex_(self,index:id)->id; @@ -2243,7 +2243,7 @@ pub trait NSTabView { unsafe fn selectLastTabViewItem_(self,sender:id); unsafe fn selectNextTabViewItem_(self, sender:id); unsafe fn selectPreviousTabViewItem_(self,sender:id); - unsafe fn selectTabViewItem_(self,tab_view_item:id); + unsafe fn selectTabViewItem_(self,tabViewItem:id); unsafe fn selectTabViewItemAtIndex_(self,index:id); unsafe fn selectTabViewItemWithIdentifier_(self,identifier:id); unsafe fn selectedTabViewItem(self) -> id; @@ -2275,18 +2275,18 @@ impl NSTabView for id { msg_send()(self, selector("initWithFrame:"), frameRect) } - unsafe fn addTabViewItem_(self, tab_view_item: id) { - msg_send()(self, selector("addTabViewItem:"), tab_view_item) + unsafe fn addTabViewItem_(self, tabViewItem: id) { + msg_send()(self, selector("addTabViewItem:"), tabViewItem) } - unsafe fn insertTabViewItem_atIndex_(self, tab_view_item: id,index:NSInteger) { - msg_send()(self, selector("addTabViewItem:atIndex:"), tab_view_item,index) + unsafe fn insertTabViewItem_atIndex_(self, tabViewItem: id,index:NSInteger) { + msg_send()(self, selector("addTabViewItem:atIndex:"), tabViewItem,index) } - unsafe fn removeTabViewItem_(self,tab_view_item:id){ - msg_send()(self, selector("removeTabViewItem:"), tab_view_item) + unsafe fn removeTabViewItem_(self,tabViewItem:id){ + msg_send()(self, selector("removeTabViewItem:"), tabViewItem) } - unsafe fn indexOfTabViewItem_(self, tab_view_item:id) -> id{ - msg_send()(self,selector("indexOfTabViewItem:"),tab_view_item) + unsafe fn indexOfTabViewItem_(self, tabViewItem:id) -> id{ + msg_send()(self,selector("indexOfTabViewItem:"),tabViewItem) } unsafe fn indexOfTabViewItemWithIdentifier_(self,identifier:id) -> id{ @@ -2318,8 +2318,8 @@ impl NSTabView for id { msg_send()(self,selector("selectPreviousTabViewItem:"),sender) } - unsafe fn selectTabViewItem_(self,tab_view_item:id){ - msg_send()(self,selector("selectTabViewItem:"),tab_view_item) + unsafe fn selectTabViewItem_(self,tabViewItem:id){ + msg_send()(self,selector("selectTabViewItem:"),tabViewItem) } unsafe fn selectTabViewItemAtIndex_(self,index:id){ From 18e93cbc5f263a448c9ef6cb7fe485a650779579 Mon Sep 17 00:00:00 2001 From: Rafael Barbosa Date: Sat, 7 Feb 2015 23:15:56 +0000 Subject: [PATCH 132/249] implemented the rest of the NSTabView methods --- src/appkit.rs | 67 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 3e7e898..ccb8417 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -2235,9 +2235,9 @@ pub trait NSTabView { unsafe fn indexOfTabViewItem_(self, tabViewItem:id) -> id; unsafe fn indexOfTabViewItemWithIdentifier_(self,identifier:id) -> id; unsafe fn numberOfTabViewItems(self) -> id; - unsafe fn tabViewItemAtIndex_(self,index:id)->id; + unsafe fn tabViewItemAtIndex_(self,index:id) -> id; - unsafe fn tabViewItems(self)->id; + unsafe fn tabViewItems(self) -> id; unsafe fn selectFirstTabViewItem_(self,sender:id); unsafe fn selectLastTabViewItem_(self,sender:id); @@ -2249,23 +2249,31 @@ pub trait NSTabView { unsafe fn selectedTabViewItem(self) -> id; unsafe fn takeSelectedTabViewItemFromSender_(self,sender:id); - unsafe fn font(self)->id; + unsafe fn font(self) -> id; unsafe fn setFont_(self, font:id); - unsafe fn tabViewType(self)->NSTabViewType; + unsafe fn tabViewType(self) -> NSTabViewType; unsafe fn setTabViewType_(self,tabViewType: NSTabViewType); - /*unsafe fn controlTint(self)->id; + unsafe fn controlTint(self) -> id; unsafe fn setControlTint_(self,controlTint:id); - unsafe fn drawsBackground(self)->BOOL; + unsafe fn drawsBackground(self) -> BOOL; unsafe fn setDrawsBackground_(self,drawsBackground:BOOL); unsafe fn minimumSize(self) -> id; unsafe fn contentRect(self) -> id; unsafe fn controlSize(self) -> id; unsafe fn setControlSize_(self,controlSize:id); - */ + + unsafe fn allowsTruncatedLabels(self) -> BOOL; + unsafe fn setAllowsTruncatedLabels_(self, allowTruncatedLabels:BOOL); + + unsafe fn setDelegate_(self, delegate:id); + unsafe fn delegate(self) -> id ; + + unsafe fn tabViewAtPoint_(self, point:id) -> id; + } @@ -2350,6 +2358,51 @@ impl NSTabView for id { msg_send()(self,selector("setTabViewType:"),tabViewType) } + unsafe fn controlTint(self) -> id{ + msg_send()(self,selector("controlTint")) + } + unsafe fn setControlTint_(self,controlTint:id){ + msg_send()(self,selector("setControlTint:"),controlTint) + } + + unsafe fn drawsBackground(self) -> BOOL{ + msg_send()(self,selector("drawsBackground")) + } + unsafe fn setDrawsBackground_(self,drawsBackground:BOOL){ + msg_send()(self,selector("setDrawsBackground:"),drawsBackground) + } + + unsafe fn minimumSize(self) -> id{ + msg_send()(self,selector("minimumSize")) + } + unsafe fn contentRect(self) -> id{ + msg_send()(self,selector("contentRect")) + } + unsafe fn controlSize(self) -> id{ + msg_send()(self,selector("controlSize")) + } + unsafe fn setControlSize_(self,controlSize:id){ + msg_send()(self,selector("setControlSize:"),controlSize) + } + + unsafe fn allowsTruncatedLabels(self) -> BOOL{ + msg_send()(self,selector("allowsTruncatedLabels")) + } + unsafe fn setAllowsTruncatedLabels_(self, allowTruncatedLabels:BOOL){ + msg_send()(self,selector("setAllowsTruncatedLabels:"),allowTruncatedLabels) + } + + unsafe fn setDelegate_(self, delegate:id){ + msg_send()(self,selector("setDelegate:"),delegate) + } + unsafe fn delegate(self) -> id { + msg_send()(self,selector("delegate")) + } + + unsafe fn tabViewAtPoint_(self, point:id) -> id{ + msg_send()(self,selector("tabViewAtPoint:"),point) + } + } #[repr(u64)] From a346846fd8042913590a43c74fff108015d3f4b6 Mon Sep 17 00:00:00 2001 From: Rafael Barbosa Date: Sat, 7 Feb 2015 23:20:43 +0000 Subject: [PATCH 133/249] Forgot the as libc::c_int in the BOOL parameters --- src/appkit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index ccb8417..f4dd76e 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -2369,7 +2369,7 @@ impl NSTabView for id { msg_send()(self,selector("drawsBackground")) } unsafe fn setDrawsBackground_(self,drawsBackground:BOOL){ - msg_send()(self,selector("setDrawsBackground:"),drawsBackground) + msg_send()(self,selector("setDrawsBackground:"),drawsBackground as libc::c_int) } unsafe fn minimumSize(self) -> id{ @@ -2389,7 +2389,7 @@ impl NSTabView for id { msg_send()(self,selector("allowsTruncatedLabels")) } unsafe fn setAllowsTruncatedLabels_(self, allowTruncatedLabels:BOOL){ - msg_send()(self,selector("setAllowsTruncatedLabels:"),allowTruncatedLabels) + msg_send()(self,selector("setAllowsTruncatedLabels:"),allowTruncatedLabels as libc::c_int) } unsafe fn setDelegate_(self, delegate:id){ From f7c8ef9d62a6460e6998e5e26623a3da9b650717 Mon Sep 17 00:00:00 2001 From: Skyler Lipthay Date: Sun, 8 Feb 2015 01:18:26 -0800 Subject: [PATCH 134/249] Silence warnings by adding `std_misc` and `hash` features and removing the `unstable` warning allowance. --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 9fd21ce..2e2a48f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,8 @@ #![crate_name = "cocoa"] #![crate_type = "rlib"] -#![allow(missing_copy_implementations, non_snake_case, unstable)] +#![allow(missing_copy_implementations, non_snake_case)] +#![feature(std_misc, hash)] #[macro_use] extern crate bitflags; From 7a2e87a0df659ed51a4b4135e5289aeb3a5e5582 Mon Sep 17 00:00:00 2001 From: Skyler Lipthay Date: Sun, 8 Feb 2015 01:29:11 -0800 Subject: [PATCH 135/249] Flushed out the entirety of the Objective-C runtime. Added some extra documentation. --- src/base.rs | 240 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 213 insertions(+), 27 deletions(-) diff --git a/src/base.rs b/src/base.rs index 8be58e6..6dd81cb 100644 --- a/src/base.rs +++ b/src/base.rs @@ -7,28 +7,39 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use libc::c_char; use libc; - -use std::ffi::CString; +use std::ffi; use std::mem; +pub type Category = libc::intptr_t; pub type Class = libc::intptr_t; -pub type IMP = extern "C" fn(id, SEL) -> id; -pub type Ivar = libc::intptr_t; -pub type SEL = libc::intptr_t; #[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; #[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 = "32")] +#[allow(non_camel_case_types)] +pub type ptrdiff_t = libc::c_int; #[cfg(target_pointer_width = "64")] pub type NSInteger = libc::c_long; #[cfg(target_pointer_width = "64")] pub type NSUInteger = libc::c_ulong; +#[cfg(target_pointer_width = "64")] +#[allow(non_camel_case_types)] +pub type ptrdiff_t = libc::c_long; #[allow(non_upper_case_globals)] pub const nil: id = 0; @@ -36,42 +47,217 @@ pub const nil: id = 0; pub const Nil: Class = 0 as Class; pub type BOOL = libc::c_schar; - -pub const YES: BOOL = 1; 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_addMethod(cls: Class, name: SEL, imp: IMP, types: *const libc::c_char) -> bool; + 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: u8, - types: *const libc::c_char) - -> bool; - pub fn object_setInstanceVariable(obj: id, name: *const libc::c_char, value: *mut libc::c_void); - pub fn object_getInstanceVariable(obj: id, name: *const libc::c_char, outValue: *mut *mut libc::c_void); - pub fn objc_allocateClassPair(superclass: Class, name: *const libc::c_char, extraBytes: libc::size_t) - -> 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, ...); + 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) -> 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_ftret(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`. -pub unsafe fn msg_send() -> extern fn(theReceiver: id, theSelector: SEL, ...) -> 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) } -pub unsafe fn msg_send_stret() -> extern fn(theReceiver: id, theSelector: SEL, ...) -> T { +/// 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) -> id { - let name_c_str = CString::from_slice(name.as_bytes()); +pub fn class(name: &str) -> Class { + let name_c_str = ffi::CString::from_slice(name.as_bytes()); unsafe { objc_getClass(name_c_str.as_ptr()) } @@ -80,7 +266,7 @@ pub fn class(name: &str) -> id { /// 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 = CString::from_slice(name.as_bytes()); + let name_c_str = ffi::CString::from_slice(name.as_bytes()); unsafe { sel_registerName(name_c_str.as_ptr()) } @@ -89,7 +275,7 @@ pub fn selector(name: &str) -> SEL { #[cfg(test)] mod test { use libc; - use std::ffi::CString; + use std::ffi; use super::*; #[test] @@ -107,13 +293,13 @@ mod test { } let ns_object = class("NSObject"); - let name_c_str = CString::from_slice("MyObject".as_bytes()); + 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 = CString::from_slice("@@:".as_bytes()); + let types_c_str = ffi::CString::from_slice("@@:".as_bytes()); unsafe { let _ = class_addMethod(my_object, doSomething, MyObject_doSomething, types_c_str.as_ptr()); From d23a4a177fb8a29557957df5d4f9266d4be829f1 Mon Sep 17 00:00:00 2001 From: Skyler Lipthay Date: Sun, 8 Feb 2015 17:16:40 -0800 Subject: [PATCH 136/249] Use libc::ptrdiff_t instead of defining ptrdiff_t manually --- src/base.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/base.rs b/src/base.rs index 6dd81cb..a7d389e 100644 --- a/src/base.rs +++ b/src/base.rs @@ -29,17 +29,11 @@ pub type SEL = libc::intptr_t; pub type NSInteger = libc::c_int; #[cfg(target_pointer_width = "32")] pub type NSUInteger = libc::c_uint; -#[cfg(target_pointer_width = "32")] -#[allow(non_camel_case_types)] -pub type ptrdiff_t = libc::c_int; #[cfg(target_pointer_width = "64")] pub type NSInteger = libc::c_long; #[cfg(target_pointer_width = "64")] pub type NSUInteger = libc::c_ulong; -#[cfg(target_pointer_width = "64")] -#[allow(non_camel_case_types)] -pub type ptrdiff_t = libc::c_long; #[allow(non_upper_case_globals)] pub const nil: id = 0; @@ -122,7 +116,7 @@ extern { 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) -> ptrdiff_t; + 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; From c4b1941432a43acbf9492aea74629f88a8b2c72c Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 9 Feb 2015 19:38:56 +1100 Subject: [PATCH 137/249] Add NSOpenGLContext methods --- src/appkit.rs | 91 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 85 insertions(+), 6 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index b73efe0..af9457c 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -27,6 +27,8 @@ 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)] @@ -1305,33 +1307,110 @@ pub trait NSOpenGLContext { msg_send()(class("NSOpenGLContext"), selector("alloc")) } - unsafe fn initWithFormat_shareContext_(self, format: id, shareContext: id) -> id; - unsafe fn setView_(self, view: id); + // Context Creation + unsafe fn initWithFormat_shareContext_(self, format: id /* (NSOpenGLPixelFormat *) */, shareContext: id /* (NSOpenGLContext *) */) -> id /* (instancetype) */; + unsafe fn initWithCGLContextObj_(self, context: CGLContextObj) -> id /* (instancetype) */; + + // Managing the Current Context + unsafe fn clearCurrentContext(_: Self); + unsafe fn currentContext(_: Self) -> id /* (NSOpenGLContext *) */; unsafe fn makeCurrentContext(self); + + // Drawable Object Management + unsafe fn setView_(self, view: id /* (NSView *) */); + unsafe fn view(self) -> id /* (NSView *) */; + unsafe fn clearDrawable(self); + unsafe fn update(self); + + // Flushing the Drawing Buffer unsafe fn flushBuffer(self); + + // Context Parameter Handling unsafe fn setValues_forParameter_(self, vals: *const GLint, param: NSOpenGLContextParameter); + unsafe fn getValues_forParameter_(self, vals: *mut GLint, param: NSOpenGLContextParameter); + + // Working with Virtual Screens + unsafe fn setCurrentVirtualScreen_(self, screen: GLint); + unsafe fn currentVirtualScreen(self) -> GLint; + + // Getting the CGL Context Object + unsafe fn CGLContextObj(self) -> CGLContextObj; } impl NSOpenGLContext for id { - unsafe fn initWithFormat_shareContext_(self, format: id, shareContext: id) -> id { - msg_send()(self, selector("initWithFormat:shareContext:"), format, shareContext) + // Context Creation + + unsafe fn initWithFormat_shareContext_(self, format: id /* (NSOpenGLPixelFormat *) */, shareContext: id /* (NSOpenGLContext *) */) -> id /* (instancetype) */ { + msg_send()(class("NSOpenGLContext"), selector("initWithFormat_shareContext:"), format, shareContext) } - unsafe fn setView_(self, view: id) { - msg_send()(self, selector("setView:"), view) + unsafe fn initWithCGLContextObj_(self, context: CGLContextObj) -> id /* (instancetype) */ { + msg_send()(class("NSOpenGLContext"), selector("initWithCGLContextObj:"), context) + } + + // Managing the Current Context + + unsafe fn clearCurrentContext(_: Self) { + msg_send()(class("NSOpenGLContext"), selector("clearCurrentContext")) + } + + unsafe fn currentContext(_: Self) -> id /* (NSOpenGLContext *) */ { + msg_send()(class("NSOpenGLContext"), selector("currentContext")) } unsafe fn makeCurrentContext(self) { msg_send()(self, selector("makeCurrentContext")) } + // Drawable Object Management + + unsafe fn setView_(self, view: id /* (NSView *) */) { + msg_send()(self, selector("setView:"), view) + } + + unsafe fn view(self) -> id /* (NSView *) */ { + msg_send()(self, selector("view")) + } + + unsafe fn clearDrawable(self) { + msg_send()(self, selector("clearDrawable")) + } + + unsafe fn update(self) { + msg_send()(self, selector("update")) + } + + // Flushing the Drawing Buffer + unsafe fn flushBuffer(self) { msg_send()(self, selector("flushBuffer")) } + // Context Parameter Handling + unsafe fn setValues_forParameter_(self, vals: *const GLint, param: NSOpenGLContextParameter) { msg_send()(self, selector("setValues:forParameter:"), vals, param) } + + unsafe fn getValues_forParameter_(self, vals: *mut GLint, param: NSOpenGLContextParameter) { + msg_send()(self, selector("getValues:forParameter:"), vals, param) + } + + // Working with Virtual Screens + + unsafe fn setCurrentVirtualScreen_(self, screen: GLint) { + msg_send()(self, selector("setCurrentVirtualScreen:"), screen) + } + + unsafe fn currentVirtualScreen(self) -> GLint { + msg_send()(self, selector("currentVirtualScreen")) + } + + // Getting the CGL Context Object + + unsafe fn CGLContextObj(self) -> CGLContextObj { + msg_send()(self, selector("CGLContextObj")) + } } pub trait NSDate { From 587657ec8e467f8f23893f783566d85ea159a6ec Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 10 Feb 2015 08:48:32 +1100 Subject: [PATCH 138/249] Fix silly copy-paste mistake Fixes #67. --- src/appkit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appkit.rs b/src/appkit.rs index af9457c..45855d7 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1341,7 +1341,7 @@ 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()(class("NSOpenGLContext"), selector("initWithFormat:shareContext:"), format, shareContext) } unsafe fn initWithCGLContextObj_(self, context: CGLContextObj) -> id /* (instancetype) */ { From 3c737a9f1663a190942ce0424ecbe706ca2d6315 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 10 Feb 2015 20:05:18 +1100 Subject: [PATCH 139/249] 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 140/249] 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 141/249] 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 142/249] 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 143/249] 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 144/249] 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 145/249] 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 146/249] 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 147/249] 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 148/249] 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 149/249] 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 150/249] 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 151/249] 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 152/249] 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 153/249] 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 154/249] 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 155/249] 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 156/249] 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 157/249] 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 158/249] 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 159/249] 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 160/249] 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 161/249] 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 162/249] 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 163/249] 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 164/249] 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 165/249] 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 166/249] 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 167/249] 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 168/249] 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 169/249] 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 170/249] 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 171/249] 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 172/249] 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 173/249] 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 174/249] 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 175/249] 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 176/249] 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 177/249] 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 178/249] 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 179/249] 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 180/249] 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 181/249] 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 182/249] 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 183/249] 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 184/249] 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 185/249] 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 186/249] 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 187/249] 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 188/249] 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 189/249] 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 190/249] 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 191/249] 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 192/249] 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 193/249] 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 194/249] 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 195/249] 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 196/249] 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 197/249] 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 198/249] 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 199/249] 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 200/249] 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 201/249] 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 202/249] 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 203/249] 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 204/249] 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 205/249] 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 206/249] 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 207/249] 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 208/249] 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 209/249] 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 210/249] 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 211/249] 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 212/249] 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 213/249] 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 0b07a7962d0fa4807e0f3f040b7e5053d3e05486 Mon Sep 17 00:00:00 2001 From: George Burton Date: Sat, 9 Jul 2016 11:27:09 +0100 Subject: [PATCH 214/249] Add NSDictionary + tests, define NSComparator and NSComparisonResult --- src/foundation.rs | 302 ++++++++++++++++++++++++++++++++++++++++++++ tests/foundation.rs | 78 ++++++++++++ 2 files changed, 380 insertions(+) diff --git a/src/foundation.rs b/src/foundation.rs index d2bcbee..68d2c03 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -228,6 +228,308 @@ impl NSArray for id { } } +pub trait NSDictionary { + unsafe fn dictionary(_: Self) -> id { + msg_send![class("NSDictionary"), dictionary] + } + + unsafe fn dictionaryWithContentsOfFile_(_: Self, path: id) -> id { + msg_send![class("NSDictionary"), dictionaryWithContentsOfFile:path] + } + + unsafe fn dictionaryWithContentsOfURL_(_: Self, aURL: id) -> id { + msg_send![class("NSDictionary"), dictionaryWithContentsOfURL:aURL] + } + + unsafe fn dictionaryWithDictionary_(_: Self, otherDictionary: id) -> id { + msg_send![class("NSDictionary"), dictionaryWithDictionary:otherDictionary] + } + + unsafe fn dictionaryWithObject_forKey_(_: Self, anObject: id, aKey: id) -> id { + msg_send![class("NSDictionary"), dictionaryWithObject:anObject forKey:aKey] + } + + unsafe fn dictionaryWithObjects_forKeys_(_: Self, objects: id, keys: id) -> id { + msg_send![class("NSDictionary"), dictionaryWithObjects:objects forKeys:keys] + } + + unsafe fn dictionaryWithObjects_forKeys_count_(_: Self, objects: *const id, keys: *const id, count: NSUInteger) -> id { + msg_send![class("NSDictionary"), dictionaryWithObjects:objects forKeys:keys count:count] + } + + unsafe fn dictionaryWithObjectsAndKeys_(_: Self, firstObject: id) -> id { + msg_send![class("NSDictionary"), dictionaryWithObjectsAndKeys:firstObject] + } + + unsafe fn init(self) -> id; + unsafe fn initWithContentsOfFile_(self, path: id) -> id; + unsafe fn initWithContentsOfURL_(self, aURL: id) -> id; + unsafe fn initWithDictionary_(self, otherDicitonary: id) -> id; + unsafe fn initWithDictionary_copyItems_(self, otherDicitonary: id, flag: BOOL) -> id; + unsafe fn initWithObjects_forKeys_(self, objects: id, keys: id) -> id; + unsafe fn initWithObjects_forKeys_count_(self, objects: id, keys: id, count: NSUInteger) -> id; + unsafe fn initWithObjectsAndKeys_(self, firstObject: id) -> id; + + unsafe fn sharedKeySetForKeys_(_: Self, keys: id) -> id { + msg_send![class("NSDictionary"), sharedKeySetForKeys:keys] + } + + unsafe fn count(self) -> NSUInteger; + + unsafe fn isEqualToDictionary_(self, otherDictionary: id) -> BOOL; + + unsafe fn allKeys(self) -> id; + unsafe fn allKeysForObject_(self, anObject: id) -> id; + unsafe fn allValues(self) -> id; + unsafe fn objectForKey_(self, aKey: id) -> id; + unsafe fn objectForKeyedSubscript_(self, key: id) -> id; + unsafe fn objectsForKeys_notFoundMarker_(self, keys: id, anObject: id) -> id; + unsafe fn valueForKey_(self, key: id) -> id; + + unsafe fn keyEnumerator(self) -> id; + unsafe fn objectEnumerator(self) -> id; + unsafe fn enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut BOOL), ()>); + unsafe fn enumerateKeysAndObjectsWithOptions_usingBlock_(self, opts: NSEnumerationOptions, + block: *mut Block<(id, id, *mut BOOL), ()>); + + unsafe fn keysSortedByValueUsingSelector_(self, comparator: SEL) -> id; + unsafe fn keysSortedByValueUsingComparator_(self, cmptr: NSComparator) -> id; + unsafe fn keysSortedByValueWithOptions_usingComparator_(self, opts: NSEnumerationOptions, cmptr: NSComparator) -> id; + + unsafe fn keysOfEntriesPassingTest_(self, predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id; + unsafe fn keysOfEntriesWithOptions_PassingTest_(self, opts: NSEnumerationOptions, + predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id; + + unsafe fn writeToFile_atomically_(self, path: id, flag: BOOL) -> BOOL; + unsafe fn writeToURL_atomically_(self, aURL: id, flag: BOOL) -> BOOL; + + unsafe fn fileCreationDate(self) -> id; + unsafe fn fileExtensionHidden(self) -> BOOL; + unsafe fn fileGroupOwnerAccountID(self) -> id; + unsafe fn fileGroupOwnerAccountName(self) -> id; + unsafe fn fileIsAppendOnly(self) -> BOOL; + unsafe fn fileIsImmutable(self) -> BOOL; + unsafe fn fileModificationDate(self) -> id; + unsafe fn fileOwnerAccountID(self) -> id; + unsafe fn fileOwnerAccountName(self) -> id; + unsafe fn filePosixPermissions(self) -> NSUInteger; + unsafe fn fileSize(self) -> libc::c_ulonglong; + unsafe fn fileSystemFileNumber(self) -> NSUInteger; + unsafe fn fileSystemNumber(self) -> NSInteger; + unsafe fn fileType(self) -> id; + + unsafe fn description(self) -> id; + unsafe fn descriptionInStringsFileFormat(self) -> id; + unsafe fn descriptionWithLocale_(self, locale: id) -> id; + unsafe fn descriptionWithLocale_indent_(self, locale: id, indent: NSUInteger) -> id; +} + +impl NSDictionary for id { + unsafe fn init(self) -> id { + msg_send![self, init] + } + + unsafe fn initWithContentsOfFile_(self, path: id) -> id { + msg_send![self, initWithContentsOfFile:path] + } + + unsafe fn initWithContentsOfURL_(self, aURL: id) -> id { + msg_send![self, initWithContentsOfURL:aURL] + } + + unsafe fn initWithDictionary_(self, otherDictionary: id) -> id { + msg_send![self, initWithDictionary:otherDictionary] + } + + unsafe fn initWithDictionary_copyItems_(self, otherDictionary: id, flag: BOOL) -> id { + msg_send![self, initWithDictionary:otherDictionary copyItems:flag] + } + + unsafe fn initWithObjects_forKeys_(self, objects: id, keys: id) -> id { + msg_send![self, initWithObjects:objects forKeys:keys] + } + + unsafe fn initWithObjects_forKeys_count_(self, objects: id, keys: id, count: NSUInteger) -> id { + msg_send![self, initWithObjects:objects forKeys:keys count:count] + } + + unsafe fn initWithObjectsAndKeys_(self, firstObject: id) -> id { + msg_send![self, initWithObjectsAndKeys:firstObject] + } + + unsafe fn count(self) -> NSUInteger { + msg_send![self, count] + } + + unsafe fn isEqualToDictionary_(self, otherDictionary: id) -> BOOL { + msg_send![self, isEqualToDictionary:otherDictionary] + } + + unsafe fn allKeys(self) -> id { + msg_send![self, allKeys] + } + + unsafe fn allKeysForObject_(self, anObject: id) -> id { + msg_send![self, allKeysForObject:anObject] + } + + unsafe fn allValues(self) -> id { + msg_send![self, allValues] + } + + unsafe fn objectForKey_(self, aKey: id) -> id { + msg_send![self, objectForKey:aKey] + } + + unsafe fn objectForKeyedSubscript_(self, key: id) -> id { + msg_send![self, objectForKeyedSubscript:key] + } + + unsafe fn objectsForKeys_notFoundMarker_(self, keys: id, anObject: id) -> id { + msg_send![self, objectsForKeys:keys notFoundMarker:anObject] + } + + unsafe fn valueForKey_(self, key: id) -> id { + msg_send![self, valueForKey:key] + } + + unsafe fn keyEnumerator(self) -> id { + msg_send![self, keyEnumerator] + } + + unsafe fn objectEnumerator(self) -> id { + msg_send![self, objectEnumerator] + } + + unsafe fn enumerateKeysAndObjectsUsingBlock_(self, block: *mut Block<(id, id, *mut BOOL), ()>) { + msg_send![self, enumerateKeysAndObjectsUsingBlock:block] + } + + unsafe fn enumerateKeysAndObjectsWithOptions_usingBlock_(self, opts: NSEnumerationOptions, + block: *mut Block<(id, id, *mut BOOL), ()>) { + msg_send![self, enumerateKeysAndObjectsWithOptions:opts usingBlock:block] + } + + unsafe fn keysSortedByValueUsingSelector_(self, comparator: SEL) -> id { + msg_send![self, keysSortedByValueUsingSelector:comparator] + } + + unsafe fn keysSortedByValueUsingComparator_(self, cmptr: NSComparator) -> id { + msg_send![self, keysSortedByValueUsingComparator:cmptr] + } + + unsafe fn keysSortedByValueWithOptions_usingComparator_(self, opts: NSEnumerationOptions, cmptr: NSComparator) -> id { + let rv: id = msg_send![self, keysSortedByValueWithOptions:opts usingComparator:cmptr]; + rv + } + + unsafe fn keysOfEntriesPassingTest_(self, predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id { + msg_send![self, keysOfEntriesPassingTest:predicate] + } + + unsafe fn keysOfEntriesWithOptions_PassingTest_(self, opts: NSEnumerationOptions, + predicate: *mut Block<(id, id, *mut BOOL), BOOL>) -> id { + msg_send![self, keysOfEntriesWithOptions:opts PassingTest:predicate] + } + + unsafe fn writeToFile_atomically_(self, path: id, flag: BOOL) -> BOOL { + msg_send![self, writeToFile:path atomically:flag] + } + + unsafe fn writeToURL_atomically_(self, aURL: id, flag: BOOL) -> BOOL { + msg_send![self, writeToURL:aURL atomically:flag] + } + + unsafe fn fileCreationDate(self) -> id { + msg_send![self, fileCreationDate] + } + + unsafe fn fileExtensionHidden(self) -> BOOL { + msg_send![self, fileExtensionHidden] + } + + unsafe fn fileGroupOwnerAccountID(self) -> id { + msg_send![self, fileGroupOwnerAccountID] + } + + unsafe fn fileGroupOwnerAccountName(self) -> id { + msg_send![self, fileGroupOwnerAccountName] + } + + unsafe fn fileIsAppendOnly(self) -> BOOL { + msg_send![self, fileIsAppendOnly] + } + + unsafe fn fileIsImmutable(self) -> BOOL { + msg_send![self, fileIsImmutable] + } + + unsafe fn fileModificationDate(self) -> id { + msg_send![self, fileModificationDate] + } + + unsafe fn fileOwnerAccountID(self) -> id { + msg_send![self, fileOwnerAccountID] + } + + unsafe fn fileOwnerAccountName(self) -> id { + msg_send![self, fileOwnerAccountName] + } + + unsafe fn filePosixPermissions(self) -> NSUInteger { + msg_send![self, filePosixPermissions] + } + + unsafe fn fileSize(self) -> libc::c_ulonglong { + msg_send![self, fileSize] + } + + unsafe fn fileSystemFileNumber(self) -> NSUInteger { + msg_send![self, fileSystemFileNumber] + } + + unsafe fn fileSystemNumber(self) -> NSInteger { + msg_send![self, fileSystemNumber] + } + + unsafe fn fileType(self) -> id { + msg_send![self, fileType] + } + + unsafe fn description(self) -> id { + msg_send![self, description] + } + + unsafe fn descriptionInStringsFileFormat(self) -> id { + msg_send![self, descriptionInStringsFileFormat] + } + + unsafe fn descriptionWithLocale_(self, locale: id) -> id { + msg_send![self, descriptionWithLocale:locale] + } + + unsafe fn descriptionWithLocale_indent_(self, locale: id, indent: NSUInteger) -> id { + msg_send![self, descriptionWithLocale:locale indent:indent] + } +} + +bitflags! { + pub flags NSEnumerationOptions: libc::c_ulonglong { + const NSEnumerationConcurrent = 1 << 0, + const NSEnumerationReverse = 1 << 1 + } +} + +pub type NSComparator = *mut Block<(id, id), NSComparisonResult>; + +#[repr(isize)] +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum NSComparisonResult { + NSOrderedAscending = -1, + NSOrderedSame = 0, + NSOrderedDescending = 1 +} + pub trait NSString { unsafe fn alloc(_: Self) -> id { msg_send![class("NSString"), alloc] diff --git a/tests/foundation.rs b/tests/foundation.rs index af6fbc5..5be8e6c 100644 --- a/tests/foundation.rs +++ b/tests/foundation.rs @@ -1,5 +1,6 @@ #[macro_use] extern crate objc; +extern crate block; extern crate cocoa; #[cfg(test)] @@ -98,4 +99,81 @@ mod foundation { } } } + + mod nsdictionary { + use block::ConcreteBlock; + use cocoa::foundation::{NSArray, NSComparisonResult, NSDictionary, NSFastEnumeration, NSString}; + use cocoa::base::{id, nil}; + + #[test] + fn test_get() { + const KEY: &'static str = "The key"; + const VALUE: &'static str = "Some value"; + unsafe { + let key = NSString::alloc(nil).init_str(KEY); + let value = NSString::alloc(nil).init_str(VALUE); + let dict = NSDictionary::dictionaryWithObject_forKey_(nil, value, key); + + let retrieved_value = dict.objectForKey_(key); + assert!(retrieved_value.isEqualToString(VALUE)); + } + } + + #[test] + fn test_iter() { + let mkstr = |s| unsafe { NSString::alloc(nil).init_str(s) }; + let keys = vec!["a", "b", "c", "d", "e", "f"]; + let objects = vec!["1", "2", "3", "4", "5", "6"]; + unsafe { + use std::{slice, str}; + use std::cmp::{Ord, Ordering}; + + let keys_raw_vec = keys.clone().into_iter().map(&mkstr).collect::>(); + let objs_raw_vec = objects.clone().into_iter().map(&mkstr).collect::>(); + + let keys_array = NSArray::arrayWithObjects(nil, &keys_raw_vec); + let objs_array = NSArray::arrayWithObjects(nil, &objs_raw_vec); + + let dict = NSDictionary::dictionaryWithObjects_forKeys_(nil, objs_array, keys_array); + + // NSDictionary does not store its contents in order of insertion, so ask for + // sorted iterators to ensure that each item is the same as its counterpart in + // the vector. + + // First test cocoa sorting... + let mut comparator = ConcreteBlock::new(|s0: id, s1: id| { + let (bytes0, len0) = (s0.UTF8String() as *const u8, s0.len()); + let (bytes1, len1) = (s1.UTF8String() as *const u8, s1.len()); + let (s0, s1) = (str::from_utf8(slice::from_raw_parts(bytes0, len0)).unwrap(), + str::from_utf8(slice::from_raw_parts(bytes1, len1)).unwrap()); + let (c0, c1) =(s0.chars().next().unwrap(), s1.chars().next().unwrap()); + match c0.cmp(&c1) { + Ordering::Less => NSComparisonResult::NSOrderedAscending, + Ordering::Equal => NSComparisonResult::NSOrderedSame, + Ordering::Greater => NSComparisonResult::NSOrderedDescending + } + }); + + let associated_iter = keys.iter().zip(objects.iter()); + for (k_id, (k, v)) in dict.keysSortedByValueUsingComparator_(&mut *comparator).iter().zip(associated_iter) { + assert!(k_id.isEqualToString(k)); + let v_id = dict.objectForKey_(k_id); + assert!(v_id.isEqualToString(v)); + } + + // Then use rust sorting + let mut keys_arr = dict.allKeys().iter().collect::>(); + keys_arr.sort(); + for (k0, k1) in keys_arr.into_iter().zip(keys.iter()) { + assert!(k0.isEqualToString(k1)); + } + + let mut objects_arr = dict.allValues().iter().collect::>(); + objects_arr.sort(); + for (v0, v1) in objects_arr.into_iter().zip(objects.iter()) { + assert!(v0.isEqualToString(v1)); + } + } + } + } } From 0b4616d1c3543e969fded27b51ad6ca507ae5cfc Mon Sep 17 00:00:00 2001 From: George Burton Date: Sun, 10 Jul 2016 10:35:14 +0100 Subject: [PATCH 215/249] 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 { From edcf333e8a395d20916b3c8f67f43b2d23b437c0 Mon Sep 17 00:00:00 2001 From: Rafael Barbosa Date: Tue, 26 Jul 2016 23:53:07 +0100 Subject: [PATCH 216/249] Updated the NSTabView and NSTabViewItem bindings to match the current codebase. Updated the tab_view example --- examples/tab_view.rs | 35 ++++++----- src/appkit.rs | 139 ++++++++++++++++++------------------------- 2 files changed, 77 insertions(+), 97 deletions(-) diff --git a/examples/tab_view.rs b/examples/tab_view.rs index 6bad430..28ca957 100644 --- a/examples/tab_view.rs +++ b/examples/tab_view.rs @@ -1,14 +1,18 @@ extern crate cocoa; -use cocoa::base::{NSUInteger, selector, nil, YES, NO}; -use cocoa::appkit::{NSApp, NSRect, NSPoint, NSSize, - NSAutoreleasePool, NSProcessInfo, +use cocoa::base::{selector,id, nil, NO}; + + +use cocoa::foundation::{NSUInteger,NSRect,NSPoint, NSSize, + NSAutoreleasePool,NSProcessInfo,NSString}; +use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, NSTitledWindowMask, NSBackingStoreBuffered, NSClosableWindowMask,NSResizableWindowMask,NSMiniaturizableWindowMask,NSUnifiedTitleAndToolbarWindowMask, - NSString, NSMenu, NSMenuItem, - NSTabView, NSTabViewItem}; + NSTabView, NSTabViewItem, + NSRunningApplication, + NSApplicationActivateIgnoringOtherApps}; fn main() { @@ -18,30 +22,30 @@ fn main() { let tab_view = NSTabView::new(nil).initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.))); // create a tab view item - let tab_view_item = NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView1\0")); + let tab_view_item = NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView1")); - tab_view_item.setLabel_(NSString::alloc(nil).init_str("Tab view item 1 \0")); + tab_view_item.setLabel_(NSString::alloc(nil).init_str("Tab view item 1")); tab_view.addTabViewItem_(tab_view_item); //create a second tab view item - let tab_view_item2 = NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView2\0")); + let tab_view_item2 = NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView2")); - tab_view_item2.setLabel_(NSString::alloc(nil).init_str("Tab view item 2 \0")); + tab_view_item2.setLabel_(NSString::alloc(nil).init_str("Tab view item 2")); tab_view.addTabViewItem_(tab_view_item2); //Create the app and set the content. - let app = create_app(NSString::alloc(nil).init_str("Tab View\0"),tab_view); + let app = create_app(NSString::alloc(nil).init_str("Tab View"),tab_view); app.run(); } } -unsafe fn create_app(title:i64,content:i64) -> i64{ +unsafe fn create_app(title:id,content:id) -> id{ let _pool = NSAutoreleasePool::new(nil); let app = NSApp(); app.setActivationPolicy_(NSApplicationActivationPolicyRegular); - // create Menu Bar + // create Menu Bar let menubar = NSMenu::new(nil).autorelease(); let app_menu_item = NSMenuItem::new(nil).autorelease(); menubar.addItem_(app_menu_item); @@ -49,12 +53,12 @@ unsafe fn create_app(title:i64,content:i64) -> i64{ // 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, @@ -77,8 +81,9 @@ unsafe fn create_app(title:i64,content:i64) -> i64{ window.makeKeyAndOrderFront_(nil); window.setContentView_(content); + let current_app = NSRunningApplication::currentApplication(nil); + current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); - app.activateIgnoringOtherApps_(YES); return app; } diff --git a/src/appkit.rs b/src/appkit.rs index fa7958e..5a6014b 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -3352,21 +3352,19 @@ pub enum NSTabViewType { } pub trait NSTabView { - unsafe fn new(_: Self) -> id { - msg_send()(class("NSTabView"), selector("new")) + unsafe fn new(_: Self) -> id { + msg_send![class("NSTabView"), new] } + unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; unsafe fn addTabViewItem_(self, tabViewItem: id); unsafe fn insertTabViewItem_atIndex_(self,tabViewItem:id, index:NSInteger); unsafe fn removeTabViewItem_(self,tabViewItem:id); - unsafe fn indexOfTabViewItem_(self, tabViewItem:id) -> id; unsafe fn indexOfTabViewItemWithIdentifier_(self,identifier:id) -> id; unsafe fn numberOfTabViewItems(self) -> id; unsafe fn tabViewItemAtIndex_(self,index:id) -> id; - unsafe fn tabViewItems(self) -> id; - unsafe fn selectFirstTabViewItem_(self,sender:id); unsafe fn selectLastTabViewItem_(self,sender:id); unsafe fn selectNextTabViewItem_(self, sender:id); @@ -3376,161 +3374,149 @@ pub trait NSTabView { unsafe fn selectTabViewItemWithIdentifier_(self,identifier:id); unsafe fn selectedTabViewItem(self) -> id; unsafe fn takeSelectedTabViewItemFromSender_(self,sender:id); - unsafe fn font(self) -> id; unsafe fn setFont_(self, font:id); - unsafe fn tabViewType(self) -> NSTabViewType; unsafe fn setTabViewType_(self,tabViewType: NSTabViewType); - unsafe fn controlTint(self) -> id; unsafe fn setControlTint_(self,controlTint:id); - unsafe fn drawsBackground(self) -> BOOL; unsafe fn setDrawsBackground_(self,drawsBackground:BOOL); - unsafe fn minimumSize(self) -> id; unsafe fn contentRect(self) -> id; unsafe fn controlSize(self) -> id; unsafe fn setControlSize_(self,controlSize:id); - unsafe fn allowsTruncatedLabels(self) -> BOOL; unsafe fn setAllowsTruncatedLabels_(self, allowTruncatedLabels:BOOL); - unsafe fn setDelegate_(self, delegate:id); unsafe fn delegate(self) -> id ; - unsafe fn tabViewAtPoint_(self, point:id) -> id; - - } impl NSTabView for id { - unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { - msg_send()(self, selector("initWithFrame:"), frameRect) + msg_send![self, initWithFrame:frameRect] } unsafe fn addTabViewItem_(self, tabViewItem: id) { - msg_send()(self, selector("addTabViewItem:"), tabViewItem) + msg_send![self, addTabViewItem:tabViewItem] } unsafe fn insertTabViewItem_atIndex_(self, tabViewItem: id,index:NSInteger) { - msg_send()(self, selector("addTabViewItem:atIndex:"), tabViewItem,index) + msg_send![self, addTabViewItem:tabViewItem atIndex:index] } unsafe fn removeTabViewItem_(self,tabViewItem:id){ - msg_send()(self, selector("removeTabViewItem:"), tabViewItem) + msg_send![self, removeTabViewItem:tabViewItem] } unsafe fn indexOfTabViewItem_(self, tabViewItem:id) -> id{ - msg_send()(self,selector("indexOfTabViewItem:"),tabViewItem) + msg_send![self, indexOfTabViewItem:tabViewItem] } unsafe fn indexOfTabViewItemWithIdentifier_(self,identifier:id) -> id{ - msg_send()(self,selector("indexOfTabViewItemWithIdentifier:"),identifier) + msg_send![self, indexOfTabViewItemWithIdentifier:identifier] } unsafe fn numberOfTabViewItems(self) -> id{ - msg_send()(self,selector("numberOfTabViewItems")) + msg_send![self, numberOfTabViewItems] } unsafe fn tabViewItemAtIndex_(self,index:id)->id{ - msg_send()(self,selector("tabViewItemAtIndex:"),index) + msg_send![self, tabViewItemAtIndex:index] } unsafe fn tabViewItems(self)->id{ - msg_send()(self,selector("tabViewItems")) + msg_send![self, tabViewItems] } unsafe fn selectFirstTabViewItem_(self,sender:id){ - msg_send()(self,selector("selectFirstTabViewItem:"),sender) + msg_send![self, selectFirstTabViewItem:sender] } unsafe fn selectLastTabViewItem_(self,sender:id){ - msg_send()(self,selector("selectLastTabViewItem:"),sender) + msg_send![self, selectLastTabViewItem:sender] } unsafe fn selectNextTabViewItem_(self, sender:id){ - msg_send()(self,selector("selectNextTabViewItem:"),sender) + msg_send![self, selectNextTabViewItem:sender] } unsafe fn selectPreviousTabViewItem_(self,sender:id){ - msg_send()(self,selector("selectPreviousTabViewItem:"),sender) + msg_send![self, selectPreviousTabViewItem:sender] } unsafe fn selectTabViewItem_(self,tabViewItem:id){ - msg_send()(self,selector("selectTabViewItem:"),tabViewItem) + msg_send![self, selectTabViewItem:tabViewItem] } unsafe fn selectTabViewItemAtIndex_(self,index:id){ - msg_send()(self,selector("selectTabViewItemAtIndex:"),index) + msg_send![self, selectTabViewItemAtIndex:index] } unsafe fn selectTabViewItemWithIdentifier_(self,identifier:id){ - msg_send()(self,selector("selectTabViewItemWithIdentifier:"),identifier) + msg_send![self, selectTabViewItemWithIdentifier:identifier] } unsafe fn selectedTabViewItem(self) -> id{ - msg_send()(self,selector("selectedTabViewItem")) + msg_send![self, selectedTabViewItem] } unsafe fn takeSelectedTabViewItemFromSender_(self,sender:id){ - msg_send()(self,selector("takeSelectedTabViewItemFromSender:"),sender) + msg_send![self, takeSelectedTabViewItemFromSender:sender] } unsafe fn font(self)->id{ - msg_send()(self,selector("font")) + msg_send![self, font] } unsafe fn setFont_(self, font:id){ - msg_send()(self,selector("setFont:"),font) + msg_send![self, setFont:font] } unsafe fn tabViewType(self)->NSTabViewType{ - msg_send()(self,selector("tabViewType")) + msg_send![self, tabViewType] } unsafe fn setTabViewType_(self,tabViewType: NSTabViewType){ - msg_send()(self,selector("setTabViewType:"),tabViewType) + msg_send![self, setTabViewType:tabViewType] } unsafe fn controlTint(self) -> id{ - msg_send()(self,selector("controlTint")) + msg_send![self, controlTint] } unsafe fn setControlTint_(self,controlTint:id){ - msg_send()(self,selector("setControlTint:"),controlTint) + msg_send![self, setControlTint:controlTint] } unsafe fn drawsBackground(self) -> BOOL{ - msg_send()(self,selector("drawsBackground")) + msg_send![self, drawsBackground] } unsafe fn setDrawsBackground_(self,drawsBackground:BOOL){ - msg_send()(self,selector("setDrawsBackground:"),drawsBackground as libc::c_int) + msg_send![self, setDrawsBackground:drawsBackground as libc::c_int] } unsafe fn minimumSize(self) -> id{ - msg_send()(self,selector("minimumSize")) + msg_send![self, minimumSize] } unsafe fn contentRect(self) -> id{ - msg_send()(self,selector("contentRect")) + msg_send![self, contentRect] } unsafe fn controlSize(self) -> id{ - msg_send()(self,selector("controlSize")) + msg_send![self, controlSize] } unsafe fn setControlSize_(self,controlSize:id){ - msg_send()(self,selector("setControlSize:"),controlSize) + msg_send![self, setControlSize:controlSize] } unsafe fn allowsTruncatedLabels(self) -> BOOL{ - msg_send()(self,selector("allowsTruncatedLabels")) + msg_send![self, allowsTruncatedLabels] } unsafe fn setAllowsTruncatedLabels_(self, allowTruncatedLabels:BOOL){ - msg_send()(self,selector("setAllowsTruncatedLabels:"),allowTruncatedLabels as libc::c_int) + msg_send![self, setAllowsTruncatedLabels:allowTruncatedLabels as libc::c_int] } unsafe fn setDelegate_(self, delegate:id){ - msg_send()(self,selector("setDelegate:"),delegate) + msg_send![self, setDelegate:delegate] } unsafe fn delegate(self) -> id { - msg_send()(self,selector("delegate")) + msg_send![self, delegate] } unsafe fn tabViewAtPoint_(self, point:id) -> id{ - msg_send()(self,selector("tabViewAtPoint:"),point) + msg_send![self, tabViewAtPoint:point] } - } #[repr(u64)] @@ -3542,107 +3528,96 @@ pub enum NSTabState { pub trait NSTabViewItem { unsafe fn alloc(_: Self) -> id { - msg_send()(class("NSTabViewItem"), selector("alloc")) + msg_send![class("NSTabViewItem"), alloc] } - unsafe fn new(_: Self) -> id { - msg_send()(class("NSTabViewItem"), selector("new")) + msg_send![class("NSTabViewItem"), new] } - unsafe fn initWithIdentifier_(self, identifier:id) -> id; - unsafe fn drawLabel_inRect_(self,shouldTruncateLabel:BOOL,labelRect:NSRect); unsafe fn label(self) -> id; unsafe fn setLabel_(self,label:id); unsafe fn sizeOfLabel_(self, computeMin:BOOL); - unsafe fn tabState(self) -> NSTabState; - unsafe fn identifier(self)-> id; unsafe fn setIdentifier_(self,identifier:id); - unsafe fn color(self)-> id; unsafe fn setColor_(self,color:id); - unsafe fn view(self) -> id; unsafe fn setView_(self, view:id); - unsafe fn initialFirstResponder(self)->id; unsafe fn setInitialFirstResponder_(self,initialFirstResponder:id); - unsafe fn tabView(self) -> id; - unsafe fn tooltip(self) -> id; unsafe fn setTooltip_(self,toolTip:id); } impl NSTabViewItem for id { - unsafe fn initWithIdentifier_(self, identifier: id) -> id { - msg_send()(self, selector("initWithIdentifier:"), identifier) + msg_send![self, initWithIdentifier:identifier] } unsafe fn drawLabel_inRect_(self, shouldTruncateLabel:BOOL,labelRect:NSRect){ - msg_send()(self,selector("drawLabel:inRect:"),shouldTruncateLabel as libc::c_int,labelRect) + msg_send![self, drawLabel:shouldTruncateLabel as libc::c_int inRect:labelRect] } unsafe fn label(self)->id{ - msg_send()(self, selector("label")) + msg_send![self, label] } unsafe fn setLabel_(self,label : id){ - msg_send()(self, selector("setLabel:"), label) + msg_send![self, setLabel:label] } unsafe fn sizeOfLabel_(self,computeMin:BOOL){ - msg_send()(self,selector("sizeOfLabel:"),computeMin as libc::c_int) + msg_send![self, sizeOfLabel:computeMin as libc::c_int] } unsafe fn tabState(self) -> NSTabState{ - msg_send()(self,selector("tabState")) + msg_send![self, tabState] } unsafe fn identifier(self)-> id { - msg_send()(self,selector("identifier")) + msg_send![self, identifier] } unsafe fn setIdentifier_(self,identifier:id){ - msg_send()(self,selector("identifier:"),identifier) + msg_send![self, identifier:identifier] } unsafe fn color(self)-> id{ - msg_send()(self,selector("color")) + msg_send![self, color] } unsafe fn setColor_(self,color:id){ - msg_send()(self,selector("color:"),color) + msg_send![self, color:color] } unsafe fn view(self) -> id { - msg_send()(self,selector("view")) + msg_send![self, view] } unsafe fn setView_(self, view:id){ - msg_send()(self,selector("setView:"),view) + msg_send![self, setView:view] } unsafe fn initialFirstResponder(self)->id{ - msg_send()(self,selector("initialFirstResponder")) + msg_send![self, initialFirstResponder] } unsafe fn setInitialFirstResponder_(self,initialFirstResponder:id){ - msg_send()(self,selector("setInitialFirstResponder:"),initialFirstResponder) + msg_send![self, setInitialFirstResponder:initialFirstResponder] } unsafe fn tabView(self) -> id{ - msg_send()(self,selector("tabView")) + msg_send![self, tabView] } unsafe fn tooltip(self) -> id{ - msg_send()(self,selector("tooltip")) + msg_send![self, tooltip] } unsafe fn setTooltip_(self,toolTip:id){ - msg_send()(self,selector("setTooltip:"),toolTip) + msg_send![self, setTooltip:toolTip] } } From ba799c0b2092ee1056b7ad7c6be667f6d4a93bd9 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 2 Aug 2016 09:46:07 +0200 Subject: [PATCH 217/249] Update core-graphics to 0.4 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2459ad0..ca98e1d 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.4" +version = "0.5.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -15,5 +15,5 @@ crate-type = ["rlib"] block = "0.1" bitflags = "0.7" libc = "0.2" -core-graphics = ">=0.2, <0.4" +core-graphics = "0.4" objc = "0.2" From 7cb21cfb61867976bbdf770236d9be8bbd6479cf Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Wed, 23 Nov 2016 00:10:51 -0500 Subject: [PATCH 218/249] Add UIKit classes and methods to support layout constraints. Written primarily for https://github.com/tomaka/winit/issues/80. --- src/appkit.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 5a6014b..d3d0a78 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1638,6 +1638,9 @@ pub trait NSView { unsafe fn setWantsLayer(self, wantsLayer: BOOL); unsafe fn layer(self) -> id; unsafe fn setLayer(self, layer: id); + + unsafe fn widthAnchor(self) -> id; + unsafe fn heightAnchor(self) -> id; } impl NSView for id { @@ -1700,6 +1703,14 @@ impl NSView for id { unsafe fn setLayer(self, layer: id) { msg_send![self, setLayer:layer] } + + unsafe fn widthAnchor(self) -> id { + msg_send![self, widthAnchor] + } + + unsafe fn heightAnchor(self) -> id { + msg_send![self, heightAnchor] + } } pub type NSAutoresizingMaskOptions = u64; @@ -3621,3 +3632,33 @@ impl NSTabViewItem for id { msg_send![self, setTooltip:toolTip] } } + +pub trait NSLayoutConstraint { + unsafe fn activateConstraints(_: Self, constraints: id) -> id; +} + +impl NSLayoutConstraint for id { + unsafe fn activateConstraints(_: Self, constraints: id) -> id { + msg_send![class("NSLayoutConstraint"), activateConstraints:constraints] + } +} + +pub trait NSLayoutDimension { + unsafe fn constraintEqualToConstant(self, c: CGFloat) -> id; + unsafe fn constraintLessThanOrEqualToConstant(self, c: CGFloat) -> id; + unsafe fn constraintGreaterThanOrEqualToConstant(self, c: CGFloat) -> id; +} + +impl NSLayoutDimension for id { + unsafe fn constraintEqualToConstant(self, c: CGFloat) -> id { + msg_send![self, constraintEqualToConstant:c] + } + + unsafe fn constraintLessThanOrEqualToConstant(self, c: CGFloat) -> id { + msg_send![self, constraintLessThanOrEqualToConstant:c] + } + + unsafe fn constraintGreaterThanOrEqualToConstant(self, c: CGFloat) -> id { + msg_send![self, constraintGreaterThanOrEqualToConstant:c] + } + } From 1c40b191f0816cc3fff314c8979e328ac6c96395 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Wed, 23 Nov 2016 00:15:19 -0500 Subject: [PATCH 219/249] Bump version to 0.5.1. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ca98e1d..7c5fdf2 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.5.0" +version = "0.5.1" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From 59fa67d90173d4bf6b9a0ac660fbadb8bd6ed808 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 26 Nov 2016 14:45:27 -0500 Subject: [PATCH 220/249] Run rustfmt on entire crate. --- examples/hello_world.rs | 90 +++++++++++++-------------- examples/tab_view.rs | 133 ++++++++++++++++++++-------------------- tests/foundation.rs | 36 +++++++---- 3 files changed, 132 insertions(+), 127 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 831e43f..4e44ff8 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,57 +1,53 @@ extern crate cocoa; use cocoa::base::{selector, nil, NO}; -use cocoa::foundation::{NSUInteger, NSRect, NSPoint, NSSize, - NSAutoreleasePool, NSProcessInfo, NSString}; -use cocoa::appkit::{NSApp, - NSApplication, NSApplicationActivationPolicyRegular, - NSWindow, NSTitledWindowMask, NSBackingStoreBuffered, - NSMenu, NSMenuItem, NSRunningApplication, - NSApplicationActivateIgnoringOtherApps}; +use cocoa::foundation::{NSUInteger, NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, + NSString}; +use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, + NSTitledWindowMask, NSBackingStoreBuffered, NSMenu, NSMenuItem, + NSRunningApplication, NSApplicationActivateIgnoringOtherApps}; fn main() { - unsafe { - let _pool = NSAutoreleasePool::new(nil); + unsafe { + let _pool = NSAutoreleasePool::new(nil); - let app = NSApp(); - app.setActivationPolicy_(NSApplicationActivationPolicyRegular); + let app = NSApp(); + app.setActivationPolicy_(NSApplicationActivationPolicyRegular); - // create Menu Bar - let menubar = NSMenu::new(nil).autorelease(); - let app_menu_item = NSMenuItem::new(nil).autorelease(); - menubar.addItem_(app_menu_item); - app.setMainMenu_(menubar); + // create Menu Bar + let menubar = NSMenu::new(nil).autorelease(); + let app_menu_item = NSMenuItem::new(nil).autorelease(); + menubar.addItem_(app_menu_item); + app.setMainMenu_(menubar); - // create Application menu - let app_menu = NSMenu::new(nil).autorelease(); - 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"); - let quit_item = NSMenuItem::alloc(nil).initWithTitle_action_keyEquivalent_( - quit_title, - quit_action, - quit_key - ).autorelease(); - app_menu.addItem_(quit_item); - app_menu_item.setSubmenu_(app_menu); + // create Application menu + let app_menu = NSMenu::new(nil).autorelease(); + 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"); + let quit_item = NSMenuItem::alloc(nil) + .initWithTitle_action_keyEquivalent_(quit_title, quit_action, quit_key) + .autorelease(); + app_menu.addItem_(quit_item); + app_menu_item.setSubmenu_(app_menu); - // create Window - let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_( - NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), - NSTitledWindowMask as NSUInteger, - NSBackingStoreBuffered, - NO - ).autorelease(); - window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); - window.center(); - let title = NSString::alloc(nil).init_str("Hello World!"); - window.setTitle_(title); - window.makeKeyAndOrderFront_(nil); - let current_app = NSRunningApplication::currentApplication(nil); - current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); - app.run(); - } + // create Window + let window = NSWindow::alloc(nil) + .initWithContentRect_styleMask_backing_defer_(NSRect::new(NSPoint::new(0., 0.), + NSSize::new(200., 200.)), + NSTitledWindowMask as NSUInteger, + NSBackingStoreBuffered, + NO) + .autorelease(); + window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); + window.center(); + let title = NSString::alloc(nil).init_str("Hello World!"); + window.setTitle_(title); + window.makeKeyAndOrderFront_(nil); + let current_app = NSRunningApplication::currentApplication(nil); + current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); + app.run(); + } } diff --git a/examples/tab_view.rs b/examples/tab_view.rs index 28ca957..51bb0be 100644 --- a/examples/tab_view.rs +++ b/examples/tab_view.rs @@ -1,90 +1,89 @@ extern crate cocoa; -use cocoa::base::{selector,id, nil, NO}; +use cocoa::base::{selector, id, nil, NO}; -use cocoa::foundation::{NSUInteger,NSRect,NSPoint, NSSize, - NSAutoreleasePool,NSProcessInfo,NSString}; -use cocoa::appkit::{NSApp, - NSApplication, NSApplicationActivationPolicyRegular, - NSWindow, NSTitledWindowMask, NSBackingStoreBuffered, - NSClosableWindowMask,NSResizableWindowMask,NSMiniaturizableWindowMask,NSUnifiedTitleAndToolbarWindowMask, - NSMenu, NSMenuItem, - NSTabView, NSTabViewItem, - NSRunningApplication, - NSApplicationActivateIgnoringOtherApps}; +use cocoa::foundation::{NSUInteger, NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, + NSString}; +use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, + NSTitledWindowMask, NSBackingStoreBuffered, NSClosableWindowMask, + NSResizableWindowMask, NSMiniaturizableWindowMask, + NSUnifiedTitleAndToolbarWindowMask, NSMenu, NSMenuItem, NSTabView, + NSTabViewItem, NSRunningApplication, NSApplicationActivateIgnoringOtherApps}; fn main() { - unsafe { - - // create a tab View - let tab_view = NSTabView::new(nil).initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.))); + unsafe { - // create a tab view item - let tab_view_item = NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView1")); - - tab_view_item.setLabel_(NSString::alloc(nil).init_str("Tab view item 1")); - tab_view.addTabViewItem_(tab_view_item); + // create a tab View + let tab_view = NSTabView::new(nil) + .initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.))); - //create a second tab view item - let tab_view_item2 = NSTabViewItem::new(nil).initWithIdentifier_(NSString::alloc(nil).init_str("TabView2")); - - tab_view_item2.setLabel_(NSString::alloc(nil).init_str("Tab view item 2")); - tab_view.addTabViewItem_(tab_view_item2); + // create a tab view item + let tab_view_item = NSTabViewItem::new(nil) + .initWithIdentifier_(NSString::alloc(nil).init_str("TabView1")); - //Create the app and set the content. - let app = create_app(NSString::alloc(nil).init_str("Tab View"),tab_view); - app.run(); - } + tab_view_item.setLabel_(NSString::alloc(nil).init_str("Tab view item 1")); + tab_view.addTabViewItem_(tab_view_item); + + // create a second tab view item + let tab_view_item2 = NSTabViewItem::new(nil) + .initWithIdentifier_(NSString::alloc(nil).init_str("TabView2")); + + tab_view_item2.setLabel_(NSString::alloc(nil).init_str("Tab view item 2")); + tab_view.addTabViewItem_(tab_view_item2); + + // Create the app and set the content. + let app = create_app(NSString::alloc(nil).init_str("Tab View"), tab_view); + app.run(); + } } -unsafe fn create_app(title:id,content:id) -> id{ - let _pool = NSAutoreleasePool::new(nil); +unsafe fn create_app(title: id, content: id) -> id { + let _pool = NSAutoreleasePool::new(nil); - let app = NSApp(); - app.setActivationPolicy_(NSApplicationActivationPolicyRegular); + let app = NSApp(); + app.setActivationPolicy_(NSApplicationActivationPolicyRegular); - // create Menu Bar - let menubar = NSMenu::new(nil).autorelease(); - let app_menu_item = NSMenuItem::new(nil).autorelease(); - menubar.addItem_(app_menu_item); - app.setMainMenu_(menubar); + // create Menu Bar + let menubar = NSMenu::new(nil).autorelease(); + let app_menu_item = NSMenuItem::new(nil).autorelease(); + menubar.addItem_(app_menu_item); + app.setMainMenu_(menubar); - // create Application menu - let app_menu = NSMenu::new(nil).autorelease(); - 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"); - let quit_item = NSMenuItem::alloc(nil).initWithTitle_action_keyEquivalent_( - quit_title, - quit_action, - quit_key - ).autorelease(); - app_menu.addItem_(quit_item); - app_menu_item.setSubmenu_(app_menu); + // create Application menu + let app_menu = NSMenu::new(nil).autorelease(); + 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"); + let quit_item = NSMenuItem::alloc(nil) + .initWithTitle_action_keyEquivalent_(quit_title, quit_action, quit_key) + .autorelease(); + app_menu.addItem_(quit_item); + app_menu_item.setSubmenu_(app_menu); - // create Window - let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_( + // create Window + let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_( NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), - NSTitledWindowMask as NSUInteger | NSClosableWindowMask as NSUInteger | NSResizableWindowMask as NSUInteger | NSMiniaturizableWindowMask as NSUInteger | NSUnifiedTitleAndToolbarWindowMask as NSUInteger, + NSTitledWindowMask as NSUInteger | + NSClosableWindowMask as NSUInteger | + NSResizableWindowMask as NSUInteger | + NSMiniaturizableWindowMask as NSUInteger | + NSUnifiedTitleAndToolbarWindowMask as NSUInteger, NSBackingStoreBuffered, NO ).autorelease(); - window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); - window.center(); - - window.setTitle_(title); - window.makeKeyAndOrderFront_(nil); + window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); + window.center(); - window.setContentView_(content); - let current_app = NSRunningApplication::currentApplication(nil); - current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); + window.setTitle_(title); + window.makeKeyAndOrderFront_(nil); - return app; + window.setContentView_(content); + let current_app = NSRunningApplication::currentApplication(nil); + current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps); + + return app; } - - diff --git a/tests/foundation.rs b/tests/foundation.rs index 5be8e6c..80ba680 100644 --- a/tests/foundation.rs +++ b/tests/foundation.rs @@ -6,8 +6,8 @@ extern crate cocoa; #[cfg(test)] mod foundation { mod nsstring { - use cocoa::foundation::{NSString}; - use cocoa::base::{nil}; + use cocoa::foundation::NSString; + use cocoa::base::nil; use std::slice; use std::str; @@ -17,7 +17,8 @@ mod foundation { 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(); + let objc_string = str::from_utf8(slice::from_raw_parts(bytes, built.len())) + .unwrap(); assert!(objc_string.len() == expected.len()); assert!(objc_string == expected); } @@ -29,7 +30,8 @@ mod foundation { 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(); + let objc_string = str::from_utf8(slice::from_raw_parts(bytes, built.len())) + .unwrap(); assert!(objc_string.len() == expected.len()); assert!(objc_string == expected); } @@ -54,7 +56,8 @@ mod foundation { 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(); + let objc_string = str::from_utf8(slice::from_raw_parts(bytes, append_string.len())) + .unwrap(); assert!(objc_string == expected); } } @@ -71,14 +74,17 @@ mod foundation { 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 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 }); + .fold(String::new(), |mut acc, s| { + acc.push_str(s); + acc + }); assert_eq!(combined, "thisisateststring"); } @@ -90,7 +96,7 @@ mod foundation { 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 components: id = msg_send![string, componentsSeparatedByString: separator]; let mut_components: id = msg_send![components, mutableCopy]; let mut iter = mut_components.iter(); iter.next(); @@ -102,7 +108,8 @@ mod foundation { mod nsdictionary { use block::ConcreteBlock; - use cocoa::foundation::{NSArray, NSComparisonResult, NSDictionary, NSFastEnumeration, NSString}; + use cocoa::foundation::{NSArray, NSComparisonResult, NSDictionary, NSFastEnumeration, + NSString}; use cocoa::base::{id, nil}; #[test] @@ -134,7 +141,8 @@ mod foundation { let keys_array = NSArray::arrayWithObjects(nil, &keys_raw_vec); let objs_array = NSArray::arrayWithObjects(nil, &objs_raw_vec); - let dict = NSDictionary::dictionaryWithObjects_forKeys_(nil, objs_array, keys_array); + let dict = + NSDictionary::dictionaryWithObjects_forKeys_(nil, objs_array, keys_array); // NSDictionary does not store its contents in order of insertion, so ask for // sorted iterators to ensure that each item is the same as its counterpart in @@ -146,16 +154,18 @@ mod foundation { let (bytes1, len1) = (s1.UTF8String() as *const u8, s1.len()); let (s0, s1) = (str::from_utf8(slice::from_raw_parts(bytes0, len0)).unwrap(), str::from_utf8(slice::from_raw_parts(bytes1, len1)).unwrap()); - let (c0, c1) =(s0.chars().next().unwrap(), s1.chars().next().unwrap()); + let (c0, c1) = (s0.chars().next().unwrap(), s1.chars().next().unwrap()); match c0.cmp(&c1) { Ordering::Less => NSComparisonResult::NSOrderedAscending, Ordering::Equal => NSComparisonResult::NSOrderedSame, - Ordering::Greater => NSComparisonResult::NSOrderedDescending + Ordering::Greater => NSComparisonResult::NSOrderedDescending, } }); let associated_iter = keys.iter().zip(objects.iter()); - for (k_id, (k, v)) in dict.keysSortedByValueUsingComparator_(&mut *comparator).iter().zip(associated_iter) { + for (k_id, (k, v)) in dict.keysSortedByValueUsingComparator_(&mut *comparator) + .iter() + .zip(associated_iter) { assert!(k_id.isEqualToString(k)); let v_id = dict.objectForKey_(k_id); assert!(v_id.isEqualToString(v)); From 5b9a27e4cb1f8ec805da424cc0cdae7ff475fc8f Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 26 Nov 2016 15:06:06 -0500 Subject: [PATCH 221/249] Init `NSColor` trait, add `clearColor` constructor. --- src/appkit.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index d3d0a78..98aec91 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -3662,3 +3662,13 @@ impl NSLayoutDimension for id { msg_send![self, constraintGreaterThanOrEqualToConstant:c] } } + +pub trait NSColor { + unsafe fn clearColor(_: Self) -> id; +} + +impl NSColor for id { + unsafe fn clearColor(_: Self) -> id { + msg_send![class("NSColor"), clearColor] + } +} From 9727b0de72b54dbb14c08082e45215c581eda37a Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 26 Nov 2016 15:21:34 -0500 Subject: [PATCH 222/249] Bump version to 0.5.2. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7c5fdf2..ff8bd7f 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.5.1" +version = "0.5.2" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From 078eb35d34927d0033d0b6aaa291b2e0167ce943 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Mon, 12 Dec 2016 20:14:50 +1100 Subject: [PATCH 223/249] Remove legacy items from .gitignore --- .gitignore | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.gitignore b/.gitignore index e04cf59..8c34689 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,4 @@ *~ -*# -*.o -*.a -*.so -*.dylib -*.dSYM -*.dll -*.dummy -cocoa-test build /target /Cargo.lock From d0566aace0fa2d11d850c1a7c359d84f77a94d00 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 19 Jan 2017 09:16:35 -0500 Subject: [PATCH 224/249] Update core-graphics to 0.5; update minor version. --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ff8bd7f..3a258db 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.5.2" +version = "0.5.3" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -15,5 +15,5 @@ crate-type = ["rlib"] block = "0.1" bitflags = "0.7" libc = "0.2" -core-graphics = "0.4" +core-graphics = "0.5" objc = "0.2" From 9b7e83091bb2b48dfe1a7761c5fcaf50fc75912e Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Fri, 20 Jan 2017 10:04:50 -0500 Subject: [PATCH 225/249] Update version to account for semver changes. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3a258db..cc13cce 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.5.3" +version = "0.6.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" From 128a1ab4602315bed7d384c7a53e16ee8b260190 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Wed, 1 Feb 2017 09:49:04 +0100 Subject: [PATCH 226/249] NSTextField support --- src/appkit.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 98aec91..8076a03 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -3350,6 +3350,26 @@ extern { pub fn NSRectFill(rect: NSRect); } +pub trait NSTextField { + unsafe fn alloc(_: Self) -> id { + msg_send![class("NSTextField"), alloc] + } + unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; + unsafe fn setEditable_(self, editable: BOOL); + unsafe fn setStringValue_(self, label: id /* NSString */); +} + +impl NSTextField for id { + unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { + msg_send![self, initWithFrame:frameRect] + } + unsafe fn setEditable_(self, editable: BOOL) { + msg_send![self, setEditable:editable]; + } + unsafe fn setStringValue_(self, label: id) { + msg_send![self, setStringValue:label]; + } +} #[repr(u64)] pub enum NSTabViewType { From 73455d52ad5ff49d34bb89f13fee2ab2e76c8fc8 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Wed, 1 Feb 2017 09:49:16 +0100 Subject: [PATCH 227/249] More NSButton methods --- src/appkit.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 8076a03..3996612 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -294,6 +294,23 @@ pub enum NSWindowButton { NSWindowFullScreenButton = 7, } +#[repr(u64)] +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum NSBezelStyle { + NSRoundedBezelStyle = 1, + NSRegularSquareBezelStyle = 2, + NSDisclosureBezelStyle = 5, + NSShadowlessSquareBezelStyle = 6, + NSCircularBezelStyle = 7, + NSTexturedSquareBezelStyle = 8, + NSHelpButtonBezelStyle = 9, + NSSmallSquareBezelStyle = 10, + NSTexturedRoundedBezelStyle = 11, + NSRoundRectBezelStyle = 12, + NSRecessedBezelStyle = 13, + NSRoundedDisclosureBezelStyle = 14, +} + pub static NSMainMenuWindowLevel: libc::int32_t = 24; pub trait NSApplication { @@ -2761,9 +2778,24 @@ impl NSScreen for id { pub trait NSButton { unsafe fn setImage_(self, img: id /* (NSImage *) */); + unsafe fn setBezelStyle_(self, style: NSBezelStyle); + unsafe fn setTitle_(self, title: id /* (NSString*) */); + unsafe fn alloc(_: Self) -> id { + msg_send![class("NSButton"), alloc] + } + unsafe fn initWithFrame_(self, frameRect: NSRect) -> id; } impl NSButton for id { + unsafe fn initWithFrame_(self, frameRect: NSRect) -> id { + msg_send![self, initWithFrame:frameRect] + } + unsafe fn setBezelStyle_(self, style: NSBezelStyle) { + msg_send![self, setBezelStyle:style]; + } + unsafe fn setTitle_(self, title: id /* (NSString*) */) { + msg_send![self, setTitle:title] + } unsafe fn setImage_(self, img: id /* (NSImage *) */) { msg_send![self, setImage:img] } From 96e6484fc2eb371ffa1089a3a1f9660afaf4ac9e Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 1 Feb 2017 16:24:26 +0100 Subject: [PATCH 228/249] Update core-graphics to 0.6 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cc13cce..51e269d 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.6.0" +version = "0.7.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -15,5 +15,5 @@ crate-type = ["rlib"] block = "0.1" bitflags = "0.7" libc = "0.2" -core-graphics = "0.5" +core-graphics = "0.6" objc = "0.2" From 4ca8bfb1f7e148340ba270993bad57028e297e54 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 18 Feb 2017 16:59:09 +0100 Subject: [PATCH 229/249] Update core-graphics to 0.7 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 51e269d..1f57bc8 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.7.0" +version = "0.8.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -15,5 +15,5 @@ crate-type = ["rlib"] block = "0.1" bitflags = "0.7" libc = "0.2" -core-graphics = "0.6" +core-graphics = "0.7" objc = "0.2" From 142bf3bbc0161be1b7d909c8c6c19c6ad079ec8e Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Wed, 15 Mar 2017 13:50:28 +0100 Subject: [PATCH 230/249] Add appearance names --- Cargo.toml | 2 +- src/appkit.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1f57bc8..63bdf3a 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.8.0" +version = "0.8.1" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" diff --git a/src/appkit.rs b/src/appkit.rs index 3996612..8b82aa4 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -81,6 +81,10 @@ extern { // Pasteboard reading options - OS X v10.6 and later. (NSString *) pub static NSPasteboardURLReadingFileURLsOnlyKey: id; pub static NSPasteboardURLReadingContentsConformToTypesKey: id; + + // NSAppearance names. (NSString *) + pub static NSAppearanceNameVibrantDark: id; + pub static NSAppearanceNameVibrantLight: id; } pub const NSAppKitVersionNumber10_0: f64 = 577.0; From c964442d55fdd5bbf04ab8278acd460222e215c2 Mon Sep 17 00:00:00 2001 From: Oluseyi Sonaiya Date: Wed, 22 Mar 2017 09:59:03 -0400 Subject: [PATCH 231/249] NSWindowMask, as an enumeration in Objective-C, degrades to NSUInteger and is therefore bitwise-combinable, though it loses type information. Instead of implementing NSWindowMask as a packed-data object with a u64 representational form, we ought to employ bit flags to generate a strong type that remains combinable in the manner Cocoa programmers are accustomed to. Also easier than manually implementing std::ops::BitOr for the type. --- src/appkit.rs | 68 +++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 8b82aa4..a0efa59 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -20,7 +20,6 @@ pub use core_graphics::geometry::CGPoint; pub use self::NSApplicationActivationPolicy::*; pub use self::NSApplicationActivationOptions::*; -pub use self::NSWindowMask::*; pub use self::NSBackingStoreType::*; pub use self::NSOpenGLPixelFormatAttribute::*; pub use self::NSOpenGLPFAOpenGLProfiles::*; @@ -141,22 +140,22 @@ pub enum NSApplicationTerminateReply { NSTerminateLater = 2, } -#[repr(u64)] -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum NSWindowMask { - NSBorderlessWindowMask = 0, - NSTitledWindowMask = 1 << 0, - NSClosableWindowMask = 1 << 1, - NSMiniaturizableWindowMask = 1 << 2, - NSResizableWindowMask = 1 << 3, +bitflags! { + pub flags NSWindowMask: NSUInteger { + const NSBorderlessWindowMask = 0, + const NSTitledWindowMask = 1 << 0, + const NSClosableWindowMask = 1 << 1, + const NSMiniaturizableWindowMask = 1 << 2, + const NSResizableWindowMask = 1 << 3, - NSTexturedBackgroundWindowMask = 1 << 8, + const NSTexturedBackgroundWindowMask = 1 << 8, - NSUnifiedTitleAndToolbarWindowMask = 1 << 12, + const NSUnifiedTitleAndToolbarWindowMask = 1 << 12, - NSFullScreenWindowMask = 1 << 14, + const NSFullScreenWindowMask = 1 << 14, - NSFullSizeContentViewWindowMask = 1 << 15 + const NSFullSizeContentViewWindowMask = 1 << 15 + } } #[repr(u64)] @@ -799,19 +798,19 @@ pub trait NSWindow { // Creating Windows unsafe fn initWithContentRect_styleMask_backing_defer_(self, rect: NSRect, - style: NSUInteger, + style: NSWindowMask, backing: NSBackingStoreType, defer: BOOL) -> id; unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self, rect: NSRect, - style: NSUInteger, + style: NSWindowMask, backing: NSBackingStoreType, defer: BOOL, screen: id) -> id; // Configuring Windows - unsafe fn styleMask(self) -> NSUInteger; - unsafe fn setStyleMask_(self, styleMask: NSUInteger); + unsafe fn styleMask(self) -> NSWindowMask; + unsafe fn setStyleMask_(self, styleMask: NSWindowMask); unsafe fn toggleFullScreen_(self, sender: id); unsafe fn worksWhenModal(self) -> BOOL; unsafe fn alphaValue(self) -> CGFloat; @@ -846,9 +845,9 @@ pub trait NSWindow { // TODO: Accessing Window Information // Getting Layout Information - unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSUInteger) -> NSRect; - unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSUInteger) -> NSRect; - unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSUInteger) -> CGFloat; + unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSWindowMask) -> NSRect; + unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSWindowMask) -> NSRect; + unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSWindowMask) -> CGFloat; unsafe fn contentRectForFrameRect_(self, windowFrame: NSRect) -> NSRect; unsafe fn frameRectForContentRect_(self, windowContent: NSRect) -> NSRect; @@ -1025,23 +1024,23 @@ impl NSWindow for id { unsafe fn initWithContentRect_styleMask_backing_defer_(self, rect: NSRect, - style: NSUInteger, + style: NSWindowMask, backing: NSBackingStoreType, defer: BOOL) -> id { msg_send![self, initWithContentRect:rect - styleMask:style + styleMask:style.bits backing:backing as NSUInteger defer:defer] } unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self, rect: NSRect, - style: NSUInteger, + style: NSWindowMask, backing: NSBackingStoreType, defer: BOOL, screen: id) -> id { msg_send![self, initWithContentRect:rect - styleMask:style + styleMask:style.bits backing:backing as NSUInteger defer:defer screen:screen] @@ -1049,12 +1048,13 @@ impl NSWindow for id { // Configuring Windows - unsafe fn styleMask(self) -> NSUInteger { - msg_send![self, styleMask] + unsafe fn styleMask(self) -> NSWindowMask { + let styleMask = msg_send![self, styleMask]; + styleMask } - unsafe fn setStyleMask_(self, styleMask: NSUInteger) { - msg_send![self, setStyleMask:styleMask] + unsafe fn setStyleMask_(self, styleMask: NSWindowMask) { + msg_send![self, setStyleMask:styleMask.bits] } unsafe fn toggleFullScreen_(self, sender: id) { @@ -1176,16 +1176,16 @@ impl NSWindow for id { // Getting Layout Information - unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSUInteger) -> NSRect { - msg_send![self, contentRectForFrameRect:windowFrame styleMask:windowStyle] + unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSWindowMask) -> NSRect { + msg_send![self, contentRectForFrameRect:windowFrame styleMask:windowStyle.bits] } - unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSUInteger) -> NSRect { - msg_send![self, frameRectForContentRect:windowContentRect styleMask:windowStyle] + unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSWindowMask) -> NSRect { + msg_send![self, frameRectForContentRect:windowContentRect styleMask:windowStyle.bits] } - unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSUInteger) -> CGFloat { - msg_send![self, minFrameWidthWithTitle:windowTitle styleMask:windowStyle] + unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSWindowMask) -> CGFloat { + msg_send![self, minFrameWidthWithTitle:windowTitle styleMask:windowStyle.bits] } unsafe fn contentRectForFrameRect_(self, windowFrame: NSRect) -> NSRect { From 7f9ba0f7d5472b53aa1c479847371e0c9ce46dd6 Mon Sep 17 00:00:00 2001 From: Oluseyi Sonaiya Date: Wed, 22 Mar 2017 11:33:12 -0400 Subject: [PATCH 232/249] Rename NSWindowMask to NSWindowStyleMask to match the Cocoa AppKit type --- src/appkit.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index a0efa59..efd7506 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -141,7 +141,7 @@ pub enum NSApplicationTerminateReply { } bitflags! { - pub flags NSWindowMask: NSUInteger { + pub flags NSWindowStyleMask: NSUInteger { const NSBorderlessWindowMask = 0, const NSTitledWindowMask = 1 << 0, const NSClosableWindowMask = 1 << 1, @@ -798,19 +798,19 @@ pub trait NSWindow { // Creating Windows unsafe fn initWithContentRect_styleMask_backing_defer_(self, rect: NSRect, - style: NSWindowMask, + style: NSWindowStyleMask, backing: NSBackingStoreType, defer: BOOL) -> id; unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self, rect: NSRect, - style: NSWindowMask, + style: NSWindowStyleMask, backing: NSBackingStoreType, defer: BOOL, screen: id) -> id; // Configuring Windows - unsafe fn styleMask(self) -> NSWindowMask; - unsafe fn setStyleMask_(self, styleMask: NSWindowMask); + unsafe fn styleMask(self) -> NSWindowStyleMask; + unsafe fn setStyleMask_(self, styleMask: NSWindowStyleMask); unsafe fn toggleFullScreen_(self, sender: id); unsafe fn worksWhenModal(self) -> BOOL; unsafe fn alphaValue(self) -> CGFloat; @@ -845,9 +845,9 @@ pub trait NSWindow { // TODO: Accessing Window Information // Getting Layout Information - unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSWindowMask) -> NSRect; - unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSWindowMask) -> NSRect; - unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSWindowMask) -> CGFloat; + unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSWindowStyleMask) -> NSRect; + unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSWindowStyleMask) -> NSRect; + unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSWindowStyleMask) -> CGFloat; unsafe fn contentRectForFrameRect_(self, windowFrame: NSRect) -> NSRect; unsafe fn frameRectForContentRect_(self, windowContent: NSRect) -> NSRect; @@ -1024,7 +1024,7 @@ impl NSWindow for id { unsafe fn initWithContentRect_styleMask_backing_defer_(self, rect: NSRect, - style: NSWindowMask, + style: NSWindowStyleMask, backing: NSBackingStoreType, defer: BOOL) -> id { msg_send![self, initWithContentRect:rect @@ -1035,7 +1035,7 @@ impl NSWindow for id { unsafe fn initWithContentRect_styleMask_backing_defer_screen_(self, rect: NSRect, - style: NSWindowMask, + style: NSWindowStyleMask, backing: NSBackingStoreType, defer: BOOL, screen: id) -> id { @@ -1048,12 +1048,12 @@ impl NSWindow for id { // Configuring Windows - unsafe fn styleMask(self) -> NSWindowMask { let styleMask = msg_send![self, styleMask]; + unsafe fn styleMask(self) -> NSWindowStyleMask { styleMask } - unsafe fn setStyleMask_(self, styleMask: NSWindowMask) { + unsafe fn setStyleMask_(self, styleMask: NSWindowStyleMask) { msg_send![self, setStyleMask:styleMask.bits] } @@ -1176,15 +1176,15 @@ impl NSWindow for id { // Getting Layout Information - unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSWindowMask) -> NSRect { + unsafe fn contentRectForFrameRect_styleMask_(self, windowFrame: NSRect, windowStyle: NSWindowStyleMask) -> NSRect { msg_send![self, contentRectForFrameRect:windowFrame styleMask:windowStyle.bits] } - unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSWindowMask) -> NSRect { + unsafe fn frameRectForContentRect_styleMask_(self, windowContentRect: NSRect, windowStyle: NSWindowStyleMask) -> NSRect { msg_send![self, frameRectForContentRect:windowContentRect styleMask:windowStyle.bits] } - unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSWindowMask) -> CGFloat { + unsafe fn minFrameWidthWithTitle_styleMask_(self, windowTitle: id, windowStyle: NSWindowStyleMask) -> CGFloat { msg_send![self, minFrameWidthWithTitle:windowTitle styleMask:windowStyle.bits] } From 135fce23857e5f6a85209d8f20a72a21f9aa5475 Mon Sep 17 00:00:00 2001 From: Oluseyi Sonaiya Date: Wed, 22 Mar 2017 11:35:32 -0400 Subject: [PATCH 233/249] Use bitflags from_bits_truncate to ensure value retrieved from msg_send maps to declared fields. Prefer truncate because macOS may use reserved bits for private purposes, or introduce new values in future versions. --- src/appkit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/appkit.rs b/src/appkit.rs index efd7506..0ab4ef0 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -1048,8 +1048,8 @@ impl NSWindow for id { // Configuring Windows - let styleMask = msg_send![self, styleMask]; unsafe fn styleMask(self) -> NSWindowStyleMask { + let styleMask = NSWindowStyleMask::from_bits_truncate(msg_send![self, styleMask]); styleMask } From e773703bb5961f4ccc29bbd5f8797050bdc4459e Mon Sep 17 00:00:00 2001 From: Oluseyi Sonaiya Date: Wed, 22 Mar 2017 14:11:07 -0400 Subject: [PATCH 234/249] Update examples to match new NSWindowStyleMask type. --- examples/hello_world.rs | 2 +- examples/tab_view.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 4e44ff8..4eed37d 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -37,7 +37,7 @@ fn main() { let window = NSWindow::alloc(nil) .initWithContentRect_styleMask_backing_defer_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), - NSTitledWindowMask as NSUInteger, + NSTitledWindowMask, NSBackingStoreBuffered, NO) .autorelease(); diff --git a/examples/tab_view.rs b/examples/tab_view.rs index 51bb0be..72c1b3d 100644 --- a/examples/tab_view.rs +++ b/examples/tab_view.rs @@ -67,11 +67,11 @@ unsafe fn create_app(title: id, content: id) -> id { // create Window let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_( NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), - NSTitledWindowMask as NSUInteger | - NSClosableWindowMask as NSUInteger | - NSResizableWindowMask as NSUInteger | - NSMiniaturizableWindowMask as NSUInteger | - NSUnifiedTitleAndToolbarWindowMask as NSUInteger, + NSTitledWindowMask | + NSClosableWindowMask | + NSResizableWindowMask | + NSMiniaturizableWindowMask | + NSUnifiedTitleAndToolbarWindowMask, NSBackingStoreBuffered, NO ).autorelease(); From 437596359a32acb3d38dba62f4d72b8c1f6dc14d Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Sat, 10 Jun 2017 22:04:14 +0200 Subject: [PATCH 235/249] Allow core-graphics 0.8 and bump version --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 63bdf3a..38f8100 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.8.1" +version = "0.9.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -15,5 +15,5 @@ crate-type = ["rlib"] block = "0.1" bitflags = "0.7" libc = "0.2" -core-graphics = "0.7" +core-graphics = "0.8" objc = "0.2" From 6202d5709decd88a012b591d24ccd60b484e8ee7 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 19 Jun 2017 15:50:00 -0400 Subject: [PATCH 236/249] Make travis compile again. --- .travis.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e5763ed..ced8c3b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,9 +2,5 @@ os: osx language: rust -branches: - except: - - master - notifications: webhooks: http://build.servo.org:54856/travis From d3d9e3c95f4464b46afec8e2e55a0d37f8f11a6b Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Mon, 19 Jun 2017 19:45:55 +0200 Subject: [PATCH 237/249] Update bitflags and bump version --- Cargo.toml | 4 +- src/appkit.rs | 220 +++++++++++++++++++++++----------------------- src/foundation.rs | 40 ++++----- 3 files changed, 132 insertions(+), 132 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 38f8100..1ffc6bf 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.9.0" +version = "0.9.1" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -13,7 +13,7 @@ crate-type = ["rlib"] [dependencies] block = "0.1" -bitflags = "0.7" +bitflags = "0.9" libc = "0.2" core-graphics = "0.8" objc = "0.2" diff --git a/src/appkit.rs b/src/appkit.rs index 0ab4ef0..1040675 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -141,20 +141,20 @@ pub enum NSApplicationTerminateReply { } bitflags! { - pub flags NSWindowStyleMask: NSUInteger { - const NSBorderlessWindowMask = 0, - const NSTitledWindowMask = 1 << 0, - const NSClosableWindowMask = 1 << 1, - const NSMiniaturizableWindowMask = 1 << 2, - const NSResizableWindowMask = 1 << 3, + pub struct NSWindowStyleMask: NSUInteger { + const NSBorderlessWindowMask = 0; + const NSTitledWindowMask = 1 << 0; + const NSClosableWindowMask = 1 << 1; + const NSMiniaturizableWindowMask = 1 << 2; + const NSResizableWindowMask = 1 << 3; - const NSTexturedBackgroundWindowMask = 1 << 8, + const NSTexturedBackgroundWindowMask = 1 << 8; - const NSUnifiedTitleAndToolbarWindowMask = 1 << 12, + const NSUnifiedTitleAndToolbarWindowMask = 1 << 12; - const NSFullScreenWindowMask = 1 << 14, + const NSFullScreenWindowMask = 1 << 14; - const NSFullSizeContentViewWindowMask = 1 << 15 + const NSFullSizeContentViewWindowMask = 1 << 15; } } @@ -174,46 +174,46 @@ pub enum NSBackingStoreType { } bitflags! { - pub flags NSWindowOrderingMode: NSInteger { - const NSWindowAbove = 1, - const NSWindowBelow = -1, - const NSWindowOut = 0, + pub struct NSWindowOrderingMode: NSInteger { + const NSWindowAbove = 1; + const NSWindowBelow = -1; + const NSWindowOut = 0; } } bitflags! { - pub flags NSAlignmentOptions: libc::c_ulonglong { - const NSAlignMinXInward = 1 << 0, - const NSAlignMinYInward = 1 << 1, - const NSAlignMaxXInward = 1 << 2, - const NSAlignMaxYInward = 1 << 3, - const NSAlignWidthInward = 1 << 4, - const NSAlignHeightInward = 1 << 5, - const NSAlignMinXOutward = 1 << 8, - const NSAlignMinYOutward = 1 << 9, - const NSAlignMaxXOutward = 1 << 10, - const NSAlignMaxYOutward = 1 << 11, - const NSAlignWidthOutward = 1 << 12, - const NSAlignHeightOutward = 1 << 13, - const NSAlignMinXNearest = 1 << 16, - const NSAlignMinYNearest = 1 << 17, - const NSAlignMaxXNearest = 1 << 18, - const NSAlignMaxYNearest = 1 << 19, - const NSAlignWidthNearest = 1 << 20, - const NSAlignHeightNearest = 1 << 21, - const NSAlignRectFlipped = 1 << 63, + pub struct NSAlignmentOptions: libc::c_ulonglong { + const NSAlignMinXInward = 1 << 0; + const NSAlignMinYInward = 1 << 1; + const NSAlignMaxXInward = 1 << 2; + const NSAlignMaxYInward = 1 << 3; + const NSAlignWidthInward = 1 << 4; + const NSAlignHeightInward = 1 << 5; + const NSAlignMinXOutward = 1 << 8; + const NSAlignMinYOutward = 1 << 9; + const NSAlignMaxXOutward = 1 << 10; + const NSAlignMaxYOutward = 1 << 11; + const NSAlignWidthOutward = 1 << 12; + const NSAlignHeightOutward = 1 << 13; + const NSAlignMinXNearest = 1 << 16; + const NSAlignMinYNearest = 1 << 17; + const NSAlignMaxXNearest = 1 << 18; + const NSAlignMaxYNearest = 1 << 19; + const NSAlignWidthNearest = 1 << 20; + const NSAlignHeightNearest = 1 << 21; + const NSAlignRectFlipped = 1 << 63; const NSAlignAllEdgesInward = NSAlignMinXInward.bits | NSAlignMaxXInward.bits | NSAlignMinYInward.bits - | NSAlignMaxYInward.bits, + | NSAlignMaxYInward.bits; const NSAlignAllEdgesOutward = NSAlignMinXOutward.bits | NSAlignMaxXOutward.bits | NSAlignMinYOutward.bits - | NSAlignMaxYOutward.bits, + | NSAlignMaxYOutward.bits; const NSAlignAllEdgesNearest = NSAlignMinXNearest.bits | NSAlignMaxXNearest.bits | NSAlignMinYNearest.bits - | NSAlignMaxYNearest.bits, + | NSAlignMaxYNearest.bits; } } @@ -767,26 +767,26 @@ impl NSMenuItem for id { pub type NSWindowDepth = libc::c_int; bitflags! { - pub flags NSWindowCollectionBehavior: NSUInteger { - const NSWindowCollectionBehaviorDefault = 0, - const NSWindowCollectionBehaviorCanJoinAllSpaces = 1 << 0, - const NSWindowCollectionBehaviorMoveToActiveSpace = 1 << 1, + pub struct NSWindowCollectionBehavior: NSUInteger { + const NSWindowCollectionBehaviorDefault = 0; + const NSWindowCollectionBehaviorCanJoinAllSpaces = 1 << 0; + const NSWindowCollectionBehaviorMoveToActiveSpace = 1 << 1; - const NSWindowCollectionBehaviorManaged = 1 << 2, - const NSWindowCollectionBehaviorTransient = 1 << 3, - const NSWindowCollectionBehaviorStationary = 1 << 4, + const NSWindowCollectionBehaviorManaged = 1 << 2; + const NSWindowCollectionBehaviorTransient = 1 << 3; + const NSWindowCollectionBehaviorStationary = 1 << 4; - const NSWindowCollectionBehaviorParticipatesInCycle = 1 << 5, - const NSWindowCollectionBehaviorIgnoresCycle = 1 << 6, + const NSWindowCollectionBehaviorParticipatesInCycle = 1 << 5; + const NSWindowCollectionBehaviorIgnoresCycle = 1 << 6; - const NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7, - const NSWindowCollectionBehaviorFullScreenAuxiliary = 1 << 8, + const NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7; + const NSWindowCollectionBehaviorFullScreenAuxiliary = 1 << 8; } } bitflags! { - pub flags NSWindowOcclusionState: NSUInteger { - const NSWindowOcclusionStateVisible = 1 << 1 + pub struct NSWindowOcclusionState: NSUInteger { + const NSWindowOcclusionStateVisible = 1 << 1; } } @@ -1919,9 +1919,9 @@ impl NSOpenGLContext for id { } bitflags! { - pub flags NSEventSwipeTrackingOptions: NSUInteger { - const NSEventSwipeTrackingLockDirection = 0x1 << 0, - const NSEventSwipeTrackingClampGestureAmount = 0x1 << 1, + pub struct NSEventSwipeTrackingOptions: NSUInteger { + const NSEventSwipeTrackingLockDirection = 0x1 << 0; + const NSEventSwipeTrackingClampGestureAmount = 0x1 << 1; } } @@ -1933,28 +1933,28 @@ pub enum NSEventGestureAxis { } bitflags! { - pub flags NSEventPhase: NSUInteger { - const NSEventPhaseNone = 0, - const NSEventPhaseBegan = 0x1 << 0, - const NSEventPhaseStationary = 0x1 << 1, - const NSEventPhaseChanged = 0x1 << 2, - const NSEventPhaseEnded = 0x1 << 3, - const NSEventPhaseCancelled = 0x1 << 4, - const NSEventPhaseMayBegin = 0x1 << 5, + pub struct NSEventPhase: NSUInteger { + const NSEventPhaseNone = 0; + const NSEventPhaseBegan = 0x1 << 0; + const NSEventPhaseStationary = 0x1 << 1; + const NSEventPhaseChanged = 0x1 << 2; + const NSEventPhaseEnded = 0x1 << 3; + const NSEventPhaseCancelled = 0x1 << 4; + const NSEventPhaseMayBegin = 0x1 << 5; } } bitflags! { - pub flags NSTouchPhase: NSUInteger { - const NSTouchPhaseBegan = 1 << 0, - const NSTouchPhaseMoved = 1 << 1, - const NSTouchPhaseStationary = 1 << 2, - const NSTouchPhaseEnded = 1 << 3, - const NSTouchPhaseCancelled = 1 << 4, + pub struct NSTouchPhase: NSUInteger { + const NSTouchPhaseBegan = 1 << 0; + const NSTouchPhaseMoved = 1 << 1; + const NSTouchPhaseStationary = 1 << 2; + const NSTouchPhaseEnded = 1 << 3; + const NSTouchPhaseCancelled = 1 << 4; const NSTouchPhaseTouching = NSTouchPhaseBegan.bits | NSTouchPhaseMoved.bits - | NSTouchPhaseStationary.bits, - const NSTouchPhaseAny = !0, // NSUIntegerMax + | NSTouchPhaseStationary.bits; + const NSTouchPhaseAny = !0; // NSUIntegerMax } } @@ -1994,37 +1994,37 @@ pub enum NSEventType { } bitflags! { - 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, - const NSRightMouseUpMask = 1 << NSRightMouseUp as libc::c_ulonglong, - const NSMouseMovedMask = 1 << NSMouseMoved as libc::c_ulonglong, - const NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged as libc::c_ulonglong, - const NSRightMouseDraggedMask = 1 << NSRightMouseDragged as libc::c_ulonglong, - const NSMouseEnteredMask = 1 << NSMouseEntered as libc::c_ulonglong, - const NSMouseExitedMask = 1 << NSMouseExited as libc::c_ulonglong, - const NSKeyDownMask = 1 << NSKeyDown as libc::c_ulonglong, - const NSKeyUpMask = 1 << NSKeyUp as libc::c_ulonglong, - 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 NSPeriodicMask = 1 << NSPeriodic as libc::c_ulonglong, - const NSCursorUpdateMask = 1 << NSCursorUpdate as libc::c_ulonglong, - const NSScrollWheelMask = 1 << NSScrollWheel as libc::c_ulonglong, - const NSTabletPointMask = 1 << NSTabletPoint as libc::c_ulonglong, - const NSTabletProximityMask = 1 << NSTabletProximity as libc::c_ulonglong, - 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 NSEventMaskSwipe = 1 << NSEventTypeSwipe as libc::c_ulonglong, - 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 = 0xffffffffffffffff, + pub struct 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; + const NSRightMouseUpMask = 1 << NSRightMouseUp as libc::c_ulonglong; + const NSMouseMovedMask = 1 << NSMouseMoved as libc::c_ulonglong; + const NSLeftMouseDraggedMask = 1 << NSLeftMouseDragged as libc::c_ulonglong; + const NSRightMouseDraggedMask = 1 << NSRightMouseDragged as libc::c_ulonglong; + const NSMouseEnteredMask = 1 << NSMouseEntered as libc::c_ulonglong; + const NSMouseExitedMask = 1 << NSMouseExited as libc::c_ulonglong; + const NSKeyDownMask = 1 << NSKeyDown as libc::c_ulonglong; + const NSKeyUpMask = 1 << NSKeyUp as libc::c_ulonglong; + 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 NSPeriodicMask = 1 << NSPeriodic as libc::c_ulonglong; + const NSCursorUpdateMask = 1 << NSCursorUpdate as libc::c_ulonglong; + const NSScrollWheelMask = 1 << NSScrollWheel as libc::c_ulonglong; + const NSTabletPointMask = 1 << NSTabletPoint as libc::c_ulonglong; + const NSTabletProximityMask = 1 << NSTabletProximity as libc::c_ulonglong; + 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 NSEventMaskSwipe = 1 << NSEventTypeSwipe as libc::c_ulonglong; + 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 = 0xffffffffffffffff; } } @@ -2035,16 +2035,16 @@ impl NSEventMask { } bitflags! { - pub flags NSEventModifierFlags: NSUInteger { - const NSAlphaShiftKeyMask = 1 << 16, - const NSShiftKeyMask = 1 << 17, - const NSControlKeyMask = 1 << 18, - const NSAlternateKeyMask = 1 << 19, - const NSCommandKeyMask = 1 << 20, - const NSNumericPadKeyMask = 1 << 21, - const NSHelpKeyMask = 1 << 22, - const NSFunctionKeyMask = 1 << 23, - const NSDeviceIndependentModifierFlagsMask = 0xffff0000, + pub struct NSEventModifierFlags: NSUInteger { + const NSAlphaShiftKeyMask = 1 << 16; + const NSShiftKeyMask = 1 << 17; + const NSControlKeyMask = 1 << 18; + const NSAlternateKeyMask = 1 << 19; + const NSCommandKeyMask = 1 << 20; + const NSNumericPadKeyMask = 1 << 21; + const NSHelpKeyMask = 1 << 22; + const NSFunctionKeyMask = 1 << 23; + const NSDeviceIndependentModifierFlagsMask = 0xffff0000; } } diff --git a/src/foundation.rs b/src/foundation.rs index 68d2c03..4d8e5bc 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -514,9 +514,9 @@ impl NSDictionary for id { } bitflags! { - pub flags NSEnumerationOptions: libc::c_ulonglong { - const NSEnumerationConcurrent = 1 << 0, - const NSEnumerationReverse = 1 << 1 + pub struct NSEnumerationOptions: libc::c_ulonglong { + const NSEnumerationConcurrent = 1 << 0; + const NSEnumerationReverse = 1 << 1; } } @@ -886,38 +886,38 @@ impl NSData for id { } bitflags! { - pub flags NSDataReadingOptions: libc::c_ulonglong { - const NSDataReadingMappedIfSafe = 1 << 0, - const NSDataReadingUncached = 1 << 1, - const NSDataReadingMappedAlways = 1 << 3 + pub struct 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 + pub struct 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 + pub struct NSDataBase64DecodingOptions: libc::c_ulonglong { + const NSDataBase64DecodingIgnoreUnknownCharacters = 1 << 0; } } bitflags! { - pub flags NSDataWritingOptions: libc::c_ulonglong { - const NSDataWritingAtomic = 1 << 0, - const NSDataWritingWithoutOverwriting = 1 << 1 + pub struct 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 + pub struct NSDataSearchOptions: libc::c_ulonglong { + const NSDataSearchBackwards = 1 << 0; + const NSDataSearchAnchored = 1 << 1; } } From 987dd375c9bff233dc6729fe6c5aa9f6ecdcf069 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 30 Jun 2017 16:35:03 +0200 Subject: [PATCH 238/249] Update to rustc 1.20.0-nightly (3bfc18a96 2017-06-29) --- Cargo.toml | 2 +- src/appkit.rs | 54 +++++++++++++++++++++++------------------------ src/foundation.rs | 22 +++++++++---------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1ffc6bf..947efce 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.9.1" +version = "0.9.2" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" diff --git a/src/appkit.rs b/src/appkit.rs index 1040675..39fe70c 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -316,7 +316,7 @@ pub enum NSBezelStyle { pub static NSMainMenuWindowLevel: libc::int32_t = 24; -pub trait NSApplication { +pub trait NSApplication: Sized { unsafe fn sharedApplication(_: Self) -> id { msg_send![class("NSApplication"), sharedApplication] } @@ -401,7 +401,7 @@ impl NSApplication for id { } } -pub trait NSRunningApplication { +pub trait NSRunningApplication: Sized { unsafe fn currentApplication(_: Self) -> id { msg_send![class("NSRunningApplication"), currentApplication] } @@ -414,7 +414,7 @@ impl NSRunningApplication for id { } } -pub trait NSPasteboard { +pub trait NSPasteboard: Sized { unsafe fn generalPasteboard(_: Self) -> id { msg_send![class("NSPasteboard"), generalPasteboard] } @@ -573,7 +573,7 @@ impl NSPasteboard for id { } -pub trait NSPasteboardItem { +pub trait NSPasteboardItem: Sized { unsafe fn types(self) -> id; unsafe fn setDataProvider_forTypes(self, dataProvider: id, types: id) -> BOOL; @@ -620,7 +620,7 @@ impl NSPasteboardItem for id { } } -pub trait NSPasteboardItemDataProvider { +pub trait NSPasteboardItemDataProvider: Sized { unsafe fn pasteboard_item_provideDataForType(self, pasteboard: id, item: id, _type: id); unsafe fn pasteboardFinishedWithDataProvider(self, pasteboard: id); } @@ -635,7 +635,7 @@ impl NSPasteboardItemDataProvider for id { } } -pub trait NSPasteboardWriting { +pub trait NSPasteboardWriting: Sized { unsafe fn writableTypesForPasteboard(self, pasteboard: id) -> id; unsafe fn writingOptionsForType_pasteboard(self, _type: id, pasteboard: id) -> NSPasteboardWritingOptions; @@ -656,7 +656,7 @@ impl NSPasteboardWriting for id { } } -pub trait NSPasteboardReading { +pub trait NSPasteboardReading: Sized { unsafe fn initWithPasteboardPropertyList_ofType(self, propertyList: id, _type: id) -> id; unsafe fn readableTypesForPasteboard(self, pasteboard: id) -> id; @@ -693,7 +693,7 @@ pub enum NSPasteboardWritingOptions { NSPasteboardWritingPromised = 1 << 9, } -pub trait NSMenu { +pub trait NSMenu: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class("NSMenu"), alloc] } @@ -732,7 +732,7 @@ impl NSMenu for id { } } -pub trait NSMenuItem { +pub trait NSMenuItem: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class("NSMenuItem"), alloc] } @@ -790,7 +790,7 @@ bitflags! { } } -pub trait NSWindow { +pub trait NSWindow: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class("NSWindow"), alloc] } @@ -1638,7 +1638,7 @@ impl NSWindow for id { // TODO: Constraint-Based Layouts } -pub trait NSView { +pub trait NSView: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class("NSView"), alloc] } @@ -1744,7 +1744,7 @@ pub const NSViewMinYMargin: u64 = 8; pub const NSViewHeightSizable: u64 = 16; pub const NSViewMaxYMargin: u64 = 32; -pub trait NSOpenGLView { +pub trait NSOpenGLView: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class("NSOpenGLView"), alloc] } @@ -1773,7 +1773,7 @@ impl NSOpenGLView for id { } } -pub trait NSOpenGLPixelFormat { +pub trait NSOpenGLPixelFormat: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class("NSOpenGLPixelFormat"), alloc] } @@ -1807,7 +1807,7 @@ impl NSOpenGLPixelFormat for id { } } -pub trait NSOpenGLContext { +pub trait NSOpenGLContext: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class("NSOpenGLContext"), alloc] } @@ -2153,7 +2153,7 @@ pub const NSFindFunctionKey: libc::c_ushort = 0xF745; pub const NSHelpFunctionKey: libc::c_ushort = 0xF746; pub const NSModeSwitchFunctionKey: libc::c_ushort = 0xF747; -pub trait NSEvent { +pub trait NSEvent: Sized { // Creating Events unsafe fn keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_( _: Self, @@ -2694,7 +2694,7 @@ impl NSEvent for id { } } -pub trait NSScreen { +pub trait NSScreen: Sized { // Getting NSScreen Objects unsafe fn mainScreen(_: Self) -> id /* (NSScreen *) */; unsafe fn deepestScreen(_: Self) -> id /* (NSScreen *) */; @@ -2780,7 +2780,7 @@ impl NSScreen for id { } } -pub trait NSButton { +pub trait NSButton: Sized { unsafe fn setImage_(self, img: id /* (NSImage *) */); unsafe fn setBezelStyle_(self, style: NSBezelStyle); unsafe fn setTitle_(self, title: id /* (NSString*) */); @@ -2805,7 +2805,7 @@ impl NSButton for id { } } -pub trait NSImage { +pub trait NSImage: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class("NSImage"), alloc] } @@ -3214,7 +3214,7 @@ pub enum NSImageLoadStatus { NSImageLoadStatusReadError } -pub trait NSSound { +pub trait NSSound: Sized { unsafe fn canInitWithPasteboard_(_: Self, pasteboard: id) -> BOOL { msg_send![class("NSSound"), canInitWithPasteboard:pasteboard] } @@ -3323,7 +3323,7 @@ impl NSSound for id { pub const NSVariableStatusItemLength: CGFloat = -1.0; pub const NSSquareStatusItemLength: CGFloat = -2.0; -pub trait NSStatusItem { +pub trait NSStatusItem: Sized { unsafe fn statusBar(self) -> id /* (NSStatusBar *) */; unsafe fn button(self) -> id /* (NSStatusBarButton *) */; unsafe fn menu(self) -> id; @@ -3358,7 +3358,7 @@ impl NSStatusItem for id { } } -pub trait NSStatusBar { +pub trait NSStatusBar: Sized { unsafe fn systemStatusBar(_: Self) -> id { msg_send![class("NSStatusBar"), systemStatusBar] } @@ -3386,7 +3386,7 @@ extern { pub fn NSRectFill(rect: NSRect); } -pub trait NSTextField { +pub trait NSTextField: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class("NSTextField"), alloc] } @@ -3418,7 +3418,7 @@ pub enum NSTabViewType { NSNoTabsNoBorder = 6 } -pub trait NSTabView { +pub trait NSTabView: Sized { unsafe fn new(_: Self) -> id { msg_send![class("NSTabView"), new] } @@ -3593,7 +3593,7 @@ pub enum NSTabState { NSPressedTab = 2 } -pub trait NSTabViewItem { +pub trait NSTabViewItem: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class("NSTabViewItem"), alloc] } @@ -3689,7 +3689,7 @@ impl NSTabViewItem for id { } } -pub trait NSLayoutConstraint { +pub trait NSLayoutConstraint: Sized { unsafe fn activateConstraints(_: Self, constraints: id) -> id; } @@ -3699,7 +3699,7 @@ impl NSLayoutConstraint for id { } } -pub trait NSLayoutDimension { +pub trait NSLayoutDimension: Sized { unsafe fn constraintEqualToConstant(self, c: CGFloat) -> id; unsafe fn constraintLessThanOrEqualToConstant(self, c: CGFloat) -> id; unsafe fn constraintGreaterThanOrEqualToConstant(self, c: CGFloat) -> id; @@ -3719,7 +3719,7 @@ impl NSLayoutDimension for id { } } -pub trait NSColor { +pub trait NSColor: Sized { unsafe fn clearColor(_: Self) -> id; } diff --git a/src/foundation.rs b/src/foundation.rs index 4d8e5bc..1693aad 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -152,7 +152,7 @@ extern { pub static NSDefaultRunLoopMode: id; } -pub trait NSAutoreleasePool { +pub trait NSAutoreleasePool: Sized { unsafe fn new(_: Self) -> id { msg_send![class("NSAutoreleasePool"), new] } @@ -171,7 +171,7 @@ impl NSAutoreleasePool for id { } } -pub trait NSProcessInfo { +pub trait NSProcessInfo: Sized { unsafe fn processInfo(_: Self) -> id { msg_send![class("NSProcessInfo"), processInfo] } @@ -187,7 +187,7 @@ impl NSProcessInfo for id { pub type NSTimeInterval = libc::c_double; -pub trait NSValue { +pub trait NSValue: Sized { unsafe fn valueWithPoint(_: Self, point: NSPoint) -> id { msg_send![class("NSValue"), valueWithPoint:point] } @@ -200,7 +200,7 @@ pub trait NSValue { impl NSValue for id { } -pub trait NSArray { +pub trait NSArray: Sized { unsafe fn array(_: Self) -> id { msg_send![class("NSArray"), array] } @@ -228,7 +228,7 @@ impl NSArray for id { } } -pub trait NSDictionary { +pub trait NSDictionary: Sized { unsafe fn dictionary(_: Self) -> id { msg_send![class("NSDictionary"), dictionary] } @@ -530,7 +530,7 @@ pub enum NSComparisonResult { NSOrderedDescending = 1 } -pub trait NSString { +pub trait NSString: Sized { unsafe fn alloc(_: Self) -> id { msg_send![class("NSString"), alloc] } @@ -569,7 +569,7 @@ impl NSString for id { } } -pub trait NSDate { +pub trait NSDate: Sized { unsafe fn distantPast(_: Self) -> id { msg_send![class("NSDate"), distantPast] } @@ -624,7 +624,7 @@ impl Iterator for NSFastIterator { 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) @@ -634,7 +634,7 @@ impl Iterator for NSFastIterator { } } -pub trait NSFastEnumeration { +pub trait NSFastEnumeration: Sized { unsafe fn iter(self) -> NSFastIterator; } @@ -661,7 +661,7 @@ extern { fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect; } -pub trait NSRunLoop { +pub trait NSRunLoop: Sized { unsafe fn currentRunLoop() -> Self; unsafe fn performSelector_target_argument_order_modes_(self, @@ -691,7 +691,7 @@ impl NSRunLoop for id { } } -pub trait NSData { +pub trait NSData: Sized { unsafe fn data(_: Self) -> id { msg_send![class("NSData"), data] } From 28b46b20adbbf507f94ee42dc40ae5fe5b81e3b0 Mon Sep 17 00:00:00 2001 From: foollbar Date: Sat, 16 Sep 2017 02:41:50 +0900 Subject: [PATCH 239/249] Remove unused imports --- examples/hello_world.rs | 2 +- examples/tab_view.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 4eed37d..46d40cf 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,7 +1,7 @@ extern crate cocoa; use cocoa::base::{selector, nil, NO}; -use cocoa::foundation::{NSUInteger, NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, +use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSString}; use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, NSTitledWindowMask, NSBackingStoreBuffered, NSMenu, NSMenuItem, diff --git a/examples/tab_view.rs b/examples/tab_view.rs index 72c1b3d..ead3a11 100644 --- a/examples/tab_view.rs +++ b/examples/tab_view.rs @@ -3,7 +3,7 @@ extern crate cocoa; use cocoa::base::{selector, id, nil, NO}; -use cocoa::foundation::{NSUInteger, NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, +use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSString}; use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, NSTitledWindowMask, NSBackingStoreBuffered, NSClosableWindowMask, From bc599eb017779e52166570bf5c17ab319595b8d7 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Mon, 18 Sep 2017 16:28:59 -0700 Subject: [PATCH 240/249] Bump core-graphics dependency and version --- Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 947efce..cd9b3ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,10 @@ + [package] 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.9.2" +version = "0.10.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -15,5 +16,5 @@ crate-type = ["rlib"] block = "0.1" bitflags = "0.9" libc = "0.2" -core-graphics = "0.8" +core-graphics = "0.9" objc = "0.2" From c4c75065c7fb34757a51ffdf2635f8f1216c68ab Mon Sep 17 00:00:00 2001 From: Barret Rennie Date: Wed, 4 Oct 2017 17:52:47 -0600 Subject: [PATCH 241/249] Support requesting user attention This patch adds the `NSRequestUserAttentionType` enum and the `NSApplication.requestUserAttention_` so applications can request attention from the user. --- src/appkit.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/appkit.rs b/src/appkit.rs index 39fe70c..86562c0 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -314,6 +314,13 @@ pub enum NSBezelStyle { NSRoundedDisclosureBezelStyle = 14, } +#[repr(u64)] +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum NSRequestUserAttentionType { + NSCriticalRequest = 0, + NSInformationalRequest = 10, +} + pub static NSMainMenuWindowLevel: libc::int32_t = 24; pub trait NSApplication: Sized { @@ -338,6 +345,7 @@ pub trait NSApplication: Sized { unsafe fn postEvent_atStart_(self, anEvent: id, flag: BOOL); unsafe fn stop_(self, sender: id); unsafe fn setApplicationIconImage_(self, image: id); + unsafe fn requestUserAttention_(self, requestType: NSRequestUserAttentionType); } impl NSApplication for id { @@ -399,6 +407,10 @@ impl NSApplication for id { unsafe fn setApplicationIconImage_(self, icon: id) { msg_send![self, setApplicationIconImage:icon] } + + unsafe fn requestUserAttention_(self, requestType: NSRequestUserAttentionType) { + msg_send![self, requestUserAttention:requestType] + } } pub trait NSRunningApplication: Sized { From cb8e0ad344afab59b5097abc88e2fe12c7d474b1 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Thu, 12 Oct 2017 12:09:09 +0200 Subject: [PATCH 242/249] Update bitflags to 1.0 and bump version --- Cargo.toml | 6 +++--- examples/hello_world.rs | 4 ++-- examples/tab_view.rs | 16 +++++++--------- src/appkit.rs | 30 +++++++++++++++--------------- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cd9b3ec..06a49a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,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.10.0" +version = "0.11.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -14,7 +14,7 @@ crate-type = ["rlib"] [dependencies] block = "0.1" -bitflags = "0.9" +bitflags = "1.0" libc = "0.2" -core-graphics = "0.9" +core-graphics = "0.10" objc = "0.2" diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 46d40cf..8f16df9 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -4,7 +4,7 @@ use cocoa::base::{selector, nil, NO}; use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSString}; use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, - NSTitledWindowMask, NSBackingStoreBuffered, NSMenu, NSMenuItem, + NSBackingStoreBuffered, NSMenu, NSMenuItem, NSWindowStyleMask, NSRunningApplication, NSApplicationActivateIgnoringOtherApps}; fn main() { @@ -37,7 +37,7 @@ fn main() { let window = NSWindow::alloc(nil) .initWithContentRect_styleMask_backing_defer_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), - NSTitledWindowMask, + NSWindowStyleMask::NSTitledWindowMask, NSBackingStoreBuffered, NO) .autorelease(); diff --git a/examples/tab_view.rs b/examples/tab_view.rs index ead3a11..985487f 100644 --- a/examples/tab_view.rs +++ b/examples/tab_view.rs @@ -6,9 +6,7 @@ use cocoa::base::{selector, id, nil, NO}; use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo, NSString}; use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow, - NSTitledWindowMask, NSBackingStoreBuffered, NSClosableWindowMask, - NSResizableWindowMask, NSMiniaturizableWindowMask, - NSUnifiedTitleAndToolbarWindowMask, NSMenu, NSMenuItem, NSTabView, + NSMenu, NSMenuItem, NSTabView, NSWindowStyleMask, NSBackingStoreType, NSTabViewItem, NSRunningApplication, NSApplicationActivateIgnoringOtherApps}; @@ -67,12 +65,12 @@ unsafe fn create_app(title: id, content: id) -> id { // create Window let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_( NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)), - NSTitledWindowMask | - NSClosableWindowMask | - NSResizableWindowMask | - NSMiniaturizableWindowMask | - NSUnifiedTitleAndToolbarWindowMask, - NSBackingStoreBuffered, + NSWindowStyleMask::NSTitledWindowMask | + NSWindowStyleMask::NSClosableWindowMask | + NSWindowStyleMask::NSResizableWindowMask | + NSWindowStyleMask::NSMiniaturizableWindowMask | + NSWindowStyleMask::NSUnifiedTitleAndToolbarWindowMask, + NSBackingStoreType::NSBackingStoreBuffered, NO ).autorelease(); window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.)); diff --git a/src/appkit.rs b/src/appkit.rs index 86562c0..688b930 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -202,18 +202,18 @@ bitflags! { const NSAlignWidthNearest = 1 << 20; const NSAlignHeightNearest = 1 << 21; const NSAlignRectFlipped = 1 << 63; - const NSAlignAllEdgesInward = NSAlignMinXInward.bits - | NSAlignMaxXInward.bits - | NSAlignMinYInward.bits - | NSAlignMaxYInward.bits; - const NSAlignAllEdgesOutward = NSAlignMinXOutward.bits - | NSAlignMaxXOutward.bits - | NSAlignMinYOutward.bits - | NSAlignMaxYOutward.bits; - const NSAlignAllEdgesNearest = NSAlignMinXNearest.bits - | NSAlignMaxXNearest.bits - | NSAlignMinYNearest.bits - | NSAlignMaxYNearest.bits; + const NSAlignAllEdgesInward = NSAlignmentOptions::NSAlignMinXInward.bits + | NSAlignmentOptions::NSAlignMaxXInward.bits + | NSAlignmentOptions::NSAlignMinYInward.bits + | NSAlignmentOptions::NSAlignMaxYInward.bits; + const NSAlignAllEdgesOutward = NSAlignmentOptions::NSAlignMinXOutward.bits + | NSAlignmentOptions::NSAlignMaxXOutward.bits + | NSAlignmentOptions::NSAlignMinYOutward.bits + | NSAlignmentOptions::NSAlignMaxYOutward.bits; + const NSAlignAllEdgesNearest = NSAlignmentOptions::NSAlignMinXNearest.bits + | NSAlignmentOptions::NSAlignMaxXNearest.bits + | NSAlignmentOptions::NSAlignMinYNearest.bits + | NSAlignmentOptions::NSAlignMaxYNearest.bits; } } @@ -1963,9 +1963,9 @@ bitflags! { const NSTouchPhaseStationary = 1 << 2; const NSTouchPhaseEnded = 1 << 3; const NSTouchPhaseCancelled = 1 << 4; - const NSTouchPhaseTouching = NSTouchPhaseBegan.bits - | NSTouchPhaseMoved.bits - | NSTouchPhaseStationary.bits; + const NSTouchPhaseTouching = NSTouchPhase::NSTouchPhaseBegan.bits + | NSTouchPhase::NSTouchPhaseMoved.bits + | NSTouchPhase::NSTouchPhaseStationary.bits; const NSTouchPhaseAny = !0; // NSUIntegerMax } } From f12143746508189308a7770b881fd88a1b3f7487 Mon Sep 17 00:00:00 2001 From: Thijs Vermeir Date: Sat, 14 Oct 2017 12:17:41 +0200 Subject: [PATCH 243/249] example: add space between quit and process name Add a space between "Quit" and the process name in the menu --- 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 8f16df9..4d5c1b0 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -22,7 +22,7 @@ fn main() { // create Application menu let app_menu = NSMenu::new(nil).autorelease(); - let quit_prefix = NSString::alloc(nil).init_str("Quit"); + let quit_prefix = NSString::alloc(nil).init_str("Quit "); let quit_title = quit_prefix.stringByAppendingString_(NSProcessInfo::processInfo(nil).processName()); let quit_action = selector("terminate:"); From cf04b6c8c9bae41e79a782bd8e0ccceab4fdcbad Mon Sep 17 00:00:00 2001 From: ratake <32758555+ratake@users.noreply.github.com> Date: Mon, 16 Oct 2017 21:35:51 -0700 Subject: [PATCH 244/249] Fix build on aarch64-apple-ios --- src/foundation.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/foundation.rs b/src/foundation.rs index 1693aad..78936c3 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -11,7 +11,7 @@ use std::mem; use std::ptr; -use base::{id, class, BOOL, SEL, nil}; +use base::{id, class, BOOL, NO, SEL, nil}; use block::Block; use core_graphics::base::CGFloat; use core_graphics::geometry::CGRect; @@ -546,7 +546,7 @@ 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 + rv != NO } unsafe fn stringByAppendingString_(self, other: id) -> id { From 1509438a8031dc04cc7d07ba1fe84a73cc9118a5 Mon Sep 17 00:00:00 2001 From: ratake <32758555+ratake@users.noreply.github.com> Date: Mon, 16 Oct 2017 23:38:13 -0700 Subject: [PATCH 245/249] Only expose AppKit and NSGeometry on macOS --- src/appkit.rs | 12 +++ src/base.rs | 12 --- src/foundation.rs | 202 ++++++++++++++++++++++++---------------------- src/lib.rs | 1 + 4 files changed, 118 insertions(+), 109 deletions(-) diff --git a/src/appkit.rs b/src/appkit.rs index 688b930..581c2cb 100644 --- a/src/appkit.rs +++ b/src/appkit.rs @@ -3740,3 +3740,15 @@ impl NSColor for id { msg_send![class("NSColor"), clearColor] } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + pub fn test_nsapp() { + unsafe { + let _nsApp = NSApp(); + } + } +} diff --git a/src/base.rs b/src/base.rs index f8546be..a864fd0 100644 --- a/src/base.rs +++ b/src/base.rs @@ -35,15 +35,3 @@ pub fn class(name: &str) -> Class { pub fn selector(name: &str) -> SEL { runtime::Sel::register(name) } - -#[cfg(test)] -mod test { - use super::*; - - #[test] - pub fn test_nsapp() { - unsafe { - let _nsApp: id = msg_send![class("NSApplication"), sharedApplication]; - } - } -} diff --git a/src/foundation.rs b/src/foundation.rs index 78936c3..90d3b15 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -9,14 +9,11 @@ #![allow(non_upper_case_globals)] -use std::mem; use std::ptr; use base::{id, class, BOOL, NO, SEL, nil}; use block::Block; -use core_graphics::base::CGFloat; -use core_graphics::geometry::CGRect; use libc; -use objc; + #[cfg(target_pointer_width = "32")] pub type NSInteger = libc::c_int; @@ -30,89 +27,123 @@ 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, -} +#[cfg(target_os = "macos")] +mod macos { + use std::mem; + use core_graphics::base::CGFloat; + use core_graphics::geometry::CGRect; + use objc; -impl NSPoint { - #[inline] - pub fn new(x: f64, y: f64) -> NSPoint { - NSPoint { - x: x, - y: y, - } + #[repr(C)] + #[derive(Copy, Clone)] + pub struct NSPoint { + pub x: f64, + pub y: f64, } -} -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)] -#[derive(Copy, Clone)] -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, - } - } -} - -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)] -#[derive(Copy, Clone)] -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 + impl NSPoint { + #[inline] + pub fn new(x: f64, y: f64) -> NSPoint { + NSPoint { + x: x, + y: y, + } } } - #[inline] - pub fn as_CGRect(&self) -> &CGRect { - unsafe { - mem::transmute::<&NSRect, &CGRect>(self) + 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) } } } - #[inline] - pub fn inset(&self, x: CGFloat, y: CGFloat) -> NSRect { - unsafe { - NSInsetRect(*self, x, y) + #[repr(C)] + #[derive(Copy, Clone)] + 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, + } } } + + 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)] + #[derive(Copy, Clone)] + 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 + } + } + + #[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) + } + } + } + + 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 { + NSRectMinXEdge, + NSRectMinYEdge, + NSRectMaxXEdge, + NSRectMaxYEdge, + } + + #[link(name = "Foundation", kind = "framework")] + extern { + fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect; + } } +#[cfg(target_os = "macos")] +pub use self::macos::*; + #[repr(C)] pub struct NSRange { pub location: NSUInteger, @@ -129,24 +160,6 @@ impl NSRange { } } -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 { - NSRectMinXEdge, - NSRectMinYEdge, - NSRectMaxXEdge, - NSRectMaxYEdge, -} - #[link(name = "Foundation", kind = "framework")] extern { pub static NSDefaultRunLoopMode: id; @@ -656,11 +669,6 @@ impl NSFastEnumeration for id { } } -#[link(name = "Foundation", kind = "framework")] -extern { - fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect; -} - pub trait NSRunLoop: Sized { unsafe fn currentRunLoop() -> Self; diff --git a/src/lib.rs b/src/lib.rs index d414970..9cdffbc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,7 @@ extern crate core_graphics; #[macro_use] extern crate objc; +#[cfg(target_os = "macos")] pub mod appkit; pub mod base; pub mod foundation; From f37a465990e9835dc8bf95b44566f40123a2f579 Mon Sep 17 00:00:00 2001 From: ratake <32758555+ratake@users.noreply.github.com> Date: Mon, 30 Oct 2017 21:08:52 -0700 Subject: [PATCH 246/249] Compile NSValue on macOS only Because it depends on NSSize/NSPoint. This fixes the build on iOS. --- src/foundation.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/foundation.rs b/src/foundation.rs index 90d3b15..71a3f5d 100644 --- a/src/foundation.rs +++ b/src/foundation.rs @@ -30,6 +30,7 @@ const UTF8_ENCODING: usize = 4; #[cfg(target_os = "macos")] mod macos { use std::mem; + use base::{id, class}; use core_graphics::base::CGFloat; use core_graphics::geometry::CGRect; use objc; @@ -139,6 +140,19 @@ mod macos { extern { fn NSInsetRect(rect: NSRect, x: CGFloat, y: CGFloat) -> NSRect; } + + pub trait NSValue: Sized { + 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 { + } } #[cfg(target_os = "macos")] @@ -200,19 +214,6 @@ impl NSProcessInfo for id { pub type NSTimeInterval = libc::c_double; -pub trait NSValue: Sized { - 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: Sized { unsafe fn array(_: Self) -> id { msg_send![class("NSArray"), array] From ebb3bebfdbf59440e24d930db25c083e30e419d9 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 17 Nov 2017 10:14:37 +0100 Subject: [PATCH 247/249] Update core-graphics to 0.11 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 06a49a3..0fd687d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,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.11.0" +version = "0.12.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -16,5 +16,5 @@ crate-type = ["rlib"] block = "0.1" bitflags = "1.0" libc = "0.2" -core-graphics = "0.10" +core-graphics = "0.11" objc = "0.2" From 8f3c195ac969bd5760b2013e966439d77e3257d7 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 17 Nov 2017 15:26:50 +0100 Subject: [PATCH 248/249] Update core-graphics to 0.12.1 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0fd687d..0c0b852 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,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.12.0" +version = "0.13.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -16,5 +16,5 @@ crate-type = ["rlib"] block = "0.1" bitflags = "1.0" libc = "0.2" -core-graphics = "0.11" +core-graphics = "0.12.1" objc = "0.2" From a9be9abd8145b51e008bb8af06559906ff2edfde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Fri, 12 Jan 2018 00:33:53 +0100 Subject: [PATCH 249/249] Depend on newer core-graphics and bump version --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0c0b852..a3530aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,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.13.0" +version = "0.14.0" authors = ["The Servo Project Developers"] license = "MIT / Apache-2.0" @@ -16,5 +16,5 @@ crate-type = ["rlib"] block = "0.1" bitflags = "1.0" libc = "0.2" -core-graphics = "0.12.1" +core-graphics = "0.13" objc = "0.2"