diff --git a/mozilla/widget/src/xpwidgets/nsDataFlavor.cpp b/mozilla/widget/src/xpwidgets/nsDataFlavor.cpp new file mode 100644 index 00000000000..3da90d74433 --- /dev/null +++ b/mozilla/widget/src/xpwidgets/nsDataFlavor.cpp @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsDataFlavor.h" + +static NS_DEFINE_IID(kIDataFlavor, NS_IDATAFLAVOR_IID); + +NS_IMPL_ADDREF(nsDataFlavor) +NS_IMPL_RELEASE(nsDataFlavor) + +//------------------------------------------------------------------------- +// +// DataFlavor constructor +// +//------------------------------------------------------------------------- +nsDataFlavor::nsDataFlavor() +{ + NS_INIT_REFCNT(); +} + +//------------------------------------------------------------------------- +// +// DataFlavor destructor +// +//------------------------------------------------------------------------- +nsDataFlavor::~nsDataFlavor() +{ +} + +/** + * @param aIID The name of the class implementing the method + * @param _classiiddef The name of the #define symbol that defines the IID + * for the class (e.g. NS_ISUPPORTS_IID) + * +*/ +nsresult nsDataFlavor::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + nsresult rv = NS_NOINTERFACE; + + if (aIID.Equals(kIDataFlavor)) { + *aInstancePtr = (void*) ((nsIDataFlavor*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return rv; +} + +/** + * + * + */ +NS_METHOD nsDataFlavor::Init(const nsString & aMimeType, const nsString & aHumanPresentableName) +{ + mMimeType = aMimeType; + mHumanPresentableName = aHumanPresentableName; + + char * str = mMimeType.ToNewCString(); + // XXXX mNativeClipboardFormat = ::RegisterClipboardFormat(str); + + delete[] str; + + return NS_OK; +} + +/** + * + * + */ +NS_METHOD nsDataFlavor::GetMimeType(nsString & aMimeStr) +{ + aMimeStr = mMimeType; + return NS_OK; +} + +/** + * + * + */ +NS_METHOD nsDataFlavor::GetHumanPresentableName(nsString & aHumanPresentableName) +{ + aHumanPresentableName = mHumanPresentableName; + return NS_OK; +} + +/** + * + * + */ +NS_METHOD nsDataFlavor::GetNativeData(void ** aData) +{ + return NS_OK; +} + +/** + * + * + */ +NS_METHOD nsDataFlavor::SetNativeData(void * aData) +{ + return NS_OK; +} + diff --git a/mozilla/widget/src/xpwidgets/nsDataFlavor.h b/mozilla/widget/src/xpwidgets/nsDataFlavor.h new file mode 100644 index 00000000000..6714c5b74e5 --- /dev/null +++ b/mozilla/widget/src/xpwidgets/nsDataFlavor.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsDataFlavor_h__ +#define nsDataFlavor_h__ + +#include "nsIDataFlavor.h" + +class nsISupportsArray; +class nsIDataFlavor; + +/** + * Native Win32 DataFlavor wrapper + */ + +class nsDataFlavor : public nsIDataFlavor +{ + +public: + nsDataFlavor(); + virtual ~nsDataFlavor(); + + //nsISupports + NS_DECL_ISUPPORTS + + //nsIDataFlavor + NS_IMETHOD Init(const nsString & aMimeType, + const nsString & aHumanPresentableName); + NS_IMETHOD GetMimeType(nsString & aMimeStr); + NS_IMETHOD GetHumanPresentableName(nsString & aReadableStr); + + NS_IMETHOD GetNativeData(void ** aData); + NS_IMETHOD SetNativeData(void * aData); + + + // Native Methods + PRUint32 GetFormat() { return mNativeClipboardFormat; } + +protected: + nsString mMimeType; + nsString mHumanPresentableName; + + PRUint32 mNativeClipboardFormat; + +}; + +#endif // nsDataFlavor_h__ diff --git a/mozilla/widget/src/xpwidgets/nsTransferable.cpp b/mozilla/widget/src/xpwidgets/nsTransferable.cpp new file mode 100644 index 00000000000..3184b8f8981 --- /dev/null +++ b/mozilla/widget/src/xpwidgets/nsTransferable.cpp @@ -0,0 +1,237 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsTransferable.h" +#include "nsIDataFlavor.h" +#include "nsDataFlavor.h" +#include "nsWidgetsCID.h" +#include "nsISupportsArray.h" +#include "nsRepository.h" + +static NS_DEFINE_IID(kITransferableIID, NS_ITRANSFERABLE_IID); +static NS_DEFINE_IID(kIDataFlavorIID, NS_IDATAFLAVOR_IID); +static NS_DEFINE_IID(kCDataFlavorCID, NS_DATAFLAVOR_CID); + +NS_IMPL_ADDREF(nsTransferable) +NS_IMPL_RELEASE(nsTransferable) + +//------------------------------------------------------------------------- +// +// Transferable constructor +// +//------------------------------------------------------------------------- +nsTransferable::nsTransferable() +{ + NS_INIT_REFCNT(); + mDataObj = nsnull; + mStrCache = nsnull; + mDataPtr = nsnull; + + nsresult rv = NS_NewISupportsArray(&mDFList); + +} + +//------------------------------------------------------------------------- +// +// Transferable destructor +// +//------------------------------------------------------------------------- +nsTransferable::~nsTransferable() +{ + if (mStrCache) { + delete mStrCache; + } + if (mDataPtr) { + delete mDataPtr; + } + +} + +/** + * @param aIID The name of the class implementing the method + * @param _classiiddef The name of the #define symbol that defines the IID + * for the class (e.g. NS_ISUPPORTS_IID) + * +*/ +nsresult nsTransferable::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + nsresult rv = NS_NOINTERFACE; + + if (aIID.Equals(kITransferableIID)) { + *aInstancePtr = (void*) ((nsITransferable*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return rv; +} + + +/** + * + * + */ +NS_IMETHODIMP nsTransferable::GetTransferDataFlavors(nsISupportsArray ** aDataFlavorList) +{ + *aDataFlavorList = mDFList; + NS_ADDREF(mDFList); + return NS_OK; +} + +/** + * + * + */ +NS_IMETHODIMP nsTransferable::IsDataFlavorSupported(nsIDataFlavor * aDataFlavor) +{ + nsAutoString mimeInQuestion; + aDataFlavor->GetMimeType(mimeInQuestion); + + PRUint32 i; + for (i=0;iCount();i++) { + nsIDataFlavor * df; + nsISupports * supports = mDFList->ElementAt(i); + if (NS_OK == supports->QueryInterface(kIDataFlavorIID, (void **)&df)) { + nsAutoString mime; + df->GetMimeType(mime); + if (mimeInQuestion.Equals(mime)) { + return NS_OK; + } + NS_RELEASE(df); + } + NS_RELEASE(supports); + } + return NS_ERROR_FAILURE; +} + +/** + * + * + */ +NS_IMETHODIMP nsTransferable::GetTransferData(nsIDataFlavor * aDataFlavor, void ** aData, PRUint32 * aDataLen) +{ + if (mDataPtr) { + delete mDataPtr; + } + + nsAutoString mimeInQuestion; + aDataFlavor->GetMimeType(mimeInQuestion); + + if (mimeInQuestion.Equals(kTextMime)) { + char * str = mStrCache->ToNewCString(); + *aDataLen = mStrCache->Length()+1; + + mDataPtr = (void *)str; + *aData = mDataPtr; + } else if (mimeInQuestion.Equals(kHTMLMime)) { + + } + + return NS_OK; +} + +/** + * + * + */ +NS_IMETHODIMP nsTransferable::SetTransferData(nsIDataFlavor * aDataFlavor, void * aData, PRUint32 aDataLen) +{ + if (aData == nsnull) { + return NS_OK; + } + + nsAutoString mimeInQuestion; + aDataFlavor->GetMimeType(mimeInQuestion); + + if (mimeInQuestion.Equals(kTextMime)) { + if (nsnull == mStrCache) { + mStrCache = new nsString(); + } + mStrCache->SetString((char *)aData, aDataLen-1); + } else if (mimeInQuestion.Equals(kHTMLMime)) { + + } + + return NS_OK; +} + +/** + * + * + */ +NS_IMETHODIMP nsTransferable::SetTransferString(const nsString & aStr) +{ + if (!mStrCache) { + mStrCache = new nsString(aStr); + } else { + *mStrCache = aStr; + } + + return NS_OK; +} + +/** + * + * + */ +NS_IMETHODIMP nsTransferable::GetTransferString(nsString & aStr) +{ + if (!mStrCache) { + mStrCache = new nsString(); + } + aStr = *mStrCache; + + return NS_OK; +} + +/** + * + * + */ +NS_IMETHODIMP nsTransferable::AddDataFlavor(const nsString & aMimeType, const nsString & aHumanPresentableName) +{ + nsIDataFlavor * df; + nsresult rv = nsComponentManager::CreateInstance(kCDataFlavorCID, nsnull, kIDataFlavorIID, (void**) &df); + if (nsnull == df) { + return rv; + } + + df->Init(aMimeType, aHumanPresentableName); + mDFList->AppendElement(df); + + return rv; +} + +/** + * + * + */ +NS_IMETHODIMP nsTransferable::IsLargeDataSet() +{ + if (mStrCache) { + return (mStrCache->Length() > 1024?NS_OK:NS_ERROR_FAILURE); + } + + return NS_ERROR_FAILURE; +} + diff --git a/mozilla/widget/src/xpwidgets/nsTransferable.h b/mozilla/widget/src/xpwidgets/nsTransferable.h new file mode 100644 index 00000000000..b4ea8051511 --- /dev/null +++ b/mozilla/widget/src/xpwidgets/nsTransferable.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsTransferable_h__ +#define nsTransferable_h__ + +#include "nsITransferable.h" + +class nsISupportsArray; +class nsIDataFlavor; +class nsDataObj; + +/** + * Native Win32 Transferable wrapper + */ + +class nsTransferable : public nsITransferable +{ + +public: + nsTransferable(); + virtual ~nsTransferable(); + + //nsISupports + NS_DECL_ISUPPORTS + + //nsITransferable + NS_IMETHOD GetTransferDataFlavors(nsISupportsArray ** aDataFlavorList); + NS_IMETHOD IsDataFlavorSupported(nsIDataFlavor * aFlavor); + + NS_IMETHOD GetTransferData(nsIDataFlavor * aFlavor, void ** aData, PRUint32 * aDataLen); + NS_IMETHOD SetTransferData(nsIDataFlavor * aFlavor, void * aData, PRUint32 aDataLen); + + NS_IMETHOD SetTransferString(const nsString & aStr); + NS_IMETHOD GetTransferString(nsString & aStr); + + NS_IMETHOD AddDataFlavor(const nsString & aMimeType, const nsString & aHumanPresentableName); + NS_IMETHOD IsLargeDataSet(); + + // Used for native implementation + nsDataObj * GetDataObj() { return mDataObj; } + +protected: + + nsISupportsArray * mDFList; + nsDataObj * mDataObj; + + nsString * mStrCache; + void * mDataPtr; +}; + +#endif // nsTransferable_h__