From d9317033424d174e96f48d6bb3241cac1bdcf1bc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 10 Aug 2010 21:48:17 +0000 Subject: [PATCH] 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 --- include/wx/generic/panelg.h | 19 ++++--------------- include/wx/msw/notebook.h | 2 ++ include/wx/msw/window.h | 5 +++++ samples/controls/controls.cpp | 7 ++++--- src/generic/panelg.cpp | 21 +++++++++++++++++---- src/msw/notebook.cpp | 8 -------- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/include/wx/generic/panelg.h b/include/wx/generic/panelg.h index 4aa4c8c..ca552db 100644 --- a/include/wx/generic/panelg.h +++ b/include/wx/generic/panelg.h @@ -77,17 +77,10 @@ public: #endif #ifdef __WXMSW__ - // This is a hack to support inheriting of background through child - // wxPanel: at least wxNotebook needs this under wxMSW as its background - // should apply to its children which are usually wxPanels which normally - // don't have a transparent background. Calling this function allows to - // 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; } + // This is overridden for MSW to return true for all panels that are child + // of a window with themed background (such as wxNotebook) which should + // show through the child panels. + virtual bool HasTransparentBackground(); #endif // __WXMSW__ WX_DECLARE_CONTROL_CONTAINER(); @@ -100,10 +93,6 @@ protected: virtual wxBorder GetDefaultBorder() const { return wxWindowBase::GetDefaultBorder(); } private: -#ifdef __WXMSW__ - bool m_isTransparent; -#endif // __WXMSW__ - DECLARE_DYNAMIC_CLASS_NO_COPY(wxPanel) DECLARE_EVENT_TABLE() }; diff --git a/include/wx/msw/notebook.h b/include/wx/msw/notebook.h index 2dfa433..30fe5c6 100644 --- a/include/wx/msw/notebook.h +++ b/include/wx/msw/notebook.h @@ -187,6 +187,8 @@ public: // draw child background virtual bool MSWPrintChild(WXHDC hDC, wxWindow *win); + + virtual bool MSWHasInheritableBackground() const { return true; } #endif // wxUSE_UXTHEME // translate wxWin styles to the Windows ones diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index 9557141..d2f9d1b 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -438,6 +438,11 @@ public: 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__) #define wxHAS_MSW_BACKGROUND_ERASE_HOOK #endif diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index 81a6236..e95eda9 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -949,9 +949,10 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) dc.DrawText(wxT("Bitmap"), 30, 40); dc.SelectObject( wxNullBitmap ); - (void)new wxBitmapButton(panel, ID_BITMAP_BTN, bitmap, wxPoint(100, 20)); - (void)new wxToggleButton(panel, ID_BITMAP_BTN_ENABLE, - wxT("Enable/disable &bitmap"), wxPoint(100, 140)); + wxPanel *panel2 = new wxPanel(panel, -1, wxPoint(100, 0), wxSize(100, 200)); + (void)new wxBitmapButton(panel2, ID_BITMAP_BTN, bitmap, wxPoint(0, 20)); + (void)new wxToggleButton(panel2, ID_BITMAP_BTN_ENABLE, + wxT("Enable/disable &bitmap"), wxPoint(0, 140)); #if defined(__WXMSW__) || defined(__WXMOTIF__) // test for masked bitmap display diff --git a/src/generic/panelg.cpp b/src/generic/panelg.cpp index ee4a901..32e656f 100644 --- a/src/generic/panelg.cpp +++ b/src/generic/panelg.cpp @@ -104,10 +104,6 @@ WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel, wxWindow) void wxPanel::Init() { WX_INIT_CONTROL_CONTAINER(); - -#ifdef __WXMSW__ - m_isTransparent = false; -#endif // __WXMSW__ } bool wxPanel::Create(wxWindow *parent, wxWindowID id, @@ -141,3 +137,20 @@ void wxPanel::InitDialog() 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__ diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 1e9a26d..b199c98 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -819,14 +819,6 @@ bool wxNotebook::InsertPage(size_t nPage, // succeeded: save the pointer to the page 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: // 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 -- 2.7.4