]>
Commit | Line | Data |
---|---|---|
cdf3a589 CE |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: svgtest.cpp | |
3 | // Purpose: SVG sample | |
4 | // Author: Chris Elliott | |
5 | // Modified by: | |
6 | // RCS-ID: $Id$ | |
7 | // Licence: wxWindows license | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // =========================================================================== | |
11 | // declarations | |
12 | // =========================================================================== | |
13 | ||
14 | // --------------------------------------------------------------------------- | |
15 | // headers | |
16 | // --------------------------------------------------------------------------- | |
17 | ||
18 | // For compilers that support precompilation, includes "wx/wx.h". | |
19 | #include "wx/wxprec.h" | |
20 | ||
21 | #ifdef __BORLANDC__ | |
22 | #pragma hdrstop | |
23 | #endif | |
24 | ||
25 | #ifndef WX_PRECOMP | |
26 | #include "wx/wx.h" | |
27 | #include "wx/mdi.h" | |
28 | #endif | |
29 | ||
ae0fbcee | 30 | #include "wx/toolbar.h" |
18cea871 | 31 | #include "wx/dcsvg.h" |
49e3b82c | 32 | #include "wx/vector.h" |
cdf3a589 CE |
33 | |
34 | #include "bitmaps/new.xpm" | |
35 | #include "bitmaps/save.xpm" | |
36 | #include "bitmaps/help.xpm" | |
37 | #include "SVGlogo24.xpm" | |
a5e6cfa8 | 38 | |
3cb332c1 VZ |
39 | #if !defined(__WXMSW__) && !defined(__WXPM__) |
40 | #include "../sample.xpm" | |
41 | #endif | |
42 | ||
cdf3a589 | 43 | class MyChild; |
49e3b82c FM |
44 | class MyCanvas; |
45 | ||
46 | // --------------------------------------------------------------------------- | |
47 | // classes | |
48 | // --------------------------------------------------------------------------- | |
cdf3a589 | 49 | |
cdf3a589 CE |
50 | class MyApp : public wxApp |
51 | { | |
49e3b82c FM |
52 | public: |
53 | bool OnInit(); | |
cdf3a589 CE |
54 | }; |
55 | ||
cdf3a589 CE |
56 | class MyFrame : public wxMDIParentFrame |
57 | { | |
49e3b82c FM |
58 | public: |
59 | MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, | |
cdf3a589 CE |
60 | const wxPoint& pos, const wxSize& size, const long style); |
61 | ||
49e3b82c FM |
62 | void InitToolBar(wxToolBar* toolBar); |
63 | ||
64 | void OnSize(wxSizeEvent& event); | |
65 | void OnAbout(wxCommandEvent& event); | |
66 | void OnNewWindow(wxCommandEvent& event); | |
67 | void OnQuit(wxCommandEvent& event); | |
68 | void FileSavePicture (wxCommandEvent& event); | |
69 | ||
70 | unsigned int GetCountOfChildren() const | |
71 | { return m_nWinCreated; } | |
72 | ||
73 | private: | |
74 | unsigned int m_nWinCreated; | |
75 | ||
76 | DECLARE_EVENT_TABLE() | |
cdf3a589 CE |
77 | }; |
78 | ||
49e3b82c | 79 | class MyChild: public wxMDIChildFrame |
cdf3a589 | 80 | { |
49e3b82c FM |
81 | public: |
82 | MyChild(wxMDIParentFrame *parent, const wxString& title, | |
83 | const wxPoint& pos = wxDefaultPosition, | |
84 | const wxSize& size = wxDefaultSize, | |
85 | const long style = wxDEFAULT_FRAME_STYLE); | |
86 | ~MyChild(); | |
87 | ||
88 | void OnActivate(wxActivateEvent& event); | |
89 | void OnQuit(wxCommandEvent& event); | |
90 | bool OnSave(wxString filename); | |
91 | ||
92 | MyFrame* GetFrame() | |
93 | { return m_frame; } | |
94 | ||
95 | private: | |
96 | MyCanvas *m_canvas; | |
97 | MyFrame *m_frame; | |
98 | ||
99 | DECLARE_EVENT_TABLE() | |
cdf3a589 CE |
100 | }; |
101 | ||
49e3b82c | 102 | class MyCanvas : public wxScrolledWindow |
cdf3a589 | 103 | { |
49e3b82c FM |
104 | public: |
105 | MyCanvas(MyChild *parent, const wxPoint& pos, const wxSize& size); | |
106 | virtual void OnDraw(wxDC& dc); | |
107 | ||
108 | private: | |
109 | int m_index; | |
110 | MyChild* m_child; | |
111 | ||
112 | DECLARE_EVENT_TABLE() | |
cdf3a589 CE |
113 | }; |
114 | ||
49e3b82c FM |
115 | // --------------------------------------------------------------------------- |
116 | // constants | |
117 | // --------------------------------------------------------------------------- | |
118 | ||
cdf3a589 CE |
119 | // menu items ids |
120 | enum | |
121 | { | |
122 | MDI_QUIT = 100, | |
123 | MDI_NEW_WINDOW, | |
124 | MDI_SAVE, | |
125 | MDI_REFRESH, | |
126 | MDI_CHILD_QUIT, | |
127 | MDI_ABOUT | |
128 | }; | |
129 | ||
cdf3a589 CE |
130 | // --------------------------------------------------------------------------- |
131 | // event tables | |
132 | // --------------------------------------------------------------------------- | |
133 | ||
134 | BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame) | |
49e3b82c FM |
135 | EVT_MENU(MDI_ABOUT, MyFrame::OnAbout) |
136 | EVT_MENU(MDI_NEW_WINDOW, MyFrame::OnNewWindow) | |
137 | EVT_MENU(MDI_QUIT, MyFrame::OnQuit) | |
138 | EVT_MENU (MDI_SAVE, MyFrame::FileSavePicture) | |
cdf3a589 | 139 | |
49e3b82c | 140 | EVT_SIZE(MyFrame::OnSize) |
cdf3a589 CE |
141 | END_EVENT_TABLE() |
142 | ||
143 | // =========================================================================== | |
144 | // implementation | |
145 | // =========================================================================== | |
146 | ||
147 | // --------------------------------------------------------------------------- | |
148 | // MyApp | |
149 | // --------------------------------------------------------------------------- | |
150 | ||
49e3b82c FM |
151 | IMPLEMENT_APP(MyApp) |
152 | ||
cdf3a589 CE |
153 | bool MyApp::OnInit() |
154 | { | |
155 | // Create the main frame window | |
156 | ||
49e3b82c FM |
157 | MyFrame* frame = new MyFrame((wxFrame *)NULL, -1, wxT("SVG Demo"), |
158 | wxDefaultPosition, wxSize(500, 400), | |
159 | wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL); | |
cdf3a589 | 160 | |
d96cdd4a | 161 | frame->Show(true); |
cdf3a589 CE |
162 | |
163 | SetTopWindow(frame); | |
164 | ||
c54e5eb0 | 165 | return true; |
cdf3a589 CE |
166 | } |
167 | ||
168 | ||
169 | // --------------------------------------------------------------------------- | |
170 | // MyFrame | |
171 | // --------------------------------------------------------------------------- | |
172 | ||
173 | // Define my frame constructor | |
174 | MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, | |
49e3b82c | 175 | const wxPoint& pos, const wxSize& size, const long style) |
cdf3a589 CE |
176 | : wxMDIParentFrame(parent, id, title, pos, size, style) |
177 | { | |
49e3b82c | 178 | m_nWinCreated = 0; |
cdf3a589 | 179 | |
3cb332c1 | 180 | SetIcon(wxICON(sample)); |
cdf3a589 | 181 | |
49e3b82c FM |
182 | // Make a menubar |
183 | wxMenu *file_menu = new wxMenu; | |
cdf3a589 | 184 | |
49e3b82c FM |
185 | file_menu->Append(MDI_NEW_WINDOW, wxT("&New test\tCtrl+N")); |
186 | file_menu->Append(MDI_QUIT, wxT("&Exit\tAlt+X")); | |
cdf3a589 | 187 | |
49e3b82c FM |
188 | wxMenu *help_menu = new wxMenu; |
189 | help_menu->Append(MDI_ABOUT, wxT("&About")); | |
cdf3a589 | 190 | |
49e3b82c | 191 | wxMenuBar *menu_bar = new wxMenuBar; |
cdf3a589 | 192 | |
49e3b82c FM |
193 | menu_bar->Append(file_menu, wxT("&File")); |
194 | menu_bar->Append(help_menu, wxT("&Help")); | |
195 | ||
196 | // Associate the menu bar with the frame | |
197 | SetMenuBar(menu_bar); | |
198 | ||
199 | #if wxUSE_STATUSBAR | |
200 | CreateStatusBar(); | |
201 | #endif // wxUSE_STATUSBAR | |
202 | ||
203 | CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL); | |
204 | InitToolBar(GetToolBar()); | |
205 | } | |
cdf3a589 CE |
206 | |
207 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
208 | { | |
209 | Close(); | |
210 | } | |
211 | ||
cdf3a589 CE |
212 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) ) |
213 | { | |
49e3b82c FM |
214 | (void)wxMessageBox(wxT("wxWidgets SVG sample\n") |
215 | wxT("Author: Chris Elliott (c) 2002-2009\n") | |
216 | wxT("Usage: click File|New to show tests"), | |
217 | wxT("About SVG Test")); | |
cdf3a589 CE |
218 | } |
219 | ||
cdf3a589 CE |
220 | void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) ) |
221 | { | |
222 | // Make another frame, containing a canvas | |
49e3b82c | 223 | MyChild *subframe = new MyChild(this, wxT("SVG Frame")); |
cdf3a589 | 224 | |
cdf3a589 | 225 | wxString title; |
49e3b82c FM |
226 | title.Printf(wxT("SVG Test Window %d"), m_nWinCreated ); |
227 | ||
cdf3a589 | 228 | // counts number of children previously, even if now closed |
49e3b82c | 229 | m_nWinCreated ++; |
cdf3a589 CE |
230 | |
231 | // Give it a title and icon | |
232 | subframe->SetTitle(title); | |
3cb332c1 | 233 | subframe->SetIcon(wxICON(sample)); |
cdf3a589 CE |
234 | |
235 | // Make a menubar | |
236 | wxMenu *file_menu = new wxMenu; | |
237 | ||
238 | file_menu->Append(MDI_NEW_WINDOW, wxT("&Another test\tCtrl+N")); | |
239 | file_menu->Append(MDI_SAVE, wxT("&Save\tCtrl+S"), wxT("Save in SVG format")); | |
240 | file_menu->Append(MDI_CHILD_QUIT, wxT("&Close child\tCtrl+F4")); | |
241 | file_menu->Append(MDI_QUIT, wxT("&Exit\tAlt+X")); | |
242 | ||
243 | wxMenu *help_menu = new wxMenu; | |
244 | help_menu->Append(MDI_ABOUT, wxT("&About")); | |
245 | ||
246 | wxMenuBar *menu_bar = new wxMenuBar; | |
247 | ||
248 | menu_bar->Append(file_menu, wxT("&File")); | |
249 | menu_bar->Append(help_menu, wxT("&Help")); | |
250 | ||
251 | // Associate the menu bar with the frame | |
252 | subframe->SetMenuBar(menu_bar); | |
253 | ||
c54e5eb0 | 254 | subframe->Show(true); |
cdf3a589 CE |
255 | } |
256 | ||
756d3e7f | 257 | void MyFrame::OnSize(wxSizeEvent& event) |
cdf3a589 CE |
258 | { |
259 | int w, h; | |
260 | GetClientSize(&w, &h); | |
261 | ||
262 | GetClientWindow()->SetSize(0, 0, w, h); | |
756d3e7f | 263 | event.Skip(); |
cdf3a589 CE |
264 | } |
265 | ||
cdf3a589 CE |
266 | void MyFrame::InitToolBar(wxToolBar* toolBar) |
267 | { | |
49e3b82c | 268 | const int maxBitmaps = 3; |
cdf3a589 CE |
269 | wxBitmap* bitmaps[maxBitmaps]; |
270 | ||
271 | bitmaps[0] = new wxBitmap( new_xpm ); | |
272 | bitmaps[1] = new wxBitmap( save_xpm ); | |
273 | bitmaps[2] = new wxBitmap( help_xpm ); | |
274 | ||
bbe28fbb PC |
275 | toolBar->AddTool(MDI_NEW_WINDOW, wxEmptyString, *(bitmaps[0]), wxS("New SVG test window")); |
276 | toolBar->AddTool(MDI_SAVE, wxEmptyString, *bitmaps[1], wxS("Save test in SVG format")); | |
a5e6cfa8 | 277 | toolBar->AddSeparator(); |
bbe28fbb | 278 | toolBar->AddTool(MDI_ABOUT, wxEmptyString, *bitmaps[2], wxS("Help")); |
cdf3a589 CE |
279 | |
280 | toolBar->Realize(); | |
281 | ||
282 | int i; | |
283 | for (i = 0; i < maxBitmaps; i++) | |
284 | delete bitmaps[i]; | |
285 | } | |
286 | ||
cdf3a589 CE |
287 | void MyFrame::FileSavePicture (wxCommandEvent & WXUNUSED(event) ) |
288 | { | |
c54e5eb0 | 289 | #if wxUSE_FILEDLG |
49e3b82c | 290 | MyChild * pChild = (MyChild *)GetActiveChild(); |
a5e6cfa8 | 291 | if (pChild == NULL) |
cdf3a589 | 292 | { |
49e3b82c | 293 | return; |
cdf3a589 CE |
294 | } |
295 | ||
296 | wxFileDialog dialog(this, wxT("Save Picture as"), wxEmptyString, pChild->GetTitle(), | |
297 | wxT("SVG vector picture files (*.svg)|*.svg"), | |
ff3e84ff | 298 | wxFD_SAVE|wxFD_OVERWRITE_PROMPT); |
cdf3a589 CE |
299 | |
300 | if (dialog.ShowModal() == wxID_OK) | |
301 | { | |
49e3b82c | 302 | if (!pChild->OnSave ( dialog.GetPath() )) |
cdf3a589 | 303 | { |
49e3b82c | 304 | return; |
cdf3a589 CE |
305 | } |
306 | } | |
49e3b82c | 307 | return; |
c54e5eb0 | 308 | #endif // wxUSE_FILEDLG |
cdf3a589 CE |
309 | } |
310 | ||
311 | ||
cdf3a589 CE |
312 | // --------------------------------------------------------------------------- |
313 | // MyCanvas | |
314 | // --------------------------------------------------------------------------- | |
315 | ||
49e3b82c FM |
316 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) |
317 | END_EVENT_TABLE() | |
318 | ||
cdf3a589 | 319 | // Define a constructor for my canvas |
49e3b82c FM |
320 | MyCanvas::MyCanvas(MyChild *parent, const wxPoint& pos, const wxSize& size) |
321 | : wxScrolledWindow(parent, wxID_ANY, pos, size, wxSUNKEN_BORDER|wxVSCROLL|wxHSCROLL) | |
cdf3a589 | 322 | { |
9a83f860 | 323 | SetBackgroundColour(wxColour(wxT("WHITE"))); |
cdf3a589 | 324 | |
49e3b82c FM |
325 | m_child = parent; |
326 | m_index = m_child->GetFrame()->GetCountOfChildren() % 7; | |
327 | } | |
cdf3a589 CE |
328 | |
329 | // Define the repainting behaviour | |
330 | void MyCanvas::OnDraw(wxDC& dc) | |
331 | { | |
332 | // vars to use ... | |
d96cdd4a | 333 | #if wxUSE_STATUSBAR |
49e3b82c | 334 | wxString s; |
d96cdd4a | 335 | #endif // wxUSE_STATUSBAR |
49e3b82c FM |
336 | wxPen wP; |
337 | wxBrush wB; | |
cdf3a589 CE |
338 | wxPoint points[6]; |
339 | wxColour wC; | |
49e3b82c | 340 | wxFont wF; |
cdf3a589 CE |
341 | |
342 | dc.SetFont(*wxSWISS_FONT); | |
343 | dc.SetPen(*wxGREEN_PEN); | |
344 | ||
cdf3a589 CE |
345 | switch (m_index) |
346 | { | |
347 | default: | |
348 | case 0: | |
349 | // draw lines to make a cross | |
350 | dc.DrawLine(0, 0, 200, 200); | |
351 | dc.DrawLine(200, 0, 0, 200); | |
352 | // draw point colored line and spline | |
49e3b82c | 353 | wP = *wxCYAN_PEN; |
cdf3a589 CE |
354 | wP.SetWidth(3); |
355 | dc.SetPen(wP); | |
356 | ||
49e3b82c | 357 | dc.DrawPoint (25,15); |
cdf3a589 CE |
358 | dc.DrawLine(50, 30, 200, 30); |
359 | dc.DrawSpline(50, 200, 50, 100, 200, 10); | |
d96cdd4a | 360 | #if wxUSE_STATUSBAR |
cdf3a589 | 361 | s = wxT("Green Cross, Cyan Line and spline"); |
d96cdd4a | 362 | #endif // wxUSE_STATUSBAR |
49e3b82c | 363 | break; |
cdf3a589 CE |
364 | |
365 | case 1: | |
366 | // draw standard shapes | |
367 | dc.SetBrush(*wxCYAN_BRUSH); | |
368 | dc.SetPen(*wxRED_PEN); | |
369 | dc.DrawRectangle(10, 10, 100, 70); | |
9a83f860 | 370 | wB = wxBrush (wxT("DARK ORCHID"), wxBRUSHSTYLE_TRANSPARENT); |
cdf3a589 CE |
371 | dc.SetBrush (wB); |
372 | dc.DrawRoundedRectangle(50, 50, 100, 70, 20); | |
9a83f860 | 373 | dc.SetBrush (wxBrush(wxT("GOLDENROD")) ); |
cdf3a589 CE |
374 | dc.DrawEllipse(100, 100, 100, 50); |
375 | ||
376 | points[0].x = 100; points[0].y = 200; | |
377 | points[1].x = 70; points[1].y = 260; | |
378 | points[2].x = 160; points[2].y = 230; | |
379 | points[3].x = 40; points[3].y = 230; | |
380 | points[4].x = 130; points[4].y = 260; | |
381 | points[5].x = 100; points[5].y = 200; | |
382 | ||
383 | dc.DrawPolygon(5, points); | |
384 | dc.DrawLines (6, points, 160); | |
d96cdd4a | 385 | #if wxUSE_STATUSBAR |
cdf3a589 | 386 | s = wxT("Blue rectangle, red edge, clear rounded rectangle, gold ellipse, gold and clear stars"); |
d96cdd4a | 387 | #endif // wxUSE_STATUSBAR |
49e3b82c | 388 | break; |
cdf3a589 CE |
389 | |
390 | case 2: | |
391 | // draw text in Arial or similar font | |
392 | dc.DrawLine(50,25,50,35); | |
393 | dc.DrawLine(45,30,55,30); | |
394 | dc.DrawText(wxT("This is a Swiss-style string"), 50, 30); | |
49e3b82c | 395 | wC = dc.GetTextForeground(); |
9a83f860 | 396 | dc.SetTextForeground (wxT("FIREBRICK")); |
a5e6cfa8 | 397 | |
cdf3a589 | 398 | // no effect in msw ?? |
9a83f860 | 399 | dc.SetTextBackground (wxT("WHEAT")); |
cdf3a589 CE |
400 | dc.DrawText(wxT("This is a Red string"), 50, 200); |
401 | dc.DrawRotatedText(wxT("This is a 45 deg string"), 50, 200, 45); | |
402 | dc.DrawRotatedText(wxT("This is a 90 deg string"), 50, 200, 90); | |
c54e5eb0 | 403 | wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman")); |
cdf3a589 | 404 | dc.SetFont(wF); |
49e3b82c | 405 | dc.SetTextForeground (wC); |
cdf3a589 | 406 | dc.DrawText(wxT("This is a Times-style string"), 50, 60); |
d96cdd4a | 407 | #if wxUSE_STATUSBAR |
cdf3a589 | 408 | s = wxT("Swiss, Times text; red text, rotated and colored orange"); |
d96cdd4a | 409 | #endif // wxUSE_STATUSBAR |
49e3b82c | 410 | break; |
cdf3a589 CE |
411 | |
412 | case 3 : | |
413 | // four arcs start and end points, center | |
414 | dc.SetBrush(*wxGREEN_BRUSH); | |
216db41f | 415 | dc.DrawArc ( 200,300, 370,230, 300,300 ); |
cdf3a589 | 416 | dc.SetBrush(*wxBLUE_BRUSH); |
216db41f | 417 | dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 ); |
cdf3a589 | 418 | dc.SetDeviceOrigin(-10,-10); |
216db41f | 419 | dc.DrawArc ( 270-50, 270-86, 270-86, 270-50, 270,270 ); |
cdf3a589 CE |
420 | dc.SetDeviceOrigin(0,0); |
421 | ||
9a83f860 | 422 | wP.SetColour (wxT("CADET BLUE")); |
cdf3a589 | 423 | dc.SetPen(wP); |
216db41f | 424 | dc.DrawArc ( 75,125, 110, 40, 75, 75 ); |
cdf3a589 | 425 | |
9a83f860 | 426 | wP.SetColour (wxT("SALMON")); |
cdf3a589 CE |
427 | dc.SetPen(wP); |
428 | dc.SetBrush(*wxRED_BRUSH); | |
429 | //top left corner, width and height, start and end angle | |
430 | // 315 same center and x-radius as last pie-arc, half Y radius | |
49e3b82c | 431 | dc.DrawEllipticArc(25,50,100,50,180.0,45.0); |
cdf3a589 | 432 | |
49e3b82c | 433 | wP = *wxCYAN_PEN; |
cdf3a589 CE |
434 | wP.SetWidth(3); |
435 | dc.SetPen(wP); | |
436 | //wxTRANSPARENT)); | |
9a83f860 | 437 | dc.SetBrush (wxBrush (wxT("SALMON"))); |
49e3b82c | 438 | dc.DrawEllipticArc(300, 0,200,100, 0.0,145.0); |
cdf3a589 | 439 | //same end point |
49e3b82c FM |
440 | dc.DrawEllipticArc(300, 50,200,100,90.0,145.0); |
441 | dc.DrawEllipticArc(300,100,200,100,90.0,345.0); | |
cdf3a589 | 442 | |
d96cdd4a | 443 | #if wxUSE_STATUSBAR |
cdf3a589 | 444 | s = wxT("This is an arc test page"); |
d96cdd4a | 445 | #endif // wxUSE_STATUSBAR |
49e3b82c | 446 | break; |
cdf3a589 CE |
447 | |
448 | case 4: | |
449 | dc.DrawCheckMark ( 30,30,25,25); | |
9a83f860 | 450 | dc.SetBrush (wxBrush (wxT("SALMON"),wxBRUSHSTYLE_TRANSPARENT)); |
cdf3a589 CE |
451 | dc.DrawCheckMark ( 80,50,75,75); |
452 | dc.DrawRectangle ( 80,50,75,75); | |
d96cdd4a | 453 | #if wxUSE_STATUSBAR |
cdf3a589 | 454 | s = wxT("Two check marks"); |
d96cdd4a | 455 | #endif // wxUSE_STATUSBAR |
49e3b82c | 456 | break; |
cdf3a589 CE |
457 | |
458 | case 5: | |
c54e5eb0 | 459 | wF = wxFont ( 18, wxROMAN, wxITALIC, wxBOLD, false, wxT("Times New Roman")); |
cdf3a589 CE |
460 | dc.SetFont(wF); |
461 | dc.DrawLine(0, 0, 200, 200); | |
462 | dc.DrawLine(200, 0, 0, 200); | |
463 | dc.DrawText(wxT("This is an 18pt string"), 50, 60); | |
464 | ||
465 | // rescale and draw in blue | |
49e3b82c | 466 | wP = *wxCYAN_PEN; |
cdf3a589 CE |
467 | dc.SetPen(wP); |
468 | dc.SetUserScale (2.0,0.5); | |
469 | dc.SetDeviceOrigin(200,0); | |
470 | dc.DrawLine(0, 0, 200, 200); | |
471 | dc.DrawLine(200, 0, 0, 200); | |
472 | dc.DrawText(wxT("This is an 18pt string 2 x 0.5 UserScaled"), 50, 60); | |
473 | dc.SetUserScale (2.0,2.0); | |
474 | dc.SetDeviceOrigin(200,200); | |
475 | dc.DrawText(wxT("This is an 18pt string 2 x 2 UserScaled"), 50, 60); | |
476 | ||
49e3b82c | 477 | wP = *wxRED_PEN; |
cdf3a589 CE |
478 | dc.SetPen(wP); |
479 | dc.SetUserScale (1.0,1.0); | |
480 | dc.SetDeviceOrigin(0,10); | |
49e3b82c | 481 | dc.SetMapMode (wxMM_METRIC); //svg ignores this |
cdf3a589 CE |
482 | dc.DrawLine(0, 0, 200, 200); |
483 | dc.DrawLine(200, 0, 0, 200); | |
a5e6cfa8 | 484 | dc.DrawText(wxT("This is an 18pt string in MapMode"), 50, 60); |
d96cdd4a | 485 | #if wxUSE_STATUSBAR |
cdf3a589 | 486 | s = wxT("Scaling test page"); |
d96cdd4a | 487 | #endif // wxUSE_STATUSBAR |
49e3b82c | 488 | break; |
cdf3a589 CE |
489 | |
490 | case 6: | |
3cb332c1 | 491 | dc.DrawIcon( wxICON(sample), 10, 10 ); |
756d3e7f | 492 | dc.DrawBitmap ( wxBitmap(svgbitmap_xpm), 50,15); |
d96cdd4a | 493 | #if wxUSE_STATUSBAR |
cdf3a589 | 494 | s = wxT("Icon and Bitmap "); |
d96cdd4a | 495 | #endif // wxUSE_STATUSBAR |
49e3b82c | 496 | break; |
cdf3a589 CE |
497 | |
498 | } | |
d96cdd4a | 499 | #if wxUSE_STATUSBAR |
cdf3a589 | 500 | m_child->SetStatusText(s); |
d96cdd4a | 501 | #endif // wxUSE_STATUSBAR |
cdf3a589 CE |
502 | } |
503 | ||
504 | ||
cdf3a589 CE |
505 | // --------------------------------------------------------------------------- |
506 | // MyChild | |
507 | // --------------------------------------------------------------------------- | |
508 | ||
49e3b82c FM |
509 | // Note that MDI_NEW_WINDOW and MDI_ABOUT commands get passed |
510 | // to the parent window for processing, so no need to | |
511 | // duplicate event handlers here. | |
512 | BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame) | |
513 | EVT_MENU(MDI_CHILD_QUIT, MyChild::OnQuit) | |
514 | END_EVENT_TABLE() | |
515 | ||
cdf3a589 | 516 | MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, |
49e3b82c FM |
517 | const wxPoint& pos, const wxSize& size, |
518 | const long style) | |
519 | : wxMDIChildFrame(parent, wxID_ANY, title, pos, size, style) | |
cdf3a589 | 520 | { |
49e3b82c FM |
521 | m_frame = (MyFrame *) parent; |
522 | ||
d96cdd4a | 523 | #if wxUSE_STATUSBAR |
cdf3a589 | 524 | CreateStatusBar(); |
a5e6cfa8 | 525 | SetStatusText(title); |
d96cdd4a | 526 | #endif // wxUSE_STATUSBAR |
cdf3a589 | 527 | |
49e3b82c FM |
528 | m_canvas = new MyCanvas(this, wxPoint(0, 0), GetClientSize()); |
529 | ||
cdf3a589 CE |
530 | // Give it scrollbars |
531 | m_canvas->SetScrollbars(20, 20, 50, 50); | |
cdf3a589 CE |
532 | } |
533 | ||
cdf3a589 CE |
534 | MyChild::~MyChild() |
535 | { | |
cdf3a589 CE |
536 | } |
537 | ||
cdf3a589 CE |
538 | void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event)) |
539 | { | |
c54e5eb0 | 540 | Close(true); |
cdf3a589 CE |
541 | } |
542 | ||
cdf3a589 CE |
543 | bool MyChild::OnSave(wxString filename) |
544 | { | |
49e3b82c | 545 | wxSVGFileDC svgDC (filename, 600, 650); |
cdf3a589 | 546 | m_canvas->OnDraw (svgDC); |
22e43568 | 547 | return svgDC.IsOk(); |
cdf3a589 CE |
548 | } |
549 | ||
cdf3a589 CE |
550 | void MyChild::OnActivate(wxActivateEvent& event) |
551 | { | |
552 | if ( event.GetActive() && m_canvas ) | |
553 | m_canvas->SetFocus(); | |
554 | } | |
555 |