
Example A-1. The simple_seln.c program (continued)
frame = (Frame) xv_create(NULL, FRAME,
FRAME_LABEL, argv[0],
NULL);
panel = (Panel)xv_create(frame, PANEL,
WIN_WIDTH, WIN_EXTEND_TO_EDGE,
NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Quit",
PANEL_NOTIFY_PROC, exit,
NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Print Selection",
PANEL_NOTIFY_PROC, print_seln,
NULL);
window_fit(panel);
window_fit(frame);
server = (Xv_Server)xv_get(xv_get(frame, XV_SCREEN), SCREEN_SERVER);
xv_main_loop(frame);
}
/*
* Get the selection using selection_ask(). Note that if the
* selection is bigger than about 2K, the whole selection will
* not be gotten with one call, thus this method of getting
* the selection may not be sufficient for all situations.
*/
int
print_seln(item, event)
Panel_item item;
Event *event;
{
Seln_holder holder;
Seln_request *response;
char text[BUFSIZ];
/* get the holder of the primary selection */
holder = selection_inquire(server, SELN_PRIMARY);
response = selection_ask(server, &holder,
SELN_REQ_CONTENTS_ASCII, NULL,
NULL);
strcpy(text, response->data + sizeof (SELN_REQ_CONTENTS_ASCII));
printf("–––selection–––\n%s\n–––end seln–––\n", text);
return XV_OK;
}
selection_ask() does not return until it has contacted the server and gotten a response
back from it. This implies that if the server does not respond, the application blocks until
either a time-out occurs or the selection