1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Erase wxWindows sample
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "erase.cpp"
22 #pragma interface "erase.cpp"
25 // For compilers that support precompilation, includes "wx/wx.h".
26 #include "wx/wxprec.h"
32 // for all others, include the necessary headers (this file is usually all you
33 // need because it includes almost all "standard" wxWindows headers)
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
41 // the application icon
42 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
43 #include "mondrian.xpm"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 class MyApp
: public wxApp
53 virtual bool OnInit();
57 class MyFrame
: public wxFrame
60 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
62 void OnQuit(wxCommandEvent
& event
);
63 void OnAbout(wxCommandEvent
& event
);
70 class MyCanvas
: public wxScrolledWindow
73 MyCanvas( MyFrame
*parent
);
75 void OnPaint( wxPaintEvent
&event
);
76 void OnEraseBackground( wxEraseEvent
&event
);
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
95 // the application class
96 // ----------------------------------------------------------------------------
102 MyFrame
*frame
= new MyFrame("Minimal wxWindows App",
103 wxPoint(50, 50), wxSize(450, 340));
110 // ----------------------------------------------------------------------------
112 // ----------------------------------------------------------------------------
114 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
115 EVT_MENU(Minimal_Quit
, MyFrame::OnQuit
)
116 EVT_MENU(Minimal_About
, MyFrame::OnAbout
)
120 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
121 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
124 wxApp::s_macAboutMenuItemId
= Minimal_About
;
127 SetIcon(wxICON(mondrian
));
129 wxMenu
*menuFile
= new wxMenu("", wxMENU_TEAROFF
);
131 wxMenu
*helpMenu
= new wxMenu
;
132 helpMenu
->Append(Minimal_About
, "&About...\tCtrl-A", "Show about dialog");
134 menuFile
->Append(Minimal_Quit
, "E&xit\tAlt-X", "Quit this program");
136 wxMenuBar
*menuBar
= new wxMenuBar();
137 menuBar
->Append(menuFile
, "&File");
138 menuBar
->Append(helpMenu
, "&Help");
143 // create a status bar just for fun (by default with 1 pane only)
145 SetStatusText("Welcome to wxWindows!");
146 #endif // wxUSE_STATUSBAR
148 (void)new MyCanvas( this );
152 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
157 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
160 msg
.Printf( _T("This is the about dialog of the Erase sample.\n")
161 _T("Welcome to %s"), wxVERSION_STRING
);
163 wxMessageBox(msg
, "About Erase", wxOK
| wxICON_INFORMATION
, this);
167 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
168 EVT_PAINT( MyCanvas::OnPaint
)
169 EVT_ERASE_BACKGROUND( MyCanvas::OnEraseBackground
)
172 MyCanvas::MyCanvas( MyFrame
*parent
)
173 : wxScrolledWindow( parent
, -1, wxDefaultPosition
, wxDefaultSize
,
174 wxScrolledWindowStyle
|wxNO_FULL_REPAINT_ON_RESIZE
)
176 SetScrollbars( 10, 10, 40, 100, 0, 0 );
179 void MyCanvas::OnPaint( wxPaintEvent
&event
)
184 wxRegion
region( 110, 110, 80, 80 );
185 wxRegion
hole( 130, 130, 40, 1 );
186 region
.Intersect( hole
);
187 dc
.SetClippingRegion( region
);
189 dc
.SetBrush( *wxRED_BRUSH
);
190 dc
.DrawRectangle( 100, 100, 200, 200 );
193 void MyCanvas::OnEraseBackground( wxEraseEvent
&event
)