Make wxCOL_WIDTH_AUTOSIZE work correctly in Mac wxDataViewCtrl
Update the width when items are expanded and collapsed and also take the expander width into account. Change m_ModelNotifier type to avoid casts when calling wxOSX-specific method on it. Closes #14939. Co-Authored-By: Vadim Zeitlin <vadim@wxwidgets.org>
This commit is contained in:
committed by
Vadim Zeitlin
parent
9a1e820cc1
commit
e89e76bb82
@@ -557,6 +557,9 @@ private:
|
||||
wxCocoaOutlineDataSource* m_DataSource;
|
||||
|
||||
wxCocoaOutlineView* m_OutlineView;
|
||||
|
||||
// Width of expander in pixels, computed on demand.
|
||||
int m_expanderWidth;
|
||||
};
|
||||
|
||||
#endif // _WX_DATAVIEWCTRL_COCOOA_H_
|
||||
|
@@ -306,7 +306,7 @@ private:
|
||||
|
||||
wxDataViewColumnPtrArrayType m_ColumnPtrs; // all column pointers are stored in an array
|
||||
|
||||
wxDataViewModelNotifier* m_ModelNotifier; // stores the model notifier for the control (does not own the notifier)
|
||||
class wxOSXDataViewModelNotifier* m_ModelNotifier; // stores the model notifier for the control (does not own the notifier)
|
||||
|
||||
// wxWidget internal stuff:
|
||||
wxDECLARE_DYNAMIC_CLASS(wxDataViewCtrl);
|
||||
|
@@ -2045,7 +2045,8 @@ wxCocoaDataViewControl::wxCocoaDataViewControl(wxWindow* peer,
|
||||
[[NSScrollView alloc] initWithFrame:wxOSXGetFrameForControl(peer,pos,size)]
|
||||
),
|
||||
m_DataSource(NULL),
|
||||
m_OutlineView([[wxCocoaOutlineView alloc] init])
|
||||
m_OutlineView([[wxCocoaOutlineView alloc] init]),
|
||||
m_expanderWidth(0)
|
||||
{
|
||||
// initialize scrollview (the outline view is part of a scrollview):
|
||||
NSScrollView* scrollview = (NSScrollView*) GetWXWidget();
|
||||
@@ -2175,7 +2176,9 @@ void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos)
|
||||
: m_width(0),
|
||||
m_view(view),
|
||||
m_column(columnIndex),
|
||||
m_indent(0)
|
||||
m_indent(0),
|
||||
m_expander(0),
|
||||
m_tableColumn(column)
|
||||
{
|
||||
// account for indentation in the column with expander
|
||||
if ( column == [m_view outlineTableColumn] )
|
||||
@@ -2193,18 +2196,27 @@ void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos)
|
||||
unsigned cellWidth = [cell cellSize].width + 1/*round the float up*/;
|
||||
|
||||
if ( m_indent )
|
||||
cellWidth += m_indent * ([m_view levelForRow:row] + 1);
|
||||
cellWidth += m_indent * [m_view levelForRow:row];
|
||||
|
||||
if ( m_expander == 0 && m_tableColumn == [m_view outlineTableColumn] )
|
||||
{
|
||||
NSRect rc = [m_view frameOfOutlineCellAtRow:row];
|
||||
m_expander = ceil(rc.origin.x + rc.size.width);
|
||||
}
|
||||
|
||||
m_width = wxMax(m_width, cellWidth);
|
||||
}
|
||||
|
||||
int GetMaxWidth() const { return m_width; }
|
||||
int GetExpanderWidth() const { return m_expander; }
|
||||
|
||||
private:
|
||||
int m_width;
|
||||
wxCocoaOutlineView *m_view;
|
||||
unsigned m_column;
|
||||
int m_indent;
|
||||
int m_expander;
|
||||
NSTableColumn *m_tableColumn;
|
||||
};
|
||||
|
||||
MaxWidthCalculator calculator(m_OutlineView, column, pos);
|
||||
@@ -2275,7 +2287,12 @@ void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos)
|
||||
count);
|
||||
}
|
||||
|
||||
[column setWidth:calculator.GetMaxWidth()];
|
||||
// there might not necessarily be an expander in the rows we've examined above so let's
|
||||
// globally store the expander width for re-use because it should always be the same
|
||||
if ( m_expanderWidth == 0 )
|
||||
m_expanderWidth = calculator.GetExpanderWidth();
|
||||
|
||||
[column setWidth:calculator.GetMaxWidth() + m_expanderWidth];
|
||||
}
|
||||
|
||||
//
|
||||
|
@@ -73,14 +73,15 @@ public:
|
||||
virtual bool Cleared() wxOVERRIDE;
|
||||
virtual void Resort() wxOVERRIDE;
|
||||
|
||||
// adjust wxCOL_WIDTH_AUTOSIZE columns to fit the data
|
||||
void AdjustAutosizedColumns();
|
||||
|
||||
protected:
|
||||
// if the dataview control can have a variable row height this method sets the dataview's control row height of
|
||||
// the passed item to the maximum value occupied by the item in all columns
|
||||
void AdjustRowHeight(wxDataViewItem const& item);
|
||||
// ... and the same method for a couple of items:
|
||||
void AdjustRowHeights(wxDataViewItemArray const& items);
|
||||
// adjust wxCOL_WIDTH_AUTOSIZE columns to fit the data
|
||||
void AdjustAutosizedColumns();
|
||||
|
||||
private:
|
||||
wxDataViewCtrl* m_DataViewCtrlPtr;
|
||||
@@ -505,6 +506,9 @@ int wxDataViewCtrl::GetColumnPosition(wxDataViewColumn const* columnPtr) const
|
||||
void wxDataViewCtrl::Collapse(wxDataViewItem const& item)
|
||||
{
|
||||
GetDataViewPeer()->Collapse(item);
|
||||
|
||||
if ( m_ModelNotifier )
|
||||
m_ModelNotifier->AdjustAutosizedColumns();
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn const* columnPtr)
|
||||
@@ -518,7 +522,10 @@ void wxDataViewCtrl::EnsureVisible(wxDataViewItem const& item, wxDataViewColumn
|
||||
|
||||
void wxDataViewCtrl::DoExpand(wxDataViewItem const& item)
|
||||
{
|
||||
return GetDataViewPeer()->DoExpand(item);
|
||||
GetDataViewPeer()->DoExpand(item);
|
||||
|
||||
if ( m_ModelNotifier )
|
||||
m_ModelNotifier->AdjustAutosizedColumns();
|
||||
}
|
||||
|
||||
bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const
|
||||
|
Reference in New Issue
Block a user