diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index 41d16201d8..e45ed0f358 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -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_ diff --git a/include/wx/osx/dataview.h b/include/wx/osx/dataview.h index a7a58d6f54..80e6aa0e99 100644 --- a/include/wx/osx/dataview.h +++ b/include/wx/osx/dataview.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); diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 770719e4a9..9f927f6abf 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -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]; } // diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index ad197cc85c..7fc3dec650 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -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