diff --git a/docs/changes.txt b/docs/changes.txt index 0c2498fcc4..ebe8bda1de 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -157,6 +157,7 @@ wxOSX: - Fix unnecessary indentation in list-like wxDataViewCtrl (Andreas Falkenhahn). - Recognize macOS 10.12 Sierra in wxGetOsDescription() (Tobias Taschner). - Don't try to open command line arguments as files (Jeff Hostetler). +- Implement wxDataViewCtrl::SetRowHeight(). Unix: diff --git a/include/wx/osx/cocoa/dataview.h b/include/wx/osx/cocoa/dataview.h index d7cca628b0..d483ab6bca 100644 --- a/include/wx/osx/cocoa/dataview.h +++ b/include/wx/osx/cocoa/dataview.h @@ -506,6 +506,7 @@ public: virtual void HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const; + virtual void SetRowHeight(int height); virtual void SetRowHeight(const wxDataViewItem& item, unsigned int height); virtual void OnSize(); @@ -520,6 +521,7 @@ public: private: void InitOutlineView(long style); + int GetDefaultRowHeight() const; wxCocoaOutlineDataSource* m_DataSource; diff --git a/include/wx/osx/core/dataview.h b/include/wx/osx/core/dataview.h index 788ab42b03..bf629c6349 100644 --- a/include/wx/osx/core/dataview.h +++ b/include/wx/osx/core/dataview.h @@ -106,6 +106,7 @@ public: virtual void DoExpand (wxDataViewItem const& item) = 0; // expands the passed item in the native control virtual void HitTest (wxPoint const& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const = 0; // return the item and column pointer that contains with the passed point + virtual void SetRowHeight(int height) = 0; // sets the height of all rows virtual void SetRowHeight(wxDataViewItem const& item, unsigned int height) = 0; // sets the height of the row containg the passed item in the native control virtual void OnSize (void) = 0; // updates the layout of the native control after a size event virtual void StartEditor( const wxDataViewItem & item, unsigned int column ) = 0; // starts editing the passed in item and column diff --git a/include/wx/osx/dataview.h b/include/wx/osx/dataview.h index 7d81447ebf..452a2718e3 100644 --- a/include/wx/osx/dataview.h +++ b/include/wx/osx/dataview.h @@ -179,6 +179,8 @@ public: virtual void HitTest(const wxPoint& point, wxDataViewItem& item, wxDataViewColumn*& columnPtr) const wxOVERRIDE; + virtual bool SetRowHeight(int rowHeight) wxOVERRIDE; + virtual bool IsSelected(const wxDataViewItem& item) const wxOVERRIDE; virtual void SelectAll() wxOVERRIDE; diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index f9c37a3c0a..849b4d4c9a 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -1596,8 +1596,8 @@ public: This function can only be used when all rows have the same height, i.e. when wxDV_VARIABLE_LINE_HEIGHT flag is not used. - Currently this is implemented in the generic and native GTK versions - only and nothing is done (and @false returned) when using OS X port. + Currently this is implemented in the generic and native GTK and OS X + (since 3.1.1) versions. Also notice that this method can only be used to increase the row height compared with the default one (as determined by the return value diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 257687338e..02103f7606 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -1975,6 +1975,8 @@ wxCocoaDataViewControl::~wxCocoaDataViewControl() // bool wxCocoaDataViewControl::ClearColumns() { + CGFloat rowHeight = [m_OutlineView rowHeight]; + // as there is a bug in NSOutlineView version (OSX 10.5.6 #6555162) the // columns cannot be deleted if there is an outline column in the view; // therefore, the whole view is deleted and newly constructed: @@ -1985,6 +1987,8 @@ bool wxCocoaDataViewControl::ClearColumns() InitOutlineView(GetDataViewCtrl()->GetWindowStyle()); + [m_OutlineView setRowHeight:rowHeight]; + return true; } @@ -2418,6 +2422,24 @@ void wxCocoaDataViewControl::HitTest(const wxPoint& point, wxDataViewItem& item, } } +void wxCocoaDataViewControl::SetRowHeight(int height) +{ + [m_OutlineView setRowHeight:wxMax(height, GetDefaultRowHeight())]; +} + +int wxCocoaDataViewControl::GetDefaultRowHeight() const +{ + const int MINIMUM_NATIVE_HEIGHT = 17; + // Custom setup of NSLayoutManager is necessary to match NSTableView sizing. + // See http://stackoverflow.com/questions/17095927/dynamically-changing-row-height-after-font-size-of-entire-nstableview-nsoutlin + NSLayoutManager *lm = [[NSLayoutManager alloc] init]; + [lm setTypesetterBehavior:NSTypesetterBehavior_10_2_WithCompatibility]; + [lm setUsesScreenFonts:NO]; + CGFloat height = [lm defaultLineHeightForFont:GetWXPeer()->GetFont().OSXGetNSFont()]; + [lm release]; + return wxMax(MINIMUM_NATIVE_HEIGHT, int(height)); +} + void wxCocoaDataViewControl::SetRowHeight(const wxDataViewItem& WXUNUSED(item), unsigned int WXUNUSED(height)) // Not supported by the native control { diff --git a/src/osx/dataview_osx.cpp b/src/osx/dataview_osx.cpp index 54d1ad5053..33ad781b33 100644 --- a/src/osx/dataview_osx.cpp +++ b/src/osx/dataview_osx.cpp @@ -568,6 +568,12 @@ void wxDataViewCtrl::HitTest(wxPoint const& point, wxDataViewItem& item, wxDataV return GetDataViewPeer()->HitTest(point,item,columnPtr); } +bool wxDataViewCtrl::SetRowHeight(int rowHeight) +{ + GetDataViewPeer()->SetRowHeight(rowHeight); + return true; +} + bool wxDataViewCtrl::IsSelected(wxDataViewItem const& item) const { return GetDataViewPeer()->IsSelected(item);