Fix sizing of temporarily last columns in macOS wxDataViewCtrl
Update the column width if it used to be the last one but isn't last one any longer. Closes #14939.
This commit is contained in:
committed by
Vadim Zeitlin
parent
36ea7ff4d6
commit
c9221fd538
@@ -86,7 +86,7 @@ class wxCocoaDataViewControl;
|
|||||||
class wxDataViewColumnNativeData
|
class wxDataViewColumnNativeData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxDataViewColumnNativeData() : m_NativeColumnPtr(NULL)
|
wxDataViewColumnNativeData() : m_NativeColumnPtr(NULL), m_isLast(false), m_prevWidth(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,9 +105,32 @@ public:
|
|||||||
m_NativeColumnPtr = newNativeColumnPtr;
|
m_NativeColumnPtr = newNativeColumnPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GetIsLast() const
|
||||||
|
{
|
||||||
|
return m_isLast;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetIsLast(bool isLast)
|
||||||
|
{
|
||||||
|
m_isLast = isLast;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetPrevWidth() const
|
||||||
|
{
|
||||||
|
return m_prevWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetPrevWidth(int prevWidth)
|
||||||
|
{
|
||||||
|
m_prevWidth = prevWidth;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// not owned by us
|
// not owned by us
|
||||||
NSTableColumn* m_NativeColumnPtr;
|
NSTableColumn* m_NativeColumnPtr;
|
||||||
|
|
||||||
|
bool m_isLast;
|
||||||
|
int m_prevWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
@@ -2206,7 +2206,8 @@ bool wxCocoaDataViewControl::InsertColumn(unsigned int pos, wxDataViewColumn* co
|
|||||||
void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos)
|
void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos)
|
||||||
{
|
{
|
||||||
const int count = GetCount();
|
const int count = GetCount();
|
||||||
NSTableColumn *column = GetColumn(pos)->GetNativeData()->GetNativeColumnPtr();
|
wxDataViewColumnNativeData *nativeData = GetColumn(pos)->GetNativeData();
|
||||||
|
NSTableColumn *column = nativeData->GetNativeColumnPtr();
|
||||||
UInt32 const noOfColumns = [[m_OutlineView tableColumns] count];
|
UInt32 const noOfColumns = [[m_OutlineView tableColumns] count];
|
||||||
|
|
||||||
class MaxWidthCalculator
|
class MaxWidthCalculator
|
||||||
@@ -2338,10 +2339,31 @@ void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos)
|
|||||||
if ( m_expanderWidth == 0 )
|
if ( m_expanderWidth == 0 )
|
||||||
m_expanderWidth = calculator.GetExpanderWidth();
|
m_expanderWidth = calculator.GetExpanderWidth();
|
||||||
|
|
||||||
if ( pos == noOfColumns - 1 )
|
const bool isLast = pos == noOfColumns - 1;
|
||||||
|
|
||||||
|
if ( isLast )
|
||||||
|
{
|
||||||
|
// Note that FitColumnWidthToContent() is called whenever a column is
|
||||||
|
// added, so we might also just temporarily become the last column;
|
||||||
|
// since we cannot know at this time whether we will just temporarily
|
||||||
|
// be the last column, we store our current column width in order to
|
||||||
|
// restore it later in case we suddenly are no longer the last column
|
||||||
|
// because new columns have been added --> we need to restore our
|
||||||
|
// previous width in that case because it must not get lost.
|
||||||
|
nativeData->SetPrevWidth(GetColumn(pos)->GetWidth());
|
||||||
|
|
||||||
[m_OutlineView sizeLastColumnToFit];
|
[m_OutlineView sizeLastColumnToFit];
|
||||||
|
}
|
||||||
else if ( GetColumn(pos)->GetWidthVariable() == wxCOL_WIDTH_AUTOSIZE )
|
else if ( GetColumn(pos)->GetWidthVariable() == wxCOL_WIDTH_AUTOSIZE )
|
||||||
|
{
|
||||||
[column setWidth:calculator.GetMaxWidth() + m_expanderWidth];
|
[column setWidth:calculator.GetMaxWidth() + m_expanderWidth];
|
||||||
|
}
|
||||||
|
else if ( nativeData->GetIsLast() )
|
||||||
|
{
|
||||||
|
[column setWidth:nativeData->GetPrevWidth()];
|
||||||
|
}
|
||||||
|
|
||||||
|
nativeData->SetIsLast(isLast);
|
||||||
|
|
||||||
if ( !(GetDataViewCtrl()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) )
|
if ( !(GetDataViewCtrl()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) )
|
||||||
{
|
{
|
||||||
|
@@ -438,6 +438,9 @@ bool wxDataViewCtrl::InsertColumn(unsigned int pos, wxDataViewColumn* columnPtr)
|
|||||||
// otherwise ask the control to 'update' the data in the newly appended column:
|
// otherwise ask the control to 'update' the data in the newly appended column:
|
||||||
if (GetColumnCount() == 1)
|
if (GetColumnCount() == 1)
|
||||||
SetExpanderColumn(columnPtr);
|
SetExpanderColumn(columnPtr);
|
||||||
|
|
||||||
|
AdjustAutosizedColumns();
|
||||||
|
|
||||||
// done:
|
// done:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -479,6 +482,8 @@ bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn* columnPtr)
|
|||||||
{
|
{
|
||||||
m_ColumnPtrs.Remove(columnPtr);
|
m_ColumnPtrs.Remove(columnPtr);
|
||||||
delete columnPtr;
|
delete columnPtr;
|
||||||
|
|
||||||
|
AdjustAutosizedColumns();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user