You are on page 1of 1

CHAPTER 2: Text Story text 55

To copy text within the same story, source and destination references should be the same. When
specifying ranges for this operation, take care they do not overlap.

Before performing the modification, check the model to ensure it is not locked
(ITextModel::IsModelLocked).

Moving text within and between stories


You can programmatically move text within or across text stories.

Solution

To move text within and between stories, use the command provided by the
ITextUtils::QueryMoveStoryCommand utility facade. Variants of this API allow common use cases of text
move to be handled; for example, moving a range from source to a range in the destination and moving
the complete source story to the end of the destination story.

To move text within the same story, source and destination references should be the same. When
specifying ranges for this operation, take care they do not overlap.

Before performing the modification, check the model to ensure it is not locked
(ITextModel::IsModelLocked).

Sample code

SnpManipulateTextFootnotes::ConvertSelectionToFootnote shows how to move the contents of one story


thread to another, which would be the case if you want to move text cell contents or footnotes.

Iterating across text story threads in a story


Given a story comprises one or more text story threads, each of which represents a discrete
subcomponent (like table cell text or a footnote), you may need to iterate or otherwise discover text story
threads within a story.

Solution

To be able to deal with distinct text units like table cell contents or footnotes, a hierarchy is built on top of
the simple linear model maintained by the various strands. The nodes of this hierarchy are represented by
text story thread dictionaries (ITextStoryThreadDict, maintained on boss classes representing the
subcomponent, such as kFootnoteReferenceBoss). The root of the hierarchy is the primary story thread.
(All stories have a primary story thread; see ITextModel::GetPrimaryStoryThreadSpan.). Story thread
dictionaries maintain a mapping to a set of text story threads (ITextStoryThread). For example, the story
thread dictionary for a table is on the table model (kTableModelBoss). It maintains the mapping to the
actual text story threads for each cell (kTextCellContentBoss). The dictionary provides the mechanism
required to iterate through all text story threads it manages.

The story (kTextModelBoss) models the inherent hierarchy using ITextStoryThreadDictHier. Using
ITextStoryThreadDictHier::NextUID, you can access all story threads in the order in which they appear
within the story.

You might also like