\pythonnote{In place of a single overloaded method name, wxPython
implements the following methods:\par
\indented{2cm}{\begin{twocollist}
-\twocolitem{\bf{InsertColumn(col, heading, format=wxLIST_FORMAT_LEFT,
+\twocolitem{\bf{InsertColumn(col, heading, format=wxLIST\_FORMAT\_LEFT,
width=-1)}}{Creates a column using a header string only.}
\twocolitem{\bf{InsertColumnInfo(col, item)}}{Creates a column using a
wxListInfo.}
The {\bf m\_stateMask} and {\bf m\_state} members take flags from the following:
+The wxListItem object can also contain item-specific colour and font
+information: for this you need to call one of SetTextColour(),
+SetBackgroundColour() or SetFont() functions on it passing it the colour/font
+to use. If the colour/font is not specified, the default list control
+colour/font is used.
+
\twocolwidtha{5cm}
\begin{twocollist}\itemsep=0pt
\twocolitem{wxLIST\_STATE\_DONTCARE}{Don't care what the state is. Win32 only. }
long m_data;
int m_xpos,m_ypos;
int m_width,m_height;
- wxColour *m_colour;
+
+ wxListItemAttr *m_attr;
public:
wxListItemData();
+ ~wxListItemData() { delete m_attr; }
+
wxListItemData( const wxListItem &info );
void SetItem( const wxListItem &info );
void SetText( const wxString &s );
void SetData( long data );
void SetPosition( int x, int y );
void SetSize( int width, int height );
- void SetColour( wxColour *col );
bool HasImage() const;
bool HasText() const;
bool IsHit( int x, int y ) const;
void GetText( wxString &s );
+ const wxString& GetText() { return m_text; }
int GetX( void ) const;
int GetY( void ) const;
int GetWidth() const;
int GetHeight() const;
int GetImage() const;
- void GetItem( wxListItem &info );
- wxColour *GetColour();
+ void GetItem( wxListItem &info ) const;
+
+ wxListItemAttr *GetAttributes() const { return m_attr; }
private:
DECLARE_DYNAMIC_CLASS(wxListItemData);
void AssignRect( wxRect &dest, const wxRect &source );
private:
+ void SetAttributes(wxDC *dc,
+ const wxListItemAttr *attr,
+ const wxColour& colText, const wxFont& font);
+
DECLARE_DYNAMIC_CLASS(wxListLineData);
};
bool *accept, wxString *res, wxListMainWindow *owner,
const wxString &value = "",
const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize,
+ int style = 0,
#if wxUSE_VALIDATORS
- int style = 0, const wxValidator& validator = wxDefaultValidator,
+ const wxValidator& validator = wxDefaultValidator,
#endif
const wxString &name = "wxListTextCtrlText" );
void OnChar( wxKeyEvent &event );
void OnSetFocus( wxFocusEvent &event );
void OnKillFocus( wxFocusEvent &event );
void OnSize( wxSizeEvent &event );
- void OnScroll(wxScrollWinEvent& event) ;
-
+ void OnScroll(wxScrollWinEvent& event) ;
+
void DrawImage( int index, wxDC *dc, int x, int y );
void GetImageSize( int index, int &width, int &height );
int GetIndexOfLine( const wxListLineData *line );
void SetItemSpacing( int spacing, bool isSmall = FALSE );
int GetItemSpacing( bool isSmall ) const;
int GetSelectedItemCount() const;
-// wxColour GetTextColour() const; // wxGLC has colours for every Item (see wxListItem)
-// void SetTextColour(const wxColour& col);
+ wxColour GetTextColour() const;
+ void SetTextColour(const wxColour& col);
long GetTopItem() const;
void SetSingleStyle( long style, bool add = TRUE ) ;
m_ypos = 0;
m_width = 0;
m_height = 0;
- m_colour = wxBLACK;
+ m_attr = NULL;
}
wxListItemData::wxListItemData( const wxListItem &info )
{
m_image = -1;
m_data = 0;
- m_colour = (wxColour *)&info.GetTextColour();
+ m_attr = NULL;
+
SetItem( info );
}
if (info.m_mask & wxLIST_MASK_TEXT) m_text = info.m_text;
if (info.m_mask & wxLIST_MASK_IMAGE) m_image = info.m_image;
if (info.m_mask & wxLIST_MASK_DATA) m_data = info.m_data;
- m_colour = (wxColour *)&info.GetTextColour();
+
+ if ( info.HasAttributes() )
+ {
+ if ( m_attr )
+ *m_attr = *info.GetAttributes();
+ else
+ m_attr = new wxListItemAttr(*info.GetAttributes());
+ }
+
m_xpos = 0;
m_ypos = 0;
m_width = info.m_width;
if (height != -1) m_height = height;
}
-void wxListItemData::SetColour( wxColour *col )
-{
- m_colour = col;
-}
-
bool wxListItemData::HasImage() const
{
return (m_image >= 0);
return m_image;
}
-void wxListItemData::GetItem( wxListItem &info )
+void wxListItemData::GetItem( wxListItem &info ) const
{
info.m_text = m_text;
info.m_image = m_image;
info.m_data = m_data;
- info.SetTextColour(*m_colour);
-}
-wxColour *wxListItemData::GetColour()
-{
- return m_colour;
+ if ( m_attr )
+ {
+ if ( m_attr->HasTextColour() )
+ info.SetTextColour(m_attr->GetTextColour());
+ if ( m_attr->HasBackgroundColour() )
+ info.SetBackgroundColour(m_attr->GetBackgroundColour());
+ if ( m_attr->HasFont() )
+ info.SetFont(m_attr->GetFont());
+ }
}
//-----------------------------------------------------------------------------
if (node)
{
wxListItemData *item = (wxListItemData*)node->Data();
- wxString s;
- item->GetText( s );
+ wxString s = item->GetText();
long lw,lh;
dc->GetTextExtent( s, &lw, &lh );
if (lw > m_spacing) m_bound_all.width = lw;
if (node)
{
wxListItemData *item = (wxListItemData*)node->Data();
- wxString s;
- item->GetText( s );
+ wxString s = item->GetText();
long lw,lh;
dc->GetTextExtent( s, &lw, &lh );
m_bound_all.width = lw;
return -1;
}
+void wxListLineData::SetAttributes(wxDC *dc,
+ const wxListItemAttr *attr,
+ const wxColour& colText,
+ const wxFont& font)
+{
+ if ( attr && attr->HasTextColour() )
+ {
+ dc->SetTextForeground(attr->GetTextColour());
+ }
+ else
+ {
+ dc->SetTextForeground(colText);
+ }
+
+ if ( attr && attr->HasFont() )
+ {
+ dc->SetFont(attr->GetFont());
+ }
+ else
+ {
+ dc->SetFont(font);
+ }
+}
+
void wxListLineData::DoDraw( wxDC *dc, bool hilight, bool paintBG )
{
long dev_x = dc->LogicalToDeviceX( m_bound_all.x-2 );
return;
}
- if (paintBG)
+ wxWindow *listctrl = m_owner->GetParent();
+
+ // default foreground colour
+ wxColour colText;
+ if ( hilight )
+ {
+ colText = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT );
+ }
+ else
+ {
+ colText = listctrl->GetForegroundColour();
+ }
+
+ // default font
+ wxFont font = listctrl->GetFont();
+
+ // VZ: currently we set the colours/fonts only once, but like this (i.e.
+ // using SetAttributes() inside the loop), it will be trivial to
+ // customize the subitems (in report mode) too.
+ wxListItemData *item = (wxListItemData*)m_items.First()->Data();
+ wxListItemAttr *attr = item->GetAttributes();
+ SetAttributes(dc, attr, colText, font);
+
+ bool hasBgCol = attr && attr->HasBackgroundColour();
+ if ( paintBG || hasBgCol )
{
if (hilight)
{
dc->SetBrush( * m_hilightBrush );
- dc->SetPen( * wxTRANSPARENT_PEN );
}
else
{
- dc->SetBrush( * wxWHITE_BRUSH );
- dc->SetPen( * wxTRANSPARENT_PEN );
+ if ( hasBgCol )
+ dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID));
+ else
+ dc->SetBrush( * wxWHITE_BRUSH );
}
+
+ dc->SetPen( * wxTRANSPARENT_PEN );
dc->DrawRectangle( m_bound_hilight.x, m_bound_hilight.y,
m_bound_hilight.width, m_bound_hilight.height );
}
- dc->SetBackgroundMode(wxTRANSPARENT);
if (m_mode == wxLC_REPORT)
{
- wxString s;
- wxColour *colour = (wxColour*) NULL;
wxNode *node = m_items.First();
while (node)
{
m_owner->GetImageSize( item->GetImage(), x, y );
x += item->GetX() + 5;
}
- if (!colour)
- colour = item->GetColour();
if (item->HasText())
{
- item->GetText( s );
- if (hilight)
- dc->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
- else
- dc->SetTextForeground( *colour );
- dc->DrawText( s, x, item->GetY() );
+ dc->DrawText( item->GetText(), x, item->GetY() );
}
dc->DestroyClippingRegion();
node = node->Next();
}
if (item->HasText())
{
- wxString s;
- item->GetText( s );
- if (hilight)
- dc->SetTextForeground( wxSystemSettings::GetSystemColour( wxSYS_COLOUR_HIGHLIGHTTEXT ) );
- else
- dc->SetTextForeground( * item->GetColour() );
- dc->DrawText( s, m_bound_label.x, m_bound_label.y );
+ dc->DrawText( item->GetText(), m_bound_label.x, m_bound_label.y );
}
}
}
return m_mainWin->GetSelectedItemCount();
}
-/*
wxColour wxListCtrl::GetTextColour() const
{
+ return GetForegroundColour();
}
-void wxListCtrl::SetTextColour(const wxColour& WXUNUSED(col))
+void wxListCtrl::SetTextColour(const wxColour& col)
{
+ SetForegroundColour(col);
}
-*/
long wxListCtrl::GetTopItem() const
{