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: tabmdi.cpp 55206 2008-08-23 16:19:16Z VZ $
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
IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIParentFrame,wxFrame)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
wxAuiMDIParentFrame(wxWindow * parent,wxWindowID id,const wxString & title,const wxPoint & pos,const wxSize & size,long style,const wxString & name)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
~wxAuiMDIParentFrame()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
Create(wxWindow * parent,wxWindowID id,const wxString & title,const wxPoint & pos,const wxSize & size,long style,const wxString & name)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
SetArtProvider(wxAuiTabArt * provider)119 void wxAuiMDIParentFrame::SetArtProvider(wxAuiTabArt* provider)
120 {
121 if (m_pClientWindow)
122 {
123 m_pClientWindow->SetArtProvider(provider);
124 }
125 }
126
GetArtProvider()127 wxAuiTabArt* wxAuiMDIParentFrame::GetArtProvider()
128 {
129 if (!m_pClientWindow)
130 return NULL;
131
132 return m_pClientWindow->GetArtProvider();
133 }
134
GetNotebook() const135 wxAuiNotebook* wxAuiMDIParentFrame::GetNotebook() const
136 {
137 return wx_static_cast(wxAuiNotebook*, m_pClientWindow);
138 }
139
140
141
142 #if wxUSE_MENUS
SetWindowMenu(wxMenu * pMenu)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
SetMenuBar(wxMenuBar * pMenuBar)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
SetChildMenuBar(wxAuiMDIChildFrame * pChild)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
ProcessEvent(wxEvent & event)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
GetActiveChild() const238 wxAuiMDIChildFrame *wxAuiMDIParentFrame::GetActiveChild() const
239 {
240 return m_pActiveChild;
241 }
242
SetActiveChild(wxAuiMDIChildFrame * pChildFrame)243 void wxAuiMDIParentFrame::SetActiveChild(wxAuiMDIChildFrame* pChildFrame)
244 {
245 m_pActiveChild = pChildFrame;
246 }
247
GetClientWindow() const248 wxAuiMDIClientWindow *wxAuiMDIParentFrame::GetClientWindow() const
249 {
250 return m_pClientWindow;
251 }
252
OnCreateClient()253 wxAuiMDIClientWindow *wxAuiMDIParentFrame::OnCreateClient()
254 {
255 m_pClientWindow = new wxAuiMDIClientWindow( this );
256 return m_pClientWindow;
257 }
258
ActivateNext()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
ActivatePrevious()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
Init()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
RemoveWindowMenu(wxMenuBar * pMenuBar)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
AddWindowMenu(wxMenuBar * pMenuBar)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
DoHandleMenu(wxCommandEvent & event)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
DoGetClientSize(int * width,int * height) const351 void wxAuiMDIParentFrame::DoGetClientSize(int* width, int* height) const
352 {
353 wxFrame::DoGetClientSize(width, height);
354 }
355
Tile(wxOrientation orient)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
IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIChildFrame,wxPanel)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
wxAuiMDIChildFrame(wxAuiMDIParentFrame * parent,wxWindowID id,const wxString & title,const wxPoint & WXUNUSED (pos),const wxSize & size,long style,const wxString & name)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
~wxAuiMDIChildFrame()416 wxAuiMDIChildFrame::~wxAuiMDIChildFrame()
417 {
418 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
419 if (pParentFrame)
420 {
421 if (pParentFrame->GetActiveChild() == this)
422 {
423 pParentFrame->SetActiveChild(NULL);
424 pParentFrame->SetChildMenuBar(NULL);
425 }
426 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
427 wxASSERT(pClientWindow);
428 int idx = pClientWindow->GetPageIndex(this);
429 if (idx != wxNOT_FOUND)
430 {
431 pClientWindow->RemovePage(idx);
432 }
433 }
434
435 #if wxUSE_MENUS
436 wxDELETE(m_pMenuBar);
437 #endif // wxUSE_MENUS
438 }
439
Create(wxAuiMDIParentFrame * parent,wxWindowID id,const wxString & title,const wxPoint & WXUNUSED (pos),const wxSize & size,long style,const wxString & name)440 bool wxAuiMDIChildFrame::Create(wxAuiMDIParentFrame* parent,
441 wxWindowID id,
442 const wxString& title,
443 const wxPoint& WXUNUSED(pos),
444 const wxSize& size,
445 long style,
446 const wxString& name)
447 {
448 wxAuiMDIClientWindow* pClientWindow = parent->GetClientWindow();
449 wxASSERT_MSG((pClientWindow != (wxWindow*) NULL), wxT("Missing MDI client window."));
450
451 // see comment in constructor
452 if (style & wxMINIMIZE)
453 m_activate_on_create = false;
454
455 wxSize cli_size = pClientWindow->GetClientSize();
456
457 // create the window off-screen to prevent flicker
458 wxPanel::Create(pClientWindow,
459 id,
460 wxPoint(cli_size.x+1, cli_size.y+1),
461 size,
462 wxNO_BORDER, name);
463
464 DoShow(false);
465
466 SetMDIParentFrame(parent);
467
468 // this is the currently active child
469 parent->SetActiveChild(this);
470
471 m_title = title;
472
473 pClientWindow->AddPage(this, title, m_activate_on_create);
474 pClientWindow->Refresh();
475
476 return true;
477 }
478
Destroy()479 bool wxAuiMDIChildFrame::Destroy()
480 {
481 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
482 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
483
484 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
485 wxASSERT_MSG(pClientWindow, wxT("Missing MDI Client Window"));
486
487 if (pParentFrame->GetActiveChild() == this)
488 {
489 // deactivate ourself
490 wxActivateEvent event(wxEVT_ACTIVATE, false, GetId());
491 event.SetEventObject(this);
492 GetEventHandler()->ProcessEvent(event);
493
494 pParentFrame->SetActiveChild(NULL);
495 pParentFrame->SetChildMenuBar(NULL);
496 }
497
498 size_t page_count = pClientWindow->GetPageCount();
499 for (size_t pos = 0; pos < page_count; pos++)
500 {
501 if (pClientWindow->GetPage(pos) == this)
502 return pClientWindow->DeletePage(pos);
503 }
504
505 return false;
506 }
507
508 #if wxUSE_MENUS
SetMenuBar(wxMenuBar * menu_bar)509 void wxAuiMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
510 {
511 wxMenuBar *pOldMenuBar = m_pMenuBar;
512 m_pMenuBar = menu_bar;
513
514 if (m_pMenuBar)
515 {
516 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
517 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
518
519 m_pMenuBar->SetParent(pParentFrame);
520 if (pParentFrame->GetActiveChild() == this)
521 {
522 // replace current menu bars
523 if (pOldMenuBar)
524 pParentFrame->SetChildMenuBar(NULL);
525 pParentFrame->SetChildMenuBar(this);
526 }
527 }
528 }
529
GetMenuBar() const530 wxMenuBar *wxAuiMDIChildFrame::GetMenuBar() const
531 {
532 return m_pMenuBar;
533 }
534 #endif // wxUSE_MENUS
535
SetTitle(const wxString & title)536 void wxAuiMDIChildFrame::SetTitle(const wxString& title)
537 {
538 m_title = title;
539
540 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
541 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
542
543 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
544 if (pClientWindow != NULL)
545 {
546 size_t pos;
547 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
548 {
549 if (pClientWindow->GetPage(pos) == this)
550 {
551 pClientWindow->SetPageText(pos, m_title);
552 break;
553 }
554 }
555 }
556 }
557
GetTitle() const558 wxString wxAuiMDIChildFrame::GetTitle() const
559 {
560 return m_title;
561 }
562
SetIcons(const wxIconBundle & icons)563 void wxAuiMDIChildFrame::SetIcons(const wxIconBundle& icons)
564 {
565 // get icon with the system icon size
566 SetIcon(icons.GetIcon(-1));
567 m_icon_bundle = icons;
568 }
569
GetIcons() const570 const wxIconBundle& wxAuiMDIChildFrame::GetIcons() const
571 {
572 return m_icon_bundle;
573 }
574
SetIcon(const wxIcon & icon)575 void wxAuiMDIChildFrame::SetIcon(const wxIcon& icon)
576 {
577 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
578 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
579
580 m_icon = icon;
581
582 wxBitmap bmp;
583 bmp.CopyFromIcon(m_icon);
584
585 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
586 if (pClientWindow != NULL)
587 {
588 int idx = pClientWindow->GetPageIndex(this);
589
590 if (idx != -1)
591 {
592 pClientWindow->SetPageBitmap((size_t)idx, bmp);
593 }
594 }
595 }
596
GetIcon() const597 const wxIcon& wxAuiMDIChildFrame::GetIcon() const
598 {
599 return m_icon;
600 }
601
602
Activate()603 void wxAuiMDIChildFrame::Activate()
604 {
605 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
606 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
607
608 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
609
610 if (pClientWindow != NULL)
611 {
612 size_t pos;
613 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
614 {
615 if (pClientWindow->GetPage(pos) == this)
616 {
617 pClientWindow->SetSelection(pos);
618 break;
619 }
620 }
621 }
622 }
623
OnMenuHighlight(wxMenuEvent & event)624 void wxAuiMDIChildFrame::OnMenuHighlight(wxMenuEvent& event)
625 {
626 #if wxUSE_STATUSBAR
627 if (m_pMDIParentFrame)
628 {
629 // we don't have any help text for this item,
630 // but may be the MDI frame does?
631 m_pMDIParentFrame->OnMenuHighlight(event);
632 }
633 #else
634 wxUnusedVar(event);
635 #endif // wxUSE_STATUSBAR
636 }
637
OnActivate(wxActivateEvent & WXUNUSED (event))638 void wxAuiMDIChildFrame::OnActivate(wxActivateEvent& WXUNUSED(event))
639 {
640 // do nothing
641 }
642
OnCloseWindow(wxCloseEvent & WXUNUSED (event))643 void wxAuiMDIChildFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
644 {
645 Destroy();
646 }
647
SetMDIParentFrame(wxAuiMDIParentFrame * parentFrame)648 void wxAuiMDIChildFrame::SetMDIParentFrame(wxAuiMDIParentFrame* parentFrame)
649 {
650 m_pMDIParentFrame = parentFrame;
651 }
652
GetMDIParentFrame() const653 wxAuiMDIParentFrame* wxAuiMDIChildFrame::GetMDIParentFrame() const
654 {
655 return m_pMDIParentFrame;
656 }
657
Init()658 void wxAuiMDIChildFrame::Init()
659 {
660 m_activate_on_create = true;
661 m_pMDIParentFrame = NULL;
662 #if wxUSE_MENUS
663 m_pMenuBar = NULL;
664 #endif // wxUSE_MENUS
665 }
666
Show(bool show)667 bool wxAuiMDIChildFrame::Show(bool show)
668 {
669 m_activate_on_create = show;
670
671 // do nothing
672 return true;
673 }
674
DoShow(bool show)675 void wxAuiMDIChildFrame::DoShow(bool show)
676 {
677 wxWindow::Show(show);
678 }
679
DoSetSize(int x,int y,int width,int height,int sizeFlags)680 void wxAuiMDIChildFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags)
681 {
682 m_mdi_newrect = wxRect(x, y, width, height);
683 #ifdef __WXGTK__
684 wxPanel::DoSetSize(x,y,width, height, sizeFlags);
685 #else
686 wxUnusedVar(sizeFlags);
687 #endif
688 }
689
DoMoveWindow(int x,int y,int width,int height)690 void wxAuiMDIChildFrame::DoMoveWindow(int x, int y, int width, int height)
691 {
692 m_mdi_newrect = wxRect(x, y, width, height);
693 }
694
ApplyMDIChildFrameRect()695 void wxAuiMDIChildFrame::ApplyMDIChildFrameRect()
696 {
697 if (m_mdi_currect != m_mdi_newrect)
698 {
699 wxPanel::DoMoveWindow(m_mdi_newrect.x, m_mdi_newrect.y,
700 m_mdi_newrect.width, m_mdi_newrect.height);
701 m_mdi_currect = m_mdi_newrect;
702 }
703 }
704
705
706 //-----------------------------------------------------------------------------
707 // wxAuiMDIClientWindow
708 //-----------------------------------------------------------------------------
709
IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIClientWindow,wxAuiNotebook)710 IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIClientWindow, wxAuiNotebook)
711
712 BEGIN_EVENT_TABLE(wxAuiMDIClientWindow, wxAuiNotebook)
713 EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, wxAuiMDIClientWindow::OnPageChanged)
714 EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, wxAuiMDIClientWindow::OnPageClose)
715 EVT_SIZE(wxAuiMDIClientWindow::OnSize)
716 END_EVENT_TABLE()
717
718 wxAuiMDIClientWindow::wxAuiMDIClientWindow()
719 {
720 }
721
wxAuiMDIClientWindow(wxAuiMDIParentFrame * parent,long style)722 wxAuiMDIClientWindow::wxAuiMDIClientWindow(wxAuiMDIParentFrame* parent, long style)
723 {
724 CreateClient(parent, style);
725 }
726
~wxAuiMDIClientWindow()727 wxAuiMDIClientWindow::~wxAuiMDIClientWindow()
728 {
729 }
730
CreateClient(wxAuiMDIParentFrame * parent,long style)731 bool wxAuiMDIClientWindow::CreateClient(wxAuiMDIParentFrame* parent, long style)
732 {
733 SetWindowStyleFlag(style);
734
735 wxSize caption_icon_size =
736 wxSize(wxSystemSettings::GetMetric(wxSYS_SMALLICON_X),
737 wxSystemSettings::GetMetric(wxSYS_SMALLICON_Y));
738 SetUniformBitmapSize(caption_icon_size);
739
740 if (!wxAuiNotebook::Create(parent,
741 wxID_ANY,
742 wxPoint(0,0),
743 wxSize(100, 100),
744 wxAUI_NB_DEFAULT_STYLE | wxNO_BORDER))
745 {
746 return false;
747 }
748
749 wxColour bkcolour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
750 SetOwnBackgroundColour(bkcolour);
751
752 m_mgr.GetArtProvider()->SetColour(wxAUI_DOCKART_BACKGROUND_COLOUR, bkcolour);
753
754 return true;
755 }
756
SetSelection(size_t nPage)757 int wxAuiMDIClientWindow::SetSelection(size_t nPage)
758 {
759 return wxAuiNotebook::SetSelection(nPage);
760 }
761
PageChanged(int old_selection,int new_selection)762 void wxAuiMDIClientWindow::PageChanged(int old_selection, int new_selection)
763 {
764 // don't do anything if the page doesn't actually change
765 if (old_selection == new_selection)
766 return;
767
768 /*
769 // don't do anything if the new page is already active
770 if (new_selection != -1)
771 {
772 wxAuiMDIChildFrame* child = (wxAuiMDIChildFrame*)GetPage(new_selection);
773 if (child->GetMDIParentFrame()->GetActiveChild() == child)
774 return;
775 }*/
776
777
778 // notify old active child that it has been deactivated
779 if ((old_selection != -1) && (old_selection < (int)GetPageCount()))
780 {
781 wxAuiMDIChildFrame* old_child = (wxAuiMDIChildFrame*)GetPage(old_selection);
782 wxASSERT_MSG(old_child, wxT("wxAuiMDIClientWindow::PageChanged - null page pointer"));
783
784 wxActivateEvent event(wxEVT_ACTIVATE, false, old_child->GetId());
785 event.SetEventObject(old_child);
786 old_child->GetEventHandler()->ProcessEvent(event);
787 }
788
789 // notify new active child that it has been activated
790 if (new_selection != -1)
791 {
792 wxAuiMDIChildFrame* active_child = (wxAuiMDIChildFrame*)GetPage(new_selection);
793 wxASSERT_MSG(active_child, wxT("wxAuiMDIClientWindow::PageChanged - null page pointer"));
794
795 wxActivateEvent event(wxEVT_ACTIVATE, true, active_child->GetId());
796 event.SetEventObject(active_child);
797 active_child->GetEventHandler()->ProcessEvent(event);
798
799 if (active_child->GetMDIParentFrame())
800 {
801 active_child->GetMDIParentFrame()->SetActiveChild(active_child);
802 active_child->GetMDIParentFrame()->SetChildMenuBar(active_child);
803 }
804 }
805
806
807 }
808
OnPageClose(wxAuiNotebookEvent & evt)809 void wxAuiMDIClientWindow::OnPageClose(wxAuiNotebookEvent& evt)
810 {
811 wxAuiMDIChildFrame*
812 wnd = wx_static_cast(wxAuiMDIChildFrame*, GetPage(evt.GetSelection()));
813
814 wnd->Close();
815
816 // regardless of the result of wnd->Close(), we've
817 // already taken care of the close operations, so
818 // suppress further processing
819 evt.Veto();
820 }
821
OnPageChanged(wxAuiNotebookEvent & evt)822 void wxAuiMDIClientWindow::OnPageChanged(wxAuiNotebookEvent& evt)
823 {
824 PageChanged(evt.GetOldSelection(), evt.GetSelection());
825 }
826
OnSize(wxSizeEvent & evt)827 void wxAuiMDIClientWindow::OnSize(wxSizeEvent& evt)
828 {
829 wxAuiNotebook::OnSize(evt);
830
831 for (size_t pos = 0; pos < GetPageCount(); pos++)
832 ((wxAuiMDIChildFrame *)GetPage(pos))->ApplyMDIChildFrameRect();
833 }
834
835 #endif // wxUSE_MDI
836
837 #endif // wxUSE_AUI
838