static const int WIDTH_COL_DEFAULT = 80;
static const int WIDTH_COL_MIN = 10;
+// the space between the image and the text in the report mode
+static const int IMAGE_MARGIN_IN_REPORT_MODE = 5;
+
// ============================================================================
// private classes
// ============================================================================
void RefreshLine( size_t line );
void RefreshLines( size_t lineFrom, size_t lineTo );
+ // refresh all selected items
+ void RefreshSelected();
+
// refresh all lines below the given one: the difference with
// RefreshLines() is that the index here might not be a valid one (happens
// when the last line is deleted)
// get the y position of the given line (only for report view)
wxCoord GetLineY(size_t line) const;
+ // get the brush to use for the item highlighting
+ wxBrush *GetHighlightBrush() const
+ {
+ return m_hasFocus ? m_highlightBrush : m_highlightUnfocusedBrush;
+ }
+
//protected:
// the array of all line objects for a non virtual list control
wxListLineDataArray m_lines;
// call
bool m_dirty;
- wxBrush *m_highlightBrush;
wxColour *m_highlightColour;
int m_xScroll,
m_yScroll;
size_t m_lineFrom,
m_lineTo;
+ // the brushes to use for item highlighting when we do/don't have focus
+ wxBrush *m_highlightBrush,
+ *m_highlightUnfocusedBrush;
+
DECLARE_DYNAMIC_CLASS(wxListMainWindow);
DECLARE_EVENT_TABLE()
};
{
if ( highlighted )
{
- dc->SetBrush( *m_owner->m_highlightBrush );
+ dc->SetBrush( *m_owner->GetHighlightBrush() );
}
else
{
if (item->HasText())
{
wxRect rectLabel = m_gi->m_rectLabel;
+
+ wxDCClipper clipper(*dc, rectLabel);
dc->DrawText( item->GetText(), rectLabel.x, rectLabel.y );
}
}
{
wxListItemData *item = node->GetData();
+ int width = m_owner->GetColumnWidth(col++);
int xOld = x;
+ x += width;
if ( item->HasImage() )
{
int ix, iy;
- m_owner->DrawImage( item->GetImage(), dc, x, y );
+ m_owner->DrawImage( item->GetImage(), dc, xOld, y );
m_owner->GetImageSize( item->GetImage(), ix, iy );
- x += ix + 5; // FIXME: what is "5"?
- }
- int width = m_owner->GetColumnWidth(col++);
+ ix += IMAGE_MARGIN_IN_REPORT_MODE;
+
+ xOld += ix;
+ width -= ix;
+ }
- wxDCClipper clipper(*dc, x, y, width, rect.height);
+ wxDCClipper clipper(*dc, xOld, y, width, rect.height);
if ( item->HasText() )
{
- dc->DrawText( item->GetText(), x, y );
+ dc->DrawText( item->GetText(), xOld, y );
}
- x = xOld + width;
-
node = node->GetNext();
}
}
dc.SetPen( *wxWHITE_PEN );
DoDrawRect( &dc, x, HEADER_OFFSET_Y, cw, h-2 );
- dc.SetClippingRegion( x, HEADER_OFFSET_Y, cw-5, h-4 );
- dc.DrawText( item.GetText(), x + EXTRA_WIDTH, HEADER_OFFSET_Y + EXTRA_HEIGHT );
- dc.DestroyClippingRegion();
+ wxDCClipper clipper(dc, x, HEADER_OFFSET_Y, cw-5, h-4 );
+
+ dc.DrawText( item.GetText(),
+ x + EXTRA_WIDTH, HEADER_OFFSET_Y + EXTRA_HEIGHT );
+
x += wCol;
if (xEnd > w+5)
{
Init();
- m_highlightBrush = (wxBrush *) NULL;
+ m_highlightBrush =
+ m_highlightUnfocusedBrush = (wxBrush *) NULL;
m_xScroll =
m_yScroll = 0;
{
Init();
- m_highlightBrush = new wxBrush( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_HIGHLIGHT), wxSOLID );
+ m_highlightBrush = new wxBrush
+ (
+ wxSystemSettings::GetSystemColour
+ (
+ wxSYS_COLOUR_HIGHLIGHT
+ ),
+ wxSOLID
+ );
+
+ m_highlightUnfocusedBrush = new wxBrush
+ (
+ wxSystemSettings::GetSystemColour
+ (
+ wxSYS_COLOUR_BTNSHADOW
+ ),
+ wxSOLID
+ );
+
wxSize sz = size;
sz.y = 25;
DoDeleteAllItems();
delete m_highlightBrush;
+ delete m_highlightUnfocusedBrush;
delete m_renameTimer;
}
else // !virtual
{
wxListLineData *ld = GetLine(line);
- wxCHECK_MSG( ld, FALSE, _T("invalid index in IsHighlighted") );
+ wxCHECK_MSG( ld, FALSE, _T("invalid index in HighlightLine") );
changed = ld->Highlight(highlight);
}
}
}
+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::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
// Note: a wxPaintDC must be constructed even if no drawing is
GetLine(line)->DrawInReportMode( &dc,
rectLine,
GetLineHighlightRect(line),
- m_hasFocus && IsHighlighted(line) );
+ IsHighlighted(line) );
}
if ( HasFlag(wxLC_HRULES) )
if ( HasCurrent() )
{
// don't draw rect outline under Max if we already have the background
- // color
+ // color but under other platforms only draw it if we do: it is a bit
+ // silly to draw "focus rect" if we don't have focus!
#ifdef __WXMAC__
if ( !m_hasFocus )
-#endif // !__WXMAC__
+#else // !__WXMAC__
+ if ( m_hasFocus )
+#endif // __WXMAC__/!__WXMAC__
{
dc.SetPen( *wxBLACK_PEN );
dc.SetBrush( *wxTRANSPARENT_BRUSH );
{
m_hasFocus = TRUE;
- if ( HasCurrent() )
- RefreshLine( m_current );
-
if (!GetParent())
return;
+ RefreshSelected();
+
#ifdef __WXGTK__
g_focusWindow = GetParent();
#endif
{
m_hasFocus = FALSE;
- if ( HasCurrent() )
- RefreshLine( m_current );
+ RefreshSelected();
}
void wxListMainWindow::DrawImage( int index, wxDC *dc, int x, int y )
// been added and its position is not known yet
if ( m_dirty )
{
- m_dirty = FALSE;
-
RecalculatePositions(TRUE /* no refresh */);
}