home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pmos2002.zip / DEMO / SRC / MPTEST.MOD < prev    next >
Text File  |  1996-11-03  |  10KB  |  264 lines

  1. MODULE MPTest;
  2.  
  3.         (********************************************************)
  4.         (*                                                      *)
  5.         (*      Test of the "maintenance page" facility         *)
  6.         (*                                                      *)
  7.         (*  Programmer:         P. Moylan                       *)
  8.         (*  Last edited:        3 November 1996                 *)
  9.         (*  Status:             Working                         *)
  10.         (*                                                      *)
  11.         (*      Bugs:                                           *)
  12.         (*              Rubbish being written to an input       *)
  13.         (*              window under certain circumstances.     *)
  14.         (*              I still haven't pinned down exactly     *)
  15.         (*              when it happens.  It looks to me like   *)
  16.         (*              a storage allocation error, i.e.        *)
  17.         (*              someone writing over someone else's     *)
  18.         (*              window data.                            *)
  19.         (*                                                      *)
  20.         (*              As nearly as I can judge, it has nothing*)
  21.         (*              to do with input.  It seems to be       *)
  22.         (*              associated with the 5th task (in this   *)
  23.         (*              module) to be created, i.e. I can move  *)
  24.         (*              the problem to a different window by    *)
  25.         (*              changing the order of task creation.    *)
  26.         (*                                                      *)
  27.         (*      Shortcomings:                                   *)
  28.         (*         1.   (Fixed)                                 *)
  29.         (*         2.   Mapping the same window to several      *)
  30.         (*              different groups is almost, but not     *)
  31.         (*              quite, supported.  I think that the     *)
  32.         (*              only enhancement needed to support this *)
  33.         (*              is a better way to decide whether to    *)
  34.         (*              hide a newly introduced window.         *)
  35.         (*         3.   Need to look into whether the order of  *)
  36.         (*              Unhide operations is satisfactory.      *)
  37.         (*                                                      *)
  38.         (********************************************************)
  39.  
  40. FROM TaskControl IMPORT
  41.     (* proc *)  CreateTask;
  42.  
  43. FROM Timer IMPORT
  44.     (* proc *)  Sleep;
  45.  
  46. FROM Semaphores IMPORT
  47.     (* type *)  Semaphore,
  48.     (* proc *)  CreateSemaphore, Wait;
  49.  
  50. FROM Keyboard IMPORT
  51.     (* proc *)  HotKey;
  52.  
  53. FROM Windows IMPORT
  54.     (* type *)  Window, Colour, FrameType, DividerType,
  55.     (* proc *)  OpenWindow, OpenWindowHidden, ChangeScrollingRegion, CloseWindow,
  56.                 PressAnyKey, WriteChar, WriteString, WriteLn, ShiftWindowAbs,
  57.                 ReadChar, ReadCharWithoutEcho;
  58.  
  59. FROM MaintenancePages IMPORT
  60.     (* type *)  MaintenancePage,
  61.     (* proc *)  CreateMaintenancePage, Associate;
  62.  
  63. FROM UserInterface IMPORT
  64.     (* type *)  UIWindow, Capability, CapabilitySet,
  65.     (* proc *)  AllowMouseControl;
  66.  
  67. FROM RandCard IMPORT
  68.     (* proc *)  RandInt;
  69.  
  70. (************************************************************************)
  71.  
  72. VAR page1, page2: MaintenancePage;
  73.  
  74. (************************************************************************)
  75.  
  76. PROCEDURE Task1;
  77.  
  78.     VAR w1: Window;  dummy: UIWindow;
  79.  
  80.     BEGIN
  81.         OpenWindowHidden (w1, blue, cyan, 6, 12, 8, 34, simpleframe, nodivider);
  82.         Associate (w1, page1);
  83.         dummy := AllowMouseControl (w1, "Task 1",
  84.                                 CapabilitySet {wshow, whide, wmove});
  85.         LOOP
  86.            WriteString (w1, "Message from Task 1 ... ");
  87.            Sleep (400);
  88.         END (*LOOP*);
  89.     END Task1;
  90.  
  91. (************************************************************************)
  92.  
  93. PROCEDURE Task2;
  94.  
  95.     VAR w2: Window;  dummy: UIWindow;
  96.  
  97.     BEGIN
  98.         OpenWindowHidden (w2, white, magenta, 12, 22, 20, 63, doubleframe, nodivider);
  99.         Associate (w2, page2);
  100.         dummy := AllowMouseControl (w2, "Task 2",
  101.                                 CapabilitySet {wshow, whide, wmove});
  102.         LOOP
  103.             WriteString (w2, "This is output from Task 2 on Page 2 ... ");
  104.             Sleep (600);
  105.         END (*LOOP*);
  106.     END Task2;
  107.  
  108. (************************************************************************)
  109.  
  110. PROCEDURE Task3;
  111.  
  112.     VAR w1: Window;  dummy: UIWindow;
  113.  
  114.     BEGIN
  115.         OpenWindowHidden (w1, black, green, 10, 20, 50, 78, doubleframe, nodivider);
  116.         Associate (w1, page1);
  117.         dummy := AllowMouseControl (w1, "Task 3",
  118.                                 CapabilitySet {wshow, whide, wmove});
  119.         LOOP
  120.            WriteString (w1, "Task 3 also uses page 1 ... ");
  121.            Sleep (200);
  122.         END (*LOOP*);
  123.     END Task3;
  124.  
  125. (************************************************************************)
  126.  
  127. PROCEDURE Random(): INTEGER;
  128.  
  129.     (* Returns a small unsigned random number.  *)
  130.  
  131.     BEGIN
  132.         RETURN RandInt (-1, +1);
  133.     END Random;
  134.  
  135. (************************************************************************)
  136.  
  137. PROCEDURE Task4;
  138.  
  139.     VAR w1: Window;  count: CARDINAL;  flip: BOOLEAN;
  140.         x0, y0: CARDINAL;  newx, newy, xspeed, yspeed: INTEGER;
  141.  
  142.     BEGIN
  143.         x0 :=66;  y0 := 3;
  144.         xspeed := -2;  yspeed := 2;
  145.         OpenWindowHidden (w1, brown, black, y0, y0+3, x0, x0+6, simpleframe, nodivider);
  146.         Associate (w1, page1);
  147.         count := 0;  flip := FALSE;
  148.         LOOP
  149.             INC (count);
  150.             IF count >= 1 THEN
  151.                 newx := VAL(INTEGER,x0) + xspeed + Random();
  152.                 IF newx < 0 THEN newx := 0;  xspeed := ABS(xspeed)
  153.                 ELSIF newx > 73 THEN newx := 73;  xspeed := -ABS(xspeed)
  154.                 END (*IF*);
  155.                 newy := VAL(INTEGER,y0) + yspeed + Random();
  156.                 IF newy < 0 THEN newy := 0;  yspeed := ABS(yspeed)
  157.                 ELSIF newy > 21 THEN newy := 21;  yspeed := -ABS(yspeed)
  158.                 END (*IF*);
  159.                 x0 := newx;  y0 := newy;
  160.                 ShiftWindowAbs (w1, y0, x0);
  161.                 count := 0;
  162.             END (*IF*);
  163.             flip := NOT flip;
  164.             IF flip THEN WriteString (w1, "/\/\/")
  165.             ELSE WriteString (w1, "\/\/\")
  166.             END (*IF*);
  167.             Sleep (400);
  168.         END (*LOOP*);
  169.     END Task4;
  170.  
  171. (************************************************************************)
  172.  
  173. PROCEDURE InputTask1;
  174.  
  175.     VAR w1: Window;  dummy: UIWindow;  ch: CHAR;
  176.  
  177.     BEGIN
  178.         OpenWindowHidden (w1, black, white, 14, 20, 3, 30, doubleframe, nodivider);
  179.         Associate (w1, page1);
  180.         dummy := AllowMouseControl (w1, "Input Task 1",
  181.                                 CapabilitySet {wshow, whide, wmove});
  182.         ch := 'A';
  183.         LOOP
  184.            WriteLn (w1);
  185.            WriteString (w1, "Press any key");
  186.            ReadCharWithoutEcho (w1, ch);
  187.            WriteLn (w1);
  188.            WriteString (w1, "The key you pressed was ");
  189.            WriteChar (w1, ch);
  190.            (*Sleep(2000);*)
  191.         END (*LOOP*);
  192.     END InputTask1;
  193.  
  194. (************************************************************************)
  195.  
  196. PROCEDURE InputTask2;
  197.  
  198.     VAR w1, w2: Window;  dummy: UIWindow;  ch: CHAR;
  199.  
  200.     BEGIN
  201.         OpenWindowHidden (w1, magenta, white, 4, 9, 40, 70,simpleframe,simpledivider);
  202.         Associate (w1, page2);
  203.         dummy := AllowMouseControl (w1, "Input Task 2",
  204.                                 CapabilitySet {wshow, whide, wmove});
  205.         WriteString (w1, "You can type into this window");
  206.         ChangeScrollingRegion (w1, 3, 4);
  207.  
  208.         OpenWindowHidden (w2, white, black, 10, 12, 40, 70,simpleframe,nodivider);
  209.         Associate (w2, page2);
  210.         dummy := AllowMouseControl (w2, "Extra window",
  211.                                 CapabilitySet {wshow, whide, wmove});
  212.         WriteString (w2, "An extra window");
  213.         LOOP
  214.            ReadChar (w1, ch);
  215.            (*Sleep(1000);*)
  216.         END (*LOOP*);
  217.     END InputTask2;
  218.  
  219. (************************************************************************)
  220.  
  221. PROCEDURE RunTheTest;
  222.  
  223.     CONST Esc = CHR(1BH);
  224.  
  225.     VAR w0, header1, header2: Window;
  226.         closedown: Semaphore;
  227.  
  228.     BEGIN
  229.         CreateSemaphore (closedown, 0);
  230.         HotKey (FALSE, Esc, closedown);
  231.         OpenWindow (w0, yellow, red, 8, 13, 19, 61, simpleframe, nodivider);
  232.         WriteString (w0, "  TEST OF THE MAINTENANCE PAGE FACILITY");
  233.         WriteLn (w0);
  234.         WriteString (w0, "Type Alt/P to toggle maintenance function");
  235.         WriteLn (w0);
  236.         WriteString (w0, "   Then F6 to cycle through the pages");
  237.         WriteLn (w0);
  238.         WriteString (w0, "         Esc to exit program");
  239.         CreateMaintenancePage (page1);
  240.         OpenWindowHidden (header1, white, black, 1, 3, 30, 49, doubleframe, nodivider);
  241.         Associate (header1, page1);
  242.         WriteString (header1, "MAINTENANCE PAGE 1");
  243.         CreateMaintenancePage (page2);
  244.         OpenWindowHidden (header2, white, black, 1, 3, 30, 49, doubleframe, nodivider);
  245.         Associate (header2, page2);
  246.         WriteString (header2, "MAINTENANCE PAGE 2");
  247.         CreateTask (Task1, 2, "Task 1");
  248.         CreateTask (Task2, 2, "Task 2");
  249.         CreateTask (Task4, 2, "Task 4");
  250.         CreateTask (InputTask1, 2, "Input Task 1");
  251.         CreateTask (InputTask2, 2, "Input Task 2");
  252.         CreateTask (Task3, 2, "Task 3");
  253.         Wait (closedown);
  254.     END RunTheTest;
  255.  
  256. (************************************************************************)
  257. (*                              MAIN PROGRAM                            *)
  258. (************************************************************************)
  259.  
  260. BEGIN
  261.     RunTheTest;
  262. END MPTest.
  263.  
  264.