home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w048 / 2.ddi / MSSRC.ARC / MSHELP.INC < prev    next >
Encoding:
Text File  |  1987-12-21  |  6.9 KB  |  258 lines

  1. {                            MSHELP.INC
  2.                                MS 4.0
  3.                 Copyright (c) 1985, 87 by Borland International, Inc.         }
  4.  
  5.   procedure EdHelpWindow(Cmd : CommandType);
  6.     {-Display help for the specified command}
  7.   label
  8.     ExitPoint;
  9.   const
  10.     Xmin = 5;
  11.     Ymin = 7;
  12.     MaxHelpPages = 20;       {Max number of pages in one help section}
  13.   type
  14.     PageIndexRec =           {Indexes the pages of a help section}
  15.     record
  16.       StartOfs : Word;
  17.       Startattr : Byte;
  18.     end;
  19.     PageArray = array[1..MaxHelpPages] of PageIndexRec;
  20.     StringBuffer = array[1..MaxInt] of Char;
  21.  
  22.   var
  23.     Ch : Char;
  24.     Attr : Byte;
  25.     Redraw, Quitting : Boolean;
  26.     PageNum, MaxPage, BytesRead : Word;
  27.     SbPtr : ^StringBuffer;
  28.     HelpRec : HelpIndexRec;
  29.     W : WindowRec;
  30.     Pages : PageArray;
  31.  
  32.     procedure EdBuildPageIndex(var S : StringBuffer; var Pages : PageArray; var MaxPage : Word);
  33.       {-Initialize the page index}
  34.     var
  35.       Spos, PageNum : Word;
  36.       Attr : Byte;
  37.       EndOfSection : Boolean;
  38.  
  39.     begin                    {EdBuildPageIndex}
  40.       Spos := 1;
  41.       PageNum := 1;
  42.       EndOfSection := False;
  43.       Attr := ScreenAttr[MnColor];
  44.  
  45.       {Keep track of the byte offset and initial video attribute of each page}
  46.       Pages[PageNum].StartOfs := Spos;
  47.       Pages[PageNum].Startattr := Attr;
  48.  
  49.       repeat
  50.         case S[Spos] of
  51.  
  52.           ^A :
  53.             Attr := ScreenAttr[MhColor];
  54.  
  55.           ^B :
  56.             Attr := ScreenAttr[MsColor];
  57.  
  58.           ^C :
  59.             Attr := ScreenAttr[MnColor];
  60.  
  61.           ^L :               {New page}
  62.             begin
  63.               Inc(PageNum);
  64.               Pages[PageNum].StartOfs := Succ(Spos);
  65.               Pages[PageNum].Startattr := Attr;
  66.             end;
  67.  
  68.           ^Z :               {End of section}
  69.             begin
  70.               EndOfSection := True;
  71.               if (Spos > 1) and (S[Pred(Spos)] = ^L) then
  72.                 MaxPage := Pred(PageNum)
  73.               else
  74.                 MaxPage := PageNum;
  75.             end;
  76.  
  77.         end;
  78.         Inc(Spos);
  79.       until EndOfSection;
  80.     end;                     {EdBuildPageIndex}
  81.  
  82.     procedure EdDrawFullPage(W : WindowRec; var S : StringBuffer; var Pages : PageArray; PageNum : Word);
  83.       {-Draw help page pagenum}
  84.     var
  85.       Attr : Byte;
  86.       Ch : Char;
  87.       EndOfPage : Boolean;
  88.       Spos, Row, Col : Integer;
  89.       msg : VarString;
  90.  
  91.     begin                    {EdDrawFullPage}
  92.       with Pages[PageNum] do begin
  93.         Spos := StartOfs;
  94.         Attr := Startattr;
  95.       end;
  96.       with W do begin
  97.         {Initialize help message}
  98.         if PageNum > 1 then
  99.           msg := EdGetMessage(300)
  100.         else
  101.           EdClearString(msg);
  102.  
  103.         {Clear out the window}
  104.         EdClearWindow(XPosn, YPosn, XSize, YSize, ScreenAttr[MnColor]);
  105.  
  106.         {Scan the buffer until end of page}
  107.         Row := 1;
  108.         Col := 1;
  109.         EndOfPage := False;
  110.  
  111.         repeat
  112.  
  113.           Ch := S[Spos];
  114.           case Ch of
  115.             ^N :             {new line}
  116.               begin
  117.                 Inc(Row);
  118.                 Col := 1;
  119.               end;
  120.             ^L, ^Z :         {new page or section}
  121.               EndOfPage := True;
  122.             ^A :
  123.               Attr := ScreenAttr[MhColor];
  124.             ^B :
  125.               Attr := ScreenAttr[MsColor];
  126.             ^C :
  127.               Attr := ScreenAttr[MnColor];
  128.           else
  129.             {Printable character}
  130.             EdFastWrite(Ch, YPosn+Row, Succ(XPosn)+Col, Attr);
  131.             Inc(Col);
  132.           end;
  133.  
  134.           Inc(Spos);
  135.         until EndOfPage;
  136.  
  137.         {Add prompt for next page}
  138.         if PageNum < MaxPage then begin
  139.           if not(EdStringEmpty(msg)) then
  140.             msg := msg+',';
  141.           msg := msg+EdGetMessage(299);
  142.         end;
  143.         {Display prompt}
  144.         EdFastWrite(msg, Succ(YPosn+HelpHeight), XPosn+HelpWidth-Length(msg), ScreenAttr[MhColor]);
  145.  
  146.       end;
  147.     end;                     {EdDrawFullPage}
  148.  
  149.   begin                      {EdHelpWindow}
  150.  
  151.     if not(HelpAvailable) then begin
  152.       EdErrormsg(64);
  153.       Exit;
  154.     end;
  155.  
  156.     {Read help index}
  157.     Seek(Helpf, Ord(Cmd)*SizeOf(HelpIndexRec));
  158.     if EdFileerror then
  159.       Exit;
  160.     EdBlockRead(Helpf, HelpRec, SizeOf(HelpIndexRec), BytesRead);
  161.     if Goterror then
  162.       Exit;
  163.     if BytesRead <> SizeOf(HelpIndexRec) then begin
  164.       EdErrormsg(51);
  165.       Exit;
  166.     end;
  167.  
  168.     with HelpRec do
  169.       if (Len = 0) or (Start = 00) then
  170.  
  171.         {No help available, put up a notice}
  172.         EdDisplayPromptWindow(EdGetMessage(52), 13, [#27], Ch, NormalBox)
  173.  
  174.       else begin
  175.  
  176.         if EdMemAvail(Len, FreeListTemp) then
  177.           GetMem(SbPtr, Len)
  178.         else begin
  179.           {Section too big for available heap space}
  180.           EdErrormsg(54);
  181.           Exit;
  182.         end;
  183.  
  184.         {Put up a help window, message line, and turn off cursor}
  185.         EdEraseMenuHelp;
  186.         EdWritePromptLine(EdGetMessage(298));
  187.         EdSaveTextWindow(Border, EdGetMessage(247), Xmin, Ymin, Xmin+HelpWidth+3, Ymin+HelpHeight+2, W);
  188.         EdSetCursor(CursorOff);
  189.  
  190.         {Read help text}
  191.         Seek(Helpf, Start);
  192.         if EdFileerror then
  193.           goto ExitPoint;
  194.         EdBlockRead(Helpf, SbPtr^[1], Len, BytesRead);
  195.         if Goterror then
  196.           goto ExitPoint;
  197.         if BytesRead <> Len then begin
  198.           EdErrormsg(53);
  199.           goto ExitPoint;
  200.         end;
  201.  
  202.         {Browse help pages}
  203.  
  204.         {Initialize}
  205.         EdBuildPageIndex(SbPtr^, Pages, MaxPage);
  206.         PageNum := 1;
  207.         Redraw := True;
  208.         Quitting := False;
  209.  
  210.         repeat
  211.  
  212.           {Update the window}
  213.           if Redraw then begin
  214.             EdDrawFullPage(W, SbPtr^, Pages, PageNum);
  215.             Redraw := False;
  216.           end;
  217.  
  218.           case EdGetCursorCommand(DirCmdSet) of
  219.  
  220.             ^E, ^R :         {Page up}
  221.               if PageNum > 1 then begin
  222.                 Dec(PageNum);
  223.                 Redraw := True;
  224.               end;
  225.  
  226.             ^X, ^C :         {Page down}
  227.               if PageNum < MaxPage then begin
  228.                 Inc(PageNum);
  229.                 Redraw := True;
  230.               end;
  231.  
  232.             ^T :             {First page in list}
  233.               if PageNum > 1 then begin
  234.                 PageNum := 1;
  235.                 Redraw := True;
  236.               end;
  237.  
  238.             ^B :             {Last page in list}
  239.               if PageNum < MaxPage then begin
  240.                 PageNum := MaxPage;
  241.                 Redraw := True;
  242.               end;
  243.  
  244.             #27 :            {Escape}
  245.               Quitting := True;
  246.  
  247.           end;
  248.         until Quitting;
  249.  
  250. ExitPoint:
  251.         {Restore screen}
  252.         EdRestoreTextWindow(W);
  253.         {Deallocate memory}
  254.         FreeMem(SbPtr, Len);
  255.  
  256.       end;
  257.   end;                       {EdHelpWindow}
  258.