]> git.saurik.com Git - wxWidgets.git/blob - src/generic/mdig.cpp
Introducing wxBase for borland based on Michael Fieldings patch 598106
[wxWidgets.git] / src / generic / mdig.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/mdig.cpp
3 // Purpose: Generic MDI (Multiple Document Interface) classes
4 // Author: Hans Van Leemputten
5 // Modified by:
6 // Created: 29/07/2002
7 // RCS-ID: $Id$
8 // Copyright: (c) Hans Van Leemputten
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "mdig.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/panel.h"
33 #include "wx/menu.h"
34 #endif //WX_PRECOMP
35
36 #include "wx/generic/mdig.h"
37
38 enum MDI_MENU_ID
39 {
40 wxWINDOWCLOSE = 4001,
41 wxWINDOWCLOSEALL,
42 wxWINDOWNEXT,
43 wxWINDOWPREV
44 };
45
46 //-----------------------------------------------------------------------------
47 // wxGenericMDIParentFrame
48 //-----------------------------------------------------------------------------
49
50 IMPLEMENT_DYNAMIC_CLASS(wxGenericMDIParentFrame, wxFrame)
51
52 BEGIN_EVENT_TABLE(wxGenericMDIParentFrame, wxFrame)
53 EVT_MENU (-1, wxGenericMDIParentFrame::DoHandleMenu)
54 END_EVENT_TABLE()
55
56 wxGenericMDIParentFrame::wxGenericMDIParentFrame()
57 {
58 Init();
59 }
60
61 wxGenericMDIParentFrame::wxGenericMDIParentFrame(wxWindow *parent,
62 wxWindowID id,
63 const wxString& title,
64 const wxPoint& pos,
65 const wxSize& size,
66 long style,
67 const wxString& name)
68 {
69 Init();
70
71 (void)Create(parent, id, title, pos, size, style, name);
72 }
73
74 wxGenericMDIParentFrame::~wxGenericMDIParentFrame()
75 {
76 // Make sure the client window is destructed before the menu bars are!
77 wxDELETE(m_pClientWindow);
78
79 #if wxUSE_MENUS
80 if (m_pMyMenuBar)
81 {
82 delete m_pMyMenuBar;
83 m_pMyMenuBar = (wxMenuBar *) NULL;
84 }
85
86 RemoveWindowMenu(GetMenuBar());
87
88 if (m_pWindowMenu)
89 {
90 delete m_pWindowMenu;
91 m_pWindowMenu = (wxMenu*) NULL;
92 }
93 #endif // wxUSE_MENUS
94 }
95
96 bool wxGenericMDIParentFrame::Create(wxWindow *parent,
97 wxWindowID id,
98 const wxString& title,
99 const wxPoint& pos,
100 const wxSize& size,
101 long style,
102 const wxString& name)
103 {
104 // this style can be used to prevent a window from having the standard MDI
105 // "Window" menu
106 if ( !(style & wxFRAME_NO_WINDOW_MENU) )
107 {
108 #if wxUSE_MENUS
109 m_pWindowMenu = new wxMenu;
110
111 m_pWindowMenu->Append(wxWINDOWCLOSE, _T("Cl&ose"));
112 m_pWindowMenu->Append(wxWINDOWCLOSEALL, _T("Close Al&l"));
113 m_pWindowMenu->AppendSeparator();
114 m_pWindowMenu->Append(wxWINDOWNEXT, _T("&Next"));
115 m_pWindowMenu->Append(wxWINDOWPREV, _T("&Previouse"));
116 #endif // wxUSE_MENUS
117 }
118
119 wxFrame::Create( parent, id, title, pos, size, style, name );
120
121 OnCreateClient();
122
123 return TRUE;
124 }
125
126 #if wxUSE_MENUS
127 void wxGenericMDIParentFrame::SetWindowMenu(wxMenu* pMenu)
128 {
129 // Replace the window menu from the currently loaded menu bar.
130 wxMenuBar *pMenuBar = GetMenuBar();
131
132 if (m_pWindowMenu)
133 {
134 RemoveWindowMenu(pMenuBar);
135
136 wxDELETE(m_pWindowMenu);
137 }
138
139 if (pMenu)
140 {
141 m_pWindowMenu = pMenu;
142
143 AddWindowMenu(pMenuBar);
144 }
145 }
146
147 void wxGenericMDIParentFrame::SetMenuBar(wxMenuBar *pMenuBar)
148 {
149 // Remove the Window menu from the old menu bar
150 RemoveWindowMenu(GetMenuBar());
151 // Add the Window menu to the new menu bar.
152 AddWindowMenu(pMenuBar);
153
154 wxFrame::SetMenuBar(pMenuBar);
155 }
156 #endif // wxUSE_MENUS
157
158 void wxGenericMDIParentFrame::SetChildMenuBar(wxGenericMDIChildFrame *pChild)
159 {
160 #if wxUSE_MENUS
161 if (pChild == (wxGenericMDIChildFrame *) NULL)
162 {
163 // No Child, set Our menu bar back.
164 SetMenuBar(m_pMyMenuBar);
165
166 // Make sure we know our menu bar is in use
167 m_pMyMenuBar = (wxMenuBar*) NULL;
168 }
169 else
170 {
171 if (pChild->GetMenuBar() == (wxMenuBar*) NULL)
172 return;
173
174 // Do we need to save the current bar?
175 if (m_pMyMenuBar == NULL)
176 m_pMyMenuBar = GetMenuBar();
177
178 SetMenuBar(pChild->GetMenuBar());
179 }
180 #endif // wxUSE_MENUS
181 }
182
183 bool wxGenericMDIParentFrame::ProcessEvent(wxEvent& event)
184 {
185 /*
186 * Redirect events to active child first.
187 */
188
189 // Stops the same event being processed repeatedly
190 static wxEventType inEvent = wxEVT_NULL;
191 if (inEvent == event.GetEventType())
192 return FALSE;
193
194 inEvent = event.GetEventType();
195
196 // Let the active child (if any) process the event first.
197 bool res = FALSE;
198 if (m_pActiveChild && event.IsKindOf(CLASSINFO(wxCommandEvent))
199 #if 0
200 /* This is sure to not give problems... */
201 && (event.GetEventType() == wxEVT_COMMAND_MENU_SELECTED ||
202 event.GetEventType() == wxEVT_UPDATE_UI ))
203 #else
204 /* This was tested on wxMSW and worked... */
205 && event.GetEventObject() != m_pClientWindow
206 && !(event.GetEventType() == wxEVT_ACTIVATE ||
207 event.GetEventType() == wxEVT_SET_FOCUS ||
208 event.GetEventType() == wxEVT_KILL_FOCUS ||
209 event.GetEventType() == wxEVT_CHILD_FOCUS ||
210 event.GetEventType() == wxEVT_COMMAND_SET_FOCUS ||
211 event.GetEventType() == wxEVT_COMMAND_KILL_FOCUS ))
212 #endif
213 {
214 res = m_pActiveChild->GetEventHandler()->ProcessEvent(event);
215 }
216
217 // If the event was not handled this frame will handle it!
218 if (!res)
219 {
220 res = GetEventHandler()->wxEvtHandler::ProcessEvent(event);
221 }
222
223 inEvent = wxEVT_NULL;
224
225 return res;
226 }
227
228 wxGenericMDIChildFrame *wxGenericMDIParentFrame::GetActiveChild() const
229 {
230 return m_pActiveChild;
231 }
232
233 void wxGenericMDIParentFrame::SetActiveChild(wxGenericMDIChildFrame* pChildFrame)
234 {
235 m_pActiveChild = pChildFrame;
236 }
237
238 wxGenericMDIClientWindow *wxGenericMDIParentFrame::GetClientWindow() const
239 {
240 return m_pClientWindow;
241 }
242
243 wxGenericMDIClientWindow *wxGenericMDIParentFrame::OnCreateClient()
244 {
245 #if wxUSE_GENERIC_MDI_AS_NATIVE
246 m_pClientWindow = new wxMDIClientWindow( this );
247 #else
248 m_pClientWindow = new wxGenericMDIClientWindow( this );
249 #endif
250 return m_pClientWindow;
251 }
252
253 void wxGenericMDIParentFrame::ActivateNext()
254 {
255 if (m_pClientWindow && m_pClientWindow->GetSelection() != -1)
256 {
257 int active = m_pClientWindow->GetSelection() + 1;
258 if (active >= m_pClientWindow->GetPageCount())
259 active = 0;
260
261 m_pClientWindow->SetSelection(active);
262 }
263 }
264
265 void wxGenericMDIParentFrame::ActivatePrevious()
266 {
267 if (m_pClientWindow && m_pClientWindow->GetSelection() != -1)
268 {
269 int active = m_pClientWindow->GetSelection() - 1;
270 if (active < 0)
271 active = m_pClientWindow->GetPageCount() - 1;
272
273 m_pClientWindow->SetSelection(active);
274 }
275 }
276
277 void wxGenericMDIParentFrame::Init()
278 {
279 m_pClientWindow = (wxGenericMDIClientWindow *) NULL;
280 m_pActiveChild = (wxGenericMDIChildFrame *) NULL;
281 #if wxUSE_MENUS
282 m_pWindowMenu = (wxMenu *) NULL;
283 m_pMyMenuBar = (wxMenuBar*) NULL;
284 #endif // wxUSE_MENUS
285 }
286
287 #if wxUSE_MENUS
288 void wxGenericMDIParentFrame::RemoveWindowMenu(wxMenuBar *pMenuBar)
289 {
290 if (pMenuBar && m_pWindowMenu)
291 {
292 // Remove old window menu
293 int pos = pMenuBar->FindMenu(_T("&Window"));
294 if (pos != wxNOT_FOUND)
295 {
296 wxASSERT(m_pWindowMenu == pMenuBar->GetMenu(pos)); // DBG:: We're going to delete the wrong menu!!!
297 pMenuBar->Remove(pos);
298 }
299 }
300 }
301
302 void wxGenericMDIParentFrame::AddWindowMenu(wxMenuBar *pMenuBar)
303 {
304 if (pMenuBar && m_pWindowMenu)
305 {
306 int pos = pMenuBar->FindMenu(_T("Help"));
307 if (pos == wxNOT_FOUND)
308 {
309 pMenuBar->Append(m_pWindowMenu, _T("&Window"));
310 }
311 else
312 {
313 pMenuBar->Insert(pos, m_pWindowMenu, _T("&Window"));
314 }
315 }
316 }
317
318 void wxGenericMDIParentFrame::DoHandleMenu(wxCommandEvent &event)
319 {
320 switch (event.GetId())
321 {
322 case wxWINDOWCLOSE:
323 if (m_pActiveChild)
324 {
325 m_pActiveChild->Close();
326 }
327 break;
328 case wxWINDOWCLOSEALL:
329 {
330 #if 0 // code is only needed if next #if is set to 0!
331 wxGenericMDIChildFrame *pFirstActiveChild = m_pActiveChild;
332 #endif
333 while (m_pActiveChild)
334 {
335 if (!m_pActiveChild->Close())
336 {
337 return; // We failed...
338 }
339 else
340 {
341 #if 1 // What's best? Delayed deleting or immediate deleting?
342 delete m_pActiveChild;
343 #else
344 ActivateNext();
345
346 if (pFirstActiveChild == m_pActiveChild)
347 return; // We've called Close on all items, no need to continue.
348 #endif
349 }
350 }
351 }
352 break;
353 case wxWINDOWNEXT:
354 ActivateNext();
355 break;
356 case wxWINDOWPREV:
357 ActivatePrevious();
358 break;
359 default :
360 event.Skip();
361 }
362 }
363 #endif // wxUSE_MENUS
364
365 void wxGenericMDIParentFrame::DoGetClientSize(int *width, int *height) const
366 {
367 wxFrame::DoGetClientSize( width, height );
368 }
369
370
371 //-----------------------------------------------------------------------------
372 // wxGenericMDIChildFrame
373 //-----------------------------------------------------------------------------
374
375 IMPLEMENT_DYNAMIC_CLASS(wxGenericMDIChildFrame, wxPanel)
376
377 BEGIN_EVENT_TABLE(wxGenericMDIChildFrame, wxPanel)
378 EVT_MENU_HIGHLIGHT_ALL(wxGenericMDIChildFrame::OnMenuHighlight)
379 EVT_ACTIVATE(wxGenericMDIChildFrame::OnActivate)
380
381 EVT_CLOSE(wxGenericMDIChildFrame::OnCloseWindow)
382 EVT_SIZE(wxGenericMDIChildFrame::OnSize)
383 END_EVENT_TABLE()
384
385 wxGenericMDIChildFrame::wxGenericMDIChildFrame()
386 {
387 Init();
388 }
389
390 wxGenericMDIChildFrame::wxGenericMDIChildFrame( wxGenericMDIParentFrame *parent,
391 wxWindowID id, const wxString& title,
392 const wxPoint& WXUNUSED(pos), const wxSize& size,
393 long style, const wxString& name )
394 {
395 Init();
396
397 Create( parent, id, title, wxDefaultPosition, size, style, name );
398 }
399
400 #include "wx/log.h"
401 wxGenericMDIChildFrame::~wxGenericMDIChildFrame()
402 {
403 wxGenericMDIParentFrame *pParentFrame = GetMDIParentFrame();
404
405 if (pParentFrame != NULL)
406 {
407 bool bActive = FALSE;
408 if (pParentFrame->GetActiveChild() == this)
409 {
410 pParentFrame->SetActiveChild((wxGenericMDIChildFrame*) NULL);
411 pParentFrame->SetChildMenuBar((wxGenericMDIChildFrame*) NULL);
412 bActive = TRUE;
413 }
414
415 wxGenericMDIClientWindow *pClientWindow = pParentFrame->GetClientWindow();
416
417 // Remove page if still there
418 int pos;
419 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
420 {
421 if (pClientWindow->GetPage(pos) == this)
422 {
423 if (pClientWindow->RemovePage(pos))
424 pClientWindow->Refresh();
425 break;
426 }
427 }
428
429 if (bActive)
430 {
431 // Set the new selection to the a remaining page
432 if (pClientWindow->GetPageCount() > pos)
433 {
434 pClientWindow->SetSelection(pos);
435 }
436 else
437 {
438 if (pClientWindow->GetPageCount() - 1 >= 0)
439 pClientWindow->SetSelection(pClientWindow->GetPageCount() - 1);
440 }
441 }
442 }
443
444 #if wxUSE_MENUS
445 wxDELETE(m_pMenuBar);
446 #endif // wxUSE_MENUS
447 }
448
449 bool wxGenericMDIChildFrame::Create( wxGenericMDIParentFrame *parent,
450 wxWindowID id, const wxString& title,
451 const wxPoint& WXUNUSED(pos), const wxSize& size,
452 long style, const wxString& name )
453 {
454 wxGenericMDIClientWindow* pClientWindow = parent->GetClientWindow();
455
456 wxASSERT_MSG((pClientWindow != (wxWindow*) NULL), "Missing MDI client window.");
457
458 wxPanel::Create(pClientWindow, id, wxDefaultPosition, size, style, name);
459
460 SetMDIParentFrame(parent);
461
462 // This is the currently active child
463 parent->SetActiveChild(this);
464
465 m_Title = title;
466
467 pClientWindow->AddPage(this, title, TRUE);
468 ApplyMDIChildFrameRect(); // Ok confirme the size change!
469 pClientWindow->Refresh();
470
471 return TRUE;
472 }
473
474 #if wxUSE_MENUS
475 void wxGenericMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar )
476 {
477 wxMenuBar *pOldMenuBar = m_pMenuBar;
478 m_pMenuBar = menu_bar;
479
480 if (m_pMenuBar)
481 {
482 wxGenericMDIParentFrame *pParentFrame = GetMDIParentFrame();
483
484 if (pParentFrame != NULL)
485 {
486 m_pMenuBar->SetParent(pParentFrame);
487
488 if (pParentFrame->GetActiveChild() == this)
489 {
490 // Replace current menu bars
491 if (pOldMenuBar)
492 pParentFrame->SetChildMenuBar((wxGenericMDIChildFrame*) NULL);
493 pParentFrame->SetChildMenuBar((wxGenericMDIChildFrame*) this);
494 }
495 }
496 }
497 }
498
499 wxMenuBar *wxGenericMDIChildFrame::GetMenuBar() const
500 {
501 return m_pMenuBar;
502 }
503 #endif // wxUSE_MENUS
504
505 void wxGenericMDIChildFrame::SetTitle(const wxString& title)
506 {
507 m_Title = title;
508
509 wxGenericMDIParentFrame *pParentFrame = GetMDIParentFrame();
510
511 if (pParentFrame != NULL)
512 {
513 wxGenericMDIClientWindow * pClientWindow = pParentFrame->GetClientWindow();
514
515 if (pClientWindow != NULL)
516 {
517 int pos;
518 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
519 {
520 if (pClientWindow->GetPage(pos) == this)
521 {
522 pClientWindow->SetPageText(pos, m_Title);
523 break;
524 }
525 }
526 }
527 }
528 }
529
530 wxString wxGenericMDIChildFrame::GetTitle()
531 {
532 return m_Title;
533 }
534
535 void wxGenericMDIChildFrame::Activate()
536 {
537 wxGenericMDIParentFrame *pParentFrame = GetMDIParentFrame();
538
539 if (pParentFrame != NULL)
540 {
541 wxGenericMDIClientWindow * pClientWindow = pParentFrame->GetClientWindow();
542
543 if (pClientWindow != NULL)
544 {
545 int pos;
546 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
547 {
548 if (pClientWindow->GetPage(pos) == this)
549 {
550 pClientWindow->SetSelection(pos);
551 break;
552 }
553 }
554 }
555 }
556 }
557
558 void wxGenericMDIChildFrame::OnMenuHighlight(wxMenuEvent& event)
559 {
560 #if wxUSE_STATUSBAR
561 if ( m_pMDIParentFrame)
562 {
563 // we don't have any help text for this item,
564 // but may be the MDI frame does?
565 m_pMDIParentFrame->OnMenuHighlight(event);
566 }
567 #endif // wxUSE_STATUSBAR
568 }
569
570 void wxGenericMDIChildFrame::OnActivate(wxActivateEvent& event)
571 {
572 // Do mothing.
573 }
574
575 /*** Copied from top level..! ***/
576 // default resizing behaviour - if only ONE subwindow, resize to fill the
577 // whole client area
578 void wxGenericMDIChildFrame::OnSize(wxSizeEvent& WXUNUSED(event))
579 {
580 // if we're using constraints or sizers - do use them
581 if ( GetAutoLayout() )
582 {
583 Layout();
584 }
585 else
586 {
587 // do we have _exactly_ one child?
588 wxWindow *child = (wxWindow *)NULL;
589 for ( wxWindowList::Node *node = GetChildren().GetFirst();
590 node;
591 node = node->GetNext() )
592 {
593 wxWindow *win = node->GetData();
594
595 // exclude top level and managed windows (status bar isn't
596 // currently in the children list except under wxMac anyhow, but
597 // it makes no harm to test for it)
598 if ( !win->IsTopLevel() /*&& !IsOneOfBars(win)*/ )
599 {
600 if ( child )
601 {
602 return; // it's our second subwindow - nothing to do
603 }
604
605 child = win;
606 }
607 }
608
609 // do we have any children at all?
610 if ( child )
611 {
612 // exactly one child - set it's size to fill the whole frame
613 int clientW, clientH;
614 DoGetClientSize(&clientW, &clientH);
615
616 // for whatever reasons, wxGTK wants to have a small offset - it
617 // probably looks better with it?
618 #ifdef __WXGTK__
619 static const int ofs = 1;
620 #else
621 static const int ofs = 0;
622 #endif
623
624 child->SetSize(ofs, ofs, clientW - 2*ofs, clientH - 2*ofs);
625 }
626 }
627 }
628
629 /*** Copied from top level..! ***/
630 // The default implementation for the close window event.
631 void wxGenericMDIChildFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
632 {
633 Destroy();
634 }
635
636 void wxGenericMDIChildFrame::SetMDIParentFrame(wxGenericMDIParentFrame* parentFrame)
637 {
638 m_pMDIParentFrame = parentFrame;
639 }
640
641 wxGenericMDIParentFrame* wxGenericMDIChildFrame::GetMDIParentFrame() const
642 {
643 return m_pMDIParentFrame;
644 }
645
646 void wxGenericMDIChildFrame::Init()
647 {
648 m_pMDIParentFrame = (wxGenericMDIParentFrame *) NULL;
649 #if wxUSE_MENUS
650 m_pMenuBar = (wxMenuBar *) NULL;
651 #endif // wxUSE_MENUS
652 }
653
654 void wxGenericMDIChildFrame::DoMoveWindow(int x, int y, int width, int height)
655 {
656 m_MDIRect = wxRect(x, y, width, height);
657 }
658
659 void wxGenericMDIChildFrame::ApplyMDIChildFrameRect()
660 {
661 wxPanel::DoMoveWindow(m_MDIRect.x, m_MDIRect.y, m_MDIRect.width, m_MDIRect.height);
662 }
663
664 //-----------------------------------------------------------------------------
665 // wxGenericMDIClientWindow
666 //-----------------------------------------------------------------------------
667
668 #define wxID_NOTEBOOK_CLIENT_AREA wxID_HIGHEST + 100
669
670 IMPLEMENT_DYNAMIC_CLASS(wxGenericMDIClientWindow, wxNotebook)
671
672 BEGIN_EVENT_TABLE(wxGenericMDIClientWindow, wxNotebook)
673 EVT_NOTEBOOK_PAGE_CHANGED(wxID_NOTEBOOK_CLIENT_AREA, wxGenericMDIClientWindow::OnPageChanged)
674 EVT_SIZE(wxGenericMDIClientWindow::OnSize)
675 END_EVENT_TABLE()
676
677
678 wxGenericMDIClientWindow::wxGenericMDIClientWindow()
679 {
680 }
681
682 wxGenericMDIClientWindow::wxGenericMDIClientWindow( wxGenericMDIParentFrame *parent, long style )
683 {
684 CreateClient( parent, style );
685 }
686
687 wxGenericMDIClientWindow::~wxGenericMDIClientWindow()
688 {
689 DestroyChildren();
690 }
691
692 bool wxGenericMDIClientWindow::CreateClient( wxGenericMDIParentFrame *parent, long style )
693 {
694 SetWindowStyleFlag(style);
695
696 bool success = wxNotebook::Create(parent, wxID_NOTEBOOK_CLIENT_AREA, wxPoint(0, 0), wxSize(100, 100), 0);
697 if (success)
698 {
699 /*
700 wxFont font(10, wxSWISS, wxNORMAL, wxNORMAL);
701 wxFont selFont(10, wxSWISS, wxNORMAL, wxBOLD);
702 GetTabView()->SetTabFont(font);
703 GetTabView()->SetSelectedTabFont(selFont);
704 GetTabView()->SetTabSize(120, 18);
705 GetTabView()->SetTabSelectionHeight(20);
706 */
707 return TRUE;
708 }
709 else
710 return FALSE;
711 }
712
713 int wxGenericMDIClientWindow::SetSelection(int nPage)
714 {
715 int oldSelection = wxNotebook::SetSelection(nPage);
716
717 #if !defined(__WXMSW__) // No need to do this for wxMSW as wxNotebook::SetSelection()
718 // will already cause this to be done!
719 // Handle the page change.
720 PageChanged(oldSelection, nPage);
721 #endif
722
723 return oldSelection;
724 }
725
726 void wxGenericMDIClientWindow::PageChanged(int OldSelection, int newSelection)
727 {
728 // Don't do to much work, only when something realy should change!
729 if (OldSelection == newSelection)
730 return;
731 // Again check if we realy need to do this...
732 if (newSelection != -1)
733 {
734 wxGenericMDIChildFrame* child = (wxGenericMDIChildFrame *)GetPage(newSelection);
735
736 if (child->GetMDIParentFrame()->GetActiveChild() == child)
737 return;
738 }
739
740 // Notify old active child that it has been deactivated
741 if (OldSelection != -1)
742 {
743 wxGenericMDIChildFrame* oldChild = (wxGenericMDIChildFrame *)GetPage(OldSelection);
744 if (oldChild)
745 {
746 wxActivateEvent event(wxEVT_ACTIVATE, FALSE, oldChild->GetId());
747 event.SetEventObject( oldChild );
748 oldChild->GetEventHandler()->ProcessEvent(event);
749 }
750 }
751
752 // Notify new active child that it has been activated
753 if (newSelection != -1)
754 {
755 wxGenericMDIChildFrame* activeChild = (wxGenericMDIChildFrame *)GetPage(newSelection);
756 if (activeChild)
757 {
758 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, activeChild->GetId());
759 event.SetEventObject( activeChild );
760 activeChild->GetEventHandler()->ProcessEvent(event);
761
762 if (activeChild->GetMDIParentFrame())
763 {
764 activeChild->GetMDIParentFrame()->SetActiveChild(activeChild);
765 activeChild->GetMDIParentFrame()->SetChildMenuBar(activeChild);
766 }
767 }
768 }
769 }
770
771 void wxGenericMDIClientWindow::OnPageChanged(wxNotebookEvent& event)
772 {
773 PageChanged(event.GetOldSelection(), event.GetSelection());
774
775 event.Skip();
776 }
777
778 void wxGenericMDIClientWindow::OnSize(wxSizeEvent& event)
779 {
780 wxNotebook::OnSize(event);
781
782 int pos;
783 for (pos = 0; pos < GetPageCount(); pos++)
784 {
785 ((wxGenericMDIChildFrame *)GetPage(pos))->ApplyMDIChildFrameRect();
786 }
787 }
788
789
790 /*
791 * Define normal wxMDI classes based on wxGenericMDI
792 */
793
794 #if wxUSE_GENERIC_MDI_AS_NATIVE
795
796 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxGenericMDIParentFrame)
797 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxGenericMDIChildFrame)
798 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxGenericMDIClientWindow)
799
800 #endif
801