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