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