📄 help.pas
字号:
((Row = EndPos.Row) and (Row > BegPos.Row) and TrailingSpaces);
end;
begin
MinLeadingSpaces := 78;
TrailingSpaces := EndPos.Col >= RowLeadingSpaces(EndPos.Row);
for Row := BegPos.Row to EndPos.Row do
if Inside(Row) then
begin
LeadingSpaces := RowLeadingSpaces(Row);
if LeadingSpaces < MinLeadingSpaces then
MinLeadingSpaces := LeadingSpaces;
end;
if MinLeadingSpaces = 78 then
MinLeadingSpaces := 0;
for Row := BegPos.Row to EndPos.Row do
begin
if Inside(Row) then
EatSpaces := MinLeadingSpaces
else
EatSpaces := 0;
if (Row = BegPos.Row) and (BegPos.Col > EatSpaces) then
EatSpaces := BegPos.Col;
RowLength := 78;
if Row = EndPos.Row then
begin
RowLength := EndPos.Col - EatSpaces;
if RowLength < 0 then
RowLength := 0;
end;
Row2Text(Row);
if Length(NewText) <= EatSpaces then
RowLength := 0
else if EatSpaces + RowLength > Length(NewText) then
RowLength := Length(NewText) - EatSpaces;
if Row <> EndPos.Row then
begin
NewText[EatSpaces+RowLength+1] := ^M;
NewText[EatSpaces+RowLength+2] := ^J;
RowLength := RowLength + 2;
end;
PutToVMem(NewText[EatSpaces+1], RowLength);
end;
Clipboard^.CopyToClip;
end;
procedure THelpView.Copy;
begin
if HasSelection then CopyToClip(BlockBeg,BlockEnd);
end;
procedure THelpView.CopyExample;
var
BegPos, EndPos: TPos;
procedure Adjust(var Pos: TPos);
begin
with Pos do
if Col = 1 then
Col := 0;
end;
begin
if HasExample then
begin
CurScreen^.GetExample(BegPos, EndPos);
Adjust(BegPos);
Adjust(EndPos);
CopyToClip(BegPos, EndPos);
end;
end;
function THelpView.GetRowCount: Word;
var
Row: Word;
begin
Row := CurScreen^.MaxRow;
if Row > 0 then
Dec(Row);
GetRowCount := Row;
end;
function THelpView.MaxLeftCol: Byte;
begin
MaxLeftCol := 78 - Size.X;
end;
procedure THelpView.AdjustCol;
var
Col: Byte;
begin
Col := MaxLeftCol;
if ScreenPos.Col > Col then
ScreenPos.Col := Col;
end;
procedure THelpView.AdjustRow;
var
Row: Word;
begin
Row := GetRowCount;
if ScreenPos.Row > Row then
ScreenPos.Row := Row;
end;
procedure THelpView.AdjustPos;
begin
AdjustRow;
AdjustCol;
end;
procedure THelpView.AdjustCursor(var Pos: TPos);
begin
if Pos.Col >= 78 then
Pos.Col := 77;
if Pos.Row > GetRowCount then
Pos.Row := GetRowCount;
end;
procedure THelpView.UpdateCursor;
begin
if (CursorPos.Col >= ScreenPos.Col) and
(CursorPos.Col < ScreenPos.Col + Size.X) and
(CursorPos.Row >= ScreenPos.Row) and
(CursorPos.Row < ScreenPos.Row + Size.Y) then
begin
SetCursor(CursorPos.Col - ScreenPos.Col, CursorPos.Row - ScreenPos.Row);
ShowCursor;
end else
HideCursor;
end;
procedure THelpView.ProcessScrollBars;
begin
ScreenPos.Row := VScrollBar^.Value;
ScreenPos.Col := HScrollBar^.Value;
DrawView;
end;
procedure THelpView.UpdateScrollBars;
begin
VScrollBar^.Value := ScreenPos.Row;
VScrollBar^.SetParams(ScreenPos.Row, 0, GetRowCount, Size.Y, 1);
VScrollBar^.DrawView;
HScrollBar^.Value := ScreenPos.Col;
HScrollBar^.SetParams(ScreenPos.Col, 0, MaxLeftCol, Size.X, 1);
HScrollBar^.DrawView;
end;
procedure THelpView.GetColors(var Colors: TColorArray);
var
StartRow: Integer;
begin
for StartRow := 0 to 7 do
Colors[StartRow] := GetColor(StartRow + 1);
end;
procedure THelpView.DrawRows(BegRow, EndRow: Word);
var
Colors: TColorArray;
Row: Word;
B: array[0..77] of Word;
Text: PChar;
Index: Word;
Example: Boolean;
I, BlockBegRow, BlockBegCol, BlockEndRow, BlockEndCol: Word;
begin
GetColors(Colors);
BlockBegRow := BlockBeg.Row;
BlockBegCol := BlockBeg.Col;
BlockEndRow := BlockEnd.Row;
BlockEndCol := BlockEnd.Col;
I := HiliteIndex shl 1 + 1;
for Row := BegRow + ScreenPos.Row to EndRow + ScreenPos.Row do
begin
CurScreen^.GetRow(Row, Text, Index, Example);
Index := Index shl 1;
asm
PUSH DS
MOV AX,Row
SUB BX,BX
CMP AX,BlockBegRow
JB @@3
JNZ @@1
MOV BX,BlockBegCol
@@1: MOV DX,78
CMP AX,BlockEndRow
JA @@3
JNZ @@2
MOV DX,BlockEndCol
@@2: SUB DX,BX
JGE @@4
@@3: SUB BX,BX
SUB DX,DX
@@4: PUSH SS
POP ES
LEA DI,B
CLD
MOV CX,BX
MOV AX,' '
REP STOSW
MOV CX,DX
MOV AH,4
REP STOSW
MOV CX,78
SUB CX,BX
SUB CX,DX
MOV AH,0
REP STOSW
LEA DI,B[2]
MOV CX,78
LDS SI,Text
MOV DH,0
TEST Example,1
JZ @@5
MOV DH,1
@@5: JMP @@10
@@6: CMP AL,2
JNE @@8
INC Index
MOV BX,Index
TEST BX,1
JNZ @@7
MOV DH,DL
JMP @@9
@@7: MOV DL,DH
MOV DH,2
CMP BX,I
JNE @@9
MOV DH,3
JMP @@9
@@8: OR AL,AL
JZ @@11
CMP AL,5
JNE @@9
XOR Example,1
MOV DH,0
JZ @@9
MOV DH,1
@@9: LODSB
CMP AL,7
JB @@6
MOV AH,DH
ADD AH,ES:[DI+1]
STOSW
@@10: LOOP @@9
@@11: POP DS
LEA BX,Colors
LEA DI,B[1]
MOV CX,78
@@12: MOV AL,ES:[DI]
XLAT
STOSB
INC DI
LOOP @@12
end;
WriteLine(0, Row - ScreenPos.Row, Size.X, 1, B[ScreenPos.Col]);
end;
end;
procedure THelpView.Draw;
begin
if ValidScreen then
begin
Reformat;
AdjustPos;
UpdateCursor;
UpdateScrollBars;
DrawRows(0, Size.Y - 1);
end;
end;
procedure THelpView.RedrawRows(BegRow, EndRow: Integer);
var
I: Integer;
begin
BegRow := BegRow - ScreenPos.Row;
EndRow := EndRow - ScreenPos.Row;
if BegRow > EndRow then
begin
I := BegRow;
BegRow := EndRow;
EndRow := I
end;
if BegRow < 0 then
BegRow := 0;
if EndRow >= Size.Y then
EndRow := Size.Y - 1;
if BegRow <= EndRow then
begin
UpdateCursor;
UpdateScrollBars;
DrawRows(BegRow, EndRow);
end;
end;
function THelpView.ScrollBy(R, C: Word): Byte;
var
Row, Col: Integer;
Flag: Byte;
begin
Row := ScreenPos.Row + R;
Col := ScreenPos.Col + C;
if Row < 0 then
Row := 0
else if Row > GetRowCount then
Row := GetRowCount;
if Col < 0 then
Col := 0
else if Col > MaxLeftCol then
Col := MaxLeftCol;
Flag := Integer(Row <> ScreenPos.Row) shl 1 or Integer(Col <> ScreenPos.Col);
if Flag <> 0 then
begin
ScreenPos.Row := Row;
ScreenPos.Col := Col;
Draw;
Flag := Flag or 4;
end;
ScrollBy := Flag;
end;
function THelpView.ScrollTo(Row, Col: Integer; Len: Word; Center: Boolean):
Byte;
var
R, C, Half: Integer;
begin
Col := Col - ScreenPos.Col;
C := Col;
if C > 0 then
begin
C := C + Len - Size.X;
if C < 0 then
C := 0
else if Col < C then
C := Col;
end;
Row := Row - ScreenPos.Row;
R := Row;
if R > 0 then
begin
R := Row - Size.Y + 1;
if R < 0 then
R := 0;
end;
if Center and (R <> 0) then
begin
Half := Size.Y shr 1;
if R < 0 then
R := R - Half
else
R := R + Half;
end;
if R or C <> 0 then
ScrollTo := ScrollBy(R, C)
else
ScrollTo := 0;
end;
function THelpView.ScrollToCursor: Byte;
var
Flag: Byte;
begin
Flag := ScrollTo(CursorPos.Row, CursorPos.Col, 1, False);
if Flag = 0 then
UpdateCursor;
ScrollToCursor := Flag;
end;
function THelpView.MoveByRaw(R, C: Word; Hilite, Drag: Boolean): Byte;
var
Flag: Byte;
NeedRedraw, Changed: Boolean;
Row, Col, OldRow: Integer;
begin
Row := CursorPos.Row + R;
Col := CursorPos.Col + C;
OldRow := CursorPos.Row;
if Row < 0 then
Row := 0
else if Row >= GetRowCount then
Row := GetRowCount;
if Col < 0 then
Col := 0
else if Col >= 78 then
Col := 77;
Changed := (Row <> CursorPos.Row) or (Col <> CursorPos.Col);
if Changed then
begin
CursorPos.Row := Row;
CursorPos.Col := Col
end;
NeedRedraw := False;
if not InDialog and Drag then
begin
NeedRedraw := Changed;
if BlockPresent then
if CursorPos.Compare(BlockEnd) >= 0 then
begin
BlockBeg := BlockEnd;
BlockEnd := CursorPos;
BlockPresent := False;
end else
BlockBeg := CursorPos
else if CursorPos.Compare(BlockBeg) < 0 then
begin
BlockEnd := BlockBeg;
BlockBeg := CursorPos;
BlockPresent := True;
end else
BlockEnd := CursorPos;
end else
begin
NeedRedraw := BlockBeg.Compare(BlockEnd) <> 0;
BlockPresent := False;
BlockBeg := CursorPos;
BlockEnd := BlockBeg;
end;
Flag := ScrollToCursor;
if Hilite then
HiliteCurrent;
if (Flag and 4 = 0) and NeedRedraw then
if Drag and (Abs(OldRow - Row) < Size.Y shr 1) then
RedrawRows(OldRow, Row)
else
Draw;
MoveByRaw := Flag;
end;
function THelpView.MoveBy(R, C: Integer; Drag: Boolean): Byte;
begin
TrackClear;
MoveBy := MoveByRaw(R, C, True, Drag);
end;
procedure THelpView.MoveToMouse(R, C: Word; Drag: Boolean);
begin
MoveBy(ScreenPos.Row + R - CursorPos.Row,
ScreenPos.Col + C - CursorPos.Col, Drag);
end;
procedure THelpView.MoveCode(RCode, CCode: Byte; Drag: Boolean);
var
R, C, RR, I, J: Integer;
W: THelpWalker;
label
A, B;
begin
R := 0;
C := 0;
RR := 0;
case RCode of
0:
;
1:
begin
if (CursorPos.Row >= ScreenPos.Row) and
(CursorPos.Row < ScreenPos.Row + Size.Y) then
RR := -Size.Y;
R := -Size.Y;
end;
2:
begin
J := CursorPos.Row + Size.Y;
if J > GetRowCount then
J := GetRowCount;
if (J < ScreenPos.Row) or (J >= ScreenPos.Row + Size.Y) then
RR := Size.Y;
R := J - CursorPos.Row;
end;
7:
R := -CursorPos.Row;
8:
R := GetRowCount - CursorPos.Row;
9:
R := ScreenPos.Row - CursorPos.Row;
10:
R := ScreenPos.Row + Size.Y - 1 - CursorPos.Row;
end;
case CCode of
0:
;
5:
C := -CursorPos.Col;
6:
begin
ScrollBy(RR, 0);
MoveBy(R, 0, Drag);
RR := 0;
R := 0;
W.Init(CurScreen, CursorPos.Row);
W.GoEol;
C := W.Col - CursorPos.Col;
end;
4:
begin
W.Init(CurScreen, CursorPos.Row);
W.GoCol(CursorPos.Col);
while W.CurChar in HelpWordChars do
W.GoForward;
while not (W.CurChar in HelpWordChars) do
if W.CurChar = #0 then
begin
Inc(R);
if not W.GetRow(CursorPos.Row + R) then
begin
Dec(R);
W.GetRow(CursorPos.Row + R);
W.GoEol;
goto A;
end
end else
W.GoForward;
A: C := W.Col - CursorPos.Col;
end;
3:
begin
W.Init(CurScreen, CursorPos.Row);
W.GoCol(CursorPos.Col);
W.GoBack;
while not (W.CurChar in HelpWordChars) do
if W.Col = 0 then
if CursorPos.Row + R = 0 then
goto B
else
begin
Dec(R);
W.GetRow(CursorPos.Row + R);
W.GoEol;
end else
W.GoBack;
while (W.Col > 0) and (W.CurChar in HelpWordChars) do
W.GoBack;
if not (W.CurChar in HelpWordChars) then
W.GoForward;
B: C := W.Col - CursorPos.Col;
end;
end;
ScrollBy(RR, 0);
MoveBy(R, C, Drag);
end;
procedure THelpView.ScrollToHilite(MoveCursor: Boolean; Ofs: Integer;
Center: Boolean);
var
R, C: Integer;
Len: Word;
begin
CurScreen^.GetPos(HiliteIndex, R, C, Len);
ScrollTo(R, C, Len, Center);
if MoveCursor then
begin
R := R - CursorPos.Row;
C := C - CursorPos.Col;
if Ofs > 0 then
MoveByRaw(R, C + Ofs, False, False)
else
MoveBy(R, C, False);
end;
end;
procedure THelpView.ChangeHilite(Index: Word; Scroll: Boolean; Ofs: Integer;
Center: Boolean);
var
OldHilite: Word;
Row, Col: Integer;
Len: Word;
begin
if CurScreen^.MaxIndex > 0 then
begin
OldHilite := HiliteIndex;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -