Chapter 24. Drag-and-Drop

Drag-and-drop of icons in the Finder goes back to the beginnings of the Macintosh user interface, and certain conventions are now so customary as to be almost subconscious: to copy or move a file to a different folder, drag its icon into the folder; to open a document with a certain application, drag its icon onto the application’s icon. But system-level drag-and-drop of data, within an application and from one application to another, was not introduced until about 1994. At first, the technology behind this was called Macintosh Drag-and-Drop; now, it is more often called the Drag Manager.[130] Drag-and-drop is an intuitive and easy way to move data, and you may well want to consider implementing it in your application.

REALbasic implements drag-and-drop by means of the DragItem class, which works very much like the Clipboard class (see Chapter 23). But don’t be misled by this comparison! Drag-and-drop does not use the clipboard; that’s one of its advantages. A DragItem is itself the repository of the data being moved; metaphorically, it’s like a suitcase, carrying the data inside it from one place to another. Like the Clipboard, a DragItem’s data is identified by a format label, such as 'TEXT' or 'PICT'. There can be more than one piece of data, and (unlike the Clipboard) there can be more than one piece of data with the same format.

Three separate situations must be considered:

  • You have a control or window, and you want the user to be able ...

Get REALBasic: TDG, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.