diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 99b620d84d..48bd4efe85 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -514,6 +514,12 @@ public: virtual void SetBitmap( const wxBitmap& bitmap ) wxOVERRIDE { m_bitmap = bitmap; } virtual wxBitmap GetBitmap() const wxOVERRIDE { return m_bitmap; } + // Special accessor for use by wxWidgets only returning the width that was + // explicitly set, either by the application, using SetWidth(), or by the + // user, resizing the column interactively. It is usually the same as + // GetWidth(), but can be different for the last column. + virtual int WXGetSpecifiedWidth() const { return GetWidth(); } + protected: wxDataViewRenderer *m_renderer; int m_model_column; diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index e01d681123..12ee1ce1db 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -145,7 +145,7 @@ public: // user interactively. void WXOnResize(int width); - int WXGetManuallySetWidth() const; + virtual int WXGetSpecifiedWidth() const wxOVERRIDE; private: // common part of all ctors diff --git a/include/wx/persist/dataview.h b/include/wx/persist/dataview.h index c5f212b2ee..ee10c02480 100644 --- a/include/wx/persist/dataview.h +++ b/include/wx/persist/dataview.h @@ -61,7 +61,15 @@ public: SaveValue(columnPrefix + wxPERSIST_DVC_HIDDEN, column->IsHidden()); SaveValue(columnPrefix + wxPERSIST_DVC_POS, control->GetColumnPosition(column)); - SaveValue(columnPrefix + wxPERSIST_DVC_WIDTH, column->GetWidth()); + + // We take special care to save only the specified width instead of + // the currently used one. Usually they're one and the same, but + // they can be different for the last column, whose size can be + // greater than specified, as it's always expanded to fill the + // entire control width. + const int width = column->WXGetSpecifiedWidth(); + if ( width > 0 ) + SaveValue(columnPrefix + wxPERSIST_DVC_WIDTH, width); // Check if this column is the current sort key. if ( column->IsSortKey() ) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 0e8689765d..0bfdc18df2 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -217,7 +217,7 @@ void wxDataViewColumn::WXOnResize(int width) m_owner->OnColumnResized(); } -int wxDataViewColumn::WXGetManuallySetWidth() const +int wxDataViewColumn::WXGetSpecifiedWidth() const { // Note that we need to return valid value even if no width was initially // specified, as otherwise the last column created without any explicit @@ -5130,7 +5130,7 @@ void wxDataViewMainWindow::UpdateColumnSizes() // reduce it until this size if it's currently wider, so this // comparison needs to be strict). if ( availableWidth < wxMax(lastCol->GetMinWidth(), - lastCol->WXGetManuallySetWidth()) ) + lastCol->WXGetSpecifiedWidth()) ) { return; } @@ -5319,7 +5319,7 @@ void wxDataViewCtrl::OnDPIChanged(wxDPIChangedEvent& event) minWidth = minWidth * event.GetNewDPI().x / event.GetOldDPI().x; m_cols[i]->SetMinWidth(minWidth); - int width = m_cols[i]->WXGetManuallySetWidth(); + int width = m_cols[i]->WXGetSpecifiedWidth(); if ( width > 0 ) width = width * event.GetNewDPI().x / event.GetOldDPI().x; m_cols[i]->SetWidth(width);