changed wxListMainWindow::m_lines from wxList to wxObjArray --> performance gain

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7674 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2000-07-03 16:16:40 +00:00
parent a7798d1ce7
commit 122e8c139e

View File

@@ -23,6 +23,7 @@
#include "wx/app.h" #include "wx/app.h"
#include "wx/listctrl.h" #include "wx/listctrl.h"
#include "wx/generic/imaglist.h" #include "wx/generic/imaglist.h"
#include "wx/dynarray.h"
#ifndef wxUSE_GENERIC_LIST_EXTENSIONS #ifndef wxUSE_GENERIC_LIST_EXTENSIONS
#define wxUSE_GENERIC_LIST_EXTENSIONS 1 #define wxUSE_GENERIC_LIST_EXTENSIONS 1
@@ -167,6 +168,11 @@ private:
DECLARE_DYNAMIC_CLASS(wxListLineData); DECLARE_DYNAMIC_CLASS(wxListLineData);
}; };
WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData, wxListLineDataArray);
#include "wx/arrimpl.cpp"
WX_DEFINE_OBJARRAY(wxListLineDataArray);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxListHeaderWindow (internal) // wxListHeaderWindow (internal)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -268,7 +274,7 @@ class WXDLLEXPORT wxListMainWindow: public wxScrolledWindow
{ {
public: public:
long m_mode; long m_mode;
wxList m_lines; wxListLineDataArray m_lines;
wxList m_columns; wxList m_columns;
wxListLineData *m_current; wxListLineData *m_current;
wxListLineData *m_currentEdit; wxListLineData *m_currentEdit;
@@ -1510,7 +1516,6 @@ END_EVENT_TABLE()
wxListMainWindow::wxListMainWindow() wxListMainWindow::wxListMainWindow()
{ {
m_mode = 0; m_mode = 0;
m_lines.DeleteContents( TRUE );
m_columns.DeleteContents( TRUE ); m_columns.DeleteContents( TRUE );
m_current = (wxListLineData *) NULL; m_current = (wxListLineData *) NULL;
m_visibleLines = 0; m_visibleLines = 0;
@@ -1539,7 +1544,6 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxWindowID id,
wxScrolledWindow( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name ) wxScrolledWindow( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name )
{ {
m_mode = style; m_mode = style;
m_lines.DeleteContents( TRUE );
m_columns.DeleteContents( TRUE ); m_columns.DeleteContents( TRUE );
m_current = (wxListLineData *) NULL; m_current = (wxListLineData *) NULL;
m_dirty = TRUE; m_dirty = TRUE;
@@ -1622,32 +1626,24 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
if (m_mode & wxLC_REPORT) if (m_mode & wxLC_REPORT)
{ {
int lineSpacing = 0; int lineSpacing = 0;
wxListLineData *line = (wxListLineData*)m_lines.First()->Data(); wxListLineData *line = &m_lines[0];
int dummy = 0; int dummy = 0;
line->GetSize( dummy, lineSpacing ); line->GetSize( dummy, lineSpacing );
lineSpacing += 1; lineSpacing += 1;
int y_s = m_yScroll*GetScrollPos( wxVERTICAL ); int y_s = m_yScroll*GetScrollPos( wxVERTICAL );
wxNode *node = m_lines.Nth( y_s / lineSpacing ); size_t i_to = y_s / lineSpacing + m_visibleLines+2;
for (int i = 0; i < m_visibleLines+2; i++) if (i_to >= m_lines.GetCount()) i_to = m_lines.GetCount();
for (size_t i = y_s / lineSpacing; i < i_to; i++)
{ {
if (!node) break; m_lines[i].Draw( &dc );
line = (wxListLineData*)node->Data();
line->Draw( &dc );
node = node->Next();
} }
} }
else else
{ {
wxNode *node = m_lines.First(); for (size_t i = 0; i < m_lines.GetCount(); i++)
while (node) m_lines[i].Draw( &dc );
{
wxListLineData *line = (wxListLineData*)node->Data();
line->Draw( &dc );
node = node->Next();
}
} }
if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus ); if (m_current) m_current->DrawRubberBand( &dc, m_hasFocus );
@@ -1657,16 +1653,14 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
void wxListMainWindow::HilightAll( bool on ) void wxListMainWindow::HilightAll( bool on )
{ {
wxNode *node = m_lines.First(); for (size_t i = 0; i < m_lines.GetCount(); i++)
while (node)
{ {
wxListLineData *line = (wxListLineData *)node->Data(); wxListLineData *line = &m_lines[i];
if (line->IsHilighted() != on) if (line->IsHilighted() != on)
{ {
line->Hilight( on ); line->Hilight( on );
RefreshLine( line ); RefreshLine( line );
} }
node = node->Next();
} }
} }
@@ -1709,10 +1703,10 @@ void wxListMainWindow::DeleteLine( wxListLineData *line )
void wxListMainWindow::EditLabel( long item ) void wxListMainWindow::EditLabel( long item )
{ {
wxNode *node = m_lines.Nth( (size_t)item ); wxCHECK_RET( ((size_t)item < m_lines.GetCount()),
wxCHECK_RET( node, wxT("wrong index in wxListCtrl::Edit()") ); wxT("wrong index in wxListCtrl::Edit()") );
m_currentEdit = (wxListLineData*) node->Data(); m_currentEdit = &m_lines[(size_t)item];
wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() ); wxListEvent le( wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT, GetParent()->GetId() );
le.SetEventObject( GetParent() ); le.SetEventObject( GetParent() );
@@ -1750,7 +1744,7 @@ void wxListMainWindow::OnRenameTimer()
{ {
wxCHECK_RET( m_current, wxT("invalid m_current") ); wxCHECK_RET( m_current, wxT("invalid m_current") );
Edit( m_lines.IndexOf( m_current ) ); Edit( m_lines.Index( *m_current ) );
} }
void wxListMainWindow::OnRenameAccept() void wxListMainWindow::OnRenameAccept()
@@ -1786,15 +1780,13 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
/* Did we actually hit an item ? */ /* Did we actually hit an item ? */
long hitResult = 0; long hitResult = 0;
wxNode *node = m_lines.First();
wxListLineData *line = (wxListLineData *) NULL; wxListLineData *line = (wxListLineData *) NULL;
while (node) for (size_t i = 0; i < m_lines.GetCount(); i++)
{ {
line = (wxListLineData*)node->Data(); line = &m_lines[i];
hitResult = line->IsHit( x, y ); hitResult = line->IsHit( x, y );
if (hitResult) break; if (hitResult) break;
line = (wxListLineData *) NULL; line = (wxListLineData *) NULL;
node = node->Next();
} }
if (event.Dragging()) if (event.Dragging())
@@ -1894,26 +1886,25 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
} }
else if (event.ShiftDown()) else if (event.ShiftDown())
{ {
size_t j;
m_current = line; m_current = line;
int numOfCurrent = -1; int numOfCurrent = -1;
node = m_lines.First(); for (j = 0; j < m_lines.GetCount(); j++)
while (node)
{ {
wxListLineData *test_line = (wxListLineData*)node->Data(); wxListLineData *test_line = &m_lines[j];
numOfCurrent++; numOfCurrent++;
if (test_line == oldCurrent) break; if (test_line == oldCurrent) break;
node = node->Next();
} }
int numOfLine = -1; int numOfLine = -1;
node = m_lines.First();
while (node) for (j = 0; j < m_lines.GetCount(); j++)
{ {
wxListLineData *test_line = (wxListLineData*)node->Data(); wxListLineData *test_line = &m_lines[j];
numOfLine++; numOfLine++;
if (test_line == line) break; if (test_line == line) break;
node = node->Next();
} }
if (numOfLine < numOfCurrent) if (numOfLine < numOfCurrent)
@@ -1923,13 +1914,11 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
numOfCurrent = i; numOfCurrent = i;
} }
wxNode *node = m_lines.Nth( numOfCurrent );
for (int i = 0; i <= numOfLine-numOfCurrent; i++) for (int i = 0; i <= numOfLine-numOfCurrent; i++)
{ {
wxListLineData *test_line= (wxListLineData*)node->Data(); wxListLineData *test_line= &m_lines[numOfCurrent + i];
test_line->Hilight(TRUE); test_line->Hilight(TRUE);
RefreshLine( test_line ); RefreshLine( test_line );
node = node->Next();
} }
} }
else else
@@ -2067,29 +2056,31 @@ void wxListMainWindow::OnChar( wxKeyEvent &event )
{ {
case WXK_UP: case WXK_UP:
{ {
wxNode *node = m_lines.Member( m_current )->Previous(); int index = m_lines.Index(*m_current);
if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); if (index != wxNOT_FOUND && index > 0)
OnArrowChar( &m_lines[index-1], event.ShiftDown() );
break; break;
} }
case WXK_DOWN: case WXK_DOWN:
{ {
wxNode *node = m_lines.Member( m_current )->Next(); int index = m_lines.Index(*m_current);
if (node) OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); if (index != wxNOT_FOUND && (size_t)index < m_lines.GetCount()-2)
OnArrowChar( &m_lines[index+1], event.ShiftDown() );
break; break;
} }
case WXK_END: case WXK_END:
{ {
wxNode *node = m_lines.Last(); if (!m_lines.IsEmpty())
OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); OnArrowChar( &m_lines.Last(), event.ShiftDown() );
break; break;
} }
case WXK_HOME: case WXK_HOME:
{ {
wxNode *node = m_lines.First(); if (!m_lines.IsEmpty())
OnArrowChar( (wxListLineData*)node->Data(), event.ShiftDown() ); OnArrowChar( &m_lines[0], event.ShiftDown() );
break; break;
} }
case WXK_PRIOR: /* case WXK_PRIOR: FIXME - finish porting
{ {
int steps = 0; int steps = 0;
if (m_mode & wxLC_REPORT) if (m_mode & wxLC_REPORT)
@@ -2188,7 +2179,7 @@ void wxListMainWindow::OnChar( wxKeyEvent &event )
m_current->GetItem( 0, le.m_item ); m_current->GetItem( 0, le.m_item );
GetParent()->GetEventHandler()->ProcessEvent( le ); GetParent()->GetEventHandler()->ProcessEvent( le );
break; break;
} }*/
default: default:
{ {
event.Skip(); event.Skip();
@@ -2292,15 +2283,9 @@ int wxListMainWindow::GetTextLength( wxString &s )
int wxListMainWindow::GetIndexOfLine( const wxListLineData *line ) int wxListMainWindow::GetIndexOfLine( const wxListLineData *line )
{ {
int i = 0; int i = m_lines.Index(*line);
wxNode *node = m_lines.First(); if (i == wxNOT_FOUND) return -1;
while (node) else return i;
{
if (line == (wxListLineData*)node->Data()) return i;
i++;
node = node->Next();
}
return -1;
} }
void wxListMainWindow::SetImageList( wxImageList *imageList, int which ) void wxListMainWindow::SetImageList( wxImageList *imageList, int which )
@@ -2381,10 +2366,10 @@ void wxListMainWindow::SetColumnWidth( int col, int width )
wxClientDC dc(this); wxClientDC dc(this);
dc.SetFont( GetFont() ); dc.SetFont( GetFont() );
int max = 10; int max = 10;
node = m_lines.First();
while (node) for (size_t i = 0; i < m_lines.GetCount(); i++)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[i];
wxNode *n = line->m_items.Nth( col ); wxNode *n = line->m_items.Nth( col );
if (n) if (n)
{ {
@@ -2405,7 +2390,6 @@ void wxListMainWindow::SetColumnWidth( int col, int width )
} }
if (current > max) max = current; if (current > max) max = current;
} }
node = node->Next();
} }
width = max+10; width = max+10;
} }
@@ -2417,17 +2401,15 @@ void wxListMainWindow::SetColumnWidth( int col, int width )
column->SetWidth( width ); column->SetWidth( width );
} }
node = m_lines.First(); for (size_t i = 0; i < m_lines.GetCount(); i++)
while (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[i];
wxNode *n = line->m_items.Nth( col ); wxNode *n = line->m_items.Nth( col );
if (n) if (n)
{ {
wxListItemData *item = (wxListItemData*)n->Data(); wxListItemData *item = (wxListItemData*)n->Data();
item->SetSize( width, -1 ); item->SetSize( width, -1 );
} }
node = node->Next();
} }
wxListHeaderWindow *headerWin = ((wxListCtrl*) GetParent())->m_headerWin; wxListHeaderWindow *headerWin = ((wxListCtrl*) GetParent())->m_headerWin;
@@ -2480,10 +2462,9 @@ int wxListMainWindow::GetCountPerPage()
void wxListMainWindow::SetItem( wxListItem &item ) void wxListMainWindow::SetItem( wxListItem &item )
{ {
m_dirty = TRUE; m_dirty = TRUE;
wxNode *node = m_lines.Nth( (size_t)item.m_itemId ); if (item.m_itemId >= 0 && (size_t)item.m_itemId < m_lines.GetCount())
if (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[(size_t)item.m_itemId];
if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3; if (m_mode & wxLC_REPORT) item.m_width = GetColumnWidth( item.m_col )-3;
line->SetItem( item.m_col, item ); line->SetItem( item.m_col, item );
} }
@@ -2497,10 +2478,9 @@ void wxListMainWindow::SetItemState( long item, long state, long stateMask )
if (stateMask & wxLIST_STATE_FOCUSED) if (stateMask & wxLIST_STATE_FOCUSED)
{ {
wxNode *node = m_lines.Nth( (size_t)item ); if (item >= 0 && (size_t)item < m_lines.GetCount())
if (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[(size_t)item];
UnfocusLine( m_current ); UnfocusLine( m_current );
m_current = line; m_current = line;
FocusLine( m_current ); FocusLine( m_current );
@@ -2514,10 +2494,9 @@ void wxListMainWindow::SetItemState( long item, long state, long stateMask )
bool on = (state & wxLIST_STATE_SELECTED) != 0; bool on = (state & wxLIST_STATE_SELECTED) != 0;
if (!on && (m_mode & wxLC_SINGLE_SEL)) return; if (!on && (m_mode & wxLC_SINGLE_SEL)) return;
wxNode *node = m_lines.Nth( (size_t)item ); if (item >= 0 && (size_t)item < m_lines.GetCount())
if (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[(size_t)item];
if (m_mode & wxLC_SINGLE_SEL) if (m_mode & wxLC_SINGLE_SEL)
{ {
UnfocusLine( m_current ); UnfocusLine( m_current );
@@ -2542,19 +2521,17 @@ int wxListMainWindow::GetItemState( long item, long stateMask )
int ret = wxLIST_STATE_DONTCARE; int ret = wxLIST_STATE_DONTCARE;
if (stateMask & wxLIST_STATE_FOCUSED) if (stateMask & wxLIST_STATE_FOCUSED)
{ {
wxNode *node = m_lines.Nth( (size_t)item ); if (item >= 0 && (size_t)item < m_lines.GetCount())
if (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[(size_t)item];
if (line == m_current) ret |= wxLIST_STATE_FOCUSED; if (line == m_current) ret |= wxLIST_STATE_FOCUSED;
} }
} }
if (stateMask & wxLIST_STATE_SELECTED) if (stateMask & wxLIST_STATE_SELECTED)
{ {
wxNode *node = m_lines.Nth( (size_t)item ); if (item >= 0 && (size_t)item < m_lines.GetCount())
if (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[(size_t)item];
if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED; if (line->IsHilighted()) ret |= wxLIST_STATE_FOCUSED;
} }
} }
@@ -2563,10 +2540,9 @@ int wxListMainWindow::GetItemState( long item, long stateMask )
void wxListMainWindow::GetItem( wxListItem &item ) void wxListMainWindow::GetItem( wxListItem &item )
{ {
wxNode *node = m_lines.Nth( (size_t)item.m_itemId ); if (item.m_itemId >= 0 && (size_t)item.m_itemId < m_lines.GetCount())
if (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[(size_t)item.m_itemId];
line->GetItem( item.m_col, item ); line->GetItem( item.m_col, item );
} }
else else
@@ -2580,16 +2556,14 @@ void wxListMainWindow::GetItem( wxListItem &item )
int wxListMainWindow::GetItemCount() int wxListMainWindow::GetItemCount()
{ {
return m_lines.Number(); return m_lines.GetCount();
} }
void wxListMainWindow::GetItemRect( long index, wxRect &rect ) void wxListMainWindow::GetItemRect( long index, wxRect &rect )
{ {
wxNode *node = m_lines.Nth( (size_t)index ); if (index >= 0 && (size_t)index < m_lines.GetCount())
if (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); m_lines[(size_t)index].GetRect( rect );
line->GetRect( rect );
} }
else else
{ {
@@ -2602,12 +2576,10 @@ void wxListMainWindow::GetItemRect( long index, wxRect &rect )
bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos)
{ {
wxNode *node = m_lines.Nth( (size_t)item ); if (item >= 0 && (size_t)item < m_lines.GetCount())
if (node)
{ {
wxRect rect; wxRect rect;
wxListLineData *line = (wxListLineData*)node->Data(); m_lines[(size_t)item].GetRect( rect );
line->GetRect( rect );
pos.x = rect.x; pos.x = rect.x;
pos.y = rect.y; pos.y = rect.y;
} }
@@ -2622,12 +2594,9 @@ bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos)
int wxListMainWindow::GetSelectedItemCount() int wxListMainWindow::GetSelectedItemCount()
{ {
int ret = 0; int ret = 0;
wxNode *node = m_lines.First(); for (size_t i = 0; i < m_lines.GetCount(); i++)
while (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); if (m_lines[i].IsHilighted()) ret++;
if (line->IsHilighted()) ret++;
node = node->Next();
} }
return ret; return ret;
} }
@@ -2662,7 +2631,7 @@ long wxListMainWindow::GetMode() const
void wxListMainWindow::CalculatePositions() void wxListMainWindow::CalculatePositions()
{ {
if (!m_lines.First()) return; if (m_lines.IsEmpty()) return;
wxClientDC dc( this ); wxClientDC dc( this );
dc.SetFont( GetFont() ); dc.SetFont( GetFont() );
@@ -2679,7 +2648,7 @@ void wxListMainWindow::CalculatePositions()
int lineHeight = 0; int lineHeight = 0;
int lineSpacing = 0; int lineSpacing = 0;
wxListLineData *line = (wxListLineData*)m_lines.First()->Data(); wxListLineData *line = &m_lines[0];
line->CalculateSize( &dc, iconSpacing ); line->CalculateSize( &dc, iconSpacing );
int dummy = 0; int dummy = 0;
line->GetSize( dummy, lineSpacing ); line->GetSize( dummy, lineSpacing );
@@ -2692,7 +2661,7 @@ void wxListMainWindow::CalculatePositions()
{ {
int x = 4; int x = 4;
int y = 1; int y = 1;
int entireHeight = m_lines.Number() * lineSpacing + 2; int entireHeight = m_lines.GetCount() * lineSpacing + 2;
int scroll_pos = GetScrollPos( wxVERTICAL ); int scroll_pos = GetScrollPos( wxVERTICAL );
#if wxUSE_GENERIC_LIST_EXTENSIONS #if wxUSE_GENERIC_LIST_EXTENSIONS
int x_scroll_pos = GetScrollPos( wxHORIZONTAL ); int x_scroll_pos = GetScrollPos( wxHORIZONTAL );
@@ -2701,11 +2670,10 @@ void wxListMainWindow::CalculatePositions()
#endif #endif
GetClientSize( &clientWidth, &clientHeight ); GetClientSize( &clientWidth, &clientHeight );
wxNode* node = m_lines.First();
int entireWidth = 0 ; int entireWidth = 0 ;
while (node) for (size_t j = 0; j < m_lines.GetCount(); j++)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[j];
line->CalculateSize( &dc, iconSpacing ); line->CalculateSize( &dc, iconSpacing );
line->SetPosition( &dc, x, y, clientWidth ); line->SetPosition( &dc, x, y, clientWidth );
int col_x = 2; int col_x = 2;
@@ -2719,7 +2687,6 @@ void wxListMainWindow::CalculatePositions()
line->SetPosition( &dc, x, y, col_x ); line->SetPosition( &dc, x, y, col_x );
#endif #endif
y += lineSpacing; // one pixel blank line between items y += lineSpacing; // one pixel blank line between items
node = node->Next();
} }
m_visibleLines = clientHeight / lineSpacing; m_visibleLines = clientHeight / lineSpacing;
#if wxUSE_GENERIC_LIST_EXTENSIONS #if wxUSE_GENERIC_LIST_EXTENSIONS
@@ -2745,11 +2712,10 @@ void wxListMainWindow::CalculatePositions()
int maxWidth = 0; int maxWidth = 0;
m_visibleLines = 0; m_visibleLines = 0;
int m_currentVisibleLines = 0; int m_currentVisibleLines = 0;
wxNode *node = m_lines.First(); for (size_t i = 0; i < m_lines.GetCount(); i++)
while (node)
{ {
m_currentVisibleLines++; m_currentVisibleLines++;
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[i];
line->CalculateSize( &dc, iconSpacing ); line->CalculateSize( &dc, iconSpacing );
line->SetPosition( &dc, x, y, clientWidth ); line->SetPosition( &dc, x, y, clientWidth );
line->GetSize( lineWidth, lineHeight ); line->GetSize( lineWidth, lineHeight );
@@ -2765,8 +2731,7 @@ void wxListMainWindow::CalculatePositions()
entireWidth += maxWidth+6; entireWidth += maxWidth+6;
maxWidth = 0; maxWidth = 0;
} }
node = node->Next(); if (i == m_lines.GetCount()-1) entireWidth += maxWidth;
if (!node) entireWidth += maxWidth;
if ((tries == 0) && (entireWidth > clientWidth)) if ((tries == 0) && (entireWidth > clientWidth))
{ {
clientHeight -= 15; // scrollbar height clientHeight -= 15; // scrollbar height
@@ -2774,7 +2739,7 @@ void wxListMainWindow::CalculatePositions()
m_currentVisibleLines = 0; m_currentVisibleLines = 0;
break; break;
} }
if (!node) tries = 1; // everything fits, no second try required if (i == m_lines.GetCount()-1) tries = 1; // everything fits, no second try required
} }
} }
@@ -2787,8 +2752,8 @@ void wxListMainWindow::RealizeChanges()
{ {
if (!m_current) if (!m_current)
{ {
wxNode *node = m_lines.First(); if (!m_lines.IsEmpty())
if (node) m_current = (wxListLineData*)node->Data(); m_current = &m_lines[0];
} }
if (m_current) if (m_current)
{ {
@@ -2819,10 +2784,9 @@ long wxListMainWindow::GetNextItem( long item,
return -1; return -1;
} }
wxNode *node = m_lines.Nth( (size_t)ret ); for (size_t i = (size_t)ret; i < m_lines.GetCount(); i++)
while (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[i];
if ((state & wxLIST_STATE_FOCUSED) && (line == m_current)) if ((state & wxLIST_STATE_FOCUSED) && (line == m_current))
return ret; return ret;
if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted())) if ((state & wxLIST_STATE_SELECTED) && (line->IsHilighted()))
@@ -2830,8 +2794,6 @@ long wxListMainWindow::GetNextItem( long item,
if (!state) if (!state)
return ret; return ret;
ret++; ret++;
node = node->Next();
} }
return -1; return -1;
@@ -2840,13 +2802,12 @@ long wxListMainWindow::GetNextItem( long item,
void wxListMainWindow::DeleteItem( long index ) void wxListMainWindow::DeleteItem( long index )
{ {
m_dirty = TRUE; m_dirty = TRUE;
wxNode *node = m_lines.Nth( (size_t)index ); if (index >= 0 && (size_t)index < m_lines.GetCount())
if (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[(size_t)index];
if (m_current == line) m_current = (wxListLineData *) NULL; if (m_current == line) m_current = (wxListLineData *) NULL;
DeleteLine( line ); DeleteLine( line );
m_lines.DeleteNode( node ); m_lines.RemoveAt( (size_t)index );
} }
} }
@@ -2892,8 +2853,8 @@ void wxListMainWindow::EnsureVisible( long index )
wxListLineData *oldCurrent = m_current; wxListLineData *oldCurrent = m_current;
m_current = (wxListLineData *) NULL; m_current = (wxListLineData *) NULL;
wxNode *node = m_lines.Nth( (size_t)index ); if (index >= 0 && (size_t)index < m_lines.GetCount())
if (node) m_current = (wxListLineData*)node->Data(); m_current = &m_lines[(size_t)index];
if (m_current) MoveToFocus(); if (m_current) MoveToFocus();
m_current = oldCurrent; m_current = oldCurrent;
} }
@@ -2903,14 +2864,12 @@ long wxListMainWindow::FindItem(long start, const wxString& str, bool WXUNUSED(p
long pos = start; long pos = start;
wxString tmp = str; wxString tmp = str;
if (pos < 0) pos = 0; if (pos < 0) pos = 0;
wxNode *node = m_lines.Nth( (size_t)pos ); for (size_t i = pos; i < m_lines.GetCount(); i++)
while (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[i];
wxString s = ""; wxString s = "";
line->GetText( 0, s ); line->GetText( 0, s );
if (s == tmp) return pos; if (s == tmp) return pos;
node = node->Next();
pos++; pos++;
} }
return -1; return -1;
@@ -2920,14 +2879,12 @@ long wxListMainWindow::FindItem(long start, long data)
{ {
long pos = start; long pos = start;
if (pos < 0) pos = 0; if (pos < 0) pos = 0;
wxNode *node = m_lines.Nth( (size_t)pos ); for (size_t i = pos; i < m_lines.GetCount(); i++)
while (node)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[i];
wxListItem item; wxListItem item;
line->GetItem( 0, item ); line->GetItem( 0, item );
if (item.m_data == data) return pos; if (item.m_data == data) return pos;
node = node->Next();
pos++; pos++;
} }
return -1; return -1;
@@ -2937,18 +2894,16 @@ long wxListMainWindow::HitTest( int x, int y, int &flags )
{ {
CalcUnscrolledPosition( x, y, &x, &y ); CalcUnscrolledPosition( x, y, &x, &y );
wxNode *node = m_lines.First();
int count = 0; int count = 0;
while (node) for (size_t i = 0; i < m_lines.GetCount(); i++)
{ {
wxListLineData *line = (wxListLineData*)node->Data(); wxListLineData *line = &m_lines[i];
long ret = line->IsHit( x, y ); long ret = line->IsHit( x, y );
if (ret & flags) if (ret & flags)
{ {
flags = (int)ret; flags = (int)ret;
return count; return count;
} }
node = node->Next();
count++; count++;
} }
return -1; return -1;
@@ -2976,14 +2931,13 @@ void wxListMainWindow::InsertItem( wxListItem &item )
} }
line->SetItem( 0, item ); line->SetItem( 0, item );
if ((item.m_itemId >= 0) && (item.m_itemId < (int)m_lines.GetCount())) if ((item.m_itemId >= 0) && ((size_t)item.m_itemId < m_lines.GetCount()))
{ {
wxNode *node = m_lines.Nth( (size_t)item.m_itemId ); m_lines.Insert( line, (size_t)item.m_itemId );
if (node) m_lines.Insert( node, line );
} }
else else
{ {
m_lines.Append( line ); m_lines.Add( line );
} }
} }
@@ -3010,10 +2964,10 @@ void wxListMainWindow::InsertColumn( long col, wxListItem &item )
wxListCtrlCompare list_ctrl_compare_func_2; wxListCtrlCompare list_ctrl_compare_func_2;
long list_ctrl_compare_data; long list_ctrl_compare_data;
int LINKAGEMODE list_ctrl_compare_func_1( const void *arg1, const void *arg2 ) int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 )
{ {
wxListLineData *line1 = *((wxListLineData**)arg1); wxListLineData *line1 = *arg1;
wxListLineData *line2 = *((wxListLineData**)arg2); wxListLineData *line2 = *arg2;
wxListItem item; wxListItem item;
line1->GetItem( 0, item ); line1->GetItem( 0, item );
long data1 = item.m_data; long data1 = item.m_data;