home *** CD-ROM | disk | FTP | other *** search
- (*************************************************************************
-
- $RCSfile: SimpleGadget.mod $
- Description: Port of simplegtgadget.c from RKM:Libraries
-
- Created by: fjc (Frank Copeland)
- $Revision: 1.6 $
- $Author: fjc $
- $Date: 1995/07/02 16:59:15 $
-
- Copyright © 1994-1995, Frank Copeland.
- This example program is part of Oberon-A.
- See Oberon-A.doc for conditions of use and distribution.
-
- *************************************************************************)
-
- <* STANDARD- *>
-
- MODULE SimpleGadget;
-
- IMPORT
- SYS := SYSTEM,
- e := Exec,
- u := Utility,
- g := Graphics,
- i := Intuition,
- gt := GadTools,
- IO := StdIO;
-
- CONST
- VersionTag = "$VER: SimpleGadget 1.2 (23.1.95)\r\n";
-
- (* Gadget defines of out choosing, to be used as GadgetID's. *)
- mygadButton = 4;
-
- VAR
- Topaz80 : g.TextAttr;
-
- (*------------------------------------*)
- PROCEDURE Init ();
-
- BEGIN (* Init *)
- Topaz80.name := SYS.ADR ("topaz.font");
- Topaz80.ySize := 8;
- Topaz80.style := {};
- Topaz80.flags := {}
- END Init;
-
- (*
- ** Standard message handling loop with GadTools message handling functions
- ** used (GetIMsg() and ReplyIMsg()).
- *)
- PROCEDURE ProcessWindowEvents (win : i.WindowPtr);
-
- VAR
- imsg : i.IntuiMessagePtr;
- gad : i.GadgetPtr;
- terminated : BOOLEAN;
- signals : SET;
-
- BEGIN (* ProcessWindowEvents *)
- terminated := FALSE;
- WHILE ~terminated DO
- signals := e.Wait ({win.userPort.sigBit});
-
- (* Use GetIMsg() and ReplyIMsg() for handling *)
- (* IntuiMessages with GadTools gadgets. *)
- LOOP
- IF terminated THEN EXIT END;
- imsg := gt.GetIMsg (win.userPort);
- IF imsg = NIL THEN EXIT END;
- IF imsg.class = {i.gadgetUp} THEN
- gad := imsg.iAddress;
- IF gad.gadgetID = mygadButton THEN
- IO.WriteStr ("Button was pressed\n")
- END
- ELSIF imsg.class = {i.closeWindow} THEN
- terminated := TRUE
- ELSIF imsg.class = {i.refreshWindow} THEN
- (* This handling is REQUIRED with GadTools *)
- gt.BeginRefresh (win);
- gt.EndRefresh (win, e.LTRUE)
- END;
- (* Use the toolkit message-replying function here... *)
- gt.ReplyIMsg (imsg)
- END;
-
- END;
- END ProcessWindowEvents;
-
- (*
- ** Prepare for using GadTools, set up gadgets and open window.
- ** Clean up and when done or on error.
- *)
- PROCEDURE GadtoolsWindow ();
-
- VAR
- mysc : i.ScreenPtr;
- mywin : i.WindowPtr;
- glist, gad : i.GadgetPtr;
- ng : gt.NewGadget;
- vi : gt.VisualInfo;
-
- BEGIN (* GadtoolsWindow *)
- glist := NIL;
- mysc := i.LockPubScreen (e.NILSTR);
- IF mysc # NIL THEN
- vi := gt.GetVisualInfo (mysc, u.end);
- IF vi # NIL THEN
- (* GadTools gadgets require this step to be taken *)
- gad := gt.CreateContext (glist);
-
- (* create a button gadget centered below the window title *)
- ng.textAttr := SYS.ADR (Topaz80);
- ng.visualInfo := vi;
- ng.leftEdge := 150;
- ng.topEdge := 20 + mysc.wBorTop + (mysc.font.ySize + 1);
- ng.width := 100;
- ng.height := 12;
- ng.gadgetText := SYS.ADR ("Click Here");
- ng.gadgetID := mygadButton;
- ng.flags := {};
- gad := gt.CreateGadget (gt.buttonKind, gad, ng, u.end);
-
- IF gad # NIL THEN
- mywin := i.OpenWindowTagsA
- ( NIL,
- i.waTitle, SYS.ADR ("GadTools Gadget Demo"),
- i.waGadgets, glist, i.waAutoAdjust, e.LTRUE,
- i.waWidth, 400, i.waInnerHeight, 100,
- i.waDragBar, e.LTRUE, i.waDepthGadget, e.LTRUE,
- i.waActivate, e.LTRUE, i.waCloseGadget, e.LTRUE,
- i.waIDCMP, gt.buttonIDCMP +
- {i.closeWindow, i.refreshWindow},
- i.waPubScreen, mysc,
- u.end );
- IF mywin # NIL THEN
- gt.RefreshWindow (mywin, NIL);
- ProcessWindowEvents (mywin);
- i.CloseWindow (mywin)
- END;
- END;
- (* FreeGadgets() must be called after the context has been
- ** created. It does nothing if glist is NIL.
- *)
- gt.FreeGadgets (glist);
- gt.FreeVisualInfo (vi)
- END;
- i.UnlockPubScreen ("", mysc)
- END;
- END GadtoolsWindow;
-
- BEGIN (* SimpleGadget *)
- IF i.base.libNode.version >= 37 THEN
- ASSERT (gt.base # NIL, 100);
- Init;
- GadtoolsWindow ()
- END;
- END SimpleGadget.
-