home *** CD-ROM | disk | FTP | other *** search
- MODULE Calculator;
-
- (* This module is an attempt at using Intuition from Modula-2.
-
- Note: "Wait" function must be imported frlom Fixes, instead of
- Tasks. The one in Tasks does not work.
-
- Created: Duncan Prindle, September 1, 1986
-
- Modified: Perhaps
-
- *)
-
- FROM CalcDisplay IMPORT DisplayX;
- FROM CalcFunctions IMPORT EXTENDX, ErrorType, X, SAME, DECI, NDeci;
- FROM CalcGadgets IMPORT InitBorder, InitGadgets, InitWindow,
- ErrorFunction, CalcButtonPtr, CalcButton;
- FROM CalcMenus IMPORT MenuHandle, InitMenus;
-
- FROM InOut IMPORT WriteLn, WriteString;
- FROM Intuition IMPORT
- IntuitionName, IntuitionBase,
- IDCMPFlags, IDCMPFlagSet,
- GadgetPtr, Gadget, GadgetFlags, GadgetFlagSet,
- ActivationFlags, ActivationFlagSet,
- BorderPtr, Border, DrawBorder, Requester,
- IntuitionTextPtr, IntuitionText, PrintIText,
- IntuiMessagePtr, IntuiMessage,
- WindowPtr, MenuPtr;
- FROM Libraries IMPORT OpenLibrary, CloseLibrary;
- FROM MathLib0 IMPORT log, power;
- FROM Menus IMPORT SetMenuStrip, ClearMenuStrip;
- FROM Ports IMPORT GetMsg;
- FROM Tasks IMPORT SignalSet, Wait;
- FROM Storage IMPORT ALLOCATE, CreateHeap, DEALLOCATE, DestroyHeap;
- FROM SYSTEM IMPORT ADR, BYTE, ADDRESS, LONGWORD, NULL;
- FROM Windows IMPORT CloseWindow;
-
-
-
- CONST
- IntuitionRev = 29;
-
- VAR
- HEAP : BOOLEAN;
- bPtr : ARRAY[0..3] OF BorderPtr;
- gPtr : ARRAY[0..46] OF GadgetPtr;
- Button : GadgetPtr;
- Signal : IntuiMessagePtr;
- Sig1 : SignalSet;
- CGadget : CARDINAL;
- Display : ARRAY[0..14] OF CHAR;
- DISPLAY : IntuitionText;
- wp : WindowPtr;
- KEY : CalcButtonPtr;
- menuPtr : MenuPtr;
-
-
-
-
- BEGIN
-
-
- (* Open intuition library *)
- IntuitionBase := OpenLibrary (IntuitionName,IntuitionRev);
- IF IntuitionBase = 0 THEN
- WriteString ("Open intuition failed"); WriteLn;
- END;
-
- (* Create Heap to contain dynamic storage *)
- HEAP := CreateHeap(15000);
- IF ~HEAP THEN
- WriteString('Heap was not created'); WriteLn;
- END;
-
- IF (IntuitionBase # 0) & (HEAP) THEN
-
-
- (* Initialize Gadgets *)
- InitBorder (bPtr);
- InitGadgets(gPtr, bPtr);
-
- (* Initialize the New window structure and open window *)
- NEW( wp );
- InitWindow ( wp, gPtr[0]);
-
- (* We draw bPtr[3] into window RastPort.
- This is the border for Calculator display *)
- DrawBorder( wp^.RPort^, bPtr[3]^, 8, 18 );
-
- (* Initialize Menu Strip *)
- menuPtr := InitMenus();
- SetMenuStrip( wp^ , menuPtr^ );
-
-
- (* Initialize display *)
- DisplayX( NoError, wp );
-
- (* Initialize the signal Mask *)
- Sig1 := SignalSet {};
- (* Convert signal number to a mask *)
- INCL (Sig1, CARDINAL (wp^.UserPort^.mpSigBit));
-
- (* Wait for message *)
- LOOP
- (* Wait for the signal *)
- Sig1 := Wait (Sig1);
- Signal := GetMsg( wp^.UserPort );
- IF Signal = NULL THEN
- EXIT;
- ELSE
- IF Signal^.Class = IDCMPFlagSet{CloseWindowFlag} THEN
- (* We have a close window request. Leave loop and close up *)
- EXIT;
- ELSIF Signal^.Class = IDCMPFlagSet{MenuPick} THEN
- (* We have a menu selection. Handle it. *)
- IF ~MenuHandle( Signal^.Code, wp ) THEN EXIT; END;
- (* We might have a new display mode *)
- DisplayX( NoError, wp );
- ELSE
- Button := Signal^.IAddress;
- CGadget := Button^.GadgetID;
- IF (CGadget >= 0) & (CGadget < 10) THEN
- EXTENDX( CGadget );
- DisplayX( NoError, wp );
- ELSIF CGadget <= 20 THEN
- KEY := Button^.UserData;
- DisplayX( KEY^.CalcKey(), wp );
- ELSE
- SAME := FALSE;
- DECI := FALSE;
- NDeci:= 0;
- KEY := Button^.UserData;
- DisplayX( KEY^.CalcKey(), wp );
- END;
- END;
- END;
- END;
-
- (* Close the window *)
- ClearMenuStrip(wp^);
- CloseWindow (wp^);
-
- (* Clean up *)
- CloseLibrary(IntuitionBase);
- DestroyHeap;
-
- END
- END Calculator.
-