1 ! Copyright (C) 2006, 2008 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.syntax io kernel namespaces core-foundation
4 core-foundation.strings cocoa.messages cocoa cocoa.classes
5 cocoa.runtime sequences threads init summary kernel.private
9 : <NSString> ( str -- alien ) <CFString> -> autorelease ;
12 NSApplicationDelegateReplySuccess
13 NSApplicationDelegateReplyCancel
14 NSApplicationDelegateReplyFailure ;
16 : with-autorelease-pool ( quot -- )
17 NSAutoreleasePool -> new slip -> release ; inline
19 : NSApp ( -- app ) NSApplication -> sharedApplication ;
21 : NSAnyEventMask ( -- mask ) HEX: ffffffff ; inline
23 FUNCTION: void NSBeep ( ) ;
25 : with-cocoa ( quot -- )
26 [ NSApp drop call ] with-autorelease-pool ; inline
28 : add-observer ( observer selector name object -- )
30 [ NSNotificationCenter -> defaultCenter ] 2dip
32 ] 2dip -> addObserver:selector:name:object: ;
34 : remove-observer ( observer -- )
35 [ NSNotificationCenter -> defaultCenter ] dip
38 : cocoa-app ( quot -- )
39 [ call NSApp -> run ] with-cocoa ; inline
41 : install-delegate ( receiver delegate -- )
42 -> alloc -> init -> setDelegate: ;
44 TUPLE: objc-error alien reason ;
46 : objc-error ( alien -- * )
47 dup -> reason CF>string \ objc-error boa throw ;
49 M: objc-error summary ( error -- )
50 drop "Objective C exception" ;
52 [ [ objc-error ] 19 setenv ] "cocoa.application" add-init-hook
54 : running.app? ( -- ? )
55 #! Test if we're running a .app.
57 NSBundle -> mainBundle -> bundlePath CF>string
60 : assert.app ( message -- )
64 "The " " requires you to run Factor from an application bundle."