[ Previous | Next | Contents | Glossary | Home | Search ]
Motif 2.1 Programmer's Guide

User Overview of Drag and Drop

Drag and drop allows the user to "pick up" objects on the screen, "drag" them around the display, and "drop" them at a new location, possibly in another application.

With drag and drop the user can

  1. Move text or other information between windows.

  2. Cause application-specific actions to occur.

  3. Obtain help information about drop sites.

    This section describes what the user does and sees during a drag and drop transaction.

  4. Overview of User Interaction

    A drag and drop transaction consists of the following actions:

    1. To start a drag transaction, a user typically presses and holds Btn2, over a source object. The application owning that object is the initiator of the drag. The current pointer is replaced by a drag icon--a picture representing the item being dragged.

    2. The user moves the pointer. From now until a drop occurs, the drag icon replaces the mouse pointer. The user may move the pointer by moving the mouse, or with the arrow keys.

    3. The user drops the object, usually by releasing the mouse button.

      Locations on the screen that can accept drops are drop sites, and the application owning that drop site is the destination or receiver.

      The drag icon can be dropped anywhere on the screen. However, only certain widgets have registered themselves as drop sites and are able to process the drop.

      The receiver application usually performs some action on the information represented by the dragged icon. The initiator application may also perform some action based on the results of a drag transaction.

      A drop can be between applications or within the same application. An application can be both source and destination of a drop, source only, destination only, or not participate in drag and drop at all.

      The user can request help about a drop site, if available, by dragging to the drop site and pressing osfHelp (usually F1).

      The user can cancel the drag at any time by pressing osfCancel, usually Escape.

    4. Overview of Drag-Over Effects

      The drag icon consists of three parts:

      1. The source icon is a picture representing the type of the source object, such as text.

      2. The state icon can be used to show whether or not the object being dragged can be dropped at its current location on the screen.

      3. The operation icon can be used to show what action should happen when the drop takes place.

        In the following illustration, the running figure is the source icon, the arrow in the upper left is the state icon, and the rectangles with the corner folded over indicate a Copy is desired.

        Figure 16. A Drag Icon.

        View figure.

        These parts can be combined (blended) and attached to each other in different ways. The default blending and attachment are shown in the previous illustration.

        Parts of the drag icon may change shape or color as it is being dragged through potential drop sites, providing visual feedback about possible drop sites to the user. These changes are drag-over effects.

        Applications can use the default drag icon effects, or provide more sophisticated or custom drag icons. The application or user can customize these drag-over effects in resource files.


        This chapter contains several illustrations of default Motif drag and drop icons. In reality, there are two different sets of default Motif icons. The XmNenableDragIcon resource of XmDisplay determines which set is used. If XmNenableDragIcon is False (the default), the traditional Motif drag and drop icons are used. If XmNenableDragIcon is True, alternate Motif drag and drop icons are used. We have used only the traditional Motif drag and drop icons for the illustrations in this chapter.

      4. Drag States

        During a drag, there are three states that describe the relationship of a drag icon to what is under it at the time:

        Valid drop site

        The drag icon is over a drop site on which it can potentially be dropped (this is only a hint; when the drop is actually attempted, further processing may show that the drop cannot actually be done).

        Invalid drop site

        The drag icon is over a drop site, but it cannot be dropped there.

        No drop site

        The drag icon is not over a registered drop site.

        The default state icon for all three states is the same: an arrow in the upper left corner of the drag icon. Because the icon is the same for all three states, it appears not to change during the drag. The application or the user can provide custom state icons or colors in a resource file.

        Drag Operations

        The user specifies what action is to take place when the drop occurs by pressing certain keys when the drag starts or while the drag is in process:

        Shift only
        Force a move from the initiator to the receiver client (Move)

        Ctrl only
        Force a copy from the initiator to the receiver client (Copy)

        Shift and Ctrl
        Force a link between the initiator and receiver clients (Link)

        The operation chosen by the user must be valid for both the drag source and the drop site, or the drop site will be considered invalid.

        If the user does not specify an operation, one is chosen by the toolkit. It choses an operation that is valid for both the drag source and drop site. Move is the first choice, Copy is the second, and Link is the third. If the system cannot find a valid operation, the drop site is considered invalid.

        The operation icon reflects the operation chosen by the user or by the system. If the operation is changed by the user during the drag, the operation icon changes also.

        The operation icon may change as the drag icon moves to different drop sites if the drop sites accept different operations.

        Overview of Drag-Under Effects

        A widget registered as a drop site may change visually as a drag icon passes over it. These visual cues are drag-under effects. The sensitive area of the widget is the part that responds to drag and drop. By default it is the whole widget, but applications can specify that only parts of the widget respond to drag and drop.

        In addition, a widget may support pause drag. This means that if a drag icon pauses over a specifed part of a widget, some action will occur, such as scrolling. See Section for more information about this feature.

        Various highlighting styles are possible:

        1. A border around the sensitive area of the drop site widget. This is the default value.

        2. The sensitive area of the drop site widget looks pushed out.

        3. The sensitive area of the drop site widget looks pushed in.

        4. A special pixmap is displayed within the sensitive area of the drop site widget, overwriting what is normally there.

        5. No drag-under effects are used for the drop site widget.

          Applications can use the default drag-under visual effects, or create more sophisticated or custom effects, such as special animation or sound effects.

        6. Overview of Drop Effects

          Visual effects also take place during the drop:

          1. The drag icon appears to sit over the drop site while the processing for the drop is finishing, but the standard cursor is restored and can be used normally.

          2. The source icon appears to melt into the drop site if the drop is successful.

          3. The source icon appears to snap back to the source if the drop is unsuccessful.

          4. The source icon appears to snap back to the source and the previous X cursor returns if Cancel is requested. All drag-under and drag-over effects are removed.

            These drop effects cannot be changed by the application or the user. However, if the receiver wants to cancel these effects completely, the receiver should ask the source to convert the special _MOTIF_CANCEL_DROP_EFFECT target. For example, the receiver can make a call like the following to cancel the effects:

                 XInternAtom(XtDisplay(wid), XmS_MOTIF_CANCEL_DROP_EFFECT, False),
                 NULL, NULL, XtLastTimeStampProcessed(XtDisplay(wid)));

            The Motif toolkit will intercept this request and fulfill it by cancelling all visual effects. The drag source should not provide any code to handle this target.

            The application or widget should supply a DialogBox containing information about a drop site if the user has requested help and the receiver client provides help.

          5. [ Previous | Next | Contents | Glossary | Home | Search ]