Fix wx[Check]ListBox font and margin on DPI change
These control are drawn using a wxDC. When the DPI changes, call SetFont to update the font of the wxDC. First call wxListBoxBase::SetFont() so m_font is updated to the new DPI, then use this font in the wxDC. For wxCheckListBox update the margins to fit the changed checkbox size.
This commit is contained in:
@@ -81,6 +81,8 @@ protected:
|
||||
ProcessCommand(event);
|
||||
}
|
||||
|
||||
virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI) wxOVERRIDE;
|
||||
|
||||
wxSize DoGetBestClientSize() const wxOVERRIDE;
|
||||
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
|
@@ -181,6 +181,8 @@ protected:
|
||||
return wxSize(w, h);
|
||||
}
|
||||
|
||||
virtual void MSWUpdateFontOnDPIChange(const wxSize& newDPI) wxOVERRIDE;
|
||||
|
||||
// free memory (common part of Clear() and dtor)
|
||||
void Free();
|
||||
|
||||
|
@@ -255,7 +255,20 @@ bool wxCheckListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item)
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void wxCheckListBox::MSWUpdateFontOnDPIChange(const wxSize& newDPI)
|
||||
{
|
||||
wxCheckListBoxBase::MSWUpdateFontOnDPIChange(newDPI);
|
||||
|
||||
wxSize size = wxRendererNative::Get().GetCheckBoxSize(this);
|
||||
size.x += 2 * CHECKMARK_EXTRA_SPACE + CHECKMARK_LABEL_SPACE;
|
||||
|
||||
for ( unsigned int i = 0; i < GetCount(); ++i )
|
||||
{
|
||||
GetItem(i)->SetMarginWidth(size.GetWidth());
|
||||
}
|
||||
}
|
||||
|
||||
// check items
|
||||
// -----------
|
||||
|
@@ -190,6 +190,14 @@ WXDWORD wxListBox::MSWGetStyle(long style, WXDWORD *exstyle) const
|
||||
return msStyle;
|
||||
}
|
||||
|
||||
void wxListBox::MSWUpdateFontOnDPIChange(const wxSize& newDPI)
|
||||
{
|
||||
wxListBoxBase::MSWUpdateFontOnDPIChange(newDPI);
|
||||
|
||||
if ( m_font.IsOk() )
|
||||
SetFont(m_font);
|
||||
}
|
||||
|
||||
void wxListBox::OnInternalIdle()
|
||||
{
|
||||
wxWindow::OnInternalIdle();
|
||||
@@ -695,22 +703,22 @@ bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
|
||||
|
||||
bool wxListBox::SetFont(const wxFont &font)
|
||||
{
|
||||
wxListBoxBase::SetFont(font);
|
||||
|
||||
if ( HasFlag(wxLB_OWNERDRAW) )
|
||||
{
|
||||
const unsigned count = m_aItems.GetCount();
|
||||
for ( unsigned i = 0; i < count; i++ )
|
||||
m_aItems[i]->SetFont(font);
|
||||
m_aItems[i]->SetFont(m_font);
|
||||
|
||||
// Non owner drawn list boxes update the item height on their own, but
|
||||
// we need to do it manually in the owner drawn case.
|
||||
wxClientDC dc(this);
|
||||
dc.SetFont(font);
|
||||
dc.SetFont(m_font);
|
||||
SendMessage(GetHwnd(), LB_SETITEMHEIGHT, 0,
|
||||
dc.GetCharHeight() + 2 * LISTBOX_EXTRA_SPACE);
|
||||
}
|
||||
|
||||
wxListBoxBase::SetFont(font);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user