Pavel Stranak wrote:
> This way the widget is still selectable and all other bindings as
> well as cursor work as in normal text.
> Do you think similar approach would be possible in Tcl::Tk?
The ROText and similar widgets exist from pre-8.4 Tk versions, where the text
widget was less functional. 8.4 added unlimited undo, some other minor
features, but most importantly in your case - a disabled state.
If you simply do:
$textWidget->configure(-state => "disabled");
you should get the effect you are looking for.
> Currently your ROText widget is a disabled Text, which means it
> doesn't take focus and consequently key bindings don't work.
> Yet I want to use the ROText for tagging text via simple key
> bindings. So I need to move cursor, make selections with keyboard and
> use my bindings to create tags from selection. I can use buttons now,
> but using mouse is too slow for this kind of work.
...
> In Perl/Tk both of these widgets are actually quite simple, but I
> have no idea, how much work would it be in Tcl/Tk to implement them.
OK, what you are asking for isn't really "read-only text", but it is also not
that hard to do in Tcl/Tk. The following simple example makes any text tagged
"readonly" ... read only:
pack [text .text]
.text tag configure readonly -background yellow
rename .text ..text
proc .text args {
if {[string match ins* $args] &&
[lsearch -exact [.text tag names [lindex $args 1]] readonly]>-1}
return
if {[string match del* $args]} {
if {[string compare {} [lindex $args 2]]} {
if {[string compare {} [eval .text tag nextrange \
readonly [lrange $args 1 2]]]} return
} else {
if {[lsearch -exact [.text tag names \
[lindex $args 1]] readonly]>-1} return
}
}
uplevel ..text $args
}
Jeff