]> git.saurik.com Git - wxWidgets.git/blob - samples/erase/erase.cpp
do *NOT* make the window of the size of its parent initially, fixes missing EVT_SIZE...
[wxWidgets.git] / samples / erase / erase.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: erase.cpp
3 // Purpose: Erase wxWindows sample
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "erase.cpp"
22 #pragma interface "erase.cpp"
23 #endif
24
25 // For compilers that support precompilation, includes "wx/wx.h".
26 #include "wx/wxprec.h"
27
28 #ifdef __BORLANDC__
29 #pragma hdrstop
30 #endif
31
32 // for all others, include the necessary headers (this file is usually all you
33 // need because it includes almost all "standard" wxWindows headers)
34 #ifndef WX_PRECOMP
35 #include "wx/wx.h"
36 #endif
37
38 // ----------------------------------------------------------------------------
39 // resources
40 // ----------------------------------------------------------------------------
41 // the application icon
42 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__)
43 #include "mondrian.xpm"
44 #endif
45
46 // ----------------------------------------------------------------------------
47 // private classes
48 // ----------------------------------------------------------------------------
49
50 class MyApp : public wxApp
51 {
52 public:
53 virtual bool OnInit();
54 };
55
56
57 class MyFrame : public wxFrame
58 {
59 public:
60 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
61
62 void OnQuit(wxCommandEvent& event);
63 void OnAbout(wxCommandEvent& event);
64
65 private:
66 DECLARE_EVENT_TABLE()
67 };
68
69
70 class MyCanvas : public wxScrolledWindow
71 {
72 public:
73 MyCanvas( MyFrame *parent );
74
75 void OnPaint( wxPaintEvent &event );
76 void OnEraseBackground( wxEraseEvent &event );
77
78 private:
79 DECLARE_EVENT_TABLE()
80 };
81
82 // ----------------------------------------------------------------------------
83 // constants
84 // ----------------------------------------------------------------------------
85
86 enum
87 {
88 // menu items
89 Minimal_Quit = 1,
90 Minimal_About
91 };
92
93
94 // ----------------------------------------------------------------------------
95 // the application class
96 // ----------------------------------------------------------------------------
97
98 IMPLEMENT_APP(MyApp)
99
100 bool MyApp::OnInit()
101 {
102 MyFrame *frame = new MyFrame("Minimal wxWindows App",
103 wxPoint(50, 50), wxSize(450, 340));
104
105 frame->Show(TRUE);
106
107 return TRUE;
108 }
109
110 // ----------------------------------------------------------------------------
111 // main frame
112 // ----------------------------------------------------------------------------
113
114 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
115 EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
116 EVT_MENU(Minimal_About, MyFrame::OnAbout)
117 END_EVENT_TABLE()
118
119 // frame constructor
120 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
121 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
122 {
123 #ifdef __WXMAC__
124 wxApp::s_macAboutMenuItemId = Minimal_About;
125 #endif
126
127 SetIcon(wxICON(mondrian));
128
129 wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF);
130
131 wxMenu *helpMenu = new wxMenu;
132 helpMenu->Append(Minimal_About, "&About...\tCtrl-A", "Show about dialog");
133
134 menuFile->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program");
135
136 wxMenuBar *menuBar = new wxMenuBar();
137 menuBar->Append(menuFile, "&File");
138 menuBar->Append(helpMenu, "&Help");
139
140 SetMenuBar(menuBar);
141
142 #if wxUSE_STATUSBAR
143 // create a status bar just for fun (by default with 1 pane only)
144 CreateStatusBar(2);
145 SetStatusText("Welcome to wxWindows!");
146 #endif // wxUSE_STATUSBAR
147
148 (void)new MyCanvas( this );
149 }
150
151
152 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
153 {
154 Close(TRUE);
155 }
156
157 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
158 {
159 wxString msg;
160 msg.Printf( _T("This is the about dialog of the Erase sample.\n")
161 _T("Welcome to %s"), wxVERSION_STRING);
162
163 wxMessageBox(msg, "About Erase", wxOK | wxICON_INFORMATION, this);
164 }
165
166
167 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
168 EVT_PAINT( MyCanvas::OnPaint)
169 EVT_ERASE_BACKGROUND( MyCanvas::OnEraseBackground)
170 END_EVENT_TABLE()
171
172 MyCanvas::MyCanvas( MyFrame *parent )
173 : wxScrolledWindow( parent, -1, wxDefaultPosition, wxDefaultSize,
174 wxScrolledWindowStyle|wxNO_FULL_REPAINT_ON_RESIZE )
175 {
176 SetScrollbars( 10, 10, 40, 100, 0, 0 );
177 }
178
179 void MyCanvas::OnPaint( wxPaintEvent &event )
180 {
181 wxPaintDC dc(this);
182 PrepareDC( dc );
183
184 dc.SetBrush( *wxRED_BRUSH );
185 dc.DrawRectangle( 100, 100, 300, 500 );
186 }
187
188 void MyCanvas::OnEraseBackground( wxEraseEvent &event )
189 {
190 event.Skip( TRUE );
191 }
192