1selection(n)                 Tk Built-In Commands                 selection(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       selection - Manipulate the X selection
9

SYNOPSIS

11       selection option ?arg arg ...?
12______________________________________________________________________________
13

DESCRIPTION

15       This  command provides a Tcl interface to the X selection mechanism and
16       implements the full selection functionality described in the  X  Inter-
17       Client Communication Conventions Manual (ICCCM).
18
19       Note  that  for  management of the CLIPBOARD selection (see below), the
20       clipboard command may also be used.
21
22       The first argument to selection determines the format of  the  rest  of
23       the arguments and the behavior of the command.  The following forms are
24       currently supported:
25
26       selection clear ?-displayof window? ?-selection selection?
27              If selection exists anywhere on window's display,  clear  it  so
28              that  no window owns the selection anymore.  Selection specifies
29              the X selection that should be cleared, and should  be  an  atom
30              name such as PRIMARY or CLIPBOARD; see the Inter-Client Communi‐
31              cation  Conventions  Manual  for  complete  details.   Selection
32              defaults  to  PRIMARY  and  window  defaults to “.”.  Returns an
33              empty string.
34
35       selection get ?-displayof window? ?-selection selection? ?-type type?
36              Retrieves the value  of  selection  from  window's  display  and
37              returns  it as a result.  Selection defaults to PRIMARY and win‐
38              dow defaults to “.”.  Type  specifies  the  form  in  which  the
39              selection  is  to  be returned (the desired “target” for conver‐
40              sion, in ICCCM terminology), and should be an atom name such  as
41              STRING  or FILE_NAME; see the Inter-Client Communication Conven‐
42              tions Manual for complete details.   Type  defaults  to  STRING.
43              The selection owner may choose to return the selection in any of
44              several  different  representation  formats,  such  as   STRING,
45              UTF8_STRING,  ATOM, INTEGER, etc. (this format is different than
46              the  selection  type;  see  the  ICCCM  for  all  the  confusing
47              details).   If the selection is returned in a non-string format,
48              such as INTEGER or ATOM, the selection command  converts  it  to
49              string  format  as  a  collection of fields separated by spaces:
50              atoms are converted to their textual names, and anything else is
51              converted to hexadecimal integers.  Note that selection get does
52              not retrieve the selection in the UTF8_STRING format unless told
53              to.
54
55       selection handle ?-selection s? ?-type t? ?-format f? window command
56              Creates a handler for selection requests, such that command will
57              be executed whenever selection s is owned by window and  someone
58              attempts  to  retrieve it in the form given by type t (e.g. t is
59              specified in the selection get command).  S defaults to PRIMARY,
60              t  defaults  to STRING, and f defaults to STRING.  If command is
61              an empty string then any existing handler for window, t,  and  s
62              is  removed.   Note  that  when the selection is handled as type
63              STRING it is also automatically handled as type  UTF8_STRING  as
64              well.
65
66              When  selection is requested, window is the selection owner, and
67              type is the requested type, command will be executed  as  a  Tcl
68              command  with  two additional numbers appended to it (with space
69              separators).  The two additional numbers  are  offset  and  max‐
70              Chars:   offset  specifies  a starting character position in the
71              selection and maxChars gives the maximum number of characters to
72              retrieve.   The  command  should return a value consisting of at
73              most maxChars of the selection,  starting  at  position  offset.
74              For  very  large selections (larger than maxChars) the selection
75              will be retrieved using  several  invocations  of  command  with
76              increasing  offset  values.   If  command returns a string whose
77              length is less than maxChars, the return  value  is  assumed  to
78              include all of the remainder of the selection;  if the length of
79              command's result is equal  to  maxChars  then  command  will  be
80              invoked again, until it eventually returns a result shorter than
81              maxChars.  The value of maxChars will always be relatively large
82              (thousands of characters).
83
84              If  command  returns  an  error  then the selection retrieval is
85              rejected just as if the selection did not exist at all.
86
87              The format argument specifies the representation that should  be
88              used to transmit the selection to the requester (the second col‐
89              umn of Table 2 of the ICCCM), and defaults to STRING.  If format
90              is  STRING,  the selection is transmitted as 8-bit ASCII charac‐
91              ters (i.e.  just in the form returned by command, in the  system
92              encoding; the UTF8_STRING format always uses UTF-8 as its encod‐
93              ing).  If format is ATOM, then the return value from command  is
94              divided  into  fields  separated  by white space;  each field is
95              converted to its atom value, and the 32-bit atom value is trans‐
96              mitted  instead  of  the  atom  name.  For any other format, the
97              return value from command is divided into  fields  separated  by
98              white space and each field is converted to a 32-bit integer;  an
99              array of integers is transmitted to the selection requester.
100
101              The format argument is needed only for compatibility with selec‐
102              tion  requesters  that  do  not  use Tk.  If Tk is being used to
103              retrieve the selection then the value is  converted  back  to  a
104              string at the requesting end, so format is irrelevant.
105
106       selection own ?-displayof window? ?-selection selection?
107
108       selection own ?-command command? ?-selection selection? window
109              The  first  form  of  selection own returns the path name of the
110              window in this application that owns selection  on  the  display
111              containing  window,  or  an  empty  string  if no window in this
112              application owns the selection.  Selection defaults  to  PRIMARY
113              and window defaults to “.”.
114
115              The second form of selection own causes window to become the new
116              owner of selection  on  window's  display,  returning  an  empty
117              string  as  result. The existing owner, if any, is notified that
118              it has lost the selection.  If command is specified, it is a Tcl
119              script to execute when some other window claims ownership of the
120              selection away from window.  Selection defaults to PRIMARY.
121

EXAMPLES

123       On X11 platforms, one of the standard selections available is the  SEC‐
124       ONDARY  selection.  Hardly anything uses it, but here is how to read it
125       using Tk:
126
127              set selContents [selection get -selection SECONDARY]
128
129       Many different types of data may be available for a selection; the spe‐
130       cial type TARGETS allows you to get a list of available types:
131
132              foreach type [selection get -type TARGETS] {
133                 puts "Selection PRIMARY supports type $type"
134              }
135
136       To  claim  the selection, you must first set up a handler to supply the
137       data for the selection. Then you have to claim the selection...
138              # Set up the data handler ready for incoming requests
139              set foo "This is a string with some data in it... blah blah"
140              selection handle -selection SECONDARY . getData
141              proc getData {offset maxChars} {
142                 puts "Retrieving selection starting at $offset"
143                 return [string range $::foo $offset [expr {$offset+$maxChars-1}]]
144              }
145
146              # Now we grab the selection itself
147              puts "Claiming selection"
148              selection own -command lost -selection SECONDARY .
149              proc lost {} {
150                 puts "Lost selection"
151              }
152

SEE ALSO

154       clipboard(n)
155

KEYWORDS

157       clear, format, handler, ICCCM, own, selection, target, type
158
159
160
161Tk                                    8.1                         selection(n)
Impressum