]> git.saurik.com Git - wxWidgets.git/blame - src/aui/tabmdi.cpp
add -mno-cygwin detection: we should treat cygwin as Windows, not Unix, when it's...
[wxWidgets.git] / src / aui / tabmdi.cpp
CommitLineData
cd05bf23 1/////////////////////////////////////////////////////////////////////////////
25f70bc4 2// Name: src/aui/tabmdi.cpp
cd05bf23
BW
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
25f70bc4 27#if wxUSE_AUI
cd05bf23
BW
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"
4444d148 37 #include "wx/settings.h"
cd05bf23
BW
38#endif //WX_PRECOMP
39
40#include "wx/stockitem.h"
41
42enum MDI_MENU_ID
43{
44 wxWINDOWCLOSE = 4001,
45 wxWINDOWCLOSEALL,
46 wxWINDOWNEXT,
47 wxWINDOWPREV
48};
49
50//-----------------------------------------------------------------------------
a3a5df9d 51// wxAuiMDIParentFrame
cd05bf23
BW
52//-----------------------------------------------------------------------------
53
a3a5df9d 54IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIParentFrame, wxFrame)
cd05bf23 55
a3a5df9d 56BEGIN_EVENT_TABLE(wxAuiMDIParentFrame, wxFrame)
cd05bf23 57#if wxUSE_MENUS
a3a5df9d 58 EVT_MENU (wxID_ANY, wxAuiMDIParentFrame::DoHandleMenu)
cd05bf23
BW
59#endif
60END_EVENT_TABLE()
61
a3a5df9d 62wxAuiMDIParentFrame::wxAuiMDIParentFrame()
cd05bf23
BW
63{
64 Init();
65}
66
a3a5df9d 67wxAuiMDIParentFrame::wxAuiMDIParentFrame(wxWindow *parent,
cd05bf23
BW
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
a3a5df9d 79wxAuiMDIParentFrame::~wxAuiMDIParentFrame()
cd05bf23
BW
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
a3a5df9d 90bool wxAuiMDIParentFrame::Create(wxWindow *parent,
cd05bf23
BW
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#if wxUSE_MENUS
a3a5df9d 118void wxAuiMDIParentFrame::SetWindowMenu(wxMenu* pMenu)
cd05bf23
BW
119{
120 // Replace the window menu from the currently loaded menu bar.
121 wxMenuBar *pMenuBar = GetMenuBar();
122
123 if (m_pWindowMenu)
124 {
125 RemoveWindowMenu(pMenuBar);
126 wxDELETE(m_pWindowMenu);
127 }
128
129 if (pMenu)
130 {
131 m_pWindowMenu = pMenu;
132 AddWindowMenu(pMenuBar);
133 }
134}
135
a3a5df9d 136void wxAuiMDIParentFrame::SetMenuBar(wxMenuBar* pMenuBar)
cd05bf23
BW
137{
138 // Remove the Window menu from the old menu bar
139 RemoveWindowMenu(GetMenuBar());
4444d148 140
cd05bf23
BW
141 // Add the Window menu to the new menu bar.
142 AddWindowMenu(pMenuBar);
4444d148 143
cd05bf23
BW
144 wxFrame::SetMenuBar(pMenuBar);
145 m_pMyMenuBar = GetMenuBar();
146}
147#endif // wxUSE_MENUS
148
a3a5df9d 149void wxAuiMDIParentFrame::SetChildMenuBar(wxAuiMDIChildFrame* pChild)
cd05bf23
BW
150{
151#if wxUSE_MENUS
152 if (!pChild)
153 {
154 // No Child, set Our menu bar back.
155 SetMenuBar(m_pMyMenuBar);
156
157 // Make sure we know our menu bar is in use
82dc21d3 158 //m_pMyMenuBar = NULL;
cd05bf23
BW
159 }
160 else
161 {
162 if (pChild->GetMenuBar() == NULL)
163 return;
ee0a94cf 164
cd05bf23
BW
165 // Do we need to save the current bar?
166 if (m_pMyMenuBar == NULL)
167 m_pMyMenuBar = GetMenuBar();
168
169 SetMenuBar(pChild->GetMenuBar());
170 }
171#endif // wxUSE_MENUS
172}
173
a3a5df9d 174bool wxAuiMDIParentFrame::ProcessEvent(wxEvent& event)
cd05bf23
BW
175{
176 // Stops the same event being processed repeatedly
177 static wxEventType inEvent = wxEVT_NULL;
178 if (inEvent == event.GetEventType())
179 return false;
180
181 inEvent = event.GetEventType();
182
183 // Let the active child (if any) process the event first.
184 bool res = false;
185 if (m_pActiveChild &&
186 event.IsCommandEvent() &&
187 event.GetEventObject() != m_pClientWindow &&
188 !(event.GetEventType() == wxEVT_ACTIVATE ||
189 event.GetEventType() == wxEVT_SET_FOCUS ||
190 event.GetEventType() == wxEVT_KILL_FOCUS ||
191 event.GetEventType() == wxEVT_CHILD_FOCUS ||
192 event.GetEventType() == wxEVT_COMMAND_SET_FOCUS ||
193 event.GetEventType() == wxEVT_COMMAND_KILL_FOCUS )
194 )
195 {
196 res = m_pActiveChild->GetEventHandler()->ProcessEvent(event);
197 }
198
199 // If the event was not handled this frame will handle it!
200 if (!res)
201 {
202 //res = GetEventHandler()->ProcessEvent(event);
203 res = wxEvtHandler::ProcessEvent(event);
204 }
205
206 inEvent = wxEVT_NULL;
207
208 return res;
209}
210
a3a5df9d 211wxAuiMDIChildFrame *wxAuiMDIParentFrame::GetActiveChild() const
cd05bf23
BW
212{
213 return m_pActiveChild;
214}
215
a3a5df9d 216void wxAuiMDIParentFrame::SetActiveChild(wxAuiMDIChildFrame* pChildFrame)
cd05bf23
BW
217{
218 m_pActiveChild = pChildFrame;
219}
220
8856768e 221wxAuiMDIClientWindow *wxAuiMDIParentFrame::GetClientWindow() const
cd05bf23
BW
222{
223 return m_pClientWindow;
224}
225
8856768e 226wxAuiMDIClientWindow *wxAuiMDIParentFrame::OnCreateClient()
cd05bf23 227{
8856768e 228 m_pClientWindow = new wxAuiMDIClientWindow( this );
cd05bf23
BW
229 return m_pClientWindow;
230}
231
a3a5df9d 232void wxAuiMDIParentFrame::ActivateNext()
cd05bf23 233{
4444d148 234 if (m_pClientWindow && m_pClientWindow->GetSelection() != wxNOT_FOUND)
cd05bf23
BW
235 {
236 size_t active = m_pClientWindow->GetSelection() + 1;
237 if (active >= m_pClientWindow->GetPageCount())
238 active = 0;
239
240 m_pClientWindow->SetSelection(active);
241 }
242}
243
a3a5df9d 244void wxAuiMDIParentFrame::ActivatePrevious()
cd05bf23 245{
4444d148 246 if (m_pClientWindow && m_pClientWindow->GetSelection() != wxNOT_FOUND)
cd05bf23
BW
247 {
248 int active = m_pClientWindow->GetSelection() - 1;
249 if (active < 0)
250 active = m_pClientWindow->GetPageCount() - 1;
251
252 m_pClientWindow->SetSelection(active);
253 }
254}
255
a3a5df9d 256void wxAuiMDIParentFrame::Init()
cd05bf23
BW
257{
258 m_pClientWindow = NULL;
259 m_pActiveChild = NULL;
260#if wxUSE_MENUS
261 m_pWindowMenu = NULL;
262 m_pMyMenuBar = NULL;
263#endif // wxUSE_MENUS
264}
265
266#if wxUSE_MENUS
a3a5df9d 267void wxAuiMDIParentFrame::RemoveWindowMenu(wxMenuBar* pMenuBar)
cd05bf23
BW
268{
269 if (pMenuBar && m_pWindowMenu)
270 {
271 // Remove old window menu
272 int pos = pMenuBar->FindMenu(_("&Window"));
273 if (pos != wxNOT_FOUND)
274 {
275 // DBG:: We're going to delete the wrong menu!!!
276 wxASSERT(m_pWindowMenu == pMenuBar->GetMenu(pos));
277 pMenuBar->Remove(pos);
278 }
279 }
280}
281
a3a5df9d 282void wxAuiMDIParentFrame::AddWindowMenu(wxMenuBar *pMenuBar)
cd05bf23
BW
283{
284 if (pMenuBar && m_pWindowMenu)
285 {
ee0a94cf 286 int pos = pMenuBar->FindMenu(wxGetStockLabel(wxID_HELP,wxSTOCK_NOFLAGS));
cd05bf23
BW
287 if (pos == wxNOT_FOUND)
288 pMenuBar->Append(m_pWindowMenu, _("&Window"));
289 else
290 pMenuBar->Insert(pos, m_pWindowMenu, _("&Window"));
291 }
292}
293
a3a5df9d 294void wxAuiMDIParentFrame::DoHandleMenu(wxCommandEvent& event)
cd05bf23
BW
295{
296 switch (event.GetId())
297 {
298 case wxWINDOWCLOSE:
299 if (m_pActiveChild)
300 m_pActiveChild->Close();
301 break;
302 case wxWINDOWCLOSEALL:
303 while (m_pActiveChild)
304 {
305 if (!m_pActiveChild->Close())
306 {
307 return; // failure
308 }
309 else
310 {
311 delete m_pActiveChild;
312 m_pActiveChild = NULL;
313 }
314 }
315 break;
316 case wxWINDOWNEXT:
317 ActivateNext();
318 break;
319 case wxWINDOWPREV:
320 ActivatePrevious();
321 break;
322 default:
323 event.Skip();
324 }
325}
326#endif // wxUSE_MENUS
327
a3a5df9d 328void wxAuiMDIParentFrame::DoGetClientSize(int* width, int* height) const
cd05bf23
BW
329{
330 wxFrame::DoGetClientSize(width, height);
331}
332
333//-----------------------------------------------------------------------------
a3a5df9d 334// wxAuiMDIChildFrame
cd05bf23
BW
335//-----------------------------------------------------------------------------
336
a3a5df9d 337IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIChildFrame, wxPanel)
cd05bf23 338
a3a5df9d
BW
339BEGIN_EVENT_TABLE(wxAuiMDIChildFrame, wxPanel)
340 EVT_MENU_HIGHLIGHT_ALL(wxAuiMDIChildFrame::OnMenuHighlight)
341 EVT_ACTIVATE(wxAuiMDIChildFrame::OnActivate)
342 EVT_CLOSE(wxAuiMDIChildFrame::OnCloseWindow)
cd05bf23
BW
343END_EVENT_TABLE()
344
a3a5df9d 345wxAuiMDIChildFrame::wxAuiMDIChildFrame()
cd05bf23
BW
346{
347 Init();
348}
349
a3a5df9d 350wxAuiMDIChildFrame::wxAuiMDIChildFrame(wxAuiMDIParentFrame *parent,
cd05bf23
BW
351 wxWindowID id,
352 const wxString& title,
353 const wxPoint& WXUNUSED(pos),
354 const wxSize& size,
355 long style,
356 const wxString& name)
357{
358 Init();
359 Create(parent, id, title, wxDefaultPosition, size, style, name);
360}
361
a3a5df9d 362wxAuiMDIChildFrame::~wxAuiMDIChildFrame()
cd05bf23
BW
363{
364#if wxUSE_MENUS
365 wxDELETE(m_pMenuBar);
366#endif // wxUSE_MENUS
367}
368
a3a5df9d 369bool wxAuiMDIChildFrame::Create(wxAuiMDIParentFrame* parent,
cd05bf23
BW
370 wxWindowID id,
371 const wxString& title,
372 const wxPoint& WXUNUSED(pos),
373 const wxSize& size,
374 long style,
375 const wxString& name)
376{
8856768e 377 wxAuiMDIClientWindow* pClientWindow = parent->GetClientWindow();
cd05bf23
BW
378 wxASSERT_MSG((pClientWindow != (wxWindow*) NULL), wxT("Missing MDI client window."));
379
380 wxPanel::Create(pClientWindow, id, wxDefaultPosition, size, style|wxNO_BORDER, name);
381
382 SetMDIParentFrame(parent);
383
384 // this is the currently active child
385 parent->SetActiveChild(this);
386
387 m_title = title;
388
389 pClientWindow->AddPage(this, title, true);
390 pClientWindow->Refresh();
391
392 return true;
393}
394
a3a5df9d 395bool wxAuiMDIChildFrame::Destroy()
cd05bf23 396{
a3a5df9d 397 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
cd05bf23 398 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
4444d148 399
8856768e 400 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
cd05bf23 401 wxASSERT_MSG(pClientWindow, wxT("Missing MDI Client Window"));
4444d148 402
cd05bf23
BW
403 if (pParentFrame->GetActiveChild() == this)
404 {
405 pParentFrame->SetActiveChild(NULL);
406 pParentFrame->SetChildMenuBar(NULL);
cd05bf23 407 }
4444d148 408
d3b647c2
VZ
409 const size_t page_count = pClientWindow->GetPageCount();
410 for (size_t pos = 0; pos < page_count; pos++)
cd05bf23
BW
411 {
412 if (pClientWindow->GetPage(pos) == this)
413 return pClientWindow->DeletePage(pos);
414 }
4444d148 415
cd05bf23
BW
416 return false;
417}
418
cd05bf23 419#if wxUSE_MENUS
a3a5df9d 420void wxAuiMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
cd05bf23
BW
421{
422 wxMenuBar *pOldMenuBar = m_pMenuBar;
423 m_pMenuBar = menu_bar;
424
425 if (m_pMenuBar)
426 {
a3a5df9d 427 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
cd05bf23
BW
428 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
429
430 m_pMenuBar->SetParent(pParentFrame);
431 if (pParentFrame->GetActiveChild() == this)
432 {
433 // replace current menu bars
434 if (pOldMenuBar)
435 pParentFrame->SetChildMenuBar(NULL);
436 pParentFrame->SetChildMenuBar(this);
437 }
438 }
439}
440
a3a5df9d 441wxMenuBar *wxAuiMDIChildFrame::GetMenuBar() const
cd05bf23
BW
442{
443 return m_pMenuBar;
444}
445#endif // wxUSE_MENUS
446
a3a5df9d 447void wxAuiMDIChildFrame::SetTitle(const wxString& title)
cd05bf23
BW
448{
449 m_title = title;
450
a3a5df9d 451 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
cd05bf23
BW
452 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
453
8856768e 454 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
cd05bf23
BW
455 if (pClientWindow != NULL)
456 {
457 size_t pos;
458 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
459 {
460 if (pClientWindow->GetPage(pos) == this)
461 {
462 pClientWindow->SetPageText(pos, m_title);
463 break;
464 }
465 }
466 }
467}
468
a3a5df9d 469wxString wxAuiMDIChildFrame::GetTitle() const
cd05bf23
BW
470{
471 return m_title;
472}
473
a3a5df9d 474void wxAuiMDIChildFrame::Activate()
cd05bf23 475{
a3a5df9d 476 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
cd05bf23
BW
477 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
478
8856768e 479 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
cd05bf23
BW
480
481 if (pClientWindow != NULL)
482 {
483 size_t pos;
484 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
485 {
486 if (pClientWindow->GetPage(pos) == this)
487 {
488 pClientWindow->SetSelection(pos);
489 break;
490 }
491 }
492 }
493}
494
a3a5df9d 495void wxAuiMDIChildFrame::OnMenuHighlight(wxMenuEvent& event)
cd05bf23
BW
496{
497#if wxUSE_STATUSBAR
498 if (m_pMDIParentFrame)
499 {
500 // we don't have any help text for this item,
501 // but may be the MDI frame does?
502 m_pMDIParentFrame->OnMenuHighlight(event);
503 }
504#else
505 wxUnusedVar(event);
506#endif // wxUSE_STATUSBAR
507}
508
a3a5df9d 509void wxAuiMDIChildFrame::OnActivate(wxActivateEvent& WXUNUSED(event))
cd05bf23
BW
510{
511 // do nothing
512}
513
a3a5df9d 514void wxAuiMDIChildFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
cd05bf23
BW
515{
516 Destroy();
517}
518
a3a5df9d 519void wxAuiMDIChildFrame::SetMDIParentFrame(wxAuiMDIParentFrame* parentFrame)
cd05bf23
BW
520{
521 m_pMDIParentFrame = parentFrame;
522}
523
a3a5df9d 524wxAuiMDIParentFrame* wxAuiMDIChildFrame::GetMDIParentFrame() const
cd05bf23
BW
525{
526 return m_pMDIParentFrame;
527}
528
a3a5df9d 529void wxAuiMDIChildFrame::Init()
cd05bf23
BW
530{
531 m_pMDIParentFrame = NULL;
532#if wxUSE_MENUS
533 m_pMenuBar = NULL;
534#endif // wxUSE_MENUS
535}
536
a3a5df9d 537bool wxAuiMDIChildFrame::Show(bool WXUNUSED(show))
cd05bf23
BW
538{
539 // do nothing
540 return true;
541}
542
a3a5df9d 543void wxAuiMDIChildFrame::DoShow(bool show)
cd05bf23
BW
544{
545 wxWindow::Show(show);
546}
547
a3a5df9d 548void wxAuiMDIChildFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags)
cd05bf23
BW
549{
550 m_mdi_newrect = wxRect(x, y, width, height);
a94476de
BW
551#ifdef __WXGTK__
552 wxPanel::DoSetSize(x,y,width, height, sizeFlags);
f9c240ec
BW
553#else
554 wxUnusedVar(sizeFlags);
a94476de 555#endif
cd05bf23
BW
556}
557
a3a5df9d 558void wxAuiMDIChildFrame::DoMoveWindow(int x, int y, int width, int height)
cd05bf23
BW
559{
560 m_mdi_newrect = wxRect(x, y, width, height);
561}
562
a3a5df9d 563void wxAuiMDIChildFrame::ApplyMDIChildFrameRect()
cd05bf23
BW
564{
565 if (m_mdi_currect != m_mdi_newrect)
566 {
567 wxPanel::DoMoveWindow(m_mdi_newrect.x, m_mdi_newrect.y,
568 m_mdi_newrect.width, m_mdi_newrect.height);
569 m_mdi_currect = m_mdi_newrect;
570 }
571}
572
573
574//-----------------------------------------------------------------------------
8856768e 575// wxAuiMDIClientWindow
cd05bf23
BW
576//-----------------------------------------------------------------------------
577
8856768e 578IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIClientWindow, wxAuiNotebook)
cd05bf23 579
8856768e
BW
580BEGIN_EVENT_TABLE(wxAuiMDIClientWindow, wxAuiNotebook)
581 EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, wxAuiMDIClientWindow::OnPageChanged)
582 EVT_SIZE(wxAuiMDIClientWindow::OnSize)
cd05bf23
BW
583END_EVENT_TABLE()
584
8856768e 585wxAuiMDIClientWindow::wxAuiMDIClientWindow()
cd05bf23
BW
586{
587}
588
8856768e 589wxAuiMDIClientWindow::wxAuiMDIClientWindow(wxAuiMDIParentFrame* parent, long style)
cd05bf23
BW
590{
591 CreateClient(parent, style);
592}
593
8856768e 594wxAuiMDIClientWindow::~wxAuiMDIClientWindow()
cd05bf23
BW
595{
596 DestroyChildren();
597}
598
8856768e 599bool wxAuiMDIClientWindow::CreateClient(wxAuiMDIParentFrame* parent, long style)
cd05bf23
BW
600{
601 SetWindowStyleFlag(style);
602
a3a5df9d 603 if (!wxAuiNotebook::Create(parent,
695c0088
BW
604 wxID_ANY,
605 wxPoint(0,0),
606 wxSize(100, 100),
607 wxAUI_NB_DEFAULT_STYLE | wxNO_BORDER))
cd05bf23
BW
608 {
609 return false;
610 }
4444d148 611
cd05bf23
BW
612 wxColour bkcolour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
613 SetBackgroundColour(bkcolour);
4444d148 614
cd05bf23 615 m_mgr.GetArtProvider()->SetColour(wxAUI_ART_BACKGROUND_COLOUR, bkcolour);
4444d148 616
cd05bf23
BW
617 return true;
618}
619
8856768e 620int wxAuiMDIClientWindow::SetSelection(size_t nPage)
cd05bf23 621{
a3a5df9d 622 return wxAuiNotebook::SetSelection(nPage);
cd05bf23
BW
623}
624
8856768e 625void wxAuiMDIClientWindow::PageChanged(int old_selection, int new_selection)
cd05bf23
BW
626{
627 // don't do anything if the page doesn't actually change
628 if (old_selection == new_selection)
629 return;
4444d148 630
cd05bf23
BW
631 // don't do anything if the new page is already active
632 if (new_selection != -1)
633 {
a3a5df9d 634 wxAuiMDIChildFrame* child = (wxAuiMDIChildFrame*)GetPage(new_selection);
cd05bf23
BW
635 if (child->GetMDIParentFrame()->GetActiveChild() == child)
636 return;
637 }
638
639 // notify old active child that it has been deactivated
640 if (old_selection != -1)
641 {
a3a5df9d 642 wxAuiMDIChildFrame* old_child = (wxAuiMDIChildFrame*)GetPage(old_selection);
8856768e 643 wxASSERT_MSG(old_child, wxT("wxAuiMDIClientWindow::PageChanged - null page pointer"));
4444d148 644
cd05bf23
BW
645 wxActivateEvent event(wxEVT_ACTIVATE, false, old_child->GetId());
646 event.SetEventObject(old_child);
647 old_child->GetEventHandler()->ProcessEvent(event);
648 }
649
650 // notify new active child that it has been activated
651 if (new_selection != -1)
652 {
a3a5df9d 653 wxAuiMDIChildFrame* active_child = (wxAuiMDIChildFrame*)GetPage(new_selection);
8856768e 654 wxASSERT_MSG(active_child, wxT("wxAuiMDIClientWindow::PageChanged - null page pointer"));
4444d148 655
cd05bf23
BW
656 wxActivateEvent event(wxEVT_ACTIVATE, true, active_child->GetId());
657 event.SetEventObject(active_child);
658 active_child->GetEventHandler()->ProcessEvent(event);
659
660 if (active_child->GetMDIParentFrame())
661 {
662 active_child->GetMDIParentFrame()->SetActiveChild(active_child);
663 active_child->GetMDIParentFrame()->SetChildMenuBar(active_child);
664 }
665 }
666}
667
8856768e 668void wxAuiMDIClientWindow::OnPageChanged(wxAuiNotebookEvent& evt)
cd05bf23
BW
669{
670 PageChanged(evt.GetOldSelection(), evt.GetSelection());
671 evt.Skip();
672}
673
8856768e 674void wxAuiMDIClientWindow::OnSize(wxSizeEvent& evt)
4444d148 675{
a3a5df9d 676 wxAuiNotebook::OnSize(evt);
cd05bf23
BW
677
678 for (size_t pos = 0; pos < GetPageCount(); pos++)
a3a5df9d 679 ((wxAuiMDIChildFrame *)GetPage(pos))->ApplyMDIChildFrameRect();
cd05bf23
BW
680}
681
25f70bc4 682#endif //wxUSE_AUI
cd05bf23 683#endif // wxUSE_MDI