Examples
Custom slot protos have two responsibilities:
Retarget
message, the custom proto should read the appropriate slot from the inherited target
variable.
target
frame and then send itself the StartFlush
message. That will cause the newtEntryView to start a watchdog timer. When the timer expires, it will write the target back to the soup.
A QuickTime movie of this example is available.
1. Create a user proto and draw a protoSlider. Add a Retarget
slot with the following contents:
func() begin if target and path and target.(path) then SetValue(self, 'viewValue, target.(path)); endThe code checks to make sure that there is indeed a current target, that the
path
slot is set, and that the slot referenced by path
exists in the target. If so, it reads the value from target
, and then sets the viewValue
of the protoSlider to that value.
2. When the view is instantiated, it needs to also read from target
. Modify the viewSetupFormScript
to:
func() begin :Retarget(); end3. When the slider changes, it needs to update
target
. Modify the ChangedSlider
method to:
func() begin if target and path then begin target.(path) := viewValue; :StartFlush(); end; end4. Now, remove the
viewBounds
slot of the protoSlider (as is normally done with user protos).5. Name the proto "mySlider" and add it to the project.
At this point we can use our new proto in the Bookstore project. We could either draw out a template that is based on mySlider, or we could simply change one of the existing slot protos so that it protos from mySlider.
6. Change the _proto
slot of the newtLabelNumInputLine that handles the number of books in stock to use mySlider as its proto.
7. Add minValue
and maxValue
slots to the mySlider template, so that the slider will have some reasonable minimum and maximum values.
An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.
Last modified: 1 DEC 1996