Adding a New viewDef to a Stationery-Based Application

Create a Viewer viewDef

Now, let's create our special read-only viewer for our data. A QuickTime movie of this example is available.

1. Create a new project and set the Platform to "Newton 2.0". In the Output Settings panel of the Project Settings dialog, set the project to auto part.


Note:The auto part and the application need to have different application symbols and package names. If you are using demo NTK, you can't change these values to make them different. Therefore, use the starter project (Mac OS/Windows) for your auto part project.


2. Create a new text file containing constants:

constant kBookDataDefSym :=
   '|Book:Bookstore:Calliope|;
constant kBookViewerViewDefSym := 'myViewer;
Save the file as "Constants" and add it to the project.

3. We've already got an editor. Rather than creating our viewer from scratch, let's just modify the editor. Copy the "BookEditorViewDef.t" to the folder containing the project and rename it to "BookViewerViewDef.t". Open it in NTK and add it to your project. Change the name, symbol, and type:

name
"Book Viewer"

symbol
kBookViewerViewDefSym

type
'viewer

4. It is up to you to make sure a viewer viewDef doesn't allow editing. We do that by using read-only versions of newtLabelInputLine, newtLabelDateInputLine, and newtLabelNumInputLine. Edit the _proto slots of the two newtLabelInputLines and change them to newtROLabelInputLine.

Unfortunately, the newtLabelDateInputLine and newtLabelNumInputLine aren't in the _proto popup (that's a deficiency of the "Newton 2.0" platform file--the constant definitions can be found in the "Newton 2.0 Defs" text file). In order to have our template have the correct _proto slot, we'll have to use an afterScript (see "After Scripts" on page 405).

5. Add the following afterScript to the newtLabelDateInputLine to convert it to a newtROLabelDateInputLine:

thisView._proto := newtROLabelDateInputLine;
6. Add the following afterScript to the newtLabelNumInputLines to convert them to newtROLabelNumInputLines:

thisView._proto := newtROLabelNumInputLine;
7. Create a text file to contain your InstallScript and RemoveScript. Add the following:

InstallScript := func(partFrame,removeFrame)
begin
   local dataDefSym :=
      EnsureInternal(kBookDataDefSym);
   RegisterViewDef(
      GetLayout("BookViewerViewDef.t"),
      dataDefSym);
end;

RemoveScript := func(removeFrame)
begin
   UnRegisterViewDef(kBookViewerViewDefSym,
      kBookDataDefSym);
end
Save the text file as "Install and Remove" and add it to the project.

FIGURE 11.20 : The book viewer.


Now build and download the auto part. Open the Bookstore application. Note the Show button now has a diamond, signifying there is a picker associated with it. FIGURE 11.20 shows the viewer in action.


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

Last modified: 1 DEC 1996