]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/foldbar/extended/extended.cpp
Fix previous change in case somebody is still using
[wxWidgets.git] / contrib / samples / foldbar / extended / extended.cpp
CommitLineData
957f5ab7
VZ
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"
7e3c8a02
JS
25#include "wx/spinctrl.h"
26#include "wx/slider.h"
27
c74ca0c0 28#include "sample.xpm"
957f5ab7
VZ
29
30#include "extended.h"
31
32MyFrame *frame = NULL;
33wxList my_children;
34
35IMPLEMENT_APP(MyApp)
36
37// For drawing lines in a canvas
38long xpos = -1;
39long ypos = -1;
40
41int winNumber = 1;
42
43// Initialise this in OnInit, not statically
44bool MyApp::OnInit(void)
45{
7e3c8a02 46 // Create the main frame window
957f5ab7 47
c74ca0c0 48 frame = new MyFrame(NULL, wxID_ANY, _T("FoldPanelBar Extended Demo"), wxDefaultPosition, wxSize(500, 600),
7e3c8a02
JS
49 wxDEFAULT_FRAME_STYLE |
50 wxNO_FULL_REPAINT_ON_RESIZE |
51 wxHSCROLL | wxVSCROLL);
957f5ab7 52
7e3c8a02 53 frame->SetIcon(wxIcon(sample_xpm));
957f5ab7 54
7e3c8a02
JS
55 // Associate the menu bar with the frame
56 frame->SetMenuBar(CreateMenuBar(false));
957f5ab7 57
7e3c8a02 58 frame->CreateStatusBar();
957f5ab7 59
c74ca0c0 60 frame->Show(true);
957f5ab7 61
7e3c8a02 62 SetTopWindow(frame);
957f5ab7 63
c74ca0c0 64 return true;
957f5ab7
VZ
65}
66
67BEGIN_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)
7e3c8a02
JS
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)
957f5ab7
VZ
84END_EVENT_TABLE()
85
86
87// Define my frame constructor
88MyFrame::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)
c74ca0c0
WS
91 , m_flags(0)
92{
7e3c8a02
JS
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);
c74ca0c0 100 m_leftWindow1->SetSashVisible(wxSASH_RIGHT, true);
7e3c8a02
JS
101 m_leftWindow1->SetExtraBorderSize(0);
102
c74ca0c0 103 m_pnl = NULL;
7e3c8a02 104 ReCreateFoldPanel(0);
957f5ab7
VZ
105}
106
107void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
108{
c74ca0c0 109 Close(true);
957f5ab7
VZ
110}
111
112void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
113{
7e3c8a02 114 (void)wxMessageBox(_T("wxWidgets 2.0 FoldPanelBar Demo\nAuthor: Julian Smart (c) 1998"), _T("About FoldPanelBar Demo"));
957f5ab7
VZ
115}
116
117void MyFrame::OnToggleWindow(wxCommandEvent& WXUNUSED(event))
118{
c74ca0c0 119 m_leftWindow1->Show(!m_leftWindow1->IsShown());
957f5ab7
VZ
120 wxLayoutAlgorithm layout;
121 layout.LayoutMDIFrame(this);
122}
123
124void 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
7e3c8a02 132 wxLayoutAlgorithm layout;
957f5ab7
VZ
133 layout.LayoutMDIFrame(this);
134
135 // Leaves bits of itself behind sometimes
136 GetClientWindow()->Refresh();
137}
138
139void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event))
140{
c74ca0c0
WS
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 ++;
957f5ab7 149
7e3c8a02
JS
150 // Give it a status line
151 subframe->CreateStatusBar();
957f5ab7 152
7e3c8a02
JS
153 // Associate the menu bar with the frame
154 subframe->SetMenuBar(CreateMenuBar(true));
957f5ab7 155
7e3c8a02
JS
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;
957f5ab7 161
7e3c8a02
JS
162 // Give it scrollbars
163 canvas->SetScrollbars(20, 20, 50, 50);
957f5ab7 164
c74ca0c0 165 subframe->Show(true);
957f5ab7
VZ
166}
167
168void MyFrame::ReCreateFoldPanel(int fpb_flags)
169{
170 // delete earlier panel
7e3c8a02 171 m_leftWindow1->DestroyChildren();
957f5ab7 172
7e3c8a02 173 // recreate the foldpanelbar
957f5ab7 174
c74ca0c0 175 m_pnl = new wxFoldPanelBar(m_leftWindow1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFPB_DEFAULT_STYLE, fpb_flags);
957f5ab7 176
c74ca0c0
WS
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);
957f5ab7 181
7e3c8a02 182 // RED color spin control
c74ca0c0
WS
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);
957f5ab7 186
7e3c8a02 187 // GREEN color spin control
c74ca0c0
WS
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);
957f5ab7 191
7e3c8a02 192 // BLUE color spin control
c74ca0c0
WS
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);
957f5ab7 198
c74ca0c0
WS
199 m_pnl->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), wxID_ANY, _T("Adjust the second colour")),
200 wxFPB_ALIGN_WIDTH, 5, 20);
957f5ab7 201
7e3c8a02 202 // RED color spin control
c74ca0c0
WS
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);
957f5ab7 206
7e3c8a02 207 // GREEN color spin control
c74ca0c0
WS
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);
957f5ab7 211
7e3c8a02 212 // BLUE color spin control
c74ca0c0
WS
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);
957f5ab7 216
c74ca0c0
WS
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);
957f5ab7 221
7e3c8a02
JS
222 // read back current gradients and set the sliders
223 // for the colour which is now taken as default
957f5ab7 224
c74ca0c0 225 wxCaptionBarStyle style = m_pnl->GetCaptionStyle(item);
7e3c8a02 226 wxColour col = style.GetFirstColour();
c74ca0c0
WS
227 m_rslider1->SetValue(col.Red());
228 m_gslider1->SetValue(col.Green());
229 m_bslider1->SetValue(col.Blue());
957f5ab7 230
7e3c8a02 231 col = style.GetSecondColour();
c74ca0c0
WS
232 m_rslider2->SetValue(col.Red());
233 m_gslider2->SetValue(col.Green());
234 m_bslider2->SetValue(col.Blue());
957f5ab7 235
7e3c8a02
JS
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
957f5ab7 238
c74ca0c0 239 item = m_pnl->AddFoldPanel(_T("Caption style"), false);
957f5ab7 240
c74ca0c0
WS
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);
7e3c8a02 243 currStyle->SetValue(true);
957f5ab7 244
c74ca0c0
WS
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);
957f5ab7 253
c74ca0c0 254 m_pnl->AddFoldPanelSeperator(item);
957f5ab7 255
c74ca0c0
WS
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);
957f5ab7
VZ
258
259
7e3c8a02 260 // one more panel to finish it
957f5ab7 261
7e3c8a02
JS
262 wxCaptionBarStyle cs;
263 cs.SetCaptionStyle(wxCAPTIONBAR_RECTANGLE);
957f5ab7 264
c74ca0c0
WS
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")));
957f5ab7 268
c74ca0c0
WS
269 m_pnl->AddFoldPanelWindow(item, new wxStaticText(item.GetParent(), wxID_ANY, _T("Enter some comments")),
270 wxFPB_ALIGN_WIDTH, 5, 20);
957f5ab7 271
c74ca0c0
WS
272 m_pnl->AddFoldPanelWindow(item, new wxTextCtrl(item.GetParent(), wxID_ANY, _T("Comments")),
273 wxFPB_ALIGN_WIDTH, wxFPB_DEFAULT_SPACING, 10);
957f5ab7 274
7e3c8a02 275 m_leftWindow1->SizeWindows();
957f5ab7
VZ
276
277}
278
279void MyFrame::OnCreateBottomStyle(wxCommandEvent& event)
280{
7e3c8a02
JS
281 // recreate with style collapse to bottom, which means
282 // all panels that are collapsed are placed at the bottom,
283 // or normal
c74ca0c0 284
7e3c8a02 285 if(event.IsChecked())
c74ca0c0 286 m_flags |= wxFPB_COLLAPSE_TO_BOTTOM;
7e3c8a02 287 else
c74ca0c0 288 m_flags &= ~wxFPB_COLLAPSE_TO_BOTTOM;
7e3c8a02 289
c74ca0c0 290 ReCreateFoldPanel(m_flags);
957f5ab7
VZ
291}
292
293void MyFrame::OnCreateNormalStyle(wxCommandEvent& event)
294{
7e3c8a02
JS
295 // receate with style where only one panel at the time is
296 // allowed to be opened
c74ca0c0 297
7e3c8a02 298 // TODO: Not yet implemented!
957f5ab7 299
7e3c8a02 300 if(event.IsChecked())
c74ca0c0 301 m_flags |= wxFPB_SINGLE_FOLD;
7e3c8a02 302 else
c74ca0c0 303 m_flags &= ~wxFPB_SINGLE_FOLD;
957f5ab7 304
c74ca0c0 305 ReCreateFoldPanel(m_flags);
957f5ab7
VZ
306}
307
c74ca0c0 308void MyFrame::OnCollapseMe(wxCommandEvent &WXUNUSED(event))
957f5ab7 309{
7e3c8a02 310 wxFoldPanel item(0);
c74ca0c0 311 for(size_t i = 0; i < m_pnl->GetCount(); i++)
7e3c8a02 312 {
c74ca0c0
WS
313 item = m_pnl->Item(i);
314 m_pnl->Collapse(item);
7e3c8a02 315 }
957f5ab7
VZ
316}
317
c74ca0c0 318void MyFrame::OnExpandMe(wxCommandEvent &WXUNUSED(event))
957f5ab7 319{
c74ca0c0
WS
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());
957f5ab7 326
7e3c8a02 327 wxCaptionBarStyle style;
957f5ab7 328
7e3c8a02
JS
329 style.SetFirstColour(col1);
330 style.SetSecondColour(col2);
957f5ab7 331
c74ca0c0 332 m_pnl->ApplyCaptionStyleAll(style);
957f5ab7
VZ
333}
334
335wxMenuBar *CreateMenuBar(bool with_window)
336{
7e3c8a02
JS
337 // Make a menubar
338 wxMenu *file_menu = new wxMenu;
957f5ab7 339
7e3c8a02
JS
340 file_menu->Append(FPBTEST_NEW_WINDOW, _T("&New window"));
341 if(with_window)
342 file_menu->Append(FPBTEST_CHILD_QUIT, _T("&Close child"));
957f5ab7 343
7e3c8a02
JS
344 file_menu->AppendSeparator();
345 file_menu->Append(FPBTEST_QUIT, _T("&Exit"));
957f5ab7 346
7e3c8a02
JS
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 }
957f5ab7 354
7e3c8a02 355 // make fold panel menu
c74ca0c0 356
7e3c8a02
JS
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"));
957f5ab7 360
7e3c8a02
JS
361 fpb_menu->AppendSeparator();
362 fpb_menu->Append(FPBTEST_TOGGLE_WINDOW, _T("&Toggle FoldPanelBar"));
957f5ab7 363
7e3c8a02
JS
364 wxMenu *help_menu = new wxMenu;
365 help_menu->Append(FPBTEST_ABOUT, _T("&About"));
957f5ab7 366
7e3c8a02 367 wxMenuBar *menu_bar = new wxMenuBar;
957f5ab7 368
7e3c8a02
JS
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"));
957f5ab7 374
7e3c8a02 375 return menu_bar;
957f5ab7
VZ
376}
377
c74ca0c0 378void MyFrame::OnSlideColour(wxScrollEvent &WXUNUSED(event))
957f5ab7 379{
c74ca0c0
WS
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);
957f5ab7 387
7e3c8a02 388 wxCaptionBarStyle style;
957f5ab7 389
7e3c8a02
JS
390 style.SetFirstColour(col1);
391 style.SetSecondColour(col2);
957f5ab7 392
c74ca0c0
WS
393 wxFoldPanel item = m_pnl->Item(0);
394 m_pnl->ApplyCaptionStyle(item, style);
957f5ab7
VZ
395}
396
397void MyFrame::OnStyleChange(wxCommandEvent &event)
398{
7e3c8a02
JS
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;
c74ca0c0 421
7e3c8a02
JS
422 default:
423 break;
424 }
425
c74ca0c0 426 if(m_single->GetValue())
7e3c8a02 427 {
c74ca0c0
WS
428 wxFoldPanel item = m_pnl->Item(1);
429 m_pnl->ApplyCaptionStyle(item, style);
7e3c8a02
JS
430 }
431 else
c74ca0c0
WS
432 {
433 m_pnl->ApplyCaptionStyleAll(style);
434 }
957f5ab7
VZ
435}
436
437/* ----------------------------------------------------------------------------------------------- */
438
439BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
440 EVT_MOUSE_EVENTS(MyCanvas::OnEvent)
441END_EVENT_TABLE()
442
443// Define a constructor for my canvas
444MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size)
c74ca0c0 445 :wxScrolledWindow(parent, wxID_ANY, pos, size,
957f5ab7
VZ
446 wxSUNKEN_BORDER | wxNO_FULL_REPAINT_ON_RESIZE)
447{
448 SetBackgroundColour(* wxWHITE);
449}
450
451// Define the repainting behaviour
452void MyCanvas::OnDraw(wxDC& dc)
453{
c74ca0c0
WS
454 dc.SetFont(*wxSWISS_FONT);
455 dc.SetPen(*wxGREEN_PEN);
456 dc.DrawLine(0, 0, 200, 200);
457 dc.DrawLine(200, 0, 0, 200);
957f5ab7 458
c74ca0c0
WS
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);
957f5ab7 463
c74ca0c0 464 dc.DrawEllipse(250, 250, 100, 50);
957f5ab7 465#if wxUSE_SPLINES
c74ca0c0 466 dc.DrawSpline(50, 200, 50, 100, 200, 10);
957f5ab7 467#endif // wxUSE_SPLINES
c74ca0c0
WS
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);
957f5ab7
VZ
477}
478
479// This implements a tiny doodling program! Drag the mouse using
480// the left button.
481void MyCanvas::OnEvent(wxMouseEvent& event)
482{
c74ca0c0
WS
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;
957f5ab7
VZ
495}
496
497void 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
507BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame)
c74ca0c0 508 EVT_MENU(FPBTEST_CHILD_QUIT, MyChild::OnQuit)
957f5ab7
VZ
509END_EVENT_TABLE()
510
c74ca0c0
WS
511MyChild::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)
957f5ab7 515{
c74ca0c0
WS
516 canvas = NULL;
517 my_children.Append(this);
957f5ab7
VZ
518}
519
520MyChild::~MyChild(void)
521{
c74ca0c0 522 my_children.DeleteObject(this);
957f5ab7
VZ
523}
524
525void MyChild::OnQuit(wxCommandEvent& WXUNUSED(event))
526{
c74ca0c0 527 Close(true);
957f5ab7
VZ
528}
529
530void MyChild::OnActivate(wxActivateEvent& event)
531{
c74ca0c0
WS
532 if (event.GetActive() && canvas)
533 canvas->SetFocus();
957f5ab7
VZ
534}
535