]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: expended.cpp | |
3 | // Purpose: Layout/foldpanelbar sample | |
4 | // Author: Jorgen Bodde | |
5 | // Modified by: | |
6 | // Created: 24/07/2004 | |
7 | // Copyright: (c) Jorgen Bodde based upon FoldPanelBarTest (c) Julian Smart | |
8 | // Licence: wxWindows license | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // For compilers that support precompilation, includes "wx/wx.h". | |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/wx.h" | |
20 | #include "wx/mdi.h" | |
21 | #endif | |
22 | ||
23 | #include "wx/toolbar.h" | |
24 | #include "wx/laywin.h" | |
25 | #include "wx/spinctrl.h" | |
26 | #include "wx/slider.h" | |
27 | ||
28 | #include "sample.xpm" | |
29 | ||
30 | #include "extended.h" | |
31 | ||
32 | MyFrame *frame = NULL; | |
33 | wxList my_children; | |
34 | ||
35 | IMPLEMENT_APP(MyApp) | |
36 | ||
37 | // For drawing lines in a canvas | |
38 | long xpos = -1; | |
39 | long ypos = -1; | |
40 | ||
41 | int winNumber = 1; | |
42 | ||
43 | // Initialise this in OnInit, not statically | |
44 | bool MyApp::OnInit(void) | |
45 | { | |
46 | // Create the main frame window | |
47 | ||
48 | frame = new MyFrame(NULL, wxID_ANY, _T("FoldPanelBar Extended Demo"), wxDefaultPosition, wxSize(500, 600), | |
49 | wxDEFAULT_FRAME_STYLE | | |
50 | wxNO_FULL_REPAINT_ON_RESIZE | | |
51 | wxHSCROLL | wxVSCROLL); | |
52 | ||
53 | frame->SetIcon(wxIcon(sample_xpm)); | |
54 | ||
55 | // Associate the menu bar with the frame | |
56 | frame->SetMenuBar(CreateMenuBar(false)); | |
57 | ||
58 | frame->CreateStatusBar(); | |
59 | ||
60 | frame->Show(true); | |
61 | ||
62 | SetTopWindow(frame); | |
63 | ||
64 | return true; | |
65 | } | |
66 | ||
67 | BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame) | |
68 | EVT_MENU(FPBTEST_ABOUT, MyFrame::OnAbout) | |
69 | EVT_MENU(FPBTEST_NEW_WINDOW, MyFrame::OnNewWindow) | |
70 | EVT_SIZE(MyFrame::OnSize) | |
71 | EVT_MENU(FPBTEST_QUIT, MyFrame::OnQuit) | |
72 | EVT_MENU(FPBTEST_TOGGLE_WINDOW, MyFrame::OnToggleWindow) | |
73 | EVT_SASH_DRAGGED_RANGE(ID_WINDOW_TOP, ID_WINDOW_BOTTOM, MyFrame::OnFoldPanelBarDrag) | |
74 | EVT_MENU(FPB_BOTTOM_STICK, MyFrame::OnCreateBottomStyle) | |
75 | EVT_MENU(FPB_SINGLE_FOLD, MyFrame::OnCreateNormalStyle) | |
76 | EVT_BUTTON(ID_COLLAPSEME, MyFrame::OnCollapseMe) | |
77 | EVT_BUTTON(ID_APPLYTOALL, MyFrame::OnExpandMe) | |
78 | EVT_SCROLL(MyFrame::OnSlideColour) | |
79 | EVT_RADIOBUTTON(ID_USE_HGRADIENT, MyFrame::OnStyleChange) | |
80 | EVT_RADIOBUTTON(ID_USE_VGRADIENT, MyFrame::OnStyleChange) | |
81 | EVT_RADIOBUTTON(ID_USE_SINGLE, MyFrame::OnStyleChange) | |
82 | EVT_RADIOBUTTON(ID_USE_RECTANGLE, MyFrame::OnStyleChange) | |
83 | EVT_RADIOBUTTON(ID_USE_FILLED_RECTANGLE, MyFrame::OnStyleChange) | |
84 | END_EVENT_TABLE() | |
85 | ||
86 | ||
87 | // Define my frame constructor | |
88 | MyFrame::MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, | |
89 | const long style) | |
90 | : wxMDIParentFrame(parent, id, title, pos, size, style) | |
91 | , m_flags(0) | |
92 | { | |
93 | m_leftWindow1 = new wxSashLayoutWindow(this, ID_WINDOW_LEFT1, | |
94 | wxDefaultPosition, wxSize(200, 30), | |
95 | wxNO_BORDER | wxSW_3D | wxCLIP_CHILDREN); | |
96 | ||
97 | m_leftWindow1->SetDefaultSize(wxSize(160, 1000)); | |
98 | m_leftWindow1->SetOrientation(wxLAYOUT_VERTICAL); | |
99 | m_leftWindow1->SetAlignment(wxLAYOUT_LEFT); | |
100 | m_leftWindow1->SetSashVisible(wxSASH_RIGHT, true); | |
101 | m_leftWindow1->SetExtraBorderSize(0); | |
102 | ||
103 | m_pnl = NULL; | |
104 | ReCreateFoldPanel(0); | |
105 | } | |
106 | ||
107 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
108 | { | |
109 | Close(true); | |
110 | } | |
111 | ||
112 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
113 | { | |
114 | (void)wxMessageBox(_T("wxWidgets 2.0 FoldPanelBar Demo\nAuthor: Julian Smart (c) 1998"), _T("About FoldPanelBar Demo")); | |
115 | } | |
116 | ||
117 | void MyFrame::OnToggleWindow(wxCommandEvent& WXUNUSED(event)) | |
118 | { | |
119 | m_leftWindow1->Show(!m_leftWindow1->IsShown()); | |
120 | wxLayoutAlgorithm layout; | |
121 | layout.LayoutMDIFrame(this); | |
122 | } | |
123 | ||
124 | void MyFrame::OnFoldPanelBarDrag(wxSashEvent& event) | |
125 | { | |
126 | if (event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE) | |
127 | return; | |
128 | ||
129 | if(event.GetId() == ID_WINDOW_LEFT1) | |
130 | m_leftWindow1->SetDefaultSize(wxSize(event.GetDragRect().width, 1000)); | |
131 | ||
132 | wxLayoutAlgorithm layout; | |
133 | layout.LayoutMDIFrame(this); | |
134 | ||
135 | // Leaves bits of itself behind sometimes | |
136 | GetClientWindow()->Refresh(); | |
137 | } | |
138 | ||
139 | void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event)) | |
140 | { | |
141 | // Make another frame, containing a canvas | |
142 | MyChild *subframe = new MyChild(frame, _T("Canvas Frame"), | |
143 | wxPoint(10, 10), wxSize(300, 300), | |
144 | wxDEFAULT_FRAME_STYLE | | |
145 | wxNO_FULL_REPAINT_ON_RESIZE); | |
146 | ||
147 | subframe->SetTitle(wxString::Format(_T("Canvas Frame %d"), winNumber)); | |
148 | winNumber ++; | |
149 | ||
150 | // Give it a status line | |
151 | subframe->CreateStatusBar(); | |
152 | ||
153 | // Associate the menu bar with the frame | |
154 | subframe->SetMenuBar(CreateMenuBar(true)); | |
155 | ||
156 | int width, height; | |
157 | subframe->GetClientSize(&width, &height); | |
158 | MyCanvas *canvas = new MyCanvas(subframe, wxPoint(0, 0), wxSize(width, height)); | |
159 | canvas->SetCursor(wxCursor(wxCURSOR_PENCIL)); | |
160 | subframe->canvas = canvas; | |
161 | ||
162 | // Give it scrollbars | |
163 | canvas->SetScrollbars(20, 20, 50, 50); | |
164 | ||
165 | subframe->Show(true); | |
166 | } | |
167 | ||
168 | void MyFrame::ReCreateFoldPanel(int fpb_flags) | |
169 | { | |
170 | // delete earlier panel | |
171 | m_leftWindow1->DestroyChildren(); | |
172 | ||
173 | // recreate the foldpanelbar | |
174 | ||
175 | m_pnl = new wxFoldPanelBar(m_leftWindow1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFPB_DEFAULT_STYLE, fpb_flags); | |
176 | ||
177 | wxFoldPanel item = m_pnl->AddFoldPanel(_T("Caption colours"), false); | |
178 | ||
179 | m_pnl->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), wxID_ANY, _T("Adjust the first colour")), | |
180 | wxFPB_ALIGN_WIDTH, 5, 20); | |
181 | ||
182 | // RED color spin control | |
183 | m_rslider1 = new wxSlider(item.GetParent(), wxID_ANY, 0, 0, 255); | |
184 | m_pnl->AddFoldPanelWindow(item, m_rslider1, wxFPB_ALIGN_WIDTH, | |
185 | 2, 20); | |
186 | ||
187 | // GREEN color spin control | |
188 | m_gslider1 = new wxSlider(item.GetParent(), wxID_ANY, 0, 0, 255); | |
189 | m_pnl->AddFoldPanelWindow(item, m_gslider1, wxFPB_ALIGN_WIDTH, | |
190 | 0, 20); | |
191 | ||
192 | // BLUE color spin control | |
193 | m_bslider1 = new wxSlider(item.GetParent(), wxID_ANY, 0, 0, 255); | |
194 | m_pnl->AddFoldPanelWindow(item, m_bslider1, wxFPB_ALIGN_WIDTH, | |
195 | 0, 20); | |
196 | ||
197 | m_pnl->AddFoldPanelSeperator(item); | |
198 | ||
199 | m_pnl->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), wxID_ANY, _T("Adjust the second colour")), | |
200 | wxFPB_ALIGN_WIDTH, 5, 20); | |
201 | ||
202 | // RED color spin control | |
203 | m_rslider2 = new wxSlider(item.GetParent(), wxID_ANY, 0, 0, 255); | |
204 | m_pnl->AddFoldPanelWindow(item, m_rslider2, wxFPB_ALIGN_WIDTH, | |
205 | 2, 20); | |
206 | ||
207 | // GREEN color spin control | |
208 | m_gslider2 = new wxSlider(item.GetParent(), wxID_ANY, 0, 0, 255); | |
209 | m_pnl->AddFoldPanelWindow(item, m_gslider2, wxFPB_ALIGN_WIDTH, | |
210 | 0, 20); | |
211 | ||
212 | // BLUE color spin control | |
213 | m_bslider2 = new wxSlider(item.GetParent(), wxID_ANY, 0, 0, 255); | |
214 | m_pnl->AddFoldPanelWindow(item, m_bslider2, wxFPB_ALIGN_WIDTH, | |
215 | 0, 20); | |
216 | ||
217 | m_pnl->AddFoldPanelSeperator(item); | |
218 | ||
219 | m_btn = new wxButton(item.GetParent(), ID_APPLYTOALL, _T("Apply to all")); | |
220 | m_pnl->AddFoldPanelWindow(item, m_btn); | |
221 | ||
222 | // read back current gradients and set the sliders | |
223 | // for the colour which is now taken as default | |
224 | ||
225 | wxCaptionBarStyle style = m_pnl->GetCaptionStyle(item); | |
226 | wxColour col = style.GetFirstColour(); | |
227 | m_rslider1->SetValue(col.Red()); | |
228 | m_gslider1->SetValue(col.Green()); | |
229 | m_bslider1->SetValue(col.Blue()); | |
230 | ||
231 | col = style.GetSecondColour(); | |
232 | m_rslider2->SetValue(col.Red()); | |
233 | m_gslider2->SetValue(col.Green()); | |
234 | m_bslider2->SetValue(col.Blue()); | |
235 | ||
236 | // put down some caption styles from which the user can | |
237 | // select to show how the current or all caption bars will look like | |
238 | ||
239 | item = m_pnl->AddFoldPanel(_T("Caption style"), false); | |
240 | ||
241 | wxRadioButton *currStyle = new wxRadioButton(item.GetParent(), ID_USE_VGRADIENT, _T("&Vertical gradient")); | |
242 | m_pnl->AddFoldPanelWindow(item, currStyle, wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 10); | |
243 | currStyle->SetValue(true); | |
244 | ||
245 | m_pnl->AddFoldPanelWindow(item, new wxRadioButton(item.GetParent(), ID_USE_HGRADIENT, _T("&Horizontal gradient")), | |
246 | wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 10); | |
247 | m_pnl->AddFoldPanelWindow(item, new wxRadioButton(item.GetParent(), ID_USE_SINGLE, _T("&Single colour")), | |
248 | wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 10); | |
249 | m_pnl->AddFoldPanelWindow(item, new wxRadioButton(item.GetParent(), ID_USE_RECTANGLE, _T("&Rectangle box")), | |
250 | wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 10); | |
251 | m_pnl->AddFoldPanelWindow(item, new wxRadioButton(item.GetParent(), ID_USE_FILLED_RECTANGLE, _T("&Filled rectangle box")), | |
252 | wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 10); | |
253 | ||
254 | m_pnl->AddFoldPanelSeperator(item); | |
255 | ||
256 | m_single = new wxCheckBox(item.GetParent(), wxID_ANY, _T("&Only this caption")); | |
257 | m_pnl->AddFoldPanelWindow(item, m_single, wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 10); | |
258 | ||
259 | ||
260 | // one more panel to finish it | |
261 | ||
262 | wxCaptionBarStyle cs; | |
263 | cs.SetCaptionStyle(wxCAPTIONBAR_RECTANGLE); | |
264 | ||
265 | item = m_pnl->AddFoldPanel(_T("Misc stuff"), true, cs); | |
266 | ||
267 | m_pnl->AddFoldPanelWindow(item, new wxButton(item.GetParent(), ID_COLLAPSEME, _T("Collapse All"))); | |
268 | ||
269 | m_pnl->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), wxID_ANY, _T("Enter some comments")), | |
270 | wxFPB_ALIGN_WIDTH, 5, 20); | |
271 | ||
272 | m_pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comments")), | |
273 | wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 10); | |
274 | ||
275 | m_leftWindow1->SizeWindows(); | |
276 | ||
277 | } | |
278 | ||
279 | void MyFrame::OnCreateBottomStyle(wxCommandEvent& event) | |
280 | { | |
281 | // recreate with style collapse to bottom, which means | |
282 | // all panels that are collapsed are placed at the bottom, | |
283 | // or normal | |
284 | ||
285 | if(event.IsChecked()) | |
286 | m_flags |= wxFPB_COLLAPSE_TO_BOTTOM; | |
287 | else | |
288 | m_flags &= ~wxFPB_COLLAPSE_TO_BOTTOM; | |
289 | ||
290 | ReCreateFoldPanel(m_flags); | |
291 | } | |
292 | ||
293 | void MyFrame::OnCreateNormalStyle(wxCommandEvent& event) | |
294 | { | |
295 | // receate with style where only one panel at the time is | |
296 | // allowed to be opened | |
297 | ||
298 | // TODO: Not yet implemented! | |
299 | ||
300 | if(event.IsChecked()) | |
301 | m_flags |= wxFPB_SINGLE_FOLD; | |
302 | else | |
303 | m_flags &= ~wxFPB_SINGLE_FOLD; | |
304 | ||
305 | ReCreateFoldPanel(m_flags); | |
306 | } | |
307 | ||
308 | void MyFrame::OnCollapseMe(wxCommandEvent &WXUNUSED(event)) | |
309 | { | |
310 | wxFoldPanel item(0); | |
311 | for(size_t i = 0; i < m_pnl->GetCount(); i++) | |
312 | { | |
313 | item = m_pnl->Item(i); | |
314 | m_pnl->Collapse(item); | |
315 | } | |
316 | } | |
317 | ||
318 | void MyFrame::OnExpandMe(wxCommandEvent &WXUNUSED(event)) | |
319 | { | |
320 | wxColour col1((unsigned char)m_rslider1->GetValue(), | |
321 | (unsigned char)m_gslider1->GetValue(), | |
322 | (unsigned char)m_bslider1->GetValue()), | |
323 | col2((unsigned char)m_rslider2->GetValue(), | |
324 | (unsigned char)m_gslider2->GetValue(), | |
325 | (unsigned char)m_bslider2->GetValue()); | |
326 | ||
327 | wxCaptionBarStyle style; | |
328 | ||
329 | style.SetFirstColour(col1); | |
330 | style.SetSecondColour(col2); | |
331 | ||
332 | m_pnl->ApplyCaptionStyleAll(style); | |
333 | } | |
334 | ||
335 | wxMenuBar *CreateMenuBar(bool with_window) | |
336 | { | |
337 | // Make a menubar | |
338 | wxMenu *file_menu = new wxMenu; | |
339 | ||
340 | file_menu->Append(FPBTEST_NEW_WINDOW, _T("&New window")); | |
341 | if(with_window) | |
342 | file_menu->Append(FPBTEST_CHILD_QUIT, _T("&Close child")); | |
343 | ||
344 | file_menu->AppendSeparator(); | |
345 | file_menu->Append(FPBTEST_QUIT, _T("&Exit")); | |
346 | ||
347 | wxMenu *option_menu = 0; | |
348 | if(with_window) | |
349 | { | |
350 | // Dummy option | |
351 | option_menu = new wxMenu; | |
352 | option_menu->Append(FPBTEST_REFRESH, _T("&Refresh picture")); | |
353 | } | |
354 | ||
355 | // make fold panel menu | |
356 | ||
357 | wxMenu *fpb_menu = new wxMenu; | |
358 | fpb_menu->AppendCheckItem(FPB_BOTTOM_STICK, _T("Create with &wxFPB_COLLAPSE_TO_BOTTOM")); | |
359 | //fpb_menu->AppendCheckItem(FPB_SINGLE_FOLD, _T("Create with &wxFPB_SINGLE_FOLD")); | |
360 | ||
361 | fpb_menu->AppendSeparator(); | |
362 | fpb_menu->Append(FPBTEST_TOGGLE_WINDOW, _T("&Toggle FoldPanelBar")); | |
363 | ||
364 | wxMenu *help_menu = new wxMenu; | |
365 | help_menu->Append(FPBTEST_ABOUT, _T("&About")); | |
366 | ||
367 | wxMenuBar *menu_bar = new wxMenuBar; | |
368 | ||
369 | menu_bar->Append(file_menu, _T("&File")); | |
370 | menu_bar->Append(fpb_menu, _T("&FoldPanel")); | |
371 | if(option_menu) | |
372 | menu_bar->Append(option_menu, _T("&Options")); | |
373 | menu_bar->Append(help_menu, _T("&Help")); | |
374 | ||
375 | return menu_bar; | |
376 | } | |
377 | ||
378 | void MyFrame::OnSlideColour(wxScrollEvent &WXUNUSED(event)) | |
379 | { | |
380 | wxColour col1((unsigned char)m_rslider1->GetValue(), | |
381 | (unsigned char)m_gslider1->GetValue(), | |
382 | (unsigned char)m_bslider1->GetValue()), | |
383 | col2((unsigned char)m_rslider2->GetValue(), | |
384 | (unsigned char)m_gslider2->GetValue(), | |
385 | (unsigned char)m_bslider2->GetValue()); | |
386 | //m_btn->SetBackgroundColour(col); | |
387 | ||
388 | wxCaptionBarStyle style; | |
389 | ||
390 | style.SetFirstColour(col1); | |
391 | style.SetSecondColour(col2); | |
392 | ||
393 | wxFoldPanel item = m_pnl->Item(0); | |
394 | m_pnl->ApplyCaptionStyle(item, style); | |
395 | } | |
396 | ||
397 | void MyFrame::OnStyleChange(wxCommandEvent &event) | |
398 | { | |
399 | wxCaptionBarStyle style; | |
400 | switch(event.GetId()) | |
401 | { | |
402 | case ID_USE_HGRADIENT: | |
403 | style.SetCaptionStyle(wxCAPTIONBAR_GRADIENT_H); | |
404 | break; | |
405 | ||
406 | case ID_USE_VGRADIENT: | |
407 | style.SetCaptionStyle(wxCAPTIONBAR_GRADIENT_V); | |
408 | break; | |
409 | ||
410 | case ID_USE_SINGLE: | |
411 | style.SetCaptionStyle(wxCAPTIONBAR_SINGLE); | |
412 | break; | |
413 | ||
414 | case ID_USE_RECTANGLE: | |
415 | style.SetCaptionStyle(wxCAPTIONBAR_RECTANGLE); | |
416 | break; | |
417 | ||
418 | case ID_USE_FILLED_RECTANGLE: | |
419 | style.SetCaptionStyle(wxCAPTIONBAR_FILLED_RECTANGLE); | |
420 | break; | |
421 | ||
422 | default: | |
423 | break; | |
424 | } | |
425 | ||
426 | if(m_single->GetValue()) | |
427 | { | |
428 | wxFoldPanel item = m_pnl->Item(1); | |
429 | m_pnl->ApplyCaptionStyle(item, style); | |
430 | } | |
431 | else | |
432 | { | |
433 | m_pnl->ApplyCaptionStyleAll(style); | |
434 | } | |
435 | } | |
436 | ||
437 | /* ----------------------------------------------------------------------------------------------- */ | |
438 | ||
439 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) | |
440 | EVT_MOUSE_EVENTS(MyCanvas::OnEvent) | |
441 | END_EVENT_TABLE() | |
442 | ||
443 | // Define a constructor for my canvas | |
444 | MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size) | |
445 | :wxScrolledWindow(parent, wxID_ANY, pos, size, | |
446 | wxSUNKEN_BORDER | wxNO_FULL_REPAINT_ON_RESIZE) | |
447 | { | |
448 | SetBackgroundColour(* wxWHITE); | |
449 | } | |
450 | ||
451 | // Define the repainting behaviour | |
452 | void MyCanvas::OnDraw(wxDC& dc) | |
453 | { | |
454 | dc.SetFont(*wxSWISS_FONT); | |
455 | dc.SetPen(*wxGREEN_PEN); | |
456 | dc.DrawLine(0, 0, 200, 200); | |
457 | dc.DrawLine(200, 0, 0, 200); | |
458 | ||
459 | dc.SetBrush(*wxCYAN_BRUSH); | |
460 | dc.SetPen(*wxRED_PEN); | |
461 | dc.DrawRectangle(100, 100, 100, 50); | |
462 | dc.DrawRoundedRectangle(150, 150, 100, 50, 20); | |
463 | ||
464 | dc.DrawEllipse(250, 250, 100, 50); | |
465 | #if wxUSE_SPLINES | |
466 | dc.DrawSpline(50, 200, 50, 100, 200, 10); | |
467 | #endif // wxUSE_SPLINES | |
468 | dc.DrawLine(50, 230, 200, 230); | |
469 | dc.DrawText(_T("This is a test string"), 50, 230); | |
470 | ||
471 | wxPoint points[3]; | |
472 | points[0].x = 200; points[0].y = 300; | |
473 | points[1].x = 100; points[1].y = 400; | |
474 | points[2].x = 300; points[2].y = 400; | |
475 | ||
476 | dc.DrawPolygon(3, points); | |
477 | } | |
478 | ||
479 | // This implements a tiny doodling program! Drag the mouse using | |
480 | // the left button. | |
481 | void MyCanvas::OnEvent(wxMouseEvent& event) | |
482 | { | |
483 | wxClientDC dc(this); | |
484 | PrepareDC(dc); | |
485 | ||
486 | wxPoint pt(event.GetLogicalPosition(dc)); | |
487 | ||
488 | if (xpos > -1 && ypos > -1 && event.Dragging()) | |
489 | { | |
490 | dc.SetPen(*wxBLACK_PEN); | |
491 | dc.DrawLine(xpos, ypos, pt.x, pt.y); | |
492 | } | |
493 | xpos = pt.x; | |
494 | ypos = pt.y; | |
495 | } | |
496 | ||
497 | void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event)) | |
498 | { | |
499 | wxLayoutAlgorithm layout; | |
500 | layout.LayoutMDIFrame(this); | |
501 | } | |
502 | ||
503 | // Note that FPBTEST_NEW_WINDOW and FPBTEST_ABOUT commands get passed | |
504 | // to the parent window for processing, so no need to | |
505 | // duplicate event handlers here. | |
506 | ||
507 | BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame) | |
508 | EVT_MENU(FPBTEST_CHILD_QUIT, MyChild::OnQuit) | |
509 | END_EVENT_TABLE() | |
510 | ||
511 | MyChild::MyChild(wxMDIParentFrame *parent, const wxString& title, | |
512 | const wxPoint& pos, const wxSize& size, | |
513 | const long style) | |
514 | :wxMDIChildFrame(parent, wxID_ANY, title, pos, size, style) | |
515 | { | |
516 | canvas = NULL; | |
517 | my_children.Append(this); | |
518 | } | |
519 | ||
520 | MyChild::~MyChild(void) | |
521 | { | |
522 | my_children.DeleteObject(this); | |
523 | } | |
524 | ||
525 | void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
526 | { | |
527 | Close(true); | |
528 | } | |
529 | ||
530 | void MyChild::OnActivate(wxActivateEvent& event) | |
531 | { | |
532 | if (event.GetActive() && canvas) | |
533 | canvas->SetFocus(); | |
534 | } | |
535 |