Generate erase background events for native controls too under MSW.

Remove the test which prevented the generation of erase background events from
wxMSW::wxWindow::HandleEraseBkgnd(). Although it is true that native controls
mostly erase background on their own, there are exceptions: we must erase the
background of wxToolBar ourselves, for example. More importantly, there is no
reason to prevent the user code from defining wxEVT_ERASE_BACKGROUND handlers
for the native controls as this works just fine under MSW (although it doesn't
under GTK nor probably other ports...). So also add a test erase background
handler to the toolbar sample to verify that this does work.

Closes #11514.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62805 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-12-07 13:37:01 +00:00
parent d2356abe70
commit 0639363014
2 changed files with 55 additions and 7 deletions

View File

@@ -134,6 +134,7 @@ public:
void OnToolbarStyle(wxCommandEvent& event); void OnToolbarStyle(wxCommandEvent& event);
void OnToolbarBgCol(wxCommandEvent& event); void OnToolbarBgCol(wxCommandEvent& event);
void OnToolbarCustomBg(wxCommandEvent& event);
void OnToolbarCustomBitmap(wxCommandEvent& event); void OnToolbarCustomBitmap(wxCommandEvent& event);
void OnToolLeftClick(wxCommandEvent& event); void OnToolLeftClick(wxCommandEvent& event);
@@ -148,6 +149,8 @@ public:
{ event.Enable( m_tbar != NULL ); } { event.Enable( m_tbar != NULL ); }
private: private:
void OnEraseToolBarBackground(wxEraseEvent& event);
void DoEnablePrint(); void DoEnablePrint();
void DoDeletePrint(); void DoDeletePrint();
void DoToggleHelp(); void DoToggleHelp();
@@ -206,6 +209,7 @@ enum
IDM_TOOLBAR_SHOW_ICONS, IDM_TOOLBAR_SHOW_ICONS,
IDM_TOOLBAR_SHOW_BOTH, IDM_TOOLBAR_SHOW_BOTH,
IDM_TOOLBAR_BG_COL, IDM_TOOLBAR_BG_COL,
IDM_TOOLBAR_CUSTOM_BG,
IDM_TOOLBAR_CUSTOM_PATH, IDM_TOOLBAR_CUSTOM_PATH,
IDM_TOOLBAR_TOP_ORIENTATION, IDM_TOOLBAR_TOP_ORIENTATION,
IDM_TOOLBAR_LEFT_ORIENTATION, IDM_TOOLBAR_LEFT_ORIENTATION,
@@ -264,6 +268,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT, IDM_TOOLBAR_SHOW_BOTH, EVT_MENU_RANGE(IDM_TOOLBAR_SHOW_TEXT, IDM_TOOLBAR_SHOW_BOTH,
MyFrame::OnToolbarStyle) MyFrame::OnToolbarStyle)
EVT_MENU(IDM_TOOLBAR_BG_COL, MyFrame::OnToolbarBgCol) EVT_MENU(IDM_TOOLBAR_BG_COL, MyFrame::OnToolbarBgCol)
EVT_MENU(IDM_TOOLBAR_CUSTOM_BG, MyFrame::OnToolbarCustomBg)
EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH, MyFrame::OnToolbarCustomBitmap) EVT_MENU(IDM_TOOLBAR_CUSTOM_PATH, MyFrame::OnToolbarCustomBitmap)
@@ -371,6 +376,17 @@ void MyFrame::RecreateToolbar()
toolBar = CreateToolBar(style, ID_TOOLBAR); toolBar = CreateToolBar(style, ID_TOOLBAR);
#endif #endif
if ( GetMenuBar()->IsChecked(IDM_TOOLBAR_CUSTOM_BG) )
{
toolBar->Connect
(
wxEVT_ERASE_BACKGROUND,
wxEraseEventHandler(MyFrame::OnEraseToolBarBackground),
NULL,
this
);
}
PopulateToolbar(toolBar); PopulateToolbar(toolBar);
} }
@@ -591,6 +607,7 @@ MyFrame::MyFrame(wxFrame* parent,
tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH, wxT("Show &both\tCtrl-Alt-B")); tbarMenu->AppendRadioItem(IDM_TOOLBAR_SHOW_BOTH, wxT("Show &both\tCtrl-Alt-B"));
tbarMenu->AppendSeparator(); tbarMenu->AppendSeparator();
tbarMenu->Append(IDM_TOOLBAR_BG_COL, wxT("Choose bac&kground colour...")); tbarMenu->Append(IDM_TOOLBAR_BG_COL, wxT("Choose bac&kground colour..."));
tbarMenu->AppendCheckItem(IDM_TOOLBAR_CUSTOM_BG, wxT("Draw custom back&ground"));
tbarMenu->Append(IDM_TOOLBAR_CUSTOM_PATH, wxT("Custom &bitmap...\tCtrl-B")); tbarMenu->Append(IDM_TOOLBAR_CUSTOM_PATH, wxT("Custom &bitmap...\tCtrl-B"));
wxMenu *toolMenu = new wxMenu; wxMenu *toolMenu = new wxMenu;
@@ -690,6 +707,15 @@ void MyFrame::OnSize(wxSizeEvent& event)
} }
} }
void MyFrame::OnEraseToolBarBackground(wxEraseEvent& event)
{
wxDC& dc = *event.GetDC();
const wxSize size = dc.GetSize();
dc.SetPen(*wxRED_PEN);
dc.DrawLine(0, 0, size.x, size.y);
dc.DrawLine(0, size.y, size.x, 0);
}
void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnToggleToolbar(wxCommandEvent& WXUNUSED(event))
{ {
wxToolBar *tbar = GetToolBar(); wxToolBar *tbar = GetToolBar();
@@ -956,6 +982,34 @@ void MyFrame::OnToolbarBgCol(wxCommandEvent& WXUNUSED(event))
} }
} }
void MyFrame::OnToolbarCustomBg(wxCommandEvent& event)
{
wxToolBarBase *tb = GetToolBar();
if ( event.IsChecked() )
{
tb->Connect
(
wxEVT_ERASE_BACKGROUND,
wxEraseEventHandler(MyFrame::OnEraseToolBarBackground),
NULL,
this
);
}
else
{
tb->Disconnect
(
wxEVT_ERASE_BACKGROUND,
wxEraseEventHandler(MyFrame::OnEraseToolBarBackground),
NULL,
this
);
}
tb->Refresh();
}
void MyFrame::OnToolbarCustomBitmap(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnToolbarCustomBitmap(wxCommandEvent& WXUNUSED(event))
{ {
m_pathBmp = wxLoadFileSelector("custom bitmap", ""); m_pathBmp = wxLoadFileSelector("custom bitmap", "");

View File

@@ -4754,12 +4754,6 @@ void wxWindowMSW::OnPaint(wxPaintEvent& event)
bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc) bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc)
{ {
// standard non top level controls (i.e. except the dialogs) always erase
// their background themselves in HandleCtlColor() or have some control-
// specific ways to set the colours (common controls)
if ( IsOfStandardClass() && !IsTopLevel() )
return false;
switch ( GetBackgroundStyle() ) switch ( GetBackgroundStyle() )
{ {
case wxBG_STYLE_ERASE: case wxBG_STYLE_ERASE:
@@ -4782,7 +4776,7 @@ bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc)
if ( rc ) if ( rc )
{ {
// background erase by the user-defined handler // background erased by the user-defined handler
return true; return true;
} }
} }