]>
git.zerfleddert.de Git - micropolis/blob - src/tk/library/text.tcl
3 # This file contains Tcl procedures used to manage Tk entries.
5 # $Header: /user6/ouster/wish/scripts/RCS/text.tcl,v 1.2 92/07/16 16:26:33 ouster Exp $ SPRITE (Berkeley)
7 # Copyright 1992 Regents of the University of California
8 # Permission to use, copy, modify, and distribute this
9 # software and its documentation for any purpose and without
10 # fee is hereby granted, provided that this copyright
11 # notice appears in all copies. The University of California
12 # makes no representations about the suitability of this
13 # software for any purpose. It is provided "as is" without
14 # express or implied warranty.
17 # The procedure below is invoked when dragging one end of the selection.
18 # The arguments are the text window name and the index of the character
19 # that is to be the new end of the selection.
21 proc tk_textSelectTo
{w index
} {
24 case
$tk_priv(selectMode
) {
26 if [$w compare
$index < anchor
] {
31 set last
[$w index
$index+1c
]
35 if [$w compare
$index < anchor
] {
36 set first
[$w index
"$index wordstart"]
37 set last
[$w index
"anchor wordend"]
39 set first
[$w index
"anchor wordstart"]
40 set last
[$w index
"$index wordend"]
44 if [$w compare
$index < anchor
] {
45 set first
[$w index
"$index linestart"]
46 set last
[$w index
"anchor lineend + 1c"]
48 set first
[$w index
"anchor linestart"]
49 set last
[$w index
"$index lineend + 1c"]
53 $w tag remove sel
0.0 $first
54 $w tag add sel
$first $last
55 $w tag remove sel
$last end
58 # The procedure below is invoked to backspace over one character in
59 # a text widget. The name of the widget is passed as argument.
61 proc tk_textBackspace w
{
62 $w delete insert-1c insert
65 # The procedure below compares three indices, a, b, and c. Index b must
66 # be less than c. The procedure returns 1 if a is closer to b than to c,
67 # and 0 otherwise. The "w" argument is the name of the text widget in
68 # which to do the comparison.
70 proc tk_textIndexCloser
{w a b c
} {
74 if [$w compare
$a <= $b] {
77 if [$w compare
$a >= $c] {
80 scan $a "%d.%d" lineA chA
81 scan $b "%d.%d" lineB chB
82 scan $c "%d.%d" lineC chC
85 set chC
[string length
[$w get
$lineC.0 $lineC.end
]]
87 if {$lineB != $lineC} {
88 return [expr {($lineA-$lineB) < ($lineC-$lineA)}]
90 return [expr {($chA-$chB) < ($chC-$chA)}]
93 # The procedure below is called to reset the selection anchor to
94 # whichever end is FARTHEST from the index argument.
96 proc tk_textResetAnchor
{w index
} {
98 if {[$w tag ranges sel
] == ""} {
99 set tk_priv
(selectMode
) char
100 $w mark
set anchor
$index
103 if [tk_textIndexCloser
$w $index sel.first sel.last
] {
104 if {$tk_priv(selectMode
) == "char"} {
105 $w mark
set anchor sel.last
107 $w mark
set anchor sel.last-1c
110 $w mark
set anchor sel.first