home *** CD-ROM | disk | FTP | other *** search
- { =========================================================================== }
- { Wmgrdemo.pas - Random-access, multi-level window demo ver 4.0, 12-12-87 }
- { }
- { This program shows you how the window management utilities allow you to }
- { access any window at any time. You can even hide the top level window for }
- { displaying later. }
- { =========================================================================== }
- { Run program.
- To make any window come to the top, press the window number.
- To move a window (only the top one), leave Scroll Lock on and press arrow
- keys, including Home, End, PgDn, PgUp, ^Left-arrrow and ^Right-arrow.
- To hide the top level window, press ESC.
- To show a hidden window, just press the window number.
- To quit, press F10. }
-
- program WindowManager;
-
- {$M 16384, 16384, 16384 }
- {$R-,S-,I-,D-,T-,F-,V-,B-,N-,L+ }
-
- uses Crt,Qwik,WndwVars,Wndw;
-
- type
- Str80 = string[80];
-
- const
- LArr = #75;
- RArr = #77;
- UArr = #72;
- DArr = #80;
- HomeKey = #71;
- EndKey = #79;
- PgUp = #73;
- PgDn = #81;
- CtrlLArr = #115;
- CtrlRArr = #116;
- EscKey = #27;
- RetKey = #13;
- NullKey = #00;
- F10Key = #68;
-
- StrA: array[1..5] of Str80 = (
- 'FORMAT: HideWindow;',
- 'This procedure simply hides the',
- 'top level window from the screen',
- 'which can later be displayed un-',
- 'altered by ShowWindow.');
-
- StrB: array[1..4] of Str80 = (
- 'FORMAT: ShowWindow (WindowName: WindowNames);',
- 'A hidden window can be redisplayed randomly to be',
- 'the new top level window. Nothing happens if the',
- 'WindowName is not found among the hidden windows.');
-
- StrC: array[1..7] of Str80 = (
- 'FORMAT: MoveWindow (Dir: DirType; NumOfChars: byte);',
- 'The top level window can be moved in any direction and',
- 'the number of characters (i.e, rows or cols) can also',
- 'specified. This gives full rate control. This even',
- 'lets you push a window to its margin limits without',
- 'calculation. Try ^Left-arrow, ^Right-arrow, PgUp, and',
- 'PgDn. Shadows are also accommodated.');
-
- StrD: array[1..5] of Str80 = (
- 'FORMAT: AccessWindow (WindowName: WindowNames);',
- 'To bring a window to the top level, whether hidden',
- 'or not, use AccessWindow. All windows are totally',
- 'managed and fluid. Shadows are permitted, but not',
- 'fully supported.');
-
- StrE: array[1..5] of Str80 = (
- 'FORMAT: Attr (Foreground,Background: byte);',
- 'This is a trivial function that simply con-',
- 'verts the colors to a byte. However, it is',
- 'recommended that you use the new background',
- 'constants instead. See WNDWVARS.PAS.');
-
- StrF: array[1..6] of Str80 = (
- 'FORMAT: RestoreTurboWindow;',
- 'If for some reason you jump',
- 'out of a window, this one',
- 'will restore Turbo window',
- 'text colors, window limits,',
- 'and cursor position.');
-
- StrG: array[1..4] of Str80 = (
- 'FORMAT: HeapOK (NumOfBytes: word);',
- 'This function returns true if NumOfBytes',
- 'is available on the Heap. An error mes-',
- 'sage is flashed on the screen otherwise.');
-
- StrH: array[1..5] of Str80 = (
- 'FORMAT: Qbox (Row,Col,Rows,Cols: byte;',
- ' Wattr,Battr: integer;',
- ' BorderSel: Borders);',
- 'Qbox is a subroutine of MakeWindow that',
- 'simply overwrites the screen with a box.');
-
- StrI: array[1..4] of Str80 = (
- 'FORMAT: GetLevelIndex (WindowName: WindowNames);',
- 'This function searches the displayed and then the',
- 'hidden WndwStats for the first level matching',
- 'WindowName. Zero is returned if no match is found.');
-
- var
- Key: char;
- ExtKey: boolean;
- ClockReading: longint absolute $0040:$006C; { low memory clock }
- TimeAtKbd1: longint;
- RowStep,ColStep,FastRowStep,FastColStep,
- i,TypematicRate,IdleTime: byte;
-
- procedure DisableInterrupts; inline($FA); { CLI }
- procedure EnableInterrupts; inline($FB); { STI }
-
- procedure ReadKbd (VAR ExtKey: boolean; VAR Key: char);
- begin
- Key:=ReadKey; { Read keyboard input. }
- if KeyPressed and (Key=NullKey) then { If first Char was null ... }
- begin
- Key:=ReadKey; { ... read second char. }
- ExtKey := true
- end
- else ExtKey:=false;
- end;
-
- function ScrollLockOn: boolean;
- var KeyStat: byte absolute $0000:$0417;
- begin
- ScrollLockOn:=((KeyStat and $10)<>0); { True if bit 4 set. }
- end;
-
- procedure InitStepRates;
- begin
- TypematicRate:=1; { A maximum of 1 clock tick indicates typematic rate }
- if CRTrows>40 then
- FastRowStep:=4
- else FastRowStep:=2;
- FastColStep:=CRTcols div 20;
- end;
-
- procedure SetStartTime;
- begin
- DisableInterrupts;
- TimeAtKbd1:=ClockReading;
- EnableInterrupts;
- end;
-
- procedure AdjustStepRates;
- begin
- DisableInterrupts;
- IdleTime:=ClockReading-TimeAtKbd1;
- EnableInterrupts;
- if IdleTime<=TypematicRate then
- begin
- ColStep:=FastColStep;
- RowStep:=FastRowStep;
- end
- else
- begin
- ColStep:=1;
- RowStep:=1;
- end;
- end;
-
- begin
- InitWindow (yellow+BlackBG,true);
- InitStepRates;
- SetWindowModes (ZoomMode);
-
- MakeWindow ( 1, 2,10,36,black+BrownBG,black+BrownBG,SingleBrdr,Window1);
- TitleWindow (Top,Left,' 1 HideWindow ');
- with TopWndwStat do
- begin
- Qwrite (WSrow+2 ,WScol+2,-1,StrA[1]);
- for i:=2 to 5 do Qwrite (WSrow+2+i,WScol+2,-1,StrA[i]);
- GotoRC (pred(WSrow2),WSwhereC);
- end;
-
- MakeWindow ( 3,15, 9,53,black+LightGrayBG,black+LightGrayBG,DoubleBrdr,
- Window2);
- TitleWindow (Top,Left,' 2 ShowWindow ');
- with TopWndwStat do
- begin
- Qwrite (WSrow+2 ,WScol+2,-1,StrB[1]);
- for i:=2 to 4 do Qwrite (WSrow+2+i,WScol+2,-1,StrB[i]);
- GotoRC (pred(WSrow2),WSwhereC);
- end;
-
- MakeWindow ( 4, 5,12,58,lightred+BlackBG,lightred+BlackBG,HdoubleBrdr,
- Window3);
- TitleWindow (Top,Left,' 3 MoveWindow ');
- with TopWndwStat do
- begin
- Qwrite (WSrow+2 ,WScol+2,-1,StrC[1]);
- for i:=2 to 7 do Qwrite (WSrow+2+i,WScol+2,-1,StrC[i]);
- GotoRC (pred(WSrow2),WSwhereC);
- end;
-
- MakeWindow ( 6, 9,10,54,white+CyanBG,white+CyanBG,SolidBrdr,Window4);
- TitleWindow (Top,Left,' 4 AccessWindow ');
- with TopWndwStat do
- begin
- Qwrite (WSrow+2 ,WScol+2,-1,StrD[1]);
- for i:=2 to 5 do Qwrite (WSrow+2+i,WScol+2,-1,StrD[i]);
- GotoRC (pred(WSrow2),WSwhereC);
- end;
-
- MakeWindow ( 8, 7,10,48,yellow+GreenBG,yellow+GreenBG,EvenSolidBrdr,Window5);
- TitleWindow (Top,Left,' 5 Attr ');
- with TopWndwStat do
- begin
- Qwrite (WSrow+2 ,WScol+2,-1,StrE[1]);
- for i:=2 to 5 do Qwrite (WSrow+2+i,WScol+2,-1,StrE[i]);
- GotoRC (pred(WSrow2),WSwhereC);
- end;
-
- MakeWindow (14, 1,11,31,white+BlueBG,white+BlueBG,ThinSolidBrdr2,Window6);
- TitleWindow (Top,Left,' 6 RestoreTurboWindow ');
- with TopWndwStat do
- begin
- Qwrite (WSrow+2 ,WScol+2,-1,StrF[1]);
- for i:=2 to 6 do Qwrite (WSrow+2+i,WScol+2,-1,StrF[i]);
- GotoRC (pred(WSrow2),WSwhereC);
- end;
-
- MakeWindow ( 5,37, 9,44,white+MagentaBG,White+MagentaBG,VdoubleBrdr,Window7);
- TitleWindow (Top,Left,' 7 HeapOK ');
- with TopWndwStat do
- begin
- Qwrite (WSrow+2 ,WScol+2,-1,StrG[1]);
- for i:=2 to 4 do Qwrite (WSrow+2+i,WScol+2,-1,StrG[i]);
- GotoRC (pred(WSrow2),WSwhereC);
- end;
-
- MakeWindow ( 7,33,10,44,yellow+RedBG,yellow+RedBG,MhatchBrdr,Window8);
- TitleWindow (Top,Left,' 8 Qbox ');
- with TopWndwStat do
- begin
- for i:=1 to 3 do Qwrite (WSrow+1+i,WScol+2,-1,StrH[i]);
- for i:=4 to 5 do Qwrite (WSrow+2+i,WScol+2,-1,StrH[i]);
- GotoRC (pred(WSrow2),WSwhereC);
- end;
-
- MakeWindow ( 9,31,17,41,white+CyanBG,white+CyanBG,HdoubleBrdr,Window9);
- TitleWindow (Top,Left,' 9 Demo Instructions ');
- with TopWndwStat do
- begin
- QwriteC (WSrow+2,WScol,WScol2,-1,'READ FIRST !');
- Qwrite (WSrow+4,WSwhereC,-1,'Press 1 - 9 to bring that number window');
- Qwrite (WSrow+5,WSwhereC,-1,'to the top. Press ESC to hide the top');
- Qwrite (WSrow+6,WSwhereC,-1,'window.');
- Qwrite (WSrow+8,WSwhereC,-1,'Press Scroll Lock on and use all the');
- Qwrite (WSrow+9,WSwhereC,-1,'cursor keys to move top window around.');
- Qwrite (WSrow+10,WSwhereC,-1,'Or type any key into the window.');
- Qwrite (WSrow+12,WSwhereC,-1,'Press F10 to quit.');
- Qwrite (WSrow+14,WSwhereC,-1,'Zoom mode is on for all windows.');
- GotoRC (pred(WSrow2),WSwhereC);
- end;
- repeat
- SetStartTime;
- ReadKbd (ExtKey,Key);
- if ExtKey then
- begin
- if ScrollLockOn then
- begin
- AdjustStepRates;
- case Key of
- UArr: MoveWindow (Up ,RowStep);
- PgUp,HomeKey: MoveWindow (Up ,CRTrows);
- DArr: MoveWindow (Down ,RowStep);
- PgDn,EndKey: MoveWindow (Down ,CRTrows);
- LArr: MoveWindow (Left ,ColStep);
- CtrlLArr: MoveWindow (Left ,CRTcols);
- RArr: MoveWindow (Right,ColStep);
- CtrlRArr: MoveWindow (Right,CRTcols);
- end
- end
- end
- else
- case Key of
- '1'..'9': AccessWindow (WindowNames(ord(Key)-ord('0')));
- EscKey: if (LI>0) then HideWindow;
- RetKey: writeln;
- #32..#126: write (Key);
- end;
- until ExtKey and (Key=F10Key);
-
- for i:=1 to LI do RemoveWindow; { Not necessary, but it's orderly. }
- ClrScr;
- end.