Solaris Common Desktop Environment: Programmer's Guide

Drag-and-Drop User Model

This section describes the user model behind drag and drop to help you design an application that is consistent with the rest of the desktop and users' expectations.

See the Common Desktop Environment: Style Guide and Certification Checklist for more information about the drag-and-drop user model and for guidelines for the visual appearance of drag-and-drop elements.

When drag and drop is available for all applications on the desktop, the system is more predictable to the user and is, therefore, easier to use and to learn. Users leverage their learning across more applications by using skills that they already know. In addition, many users prefer drag and drop to using menus.

In this chapter, the term drop zone is used to describe places where users can drop something. Drop zones are usually represented by a control or icon graphic; for example, a trash icon or a type-in field graphic. The term drop target is used to describe the rectangular area that represents the drop zone.

Drag and Drop Capability

With the Drag and Drop capability, users can select and manipulate objects represented as icons.


Note -

Drag and drop is an accelerator to functionality that is accessible through other user interface controls supported within your application. However, not all users are able to take advantage of drag and drop. Do not support any basic operations solely through drag and drop. Any basic function that your application supports through drag and drop should also be supported by menus, buttons, or dialog boxes.


Drag Icons

When users select and manipulate icons using drag and drop, they expect the graphic icon that represents the item being dragged to remain consistent from the selection through the drag and drop. If the user selects a message icon in the File Manager and starts to drag it, the source portion of the drag icon is represented by that message icon. Providing this kind of consistency makes drag and drop more predictable to the user. Where the destination application uses icons, the icon shown should, in most cases, be the same one that was selected and then dragged and dropped. This behavior is not, however, always appropriate for all applications. Dragging text is an exception. A text drag icon is used instead of dragging the selected text.

Both the source and destination applications specify the visual appearance of drag icons. You are responsible for ensuring that an application has a consistent and appropriate icon to drag. Although the drag-and-drop library provides default icons, it is a good idea for you to specify your own for each application. Most often, you should use the data-typing database to obtain the icon associated with the type data represented by the icon. See Chapter 9, Accessing the Data-Typing Database.

When users start a drag without selecting an icon, it is appropriate for you to provide a relevant drag icon. For example, in an appointment editor, the user can select an appointment out of a scrolling list--which may or may not show icons. You should use an appointment icon as the source indicator. The destination application (for example, a File Manager) should display the same appointment icon.

Parts of the Drag Icon

The drag icon changes appearance to provide drag-over feedback when the user moves it over potential drop zones.

The drag icon has three parts that combine to provide the drag-over feedback:

The state indicator is a pointer used for positioning combined with a valid or invalid drop zone indicator. The valid state indicator is an arrow pointer. The pointer has a hot spot so users can position it in a predictable manner. The invalid state indicator--a circle with a diagonal line--is displayed when users have positioned the cursor over an invalid drop zone.

The operation indicator gives users feedback on what operation is occurring during the drag; either move, copy, or link. Because most drags are moves, users are given additional feedback when they perform the less-frequent copy or link operations.


Note -

The operation feedback is drawn on top of the state and source feedback. This behavior is consistent with Motif drag-and-drop behavior.


The user can choose the drag operation move, copy, or link by pressing and holding certain keys during a drag, as shown in Table 5-1.

Table 5-1 Keys Used to Modify a Drag Operation

Modifier Key 

Operation 

Shift 

Move 

Control 

Copy 

Control and Shift 

Link 

The source application can force a copy, as in the case of the read-only File Manager window. When the user chooses an operation, the drop zone must match that operation for the drop to succeed; otherwise, the drop zone is invalid. In other words, if the user chooses a copy by holding down the Control key, and then drags the drag icon over the trash icon, the drag icon should show the trash icon as an invalid drop zone and any drop should fail, because copying to the trash is not allowed.

The source indicator represents the selection (or the item being dragged). The source indicator varies depending on whether the selection represents single or multiple items and what kind of item the selection represents.

Drags from Inside Windows

Sometimes an application needs to enable a drag from within a dialog box or window. The Appointment Editor in Calendar has a scrolling list of appointments and an entry area for editing an appointment. Users can drag from the scrolling list to get an appointment, but users also need to be able to drag from the appointment entry area. Enabling users to drag from the entry area covers those times when the appointment is not yet inserted in the calendar (for example, when a proposed meeting time is entered but not inserted into the calendar).

The item that can be dragged needs to have an icon graphic associated with it. Place the icon graphic in the dialog box in an appropriate area adjacent to the information to be dragged. The upper-right corner of the dialog box or window is the recommended default position. The icon lets the user know that something can be dragged and the graphic used is the same graphic used in the drag icon to provide consistency. The icon should be 32x32 pixels and have a label so that it resembles a File Manager icon. See the Common Desktop Environment: Style Guide and Certification Checklist chapter on drag and drop for more information.


Note -

Drags are only enabled from human interface elements that have components or items that can be selected. Drags cannot be enabled from static labels such as those on buttons or menus.


Visual Feedback

The following sections describe the drop zone feedback and transition effects of drag and drop.

Drop Zone Feedback

The default drop zone feedback, called drag under, can be a solid line drawn around the site, a raised or lowered surface with a beveled edge around the drop zone, or a pixmap drawing over the drop zone.

Transition Effects

Transition effects show the user that the drop has either succeeded or failed. The two transition effects are melt and snap back.

Melting occurs when the user drops a drag icon on a valid drop zone. When the user drops a drag icon on a valid drop zone, the drag icon melts into the drop zone. The drag icon is replaced by the icon appropriate to the destination application. A printer on the Front Panel may show nothing other than the melting effect. An open File Manager window may display an appropriate icon.

When an icon is dropped, sometimes the melting effect does not take place immediately. The icon is displayed where it is placed until the transfer is done. It is a good idea for the destination to set its cursor to a busy state while the transfer is occurring. The user cannot move or select the icon until the transfer is complete; the busy cursor lets the user know the transfer is in process.

Snap back occurs when a drop fails. Drops can fail in two ways. If the user drops a drag icon over an invalid drop zone, then the drag icon snaps back to the source application. Once a drop occurs, the source and destination applications have to transfer the data. If the data transfer fails, the drag icon snaps back and the destination application is responsible for indicating failure to the user and providing information on why the drop failed.

Drag-and-Drop Sources

To help you understand the behavior of drag-and-drop sources, Table 5-2 describes the key desktop components that can be a source of drags of text selections, files, and buffers.

Table 5-2 Desktop Components That Can Be Drag Sources

Drag Source 

Text Selections 

Files 

Buffers 

Text fields (Motif)* 

Selected text 

N/A 

N/A 

Text Editor: Main Window 

Selected Text 

N/A 

N/A 

Terminal: Main Window 

Selected Text 

N/A 

N/A 

File Manager: Folder Window 

N/A 

Files 

N/A 

File Manager: Trash Window 

N/A 

Files 

N/A 

Mail: Message List 

N/A 

N/A 

Message in mail-message format 

Mail: Attachment List 

N/A 

N/A 

Attachment in format of the attachment 

Calendar: Appointment Editor 

N/A 

N/A 

Appointment in appointment format 

*Any application that has Motif text field sources selected drags text.

Drag-and-Drop Destinations

The following components on the desktop provide drop destinations:

Each component accepts drops of text selections, files, and buffers. Most of the text drop destinations are provided automatically by the Motif library. File or buffer data drop destinations require additional code.

When a user drops data from a file, and that file is modified in some way, the modifications can be written back to the original holder of the file. This behavior is described as saveback. However, when data is dropped from a buffer, the data does not have information about an originating file. As a result, changes to data from buffers cannot be written back, because there is no original holder of the data. This behavior is described as no saveback.

For example, the Mailer can export mail attachments to editors using drag and drop. If the attachment is exported as a buffer (that has no saveback), the editor has no way to change the original attachment in the mailer. So, the editor can only save its modified version of the attachment to a new file.

Because mail attachments are not already separate files (they are embedded into a mail folder file), they are only exported as buffers and cannot be saved back by other editors.

If the attachment is exported as a file (that has saveback) the editor saves its modified version to that same file. Table 5-3 describes the drops of text selections, files, and buffers on editor-type components such as Text Editor, Icon Editor, Calendar and Mailer.

Table 5-3 Editor Drop Destinations

Drop Destination 

Text Selections 

Files 

Buffers 

Text Editor: Main Window 

Insert 

Insert 

Insert 

Terminal: Main Window 

Insert 

N/A 

N/A 

Icon Editor: Main Window 

N/A 

Load (if file in icon format) saveback 

Load into read-only (if data in icon format) no saveback 

Mailer: Message List 

N/A 

Append (if file in mail format) 

Append (if data in mail format) 

Mailer: Compose 

Insert 

Insert 

Insert 

Mailer: Attachment List 

Attach 

Attach 

Attach 

Calendar: Main Window 

N/A 

Schedule Appointment (if file in appointment format) 

Schedule appointment (if data in appointment format) 

Calendar: Appointment Editor 

Insert into text field 

Fill in appointment fields (if file in appointment format) 

Fill in appointment fields (if data in appointment format) 

AppBuilder 

N/A 

Load (if file in BIX or BIL format) saveback 

Load into read-only (if data in BIP format) no saveback 

Table 5-4 describes the drops of text selections, files, and buffers on file and folder icons in the File Manager.

Table 5-4 File Manager Drop Destinations

Drop Destination 

Text Selections 

Files 

Buffers 

File Icon 

Invoke drop action on target file and dropped text (if file accepts text drops and dropped text in appropriate format) no saveback/copy 

Invoke drop action on target file and dropped file (if file accepts file drop and dropped file in appropriate format) saveback 

Invoke drop action on target file and dropped data (if file accepts data drop and dropped data in appropriate format) no saveback/copy 

Folder Icon 

Insert text into new file using "Untitled" name in folder 

Copy/move file to folder 

Insert data into new file using supplied name (if available) in folder else using "Untitled" 

Action Icon 

Invoke action on text (if appropriate format and accepts text drop) no saveback 

Invoke action on files (if appropriate format and accepts file drop) saveback 

Invoke action on data (if appropriate format and accepts data drop) no saveback 

Mail Container Icon 

Append to mailbox (if text in mail format) 

Append to mailbox (if file in mail format) 

Append to mailbox (if data in mail format) 

Table 5-5 describes the drops of text selections, files, and buffers on action icons in the Front Panel.

Table 5-5 Front Panel Drop Destinations

Drop Destination 

Text Selections 

Files 

Buffers 

Text Editor 

Load into read-only no saveback 

Load saveback 

Load into read-only no saveback 

Calendar 

Schedule appointment (if text in appointment format) 

Schedule appointment (if file in appointment format) 

Schedule appointment (if data in appointment format) 

Mail 

Compose message attach text 

Compose message attach file 

Compose message attach data 

Printer 

Print text (if print method available for text) 

Print file contents (if print method available for file format) 

Print data (if print method available for data format) 

Trash Can 

N/A 

Move file to Trash Can 

N/A 

Subpanel: Install Icon 

N/A 

Install icon 

N/A 

Subpanel: Action 

Same as File Manager 

Same as File Manager 

Same as File Manager 

Subpanel: Executable 

Same as File Manager 

Same as File Manager 

Same as File Manager 

See the Common Desktop Environment: Style Guide and Certification Checklist for more information and guidelines on how the drag and drop should appear to the user.