]>
Commit | Line | Data |
---|---|---|
6c70a9b5 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/generic/mdig.cpp | |
3 | // Purpose: Generic MDI (Multiple Document Interface) classes | |
4 | // Author: Hans Van Leemputten | |
d2824cdb | 5 | // Modified by: 2008-10-31 Vadim Zeitlin: derive from the base classes |
6c70a9b5 JS |
6 | // Created: 29/07/2002 |
7 | // RCS-ID: $Id$ | |
d2824cdb VZ |
8 | // Copyright: (c) 2002 Hans Van Leemputten |
9 | // (c) 2008 Vadim Zeitlin | |
65571936 | 10 | // Licence: wxWindows licence |
6c70a9b5 JS |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
13 | // =========================================================================== | |
14 | // declarations | |
15 | // =========================================================================== | |
16 | ||
17 | // --------------------------------------------------------------------------- | |
18 | // headers | |
19 | // --------------------------------------------------------------------------- | |
20 | ||
6c70a9b5 JS |
21 | // For compilers that support precompilation, includes "wx.h". |
22 | #include "wx/wxprec.h" | |
23 | ||
24 | #ifdef __BORLANDC__ | |
25 | #pragma hdrstop | |
26 | #endif | |
27 | ||
9a6384ca WS |
28 | #if wxUSE_MDI |
29 | ||
6c70a9b5 | 30 | #ifndef WX_PRECOMP |
6c70a9b5 | 31 | #include "wx/menu.h" |
2b5f62a0 | 32 | #include "wx/intl.h" |
e4db172a | 33 | #include "wx/log.h" |
6c70a9b5 JS |
34 | #endif //WX_PRECOMP |
35 | ||
d2824cdb VZ |
36 | #include "wx/mdi.h" |
37 | #include "wx/generic/mdig.h" | |
38 | #include "wx/notebook.h" | |
39 | #include "wx/scopeguard.h" | |
40 | ||
e27d9a91 | 41 | #include "wx/stockitem.h" |
6c70a9b5 | 42 | |
c0924519 | 43 | enum MDI_MENU_ID |
6c70a9b5 JS |
44 | { |
45 | wxWINDOWCLOSE = 4001, | |
46 | wxWINDOWCLOSEALL, | |
47 | wxWINDOWNEXT, | |
48 | wxWINDOWPREV | |
49 | }; | |
50 | ||
51 | //----------------------------------------------------------------------------- | |
52 | // wxGenericMDIParentFrame | |
53 | //----------------------------------------------------------------------------- | |
54 | ||
55 | IMPLEMENT_DYNAMIC_CLASS(wxGenericMDIParentFrame, wxFrame) | |
56 | ||
57 | BEGIN_EVENT_TABLE(wxGenericMDIParentFrame, wxFrame) | |
d2824cdb | 58 | EVT_CLOSE(wxGenericMDIParentFrame::OnClose) |
d7260478 | 59 | #if wxUSE_MENUS |
d2824cdb | 60 | EVT_MENU(wxID_ANY, wxGenericMDIParentFrame::OnWindowMenu) |
d7260478 | 61 | #endif |
6c70a9b5 JS |
62 | END_EVENT_TABLE() |
63 | ||
d2824cdb | 64 | void wxGenericMDIParentFrame::Init() |
6c70a9b5 | 65 | { |
d2824cdb VZ |
66 | #if wxUSE_MENUS |
67 | m_pMyMenuBar = NULL; | |
68 | #endif // wxUSE_MENUS | |
6c70a9b5 JS |
69 | } |
70 | ||
71 | wxGenericMDIParentFrame::~wxGenericMDIParentFrame() | |
c0924519 | 72 | { |
6c70a9b5 | 73 | // Make sure the client window is destructed before the menu bars are! |
d2824cdb | 74 | wxDELETE(m_clientWindow); |
6c70a9b5 | 75 | |
c0924519 | 76 | #if wxUSE_MENUS |
6c70a9b5 JS |
77 | if (m_pMyMenuBar) |
78 | { | |
79 | delete m_pMyMenuBar; | |
d2824cdb | 80 | m_pMyMenuBar = NULL; |
6c70a9b5 | 81 | } |
c0924519 | 82 | |
6c70a9b5 | 83 | RemoveWindowMenu(GetMenuBar()); |
6c70a9b5 JS |
84 | #endif // wxUSE_MENUS |
85 | } | |
86 | ||
87 | bool wxGenericMDIParentFrame::Create(wxWindow *parent, | |
88 | wxWindowID id, | |
89 | const wxString& title, | |
90 | const wxPoint& pos, | |
91 | const wxSize& size, | |
92 | long style, | |
93 | const wxString& name) | |
94 | { | |
d2824cdb VZ |
95 | // this style can be used to prevent a window from having the standard MDI |
96 | // "Window" menu | |
97 | if ( !(style & wxFRAME_NO_WINDOW_MENU) ) | |
98 | { | |
6c70a9b5 | 99 | #if wxUSE_MENUS |
d2824cdb | 100 | m_windowMenu = new wxMenu; |
6c70a9b5 | 101 | |
d2824cdb VZ |
102 | m_windowMenu->Append(wxWINDOWCLOSE, _("Cl&ose")); |
103 | m_windowMenu->Append(wxWINDOWCLOSEALL, _("Close All")); | |
104 | m_windowMenu->AppendSeparator(); | |
105 | m_windowMenu->Append(wxWINDOWNEXT, _("&Next")); | |
106 | m_windowMenu->Append(wxWINDOWPREV, _("&Previous")); | |
6c70a9b5 | 107 | #endif // wxUSE_MENUS |
d2824cdb | 108 | } |
6c70a9b5 | 109 | |
d2824cdb VZ |
110 | // the scrolling styles don't make sense neither for us nor for our client |
111 | // window (to which they're supposed to apply) | |
112 | style &= ~(wxHSCROLL | wxVSCROLL); | |
6c70a9b5 | 113 | |
d2824cdb VZ |
114 | if ( !wxFrame::Create( parent, id, title, pos, size, style, name ) ) |
115 | return false; | |
6c70a9b5 | 116 | |
d2824cdb VZ |
117 | wxGenericMDIClientWindow * const client = OnCreateGenericClient(); |
118 | if ( !client->CreateGenericClient(this) ) | |
119 | return false; | |
120 | ||
121 | m_clientWindow = client; | |
122 | ||
123 | return true; | |
124 | } | |
125 | ||
126 | wxGenericMDIClientWindow *wxGenericMDIParentFrame::OnCreateGenericClient() | |
127 | { | |
128 | return new wxGenericMDIClientWindow; | |
129 | } | |
130 | ||
131 | bool wxGenericMDIParentFrame::CloseAll() | |
132 | { | |
133 | wxGenericMDIClientWindow * const client = GetGenericClientWindow(); | |
134 | if ( !client ) | |
135 | return true; // none of the windows left | |
136 | ||
137 | wxBookCtrlBase * const book = client->GetBookCtrl(); | |
138 | while ( book->GetPageCount() ) | |
139 | { | |
140 | wxGenericMDIChildFrame * const child = client->GetChild(0); | |
141 | if ( !child->Close() ) | |
142 | { | |
143 | // it refused to close, don't close the remaining ones neither | |
144 | return false; | |
145 | } | |
146 | } | |
147 | ||
148 | return true; | |
6c70a9b5 JS |
149 | } |
150 | ||
151 | #if wxUSE_MENUS | |
152 | void wxGenericMDIParentFrame::SetWindowMenu(wxMenu* pMenu) | |
153 | { | |
154 | // Replace the window menu from the currently loaded menu bar. | |
155 | wxMenuBar *pMenuBar = GetMenuBar(); | |
156 | ||
d2824cdb | 157 | if (m_windowMenu) |
6c70a9b5 JS |
158 | { |
159 | RemoveWindowMenu(pMenuBar); | |
160 | ||
d2824cdb | 161 | wxDELETE(m_windowMenu); |
6c70a9b5 JS |
162 | } |
163 | ||
164 | if (pMenu) | |
165 | { | |
d2824cdb | 166 | m_windowMenu = pMenu; |
6c70a9b5 JS |
167 | |
168 | AddWindowMenu(pMenuBar); | |
169 | } | |
170 | } | |
171 | ||
172 | void wxGenericMDIParentFrame::SetMenuBar(wxMenuBar *pMenuBar) | |
173 | { | |
174 | // Remove the Window menu from the old menu bar | |
175 | RemoveWindowMenu(GetMenuBar()); | |
176 | // Add the Window menu to the new menu bar. | |
177 | AddWindowMenu(pMenuBar); | |
178 | ||
179 | wxFrame::SetMenuBar(pMenuBar); | |
180 | } | |
181 | #endif // wxUSE_MENUS | |
182 | ||
d2824cdb | 183 | void wxGenericMDIParentFrame::WXSetChildMenuBar(wxGenericMDIChildFrame *pChild) |
6c70a9b5 JS |
184 | { |
185 | #if wxUSE_MENUS | |
d2824cdb | 186 | if (pChild == NULL) |
6c70a9b5 JS |
187 | { |
188 | // No Child, set Our menu bar back. | |
189 | SetMenuBar(m_pMyMenuBar); | |
c0924519 | 190 | |
6c70a9b5 | 191 | // Make sure we know our menu bar is in use |
d2824cdb | 192 | m_pMyMenuBar = NULL; |
6c70a9b5 JS |
193 | } |
194 | else | |
195 | { | |
d2824cdb | 196 | if (pChild->GetMenuBar() == NULL) |
6c70a9b5 JS |
197 | return; |
198 | ||
199 | // Do we need to save the current bar? | |
200 | if (m_pMyMenuBar == NULL) | |
201 | m_pMyMenuBar = GetMenuBar(); | |
202 | ||
203 | SetMenuBar(pChild->GetMenuBar()); | |
204 | } | |
205 | #endif // wxUSE_MENUS | |
206 | } | |
207 | ||
d2824cdb VZ |
208 | wxGenericMDIClientWindow * |
209 | wxGenericMDIParentFrame::GetGenericClientWindow() const | |
6c70a9b5 | 210 | { |
d2824cdb | 211 | return static_cast<wxGenericMDIClientWindow *>(m_clientWindow); |
6c70a9b5 JS |
212 | } |
213 | ||
d2824cdb | 214 | wxBookCtrlBase *wxGenericMDIParentFrame::GetBookCtrl() const |
6c70a9b5 | 215 | { |
d2824cdb VZ |
216 | wxGenericMDIClientWindow * const client = GetGenericClientWindow(); |
217 | return client ? client->GetBookCtrl() : NULL; | |
6c70a9b5 JS |
218 | } |
219 | ||
d2824cdb | 220 | void wxGenericMDIParentFrame::AdvanceActive(bool forward) |
6c70a9b5 | 221 | { |
d2824cdb VZ |
222 | wxBookCtrlBase * const book = GetBookCtrl(); |
223 | if ( book ) | |
224 | book->AdvanceSelection(forward); | |
6c70a9b5 JS |
225 | } |
226 | ||
d2824cdb | 227 | void wxGenericMDIParentFrame::WXUpdateChildTitle(wxGenericMDIChildFrame *child) |
6c70a9b5 | 228 | { |
d2824cdb VZ |
229 | wxGenericMDIClientWindow * const client = GetGenericClientWindow(); |
230 | ||
231 | const int pos = client->FindChild(child); | |
232 | if ( pos == wxNOT_FOUND ) | |
233 | return; | |
234 | ||
235 | client->GetBookCtrl()->SetPageText(pos, child->GetTitle()); | |
6c70a9b5 JS |
236 | } |
237 | ||
d2824cdb | 238 | void wxGenericMDIParentFrame::WXActivateChild(wxGenericMDIChildFrame *child) |
6c70a9b5 | 239 | { |
d2824cdb VZ |
240 | wxGenericMDIClientWindow * const client = GetGenericClientWindow(); |
241 | ||
242 | const int pos = client->FindChild(child); | |
243 | if ( pos == wxNOT_FOUND ) | |
244 | return; | |
245 | ||
246 | client->GetBookCtrl()->SetSelection(pos); | |
6c70a9b5 JS |
247 | } |
248 | ||
d2824cdb | 249 | void wxGenericMDIParentFrame::WXRemoveChild(wxGenericMDIChildFrame *child) |
6c70a9b5 | 250 | { |
d2824cdb VZ |
251 | const bool removingActive = WXIsActiveChild(child); |
252 | if ( removingActive ) | |
6c70a9b5 | 253 | { |
d2824cdb VZ |
254 | SetActiveChild(NULL); |
255 | WXSetChildMenuBar(NULL); | |
6c70a9b5 | 256 | } |
6c70a9b5 | 257 | |
d2824cdb VZ |
258 | wxGenericMDIClientWindow * const client = GetGenericClientWindow(); |
259 | wxCHECK_RET( client, "should have client window" ); | |
260 | ||
261 | wxBookCtrlBase * const book = client->GetBookCtrl(); | |
262 | ||
263 | // Remove page if still there | |
264 | int pos = client->FindChild(child); | |
265 | if ( pos != wxNOT_FOUND ) | |
6c70a9b5 | 266 | { |
d2824cdb VZ |
267 | if ( book->RemovePage(pos) ) |
268 | book->Refresh(); | |
269 | } | |
6c70a9b5 | 270 | |
d2824cdb VZ |
271 | if ( removingActive ) |
272 | { | |
273 | // Set the new selection to a remaining page | |
274 | const size_t count = book->GetPageCount(); | |
275 | if ( count > (size_t)pos ) | |
276 | { | |
277 | book->SetSelection(pos); | |
278 | } | |
279 | else | |
280 | { | |
281 | if ( count > 0 ) | |
282 | book->SetSelection(count - 1); | |
283 | } | |
6c70a9b5 JS |
284 | } |
285 | } | |
286 | ||
d2824cdb VZ |
287 | bool |
288 | wxGenericMDIParentFrame::WXIsActiveChild(wxGenericMDIChildFrame *child) const | |
6c70a9b5 | 289 | { |
d2824cdb | 290 | return static_cast<wxMDIChildFrameBase *>(GetActiveChild()) == child; |
6c70a9b5 JS |
291 | } |
292 | ||
293 | #if wxUSE_MENUS | |
294 | void wxGenericMDIParentFrame::RemoveWindowMenu(wxMenuBar *pMenuBar) | |
295 | { | |
d2824cdb | 296 | if (pMenuBar && m_windowMenu) |
6c70a9b5 JS |
297 | { |
298 | // Remove old window menu | |
2b5f62a0 | 299 | int pos = pMenuBar->FindMenu(_("&Window")); |
6c70a9b5 JS |
300 | if (pos != wxNOT_FOUND) |
301 | { | |
d2824cdb | 302 | wxASSERT(m_windowMenu == pMenuBar->GetMenu(pos)); // DBG:: We're going to delete the wrong menu!!! |
6c70a9b5 JS |
303 | pMenuBar->Remove(pos); |
304 | } | |
305 | } | |
306 | } | |
307 | ||
308 | void wxGenericMDIParentFrame::AddWindowMenu(wxMenuBar *pMenuBar) | |
309 | { | |
d2824cdb | 310 | if (pMenuBar && m_windowMenu) |
c0924519 | 311 | { |
e27d9a91 | 312 | int pos = pMenuBar->FindMenu(wxGetStockLabel(wxID_HELP,false)); |
6c70a9b5 JS |
313 | if (pos == wxNOT_FOUND) |
314 | { | |
d2824cdb | 315 | pMenuBar->Append(m_windowMenu, _("&Window")); |
6c70a9b5 JS |
316 | } |
317 | else | |
318 | { | |
d2824cdb | 319 | pMenuBar->Insert(pos, m_windowMenu, _("&Window")); |
6c70a9b5 JS |
320 | } |
321 | } | |
322 | } | |
323 | ||
d2824cdb | 324 | void wxGenericMDIParentFrame::OnWindowMenu(wxCommandEvent &event) |
6c70a9b5 | 325 | { |
d2824cdb | 326 | switch ( event.GetId() ) |
6c70a9b5 | 327 | { |
d2824cdb VZ |
328 | case wxWINDOWCLOSE: |
329 | if ( m_currentChild ) | |
330 | m_currentChild->Close(); | |
331 | break; | |
332 | ||
333 | case wxWINDOWCLOSEALL: | |
334 | CloseAll(); | |
335 | break; | |
336 | ||
337 | case wxWINDOWNEXT: | |
338 | ActivateNext(); | |
339 | break; | |
340 | ||
341 | case wxWINDOWPREV: | |
342 | ActivatePrevious(); | |
343 | break; | |
344 | ||
345 | default: | |
346 | event.Skip(); | |
6c70a9b5 JS |
347 | } |
348 | } | |
349 | #endif // wxUSE_MENUS | |
350 | ||
d2824cdb | 351 | void wxGenericMDIParentFrame::OnClose(wxCloseEvent& event) |
6c70a9b5 | 352 | { |
d2824cdb VZ |
353 | if ( !CloseAll() ) |
354 | event.Veto(); | |
355 | else | |
356 | event.Skip(); | |
6c70a9b5 JS |
357 | } |
358 | ||
d2824cdb VZ |
359 | bool wxGenericMDIParentFrame::ProcessEvent(wxEvent& event) |
360 | { | |
361 | if ( m_currentChild ) | |
362 | { | |
363 | // the menu events should be given to the child as we show its menu bar | |
364 | // as our own | |
365 | const wxEventType eventType = event.GetEventType(); | |
366 | if ( eventType == wxEVT_COMMAND_MENU_SELECTED || | |
367 | eventType == wxEVT_UPDATE_UI ) | |
368 | { | |
369 | // set the flag indicating that this event was forwarded to the | |
370 | // child from the parent and so shouldn't be propagated upwards if | |
371 | // not processed to avoid infinite loop | |
372 | m_childHandler = m_currentChild; | |
373 | wxON_BLOCK_EXIT_NULL(m_childHandler); | |
374 | ||
3b7fa206 | 375 | if ( m_currentChild->ProcessWindowEvent(event) ) |
d2824cdb VZ |
376 | return true; |
377 | } | |
378 | } | |
6c70a9b5 | 379 | |
d2824cdb VZ |
380 | return wxMDIParentFrameBase::ProcessEvent(event); |
381 | } | |
382 | ||
383 | // ---------------------------------------------------------------------------- | |
6c70a9b5 | 384 | // wxGenericMDIChildFrame |
d2824cdb | 385 | // ---------------------------------------------------------------------------- |
6c70a9b5 | 386 | |
d2824cdb | 387 | IMPLEMENT_DYNAMIC_CLASS(wxGenericMDIChildFrame, wxFrame) |
6c70a9b5 | 388 | |
d2824cdb | 389 | BEGIN_EVENT_TABLE(wxGenericMDIChildFrame, wxFrame) |
6c70a9b5 | 390 | EVT_MENU_HIGHLIGHT_ALL(wxGenericMDIChildFrame::OnMenuHighlight) |
6c70a9b5 | 391 | |
d2824cdb | 392 | EVT_CLOSE(wxGenericMDIChildFrame::OnClose) |
6c70a9b5 JS |
393 | END_EVENT_TABLE() |
394 | ||
d2824cdb | 395 | void wxGenericMDIChildFrame::Init() |
6c70a9b5 | 396 | { |
d2824cdb VZ |
397 | #if wxUSE_MENUS |
398 | m_pMenuBar = NULL; | |
399 | #endif // wxUSE_MENUS | |
6c70a9b5 | 400 | |
d2824cdb VZ |
401 | #if !wxUSE_GENERIC_MDI_AS_NATIVE |
402 | m_mdiParentGeneric = NULL; | |
403 | #endif | |
6c70a9b5 JS |
404 | } |
405 | ||
6c70a9b5 JS |
406 | wxGenericMDIChildFrame::~wxGenericMDIChildFrame() |
407 | { | |
d2824cdb | 408 | wxGenericMDIParentFrame * const parent = GetGenericMDIParent(); |
6c70a9b5 | 409 | |
d2824cdb VZ |
410 | // it could happen that we don't have a valid parent if we hadn't been ever |
411 | // really created -- but in this case there is nothing else to do neither | |
412 | if ( parent ) | |
413 | parent->WXRemoveChild(this); | |
6c70a9b5 JS |
414 | |
415 | #if wxUSE_MENUS | |
d2824cdb | 416 | delete m_pMenuBar; |
6c70a9b5 JS |
417 | #endif // wxUSE_MENUS |
418 | } | |
419 | ||
d2824cdb VZ |
420 | bool wxGenericMDIChildFrame::Create(wxGenericMDIParentFrame *parent, |
421 | wxWindowID id, | |
422 | const wxString& title, | |
423 | const wxPoint& WXUNUSED(pos), | |
424 | const wxSize& size, | |
425 | long WXUNUSED(style), | |
426 | const wxString& name) | |
6c70a9b5 | 427 | { |
d2824cdb VZ |
428 | // unfortunately we can't use the base class m_mdiParent field unless |
429 | // wxGenericMDIParentFrame is wxMDIParentFrame | |
430 | #if wxUSE_GENERIC_MDI_AS_NATIVE | |
431 | m_mdiParent = parent; | |
432 | #else // generic != native | |
433 | // leave m_mdiParent NULL, we don't have it | |
434 | m_mdiParentGeneric = parent; | |
435 | #endif | |
c0924519 | 436 | |
d2824cdb | 437 | wxBookCtrlBase * const book = parent->GetBookCtrl(); |
6c70a9b5 | 438 | |
d2824cdb | 439 | wxASSERT_MSG( book, "Missing MDI client window." ); |
6c70a9b5 | 440 | |
d2824cdb VZ |
441 | // note that we ignore the styles, none of the usual TLW styles apply to |
442 | // this (child) window | |
443 | if ( !wxWindow::Create(book, id, wxDefaultPosition, size, 0, name) ) | |
444 | return false; | |
6c70a9b5 | 445 | |
d2824cdb VZ |
446 | m_title = title; |
447 | book->AddPage(this, title, true); | |
6c70a9b5 | 448 | |
ca65c044 | 449 | return true; |
6c70a9b5 JS |
450 | } |
451 | ||
c0924519 | 452 | #if wxUSE_MENUS |
6c70a9b5 JS |
453 | void wxGenericMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar ) |
454 | { | |
455 | wxMenuBar *pOldMenuBar = m_pMenuBar; | |
456 | m_pMenuBar = menu_bar; | |
457 | ||
458 | if (m_pMenuBar) | |
459 | { | |
d2824cdb | 460 | wxGenericMDIParentFrame *parent = GetGenericMDIParent(); |
c0924519 | 461 | |
d2824cdb | 462 | if ( parent ) |
6c70a9b5 | 463 | { |
d2824cdb | 464 | m_pMenuBar->SetParent(parent); |
6c70a9b5 | 465 | |
d2824cdb | 466 | if ( parent->WXIsActiveChild(this) ) |
6c70a9b5 JS |
467 | { |
468 | // Replace current menu bars | |
469 | if (pOldMenuBar) | |
d2824cdb VZ |
470 | parent->WXSetChildMenuBar(NULL); |
471 | parent->WXSetChildMenuBar(this); | |
6c70a9b5 JS |
472 | } |
473 | } | |
474 | } | |
475 | } | |
476 | ||
477 | wxMenuBar *wxGenericMDIChildFrame::GetMenuBar() const | |
478 | { | |
479 | return m_pMenuBar; | |
480 | } | |
c0924519 | 481 | #endif // wxUSE_MENUS |
6c70a9b5 JS |
482 | |
483 | void wxGenericMDIChildFrame::SetTitle(const wxString& title) | |
484 | { | |
d2824cdb | 485 | m_title = title; |
6c70a9b5 | 486 | |
d2824cdb VZ |
487 | wxGenericMDIParentFrame * const parent = GetGenericMDIParent(); |
488 | if ( parent ) | |
489 | parent->WXUpdateChildTitle(this); | |
490 | //else: it's ok, we might be not created yet | |
6c70a9b5 JS |
491 | } |
492 | ||
493 | void wxGenericMDIChildFrame::Activate() | |
494 | { | |
d2824cdb | 495 | wxGenericMDIParentFrame * const parent = GetGenericMDIParent(); |
6c70a9b5 | 496 | |
d2824cdb VZ |
497 | wxCHECK_RET( parent, "can't activate MDI child without parent" ); |
498 | parent->WXActivateChild(this); | |
6c70a9b5 JS |
499 | } |
500 | ||
501 | void wxGenericMDIChildFrame::OnMenuHighlight(wxMenuEvent& event) | |
502 | { | |
d2824cdb VZ |
503 | wxGenericMDIParentFrame * const parent = GetGenericMDIParent(); |
504 | if ( parent) | |
6c70a9b5 | 505 | { |
c0924519 | 506 | // we don't have any help text for this item, |
6c70a9b5 | 507 | // but may be the MDI frame does? |
d2824cdb | 508 | parent->OnMenuHighlight(event); |
6c70a9b5 JS |
509 | } |
510 | } | |
511 | ||
d2824cdb | 512 | void wxGenericMDIChildFrame::OnClose(wxCloseEvent& WXUNUSED(event)) |
6c70a9b5 | 513 | { |
d2824cdb VZ |
514 | // we're not a TLW so don't delay the destruction of this window |
515 | delete this; | |
6c70a9b5 JS |
516 | } |
517 | ||
8cc208e3 | 518 | bool wxGenericMDIChildFrame::TryAfter(wxEvent& event) |
c0924519 | 519 | { |
d2824cdb VZ |
520 | // we shouldn't propagate the event to the parent if we received it from it |
521 | // in the first place | |
522 | wxGenericMDIParentFrame * const parent = GetGenericMDIParent(); | |
523 | if ( parent && parent->WXIsInsideChildHandler(this) ) | |
524 | return false; | |
6c70a9b5 | 525 | |
8cc208e3 | 526 | return wxTDIChildFrame::TryAfter(event); |
6c70a9b5 JS |
527 | } |
528 | ||
d2824cdb | 529 | // ---------------------------------------------------------------------------- |
6c70a9b5 | 530 | // wxGenericMDIClientWindow |
d2824cdb | 531 | // ---------------------------------------------------------------------------- |
6c70a9b5 | 532 | |
d2824cdb | 533 | IMPLEMENT_DYNAMIC_CLASS(wxGenericMDIClientWindow, wxWindow) |
6c70a9b5 | 534 | |
d2824cdb VZ |
535 | bool |
536 | wxGenericMDIClientWindow::CreateGenericClient(wxWindow *parent) | |
537 | { | |
538 | if ( !wxWindow::Create(parent, wxID_ANY) ) | |
539 | return false; | |
6c70a9b5 | 540 | |
d2824cdb VZ |
541 | m_notebook = new wxNotebook(this, wxID_ANY); |
542 | m_notebook->Connect | |
543 | ( | |
544 | wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, | |
545 | wxNotebookEventHandler( | |
546 | wxGenericMDIClientWindow::OnPageChanged), | |
547 | NULL, | |
548 | this | |
549 | ); | |
6c70a9b5 | 550 | |
d2824cdb VZ |
551 | // now that we have a notebook to resize, hook up OnSize() too |
552 | Connect(wxEVT_SIZE, wxSizeEventHandler(wxGenericMDIClientWindow::OnSize)); | |
6c70a9b5 | 553 | |
d2824cdb | 554 | return true; |
6c70a9b5 JS |
555 | } |
556 | ||
d2824cdb | 557 | wxBookCtrlBase *wxGenericMDIClientWindow::GetBookCtrl() const |
6c70a9b5 | 558 | { |
d2824cdb | 559 | return m_notebook; |
6c70a9b5 JS |
560 | } |
561 | ||
d2824cdb | 562 | wxGenericMDIChildFrame *wxGenericMDIClientWindow::GetChild(size_t pos) const |
6c70a9b5 | 563 | { |
d2824cdb | 564 | return static_cast<wxGenericMDIChildFrame *>(GetBookCtrl()->GetPage(pos)); |
6c70a9b5 JS |
565 | } |
566 | ||
d2824cdb | 567 | int wxGenericMDIClientWindow::FindChild(wxGenericMDIChildFrame *child) const |
6c70a9b5 | 568 | { |
d2824cdb VZ |
569 | wxBookCtrlBase * const book = GetBookCtrl(); |
570 | const size_t count = book->GetPageCount(); | |
571 | for ( size_t pos = 0; pos < count; pos++ ) | |
6c70a9b5 | 572 | { |
d2824cdb VZ |
573 | if ( book->GetPage(pos) == child ) |
574 | return pos; | |
6c70a9b5 | 575 | } |
6c70a9b5 | 576 | |
d2824cdb | 577 | return wxNOT_FOUND; |
6c70a9b5 JS |
578 | } |
579 | ||
d2824cdb | 580 | void wxGenericMDIClientWindow::PageChanged(int oldSelection, int newSelection) |
6c70a9b5 | 581 | { |
d2824cdb VZ |
582 | // Don't do anything if nothing changed |
583 | if (oldSelection == newSelection) | |
6c70a9b5 | 584 | return; |
d2824cdb VZ |
585 | |
586 | // Again check if we really need to do this... | |
6c70a9b5 JS |
587 | if (newSelection != -1) |
588 | { | |
d2824cdb | 589 | wxGenericMDIChildFrame * const child = GetChild(newSelection); |
6c70a9b5 | 590 | |
d2824cdb | 591 | if ( child->GetGenericMDIParent()->WXIsActiveChild(child) ) |
6c70a9b5 JS |
592 | return; |
593 | } | |
594 | ||
595 | // Notify old active child that it has been deactivated | |
d2824cdb | 596 | if (oldSelection != -1) |
6c70a9b5 | 597 | { |
d2824cdb | 598 | wxGenericMDIChildFrame * const oldChild = GetChild(oldSelection); |
6c70a9b5 JS |
599 | if (oldChild) |
600 | { | |
ca65c044 | 601 | wxActivateEvent event(wxEVT_ACTIVATE, false, oldChild->GetId()); |
6c70a9b5 JS |
602 | event.SetEventObject( oldChild ); |
603 | oldChild->GetEventHandler()->ProcessEvent(event); | |
604 | } | |
605 | } | |
606 | ||
607 | // Notify new active child that it has been activated | |
608 | if (newSelection != -1) | |
609 | { | |
d2824cdb VZ |
610 | wxGenericMDIChildFrame * const activeChild = GetChild(newSelection); |
611 | if ( activeChild ) | |
6c70a9b5 | 612 | { |
ca65c044 | 613 | wxActivateEvent event(wxEVT_ACTIVATE, true, activeChild->GetId()); |
6c70a9b5 JS |
614 | event.SetEventObject( activeChild ); |
615 | activeChild->GetEventHandler()->ProcessEvent(event); | |
616 | ||
d2824cdb VZ |
617 | wxGenericMDIParentFrame * const |
618 | parent = activeChild->GetGenericMDIParent(); | |
619 | ||
620 | if ( parent ) | |
6c70a9b5 | 621 | { |
d2824cdb VZ |
622 | // this is a dirty hack as activeChild is not really a |
623 | // wxMDIChildFrame at all but we still want to store it in the | |
624 | // base class m_currentChild field and this will work as long | |
625 | // as we only use as wxMDIChildFrameBase pointer (which it is) | |
626 | parent->SetActiveChild( | |
627 | reinterpret_cast<wxMDIChildFrame *>(activeChild)); | |
628 | parent->WXSetChildMenuBar(activeChild); | |
6c70a9b5 JS |
629 | } |
630 | } | |
631 | } | |
632 | } | |
633 | ||
3e97a905 | 634 | void wxGenericMDIClientWindow::OnPageChanged(wxBookCtrlEvent& event) |
6c70a9b5 JS |
635 | { |
636 | PageChanged(event.GetOldSelection(), event.GetSelection()); | |
637 | ||
638 | event.Skip(); | |
639 | } | |
640 | ||
d2824cdb | 641 | void wxGenericMDIClientWindow::OnSize(wxSizeEvent& WXUNUSED(event)) |
6c70a9b5 | 642 | { |
d2824cdb | 643 | m_notebook->SetSize(GetClientSize()); |
6c70a9b5 JS |
644 | } |
645 | ||
b4ca5976 VS |
646 | #endif // wxUSE_MDI |
647 |