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-15 01:20:59 -05:00
|
|
|
USING: alien errors gadgets io kernel namespaces objc
|
2006-03-12 23:21:01 -05:00
|
|
|
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-03-13 00:41:59 -05:00
|
|
|
: with-cocoa ( quot -- )
|
|
|
|
[
|
|
|
|
NSApplication [sharedApplication] drop
|
|
|
|
call
|
|
|
|
] with-autorelease-pool ; inline
|
|
|
|
|
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:] ;
|
|
|
|
|
|
|
|
: do-events ( app -- )
|
2006-03-14 01:22:33 -05:00
|
|
|
dup next-event [
|
|
|
|
dupd [ [sendEvent:] ] with-autorelease-pool do-events
|
|
|
|
] [
|
|
|
|
drop
|
|
|
|
] if* ;
|
2006-02-09 20:36:11 -05:00
|
|
|
|
2006-03-13 01:12:26 -05:00
|
|
|
: event-loop ( -- )
|
2006-02-09 20:36:11 -05:00
|
|
|
[
|
2006-03-12 23:21:01 -05:00
|
|
|
NSApplication [sharedApplication] do-events world-step
|
2006-03-13 01:12:26 -05:00
|
|
|
] with-autorelease-pool 10 sleep 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-02-19 22:08:08 -05:00
|
|
|
IN: errors
|
|
|
|
|
|
|
|
: objc-error. ( alien -- )
|
|
|
|
"Objective C exception:" print [reason] CF>string print ;
|