Inherit notebook background recursively under wxMSW.
With MSWSetTransparentBackground() hack only the panel which was the immediate child of wxNotebook (i.e. its page) inherited the notebook background but not its children. This resulted in jarring background discontinuities when nested panels were used. Fix this by inheriting notebook background in all child panels by testing for the return value of the parents MSWHasInheritableBackground() method in wxPanel::HasTransparentBackground() recursively. Closes #12317. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65238 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -77,17 +77,10 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
// This is a hack to support inheriting of background through child
|
// This is overridden for MSW to return true for all panels that are child
|
||||||
// wxPanel: at least wxNotebook needs this under wxMSW as its background
|
// of a window with themed background (such as wxNotebook) which should
|
||||||
// should apply to its children which are usually wxPanels which normally
|
// show through the child panels.
|
||||||
// don't have a transparent background. Calling this function allows to
|
virtual bool HasTransparentBackground();
|
||||||
// change this for the panels which are used as notebook pages.
|
|
||||||
void MSWSetTransparentBackground(bool isTransparent = true)
|
|
||||||
{
|
|
||||||
m_isTransparent = isTransparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool HasTransparentBackground() { return m_isTransparent; }
|
|
||||||
#endif // __WXMSW__
|
#endif // __WXMSW__
|
||||||
|
|
||||||
WX_DECLARE_CONTROL_CONTAINER();
|
WX_DECLARE_CONTROL_CONTAINER();
|
||||||
@@ -100,10 +93,6 @@ protected:
|
|||||||
virtual wxBorder GetDefaultBorder() const { return wxWindowBase::GetDefaultBorder(); }
|
virtual wxBorder GetDefaultBorder() const { return wxWindowBase::GetDefaultBorder(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef __WXMSW__
|
|
||||||
bool m_isTransparent;
|
|
||||||
#endif // __WXMSW__
|
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxPanel)
|
DECLARE_DYNAMIC_CLASS_NO_COPY(wxPanel)
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
@@ -187,6 +187,8 @@ public:
|
|||||||
|
|
||||||
// draw child background
|
// draw child background
|
||||||
virtual bool MSWPrintChild(WXHDC hDC, wxWindow *win);
|
virtual bool MSWPrintChild(WXHDC hDC, wxWindow *win);
|
||||||
|
|
||||||
|
virtual bool MSWHasInheritableBackground() const { return true; }
|
||||||
#endif // wxUSE_UXTHEME
|
#endif // wxUSE_UXTHEME
|
||||||
|
|
||||||
// translate wxWin styles to the Windows ones
|
// translate wxWin styles to the Windows ones
|
||||||
|
@@ -438,6 +438,11 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This should be overridden to return true for the controls which have
|
||||||
|
// themed background that should through their children. Currently only
|
||||||
|
// wxNotebook uses this.
|
||||||
|
virtual bool MSWHasInheritableBackground() const { return false; }
|
||||||
|
|
||||||
#if !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
|
#if !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__)
|
||||||
#define wxHAS_MSW_BACKGROUND_ERASE_HOOK
|
#define wxHAS_MSW_BACKGROUND_ERASE_HOOK
|
||||||
#endif
|
#endif
|
||||||
|
@@ -949,9 +949,10 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
|
|||||||
dc.DrawText(wxT("Bitmap"), 30, 40);
|
dc.DrawText(wxT("Bitmap"), 30, 40);
|
||||||
dc.SelectObject( wxNullBitmap );
|
dc.SelectObject( wxNullBitmap );
|
||||||
|
|
||||||
(void)new wxBitmapButton(panel, ID_BITMAP_BTN, bitmap, wxPoint(100, 20));
|
wxPanel *panel2 = new wxPanel(panel, -1, wxPoint(100, 0), wxSize(100, 200));
|
||||||
(void)new wxToggleButton(panel, ID_BITMAP_BTN_ENABLE,
|
(void)new wxBitmapButton(panel2, ID_BITMAP_BTN, bitmap, wxPoint(0, 20));
|
||||||
wxT("Enable/disable &bitmap"), wxPoint(100, 140));
|
(void)new wxToggleButton(panel2, ID_BITMAP_BTN_ENABLE,
|
||||||
|
wxT("Enable/disable &bitmap"), wxPoint(0, 140));
|
||||||
|
|
||||||
#if defined(__WXMSW__) || defined(__WXMOTIF__)
|
#if defined(__WXMSW__) || defined(__WXMOTIF__)
|
||||||
// test for masked bitmap display
|
// test for masked bitmap display
|
||||||
|
@@ -104,10 +104,6 @@ WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel, wxWindow)
|
|||||||
void wxPanel::Init()
|
void wxPanel::Init()
|
||||||
{
|
{
|
||||||
WX_INIT_CONTROL_CONTAINER();
|
WX_INIT_CONTROL_CONTAINER();
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
|
||||||
m_isTransparent = false;
|
|
||||||
#endif // __WXMSW__
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxPanel::Create(wxWindow *parent, wxWindowID id,
|
bool wxPanel::Create(wxWindow *parent, wxWindowID id,
|
||||||
@@ -141,3 +137,20 @@ void wxPanel::InitDialog()
|
|||||||
GetEventHandler()->ProcessEvent(event);
|
GetEventHandler()->ProcessEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
|
||||||
|
bool wxPanel::HasTransparentBackground()
|
||||||
|
{
|
||||||
|
for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
|
||||||
|
{
|
||||||
|
if ( win->MSWHasInheritableBackground() )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if ( win->IsTopLevel() )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // __WXMSW__
|
||||||
|
@@ -819,14 +819,6 @@ bool wxNotebook::InsertPage(size_t nPage,
|
|||||||
// succeeded: save the pointer to the page
|
// succeeded: save the pointer to the page
|
||||||
m_pages.Insert(pPage, nPage);
|
m_pages.Insert(pPage, nPage);
|
||||||
|
|
||||||
// also ensure that the notebook background is used for its pages by making
|
|
||||||
// them transparent: this ensures that MSWGetBgBrush() queries the notebook
|
|
||||||
// for the background brush to be used for erasing them
|
|
||||||
if ( wxPanel *panel = wxDynamicCast(pPage, wxPanel) )
|
|
||||||
{
|
|
||||||
panel->MSWSetTransparentBackground();
|
|
||||||
}
|
|
||||||
|
|
||||||
// we may need to adjust the size again if the notebook size changed:
|
// we may need to adjust the size again if the notebook size changed:
|
||||||
// normally this only happens for the first page we add (the tabs which
|
// normally this only happens for the first page we add (the tabs which
|
||||||
// hadn't been there before are now shown) but for a multiline notebook it
|
// hadn't been there before are now shown) but for a multiline notebook it
|
||||||
|
Reference in New Issue
Block a user