From 2d5beca260fbd5a9ea750f1156848ef971e7f757 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 1 Jun 2015 20:06:58 +0200 Subject: [PATCH] Refactor: share duplicated code in the internal class wxPGHeaderCtrl. Because code responsible for determining widths of all columns is duplicated in OnPageUpdated() and OnColumWidthsChanged() methods it can be moved to the new shared method DetermineAllColumnWidths(). Method DetermineColumnWidth() used now to determine width of the one column only is no longer necessary and can be removed. --- src/propgrid/manager.cpp | 69 +++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/src/propgrid/manager.cpp b/src/propgrid/manager.cpp index 5ef9023124..0edf0b165e 100644 --- a/src/propgrid/manager.cpp +++ b/src/propgrid/manager.cpp @@ -244,26 +244,6 @@ public: delete m_columns[i]; } - int DetermineColumnWidth(unsigned int idx, int* pMinWidth) const - { - const wxPropertyGridPage* page = m_page; - int colWidth = page->GetColumnWidth(idx); - int colMinWidth = page->GetColumnMinWidth(idx); - if ( idx == 0 ) - { - wxPropertyGrid* pg = m_manager->GetGrid(); - int margin = pg->GetMarginWidth(); - - // Compensate for the internal border - margin += (pg->GetSize().x - pg->GetClientSize().x) / 2; - - colWidth += margin; - colMinWidth += margin; - } - *pMinWidth = colMinWidth; - return colWidth; - } - void OnPageChanged(const wxPropertyGridPage* page) { m_page = page; @@ -273,34 +253,19 @@ public: void OnPageUpdated() { // Get column info from the page - const wxPropertyGridPage* page = m_page; - unsigned int colCount = page->GetColumnCount(); + unsigned int colCount = m_page->GetColumnCount(); EnsureColumnCount(colCount); - - for ( unsigned int i=0; iSetWidth(colWidth); - colInfo->SetMinWidth(colMinWidth); - } - + DetermineAllColumnWidths(); SetColumnCount(colCount); } void OnColumWidthsChanged() { - const wxPropertyGridPage* page = m_page; - unsigned int colCount = page->GetColumnCount(); + unsigned int colCount = m_page->GetColumnCount(); + DetermineAllColumnWidths(); for ( unsigned int i=0; iSetWidth(colWidth); - colInfo->SetMinWidth(colMinWidth); UpdateColumn(i); } } @@ -326,6 +291,32 @@ private: } } + void DetermineAllColumnWidths() const + { + const unsigned int colCount = m_page->GetColumnCount(); + + for ( unsigned int i = 0; i < colCount; i++ ) + { + wxHeaderColumnSimple* colInfo = m_columns[i]; + + int colWidth = m_page->GetColumnWidth(i); + 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; + + colWidth += margin; + colMinWidth += margin; + } + colInfo->SetWidth(colWidth); + colInfo->SetMinWidth(colMinWidth); + } + } + void OnSetColumnWidth(int col, int colWidth) { wxPropertyGrid* pg = m_manager->GetGrid();