Fix colours and fonts of wxStaticBox label window in wxMSW

Inherit from wxCompositeWindowSettersOnly<> to make sure all the usual
setters, such as SetForegroundColour() and SetFont(), called on
wxStaticBox are propagated to the label window too.

However also prevent SetBackgroundColour() from being propagated
unnecessarily -- because the checkbox already inherits the parent
background colour by default in wxMSW anyhow -- and still override
SetFont() to adjust the label window position after the font change,
otherwise it could be truncated after increasing the font size, for
example.

Because of these issues, wxCompositeWindowSettersOnly is not ideally
suited for its use here, but on balance it still seems to be better to
use it rather than reimplement parts of its functionality here.
This commit is contained in:
Vadim Zeitlin
2017-12-24 21:48:51 +01:00
parent 329af399eb
commit fdf47e8e12
2 changed files with 56 additions and 3 deletions

View File

@@ -11,11 +11,16 @@
#ifndef _WX_MSW_STATBOX_H_
#define _WX_MSW_STATBOX_H_
#include "wx/compositewin.h"
// Group box
class WXDLLIMPEXP_CORE wxStaticBox : public wxStaticBoxBase
class WXDLLIMPEXP_CORE wxStaticBox : public wxCompositeWindowSettersOnly<wxStaticBoxBase>
{
public:
wxStaticBox() { }
wxStaticBox()
: wxCompositeWindowSettersOnly<wxStaticBoxBase>()
{
}
wxStaticBox(wxWindow *parent, wxWindowID id,
const wxString& label,
@@ -23,6 +28,7 @@ public:
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxStaticBoxNameStr)
: wxCompositeWindowSettersOnly<wxStaticBoxBase>()
{
Create(parent, id, label, pos, size, style, name);
}
@@ -33,6 +39,7 @@ public:
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString &name = wxStaticBoxNameStr)
: wxCompositeWindowSettersOnly<wxStaticBoxBase>()
{
Create(parent, id, label, pos, size, style, name);
}
@@ -54,6 +61,9 @@ public:
/// Implementation only
virtual void GetBordersForSizer(int *borderTop, int *borderOther) const wxOVERRIDE;
virtual bool SetBackgroundColour(const wxColour& colour) wxOVERRIDE;
virtual bool SetFont(const wxFont& font) wxOVERRIDE;
virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const wxOVERRIDE;
// returns true if the platform should explicitly apply a theme border
@@ -66,6 +76,8 @@ public:
virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE;
protected:
virtual wxWindowList GetCompositeWindowParts() const wxOVERRIDE;
// return the region with all the windows inside this static box excluded
virtual WXHRGN MSWGetRegionWithoutChildren();
@@ -80,6 +92,9 @@ protected:
void OnPaint(wxPaintEvent& event);
private:
void PositionLabelWindow();
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxStaticBox);
};