+ return 0;
+}
+
+// ----------------------------------------------------------------------------
+// highlight (selection) handling
+// ----------------------------------------------------------------------------
+
+bool wxListMainWindow::IsHighlighted(size_t line) const
+{
+ if ( IsVirtual() )
+ {
+ return m_selStore.IsSelected(line);
+ }
+ else // !virtual
+ {
+ wxListLineData *ld = GetLine(line);
+ wxCHECK_MSG( ld, false, _T("invalid index in IsHighlighted") );
+
+ return ld->IsHighlighted();
+ }
+}
+
+void wxListMainWindow::HighlightLines( size_t lineFrom,
+ size_t lineTo,
+ bool highlight )
+{
+ if ( IsVirtual() )
+ {
+ wxArrayInt linesChanged;
+ if ( !m_selStore.SelectRange(lineFrom, lineTo, highlight,
+ &linesChanged) )
+ {
+ // meny items changed state, refresh everything
+ RefreshLines(lineFrom, lineTo);
+ }
+ else // only a few items changed state, refresh only them
+ {
+ size_t count = linesChanged.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ RefreshLine(linesChanged[n]);
+ }
+ }
+ }
+ else // iterate over all items in non report view
+ {
+ for ( size_t line = lineFrom; line <= lineTo; line++ )
+ {
+ if ( HighlightLine(line, highlight) )
+ {
+ RefreshLine(line);
+ }
+ }
+ }
+}
+
+bool wxListMainWindow::HighlightLine( size_t line, bool highlight )
+{
+ bool changed;
+
+ if ( IsVirtual() )
+ {
+ changed = m_selStore.SelectItem(line, highlight);
+ }
+ else // !virtual
+ {
+ wxListLineData *ld = GetLine(line);
+ wxCHECK_MSG( ld, false, _T("invalid index in HighlightLine") );
+
+ changed = ld->Highlight(highlight);
+ }
+
+ if ( changed )
+ {
+ SendNotify( line, highlight ? wxEVT_COMMAND_LIST_ITEM_SELECTED
+ : wxEVT_COMMAND_LIST_ITEM_DESELECTED );
+ }
+
+ return changed;
+}
+
+void wxListMainWindow::RefreshLine( size_t line )
+{
+ if ( InReportView() )
+ {
+ size_t visibleFrom, visibleTo;
+ GetVisibleLinesRange(&visibleFrom, &visibleTo);
+
+ if ( line < visibleFrom || line > visibleTo )
+ return;
+ }
+
+ wxRect rect = GetLineRect(line);
+
+ 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") );
+
+ wxASSERT_MSG( lineTo < GetItemCount(), _T("invalid line range") );
+
+ if ( InReportView() )
+ {
+ size_t visibleFrom, visibleTo;
+ GetVisibleLinesRange(&visibleFrom, &visibleTo);
+
+ if ( lineFrom < visibleFrom )
+ lineFrom = visibleFrom;
+ if ( lineTo > visibleTo )
+ lineTo = visibleTo;
+
+ wxRect rect;
+ rect.x = 0;
+ rect.y = GetLineY(lineFrom);
+ rect.width = GetClientSize().x;
+ rect.height = GetLineY(lineTo) - rect.y + GetLineHeight();
+
+ 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::RefreshAfter( size_t lineFrom )
+{
+ if ( InReportView() )
+ {
+ size_t visibleFrom, visibleTo;
+ GetVisibleLinesRange(&visibleFrom, &visibleTo);
+
+ if ( lineFrom < visibleFrom )
+ lineFrom = visibleFrom;
+ else if ( lineFrom > visibleTo )
+ return;
+
+ wxRect rect;
+ rect.x = 0;
+ rect.y = GetLineY(lineFrom);
+ CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+
+ wxSize size = GetClientSize();
+ rect.width = size.x;
+ // refresh till the bottom of the window
+ rect.height = size.y - rect.y;
+
+ RefreshRect( rect );
+ }
+ else // !report
+ {
+ // TODO: how to do it more efficiently?
+ m_dirty = true;
+ }
+}
+
+void wxListMainWindow::RefreshSelected()
+{
+ if ( IsEmpty() )
+ return;
+
+ size_t from, to;
+ if ( InReportView() )
+ {
+ GetVisibleLinesRange(&from, &to);
+ }
+ else // !virtual
+ {
+ from = 0;
+ to = GetItemCount() - 1;
+ }
+
+ if ( HasCurrent() && m_current >= from && m_current <= to )
+ {
+ RefreshLine(m_current);
+ }
+
+ for ( size_t line = from; line <= to; line++ )
+ {
+ // NB: the test works as expected even if m_current == -1
+ if ( line != m_current && IsHighlighted(line) )
+ {
+ RefreshLine(line);
+ }
+ }
+}
+
+void wxListMainWindow::Freeze()
+{
+ m_freezeCount++;
+}
+
+void wxListMainWindow::Thaw()
+{
+ wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen list control?") );
+
+ if ( !--m_freezeCount )
+ {
+ Refresh();
+ }