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