MODULE example;

(* EXAMPLE.MOD written 10/05/87 by Martin Murray for PW2
    last modified 09/15/88

********************************************************************************
*       THIS CODE IS IN NO WAY COPYRIGHT BY INOVATRONICS, INC.  IN FACT, YOU   *
*       CAN DO ANYTHING WITH IT THAT YOU WANT TO DO.  JUST REMEMBER,           *
*       INOVATRONICS, INC. WILL BEAR ABSOLUTELY NO RESPONSIBILITY FOR THE USE, *
*       MISUSE, INABILITY TO USE OR INABLITY TO UNDERSTAND ANY OR ALL PARTS OF *
*       THIS CODE.  ENJOY IT IN GOOD HEALTH.                                   *
********************************************************************************
********************************************************************************
*       THE PURPOSE OF THE CODE IS TO LET YOU SEE WHAT YOUR PowerWindows2      *
*       GENERATED SOURCE CODE WILL LOOK LIKE IN A PROGRAM.  IN MOST CASES, ALL *
*       YOU SHOULD HAVE TO DO IS COMPILE THIS FILE.  IT WILL  AUTOMATICALLY    *
*       INCLUDE YOUR SOURCE FILE, PROVIDED IT IS IN THE DEFAULT DIRECTORY, AND *
*       IS NAMED "PW2example".  JUST COMPILE IT, LINK IT AND RUN IT.  IT       *
*       DEFAULTS TO TERMINATING WHEN THE CLOSE GADGET IS HIT, BUT IF YOU LOOK  *
*       BELOW YOU'LL SEE HOW TO MAKE IT TERMINATE ON ANY EVENT AT ALL.         *
*       PLEASE NOTE: IT IS DESIGNED FOR ONLY 1 WINDOW.  IT WILL LOAD A SCREEN  *
*       AND A PALETTE IF THEY ARE PRESENT, BUT ONLY WINDOW NUMBER 1 AND ITS    *
*       PROGENY.  TRY IT FIRST WITH TDIEXAMPLE.PW.                             *
***************************************************************************** *)

(* NOTE:  Little error handling is used.
  Just open 'er up and hope for the best! *)

(* comment this if not using a CustomScreen *)
FROM Colors IMPORT LoadRGB4;
(* *)
FROM GraphicsLibrary IMPORT GraphicsBase, GraphicsName;
FROM Intuition IMPORT IntuitionBase, IntuitionName, ScreenFlagSet, NewWindow,
 Window, WBenchScreen, WindowPtr, WindowFlagSet, IDCMPFlagSet, MenuPick,
 IntuiMessagePtr, CloseWindowFlag, FreeRemember, GadgetUp, GadgetDown,
 ScreenPtr, DrawImage, DrawBorder, PrintIText;
(* uncomment this if using InovaTools1 functions
FROM ITools1 IMPORT InovaTools1Base, InovaTools1Name, DrawKnobs;
*)
FROM Libraries IMPORT OpenLibrary, CloseLibrary;
(* comment this if you don't have a menu *)
FROM Menus IMPORT SetMenuStrip, ClearMenuStrip, ItemAddress;
(* *)
FROM Ports IMPORT WaitPort, GetMsg, ReplyMsg, MessagePtr;
FROM PW2example IMPORT PW2example, NewWindowStructure1, PW2exampleRememberPtr,
 MenuList1, BorderList1, ImageList1, IntuiTextList1,
(* uncomment this for the event-handler
 HandleEvent,
*)
(* comment this if not using a CustomScreen *)
 NewScreenStructure, PaletteColorCount, Palette;
(* *)
(* comment this if not using a CustomScreen *)
FROM Rasters IMPORT RastPortPtr;
FROM Screens IMPORT OpenScreen, CloseScreen;
(* *)
FROM SYSTEM IMPORT NULL, ADDRESS, ADR;
FROM Windows IMPORT OpenWindow, CloseWindow;

VAR
        w : WindowPtr;
        r : RastPortPtr;
(* comment this if not using a CustomScreen *)
        s : ScreenPtr;
(* *)
        message : IntuiMessagePtr;
        amessage : MessagePtr;
        class : IDCMPFlagSet;
        code : CARDINAL;
        object : ADDRESS;
        memoryOK : BOOLEAN;

BEGIN
        IntuitionBase := OpenLibrary(IntuitionName,0);
        GraphicsBase := OpenLibrary(GraphicsName,0);
(* uncomment this if using InovaTools1 functions
        InovaTools1Base := OpenLibrary(InovaTools1Name,0);
*)
        memoryOK := PW2example();        (* allocate all the PW2 data *)

        IF (memoryOK) THEN        (* proceed ONLY if the memory was there *)
(* comment this if not using a CustomScreen *)
        s := OpenScreen(ADR(NewScreenStructure^));
        NewWindowStructure1^.Screen := s;
        LoadRGB4(ADR(s^.VPort),ADR(Palette),PaletteColorCount);
(* *)
        w := OpenWindow(NewWindowStructure1^);
(* comment this if you don't have a menu, and then IMPORT it from PW2example *)
        SetMenuStrip(w,MenuList1^);
(* *)
(* now we assign the RastPort pointer and draw in the free standing Render *)
        r := w^.RPort;
        DrawImage(r,ImageList1^,0,0);
        DrawBorder(r,BorderList1^,0,0);
        PrintIText(r,IntuiTextList1^,0,0);
(* *)
(* uncomment this if using Knobs and IMPORT the KnobList from PW2example
        DrawKnobs(w^,KnobsList1^);
*)
        WHILE (class <> IDCMPFlagSet{CloseWindowFlag}) DO
                amessage := WaitPort(w^.UserPort);
                message := GetMsg(w^.UserPort);
                class :=message^.Class;
                code :=message^.Code;
                object :=message^.IAddress;
                ReplyMsg(MessagePtr(message));

(* uncomment this for the event-handler, and then IMPORT it from PW2example
                IF (class = IDCMPFlagSet{MenuPick}) THEN HandleEvent(ItemAddress(Menu1^,code)); END;
                IF (class = IDCMPFlagSet{GadgetUp}) THEN HandleEvent(object); END;
                IF (class = IDCMPFlagSet{GadgetDown}) THEN HandleEvent(object); END;
*)
(* uncomment this if using Knobs
                IF (class = IDCMPFlagsSet{MouseButtons}) AND (code = SelectDown)
                        THEN KnobGadgets(w^,KnobsList1^);
*)

        END;

(* comment this if you don't have a menu, and then IMPORT it from PW2example *)
        ClearMenuStrip(w);
(* *)
        CloseWindow(w);
(* comment this if not using a CustomScreen *)
        CloseScreen(s);
(* *)
        END;

        FreeRemember(PW2exampleRememberPtr,TRUE);

(* uncomment this if using InovaTools1 functions
        CloseLibrary(InovaTools1Base);
*)
        CloseLibrary(GraphicsBase);
        CloseLibrary(IntuitionBase);

END example.
