DragAndDropHandler Class Reference

#include <idraganddrop.h>

Class Description

The base class from which specialized drag-and-drop handlers should be derived.

+ Inheritance diagram for DragAndDropHandler:

Public Member Functions

 DragAndDropHandler ()
 constructor More...
 
virtual CoreExport HRESULT DragEnter (HWND window, IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
 Gets low level control over drag and drop operations. More...
 
virtual CoreExport HRESULT Drop (HWND window, IDataObject *pDataObject, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
 
virtual CoreExport HRESULT DragOver (HWND window, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect)
 
virtual CoreExport HRESULT DragLeave (HWND window)
 
virtual HRESULT DragEnter (HWND window, DropType *type, DWORD grfKeyState, POINT &pt, DWORD *pdwEffect)
 
virtual HRESULT Drop (HWND window, DropType *type, DWORD grfKeyState, POINT &pt, DWORD *pdwEffect)
 
virtual HRESULT DragOver (HWND window, DWORD grfKeyState, POINT &pt, DWORD *pdwEffect)
 
virtual void Acquire ()
 
virtual void Release ()
 This method is called called during a when the drag and drop manager stops managing drag and drop events for a particular window for this handler. More...
 
- Public Member Functions inherited from InterfaceServer
virtual UtilExport ~InterfaceServer ()
 Destructor. More...
 
virtual UtilExport BaseInterfaceGetInterface (Interface_ID id)
 

Protected Attributes

DropTypecurrent_droptype
 Cache for the currently parsed DropType. More...
 

Static Protected Attributes

static CoreExport IDragAndDropMgrdndMgr
 Cached pointer to drag and drop manager. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 

Constructor & Destructor Documentation

DragAndDropHandler ( )
inline

constructor

252  {
253  if (dndMgr == NULL)
255  }
IDragAndDropMgr * GetDragAndDropMgr()
Definition: idraganddrop.h:79
static CoreExport IDragAndDropMgr * dndMgr
Cached pointer to drag and drop manager.
Definition: idraganddrop.h:538
DropType * current_droptype
Cache for the currently parsed DropType.
Definition: idraganddrop.h:531
#define NULL
Definition: autoptr.h:18

Member Function Documentation

virtual CoreExport HRESULT DragEnter ( HWND  window,
IDataObject *  pDataObject,
DWORD  grfKeyState,
POINTL  pt,
DWORD *  pdwEffect 
)
virtual

Gets low level control over drag and drop operations.

Override this method in your DragAndDropHandler subclass to get low-level control over drag and drop operations. This is just a redirect of the identical method called on the OLE IDropTarget interface, see MSDN docs for details.

The default implementation for this methods use the DropClipFormat and DropType classes to recognize and parse the incoming IDataObject into a DropType instance and hand this to the associated high-level drag and drop handler methods desribed next.

As an example, here is the default DragEnter() implementation which does the initial parsing on entry to a window:

HRESULT DragAndDropHandler::DragEnter(HWND hWnd, IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
{
// look for one of our accepted clip formats
if (cf != NULL)
{
// have one, get it to parse it into a DropType subclass
current_droptype = cf->ParseDataObject(pDataObject);
{
// got recognizable drop data,
// pass on to high-level method
if(pdwEffect)
*pdwEffect = DROPEFFECT_LINK|DROPEFFECT_COPY;
POINT p = { pt.x, pt.y };
DragEnter(hWnd, current_droptype, grfKeyState, p, pdwEffect);
return S_OK;
}
}
// nothing for us
if(pdwEffect)
*pdwEffect = DROPEFFECT_NONE;
return S_OK;
}
Parameters
window- The specified handle to the window in which the drag and drop event is occuring. This is one of the windows that was enabled via a IDragAndDropMgr::EnabledDnD() call, so it may be the parent of the lowest-level window that the mouse is actually over.
pDataObject- The incoming IDataObject.
grfKeyState- The specified current state of the keyboard modifier keys on the keyboard. Valid values can be a combination of any of the flags MK_CONTROL, MK_SHIFT, MK_ALT, MK_BUTTON, MK_LBUTTON, MK_MBUTTON, and MK_RBUTTON.
pt- The specified current cursor coordinates in the coordinate space of the drop-target window.
pdwEffect- On entry, pointer to the value of the pdwEffect parameter of the DoDragDrop function. On return, must contain one of the effect flags from the Win32 DROPEFFECT enumeration, which indicates what the result of the drop operation would be.
Returns
Standard return values of E_OUTOFMEMORY, E_INVALIDARG, F_UNEXPECTED, and E_FAIL, S_OK.
virtual CoreExport HRESULT Drop ( HWND  window,
IDataObject *  pDataObject,
DWORD  grfKeyState,
POINTL  pt,
DWORD *  pdwEffect 
)
virtual
Remarks
This method will parse the dropped dataObject.
Parameters:
HWND window

The specified handle to the window in which the drag and drop event is occuring. This is one of the windows that was enabled via a IDragAndDropMgr::EnabledDnD() call, so it may be the parent of the lowest-level window that the mouse is actually over.

IDataObject* pDataObject

The incoming IDataObject.

DWORD grfKeyState

The specified current state of the keyboard modifier keys on the keyboard. Valid values can be a combination of any of the flags MK_CONTROL, MK_SHIFT, MK_ALT, MK_BUTTON, MK_LBUTTON, MK_MBUTTON, and MK_RBUTTON.

POINTL pt

The specified current cursor coordinates in the coordinate space of the drop-target window.

DWORD* pdwEffect

On entry, pointer to the value of the pdwEffect parameter of the DoDragDrop function. On return, must contain one of the effect flags from the Win32 DROPEFFECT enumeration, which indicates what the result of the drop operation would be.
Returns
Standard return values of E_OUTOFMEMORY, E_INVALIDARG, F_UNEXPECTED, and E_FAIL, S_OK.
virtual CoreExport HRESULT DragOver ( HWND  window,
DWORD  grfKeyState,
POINTL  pt,
DWORD *  pdwEffect 
)
virtual
Remarks
This method handles the process of dragging over a drop target.
Parameters:
HWND window

The specified handle to the window in which the drag and drop event is occuring. This is one of the windows that was enabled via a IDragAndDropMgr::EnabledDnD() call, so it may be the parent of the lowest-level window that the mouse is actually over.

DWORD grfKeyState

The specified current state of the keyboard modifier keys on the keyboard. Valid values can be a combination of any of the flags MK_CONTROL, MK_SHIFT, MK_ALT, MK_BUTTON, MK_LBUTTON, MK_MBUTTON, and MK_RBUTTON.

POINTL pt

The specified current cursor coordinates in the coordinate space of the drop-target window.

DWORD* pdwEffect

On entry, pointer to the value of the pdwEffect parameter of the DoDragDrop function. On return, must contain one of the effect flags from the Win32 DROPEFFECT enumeration, which indicates what the result of the drop operation would be.
Returns
Standard return values of E_OUTOFMEMORY, E_INVALIDARG, F_UNEXPECTED, and E_FAIL, S_OK.
virtual CoreExport HRESULT DragLeave ( HWND  window)
inlinevirtual
Remarks
This method handles the process of the drag operation leaving the drop target window.
Parameters:
HWND window

The specified handle to the window in which the drag and drop event is occuring. This is one of the windows that was enabled via a IDragAndDropMgr::EnabledDnD() call, so it may be the parent of the lowest-level window that the mouse is actually over.
Returns
Standard return values of E_OUTOFMEMORY, E_INVALIDARG, F_UNEXPECTED, and E_FAIL, S_OK.
Default Implementation:
{ return E_FAIL; }
378 { return E_FAIL; }
virtual HRESULT DragEnter ( HWND  window,
DropType type,
DWORD  grfKeyState,
POINT &  pt,
DWORD *  pdwEffect 
)
inlinevirtual
Remarks
This is the high-level method called to handle drag and drop events with already recognized and parsed data object. Override the above methods as needed in your DragAndDropHandler subclass to handle drag and drop events.
Parameters:
HWND window

The specified handle to the window in which the drag and drop event is occuring. This is one of the windows that was enabled via a IDragAndDropMgr::EnabledDnD() call, so it may be the parent of the lowest-level window that the mouse is actually over.

DropType* type

The specified Pointer to the DropType instance that corresponds to the data in the dropped IDataObject. You can use the DropType::TypeCode() method to determine the droptype (see the built-in codes in the DropType section). Each DropType subclass instance has utility methods and public data members containing the parsed drop data. See each subclass definition for details.

DWORD grfKeyState

The specified current state of the keyboard modifier keys on the keyboard. Valid values can be a combination of any of the flags MK_CONTROL, MK_SHIFT, MK_ALT, MK_BUTTON, MK_LBUTTON, MK_MBUTTON, and MK_RBUTTON.

POINT& pt

The specified current cursor coordinates in the coordinate space of the drop-target window.

DWORD* pdwEffect

On entry, pointer to the value of the pdwEffect parameter of the DoDragDrop function. On return, must contain one of the effect flags from the Win32 DROPEFFECT enumeration, which indicates what the result of the drop operation would be.
Returns
Standard return values of E_OUTOFMEMORY, E_INVALIDARG, F_UNEXPECTED, and E_FAIL, S_OK.
Default Implementation:
{ return E_FAIL; }
414 { return E_FAIL; }
virtual HRESULT Drop ( HWND  window,
DropType type,
DWORD  grfKeyState,
POINT &  pt,
DWORD *  pdwEffect 
)
inlinevirtual
Remarks
This method will parse the dropped dataObject.

Here's an example implementation of Drop() in the default handler:

HRESULT DefaultDragAndDropHandler::Drop(HWND hwnd, DropType* type, DWORD grfKeyState, POINT& pt, DWORD* pdwEffect)
{
// This could take a while, set wait cursor
HCURSOR hOldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));
HRESULT result = S_OK;
// load the dropped data if needed
if (type->Load()) {
// see if dropped on a viewport, if so adjust point
// to be vp-relative
HWND vpwin = FindDropViewport(hwnd, pt);
// Handle the drop depending on drop type
BOOL bRet;
switch (type->TypeCode()) {
bRet = HandleDroppedGeom(
hwnd, vpwin, pt,
break;
bRet = HandleDroppedBitmap(
hwnd, vpwin, pt,
break;
case DROPSCRIPTEFILE_DROPTYPE:
bRet = HandleDroppedDropScript(
hwnd, vpwin, pt,
break;
}
result = bRet ? S_OK : E_FAIL;
}
// restore cursor
SetCursor(hOldCursor);
return result;
}
Parameters:
HWND window

The specified handle to the window in which the drag and drop event is occuring. This is one of the windows that was enabled via a IDragAndDropMgr::EnabledDnD() call, so it may be the parent of the lowest-level window that the mouse is actually over.

DropType* type

The specified Pointer to the DropType instance that corresponds to the data in the dropped IDataObject. You can use the DropType::TypeCode() method to determine the droptype (see the built-in codes in the DropType section). Each DropType subclass instance has utility methods and public data members containing the parsed drop data. See each subclass definition for details.

DWORD grfKeyState

The specified current state of the keyboard modifier keys on the keyboard. Valid values can be a combination of any of the flags MK_CONTROL, MK_SHIFT, MK_ALT, MK_BUTTON, MK_LBUTTON, MK_MBUTTON, and MK_RBUTTON.

POINT& pt

The specified current cursor coordinates in the coordinate space of the drop-target window.

DWORD* pdwEffect

On entry, pointer to the value of the pdwEffect parameter of the DoDragDrop function. On return, must contain one of the effect flags from the Win32 DROPEFFECT enumeration, which indicates what the result of the drop operation would be.
Returns
Standard return values of E_OUTOFMEMORY, E_INVALIDARG, F_UNEXPECTED, and E_FAIL, S_OK.
Default Implementation:
{ return E_FAIL; }
486 { return E_FAIL; }
virtual HRESULT DragOver ( HWND  window,
DWORD  grfKeyState,
POINT &  pt,
DWORD *  pdwEffect 
)
inlinevirtual
Remarks
This method handles the process of dragging over a drop target.
Parameters:
HWND window

The specified handle to the window in which the drag and drop event is occuring. This is one of the windows that was enabled via a IDragAndDropMgr::EnabledDnD() call, so it may be the parent of the lowest-level window that the mouse is actually over.

DWORD grfKeyState

The specified current state of the keyboard modifier keys on the keyboard. Valid values can be a combination of any of the flags MK_CONTROL, MK_SHIFT, MK_ALT, MK_BUTTON, MK_LBUTTON, MK_MBUTTON, and MK_RBUTTON.

POINT& pt

The specified current cursor coordinates in the coordinate space of the drop-target window.

DWORD* pdwEffect

On entry, pointer to the value of the pdwEffect parameter of the DoDragDrop function. On return, must contain one of the effect flags from the Win32 DROPEFFECT enumeration, which indicates what the result of the drop operation would be.

Returns
Standard return values of E_OUTOFMEMORY, E_INVALIDARG, F_UNEXPECTED, and E_FAIL, S_OK.
Default Implementation:
{ return E_FAIL; }
513 { return E_FAIL; }
virtual void Acquire ( )
inlinevirtual
Remarks
This method is called when the drag and drop manager starts managing a window for this handler. managing drag and drop events for a particular window for this handler. You can provide an implementation if you need to keep track of extant uses of the handler (say, by ref-counting) or to do handler-specific cleanup.
Default Implementation:
{ }
522 { };
virtual void Release ( )
inlinevirtual

This method is called called during a when the drag and drop manager stops managing drag and drop events for a particular window for this handler.

By default, the drag and drop manager will call this method on all registered DragAndDropHandler's during a NOTIFY_SYSTEM_SHUTDOWN broadcast. You should provide an implementation if you need to keep track of extant uses of the handler (say, by ref-counting) or to do handler-specific cleanup.

Default Implementation:
{ }
531 { };

Member Data Documentation

DropType* current_droptype
protected

Cache for the currently parsed DropType.

This is usually filled in during DragEnter() processing in the DragAndDropHandler for the current window.

CoreExport IDragAndDropMgr* dndMgr
staticprotected

Cached pointer to drag and drop manager.