home *** CD-ROM | disk | FTP | other *** search
- { MSHELP.INC
- MS 4.0
- Copyright (c) 1985, 87 by Borland International, Inc. }
-
- procedure EdHelpWindow(Cmd : CommandType);
- {-Display help for the specified command}
- label
- ExitPoint;
- const
- Xmin = 5;
- Ymin = 7;
- MaxHelpPages = 20; {Max number of pages in one help section}
- type
- PageIndexRec = {Indexes the pages of a help section}
- record
- StartOfs : Word;
- Startattr : Byte;
- end;
- PageArray = array[1..MaxHelpPages] of PageIndexRec;
- StringBuffer = array[1..MaxInt] of Char;
-
- var
- Ch : Char;
- Attr : Byte;
- Redraw, Quitting : Boolean;
- PageNum, MaxPage, BytesRead : Word;
- SbPtr : ^StringBuffer;
- HelpRec : HelpIndexRec;
- W : WindowRec;
- Pages : PageArray;
-
- procedure EdBuildPageIndex(var S : StringBuffer; var Pages : PageArray; var MaxPage : Word);
- {-Initialize the page index}
- var
- Spos, PageNum : Word;
- Attr : Byte;
- EndOfSection : Boolean;
-
- begin {EdBuildPageIndex}
- Spos := 1;
- PageNum := 1;
- EndOfSection := False;
- Attr := ScreenAttr[MnColor];
-
- {Keep track of the byte offset and initial video attribute of each page}
- Pages[PageNum].StartOfs := Spos;
- Pages[PageNum].Startattr := Attr;
-
- repeat
- case S[Spos] of
-
- ^A :
- Attr := ScreenAttr[MhColor];
-
- ^B :
- Attr := ScreenAttr[MsColor];
-
- ^C :
- Attr := ScreenAttr[MnColor];
-
- ^L : {New page}
- begin
- Inc(PageNum);
- Pages[PageNum].StartOfs := Succ(Spos);
- Pages[PageNum].Startattr := Attr;
- end;
-
- ^Z : {End of section}
- begin
- EndOfSection := True;
- if (Spos > 1) and (S[Pred(Spos)] = ^L) then
- MaxPage := Pred(PageNum)
- else
- MaxPage := PageNum;
- end;
-
- end;
- Inc(Spos);
- until EndOfSection;
- end; {EdBuildPageIndex}
-
- procedure EdDrawFullPage(W : WindowRec; var S : StringBuffer; var Pages : PageArray; PageNum : Word);
- {-Draw help page pagenum}
- var
- Attr : Byte;
- Ch : Char;
- EndOfPage : Boolean;
- Spos, Row, Col : Integer;
- msg : VarString;
-
- begin {EdDrawFullPage}
- with Pages[PageNum] do begin
- Spos := StartOfs;
- Attr := Startattr;
- end;
- with W do begin
- {Initialize help message}
- if PageNum > 1 then
- msg := EdGetMessage(300)
- else
- EdClearString(msg);
-
- {Clear out the window}
- EdClearWindow(XPosn, YPosn, XSize, YSize, ScreenAttr[MnColor]);
-
- {Scan the buffer until end of page}
- Row := 1;
- Col := 1;
- EndOfPage := False;
-
- repeat
-
- Ch := S[Spos];
- case Ch of
- ^N : {new line}
- begin
- Inc(Row);
- Col := 1;
- end;
- ^L, ^Z : {new page or section}
- EndOfPage := True;
- ^A :
- Attr := ScreenAttr[MhColor];
- ^B :
- Attr := ScreenAttr[MsColor];
- ^C :
- Attr := ScreenAttr[MnColor];
- else
- {Printable character}
- EdFastWrite(Ch, YPosn+Row, Succ(XPosn)+Col, Attr);
- Inc(Col);
- end;
-
- Inc(Spos);
- until EndOfPage;
-
- {Add prompt for next page}
- if PageNum < MaxPage then begin
- if not(EdStringEmpty(msg)) then
- msg := msg+',';
- msg := msg+EdGetMessage(299);
- end;
- {Display prompt}
- EdFastWrite(msg, Succ(YPosn+HelpHeight), XPosn+HelpWidth-Length(msg), ScreenAttr[MhColor]);
-
- end;
- end; {EdDrawFullPage}
-
- begin {EdHelpWindow}
-
- if not(HelpAvailable) then begin
- EdErrormsg(64);
- Exit;
- end;
-
- {Read help index}
- Seek(Helpf, Ord(Cmd)*SizeOf(HelpIndexRec));
- if EdFileerror then
- Exit;
- EdBlockRead(Helpf, HelpRec, SizeOf(HelpIndexRec), BytesRead);
- if Goterror then
- Exit;
- if BytesRead <> SizeOf(HelpIndexRec) then begin
- EdErrormsg(51);
- Exit;
- end;
-
- with HelpRec do
- if (Len = 0) or (Start = 00) then
-
- {No help available, put up a notice}
- EdDisplayPromptWindow(EdGetMessage(52), 13, [#27], Ch, NormalBox)
-
- else begin
-
- if EdMemAvail(Len, FreeListTemp) then
- GetMem(SbPtr, Len)
- else begin
- {Section too big for available heap space}
- EdErrormsg(54);
- Exit;
- end;
-
- {Put up a help window, message line, and turn off cursor}
- EdEraseMenuHelp;
- EdWritePromptLine(EdGetMessage(298));
- EdSaveTextWindow(Border, EdGetMessage(247), Xmin, Ymin, Xmin+HelpWidth+3, Ymin+HelpHeight+2, W);
- EdSetCursor(CursorOff);
-
- {Read help text}
- Seek(Helpf, Start);
- if EdFileerror then
- goto ExitPoint;
- EdBlockRead(Helpf, SbPtr^[1], Len, BytesRead);
- if Goterror then
- goto ExitPoint;
- if BytesRead <> Len then begin
- EdErrormsg(53);
- goto ExitPoint;
- end;
-
- {Browse help pages}
-
- {Initialize}
- EdBuildPageIndex(SbPtr^, Pages, MaxPage);
- PageNum := 1;
- Redraw := True;
- Quitting := False;
-
- repeat
-
- {Update the window}
- if Redraw then begin
- EdDrawFullPage(W, SbPtr^, Pages, PageNum);
- Redraw := False;
- end;
-
- case EdGetCursorCommand(DirCmdSet) of
-
- ^E, ^R : {Page up}
- if PageNum > 1 then begin
- Dec(PageNum);
- Redraw := True;
- end;
-
- ^X, ^C : {Page down}
- if PageNum < MaxPage then begin
- Inc(PageNum);
- Redraw := True;
- end;
-
- ^T : {First page in list}
- if PageNum > 1 then begin
- PageNum := 1;
- Redraw := True;
- end;
-
- ^B : {Last page in list}
- if PageNum < MaxPage then begin
- PageNum := MaxPage;
- Redraw := True;
- end;
-
- #27 : {Escape}
- Quitting := True;
-
- end;
- until Quitting;
-
- ExitPoint:
- {Restore screen}
- EdRestoreTextWindow(W);
- {Deallocate memory}
- FreeMem(SbPtr, Len);
-
- end;
- end; {EdHelpWindow}