]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/list.cpp
Refresh() didn't work as it wasn't passed to subwindows
[wxWidgets.git] / src / common / list.cpp
index 1d647ddd273249276ef893ca71eaa872492513b7..fed64c544f3b8a5b02d41ba2eb12ef65e15a1fa7 100644 (file)
@@ -5,8 +5,8 @@
 // Modified by: VZ at 16/11/98: WX_DECLARE_LIST() and typesafe lists added
 // Created:     04/01/98
 // RCS-ID:      $Id$
-// Copyright:   (c) Julian Smart and Markus Holzem
-// Licence:     wxWindows license
+// Copyright:   (c) Julian Smart
+// Licence:     wxWindows licence
 ////////////////////////////////////////////////////////////////////////////////
 
 // =============================================================================
@@ -35,7 +35,6 @@
 #ifndef WX_PRECOMP
     #include "wx/defs.h"
     #include "wx/list.h"
-    #include "wx/utils.h"   // for copystring() (beurk...)
 #endif
 
 // =============================================================================
@@ -513,9 +512,9 @@ void wxListBase::Sort(const wxSortCompareFunction compfunc)
 
     // go through the list and put the pointers into the array
     wxNodeBase *node;
-    for ( node = GetFirst(); node; node = node->Next() )
+    for ( node = GetFirst(); node; node = node->GetNext() )
     {
-        *objPtr++ = node->Data();
+        *objPtr++ = node->GetData();
     }
 
     // sort the array
@@ -523,7 +522,7 @@ void wxListBase::Sort(const wxSortCompareFunction compfunc)
 
     // put the sorted pointers back into the list
     objPtr = objArray;
-    for ( node = GetFirst(); node; node = node->Next() )
+    for ( node = GetFirst(); node; node = node->GetNext() )
     {
         node->SetData(*objPtr++);
     }
@@ -532,18 +531,63 @@ void wxListBase::Sort(const wxSortCompareFunction compfunc)
     delete[] objArray;
 }
 
+// ============================================================================
+// compatibility section from now on
+// ============================================================================
+
+#ifdef wxLIST_COMPATIBILITY
+
+// -----------------------------------------------------------------------------
+// wxNodeBase deprecated methods
+// -----------------------------------------------------------------------------
+
+wxNode *wxNodeBase::Next() const { return (wxNode *)GetNext(); }
+wxNode *wxNodeBase::Previous() const { return (wxNode *)GetPrevious(); }
+wxObject *wxNodeBase::Data() const { return (wxObject *)GetData(); }
+
+// -----------------------------------------------------------------------------
+// wxListBase deprecated methods
+// -----------------------------------------------------------------------------
+
+int wxListBase::Number() const { return GetCount(); }
+wxNode *wxListBase::First() const { return (wxNode *)GetFirst(); }
+wxNode *wxListBase::Last() const { return (wxNode *)GetLast(); }
+wxNode *wxListBase::Nth(size_t n) const { return (wxNode *)Item(n); }
+wxListBase::operator wxList&() const { return *(wxList*)this; }
+
 // -----------------------------------------------------------------------------
 // wxList (a.k.a. wxObjectList)
 // -----------------------------------------------------------------------------
 
+IMPLEMENT_DYNAMIC_CLASS(wxList, wxObject)
+
+wxList::wxList( int key_type )
+    : wxObjectList( (wxKeyType)key_type )
+{
+}
+
 void wxObjectListNode::DeleteData()
 {
     delete (wxObject *)GetData();
 }
 
-// -----------------------------------------------------------------------------
+// ----------------------------------------------------------------------------
 // wxStringList
-// -----------------------------------------------------------------------------
+// ----------------------------------------------------------------------------
+
+static inline wxChar* MYcopystring(const wxString& s)
+{
+    wxChar* copy = new wxChar[s.length() + 1];
+    return wxStrcpy(copy, s.c_str());
+}
+
+static inline wxChar* MYcopystring(const wxChar* s)
+{
+    wxChar* copy = new wxChar[wxStrlen(s) + 1];
+    return wxStrcpy(copy, s);
+}
+
+IMPLEMENT_DYNAMIC_CLASS(wxStringList, wxObject)
 
 // instead of WX_DEFINE_LIST(wxStringListBase) we define this function
 // ourselves
@@ -580,6 +624,11 @@ void wxStringList::DoCopy(const wxStringList& other)
     }
 }
 
+wxStringList::wxStringList()
+{
+    DeleteContents(TRUE);
+}
+
 // Variable argument list, terminated by a zero
 // Makes new storage for the strings
 wxStringList::wxStringList (const wxChar *first, ...)
@@ -618,7 +667,7 @@ wxChar **wxStringList::ListToArray(bool new_copies) const
     {
         wxChar *s = node->GetData();
         if ( new_copies )
-            string_array[i] = copystring(s);
+            string_array[i] = MYcopystring(s);
         else
             string_array[i] = s;
         node = node->GetNext();
@@ -640,7 +689,7 @@ bool wxStringList::Member(const wxChar *s) const
     return FALSE;
 }
 
-static int LINKAGEMODE
+extern "C" int LINKAGEMODE
 wx_comparestrings(const void *arg1, const void *arg2)
 {
   wxChar **s1 = (wxChar **) arg1;
@@ -670,3 +719,16 @@ void wxStringList::Sort()
 
     delete [] array;
 }
+
+wxNode *wxStringList::Add(const wxChar *s)
+{
+    return (wxNode *)wxStringListBase::Append(MYcopystring(s));
+}
+        
+wxNode *wxStringList::Prepend(const wxChar *s)
+{
+    return (wxNode *)wxStringListBase::Insert(MYcopystring(s));
+}
+
+#endif // wxLIST_COMPATIBILITY
+