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