Important: The information in this document is obsolete and should not be used for new development.
Editing Text
MacApp provides theTTEViewclass, a subclass ofTView,to supply text-editing capability. Objects of this class represent TextEdit records, as described in Inside Macintosh: Text. TextEdit is a simple text-editing facility built into the operating system. The purpose ofTTEViewis to make TextEdit function properly in a MacApp application, for tasks such as scrolling, printing, displaying page breaks, and handling commands.In addition to the
TTEViewclass, MacApp's text-editing support includes the following classes:
The DemoDialogs sample application demonstrates text editing in various kinds of dialog boxes, with drag and drop implemented in some of the samples. The DemoText sample application implements a document that supports text editing, including drag and drop and support for PowerTalk mailers. For information on using a text-editing view in your application, see "Recipe--Using a Document Class With a Text-Editing View," beginning on page 434.
TDialogTEView- The
TDialogTEViewclass provides a floatingTTEViewthat is placed over edit and number text fields to support text editing.TEditText- This control view class supports entering and modifying text data.
TFloatingTEManager- The
TFloatingTEManagerclass supplies aTDialogTEViewobject on demand. An instance of theTFloatingTEManagerclass is created in theInitUDialoginitialization routine and is referenced bygFloatingTEManager.TNumberText- The
TNumberTextcontrol view class can accept and validate numeric data.TTECommand- This is the base command class for undoable text-editing command classes.
TTECutCopyCommand- The
TTECutCopyCommandclass supports cut, copy, and clear of text, with undo.TTEDragDropCommand,TTEDragMoveCommandThese command classes support dragging text into, out of, and within a view, with undo. MacApp's support for drag and drop is described in Chapter 9, "Drag and Drop."TTEPasteCommand- The
TTEPasteCommandclass supports pasting of text, with undo.TTEStyleCommand- The
TTEStyleCommandclass supports changing of text style, with undo.TTETypingCommand- The
TTETypingCommandclass supports typing of text,
with undo.The TDialogTEView Class
MacApp supplies theTDialogTEViewclass, a subclass ofTTEView, to perform text editing inTEditTextandTNumberTextviews. When aTEditTextorTNumberTextview is the target view, MacApp superimposes aTDialogTEViewobject to do the actual editing. TheTDialogTEViewobject is said to "float" over the current text field. When editing is complete, the edit or number text view extracts the edited text from theTDialogTEViewobject.The global
gFloatingTEManagerobject is responsible for supplying aTDialogTEViewview when one is needed. If possible, it reuses an existingTDialogTEViewobject.Editing With TEditText Objects
TheTDialogTEViewclass is specialized for editing the text inTEditTextorTNumberTextobjects:
You don't normally create
- In its initialization method, the
TDialogTEViewclass creates a scroller to control scrolling of text.- The
fEditTextfield stores a reference to the edit or number text view that is the current target of editing.- The
InstallEditTextmethod sets up theTDialogTEViewobject to work with the current edit text view, including
- resizing itself to fit the edit text view
- setting its text and text style from the edit text view
- installing its scroller as a superview of the edit text view
- setting its
fEditTextfield to the edit text view
TDialogTEViewobjects yourself--MacApp creates them as needed, as described in the next section.Installing a TDialogTEView Object for the Current View
As part of its target management function, MacApp installs aTDialogTEViewobject to handle editing whenever aTEditTextorTNumberTextview becomes the current target. This can happen when
Target management is described in detail in "Target Management," beginning on page 113.
- the edit text view is the default target in an activated window
- a user clicks in the edit text view with the mouse
- a user tabs into the edit text field
In general, MacApp does the following when a user action or program operation causes a need to change the current target object:
When a user finishes editing in an edit or number text view, MacApp calls the
- MacApp calls the
ResignTargetmethod of the current target object to see if that object is willing to resign as the target. If its contents are invalid, the target object can refuse to resign and can inform the user about the invalid data and how to correct the problem.- If the current target object is willing to resign, MacApp then calls
gApplication->SetTargetto set the new target. TheSetTargetmethod
- For edit and number text views, the
BecameTargetmethod of theTEditTextclass makes the following calls:
this->InstallFloatingTEView(FALSE);
gApplication->SetTarget(fTEView);- The
TEditText::InstallFloatingTEViewmethod
- The
InstallEditTextmethod of theTDialogTEViewobject performs a number of tasks to prepare the view for editing and becomes the current target object through the call toSetTarget.
ResignedTargetmethod of theTDialogTEViewobject. As a result, the edit text view sets its text to the contents of theTDialogTEViewobject and theTDialogTEViewobject is removed.