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