Drop Effects

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Drop Effects

Previous pageReturn to chapter overviewNext page

When the data is dragged over some drag&drop target, the target should accept or reject the data. But, in OLE drag&drop its not just a Boolean value, the target should specify which drop effect it prefers. The following drop effects are predefined by OLE drag&drop interface:

 

Move (deMove) - data is moved from one place to another, or from one application to another. After successful drag&drop operation initial data should be removed.

Copy (deCopy) - data is copied from one place to another, or from one application to another. After successful drag&drop operation initial data should not be removed, and two copies of data should exist as a result.

Link (deLink) - some sort of link to initial data should be created as a result of successful drag&drop operation.

None (deNone) - target do not accept dragging data.

 

Most people are familiar with drop effects, because they are used in Windows Explorer when dragging files. If the file is simply dragged it will be moved from one location to another. If the user holds Ctrl key pressed, mouse cursor include "+" glyph to indicate that dragging file will be copied. As well, if the user holds Ctrl+Shift keys pressed, a link to dragging file will be created.

 

The same thing actually happens when the user drag selected text from WordPad to Word, for example. If the Ctrl key is not pressed the text will be "moved" from one application to another, disappearing in the initial application. Of course, what is really happens, is that receiving application adds dragging text to its document, and then sending (source) application remove dragged text from its document.

 

Some applications can restrict possible drop effects. For example, bookmarks in Google Chrome can not be copied, they can be only moved.

 

When initiating drag&drop operation, the source side should specify, which drop effects are allowed for this operation. TNGDropSource.Execute method allows to specify allowed drop effects using its Allowed parameter. If the value for this parameter is not provided, all drop effects will be allowed.

If the target side want to accepts dragging data it should choose one drop effect from allowed effects to indicate data acceptance. Context's C.Accepted property should be set to chosen drop effect or to deNone, if the target do not accept dragging data.

After dragging data has been accepted and dropped on the target, TNGDropSource.Execute returns and provide the final drop effect, chosen by the target, as a result value.

 

Choosing drop effect can be tricky task for target, since it need to analyze provided by the source allowed drop effects, analyze C.KeyState, analyze its own possibilities (e.g. whether it can support, for example, deLink at all). So, NG Drag&Drop provides helper Accept methods, which can simplify the task. Accept methods provide Accepted parameter, which can be used to specify, which drop effects are supported by the target. If the parameter value is not specified, all drop effects will be accepted.

 

NG Drag&Drop use the following algorithm to choose drop effect:

 

Intersect allowed by the source drop effects with supported by the target.

If intersected effects include deLink, and Ctrl+Shift keys are pressed, then the resulting drop effect is deLink.

Otherwise, if intersected effects include deCopy, and Ctrl key is pressed, then the resulting drop effect is deCopy.

Otherwise, if intersected effects include deMove, then the resulting drop effect is deMove.

Otherwise, if intersected effects include deCopy, then the resulting drop effect is deCopy, even if no keys are pressed.

Otherwise, if intersected effects include deLink, then the resulting drop effect is deLink, even if no keys are pressed.

Otherwise the resulting drop effect is deNone.

 

So, in very simple case C.Accept method can be called to accept dragging data without worrying about effects, and NG Drag&Drop will choose appropriate drop effect automatically. In more advanced cases, when the application wants to customize the above algorithm, it should set the value of C.Accepted property manually, without using Accept helper methods.