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