gecko-dev/widget/src/windows/nsDragService.cpp

146 lines
4.1 KiB
C++
Raw Normal View History

1999-03-23 15:37:34 +00:00
/* -*- 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 "nsDragService.h"
#include "nsITransferable.h"
#include "nsDataObj.h"
1999-04-06 20:25:09 +00:00
#include "nsWidgetsCID.h"
#include "nsNativeDragTarget.h"
#include "nsNativeDragSource.h"
1999-04-06 20:25:09 +00:00
#include "nsClipboard.h"
1999-03-23 15:37:34 +00:00
#include <OLE2.h>
#include "OLEIDL.H"
1999-03-23 15:37:34 +00:00
static NS_DEFINE_IID(kIDragServiceIID, NS_IDRAGSERVICE_IID);
//static NS_DEFINE_IID(kIClipboardIID, NS_ICLIPBOARD_IID);
//static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
1999-03-23 15:37:34 +00:00
NS_IMPL_ADDREF_INHERITED(nsDragService, nsBaseDragService)
NS_IMPL_RELEASE_INHERITED(nsDragService, nsBaseDragService)
1999-03-23 15:37:34 +00:00
//-------------------------------------------------------------------------
//
// DragService constructor
//
//-------------------------------------------------------------------------
nsDragService::nsDragService()
{
NS_INIT_REFCNT();
mNativeDragTarget = nsnull;
mNativeDragSrc = nsnull;
mDataObject = nsnull;
1999-03-23 15:37:34 +00:00
}
//-------------------------------------------------------------------------
//
// DragService destructor
//
//-------------------------------------------------------------------------
nsDragService::~nsDragService()
{
NS_IF_RELEASE(mNativeDragSrc);
NS_IF_RELEASE(mNativeDragTarget);
NS_IF_RELEASE(mDataObject);
1999-03-23 15:37:34 +00:00
}
/**
* @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 nsDragService::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
nsresult rv = NS_NOINTERFACE;
if (aIID.Equals(kIDragServiceIID)) {
*aInstancePtr = (void*) ((nsIDragService*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return rv;
}
//---------------------------------------------------------
NS_IMETHODIMP nsDragService::StartDragSession (nsITransferable * aTransferable, PRUint32 aActionType)
1999-03-23 15:37:34 +00:00
{
// 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
1999-03-23 15:37:34 +00:00
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)
1999-03-23 15:37:34 +00:00
{
if (nsnull != mDataObject) {
return nsClipboard::GetDataFromDataObject(mDataObject, nsnull, aTransferable);
1999-04-06 20:25:09 +00:00
}
return NS_ERROR_FAILURE;
1999-03-23 15:37:34 +00:00
}
//---------------------------------------------------------
NS_IMETHODIMP nsDragService::SetIDataObject (IDataObject * aDataObj)
{
NS_IF_RELEASE(mDataObject);
mDataObject = aDataObj;
NS_ADDREF(mDataObject);
return NS_OK;
}