item->SetAttr(attr);
}
-bool wxListLineData::SetAttributes(wxDC *dc,
- const wxListItemAttr *attr,
- bool highlighted)
+void wxListLineData::ApplyAttributes(wxDC *dc,
+ const wxRect& rectHL,
+ bool highlighted,
+ bool current)
{
- wxWindow *listctrl = m_owner->GetParent();
+ const wxListItemAttr * const attr = GetAttr();
+
+ wxWindow * const listctrl = m_owner->GetParent();
+
+ const bool hasFocus = listctrl->HasFocus()
+#if defined(__WXMAC__) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
+ && IsControlActive( (ControlRef)listctrl->GetHandle() )
+#endif
+ ;
// fg colour
// arithmetics on wxColour, unfortunately)
wxColour colText;
if ( highlighted )
-#ifdef __WXMAC__
{
- if (m_owner->HasFocus()
-#if !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
- && IsControlActive( (ControlRef)m_owner->GetHandle() )
-#endif
- )
+#ifdef __WXMAC__
+ if ( hasFocus )
colText = *wxWHITE;
else
colText = *wxBLACK;
- }
#else
colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
#endif
+ }
else if ( attr && attr->HasTextColour() )
colText = attr->GetTextColour();
else
dc->SetFont(font);
- // bg colour
- bool hasBgCol = attr && attr->HasBackgroundColour();
- if ( highlighted || hasBgCol )
- {
- if ( highlighted )
- dc->SetBrush( *m_owner->GetHighlightBrush() );
- else
- dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxBRUSHSTYLE_SOLID));
-
- dc->SetPen( *wxTRANSPARENT_PEN );
-
- return true;
- }
-
- return false;
-}
-
-void wxListLineData::Draw( wxDC *dc )
-{
- wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
- wxCHECK_RET( node, wxT("no subitems at all??") );
-
- bool highlighted = IsHighlighted();
-
- wxListItemAttr *attr = GetAttr();
-
- if ( SetAttributes(dc, attr, highlighted) )
+ // background
+ if ( highlighted )
{
- int flags = 0;
- if (highlighted)
- flags |= wxCONTROL_SELECTED;
- if (m_owner->HasFocus()
-#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
- && IsControlActive( (ControlRef)m_owner->GetHandle() )
-#endif
- )
+ // Use the renderer method to ensure that the selected items use the
+ // native look.
+ int flags = wxCONTROL_SELECTED;
+ if ( hasFocus )
flags |= wxCONTROL_FOCUSED;
+ if (current)
+ flags |= wxCONTROL_CURRENT;
wxRendererNative::Get().
- DrawItemSelectionRect( m_owner, *dc, m_gi->m_rectHighlight, flags );
+ DrawItemSelectionRect( m_owner, *dc, rectHL, flags );
+ }
+ else if ( attr && attr->HasBackgroundColour() )
+ {
+ // Draw the background using the items custom background colour.
+ dc->SetBrush(attr->GetBackgroundColour());
+ dc->SetPen(*wxTRANSPARENT_PEN);
+ dc->DrawRectangle(rectHL);
}
// just for debugging to better see where the items are
dc->SetPen(*wxGREEN_PEN);
dc->DrawRectangle( m_gi->m_rectIcon );
#endif
+}
+
+void wxListLineData::Draw(wxDC *dc, bool current)
+{
+ wxListItemDataList::compatibility_iterator node = m_items.GetFirst();
+ wxCHECK_RET( node, wxT("no subitems at all??") );
+
+ ApplyAttributes(dc, m_gi->m_rectHighlight, IsHighlighted(), current);
wxListItemData *item = node->GetData();
if (item->HasImage())
// TODO: later we should support setting different attributes for
// different columns - to do it, just add "col" argument to
// GetAttr() and move these lines into the loop below
- wxListItemAttr *attr = GetAttr();
- if ( SetAttributes(dc, attr, highlighted) )
- {
- int flags = 0;
- if (highlighted)
- flags |= wxCONTROL_SELECTED;
- if (m_owner->HasFocus())
- flags |= wxCONTROL_FOCUSED;
- if (current)
- flags |= wxCONTROL_CURRENT;
- wxRendererNative::Get().DrawItemSelectionRect( m_owner, *dc, rectHL, flags );
- }
+
+ ApplyAttributes(dc, rectHL, highlighted, current);
wxCoord x = rect.x + HEADER_OFFSET_X,
yMid = rect.y + rect.height/2;
size_t count = GetItemCount();
for ( size_t i = 0; i < count; i++ )
{
- GetLine(i)->Draw( &dc );
+ GetLine(i)->Draw( &dc, i == m_current );
}
}
+ // DrawFocusRect() is unusable under Mac, it draws outside of the highlight
+ // rectangle somehow and so leaves traces when the item is not selected any
+ // more, see #12229.
+#ifndef __WXMAC__
if ( HasCurrent() )
{
int flags = 0;
wxRendererNative::Get().
DrawFocusRect(this, dc, GetLineHighlightRect(m_current), flags);
}
+#endif // !__WXMAC__
}
void wxListMainWindow::HighlightAll( bool on )
if (parent->GetEventHandler()->ProcessEvent( ke ))
return;
+ // send a list event
+ wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, parent->GetId() );
+ le.m_itemIndex = m_current;
+ if (HasCurrent())
+ GetLine(m_current)->GetItem( 0, le.m_item );
+ le.m_code = event.GetKeyCode();
+ le.SetEventObject( parent );
+ if (parent->GetEventHandler()->ProcessEvent( le ))
+ return;
+
event.Skip();
}
{
wxWindow *parent = GetParent();
- // send a list_key event up
- if ( HasCurrent() )
- {
- wxListEvent le( wxEVT_COMMAND_LIST_KEY_DOWN, GetParent()->GetId() );
- le.m_itemIndex = m_current;
- GetLine(m_current)->GetItem( 0, le.m_item );
- le.m_code = event.GetKeyCode();
- le.SetEventObject( parent );
- parent->GetEventHandler()->ProcessEvent( le );
- }
-
// propagate the char event upwards
wxKeyEvent ke(event);
ke.SetEventObject( parent );