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