Advanced Drag and Drop: Patron

If you've been playing with the Patron sample from Chapter 11, you've probably noticed the annoying absence of a way to simply move a tenant on a page in one step. You can resize a tenant from one corner and then resize it from the opposite corner, but that's a pretty lame way to carry out what should be a single action. With OLE Drag and Drop, we can add the capability to do this in one step. Not only that, with the same code, we can also copy tenants to other documents either in the same instance of Patron, in a different instance, or to a different application altogether (particularly one that understands a graphics format). To do this, we need to make Patron both a source and a target, where dragging and dropping within the same document doesn't need to copy anything but can only reposition the tenant.

Patron (CHAP13\PATRON) implements the same steps as described for Cosmo, using similar source and target objects found in DROPSRC.CPP and DROPTGT.CPP. In fact, Patron's CDropSource is identical to Cosmo's. CDropTarget is structurally the same, but we have to do more work to support scrolling and additional user feedback in the target window. Other modifications to Patron include the file DRAGDROP.CPP, which contains some helper functions in the CPages class for performing hit-testing, scrolling, and end-user feedback. These are the functions CPages::UTestDroppablePoint, CPages::DrawDropTargetRect, and CPages::AdjustPosition. Finally, CPage::OnLeftDown (PAGEMOUS.CPP) is where we begin a drag and drop, so we perform hit-testing as well as mouse debouncing here.