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(); }
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.