home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / 4utils83.zip / DISPLAYK.PAS < prev    next >
Pascal/Delphi Source File  |  1994-04-28  |  12KB  |  391 lines

  1. UNIT DisplayKeyboardAndCursor;
  2. (* ----------------------------------------------------------------------
  3.    Part of 4DESC - A Simple 4DOS File Description Editor
  4.  
  5.        David Frey,         & Tom Bowden
  6.        Urdorferstrasse 30    1575 Canberra Drive
  7.        8952 Schlieren ZH     Stone Mountain, GA 30088-3629
  8.        Switzerland           USA
  9.  
  10.        Code created using Turbo Pascal 7.0, (c) Borland International 1992
  11.  
  12.    DISCLAIMER: This unit is freeware: you are allowed to use, copy
  13.                and change it free of charge, but you may not sell or hire
  14.                this part of 4DESC. The copyright remains in our hands.
  15.  
  16.                If you make any (considerable) changes to the source code,
  17.                please let us know. (send a copy or a listing).
  18.                We would like to see what you have done.
  19.  
  20.                We, David Frey and Tom Bowden, the authors, provide absolutely
  21.                no warranty of any kind. The user of this software takes the
  22.                entire risk of damages, failures, data losses or other
  23.                incidents.
  24.  
  25.    This unit manages displaying messages, switching cursor modes etc.
  26.  
  27.    ----------------------------------------------------------------------- *)
  28.  
  29. INTERFACE USES Crt, Dos, Dmouse;
  30.  
  31. CONST Header1 = '4DESC 1.73 - (c) 1992, 1994 Copyright by David Frey & Tom Bowden ';
  32.       Header2 = 'Portions of code (c) 1993 Robert Juhasz and (c) 1990 Borland Inc.';
  33. (* Cursor *)
  34.  
  35. VAR OrigCursor : WORD;
  36.     OverCursor : WORD; (* Cursor shape when overwriting *)
  37.     InsCursor  : WORD; (*   "      "    "   inserting   *)
  38.  
  39. (* Color constants for color screens: *)
  40.  
  41. CONST co_StatusFg = Blue;
  42.       co_StatusBg = Cyan;
  43.       co_DirFg    = LightCyan;
  44.       co_SelectFg = Blue;
  45.       co_SelectBg = Cyan;
  46.       co_HighFg   = LightRed;
  47.       co_NormFg   = LightGray;
  48.       co_NormBg   = Blue;
  49.       co_WarnFg   = Yellow;
  50.       co_WarnBg   = Cyan;
  51.  
  52.       (* ...and for monochrome displays: *)
  53.  
  54.       mo_StatusFg = Black;
  55.       mo_StatusBg = LightGray;
  56.       mo_DirFg    = White;
  57.       mo_SelectFg = Black;
  58.       mo_SelectBg = LightGray;
  59.       mo_HighFg   = LightGray;
  60.       mo_NormFg   = LightGray;
  61.       mo_NormBg   = Black;
  62.       mo_WarnFg   = Black;
  63.       mo_WarnBg   = White;
  64.  
  65. VAR   ScreenSize : BYTE;
  66.       ScreenWidth: BYTE;
  67.       MaxLines   : BYTE;
  68.       Monochrome : BOOLEAN;
  69.  
  70. VAR   StatusFg   : BYTE;
  71.       StatusBg   : BYTE;
  72.       DirFg      : BYTE;
  73.       SelectFg   : BYTE;
  74.       SelectBg   : BYTE;
  75.       HighFg     : BYTE;
  76.       NormFg     : BYTE;
  77.       NormBg     : BYTE;
  78.       WarnFg     : BYTE;
  79.       WarnBg     : BYTE;
  80.       _4DOSVer   : STRING[11];
  81.  
  82.       ListCmd    : PathStr;
  83.       EditCmd    : PathStr;
  84.  
  85. (* Min/Max *)
  86. FUNCTION Min(a,b : INTEGER): INTEGER;
  87. FUNCTION Max(a,b : INTEGER): INTEGER;
  88.  
  89. (* Cursor *)
  90. PROCEDURE SetCursorShape(Cursor: WORD);
  91. FUNCTION  GetCursorShape: WORD;
  92. PROCEDURE ResetCursor(Overwrite: BOOLEAN);
  93.  
  94. (* Screen *)
  95. PROCEDURE Get4DOSVer;
  96. PROCEDURE ChooseColors(Monochrome: BOOLEAN);
  97.  
  98. PROCEDURE ReportError(msg: STRING; FullClipBoard, Changed: BOOLEAN);
  99. PROCEDURE DrawMainScreen(Index,NrOfFiles: WORD; Col,CurDescLen: BYTE);
  100. PROCEDURE DrawStatusLine(Redraw,FullClipboard, Changed, ReverseFlag: BOOLEAN);
  101. PROCEDURE ShowHelpPage;
  102.  
  103. (* Keyboard *)
  104.  
  105. FUNCTION GetKey: WORD;
  106.  
  107. PROCEDURE EvaluateINIFileSettings;
  108.  
  109. IMPLEMENTATION USES HandleINIFile, StringDateHandling;
  110.  
  111. VAR s   : STRING;
  112.     line: STRING[132];
  113.  
  114. (*------------------------------------------------------------- Min/Max *)
  115. FUNCTION Min(a,b : INTEGER): INTEGER;
  116.  
  117. BEGIN
  118.  IF a < b THEN Min := a
  119.           ELSE Min := b;
  120. END;
  121.  
  122. FUNCTION Max(a,b : INTEGER): INTEGER;
  123.  
  124. BEGIN
  125.  IF a > b THEN Max := a
  126.           ELSE Max := b;
  127. END;
  128.  
  129.  
  130. (* -------------------------------------------------------- Cursor *)
  131.  
  132. PROCEDURE SetCursorShape(Cursor: WORD); ASSEMBLER;
  133.  
  134. ASM
  135.  mov ah,01h
  136.  mov cx,Cursor
  137.  Int 10h
  138. END;
  139.  
  140. FUNCTION  GetCursorShape: WORD; ASSEMBLER;
  141.  
  142. ASM
  143.  mov ah,03h
  144.  mov bh,0
  145.  Int 10h
  146.  mov ax,cx
  147. END;
  148.  
  149. PROCEDURE ResetCursor(Overwrite: BOOLEAN);
  150.  
  151. VAR Cursor : WORD;
  152.  
  153. BEGIN
  154.  IF Overwrite THEN Cursor := OverCursor
  155.               ELSE Cursor := InsCursor;
  156.  SetCursorShape(Cursor);
  157. END; (* ResetCursor *)
  158.  
  159.  
  160. (* -------------------------------------------------------- Screen *)
  161. PROCEDURE Get4DOSVer;
  162.  
  163. VAR Regs    : Registers;
  164.     _4dvmaj : STRING[1];
  165.     _4dvmin : STRING[2];
  166.  
  167.  PROCEDURE DisplayVer;
  168.   BEGIN
  169.    Str(Regs.bl:1,_4dvmaj);
  170.    Str(Regs.bh:2,_4dvmin);
  171.    IF _4dvmin[1] = ' ' THEN _4dvmin[1] := '0';
  172.    _4DOSVer := ' 4DOS ' + _4dvmaj + '.' + _4dvmin + ' ';
  173.   END;
  174.  
  175. BEGIN
  176.  Regs.ax := $D44D;
  177.  Regs.bx := $0;
  178.  Intr($2F,Regs);
  179.  IF Regs.ax = $44DD THEN    (* 4DOS is active *)
  180.   DisplayVer
  181.  ELSE
  182.   BEGIN
  183.    Regs.ax := $E44D;
  184.    Regs.bx := $0;
  185.    Intr($2F,Regs);
  186.    IF Regs.ax = $44EE THEN    (* NDOS is active *)
  187.     BEGIN
  188.      DisplayVer;
  189.      _4DOSVer[2] := 'N';
  190.     END
  191.    ELSE
  192.     _4DOSVer := '───────────';
  193.   END
  194. END;  (* Get4DOSVer *)
  195.  
  196. Procedure CheckKeyOrMouse;
  197.  
  198. Var Key : Word;
  199.  
  200. Begin
  201.   Key := $0000;
  202.   Repeat
  203.     If KeyPressed Then Key := GetKey
  204.     Else
  205.       If MouseLoaded Then
  206.          Begin
  207.            ButtonReleased(Left);
  208.            If ReleaseCount > 0 Then Key := $FF;
  209.            ButtonReleased(Right);
  210.            If ReleaseCount > 0 Then Key := $FF;
  211.          End;
  212.   Until Key <> $0000;
  213. End;  (* CheckKeyOrMouse *)
  214.  
  215. PROCEDURE ReportError(msg: STRING; FullClipBoard, Changed: BOOLEAN);
  216.  
  217. VAR ch : WORD;
  218.  
  219. BEGIN
  220.  TextColor(WarnFg); TextBackGround(WarnBg);
  221.  GotoXY(1,MaxLines);
  222.  IF Length(msg) < ScreenWidth-1 THEN Write(Chars(' ',(ScreenWidth-Length(msg)) div 2));
  223.  Write(msg); ClrEol;
  224.  CheckKeyOrMouse;
  225.  DrawStatusLine(TRUE,FullClipBoard,Changed,FALSE);
  226. END; (* ReportError *)
  227.  
  228. PROCEDURE DrawStatusLine(Redraw,FullClipboard, Changed, ReverseFlag: BOOLEAN);
  229.  
  230. VAR OldTextAttr: BYTE;
  231.  
  232. BEGIN
  233.  OldTextAttr := TextAttr; (* Save the old text attribute *)
  234.  
  235.  TextBackGround(NormBg);
  236.  IF Redraw THEN
  237.   BEGIN
  238.    TextColor(NormFg);
  239.    GotoXY(1,MaxLines); ClrEol;
  240.    GotoXY(1,MaxLines); Write(line);
  241.    GotoXY(3,MaxLines); Write(_4DOSVer);
  242.   END;
  243.  
  244.  GotoXY(76,MaxLines);
  245.  IF FullClipBoard THEN BEGIN TextColor(HighFg); Write('Buf'); END
  246.                   ELSE BEGIN TextColor(NormFg); Write('───'); END;
  247.  
  248.  GotoXY(70,MaxLines);
  249.  IF Changed THEN BEGIN TextColor(HighFg); Write('Edit'); END
  250.             ELSE BEGIN TextColor(NormFg); Write('────'); END;
  251.  
  252.  GotoXY(68,MaxLines);
  253.  IF ReverseFlag THEN BEGIN TextColor(HighFg); Write('R'); END
  254.                 ELSE BEGIN TextColor(NormFg); Write('─'); END;
  255.  
  256.  TextAttr := OldTextAttr; (* and the original text attribute *)
  257. END; (* DrawStatusLine *)
  258.  
  259. PROCEDURE DrawMainScreen(Index,NrOfFiles: WORD; Col,CurDescLen: BYTE);
  260.  
  261. BEGIN
  262.  TextColor(NormFg); TextBackGround(NormBg);
  263.  ClrScr;
  264.  TextColor(StatusFg); TextBackGround(StatusBg);
  265.  GotoXY(1,1);
  266.  Write('ESC exits │ F1 Help │ F2 or F10 Saves │ Line ',Index:5,' of ',NrOfFiles:5,
  267.        ', Col ',Col:3,' Length ',CurDescLen:3,' '); ClrEol;
  268.  DrawStatusLine(TRUE,FALSE,FALSE,FALSE);
  269. END; (* DrawMainScreen *)
  270.  
  271. PROCEDURE ShowHelpPage;
  272.  
  273. VAR ch, cursor : WORD;
  274.  
  275. BEGIN
  276.  TextBackGround(NormBg);
  277.  ClrScr;
  278.  TextColor(DirFg);
  279.  GotoXY((ScreenWidth-10) DIV 2, 1); Write('4DESC Help');
  280.  TextColor(NormFg);
  281.  GotoXY((ScreenWidth-52) DIV 2, 2); Write('USAGE:  4DESC [/help] [/mono] [/dontask] [d:][\path]');
  282.  
  283.  GotoXY( 3, 4); Write(Chr(24),Chr(25),Chr(27),Chr(26),', PgUp, PgDn, Home, End: Moves bar & cursor');
  284.  GotoXY( 3, 5); Write('Ctrl-PgUp/Ctrl-PgDn:         Moves to first/last line');
  285.  GotoXY( 3, 6); Write('Ctrl-Left/Ctrl-Right:        Moves to previous/next word');
  286.  GotoXY( 3, 7); Write('Ctrl-Home/Ctrl-End:          Deletes from cursor to start/end of line');
  287.  GotoXY( 3, 8); Write('Backspace/DEL:               Deletes character before/under cursor');
  288.  GotoXY( 3,10); Write('INS:                         Toggles from insert mode to overwrite mode');
  289.  GotoXY( 3,11); Write('Alt-D:                       Deletes current description');
  290.  GotoXY( 3,12); Write('Alt-C:                       Copy current description to buffer');
  291.  GotoXY( 3,13); Write('Alt-M or Alt-T:              Move current description to buffer');
  292.  GotoXY( 3,14); Write('Alt-P:                       Paste buffer to current description');
  293.  GotoXY( 3,15); Write('Alt-S or Shift-F10:          Shell to (4)DOS');
  294.  GotoXY( 3,16); Write('Alt-X (Alt-Q), ESC:          Exit (quit) program (Alt-X stays in current dir)');
  295.  GotoXY( 3,17); Write('F3 or Alt-V, (Alt-E):        View (edit) highlighted file');
  296.  GotoXY( 3,18); Write('F4 (F5) or ENTER on dir/..:  Change to highlighted/parent directory');
  297.  GotoXY( 3,19); Write('F6 or Alt-L:                 Change drive');
  298.  GotoXY( 3,21); Write('Ctrl-N/Ctrl-E/Ctrl-S/Ctrl-D: sort current directory (Name/Ext/Size/Date)');
  299.  GotoXY( 3,22); Write('Ctrl-R Ctrl-N/E/S/D:         reverse sort directory (Name/Ext/Size/Date)');
  300.  
  301.  GotoXY((ScreenWidth-Length(Header1)) div 2 ,24); Write(Header1);
  302.  GotoXY((ScreenWidth-Length(Header2)) div 2 ,25); Write(Header2);
  303. (* GotoXY((ScreenWidth-24) div 2,25); Write('Press any key to return.'); *)
  304.  
  305.  Cursor := $2000; SetCursorShape(Cursor);   (* Hide cursor. *)
  306.  CheckKeyOrMouse;
  307. END; (* ShowHelp *)
  308.  
  309.  
  310. (* -------------------------------------------------------- Keyboard *)
  311.  
  312. FUNCTION GetKey: WORD;
  313.  
  314. VAR chlo, chhi : CHAR;
  315.  
  316. BEGIN
  317.  chlo := ReadKey;
  318.  IF chlo = #0 THEN chhi := ReadKey
  319.               ELSE chhi := #0;
  320.  
  321.  
  322.  (* Special cases to fit TP kbXXX constants: *)
  323.  IF (chlo = #$1B) THEN  BEGIN chhi := #$01; END  (* ESC   *)
  324.  ELSE
  325.  IF (chlo = #$0D) THEN  BEGIN chhi := #$1C; END  (* Enter *)
  326.  ELSE
  327.  IF (chlo = #$08) THEN  BEGIN chhi := #$0E; END; (* Backspace *)
  328.  
  329.  GetKey := WORD(chhi) SHL 8 + BYTE(chlo);
  330. END;
  331.  
  332.  
  333. PROCEDURE ChooseColors(Monochrome: BOOLEAN);
  334.  
  335. BEGIN
  336.  IF Monochrome THEN
  337.   BEGIN
  338.    DirFg    := ReadSettingsColor('monodisplay','dirfg'   ,mo_DirFg);
  339.    StatusFg := ReadSettingsColor('monodisplay','statusfg',mo_StatusFg);
  340.    StatusBg := ReadSettingsColor('monodisplay','statusbg',mo_StatusBg);
  341.    SelectFg := ReadSettingsColor('monodisplay','selectfg',mo_SelectFg);
  342.    SelectBg := ReadSettingsColor('monodisplay','selectbg',mo_SelectBg);
  343.    HighFg   := ReadSettingsColor('monodisplay','highfg'  ,mo_HighFg);
  344.    NormFg   := ReadSettingsColor('monodisplay','normfg'  ,mo_NormFg);
  345.    NormBg   := ReadSettingsColor('monodisplay','normbg'  ,mo_NormBg);
  346.    WarnFg   := ReadSettingsColor('monodisplay','warnfg'  ,mo_WarnFg);
  347.    WarnBg   := ReadSettingsColor('monodisplay','warnbg'  ,mo_WarnBg);
  348.   END
  349.  ELSE
  350.   BEGIN
  351.    DirFg    := ReadSettingsColor('colordisplay','dirfg'   ,co_DirFg);
  352.    StatusFg := ReadSettingsColor('colordisplay','statusfg',co_StatusFg);
  353.    StatusBg := ReadSettingsColor('colordisplay','statusbg',co_StatusBg);
  354.    SelectFg := ReadSettingsColor('colordisplay','selectfg',co_SelectFg);
  355.    SelectBg := ReadSettingsColor('colordisplay','selectbg',co_SelectBg);
  356.    HighFg   := ReadSettingsColor('colordisplay','highfg'  ,co_HighFg);
  357.    NormFg   := ReadSettingsColor('colordisplay','normfg'  ,co_NormFg);
  358.    NormBg   := ReadSettingsColor('colordisplay','normbg'  ,co_NormBg);
  359.    WarnFg   := ReadSettingsColor('colordisplay','warnfg'  ,co_WarnFg);
  360.    WarnBg   := ReadSettingsColor('colordisplay','warnbg'  ,co_WarnBg);
  361.   END
  362. END;
  363.  
  364. PROCEDURE EvaluateINIFileSettings;
  365.  
  366. VAR c: WORD;
  367.  
  368. BEGIN
  369.  ListCmd := ReadSettingsString('generaldisplay','viewer','list');
  370.  EditCmd := ReadSettingsString('generaldisplay','editor','edit');
  371.  
  372.  c := ReadSettingsInt('','cursorover',100);
  373.  IF c = 100 THEN c := ReadSettingsInt('primary','cursorover',100);
  374.  OverCursor := ($07-Round(c/100 * 7)) SHL 8 + $07;
  375.  
  376.  c := ReadSettingsInt('','cursorins' , 10);
  377.  IF c = 10 THEN c := ReadSettingsInt('primary','cursorins' , 10);
  378.  
  379.  InsCursor  := ($07-Round(c/100 * 7)) SHL 8 + $07;
  380. END;
  381.  
  382. BEGIN
  383.  Get4DOSVer;
  384.  OrigCursor := GetCursorShape;
  385.  MaxLines   := Hi(WindMax)+1;
  386.  ScreenSize := MaxLines-4;
  387.  ScreenWidth:= Lo(WindMax)+1;
  388.  Monochrome := (LastMode = Mono);
  389.  line       := Chars('─',ScreenWidth-1);
  390. END.
  391.