Have wxGenericListCtrl record and store the selection state of each column, and on OS X, use this to correctly draw selected headers. Also, move to DrawItemSelectionRect for drawing the background selection.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43507 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Kevin Ollivier
2006-11-19 06:32:08 +00:00
parent a4609ab847
commit df0edf4443

View File

@@ -203,6 +203,7 @@ public:
void SetItem( const wxListItem &item ); void SetItem( const wxListItem &item );
void SetPosition( int x, int y ); void SetPosition( int x, int y );
void SetWidth( int w ); void SetWidth( int w );
void SetState( int state );
void SetFormat( int format ); void SetFormat( int format );
void SetHeight( int h ); void SetHeight( int h );
bool HasImage() const; bool HasImage() const;
@@ -217,6 +218,7 @@ public:
int GetImage() const; int GetImage() const;
int GetWidth() const; int GetWidth() const;
int GetFormat() const; int GetFormat() const;
int GetState() const;
protected: protected:
long m_mask; long m_mask;
@@ -227,6 +229,7 @@ protected:
int m_xpos, int m_xpos,
m_ypos; m_ypos;
int m_height; int m_height;
int m_state;
private: private:
void Init(); void Init();
@@ -1002,6 +1005,7 @@ void wxListHeaderData::Init()
m_xpos = 0; m_xpos = 0;
m_ypos = 0; m_ypos = 0;
m_height = 0; m_height = 0;
m_state = 0;
} }
wxListHeaderData::wxListHeaderData() wxListHeaderData::wxListHeaderData()
@@ -1031,6 +1035,9 @@ void wxListHeaderData::SetItem( const wxListItem &item )
if ( m_mask & wxLIST_MASK_WIDTH ) if ( m_mask & wxLIST_MASK_WIDTH )
SetWidth(item.m_width); SetWidth(item.m_width);
if ( m_mask & wxLIST_MASK_STATE )
SetState(item.m_state);
} }
void wxListHeaderData::SetPosition( int x, int y ) void wxListHeaderData::SetPosition( int x, int y )
@@ -1049,6 +1056,11 @@ void wxListHeaderData::SetWidth( int w )
m_width = w < 0 ? WIDTH_COL_DEFAULT : w; m_width = w < 0 ? WIDTH_COL_DEFAULT : w;
} }
void wxListHeaderData::SetState( int flag )
{
m_state = flag;
}
void wxListHeaderData::SetFormat( int format ) void wxListHeaderData::SetFormat( int format )
{ {
m_format = format; m_format = format;
@@ -1071,6 +1083,7 @@ void wxListHeaderData::GetItem( wxListItem& item )
item.m_image = m_image; item.m_image = m_image;
item.m_format = m_format; item.m_format = m_format;
item.m_width = m_width; item.m_width = m_width;
item.m_state = m_state;
} }
int wxListHeaderData::GetImage() const int wxListHeaderData::GetImage() const
@@ -1088,6 +1101,11 @@ int wxListHeaderData::GetFormat() const
return m_format; return m_format;
} }
int wxListHeaderData::GetState() const
{
return m_state;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxListLineData // wxListLineData
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -1442,7 +1460,7 @@ void wxListLineData::Draw( wxDC *dc )
wxListItemAttr *attr = GetAttr(); wxListItemAttr *attr = GetAttr();
if ( SetAttributes(dc, attr, highlighted) ) if ( SetAttributes(dc, attr, highlighted) )
#ifndef __WXGTK20__ #if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
{ {
dc->DrawRectangle( m_gi->m_rectHighlight ); dc->DrawRectangle( m_gi->m_rectHighlight );
} }
@@ -1501,7 +1519,7 @@ void wxListLineData::DrawInReportMode( wxDC *dc,
// GetAttr() and move these lines into the loop below // GetAttr() and move these lines into the loop below
wxListItemAttr *attr = GetAttr(); wxListItemAttr *attr = GetAttr();
if ( SetAttributes(dc, attr, highlighted) ) if ( SetAttributes(dc, attr, highlighted) )
#ifndef __WXGTK20__ #if ( !defined(__WXGTK20__) && !defined(__WXMAC__) )
{ {
dc->DrawRectangle( rectHL ); dc->DrawRectangle( rectHL );
} }
@@ -1779,13 +1797,26 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
int ch = h - 2; int ch = h - 2;
#endif #endif
int flags = 0;
if (!m_parent->IsEnabled())
flags |= wxCONTROL_DISABLED;
// NB: The code below is not really Mac-specific, but since we are close
// to 2.8 release and I don't have time to test on other platforms, I
// defined this only for wxMac. If this behavior is desired on
// other platforms, please go ahead and revise or remove the #ifdef.
#ifdef __WXMAC__
if ( !m_owner->IsVirtual() && (item.m_mask & wxLIST_MASK_STATE) &&
(item.m_state & wxLIST_STATE_SELECTED) )
flags |= wxCONTROL_SELECTED;
#endif
wxRendererNative::Get().DrawHeaderButton wxRendererNative::Get().DrawHeaderButton
( (
this, this,
dc, dc,
wxRect(x, HEADER_OFFSET_Y, cw, ch), wxRect(x, HEADER_OFFSET_Y, cw, ch),
m_parent->IsEnabled() ? 0 flags
: (int)wxCONTROL_DISABLED
); );
// see if we have enough space for the column label // see if we have enough space for the column label
@@ -1981,6 +2012,22 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
} }
else // click on a column else // click on a column
{ {
// record the selected state of the columns
if (event.LeftDown())
{
for (int i=0; i < m_owner->GetColumnCount(); i++)
{
wxListItem colItem;
m_owner->GetColumn(i, colItem);
long state = colItem.GetState();
if (i == m_column)
colItem.SetState(state | wxLIST_STATE_SELECTED);
else
colItem.SetState(state & ~wxLIST_STATE_SELECTED);
m_owner->SetColumn(i, colItem);
}
}
SendListEvent( event.LeftDown() SendListEvent( event.LeftDown()
? wxEVT_COMMAND_LIST_COL_CLICK ? wxEVT_COMMAND_LIST_COL_CLICK
: wxEVT_COMMAND_LIST_COL_RIGHT_CLICK, : wxEVT_COMMAND_LIST_COL_RIGHT_CLICK,
@@ -2243,14 +2290,6 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent,
{ {
Init(); Init();
#ifdef __WXMAC__
// OS X sel item highlight color differs from text highlight color, which is
// what wxSYS_COLOUR_HIGHLIGHT returns.
RGBColor hilight;
GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor, 32, true, &hilight);
m_highlightBrush = new wxBrush( wxColour(hilight.red, hilight.green, hilight.blue ), wxSOLID );
#else
m_highlightBrush = new wxBrush m_highlightBrush = new wxBrush
( (
wxSystemSettings::GetColour wxSystemSettings::GetColour
@@ -2259,14 +2298,7 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent,
), ),
wxSOLID wxSOLID
); );
#endif
#ifdef __WXMAC__
// on Mac, this color also differs from the wxSYS_COLOUR_BTNSHADOW, enough to be noticable.
// I don't know if BTNSHADOW is appropriate in other contexts, so I'm just changing it here.
GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor, 32, true, &hilight);
m_highlightUnfocusedBrush = new wxBrush( wxColour(hilight.red, hilight.green, hilight.blue ), wxSOLID );
#else
m_highlightUnfocusedBrush = new wxBrush m_highlightUnfocusedBrush = new wxBrush
( (
wxSystemSettings::GetColour wxSystemSettings::GetColour
@@ -2275,7 +2307,6 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent,
), ),
wxSOLID wxSOLID
); );
#endif
SetScrollbars( 0, 0, 0, 0, 0, 0 ); SetScrollbars( 0, 0, 0, 0, 0, 0 );