]>
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 | ||
113 | wxFrame::Create(parent, id, title, pos, size, style, name); | |
114 | OnCreateClient(); | |
115 | return true; | |
116 | } | |
117 | ||
f39fddcd BW |
118 | |
119 | void wxAuiMDIParentFrame::SetArtProvider(wxAuiTabArt* provider) | |
120 | { | |
121 | if (m_pClientWindow) | |
122 | { | |
123 | m_pClientWindow->SetArtProvider(provider); | |
124 | } | |
125 | } | |
126 | ||
127 | wxAuiTabArt* wxAuiMDIParentFrame::GetArtProvider() | |
128 | { | |
129 | if (!m_pClientWindow) | |
130 | return NULL; | |
131 | ||
132 | return m_pClientWindow->GetArtProvider(); | |
133 | } | |
134 | ||
135 | wxAuiNotebook* wxAuiMDIParentFrame::GetNotebook() const | |
136 | { | |
137 | return static_cast<wxAuiNotebook*>(m_pClientWindow); | |
138 | } | |
139 | ||
140 | ||
141 | ||
cd05bf23 | 142 | #if wxUSE_MENUS |
a3a5df9d | 143 | void 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 | 161 | void 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 | 174 | void 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 | 199 | bool 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 BW |
204 | m_pLastEvt = &event; |
205 | ||
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 | 235 | wxAuiMDIChildFrame *wxAuiMDIParentFrame::GetActiveChild() const |
cd05bf23 BW |
236 | { |
237 | return m_pActiveChild; | |
238 | } | |
239 | ||
a3a5df9d | 240 | void wxAuiMDIParentFrame::SetActiveChild(wxAuiMDIChildFrame* pChildFrame) |
cd05bf23 BW |
241 | { |
242 | m_pActiveChild = pChildFrame; | |
243 | } | |
244 | ||
8856768e | 245 | wxAuiMDIClientWindow *wxAuiMDIParentFrame::GetClientWindow() const |
cd05bf23 BW |
246 | { |
247 | return m_pClientWindow; | |
248 | } | |
249 | ||
8856768e | 250 | wxAuiMDIClientWindow *wxAuiMDIParentFrame::OnCreateClient() |
cd05bf23 | 251 | { |
8856768e | 252 | m_pClientWindow = new wxAuiMDIClientWindow( this ); |
cd05bf23 BW |
253 | return m_pClientWindow; |
254 | } | |
255 | ||
a3a5df9d | 256 | void 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 | 268 | void 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 | 280 | void 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 | 292 | void 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 | 307 | void 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 | 319 | void 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 | } | |
334 | else | |
335 | { | |
336 | delete m_pActiveChild; | |
337 | m_pActiveChild = NULL; | |
338 | } | |
339 | } | |
340 | break; | |
341 | case wxWINDOWNEXT: | |
342 | ActivateNext(); | |
343 | break; | |
344 | case wxWINDOWPREV: | |
345 | ActivatePrevious(); | |
346 | break; | |
347 | default: | |
348 | event.Skip(); | |
349 | } | |
350 | } | |
351 | #endif // wxUSE_MENUS | |
352 | ||
a3a5df9d | 353 | void wxAuiMDIParentFrame::DoGetClientSize(int* width, int* height) const |
cd05bf23 BW |
354 | { |
355 | wxFrame::DoGetClientSize(width, height); | |
356 | } | |
357 | ||
d606b6e9 BW |
358 | void wxAuiMDIParentFrame::Tile(wxOrientation orient) |
359 | { | |
360 | wxAuiMDIClientWindow* client_window = GetClientWindow(); | |
361 | wxASSERT_MSG(client_window, wxT("Missing MDI Client Window")); | |
362 | ||
363 | int cur_idx = client_window->GetSelection(); | |
364 | if (cur_idx == -1) | |
365 | return; | |
366 | ||
367 | if (orient == wxVERTICAL) | |
368 | { | |
369 | client_window->Split(cur_idx, wxLEFT); | |
370 | } | |
371 | else if (orient == wxHORIZONTAL) | |
372 | { | |
373 | client_window->Split(cur_idx, wxTOP); | |
374 | } | |
375 | } | |
376 | ||
377 | ||
cd05bf23 | 378 | //----------------------------------------------------------------------------- |
a3a5df9d | 379 | // wxAuiMDIChildFrame |
cd05bf23 BW |
380 | //----------------------------------------------------------------------------- |
381 | ||
a3a5df9d | 382 | IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIChildFrame, wxPanel) |
cd05bf23 | 383 | |
a3a5df9d BW |
384 | BEGIN_EVENT_TABLE(wxAuiMDIChildFrame, wxPanel) |
385 | EVT_MENU_HIGHLIGHT_ALL(wxAuiMDIChildFrame::OnMenuHighlight) | |
386 | EVT_ACTIVATE(wxAuiMDIChildFrame::OnActivate) | |
387 | EVT_CLOSE(wxAuiMDIChildFrame::OnCloseWindow) | |
cd05bf23 BW |
388 | END_EVENT_TABLE() |
389 | ||
a3a5df9d | 390 | wxAuiMDIChildFrame::wxAuiMDIChildFrame() |
cd05bf23 BW |
391 | { |
392 | Init(); | |
393 | } | |
394 | ||
a3a5df9d | 395 | wxAuiMDIChildFrame::wxAuiMDIChildFrame(wxAuiMDIParentFrame *parent, |
cd05bf23 BW |
396 | wxWindowID id, |
397 | const wxString& title, | |
398 | const wxPoint& WXUNUSED(pos), | |
399 | const wxSize& size, | |
400 | long style, | |
401 | const wxString& name) | |
402 | { | |
403 | Init(); | |
e7e324be BW |
404 | |
405 | // There are two ways to create an tabbed mdi child fram without | |
406 | // making it the active document. Either Show(false) can be called | |
407 | // before Create() (as is customary on some ports with wxFrame-type | |
408 | // windows), or wxMINIMIZE can be passed in the style flags. Note that | |
409 | // wxAuiMDIChildFrame is not really derived from wxFrame, as wxMDIChildFrame | |
410 | // is, but those are the expected symantics. No style flag is passed | |
411 | // onto the panel underneath. | |
412 | if (style & wxMINIMIZE) | |
413 | m_activate_on_create = false; | |
414 | ||
415 | Create(parent, id, title, wxDefaultPosition, size, 0, name); | |
cd05bf23 BW |
416 | } |
417 | ||
a3a5df9d | 418 | wxAuiMDIChildFrame::~wxAuiMDIChildFrame() |
cd05bf23 | 419 | { |
b0a54b8a RD |
420 | wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame(); |
421 | if (pParentFrame && pParentFrame->GetActiveChild() == this) | |
422 | { | |
423 | pParentFrame->SetActiveChild(NULL); | |
424 | pParentFrame->SetChildMenuBar(NULL); | |
425 | } | |
426 | ||
cd05bf23 BW |
427 | #if wxUSE_MENUS |
428 | wxDELETE(m_pMenuBar); | |
429 | #endif // wxUSE_MENUS | |
430 | } | |
431 | ||
a3a5df9d | 432 | bool wxAuiMDIChildFrame::Create(wxAuiMDIParentFrame* parent, |
cd05bf23 BW |
433 | wxWindowID id, |
434 | const wxString& title, | |
435 | const wxPoint& WXUNUSED(pos), | |
436 | const wxSize& size, | |
437 | long style, | |
438 | const wxString& name) | |
439 | { | |
8856768e | 440 | wxAuiMDIClientWindow* pClientWindow = parent->GetClientWindow(); |
cd05bf23 BW |
441 | wxASSERT_MSG((pClientWindow != (wxWindow*) NULL), wxT("Missing MDI client window.")); |
442 | ||
e7e324be BW |
443 | // see comment in constructor |
444 | if (style & wxMINIMIZE) | |
445 | m_activate_on_create = false; | |
446 | ||
ea53a601 BW |
447 | wxSize cli_size = pClientWindow->GetClientSize(); |
448 | ||
449 | // create the window off-screen to prevent flicker | |
450 | wxPanel::Create(pClientWindow, | |
451 | id, | |
452 | wxPoint(cli_size.x+1, cli_size.y+1), | |
453 | size, | |
e7e324be BW |
454 | wxNO_BORDER, name); |
455 | ||
456 | DoShow(false); | |
cd05bf23 BW |
457 | |
458 | SetMDIParentFrame(parent); | |
459 | ||
460 | // this is the currently active child | |
461 | parent->SetActiveChild(this); | |
462 | ||
463 | m_title = title; | |
464 | ||
e7e324be | 465 | pClientWindow->AddPage(this, title, m_activate_on_create); |
cd05bf23 | 466 | pClientWindow->Refresh(); |
e7e324be | 467 | |
cd05bf23 BW |
468 | return true; |
469 | } | |
470 | ||
a3a5df9d | 471 | bool wxAuiMDIChildFrame::Destroy() |
cd05bf23 | 472 | { |
a3a5df9d | 473 | wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame(); |
cd05bf23 | 474 | wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame")); |
4444d148 | 475 | |
8856768e | 476 | wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow(); |
cd05bf23 | 477 | wxASSERT_MSG(pClientWindow, wxT("Missing MDI Client Window")); |
4444d148 | 478 | |
cd05bf23 BW |
479 | if (pParentFrame->GetActiveChild() == this) |
480 | { | |
c5e2ca7c BW |
481 | // deactivate ourself |
482 | wxActivateEvent event(wxEVT_ACTIVATE, false, GetId()); | |
483 | event.SetEventObject(this); | |
484 | GetEventHandler()->ProcessEvent(event); | |
485 | ||
cd05bf23 BW |
486 | pParentFrame->SetActiveChild(NULL); |
487 | pParentFrame->SetChildMenuBar(NULL); | |
cd05bf23 | 488 | } |
4444d148 | 489 | |
c5e2ca7c | 490 | size_t page_count = pClientWindow->GetPageCount(); |
d3b647c2 | 491 | for (size_t pos = 0; pos < page_count; pos++) |
cd05bf23 BW |
492 | { |
493 | if (pClientWindow->GetPage(pos) == this) | |
494 | return pClientWindow->DeletePage(pos); | |
495 | } | |
4444d148 | 496 | |
cd05bf23 BW |
497 | return false; |
498 | } | |
499 | ||
cd05bf23 | 500 | #if wxUSE_MENUS |
a3a5df9d | 501 | void wxAuiMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar) |
cd05bf23 BW |
502 | { |
503 | wxMenuBar *pOldMenuBar = m_pMenuBar; | |
504 | m_pMenuBar = menu_bar; | |
505 | ||
506 | if (m_pMenuBar) | |
507 | { | |
a3a5df9d | 508 | wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame(); |
cd05bf23 BW |
509 | wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame")); |
510 | ||
511 | m_pMenuBar->SetParent(pParentFrame); | |
512 | if (pParentFrame->GetActiveChild() == this) | |
513 | { | |
514 | // replace current menu bars | |
515 | if (pOldMenuBar) | |
516 | pParentFrame->SetChildMenuBar(NULL); | |
517 | pParentFrame->SetChildMenuBar(this); | |
518 | } | |
519 | } | |
520 | } | |
521 | ||
a3a5df9d | 522 | wxMenuBar *wxAuiMDIChildFrame::GetMenuBar() const |
cd05bf23 BW |
523 | { |
524 | return m_pMenuBar; | |
525 | } | |
526 | #endif // wxUSE_MENUS | |
527 | ||
a3a5df9d | 528 | void wxAuiMDIChildFrame::SetTitle(const wxString& title) |
cd05bf23 BW |
529 | { |
530 | m_title = title; | |
531 | ||
a3a5df9d | 532 | wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame(); |
cd05bf23 BW |
533 | wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame")); |
534 | ||
8856768e | 535 | wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow(); |
cd05bf23 BW |
536 | if (pClientWindow != NULL) |
537 | { | |
538 | size_t pos; | |
539 | for (pos = 0; pos < pClientWindow->GetPageCount(); pos++) | |
540 | { | |
541 | if (pClientWindow->GetPage(pos) == this) | |
542 | { | |
543 | pClientWindow->SetPageText(pos, m_title); | |
544 | break; | |
545 | } | |
546 | } | |
547 | } | |
548 | } | |
549 | ||
a3a5df9d | 550 | wxString wxAuiMDIChildFrame::GetTitle() const |
cd05bf23 BW |
551 | { |
552 | return m_title; | |
553 | } | |
554 | ||
e0dc13d4 BW |
555 | void wxAuiMDIChildFrame::SetIcons(const wxIconBundle& icons) |
556 | { | |
557 | // get icon with the system icon size | |
558 | SetIcon(icons.GetIcon(-1)); | |
559 | m_icon_bundle = icons; | |
560 | } | |
561 | ||
562 | const wxIconBundle& wxAuiMDIChildFrame::GetIcons() const | |
563 | { | |
564 | return m_icon_bundle; | |
565 | } | |
566 | ||
567 | void wxAuiMDIChildFrame::SetIcon(const wxIcon& icon) | |
568 | { | |
569 | wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame(); | |
570 | wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame")); | |
571 | ||
572 | m_icon = icon; | |
573 | ||
574 | wxBitmap bmp; | |
575 | bmp.CopyFromIcon(m_icon); | |
9fbb7d80 | 576 | |
e0dc13d4 BW |
577 | wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow(); |
578 | if (pClientWindow != NULL) | |
579 | { | |
580 | int idx = pClientWindow->GetPageIndex(this); | |
581 | ||
582 | if (idx != -1) | |
583 | { | |
584 | pClientWindow->SetPageBitmap((size_t)idx, bmp); | |
585 | } | |
586 | } | |
587 | } | |
588 | ||
589 | const wxIcon& wxAuiMDIChildFrame::GetIcon() const | |
590 | { | |
591 | return m_icon; | |
592 | } | |
593 | ||
594 | ||
a3a5df9d | 595 | void wxAuiMDIChildFrame::Activate() |
cd05bf23 | 596 | { |
a3a5df9d | 597 | wxAuiMDIParentFrame* pParentFrame = GetMDIParentFrame(); |
cd05bf23 BW |
598 | wxASSERT_MSG(pParentFrame, wxT("Missing MDI Parent Frame")); |
599 | ||
8856768e | 600 | wxAuiMDIClientWindow* pClientWindow = pParentFrame->GetClientWindow(); |
cd05bf23 BW |
601 | |
602 | if (pClientWindow != NULL) | |
603 | { | |
604 | size_t pos; | |
605 | for (pos = 0; pos < pClientWindow->GetPageCount(); pos++) | |
606 | { | |
607 | if (pClientWindow->GetPage(pos) == this) | |
608 | { | |
609 | pClientWindow->SetSelection(pos); | |
610 | break; | |
611 | } | |
612 | } | |
613 | } | |
614 | } | |
615 | ||
a3a5df9d | 616 | void wxAuiMDIChildFrame::OnMenuHighlight(wxMenuEvent& event) |
cd05bf23 BW |
617 | { |
618 | #if wxUSE_STATUSBAR | |
619 | if (m_pMDIParentFrame) | |
620 | { | |
621 | // we don't have any help text for this item, | |
622 | // but may be the MDI frame does? | |
623 | m_pMDIParentFrame->OnMenuHighlight(event); | |
624 | } | |
625 | #else | |
626 | wxUnusedVar(event); | |
627 | #endif // wxUSE_STATUSBAR | |
628 | } | |
629 | ||
a3a5df9d | 630 | void wxAuiMDIChildFrame::OnActivate(wxActivateEvent& WXUNUSED(event)) |
cd05bf23 BW |
631 | { |
632 | // do nothing | |
633 | } | |
634 | ||
a3a5df9d | 635 | void wxAuiMDIChildFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
cd05bf23 BW |
636 | { |
637 | Destroy(); | |
638 | } | |
639 | ||
a3a5df9d | 640 | void wxAuiMDIChildFrame::SetMDIParentFrame(wxAuiMDIParentFrame* parentFrame) |
cd05bf23 BW |
641 | { |
642 | m_pMDIParentFrame = parentFrame; | |
643 | } | |
644 | ||
a3a5df9d | 645 | wxAuiMDIParentFrame* wxAuiMDIChildFrame::GetMDIParentFrame() const |
cd05bf23 BW |
646 | { |
647 | return m_pMDIParentFrame; | |
648 | } | |
649 | ||
a3a5df9d | 650 | void wxAuiMDIChildFrame::Init() |
cd05bf23 | 651 | { |
e7e324be | 652 | m_activate_on_create = true; |
cd05bf23 BW |
653 | m_pMDIParentFrame = NULL; |
654 | #if wxUSE_MENUS | |
655 | m_pMenuBar = NULL; | |
656 | #endif // wxUSE_MENUS | |
657 | } | |
658 | ||
e7e324be | 659 | bool wxAuiMDIChildFrame::Show(bool show) |
cd05bf23 | 660 | { |
e7e324be BW |
661 | m_activate_on_create = show; |
662 | ||
cd05bf23 BW |
663 | // do nothing |
664 | return true; | |
665 | } | |
666 | ||
a3a5df9d | 667 | void wxAuiMDIChildFrame::DoShow(bool show) |
cd05bf23 BW |
668 | { |
669 | wxWindow::Show(show); | |
670 | } | |
671 | ||
a3a5df9d | 672 | void wxAuiMDIChildFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
cd05bf23 BW |
673 | { |
674 | m_mdi_newrect = wxRect(x, y, width, height); | |
a94476de BW |
675 | #ifdef __WXGTK__ |
676 | wxPanel::DoSetSize(x,y,width, height, sizeFlags); | |
f9c240ec BW |
677 | #else |
678 | wxUnusedVar(sizeFlags); | |
a94476de | 679 | #endif |
cd05bf23 BW |
680 | } |
681 | ||
a3a5df9d | 682 | void wxAuiMDIChildFrame::DoMoveWindow(int x, int y, int width, int height) |
cd05bf23 BW |
683 | { |
684 | m_mdi_newrect = wxRect(x, y, width, height); | |
685 | } | |
686 | ||
a3a5df9d | 687 | void wxAuiMDIChildFrame::ApplyMDIChildFrameRect() |
cd05bf23 BW |
688 | { |
689 | if (m_mdi_currect != m_mdi_newrect) | |
690 | { | |
691 | wxPanel::DoMoveWindow(m_mdi_newrect.x, m_mdi_newrect.y, | |
692 | m_mdi_newrect.width, m_mdi_newrect.height); | |
693 | m_mdi_currect = m_mdi_newrect; | |
694 | } | |
695 | } | |
696 | ||
697 | ||
698 | //----------------------------------------------------------------------------- | |
8856768e | 699 | // wxAuiMDIClientWindow |
cd05bf23 BW |
700 | //----------------------------------------------------------------------------- |
701 | ||
8856768e | 702 | IMPLEMENT_DYNAMIC_CLASS(wxAuiMDIClientWindow, wxAuiNotebook) |
cd05bf23 | 703 | |
8856768e BW |
704 | BEGIN_EVENT_TABLE(wxAuiMDIClientWindow, wxAuiNotebook) |
705 | EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, wxAuiMDIClientWindow::OnPageChanged) | |
c5e2ca7c | 706 | EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, wxAuiMDIClientWindow::OnPageClose) |
8856768e | 707 | EVT_SIZE(wxAuiMDIClientWindow::OnSize) |
cd05bf23 BW |
708 | END_EVENT_TABLE() |
709 | ||
8856768e | 710 | wxAuiMDIClientWindow::wxAuiMDIClientWindow() |
cd05bf23 BW |
711 | { |
712 | } | |
713 | ||
8856768e | 714 | wxAuiMDIClientWindow::wxAuiMDIClientWindow(wxAuiMDIParentFrame* parent, long style) |
cd05bf23 BW |
715 | { |
716 | CreateClient(parent, style); | |
717 | } | |
718 | ||
8856768e | 719 | wxAuiMDIClientWindow::~wxAuiMDIClientWindow() |
cd05bf23 BW |
720 | { |
721 | DestroyChildren(); | |
722 | } | |
723 | ||
8856768e | 724 | bool wxAuiMDIClientWindow::CreateClient(wxAuiMDIParentFrame* parent, long style) |
cd05bf23 BW |
725 | { |
726 | SetWindowStyleFlag(style); | |
727 | ||
9fbb7d80 BW |
728 | wxSize caption_icon_size = |
729 | wxSize(wxSystemSettings::GetMetric(wxSYS_SMALLICON_X), | |
730 | wxSystemSettings::GetMetric(wxSYS_SMALLICON_Y)); | |
731 | SetUniformBitmapSize(caption_icon_size); | |
ca0d4407 | 732 | |
a3a5df9d | 733 | if (!wxAuiNotebook::Create(parent, |
695c0088 BW |
734 | wxID_ANY, |
735 | wxPoint(0,0), | |
736 | wxSize(100, 100), | |
737 | wxAUI_NB_DEFAULT_STYLE | wxNO_BORDER)) | |
cd05bf23 BW |
738 | { |
739 | return false; | |
740 | } | |
4444d148 | 741 | |
cd05bf23 | 742 | wxColour bkcolour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE); |
e7e324be | 743 | SetOwnBackgroundColour(bkcolour); |
4444d148 | 744 | |
254a3429 | 745 | m_mgr.GetArtProvider()->SetColour(wxAUI_DOCKART_BACKGROUND_COLOUR, bkcolour); |
4444d148 | 746 | |
cd05bf23 BW |
747 | return true; |
748 | } | |
749 | ||
8856768e | 750 | int wxAuiMDIClientWindow::SetSelection(size_t nPage) |
cd05bf23 | 751 | { |
a3a5df9d | 752 | return wxAuiNotebook::SetSelection(nPage); |
cd05bf23 BW |
753 | } |
754 | ||
8856768e | 755 | void wxAuiMDIClientWindow::PageChanged(int old_selection, int new_selection) |
cd05bf23 BW |
756 | { |
757 | // don't do anything if the page doesn't actually change | |
758 | if (old_selection == new_selection) | |
759 | return; | |
c5e2ca7c BW |
760 | |
761 | /* | |
cd05bf23 BW |
762 | // don't do anything if the new page is already active |
763 | if (new_selection != -1) | |
764 | { | |
a3a5df9d | 765 | wxAuiMDIChildFrame* child = (wxAuiMDIChildFrame*)GetPage(new_selection); |
cd05bf23 BW |
766 | if (child->GetMDIParentFrame()->GetActiveChild() == child) |
767 | return; | |
c5e2ca7c BW |
768 | }*/ |
769 | ||
770 | ||
cd05bf23 BW |
771 | // notify old active child that it has been deactivated |
772 | if (old_selection != -1) | |
773 | { | |
a3a5df9d | 774 | wxAuiMDIChildFrame* old_child = (wxAuiMDIChildFrame*)GetPage(old_selection); |
8856768e | 775 | wxASSERT_MSG(old_child, wxT("wxAuiMDIClientWindow::PageChanged - null page pointer")); |
4444d148 | 776 | |
cd05bf23 BW |
777 | wxActivateEvent event(wxEVT_ACTIVATE, false, old_child->GetId()); |
778 | event.SetEventObject(old_child); | |
779 | old_child->GetEventHandler()->ProcessEvent(event); | |
780 | } | |
c5e2ca7c | 781 | |
cd05bf23 BW |
782 | // notify new active child that it has been activated |
783 | if (new_selection != -1) | |
784 | { | |
a3a5df9d | 785 | wxAuiMDIChildFrame* active_child = (wxAuiMDIChildFrame*)GetPage(new_selection); |
8856768e | 786 | wxASSERT_MSG(active_child, wxT("wxAuiMDIClientWindow::PageChanged - null page pointer")); |
c5e2ca7c | 787 | |
cd05bf23 BW |
788 | wxActivateEvent event(wxEVT_ACTIVATE, true, active_child->GetId()); |
789 | event.SetEventObject(active_child); | |
790 | active_child->GetEventHandler()->ProcessEvent(event); | |
c5e2ca7c | 791 | |
cd05bf23 BW |
792 | if (active_child->GetMDIParentFrame()) |
793 | { | |
794 | active_child->GetMDIParentFrame()->SetActiveChild(active_child); | |
795 | active_child->GetMDIParentFrame()->SetChildMenuBar(active_child); | |
796 | } | |
797 | } | |
c5e2ca7c BW |
798 | |
799 | ||
800 | } | |
801 | ||
802 | void wxAuiMDIClientWindow::OnPageClose(wxAuiNotebookEvent& evt) | |
803 | { | |
804 | wxAuiMDIChildFrame* wnd; | |
805 | wnd = static_cast<wxAuiMDIChildFrame*>(GetPage(evt.GetSelection())); | |
806 | ||
807 | wnd->Close(); | |
808 | ||
809 | // regardless of the result of wnd->Close(), we've | |
810 | // already taken care of the close operations, so | |
811 | // suppress further processing | |
812 | evt.Veto(); | |
cd05bf23 BW |
813 | } |
814 | ||
8856768e | 815 | void wxAuiMDIClientWindow::OnPageChanged(wxAuiNotebookEvent& evt) |
cd05bf23 BW |
816 | { |
817 | PageChanged(evt.GetOldSelection(), evt.GetSelection()); | |
cd05bf23 BW |
818 | } |
819 | ||
8856768e | 820 | void wxAuiMDIClientWindow::OnSize(wxSizeEvent& evt) |
4444d148 | 821 | { |
a3a5df9d | 822 | wxAuiNotebook::OnSize(evt); |
cd05bf23 BW |
823 | |
824 | for (size_t pos = 0; pos < GetPageCount(); pos++) | |
a3a5df9d | 825 | ((wxAuiMDIChildFrame *)GetPage(pos))->ApplyMDIChildFrameRect(); |
cd05bf23 BW |
826 | } |
827 | ||
25f70bc4 | 828 | #endif //wxUSE_AUI |
cd05bf23 | 829 | #endif // wxUSE_MDI |