]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/listctrl.cpp
and ITEM_COLLAPSED/ING too
[wxWidgets.git] / src / generic / listctrl.cpp
index 77f0ebe6d79a7ba3abc63278d3b89a3801a9b461..6421ecff5205a17fb1ea19e4114d842deb01f612 100644 (file)
@@ -8,7 +8,8 @@
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
-#pragma implementation "listctrl.h"
+    #pragma implementation "listctrl.h"
+    #pragma implementation "listctrlbase.h"
 #endif
 
 // For compilers that support precompilation, includes "wx.h".
 #endif
 
 // For compilers that support precompilation, includes "wx.h".
@@ -1170,6 +1171,8 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
 
 wxListMainWindow::~wxListMainWindow()
 {
 
 wxListMainWindow::~wxListMainWindow()
 {
+    DeleteEverything();
+
     if (m_hilightBrush) delete m_hilightBrush;
 
     delete m_renameTimer;
     if (m_hilightBrush) delete m_hilightBrush;
 
     delete m_renameTimer;
@@ -1466,13 +1469,13 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
         }
         else
         {
         }
         else
         {
-            if (event.ShiftDown())
+            if (event.ControlDown())
             {
                 m_current = line;
                 m_current->ReverseHilight();
                 RefreshLine( m_current );
             }
             {
                 m_current = line;
                 m_current->ReverseHilight();
                 RefreshLine( m_current );
             }
-            else if (event.ControlDown())
+            else if (event.ShiftDown())
             {
                 m_current = line;
 
             {
                 m_current = line;
 
@@ -1622,8 +1625,9 @@ void wxListMainWindow::OnChar( wxKeyEvent &event )
     {
         wxNavigationKeyEvent nevent;
         nevent.SetDirection( !event.ShiftDown() );
     {
         wxNavigationKeyEvent nevent;
         nevent.SetDirection( !event.ShiftDown() );
+        nevent.SetEventObject( GetParent()->GetParent() );
         nevent.SetCurrentFocus( m_parent );
         nevent.SetCurrentFocus( m_parent );
-        if (m_parent->GetEventHandler()->ProcessEvent( nevent )) return;
+        if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) return;
     }
 
     /* no item -> nothing to do */
     }
 
     /* no item -> nothing to do */
@@ -2329,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();
     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++;
         ret++;
+
         node = node->Next();
     }
         node = node->Next();
     }
+
     return -1;
 }
 
     return -1;
 }
 
@@ -2370,7 +2394,7 @@ void wxListMainWindow::DeleteColumn( int col )
     if (node) m_columns.DeleteNode( node );
 }
 
     if (node) m_columns.DeleteNode( node );
 }
 
-void wxListMainWindow::DeleteAllItems( void )
+void wxListMainWindow::DeleteAllItems()
 {
     m_dirty = TRUE;
     m_current = (wxListLineData *) NULL;
 {
     m_dirty = TRUE;
     m_current = (wxListLineData *) NULL;
@@ -2378,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
     // 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();
 }
 
 
     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();
 }
 
     m_columns.Clear();
 }
 
@@ -2551,6 +2559,7 @@ void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
     list_ctrl_compare_func_2 = fn;
     list_ctrl_compare_data = data;
     m_lines.Sort( list_ctrl_compare_func_1 );
     list_ctrl_compare_func_2 = fn;
     list_ctrl_compare_data = data;
     m_lines.Sort( list_ctrl_compare_func_1 );
+    m_dirty = TRUE;
 }
 
 void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
 }
 
 void wxListMainWindow::OnScroll(wxScrollWinEvent& event)