Fix font of custom attributes in wxTreeCtrl on DPI change

This commit is contained in:
Maarten Bent
2019-02-17 19:47:01 +01:00
parent b075465645
commit 017978a139
2 changed files with 15 additions and 1 deletions

View File

@@ -261,6 +261,7 @@ protected:
// return true if the key was processed, false otherwise // return true if the key was processed, false otherwise
bool MSWHandleSelectionKey(unsigned vkey); bool MSWHandleSelectionKey(unsigned vkey);
virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI) wxOVERRIDE;
// data used only while editing the item label: // data used only while editing the item label:
wxTextCtrl *m_textCtrl; // text control in which it is edited wxTextCtrl *m_textCtrl; // text control in which it is edited

View File

@@ -1253,7 +1253,9 @@ void wxTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font)
attr = it->second; attr = it->second;
} }
attr->SetFont(font); wxFont f = font;
f.WXAdjustToPPI(GetDPI());
attr->SetFont(f);
// Reset the item's text to ensure that the bounding rect will be adjusted // Reset the item's text to ensure that the bounding rect will be adjusted
// for the new font. // for the new font.
@@ -2270,6 +2272,17 @@ bool wxTreeCtrl::MSWCommand(WXUINT cmd, WXWORD id_)
return true; return true;
} }
void wxTreeCtrl::MSWUpdateFontOnDPIChange(const wxSize& newDPI)
{
wxTreeCtrlBase::MSWUpdateFontOnDPIChange(newDPI);
for ( wxMapTreeAttr::const_iterator it = m_attrs.begin(); it != m_attrs.end(); ++it )
{
if ( it->second->HasFont() )
SetItemFont(it->first, it->second->GetFont());
}
}
bool wxTreeCtrl::MSWIsOnItem(unsigned flags) const bool wxTreeCtrl::MSWIsOnItem(unsigned flags) const
{ {
unsigned mask = TVHT_ONITEM; unsigned mask = TVHT_ONITEM;