Next | Prev | Up | Top | Contents | Index

Text Verify Callbacks

These text widgets allow the application to do special processing of entered data. After text has been typed or pasted in, initial processing by the text widget determines what the user has entered. This text is then passed to special callback functions, which can make copies of the text, alter it, or choose not to display it. Simple uses for this are text formatting widgets, and password entry widgets that read data but neither display it nor echo "*" for each character typed.

The callback mechanism for this is basically the same as for other callbacks, and similar sorts of substitutions are allowed. For example, the term currInsert is replaced by the current insert position. Other substitutions do not produce a value, but rather give the name of a Tcl variable, allowing the application to alter its value. For example, this callback substitution turns off the echoing of characters:

.text modifyVerifyCallback { set %doit false }
An alternate style is to call a separate procedure to handle the work. The Tcl variable is in the context of the calling routine, so the Tcl upvar function is needed:

.text modifyVerifyCallback {no_echo %doit}
proc no_echo {doit} {
    upvar 1 $doit do_insert
    set do_insert false
}
Actually, the Tcl variable here is the global variable _Tm_Text_Doit. Variables beginning with _Tm_ are reserved for use by the Tm library.

The supported callbacks are listed in Table 4-23:

Text Verify Callbacks
Method Name Why
helpCallback The help key is pressed.
destroyCallback The widget is destroyed.
activateCallback Some event triggered the Activate action.
gainPrimaryCallback Ownership of the primary selection is gained.
losePrimaryCallback Ownership of the primary selection is lost.
losingFocusCallback Before losing input focus.
modifyVerifyCallback Before deletion or insertion.
motionVerifyCallback Before moving the insertion point.
valueChangedCallback Some text was deleted or inserted.

The following callbacks substitutions are defined for the text-specific callbacks:

%doit

In a verify callback, the flag variable to determine whether an action should be executed or not.

%currInsert, %newInsert


In a motionVerifyCallback, the insertion point before and after a motion.

%startPos, %endPos


Define a substring in the widget's text string.

%ptr, %length

Define the string that is to be modified in a modifyVerify callback. For instance, the following example changes input to uppercase:

proc allcaps {ptr length} {

upvar 1 $ptr p

upvar 1 $length l

if {$l == 0} return

set upper [string toupper $p]

set p $upper

}

.text modifyVerifyCallback {allcaps %ptr %length}

In addition, text widgets inherit callbacks from the Primitive class, namely help and destroy callbacks.


Next | Prev | Up | Top | Contents | Index