Previous Book Contents Book Index Next

Inside Macintosh: Programmer's Guide to MacApp / Part 1 - MacApp Theory and Architecture
Chapter 8 - Displaying, Manipulating, and Printing Data


Editing Text

MacApp provides the TTEView class, a subclass of TView, 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 of TTEView 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:

TDialogTEView
The TDialogTEView class provides a floating TTEView 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 a TDialogTEView object on demand. An instance of the TFloatingTEManager class is created in the InitUDialog initialization routine and is referenced by gFloatingTEManager.
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 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.

The TDialogTEView Class

MacApp supplies the TDialogTEView class, a subclass of TTEView, to perform text editing in TEditText and TNumberText views. When a TEditText or TNumberText view is the target view, MacApp superimposes a TDialogTEView object to do the actual editing. The TDialogTEView 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 the TDialogTEView object.

The global gFloatingTEManager object is responsible for supplying a TDialogTEView view when one is needed. If possible, it reuses an existing TDialogTEView object.

Editing With TEditText Objects

The TDialogTEView class is specialized for editing the text in TEditText or TNumberText objects:

You don't normally create 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 a TDialogTEView object to handle editing whenever a TEditText or TNumberText view becomes the current target. This can happen when

Target management is described in detail in "Target Management," beginning on page 113.

In general, MacApp does the following when a user action or program operation causes a need to change the current target object:

  1. 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.
  2. If the current target object is willing to resign, MacApp then calls gApplication->SetTarget to set the new target. The SetTarget method

    • calls the ResignedTarget method of the current target, allowing that object to make any final adjustments
    • sets the current target to the new target
    • calls the BecameTarget method of the new target so that it can perform any preparations needed to serve as the target object

  3. For edit and number text views, the BecameTarget method of the TEditText class makes the following calls:

    this->InstallFloatingTEView(FALSE);
    gApplication->SetTarget(fTEView);
  4. The TEditText::InstallFloatingTEView method

    • gets a TDialogTEView object from the global gFloatingTEManager object
    • calls the TDialogTEView object's InstallEditText method
    • sets the edit text object's fTEView field to refer to the TDialogTEView object

  5. The InstallEditText method of the TDialogTEView object performs a number of tasks to prepare the view for editing and becomes the current target object through the call to SetTarget.

When a user finishes editing in an edit or number text view, MacApp calls the ResignedTarget method of the TDialogTEView object. As a result, the edit text view sets its text to the contents of the TDialogTEView object and the TDialogTEView object is removed.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
25 JUL 1996