]> git.saurik.com Git - wxWidgets.git/commitdiff
Inherit notebook background recursively under wxMSW.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 10 Aug 2010 21:48:17 +0000 (21:48 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 10 Aug 2010 21:48:17 +0000 (21:48 +0000)
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
include/wx/msw/notebook.h
include/wx/msw/window.h
samples/controls/controls.cpp
src/generic/panelg.cpp
src/msw/notebook.cpp

index 4aa4c8c9886c87b898bd1ca4584d653938acc596..ca552db5fb9bb2c245e543e8f53ef3ac2435fbb6 100644 (file)
@@ -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()
 };
index 2dfa4337e8951320875c752864bba3072c47360c..30fe5c6780727c9ccdf1548378500c8a5f84b053 100644 (file)
@@ -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
index 9557141e5ff3eaceffedc60b79c025d7394c9a48..d2f9d1be90e927ab7cd6d9c093663fbd966d4675 100644 (file)
@@ -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
index 81a62369ba4befe6a2a35a6c8ac087f1d286d4ec..e95eda9e445c7cb6a3ad4e8535ef6b7a2901a10a 100644 (file)
@@ -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
index ee4a901a06c105d6d431934a31a54f54a9d5f70b..32e656f94e3c6f431b47c058c8e5e7f636511df6 100644 (file)
@@ -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__
index 1e9a26dbbf6bbdffee2b91abdca4cfd9bbd0e75e..b199c98ab9ea8ce90c5ea660c32e4c7f82e48ed0 100644 (file)
@@ -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