]> git.saurik.com Git - wxWidgets.git/blame - src/aui/tabmdi.cpp
Update from Hartwig for OS X implementation
[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
b0a54b8a 85 wxDELETE(m_pMyMenuBar);
cd05bf23 86 RemoveWindowMenu(GetMenuBar());
b0a54b8a 87 wxDELETE(m_pWindowMenu);
cd05bf23
BW
88#endif // wxUSE_MENUS
89}
90
a3a5df9d 91bool wxAuiMDIParentFrame::Create(wxWindow *parent,
cd05bf23
BW
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
f39fddcd
BW
118
119void wxAuiMDIParentFrame::SetArtProvider(wxAuiTabArt* provider)
120{
121 if (m_pClientWindow)
122 {
123 m_pClientWindow->SetArtProvider(provider);
124 }
125}
126
127wxAuiTabArt* wxAuiMDIParentFrame::GetArtProvider()
128{
129 if (!m_pClientWindow)
130 return NULL;
ccc8c01a 131
f39fddcd
BW
132 return m_pClientWindow->GetArtProvider();
133}
134
135wxAuiNotebook* wxAuiMDIParentFrame::GetNotebook() const
136{
137 return static_cast<wxAuiNotebook*>(m_pClientWindow);
138}
139
140
141
cd05bf23 142#if wxUSE_MENUS
a3a5df9d 143void wxAuiMDIParentFrame::SetWindowMenu(wxMenu* pMenu)
cd05bf23
BW
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
a3a5df9d 161void wxAuiMDIParentFrame::SetMenuBar(wxMenuBar* pMenuBar)
cd05bf23
BW
162{
163 // Remove the Window menu from the old menu bar
164 RemoveWindowMenu(GetMenuBar());
4444d148 165
cd05bf23
BW
166 // Add the Window menu to the new menu bar.
167 AddWindowMenu(pMenuBar);
4444d148 168
cd05bf23 169 wxFrame::SetMenuBar(pMenuBar);
b0a54b8a 170 //m_pMyMenuBar = GetMenuBar();
cd05bf23
BW
171}
172#endif // wxUSE_MENUS
173
a3a5df9d 174void wxAuiMDIParentFrame::SetChildMenuBar(wxAuiMDIChildFrame* pChild)
cd05bf23
BW
175{
176#if wxUSE_MENUS
177 if (!pChild)
178 {
179 // No Child, set Our menu bar back.
092d7f88
BW
180 if (m_pMyMenuBar)
181 SetMenuBar(m_pMyMenuBar);
cedd7b22 182 else
092d7f88 183 SetMenuBar(GetMenuBar());
cd05bf23
BW
184
185 // Make sure we know our menu bar is in use
b0a54b8a 186 m_pMyMenuBar = NULL;
cd05bf23 187 }
cedd7b22 188 else
cd05bf23
BW
189 {
190 if (pChild->GetMenuBar() == NULL)
191 return;
ee0a94cf 192
cd05bf23
BW
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
a3a5df9d 202bool wxAuiMDIParentFrame::ProcessEvent(wxEvent& event)
cd05bf23 203{
7e1f1a13
BW
204 // stops the same event being processed repeatedly
205 if (m_pLastEvt == &event)
cd05bf23 206 return false;
7e1f1a13 207 m_pLastEvt = &event;
ccc8c01a 208
7e1f1a13 209 // let the active child (if any) process the event first.
cd05bf23
BW
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
cd05bf23
BW
225 if (!res)
226 {
7e1f1a13
BW
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
cd05bf23
BW
230 res = wxEvtHandler::ProcessEvent(event);
231 }
232
7e1f1a13 233 m_pLastEvt = NULL;
cd05bf23
BW
234
235 return res;
236}
237
a3a5df9d 238wxAuiMDIChildFrame *wxAuiMDIParentFrame::GetActiveChild() const
cd05bf23
BW
239{
240 return m_pActiveChild;
241}
242
a3a5df9d 243void wxAuiMDIParentFrame::SetActiveChild(wxAuiMDIChildFrame* pChildFrame)
cd05bf23
BW
244{
245 m_pActiveChild = pChildFrame;
246}
247
8856768e 248wxAuiMDIClientWindow *wxAuiMDIParentFrame::GetClientWindow() const
cd05bf23
BW
249{
250 return m_pClientWindow;
251}
252
8856768e 253wxAuiMDIClientWindow *wxAuiMDIParentFrame::OnCreateClient()
cd05bf23 254{
8856768e 255 m_pClientWindow = new wxAuiMDIClientWindow( this );
cd05bf23
BW
256 return m_pClientWindow;
257}
258
a3a5df9d 259void wxAuiMDIParentFrame::ActivateNext()
cd05bf23 260{
4444d148 261 if (m_pClientWindow && m_pClientWindow->GetSelection() != wxNOT_FOUND)
cd05bf23
BW
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
a3a5df9d 271void wxAuiMDIParentFrame::ActivatePrevious()
cd05bf23 272{
4444d148 273 if (m_pClientWindow && m_pClientWindow->GetSelection() != wxNOT_FOUND)
cd05bf23
BW
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
a3a5df9d 283void wxAuiMDIParentFrame::Init()
cd05bf23 284{
7e1f1a13 285 m_pLastEvt = NULL;
cd05bf23
BW
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
a3a5df9d 295void wxAuiMDIParentFrame::RemoveWindowMenu(wxMenuBar* pMenuBar)
cd05bf23
BW
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
a3a5df9d 310void wxAuiMDIParentFrame::AddWindowMenu(wxMenuBar *pMenuBar)
cd05bf23
BW
311{
312 if (pMenuBar && m_pWindowMenu)
313 {
ee0a94cf 314 int pos = pMenuBar->FindMenu(wxGetStockLabel(wxID_HELP,wxSTOCK_NOFLAGS));
cd05bf23
BW
315 if (pos == wxNOT_FOUND)
316 pMenuBar->Append(m_pWindowMenu, _("&Window"));
cedd7b22 317 else
cd05bf23
BW
318 pMenuBar->Insert(pos, m_pWindowMenu, _("&Window"));
319 }
320}
321
a3a5df9d 322void wxAuiMDIParentFrame::DoHandleMenu(wxCommandEvent& event)
cd05bf23
BW
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 }
cd05bf23
BW
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
a3a5df9d 351void wxAuiMDIParentFrame::DoGetClientSize(int* width, int* height) const
cd05bf23
BW
352{
353 wxFrame::DoGetClientSize(width, height);
354}
355
d606b6e9
BW
356void wxAuiMDIParentFrame::Tile(wxOrientation orient)
357{
358 wxAuiMDIClientWindow* client_window = GetClientWindow();
359 wxASSERT_MSG(client_window, wxT("Missing MDI Client Window"));
ccc8c01a 360
d606b6e9
BW
361 int cur_idx = client_window->GetSelection();
362 if (cur_idx == -1)
363 return;
ccc8c01a 364
d606b6e9
BW
365 if (orient == wxVERTICAL)
366 {
367 client_window->Split(cur_idx, wxLEFT);
368 }
cedd7b22 369 else if (orient == wxHORIZONTAL)
d606b6e9
BW
370 {
371 client_window->Split(cur_idx, wxTOP);
372 }
373}
374
375
cd05bf23 376//-----------------------------------------------------------------------------
a3a5df9d 377// wxAuiMDIChildFrame
cd05bf23
BW
378//-----------------------------------------------------------------------------
379
a3a5df9d 380IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIChildFrame, wxPanel)
cd05bf23 381
a3a5df9d
BW
382BEGIN_EVENT_TABLE(wxAuiMDIChildFrame, wxPanel)
383 EVT_MENU_HIGHLIGHT_ALL(wxAuiMDIChildFrame::OnMenuHighlight)
384 EVT_ACTIVATE(wxAuiMDIChildFrame::OnActivate)
385 EVT_CLOSE(wxAuiMDIChildFrame::OnCloseWindow)
cd05bf23
BW
386END_EVENT_TABLE()
387
a3a5df9d 388wxAuiMDIChildFrame::wxAuiMDIChildFrame()
cd05bf23
BW
389{
390 Init();
391}
392
a3a5df9d 393wxAuiMDIChildFrame::wxAuiMDIChildFrame(wxAuiMDIParentFrame *parent,
cd05bf23
BW
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();
ccc8c01a 402
e7e324be
BW
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;
ccc8c01a 412
e7e324be 413 Create(parent, id, title, wxDefaultPosition, size, 0, name);
cd05bf23
BW
414}
415
a3a5df9d 416wxAuiMDIChildFrame::~wxAuiMDIChildFrame()
cd05bf23 417{
b0a54b8a
RD
418 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
419 if (pParentFrame && pParentFrame->GetActiveChild() == this)
420 {
421 pParentFrame->SetActiveChild(NULL);
422 pParentFrame->SetChildMenuBar(NULL);
423 }
ccc8c01a 424
cd05bf23
BW
425#if wxUSE_MENUS
426 wxDELETE(m_pMenuBar);
427#endif // wxUSE_MENUS
428}
429
a3a5df9d 430bool wxAuiMDIChildFrame::Create(wxAuiMDIParentFrame* parent,
cd05bf23
BW
431 wxWindowID id,
432 const wxString& title,
433 const wxPoint& WXUNUSED(pos),
434 const wxSize& size,
435 long style,
436 const wxString& name)
437{
8856768e 438 wxAuiMDIClientWindow* pClientWindow = parent->GetClientWindow();
cd05bf23
BW
439 wxASSERT_MSG((pClientWindow != (wxWindow*) NULL), wxT("Missing MDI client window."));
440
e7e324be
BW
441 // see comment in constructor
442 if (style & wxMINIMIZE)
443 m_activate_on_create = false;
444
ea53a601
BW
445 wxSize cli_size = pClientWindow->GetClientSize();
446
447 // create the window off-screen to prevent flicker
448 wxPanel::Create(pClientWindow,
cedd7b22
PC
449 id,
450 wxPoint(cli_size.x+1, cli_size.y+1),
451 size,
452 wxNO_BORDER, name);
e7e324be
BW
453
454 DoShow(false);
cd05bf23
BW
455
456 SetMDIParentFrame(parent);
457
458 // this is the currently active child
459 parent->SetActiveChild(this);
460
461 m_title = title;
462
e7e324be 463 pClientWindow->AddPage(this, title, m_activate_on_create);
cd05bf23 464 pClientWindow->Refresh();
ccc8c01a 465
cd05bf23
BW
466 return true;
467}
468
a3a5df9d 469bool wxAuiMDIChildFrame::Destroy()
cd05bf23 470{
a3a5df9d 471 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
cd05bf23 472 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
4444d148 473
8856768e 474 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
cd05bf23 475 wxASSERT_MSG(pClientWindow, wxT("Missing MDI Client Window"));
4444d148 476
cd05bf23
BW
477 if (pParentFrame->GetActiveChild() == this)
478 {
c5e2ca7c
BW
479 // deactivate ourself
480 wxActivateEvent event(wxEVT_ACTIVATE, false, GetId());
481 event.SetEventObject(this);
482 GetEventHandler()->ProcessEvent(event);
ccc8c01a 483
cd05bf23
BW
484 pParentFrame->SetActiveChild(NULL);
485 pParentFrame->SetChildMenuBar(NULL);
cd05bf23 486 }
4444d148 487
c5e2ca7c 488 size_t page_count = pClientWindow->GetPageCount();
d3b647c2 489 for (size_t pos = 0; pos < page_count; pos++)
cd05bf23
BW
490 {
491 if (pClientWindow->GetPage(pos) == this)
492 return pClientWindow->DeletePage(pos);
493 }
4444d148 494
cd05bf23
BW
495 return false;
496}
497
cd05bf23 498#if wxUSE_MENUS
a3a5df9d 499void wxAuiMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
cd05bf23
BW
500{
501 wxMenuBar *pOldMenuBar = m_pMenuBar;
502 m_pMenuBar = menu_bar;
503
504 if (m_pMenuBar)
505 {
a3a5df9d 506 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
cd05bf23
BW
507 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
508
509 m_pMenuBar->SetParent(pParentFrame);
510 if (pParentFrame->GetActiveChild() == this)
511 {
512 // replace current menu bars
513 if (pOldMenuBar)
514 pParentFrame->SetChildMenuBar(NULL);
515 pParentFrame->SetChildMenuBar(this);
516 }
517 }
518}
519
a3a5df9d 520wxMenuBar *wxAuiMDIChildFrame::GetMenuBar() const
cd05bf23
BW
521{
522 return m_pMenuBar;
523}
524#endif // wxUSE_MENUS
525
a3a5df9d 526void wxAuiMDIChildFrame::SetTitle(const wxString& title)
cd05bf23
BW
527{
528 m_title = title;
529
a3a5df9d 530 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
cd05bf23
BW
531 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
532
8856768e 533 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
cd05bf23
BW
534 if (pClientWindow != NULL)
535 {
536 size_t pos;
537 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
538 {
539 if (pClientWindow->GetPage(pos) == this)
540 {
541 pClientWindow->SetPageText(pos, m_title);
542 break;
543 }
544 }
545 }
546}
547
a3a5df9d 548wxString wxAuiMDIChildFrame::GetTitle() const
cd05bf23
BW
549{
550 return m_title;
551}
552
e0dc13d4
BW
553void wxAuiMDIChildFrame::SetIcons(const wxIconBundle& icons)
554{
555 // get icon with the system icon size
556 SetIcon(icons.GetIcon(-1));
557 m_icon_bundle = icons;
558}
559
560const wxIconBundle& wxAuiMDIChildFrame::GetIcons() const
561{
562 return m_icon_bundle;
563}
564
565void wxAuiMDIChildFrame::SetIcon(const wxIcon& icon)
566{
567 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
568 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
569
570 m_icon = icon;
ccc8c01a 571
e0dc13d4
BW
572 wxBitmap bmp;
573 bmp.CopyFromIcon(m_icon);
ccc8c01a 574
e0dc13d4
BW
575 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
576 if (pClientWindow != NULL)
577 {
578 int idx = pClientWindow->GetPageIndex(this);
ccc8c01a 579
e0dc13d4
BW
580 if (idx != -1)
581 {
582 pClientWindow->SetPageBitmap((size_t)idx, bmp);
583 }
584 }
585}
586
587const wxIcon& wxAuiMDIChildFrame::GetIcon() const
588{
589 return m_icon;
590}
ccc8c01a
VZ
591
592
a3a5df9d 593void wxAuiMDIChildFrame::Activate()
cd05bf23 594{
a3a5df9d 595 wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame();
cd05bf23
BW
596 wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame"));
597
8856768e 598 wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow();
cd05bf23
BW
599
600 if (pClientWindow != NULL)
601 {
602 size_t pos;
603 for (pos = 0; pos < pClientWindow->GetPageCount(); pos++)
604 {
605 if (pClientWindow->GetPage(pos) == this)
606 {
607 pClientWindow->SetSelection(pos);
608 break;
609 }
610 }
611 }
612}
613
a3a5df9d 614void wxAuiMDIChildFrame::OnMenuHighlight(wxMenuEvent& event)
cd05bf23
BW
615{
616#if wxUSE_STATUSBAR
617 if (m_pMDIParentFrame)
618 {
619 // we don't have any help text for this item,
620 // but may be the MDI frame does?
621 m_pMDIParentFrame->OnMenuHighlight(event);
622 }
623#else
624 wxUnusedVar(event);
625#endif // wxUSE_STATUSBAR
626}
627
a3a5df9d 628void wxAuiMDIChildFrame::OnActivate(wxActivateEvent& WXUNUSED(event))
cd05bf23
BW
629{
630 // do nothing
631}
632
a3a5df9d 633void wxAuiMDIChildFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
cd05bf23
BW
634{
635 Destroy();
636}
637
a3a5df9d 638void wxAuiMDIChildFrame::SetMDIParentFrame(wxAuiMDIParentFrame* parentFrame)
cd05bf23
BW
639{
640 m_pMDIParentFrame = parentFrame;
641}
642
a3a5df9d 643wxAuiMDIParentFrame* wxAuiMDIChildFrame::GetMDIParentFrame() const
cd05bf23
BW
644{
645 return m_pMDIParentFrame;
646}
647
a3a5df9d 648void wxAuiMDIChildFrame::Init()
cd05bf23 649{
e7e324be 650 m_activate_on_create = true;
cd05bf23
BW
651 m_pMDIParentFrame = NULL;
652#if wxUSE_MENUS
653 m_pMenuBar = NULL;
654#endif // wxUSE_MENUS
655}
656
e7e324be 657bool wxAuiMDIChildFrame::Show(bool show)
cd05bf23 658{
e7e324be 659 m_activate_on_create = show;
ccc8c01a 660
cd05bf23
BW
661 // do nothing
662 return true;
663}
664
a3a5df9d 665void wxAuiMDIChildFrame::DoShow(bool show)
cd05bf23
BW
666{
667 wxWindow::Show(show);
668}
669
a3a5df9d 670void wxAuiMDIChildFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags)
cd05bf23
BW
671{
672 m_mdi_newrect = wxRect(x, y, width, height);
a94476de
BW
673#ifdef __WXGTK__
674 wxPanel::DoSetSize(x,y,width, height, sizeFlags);
f9c240ec
BW
675#else
676 wxUnusedVar(sizeFlags);
a94476de 677#endif
cd05bf23
BW
678}
679
a3a5df9d 680void wxAuiMDIChildFrame::DoMoveWindow(int x, int y, int width, int height)
cd05bf23
BW
681{
682 m_mdi_newrect = wxRect(x, y, width, height);
683}
684
a3a5df9d 685void wxAuiMDIChildFrame::ApplyMDIChildFrameRect()
cd05bf23
BW
686{
687 if (m_mdi_currect != m_mdi_newrect)
688 {
689 wxPanel::DoMoveWindow(m_mdi_newrect.x, m_mdi_newrect.y,
690 m_mdi_newrect.width, m_mdi_newrect.height);
691 m_mdi_currect = m_mdi_newrect;
692 }
693}
694
695
696//-----------------------------------------------------------------------------
8856768e 697// wxAuiMDIClientWindow
cd05bf23
BW
698//-----------------------------------------------------------------------------
699
8856768e 700IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIClientWindow, wxAuiNotebook)
cd05bf23 701
8856768e
BW
702BEGIN_EVENT_TABLE(wxAuiMDIClientWindow, wxAuiNotebook)
703 EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, wxAuiMDIClientWindow::OnPageChanged)
c5e2ca7c 704 EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, wxAuiMDIClientWindow::OnPageClose)
8856768e 705 EVT_SIZE(wxAuiMDIClientWindow::OnSize)
cd05bf23
BW
706END_EVENT_TABLE()
707
8856768e 708wxAuiMDIClientWindow::wxAuiMDIClientWindow()
cd05bf23
BW
709{
710}
711
8856768e 712wxAuiMDIClientWindow::wxAuiMDIClientWindow(wxAuiMDIParentFrame* parent, long style)
cd05bf23
BW
713{
714 CreateClient(parent, style);
715}
716
8856768e 717wxAuiMDIClientWindow::~wxAuiMDIClientWindow()
cd05bf23
BW
718{
719 DestroyChildren();
720}
721
8856768e 722bool wxAuiMDIClientWindow::CreateClient(wxAuiMDIParentFrame* parent, long style)
cd05bf23
BW
723{
724 SetWindowStyleFlag(style);
725
ccc8c01a 726 wxSize caption_icon_size =
9fbb7d80
BW
727 wxSize(wxSystemSettings::GetMetric(wxSYS_SMALLICON_X),
728 wxSystemSettings::GetMetric(wxSYS_SMALLICON_Y));
729 SetUniformBitmapSize(caption_icon_size);
ccc8c01a 730
a3a5df9d 731 if (!wxAuiNotebook::Create(parent,
695c0088
BW
732 wxID_ANY,
733 wxPoint(0,0),
734 wxSize(100, 100),
735 wxAUI_NB_DEFAULT_STYLE | wxNO_BORDER))
cd05bf23
BW
736 {
737 return false;
738 }
4444d148 739
cd05bf23 740 wxColour bkcolour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
e7e324be 741 SetOwnBackgroundColour(bkcolour);
4444d148 742
254a3429 743 m_mgr.GetArtProvider()->SetColour(wxAUI_DOCKART_BACKGROUND_COLOUR, bkcolour);
4444d148 744
cd05bf23
BW
745 return true;
746}
747
8856768e 748int wxAuiMDIClientWindow::SetSelection(size_t nPage)
cd05bf23 749{
a3a5df9d 750 return wxAuiNotebook::SetSelection(nPage);
cd05bf23
BW
751}
752
8856768e 753void wxAuiMDIClientWindow::PageChanged(int old_selection, int new_selection)
cd05bf23
BW
754{
755 // don't do anything if the page doesn't actually change
756 if (old_selection == new_selection)
757 return;
ccc8c01a 758
c5e2ca7c 759 /*
cd05bf23
BW
760 // don't do anything if the new page is already active
761 if (new_selection != -1)
762 {
a3a5df9d 763 wxAuiMDIChildFrame* child = (wxAuiMDIChildFrame*)GetPage(new_selection);
cd05bf23
BW
764 if (child->GetMDIParentFrame()->GetActiveChild() == child)
765 return;
c5e2ca7c 766 }*/
ccc8c01a
VZ
767
768
cd05bf23
BW
769 // notify old active child that it has been deactivated
770 if (old_selection != -1)
771 {
a3a5df9d 772 wxAuiMDIChildFrame* old_child = (wxAuiMDIChildFrame*)GetPage(old_selection);
8856768e 773 wxASSERT_MSG(old_child, wxT("wxAuiMDIClientWindow::PageChanged - null page pointer"));
4444d148 774
cd05bf23
BW
775 wxActivateEvent event(wxEVT_ACTIVATE, false, old_child->GetId());
776 event.SetEventObject(old_child);
777 old_child->GetEventHandler()->ProcessEvent(event);
778 }
ccc8c01a 779
cd05bf23
BW
780 // notify new active child that it has been activated
781 if (new_selection != -1)
782 {
a3a5df9d 783 wxAuiMDIChildFrame* active_child = (wxAuiMDIChildFrame*)GetPage(new_selection);
8856768e 784 wxASSERT_MSG(active_child, wxT("wxAuiMDIClientWindow::PageChanged - null page pointer"));
ccc8c01a 785
cd05bf23
BW
786 wxActivateEvent event(wxEVT_ACTIVATE, true, active_child->GetId());
787 event.SetEventObject(active_child);
788 active_child->GetEventHandler()->ProcessEvent(event);
ccc8c01a 789
cd05bf23
BW
790 if (active_child->GetMDIParentFrame())
791 {
792 active_child->GetMDIParentFrame()->SetActiveChild(active_child);
793 active_child->GetMDIParentFrame()->SetChildMenuBar(active_child);
794 }
795 }
ccc8c01a 796
c5e2ca7c
BW
797
798}
799
800void wxAuiMDIClientWindow::OnPageClose(wxAuiNotebookEvent& evt)
801{
802 wxAuiMDIChildFrame* wnd;
803 wnd = static_cast<wxAuiMDIChildFrame*>(GetPage(evt.GetSelection()));
ccc8c01a 804
c5e2ca7c 805 wnd->Close();
ccc8c01a 806
c5e2ca7c
BW
807 // regardless of the result of wnd->Close(), we've
808 // already taken care of the close operations, so
809 // suppress further processing
810 evt.Veto();
cd05bf23
BW
811}
812
8856768e 813void wxAuiMDIClientWindow::OnPageChanged(wxAuiNotebookEvent& evt)
cd05bf23
BW
814{
815 PageChanged(evt.GetOldSelection(), evt.GetSelection());
cd05bf23
BW
816}
817
8856768e 818void wxAuiMDIClientWindow::OnSize(wxSizeEvent& evt)
4444d148 819{
a3a5df9d 820 wxAuiNotebook::OnSize(evt);
cd05bf23
BW
821
822 for (size_t pos = 0; pos < GetPageCount(); pos++)
a3a5df9d 823 ((wxAuiMDIChildFrame *)GetPage(pos))->ApplyMDIChildFrameRect();
cd05bf23
BW
824}
825
25f70bc4 826#endif //wxUSE_AUI
cd05bf23 827#endif // wxUSE_MDI