trichview.com

trichview.support




Re: Indenting on the fly


Return to index


Author

Message

Sergey Tkachenko

Posted: 10/15/2003 19:31:12


TRVStyle component (linked to this editor) contains collections of text

styles (defining text fonts, colors, etc.) and paragraph styles (defining

paragraph alignments, indents, etc.). They are available as properties

TextStyles and ParaStyles.

You can edit these collections at run time or at design time.

For example, you can define two text styles (for normal text and for bold

text) and use their indices as the second parameter of AddNL.

(NOTE: the second patameter of AddNL is an index in editor.Style.TextStyles;

editor.Style.ItemNo must not be used here, it is a completely different

value).

Besides, you can define a paragraph style with the proper LeftIndent and use

its index as the third parameter of AddNL.


The main problem is identing text loaded from rtfStream.

I can suggest the following solution:

1) Make sure that "Allow adding styles dynamically" is set in the component

editor for this TRichViewEdit (in Delphi, right click this TRichViewEdit,

choose "Settings" in the context menu).

2) Make sure that TRVStyle component linked to this TRichViewEdit (as

editor.Style) is not linked to any other TRichViewEdit

3) Store the number of paragraph styles before the RTF loading in a

variable:

   ParaStyleCount := editor.Style.ParaStyles.Count;

4) LoadRTFFromStream will add paragraph styles in

editor.Style.ParaStyles.Count. After loading, increase left indent of these

styles:

  for i := ParaStyleCount to editor.Style.ParaStyles.Count-1 do

    editor.Style.ParaStyles[i].LeftIndent :=

editor.Style.ParaStyles[i].LeftIndent+30;


That's all. Well, almost all. There may be a problem: LoadRTFFromStream may

reuse some existing paragraph styles that is already in the collection

instead of adding new styles (if some paragraph in RTF has the same

attributes as existing paragraph styles).

You can use a trick to avoid this:

- after the step 3, temporary assign to existing paragraph styles some

properties that cannot be in RTF. For example, set LeftIndent to -1000:

  for i := 0 to ParaStyleCount-1 do

    editor.Style.ParaStyles[i].LeftIndent := -1000;

- after the step 4, restore their left indents:

  for i := 0 to ParaStyleCount-1 do

    editor.Style.ParaStyles[i].LeftIndent := 0;



> I am loading a TRichViewEdit and want to indent some text on the fly.

This

> is for replying to a mail message, so the original message will be

indented.

> I'm not sure how to do this.  Please see the code below.





Powered by ABC Amber Outlook Express Converter