Added support for corner, row and column headers renderers to wxGrid.

Make it possible to customize the appearance of wxGrid corner window and its
row and column headers by defining custom renderers for them.

Add demonstration of this new feature to the grid sample and update the
documentation.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61919 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-09-14 00:45:29 +00:00
parent 62960a2c6e
commit ba9574c310
6 changed files with 536 additions and 70 deletions

View File

@@ -385,6 +385,7 @@ All:
All (GUI): All (GUI):
- Added support for showing bitmaps in wxButton. - Added support for showing bitmaps in wxButton.
- Added support for corner, row and column headers renderers to wxGrid.
- wxWindow::SetAutoLayout() now works for all windows, not just panels. - wxWindow::SetAutoLayout() now works for all windows, not just panels.
- Support wxListCtrl columns, items and image lists in XRC (Kinaou Herv<72>). - Support wxListCtrl columns, items and image lists in XRC (Kinaou Herv<72>).
- Added support for wxFileCtrl to XRC (Kinaou Herv<72>). - Added support for wxFileCtrl to XRC (Kinaou Herv<72>).

View File

@@ -282,6 +282,82 @@ protected:
wxDECLARE_NO_COPY_CLASS(wxGridCellEditor); wxDECLARE_NO_COPY_CLASS(wxGridCellEditor);
}; };
// ----------------------------------------------------------------------------
// wxGridHeaderRenderer and company: like wxGridCellRenderer but for headers
// ----------------------------------------------------------------------------
// Base class for corner window renderer: it is the simplest of all renderers
// and only has a single function
class WXDLLIMPEXP_ADV wxGridCornerHeaderRenderer
{
public:
// Draw the border around the corner window.
virtual void DrawBorder(const wxGrid& grid,
wxDC& dc,
wxRect& rect) const = 0;
};
// Base class for the row/column header cells renderers
class WXDLLIMPEXP_ADV wxGridHeaderLabelsRenderer
: public wxGridCornerHeaderRenderer
{
public:
// Draw header cell label
virtual void DrawLabel(const wxGrid& grid,
wxDC& dc,
const wxString& value,
const wxRect& rect,
int horizAlign,
int vertAlign,
int textOrientation) const;
};
// Currently the row/column/corner renders don't need any methods other than
// those already in wxGridHeaderLabelsRenderer but still define separate classes
// for them for future extensions and also for better type safety (i.e. to
// avoid inadvertently using a column header renderer for the row headers)
class WXDLLIMPEXP_ADV wxGridRowHeaderRenderer
: public wxGridHeaderLabelsRenderer
{
};
class WXDLLIMPEXP_ADV wxGridColumnHeaderRenderer
: public wxGridHeaderLabelsRenderer
{
};
// Also define the default renderers which are used by wxGridCellAttrProvider
// by default
class WXDLLIMPEXP_ADV wxGridRowHeaderRendererDefault
: public wxGridRowHeaderRenderer
{
public:
virtual void DrawBorder(const wxGrid& grid,
wxDC& dc,
wxRect& rect) const;
};
// Column header cells renderers
class WXDLLIMPEXP_ADV wxGridColumnHeaderRendererDefault
: public wxGridColumnHeaderRenderer
{
public:
virtual void DrawBorder(const wxGrid& grid,
wxDC& dc,
wxRect& rect) const;
};
// Header corner renderer
class WXDLLIMPEXP_ADV wxGridCornerHeaderRendererDefault
: public wxGridCornerHeaderRenderer
{
public:
virtual void DrawBorder(const wxGrid& grid,
wxDC& dc,
wxRect& rect) const;
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGridCellAttr: this class can be used to alter the cells appearance in // wxGridCellAttr: this class can be used to alter the cells appearance in
@@ -464,11 +540,40 @@ public:
void UpdateAttrRows( size_t pos, int numRows ); void UpdateAttrRows( size_t pos, int numRows );
void UpdateAttrCols( size_t pos, int numCols ); void UpdateAttrCols( size_t pos, int numCols );
// get renderers for the given row/column header label and the corner
// window: unlike cell renderers, these objects are not reference counted
// and are never NULL so they are returned by reference
virtual const wxGridColumnHeaderRenderer&
GetColumnHeaderRenderer(int WXUNUSED(col))
{
return m_defaultHeaderRenderers.colRenderer;
}
virtual const wxGridRowHeaderRenderer&
GetRowHeaderRenderer(int WXUNUSED(row))
{
return m_defaultHeaderRenderers.rowRenderer;
}
virtual const wxGridCornerHeaderRenderer& GetCornerRenderer()
{
return m_defaultHeaderRenderers.cornerRenderer;
}
private: private:
void InitData(); void InitData();
wxGridCellAttrProviderData *m_data; wxGridCellAttrProviderData *m_data;
// this struct simply combines together the default header renderers
struct
{
wxGridColumnHeaderRendererDefault colRenderer;
wxGridRowHeaderRendererDefault rowRenderer;
wxGridCornerHeaderRendererDefault cornerRenderer;
} m_defaultHeaderRenderers;
wxDECLARE_NO_COPY_CLASS(wxGridCellAttrProvider); wxDECLARE_NO_COPY_CLASS(wxGridCellAttrProvider);
}; };
@@ -923,12 +1028,12 @@ public:
void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&, void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&,
int horizontalAlignment = wxALIGN_LEFT, int horizontalAlignment = wxALIGN_LEFT,
int verticalAlignment = wxALIGN_TOP, int verticalAlignment = wxALIGN_TOP,
int textOrientation = wxHORIZONTAL ); int textOrientation = wxHORIZONTAL ) const;
void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&, void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&,
int horizontalAlignment = wxALIGN_LEFT, int horizontalAlignment = wxALIGN_LEFT,
int verticalAlignment = wxALIGN_TOP, int verticalAlignment = wxALIGN_TOP,
int textOrientation = wxHORIZONTAL ); int textOrientation = wxHORIZONTAL ) const;
// Split a string containing newline characters into an array of // Split a string containing newline characters into an array of
@@ -2001,10 +2106,12 @@ protected:
friend class wxGridColLabelWindow; friend class wxGridColLabelWindow;
friend class wxGridRowLabelWindow; friend class wxGridRowLabelWindow;
friend class wxGridWindow; friend class wxGridWindow;
friend class wxGridHeaderRenderer;
friend class wxGridHeaderCtrl; friend class wxGridHeaderCtrl;
private: private:
// implement wxScrolledWindow method to return m_gridWin size // implement wxScrolledWindow method to return m_gridWin size
virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size); virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size);

View File

@@ -642,6 +642,152 @@ public:
void SetTextColour(const wxColour& colText); void SetTextColour(const wxColour& colText);
}; };
/**
Base class for corner window renderer.
This is the simplest of all header renderers and only has a single
function.
@see wxGridCellAttrProvider::GetCornerRenderer()
@since 2.9.1
*/
class wxGridCornerHeaderRenderer
{
public:
/**
Called by the grid to draw the corner window border.
This method is responsible for drawing the border inside the given @a
rect and adjusting the rectangle size to correspond to the area inside
the border, i.e. usually call wxRect::Deflate() to account for the
border width.
@param grid
The grid whose corner window is being drawn.
@param dc
The device context to use for drawing.
@param rect
Input/output parameter which contains the border rectangle on input
and should be updated to contain the area inside the border on
function return.
*/
virtual void DrawBorder(const wxGrid& grid,
wxDC& dc,
wxRect& rect) const = 0;
};
/**
Common base class for row and column headers renderers.
@see wxGridColumnHeaderRenderer, wxGridRowHeaderRenderer
@since 2.9.1
*/
class wxGridHeaderLabelsRenderer : public wxGridCornerHeaderRenderer
{
public:
/**
Called by the grid to draw the specified label.
Notice that the base class DrawBorder() method is called before this
one.
The default implementation uses wxGrid::GetLabelTextColour() and
wxGrid::GetLabelFont() to draw the label.
*/
virtual void DrawLabel(const wxGrid& grid,
wxDC& dc,
const wxString& value,
const wxRect& rect,
int horizAlign,
int vertAlign,
int textOrientation) const;
};
/**
Base class for row headers renderer.
This is the same as wxGridHeaderLabelsRenderer currently but we still use a
separate class for it to distinguish it from wxGridColumnHeaderRenderer.
@see wxGridRowHeaderRendererDefault
@see wxGridCellAttrProvider::GetRowHeaderRenderer()
@since 2.9.1
*/
class wxGridRowHeaderRenderer : public wxGridHeaderLabelsRenderer
{
};
/**
Base class for column headers renderer.
This is the same as wxGridHeaderLabelsRenderer currently but we still use a
separate class for it to distinguish it from wxGridRowHeaderRenderer.
@see wxGridColumnHeaderRendererDefault
@see wxGridCellAttrProvider::GetColumnHeaderRenderer()
@since 2.9.1
*/
class wxGridColumnHeaderRenderer : public wxGridHeaderLabelsRenderer
{
};
/**
Default row header renderer.
You may derive from this class if you need to only override one of its
methods (i.e. either DrawLabel() or DrawBorder()) but continue to use the
default implementation for the other one.
@see wxGridColumnHeaderRendererDefault
@since 2.9.1
*/
class wxGridRowHeaderRendererDefault : public wxGridRowHeaderRendererDefault
{
public:
/// Implement border drawing for the row labels.
virtual void DrawBorder(const wxGrid& grid,
wxDC& dc,
wxRect& rect) const;
};
/**
Default column header renderer.
@see wxGridRowHeaderRendererDefault
@since 2.9.1
*/
class wxGridColumnHeaderRendererDefault : public wxGridColumnHeaderRenderer
{
public:
/// Implement border drawing for the column labels.
virtual void DrawBorder(const wxGrid& grid,
wxDC& dc,
wxRect& rect) const;
};
/**
Default corner window renderer.
@see wxGridColumnHeaderRendererDefault, wxGridRowHeaderRendererDefault
@since 2.9.1
*/
class wxGridCornerHeaderRendererDefault : public wxGridCornerHeaderRenderer
{
public:
/// Implement border drawing for the corner window.
virtual void DrawBorder(const wxGrid& grid,
wxDC& dc,
wxRect& rect) const;
};
/** /**
Class providing attributes to be used for the grid cells. Class providing attributes to be used for the grid cells.
@@ -727,6 +873,50 @@ public:
virtual void SetColAttr(wxGridCellAttr *attr, int col); virtual void SetColAttr(wxGridCellAttr *attr, int col);
//@} //@}
/**
Getting header renderers.
These functions return the renderers for the given row or column header
label and the corner window. Unlike cell attributes, these objects are
not reference counted and are never @NULL so they are returned by
reference and not pointer and DecRef() shouldn't (and can't) be called
for them.
All these functions were added in wxWidgets 2.9.1.
*/
//@{
/**
Return the renderer used for drawing column headers.
By default wxGridColumnHeaderRendererDefault is returned.
@see wxGrid::SetUseNativeColLabels(), wxGrid::UseNativeColHeader()
@since 2.9.1
*/
virtual const wxGridColumnHeaderRenderer& GetColumnHeaderRenderer(int col);
/**
Return the renderer used for drawing row headers.
By default wxGridRowHeaderRendererDefault is returned.
@since 2.9.1
*/
virtual const wxGridRowHeaderRenderer& GetRowHeaderRenderer(int row);
/**
Return the renderer used for drawing the corner window.
By default wxGridCornerHeaderRendererDefault is returned.
@since 2.9.1
*/
virtual const wxGridCornerHeaderRenderer& GetCornerRenderer();
//@}
}; };

View File

@@ -43,6 +43,85 @@
#include "../sample.xpm" #include "../sample.xpm"
#endif #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);
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxWin macros // wxWin macros
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -78,7 +157,9 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
EVT_MENU( ID_TOGGLECOLMOVING, GridFrame::ToggleColMoving ) EVT_MENU( ID_TOGGLECOLMOVING, GridFrame::ToggleColMoving )
EVT_MENU( ID_TOGGLEGRIDSIZING, GridFrame::ToggleGridSizing ) EVT_MENU( ID_TOGGLEGRIDSIZING, GridFrame::ToggleGridSizing )
EVT_MENU( ID_TOGGLEGRIDDRAGCELL, GridFrame::ToggleGridDragCell ) EVT_MENU( ID_TOGGLEGRIDDRAGCELL, GridFrame::ToggleGridDragCell )
EVT_MENU( ID_TOGGLENATIVEHEADER, GridFrame::ToggleNativeHeader ) EVT_MENU( ID_COLNATIVEHEADER, GridFrame::SetNativeColHeader )
EVT_MENU( ID_COLDEFAULTHEADER, GridFrame::SetDefaultColHeader )
EVT_MENU( ID_COLCUSTOMHEADER, GridFrame::SetCustomColHeader )
EVT_MENU( ID_TOGGLEGRIDLINES, GridFrame::ToggleGridLines ) EVT_MENU( ID_TOGGLEGRIDLINES, GridFrame::ToggleGridLines )
EVT_MENU( ID_AUTOSIZECOLS, GridFrame::AutoSizeCols ) EVT_MENU( ID_AUTOSIZECOLS, GridFrame::AutoSizeCols )
EVT_MENU( ID_CELLOVERFLOW, GridFrame::CellOverflow ) EVT_MENU( ID_CELLOVERFLOW, GridFrame::CellOverflow )
@@ -170,7 +251,6 @@ GridFrame::GridFrame()
viewMenu->AppendCheckItem(ID_TOGGLECOLMOVING, "Col drag-&move"); viewMenu->AppendCheckItem(ID_TOGGLECOLMOVING, "Col drag-&move");
viewMenu->AppendCheckItem(ID_TOGGLEGRIDSIZING, "&Grid drag-resize"); viewMenu->AppendCheckItem(ID_TOGGLEGRIDSIZING, "&Grid drag-resize");
viewMenu->AppendCheckItem(ID_TOGGLEGRIDDRAGCELL, "&Grid drag-cell"); viewMenu->AppendCheckItem(ID_TOGGLEGRIDDRAGCELL, "&Grid drag-cell");
viewMenu->AppendCheckItem(ID_TOGGLENATIVEHEADER, "&Native column headers");
viewMenu->AppendCheckItem(ID_TOGGLEGRIDLINES, "&Grid Lines"); viewMenu->AppendCheckItem(ID_TOGGLEGRIDLINES, "&Grid Lines");
viewMenu->AppendCheckItem(ID_SET_HIGHLIGHT_WIDTH, "&Set Cell Highlight Width..."); viewMenu->AppendCheckItem(ID_SET_HIGHLIGHT_WIDTH, "&Set Cell Highlight Width...");
viewMenu->AppendCheckItem(ID_SET_RO_HIGHLIGHT_WIDTH, "&Set Cell RO Highlight Width..."); viewMenu->AppendCheckItem(ID_SET_RO_HIGHLIGHT_WIDTH, "&Set Cell RO Highlight Width...");
@@ -184,8 +264,8 @@ GridFrame::GridFrame()
rowLabelMenu, rowLabelMenu,
wxT("Change alignment of row labels") ); wxT("Change alignment of row labels") );
rowLabelMenu->Append( ID_ROWLABELHORIZALIGN, wxT("&Horizontal") ); rowLabelMenu->AppendRadioItem( ID_ROWLABELHORIZALIGN, wxT("&Horizontal") );
rowLabelMenu->Append( ID_ROWLABELVERTALIGN, wxT("&Vertical") ); rowLabelMenu->AppendRadioItem( ID_ROWLABELVERTALIGN, wxT("&Vertical") );
wxMenu *colLabelMenu = new wxMenu; wxMenu *colLabelMenu = new wxMenu;
@@ -193,8 +273,19 @@ GridFrame::GridFrame()
colLabelMenu, colLabelMenu,
wxT("Change alignment of col labels") ); wxT("Change alignment of col labels") );
colLabelMenu->Append( ID_COLLABELHORIZALIGN, wxT("&Horizontal") ); colLabelMenu->AppendRadioItem( ID_COLLABELHORIZALIGN, wxT("&Horizontal") );
colLabelMenu->Append( ID_COLLABELVERTALIGN, wxT("&Vertical") ); colLabelMenu->AppendRadioItem( ID_COLLABELVERTALIGN, wxT("&Vertical") );
wxMenu *colHeaderMenu = new wxMenu;
viewMenu->Append( ID_ROWLABELALIGN, wxT("Col header style"),
colHeaderMenu,
wxT("Change style of col header") );
colHeaderMenu->AppendRadioItem( ID_COLDEFAULTHEADER, wxT("&Default") );
colHeaderMenu->AppendRadioItem( ID_COLNATIVEHEADER, wxT("&Native") );
colHeaderMenu->AppendRadioItem( ID_COLCUSTOMHEADER, wxT("&Custom") );
wxMenu *colMenu = new wxMenu; wxMenu *colMenu = new wxMenu;
colMenu->Append( ID_SETLABELCOLOUR, wxT("Set &label colour...") ); colMenu->Append( ID_SETLABELCOLOUR, wxT("Set &label colour...") );
@@ -267,6 +358,7 @@ GridFrame::GridFrame()
wxPoint( 0, 0 ), wxPoint( 0, 0 ),
wxSize( 400, 300 ) ); wxSize( 400, 300 ) );
#if wxUSE_LOG #if wxUSE_LOG
int gridW = 600, gridH = 300; int gridW = 600, gridH = 300;
int logW = gridW, logH = 100; int logW = gridW, logH = 100;
@@ -286,6 +378,9 @@ GridFrame::GridFrame()
// this will create a grid and, by default, an associated grid // this will create a grid and, by default, an associated grid
// table for strings // table for strings
grid->CreateGrid( 0, 0 ); grid->CreateGrid( 0, 0 );
grid->GetTable()->SetAttrProvider(new CustomColumnHeadersProvider());
grid->AppendRows(100); grid->AppendRows(100);
grid->AppendCols(100); grid->AppendCols(100);
@@ -427,7 +522,6 @@ void GridFrame::SetDefaults()
GetMenuBar()->Check( ID_TOGGLECOLMOVING, false ); GetMenuBar()->Check( ID_TOGGLECOLMOVING, false );
GetMenuBar()->Check( ID_TOGGLEGRIDSIZING, true ); GetMenuBar()->Check( ID_TOGGLEGRIDSIZING, true );
GetMenuBar()->Check( ID_TOGGLEGRIDDRAGCELL, false ); GetMenuBar()->Check( ID_TOGGLEGRIDDRAGCELL, false );
GetMenuBar()->Check( ID_TOGGLENATIVEHEADER, false );
GetMenuBar()->Check( ID_TOGGLEGRIDLINES, true ); GetMenuBar()->Check( ID_TOGGLEGRIDLINES, true );
GetMenuBar()->Check( ID_CELLOVERFLOW, true ); GetMenuBar()->Check( ID_CELLOVERFLOW, true );
} }
@@ -497,12 +591,31 @@ void GridFrame::ToggleGridDragCell( wxCommandEvent& WXUNUSED(ev) )
GetMenuBar()->IsChecked( ID_TOGGLEGRIDDRAGCELL ) ); GetMenuBar()->IsChecked( ID_TOGGLEGRIDDRAGCELL ) );
} }
void GridFrame::ToggleNativeHeader( wxCommandEvent& WXUNUSED(ev) ) void GridFrame::SetNativeColHeader( wxCommandEvent& WXUNUSED(ev) )
{ {
grid->SetUseNativeColLabels( CustomColumnHeadersProvider* provider =
GetMenuBar()->IsChecked( ID_TOGGLENATIVEHEADER ) ); static_cast<CustomColumnHeadersProvider*>(grid->GetTable()->GetAttrProvider());
provider->UseCustomColHeaders(false);
grid->SetUseNativeColLabels(true);
} }
void GridFrame::SetCustomColHeader( wxCommandEvent& WXUNUSED(ev) )
{
CustomColumnHeadersProvider* provider =
static_cast<CustomColumnHeadersProvider*>(grid->GetTable()->GetAttrProvider());
provider->UseCustomColHeaders(true);
grid->SetUseNativeColLabels(false);
}
void GridFrame::SetDefaultColHeader( wxCommandEvent& WXUNUSED(ev) )
{
CustomColumnHeadersProvider* provider =
static_cast<CustomColumnHeadersProvider*>(grid->GetTable()->GetAttrProvider());
provider->UseCustomColHeaders(false);
grid->SetUseNativeColLabels(false);
}
void GridFrame::ToggleGridLines( wxCommandEvent& WXUNUSED(ev) ) void GridFrame::ToggleGridLines( wxCommandEvent& WXUNUSED(ev) )
{ {
grid->EnableGridLines( grid->EnableGridLines(

View File

@@ -39,7 +39,9 @@ class GridFrame : public wxFrame
void ToggleColMoving( wxCommandEvent& ); void ToggleColMoving( wxCommandEvent& );
void ToggleGridSizing( wxCommandEvent& ); void ToggleGridSizing( wxCommandEvent& );
void ToggleGridDragCell ( wxCommandEvent& ); void ToggleGridDragCell ( wxCommandEvent& );
void ToggleNativeHeader ( wxCommandEvent& ); void SetNativeColHeader ( wxCommandEvent& );
void SetCustomColHeader( wxCommandEvent& );
void SetDefaultColHeader( wxCommandEvent& );
void ToggleGridLines( wxCommandEvent& ); void ToggleGridLines( wxCommandEvent& );
void AutoSizeCols( wxCommandEvent& ); void AutoSizeCols( wxCommandEvent& );
void CellOverflow( wxCommandEvent& ); void CellOverflow( wxCommandEvent& );
@@ -121,7 +123,6 @@ public:
ID_TOGGLECOLMOVING, ID_TOGGLECOLMOVING,
ID_TOGGLEGRIDSIZING, ID_TOGGLEGRIDSIZING,
ID_TOGGLEGRIDDRAGCELL, ID_TOGGLEGRIDDRAGCELL,
ID_TOGGLENATIVEHEADER,
ID_TOGGLEGRIDLINES, ID_TOGGLEGRIDLINES,
ID_AUTOSIZECOLS, ID_AUTOSIZECOLS,
ID_CELLOVERFLOW, ID_CELLOVERFLOW,
@@ -135,6 +136,9 @@ public:
ID_COLLABELALIGN, ID_COLLABELALIGN,
ID_COLLABELHORIZALIGN, ID_COLLABELHORIZALIGN,
ID_COLLABELVERTALIGN, ID_COLLABELVERTALIGN,
ID_COLDEFAULTHEADER,
ID_COLNATIVEHEADER,
ID_COLCUSTOMHEADER,
ID_GRIDLINECOLOUR, ID_GRIDLINECOLOUR,
ID_INSERTROW, ID_INSERTROW,
ID_INSERTCOL, ID_INSERTCOL,

View File

@@ -191,6 +191,90 @@ wxGridCellWorker::~wxGridCellWorker()
{ {
} }
// ----------------------------------------------------------------------------
// wxGridHeaderLabelsRenderer and related classes
// ----------------------------------------------------------------------------
void wxGridHeaderLabelsRenderer::DrawLabel(const wxGrid& grid,
wxDC& dc,
const wxString& value,
const wxRect& rect,
int horizAlign,
int vertAlign,
int textOrientation) const
{
dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
dc.SetTextForeground(grid.GetLabelTextColour());
dc.SetFont(grid.GetLabelFont());
grid.DrawTextRectangle(dc, value, rect, horizAlign, vertAlign, textOrientation);
}
void wxGridRowHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid),
wxDC& dc,
wxRect& rect) const
{
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
dc.DrawLine(rect.GetRight(), rect.GetTop(),
rect.GetRight(), rect.GetBottom());
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
rect.GetLeft(), rect.GetBottom());
dc.DrawLine(rect.GetLeft(), rect.GetBottom(),
rect.GetRight() + 1, rect.GetBottom());
dc.SetPen(*wxWHITE_PEN);
dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(),
rect.GetLeft() + 1, rect.GetBottom());
dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(),
rect.GetRight(), rect.GetTop());
rect.Deflate(2);
}
void wxGridColumnHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid),
wxDC& dc,
wxRect& rect) const
{
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
dc.DrawLine(rect.GetRight(), rect.GetTop(),
rect.GetRight(), rect.GetBottom());
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
rect.GetRight(), rect.GetTop());
dc.DrawLine(rect.GetLeft(), rect.GetBottom(),
rect.GetRight() + 1, rect.GetBottom());
dc.SetPen(*wxWHITE_PEN);
dc.DrawLine(rect.GetLeft(), rect.GetTop() + 1,
rect.GetLeft(), rect.GetBottom());
dc.DrawLine(rect.GetLeft(), rect.GetTop() + 1,
rect.GetRight(), rect.GetTop() + 1);
rect.Deflate(2);
}
void wxGridCornerHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid),
wxDC& dc,
wxRect& rect) const
{
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
dc.DrawLine(rect.GetRight() - 1, rect.GetBottom() - 1,
rect.GetRight() - 1, rect.GetTop());
dc.DrawLine(rect.GetRight() - 1, rect.GetBottom() - 1,
rect.GetLeft(), rect.GetBottom() - 1);
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
rect.GetRight(), rect.GetTop());
dc.DrawLine(rect.GetLeft(), rect.GetTop(),
rect.GetLeft(), rect.GetBottom());
dc.SetPen(*wxWHITE_PEN);
dc.DrawLine(rect.GetLeft() + 1, rect.GetTop() + 1,
rect.GetRight() - 1, rect.GetTop() + 1);
dc.DrawLine(rect.GetLeft() + 1, rect.GetTop() + 1,
rect.GetLeft() + 1, rect.GetBottom() - 1);
rect.Deflate(2);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGridCellAttr // wxGridCellAttr
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -5324,32 +5408,16 @@ void wxGrid::DrawRowLabel( wxDC& dc, int row )
if ( GetRowHeight(row) <= 0 || m_rowLabelWidth <= 0 ) if ( GetRowHeight(row) <= 0 || m_rowLabelWidth <= 0 )
return; return;
wxRect rect; const wxGridRowHeaderRenderer&
rend = m_table->GetAttrProvider()->GetRowHeaderRenderer(row);
int rowTop = GetRowTop(row), wxRect rect(0, GetRowTop(row), m_rowLabelWidth, GetRowHeight(row));
rowBottom = GetRowBottom(row) - 1; rend.DrawBorder(*this, dc, rect);
dc.SetPen( wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
dc.DrawLine( m_rowLabelWidth - 1, rowTop, m_rowLabelWidth - 1, rowBottom );
dc.DrawLine( 0, rowTop, 0, rowBottom );
dc.DrawLine( 0, rowBottom, m_rowLabelWidth, rowBottom );
dc.SetPen( *wxWHITE_PEN );
dc.DrawLine( 1, rowTop, 1, rowBottom );
dc.DrawLine( 1, rowTop, m_rowLabelWidth - 1, rowTop );
dc.SetBackgroundMode( wxBRUSHSTYLE_TRANSPARENT );
dc.SetTextForeground( GetLabelTextColour() );
dc.SetFont( GetLabelFont() );
int hAlign, vAlign; int hAlign, vAlign;
GetRowLabelAlignment( &hAlign, &vAlign ); GetRowLabelAlignment(&hAlign, &vAlign);
rect.SetX( 2 ); rend.DrawLabel(*this, dc, GetRowLabelValue(row),
rect.SetY( GetRowTop(row) + 2 ); rect, hAlign, vAlign, wxHORIZONTAL);
rect.SetWidth( m_rowLabelWidth - 4 );
rect.SetHeight( GetRowHeight(row) - 4 );
DrawTextRectangle( dc, GetRowLabelValue( row ), rect, hAlign, vAlign );
} }
void wxGrid::UseNativeColHeader(bool native) void wxGrid::UseNativeColHeader(bool native)
@@ -5397,26 +5465,23 @@ void wxGrid::DrawColLabels( wxDC& dc,const wxArrayInt& cols )
void wxGrid::DrawCornerLabel(wxDC& dc) void wxGrid::DrawCornerLabel(wxDC& dc)
{ {
wxRect rect(wxSize(m_rowLabelWidth, m_colLabelHeight));
if ( m_nativeColumnLabels ) if ( m_nativeColumnLabels )
{ {
wxRect rect(wxSize(m_rowLabelWidth, m_colLabelHeight));
rect.Deflate(1); rect.Deflate(1);
wxRendererNative::Get().DrawHeaderButton(m_cornerLabelWin, dc, rect, 0); wxRendererNative::Get().DrawHeaderButton(m_cornerLabelWin, dc, rect, 0);
} }
else else
{ {
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW))); rect.width++;
dc.DrawLine( m_rowLabelWidth - 1, m_colLabelHeight - 1, rect.height++;
m_rowLabelWidth - 1, 0 );
dc.DrawLine( m_rowLabelWidth - 1, m_colLabelHeight - 1,
0, m_colLabelHeight - 1 );
dc.DrawLine( 0, 0, m_rowLabelWidth, 0 );
dc.DrawLine( 0, 0, 0, m_colLabelHeight );
dc.SetPen( *wxWHITE_PEN ); const wxGridCornerHeaderRenderer&
dc.DrawLine( 1, 1, m_rowLabelWidth - 1, 1 ); rend = m_table->GetAttrProvider()->GetCornerRenderer();
dc.DrawLine( 1, 1, 1, m_colLabelHeight - 1 );
rend.DrawBorder(*this, dc, rect);
} }
} }
@@ -5428,6 +5493,8 @@ void wxGrid::DrawColLabel(wxDC& dc, int col)
int colLeft = GetColLeft(col); int colLeft = GetColLeft(col);
wxRect rect(colLeft, 0, GetColWidth(col), m_colLabelHeight); wxRect rect(colLeft, 0, GetColWidth(col), m_colLabelHeight);
const wxGridColumnHeaderRenderer&
rend = m_table->GetAttrProvider()->GetColumnHeaderRenderer(col);
if ( m_nativeColumnLabels ) if ( m_nativeColumnLabels )
{ {
@@ -5443,34 +5510,18 @@ void wxGrid::DrawColLabel(wxDC& dc, int col)
: wxHDR_SORT_ICON_DOWN : wxHDR_SORT_ICON_DOWN
: wxHDR_SORT_ICON_NONE : wxHDR_SORT_ICON_NONE
); );
rect.Deflate(2);
} }
else else
{ {
int colRight = GetColRight(col) - 1; rend.DrawBorder(*this, dc, rect);
dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)));
dc.DrawLine( colRight, 0,
colRight, m_colLabelHeight - 1 );
dc.DrawLine( colLeft, 0,
colRight, 0 );
dc.DrawLine( colLeft, m_colLabelHeight - 1,
colRight + 1, m_colLabelHeight - 1 );
dc.SetPen( *wxWHITE_PEN );
dc.DrawLine( colLeft, 1, colLeft, m_colLabelHeight - 1 );
dc.DrawLine( colLeft, 1, colRight, 1 );
} }
dc.SetBackgroundMode( wxBRUSHSTYLE_TRANSPARENT );
dc.SetTextForeground( GetLabelTextColour() );
dc.SetFont( GetLabelFont() );
int hAlign, vAlign; int hAlign, vAlign;
GetColLabelAlignment( &hAlign, &vAlign ); GetColLabelAlignment(&hAlign, &vAlign);
const int orient = GetColLabelTextOrientation(); const int orient = GetColLabelTextOrientation();
rect.Deflate(2); rend.DrawLabel(*this, dc, GetColLabelValue(col), rect, hAlign, vAlign, orient);
DrawTextRectangle(dc, GetColLabelValue(col), rect, hAlign, vAlign, orient);
} }
// TODO: these 2 functions should be replaced with wxDC::DrawLabel() to which // TODO: these 2 functions should be replaced with wxDC::DrawLabel() to which
@@ -5480,7 +5531,7 @@ void wxGrid::DrawTextRectangle( wxDC& dc,
const wxRect& rect, const wxRect& rect,
int horizAlign, int horizAlign,
int vertAlign, int vertAlign,
int textOrientation ) int textOrientation ) const
{ {
wxArrayString lines; wxArrayString lines;
@@ -5494,7 +5545,7 @@ void wxGrid::DrawTextRectangle(wxDC& dc,
const wxRect& rect, const wxRect& rect,
int horizAlign, int horizAlign,
int vertAlign, int vertAlign,
int textOrientation) int textOrientation) const
{ {
if ( lines.empty() ) if ( lines.empty() )
return; return;