home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-06-20 | 27.7 KB | 1,150 lines |
- 18-Jun-88 14:27:27-MDT,29426;000000000000
- Return-Path: <u-lchoqu%sunset@cs.utah.edu>
- Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:26:49 MDT
- Received: by cs.utah.edu (5.54/utah-2.0-cs)
- id AA22114; Sat, 18 Jun 88 14:26:49 MDT
- Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
- id AA24544; Sat, 18 Jun 88 14:26:44 MDT
- Date: Sat, 18 Jun 88 14:26:44 MDT
- From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
- Message-Id: <8806182026.AA24544@sunset.utah.edu>
- To: rthum@simtel20.arpa
- Subject: DialogMgrDA.p.shar
-
- #! /bin/sh
- #
- # This is a shell archive. Save this into a file, edit it
- # and delete all lines above this comment. Then give this
- # file to sh by executing the command "sh file". The files
- # will be extracted into the current directory owned by
- # you with default permissions.
- #
- # The files contained herein are:
- #
- # 9 DialogMgrDA.doc
- # 15 DialogMgrDA.p
- # 1 DialogMgrDA.r
- # 1 Example
- #
- echo 'Extracting DialogMgrDA.doc'
- if test -f DialogMgrDA.doc; then echo 'shar: will not overwrite DialogMgrDA.doc'; else
- sed 's/^X//' << '________This_Is_The_END________' > DialogMgrDA.doc
- X
- X
- XDialogManager DA
- X DialogManager DA
- X
- X
- X
- X
- X
- XWhy Dialog Manager?
- X
- X
- X
- XThis document is the result of a couple of weeks work preparing a
- Xpresentation on desk accessories for the November '86 meeting of the
- XMACincinnati Hacker Group. It is a DA shell in TML Pascal the fields typical
- Xevents that occur for a DA and executes most of its functions using the dialog
- Xmanager. It has a 'draggable' window, radio buttons, text boxes, a menu, and
- Xbuttons, buttons, buttons. It shows how to put up ModalDialogs without
- Xreentrancy problems, use global data, and handle activate/deactivate calls.
- XAnd it shows you three ways to close a DA.
- X
- X
- X
- XIts only 'features' are to multiply two integers and adjust your Mac clock to
- XDaylight Savings Time...
- X
- X
- X
- X
- X
- XContained in this .pit file should be:
- X
- X DialogManager.Doc this MacWrite file.
- X
- X DialogManager.acc the executable desk accessory file.
- X
- X DialogManagerDA.Pas the Pascal source code.
- X
- X DialogManagerDA.R the RMaker source code.
- X
- X DialogManagerDA.resed the resource file, created with ResEdit.
- X
- X
- X
- XThese files were created and compiled in an HFS folder named 'Development'
- Xon a volume (disk) named '20Meg'. In order to compile them you'll need version
- X2.0 of TML Pascal, RMaker, and the TML Linker. You will also need a USES file
- Xnamed 'MacIntf' in the 'Development' folder. You may use a different folder
- Xarrangement than I have used, but you'll have to insert your own paths in the
- Xproper places in the .Pas and .R files.
- X
- X
- X
- XI would welcome all questions and comments.
- X
- X
- X
- X
- X
- X
- X
- XBill Johnson
- X
- XMacCincinnati Hacker Group
- X
- XCompuserve: 72257,2064
- X
- XGEnie: W Johnson
- X
- XMacCincinnatus BBS: (606) 572-5375
- X
- X
- X
- X
- X
- XMain Data Structures
- X DialogManager DA
- X
- X
- X
- XTYPE
- X
- X DAGlobals = record { Global data. Store a handle to it in Device.dctlStorage }
- X Finished : boolean;
- X
- X ButtonNo : longint;
- X
- X Number: longint;
- X
- X NoText : longint;
- X
- X menuHand : menuHandle;
- X
- X StringArray : array[1..NoStrings] of str25;
- X end;
- X
- X
- X
- X DeviceControlRec = record {replace predefined DCtlEntry record in interface files }
- X dCtlDriver : Handle;
- X
- X dCtlFlags : Integer;
- X
- X dCtlQueue : Integer;
- X
- X dCtlQhead : Lptr;
- X
- X dCtlQtail : Lptr;
- X
- X dCtlPosition : longint;
- X
- X dCtlStorage : DAGlobalsH; {define as handle to global data}
- X dCtlRefNum : integer;
- X
- X dCtlCurTicks : longint;
- X
- X dCtlWindow : GrafPtr;
- X
- X dCtlDelay : integer;
- X
- X dCtlEmask : integer;
- X
- X dCtlMenu : integer;
- X
- X end;
- X
- X
- X
- X
- X
- XProcedures and Functions
- X
- X
- XDescription/Dependencies
- X
- X
- X
- X
- X
- XLow-Level Dialog Procedures
- X
- XPROCEDURE ItemActivate (theDialog : DialogPtr; ItemNo, HiliteMode : integer);
- X
- X ==Used to activate, deactivate, and hilite buttons==
- X
- X
- X
- XPROCEDURE SetRadioButton (theDialog: DialogPtr; ItemNo, ChkMark : integer);
- X
- X ==Used to, well, set radio buttons==
- X
- X
- X
- XFUNCTION GetTxtValue (theDialog : DialogPtr; ItemNo : Integer): longint;
- X
- X ==returns the numeric value of a textbox. Textbox must only contain integers==
- X
- X
- X
- X
- X
- XDrawing Procedures
- X
- XPROCEDURE HiliteDefButton (theDialog: DialogPtr);
- X
- X ==Draw the hiliting around the default button==
- X
- X
- X
- XPROCEDURE DrawEText (VAR DataRec: DAGlobals);
- X
- X ==Draws user-entered text in the dialog window==
- X
- X
- X
- XPROCEDURE DitlText(VAR DataRec: DAGlobals);
- X
- X ==Draws text for the DA after the Dialog Mgr is done==
- X
- X ==Calls: DrawEText();==
- X
- X
- X
- XPROCEDURE DitlLines;
- X
- X ==draw dotted lines in main window==
- X
- X
- X
- X
- X
- XSetup Procedure
- X
- XPROCEDURE InitDlogStatus(VAR device: DeviceControlRec);
- X
- X ==set buttons, cursor location, and initialize variables==
- X
- X
- X
- X
- X
- XModalDialog Procedures
- X
- XPROCEDURE DoAbout (DlogID : longint);
- X
- X ==put up the About Box, or the Command key dialog==
- X
- X
- X
- XPROCEDURE EnterText ( VAR Device: DeviceControlRec);
- X
- X ==put up modaldialog to accept text input in response to selection of the ICON==
- X
- X
- X
- X
- X
- XActivate, Deactivate, Update Procedures
- X
- XPROCEDURE UpdateDA(VAR device: DeviceControlRec);
- X
- X ==field Update calls, draw the window contents==
- X
- X ==Calls: DitlLines(); DitlText(); HiliteDefButton(); ==
- X
- X
- X
- XPROCEDURE DAactivate(VAR device: DeviceControlRec);
- X
- X ==activate call, put menu on the menu bar==
- X
- X
- X
- XPROCEDURE DAdeactivate(VAR device: DeviceControlRec);
- X
- X ==deactivate call, remove menu from the menu bar==
- X
- X
- X
- X
- X
- XButton Procedures
- X
- XPROCEDURE CtlRadioButtons (VAR Device : DeviceControlRec; WhichButton : integer);
- X
- X ==Manage the three radio buttons in the main dialog window==
- X
- X ==Call: SetRadioButton ();==
- X
- X
- X
- XPROCEDURE DoDefButton(VAR Device: DeviceControlRec);
- X
- X ==Enable the Reset button & multiply the contents of the text boxes==
- X
- X ==Call: GetTxtValue ();==
- X
- X
- X
- XPROCEDURE DoResetButton(VAR Device: DeviceControlRec);
- X
- X ==Clear and redraw the window==
- X
- X
- X
- XPROCEDURE DoTimeButton(VAR Device: DeviceControlRec);
- X
- X ==Put up Alert and set the clock chip ahead or back an hour==
- X
- X
- X
- X
- X
- XEvent Procedures
- X
- XPROCEDURE doKeyEvent (VAR Device: DeviceControlRec; EventPtr : EventPointer);
- X
- X ==Handle all keyboard events from here==
- X
- X ==Call: CtlRadioButtons (); DoResetButton(); DoTimeButton(); DoDefButton();==
- X
- X
- X
- XPROCEDURE Event(VAR Device : DeviceControlRec; VAR Block : ParamBlockRec);
- X
- X ==Handle _all_ events passed to the desk accessory==
- X
- X ==Call: DoDefButton(); DoAbout(); DoResetButton(); DoTimeButton(); CtlRadioButtons ();==
- X
- X ==Call: doKeyEvent(); UpdateDA(); DAactivate(); DAdeactivate();==
- X
- X
- X
- X
- X
- XOPEN Procedure
- X
- XPROCEDURE Open(VAR Device : DeviceControlRec; VAR Block : ParamBlockRec);
- X
- X ==Create main window, allocate globals, set WindowKind field, initialize variables, get Menu handle==
- X
- X ==Call: InitDlogStatus();==
- X
- X
- X
- X
- X
- XCONTROL Procedure
- X
- XPROCEDURE Ctl(VAR Device : DeviceControlRec; VAR Block : ParamBlockRec);
- X
- X ==Handle all calls made to the desk accessory - accEvent, accRun, accMenu==
- X
- X ==Call: Event(); DoAbout();==
- X
- X
- X
- X
- X
- XCLOSE Procedure
- X
- XPROCEDURE Close(VAR Device: DeviceControlRec; VAR Block : ParamBlockRec);
- X
- X ==Remove menu, dispose of window, dispose of globals, release Menu handle, set driver purgeable==
- X
- X ==Call: DAdeactivate();==
- X
- X
- X
- X
- X
- XNo Main Procedure Allowed
- X
- X
- X
- X
- X
- X
- X
- XOwned Resources
- X
- X
- X
- X
- XA desk accessory can have its own resources. But in order for those resources to be moved by the
- XFont/DA Mover, and avoid conflicts with other resources in the System file (the final destination of
- Xall desk accessories) they must have resource ID numbers within a designated range; 32 resource ID
- Xper DA starting at $C000.
- X
- X
- X
- XOwned resources can be calculated as follows:
- X
- X $C000 + (32 * DRVR ID#)
- X
- X
- X
- XSince the DialogManagerDA is assigned the ID number 16, the owned resources will be in the range
- Xof ($C200 -> $C20F), or -15872 through -15857.
- X
- X
- X
- X
- X
- X
- X
- XResource File
- X
- X
- XDialogManagerDA.resed
- X
- X
- X
- XThe resources in this file were created with ResEdit. They could all be generated while compiling
- Xresources with RMaker (the same way that the menu resource is), but it's easier to create them
- Xwith ResEdit.
- X
- X
- X
- X
- X
- XAlert Templates
- X
- X
- X
- XALRT, -15872 (sub ID #0) Do-nothing alert in response to the Bullseye.
- X
- XALRT, -15871 (sub ID #1) Alert for time change, w/ Cancel, Spring, and Fall buttons.
- X
- X
- X
- X
- X
- XDialog Item List
- X
- X
- X
- XDITL, -15872 (sub ID #0) Dialog item list for main window.
- X
- XDITL, -15871 (sub ID #1) Dialog item list for the 'About' dialog.
- X
- XDITL, -15870 (sub ID #2) Dialog item list for the text entry dialog.
- X
- XDITL, -15869 (sub ID #3) Dialog item list for the 'Command Keys' dialog.
- X
- XDITL, -15868 (sub ID #4) Dialog item list for the time change alert.
- X
- XDITL, -15867 (sub ID #5) Dialog item list for the bullseye alert.
- X
- X
- X
- X
- X
- XDialog Template
- X
- X
- X
- XDLOG, -15872 (sub ID #0) Dialog template for main window.
- X
- XDLOG, -15871 (sub ID #1) Dialog template for the text entry dialog.
- X
- X
- X
- X
- X
- XICON
- X
- X
- X
- XICON, -15872 (sub ID #0) Bullseye ICON. Called by the main dialog item list.
- X
- XICON, -15871 (sub ID #1) Text entry ICON. Called by the main dialog item list.
- X
- X
- X
- XResources
- X
- X
- XRMaker
- X
- X
- X
- XThe following is the RMaker file for DialogManager DA.
- X
- XIt's functions are to:
- X
- X a) Create an output file DialogManager.acc with correct TYPE & CREATOR
- X
- X b) Convert the .Rel file to DRVR resource & assign it an ID# of 16
- X
- X c) Create a MENU resource that is owned by DRVR #16
- X
- X d) Copy the resources from the DialogManagerDA.resed file into this file
- X
- X
- X
- X
- X
- X
- X
- XRMaker File
- X
- XDialogManagerDA.R
- X
- X
- X
- XNote the pathnames that precede the filenames. All input and output files are in an HFS folder named
- X'Development' on a volume named '20Meg'.
- X
- X
- X
- X
- X
- X* DialogManagerDA.R
- X
- X* Resource File for DialogManagerDA.Pas
- X
- X
- X
- X*Output file name and the Type and Creator flags
- X
- X20Meg:Development:DialogManager.acc
- X
- XDFILDMOV
- X
- X
- X
- XTYPE DRVR = PROC
- X
- X DialogManager DA,16
- X
- X20Meg:Development:DialogManagerDA
- X
- X
- X
- Xtype MENU
- X
- XDManMENU,-15872
- X
- XDialogManager;; menu title
- X
- XCommand Keys;;\CA menu1
- X
- X(-;; dotted line
- X
- XAbout...;; menu3
- X
- XQuit;; menu4
- X
- X
- X
- XINCLUDE 20Meg:Development:DialogManagerDA.resed
- X
- X
- X
- X
- X
- X
- X
- ________This_Is_The_END________
- if test `wc -l < DialogMgrDA.doc` -ne 520; then
- echo 'shar: DialogMgrDA.doc was damaged during transit'
- echo ' (should have been 520 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting DialogMgrDA.p'
- if test -f DialogMgrDA.p; then echo 'shar: will not overwrite DialogMgrDA.p'; else
- sed 's/^X//' << '________This_Is_The_END________' > DialogMgrDA.p
- XPROGRAM DialogManagerDA;
- X
- X(* Desk accessory to show the structure of DAs Beta version 0.9 __ 11/22/86
- X by William S. Johnson, with help from the MACincinnati Hacker Group.
- X Written in TML Pascal, version 2.0
- X
- XThis desk accessory is a shell you can use to understand the structure of DAs and how to use the Dialog
- XManager from a desk accessory. It makes use of buttons, ICONs, radio buttons, text boxes, and does
- Xsome drawing of its own. Its most useful feature will adjust your MAC to Daylight Savings Time......*)
- X
- XUSES MacIntf;
- X
- XCONST {dialog item list}
- X DefButton = 1; Chk_On = 1; {check on/off radio buttons}
- X QuitButton = 2; Chk_Off = 0;
- X AboutButton = 3;
- X Tbox = 4; CNTL_enable = 0; {enable controls}
- X TboxII = 5; CNTL_disable = 255;
- X RadioBut1 = 6;
- X RadioBut2 = 7; NoStrings = 3; { # of global strings }
- X RadioBut3 = 8;
- X BullsICON = 9;
- X TEnterICON = 10;
- X TimeButton = 11;
- X ResetButton = 12;
- X
- XTYPE
- X EventPointer = ^EventRecord;
- X Lptr = ^longint;
- X str25 = string[25]; { define a short string to consume less global space }
- X
- X DAGlobals = record { Global data. Store a handle to it in Device.dctlStorage }
- X Finished : boolean;
- X ButtonNo : longint;
- X Number: longint;
- X NoText : longint;
- X menuHand : menuHandle;
- X StringArray : array[1..NoStrings] of str25;
- X end;
- X
- X DAGlobalsP = ^DAGlobals; { define handle to DAGlobals record }
- X DAGlobalsH = ^DAGlobalsP;
- X
- X DeviceControlRec = record {replace predefined DCtlEntry record in interface files }
- X dCtlDriver : Handle;
- X dCtlFlags : Integer;
- X dCtlQueue : Integer;
- X dCtlQhead : Lptr;
- X dCtlQtail : Lptr;
- X dCtlPosition : longint;
- X dCtlStorage : DAGlobalsH; {define as handle to global data}
- X dCtlRefNum : integer;
- X dCtlCurTicks : longint;
- X dCtlWindow : GrafPtr;
- X dCtlDelay : integer;
- X dCtlEmask : integer;
- X dCtlMenu : integer;
- X end;
- X
- XPROCEDURE ItemActivate (theDialog : DialogPtr;ItemNo, HiliteMode : integer); { Activate & hilite buttons }
- XVar
- X ItemType: Integer;
- X ItemBox: Rect;
- X ItemHdl : Handle;
- XBegin
- X GetDItem(theDialog,ItemNo,ItemType,ItemHdl,ItemBox);
- X HiliteControl(ControlHandle(ItemHdl),HiliteMode);
- XEnd;
- X
- XPROCEDURE SetRadioButton (theDialog : DialogPtr; ItemNo, ChkMark : integer); { set on/off radio buttons }
- XVar
- X ItemType: Integer;
- X ItemBox: Rect;
- X ItemHdl: Handle;
- XBegin
- X GetDItem(theDialog,ItemNo,ItemType,ItemHdl,ItemBox);
- X SetCtlValue(ControlHandle(ItemHdl), ChkMark);
- XEnd;
- X
- XFUNCTION GetTxtValue (theDialog : DialogPtr; ItemNo : Integer): longint; { get integer from text box }
- XVar
- X ItemType : Integer;
- X ItemBox : Rect;
- X ItemHdl : Handle;
- X theString : Str255;
- X Value : longint;
- Xbegin
- X GetDItem(theDialog, ItemNo, ItemType, ItemHdl, ItemBox);
- X GetIText(ItemHdl, theString);
- X StringToNum (theString, Value);
- X GetTxtValue := Value;
- Xend;
- X
- XPROCEDURE HiliteDefButton (theDialog: DialogPtr);
- Xvar
- X ItemType: Integer;
- X ButtRect: rect;
- X ItemHdl : Handle;
- Xbegin
- X PenSize(3,3); {set pen size}
- X GetDItem(theDialog,1,ItemType,ItemHdl,ButtRect);
- X InsetRect(ButtRect,-4,-4);
- X FrameRoundRect(ButtRect,28,28);
- X PenSize(1,1); {reset pen size}
- Xend;
- X
- XPROCEDURE DrawEText (VAR DataRec: DAGlobals); { put text from Globals in dialog }
- XVar
- X VLoc, counter: integer;
- XBegin
- X with DataRec do begin
- X TextFont(3); { make Geneva 9 pt. the current font }
- X TextSize(9);
- X for counter := 1 to NoText do begin
- X VLoc := 80 + (counter*14);
- X MoveTo(12,VLoc);
- X DrawString ( StringArray[counter] );
- X end; {with DataRec do - for counter}
- X TextFont(0); { make Chicago 12 pt. the current font }
- X TextSize(12);
- X end;
- XEnd;
- X
- XPROCEDURE DitlText(VAR DataRec: DAGlobals); { Draw text and output data in main window }
- Xvar
- X aString : str255;
- Xbegin
- X with DataRec do begin
- X if (NoText > 0) then DrawEText (DataRec);
- X if (Number>0) then begin { draw result of multiplication }
- X MoveTo(300,76);
- X NumToString (Number, aString);
- X DrawString (aString);
- X end;
- X end;
- Xend;
- X
- XPROCEDURE DitlLines; { draw dotted lines in main window }
- Xvar
- X Pattrn : Pattern;
- Xbegin
- X GetIndPattern(Pattrn,0,4); {set pen pattern to gray}
- X PenPat(Pattrn);
- X MoveTo(182,40); { vertical line }
- X Line(0,194);
- X MoveTo(300,80); { horizontal line }
- X Line(50,0);
- X GetIndPattern(Pattrn,0,1); {reset pen pattern to black}
- X PenPat(Pattrn);
- Xend;
- X
- XPROCEDURE InitDlogStatus(VAR device: DeviceControlRec); { set buttons, globals, and cursor location }
- XBegin
- X with device do begin
- X SetRadioButton(DctlWindow, RadioBut1, Chk_On);
- X SetRadioButton(DctlWindow, RadioBut2, chk_off);
- X SetRadioButton(DctlWindow, RadioBut3, chk_off);
- X ItemActivate (DCtlWindow, ResetButton, CNTL_disable);
- X dCtlStorage^^.ButtonNo := 1;
- X dCtlStorage^^.NoText := 0;
- X dCtlStorage^^.Number := 0;
- X SelIText (DCtlWindow, Tbox, 0, 0); {jumpstart cursor in 1st textbox}
- X end;
- XEnd;
- X
- XPROCEDURE DoAbout (DlogID : longint);
- XVar
- X item : integer;
- X ViewRect : rect; {size of dialog window}
- X DITL_Hdl : handle;
- X AboutDptr : GrafPtr;
- XBegin
- X SetRect(ViewRect,68,50,444,220); {dialog box size- lf,tp,rt,bot}
- X DITL_Hdl := GetResource('DITL', DlogID);
- X if DITL_Hdl <> nil then begin
- X AboutDptr:= NewDialog(Nil, {Use _NewDialog_ to put up one of 2 different DITLs }
- X ViewRect, {size of this dialog box}
- X 'About Dialog', {title of this dialog - unused}
- X True, {dialog visible upon creation}
- X dBoxProc, {modal type}
- X POINTER(-1), {make it the frontmost window}
- X False, {no goAway box in the dialog}
- X 0, {RefCon variable in dialog record}
- X DITL_Hdl); {handle to the dialog itemlist}
- X ModalDialog(nil,item);
- X DisposDialog(AboutDptr);
- X DetachResource(DITL_Hdl);
- X end;
- XEnd;
- X
- XPROCEDURE EnterText ( VAR Device: DeviceControlRec);
- XVar
- X LoadDptr : DialogPtr;
- X itemno, ItemType : integer;
- X ItemBox : Rect;
- X ItemHdl : Handle;
- X theString : Str255;
- XBegin
- X LoadDptr:= GetNewDialog (device.dCtlMenu + 1, Nil, pointer(-1));
- X ModalDialog(nil, ItemNo);
- X With Device.Dctlstorage^^ do begin
- X NoText := NoText + 1;
- X GetDItem(LoadDptr, 2, ItemType, ItemHdl, ItemBox);
- X GetIText(ItemHdl, theString);
- X if (theString = '')
- X then NoText := NoText - 1
- X else StringArray[NoText] := copy (theString, 1, 25);
- X end;
- X DisposDialog(LoadDptr);
- XEnd;
- X
- XPROCEDURE UpdateDA(VAR device: DeviceControlRec); { update call - draw window contents }
- Xbegin
- X with device do begin
- X BeginUpdate(DialogPtr(dctlWindow));
- X DrawDialog(DialogPtr(dctlWindow));
- X DitlLines;
- X DitlText(dCtlStorage^^);
- X HiliteDefButton (DialogPtr(dctlWindow));
- X EndUpdate(DialogPtr(dctlWindow));
- X end;
- Xend;
- X
- XPROCEDURE DAactivate(VAR device: DeviceControlRec); { activate call - put menu on menu bar }
- Xbegin
- X with device do
- X with dCtlStorage^^ do begin
- X menuHand^^.menuID := DCtlMenu;
- X InsertMenu (menuHand,0);
- X DrawMenuBar;
- X end;
- Xend;
- X
- XPROCEDURE DAdeactivate(VAR device: DeviceControlRec); { deactivate - remove menu from menu bar }
- Xbegin
- X DeleteMenu(Device.DCtlMenu);
- X DrawMenuBar;
- Xend; { of DAdeactivate }
- X
- XPROCEDURE CtlRadioButtons (VAR Device : DeviceControlRec; WhichButton : integer);
- XBegin
- X with device.dctlstorage^^ do begin
- X SetRadioButton (Device.DCtlWindow, ButtonNo + 5, chk_off);
- X SetRadioButton (Device.DCtlWindow, WhichButton + 5, Chk_On);
- X ButtonNo := WhichButton;
- X end;
- XEnd;
- X
- XPROCEDURE DoDefButton(VAR Device: DeviceControlRec);
- XVar
- X NumOne, NumTwo : longint;
- X BigRec : rect;
- XBegin
- X with device do begin
- X SetRect(BigRec,-999,-999,999,999);
- X ItemActivate (DCtlWindow, ResetButton, CNTL_enable);
- X NumOne := GetTxtValue(dctlWindow, Tbox);
- X NumTwo := GetTxtValue(dctlWindow, TboxII);
- X dctlstorage^^.Number := NumOne * NumTwo;
- X EraseRect(BigRec);
- X InvalRect(BigRec); {force update}
- X end;
- XEnd;
- X
- XPROCEDURE DoResetButton(VAR Device: DeviceControlRec);
- XVar
- X BigRec : rect;
- XBegin
- X SetRect(BigRec,-999,-999,999,999);
- X InitDlogStatus(device);
- X EraseRect(BigRec);
- X InvalRect(BigRec); {force update}
- XEnd;
- X
- XPROCEDURE DoTimeButton(VAR Device: DeviceControlRec);
- XVar
- X OSErr : integer;
- X DismissItem : longint;
- X TimeAdjust, TimeInSec : longint;
- XBegin
- X DismissItem := Alert(device.dCtlMenu + 1, nil);
- X TimeAdjust := 0;
- X case DismissItem of
- X 2: TimeAdjust := 3600;
- X 3: TimeAdjust := -3600;
- X end;
- X GetDateTime (TimeInSec);
- X OSErr := SetDateTime (TimeInSec + TimeAdjust);
- XEnd;
- X
- XPROCEDURE doKeyEvent (VAR Device : DeviceControlRec; EventPtr : EventPointer);
- XConst {key codes}
- X CmdT = $74; Return = $03; Zero = $30;
- X CmdR = $72; Enter = $0D; Nine = $39;
- X CmdQ = $71; Tab = $09;
- X CmdB = $62; Backspace = $08;
- XVar
- X item, charCode : integer;
- X tmpDPtr : DialogPtr;
- X aFlag : boolean; { used as dummy variable in calling DialogSelect }
- X ButNum : longint; { used to set button in CtlRadioButton, & in Delay call }
- XBegin
- X with EventPtr^ do
- X with device.dctlstorage^^ do begin
- X charCode := BitAnd(message, charCodeMask);
- X if BitAnd (modifiers, cmdKey) <> 0
- X then case charCode of { ====== field allowable command keys ====== }
- X CmdB: { rotate radio buttons }
- X begin
- X if (ButtonNo = 3)
- X then ButNum := 1
- X else ButNum := ButtonNo + 1;
- X CtlRadioButtons (Device, ButNum);
- X end;
- X CmdR:
- X DoResetButton(device);
- X CmdT:
- X DoTimeButton(device);
- X CmdQ: { Quit }
- X Finished := True;
- X otherwise
- X Sysbeep(1); { ignore all other command keys }
- X end {of case}
- X else begin { ======== handle all other keys ======== }
- X if (charCode >= Zero) and (charCode <= Nine) { ===allow numeric keys=== }
- X then aFlag := DialogSelect (EventPtr^, tmpDptr, item)
- X else case charcode of { ===== allow some non-numeric keys===== }
- X Return, Enter:
- X begin
- X ItemActivate (Device.DCtlWindow, Defbutton, inButton);
- X Delay(15, ButNum);
- X ItemActivate (Device.DCtlWindow, Defbutton, CNTL_enable);
- X DoDefButton(device);
- X end;
- X Tab, Backspace:
- X aFlag := DialogSelect (EventPtr^, tmpDptr, item);
- X otherwise
- X Sysbeep(1); { ignore all other keys }
- X end; { of case charcode - non-numeric keys }
- X end; { of non-command keys }
- X end; { with device.dctlstorage^^ }
- XEnd;
- X
- XPROCEDURE Event(VAR Device : DeviceControlRec;
- X VAR Block : ParamBlockRec);
- XVar
- X item, DismissItem : integer;
- X tmpDPtr : DialogPtr;
- X EventPtr : EventPointer;
- X aFlag : boolean; { used as dummy variable in calling DialogSelect }
- X lastVal : longint; { used as dummy variable in DELAY proc }
- XBegin
- X blockMove(@block.csParam[0],@EventPtr,4);
- X with device.dctlstorage^^ do begin
- X case EventPtr^.what of
- X MouseDown:
- X begin
- X if DialogSelect (EventPtr^, tmpDptr, item) then { process if item is enabled }
- X case Item of
- X Defbutton:
- X DoDefButton(device);
- X Aboutbutton:
- X DoAbout(device.dctlMenu + 1);
- X QuitButton:
- X Finished := True;
- X ResetButton:
- X DoResetButton(device);
- X TimeButton:
- X DoTimeButton(device);
- X BullsICON:
- X DismissItem := Alert(device.dCtlMenu, nil);
- X TEnterICON:
- X If (NoText < NoStrings) then begin
- X EnterText (device);
- X DitlText(device.dctlStorage^^);
- X end;
- X RadioBut1:
- X CtlRadioButtons (Device, 1);
- X RadioBut2:
- X CtlRadioButtons (Device, 2);
- X RadioBut3:
- X CtlRadioButtons (Device, 3);
- X otherwise; { ignore all other mousedowns }
- X end; { if DialogSelect/case of item hit }
- X end; { MouseDown case }
- X KeyDown:
- X doKeyEvent (device, EventPtr);
- X UpdateEvt:
- X UpdateDA(device);
- X ActivateEvt:
- X if odd(EventPtr^.modifiers)
- X then DAactivate(device)
- X else DAdeactivate(device);
- X otherwise; { ignore all other events }
- X end; { case of what }
- X end; { with EventRecord }
- Xend; { Event Procedure }
- X
- XPROCEDURE Open(VAR Device : DeviceControlRec; VAR Block : ParamBlockRec);
- XVAR
- X TmpPtr: Ptr;
- X WPeek: WindowPeek;
- X ResourceID: Integer; {ID to the dialog item list & main reference ID for resources}
- XBEGIN { Open Procedure }
- X ResourceID := $BFE0 + 32 * (-Device.DCtlRefNum); { Compute main resource ID }
- X Device.dCtlMenu := ResourceID;
- X if Device.DctlWindow = nil then begin
- X Device.DctlStorage := DAGlobalsH(NewHandle(132));
- X TmpPtr := NewPtr($1000); { Create hole in the heap under Window record }
- X Device.DCtlWindow:= GetNewDialog (ResourceID, Nil, pointer(-1));
- X WPeek := pointer(ord(Device.DCtlWindow));
- X WPeek^.WindowKind := Device.DCtlRefNum; {set the WindowKind field to the DA RefNum }
- X SetPort(Device.DCtlWindow);
- X DisposPtr(TmpPtr);
- X
- X HLock (Handle (Device.dCtlstorage));
- X With Device.dCtlstorage^^ do begin
- X InitDlogStatus(device);
- X Finished := False; { set program terminator to false }
- X menuHand := GetMenu (ResourceID);
- X end;
- X HUnlock(Handle(Device.Dctlstorage));
- X end;
- XEND; { of Open }
- X
- XPROCEDURE Ctl (VAR Device : DeviceControlRec; VAR Block : ParamBlockRec);
- XCONST
- X accEvent = 64; accUndo = 68; accClear = 73;
- X accRun = 65; accCut = 70; CmdMenuNo = 1;
- X accCursor = 66; accCopy = 71; AboutMenuNo = 3;
- X accMenu = 67; accPaste = 72; QuitMenuNo = 4;
- XVAR
- X Done : boolean; { local pgm terminator - for calling CloseDeskAcc after globals unlocked }
- X DPeek : DialogPeek;
- XBEGIN { Main body of CTL Procedure }
- X BitClr(@Device.dCtlFlags, 5); { prevent CTL calls until done, since we use modaldialogs }
- X SetPort(Device.DCtlWindow); { Set the current grafport }
- X HLock(Handle(Device.DCtlStorage)); { lock DAGlobals down }
- X Done := False; { set local boolean program terminator }
- X with device.dctlStorage^^ do
- X with block do begin
- X case csCode of
- X accEvent:
- X Event(Device, Block);
- X accRun:
- X begin
- X DPeek := DialogPeek(Device.DCtlWindow);
- X TEIdle (DPeek^.textH); { blink caret in text box }
- X end;
- X accCursor: ;
- X accMenu:
- X begin
- X case csParam[1] of
- X CmdMenuNo:
- X DoAbout(device.dctlMenu + 3);
- X AboutMenuNo:
- X DoAbout(device.dctlMenu + 1);
- X QuitMenuNo:
- X Finished := True;
- X end; { case of menu }
- X HiliteMenu(0);
- X end; { menu case}
- X accUndo: ;
- X accCut: ;
- X accCopy: ;
- X accPaste: ;
- X accClear: ;
- X end; { case of csCode }
- X Done := Finished;
- X end; { of Block/device.dctlStorage^^ }
- X HUnLock(Handle(Device.DCtlStorage));
- X BitSet(@Device.dCtlFlags, 5); {Allow _Control calls again.}
- X if Done then CloseDeskAcc(Device.DCtlRefNum);
- XEND; { of Ctl }
- X
- XPROCEDURE Close(VAR Device: DeviceControlRec; VAR Block : ParamBlockRec);
- XBEGIN
- X DAdeactivate(device);
- X with Device do
- X begin
- X disposDialog(DialogPtr(dCtlWindow)); { dispose of window }
- X ReleaseResource (Handle (DCtlStorage^^.menuHand));
- X HPurge(Handle(dCtlDriver));
- X dctlWindow := nil;
- X disposHandle(Handle(dCtlStorage)); { Release private storage area }
- X dctlStorage := nil;
- X end;
- XEND; { of Close }
- X
- XBEGIN { No main program }
- XEND.
- ________This_Is_The_END________
- if test `wc -l < DialogMgrDA.p` -ne 491; then
- echo 'shar: DialogMgrDA.p was damaged during transit'
- echo ' (should have been 491 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting DialogMgrDA.r'
- if test -f DialogMgrDA.r; then echo 'shar: will not overwrite DialogMgrDA.r'; else
- sed 's/^X//' << '________This_Is_The_END________' > DialogMgrDA.r
- X* DialogManagerDA.R
- X* Resource file for DialogManagerDA.Pas
- X*
- X*Output file name and the Type and Creator flags
- X20Meg:Development:DialogManager.acc
- XDFILDMOV
- X
- XTYPE DRVR = PROC
- X DialogManager DA,16
- X20Meg:Development:DialogManagerDA
- X
- Xtype MENU
- XDManMENU,-15872
- XDialogManager;;\CA\CA\CA\CA\CAmenu title
- XCommand Keys;;\CA\CA\CA menu1
- X(-;;\CA\CA\CA\CA\CA\CA\CA\CA\CA\CA\CA\CA\CA dotted line
- XAbout...;;\CA\CA\CA menu3
- XQuit;; menu4
- X
- XINCLUDE 20Meg:Development:DialogManagerDA.resed
- X
- X
- ________This_Is_The_END________
- if test `wc -l < DialogMgrDA.r` -ne 22; then
- echo 'shar: DialogMgrDA.r was damaged during transit'
- echo ' (should have been 22 bytes)'
- fi
- fi ; : end of overwriting check
- echo 'Extracting Example'
- if test -f Example; then echo 'shar: will not overwrite Example'; else
- sed 's/^X//' << '________This_Is_The_END________' > Example
- Xtype DLOG
- X,128
- X77 63 260 434
- XVisible 1 NoGoAway 0
- X128
- X(No Title)
- X
- Xtype DITL
- X,128
- X10
- XIconItem Enabled
- X11 17 52 80
- X128
- X
- XStatText Enabled
- X20 90 37 265
- XDIALOG CREATION EXAMPLE
- X
- XStatText Enabled
- X68 44 109 326
- XThis example demonstrates the use of a multitude of different item types.
- X
- XBtnItem Enabled
- X141 132 179 241
- XOK
- X
- XBtnItem Enabled
- X141 254 179 366
- XCANCEL
- X
- XChkItem Enabled
- X114 8 132 133
- XI Like Examples
- X
- XRadioItem Enabled
- X114 143 131 228
- XThis is fun
- X
- XRadioItem Enabled
- X114 240 132 361
- XThis is very fun
- X
- XResCItem Enabled
- X141 10 178 116
- X130
- X
- XPicItem Disabled
- X4 277 62 366
- X129
- X
- X
- ________This_Is_The_END________
- if test `wc -l < Example` -ne 51; then
- echo 'shar: Example was damaged during transit'
- echo ' (should have been 51 bytes)'
- fi
- fi ; : end of overwriting check
- exit 0
-