Cocoa GUI interface for Darwin based Forth systems.


Goals:

-- Similar in usage as other interfaces in MacForth and Mach2. Think of things like NEW-XXX ADD.XXX etc.

-- No hacks, no shortcuts. Should survive OS upgrades! Follow their rules.

-- Try to stay close to ObjC names and procedures. Makes Apple examples easy to follow and to implement.

Inevitable is breaking the rules.


Note: Cocoa interface runs in CarbonMacForth(2008), iForth(2009) and SwiftForth(2010).

      Current Mac OSX is Snow Leopard 10.6.8 and Lion 10.7.1

      Current development is in SwiftForth.

      Current target is ObjC runtime 2.


Examples shown with SwiftForth for OSX. Window named 'coco-sf' is the default I/O console and owned by Terminal.app running SwiftForth in a shell.


Interface to existing classes and methods:

   COCOACLASS ( <classname> -- ) ( -- class )   register class with the runtime and return ref when executed

   COCOAFUNC ( <selectorname> <parameters> -- ) ( n0 . . . ni -- n0 . . . ni nj )   register selector with the runtime and run as function when executed


Examples:

cocoaclass NSEvent

cocoafunc @mouseLocation ( -- point )

Note: -- the receiver is automaticly implied in the call setup

      -- I use a leading @ character in method names


Create new classes:

   NEW.CLASS ( parent <name> -- ) ( -- class )

   ADD.CLASS ( class -- )

   ADD.METHOD ( imp types name class -- )

   ADD.CLASSMETHOD ( imp types name class -- )

   ADD.IVAR ( type name class -- )


Example: buttons in NIB 'objects' created in Interfacebuilder are linked to methods in classes build with Forth.

         Screen shot 2011-02-28 at 10.36.17.jpg


Some of the most used spin offs, neccesities and conveniences for working with the Mac OS

   FRAMEWORK ( <name> -- ) same as Library /System/Library/Frameworks/name.framework/name

   2RET> ( n1 -- n1 n2 ) fetches the second returned parameter from call. See OSX Intel ABI.

   *might find a better name for this


Examples:

   framework Cocoa.framework

   : @mouse ( f: -- x y ) nsevent @mouselocation 2ret> swap sf>f sf>f ;


Much used GUI items needing Cocoa

   LOAD-FILE (including files using the file selector box) and cousins

   EDIT-FILE LOAD-EDIT LOAD-SCRAP Screen shot 2011-02-28 at 15.58.04.jpg


   

   NEW.WINDOW ( <name> -- ) ( -- wptr4 )

   ADD.WINDOW ( wptr4 -- )

   . . . and the rest of the window related family.    Screen shot 2011-02-28 at 10.03.46.jpg

   These words are similar to those found in MacForth and Mach2.


My stuff, won't bother or tire you with:

   pet words, Quartz 2D, audio, video, IPC, GDB, schedulers, interrupts, Applescript etc.

   

Still some window usage examples:

Screen shot 2011-02-28 at 15.08.03.jpg Redirect output to window: ioregistry listing (similar to device tree in Openfirmware)


     Showing photo's in a window, part of slideshow

     Screen shot 2011-02-28 at 15.13.55.jpg


     Drawing Quartz 2D in borderless window Screen shot 2011-02-28 at 15.17.02.jpg


     Screen shot 2011-02-28 at 15.19.19.jpg Window for web access with WebKit

   

Window becomes console for Forth I/O Screen shot 2011-02-28 at 15.11.33.jpg


Non Cocoa related examples:


A session with the resident GDB in a manner reminiscent of MacsBug

Screen shot 2011-02-28 at 15.38.16.jpg


Controlling SuperCollider with OpenSoundControl Screen shot 2011-02-28 at 15.53.03.jpg


Not used/implemented: standalone app without Terminal, programaticly creating menus, dialogs, controls, whatever other GUI widgets.

   For now: I could implement some and do research on others, but I'm not using these. Time is limited.

   You could use InterfaceBuilder supplying the actions with your cocoa-forth classes.

   The main menu for coco-sf is implemented, but as exercise and demo.

   

   Not in use. Screen shot 2011-02-28 at 10.49.07.jpg



--- draw line here, done! ---