+ if ( m_small_image_list && m_small_image_list->GetImageCount() )
+ {
+ int iw = 0;
+ int ih = 0;
+ m_small_image_list->GetSize(0, iw, ih);
+ y = wxMax(y, ih);
+ }
+
+ y += EXTRA_HEIGHT;
+ self->m_lineHeight = y + LINE_SPACING;
+ }
+
+ return m_lineHeight;
+}
+
+wxCoord wxListMainWindow::GetLineY(size_t line) const
+{
+ wxASSERT_MSG( InReportView(), _T("only works in report mode") );
+
+ return LINE_SPACING + line*GetLineHeight();
+}
+
+wxRect wxListMainWindow::GetLineRect(size_t line) const
+{
+ if ( !InReportView() )
+ return GetLine(line)->m_gi->m_rectAll;
+
+ wxRect rect;
+ rect.x = HEADER_OFFSET_X;
+ rect.y = GetLineY(line);
+ rect.width = GetHeaderWidth();
+ rect.height = GetLineHeight();
+
+ return rect;
+}
+
+wxRect wxListMainWindow::GetLineLabelRect(size_t line) const
+{
+ if ( !InReportView() )
+ return GetLine(line)->m_gi->m_rectLabel;
+
+ wxRect rect;
+ rect.x = HEADER_OFFSET_X;
+ rect.y = GetLineY(line);
+ rect.width = GetColumnWidth(0);
+ rect.height = GetLineHeight();
+
+ return rect;
+}
+
+wxRect wxListMainWindow::GetLineIconRect(size_t line) const
+{
+ if ( !InReportView() )
+ return GetLine(line)->m_gi->m_rectIcon;
+
+ wxListLineData *ld = GetLine(line);
+ wxASSERT_MSG( ld->HasImage(), _T("should have an image") );
+
+ wxRect rect;
+ rect.x = HEADER_OFFSET_X;
+ rect.y = GetLineY(line);
+ GetImageSize(ld->GetImage(), rect.width, rect.height);
+
+ return rect;
+}
+
+wxRect wxListMainWindow::GetLineHighlightRect(size_t line) const
+{
+ return InReportView() ? GetLineRect(line)
+ : GetLine(line)->m_gi->m_rectHighlight;
+}
+
+long wxListMainWindow::HitTestLine(size_t line, int x, int y) const
+{
+ wxASSERT_MSG( line < GetItemCount(), _T("invalid line in HitTestLine") );
+
+ wxListLineData *ld = GetLine(line);
+
+ if ( ld->HasImage() && GetLineIconRect(line).Inside(x, y) )
+ return wxLIST_HITTEST_ONITEMICON;
+
+ // VS: Testing for "ld->HasText() || InReportView()" instead of
+ // "ld->HasText()" is needed to make empty lines in report view
+ // possible
+ if ( ld->HasText() || InReportView() )
+ {
+ wxRect rect = InReportView() ? GetLineRect(line)
+ : GetLineLabelRect(line);
+
+ if ( rect.Inside(x, y) )
+ return wxLIST_HITTEST_ONITEMLABEL;
+ }
+
+ 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++;