From a0beec3a1a278ba1bfa9bf72583e0390b2887929 Mon Sep 17 00:00:00 2001 From: "akkana%netscape.com" Date: Mon, 19 Jul 1999 19:37:08 +0000 Subject: [PATCH] Fix paste html; remove some unneeded inclusions --- editor/base/nsEditor.cpp | 33 ++++++--- editor/base/nsHTMLEditor.cpp | 97 +++++++++++++++++++++++++- editor/libeditor/base/nsEditor.cpp | 33 ++++++--- editor/libeditor/html/nsHTMLEditor.cpp | 97 +++++++++++++++++++++++++- 4 files changed, 236 insertions(+), 24 deletions(-) diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index 7b401f80bd3f..48c22b8bafc6 100644 --- a/editor/base/nsEditor.cpp +++ b/editor/base/nsEditor.cpp @@ -108,12 +108,10 @@ #include "nsWidgetsCID.h" #include "nsIClipboard.h" #include "nsITransferable.h" -#include "nsIFormatConverter.h" // Drag & Drop, Clipboard Support static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID); static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID); -static NS_DEFINE_IID(kCXIFFormatConverterCID, NS_XIFFORMATCONVERTER_CID); static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID); static NS_DEFINE_CID(kEditorCID, NS_EDITOR_CID); @@ -1298,9 +1296,11 @@ NS_IMETHODIMP nsEditor::Paste() rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, nsITransferable::GetIID(), (void**) getter_AddRefs(trans)); - if (NS_OK == rv) { + if (NS_SUCCEEDED(rv)) + { // Get the nsITransferable interface for getting the data from the clipboard - if (trans) { + if (trans) + { // Create the desired DataFlavor for the type of data we want to get out of the transferable nsAutoString htmlFlavor(kHTMLMime); nsAutoString textFlavor(kTextMime); @@ -1311,23 +1311,34 @@ NS_IMETHODIMP nsEditor::Paste() trans->AddDataFlavor(&imageFlavor); // Get the Data from the clipboard - if (NS_OK == clipboard->GetData(trans)) { + if (NS_SUCCEEDED(clipboard->GetData(trans))) + { nsAutoString flavor; char * data; PRUint32 len; - if (NS_OK == trans->GetAnyTransferData(&flavor, (void **)&data, &len)) { + if (NS_SUCCEEDED(trans->GetAnyTransferData(&flavor, (void **)&data, &len))) + { +#ifdef DEBUG printf("Got flavor [%s]\n", flavor.ToNewCString()); - if (flavor.Equals(htmlFlavor)) { - if (data && len > 0) { // stuffToPaste is ready for insertion into the content +#endif + if (flavor.Equals(htmlFlavor)) + { + if (data && len > 0) // stuffToPaste is ready for insertion into the content + { stuffToPaste.SetString(data, len); rv = InsertText(stuffToPaste); } - } else if (flavor.Equals(textFlavor)) { - if (data && len > 0) { // stuffToPaste is ready for insertion into the content + } + else if (flavor.Equals(textFlavor)) + { + if (data && len > 0) // stuffToPaste is ready for insertion into the content + { stuffToPaste.SetString(data, len); rv = InsertText(stuffToPaste); } - } else if (flavor.Equals(imageFlavor)) { + } + else if (flavor.Equals(imageFlavor)) + { image = (nsIImage *)data; // Insert Image code here NS_RELEASE(image); diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp index 3d5cc6d98f83..1463724c9585 100644 --- a/editor/base/nsHTMLEditor.cpp +++ b/editor/base/nsHTMLEditor.cpp @@ -48,6 +48,13 @@ #include "nsIPref.h" #include "nsIDOMDocumentFragment.h" #include "nsIPresShell.h" +#include "nsIImage.h" + +// Drag & Drop, Clipboard +#include "nsWidgetsCID.h" +#include "nsIClipboard.h" +#include "nsITransferable.h" + #include "prprf.h" const unsigned char nbsp = 160; @@ -63,6 +70,10 @@ static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID); static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID); static NS_DEFINE_IID(kFileWidgetCID, NS_FILEWIDGET_CID); +// Drag & Drop, Clipboard Support +static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID); +static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID); + #ifdef NS_DEBUG static PRBool gNoisy = PR_FALSE; #else @@ -445,7 +456,91 @@ NS_IMETHODIMP nsHTMLEditor::Copy() NS_IMETHODIMP nsHTMLEditor::Paste() { - return nsTextEditor::Paste(); +#ifdef DEBUG_akkana + printf("nsHTMLEditor::Paste()\n"); +#endif + +#ifdef ENABLE_JS_EDITOR_LOG + nsAutoJSEditorLogLock logLock(mJSEditorLog); + + if (mJSEditorLog) + mJSEditorLog->Paste(); +#endif // ENABLE_JS_EDITOR_LOG + + nsIImage * image = nsnull; + + nsString stuffToPaste; + + // Get Clipboard Service + nsIClipboard* clipboard; + nsresult rv = nsServiceManager::GetService(kCClipboardCID, + nsIClipboard::GetIID(), + (nsISupports **)&clipboard); + + // Create generic Transferable for getting the data + nsCOMPtr trans; + rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, + nsITransferable::GetIID(), + (void**) getter_AddRefs(trans)); + if (NS_SUCCEEDED(rv)) + { + // Get the nsITransferable interface for getting the data from the clipboard + if (trans) + { + // Create the desired DataFlavor for the type of data we want to get out of the transferable + nsAutoString htmlFlavor(kHTMLMime); + nsAutoString textFlavor(kTextMime); + nsAutoString imageFlavor(kJPEGImageMime); + + trans->AddDataFlavor(&htmlFlavor); + trans->AddDataFlavor(&textFlavor); + trans->AddDataFlavor(&imageFlavor); + + // Get the Data from the clipboard + if (NS_SUCCEEDED(clipboard->GetData(trans))) + { + nsAutoString flavor; + char * data; + PRUint32 len; + if (NS_SUCCEEDED(trans->GetAnyTransferData(&flavor, (void **)&data, &len))) + { +#ifdef DEBUG_akkana + printf("Got flavor [%s]\n", flavor.ToNewCString()); +#endif + if (flavor.Equals(htmlFlavor)) + { + if (data && len > 0) // stuffToPaste is ready for insertion into the content + { + stuffToPaste.SetString(data, len); + rv = InsertHTML(stuffToPaste); + } + } + else if (flavor.Equals(textFlavor)) + { + if (data && len > 0) // stuffToPaste is ready for insertion into the content + { + stuffToPaste.SetString(data, len); + rv = InsertText(stuffToPaste); + } + } + else if (flavor.Equals(imageFlavor)) + { + image = (nsIImage *)data; + // Insert Image code here + NS_RELEASE(image); + rv = NS_ERROR_FAILURE; // for now give error code + } + } + + } + } + } + nsServiceManager::ReleaseService(kCClipboardCID, clipboard); + + //printf("Trying to insert '%s'\n", stuffToPaste.ToNewCString()); + + // Now let InsertText handle the hard stuff: + return rv; } // diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 7b401f80bd3f..48c22b8bafc6 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -108,12 +108,10 @@ #include "nsWidgetsCID.h" #include "nsIClipboard.h" #include "nsITransferable.h" -#include "nsIFormatConverter.h" // Drag & Drop, Clipboard Support static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID); static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID); -static NS_DEFINE_IID(kCXIFFormatConverterCID, NS_XIFFORMATCONVERTER_CID); static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID); static NS_DEFINE_CID(kEditorCID, NS_EDITOR_CID); @@ -1298,9 +1296,11 @@ NS_IMETHODIMP nsEditor::Paste() rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, nsITransferable::GetIID(), (void**) getter_AddRefs(trans)); - if (NS_OK == rv) { + if (NS_SUCCEEDED(rv)) + { // Get the nsITransferable interface for getting the data from the clipboard - if (trans) { + if (trans) + { // Create the desired DataFlavor for the type of data we want to get out of the transferable nsAutoString htmlFlavor(kHTMLMime); nsAutoString textFlavor(kTextMime); @@ -1311,23 +1311,34 @@ NS_IMETHODIMP nsEditor::Paste() trans->AddDataFlavor(&imageFlavor); // Get the Data from the clipboard - if (NS_OK == clipboard->GetData(trans)) { + if (NS_SUCCEEDED(clipboard->GetData(trans))) + { nsAutoString flavor; char * data; PRUint32 len; - if (NS_OK == trans->GetAnyTransferData(&flavor, (void **)&data, &len)) { + if (NS_SUCCEEDED(trans->GetAnyTransferData(&flavor, (void **)&data, &len))) + { +#ifdef DEBUG printf("Got flavor [%s]\n", flavor.ToNewCString()); - if (flavor.Equals(htmlFlavor)) { - if (data && len > 0) { // stuffToPaste is ready for insertion into the content +#endif + if (flavor.Equals(htmlFlavor)) + { + if (data && len > 0) // stuffToPaste is ready for insertion into the content + { stuffToPaste.SetString(data, len); rv = InsertText(stuffToPaste); } - } else if (flavor.Equals(textFlavor)) { - if (data && len > 0) { // stuffToPaste is ready for insertion into the content + } + else if (flavor.Equals(textFlavor)) + { + if (data && len > 0) // stuffToPaste is ready for insertion into the content + { stuffToPaste.SetString(data, len); rv = InsertText(stuffToPaste); } - } else if (flavor.Equals(imageFlavor)) { + } + else if (flavor.Equals(imageFlavor)) + { image = (nsIImage *)data; // Insert Image code here NS_RELEASE(image); diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 3d5cc6d98f83..1463724c9585 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -48,6 +48,13 @@ #include "nsIPref.h" #include "nsIDOMDocumentFragment.h" #include "nsIPresShell.h" +#include "nsIImage.h" + +// Drag & Drop, Clipboard +#include "nsWidgetsCID.h" +#include "nsIClipboard.h" +#include "nsITransferable.h" + #include "prprf.h" const unsigned char nbsp = 160; @@ -63,6 +70,10 @@ static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID); static NS_DEFINE_CID(kCRangeCID, NS_RANGE_CID); static NS_DEFINE_IID(kFileWidgetCID, NS_FILEWIDGET_CID); +// Drag & Drop, Clipboard Support +static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID); +static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID); + #ifdef NS_DEBUG static PRBool gNoisy = PR_FALSE; #else @@ -445,7 +456,91 @@ NS_IMETHODIMP nsHTMLEditor::Copy() NS_IMETHODIMP nsHTMLEditor::Paste() { - return nsTextEditor::Paste(); +#ifdef DEBUG_akkana + printf("nsHTMLEditor::Paste()\n"); +#endif + +#ifdef ENABLE_JS_EDITOR_LOG + nsAutoJSEditorLogLock logLock(mJSEditorLog); + + if (mJSEditorLog) + mJSEditorLog->Paste(); +#endif // ENABLE_JS_EDITOR_LOG + + nsIImage * image = nsnull; + + nsString stuffToPaste; + + // Get Clipboard Service + nsIClipboard* clipboard; + nsresult rv = nsServiceManager::GetService(kCClipboardCID, + nsIClipboard::GetIID(), + (nsISupports **)&clipboard); + + // Create generic Transferable for getting the data + nsCOMPtr trans; + rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, + nsITransferable::GetIID(), + (void**) getter_AddRefs(trans)); + if (NS_SUCCEEDED(rv)) + { + // Get the nsITransferable interface for getting the data from the clipboard + if (trans) + { + // Create the desired DataFlavor for the type of data we want to get out of the transferable + nsAutoString htmlFlavor(kHTMLMime); + nsAutoString textFlavor(kTextMime); + nsAutoString imageFlavor(kJPEGImageMime); + + trans->AddDataFlavor(&htmlFlavor); + trans->AddDataFlavor(&textFlavor); + trans->AddDataFlavor(&imageFlavor); + + // Get the Data from the clipboard + if (NS_SUCCEEDED(clipboard->GetData(trans))) + { + nsAutoString flavor; + char * data; + PRUint32 len; + if (NS_SUCCEEDED(trans->GetAnyTransferData(&flavor, (void **)&data, &len))) + { +#ifdef DEBUG_akkana + printf("Got flavor [%s]\n", flavor.ToNewCString()); +#endif + if (flavor.Equals(htmlFlavor)) + { + if (data && len > 0) // stuffToPaste is ready for insertion into the content + { + stuffToPaste.SetString(data, len); + rv = InsertHTML(stuffToPaste); + } + } + else if (flavor.Equals(textFlavor)) + { + if (data && len > 0) // stuffToPaste is ready for insertion into the content + { + stuffToPaste.SetString(data, len); + rv = InsertText(stuffToPaste); + } + } + else if (flavor.Equals(imageFlavor)) + { + image = (nsIImage *)data; + // Insert Image code here + NS_RELEASE(image); + rv = NS_ERROR_FAILURE; // for now give error code + } + } + + } + } + } + nsServiceManager::ReleaseService(kCClipboardCID, clipboard); + + //printf("Trying to insert '%s'\n", stuffToPaste.ToNewCString()); + + // Now let InsertText handle the hard stuff: + return rv; } //