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