wcb::callback
command
wcb::cbappend
command
wcb::cbprepend
command
wcb::cancel
command
wcb::canceled
command
wcb::extend
command
wcb::replace
command
wcb::pathname
command
wcb::changeEntryText
command
wcb::postInsertEntryLen
command
wcb::postInsertEntryText
command
insert
callbacks for entry
and spinbox widgets
insert
callbacks for text
widgets
wcb::callback
commandwcb::callback
- Retrieve, set, and remove widget callbacks
wcb::callback widgetName before|after option ?callback callback ...?
widgetName
, the argument before
or after
, and the command corresponding to
option
. The values of the
option
argument can be:
insert
, delete
, or
motion
, for an entry, spinbox, or text
widget;
activate
, for a listbox or tablelist widget;
selset
or selclear
, for a
listbox, tablelist, or text widget.
If no arguments after the option
parameter are
specified, then the procedure just returns the current before- or
after-callback list, respectively, for the given widget operation.
Otherwise:
option
parameter is a nonempty string, then:
option
parameter, then the procedure
renames the Tcl command widgetName
to
_widgetName
and builds a new procedure
widgetName
, in which the execution of
the widget operations associated with the above values of
option
is preceded by invocations of
the corresponding before-callbacks and followed by calls to
the corresponding after-callbacks, in the global scope;
option
parameter are empty, then the procedure unregisters all the
corresponding before- or after-callbacks for the given widget and
returns an empty string.
When a callback is invoked, the name of the original Tcl command for
the widget widgetName
as well as the command
arguments are automatically appended to it as parameters.
The following table shows the widget subcommands corresponding to
the above values of option
, together with the
arguments of these subcommands:
Widget | option |
Subcommand | Arguments |
---|---|---|---|
entry or spinbox |
insert |
insert |
index string |
delete |
delete |
from ?to? |
|
motion |
icursor |
index |
|
listbox or tablelist |
activate |
activate |
index |
selset |
selection set |
first ?last? |
|
selclear |
selection clear |
first ?last? |
|
text | insert |
insert |
index string ?tagList
string tagList ...? |
delete |
delete |
from ?to? |
|
motion |
mark set insert |
index |
|
selset |
tag add sel |
from ?to
from to ...? |
|
selclear |
tag remove sel |
from ?to
from to ...? |
before
,
after
, insert
,
delete
, motion
, and
activate
to a minimum of one character.
Similarly, the first four characters of the words
selset
and selclear
are
sufficient for Wcb to recognize these options.
option
argument, you can use either the new procedure
widgetName
or the original Tcl command
_widgetName
to perform any valid operation on
the widget widgetName
. Use the old Tcl
command _widgetName
if you want to prevent
the callbacks from being invoked when executing the respective
widget subcommand.
widgetName
for which
wcb::callback
has replaced the corresponding
Tcl command with a new procedure, the original command
_widgetName
is deleted automatically by the
Tcl interpreter (this is not true in the case of a tablelist
widget). The new widget procedure
widgetName
would persist, but Wcb arranges
for it to be deleted from within a cleanup script bound to the
<Destroy>
event. This cleanup
script is associated with a binding tag called
WcbCleanup
, which is appended to the list of
binding tags of the widget the first time when registering some
callbacks for it. (In the case of a tablelist widget, this
script also deletes the original Tcl command
_widgetName
.)
widgetName
, thus ensuring that a
widget with the same path created later will not inherit them
from the widget just deleted (this can be important in some
applications). For this reason, you should be careful not
to remove WcbCleanup
from the list of binding
tags of the given widget!
wcb::cbappend
commandwcb::cbappend
- Append to a callback list
wcb::cbappend widgetName before|after option ?callback callback ...?
wcb::callback
. The only difference is
that wcb::cbappend
appends the arguments
specified after the option
parameter to the current
callback list (if present), while wcb::callback
replaces the old callbacks with these arguments.
wcb::cbprepend
commandwcb::cbprepend
- Prepend to a callback list
wcb::cbprepend widgetName before|after option ?callback callback ...?
wcb::callback
. The only difference is
that wcb::cbprepend
prepends the arguments
specified after the option
parameter to the current
callback list (if present), while wcb::callback
replaces the old callbacks with these arguments.
wcb::cancel
commandwcb::cancel
- Cancel a widget command
wcb::cancel ?script?
script
argument in the global scope. If this argument is not specified,
it defaults to the bell
command.
The return value is the one obtained from script
if this argument is specified and nonempty. Otherwise, the
command returns an empty string.
wcb::canceled
commandwcb::canceled
- Query the canceled status of a widget
command
wcb::canceled widgetName option
1
if the most recent invocation of the
widget operation corresponding to widgetName
and
option
has been aborted by some before-callback by
invoking wcb::cancel
;
otherwise, the return value is 0
. The arguments must
fulfil the same restrictions as in the case of the wcb::callback
command.
wcb::extend
commandwcb::extend
- Extend the argument list of a widget command
wcb::extend ?arg arg ...?
arg
parameters to the argument list of that
command. The new argument list will be passed to the remaining
callbacks for that command, too.
This procedure simply passes its parameters to the
lappend
command, called for the argument list of
the respective widget operation.
wcb::replace
commandwcb::replace
- Replace arguments of a widget command with
new ones
wcb::replace first last ?arg arg ...?
first
through last
of that
command with the optional arg
parameters. The
new argument list will be passed to the remaining callbacks for that
command, too. The arguments are numbered from 0
(see
the table in the description of the
wcb::callback
command).
This procedure simply passes its parameters to the
lreplace
command, called for the argument list of
the respective widget operation.
wcb::pathname
commandwcb::pathname
- Query the path name of the widget
corresponding to a Tcl command name
wcb::pathname origCmd
origCmd
passed to a callback.
When a before- or after-callback for a widget is invoked, the name
of the original Tcl command associated with that widget is
automatically appended to it as parameter. This procedure can be
used within a callback to derive the path name of the widget from the
command name passed to the callback as argument. It simply
returns the string range obtained from origCmd
by
removing the "::_"
prefix.
wcb::changeEntryText
commandwcb::changeEntryText
- Change the text of an entry or
spinbox widget
wcb::changeEntryText widgetName string
widgetName
with string
,
by using the delete
and insert
operations. If the first subcommand is canceled by some
before-delete
callback then the procedure returns
without inserting the new text; if the second operation is canceled by
some before-insert
callback then the command
restores the original contents of the widget.
The procedure keeps the position of the insertion cursor. The
return value is 1
on success and 0
on
failure, i.e., if one of the attempted operations was canceled by some
before-callback.
wcb::postInsertEntryLen
commandwcb::postInsertEntryLen
- Query the would-be length of the
text in an entry or spinbox widget
wcb::postInsertEntryLen widgetName string
widgetName
after inserting
string
.
wcb::postInsertEntryText
commandwcb::postInsertEntryText
- Query the would-be text of an
entry or spinbox widget
wcb::postInsertEntryText widgetName index string
widgetName
after
inserting string
before the character indicated by
index
.
insert
callbacks for entry
and spinbox widgetswcb::checkStrFor*
, wcb::convStrTo*
,
wcb::checkEntryFor*
, wcb::checkEntryLen
-
Before-insert
callbacks for entry and spinbox
widgets
wcb::checkStrForRegExp {exp w idx str} wcb::checkStrForAlpha {w idx str} wcb::checkStrForNum {w idx str} wcb::checkStrForAlnum {w idx str} wcb::convStrToUpper {w idx str} wcb::convStrToLower {w idx str} wcb::checkEntryForInt {w idx str} wcb::checkEntryForUInt {max w idx str} wcb::checkEntryForReal {w idx str} wcb::checkEntryForFixed {cnt w idx str} wcb::checkEntryLen {len w idx str}
wcb::checkStrForRegExp
callback checks whether
the string str
to be inserted into the entry widget
or entry component of the spinbox widget w
is
matched by the regular expression exp
; if not, it
cancels the insert
operation.
The three other wcb::checkStrFor*
callbacks
check whether the string str
to be inserted into
the entry widget or entry component of the spinbox widget
w
is alphabetic, numeric, or alphanumeric,
respectively; if not, they cancel the insert
operation. These procedures just invoke the callback
wcb::checkStrForRegExp
, passing to it the
Unicode-based patterns {^[[:alpha:]]*$}
,
{^[[:digit:]]*$}
, and {^[[:alnum:]]*$}
for Tk
versions 8.1 or higher, and the ASCII patterns
{^[A-Za-z]*$}
, {^[0-9]*$}
, and
{^[A-Za-z0-9]*$}
if Tk version 8.0 is being used.
The wcb::convStrTo*
callbacks replace the string
str
to be inserted into the entry widget or entry
component of the spinbox widget w
with its
uppercase or lowercase equivalent, respectively.
The wcb::checkEntryFor*
callbacks check whether
the text contained in the entry widget or entry component of the
spinbox widget w
after inserting the string
str
before the character indicated by the index
idx
would represent (the starting part of) an
integer number, unsigned integer no greater than
max
, real number, or real number in fixed-point
format with at most cnt
digits after the decimal
point, respectively; if not, they cancel the insert
operation. max
and cnt
should be nonnegative numbers or *
;
max = *
means: no upper bound
for the entry or spinbox value, while cnt =
*
stands for an unlimited number of digits after
the decimal point.
The wcb::checkEntryLen
callback checks whether
the length of the text contained in the entry widget or entry component
of the spinbox widget w
after inserting the string
str
would be greater than len
;
if yes, it cancels the insert
operation.
These callback procedures are implemented in the file
wcbEntry.tcl
, contained in the
scripts
directory. They return an empty
string.
insert
callbacks for text
widgetswcb::checkStrsFor*
, wcb::convStrsTo*
-
Before-insert
callbacks for text widgets
wcb::checkStrsForRegExp {exp w idx args} wcb::checkStrsForAlpha {w idx args} wcb::checkStrsForNum {w idx args} wcb::checkStrsForAlnum {w idx args} wcb::convStrsToUpper {w idx args} wcb::convStrsToLower {w idx args}
wcb::checkStrsForRegExp
callback checks whether
the strings to be inserted into the text widget w
,
contained in the list args
of the form
string ?tagList string tagList
...?
, are matched by the regular expression
exp
; if not, it cancels the
insert
operation.
The three other wcb::checkStrsFor*
callbacks
check whether the strings to be inserted into the text widget
w
, contained in the list args
of the form string ?tagList string
tagList ...?
, are alphabetic, numeric, or alphanumeric,
respectively; if not, they cancel the insert
operation. These procedures just invoke the callback
wcb::checkStrsForRegExp
, passing to it the
Unicode-based patterns {^[[:alpha:]\n]*$}
,
{^[[:digit:]\n]*$}
, and {^[[:alnum:]\n]*$}
for Tk versions 8.1 or higher, and the ASCII patterns
"^\[A-Za-z\n]*$"
, "^\[0-9\n]*$"
, and
"^\[A-Za-z0-9\n]*$"
if Tk version 8.0 is being used (in
this case, the presence of the "\n"
makes the regular
expressions a bit ugly).
The wcb::convStrsTo*
callbacks replace the
strings to be inserted into the text widget w
,
contained in the list args
of the form
string ?tagList string tagList
...?
, with their uppercase or lowercase equivalents,
respectively.
These callback procedures are implemented in the file
wcbText.tcl
, contained in the
scripts
directory. They return an empty
string.