Add implementation for [Get/Set]CornerLabelValue()

Now, every header cell can have a label, including the corner one,
so wxGridHeaderLabelsRenderer::DrawLabel() was moved up one level
in the inheritance chain. Class names were changed accordingly.

Actual storage of corner label is delegated to a grid table class,
just because it is already done that way for column and row labels.
This commit is contained in:
Pavel Kalugin
2018-09-03 17:44:51 +03:00
parent 967ff67459
commit 2d8bbbe3c9
2 changed files with 86 additions and 34 deletions

View File

@@ -325,28 +325,17 @@ protected:
// wxGridHeaderRenderer and company: like wxGridCellRenderer but for headers // wxGridHeaderRenderer and company: like wxGridCellRenderer but for headers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Base class for corner window renderer: it is the simplest of all renderers // Base class for header cells renderers.
// and only has a single function class WXDLLIMPEXP_CORE wxGridHeaderCellRenderer
class WXDLLIMPEXP_CORE wxGridCornerHeaderRenderer
{ {
public: public:
// Draw the border around the corner window. virtual ~wxGridHeaderCellRenderer() {}
// Draw the border around cell window.
virtual void DrawBorder(const wxGrid& grid, virtual void DrawBorder(const wxGrid& grid,
wxDC& dc, wxDC& dc,
wxRect& rect) const = 0; wxRect& rect) const = 0;
// make the dtor of a class with virtual functions virtual to avoid g++
// warnings, even though this class is not supposed to be used
// polymorphically
virtual ~wxGridCornerHeaderRenderer() { }
};
// Base class for the row/column header cells renderers
class WXDLLIMPEXP_CORE wxGridHeaderLabelsRenderer
: public wxGridCornerHeaderRenderer
{
public:
// Draw header cell label // Draw header cell label
virtual void DrawLabel(const wxGrid& grid, virtual void DrawLabel(const wxGrid& grid,
wxDC& dc, wxDC& dc,
@@ -358,16 +347,21 @@ public:
}; };
// Currently the row/column/corner renders don't need any methods other than // Currently the row/column/corner renders don't need any methods other than
// those already in wxGridHeaderLabelsRenderer but still define separate classes // those already in wxGridHeaderCellRenderer but still define separate classes
// for them for future extensions and also for better type safety (i.e. to // 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) // avoid inadvertently using a column header renderer for the row headers)
class WXDLLIMPEXP_CORE wxGridRowHeaderRenderer class WXDLLIMPEXP_CORE wxGridRowHeaderRenderer
: public wxGridHeaderLabelsRenderer : public wxGridHeaderCellRenderer
{ {
}; };
class WXDLLIMPEXP_CORE wxGridColumnHeaderRenderer class WXDLLIMPEXP_CORE wxGridColumnHeaderRenderer
: public wxGridHeaderLabelsRenderer : public wxGridHeaderCellRenderer
{
};
class WXDLLIMPEXP_CORE wxGridCornerHeaderRenderer
: public wxGridHeaderCellRenderer
{ {
}; };
@@ -745,8 +739,10 @@ public:
virtual wxString GetRowLabelValue( int row ); virtual wxString GetRowLabelValue( int row );
virtual wxString GetColLabelValue( int col ); virtual wxString GetColLabelValue( int col );
virtual wxString GetCornerLabelValue() const;
virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {} virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {}
virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {} virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {}
virtual void SetCornerLabelValue( const wxString& ) {}
// Attribute handling // Attribute handling
// //
@@ -870,8 +866,10 @@ public:
void SetRowLabelValue( int row, const wxString& ) wxOVERRIDE; void SetRowLabelValue( int row, const wxString& ) wxOVERRIDE;
void SetColLabelValue( int col, const wxString& ) wxOVERRIDE; void SetColLabelValue( int col, const wxString& ) wxOVERRIDE;
void SetCornerLabelValue( const wxString& ) wxOVERRIDE;
wxString GetRowLabelValue( int row ) wxOVERRIDE; wxString GetRowLabelValue( int row ) wxOVERRIDE;
wxString GetColLabelValue( int col ) wxOVERRIDE; wxString GetColLabelValue( int col ) wxOVERRIDE;
wxString GetCornerLabelValue() const wxOVERRIDE;
private: private:
wxGridStringArray m_data; wxGridStringArray m_data;
@@ -888,6 +886,8 @@ private:
wxArrayString m_rowLabels; wxArrayString m_rowLabels;
wxArrayString m_colLabels; wxArrayString m_colLabels;
wxString m_cornerLabel;
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxGridStringTable); wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxGridStringTable);
}; };
@@ -1226,6 +1226,7 @@ public:
int GetColLabelTextOrientation() const; int GetColLabelTextOrientation() const;
wxString GetRowLabelValue( int row ) const; wxString GetRowLabelValue( int row ) const;
wxString GetColLabelValue( int col ) const; wxString GetColLabelValue( int col ) const;
wxString GetCornerLabelValue() const;
wxColour GetCellHighlightColour() const { return m_cellHighlightColour; } wxColour GetCellHighlightColour() const { return m_cellHighlightColour; }
int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; } int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; }
@@ -1250,6 +1251,7 @@ public:
void SetColLabelTextOrientation( int textOrientation ); void SetColLabelTextOrientation( int textOrientation );
void SetRowLabelValue( int row, const wxString& ); void SetRowLabelValue( int row, const wxString& );
void SetColLabelValue( int col, const wxString& ); void SetColLabelValue( int col, const wxString& );
void SetCornerLabelValue( const wxString& );
void SetCellHighlightColour( const wxColour& ); void SetCellHighlightColour( const wxColour& );
void SetCellHighlightPenWidth(int width); void SetCellHighlightPenWidth(int width);
void SetCellHighlightROPenWidth(int width); void SetCellHighlightROPenWidth(int width);

View File

@@ -216,10 +216,10 @@ wxGridCellWorker::~wxGridCellWorker()
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxGridHeaderLabelsRenderer and related classes // wxGridHeaderCellRenderer and related classes
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxGridHeaderLabelsRenderer::DrawLabel(const wxGrid& grid, void wxGridHeaderCellRenderer::DrawLabel(const wxGrid& grid,
wxDC& dc, wxDC& dc,
const wxString& value, const wxString& value,
const wxRect& rect, const wxRect& rect,
@@ -1167,6 +1167,11 @@ wxString wxGridTableBase::GetColLabelValue( int col )
return s2; return s2;
} }
wxString wxGridTableBase::GetCornerLabelValue() const
{
return wxString{};
}
wxString wxGridTableBase::GetTypeName( int WXUNUSED(row), int WXUNUSED(col) ) wxString wxGridTableBase::GetTypeName( int WXUNUSED(row), int WXUNUSED(col) )
{ {
return wxGRID_VALUE_STRING; return wxGRID_VALUE_STRING;
@@ -1600,6 +1605,15 @@ void wxGridStringTable::SetColLabelValue( int col, const wxString& value )
m_colLabels[col] = value; m_colLabels[col] = value;
} }
void wxGridStringTable::SetCornerLabelValue( const wxString& value )
{
m_cornerLabel = value;
}
wxString wxGridStringTable::GetCornerLabelValue() const
{
return m_cornerLabel;
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@@ -5919,6 +5933,13 @@ void wxGrid::DrawCornerLabel(wxDC& dc)
{ {
wxRect rect(wxSize(m_rowLabelWidth, m_colLabelHeight)); wxRect rect(wxSize(m_rowLabelWidth, m_colLabelHeight));
wxGridCellAttrProvider * const
attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
const wxGridCornerHeaderRenderer&
rend = attrProvider ? attrProvider->GetCornerRenderer()
: static_cast<wxGridCornerHeaderRenderer&>
(gs_defaultHeaderRenderers.cornerRenderer);
if ( m_nativeColumnLabels ) if ( m_nativeColumnLabels )
{ {
rect.Deflate(1); rect.Deflate(1);
@@ -5930,15 +5951,19 @@ void wxGrid::DrawCornerLabel(wxDC& dc)
rect.width++; rect.width++;
rect.height++; rect.height++;
wxGridCellAttrProvider * const
attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
const wxGridCornerHeaderRenderer&
rend = attrProvider ? attrProvider->GetCornerRenderer()
: static_cast<wxGridCornerHeaderRenderer&>
(gs_defaultHeaderRenderers.cornerRenderer);
rend.DrawBorder(*this, dc, rect); rend.DrawBorder(*this, dc, rect);
} }
wxString label = GetCornerLabelValue();
if( !label.IsEmpty() )
{
// TODO: add alignment and orientation support for corner window.
int hAlign, vAlign;
GetColLabelAlignment(&hAlign, &vAlign);
const int orient = GetColLabelTextOrientation();
rend.DrawLabel(*this, dc, label, rect, hAlign, vAlign, orient);
}
} }
void wxGrid::DrawColLabel(wxDC& dc, int col) void wxGrid::DrawColLabel(wxDC& dc, int col)
@@ -7071,6 +7096,18 @@ wxString wxGrid::GetColLabelValue( int col ) const
} }
} }
wxString wxGrid::GetCornerLabelValue() const
{
if ( m_table )
{
return m_table->GetCornerLabelValue();
}
else
{
return wxString{};
}
}
void wxGrid::SetRowLabelSize( int width ) void wxGrid::SetRowLabelSize( int width )
{ {
wxASSERT( width >= 0 || width == wxGRID_AUTOSIZE ); wxASSERT( width >= 0 || width == wxGRID_AUTOSIZE );
@@ -7299,6 +7336,19 @@ void wxGrid::SetColLabelValue( int col, const wxString& s )
} }
} }
void wxGrid::SetCornerLabelValue( const wxString& s )
{
if ( m_table )
{
m_table->SetCornerLabelValue( s );
if ( !GetBatchCount() )
{
wxRect rect(wxSize(m_rowLabelWidth, m_colLabelHeight));
m_cornerLabelWin->Refresh(true, &rect);
}
}
}
void wxGrid::SetGridLineColour( const wxColour& colour ) void wxGrid::SetGridLineColour( const wxColour& colour )
{ {
if ( m_gridLineColour != colour ) if ( m_gridLineColour != colour )