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