diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index 9f54e49e6d..90be1a8ae0 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -86,7 +86,7 @@ class wxCocoaDataViewControl; class wxDataViewColumnNativeData { public: - wxDataViewColumnNativeData() : m_NativeColumnPtr(NULL), m_isLast(false), m_prevWidth(0) + wxDataViewColumnNativeData() : m_NativeColumnPtr(NULL) { } @@ -105,32 +105,9 @@ public: 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: // not owned by us NSTableColumn* m_NativeColumnPtr; - - bool m_isLast; - int m_prevWidth; }; // ============================================================================ diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index ae6fb345bb..3b603a36e9 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2092,7 +2092,7 @@ wxCocoaDataViewControl::wxCocoaDataViewControl(wxWindow* peer, ), m_DataSource(NULL), m_OutlineView([[wxCocoaOutlineView alloc] init]), - m_expanderWidth(0) + m_expanderWidth(-1) { // initialize scrollview (the outline view is part of a scrollview): NSScrollView* scrollview = (NSScrollView*) GetWXWidget(); @@ -2243,9 +2243,7 @@ bool wxCocoaDataViewControl::InsertColumn(unsigned int pos, wxDataViewColumn* co void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos) { const int count = GetCount(); - wxDataViewColumnNativeData *nativeData = GetColumn(pos)->GetNativeData(); - NSTableColumn *column = nativeData->GetNativeColumnPtr(); - UInt32 const noOfColumns = [[m_OutlineView tableColumns] count]; + NSTableColumn *column = GetColumn(pos)->GetNativeData()->GetNativeColumnPtr(); class MaxWidthCalculator { @@ -2253,11 +2251,10 @@ void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos) MaxWidthCalculator(wxCocoaOutlineView *view, NSTableColumn *column, unsigned columnIndex) : m_width(0), - m_height(0), m_view(view), m_column(columnIndex), m_indent(0), - m_expander(0), + m_expander(-1), m_tableColumn(column) { // account for indentation in the column with expander @@ -2274,28 +2271,24 @@ void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos) { NSCell *cell = [m_view preparedCellAtColumn:m_column row:row]; unsigned cellWidth = ceil([cell cellSize].width); - unsigned cellHeight = ceil([cell cellSize].height); if ( m_indent ) cellWidth += m_indent * [m_view levelForRow:row]; - if ( m_expander == 0 && m_tableColumn == [m_view outlineTableColumn] ) + if ( m_expander == -1 && 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); - m_height = wxMax(m_height, cellHeight); } int GetMaxWidth() const { return m_width; } - int GetMaxHeight() const { return m_height; } int GetExpanderWidth() const { return m_expander; } private: int m_width; - int m_height; wxCocoaOutlineView *m_view; unsigned m_column; int m_indent; @@ -2373,42 +2366,10 @@ void wxCocoaDataViewControl::FitColumnWidthToContent(unsigned int pos) // 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 ) + if ( m_expanderWidth == -1 ) m_expanderWidth = calculator.GetExpanderWidth(); - 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]; - } - else if ( GetColumn(pos)->GetWidthVariable() == wxCOL_WIDTH_AUTOSIZE ) - { - [column setWidth:calculator.GetMaxWidth() + m_expanderWidth]; - } - else if ( nativeData->GetIsLast() ) - { - [column setWidth:nativeData->GetPrevWidth()]; - } - - nativeData->SetIsLast(isLast); - - if ( !(GetDataViewCtrl()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) ) - { - int curHeight = ceil([m_OutlineView rowHeight]); - int rowHeight = calculator.GetMaxHeight(); - if ( rowHeight > curHeight ) - SetRowHeight(rowHeight); - } + [column setWidth:calculator.GetMaxWidth() + wxMax(0, m_expanderWidth)]; } // diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index 7ac200d45b..def9d099d4 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -302,7 +302,10 @@ void wxOSXDataViewModelNotifier::AdjustAutosizedColumns() unsigned count = m_DataViewCtrlPtr->GetColumnCount(); for ( unsigned col = 0; col < count; col++ ) { - m_DataViewCtrlPtr->GetDataViewPeer()->FitColumnWidthToContent(col); + wxDataViewColumn *column = m_DataViewCtrlPtr->GetColumnPtr(col); + + if ( column->GetWidthVariable() == wxCOL_WIDTH_AUTOSIZE ) + m_DataViewCtrlPtr->GetDataViewPeer()->FitColumnWidthToContent(col); } } @@ -438,9 +441,6 @@ bool wxDataViewCtrl::InsertColumn(unsigned int pos, wxDataViewColumn* columnPtr) // otherwise ask the control to 'update' the data in the newly appended column: if (GetColumnCount() == 1) SetExpanderColumn(columnPtr); - - AdjustAutosizedColumns(); - // done: return true; } @@ -482,8 +482,6 @@ bool wxDataViewCtrl::DeleteColumn(wxDataViewColumn* columnPtr) { m_ColumnPtrs.Remove(columnPtr); delete columnPtr; - - AdjustAutosizedColumns(); return true; } else