+#ifndef __WXMSW__
+ #include "../sample.xpm"
+#endif
+
+// Custom renderer that renders column header cells without borders and in
+// italic
+class CustomColumnHeaderRenderer : public wxGridColumnHeaderRenderer
+{
+public:
+ CustomColumnHeaderRenderer(const wxColour& colFg, const wxColour& colBg)
+ : m_colFg(colFg),
+ m_colBg(colBg)
+ {
+ }
+
+ virtual void DrawLabel(const wxGrid& WXUNUSED(grid),
+ wxDC& dc,
+ const wxString& value,
+ const wxRect& rect,
+ int horizAlign,
+ int vertAlign,
+ int WXUNUSED(textOrientation)) const
+ {
+ dc.SetTextForeground(m_colFg);
+ dc.SetFont(wxITALIC_FONT->Bold());
+ dc.DrawLabel(value, rect, horizAlign | vertAlign);
+ }
+
+ virtual void DrawBorder(const wxGrid& WXUNUSED(grid),
+ wxDC& dc,
+ wxRect& rect) const
+ {
+ dc.SetPen(*wxTRANSPARENT_PEN);
+ dc.SetBrush(wxBrush(m_colBg));
+ dc.DrawRectangle(rect);
+ }
+
+private:
+ const wxColour m_colFg, m_colBg;
+
+ wxDECLARE_NO_COPY_CLASS(CustomColumnHeaderRenderer);
+};
+
+// And a custom attributes provider which uses custom column header renderer
+// defined above
+class CustomColumnHeadersProvider : public wxGridCellAttrProvider
+{
+public:
+ // by default custom column renderer is not used, call
+ // UseCustomColHeaders() to enable it
+ CustomColumnHeadersProvider()
+ : m_customOddRenderer(*wxYELLOW, *wxBLUE),
+ m_customEvenRenderer(*wxWHITE, *wxBLACK),
+ m_useCustom(false)
+ {
+ }
+
+ // enable or disable the use of custom renderer for column headers
+ void UseCustomColHeaders(bool use = true) { m_useCustom = use; }
+
+protected:
+ virtual const wxGridColumnHeaderRenderer& GetColumnHeaderRenderer(int col)
+ {
+ // if enabled, use custom renderers
+ if ( m_useCustom )
+ {
+ // and use different ones for odd and even columns -- just to show
+ // that we can
+ return col % 2 ? m_customOddRenderer : m_customEvenRenderer;
+ }
+
+ return wxGridCellAttrProvider::GetColumnHeaderRenderer(col);
+ }
+
+private:
+ CustomColumnHeaderRenderer m_customOddRenderer,
+ m_customEvenRenderer;
+
+ bool m_useCustom;
+
+ wxDECLARE_NO_COPY_CLASS(CustomColumnHeadersProvider);
+};
+