| 1 |
# Copyright (c) 1990-1994 The Regents of the University of California. |
| 2 |
# Copyright (c) 1994-1996 Sun Microsystems, Inc. |
| 3 |
# See the file "license.terms" for information on usage and redistribution |
| 4 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 5 |
# |
| 6 |
# |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
Tk_CreateSelHandler, Tk_DeleteSelHandler - arrange to handle requests for a selection |
| 11 |
|
| 12 |
=for category C Programming |
| 13 |
|
| 14 |
=head1 SYNOPSIS |
| 15 |
|
| 16 |
B<#include E<lt>tk.hE<gt>> |
| 17 |
|
| 18 |
B<Tk_CreateSelHandler>(I<tkwin, selection, target, proc, clientData, format>) |
| 19 |
|
| 20 |
B<Tk_DeleteSelHandler>(I<tkwin, selection, target>) |
| 21 |
|
| 22 |
=head1 ARGUMENTS |
| 23 |
|
| 24 |
=over 4 |
| 25 |
|
| 26 |
=item Tk_Window tkwin (in) |
| 27 |
|
| 28 |
Window for which I<proc> will provide selection information. |
| 29 |
|
| 30 |
=item Atom selection (in) |
| 31 |
|
| 32 |
The name of the selection for which I<proc> will provide |
| 33 |
selection information. |
| 34 |
|
| 35 |
=item Atom target (in) |
| 36 |
|
| 37 |
Form in which I<proc> can provide the selection (e.g. STRING |
| 38 |
or FILE_NAME). Corresponds to I<type> arguments in B<selection> |
| 39 |
commands. |
| 40 |
|
| 41 |
=item Tk_SelectionProc *proc (in) |
| 42 |
|
| 43 |
Procedure to invoke whenever the selection is owned by I<tkwin> |
| 44 |
and the selection contents are requested in the format given by |
| 45 |
I<target>. |
| 46 |
|
| 47 |
=item ClientData clientData (in) |
| 48 |
|
| 49 |
Arbitrary one-word value to pass to I<proc>. |
| 50 |
|
| 51 |
=item Atom format (in) |
| 52 |
|
| 53 |
If the selection requestor isn't in this process, I<format> determines |
| 54 |
the representation used to transmit the selection to its |
| 55 |
requestor. |
| 56 |
|
| 57 |
=back |
| 58 |
|
| 59 |
=head1 DESCRIPTION |
| 60 |
|
| 61 |
B<Tk_CreateSelHandler> arranges for a particular procedure |
| 62 |
(I<proc>) to be called whenever I<selection> is owned by |
| 63 |
I<tkwin> and the selection contents are requested in the |
| 64 |
form given by I<target>. |
| 65 |
I<Target> should be one of |
| 66 |
the entries defined in the left column of Table 2 of the |
| 67 |
X Inter-Client Communication Conventions Manual (ICCCM) or |
| 68 |
any other form in which an application is willing to present |
| 69 |
the selection. The most common form is STRING. |
| 70 |
|
| 71 |
I<Proc> should have arguments and result that match the |
| 72 |
type B<Tk_SelectionProc>: |
| 73 |
|
| 74 |
typedef int Tk_SelectionProc( |
| 75 |
ClientData clientData, |
| 76 |
int offset, |
| 77 |
char *buffer, |
| 78 |
int maxBytes); |
| 79 |
|
| 80 |
The I<clientData> parameter to I<proc> is a copy of the |
| 81 |
I<clientData> argument given to B<Tk_CreateSelHandler>. |
| 82 |
Typically, I<clientData> points to a data |
| 83 |
structure containing application-specific information that is |
| 84 |
needed to retrieve the selection. I<Offset> specifies an |
| 85 |
offset position into the selection, I<buffer> specifies a |
| 86 |
location at which to copy information about the selection, and |
| 87 |
I<maxBytes> specifies the amount of space available at |
| 88 |
I<buffer>. I<Proc> should place a NULL-terminated string |
| 89 |
at I<buffer> containing I<maxBytes> or fewer characters |
| 90 |
(not including the terminating NULL), and it should return a |
| 91 |
count of the number of non-NULL characters stored at |
| 92 |
I<buffer>. If the selection no longer exists (e.g. it once |
| 93 |
existed but the user deleted the range of characters containing |
| 94 |
it), then I<proc> should return -1. |
| 95 |
|
| 96 |
When transferring large selections, Tk will break them up into |
| 97 |
smaller pieces (typically a few thousand bytes each) for more |
| 98 |
efficient transmission. It will do this by calling I<proc> |
| 99 |
one or more times, using successively higher values of I<offset> |
| 100 |
to retrieve successive portions of the selection. If I<proc> |
| 101 |
returns a count less than I<maxBytes> it means that the entire |
| 102 |
remainder of the selection has been returned. If I<proc>'s return |
| 103 |
value is I<maxBytes> it means there may be additional information |
| 104 |
in the selection, so Tk must make another call to I<proc> to |
| 105 |
retrieve the next portion. |
| 106 |
|
| 107 |
I<Proc> always returns selection information in the form of a |
| 108 |
character string. However, the ICCCM allows for information to |
| 109 |
be transmitted from the selection owner to the selection requestor |
| 110 |
in any of several formats, such as a string, an array of atoms, an |
| 111 |
array of integers, etc. The I<format> argument to |
| 112 |
B<Tk_CreateSelHandler> indicates what format should be used to |
| 113 |
transmit the selection to its requestor (see the middle column of |
| 114 |
Table 2 of the ICCCM for examples). If I<format> is not |
| 115 |
STRING, then Tk will take the value returned by I<proc> and divided |
| 116 |
it into fields separated by white space. If I<format> is ATOM, |
| 117 |
then Tk will return the selection as an array of atoms, with each |
| 118 |
field in I<proc>'s result treated as the name of one atom. For |
| 119 |
any other value of I<format>, Tk will return the selection as an |
| 120 |
array of 32-bit values where each field of I<proc>'s result is |
| 121 |
treated as a number and translated to a 32-bit value. In any event, |
| 122 |
the I<format> atom is returned to the selection requestor along |
| 123 |
with the contents of the selection. |
| 124 |
|
| 125 |
If B<Tk_CreateSelHandler> is called when there already exists a |
| 126 |
handler for I<selection> and I<target> on I<tkwin>, then the |
| 127 |
existing handler is replaced with a new one. |
| 128 |
|
| 129 |
B<Tk_DeleteSelHandler> removes the handler given by I<tkwin>, |
| 130 |
I<selection>, and I<target>, if such a handler exists. |
| 131 |
If there is no such handler then it has no effect. |
| 132 |
|
| 133 |
=head1 KEYWORDS |
| 134 |
|
| 135 |
format, handler, selection, target |