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

📄 rm_wwrtf.pas

📁 report machine 2.3 功能强大
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    hdcTarget := hdc;
    rcPage := rc;
    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 TRMWWRichView.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 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;
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;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{TRMWWRichForm}

procedure TRMwwRichForm.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);

  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 + 157);
  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);
  ItemEditSelectAll.Caption := RMLoadStr(rmRes + 170);
  ItemEditFind.Caption := RMLoadStr(rmRes + 582);
  ItemEditFindNext.Caption := RMLoadStr(rmRes + 583);
  ItemEditReplace.Caption := RMLoadStr(rmRes + 584);
  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);
  btnSuperscript.Hint := RMLoadStr(rmRes + 580);
  btnSubscript.Hint := RMLoadStr(rmRes + 581);
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;

    OnSelectionChange := SelectionChange;
    OnChange := RichEditChange;
  end;

⌨️ 快捷键说明

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