home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-06-14 | 14.4 KB | 335 lines | [TEXT/PMED] |
- MODULE smallControl; (* 28.05.85 / Franz Kronseder *)
- (* last modified 31.05.85 *)
- (* this test program intends to try out the Toolbox routines *)
- (* of the Macintosh Control Manager. *)
- (* there are two windows, one for the Control Features and *)
- (* one for the Test-I/O Terminal. *)
-
- FROM SYSTEM IMPORT ADR,ADDRESS;
- FROM MacBase IMPORT RootRecord;
- FROM QuickDrawTypes IMPORT GrafPtr,Rect,QDGPointer,Pattern;
- FROM QuickDraw1 IMPORT GetPort,SetPort,DrawString,SetRect,FillRect,EraseRect,
- TextFont,TextSize,GlobalToLocal;
- FROM Terminal IMPORT ReadString,Read,Write,WriteLn,WriteString,ClearTerminal;
- FROM OutTerminal IMPORT WriteI,WriteB,WriteC;
- FROM PascalStrings IMPORT MakePascalString,MakeModulaString;
- FROM EventMgr IMPORT EventRecord,abortEvt,everyEvent,abortMask,EventAvail,
- FlushEvents,PostEvent,
- mouseDown,activateEvt,updateEvt;
- FROM WindowMgr IMPORT WindowRecord,WindowPtr,DocumentProc,DBoxProc,RDocProc,
- GetWMgrPort,NewWindow,CloseWindow,FrontWindow,SelectWindow,
- FindWindow,BeginUpdate,EndUpdate,
- DragWindow,SizeWindow,GrowWindow,
- inDrag,inGrow,inGoAway,inContent;
- FROM EventShell IMPORT addrearHandler,removeHandler,EventHandler;
- FROM TextEdit IMPORT TextBox,teJustCenter;
- FROM ControlMgr IMPORT ControlHandle,NewControl,KillControls,
- ShowControl,HideControl,DrawControls,FindControl,
- TrackControl,GetCtlValue,SetCtlValue,GetCTitle,SetCTitle,
- HiliteControl,
- ScrollBarProc,RadioButProc,CheckBoxProc,PushButProc,
- noControl,inButton,inCheckbox,inUpButton,inDownButton,
- inPageUp,inPageDown,inThumb;
-
- (*-----------------------------------------------------------------------------*)
- CONST systemFont=0; Monaco=4;
- activateBit=0;
- TYPE OsErr=INTEGER;
- (*-----------------------------------------------------------------------------*)
- VAR TSData : RECORD TSW:WindowPtr;
- TSWstorage:WindowRecord;
- TSWHandlerProc:EventHandler;
- TSWHid:CARDINAL;
- END;
- (* TSD=Test Screen Data, TSW=Test Screen Window *)
-
- PROCEDURE EnterTestScreen;
- (* put the Input/Output via MODULE Terminal into a Window called "Test Screen" *)
- CONST visible=TRUE;
- VAR TSWtitle: ARRAY[0..40] OF CHAR; boundsRect:Rect; ok:BOOLEAN;
- WPort:GrafPtr;
- BEGIN PaintScreenGray;
- WITH TSData DO
- GetWMgrPort(WPort); SetPort(WPort); TextFont(systemFont); TextSize(12);
- SetRect(boundsRect,5,250,405,340); MakePascalString("Test Screen",TSWtitle);
- TSW:=NewWindow(ADR(TSWstorage),boundsRect,ADR(TSWtitle),visible,
- DocumentProc,MacNIL,FALSE,ADR(TSData));
- SetPort(TSW); TextFont(Monaco); TextSize(9);ClearTerminal;
- addrearHandler(TSWHandler,TSWHid,ok);
- END(*with*);END EnterTestScreen;
-
- PROCEDURE LeaveTestScreen;
- VAR ok:BOOLEAN;
- BEGIN WITH TSData DO
- CloseWindow(TSW); removeHandler(TSWHid,ok);
- END(*with*); END LeaveTestScreen;
-
- PROCEDURE TSWHandler (VAR event:EventRecord):BOOLEAN;
- VAR findcode:INTEGER; whichWindow:WindowPtr; boundsRect:Rect;
- savePort,wPort:GrafPtr; growResult:ADDRESS;
- BEGIN WITH TSData DO WITH event DO
- CASE event.what
- OF mouseDown:
- findcode:=FindWindow(where.h,where.v,whichWindow);
- IF (whichWindow=TSW)
- THEN IF (FrontWindow()=TSW)
- THEN GetPort(savePort); GetWMgrPort(wPort); SetPort(wPort);
- CASE findcode
- OF inDrag: SetRect(boundsRect,4,24,508,300);
- DragWindow(whichWindow,where.h,where.v,boundsRect);
- | inGrow: SetRect(boundsRect,4,24,508,300);
- growResult:=GrowWindow(whichWindow,where.h,where.v,boundsRect);
- SizeWindow(whichWindow,INTEGER(growResult MOD ADDRESS(10000H)),
- INTEGER(growResult DIV ADDRESS(10000H)),FALSE);
- ELSE
- END;(*case findcode*)
- SetPort(savePort);
- ELSE SelectWindow(TSW); SetPort(TSW);
- END;(*if*)
- RETURN TRUE;
- ELSE RETURN FALSE;
- END;(*if*)
- | updateEvt: IF (ADDRESS(message)=TSW)
- THEN BeginUpdate(TSW); EndUpdate(TSW);
- RETURN TRUE;
- ELSE RETURN FALSE;
- END; (*if*)
- | activateEvt: IF (ADDRESS(message)=TSW)
- THEN
- RETURN TRUE;
- ELSE RETURN FALSE;
- END;
-
- ELSE RETURN FALSE; (* don't handle this event *)
- END;(*case*)
- END;(*with*) END;(*with*) END TSWHandler;
-
- PROCEDURE PaintScreenGray;
- VAR ScreenPort:GrafPtr;
- QDGPtr:QDGPointer; GrayPtr : POINTER TO Pattern;
- BEGIN QDGPtr:=RootRecord.patch3; GrayPtr:=ADR(QDGPtr^.gray );
- (* this is still a bit complicated, because QuickDraw doesn't *)
- (* yet export the QuickDraw global variables properly *)
- GetPort(ScreenPort);
- FillRect(ScreenPort^.portRect,GrayPtr^);
- END PaintScreenGray;
-
- PROCEDURE note(VAR text:ARRAY OF CHAR);
- (* write the text to the Test Screen Window *)
- VAR savePort:GrafPtr;
- BEGIN GetPort(savePort); SetPort(TSData.TSW);
- WriteString(text); WriteLn; Write(' ');
- SetPort(savePort);
- END note;
-
- PROCEDURE noteI(VAR text:ARRAY OF CHAR;i:INTEGER);
- (* write the text to the Test Screen Window *)
- VAR savePort:GrafPtr;
- BEGIN GetPort(savePort); SetPort(TSData.TSW);
- WriteString(text);WriteI(i,5); WriteLn; Write(' ');
- SetPort(savePort);
- END noteI;
-
- (*-----------------------------------------------------------------------------*)
- VAR CSData : RECORD CSW:WindowPtr;
- CSWstorage:WindowRecord;
- CSWHandlerProc:EventHandler;
- CSWHid:CARDINAL;
- bar1,bar2,button1,button2,
- rb1,rb2,rb3,rb4,chk1,chk2,chk3,chk4 :ControlHandle;
- (* scrollbar, pushbutton , radiobutton, checkbox *)
- END;
- (* CSD=Control Screen Data, CSW=Control Screen Window *)
-
- PROCEDURE EnterControlScreen;
- CONST visible=TRUE;
- VAR CSWtitle: ARRAY[0..40] OF CHAR; boundsRect:Rect; ok:BOOLEAN;
- savePort,WPort:GrafPtr;
- BEGIN WITH CSData DO
- GetPort(savePort);GetWMgrPort(WPort); SetPort(WPort); TextFont(systemFont); TextSize(12);
- SetRect(boundsRect,20,40,450,200); MakePascalString("Control Screen",CSWtitle);
- CSW:=NewWindow(ADR(CSWstorage),boundsRect,ADR(CSWtitle),visible,
- DocumentProc,MacNIL,FALSE,ADR(TSData));
- addrearHandler(CSWHandler,CSWHid,ok);
- MakeControls; SetPort(savePort);
- END(*with*);
- END EnterControlScreen;
-
- PROCEDURE LeaveControlScreen;
- VAR ok:BOOLEAN;
- BEGIN WITH CSData DO
- RemoveControls;
- CloseWindow(CSW); removeHandler(CSWHid,ok);
- END(*with*); END LeaveControlScreen;
-
- PROCEDURE CSWHandler (VAR event:EventRecord):BOOLEAN;
- VAR findcode:INTEGER; growResult:ADDRESS; whichWindow:WindowPtr;
- savePort,wPort:GrafPtr; boundsRect:Rect;
- PROCEDURE handletheControls():BOOLEAN;
- VAR theControl:ControlHandle; partCode:INTEGER;
- Title,MTitle:ARRAY[0..63]OF CHAR;
- BEGIN
- partCode:=FindControl(event.where,CSData.CSW,theControl);
- IF partCode=noControl
- THEN note("noControl"); RETURN FALSE;
- ELSE note("-----------------");
- GetCTitle(theControl,ADR(Title));MakeModulaString(Title,MTitle);
- note(MTitle);
- CASE partCode
- OF inButton: note("inButton ");
- IF (GetCtlValue(theControl)=0)
- THEN SetCtlValue(theControl,1);
- HiliteControl(theControl,inButton);
- ELSE SetCtlValue(theControl,0);
- HiliteControl(theControl,0);
- END;(*if*)
- | inCheckbox: note("inCheckbox ");
- IF (GetCtlValue(theControl)=0)
- THEN SetCtlValue(theControl,1);
- ELSE SetCtlValue(theControl,0); END;(*if*)
- | inUpButton: note("inUpButton ");
- | inDownButton: note("inDownButton ");
- | inPageUp: note("inPageUp ");
- | inPageDown: note("inPageDown ");
- | inThumb: note("inThumb ");
- noteI("TrackControl: ",
- TrackControl(theControl,event.where,ADDRESS(-1)));
- ELSE (*nothing*)
- END;(*case partcode*)
- noteI("GetCtlValue: ",GetCtlValue(theControl));
- RETURN TRUE;
- END;(*if partCode *)
- END handletheControls;
- BEGIN WITH CSData DO WITH event DO (* body of CSWHandler *)
- CASE event.what
- OF mouseDown:
- findcode:=FindWindow(where.h,where.v,whichWindow);
- IF (whichWindow=CSW)
- THEN GetPort(savePort); GetWMgrPort(wPort); SetPort(wPort);
- IF (FrontWindow()=CSW)
- THEN CASE findcode
- OF inDrag: SetRect(boundsRect,4,24,508,300);
- DragWindow(whichWindow,where.h,where.v,boundsRect);
- | inGrow: SetRect(boundsRect,4,24,508,300);
- growResult:=GrowWindow(whichWindow,where.h,where.v,boundsRect);
- SizeWindow(whichWindow,INTEGER(growResult MOD ADDRESS(10000H)),
- INTEGER(growResult DIV ADDRESS(10000H)),FALSE);
- | inContent: SetPort(CSW);GlobalToLocal(where);
- IF handletheControls()
- THEN (*do nothing*)
- ELSE
- END;
- ELSE (*do nothing*)
- END;(*case findcode*)
- ELSE SelectWindow(CSW);
- END;(*if*)
- SetPort(savePort);
- RETURN TRUE;
- ELSE RETURN FALSE;
- END;(*if*)
- | updateEvt: IF (ADDRESS(message)=CSW)
- THEN BeginUpdate(CSW); EndUpdate(CSW);
- RETURN TRUE;
- ELSE RETURN FALSE;
- END; (*if*)
- | activateEvt: IF (ADDRESS(message)=CSW)
- THEN GetPort(savePort); GetWMgrPort(wPort); SetPort(wPort);
- IF activateBit IN modifiers
- THEN (* activate*) DrawControls(CSW);
- ELSE (*deactivate*) SetPort(CSW); EraseRect(CSW^.portRect);
- END;
- SetPort(savePort);
- RETURN TRUE;
- ELSE RETURN FALSE;
- END;
-
- ELSE RETURN FALSE; (* don't handle this event *)
- END;(*case*)
- END;(*with*) END;(*with*) END CSWHandler;
-
- PROCEDURE MakeControls;
- CONST visible=TRUE;
- VAR Title:ARRAY[0..40] OF CHAR; boundsRect:Rect;
- BEGIN WITH CSData DO
- SetRect(boundsRect,40,20,240,35); MakePascalString("bar1",Title);
- bar1:=NewControl(CSW,boundsRect,ADR(Title),visible,50,0,100,
- ScrollBarProc,11223344);
- SetRect(boundsRect,5,40,20,300); MakePascalString("bar2",Title);
- bar2:=NewControl(CSW,boundsRect,ADR(Title),visible,0,-1000,+1000,
- ScrollBarProc,11223344);
-
- SetRect(boundsRect,50,50,120,70); MakePascalString("button1",Title);
- button1:=NewControl(CSW,boundsRect,ADR(Title),visible,0,0,1,
- PushButProc,11223344);
- SetRect(boundsRect,150,50,220,70); MakePascalString("button2",Title);
- button2:=NewControl(CSW,boundsRect,ADR(Title),visible,1,0,1,
- PushButProc,11223344);
-
- SetRect(boundsRect,50,100,95,125); MakePascalString("rb1",Title);
- rb1:=NewControl(CSW,boundsRect,ADR(Title),visible,0,0,1,
- RadioButProc,11223344);
- SetRect(boundsRect,100,100,145,125); MakePascalString("rb2",Title);
- rb2:=NewControl(CSW,boundsRect,ADR(Title),visible,1,0,1,
- RadioButProc,11223344);
- SetRect(boundsRect,150,100,195,125); MakePascalString("rb3",Title);
- rb3:=NewControl(CSW,boundsRect,ADR(Title),visible,0,0,1,
- RadioButProc,11223344);
- SetRect(boundsRect,200,100,245,125); MakePascalString("rb4",Title);
- rb4:=NewControl(CSW,boundsRect,ADR(Title),visible,1,0,1,
- RadioButProc,11223344);
-
- SetRect(boundsRect,50,150,100,175); MakePascalString("chk1",Title);
- chk1:=NewControl(CSW,boundsRect,ADR(Title),visible,1,0,1,
- CheckBoxProc,11223344);
- SetRect(boundsRect,50,175,100,200); MakePascalString("chk2",Title);
- chk2:=NewControl(CSW,boundsRect,ADR(Title),visible,0,0,1,
- CheckBoxProc,11223344);
- SetRect(boundsRect,50,200,100,225); MakePascalString("chk3",Title);
- chk3:=NewControl(CSW,boundsRect,ADR(Title),visible,1,0,1,
- CheckBoxProc,11223344);
- SetRect(boundsRect,50,225,100,250); MakePascalString("chk4",Title);
- chk4:=NewControl(CSW,boundsRect,ADR(Title),visible,0,0,1,
- CheckBoxProc,11223344);
- END;(*with*)END MakeControls;
-
- PROCEDURE RemoveControls;
- BEGIN WITH CSData DO
- KillControls(CSW);
- END; END RemoveControls;
- (*-----------------------------------------------------------------------------*)
- VAR MacNIL:ADDRESS; mainPort:GrafPtr;
-
- PROCEDURE EnterMain;
- (* initialize the main program *)
- BEGIN MacNIL:=000000H; GetPort(mainPort);
- FlushEvents(everyEvent,0);
- END EnterMain;
-
- PROCEDURE LeaveMain;
- (* undo the main program setup*)
- BEGIN SetPort(mainPort);
- END LeaveMain;
-
- PROCEDURE RunMainLoop;
- VAR Mzeile,zeile: ARRAY[0..80] OF CHAR;
- theEvent:EventRecord; echo:OsErr;
- BEGIN ClearTerminal;
- REPEAT WriteString("->"); ReadString(Mzeile);
- MakePascalString(Mzeile,zeile);
- IF ORD(zeile[0])=0
- THEN (* do nothing*)
- ELSE CASE CAP(zeile[1])
- OF "Q": echo:=PostEvent(abortEvt,0);
- ELSE (*DrawString(ADR(zeile)); *) WriteString(Mzeile); WriteLn;
- END;(*case*)
- END;(*if*)
- UNTIL EventAvail(abortMask,theEvent);
- END RunMainLoop;
-
- (*-----------------------------------------------------------------------------*)
- BEGIN (*body of smallControl*)
- EnterMain; EnterTestScreen; EnterControlScreen;
- RunMainLoop;
- LeaveControlScreen; LeaveTestScreen; LeaveMain;
- END smallControl.
-