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