From ba8c1601448fa16d64c4e75a095f1cb037909c5b Mon Sep 17 00:00:00 2001
From: Mattia Barbon <mbarbon@cpan.org>
Date: Thu, 3 Jul 2003 21:59:55 +0000
Subject: [PATCH]   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
---
 docs/changes.txt          |  6 +++++-
 include/wx/cshelp.h       |  8 ++++++--
 include/wx/fs_zip.h       |  4 ++--
 include/wx/generic/grid.h |  9 ++++++---
 include/wx/hash.h         | 22 ++++++++++++++++++++++
 include/wx/string.h       | 16 ++++++++++++++--
 src/common/config.cpp     |  2 +-
 src/common/cshelp.cpp     | 24 ++++++++++++++----------
 src/common/filename.cpp   |  2 +-
 src/common/fs_zip.cpp     | 11 +++++++----
 src/common/hash.cpp       |  4 ++++
 src/common/string.cpp     | 35 ++++++++++++++++++++++++++---------
 src/generic/grid.cpp      | 12 ++++++------
 src/gtk/listbox.cpp       |  2 +-
 src/gtk1/listbox.cpp      |  2 +-
 src/html/helpfrm.cpp      | 17 ++++++++++++-----
 src/motif/menu.cpp        |  2 +-
 src/msw/menu.cpp          |  2 +-
 src/msw/volume.cpp        |  2 +-
 19 files changed, 131 insertions(+), 51 deletions(-)

diff --git a/docs/changes.txt b/docs/changes.txt
index 2b9b5340c6..d8c86d74e3 100644
--- a/docs/changes.txt
+++ b/docs/changes.txt
@@ -21,7 +21,11 @@ versions, please update your code to not use them.
 - wxList::Number, First, Last, Nth: use GetCount, GetFirst/Last, Item instead
 - wxNode::Next, Previous, Data: use GetNext, GetPrevious, GetData 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
diff --git a/include/wx/cshelp.h b/include/wx/cshelp.h
index ecad164325..99169934b1 100644
--- a/include/wx/cshelp.h
+++ b/include/wx/cshelp.h
@@ -22,6 +22,7 @@
 
 #include "wx/help.h"
 
+#include "wx/hashmap.h"
 #if wxUSE_BMPBUTTON
 #include "wx/bmpbuttn.h"
 #endif
@@ -140,6 +141,9 @@ private:
     static wxHelpProvider *ms_helpProvider;
 };
 
+WX_DECLARE_HASH_MAP( long, wxString, wxIntegerHash, wxIntegerEqual,
+                     wxLongToStringHashMap );
+
 // wxSimpleHelpProvider is an implementation of wxHelpProvider which supports
 // only plain text help strings and shows the string associated with the
 // control (if any) in a tooltip
@@ -156,8 +160,8 @@ public:
 protected:
     // we use 2 hashes for storing the help strings associated with windows
     // and the ids
-    wxStringHashTable m_hashWindows,
-                     m_hashIds;
+    wxLongToStringHashMap m_hashWindows,
+                          m_hashIds;
 };
 
 // wxHelpControllerHelpProvider is an implementation of wxHelpProvider which supports
diff --git a/include/wx/fs_zip.h b/include/wx/fs_zip.h
index 1687d56655..938a091e5e 100644
--- a/include/wx/fs_zip.h
+++ b/include/wx/fs_zip.h
@@ -24,7 +24,7 @@
 
 #include "wx/filesys.h"
 
-class WXDLLIMPEXP_BASE wxHashTableLong;
+class WXDLLIMPEXP_BASE wxLongToLongHashMap;
 
 //--------------------------------------------------------------------------------
 // wxZipFSHandler
@@ -45,7 +45,7 @@ class WXDLLIMPEXP_BASE wxZipFSHandler : public wxFileSystemHandler
         void *m_Archive;
         wxString m_Pattern, m_BaseDir, m_ZipFile;
         bool m_AllowDirs, m_AllowFiles;
-        wxHashTableLong *m_DirsFound;
+        wxLongToLongHashMap *m_DirsFound;
 
         wxString DoFind();
 
diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h
index 95cc40e022..5f4aa749af 100644
--- a/include/wx/generic/grid.h
+++ b/include/wx/generic/grid.h
@@ -18,7 +18,7 @@
 #pragma interface "grid.h"
 #endif
 
-#include "wx/hash.h"
+#include "wx/hashmap.h"
 #include "wx/panel.h"
 #include "wx/scrolwin.h"
 #include "wx/string.h"
@@ -80,6 +80,9 @@ class WXDLLEXPORT wxComboBox;
 class WXDLLEXPORT wxTextCtrl;
 class WXDLLEXPORT wxSpinCtrl;
 
+WX_DECLARE_EXPORTED_HASH_MAP( long, long, wxIntegerHash, wxIntegerEqual,
+                              wxLongToLongHashMap );
+
 // ----------------------------------------------------------------------------
 // macros
 // ----------------------------------------------------------------------------
@@ -1759,8 +1762,8 @@ protected:
 
     // if a column has a minimal width, it will be the value for it in this
     // hash table
-    wxHashTableLong m_colMinWidths,
-                    m_rowMinHeights;
+    wxLongToLongHashMap m_colMinWidths,
+                        m_rowMinHeights;
 
     // get the minimal width of the given column/row
     int GetColMinimalWidth(int col) const;
diff --git a/include/wx/hash.h b/include/wx/hash.h
index b88d1648df..5ac029b01e 100644
--- a/include/wx/hash.h
+++ b/include/wx/hash.h
@@ -72,6 +72,8 @@ private:
     DECLARE_NO_COPY_CLASS(wxHashTableBase)
 };
 
+#if WXWIN_COMPATIBILITY_2_4
+
 // ----------------------------------------------------------------------------
 // a hash table which stores longs
 // ----------------------------------------------------------------------------
@@ -143,6 +145,8 @@ private:
     DECLARE_NO_COPY_CLASS(wxStringHashTable)
 };
 
+#endif
+
 // ----------------------------------------------------------------------------
 // for compatibility only
 // ----------------------------------------------------------------------------
@@ -305,5 +309,23 @@ private:
 #define WX_DECLARE_USER_EXPORTED_HASH(el, list, hash, 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
     // _WX_HASH_H__
diff --git a/include/wx/string.h b/include/wx/string.h
index 289b8d1d11..8c8379b0db 100644
--- a/include/wx/string.h
+++ b/include/wx/string.h
@@ -1027,12 +1027,19 @@ public:
 // 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
 {
 public:
   // type of function used by wxArrayString::Sort()
   typedef int (*CompareFunction)(const wxString& first,
                                  const wxString& second);
+  // type of function used by wxArrayString::Sort(), for compatibility with
+  // wxArray
+  typedef int (*CompareFunction2)(wxString* first,
+                                  wxString* second);
 
   // constructors and destructor
     // default ctor
@@ -1095,11 +1102,13 @@ public:
       return Item(Count() - 1);
   }
 
+#if WXWIN_COMPATIBILITY_2_4
     // return a wxString[], useful for the controls which
     // take one in their ctor.  You must delete[] it yourself
     // once you are done with it.  Will return NULL if the
     // ArrayString was empty.
   wxString* GetStringArray() const;
+#endif
 
   // item management
     // Search the element in the array, starting from the beginning if
@@ -1117,8 +1126,10 @@ public:
     // remove first item matching this value
   void Remove(const wxChar *sz);
     // remove item by index
-  void Remove(size_t nIndex, size_t nRemove = 1);
-  void RemoveAt(size_t nIndex, size_t nRemove = 1) { Remove(nIndex, nRemove); }
+#if WXWIN_COMPATIBILITY_2_4
+  void Remove(size_t nIndex, size_t nRemove = 1) { RemoveAt(nIndex, nRemove); }
+#endif
+  void RemoveAt(size_t nIndex, size_t nRemove = 1);
 
   // sorting
     // sort array elements in alphabetical order (or reversed alphabetical
@@ -1126,6 +1137,7 @@ public:
   void Sort(bool reverseOrder = FALSE);
     // sort array elements using specified comparaison function
   void Sort(CompareFunction compareFunction);
+  void Sort(CompareFunction2 compareFunction);
 
   // comparison
     // compare two arrays case sensitively
diff --git a/src/common/config.cpp b/src/common/config.cpp
index 031b7e9fbb..664f34574c 100644
--- a/src/common/config.cpp
+++ b/src/common/config.cpp
@@ -409,7 +409,7 @@ void wxSplitPath(wxArrayString& aParts, const wxChar *sz)
         if ( aParts.IsEmpty() )
           wxLogWarning(_("'%s' has extra '..', ignored."), sz);
         else
-          aParts.Remove(aParts.Count() - 1);
+          aParts.RemoveAt(aParts.Count() - 1);
 
         strCurrent.Empty();
       }
diff --git a/src/common/cshelp.cpp b/src/common/cshelp.cpp
index 8071439665..17b26dae36 100644
--- a/src/common/cshelp.cpp
+++ b/src/common/cshelp.cpp
@@ -326,30 +326,34 @@ wxHelpProvider::~wxHelpProvider()
 
 wxString wxSimpleHelpProvider::GetHelp(const wxWindowBase *window)
 {
-    bool wasFound;
-    wxString text = m_hashWindows.Get((long)window, &wasFound);
-    if ( !wasFound )
-        text = m_hashIds.Get(window->GetId());
+    wxLongToStringHashMap::iterator it = m_hashWindows.find((long)window);
 
-    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)
 {
-    m_hashWindows.Delete((long)window);
-    m_hashWindows.Put((long)window, text);
+    m_hashWindows.erase((long)window);
+    m_hashWindows[(long)window] = text;
 }
 
 void wxSimpleHelpProvider::AddHelp(wxWindowID id, const wxString& text)
 {
-    m_hashIds.Delete((long)id);
-    m_hashIds.Put(id, text);
+    m_hashIds.erase((long)id);
+    m_hashIds[id] = text;
 }
 
 // removes the association
 void wxSimpleHelpProvider::RemoveHelp(wxWindowBase* window)
 {
-    m_hashWindows.Delete((long)window);
+    m_hashWindows.erase((long)window);
 }
 
 bool wxSimpleHelpProvider::ShowHelp(wxWindowBase *window)
diff --git a/src/common/filename.cpp b/src/common/filename.cpp
index 82efd1a6ae..77d2f2fcab 100644
--- a/src/common/filename.cpp
+++ b/src/common/filename.cpp
@@ -1140,7 +1140,7 @@ void wxFileName::InsertDir( int before, const wxString &dir )
 
 void wxFileName::RemoveDir( int pos )
 {
-    m_dirs.Remove( (size_t)pos );
+    m_dirs.RemoveAt( (size_t)pos );
 }
 
 // ----------------------------------------------------------------------------
diff --git a/src/common/fs_zip.cpp b/src/common/fs_zip.cpp
index 4d9d3aa3c5..3e879ecfdd 100644
--- a/src/common/fs_zip.cpp
+++ b/src/common/fs_zip.cpp
@@ -26,7 +26,7 @@
     #include "wx/log.h"
 #endif
 
-#include "wx/hash.h"
+#include "wx/hashmap.h"
 #include "wx/filesys.h"
 #include "wx/zipstrm.h"
 #include "wx/fs_zip.h"
@@ -38,6 +38,8 @@
 #include "unzip.h"
 #endif
 
+WX_DECLARE_EXPORTED_HASH_MAP( long, long, wxIntegerHash, wxIntegerEqual,
+                              wxLongToLongHashMap );
 
 //----------------------------------------------------------------------------
 // wxZipFSHandler
@@ -165,7 +167,7 @@ wxString wxZipFSHandler::FindFirst(const wxString& spec, int flags)
             if (m_AllowDirs)
             {
                 delete m_DirsFound;
-                m_DirsFound = new wxHashTableLong();
+                m_DirsFound = new wxLongToLongHashMap();
             }
             return DoFind();
         }
@@ -203,9 +205,10 @@ wxString wxZipFSHandler::DoFind()
             {
                 long key = 0;
                 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('/'));
                     dir = dir.BeforeLast(wxT('/'));
                     if (!filename.IsEmpty() && m_BaseDir == dir &&
diff --git a/src/common/hash.cpp b/src/common/hash.cpp
index 9882539bb4..db2a5a141a 100644
--- a/src/common/hash.cpp
+++ b/src/common/hash.cpp
@@ -119,6 +119,8 @@ wxNodeBase *wxHashTableBase::GetNode(long key, long value) const
     return node;
 }
 
+#if WXWIN_COMPATIBILITY_2_4
+
 // ----------------------------------------------------------------------------
 // wxHashTableLong
 // ----------------------------------------------------------------------------
@@ -334,6 +336,8 @@ bool wxStringHashTable::Delete(long key) const
     return FALSE;
 }
 
+#endif // WXWIN_COMPATIBILITY_2_4
+
 // ----------------------------------------------------------------------------
 // old not type safe wxHashTable
 // ----------------------------------------------------------------------------
diff --git a/src/common/string.cpp b/src/common/string.cpp
index 25e4aa3de3..76251136ca 100644
--- a/src/common/string.cpp
+++ b/src/common/string.cpp
@@ -1906,6 +1906,8 @@ void wxArrayString::Shrink()
   }
 }
 
+#if WXWIN_COMPATIBILITY_2_4
+
 // return a wxString[] as required for some control ctors.
 wxString* wxArrayString::GetStringArray() const
 {
@@ -1921,6 +1923,8 @@ wxString* wxArrayString::GetStringArray() const
     return array;
 }
 
+#endif // WXWIN_COMPATIBILITY_2_4
+
 // searches the array for an item (forward or backwards)
 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)
-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 + nRemove <= m_nCount,
@@ -2074,7 +2078,7 @@ void wxArrayString::Remove(const wxChar *sz)
   wxCHECK_RET( iIndex != wxNOT_FOUND,
                wxT("removing inexistent element in wxArrayString::Remove") );
 
-  Remove(iIndex);
+  RemoveAt(iIndex);
 }
 
 // ----------------------------------------------------------------------------
@@ -2142,18 +2146,22 @@ void wxArrayString::Sort(CompareFunction compareFunction)
   END_SORT();
 }
 
-void wxArrayString::Sort(bool reverseOrder)
-{
-  START_SORT();
+typedef  int (wxC_CALLING_CONV * wxStringCompareFn)(const void *first, const void *second);
 
-  wxASSERT( !gs_compareFunction );  // must have been reset to NULL
-  gs_sortAscending = !reverseOrder;
+void wxArrayString::Sort(CompareFunction2 compareFunction)
+{
+  qsort(m_pItems, m_nCount, sizeof(wxChar *), (wxStringCompareFn)compareFunction);
+}
 
-  DoSort();
+#if WXWIN_COMPATIBILITY_2_4
 
-  END_SORT();
+void wxArrayString::Sort(bool reverseOrder)
+{
+  Sort(reverseOrder ? wxStringSortDescending : wxStringSortAscending);
 }
 
+#endif // WXWIN_COMPATIBILITY_2_4
+
 void wxArrayString::DoSort()
 {
   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;
 }
 
+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());
+}
diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp
index 001bdbd65e..068d735b61 100644
--- a/src/generic/grid.cpp
+++ b/src/generic/grid.cpp
@@ -9377,27 +9377,27 @@ void wxGrid::SetColSize( int col, int width )
 void wxGrid::SetColMinimalWidth( int col, int width )
 {
     if (width > GetColMinimalAcceptableWidth()) {
-        m_colMinWidths.Put(col, width);
+        m_colMinWidths[col] = width;
     }
 }
 
 void wxGrid::SetRowMinimalHeight( int row, int width )
 {
     if (width > GetRowMinimalAcceptableHeight()) {
-       m_rowMinHeights.Put(row, width);
+       m_rowMinHeights[row] = width;
     }
 }
 
 int wxGrid::GetColMinimalWidth(int col) const
 {
-    long value = m_colMinWidths.Get(col);
-    return value != wxNOT_FOUND ? (int)value : m_minAcceptableColWidth;
+    wxLongToLongHashMap::const_iterator it = m_colMinWidths.find(col);
+    return it != m_colMinWidths.end() ? (int)it->second : m_minAcceptableColWidth;
 }
 
 int wxGrid::GetRowMinimalHeight(int row) const
 {
-    long value = m_rowMinHeights.Get(row);
-    return value != wxNOT_FOUND ? (int)value : m_minAcceptableRowHeight;
+    wxLongToLongHashMap::const_iterator it = m_rowMinHeights.find(row);
+    return it != m_rowMinHeights.end() ? (int)it->second : m_minAcceptableRowHeight;
 }
 
 void wxGrid::SetColMinimalAcceptableWidth( int width )
diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp
index e3edea4f3d..0cecdfddb1 100644
--- a/src/gtk/listbox.cpp
+++ b/src/gtk/listbox.cpp
@@ -657,7 +657,7 @@ void wxListBox::Delete( int n )
     }
 
     if ( m_strings )
-        m_strings->Remove(n);
+        m_strings->RemoveAt(n);
 }
 
 // ----------------------------------------------------------------------------
diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp
index e3edea4f3d..0cecdfddb1 100644
--- a/src/gtk1/listbox.cpp
+++ b/src/gtk1/listbox.cpp
@@ -657,7 +657,7 @@ void wxListBox::Delete( int n )
     }
 
     if ( m_strings )
-        m_strings->Remove(n);
+        m_strings->RemoveAt(n);
 }
 
 // ----------------------------------------------------------------------------
diff --git a/src/html/helpfrm.cpp b/src/html/helpfrm.cpp
index 5191e19ecd..d51186b765 100644
--- a/src/html/helpfrm.cpp
+++ b/src/html/helpfrm.cpp
@@ -496,7 +496,11 @@ wxHtmlHelpFrame::~wxHtmlHelpFrame()
         delete m_Data;
     if (m_NormalFonts) delete m_NormalFonts;
     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();
 
-    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->DeleteContents(TRUE);
 
     int cnt = m_Data->GetContentsCnt();
     int i;
@@ -1310,8 +1317,8 @@ void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
                 pos = m_BookmarksNames.Index(item);
                 if (pos != wxNOT_FOUND)
                 {
-                    m_BookmarksNames.Remove(pos);
-                    m_BookmarksPages.Remove(pos);
+                    m_BookmarksNames.RemoveAt(pos);
+                    m_BookmarksPages.RemoveAt(pos);
                     m_Bookmarks->Delete(m_Bookmarks->GetSelection());
                 }
             }
diff --git a/src/motif/menu.cpp b/src/motif/menu.cpp
index 06ad86e72d..8699350bbb 100644
--- a/src/motif/menu.cpp
+++ b/src/motif/menu.cpp
@@ -316,7 +316,7 @@ wxMenu *wxMenuBar::Remove(size_t pos)
 
     menu->SetMenuBar(NULL);
 
-    m_titles.Remove(pos);
+    m_titles.RemoveAt(pos);
 
     return menu;
 }
diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp
index b3005be6cc..f3c898b413 100644
--- a/src/msw/menu.cpp
+++ b/src/msw/menu.cpp
@@ -799,7 +799,7 @@ wxMenu *wxMenuBar::Remove(size_t pos)
         Refresh();
     }
 
-    m_titles.Remove(pos);
+    m_titles.RemoveAt(pos);
 
     return menu;
 }
diff --git a/src/msw/volume.cpp b/src/msw/volume.cpp
index 246a4c4e70..c36b73379a 100644
--- a/src/msw/volume.cpp
+++ b/src/msw/volume.cpp
@@ -354,7 +354,7 @@ static bool BuildRemoteList(wxArrayString& list, NETRESOURCE* pResSrc,
             {
                 // Found the element.  Remove it or mark it mounted.
                 if (flagsUnset & wxFS_VOL_MOUNTED)
-                    list.Remove(iList);
+                    list.RemoveAt(iList);
                 else
                     s_fileInfo[list[iList]].m_flags |= wxFS_VOL_MOUNTED;
 
-- 
2.47.2