From: mmc@att.com (Michael J. McLennan)
Subject: New "drag&drop" facility for TCL/Tk
Originator: news@cbnewsg.cb.att.com
Reply-To: michael.mclennan@att.com
Organization: AT&T Bell Laboratories
X-Newsreader: TIN [version 1.1 PL6]
Date: Wed, 18 Nov 1992 20:44:41 GMT

All of the recent discussion about a drag-and-drop facility for TCL/Tk
prompted me to polish up a facility that I developed a little while
back.  It is now publicly available on barkley.berkeley.edu in the
usual tcl/extensions directory.

This facility was not meant to imitate or integrate with any existing
drag-and-drop protocol (so spare me your flames!).  Rather, it was
designed in the mindset of TCL/Tk.  Any of the usual Tk widgets can
be registered as sources or targets for drag-and-drop, and TCL commands
are used to implement the transfer and interpretation of data.

When I originally started working on it, I imagined that it would be
useful for transferring data between applications.  Since I started
playing around with it, however, I see much more potential for transfers
within a single application--just dragging a list item into an entry
widget, or dragging the value from one scale widget to another.

Following is the README giving more detailed information...

Enjoy!
--Michael

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 Michael J. McLennan 2C-226    [   [ [   [  [[   E-mail: alux2!mmc@att.com
 AT&T Bell Laboratories        [[ [[ [[ [[ [      Phone: (215) 770-2842
 1247 S Cedar Crest Blvd    [[ [ [ [ [ [ [  [[[     FAX: (215) 770-3843
 Allentown, PA  18103          [   [ [   [       
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

------------------------------------------------------------------------
  Version 1.0 of the drag&drop facility has been made available for
  anonymous ftp:
   
      SOURCE: barkley.berkeley.edu [128.32.142.237]
        FILE: pub/tcl/extensions/dragdrop-1.0.tar.Z

  Please send comments or suggestions to michael.mclennan@att.com.
------------------------------------------------------------------------

========================================================================
                Copyright 1992 by AT&T Bell Laboratories
========================================================================
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that the copyright notice and warranty disclaimer appear in
supporting documentation, and that the names of AT&T Bell Laboratories
any of their entities not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission.

AT&T disclaims all warranties with regard to this software, including
all implied warranties of merchantability and fitness.  In no event
shall AT&T be liable for any special, indirect or consequential
damages or any damages whatsoever resulting from loss of use, data or
profits, whether in an action of contract, negligence or other
tortuous action, arising out of or in connection with the use or
performance of this software.
========================================================================


Implementation Notes:

This drag&drop facility provides a graphical paradigm for coordinating
"send" commands between related TCL/Tk applications.  It was written
to operate in the spirit of TCL/Tk, and not necessarily to imitate
other drag-and-drop protocols.


GETTING THE DISTRIBUTION:

 - FTP the distribution from barkley.berkeley.edu:

     ftp barkley.berkeley.edu
     cd
     binary
     get dragdrop-1.0.tar.Z
     quit

 - untar the distribution file:

     zcat dragdrop-1.0.tar.Z | tar -xvf -

This will create a directory "dragdrop-1.0" with the subdirectory
"demos".


MAKING A NEW WISH:

Update the first few lines of the given Makefile to use the proper
paths for your local installation of TCL/Tk.  Note that the Makefile
references the source directories for TCL/Tk, as well as the usual
libraries.  Build a new wish (called "dish" to avoid any conflict
with your usual wish) that will contain the drag&drop facility:

    make


UPDATING YOUR APPLICATION:

To add this facility to your application, simply add the following
command when initializing new interpreters:

    extern void Tk_AddDragDropCmd
        _ANSI_ARGS_((Tcl_Interp *interp, Tk_Window tkwin));

    main(argc,argv)
        int argc;
        char **argv;
    {
        Tcl_Interp *interp;  /* main interpreter */
        Tk_Window w;         /* main application window */

        interp = Tcl_CreateInterp();
            .
            .  usual set-up stuff
            .
        w = Tk_CreateMainWindow(interp, display, name);
            .
            .  usual set-up stuff
            .
        Tk_AddDragDropCmd(interp,w);

            .
            .  finish set-up and enter main loop
            .
    }

The usual "main.c" file used for wish has been updated with these
changes, and is included in this distribution.


RUNNING THE DEMO:

The "palette" demo provided in the "demos" directory illustrates the
basic concepts of the drag&drop facility.  You may drag and drop
between the widgets of a single application, or between multiple
palette applications.  Once you have created the "dish" application
which recognizes the drag&drop command, you can invoke the palette
application as:

    dish -f demos/palette

This brings up a window with three sliders controlling the RGB values
of a sample color; as you move the sliders, the color sample changes.

  - If you click with the third mouse button on one of the sliders,
    a token window with the numerical value of the slider will appear.
    This token window can then be "dropped" on another slider (or on
    the color sample next to the slider) to change its value.

  - If you click with the third mouse button on the color sample, a
    token window with the color value will appear.  This color can
    be dropped on the "Foreground" and "Background" targets to change
    the color scheme for the entire application.  It can also be
    dropped on the color sample in another application to transfer
    the RGB values.  Finally, it can be dropped on a slider (or on
    the color sample next to the slider); in this case, the appropriate
    color component (red, green, or blue) is extracted from the color
    and used to set the slider value.

  - If you try to drop a number value (from the slider) on the
    "Foreground" or "Background" targets, it will be rejected.

Notice that a particular widget can be configured to handle more than
one kind of data.  For instance, the slider (and its associated
color sample) will accept either a number value or a color value.

Notice also that a single kind of data can be handled differently by
different targets.  A single mechanism is used to transmit RGB color
values, for example, but the "Foreground" and "Background" targets
do very different things with the data.

Please experiment with this facility and send me your comments.

--Michael
------------------------------------------------------------------------
Newsgroups: comp.lang.tcl