From 2d8bbbe3c9fbe8a2b2f9fda91576d922aa37f28c Mon Sep 17 00:00:00 2001 From: Pavel Kalugin Date: Mon, 3 Sep 2018 17:44:51 +0300 Subject: [PATCH 1/9] 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 ) From e07d27ce7846dda8e94095aede3ea8043a53ba9b Mon Sep 17 00:00:00 2001 From: Pavel Kalugin Date: Mon, 3 Sep 2018 18:07:56 +0300 Subject: [PATCH 2/9] Add a command to set corner label to grid sample --- samples/grid/griddemo.cpp | 16 ++++++++++++++++ samples/grid/griddemo.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index 774efad4b3..d8c775988c 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -178,6 +178,7 @@ wxBEGIN_EVENT_TABLE( GridFrame, wxFrame ) EVT_MENU( ID_DELETEROW, GridFrame::DeleteSelectedRows ) EVT_MENU( ID_DELETECOL, GridFrame::DeleteSelectedCols ) EVT_MENU( ID_CLEARGRID, GridFrame::ClearGrid ) + EVT_MENU( ID_SETCORNERLABEL, GridFrame::SetCornerLabelValue ) EVT_MENU( ID_SHOWSEL, GridFrame::ShowSelection ) EVT_MENU( ID_SELCELLS, GridFrame::SelectCells ) EVT_MENU( ID_SELROWS, GridFrame::SelectRows ) @@ -352,6 +353,7 @@ GridFrame::GridFrame() editMenu->Append( ID_DELETEROW, wxT("Delete selected ro&ws") ); editMenu->Append( ID_DELETECOL, wxT("Delete selected co&ls") ); editMenu->Append( ID_CLEARGRID, wxT("Cl&ear grid cell contents") ); + editMenu->Append( ID_SETCORNERLABEL, wxT("&Set corner label...") ); wxMenu *selectMenu = new wxMenu; selectMenu->Append( ID_SELECT_UNSELECT, wxT("Add new cells to the selection"), @@ -1040,6 +1042,20 @@ void GridFrame::ClearGrid( wxCommandEvent& WXUNUSED(ev) ) grid->ClearGrid(); } +void GridFrame::SetCornerLabelValue( wxCommandEvent& WXUNUSED(ev) ) +{ + wxTextEntryDialog dialog(this, + "Please enter corner label:", + "Please enter a string", + grid->GetCornerLabelValue(), + wxOK | wxCANCEL); + + if (dialog.ShowModal() == wxID_OK) + { + grid->SetCornerLabelValue(dialog.GetValue()); + } +} + void GridFrame::ShowSelection( wxCommandEvent& WXUNUSED(ev) ) { switch ( grid->GetSelectionMode() ) diff --git a/samples/grid/griddemo.h b/samples/grid/griddemo.h index 30c1a85150..6d3e60667c 100644 --- a/samples/grid/griddemo.h +++ b/samples/grid/griddemo.h @@ -64,6 +64,7 @@ class GridFrame : public wxFrame void DeleteSelectedRows( wxCommandEvent& ); void DeleteSelectedCols( wxCommandEvent& ); void ClearGrid( wxCommandEvent& ); + void SetCornerLabelValue( wxCommandEvent& ); void ShowSelection( wxCommandEvent& ); void SelectCells( wxCommandEvent& ); void SelectRows( wxCommandEvent& ); @@ -165,6 +166,7 @@ public: ID_DELETEROW, ID_DELETECOL, ID_CLEARGRID, + ID_SETCORNERLABEL, ID_SHOWSEL, ID_CHANGESEL, ID_SELCELLS, From db83d416932d0d20a44aa3b26e20c53bd9977eee Mon Sep 17 00:00:00 2001 From: Pavel Kalugin Date: Tue, 4 Sep 2018 12:41:40 +0300 Subject: [PATCH 3/9] Replace C++11 expressions with C++03 ones --- src/generic/grid.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index e45f047774..ca39c5b08f 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -1169,7 +1169,7 @@ wxString wxGridTableBase::GetColLabelValue( int col ) wxString wxGridTableBase::GetCornerLabelValue() const { - return wxString{}; + return wxString(); } wxString wxGridTableBase::GetTypeName( int WXUNUSED(row), int WXUNUSED(col) ) @@ -7104,7 +7104,7 @@ wxString wxGrid::GetCornerLabelValue() const } else { - return wxString{}; + return wxString(); } } From 7ed7f87a50eac2c98644373e79956222e14e1194 Mon Sep 17 00:00:00 2001 From: Pavel Kalugin Date: Tue, 4 Sep 2018 12:57:25 +0300 Subject: [PATCH 4/9] Get corner window's rectangle in a more clear way --- src/generic/grid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index ca39c5b08f..269aa5ef6d 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -7343,7 +7343,7 @@ void wxGrid::SetCornerLabelValue( const wxString& s ) m_table->SetCornerLabelValue( s ); if ( !GetBatchCount() ) { - wxRect rect(wxSize(m_rowLabelWidth, m_colLabelHeight)); + wxRect rect = m_cornerLabelWin->GetRect(); m_cornerLabelWin->Refresh(true, &rect); } } From d473d47e7ee759dbda3364f725359725f58b6956 Mon Sep 17 00:00:00 2001 From: Pavel Kalugin Date: Tue, 4 Sep 2018 16:52:52 +0300 Subject: [PATCH 5/9] Add text alignment and orientation support for corner label --- include/wx/generic/grid.h | 7 +++++ src/generic/grid.cpp | 64 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 7969d95cec..dd4791be10 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -1223,7 +1223,9 @@ public: wxFont GetLabelFont() const { return m_labelFont; } void GetRowLabelAlignment( int *horiz, int *vert ) const; void GetColLabelAlignment( int *horiz, int *vert ) const; + void GetCornerLabelAlignment( int *horiz, int *vert ) const; int GetColLabelTextOrientation() const; + int GetCornerLabelTextOrientation() const; wxString GetRowLabelValue( int row ) const; wxString GetColLabelValue( int col ) const; wxString GetCornerLabelValue() const; @@ -1248,7 +1250,9 @@ public: void SetLabelFont( const wxFont& ); void SetRowLabelAlignment( int horiz, int vert ); void SetColLabelAlignment( int horiz, int vert ); + void SetCornerLabelAlignment( int horiz, int vert ); void SetColLabelTextOrientation( int textOrientation ); + void SetCornerLabelTextOrientation( int textOrientation ); void SetRowLabelValue( int row, const wxString& ); void SetColLabelValue( int col, const wxString& ); void SetCornerLabelValue( const wxString& ); @@ -1972,6 +1976,9 @@ protected: int m_colLabelHorizAlign; int m_colLabelVertAlign; int m_colLabelTextOrientation; + int m_cornerLabelHorizAlign; + int m_cornerLabelVertAlign; + int m_cornerLabelTextOrientation; bool m_defaultRowLabelValues; bool m_defaultColLabelValues; diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 269aa5ef6d..6c7713b5bc 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -2454,6 +2454,10 @@ void wxGrid::Init() m_colLabelVertAlign = wxALIGN_CENTRE; m_colLabelTextOrientation = wxHORIZONTAL; + m_cornerLabelHorizAlign = wxALIGN_CENTRE; + m_cornerLabelVertAlign = wxALIGN_CENTRE; + m_cornerLabelTextOrientation = wxHORIZONTAL; + m_defaultColWidth = WXGRID_DEFAULT_COL_WIDTH; m_defaultRowHeight = 0; // this will be initialized after creation @@ -5957,10 +5961,9 @@ void wxGrid::DrawCornerLabel(wxDC& dc) 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(); + GetCornerLabelAlignment(&hAlign, &vAlign); + const int orient = GetCornerLabelTextOrientation(); rend.DrawLabel(*this, dc, label, rect, hAlign, vAlign, orient); } @@ -7068,6 +7071,19 @@ int wxGrid::GetColLabelTextOrientation() const return m_colLabelTextOrientation; } +void wxGrid::GetCornerLabelAlignment( int *horiz, int *vert ) const +{ + if ( horiz ) + *horiz = m_cornerLabelHorizAlign; + if ( vert ) + *vert = m_cornerLabelVertAlign; +} + +int wxGrid::GetCornerLabelTextOrientation() const +{ + return m_cornerLabelTextOrientation; +} + wxString wxGrid::GetRowLabelValue( int row ) const { if ( m_table ) @@ -7275,6 +7291,39 @@ void wxGrid::SetColLabelAlignment( int horiz, int vert ) } } +void wxGrid::SetCornerLabelAlignment( int horiz, int vert ) +{ + // allow old (incorrect) defs to be used + switch ( horiz ) + { + case wxLEFT: horiz = wxALIGN_LEFT; break; + case wxRIGHT: horiz = wxALIGN_RIGHT; break; + case wxCENTRE: horiz = wxALIGN_CENTRE; break; + } + + switch ( vert ) + { + case wxTOP: vert = wxALIGN_TOP; break; + case wxBOTTOM: vert = wxALIGN_BOTTOM; break; + case wxCENTRE: vert = wxALIGN_CENTRE; break; + } + + if ( horiz == wxALIGN_LEFT || horiz == wxALIGN_CENTRE || horiz == wxALIGN_RIGHT ) + { + m_cornerLabelHorizAlign = horiz; + } + + if ( vert == wxALIGN_TOP || vert == wxALIGN_CENTRE || vert == wxALIGN_BOTTOM ) + { + m_cornerLabelVertAlign = vert; + } + + if ( !GetBatchCount() ) + { + m_cornerLabelWin->Refresh(); + } +} + // Note: under MSW, the default column label font must be changed because it // does not support vertical printing // @@ -7291,6 +7340,15 @@ void wxGrid::SetColLabelTextOrientation( int textOrientation ) m_colWindow->Refresh(); } +void wxGrid::SetCornerLabelTextOrientation( int textOrientation ) +{ + if ( textOrientation == wxHORIZONTAL || textOrientation == wxVERTICAL ) + m_cornerLabelTextOrientation = textOrientation; + + if ( !GetBatchCount() ) + m_cornerLabelWin->Refresh(); +} + void wxGrid::SetRowLabelValue( int row, const wxString& s ) { if ( m_table ) From ccc93c0cd99af46f0b2cde1025b9dc70c4ba2ff5 Mon Sep 17 00:00:00 2001 From: Pavel Kalugin Date: Tue, 4 Sep 2018 17:51:01 +0300 Subject: [PATCH 6/9] Add corner label alignment command to grid sample --- samples/grid/griddemo.cpp | 58 +++++++++++++++++++++++++++++++++++++++ samples/grid/griddemo.h | 5 ++++ 2 files changed, 63 insertions(+) diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index d8c775988c..7918859965 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -172,6 +172,8 @@ wxBEGIN_EVENT_TABLE( GridFrame, wxFrame ) EVT_MENU( ID_ROWLABELVERTALIGN, GridFrame::SetRowLabelVertAlignment ) EVT_MENU( ID_COLLABELHORIZALIGN, GridFrame::SetColLabelHorizAlignment ) EVT_MENU( ID_COLLABELVERTALIGN, GridFrame::SetColLabelVertAlignment ) + EVT_MENU( ID_CORNERLABELHORIZALIGN, GridFrame::SetCornerLabelHorizAlignment ) + EVT_MENU( ID_CORNERLABELVERTALIGN, GridFrame::SetCornerLabelVertAlignment ) EVT_MENU( ID_GRIDLINECOLOUR, GridFrame::SetGridLineColour ) EVT_MENU( ID_INSERTROW, GridFrame::InsertRow ) EVT_MENU( ID_INSERTCOL, GridFrame::InsertCol ) @@ -322,6 +324,14 @@ GridFrame::GridFrame() colLabelMenu->AppendRadioItem( ID_COLLABELHORIZALIGN, wxT("&Horizontal") ); colLabelMenu->AppendRadioItem( ID_COLLABELVERTALIGN, wxT("&Vertical") ); + wxMenu *cornerLabelMenu = new wxMenu; + viewMenu->Append( ID_CORNERLABELALIGN, wxT("Corner label alignment"), + cornerLabelMenu, + wxT("Change alignment of corner label") ); + + cornerLabelMenu->AppendRadioItem( ID_CORNERLABELHORIZALIGN, wxT("&Horizontal") ); + cornerLabelMenu->AppendRadioItem( ID_CORNERLABELVERTALIGN, wxT("&Vertical") ); + wxMenu *colHeaderMenu = new wxMenu; viewMenu->Append( ID_ROWLABELALIGN, wxT("Col header style"), @@ -922,6 +932,54 @@ void GridFrame::SetColLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) ) } +void GridFrame::SetCornerLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) ) +{ + int horiz, vert; + grid->GetCornerLabelAlignment( &horiz, &vert ); + + switch ( horiz ) + { + case wxALIGN_LEFT: + horiz = wxALIGN_CENTRE; + break; + + case wxALIGN_CENTRE: + horiz = wxALIGN_RIGHT; + break; + + case wxALIGN_RIGHT: + horiz = wxALIGN_LEFT; + break; + } + + grid->SetCornerLabelAlignment( horiz, vert ); +} + + +void GridFrame::SetCornerLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) ) +{ + int horiz, vert; + grid->GetCornerLabelAlignment( &horiz, &vert ); + + switch ( vert ) + { + case wxALIGN_TOP: + vert = wxALIGN_CENTRE; + break; + + case wxALIGN_CENTRE: + vert = wxALIGN_BOTTOM; + break; + + case wxALIGN_BOTTOM: + vert = wxALIGN_TOP; + break; + } + + grid->SetCornerLabelAlignment( horiz, vert ); +} + + void GridFrame::SetGridLineColour( wxCommandEvent& WXUNUSED(ev) ) { wxColourDialog dlg( NULL ); diff --git a/samples/grid/griddemo.h b/samples/grid/griddemo.h index 6d3e60667c..680614af3d 100644 --- a/samples/grid/griddemo.h +++ b/samples/grid/griddemo.h @@ -54,6 +54,8 @@ class GridFrame : public wxFrame void SetRowLabelVertAlignment( wxCommandEvent& ); void SetColLabelHorizAlignment( wxCommandEvent& ); void SetColLabelVertAlignment( wxCommandEvent& ); + void SetCornerLabelHorizAlignment( wxCommandEvent& ); + void SetCornerLabelVertAlignment( wxCommandEvent& ); void SetGridLineColour( wxCommandEvent& ); void SetCellFgColour(wxCommandEvent &); @@ -153,6 +155,9 @@ public: ID_COLLABELALIGN, ID_COLLABELHORIZALIGN, ID_COLLABELVERTALIGN, + ID_CORNERLABELALIGN, + ID_CORNERLABELHORIZALIGN, + ID_CORNERLABELVERTALIGN, ID_COLDEFAULTHEADER, ID_COLNATIVEHEADER, ID_COLCUSTOMHEADER, From 34416d75076758dfa415c02a25260a593f227699 Mon Sep 17 00:00:00 2001 From: Pavel Kalugin Date: Tue, 4 Sep 2018 18:20:34 +0300 Subject: [PATCH 7/9] Add corner label orientation toggle to grid sample --- samples/grid/griddemo.cpp | 22 ++++++++++++++++++++++ samples/grid/griddemo.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index 7918859965..52fac38477 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -174,6 +174,7 @@ wxBEGIN_EVENT_TABLE( GridFrame, wxFrame ) EVT_MENU( ID_COLLABELVERTALIGN, GridFrame::SetColLabelVertAlignment ) EVT_MENU( ID_CORNERLABELHORIZALIGN, GridFrame::SetCornerLabelHorizAlignment ) EVT_MENU( ID_CORNERLABELVERTALIGN, GridFrame::SetCornerLabelVertAlignment ) + EVT_MENU( ID_CORNERLABELORIENTATION, GridFrame::ToggleCornerLabelOrientation ) EVT_MENU( ID_GRIDLINECOLOUR, GridFrame::SetGridLineColour ) EVT_MENU( ID_INSERTROW, GridFrame::InsertRow ) EVT_MENU( ID_INSERTCOL, GridFrame::InsertCol ) @@ -332,6 +333,8 @@ GridFrame::GridFrame() cornerLabelMenu->AppendRadioItem( ID_CORNERLABELHORIZALIGN, wxT("&Horizontal") ); cornerLabelMenu->AppendRadioItem( ID_CORNERLABELVERTALIGN, wxT("&Vertical") ); + viewMenu->Append( ID_CORNERLABELORIENTATION, wxT("Toggle corner label orientation") ); + wxMenu *colHeaderMenu = new wxMenu; viewMenu->Append( ID_ROWLABELALIGN, wxT("Col header style"), @@ -980,6 +983,25 @@ void GridFrame::SetCornerLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) ) } +void GridFrame::ToggleCornerLabelOrientation( wxCommandEvent& WXUNUSED(ev) ) +{ + int orientation = grid->GetCornerLabelTextOrientation(); + + switch(orientation) + { + case wxHORIZONTAL: + orientation = wxVERTICAL; + break; + + case wxVERTICAL: + orientation = wxHORIZONTAL; + break; + } + + grid->SetCornerLabelTextOrientation(orientation); +} + + void GridFrame::SetGridLineColour( wxCommandEvent& WXUNUSED(ev) ) { wxColourDialog dlg( NULL ); diff --git a/samples/grid/griddemo.h b/samples/grid/griddemo.h index 680614af3d..c9ce9b924e 100644 --- a/samples/grid/griddemo.h +++ b/samples/grid/griddemo.h @@ -56,6 +56,7 @@ class GridFrame : public wxFrame void SetColLabelVertAlignment( wxCommandEvent& ); void SetCornerLabelHorizAlignment( wxCommandEvent& ); void SetCornerLabelVertAlignment( wxCommandEvent& ); + void ToggleCornerLabelOrientation( wxCommandEvent& ); void SetGridLineColour( wxCommandEvent& ); void SetCellFgColour(wxCommandEvent &); @@ -158,6 +159,7 @@ public: ID_CORNERLABELALIGN, ID_CORNERLABELHORIZALIGN, ID_CORNERLABELVERTALIGN, + ID_CORNERLABELORIENTATION, ID_COLDEFAULTHEADER, ID_COLNATIVEHEADER, ID_COLCUSTOMHEADER, From fcae53c5b10fdb72164a4da946ca3d6a40eed168 Mon Sep 17 00:00:00 2001 From: Pavel Kalugin Date: Tue, 4 Sep 2018 21:00:47 +0300 Subject: [PATCH 8/9] Add documentation for new [Get/Set]CornerLabelValue functionality --- interface/wx/grid.h | 148 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 118 insertions(+), 30 deletions(-) diff --git a/interface/wx/grid.h b/interface/wx/grid.h index 955f7aa5ac..0be92a14e7 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -1012,20 +1012,18 @@ protected: }; /** - Base class for corner window renderer. + Base class for header cells renderers. - This is the simplest of all header renderers and only has a single - function. - - @see wxGridCellAttrProvider::GetCornerRenderer() + A cell renderer can be used to draw the text of a cell's label, and/or + the border around it. @since 2.9.1 */ -class wxGridCornerHeaderRenderer +class wxGridHeaderCellRenderer { public: /** - Called by the grid to draw the corner window border. + Called by the grid to draw the border around the cell header. This method is responsible for drawing the border inside the given @a rect and adjusting the rectangle size to correspond to the area inside @@ -1033,7 +1031,7 @@ public: border width. @param grid - The grid whose corner window is being drawn. + The grid whose header cell window is being drawn. @param dc The device context to use for drawing. @param rect @@ -1044,23 +1042,11 @@ public: 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. + Notice that the DrawBorder() method is called before this one. The default implementation uses wxGrid::GetLabelTextColour() and wxGrid::GetLabelFont() to draw the label. @@ -1077,8 +1063,9 @@ public: /** 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. + This is the same as wxGridHeaderCellRenderer currently but we still use a + separate class for it to distinguish it from wxGridColumnHeaderRenderer + and wxGridCornerHeaderRenderer. @see wxGridRowHeaderRendererDefault @@ -1086,15 +1073,16 @@ public: @since 2.9.1 */ -class wxGridRowHeaderRenderer : public wxGridHeaderLabelsRenderer +class wxGridRowHeaderRenderer : public wxGridHeaderCellRenderer { }; /** 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. + This is the same as wxGridHeaderCellRenderer currently but we still use a + separate class for it to distinguish it from wxGridRowHeaderRenderer and + wxGridCornerHeaderRenderer. @see wxGridColumnHeaderRendererDefault @@ -1102,7 +1090,24 @@ class wxGridRowHeaderRenderer : public wxGridHeaderLabelsRenderer @since 2.9.1 */ -class wxGridColumnHeaderRenderer : public wxGridHeaderLabelsRenderer +class wxGridColumnHeaderRenderer : public wxGridHeaderCellRenderer +{ +}; + +/** + Base class for corner header renderer. + + This is the same as wxGridHeaderCellRenderer currently but we still use a + separate class for it to distinguish it from wxGridRowHeaderRenderer and + wxGridColumnHeaderRenderer. + + @see wxGridCornerHeaderRendererDefault + + @see wxGridCellAttrProvider::GetCornerRenderer() + + @since 2.9.1 + */ +class wxGridCornerHeaderRenderer : public wxGridHeaderCellRenderer { }; @@ -1113,7 +1118,7 @@ class wxGridColumnHeaderRenderer : public wxGridHeaderLabelsRenderer methods (i.e. either DrawLabel() or DrawBorder()) but continue to use the default implementation for the other one. - @see wxGridColumnHeaderRendererDefault + @see wxGridColumnHeaderRendererDefault, wxGridCornerHeaderRendererDefault @since 2.9.1 */ @@ -1129,7 +1134,7 @@ public: /** Default column header renderer. - @see wxGridRowHeaderRendererDefault + @see wxGridRowHeaderRendererDefault, wxGridCornerHeaderRendererDefault @since 2.9.1 */ @@ -1393,8 +1398,10 @@ public: void SetRowLabelValue( int row, const wxString& ); void SetColLabelValue( int col, const wxString& ); + void SetCornerLabelValue( const wxString& ); wxString GetRowLabelValue( int row ); wxString GetColLabelValue( int col ); + wxString GetCornerLabelValue() const; }; /** @@ -1764,13 +1771,19 @@ public: //@} /*! - @name Table Row and Column Labels + @name Table Row, Column and Corner Labels By default the numbers are used for labelling rows and Latin letters for labelling columns. If the table has more than 26 columns, the pairs of letters are used starting from the 27-th one and so on, i.e. the sequence of labels is A, B, ..., Z, AA, AB, ..., AZ, BA, ..., ..., ZZ, AAA, ... + + A cell in the top-left corner of a grid can also have a label. It is + empty by default. Use wxGrid::SetCornerLabelValue() to set it and + wxGrid::GetCornerLabelValue() to get its' current value. + + @see wxGridTableBase::GetCornerLabelValue, wxGridTableBase::SetCornerLabelValue */ //@{ @@ -1784,6 +1797,13 @@ public: */ virtual wxString GetColLabelValue(int col); + /** + Return the label of the grid's corner. + + @since 3.1.2 + */ + virtual wxString GetCornerLabelValue() const; + /** Set the given label for the specified row. @@ -1798,6 +1818,17 @@ public: */ virtual void SetColLabelValue(int col, const wxString& label); + /** + Set the given label for the grid's corner. + + The default version does nothing, i.e. the label is not stored. You + must override this method in your derived class if you wish + wxGrid::GetCornerLabelValue() to work. + + @since 3.1.2 + */ + virtual void SetCornerLabelValue( const wxString& ); + //@} @@ -2336,6 +2367,34 @@ public: */ wxString GetColLabelValue(int col) const; + /** + Sets the arguments to the current corner label alignment values. + + Horizontal alignment will be one of @c wxALIGN_LEFT, @c wxALIGN_CENTRE + or @c wxALIGN_RIGHT. + + Vertical alignment will be one of @c wxALIGN_TOP, @c wxALIGN_CENTRE or + @c wxALIGN_BOTTOM. + + @since 3.1.2 + */ + void GetCornerLabelAlignment( int *horiz, int *vert ) const; + + /** + Returns the orientation of the corner label (either @c wxHORIZONTAL or + @c wxVERTICAL). + + @since 3.1.2 + */ + int GetCornerLabelTextOrientation() const; + + /** + Returns the (top-left) corner label. + + @since 3.1.2 + */ + wxString GetCornerLabelValue() const; + /** Returns the colour used for the background of row and column labels. */ @@ -2408,6 +2467,35 @@ public: */ void SetColLabelValue(int col, const wxString& value); + /** + Sets the horizontal and vertical alignment of the (top-left) corner label text. + + Horizontal alignment should be one of @c wxALIGN_LEFT, + @c wxALIGN_CENTRE or @c wxALIGN_RIGHT. Vertical alignment should be one + of @c wxALIGN_TOP, @c wxALIGN_CENTRE or @c wxALIGN_BOTTOM. + + @since 3.1.2 + */ + void SetCornerLabelAlignment( int horiz, int vert ); + + /** + Sets the orientation of the (top-left) corner label (either @c wxHORIZONTAL or + @c wxVERTICAL). + + @since 3.1.2 + */ + void SetCornerLabelTextOrientation( int textOrientation ); + + /** + Set the value for the (top-left) corner label. + + If you are using a custom grid table you must override + wxGridTableBase::SetCornerLabelValue() for this to have any effect. + + @since 3.1.2 + */ + void SetCornerLabelValue( const wxString& ); + /** Sets the background colour for row and column labels. */ From 6a9dea37f78005239ab26b447256da42bebffc04 Mon Sep 17 00:00:00 2001 From: Pavel Kalugin Date: Wed, 5 Sep 2018 18:34:07 +0300 Subject: [PATCH 9/9] Rename a class to restore backward compatibility This solves backward incompatibility problem introduced in 2d8bbbe3c9. The name of base class for grid header renderers hierarchy is restored to be wxGridHeaderLabelsRenderer. This introduces another problem: now wxGridCornerHeaderRenderer is derived from wxGridHeaderLabelsRenderer, not vice versa, as it was before. But it is considered less disruptive change, compared to base class rename. --- include/wx/generic/grid.h | 12 ++++++------ interface/wx/grid.h | 14 +++++++------- src/generic/grid.cpp | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index dd4791be10..84e283154d 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -326,10 +326,10 @@ protected: // ---------------------------------------------------------------------------- // Base class for header cells renderers. -class WXDLLIMPEXP_CORE wxGridHeaderCellRenderer +class WXDLLIMPEXP_CORE wxGridHeaderLabelsRenderer { public: - virtual ~wxGridHeaderCellRenderer() {} + virtual ~wxGridHeaderLabelsRenderer() {} // Draw the border around cell window. virtual void DrawBorder(const wxGrid& grid, @@ -347,21 +347,21 @@ public: }; // Currently the row/column/corner renders don't need any methods other than -// those already in wxGridHeaderCellRenderer but still define separate classes +// 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_CORE wxGridRowHeaderRenderer - : public wxGridHeaderCellRenderer + : public wxGridHeaderLabelsRenderer { }; class WXDLLIMPEXP_CORE wxGridColumnHeaderRenderer - : public wxGridHeaderCellRenderer + : public wxGridHeaderLabelsRenderer { }; class WXDLLIMPEXP_CORE wxGridCornerHeaderRenderer - : public wxGridHeaderCellRenderer + : public wxGridHeaderLabelsRenderer { }; diff --git a/interface/wx/grid.h b/interface/wx/grid.h index 0be92a14e7..85f339aa3b 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -1019,7 +1019,7 @@ protected: @since 2.9.1 */ -class wxGridHeaderCellRenderer +class wxGridHeaderLabelsRenderer { public: /** @@ -1063,7 +1063,7 @@ public: /** Base class for row headers renderer. - This is the same as wxGridHeaderCellRenderer currently but we still use a + This is the same as wxGridHeaderLabelsRenderer currently but we still use a separate class for it to distinguish it from wxGridColumnHeaderRenderer and wxGridCornerHeaderRenderer. @@ -1073,14 +1073,14 @@ public: @since 2.9.1 */ -class wxGridRowHeaderRenderer : public wxGridHeaderCellRenderer +class wxGridRowHeaderRenderer : public wxGridHeaderLabelsRenderer { }; /** Base class for column headers renderer. - This is the same as wxGridHeaderCellRenderer currently but we still use a + This is the same as wxGridHeaderLabelsRenderer currently but we still use a separate class for it to distinguish it from wxGridRowHeaderRenderer and wxGridCornerHeaderRenderer. @@ -1090,14 +1090,14 @@ class wxGridRowHeaderRenderer : public wxGridHeaderCellRenderer @since 2.9.1 */ -class wxGridColumnHeaderRenderer : public wxGridHeaderCellRenderer +class wxGridColumnHeaderRenderer : public wxGridHeaderLabelsRenderer { }; /** Base class for corner header renderer. - This is the same as wxGridHeaderCellRenderer currently but we still use a + This is the same as wxGridHeaderLabelsRenderer currently but we still use a separate class for it to distinguish it from wxGridRowHeaderRenderer and wxGridColumnHeaderRenderer. @@ -1107,7 +1107,7 @@ class wxGridColumnHeaderRenderer : public wxGridHeaderCellRenderer @since 2.9.1 */ -class wxGridCornerHeaderRenderer : public wxGridHeaderCellRenderer +class wxGridCornerHeaderRenderer : public wxGridHeaderLabelsRenderer { }; diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 6c7713b5bc..f6993de388 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -216,10 +216,10 @@ wxGridCellWorker::~wxGridCellWorker() } // ---------------------------------------------------------------------------- -// wxGridHeaderCellRenderer and related classes +// wxGridHeaderLabelsRenderer and related classes // ---------------------------------------------------------------------------- -void wxGridHeaderCellRenderer::DrawLabel(const wxGrid& grid, +void wxGridHeaderLabelsRenderer::DrawLabel(const wxGrid& grid, wxDC& dc, const wxString& value, const wxRect& rect,