Save specified, not actual, col width in wxPersistentDataViewCtrl
This is more correct as saving the current width of the last column would prevent the user from shrinking it under the last automatically set size, i.e. the UI behaviour would change after restarting the program, which shouldn't be the case. Doing this required making WXGetManuallySetWidth(), which previously existed in the generic version only, available in all ports, so do it and also rename it to WXGetSpecifiedWidth() in the process, as this seems a somewhat better name (it doesn't have to be manually specified, i.e. it could also be done by the program itself or even implicitly by wxPersistentDataViewCtrl). Don't make this function public, at least for now, because it's not clear how could it be useful and it might still need to be changed to behave differently in the other ports.
This commit is contained in:
@@ -514,6 +514,12 @@ public:
|
|||||||
virtual void SetBitmap( const wxBitmap& bitmap ) wxOVERRIDE { m_bitmap = bitmap; }
|
virtual void SetBitmap( const wxBitmap& bitmap ) wxOVERRIDE { m_bitmap = bitmap; }
|
||||||
virtual wxBitmap GetBitmap() const wxOVERRIDE { return m_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:
|
protected:
|
||||||
wxDataViewRenderer *m_renderer;
|
wxDataViewRenderer *m_renderer;
|
||||||
int m_model_column;
|
int m_model_column;
|
||||||
|
@@ -145,7 +145,7 @@ public:
|
|||||||
// user interactively.
|
// user interactively.
|
||||||
void WXOnResize(int width);
|
void WXOnResize(int width);
|
||||||
|
|
||||||
int WXGetManuallySetWidth() const;
|
virtual int WXGetSpecifiedWidth() const wxOVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// common part of all ctors
|
// common part of all ctors
|
||||||
|
@@ -61,7 +61,15 @@ public:
|
|||||||
SaveValue(columnPrefix + wxPERSIST_DVC_HIDDEN, column->IsHidden());
|
SaveValue(columnPrefix + wxPERSIST_DVC_HIDDEN, column->IsHidden());
|
||||||
SaveValue(columnPrefix + wxPERSIST_DVC_POS,
|
SaveValue(columnPrefix + wxPERSIST_DVC_POS,
|
||||||
control->GetColumnPosition(column));
|
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.
|
// Check if this column is the current sort key.
|
||||||
if ( column->IsSortKey() )
|
if ( column->IsSortKey() )
|
||||||
|
@@ -217,7 +217,7 @@ void wxDataViewColumn::WXOnResize(int width)
|
|||||||
m_owner->OnColumnResized();
|
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
|
// Note that we need to return valid value even if no width was initially
|
||||||
// specified, as otherwise the last column created without any explicit
|
// 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
|
// reduce it until this size if it's currently wider, so this
|
||||||
// comparison needs to be strict).
|
// comparison needs to be strict).
|
||||||
if ( availableWidth < wxMax(lastCol->GetMinWidth(),
|
if ( availableWidth < wxMax(lastCol->GetMinWidth(),
|
||||||
lastCol->WXGetManuallySetWidth()) )
|
lastCol->WXGetSpecifiedWidth()) )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -5319,7 +5319,7 @@ void wxDataViewCtrl::OnDPIChanged(wxDPIChangedEvent& event)
|
|||||||
minWidth = minWidth * event.GetNewDPI().x / event.GetOldDPI().x;
|
minWidth = minWidth * event.GetNewDPI().x / event.GetOldDPI().x;
|
||||||
m_cols[i]->SetMinWidth(minWidth);
|
m_cols[i]->SetMinWidth(minWidth);
|
||||||
|
|
||||||
int width = m_cols[i]->WXGetManuallySetWidth();
|
int width = m_cols[i]->WXGetSpecifiedWidth();
|
||||||
if ( width > 0 )
|
if ( width > 0 )
|
||||||
width = width * event.GetNewDPI().x / event.GetOldDPI().x;
|
width = width * event.GetNewDPI().x / event.GetOldDPI().x;
|
||||||
m_cols[i]->SetWidth(width);
|
m_cols[i]->SetWidth(width);
|
||||||
|
Reference in New Issue
Block a user