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