+bool wxListMainWindow::IsHilighted(size_t line) const
+{
+ if ( IsVirtual() )
+ {
+ return m_selections.Index(line) != wxNOT_FOUND;
+ }
+ else // !virtual
+ {
+ wxListLineData *ld = GetLine(line);
+ wxCHECK_MSG( ld, FALSE, _T("invalid index in IsHilighted") );
+
+ return ld->IsHilighted();
+ }
+}
+
+bool wxListMainWindow::HilightLine( size_t line, bool hilight )
+{
+ bool changed;
+
+ if ( IsVirtual() )
+ {
+ changed = FALSE;
+
+ int index = m_selections.Index(line);
+ if ( hilight )
+ {
+ if ( index == wxNOT_FOUND )
+ {
+ m_selections.Add(line);
+ changed = TRUE;
+ }
+ }
+ else // !hilight
+ {
+ if ( index != wxNOT_FOUND )
+ {
+ m_selections.RemoveAt((size_t)index);
+ changed = TRUE;
+ }
+ }
+ }
+ else // !virtual
+ {
+ wxListLineData *ld = GetLine(line);
+ wxCHECK_MSG( ld, FALSE, _T("invalid index in IsHilighted") );
+
+ changed = ld->Hilight(hilight);
+ }
+
+ if ( changed )
+ {
+ SendNotify( line, hilight ? wxEVT_COMMAND_LIST_ITEM_SELECTED
+ : wxEVT_COMMAND_LIST_ITEM_DESELECTED );
+ }
+
+ return changed;
+}
+
+void wxListMainWindow::RefreshLine( size_t line )
+{
+ wxRect rect = GetLine(line)->GetRect();
+
+ CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+ RefreshRect( rect );
+}
+
+void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo )
+{
+ // we suppose that they are ordered by caller
+ wxASSERT_MSG( lineFrom <= lineTo, _T("indices in disorder") );
+
+ if ( HasFlag(wxLC_REPORT) )
+ {
+ if ( lineFrom < m_lineFrom )
+ lineFrom = m_lineFrom;
+ if ( lineTo > m_lineTo )
+ lineTo = m_lineTo;
+
+ wxRect rect;
+ rect.x = 0;
+ rect.y = GetLineY(lineFrom);
+ rect.width = GetClientSize().x;
+ rect.height = GetLineY(lineTo) - rect.y;
+
+ CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+ RefreshRect( rect );
+ }
+ else // !report
+ {
+ // TODO: this should be optimized...
+ for ( size_t line = lineFrom; line <= lineTo; line++ )
+ {
+ RefreshLine(line);
+ }
+ }
+}
+
+void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
+{
+ // Note: a wxPaintDC must be constructed even if no drawing is
+ // done (a Windows requirement).
+ wxPaintDC dc( this );
+
+ if ( m_dirty )
+ {
+ // postpone redrawing until the next OnIdle() call to minimize flicker
+ return;
+ }
+
+ if ( IsEmpty() )
+ {
+ // empty control. nothing to draw
+ return;
+ }
+
+ PrepareDC( dc );
+
+ int dev_x, dev_y;
+ CalcScrolledPosition( 0, 0, &dev_x, &dev_y );
+
+ dc.BeginDrawing();
+
+ dc.SetFont( GetFont() );
+
+ if ( HasFlag(wxLC_REPORT) )
+ {
+ int lineSpacing = GetLineHeight();
+
+ for ( size_t line = m_lineFrom; line <= m_lineTo; line++ )
+ {
+ GetLine(line)->Draw( &dc,
+ GetLineY(line),
+ lineSpacing,
+ IsHilighted(line) );
+ }
+
+ if ( HasFlag(wxLC_HRULES) )
+ {
+ wxPen pen(wxSystemSettings::
+ GetSystemColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
+ wxSize clientSize = GetClientSize();
+
+ for ( size_t i = m_lineFrom; i <= m_lineTo; i++ )
+ {
+ dc.SetPen(pen);
+ dc.SetBrush( *wxTRANSPARENT_BRUSH );
+ dc.DrawLine(0 - dev_x, i*lineSpacing,
+ clientSize.x - dev_x, i*lineSpacing);
+ }
+
+ // Draw last horizontal rule
+ if ( m_lineTo > m_lineFrom )
+ {
+ dc.SetPen(pen);
+ dc.SetBrush( *wxTRANSPARENT_BRUSH );
+ dc.DrawLine(0 - dev_x, m_lineTo*lineSpacing,
+ clientSize.x - dev_x , m_lineTo*lineSpacing );
+ }