Clarification regarding styles needed

General TRichView support forum. Please post your questions here
Post Reply
aoven
Posts: 45
Joined: Wed Nov 09, 2005 7:28 pm

Clarification regarding styles needed

Post by aoven »

I'm finally putting TRichView to some real use and I need to understand a few things about styles.

Basically, my app is a rich text editor, which allows users to create documents with all kinds of goodies (basic formatting, alignment, tables, pictures, etc.). Additionally, users should be able to select certain parts of their documents, tag those parts with an invisible id and make them protected so they can't be modified anymore.

This is all well and done. For this purpose I defined two styles at design-time:
- normal text
- tagged text

When user selects some text, they can right-click it and convert it to tagged text by inserting a string tag with InsertStringWTag and applying the 2nd style.

This works fine with new documents - i.e. the ones that user starts building from scratch.

Problems arise, when user decides to import an existing RTF document. This action messes up the styles that I defined at design-time.

RTFReadProperties.ParaStyleMode and TextStyleMode are both set to rvrsAddIfNeeded, because I want to preserve original RTF formatting as much as possible.

So now I have 2 questions:

1. What should I do to allow for dynamic addition of styles from the loaded RTF document AND preserve my "tagged text" style from design-time?

2. Where can I find out more about the mechanics behind styles? Do I need to define them at all or are they dynamically built when user modifies the document (bold, italic, right align, etc.)?

Aleksander
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

RTF and RVF import tries to reuse existing styles if possible.
When importing RVF files, all properties are taken into account, including protection. When importing RTF, protection property is ignored, and yes, protected styles can appear in the loaded/inserted text.

I can imagine two solutions:
- to forbid reusing protected styles when importing RTF;
- to add an event where you can allow or disallow using some specific existing style for the imported text.

I think, of these two options, the former is better. What do you think?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

For a typical rich text editor based on TRichViewEdit, new styles are created dynamically in OnStyleConversion/OnParaStyleConversion events.
You can either use RichViewActions ( http://www.trichview.com/resources/actions/ ) or implement these events yourself (see Demos\Delphi\Editors\Editor 2\)
Do not forget to set Standard property to False for all styles added in these events.

When creating a new document (File | New), you can reset collections of styles to defaults.
When loading RVF document, it's recommended to call DeleteUnisedStyles (after LoadRVF and before Format). This method deletes all unnecessary non-Standard styles.
Post Reply