Backported toolbar rendering fix for Vista

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@46237 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2007-05-29 13:32:30 +00:00
parent d129f01808
commit 4bf6833edf

View File

@@ -1412,6 +1412,9 @@ void wxToolBar::OnEraseBackground(wxEraseEvent& event)
RECT rect = wxGetClientRect(GetHwnd());
HDC hdc = GetHdcOf((*event.GetDC()));
int majorVersion, minorVersion;
wxGetOsVersion(& majorVersion, & minorVersion);
#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
@@ -1432,6 +1435,30 @@ void wxToolBar::OnEraseBackground(wxEraseEvent& event)
wxLogApiError(_T("DrawThemeParentBackground(toolbar)"), hr);
}
}
// Only draw a rebar theme on Vista, since it doesn't jive so well with XP
if ( !UseBgCol() && majorVersion >= 6 )
{
wxUxThemeEngine *theme = wxUxThemeEngine::GetIfActive();
if ( theme )
{
wxUxThemeHandle hTheme(this, L"REBAR");
RECT r;
wxRect rect = GetClientRect();
wxCopyRectToRECT(rect, r);
HRESULT hr = theme->DrawThemeBackground(hTheme, hdc, 0, 0, & r, NULL);
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("DrawThemeBackground(toolbar)"), hr);
}
}
#endif // wxUSE_UXTHEME
if ( UseBgCol() || (GetMSWToolbarStyle() & TBSTYLE_TRANSPARENT) )
@@ -1516,6 +1543,11 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam)
// no controls, nothing to erase
return false;
wxSize clientSize = GetClientSize();
int majorVersion, minorVersion;
wxGetOsVersion(& majorVersion, & minorVersion);
// prepare the DC on which we'll be drawing
// prepare the DC on which we'll be drawing
wxClientDC dc(this);
dc.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID));
@@ -1582,7 +1614,39 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam)
if ( rectCtrl.Intersects(rectItem) )
{
// yes, do erase it!
dc.DrawRectangle(rectItem);
bool haveRefreshed = false;
#if wxUSE_UXTHEME
if ( !UseBgCol() && !GetParent()->UseBgCol() )
{
// Don't use DrawThemeBackground
}
else if (!UseBgCol() && majorVersion >= 6 )
{
wxUxThemeEngine *theme = wxUxThemeEngine::GetIfActive();
if ( theme )
{
wxUxThemeHandle hTheme(this, L"REBAR");
RECT clipRect = r;
// Draw the whole background since the pattern may be position sensitive;
// but clip it to the area of interest.
r.left = 0;
r.right = clientSize.x;
r.top = 0;
r.bottom = clientSize.y;
HRESULT hr = theme->DrawThemeBackground(hTheme, (HDC) dc.GetHDC(), 0, 0, & r, & clipRect);
if ( hr == S_OK )
haveRefreshed = true;
}
}
#endif
if (!haveRefreshed)
dc.DrawRectangle(rectItem);
// Necessary in case we use a no-paint-on-size
// style in the parent: the controls can disappear