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

  1. (*************************************************************************
  2.  
  3.      $RCSfile: EasyIntuition37.mod $
  4.   Description: A port of easyintuition37.c from the RKM:Libraries, Ch 2.
  5.                "easyintuition37.c -- Simple Intuition program for V37"
  6.                "(Release 2) and later versions of the operating system."
  7.  
  8.    Created by: fjc (Frank Copeland)
  9.     $Revision: 1.5 $
  10.       $Author: fjc $
  11.         $Date: 1995/01/25 23:52:19 $
  12.  
  13. *************************************************************************)
  14.  
  15. <* STANDARD- *>
  16.  
  17. MODULE EasyIntuition37;
  18.  
  19. IMPORT
  20.   SYS := SYSTEM, E := Exec, U := Utility, D := Dos, G := Graphics,
  21.   I := Intuition;
  22.  
  23. CONST
  24.  
  25. (* Position and sizes for our window *)
  26.  
  27.   winLeftEdge  =  20;
  28.   winTopEdge   =  20;
  29.   winWidth     = 400;
  30.   winMinWidth  =  80;
  31.   winHeight    = 150;
  32.   winMinHeight =  20;
  33.  
  34. (*------------------------------------*)
  35. PROCEDURE cleanExit (scrn : I.ScreenPtr; wind : I.WindowPtr);
  36.  
  37. BEGIN (* cleanExit *)
  38.   (* Close things in the reverse order of opening *)
  39.   IF wind # NIL THEN I.CloseWindow (wind) END;
  40.   IF scrn # NIL THEN IF I.CloseScreen (scrn) THEN END END;
  41. END cleanExit;
  42.  
  43. (*------------------------------------*)
  44. PROCEDURE handleIDCMP (win : I.WindowPtr) : BOOLEAN;
  45.  
  46.   VAR
  47.     done    : BOOLEAN;
  48.     message : I.IntuiMessagePtr;
  49.     class   : SET;
  50.  
  51. BEGIN (* handleIDCMP *)
  52.   done := FALSE; message := NIL;
  53.   (* Examine pending messages *)
  54.   LOOP
  55.     message := SYS.VAL (I.IntuiMessagePtr, E.GetMsg (win.userPort));
  56.     IF message = NIL THEN EXIT END;
  57.     class := message.class; (* get all the data we need from message *)
  58.  
  59.     (* When we're through with a message, reply *)
  60.     E.ReplyMsg (message);
  61.  
  62.     (* See what events occurred *)
  63.     IF I.closeWindow IN class THEN done := TRUE END;
  64.   END; (* LOOP *)
  65.   RETURN done
  66. END handleIDCMP;
  67.  
  68. (*------------------------------------*)
  69. PROCEDURE main ();
  70.  
  71.   VAR
  72.     signalmask, signals : SET;
  73.     winsignal : SHORTINT;
  74.     done      : BOOLEAN;
  75.     pens      : ARRAY 1 OF E.UWORD;
  76.     screen1   : I.ScreenPtr;
  77.     window1   : I.WindowPtr;
  78.     tags      : ARRAY 19 OF U.TagItem;
  79.  
  80. BEGIN (* main *)
  81.   done := FALSE; pens [0] := -1; (* ~0 *)
  82.   screen1 := NIL; window1 := NIL;
  83.  
  84.   (* Open the screen *)
  85.   screen1 :=
  86.     I.OpenScreenTagsA (
  87.       NIL,
  88.       I.saPens,      SYS.ADR (pens),
  89.       I.saDisplayID, G.hiresKey,
  90.       I.saDepth,     2,
  91.       I.saTitle,     SYS.ADR ("Our Screen"),
  92.       U.done );
  93.   IF screen1 = NIL THEN cleanExit (screen1, window1); HALT (D.warn) END;
  94.  
  95.   (* ... and open the window *)
  96.   window1 :=
  97.     I.OpenWindowTagsA (
  98.       NIL,
  99.       (* Specify window dimensions and limits *)
  100.  
  101.       I.waLeft,           winLeftEdge,
  102.       I.waTop,            winTopEdge,
  103.       I.waWidth,          winWidth,
  104.       I.waHeight,         winHeight,
  105.       I.waMinWidth,       winMinWidth,
  106.       I.waMinHeight,      winMinHeight,
  107.       I.waMaxWidth,       -1, (* ~0 *)
  108.       I.waMaxHeight,      -1, (* ~0 *)
  109.  
  110.       (* Specify the system gadgets we want *)
  111.  
  112.       I.waCloseGadget,    E.LTRUE,
  113.       I.waSizeGadget,     E.LTRUE,
  114.       I.waDepthGadget,    E.LTRUE,
  115.       I.waDragBar,        E.LTRUE,
  116.  
  117.       (* Specify other attributes *)
  118.  
  119.       I.waActivate,       E.LTRUE,
  120.       I.waNoCareRefresh,  E.LTRUE,
  121.  
  122.       (* Specify the events we want to know about *)
  123.  
  124.       I.waIDCMP,          {I.closeWindow},
  125.  
  126.       (* Attach the window to the open screen *)
  127.  
  128.       I.waCustomScreen,   screen1,
  129.       I.waTitle,          SYS.ADR ("EasyWindow"),
  130.       I.waScreenTitle,    SYS.ADR ("Our Screen - EasyWindow is Active"),
  131.  
  132.       U.done );
  133.   IF window1 = NIL THEN cleanExit (screen1, window1); HALT (D.warn) END;
  134.  
  135.   (* Set up the signals for the events we want to hear about ... *)
  136.   winsignal := window1.userPort.sigBit;
  137.   signalmask := {winsignal}; (* we are only waiting on IDCMP events. *)
  138.  
  139.   (* Here's the main input event loop where we wait for events.  *)
  140.   (* We have asked Intuition to send us CLOSEWINDOW IDCMP events *)
  141.   (* Exec will wake us if any event we are waiting for occurs.   *)
  142.   WHILE ~done DO
  143.     signals := E.Wait (signalmask);
  144.     (* An event occurred - now act on the signal(s) we received. *)
  145.     (* We were only waiting on one signal (winsignal) in our     *)
  146.     (* signalmask, so we actually know we received winsignal.    *)
  147.     IF winsignal IN signals THEN
  148.       done := handleIDCMP (window1)
  149.     END; (* IF *)
  150.   END; (* WHILE *)
  151.   cleanExit (screen1, window1); HALT (D.ok); (* Exit the program *)
  152. END main;
  153.  
  154. BEGIN (* EasyIntuition37 *)
  155.   main ();
  156. END EasyIntuition37.
  157.