Important: The information in this document is obsolete and should not be used for new development.
Editing Text
MacApp provides theTTEView
class, 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 ofTTEView
is 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
TTEView
class, 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
TDialogTEView
class provides a floatingTTEView
that 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
TFloatingTEManager
class supplies aTDialogTEView
object on demand. An instance of theTFloatingTEManager
class is created in theInitUDialog
initialization routine and is referenced bygFloatingTEManager
.TNumberText
- The
TNumberText
control view class can accept and validate numeric data.TTECommand
- This is the base command class for undoable text-editing command classes.
TTECutCopyCommand
- The
TTECutCopyCommand
class supports cut, copy, and clear of text, with undo.TTEDragDropCommand
,TTEDragMoveCommand
These 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
TTEPasteCommand
class supports pasting of text, with undo.TTEStyleCommand
- The
TTEStyleCommand
class supports changing of text style, with undo.TTETypingCommand
- The
TTETypingCommand
class supports typing of text,
with undo.The TDialogTEView Class
MacApp supplies theTDialogTEView
class, a subclass ofTTEView
, to perform text editing inTEditText
andTNumberText
views. When aTEditText
orTNumberText
view is the target view, MacApp superimposes aTDialogTEView
object to do the actual editing. TheTDialogTEView
object is said to "float" over the current text field. When editing is complete, the edit or number text view extracts the edited text from theTDialogTEView
object.The global
gFloatingTEManager
object is responsible for supplying aTDialogTEView
view when one is needed. If possible, it reuses an existingTDialogTEView
object.Editing With TEditText Objects
TheTDialogTEView
class is specialized for editing the text inTEditText
orTNumberText
objects:
You don't normally create
- In its initialization method, the
TDialogTEView
class creates a scroller to control scrolling of text.- The
fEditText
field stores a reference to the edit or number text view that is the current target of editing.- The
InstallEditText
method sets up theTDialogTEView
object 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
fEditText
field to the edit text view
TDialogTEView
objects 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 aTDialogTEView
object to handle editing whenever aTEditText
orTNumberText
view 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
ResignTarget
method 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->SetTarget
to set the new target. TheSetTarget
method
- For edit and number text views, the
BecameTarget
method of theTEditText
class makes the following calls:
this->InstallFloatingTEView(FALSE);
gApplication->SetTarget(fTEView);- The
TEditText
::InstallFloatingTEView
method
- The
InstallEditText
method of theTDialogTEView
object performs a number of tasks to prepare the view for editing and becomes the current target object through the call toSetTarget
.
ResignedTarget
method of theTDialogTEView
object. As a result, the edit text view sets its text to the contents of theTDialogTEView
object and theTDialogTEView
object is removed.