Clipboards and Drag and Drop

As users work with more and more types of data in different applications, they have an increasing need to share objects and data between their applications. GNOME supports two related methods for transfering data between applications: using drag and drop operations, and copying to and pasting from a system-wide clipboard. Both the clipboard and drag and drop work across multiple applications, including those not developed with GNOME.

The clipboard is used when a user explicitly copies data in an application. The application then claims ownership of the clipboard. When the user pastes the data into another application, that application requests the clipboard data from the first application. Clipboard operations are fully supported in GTK+.

Drag and drop operations are similar, but they require the pointer to be tracked and updated as the user moves across potential drop targets. When an application is notified a pointer is moving over it during an active drag, it must update the cursor to indicate whether or not it can accept the drop. GTK+ provides drag and drop support with a sophisticated API that makes it easy to manage drop targets in your applications.

Both the clipboard and drag and drop operations support content negotation. When an application has data to offer, it advertises which formats are available for that data. Receiving applications can request the most suitable formats. For instance, if a user copies text from a web browser, a word processor can maintain formatting by requesting the data in HTML, while a plain text editor can receive the text without formatting.

You should provide clipboard and drag and drop functionality for any data your application operates on. The clipboard and drag and drop are useful for more than just text: files, graphics, and sound clips are all examples of data that can be transferred between applications. When you use GTK+, you automatically get clipboard and drag and drop support for text areas, color buttons, file choosers, and other built-in user interface controls. You should use the APIs in GTK+ to provide support for any other data in your application.

For more information, see Drag-and-Drop Protocol for the X Window System, X Clipboard Explanation, and The Clipboard Manager Specification.