Make it such that clients of the clipboard/d&d only need to work with the text/unicode flavor and not text/plain. The conversion to text/plain for the native OS (in the correct charset encoding for the platform) is now done w/in the native clipboard/d&d implementations.

This commit is contained in:
pinkerton%netscape.com 2000-01-29 20:24:50 +00:00
Родитель 201000c9ad
Коммит a7c192941f
10 изменённых файлов: 237 добавлений и 90 удалений

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

@ -274,6 +274,13 @@ NS_IMETHODIMP nsClipboard::SetNativeClipboardData()
// add these types as selection targets
RegisterFormat(format);
// if text/unicode is present, also add text/plain to the list of flavors we
// export as we will do the conversion by hand.
if ( strcmp(flavorStr, kUnicodeMime) == 0 ) {
gint textFormat = GetFormat(kTextMime);
RegisterFormat(textFormat);
}
}
}
@ -292,7 +299,7 @@ void nsClipboard::AddTarget(GdkAtom aAtom)
gint nsClipboard::GetFormat(const char* aMimeStr)
{
gint type = TARGET_NONE;
nsCAutoString mimeStr ( CBufDescriptor(NS_CONST_CAST(char*,aMimeStr), PR_TRUE, PL_strlen(aMimeStr)+1) );
nsCAutoString mimeStr ( CBufDescriptor(aMimeStr, PR_TRUE, PL_strlen(aMimeStr)+1) );
#ifdef DEBUG_CLIPBOARD
g_print(" nsClipboard::GetFormat(%s)\n", aMimeStr);
#endif
@ -785,11 +792,14 @@ void nsClipboard::SelectionGetCB(GtkWidget *widget,
}
}
PRBool needToDoConversionToPlainText = PR_FALSE;
switch(type)
{
case GDK_TARGET_STRING:
case TARGET_TEXT_PLAIN:
dataFlavor = kTextMime;
// if someone was asking for text/plain, lookup unicode instead so we can convert it.
dataFlavor = kUnicodeMime;
needToDoConversionToPlainText = PR_TRUE;
break;
case TARGET_TEXT_XIF:
dataFlavor = kXIFMime;
@ -821,7 +831,7 @@ void nsClipboard::SelectionGetCB(GtkWidget *widget,
#ifdef DEBUG_CLIPBOARD
g_print("- aInfo is for %s\n", gdk_atom_name(aInfo));
#endif
// Get data out of transferable.
nsCOMPtr<nsISupports> genericDataWrapper;
rv = cb->mTransferable->GetTransferData(dataFlavor,
@ -833,11 +843,26 @@ void nsClipboard::SelectionGetCB(GtkWidget *widget,
// find the number of bytes in the data for the below thing
// size_t size = sizeof((void*)((unsigned char)clipboardData[0]));
// g_print("************ ***************** ******************* %i\n", size);
// if required, do the extra work to convert unicode to plain text and replace the output
// values with the plain text.
if ( needToDoConversionToPlainText ) {
char* plainTextData = nsnull;
PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, clipboardData);
PRInt32 plainTextLen = 0;
nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText ( castedUnicode, dataLength / 2, &plainTextData, &plainTextLen );
if ( clipboardData ) {
nsAllocator::Free(NS_REINTERPRET_CAST(char*, clipboardData));
clipboardData = plainTextData;
dataLength = plainTextLen;
}
}
gtk_selection_data_set(aSelectionData,
aInfo, size*8,
(unsigned char *)clipboardData,
dataLength);
if ( clipboardData )
gtk_selection_data_set(aSelectionData,
aInfo, size*8,
NS_REINTERPRET_CAST(unsigned char *, clipboardData),
dataLength);
nsCRT::free ( NS_REINTERPRET_CAST(char*, clipboardData) );
}
else

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

@ -125,6 +125,21 @@ nsClipboard :: SetNativeClipboardData()
if ( numBytes != noErr )
errCode = NS_ERROR_FAILURE;
// if the flavor was unicode, then we also need to put it on as 'TEXT' after
// doing the conversion to the platform charset.
if ( strcmp(flavorStr,kUnicodeMime) == 0 ) {
char* plainTextData = nsnull;
PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, data);
PRInt32 plainTextLen = 0;
nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText ( castedUnicode, dataSize / 2, &plainTextData, &plainTextLen );
if ( plainTextData ) {
long numTextBytes = ::PutScrap ( plainTextLen, 'TEXT', plainTextData );
if ( numTextBytes != noErr )
errCode = NS_ERROR_FAILURE;
nsAllocator::Free ( plainTextData );
}
} // if unicode
nsAllocator::Free ( data );
}
} // foreach flavor in transferable

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

@ -225,6 +225,13 @@ nsDragService :: RegisterDragItemsAndFlavors ( nsISupportsArray * inArray )
currentFlavor->ToString ( getter_Copies(flavorStr) );
FlavorType macOSFlavor = theMapper.MapMimeTypeToMacOSType(flavorStr);
::AddDragItemFlavor ( mDragRef, itemIndex, macOSFlavor, NULL, 0, flags );
// If we advertise text/unicode, then make sure we add 'TEXT' to the list
// of flavors supported since we will do the conversion ourselves in GetDataForFlavor()
if ( strcmp(flavorStr, kUnicodeMime) == 0 ) {
theMapper.MapMimeTypeToMacOSType(kTextMime);
::AddDragItemFlavor ( mDragRef, itemIndex, 'TEXT', NULL, 0, flags );
}
}
} // foreach flavor in item
@ -479,6 +486,13 @@ nsDragService :: DragSendDataProc ( FlavorType inFlavor, void* inRefCon, ItemRef
//
// Given a MacOS flavor and an index for which drag item to lookup, get the information from the
// drag item corresponding to this flavor.
//
// This routine also handles the conversions between text/plain and text/unicode to take platform
// charset encodings into account. If someone asks for text/plain, we convert the unicode (we assume
// it is present because that's how we knew to advertise text/plain in the first place) and give it
// to them. If someone asks for text/unicode, and it isn't there, we need to convert text/plain and
// hand them back the unicode. Again, we can assume that text/plain is there because otherwise we
// wouldn't have been allowed to look for unicode.
//
OSErr
nsDragService :: GetDataForFlavor ( nsISupportsArray* inDragItems, DragReference inDragRef, unsigned int inItemIndex,
@ -489,24 +503,50 @@ nsDragService :: GetDataForFlavor ( nsISupportsArray* inDragItems, DragReference
OSErr retVal = noErr;
// (assumes that the items were placed into the transferable as nsITranferable*'s, not
// nsISupports*'s. Don't forget ElementAt() addRefs for us.)
// (assumes that the items were placed into the transferable as nsITranferable*'s, not nsISupports*'s.)
nsCOMPtr<nsISupports> genericItem;
inDragItems->GetElementAt ( inItemIndex, getter_AddRefs(genericItem) );
nsCOMPtr<nsITransferable> item ( do_QueryInterface(genericItem) );
if ( item ) {
nsCAutoString mimeFlavor;
// create a mime mapper to help us out based on data in a special flavor for this item.
char* mappings = LookupMimeMappingsForItem(inDragRef, inItemIndex) ;
nsMimeMapperMac theMapper ( mappings );
theMapper.MapMacOSTypeToMimeType ( inFlavor, mimeFlavor );
nsCRT::free ( mappings );
nsAllocator::Free ( mappings );
// if someone was asking for text/plain, lookup unicode instead so we can convert it.
PRBool needToDoConversionToPlainText = PR_FALSE;
char* actualFlavor = mimeFlavor;
if ( strcmp(mimeFlavor,kTextMime) == 0 ) {
actualFlavor = kUnicodeMime;
needToDoConversionToPlainText = PR_TRUE;
}
else
actualFlavor = mimeFlavor;
*outDataSize = 0;
nsCOMPtr<nsISupports> data;
if ( NS_SUCCEEDED(item->GetTransferData(mimeFlavor.GetBuffer(), getter_AddRefs(data), outDataSize)) )
nsPrimitiveHelpers::CreateDataFromPrimitive ( mimeFlavor.GetBuffer(), data, outData, *outDataSize );
if ( NS_SUCCEEDED(item->GetTransferData(actualFlavor, getter_AddRefs(data), outDataSize)) ) {
nsPrimitiveHelpers::CreateDataFromPrimitive ( actualFlavor, data, outData, *outDataSize );
// if required, do the extra work to convert unicode to plain text and replace the output
// values with the plain text.
if ( needToDoConversionToPlainText ) {
char* plainTextData = nsnull;
PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, *outData);
PRInt32 plainTextLen = 0;
nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText ( castedUnicode, *outDataSize / 2, &plainTextData, &plainTextLen );
if ( *outData ) {
nsAllocator::Free(*outData);
*outData = plainTextData;
*outDataSize = plainTextLen;
}
else
retVal = cantGetFlavorErr;
}
}
else
retVal = cantGetFlavorErr;
} // if valid item

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

@ -159,6 +159,14 @@ nsresult nsClipboard::SetupNativeDataObject(nsITransferable * aTransferable, IDa
// Now tell the native IDataObject about both the DataFlavor and
// the native data format
dObj->AddDataFlavor(flavorStr, &fe);
// if we find text/unicode, also advertise text/plain (which we will convert
// on our own in nsDataObj::GetText().
if ( strcmp(flavorStr, kUnicodeMime) ) {
FORMATETC fe2;
SET_FORMATETC(fe2, CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL)
dObj->AddDataFlavor("text/plain", &fe2);
}
}
}

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

@ -75,13 +75,13 @@ nsDataObj::~nsDataObj()
NS_IF_RELEASE(mTransferable);
PRInt32 i;
for (i=0;i<mDataFlavors->Count();i++) {
nsString * df = (nsString *)mDataFlavors->ElementAt(i);
nsCAutoString* df = NS_REINTERPRET_CAST(nsCAutoString *, mDataFlavors->ElementAt(i));
delete df;
}
delete mDataFlavors;
m_cRef = 0;
m_cRef = 0;
m_enumFE->Release();
}
@ -157,13 +157,14 @@ STDMETHODIMP nsDataObj::GetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
FORMATETC fe;
m_enumFE->Reset();
while (NOERROR == m_enumFE->Next(1, &fe, &count)) {
nsString * df = (nsString *)mDataFlavors->ElementAt(dfInx);
if (nsnull != df) {
nsCAutoString * df = NS_REINTERPRET_CAST(nsCAutoString*, mDataFlavors->ElementAt(dfInx));
if ( df ) {
if (FormatsMatch(fe, *pFE)) {
pSTM->pUnkForRelease = NULL;
CLIPFORMAT format = pFE->cfFormat;
switch(format) {
case CF_TEXT:
case CF_UNICODETEXT:
return GetText(df, *pFE, *pSTM);
//case CF_BITMAP:
// return GetBitmap(*pFE, *pSTM);
@ -332,21 +333,24 @@ HRESULT nsDataObj::GetDib(FORMATETC&, STGMEDIUM&)
}
//-----------------------------------------------------
HRESULT nsDataObj::GetText(nsString * aDF, FORMATETC& aFE, STGMEDIUM& aSTG)
HRESULT nsDataObj::GetText(nsCAutoString * aDataFlavor, FORMATETC& aFE, STGMEDIUM& aSTG)
{
void* data;
PRUint32 len;
char* flavorStr = aDF->ToNewCString();
// if someone asks for text/plain, look up text/unicode instead in the transferable.
char* flavorStr;
if ( aDataFlavor->Equals("text/plain") )
flavorStr = kUnicodeMime;
else
flavorStr = *aDataFlavor;
// NOTE: CreateDataFromPrimitive creates new memory, that needs to be deleted
nsCOMPtr<nsISupports> genericDataWrapper;
mTransferable->GetTransferData(flavorStr, getter_AddRefs(genericDataWrapper), &len);
if (0 == len) {
return ResultFromScode(E_FAIL);
}
if ( !len )
return ResultFromScode(E_FAIL);
nsPrimitiveHelpers::CreateDataFromPrimitive ( flavorStr, genericDataWrapper, &data, len );
nsAllocator::Free(flavorStr);
HGLOBAL hGlobalMemory = NULL;
PSTR pGlobalMemory = NULL;
@ -354,33 +358,50 @@ HRESULT nsDataObj::GetText(nsString * aDF, FORMATETC& aFE, STGMEDIUM& aSTG)
aSTG.tymed = TYMED_HGLOBAL;
aSTG.pUnkForRelease = NULL;
// If someone is asking for text/plain, we need to convert unicode (assuming it's present)
// to text with the correct platform encoding.
//
// The transferable gives us data that is null-terminated, but this isn't reflected in
// the |len| parameter. Windoze apps expect this null to be there so bump our data buffer
// by the appropriate size to account for the null (one char for CF_TEXT, one PRUnichar for
// CF_UNICODETEXT).
DWORD allocLen = (DWORD)len;
if ( CF_TEXT == aFE.cfFormat )
allocLen += sizeof(char);
else if ( CF_UNICODETEXT == aFE.cfFormat)
if ( aFE.cfFormat == CF_TEXT ) {
char* plainTextData = nsnull;
PRUnichar* castedUnicode = NS_REINTERPRET_CAST(PRUnichar*, data);
PRInt32 plainTextLen = 0;
nsPrimitiveHelpers::ConvertUnicodeToPlatformPlainText ( castedUnicode, len / 2, &plainTextData, &plainTextLen );
// replace the unicode data with our plaintext data. Recall that |plainTextLen| doesn't include
// the null in the length.
nsAllocator::Free(data);
if ( plainTextData ) {
data = plainTextData;
allocLen = plainTextLen + sizeof(char);
}
else {
NS_WARNING ( "Oh no, couldn't convert unicode to plain text" );
return ResultFromScode(S_OK);
}
}
else if ( aFE.cfFormat == CF_UNICODETEXT )
allocLen += sizeof(PRUnichar);
// GHND zeroes the memory
hGlobalMemory = (HGLOBAL)::GlobalAlloc(GHND, allocLen);
hGlobalMemory = (HGLOBAL)::GlobalAlloc(GHND, allocLen); // GHND zeroes the memory
// Copy text to Global Memory Area
if (hGlobalMemory != NULL) {
if ( hGlobalMemory ) {
char* dest = NS_REINTERPRET_CAST(char*, ::GlobalLock(hGlobalMemory));
char* source = NS_REINTERPRET_CAST(char*, data);
memcpy ( dest, source, allocLen ); // copies the null as well
memcpy ( dest, source, allocLen ); // copies the null as well
BOOL status = ::GlobalUnlock(hGlobalMemory);
}
aSTG.hGlobal = hGlobalMemory;
// Now, delete the memory that was created by CreateDataFromPrimitive
// Now, delete the memory that was created by CreateDataFromPrimitive (or our text/plain data)
nsAllocator::Free(data);
return ResultFromScode(S_OK);
return ResultFromScode(S_OK);
}
//-----------------------------------------------------
@ -447,7 +468,6 @@ void nsDataObj::AddDataFlavor(const char* aDataFlavor, LPFORMATETC aFE)
// and then ask the transferable for that type of data
mDataFlavors->AppendElement(new nsCAutoString(aDataFlavor));
m_enumFE->AddFE(aFE);
}
//-----------------------------------------------------

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

@ -67,7 +67,7 @@ class nsDataObj : public IDataObject
void AddDataFlavor(const char* aDataFlavor, LPFORMATETC aFE);
void SetTransferable(nsITransferable * aTransferable);
virtual HRESULT GetText(nsString * aDF, FORMATETC& FE, STGMEDIUM& STM);
virtual HRESULT GetText(nsCAutoString * aDF, FORMATETC& FE, STGMEDIUM& STM);
// Return the registered OLE class ID of this object's CfDataObj.
CLSID GetClassID() const;

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

@ -43,14 +43,22 @@
#include "nsIComponentManager.h"
#include "nsLinebreakConverter.h"
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
// unicode conversion
#define NS_IMPL_IDS
# include "nsIPlatformCharset.h"
#undef NS_IMPL_IDS
#include "nsISaveAsCharset.h"
//
// CreatePrimitiveForData
//
// Given some data and the flavor it corresponds to, creates the appropriate
// nsISupports* wrapper for passing across IDL boundaries. Right now, everything
// creates a two-byte |nsISupportsWString| unless the flavor is "text/plain", in which
// case it creates a one-byte |nsISupportsString|.
// creates a two-byte |nsISupportsWString|, even "text/plain" since it is decoded
// from the native platform charset into unicode.
//
void
nsPrimitiveHelpers :: CreatePrimitiveForData ( const char* aFlavor, void* aDataBuff,
@ -114,6 +122,61 @@ nsPrimitiveHelpers :: CreateDataFromPrimitive ( const char* aFlavor, nsISupports
}
//
// ConvertUnicodeToPlatformPlainText
//
// Given a unicode buffer (flavor text/unicode), this converts it to plain text using
// the appropriate platform charset encoding. |inUnicodeLen| is the length of the input
// string, not the # of bytes in the buffer. The |outPlainTextData| is null terminated,
// but its length parameter, |outPlainTextLen|, does not reflect that.
//
void
nsPrimitiveHelpers :: ConvertUnicodeToPlatformPlainText ( PRUnichar* inUnicode, PRInt32 inUnicodeLen,
char** outPlainTextData, PRInt32* outPlainTextLen )
{
if ( !outPlainTextData || !outPlainTextLen )
return;
// Get the appropriate unicode encoder. We're guaranteed that this won't change
// through the life of the app so we can cache it.
nsresult rv;
static nsCOMPtr<nsIUnicodeEncoder> encoder;
static PRBool hasConverter = PR_FALSE;
if ( !hasConverter ) {
// get the charset
nsCOMPtr <nsIPlatformCharset> platformCharsetService;
nsAutoString platformCharset;
nsresult res = nsComponentManager::CreateInstance(NS_PLATFORMCHARSET_PROGID, nsnull,
NS_GET_IID(nsIPlatformCharset),
getter_AddRefs(platformCharsetService));
if (NS_SUCCEEDED(res))
res = platformCharsetService->GetCharset(kPlatformCharsetSel_PlainTextInClipboard, platformCharset);
if (NS_FAILED(res))
platformCharset.SetString("ISO-8859-1");
// get the encoder
NS_WITH_SERVICE(nsICharsetConverterManager, ccm, NS_CHARSETCONVERTERMANAGER_PROGID, &rv);
rv = ccm->GetUnicodeEncoder(&platformCharset, getter_AddRefs(encoder));
hasConverter = PR_TRUE;
}
// Estimate out length and allocate the buffer based on a worst-case estimate, then do
// the conversion.
encoder->GetMaxLength(inUnicode, inUnicodeLen, outPlainTextLen);
if ( *outPlainTextLen ) {
*outPlainTextData = NS_REINTERPRET_CAST(char*, nsAllocator::Alloc(*outPlainTextLen + 1));
if ( *outPlainTextData ) {
rv = encoder->Convert(inUnicode, &inUnicodeLen, *outPlainTextData, outPlainTextLen);
(*outPlainTextData)[*outPlainTextLen] = '\0'; // null terminate. Convert() doesn't do it for us
}
} // if valid length
NS_ASSERTION ( NS_SUCCEEDED(rv), "Error converting unicode to plain text" );
} // ConvertUnicodeToPlatformPlainText
#ifdef XP_MAC
#pragma mark -
#endif

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

@ -25,6 +25,7 @@
#include "prtypes.h"
#include "nsError.h"
#include "nscore.h"
class nsISupports;
@ -45,6 +46,13 @@ public:
static void CreateDataFromPrimitive ( const char* aFlavor, nsISupports* aPrimitive,
void** aDataBuff, PRUint32 aDataLen ) ;
// Given a unicode buffer (flavor text/unicode), this converts it to plain text using
// the appropriate platform charset encoding. |inUnicodeLen| is the length of the input
// string, not the # of bytes in the buffer. The |outPlainTextData| is null terminated,
// but its length parameter, |outPlainTextLen|, does not reflect that.
static void ConvertUnicodeToPlatformPlainText ( PRUnichar* inUnicode, PRInt32 inUnicodeLen,
char** outPlainTextData, PRInt32* outPlainTextLen ) ;
}; // class nsPrimitiveHelpers

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

@ -50,15 +50,9 @@
#include "nsString.h"
#include "nsWidgetsCID.h"
#include "nsXIFFormatConverter.h"
#include "nsPrimitiveHelpers.h"
// unicode conversion
#define NS_IMPL_IDS
# include "nsIPlatformCharset.h"
#undef NS_IMPL_IDS
#include "nsISaveAsCharset.h"
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); // don't panic. NS_PARSER_IID just has the wrong name.
NS_IMPL_ADDREF(nsXIFFormatConverter)
@ -142,9 +136,6 @@ nsXIFFormatConverter::GetOutputDataFlavors(nsISupportsArray **_retval)
rv = AddFlavorToList ( *_retval, kUnicodeMime );
if ( NS_FAILED(rv) )
return rv;
rv = AddFlavorToList ( *_retval, kTextMime );
if ( NS_FAILED(rv) )
return rv;
}
return rv;
@ -191,9 +182,7 @@ nsXIFFormatConverter::CanConvert(const char *aFromDataFlavor, const char *aToDat
nsAutoString fromFlavor ( aFromDataFlavor );
if ( fromFlavor.Equals(kXIFMime) ) {
nsAutoString toFlavor ( aToDataFlavor );
if ( toFlavor.Equals(kTextMime) )
*_retval = PR_TRUE;
else if ( toFlavor.Equals(kHTMLMime) )
if ( toFlavor.Equals(kHTMLMime) )
*_retval = PR_TRUE;
else if ( toFlavor.Equals(kUnicodeMime) )
*_retval = PR_TRUE;
@ -246,22 +235,9 @@ nsXIFFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromDat
PRUnichar* castedData = NS_CONST_CAST(PRUnichar*, NS_STATIC_CAST(const PRUnichar*, data));
nsAutoString dataStr ( CBufDescriptor(castedData, PR_TRUE, aDataLen) ); //¥¥¥ try not to copy the data
if ( toFlavor.Equals(kTextMime) ) {
nsCAutoString outStr;
if ( NS_SUCCEEDED(ConvertFromXIFToText(dataStr, outStr)) ) {
nsCOMPtr<nsISupportsString> dataWrapper;
nsComponentManager::CreateInstance(NS_SUPPORTS_STRING_PROGID, nsnull,
NS_GET_IID(nsISupportsString), getter_AddRefs(dataWrapper) );
if ( dataWrapper ) {
dataWrapper->SetData ( outStr.GetBuffer() );
nsCOMPtr<nsISupports> genericDataWrapper ( do_QueryInterface(dataWrapper) );
*aToData = genericDataWrapper;
NS_ADDREF(*aToData);
*aDataToLen = outStr.Length();
}
}
} // if plain text
else if ( toFlavor.Equals(kHTMLMime) || toFlavor.Equals(kUnicodeMime) ) {
// note: conversion to text/plain is done inside the clipboard. we do not need to worry
// about it here.
if ( toFlavor.Equals(kHTMLMime) || toFlavor.Equals(kUnicodeMime) ) {
nsAutoString outStr;
nsresult res;
if (toFlavor.Equals(kHTMLMime))
@ -269,31 +245,19 @@ nsXIFFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromDat
else
res = ConvertFromXIFToUnicode(dataStr, outStr);
if ( NS_SUCCEEDED(res) ) {
nsCOMPtr<nsISupportsWString> dataWrapper;
nsComponentManager::CreateInstance(NS_SUPPORTS_WSTRING_PROGID, nsnull,
NS_GET_IID(nsISupportsWString), getter_AddRefs(dataWrapper) );
if ( dataWrapper ) {
dataWrapper->SetData ( NS_CONST_CAST(PRUnichar*,outStr.GetUnicode()) ); //¥¥¥ COPY #2
nsCOMPtr<nsISupports> genericDataWrapper ( do_QueryInterface(dataWrapper) );
*aToData = genericDataWrapper;
NS_ADDREF(*aToData);
*aDataToLen = outStr.Length() * 2;
}
PRInt32 dataLen = outStr.Length() * 2;
nsPrimitiveHelpers::CreatePrimitiveForData ( toFlavor, (void*)outStr.GetUnicode(), dataLen, aToData );
if ( *aToData )
*aDataToLen = dataLen;
}
} // else if HTML
} // else if HTML or Unicode
else if ( toFlavor.Equals(kAOLMailMime) ) {
nsAutoString outStr;
if ( NS_SUCCEEDED(ConvertFromXIFToAOLMail(dataStr, outStr)) ) { //¥¥¥ COPY #2
nsCOMPtr<nsISupportsWString> dataWrapper;
nsComponentManager::CreateInstance(NS_SUPPORTS_WSTRING_PROGID, nsnull,
NS_GET_IID(nsISupportsWString), getter_AddRefs(dataWrapper) );
if ( dataWrapper ) {
dataWrapper->SetData ( NS_CONST_CAST(PRUnichar*,outStr.GetUnicode()) ); //¥¥¥ COPY #3
nsCOMPtr<nsISupports> genericDataWrapper ( do_QueryInterface(dataWrapper) );
*aToData = genericDataWrapper;
NS_ADDREF(*aToData);
*aDataToLen = outStr.Length() * 2;
}
if ( NS_SUCCEEDED(ConvertFromXIFToAOLMail(dataStr, outStr)) ) {
PRInt32 dataLen = outStr.Length() * 2;
nsPrimitiveHelpers::CreatePrimitiveForData ( toFlavor, (void*)outStr.GetUnicode(), dataLen, aToData );
if ( *aToData )
*aDataToLen = dataLen;
}
} // else if AOL mail
else {
@ -313,11 +277,15 @@ nsXIFFormatConverter::Convert(const char *aFromDataFlavor, nsISupports *aFromDat
} // Convert
#if USE_PLAIN_TEXT
//
// ConvertFromXIFToText
//
// Takes XIF and converts it to plain text using the correct charset for the platform/OS/language.
//
// *** This code is now obsolete, but I'm leaving it around for reference about how to do
// *** charset conversion with streams
//
NS_IMETHODIMP
nsXIFFormatConverter::ConvertFromXIFToText(const nsAutoString & aFromStr, nsCAutoString & aToStr)
{
@ -374,6 +342,7 @@ nsXIFFormatConverter::ConvertFromXIFToText(const nsAutoString & aFromStr, nsCAut
return NS_OK;
} // ConvertFromXIFToText
#endif
//

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

@ -49,7 +49,6 @@ protected:
NS_IMETHOD ConvertFromXIFToHTML(const nsAutoString & aFromStr, nsAutoString & aToStr);
NS_IMETHOD ConvertFromXIFToUnicode(const nsAutoString & aFromStr, nsAutoString & aToStr);
NS_IMETHOD ConvertFromXIFToText(const nsAutoString & aFromStr, nsCAutoString & aToStr);
NS_IMETHOD ConvertFromXIFToAOLMail(const nsAutoString & aFromStr, nsAutoString & aToStr);
};