]> git.saurik.com Git - wxWidgets.git/commitdiff
Restored the ability to set the background colour for a toolbar on Windows
authorJulian Smart <julian@anthemion.co.uk>
Sun, 6 Feb 2005 18:42:43 +0000 (18:42 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Sun, 6 Feb 2005 18:42:43 +0000 (18:42 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31806 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/tbar95.h
src/msw/tbar95.cpp

index 03cb30b65769e940fea1881c6a006e2241edf106..0f74e3da580b1b0a2ef3172574530fe712c90487 100644 (file)
@@ -67,6 +67,7 @@ public:
 
     void OnMouseEvent(wxMouseEvent& event);
     void OnSysColourChanged(wxSysColourChangedEvent& event);
+    void OnEraseBackground(wxEraseEvent& event);
 
     void SetFocus() {}
 
index 28f96b3f93bb5fb7860bb127cfb6d47ab2ef2ff1..48a58f45d4d5f1dad340c4f6ce71c8a1c4b9cd77 100644 (file)
@@ -124,6 +124,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
 BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase)
     EVT_MOUSE_EVENTS(wxToolBar::OnMouseEvent)
     EVT_SYS_COLOUR_CHANGED(wxToolBar::OnSysColourChanged)
+    EVT_ERASE_BACKGROUND(wxToolBar::OnEraseBackground)
 END_EVENT_TABLE()
 
 // ----------------------------------------------------------------------------
@@ -1226,6 +1227,40 @@ void wxToolBar::OnMouseEvent(wxMouseEvent& event)
     }
 }
 
+// This handler is required to allow the toolbar to be set to a non-default
+// colour: for example, when it must blend in with a notebook page.
+void wxToolBar::OnEraseBackground(wxEraseEvent& event)
+{
+    wxColour bgCol = GetBackgroundColour();
+    if (!bgCol.Ok())
+    {
+        event.Skip();
+        return;
+    }
+    
+    // notice that this 'dumb' implementation may cause flicker for some of the
+    // controls in which case they should intercept wxEraseEvent and process it
+    // themselves somehow
+
+    RECT rect;
+    ::GetClientRect(GetHwnd(), &rect);
+
+    HBRUSH hBrush = ::CreateSolidBrush(wxColourToRGB(bgCol));
+
+    HDC hdc = GetHdcOf((*event.GetDC()));
+
+#ifndef __WXWINCE__
+    int mode = ::SetMapMode(hdc, MM_TEXT);
+#endif
+
+    ::FillRect(hdc, &rect, hBrush);
+    ::DeleteObject(hBrush);
+
+#ifndef __WXWINCE__
+    ::SetMapMode(hdc, mode);
+#endif
+}
+
 bool wxToolBar::HandleSize(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam)
 {
     // calculate our minor dimension ourselves - we're confusing the standard