📄 jveditorcommon.pas
字号:
begin
{
Result := FPtr < Count;
}
Result := False;
ClearRedo;
end;
//=== { TJvUndo } ============================================================
constructor TJvUndo.Create(AJvEditor: TJvCustomEditorBase);
begin
inherited Create;
FJvEditor := AJvEditor;
FModified := FJvEditor.FModified;
UndoBuffer.Add(Self);
FSelection := nil;
end;
destructor TJvUndo.Destroy;
begin
if Assigned(FSelection) then
Dispose(FSelection);
// (rom) added inherited Destroy
inherited Destroy;
end;
procedure TJvUndo.Redo;
begin
RedoNotImplemented;
end;
procedure TJvUndo.RestoreSelection;
begin
if Assigned(FSelection) then
begin
FJvEditor.FSelection := FSelection^;
FJvEditor.SetSelUpdateRegion(FSelection^.SelBegY, FSelection^.SelEndY);
end;
end;
procedure TJvUndo.SaveSelection;
begin
if not Assigned(FSelection) then
New(FSelection);
FSelection^ := FJvEditor.FSelection;
end;
function TJvUndo.UndoBuffer: TJvUndoBuffer;
begin
if FJvEditor <> nil then
Result := FJvEditor.FUndoBuffer
else
Result := nil;
end;
//=== { TJvCaretUndo } =======================================================
constructor TJvCaretUndo.Create(AJvEditor: TJvCustomEditorBase;
ACaretX, ACaretY: Integer);
begin
inherited Create(AJvEditor);
FCaretX := ACaretX;
FCaretY := ACaretY;
end;
procedure TJvCaretUndo.Undo;
begin
with UndoBuffer do
begin
Dec(FPtr);
while JvEditor.FGroupUndo and (FPtr >= 0) and not IsNewGroup(Self) do
Dec(FPtr);
Inc(FPtr);
with TJvCaretUndo(Items[FPtr]) do
JvEditor.SetCaretInternal(FCaretX, FCaretY);
end;
end;
//=== { TJvSelectUndo } ======================================================
constructor TJvSelectUndo.Create(AJvEditor: TJvCustomEditorBase;
ACaretX, ACaretY: Integer);
begin
inherited Create(AJvEditor, ACaretX, ACaretY);
SaveSelection;
end;
procedure TJvSelectUndo.Undo;
var
LastSel: TJvSelectUndo;
LastCaret: TJvCaretUndo;
begin
LastSel := Self;
LastCaret := nil;
{ Undo TJvSelectUndo and TJvCaretUndo in one action. This prevents
unnecessary caret movement with scolling. }
with UndoBuffer do
begin
while (FPtr >= 0) and ((not IsNewGroup(Self)) or (IsCaretGroup)) do
begin
if LastUndo.ClassType = TJvCaretUndo then
LastCaret := TJvCaretUndo(LastUndo)
else
LastSel := TJvSelectUndo(LastUndo);
Dec(FPtr);
if not FJvEditor.FGroupUndo then
Break;
end;
Inc(FPtr);
end;
LastSel.RestoreSelection;
if LastCaret <> nil then
LastCaret.Undo
else
FJvEditor.SetCaretInternal(LastSel.FCaretX, LastSel.FCaretY);
end;
//=== { TJvBeginCompoundUndo } ===============================================
procedure TJvBeginCompoundUndo.Undo;
begin
{ nothing }
end;
//=== { TJvControlScrollBar95 } ==============================================
const
SBKIND: array [TScrollBarKind] of Integer = (SB_HORZ, SB_VERT);
constructor TJvControlScrollBar95.Create;
begin
inherited Create;
FPage := 1;
FSmallChange := 1;
FLargeChange := 1;
end;
procedure TJvControlScrollBar95.SetParams(AMin, AMax, APosition, APage: Integer);
var
ScrollInfo: TScrollInfo;
begin
if AMax < AMin then
raise EInvalidOperation.CreateRes(@SScrollBarRange);
if APosition < AMin then
APosition := AMin;
if APosition > AMax then
APosition := AMax;
if Handle > 0 then
begin
with ScrollInfo do
begin
cbSize := SizeOf(TScrollInfo);
fMask := SIF_DISABLENOSCROLL;
if (AMin >= 0) or (AMax >= 0) then
fMask := fMask or SIF_RANGE;
if APosition >= 0 then
fMask := fMask or SIF_POS;
if APage >= 0 then
fMask := fMask or SIF_PAGE;
nPos := APosition;
nMin := AMin;
nMax := AMax;
nPage := APage;
end;
SetScrollInfo(
Handle, // handle of window with scroll bar
SBKIND[Kind], // scroll bar flag
ScrollInfo, // pointer to structure with scroll parameters
True); // redraw flag
end;
end;
procedure TJvControlScrollBar95.SetParam(Index, Value: Integer);
begin
case Index of
0:
FMin := Value;
1:
FMax := Value;
2:
FPosition := Value;
3:
FPage := Value;
end;
if FMax < FMin then
raise EInvalidOperation.CreateRes(@SScrollBarRange);
if FPosition < FMin then
FPosition := FMin;
if FPosition > FMax then
FPosition := FMax;
SetParams(FMin, FMax, FPosition, FPage);
end;
procedure TJvControlScrollBar95.DoScroll(var Msg: TWMScroll);
var
ScrollPos: Integer;
NewPos: Longint;
ScrollInfo: TScrollInfo;
begin
with Msg do
begin
NewPos := FPosition;
case TScrollCode(ScrollCode) of
scLineUp:
Dec(NewPos, FSmallChange);
scLineDown:
Inc(NewPos, FSmallChange);
scPageUp:
Dec(NewPos, FLargeChange);
scPageDown:
Inc(NewPos, FLargeChange);
scPosition, scTrack:
with ScrollInfo do
begin
cbSize := SizeOf(ScrollInfo);
fMask := SIF_ALL;
GetScrollInfo(Handle, SBKIND[Kind], ScrollInfo);
NewPos := nTrackPos;
end;
scTop:
NewPos := FMin;
scBottom:
NewPos := FMax;
end;
if NewPos < FMin then
NewPos := FMin;
if NewPos > FMax then
NewPos := FMax;
ScrollPos := NewPos;
Scroll(TScrollCode(ScrollCode), ScrollPos);
end;
Position := ScrollPos;
end;
procedure TJvControlScrollBar95.Scroll(ScrollCode: TScrollCode; var ScrollPos: Integer);
begin
if Assigned(FOnScroll) then
FOnScroll(Self, ScrollCode, ScrollPos);
end;
//=== { TJvEditKey } =========================================================
constructor TJvEditKey.Create(const ACommand: TEditCommand; const AKey1: Word;
const AShift1: TShiftState);
begin
inherited Create;
Key1 := AKey1;
Shift1 := AShift1;
Command := ACommand;
end;
constructor TJvEditKey.Create2(const ACommand: TEditCommand; const AKey1: Word;
const AShift1: TShiftState; const AKey2: Word; const AShift2: TShiftState);
begin
inherited Create;
Key1 := AKey1;
Shift1 := AShift1;
Key2 := AKey2;
Shift2 := AShift2;
Command := ACommand;
end;
//=== { TJvKeyboard } ========================================================
constructor TJvKeyboard.Create;
begin
inherited Create;
FList := TObjectList.Create;
end;
destructor TJvKeyboard.Destroy;
begin
FList.Free;
inherited Destroy;
end;
procedure TJvKeyboard.Assign(Source: TPersistent);
var
I: Integer;
begin
if Source is TJvKeyboard then
begin
Clear;
for I := 0 to TJvKeyboard(Source).FList.Count - 1 do
with TJvEditKey(TJvKeyboard(Source).FList[I]) do
Add2(Command, Key1, Shift1, Key2, Shift2);
end
else
inherited Assign(Source);
end;
procedure TJvKeyboard.Add(const ACommand: TEditCommand; const AKey1: Word;
const AShift1: TShiftState);
begin
FList.Add(TJvEditKey.Create(ACommand, AKey1, AShift1));
end;
procedure TJvKeyboard.Add2(const ACommand: TEditCommand; const AKey1: Word;
const AShift1: TShiftState; const AKey2: Word; const AShift2: TShiftState);
begin
FList.Add(TJvEditKey.Create2(ACommand, AKey1, AShift1, AKey2, AShift2));
end;
procedure TJvKeyboard.Add2Ctrl(const ACommand: TEditCommand;
const AKey1: Word; const AShift1: TShiftState; const AKey2: Word);
begin
Add2(ACommand, AKey1, AShift1, AKey2, [ssCtrl]);
Add2(ACommand, AKey1, AShift1, AKey2, []);
end;
procedure TJvKeyboard.Remove(const AKey1: Word; const AShift1: TShiftState);
begin
Remove2(AKey1, AShift1, 0, []);
end;
procedure TJvKeyboard.Remove2(const AKey1: Word; const AShift1: TShiftState;
const AKey2: Word; const AShift2: TShiftState);
var
I: Integer;
ek: TJvEditKey;
begin
for I := FList.Count - 1 downto 0 do
begin
ek := TJvEditKey(FList[I]);
if (ek.Key1 = AKey1) and (ek.Shift1 = AShift1) and
(ek.Key2 = AKey2) and (ek.Shift2 = AShift2) then
FList.Delete(I);
end;
end;
procedure TJvKeyboard.RemoveCtrl(const ACommand: TEditCommand);
var
I: Integer;
begin
for I := FList.Count - 1 downto 0 do
if TJvEditKey(FList[I]).Command = ACommand then
FList.Delete(I);
end;
procedure TJvKeyboard.Clear;
begin
FList.Clear;
end;
function TJvKeyboard.Command(const AKey: Word; const AShift: TShiftState): TEditCommand;
var
I: Integer;
begin
Result := 0;
for I := 0 to FList.Count - 1 do
with TJvEditKey(FList[I]) do
if (Key1 = AKey) and (Shift1 = AShift) then
begin
if Key2 = 0 then
Result := Command
else
Result := twoKeyCommand;
Exit;
end;
end;
function TJvKeyboard.Command2(const AKey1: Word; const AShift1: TShiftState;
const AKey2: Wor
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -