Changed over to nsIGenericTransferable for setting transferables

Added Drag & Drag Support ifdef'ed out with NEW_DRAG_AND_DROP
This commit is contained in:
rods%netscape.com 1999-04-17 13:49:39 +00:00
parent 1bd24697e3
commit 7a714d4942
26 changed files with 382 additions and 997 deletions

View File

@ -20,34 +20,66 @@
#define nsIDragService_h__
#include "nsISupports.h"
#include "nsPoint.h"
class nsIDragSource;
class nsIImage;
class nsITransferable;
struct nsSize;
// {8B5314BB-DB01-11d2-96CE-0060B0FB9956}
#define NS_IDRAGSERVICE_IID \
{ 0x8b5314bb, 0xdb01, 0x11d2, { 0x96, 0xce, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } }
#define DRAGDROP_ACTION_COPY 1
#define DRAGDROP_ACTION_MOVE 2
#define DRAGDROP_ACTION_LINK 4
class nsIDragService : public nsISupports {
public:
/**
* Set the current state of the drag whether it can be dropped or not.
* usually the target "frame" sets this so the native system can render the correct feedback
*
* @param aCanDrop indicates whether it can be dropped here
*/
NS_IMETHOD SetCanDrop (PRBool aCanDrop) = 0;
/**
* Retrieves whether the drag can be dropped at this location
*
* @param aCanDrop indicates whether it can be dropped here
*/
NS_IMETHOD GetCanDrop (PRBool * aCanDrop) = 0;
/**
* Sets the current width and height if the drag target area.
* It will contain the current size of the Frame that the drag is currently in
*
* @param aDragTargetSize contains width/height of the current target
*/
NS_IMETHOD SetTargetSize (nsSize aDragTargetSize) = 0;
/**
* Gets the current width and height if the drag target area.
* It will contain the current size of the Frame that the drag is currently in
*
* @param aCanDrop indicates whether it can be dropped here
*/
NS_IMETHOD GetTargetSize (nsSize * aDragTargetSize) = 0;
/**
* Starts a modal drag session.
*
* @param aDragSrc the object being dragged
* @param aStartLocation start location of drag
* @param aImageOffset the offset the image should be from the cursor
* @param aImage image to be dragged
* @param aDoFlyback indicates image flys back
* @param aTransferable the transferable to be dragged
*/
NS_IMETHOD StartDragSession (nsIDragSource * aDragSrc,
nsPoint * aStartLocation,
nsPoint * aImageOffset,
nsIImage * aImage,
PRBool aDoFlyback) = 0;
NS_IMETHOD StartDragSession (nsITransferable * aTransferable, PRUint32 aActionType) = 0;
/**
* Get data from a Drag->Drop
*
* @param aTransferable the transferable for the data to be put into
*/
NS_IMETHOD GetData (nsITransferable * aTransferable) = 0;
};
#endif

View File

@ -36,15 +36,6 @@ class nsITransferable : public nsISupports {
static const nsIID& GetIID() { static nsIID iid = NS_ITRANSFERABLE_IID; return iid; }
/**
* Computes a list of flavors that the transferable can accept into it, either through
* intrinsic knowledge or input data converters.
*
* @param outFlavorList fills list with supported flavors. This is a copy of
* the internal list, so it may be edited w/out affecting the transferable.
*/
NS_IMETHOD FlavorsTransferableCanImport ( nsISupportsArray** outFlavorList ) = 0;
/**
* Computes a list of flavors that the transferable can export, either through
* intrinsic knowledge or output data converters.
@ -81,43 +72,12 @@ class nsITransferable : public nsISupports {
*/
NS_IMETHOD GetTransferData(nsIDataFlavor * aFlavor, void ** aData, PRUint32 * aDataLen) = 0;
/**
* Set Data into the transferable as a specified DataFlavor. The transferable now
* owns the data, so the caller must not delete it.
*
* @param aFlavor the flavor of data that is being set
* @param aData the data
* @param aDataLen the length of the data (it may or may not be meaningful)
*/
NS_IMETHOD SetTransferData(nsIDataFlavor * aFlavor, void * aData, PRUint32 aDataLen) = 0;
/**
* Add the data flavor, indicating that this transferable
* can receive this type of flavor
*
* @param aDataFlavor a new data flavor to handle
* @param aHumanPresentableName human readable string for mime
*/
NS_IMETHOD AddDataFlavor(nsIDataFlavor * aDataFlavor) = 0;
/**
* Returns PR_TRUE if the data is large.
*
*/
NS_IMETHOD_(PRBool) IsLargeDataSet() = 0;
/**
* Sets the converter for this transferable
*
*/
NS_IMETHOD SetConverter(nsIFormatConverter * aConverter) = 0;
/**
* Gets the converter for this transferable
*
*/
NS_IMETHOD GetConverter(nsIFormatConverter ** aConverter) = 0;
};
#endif

View File

@ -175,30 +175,18 @@
//-----------------------------------------------------------
//Drag & Drop & Clipboard
//-----------------------------------------------------------
// {8B5314B9-DB01-11d2-96CE-0060B0FB9956}
#define NS_DRAGGEDOBJECT_CID \
{ 0x8b5314b9, 0xdb01, 0x11d2, { 0x96, 0xce, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } }
// {8B5314BB-DB01-11d2-96CE-0060B0FB9956}
#define NS_DRAGSERVICE_CID \
{ 0x8b5314bb, 0xdb01, 0x11d2, { 0x96, 0xce, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } }
// {8B5314BC-DB01-11d2-96CE-0060B0FB9956}
#define NS_TRANSFERABLE_CID \
{ 0x8b5314bc, 0xdb01, 0x11d2, { 0x96, 0xce, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } }
// {867AF703-F360-11D2-96D2-0060B0FB9956}
#define NS_GENERICTRANSFERABLE_CID \
{ 0x867af703, 0xf360, 0x11d2, { 0x96, 0xd2, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } }
// {8B5314BA-DB01-11d2-96CE-0060B0FB9956}
#define NS_CLIPBOARD_CID \
{ 0x8b5314ba, 0xdb01, 0x11d2, { 0x96, 0xce, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } }
// {8B5314B7-DB01-11d2-96CE-0060B0FB9956}
#define NS_DRAGSOURCE_CID \
{ 0x8b5314b7, 0xdb01, 0x11d2, { 0x96, 0xce, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } }
// {8B5314B8-DB01-11d2-96CE-0060B0FB9956}
#define NS_DRAGTARGET_CID \
{ 0x8b5314b8, 0xdb01, 0x11d2, { 0x96, 0xce, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } }
// {8B5314BD-DB01-11d2-96CE-0060B0FB9956}
#define NS_DATAFLAVOR_CID \
{ 0x8b5314bd, 0xdb01, 0x11d2, { 0x96, 0xce, 0x0, 0x60, 0xb0, 0xfb, 0x99, 0x56 } }

View File

@ -54,9 +54,6 @@
#include "nsXIFFormatConverter.h"
#include "nsDataFlavor.h"
#include "nsDragService.h"
#include "nsDragSource.h"
#include "nsDragTarget.h"
#include "nsDraggedObject.h"
static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID);
static NS_DEFINE_IID(kCChild, NS_CHILD_CID);
@ -87,13 +84,10 @@ static NS_DEFINE_IID(kCMenuButton, NS_MENUBUTTON_CID);
// Drag & Drop, Clipboard
static NS_DEFINE_IID(kCDataObj, NS_DATAOBJ_CID);
static NS_DEFINE_IID(kCClipboard, NS_CLIPBOARD_CID);
static NS_DEFINE_IID(kCTransferable, NS_TRANSFERABLE_CID);
static NS_DEFINE_IID(kCGenericTransferable, NS_GENERICTRANSFERABLE_CID);
static NS_DEFINE_IID(kCXIFFormatConverter, NS_XIFFORMATCONVERTER_CID);
static NS_DEFINE_IID(kCDataFlavor, NS_DATAFLAVOR_CID);
static NS_DEFINE_IID(kCDragService, NS_DRAGSERVICE_CID);
static NS_DEFINE_IID(kCDragSource, NS_DRAGSOURCE_CID);
static NS_DEFINE_IID(kCDragTarget, NS_DRAGTARGET_CID);
static NS_DEFINE_IID(kCDraggedObject, NS_DRAGGEDOBJECT_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
@ -249,8 +243,8 @@ nsresult nsWidgetFactory::CreateInstance( nsISupports* aOuter,
else if (mClassID.Equals(kCDataFlavor)) {
inst = (nsISupports*)new nsDataFlavor();
}
else if (mClassID.Equals(kCTransferable)) {
inst = (nsISupports*)new nsTransferable();
else if (mClassID.Equals(kCGenericTransferable)) {
inst = (nsISupports*)(nsIGenericTransferable *)new nsTransferable();
}
else if (mClassID.Equals(kCXIFFormatConverter)) {
inst = (nsISupports*)new nsXIFFormatConverter();
@ -261,20 +255,6 @@ nsresult nsWidgetFactory::CreateInstance( nsISupports* aOuter,
else if (mClassID.Equals(kCDragService)) {
inst = (nsISupports*)new nsDragService();
}
else if (mClassID.Equals(kCDragSource)) {
inst = (nsISupports*)new nsDragSource();
}
else if (mClassID.Equals(kCDragTarget)) {
inst = (nsISupports*)new nsDragTarget();
}
else if (mClassID.Equals(kCDraggedObject)) {
inst = (nsISupports*)new nsDraggedObject();
}
#ifdef DRAG_DROP
//else if (mClassID.Equals(kCDataObj)) {
//inst = (nsISupports*)new CfDataObj();
//}
#endif
/* */
if (inst == NULL) {

View File

@ -34,6 +34,7 @@
#include "nsIClipboardOwner.h"
#include "nsIDataFlavor.h"
#include "nsIFormatConverter.h"
#include "nsIGenericTransferable.h"
#include "nsIComponentManager.h"
#include "nsWidgetsCID.h"
@ -202,10 +203,15 @@ nsClipboard :: GetNativeClipboardData(nsITransferable * aTransferable)
if ( !aTransferable )
return NS_ERROR_INVALID_ARG;
nsCOMPtr<nsIGenericTransferable> genericTrans = do_QueryInterface(aTransferable);
if (!genericTrans) {
return NS_ERROR_FAILURE;
}
// get flavor list that includes all acceptable flavors (including ones obtained through
// conversion)
nsCOMPtr<nsISupportsArray> flavorList;
errCode = aTransferable->FlavorsTransferableCanImport ( getter_AddRefs(flavorList) );
errCode = genericTrans->FlavorsTransferableCanImport ( getter_AddRefs(flavorList) );
if ( errCode != NS_OK )
return NS_ERROR_FAILURE;
@ -240,7 +246,7 @@ nsClipboard :: GetNativeClipboardData(nsITransferable * aTransferable)
::HUnlock(dataHand);
// put it into the transferable
errCode = aTransferable->SetTransferData ( currentFlavor, dataBuff, dataSize );
errCode = genericTrans->SetTransferData ( currentFlavor, dataBuff, dataSize );
#ifdef NS_DEBUG
if ( errCode != NS_OK ) printf("nsClipboard:: Error setting data into transferable\n");
#endif

View File

@ -25,9 +25,6 @@ DEFINES =-D_IMPL_NS_WIDGET
CPPSRCS = \
nsNativeDragTarget.cpp \
nsNativeDragSource.cpp \
nsDraggedObject.cpp \
nsDragTarget.cpp \
nsDragSource.cpp \
nsDragService.cpp \
Ienumfe.cpp \
nsDataObj.cpp \
@ -64,9 +61,6 @@ MODULE=raptor
OBJS = \
.\$(OBJDIR)\nsNativeDragTarget.obj \
.\$(OBJDIR)\nsNativeDragSource.obj \
.\$(OBJDIR)\nsDraggedObject.obj \
.\$(OBJDIR)\nsDragSource.obj \
.\$(OBJDIR)\nsDragTarget.obj \
.\$(OBJDIR)\nsDragService.obj \
.\$(OBJDIR)\Ienumfe.obj \
.\$(OBJDIR)\nsDataObj.obj \

View File

@ -20,11 +20,14 @@
#include <windows.h>
#include <OLE2.h>
#include "nsCOMPtr.h"
#include "nsDataObj.h"
#include "nsISupportsArray.h"
#include "nsIClipboardOwner.h"
#include "nsIDataFlavor.h"
#include "nsIFormatConverter.h"
#include "nsIGenericTransferable.h"
#include "nsITransferable.h"
#include "nsIWidget.h"
#include "nsIComponentManager.h"
@ -127,7 +130,7 @@ static UINT GetFormat(const nsString & aMimeStr)
*
*
*/
NS_IMETHODIMP nsClipboard::CreateNativeDataObject(nsITransferable * aTransferable, IDataObject ** aDataObj)
nsresult nsClipboard::CreateNativeDataObject(nsITransferable * aTransferable, IDataObject ** aDataObj)
{
if (nsnull == aTransferable) {
return NS_ERROR_FAILURE;
@ -158,7 +161,7 @@ NS_IMETHODIMP nsClipboard::CreateNativeDataObject(nsITransferable * aTransferabl
UINT format = GetFormat(mime);
FORMATETC fe;
SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, 0, TYMED_HGLOBAL);
SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
// Now tell the native IDataObject about both the DataFlavor and
// the native data format
@ -173,8 +176,10 @@ NS_IMETHODIMP nsClipboard::CreateNativeDataObject(nsITransferable * aTransferabl
// Now check to see if there is a converter for the transferable
// and then register any of it's output formats
// Get the transferable list of data flavors
nsCOMPtr<nsIGenericTransferable> genericTrans = do_QueryInterface(aTransferable);
if (genericTrans) {
nsIFormatConverter * converter = nsnull;
aTransferable->GetConverter(&converter);
genericTrans->GetConverter(&converter);
if (nsnull != converter) {
// Get list of output flavors
converter->GetOutputDataFlavors(&dfList);
@ -188,7 +193,7 @@ NS_IMETHODIMP nsClipboard::CreateNativeDataObject(nsITransferable * aTransferabl
UINT format = GetFormat(mime);
FORMATETC fe;
SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, 0, TYMED_HGLOBAL);
SET_FORMATETC(fe, format, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
// Now tell the native IDataObject about both the DataFlavor and
// the native data format
@ -201,6 +206,7 @@ NS_IMETHODIMP nsClipboard::CreateNativeDataObject(nsITransferable * aTransferabl
}
NS_RELEASE(converter);
}
}
*aDataObj = dataObj;
return NS_OK;
@ -247,7 +253,7 @@ NS_IMETHODIMP nsClipboard::SetNativeClipboardData()
*
*
*/
static nsresult GetGlobalData(HGLOBAL aHGBL, void ** aData, PRUint32 * aLen)
nsresult nsClipboard::GetGlobalData(HGLOBAL aHGBL, void ** aData, PRUint32 * aLen)
{
nsresult result = NS_ERROR_FAILURE;
LPSTR lpStr;
@ -296,7 +302,7 @@ static nsresult GetGlobalData(HGLOBAL aHGBL, void ** aData, PRUint32 * aLen)
*
*
*/
static nsresult GetNativeDataOffClipboard(nsIWidget * aWindow, UINT aFormat, void ** aData, PRUint32 * aLen)
nsresult nsClipboard::GetNativeDataOffClipboard(nsIWidget * aWindow, UINT aFormat, void ** aData, PRUint32 * aLen)
{
HGLOBAL hglb;
nsresult result = NS_ERROR_FAILURE;
@ -314,7 +320,7 @@ static nsresult GetNativeDataOffClipboard(nsIWidget * aWindow, UINT aFormat, voi
*
*
*/
static nsresult GetNativeDataOffClipboard(IDataObject * aDataObject, UINT aFormat, void ** aData, PRUint32 * aLen)
nsresult nsClipboard::GetNativeDataOffClipboard(IDataObject * aDataObject, UINT aFormat, void ** aData, PRUint32 * aLen)
{
nsresult result = NS_ERROR_FAILURE;
@ -323,7 +329,7 @@ static nsresult GetNativeDataOffClipboard(IDataObject * aDataObject, UINT aForma
}
FORMATETC fe;
SET_FORMATETC(fe, aFormat, 0, DVASPECT_CONTENT, 0, TYMED_HGLOBAL);
SET_FORMATETC(fe, aFormat, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL);
if (S_OK == aDataObject->QueryGetData(&fe)) {
LPSTGMEDIUM stm;
@ -380,17 +386,19 @@ static nsresult GetNativeDataOffClipboard(IDataObject * aDataObject, UINT aForma
*
*
*/
NS_IMETHODIMP nsClipboard::GetNativeClipboardData(nsITransferable * aTransferable)
nsresult nsClipboard::GetDataFromDataObject(IDataObject * aDataObject,
nsIWidget * aWindow,
nsITransferable * aTransferable)
{
nsresult res = NS_ERROR_FAILURE;
// make sure we have a good transferable
if (nsnull == aTransferable) {
return NS_ERROR_FAILURE;
return res;
}
PRBool useOLE = PR_FALSE;
IDataObject * dataObj;
if (S_OK == ::OleGetClipboard(&dataObj)) {
useOLE = PR_TRUE;
nsCOMPtr<nsIGenericTransferable> genericTrans = do_QueryInterface(aTransferable);
if (!genericTrans) {
return res;
}
// Get the transferable list of data flavors
@ -410,21 +418,47 @@ NS_IMETHODIMP nsClipboard::GetNativeClipboardData(nsITransferable * aTransferabl
void * data;
PRUint32 dataLen;
if (useOLE) {
if (NS_OK == GetNativeDataOffClipboard(dataObj, format, &data, &dataLen)) {
aTransferable->SetTransferData(df, data, dataLen);
if (nsnull != aDataObject) {
res = GetNativeDataOffClipboard(aDataObject, format, &data, &dataLen);
if (NS_OK == res) {
genericTrans->SetTransferData(df, data, dataLen);
}
} else {
if (NS_OK == GetNativeDataOffClipboard(mWindow, format, &data, &dataLen)) {
aTransferable->SetTransferData(df, data, dataLen);
} else if (nsnull != aWindow) {
res = GetNativeDataOffClipboard(aWindow, format, &data, &dataLen);
if (NS_OK == res) {
genericTrans->SetTransferData(df, data, dataLen);
}
}
NS_RELEASE(df);
NS_IF_RELEASE(df);
}
NS_RELEASE(supports);
}
return NS_OK;
return res;
}
/**
*
*
*/
NS_IMETHODIMP nsClipboard::GetNativeClipboardData(nsITransferable * aTransferable)
{
// make sure we have a good transferable
if (nsnull == aTransferable) {
return NS_ERROR_FAILURE;
}
nsresult res;
IDataObject * dataObj;
if (S_OK == ::OleGetClipboard(&dataObj)) {
res = GetDataFromDataObject(dataObj, nsnull, aTransferable);
} else {
res = GetDataFromDataObject(nsnull, mWindow, aTransferable);
}
return res;
}

View File

@ -20,6 +20,7 @@
#define nsClipboard_h__
#include "nsBaseClipboard.h"
#include <windows.h>
class nsITransferable;
//class nsDataObj;
@ -46,7 +47,19 @@ public:
NS_IMETHOD ForceDataToClipboard();
// Internal Native Routines
NS_IMETHODIMP CreateNativeDataObject(nsITransferable * aTransferable, IDataObject ** aDataObj);
static nsresult CreateNativeDataObject(nsITransferable * aTransferable,
IDataObject ** aDataObj);
static nsresult GetDataFromDataObject(IDataObject * aDataObject,
nsIWidget * aWindow,
nsITransferable * aTransferable);
static nsresult GetNativeDataOffClipboard(nsIWidget * aWindow, UINT aFormat, void ** aData, PRUint32 * aLen);
static nsresult GetNativeDataOffClipboard(IDataObject * aDataObject, UINT aFormat, void ** aData, PRUint32 * aLen);
static nsresult GetGlobalData(HGLOBAL aHGBL, void ** aData, PRUint32 * aLen);
protected:

View File

@ -203,6 +203,7 @@ BOOL nsDataObj::FormatsMatch(const FORMATETC& source, const FORMATETC& target) c
STDMETHODIMP nsDataObj::GetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
{
printf("nsDataObj::GetData\n");
if (nsnull == mTransferable) {
return ResultFromScode(DATA_E_FORMATETC);
}
@ -244,6 +245,7 @@ STDMETHODIMP nsDataObj::GetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
STDMETHODIMP nsDataObj::GetDataHere(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
{
printf("nsDataObj::GetDataHere\n");
//if (m_dragDrop) {
// return m_dragDrop->GetDataHere(pFE, pSTM);
//} else {
@ -254,16 +256,26 @@ STDMETHODIMP nsDataObj::GetDataHere(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
STDMETHODIMP nsDataObj::QueryGetData(LPFORMATETC pFE)
{
//if (m_dragDrop) {
// return m_dragDrop->QueryGetData(pFE);
//} else {
printf("nsDataObj::QueryGetData ");
printf("format: %d Text: %d\n", pFE->cfFormat, CF_TEXT);
PRUint32 dfInx = 0;
ULONG count;
FORMATETC fe;
m_enumFE->Reset();
while (NOERROR == m_enumFE->Next(1, &fe, &count)) {
if (fe.cfFormat == pFE->cfFormat) {
return S_OK;
}
}
return ResultFromScode(E_FAIL);
//}
}
STDMETHODIMP nsDataObj::GetCanonicalFormatEtc
(LPFORMATETC pFEIn, LPFORMATETC pFEOut)
{
printf("nsDataObj::GetCanonicalFormatEtc\n");
//if (m_dragDrop) {
// return m_dragDrop->GetCanonicalFormatEtc(pFEIn, pFEOut);
//} else {
@ -274,6 +286,7 @@ STDMETHODIMP nsDataObj::GetCanonicalFormatEtc
STDMETHODIMP nsDataObj::SetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL fRelease)
{
printf("nsDataObj::SetData\n");
return ResultFromScode(E_FAIL);
//return m_dragDrop->SetData(pFE, pSTM, fRelease);
}
@ -281,6 +294,7 @@ STDMETHODIMP nsDataObj::SetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM, BOOL fRelease
STDMETHODIMP nsDataObj::EnumFormatEtc(DWORD dwDir, LPENUMFORMATETC *ppEnum)
{
printf("nsDataObj::EnumFormatEtc\n");
switch (dwDir) {
case DATADIR_GET: {
@ -305,17 +319,20 @@ STDMETHODIMP nsDataObj::EnumFormatEtc(DWORD dwDir, LPENUMFORMATETC *ppEnum)
STDMETHODIMP nsDataObj::DAdvise(LPFORMATETC pFE, DWORD dwFlags,
LPADVISESINK pIAdviseSink, DWORD* pdwConn)
{
printf("nsDataObj::DAdvise\n");
return ResultFromScode(E_FAIL);
}
STDMETHODIMP nsDataObj::DUnadvise(DWORD dwConn)
{
printf("nsDataObj::DUnadvise\n");
return ResultFromScode(E_FAIL);
}
STDMETHODIMP nsDataObj::EnumDAdvise(LPENUMSTATDATA *ppEnum)
{
printf("nsDataObj::EnumDAdvise\n");
return ResultFromScode(E_FAIL);
}

View File

@ -17,26 +17,25 @@
*/
#include "nsDragService.h"
#include "nsIDragSource.h"
#include "nsITransferable.h"
#include "nsDragSource.h"
#include "nsDataObj.h"
#include "nsTransferable.h"
#include "nsIServiceManager.h"
#include "nsWidgetsCID.h"
#include "nsIClipboard.h"
#include "nsNativeDragTarget.h"
#include "nsNativeDragSource.h"
#include "nsClipboard.h"
#include "OLEIDL.h"
#include "OLE2.h"
#include <OLE2.h>
#include "OLEIDL.H"
static NS_DEFINE_IID(kIDragServiceIID, NS_IDRAGSERVICE_IID);
static NS_DEFINE_IID(kIClipboardIID, NS_ICLIPBOARD_IID);
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
//static NS_DEFINE_IID(kIClipboardIID, NS_ICLIPBOARD_IID);
NS_IMPL_ADDREF(nsDragService)
NS_IMPL_RELEASE(nsDragService)
//static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
NS_IMPL_ADDREF_INHERITED(nsDragService, nsBaseDragService)
NS_IMPL_RELEASE_INHERITED(nsDragService, nsBaseDragService)
//-------------------------------------------------------------------------
//
@ -46,8 +45,9 @@ NS_IMPL_RELEASE(nsDragService)
nsDragService::nsDragService()
{
NS_INIT_REFCNT();
mDragSource = nsnull;
mNativeDragTarget = nsnull;
mNativeDragSrc = nsnull;
mDataObject = nsnull;
}
//-------------------------------------------------------------------------
@ -57,7 +57,9 @@ nsDragService::nsDragService()
//-------------------------------------------------------------------------
nsDragService::~nsDragService()
{
NS_IF_RELEASE(mDragSource);
NS_IF_RELEASE(mNativeDragSrc);
NS_IF_RELEASE(mNativeDragTarget);
NS_IF_RELEASE(mDataObject);
}
/**
@ -84,34 +86,60 @@ nsresult nsDragService::QueryInterface(const nsIID& aIID, void** aInstancePtr)
return rv;
}
NS_IMETHODIMP nsDragService::StartDragSession (nsIDragSource * aDragSrc,
nsPoint * aStartLocation,
nsPoint * aImageOffset,
nsIImage * aImage,
PRBool aDoFlyback)
//---------------------------------------------------------
NS_IMETHODIMP nsDragService::StartDragSession (nsITransferable * aTransferable, PRUint32 aActionType)
{
NS_IF_RELEASE(mDragSource);
mDragSource = aDragSrc;
NS_ADDREF(mDragSource);
nsIClipboard* clipboard;
nsresult rv = nsServiceManager::GetService(kCClipboardCID,
kIClipboardIID,
(nsISupports **)&clipboard);
if (NS_OK == rv) {
nsITransferable * trans;
mDragSource->GetTransferable(&trans);
IDataObject * dataObj;
((nsClipboard *)clipboard)->CreateNativeDataObject(trans, &dataObj);
// To do the drag we need to create an object that
// mplements the IDataObject interface (for OLE)
//
// We start by getting the clipboard object,
// casting it our known class and using utility
DWORD dropRes;
HRESULT res = 0;
res = ::DoDragDrop(dataObj,
(IDropSource *)((nsDragSource *)mDragSource)->GetNativeDragSrc(),
DROPEFFECT_COPY | DROPEFFECT_MOVE | DROPEFFECT_SCROLL, &dropRes);
NS_IF_RELEASE(mNativeDragSrc);
mNativeDragSrc = (IDropSource *)new nsNativeDragSource();
if (nsnull != mNativeDragSrc) {
mNativeDragSrc->AddRef();
}
mTransferable = dont_QueryInterface(aTransferable);
IDataObject * dataObj;
nsClipboard::CreateNativeDataObject(mTransferable, &dataObj);
nsresult result = NS_ERROR_FAILURE;
DWORD dropRes;
DWORD effects = DROPEFFECT_SCROLL;
if (aActionType & DRAGDROP_ACTION_COPY) {
effects |= DROPEFFECT_COPY;
}
if (aActionType & DRAGDROP_ACTION_MOVE) {
effects |= DROPEFFECT_MOVE;
}
if (aActionType & DRAGDROP_ACTION_LINK) {
effects |= DROPEFFECT_LINK;
}
HRESULT res = ::DoDragDrop(dataObj, mNativeDragSrc, effects, &dropRes);
return (DRAGDROP_S_DROP == res?NS_OK:NS_ERROR_FAILURE);
}
//-------------------------------------------------------------------------
NS_IMETHODIMP nsDragService::GetData (nsITransferable * aTransferable)
{
if (nsnull != mDataObject) {
return nsClipboard::GetDataFromDataObject(mDataObject, nsnull, aTransferable);
}
return NS_ERROR_FAILURE;
}
//---------------------------------------------------------
NS_IMETHODIMP nsDragService::SetIDataObject (IDataObject * aDataObj)
{
NS_IF_RELEASE(mDataObject);
mDataObject = aDataObj;
NS_ADDREF(mDataObject);
return NS_OK;
}

View File

@ -19,23 +19,17 @@
#ifndef nsDragService_h__
#define nsDragService_h__
#include "nsIDragService.h"
#include "nsPoint.h"
#include "nsIImage.h"
#include "nsBaseDragService.h"
#include <OLE2.h>
#include "OLEIDL.H"
class nsIDragSource;
class nsDataObj;
#define MAX_FORMATS 32
struct IDropSource;
struct IDataObject;
class nsNativeDragTarget;
/**
* Native Win32 DragService wrapper
*/
class nsDragService : public nsIDragService
class nsDragService : public nsBaseDragService
{
public:
@ -43,22 +37,20 @@ public:
virtual ~nsDragService();
//nsISupports
NS_DECL_ISUPPORTS
NS_DECL_ISUPPORTS_INHERITED
//nsIDragService
NS_IMETHOD StartDragSession (nsIDragSource * aDragSrc,
nsPoint * aStartLocation,
nsPoint * aImageOffset,
nsIImage * aImage,
PRBool aDoFlyback);
NS_IMETHOD StartDragSession (nsITransferable * aTransferable, PRUint32 aActionType);
// Native Impl.
NS_IMETHOD SetIDataObject (IDataObject * aDataObj);
NS_IMETHOD GetData (nsITransferable * aTransferable);
protected:
nsIDragSource * mDragSource;
//nsDataObj * mDataObj;
IDropSource * mNativeDragSrc;
nsNativeDragTarget * mNativeDragTarget;
IDataObject * mDataObject;
};
#endif // nsDragService_h__

View File

@ -1,107 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsDragSource.h"
#include "nsITransferable.h"
#include "nsNativeDragSource.h"
static NS_DEFINE_IID(kIDragSourceIID, NS_IDRAGSOURCE_IID);
NS_IMPL_ADDREF(nsDragSource)
NS_IMPL_RELEASE(nsDragSource)
//-------------------------------------------------------------------------
//
// DragSource constructor
//
//-------------------------------------------------------------------------
nsDragSource::nsDragSource()
{
NS_INIT_REFCNT();
mNativeDragSrc = (IDropSource *)new nsNativeDragSource();
if (mNativeDragSrc) {
mNativeDragSrc->AddRef();
}
mTransferable = nsnull;
}
//-------------------------------------------------------------------------
//
// DragSource destructor
//
//-------------------------------------------------------------------------
nsDragSource::~nsDragSource()
{
if (mNativeDragSrc) {
mNativeDragSrc->Release();
}
}
/**
* @param aIID The name of the class implementing the method
* @param _classiiddef The name of the #define symbol that defines the IID
* for the class (e.g. NS_ISUPPORTS_IID)
*
*/
nsresult nsDragSource::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
nsresult rv = NS_NOINTERFACE;
if (aIID.Equals(kIDragSourceIID)) {
*aInstancePtr = (void*) ((nsIDragSource*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return rv;
}
NS_IMETHODIMP nsDragSource::GetTransferable(nsITransferable ** aTransferable)
{
if (nsnull != mTransferable) {
*aTransferable = mTransferable;
NS_ADDREF(mTransferable);
} else {
aTransferable = nsnull;
}
return NS_OK;
}
NS_IMETHODIMP nsDragSource::SetTransferable(nsITransferable * aTransferable)
{
NS_IF_RELEASE(mTransferable);
mTransferable = aTransferable;
NS_ADDREF(mTransferable);
return NS_OK;
}
NS_IMETHODIMP nsDragSource:: DragStopped(nsIDraggedObject * aDraggedObj, PRInt32 anAction)
{
return NS_OK;
}

View File

@ -1,60 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsDragSource_h__
#define nsDragSource_h__
#include "nsIDragSource.h"
//#include <OLE2.h>
//#include "OLEIDL.H"
class nsITransferable;
struct IDropSource;
/**
* Native Win32 DragSource wrapper
*/
class nsDragSource : public nsIDragSource
{
public:
nsDragSource();
virtual ~nsDragSource();
//nsISupports
NS_DECL_ISUPPORTS
//nsIDragSource
NS_IMETHOD GetTransferable(nsITransferable ** aTransferable);
NS_IMETHOD SetTransferable(nsITransferable * aTransferable);
NS_IMETHOD DragStopped(nsIDraggedObject * aDraggedObj, PRInt32 anAction);
IDropSource * GetNativeDragSrc() { return mNativeDragSrc; } // XXX this needs to be moved into impl
protected:
nsITransferable * mTransferable;
IDropSource * mNativeDragSrc;
};
#endif // nsDragSource_h__

View File

@ -1,90 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsDragTarget.h"
#include "nsIDraggedObject.h"
static NS_DEFINE_IID(kIDragTargetIID, NS_IDRAGTARGET_IID);
NS_IMPL_ADDREF(nsDragTarget)
NS_IMPL_RELEASE(nsDragTarget)
//-------------------------------------------------------------------------
//
// DragTarget constructor
//
//-------------------------------------------------------------------------
nsDragTarget::nsDragTarget()
{
NS_INIT_REFCNT();
}
//-------------------------------------------------------------------------
//
// DragTarget destructor
//
//-------------------------------------------------------------------------
nsDragTarget::~nsDragTarget()
{
}
/**
* @param aIID The name of the class implementing the method
* @param _classiiddef The name of the #define symbol that defines the IID
* for the class (e.g. NS_ISUPPORTS_IID)
*
*/
nsresult nsDragTarget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
nsresult rv = NS_NOINTERFACE;
if (aIID.Equals(kIDragTargetIID)) {
*aInstancePtr = (void*) ((nsIDragTarget*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return rv;
}
NS_IMETHODIMP nsDragTarget::DragEnter(nsIDraggedObject * aDraggedObj, nsPoint * aLocation)
{
return NS_OK;
}
NS_IMETHODIMP nsDragTarget::DragOver(nsIDraggedObject * aDraggedObj, nsPoint * aLocation)
{
return NS_OK;
}
NS_IMETHODIMP nsDragTarget::DragExit(nsIDraggedObject * aDraggedObj, nsPoint * aLocation)
{
return NS_OK;
}
NS_IMETHODIMP nsDragTarget::DragDrop(nsIDraggedObject * aDraggedObj, PRInt32 aActions)
{
return NS_OK;
}

View File

@ -1,58 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsDragTarget_h__
#define nsDragTarget_h__
#include "nsIDragTarget.h"
#include "nsPoint.h"
#include <OLE2.h>
#include "OLEIDL.H"
class nsIDraggedObject;
/**
* Native Win32 DragTarget wrapper
*/
class nsDragTarget : public nsIDragTarget
{
public:
nsDragTarget();
virtual ~nsDragTarget();
//nsISupports
NS_DECL_ISUPPORTS
//nsIDragTarget
NS_IMETHOD DragEnter(nsIDraggedObject * aDraggedObj, nsPoint * aLocation);
NS_IMETHOD DragOver(nsIDraggedObject * aDraggedObj, nsPoint * aLocation);
NS_IMETHOD DragExit(nsIDraggedObject * aDraggedObj, nsPoint * aLocation);
NS_IMETHOD DragDrop(nsIDraggedObject * aDraggedObj, PRInt32 aActions);
protected:
};
#endif // nsDragTarget_h__

View File

@ -1,96 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsDraggedObject.h"
#include "nsIDraggedObject.h"
static NS_DEFINE_IID(kIDraggedObjectIID, NS_IDRAGGEDOBJECT_IID);
NS_IMPL_ADDREF(nsDraggedObject)
NS_IMPL_RELEASE(nsDraggedObject)
//-------------------------------------------------------------------------
//
// DraggedObject constructor
//
//-------------------------------------------------------------------------
nsDraggedObject::nsDraggedObject()
{
NS_INIT_REFCNT();
}
//-------------------------------------------------------------------------
//
// DraggedObject destructor
//
//-------------------------------------------------------------------------
nsDraggedObject::~nsDraggedObject()
{
}
/**
* @param aIID The name of the class implementing the method
* @param _classiiddef The name of the #define symbol that defines the IID
* for the class (e.g. NS_ISUPPORTS_IID)
*
*/
nsresult nsDraggedObject::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
nsresult rv = NS_NOINTERFACE;
if (aIID.Equals(kIDraggedObjectIID)) {
*aInstancePtr = (void*) ((nsIDraggedObject*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return rv;
}
NS_IMETHODIMP nsDraggedObject::GetDragOffset(nscoord * aX, nscoord * aY)
{
return NS_OK;
}
NS_IMETHODIMP nsDraggedObject::GetTransferable(nsITransferable ** aTransferable)
{
return NS_OK;
}
NS_IMETHODIMP nsDraggedObject::GetSource(nsIDragSource ** aDragSrc)
{
return NS_OK;
}
NS_IMETHODIMP nsDraggedObject::GetTarget(nsIDragTarget ** aTarget)
{
return NS_OK;
}
NS_IMETHODIMP nsDraggedObject::GetTargetnFrame(nsIFrame ** aFrame)
{
return NS_OK;
}

View File

@ -1,58 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsDraggedObject_h__
#define nsDraggedObject_h__
#include "nsIDraggedObject.h"
#include "nsPoint.h"
#include <OLE2.h>
#include "OLEIDL.H"
class nsIDraggedObject;
/**
* Native Win32 DraggedObject wrapper
*/
class nsDraggedObject : public nsIDraggedObject
{
public:
nsDraggedObject();
virtual ~nsDraggedObject();
//nsISupports
NS_DECL_ISUPPORTS
//nsIDraggedObject
NS_IMETHOD GetDragOffset(nscoord * aX, nscoord * aY);
NS_IMETHOD GetTransferable(nsITransferable ** aTransferable);
NS_IMETHOD GetSource(nsIDragSource ** aDragSrc);
NS_IMETHOD GetTarget(nsIDragTarget ** aTarget);
NS_IMETHOD GetTargetnFrame(nsIFrame ** aFrame);
protected:
};
#endif // nsDraggedObject_h__

View File

@ -1,234 +0,0 @@
//#include "stdafx.h"
//#include "olebase.h"
//#include "idropsrc.h"
#include "nsDropTarget.h"
//#include "contndoc.h"
#include "stdio.h"
#include "nsIWidget.h"
#include "nsWindow.h"
//Don't forget to RegisterDragDrop and to
//CoLockObjectExternal.
//You must RevokeDragDrop before destroying this object
//
nsDropTarget::nsDropTarget(nsIWidget * aWindow)
{
printf("nsDropTarget::nsDropTarget\n");
m_refs = 0;
m_pWin = aWindow;
NS_ADDREF(aWindow);
}
//Destructor for nsDropTarget
//Doesn't do a whole lot!
//
nsDropTarget::~nsDropTarget()
{
printf("nsDropTarget::Drop\n");
;
}
//QueryInterface for IDropTarget
//Notice that this QueryInterface does not refer to another object's QueryInterface,
//this is a totally stand-alone separate object
//
STDMETHODIMP nsDropTarget::QueryInterface(REFIID riid, LPVOID FAR* ppv)
{
printf("nsDropTarget::QueryInterface\n");
if (riid == IID_IUnknown)
*ppv = this;
else if (riid == IID_IDropTarget)
*ppv = this;
else{
*ppv = NULL;
}
if (*ppv != NULL){
((LPUNKNOWN)(*ppv))->AddRef();
return NOERROR;
}
//If for some reason our constructor did not create the requested interface
//don't pass the NULL interface without telling the caller that we don't support
//the requested interface.
return ResultFromScode(E_NOINTERFACE);
}
//A private AddRef for IDropTarget
//
STDMETHODIMP_(ULONG) nsDropTarget::AddRef(void)
{
printf("nsDropTarget::AddRef\n");
return ++m_refs;
}
//A private Release for IDropTarget
//
STDMETHODIMP_(ULONG) nsDropTarget::Release(void)
{
printf("nsDropTarget::Release\n");
if(--m_refs == 0){
//And now we can delete this object
delete this;
}
return m_refs;
}
//
//This helper function tells us what the drag/drop effect would be at
//the point pointl. Since our object accepts being a drop target anywhere
//in the window, we will ignore pointl
//
DWORD nsDropTarget::FindDragDropEffect(DWORD grfKeyState, POINTL /* pointl */)
{
printf("nsDropTarget::FindDragDropEffect\n");
DWORD dwRet;
// no modifier -- DROPEFFECT_MOVE or source default
// SHIFT -- DROPEFFECT_MOVE
// CTRL -- DROPEFFECT_COPY
// CTRL-SHIFT -- DROPEFFECT_LINK
dwRet = 0;//OleStdGetDropEffect(grfKeyState);
if (dwRet == 0)
dwRet = DROPEFFECT_COPY;
return dwRet;
}
//Notification that a DropSource is over the current DropTarget
//
STDMETHODIMP nsDropTarget::DragEnter (LPDATAOBJECT pDataObj,
DWORD grfKeyState,
POINTL pointl,
LPDWORD pdwEffect)
{
printf("nsDropTarget::DragEnter\n");
*pdwEffect = FindDragDropEffect(grfKeyState, pointl);
return NOERROR;
}
//Provides user feedback when a DropSource is over a DropTarget
//
STDMETHODIMP nsDropTarget::DragOver (DWORD grfKeyState,
POINTL pointl,
LPDWORD pdwEffect)
{
printf("nsDropTarget::DragOver\n");
*pdwEffect = FindDragDropEffect(grfKeyState, pointl);
return NOERROR;
}
//The DropSource is leaving our target window
//so its cleanup time!!!
//
STDMETHODIMP nsDropTarget::DragLeave (void)
{
printf("nsDropTarget::DragLeave\n");
return NOERROR;
}
//Drops the DropSource
//
STDMETHODIMP nsDropTarget::Drop (LPDATAOBJECT pIDataObject,
DWORD grfKeyState,
POINTL pointl,
LPDWORD pdwEffect)
{
printf("nsDropTarget::Drop\n");
printf("pIDataObject 0x%x\n", pIDataObject);
pIDataObject->AddRef();
if (nsnull != m_pWin) {
nsEventStatus status;
nsDragDropEvent event;
((nsWindow *)m_pWin)->InitEvent(event, NS_DRAGDROP_EVENT);
event.mType = nsDragDropEventStatus_eDrop;
event.mIsFileURL = PR_FALSE;
event.mURL = nsnull;
m_pWin->DispatchEvent(&event, status);
}
//pdwEffect = FindDragDropEffect(grfKeyState, pointl);
if (pIDataObject != NULL) {
IDataObject * presistStorage;
//printf("QueryInterface for persist\n");
pIDataObject->QueryInterface(IID_IDataObject,(LPVOID *)&presistStorage);
//printf("Done QueryInterface for persist\n");
if (presistStorage != NULL) {
printf("$$$$$$$$$$$$$$$ Got it!\n");
FORMATETC pFE;
presistStorage->QueryGetData(&pFE);
pFE.tymed = TYMED_FILE;
STGMEDIUM pSTM;
HRESULT st = presistStorage->GetDataHere(&pFE, &pSTM);
printf("st 0x%X\n", st);
if (NOERROR != st) {
return FALSE;
}
//TYMED_STORAGE, TYMED_STREAM, TYMED_HGLOBAL, or TYMED_FILE
//printf("%s\n", pSTM.lpszFileName);
{
//HRESULT hr = pIDataObject->GetData(&pFE, &pSTM);
//printf("hr 0x%X\n", hr);
//if (NOERROR != hr) {
// return FALSE;
//}
const CLIPFORMAT format = pFE.cfFormat;
switch(format) {
case CF_BITMAP:
//hr = SetBitmap(*pFE, stm);
break;
case CF_DIB:
//hr = SetDib(*pFE, stm);
break;
case CF_TEXT:
//hr = SetText(*pFE, stm);
break;
case CF_METAFILEPICT:
//hr = SetMetafilePict(*pFE, stm);
break;
default:
//if (format == GetRcfFormat()) {
// hr = SetRcf(*pFE, stm);
//}
break;
}
//return (SUCCEEDED(hr));
}
} else {
printf("^^^^^^^^^^^^^^^^^ Didn't!\n");
}
}
/* if (m_pContainDoc->m_pOleSiteObject)
delete m_pContainDoc->m_pOleSiteObject;
m_pContainDoc->m_pOleSiteObject = new COleSiteObject(m_pContainDoc);
FORMATETC fmtetc;
fmtetc.cfFormat = NULL;
fmtetc.ptd = NULL;
fmtetc.lindex = -1;
fmtetc.dwAspect = DVASPECT_CONTENT;
fmtetc.tymed = TYMED_NULL;
m_pContainDoc->m_pOleSiteObject->AddSiteFromData(m_pContainDoc,
pIDataObject,
&fmtetc);
*/
pIDataObject->Release();
DragLeave();
return NOERROR;
}

View File

@ -1,39 +0,0 @@
//IDropTarget.h
#ifndef __IDROPTARGET_H__
#define __IDROPTARGET_H__
#include "OLEIDL.H"
//forward declaration
//CLASS CContainDoc;
class nsIWidget;
class nsDropTarget : public IDropTarget
{
public:
STDMETHODIMP QueryInterface (REFIID riid, LPVOID FAR* ppv);
STDMETHODIMP_(ULONG) AddRef (void);
STDMETHODIMP_(ULONG) Release (void);
STDMETHODIMP DragEnter (LPDATAOBJECT pDataObj, DWORD grfKeyState,POINTL pt, LPDWORD pdwEffect);
STDMETHODIMP DragOver (DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
STDMETHODIMP DragLeave ();
STDMETHODIMP Drop (LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt,LPDWORD pdwEffect);
nsDropTarget(nsIWidget * aWindow);
~nsDropTarget();
protected:
USHORT nsDropTarget::GetFormats(DWORD direction, USHORT maxFormats, FORMATETC* formats);
private:
nsIWidget * m_pWin;
long m_refs;
DWORD FindDragDropEffect(DWORD grfKeyState, POINTL pointl);
};
#endif

View File

@ -20,7 +20,6 @@
#include "nsNativeDragSource.h"
#include <stdio.h>
#include "nsIDragSource.h"
/*
* class nsNativeDragSource
@ -70,18 +69,18 @@ STDMETHODIMP_(ULONG) nsNativeDragSource::Release(void)
STDMETHODIMP nsNativeDragSource::QueryContinueDrag(BOOL fEsc, DWORD grfKeyState)
{
printf("QueryContinueDrag\n");
//printf("QueryContinueDrag\n");
if (fEsc) {
//printf("QueryContinueDrag: fEsc\n");
return ResultFromScode(DRAGDROP_S_CANCEL);
}
if (!(grfKeyState & MK_LBUTTON)) {
printf("QueryContinueDrag: grfKeyState & MK_LBUTTON\n");
//printf("QueryContinueDrag: grfKeyState & MK_LBUTTON\n");
return ResultFromScode(DRAGDROP_S_DROP);
}
printf("QueryContinueDrag: NOERROR\n");
//printf("QueryContinueDrag: NOERROR\n");
return NOERROR;
}

View File

@ -22,46 +22,56 @@
#include "nsIDragService.h"
#include "nsWidgetsCID.h"
#include "nsNativeDragTarget.h"
#include "nsDragService.h"
#include "nsIServiceManager.h"
#include "nsIWidget.h"
#include "nsWindow.h"
#define DRAG_DEBUG 0
/* Define Class IDs */
static NS_DEFINE_IID(kDragServiceCID, NS_DRAGSERVICE_CID);
static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID);
/* Define Interface IDs */
static NS_DEFINE_IID(kIDragServiceIID, NS_IDRAGSERVICE_IID);
// This is cached for Leave notification
static POINTL gDragLastPoint;
/*
* class nsNativeDragTarget
*/
// construction, destruction
//-----------------------------------------------------
// construction
//-----------------------------------------------------
nsNativeDragTarget::nsNativeDragTarget(nsIWidget * aWnd)
{
m_cRef = 0;
mWindow = aWnd;
NS_ADDREF(mWindow);
mHWnd = (HWND)mWindow->GetNativeData(NS_NATIVE_WINDOW);
/*
* Get the DragService
*/
nsresult rv = nsServiceManager::GetService(kDragServiceCID,
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
kIDragServiceIID,
(nsISupports**)&mDragService);
}
//-----------------------------------------------------
// destruction
//-----------------------------------------------------
nsNativeDragTarget::~nsNativeDragTarget()
{
NS_IF_RELEASE(mWindow);
}
//-----------------------------------------------------
// IUnknown methods - see iunknown.h for documentation
//-----------------------------------------------------
STDMETHODIMP nsNativeDragTarget::QueryInterface(REFIID riid, void** ppv)
{
*ppv=NULL;
@ -78,11 +88,13 @@ STDMETHODIMP nsNativeDragTarget::QueryInterface(REFIID riid, void** ppv)
}
//-----------------------------------------------------
STDMETHODIMP_(ULONG) nsNativeDragTarget::AddRef(void)
{
return ++m_cRef;
}
//-----------------------------------------------------
STDMETHODIMP_(ULONG) nsNativeDragTarget::Release(void)
{
if (0 != --m_cRef)
@ -92,22 +104,54 @@ STDMETHODIMP_(ULONG) nsNativeDragTarget::Release(void)
return 0;
}
void nsNativeDragTarget::DispatchDragDropEvent(PRUint32 aEventType)
//-----------------------------------------------------
void nsNativeDragTarget::DispatchDragDropEvent(PRUint32 aEventType,
POINTL aPT)
{
nsEventStatus status;
nsGUIEvent event;
((nsWindow *)mWindow)->InitEvent(event, aEventType);
//DWORD pos = ::GetMessagePos();
POINT cpos;
cpos.x = aPT.x;
cpos.y = aPT.y;
//cpos.x = LOWORD(pos);
//cpos.y = HIWORD(pos);
if (mHWnd != NULL) {
::ScreenToClient(mHWnd, &cpos);
event.point.x = cpos.x;
event.point.y = cpos.y;
} else {
event.point.x = 0;
event.point.y = 0;
}
//event.point.x = aPT.x;
//event.point.y = aPT.y;
mWindow->DispatchEvent(&event, status);
}
//-----------------------------------------------------
// IDropTarget methods
STDMETHODIMP nsNativeDragTarget::DragEnter(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
POINTL pt, DWORD* pdwEffect)
//-----------------------------------------------------
STDMETHODIMP nsNativeDragTarget::DragEnter(LPDATAOBJECT pIDataSource,
DWORD grfKeyState,
POINTL pt,
DWORD* pdwEffect)
{
printf("DragEnter\n");
if (DRAG_DEBUG) printf("DragEnter\n");
if (mDragService) {
DispatchDragDropEvent(NS_DRAGDROP_ENTER);
DispatchDragDropEvent(NS_DRAGDROP_ENTER, pt);
PRBool canDrop;
mDragService->GetCanDrop(&canDrop);
if (!canDrop) {
*pdwEffect = DROPEFFECT_NONE;
}
mDragService->SetCanDrop(PR_FALSE);
return NOERROR;
} else {
return ResultFromScode(E_FAIL);
@ -115,22 +159,33 @@ STDMETHODIMP nsNativeDragTarget::DragEnter(LPDATAOBJECT pIDataSource, DWORD grfK
}
STDMETHODIMP nsNativeDragTarget::DragOver(DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
//-----------------------------------------------------
STDMETHODIMP nsNativeDragTarget::DragOver(DWORD grfKeyState,
POINTL pt,
LPDWORD pdwEffect)
{
printf("DragOver\n");
if (DRAG_DEBUG) printf("DragOver\n");
if (mDragService) {
DispatchDragDropEvent(NS_DRAGDROP_OVER);
DispatchDragDropEvent(NS_DRAGDROP_OVER, pt);
gDragLastPoint = pt;
PRBool canDrop;
mDragService->GetCanDrop(&canDrop);
printf("Can Drop %d\n", canDrop);
if (!canDrop) {
*pdwEffect = DROPEFFECT_NONE;
}
mDragService->SetCanDrop(PR_FALSE);
return NOERROR;
} else {
return ResultFromScode(E_FAIL);
}
}
//-----------------------------------------------------
STDMETHODIMP nsNativeDragTarget::DragLeave() {
printf("DragLeave\n");
if (DRAG_DEBUG) printf("DragLeave\n");
if (mDragService) {
DispatchDragDropEvent(NS_DRAGDROP_EXIT);
DispatchDragDropEvent(NS_DRAGDROP_EXIT, gDragLastPoint);
return NOERROR;
} else {
return ResultFromScode(E_FAIL);
@ -138,18 +193,30 @@ STDMETHODIMP nsNativeDragTarget::DragLeave() {
}
STDMETHODIMP nsNativeDragTarget::Drop(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
POINTL pt, LPDWORD pdwEffect)
//-----------------------------------------------------
STDMETHODIMP nsNativeDragTarget::Drop(LPDATAOBJECT pIDataSource,
DWORD grfKeyState,
POINTL aPT,
LPDWORD pdwEffect)
{
printf("Drop\n");
if (DRAG_DEBUG) printf("Drop\n");
if (mDragService) {
// Clear the native clipboard
::OleFlushClipboard();
//::OleFlushClipboard();
::OleSetClipboard(pIDataSource);
//::OleSetClipboard(pIDataSource);
nsDragService * dragService = (nsDragService *)mDragService;
dragService->SetIDataObject(pIDataSource);
DispatchDragDropEvent(NS_DRAGDROP_DROP);
DispatchDragDropEvent(NS_DRAGDROP_DROP, aPT);
PRBool canDrop;
mDragService->GetCanDrop(&canDrop);
if (!canDrop) {
*pdwEffect = DROPEFFECT_NONE;
}
mDragService->SetCanDrop(PR_FALSE);
return NOERROR;
} else {
return ResultFromScode(E_FAIL);

View File

@ -69,11 +69,12 @@ class nsNativeDragTarget : public IDropTarget
POINTL point, DWORD* pEffect);
protected:
void DispatchDragDropEvent(PRUint32 aType);
void DispatchDragDropEvent(PRUint32 aType, POINTL pt);
ULONG m_cRef; // reference count
nsIDragService* mDragService; // adapter
nsIWidget * mWindow;
HWND mHWnd;
};
#endif // _nsNativeDragTarget_h_

View File

@ -22,7 +22,9 @@ LIBRARY_NAME = raptorbasewidget_s
REQUIRES=xpcom gfxwin raptor dom js network netlib
DEFINES =-D_IMPL_NS_WIDGET
CPPSRCS =nsBaseWidget.cpp \
CPPSRCS = \
nsBaseDragService.cpp \
nsBaseWidget.cpp \
nsMenuButton.cpp \
nsImageButton.cpp \
nsBaseClipboard.cpp \
@ -33,7 +35,9 @@ CPPSRCS =nsBaseWidget.cpp \
MODULE=raptor
OBJS=.\$(OBJDIR)\nsBaseWidget.obj \
OBJS= \
.\$(OBJDIR)\nsBaseDragService.obj \
.\$(OBJDIR)\nsBaseWidget.obj \
.\$(OBJDIR)\nsMenuButton.obj \
.\$(OBJDIR)\nsImageButton.obj \
.\$(OBJDIR)\nsBaseClipboard.obj \

View File

@ -123,12 +123,12 @@ NS_IMETHODIMP nsBaseClipboard::SetData(nsITransferable * aTransferable, nsIClipb
NS_IMETHODIMP nsBaseClipboard::GetData(nsITransferable * aTransferable)
{
if (nsnull != aTransferable) {
GetNativeClipboardData(aTransferable);
return GetNativeClipboardData(aTransferable);
} else {
printf(" nsBaseClipboard::GetData(), aTransferable is NULL.\n");
}
return NS_OK;
return NS_ERROR_FAILURE;
}

View File

@ -28,6 +28,7 @@
static NS_DEFINE_IID(kITransferableIID, NS_ITRANSFERABLE_IID);
static NS_DEFINE_IID(kIGenericTransferableIID, NS_IGENERICTRANSFERABLE_IID);
static NS_DEFINE_IID(kIDataFlavorIID, NS_IDATAFLAVOR_IID);
static NS_DEFINE_IID(kCDataFlavorCID, NS_DATAFLAVOR_CID);
@ -37,7 +38,7 @@ NS_IMPL_RELEASE(nsTransferable)
typedef struct {
nsIDataFlavor * mFlavor;
void * mData;
char * mData;
PRUint32 mDataLen;
} DataStruct;
@ -91,6 +92,12 @@ nsresult nsTransferable::QueryInterface(const nsIID& aIID, void** aInstancePtr)
return NS_OK;
}
if (aIID.Equals(kIGenericTransferableIID)) {
*aInstancePtr = (void*) ((nsIGenericTransferable*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return rv;
}
@ -190,7 +197,7 @@ NS_IMETHODIMP nsTransferable::SetTransferData(nsIDataFlavor * aDataFlavor, void
if (nsnull != data->mData) {
delete[] data->mData;
}
data->mData = aData;
data->mData = (char *)aData;
data->mDataLen = aDataLen;
return NS_OK;
}

View File

@ -21,6 +21,7 @@
#include "nsIFormatConverter.h"
#include "nsITransferable.h"
#include "nsIGenericTransferable.h"
#include "nsCOMPtr.h"
@ -34,7 +35,7 @@ class nsVoidArray;
* XP Transferable wrapper
*/
class nsTransferable : public nsITransferable
class nsTransferable : public nsITransferable, public nsIGenericTransferable
{
public:
@ -44,19 +45,23 @@ public:
//nsISupports
NS_DECL_ISUPPORTS
//nsITransferable
NS_IMETHOD FlavorsTransferableCanImport ( nsISupportsArray** outFlavorList ) ;
NS_IMETHOD FlavorsTransferableCanExport ( nsISupportsArray** outFlavorList ) ;
NS_IMETHOD GetTransferDataFlavors(nsISupportsArray ** aDataFlavorList);
NS_IMETHOD IsDataFlavorSupported(nsIDataFlavor * aFlavor);
// Transferable still owns |aData|. Do not delete it.
NS_IMETHOD GetTransferData(nsIDataFlavor * aFlavor, void ** aData, PRUint32 * aDataLen);
NS_IMETHOD_(PRBool) IsLargeDataSet();
//nsIGenericTransferable
NS_IMETHOD FlavorsTransferableCanImport ( nsISupportsArray** outFlavorList ) ;
// Transferable consumes |aData|. Do not delete it.
NS_IMETHOD SetTransferData(nsIDataFlavor * aFlavor, void * aData, PRUint32 aDataLen);
NS_IMETHOD AddDataFlavor(nsIDataFlavor * aDataFlavor);
NS_IMETHOD_(PRBool) IsLargeDataSet();
NS_IMETHOD SetConverter(nsIFormatConverter * aConverter);
NS_IMETHOD GetConverter(nsIFormatConverter ** aConverter);