[Contents] [Index] [Next] [Previous]

Using Drag and Drop


The drag and drop facility allows you to pick up an object from one part of your display and move it to a new location. The object you pick up is called the drag source. The location where you drop it is called the drop site.

With drag and drop, you can do the following tasks:

For example, you can print the contents of a file by dragging an icon representing the file and dropping it on an icon representing a printer.

The source and destination of the drop can both be in the same application, or they can be in different applications. Text components, Labels and Lists are drag sources in all Motif applications. Text components are also automatically drop sites. Other drag sources and drop sites are defined by the specific applications.

Starting a Drag

To start a drag:
  1. Decide what you want to drag, and select it as follows:
  2. Move the pointer to the item that you want to drag. This item is called the drag source.
  3. Press and hold down Button 2.
  4. Specify the operation that you want to happen when the drop is made by pressing modifier keys on your keyboard. Descriptions of the different drag operations are given below.
Move- information is moved from the initiator to the receiver
Copy- information is copied from the initiator to the receiver
Link- information is linked from the initiator to the receiver

If a modifier key is not pressed, a move operation is generally assumed, but the actual operation chosen depends on the source and destination. The applications that are controlling the source and destination may have specified that only some of the possible operations are allowed. A move operation deletes the information from the original location after it has been copied to the new location.

If the system selects an operation that you do not want, press the appropriate modifier keys to change to a new operation at any time during the drag.

A drag icon representing the drag source appears instead of the normal pointer. The drag icon used depends on the the drag source. The drag icon consists of three parts:

Source Icon
The source icon is a graphical representation of the object being dragged.
State Icon
The state icon represents the relation of the drag icon to what is under it. It may change depending on whether the drag icon is over a valid drop site, over an invalid drop site, or not over a drop site.
Operation Icon
The operation icon represents the operation to be performed when the drop is made (copy, move, or link). If you have requested an operation that either the initiator or receiver does not allow, this icon will be blank.

A drag icon is shown below. The source icon is the running figure, the state icon is the arrow in the upper left corner, and the operation icon is the box just below the arrow.

Motif defines a default source icon for textual information, which is used if the drag source is a List, a Label, or a Text component. If the source is a graphics component, Motif will attempt to use the graphic image as the source icon. If the source is of a different type and the application has not provided a source icon for that type of data, the running figure is used as the source icon.

The state and operation icons are optional in a drag icon. Motif provides default operation icons for move, copy, and link operations. The default state icon for all three states is an arrow in the upper left corner of the drag icon.

The default drag icons for graphics and textual information for move, copy and link operations are shown below.

An application can specify different icons for each of the operations and states, as well as arrange the icons in a different way than the one shown in the illustration. You can also specify different icons by setting resources.

During the Drag

Without releasing the mouse button, move the mouse around. The drag icon representing the source moves around the screen instead of the normal pointer shape.

Every drag icon has a hot spot. The whole icon is considered in or out of a drop site when the hot spot is in or out of the drop site. If a drag icon displays a state icon, the hot spot is in it. Otherwise, the hot spot is in the source icon. The hot spot in the default state icon is located at the point of the arrow.

As the drag icon moves around the screen, it may change color or shape to indicate whether the drag icon is over a valid drop site, an invalid drop site, or no drop site. These changes are called drag-over effects. The default behavior is that there is no apparent change during the move. However, an application may provide other drag-over effects or you can specify your own with resources.

The operation icon indicates which operation will occur when the drop is made. You can change modifier keys to switch the operation at any time during a drag. The operation icon will change to show the new operation. If you have not specified an operation using the modifier keys, the default operation depends on what drop site the drag icon is over.

The appearance of a drop site may also change as the drag icon moves in and out of it. These changes are called drag-under effects. The default drag-under effect for a valid drop site is to display a border around the drop site. Other drag-under effects depend on the application that is controlling the drop site.

Dropping on a Destination

To drop a dragged object on a destination:
  1. Move the drag icon over a drop site
  2. Release Button 2 while still pressing any modifier keys that you are using to determine the operation

If the drop site is valid for that drag source, then the drag icon shows the completed drop by melting into the destination. If the drop site is not valid for that drag source, then the drag icon snaps back to the point from where the drag was initiated.

If the drag source is a Label, a List, or a Text component, the data being dragged is textual information and can be dropped on any Text destination. Other combinations of source type and destination type are defined by the application.

If the destination holds data or information, the dragged information generally is inserted at the pointer location. If the destination represents an application or device, generally a drop starts some action. What the action is depends on the application. For instance, if you drag an icon representing a file to an icon representing a printer, then the action will be that the contents of that file are printed on the printer indicated by the icon.

Getting Help

You can request help about a particular drop site if the application has provided help information. The help information usually explains the sources that are expected by a drop site and the actions that will occur as a result of a drop.

To request help:

  1. Move the drag icon over a drop site
  2. Press or

Canceling a Drag

At any time during a drag, you can cancel the drag operation. To cancel a drag in progress, press . The drag icon is replaced by the normal pointer shape and any special drag-over and drag-under effects go away.