refactored code to do brush adjustment for bg drawing in only one place
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30641 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -167,7 +167,9 @@ public:
|
|||||||
|
|
||||||
// get the brush to be used for painting the background for the controls
|
// get the brush to be used for painting the background for the controls
|
||||||
// which need it in their MSWControlColor()
|
// which need it in their MSWControlColor()
|
||||||
WXHBRUSH GetThemeBackgroundBrush() const { return m_hbrBackground; }
|
//
|
||||||
|
// the brush will be adjusted for use with the given window on this DC
|
||||||
|
WXHBRUSH GetThemeBackgroundBrush(WXHDC hDC, wxWindow *win) const;
|
||||||
#endif // wxUSE_UXTHEME
|
#endif // wxUSE_UXTHEME
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@@ -327,24 +327,32 @@ bool wxControl::MSWOnNotify(int idCtrl,
|
|||||||
}
|
}
|
||||||
#endif // Win95
|
#endif // Win95
|
||||||
|
|
||||||
WXHBRUSH wxControl::MSWControlColor(WXHDC pDC)
|
WXHBRUSH wxControl::MSWControlColorSolid(WXHDC pDC, wxColour colBg)
|
||||||
{
|
{
|
||||||
HDC hdc = (HDC)pDC;
|
HDC hdc = (HDC)pDC;
|
||||||
if ( m_hasFgCol )
|
if ( m_hasFgCol )
|
||||||
::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
|
::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
|
||||||
|
|
||||||
if ( m_hasBgCol )
|
if ( colBg.Ok() )
|
||||||
{
|
{
|
||||||
wxColour colBack = GetBackgroundColour();
|
::SetBkColor(hdc, wxColourToRGB(colBg));
|
||||||
|
|
||||||
::SetBkColor(hdc, wxColourToRGB(colBack));
|
wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBg, wxSOLID);
|
||||||
|
|
||||||
wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
|
|
||||||
|
|
||||||
return (WXHBRUSH)brush->GetResourceHandle();
|
return (WXHBRUSH)brush->GetResourceHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
SetBkMode(hdc, TRANSPARENT);
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
WXHBRUSH wxControl::MSWControlColor(WXHDC pDC)
|
||||||
|
{
|
||||||
|
WXHBRUSH hbr = MSWControlColorSolid(pDC, m_hasBgCol ? m_backgroundColour
|
||||||
|
: wxNullColour);
|
||||||
|
if ( hbr )
|
||||||
|
return hbr;
|
||||||
|
|
||||||
|
::SetBkMode((HDC)pDC, TRANSPARENT);
|
||||||
|
|
||||||
#if wxUSE_UXTHEME && wxUSE_NOTEBOOK
|
#if wxUSE_UXTHEME && wxUSE_NOTEBOOK
|
||||||
if ( wxUxThemeEngine::GetIfActive() )
|
if ( wxUxThemeEngine::GetIfActive() )
|
||||||
@@ -354,22 +362,25 @@ WXHBRUSH wxControl::MSWControlColor(WXHDC pDC)
|
|||||||
wxNotebook *nbook = wxDynamicCast(win, wxNotebook);
|
wxNotebook *nbook = wxDynamicCast(win, wxNotebook);
|
||||||
if ( nbook )
|
if ( nbook )
|
||||||
{
|
{
|
||||||
WXHBRUSH hbr = nbook->GetThemeBackgroundBrush();
|
// return value may be NULL but it is ok: if the first parent
|
||||||
if ( hbr )
|
// notebook doesn't use themes, then we don't have to process
|
||||||
{
|
// this message at all, so let default processing take place
|
||||||
RECT rc;
|
return nbook->GetThemeBackgroundBrush(pDC, this);
|
||||||
GetWindowRect(GetHwnd(), &rc);
|
|
||||||
|
|
||||||
MapWindowPoints(NULL, GetHwndOf(nbook), (POINT *)&rc, 1);
|
|
||||||
SetBrushOrgEx(hdc, -rc.left, -rc.top, NULL);
|
|
||||||
return hbr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // wxUSE_UXTHEME
|
#endif // wxUSE_UXTHEME
|
||||||
|
|
||||||
return GetStockObject(NULL_BRUSH);
|
return ::GetStockObject(NULL_BRUSH);
|
||||||
|
}
|
||||||
|
|
||||||
|
WXHBRUSH wxControl::MSWControlColorDisabled(WXHDC pDC)
|
||||||
|
{
|
||||||
|
return MSWControlColorSolid
|
||||||
|
(
|
||||||
|
pDC,
|
||||||
|
wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
@@ -888,32 +888,40 @@ void wxNotebook::UpdateBgBrush()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WXHBRUSH wxNotebook::GetThemeBackgroundBrush(WXHDC hDC, wxWindow *win) const
|
||||||
|
{
|
||||||
|
if ( m_hbrBackground )
|
||||||
|
{
|
||||||
|
// before drawing with the background brush, we need to position it
|
||||||
|
// correctly
|
||||||
|
RECT rc;
|
||||||
|
::GetWindowRect(GetHwndOf(win), &rc);
|
||||||
|
|
||||||
|
::MapWindowPoints(NULL, GetHwnd(), (POINT *)&rc, 1);
|
||||||
|
|
||||||
|
if ( !::SetBrushOrgEx((HDC)hDC, -rc.left, -rc.top, NULL) )
|
||||||
|
{
|
||||||
|
wxLogLastError(_T("SetBrushOrgEx(notebook bg brush)"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_hbrBackground;
|
||||||
|
}
|
||||||
|
|
||||||
void wxNotebook::DoEraseBackground(wxEraseEvent& event)
|
void wxNotebook::DoEraseBackground(wxEraseEvent& event)
|
||||||
{
|
{
|
||||||
// we can either draw the background ourselves or let DrawThemeBackground()
|
// we can either draw the background ourselves or let DrawThemeBackground()
|
||||||
// do it, but as we already have the correct brush, let's do it ourselves
|
// do it, but as we already have the correct brush, let's do it ourselves
|
||||||
// (note that we use the same code in wxControl::MSWControlColor(), so if
|
// (note that we use the same code in wxControl::MSWControlColor(), so if
|
||||||
// it breaks, it should at least break in consistent way)
|
// it breaks, it should at least break in consistent way)
|
||||||
if ( m_hbrBackground )
|
|
||||||
{
|
|
||||||
// before drawing with the background brush, we need to position it
|
|
||||||
// correctly
|
|
||||||
wxWindow *win = (wxWindow *)event.GetEventObject();
|
wxWindow *win = (wxWindow *)event.GetEventObject();
|
||||||
|
|
||||||
RECT rc;
|
|
||||||
::GetWindowRect(GetHwndOf(win), &rc);
|
|
||||||
|
|
||||||
::MapWindowPoints(NULL, GetHwnd(), (POINT *)&rc, 1);
|
|
||||||
|
|
||||||
HDC hdc = GetHdcOf(*event.GetDC());
|
HDC hdc = GetHdcOf(*event.GetDC());
|
||||||
if ( !::SetBrushOrgEx(hdc, -rc.left, -rc.top, NULL) )
|
WXHBRUSH hbr = GetThemeBackgroundBrush((WXHDC)hdc, win);
|
||||||
|
if ( hbr )
|
||||||
{
|
{
|
||||||
wxLogLastError(_T("SetBrushOrgEx(notebook bg brush)"));
|
|
||||||
}
|
|
||||||
|
|
||||||
RECT rectClient;
|
RECT rectClient;
|
||||||
::GetClientRect(GetHwndOf(win), &rectClient);
|
::GetClientRect(GetHwndOf(win), &rectClient);
|
||||||
::FillRect(hdc, &rectClient, (HBRUSH)m_hbrBackground);
|
::FillRect(hdc, &rectClient, (HBRUSH)hbr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user