In Motif 1.1, the text widgets used two different cursors. The I−beam was used to mark the insertion position, while a
caret (^) was used as the destination cursor when it was separate from the insertion cursor. The destination cursor
showed the last position that text was inserted, edited, or selected. Having two separate cursors was confusing for
users and programmers, so the model has been simplified for Motif 1.2 to use only the I−beam cursor.
The text widgets have predefined action routines that allow the user to perform simple editing operations such as
moving one character to the right or deleting backwards to the beginning of the line. The user can specify translations
in a resource file that modify the input behavior of the widgets. The widgets are modeless, so they are always in
text−insertion mode. In Motif 1.2, there is an action that puts the Text widget in overstrike mode, while in Motif 1.1, it
is programmatically possible to emulate such a mode using multiple action routines.
The user can use the action routines provided by the widgets to set up the translation table to mimic an editor such as
emacs. The Text widget does not insert nonprintable characters, so users typically bind control−character sequences to
editing action routines. An editor like vi cannot be emulated because there is no distinction between command mode
and text−entry mode.
15.1.2 Selecting Text
Users have become accustomed to the ability to cut and paste text between windows in GUI−based applications. Cut
and paste is more difficult for the programmer to implement with the X Window System than a system where a single
vendor controls all of the variables, because the nature of X requires a more general solution . For example,
applications running on the same display may actually be executing on different systems; these systems may have
different byte orders or other differences in the underlying data format. Currently, only text selections are
implemented, which makes byte order irrelevant. However, the mechanism is designed to allow transparent transfer of
any kind of data. In order to insulate cut and paste operations from dependencies like these, all communication
between applications is implemented via the X server. Data that is cut is stored in a property on the X server. A
property is simply a named piece of data associated with a window and stored on the server.
The Interclient Communications Conventions Manual Reprinted as Appendix L in Volume Zero, X Protocol
Reference Manual. (ICCCM) defines a set of standard property names to be used for operations such as cut and paste
and lays out rules for how applications should interact with these properties. According to the ICCCM, text that is
selected is typically stored in the PRIMARY property. The SECONDARY property is defined as an alternate storage
area for use by applications that wish to support more than one simultaneous selection operation or that wish to
support operations requiring two selections, such as switching the contents of the two selections. The CLIPBOARD
property is defined as a longer−term holding area for data that is actually cut (rather than simply copied) from the
application's window. When we refer to the primary, secondary, or clipboard selection, we mean the property of the
same name.
The most common implementation of the selection mechanism is provided by the X Toolkit Intrinsics. The low−level
routines that are used to implement selections are described in detail in Volume Four, X Toolkit Intrinsics
Programming Manual. In general, applications such as xterm and widgets such as the Motif Text widget encapsulate
this functionality in action routines that are invoked by the user with mouse button or key combinations.
The user can select text in a Motif Text widget by pressing the left mouse button and dragging the pointer across the
text. The selected text is displayed in reverse video. When the button is released, the text widget has ownership of the
selection, but no text is copied. The selection can be extended either by pressing the SHIFT key and then dragging the
pointer with the left mouse button down, or by pressing any of the arrow keys while holding down the SHIFT key. In
addition to the click−and−drag technique for text selection, the Text widget also supports multiple−clicking
techniques: double−clicking selects a word, triple−clicking selects the current line, and quadruple−clicking selects all
of the text in the widget. An important constraint imposed by the ICCCM is that only one window may own a
selection property at one time, which means that once the user makes another primary selection, the original selection
15 Text Widgets 15.1.2 Selecting Text
379
is lost.
The user can copy text directly from the primary selection into the Text widget by clicking the middle mouse button at
the location where the text is to be inserted. This action is sometimes called stuffing the selection into the widget. The
user can stuff text at any location in the text stream, as long as the location is not inside the current selection. The text
is copied only when the middle mouse button is clicked, which is defined as a quick succession of press and release
actions. The operation does not take place simply because the middle mouse button is pressed, as this action is used
for drag and drop operations.
In Motif 1.2, the Text and TextField widgets support the drag−and−drop model of transferring textual data. Once text
has been selected in a widget, the selection can be dragged by pressing the middle mouse button over the selection and
dragging the pointer. The text is transferred when the user releases the middle mouse button with the pointer over
another location in the same widget or over another text widget. By default, the text is moved, which means that the
original text is deleted once the transfer is complete. The user can force a copy operation by holding down the
CONTROL key while dragging the pointer and releasing the mouse button. For more information on drag and drop,
see Chapter 18, Drag and Drop.
The secondary selection is used by the Motif text widgets to copy text directly within a widget. The user performs this
type of operation by first selecting the location where the copied text is to be placed; clicking the left mouse button
places the insertion point. Then the text that is to be copied is selected by pressing and dragging the middle mouse
button while the ALT key is pressed. The selected text is underlined rather than highlighted in reverse video. When
the button is released, the selected text is immediately stuffed at the location of the insertion cursor. Unlike the
primary selection, which may be retrieved many times, the secondary selection is immediate and can only be stuffed
once.
The third location for holding text is the clipboard selection. The clipboard selection is designed to be used as a
longer−term storage area for data. For example, MIT provides a client called xclipboard that asserts ownership of the
CLIPBOARD property and provides a user interface to it. xclipboard not only allows a selection to survive the
termination of the window where the data was originally selected, but it also allows for the storage of multiple
selections. The user can view all of the selections before deciding which one to paste.
OSF's implementation of the clipboard is incompatible with xclipboard. If xclipboard is running, any Motif routines
that attempt to store data on the clipboard will not succeed. The Motif routines temporarily try to lock the clipboard,
and xclipboard will not give up its own lock. Motif treats the clipboard as a two−item cache. Only Motif applications
that use the clipboard routines described in Chapter 17, The Clipboard, can interoperate using this selection. The
advantage of the Motif implementation is that it provides functionality far beyond that provided by the standard MIT
clients. With xterm and the Athena widgets, selections can really only be used for copy−and−paste operations; the
selected text is unchanged. The Motif Text widget, by contrast, allows you to cut, copy, clear, or type over a selection.
While there is a translation and action−based interface defined for these operations, it is typically not implemented.
As described in Chapter 2, The Motif Programming Model, Motif defines translations in terms of virtual key
bindings. By default, the virtual keys osfCut, osfCopy, osfPaste, et. al., are not bound to any actual keys. If a user
wants to use these keys, he must specify the bindings in a .motifbind file in his home directory. The interface for these
features is usually provided by menu items associated with the Text widget, as we will demonstrate in this chapter.
When text is selected in a Text widget, it is automatically stored in the primary selection. When one of the Text
widget functions, such as XmTextCut(), is used, the text is also stored in the clipboard selection. Most users will be
completely unaware that there are separate holding areas for selected text. If your application gets heavily into cutting
and pasting, you may find that the fusion of the primary and clipboard selections in the convenience routines is
confusing. You should be careful to implement the selection operations so that the different properties are transparent
to the user.
15 Text Widgets 15.1.2 Selecting Text
380
Get Volume 6A: Motif Programming Manual now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.