implemented MSWGetBgBrush/ColourForChild() to propagate themed notebook background to children
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30977 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
c5bd3c6268
commit
c4a95f6f99
@ -162,17 +162,18 @@ public:
|
|||||||
// -------------------
|
// -------------------
|
||||||
|
|
||||||
#if wxUSE_UXTHEME
|
#if wxUSE_UXTHEME
|
||||||
// handler for child pages erase background event
|
virtual bool SetBackgroundColour(const wxColour& colour)
|
||||||
void DoEraseBackground(wxEraseEvent& event);
|
{
|
||||||
|
if ( !wxNotebookBase::SetBackgroundColour(colour) )
|
||||||
|
return false;
|
||||||
|
|
||||||
// real implementation of the above method
|
UpdateBgBrush();
|
||||||
void DoEraseBackground(wxWindow *win, WXHDC hDC);
|
|
||||||
|
|
||||||
// get the brush to be used for painting the background for the controls
|
return true;
|
||||||
// which need it in their MSWControlColor()
|
}
|
||||||
//
|
|
||||||
// the brush will be adjusted for use with the given window on this DC
|
virtual WXHBRUSH MSWGetBgBrushForChild(WXHDC hDC, wxWindow *win);
|
||||||
WXHBRUSH GetThemeBackgroundBrush(WXHDC hDC, wxWindow *win) const;
|
virtual wxColour MSWGetBgColourForChild(wxWindow *win);
|
||||||
#endif // wxUSE_UXTHEME
|
#endif // wxUSE_UXTHEME
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -189,6 +190,14 @@ protected:
|
|||||||
void AdjustPageSize(wxNotebookPage *page);
|
void AdjustPageSize(wxNotebookPage *page);
|
||||||
|
|
||||||
#if wxUSE_UXTHEME
|
#if wxUSE_UXTHEME
|
||||||
|
// this is a slightly ugly function which gets the bitmap of notebook
|
||||||
|
// background and either returns the colour under the specified window in it
|
||||||
|
// or creates a brush from it
|
||||||
|
//
|
||||||
|
// so if win == NULL, a brush is created and returned
|
||||||
|
// win != NULL, returns COLORREF of the pixel under its top left corner
|
||||||
|
WXHANDLE QueryBgBitmap(wxWindow *win = NULL);
|
||||||
|
|
||||||
// creates the brush to be used for drawing the tab control background
|
// creates the brush to be used for drawing the tab control background
|
||||||
void UpdateBgBrush();
|
void UpdateBgBrush();
|
||||||
#endif // wxUSE_UXTHEME
|
#endif // wxUSE_UXTHEME
|
||||||
|
@ -862,26 +862,44 @@ void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
|
|||||||
|
|
||||||
#if wxUSE_UXTHEME
|
#if wxUSE_UXTHEME
|
||||||
|
|
||||||
|
WXHANDLE wxNotebook::QueryBgBitmap(wxWindow *win)
|
||||||
|
{
|
||||||
|
RECT rc;
|
||||||
|
GetWindowRect(GetHwnd(), &rc);
|
||||||
|
|
||||||
|
WindowHDC hDC(GetHwnd());
|
||||||
|
MemoryHDC hDCMem(hDC);
|
||||||
|
CompatibleBitmap hBmp(hDC, rc.right - rc.left, rc.bottom - rc.top);
|
||||||
|
|
||||||
|
SelectInHDC selectBmp(hDCMem, hBmp);
|
||||||
|
|
||||||
|
::SendMessage(GetHwnd(), WM_PRINTCLIENT,
|
||||||
|
(WPARAM)(HDC)hDCMem,
|
||||||
|
PRF_ERASEBKGND | PRF_CLIENT | PRF_NONCLIENT);
|
||||||
|
|
||||||
|
if ( win )
|
||||||
|
{
|
||||||
|
RECT rc2;
|
||||||
|
::GetWindowRect(GetHwndOf(win), &rc2);
|
||||||
|
|
||||||
|
COLORREF c = ::GetPixel(hDCMem, rc2.left - rc.left, rc2.top - rc.top);
|
||||||
|
|
||||||
|
return (WXHANDLE)c;
|
||||||
|
}
|
||||||
|
else // we are asked to create the brush
|
||||||
|
{
|
||||||
|
return (WXHANDLE)::CreatePatternBrush(hBmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void wxNotebook::UpdateBgBrush()
|
void wxNotebook::UpdateBgBrush()
|
||||||
{
|
{
|
||||||
if ( m_hbrBackground )
|
if ( m_hbrBackground )
|
||||||
::DeleteObject((HBRUSH)m_hbrBackground);
|
::DeleteObject((HBRUSH)m_hbrBackground);
|
||||||
|
|
||||||
if ( wxUxThemeEngine::GetIfActive() )
|
if ( !m_hasBgCol && wxUxThemeEngine::GetIfActive() )
|
||||||
{
|
{
|
||||||
RECT rc;
|
m_hbrBackground = (WXHBRUSH)QueryBgBitmap();
|
||||||
GetWindowRect(GetHwnd(), &rc);
|
|
||||||
|
|
||||||
WindowHDC hDC(GetHwnd());
|
|
||||||
MemoryHDC hDCMem(hDC);
|
|
||||||
CompatibleBitmap hBmp(hDC, rc.right - rc.left, rc.bottom - rc.top);
|
|
||||||
|
|
||||||
SelectInHDC selectBmp(hDCMem, hBmp);
|
|
||||||
|
|
||||||
SendMessage(GetHwnd(), WM_PRINTCLIENT, (WPARAM)(HDC)hDCMem,
|
|
||||||
PRF_ERASEBKGND | PRF_CLIENT | PRF_NONCLIENT);
|
|
||||||
|
|
||||||
m_hbrBackground = (WXHBRUSH)::CreatePatternBrush(hBmp);
|
|
||||||
}
|
}
|
||||||
else // no themes
|
else // no themes
|
||||||
{
|
{
|
||||||
@ -889,7 +907,7 @@ void wxNotebook::UpdateBgBrush()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WXHBRUSH wxNotebook::GetThemeBackgroundBrush(WXHDC hDC, wxWindow *win) const
|
WXHBRUSH wxNotebook::MSWGetBgBrushForChild(WXHDC hDC, wxWindow *win)
|
||||||
{
|
{
|
||||||
if ( m_hbrBackground )
|
if ( m_hbrBackground )
|
||||||
{
|
{
|
||||||
@ -904,30 +922,24 @@ WXHBRUSH wxNotebook::GetThemeBackgroundBrush(WXHDC hDC, wxWindow *win) const
|
|||||||
{
|
{
|
||||||
wxLogLastError(_T("SetBrushOrgEx(notebook bg brush)"));
|
wxLogLastError(_T("SetBrushOrgEx(notebook bg brush)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return m_hbrBackground;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_hbrBackground;
|
return wxNotebookBase::MSWGetBgBrushForChild(hDC, win);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNotebook::DoEraseBackground(wxEraseEvent& event)
|
wxColour wxNotebook::MSWGetBgColourForChild(wxWindow *win)
|
||||||
{
|
{
|
||||||
DoEraseBackground((wxWindow *)event.GetEventObject(),
|
if ( m_hasBgCol )
|
||||||
(WXHDC)GetHdcOf(*event.GetDC()));
|
return GetBackgroundColour();
|
||||||
}
|
|
||||||
|
|
||||||
void wxNotebook::DoEraseBackground(wxWindow *win, WXHDC hDC)
|
if ( !wxUxThemeEngine::GetIfActive() )
|
||||||
{
|
return wxNullColour;
|
||||||
// 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
|
COLORREF c = (COLORREF)QueryBgBitmap(win);
|
||||||
// (note that we use the same code in wxControl::MSWControlColor(), so if
|
|
||||||
// it breaks, it should at least break in consistent way)
|
return c == CLR_INVALID ? wxNullColour : wxRGBToColour(c);
|
||||||
WXHBRUSH hbr = GetThemeBackgroundBrush(hDC, win);
|
|
||||||
if ( hbr )
|
|
||||||
{
|
|
||||||
RECT rectClient;
|
|
||||||
::GetClientRect(GetHwndOf(win), &rectClient);
|
|
||||||
::FillRect((HDC)hDC, &rectClient, (HBRUSH)hbr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_UXTHEME
|
#endif // wxUSE_UXTHEME
|
||||||
|
Loading…
Reference in New Issue
Block a user