From 2d8bbbe3c9fbe8a2b2f9fda91576d922aa37f28c Mon Sep 17 00:00:00 2001
From: Pavel Kalugin
Date: Mon, 3 Sep 2018 17:44:51 +0300
Subject: [PATCH] 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.
---
include/wx/generic/grid.h | 40 ++++++++++----------
src/generic/grid.cpp | 80 +++++++++++++++++++++++++++++++--------
2 files changed, 86 insertions(+), 34 deletions(-)
diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h
index 61b0605bcd..7969d95cec 100644
--- a/include/wx/generic/grid.h
+++ b/include/wx/generic/grid.h
@@ -325,28 +325,17 @@ protected:
// 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_CORE wxGridCornerHeaderRenderer
+// Base class for header cells renderers.
+class WXDLLIMPEXP_CORE wxGridHeaderCellRenderer
{
public:
- // Draw the border around the corner window.
+ virtual ~wxGridHeaderCellRenderer() {}
+
+ // Draw the border around cell window.
virtual void DrawBorder(const wxGrid& grid,
wxDC& dc,
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
virtual void DrawLabel(const wxGrid& grid,
wxDC& dc,
@@ -358,16 +347,21 @@ public:
};
// 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
// avoid inadvertently using a column header renderer for the row headers)
class WXDLLIMPEXP_CORE wxGridRowHeaderRenderer
- : public wxGridHeaderLabelsRenderer
+ : public wxGridHeaderCellRenderer
{
};
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 GetColLabelValue( int col );
+ virtual wxString GetCornerLabelValue() const;
virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {}
virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {}
+ virtual void SetCornerLabelValue( const wxString& ) {}
// Attribute handling
//
@@ -870,8 +866,10 @@ public:
void SetRowLabelValue( int row, const wxString& ) wxOVERRIDE;
void SetColLabelValue( int col, const wxString& ) wxOVERRIDE;
+ void SetCornerLabelValue( const wxString& ) wxOVERRIDE;
wxString GetRowLabelValue( int row ) wxOVERRIDE;
wxString GetColLabelValue( int col ) wxOVERRIDE;
+ wxString GetCornerLabelValue() const wxOVERRIDE;
private:
wxGridStringArray m_data;
@@ -888,6 +886,8 @@ private:
wxArrayString m_rowLabels;
wxArrayString m_colLabels;
+ wxString m_cornerLabel;
+
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxGridStringTable);
};
@@ -1226,6 +1226,7 @@ public:
int GetColLabelTextOrientation() const;
wxString GetRowLabelValue( int row ) const;
wxString GetColLabelValue( int col ) const;
+ wxString GetCornerLabelValue() const;
wxColour GetCellHighlightColour() const { return m_cellHighlightColour; }
int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; }
@@ -1250,6 +1251,7 @@ public:
void SetColLabelTextOrientation( int textOrientation );
void SetRowLabelValue( int row, const wxString& );
void SetColLabelValue( int col, const wxString& );
+ void SetCornerLabelValue( const wxString& );
void SetCellHighlightColour( const wxColour& );
void SetCellHighlightPenWidth(int width);
void SetCellHighlightROPenWidth(int width);
diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp
index 2f01b2f667..e45f047774 100644
--- a/src/generic/grid.cpp
+++ b/src/generic/grid.cpp
@@ -216,16 +216,16 @@ wxGridCellWorker::~wxGridCellWorker()
}
// ----------------------------------------------------------------------------
-// wxGridHeaderLabelsRenderer and related classes
+// wxGridHeaderCellRenderer and related classes
// ----------------------------------------------------------------------------
-void wxGridHeaderLabelsRenderer::DrawLabel(const wxGrid& grid,
- wxDC& dc,
- const wxString& value,
- const wxRect& rect,
- int horizAlign,
- int vertAlign,
- int textOrientation) const
+void wxGridHeaderCellRenderer::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());
@@ -1167,6 +1167,11 @@ wxString wxGridTableBase::GetColLabelValue( int col )
return s2;
}
+wxString wxGridTableBase::GetCornerLabelValue() const
+{
+ return wxString{};
+}
+
wxString wxGridTableBase::GetTypeName( int WXUNUSED(row), int WXUNUSED(col) )
{
return wxGRID_VALUE_STRING;
@@ -1600,6 +1605,15 @@ void wxGridStringTable::SetColLabelValue( int col, const wxString& 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));
+ wxGridCellAttrProvider * const
+ attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
+ const wxGridCornerHeaderRenderer&
+ rend = attrProvider ? attrProvider->GetCornerRenderer()
+ : static_cast
+ (gs_defaultHeaderRenderers.cornerRenderer);
+
if ( m_nativeColumnLabels )
{
rect.Deflate(1);
@@ -5930,15 +5951,19 @@ void wxGrid::DrawCornerLabel(wxDC& dc)
rect.width++;
rect.height++;
- wxGridCellAttrProvider * const
- attrProvider = m_table ? m_table->GetAttrProvider() : NULL;
- const wxGridCornerHeaderRenderer&
- rend = attrProvider ? attrProvider->GetCornerRenderer()
- : static_cast
- (gs_defaultHeaderRenderers.cornerRenderer);
-
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)
@@ -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 )
{
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 )
{
if ( m_gridLineColour != colour )