Initializing the default model or presenter state

You can make minor modifications to the text model and presenter state before launching an editable text document component. You can:

To add initial text to a document, add a text string to the text model prior to launching the model in a document. You can pass the text string to the text model when you construct the model, or use the TTextModel::ReplaceText function to add the text after construction. You can also apply styles to the initial text, using either TText functions to apply the initial styles to the text object before inserting it into the model, or the TTextModel::AddStyles function after the text is in the model. Any styles applied to the initial text are propagated to subsequently entered text.

To control the initial typing styles without putting initial text in the model, call TTextModel::AddStyles with a text area of length zero. This is analagous to the user specifying styles for an insertion point.

To modify the appearance of the default text presentation, apply changes to the text presenter state before launching the document. TTextPresenterState provides the following member functions for modifying the presentation:

For example, the following sample code creates an editable text document component with initial text and modified presentation options:

      TStandardText initialText( "Hello world!" );
      TStyleSet stylesToAdd;
      stylesToAdd.Add( TTextColorStyle::GetYellow() );
      stylesToAdd.Add( TUnderlineStyle( 0, 0, 2, 0 ) );
      initialText.AddStyles( stylesToAdd );
      
      TTextModel* model = new TTextModel( initialText );
      TTextPresenterState* presenterState = new TTextPresenterState;
      
      presenterState->SetTextBackgroundColor( TRGBColor( .9, .9, 1 ) );
      presenterState->SetTextMargins( 8, 8, 12, 12 );
      
      TCompoundDocument theDocument( model, presenterState );
The end user can modify the typing styles or presentation settings at any time by using the appropriate text menu items.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker