Is there a way to intercept content that is being pasted and modify it just before it integrates with the document?
The problem I'm facing is as follows:
User can mark a few text blocks and attach string tags to them. Each block receives a unique tag by which program can identify the block later on. Now, if user were to select one or more tagged blocks and copy&paste them back into document, they'd get multiple blocks with the same tag, which I need to avoid somehow.
What can I do?
Aleksander
Intercepting pasted content
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Intercepting pasted content
I have the same problem. Could you post a sample of how to paste the clipboard contents into a tempory editor?aoven wrote:I managed to solve the problem by creating a temporary TRichView in the OnPaste event and process the pasted RVF before inserting it into the target editor.
Thanks for the tip!
Aleksander
Thanks,
Geurt Lagemaat
Sure, this is how I did it:
Code: Select all
procedure TSourceDocDesigner.rvEditPaste(Sender: TCustomRichViewEdit;
var DoDefault: Boolean);
var
RV: TRichView;
RS: TRVStyle;
MS: TMemoryStream;
hMem: Cardinal;
P: Pointer;
Size: Integer;
begin
if Clipboard.HasFormat(CFRV_RVF) then begin
RV := TRichView.Create(nil);
RS := TRVStyle.Create(nil);
RV.Style := RS;
try
RV.Options := RV.Options + [rvoTagsArePChars];
RV.RTFReadProperties.ParaStyleMode := rvrsAddIfNeeded;
RV.RTFReadProperties.TextStyleMode := rvrsAddIfNeeded;
RV.RTFReadProperties.UnicodeMode := rvruOnlyUnicode;
RV.RVFOptions := RV.RVFOptions + [rvfoSaveTextStyles, rvfoSaveParaStyles];
Clipboard.Open;
MS := TMemoryStream.Create;
try
hMem := Clipboard.GetAsHandle(CFRV_RVF);
Size := GlobalSize(hMem);
MS.SetSize(Size);
P := GlobalLock(hMem);
Move(P^, MS.Memory^, Size);
GlobalUnlock(hMem);
MS.Seek(0, soBeginning);
MS.ReadBuffer(Size, SizeOf(Size));
MS.SetSize(SizeOf(Size) + Size);
MS.Seek(SizeOf(Size), soBeginning);
RV.LoadRVFFromStream(MS);
finally
MS.Free;
Clipboard.Close;
end;
// do something with RVF in temp editor
// insert the modified temp RVF to target editor at caret
MS := TMemoryStream.Create;
try
RV.SaveRVFToStream(MS, False);
MS.Seek(0, soBeginning);
rvEdit.InsertRVFFromStreamEd(MS);
finally
MS.Free;
end;
finally
RV.Style := nil;
RS.Free;
RV.Free;
end;
DoDefault := False;
end;
end;
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: