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

📄 unit1.pas

📁 wptools5 pro 完整源代码 Msword界面的文本编辑器源代码
💻 PAS
字号:
unit Unit1;
// modified for WPTools V5

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, WPRTEDefs, WPCTRMemo, WPCTRRich, Buttons;

type
  TForm1 = class(TForm)
    WPRichText1: TWPRichText;
    InsAnnot: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    ShowAnnotations: TSpeedButton;
    procedure InsAnnotClick(Sender: TObject);
    procedure ShowAnnotationsClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    procedure ShowHideAnnots( show : Boolean );
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

  // This is our Annotation Object
  type
  TWPOAnnotation = class(TWPObject)
  private
    FCaption: string;
  public
    constructor Create(RTFData: TWPRTFDataCollection); override;
    destructor Destroy; override;
    procedure Paint(toCanvas : TCanvas; BoundCanvas : TRect); override;
    procedure Select(yes: Boolean); override;
  published
    property Caption: string read FCaption write FCaption;
  end;


constructor TWPOAnnotation.Create(RTFData: TWPRTFDataCollection);
begin
  inherited Create(RTFData);
end;

destructor TWPOAnnotation.Destroy;
begin
  inherited Destroy;
end;

procedure TWPOAnnotation.Paint;
var x: Integer;
begin
  //! OBSOLETE UpdateBoundCanvas;
  toCanvas.Brush.Color := clWhite;
  toCanvas.Brush.Style := bsSolid;
  toCanvas.Pen.Color := clRed;
  toCanvas.Pen.Width := 2;
  toCanvas.Rectangle(
    BoundCanvas.Left,
    BoundCanvas.Top,
    BoundCanvas.Right,
    BoundCanvas.Bottom);
  x := (BoundCanvas.Left + BoundCanvas.Right) div 2;
  toCanvas.MoveTo(x, BoundCanvas.Top + 2);
  toCanvas.LineTo(x, BoundCanvas.Bottom - 7);
  toCanvas.MoveTo(x, BoundCanvas.Bottom - 5);
  toCanvas.LineTo(x, BoundCanvas.Bottom - 4);
end;

// Instead of selection this object we show an editor
procedure TWPOAnnotation.Select(yes: Boolean);
var s: string;
begin
  if yes then
  begin
    s := Caption;
    if InputQuery('Annotation', 'Text:', s) then
      Caption := s;
  end;
end;

// This procedure hides or shows the annotations
procedure TForm1.ShowHideAnnots( show : Boolean );
var i : Integer;
begin
  // We simply set the width which is stored in the 'reference' to 0
  { OBSOLETE CODE
  for i:=0 to WPRichText1.Memo.TxtObjLst.Count do
  begin
     if WPRichText1.Memo.TxtObjLst.Objects[i] is TWPOAnnotation then
     begin
        if Show then
             WPRichText1.Memo.TxtObjLst.Reference[i]^.w := 200
        else WPRichText1.Memo.TxtObjLst.Reference[i]^.w := 0;
     end;
  end;           }
  // New Code
  for i:=0 to WPRichText1.TextObjects.ObjCount-1 do
    if WPRichText1.TextObjects.ObjList[i].ObjRef is TWPOAnnotation then
    begin
        if Show then
             WPRichText1.TextObjects.ObjList[i].Width := 200
        else WPRichText1.TextObjects.ObjList[i].Width := 0;
     end;

  WPRichText1.ReformatAll;
  // WPRichText1.ShowCursor;
end;

// This is how we insert the annotation
procedure TForm1.InsAnnotClick(Sender: TObject);
var
  obj: TWPOAnnotation;
begin
  obj := TWPOAnnotation.Create(WPRichText1.Memo.RTFData);
  obj.WidthTW := 200;
  obj.HeightTW := 200;
  obj.Caption := edit1.Text;
  // WPRichText1.Modified := True;
  WPRichText1.TextObjects.Insert(obj);
  WPRichText1.SetFocus;
end;

// Toggle the display of the annotation markers
procedure TForm1.ShowAnnotationsClick(Sender: TObject);
begin
  ShowHideAnnots( ShowAnnotations.Down );
end;

initialization

//  WPRegisterClasses([TWPOAnnotation]); // Don't forget!
  if GlobalWPToolsCustomEnviroment <> nil then
  begin
    GlobalWPToolsCustomEnviroment.RegisterWPObject([TWPOAnnotation]);
  end;


end.


⌨️ 快捷键说明

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