\ dialog gui support \ \ dialog \ generic, mac specific dialog box support. \ \ code: Han-earl Park \ copyright 2004 buster & friends' C-ALTO Labs \ (Southampton, September 2000 - \ \ MOD: HeP 09/15/00 Collected together commonly used dialog support code. \ MOD: HeP 03/19/01 Add DLOG.SET.CHECK for check boxes. \ MOD: HeP 03/22/01 Add DLOG.CLICK.BUTTON and words for activating and \ inactivating mac controls. \ Rewrite, fix and simplify DLOG.GET.INT. \ MOD: HeP 02-23-04 DLOG.CLICK.BUTTON's delay isn't affected by the rtc rate. anew task-dialog .NEED eol= : EOL= ( char -- flag , true if return of enter key ) dup EOL = swap 3 = OR ; .THEN .NEED HiliteControl() : HiliteControl() ( ControlHandle HiliteState -- ) pass: 42 trap: a95d ; .THEN \ dialog window : DLOG.OPEN ( var id# -- , open non-modal dialog box ) over @ IF drop @ SelectWindow() ELSE 0 -1 GetNewDialog() \ id# dStorage behind -- dlgPtr swap ! THEN ; : DLOG.CLOSE ( var -- , close dialog box if open ) dup @ dup IF DisposeDialog() \ var dlgPtr -- var 0 swap ! \ var -- ELSE 2drop \ var dlgPtr -- THEN ; \ dialog items : DLOG.ITEM.HANDLE@ ( dlogPtr item# -- itemHandle ) item-type item-handle item-box-rect GetDitem() \ dlogPtr item# itemType itemHandle boxRect -- \ item-handle @ ; \ (in)activate controls : INACTIVATE.CONTROL ( ControlHandle -- , greyout control ) 255 HiliteControl() ; : ACTIVATE.CONTROL ( ControlHandle -- , draw control as normal ) 0 HiliteControl() ; \ buttons 10 constant inButton : TICK.DELAY ( ticks -- , mac specific delay unaffected by rtc.rate ) tickcount() + BEGIN dup tickcount() time< UNTIL drop ; : DLOG.CLICK.BUTTON { dlogVar item# -- , simulate click on button } dlogVar @ item# dlog.item.handle@ dup inButton HiliteControl() 8 tick.delay 0 HiliteControl() ; \ check boxes : DLOG.SET.CHECK { flag dlogVar item# -- } dlogVar @ item# dlog.item.handle@ flag 0<> 1 AND SetCtlValue() \ ctrlHandle value -- ; \ text items : DLOG.SET.TEXT { new$ dlog$ dlogVar txtItem -- } dlog$ off new$ count dlog$ $append \ update dlog$ text string \ dlogVar @ txtItem dlog.item.handle@ dlog$ SetIText() \ itemHandle $ -- \ dlogVar @ txtItem 0 dlog$ c@ SeLIText() \ the-dialog itemno strtsel endsel -- ; : DLOG.GET.TEXT { dlogVar txtItem dlog$ -- dlog$ } dlogVar @ txtItem dlog.item.handle@ dlog$ GetIText() \ itemHandle varTxt -- \ dlog$ ; \ text item as number : DLOG.SET.INT ( n dlog$ dlogVar txtItem -- ) 2swap swap n>text text>string swap 2swap dlog.set.text ; : DLOG.GET.INT ( dlogVar txtItem dlog$ -- n flag ) dlog.get.text \ number? \ -- d true | false IF drop \ just want 32 bit precision \ dpl @ \ decimal point location dup 0> IF 0 DO 10 / LOOP ELSE drop THEN \ TRUE \ -- n true ELSE 0 FALSE \ -- 0 false THEN ; : INVALID.NUMBER.DIALOG ( -- , alert user of bad number entered ) " Invalid number!" dialog.a ; : OUT.OF.RANGE.DIALOG ( -- , alert user of bad number entered ) " Value entered is out of range!" dialog.a ; \ general purpose event handlers : DLOG.WINDOW.CONTENT ( -- ) FrontWindow() which-window @ - IF which-window @ SelectWindow() THEN ; : DLOG.WINDOW.DRAG ( -- ) which-window @ last-event ..@ er_where DragRect DragWindow() ; : DLOG.HANDLE.DOWN ( -- ) which-part @ CASE InContent OF dlog.window.content ENDOF InDrag OF dlog.window.drag ENDOF ENDCASE ; \ event handler :struct DlogTracker aptr dlog_EVHandler aptr dlog_MDHandler aptr dlog_Window ;struct : LINK.DLOG<->TRACKER ( dlog trckr -- ) 2dup swap wRefCon + ! \ store in wRefCon ..! dlog_Window ;