C H A P T E R 8
Text and Ink Input and Display
8-38
Using Text
a view descended from
protoInputLine
with the
vApplication
flag set in
the
viewFlags
slot
The Caret Pop-up Menu
8
Normally, when the user taps the insertion caret, the system-provided Punctuation
pop-up Menu opens. However, you can override this with a pop-up menu of your
own creation.
When the user taps the insertion caret, the system starts searching for a slot named
_caretPopup
. The search begins in the view owning the caret, and follows both
the proto and parent inheritance paths. The default Punctuation pop-up is stored in
the root view.
The
_caretPopup
slot must hold a frame containing two slots. The first slot,
pop
, defines a list of pop-up items suitable for passing to
DoPopup
. The second
slot must contain a
pickActionScript
. If not, control passes to the punctuation
pop-up, which has its own version of the
pickActionScript
. This routine then
inserts a string, corresponding to the selected character at the caret, by using the
function
PostKeyString
.
Handling Input Events
8
You sometimes need to respond to input events that occur in text views. This
section describes how to test for a selection hit and respond to keystrokes and
insertion events.
Testing for a Selection Hit
8
After the user taps the screen, you can determine if the point "hits" a specific
character or word in a paragraph view.
The
view:PointToCharOffset
method returns the offset within the paragraph
that is closest to the point (x, y). This method is described in "PointToCharOffset"
(page 7-51) in Newton Programmer's Reference.
The
view:PointToWord
method returns a frame that indicates the position of
the word within the paragraph that is closest to the point (x, y). This method is
described in "PointToWord" (page 7-52) in Newton Programmer's Reference.
Note
Both of these functions return
nil
if the view is not a paragraph
view. Also, the point you are testing must correspond to a visible
position within the paragraph view; you cannot hit-test on
off-screen portions of a view.