diff --git a/widget/src/windows/nsDataObjCollection.cpp b/widget/src/windows/nsDataObjCollection.cpp index c24879718326..3a32a7d831ac 100644 --- a/widget/src/windows/nsDataObjCollection.cpp +++ b/widget/src/windows/nsDataObjCollection.cpp @@ -60,7 +60,6 @@ ULONG nsDataObjCollection::g_cRef = 0; EXTERN_C GUID CDECL CLSID_nsDataObjCollection = { 0x2d851b91, 0xd4c, 0x11d3, { 0x96, 0xd4, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } }; - /* * Class nsDataObjCollection */ @@ -113,7 +112,13 @@ STDMETHODIMP nsDataObjCollection::QueryInterface(REFIID riid, void** ppv) *ppv=NULL; if ( (IID_IUnknown == riid) || (IID_IDataObject == riid) ) { - *ppv = this; + *ppv = static_cast(this); + AddRef(); + return NOERROR; + } + + if ( IID_IDataObjCollection == riid ) { + *ppv = static_cast(this); AddRef(); return NOERROR; } diff --git a/widget/src/windows/nsDataObjCollection.h b/widget/src/windows/nsDataObjCollection.h index 72bcd6a472f7..1e1b24da5135 100644 --- a/widget/src/windows/nsDataObjCollection.h +++ b/widget/src/windows/nsDataObjCollection.h @@ -38,6 +38,8 @@ #ifndef _NSDATAOBJCOLLECTION_H_ #define _NSDATAOBJCOLLECTION_H_ +#define INITGUID // needed for initializing the IID_IDataObjCollection GUID + #include "OLEIDL.H" #include "nsString.h" @@ -65,13 +67,24 @@ public: }; #endif +// {25589C3E-1FAC-47b9-BF43-CAEA89B79533} +DEFINE_GUID(IID_IDataObjCollection, +0x25589c3e, 0x1fac, 0x47b9, 0xbf, 0x43, 0xca, 0xea, 0x89, 0xb7, 0x95, 0x33); + +// An interface to make sure we have the right kind of object for D&D +// this way we can filter out collection objects that aren't ours +class nsIDataObjCollection : public IUnknown { +public: + +}; + /* * This ole registered class is used to facilitate drag-drop of objects which * can be adapted by an object derived from CfDragDrop. The CfDragDrop is * associated with instances via SetDragDrop(). */ -class nsDataObjCollection : public IDataObject //, public nsPIDataObjCollection +class nsDataObjCollection : public IDataObject, public nsIDataObjCollection //, public nsPIDataObjCollection { public: // construction, destruction nsDataObjCollection(); diff --git a/widget/src/windows/nsDragService.cpp b/widget/src/windows/nsDragService.cpp index 1723236493d4..429986ff86ae 100644 --- a/widget/src/windows/nsDragService.cpp +++ b/widget/src/windows/nsDragService.cpp @@ -163,6 +163,22 @@ NS_IMETHODIMP nsDragService::StartInvokingDragSession(IDataObject * aDataObj, PR return (DRAGDROP_S_DROP == res?NS_OK:NS_ERROR_FAILURE); } +//------------------------------------------------------------------------- +// Make Sure we have the right kind of object +nsDataObjCollection* nsDragService::GetDataObjCollection(IDataObject* aDataObj) +{ + nsDataObjCollection * dataObjCol = nsnull; + if (aDataObj) { + nsIDataObjCollection* dataObj; + if (aDataObj->QueryInterface(IID_IDataObjCollection, (void**)&dataObj) == S_OK) { + dataObjCol = NS_STATIC_CAST(nsDataObjCollection*, aDataObj); + dataObj->Release(); + } + } + + return dataObjCol; +} + //------------------------------------------------------------------------- NS_IMETHODIMP nsDragService::GetNumDropItems (PRUint32 * aNumItems) { @@ -172,7 +188,8 @@ NS_IMETHODIMP nsDragService::GetNumDropItems (PRUint32 * aNumItems) } if ( IsCollectionObject(mDataObject) ) { - nsDataObjCollection * dataObjCol = NS_STATIC_CAST(nsDataObjCollection*, mDataObject); + + nsDataObjCollection * dataObjCol = GetDataObjCollection(mDataObject); if ( dataObjCol ) *aNumItems = dataObjCol->GetNumDataObjects(); } @@ -211,7 +228,7 @@ NS_IMETHODIMP nsDragService::GetData (nsITransferable * aTransferable, PRUint32 if ( IsCollectionObject(mDataObject) ) { // multiple items, use |anItem| as an index into our collection - nsDataObjCollection * dataObjCol = NS_STATIC_CAST(nsDataObjCollection*, mDataObject); + nsDataObjCollection * dataObjCol = GetDataObjCollection(mDataObject); PRUint32 cnt = dataObjCol->GetNumDataObjects(); if (anItem >= 0 && anItem < cnt) { IDataObject * dataObj = dataObjCol->GetDataObjectAt(anItem); @@ -271,7 +288,7 @@ NS_IMETHODIMP nsDragService::IsDataFlavorSupported(const char *aDataFlavor, PRBo SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL | TYMED_FILE | TYMED_GDI); // See if any one of the IDataObjects in the collection supports this data type - nsDataObjCollection* dataObjCol = NS_STATIC_CAST(nsDataObjCollection*, mDataObject); + nsDataObjCollection* dataObjCol = GetDataObjCollection(mDataObject); if ( dataObjCol ) { PRUint32 cnt = dataObjCol->GetNumDataObjects(); for (PRUint32 i=0;i