]> git.saurik.com Git - wxWidgets.git/blame - samples/mdi/mdi.cpp
For wxGTK2, link with X11 explicitly, since we use many X11 functions directly.
[wxWidgets.git] / samples / mdi / mdi.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: mdi.cpp
3// Purpose: MDI sample
4// Author: Julian Smart
d2824cdb 5// Modified by: 2008-10-31 Vadim Zeitlin: big clean up
c801d85f
KB
6// Created: 04/01/98
7// RCS-ID: $Id$
d2824cdb
VZ
8// Copyright: (c) 1997 Julian Smart
9// (c) 2008 Vadim Zeitlin
526954c5 10// Licence: wxWindows licence
c801d85f
KB
11/////////////////////////////////////////////////////////////////////////////
12
c52d95b4
VZ
13// ===========================================================================
14// declarations
15// ===========================================================================
16
17// ---------------------------------------------------------------------------
18// headers
19// ---------------------------------------------------------------------------
20
c801d85f
KB
21// For compilers that support precompilation, includes "wx/wx.h".
22#include "wx/wxprec.h"
23
24#ifdef __BORLANDC__
c52d95b4 25 #pragma hdrstop
c801d85f
KB
26#endif
27
28#ifndef WX_PRECOMP
c52d95b4
VZ
29 #include "wx/wx.h"
30 #include "wx/mdi.h"
c801d85f
KB
31#endif
32
012f2cb2 33#include "wx/toolbar.h"
c801d85f 34
9fa453ec 35#if !defined(__WXMSW__)
ea7fb468
VZ
36 #include "../sample.xpm"
37 #include "chart.xpm"
716b7364
RR
38#endif
39
d04d32c4
CE
40#include "bitmaps/new.xpm"
41#include "bitmaps/open.xpm"
42#include "bitmaps/save.xpm"
43#include "bitmaps/copy.xpm"
44#include "bitmaps/cut.xpm"
45#include "bitmaps/paste.xpm"
46#include "bitmaps/print.xpm"
47#include "bitmaps/help.xpm"
48
d2824cdb
VZ
49// replace this 0 with 1 to build the sample using the generic MDI classes (you
50// may also need to add src/generic/mdig.cpp to the build)
51#if 0
52 #include "wx/generic/mdig.h"
53 #define wxMDIParentFrame wxGenericMDIParentFrame
54 #define wxMDIChildFrame wxGenericMDIChildFrame
55 #define wxMDIClientWindow wxGenericMDIClientWindow
56#endif
d04d32c4 57
c801d85f
KB
58#include "mdi.h"
59
c52d95b4
VZ
60IMPLEMENT_APP(MyApp)
61
c52d95b4
VZ
62// ---------------------------------------------------------------------------
63// event tables
64// ---------------------------------------------------------------------------
65
66BEGIN_EVENT_TABLE(MyFrame, wxMDIParentFrame)
d2824cdb
VZ
67 EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
68 EVT_MENU(wxID_NEW, MyFrame::OnNewWindow)
9089cffb 69 EVT_MENU(MDI_FULLSCREEN, MyFrame::OnFullScreen)
d2824cdb 70 EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
c52d95b4 71
1483e5db
VZ
72 EVT_MENU(wxID_CLOSE_ALL, MyFrame::OnCloseAll)
73
c52d95b4 74 EVT_CLOSE(MyFrame::OnClose)
c52d95b4
VZ
75END_EVENT_TABLE()
76
d2824cdb 77// Note that wxID_NEW and wxID_ABOUT commands get passed
c52d95b4
VZ
78// to the parent window for processing, so no need to
79// duplicate event handlers here.
80BEGIN_EVENT_TABLE(MyChild, wxMDIChildFrame)
d2824cdb 81 EVT_MENU(wxID_CLOSE, MyChild::OnClose)
c52d95b4 82 EVT_MENU(MDI_REFRESH, MyChild::OnRefresh)
f6bcfd97 83 EVT_MENU(MDI_CHANGE_TITLE, MyChild::OnChangeTitle)
3d8dea7e
VZ
84 EVT_MENU(MDI_CHANGE_POSITION, MyChild::OnChangePosition)
85 EVT_MENU(MDI_CHANGE_SIZE, MyChild::OnChangeSize)
86
c9f856af
VZ
87#if wxUSE_CLIPBOARD
88 EVT_MENU(wxID_PASTE, MyChild::OnPaste)
89 EVT_UPDATE_UI(wxID_PASTE, MyChild::OnUpdatePaste)
90#endif // wxUSE_CLIPBOARD
91
3d8dea7e
VZ
92 EVT_SIZE(MyChild::OnSize)
93 EVT_MOVE(MyChild::OnMove)
c52d95b4 94
d2824cdb 95 EVT_CLOSE(MyChild::OnCloseWindow)
c52d95b4
VZ
96END_EVENT_TABLE()
97
98BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
99 EVT_MOUSE_EVENTS(MyCanvas::OnEvent)
100END_EVENT_TABLE()
101
396e9eb8
VZ
102BEGIN_EVENT_TABLE(MyChild::EventHandler, wxEvtHandler)
103 EVT_MENU(MDI_REFRESH, MyChild::EventHandler::OnRefresh)
104END_EVENT_TABLE()
105
c52d95b4
VZ
106// ===========================================================================
107// implementation
108// ===========================================================================
c801d85f 109
c52d95b4
VZ
110// ---------------------------------------------------------------------------
111// MyApp
112// ---------------------------------------------------------------------------
c801d85f
KB
113
114// Initialise this in OnInit, not statically
c52d95b4 115bool MyApp::OnInit()
c801d85f 116{
45e6e6f8
VZ
117 if ( !wxApp::OnInit() )
118 return false;
119
c52d95b4 120 // Create the main frame window
c801d85f 121
d2824cdb 122 MyFrame *frame = new MyFrame;
c801d85f 123
d2824cdb
VZ
124 frame->Show(true);
125
126 return true;
127}
128
129// ---------------------------------------------------------------------------
130// MyFrame
131// ---------------------------------------------------------------------------
132
133// Define my frame constructor
134MyFrame::MyFrame()
135 : wxMDIParentFrame(NULL, wxID_ANY, "wxWidgets MDI Sample",
136 wxDefaultPosition, wxSize(500, 400))
137{
138 SetIcon(wxICON(sample));
c801d85f 139
c52d95b4 140 // Make a menubar
d2824cdb 141#if wxUSE_MENUS
c52d95b4 142 // Associate the menu bar with the frame
4f7cd56c 143 SetMenuBar(CreateMainMenubar());
d2824cdb 144
1483e5db
VZ
145
146 // This shows that the standard window menu may be customized:
147 wxMenu * const windowMenu = GetWindowMenu();
148 if ( windowMenu )
149 {
150 // we can change the labels of standard items (which also means we can
151 // set up accelerators for them as they're part of the label)
152 windowMenu->SetLabel(wxID_MDI_WINDOW_TILE_HORZ,
153 "&Tile horizontally\tCtrl-Shift-H");
154 windowMenu->SetLabel(wxID_MDI_WINDOW_TILE_VERT,
155 "&Tile vertically\tCtrl-Shift-V");
156
157 // we can also change the help string
158 windowMenu->SetHelpString(wxID_MDI_WINDOW_CASCADE,
159 "Arrange windows in cascade");
160
161 // we can remove some items
162 windowMenu->Delete(wxID_MDI_WINDOW_ARRANGE_ICONS);
163
164 // and we can add completely custom commands -- but then we must handle
165 // them ourselves, see OnCloseAll()
166 windowMenu->AppendSeparator();
167 windowMenu->Append(wxID_CLOSE_ALL, "&Close all windows\tCtrl-Shift-C",
168 "Close all open windows");
169
170 SetWindowMenu(windowMenu);
171 }
d2824cdb 172#endif // wxUSE_MENUS
c801d85f 173
8520f137 174#if wxUSE_STATUSBAR
d2824cdb 175 CreateStatusBar();
8520f137 176#endif // wxUSE_STATUSBAR
c801d85f 177
c801d85f 178
d2824cdb
VZ
179 m_textWindow = new wxTextCtrl(this, wxID_ANY, "A help window",
180 wxDefaultPosition, wxDefaultSize,
181 wxTE_MULTILINE | wxSUNKEN_BORDER);
c801d85f 182
6ceba174 183#if wxUSE_TOOLBAR
fa762db4 184 CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL);
81d66cf3 185 InitToolBar(GetToolBar());
6ceba174 186#endif // wxUSE_TOOLBAR
57a7b7c1 187
4219b5e7 188#if wxUSE_ACCEL
57a7b7c1
JS
189 // Accelerators
190 wxAcceleratorEntry entries[3];
d2824cdb
VZ
191 entries[0].Set(wxACCEL_CTRL, (int) 'N', wxID_NEW);
192 entries[1].Set(wxACCEL_CTRL, (int) 'X', wxID_EXIT);
193 entries[2].Set(wxACCEL_CTRL, (int) 'A', wxID_ABOUT);
57a7b7c1
JS
194 wxAcceleratorTable accel(3, entries);
195 SetAcceleratorTable(accel);
4219b5e7 196#endif // wxUSE_ACCEL
d2824cdb
VZ
197
198 // connect it only now, after creating m_textWindow
199 Connect(wxEVT_SIZE, wxSizeEventHandler(MyFrame::OnSize));
200}
201
202MyFrame::~MyFrame()
203{
204 // and disconnect it to prevent accessing already deleted m_textWindow in
205 // the size event handler if it's called during destruction
206 Disconnect(wxEVT_SIZE, wxSizeEventHandler(MyFrame::OnSize));
c801d85f
KB
207}
208
4f7cd56c
VZ
209#if wxUSE_MENUS
210/* static */
211wxMenuBar *MyFrame::CreateMainMenubar()
212{
213 wxMenu *menuFile = new wxMenu;
214
215 menuFile->Append(wxID_NEW, "&New window\tCtrl-N", "Create a new child window");
216 menuFile->AppendCheckItem(MDI_FULLSCREEN, "Show &full screen\tCtrl-F");
217 menuFile->Append(wxID_EXIT, "&Exit\tAlt-X", "Quit the program");
218
219 wxMenu *menuHelp = new wxMenu;
220 menuHelp->Append(wxID_ABOUT, "&About\tF1");
221
222 wxMenuBar *mbar = new wxMenuBar;
223 mbar->Append(menuFile, "&File");
224 mbar->Append(menuHelp, "&Help");
225
226 return mbar;
227}
228#endif // wxUSE_MENUS
229
c52d95b4
VZ
230void MyFrame::OnClose(wxCloseEvent& event)
231{
d2824cdb
VZ
232 unsigned numChildren = MyChild::GetChildrenCount();
233 if ( event.CanVeto() && (numChildren > 0) )
c52d95b4
VZ
234 {
235 wxString msg;
d2824cdb
VZ
236 msg.Printf("%d windows still open, close anyhow?", numChildren);
237 if ( wxMessageBox(msg, "Please confirm",
c52d95b4
VZ
238 wxICON_QUESTION | wxYES_NO) != wxYES )
239 {
240 event.Veto();
241
242 return;
243 }
244 }
245
246 event.Skip();
247}
248
249void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
c801d85f 250{
c52d95b4 251 Close();
c801d85f
KB
252}
253
e3e65dac 254void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
c801d85f 255{
d2824cdb
VZ
256 (void)wxMessageBox("wxWidgets 2.0 MDI Demo\n"
257 "Author: Julian Smart (c) 1997\n"
258 "Usage: mdi.exe", "About MDI Demo");
c801d85f
KB
259}
260
e3e65dac 261void MyFrame::OnNewWindow(wxCommandEvent& WXUNUSED(event) )
c801d85f 262{
d2824cdb
VZ
263 // create and show another child frame
264 MyChild *subframe = new MyChild(this);
eb839c84 265 subframe->Show(true);
c801d85f
KB
266}
267
9089cffb
VZ
268void MyFrame::OnFullScreen(wxCommandEvent& event)
269{
270 ShowFullScreen(event.IsChecked());
271}
272
1483e5db
VZ
273void MyFrame::OnCloseAll(wxCommandEvent& WXUNUSED(event))
274{
275 for ( wxWindowList::const_iterator i = GetChildren().begin();
276 i != GetChildren().end();
277 ++i )
278 {
279 if ( wxDynamicCast(*i, wxMDIChildFrame) )
280 (*i)->Close();
281 }
282}
283
9298a1c2 284void MyFrame::OnSize(wxSizeEvent& event)
c52d95b4
VZ
285{
286 int w, h;
287 GetClientSize(&w, &h);
288
d2824cdb 289 m_textWindow->SetSize(0, 0, 200, h);
c52d95b4 290 GetClientWindow()->SetSize(200, 0, w - 200, h);
a9c824e9
JS
291
292 // FIXME: On wxX11, we need the MDI frame to process this
293 // event, but on other platforms this should not
294 // be done.
4219b5e7 295#ifdef __WXUNIVERSAL__
b9f933ab 296 event.Skip();
9298a1c2
VZ
297#else
298 wxUnusedVar(event);
a9c824e9 299#endif
c52d95b4
VZ
300}
301
6ceba174 302#if wxUSE_TOOLBAR
c52d95b4
VZ
303void MyFrame::InitToolBar(wxToolBar* toolBar)
304{
e21d8614
VZ
305 wxBitmap bitmaps[8];
306
307 bitmaps[0] = wxBitmap( new_xpm );
308 bitmaps[1] = wxBitmap( open_xpm );
309 bitmaps[2] = wxBitmap( save_xpm );
310 bitmaps[3] = wxBitmap( copy_xpm );
311 bitmaps[4] = wxBitmap( cut_xpm );
312 bitmaps[5] = wxBitmap( paste_xpm );
313 bitmaps[6] = wxBitmap( print_xpm );
314 bitmaps[7] = wxBitmap( help_xpm );
315
d2824cdb
VZ
316 toolBar->AddTool(wxID_NEW, "New", bitmaps[0], "New file");
317 toolBar->AddTool(1, "Open", bitmaps[1], "Open file");
318 toolBar->AddTool(2, "Save", bitmaps[2], "Save file");
c52d95b4 319 toolBar->AddSeparator();
d2824cdb
VZ
320 toolBar->AddTool(3, "Copy", bitmaps[3], "Copy");
321 toolBar->AddTool(4, "Cut", bitmaps[4], "Cut");
322 toolBar->AddTool(5, "Paste", bitmaps[5], "Paste");
c52d95b4 323 toolBar->AddSeparator();
d2824cdb 324 toolBar->AddTool(6, "Print", bitmaps[6], "Print");
c52d95b4 325 toolBar->AddSeparator();
d2824cdb 326 toolBar->AddTool(wxID_ABOUT, "About", bitmaps[7], "Help");
c52d95b4
VZ
327
328 toolBar->Realize();
c52d95b4 329}
6ceba174 330#endif // wxUSE_TOOLBAR
c52d95b4
VZ
331
332// ---------------------------------------------------------------------------
333// MyCanvas
334// ---------------------------------------------------------------------------
c801d85f
KB
335
336// Define a constructor for my canvas
c52d95b4 337MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size)
eb839c84 338 : wxScrolledWindow(parent, wxID_ANY, pos, size,
3ebcfb76
VZ
339 wxSUNKEN_BORDER |
340 wxNO_FULL_REPAINT_ON_RESIZE |
341 wxVSCROLL | wxHSCROLL)
c801d85f 342{
d2824cdb
VZ
343 SetBackgroundColour(wxColour("WHITE"));
344 SetCursor(wxCursor(wxCURSOR_PENCIL));
345
346 SetScrollbars(20, 20, 50, 50);
c52d95b4 347
eb839c84 348 m_dirty = false;
c801d85f
KB
349}
350
351// Define the repainting behaviour
352void MyCanvas::OnDraw(wxDC& dc)
353{
c9f856af
VZ
354 if ( !m_text.empty() )
355 dc.DrawText(m_text, 10, 10);
356
c52d95b4
VZ
357 dc.SetFont(*wxSWISS_FONT);
358 dc.SetPen(*wxGREEN_PEN);
359 dc.DrawLine(0, 0, 200, 200);
360 dc.DrawLine(200, 0, 0, 200);
361
362 dc.SetBrush(*wxCYAN_BRUSH);
363 dc.SetPen(*wxRED_PEN);
364 dc.DrawRectangle(100, 100, 100, 50);
365 dc.DrawRoundedRectangle(150, 150, 100, 50, 20);
366
367 dc.DrawEllipse(250, 250, 100, 50);
c41ea66a 368#if wxUSE_SPLINES
c52d95b4 369 dc.DrawSpline(50, 200, 50, 100, 200, 10);
c41ea66a 370#endif // wxUSE_SPLINES
c52d95b4 371 dc.DrawLine(50, 230, 200, 230);
d2824cdb 372 dc.DrawText("This is a test string", 50, 230);
c52d95b4
VZ
373
374 wxPoint points[3];
375 points[0].x = 200; points[0].y = 300;
376 points[1].x = 100; points[1].y = 400;
377 points[2].x = 300; points[2].y = 400;
378
379 dc.DrawPolygon(3, points);
c801d85f
KB
380}
381
c52d95b4
VZ
382// This implements a tiny doodling program! Drag the mouse using the left
383// button.
c801d85f
KB
384void MyCanvas::OnEvent(wxMouseEvent& event)
385{
c52d95b4
VZ
386 wxClientDC dc(this);
387 PrepareDC(dc);
c801d85f 388
c52d95b4 389 wxPoint pt(event.GetLogicalPosition(dc));
c801d85f 390
d2824cdb
VZ
391 static long xpos = -1;
392 static long ypos = -1;
393
c52d95b4
VZ
394 if (xpos > -1 && ypos > -1 && event.Dragging())
395 {
396 dc.SetPen(*wxBLACK_PEN);
397 dc.DrawLine(xpos, ypos, pt.x, pt.y);
c801d85f 398
eb839c84 399 m_dirty = true;
c52d95b4 400 }
c801d85f 401
c52d95b4
VZ
402 xpos = pt.x;
403 ypos = pt.y;
404}
405
406// ---------------------------------------------------------------------------
407// MyChild
408// ---------------------------------------------------------------------------
409
d2824cdb
VZ
410unsigned MyChild::ms_numChildren = 0;
411
412MyChild::MyChild(wxMDIParentFrame *parent)
413 : wxMDIChildFrame
414 (
415 parent,
416 wxID_ANY,
417 wxString::Format("Child %u", ++ms_numChildren)
418 )
c801d85f 419{
d2824cdb
VZ
420 m_canvas = new MyCanvas(this, wxPoint(0, 0), GetClientSize());
421
422 SetIcon(wxICON(chart));
423
424 const bool canBeResized = !IsAlwaysMaximized();
425
4f7cd56c 426 // create our menu bar: it will be shown instead of the main frame one when
d2824cdb
VZ
427 // we're active
428#if wxUSE_MENUS
4f7cd56c
VZ
429 wxMenuBar *mbar = MyFrame::CreateMainMenubar();
430 mbar->GetMenu(0)->Insert(1, wxID_CLOSE, "&Close child\tCtrl-W",
431 "Close this window");
d2824cdb 432
4f7cd56c 433 wxMenu *menuChild = new wxMenu;
d2824cdb 434
4f7cd56c
VZ
435 menuChild->Append(MDI_REFRESH, "&Refresh picture");
436 menuChild->Append(MDI_CHANGE_TITLE, "Change &title...\tCtrl-T");
d2824cdb
VZ
437 if ( canBeResized )
438 {
4f7cd56c
VZ
439 menuChild->AppendSeparator();
440 menuChild->Append(MDI_CHANGE_POSITION, "Move frame\tCtrl-M");
441 menuChild->Append(MDI_CHANGE_SIZE, "Resize frame\tCtrl-S");
d2824cdb
VZ
442 }
443#if wxUSE_CLIPBOARD
4f7cd56c
VZ
444 menuChild->AppendSeparator();
445 menuChild->Append(wxID_PASTE, "Copy text from clipboard\tCtrl-V");
d2824cdb
VZ
446#endif // wxUSE_CLIPBOARD
447
4f7cd56c 448 mbar->Insert(1, menuChild, "&Child");
d2824cdb
VZ
449
450 // Associate the menu bar with the frame
4f7cd56c 451 SetMenuBar(mbar);
d2824cdb
VZ
452#endif // wxUSE_MENUS
453
454 // this should work for MDI frames as well as for normal ones, provided
455 // they can be resized at all
456 if ( canBeResized )
457 SetSizeHints(100, 100);
396e9eb8
VZ
458
459 // test that event handlers pushed on top of MDI children do work (this
460 // used to be broken, see #11225)
461 PushEventHandler(new EventHandler(ms_numChildren));
c801d85f
KB
462}
463
c52d95b4 464MyChild::~MyChild()
c801d85f 465{
396e9eb8
VZ
466 PopEventHandler(true);
467
d2824cdb 468 ms_numChildren--;
c801d85f
KB
469}
470
d2824cdb 471void MyChild::OnClose(wxCommandEvent& WXUNUSED(event))
c801d85f 472{
eb839c84 473 Close(true);
c52d95b4
VZ
474}
475
f6bcfd97
BP
476void MyChild::OnRefresh(wxCommandEvent& WXUNUSED(event))
477{
d2824cdb
VZ
478 if ( m_canvas )
479 m_canvas->Refresh();
f6bcfd97
BP
480}
481
fa762db4
VZ
482void MyChild::OnChangePosition(wxCommandEvent& WXUNUSED(event))
483{
484 Move(10, 10);
485}
486
487void MyChild::OnChangeSize(wxCommandEvent& WXUNUSED(event))
488{
489 SetClientSize(100, 100);
490}
491
f6bcfd97 492void MyChild::OnChangeTitle(wxCommandEvent& WXUNUSED(event))
c52d95b4 493{
e21d8614 494#if wxUSE_TEXTDLG
d2824cdb 495 static wxString s_title = "Canvas Frame";
f6bcfd97 496
d2824cdb
VZ
497 wxString title = wxGetTextFromUser("Enter the new title for MDI child",
498 "MDI sample question",
f6bcfd97 499 s_title,
fa762db4 500 GetParent()->GetParent());
f6bcfd97
BP
501 if ( !title )
502 return;
503
504 s_title = title;
505 SetTitle(s_title);
e21d8614 506#endif // wxUSE_TEXTDLG
c801d85f
KB
507}
508
509void MyChild::OnActivate(wxActivateEvent& event)
510{
d2824cdb
VZ
511 if ( event.GetActive() && m_canvas )
512 m_canvas->SetFocus();
c801d85f
KB
513}
514
fa762db4
VZ
515void MyChild::OnMove(wxMoveEvent& event)
516{
517 // VZ: here everything is totally wrong under MSW, the positions are
518 // different and both wrong (pos2 is off by 2 pixels for me which seems
519 // to be the width of the MDI canvas border)
520 wxPoint pos1 = event.GetPosition(),
521 pos2 = GetPosition();
d2824cdb 522 wxLogStatus("position from event: (%d, %d), from frame (%d, %d)",
fa762db4
VZ
523 pos1.x, pos1.y, pos2.x, pos2.y);
524
525 event.Skip();
526}
527
528void MyChild::OnSize(wxSizeEvent& event)
529{
530 // VZ: under MSW the size event carries the client size (quite
531 // unexpectedly) *except* for the very first one which has the full
532 // size... what should it really be? TODO: check under wxGTK
533 wxSize size1 = event.GetSize(),
534 size2 = GetSize(),
535 size3 = GetClientSize();
d2824cdb 536 wxLogStatus("size from event: %dx%d, from frame %dx%d, client %dx%d",
fa762db4
VZ
537 size1.x, size1.y, size2.x, size2.y, size3.x, size3.y);
538
539 event.Skip();
540}
541
d2824cdb 542void MyChild::OnCloseWindow(wxCloseEvent& event)
c801d85f 543{
d2824cdb 544 if ( m_canvas && m_canvas->IsDirty() )
c52d95b4 545 {
d2824cdb 546 if ( wxMessageBox("Really close?", "Please confirm",
c52d95b4
VZ
547 wxICON_QUESTION | wxYES_NO) != wxYES )
548 {
549 event.Veto();
c801d85f 550
c52d95b4
VZ
551 return;
552 }
553 }
c801d85f 554
c52d95b4 555 event.Skip();
c801d85f 556}
c9f856af
VZ
557
558#if wxUSE_CLIPBOARD
559
560#include "wx/clipbrd.h"
561
562void MyChild::OnPaste(wxCommandEvent& WXUNUSED(event))
563{
564 wxClipboardLocker lock;
565 wxTextDataObject data;
d2824cdb
VZ
566 m_canvas->SetText(wxTheClipboard->GetData(data)
567 ? data.GetText()
568 : wxString("No text on clipboard"));
c9f856af
VZ
569}
570
571void MyChild::OnUpdatePaste(wxUpdateUIEvent& event)
572{
573 wxClipboardLocker lock;
574 event.Enable( wxTheClipboard->IsSupported(wxDF_TEXT) );
575}
576
577#endif // wxUSE_CLIPBOARD