GG: Drag and Drop

GG

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

Drag and Drop

# Basics

GG has drag and drop support that allows you to potentially drag any GG::Wnd and drop it onto any other GG::Wnd. The results of this drop depend on the two GG::Wnd's involved. Each GG::Wnd has a GG::Wnd::DragDropDataType() method that returns a string describing what kind of data the GG::Wnd represents. The string can be a MIME type, or any arbitrary string the user likes. During the dragging portion of the operation, a GG::Wnd under the cursor has its GG::Wnd::DropsAcceptable() member called, in which it can examine the data type string and other relevant aspects of each dragged GG::Wnd and decide whether or not to accept it. On the drop, the GG::Wnd under the cursor has its GG::Wnd::AcceptDrops() method called with those GG::Wnd's it has previously deemed accepted in GG::Wnd::DropAcceptable(). GG::Wnd's accepted by the drop target are removed from their original parent, if any, through a call to GG::Wnd::ChildrenDraggedAway().

Note that only GG::Wnd's with non-empty GG::Wnd::DragDropDataType() may be dragged and dropped. Within those GG::Wnd's, there are two categories: 1) GG::Wnd's with GG::Wnd::Dragable() true and those without. A GG::Wnd::Dragable() GG::Wnd moves across the screen normally when dragged. A Non-GG::Wnd::Dragable() GG::Wnd does not move when drag-and-dropped; instead, it is rendered in place, and an additional copy of it is rendered as if the cursor were dragging it.

# Advanced Use

There is an extensive set of notification functions that may be called during a drag and drop operation. The drop target and the orginal parent of the dragged GG::Wnd(s), if any, may be notified of various events or queried (e.g. GG::Wnd::DropsAcceptable()). Additionally, GG::Wnd::GetDragDropRenderingState() indicates whether a GG::Wnd is being dragged, whether it is over a valid drop target, etc. See the GG::Wnd documentation for details.