| 1 |
# Copyright (c) 1992 The Regents of the University of California. |
| 2 |
# Copyright (c) 1994-1996 Sun Microsystems, Inc. |
| 3 |
# Copyright (c) 2002 O'Reilly & Associates Inc. |
| 4 |
# See the file "license.terms" for information on usage and redistribution |
| 5 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 6 |
# |
| 7 |
# |
| 8 |
|
| 9 |
=head1 NAME |
| 10 |
|
| 11 |
Tk::Text - Create and manipulate Text widgets |
| 12 |
|
| 13 |
=for category Tk Widget Classes |
| 14 |
|
| 15 |
=head1 SYNOPSIS |
| 16 |
|
| 17 |
I<$text> = I<$parent>-E<gt>B<Text>(?I<options>?); |
| 18 |
|
| 19 |
B<-background> B<-highlightbackground> B<-insertontime> B<-selectborderwidth> |
| 20 |
B<-borderwidth> B<-highlightcolor> B<-insertwidth> B<-selectforeground> |
| 21 |
B<-cursor> B<-highlightthickness> B<-padx> B<-setgrid> |
| 22 |
B<-exportselection> B<-insertbackground> B<-pady> B<-takefocus> |
| 23 |
B<-font> B<-insertborderwidth> B<-relief> B<-xscrollcommand> |
| 24 |
B<-foreground> B<-insertofftime> B<-selectbackground> B<-yscrollcommand> |
| 25 |
|
| 26 |
=head1 WIDGET-SPECIFIC OPTIONS |
| 27 |
|
| 28 |
=over 4 |
| 29 |
|
| 30 |
=item Name: B<height> |
| 31 |
|
| 32 |
=item Class: B<Height> |
| 33 |
|
| 34 |
=item Switch: B<-height> |
| 35 |
|
| 36 |
Specifies the desired height for the window, in units of characters |
| 37 |
in the font given by the B<-font> option. |
| 38 |
Must be at least one. |
| 39 |
|
| 40 |
=item Name: B<spacing1> |
| 41 |
|
| 42 |
=item Class: B<Spacing1> |
| 43 |
|
| 44 |
=item Switch: B<-spacing1> |
| 45 |
|
| 46 |
Requests additional space above each text line in the widget, |
| 47 |
using any of the standard forms for screen distances. |
| 48 |
If a line wraps, this option only applies to the first line |
| 49 |
on the display. |
| •50 |
This option may be overridden with B<-spacing1> options in |
| 51 |
tags. |
| 52 |
|
| 53 |
=item Name: B<spacing2> |
| 54 |
|
| 55 |
=item Class: B<Spacing2> |
| 56 |
|
| 57 |
=item Switch: B<-spacing2> |
| 58 |
|
| 59 |
For lines that wrap (so that they cover more than one line on the |
| 60 |
display) this option specifies additional space to provide between |
| 61 |
the display lines that represent a single line of text. |
| 62 |
The value may have any of the standard forms for screen distances. |
| •63 |
This option may be overridden with B<-spacing2> options in |
| 64 |
tags. |
| 65 |
|
| 66 |
=item Name: B<spacing3> |
| 67 |
|
| 68 |
=item Class: B<Spacing3> |
| 69 |
|
| 70 |
=item Switch: B<-spacing3> |
| 71 |
|
| 72 |
Requests additional space below each text line in the widget, |
| 73 |
using any of the standard forms for screen distances. |
| 74 |
If a line wraps, this option only applies to the last line |
| 75 |
on the display. |
| •76 |
This option may be overridden with B<-spacing3> options in |
| 77 |
tags. |
| 78 |
|
| 79 |
=item Name: B<state> |
| 80 |
|
| 81 |
=item Class: B<State> |
| 82 |
|
| 83 |
=item Switch: B<-state> |
| 84 |
|
| 85 |
Specifies one of two states for the text: B<normal> or B<disabled>. |
| 86 |
If the text is disabled then characters may not be inserted or deleted |
| 87 |
and no insertion cursor will be displayed, even if the input focus is |
| 88 |
in the widget. |
| 89 |
|
| 90 |
=item Name: B<tabs> |
| 91 |
|
| 92 |
=item Class: B<Tabs> |
| 93 |
|
| 94 |
=item Switch: B<-tabs> |
| 95 |
|
| 96 |
Specifies a set of tab stops for the window. The option's value consists |
| 97 |
of a list of screen distances giving the positions of the tab stops. Each |
| 98 |
position may optionally be followed in the next list element |
| 99 |
by one of the keywords B<left>, B<right>, B<center>, |
| 100 |
or B<numeric>, which specifies how to justify |
| 101 |
text relative to the tab stop. B<Left> is the default; it causes |
| 102 |
the text following the tab character to be positioned with its left edge |
| 103 |
at the tab position. B<Right> means that the right edge of the text |
| 104 |
following the tab character is positioned at the tab position, and |
| 105 |
B<center> means that the text is centered at the tab position. |
| 106 |
B<Numeric> means that the decimal point in the text is positioned |
| 107 |
at the tab position; if there is no decimal point then the least |
| 108 |
significant digit of the number is positioned just to the left of the |
| 109 |
tab position; if there is no number in the text then the text is |
| 110 |
right-justified at the tab position. |
| 111 |
For example, B<-tabs =E<gt> [qw/2c left 4c 6c center/]> creates three |
| 112 |
tab stops at two-centimeter intervals; the first two use left |
| 113 |
justification and the third uses center justification. |
| 114 |
If the list of tab stops does not have enough elements to cover all |
| 115 |
of the tabs in a text line, then Tk extrapolates new tab stops using |
| 116 |
the spacing and alignment from the last tab stop in the list. |
| 117 |
The value of the B<tabs> option may be overridden by B<-tabs> |
| 118 |
options in tags. |
| 119 |
If no B<-tabs> option is specified, or if it is specified as |
| 120 |
an empty list, then Tk uses default tabs spaced every eight |
| 121 |
(average size) characters. |
| 122 |
|
| 123 |
=item Name: B<width> |
| 124 |
|
| 125 |
=item Class: B<Width> |
| 126 |
|
| 127 |
=item Switch: B<-width> |
| 128 |
|
| 129 |
Specifies the desired width for the window in units of characters |
| 130 |
in the font given by the B<-font> option. |
| 131 |
If the font doesn't have a uniform width then the width of the |
| 132 |
character ``0'' is used in translating from character units to |
| 133 |
screen units. |
| 134 |
|
| 135 |
=item Name: B<wrap> |
| 136 |
|
| 137 |
=item Class: B<Wrap> |
| 138 |
|
| 139 |
=item Switch: B<-wrap> |
| 140 |
|
| 141 |
Specifies how to handle lines in the text that are too long to be |
| 142 |
displayed in a single line of the text's window. |
| 143 |
The value must be B<none> or B<char> or B<word>. |
| 144 |
A wrap mode of B<none> means that each line of text appears as |
| 145 |
exactly one line on the screen; extra characters that don't fit |
| 146 |
on the screen are not displayed. |
| 147 |
In the other modes each line of text will be broken up into several |
| 148 |
screen lines if necessary to keep all the characters visible. |
| 149 |
In B<char> mode a screen line break may occur after any character; |
| 150 |
in B<word> mode a line break will only be made at word boundaries. |
| 151 |
|
| 152 |
=back |
| 153 |
|
| 154 |
=head1 DESCRIPTION |
| 155 |
|
| 156 |
The B<Text> method creates a new window (given by the |
| 157 |
$text argument) and makes it into a text widget. |
| 158 |
Additional |
| 159 |
options, described above, may be specified on the command line |
| 160 |
or in the option database |
| 161 |
to configure aspects of the text such as its default background color |
| 162 |
and relief. The B<text> command returns the |
| 163 |
path name of the new window. |
| 164 |
|
| 165 |
A text widget displays one or more lines of text and allows that |
| 166 |
text to be edited. |
| 167 |
Text widgets support four different kinds of annotations on the |
| 168 |
text, called tags, marks, embedded windows or embedded images. |
| 169 |
Tags allow different portions of the text |
| 170 |
to be displayed with different fonts and colors. |
| 171 |
In addition, L<perlE<sol>Tk callbacks|Tk::callbacks> can be associated with tags so |
| 172 |
that scripts are invoked when particular actions such as keystrokes |
| 173 |
and mouse button presses occur in particular ranges of the text. |
| 174 |
See L<"TAGS"> below for more details. |
| 175 |
|
| 176 |
The second form of annotation consists of marks, which are floating |
| 177 |
markers in the text. |
| 178 |
Marks are used to keep track of various interesting positions in the |
| 179 |
text as it is edited. |
| 180 |
See L<"MARKS"> below for more details. |
| 181 |
|
| 182 |
The third form of annotation allows arbitrary windows to be |
| 183 |
embedded in a text widget. |
| 184 |
See L<"EMBEDDED WINDOWS"> below for more details. |
| 185 |
|
| 186 |
The fourth form of annotation allows Tk images to be embedded in a text |
| 187 |
widget. |
| 188 |
See L<"EMBEDDED IMAGES"> below for more details. |
| 189 |
|
| 190 |
The Perl/Tk B<Text> widget does not support undo/redo, use the B<TextUndo> |
| 191 |
widget instead. |
| 192 |
|
| 193 |
=head1 INDICES |
| 194 |
|
| 195 |
Many of the methods for texts take one or more indices |
| 196 |
as arguments. |
| 197 |
An index is a string used to indicate a particular place within |
| 198 |
a text, such as a place to insert characters or one endpoint of a |
| 199 |
range of characters to delete. |
| 200 |
Indices have the syntax |
| 201 |
|
| 202 |
base modifier modifier modifier ... |
| 203 |
|
| 204 |
Where I<base> gives a starting point and the I<modifier>s |
| 205 |
adjust the index from the starting point (e.g. move forward or |
| 206 |
backward one character). Every index must contain a I<base>, |
| 207 |
but the I<modifier>s are optional. |
| 208 |
|
| 209 |
The I<base> for an index must have one of the following forms: |
| 210 |
|
| 211 |
=over 4 |
| 212 |
|
| 213 |
=item I<line>B<.>I<char> |
| 214 |
|
| 215 |
Indicates I<char>'th character on line I<line>. |
| 216 |
Lines are numbered from 1 for consistency with other UNIX programs |
| 217 |
that use this numbering scheme. |
| 218 |
Within a line, characters are numbered from 0. |
| 219 |
If I<char> is B<end> then it refers to the newline character |
| 220 |
that ends the line. |
| 221 |
|
| 222 |
=item B<@>I<x>B<,>I<y> |
| 223 |
|
| 224 |
Indicates the character that covers the pixel whose x and y coordinates |
| 225 |
within the text's window are I<x> and I<y>. |
| 226 |
|
| 227 |
=item B<end> |
| 228 |
|
| 229 |
Indicates the end of the text (the character just after the last |
| 230 |
newline). |
| 231 |
|
| 232 |
=item I<mark> |
| 233 |
|
| 234 |
Indicates the character just after the mark whose name is I<mark>. |
| 235 |
|
| 236 |
=item I<tag>B<.first> |
| 237 |
|
| 238 |
Indicates the first character in the text that has been tagged with |
| 239 |
I<tag>. |
| 240 |
This form generates an error if no characters are currently tagged |
| 241 |
with I<tag>. |
| 242 |
|
| 243 |
=item I<tag>B<.last> |
| 244 |
|
| 245 |
Indicates the character just after the last one in the text that has |
| 246 |
been tagged with I<tag>. |
| 247 |
This form generates an error if no characters are currently tagged |
| 248 |
with I<tag>. |
| 249 |
|
| 250 |
=item I<$widget> |
| 251 |
|
| 252 |
Indicates the position of the embedded window referenced by I<$widget>. |
| 253 |
This form generates an error if I<$widget> does not reference to an |
| 254 |
embedded window. |
| 255 |
|
| 256 |
=item I<imageName> |
| 257 |
|
| 258 |
Indicates the position of the embedded image whose name is |
| 259 |
I<imageName>. |
| 260 |
This form generates an error if there is no embedded image |
| 261 |
by the given name. |
| 262 |
|
| 263 |
=back |
| 264 |
|
| 265 |
If the I<base> could match more than one of the above forms, such |
| 266 |
as a I<mark> and I<imageName> both having the same value, then |
| 267 |
the form earlier in the above list takes precedence. |
| 268 |
If modifiers follow the base index, each one of them must have one |
| 269 |
of the forms listed below. Keywords such as B<chars> and B<wordend> |
| 270 |
may be abbreviated as long as the abbreviation is unambiguous. |
| 271 |
|
| 272 |
=over 4 |
| 273 |
|
| 274 |
=item B<+ >I<count>B< chars> |
| 275 |
|
| 276 |
Adjust the index forward by I<count> characters, moving to later |
| 277 |
lines in the text if necessary. If there are fewer than I<count> |
| 278 |
characters in the text after the current index, then set the index |
| 279 |
to the last character in the text. |
| 280 |
Spaces on either side of I<count> are optional. |
| 281 |
|
| 282 |
=item B<- >I<count>B< chars> |
| 283 |
|
| 284 |
Adjust the index backward by I<count> characters, moving to earlier |
| 285 |
lines in the text if necessary. If there are fewer than I<count> |
| 286 |
characters in the text before the current index, then set the index |
| 287 |
to the first character in the text. |
| 288 |
Spaces on either side of I<count> are optional. |
| 289 |
|
| 290 |
=item B<+ >I<count>B< lines> |
| 291 |
|
| 292 |
Adjust the index forward by I<count> lines, retaining the same |
| 293 |
character position within the line. If there are fewer than I<count> |
| 294 |
lines after the line containing the current index, then set the index |
| 295 |
to refer to the same character position on the last line of the text. |
| 296 |
Then, if the line is not long enough to contain a character at the indicated |
| 297 |
character position, adjust the character position to refer to the last |
| 298 |
character of the line (the newline). |
| 299 |
Spaces on either side of I<count> are optional. |
| 300 |
|
| 301 |
=item B<- >I<count>B< lines> |
| 302 |
|
| 303 |
Adjust the index backward by I<count> lines, retaining the same |
| 304 |
character position within the line. If there are fewer than I<count> |
| 305 |
lines before the line containing the current index, then set the index |
| 306 |
to refer to the same character position on the first line of the text. |
| 307 |
Then, if the line is not long enough to contain a character at the indicated |
| 308 |
character position, adjust the character position to refer to the last |
| 309 |
character of the line (the newline). |
| 310 |
Spaces on either side of I<count> are optional. |
| 311 |
|
| 312 |
=item B<linestart> |
| 313 |
|
| 314 |
Adjust the index to refer to the first character on the line. |
| 315 |
|
| 316 |
=item B<lineend> |
| 317 |
|
| 318 |
Adjust the index to refer to the last character on the line (the newline). |
| 319 |
|
| 320 |
=item B<wordstart> |
| 321 |
|
| 322 |
Adjust the index to refer to the first character of the word containing |
| 323 |
the current index. A word consists of any number of adjacent characters |
| 324 |
that are letters, digits, or underscores, or a single character that |
| 325 |
is not one of these. |
| 326 |
|
| 327 |
=item B<wordend> |
| 328 |
|
| 329 |
Adjust the index to refer to the character just after the last one of the |
| 330 |
word containing the current index. If the current index refers to the last |
| 331 |
character of the text then it is not modified. |
| 332 |
|
| 333 |
=back |
| 334 |
|
| 335 |
If more than one modifier is present then they are applied in |
| 336 |
left-to-right order. For example, the index ``B<end - 1 chars>'' |
| 337 |
refers to the next-to-last character in the text and |
| 338 |
``B<insert wordstart - 1 c>'' refers to the character just before |
| 339 |
the first one in the word containing the insertion cursor. |
| 340 |
|
| 341 |
=head1 TAGS |
| 342 |
|
| 343 |
The first form of annotation in text widgets is a tag. |
| 344 |
A tag is a textual string that is associated with some of the characters |
| 345 |
in a text. |
| 346 |
Tags may contain arbitrary characters, but it is probably best to |
| 347 |
avoid using the the characters `` '' (space), B<+>, or B<->: |
| 348 |
these characters have special meaning in indices, so tags containing |
| 349 |
them can't be used as indices. |
| 350 |
There may be any number of tags associated with characters in a |
| 351 |
text. |
| 352 |
Each tag may refer to a single character, a range of characters, or |
| 353 |
several ranges of characters. |
| 354 |
An individual character may have any number of tags associated with it. |
| 355 |
|
| 356 |
A priority order is defined among tags, and this order is used in |
| 357 |
implementing some of the tag-related functions described below. |
| 358 |
When a tag is defined (by associating it with characters or setting |
| 359 |
its display options or binding callbacks to it), it is given |
| 360 |
a priority higher than any existing tag. |
| 361 |
The priority order of tags may be redefined using the |
| 362 |
``I<$text>-E<gt>B<tagRaise>'' and ``I<$text>-E<gt>B<tagLower>'' |
| 363 |
methods. |
| 364 |
|
| 365 |
Tags serve three purposes in text widgets. |
| 366 |
First, they control the way information is displayed on the screen. |
| 367 |
By default, characters are displayed as determined by the |
| 368 |
B<background>, B<font>, and B<foreground> options for the |
| 369 |
text widget. |
| 370 |
However, display options may be associated with individual tags |
| 371 |
using the ``I<$text>-E<gt>B<tagConfigure>'' method. |
| 372 |
If a character has been tagged, then the display options associated |
| 373 |
with the tag override the default display style. |
| 374 |
The following options are currently supported for tags: |
| 375 |
|
| 376 |
=over 4 |
| 377 |
|
| 378 |
=item B<-background> =E<gt> I<color> |
| 379 |
|
| 380 |
I<Color> specifies the background color to use for characters |
| 381 |
associated with the tag. |
| 382 |
It may have any of the forms accepted by B<Tk_GetColor>. |
| 383 |
|
| 384 |
=item B<-bgstipple> =E<gt> I<bitmap> |
| 385 |
|
| 386 |
I<Bitmap> specifies a bitmap that is used as a stipple pattern |
| 387 |
for the background. |
| 388 |
It may have any of the forms accepted by B<Tk_GetBitmap>. |
| 389 |
If I<bitmap> hasn't been specified, or if it is specified |
| 390 |
as an empty string, then a solid fill will be used for the |
| 391 |
background. |
| 392 |
|
| 393 |
=item B<-borderwidth> =E<gt> I<pixels> |
| 394 |
|
| 395 |
I<Pixels> specifies the width of a 3-D border to draw around |
| 396 |
the background. |
| 397 |
It may have any of the forms accepted by B<Tk_GetPixels>. |
| 398 |
This option is used in conjunction with the B<-relief> |
| 399 |
option to give a 3-D appearance to the background for characters; |
| 400 |
it is ignored unless the B<-background> option |
| 401 |
has been set for the tag. |
| 402 |
|
| 403 |
=item B<-elide> =E<gt> boolean |
| 404 |
|
| 405 |
Elide specifies whether the data should be elided. Elided data |
| 406 |
is not displayed and takes no space on screen, but further on |
| 407 |
behaves just as normal data. |
| 408 |
|
| 409 |
=item B<-data> =E<gt> I<value> |
| 410 |
|
| 411 |
Allows an arbitrary perl scalar I<value> to be associated with the tag. |
| 412 |
|
| 413 |
=item B<-fgstipple> =E<gt> I<bitmap> |
| 414 |
|
| 415 |
I<Bitmap> specifies a bitmap that is used as a stipple pattern |
| 416 |
when drawing text and other foreground information such as |
| 417 |
underlines. |
| 418 |
It may have any of the forms accepted by B<Tk_GetBitmap>. |
| 419 |
If I<bitmap> hasn't been specified, or if it is specified |
| 420 |
as an empty string, then a solid fill will be used. |
| 421 |
|
| 422 |
=item B<-font> =E<gt> I<fontName> |
| 423 |
|
| 424 |
I<FontName> is the name of a font to use for drawing characters. |
| 425 |
It may have any of the forms accepted by B<Tk_GetFontStruct>. |
| 426 |
|
| 427 |
=item B<-foreground> =E<gt> I<color> |
| 428 |
|
| 429 |
I<Color> specifies the color to use when drawing text and other |
| 430 |
foreground information such as underlines. |
| 431 |
It may have any of the forms accepted by B<Tk_GetColor>. |
| 432 |
|
| 433 |
=item B<-justify> =E<gt> I<justify> |
| 434 |
|
| 435 |
If the first character of a display line has a tag for which this |
| 436 |
option has been specified, then I<justify> determines how to |
| 437 |
justify the line. |
| 438 |
It must be one of B<left>, B<right>, or B<center>. |
| 439 |
If a line wraps, then the justification for each line on the |
| 440 |
display is determined by the first character of that display line. |
| 441 |
|
| 442 |
=item B<-lmargin1> =E<gt> I<pixels> |
| 443 |
|
| 444 |
If the first character of a text line has a tag for which this |
| 445 |
option has been specified, then I<pixels> specifies how |
| 446 |
much the line should be indented from the left edge of the |
| 447 |
window. |
| 448 |
I<Pixels> may have any of the standard forms for screen |
| 449 |
distances. |
| 450 |
If a line of text wraps, this option only applies to the |
| 451 |
first line on the display; the B<-lmargin2> option controls |
| 452 |
the indentation for subsequent lines. |
| 453 |
|
| 454 |
=item B<-lmargin2> =E<gt> I<pixels> |
| 455 |
|
| 456 |
If the first character of a display line has a tag for which this |
| 457 |
option has been specified, and if the display line is not the |
| 458 |
first for its text line (i.e., the text line has wrapped), then |
| 459 |
I<pixels> specifies how much the line should be indented from |
| 460 |
the left edge of the window. |
| 461 |
I<Pixels> may have any of the standard forms for screen |
| 462 |
distances. |
| 463 |
This option is only used when wrapping is enabled, and it only |
| 464 |
applies to the second and later display lines for a text line. |
| 465 |
|
| 466 |
=item B<-offset> =E<gt> I<pixels> |
| 467 |
|
| 468 |
I<Pixels> specifies an amount by which the text's baseline |
| 469 |
should be offset vertically from the baseline of the overall |
| 470 |
line, in pixels. |
| 471 |
For example, a positive offset can be used for superscripts |
| 472 |
and a negative offset can be used for subscripts. |
| 473 |
I<Pixels> may have any of the standard forms for screen |
| 474 |
distances. |
| 475 |
|
| 476 |
=item B<-overstrike> =E<gt> I<boolean> |
| 477 |
|
| 478 |
Specifies whether or not to draw a horizontal rule through |
| 479 |
the middle of characters. |
| 480 |
I<Boolean> may have any of the forms accepted by B<Tk_GetBoolean>. |
| 481 |
|
| 482 |
=item B<-relief> =E<gt> I<relief> |
| 483 |
|
| 484 |
I<Relief> specifies the 3-D relief to use for drawing backgrounds, |
| 485 |
in any of the forms accepted by B<Tk_GetRelief>. |
| 486 |
This option is used in conjunction with the B<-borderwidth> |
| 487 |
option to give a 3-D appearance to the background for characters; |
| 488 |
it is ignored unless the B<-background> option |
| 489 |
has been set for the tag. |
| 490 |
|
| 491 |
=item B<-rmargin> =E<gt> I<pixels> |
| 492 |
|
| 493 |
If the first character of a display line has a tag for which this |
| 494 |
option has been specified, then I<pixels> specifies how wide |
| 495 |
a margin to leave between the end of the line and the right |
| 496 |
edge of the window. |
| 497 |
I<Pixels> may have any of the standard forms for screen |
| 498 |
distances. |
| 499 |
This option is only used when wrapping is enabled. |
| 500 |
If a text line wraps, the right margin for each line on the |
| 501 |
display is determined by the first character of that display |
| 502 |
line. |
| 503 |
|
| 504 |
=item B<-spacing1> =E<gt> I<pixels> |
| 505 |
|
| 506 |
I<Pixels> specifies how much additional space should be |
| 507 |
left above each text line, using any of the standard forms for |
| 508 |
screen distances. |
| 509 |
If a line wraps, this option only applies to the first |
| 510 |
line on the display. |
| 511 |
|
| 512 |
=item B<-spacing2> =E<gt> I<pixels> |
| 513 |
|
| 514 |
For lines that wrap, this option specifies how much additional |
| 515 |
space to leave between the display lines for a single text line. |
| 516 |
I<Pixels> may have any of the standard forms for screen |
| 517 |
distances. |
| 518 |
|
| 519 |
=item B<-spacing3> =E<gt> I<pixels> |
| 520 |
|
| 521 |
I<Pixels> specifies how much additional space should be |
| 522 |
left below each text line, using any of the standard forms for |
| 523 |
screen distances. |
| 524 |
If a line wraps, this option only applies to the last |
| 525 |
line on the display. |
| 526 |
|
| 527 |
=item B<-tabs> =E<gt> I<tabList> |
| 528 |
|
| 529 |
I<TabList> specifies a set of tab stops in the same form |
| 530 |
as for the B<-tabs> option for the text widget. This |
| 531 |
option only applies to a display line if it applies to the |
| 532 |
first character on that display line. |
| 533 |
If this option is specified as an empty string, it cancels |
| 534 |
the option, leaving it unspecified for the tag (the default). |
| 535 |
If the option is specified as a non-empty string that is |
| 536 |
an empty list, such as B<-tabs => " ">, then it requests |
| 537 |
default 8-character tabs as described for the B<tabs> |
| 538 |
widget option. |
| 539 |
|
| 540 |
=item B<-underline> =E<gt> I<boolean> |
| 541 |
|
| 542 |
I<Boolean> specifies whether or not to draw an underline underneath |
| 543 |
characters. |
| 544 |
It may have any of the forms accepted by B<Tk_GetBoolean>. |
| 545 |
|
| 546 |
=item B<-wrap> =E<gt> I<mode> |
| 547 |
|
| 548 |
I<Mode> specifies how to handle lines that are wider than the |
| 549 |
text's window. |
| 550 |
It has the same legal values as the B<-wrap> option |
| 551 |
for the text widget: B<none>, B<char>, or B<word>. |
| 552 |
If this tag option is specified, it overrides the B<-wrap> option |
| 553 |
for the text widget. |
| 554 |
|
| 555 |
=back |
| 556 |
|
| 557 |
If a character has several tags associated with it, and if their |
| 558 |
display options conflict, then the options of the highest priority |
| 559 |
tag are used. |
| 560 |
If a particular display option hasn't been specified for a |
| 561 |
particular tag, or if it is specified as an empty string, then |
| 562 |
that option will never be used; the next-highest-priority |
| 563 |
tag's option will used instead. |
| 564 |
If no tag specifies a particular display option, then the default |
| 565 |
style for the widget will be used. |
| 566 |
|
| 567 |
The second purpose for tags is event bindings. |
| 568 |
You can associate bindings with a tag in much the same way you can |
| 569 |
associate bindings with a widget class: whenever particular X |
| 570 |
events occur on characters with the given tag, a given |
| 571 |
<perl/Tk callback|Tk::callbacks> will be executed. |
| 572 |
Tag bindings can be used to give behaviors to ranges of characters; |
| 573 |
among other things, this allows hypertext-like |
| 574 |
features to be implemented. |
| 575 |
For details, see the description of the B<tagBind> widget |
| 576 |
method below. |
| 577 |
|
| 578 |
The third use for tags is in managing the selection. |
| 579 |
See L<"THE SELECTION"> below. |
| 580 |
|
| 581 |
=head1 MARKS |
| 582 |
|
| 583 |
The second form of annotation in text widgets is a mark. |
| 584 |
Marks are used for remembering particular places in a text. |
| 585 |
They are something like tags, in that they have names and |
| 586 |
they refer to places in the file, but a mark isn't associated |
| 587 |
with particular characters. |
| 588 |
Instead, a mark is associated with the gap between two characters. |
| 589 |
Only a single position may be associated with a mark at any given |
| 590 |
time. |
| 591 |
If the characters around a mark are deleted the mark will still |
| 592 |
remain; it will just have new neighbor characters. |
| 593 |
In contrast, if the characters containing a tag are deleted then |
| 594 |
the tag will no longer have an association with characters in |
| 595 |
the file. |
| 596 |
Marks may be manipulated with the ``I<$text>-E<gt>B<mark>'' text widget |
| 597 |
method, and their current locations may be determined by using the |
| 598 |
mark name as an index in methods. |
| 599 |
|
| 600 |
Each mark also has a I<gravity>, which is either B<left> or |
| 601 |
B<right>. |
| 602 |
The gravity for a mark specifies what happens to the mark when |
| 603 |
text is inserted at the point of the mark. |
| 604 |
If a mark has left gravity, then the mark is treated as if it |
| 605 |
were attached to the character on its left, so the mark will |
| 606 |
remain to the left of any text inserted at the mark position. |
| 607 |
If the mark has right gravity, new text inserted at the mark |
| 608 |
position will appear to the right of the mark. The gravity |
| 609 |
for a mark defaults to B<right>. |
| 610 |
|
| 611 |
The name space for marks is different from that for tags: the |
| 612 |
same name may be used for both a mark and a tag, but they will refer |
| 613 |
to different things. |
| 614 |
|
| 615 |
Two marks have special significance. |
| 616 |
First, the mark B<insert> is associated with the insertion cursor, |
| 617 |
as described under L<"THE INSERTION CURSOR"> below. |
| 618 |
Second, the mark B<current> is associated with the character |
| 619 |
closest to the mouse and is adjusted automatically to track the |
| 620 |
mouse position and any changes to the text in the widget (one |
| 621 |
exception: B<current> is not updated in response to mouse |
| 622 |
motions if a mouse button is down; the update will be deferred |
| 623 |
until all mouse buttons have been released). |
| 624 |
Neither of these special marks may be deleted. |
| 625 |
|
| 626 |
=head1 EMBEDDED WINDOWS |
| 627 |
|
| 628 |
The third form of annotation in text widgets is an embedded window. |
| 629 |
Each embedded window annotation causes a window to be displayed |
| 630 |
at a particular point in the text. |
| 631 |
There may be any number of embedded windows in a text widget, |
| 632 |
and any widget may be used as an embedded window (subject to the |
| 633 |
usual rules for geometry management, which require the text window |
| 634 |
to be the parent of the embedded window or a descendant of its |
| 635 |
parent). |
| 636 |
The embedded window's position on the screen will be updated as the |
| 637 |
text is modified or scrolled, and it will be mapped and unmapped as |
| 638 |
it moves into and out of the visible area of the text widget. |
| 639 |
Each embedded window occupies one character's worth of index space |
| 640 |
in the text widget, and it may be referred to either by the name |
| 641 |
of its embedded window or by its position in the widget's |
| 642 |
index space. |
| 643 |
If the range of text containing the embedded window is deleted then |
| 644 |
the window is destroyed. |
| 645 |
|
| 646 |
When an embedded window is added to a text widget with the |
| 647 |
B<widgetCreate> method, several configuration |
| 648 |
options may be associated with it. |
| 649 |
These options may be modified later with the B<widgetConfigure> |
| 650 |
method. |
| 651 |
The following options are currently supported: |
| 652 |
|
| 653 |
=over 4 |
| 654 |
|
| 655 |
=item B<-align> =E<gt> I<where> |
| 656 |
|
| 657 |
If the window is not as tall as the line in which it is displayed, |
| 658 |
this option determines where the window is displayed in the line. |
| 659 |
I<Where> must have one of the values B<top> (align the top of the window |
| 660 |
with the top of the line), B<center> (center the window |
| 661 |
within the range of the line), B<bottom> (align the bottom of the |
| 662 |
window with the bottom of the line's area), |
| 663 |
or B<baseline> (align the bottom of the window with the baseline |
| 664 |
of the line). |
| 665 |
|
| 666 |
=item B<-create> =E<gt> I<callback> |
| 667 |
|
| 668 |
Specifies a L<callback|Tk::callbacks> that may be evaluated to create the window |
| 669 |
for the annotation. |
| 670 |
If no B<-window> option has been specified for the annotation |
| 671 |
this I<callback> will be evaluated when the annotation is about to |
| 672 |
be displayed on the screen. |
| 673 |
I<Callback> must create a window for the annotation and return |
| 674 |
the name of that window as its result. |
| 675 |
If the annotation's window should ever be deleted, I<callback> |
| 676 |
will be evaluated again the next time the annotation is displayed. |
| 677 |
|
| 678 |
=item B<-padx> =E<gt> I<pixels> |
| 679 |
|
| 680 |
I<Pixels> specifies the amount of extra space to leave on |
| 681 |
each side of the embedded window. |
| 682 |
It may have any of the usual forms defined for a screen distance |
| 683 |
(see B<Tk_GetPixels>). |
| 684 |
|
| 685 |
=item B<-pady> =E<gt> I<pixels> |
| 686 |
|
| 687 |
I<Pixels> specifies the amount of extra space to leave on |
| 688 |
the top and on the bottom of the embedded window. |
| 689 |
It may have any of the usual forms defined for a screen distance |
| 690 |
(see B<Tk_GetPixels>). |
| 691 |
|
| 692 |
=item B<-stretch> =E<gt> I<boolean> |
| 693 |
|
| 694 |
If the requested height of the embedded window is less than the |
| 695 |
height of the line in which it is displayed, this option can be |
| 696 |
used to specify whether the window should be stretched vertically |
| 697 |
to fill its line. |
| 698 |
If the B<-pady> option has been specified as well, then the |
| 699 |
requested padding will be retained even if the window is |
| 700 |
stretched. |
| 701 |
|
| 702 |
=item B<-window> =E<gt> I<$widget> |
| 703 |
|
| 704 |
Specifies the name of a window to display in the annotation. |
| 705 |
|
| 706 |
=back |
| 707 |
|
| 708 |
=head1 EMBEDDED IMAGES |
| 709 |
|
| 710 |
The final form of annotation in text widgets is an embedded image. |
| 711 |
Each embedded image annotation causes an image to be displayed |
| 712 |
at a particular point in the text. |
| 713 |
There may be any number of embedded images in a text widget, |
| 714 |
and a particular image may be embedded in multiple places in the same |
| 715 |
text widget. |
| 716 |
The embedded image's position on the screen will be updated as the |
| 717 |
text is modified or scrolled. |
| 718 |
Each embedded image occupies one character's worth of index space |
| 719 |
in the text widget, and it may be referred to either by |
| 720 |
its position in the widget's index space, or the name it is assigned |
| 721 |
when the image is inserted into the text widget with B<imageCreate>. |
| 722 |
If the range of text containing the embedded image is deleted then |
| 723 |
that copy of the image is removed from the screen. |
| 724 |
|
| 725 |
When an embedded image is added to a text widget with the B<image> |
| 726 |
create method, a name unique to this instance of the image |
| 727 |
is returned. This name may then be used to refer to this image |
| 728 |
instance. The name is taken to be the value of the B<-name> option |
| 729 |
(described below). If the B<-name> option is not provided, the |
| 730 |
B<-image> name is used instead. If the I<imageName> is already |
| 731 |
in use in the text widget, then B<#>I<nn> is added to the end of the |
| 732 |
I<imageName>, where I<nn> is an arbitrary integer. This insures |
| 733 |
the I<imageName> is unique. |
| 734 |
Once this name is assigned to this instance of the image, it does not |
| 735 |
change, even though the B<-image> or B<-name> values can be changed |
| 736 |
with B<image configure>. |
| 737 |
|
| 738 |
When an embedded image is added to a text widget with the |
| 739 |
B<imageCreate> method, several configuration |
| 740 |
options may be associated with it. |
| 741 |
These options may be modified later with the B<image configure> |
| 742 |
method. |
| 743 |
The following options are currently supported: |
| 744 |
|
| 745 |
=over 4 |
| 746 |
|
| 747 |
=item B<-align> =E<gt> I<where> |
| 748 |
|
| 749 |
If the image is not as tall as the line in which it is displayed, |
| 750 |
this option determines where the image is displayed in the line. |
| 751 |
I<Where> must have one of the values B<top> (align the top of the image |
| 752 |
with the top of the line), B<center> (center the image |
| 753 |
within the range of the line), B<bottom> (align the bottom of the |
| 754 |
image with the bottom of the line's area), |
| 755 |
or B<baseline> (align the bottom of the image with the baseline |
| 756 |
of the line). |
| 757 |
|
| 758 |
=item B<-image> =E<gt> I<image> |
| 759 |
|
| 760 |
Specifies the name of the Tk image to display in the annotation. |
| 761 |
If I<image> is not a valid Tk image, then an error is returned. |
| 762 |
|
| 763 |
=item B<-name> =E<gt> I<ImageName> |
| 764 |
|
| 765 |
Specifies the name by which this image instance may be referenced in |
| 766 |
the text widget. If I<ImageName> is not supplied, then the |
| 767 |
name of the Tk image is used instead. |
| 768 |
If the I<imageName> is already in use, I<#nn> is appended to |
| 769 |
the end of the name as described above. |
| 770 |
|
| 771 |
=item B<-padx> =E<gt> I<pixels> |
| 772 |
|
| 773 |
I<Pixels> specifies the amount of extra space to leave on |
| 774 |
each side of the embedded image. |
| 775 |
It may have any of the usual forms defined for a screen distance. |
| 776 |
|
| 777 |
=item B<-pady> =E<gt> I<pixels> |
| 778 |
|
| 779 |
I<Pixels> specifies the amount of extra space to leave on |
| 780 |
the top and on the bottom of the embedded image. |
| 781 |
It may have any of the usual forms defined for a screen distance. |
| 782 |
|
| 783 |
=back |
| 784 |
|
| 785 |
=head1 THE SELECTION |
| 786 |
|
| 787 |
Selection support is implemented via tags. |
| 788 |
If the B<exportSelection> option for the text widget is true |
| 789 |
then the B<sel> tag will be associated with the selection: |
| 790 |
|
| 791 |
=over 4 |
| 792 |
|
| 793 |
=item [1] |
| 794 |
|
| 795 |
Whenever characters are tagged with B<sel> the text widget |
| 796 |
will claim ownership of the selection. |
| 797 |
|
| 798 |
=item [2] |
| 799 |
|
| 800 |
Attempts to retrieve the |
| 801 |
selection will be serviced by the text widget, returning all the |
| 802 |
characters with the B<sel> tag. |
| 803 |
|
| 804 |
=item [3] |
| 805 |
|
| 806 |
If the selection is claimed away by another application or by another |
| 807 |
window within this application, then the B<sel> tag will be removed |
| 808 |
from all characters in the text. |
| 809 |
|
| 810 |
=item [4] |
| 811 |
|
| 812 |
Whenever the sel tag range changes a virtual event B<<<Selection>>> |
| 813 |
is generated. |
| 814 |
|
| 815 |
The B<sel> tag is automatically defined when a text widget is |
| 816 |
created, and it may not be deleted with the ``I<$text>-E<gt>B<tagDelete>'' |
| 817 |
method. Furthermore, the B<selectBackground>, |
| 818 |
B<selectBorderWidth>, and B<selectForeground> options for |
| 819 |
the text widget are tied to the B<-background>, |
| 820 |
B<-borderwidth>, and B<-foreground> options for the B<sel> |
| 821 |
tag: changes in either will automatically be reflected in the |
| 822 |
other. |
| 823 |
|
| 824 |
=back |
| 825 |
|
| 826 |
=head1 THE INSERTION CURSOR |
| 827 |
|
| 828 |
The mark named B<insert> has special significance in text widgets. |
| 829 |
It is defined automatically when a text widget is created and it |
| 830 |
may not be unset with the ``I<$text>-E<gt>B<markUnset>'' widget |
| 831 |
command. |
| 832 |
The B<insert> mark represents the position of the insertion |
| 833 |
cursor, and the insertion cursor will automatically be drawn at |
| 834 |
this point whenever the text widget has the input focus. |
| 835 |
|
| 836 |
=head1 THE MODIFIED FLAG |
| 837 |
|
| 838 |
The text widget can keep track of changes to the content of the widget |
| 839 |
by means of the modified flag. Inserting or deleting text will set this |
| 840 |
flag. The flag can be queried, set and cleared programatically as well. |
| 841 |
Whenever the flag changes state a B<<<Modified>>> virtual event is gener- |
| 842 |
ated. See the edit modified widget command for more details. |
| 843 |
|
| 844 |
|
| 845 |
=head1 WIDGET METHODS |
| 846 |
|
| 847 |
The B<Text> method creates a widget object. |
| 848 |
This object supports the B<configure> and B<cget> methods |
| 849 |
described in L<Tk::options> which can be used to enquire and |
| 850 |
modify the options described above. |
| 851 |
The widget also inherits all the methods provided by the generic |
| 852 |
L<Tk::Widget|Tk::Widget> class. |
| 853 |
|
| 854 |
The following additional methods are available for text widgets. |
| 855 |
In addition, the extended text widget methods as documented |
| 856 |
in I<"Mastering Perl/Tk"> are included in this pod (with |
| 857 |
permission from the publisher, B<O'Reilly and Associates Inc.>). |
| 858 |
|
| 859 |
=over 4 |
| 860 |
|
| 861 |
=item I<$text>-E<gt>B<adjustSelect> |
| 862 |
|
| 863 |
Moves the end point of the selection and anchor point to the |
| 864 |
mouse pointer location. |
| 865 |
|
| 866 |
=item I<$text>-E<gt>B<bbox>(I<index>) |
| 867 |
|
| 868 |
Returns a list of four elements describing the screen area |
| 869 |
of the character given by I<index>. |
| 870 |
The first two elements of the list give the x and y coordinates |
| 871 |
of the upper-left corner of the area occupied by the |
| 872 |
character, and the last two elements give the width and height |
| 873 |
of the area. |
| 874 |
If the character is only partially visible on the screen, then |
| 875 |
the return value reflects just the visible part. |
| 876 |
If the character is not visible on the screen then the return |
| 877 |
value is an empty list. |
| 878 |
|
| 879 |
=item I<$text>-E<gt>B<clipboardColumnCopy> |
| 880 |
|
| 881 |
Performs a rectangular copy of the currently selected text with |
| 882 |
basic compensation for tab characters. |
| 883 |
|
| 884 |
=item I<$text>-E<gt>B<clipboardColumnCut> |
| 885 |
|
| 886 |
Performs a rectangular cut of the currently selected text with |
| 887 |
basic compensation for tab characters. |
| 888 |
|
| 889 |
=item I<$text>-E<gt>B<clipboardColumnPaste> |
| 890 |
|
| 891 |
Performs a rectangular paste of the text in the clipboard. The |
| 892 |
upper-left corner is specified by the current position of the |
| 893 |
insert mark with basic compensation for tab characters. |
| 894 |
|
| 895 |
=item I<$text>-E<gt>B<compare>(I<index1, op, index2>) |
| 896 |
|
| 897 |
Compares the indices given by I<index1> and I<index2> according |
| 898 |
to the relational operator given by I<op>, and returns 1 if |
| 899 |
the relationship is satisfied and 0 if it isn't. |
| 900 |
I<Op> must be one of the operators E<lt>, E<lt>=, ==, E<gt>=, E<gt>, or !=. |
| 901 |
If I<op> is == then 1 is returned if the two indices refer to |
| 902 |
the same character, if I<op> is E<lt> then 1 is returned if I<index1> |
| 903 |
refers to an earlier character in the text than I<index2>, and |
| 904 |
so on. |
| 905 |
|
| 906 |
=item I<$text>-E<gt>B<Contents>(I<?args>?) |
| 907 |
|
| 908 |
Query or change the entire contents of the text widget. If no |
| 909 |
arguments are given, the entire contents of the text widget are |
| 910 |
returned. If any arguments are given, the entire contents of the |
| 911 |
text widget are deleted and replaced by the argument list. |
| 912 |
|
| 913 |
=item I<$text>-E<gt>B<debug>(?I<boolean>?) |
| 914 |
|
| 915 |
If I<boolean> is specified, then it must have one of the true or |
| 916 |
false values accepted by Tcl_GetBoolean. |
| 917 |
If the value is a true one then internal consistency checks will be |
| 918 |
turned on in the B-tree code associated with text widgets. |
| 919 |
If I<boolean> has a false value then the debugging checks will |
| 920 |
be turned off. |
| 921 |
In either case the command returns an empty string. |
| 922 |
If I<boolean> is not specified then the command returns B<on> |
| 923 |
or B<off> to indicate whether or not debugging is turned on. |
| 924 |
There is a single debugging switch shared by all text widgets: turning |
| 925 |
debugging on or off in any widget turns it on or off for all widgets. |
| 926 |
For widgets with large amounts of text, the consistency checks may |
| 927 |
cause a noticeable slow-down. |
| 928 |
|
| 929 |
=item I<$text>-E<gt>B<delete>(I<index1, >?I<index2>?) |
| 930 |
|
| 931 |
Delete a range of characters from the text. |
| 932 |
If both I<index1> and I<index2> are specified, then delete |
| 933 |
all the characters starting with the one given by I<index1> |
| 934 |
and stopping just before I<index2> (i.e. the character at |
| 935 |
I<index2> is not deleted). |
| 936 |
If I<index2> doesn't specify a position later in the text |
| 937 |
than I<index1> then no characters are deleted. |
| 938 |
If I<index2> isn't specified then the single character at |
| 939 |
I<index1> is deleted. |
| 940 |
It is not allowable to delete characters in a way that would leave |
| 941 |
the text without a newline as the last character. |
| 942 |
The command returns an empty string. |
| 943 |
If more indices are given, multiple ranges of text will |
| 944 |
be deleted. All indices are first checked for validity before |
| 945 |
any deletions are made. They are sorted and the text is removed |
| 946 |
from the last range to the first range to deleted text does not |
| 947 |
cause a undesired index shifting side-effects. If multiple |
| 948 |
ranges with the same start index are given, then the longest |
| 949 |
range is used. If overlapping ranges are given, then they will |
| 950 |
be merged into spans that do not cause deletion of text outside |
| 951 |
the given ranges due to text shifted during deletion. |
| 952 |
|
| 953 |
=item I<$text>-E<gt>B<deleteSelected> |
| 954 |
|
| 955 |
Delete the currently selected text. |
| 956 |
|
| 957 |
=item I<$text>-E<gt>B<deleteTextTaggedWith>(I<tag>) |
| 958 |
|
| 959 |
Delete the text tagged with the I<tag> parameter. |
| 960 |
|
| 961 |
=item I<$text>-E<gt>B<deleteToEndofLine> |
| 962 |
|
| 963 |
Delete from the insert mark location to the end of line. |
| 964 |
|
| 965 |
=item I<$text>-E<gt>B<dlineinfo>(I<index>) |
| 966 |
|
| 967 |
Returns a list with five elements describing the area occupied |
| 968 |
by the display line containing I<index>. |
| 969 |
The first two elements of the list give the x and y coordinates |
| 970 |
of the upper-left corner of the area occupied by the |
| 971 |
line, the third and fourth elements give the width and height |
| 972 |
of the area, and the fifth element gives the position of the baseline |
| 973 |
for the line, measured down from the top of the area. |
| 974 |
All of this information is measured in pixels. |
| 975 |
If the current wrap mode is B<none> and the line extends beyond |
| 976 |
the boundaries of the window, |
| 977 |
the area returned reflects the entire area of the line, including the |
| 978 |
portions that are out of the window. |
| 979 |
If the line is shorter than the full width of the window then the |
| 980 |
area returned reflects just the portion of the line that is occupied |
| 981 |
by characters and embedded windows. |
| 982 |
If the display line containing I<index> is not visible on |
| 983 |
the screen then the return value is an empty list. |
| 984 |
|
| 985 |
=item I<$text>-E<gt>B<dump>(?I<switches>?, I<index1, >?I<index2>?) |
| 986 |
|
| 987 |
Return the contents of the text widget from I<index1> up to, |
| 988 |
but not including I<index2>, |
| 989 |
including the text and |
| 990 |
information about marks, tags, and embedded windows. |
| 991 |
If I<index2> is not specified, then it defaults to |
| 992 |
one character past I<index1>. The information is returned |
| 993 |
in the following format: |
| 994 |
|
| 995 |
I<key1 value1 index1 key2 value2 index2> ... |
| 996 |
|
| 997 |
The possible I<key> values are B<text>, B<mark>, |
| 998 |
B<tagon>, B<tagoff>, and I<$text>. The corresponding |
| 999 |
I<value> is the text, mark name, tag name, or window name. |
| 1000 |
The I<index> information is the index of the |
| 1001 |
start of the text, the mark, the tag transition, or the window. |
| 1002 |
One or more of the following switches (or abbreviations thereof) |
| 1003 |
may be specified to control the dump: |
| 1004 |
|
| 1005 |
=over 4 |
| 1006 |
|
| 1007 |
=item B<-all> |
| 1008 |
|
| 1009 |
Return information about all elements: text, marks, tags, and windows. |
| 1010 |
This is the default. |
| 1011 |
|
| 1012 |
=item B<-command> =E<gt> I<callback> |
| 1013 |
|
| 1014 |
Instead of returning the information as the result of the dump operation, |
| 1015 |
invoke the I<callback> on each element of the text widget within the range. |
| 1016 |
The callback has three arguments appended to it before it is evaluated: |
| 1017 |
the I<key>, I<value>, and I<index>. |
| 1018 |
|
| 1019 |
=item B<-mark> |
| 1020 |
|
| 1021 |
Include information about marks in the dump results. |
| 1022 |
|
| 1023 |
=item B<-tag> |
| 1024 |
|
| 1025 |
Include information about tag transitions in the dump results. Tag information is |
| 1026 |
returned as B<tagon> and B<tagoff> elements that indicate the |
| 1027 |
begin and end of each range of each tag, respectively. |
| 1028 |
|
| 1029 |
=item B<-text> |
| 1030 |
|
| 1031 |
Include information about text in the dump results. The value is the |
| 1032 |
text up to the next element or the end of range indicated by I<index2>. |
| 1033 |
A text element does not span newlines. A multi-line block of text that |
| 1034 |
contains no marks or tag transitions will still be dumped as a set |
| 1035 |
of text seqments that each end with a newline. The newline is part |
| 1036 |
of the value. |
| 1037 |
|
| 1038 |
=item B<-window> |
| 1039 |
|
| 1040 |
=back |
| 1041 |
|
| 1042 |
Include information about embedded windows in the dump results. |
| 1043 |
The value of a window is its Tk pathname, unless the window |
| 1044 |
has not been created yet. (It must have a create script.) |
| 1045 |
In this case an empty string is returned, and you must query the |
| 1046 |
window by its index position to get more information. |
| 1047 |
|
| 1048 |
=item I<$text>-E<gt>B<edit>( I< option, ?arg, arg ...?> ); |
| 1049 |
|
| 1050 |
This command controls the undo mechanism and the modified flag. |
| 1051 |
The exact behavior of the command depends on the option argument |
| 1052 |
that follows the edit argument. The following forms of the command |
| 1053 |
are currently supported: |
| 1054 |
|
| 1055 |
=over 4 |
| 1056 |
|
| 1057 |
=item I<$text>-E<gt>B<editModified>( ?boolean? ); |
| 1058 |
|
| 1059 |
If boolean is not specified, returns the modified flag of |
| 1060 |
the widget. The insert, delete, edit undo and edit redo |
| 1061 |
commands or the user can set or clear the modified flag. |
| 1062 |
If boolean is specified, sets the modified flag of the |
| 1063 |
widget to boolean. |
| 1064 |
|
| 1065 |
=item I<$text>-E<gt>B<editRedo>; |
| 1066 |
|
| 1067 |
(Not implemented, use B<TextUndo>.) When the B<-undo> option is true, |
| 1068 |
reapplies the last undone edits provided no other edits were done |
| 1069 |
since then. Generates an error when the redo stack is empty. Does |
| 1070 |
nothing when the B<-undo> option is false. |
| 1071 |
|
| 1072 |
=item I<$text>-E<gt>B<editReset>; |
| 1073 |
|
| 1074 |
(Not implemented, use B<TextUndo>.) Clears the undo and redo stacks. |
| 1075 |
|
| 1076 |
=item I<$text>-E<gt>B<editSeparator>; |
| 1077 |
|
| 1078 |
(Not implemented, use B<TextUndo>.) Inserts a separator (boundary) on |
| 1079 |
the undo stack. Does nothing when the -undo option is false. |
| 1080 |
|
| 1081 |
=item I<$text>-E<gt>B<editUndo>; |
| 1082 |
|
| 1083 |
(Not implemented, use B<TextUndo>.) Undoes the last edit action when |
| 1084 |
the -undo option is true. An edit action is defined as all the insert |
| 1085 |
and delete commands that are recorded on the undo stack in between two |
| 1086 |
separators. Generates an error when the undo stack is empty. Does |
| 1087 |
nothing when the -undo option is false. |
| 1088 |
|
| 1089 |
=back |
| 1090 |
|
| 1091 |
=item I<$text>-E<gt>B<FindAll>(I<mode, case, pattern>) |
| 1092 |
|
| 1093 |
Removes any current selections and then performs a global text |
| 1094 |
search. All matches are tagged with the B<sel> tag. |
| 1095 |
|
| 1096 |
I<mode> can be be B<-exact> or B<-regexp>. See the B<search> command |
| 1097 |
for more information |
| 1098 |
|
| 1099 |
I<case> can be B<-nocase> or B<-case>. See the B<search> command |
| 1100 |
for more information |
| 1101 |
|
| 1102 |
I<pattern> is an exact string to match if I<mode> is B<-exact> or a |
| 1103 |
regular expression if the match I<mode> is B<-regexp>. |
| 1104 |
|
| 1105 |
|
| 1106 |
=item I<$text>-E<gt>B<FindAndReplaceAll>(I<mode, case, find, replace>) |
| 1107 |
|
| 1108 |
Same as the B<FindAll> method, however additionally substitutes the |
| 1109 |
matched text with the characters I<replace>. |
| 1110 |
|
| 1111 |
=item I<$text>-E<gt>B<FindAndReplacePopUp> |
| 1112 |
|
| 1113 |
Creates a find-and-replace popup window if one does not already exist. |
| 1114 |
If there is currently selected text, then the 'find' field will be |
| 1115 |
'pre-filled' with the selection. |
| 1116 |
|
| 1117 |
=item I<$text>-E<gt>B<FindNext>(I<direction, mode, case, pattern>) |
| 1118 |
|
| 1119 |
Removes any current selections and then performs a forward or reverse |
| 1120 |
text search. All matches are tagged with the B<sel> tag. I<direction> |
| 1121 |
can be B<-forwards> or B<-backwards>. I<mode, case> and I<pattern> are |
| 1122 |
as for the B<FindAll> method. |
| 1123 |
|
| 1124 |
=item I<$text>-E<gt>B<FindPopUp> |
| 1125 |
|
| 1126 |
Creates a find popup, if one does not yet exist. If there is currently |
| 1127 |
selected text, then the 'find' field will be 'pre-filled' with the |
| 1128 |
selection. |
| 1129 |
|
| 1130 |
=item I<$text>-E<gt>B<FindSelectionNext> |
| 1131 |
|
| 1132 |
Gets the currently selected text and removes all selections. It then |
| 1133 |
finds the next exact, case-sensitive string that matches in a forward |
| 1134 |
direction and selects the text and makes the new selection visible. |
| 1135 |
|
| 1136 |
=item I<$text>-E<gt>B<FindSelectionPrevious> |
| 1137 |
|
| 1138 |
Gets the currently selected text and removes all selections. It then |
| 1139 |
finds the next exact, case-sensitive string that matches in a reverse |
| 1140 |
direction and selects the text and makes the new selection visible. |
| 1141 |
|
| 1142 |
=item I<$text>-E<gt>B<get>(I<index1, >?I<index2>?) |
| 1143 |
|
| 1144 |
Return a range of characters from the text. The return value will be |
| 1145 |
all the characters in the text starting with the one whose index is |
| 1146 |
I<index1> and ending just before the one whose index is I<index2> (the |
| 1147 |
character at I<index2> will not be returned). If I<index2> is omitted |
| 1148 |
then the single character at I<index1> is returned. If there are no |
| 1149 |
characters in the specified range (e.g. I<index1> is past the end of |
| 1150 |
the file or I<index2> is less than or equal to I<index1>) then an |
| 1151 |
empty string is returned. If the specified range contains embedded |
| 1152 |
windows, no information about them is included in the returned string. |
| 1153 |
If multiple index pairs are given, multiple ranges of text will be |
| 1154 |
returned in a list. Invalid ranges will not be represented with empty |
| 1155 |
strings in the list. The ranges are returned in the order passed to |
| 1156 |
B<get>. |
| 1157 |
|
| 1158 |
=item I<$text>-E<gt>B<getSelected> |
| 1159 |
|
| 1160 |
Return the currently selected text. |
| 1161 |
|
| 1162 |
=item I<$text>-E<gt>B<GetTextTaggedWith>(I<tag>) |
| 1163 |
|
| 1164 |
Return the text tagged with the I<tag> parameter. |
| 1165 |
|
| 1166 |
=item I<$text>-E<gt>B<GotoLineNumber>(I<line_number>) |
| 1167 |
|
| 1168 |
Set the insert mark to I<line_number> and ensures the line is |
| 1169 |
visible. |
| 1170 |
|
| 1171 |
=item I<$text>-E<gt>B<GotoLineNumberPopUp>(I<line_number>) |
| 1172 |
|
| 1173 |
Displays a popup, pre-filling it with selected numeric text |
| 1174 |
(if any), or the line number from B<GotoLineNumber> (if any). |
| 1175 |
|
| 1176 |
=item I<$text>-E<gt>B<image>(I<option>, ?I<arg, arg, ...>?) |
| 1177 |
|
| 1178 |
=item I<$text>-E<gt>B<image>I<Option>(?I<arg, arg, ...>?) |
| 1179 |
|
| 1180 |
This method is used to manipulate embedded images. |
| 1181 |
The behavior of the method depends on the I<option> argument |
| 1182 |
that follows the B<image> prefix. |
| 1183 |
The following forms of the methods are currently supported: |
| 1184 |
|
| 1185 |
=over 8 |
| 1186 |
|
| 1187 |
=item I<$text>-E<gt>B<imageCget>(I<index, option>) |
| 1188 |
|
| 1189 |
Returns the value of a configuration option for an embedded image. |
| 1190 |
I<Index> identifies the embedded image, and I<option> |
| 1191 |
specifies a particular configuration option, which must be one of |
| 1192 |
the ones listed in L<"EMBEDDED IMAGES">. |
| 1193 |
|
| 1194 |
=item I<$text>-E<gt>B<imageConfigure>(I<index, >?I<option, value, ...>?) |
| 1195 |
|
| 1196 |
Query or modify the configuration options for an embedded image. |
| 1197 |
If no I<option> is specified, returns a list describing all of |
| 1198 |
the available options for the embedded image at I<index> |
| 1199 |
(see L<Tk::options> for information on the format of this list). |
| 1200 |
If I<option> is specified with no I<value>, then the command |
| 1201 |
returns a list describing the one named option (this list will be |
| 1202 |
identical to the corresponding sublist of the value returned if no |
| 1203 |
I<option> is specified). |
| 1204 |
If one or more I<option-value> pairs are specified, then the command |
| 1205 |
modifies the given option(s) to have the given value(s); in |
| 1206 |
this case the command returns an empty string. |
| 1207 |
See L<"EMBEDDED IMAGES"> for information on the options that |
| 1208 |
are supported. |
| 1209 |
|
| 1210 |
=item I<$text>-E<gt>B<imageCreate>(I<index, >?I<option, value, ...>?) |
| 1211 |
|
| 1212 |
This command creates a new image annotation, which will appear |
| 1213 |
in the text at the position given by I<index>. |
| 1214 |
Any number of I<option-value> pairs may be specified to |
| 1215 |
configure the annotation. |
| 1216 |
Returns a unique identifier that may be used as an index to refer to |
| 1217 |
this image. |
| 1218 |
See L<"EMBEDDED IMAGES"> for information on the options that |
| 1219 |
are supported, and a description of the identifier returned. |
| 1220 |
|
| 1221 |
=item I<$text>-E<gt>B<imageNames> |
| 1222 |
|
| 1223 |
Returns a list whose elements are the names of all image instances currently |
| 1224 |
embedded in $text. |
| 1225 |
|
| 1226 |
=back |
| 1227 |
|
| 1228 |
=item I<$text>-E<gt>B<index>(I<index>) |
| 1229 |
|
| 1230 |
Returns the position corresponding to I<index> in the form |
| 1231 |
I<line.char> where I<line> is the line number and I<char> |
| 1232 |
is the character number. |
| 1233 |
I<Index> may have any of the forms described under L<"INDICES"> above. |
| 1234 |
|
| 1235 |
=item I<$text>-E<gt>B<insert>(I<index, chars, >?I<tagList, chars, tagList, ...>?) |
| 1236 |
|
| 1237 |
Inserts all of the I<chars> arguments just before the character at |
| 1238 |
I<index>. |
| 1239 |
If I<index> refers to the end of the text (the character after |
| 1240 |
the last newline) then the new text is inserted just before the |
| 1241 |
last newline instead. |
| 1242 |
If there is a single I<chars> argument and no I<tagList>, then |
| 1243 |
the new text will receive any tags that are present on both the |
| 1244 |
character before and the character after the insertion point; if a tag |
| 1245 |
is present on only one of these characters then it will not be |
| 1246 |
applied to the new text. |
| 1247 |
If I<tagList> is specified then it consists of a list of |
| 1248 |
tag names; the new characters will receive all of the tags in |
| 1249 |
this list and no others, regardless of the tags present around |
| 1250 |
the insertion point. |
| 1251 |
If multiple I<chars>-I<tagList> argument pairs are present, |
| 1252 |
they produce the same effect as if a separate B<insert> widget |
| 1253 |
command had been issued for each pair, in order. |
| 1254 |
The last I<tagList> argument may be omitted. |
| 1255 |
|
| 1256 |
=item I<$text>-E<gt>B<Insert>(I<string>) |
| 1257 |
|
| 1258 |
Do NOT confuse this with the lower-case B<insert> method. |
| 1259 |
Insert I<string> at the point of the insertion cursor. If there is |
| 1260 |
a selection in the text, and it covers the point of the insertion |
| 1261 |
cursor, then it deletes the selection before inserting. |
| 1262 |
|
| 1263 |
=item I<$text>-E<gt>B<InsertKeypress>(I<character>) |
| 1264 |
|
| 1265 |
Inserts I<character> at the B<insert> mark. If in overstrike mode, |
| 1266 |
it firsts deletes the character at the B<insert> mark. |
| 1267 |
|
| 1268 |
=item I<$text>-E<gt>B<InsertSelection> |
| 1269 |
|
| 1270 |
Inserts the current selection at the B<insert> mark. |
| 1271 |
|
| 1272 |
=item I<$text>-E<gt>B<insertTab> |
| 1273 |
|
| 1274 |
Inserts a tab (\t) character at the B<insert> mark. |
| 1275 |
|
| 1276 |
=item I<$text>-E<gt>B<mark>(I<option, >?I<arg, arg, ...>?) |
| 1277 |
|
| 1278 |
This command is used to manipulate marks. The exact behavior of |
| 1279 |
the command depends on the I<option> argument that follows |
| 1280 |
the B<mark> argument. The following forms of the command |
| 1281 |
are currently supported: |
| 1282 |
|
| 1283 |
=over 8 |
| 1284 |
|
| 1285 |
=item I<$text>-E<gt>B<markGravity>(I<markName, >?I<direction>?) |
| 1286 |
|
| 1287 |
If I<direction> is not specified, returns B<left> or B<right> |
| 1288 |
to indicate which of its adjacent characters I<markName> is attached |
| 1289 |
to. |
| 1290 |
If I<direction> is specified, it must be B<left> or B<right>; |
| 1291 |
the gravity of I<markName> is set to the given value. |
| 1292 |
|
| 1293 |
=item I<$text>-E<gt>B<markNames> |
| 1294 |
|
| 1295 |
Returns a list whose elements are the names of all the marks that |
| 1296 |
are currently set. |
| 1297 |
|
| 1298 |
=item I<$text>-E<gt>B<markNext>(I<index>) |
| 1299 |
|
| 1300 |
Returns the name of the next mark at or after I<index>. |
| 1301 |
If I<index> is specified in numerical form, then the search for |
| 1302 |
the next mark begins at that index. |
| 1303 |
If I<index> is the name of a mark, then the search for |
| 1304 |
the next mark begins immediately after that mark. |
| 1305 |
This can still return a mark at the same position if |
| 1306 |
there are multiple marks at the same index. |
| 1307 |
These semantics mean that the B<mark next> operation can be used to |
| 1308 |
step through all the marks in a text widget in the same order |
| 1309 |
as the mark information returned by the B<dump> operation. |
| 1310 |
If a mark has been set to the special B<end> index, |
| 1311 |
then it appears to be I<after> B<end> with respect to the B<mark next> operation. |
| 1312 |
An empty string is returned if there are no marks after I<index>. |
| 1313 |
|
| 1314 |
=item I<$text>-E<gt>B<markPrevious>(I<index>) |
| 1315 |
|
| 1316 |
Returns the name of the mark at or before I<index>. |
| 1317 |
If I<index> is specified in numerical form, then the search for |
| 1318 |
the previous mark begins with the character just before that index. |
| 1319 |
If I<index> is the name of a mark, then the search for |
| 1320 |
the next mark begins immediately before that mark. |
| 1321 |
This can still return a mark at the same position if |
| 1322 |
there are multiple marks at the same index. |
| 1323 |
These semantics mean that the B<mark previous> operation can be used to |
| 1324 |
step through all the marks in a text widget in the reverse order |
| 1325 |
as the mark information returned by the B<dump> operation. |
| 1326 |
An empty string is returned if there are no marks before I<index>. |
| 1327 |
|
| 1328 |
=item I<$text>-E<gt>B<markSet>(I<markName, index>) |
| 1329 |
|
| 1330 |
Sets the mark named I<markName> to a position just before the |
| 1331 |
character at I<index>. |
| 1332 |
If I<markName> already exists, it is moved from its old position; |
| 1333 |
if it doesn't exist, a new mark is created. |
| 1334 |
This command returns an empty string. |
| 1335 |
|
| 1336 |
=item I<$text>-E<gt>B<markUnset>(I<markName>?, I<markName, markName, ...>?) |
| 1337 |
|
| 1338 |
Remove the mark corresponding to each of the I<markName> arguments. |
| 1339 |
The removed marks will not be usable in indices and will not be |
| 1340 |
returned by future calls to ``I<$text>-E<gt>B<markNames>''. |
| 1341 |
This command returns an empty string. |
| 1342 |
|
| 1343 |
=back |
| 1344 |
|
| 1345 |
=item I<$text>-E<gt>B<markExists>(I<markname>) |
| 1346 |
|
| 1347 |
Returns true if I<markname> exists - false otherwise. |
| 1348 |
|
| 1349 |
=item I<$text>-E<gt>B<menu>(I<?menu?>) |
| 1350 |
|
| 1351 |
If I<menu> reference is given as an argument, then the text widget |
| 1352 |
menu is adjusted to use this new I<menu>. If the I<menu> argument |
| 1353 |
is B<undef>, then this command disables the current text widget menu. |
| 1354 |
If the I<menu> argument is omitted altogether, then the current text |
| 1355 |
widget menu reference is returned. |
| 1356 |
|
| 1357 |
=item I<$text>-E<gt>B<openLine> |
| 1358 |
|
| 1359 |
Inserts a newline (\n) at the insert mark. |
| 1360 |
|
| 1361 |
=item I<$text>-E<gt>B<OverstrikeMode>(I<?boolean?>) |
| 1362 |
|
| 1363 |
Returns the overstrike mode if I<boolean> is omitted or sets the |
| 1364 |
overstrike mode to I<boolean>. True means overstrike mode is enabled. |
| 1365 |
|
| 1366 |
=item I<$text>-E<gt>B<PostPopupMenu>(I<x,y>) |
| 1367 |
|
| 1368 |
Creates a popup menu at the specified (I<x,y>) pixel coordinates. The |
| 1369 |
default menu has File, Edit, Search and View menu items which cascade |
| 1370 |
to sub-menus for further commands. There is an implicit E<lt>Button-3E<gt> |
| 1371 |
binding to this method that posts the menu over the cursor. |
| 1372 |
|
| 1373 |
=item I<$text>-E<gt>B<ResetAnchor> |
| 1374 |
|
| 1375 |
Sets the selection anchor to whichever end is farthest from the index |
| 1376 |
argument. |
| 1377 |
|
| 1378 |
=item I<$text>-E<gt>B<scan>(I<option>, I<args>) or |
| 1379 |
|
| 1380 |
=item I<$text>-E<gt>B<scan>I<option>(I<args>) |
| 1381 |
|
| 1382 |
This method is used to implement scanning on texts. It has |
| 1383 |
two forms, depending on I<option>: |
| 1384 |
|
| 1385 |
=over 8 |
| 1386 |
|
| 1387 |
=item I<$text>-E<gt>B<scanMark>(I<x, y>) |
| 1388 |
|
| 1389 |
Records I<x> and I<y> and the current view in the text window, |
| 1390 |
for use in conjunction with later B<scanDragto> method. |
| 1391 |
Typically this method is associated with a mouse button press in |
| 1392 |
the widget. It returns an empty string. |
| 1393 |
|
| 1394 |
=item I<$text>-E<gt>B<scanDragto>(I<x, y>) |
| 1395 |
|
| 1396 |
This command computes the difference between its I<x> and I<y> |
| 1397 |
arguments and the I<x> and I<y> arguments to the last |
| 1398 |
B<scanMark> method for the widget. |
| 1399 |
It then adjusts the view by 10 times the difference in coordinates. |
| 1400 |
This command is typically associated |
| 1401 |
with mouse motion events in the widget, to produce the effect of |
| 1402 |
dragging the text at high speed through the window. The return |
| 1403 |
value is an empty string. |
| 1404 |
|
| 1405 |
=back |
| 1406 |
|
| 1407 |
=item I<$text>-E<gt>B<search>(?I<switches>,? I<pattern, index, >?I<stopIndex>?) |
| 1408 |
|
| 1409 |
Searches the text in I<$text> starting at I<index> for a range |
| 1410 |
of characters that matches I<pattern>. |
| 1411 |
If a match is found, the index of the first character in the match is |
| 1412 |
returned as result; otherwise an empty string is returned. |
| 1413 |
One or more of the following switches (or abbreviations thereof) |
| 1414 |
may be specified to control the search: |
| 1415 |
|
| 1416 |
=over 8 |
| 1417 |
|
| 1418 |
=item B<-forwards> |
| 1419 |
|
| 1420 |
The search will proceed forward through the text, finding the first |
| 1421 |
matching range starting at or after the position given by I<index>. |
| 1422 |
This is the default. |
| 1423 |
|
| 1424 |
=item B<-backwards> |
| 1425 |
|
| 1426 |
The search will proceed backward through the text, finding the |
| 1427 |
matching range closest to I<index> whose first character |
| 1428 |
is before I<index>. |
| 1429 |
|
| 1430 |
=item B<-exact> |
| 1431 |
|
| 1432 |
Use exact matching: the characters in the matching range must be |
| 1433 |
identical to those in I<pattern>. |
| 1434 |
This is the default. |
| 1435 |
|
| 1436 |
=item B<-regexp> |
| 1437 |
|
| 1438 |
Treat I<pattern> as a regular expression and match it against |
| 1439 |
the text using the rules for regular expressions (see the B<regexp> |
| 1440 |
command for details). |
| 1441 |
|
| 1442 |
=item B<-nocase> |
| 1443 |
|
| 1444 |
Ignore case differences between the pattern and the text. |
| 1445 |
|
| 1446 |
=item B<-count>I< varName> |
| 1447 |
|
| 1448 |
The argument following B<-count> gives the name of a variable; |
| 1449 |
if a match is found, the number of characters in the matching |
| 1450 |
range will be stored in the variable. |
| 1451 |
|
| 1452 |
=item B<-hidden> |
| 1453 |
|
| 1454 |
Find hidden text as well. By default only displayed text is found. |
| 1455 |
|
| 1456 |
=item B<--> |
| 1457 |
|
| 1458 |
This switch has no effect except to terminate the list of switches: |
| 1459 |
the next argument will be treated as I<pattern> even if it starts |
| 1460 |
with B<->. |
| 1461 |
|
| 1462 |
=back |
| 1463 |
|
| 1464 |
=back |
| 1465 |
|
| 1466 |
The matching range must be entirely within a single line of text. |
| 1467 |
For regular expression matching the newlines are removed from the ends |
| 1468 |
of the lines before matching: use the B<$> feature in regular |
| 1469 |
expressions to match the end of a line. |
| 1470 |
For exact matching the newlines are retained. |
| 1471 |
If I<stopIndex> is specified, the search stops at that index: |
| 1472 |
for forward searches, no match at or after I<stopIndex> will |
| 1473 |
be considered; for backward searches, no match earlier in the |
| 1474 |
text than I<stopIndex> will be considered. |
| 1475 |
If I<stopIndex> is omitted, the entire text will be searched: |
| 1476 |
when the beginning or end of the text is reached, the search |
| 1477 |
continues at the other end until the starting location is reached |
| 1478 |
again; if I<stopIndex> is specified, no wrap-around will occur. |
| 1479 |
|
| 1480 |
=over 4 |
| 1481 |
|
| 1482 |
=item I<$text>-E<gt>B<see>(I<index>) |
| 1483 |
|
| 1484 |
Adjusts the view in the window so that the character given by I<index> |
| 1485 |
is completely visible. |
| 1486 |
If I<index> is already visible then the command does nothing. |
| 1487 |
If I<index> is a short distance out of view, the command |
| 1488 |
adjusts the view just enough to make I<index> visible at the |
| 1489 |
edge of the window. |
| 1490 |
If I<index> is far out of view, then the command centers |
| 1491 |
I<index> in the window. |
| 1492 |
|
| 1493 |
=item I<$text>-E<gt>B<selectAll> |
| 1494 |
|
| 1495 |
Selects all the text in the widget. |
| 1496 |
|
| 1497 |
=item I<$text>-E<gt>B<selectLine> |
| 1498 |
|
| 1499 |
Selects the line with the insert mark. |
| 1500 |
|
| 1501 |
=item I<$text>-E<gt>B<selectWord> |
| 1502 |
|
| 1503 |
Selects the word with the insert mark. |
| 1504 |
|
| 1505 |
=item I<$text>-E<gt>B<SetCursor>(I<position>) |
| 1506 |
|
| 1507 |
Moves the insert mark to I<position>. |
| 1508 |
|
| 1509 |
=item I<$text>-E<gt>B<tag>(I<option, >?I<arg, arg, ...>?) |
| 1510 |
|
| 1511 |
This command is used to manipulate tags. The exact behavior of the |
| 1512 |
command depends on the I<option> argument that follows the |
| 1513 |
B<tag> argument. The following forms of the command are currently |
| 1514 |
supported: |
| 1515 |
|
| 1516 |
=over 8 |
| 1517 |
|
| 1518 |
=item I<$text>-E<gt>B<tagAdd>(I<tagName, index1, >?I<index2, index1, index2, ...>?) |
| 1519 |
|
| 1520 |
Associate the tag I<tagName> with all of the characters starting |
| 1521 |
with I<index1> and ending just before |
| 1522 |
I<index2> (the character at I<index2> isn't tagged). |
| 1523 |
A single command may contain any number of I<index1>-I<index2> |
| 1524 |
pairs. |
| 1525 |
If the last I<index2> is omitted then the single character at |
| 1526 |
I<index1> is tagged. |
| 1527 |
If there are no characters in the specified range (e.g. I<index1> |
| 1528 |
is past the end of the file or I<index2> is less than or equal |
| 1529 |
to I<index1>) then the command has no effect. |
| 1530 |
|
| 1531 |
=item I<$text>-E<gt>B<tagBind>(I<tagName, >?I<sequence>?, ?I<script>?) |
| 1532 |
|
| 1533 |
This command associates I<script> with the tag given by |
| 1534 |
I<tagName>. |
| 1535 |
Whenever the event sequence given by I<sequence> occurs for a |
| 1536 |
character that has been tagged with I<tagName>, |
| 1537 |
the script will be invoked. |
| 1538 |
This method is similar to the B<bind> command except that |
| 1539 |
it operates on characters in a text rather than entire widgets. |
| 1540 |
See the L<Tk::bind> documentation for complete details |
| 1541 |
on the syntax of I<sequence> and the substitutions performed |
| 1542 |
on I<script> before invoking it. |
| 1543 |
If all arguments are specified then a new binding is created, replacing |
| 1544 |
any existing binding for the same I<sequence> and I<tagName> |
| 1545 |
(if the first character of I<script> is ``+'' then I<script> |
| 1546 |
augments an existing binding rather than replacing it). |
| 1547 |
In this case the return value is an empty string. |
| 1548 |
If I<script> is omitted then the command returns the I<script> |
| 1549 |
associated with I<tagName> and I<sequence> (an error occurs |
| 1550 |
if there is no such binding). |
| 1551 |
If both I<script> and I<sequence> are omitted then the command |
| 1552 |
returns a list of all the sequences for which bindings have been |
| 1553 |
defined for I<tagName>. |
| 1554 |
|
| 1555 |
The only events for which bindings may be specified are those related |
| 1556 |
to the mouse and keyboard (such as B<Enter>, B<Leave>, |
| 1557 |
B<ButtonPress>, B<Motion>, and B<KeyPress>) or virtual events. |
| 1558 |
Event bindings for a text widget use the B<current> mark described |
| 1559 |
under L<"MARKS"> above. An B<Enter> event triggers for a tag when the tag |
| 1560 |
first becomes present on the current character, and a B<Leave> event |
| 1561 |
triggers for a tag when it ceases to be present on the current character. |
| 1562 |
B<Enter> and B<Leave> events can happen either because the |
| 1563 |
B<current> mark moved or because the character at that position |
| 1564 |
changed. Note that these events are different than B<Enter> and |
| 1565 |
B<Leave> events for windows. Mouse and keyboard events are directed |
| 1566 |
to the current character. If a virtual event is used in a binding, that |
| 1567 |
binding can trigger only if the virtual event is defined by an underlying |
| 1568 |
mouse-related or keyboard-related event. |
| 1569 |
|
| 1570 |
It is possible for the current character to have multiple tags, |
| 1571 |
and for each of them to have a binding for a particular event |
| 1572 |
sequence. |
| 1573 |
When this occurs, one binding is invoked for each tag, in order |
| 1574 |
from lowest-priority to highest priority. |
| 1575 |
If there are multiple matching bindings for a single tag, then |
| 1576 |
the most specific binding is chosen (see the the documentation for |
| 1577 |
the B<bind> command for details). |
| 1578 |
B<continue> and B<break> commands within binding scripts |
| 1579 |
are processed in the same way as for bindings created with |
| 1580 |
the B<bind> command. |
| 1581 |
|
| 1582 |
If bindings are created for the widget as a whole using the |
| 1583 |
B<bind> command, then those bindings will supplement the |
| 1584 |
tag bindings. |
| 1585 |
The tag bindings will be invoked first, followed by bindings |
| 1586 |
for the window as a whole. |
| 1587 |
|
| 1588 |
=item I<$text>-E<gt>B<tagCget>(I<tagName, option>) |
| 1589 |
|
| 1590 |
This command returns the current value of the option named I<option> |
| 1591 |
associated with the tag given by I<tagName>. |
| 1592 |
I<Option> may have any of the values accepted by the B<tag configure> |
| 1593 |
method. |
| 1594 |
|
| 1595 |
=item I<$text>-E<gt>B<tagConfigure>(I<tagName, >?I<option>?, ?I<value>?, ?I<option, value, ...>?) |
| 1596 |
|
| 1597 |
This command is similar to the B<configure> method except |
| 1598 |
that it modifies options associated with the tag given by I<tagName> |
| 1599 |
instead of modifying options for the overall text widget. |
| 1600 |
If no I<option> is specified, the command returns a list describing |
| 1601 |
all of the available options for I<tagName> |
| 1602 |
(see L<Tk::options> for information on the format of this list). |
| 1603 |
If I<option> is specified with no I<value>, then the command returns |
| 1604 |
a list describing the one named option (this list will be identical to |
| 1605 |
the corresponding sublist of the value returned if no I<option> |
| 1606 |
is specified). |
| 1607 |
If one or more I<option-value> pairs are specified, then the command |
| 1608 |
modifies the given option(s) to have the given value(s) in I<tagName>; |
| 1609 |
in this case the command returns an empty string. |
| 1610 |
See L<"TAGS"> above for details on the options available for tags. |
| 1611 |
|
| 1612 |
=item I<$text>-E<gt>B<tagDelete>(I<tagName, >?I<tagName, ...>?) |
| 1613 |
|
| 1614 |
Deletes all tag information for each of the I<tagName> |
| 1615 |
arguments. |
| 1616 |
The command removes the tags from all characters in the file |
| 1617 |
and also deletes any other information associated with the tags, |
| 1618 |
such as bindings and display information. |
| 1619 |
The command returns an empty string. |
| 1620 |
|
| 1621 |
=item I<$text>-E<gt>B<tagLower>(I<tagName>?, I<belowThis>?) |
| 1622 |
|
| 1623 |
Changes the priority of tag I<tagName> so that it is just lower |
| 1624 |
in priority than the tag whose name is I<belowThis>. |
| 1625 |
If I<belowThis> is omitted, then I<tagName>'s priority |
| 1626 |
is changed to make it lowest priority of all tags. |
| 1627 |
|
| 1628 |
=item I<$text>-E<gt>B<tagNames>(?I<index>?) |
| 1629 |
|
| 1630 |
Returns a list whose elements are the names of all the tags that |
| 1631 |
are active at the character position given by I<index>. |
| 1632 |
If I<index> is omitted, then the return value will describe |
| 1633 |
all of the tags that exist for the text (this includes all tags |
| 1634 |
that have been named in a ``I<$text>-E<gt>B<tag>'' widget |
| 1635 |
command but haven't been deleted by a ``I<$text>-E<gt>B<tagDelete>'' |
| 1636 |
method, even if no characters are currently marked with |
| 1637 |
the tag). |
| 1638 |
The list will be sorted in order from lowest priority to highest |
| 1639 |
priority. |
| 1640 |
|
| 1641 |
=item I<$text>-E<gt>B<tagNextrange>(I<tagName, index1, >?I<index2>?) |
| 1642 |
|
| 1643 |
This command searches the text for a range of characters tagged |
| 1644 |
with I<tagName> where the first character of the range is |
| 1645 |
no earlier than the character at I<index1> and no later than |
| 1646 |
the character just before I<index2> (a range starting at |
| 1647 |
I<index2> will not be considered). |
| 1648 |
If several matching ranges exist, the first one is chosen. |
| 1649 |
The command's return value is a list containing |
| 1650 |
two elements, which are the index of the first character of the |
| 1651 |
range and the index of the character just after the last one in |
| 1652 |
the range. |
| 1653 |
If no matching range is found then the return value is an |
| 1654 |
empty string. |
| 1655 |
If I<index2> is not given then it defaults to the end of the text. |
| 1656 |
|
| 1657 |
=item I<$text>-E<gt>B<tagPrevrange>(I<tagName, index1, >?I<index2>?) |
| 1658 |
|
| 1659 |
This command searches the text for a range of characters tagged |
| 1660 |
with I<tagName> where the first character of the range is |
| 1661 |
before the character at I<index1> and no earlier than |
| 1662 |
the character at I<index2> (a range starting at |
| 1663 |
I<index2> will be considered). |
| 1664 |
If several matching ranges exist, the one closest to I<index1> is chosen. |
| 1665 |
The command's return value is a list containing |
| 1666 |
two elements, which are the index of the first character of the |
| 1667 |
range and the index of the character just after the last one in |
| 1668 |
the range. |
| 1669 |
If no matching range is found then the return value is an |
| 1670 |
empty string. |
| 1671 |
If I<index2> is not given then it defaults to the beginning of the text. |
| 1672 |
|
| 1673 |
=item I<$text>-E<gt>B<tagRaise>(I<tagName, >?I<aboveThis>?) |
| 1674 |
|
| 1675 |
Changes the priority of tag I<tagName> so that it is just higher |
| 1676 |
in priority than the tag whose name is I<aboveThis>. |
| 1677 |
If I<aboveThis> is omitted, then I<tagName>'s priority |
| 1678 |
is changed to make it highest priority of all tags. |
| 1679 |
|
| 1680 |
=item I<$text>-E<gt>B<tagRanges>(I<tagName>) |
| 1681 |
|
| 1682 |
Returns a list describing all of the ranges of text that have been |
| 1683 |
tagged with I<tagName>. |
| 1684 |
The first two elements of the list describe the first tagged range |
| 1685 |
in the text, the next two elements describe the second range, and |
| 1686 |
so on. |
| 1687 |
The first element of each pair contains the index of the first |
| 1688 |
character of the range, and the second element of the pair contains |
| 1689 |
the index of the character just after the last one in the |
| 1690 |
range. |
| 1691 |
If there are no characters tagged with I<tag> then an |
| 1692 |
empty string is returned. |
| 1693 |
|
| 1694 |
=item I<$text>-E<gt>B<tagRemove>(I<tagName, index1, >?I<index2, index1, index2, ...>?) |
| 1695 |
|
| 1696 |
Remove the tag I<tagName> from all of the characters starting |
| 1697 |
at I<index1> and ending just before |
| 1698 |
I<index2> (the character at I<index2> isn't affected). |
| 1699 |
A single command may contain any number of I<index1>-I<index2> |
| 1700 |
pairs. |
| 1701 |
If the last I<index2> is omitted then the single character at |
| 1702 |
I<index1> is tagged. |
| 1703 |
If there are no characters in the specified range (e.g. I<index1> |
| 1704 |
is past the end of the file or I<index2> is less than or equal |
| 1705 |
to I<index1>) then the command has no effect. |
| 1706 |
This command returns an empty string. |
| 1707 |
|
| 1708 |
=back |
| 1709 |
|
| 1710 |
=item I<$text>-E<gt>B<ToggleInsertMode> |
| 1711 |
|
| 1712 |
Toggles the current overstrike mode. |
| 1713 |
|
| 1714 |
=item I<$text>-E<gt>B<unselectAll> |
| 1715 |
|
| 1716 |
Unselects all the text in the widget. |
| 1717 |
|
| 1718 |
=item I<$text>-E<gt>B<WhatLineNumberPopup> |
| 1719 |
|
| 1720 |
Creates a popup that displays the current line number of the |
| 1721 |
insert mark. |
| 1722 |
|
| 1723 |
=item I<$text>->B<widget>(I<option?, arg, arg, ...>?) |
| 1724 |
|
| 1725 |
=item I<$text>->B<widget>I<Option>(?I<arg, arg, ...>?) |
| 1726 |
|
| 1727 |
This method is used to manipulate embedded windows. |
| 1728 |
The behavior of the method depends on the I<option> argument |
| 1729 |
that follows the B<window> argument. |
| 1730 |
The following forms of the method are currently supported: |
| 1731 |
|
| 1732 |
=over 8 |
| 1733 |
|
| 1734 |
=item I<$text>->B<windowCget>(I<index, option>) |
| 1735 |
|
| 1736 |
Returns the value of a configuration option for an embedded window. |
| 1737 |
I<Index> identifies the embedded window, and I<option> |
| 1738 |
specifies a particular configuration option, which must be one of |
| 1739 |
the ones listed in L<"EMBEDDED WINDOWS"> above. |
| 1740 |
|
| 1741 |
=item I<$text>->B<windowConfigure>(I<index>?, I<option, value, ...>?) |
| 1742 |
|
| 1743 |
Query or modify the configuration options for an embedded window. |
| 1744 |
If no I<option> is specified, returns a list describing all of |
| 1745 |
the available options for the embedded window at I<index> |
| 1746 |
(see L<Tk::options> for information on the format of this list). |
| 1747 |
If I<option> is specified with no I<value>, then the command |
| 1748 |
returns a list describing the one named option (this list will be |
| 1749 |
identical to the corresponding sublist of the value returned if no |
| 1750 |
I<option> is specified). |
| 1751 |
If one or more I<option-value> pairs are specified, then the command |
| 1752 |
modifies the given option(s) to have the given value(s); in |
| 1753 |
this case the command returns an empty string. |
| 1754 |
See L<"EMBEDDED WINDOWS"> above for information on the options that |
| 1755 |
are supported. |
| 1756 |
|
| 1757 |
=item I<$text>->B<windowCreate>(I<index>?, I<option, value, ...>?) |
| 1758 |
|
| 1759 |
This command creates a new window annotation, which will appear |
| 1760 |
in the text at the position given by I<index>. |
| 1761 |
Any number of I<option-value> pairs may be specified to |
| 1762 |
configure the annotation. |
| 1763 |
See L<"EMBEDDED WINDOWS"> above for information on the options that |
| 1764 |
are supported. |
| 1765 |
Returns an empty string. |
| 1766 |
|
| 1767 |
=item I<$text>->B<windowNames> |
| 1768 |
|
| 1769 |
Returns a list whose elements are the names of all windows currently |
| 1770 |
embedded in $text. |
| 1771 |
|
| 1772 |
=back |
| 1773 |
|
| 1774 |
=item I<$text>->B<xview>(I<option, args>) |
| 1775 |
|
| 1776 |
This command is used to query and change the horizontal position of the |
| 1777 |
text in the widget's window. It can take any of the following |
| 1778 |
forms: |
| 1779 |
|
| 1780 |
=over 8 |
| 1781 |
|
| 1782 |
=item I<$text>->B<xview> |
| 1783 |
|
| 1784 |
Returns a list containing two elements. |
| 1785 |
Each element is a real fraction between 0 and 1; together they describe |
| 1786 |
the portion of the document's horizontal span that is visible in |
| 1787 |
the window. |
| 1788 |
For example, if the first element is .2 and the second element is .6, |
| 1789 |
20% of the text is off-screen to the left, the middle 40% is visible |
| 1790 |
in the window, and 40% of the text is off-screen to the right. |
| 1791 |
The fractions refer only to the lines that are actually visible in the |
| 1792 |
window: if the lines in the window are all very short, so that they |
| 1793 |
are entirely visible, the returned fractions will be 0 and 1, |
| 1794 |
even if there are other lines in the text that are |
| 1795 |
much wider than the window. |
| 1796 |
These are the same values passed to scrollbars via the B<-xscrollcommand> |
| 1797 |
option. |
| 1798 |
|
| 1799 |
=item I<$text>-E<gt>B<xviewMoveto>(I<fraction>) |
| 1800 |
|
| 1801 |
Adjusts the view in the window so that I<fraction> of the horizontal |
| 1802 |
span of the text is off-screen to the left. |
| 1803 |
I<Fraction> is a fraction between 0 and 1. |
| 1804 |
|
| 1805 |
=item I<$text>-E<gt>B<xviewScroll>(I<number, what>) |
| 1806 |
|
| 1807 |
This command shifts the view in the window left or right according to |
| 1808 |
I<number> and I<what>. |
| 1809 |
I<Number> must be an integer. |
| 1810 |
I<What> must be either B<units> or B<pages> or an abbreviation |
| 1811 |
of one of these. |
| 1812 |
If I<what> is B<units>, the view adjusts left or right by |
| 1813 |
I<number> average-width characters on the display; if it is |
| 1814 |
B<pages> then the view adjusts by I<number> screenfuls. |
| 1815 |
If I<number> is negative then characters farther to the left |
| 1816 |
become visible; if it is positive then characters farther to the right |
| 1817 |
become visible. |
| 1818 |
|
| 1819 |
=back |
| 1820 |
|
| 1821 |
=item I<$text>-E<gt>B<yview>(I<?args>?) |
| 1822 |
|
| 1823 |
This command is used to query and change the vertical position of the |
| 1824 |
text in the widget's window. |
| 1825 |
It can take any of the following forms: |
| 1826 |
|
| 1827 |
=over 8 |
| 1828 |
|
| 1829 |
=item I<$text>-E<gt>B<yview> |
| 1830 |
|
| 1831 |
Returns a list containing two elements, both of which are real fractions |
| 1832 |
between 0 and 1. |
| 1833 |
The first element gives the position of the first character in the |
| 1834 |
top line in the window, relative to the text as a whole (0.5 means |
| 1835 |
it is halfway through the text, for example). |
| 1836 |
The second element gives the position of the character just after |
| 1837 |
the last one in the bottom line of the window, |
| 1838 |
relative to the text as a whole. |
| 1839 |
These are the same values passed to scrollbars via the B<-yscrollcommand> |
| 1840 |
option. |
| 1841 |
|
| 1842 |
=item I<$text>-E<gt>B<yviewMoveto>(I<fraction>) |
| 1843 |
|
| 1844 |
Adjusts the view in the window so that the character given by I<fraction> |
| 1845 |
appears on the top line of the window. |
| 1846 |
I<Fraction> is a fraction between 0 and 1; 0 indicates the first |
| 1847 |
character in the text, 0.33 indicates the character one-third the |
| 1848 |
way through the text, and so on. |
| 1849 |
|
| 1850 |
=item I<$text>-E<gt>B<yviewScroll>(I<number, what>) |
| 1851 |
|
| 1852 |
This command adjust the view in the window up or down according to |
| 1853 |
I<number> and I<what>. |
| 1854 |
I<Number> must be an integer. |
| 1855 |
I<What> must be either B<units> or B<pages>. |
| 1856 |
If I<what> is B<units>, the view adjusts up or down by |
| 1857 |
I<number> lines on the display; if it is B<pages> then |
| 1858 |
the view adjusts by I<number> screenfuls. |
| 1859 |
If I<number> is negative then earlier positions in the text |
| 1860 |
become visible; if it is positive then later positions in the text |
| 1861 |
become visible. |
| 1862 |
|
| 1863 |
=item I<$text>->B<yview>(?B<-pickplace>,? I<index>) |
| 1864 |
|
| 1865 |
Changes the view in the I<$text>'s window to make I<index> visible. |
| 1866 |
If the B<-pickplace> option isn't specified then I<index> will |
| 1867 |
appear at the top of the window. |
| 1868 |
If B<-pickplace> is specified then the widget chooses where |
| 1869 |
I<index> appears in the window: |
| 1870 |
|
| 1871 |
=over 12 |
| 1872 |
|
| 1873 |
=item [1] |
| 1874 |
|
| 1875 |
If I<index> is already visible somewhere in the window then the |
| 1876 |
command does nothing. |
| 1877 |
|
| 1878 |
=item [2] |
| 1879 |
|
| 1880 |
If I<index> is only a few lines off-screen above the window then |
| 1881 |
it will be positioned at the top of the window. |
| 1882 |
|
| 1883 |
=item [3] |
| 1884 |
|
| 1885 |
If I<index> is only a few lines off-screen below the window then |
| 1886 |
it will be positioned at the bottom of the window. |
| 1887 |
|
| 1888 |
=item [4] |
| 1889 |
|
| 1890 |
Otherwise, I<index> will be centered in the window. |
| 1891 |
|
| 1892 |
=back |
| 1893 |
|
| 1894 |
=back |
| 1895 |
|
| 1896 |
=back |
| 1897 |
|
| 1898 |
The B<-pickplace> option has been obsoleted by the B<see> widget |
| 1899 |
command (B<see> handles both x- and y-motion to make a location |
| 1900 |
visible, whereas B<-pickplace> only handles motion in y). |
| 1901 |
|
| 1902 |
=over 4 |
| 1903 |
|
| 1904 |
=item I<$text>-E<gt>B<yview>(I<number>) |
| 1905 |
|
| 1906 |
This command makes the first character on the line after |
| 1907 |
the one given by I<number> visible at the top of the window. |
| 1908 |
I<Number> must be an integer. |
| 1909 |
This command used to be used for scrolling, but now it is obsolete. |
| 1910 |
|
| 1911 |
=back |
| 1912 |
|
| 1913 |
=head1 BINDINGS |
| 1914 |
|
| 1915 |
Tk automatically creates class bindings for texts that give them |
| 1916 |
the following default behavior. |
| 1917 |
In the descriptions below, ``word'' refers to a contiguous group |
| 1918 |
of letters, digits, or ``_'' characters, or any single character |
| 1919 |
other than these. |
| 1920 |
|
| 1921 |
=over 4 |
| 1922 |
|
| 1923 |
=item [1] |
| 1924 |
|
| 1925 |
Clicking mouse button 1 positions the insertion cursor |
| 1926 |
just before the character underneath the mouse cursor, sets the |
| 1927 |
input focus to this widget, and clears any selection in the widget. |
| 1928 |
Dragging with mouse button 1 strokes out a selection between |
| 1929 |
the insertion cursor and the character under the mouse. |
| 1930 |
|
| 1931 |
=item [2] |
| 1932 |
|
| 1933 |
Double-clicking with mouse button 1 selects the word under the mouse |
| 1934 |
and positions the insertion cursor at the beginning of the word. |
| 1935 |
Dragging after a double click will stroke out a selection consisting |
| 1936 |
of whole words. |
| 1937 |
|
| 1938 |
=item [3] |
| 1939 |
|
| 1940 |
Triple-clicking with mouse button 1 selects the line under the mouse |
| 1941 |
and positions the insertion cursor at the beginning of the line. |
| 1942 |
Dragging after a triple click will stroke out a selection consisting |
| 1943 |
of whole lines. |
| 1944 |
|
| 1945 |
=item [4] |
| 1946 |
|
| 1947 |
The ends of the selection can be adjusted by dragging with mouse |
| 1948 |
button 1 while the Shift key is down; this will adjust the end |
| 1949 |
of the selection that was nearest to the mouse cursor when button |
| 1950 |
1 was pressed. |
| 1951 |
If the button is double-clicked before dragging then the selection |
| 1952 |
will be adjusted in units of whole words; if it is triple-clicked |
| 1953 |
then the selection will be adjusted in units of whole lines. |
| 1954 |
|
| 1955 |
=item [5] |
| 1956 |
|
| 1957 |
Clicking mouse button 1 with the Control key down will reposition the |
| 1958 |
insertion cursor without affecting the selection. |
| 1959 |
|
| 1960 |
=item [6] |
| 1961 |
|
| 1962 |
If any normal printing characters are typed, they are |
| 1963 |
inserted at the point of the insertion cursor. |
| 1964 |
|
| 1965 |
=item [7] |
| 1966 |
|
| 1967 |
The view in the widget can be adjusted by dragging with mouse button 2. |
| 1968 |
If mouse button 2 is clicked without moving the mouse, the selection |
| 1969 |
is copied into the text at the position of the mouse cursor. |
| 1970 |
The Insert key also inserts the selection, but at the position of |
| 1971 |
the insertion cursor. |
| 1972 |
|
| 1973 |
=item [8] |
| 1974 |
|
| 1975 |
If the mouse is dragged out of the widget |
| 1976 |
while button 1 is pressed, the entry will automatically scroll to |
| 1977 |
make more text visible (if there is more text off-screen on the side |
| 1978 |
where the mouse left the window). |
| 1979 |
|
| 1980 |
=item [9] |
| 1981 |
|
| 1982 |
The Left and Right keys move the insertion cursor one character to the |
| 1983 |
left or right; they also clear any selection in the text. |
| 1984 |
If Left or Right is typed with the Shift key down, then the insertion |
| 1985 |
cursor moves and the selection is extended to include the new character. |
| 1986 |
Control-Left and Control-Right move the insertion cursor by words, and |
| 1987 |
Control-Shift-Left and Control-Shift-Right move the insertion cursor |
| 1988 |
by words and also extend the selection. |
| 1989 |
Control-b and Control-f behave the same as Left and Right, respectively. |
| 1990 |
Meta-b and Meta-f behave the same as Control-Left and Control-Right, |
| 1991 |
respectively. |
| 1992 |
|
| 1993 |
=item [10] |
| 1994 |
|
| 1995 |
The Up and Down keys move the insertion cursor one line up or |
| 1996 |
down and clear any selection in the text. |
| 1997 |
If Up or Right is typed with the Shift key down, then the insertion |
| 1998 |
cursor moves and the selection is extended to include the new character. |
| 1999 |
Control-Up and Control-Down move the insertion cursor by paragraphs (groups |
| 2000 |
of lines separated by blank lines), and |
| 2001 |
Control-Shift-Up and Control-Shift-Down move the insertion cursor |
| 2002 |
by paragraphs and also extend the selection. |
| 2003 |
Control-p and Control-n behave the same as Up and Down, respectively. |
| 2004 |
|
| 2005 |
=item [11] |
| 2006 |
|
| 2007 |
The Next and Prior keys move the insertion cursor forward or backwards |
| 2008 |
by one screenful and clear any selection in the text. |
| 2009 |
If the Shift key is held down while Next or Prior is typed, then |
| 2010 |
the selection is extended to include the new character. |
| 2011 |
Control-v moves the view down one screenful without moving the |
| 2012 |
insertion cursor or adjusting the selection. |
| 2013 |
|
| 2014 |
=item [12] |
| 2015 |
|
| 2016 |
Control-Next and Control-Prior scroll the view right or left by one page |
| 2017 |
without moving the insertion cursor or affecting the selection. |
| 2018 |
|
| 2019 |
=item [13] |
| 2020 |
|
| 2021 |
Home and Control-a move the insertion cursor to the |
| 2022 |
beginning of its line and clear any selection in the widget. |
| 2023 |
Shift-Home moves the insertion cursor to the beginning of the line |
| 2024 |
and also extends the selection to that point. |
| 2025 |
|
| 2026 |
=item [14] |
| 2027 |
|
| 2028 |
End and Control-e move the insertion cursor to the |
| 2029 |
end of the line and clear any selection in the widget. |
| 2030 |
Shift-End moves the cursor to the end of the line and extends the selection |
| 2031 |
to that point. |
| 2032 |
|
| 2033 |
=item [15] |
| 2034 |
|
| 2035 |
Control-Home and Meta-E<lt> move the insertion cursor to the beginning of |
| 2036 |
the text and clear any selection in the widget. |
| 2037 |
Control-Shift-Home moves the insertion cursor to the beginning of the text |
| 2038 |
and also extends the selection to that point. |
| 2039 |
|
| 2040 |
=item [16] |
| 2041 |
|
| 2042 |
Control-End and Meta-E<gt> move the insertion cursor to the end of the |
| 2043 |
text and clear any selection in the widget. |
| 2044 |
Control-Shift-End moves the cursor to the end of the text and extends |
| 2045 |
the selection to that point. |
| 2046 |
|
| 2047 |
=item [17] |
| 2048 |
|
| 2049 |
The Select key and Control-Space set the selection anchor to the position |
| 2050 |
of the insertion cursor. They don't affect the current selection. |
| 2051 |
Shift-Select and Control-Shift-Space adjust the selection to the |
| 2052 |
current position of the insertion cursor, selecting from the anchor |
| 2053 |
to the insertion cursor if there was not any selection previously. |
| 2054 |
|
| 2055 |
=item [18] |
| 2056 |
|
| 2057 |
Control-/ selects the entire contents of the widget. |
| 2058 |
|
| 2059 |
=item [19] |
| 2060 |
|
| 2061 |
Control-\ clears any selection in the widget. |
| 2062 |
|
| 2063 |
=item [20] |
| 2064 |
|
| 2065 |
The F16 key (labelled Copy on many Sun workstations) or Meta-w |
| 2066 |
copies the selection in the widget to the clipboard, if there is a selection. |
| 2067 |
|
| 2068 |
=item [21] |
| 2069 |
|
| 2070 |
The F20 key (labelled Cut on many Sun workstations) or Control-w |
| 2071 |
copies the selection in the widget to the clipboard and deletes |
| 2072 |
the selection. |
| 2073 |
If there is no selection in the widget then these keys have no effect. |
| 2074 |
|
| 2075 |
=item [22] |
| 2076 |
|
| 2077 |
The F18 key (labelled Paste on many Sun workstations) or Control-y |
| 2078 |
inserts the contents of the clipboard at the position of the |
| 2079 |
insertion cursor. |
| 2080 |
|
| 2081 |
=item [23] |
| 2082 |
|
| 2083 |
The Delete key deletes the selection, if there is one in the widget. |
| 2084 |
If there is no selection, it deletes the character to the right of |
| 2085 |
the insertion cursor. |
| 2086 |
|
| 2087 |
=item [24] |
| 2088 |
|
| 2089 |
Backspace and Control-h delete the selection, if there is one |
| 2090 |
in the widget. |
| 2091 |
If there is no selection, they delete the character to the left of |
| 2092 |
the insertion cursor. |
| 2093 |
|
| 2094 |
=item [25] |
| 2095 |
|
| 2096 |
Control-d deletes the character to the right of the insertion cursor. |
| 2097 |
|
| 2098 |
=item [26] |
| 2099 |
|
| 2100 |
Meta-d deletes the word to the right of the insertion cursor. |
| 2101 |
|
| 2102 |
=item [27] |
| 2103 |
|
| 2104 |
Control-k deletes from the insertion cursor to the end of its line; |
| 2105 |
if the insertion cursor is already at the end of a line, then |
| 2106 |
Control-k deletes the newline character. |
| 2107 |
|
| 2108 |
=item [28] |
| 2109 |
|
| 2110 |
Control-o opens a new line by inserting a newline character in |
| 2111 |
front of the insertion cursor without moving the insertion cursor. |
| 2112 |
|
| 2113 |
=item [29] |
| 2114 |
|
| 2115 |
Meta-backspace and Meta-Delete delete the word to the left of the |
| 2116 |
insertion cursor. |
| 2117 |
|
| 2118 |
=item [30] |
| 2119 |
|
| 2120 |
Control-x deletes whatever is selected in the text widget. |
| 2121 |
|
| 2122 |
=item [31] |
| 2123 |
|
| 2124 |
Control-t reverses the order of the two characters to the right of |
| 2125 |
the insertion cursor. |
| 2126 |
|
| 2127 |
=item [32] |
| 2128 |
|
| 2129 |
Control-z (and Control-underscore on UNIX when tk_strictMotif is |
| 2130 |
true) undoes the last edit action if the -undo option is true. |
| 2131 |
Does nothing otherwise. |
| 2132 |
|
| 2133 |
=item [33] |
| 2134 |
|
| 2135 |
Control-Z (or Control-y on Windows) reapplies the last undone edit |
| 2136 |
action if the -undo option is true. Does nothing otherwise. |
| 2137 |
|
| 2138 |
=back |
| 2139 |
|
| 2140 |
If the widget is disabled using the B<-state> option, then its |
| 2141 |
view can still be adjusted and text can still be selected, |
| 2142 |
but no insertion cursor will be displayed and no text modifications will |
| 2143 |
take place. |
| 2144 |
|
| 2145 |
The behavior of texts can be changed by defining new bindings for |
| 2146 |
individual widgets or by redefining the class bindings. |
| 2147 |
|
| 2148 |
|
| 2149 |
=head1 TIED INTERFACE |
| 2150 |
|
| 2151 |
The Perl/Tk Text widget also has built-in TIEHANDLE methods for |
| 2152 |
B<print> and B<printf> statements. This means you can print to file |
| 2153 |
handles tied to a Text widget, and the tied methods automatically |
| 2154 |
insert the print statement's arguments into the Text widget. |
| 2155 |
|
| 2156 |
For example: |
| 2157 |
|
| 2158 |
#!/usr/local/bin/perl -w |
| 2159 |
use POSIX 'acos'; |
| 2160 |
use Tk; |
| 2161 |
use strict; |
| 2162 |
|
| 2163 |
my $mw = MainWindow->new; |
| 2164 |
my $text = $mw->Text(qw/-width 40 -height 10/)->pack; |
| 2165 |
|
| 2166 |
tie *STDOUT, ref $text, $text; |
| 2167 |
|
| 2168 |
print "Hello Text World!\n"; |
| 2169 |
printf "pi ~= %1.5f", acos(-1.0); |
| 2170 |
|
| 2171 |
MainLoop; |
| 2172 |
|
| 2173 |
To tie a scrolled Text widget, use the Subwidget method to get to the |
| 2174 |
E<quot>realE<quot> widget: |
| 2175 |
|
| 2176 |
my $text = $mw->Scrolled('Text')->pack; |
| 2177 |
tie *STDOUT, 'Tk::Text', $text->Subwidget('scrolled'); |
| 2178 |
|
| 2179 |
=head1 PERFORMANCE ISSUES |
| 2180 |
|
| 2181 |
Text widgets should run efficiently under a variety |
| 2182 |
of conditions. The text widget uses about 2-3 bytes of |
| 2183 |
main memory for each byte of text, so texts containing a megabyte |
| 2184 |
or more should be practical on most workstations. |
| 2185 |
Text is represented internally with a modified B-tree structure |
| 2186 |
that makes operations relatively efficient even with large texts. |
| 2187 |
Tags are included in the B-tree structure in a way that allows |
| 2188 |
tags to span large ranges or have many disjoint smaller ranges |
| 2189 |
without loss of efficiency. |
| 2190 |
Marks are also implemented in a way that allows large numbers of |
| 2191 |
marks. |
| 2192 |
In most cases it is fine to have large numbers of unique tags, |
| 2193 |
or a tag that has many distinct ranges. |
| 2194 |
|
| 2195 |
One performance problem can arise if you have hundreds or thousands |
| 2196 |
of different tags that all have the following characteristics: |
| 2197 |
the first and last ranges of each tag are near the beginning and |
| 2198 |
end of the text, respectively, |
| 2199 |
or a single tag range covers most of the text widget. |
| 2200 |
The cost of adding and deleting tags like this is proportional |
| 2201 |
to the number of other tags with the same properties. |
| 2202 |
In contrast, there is no problem with having thousands of distinct |
| 2203 |
tags if their overall ranges are localized and spread uniformly throughout |
| 2204 |
the text. |
| 2205 |
|
| 2206 |
Very long text lines can be expensive, |
| 2207 |
especially if they have many marks and tags within them. |
| 2208 |
|
| 2209 |
The display line with the insert cursor is redrawn each time the |
| 2210 |
cursor blinks, which causes a steady stream of graphics traffic. |
| 2211 |
Set the B<-insertofftime> option to 0 avoid this. |
| 2212 |
|
| 2213 |
=head1 SEE ALSO |
| 2214 |
|
| 2215 |
L<Tk::ROText|Tk::ROText> |
| 2216 |
L<Tk::TextUndo|Tk::TextUndo> |
| 2217 |
|
| 2218 |
=head1 KEYWORDS |
| 2219 |
|
| 2220 |
text, widget |
| 2221 |
|
| 2222 |
=cut |
| 2223 |
|
| 2224 |
|