The first argument to selection determines the format of the rest of the arguments and the behavior of the procedure. The following forms are currently supported:
When selection is requested, window is the selection owner, and type is the requested type, procedure will be applied as a STk procedure with a list of two numbers. The two additional numbers are offset and maxBytes: offset specifies a starting character position in the selection and maxBytes gives the maximum number of bytes to retrieve. The procedure should return a value consisting of at most maxBytes of the selection, starting at position offset. For very large selections (larger than maxBytes) the selection will be retrieved using several invocations of procedure with increasing offset values. If procedure returns a string whose length is less than maxBytes, the return value is assumed to include all of the remainder of the selection; if the length of procedure's result is equal to maxBytes then procedure will be invoked again, until it eventually returns a result shorter than maxBytes. The value of maxBytes will always be relatively large (thousands of bytes).
If procedure returns an error then the selection retrieval is rejected just as if the selection didn't exist at all.
The format argument specifies the representation that should be used to transmit the selection to the requester (the second column of Table 2 of the ICCCM), and defaults to STRING. If format is STRING, the selection is transmitted as 8-bit ASCII characters (i.e. just in the form returned by procedure). If format is ATOM, then the return value from procedure is divided into fields separated by white space; each field is converted to its atom value, and the 32-bit atom value is transmitted instead of the atom name. For any other format, the return value from procedure is divided into fields separated by white space and each field is converted to a 32-bit integer; an array of integers is transmitted to the selection requester.
The format argument is needed only for compatibility with selection requesters that don't use Tk. If Tk is being used to retrieve the selection then the value is converted back to a string at the requesting end, so format is irrelevant.
The second form of selection own causes window to become
the new owner of selection on window's display, returning
an empty list as result. The existing owner, if any, is notified
that it has lost the selection.
If procedure is specified, it is a STk script to execute when
some other window claims ownership of the selection away from
window. Selection defaults to "PRIMARY".