📄 qimport3txtview.pas
字号:
else
Style := Style or WS_BORDER;
WindowClass.Style := WindowClass.Style and not (CS_HREDRAW or CS_VREDRAW);
end;
end;
procedure TQImport3TXTViewer.DrawRulers;
begin
if FBottomRuler.Step = 0 then
FBottomRuler.Step := FCharWidth;
if FTopRuler.Step = 0 then
FTopRuler.Step := FCharWidth;
end;
procedure TQImport3TXTViewer.DrawLines;
var
i, t, cnt: integer;
ScrollInfo: TScrollInfo;
begin
{$IFDEF QI_UNICODE}
cnt := FLinesW.Count;
{$ELSE}
cnt := FLines.Count;
{$ENDIF}
for i := 0 to cnt - 1 do
begin
t := FRealTop + FTopRuler.Height + 3 + i * (FCharHeight + 1);
if (t > 0) and (t < ClientHeight - FBottomRuler.Height - FTopRuler.Height) then
begin
{$IFDEF QI_UNICODE}
Canvas.TextOutW(FRealLeft + FCharWidth, t, FLinesW[i] + ' ');
{$ELSE}
Canvas.TextOut(FRealLeft + FCharWidth, t, FLines[i] + ' ');
{$ENDIF}
end;
end;
if FSelection.Exists then
InvertRect(Canvas.Handle, FSelection.VisibleRect);
if GetFullWidth > ClientWidth then
begin
if ScrollBars = ssVertical then
ScrollBars := ssBoth
else if ScrollBars = ssNone then
ScrollBars := ssHorizontal;
ScrollInfo.cbSize := SizeOf(ScrollInfo);
ScrollInfo.fMask := SIF_ALL;
GetScrollInfo(Self.Handle, SB_HORZ, ScrollInfo);
ScrollInfo.nMin := 0;
if FCharWidth = 0
then ScrollInfo.nMax := 0
else ScrollInfo.nMax := FMaxLineLength - 1;
SetScrollInfo(Self.Handle, SB_HORZ, ScrollInfo, True);
end;
if GetFullHeight > ClientHeight then
begin
if ScrollBars = ssHorizontal then
ScrollBars := ssBoth
else if ScrollBars = ssNone then
ScrollBars := ssVertical;
ScrollInfo.cbSize := SizeOf(ScrollInfo);
ScrollInfo.fMask := SIF_ALL;
GetScrollInfo(Self.Handle, SB_VERT, ScrollInfo);
ScrollInfo.nMin := 0;
if FCharHeight = 0
then ScrollInfo.nMax := 0
else ScrollInfo.nMax := GetFullHeight div FCharHeight - 1;
SetScrollInfo(Self.Handle, SB_VERT, ScrollInfo, True);
end;
end;
procedure TQImport3TXTViewer.DrawArrow(Index: integer);
var
ATop, AHeight: integer;
begin
ATop := 16;
AHeight := ClientHeight - ATop;
Canvas.MoveTo(FArrows[Index].Position, ATop);
Canvas.LineTo(FArrows[Index].Position, AHeight);
end;
procedure TQImport3TXTViewer.DrawArrows;
var
i, l: integer;
begin
for i := 0 to FArrows.Count - 1 do
begin
l := GetNewArrowPosition(FArrows[i].Position);
if l > 0 then
FArrows[i].Position := l;
DrawArrow(i);
end;
end;
procedure TQImport3TXTViewer.Paint;
begin
inherited;
if Assigned(Parent) then
begin
if FCharHeight = 0 then
begin
{$IFDEF QI_UNICODE}
FCharHeight := Canvas.TextHeightW('A');
{$ELSE}
FCharHeight := Canvas.TextHeight('A');
{$ENDIF}
end;
if FCharWidth = 0 then
begin
{$IFDEF QI_UNICODE}
FCharWidth := Canvas.TextWidthW('A');
{$ELSE}
FCharWidth := Canvas.TextWidth('A');
{$ENDIF}
end;
FRealHeight := GetFullHeight;
FRealWidth := GetFullWidth;
DrawRulers;
DrawLines;
if not Assigned(FActiveArrow) then DrawArrows;
end;
end;
procedure TQImport3TXTViewer.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
Index, L, R, L1, R1: integer;
Arrow: TViewArrow;
begin
inherited;
if not (ssLeft in Shift) then Exit;
if ssDouble in Shift then
begin
if FArrows.FindBetweenExcept(X - 3, X + 3, -1, Index) then
begin
if FSelection.Exists and
((FArrows[Index] = FSelection.LeftArrow) or
(FArrows[Index] = FSelection.RightArrow)) then
FSelection.SetSelection(nil, nil);
DrawArrow(Index);
if Assigned(FOnDeleteArrow) then
FOnDeleteArrow(Self, (FArrows[Index].Position - FRealLeft) div FCharWidth - 1);
FArrows.Delete(Index);
Cursor := crDefault;
end
else begin
L := GetNewArrowPosition(X);
if ((L - FRealLeft) div FCharWidth) < 1 then Exit;
Arrow := FArrows.Add;
Arrow.Position := GetNewArrowPosition(X);
DrawArrow(Arrow.Index);
if FSelection.Exists and
((Arrow.Position > FSelection.LeftArrow.Position) and
(Arrow.Position < FSelection.RightArrow.Position)) then
FSelection.SetSelection(nil, nil);
//FArrows.Sort;
end;
end
else begin
if FArrows.FindBetweenExcept(X - 3, X + 3, -1, Index) then
FActiveArrow := FArrows[Index]
else begin
if FArrows.FindLeftAndRight(X, L, R) then
begin
L1 := -1;
R1 := -1;
if FSelection.Exists then
begin
L1 := FSelection.LeftArrow.Index;
R1 := FSelection.RightArrow.Index;
FSelection.SetSelection(nil, nil);
end;
if (L <> L1) and (R <> R1) then
FSelection.SetSelection(FArrows[L], FArrows[R]);
end;
end;
end
end;
procedure TQImport3TXTViewer.MouseMove(Shift: TShiftState; X, Y: Integer);
var
OP, NP, Index: integer;
begin
inherited;
if Shift = [] then
begin
if FArrows.FindBetweenExcept(X - 3, X + 3, -1, Index)
then Cursor := crHSplit
else Cursor := crDefault;
end
else if (ssLeft in Shift) and Assigned(FActiveArrow) then
begin
if X - FRealLeft < FCharWidth then // ab
Exit;
OP := FActiveArrow.Position;
if not FArrows.FindBetweenExcept(OP, Op, FActiveArrow.Index, Index) then
DrawArrow(FActiveArrow.Index);
NP := GetNewArrowPosition(X);
FActiveArrow.Position := NP;
if Assigned(FOnMoveArrow) then
FOnMoveArrow(Self, (OP - FRealLeft) div FCharWidth - 1,
(NP - FRealLeft) div FCharWidth - 1);
if not FArrows.FindBetweenExcept(NP, NP, FActiveArrow.Index, Index) then
begin
DrawArrow(FActiveArrow.Index);
if (FActiveArrow = FSelection.LeftArrow) or
(FActiveArrow = FSelection.RightArrow) then
begin
FSelection.Update;
end;
end
else begin
FSelection.SetSelection(nil, nil);
if Assigned(FOnIntersectArrows) then
FOnIntersectArrows(Self, (NP - FRealLeft) div FCharWidth - 1);
end;
end;
end;
procedure TQImport3TXTViewer.MouseUp(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
L, Index: integer;
begin
inherited;
if Assigned(FActiveArrow) then
begin
if X - FRealLeft >= FCharWidth then // ab
begin
L := GetNewArrowPosition(X);
if FArrows.FindBetweenExcept(L, L, FActiveArrow.Index, Index) then
FArrows.Delete(FActiveArrow.Index)
else if ((L - FRealLeft) div FCharWidth) < 1 then
begin
DrawArrow(FActiveArrow.Index);
FArrows.Delete(FActiveArrow.Index);
end;
// else DrawArrow(FActiveArrow.Index);
end;
FActiveArrow := nil;
//FArrows.Sort;
end;
end;
procedure TQImport3TXTViewer.SetScrollBars(const Value: TScrollStyle);
begin
if FScrollBars <> Value then
begin
FScrollBars := Value;
RecreateWnd;
end;
end;
function TQImport3TXTViewer.CreateRuler(Align: TViewRulerAlign): TViewRuler;
begin
Result := TViewRuler.Create(Self);
Result.Parent := Self;
Result.Align := Align;
Result.Step := FCharWidth;
end;
function TQImport3TXTViewer.GetFullWidth: integer;
begin
Result := FCharWidth * FMaxLineLength;
end;
function TQImport3TXTViewer.GetFullHeight: integer;
begin
Result := FCharHeight * {$IFDEF QI_UNICODE}FLinesW{$ELSE}FLines{$ENDIF}.Count;
// Result := ClientHeight - FRealTop - FBottomRuler.Height;
end;
procedure TQImport3TXTViewer.WMHScroll(var Msg: TWMHScroll);
procedure HorzScroll(Step: integer);
begin
FBottomRuler.Offset := FBottomRuler.Offset + (FCharWidth + 1) * Step;
FTopRuler.Offset := FTopRuler.Offset + (FCharWidth + 1) * Step;
end;
var
OldScroll, NewScroll: TScrollInfo;
i, Step: integer;
begin
OldScroll.cbSize := SizeOf(OldScroll);
OldScroll.fMask := SIF_ALL;
GetScrollInfo(Self.Handle, SB_HORZ, OldScroll);
OldScroll.nMin := 0;
if FCharWidth = 0
then OldScroll.nMax := 0
else OldScroll.nMax := FMaxLineLength - 1;
NewScroll := OldScroll;
case Msg.ScrollCode of
SB_LINELEFT,
SB_PAGELEFT:
if NewScroll.nPos > NewScroll.nMin then
begin
if Msg.ScrollCode = SB_LINELEFT
then Step := 1
else Step := 10;
if NewScroll.nPos <= NewScroll.nMin + Step then
Step := NewScroll.nPos - NewScroll.nMin;
Dec(NewScroll.nPos, Step);
Inc(FRealLeft, FCharWidth * Step);
ScrollBy(FCharWidth * Step, 0);
HorzScroll(Step);
for i := 0 to FArrows.Count - 1 do
FArrows[i].Position := FArrows[i].Position + FCharWidth * Step;
end;
SB_LINERIGHT,
SB_PAGERIGHT:
if NewScroll.nPos < NewScroll.nMax then
begin
if Msg.ScrollCode = SB_LINERIGHT
then Step := 1
else Step := 10;
if NewScroll.nPos >= NewScroll.nMax - Step then
Step := NewScroll.nMax - NewScroll.nPos;
Inc(NewScroll.nPos, Step);
Dec(FRealLeft, FCharWidth * Step);
ScrollBy(-FCharWidth * Step, 0);
HorzScroll(-Step);
for i := 0 to FArrows.Count - 1 do
FArrows[i].Position := FArrows[i].Position - FCharWidth * Step;
end;
SB_THUMBTRACK:
if NewScroll.nPos <> NewScroll.nTrackPos then
begin
FRealLeft := FRealLeft -
(NewScroll.nTrackPos - NewScroll.nPos) * FCharWidth;
ScrollBy((NewScroll.nPos - NewScroll.nTrackPos) * FCharWidth, 0);
HorzScroll(NewScroll.nPos - NewScroll.nTrackPos);
for i := 0 to FArrows.Count - 1 do
FArrows[i].Position := FArrows[i].Position -
(NewScroll.nTrackPos - NewScroll.nPos) * FCharWidth;
NewScroll.nPos := NewScroll.nTrackPos;
end;
else Exit;
end;
if @OldScroll <> @NewScroll then
SetScrollInfo(Self.Handle, SB_HORZ, NewScroll, True);
FSelection.Update;
end;
procedure TQImport3TXTViewer.WMVScroll(var Msg: TWMVScroll);
var
OldScroll, NewScroll: TScrollInfo;
Step: integer;
begin
OldScroll.cbSize := SizeOf(OldScroll);
OldScroll.fMask := SIF_ALL;
GetScrollInfo(Self.Handle, SB_VERT, OldScroll);
OldScroll.nMin := 0;
if FCharWidth = 0 then
OldScroll.nMax := 0
else
OldScroll.nMax := {$IFDEF QI_UNICODE}FLinesW{$ELSE}FLines{$ENDIF}.Count - 1;
NewScroll := OldScroll;
case Msg.ScrollCode of
SB_LINEUP,
SB_PAGEUP:
if NewScroll.nPos > NewScroll.nMin then
begin
if Msg.ScrollCode = SB_LINEUP
then Step := 1
else Step := 10;
if NewScroll.nPos <= NewScroll.nMin + Step then
Step := NewScroll.nPos - NewScroll.nMin;
Dec(NewScroll.nPos, Step);
Inc(FRealTop, FCharHeight * Step);
ScrollBy(0, FCharHeight * Step);
end;
SB_LINEDOWN,
SB_PAGEDOWN:
if NewScroll.nPos < NewScroll.nMax then
begin
if Msg.ScrollCode = SB_LINEDOWN
then Step := 1
else Step := 10;
if NewScroll.nPos >= NewScroll.nMax - Step then
Step := NewScroll.nMax - NewScroll.nPos;
Inc(NewScroll.nPos, Step);
Dec(FRealTop, FCharHeight * Step);
ScrollBy(0, -FCharHeight * Step);
end;
SB_THUMBTRACK:
if NewScroll.nPos <> NewScroll.nTrackPos then
begin
FRealTop := FRealTop -
(NewScroll.nTrackPos - NewScroll.nPos) * FCharHeight;
ScrollBy(0, (NewScroll.nPos - NewScroll.nTrackPos) * FCharHeight);
NewScroll.nPos := NewScroll.nTrackPos;
end;
else Exit;
end;
if @OldScroll <> @NewScroll then
SetScrollInfo(Self.Handle, SB_VERT, NewScroll, True);
end;
function TQImport3TXTViewer.GetNewArrowPosition(X: integer): integer;
begin
Result := 0;
if (FCharWidth > 0) and (X > 0) then
begin
if (X mod FCharWidth) > (FCharWidth / 2) then
Result := ((X div FCharWidth) + 1) * FCharWidth
else Result := (X div FCharWidth) * FCharWidth;
end
end;
procedure TQImport3TXTViewer.ChangeSelection(Sender: TObject);
begin
if Assigned(FOnChangeSelection) then FOnChangeSelection(Self);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -