trichview.com

trichview.support




Re: Indenting on the fly


Return to index


Author

Message

David Kroll

Posted: 10/15/2003 21:43:31


Sergey,


I got it to work, almost.  The first two blank lines are style 1, the

original message is style 0.  After loading the rtf, I call editor.Format,

then set the LeftIndent of Style 0 to 25 and call editor.Format.  This works

well, but I have one problem.  If the rtf had areas that were indented,

those areas are put back to 25.  For instance, if I reply to a message that

had been replied to, I should have something like:



        -- Original Message --

        From:

        Subject:


        Body of replied to message.


                -- Original Message --

                From:

                Subject:


                Body of Original message.



Any suggestions?


  rtfStream := TStringStream.Create(oMessage.Text);

  try

    editor.Clear;

    if MessageType in [mtReply, mtForward] then

    begin

      //This is the top of the message

      editor.AddNL('', 0, 1);

      editor.AddNL('', 0, 1);


      //This is the original message and will be indented

      editor.AddNL('---- Original Message ----', 0, 0);

      editor.AddNL('From: ' + oMessage.SenderAddress, 0, 0);

      editor.AddNL('Sent: ' + DateTimeToStr(oMessage.Timestamp), 0, 0);

      editor.AddNL('To: ' + GetRecipientString(oMessage), 0, 0);

      editor.AddNL('Subejct: ' + oMessage.Subject, 0, 0);

      editor.AddNL('', 0, 0);

    end;

    editor.LoadRTFFromStream(rtfStream);

    editor.Format;


    //This indents the original message portion

    if MessageType in [mtReply, mtForward] then

    begin

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

      editor.Format;

    end;

  finally

    rtfStream.Free;

  end;


"Sergey Tkachenko" <[email protected]> wrote in message

news:[email protected]...

> 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