Implement wxDataViewCtrl::SetFont() on OS X

wxDataViewCtrl now behaves consistently with other ports on OS X:
calling SetFont() sets the default font used by renderers and adjusts
row height to fit.
This commit is contained in:
Václav Slavík 2016-10-09 16:09:24 +02:00
parent 8a6a20b1e3
commit 29d310c6f0
2 changed files with 23 additions and 1 deletions

View File

@ -204,6 +204,10 @@ public:
// Set the line break mode for the given cell using our m_ellipsizeMode
void ApplyLineBreakMode(NSCell *cell);
// Does the rendered use a font that the control can't override?
void SetHasCustomFont(bool has) { m_hasCustomFont = has; }
bool HasCustomFont() const { return m_hasCustomFont; }
private:
// common part of all ctors
void Init();
@ -224,6 +228,8 @@ private:
NSColor *m_origTextColour;
wxEllipsizeMode m_ellipsizeMode;
bool m_hasCustomFont;
};
// ============================================================================
@ -519,6 +525,8 @@ public:
// Cocoa-specific helpers
id GetItemAtRow(int row) const;
virtual void SetFont(const wxFont& font, const wxColour& foreground, long windowStyle, bool ignoreBlack = true);
private:
void InitOutlineView(long style);
int GetDefaultRowHeight() const;

View File

@ -392,6 +392,10 @@ NSTableColumn* CreateNativeColumn(const wxDataViewColumn *column)
[[nativeColumn dataCell] setWraps:NO];
// setting the default data cell:
[nativeColumn setDataCell:renderData->GetColumnCell()];
if (!renderData->HasCustomFont())
[renderData->GetColumnCell() setFont:column->GetOwner()->GetFont().OSXGetNSFont()];
// setting the editablility:
const bool isEditable = renderer->GetMode() == wxDATAVIEW_CELL_EDITABLE;
@ -2547,6 +2551,13 @@ id wxCocoaDataViewControl::GetItemAtRow(int row) const
return [m_OutlineView itemAtRow:row];
}
void wxCocoaDataViewControl::SetFont(const wxFont& font, const wxColour& foreground, long windowStyle, bool ignoreBlack)
{
wxWidgetCocoaImpl::SetFont(font, foreground, windowStyle, ignoreBlack);
SetRowHeight(0/*will use default/minimum height*/);
}
// ----------------------------------------------------------------------------
// wxDataViewRendererNativeData
// ----------------------------------------------------------------------------
@ -2556,6 +2567,7 @@ void wxDataViewRendererNativeData::Init()
m_origFont = NULL;
m_origTextColour = NULL;
m_ellipsizeMode = wxELLIPSIZE_MIDDLE;
m_hasCustomFont = false;
if ( m_ColumnCell )
ApplyLineBreakMode(m_ColumnCell);
@ -2890,7 +2902,9 @@ wxDataViewChoiceRenderer::wxDataViewChoiceRenderer(const wxArrayString& choices,
[cell setFont:[NSFont fontWithName:[[cell font] fontName] size:[NSFont systemFontSizeForControlSize:NSMiniControlSize]]];
for (size_t i=0; i<choices.GetCount(); ++i)
[cell addItemWithTitle:wxCFStringRef(choices[i]).AsNSString()];
SetNativeData(new wxDataViewRendererNativeData(cell));
wxDataViewRendererNativeData *data = new wxDataViewRendererNativeData(cell);
data->SetHasCustomFont(true);
SetNativeData(data);
[cell release];
}