2006-02-09 20:36:11 -05:00
|
|
|
! Copyright (C) 2006 Slava Pestov
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
IN: cocoa
|
2006-03-18 01:57:57 -05:00
|
|
|
USING: alien errors gadgets io kernel namespaces
|
2006-03-17 20:24:28 -05:00
|
|
|
objc objc-NSApplication objc-NSAutoreleasePool objc-NSException
|
2006-03-15 01:20:59 -05:00
|
|
|
objc-NSNotificationCenter objc-NSObject objc-NSView threads ;
|
2006-02-09 20:36:11 -05:00
|
|
|
|
|
|
|
: with-autorelease-pool ( quot -- )
|
2006-02-09 22:11:22 -05:00
|
|
|
NSAutoreleasePool [new] slip [release] ; inline
|
2006-02-09 20:36:11 -05:00
|
|
|
|
2006-05-18 22:01:38 -04:00
|
|
|
: NSApp NSApplication [sharedApplication] ;
|
|
|
|
|
2006-03-13 00:41:59 -05:00
|
|
|
: with-cocoa ( quot -- )
|
2006-05-18 22:01:38 -04:00
|
|
|
[ NSApp drop call ] with-autorelease-pool ;
|
2006-03-13 00:41:59 -05:00
|
|
|
|
2006-02-09 20:36:11 -05:00
|
|
|
: <NSString> <CFString> [autorelease] ;
|
|
|
|
|
2006-02-09 22:11:22 -05:00
|
|
|
: CFRunLoopDefaultMode "kCFRunLoopDefaultMode" <NSString> ;
|
|
|
|
|
|
|
|
: next-event ( app -- event )
|
|
|
|
0 f CFRunLoopDefaultMode 1
|
2006-02-09 20:36:11 -05:00
|
|
|
[nextEventMatchingMask:untilDate:inMode:dequeue:] ;
|
|
|
|
|
2006-03-19 18:18:12 -05:00
|
|
|
: do-event ( app -- ? )
|
|
|
|
[
|
|
|
|
dup next-event [ [sendEvent:] t ] [ drop f ] if*
|
|
|
|
] with-autorelease-pool ;
|
|
|
|
|
2006-02-09 20:36:11 -05:00
|
|
|
: do-events ( app -- )
|
2006-03-19 18:18:12 -05:00
|
|
|
dup do-event [ do-events ] [ drop ] if ;
|
2006-02-09 20:36:11 -05:00
|
|
|
|
2006-03-13 01:12:26 -05:00
|
|
|
: event-loop ( -- )
|
2006-05-18 22:01:38 -04:00
|
|
|
[ NSApp do-events ui-step ] with-autorelease-pool
|
|
|
|
event-loop ;
|
2006-02-19 22:08:08 -05:00
|
|
|
|
2006-03-15 01:20:59 -05:00
|
|
|
: add-observer ( observer selector name object -- )
|
|
|
|
>r >r >r >r NSNotificationCenter [defaultCenter] r> r>
|
|
|
|
sel_registerName r> r> [addObserver:selector:name:object:] ;
|
|
|
|
|
2006-03-21 01:43:03 -05:00
|
|
|
: remove-observer ( observer -- )
|
|
|
|
>r NSNotificationCenter [defaultCenter] r>
|
|
|
|
[removeObserver:] ;
|
|
|
|
|
2006-05-18 22:01:38 -04:00
|
|
|
: finish-launching ( -- ) NSApp [finishLaunching] ;
|
2006-03-17 02:50:16 -05:00
|
|
|
|
2006-02-19 22:08:08 -05:00
|
|
|
IN: errors
|
|
|
|
|
|
|
|
: objc-error. ( alien -- )
|
|
|
|
"Objective C exception:" print [reason] CF>string print ;
|