Document parts in TSRichViewEdit

Overview

<< Click to display table of contents >>

Document parts in TSRichViewEdit

Overview

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 headers;

RVFooter for page footers;

RVNote for notes and text box items.

RichViewEdit stores the main document. Other editors are used to edit documents stored in different places:

RVHeader and RVFooter edit Subdocuments

RVNote edits Document of footnotes, endnotes, sidenotes, text boxes.

RichViewEdit always contain the main document. Other editors contain valid documents only when they are active (equal to ActiveEditor).

Loading

When you load a new document, call TSRichViewEdit.Format.

This method copies page properties from TSRichViewEdit.RichViewEdit.DocParameters to TSRichViewEdit.PageProperty (when loading files, page properties are loaded in RichViewEdit.DocParameters), formats RVHeader, RVFooter, RichViewEdit, notes and text boxes, paginates the document.

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;

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;

ChangeStyleTemplates must not be called for ActiveEditor. It must not be called if ActiveEditor=RVNote.

Operations applied to the whole document (such as saving or loading) must be called for the main editor:

SRichViewEdit1.RichViewEdit.SaveRTF(...);

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