The selection requestor then requests that the selection owner convert a list of targets.
On the selection owner side, a MULTIPLE request is treated as a stream of single requests.
The package calls the conversion procedure as many times as required to convert all of the
targets requested.
In the special case where a multiple request also involves an incremental target (INCR), the
selection owner calls the application-defined conversion procedure with format set
SEL_MULTIPLE to indicate that the selection request is a incremental request that is part of a
multiple request.
18.6 Additional Transfer Mechanisms (Selection Requestor)
A selection requestor may associate data with the window property being used in the
selection transaction. This property may be used by the selection owner for certain types of
selection transfers. The selection-requestor object attributes: SEL_PROP_DATA, and
SEL_TYPE_INDEX
support bi-directional data transfer for a property associated with a
selection. In addition, the attributes SEL_PROP_FORMAT, SEL_PROP_LENGTH,
SEL_PROP_TYPE, and SEL_PROP_TYPE_NAME, also support this type of selection transfer. A
selection requestor may associate a property with the selection that the requestor is request-
ing. For example, this associated property may be used to support an INSERT_SELECTION or
a INSERT_PROPERTY target. Or properties may be used by the owner for other reasons. A
selection-requestor object may associate data with the property that the selection is request-
ing. This information may be of interest to a selection owner for certain types of selection
transfers.
18.7 Additional Transfer Mechanisms (Selection Owner)
If the selection requestor is sending data to the selection owner, using additional properties,
the attribute SEL_PROP_INFO allows the selection owner to access this property data.
18.8 Sample Selection Owner Program with a Selection Item
Example 18-9 shows a simple panel with two text items and two buttons inside a frame. This
example uses a selection item to return the TARGETS type and a conversion procedure to
return the remaining supported types. The “Selection:” field allows the user to enter the
desired selection rank. The “Contents:” field allows the user to enter a string, the selection
data to be operated on. The “Own Selection” button causes the application to own the
selection. The “Lose Selection” button causes the selection to be lost.
418 XView Programming Manual
Example 18-9. Sample program
–
sel_hold.c
/*
* sel_hold.c: Example of how to acquire and hold a selection.
*
*/
#include <stdio.h>
#include <X11/Xlib.h>
#include <xview/xview.h>
#include <xview/frame.h>
#include <xview/panel.h>
#include <xview/textsw.h>
#include <xview/font.h>
#include <xview/sel_pkg.h>
Frame frame;
Xv_Server server;
Panel panel;
Panel_item p_selection,
p_contents,
p_own,
p_lose;
Selection_owner sel;
Selection_item sel_targets;
#define ATOM(server, name) (Atom)xv_get(server, SERVER_ATOM, name)
main(argc, argv)
int argc;
char **argv;
{
Panel_setting NotifyProc();
int SelectionConvertProc();
void SelectionDoneProc(),
SelectionLoseProc();
Xv_Font font;
Atom targets[5];
server = xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
frame = xv_create((Window)NULL, FRAME,
XV_X, 520,
XV_Y, 655,
XV_LABEL, "Selection Holder Example",
FRAME_SHOW_FOOTER, True,
NULL);
panel = xv_create(frame, PANEL, NULL);
p_selection = xv_create(panel, PANEL_TEXT,
PANEL_LABEL_STRING, "Selection:",
PANEL_VALUE_DISPLAY_LENGTH, 40,
PANEL_NOTIFY_PROC, NotifyProc,
PANEL_ITEM_X, xv_col(panel,0),
PANEL_ITEM_Y, xv_row(panel,0),
NULL);
Selections
Selections 419
Example 18-9. Sample program
–
sel_hold.c (continued)
p_contents = xv_create(panel, PANEL_TEXT,
PANEL_LABEL_STRING, "Contents:",
PANEL_VALUE_DISPLAY_LENGTH, 40,
PANEL_ITEM_X, xv_col(panel,0),
PANEL_ITEM_Y, xv_row(panel,1),
NULL);
p_own = xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Own Selection",
PANEL_NOTIFY_PROC, NotifyProc,
PANEL_ITEM_X, xv_col(panel,5),
PANEL_ITEM_Y, xv_row(panel,2),
NULL);
p_lose = xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Lose Selection",
PANEL_NOTIFY_PROC, NotifyProc,
PANEL_ITEM_X, xv_col(panel,30),
PANEL_ITEM_Y, xv_row(panel,2),
NULL);
/* Create a selection owner object */
sel = xv_create(panel, SELECTION_OWNER,
SEL_CONVERT_PROC, SelectionConvertProc,
SEL_DONE_PROC, SelectionDoneProc,
SEL_LOSE_PROC, SelectionLoseProc,
NULL);
targets[0] = (Atom)xv_get(server, SERVER_ATOM, "TARGETS");
targets[1] = (Atom)xv_get(server, SERVER_ATOM, "TIMESTAMP");
targets[2] = (Atom)xv_get(server, SERVER_ATOM, "LENGTH");
targets[3] = (Atom)xv_get(server, SERVER_ATOM, "STRING");
targets[4] = (Atom)xv_get(server, SERVER_ATOM, "DELETE");
/* Create a selection item, owned by the selection owner we just
* created. This pre-registers a conversion, in this case a
* conversion for ‘‘TARGETS’’.
*/
sel_targets = xv_create(sel, SELECTION_ITEM,
SEL_TYPE_NAME, "TARGETS",
SEL_FORMAT, 32,
SEL_LENGTH, 5,
SEL_DATA, (Xv_opaque)targets,
NULL);
window_fit(panel);
window_fit(frame);
xv_main_loop(frame);
exit(0);
}
The selection-owner object sel specifies the conversion procedure, the done procedure, and
the lose procedure. Next, the targets array is filled with supported atoms. These are the
names for the supported conversions. The selection-item object’s conversion is specified
420 XView Programming Manual
using the attributes: SEL_TYPE_NAME, SEL_FORMAT, and SEL_LENGTH. The attribute
SEL_DATA associates the selection data with the selection item.
18.8.0.1 The notify procedure
Example 18-10 shows how the NotifyProc() routine is used to handle the selection rank
entry, owning the selection, and losing the selection. If a selection rank has been entered, it is
read from the panel text item and then assigned to sel, the selection-owner object. If the
“own” button is pressed, the current selection is acquired by setting SEL_OWN to TRUE and
SEL_TIME to the time of the event. If the “lose” button is pressed, the current selection is
released by setting SEL_OWN to FALSE and SEL_TIME to the time of the event.
Example 18-10. The notify procedure
–
NotifyProc()
Panel_setting
NotifyProc(item, event)
Panel_item item;
Event *event;
{
if (item == p_selection) {
char *rank;
/* Get the rank of the selection */
/* the user would like to use. */
rank = (char *)xv_get(item, PANEL_VALUE);
/* Set the rank to our selection owner object. */
xv_set(sel, SEL_RANK_NAME, rank, NULL);
return(PANEL_NEXT);
} else if (item == p_own) {
/* The user pressed the ‘‘own’’ button, so we */
/* acquire the selection. */
xv_set(sel, SEL_OWN, True,
SEL_TIME, event_time(event),
NULL);
xv_set(frame,
FRAME_LEFT_FOOTER, "Acquired Selection...", NULL);
} else if (item == p_lose) {
/* The user pressed the ‘‘lose’’ button, so we lose ownership
* of the selection.
*/
xv_set(sel, SEL_OWN, False,
SEL_TIME, event_time(event),
NULL);
xv_set(frame, FRAME_LEFT_FOOTER, "Lost Selection...", NULL);
}
return(PANEL_DONE);
}
Selections
Selections 421
18.8.0.2 The conversion procedure
The conversion procedure is specified by the SEL_CONVERT_PROC attribute. This conversion
procedure, SelectionConvertProc, is called whenever an application makes a request
to the selection owned by this application. This procedure is shown in Example 18-11. The
selection owner responds to the requesting application by converting the acquired selection
to the target type requested. A well behaved routine provides for the case of a TARGETS
request by returning a list of valid target types to the requestor. In this case, the selection
owner returns the length of the string selected for LENGTH, a copy of the contents of the string
selected for STRING, and sets the string to NULL and returns NULL for the DELETE target.
Example 18-11. Sample conversion procedure
–
SelectionConvertProc
int
SelectionConvertProc(sel, target, data, length, format)
Selection_owner sel;
Atom *target; /* Input/Output */
Xv_opaque *data; /* Output */
unsigned long *length; /* Output */
int *format; /* Output */
{
/* Request for the length of the selection. */
if (*target == ATOM(server, "LENGTH")) {
static unsigned long len;
char *contents;
contents = (char *)xv_get(p_contents, PANEL_VALUE);
len = strlen(contents);
*target = ATOM(server, "INTEGER");
*format = 32;
*length = 1;
*data = (Xv_opaque)&len;
return(True);
}
/* Request for the string contents of the selection. */
else if (*target == ATOM(server, "STRING")) {
char *contents;
contents = (char *)xv_get(p_contents, PANEL_VALUE);
*target = ATOM(server, "STRING");
*format = 8;
*length = strlen(contents);
*data = (Xv_opaque)strdup(contents);
return(True);
}
/* Request to delete the selection. */
else if (*target == ATOM(server, "DELETE")) {
xv_set(p_contents, PANEL_VALUE, "", NULL);
*target = ATOM(server, "NULL");
*format = 32;
*length = 0;
*data = (Xv_opaque)NULL;
return(True);
422 XView Programming Manual
Get Volume 7A: XView 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.