Working on Cocoa bindings
parent
21af22aa5b
commit
10df681132
|
@ -0,0 +1,26 @@
|
|||
! Copyright (C) 2006 Slava Pestov
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
IN: cocoa
|
||||
USING: errors kernel objc-NSApplication objc-NSAutoreleasePool
|
||||
objc-NSObject threads ;
|
||||
|
||||
: with-autorelease-pool ( quot -- )
|
||||
NSAutoreleasePool [new] [
|
||||
[ call ] keep
|
||||
] [
|
||||
drop [release]
|
||||
] cleanup ; inline
|
||||
|
||||
: <NSString> <CFString> [autorelease] ;
|
||||
|
||||
: next-event ( app -- )
|
||||
0 f "NSDefaultRunLoopMode" 1
|
||||
[nextEventMatchingMask:untilDate:inMode:dequeue:] ;
|
||||
|
||||
: do-events ( app -- )
|
||||
dup dup next-event [ [sendEvent:] do-events ] [ drop ] if* ;
|
||||
|
||||
: event-loop ( -- )
|
||||
[
|
||||
NSApplication [sharedApplication] do-events
|
||||
] with-autorelease-pool 10 sleep event-loop ;
|
|
@ -0,0 +1,44 @@
|
|||
! Copyright (C) 2006 Slava Pestov
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
IN: cocoa
|
||||
USING: alien kernel ;
|
||||
|
||||
BEGIN-STRUCT: NSRect
|
||||
FIELD: float x
|
||||
FIELD: float y
|
||||
FIELD: float w
|
||||
FIELD: float h
|
||||
END-STRUCT
|
||||
|
||||
TYPEDEF: NSRect _NSRect
|
||||
|
||||
: <NSRect>
|
||||
"NSRect" <c-object>
|
||||
[ set-NSRect-h ] keep
|
||||
[ set-NSRect-w ] keep
|
||||
[ set-NSRect-y ] keep
|
||||
[ set-NSRect-x ] keep ;
|
||||
|
||||
BEGIN-STRUCT: NSPoint
|
||||
FIELD: float x
|
||||
FIELD: float y
|
||||
END-STRUCT
|
||||
|
||||
TYPEDEF: NSPoint _NSPoint
|
||||
|
||||
: <NSPoint>
|
||||
"NSPoint" <c-object>
|
||||
[ set-NSPoint-y ] keep
|
||||
[ set-NSPoint-x ] keep ;
|
||||
|
||||
BEGIN-STRUCT: NSSize
|
||||
FIELD: float w
|
||||
FIELD: float h
|
||||
END-STRUCT
|
||||
|
||||
TYPEDEF: NSSize _NSSize
|
||||
|
||||
: <NSSize>
|
||||
"NSSize" <c-object>
|
||||
[ set-NSSize-h ] keep
|
||||
[ set-NSSize-w ] keep ;
|
|
@ -0,0 +1,48 @@
|
|||
! Copyright (C) 2006 Slava Pestov
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
IN: cocoa
|
||||
USING: hashtables kernel namespaces ;
|
||||
|
||||
! Core Foundation utilities -- will be moved elsewhere
|
||||
: kCFURLPOSIXPathStyle 0 ;
|
||||
|
||||
: kCFStringEncodingMacRoman 0 ;
|
||||
|
||||
FUNCTION: void* CFURLCreateWithFileSystemPath ( void* allocator, void* filePath, int pathStyle, bool isDirectory ) ;
|
||||
|
||||
FUNCTION: void* CFURLCreateWithString ( void* allocator, void* string, void* base ) ;
|
||||
|
||||
FUNCTION: void* CFStringCreateWithCString ( void* allocator, char* cStr, int encoding ) ;
|
||||
|
||||
FUNCTION: void* CFBundleCreate ( void* allocator, void* bundleURL ) ;
|
||||
|
||||
FUNCTION: void* CFBundleGetFunctionPointerForName ( void* bundle, void* functionName ) ;
|
||||
|
||||
FUNCTION: bool CFBundleLoadExecutable ( void* bundle ) ;
|
||||
|
||||
FUNCTION: void CFRelease ( void* cf ) ;
|
||||
|
||||
: <CFString> ( string -- cf )
|
||||
f swap kCFStringEncodingMacRoman CFStringCreateWithCString ;
|
||||
|
||||
: <CFFileSystemURL> ( string dir? -- cf )
|
||||
>r <CFString> f over kCFURLPOSIXPathStyle
|
||||
r> CFURLCreateWithFileSystemPath swap CFRelease ;
|
||||
|
||||
: <CFURL> ( string -- cf )
|
||||
<CFString>
|
||||
[ f swap f CFURLCreateWithString ] keep
|
||||
CFRelease ;
|
||||
|
||||
: <CFBundle> ( string -- cf )
|
||||
t <CFFileSystemURL> f over CFBundleCreate swap CFRelease ;
|
||||
|
||||
! A rough framework loader.
|
||||
SYMBOL: frameworks
|
||||
|
||||
: load-framework ( name -- )
|
||||
frameworks get [
|
||||
<CFBundle> dup CFBundleLoadExecutable drop
|
||||
] cache drop ;
|
||||
|
||||
H{ } clone frameworks set-global
|
|
@ -0,0 +1,38 @@
|
|||
! Copyright (C) 2006 Slava Pestov
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: cocoa compiler io kernel objc sequences words ;
|
||||
|
||||
"Compiling Objective C bridge..." print
|
||||
|
||||
{ "cocoa" "objc" } compile-vocabs
|
||||
|
||||
"Loading Cocoa frameworks..." print
|
||||
{
|
||||
"/System/Library/Frameworks/WebKit.framework"
|
||||
"/System/Library/Frameworks/QTKit.framework"
|
||||
"/System/Library/Frameworks/Quartz.framework/Frameworks/PDFKit.framework"
|
||||
} [
|
||||
dup print flush load-framework
|
||||
] each
|
||||
|
||||
"Importing Cocoa classes..." print
|
||||
{
|
||||
"NSApplication"
|
||||
"NSAutoreleasePool"
|
||||
"NSDate"
|
||||
"NSEvent"
|
||||
"NSInvocation"
|
||||
"NSMethodSignature"
|
||||
"NSObject"
|
||||
"NSOpenGLView"
|
||||
"NSSpeechSynthesizer"
|
||||
"NSURLRequest"
|
||||
"NSWindow"
|
||||
"PDFView"
|
||||
"QTMovie"
|
||||
"QTMovieView"
|
||||
"WebFrame"
|
||||
"WebView"
|
||||
} [
|
||||
dup print flush define-objc-class
|
||||
] each
|
|
@ -0,0 +1,16 @@
|
|||
USING: compiler io parser sequences words ;
|
||||
|
||||
{
|
||||
"/library/cocoa/objc-runtime.factor"
|
||||
"/library/cocoa/objc-utils.factor"
|
||||
"/library/cocoa/core-foundation.factor"
|
||||
"/library/cocoa/cocoa-types.factor"
|
||||
"/library/cocoa/init-cocoa.factor"
|
||||
"/library/cocoa/application-utils.factor"
|
||||
"/library/cocoa/window-utils.factor"
|
||||
} [
|
||||
run-resource
|
||||
] each
|
||||
|
||||
"Compiling Cocoa bindings..." print
|
||||
vocabs [ "objc-" head? ] subset compile-vocabs
|
|
@ -0,0 +1,25 @@
|
|||
! Copyright (C) 2006 Slava Pestov
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
IN: cocoa
|
||||
USING: kernel math objc-NSObject objc-NSWindow ;
|
||||
|
||||
: NSBorderlessWindowMask 0 ; inline
|
||||
: NSTitledWindowMask 1 ; inline
|
||||
: NSClosableWindowMask 2 ; inline
|
||||
: NSMiniaturizableWindowMask 4 ; inline
|
||||
: NSResizableWindowMask 8 ; inline
|
||||
|
||||
: NSBackingStoreRetained 0 ; inline
|
||||
: NSBackingStoreNonretained 1 ; inline
|
||||
: NSBackingStoreBuffered 2 ; inline
|
||||
|
||||
: standard-window-type
|
||||
NSTitledWindowMask
|
||||
NSClosableWindowMask bitor
|
||||
NSMiniaturizableWindowMask bitor
|
||||
NSResizableWindowMask bitor ; inline
|
||||
|
||||
: <NSWindow> ( title rect type -- window )
|
||||
NSWindow [alloc] -rot NSBackingStoreBuffered 1
|
||||
[initWithContentRect:styleMask:backing:defer:]
|
||||
[ swap <NSString> [setTitle:] ] keep ;
|
Loading…
Reference in New Issue