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