1Tk_CreateSelHandler(3) Tk Library Procedures Tk_CreateSelHandler(3)
2
3
4
5______________________________________________________________________________
6
8 Tk_CreateSelHandler, Tk_DeleteSelHandler - arrange to handle requests
9 for a selection
10
12 #include <tk.h>
13
14 Tk_CreateSelHandler(tkwin, selection, target, proc, clientData, format)
15
16 Tk_DeleteSelHandler(tkwin, selection, target)
17
19 Tk_Window tkwin (in) Window for which proc will
20 provide selection informa‐
21 tion.
22
23 Atom selection (in) The name of the selection for
24 which proc will provide
25 selection information.
26
27 Atom target (in) Form in which proc can pro‐
28 vide the selection (e.g.
29 STRING or FILE_NAME). Corre‐
30 sponds to type arguments in
31 selection commands.
32
33 Tk_SelectionProc *proc (in) Procedure to invoke whenever
34 the selection is owned by
35 tkwin and the selection con‐
36 tents are requested in the
37 format given by target.
38
39 ClientData clientData (in) Arbitrary one-word value to
40 pass to proc.
41
42 Atom format (in) If the selection requestor
43 isn't in this process, format
44 determines the representation
45 used to transmit the selec‐
46 tion to its requestor.
47_________________________________________________________________
48
49
51 Tk_CreateSelHandler arranges for a particular procedure (proc) to be
52 called whenever selection is owned by tkwin and the selection contents
53 are requested in the form given by target. Target should be one of the
54 entries defined in the left column of Table 2 of the X Inter-Client
55 Communication Conventions Manual (ICCCM) or any other form in which an
56 application is willing to present the selection. The most common form
57 is STRING.
58
59 Proc should have arguments and result that match the type Tk_Selection‐
60 Proc:
61 typedef int Tk_SelectionProc(
62 ClientData clientData,
63 int offset,
64 char *buffer,
65 int maxBytes);
66 The clientData parameter to proc is a copy of the clientData argument
67 given to Tk_CreateSelHandler. Typically, clientData points to a data
68 structure containing application-specific information that is needed to
69 retrieve the selection. Offset specifies an offset position into the
70 selection, buffer specifies a location at which to copy information
71 about the selection, and maxBytes specifies the amount of space avail‐
72 able at buffer. Proc should place a NULL-terminated string at buffer
73 containing maxBytes or fewer characters (not including the terminating
74 NULL), and it should return a count of the number of non-NULL charac‐
75 ters stored at buffer. If the selection no longer exists (e.g. it once
76 existed but the user deleted the range of characters containing it),
77 then proc should return -1.
78
79 When transferring large selections, Tk will break them up into smaller
80 pieces (typically a few thousand bytes each) for more efficient trans‐
81 mission. It will do this by calling proc one or more times, using suc‐
82 cessively higher values of offset to retrieve successive portions of
83 the selection. If proc returns a count less than maxBytes it means
84 that the entire remainder of the selection has been returned. If
85 proc's return value is maxBytes it means there may be additional infor‐
86 mation in the selection, so Tk must make another call to proc to
87 retrieve the next portion.
88
89 Proc always returns selection information in the form of a character
90 string. However, the ICCCM allows for information to be transmitted
91 from the selection owner to the selection requestor in any of several
92 formats, such as a string, an array of atoms, an array of integers,
93 etc. The format argument to Tk_CreateSelHandler indicates what format
94 should be used to transmit the selection to its requestor (see the mid‐
95 dle column of Table 2 of the ICCCM for examples). If format is not
96 STRING, then Tk will take the value returned by proc and divided it
97 into fields separated by white space. If format is ATOM, then Tk will
98 return the selection as an array of atoms, with each field in proc's
99 result treated as the name of one atom. For any other value of format,
100 Tk will return the selection as an array of 32-bit values where each
101 field of proc's result is treated as a number and translated to a
102 32-bit value. In any event, the format atom is returned to the selec‐
103 tion requestor along with the contents of the selection.
104
105 If Tk_CreateSelHandler is called when there already exists a handler
106 for selection and target on tkwin, then the existing handler is
107 replaced with a new one.
108
109 Tk_DeleteSelHandler removes the handler given by tkwin, selection, and
110 target, if such a handler exists. If there is no such handler then it
111 has no effect.
112
113
115 format, handler, selection, target
116
117
118
119Tk 4.0 Tk_CreateSelHandler(3)