wxAuiMDI* now more accurately respects normal mdi event sequence
[wxWidgets.git] / src / aui / tabmdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/aui/tabmdi.cpp
3 // Purpose: Generic MDI (Multiple Document Interface) classes
4 // Author: Hans Van Leemputten
5 // Modified by: Benjamin I. Williams / Kirix Corporation
6 // Created: 29/07/2002
7 // RCS-ID: $Id$
8 // Copyright: (c) Hans Van Leemputten
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_AUI
28 #if wxUSE_MDI
29
30 #include "wx/aui/tabmdi.h"
31
32 #ifndef WX_PRECOMP
33 #include "wx/panel.h"
34 #include "wx/menu.h"
35 #include "wx/intl.h"
36 #include "wx/log.h"
37 #include "wx/settings.h"
38 #endif //WX_PRECOMP
39
40 #include "wx/stockitem.h"
41
42 enum MDI_MENU_ID
43 {
44 wxWINDOWCLOSE = 4001,
45 wxWINDOWCLOSEALL,
46 wxWINDOWNEXT,
47 wxWINDOWPREV
48 };
49
50 //-----------------------------------------------------------------------------
51 // wxAuiMDIParentFrame
52 //-----------------------------------------------------------------------------
53
54 IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIParentFrame, wxFrame)
55
56 BEGIN_EVENT_TABLE(wxAuiMDIParentFrame, wxFrame)
57 #if wxUSE_MENUS
58 EVT_MENU (wxID_ANY, wxAuiMDIParentFrame::DoHandleMenu)
59 #endif
60 END_EVENT_TABLE()
61
62 wxAuiMDIParentFrame::wxAuiMDIParentFrame()
63 {
64 Init();
65 }
66
67 wxAuiMDIParentFrame::wxAuiMDIParentFrame(wxWindow *parent,
68 wxWindowID id,
69 const wxString& title,
70 const wxPoint& pos,
71 const wxSize& size,
72 long style,
73 const wxString& name)
74 {
75 Init();
76 (void)Create(parent, id, title, pos, size, style, name);
77 }
78
79 wxAuiMDIParentFrame::~wxAuiMDIParentFrame()
80 {
81 // Make sure the client window is destructed before the menu bars are!
82 wxDELETE(m_pClientWindow);
83
84 #if wxUSE_MENUS
85 RemoveWindowMenu(GetMenuBar());
86 delete m_pWindowMenu;
87 #endif // wxUSE_MENUS
88 }
89
90 bool wxAuiMDIParentFrame::Create(wxWindow *parent,
91 wxWindowID id,
92 const wxString& title,
93 const wxPoint& pos,
94 const wxSize& size,
95 long style,
96 const wxString& name)
97 {
98 #if wxUSE_MENUS
99 // this style can be used to prevent a window from having the standard MDI
100 // "Window" menu
101 if (!(style & wxFRAME_NO_WINDOW_MENU))
102 {
103 m_pWindowMenu = new wxMenu;
104 m_pWindowMenu->Append(wxWINDOWCLOSE, _("Cl&ose"));
105 m_pWindowMenu->Append(wxWINDOWCLOSEALL, _("Close All"));
106 m_pWindowMenu->AppendSeparator();
107 m_pWindowMenu->Append(wxWINDOWNEXT, _("&Next"));
108 m_pWindowMenu->Append(wxWINDOWPREV, _("&Previous"));
109 }
110 #endif // wxUSE_MENUS
111
112 wxFrame::Create(parent, id, title, pos, size, style, name);
113 OnCreateClient();
114 return true;
115 }
116
117
118 void wxAuiMDIParentFrame::SetArtProvider(wxAuiTabArt* provider)
119 {
120 if (m_pClientWindow)
121 {
122 m_pClientWindow->SetArtProvider(provider);
123 }
124 }
125
126 wxAuiTabArt* wxAuiMDIParentFrame::GetArtProvider()
127 {
128 if (!m_pClientWindow)
129 return NULL;
130
131 return m_pClientWindow->GetArtProvider();
132 }
133
134 wxAuiNotebook* wxAuiMDIParentFrame::GetNotebook() const
135 {
136 return static_cast<wxAuiNotebook*>(m_pClientWindow);
137 }
138
139
140
141 #if wxUSE_MENUS
142 void wxAuiMDIParentFrame::SetWindowMenu(wxMenu* pMenu)
143 {
144 // Replace the window menu from the currently loaded menu bar.
145 wxMenuBar *pMenuBar = GetMenuBar();
146
147 if (m_pWindowMenu)
148 {
149 RemoveWindowMenu(pMenuBar);
150 wxDELETE(m_pWindowMenu);
151 }
152
153 if (pMenu)
154 {
155 m_pWindowMenu = pMenu;
156 AddWindowMenu(pMenuBar);
157 }
158 }
159
160 void wxAuiMDIParentFrame::SetMenuBar(wxMenuBar* pMenuBar)
161 {
162 // Remove the Window menu from the old menu bar
163 RemoveWindowMenu(GetMenuBar());
164
165 // Add the Window menu to the new menu bar.
166 AddWindowMenu(pMenuBar);
167
168 wxFrame::SetMenuBar(pMenuBar);
169 m_pMyMenuBar = GetMenuBar();
170 }
171 #endif // wxUSE_MENUS
172
173 void wxAuiMDIParentFrame::SetChildMenuBar(wxAuiMDIChildFrame* pChild)
174 {
175 #if wxUSE_MENUS
176 if (!pChild)
177 {
178 // No Child, set Our menu bar back.
179 SetMenuBar(m_pMyMenuBar);
180
181 // Make sure we know our menu bar is in use
182 //m_pMyMenuBar = NULL;
183 }
184 else
185 {
186 if (pChild->GetMenuBar() == NULL)
187 return;
188
189 // Do we need to save the current bar?
190 if (m_pMyMenuBar == NULL)
191 m_pMyMenuBar = GetMenuBar();
192
193 SetMenuBar(pChild->GetMenuBar());
194 }
195 #endif // wxUSE_MENUS
196 }
197
198 bool wxAuiMDIParentFrame::ProcessEvent(wxEvent& event)
199 {
200 // stops the same event being processed repeatedly
201 if (m_pLastEvt == &event)
202 return false;
203 m_pLastEvt = &event;
204
205 // let the active child (if any) process the event first.
206 bool res = false;
207 if (m_pActiveChild &&
208 event.IsCommandEvent() &&
209 event.GetEventObject() != m_pClientWindow &&
210 !(event.GetEventType() == wxEVT_ACTIVATE ||
211 event.GetEventType() == wxEVT_SET_FOCUS ||
212 event.GetEventType() == wxEVT_KILL_FOCUS ||
213 event.GetEventType() == wxEVT_CHILD_FOCUS ||
214 event.GetEventType() == wxEVT_COMMAND_SET_FOCUS ||
215 event.GetEventType() == wxEVT_COMMAND_KILL_FOCUS )
216 )
217 {
218 res = m_pActiveChild->GetEventHandler()->ProcessEvent(event);
219 }
220
221 if (!res)
222 {
223 // if the event was not handled this frame will handle it,
224 // which is why we need the protection code at the beginning
225 // of this method
226 res = wxEvtHandler::ProcessEvent(event);
227 }
228
229 m_pLastEvt = NULL;
230
231 return res;
232 }
233
234 wxAuiMDIChildFrame *wxAuiMDIParentFrame::GetActiveChild() const
235 {
236 return m_pActiveChild;
237 }
238
239 void wxAuiMDIParentFrame::SetActiveChild(wxAuiMDIChildFrame* pChildFrame)
240 {
241 m_pActiveChild = pChildFrame;
242 }
243
244 wxAuiMDIClientWindow *wxAuiMDIParentFrame::GetClientWindow() const
245 {
246 return m_pClientWindow;
247 }
248
249 wxAuiMDIClientWindow *wxAuiMDIParentFrame::OnCreateClient()
250 {
251 m_pClientWindow = new wxAuiMDIClientWindow( this );
252 return m_pClientWindow;
253 }
254
255 void wxAuiMDIParentFrame::ActivateNext()
256 {
257 if (m_pClientWindow && m_pClientWindow->GetSelection() != wxNOT_FOUND)
258 {
259 size_t active = m_pClientWindow->GetSelection() + 1;
260 if (active >= m_pClientWindow->GetPageCount())
261 active = 0;
262
263 m_pClientWindow->SetSelection(active);
264 }
265 }
266
267 void wxAuiMDIParentFrame::ActivatePrevious()
268 {
269 if (m_pClientWindow && m_pClientWindow->GetSelection() != wxNOT_FOUND)
270 {
271 int active = m_pClientWindow->GetSelection() - 1;
272 if (active < 0)
273 active = m_pClientWindow->GetPageCount() - 1;
274
275 m_pClientWindow->SetSelection(active);
276 }
277 }
278
279 void wxAuiMDIParentFrame::Init()
280 {
281 m_pLastEvt = NULL;
282 m_pClientWindow = NULL;
283 m_pActiveChild = NULL;
284 #if wxUSE_MENUS
285 m_pWindowMenu = NULL;
286 m_pMyMenuBar = NULL;
287 #endif // wxUSE_MENUS
288 }
289
290 #if wxUSE_MENUS
291 void wxAuiMDIParentFrame::RemoveWindowMenu(wxMenuBar* pMenuBar)
292 {
293 if (pMenuBar && m_pWindowMenu)
294 {
295 // Remove old window menu
296 int pos = pMenuBar->FindMenu(_("&Window"));
297 if (pos != wxNOT_FOUND)
298 {
299 // DBG:: We're going to delete the wrong menu!!!
300 wxASSERT(m_pWindowMenu == pMenuBar->GetMenu(pos));
301 pMenuBar->Remove(pos);
302 }
303 }
304 }
305
306 void wxAuiMDIParentFrame::AddWindowMenu(wxMenuBar *pMenuBar)
307 {
308 if (pMenuBar && m_pWindowMenu)
309 {
310 int pos = pMenuBar->FindMenu(wxGetStockLabel(wxID_HELP,wxSTOCK_NOFLAGS));
311 if (pos == wxNOT_FOUND)
312 pMenuBar->Append(m_pWindowMenu, _("&Window"));
313 else
314 pMenuBar->Insert(pos, m_pWindowMenu, _("&Window"));
315 }
316 }
317
318 void wxAuiMDIParentFrame::DoHandleMenu(wxCommandEvent& event)
319 {
320 switch (event.GetId())
321 {
322 case wxWINDOWCLOSE:
323 if (m_pActiveChild)
324 m_pActiveChild->Close();
325 break;
326 case wxWINDOWCLOSEALL:
327 while (m_pActiveChild)
328 {
329 if (!m_pActiveChild->Close())
330 {
331 return; // failure
332 }
333 else
334 {
335 delete m_pActiveChild;
336 m_pActiveChild = NULL;
337 }
338 }
339 break;
340 case wxWINDOWNEXT:
341 ActivateNext();
342 break;
343 case wxWINDOWPREV:
344 ActivatePrevious();
345 break;
346 default:
347 event.Skip();
348 }
349 }
350 #endif // wxUSE_MENUS
351
352 void wxAuiMDIParentFrame::DoGetClientSize(int* width, int* height) const
353 {
354 wxFrame::DoGetClientSize(width, height);
355 }
356
357 //-----------------------------------------------------------------------------
358 // wxAuiMDIChildFrame
359 //-----------------------------------------------------------------------------
360
361 IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIChildFrame, wxPanel)
362
363 BEGIN_EVENT_TABLE(wxAuiMDIChildFrame, wxPanel)
364 EVT_MENU_HIGHLIGHT_ALL(wxAuiMDIChildFrame::OnMenuHighlight)
365 EVT_ACTIVATE(wxAuiMDIChildFrame::OnActivate)
366 EVT_CLOSE(wxAuiMDIChildFrame::OnCloseWindow)
367 END_EVENT_TABLE()
368
369 wxAuiMDIChildFrame::wxAuiMDIChildFrame()
370 {
371 Init();
372 }
373
374 wxAuiMDIChildFrame::wxAuiMDIChildFrame(wxAuiMDIParentFrame *parent,
375 wxWindowID id,
376 const wxString& title,
377 const wxPoint& WXUNUSED(pos),
378 const wxSize& size,
379 long style,
380 const wxString& name)
381 {
382 Init();
383 Create(parent, id, title, wxDefaultPosition, size, style, name);
384 }
385
386 wxAuiMDIChildFrame::~wxAuiMDIChildFrame()
387 {
388 #if wxUSE_MENUS
389 wxDELETE(m_pMenuBar);
390 #endif // wxUSE_MENUS
391 }
392
393 bool wxAuiMDIChildFrame::Create(wxAuiMDIParentFrame* parent,
394 wxWindowID id,
395 const wxString& title,
396 const wxPoint& WXUNUSED(pos),
397 const wxSize& size,
398 long style,
399 const wxString& name)
400 {
401 wxAuiMDIClientWindow* pClientWindow = parent->GetClientWindow();
402 wxASSERT_MSG((pClientWindow != (wxWindow*) NULL), wxT("Missing MDI client window."));
403
404 wxSize cli_size = pClientWindow->GetClientSize();
405
406 // create the window off-screen to prevent flicker
407 wxPanel::Create(pClientWindow,
408 id,
409 wxPoint(cli_size.x+1, cli_size.y+1),
410 size,
411 style|wxNO_BORDER, name);
412
413 SetMDIParentFrame(parent);
414
415 // this is the currently active child
416 parent->SetActiveChild(this);
417
418 m_title = title;
419
420 pClientWindow->AddPage(this, title, true);
421 pClientWindow->Refresh();
422
423 return true;
424 }
425
426 bool wxAuiMDIChildFrame::Destroy()
427 {
428 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
429 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
430
431 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
432 wxASSERT_MSG(pClientWindow, wxT("Missing MDI Client Window"));
433
434 if (pParentFrame->GetActiveChild() == this)
435 {
436 // deactivate ourself
437 wxActivateEvent event(wxEVT_ACTIVATE, false, GetId());
438 event.SetEventObject(this);
439 GetEventHandler()->ProcessEvent(event);
440
441 pParentFrame->SetActiveChild(NULL);
442 pParentFrame->SetChildMenuBar(NULL);
443 }
444
445 size_t page_count = pClientWindow->GetPageCount();
446 for (size_t pos = 0; pos < page_count; pos++)
447 {
448 if (pClientWindow->GetPage(pos) == this)
449 return pClientWindow->DeletePage(pos);
450 }
451
452 return false;
453 }
454
455 #if wxUSE_MENUS
456 void wxAuiMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
457 {
458 wxMenuBar *pOldMenuBar = m_pMenuBar;
459 m_pMenuBar = menu_bar;
460
461 if (m_pMenuBar)
462 {
463 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
464 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
465
466 m_pMenuBar->SetParent(pParentFrame);
467 if (pParentFrame->GetActiveChild() == this)
468 {
469 // replace current menu bars
470 if (pOldMenuBar)
471 pParentFrame->SetChildMenuBar(NULL);
472 pParentFrame->SetChildMenuBar(this);
473 }
474 }
475 }
476
477 wxMenuBar *wxAuiMDIChildFrame::GetMenuBar() const
478 {
479 return m_pMenuBar;
480 }
481 #endif // wxUSE_MENUS
482
483 void wxAuiMDIChildFrame::SetTitle(const wxString& title)
484 {
485 m_title = title;
486
487 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
488 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
489
490 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
491 if (pClientWindow != NULL)
492 {
493 size_t pos;
494 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
495 {
496 if (pClientWindow->GetPage(pos) == this)
497 {
498 pClientWindow->SetPageText(pos, m_title);
499 break;
500 }
501 }
502 }
503 }
504
505 wxString wxAuiMDIChildFrame::GetTitle() const
506 {
507 return m_title;
508 }
509
510 void wxAuiMDIChildFrame::SetIcons(const wxIconBundle& icons)
511 {
512 // get icon with the system icon size
513 SetIcon(icons.GetIcon(-1));
514 m_icon_bundle = icons;
515 }
516
517 const wxIconBundle& wxAuiMDIChildFrame::GetIcons() const
518 {
519 return m_icon_bundle;
520 }
521
522 void wxAuiMDIChildFrame::SetIcon(const wxIcon& icon)
523 {
524 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
525 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
526
527 m_icon = icon;
528
529 wxBitmap bmp;
530 bmp.CopyFromIcon(m_icon);
531
532 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
533 if (pClientWindow != NULL)
534 {
535 int idx = pClientWindow->GetPageIndex(this);
536
537 if (idx != -1)
538 {
539 pClientWindow->SetPageBitmap((size_t)idx, bmp);
540 }
541 }
542 }
543
544 const wxIcon& wxAuiMDIChildFrame::GetIcon() const
545 {
546 return m_icon;
547 }
548
549
550 void wxAuiMDIChildFrame::Activate()
551 {
552 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
553 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
554
555 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
556
557 if (pClientWindow != NULL)
558 {
559 size_t pos;
560 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
561 {
562 if (pClientWindow->GetPage(pos) == this)
563 {
564 pClientWindow->SetSelection(pos);
565 break;
566 }
567 }
568 }
569 }
570
571 void wxAuiMDIChildFrame::OnMenuHighlight(wxMenuEvent& event)
572 {
573 #if wxUSE_STATUSBAR
574 if (m_pMDIParentFrame)
575 {
576 // we don't have any help text for this item,
577 // but may be the MDI frame does?
578 m_pMDIParentFrame->OnMenuHighlight(event);
579 }
580 #else
581 wxUnusedVar(event);
582 #endif // wxUSE_STATUSBAR
583 }
584
585 void wxAuiMDIChildFrame::OnActivate(wxActivateEvent& WXUNUSED(event))
586 {
587 // do nothing
588 }
589
590 void wxAuiMDIChildFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
591 {
592 Destroy();
593 }
594
595 void wxAuiMDIChildFrame::SetMDIParentFrame(wxAuiMDIParentFrame* parentFrame)
596 {
597 m_pMDIParentFrame = parentFrame;
598 }
599
600 wxAuiMDIParentFrame* wxAuiMDIChildFrame::GetMDIParentFrame() const
601 {
602 return m_pMDIParentFrame;
603 }
604
605 void wxAuiMDIChildFrame::Init()
606 {
607 m_pMDIParentFrame = NULL;
608 #if wxUSE_MENUS
609 m_pMenuBar = NULL;
610 #endif // wxUSE_MENUS
611 }
612
613 bool wxAuiMDIChildFrame::Show(bool WXUNUSED(show))
614 {
615 // do nothing
616 return true;
617 }
618
619 void wxAuiMDIChildFrame::DoShow(bool show)
620 {
621 wxWindow::Show(show);
622 }
623
624 void wxAuiMDIChildFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags)
625 {
626 m_mdi_newrect = wxRect(x, y, width, height);
627 #ifdef __WXGTK__
628 wxPanel::DoSetSize(x,y,width, height, sizeFlags);
629 #else
630 wxUnusedVar(sizeFlags);
631 #endif
632 }
633
634 void wxAuiMDIChildFrame::DoMoveWindow(int x, int y, int width, int height)
635 {
636 m_mdi_newrect = wxRect(x, y, width, height);
637 }
638
639 void wxAuiMDIChildFrame::ApplyMDIChildFrameRect()
640 {
641 if (m_mdi_currect != m_mdi_newrect)
642 {
643 wxPanel::DoMoveWindow(m_mdi_newrect.x, m_mdi_newrect.y,
644 m_mdi_newrect.width, m_mdi_newrect.height);
645 m_mdi_currect = m_mdi_newrect;
646 }
647 }
648
649
650 //-----------------------------------------------------------------------------
651 // wxAuiMDIClientWindow
652 //-----------------------------------------------------------------------------
653
654 IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIClientWindow, wxAuiNotebook)
655
656 BEGIN_EVENT_TABLE(wxAuiMDIClientWindow, wxAuiNotebook)
657 EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, wxAuiMDIClientWindow::OnPageChanged)
658 EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, wxAuiMDIClientWindow::OnPageClose)
659 EVT_SIZE(wxAuiMDIClientWindow::OnSize)
660 END_EVENT_TABLE()
661
662 wxAuiMDIClientWindow::wxAuiMDIClientWindow()
663 {
664 }
665
666 wxAuiMDIClientWindow::wxAuiMDIClientWindow(wxAuiMDIParentFrame* parent, long style)
667 {
668 CreateClient(parent, style);
669 }
670
671 wxAuiMDIClientWindow::~wxAuiMDIClientWindow()
672 {
673 DestroyChildren();
674 }
675
676 bool wxAuiMDIClientWindow::CreateClient(wxAuiMDIParentFrame* parent, long style)
677 {
678 SetWindowStyleFlag(style);
679
680 if (!wxAuiNotebook::Create(parent,
681 wxID_ANY,
682 wxPoint(0,0),
683 wxSize(100, 100),
684 wxAUI_NB_DEFAULT_STYLE | wxNO_BORDER))
685 {
686 return false;
687 }
688
689 wxColour bkcolour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
690 SetBackgroundColour(bkcolour);
691
692 m_mgr.GetArtProvider()->SetColour(wxAUI_ART_BACKGROUND_COLOUR, bkcolour);
693
694 return true;
695 }
696
697 int wxAuiMDIClientWindow::SetSelection(size_t nPage)
698 {
699 return wxAuiNotebook::SetSelection(nPage);
700 }
701
702 void wxAuiMDIClientWindow::PageChanged(int old_selection, int new_selection)
703 {
704 // don't do anything if the page doesn't actually change
705 if (old_selection == new_selection)
706 return;
707
708 /*
709 // don't do anything if the new page is already active
710 if (new_selection != -1)
711 {
712 wxAuiMDIChildFrame* child = (wxAuiMDIChildFrame*)GetPage(new_selection);
713 if (child->GetMDIParentFrame()->GetActiveChild() == child)
714 return;
715 }*/
716
717
718 // notify old active child that it has been deactivated
719 if (old_selection != -1)
720 {
721 wxAuiMDIChildFrame* old_child = (wxAuiMDIChildFrame*)GetPage(old_selection);
722 wxASSERT_MSG(old_child, wxT("wxAuiMDIClientWindow::PageChanged - null page pointer"));
723
724 wxActivateEvent event(wxEVT_ACTIVATE, false, old_child->GetId());
725 event.SetEventObject(old_child);
726 old_child->GetEventHandler()->ProcessEvent(event);
727 }
728
729 // notify new active child that it has been activated
730 if (new_selection != -1)
731 {
732 wxAuiMDIChildFrame* active_child = (wxAuiMDIChildFrame*)GetPage(new_selection);
733 wxASSERT_MSG(active_child, wxT("wxAuiMDIClientWindow::PageChanged - null page pointer"));
734
735 wxActivateEvent event(wxEVT_ACTIVATE, true, active_child->GetId());
736 event.SetEventObject(active_child);
737 active_child->GetEventHandler()->ProcessEvent(event);
738
739 if (active_child->GetMDIParentFrame())
740 {
741 active_child->GetMDIParentFrame()->SetActiveChild(active_child);
742 active_child->GetMDIParentFrame()->SetChildMenuBar(active_child);
743 }
744 }
745
746
747 }
748
749 void wxAuiMDIClientWindow::OnPageClose(wxAuiNotebookEvent& evt)
750 {
751 wxAuiMDIChildFrame* wnd;
752 wnd = static_cast<wxAuiMDIChildFrame*>(GetPage(evt.GetSelection()));
753
754 wnd->Close();
755
756 // regardless of the result of wnd->Close(), we've
757 // already taken care of the close operations, so
758 // suppress further processing
759 evt.Veto();
760 }
761
762 void wxAuiMDIClientWindow::OnPageChanged(wxAuiNotebookEvent& evt)
763 {
764 PageChanged(evt.GetOldSelection(), evt.GetSelection());
765 }
766
767 void wxAuiMDIClientWindow::OnSize(wxSizeEvent& evt)
768 {
769 wxAuiNotebook::OnSize(evt);
770
771 for (size_t pos = 0; pos < GetPageCount(); pos++)
772 ((wxAuiMDIChildFrame *)GetPage(pos))->ApplyMDIChildFrameRect();
773 }
774
775 #endif //wxUSE_AUI
776 #endif // wxUSE_MDI