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

📄 rm_rxrichedit.pas

📁 胜天进销存源码,国产优秀的进销存
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  s1 := s1 + ';*.jpg';
{$ENDIF}
{$IFDEF RXGIF}
  s := s + ' *.gif';
  s1 := s1 + ';*.gif';
{$ENDIF}
  FOpenPictureDialog.Filter := RMLoadStr(SPictFile) + ' (' + s + ')|' + s1 + '|' + RMLoadStr(SAllFiles) + '|*.*';

  FClipboardMonitor := TJvClipboardMonitor.Create(Self);
  FClipboardMonitor.OnChange := ClipboardChanged;
  BtnSuperscript.Enabled := RichEditVersion >= 2;
  BtnSubscript.Enabled := RichEditVersion >= 2;
  FBtnBackColor.Enabled := RichEditVersion >= 2;
end;

procedure TRMRxRichForm.PerformFileOpen(const AFileName: string);
begin
  FProtectChanging := True;
  try
    Editor.Lines.LoadFromFile(AFileName);
  finally
    FProtectChanging := False;
  end;
  SetFileName(AFileName);
  Editor.SetFocus;
  Editor.Modified := False;
  SetModified(False);
end;

procedure TRMRxRichForm.FormResize(Sender: TObject);
begin
  SetEditRect;
  SelectionChange(Sender);
end;

procedure TRMRxRichForm.FormPaint(Sender: TObject);
begin
  SetEditRect;
end;

procedure TRMRxRichForm.UpdateCursorPos;
var
  CharPos: TPoint;
begin
  CharPos := Editor.CaretPos;
  StatusBar.Panels[0].Text := Format('行: %3d  列: %3d', [CharPos.Y + 1, CharPos.X + 1]);
  BtnCopy.Enabled := Editor.SelLength > 0;
  ItemEditCopy.Enabled := BtnCopy.Enabled;
  ItmCopy.Enabled := BtnCopy.Enabled;
  BtnCut.Enabled := ItemEditCopy.Enabled;
  ItmCut.Enabled := btnCut.Enabled;
  ItemEditPasteSpecial.Enabled := btnCopy.Enabled;
  ItemEditCut.Enabled := ItemEditCopy.Enabled;
  ItemEditObjProps.Enabled := Editor.SelectionType = [stObject];
end;

procedure TRMRxRichForm.FormShow(Sender: TObject);
begin
  UpdateCursorPos;
  RichEditChange(nil);
  SetModified(FALSE);
  FocusEditor;
  ClipboardChanged(nil);
end;

procedure TRMRxRichForm.RichEditChange(Sender: TObject);
begin
  SetModified(Editor.Modified);
  { Undo }
  BtnUndo.Enabled := Editor.CanUndo;
  ItemEditUndo.Enabled := btnUndo.Enabled;
  ItemEditUndo.Caption := '取消(&U) ' + UndoNames[Editor.UndoName];
  { Redo }
  ItemEditRedo.Enabled := Editor.CanRedo;
  btnRedo.Enabled := ItemEditRedo.Enabled;
  ItemEditRedo.Caption := '重复(&R) ' + UndoNames[Editor.RedoName];
end;

procedure TRMRxRichForm.SetModified(Value: Boolean);
begin
  if Value then
    StatusBar.Panels[1].Text := '修改'
  else
    StatusBar.Panels[1].Text := '';
end;

procedure TRMRxRichForm.ClipboardChanged(Sender: TObject);
var
  E: Boolean;
begin
  E := Editor.CanPaste;
  btnPaste.Enabled := E;
  ItemEditPaste.Enabled := E;
  ItemEditPasteSpecial.Enabled := E;
  ItmPaste.Enabled := E;
end;

procedure TRMRxRichForm.FormDestroy(Sender: TObject);
begin
  FClipboardMonitor.Free;
  FRuler.Free;
end;

procedure TRMRxRichForm.EditorTextNotFound(Sender: TObject;
  const FindText: string);
begin
  MessageDlg(Format('Text "%s" not found.', [FindText]), mtWarning,
    [mbOk], 0);
end;

{$IFDEF OPENPICTUREDLG}

procedure TRMRxRichForm.EditFindDialogClose(Sender: TObject; Dialog: TFindDialog);
begin
  FocusEditor;
end;
{$ENDIF}

procedure TRMRxRichForm.EditorProtectChange(Sender: TObject; StartPos,
  EndPos: Integer; var AllowChange: Boolean);
begin
  AllowChange := FProtectChanging;
end;

procedure TRMRxRichForm.EditSelectAll(Sender: TObject);
begin
  Editor.SelectAll;
end;

procedure TRMRxRichForm.btnFileNewClick(Sender: TObject);
begin
  SetFileName('Untitled');
  FProtectChanging := True;
  try
    Editor.Lines.Clear;
    Editor.Modified := False;
    Editor.ReadOnly := False;
    SetModified(False);
    with Editor do
    begin
      DefAttributes.Assign(Font);
      SelAttributes.Assign(Font);
    end;
    SelectionChange(nil);
  finally
    FProtectChanging := False;
  end;
end;

procedure TRMRxRichForm.btnFileOpenClick(Sender: TObject);
begin
  OpenDialog.Filter := RMLoadStr(SRTFFile) + '(*.rtf)|*.rtf' + '|' +
    RMLoadStr(STextFile) + '(*.txt)|*.txt';
  if OpenDialog.Execute then
  begin
    PerformFileOpen(OpenDialog.FileName);
    Editor.ReadOnly := ofReadOnly in OpenDialog.Options;
  end;
end;

procedure TRMRxRichForm.btnFileSaveClick(Sender: TObject);
begin
  if FFileName = 'Untitled' then
    ItemFileSaveAs.Click
  else
  begin
    Editor.Lines.SaveToFile(FFileName);
    Editor.Modified := False;
    SetModified(False);
    RichEditChange(nil);
  end;
end;

procedure TRMRxRichForm.btnFindClick(Sender: TObject);
begin
  with Editor do
    FindDialog(SelText);
end;

procedure TRMRxRichForm.btnCutClick(Sender: TObject);
begin
  Editor.CutToClipboard;
end;

procedure TRMRxRichForm.btnCopyClick(Sender: TObject);
begin
  Editor.CopyToClipboard;
end;

procedure TRMRxRichForm.btnPasteClick(Sender: TObject);
begin
  Editor.PasteFromClipboard;
end;

procedure TRMRxRichForm.btnUndoApplyAlign(Sender: TObject; Align: TAlign;
  var Apply: Boolean);
begin
  Editor.Undo;
  RichEditChange(nil);
  SelectionChange(nil);
end;

procedure TRMRxRichForm.btnRedoClick(Sender: TObject);
begin
  Editor.Redo;
  RichEditChange(nil);
  SelectionChange(nil);
end;

procedure TRMRxRichForm.btnFontBoldClick(Sender: TObject);
begin
  if FUpdating then
    Exit;
  if btnFontBold.Down then
    CurrText.Style := CurrText.Style + [fsBold]
  else
    CurrText.Style := CurrText.Style - [fsBold];
end;

procedure TRMRxRichForm.btnFontItalicClick(Sender: TObject);
begin
  if FUpdating then
    Exit;
  if btnFontItalic.Down then
    CurrText.Style := CurrText.Style + [fsItalic]
  else
    CurrText.Style := CurrText.Style - [fsItalic];
end;

procedure TRMRxRichForm.btnFontUnderlineClick(Sender: TObject);
begin
  if FUpdating then
    Exit;
  if btnFontUnderline.Down then
    CurrText.Style := CurrText.Style + [fsUnderline]
  else
    CurrText.Style := CurrText.Style - [fsUnderline];
end;

procedure TRMRxRichForm.btnAlignLeftClick(Sender: TObject);
begin
  if FUpdating then
    Exit;
  Editor.Paragraph.Alignment := TParaAlignment(TComponent(Sender).Tag);
end;

procedure TRMRxRichForm.btnBulletsClick(Sender: TObject);
begin
  if FUpdating then
    Exit;
  Editor.Paragraph.Numbering := TJvNumbering(btnBullets.Down);
end;

procedure TRMRxRichForm.ItemFileSaveAsClick(Sender: TObject);
begin
  if SaveDialog.Execute then
  begin
    Editor.Lines.SaveToFile(SaveDialog.FileName);
    SetFileName(SaveDialog.FileName);
    Editor.Modified := False;
    SetModified(False);
    RichEditChange(nil);
  end;
  FocusEditor;
end;

procedure TRMRxRichForm.ItemFilePrintClick(Sender: TObject);
begin
  if PrintDialog.Execute then
    Editor.Print(FFileName);
end;

procedure TRMRxRichForm.ItemFormatFontClick(Sender: TObject);
begin
  FontDialog.Font.Assign(Editor.SelAttributes);
  if FontDialog.Execute then
    CurrText.Assign(FontDialog.Font);
  FocusEditor;
end;

procedure TRMRxRichForm.ItemInserObjectClick(Sender: TObject);
begin
  Editor.InsertObjectDialog;
end;

procedure TRMRxRichForm.ItemInsertPictureClick(Sender: TObject);
var
  Pict: TPicture;
begin
  with FOpenPictureDialog do
  begin
    if Execute then
    begin
      Pict := TPicture.Create;
      try
        Pict.LoadFromFile(FileName);
        Clipboard.Assign(Pict);
        Editor.PasteFromClipboard;
      finally
        Pict.Free;
      end;
    end;
  end;
end;

procedure TRMRxRichForm.btnUndoClick(Sender: TObject);
begin
  Editor.Undo;
  RichEditChange(nil);
  SelectionChange(nil);
end;

procedure TRMRxRichForm.ItemEditPasteSpecialClick(Sender: TObject);
begin
  try
    Editor.PasteSpecialDialog;
  finally
    FocusEditor;
  end;
end;

procedure TRMRxRichForm.ItemEditFindNextClick(Sender: TObject);
begin
  if not Editor.FindNext then
  begin
    Exit;
//    Beep;
  end;

  FocusEditor;
end;

procedure TRMRxRichForm.ItemEditReplaceClick(Sender: TObject);
begin
  with Editor do
    ReplaceDialog(SelText, '');
end;

procedure TRMRxRichForm.ItemEditObjPropsClick(Sender: TObject);
begin
  Editor.ObjectPropertiesDialog;
end;

procedure TRMRxRichForm.btnInsertFieldClick(Sender: TObject);
var
  s: string;
begin
  if RMDesigner <> nil then
  begin
    s := RMDesigner.InsertExpression;
    if s <> '' then
      Editor.SelText := s;
  end;
end;

procedure TRMRxRichForm.btnSuperscriptClick(Sender: TObject);
begin
  if FUpdating then
    Exit;
  if btnSuperscript.Down then
    CurrText.SubscriptStyle := ssSuperscript
  else if btnSubscript.Down then
    CurrText.SubscriptStyle := ssSubscript
  else
    CurrText.SubscriptStyle := ssNone;
end;

procedure TRMRxRichForm.ItemEditSelectAllClick(Sender: TObject);
begin
  Editor.SelectAll;
end;

procedure TRMRxRichForm.OnCmbFontChange(Sender: TObject);
begin
  if FUpdating then
    Exit;
  CurrText.Name := FCmbFont.FontName;
  if RMIsChineseGB then
  begin
    if ByteType(FCmbFont.FontName, 1) = mbSingleByte then
      CurrText.Charset := ANSI_CHARSET
    else
      CurrText.Charset := GB2312_CHARSET;
  end;
end;

procedure TRMRxRichForm.OnCmbFontSizeChange(Sender: TObject);
var
  liFontSize: Integer;
  lFont: TFont;
begin
  if FUpdating then Exit;

  liFontSize := RMGetFontSize(TComboBox(FCmbFontSize));
  if liFontSize > 0 then
    CurrText.Size := liFontSize
  else
  begin
    lFont := TFont.Create;
    lFont.Height := liFontSize;
    liFontSize := lFont.Size;
    CurrText.Size := liFontSize;
    lFont.Free;
  end;
end;

procedure TRMRxRichForm.btnOKClick(Sender: TObject);
begin
  OnResize := nil;
  ModalResult := mrOK;
end;

procedure TRMRxRichForm.btnCancelClick(Sender: TObject);
begin
  OnResize := nil;
  ModalResult := mrCancel;
end;

procedure TRMRxRichForm.OnColorChangeEvent(Sender: TObject);
begin
  if Sender = FBtnFontColor then
    CurrText.Color := FBtnFontColor.CurrentColor
  else
    CurrText.BackColor := FBtnBackColor.CurrentColor;
end;

procedure TRMRxRichForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  OnResize := nil;
end;

procedure TRMRxRichForm.ItemFormatParagraphClick(Sender: TObject);
var
  tmp: TRMParaFormatDlg;
begin
  tmp := TRMParaFormatDlg.Create(nil);
  try
    tmp.SpacingBox.Enabled := (RichEditVersion >= 2);
    tmp.UpDownLeftIndent.Position := Editor.Paragraph.LeftIndent;
    tmp.UpDownRightIndent.Position := Editor.Paragraph.RightIndent;
    tmp.UpDownFirstIndent.Position := Editor.Paragraph.FirstIndent;
    tmp.Alignment.ItemIndex := Ord(Editor.Paragraph.Alignment);
    tmp.UpDownSpaceBefore.Position := Editor.Paragraph.SpaceBefore;
    tmp.UpDownSpaceAfter.Position := Editor.Paragraph.SpaceAfter;
    tmp.UpDownLineSpacing.Position := Editor.Paragraph.LineSpacing;
    if tmp.ShowModal = mrOK then
    begin
      Editor.Paragraph.LeftIndent := tmp.UpDownLeftIndent.Position;
      Editor.Paragraph.RightIndent := tmp.UpDownRightIndent.Position;
      Editor.Paragraph.FirstIndent := tmp.UpDownFirstIndent.Position;
      Editor.Paragraph.Alignment := TParaAlignment(tmp.Alignment.ItemIndex);
      Editor.Paragraph.SpaceBefore := tmp.UpDownSpaceBefore.Position;
      Editor.Paragraph.SpaceAfter := tmp.UpDownSpaceAfter.Position;
      if tmp.UpDownLineSpacing.Position > 0 then
        Editor.Paragraph.LineSpacingRule := lsSpecifiedOrMore
      else
        Editor.Paragraph.LineSpacingRule := lsSingle;
      Editor.Paragraph.LineSpacing := tmp.UpDownLineSpacing.Position;
    end;
  finally
    tmp.Free;
  end;
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}

procedure TRMRxRichView_LoadFromRichEdit(var Value: Variant; Args: TJvInterpreterArgs);
begin
  TRMRxRichView(Args.Obj).LoadFromRichEdit(TJvRichEdit(V2O(Args.Values[0])));
end;


procedure RM_RegisterRAI2Adapter(RAI2Adapter: TJvInterpreterAdapter);
begin
  with RAI2Adapter do
  begin
    AddClass('ReportMachine', TRMRxRichView, 'TRMRxRichView');

    AddGet(TRMRxRichView, 'LoadFromRichEdit', TRMRxRichView_LoadFromRichEdit, 1, [0], varEmpty);
  end;
end;

initialization
  RMRegisterObjectByRes(TRMRxRichView, 'RM_RxRichObject', RMLoadStr(SInsRich2Object), TRMRxRichForm);
  RM_RegisterRAI2Adapter(GlobalJvInterpreterAdapter);

finalization

{$ENDIF}
end.

⌨️ 快捷键说明

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