Debian Codegraph @

man/dragdrop.mann

raw
1 '\"
2 '\" Copyright 1991-1997 by Bell Labs Innovations for Lucent Technologies.
3 '\"
4 '\" Permission to use, copy, modify, and distribute this software and its
5 '\" documentation for any purpose and without fee is hereby granted, provided
6 '\" that the above copyright notice appear in all copies and that both that the
7 '\" copyright notice and warranty disclaimer appear in supporting documentation,
8 '\" and that the names of Lucent Technologies any of their entities not be used
9 '\" in advertising or publicity pertaining to distribution of the software
10 '\" without specific, written prior permission.
11 '\"
12 '\" Lucent Technologies disclaims all warranties with regard to this software,
13 '\" including all implied warranties of merchantability and fitness. In no event
14 '\" shall Lucent Technologies be liable for any special, indirect or
15 '\" consequential damages or any damages whatsoever resulting from loss of use,
16 '\" data or profits, whether in an action of contract, negligence or other
17 '\" tortuous action, arising out of or in connection with the use or performance
18 '\" of this software.
19 '\"
20 '\"
21 .so man.macros
22 .TH drag&drop n BLT_VERSION BLT "BLT Built-In Commands"
23 .BS
24 '\" Note: do not modify the .SH NAME line immediately below!
25 .SH NAME
26 drag&drop \- facilities for handling drag&drop data transfers
27 .SH SYNOPSIS
28 \fBdrag&drop source
29 .br
30 \fBdrag&drop source \fIwindow \fR?\fIoptions\fR?
31 .br
32 \fBdrag&drop source \fIwindow \fBhandler \fR?\fIdataType\fR? ?\fIcommand arg arg...\fR?
33 .sp
34 \fBdrag&drop target
35 .br
36 \fBdrag&drop target \fIwindow \fBhandler \fR?\fIdataType command arg arg...\fR?
37 .sp
38 \fBdrag&drop target \fIwindow \fBhandle \fIdataType\fR ?\fIvalue\fR?
39 .sp
40 \fBdrag&drop token \fIwindow
41 .sp
42 \fBdrag&drop drag \fIwindow x y
43 .br
44 \fBdrag&drop drop \fIwindow x y
45 .br
46 \fBdrag&drop active
47 .br
48 \fBdrag&drop errors \fR?\fIproc\fR?
49 .br
50 \fBdrag&drop location \fR?\fIx y\fR?
51 .BE
52
53 .SH DESCRIPTION
54 .PP
55 The \fBdrag&drop\fR command provides access to a set of facilities
56 for managing drag-and-drop data transfers. Any of the usual Tk widgets can
57 be registered to participate in the drag-and-drop process. Widgets
58 registered as a drag&drop \fIsource\fP can export data to other widgets
59 registered as a drag&drop \fItarget\fP. Note that a particular widget
60 can be registered as a source, as a target, or as both.
61 .PP
62 The drag-and-drop process begins when the user clicks and holds a mouse
63 button in a source window; a token window appears with an icon or message
64 to represent the data being transferred. As the user moves the mouse pointer,
65 the token window follows along, acting as a movable packet of data.
66 Whenever the mouse pointer falls on a valid target window, the border of the
67 token window is changed to a raised (active) state. When the mouse button is
68 released over the target window, a Tcl routine is invoked to send the data
69 to the desired application, and the target window is asked to "handle"
70 the data. If this communication process fails, a rejection symbol (a
71 circle with a line through it) is displayed on the token window to
72 indicate failure.
73 .PP
74 The details of the communication process are fully configurable by the
75 application developer. In the simplest case, the value that is sent
76 to the target window is a simple string. The target window is simply
77 asked to "handle" that string value. In general, the source window
78 can have a special "handler" procedure to transfer a particular data
79 type by issuing a series of "send" commands. After this, the target
80 window is again asked to "handle" the result.
81 .PP
82 Both sources and targets can have a list of "handlers" for different
83 data types. As a token window is dragged from its source to various
84 targets, each target is checked to see if it recognizes a handler
85 offered by the source. If it does, it is treated as a valid target.
86 Otherwise, it is ignored. This scheme allows the same source to
87 interact with many different kinds of targets. For example, a source
88 for RGB color samples might have "color" and "string" handlers. This
89 would allow it to communicate with "color" targets (sending RGB data)
90 as well as entry widgets (sending strings of the form "#rrggbb").
91 .PP
92 This introduction was presented as a brief overview of the communication
93 process; further details are presented below:
94 .TP
95 \fBdrag&drop source\fR
96 Returns a list of path names for widgets registered as drag&drop
97 sources. Returns an empty string if no widgets have been registered.
98 .TP
99 \fBdrag&drop source \fIwindow \fR?\fIoptions\fR?
100 Registers a new drag&drop source window with the given options, or
101 modifies the options for an existing window:
102 .RS
103 .LP
104 .nf
105 Name: \fBbuttonBinding\fR
106 Class: \fBButtonBinding\fR
107 Switch: \fB\-button\fR \fIn\fR
108 .fi
109 .IP
110 Specifies the mouse button (integer 1-5) that will invoke the drag&drop
111 operation on the source window. This causes the following bindings to
112 be added to the widget:
113 .sp
114 .nf
115 .RS
116 \fBbind \fIwin\fP <ButtonPress-\fIn\fP> {drag&drop drag %W %X %Y}
117 \fBbind \fIwin\fP <B\fIn\fP-Motion> {drag&drop drag %W %X %Y}
118 \fBbind \fIwin\fP <ButtonRelease-\fIn\fP> {drag&drop drop %W %X %Y}\fR
119 .RE
120 .fi
121 .sp
122 The default value is button 3. If the value "0" is specified, then no
123 bindings are added; this enables the user to establish bindings
124 manually.
125 .LP
126 .nf
127 Name: \fBpackageCommand\fR
128 Class: \fBCommand\fR
129 Switch: \fB\-packagecmd \fIcommand\fR
130 .fi
131 .IP
132 Specifies a Tcl command used to establish the appearance of the token
133 window at the start of each drag&drop operation. This command is
134 automatically invoked by the \fBdrag&drop drag\fP command whenever the
135 token window is about to be mapped for a drag operation. It should
136 update the appearance of the token window to represent the data that
137 is being moved.
138 .PP
139 The following substitutions are made in the \fIcommand\fR string
140 before it is executed:
141 .RS
142 .TP
143 \fB%t\fR
144 Replaced with the window path name for the token which represents
145 the data being dragged.
146 .TP
147 \fB%W\fR
148 Replaced with the window path name for the drag&drop source.
149 .RE
150 .LP
151 The return value from the package command represents the data being
152 transferred. If the package command returns an empty string, the
153 drag operation is quietly aborted. This can be used to disallow
154 drag&drop operations from certain parts of a widget, if the drag
155 position is inappropriate.
156 .LP
157 For example, the following package routine will select an item
158 from a listbox and configure the token window to display the selected
159 string. It uses the \fBdrag&drop location\fR command to
160 determine the entry in the listbox that the user has selected
161 and it returns this as the data value:
162 .sp
163 .nf
164 .RS
165 \fBproc package_list_item {lbox token} {
166 set xy [drag&drop location]
167 set y [expr [lindex $xy 1]-[winfo rooty $lbox]]
168
169 set str [$lbox get [$lbox nearest $y]]
170 $token.value configure -text $str
171 return $str
172 }\fR
173 .RE
174 .fi
175 .sp
176 The return value is available later when the source and target
177 communicate. If the source has a command associated with its
178 data handler, then this value is substituted in place of "%v"
179 in the source handler. Otherwise, it is substituted in place
180 of "%v" in the target handler.
181 .LP
182 .nf
183 Name: \fBrejectBackground\fR
184 Class: \fBBackground\fR
185 Switch: \fB\-rejectbg \fIcolor\fR
186 .fi
187 .IP
188 Specifies the color used to draw the background of the rejection symbol
189 on the token window. The rejection symbol (a circle with a line through
190 it--the international "no") appears whenever communication fails.
191 .LP
192 .nf
193 Name: \fBrejectForeground\fR
194 Class: \fBForeground\fR
195 Switch: \fB\-rejectfg \fIcolor\fR
196 .fi
197 .IP
198 Specifies the color used to draw the foreground of the rejection symbol
199 on the token window.
200 .LP
201 .nf
202 Name: \fBrejectStipple\fR
203 Class: \fBStipple\fR
204 Switch: \fB\-rejectstipple \fIpattern\fR
205 .fi
206 .IP
207 Specifies a stipple pattern used to draw the foreground of the rejection
208 symbol on the token window. Any of the forms acceptable to Tk_GetBitmap
209 can be used.
210 .LP
211 .nf
212 Name: \fBselfTarget\fR
213 Class: \fBSelfTarget\fR
214 Switch: \fB\-selftarget \fIboolean\fR
215 .fi
216 .IP
217 If the \fIboolean\fR value is true, and if a source widget is also
218 registered as a compatible target, then the source will be able to transmit
219 to itself during drag&drop operations. This is primarily useful for
220 complex sources such as a canvas widget, where items may be moved from
221 place to place within the same widget. By default, this option is disabled.
222 .LP
223 .nf
224 Name: \fBsend\fR
225 Class: \fBSend\fR
226 Switch: \fB\-send \fIlist\fR
227 .fi
228 .IP
229 Specifies a \fIlist\fR of \fIdataTypes\fR enabled for communication. Only
230 \fIdataTypes\fR defined by commands of the form "\fBdrag&drop source
231 \fIwindow \fBhandler \fR?\fIdataType\fR ?\fIcommand arg arg...\fR?" are
232 allowed. This list also determines the priority of the various
233 \fIdataTypes\fR.
234 When a token window is over a potential drag&drop target, this list is
235 searched from start to finish for a \fIdataType\fR that is also recognized
236 by the target. The first matching \fIdataType\fR found determines the
237 value that will be sent if the token is dropped. If no matching \fIdataType\fR
238 is found, then the target is incompatible, and is ignored. By default,
239 this option has the value "all", indicating that all \fIdataTypes\fR should
240 be considered in the order that they were defined for the source.
241 .LP
242 Note that this option makes it easy to control a drag&drop source. Setting
243 the value to an empty string disables the source; setting the value back
244 to "all" restores communication.
245 .LP
246 .nf
247 Name: \fBsiteCommand\fR
248 Class: \fBCommand\fR
249 Switch: \fB\-sitecmd \fIcommand\fR
250 .fi
251 .IP
252 Specifies a Tcl command used to update the appearance of the token window.
253 If specified, this command is automatically invoked by the
254 \fBdrag&drop drag\fP command whenever the token window is over a
255 compatible drag&drop target.
256 .PP
257 The following substitutions are made in the \fIcommand\fR string
258 before it is executed:
259 .RS
260 .TP
261 \fB%s\fR
262 Replaced with "1" if the token window is over a compatible target,
263 and "0" otherwise.
264 .TP
265 \fB%t\fR
266 Replaced with the window path name for the token which represents
267 the data being dragged.
268 .RE
269 .LP
270 Regardless of this command, border of the token window will become
271 raised whenever the token is over a valid target. This command
272 can be used to display other visual cues.
273 .LP
274 .nf
275 Name: \fBtokenAnchor\fR
276 Class: \fBAnchor\fR
277 Switch: \fB\-tokenanchor \fIanchor\fR
278 .fi
279 .IP
280 Specifies how the token window is positioned relative to the mouse
281 pointer coordinates passed to the \fBdrag&drop drag\fP command.
282 Must be one of the values n, s, e, w, center, nw, ne, sw or se.
283 For example, "nw" means to position the token such that its upper-left
284 corner is at the mouse pointer. The default value is "center".
285 .LP
286 .nf
287 Name: \fBtokenBackground\fR
288 Class: \fBBackground\fR
289 Switch: \fB\-tokenbg \fIcolor\fR
290 .fi
291 .IP
292 Specifies the color used to draw the background of the token window.
293 .LP
294 .nf
295 Name: \fBtokenBorderWidth\fR
296 Class: \fBBorderWidth\fR
297 Switch: \fB\-tokenborderwidth \fIsize\fR
298 .fi
299 .IP
300 Specifies the width in pixels of the border around the token window.
301 This border becomes raised to indicate when the token is over a compatible
302 drag&drop target site. The value may have any of the forms acceptable
303 to Tk_GetPixels. The default value is "3".
304 .LP
305 .nf
306 Name: \fBtokenCursor\fR
307 Class: \fBCursor\fR
308 Switch: \fB\-tokencursor \fIcursor\fR
309 .fi
310 .IP
311 Specifies the cursor used when a token window is active. The value
312 may have any of the forms acceptable to Tk_GetCursor. The default
313 value is "center_ptr".
314 .RE
315 .TP
316 \fBdrag&drop source \fIwindow \fBhandler \fR?\fIdataType\fR? ?\fIcommand arg arg...\fR?
317 With no extra arguments, this command returns a list of all \fIdataType\fR
318 names that have been registered for the source \fIwindow\fR. If only the
319 \fIdataType\fR is specified, then the \fIdataType\fR is created if
320 necessary, and the command associated with the \fIdataType\fR is returned.
321 Otherwise, it concatenates the \fIcommand\fR and any extra \fIarg\fR strings,
322 and registers a new \fIdataType\fR with this command.
323 .PP
324 The following substitutions are made in the \fIcommand\fR string
325 before it is executed:
326 .RS
327 .TP
328 \fB%i\fR
329 Replaced with the name of the interpreter for the target application.
330 .TP
331 \fB%v\fR
332 Replaced with the value returned from the "-packagecmd" command.
333 .TP
334 \fB%w\fR
335 Replaced with the window path name for the target window.
336 .RE
337 .LP
338 A typical source handler contains one or more "send" commands which
339 transfer data to the remote application. The target window is then
340 asked to handle the new data. Whatever value is returned by the
341 source \fIcommand\fR handler is automatically substituted into the
342 "%v" fields of the target handler.
343 .LP
344 This separation between the transfer and the handling of the data is
345 important. It allows the same source handler to transfer data for
346 many different targets, and it allows each of the targets to handle
347 the incoming data differently. If an error is encountered during the
348 communication process, the rejection symbol is posted on the token window
349 to indicate failure.
350 .RE
351 .sp
352 .TP
353 \fBdrag&drop target\fR
354 Returns a list of path names for widgets registered as drag&drop
355 targets. Returns an empty string if no widgets have been registered.
356 .TP
357 \fBdrag&drop target \fIwindow \fBhandler \fR?\fIdataType command arg arg...\fR?
358 Registers a new drag&drop target window with a given handler, or
359 modifies the handlers for an existing window. If no \fIdataType\fR
360 is specified, this command returns the current list of recognized
361 \fIdataType\fR strings. Each \fIdataType\fR is a symbolic name
362 representing a form of data, and the corresponding \fIcommand\fR is
363 a Tcl command that specifies how the target will make use of the data.
364 This command is invoked indirectly after a source has transferred data
365 to a target application.
366 .PP
367 The following substitutions are made in the \fIcommand\fR string
368 before it is executed:
369 .RS
370 .TP
371 \fB%v\fR
372 In the simplest case, the source window does not have a handler command
373 for the selected \fIdataType\fR, and this field is replaced with the
374 result from the "-packagecmd" command. When the source does have a
375 handler command, the result from the "-packagecmd" command is substituted
376 into its "%v" field, and the result from this command is substituted
377 into this field in the target command.
378 .TP
379 \fB%W\fR
380 Replaced with the window path name for the target window.
381 .RE
382 .TP
383 \fBdrag&drop target \fIwindow \fRhandle \fIdataType\fR ?\fIvalue\fR?
384 Searches for the given \fIdataType\fR name among the handlers registered
385 for the target \fIwindow\fR, and invokes the appropriate \fIcommand\fR.
386 If a \fIvalue\fR is specified, it is substituted into any "%v" fields
387 in the handler command associated with the \fIdataType\fR. If the
388 \fIdataType\fR name is not recognized, this command returns an error.
389 This command is invoked automatically by the drag&drop facility when
390 data is being transferred from a source to a target.
391 .TP
392 \fBdrag&drop token \fIwindow\fR
393 Returns the token window associated with a drag&drop source \fIwindow\fR.
394 The token window is used to represent data as it is being dragged from
395 the source to a target. When a source is first established, its token
396 window must be filled with widgets to display the source data. For
397 example,
398 .sp
399 .nf
400 .RS
401 \fBdrag&drop source .foo
402
403 set win [drag&drop token .foo]
404 label $win.label -text "Data"
405 pack $win.label\fR
406 .RE
407 .fi
408 .sp
409 .TP
410 \fBdrag&drop drag \fIwindow x y\fR
411 Marks the start of (or movement during) a drag&drop operation. If
412 the token window is unmapped when this command is invoked, then the
413 \fB\-packagecmd\fR for the source \fIwindow\fR is executed. If this
414 command is successful and returns a non-null string, the token window
415 is mapped. On subsequent calls, the token window is moved to the new
416 \fIx y\fR location. Unless the "\fB\-button 0\fR" option is specified for
417 the source, this command is automatically bound to <ButtonPress-\fIn\fR>
418 and <B\fIn\fR-Motion> events for "\fB\-button \fIn\fR" of the source widget.
419 .TP
420 \fBdrag&drop drop \fIwindow x y\fR
421 Marks the end of a drag&drop operation. If the mouse pointer is
422 over a compatible target window, then the appropriate send handler for
423 the first compatible \fIdataType\fR is invoked to handle the data transfer.
424 If the data transfer is successful, then the token window is unmapped;
425 otherwise, a rejection symbol is drawn on the token window, and the window
426 is unmapped after a small delay. Unless the "\fB\-button 0\fR" option is
427 specified for the source, this command is automatically bound to the
428 <ButtonRelease-\fIn\fR> event for "\fB\-button \fIn\fR" of the source widget.
429 .TP
430 \fBdrag&drop active\fR
431 Returns "1" if a drag&drop operation is in progress, and "0" otherwise.
432 A drag&drop operation officially starts after the package command has
433 been executed successfully, and ends after the send handler has been
434 executed (successfully or otherwise).
435 .TP
436 \fBdrag&drop errors \fR?\fIproc\fR?
437 Specifies a Tcl \fIproc\fR used to handle errors encountered during
438 drag&drop operations. If a \fIproc\fR is not specified, this command
439 returns the current error handler. By default, all errors are sent
440 to the usual \fBtkerror\fR command, and therefore appear in a dialog
441 box to the user. This behavior is quite useful when debugging
442 communication protocols, but may not be desirable in a finished
443 application. Errors can be suppressed entirely (leaving the rejection
444 symbol as the only error indicator) by specifying a null string in
445 place of the \fIproc\fR name.
446 .TP
447 \fBdrag&drop location \fR?\fIx y\fR?
448 Used to set or query the pointer location during a drag&drop operation.
449 The \fIx y\fR arguments specify the current location; if these arguments
450 are missing, then the last reported (x,y) location is returned as a list
451 with two elements. This command is issued automatically within the
452 \fBdrag&drop drag\fR and \fBdrag&drop drop\fR commands, to
453 keep track of pointer movement.
454
455 .SH KEYWORDS
456 drag&drop, send, bind, widget