Add an interface to nsDataObjectCollection so we can QI to check to make sure

it is one of our objects before doing the static cast.
Bug 106211 r=pink sr=jst
This commit is contained in:
rods%netscape.com 2002-06-14 11:28:13 +00:00
Родитель 32a633fa36
Коммит 1fda50c412
4 изменённых файлов: 43 добавлений и 6 удалений

Просмотреть файл

@ -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<IDataObject*>(this);
AddRef();
return NOERROR;
}
if ( IID_IDataObjCollection == riid ) {
*ppv = static_cast<nsIDataObjCollection*>(this);
AddRef();
return NOERROR;
}

Просмотреть файл

@ -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();

Просмотреть файл

@ -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<cnt;++i) {

Просмотреть файл

@ -43,6 +43,7 @@
struct IDropSource;
struct IDataObject;
class nsNativeDragTarget;
class nsDataObjCollection;
/**
* Native Win32 DragService wrapper
@ -69,6 +70,7 @@ public:
NS_IMETHOD StartInvokingDragSession(IDataObject * aDataObj, PRUint32 aActionType);
protected:
nsDataObjCollection* GetDataObjCollection(IDataObject* aDataObj);
// determine if we have a single data object or one of our private collections
PRBool IsCollectionObject ( IDataObject* inDataObj ) ;