📄 rvedit.pas
字号:
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.ApplyTextStyleConversionProc(Sender: TCustomRichViewEdit; StyleNo, UserData: Integer;
AppliedToText: Boolean;
var NewStyleNo: Integer);
begin
if not (AppliedToText and (rvprStyleProtect in Style.TextStyles[StyleNo].Protection)) then
NewStyleNo := UserData;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.ApplyStyleConversion(UserData: Integer);
begin
{$IFNDEF RVDONOTUSEINPLACE}
if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
TCustomRichViewEdit(InplaceEditor).ApplyStyleConversion(UserData);
exit;
end;
{$ENDIF}
if Assigned(FOnStyleConversion) and BeforeChange(False) then begin
FCurStyleConversion := FOnStyleConversion;
TRVEditRVData(RVData).ApplyStyleConversion_(UserData);
end;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.ApplyParaStyleConversion(UserData: Integer);
begin
{$IFNDEF RVDONOTUSEINPLACE}
if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
TCustomRichViewEdit(InplaceEditor).ApplyParaStyleConversion(UserData);
exit;
end;
{$ENDIF}
if Assigned(FOnParaStyleConversion) and BeforeChange(False) then begin
TRVEditRVData(RVData).BeginUndoSequence(rvutPara, True);
FCurStyleConversion := FOnParaStyleConversion;
TRVEditRVData(RVData).ApplyParaStyle(UserData,True);
end;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.ApplyTextStyle(TextStyleNo: Integer);
begin
{$IFNDEF RVDONOTUSEINPLACE}
if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
TCustomRichViewEdit(InplaceEditor).ApplyTextStyle(TextStyleNo);
exit;
end;
{$ENDIF}
if BeforeChange(False) then begin
FCurStyleConversion := ApplyTextStyleConversionProc;
TRVEditRVData(RVData).ApplyStyleConversion_(TextStyleNo);
end;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.OnBackSpacePress(Ctrl: Boolean);
begin
if not BeforeChange(False) then exit;
TRVEditRVData(RVData).OnBackSpacePress_(Ctrl, False);
Change;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.OnDeletePress(Ctrl: Boolean);
begin
if not BeforeChange(False) then exit;
TRVEditRVData(RVData).OnDeletePress_(Ctrl, False);
Change;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.OnEnterPress(Shift: Boolean);
begin
if not BeforeChange(False) then exit;
TRVEditRVData(RVData).OnEnterPress_(Shift);
Refresh;
Change;
end;
{------------------------------------------------------------------------------}
function TCustomRichViewEdit.InsertRVFFromStreamEd(Stream: TStream):Boolean;
begin
{$IFNDEF RVDONOTUSEINPLACE}
if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
Result := TCustomRichViewEdit(InplaceEditor).InsertRVFFromStreamEd(Stream);
exit;
end;
{$ENDIF}
Result := True;
if not BeforeChange(False) then exit;
if (RVData.PartialSelectedItem<>nil)or not CanDelete then begin
TRVEditRVData(RVData).Beep;
exit;
end;
TRVEditRVData(RVData).BeginUndoSequence(rvutInsert, True);
SetUndoGroupMode(True);
try
TRVEditRVData(RVData).DeleteSelection_;
Result := TRVEditRVData(RVData).InsertRVFFromStreamEd_(Stream);
finally
SetUndoGroupMode(False);
end;
end;
{------------------------------------------------------------------------------}
function TCustomRichViewEdit.InsertRVFFromFileEd(const FileName: String):Boolean;
var Stream: TFileStream;
begin
try
Stream := TFileStream.Create(FileName, fmOpenRead);
try
Result := InsertRVFFromStreamEd(Stream);
finally
Stream.Free;
end;
except
Result := False;
end;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.KeyPress(var Key: Char);
var s: String;
i: Integer;
begin
if rvstIgnoreNextChar in RVData.State then
exit;
if (ord(Key)=VK_RETURN) and (rvoDoNotWantReturns in EditorOptions) then begin
Key := #0;
TRVEditRVData(RVData).Beep;
exit;
end;
if ((Key < #32) or (Key=#127)) and (ord(Key)<>VK_TAB) then exit;
if not BeforeChange(False) then exit;
inherited KeyPress(Key);
if Key=#0 then
exit;
DeleteSelection;
if ord(Key)=VK_TAB then begin
SetLength(s, Style.SpacesInTab);
for i := 1 to Style.SpacesInTab do
s[i] := ' ';
InsertText(s, False);
exit;
end;
TRVEditRVData(RVData).KeyPress(Key);
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.SetCheckpointInfoEd(ItemNo: Integer; ATag: Integer; const AName: String;
ARaiseEvent: Boolean);
var cp: TRVCPInfo;
begin
if not BeforeChange(False) then exit;
cp := TCustomRVItemInfo(RVData.Items.Objects[ItemNo]).Checkpoint;
if cp<>nil then begin
TRVEditRVData(RVData).BeginUndoSequence(rvutModifyCheckpoint, True);
if ATag=cp.Tag then
ATag := RV_CopyTag(ATag, rvoTagsArePChars in Options);
TRVEditRVData(RVData).Do_DeleteCP(ItemNo);
end
else
TRVEditRVData(RVData).BeginUndoSequence(rvutAddCheckpoint, True);
cp := TRVCPInfo.Create;
cp.Name := AName;
cp.Tag := ATag;
cp.RaiseEvent := ARaiseEvent;
TRVEditRVData(RVData).Do_AddCP(ItemNo, cp);
Change;
Invalidate;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.RemoveCheckpointEd(ItemNo: Integer);
begin
if TCustomRVItemInfo(RVData.Items.Objects[ItemNo]).Checkpoint=nil then exit;
if not BeforeChange(False) then exit;
TRVEditRVData(RVData).BeginUndoSequence(rvutRemoveCheckpoint, True);
TRVEditRVData(RVData).Do_DeleteCP(ItemNo);
Change;
Invalidate;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.SetCurrentCheckpointInfo(ATag: Integer; const AName: String;
ARaiseEvent: Boolean);
begin
{$IFNDEF RVDONOTUSEINPLACE}
if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
TCustomRichViewEdit(InplaceEditor).SetCurrentCheckpointInfo(ATag, AName, ARaiseEvent);
exit;
end;
{$ENDIF}
SetCheckpointInfoEd(CurItemNo, ATag, AName, ARaiseEvent);
end;
{------------------------------------------------------------------------------}
function TCustomRichViewEdit.GetCurrentCheckpoint: TCheckpointData;
begin
{$IFNDEF RVDONOTUSEINPLACE}
if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
Result := TCustomRichViewEdit(InplaceEditor).GetCurrentCheckpoint;
exit;
end;
{$ENDIF}
Result := GetItemCheckpoint(CurItemNo);
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.RemoveCurrentCheckpoint;
begin
{$IFNDEF RVDONOTUSEINPLACE}
if (InplaceEditor<>nil) and (InplaceEditor is TCustomRichViewEdit) then begin
TCustomRichViewEdit(InplaceEditor).RemoveCurrentCheckpoint;
exit;
end;
{$ENDIF}
RemoveCheckpointEd(CurItemNo);
end;
{------------------------------------------------------------------------------}
function TCustomRichViewEdit.BeforeChange(FromOutside: Boolean): Boolean;
begin
Result := (not ReadOnly) and (Style<>nil) and
(FromOutside or (RVData.CaptureMouseItem=nil));
if Result then begin
TRVEditRVData(RVData).PrepareForEdit;
if (LockCount<=0) and Assigned(FOnChanging) then
FOnChanging(Self);
end
else
TRVEditRVData(RVData).Beep;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.DoChange(ClearRedo: Boolean);
begin
Modified := True;
ClearSoftPageBreaks;
TRVEditRVData(RVData).ClearJumpsCoords;
if ClearRedo then
TRVEditRVData(RVData).RedoList.Clear;
if (LockCount<=0) and Assigned(FOnChange) then FOnChange(Self);
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.Change;
begin
DoChange(True);
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.BeginUpdate;
begin
inc(LockCount);
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.EndUpdate;
begin
dec(LockCount);
end;
{------------------------------------------------------------------------------}
function TCustomRichViewEdit.CanPasteRVF: Boolean;
begin
Result := Clipboard.HasFormat(RegisterClipboardFormat(RVFormatName));
end;
{------------------------------------------------------------------------------}
{$IFNDEF RVDONOTUSERTFIMPORT}
function TCustomRichViewEdit.CanPasteRTF: Boolean;
begin
Result := Clipboard.HasFormat(RegisterClipboardFormat(RTFormatName));
end;
{$ENDIF}
{------------------------------------------------------------------------------}
function TCustomRichViewEdit.CanPaste: Boolean;
begin
Result := (Clipboard.HasFormat(CF_TEXT) or
{$IFNDEF RVDONOTUSEUNICODE}
Clipboard.HasFormat(CF_UNICODETEXT) or
{$ENDIF}
Clipboard.HasFormat(CF_BITMAP) or
Clipboard.HasFormat(CF_METAFILEPICT) or
{$IFNDEF RVDONOTUSERTFIMPORT}
Clipboard.HasFormat(RegisterClipboardFormat(RTFormatName)) or
{$ENDIF}
Clipboard.HasFormat(RegisterClipboardFormat(RVFormatName)));
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.Paste;
var DoDefault: Boolean;
begin
if not BeforeChange(False) then exit;
try
DoDefault := True;
if Assigned(FOnPaste) then
FOnPaste(Self, DoDefault);
if not DoDefault then exit;
if Clipboard.HasFormat(RegisterClipboardFormat(RVFormatName)) then
PasteRVF
{$IFNDEF RVDONOTUSERTFIMPORT}
else if Clipboard.HasFormat(RegisterClipboardFormat(RTFormatName)) then
PasteRTF
{$ENDIF}
{$IFNDEF RVDONOTUSEUNICODE}
else if Clipboard.HasFormat(CF_UNICODETEXT) then begin
if not Style.TextStyles [TRVEditRVData(RVData).FCurTextStyleNo].Unicode and
Clipboard.HasFormat(CF_TEXT) then
PasteText
else
PasteTextW;
end
{$ENDIF}
else if Clipboard.HasFormat(CF_TEXT) then
PasteText
else if Clipboard.HasFormat(CF_BITMAP) then
PasteBitmap(False)
else if Clipboard.HasFormat(CF_METAFILEPICT) then
PasteMetafile(False)
except
TRVEditRVData(RVData).Beep;
end;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.CutDef;
begin
if not BeforeChange(False) then exit;
if CopyDef then DeleteSelection;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.WMCut(var Message: TWMCut);
begin
CutDef;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.WMPaste(var Message: TWMpaste);
begin
Paste;
end;
{------------------------------------------------------------------------------}
procedure TCustomRichViewEdit.EMCanPaste(var Message: TMessage);
begin
Message.Result := 0;
if ReadOnly then
exit;
case Message.WParam of
0:
Message.Result := Integer(CanPaste);
CF_BITMAP, CF_TEXT, CF_UNICODETEXT, CF_METAFILEPICT:
Message.Result := Integer(Clipboard.HasFormat(Message.WParam));
else
{$IFNDEF RVDONOTUSERTFIMPORT}
if UINT(Message.WParam)=RegisterClipboardFormat(RTFormatName) then
Message.Result := Integer(CanPasteRTF)
else
{$ENDIF}
if UINT(Message.WParam)=RegisterClipboardFormat(RVFormatName)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -