Simplify and correct MSW selection of background brush for children painting.

Check for the transparency of the window background in MSWGetBgBrush() itself
and let MSWGetBgBrushForChild() just return the brush to be used.

This required adding a MSW-specific hack to wxPanel to allow inheriting
background of wxNotebook by its children which is slightly ugly but is exactly
what we need to do in this case and makes the rest of the code much simpler.

Also add a possibility to set the background of the page containing the
control being tested to the widgets sample to test for background inheritance.
This shows problems with wxSlider and wxRadioBox backgrounds but they're not
new with this patch.

Closes #12057.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64372 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-05-21 12:51:20 +00:00
parent d3eb13d2aa
commit ebfee17940
8 changed files with 86 additions and 56 deletions

View File

@@ -75,6 +75,7 @@ enum
#endif // wxUSE_TOOLTIPS
Widgets_SetFgColour,
Widgets_SetBgColour,
Widgets_SetPageBg,
Widgets_SetFont,
Widgets_Enable,
@@ -159,6 +160,7 @@ protected:
#endif // wxUSE_TOOLTIPS
void OnSetFgCol(wxCommandEvent& event);
void OnSetBgCol(wxCommandEvent& event);
void OnSetPageBg(wxCommandEvent& event);
void OnSetFont(wxCommandEvent& event);
void OnEnable(wxCommandEvent& event);
void OnSetBorder(wxCommandEvent& event);
@@ -285,6 +287,7 @@ BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame)
EVT_MENU(Widgets_SetFgColour, WidgetsFrame::OnSetFgCol)
EVT_MENU(Widgets_SetBgColour, WidgetsFrame::OnSetBgCol)
EVT_MENU(Widgets_SetPageBg, WidgetsFrame::OnSetPageBg)
EVT_MENU(Widgets_SetFont, WidgetsFrame::OnSetFont)
EVT_MENU(Widgets_Enable, WidgetsFrame::OnEnable)
@@ -381,6 +384,7 @@ WidgetsFrame::WidgetsFrame(const wxString& title)
#endif // wxUSE_TOOLTIPS
menuWidget->Append(Widgets_SetFgColour, wxT("Set &foreground...\tCtrl-F"));
menuWidget->Append(Widgets_SetBgColour, wxT("Set &background...\tCtrl-B"));
menuWidget->Append(Widgets_SetPageBg, wxT("Set &page background...\tShift-Ctrl-B"));
menuWidget->Append(Widgets_SetFont, wxT("Set f&ont...\tCtrl-O"));
menuWidget->AppendCheckItem(Widgets_Enable, wxT("&Enable/disable\tCtrl-E"));
@@ -766,16 +770,35 @@ void WidgetsFrame::OnSetTooltip(wxCommandEvent& WXUNUSED(event))
#endif // wxUSE_TOOLTIPS
void WidgetsFrame::OnSetFgCol(wxCommandEvent& WXUNUSED(event))
namespace
{
// Trivial wrapper for wxGetColourFromUser() which also does something even if
// the colour dialog is not available in the current build (which may happen
// for the ports in development and it is still useful to see how colours work)
wxColour GetColourFromUser(wxWindow *parent, const wxColour& colDefault)
{
#if wxUSE_COLOURDLG
return wxGetColourFromUser(parent, colDefault);
#else // !wxUSE_COLOURDLG
if ( colDefault == *wxBLACK )
return *wxWHITE;
else
return *wxBLACK;
#endif // wxUSE_COLOURDLG/!wxUSE_COLOURDLG
}
} // anonymous namespace
void WidgetsFrame::OnSetFgCol(wxCommandEvent& WXUNUSED(event))
{
// allow for debugging the default colour the first time this is called
WidgetsPage *page = CurrentPage();
if (!m_colFg.Ok())
m_colFg = page->GetForegroundColour();
wxColour col = wxGetColourFromUser(this, m_colFg);
wxColour col = GetColourFromUser(this, m_colFg);
if ( !col.Ok() )
return;
@@ -789,20 +812,16 @@ void WidgetsFrame::OnSetFgCol(wxCommandEvent& WXUNUSED(event))
(*it)->SetForegroundColour(m_colFg);
(*it)->Refresh();
}
#else
wxLogMessage(wxT("Colour selection dialog not available in current build."));
#endif
}
void WidgetsFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event))
{
#if wxUSE_COLOURDLG
WidgetsPage *page = CurrentPage();
if ( !m_colBg.Ok() )
m_colBg = page->GetBackgroundColour();
wxColour col = wxGetColourFromUser(this, m_colBg);
wxColour col = GetColourFromUser(this, m_colBg);
if ( !col.Ok() )
return;
@@ -816,9 +835,16 @@ void WidgetsFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event))
(*it)->SetBackgroundColour(m_colBg);
(*it)->Refresh();
}
#else
wxLogMessage(wxT("Colour selection dialog not available in current build."));
#endif
}
void WidgetsFrame::OnSetPageBg(wxCommandEvent& WXUNUSED(event))
{
wxColour col = GetColourFromUser(this, GetBackgroundColour());
if ( !col.Ok() )
return;
CurrentPage()->SetBackgroundColour(col);
CurrentPage()->Refresh();
}
void WidgetsFrame::OnSetFont(wxCommandEvent& WXUNUSED(event))