Bug 474369 - get rid of nsVoidArray; widget part; r+sr=roc

This commit is contained in:
Arpad Borsos 2009-02-23 02:05:24 +01:00
Родитель 864a45296a
Коммит 7b9bf0ac75
18 изменённых файлов: 124 добавлений и 137 удалений

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

@ -41,7 +41,6 @@
#include "nsCOMPtr.h"
#include "nsIDeviceContextSpec.h"
#include "nsVoidArray.h"
#include "nsIPrintSettings.h"
#include "nsIPrintOptions.h"
// For public interface?

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

@ -45,7 +45,6 @@
#include "nsITransferable.h"
#include "nsIServiceManager.h"
#include "nsISupportsPrimitives.h"
#include "nsVoidArray.h"
#include "nsXPIDLString.h"
#include "nsPrimitiveHelpers.h"
#include "nsWidgetsCID.h"

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

@ -56,7 +56,7 @@
#include "resource.h"
#include "prtime.h"
#include "nsReadableUtils.h"
#include "nsVoidArray.h"
#include "nsTPtrArray.h"
#include "nsIProxyObjectManager.h"
#include <Application.h>
@ -101,7 +101,7 @@ static BWindow * gLastActiveWindow = NULL;
// such as regxpcom, do not create a BApplication object, and therefor fail to run.,
// since a BCursor requires a vaild BApplication (see Bug#129964). But, we still want
// to cache them for performance. Currently, there are 17 cursors available;
static nsVoidArray gCursorArray(21);
static nsTPtrArray<BCursor> gCursorArray(21);
// Used in contrain position. Specifies how much of a window must remain on screen
#define kWindowPositionSlop 20
// BeOS does not provide this information, so we must hard-code it
@ -1259,29 +1259,29 @@ NS_METHOD nsWindow::SetCursor(nsCursor aCursor)
be_app->ShowCursor();
// Check to see if the array has been loaded, if not, do it.
if (gCursorArray.Count() == 0)
if (gCursorArray.Length() == 0)
{
gCursorArray.InsertElementAt((void*) new BCursor(cursorHyperlink),0);
gCursorArray.InsertElementAt((void*) new BCursor(cursorHorizontalDrag),1);
gCursorArray.InsertElementAt((void*) new BCursor(cursorVerticalDrag),2);
gCursorArray.InsertElementAt((void*) new BCursor(cursorUpperLeft),3);
gCursorArray.InsertElementAt((void*) new BCursor(cursorLowerRight),4);
gCursorArray.InsertElementAt((void*) new BCursor(cursorUpperRight),5);
gCursorArray.InsertElementAt((void*) new BCursor(cursorLowerLeft),6);
gCursorArray.InsertElementAt((void*) new BCursor(cursorCrosshair),7);
gCursorArray.InsertElementAt((void*) new BCursor(cursorHelp),8);
gCursorArray.InsertElementAt((void*) new BCursor(cursorGrab),9);
gCursorArray.InsertElementAt((void*) new BCursor(cursorGrabbing),10);
gCursorArray.InsertElementAt((void*) new BCursor(cursorCopy),11);
gCursorArray.InsertElementAt((void*) new BCursor(cursorAlias),12);
gCursorArray.InsertElementAt((void*) new BCursor(cursorWatch2),13);
gCursorArray.InsertElementAt((void*) new BCursor(cursorCell),14);
gCursorArray.InsertElementAt((void*) new BCursor(cursorZoomIn),15);
gCursorArray.InsertElementAt((void*) new BCursor(cursorZoomOut),16);
gCursorArray.InsertElementAt((void*) new BCursor(cursorLeft),17);
gCursorArray.InsertElementAt((void*) new BCursor(cursorRight),18);
gCursorArray.InsertElementAt((void*) new BCursor(cursorTop),19);
gCursorArray.InsertElementAt((void*) new BCursor(cursorBottom),20);
gCursorArray.InsertElementAt(0 , new BCursor(cursorHyperlink));
gCursorArray.InsertElementAt(1 , new BCursor(cursorHorizontalDrag));
gCursorArray.InsertElementAt(2 , new BCursor(cursorVerticalDrag));
gCursorArray.InsertElementAt(3 , new BCursor(cursorUpperLeft));
gCursorArray.InsertElementAt(4 , new BCursor(cursorLowerRight));
gCursorArray.InsertElementAt(5 , new BCursor(cursorUpperRight));
gCursorArray.InsertElementAt(6 , new BCursor(cursorLowerLeft));
gCursorArray.InsertElementAt(7 , new BCursor(cursorCrosshair));
gCursorArray.InsertElementAt(8 , new BCursor(cursorHelp));
gCursorArray.InsertElementAt(9 , new BCursor(cursorGrab));
gCursorArray.InsertElementAt(10, new BCursor(cursorGrabbing));
gCursorArray.InsertElementAt(11, new BCursor(cursorCopy));
gCursorArray.InsertElementAt(12, new BCursor(cursorAlias));
gCursorArray.InsertElementAt(13, new BCursor(cursorWatch2));
gCursorArray.InsertElementAt(14, new BCursor(cursorCell));
gCursorArray.InsertElementAt(15, new BCursor(cursorZoomIn));
gCursorArray.InsertElementAt(16, new BCursor(cursorZoomOut));
gCursorArray.InsertElementAt(17, new BCursor(cursorLeft));
gCursorArray.InsertElementAt(18, new BCursor(cursorRight));
gCursorArray.InsertElementAt(19, new BCursor(cursorTop));
gCursorArray.InsertElementAt(20, new BCursor(cursorBottom));
}
switch (aCursor)
@ -1296,55 +1296,55 @@ NS_METHOD nsWindow::SetCursor(nsCursor aCursor)
break;
case eCursor_hyperlink:
newCursor = (BCursor *)gCursorArray.SafeElementAt(0);
newCursor = gCursorArray.SafeElementAt(0);
break;
case eCursor_n_resize:
newCursor = (BCursor *)gCursorArray.SafeElementAt(19);
newCursor = gCursorArray.SafeElementAt(19);
break;
case eCursor_s_resize:
newCursor = (BCursor *)gCursorArray.SafeElementAt(20);
newCursor = gCursorArray.SafeElementAt(20);
break;
case eCursor_w_resize:
newCursor = (BCursor *)gCursorArray.SafeElementAt(17);
newCursor = gCursorArray.SafeElementAt(17);
break;
case eCursor_e_resize:
newCursor = (BCursor *)gCursorArray.SafeElementAt(18);
newCursor = gCursorArray.SafeElementAt(18);
break;
case eCursor_nw_resize:
newCursor = (BCursor *)gCursorArray.SafeElementAt(3);
newCursor = gCursorArray.SafeElementAt(3);
break;
case eCursor_se_resize:
newCursor = (BCursor *)gCursorArray.SafeElementAt(4);
newCursor = gCursorArray.SafeElementAt(4);
break;
case eCursor_ne_resize:
newCursor = (BCursor *)gCursorArray.SafeElementAt(5);
newCursor = gCursorArray.SafeElementAt(5);
break;
case eCursor_sw_resize:
newCursor = (BCursor *)gCursorArray.SafeElementAt(6);
newCursor = gCursorArray.SafeElementAt(6);
break;
case eCursor_crosshair:
newCursor = (BCursor *)gCursorArray.SafeElementAt(7);
newCursor = gCursorArray.SafeElementAt(7);
break;
case eCursor_help:
newCursor = (BCursor *)gCursorArray.SafeElementAt(8);
newCursor = gCursorArray.SafeElementAt(8);
break;
case eCursor_copy:
newCursor = (BCursor *)gCursorArray.SafeElementAt(11);
newCursor = gCursorArray.SafeElementAt(11);
break;
case eCursor_alias:
newCursor = (BCursor *)gCursorArray.SafeElementAt(12);
newCursor = gCursorArray.SafeElementAt(12);
break;
case eCursor_context_menu:
@ -1352,28 +1352,28 @@ NS_METHOD nsWindow::SetCursor(nsCursor aCursor)
break;
case eCursor_cell:
newCursor = (BCursor *)gCursorArray.SafeElementAt(14);
newCursor = gCursorArray.SafeElementAt(14);
break;
case eCursor_grab:
newCursor = (BCursor *)gCursorArray.SafeElementAt(9);
newCursor = gCursorArray.SafeElementAt(9);
break;
case eCursor_grabbing:
newCursor = (BCursor *)gCursorArray.SafeElementAt(10);
newCursor = gCursorArray.SafeElementAt(10);
break;
case eCursor_wait:
case eCursor_spinning:
newCursor = (BCursor *)gCursorArray.SafeElementAt(13);
newCursor = gCursorArray.SafeElementAt(13);
break;
case eCursor_zoom_in:
newCursor = (BCursor *)gCursorArray.SafeElementAt(15);
newCursor = gCursorArray.SafeElementAt(15);
break;
case eCursor_zoom_out:
newCursor = (BCursor *)gCursorArray.SafeElementAt(16);
newCursor = gCursorArray.SafeElementAt(16);
break;
case eCursor_not_allowed:
@ -1383,12 +1383,12 @@ NS_METHOD nsWindow::SetCursor(nsCursor aCursor)
case eCursor_col_resize:
// XXX not 100% appropriate perhaps
newCursor = (BCursor *)gCursorArray.SafeElementAt(1);
newCursor = gCursorArray.SafeElementAt(1);
break;
case eCursor_row_resize:
// XXX not 100% appropriate perhaps
newCursor = (BCursor *)gCursorArray.SafeElementAt(2);
newCursor = gCursorArray.SafeElementAt(2);
break;
case eCursor_vertical_text:
@ -1402,20 +1402,20 @@ NS_METHOD nsWindow::SetCursor(nsCursor aCursor)
case eCursor_nesw_resize:
// XXX not 100% appropriate perhaps
newCursor = (BCursor *)gCursorArray.SafeElementAt(1);
newCursor = gCursorArray.SafeElementAt(1);
break;
case eCursor_nwse_resize:
// XXX not 100% appropriate perhaps
newCursor = (BCursor *)gCursorArray.SafeElementAt(1);
newCursor = gCursorArray.SafeElementAt(1);
break;
case eCursor_ns_resize:
newCursor = (BCursor *)gCursorArray.SafeElementAt(2);
newCursor = gCursorArray.SafeElementAt(2);
break;
case eCursor_ew_resize:
newCursor = (BCursor *)gCursorArray.SafeElementAt(1);
newCursor = gCursorArray.SafeElementAt(1);
break;
case eCursor_none:

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

@ -52,7 +52,7 @@
#include "nsIFileURL.h"
#include "nsNetUtil.h"
#include "prlog.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "nsPrimitiveHelpers.h"
#include "prtime.h"
#include "prthread.h"
@ -977,7 +977,7 @@ nsDragService::GetSourceList(void)
{
if (!mSourceDataItems)
return NULL;
nsVoidArray targetArray;
nsTArray<GtkTargetEntry*> targetArray;
GtkTargetEntry *targets;
GtkTargetList *targetList = 0;
PRUint32 targetCount = 0;
@ -1126,15 +1126,14 @@ nsDragService::GetSourceList(void)
} // if it is a single item drag
// get all the elements that we created.
targetCount = targetArray.Count();
targetCount = targetArray.Length();
if (targetCount) {
// allocate space to create the list of valid targets
targets =
(GtkTargetEntry *)g_malloc(sizeof(GtkTargetEntry) * targetCount);
PRUint32 targetIndex;
for ( targetIndex = 0; targetIndex < targetCount; ++targetIndex) {
GtkTargetEntry *disEntry =
(GtkTargetEntry *)targetArray.ElementAt(targetIndex);
GtkTargetEntry *disEntry = targetArray.ElementAt(targetIndex);
// this is a string reference but it will be freed later.
targets[targetIndex].target = disEntry->target;
targets[targetIndex].flags = disEntry->flags;
@ -1143,8 +1142,7 @@ nsDragService::GetSourceList(void)
targetList = gtk_target_list_new(targets, targetCount);
// clean up the target list
for (PRUint32 cleanIndex = 0; cleanIndex < targetCount; ++cleanIndex) {
GtkTargetEntry *thisTarget =
(GtkTargetEntry *)targetArray.ElementAt(cleanIndex);
GtkTargetEntry *thisTarget = targetArray.ElementAt(cleanIndex);
g_free(thisTarget->target);
g_free(thisTarget);
}

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

@ -51,7 +51,6 @@
#include "nsIDeviceContextSpec.h"
#include "nsIPrintOptions.h"
#include "nsIPrintSettings.h"
#include "nsVoidArray.h"
#include "nsPrintdOS2.h"
#include <os2.h>
#include <pmddim.h>

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

@ -40,7 +40,6 @@
// OS/2 defines; for user messages & warp4 stuff, plus module-global data
#include "nsIWidget.h"
#include "nsVoidArray.h"
#define INCL_PM
#define INCL_NLS

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

@ -395,8 +395,8 @@ nsDataObj::~nsDataObj()
{
NS_IF_RELEASE(mTransferable);
for (PRInt32 i = 0; i < mDataFlavors.Count(); ++i) {
delete reinterpret_cast<nsCString *>(mDataFlavors.ElementAt(i));
for (PRUint32 i = 0; i < mDataFlavors.Length(); ++i) {
delete mDataFlavors.ElementAt(i);
}
m_enumFE->Release();
@ -498,7 +498,7 @@ STDMETHODIMP nsDataObj::GetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
FORMATETC fe;
m_enumFE->Reset();
while (NOERROR == m_enumFE->Next(1, &fe, &count)) {
nsCString * df = reinterpret_cast<nsCString*>(mDataFlavors.SafeElementAt(dfInx));
nsCString * df = mDataFlavors.SafeElementAt(dfInx);
if ( df ) {
if (FormatsMatch(fe, *pFE)) {
pSTM->pUnkForRelease = NULL; // caller is responsible for deleting this data
@ -1373,7 +1373,7 @@ HRESULT nsDataObj::GetFile(FORMATETC& aFE, STGMEDIUM& aSTG)
m_enumFE->Reset();
PRBool found = PR_FALSE;
while (NOERROR == m_enumFE->Next(1, &fe, &count)) {
nsCString * df = reinterpret_cast<nsCString*>(mDataFlavors.SafeElementAt(dfInx));
nsCString * df = mDataFlavors.SafeElementAt(dfInx);
dfInx++;
if (df && df->EqualsLiteral(kNativeImageMime)) {
found = PR_TRUE;

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

@ -51,8 +51,7 @@
#include "nsIURI.h"
#include "nsIInputStream.h"
#include "nsIChannel.h"
#include "nsTArray.h"
#include "nsVoidArray.h"
#include "nsTPtrArray.h"
// XXX for older version of PSDK where IAsyncOperation and related stuff is not available
// but thisdefine should be removed when parocles config is updated
@ -265,7 +264,7 @@ class nsDataObj : public IDataObject,
ULONG m_cRef; // the reference count
nsVoidArray mDataFlavors;
nsTPtrArray<nsCString> mDataFlavors;
nsITransferable * mTransferable; // nsDataObj owns and ref counts nsITransferable,
// the nsITransferable does know anything about the nsDataObj

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

@ -76,14 +76,14 @@ nsDataObjCollection::~nsDataObjCollection()
{
NS_IF_RELEASE(mTransferable);
PRInt32 i;
PRUint32 i;
for (i = 0; i < mDataFlavors.Count(); ++i) {
delete (nsString *)mDataFlavors.ElementAt(i);
for (i = 0; i < mDataFlavors.Length(); ++i) {
delete mDataFlavors.ElementAt(i);
}
for (i = 0; i < mDataObjects.Count(); ++i) {
IDataObject * dataObj = (IDataObject *)mDataObjects.ElementAt(i);
for (i = 0; i < mDataObjects.Length(); ++i) {
IDataObject * dataObj = mDataObjects.ElementAt(i);
NS_RELEASE(dataObj);
}
@ -154,8 +154,8 @@ STDMETHODIMP nsDataObjCollection::GetData(LPFORMATETC pFE, LPSTGMEDIUM pSTM)
PRNTDEBUG("nsDataObjCollection::GetData\n");
PRNTDEBUG3(" format: %d Text: %d\n", pFE->cfFormat, CF_TEXT);
for (PRInt32 i = 0; i < mDataObjects.Count(); ++i) {
IDataObject * dataObj = (IDataObject *)mDataObjects.ElementAt(i);
for (PRUint32 i = 0; i < mDataObjects.Length(); ++i) {
IDataObject * dataObj = mDataObjects.ElementAt(i);
if (S_OK == dataObj->GetData(pFE, pSTM)) {
return S_OK;
}
@ -189,8 +189,8 @@ STDMETHODIMP nsDataObjCollection::QueryGetData(LPFORMATETC pFE)
}
for (PRInt32 i = 0; i < mDataObjects.Count(); ++i) {
IDataObject * dataObj = (IDataObject *)mDataObjects.ElementAt(i);
for (PRUint32 i = 0; i < mDataObjects.Length(); ++i) {
IDataObject * dataObj = mDataObjects.ElementAt(i);
if (S_OK == dataObj->QueryGetData(pFE)) {
return S_OK;
}

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

@ -48,7 +48,8 @@
#include <oleidl.h>
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "nsTPtrArray.h"
class CEnumFormatEtc;
class nsITransferable;
@ -119,14 +120,14 @@ class nsDataObjCollection : public IDataObject, public nsIDataObjCollection //,
#if NOT_YET
// from nsPIDataObjCollection
STDMETHODIMP AddDataObject(IDataObject * aDataObj);
STDMETHODIMP GetNumDataObjects(PRInt32* outNum) { *outNum = mDataObjects.Count(); }
STDMETHODIMP GetDataObjectAt(PRUint32 aItem, IDataObject** outItem) { *outItem = (IDataObject *)mDataObjects.SafeElementAt(aItem); }
STDMETHODIMP GetNumDataObjects(PRInt32* outNum) { *outNum = mDataObjects.Length(); }
STDMETHODIMP GetDataObjectAt(PRUint32 aItem, IDataObject** outItem) { *outItem = mDataObjects.SafeElementAt(aItem); }
#endif
// from nsPIDataObjCollection
void AddDataObject(IDataObject * aDataObj);
PRInt32 GetNumDataObjects() { return mDataObjects.Count(); }
IDataObject* GetDataObjectAt(PRUint32 aItem) { return (IDataObject *)mDataObjects.SafeElementAt(aItem); }
PRInt32 GetNumDataObjects() { return mDataObjects.Length(); }
IDataObject* GetDataObjectAt(PRUint32 aItem) { return mDataObjects.SafeElementAt(aItem); }
// Return the registered OLE class ID of this object's CfDataObj.
CLSID GetClassID() const;
@ -191,7 +192,7 @@ class nsDataObjCollection : public IDataObject, public nsIDataObjCollection //,
ULONG m_cRef; // the reference count
nsVoidArray mDataFlavors;
nsTArray<nsString*> mDataFlavors;
nsITransferable * mTransferable; // nsDataObjCollection owns and ref counts nsITransferable,
// the nsITransferable does know anything about the nsDataObjCollection
@ -199,7 +200,7 @@ class nsDataObjCollection : public IDataObject, public nsIDataObjCollection //,
CEnumFormatEtc * m_enumFE; // Ownership Rules:
// nsDataObjCollection owns and ref counts CEnumFormatEtc,
nsVoidArray mDataObjects;
nsTPtrArray<IDataObject> mDataObjects;
};

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

@ -47,7 +47,6 @@
#include "nsAutoPtr.h"
#include "nsIWidget.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "nsIPrintSettingsWin.h"
@ -96,23 +95,23 @@ public:
void FreeGlobalPrinters();
PRBool PrintersAreAllocated() { return mPrinters != nsnull; }
LPTSTR GetItemFromList(PRInt32 aInx) { return mPrinters?(LPTSTR)mPrinters->ElementAt(aInx):nsnull; }
LPTSTR GetItemFromList(PRInt32 aInx) { return mPrinters?mPrinters->ElementAt(aInx):nsnull; }
nsresult EnumeratePrinterList();
void GetDefaultPrinterName(LPTSTR& aDefaultPrinterName);
PRInt32 GetNumPrinters() { return mPrinters?mPrinters->Count():0; }
PRInt32 GetNumPrinters() { return mPrinters?mPrinters->Length():0; }
protected:
GlobalPrinters() {}
nsresult EnumerateNativePrinters();
void ReallocatePrinters();
static GlobalPrinters mGlobalPrinters;
static nsVoidArray* mPrinters;
static GlobalPrinters mGlobalPrinters;
static nsTArray<LPTSTR>* mPrinters;
};
//---------------
// static members
GlobalPrinters GlobalPrinters::mGlobalPrinters;
nsVoidArray* GlobalPrinters::mPrinters = nsnull;
GlobalPrinters GlobalPrinters::mGlobalPrinters;
nsTArray<LPTSTR>* GlobalPrinters::mPrinters = nsnull;
//******************************************************
@ -979,7 +978,7 @@ GlobalPrinters::ReallocatePrinters()
if (PrintersAreAllocated()) {
FreeGlobalPrinters();
}
mPrinters = new nsVoidArray();
mPrinters = new nsTArray<LPTSTR>();
NS_ASSERTION(mPrinters, "Printers Array is NULL!");
}
@ -988,8 +987,8 @@ void
GlobalPrinters::FreeGlobalPrinters()
{
if (mPrinters != nsnull) {
for (int i=0;i<mPrinters->Count();i++) {
free((LPTSTR)mPrinters->ElementAt(i));
for (int i=0;i<mPrinters->Length();i++) {
free(mPrinters->ElementAt(i));
}
delete mPrinters;
mPrinters = nsnull;
@ -1078,13 +1077,13 @@ GlobalPrinters::EnumeratePrinterList()
// put the default printer at the beginning of list
if (defPrinterName != nsnull) {
for (PRInt32 i=0;i<mPrinters->Count();i++) {
LPTSTR name = (LPTSTR)mPrinters->ElementAt(i);
for (PRInt32 i=0;i<mPrinters->Length();i++) {
LPTSTR name = mPrinters->ElementAt(i);
if (!_tcscmp(name, defPrinterName)) {
if (i > 0) {
LPTSTR ptr = (LPTSTR)mPrinters->ElementAt(0);
mPrinters->ReplaceElementAt((void*)name, 0);
mPrinters->ReplaceElementAt((void*)ptr, i);
LPTSTR ptr = mPrinters->ElementAt(0);
mPrinters->ElementAt(0) = name;
mPrinters->ElementAt(i) = ptr;
}
break;
}

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

@ -75,8 +75,8 @@ nsScreenManagerWin :: nsScreenManagerWin ( )
nsScreenManagerWin :: ~nsScreenManagerWin()
{
// walk our list of cached screens and delete them.
for ( int i = 0; i < mScreenList.Count(); ++i ) {
ScreenListItem* item = reinterpret_cast<ScreenListItem*>(mScreenList[i]);
for ( int i = 0; i < mScreenList.Length(); ++i ) {
ScreenListItem* item = mScreenList[i];
delete item;
}
}
@ -101,8 +101,8 @@ nsScreenManagerWin :: CreateNewScreenObject ( void* inScreen )
// look through our screen list, hoping to find it. If it's not there,
// add it and return the new one.
for ( int i = 0; i < mScreenList.Count(); ++i ) {
ScreenListItem* curr = reinterpret_cast<ScreenListItem*>(mScreenList[i]);
for ( int i = 0; i < mScreenList.Length(); ++i ) {
ScreenListItem* curr = mScreenList[i];
if ( inScreen == curr->mMon ) {
NS_IF_ADDREF(retScreen = curr->mScreen.get());
return retScreen;

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

@ -42,10 +42,10 @@
#include <windows.h>
#include "nsCOMPtr.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
class nsIScreen;
class ScreenListItem;
//------------------------------------------------------------------------
@ -65,7 +65,7 @@ private:
PRUint32 mNumberOfScreens;
// cache the screens to avoid the memory allocations
nsAutoVoidArray mScreenList;
nsAutoTArray<ScreenListItem*, 8> mScreenList;
};

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

@ -54,7 +54,6 @@
#include "nsIEventListener.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
class nsNativeDragTarget;

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

@ -44,7 +44,6 @@
#include "nsIAppShell.h"
#include "nsILocalFile.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsCOMPtr.h"
#include "nsGUIEvent.h"

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

@ -48,7 +48,6 @@
#include "nsISupportsPrimitives.h"
#include "nsIWindowWatcher.h"
#include "nsIDOMWindowInternal.h"
#include "nsVoidArray.h"
#include "nsSupportsArray.h"
#include "prprf.h"

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

@ -50,7 +50,7 @@ Notes to self:
#include "nsTransferable.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "nsIFormatConverter.h"
#include "nsIComponentManager.h"
#include "nsCOMPtr.h"
@ -106,12 +106,11 @@ protected:
};
DataStruct* GetDataForFlavor (const nsVoidArray* pArray, const char* aDataFlavor);
DataStruct* GetDataForFlavor (const nsVoidArray* pArray, const char* aDataFlavor)
DataStruct* GetDataForFlavor (const nsTArray<DataStruct*>* pArray,
const char* aDataFlavor)
{
for (PRInt32 i = 0 ; i < pArray->Count () ; ++i) {
DataStruct* data = (DataStruct*)pArray->ElementAt (i);
for (PRUint32 i = 0 ; i < pArray->Length () ; ++i) {
DataStruct* data = pArray->ElementAt (i);
if (data->GetFlavor().Equals (aDataFlavor))
return data;
}
@ -295,7 +294,7 @@ DataStruct::ReadCache(nsISupports** aData, PRUint32* aDataLen)
//-------------------------------------------------------------------------
nsTransferable::nsTransferable()
{
mDataArray = new nsVoidArray();
mDataArray = new nsTArray<DataStruct*>();
}
//-------------------------------------------------------------------------
@ -305,8 +304,8 @@ nsTransferable::nsTransferable()
//-------------------------------------------------------------------------
nsTransferable::~nsTransferable()
{
for (PRInt32 i=0;i<mDataArray->Count();i++) {
DataStruct * data = (DataStruct *)mDataArray->ElementAt(i);
for (PRUint32 i=0;i<mDataArray->Length();i++) {
DataStruct * data = mDataArray->ElementAt(i);
delete data;
}
delete mDataArray;
@ -326,8 +325,8 @@ nsTransferable::GetTransferDataFlavors(nsISupportsArray ** aDataFlavorList)
nsresult rv = NS_NewISupportsArray ( aDataFlavorList );
if (NS_FAILED(rv)) return rv;
for ( PRInt32 i=0; i<mDataArray->Count(); ++i ) {
DataStruct * data = (DataStruct *)mDataArray->ElementAt(i);
for ( PRUint32 i=0; i<mDataArray->Length(); ++i ) {
DataStruct * data = mDataArray->ElementAt(i);
nsCOMPtr<nsISupportsCString> flavorWrapper = do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID);
if ( flavorWrapper ) {
flavorWrapper->SetData ( data->GetFlavor() );
@ -355,9 +354,9 @@ nsTransferable::GetTransferData(const char *aFlavor, nsISupports **aData, PRUint
nsresult rv = NS_OK;
// first look and see if the data is present in one of the intrinsic flavors
PRInt32 i;
for (i = 0; i < mDataArray->Count(); ++i ) {
DataStruct * data = (DataStruct *)mDataArray->ElementAt(i);
PRUint32 i;
for (i = 0; i < mDataArray->Length(); ++i ) {
DataStruct * data = mDataArray->ElementAt(i);
if ( data->GetFlavor().Equals(aFlavor) ) {
data->GetData(aData, aDataLen);
if (*aDataLen == kFlavorHasDataProvider) {
@ -380,8 +379,8 @@ nsTransferable::GetTransferData(const char *aFlavor, nsISupports **aData, PRUint
// if not, try using a format converter to get the requested flavor
if ( mFormatConv ) {
for (i = 0; i < mDataArray->Count(); ++i) {
DataStruct * data = (DataStruct *)mDataArray->ElementAt(i);
for (i = 0; i < mDataArray->Length(); ++i) {
DataStruct * data = mDataArray->ElementAt(i);
PRBool canConvert = PR_FALSE;
mFormatConv->CanConvert(data->GetFlavor().get(), aFlavor, &canConvert);
if ( canConvert ) {
@ -418,8 +417,8 @@ nsTransferable::GetAnyTransferData(char **aFlavor, nsISupports **aData, PRUint32
{
NS_ENSURE_ARG_POINTER(aFlavor && aData && aDataLen);
for ( PRInt32 i=0; i < mDataArray->Count(); ++i ) {
DataStruct * data = (DataStruct *)mDataArray->ElementAt(i);
for ( PRUint32 i=0; i < mDataArray->Length(); ++i ) {
DataStruct * data = mDataArray->ElementAt(i);
if (data->IsDataAvailable()) {
*aFlavor = ToNewCString(data->GetFlavor());
data->GetData(aData, aDataLen);
@ -442,9 +441,9 @@ nsTransferable::SetTransferData(const char *aFlavor, nsISupports *aData, PRUint3
NS_ENSURE_ARG(aFlavor);
// first check our intrinsic flavors to see if one has been registered.
PRInt32 i = 0;
for (i = 0; i < mDataArray->Count(); ++i) {
DataStruct * data = (DataStruct *)mDataArray->ElementAt(i);
PRUint32 i = 0;
for (i = 0; i < mDataArray->Length(); ++i) {
DataStruct * data = mDataArray->ElementAt(i);
if ( data->GetFlavor().Equals(aFlavor) ) {
data->SetData ( aData, aDataLen );
return NS_OK;
@ -453,8 +452,8 @@ nsTransferable::SetTransferData(const char *aFlavor, nsISupports *aData, PRUint3
// if not, try using a format converter to find a flavor to put the data in
if ( mFormatConv ) {
for (i = 0; i < mDataArray->Count(); ++i) {
DataStruct * data = (DataStruct *)mDataArray->ElementAt(i);
for (i = 0; i < mDataArray->Length(); ++i) {
DataStruct * data = mDataArray->ElementAt(i);
PRBool canConvert = PR_FALSE;
mFormatConv->CanConvert(aFlavor, data->GetFlavor().get(), &canConvert);
@ -490,7 +489,7 @@ nsTransferable::AddDataFlavor(const char *aDataFlavor)
// Create a new "slot" for the data
DataStruct * data = new DataStruct ( aDataFlavor ) ;
mDataArray->AppendElement((void *)data);
mDataArray->AppendElement(data);
return NS_OK;
}

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

@ -41,13 +41,11 @@
#include "nsIFormatConverter.h"
#include "nsITransferable.h"
#include "nsCOMPtr.h"
#include "nsTArray.h"
class nsVoidArray;
class nsString;
class nsDataObj;
class nsVoidArray;
class DataStruct;
/**
* XP Transferable wrapper
@ -69,7 +67,7 @@ protected:
// get flavors w/out converter
nsresult GetTransferDataFlavors(nsISupportsArray** aDataFlavorList);
nsVoidArray * mDataArray;
nsTArray<DataStruct*> * mDataArray;
nsCOMPtr<nsIFormatConverter> mFormatConv;
};