📄 richedeh.pas
字号:
end;
procedure TRichStrEditDlgEh.PerformFileOpen(const AFileName: string);
begin
Editor.Lines.LoadFromFile(AFileName);
Editor.SetFocus;
Editor.Modified := False;
SetModified(False);
end;
procedure TRichStrEditDlgEh.FileOpen(Sender: TObject);
begin
if OpenDialog.Execute then
begin
PerformFileOpen(OpenDialog.FileName);
Editor.ReadOnly := ofReadOnly in OpenDialog.Options;
end;
end;
procedure TRichStrEditDlgEh.FileSave(Sender: TObject);
begin
FileSaveAs(Sender)
end;
procedure TRichStrEditDlgEh.FileSaveAs(Sender: TObject);
begin
if SaveDialog.Execute then
begin
if not (AnsiUpperCase(Copy(SaveDialog.FileName, Length(SaveDialog.FileName) - 3, 4)) = '.RTF') then
SaveDialog.FileName := SaveDialog.FileName + '.rtf';
if FileExists(SaveDialog.FileName) then
if MessageDlg(Format(sOverWrite, [SaveDialog.FileName]),
mtConfirmation, mbYesNoCancel, 0) <> idYes then Exit;
Editor.Lines.SaveToFile(SaveDialog.FileName);
Editor.Modified := False;
SetModified(False);
end;
end;
procedure TRichStrEditDlgEh.FilePrint(Sender: TObject);
begin
if PrintDialog.Execute then
Editor.Print(FFileName);
end;
procedure TRichStrEditDlgEh.FileExit(Sender: TObject);
begin
Close;
end;
procedure TRichStrEditDlgEh.EditUndo(Sender: TObject);
begin
with Editor do
if HandleAllocated then SendMessage(Handle, EM_UNDO, 0, 0);
end;
procedure TRichStrEditDlgEh.EditCut(Sender: TObject);
begin
Editor.CutToClipboard;
end;
procedure TRichStrEditDlgEh.EditCopy(Sender: TObject);
begin
Editor.CopyToClipboard;
end;
procedure TRichStrEditDlgEh.EditPaste(Sender: TObject);
begin
Editor.PasteFromClipboard;
end;
procedure TRichStrEditDlgEh.SelectFont(Sender: TObject);
begin
FontDialog1.Font.Assign(Editor.SelAttributes);
if FontDialog1.Execute then
CurrText.Assign(FontDialog1.Font);
SelectionChange(Self);
Editor.SetFocus;
end;
procedure TRichStrEditDlgEh.RulerResize(Sender: TObject);
begin
RulerLine.Width := Ruler.ClientWidth - (RulerLine.Left * 2);
end;
procedure TRichStrEditDlgEh.FormResize(Sender: TObject);
begin
SetEditRect;
SelectionChange(Sender);
end;
procedure TRichStrEditDlgEh.FormPaint(Sender: TObject);
begin
SetEditRect;
end;
procedure TRichStrEditDlgEh.BoldButtonClick(Sender: TObject);
begin
if FUpdating then Exit;
if BoldButton.Down then
CurrText.Style := CurrText.Style + [fsBold]
else
CurrText.Style := CurrText.Style - [fsBold];
end;
procedure TRichStrEditDlgEh.ItalicButtonClick(Sender: TObject);
begin
if FUpdating then Exit;
if ItalicButton.Down then
CurrText.Style := CurrText.Style + [fsItalic]
else
CurrText.Style := CurrText.Style - [fsItalic];
end;
procedure TRichStrEditDlgEh.FontSizeChange(Sender: TObject);
begin
if FUpdating then Exit;
CurrText.Size := StrToInt(FontSize.Text);
end;
procedure TRichStrEditDlgEh.AlignButtonClick(Sender: TObject);
begin
if FUpdating then Exit;
Editor.Paragraph.Alignment := TAlignment(TControl(Sender).Tag);
end;
procedure TRichStrEditDlgEh.FontNameChange(Sender: TObject);
begin
if FUpdating then Exit;
CurrText.Name := FontName.Items[FontName.ItemIndex];
end;
procedure TRichStrEditDlgEh.UnderlineButtonClick(Sender: TObject);
begin
if FUpdating then Exit;
if UnderlineButton.Down then
CurrText.Style := CurrText.Style + [fsUnderline]
else
CurrText.Style := CurrText.Style - [fsUnderline];
end;
procedure TRichStrEditDlgEh.BulletsButtonClick(Sender: TObject);
begin
if FUpdating then Exit;
Editor.Paragraph.Numbering := TNumberingStyle(BulletsButton.Down);
end;
{ Ruler Indent Dragging }
procedure TRichStrEditDlgEh.RulerItemMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDragOfs := (TLabel(Sender).Width div 2);
TLabel(Sender).Left := TLabel(Sender).Left + X - FDragOfs;
FDragging := True;
end;
procedure TRichStrEditDlgEh.RulerItemMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
if FDragging then
TLabel(Sender).Left := TLabel(Sender).Left + X - FDragOfs
end;
procedure TRichStrEditDlgEh.FirstIndMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDragging := False;
Editor.Paragraph.FirstIndent := Trunc((FirstInd.Left + FDragOfs - GutterWid) / RulerAdj);
LeftIndMouseUp(Sender, Button, Shift, X, Y);
end;
procedure TRichStrEditDlgEh.LeftIndMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDragging := False;
Editor.Paragraph.LeftIndent := Trunc((LeftInd.Left + FDragOfs - GutterWid) / RulerAdj) - Editor.Paragraph.FirstIndent;
SelectionChange(Sender);
end;
procedure TRichStrEditDlgEh.RightIndMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FDragging := False;
Editor.Paragraph.RightIndent := Trunc((Ruler.ClientWidth - RightInd.Left + FDragOfs - 2) / RulerAdj) - 2 * GutterWid;
SelectionChange(Sender);
end;
procedure TRichStrEditDlgEh.UpdateCursorPos;
var
CharPos: TPoint;
begin
CharPos.Y := SendMessage(Editor.Handle, EM_EXLINEFROMCHAR, 0,
Editor.SelStart);
CharPos.X := (Editor.SelStart -
SendMessage(Editor.Handle, EM_LINEINDEX, CharPos.Y, 0));
Inc(CharPos.Y);
Inc(CharPos.X);
StatusBar.Panels[0].Text := Format(sColRowInfo, [CharPos.Y, CharPos.X]);
// update the status of the cut and copy command
CopyButton.Enabled := Editor.SelLength > 0;
EditCopyItem.Enabled := CopyButton.Enabled;
CutButton.Enabled := CopyButton.Enabled;
EditCutItem.Enabled := CopyButton.Enabled;
end;
procedure TRichStrEditDlgEh.FormShow(Sender: TObject);
begin
UpdateCursorPos;
DragAcceptFiles(Handle, True);
RichEditChange(nil);
Editor.SetFocus;
end;
procedure TRichStrEditDlgEh.WMDropFiles(var Msg: TWMDropFiles);
var
CFileName: array[0..MAX_PATH] of Char;
begin
try
{$IFDEF CIL}
{ TODO : To do DropFile }
{$ELSE}
if DragQueryFile(Msg.Drop, 0, CFileName, MAX_PATH) > 0 then
begin
PerformFileOpen(CFileName);
Msg.Result := 0;
end;
{$ENDIF}
finally
DragFinish(Msg.Drop);
end;
end;
procedure TRichStrEditDlgEh.RichEditChange(Sender: TObject);
begin
SetModified(Editor.Modified);
end;
procedure TRichStrEditDlgEh.SetModified(Value: Boolean);
begin
if Value then StatusBar.Panels[1].Text := sModified
else StatusBar.Panels[1].Text := '';
end;
{ TRichEditStringsEh }
procedure TRichEditStringsEh.Edit;
var
Stream: TStringStream;
begin
with TRichStrEditDlgEh.Create(Application) do
try
Stream := TStringStream.Create('');
{$IFDEF CIL}
TStrings(GetObjValue).SaveToStream(Stream);
{$ELSE}
TStrings(GetOrdValue).SaveToStream(Stream);
{$ENDIF}
Stream.Position := 0;
Editor.Lines.LoadFromStream(Stream);
case ShowModal of
mrOk:
begin
Stream.Position := 0;
Editor.Lines.SaveToStream(Stream);
Stream.Position := 0;
{$IFDEF CIL}
TStrings(GetObjValue).LoadFromStream(Stream);
{$ELSE}
TStrings(GetOrdValue).LoadFromStream(Stream);
{$ENDIF}
Modified;
// SetOrdValue(Longint(Editor.Lines));
end;
end;
Stream.Free;
finally
Free;
end;
end;
function TRichEditStringsEh.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paDialog] - [paSubProperties];
end;
procedure TRichStrEditDlgEh.EditorKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_ESCAPE then Close;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -