From 4d8da33c9c123fb5df3845e3131e3a7a7138e85c Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Thu, 26 Aug 1999 14:41:17 +0000 Subject: [PATCH] Changed EnableDropFile to EnableDragDrop. D&D is now NOT automatically registered for all windows during creation and initialization. The method EnableDragDrop is not used to "turn it on". The method nsIView::CreateView has parameter that indicates whether it should be turned on or not This make it configurable from the outside, it is needed for the editor --- widget/public/nsIWidget.h | 2 +- widget/src/windows/nsWindow.cpp | 46 ++++++++++++++++----------- widget/src/windows/nsWindow.h | 2 +- widget/src/xpwidgets/nsBaseWidget.cpp | 4 +-- widget/src/xpwidgets/nsBaseWidget.h | 2 +- 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/widget/public/nsIWidget.h b/widget/public/nsIWidget.h index df4619df36ea..fafc3313bc2b 100644 --- a/widget/public/nsIWidget.h +++ b/widget/public/nsIWidget.h @@ -650,7 +650,7 @@ class nsIWidget : public nsISupports { * Enables the dropping of files to a widget (XXX this is temporary) * */ - NS_IMETHOD EnableFileDrop(PRBool aEnable) = 0; + NS_IMETHOD EnableDragDrop(PRBool aEnable) = 0; virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) = 0; diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 126e3b68c0b4..f98c3ce52cc9 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -619,14 +619,14 @@ nsresult nsWindow::StandardWindowCreate(nsIWidget *aParent, gOLEInited = TRUE; } - mNativeDragTarget = new nsNativeDragTarget(this); + /*mNativeDragTarget = new nsNativeDragTarget(this); if (NULL != mNativeDragTarget) { mNativeDragTarget->AddRef(); if (S_OK == ::CoLockObjectExternal((LPUNKNOWN)mNativeDragTarget,TRUE,FALSE)) { if (S_OK == ::RegisterDragDrop(mWnd, (LPDROPTARGET)mNativeDragTarget)) { } } - } + }*/ // call the event callback to notify about creation @@ -696,11 +696,7 @@ NS_METHOD nsWindow::Destroy() nsBaseWidget::Destroy(); } - if (NULL != mNativeDragTarget) { - if (S_OK == ::CoLockObjectExternal((LPUNKNOWN)mNativeDragTarget, FALSE, TRUE)) { - } - NS_RELEASE(mNativeDragTarget); - } + EnableDragDrop(PR_FALSE); // destroy the HWND if (mWnd) { @@ -1811,19 +1807,33 @@ nsresult nsWindow::MenuHasBeenSelected( return NS_OK; } //--------------------------------------------------------- -NS_METHOD nsWindow::EnableFileDrop(PRBool aEnable) +NS_METHOD nsWindow::EnableDragDrop(PRBool aEnable) { - //::DragAcceptFiles(mWnd, (aEnable?TRUE:FALSE)); - mNativeDragTarget = new nsNativeDragTarget(this); - if (NULL != mNativeDragTarget) { - mNativeDragTarget->AddRef(); - if (S_OK == ::CoLockObjectExternal((LPUNKNOWN)mNativeDragTarget,TRUE,FALSE)) { - if (S_OK == ::RegisterDragDrop(mWnd, (LPDROPTARGET)mNativeDragTarget)) { - } - } - } + nsresult rv = NS_ERROR_FAILURE; - return NS_OK; + if (aEnable) { + if (nsnull == mNativeDragTarget) { + mNativeDragTarget = new nsNativeDragTarget(this); + if (NULL != mNativeDragTarget) { + mNativeDragTarget->AddRef(); + if (S_OK == ::CoLockObjectExternal((LPUNKNOWN)mNativeDragTarget,TRUE,FALSE)) { + if (S_OK == ::RegisterDragDrop(mWnd, (LPDROPTARGET)mNativeDragTarget)) { + rv = NS_OK; + } + } + } + } + } else { + if (nsnull != mWnd && NULL != mNativeDragTarget) { + ::RevokeDragDrop(mWnd); + if (S_OK == ::CoLockObjectExternal((LPUNKNOWN)mNativeDragTarget, FALSE, TRUE)) { + rv = NS_OK; + } + NS_RELEASE(mNativeDragTarget); + } + } + + return rv; } diff --git a/widget/src/windows/nsWindow.h b/widget/src/windows/nsWindow.h index 1e0fccdcc0ca..072d13989ff2 100644 --- a/widget/src/windows/nsWindow.h +++ b/widget/src/windows/nsWindow.h @@ -121,7 +121,7 @@ public: NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight); NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight); NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus); - NS_IMETHOD EnableFileDrop(PRBool aEnable); + NS_IMETHOD EnableDragDrop(PRBool aEnable); virtual void SetUpForPaint(HDC aHDC); virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {} diff --git a/widget/src/xpwidgets/nsBaseWidget.cpp b/widget/src/xpwidgets/nsBaseWidget.cpp index 8a3a0a12e7d4..2bde56de58d2 100644 --- a/widget/src/xpwidgets/nsBaseWidget.cpp +++ b/widget/src/xpwidgets/nsBaseWidget.cpp @@ -425,7 +425,7 @@ void nsBaseWidget::OnDestroy() //------------------------------------------------------------------------- nsBaseWidget::Enumerator::Enumerator(nsBaseWidget & inParent) - : mParent(inParent), mCurrentPosition(0) + : mCurrentPosition(0), mParent(inParent) { NS_INIT_REFCNT(); } @@ -761,7 +761,7 @@ NS_METHOD nsBaseWidget::SetVerticalScrollbar(nsIWidget * aWidget) return NS_OK; } -NS_METHOD nsBaseWidget::EnableFileDrop(PRBool aEnable) +NS_METHOD nsBaseWidget::EnableDragDrop(PRBool aEnable) { return NS_OK; } diff --git a/widget/src/xpwidgets/nsBaseWidget.h b/widget/src/xpwidgets/nsBaseWidget.h index 61c635f32933..49b744e4f0ef 100644 --- a/widget/src/xpwidgets/nsBaseWidget.h +++ b/widget/src/xpwidgets/nsBaseWidget.h @@ -89,7 +89,7 @@ public: NS_IMETHOD GetBorderSize(PRInt32 &aWidth, PRInt32 &aHeight); NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect); NS_IMETHOD SetVerticalScrollbar(nsIWidget * aScrollbar); - NS_IMETHOD EnableFileDrop(PRBool aEnable); + NS_IMETHOD EnableDragDrop(PRBool aEnable); virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {} virtual void FreeNativeData(void * data, PRUint32 aDataType) {}//~~~ protected: