Creating a simple editable text element

The framework also provides a set of core classes that implement the Text Editing framework abstract classes but do not derive from the Document frameworks, giving you the ability to create simple editable text elements:

This figure shows how these classes work together, along with the associated interactors:


The objects that comprise a simple editable text element work together very much like the objects that comprise an editable text document component, except that the simple text element does not have a presenter or presenter state. Information relevant to the presentation is handled by the view.

You can easily create a lightweight text component by instantiating TSimpleTextStore and TSimpleTextView, and launching the text view in a window. The following code demonstrates how to do this:

      
    TStandardText initialText( "A simple text element" );
      TSimpleTextStore* store = new TSimpleTextStore( initialText );
      
      TSimpleTextView* contentView = new TSimpleTextView( store );
      contentView->SetAllocatedArea( TGRect( TGPoint::GetOrigin(), TGPoint( 300, 300 ) ) );
      
      
    TRequestHandler* rh = new TRequestHandler( new TRequestQueue() );
      TWindowGroup windowGroup( rh->GetRequestQueue() );
      TStandardText windowTitle( "Simple Text View" );
      TStandardWindow* window = new TStandardWindow( windowTitle, TRUE, TRUE, TRUE, TRUE,
          TRUE );
      
      TGPoint windowOrigin = TGPoint( 100, 5 );
      TGPoint windowSize = TGPoint( 400, 300 );
      windowGroup.AdoptContentWindow( window );
      window->SetWindowSize( windowSize );
      window->MoveWindowTo( windowOrigin );
      
      
    windowGroup.Activate();
      window->Open();
      
      while( window->IsOpen() ) {
          rh->WaitAndDispatchNextRequest();
      }
This code produces a text element that can be edited, embedded in other documents, and so on. The behavior for handling simple keyboard input is identical to that provided by the text document component. The simple element does not, however, provide some of the functionality associated with compound documents--for example, endless undo and redo.

You can also add features to simple text elements. For example, you can easily add menus using the TTextMenu class, as described in "Adding text menus" on page 111.


[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