Hi,
I'm having some trouble pasting text from another text editor in a TWPRichText with styles.
Some info about my project first: my WPRichText has ClipboardOptions := [wpcoDontPasteFonts], ProtectedProp := [ppAllExceptForEditFields], and I created two styles with diferent font types, font sizes, linespacing, etc. within a TWPStyleCollection. All the editing is done inside a EditField obviously. I use version 5.43 of WPTools with Delphi 7.
The style is applied to the document using the following code:
wprich.ActiveStyleName := nmStyle;
if wprich.IsSelected then
wprich.SelectedTextAttr.ClearAttr(true, true);
else
wprich.ActiveParagraph.ClearCharAttr(true);
wprich.ReformatAll(false, true);
This works fine. The problem is as follows:
1 - Apply a style to a paragraph (or all the document);
2 - go to the end of the line and hit Enter to create a new line;
3 - paste a text from another editor (or any other source in fact) into the new line;
4 - the new text is pasted without the style. No matter the font type of the original text, it is pasted with Arial font size 11, while my styles uses Garamond and Verdana with sizes 13 and 12;
I know that when a new line is created the style is not applied to this line (same behavior as Microsoft Word), so in the OnKeyPress event I set the style for the new line:
if Ord(Key) = VK_RETURN then
wprich.ActiveParagraph.SetStyle(wprich.ActiveParagraph.PrevPar.Style, false, true);
As far I can tell this works fine too, but do not solve the problem. When a paste a text, it still has Arial font size 11.
Before I start to use styles, the text was pasted using the document's font type (garamond size 13) wich is the behavior I espected from the ClipboardOptions := [wpcoDontPasteFonts]. Why is it pasted with a font other than the one defined in the style now?
Any ideas on how to solve this?
P.S.: Can I set a base style to all the document without looping through the paragraphs (ActivePar.ASetBaseStyle(0)) so I don't need the OnKeyPress code?