CH5.xml revision 421c997b
1<chapter id='Text_Widgets'>
2<title>Text Widgets</title>
3
4<para>
5The Text widget provides a window that will allow an application
6to display and edit one or more lines of text.  Options are provided to
7allow the user to add Scrollbars to its window, search for a specific
8string, and modify the text in the buffer.
9</para>
10<para>
11The Text widget is made up of a number of pieces; it was modularized to
12ease customization.  The AsciiText widget class (actually not limited to
13ASCII but so named for compatibility) is be general enough to most
14needs.  If more flexibility, special features, or extra functionality is
15needed, they can be added by implementing a new TextSource or TextSink, or
16by subclassing the Text Widget (See Section 5.8 for customization
17details.) <!-- xref -->
18</para>
19<para>
20The words <emphasis remap='I'>insertion point</emphasis> are used in this chapter to refer to the text
21caret.  This is the symbol that is displayed between two characters in
22the file.  The insertion point marks the location where any new characters
23will be added to the file.  To avoid confusion the pointer cursor will
24always be referred to as the <emphasis remap='I'>pointer</emphasis>.
25</para>
26<para>
27The text widget supports three edit modes, controlling the types of
28modifications a user is allowed to make:
29</para>
30<para>
31<itemizedlist>
32  <listitem><para>Append-only</para></listitem>
33  <listitem><para>Editable</para></listitem>
34  <listitem><para>Read-only</para></listitem>
35</itemizedlist>
36</para>
37<para>
38Read-only mode does not allow the user or the programmer to modify the text
39in the widget.  While the entire string may be reset in
40read-only mode with <xref linkend='XtSetValues' xrefstyle='select: title'/>, it cannot be modified via
41with <xref linkend='XawTextReplace' xrefstyle='select: title'/>.  Append-only and editable modes allow
42the text at the insertion point to be modified.  The only difference is
43that text may only be added to or removed from the end of a buffer in
44append-only mode.
45</para>
46<sect1 id="Text_Widget_for_Users">
47<title>Text Widget for Users</title>
48<!-- .IN "Text widget" "User's Guide to the Text widget" -->
49<!-- .XS -->
50<!-- 	Text Widget for Users -->
51<!-- .XE -->
52<para>
53<!-- .LP -->
54The Text widget provides many of the common keyboard editing commands.
55These commands allow users to move around and edit the buffer.  If an
56illegal operation is attempted, (such as deleting characters in a
57read-only text widget), the X server will beep.
58</para>
59<sect2 id="Default_Key_Bindings">
60<title>Default Key Bindings</title>
61<!-- .IN "Text widget" "default key bindings" -->
62<para>
63<!-- .LP -->
64The default key bindings are patterned after those in the EMACS text editor:
65<!-- .sp -->
66<literallayout class="monospaced">
67<!-- .TA 1.0i 3.0i 4.5i -->
68<!-- .ta 1.0i 3.0i 4.5i -->
69Ctrl-a	Beginning Of Line	Meta-b	Backward Word
70Ctrl-b	Backward Character	Meta-f	Forward Word
71Ctrl-d	Delete Next Character	Meta-i	Insert File
72Ctrl-e	End Of Line	Meta-k	Kill To End Of Paragraph
73Ctrl-f	Forward Character	Meta-q	Form Paragraph
74Ctrl-g	Multiply Reset	Meta-v	Previous Page
75Ctrl-h	Delete Previous Character	Meta-y	Insert Current Selection
76Ctrl-j	Newline And Indent	Meta-z	Scroll One Line Down
77Ctrl-k	Kill To End Of Line	Meta-d	Delete Next Word
78Ctrl-l	Redraw Display	Meta-D	Kill Word
79Ctrl-m	Newline	Meta-h	Delete Previous Word
80Ctrl-n	Next Line	Meta-H	Backward Kill Word
81Ctrl-o	Newline And Backup	Meta-&lt;	Beginning Of File
82Ctrl-p	Previous Line	Meta-&gt;	End Of File
83Ctrl-r	Search/Replace Backward	Meta-]	Forward Paragraph
84Ctrl-s	Search/Replace Forward	Meta-[	Backward Paragraph
85Ctrl-t	Transpose Characters
86Ctrl-u	Multiply by 4	Meta-Delete	Delete Previous Word
87Ctrl-v	Next Page	Meta-Shift Delete	Kill Previous Word
88Ctrl-w	Kill Selection	Meta-Backspace	Delete Previous Word
89Ctrl-y	Unkill	Meta-Shift Backspace	Kill Previous Word
90Ctrl-z	Scroll One Line Up
91Ctrl-\\	Reconnect to input method
92Kanji	Reconnect to input method
93</literallayout>
94<!-- .sp -->
95</para>
96<para>
97<!-- .LP -->
98In addition, the pointer may be used to cut and paste text:
99</para>
100<para>
101<!-- .LP -->
102<literallayout class="monospaced">
103<!-- .TA .5i 2.0i -->
104<!-- .ta .5i 2.0i -->
105	Button 1 Down	Start Selection
106	Button 1 Motion	Adjust Selection
107	Button 1 Up	End Selection (cut)
108
109	Button 2 Down	Insert Current Selection (paste)
110
111	Button 3 Down	Extend Current Selection
112	Button 3 Motion	Adjust Selection
113	Button 3 Up	End Selection (cut)
114
115</literallayout>
116</para>
117<para>
118<!-- .LP -->
119Since all of these key and pointer bindings are set through the
120translations and resource manager, the user and the application
121programmer can modify them by changing the Text widget's
122<function>translations</function> resource.
123<!-- .\" -->
124</para>
125</sect2>
126<sect2 id="Search_and_Replace">
127<title>Search and Replace</title>
128<!-- .IN "Text widget" "search" -->
129<!-- .IN "Text widget" "query replace" -->
130<para>
131<!-- .LP -->
132The Text widget provides a search popup that can be used to search for a
133string within the current Text widget.  The popup can be activated by
134typing either <emphasis remap='I'>Control-r</emphasis> or <emphasis remap='I'>Control-s</emphasis>.  If <emphasis remap='I'>Control-s</emphasis> is
135used the search will be forward in the file from the current location of the
136insertion point; if <emphasis remap='I'>Control-r</emphasis> is used the search will be backward.  The
137activated popup is placed under the pointer.  It has a number of buttons
138that allow both text searches and text replacements to be performed.
139</para>
140<para>
141<!-- .LP -->
142At the top of the search popup are two toggle buttons labeled
143<emphasis remap='I'>backward</emphasis> and <emphasis remap='I'>forward</emphasis>.  One of these buttons will always be
144highlighted; this is the direction in which the search will be
145performed.  The user can change the direction at any time by clicking on
146the appropriate button.
147</para>
148<para>
149<!-- .LP -->
150Directly under the buttons there are two text areas, one labeled
151<emphasis remap='I'>Search for:</emphasis> and the other labeled <emphasis remap='I'>Replace with:</emphasis>.  If this is
152a read-only Text widget the <emphasis remap='I'>Replace with:</emphasis> field will be insensitive
153and no replacements will be allowed.  After each of these labels will be
154a text field.  This field will allow the user to enter a string to
155search for and the string to replace it with.  Only one of these text
156fields will have a window border around it; this is the active text
157field.  Any key presses that occur when the focus in in the search popup
158will be directed to the active text field.  There are also a few special
159key sequences:
160<literallayout class="monospaced">
161<!-- .TA 1.75i -->
162<!-- .ta 1.75i -->
163<function>Carriage Return</function>:	Execute the action, and pop down the search widget.
164<function>Tab</function>:	Execute the action, then move to the next field.
165<function>Shift Carriage Return</function>:	Execute the action, then move to the next field.
166<function>Control-q Tab</function>:	Enter a Tab into a text field.
167<function>Control-c</function>:	Pop down the search popup.
168</literallayout>
169</para>
170<para>
171<!-- .LP -->
172Using these special key sequences should allow simple
173searches without ever removing one's hands from the keyboard.
174</para>
175<para>
176<!-- .LP -->
177Near the bottom of the search popup is a row of buttons.  These buttons
178allow the same actions to to be performed as the key sequences, but the
179buttons will leave the popup active.  This can be quite useful if many
180searches are being performed, as the popup will be left on the display.
181Since the search popup is a transient window, it may be picked
182up with the window manager and pulled off to the side for use
183at a later time.
184</para>
185<variablelist>
186  <varlistentry>
187    <term>Search</term>
188    <listitem>
189      <para>
190Search for the specified string.
191      </para>
192    </listitem>
193  </varlistentry>
194  <varlistentry>
195    <term>Replace</term>
196    <listitem>
197      <para>
198Replace the currently highlighted string with the string in the
199<emphasis remap='I'>Replace with</emphasis> text field, and move onto the next occurrence of the
200<emphasis remap='I'>Search for</emphasis> text field.  The functionality is commonly referred to as
201query-replace.
202      </para>
203    </listitem>
204  </varlistentry>
205  <varlistentry>
206    <term>ReplaceAll</term>
207    <listitem>
208      <para>
209Replace all occurrences of the search string with the replace string from
210the current insertion point position to the end (or beginning) of the
211file.  There is no key sequence to perform this action.
212      </para>
213    </listitem>
214  </varlistentry>
215  <varlistentry>
216      <term>ReplaceAll</term>
217      <listitem>
218        <para>
219Remove the search popup from the screen.
220      </para>
221    </listitem>
222  </varlistentry>
223</variablelist>
224<para>
225<!-- .LP -->
226Finally, when <function>international</function> resource is <function>true</function>, there may be a
227pre-edit buffer below the button row, for composing input.  Its presence
228is determined by the X locale in use and the VendorShell's <function>preeditType</function>
229resource.
230</para>
231<para>
232<!-- .LP -->
233The widget hierarchy for the search popup is show below, all widgets
234are listed by class and instance name.
235<!-- .sp -->
236<!-- .nf -->
237<!-- .ta .5i 1.0i 1.5i 2.0i 2.5i -->
238<literallayout class="monospaced">
239Text  &lt;name of Text widget&gt;
240	TransientShell  search
241		Form  form
242			Label label1
243			Label  label2
244			Toggle  backwards
245			Toggle  forwards
246			Label  searchLabel
247			Text  searchText
248			Label  replaceLabel
249			Text  replaceText
250			Command  search
251			Command  replaceOne
252			Command  replaceAll
253			Command  cancel
254</literallayout>
255<!-- .fi -->
256</para>
257</sect2>
258<sect2 id="File_Insertion">
259<title>File Insertion</title>
260<para>
261<!-- .LP -->
262<!-- .IN "Text widget" "file insertion" -->
263To insert a file into a text widget, type the key sequence <emphasis remap='I'>Meta-i</emphasis>,
264which will activate the file insert popup.  This popup will appear under
265the pointer, and any text typed while the focus is in this popup will be
266redirected to the text field used for the filename.  When the desired
267filename has been entered, click on <emphasis remap='I'>Insert File</emphasis>, or type
268<emphasis remap='I'>Carriage Return</emphasis>.  The named file will then be inserted in the text
269widget beginning at the insertion point position.  If an error occurs when
270opening the file, an error message will be printed, prompting the user
271to enter the filename again.  The file insert may be aborted by clicking
272on <emphasis remap='I'>Cancel</emphasis>.  If <emphasis remap='I'>Meta-i</emphasis> is typed at a text widget that is
273read-only, it will beep, as no file insertion is allowed.
274</para>
275<para>
276<!-- .LP -->
277The widget hierarchy for the file insert popup is show below; all widgets
278are listed by class and instance name.
279<!-- .sp -->
280<!-- .nf -->
281<!-- .ta .5i 1.0i 1.5i 2.0i 2.5i -->
282<literallayout class="monospaced">
283Text  &lt;name of Text widget&gt;
284	TransientShell  insertFile
285		Form  form
286			Label  label
287			Text  text
288			Command  insert
289			Command  cancel
290</literallayout>
291<!-- .fi -->
292</para>
293</sect2>
294<sect2 id="Text_Selections_for_Users">
295<title>Text Selections for Users</title>
296<para>
297<!-- .LP -->
298<!-- .IN "Text widget" "Text Selections for Users" -->
299The text widgets have a text selection mechanism that allows
300the user to copy pieces of the text into the <function>PRIMARY</function> selection,
301and paste
302into the text widget some text that another application (or text
303widget) has put in the <function>PRIMARY</function> selection.
304</para>
305<para>
306<!-- .LP -->
307One method of selecting text is to press pointer button 1
308on the beginning of the text to be selected, drag the pointer until all
309of the desired text is highlighted, and then release the button to
310activate the selection.  Another method is to click pointer button 1 at
311one end of the text to be selected, then click pointer button 3 at the
312other end.
313</para>
314<para>
315<!-- .LP -->
316To modify a currently active selection, press pointer button 3 near
317either the end of the selection that you want to
318adjust.  This end of the selection may be moved while holding down pointer
319button 3.  When the proper area has been highlighted release the pointer
320button to activate the selection.
321</para>
322<para>
323<!-- .LP -->
324The selected text may now be pasted into another application, and
325will remain active until some other client makes a selection.
326To paste text that some other application has
327put into the <function>PRIMARY</function> selection use pointer button 2.
328First place the insertion point where you would like the text to be inserted,
329then click and release pointer button 2.
330</para>
331<para>
332<!-- .LP -->
333Rapidly clicking pointer button 1 the following number of times will adjust
334the selection as described.
335<variablelist>
336  <varlistentry>
337    <term>
338      <function>Two</function>
339    </term>
340    <listitem>
341      <para>
342Select the word under the pointer.  A word boundary is defined by the
343Text widget to be a Space, Tab, or Carriage Return.
344      </para>
345    </listitem>
346  </varlistentry>
347  <varlistentry>
348    <term>
349      <function>Three</function>
350    </term>
351    <listitem>
352      <para>
353Select the line under the pointer.
354      </para>
355    </listitem>
356  </varlistentry>
357  <varlistentry>
358    <term>
359      <function>Four</function>
360    </term>
361    <listitem>
362      <para>
363Select the paragraph under the pointer.  A paragraph boundary is
364defined by the text widget as two Carriage Returns in a row with only
365Spaces or Tabs between them.
366      </para>
367    </listitem>
368  </varlistentry>
369  <varlistentry>
370    <term>
371      <function>Five</function>
372    </term>
373    <listitem>
374      <para>
375Select the entire text buffer.
376    </para>
377  </listitem>
378  </varlistentry>
379</variablelist>
380</para>
381<para>
382To unset the text selection, click pointer button 1 without moving it.
383</para>
384</sect2>
385</sect1>
386
387<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="TextActions_text_widget_actions.xml"/>
388<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="TextActions_default_translation_bindings.xml"/>
389<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="TextFuncs.xml"/>
390<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="TextCustom.xml"/>
391<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="Text.xml"/>
392<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="TextSink.xml"/>
393<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="TextSource.xml"/>
394<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="AsciiSink.xml"/>
395<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="AsciiSource.xml"/>
396<xi:include xmlns:xi="http://www.w3.org/2001/XInclude"  href="AsciiText.xml"/>
397</chapter>
398