
Adding a New viewDef to a Stationery-Based Application
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.
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.
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"
symbolkBookViewerViewDefSym
type'viewer
_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.
An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.
Last modified: 1 DEC 1996