]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/listctrl.cpp
Fixed problem with label resize cursor not resetting
[wxWidgets.git] / src / generic / listctrl.cpp
index 62c3aa3787852c466c34dd736cecb44ca72585b2..6421ecff5205a17fb1ea19e4114d842deb01f612 100644 (file)
@@ -1171,6 +1171,8 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
 
 wxListMainWindow::~wxListMainWindow()
 {
+    DeleteEverything();
+
     if (m_hilightBrush) delete m_hilightBrush;
 
     delete m_renameTimer;
@@ -1467,13 +1469,13 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
         }
         else
         {
-            if (event.ShiftDown())
+            if (event.ControlDown())
             {
                 m_current = line;
                 m_current->ReverseHilight();
                 RefreshLine( m_current );
             }
-            else if (event.ControlDown())
+            else if (event.ShiftDown())
             {
                 m_current = line;
 
@@ -2331,21 +2333,41 @@ void wxListMainWindow::RealizeChanges( void )
     }
 }
 
-long wxListMainWindow::GetNextItem( long item, int WXUNUSED(geometry), int state )
+long wxListMainWindow::GetNextItem( long item,
+                                    int WXUNUSED(geometry),
+                                    int state )
 {
-    long ret = 0;
-    if (item > 0) ret = item;
-    if(ret >= GetItemCount()) return -1;
-    wxNode *node = m_lines.Nth( (size_t)++ret );
+    long ret = item,
+         max = GetItemCount();
+    wxCHECK_MSG( (ret == -1) || (ret < max), -1,
+                 _T("invalid listctrl index in GetNextItem()") );
+
+    // notice that we start with the next item (or the first one if item == -1)
+    // and this is intentional to allow writing a simple loop to iterate over
+    // all selected items
+    ret++;
+    if ( ret == max )
+    {
+        // this is not an error because the index was ok initially, just no
+        // such item
+        return -1;
+    }
+
+    wxNode *node = m_lines.Nth( (size_t)ret );
     while (node)
     {
         wxListLineData *line = (wxListLineData*)node->Data();
-        if ((state & wxLIST_STATE_FOCUSED) && (line == m_current)) return ret;
-        if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted())) return ret;
-        if (!state) return ret;
+        if ((state & wxLIST_STATE_FOCUSED) && (line == m_current))
+            return ret;
+        if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted()))
+            return ret;
+        if (!state)
+            return ret;
         ret++;
+
         node = node->Next();
     }
+
     return -1;
 }
 
@@ -2372,7 +2394,7 @@ void wxListMainWindow::DeleteColumn( int col )
     if (node) m_columns.DeleteNode( node );
 }
 
-void wxListMainWindow::DeleteAllItems( void )
+void wxListMainWindow::DeleteAllItems()
 {
     m_dirty = TRUE;
     m_current = (wxListLineData *) NULL;
@@ -2380,34 +2402,18 @@ void wxListMainWindow::DeleteAllItems( void )
     // to make the deletion of all items faster, we don't send the
     // notifications in this case: this is compatible with wxMSW and
     // documented in DeleteAllItems() description
-#if 0
-    wxNode *node = m_lines.First();
-    while (node)
-    {
-        wxListLineData *line = (wxListLineData*)node->Data();
 
-        DeleteLine( line );
-
-        node = node->Next();
-    }
-#endif // 0
+    wxListEvent event( wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS, GetParent()->GetId() );
+    event.SetEventObject( GetParent() );
+    GetParent()->GetEventHandler()->ProcessEvent( event );
 
     m_lines.Clear();
 }
 
-void wxListMainWindow::DeleteEverything( void )
+void wxListMainWindow::DeleteEverything()
 {
-    m_dirty = TRUE;
-    m_current = (wxListLineData *) NULL;
-    wxNode *node = m_lines.First();
-    while (node)
-    {
-        wxListLineData *line = (wxListLineData*)node->Data();
-        DeleteLine( line );
-        node = node->Next();
-    }
-    m_lines.Clear();
-    m_current = (wxListLineData *) NULL;
+    DeleteAllItems();
+    
     m_columns.Clear();
 }