From d7fed302a3e0fe75b653e45884450d62ca81e0af Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 9 Jun 2019 00:02:27 +0200 Subject: [PATCH 1/4] Grey out wxGrid row/column labels when it is disabled Grid contents was drawn in grey colour instead of the usual active one when it was disabled, but the row and column labels kept their default appearance, which looked out of place. Fix this by greying them out too. This should have been arguably done in 73145b0ed18e99b66988c3caf6ad9119911913bb ~17 years ago, but better late than never. --- src/generic/grid.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index f79ad3035a..4c80962545 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -228,8 +228,35 @@ void wxGridHeaderLabelsRenderer::DrawLabel(const wxGrid& grid, int textOrientation) const { dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); - dc.SetTextForeground(grid.GetLabelTextColour()); dc.SetFont(grid.GetLabelFont()); + + // Draw text in a different colour and with a shadow when the control + // is disabled. + // + // Note that the colours used here are consistent with wxGenericStaticText + // rather than our own wxGridCellStringRenderer::SetTextColoursAndFont() + // because this results in a better disabled appearance for the default + // bold font used for the labels. + wxColour colText; + if ( !grid.IsThisEnabled() ) + { + colText = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT); + dc.SetTextForeground(colText); + + wxRect rectShadow = rect; + rectShadow.Offset(1, 1); + grid.DrawTextRectangle(dc, value, rectShadow, + horizAlign, vertAlign, textOrientation); + + colText = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW); + } + else + { + colText = grid.GetLabelTextColour(); + } + + dc.SetTextForeground(colText); + grid.DrawTextRectangle(dc, value, rect, horizAlign, vertAlign, textOrientation); } From d584420059c37ab7deb90bf5acf360336a1ece39 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 9 Jun 2019 13:46:10 +0200 Subject: [PATCH 2/4] Don't draw outer border in wxGrid subwindows if wxGrid has one Combination of multiple borders looks bad, so skip drawing the left/top borders in wxGrid{Row,Col,Corner}LabelWindow if wxGrid already has a border around it. --- src/generic/grid.cpp | 80 ++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 4c80962545..6f6fb05e2d 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -261,49 +261,68 @@ void wxGridHeaderLabelsRenderer::DrawLabel(const wxGrid& grid, } -void wxGridRowHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid), +void wxGridRowHeaderRendererDefault::DrawBorder(const wxGrid& 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()); + // Only draw the external borders when the containing control doesn't have + // any border, otherwise they would compound with the outer border which + // looks bad. + int ofs = 0; + if ( grid.GetBorder() == wxBORDER_NONE ) + { + dc.DrawLine(rect.GetLeft(), rect.GetTop(), + rect.GetLeft(), rect.GetBottom()); + + ofs = 1; + } + dc.SetPen(*wxWHITE_PEN); - dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(), - rect.GetLeft() + 1, rect.GetBottom()); - dc.DrawLine(rect.GetLeft() + 1, rect.GetTop(), + dc.DrawLine(rect.GetLeft() + ofs, rect.GetTop(), + rect.GetLeft() + ofs, rect.GetBottom()); + dc.DrawLine(rect.GetLeft() + ofs, rect.GetTop(), rect.GetRight(), rect.GetTop()); - rect.Deflate(2); + rect.Deflate(1 + ofs); } -void wxGridColumnHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid), +void wxGridColumnHeaderRendererDefault::DrawBorder(const wxGrid& 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); + // As above, don't draw the outer border if the control has its own one. + int ofs = 0; + if ( grid.GetBorder() == wxBORDER_NONE ) + { + dc.DrawLine(rect.GetLeft(), rect.GetTop(), + rect.GetRight(), rect.GetTop()); - rect.Deflate(2); + ofs = 1; + } + + dc.SetPen(*wxWHITE_PEN); + dc.DrawLine(rect.GetLeft(), rect.GetTop() + ofs, + rect.GetLeft(), rect.GetBottom()); + dc.DrawLine(rect.GetLeft(), rect.GetTop() + ofs, + rect.GetRight(), rect.GetTop() + ofs); + + rect.Deflate(1 + ofs); } -void wxGridCornerHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid), +void wxGridCornerHeaderRendererDefault::DrawBorder(const wxGrid& grid, wxDC& dc, wxRect& rect) const { @@ -312,18 +331,27 @@ void wxGridCornerHeaderRendererDefault::DrawBorder(const wxGrid& WXUNUSED(grid), 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()); + + // As above, don't draw either of outer border if there is already a border + // around the entire window. + int ofs = 0; + if ( grid.GetBorder() == wxBORDER_NONE ) + { + dc.DrawLine(rect.GetLeft(), rect.GetTop(), + rect.GetRight(), rect.GetTop()); + dc.DrawLine(rect.GetLeft(), rect.GetTop(), + rect.GetLeft(), rect.GetBottom()); + + ofs = 1; + } 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); + dc.DrawLine(rect.GetLeft() + 1, rect.GetTop() + ofs, + rect.GetRight() - 1, rect.GetTop() + ofs); + dc.DrawLine(rect.GetLeft() + ofs, rect.GetTop() + ofs, + rect.GetLeft() + ofs, rect.GetBottom() - 1); - rect.Deflate(2); + rect.Deflate(1 + ofs); } // ---------------------------------------------------------------------------- From 18956125d38d5ccc5a6cd30f4bf8d6163f32ee39 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 18 Jun 2019 00:55:16 +0200 Subject: [PATCH 3/4] Fix copy-and-pasto in wxGrid::HideColLabels() documentation The old sentence didn't make sense for this function. --- interface/wx/grid.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interface/wx/grid.h b/interface/wx/grid.h index 27690c953a..ad840f7f6b 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -2511,7 +2511,9 @@ public: /** Hides the column labels by calling SetColLabelSize() with a size of 0. - Show labels again by calling that method with a width greater than 0. + + The labels can be shown again by calling SetColLabelSize() with a + height greater than 0. */ void HideColLabels(); From 5b525ed201ee4004ab2fc2e649072f74bf07ab8f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 18 Jun 2019 00:58:51 +0200 Subject: [PATCH 4/4] Advise using a border with a wxGrid not showing column/row labels In this case a border can be useful to visually separate the grid from the surrounding area as without it there is no separation at all. --- interface/wx/grid.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/interface/wx/grid.h b/interface/wx/grid.h index ad840f7f6b..ec87b3c6bc 100644 --- a/interface/wx/grid.h +++ b/interface/wx/grid.h @@ -2514,6 +2514,14 @@ public: The labels can be shown again by calling SetColLabelSize() with a height greater than 0. + + Note that when the column labels are hidden, the grid won't have any + visible border on the top side, which may result in a less than ideal + appearance. Because of this, you may want to create the grid window + with a border style, such as @c wxBORDER_SIMPLE, when you don't plan to + show the column labels for it. + + @see HideRowLabels() */ void HideColLabels(); @@ -2522,6 +2530,9 @@ public: The labels can be shown again by calling SetRowLabelSize() with a width greater than 0. + + See HideColLabels() for a note explaining why you may want to use a + border with a grid without the row labels. */ void HideRowLabels();