Customizing Filters with Labelled Input Lines
One of the Newton 2.x OS Q&As
Copyright © 1997 Newton, Inc. All Rights Reserved. Newton, Newton Technology, Newton Works, the Newton, Inc. logo, the Newton Technology logo, the Light Bulb logo and MessagePad are trademarks of Newton, Inc. and may be registered in the U.S.A. and other countries. Windows is a registered trademark of Microsoft Corp. All other trademarks and company names are the intellectual property of their respective owners.
For the most recent version of the Q&As on the World Wide Web, check the URL:
http://www.newton-inc.com/dev/techinfo/qa/qa.htm
If you've copied this file locally,
click here to go to the main Newton Q&A page.
This document was exported on 7/23/97.
Customizing Filters with Labelled Input Lines (9/4/96)
- Q: I need to open a slot view on a slot that isn't a standard data type (int, string, etc). How do I translate the data from the soup format to and from a string?
A: Here is some interim documentation on the filter objects that newtLabelInputLines
(and their variants) use to accomplish their work.
A filter is an object, specified in the 'flavor
slot of the newtLabelInputLine
set of protos, which acts as a translator between the target data frame (or more typically a slot in that frame) and the text field which is visible to the user. For example, it's the filter for newtDateInputLines
which translates the time-in-minutes value to a string for display, and translates the string into a time-in-minutes for the target data.
You can create your own custom filters by protoing to newtFilter
or one of the other specialized filters described in Chapter 4 of the Newton Programmer's Guide.
When a newtLabelInputLine
is opened, a new filter object is instantiated from the template found in the 'flavor
slot for that input line. The instantiated filter can then be found in the filter
slot of the view itself. The _parent
slot of the instantiated filter will be set to the input line itself, which allows methods in the filter to get data from the current environment.
Here are the slots which are of interest. The first four are simply values that you specify which give you control over the recognition settings of the inputLine
part of the field, and the rest are methods which you can override or call as appropriate.
Settings:
recFlags
Works like entryFlags in protoLableInputLine
. This provides the 'viewFlags
settings for the inputLine
part of the proto -- the field the user interacts with.
recTextFlags
Provides the 'textFlags
settings for the inputLine
part of the proto.
recConfig
Provides the 'recConfig
settings for the inputLine
part of the proto.
dictionaries
Like the 'dictionaries
slot used in recognition, Provides custom dictionaries if vCustomDictionaries
is on in the recFlags
slot.
Methods:
PathToText()
Called when the inputLine
needs to be updated. The function should read data out of the appropriate slot in the 'target
data frame (usually specified in the 'path
slot) and return a user-visible string form of that data. For example, for numbers the function might look like func() NumberStr(target.(path))
TextToPath(str)
Called when the inputLine
value changes. The result will be written into the appropriate slot in the 'target
data frame. The string argument is the one the user has modified from the inputLine
part of the proto. For example, for numbers the function might look like func(str) if StrFilled(str) then StringToNumber(str)
Picker()
An optional function. If present, this method is called when the user taps on the label part of the item. It should create and display an appropriate picker for the data type. For the pre-defined filters, you may also wish to call this method to open the picker. You should store a reference to the filter in the picker view. Then if the user picks an item, send the filter instance a PickActionScript
message. If the picker is cancelled, send a PickCancelledScript
message.
Note: If this method is defined, a pick separator line and the text "Other..." will be added to the labelCommands
array.
PickActionScript( newValue )
An optional function. This method should be called when the user selects something from the picker opened through the filter's Picker
method. If you override this method be sure to call the inherited PickActionScript
method.
PickCancelledScript()
An optional function. This method should be called when the user cancels the picker opened through the filter's Picker
method. If you override this method be sure to call the inherited PickCancelledScript
method.
InitFilter()
Optional. This method is called when an inputLine
that uses this filter is first opened. This method can be used to get data from the current environment (for example, the 'path
slot of the inputLine
) and adjust other settings as appropriate.