Debian Codegraph @

html/dragdrop.html

raw symbols SCIP
1 <!-- manual page source format generated by PolyglotMan v3.0.8+XFree86, -->
2 <!-- available via anonymous ftp from ftp.cs.berkeley.edu:/ucb/people/phelps/tcltk/rman.tar.Z -->
3
4 <HTML>
5 <HEAD>
6 <TITLE>drag&drop(n) manual page</TITLE>
7 </HEAD>
8 <BODY BGCOLOR="#efefef" TEXT="black" LINK="blue" VLINK="#551A8B" ALINK="red">
9 <A HREF="#toc">Table of Contents</A><P>
10
11 <H2><A NAME="sect0" HREF="#toc0">Name</A></H2>
12 drag&amp;drop - facilities for handling drag&amp;drop data
13 transfers
14 <H2><A NAME="sect1" HREF="#toc1">Synopsis</A></H2>
15 <B>drag&amp;drop source </B><BR>
16 <B>drag&amp;drop source <I>window </I></B>?<I>options</I>? <BR>
17 <B>drag&amp;drop source <I>window <B>handler </B></I></B>?<I>dataType</I>? ?<I>command arg arg...</I>? <P>
18 <B>drag&amp;drop target
19 </B><BR>
20 <B>drag&amp;drop target <I>window <B>handler </B></I></B>?<I>dataType command arg arg...</I>? <P>
21 <B>drag&amp;drop target
22 <I>window <B>handle <I>dataType</I></B></I></B> ?<I>value</I>? <P>
23 <B>drag&amp;drop token <I>window </I></B><P>
24 <B>drag&amp;drop drag <I>window
25 x y </I></B><BR>
26 <B>drag&amp;drop drop <I>window x y </I></B><BR>
27 <B>drag&amp;drop active </B><BR>
28 <B>drag&amp;drop errors </B>?<I>proc</I>? <BR>
29 <B>drag&amp;drop location </B>?<I>x y</I>? <P>
30
31 <H2><A NAME="sect2" HREF="#toc2">Description</A></H2>
32 <P>
33 The <B>drag&amp;drop</B> command provides access
34 to a set of facilities for managing drag-and-drop data transfers. Any of
35 the usual Tk widgets can be registered to participate in the drag-and-drop
36 process. Widgets registered as a drag&amp;drop <I>source</I> can export data to other
37 widgets registered as a drag&amp;drop <I>target</I>. Note that a particular widget
38 can be registered as a source, as a target, or as both. <P>
39 The drag-and-drop
40 process begins when the user clicks and holds a mouse button in a source
41 window; a token window appears with an icon or message to represent the
42 data being transferred. As the user moves the mouse pointer, the token
43 window follows along, acting as a movable packet of data. Whenever the mouse
44 pointer falls on a valid target window, the border of the token window
45 is changed to a raised (active) state. When the mouse button is released
46 over the target window, a Tcl routine is invoked to send the data to the
47 desired application, and the target window is asked to "handle" the data.
48 If this communication process fails, a rejection symbol (a circle with
49 a line through it) is displayed on the token window to indicate failure.
50 <P>
51 The details of the communication process are fully configurable by the
52 application developer. In the simplest case, the value that is sent to
53 the target window is a simple string. The target window is simply asked
54 to "handle" that string value. In general, the source window can have a
55 special "handler" procedure to transfer a particular data type by issuing
56 a series of "send" commands. After this, the target window is again asked
57 to "handle" the result. <P>
58 Both sources and targets can have a list of "handlers"
59 for different data types. As a token window is dragged from its source
60 to various targets, each target is checked to see if it recognizes a handler
61 offered by the source. If it does, it is treated as a valid target. Otherwise,
62 it is ignored. This scheme allows the same source to interact with many
63 different kinds of targets. For example, a source for RGB color samples
64 might have "color" and "string" handlers. This would allow it to communicate
65 with "color" targets (sending RGB data) as well as entry widgets (sending
66 strings of the form "#rrggbb"). <P>
67 This introduction was presented as a brief
68 overview of the communication process; further details are presented below:
69
70 <DL>
71
72 <DT><B>drag&amp;drop source</B> </DT>
73 <DD>Returns a list of path names for widgets registered as
74 drag&amp;drop sources. Returns an empty string if no widgets have been registered.
75 </DD>
76
77 <DT><B>drag&amp;drop source <I>window </I></B>?<I>options</I>? </DT>
78 <DD>Registers a new drag&amp;drop source window
79 with the given options, or modifies the options for an existing window:
80 <blockquote></DD>
81 </DL>
82 <P>
83 <BR>
84 <PRE>Name:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>buttonBinding</B>
85 Class:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>ButtonBinding</B>
86 Switch:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>-button</B> <I>n</I>
87 </PRE>
88 <DL>
89
90 <DT>Specifies the mouse button (integer 1-5) that will invoke the drag&amp;drop </DT>
91 <DD>operation
92 on the source window. This causes the following bindings to be added to
93 the widget: <P>
94 <BR>
95 <PRE><I>bind <I>win</I></I> &lt;ButtonPress-<I>n</I>&gt; {drag&amp;drop drag %W %X %Y}
96 <I>bind <I>win</I></I> &lt;B<I>n</I>-Motion&gt; {drag&amp;drop drag %W %X %Y}
97 <I>bind <I>win</I></I> &lt;ButtonRelease-<I>n</I>&gt; {drag&amp;drop drop %W %X %Y}
98 </PRE><P>
99 The default value is button 3. If the value "0" is specified, then no bindings
100 are added; this enables the user to establish bindings manually. <P>
101 <BR>
102 <PRE>Name:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>packageCommand</B>
103 Class:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>Command</B>
104 Switch:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>-packagecmd <I>command</I></B>
105 </PRE>
106 <DL>
107
108 <DT>Specifies a Tcl command used to establish the appearance of the token </DT>
109 <DD>window
110 at the start of each drag&amp;drop operation. This command is automatically
111 invoked by the <B>drag&amp;drop drag</B> command whenever the token window is about
112 to be mapped for a drag operation. It should update the appearance of the
113 token window to represent the data that is being moved. </DD>
114 </DL>
115 <P>
116 The following substitutions
117 are made in the <I>command</I> string before it is executed: <blockquote>
118 <DL>
119
120 <DT><B>%t</B> </DT>
121 <DD>Replaced with
122 the window path name for the token which represents the data being dragged.
123 </DD>
124
125 <DT><B>%W</B> </DT>
126 <DD>Replaced with the window path name for the drag&amp;drop source. </DD>
127 </DL>
128 </blockquote>
129 <P>
130 The return
131 value from the package command represents the data being transferred. If
132 the package command returns an empty string, the drag operation is quietly
133 aborted. This can be used to disallow drag&amp;drop operations from certain
134 parts of a widget, if the drag position is inappropriate. <P>
135 For example, the
136 following package routine will select an item from a listbox and configure
137 the token window to display the selected string. It uses the <B>drag&amp;drop location</B>
138 command to determine the entry in the listbox that the user has selected
139 and it returns this as the data value: <P>
140 <BR>
141 <PRE><I>proc package_list_item {lbox token} {</I>
142 set xy [drag&amp;drop location]
143 set y [expr [lindex $xy 1]-[winfo rooty $lbox]]
144 set str [$lbox get [$lbox nearest $y]]
145 $token.value configure -text $str
146 return $str
147 }
148 </PRE><P>
149 The return value is available later when the source and target communicate.
150 If the source has a command associated with its data handler, then this
151 value is substituted in place of "%v" in the source handler. Otherwise,
152 it is substituted in place of "%v" in the target handler. <P>
153 <BR>
154 <PRE>Name:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>rejectBackground</B>
155 Class:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>Background</B>
156 Switch:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>-rejectbg <I>color</I></B>
157 </PRE>
158 <DL>
159
160 <DT>Specifies the color used to draw the background of the rejection symbol
161 </DT>
162 <DD>on the token window. The rejection symbol (a circle with a line through
163 it--the international "no") appears whenever communication fails. </DD>
164 </DL>
165 <P>
166 <BR>
167 <PRE>Name:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>rejectForeground</B>
168 Class:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>Foreground</B>
169 Switch:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>-rejectfg <I>color</I></B>
170 </PRE>
171 <DL>
172
173 <DT>Specifies the color used to draw the foreground of the rejection symbol
174 </DT>
175 <DD>on the token window. </DD>
176 </DL>
177 <P>
178 <BR>
179 <PRE>Name:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>rejectStipple</B>
180 Class:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>Stipple</B>
181 Switch:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>-rejectstipple <I>pattern</I></B>
182 </PRE>
183 <DL>
184
185 <DT>Specifies a stipple pattern used to draw the foreground of the rejection
186 </DT>
187 <DD>symbol on the token window. Any of the forms acceptable to Tk_GetBitmap
188 can be used. </DD>
189 </DL>
190 <P>
191 <BR>
192 <PRE>Name:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>selfTarget</B>
193 Class:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>SelfTarget</B>
194 Switch:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>-selftarget <I>boolean</I></B>
195 </PRE>
196 <DL>
197
198 <DT>If the <I>boolean</I> value is true, and if a source widget is also </DT>
199 <DD>registered
200 as a compatible target, then the source will be able to transmit to itself
201 during drag&amp;drop operations. This is primarily useful for complex sources
202 such as a canvas widget, where items may be moved from place to place within
203 the same widget. By default, this option is disabled. </DD>
204 </DL>
205 <P>
206 <BR>
207 <PRE>Name:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>send</B>
208 Class:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>Send</B>
209 Switch:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>-send <I>list</I></B>
210 </PRE>
211 <DL>
212
213 <DT>Specifies a <I>list</I> of <I>dataTypes</I> enabled for communication. Only </DT>
214 <DD><I>dataTypes</I>
215 defined by commands of the form "<B>drag&amp;drop source <I>window <B>handler </B></I></B>?<I>dataType</I>
216 ?<I>command arg arg...</I>?" are allowed. This list also determines the priority
217 of the various <I>dataTypes</I>. When a token window is over a potential drag&amp;drop
218 target, this list is searched from start to finish for a <I>dataType</I> that
219 is also recognized by the target. The first matching <I>dataType</I> found determines
220 the value that will be sent if the token is dropped. If no matching <I>dataType</I>
221 is found, then the target is incompatible, and is ignored. By default,
222 this option has the value "all", indicating that all <I>dataTypes</I> should be
223 considered in the order that they were defined for the source. </DD>
224 </DL>
225 <P>
226 Note that
227 this option makes it easy to control a drag&amp;drop source. Setting the value
228 to an empty string disables the source; setting the value back to "all"
229 restores communication. <P>
230 <BR>
231 <PRE>Name:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>siteCommand</B>
232 Class:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>Command</B>
233 Switch:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>-sitecmd <I>command</I></B>
234 </PRE>
235 <DL>
236
237 <DT>Specifies a Tcl command used to update the appearance of the token window.
238 </DT>
239 <DD>If specified, this command is automatically invoked by the <B>drag&amp;drop drag</B>
240 command whenever the token window is over a compatible drag&amp;drop target.
241 </DD>
242 </DL>
243 <P>
244 The following substitutions are made in the <I>command</I> string before it is
245 executed: <blockquote>
246 <DL>
247
248 <DT><B>%s</B> </DT>
249 <DD>Replaced with "1" if the token window is over a compatible
250 target, and "0" otherwise. </DD>
251
252 <DT><B>%t</B> </DT>
253 <DD>Replaced with the window path name for the
254 token which represents the data being dragged. </DD>
255 </DL>
256 </blockquote>
257 <P>
258 Regardless of this command,
259 border of the token window will become raised whenever the token is over
260 a valid target. This command can be used to display other visual cues. <P>
261 <BR>
262 <PRE>Name:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>tokenAnchor</B>
263 Class:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>Anchor</B>
264 Switch:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>-tokenanchor <I>anchor</I></B>
265 </PRE>
266 <DL>
267
268 <DT>Specifies how the token window is positioned relative to the mouse </DT>
269 <DD>pointer
270 coordinates passed to the <B>drag&amp;drop drag</B> command. Must be one of the values
271 n, s, e, w, center, nw, ne, sw or se. For example, "nw" means to position
272 the token such that its upper-left corner is at the mouse pointer. The default
273 value is "center". </DD>
274 </DL>
275 <P>
276 <BR>
277 <PRE>Name:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>tokenBackground</B>
278 Class:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>Background</B>
279 Switch:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>-tokenbg <I>color</I></B>
280 </PRE>
281 <DL>
282
283 <DT>Specifies the color used to draw the background of the token window. </DT>
284 <DD></DD>
285 </DL>
286 <P>
287 <BR>
288 <PRE>Name:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>tokenBorderWidth</B>
289 Class:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>BorderWidth</B>
290 Switch:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>-tokenborderwidth <I>size</I></B>
291 </PRE>
292 <DL>
293
294 <DT>Specifies the width in pixels of the border around the token window. </DT>
295 <DD>This
296 border becomes raised to indicate when the token is over a compatible drag&amp;drop
297 target site. The value may have any of the forms acceptable to Tk_GetPixels.
298 The default value is "3". </DD>
299 </DL>
300 <P>
301 <BR>
302 <PRE>Name:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>tokenCursor</B>
303 Class:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>Cursor</B>
304 Switch:<tt>&#32;</tt>&nbsp;<tt>&#32;</tt>&nbsp;<B>-tokencursor <I>cursor</I></B>
305 </PRE>
306 <DL>
307
308 <DT>Specifies the cursor used when a token window is active. The value </DT>
309 <DD>may
310 have any of the forms acceptable to Tk_GetCursor. The default value is
311 "center_ptr". </DD>
312 </DL>
313 </blockquote>
314
315 <DL>
316
317 <DT><B>drag&amp;drop source <I>window <B>handler </B></I></B>?<I>dataType</I>? ?<I>command arg arg...</I>?
318 </DT>
319 <DD>With no extra arguments, this command returns a list of all <I>dataType</I> names
320 that have been registered for the source <I>window</I>. If only the <I>dataType</I> is
321 specified, then the <I>dataType</I> is created if necessary, and the command associated
322 with the <I>dataType</I> is returned. Otherwise, it concatenates the <I>command</I> and
323 any extra <I>arg</I> strings, and registers a new <I>dataType</I> with this command. </DD>
324 </DL>
325 <P>
326 The
327 following substitutions are made in the <I>command</I> string before it is executed:
328 <blockquote>
329 <DL>
330
331 <DT><B>%i</B> </DT>
332 <DD>Replaced with the name of the interpreter for the target application.
333 </DD>
334
335 <DT><B>%v</B> </DT>
336 <DD>Replaced with the value returned from the "-packagecmd" command. </DD>
337
338 <DT><B>%w</B> </DT>
339 <DD>Replaced
340 with the window path name for the target window. </DD>
341 </DL>
342 </blockquote>
343 <P>
344 A typical source handler
345 contains one or more "send" commands which transfer data to the remote
346 application. The target window is then asked to handle the new data. Whatever
347 value is returned by the source <I>command</I> handler is automatically substituted
348 into the "%v" fields of the target handler. <P>
349 This separation between the
350 transfer and the handling of the data is important. It allows the same
351 source handler to transfer data for many different targets, and it allows
352 each of the targets to handle the incoming data differently. If an error
353 is encountered during the communication process, the rejection symbol is
354 posted on the token window to indicate failure. </blockquote>
355 <P>
356
357 <DL>
358
359 <DT><B>drag&amp;drop target</B> </DT>
360 <DD>Returns
361 a list of path names for widgets registered as drag&amp;drop targets. Returns
362 an empty string if no widgets have been registered. </DD>
363
364 <DT><B>drag&amp;drop target <I>window
365 <B>handler </B></I></B>?<I>dataType command arg arg...</I>? </DT>
366 <DD>Registers a new drag&amp;drop target window
367 with a given handler, or modifies the handlers for an existing window.
368 If no <I>dataType</I> is specified, this command returns the current list of recognized
369 <I>dataType</I> strings. Each <I>dataType</I> is a symbolic name representing a form
370 of data, and the corresponding <I>command</I> is a Tcl command that specifies
371 how the target will make use of the data. This command is invoked indirectly
372 after a source has transferred data to a target application. </DD>
373 </DL>
374 <P>
375 The following
376 substitutions are made in the <I>command</I> string before it is executed: <blockquote>
377 <DL>
378
379 <DT><B>%v</B>
380 </DT>
381 <DD>In the simplest case, the source window does not have a handler command
382 for the selected <I>dataType</I>, and this field is replaced with the result from
383 the "-packagecmd" command. When the source does have a handler command,
384 the result from the "-packagecmd" command is substituted into its "%v" field,
385 and the result from this command is substituted into this field in the
386 target command. </DD>
387
388 <DT><B>%W</B> </DT>
389 <DD>Replaced with the window path name for the target window.
390 </DD>
391 </DL>
392 </blockquote>
393
394 <DL>
395
396 <DT><B>drag&amp;drop target <I>window </I></B>handle <I>dataType</I> ?<I>value</I>? </DT>
397 <DD>Searches for the given <I>dataType</I>
398 name among the handlers registered for the target <I>window</I>, and invokes the
399 appropriate <I>command</I>. If a <I>value</I> is specified, it is substituted into any
400 "%v" fields in the handler command associated with the <I>dataType</I>. If the
401 <I>dataType</I> name is not recognized, this command returns an error. This command
402 is invoked automatically by the drag&amp;drop facility when data is being transferred
403 from a source to a target. </DD>
404
405 <DT><B>drag&amp;drop token <I>window</I></B> </DT>
406 <DD>Returns the token window
407 associated with a drag&amp;drop source <I>window</I>. The token window is used to represent
408 data as it is being dragged from the source to a target. When a source
409 is first established, its token window must be filled with widgets to display
410 the source data. For example, <P>
411 <BR>
412 <PRE><I>drag&amp;drop source .foo</I>
413 set win [drag&amp;drop token .foo]
414 label $win.label -text "Data"
415 pack $win.label
416 </PRE><P>
417
418 <DL>
419
420 <DT><B>drag&amp;drop drag <I>window x y</I></B> </DT>
421 <DD>Marks the start of (or movement during) a drag&amp;drop
422 operation. If the token window is unmapped when this command is invoked,
423 then the <B>-packagecmd</B> for the source <I>window</I> is executed. If this command
424 is successful and returns a non-null string, the token window is mapped.
425 On subsequent calls, the token window is moved to the new <I>x y</I> location.
426 Unless the "<B>-button 0</B>" option is specified for the source, this command
427 is automatically bound to &lt;ButtonPress-<I>n</I>&gt; and &lt;B<I>n</I>-Motion&gt; events for "<B>-button
428 <I>n</I></B>" of the source widget. </DD>
429
430 <DT><B>drag&amp;drop drop <I>window x y</I></B> </DT>
431 <DD>Marks the end of a drag&amp;drop
432 operation. If the mouse pointer is over a compatible target window, then
433 the appropriate send handler for the first compatible <I>dataType</I> is invoked
434 to handle the data transfer. If the data transfer is successful, then the
435 token window is unmapped; otherwise, a rejection symbol is drawn on the
436 token window, and the window is unmapped after a small delay. Unless the
437 "<B>-button 0</B>" option is specified for the source, this command is automatically
438 bound to the &lt;ButtonRelease-<I>n</I>&gt; event for "<B>-button <I>n</I></B>" of the source widget. </DD>
439
440 <DT><B>drag&amp;drop
441 active</B> </DT>
442 <DD>Returns "1" if a drag&amp;drop operation is in progress, and "0" otherwise.
443 A drag&amp;drop operation officially starts after the package command has been
444 executed successfully, and ends after the send handler has been executed
445 (successfully or otherwise). </DD>
446
447 <DT><B>drag&amp;drop errors </B>?<I>proc</I>? </DT>
448 <DD>Specifies a Tcl <I>proc</I>
449 used to handle errors encountered during drag&amp;drop operations. If a <I>proc</I>
450 is not specified, this command returns the current error handler. By default,
451 all errors are sent to the usual <B>tkerror</B> command, and therefore appear
452 in a dialog box to the user. This behavior is quite useful when debugging
453 communication protocols, but may not be desirable in a finished application.
454 Errors can be suppressed entirely (leaving the rejection symbol as the
455 only error indicator) by specifying a null string in place of the <I>proc</I>
456 name. </DD>
457
458 <DT><B>drag&amp;drop location </B>?<I>x y</I>? </DT>
459 <DD>Used to set or query the pointer location
460 during a drag&amp;drop operation. The <I>x y</I> arguments specify the current location;
461 if these arguments are missing, then the last reported (x,y) location is
462 returned as a list with two elements. This command is issued automatically
463 within the <B>drag&amp;drop drag</B> and <B>drag&amp;drop drop</B> commands, to keep track of pointer
464 movement. <P>
465 </DD>
466 </DL>
467
468 <H2><A NAME="sect3" HREF="#toc3">Keywords</A></H2>
469 drag&amp;drop, send, bind, widget <P>
470
471 <HR><P>
472 <A NAME="toc"><B>Table of Contents</B></A><P>
473 <UL>
474 <LI><A NAME="toc0" HREF="#sect0">Name</A></LI>
475 <LI><A NAME="toc1" HREF="#sect1">Synopsis</A></LI>
476 <LI><A NAME="toc2" HREF="#sect2">Description</A></LI>
477 <LI><A NAME="toc3" HREF="#sect3">Keywords</A></LI>
478 </UL>
479 </BODY></HTML>