<?xml version="1.0"?>
<paste-with-annotations>
  <paste>
    <number>
      <integer>16539</integer>
    </number>
    <user>
      <string>slava</string>
    </user>
    <title>
      <string>WebKit demo</string>
    </title>
    <contents>
      <string>IN: webkit-test
USING: alien compiler io kernel math objc parser sequences ;

! Very rough Cocoa bridge demo.

! Problems:
! - does not release many objects; need to support autorelease
! - you cannot return to the REPL after, because we don't
!   support Cocoa events yet.

! Core Foundation utilities -- will be moved elsewhere
: kCFURLPOSIXPathStyle 0 ;

: kCFStringEncodingMacRoman 0 ;

FUNCTION: void* CFURLCreateWithFileSystemPath ( void* allocator, void* filePath, int pathStyle, bool isDirectory ) ; compiled

FUNCTION: void* CFURLCreateWithString ( void* allocator, void* string, void* base ) ; compiled

FUNCTION: void* CFStringCreateWithCString ( void* allocator, char* cStr, int encoding ) ; compiled

FUNCTION: void* CFBundleCreate ( void* allocator, void* bundleURL ) ; compiled

FUNCTION: void* CFBundleGetFunctionPointerForName ( void* bundle, void* functionName ) ; compiled

FUNCTION: bool CFBundleLoadExecutable ( void* bundle ) ; compiled

FUNCTION: void CFRelease ( void* cf ) ; compiled

: &lt;CFString&gt; ( string -- cf )
    f swap kCFStringEncodingMacRoman CFStringCreateWithCString ;

: &lt;CFFileSystemURL&gt; ( string dir? -- cf )
    &gt;r &lt;CFString&gt; f over kCFURLPOSIXPathStyle
    r&gt; CFURLCreateWithFileSystemPath swap CFRelease ;

: &lt;CFURL&gt; ( string -- cf )
    &lt;CFString&gt;
    [ f swap f CFURLCreateWithString ] keep
    CFRelease ;

: &lt;CFBundle&gt; ( string -- cf )
    t &lt;CFFileSystemURL&gt; f over CFBundleCreate swap CFRelease ;

! Cocoa, WebKit classes and messages

! We do this at parse time so that the following code can see
! the new words
: init-cocoa
    &quot;/System/Library/Frameworks/WebKit.framework&quot; &lt;CFBundle&gt;
    CFBundleLoadExecutable drop
    {
        &quot;NSObject&quot; &quot;NSWindow&quot;
        &quot;NSURLRequest&quot; &quot;NSApplication&quot; &quot;%NSURL&quot;
        &quot;WebView&quot; &quot;WebFrame&quot;
    } [ dup define-objc-class &quot;objc-&quot; swap append use+ ] each ;
    parsing

init-cocoa

! This will move elsewhere really soon...
BEGIN-STRUCT: NSRect
    FIELD: float x
    FIELD: float y
    FIELD: float w
    FIELD: float h
END-STRUCT

TYPEDEF: NSRect _NSRect

: &lt;NSRect&gt;
    &quot;NSRect&quot; &lt;c-object&gt;
    [ set-NSRect-h ] keep
    [ set-NSRect-w ] keep
    [ set-NSRect-y ] keep
    [ set-NSRect-x ] keep ;

: NSBorderlessWindowMask     0 ; inline
: NSTitledWindowMask         1 ; inline
: NSClosableWindowMask       2 ; inline
: NSMiniaturizableWindowMask 4 ; inline
: NSResizableWindowMask      8 ; inline

: NSBackingStoreRetained    0 ; inline
: NSBackingStoreNonretained 1 ; inline
: NSBackingStoreBuffered    2 ; inline

: &lt;NSURLRequest&gt; ( string -- id )
    NSURLRequest swap &lt;CFURL&gt; [requestWithURL:] ;

! The ugliest colon definition ever
: webkit-test
    NSWindow [alloc]
    10 10 600 600 &lt;NSRect&gt;
    NSTitledWindowMask NSClosableWindowMask NSMiniaturizableWindowMask NSResizableWindowMask bitor bitor bitor
    NSBackingStoreBuffered 1 [initWithContentRect:styleMask:backing:defer:]
    dup &quot;Hello world&quot; &lt;CFString&gt; [setTitle:]
    dup
    
    WebView [alloc] 10 10 600 600 &lt;NSRect&gt; f f [initWithFrame:frameName:groupName:]
    
    dup [mainFrame] &quot;http://factorcode.org&quot; &lt;NSURLRequest&gt; [loadRequest:]
    
    [setContentView:]
    
    dup f [makeKeyAndOrderFront:]
    NSApplication [sharedApplication] [run] ;

\ webkit-test compile

webkit-test</string>
    </contents>
    <universal-time>
      <integer>3348273257</integer>
    </universal-time>
    <channel>
      <string>#concatenative</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <null/>
    </is-unicode>
  </paste>
</paste-with-annotations>