- 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
#include "wx/help.h"
+#include "wx/hashmap.h"
#if wxUSE_BMPBUTTON
#include "wx/bmpbuttn.h"
#endif
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
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
#include "wx/filesys.h"
-class WXDLLIMPEXP_BASE wxHashTableLong;
+class WXDLLIMPEXP_BASE wxLongToLongHashMap;
//--------------------------------------------------------------------------------
// wxZipFSHandler
void *m_Archive;
wxString m_Pattern, m_BaseDir, m_ZipFile;
bool m_AllowDirs, m_AllowFiles;
- wxHashTableLong *m_DirsFound;
+ wxLongToLongHashMap *m_DirsFound;
wxString DoFind();
#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"
class WXDLLEXPORT wxTextCtrl;
class WXDLLEXPORT wxSpinCtrl;
+WX_DECLARE_EXPORTED_HASH_MAP( long, long, wxIntegerHash, wxIntegerEqual,
+ wxLongToLongHashMap );
+
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
// 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;
DECLARE_NO_COPY_CLASS(wxHashTableBase)
};
+#if WXWIN_COMPATIBILITY_2_4
+
// ----------------------------------------------------------------------------
// a hash table which stores longs
// ----------------------------------------------------------------------------
DECLARE_NO_COPY_CLASS(wxStringHashTable)
};
+#endif
+
// ----------------------------------------------------------------------------
// for compatibility only
// ----------------------------------------------------------------------------
#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__
// 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
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
// 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
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
if ( aParts.IsEmpty() )
wxLogWarning(_("'%s' has extra '..', ignored."), sz);
else
- aParts.Remove(aParts.Count() - 1);
+ aParts.RemoveAt(aParts.Count() - 1);
strCurrent.Empty();
}
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)
void wxFileName::RemoveDir( int pos )
{
- m_dirs.Remove( (size_t)pos );
+ m_dirs.RemoveAt( (size_t)pos );
}
// ----------------------------------------------------------------------------
#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"
#include "unzip.h"
#endif
+WX_DECLARE_EXPORTED_HASH_MAP( long, long, wxIntegerHash, wxIntegerEqual,
+ wxLongToLongHashMap );
//----------------------------------------------------------------------------
// wxZipFSHandler
if (m_AllowDirs)
{
delete m_DirsFound;
- m_DirsFound = new wxHashTableLong();
+ m_DirsFound = new wxLongToLongHashMap();
}
return 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 &&
return node;
}
+#if WXWIN_COMPATIBILITY_2_4
+
// ----------------------------------------------------------------------------
// wxHashTableLong
// ----------------------------------------------------------------------------
return FALSE;
}
+#endif // WXWIN_COMPATIBILITY_2_4
+
// ----------------------------------------------------------------------------
// old not type safe wxHashTable
// ----------------------------------------------------------------------------
}
}
+#if WXWIN_COMPATIBILITY_2_4
+
// return a wxString[] as required for some control ctors.
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
{
}
// 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,
wxCHECK_RET( iIndex != wxNOT_FOUND,
wxT("removing inexistent element in wxArrayString::Remove") );
- Remove(iIndex);
+ RemoveAt(iIndex);
}
// ----------------------------------------------------------------------------
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") );
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());
+}
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 )
}
if ( m_strings )
- m_strings->Remove(n);
+ m_strings->RemoveAt(n);
}
// ----------------------------------------------------------------------------
}
if ( m_strings )
- m_strings->Remove(n);
+ m_strings->RemoveAt(n);
}
// ----------------------------------------------------------------------------
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;
+ }
}
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;
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());
}
}
menu->SetMenuBar(NULL);
- m_titles.Remove(pos);
+ m_titles.RemoveAt(pos);
return menu;
}
Refresh();
}
- m_titles.Remove(pos);
+ m_titles.RemoveAt(pos);
return menu;
}
{
// 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;