selection.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:8k
- '"
- '" Copyright (c) 1990-1994 The Regents of the University of California.
- '" Copyright (c) 1994-1996 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: selection.n,v 1.4.4.1 2004/10/28 12:25:22 dkf Exp $
- '"
- .so man.macros
- .TH selection n 8.1 Tk "Tk Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- selection - Manipulate the X selection
- .SH SYNOPSIS
- fBselection fIoptionfR ?fIarg arg ...fR?
- .BE
- .SH DESCRIPTION
- .PP
- This command provides a Tcl interface to the X selection mechanism and
- implements the full selection functionality described in the
- X Inter-Client Communication Conventions Manual (ICCCM).
- .PP
- Note that for management of the CLIPBOARD selection (see below), the
- fBclipboardfR command may also be used.
- .PP
- The first argument to fBselectionfR determines the format of the
- rest of the arguments and the behavior of the command. The following
- forms are currently supported:
- .PP
- .TP
- fBselection clearfR ?fB-displayoffR fIwindowfR? ?fB-selectionfR fIselectionfR?
- If fIselectionfR exists anywhere on fIwindowfR's display, clear it
- so that no window owns the selection anymore. fISelectionfR
- specifies the X selection that should be cleared, and should be an
- atom name such as PRIMARY or CLIPBOARD; see the Inter-Client
- Communication Conventions Manual for complete details.
- fISelectionfR defaults to PRIMARY and fIwindowfR defaults to ``.''.
- Returns an empty string.
- .TP
- fBselection getfR ?fB-displayoffR fIwindowfR? ?fB-selectionfR fIselectionfR? ?fB-typefR fItypefR?
- Retrieves the value of fIselectionfR from fIwindowfR's display and
- returns it as a result. fISelectionfR defaults to PRIMARY and
- fIwindowfR defaults to ``.''.
- fITypefR specifies the form in which the selection is to be returned
- (the desired ``target'' for conversion, in ICCCM terminology), and
- should be an atom name such as STRING or FILE_NAME; see the
- Inter-Client Communication Conventions Manual for complete details.
- fITypefR defaults to STRING. The selection owner may choose to
- return the selection in any of several different representation
- formats, such as STRING, ATOM, INTEGER, etc. (this format is different
- than the selection type; see the ICCCM for all the confusing details).
- If the selection is returned in a non-string format, such as INTEGER
- or ATOM, the fBselectionfR command converts it to string format as a
- collection of fields separated by spaces: atoms are converted to their
- textual names, and anything else is converted to hexadecimal integers.
- .TP
- fBselection handlefR ?fB-selectionfR fIselectionfR? ?fB-typefR fItypefR? ?fB-formatfR fIformatfR? fIwindow commandfR
- Creates a handler for selection requests, such that fIcommandfR will
- be executed whenever fIselectionfR is owned by fIwindowfR and
- someone attempts to retrieve it in the form given by fItypefR
- (e.g. fItypefR is specified in the fBselection getfR command).
- fISelectionfR defaults to PRIMARY, fItypefR defaults to STRING, and
- fIformatfR defaults to STRING. If fIcommandfR is an empty string
- then any existing handler for fIwindowfR, fItypefR, and
- fIselectionfR is removed.
- .RS
- .PP
- When fIselectionfR is requested, fIwindowfR is the selection owner,
- and fItypefR is the requested type, fIcommandfR will be executed
- as a Tcl command with two additional numbers appended to it
- (with space separators).
- The two additional numbers
- .VS
- are fIoffsetfR and fImaxCharsfR: fIoffsetfR specifies a starting
- character position in the selection and fImaxCharsfR gives the maximum
- number of characters to retrieve. The command should return a value consisting
- of at most fImaxCharsfR of the selection, starting at position
- fIoffsetfR. For very large selections (larger than fImaxCharsfR)
- the selection will be retrieved using several invocations of fIcommandfR
- with increasing fIoffsetfR values. If fIcommandfR returns a string
- whose length is less than fImaxCharsfR, the return value is assumed to
- include all of the remainder of the selection; if the length of
- fIcommandfR's result is equal to fImaxCharsfR then
- fIcommandfR will be invoked again, until it eventually
- returns a result shorter than fImaxCharsfR. The value of fImaxCharsfR
- will always be relatively large (thousands of characters).
- .VE
- .PP
- If fIcommandfR returns an error then the selection retrieval is rejected
- just as if the selection didn't exist at all.
- .PP
- The fIformatfR 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 fIformatfR is
- STRING, the selection is transmitted as 8-bit ASCII characters (i.e.
- just in the form returned by fIcommandfR). If fIformatfR is
- ATOM, then the return value from fIcommandfR 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 fIformatfR, the return value from fIcommandfR 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.
- .PP
- The fIformatfR 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 fIformatfR is
- irrelevant.
- .RE
- .TP
- fBselection ownfR ?fB-displayoffR fIwindowfR? ?fB-selectionfR fIselectionfR?
- .TP
- fBselection ownfR ?fB-commandfR fIcommandfR? ?fB-selectionfR fIselectionfR? fIwindowfR
- The first form of fBselection ownfR returns the path name of the
- window in this application that owns fIselectionfR on the display
- containing fIwindowfR, or an empty string if no window in this
- application owns the selection. fISelectionfR defaults to PRIMARY and
- fIwindowfR defaults to ``.''.
- .PP
- The second form of fBselection ownfR causes fIwindowfR to become
- the new owner of fIselectionfR on fIwindowfR's display, returning
- an empty string as result. The existing owner, if any, is notified
- that it has lost the selection.
- If fIcommandfR is specified, it is a Tcl script to execute when
- some other window claims ownership of the selection away from
- fIwindowfR. fISelectionfR defaults to PRIMARY.
- .SH EXAMPLES
- On X11 platforms, one of the standard selections available is the
- SECONDARY selection. Hardly anything uses it, but here is how to read
- it using Tk:
- .CS
- set selContents [fBselection getfR -selection SECONDARY]
- .CE
- .PP
- Many different types of data may be available for a selection; the
- special type TARGETS allows you to get a list of available types:
- .CS
- foreach type [fBselection getfR -type TARGETS] {
- puts "Selection PRIMARY supports type $type"
- }
- .CE
- .PP
- To claim the selection, you must first set up a handler to supply the
- data for the selection. Then you have to claim the selection...
- .CS
- # Set up the data handler ready for incoming requests
- set foo "This is a string with some data in it... blah blah"
- fBselection handlefR -selection SECONDARY . getData
- proc getData {offset maxChars} {
- puts "Retrieving selection starting at $offset"
- return [string range $::foo $offset [expr {$offset+$maxChars}]]
- }
- # Now we grab the selection itself
- puts "Claiming selection"
- fBselection ownfR -command lost -selection SECONDARY .
- proc lost {} {
- puts "Lost selection"
- }
- .CE
- .SH "SEE ALSO"
- clipboard(n)
- .SH KEYWORDS
- clear, format, handler, ICCCM, own, selection, target, type