From ee25e1ce6d6b3b14b53694e470bfee34fda5bc7f Mon Sep 17 00:00:00 2001 From: "akkana%netscape.com" Date: Fri, 26 Feb 1999 19:01:15 +0000 Subject: [PATCH] Turn on nsSelectionMgr for windows git-svn-id: svn://10.0.0.236/trunk@22181 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/windows/makefile.win | 2 + mozilla/widget/src/windows/nsAppShell.cpp | 18 +++ mozilla/widget/src/windows/nsAppShell.h | 2 + mozilla/widget/src/windows/nsSelectionMgr.cpp | 111 +++++++++++++++--- mozilla/widget/src/windows/nsSelectionMgr.h | 4 +- 5 files changed, 116 insertions(+), 21 deletions(-) diff --git a/mozilla/widget/src/windows/makefile.win b/mozilla/widget/src/windows/makefile.win index 83d9e3a6c5f..fdbe93ecbdf 100644 --- a/mozilla/widget/src/windows/makefile.win +++ b/mozilla/widget/src/windows/makefile.win @@ -46,6 +46,7 @@ CPPSRCS = \ nsDialog.cpp \ nsLabel.cpp \ nsToolkit.cpp \ + nsSelectionMgr.cpp \ $(NULL) MODULE=raptor @@ -74,6 +75,7 @@ OBJS = \ .\$(OBJDIR)\nsDialog.obj \ .\$(OBJDIR)\nsLabel.obj \ .\$(OBJDIR)\nsToolkit.obj \ + .\$(OBJDIR)\nsSelectionMgr.obj \ $(NULL) LINCS= \ diff --git a/mozilla/widget/src/windows/nsAppShell.cpp b/mozilla/widget/src/windows/nsAppShell.cpp index b59ef4f7ca8..b448fe6729a 100644 --- a/mozilla/widget/src/windows/nsAppShell.cpp +++ b/mozilla/widget/src/windows/nsAppShell.cpp @@ -18,6 +18,7 @@ #include "nsAppShell.h" #include "nsIWidget.h" +#include "nsSelectionMgr.h" #include NS_IMPL_ISUPPORTS(nsAppShell, NS_IAPPSHELL_IID) @@ -31,6 +32,7 @@ nsAppShell::nsAppShell() { NS_INIT_REFCNT(); mDispatchListener = 0; + mSelectionMgr = 0; } @@ -43,6 +45,10 @@ nsAppShell::nsAppShell() NS_METHOD nsAppShell::Create(int* argc, char ** argv) { + // Create the selection manager + if (!mSelectionMgr) + NS_NewSelectionMgr(&mSelectionMgr); + return NS_OK; } @@ -167,6 +173,7 @@ NS_METHOD nsAppShell::Exit() //------------------------------------------------------------------------- nsAppShell::~nsAppShell() { + NS_IF_RELEASE(mSelectionMgr); } //------------------------------------------------------------------------- @@ -181,3 +188,14 @@ void* nsAppShell::GetNativeData(PRUint32 aDataType) } return nsnull; } + +NS_METHOD +nsAppShell::GetSelectionMgr(nsISelectionMgr** aSelectionMgr) +{ + *aSelectionMgr = mSelectionMgr; + NS_IF_ADDREF(mSelectionMgr); + if (!mSelectionMgr) + return NS_ERROR_NOT_INITIALIZED; + return NS_OK; +} + diff --git a/mozilla/widget/src/windows/nsAppShell.h b/mozilla/widget/src/windows/nsAppShell.h index b92855caf64..54c8c81d8fc 100644 --- a/mozilla/widget/src/windows/nsAppShell.h +++ b/mozilla/widget/src/windows/nsAppShell.h @@ -43,6 +43,7 @@ class nsAppShell : public nsIAppShell NS_IMETHOD SetDispatchListener(nsDispatchListener* aDispatchListener); NS_IMETHOD Exit(); virtual void* GetNativeData(PRUint32 aDataType); + NS_IMETHOD GetSelectionMgr(nsISelectionMgr** aSelectionMgr); // XXX temporary for Dialog investigation NS_IMETHOD GetNativeEvent(void *& aEvent, nsIWidget* aWidget, PRBool &aIsInWindow, PRBool &aIsMouseEvent); @@ -51,6 +52,7 @@ class nsAppShell : public nsIAppShell private: nsDispatchListener* mDispatchListener; + nsISelectionMgr *mSelectionMgr; }; #endif // nsAppShell_h__ diff --git a/mozilla/widget/src/windows/nsSelectionMgr.cpp b/mozilla/widget/src/windows/nsSelectionMgr.cpp index feb1848455c..525436747d9 100644 --- a/mozilla/widget/src/windows/nsSelectionMgr.cpp +++ b/mozilla/widget/src/windows/nsSelectionMgr.cpp @@ -26,23 +26,8 @@ * Owns the copied text, listens for selection request events. */ -class nsSelectionMgr : nsISelectionMgr -{ -public: - virtual void CopyToClipboard(); - - virtual ostream& GetCopyOStream(); - - virtual void HandlePasteRequest(); - - virtual nsEventStatus ProcessEvent(const nsGUIEvent & anEvent) = 0; - -private: - ostream* mCopyStream; -} - -NS_IMPL_ADDREF(nsDialog) -NS_IMPL_RELEASE(nsDialog) +NS_IMPL_ADDREF(nsSelectionMgr) +NS_IMPL_RELEASE(nsSelectionMgr) nsSelectionMgr::nsSelectionMgr() { @@ -55,20 +40,108 @@ nsSelectionMgr::~nsSelectionMgr() { } +nsresult nsSelectionMgr::QueryInterface(const nsIID& aIID, + void** aInstancePtrResult) +{ + NS_PRECONDITION(aInstancePtrResult, "null pointer"); + if (!aInstancePtrResult) + { + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(nsISupports::IID())) + { + *aInstancePtrResult = (void*)(nsISupports*)this; + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(nsISelectionMgr::IID())) + { + *aInstancePtrResult = (void*)(nsISelectionMgr*)this; + NS_ADDREF_THIS(); + return NS_OK; + } + return !NS_OK; +} + nsresult nsSelectionMgr::GetCopyOStream(ostream** aStream) { if (mCopyStream) delete mCopyStream; - mCopyStream = new ostringstream; + mCopyStream = new ostrstream; *aStream = mCopyStream; + return NS_OK; } -nsresult nsSelectionMgr::CopyToClipboard(ostream& str) + +static const char* gsAOLFormat = "AOLMAIL"; +static const char* gsHTMLFormat = "text/html"; + +static void PlaceHTMLOnClipboard(PRUint32 aFormat, char* aData, int aLength) +{ + HGLOBAL hGlobalMemory; + PSTR pGlobalMemory; + + PRUint32 cf_aol = RegisterClipboardFormat(gsAOLFormat); + PRUint32 cf_html = RegisterClipboardFormat(gsHTMLFormat); + + char* preamble = ""; + char* postamble = ""; + + if (aFormat == cf_aol || aFormat == CF_TEXT) + { + preamble = ""; + postamble = ""; + } + + PRInt32 size = aLength + 1 + strlen(preamble) + strlen(postamble); + + + if (aLength) + { + // Copy text to Global Memory Area + hGlobalMemory = (HGLOBAL)GlobalAlloc(GHND, size); + if (hGlobalMemory != NULL) + { + pGlobalMemory = (PSTR) GlobalLock(hGlobalMemory); + + int i; + + // AOL requires HTML prefix/postamble + char* s = preamble; + PRInt32 len = strlen(s); + for (i=0; i < len; i++) + { + *pGlobalMemory++ = *s++; + } + + s = aData; + len = aLength; + for (i=0;i< len;i++) { + *pGlobalMemory++ = *s++; + } + + + s = postamble; + len = strlen(s); + for (i=0; i < len; i++) + { + *pGlobalMemory++ = *s++; + } + + // Put data on Clipboard + GlobalUnlock(hGlobalMemory); + SetClipboardData(aFormat, hGlobalMemory); + } + } +} + +nsresult nsSelectionMgr::CopyToClipboard() { // we'd better already have a stream ... if (!mCopyStream) return NS_ERROR_NOT_INITIALIZED; + PRInt32 len = mCopyStream->pcount(); char* str = (char*)mCopyStream->str(); PRUint32 cf_aol = RegisterClipboardFormat(gsAOLFormat); diff --git a/mozilla/widget/src/windows/nsSelectionMgr.h b/mozilla/widget/src/windows/nsSelectionMgr.h index a40595003c0..61a6982302d 100644 --- a/mozilla/widget/src/windows/nsSelectionMgr.h +++ b/mozilla/widget/src/windows/nsSelectionMgr.h @@ -25,7 +25,7 @@ class ostrstream; * Owns the copied text, listens for selection request events. */ -class nsSelectionMgr : nsISelectionMgr +class nsSelectionMgr : public nsISelectionMgr { public: nsSelectionMgr(); @@ -39,7 +39,7 @@ public: private: ostrstream* mCopyStream; -} +}; nsresult NS_NewSelectionMgr(nsISelectionMgr** aInstancePtrResult);