Finishing clipboard ifdef so we can remove the old clipboard.

This commit is contained in:
mcafee%netscape.com 1999-04-07 03:56:07 +00:00
Родитель af15e24c5c
Коммит 616c553b24
7 изменённых файлов: 201 добавлений и 111 удалений

Просмотреть файл

@ -40,7 +40,9 @@
#include "nsIAtom.h"
#include "nsVoidArray.h"
#include "nsICaret.h"
#ifndef NEW_CLIPBOARD_SUPPORT
#include "nsISelectionMgr.h"
#endif
#include "nsIContent.h"
#include "nsIContentIterator.h"
@ -71,8 +73,6 @@
// END
#endif
//#define NEW_CLIPBOARD_SUPPORT
#ifdef NEW_CLIPBOARD_SUPPORT
// Drag & Drop, Clipboard
@ -836,12 +836,15 @@ NS_IMETHODIMP nsEditor::Cut()
return res;
}
#ifndef NEW_CLIPBOARD_SUPPORT
extern "C" NS_EXPORT nsISelectionMgr* GetSelectionMgr();
#endif
NS_IMETHODIMP nsEditor::Copy()
{
//printf("nsEditor::Copy\n");
#ifndef NEW_CLIPBOARD_SUPPORT
// Get the nsSelectionMgr:
// XXX BWEEP BWEEP TEMPORARY!
// The selection mgr needs to be a service.
@ -857,6 +860,10 @@ NS_IMETHODIMP nsEditor::Copy()
//NS_ADD_REF(theSelectionMgr);
return mPresShell->DoCopy(selectionMgr);
#else
return mPresShell->DoCopy();
#endif
}
NS_IMETHODIMP nsEditor::Paste()

Просмотреть файл

@ -40,7 +40,9 @@
#include "nsIAtom.h"
#include "nsVoidArray.h"
#include "nsICaret.h"
#ifndef NEW_CLIPBOARD_SUPPORT
#include "nsISelectionMgr.h"
#endif
#include "nsIContent.h"
#include "nsIContentIterator.h"
@ -71,8 +73,6 @@
// END
#endif
//#define NEW_CLIPBOARD_SUPPORT
#ifdef NEW_CLIPBOARD_SUPPORT
// Drag & Drop, Clipboard
@ -836,12 +836,15 @@ NS_IMETHODIMP nsEditor::Cut()
return res;
}
#ifndef NEW_CLIPBOARD_SUPPORT
extern "C" NS_EXPORT nsISelectionMgr* GetSelectionMgr();
#endif
NS_IMETHODIMP nsEditor::Copy()
{
//printf("nsEditor::Copy\n");
#ifndef NEW_CLIPBOARD_SUPPORT
// Get the nsSelectionMgr:
// XXX BWEEP BWEEP TEMPORARY!
// The selection mgr needs to be a service.
@ -857,6 +860,10 @@ NS_IMETHODIMP nsEditor::Copy()
//NS_ADD_REF(theSelectionMgr);
return mPresShell->DoCopy(selectionMgr);
#else
return mPresShell->DoCopy();
#endif
}
NS_IMETHODIMP nsEditor::Paste()

Просмотреть файл

@ -38,7 +38,9 @@ class nsString;
class nsStringArray;
class nsICaret;
class nsIStyleContext;
#ifndef NEW_CLIPBOARD_SUPPORT
class nsISelectionMgr;
#endif
#define NS_IPRESSHELL_IID \
{ 0x76e79c60, 0x944e, 0x11d1, \
@ -261,7 +263,11 @@ public:
/**
* Notify the SelectionMgr that we have something to copy.
*/
#ifndef NEW_CLIPBOARD_SUPPORT
NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr) = 0;
#else
NS_IMETHOD DoCopy() = 0;
#endif
/**
* Get the caret, if it exists. AddRefs it.

Просмотреть файл

@ -326,7 +326,12 @@ public:
PRUint32 aVFlags,
PRInt32 aHOffsetPercent,
PRUint32 aHFlags) const;
#ifdef NEW_CLIPBOARD_SUPPORT
NS_IMETHOD DoCopy();
#else
NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr);
#endif
//nsIViewObserver interface
@ -1542,6 +1547,83 @@ PresShell::ScrollFrameIntoView(nsIFrame *aFrame,
return rv;
}
#ifdef NEW_CLIPBOARD_SUPPORT
// New way
NS_IMETHODIMP
PresShell::DoCopy()
{
nsCOMPtr<nsIDocument> doc;
GetDocument(getter_AddRefs(doc));
if (doc) {
nsString buffer;
nsIDOMSelection* sel = nsnull;
GetSelection(&sel);
if (sel != nsnull)
doc->CreateXIF(buffer,sel);
NS_IF_RELEASE(sel);
// Get the Clipboard
nsIClipboard* clipboard;
nsresult rv = nsServiceManager::GetService(kCClipboardCID,
kIClipboardIID,
(nsISupports **)&clipboard);
if (NS_OK == rv) {
// Create a data flavor to tell the transferable
// that it is about to receive XIF
nsIDataFlavor * flavor;
rv = nsComponentManager::CreateInstance(kCDataFlavorCID,
nsnull,
kIDataFlavorIID, (void**) &flavor);
if (NS_OK == rv) {
// Initialize data flavor to XIF
flavor->Init(kXIFMime, "XIF");
// Create a transferable for putting data on the Clipboard
nsITransferable * trans;
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
kITransferableIID, (void**) &trans);
if (NS_OK == rv) {
// The data on the clipboard will be in "XIF" format
// so give the clipboard transferable a "XIFConverter" for
// converting from XIF to other formats
nsIFormatConverter * xifConverter;
rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull,
kIFormatConverterIID, (void**) &xifConverter);
if (NS_OK == rv) {
// Add the XIF DataFlavor to the transferable
// this tells the transferable that it can handle receiving the XIF format
trans->AddDataFlavor(flavor);
// Add the converter for going from XIF to other formats
trans->SetConverter(xifConverter);
// Now add the XIF data to the transferable
trans->SetTransferData(flavor, buffer.ToNewCString(), buffer.Length());
// put the transferable on the clipboard
clipboard->SetData(trans, nsnull);
NS_IF_RELEASE(xifConverter);
}
NS_IF_RELEASE(trans);
}
NS_IF_RELEASE(flavor);
}
NS_IF_RELEASE(clipboard);
}
}
return NS_OK;
}
#else
// Old SelectionMgr implementation.
NS_IMETHODIMP
PresShell::DoCopy(nsISelectionMgr* aSelectionMgr)
{
@ -1557,8 +1639,6 @@ PresShell::DoCopy(nsISelectionMgr* aSelectionMgr)
doc->CreateXIF(buffer,sel);
NS_IF_RELEASE(sel);
////////////////////////// Old Way
#ifndef NEW_CLIPBOARD_SUPPORT
nsIParser* parser;
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
@ -1605,61 +1685,13 @@ PresShell::DoCopy(nsISelectionMgr* aSelectionMgr)
NS_IF_RELEASE(sink);
NS_RELEASE(parser);
#else /////////////////////////// New Way
// Put XIF into transferable
// Get the Clipboard
nsIClipboard* clipboard;
nsresult rv = nsServiceManager::GetService(kCClipboardCID,
kIClipboardIID,
(nsISupports **)&clipboard);
if (NS_OK == rv) {
// Create a data flavor to tell the transferable
// that it is about to receive XIF
nsIDataFlavor * flavor;
rv = nsComponentManager::CreateInstance(kCDataFlavorCID, nsnull, kIDataFlavorIID, (void**) &flavor);
if (NS_OK == rv) {
// Initialize data flavor to XIF
flavor->Init(kXIFMime, "XIF");
// Create a transferable for putting data on the Clipboard
nsITransferable * trans;
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, kITransferableIID, (void**) &trans);
if (NS_OK == rv) {
// The data on the clipboard will be in "XIF" format
// so give the clipboard transferable a "XIFConverter" for
// converting from XIF to other formats
nsIFormatConverter * xifConverter;
rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull, kIFormatConverterIID, (void**) &xifConverter);
if (NS_OK == rv) {
// Add the XIF DataFlavor to the transferable
// this tells the transferable that it can handle receiving the XIF format
trans->AddDataFlavor(flavor);
// Add the converter for going from XIF to other formats
trans->SetConverter(xifConverter);
// Now add the XIF data to the transferable
trans->SetTransferData(flavor, buffer.ToNewCString(), buffer.Length());
// put the transferable on the clipboard
clipboard->SetData(trans, nsnull);
NS_IF_RELEASE(xifConverter);
}
NS_IF_RELEASE(trans);
}
NS_IF_RELEASE(flavor);
}
NS_IF_RELEASE(clipboard);
}
#endif
}
return NS_OK;
}
#endif // NEW_CLIPBOARD_SUPPORT
NS_IMETHODIMP
PresShell::ContentChanged(nsIDocument *aDocument,
nsIContent* aContent,

Просмотреть файл

@ -38,7 +38,9 @@ class nsString;
class nsStringArray;
class nsICaret;
class nsIStyleContext;
#ifndef NEW_CLIPBOARD_SUPPORT
class nsISelectionMgr;
#endif
#define NS_IPRESSHELL_IID \
{ 0x76e79c60, 0x944e, 0x11d1, \
@ -261,7 +263,11 @@ public:
/**
* Notify the SelectionMgr that we have something to copy.
*/
#ifndef NEW_CLIPBOARD_SUPPORT
NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr) = 0;
#else
NS_IMETHOD DoCopy() = 0;
#endif
/**
* Get the caret, if it exists. AddRefs it.

Просмотреть файл

@ -326,7 +326,12 @@ public:
PRUint32 aVFlags,
PRInt32 aHOffsetPercent,
PRUint32 aHFlags) const;
#ifdef NEW_CLIPBOARD_SUPPORT
NS_IMETHOD DoCopy();
#else
NS_IMETHOD DoCopy(nsISelectionMgr* aSelectionMgr);
#endif
//nsIViewObserver interface
@ -1542,6 +1547,83 @@ PresShell::ScrollFrameIntoView(nsIFrame *aFrame,
return rv;
}
#ifdef NEW_CLIPBOARD_SUPPORT
// New way
NS_IMETHODIMP
PresShell::DoCopy()
{
nsCOMPtr<nsIDocument> doc;
GetDocument(getter_AddRefs(doc));
if (doc) {
nsString buffer;
nsIDOMSelection* sel = nsnull;
GetSelection(&sel);
if (sel != nsnull)
doc->CreateXIF(buffer,sel);
NS_IF_RELEASE(sel);
// Get the Clipboard
nsIClipboard* clipboard;
nsresult rv = nsServiceManager::GetService(kCClipboardCID,
kIClipboardIID,
(nsISupports **)&clipboard);
if (NS_OK == rv) {
// Create a data flavor to tell the transferable
// that it is about to receive XIF
nsIDataFlavor * flavor;
rv = nsComponentManager::CreateInstance(kCDataFlavorCID,
nsnull,
kIDataFlavorIID, (void**) &flavor);
if (NS_OK == rv) {
// Initialize data flavor to XIF
flavor->Init(kXIFMime, "XIF");
// Create a transferable for putting data on the Clipboard
nsITransferable * trans;
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
kITransferableIID, (void**) &trans);
if (NS_OK == rv) {
// The data on the clipboard will be in "XIF" format
// so give the clipboard transferable a "XIFConverter" for
// converting from XIF to other formats
nsIFormatConverter * xifConverter;
rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull,
kIFormatConverterIID, (void**) &xifConverter);
if (NS_OK == rv) {
// Add the XIF DataFlavor to the transferable
// this tells the transferable that it can handle receiving the XIF format
trans->AddDataFlavor(flavor);
// Add the converter for going from XIF to other formats
trans->SetConverter(xifConverter);
// Now add the XIF data to the transferable
trans->SetTransferData(flavor, buffer.ToNewCString(), buffer.Length());
// put the transferable on the clipboard
clipboard->SetData(trans, nsnull);
NS_IF_RELEASE(xifConverter);
}
NS_IF_RELEASE(trans);
}
NS_IF_RELEASE(flavor);
}
NS_IF_RELEASE(clipboard);
}
}
return NS_OK;
}
#else
// Old SelectionMgr implementation.
NS_IMETHODIMP
PresShell::DoCopy(nsISelectionMgr* aSelectionMgr)
{
@ -1557,8 +1639,6 @@ PresShell::DoCopy(nsISelectionMgr* aSelectionMgr)
doc->CreateXIF(buffer,sel);
NS_IF_RELEASE(sel);
////////////////////////// Old Way
#ifndef NEW_CLIPBOARD_SUPPORT
nsIParser* parser;
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
@ -1605,61 +1685,13 @@ PresShell::DoCopy(nsISelectionMgr* aSelectionMgr)
NS_IF_RELEASE(sink);
NS_RELEASE(parser);
#else /////////////////////////// New Way
// Put XIF into transferable
// Get the Clipboard
nsIClipboard* clipboard;
nsresult rv = nsServiceManager::GetService(kCClipboardCID,
kIClipboardIID,
(nsISupports **)&clipboard);
if (NS_OK == rv) {
// Create a data flavor to tell the transferable
// that it is about to receive XIF
nsIDataFlavor * flavor;
rv = nsComponentManager::CreateInstance(kCDataFlavorCID, nsnull, kIDataFlavorIID, (void**) &flavor);
if (NS_OK == rv) {
// Initialize data flavor to XIF
flavor->Init(kXIFMime, "XIF");
// Create a transferable for putting data on the Clipboard
nsITransferable * trans;
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull, kITransferableIID, (void**) &trans);
if (NS_OK == rv) {
// The data on the clipboard will be in "XIF" format
// so give the clipboard transferable a "XIFConverter" for
// converting from XIF to other formats
nsIFormatConverter * xifConverter;
rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull, kIFormatConverterIID, (void**) &xifConverter);
if (NS_OK == rv) {
// Add the XIF DataFlavor to the transferable
// this tells the transferable that it can handle receiving the XIF format
trans->AddDataFlavor(flavor);
// Add the converter for going from XIF to other formats
trans->SetConverter(xifConverter);
// Now add the XIF data to the transferable
trans->SetTransferData(flavor, buffer.ToNewCString(), buffer.Length());
// put the transferable on the clipboard
clipboard->SetData(trans, nsnull);
NS_IF_RELEASE(xifConverter);
}
NS_IF_RELEASE(trans);
}
NS_IF_RELEASE(flavor);
}
NS_IF_RELEASE(clipboard);
}
#endif
}
return NS_OK;
}
#endif // NEW_CLIPBOARD_SUPPORT
NS_IMETHODIMP
PresShell::ContentChanged(nsIDocument *aDocument,
nsIContent* aContent,

Просмотреть файл

@ -929,7 +929,7 @@ nsBrowserAppCore::Copy()
#ifdef NEW_CLIPBOARD_SUPPORT
nsIPresShell * presShell = GetPresShellFor(mContentAreaWebShell);
if (nsnull != presShell) {
presShell->DoCopy(nsnull);
presShell->DoCopy();
}
#endif