new drag session interface and lots of work to get d&d going.

This commit is contained in:
pinkerton%netscape.com 1999-05-07 19:52:15 +00:00
parent dbebfd2a64
commit e8f6fb3878
2 changed files with 254 additions and 16 deletions

View File

@ -52,21 +52,23 @@
#include "nsDragService.h"
#include "nsITransferable.h"
#include "nsIDataFlavor.h"
#include "nsMimeMapper.h"
#include "nsWidgetsCID.h"
#include "nsClipboard.h"
#include "nsIRegion.h"
static NS_DEFINE_IID(kIDragServiceIID, NS_IDRAGSERVICE_IID);
NS_IMPL_ADDREF_INHERITED(nsDragService, nsBaseDragService)
@ -84,9 +86,9 @@ NS_IMPL_RELEASE_INHERITED(nsDragService, nsBaseDragService)
nsDragService::nsDragService()
{
: mDragRef(0)
NS_INIT_REFCNT();
{
}
@ -142,7 +144,7 @@ nsDragService::QueryInterface(const nsIID& aIID, void** aInstancePtr)
if (aIID.Equals(kIDragServiceIID)) {
if (aIID.Equals(nsIDragService::GetIID())) {
*aInstancePtr = (void*) ((nsIDragService*)this);
@ -174,13 +176,133 @@ nsDragService::QueryInterface(const nsIID& aIID, void** aInstancePtr)
NS_IMETHODIMP
nsDragService::StartDragSession (nsITransferable * aTransferable, PRUint32 aActionType)
nsDragService :: InvokeDragSession (nsISupportsArray * anArrayTransferables, nsIRegion * aDragRgn, PRUint32 aActionType)
{
return NS_ERROR_FAILURE;
//¥¥¥ what should we do about |mDragRef| from the previous drag?? Does anyone
//¥¥¥ outside of this method need it? Should it really be a member variable?
OSErr result = ::NewDrag(&mDragRef);
if ( !result )
return NS_ERROR_FAILURE;
//¥¥¥ add the flavors from the transferables
// create the drag region. Pull out the native mac region from the nsIRegion we're
// given, copy it, inset it one pixel, and subtract them so we're left with just an
// outline. Too bad we can't do this with gfx api's.
//
// At the end, we are left with an outline of the region in global coordinates.
RgnHandle dragRegion = nsnull;
aDragRgn->GetNativeRegion(dragRegion);
RgnHandle insetDragRegion = ::NewRgn();
if ( dragRegion && insetDragRegion ) {
::CopyRgn ( dragRegion, insetDragRegion );
::InsetRgn ( insetDragRegion, 1, 1 );
::DiffRgn ( dragRegion, insetDragRegion, insetDragRegion );
// now shift the region into global coordinates.
Point offsetFromLocalToGlobal = { 0, 0 };
::LocalToGlobal ( &offsetFromLocalToGlobal );
::OffsetRgn ( insetDragRegion, offsetFromLocalToGlobal.h, offsetFromLocalToGlobal.v );
}
//¥¥¥ register drag send procs
// we have to synthesize the native event because we may be called from JavaScript
// through XPConnect. In that case, we only have a DOM event and no way to
// get to the native event. As a consequence, we just always fake it.
Point globalMouseLoc;
::GetMouse(&globalMouseLoc);
::LocalToGlobal(&globalMouseLoc);
WindowPtr theWindow = nsnull;;
if ( ::FindWindow(globalMouseLoc, &theWindow) != inContent ) {
// debugging sanity check
#ifdef NS_DEBUG
DebugStr("\pAbout to start drag, but FindWindow() != inContent");
#endif
}
EventRecord theEvent;
theEvent.what = mouseDown;
theEvent.message = reinterpret_cast<UInt32>(theWindow);
theEvent.when = 0;
theEvent.where = globalMouseLoc;
theEvent.modifiers = 0;
// start the drag
result = ::TrackDrag ( mDragRef, &theEvent, insetDragRegion );
// clean up after ourselves
::DisposeRgn ( insetDragRegion );
::DisposeDrag ( mDragRef );
return NS_OK;
@ -188,3 +310,101 @@ nsDragService::StartDragSession (nsITransferable * aTransferable, PRUint32 aActi
//
// GetData
//
// Pull data out of the OS drag items and stash it into the given transferable
//
NS_IMETHODIMP
nsDragService :: GetData (nsITransferable * aTransferable)
{
printf("nsDragService::GetData -- unimplemented on MacOS\n");
return NS_ERROR_FAILURE;
}
//
// IsDataFlavorSupported
//
// Check the OS to see if the given drag flavor is in the list. Oddly returns
// NS_OK for success and NS_ERROR_FAILURE if flavor is not present.
//
NS_IMETHODIMP
nsDragService :: IsDataFlavorSupported(nsIDataFlavor * aDataFlavor)
{
nsresult flavorSupported = NS_ERROR_FAILURE;
// convert to 4 character MacOS type
nsAutoString mimeType;
aDataFlavor->GetMimeType(mimeType);
FlavorType macFlavor = nsMimeMapperMac::MapMimeTypeToMacOSType(mimeType);
// search through all drag items looking for something with this flavor
unsigned short numDragItems = 0;
::CountDragItems ( mDragRef, &numDragItems );
for ( int i = 0; i < numDragItems; ++i ) {
ItemReference currItem;
OSErr res = ::GetDragItemReferenceNumber ( mDragRef, i, &currItem );
if ( res != noErr )
return NS_ERROR_FAILURE;
FlavorFlags ignored;
char foundFlavor = ::GetFlavorFlags(mDragRef, currItem, macFlavor, &ignored) == noErr;
if ( foundFlavor )
flavorSupported = NS_OK;
} // for each item in drag
return flavorSupported;
} // IsDataFlavorSupported

View File

@ -58,6 +58,8 @@
#include "nsBaseDragService.h"
#include <Drag.h>
class nsNativeDragTarget;
@ -68,7 +70,7 @@ class nsNativeDragTarget;
//
// Native MAC DragService wrapper
// Native MacOS DragService/DragSession implementation
//
@ -76,8 +78,6 @@ class nsDragService : public nsBaseDragService
{
public:
nsDragService();
@ -92,17 +92,35 @@ public:
//nsIDragService
NS_IMETHOD StartDragSession (nsITransferable * aTransferable, PRUint32 aActionType);
NS_IMETHOD InvokeDragSession (nsISupportsArray * anArrayTransferables, nsIRegion * aRegion, PRUint32 aActionType);
//NS_IMETHOD InvokeDragSessionSingle (nsITransferable * aTransferable, nsIRegion * aRegion, PRUint32 aActionType);
//nsIDragSession
NS_IMETHOD GetData (nsITransferable * aTransferable);
NS_IMETHOD IsDataFlavorSupported(nsIDataFlavor * aDataFlavor);
private:
DragReference mDragRef; // reference to _the_ drag. There can be only one.
}; // class nsDragService
#endif // nsDragService_h__