📄 rm_wwrtf.pas.~1~
字号:
rcPage := rc;
FLastChar := FCharFrom;
chrg.cpMin := FLastChar;
chrg.cpMax := -1;
liSaveMapMode := SetMapMode(hdc, MM_TEXT);
re.Perform(EM_FORMATRANGE, 0, 0);
try
FLastChar := re.Perform(EM_FORMATRANGE, Integer(Render), Longint(@lFormatRange));
finally
re.Perform(EM_FORMATRANGE, 0, 0);
SetMapMode(hdc, liSaveMapMode);
end;
end;
re.Perform(EM_FORMATRANGE, 0, 0);
if not Render then
ReleaseDC(0, lFormatRange.hdc)
else if not IsPrinting then
begin
EMFCanvas.Free;
if DocMode <> dmDesigning then
Canvas.StretchDraw(DRect, EMF)
else
begin
BMP := TBitmap.Create;
BMP.Width := DRect.Right - DRect.Left + 1;
BMP.Height := DRect.Bottom - DRect.Top + 1;
BMP.Canvas.StretchDraw(Rect(0, 0, BMP.Width, BMP.Height), EMF);
Canvas.Draw(DRect.Left, DRect.Top, BMP);
BMP.Free;
end;
EMF.Free;
end;
end;
{$WARNINGS ON}
procedure TRMWWRichView.Draw(aCanvas: TCanvas);
begin
BeginDraw(aCanvas);
CalcGaps;
with aCanvas do
begin
ShowBackground;
FCharFrom := 0;
InflateRect(DRect, -gapx, -gapy);
if (dx > 0) and (dy > 0) then
ShowRich(True);
ShowFrame;
end;
RestoreCoord;
end;
procedure TRMWWRichView.StreamOut(Stream: TStream);
var
SaveTag: string;
n: integer;
begin
BeginDraw(Canvas);
Memo1.Assign(Memo);
CurReport.InternalOnEnterRect(Memo1, Self);
RMInterpretator.DoScript(Script);
if not Visible then
Exit;
SaveTag := Tag;
if (Tag <> '') and (Pos('[', Tag) <> 0) then
ExpandVariables(Tag);
AssignRich(SRichEdit, RichEdit);
if (Flags and flTextOnly) = 0 then
GetRichData(SRichEdit);
if DrawMode = drPart then
begin
FCharFrom := FLastChar;
ShowRich(False);
n := SRichEdit.GetTextLen - FLastChar + 1;
if n > 0 then
begin
SRichEdit.SelStart := FLastChar;
SRichEdit.SelLength := n;
SRichEdit.SelText := '';
end;
SRichEdit.SelStart := 0;
SRichEdit.SelLength := FCurChar;
SRichEdit.SelText := '';
FCurChar := FLastChar;
end;
Stream.Write(Typ, 1);
RMWriteString(Stream, ClassName);
FFlag := True;
SaveToStream(Stream);
FFlag := False;
RMInterpretator.DoScript(Script_AfterPrint);
Tag := SaveTag;
end;
function TRMWWRichView.CalcHeight: Integer;
begin
FLastChar := 0;
FCurChar := 0;
Result := 0;
RMInterpretator.DoScript(Script);
if not Visible then
Exit;
Memo1.Assign(Memo);
CurReport.InternalOnEnterRect(Memo1, Self);
AssignRich(SRichEdit, RichEdit);
if (Flags and flTextOnly) = 0 then
GetRichData(SRichEdit);
RMInterpretator.DoScript(Script_AfterPrint);
FCharFrom := 0;
Result := DoCalcHeight + GapY + GapY + _CalcVFrameWidth(TopFrame.Width, BottomFrame.Width);
end;
function TRMWWRichView.MinHeight: Integer;
begin
Result := 8;
end;
function TRMWWRichView.LostSpace: Integer;
var
n, lc, cc: Integer;
begin
AssignRich(SRichEdit, RichEdit);
if (Flags and flTextOnly) = 0 then
GetRichData(SRichEdit);
lc := FLastChar;
cc := FCurChar;
FCharFrom := 0;
SRichEdit.SelStart := 0;
SRichEdit.SelLength := FLastChar;
SRichEdit.SelText := '';
ShowRich(False);
n := SRichEdit.GetTextLen - FLastChar + 1;
if n > 0 then
begin
SRichEdit.SelStart := FLastChar;
SRichEdit.SelLength := n;
SRichEdit.SelText := '';
end;
FCharFrom := 0;
// Result := Round(Abs(dy - DoCalcHeight)) + gapy * 2 + Round(FrameWidth * 2);
Result := 0;
FLastChar := lc;
FCurChar := cc;
end;
function TRMWWRichView.RemainHeight: Integer;
begin
Memo1.Assign(Memo);
CurReport.InternalOnEnterRect(Memo1, Self);
AssignRich(SRichEdit, RichEdit);
if (Flags and flTextOnly) = 0 then
GetRichData(SRichEdit);
FCharFrom := FLastChar;
Result := DoCalcHeight;
end;
procedure TRMWWRichView.LoadFromStream(Stream: TStream);
var
b: Byte;
n: Integer;
begin
inherited LoadFromStream(Stream);
Stream.Read(b, 1);
Stream.Read(n, 4);
if b <> 0 then
RichEdit.Lines.LoadFromStream(Stream);
Stream.Seek(n, soFromBeginning);
end;
procedure TRMWWRichView.SaveToStream(Stream: TStream);
var
b: Byte;
n, o: Integer;
re: TwwDBRichEdit;
begin
LVersion := 0;
inherited SaveToStream(Stream);
re := RichEdit;
if FFlag then
re := SRichEdit;
b := 0;
if re.Lines.Count <> 0 then
b := 1;
Stream.Write(b, 1);
n := Stream.Position;
Stream.Write(n, 4);
if b <> 0 then
re.Lines.SaveToStream(Stream);
o := Stream.Position;
Stream.Seek(n, soFromBeginning);
Stream.Write(o, 4);
Stream.Seek(0, soFromEnd);
end;
procedure TRMWWRichView.GetBlob(b: TField);
var
s: TMemoryStream;
begin
s := TMemoryStream.Create;
if not Flag_TableEmpty then
RMAssignBlobTo(b, s);
RichEdit.Lines.LoadFromStream(s);
s.Free;
end;
procedure TRMWWRichView.ShowEditor;
var
tmpForm: TRMwwRichForm;
begin
tmpForm := TRMwwRichForm.Create(Application);
try
AssignRich(tmpForm.Editor, RichEdit);
tmpForm.Editor.MeasurementUnits := RichEdit.MeasurementUnits;
if tmpForm.ShowModal = mrOK then
begin
RMDesigner.BeforeChange;
AssignRich(RichEdit, tmpForm.Editor);
RMDesigner.AfterChange;
end;
finally
tmpForm.Free;
end;
end;
procedure TRMWWRichView.RichEditor(Sender: TObject);
begin
ShowEditor;
end;
procedure TRMWWRichView.DefinePopupMenu(Popup: TPopupMenu);
var
m: TMenuItem;
begin
inherited DefinePopupMenu(Popup);
m := TMenuItem.Create(Popup);
m.Caption := RMLoadStr(STextOnly);
m.OnClick := P1Click;
m.Checked := (Flags and flTextOnly) <> 0;
Popup.Items.Add(m);
end;
procedure TRMWWRichView.P1Click(Sender: TObject);
var
i: Integer;
t: TRMView;
begin
RMDesigner.BeforeChange;
with Sender as TMenuItem do
begin
Checked := not Checked;
for i := 0 to RMDesigner.Page.Objects.Count - 1 do
begin
t := RMDesigner.Page.Objects[i];
if t.Selected then
t.Flags := (t.Flags and not flTextOnly) + Word(Checked) * flTextOnly;
end;
end;
RMDesigner.AfterChange;
end;
function TRMWWRichView.GetViewCommon;
begin
Result := '[ww Rich]';
end;
procedure TRMWWRichView.LoadFromRichEdit(aRichEdit: TwwDBRichEdit);
begin
AssignRich(RichEdit, aRichEdit);
end;
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMWWRichForm}
procedure TRMwwRichForm.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);
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 + 157);
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(ItemEditSelectAll, 'Caption', rmRes + 170);
RMSetStrProp(ItemEditFind, 'Caption', rmRes + 582);
RMSetStrProp(ItemEditFindNext, 'Caption', rmRes + 583);
RMSetStrProp(ItemEditReplace, 'Caption', rmRes + 584);
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(btnSuperscript, 'Hint', rmRes + 580);
RMSetStrProp(btnSubscript, 'Hint', rmRes + 581);
RMSetStrProp(ItemFormatParagraph, 'Caption', rmRes + 852);
btnOK.Hint := RMLoadStr(rmRes + 573);
btnCancel.Hint := RMLoadStr(rmRes + 574);
end;
procedure TRMwwRichForm.SelectionChange(Sender: TObject);
begin
RefreshControls;
end;
procedure TRMwwRichForm.RefreshControls;
var
haveSelection, haveText: boolean;
begin
try
FUpdating := True;
FRuler.UpdateInd;
btnFontBold.down := fsBold in Editor.SelAttributes.Style;
btnFontUnderline.down := fsUnderline in Editor.SelAttributes.Style;
btnFontItalic.down := fsItalic in Editor.SelAttributes.Style;
BtnSuperscript.Down := RMGetSubscriptStyle(Editor) = rmssSuperscript;
BtnSubscript.Down := RMGetSubscriptStyle(Editor) = rmssSubscript;
FCmbFont.FontName := Editor.SelAttributes.Name;
RMSetFontSize(TComboBox(FCmbFontSize), Editor.SelAttributes.Size);
btnBullets.down := Editor.Paragraph.Numbering = nsBullet;
// btnHighlight.Down:= (Editor.GetTextBackgroundColor <> 0) and
// (Editor.GetTextBackgroundColor <> ColorToRGB(clWindow));
if ord(Editor.Paragraph.Alignment) = PFA_FULLJUSTIFY - 1 then
btnJustify.Down := True
else
begin
case Editor.Paragraph.Alignment of
taLeftJustify: btnAlignLeft.Down := True;
taCenter: btnAlignCenter.Down := True;
taRightJustify: btnAlignRight.Down := True;
end;
end;
ItemEditPaste.Enabled := Editor.CanPaste and (not Editor.readonly);
btnPaste.Enabled := ItemEditPaste.Enabled;
ItmPaste.Enabled := ItemEditPaste.Enabled;
ItemEditUndo.Enabled := Editor.CanUndo;
ItemEditRedo.Enabled := Editor.CanRedo;
btnUndo.Enabled := ItemEditUndo.Enabled;
btnRedo.Enabled := ItemEditRedo.Enabled;
haveSelection := Editor.SelLength > 0; //Editor.CanCut;
haveText := (Editor.Lines.Count > 1) or
(Editor.Lines.Count = 1) and (Editor.Lines[0] <> '');
ItemEditCut.Enabled := haveSelection and (not Editor.readonly);
btnCut.Enabled := ItemEditCut.Enabled;
ItmCut.Enabled := ItemEditCut.Enabled;
ItemEditCopy.Enabled := haveSelection;
btnCopy.Enabled := ItemEditCopy.Enabled;
ItmCopy.Enabled := ItemEditCopy.Enabled;
ItemEditSelectAll.Enabled := haveText;
ItemEditFind.Enabled := haveText;
btnFind.Enabled := ItemEditFind.Enabled;
ItemEditFindNext.Enabled := Editor.CanFindNext;
ItemEditReplace.Enabled := haveText and (not Editor.readOnly);
finally
FUpdating := False;
end;
end;
procedure TRMwwRichForm.FocusEditor;
begin
with Editor do
if CanFocus then
SetFocus;
end;
procedure TRMwwRichForm.SetFileName(const FileName: string);
begin
FFileName := FileName;
Editor.Title := ExtractFileName(FileName);
end;
{ Event Handlers }
procedure TRMwwRichForm.FormCreate(Sender: TObject);
var
i, liOffset: Integer;
s, s1: string;
begin
Localize;
Editor := TwwDBRichEdit.Create(Self);
with Editor do
begin
Parent := Self;
Align := alClient;
HideSelection := False;
PopupMenu := EditPopupMenu;
WantTabs := True;
ScrollBars := ssBoth;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -