diff --git a/include/wx/generic/panelg.h b/include/wx/generic/panelg.h index 4aa4c8c988..ca552db5fb 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 2dfa4337e8..30fe5c6780 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 9557141e5f..d2f9d1be90 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 81a62369ba..e95eda9e44 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 ee4a901a06..32e656f94e 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 1e9a26dbbf..b199c98ab9 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