1 ! Copyright (C) 2006, 2010 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types alien.syntax io kernel namespaces
4 core-foundation core-foundation.strings cocoa.messages cocoa
5 cocoa.classes cocoa.runtime sequences init summary
6 kernel.private assocs ;
9 : <NSString> ( str -- alien ) <CFString> -> autorelease ;
11 CONSTANT: NSApplicationDelegateReplySuccess 0
12 CONSTANT: NSApplicationDelegateReplyCancel 1
13 CONSTANT: NSApplicationDelegateReplyFailure 2
15 : with-autorelease-pool ( quot -- )
16 NSAutoreleasePool -> new [ call ] [ -> release ] bi* ; inline
18 : NSApp ( -- app ) NSApplication -> sharedApplication ;
20 CONSTANT: NSAnyEventMask 0xffffffff
22 FUNCTION: void NSBeep ( ) ;
24 : with-cocoa ( quot -- )
25 [ NSApp drop call ] with-autorelease-pool ; inline
27 : add-observer ( observer selector name object -- )
29 [ NSNotificationCenter -> defaultCenter ] 2dip
31 ] 2dip -> addObserver:selector:name:object: ;
33 : remove-observer ( observer -- )
34 [ NSNotificationCenter -> defaultCenter ] dip
37 : cocoa-app ( quot -- )
38 [ call NSApp -> run ] with-cocoa ; inline
40 : install-delegate ( receiver delegate -- )
41 -> alloc -> init -> setDelegate: ;
43 : running.app? ( -- ? )
44 #! Test if we're running a .app.
46 NSBundle -> mainBundle -> bundlePath CF>string
49 : assert.app ( message -- )
53 "The " " requires you to run Factor from an application bundle."