View System and Messages

How Views Are Created

Views proto from a template (or sometimes directly from a proto) and contain an integer viewCObject slot. The viewCObject is a C++ object in the underlying view system. It handles the actual drawing, handwriting recognition, displaying pictures, etc.

When your application is launched, it is sent an Open message. Its views are then sent these three messages in this order:

1. viewSetupFormScript

2. viewSetupChildrenScript

3. viewSetupDoneScript

Before going into the details of each, let us look at what happens on the Newton when your application's views are opened. As you can see in FIGURE 6.1, the first thing that happens is the view system creates an empty view frame (unless it already exists). Next, the viewSetupFormScript is executed and it adds or modifies any necessary slots in the view. After this, the viewCObject is created based on slots read from the view.

The next message that is executed is the viewSetupChildrenScript, which modifies the stepChildren array, if necessary. If the view has any children, the view creation is started again from scratch for the first child view in the stepChildren array (see the second column in FIGURE 6.1). If the child has any children of its own (the grandchildren), they are created after the child's own viewSetupChildrenScript executes.

Once the last child (one with no children of its own) is created, that child's viewSetupDoneScript is executed (see the third column in FIGURE 6.1). The view system winds itself back up the ancestor chain, executing the viewSetupDoneScript of each view until it reaches the application's base view (the first view in the chain). Presto! Your views are now open on the Newton.

FIGURE 6.1 : Opening a view on the Newton.


As you can see, the same three messages are sent to each view in exactly the same order. You will handle particular things in each message. Let's look at each message in turn.

viewSetupFormScript()
viewSetupChildrenScript()
viewSetupDoneScript()
viewShowScript()
How Views Are Destroyed
viewQuitScript()
viewHideScript()

An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996