From d473d47e7ee759dbda3364f725359725f58b6956 Mon Sep 17 00:00:00 2001 From: Pavel Kalugin Date: Tue, 4 Sep 2018 16:52:52 +0300 Subject: [PATCH] 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 )