Manipulate pasted text
Manipulate pasted text
I want to check and eventually change styles of pasted text. But I can't find a way to find out which part of the text is the just pasted.
-
- Site Admin
- Posts: 17564
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
OnPaste event occurs before pasting.
In this event, you can get data from the Clipboard, process it and insert it yourself.
If you want to modify RTF or RVF, the simplest way is to paste it in a hidden TRichViewEdit, modify it, save to TMemoryStream as RVF, and insert in the main editor using InsertRVFFromStreamEd.
In this event, you can get data from the Clipboard, process it and insert it yourself.
If you want to modify RTF or RVF, the simplest way is to paste it in a hidden TRichViewEdit, modify it, save to TMemoryStream as RVF, and insert in the main editor using InsertRVFFromStreamEd.
-
- Site Admin
- Posts: 17564
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
It's depend on what do you want to do.
If you want, for example, changing a text style for inserted plain text, simply set CurTextStyleNo property in OnPaste and leave DoDefault = True.
More complex manipulation requires parsing of the inserted content, and the simplest way to do it is to loading it in a separate control.
If you want, for example, changing a text style for inserted plain text, simply set CurTextStyleNo property in OnPaste and leave DoDefault = True.
More complex manipulation requires parsing of the inserted content, and the simplest way to do it is to loading it in a separate control.
I want to allow only certain para- and textstyles if somebody pastes - or drops - text from other software as e.g. Word or browser, but not completely plain; bold, italic, underline, strikeout is ok. In my opinion it's one of the most confusing experiences of users if they paste or drop text to their document and get a patchwork of styles as a result. Exactly that i prevent, allowing only bold, italic, ... but keep the basic 'normal' style (font, size ...).
I thougt there might be a trick, something as OnAfterPaste where pastetd text remains selected. So I could do it simply by the usual way via ApplyStyleConversion.
But I will try it out CurTextStyleNo and report my insight.
I thougt there might be a trick, something as OnAfterPaste where pastetd text remains selected. So I could do it simply by the usual way via ApplyStyleConversion.
But I will try it out CurTextStyleNo and report my insight.
-
- Site Admin
- Posts: 17564
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
There are two situations where I have to check the inserted text: pasted and dropped.
In case of paste I did it with a hiden editor and it works simply and fine.
A little more extensive is after dropping. I solved it with a self made Windows message:
It works because fortunately the dropped text is selected after dropping
In each case an event (OnAfterPasted and OnAfterDropped) would make it more comfortable and simple. It would be optimal if these events would return the pasted/dropped range of items/offsets.
In case of paste I did it with a hiden editor and it works simply and fine.
A little more extensive is after dropping. I solved it with a self made Windows message:
Code: Select all
procedure KMAfterOleDrop(var Msg:TMessage); message KM_AfterOleDrop;
...
procedure TfMain.rvOleDrop(Sender: T...);
begin
PostMessage(Handle, KM_AfterOleDrop, 0 , 0);
end;
...
procedure TfMain.KMAfterOleDrop(var Msg: TMessage);
var S: string;
begin
rv.ApplyStyleConversion(NORMALIZE_TEXT);
end;
In each case an event (OnAfterPasted and OnAfterDropped) would make it more comfortable and simple. It would be optimal if these events would return the pasted/dropped range of items/offsets.