CH5.xml revision 421c997b
1421c997bSmrg<chapter id='Text_Widgets'>
2994689c1Smrg<title>Text Widgets</title>
3994689c1Smrg
4994689c1Smrg<para>
5994689c1SmrgThe Text widget provides a window that will allow an application
6994689c1Smrgto display and edit one or more lines of text.  Options are provided to
7994689c1Smrgallow the user to add Scrollbars to its window, search for a specific
8994689c1Smrgstring, and modify the text in the buffer.
9994689c1Smrg</para>
10994689c1Smrg<para>
11994689c1SmrgThe Text widget is made up of a number of pieces; it was modularized to
12994689c1Smrgease customization.  The AsciiText widget class (actually not limited to
13994689c1SmrgASCII but so named for compatibility) is be general enough to most
14994689c1Smrgneeds.  If more flexibility, special features, or extra functionality is
15994689c1Smrgneeded, they can be added by implementing a new TextSource or TextSink, or
16994689c1Smrgby subclassing the Text Widget (See Section 5.8 for customization
17994689c1Smrgdetails.) <!-- xref -->
18994689c1Smrg</para>
19994689c1Smrg<para>
20994689c1SmrgThe words <emphasis remap='I'>insertion point</emphasis> are used in this chapter to refer to the text
21994689c1Smrgcaret.  This is the symbol that is displayed between two characters in
22994689c1Smrgthe file.  The insertion point marks the location where any new characters
23994689c1Smrgwill be added to the file.  To avoid confusion the pointer cursor will
24994689c1Smrgalways be referred to as the <emphasis remap='I'>pointer</emphasis>.
25994689c1Smrg</para>
26994689c1Smrg<para>
27994689c1SmrgThe text widget supports three edit modes, controlling the types of
28994689c1Smrgmodifications a user is allowed to make:
29994689c1Smrg</para>
30994689c1Smrg<para>
31994689c1Smrg<itemizedlist>
32994689c1Smrg  <listitem><para>Append-only</para></listitem>
33994689c1Smrg  <listitem><para>Editable</para></listitem>
34994689c1Smrg  <listitem><para>Read-only</para></listitem>
35994689c1Smrg</itemizedlist>
36994689c1Smrg</para>
37994689c1Smrg<para>
38994689c1SmrgRead-only mode does not allow the user or the programmer to modify the text
39994689c1Smrgin the widget.  While the entire string may be reset in
40421c997bSmrgread-only mode with <xref linkend='XtSetValues' xrefstyle='select: title'/>, it cannot be modified via
41421c997bSmrgwith <xref linkend='XawTextReplace' xrefstyle='select: title'/>.  Append-only and editable modes allow
42994689c1Smrgthe text at the insertion point to be modified.  The only difference is
43994689c1Smrgthat text may only be added to or removed from the end of a buffer in
44994689c1Smrgappend-only mode.
45994689c1Smrg</para>
46994689c1Smrg<sect1 id="Text_Widget_for_Users">
47994689c1Smrg<title>Text Widget for Users</title>
48994689c1Smrg<!-- .IN "Text widget" "User's Guide to the Text widget" -->
49994689c1Smrg<!-- .XS -->
50994689c1Smrg<!-- 	Text Widget for Users -->
51994689c1Smrg<!-- .XE -->
52994689c1Smrg<para>
53994689c1Smrg<!-- .LP -->
54994689c1SmrgThe Text widget provides many of the common keyboard editing commands.
55994689c1SmrgThese commands allow users to move around and edit the buffer.  If an
56994689c1Smrgillegal operation is attempted, (such as deleting characters in a
57994689c1Smrgread-only text widget), the X server will beep.
58994689c1Smrg</para>
59994689c1Smrg<sect2 id="Default_Key_Bindings">
60994689c1Smrg<title>Default Key Bindings</title>
61994689c1Smrg<!-- .IN "Text widget" "default key bindings" -->
62994689c1Smrg<para>
63994689c1Smrg<!-- .LP -->
64994689c1SmrgThe default key bindings are patterned after those in the EMACS text editor:
65994689c1Smrg<!-- .sp -->
66994689c1Smrg<literallayout class="monospaced">
67994689c1Smrg<!-- .TA 1.0i 3.0i 4.5i -->
68994689c1Smrg<!-- .ta 1.0i 3.0i 4.5i -->
69994689c1SmrgCtrl-a	Beginning Of Line	Meta-b	Backward Word
70994689c1SmrgCtrl-b	Backward Character	Meta-f	Forward Word
71994689c1SmrgCtrl-d	Delete Next Character	Meta-i	Insert File
72994689c1SmrgCtrl-e	End Of Line	Meta-k	Kill To End Of Paragraph
73994689c1SmrgCtrl-f	Forward Character	Meta-q	Form Paragraph
74994689c1SmrgCtrl-g	Multiply Reset	Meta-v	Previous Page
75994689c1SmrgCtrl-h	Delete Previous Character	Meta-y	Insert Current Selection
76994689c1SmrgCtrl-j	Newline And Indent	Meta-z	Scroll One Line Down
77994689c1SmrgCtrl-k	Kill To End Of Line	Meta-d	Delete Next Word
78994689c1SmrgCtrl-l	Redraw Display	Meta-D	Kill Word
79994689c1SmrgCtrl-m	Newline	Meta-h	Delete Previous Word
80994689c1SmrgCtrl-n	Next Line	Meta-H	Backward Kill Word
81994689c1SmrgCtrl-o	Newline And Backup	Meta-&lt;	Beginning Of File
82994689c1SmrgCtrl-p	Previous Line	Meta-&gt;	End Of File
83994689c1SmrgCtrl-r	Search/Replace Backward	Meta-]	Forward Paragraph
84994689c1SmrgCtrl-s	Search/Replace Forward	Meta-[	Backward Paragraph
85994689c1SmrgCtrl-t	Transpose Characters
86994689c1SmrgCtrl-u	Multiply by 4	Meta-Delete	Delete Previous Word
87994689c1SmrgCtrl-v	Next Page	Meta-Shift Delete	Kill Previous Word
88994689c1SmrgCtrl-w	Kill Selection	Meta-Backspace	Delete Previous Word
89994689c1SmrgCtrl-y	Unkill	Meta-Shift Backspace	Kill Previous Word
90994689c1SmrgCtrl-z	Scroll One Line Up
91994689c1SmrgCtrl-\\	Reconnect to input method
92994689c1SmrgKanji	Reconnect to input method
93994689c1Smrg</literallayout>
94994689c1Smrg<!-- .sp -->
95994689c1Smrg</para>
96994689c1Smrg<para>
97994689c1Smrg<!-- .LP -->
98994689c1SmrgIn addition, the pointer may be used to cut and paste text:
99994689c1Smrg</para>
100994689c1Smrg<para>
101994689c1Smrg<!-- .LP -->
102994689c1Smrg<literallayout class="monospaced">
103994689c1Smrg<!-- .TA .5i 2.0i -->
104994689c1Smrg<!-- .ta .5i 2.0i -->
105994689c1Smrg	Button 1 Down	Start Selection
106994689c1Smrg	Button 1 Motion	Adjust Selection
107994689c1Smrg	Button 1 Up	End Selection (cut)
108994689c1Smrg
109994689c1Smrg	Button 2 Down	Insert Current Selection (paste)
110994689c1Smrg
111994689c1Smrg	Button 3 Down	Extend Current Selection
112994689c1Smrg	Button 3 Motion	Adjust Selection
113994689c1Smrg	Button 3 Up	End Selection (cut)
114994689c1Smrg
115994689c1Smrg</literallayout>
116994689c1Smrg</para>
117994689c1Smrg<para>
118994689c1Smrg<!-- .LP -->
119994689c1SmrgSince all of these key and pointer bindings are set through the
120994689c1Smrgtranslations and resource manager, the user and the application
121994689c1Smrgprogrammer can modify them by changing the Text widget's
122994689c1Smrg<function>translations</function> resource.
123994689c1Smrg<!-- .\" -->
124994689c1Smrg</para>
125994689c1Smrg</sect2>
126994689c1Smrg<sect2 id="Search_and_Replace">
127994689c1Smrg<title>Search and Replace</title>
128994689c1Smrg<!-- .IN "Text widget" "search" -->
129994689c1Smrg<!-- .IN "Text widget" "query replace" -->
130994689c1Smrg<para>
131994689c1Smrg<!-- .LP -->
132994689c1SmrgThe Text widget provides a search popup that can be used to search for a
133994689c1Smrgstring within the current Text widget.  The popup can be activated by
134994689c1Smrgtyping either <emphasis remap='I'>Control-r</emphasis> or <emphasis remap='I'>Control-s</emphasis>.  If <emphasis remap='I'>Control-s</emphasis> is
135994689c1Smrgused the search will be forward in the file from the current location of the
136994689c1Smrginsertion point; if <emphasis remap='I'>Control-r</emphasis> is used the search will be backward.  The
137994689c1Smrgactivated popup is placed under the pointer.  It has a number of buttons
138994689c1Smrgthat allow both text searches and text replacements to be performed.
139994689c1Smrg</para>
140994689c1Smrg<para>
141994689c1Smrg<!-- .LP -->
142994689c1SmrgAt the top of the search popup are two toggle buttons labeled
143994689c1Smrg<emphasis remap='I'>backward</emphasis> and <emphasis remap='I'>forward</emphasis>.  One of these buttons will always be
144994689c1Smrghighlighted; this is the direction in which the search will be
145994689c1Smrgperformed.  The user can change the direction at any time by clicking on
146994689c1Smrgthe appropriate button.
147994689c1Smrg</para>
148994689c1Smrg<para>
149994689c1Smrg<!-- .LP -->
150994689c1SmrgDirectly under the buttons there are two text areas, one labeled
151994689c1Smrg<emphasis remap='I'>Search for:</emphasis> and the other labeled <emphasis remap='I'>Replace with:</emphasis>.  If this is
152994689c1Smrga read-only Text widget the <emphasis remap='I'>Replace with:</emphasis> field will be insensitive
153994689c1Smrgand no replacements will be allowed.  After each of these labels will be
154994689c1Smrga text field.  This field will allow the user to enter a string to
155994689c1Smrgsearch for and the string to replace it with.  Only one of these text
156994689c1Smrgfields will have a window border around it; this is the active text
157994689c1Smrgfield.  Any key presses that occur when the focus in in the search popup
158994689c1Smrgwill be directed to the active text field.  There are also a few special
159994689c1Smrgkey sequences:
160994689c1Smrg<literallayout class="monospaced">
161994689c1Smrg<!-- .TA 1.75i -->
162994689c1Smrg<!-- .ta 1.75i -->
163994689c1Smrg<function>Carriage Return</function>:	Execute the action, and pop down the search widget.
164994689c1Smrg<function>Tab</function>:	Execute the action, then move to the next field.
165994689c1Smrg<function>Shift Carriage Return</function>:	Execute the action, then move to the next field.
166994689c1Smrg<function>Control-q Tab</function>:	Enter a Tab into a text field.
167994689c1Smrg<function>Control-c</function>:	Pop down the search popup.
168994689c1Smrg</literallayout>
169994689c1Smrg</para>
170994689c1Smrg<para>
171994689c1Smrg<!-- .LP -->
172994689c1SmrgUsing these special key sequences should allow simple
173994689c1Smrgsearches without ever removing one's hands from the keyboard.
174994689c1Smrg</para>
175994689c1Smrg<para>
176994689c1Smrg<!-- .LP -->
177994689c1SmrgNear the bottom of the search popup is a row of buttons.  These buttons
178994689c1Smrgallow the same actions to to be performed as the key sequences, but the
179994689c1Smrgbuttons will leave the popup active.  This can be quite useful if many
180994689c1Smrgsearches are being performed, as the popup will be left on the display.
181994689c1SmrgSince the search popup is a transient window, it may be picked
182994689c1Smrgup with the window manager and pulled off to the side for use
183994689c1Smrgat a later time.
184994689c1Smrg</para>
185994689c1Smrg<variablelist>
186994689c1Smrg  <varlistentry>
187994689c1Smrg    <term>Search</term>
188994689c1Smrg    <listitem>
189994689c1Smrg      <para>
190994689c1SmrgSearch for the specified string.
191994689c1Smrg      </para>
192994689c1Smrg    </listitem>
193994689c1Smrg  </varlistentry>
194994689c1Smrg  <varlistentry>
195994689c1Smrg    <term>Replace</term>
196994689c1Smrg    <listitem>
197994689c1Smrg      <para>
198994689c1SmrgReplace the currently highlighted string with the string in the
199994689c1Smrg<emphasis remap='I'>Replace with</emphasis> text field, and move onto the next occurrence of the
200994689c1Smrg<emphasis remap='I'>Search for</emphasis> text field.  The functionality is commonly referred to as
201994689c1Smrgquery-replace.
202994689c1Smrg      </para>
203994689c1Smrg    </listitem>
204994689c1Smrg  </varlistentry>
205994689c1Smrg  <varlistentry>
206994689c1Smrg    <term>ReplaceAll</term>
207994689c1Smrg    <listitem>
208994689c1Smrg      <para>
209994689c1SmrgReplace all occurrences of the search string with the replace string from
210994689c1Smrgthe current insertion point position to the end (or beginning) of the
211994689c1Smrgfile.  There is no key sequence to perform this action.
212994689c1Smrg      </para>
213994689c1Smrg    </listitem>
214994689c1Smrg  </varlistentry>
215994689c1Smrg  <varlistentry>
216994689c1Smrg      <term>ReplaceAll</term>
217994689c1Smrg      <listitem>
218994689c1Smrg        <para>
219994689c1SmrgRemove the search popup from the screen.
220994689c1Smrg      </para>
221994689c1Smrg    </listitem>
222994689c1Smrg  </varlistentry>
223994689c1Smrg</variablelist>
224994689c1Smrg<para>
225994689c1Smrg<!-- .LP -->
226994689c1SmrgFinally, when <function>international</function> resource is <function>true</function>, there may be a
227994689c1Smrgpre-edit buffer below the button row, for composing input.  Its presence
228994689c1Smrgis determined by the X locale in use and the VendorShell's <function>preeditType</function>
229994689c1Smrgresource.
230994689c1Smrg</para>
231994689c1Smrg<para>
232994689c1Smrg<!-- .LP -->
233994689c1SmrgThe widget hierarchy for the search popup is show below, all widgets
234994689c1Smrgare listed by class and instance name.
235994689c1Smrg<!-- .sp -->
236994689c1Smrg<!-- .nf -->
237994689c1Smrg<!-- .ta .5i 1.0i 1.5i 2.0i 2.5i -->
238994689c1Smrg<literallayout class="monospaced">
239994689c1SmrgText  &lt;name of Text widget&gt;
240994689c1Smrg	TransientShell  search
241994689c1Smrg		Form  form
242994689c1Smrg			Label label1
243994689c1Smrg			Label  label2
244994689c1Smrg			Toggle  backwards
245994689c1Smrg			Toggle  forwards
246994689c1Smrg			Label  searchLabel
247994689c1Smrg			Text  searchText
248994689c1Smrg			Label  replaceLabel
249994689c1Smrg			Text  replaceText
250994689c1Smrg			Command  search
251994689c1Smrg			Command  replaceOne
252994689c1Smrg			Command  replaceAll
253994689c1Smrg			Command  cancel
254994689c1Smrg</literallayout>
255994689c1Smrg<!-- .fi -->
256994689c1Smrg</para>
257994689c1Smrg</sect2>
258994689c1Smrg<sect2 id="File_Insertion">
259994689c1Smrg<title>File Insertion</title>
260994689c1Smrg<para>
261994689c1Smrg<!-- .LP -->
262994689c1Smrg<!-- .IN "Text widget" "file insertion" -->
263994689c1SmrgTo insert a file into a text widget, type the key sequence <emphasis remap='I'>Meta-i</emphasis>,
264994689c1Smrgwhich will activate the file insert popup.  This popup will appear under
265994689c1Smrgthe pointer, and any text typed while the focus is in this popup will be
266994689c1Smrgredirected to the text field used for the filename.  When the desired
267994689c1Smrgfilename has been entered, click on <emphasis remap='I'>Insert File</emphasis>, or type
268994689c1Smrg<emphasis remap='I'>Carriage Return</emphasis>.  The named file will then be inserted in the text
269994689c1Smrgwidget beginning at the insertion point position.  If an error occurs when
270994689c1Smrgopening the file, an error message will be printed, prompting the user
271994689c1Smrgto enter the filename again.  The file insert may be aborted by clicking
272994689c1Smrgon <emphasis remap='I'>Cancel</emphasis>.  If <emphasis remap='I'>Meta-i</emphasis> is typed at a text widget that is
273994689c1Smrgread-only, it will beep, as no file insertion is allowed.
274994689c1Smrg</para>
275994689c1Smrg<para>
276994689c1Smrg<!-- .LP -->
277994689c1SmrgThe widget hierarchy for the file insert popup is show below; all widgets
278994689c1Smrgare listed by class and instance name.
279994689c1Smrg<!-- .sp -->
280994689c1Smrg<!-- .nf -->
281994689c1Smrg<!-- .ta .5i 1.0i 1.5i 2.0i 2.5i -->
282994689c1Smrg<literallayout class="monospaced">
283994689c1SmrgText  &lt;name of Text widget&gt;
284994689c1Smrg	TransientShell  insertFile
285994689c1Smrg		Form  form
286994689c1Smrg			Label  label
287994689c1Smrg			Text  text
288994689c1Smrg			Command  insert
289994689c1Smrg			Command  cancel
290994689c1Smrg</literallayout>
291994689c1Smrg<!-- .fi -->
292994689c1Smrg</para>
293994689c1Smrg</sect2>
294994689c1Smrg<sect2 id="Text_Selections_for_Users">
295994689c1Smrg<title>Text Selections for Users</title>
296994689c1Smrg<para>
297994689c1Smrg<!-- .LP -->
298994689c1Smrg<!-- .IN "Text widget" "Text Selections for Users" -->
299994689c1SmrgThe text widgets have a text selection mechanism that allows
300994689c1Smrgthe user to copy pieces of the text into the <function>PRIMARY</function> selection,
301994689c1Smrgand paste
302994689c1Smrginto the text widget some text that another application (or text
303994689c1Smrgwidget) has put in the <function>PRIMARY</function> selection.
304994689c1Smrg</para>
305994689c1Smrg<para>
306994689c1Smrg<!-- .LP -->
307994689c1SmrgOne method of selecting text is to press pointer button 1
308994689c1Smrgon the beginning of the text to be selected, drag the pointer until all
309994689c1Smrgof the desired text is highlighted, and then release the button to
310994689c1Smrgactivate the selection.  Another method is to click pointer button 1 at
311994689c1Smrgone end of the text to be selected, then click pointer button 3 at the
312994689c1Smrgother end.
313994689c1Smrg</para>
314994689c1Smrg<para>
315994689c1Smrg<!-- .LP -->
316994689c1SmrgTo modify a currently active selection, press pointer button 3 near
317994689c1Smrgeither the end of the selection that you want to
318994689c1Smrgadjust.  This end of the selection may be moved while holding down pointer
319994689c1Smrgbutton 3.  When the proper area has been highlighted release the pointer
320994689c1Smrgbutton to activate the selection.
321994689c1Smrg</para>
322994689c1Smrg<para>
323994689c1Smrg<!-- .LP -->
324994689c1SmrgThe selected text may now be pasted into another application, and
325994689c1Smrgwill remain active until some other client makes a selection.
326994689c1SmrgTo paste text that some other application has
327994689c1Smrgput into the <function>PRIMARY</function> selection use pointer button 2.
328994689c1SmrgFirst place the insertion point where you would like the text to be inserted,
329994689c1Smrgthen click and release pointer button 2.
330994689c1Smrg</para>
331994689c1Smrg<para>
332994689c1Smrg<!-- .LP -->
333994689c1SmrgRapidly clicking pointer button 1 the following number of times will adjust
334994689c1Smrgthe selection as described.
335994689c1Smrg<variablelist>
336994689c1Smrg  <varlistentry>
337994689c1Smrg    <term>
338994689c1Smrg      <function>Two</function>
339994689c1Smrg    </term>
340994689c1Smrg    <listitem>
341994689c1Smrg      <para>
342994689c1SmrgSelect the word under the pointer.  A word boundary is defined by the
343994689c1SmrgText widget to be a Space, Tab, or Carriage Return.
344994689c1Smrg      </para>
345994689c1Smrg    </listitem>
346994689c1Smrg  </varlistentry>
347994689c1Smrg  <varlistentry>
348994689c1Smrg    <term>
349994689c1Smrg      <function>Three</function>
350994689c1Smrg    </term>
351994689c1Smrg    <listitem>
352994689c1Smrg      <para>
353994689c1SmrgSelect the line under the pointer.
354994689c1Smrg      </para>
355994689c1Smrg    </listitem>
356994689c1Smrg  </varlistentry>
357994689c1Smrg  <varlistentry>
358994689c1Smrg    <term>
359994689c1Smrg      <function>Four</function>
360994689c1Smrg    </term>
361994689c1Smrg    <listitem>
362994689c1Smrg      <para>
363994689c1SmrgSelect the paragraph under the pointer.  A paragraph boundary is
364994689c1Smrgdefined by the text widget as two Carriage Returns in a row with only
365994689c1SmrgSpaces or Tabs between them.
366994689c1Smrg      </para>
367994689c1Smrg    </listitem>
368994689c1Smrg  </varlistentry>
369994689c1Smrg  <varlistentry>
370994689c1Smrg    <term>
371994689c1Smrg      <function>Five</function>
372994689c1Smrg    </term>
373994689c1Smrg    <listitem>
374994689c1Smrg      <para>
375994689c1SmrgSelect the entire text buffer.
376994689c1Smrg    </para>
377994689c1Smrg  </listitem>
378994689c1Smrg  </varlistentry>
379994689c1Smrg</variablelist>
380994689c1Smrg</para>
381994689c1Smrg<para>
382994689c1SmrgTo unset the text selection, click pointer button 1 without moving it.
383994689c1Smrg</para>
384994689c1Smrg</sect2>
385994689c1Smrg</sect1>
386994689c1Smrg
387994689c1Smrg<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="TextActions_text_widget_actions.xml"/>
388994689c1Smrg<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="TextActions_default_translation_bindings.xml"/>
389994689c1Smrg<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="TextFuncs.xml"/>
390994689c1Smrg<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="TextCustom.xml"/>
391994689c1Smrg<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="Text.xml"/>
392994689c1Smrg<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="TextSink.xml"/>
393994689c1Smrg<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="TextSource.xml"/>
394994689c1Smrg<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="AsciiSink.xml"/>
395994689c1Smrg<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="AsciiSource.xml"/>
396994689c1Smrg<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="AsciiText.xml"/>
397994689c1Smrg</chapter>
398