Implement wxDataViewCtrl::SetRowHeight() on OS X

This commit is contained in:
Václav Slavík
2016-10-09 13:53:09 +02:00
parent e7145999f4
commit 8a6a20b1e3
7 changed files with 36 additions and 2 deletions

View File

@@ -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:

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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
{

View File

@@ -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);