Moved some methods/classes inside COMPATIBILITY_2_4.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21616 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon
2003-07-03 21:59:55 +00:00
parent 2ea4a2f552
commit ba8c160144
19 changed files with 132 additions and 52 deletions

View File

@@ -21,7 +21,11 @@ versions, please update your code to not use them.
- wxList::Number, First, Last, Nth: use GetCount, GetFirst/Last, Item instead - wxList::Number, First, Last, Nth: use GetCount, GetFirst/Last, Item instead
- wxNode::Next, Previous, Data: use GetNext, GetPrevious, GetData instead - wxNode::Next, Previous, Data: use GetNext, GetPrevious, GetData instead
- wxListBase::operator wxList&(): use typesafe lists instead - wxListBase::operator wxList&(): use typesafe lists instead
- wxTheFontMapper, use wxFontMapper::Get() instead - wxTheFontMapper: use wxFontMapper::Get() instead
- wxStringHashTable: use wxHashMap instead
- wxHashTableLong: use wxHashMap instead
- wxArrayString::GetStringArray: no replacement
- wxArrayString::Remove(index, count): use RemoveAt instead
OTHER CHANGES OTHER CHANGES

View File

@@ -22,6 +22,7 @@
#include "wx/help.h" #include "wx/help.h"
#include "wx/hashmap.h"
#if wxUSE_BMPBUTTON #if wxUSE_BMPBUTTON
#include "wx/bmpbuttn.h" #include "wx/bmpbuttn.h"
#endif #endif
@@ -140,6 +141,9 @@ private:
static wxHelpProvider *ms_helpProvider; static wxHelpProvider *ms_helpProvider;
}; };
WX_DECLARE_HASH_MAP( long, wxString, wxIntegerHash, wxIntegerEqual,
wxLongToStringHashMap );
// wxSimpleHelpProvider is an implementation of wxHelpProvider which supports // wxSimpleHelpProvider is an implementation of wxHelpProvider which supports
// only plain text help strings and shows the string associated with the // only plain text help strings and shows the string associated with the
// control (if any) in a tooltip // control (if any) in a tooltip
@@ -156,8 +160,8 @@ public:
protected: protected:
// we use 2 hashes for storing the help strings associated with windows // we use 2 hashes for storing the help strings associated with windows
// and the ids // and the ids
wxStringHashTable m_hashWindows, wxLongToStringHashMap m_hashWindows,
m_hashIds; m_hashIds;
}; };
// wxHelpControllerHelpProvider is an implementation of wxHelpProvider which supports // wxHelpControllerHelpProvider is an implementation of wxHelpProvider which supports

View File

@@ -24,7 +24,7 @@
#include "wx/filesys.h" #include "wx/filesys.h"
class WXDLLIMPEXP_BASE wxHashTableLong; class WXDLLIMPEXP_BASE wxLongToLongHashMap;
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// wxZipFSHandler // wxZipFSHandler
@@ -45,7 +45,7 @@ class WXDLLIMPEXP_BASE wxZipFSHandler : public wxFileSystemHandler
void *m_Archive; void *m_Archive;
wxString m_Pattern, m_BaseDir, m_ZipFile; wxString m_Pattern, m_BaseDir, m_ZipFile;
bool m_AllowDirs, m_AllowFiles; bool m_AllowDirs, m_AllowFiles;
wxHashTableLong *m_DirsFound; wxLongToLongHashMap *m_DirsFound;
wxString DoFind(); wxString DoFind();

View File

@@ -18,7 +18,7 @@
#pragma interface "grid.h" #pragma interface "grid.h"
#endif #endif
#include "wx/hash.h" #include "wx/hashmap.h"
#include "wx/panel.h" #include "wx/panel.h"
#include "wx/scrolwin.h" #include "wx/scrolwin.h"
#include "wx/string.h" #include "wx/string.h"
@@ -80,6 +80,9 @@ class WXDLLEXPORT wxComboBox;
class WXDLLEXPORT wxTextCtrl; class WXDLLEXPORT wxTextCtrl;
class WXDLLEXPORT wxSpinCtrl; class WXDLLEXPORT wxSpinCtrl;
WX_DECLARE_EXPORTED_HASH_MAP( long, long, wxIntegerHash, wxIntegerEqual,
wxLongToLongHashMap );
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// macros // macros
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1759,8 +1762,8 @@ protected:
// if a column has a minimal width, it will be the value for it in this // if a column has a minimal width, it will be the value for it in this
// hash table // hash table
wxHashTableLong m_colMinWidths, wxLongToLongHashMap m_colMinWidths,
m_rowMinHeights; m_rowMinHeights;
// get the minimal width of the given column/row // get the minimal width of the given column/row
int GetColMinimalWidth(int col) const; int GetColMinimalWidth(int col) const;

View File

@@ -72,6 +72,8 @@ private:
DECLARE_NO_COPY_CLASS(wxHashTableBase) DECLARE_NO_COPY_CLASS(wxHashTableBase)
}; };
#if WXWIN_COMPATIBILITY_2_4
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// a hash table which stores longs // a hash table which stores longs
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -143,6 +145,8 @@ private:
DECLARE_NO_COPY_CLASS(wxStringHashTable) DECLARE_NO_COPY_CLASS(wxStringHashTable)
}; };
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// for compatibility only // for compatibility only
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -305,5 +309,23 @@ private:
#define WX_DECLARE_USER_EXPORTED_HASH(el, list, hash, usergoo) \ #define WX_DECLARE_USER_EXPORTED_HASH(el, list, hash, usergoo) \
_WX_DECLARE_HASH(el, list, hash, class usergoo) _WX_DECLARE_HASH(el, list, hash, class usergoo)
// delete all hash elements
//
// NB: the class declaration of the hash elements must be visible from the
// place where you use this macro, otherwise the proper destructor may not
// be called (a decent compiler should give a warning about it, but don't
// count on it)!
#define WX_CLEAR_HASH_TABLE(array) \
{ \
(array).BeginFind(); \
wxNode* it = (array).Next(); \
while( it ) \
{ \
delete it->GetData(); \
it = (array).Next(); \
} \
(array).Clear(); \
}
#endif #endif
// _WX_HASH_H__ // _WX_HASH_H__

View File

@@ -1027,12 +1027,19 @@ public:
// from the array (operator[] or Item() method), a reference is returned. // from the array (operator[] or Item() method), a reference is returned.
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
int WXDLLIMPEXP_BASE wxStringSortAscending(wxString*, wxString*);
int WXDLLIMPEXP_BASE wxStringSortDescending(wxString*, wxString*);
class WXDLLIMPEXP_BASE wxArrayString class WXDLLIMPEXP_BASE wxArrayString
{ {
public: public:
// type of function used by wxArrayString::Sort() // type of function used by wxArrayString::Sort()
typedef int (*CompareFunction)(const wxString& first, typedef int (*CompareFunction)(const wxString& first,
const wxString& second); const wxString& second);
// type of function used by wxArrayString::Sort(), for compatibility with
// wxArray
typedef int (*CompareFunction2)(wxString* first,
wxString* second);
// constructors and destructor // constructors and destructor
// default ctor // default ctor
@@ -1095,11 +1102,13 @@ public:
return Item(Count() - 1); return Item(Count() - 1);
} }
#if WXWIN_COMPATIBILITY_2_4
// return a wxString[], useful for the controls which // return a wxString[], useful for the controls which
// take one in their ctor. You must delete[] it yourself // take one in their ctor. You must delete[] it yourself
// once you are done with it. Will return NULL if the // once you are done with it. Will return NULL if the
// ArrayString was empty. // ArrayString was empty.
wxString* GetStringArray() const; wxString* GetStringArray() const;
#endif
// item management // item management
// Search the element in the array, starting from the beginning if // Search the element in the array, starting from the beginning if
@@ -1117,8 +1126,10 @@ public:
// remove first item matching this value // remove first item matching this value
void Remove(const wxChar *sz); void Remove(const wxChar *sz);
// remove item by index // remove item by index
void Remove(size_t nIndex, size_t nRemove = 1); #if WXWIN_COMPATIBILITY_2_4
void RemoveAt(size_t nIndex, size_t nRemove = 1) { Remove(nIndex, nRemove); } void Remove(size_t nIndex, size_t nRemove = 1) { RemoveAt(nIndex, nRemove); }
#endif
void RemoveAt(size_t nIndex, size_t nRemove = 1);
// sorting // sorting
// sort array elements in alphabetical order (or reversed alphabetical // sort array elements in alphabetical order (or reversed alphabetical
@@ -1126,6 +1137,7 @@ public:
void Sort(bool reverseOrder = FALSE); void Sort(bool reverseOrder = FALSE);
// sort array elements using specified comparaison function // sort array elements using specified comparaison function
void Sort(CompareFunction compareFunction); void Sort(CompareFunction compareFunction);
void Sort(CompareFunction2 compareFunction);
// comparison // comparison
// compare two arrays case sensitively // compare two arrays case sensitively

View File

@@ -409,7 +409,7 @@ void wxSplitPath(wxArrayString& aParts, const wxChar *sz)
if ( aParts.IsEmpty() ) if ( aParts.IsEmpty() )
wxLogWarning(_("'%s' has extra '..', ignored."), sz); wxLogWarning(_("'%s' has extra '..', ignored."), sz);
else else
aParts.Remove(aParts.Count() - 1); aParts.RemoveAt(aParts.Count() - 1);
strCurrent.Empty(); strCurrent.Empty();
} }

View File

@@ -326,30 +326,34 @@ wxHelpProvider::~wxHelpProvider()
wxString wxSimpleHelpProvider::GetHelp(const wxWindowBase *window) wxString wxSimpleHelpProvider::GetHelp(const wxWindowBase *window)
{ {
bool wasFound; wxLongToStringHashMap::iterator it = m_hashWindows.find((long)window);
wxString text = m_hashWindows.Get((long)window, &wasFound);
if ( !wasFound )
text = m_hashIds.Get(window->GetId());
return text; if ( it == m_hashWindows.end() )
{
it = m_hashIds.find(window->GetId());
if ( it == m_hashIds.end() )
return wxEmptyString;
}
return it->second;
} }
void wxSimpleHelpProvider::AddHelp(wxWindowBase *window, const wxString& text) void wxSimpleHelpProvider::AddHelp(wxWindowBase *window, const wxString& text)
{ {
m_hashWindows.Delete((long)window); m_hashWindows.erase((long)window);
m_hashWindows.Put((long)window, text); m_hashWindows[(long)window] = text;
} }
void wxSimpleHelpProvider::AddHelp(wxWindowID id, const wxString& text) void wxSimpleHelpProvider::AddHelp(wxWindowID id, const wxString& text)
{ {
m_hashIds.Delete((long)id); m_hashIds.erase((long)id);
m_hashIds.Put(id, text); m_hashIds[id] = text;
} }
// removes the association // removes the association
void wxSimpleHelpProvider::RemoveHelp(wxWindowBase* window) void wxSimpleHelpProvider::RemoveHelp(wxWindowBase* window)
{ {
m_hashWindows.Delete((long)window); m_hashWindows.erase((long)window);
} }
bool wxSimpleHelpProvider::ShowHelp(wxWindowBase *window) bool wxSimpleHelpProvider::ShowHelp(wxWindowBase *window)

View File

@@ -1140,7 +1140,7 @@ void wxFileName::InsertDir( int before, const wxString &dir )
void wxFileName::RemoveDir( int pos ) void wxFileName::RemoveDir( int pos )
{ {
m_dirs.Remove( (size_t)pos ); m_dirs.RemoveAt( (size_t)pos );
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -26,7 +26,7 @@
#include "wx/log.h" #include "wx/log.h"
#endif #endif
#include "wx/hash.h" #include "wx/hashmap.h"
#include "wx/filesys.h" #include "wx/filesys.h"
#include "wx/zipstrm.h" #include "wx/zipstrm.h"
#include "wx/fs_zip.h" #include "wx/fs_zip.h"
@@ -38,6 +38,8 @@
#include "unzip.h" #include "unzip.h"
#endif #endif
WX_DECLARE_EXPORTED_HASH_MAP( long, long, wxIntegerHash, wxIntegerEqual,
wxLongToLongHashMap );
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// wxZipFSHandler // wxZipFSHandler
@@ -165,7 +167,7 @@ wxString wxZipFSHandler::FindFirst(const wxString& spec, int flags)
if (m_AllowDirs) if (m_AllowDirs)
{ {
delete m_DirsFound; delete m_DirsFound;
m_DirsFound = new wxHashTableLong(); m_DirsFound = new wxLongToLongHashMap();
} }
return DoFind(); return DoFind();
} }
@@ -203,9 +205,10 @@ wxString wxZipFSHandler::DoFind()
{ {
long key = 0; long key = 0;
for (size_t i = 0; i < dir.Length(); i++) key += (wxUChar)dir[i]; for (size_t i = 0; i < dir.Length(); i++) key += (wxUChar)dir[i];
if (m_DirsFound->Get(key) == wxNOT_FOUND) wxLongToLongHashMap::iterator it = m_DirsFound->find(key);
if (it == m_DirsFound->end())
{ {
m_DirsFound->Put(key, 1); m_DirsFound[key] = 1;
filename = dir.AfterLast(wxT('/')); filename = dir.AfterLast(wxT('/'));
dir = dir.BeforeLast(wxT('/')); dir = dir.BeforeLast(wxT('/'));
if (!filename.IsEmpty() && m_BaseDir == dir && if (!filename.IsEmpty() && m_BaseDir == dir &&

View File

@@ -119,6 +119,8 @@ wxNodeBase *wxHashTableBase::GetNode(long key, long value) const
return node; return node;
} }
#if WXWIN_COMPATIBILITY_2_4
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxHashTableLong // wxHashTableLong
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -334,6 +336,8 @@ bool wxStringHashTable::Delete(long key) const
return FALSE; return FALSE;
} }
#endif // WXWIN_COMPATIBILITY_2_4
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// old not type safe wxHashTable // old not type safe wxHashTable
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -1906,6 +1906,8 @@ void wxArrayString::Shrink()
} }
} }
#if WXWIN_COMPATIBILITY_2_4
// return a wxString[] as required for some control ctors. // return a wxString[] as required for some control ctors.
wxString* wxArrayString::GetStringArray() const wxString* wxArrayString::GetStringArray() const
{ {
@@ -1921,6 +1923,8 @@ wxString* wxArrayString::GetStringArray() const
return array; return array;
} }
#endif // WXWIN_COMPATIBILITY_2_4
// searches the array for an item (forward or backwards) // searches the array for an item (forward or backwards)
int wxArrayString::Index(const wxChar *sz, bool bCase, bool bFromEnd) const int wxArrayString::Index(const wxChar *sz, bool bCase, bool bFromEnd) const
{ {
@@ -2051,7 +2055,7 @@ void wxArrayString::SetCount(size_t count)
} }
// removes item from array (by index) // removes item from array (by index)
void wxArrayString::Remove(size_t nIndex, size_t nRemove) void wxArrayString::RemoveAt(size_t nIndex, size_t nRemove)
{ {
wxCHECK_RET( nIndex < m_nCount, wxT("bad index in wxArrayString::Remove") ); wxCHECK_RET( nIndex < m_nCount, wxT("bad index in wxArrayString::Remove") );
wxCHECK_RET( nIndex + nRemove <= m_nCount, wxCHECK_RET( nIndex + nRemove <= m_nCount,
@@ -2074,7 +2078,7 @@ void wxArrayString::Remove(const wxChar *sz)
wxCHECK_RET( iIndex != wxNOT_FOUND, wxCHECK_RET( iIndex != wxNOT_FOUND,
wxT("removing inexistent element in wxArrayString::Remove") ); wxT("removing inexistent element in wxArrayString::Remove") );
Remove(iIndex); RemoveAt(iIndex);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -2142,18 +2146,22 @@ void wxArrayString::Sort(CompareFunction compareFunction)
END_SORT(); END_SORT();
} }
typedef int (wxC_CALLING_CONV * wxStringCompareFn)(const void *first, const void *second);
void wxArrayString::Sort(CompareFunction2 compareFunction)
{
qsort(m_pItems, m_nCount, sizeof(wxChar *), (wxStringCompareFn)compareFunction);
}
#if WXWIN_COMPATIBILITY_2_4
void wxArrayString::Sort(bool reverseOrder) void wxArrayString::Sort(bool reverseOrder)
{ {
START_SORT(); Sort(reverseOrder ? wxStringSortDescending : wxStringSortAscending);
wxASSERT( !gs_compareFunction ); // must have been reset to NULL
gs_sortAscending = !reverseOrder;
DoSort();
END_SORT();
} }
#endif // WXWIN_COMPATIBILITY_2_4
void wxArrayString::DoSort() void wxArrayString::DoSort()
{ {
wxCHECK_RET( !m_autoSort, wxT("can't use this method with sorted arrays") ); wxCHECK_RET( !m_autoSort, wxT("can't use this method with sorted arrays") );
@@ -2177,3 +2185,12 @@ bool wxArrayString::operator==(const wxArrayString& a) const
return TRUE; return TRUE;
} }
int wxStringSortAscending(wxString* s1, wxString* s2)
{
return wxStrcmp(s1->c_str(), s2->c_str());
}
int wxStringSortDescending(wxString* s1, wxString* s2)
{
return -wxStrcmp(s1->c_str(), s2->c_str());
}

View File

@@ -9377,27 +9377,27 @@ void wxGrid::SetColSize( int col, int width )
void wxGrid::SetColMinimalWidth( int col, int width ) void wxGrid::SetColMinimalWidth( int col, int width )
{ {
if (width > GetColMinimalAcceptableWidth()) { if (width > GetColMinimalAcceptableWidth()) {
m_colMinWidths.Put(col, width); m_colMinWidths[col] = width;
} }
} }
void wxGrid::SetRowMinimalHeight( int row, int width ) void wxGrid::SetRowMinimalHeight( int row, int width )
{ {
if (width > GetRowMinimalAcceptableHeight()) { if (width > GetRowMinimalAcceptableHeight()) {
m_rowMinHeights.Put(row, width); m_rowMinHeights[row] = width;
} }
} }
int wxGrid::GetColMinimalWidth(int col) const int wxGrid::GetColMinimalWidth(int col) const
{ {
long value = m_colMinWidths.Get(col); wxLongToLongHashMap::const_iterator it = m_colMinWidths.find(col);
return value != wxNOT_FOUND ? (int)value : m_minAcceptableColWidth; return it != m_colMinWidths.end() ? (int)it->second : m_minAcceptableColWidth;
} }
int wxGrid::GetRowMinimalHeight(int row) const int wxGrid::GetRowMinimalHeight(int row) const
{ {
long value = m_rowMinHeights.Get(row); wxLongToLongHashMap::const_iterator it = m_rowMinHeights.find(row);
return value != wxNOT_FOUND ? (int)value : m_minAcceptableRowHeight; return it != m_rowMinHeights.end() ? (int)it->second : m_minAcceptableRowHeight;
} }
void wxGrid::SetColMinimalAcceptableWidth( int width ) void wxGrid::SetColMinimalAcceptableWidth( int width )

View File

@@ -657,7 +657,7 @@ void wxListBox::Delete( int n )
} }
if ( m_strings ) if ( m_strings )
m_strings->Remove(n); m_strings->RemoveAt(n);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -657,7 +657,7 @@ void wxListBox::Delete( int n )
} }
if ( m_strings ) if ( m_strings )
m_strings->Remove(n); m_strings->RemoveAt(n);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -496,7 +496,11 @@ wxHtmlHelpFrame::~wxHtmlHelpFrame()
delete m_Data; delete m_Data;
if (m_NormalFonts) delete m_NormalFonts; if (m_NormalFonts) delete m_NormalFonts;
if (m_FixedFonts) delete m_FixedFonts; if (m_FixedFonts) delete m_FixedFonts;
if (m_PagesHash) delete m_PagesHash; if (m_PagesHash)
{
WX_CLEAR_HASH_TABLE(*m_PagesHash);
delete m_PagesHash;
}
} }
@@ -719,9 +723,12 @@ void wxHtmlHelpFrame::CreateContents()
m_ContentsBox->Clear(); m_ContentsBox->Clear();
if (m_PagesHash) delete m_PagesHash; if (m_PagesHash)
{
WX_CLEAR_HASH_TABLE(*m_PagesHash);
delete m_PagesHash;
}
m_PagesHash = new wxHashTable(wxKEY_STRING, 2 * m_Data->GetContentsCnt()); m_PagesHash = new wxHashTable(wxKEY_STRING, 2 * m_Data->GetContentsCnt());
m_PagesHash->DeleteContents(TRUE);
int cnt = m_Data->GetContentsCnt(); int cnt = m_Data->GetContentsCnt();
int i; int i;
@@ -1310,8 +1317,8 @@ void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
pos = m_BookmarksNames.Index(item); pos = m_BookmarksNames.Index(item);
if (pos != wxNOT_FOUND) if (pos != wxNOT_FOUND)
{ {
m_BookmarksNames.Remove(pos); m_BookmarksNames.RemoveAt(pos);
m_BookmarksPages.Remove(pos); m_BookmarksPages.RemoveAt(pos);
m_Bookmarks->Delete(m_Bookmarks->GetSelection()); m_Bookmarks->Delete(m_Bookmarks->GetSelection());
} }
} }

View File

@@ -316,7 +316,7 @@ wxMenu *wxMenuBar::Remove(size_t pos)
menu->SetMenuBar(NULL); menu->SetMenuBar(NULL);
m_titles.Remove(pos); m_titles.RemoveAt(pos);
return menu; return menu;
} }

View File

@@ -799,7 +799,7 @@ wxMenu *wxMenuBar::Remove(size_t pos)
Refresh(); Refresh();
} }
m_titles.Remove(pos); m_titles.RemoveAt(pos);
return menu; return menu;
} }

View File

@@ -354,7 +354,7 @@ static bool BuildRemoteList(wxArrayString& list, NETRESOURCE* pResSrc,
{ {
// Found the element. Remove it or mark it mounted. // Found the element. Remove it or mark it mounted.
if (flagsUnset & wxFS_VOL_MOUNTED) if (flagsUnset & wxFS_VOL_MOUNTED)
list.Remove(iList); list.RemoveAt(iList);
else else
s_fileInfo[list[iList]].m_flags |= wxFS_VOL_MOUNTED; s_fileInfo[list[iList]].m_flags |= wxFS_VOL_MOUNTED;