Document parts in TSRichViewEdit

Overview

Top  Previous  Next

Editors

TSRichViewEdit control contains several TRichViewEdit controls inside. These controls are invisible, they are used to render end edit different document parts. These controls are available as properties of TSRichViewEdit:

RichViewEdit for the main document;

RVHeader for page header;

RVFooter for page footer;

RVNote for footnotes and endnotes.

Loading

When you load a new document, the main document, header and footer are visible. So you need to format RVHeader, RVFooter, and RichViewEdit.

Margins and page size are loaded in TSRichViewEdit.RichViewEdit.DocParameters, so in addition to formatting, you need to assign them from DocParameters to the corresponding properties of TSRichViewEdit.

Example of loading RTF file:

SRichViewEdit1.Clear;

SRichViewEdit1.RichViewEdit.LoadRTF(FileName);

SRichViewEdit1.Format;

The same sequence must be called for other loading methods of TSRichViewEdit.RichViewEdit: LoadRTFFromStream, LoadRVF, LoadRVFFromStream, LoadText, etc.

For RVF, you can use the methods of TSRichViewEdit: LoadRVF and LoadRVFFromStream. These methods load, format and assign all necessary data themselves.

If you do not want to display a header and a footer, assign:

SRichViewEdit1.PageProperty.HeaderVisible := False;

SRichViewEdit1.PageProperty.FooterVisible := False;

If a header and a footer are invisible, it is not necessary to format RVHeader and RVFooter after loading.

Loading with RichViewActions

RichViewActions format TSRichViewEdit themselves after loading. However, they do not assign margins and page size from TSRichViewEdit.RichViewEdit.DocParameters to properties of TSRichViewEdit.

Use the event RVAControlPanel1MarginsChanged to call SelRVMargins:

procedure TForm3.RVAControlPanel1MarginsChanged(Sender: TrvAction;

  Edit: TCustomRichViewEdit);

begin

  SRichViewEdit1.RichViewEdit.RVData.State :=

    SRichViewEdit1.RichViewEdit.RVData.State + [rvstSkipFormatting];

  SRichViewEdit1.SetRVMargins;

  ...

  SRichViewEdit1.RichViewEdit.RVData.State :=

     SRichViewEdit1.RichViewEdit.RVData.State - [rvstSkipFormatting];

end;

Switching between document parts

The active TRichViewEdit control (the control corresponding to the document part containing the caret) is returned in the TSRichViewEdit.ActiveEditor property.

To activate editing of the main document, a header, or a footer, call StartEditing.

To activate editing of a footnote or an endnote, call StartEditNote.

The user can activate editing of the page header/footer by double clicking.

If you use RichViewActions, you can use the following actions to switch between document parts:

a_header TsrvActionEditHeader starts editing a page header;

a_footer TsrvActionEditFooter starts editing a page footer;

a_cross TsrvActionEditMain to return to the main document.

Then ActiveEditor is changed, OnChangeActiveEditor event occurs.

Editing

All editing operations must be applied to ActiveEditor, for example:

SRichViewEdit1.ActiveEditor.Undo;

In the events of TSRichViewEdit (such as OnStyleConversion, OnParaStyleConversion, OnCurTextStyleChanged, OnCurParaStyleChanged) you can distinguish the TRichViewEdit control using the Sender parameter.

Editing with RichViewActions

To help the actions to chose the proper TRichViewEdit inside TSRichViewEdit, call (one time, for example in the initialization section):

  RVA_GetRichViewEditFromPopupComponent :=

   SRVGetRichViewEditFromPopupComponent;

  RVA_GetRichViewEdit := SRVGetRichViewEdit


ScaleRichView © Ilya Zelensky & Sergey Tkachenko