Debian Codegraph @

info/gcl-tk/text.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>text (GCL TK Manual)</title>
7
8 <meta name="description" content="text (GCL TK Manual)">
9 <meta name="keywords" content="text (GCL TK Manual)">
10 <meta name="resource-type" content="document">
11 <meta name="distribution" content="global">
12 <meta name="Generator" content="makeinfo">
13 <link href="index.html" rel="start" title="Top">
14 <link href="wm.html#SEC_Contents" rel="contents" title="Table of Contents">
15 <link href="Widgets.html" rel="up" title="Widgets">
16 <link href="entry.html" rel="next" title="entry">
17 <link href="menubutton.html" rel="prev" title="menubutton">
18 <style type="text/css">
19 <!--
20 a.summary-letter {text-decoration: none}
21 blockquote.indentedblock {margin-right: 0em}
22 div.display {margin-left: 3.2em}
23 div.example {margin-left: 3.2em}
24 div.lisp {margin-left: 3.2em}
25 kbd {font-style: oblique}
26 pre.display {font-family: inherit}
27 pre.format {font-family: inherit}
28 pre.menu-comment {font-family: serif}
29 pre.menu-preformatted {font-family: serif}
30 span.nolinebreak {white-space: nowrap}
31 span.roman {font-family: initial; font-weight: normal}
32 span.sansserif {font-family: sans-serif; font-weight: normal}
33 ul.no-bullet {list-style: none}
34 -->
35 </style>
36
37
38 </head>
39
40 <body lang="en">
41 <span id="text"></span><div class="header">
42 <p>
43 Next: <a href="entry.html" accesskey="n" rel="next">entry</a>, Previous: <a href="menubutton.html" accesskey="p" rel="prev">menubutton</a>, Up: <a href="Widgets.html" accesskey="u" rel="up">Widgets</a> &nbsp; [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
44 </div>
45 <hr>
46 <span id="text-1"></span><h3 class="section">2.9 text</h3>
47
48 <p>text \- Create and manipulate text widgets
49 </p><span id="Synopsis-8"></span><h4 class="unnumberedsubsec">Synopsis</h4>
50 <p><b>text</b><i> </i><i>pathName </i><span class="roman">?</span><i>options</i>?
51 </p><span id="Standard-Options-8"></span><h4 class="unnumberedsubsec">Standard Options</h4>
52
53
54 <div class="example">
55 <pre class="example">background foreground insertWidth selectBorderWidth
56 borderWidth insertBackground padX selectForeground
57 cursor insertBorderWidth padY setGrid
58 exportSelection insertOffTime relief yScrollCommand
59 font insertOnTime selectBackground
60 </pre></div>
61
62
63 <p>See <a href="options.html">options</a>, for more information.
64 </p><span id="Arguments-for-Text"></span><h4 class="unnumberedsubsec">Arguments for Text</h4>
65
66
67 <dl compact="compact">
68 <dt><code><b>:height</b></code></dt>
69 <dd><p align="right">Name=<code>&quot;<b>height</b><span class="roman">&quot;</span> Class=<code>&quot;</code><b>Height</b>&quot;</code>
70 </p><br>
71
72 <p>Specifies the desired height for the window, in units of characters.
73 Must be at least one.
74 </p></dd>
75 </dl>
76
77
78 <dl compact="compact">
79 <dt><code><b>:state</b></code></dt>
80 <dd><p align="right">Name=<code>&quot;<b>state</b><span class="roman">&quot;</span> Class=<code>&quot;</code><b>State</b>&quot;</code>
81 </p><br>
82
83 <p>Specifies one of two states for the text: <b>normal</b><span class="roman"> or </span><b>disabled</b>.
84 If the text is disabled then characters may not be inserted or deleted
85 and no insertion cursor will be displayed, even if the input focus is
86 in the widget.
87 </p></dd>
88 </dl>
89
90
91 <dl compact="compact">
92 <dt><code><b>:width</b></code></dt>
93 <dd><p align="right">Name=<code>&quot;<b>width</b><span class="roman">&quot;</span> Class=<code>&quot;</code><b>Width</b>&quot;</code>
94 </p><br>
95
96 <p>Specifies the desired width for the window in units of characters.
97 If the font doesn&rsquo;t have a uniform width then the width of the
98 character &ldquo;0&rdquo; is used in translating from character units to
99 screen units.
100 </p></dd>
101 </dl>
102
103
104 <dl compact="compact">
105 <dt><code><b>:wrap</b></code></dt>
106 <dd><p align="right">Name=<code>&quot;<b>wrap</b><span class="roman">&quot;</span> Class=<code>&quot;</code><b>Wrap</b>&quot;</code>
107 </p><br>
108
109 <p>Specifies how to handle lines in the text that are too long to be
110 displayed in a single line of the text&rsquo;s window.
111 The value must be <b>none</b><span class="roman"> or </span><b>char</b><span class="roman"> or </span><b>word</b>.
112 A wrap mode of <b>none</b> means that each line of text appears as
113 exactly one line on the screen; extra characters that don&rsquo;t fit
114 on the screen are not displayed.
115 In the other modes each line of text will be broken up into several
116 screen lines if necessary to keep all the characters visible.
117 In <b>char</b> mode a screen line break may occur after any character;
118 in <b>word</b> mode a line break will only be made at word boundaries.
119 </p></dd>
120 </dl>
121
122 <span id="Description-5"></span><h4 class="unnumberedsubsec">Description</h4>
123
124 <p>The <b>text</b> command creates a new window (given by the
125 <i>pathName</i> argument) and makes it into a text widget.
126 Additional
127 options, described above, may be specified on the command line
128 or in the option database
129 to configure aspects of the text such as its default background color
130 and relief. The <b>text</b> command returns the
131 path name of the new window.
132 </p>
133 <p>A text widget displays one or more lines of text and allows that
134 text to be edited.
135 Text widgets support three different kinds of annotations on the
136 text, called tags, marks, and windows.
137 Tags allow different portions of the text
138 to be displayed with different fonts and colors.
139 In addition, Tcl commands can be associated with tags so
140 that commands are invoked when particular actions such as keystrokes
141 and mouse button presses occur in particular ranges of the text.
142 See TAGS below for more details.
143 </p>
144 <p>The second form of annotation consists of marks, which are floating
145 markers in the text.
146 Marks are used to keep track of various interesting positions in the
147 text as it is edited.
148 See MARKS below for more details.
149 </p>
150 <p>The third form of annotation allows arbitrary windows to be displayed
151 in the text widget.
152 See WINDOWS below for more details.
153 </p>
154 <span id="Indices-1"></span><h4 class="unnumberedsubsec">Indices</h4>
155
156 <p>Many of the widget commands for texts take one or more indices
157 as arguments.
158 An index is a string used to indicate a particular place within
159 a text, such as a place to insert characters or one endpoint of a
160 range of characters to delete.
161 Indices have the syntax
162 </p>
163 <p><i>base modifier modifier modifier ...</i>
164 </p>
165
166 <p>Where <i>base</i><span class="roman"> gives a starting point and the </span><i>modifier</i>s
167 adjust the index from the starting point (e.g. move forward or
168 backward one character). Every index must contain a <i>base</i>,
169 but the <i>modifier</i>s are optional.
170 </p>
171
172 <p>The <i>base</i> for an index must have one of the following forms:
173 </p>
174 <dl compact="compact">
175 <dt><i>line</i><b>.</b><i>char</i></dt>
176 <dd><p>Indicates <i>char</i><span class="roman">&rsquo;th character on line </span><i>line</i>.
177 Lines are numbered from 1 for consistency with other UNIX programs
178 that use this numbering scheme.
179 Within a line, characters are numbered from 0.
180 </p></dd>
181 <dt><b>@</b><i>x</i><b>,</b><i>y</i></dt>
182 <dd><p>Indicates the character that covers the pixel whose x and y coordinates
183 within the text&rsquo;s window are <i>x</i><span class="roman"> and </span><i>y</i>.
184 </p></dd>
185 <dt><b>end</b></dt>
186 <dd><p>Indicates the last character in the text, which is always a newline
187 character.
188 </p></dd>
189 <dt><i>mark</i></dt>
190 <dd><p>Indicates the character just after the mark whose name is <i>mark</i>.
191 </p></dd>
192 <dt><i>tag</i><b>.first</b></dt>
193 <dd><p>Indicates the first character in the text that has been tagged with
194 <i>tag</i>.
195 This form generates an error if no characters are currently tagged
196 with <i>tag</i>.
197 </p></dd>
198 <dt><i>tag</i><b>.last</b></dt>
199 <dd><p>Indicates the character just after the last one in the text that has
200 been tagged with <i>tag</i>.
201 This form generates an error if no characters are currently tagged
202 with <i>tag</i>.
203 </p></dd>
204 </dl>
205
206
207 <p>If modifiers follow the base index, each one of them must have one
208 of the forms listed below. Keywords such as <b>chars</b><span class="roman"> and </span><b>wordend</b>
209 may be abbreviated as long as the abbreviation is unambiguous.
210 </p>
211 <dl compact="compact">
212 <dt><b>+ </b><i>count</i><b> chars</b></dt>
213 <dd><p>Adjust the index forward by <i>count</i> characters, moving to later
214 lines in the text if necessary. If there are fewer than <i>count</i>
215 characters in the text after the current index, then set the index
216 to the last character in the text.
217 Spaces on either side of <i>count</i> are optional.
218 </p></dd>
219 <dt><b>-</b> <i>count</i><b> chars</b></dt>
220 <dd><p>Adjust the index backward by <i>count</i> characters, moving to earlier
221 lines in the text if necessary. If there are fewer than <i>count</i>
222 characters in the text before the current index, then set the index
223 to the first character in the text.
224 Spaces on either side of <i>count</i> are optional.
225 </p></dd>
226 <dt><b>+ </b><i>count</i><b> lines</b></dt>
227 <dd><p>Adjust the index forward by <i>count</i> lines, retaining the same
228 character position within the line. If there are fewer than <i>count</i>
229 lines after the line containing the current index, then set the index
230 to refer to the same character position on the last line of the text.
231 Then, if the line is not long enough to contain a character at the indicated
232 character position, adjust the character position to refer to the last
233 character of the line (the newline).
234 Spaces on either side of <i>count</i> are optional.
235 </p></dd>
236 <dt><b>-</b> <i>count</i><b> lines</b></dt>
237 <dd><p>Adjust the index backward by <i>count</i> lines, retaining the same
238 character position within the line. If there are fewer than <i>count</i>
239 lines before the line containing the current index, then set the index
240 to refer to the same character position on the first line of the text.
241 Then, if the line is not long enough to contain a character at the indicated
242 character position, adjust the character position to refer to the last
243 character of the line (the newline).
244 Spaces on either side of <i>count</i> are optional.
245 </p></dd>
246 <dt><b>linestart</b></dt>
247 <dd><p>Adjust the index to refer to the first character on the line.
248 </p></dd>
249 <dt><b>lineend</b></dt>
250 <dd><p>Adjust the index to refer to the last character on the line (the newline).
251 </p></dd>
252 <dt><b>wordstart</b></dt>
253 <dd><p>Adjust the index to refer to the first character of the word containing
254 the current index. A word consists of any number of adjacent characters
255 that are letters, digits, or underscores, or a single character that
256 is not one of these.
257 </p></dd>
258 <dt><b>wordend</b></dt>
259 <dd><p>Adjust the index to refer to the character just after the last one of the
260 word containing the current index. If the current index refers to the last
261 character of the text then it is not modified.
262 </p></dd>
263 </dl>
264
265
266 <p>If more than one modifier is present then they are applied in
267 left-to-right order. For example, the index &ldquo;\fBend \- 1 chars&rdquo;
268 refers to the next-to-last character in the text and
269 &ldquo;\fBinsert wordstart \- 1 c&rdquo; refers to the character just before
270 the first one in the word containing the insertion cursor.
271 </p>
272 <span id="Tags"></span><h4 class="unnumberedsubsec">Tags</h4>
273
274 <p>The first form of annotation in text widgets is a tag.
275 A tag is a textual string that is associated with some of the characters
276 in a text.
277 There may be any number of tags associated with characters in a
278 text.
279 Each tag may refer to a single character, a range of characters, or
280 several ranges of characters.
281 An individual character may have any number of tags associated with it.
282 </p>
283 <p>A priority order is defined among tags, and this order is used in
284 implementing some of the tag-related functions described below.
285 When a tag is defined (by associating it with characters or setting
286 its display options or binding commands to it), it is given
287 a priority higher than any existing tag.
288 The priority order of tags may be redefined using the
289 &ldquo;<i>pathName </i><b>:tag :raise</b><span class="roman">&rdquo; and &ldquo;</span><i>pathName </i><b>:tag :lower</b>&rdquo;
290 widget commands.
291 </p>
292 <p>Tags serve three purposes in text widgets.
293 First, they control the way information is displayed on the screen.
294 By default, characters are displayed as determined by the
295 <b>background</b><span class="roman">, </span><b>font</b><span class="roman">, and </span><b>foreground</b> options for the
296 text widget.
297 However, display options may be associated with individual tags
298 using the &ldquo;<i>pathName </i><b>:tag configure</b>&rdquo; widget command.
299 If a character has been tagged, then the display options associated
300 with the tag override the default display style.
301 The following options are currently supported for tags:
302 </p>
303 <dl compact="compact">
304 <dt><b>:background </b><i>color</i></dt>
305 <dd><p><i>Color</i> specifies the background color to use for characters
306 associated with the tag.
307 It may have any of the forms accepted by <b>Tk_GetColor</b>.
308 </p></dd>
309 <dt><b>:bgstipple </b><i>bitmap</i></dt>
310 <dd><p><i>Bitmap</i> specifies a bitmap that is used as a stipple pattern
311 for the background.
312 It may have any of the forms accepted by <b>Tk_GetBitmap</b>.
313 If <i>bitmap</i> hasn&rsquo;t been specified, or if it is specified
314 as an empty string, then a solid fill will be used for the
315 background.
316 </p></dd>
317 <dt><b>:borderwidth </b><i>pixels</i></dt>
318 <dd><p><i>Pixels</i> specifies the width of a 3-D border to draw around
319 the background.
320 It may have any of the forms accepted by <b>Tk_GetPixels</b>.
321 This option is used in conjunction with the <b>:relief</b>
322 option to give a 3-D appearance to the background for characters;
323 it is ignored unless the <b>:background</b> option
324 has been set for the tag.
325 </p></dd>
326 <dt><b>:fgstipple </b><i>bitmap</i></dt>
327 <dd><p><i>Bitmap</i> specifies a bitmap that is used as a stipple pattern
328 when drawing text and other foreground information such as
329 underlines.
330 It may have any of the forms accepted by <b>Tk_GetBitmap</b>.
331 If <i>bitmap</i> hasn&rsquo;t been specified, or if it is specified
332 as an empty string, then a solid fill will be used.
333 </p></dd>
334 <dt><b>:font </b><i>fontName</i></dt>
335 <dd><p><i>FontName</i> is the name of a font to use for drawing characters.
336 It may have any of the forms accepted by <b>Tk_GetFontStruct</b>.
337 </p></dd>
338 <dt><b>:foreground </b><i>color</i></dt>
339 <dd><p><i>Color</i> specifies the color to use when drawing text and other
340 foreground information such as underlines.
341 It may have any of the forms accepted by <b>Tk_GetColor</b>.
342 </p></dd>
343 <dt><b>:relief </b><i>relief</i></dt>
344 <dd><p>\fIRelief specifies the 3-D relief to use for drawing backgrounds,
345 in any of the forms accepted by <b>Tk_GetRelief</b>.
346 This option is used in conjunction with the <b>:borderwidth</b>
347 option to give a 3-D appearance to the background for characters;
348 it is ignored unless the <b>:background</b> option
349 has been set for the tag.
350 </p></dd>
351 <dt><b>:underline </b><i>boolean</i></dt>
352 <dd><p><i>Boolean</i> specifies whether or not to draw an underline underneath
353 characters.
354 It may have any of the forms accepted by <b>Tk_GetBoolean</b>.
355 </p>
356 <p>If a character has several tags associated with it, and if their
357 display options conflict, then the options of the highest priority
358 tag are used.
359 If a particular display option hasn&rsquo;t been specified for a
360 particular tag, or if it is specified as an empty string, then
361 that option will never be used; the next-highest-priority
362 tag&rsquo;s option will used instead.
363 If no tag specifies a particular display optionl, then the default
364 style for the widget will be used.
365 </p>
366 <p>The second purpose for tags is event bindings.
367 You can associate bindings with a tag in much the same way you can
368 associate bindings with a widget class: whenever particular X
369 events occur on characters with the given tag, a given
370 Tcl command will be executed.
371 Tag bindings can be used to give behaviors to ranges of characters;
372 among other things, this allows hypertext-like
373 features to be implemented.
374 For details, see the description of the <b>tag bind</b> widget
375 command below.
376 </p>
377 <p>The third use for tags is in managing the selection.
378 See THE SELECTION below.
379 </p>
380 </dd>
381 </dl>
382 <span id="Marks"></span><h4 class="unnumberedsubsec">Marks</h4>
383
384 <p>The second form of annotation in text widgets is a mark.
385 Marks are used for remembering particular places in a text.
386 They are something like tags, in that they have names and
387 they refer to places in the file, but a mark isn&rsquo;t associated
388 with particular characters.
389 Instead, a mark is associated with the gap between two characters.
390 Only a single position may be associated with a mark at any given
391 time.
392 If the characters around a mark are deleted the mark will still
393 remain; it will just have new neighbor characters.
394 In contrast, if the characters containing a tag are deleted then
395 the tag will no longer have an association with characters in
396 the file.
397 Marks may be manipulated with the &ldquo;<i>pathName </i><b>:mark</b>&rdquo; widget
398 command, and their current locations may be determined by using the
399 mark name as an index in widget commands.
400 </p>
401 <p>The name space for marks is different from that for tags: the
402 same name may be used for both a mark and a tag, but they will refer
403 to different things.
404 </p>
405 <p>Two marks have special significance.
406 First, the mark <b>insert</b> is associated with the insertion cursor,
407 as described under THE INSERTION CURSOR below.
408 Second, the mark <b>current</b> is associated with the character
409 closest to the mouse and is adjusted automatically to track the
410 mouse position and any changes to the text in the widget (one
411 exception: <b>current</b> is not updated in response to mouse
412 motions if a mouse button is down; the update will be deferred
413 until all mouse buttons have been released).
414 Neither of these special marks may be unset.
415 </p>
416 <span id="Windows"></span><h4 class="unnumberedsubsec">Windows</h4>
417
418 <p>The third form of annotation in text widgets is a window.
419 Window support isn&rsquo;t implemented yet, but when it is it will be
420 described here.
421 </p>
422 <span id="The-Selection"></span><h4 class="unnumberedsubsec">The Selection</h4>
423
424 <p>Text widgets support the standard X selection.
425 Selection support is implemented via tags.
426 If the <b>exportSelection</b> option for the text widget is true
427 then the <b>sel</b> tag will be associated with the selection:
428 </p><ul class="no-bullet">
429 <li> [1]
430 Whenever characters are tagged with <b>sel</b> the text widget
431 will claim ownership of the selection.
432 </li><li> [2]
433 Attempts to retrieve the
434 selection will be serviced by the text widget, returning all the
435 charaters with the <b>sel</b> tag.
436 </li><li> [3]
437 If the selection is claimed away by another application or by another
438 window within this application, then the <b>sel</b> tag will be removed
439 from all characters in the text.
440 </li></ul>
441
442 <p>The <b>sel</b> tag is automatically defined when a text widget is
443 created, and it may not be deleted with the &ldquo;<i>pathName </i><b>:tag delete</b>&rdquo;
444 widget command. Furthermore, the <b>selectBackground</b>,
445 <b>selectBorderWidth</b><span class="roman">, and </span><b>selectForeground</b> options for
446 the text widget are tied to the <b>:background</b>,
447 <b>:borderwidth</b><span class="roman">, and </span><b>:foreground</b><span class="roman"> options for the </span><b>sel</b>
448 tag: changes in either will automatically be reflected in the
449 other.
450 </p>
451 <span id="The-Insertion-Cursor"></span><h4 class="unnumberedsubsec">The Insertion Cursor</h4>
452
453 <p>The mark named <b>insert</b> has special significance in text widgets.
454 It is defined automatically when a text widget is created and it
455 may not be unset with the &ldquo;<i>pathName </i><b>:mark unset</b>&rdquo; widget
456 command.
457 The <b>insert</b> mark represents the position of the insertion
458 cursor, and the insertion cursor will automatically be drawn at
459 this point whenever the text widget has the input focus.
460 </p>
461 <span id="A-Text-Widget_0027s-Arguments"></span><h4 class="unnumberedsubsec">A Text Widget&rsquo;s Arguments</h4>
462
463 <p>The <b>text</b> command creates a new Tcl command whose
464 name is the same as the path name of the text&rsquo;s window. This
465 command may be used to invoke various
466 operations on the widget. It has the following general form:
467 </p>
468 <div class="example">
469 <pre class="example"><i>pathName option </i><span class="roman">?</span><i>arg arg ...</i>?
470 </pre></div>
471
472 <p><i>PathName</i> is the name of the command, which is the same as
473 the text widget&rsquo;s path name. <i>Option</i><span class="roman"> and the </span><i>arg</i>s
474 determine the exact behavior of the command. The following
475 commands are possible for text widgets:
476 </p>
477 <dl compact="compact">
478 <dt><i>pathName </i><b>:compare</b><span class="roman"> </span><i>index1 op index2</i></dt>
479 <dd><p>Compares the indices given by <i>index1</i><span class="roman"> and </span><i>index2</i> according
480 to the relational operator given by <i>op</i>, and returns 1 if
481 the relationship is satisfied and 0 if it isn&rsquo;t.
482 <i>Op</i> must be one of the operators &lt;, &lt;=, ==, &gt;=, &gt;, or !=.
483 If <i>op</i> is == then 1 is returned if the two indices refer to
484 the same character, if <i>op</i><span class="roman"> is &lt; then 1 is returned if </span><i>index1</i>
485 refers to an earlier character in the text than <i>index2</i>, and
486 so on.
487 </p></dd>
488 <dt><i>pathName </i><b>:configure</b><span class="roman"> ?</span><i>option</i><span class="roman">? </span><i>?value option value ...</i>?</dt>
489 <dd><p>Query or modify the configuration options of the widget.
490 If no <i>option</i> is specified, returns a list describing all of
491 the available options for <i>pathName</i><span class="roman"> (see </span><b>Tk_ConfigureInfo</b> for
492 information on the format of this list). If <i>option</i> is specified
493 with no <i>value</i>, then the command returns a list describing the
494 one named option (this list will be identical to the corresponding
495 sublist of the value returned if no <i>option</i> is specified). If
496 one or more <i>option:value</i> pairs are specified, then the command
497 modifies the given widget option(s) to have the given value(s); in
498 this case the command returns an empty string.
499 <i>Option</i><span class="roman"> may have any of the values accepted by the </span><b>text</b>
500 command.
501 </p></dd>
502 <dt><i>pathName </i><b>:debug </b><span class="roman">?</span><i>boolean</i>?</dt>
503 <dd><p>If <i>boolean</i> is specified, then it must have one of the true or
504 false values accepted by Tcl_GetBoolean.
505 If the value is a true one then internal consistency checks will be
506 turned on in the B-tree code associated with text widgets.
507 If <i>boolean</i> has a false value then the debugging checks will
508 be turned off.
509 In either case the command returns an empty string.
510 If <i>boolean</i><span class="roman"> is not specified then the command returns </span><b>on</b>
511 or <b>off</b> to indicate whether or not debugging is turned on.
512 There is a single debugging switch shared by all text widgets: turning
513 debugging on or off in any widget turns it on or off for all widgets.
514 For widgets with large amounts of text, the consistency checks may
515 cause a noticeable slow-down.
516 </p></dd>
517 <dt><i>pathName </i><b>:delete </b><i>index1 </i><span class="roman">?</span><i>index2</i>?</dt>
518 <dd><p>Delete a range of characters from the text.
519 If both <i>index1</i><span class="roman"> and </span><i>index2</i> are specified, then delete
520 all the characters starting with the one given by <i>index1</i>
521 and stopping just before <i>index2</i> (i.e. the character at
522 <i>index2</i> is not deleted).
523 If <i>index2</i> doesn&rsquo;t specify a position later in the text
524 than <i>index1</i> then no characters are deleted.
525 If <i>index2</i> isn&rsquo;t specified then the single character at
526 <i>index1</i> is deleted.
527 It is not allowable to delete characters in a way that would leave
528 the text without a newline as the last character.
529 The command returns an empty string.
530 </p></dd>
531 <dt><i>pathName </i><b>:get </b><i>index1 </i><span class="roman">?</span><i>index2</i>?</dt>
532 <dd><p>Return a range of characters from the text.
533 The return value will be all the characters in the text starting
534 with the one whose index is <i>index1</i> and ending just before
535 the one whose index is <i>index2</i><span class="roman"> (the character at </span><i>index2</i>
536 will not be returned).
537 If <i>index2</i><span class="roman"> is omitted then the single character at </span><i>index1</i>
538 is returned.
539 If there are no characters in the specified range (e.g. <i>index1</i>
540 is past the end of the file or <i>index2</i> is less than or equal
541 to <i>index1</i>) then an empty string is returned.
542 </p></dd>
543 <dt><i>pathName </i><b>:index </b><i>index</i></dt>
544 <dd><p>Returns the position corresponding to <i>index</i> in the form
545 <i>line.char</i><span class="roman"> where </span><i>line</i><span class="roman"> is the line number and </span><i>char</i>
546 is the character number.
547 <i>Index</i> may have any of the forms described under INDICES above.
548 </p></dd>
549 <dt><i>pathName </i><b>:insert </b>\fIindex chars</dt>
550 <dd><p>Inserts <i>chars</i> into the text just before the character at
551 <i>index</i> and returns an empty string.
552 It is not possible to insert characters after the last newline
553 of the text.
554 </p></dd>
555 <dt><i>pathName </i><b>:mark </b><i>option </i><span class="roman">?</span><i>arg arg ...</i>?</dt>
556 <dd><p>This command is used to manipulate marks. The exact behavior of
557 the command depends on the <i>option</i> argument that follows
558 the <b>mark</b> argument. The following forms of the command
559 are currently supported:
560 </p><dl compact="compact">
561 <dt><i>pathName </i><b>:mark :names</b></dt>
562 <dd><p>Returns a list whose elements are the names of all the marks that
563 are currently set.
564 </p></dd>
565 <dt><i>pathName </i><b>:mark :set </b><i>markName index</i></dt>
566 <dd><p>Sets the mark named <i>markName</i> to a position just before the
567 character at <i>index</i>.
568 If <i>markName</i> already exists, it is moved from its old position;
569 if it doesn&rsquo;t exist, a new mark is created.
570 This command returns an empty string.
571 </p></dd>
572 <dt><i>pathName </i><b>:mark :unset </b><i>markName </i><span class="roman">?</span><i>markName markName ...</i>?</dt>
573 <dd><p>Remove the mark corresponding to each of the <i>markName</i> arguments.
574 The removed marks will not be usable in indices and will not be
575 returned by future calls to &ldquo;<i>pathName </i><b>:mark names</b>&rdquo;.
576 This command returns an empty string.
577 </p></dd>
578 </dl>
579
580 </dd>
581 <dt><i>pathName </i><b>:scan</b><span class="roman"> </span><i>option args</i></dt>
582 <dd><p>This command is used to implement scanning on texts. It has
583 two forms, depending on <i>option</i>:
584 </p><dl compact="compact">
585 <dt><i>pathName </i><b>:scan :mark </b><i>y</i></dt>
586 <dd><p>Records <i>y</i> and the current view in the text window; used in
587 conjunction with later <b>scan dragto</b> commands. Typically this
588 command is associated with a mouse button press in the widget. It
589 returns an empty string.
590 </p></dd>
591 <dt><i>pathName </i><b>:scan :dragto </b><i>y</i></dt>
592 <dd><p>This command computes the difference between its <i>y</i> argument
593 and the <i>y</i><span class="roman"> argument to the last </span><b>scan mark</b> command for
594 the widget. It then adjusts the view up or down by 10 times the
595 difference in y-coordinates. This command is typically associated
596 with mouse motion events in the widget, to produce the effect of
597 dragging the text at high speed through the window. The return
598 value is an empty string.
599 </p></dd>
600 </dl>
601
602 </dd>
603 <dt><i>pathName </i><b>:tag </b><i>option </i><span class="roman">?</span><i>arg arg ...</i>?</dt>
604 <dd><p>This command is used to manipulate tags. The exact behavior of the
605 command depends on the <i>option</i> argument that follows the
606 <b>tag</b> argument. The following forms of the command are currently
607 supported:
608 </p>
609 <dl compact="compact">
610 <dt><i>pathName </i><b>:tag :add </b><i>tagName index1 </i><span class="roman">?</span><i>index2</i>?</dt>
611 <dd><p>Associate the tag <i>tagName</i> with all of the characters starting
612 with <i>index1</i> and ending just before
613 <i>index2</i><span class="roman"> (the character at </span><i>index2</i> isn&rsquo;t tagged).
614 If <i>index2</i> is omitted then the single character at
615 <i>index1</i> is tagged.
616 If there are no characters in the specified range (e.g. <i>index1</i>
617 is past the end of the file or <i>index2</i> is less than or equal
618 to <i>index1</i>) then the command has no effect.
619 This command returns an empty string.
620 </p></dd>
621 <dt><i>pathName </i><b>:tag :bind </b><i>tagName</i><span class="roman"> ?</span><i>sequence</i><span class="roman">? ?</span><i>command</i>?</dt>
622 <dd><p>This command associates <i>command</i> with the tag given by
623 <i>tagName</i>.
624 Whenever the event sequence given by <i>sequence</i> occurs for a
625 character that has been tagged with <i>tagName</i>,
626 the command will be invoked.
627 This widget command is similar to the <b>bind</b> command except that
628 it operates on characters in a text rather than entire widgets.
629 See the <b>bind</b> manual entry for complete details
630 on the syntax of <i>sequence</i> and the substitutions performed
631 on <i>command</i> before invoking it.
632 If all arguments are specified then a new binding is created, replacing
633 any existing binding for the same <i>sequence</i><span class="roman"> and </span><i>tagName</i>
634 (if the first character of <i>command</i><span class="roman"> is &ldquo;+&rdquo; then </span><i>command</i>
635 augments an existing binding rather than replacing it).
636 In this case the return value is an empty string.
637 If <i>command</i><span class="roman"> is omitted then the command returns the </span><i>command</i>
638 associated with <i>tagName</i><span class="roman"> and </span><i>sequence</i> (an error occurs
639 if there is no such binding).
640 If both <i>command</i><span class="roman"> and </span><i>sequence</i> are omitted then the command
641 returns a list of all the sequences for which bindings have been
642 defined for <i>tagName</i>.
643 </p>
644
645 <p>The only events for which bindings may be specified are those related
646 to the mouse and keyboard, such as <b>Enter</b><span class="roman">, </span><b>Leave</b>,
647 <b>ButtonPress</b><span class="roman">, </span><b>Motion</b><span class="roman">, and </span><b>KeyPress</b>.
648 Event bindings for a text widget use the <b>current</b> mark
649 described under MARKS above.
650 <b>Enter</b> events trigger for a character when it
651 becomes the current character (i.e. the <b>current</b> mark moves
652 to just in front of that character).
653 <b>Leave</b> events trigger for a character when it ceases to be
654 the current item (i.e. the <b>current</b> mark moves away from
655 that character, or the character is deleted).
656 These events are different than <b>Enter</b><span class="roman"> and </span><b>Leave</b>
657 events for windows.
658 Mouse and keyboard events are directed to the current character.
659 </p>
660
661 <p>It is possible for the current character to have multiple tags,
662 and for each of them to have a binding for a particular event
663 sequence.
664 When this occurs, the binding from the highest priority tag is
665 used.
666 If a particular tag doesn&rsquo;t have a binding that matches an
667 event, then the tag is ignored and tags with lower priority
668 will be checked.
669 </p>
670
671 <p>If bindings are created for the widget as a whole using the
672 <b>bind</b> command, then those bindings will supplement the
673 tag bindings.
674 This means that a single event can trigger two Tcl scripts,
675 one for a widget-level binding and one for a tag-level
676 binding.
677 </p>
678
679 </dd>
680 <dt><i>pathName </i><b>:tag :configure </b><i>tagName</i><span class="roman"> ?</span><i>option</i><span class="roman">? ?</span><i>value</i><span class="roman">? ?</span><i>option value ...</i>?</dt>
681 <dd><p>This command is similar to the <b>configure</b> widget command except
682 that it modifies options associated with the tag given by <i>tagName</i>
683 instead of modifying options for the overall text widget.
684 If no <i>option</i> is specified, the command returns a list describing
685 all of the available options for <i>tagName</i><span class="roman"> (see </span><b>Tk_ConfigureInfo</b>
686 for information on the format of this list).
687 If <i>option</i><span class="roman"> is specified with no </span><i>value</i>, then the command returns
688 a list describing the one named option (this list will be identical to
689 the corresponding sublist of the value returned if no <i>option</i>
690 is specified).
691 If one or more <i>option:value</i> pairs are specified, then the command
692 modifies the given option(s) to have the given value(s) in <i>tagName</i>;
693 in this case the command returns an empty string.
694 See TAGS above for details on the options available for tags.
695 </p></dd>
696 <dt><i>pathName </i><b>:tag :delete </b><i>tagName </i><span class="roman">?</span><i>tagName ...</i>?</dt>
697 <dd><p>Deletes all tag information for each of the <i>tagName</i>
698 arguments.
699 The command removes the tags from all characters in the file
700 and also deletes any other information associated with the tags,
701 such as bindings and display information.
702 The command returns an empty string.
703 </p></dd>
704 <dt><i>pathName </i><b>:tag :lower </b><i>tagName </i><span class="roman">?</span><i>belowThis</i>?</dt>
705 <dd><p>Changes the priority of tag <i>tagName</i> so that it is just lower
706 in priority than the tag whose name is <i>belowThis</i>.
707 If <i>belowThis</i><span class="roman"> is omitted, then </span><i>tagName</i>&rsquo;s priority
708 is changed to make it lowest priority of all tags.
709 </p></dd>
710 <dt><i>pathName </i><b>:tag :names </b><span class="roman">?</span><i>index</i>?</dt>
711 <dd><p>Returns a list whose elements are the names of all the tags that
712 are active at the character position given by <i>index</i>.
713 If <i>index</i> is omitted, then the return value will describe
714 all of the tags that exist for the text (this includes all tags
715 that have been named in a &ldquo;<i>pathName </i><b>:tag</b>&rdquo; widget
716 command but haven&rsquo;t been deleted by a &ldquo;<i>pathName </i><b>:tag :delete</b>&rdquo;
717 widget command, even if no characters are currently marked with
718 the tag).
719 The list will be sorted in order from lowest priority to highest
720 priority.
721 </p></dd>
722 <dt><i>pathName </i><b>:tag :nextrange </b><i>tagName index1 </i><span class="roman">?</span><i>index2</i>?</dt>
723 <dd><p>This command searches the text for a range of characters tagged
724 with <i>tagName</i> where the first character of the range is
725 no earlier than the character at <i>index1</i> and no later than
726 the character just before <i>index2</i> (a range starting at
727 <i>index2</i> will not be considered).
728 If several matching ranges exist, the first one is chosen.
729 The command&rsquo;s return value is a list containing
730 two elements, which are the index of the first character of the
731 range and the index of the character just after the last one in
732 the range.
733 If no matching range is found then the return value is an
734 empty string.
735 If <i>index2</i> is not given then it defaults to the end of the text.
736 </p></dd>
737 <dt><i>pathName </i><b>:tag :raise </b><i>tagName </i><span class="roman">?</span><i>aboveThis</i>?</dt>
738 <dd><p>Changes the priority of tag <i>tagName</i> so that it is just higher
739 in priority than the tag whose name is <i>aboveThis</i>.
740 If <i>aboveThis</i><span class="roman"> is omitted, then </span><i>tagName</i>&rsquo;s priority
741 is changed to make it highest priority of all tags.
742 </p></dd>
743 <dt><i>pathName </i><b>:tag :ranges </b><i>tagName</i></dt>
744 <dd><p>Returns a list describing all of the ranges of text that have been
745 tagged with <i>tagName</i>.
746 The first two elements of the list describe the first tagged range
747 in the text, the next two elements describe the second range, and
748 so on.
749 The first element of each pair contains the index of the first
750 character of the range, and the second element of the pair contains
751 the index of the character just after the last one in the
752 range.
753 If there are no characters tagged with <i>tag</i> then an
754 empty string is returned.
755 </p></dd>
756 <dt><i>pathName </i><b>:tag :remove </b><i>tagName index1 </i><span class="roman">?</span><i>index2</i>?</dt>
757 <dd><p>Remove the tag <i>tagName</i> from all of the characters starting
758 at <i>index1</i> and ending just before
759 <i>index2</i><span class="roman"> (the character at </span><i>index2</i> isn&rsquo;t affected).
760 If <i>index2</i> is omitted then the single character at
761 <i>index1</i> is untagged.
762 If there are no characters in the specified range (e.g. <i>index1</i>
763 is past the end of the file or <i>index2</i> is less than or equal
764 to <i>index1</i>) then the command has no effect.
765 This command returns an empty string.
766 </p>
767 </dd>
768 </dl>
769 </dd>
770 <dt><i>pathName </i><b>:yview </b><span class="roman">?</span><b>:pickplace</b><span class="roman">? </span><i>what</i></dt>
771 <dd><p>This command changes the view in the widget&rsquo;s window so that the line
772 given by <i>what</i> is visible in the window.
773 <i>What</i> may be either an absolute line number, where 0 corresponds
774 to the first line of the file, or an index with any of the forms
775 described under INDICES above.
776 The first form (absolute line number) is used in the commands issued
777 by scrollbars to control the widget&rsquo;s view.
778 If the <b>:pickplace</b><span class="roman"> option isn&rsquo;t specified then </span><i>what</i> will
779 appear at the top of the window.
780 If <b>:pickplace</b> is specified then the widget chooses where
781 <i>what</i> appears in the window:
782 </p><ul class="no-bullet">
783 <li> [1]
784 If <i>what</i> is already visible somewhere in the window then the
785 command does nothing.
786 </li><li> [2]
787 If <i>what</i> is only a few lines off-screen above the window then
788 it will be positioned at the top of the window.
789 </li><li> [3]
790 If <i>what</i> is only a few lines off-screen below the window then
791 it will be positioned at the bottom of the window.
792 </li><li> [4]
793 Otherwise, <i>what</i> will be centered in the window.
794 </li></ul>
795
796 <p>The <b>:pickplace</b> option is typically used after inserting text
797 to make sure that the insertion cursor is still visible on the screen.
798 This command returns an empty string.
799 </p></dd>
800 </dl>
801
802
803 <span id="Bindings-4"></span><h4 class="unnumberedsubsec">Bindings</h4>
804
805 <p>Tk automatically creates class bindings for texts that give them
806 the following default behavior:
807 </p><ul class="no-bullet">
808 <li> [1]
809 Pressing mouse button 1 in an text positions the insertion cursor
810 just before the character underneath the mouse cursor and sets the
811 input focus to this widget.
812 </li><li> [2]
813 Dragging with mouse button 1 strokes out a selection between
814 the insertion cursor and the character under the mouse.
815 </li><li> [3]
816 If you double-press mouse button 1 then the word under the mouse cursor
817 will be selected, the insertion cursor will be positioned at the
818 beginning of the word, and dragging the mouse will stroke out a selection
819 whole words at a time.
820 </li><li> [4]
821 If you triple-press mouse button 1 then the line under the mouse cursor
822 will be selected, the insertion cursor will be positioned at the
823 beginning of the line, and dragging the mouse will stroke out a selection
824 whole line at a time.
825 </li><li> [5]
826 The ends of the selection can be adjusted by dragging with mouse
827 button 1 while the shift key is down; this will adjust the end
828 of the selection that was nearest to the mouse cursor when button
829 1 was pressed. If the selection was made in word or line mode then
830 it will be adjusted in this same mode.
831 </li><li> [6]
832 The view in the text can be adjusted by dragging with mouse button 2.
833 </li><li> [7]
834 If the input focus is in a text widget and characters are typed on the
835 keyboard, the characters are inserted just before the insertion cursor.
836 </li><li> [8]
837 Control+h and the Backspace and Delete keys erase the character just
838 before the insertion cursor.
839 </li><li> [9]
840 Control+v inserts the current selection just before the insertion cursor.
841 </li><li> [10]
842 Control+d deletes the selected characters; an error occurs if the selection
843 is not in this widget.
844 </li></ul>
845
846 <p>If the text is disabled using the <b>state</b> option, then the text&rsquo;s
847 view can still be adjusted and text in the text can still be selected,
848 but no insertion cursor will be displayed and no text modifications will
849 take place.
850 </p>
851 <p>The behavior of texts can be changed by defining new bindings for
852 individual widgets or by redefining the class bindings.
853 </p>
854 <span id="g_t_0022Performance-Issues_0022"></span><h4 class="unnumberedsubsec">&quot;Performance Issues&quot;</h4>
855
856 <p>Text widgets should run efficiently under a variety
857 of conditions. The text widget uses about 2-3 bytes of
858 main memory for each byte of text, so texts containing a megabyte
859 or more should be practical on most workstations.
860 Text is represented internally with a modified B-tree structure
861 that makes operations relatively efficient even with large texts.
862 Tags are included in the B-tree structure in a way that allows
863 tags to span large ranges or have many disjoint smaller ranges
864 without loss of efficiency.
865 Marks are also implemented in a way that allows large numbers of
866 marks.
867 The only known mode of operation where a text widget may not run
868 efficiently is if it has a very large number of different tags.
869 Hundreds of tags should be fine, or even a thousand,
870 but tens of thousands of tags will make texts consume a lot of
871 memory and run slowly.
872 </p>
873 <span id="Keywords-8"></span><h4 class="unnumberedsubsec">Keywords</h4>
874 <p>text, widget
875 </p><hr>
876 <div class="header">
877 <p>
878 Next: <a href="entry.html" accesskey="n" rel="next">entry</a>, Previous: <a href="menubutton.html" accesskey="p" rel="prev">menubutton</a>, Up: <a href="Widgets.html" accesskey="u" rel="up">Widgets</a> &nbsp; [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
879 </div>
880
881
882
883 </body>
884 </html>