📄 rm_rxrichedit.pas
字号:
liDC := GetDC(0);
liMetaFile := TMetaFile.Create;
try
if aRender then
begin
liWidth := mmSaveWidth - mmSaveGapX * 2 - _CalcHFrameWidth(mmSaveFWLeft, mmSaveFWRight);
liHeight := mmSaveHeight - mmSaveGapY * 2 - _CalcVFrameWidth(mmSaveFWTop, mmSaveFWBottom);
end
else
begin
liWidth := mmWidth - mmGapLeft * 2 - _CalcHFrameWidth(LeftFrame.mmWidth, RightFrame.mmWidth);
liHeight := mmHeight - mmGapTop * 2 - _CalcVFrameWidth(TopFrame.mmWidth, BottomFrame.mmWidth);
end;
liCanvasRect := Rect(0, 0,
Round(RMFromMMThousandths_Printer(liWidth, rmrtHorizontal, liPrinter)) + 1,
Round(RMFromMMThousandths_Printer(liHeight, rmrtVertical, liPrinter)));
liMetaFile.Width := liCanvasRect.Right - liCanvasRect.Left;
liMetaFile.Height := liCanvasRect.Bottom - liCanvasRect.Top;
liMetaFileCanvas := TMetaFileCanvas.Create(liMetaFile, liDC);
liMetaFileCanvas.Brush.Style := bsClear;
FEndCharPos := FormatRange(liMetaFileCanvas.Handle, liDC, liCanvasRect, liCharRange, aRender);
liMetaFileCanvas.Free;
if liPrinter.DC = 0 then
ReleaseDC(0, liDC);
if aRender then
begin
if DocMode = rmdmDesigning then
begin
liBitmap := TBitmap.Create;
liBitmap.Width := RealRect.Right - RealRect.Left + 1;
liBitmap.Height := RealRect.Bottom - RealRect.Top + 1;
liBitmap.Canvas.StretchDraw(Rect(0, 0, liBitmap.Width, liBitmap.Height), liMetaFile);
Canvas.Draw(RealRect.Left, RealRect.Top, liBitmap);
liBitmap.Free;
end
else
Canvas.StretchDraw(RealRect, liMetaFile);
end;
finally
liMetaFile.Free;
end;
end;
begin
FEndCharPos := FStartCharPos;
liCharRange.cpMax := -1;
liCharRange.cpMin := FEndCharPos;
if DocMode = rmdmPrinting then
_ShowRichOnPrinter
else
_ShowRichOnScreen;
end;
{$WARNINGS ON}
procedure TRMRxRichView.Draw(aCanvas: TCanvas);
begin
BeginDraw(aCanvas);
CalcGaps;
with aCanvas do
begin
ShowBackground;
FStartCharPos := 0;
InflateRect(RealRect, -RMToScreenPixels(mmGapLeft, rmutMMThousandths),
-RMToScreenPixels(mmGapTop, rmutMMThousandths));
if (spWidth > 0) and (spHeight > 0) then
ShowRichText(True);
ShowFrame;
end;
RestoreCoord;
end;
procedure TRMRxRichView.Prepare;
begin
inherited Prepare;
FStartCharPos := 0;
end;
procedure TRMRxRichView.GetMemoVariables;
begin
if DrawMode = rmdmAll then
begin
Memo1.Assign(Memo);
InternalOnBeforePrint(Memo1, Self);
RMRxAssignRich(SRichEdit, FRichEdit);
if not TextOnly then
GetRichData(SRichEdit);
end;
end;
procedure TRMRxRichView.PlaceOnEndPage(aStream: TStream);
var
n: integer;
begin
BeginDraw(Canvas);
if not Visible then Exit;
GetMemoVariables;
if DrawMode = rmdmPart then
begin
FStartCharPos := FEndCharPos;
ShowRichText(False);
n := SRichEdit.GetTextLen - FEndCharPos + 1;
if n > 0 then
begin
SRichEdit.SelStart := FEndCharPos;
SRichEdit.SelLength := n;
SRichEdit.SelText := '';
end;
SRichEdit.SelStart := 0;
SRichEdit.SelLength := FSaveCharPos;
SRichEdit.SelText := '';
FSaveCharPos := FEndCharPos;
end;
aStream.Write(Typ, 1);
RMWriteString(aStream, ClassName);
FUseSRichEdit := True;
try
SaveToStream(aStream);
finally
FUseSRichEdit := False;
end;
end;
function TRMRxRichView.CalcHeight: Integer;
begin
FEndCharPos := 0;
FSaveCharPos := 0;
Result := 0;
if not Visible then
Exit;
CalcGaps;
DrawMode := rmdmAll;
GetMemoVariables;
// DrawMode := rmdmAfterCalcHeight;
FStartCharPos := 0;
CalculatedHeight := RMToMMThousandths(spGapTop * 2 + _CalcVFrameWidth(TopFrame.spWidth, BottomFrame.spWidth), rmutScreenPixels) +
DoCalcHeight;
RestoreCoord;
Result := CalculatedHeight;
end;
function TRMRxRichView.RemainHeight: Integer;
begin
DrawMode := rmdmAll;
GetMemoVariables;
// DrawMode := rmdmAfterCalcHeight;
FStartCharPos := FEndCharPos + 1;
ActualHeight := RMToMMThousandths(spGapTop * 2 + _CalcVFrameWidth(TopFrame.spWidth, BottomFrame.spWidth), rmutScreenPixels) +
DoCalcHeight;
Result := ActualHeight;
end;
procedure TRMRxRichView.LoadFromStream(aStream: TStream);
var
b: Byte;
liSavePos: Integer;
begin
inherited LoadFromStream(aStream);
RMReadWord(aStream);
b := RMReadByte(aStream);
liSavePos := RMReadInt32(aStream);
if b > 0 then
FRichEdit.Lines.LoadFromStream(aStream);
aStream.Seek(liSavePos, soFromBeginning);
end;
procedure TRMRxRichView.SaveToStream(aStream: TStream);
var
b: Byte;
liSavePos, liPos: Integer;
liRichEdit: TJvRichEdit;
begin
inherited SaveToStream(aStream);
RMWriteWord(aStream, 0);
if FUseSRichEdit then
liRichEdit := SRichEdit
else
liRichEdit := FRichEdit;
if liRichEdit.Lines.Count > 0 then b := 1 else b := 0;
RMWriteByte(aStream, b);
liSavePos := aStream.Position;
RMWriteInt32(aStream, liSavePos);
if b > 0 then
liRichEdit.Lines.SaveToStream(aStream);
liPos := aStream.Position;
aStream.Seek(liSavePos, soFromBeginning);
RMWriteInt32(aStream, liPos);
aStream.Seek(liPos, soFromBeginning);
end;
procedure TRMRxRichView.GetBlob;
var
liStream: TMemoryStream;
begin
liStream := TMemoryStream.Create;
try
if not ParentReport.Flag_TableEmpty then
FDataSet.AssignBlobFieldTo(FDataFieldName, liStream);
FRichEdit.Lines.LoadFromStream(liStream);
finally
liStream.Free;
end;
end;
procedure TRMRxRichView.ShowEditor;
var
tmpForm: TRMRxRichForm;
begin
tmpForm := TRMRxRichForm.Create(Application);
try
RMRxAssignRich(tmpForm.Editor, FRichEdit);
if tmpForm.ShowModal = mrOK then
begin
RMDesigner.BeforeChange;
RMRxAssignRich(FRichEdit, tmpForm.Editor);
RMDesigner.AfterChange;
end;
finally
tmpForm.Free;
end;
end;
procedure TRMRxRichView.DefinePopupMenu(Popup: TRMCustomMenuItem);
begin
inherited DefinePopupMenu(Popup);
end;
procedure TRMRxRichView.LoadFromRichEdit(aRichEdit: TJvRichEdit);
begin
RMRxAssignRich(FRichEdit, aRichEdit);
end;
function TRMRxRichView.GetViewCommon: string;
begin
Result := '[Rx Rich]';
end;
procedure TRMRxRichView.ClearContents;
begin
FRichEdit.Clear;
inherited;
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMRxRichForm}
procedure TRMRxRichForm.Localize;
begin
Font.Name := RMLoadStr(SRMDefaultFontName);
Font.Size := StrToInt(RMLoadStr(SRMDefaultFontSize));
Font.Charset := StrToInt(RMLoadStr(SCharset));
// Caption := RMLoadStr(rmRes + 560);
RMSetStrProp(btnFileNew, 'Hint', rmRes + 155);
RMSetStrProp(btnFileOpen, 'Hint', rmRes + 561);
RMSetStrProp(btnFileSave, 'Hint', rmRes + 562);
RMSetStrProp(btnUndo, 'Hint', rmRes + 94);
RMSetStrProp(btnRedo, 'Hint', rmRes + 95);
RMSetStrProp(btnFind, 'Hint', rmRes + 582);
RMSetStrProp(btnFontBold, 'Hint', rmRes + 564);
RMSetStrProp(btnFontItalic, 'Hint', rmRes + 565);
RMSetStrProp(btnFontUnderline, 'Hint', rmRes + 569);
RMSetStrProp(btnAlignLeft, 'Hint', rmRes + 566);
RMSetStrProp(btnAlignCenter, 'Hint', rmRes + 567);
RMSetStrProp(btnAlignRight, 'Hint', rmRes + 568);
RMSetStrProp(btnBullets, 'Hint', rmRes + 570);
RMSetStrProp(btnInsertField, 'Hint', rmRes + 575);
RMSetStrProp(btnCut, 'Hint', rmRes + 91);
RMSetStrProp(btnCopy, 'Hint', rmRes + 92);
RMSetStrProp(btnPaste, 'Hint', rmRes + 93);
RMSetStrProp(btnSuperscript, 'Hint', rmRes + 580);
RMSetStrProp(btnSubscript, 'Hint', rmRes + 581);
ItmCut.Caption := btnCut.Hint;
ItmCopy.Caption := btnCopy.Hint;
ItmPaste.Caption := btnPaste.Hint;
RMSetStrProp(MenuFile, 'Caption', rmRes + 154);
RMSetStrProp(ItemFileNew, 'Caption', rmRes + 155);
RMSetStrProp(ItemFileOpen, 'Caption', rmRes + 156);
RMSetStrProp(ItemFileSaveAs, 'Caption', rmRes + 188);
RMSetStrProp(ItemFilePrint, 'Caption', rmRes + 159);
RMSetStrProp(ItemFileExit, 'Caption', rmRes + 162);
RMSetStrProp(MenuEdit, 'Caption', rmRes + 163);
RMSetStrProp(ItemEditUndo, 'Caption', rmRes + 164);
RMSetStrProp(ItemEditRedo, 'Caption', rmRes + 165);
RMSetStrProp(ItemEditCut, 'Caption', rmRes + 166);
RMSetStrProp(ItemEditCopy, 'Caption', rmRes + 167);
RMSetStrProp(ItemEditPaste, 'Caption', rmRes + 168);
RMSetStrProp(ItemEditPasteSpecial, 'Caption', rmRes + 572);
RMSetStrProp(ItemEditSelectAll, 'Caption', rmRes + 170);
RMSetStrProp(ItemEditFind, 'Caption', rmRes + 582);
RMSetStrProp(ItemEditFindNext, 'Caption', rmRes + 583);
RMSetStrProp(ItemEditReplace, 'Caption', rmRes + 584);
RMSetStrProp(ItemEditObjProps, 'Caption', rmRes + 585);
RMSetStrProp(MenuInsert, 'Caption', rmRes + 586);
RMSetStrProp(ItemInserObject, 'Caption', rmRes + 587);
RMSetStrProp(ItemInsertPicture, 'Caption', rmRes + 588);
RMSetStrProp(ItemInsertField, 'Caption', rmRes + 575);
RMSetStrProp(MenuFormat, 'Caption', rmRes + 589);
RMSetStrProp(ItemFormatFont, 'Caption', rmRes + 576);
RMSetStrProp(ItemFormatParagraph, 'Caption', rmRes + 852);
btnOK.Hint := RMLoadStr(rmRes + 573);
btnCancel.Hint := RMLoadStr(rmRes + 574);
end;
procedure TRMRxRichForm.FocusEditor;
begin
with Editor do
begin
if CanFocus then
SetFocus;
end;
end;
procedure TRMRxRichForm.SelectionChange(Sender: TObject);
var
lFont: TFont;
lFontHeight: Integer;
begin
with Editor.Paragraph do
begin
try
FUpdating := True;
FRuler.UpdateInd;
BtnFontBold.Down := fsBold in CurrText.Style;
BtnFontItalic.Down := fsItalic in CurrText.Style;
BtnFontUnderline.Down := fsUnderline in CurrText.Style;
BtnBullets.Down := Boolean(Numbering);
BtnSuperscript.Down := CurrText.SubscriptStyle = ssSuperscript;
BtnSubscript.Down := CurrText.SubscriptStyle = ssSubscript;
lFont := TFont.Create;
lFont.Size := CurrText.Size;
lFontHeight := lFont.Height;
lFont.Free;
RMSetFontSize(TComboBox(FCmbFontSize), lFontHeight, CurrText.Size);
FCmbFont.FontName := CurrText.Name;
case Ord(Alignment) of
0: BtnAlignLeft.Down := True;
1: BtnAlignRight.Down := True;
2: BtnAlignCenter.Down := True;
end;
UpdateCursorPos;
finally
FUpdating := False;
end;
end;
end;
function TRMRxRichForm.CurrText: TJvTextAttributes;
begin
if Editor.SelLength > 0 then
Result := Editor.SelAttributes
else
Result := Editor.WordAttributes;
end;
procedure TRMRxRichForm.SetFileName(const FileName: string);
begin
FFileName := FileName;
Editor.Title := ExtractFileName(FileName);
end;
procedure TRMRxRichForm.SetEditRect;
var
R: TRect;
Offs: Integer;
begin
with Editor do
begin
if SelectionBar then
Offs := 3
else
Offs := 0;
R := Rect(GutterWid + Offs, 0, ClientWidth - GutterWid, ClientHeight);
SendMessage(Handle, EM_SETRECT, 0, Longint(@R));
end;
end;
{ Event Handlers }
procedure TRMRxRichForm.FormCreate(Sender: TObject);
var
i, liOffset: Integer;
s, s1: string;
begin
Localize;
Editor := TJvRichEdit.Create(Self);
with Editor do
begin
Parent := Self;
Align := alClient;
HideSelection := False;
Editor.PopupMenu := Self.EditPopupMenu;
WantTabs := False;
ScrollBars := ssBoth;
OnTextNotFound := EditorTextNotFound;
OnSelectionChange := SelectionChange;
OnProtectChange := EditorProtectChange;
OnChange := RichEditChange;
end;
FcmbFont := TRMFontComboBox.Create(ToolBar2);
with FcmbFont do
begin
Parent := ToolBar2;
Left := 0;
Top := 0;
Height := 21;
Width := 150;
Tag := 7;
// Device := rmfdPrinter;
OnChange := OnCmbFontChange;
end;
FcmbFontSize := TComboBox.Create(ToolBar2);
with FcmbFontSize do
begin
Parent := ToolBar2;
Left := 150;
Top := 0;
Height := 21;
Width := 59;
Tag := 8;
DropDownCount := 12;
if RMIsChineseGB then
liOffset := 0
else
liOffset := 13;
for i := Low(RMDefaultFontSizeStr) + liOffset to High(RMDefaultFontSizeStr) do
Items.Add(RMDefaultFontSizeStr[i]);
OnChange := OnCmbFontSizeChange;
end;
FBtnFontColor := TRMColorPickerButton.Create(ToolBar2);
with FBtnFontColor do
begin
Parent := ToolBar2;
Left := ToolButton18.Left + ToolButton18.Width;
Top := 0;
ColorType := rmptFont;
OnColorChange := OnColorChangeEvent;
end;
FBtnBackColor := TRMColorPickerButton.Create(ToolBar2);
with FBtnBackColor do
begin
Parent := ToolBar2;
Left := FBtnFontColor.Left + FBtnFontColor.Width;
Top := 0;
ColorType := rmptFill;
OnColorChange := OnColorChangeEvent;
end;
FRuler := TRMRuler.Create(Self);
with FRuler do
begin
Top := ToolBar2.Top + ToolBar2.Height;
RichEdit := TCustomRichEdit(Editor);
Align := alTop;
Height := 26;
OnIndChanged := SelectionChange;
end;
OpenDialog.InitialDir := ExtractFilePath(ParamStr(0));
SaveDialog.InitialDir := OpenDialog.InitialDir;
SetFileName('Untitled');
HandleNeeded;
SelectionChange(Self);
{$IFDEF OPENPICTUREDLG}
Editor.OnCloseFindDialog := EditFindDialogClose;
FOpenPictureDialog := TOpenPictureDialog.Create(Self);
{$ELSE}
FOpenPictureDialog := TOpenDialog.Create(Self);
{$ENDIF}
s := '*.bmp *.ico *.wmf *.emf';
s1 := '*.bmp;*.ico;*.wmf;*.emf';
{$IFDEF JPEG}
s := s + ' *.jpg';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -