From 85a76d2d6192ac57e05e67f4d9419275b9ddd762 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 1 Jun 2015 20:19:11 +0200 Subject: [PATCH] Fix calculating width of columns in the wxPG header. When calculating widths of columns in the header there is necessary to take into account also width of the vertical scrollbar in the grid, if it exists. When scrollbar is ignored in calculations then we get wrong width of internal border and in result the columns of the header don't match the columns of the grid (this issue can be observed in the propgrid sample). --- src/propgrid/manager.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/propgrid/manager.cpp b/src/propgrid/manager.cpp index 0edf0b165e..d3208c0deb 100644 --- a/src/propgrid/manager.cpp +++ b/src/propgrid/manager.cpp @@ -293,8 +293,15 @@ private: void DetermineAllColumnWidths() const { - const unsigned int colCount = m_page->GetColumnCount(); + wxPropertyGrid* pg = m_manager->GetGrid(); + int sbWidth = pg->HasScrollbar(wxSB_VERTICAL) + ? wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, pg) + : 0; + // Internal border width + int borderWidth = (pg->GetSize().x - pg->GetClientSize().x - sbWidth) / 2; + + const unsigned int colCount = m_page->GetColumnCount(); for ( unsigned int i = 0; i < colCount; i++ ) { wxHeaderColumnSimple* colInfo = m_columns[i]; @@ -303,15 +310,21 @@ private: int colMinWidth = m_page->GetColumnMinWidth(i); if ( i == 0 ) { - wxPropertyGrid* pg = m_manager->GetGrid(); - int margin = pg->GetMarginWidth(); - // Compensate for the internal border - margin += (pg->GetSize().x - pg->GetClientSize().x) / 2; + int margin = pg->GetMarginWidth() + borderWidth; colWidth += margin; colMinWidth += margin; } + else if ( i == colCount-1 ) + { + // Compensate for the internal border and scrollbar + int margin = pg->GetMarginWidth() + borderWidth + sbWidth; + + colWidth += margin; + colMinWidth += margin; + } + colInfo->SetWidth(colWidth); colInfo->SetMinWidth(colMinWidth); } @@ -321,8 +334,14 @@ private: { wxPropertyGrid* pg = m_manager->GetGrid(); + int sbWidth = pg->HasScrollbar(wxSB_VERTICAL) + ? wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, pg) + : 0; + // Internal border width + int borderWidth = (pg->GetSize().x - pg->GetClientSize().x - sbWidth) / 2; + // Compensate for the internal border - int x = -((pg->GetSize().x - pg->GetClientSize().x) / 2); + int x = -borderWidth; for ( int i=0; iGetWidth();