Replace dynamic casts with MSWShouldSetDefaultFont() virtual method
Get rid of ugly wxDynamicCastThis()s in wxMSW wxControl code and add a new virtual method overridden in wx{Tree,List}Ctrl instead. Also stop comparing the font with wxSYS_DEFAULT_GUI_FONT, there doesn't seem to be any good reason to set this particular font for these controls neither. In addition to simplifying and de-ugligying the code, this commit incidentally fixes -Wnonnull-compare warnings in this code from gcc6 too.
This commit is contained in:
@@ -70,6 +70,12 @@ public:
|
||||
virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const wxOVERRIDE;
|
||||
|
||||
protected:
|
||||
// Hook for common controls for which we don't want to set the default font
|
||||
// as if we do set it, the controls don't update their font size
|
||||
// automatically in response to WM_SETTINGCHANGE if it's changed in the
|
||||
// display properties in the control panel, so avoid doing this for them.
|
||||
virtual bool MSWShouldSetDefaultFont() const { return true; }
|
||||
|
||||
// choose the default border for this window
|
||||
virtual wxBorder GetDefaultBorder() const wxOVERRIDE;
|
||||
|
||||
|
@@ -380,6 +380,8 @@ protected:
|
||||
// common part of all ctors
|
||||
void Init();
|
||||
|
||||
virtual bool MSWShouldSetDefaultFont() const wxOVERRIDE { return false; }
|
||||
|
||||
// Implement constrained best size calculation.
|
||||
virtual int DoGetBestClientHeight(int width) const wxOVERRIDE
|
||||
{ return MSWGetBestViewRect(width, -1).y; }
|
||||
|
@@ -211,6 +211,8 @@ protected:
|
||||
int width, int height,
|
||||
int sizeFlags = wxSIZE_AUTO) wxOVERRIDE;
|
||||
|
||||
virtual bool MSWShouldSetDefaultFont() const wxOVERRIDE { return false; }
|
||||
|
||||
// SetImageList helper
|
||||
void SetAnyImageList(wxImageList *imageList, int which);
|
||||
|
||||
|
@@ -184,39 +184,7 @@ bool wxControl::MSWCreateControl(const wxChar *classname,
|
||||
InheritAttributes();
|
||||
if ( !m_hasFont )
|
||||
{
|
||||
bool setFont = true;
|
||||
|
||||
wxFont font = GetDefaultAttributes().font;
|
||||
|
||||
// if we set a font for {list,tree}ctrls and the font size is changed in
|
||||
// the display properties then the font size for these controls doesn't
|
||||
// automatically adjust when they receive WM_SETTINGCHANGE
|
||||
|
||||
// FIXME: replace the dynamic casts with virtual function calls!!
|
||||
#if wxUSE_LISTCTRL || wxUSE_TREECTRL
|
||||
bool testFont = false;
|
||||
#if wxUSE_LISTCTRL
|
||||
if ( wxDynamicCastThis(wxListCtrl) )
|
||||
testFont = true;
|
||||
#endif // wxUSE_LISTCTRL
|
||||
#if wxUSE_TREECTRL
|
||||
if ( wxDynamicCastThis(wxTreeCtrl) )
|
||||
testFont = true;
|
||||
#endif // wxUSE_TREECTRL
|
||||
|
||||
if ( testFont )
|
||||
{
|
||||
// we can't explicitly set the font here
|
||||
// see wxGetCCDefaultFont() in src/msw/settings.cpp for explanation
|
||||
// of why this test works
|
||||
if ( font != wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) )
|
||||
{
|
||||
setFont = false;
|
||||
}
|
||||
}
|
||||
#endif // wxUSE_LISTCTRL || wxUSE_TREECTRL
|
||||
|
||||
if ( setFont )
|
||||
if ( MSWShouldSetDefaultFont() )
|
||||
{
|
||||
SetFont(GetDefaultAttributes().font);
|
||||
}
|
||||
|
Reference in New Issue
Block a user