]> git.saurik.com Git - wxWidgets.git/blob - src/aui/tabmdi.cpp
don't allow TAB-bing away to other TLWs
[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 wxDELETE(m_pMyMenuBar);
86 RemoveWindowMenu(GetMenuBar());
87 wxDELETE(m_pWindowMenu);
88 #endif // wxUSE_MENUS
89 }
90
91 bool wxAuiMDIParentFrame::Create(wxWindow *parent,
92 wxWindowID id,
93 const wxString& title,
94 const wxPoint& pos,
95 const wxSize& size,
96 long style,
97 const wxString& name)
98 {
99 #if wxUSE_MENUS
100 // this style can be used to prevent a window from having the standard MDI
101 // "Window" menu
102 if (!(style & wxFRAME_NO_WINDOW_MENU))
103 {
104 m_pWindowMenu = new wxMenu;
105 m_pWindowMenu->Append(wxWINDOWCLOSE, _("Cl&ose"));
106 m_pWindowMenu->Append(wxWINDOWCLOSEALL, _("Close All"));
107 m_pWindowMenu->AppendSeparator();
108 m_pWindowMenu->Append(wxWINDOWNEXT, _("&Next"));
109 m_pWindowMenu->Append(wxWINDOWPREV, _("&Previous"));
110 }
111 #endif // wxUSE_MENUS
112
113 wxFrame::Create(parent, id, title, pos, size, style, name);
114 OnCreateClient();
115 return true;
116 }
117
118
119 void wxAuiMDIParentFrame::SetArtProvider(wxAuiTabArt* provider)
120 {
121 if (m_pClientWindow)
122 {
123 m_pClientWindow->SetArtProvider(provider);
124 }
125 }
126
127 wxAuiTabArt* wxAuiMDIParentFrame::GetArtProvider()
128 {
129 if (!m_pClientWindow)
130 return NULL;
131
132 return m_pClientWindow->GetArtProvider();
133 }
134
135 wxAuiNotebook* wxAuiMDIParentFrame::GetNotebook() const
136 {
137 return static_cast<wxAuiNotebook*>(m_pClientWindow);
138 }
139
140
141
142 #if wxUSE_MENUS
143 void wxAuiMDIParentFrame::SetWindowMenu(wxMenu* pMenu)
144 {
145 // Replace the window menu from the currently loaded menu bar.
146 wxMenuBar *pMenuBar = GetMenuBar();
147
148 if (m_pWindowMenu)
149 {
150 RemoveWindowMenu(pMenuBar);
151 wxDELETE(m_pWindowMenu);
152 }
153
154 if (pMenu)
155 {
156 m_pWindowMenu = pMenu;
157 AddWindowMenu(pMenuBar);
158 }
159 }
160
161 void wxAuiMDIParentFrame::SetMenuBar(wxMenuBar* pMenuBar)
162 {
163 // Remove the Window menu from the old menu bar
164 RemoveWindowMenu(GetMenuBar());
165
166 // Add the Window menu to the new menu bar.
167 AddWindowMenu(pMenuBar);
168
169 wxFrame::SetMenuBar(pMenuBar);
170 //m_pMyMenuBar = GetMenuBar();
171 }
172 #endif // wxUSE_MENUS
173
174 void wxAuiMDIParentFrame::SetChildMenuBar(wxAuiMDIChildFrame* pChild)
175 {
176 #if wxUSE_MENUS
177 if (!pChild)
178 {
179 // No Child, set Our menu bar back.
180 if (m_pMyMenuBar)
181 SetMenuBar(m_pMyMenuBar);
182 else
183 SetMenuBar(GetMenuBar());
184
185 // Make sure we know our menu bar is in use
186 m_pMyMenuBar = NULL;
187 }
188 else
189 {
190 if (pChild->GetMenuBar() == NULL)
191 return;
192
193 // Do we need to save the current bar?
194 if (m_pMyMenuBar == NULL)
195 m_pMyMenuBar = GetMenuBar();
196
197 SetMenuBar(pChild->GetMenuBar());
198 }
199 #endif // wxUSE_MENUS
200 }
201
202 bool wxAuiMDIParentFrame::ProcessEvent(wxEvent& event)
203 {
204 // stops the same event being processed repeatedly
205 if (m_pLastEvt == &event)
206 return false;
207 m_pLastEvt = &event;
208
209 // let the active child (if any) process the event first.
210 bool res = false;
211 if (m_pActiveChild &&
212 event.IsCommandEvent() &&
213 event.GetEventObject() != m_pClientWindow &&
214 !(event.GetEventType() == wxEVT_ACTIVATE ||
215 event.GetEventType() == wxEVT_SET_FOCUS ||
216 event.GetEventType() == wxEVT_KILL_FOCUS ||
217 event.GetEventType() == wxEVT_CHILD_FOCUS ||
218 event.GetEventType() == wxEVT_COMMAND_SET_FOCUS ||
219 event.GetEventType() == wxEVT_COMMAND_KILL_FOCUS )
220 )
221 {
222 res = m_pActiveChild->GetEventHandler()->ProcessEvent(event);
223 }
224
225 if (!res)
226 {
227 // if the event was not handled this frame will handle it,
228 // which is why we need the protection code at the beginning
229 // of this method
230 res = wxEvtHandler::ProcessEvent(event);
231 }
232
233 m_pLastEvt = NULL;
234
235 return res;
236 }
237
238 wxAuiMDIChildFrame *wxAuiMDIParentFrame::GetActiveChild() const
239 {
240 return m_pActiveChild;
241 }
242
243 void wxAuiMDIParentFrame::SetActiveChild(wxAuiMDIChildFrame* pChildFrame)
244 {
245 m_pActiveChild = pChildFrame;
246 }
247
248 wxAuiMDIClientWindow *wxAuiMDIParentFrame::GetClientWindow() const
249 {
250 return m_pClientWindow;
251 }
252
253 wxAuiMDIClientWindow *wxAuiMDIParentFrame::OnCreateClient()
254 {
255 m_pClientWindow = new wxAuiMDIClientWindow( this );
256 return m_pClientWindow;
257 }
258
259 void wxAuiMDIParentFrame::ActivateNext()
260 {
261 if (m_pClientWindow && m_pClientWindow->GetSelection() != wxNOT_FOUND)
262 {
263 size_t active = m_pClientWindow->GetSelection() + 1;
264 if (active >= m_pClientWindow->GetPageCount())
265 active = 0;
266
267 m_pClientWindow->SetSelection(active);
268 }
269 }
270
271 void wxAuiMDIParentFrame::ActivatePrevious()
272 {
273 if (m_pClientWindow && m_pClientWindow->GetSelection() != wxNOT_FOUND)
274 {
275 int active = m_pClientWindow->GetSelection() - 1;
276 if (active < 0)
277 active = m_pClientWindow->GetPageCount() - 1;
278
279 m_pClientWindow->SetSelection(active);
280 }
281 }
282
283 void wxAuiMDIParentFrame::Init()
284 {
285 m_pLastEvt = NULL;
286 m_pClientWindow = NULL;
287 m_pActiveChild = NULL;
288 #if wxUSE_MENUS
289 m_pWindowMenu = NULL;
290 m_pMyMenuBar = NULL;
291 #endif // wxUSE_MENUS
292 }
293
294 #if wxUSE_MENUS
295 void wxAuiMDIParentFrame::RemoveWindowMenu(wxMenuBar* pMenuBar)
296 {
297 if (pMenuBar && m_pWindowMenu)
298 {
299 // Remove old window menu
300 int pos = pMenuBar->FindMenu(_("&Window"));
301 if (pos != wxNOT_FOUND)
302 {
303 // DBG:: We're going to delete the wrong menu!!!
304 wxASSERT(m_pWindowMenu == pMenuBar->GetMenu(pos));
305 pMenuBar->Remove(pos);
306 }
307 }
308 }
309
310 void wxAuiMDIParentFrame::AddWindowMenu(wxMenuBar *pMenuBar)
311 {
312 if (pMenuBar && m_pWindowMenu)
313 {
314 int pos = pMenuBar->FindMenu(wxGetStockLabel(wxID_HELP,wxSTOCK_NOFLAGS));
315 if (pos == wxNOT_FOUND)
316 pMenuBar->Append(m_pWindowMenu, _("&Window"));
317 else
318 pMenuBar->Insert(pos, m_pWindowMenu, _("&Window"));
319 }
320 }
321
322 void wxAuiMDIParentFrame::DoHandleMenu(wxCommandEvent& event)
323 {
324 switch (event.GetId())
325 {
326 case wxWINDOWCLOSE:
327 if (m_pActiveChild)
328 m_pActiveChild->Close();
329 break;
330 case wxWINDOWCLOSEALL:
331 while (m_pActiveChild)
332 {
333 if (!m_pActiveChild->Close())
334 {
335 return; // failure
336 }
337 }
338 break;
339 case wxWINDOWNEXT:
340 ActivateNext();
341 break;
342 case wxWINDOWPREV:
343 ActivatePrevious();
344 break;
345 default:
346 event.Skip();
347 }
348 }
349 #endif // wxUSE_MENUS
350
351 void wxAuiMDIParentFrame::DoGetClientSize(int* width, int* height) const
352 {
353 wxFrame::DoGetClientSize(width, height);
354 }
355
356 void wxAuiMDIParentFrame::Tile(wxOrientation orient)
357 {
358 wxAuiMDIClientWindow* client_window = GetClientWindow();
359 wxASSERT_MSG(client_window, wxT("Missing MDI Client Window"));
360
361 int cur_idx = client_window->GetSelection();
362 if (cur_idx == -1)
363 return;
364
365 if (orient == wxVERTICAL)
366 {
367 client_window->Split(cur_idx, wxLEFT);
368 }
369 else if (orient == wxHORIZONTAL)
370 {
371 client_window->Split(cur_idx, wxTOP);
372 }
373 }
374
375
376 //-----------------------------------------------------------------------------
377 // wxAuiMDIChildFrame
378 //-----------------------------------------------------------------------------
379
380 IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIChildFrame, wxPanel)
381
382 BEGIN_EVENT_TABLE(wxAuiMDIChildFrame, wxPanel)
383 EVT_MENU_HIGHLIGHT_ALL(wxAuiMDIChildFrame::OnMenuHighlight)
384 EVT_ACTIVATE(wxAuiMDIChildFrame::OnActivate)
385 EVT_CLOSE(wxAuiMDIChildFrame::OnCloseWindow)
386 END_EVENT_TABLE()
387
388 wxAuiMDIChildFrame::wxAuiMDIChildFrame()
389 {
390 Init();
391 }
392
393 wxAuiMDIChildFrame::wxAuiMDIChildFrame(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 Init();
402
403 // There are two ways to create an tabbed mdi child fram without
404 // making it the active document. Either Show(false) can be called
405 // before Create() (as is customary on some ports with wxFrame-type
406 // windows), or wxMINIMIZE can be passed in the style flags. Note that
407 // wxAuiMDIChildFrame is not really derived from wxFrame, as wxMDIChildFrame
408 // is, but those are the expected symantics. No style flag is passed
409 // onto the panel underneath.
410 if (style & wxMINIMIZE)
411 m_activate_on_create = false;
412
413 Create(parent, id, title, wxDefaultPosition, size, 0, name);
414 }
415
416 wxAuiMDIChildFrame::~wxAuiMDIChildFrame()
417 {
418 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
419 if (pParentFrame && pParentFrame->GetActiveChild() == this)
420 {
421 pParentFrame->SetActiveChild(NULL);
422 pParentFrame->SetChildMenuBar(NULL);
423 }
424
425 #if wxUSE_MENUS
426 wxDELETE(m_pMenuBar);
427 #endif // wxUSE_MENUS
428 }
429
430 bool wxAuiMDIChildFrame::Create(wxAuiMDIParentFrame* parent,
431 wxWindowID id,
432 const wxString& title,
433 const wxPoint& WXUNUSED(pos),
434 const wxSize& size,
435 long style,
436 const wxString& name)
437 {
438 wxAuiMDIClientWindow* pClientWindow = parent->GetClientWindow();
439 wxASSERT_MSG((pClientWindow != (wxWindow*) NULL), wxT("Missing MDI client window."));
440
441 // see comment in constructor
442 if (style & wxMINIMIZE)
443 m_activate_on_create = false;
444
445 wxSize cli_size = pClientWindow->GetClientSize();
446
447 // create the window off-screen to prevent flicker
448 wxPanel::Create(pClientWindow,
449 id,
450 wxPoint(cli_size.x+1, cli_size.y+1),
451 size,
452 wxNO_BORDER, name);
453
454 DoShow(false);
455
456 SetMDIParentFrame(parent);
457
458 // this is the currently active child
459 parent->SetActiveChild(this);
460
461 m_title = title;
462
463 pClientWindow->AddPage(this, title, m_activate_on_create);
464 pClientWindow->Refresh();
465
466 return true;
467 }
468
469 bool wxAuiMDIChildFrame::Destroy()
470 {
471 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
472 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
473
474 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
475 wxASSERT_MSG(pClientWindow, wxT("Missing MDI Client Window"));
476
477 if (pParentFrame->GetActiveChild() == this)
478 {
479 // deactivate ourself
480 wxActivateEvent event(wxEVT_ACTIVATE, false, GetId());
481 event.SetEventObject(this);
482 GetEventHandler()->ProcessEvent(event);
483
484 pParentFrame->SetActiveChild(NULL);
485 pParentFrame->SetChildMenuBar(NULL);
486 }
487
488 size_t page_count = pClientWindow->GetPageCount();
489 for (size_t pos = 0; pos < page_count; pos++)
490 {
491 if (pClientWindow->GetPage(pos) == this)
492 return pClientWindow->DeletePage(pos);
493 }
494
495 return false;
496 }
497
498 #if wxUSE_MENUS
499 void wxAuiMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
500 {
501 wxMenuBar *pOldMenuBar = m_pMenuBar;
502 m_pMenuBar = menu_bar;
503
504 if (m_pMenuBar)
505 {
506 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
507 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
508
509 m_pMenuBar->SetParent(pParentFrame);
510 if (pParentFrame->GetActiveChild() == this)
511 {
512 // replace current menu bars
513 if (pOldMenuBar)
514 pParentFrame->SetChildMenuBar(NULL);
515 pParentFrame->SetChildMenuBar(this);
516 }
517 }
518 }
519
520 wxMenuBar *wxAuiMDIChildFrame::GetMenuBar() const
521 {
522 return m_pMenuBar;
523 }
524 #endif // wxUSE_MENUS
525
526 void wxAuiMDIChildFrame::SetTitle(const wxString& title)
527 {
528 m_title = title;
529
530 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
531 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
532
533 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
534 if (pClientWindow != NULL)
535 {
536 size_t pos;
537 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
538 {
539 if (pClientWindow->GetPage(pos) == this)
540 {
541 pClientWindow->SetPageText(pos, m_title);
542 break;
543 }
544 }
545 }
546 }
547
548 wxString wxAuiMDIChildFrame::GetTitle() const
549 {
550 return m_title;
551 }
552
553 void wxAuiMDIChildFrame::SetIcons(const wxIconBundle& icons)
554 {
555 // get icon with the system icon size
556 SetIcon(icons.GetIcon(-1));
557 m_icon_bundle = icons;
558 }
559
560 const wxIconBundle& wxAuiMDIChildFrame::GetIcons() const
561 {
562 return m_icon_bundle;
563 }
564
565 void wxAuiMDIChildFrame::SetIcon(const wxIcon& icon)
566 {
567 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
568 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
569
570 m_icon = icon;
571
572 wxBitmap bmp;
573 bmp.CopyFromIcon(m_icon);
574
575 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
576 if (pClientWindow != NULL)
577 {
578 int idx = pClientWindow->GetPageIndex(this);
579
580 if (idx != -1)
581 {
582 pClientWindow->SetPageBitmap((size_t)idx, bmp);
583 }
584 }
585 }
586
587 const wxIcon& wxAuiMDIChildFrame::GetIcon() const
588 {
589 return m_icon;
590 }
591
592
593 void wxAuiMDIChildFrame::Activate()
594 {
595 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
596 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
597
598 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
599
600 if (pClientWindow != NULL)
601 {
602 size_t pos;
603 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
604 {
605 if (pClientWindow->GetPage(pos) == this)
606 {
607 pClientWindow->SetSelection(pos);
608 break;
609 }
610 }
611 }
612 }
613
614 void wxAuiMDIChildFrame::OnMenuHighlight(wxMenuEvent& event)
615 {
616 #if wxUSE_STATUSBAR
617 if (m_pMDIParentFrame)
618 {
619 // we don't have any help text for this item,
620 // but may be the MDI frame does?
621 m_pMDIParentFrame->OnMenuHighlight(event);
622 }
623 #else
624 wxUnusedVar(event);
625 #endif // wxUSE_STATUSBAR
626 }
627
628 void wxAuiMDIChildFrame::OnActivate(wxActivateEvent& WXUNUSED(event))
629 {
630 // do nothing
631 }
632
633 void wxAuiMDIChildFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
634 {
635 Destroy();
636 }
637
638 void wxAuiMDIChildFrame::SetMDIParentFrame(wxAuiMDIParentFrame* parentFrame)
639 {
640 m_pMDIParentFrame = parentFrame;
641 }
642
643 wxAuiMDIParentFrame* wxAuiMDIChildFrame::GetMDIParentFrame() const
644 {
645 return m_pMDIParentFrame;
646 }
647
648 void wxAuiMDIChildFrame::Init()
649 {
650 m_activate_on_create = true;
651 m_pMDIParentFrame = NULL;
652 #if wxUSE_MENUS
653 m_pMenuBar = NULL;
654 #endif // wxUSE_MENUS
655 }
656
657 bool wxAuiMDIChildFrame::Show(bool show)
658 {
659 m_activate_on_create = show;
660
661 // do nothing
662 return true;
663 }
664
665 void wxAuiMDIChildFrame::DoShow(bool show)
666 {
667 wxWindow::Show(show);
668 }
669
670 void wxAuiMDIChildFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags)
671 {
672 m_mdi_newrect = wxRect(x, y, width, height);
673 #ifdef __WXGTK__
674 wxPanel::DoSetSize(x,y,width, height, sizeFlags);
675 #else
676 wxUnusedVar(sizeFlags);
677 #endif
678 }
679
680 void wxAuiMDIChildFrame::DoMoveWindow(int x, int y, int width, int height)
681 {
682 m_mdi_newrect = wxRect(x, y, width, height);
683 }
684
685 void wxAuiMDIChildFrame::ApplyMDIChildFrameRect()
686 {
687 if (m_mdi_currect != m_mdi_newrect)
688 {
689 wxPanel::DoMoveWindow(m_mdi_newrect.x, m_mdi_newrect.y,
690 m_mdi_newrect.width, m_mdi_newrect.height);
691 m_mdi_currect = m_mdi_newrect;
692 }
693 }
694
695
696 //-----------------------------------------------------------------------------
697 // wxAuiMDIClientWindow
698 //-----------------------------------------------------------------------------
699
700 IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIClientWindow, wxAuiNotebook)
701
702 BEGIN_EVENT_TABLE(wxAuiMDIClientWindow, wxAuiNotebook)
703 EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, wxAuiMDIClientWindow::OnPageChanged)
704 EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, wxAuiMDIClientWindow::OnPageClose)
705 EVT_SIZE(wxAuiMDIClientWindow::OnSize)
706 END_EVENT_TABLE()
707
708 wxAuiMDIClientWindow::wxAuiMDIClientWindow()
709 {
710 }
711
712 wxAuiMDIClientWindow::wxAuiMDIClientWindow(wxAuiMDIParentFrame* parent, long style)
713 {
714 CreateClient(parent, style);
715 }
716
717 wxAuiMDIClientWindow::~wxAuiMDIClientWindow()
718 {
719 DestroyChildren();
720 }
721
722 bool wxAuiMDIClientWindow::CreateClient(wxAuiMDIParentFrame* parent, long style)
723 {
724 SetWindowStyleFlag(style);
725
726 wxSize caption_icon_size =
727 wxSize(wxSystemSettings::GetMetric(wxSYS_SMALLICON_X),
728 wxSystemSettings::GetMetric(wxSYS_SMALLICON_Y));
729 SetUniformBitmapSize(caption_icon_size);
730
731 if (!wxAuiNotebook::Create(parent,
732 wxID_ANY,
733 wxPoint(0,0),
734 wxSize(100, 100),
735 wxAUI_NB_DEFAULT_STYLE | wxNO_BORDER))
736 {
737 return false;
738 }
739
740 wxColour bkcolour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
741 SetOwnBackgroundColour(bkcolour);
742
743 m_mgr.GetArtProvider()->SetColour(wxAUI_DOCKART_BACKGROUND_COLOUR, bkcolour);
744
745 return true;
746 }
747
748 int wxAuiMDIClientWindow::SetSelection(size_t nPage)
749 {
750 return wxAuiNotebook::SetSelection(nPage);
751 }
752
753 void wxAuiMDIClientWindow::PageChanged(int old_selection, int new_selection)
754 {
755 // don't do anything if the page doesn't actually change
756 if (old_selection == new_selection)
757 return;
758
759 /*
760 // don't do anything if the new page is already active
761 if (new_selection != -1)
762 {
763 wxAuiMDIChildFrame* child = (wxAuiMDIChildFrame*)GetPage(new_selection);
764 if (child->GetMDIParentFrame()->GetActiveChild() == child)
765 return;
766 }*/
767
768
769 // notify old active child that it has been deactivated
770 if (old_selection != -1)
771 {
772 wxAuiMDIChildFrame* old_child = (wxAuiMDIChildFrame*)GetPage(old_selection);
773 wxASSERT_MSG(old_child, wxT("wxAuiMDIClientWindow::PageChanged - null page pointer"));
774
775 wxActivateEvent event(wxEVT_ACTIVATE, false, old_child->GetId());
776 event.SetEventObject(old_child);
777 old_child->GetEventHandler()->ProcessEvent(event);
778 }
779
780 // notify new active child that it has been activated
781 if (new_selection != -1)
782 {
783 wxAuiMDIChildFrame* active_child = (wxAuiMDIChildFrame*)GetPage(new_selection);
784 wxASSERT_MSG(active_child, wxT("wxAuiMDIClientWindow::PageChanged - null page pointer"));
785
786 wxActivateEvent event(wxEVT_ACTIVATE, true, active_child->GetId());
787 event.SetEventObject(active_child);
788 active_child->GetEventHandler()->ProcessEvent(event);
789
790 if (active_child->GetMDIParentFrame())
791 {
792 active_child->GetMDIParentFrame()->SetActiveChild(active_child);
793 active_child->GetMDIParentFrame()->SetChildMenuBar(active_child);
794 }
795 }
796
797
798 }
799
800 void wxAuiMDIClientWindow::OnPageClose(wxAuiNotebookEvent& evt)
801 {
802 wxAuiMDIChildFrame* wnd;
803 wnd = static_cast<wxAuiMDIChildFrame*>(GetPage(evt.GetSelection()));
804
805 wnd->Close();
806
807 // regardless of the result of wnd->Close(), we've
808 // already taken care of the close operations, so
809 // suppress further processing
810 evt.Veto();
811 }
812
813 void wxAuiMDIClientWindow::OnPageChanged(wxAuiNotebookEvent& evt)
814 {
815 PageChanged(evt.GetOldSelection(), evt.GetSelection());
816 }
817
818 void wxAuiMDIClientWindow::OnSize(wxSizeEvent& evt)
819 {
820 wxAuiNotebook::OnSize(evt);
821
822 for (size_t pos = 0; pos < GetPageCount(); pos++)
823 ((wxAuiMDIChildFrame *)GetPage(pos))->ApplyMDIChildFrameRect();
824 }
825
826 #endif //wxUSE_AUI
827 #endif // wxUSE_MDI