From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Mon, 24 Jul 2006 14:57:57 +0000 (+0000)
Subject: minor refactoring of OnEraseBackground()
X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/2588b9c467b3a313f516ef81c7d5cfd14d1e8bb6

minor refactoring of OnEraseBackground()


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40275 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---

diff --git a/include/wx/msw/tbar95.h b/include/wx/msw/tbar95.h
index 508dad108a..daa168e3d6 100644
--- a/include/wx/msw/tbar95.h
+++ b/include/wx/msw/tbar95.h
@@ -118,6 +118,9 @@ protected:
     // unneeded
     void CreateDisabledImageList();
 
+    // get the Windows toolbar style of this control
+    long GetMSWToolbarStyle() const;
+
 
     // the big bitmap containing all bitmaps of the toolbar buttons
     WXHBITMAP m_hBitmap;
diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp
index 684e3f117f..8dff81d4f9 100644
--- a/src/msw/tbar95.cpp
+++ b/src/msw/tbar95.cpp
@@ -182,7 +182,6 @@ private:
     DECLARE_NO_COPY_CLASS(wxToolBarTool)
 };
 
-
 // ============================================================================
 // implementation
 // ============================================================================
@@ -248,7 +247,7 @@ bool wxToolBar::Create(wxWindow *parent,
 #if wxUSE_UXTHEME
     if ( style & wxTB_FLAT )
     {
-        LRESULT style = ::SendMessage(GetHwnd(), TB_GETSTYLE, 0, 0L);
+        LRESULT style = GetMSWToolbarStyle();
 
         if ( !(style & TBSTYLE_FLAT) )
             ::SendMessage(GetHwnd(), TB_SETSTYLE, 0, style | TBSTYLE_FLAT);
@@ -1273,6 +1272,12 @@ void wxToolBar::UpdateSize()
 // toolbar styles
 // ---------------------------------------------------------------------------
 
+// get the TBSTYLE of the given toolbar window
+long wxToolBar::GetMSWToolbarStyle() const
+{
+    return ::SendMessage(GetHwnd(), TB_GETSTYLE, 0, 0L);
+}
+
 void wxToolBar::SetWindowStyleFlag(long style)
 {
     // the style bits whose changes force us to recreate the toolbar
@@ -1372,7 +1377,29 @@ void wxToolBar::OnEraseBackground(wxEraseEvent& event)
     RECT rect = wxGetClientRect(GetHwnd());
     HDC hdc = GetHdcOf((*event.GetDC()));
 
-    if ( UseBgCol() )
+#if wxUSE_UXTHEME
+    // we may need to draw themed colour so that we appear correctly on
+    // e.g. notebook page under XP with themes but only do it if the parent
+    // draws themed background itself
+    if ( !UseBgCol() && !GetParent()->UseBgCol() )
+    {
+        wxUxThemeEngine *theme = wxUxThemeEngine::GetIfActive();
+        if ( theme )
+        {
+            HRESULT
+                hr = theme->DrawThemeParentBackground(GetHwnd(), hdc, &rect);
+            if ( hr == S_OK )
+                return;
+
+            // it can also return S_FALSE which seems to simply say that it
+            // didn't draw anything but no error really occurred
+            if ( FAILED(hr) )
+                wxLogApiError(_T("DrawThemeParentBackground(toolbar)"), hr);
+        }
+    }
+#endif // wxUSE_UXTHEME
+
+    if ( UseBgCol() || (GetMSWToolbarStyle() & TBSTYLE_TRANSPARENT) )
     {
         // do draw our background
         //
@@ -1386,39 +1413,8 @@ void wxToolBar::OnEraseBackground(wxEraseEvent& event)
     }
     else // we have no non default background colour
     {
-#if wxUSE_UXTHEME
-        // we may need to draw themed colour so that we appear correctly on
-        // e.g. notebook page under XP with themes but only do it if the parent
-        // draws themed background itself
-        if ( !GetParent()->UseBgCol() )
-        {
-            wxUxThemeEngine *theme = wxUxThemeEngine::GetIfActive();
-            if ( theme )
-            {
-                HRESULT
-                    hr = theme->DrawThemeParentBackground(GetHwnd(), hdc, &rect);
-                if ( hr == S_OK )
-                    return;
-
-                // it can also return S_FALSE which seems to simply say that it
-                // didn't draw anything but no error really occurred
-                if ( FAILED(hr) )
-                    wxLogApiError(_T("DrawThemeParentBackground(toolbar)"), hr);
-            }
-        }
-#endif // wxUSE_UXTHEME
-
-        // if we are transparent then paint our background ourselves
-        LRESULT style = ::SendMessage(GetHwnd(), TB_GETSTYLE, 0, 0L);
-        if ( style & TBSTYLE_TRANSPARENT )
-        {
-            ::FillRect(hdc, &rect, ::GetSysColorBrush(COLOR_BTNFACE));
-        }
-        else
-        {
-            // let the system do it for us
-            event.Skip();
-        }
+        // let the system do it for us
+        event.Skip();
     }
 }