home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 10 / Fresh_Fish_10_2352.bin / new / dev / obero / oberon-a / examples / libraries / intuition / easyintuition.mod < prev    next >
Text File  |  1995-07-02  |  7KB  |  213 lines

  1. (***************************************************************************
  2.  
  3.      $RCSfile: EasyIntuition.mod $
  4.   Description: A port of easyintuition.c from the RKM:Libraries, Ch 2.
  5.  
  6.                "easyintuition.c  Simple backward-compatible V37 Intuition
  7.                example.
  8.  
  9.                This example uses extended structures with the pre-V37
  10.                OpenScreen() and OpenWindow() functions to compatibly open an
  11.                Intuition display.  Enhanced V37 options specified via tags
  12.                are ignored on 1.3 systems."
  13.  
  14.    Created by: fjc (Frank Copeland)
  15.     $Revision: 1.5 $
  16.       $Author: fjc $
  17.         $Date: 1995/01/25 23:52:19 $
  18.  
  19. ***************************************************************************)
  20.  
  21. <* STANDARD- *>
  22.  
  23. MODULE EasyIntuition;
  24.  
  25. IMPORT
  26.   SYS := SYSTEM, E := Exec, U := Utility, D := Dos, G := Graphics,
  27.   I := Intuition;
  28.  
  29. VAR
  30.  
  31. (*
  32.  *  We can specify that we want the V37-compatible 3D look when running
  33.  *  under V37 by adding an saPens tag.
  34.  *)
  35.  
  36.   pens : ARRAY 1 OF INTEGER; (* empty pen array to get default 3D look *)
  37.   ourscreentags : ARRAY 2 OF U.TagItem;
  38.  
  39. (*
  40.  *  ExtNewScreen is an extended NewScreen structure.
  41.  *  nsExtended flags that there is a tag pointer to additional
  42.  *  tag information at the end of this structure.  The tags will
  43.  *  be parsed by Release 2 but ignored by earlier OS versions.
  44.  *)
  45.  
  46.   fullHires : I.ExtNewScreen;
  47.  
  48. CONST
  49.  
  50. (* Position and sizes for our window *)
  51.  
  52.   winLeftEdge  =  20;
  53.   winTopEdge   =  20;
  54.   winWidth     = 400;
  55.   winMinWidth  =  80;
  56.   winHeight    = 150;
  57.   winMinHeight =  20;
  58.  
  59. (* Under V37, we'll get a special screen title when our window is active *)
  60.  
  61.   activetitle = "Our Screen - EasyWindow is Active";
  62.  
  63. VAR
  64.  
  65.   ourwindowtags : ARRAY 2 OF U.TagItem;
  66.  
  67. (*
  68.  *  ExtNewWindow is an extended NewWindow structure.
  69.  *  I.nwExtended indicates that there is a tag pointer to additional tag
  70.  *  information at the end of this structure.  The tags will be parsed
  71.  *  by Released 2 but ignored by earlier OS versions.
  72.  *)
  73.  
  74.   easyWindow : I.ExtNewWindow;
  75.  
  76. (*------------------------------------*)
  77. (*
  78.  *  Initialises global variables.  C does this at compile time.
  79.  *)
  80. PROCEDURE init ();
  81.  
  82. BEGIN (* init *)
  83.   pens [0] := -1; (* ~0 *)
  84.   ourscreentags [0].tag := I.saPens;
  85.   ourscreentags [0].data := SYS.ADR (pens);
  86.   ourscreentags [1].tag := U.done;
  87.   fullHires.ns.leftEdge := 0; (* must be zero prior to Release 2 *)
  88.   fullHires.ns.topEdge := 0;
  89.   fullHires.ns.width := 640; (* high-resolution *)
  90.   fullHires.ns.height := I.stdScreenHeight; (* non-interlace *)
  91.   fullHires.ns.depth := 2; (* 4 colors will be available *)
  92.   fullHires.ns.detailPen := 0; (* Default *)
  93.   fullHires.ns.blockPen := 1; (* Default *)
  94.   fullHires.ns.viewModes := {G.hires}; (* the high-resolution display mode *)
  95.   fullHires.ns.type := I.customScreen + {I.nsExtended}; (* the screen type *)
  96.   fullHires.ns.font := NIL; (* no special font *)
  97.   fullHires.ns.defaultTitle := SYS.ADR ("Our Screen");
  98.   fullHires.ns.gadgets := NIL; (* no custom screen gadgets (not supported) *)
  99.   fullHires.ns.customBitMap := NIL;
  100.   fullHires.extension := SYS.ADR (ourscreentags);
  101.                                     (* tags for additional V37 features *)
  102.   ourwindowtags [0].tag := I.waScreenTitle;
  103.   ourwindowtags [0].data := SYS.ADR (activetitle);
  104.   ourwindowtags [1].tag := U.done;
  105.   easyWindow.nw.leftEdge := winLeftEdge;
  106.   easyWindow.nw.topEdge := winTopEdge;
  107.   easyWindow.nw.width := winWidth;
  108.   easyWindow.nw.height := winHeight;
  109.   easyWindow.nw.detailPen := -1; (* Means use the screen's Detail
  110.   easyWindow.nw.blockPen := -1;     and Block Pens *)
  111.   easyWindow.nw.idcmpFlags := {I.closeWindow};
  112.   (* These flags specify system gadgets and other window attributes  *)
  113.   (* including the Extended flag which flags this as an ExtNewWindow *)
  114.   easyWindow.nw.flags :=
  115.     I.smartRefresh +
  116.     { I.windowClose, I.activate, I.windowDrag,
  117.       I.windowDepth, I.windowSizing, I.noCareRefresh,
  118.       I.nwExtended };
  119.   easyWindow.nw.firstGadget := NIL;
  120.   easyWindow.nw.checkMark := NIL;
  121.   easyWindow.nw.title := SYS.ADR("EasyWindow");
  122.   easyWindow.nw.screen := NIL; (* Attach a screen later *)
  123.   easyWindow.nw.bitMap := NIL; (* Let Intuition set up bitmap *)
  124.   easyWindow.nw.minWidth := winMinWidth;
  125.   easyWindow.nw.minHeight := winMinHeight;
  126.   easyWindow.nw.maxWidth := -1;
  127.   easyWindow.nw.maxHeight := -1;
  128.   easyWindow.nw.type := I.customScreen;
  129.   easyWindow.extension := SYS.ADR(ourwindowtags);
  130. END init;
  131.  
  132. (*------------------------------------*)
  133. PROCEDURE cleanExit (scrn : I.ScreenPtr; wind : I.WindowPtr);
  134.  
  135. BEGIN (* cleanExit *)
  136.   (* Close things in the reverse order of opening *)
  137.   IF wind # NIL THEN I.CloseWindow (wind) END;
  138.   IF scrn # NIL THEN IF I.CloseScreen (scrn) THEN END END;
  139. END cleanExit;
  140.  
  141. (*------------------------------------*)
  142. PROCEDURE handleIDCMP (win : I.WindowPtr) : BOOLEAN;
  143.  
  144.   VAR
  145.     done    : BOOLEAN;
  146.     message : I.IntuiMessagePtr;
  147.     class   : SET;
  148.  
  149. BEGIN (* handleIDCMP *)
  150.   done := FALSE;
  151.   (* Examine pending messages *)
  152.   LOOP
  153.     message := SYS.VAL (I.IntuiMessagePtr, E.GetMsg (win.userPort));
  154.     IF message = NIL THEN EXIT END;
  155.     class := message.class; (* get all the data we need from message *)
  156.  
  157.     (* When we're through with a message, reply *)
  158.     E.ReplyMsg (message);
  159.  
  160.     (* See what events occurred *)
  161.     IF I.closeWindow IN class THEN done := TRUE END;
  162.   END; (* LOOP *)
  163.   RETURN done
  164. END handleIDCMP;
  165.  
  166. (*------------------------------------*)
  167. PROCEDURE main ();
  168.  
  169.   VAR
  170.     signalmask, signals : SET;
  171.     winsignal : SHORTINT;
  172.     done      : BOOLEAN;
  173.     screen1   : I.ScreenPtr;
  174.     window1   : I.WindowPtr;
  175.  
  176. BEGIN (* main *)
  177.   done := FALSE; screen1 := NIL; window1 := NIL;
  178.  
  179.   (* Open the screen *)
  180.   screen1 := I.OpenScreen (fullHires);
  181.   IF screen1 = NIL THEN cleanExit (screen1, window1); HALT (D.warn) END;
  182.  
  183.   (* Attach the window to the open screen ... *)
  184.   easyWindow.nw.screen := screen1;
  185.  
  186.   (* ... and open the window *)
  187.   window1 := I.OpenWindow (easyWindow);
  188.   IF window1 = NIL THEN cleanExit (screen1, window1); HALT (D.warn) END;
  189.  
  190.   (* Set up the signals for the events we want to hear about ... *)
  191.   winsignal := window1.userPort.sigBit;
  192.   signalmask := {winsignal}; (* we are only waiting on IDCMP events. *)
  193.  
  194.   (* Here's the main input event loop where we wait for events.  *)
  195.   (* We have asked Intuition to send us CLOSEWINDOW IDCMP events *)
  196.   (* Exec will wake us if any event we are waiting for occurs.   *)
  197.   WHILE ~done DO
  198.     signals := E.Wait (signalmask);
  199.     (* An event occurred - now act on the signal(s) we received. *)
  200.     (* We were only waiting on one signal (winsignal) in our     *)
  201.     (* signalmask, so we actually know we received winsignal.    *)
  202.     IF winsignal IN signals THEN
  203.       done := handleIDCMP (window1)
  204.     END; (* IF *)
  205.   END; (* WHILE *)
  206.   cleanExit (screen1, window1); HALT (D.ok); (* Exit the program *)
  207. END main;
  208.  
  209. BEGIN (* EasyIntuition *)
  210.   init ();
  211.   main ();
  212. END EasyIntuition.
  213.