⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rm_rxrtf.pas

📁 report machine 2.3 功能强大
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    FLastChar := FCharFrom;
    chrg.cpMin := FLastChar;
    chrg.cpMax := -1;
    mm := SetMapMode(hdc, MM_TEXT);
    FLastChar := re.Perform(EM_FORMATRANGE, Integer(Render), Integer(@Range));
    SetMapMode(hdc, mm);
  end;

  re.Perform(EM_FORMATRANGE, 0, 0);
  if not Render then
    ReleaseDC(0, Range.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 TRMRxRichView.Draw(Canvas: TCanvas);
begin
  BeginDraw(Canvas);
  CalcGaps;
  with Canvas do
  begin
    ShowBackground;
    FCharFrom := 0;
    InflateRect(DRect, -gapx, -gapy);
    if (dx > 0) and (dy > 0) then
      ShowRich(True);
    ShowFrame;
  end;
  RestoreCoord;
end;

procedure TRMRxRichView.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 TRMRxRichView.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;
end;

function TRMRxRichView.MinHeight: Integer;
begin
  Result := 8;
end;

function TRMRxRichView.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 TRMRxRichView.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 TRMRxRichView.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 TRMRxRichView.SaveToStream(Stream: TStream);
var
  b: Byte;
  n, o: Integer;
  re: TRxRichEdit;
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 TRMRxRichView.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 TRMRxRichView.ShowEditor;
var
  tmpForm: TRMRxRichForm;
begin
  tmpForm := TRMRxRichForm.Create(Application);
  try
    AssignRich(tmpForm.Editor, RichEdit);
    if tmpForm.ShowModal = mrOK then
    begin
      RMDesigner.BeforeChange;
      AssignRich(RichEdit, tmpForm.Editor);
      RMDesigner.AfterChange;
    end;
  finally
    tmpForm.Free;
  end;
end;

procedure TRMRxRichView.RichEditor(Sender: TObject);
begin
  ShowEditor;
end;

procedure TRMRxRichView.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 TRMRxRichView.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 TRMRxRichView.GetViewCommon: string;
begin
	Result := '[Rx Rich]';
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMRxRichForm}

procedure TRMRxRichForm.Localize;
begin
	Font.Name := RMLoadStr(SRMDefaultFontName);
  Font.Size := StrToInt(RMLoadStr(SRMDefaultFontSize));
  Font.Charset := StrToInt(RMLoadStr(SCharset));

//  Caption := RMLoadStr(rmRes + 560);
  btnFileNew.Hint := RMLoadStr(rmRes + 155);
  btnFileOpen.Hint := RMLoadStr(rmRes + 561);
  btnFileSave.Hint := RMLoadStr(rmRes + 562);
  btnUndo.Hint := RMLoadStr(rmRes + 94);
  btnRedo.Hint := RMLoadStr(rmRes + 95);
  btnFind.Hint := RMLoadStr(rmRes + 582);
  btnFontBold.Hint := RMLoadStr(rmRes + 564);
  btnFontItalic.Hint := RMLoadStr(rmRes + 565);
  btnFontUnderline.Hint := RMLoadStr(rmRes + 569);
  btnAlignLeft.Hint := RMLoadStr(rmRes + 566);
  btnAlignCenter.Hint := RMLoadStr(rmRes + 567);
  btnAlignRight.Hint := RMLoadStr(rmRes + 568);
  btnBullets.Hint := RMLoadStr(rmRes + 570);
  btnOK.Hint := RMLoadStr(rmRes + 573);
  btnCancel.Hint := RMLoadStr(rmRes + 574);
  btnInsertField.Hint := RMLoadStr(rmRes + 575);
  btnCut.Hint := RMLoadStr(rmRes + 91);
  btnCopy.Hint := RMLoadStr(rmRes + 92);
  btnPaste.Hint := RMLoadStr(rmRes + 93);
  btnSuperscript.Hint := RMLoadStr(rmRes + 580);
  btnSubscript.Hint := RMLoadStr(rmRes + 581);

  ItmCut.Caption := btnCut.Hint;
  ItmCopy.Caption := btnCopy.Hint;
  ItmPaste.Caption := btnPaste.Hint;
  MenuFile.Caption := RMLoadStr(rmRes + 154);
  ItemFileNew.Caption := RMLoadStr(rmRes + 155);
  ItemFileOpen.Caption := RMLoadStr(rmRes + 156);
  ItemFileSaveAs.Caption := RMLoadStr(rmRes + 188);
  ItemFilePrint.Caption := RMLoadStr(rmRes + 159);
	ItemFileExit.Caption := RMLoadStr(rmRes + 162);
	MenuEdit.Caption := RMLoadStr(rmRes + 163);
	ItemEditUndo.Caption := RMLoadStr(rmRes + 164);
  ItemEditRedo.Caption := RMLoadStr(rmRes + 165);
	ItemEditCut.Caption := RMLoadStr(rmRes + 166);
  ItemEditCopy.Caption := RMLoadStr(rmRes + 167);
	ItemEditPaste.Caption := RMLoadStr(rmRes + 168);
  ItemEditPasteSpecial.Caption := RMLoadStr(rmRes + 572);
  ItemEditSelectAll.Caption := RMLoadStr(rmRes + 170);
	ItemEditFind.Caption := RMLoadStr(rmRes + 582);
  ItemEditFindNext.Caption := RMLoadStr(rmRes + 583);
  ItemEditReplace.Caption := RMLoadStr(rmRes + 584);
  ItemEditObjProps.Caption := RMLoadStr(rmRes + 585);
  MenuInsert.Caption := RMLoadStr(rmRes + 586);
  ItemInserObject.Caption := RMLoadStr(rmRes + 587);
  ItemInsertPicture.Caption := RMLoadStr(rmRes + 588);
  ItemInsertField.Caption := RMLoadStr(rmRes + 575);
  MenuFormat.Caption := RMLoadStr(rmRes + 589);
  ItemFormatFont.Caption := RMLoadStr(rmRes + 576);
end;

procedure TRMRxRichForm.FocusEditor;
begin
  with Editor do if CanFocus then SetFocus;
end;

procedure TRMRxRichForm.SelectionChange(Sender: TObject);
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;
      RMSetFontSize(TComboBox(FCmbFontSize), 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: TRxTextAttributes;
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 := TRxRichEdit.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;
    UseFonts := TRUE;
//    Device := rmfdPrinter;
    OnChange := OnCmbFontChange;
  end;
  FcmbFontSize := TRMComboBox.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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -