From 2a1b7641544743fe584a21c51438472bfb128abc Mon Sep 17 00:00:00 2001 From: "pinkerton%netscape.com" Date: Fri, 2 Apr 1999 18:22:36 +0000 Subject: [PATCH] added new interfaces for closure over all flavors and converters when clients ask for a list of known flavors. --- widget/public/nsITransferable.h | 30 +++++++-- widget/src/xpwidgets/nsTransferable.cpp | 83 +++++++++++++++++++++---- widget/src/xpwidgets/nsTransferable.h | 12 ++-- 3 files changed, 105 insertions(+), 20 deletions(-) diff --git a/widget/public/nsITransferable.h b/widget/public/nsITransferable.h index 2578412fd0b..1bd03dde865 100644 --- a/widget/public/nsITransferable.h +++ b/widget/public/nsITransferable.h @@ -37,9 +37,30 @@ class nsITransferable : public nsISupports { static const nsIID& GetIID() { static nsIID iid = NS_ITRANSFERABLE_IID; return iid; } /** - * Get the list of data flavors that this transferable supports. + * Computes a list of flavors that the transferable can accept into it, either through + * intrinsic knowledge or input data converters. * - * @param aDataFlavorList fills list with supported flavors + * @param outFlavorList fills list with supported flavors. This is a copy of + * the internal list, so it may be edited w/out affecting the transferable. + */ + NS_IMETHOD FlavorsTransferableCanImport ( nsISupportsArray** outFlavorList ) = 0; + + /** + * Computes a list of flavors that the transferable can export, either through + * intrinsic knowledge or output data converters. + * + * @param aDataFlavorList fills list with supported flavors. This is a copy of + * the internal list, so it may be edited w/out affecting the transferable. + */ + NS_IMETHOD FlavorsTransferableCanExport ( nsISupportsArray** outFlavorList ) = 0; + + /** + * Get the list of data flavors that this transferable supports (w/out conversion). + * (NOTE: We're not sure how useful this is in the presence of the above two methods, + * but figured we'd keep it around just in case). + * + * @param aDataFlavorList fills list with supported flavors. This is a copy of + * the internal list, so it may be edited w/out affecting the transferable. */ NS_IMETHOD GetTransferDataFlavors(nsISupportsArray ** aDataFlavorList) = 0; @@ -55,13 +76,14 @@ class nsITransferable : public nsISupports { * Given a flavor retrieve the data. * * @param aFlavor the flavor of data to retrieve - * @param aData the data + * @param aData the data. This is NOT a copy, so the caller MUST NOT DELETE it. * @param aDataLen the length of the data */ NS_IMETHOD GetTransferData(nsIDataFlavor * aFlavor, void ** aData, PRUint32 * aDataLen) = 0; /** - * Set Data into the transferable as a specified DataFlavor + * Set Data into the transferable as a specified DataFlavor. The transferable now + * owns the data, so the caller must not delete it. * * @param aFlavor the flavor of data that is being set * @param aData the data diff --git a/widget/src/xpwidgets/nsTransferable.cpp b/widget/src/xpwidgets/nsTransferable.cpp index e58bdc56097..0983de2277b 100644 --- a/widget/src/xpwidgets/nsTransferable.cpp +++ b/widget/src/xpwidgets/nsTransferable.cpp @@ -24,6 +24,7 @@ #include "nsIFormatConverter.h" #include "nsVoidArray.h" #include "nsIComponentManager.h" +#include "nsCOMPtr.h" static NS_DEFINE_IID(kITransferableIID, NS_ITRANSFERABLE_IID); @@ -49,7 +50,6 @@ nsTransferable::nsTransferable() { NS_INIT_REFCNT(); mDataArray = new nsVoidArray(); - mFormatConv = nsnull; } //------------------------------------------------------------------------- @@ -59,8 +59,6 @@ nsTransferable::nsTransferable() //------------------------------------------------------------------------- nsTransferable::~nsTransferable() { - NS_IF_RELEASE(mFormatConv); - PRInt32 i; for (i=0;iCount();i++) { DataStruct * data = (DataStruct *)mDataArray->ElementAt(i); @@ -252,14 +250,7 @@ NS_IMETHODIMP nsTransferable::IsLargeDataSet() */ NS_IMETHODIMP nsTransferable::SetConverter(nsIFormatConverter * aConverter) { - if (nsnull != mFormatConv) { - NS_RELEASE(mFormatConv); - } - - mFormatConv = aConverter; - if (nsnull != mFormatConv) { - NS_ADDREF(mFormatConv); - } + mFormatConv = dont_QueryInterface(aConverter); return NS_OK; } @@ -271,8 +262,76 @@ NS_IMETHODIMP nsTransferable::GetConverter(nsIFormatConverter ** aConverter) { if (nsnull != mFormatConv) { *aConverter = mFormatConv; - NS_ADDREF(mFormatConv); + NS_ADDREF(*aConverter); } return NS_OK; } + +// +// FlavorsTransferableCanImport +// +// Computes a list of flavors that the transferable can accept into it, either through +// intrinsic knowledge or input data converters. +// +NS_IMETHODIMP +nsTransferable :: FlavorsTransferableCanImport ( nsISupportsArray** outFlavorList ) +{ + if ( !outFlavorList ) + return NS_ERROR_INVALID_ARG; + + // Get the flavor list, and on to the end of it, append the list of flavors we + // can also get to through a converter. This is so that we can just walk the list + // in one go, looking for the desired flavor. + GetTransferDataFlavors(outFlavorList); // addrefs + nsCOMPtr converter; + GetConverter(getter_AddRefs(converter)); + if ( converter ) { + nsCOMPtr convertedList; + converter->GetInputDataFlavors(getter_AddRefs(convertedList)); + if ( convertedList ) { + for (int i=0;iCount();i++) { + nsCOMPtr temp = getter_AddRefs(convertedList->ElementAt(i)); + (*outFlavorList)->AppendElement(temp); // this addref's for us + } // foreach flavor that can be converted to + } + } // if a converter exists + + return NS_OK; + +} // FlavorsTransferableCanImport + + +// +// FlavorsTransferableCanExport +// +// Computes a list of flavors that the transferable can export, either through +// intrinsic knowledge or output data converters. +// +NS_IMETHODIMP +nsTransferable :: FlavorsTransferableCanExport ( nsISupportsArray** outFlavorList ) +{ + if ( !outFlavorList ) + return NS_ERROR_INVALID_ARG; + + // Get the flavor list, and on to the end of it, append the list of flavors we + // can also get to through a converter. This is so that we can just walk the list + // in one go, looking for the desired flavor. + GetTransferDataFlavors(outFlavorList); // addrefs + nsCOMPtr converter; + GetConverter(getter_AddRefs(converter)); + if ( converter ) { + nsCOMPtr convertedList; + converter->GetOutputDataFlavors(getter_AddRefs(convertedList)); + if ( convertedList ) { + for (int i=0;iCount();i++) { + nsCOMPtr temp = getter_AddRefs(convertedList->ElementAt(i)); + (*outFlavorList)->AppendElement(temp); // this addref's for us + } // foreach flavor that can be converted to + } + } // if a converter exists + + return NS_OK; + +} // FlavorsTransferableCanImport + diff --git a/widget/src/xpwidgets/nsTransferable.h b/widget/src/xpwidgets/nsTransferable.h index a1318fffd56..71fb05494ef 100644 --- a/widget/src/xpwidgets/nsTransferable.h +++ b/widget/src/xpwidgets/nsTransferable.h @@ -19,13 +19,15 @@ #ifndef nsTransferable_h__ #define nsTransferable_h__ +#include "nsIFormatConverter.h" #include "nsITransferable.h" +#include "nsCOMPtr.h" + class nsISupportsArray; class nsIDataFlavor; class nsDataObj; class nsVoidArray; -class nsIFormatConverter; /** @@ -43,11 +45,12 @@ public: NS_DECL_ISUPPORTS //nsITransferable - // Returns a copy of the flavor list + NS_IMETHOD FlavorsTransferableCanImport ( nsISupportsArray** outFlavorList ) ; + NS_IMETHOD FlavorsTransferableCanExport ( nsISupportsArray** outFlavorList ) ; NS_IMETHOD GetTransferDataFlavors(nsISupportsArray ** aDataFlavorList); NS_IMETHOD IsDataFlavorSupported(nsIDataFlavor * aFlavor); - // Transferable still owns |aData|. Do not delete it. + // Transferable still owns |aData|. Do not delete it. NS_IMETHOD GetTransferData(nsIDataFlavor * aFlavor, void ** aData, PRUint32 * aDataLen); // Transferable consumes |aData|. Do not delete it. NS_IMETHOD SetTransferData(nsIDataFlavor * aFlavor, void * aData, PRUint32 aDataLen); @@ -58,10 +61,11 @@ public: NS_IMETHOD SetConverter(nsIFormatConverter * aConverter); NS_IMETHOD GetConverter(nsIFormatConverter ** aConverter); + protected: nsVoidArray * mDataArray; - nsIFormatConverter * mFormatConv; + nsCOMPtr mFormatConv; };