home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pmos2002.zip / TESTS / SRC / UITEST.MOD < prev    next >
Text File  |  1996-10-29  |  7KB  |  203 lines

  1. MODULE UITest;
  2.  
  3.         (****************************************************************)
  4.         (*                                                              *)
  5.         (*              Test of module UserInterface                    *)
  6.         (*                                                              *)
  7.         (*      Programmer:     M. Walsh                                *)
  8.         (*      Modifications:  P. Moylan                               *)
  9.         (*      Last edited:    29 October 1996                         *)
  10.         (*      Status:         Working, although somewhat slower than  *)
  11.         (*                      the DOS version.                        *)
  12.         (*                                                              *)
  13.         (****************************************************************)
  14.  
  15. FROM Conversions IMPORT
  16.     (* proc *)  CardinalToString;
  17.  
  18. FROM TaskControl IMPORT
  19.     (* proc *)  CreateTask;
  20.  
  21. FROM Timer IMPORT
  22.     (* proc *)  Sleep;
  23.  
  24. FROM SoundEffects IMPORT Beep;
  25.  
  26. FROM Keyboard IMPORT
  27.     (* proc *)  KeyPressed;
  28.  
  29. FROM Mouse IMPORT
  30.     (* type *)  Buttons, ButtonSet,
  31.     (* proc *)  GetTextMouseStatus, GetTextMousePosition,
  32.                 ShowMouseCursor, HideMouseCursor;
  33.  
  34. FROM Windows IMPORT
  35.     (* type *)  Window,Colour,FrameType,DividerType,
  36.                 MaxRowNumber,MaxColumnNumber, ColumnRange,RowRange,
  37.     (* proc *)  OpenWindow, WriteString, WriteLn, SetCursor;
  38.  
  39. FROM UserInterface IMPORT
  40.     (* type *)  UIWindow, Capability, CapabilitySet,
  41.     (* proc *)  AllowMouseControl, AddActiveRegion;
  42.  
  43. CONST
  44.     LeftOnly = ButtonSet {LeftButton};
  45.     RightOnly = ButtonSet {RightButton};
  46.  
  47. (************************************************************************)
  48.  
  49. PROCEDURE BEEP (w: Window;  r: RowRange;  c: ColumnRange);
  50.  
  51.     BEGIN
  52.         Beep;
  53.     END BEEP;
  54.  
  55. (************************************************************************)
  56.  
  57. PROCEDURE BEEPBEEP (w: Window;  r: RowRange;  c: ColumnRange);
  58.  
  59.     BEGIN
  60.         Beep;  Beep;
  61.     END BEEPBEEP;
  62.  
  63. (************************************************************************)
  64.  
  65. PROCEDURE Spawned;
  66.  
  67.     VAR w: Window;  Test: UIWindow;
  68.  
  69.     BEGIN
  70.         OpenWindow (w,white,black,1,12,1,18,doubleframe,nodivider);
  71.         Test := AllowMouseControl (w, "Spawned",
  72.                                         CapabilitySet{wmove, whide, wshow});
  73.         AddActiveRegion(Test,1,10,1,16,LeftOnly,BEEP);
  74.         AddActiveRegion(Test,1,10,1,16,RightOnly,BEEPBEEP);
  75.         LOOP
  76.             WriteString(w,'Testing and it appears to work - Amazing');
  77.             Sleep(100);
  78.         END (*LOOP*);
  79.     END Spawned;
  80.  
  81. (************************************************************************)
  82.  
  83. PROCEDURE Spawned2;
  84.  
  85.     VAR w: Window;  Test: UIWindow;
  86.  
  87.     BEGIN
  88.         OpenWindow (w,white,black,14,23,1,18,doubleframe,nodivider);
  89.         Test := AllowMouseControl (w, "Spawned as well",
  90.                                 CapabilitySet {wmove, whide, wshow});
  91.         AddActiveRegion(Test,1,8,1,16,LeftOnly,BEEP);
  92.         LOOP
  93.             WriteString (w,'Testing and also working ---------- !!!!!!!!!');
  94.             Sleep(100);
  95.         END (*LOOP*);
  96.     END Spawned2;
  97.  
  98. (************************************************************************)
  99.  
  100. PROCEDURE MouseWindow;
  101.  
  102.     VAR w: Window;  MousePos: UIWindow;
  103.         X, Y: CARDINAL;  LastX, LastY: CARDINAL;
  104.         string: ARRAY [0..2] OF CHAR;
  105.  
  106.     BEGIN
  107.         OpenWindow (w,black,white,15,18,20,27,doubleframe,nodivider);
  108.         MousePos := AllowMouseControl (w, "MousePos",
  109.                                 CapabilitySet {wmove, whide, wshow});
  110.         SetCursor (w, 1, 2);  WriteString (w, "X");
  111.         SetCursor (w, 2, 2);  WriteString (w, "Y");
  112.         AddActiveRegion(MousePos,1,2,1,6,LeftOnly,BEEP);
  113.         LastX := MAX(ColumnRange) + 1;  LastY := 0;
  114.         LOOP
  115.             GetTextMousePosition (X, Y);
  116.             IF (LastX <> X) OR (LastY <> Y) THEN
  117.                 HideMouseCursor;
  118.                 CardinalToString (X, string, 3);
  119.                 SetCursor (w, 1, 3);  WriteString (w, string);
  120.                 CardinalToString (Y, string, 3);
  121.                 SetCursor (w, 2, 3);  WriteString (w, string);
  122.                 ShowMouseCursor;
  123.                 LastX := X;
  124.                 LastY := Y;
  125.             END (*IF*);
  126.             Sleep(60);
  127.         END (*LOOP*);
  128.     END MouseWindow;
  129.  
  130. (************************************************************************)
  131.  
  132. PROCEDURE ScrollWindowtask;
  133.  
  134.     VAR w: Window;  LoopCount:CARDINAL;  ScrollWindow: UIWindow;
  135.  
  136.     BEGIN
  137.         OpenWindow (w,intensewhite,red,1,11,40,75,doubleframe,nodivider);
  138.         ScrollWindow := AllowMouseControl (w, "ScrollWindow",
  139.                                 CapabilitySet {wmove, whide, wshow});
  140.         AddActiveRegion(ScrollWindow,1,9,1,34,LeftOnly,BEEP);
  141.         Sleep(100);
  142.         LOOP
  143.             FOR LoopCount := 1 TO 10 DO
  144.                 WriteString(w,"Scrolling Text Is Fast. Faster than you can read !");
  145.             END (*FOR*);
  146.             Sleep(100);
  147.         END (*LOOP*);
  148.  
  149.     END ScrollWindowtask;
  150.  
  151. (************************************************************************)
  152.  
  153. PROCEDURE ScrollWindow2task;
  154.  
  155.     VAR LoopCount:CARDINAL;  ScrollWindow2: UIWindow;  w: Window;
  156.  
  157.     BEGIN
  158.         OpenWindow (w,blue,cyan,12,18,40,75,doubleframe,nodivider);
  159.         ScrollWindow2 := AllowMouseControl (w, "ScrollWindow Too",
  160.                                 CapabilitySet {wmove, whide, wshow});
  161.         AddActiveRegion(ScrollWindow2,1,5,1,34,LeftOnly,BEEP);
  162.         Sleep(100);
  163.         LOOP
  164.             FOR LoopCount := 1 TO 10 DO
  165.                 WriteString(w,"Scrolling Text Is Fast. Faster than you can read !");
  166.             END (*FOR*);
  167.             Sleep(100);
  168.         END (*LOOP*);
  169.  
  170.     END ScrollWindow2task;
  171.  
  172. (************************************************************************)
  173. (*                              MAIN PROGRAM                            *)
  174. (************************************************************************)
  175.  
  176. VAR buttons: ButtonSet;  X, Y: CARDINAL;
  177.     instructions: Window;
  178.     Exit1, Exit2: BOOLEAN;
  179.  
  180. BEGIN
  181.     OpenWindow (instructions,black,white,19,24,30,79,doubleframe,nodivider);
  182.     WriteString (instructions, "Press any key to exit.  Use left mouse button");
  183.     WriteLn (instructions);
  184.     WriteString (instructions, "to move or hide a window.  To restore a hidden");
  185.     WriteLn (instructions);
  186.     WriteString (instructions, "window, click right mouse button and then");
  187.     WriteLn (instructions);
  188.     WriteString (instructions, "left click on the name of the desired window.");
  189.     CreateTask(MouseWindow,5,"Mouse");
  190.     CreateTask(ScrollWindowtask,2,"SW");
  191.     CreateTask(ScrollWindow2task,3,"SW2");
  192.     CreateTask(Spawned,2,"Spawned");
  193.     CreateTask(Spawned2,2,"Spawned2");
  194.     REPEAT
  195.         Sleep(100);
  196.         GetTextMouseStatus(buttons, X, Y);
  197.         Exit1 := KeyPressed();
  198.         Exit2 := ButtonSet{LeftButton,RightButton} <= buttons;
  199.     UNTIL Exit1 OR Exit2;
  200.  
  201. END UITest.
  202.  
  203.