BeforePasteText Event

Applies to
TWPRichText

Declaration
TWPOnBeforePaste = Procedure(Sender: TObject; RTFData: TWPRTFDataCollection; par: TParagraph; Stream: TStream; Reader: TWPCustomTextReader; OnlyBodyText: Boolean; var LoadedText: TWPRTFDataBlock) of object;

Description
This event is executed after text was loaded from the clipboad and before it is inserted at the cursor position. This event makes it possible to modify the text before it is inserted!
This Example changes the attributes of the inserted text to 'Courier, 10.5, blue':
procedure TForm1.WPRichText1BeforePasteText(Sender: TObject;
  RTFData: TWPRTFDataCollection; par: TParagraph; Stream: TStream;
  Reader: TWPCustomTextReader; OnlyBodyText: Boolean;
  var LoadedText: TWPRTFDataBlock);
var i : Integer;
    CharAttrIndex : Cardinal;
begin
  // This is an example to change the format
  // of all inserted text to a given font and size

  // 'AttrHelper' is our working horse to create the attribute
  RTFData.RTFProps.AttrHelper.Clear;
  RTFData.RTFProps.AttrHelper.SetFontName('Courier New');
  RTFData.RTFProps.AttrHelper.SetFontSize(10.5);
  RTFData.RTFProps.AttrHelper.SetColor(clBlue);
  CharAttrIndex := RTFData.RTFProps.AttrHelper.CharAttr;

  // At this point we can calculate another CharAttrIndex

  while par<>nil do
  begin
     for i:=0 to par.CharCount-1 do
     begin
        par.CharAttr[i] := CharAttrIndex;
     end;
     par := par.next;
  end;
end;

Category
Clipboard


Copyright (C) by WPCUBED GmbH - Munich
http://www.wpcubed.com