Restored the ability to set the background colour for a toolbar on Windows

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31806 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2005-02-06 18:42:43 +00:00
parent 9a75ba66de
commit 0090a1538c
2 changed files with 36 additions and 0 deletions

View File

@ -67,6 +67,7 @@ public:
void OnMouseEvent(wxMouseEvent& event);
void OnSysColourChanged(wxSysColourChangedEvent& event);
void OnEraseBackground(wxEraseEvent& event);
void SetFocus() {}

View 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