]> git.saurik.com Git - wxWidgets.git/blame - src/msw/mdi.cpp
Fix broken and missing DataView interface items for Phoenix
[wxWidgets.git] / src / msw / mdi.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
a967ef9d
VZ
2// Name: src/msw/mdi.cpp
3// Purpose: MDI classes for wxMSW
2bda0e17 4// Author: Julian Smart
6125428d 5// Modified by: Vadim Zeitlin on 2008-11-04 to use the base classes
2bda0e17
KB
6// Created: 04/01/98
7// RCS-ID: $Id$
6125428d
VZ
8// Copyright: (c) 1998 Julian Smart
9// (c) 2008-2009 Vadim Zeitlin
65571936 10// Licence: wxWindows licence
2bda0e17
KB
11/////////////////////////////////////////////////////////////////////////////
12
a23fd0e1
VZ
13// ===========================================================================
14// declarations
15// ===========================================================================
16
17// ---------------------------------------------------------------------------
18// headers
19// ---------------------------------------------------------------------------
20
2bda0e17
KB
21// For compilers that support precompilation, includes "wx.h".
22#include "wx/wxprec.h"
23
24#ifdef __BORLANDC__
a23fd0e1 25 #pragma hdrstop
2bda0e17
KB
26#endif
27
efd17a1d 28#if wxUSE_MDI && !defined(__WXUNIVERSAL__)
b442f107 29
59cf2e49
WS
30#include "wx/mdi.h"
31
2bda0e17 32#ifndef WX_PRECOMP
a23fd0e1
VZ
33 #include "wx/frame.h"
34 #include "wx/menu.h"
35 #include "wx/app.h"
36 #include "wx/utils.h"
37 #include "wx/dialog.h"
3304646d 38 #include "wx/statusbr.h"
a23fd0e1 39 #include "wx/settings.h"
0c589ad0
BM
40 #include "wx/intl.h"
41 #include "wx/log.h"
4e3e485b 42 #include "wx/toolbar.h"
2bda0e17
KB
43#endif
44
e27d9a91 45#include "wx/stockitem.h"
2bda0e17
KB
46#include "wx/msw/private.h"
47
2bda0e17
KB
48#include <string.h>
49
a23fd0e1
VZ
50// ---------------------------------------------------------------------------
51// global variables
52// ---------------------------------------------------------------------------
53
e1a6fc11 54extern wxMenu *wxCurrentPopupMenu;
2bda0e17 55
ac6482e0 56extern void wxRemoveHandleAssociation(wxWindow *win);
a23fd0e1 57
838e6ed7
VZ
58namespace
59{
60
a23fd0e1
VZ
61// ---------------------------------------------------------------------------
62// constants
63// ---------------------------------------------------------------------------
64
a23fd0e1 65// This range gives a maximum of 500 MDI children. Should be enough :-)
838e6ed7
VZ
66const int wxFIRST_MDI_CHILD = 4100;
67const int wxLAST_MDI_CHILD = 4600;
68
69// The MDI "Window" menu label
70const char *WINDOW_MENU_LABEL = gettext_noop("&Window");
2bda0e17 71
42e69d6b
VZ
72// ---------------------------------------------------------------------------
73// private functions
74// ---------------------------------------------------------------------------
75
76// set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
77// of the parent of win (which is supposed to be the MDI client window)
838e6ed7 78void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow);
42e69d6b
VZ
79
80// insert the window menu (subMenu) into menu just before "Help" submenu or at
81// the very end if not found
838e6ed7 82void MDIInsertWindowMenu(wxWindow *win, WXHMENU hMenu, HMENU subMenu);
42e69d6b 83
df61c009 84// Remove the window menu
838e6ed7 85void MDIRemoveWindowMenu(wxWindow *win, WXHMENU hMenu);
df61c009 86
4e152a23 87// unpack the parameters of WM_MDIACTIVATE message
838e6ed7
VZ
88void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam,
89 WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact);
42e69d6b 90
4e152a23 91// return the HMENU of the MDI menu
ecc63060
VZ
92//
93// this function works correctly even when we don't have a window menu and just
94// returns 0 then
838e6ed7 95inline HMENU GetMDIWindowMenu(wxMDIParentFrame *frame)
4e152a23
VZ
96{
97 wxMenu *menu = frame->GetWindowMenu();
98 return menu ? GetHmenuOf(menu) : 0;
99}
100
838e6ed7
VZ
101} // anonymous namespace
102
a23fd0e1
VZ
103// ===========================================================================
104// implementation
105// ===========================================================================
106
107// ---------------------------------------------------------------------------
108// wxWin macros
109// ---------------------------------------------------------------------------
2bda0e17 110
225fe9d6
VZ
111IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
112IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
113IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
2bda0e17
KB
114
115BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
a23fd0e1 116 EVT_SIZE(wxMDIParentFrame::OnSize)
6bbe97b7 117 EVT_ICONIZE(wxMDIParentFrame::OnIconized)
a23fd0e1 118 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
1483e5db
VZ
119
120#if wxUSE_MENUS
121 EVT_MENU_RANGE(wxFIRST_MDI_CHILD, wxLAST_MDI_CHILD,
122 wxMDIParentFrame::OnMDIChild)
123 EVT_MENU_RANGE(wxID_MDI_WINDOW_FIRST, wxID_MDI_WINDOW_LAST,
124 wxMDIParentFrame::OnMDICommand)
125#endif // wxUSE_MENUS
2bda0e17
KB
126END_EVENT_TABLE()
127
f6bcfd97
BP
128BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame)
129 EVT_IDLE(wxMDIChildFrame::OnIdle)
130END_EVENT_TABLE()
131
2bda0e17 132BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
a23fd0e1 133 EVT_SCROLL(wxMDIClientWindow::OnScroll)
2bda0e17
KB
134END_EVENT_TABLE()
135
42e69d6b
VZ
136// ===========================================================================
137// wxMDIParentFrame: the frame which contains the client window which manages
138// the children
139// ===========================================================================
2bda0e17 140
0fd2ecfe
VZ
141void wxMDIParentFrame::Init()
142{
143#if wxUSE_MENUS && wxUSE_ACCEL
144 // the default menu doesn't have any accelerators (even if we have it)
145 m_accelWindowMenu = NULL;
146#endif // wxUSE_MENUS && wxUSE_ACCEL
147}
148
2bda0e17 149bool wxMDIParentFrame::Create(wxWindow *parent,
a23fd0e1
VZ
150 wxWindowID id,
151 const wxString& title,
152 const wxPoint& pos,
153 const wxSize& size,
154 long style,
155 const wxString& name)
2bda0e17 156{
3d8dea7e
VZ
157 // this style can be used to prevent a window from having the standard MDI
158 // "Window" menu
d2824cdb 159 if ( !(style & wxFRAME_NO_WINDOW_MENU) )
df61c009 160 {
d2824cdb 161 // normal case: we have the window menu, so construct it
df61c009
JS
162 m_windowMenu = new wxMenu;
163
1483e5db
VZ
164 m_windowMenu->Append(wxID_MDI_WINDOW_CASCADE, _("&Cascade"));
165 m_windowMenu->Append(wxID_MDI_WINDOW_TILE_HORZ, _("Tile &Horizontally"));
166 m_windowMenu->Append(wxID_MDI_WINDOW_TILE_VERT, _("Tile &Vertically"));
df61c009 167 m_windowMenu->AppendSeparator();
1483e5db
VZ
168 m_windowMenu->Append(wxID_MDI_WINDOW_ARRANGE_ICONS, _("&Arrange Icons"));
169 m_windowMenu->Append(wxID_MDI_WINDOW_NEXT, _("&Next"));
170 m_windowMenu->Append(wxID_MDI_WINDOW_PREV, _("&Previous"));
df61c009
JS
171 }
172
2bda0e17
KB
173 if (!parent)
174 wxTopLevelWindows.Append(this);
175
176 SetName(name);
177 m_windowStyle = style;
178
b225f659
VZ
179 if ( parent )
180 parent->AddChild(this);
2bda0e17 181
598ddd96 182 if ( id != wxID_ANY )
2bda0e17
KB
183 m_windowId = id;
184 else
b225f659 185 m_windowId = NewControlId();
2bda0e17 186
912c192f
VZ
187 WXDWORD exflags;
188 WXDWORD msflags = MSWGetCreateWindowFlags(&exflags);
ea723360
JS
189 msflags &= ~WS_VSCROLL;
190 msflags &= ~WS_HSCROLL;
2bda0e17 191
9a83f860 192 if ( !wxWindow::MSWCreate(wxApp::GetRegisteredClassName(wxT("wxMDIFrame")),
017dc06b 193 title.t_str(),
b225f659
VZ
194 pos, size,
195 msflags,
196 exflags) )
3ca6a5f0 197 {
4f8090e0 198 return false;
3ca6a5f0 199 }
2bda0e17 200
5bee6b2b
VZ
201 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
202
f6bcfd97 203 // unlike (almost?) all other windows, frames are created hidden
4f8090e0 204 m_isShown = false;
f6bcfd97 205
4f8090e0 206 return true;
2bda0e17
KB
207}
208
c2dcfdef 209wxMDIParentFrame::~wxMDIParentFrame()
2bda0e17 210{
d1e44484 211 // see comment in ~wxMDIChildFrame
1904aa72 212#if wxUSE_TOOLBAR
f048e32f 213 m_frameToolBar = NULL;
1904aa72 214#endif
67a99992 215#if wxUSE_STATUSBAR
c0bcc480 216 m_frameStatusBar = NULL;
67a99992 217#endif // wxUSE_STATUSBAR
f048e32f 218
1483e5db
VZ
219#if wxUSE_MENUS && wxUSE_ACCEL
220 delete m_accelWindowMenu;
221#endif // wxUSE_MENUS && wxUSE_ACCEL
222
d1e44484
VZ
223 DestroyChildren();
224
4e152a23
VZ
225 // the MDI frame menubar is not automatically deleted by Windows unlike for
226 // the normal frames
227 if ( m_hMenu )
4e152a23 228 ::DestroyMenu((HMENU)m_hMenu);
4e152a23 229
42e69d6b
VZ
230 if ( m_clientWindow )
231 {
232 if ( m_clientWindow->MSWGetOldWndProc() )
233 m_clientWindow->UnsubclassWin();
2bda0e17 234
42e69d6b
VZ
235 m_clientWindow->SetHWND(0);
236 delete m_clientWindow;
237 }
2bda0e17
KB
238}
239
ecc63060
VZ
240// ----------------------------------------------------------------------------
241// wxMDIParentFrame child management
242// ----------------------------------------------------------------------------
243
51181d29
VZ
244wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const
245{
246 HWND hWnd = (HWND)::SendMessage(GetWinHwnd(GetClientWindow()),
247 WM_MDIGETACTIVE, 0, 0L);
1483e5db 248 if ( !hWnd )
51181d29
VZ
249 return NULL;
250
1483e5db 251 return static_cast<wxMDIChildFrame *>(wxFindWinFromHandle(hWnd));
51181d29
VZ
252}
253
ecc63060
VZ
254int wxMDIParentFrame::GetChildFramesCount() const
255{
256 int count = 0;
257 for ( wxWindowList::const_iterator i = GetChildren().begin();
258 i != GetChildren().end();
259 ++i )
260 {
261 if ( wxDynamicCast(*i, wxMDIChildFrame) )
262 count++;
263 }
264
265 return count;
266}
267
7e6d6840
VZ
268#if wxUSE_MENUS
269
ecc63060
VZ
270void wxMDIParentFrame::AddMDIChild(wxMDIChildFrame * WXUNUSED(child))
271{
6125428d 272 switch ( GetChildFramesCount() )
ecc63060 273 {
6125428d
VZ
274 case 1:
275 // first MDI child was just added, we need to insert the window
276 // menu now if we have it
277 AddWindowMenu();
278
279 // and disable the items which can't be used until we have more
280 // than one child
281 UpdateWindowMenu(false);
282 break;
283
284 case 2:
285 // second MDI child was added, enable the menu items which were
286 // disabled because they didn't make sense for a single window
287 UpdateWindowMenu(true);
288 break;
ecc63060
VZ
289 }
290}
291
292void wxMDIParentFrame::RemoveMDIChild(wxMDIChildFrame * WXUNUSED(child))
293{
6125428d 294 switch ( GetChildFramesCount() )
ecc63060 295 {
6125428d
VZ
296 case 1:
297 // last MDI child is being removed, remove the now unnecessary
298 // window menu too
299 RemoveWindowMenu();
300
301 // there is no need to call UpdateWindowMenu(true) here so this is
302 // not quite symmetric to AddMDIChild() above
303 break;
304
305 case 2:
306 // only one MDI child is going to remain, disable the menu commands
307 // which don't make sense for a single child window
308 UpdateWindowMenu(false);
309 break;
ecc63060
VZ
310 }
311}
312
313// ----------------------------------------------------------------------------
314// wxMDIParentFrame window menu handling
315// ----------------------------------------------------------------------------
316
317void wxMDIParentFrame::AddWindowMenu()
318{
319 if ( m_windowMenu )
679dc4e8
VZ
320 {
321 // For correct handling of the events from this menu we also must
322 // attach it to the menu bar.
323 m_windowMenu->Attach(GetMenuBar());
324
ecc63060 325 MDIInsertWindowMenu(GetClientWindow(), m_hMenu, GetMDIWindowMenu(this));
679dc4e8 326 }
ecc63060
VZ
327}
328
329void wxMDIParentFrame::RemoveWindowMenu()
330{
331 if ( m_windowMenu )
679dc4e8 332 {
ecc63060 333 MDIRemoveWindowMenu(GetClientWindow(), m_hMenu);
679dc4e8
VZ
334
335 m_windowMenu->Detach();
336 }
ecc63060
VZ
337}
338
6125428d
VZ
339void wxMDIParentFrame::UpdateWindowMenu(bool enable)
340{
341 if ( m_windowMenu )
342 {
1483e5db
VZ
343 m_windowMenu->Enable(wxID_MDI_WINDOW_NEXT, enable);
344 m_windowMenu->Enable(wxID_MDI_WINDOW_PREV, enable);
6125428d
VZ
345 }
346}
347
1e6feb95
VZ
348#if wxUSE_MENUS_NATIVE
349
42e69d6b 350void wxMDIParentFrame::InternalSetMenuBar()
2bda0e17 351{
ecc63060
VZ
352 if ( GetActiveChild() )
353 {
354 AddWindowMenu();
355 }
356 else // we don't have any MDI children yet
357 {
358 // wait until we do to add the window menu but do set the main menu for
359 // now (this is done by AddWindowMenu() as a side effect)
360 MDISetMenu(GetClientWindow(), (HMENU)m_hMenu, NULL);
361 }
2bda0e17
KB
362}
363
1e6feb95
VZ
364#endif // wxUSE_MENUS_NATIVE
365
df61c009
JS
366void wxMDIParentFrame::SetWindowMenu(wxMenu* menu)
367{
1483e5db
VZ
368 if ( menu != m_windowMenu )
369 {
370 // notice that Remove/AddWindowMenu() are safe to call even when
371 // m_windowMenu is NULL
372 RemoveWindowMenu();
373
374 delete m_windowMenu;
375
376 m_windowMenu = menu;
df61c009 377
1483e5db
VZ
378 AddWindowMenu();
379 }
4e152a23 380
1483e5db 381#if wxUSE_ACCEL
5276b0a5 382 wxDELETE(m_accelWindowMenu);
ecc63060 383
1483e5db
VZ
384 if ( menu && menu->HasAccels() )
385 m_accelWindowMenu = menu->CreateAccelTable();
386#endif // wxUSE_ACCEL
df61c009
JS
387}
388
51181d29
VZ
389// ----------------------------------------------------------------------------
390// wxMDIParentFrame other menu-related stuff
391// ----------------------------------------------------------------------------
392
6aca4628
CE
393void wxMDIParentFrame::DoMenuUpdates(wxMenu* menu)
394{
395 wxMDIChildFrame *child = GetActiveChild();
396 if ( child )
397 {
398 wxEvtHandler* source = child->GetEventHandler();
399 wxMenuBar* bar = child->GetMenuBar();
400
401 if (menu)
402 {
403 menu->UpdateUI(source);
404 }
405 else
406 {
407 if ( bar != NULL )
408 {
409 int nCount = bar->GetMenuCount();
410 for (int n = 0; n < nCount; n++)
92218ce6 411 bar->GetMenu(n)->UpdateUI(source);
6aca4628
CE
412 }
413 }
414 }
415 else
416 {
417 wxFrameBase::DoMenuUpdates(menu);
418 }
419}
420
79f9ea05 421wxMenuItem *wxMDIParentFrame::FindItemInMenuBar(int menuId) const
10816efb 422{
79f9ea05 423 wxMenuItem *item = wxFrame::FindItemInMenuBar(menuId);
1483e5db 424 if ( !item && GetActiveChild() )
10816efb 425 {
1483e5db 426 item = GetActiveChild()->FindItemInMenuBar(menuId);
10816efb
VZ
427 }
428
79f9ea05
VZ
429 if ( !item && m_windowMenu )
430 item = m_windowMenu->FindItem(menuId);
431
10816efb
VZ
432 return item;
433}
434
51181d29
VZ
435WXHMENU wxMDIParentFrame::MSWGetActiveMenu() const
436{
437 wxMDIChildFrame * const child = GetActiveChild();
438 if ( child )
439 {
440 const WXHMENU hmenu = child->MSWGetActiveMenu();
441 if ( hmenu )
442 return hmenu;
443 }
444
445 return wxFrame::MSWGetActiveMenu();
446}
447
448#endif // wxUSE_MENUS
449
450// ----------------------------------------------------------------------------
451// wxMDIParentFrame event handling
452// ----------------------------------------------------------------------------
453
6bbe97b7 454void wxMDIParentFrame::UpdateClientSize()
2bda0e17 455{
2bda0e17 456 if ( GetClientWindow() )
42e69d6b
VZ
457 {
458 int width, height;
459 GetClientSize(&width, &height);
2bda0e17 460
42e69d6b
VZ
461 GetClientWindow()->SetSize(0, 0, width, height);
462 }
2bda0e17
KB
463}
464
6bbe97b7
VZ
465void wxMDIParentFrame::OnSize(wxSizeEvent& WXUNUSED(event))
466{
467 UpdateClientSize();
468
469 // do not call event.Skip() here, it somehow messes up MDI client window
470}
471
472void wxMDIParentFrame::OnIconized(wxIconizeEvent& event)
473{
474 event.Skip();
475
6ad7799c 476 if ( !event.IsIconized() )
6bbe97b7 477 UpdateClientSize();
6bbe97b7
VZ
478}
479
2bda0e17
KB
480// Responds to colour changes, and passes event on to children.
481void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
482{
483 if ( m_clientWindow )
484 {
a756f210 485 m_clientWindow->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
2bda0e17
KB
486 m_clientWindow->Refresh();
487 }
2bda0e17 488
42e69d6b 489 event.Skip();
2bda0e17
KB
490}
491
82c9f85c
VZ
492WXHICON wxMDIParentFrame::GetDefaultIcon() const
493{
94826170
VZ
494 // we don't have any standard icons (any more)
495 return (WXHICON)0;
82c9f85c
VZ
496}
497
42e69d6b 498// ---------------------------------------------------------------------------
2bda0e17 499// MDI operations
42e69d6b
VZ
500// ---------------------------------------------------------------------------
501
c2dcfdef 502void wxMDIParentFrame::Cascade()
2bda0e17 503{
a23fd0e1 504 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE, 0, 0);
2bda0e17
KB
505}
506
0d97c090 507void wxMDIParentFrame::Tile(wxOrientation orient)
2bda0e17 508{
0d97c090 509 wxASSERT_MSG( orient == wxHORIZONTAL || orient == wxVERTICAL,
9a83f860 510 wxT("invalid orientation value") );
0d97c090
VZ
511
512 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE,
513 orient == wxHORIZONTAL ? MDITILE_HORIZONTAL
514 : MDITILE_VERTICAL, 0);
2bda0e17
KB
515}
516
c2dcfdef 517void wxMDIParentFrame::ArrangeIcons()
2bda0e17 518{
a23fd0e1 519 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE, 0, 0);
2bda0e17
KB
520}
521
c2dcfdef 522void wxMDIParentFrame::ActivateNext()
2bda0e17 523{
a23fd0e1 524 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 0);
2bda0e17
KB
525}
526
c2dcfdef 527void wxMDIParentFrame::ActivatePrevious()
2bda0e17 528{
a23fd0e1 529 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 1);
2bda0e17
KB
530}
531
42e69d6b 532// ---------------------------------------------------------------------------
a23fd0e1 533// the MDI parent frame window proc
42e69d6b
VZ
534// ---------------------------------------------------------------------------
535
c140b7e7 536WXLRESULT wxMDIParentFrame::MSWWindowProc(WXUINT message,
f4be5cd0
VZ
537 WXWPARAM wParam,
538 WXLPARAM lParam)
2bda0e17 539{
c140b7e7 540 WXLRESULT rc = 0;
4f8090e0 541 bool processed = false;
2bda0e17 542
a23fd0e1
VZ
543 switch ( message )
544 {
42e69d6b
VZ
545 case WM_ACTIVATE:
546 {
547 WXWORD state, minimized;
548 WXHWND hwnd;
549 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
550
551 processed = HandleActivate(state, minimized != 0, hwnd);
552 }
553 break;
554
f4be5cd0
VZ
555 case WM_COMMAND:
556 // system messages such as SC_CLOSE are sent as WM_COMMANDs to the
557 // parent MDI frame and we must let the DefFrameProc() have them
558 // for these commands to work (without it, closing the maximized
559 // MDI children doesn't work, for example)
560 {
561 WXWORD id, cmd;
562 WXHWND hwnd;
563 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
564
565 if ( cmd == 0 /* menu */ &&
566 id >= SC_SIZE /* first system menu command */ )
567 {
568 MSWDefWindowProc(message, wParam, lParam);
569 processed = true;
570 }
571 }
572 break;
573
a23fd0e1
VZ
574 case WM_CREATE:
575 m_clientWindow = OnCreateClient();
576 // Uses own style for client style
577 if ( !m_clientWindow->CreateClient(this, GetWindowStyleFlag()) )
578 {
579 wxLogMessage(_("Failed to create MDI parent frame."));
2bda0e17 580
a23fd0e1
VZ
581 rc = -1;
582 }
2bda0e17 583
4f8090e0 584 processed = true;
a23fd0e1 585 break;
a23fd0e1 586 }
2bda0e17 587
a23fd0e1
VZ
588 if ( !processed )
589 rc = wxFrame::MSWWindowProc(message, wParam, lParam);
2bda0e17 590
a23fd0e1 591 return rc;
2bda0e17
KB
592}
593
42e69d6b 594bool wxMDIParentFrame::HandleActivate(int state, bool minimized, WXHWND activate)
2bda0e17 595{
4f8090e0 596 bool processed = false;
a23fd0e1 597
42e69d6b 598 if ( wxWindow::HandleActivate(state, minimized, activate) )
a23fd0e1
VZ
599 {
600 // already processed
4f8090e0 601 processed = true;
a23fd0e1 602 }
2bda0e17
KB
603
604 // If this window is an MDI parent, we must also send an OnActivate message
605 // to the current child.
1483e5db 606 if ( GetActiveChild() &&
a23fd0e1 607 ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)) )
c2dcfdef 608 {
1483e5db
VZ
609 wxActivateEvent event(wxEVT_ACTIVATE, true, GetActiveChild()->GetId());
610 event.SetEventObject( GetActiveChild() );
611 if ( GetActiveChild()->HandleWindowEvent(event) )
4f8090e0 612 processed = true;
2bda0e17 613 }
a23fd0e1
VZ
614
615 return processed;
2bda0e17
KB
616}
617
1483e5db 618#if wxUSE_MENUS
8a0dce9c 619
1483e5db
VZ
620void wxMDIParentFrame::OnMDIChild(wxCommandEvent& event)
621{
622 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
623 while ( node )
e1a6fc11 624 {
1483e5db
VZ
625 wxWindow *child = node->GetData();
626 if ( child->GetHWND() )
627 {
628 int childId = wxGetWindowId(child->GetHWND());
629 if ( childId == event.GetId() )
630 {
0079c032 631 wxStaticCast(child, wxMDIChildFrame)->Activate();
1483e5db
VZ
632 return;
633 }
634 }
e1a6fc11 635
1483e5db 636 node = node->GetNext();
7dbe942a
JS
637 }
638
1483e5db
VZ
639 wxFAIL_MSG( "unknown MDI child selected?" );
640}
641
642void wxMDIParentFrame::OnMDICommand(wxCommandEvent& event)
643{
42e69d6b 644 WXWPARAM wParam = 0;
4f3b37fd 645 WXLPARAM lParam = 0;
42e69d6b 646 int msg;
1483e5db 647 switch ( event.GetId() )
2bda0e17 648 {
1483e5db 649 case wxID_MDI_WINDOW_CASCADE:
42e69d6b
VZ
650 msg = WM_MDICASCADE;
651 wParam = MDITILE_SKIPDISABLED;
652 break;
653
1483e5db 654 case wxID_MDI_WINDOW_TILE_HORZ:
42e69d6b
VZ
655 wParam |= MDITILE_HORIZONTAL;
656 // fall through
657
1483e5db 658 case wxID_MDI_WINDOW_TILE_VERT:
42e69d6b
VZ
659 if ( !wParam )
660 wParam = MDITILE_VERTICAL;
661 msg = WM_MDITILE;
662 wParam |= MDITILE_SKIPDISABLED;
663 break;
664
1483e5db 665 case wxID_MDI_WINDOW_ARRANGE_ICONS:
42e69d6b
VZ
666 msg = WM_MDIICONARRANGE;
667 break;
668
1483e5db 669 case wxID_MDI_WINDOW_NEXT:
42e69d6b 670 msg = WM_MDINEXT;
4f3b37fd
JS
671 lParam = 0; // next child
672 break;
673
1483e5db 674 case wxID_MDI_WINDOW_PREV:
4f3b37fd
JS
675 msg = WM_MDINEXT;
676 lParam = 1; // previous child
42e69d6b
VZ
677 break;
678
679 default:
1483e5db
VZ
680 wxFAIL_MSG( "unknown MDI command" );
681 return;
2bda0e17 682 }
c2dcfdef 683
1483e5db
VZ
684 ::SendMessage(GetWinHwnd(GetClientWindow()), msg, wParam, lParam);
685}
42e69d6b 686
1483e5db 687#endif // wxUSE_MENUS
2bda0e17 688
8cc208e3 689bool wxMDIParentFrame::TryBefore(wxEvent& event)
1483e5db 690{
cd60273b
VZ
691 // menu (and toolbar) events should be sent to the active child frame
692 // first, if any
693 if ( event.GetEventType() == wxEVT_COMMAND_MENU_SELECTED )
694 {
695 wxMDIChildFrame * const child = GetActiveChild();
396e9eb8 696 if ( child && child->ProcessWindowEventLocally(event) )
cd60273b
VZ
697 return true;
698 }
1483e5db 699
8cc208e3 700 return wxMDIParentFrameBase::TryBefore(event);
2bda0e17
KB
701}
702
c140b7e7 703WXLRESULT wxMDIParentFrame::MSWDefWindowProc(WXUINT message,
42e69d6b
VZ
704 WXWPARAM wParam,
705 WXLPARAM lParam)
2bda0e17 706{
c2dcfdef
VZ
707 WXHWND clientWnd;
708 if ( GetClientWindow() )
709 clientWnd = GetClientWindow()->GetHWND();
710 else
711 clientWnd = 0;
2bda0e17 712
a23fd0e1 713 return DefFrameProc(GetHwnd(), (HWND)clientWnd, message, wParam, lParam);
2bda0e17
KB
714}
715
57a7b7c1
JS
716bool wxMDIParentFrame::MSWTranslateMessage(WXMSG* msg)
717{
a23fd0e1 718 MSG *pMsg = (MSG *)msg;
2bda0e17 719
f6bcfd97 720 // first let the current child get it
1483e5db
VZ
721 wxMDIChildFrame * const child = GetActiveChild();
722 if ( child && child->MSWTranslateMessage(msg) )
a23fd0e1 723 {
4f8090e0 724 return true;
a23fd0e1 725 }
2bda0e17 726
1483e5db
VZ
727 // then try out accelerator table (will also check the accelerators for the
728 // normal menu items)
f6bcfd97 729 if ( wxFrame::MSWTranslateMessage(msg) )
a23fd0e1 730 {
4f8090e0 731 return true;
a23fd0e1 732 }
2bda0e17 733
1483e5db
VZ
734#if wxUSE_MENUS && wxUSE_ACCEL
735 // but it doesn't check for the (custom) accelerators of the window menu
736 // items as it's not part of the menu bar as it's handled by Windows itself
737 // so we need to do this explicitly
e61f95ea 738 if ( m_accelWindowMenu && m_accelWindowMenu->Translate(this, msg) )
1483e5db
VZ
739 return true;
740#endif // wxUSE_MENUS && wxUSE_ACCEL
741
742 // finally, check for MDI specific built-in accelerators
a23fd0e1
VZ
743 if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN )
744 {
745 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg))
4f8090e0 746 return true;
a23fd0e1 747 }
57a7b7c1 748
4f8090e0 749 return false;
2bda0e17
KB
750}
751
42e69d6b 752// ===========================================================================
a23fd0e1 753// wxMDIChildFrame
42e69d6b 754// ===========================================================================
2bda0e17 755
f6bcfd97 756void wxMDIChildFrame::Init()
2bda0e17 757{
4f8090e0 758 m_needsResize = true;
2596e9fb 759 m_needsInitialShow = true;
2bda0e17
KB
760}
761
762bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
a23fd0e1
VZ
763 wxWindowID id,
764 const wxString& title,
765 const wxPoint& pos,
766 const wxSize& size,
767 long style,
768 const wxString& name)
2bda0e17 769{
d2824cdb
VZ
770 m_mdiParent = parent;
771
2bda0e17
KB
772 SetName(name);
773
598ddd96 774 if ( id != wxID_ANY )
2bda0e17
KB
775 m_windowId = id;
776 else
cf2810aa 777 m_windowId = NewControlId();
2bda0e17 778
42e69d6b
VZ
779 if ( parent )
780 {
781 parent->AddChild(this);
782 }
2bda0e17 783
2bda0e17
KB
784 int x = pos.x;
785 int y = pos.y;
786 int width = size.x;
787 int height = size.y;
788
789 MDICREATESTRUCT mcs;
c2dcfdef 790
d9698bd4 791 wxString className =
9a83f860 792 wxApp::GetRegisteredClassName(wxT("wxMDIChildFrame"), COLOR_WINDOW);
d9698bd4
VZ
793 if ( !(style & wxFULL_REPAINT_ON_RESIZE) )
794 className += wxApp::GetNoRedrawClassSuffix();
795
017dc06b
VZ
796 mcs.szClass = className.t_str();
797 mcs.szTitle = title.t_str();
2bda0e17 798 mcs.hOwner = wxGetInstance();
598ddd96 799 if (x != wxDefaultCoord)
42e69d6b
VZ
800 mcs.x = x;
801 else
802 mcs.x = CW_USEDEFAULT;
2bda0e17 803
598ddd96 804 if (y != wxDefaultCoord)
42e69d6b
VZ
805 mcs.y = y;
806 else
807 mcs.y = CW_USEDEFAULT;
2bda0e17 808
598ddd96 809 if (width != wxDefaultCoord)
42e69d6b
VZ
810 mcs.cx = width;
811 else
812 mcs.cx = CW_USEDEFAULT;
2bda0e17 813
598ddd96 814 if (height != wxDefaultCoord)
42e69d6b
VZ
815 mcs.cy = height;
816 else
817 mcs.cy = CW_USEDEFAULT;
2bda0e17 818
2596e9fb 819 DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN;
2bda0e17
KB
820 if (style & wxMINIMIZE_BOX)
821 msflags |= WS_MINIMIZEBOX;
822 if (style & wxMAXIMIZE_BOX)
823 msflags |= WS_MAXIMIZEBOX;
1c067fe3 824 if (style & wxRESIZE_BORDER)
2bda0e17
KB
825 msflags |= WS_THICKFRAME;
826 if (style & wxSYSTEM_MENU)
827 msflags |= WS_SYSMENU;
828 if ((style & wxMINIMIZE) || (style & wxICONIZE))
829 msflags |= WS_MINIMIZE;
830 if (style & wxMAXIMIZE)
831 msflags |= WS_MAXIMIZE;
832 if (style & wxCAPTION)
833 msflags |= WS_CAPTION;
834
835 mcs.style = msflags;
836
837 mcs.lParam = 0;
838
b225f659
VZ
839 wxWindowCreationHook hook(this);
840
3ca6a5f0 841 m_hWnd = (WXHWND)::SendMessage(GetWinHwnd(parent->GetClientWindow()),
dca0f651 842 WM_MDICREATE, 0, (LPARAM)&mcs);
2bda0e17 843
05ae668c
VZ
844 if ( !m_hWnd )
845 {
9a83f860 846 wxLogLastError(wxT("WM_MDICREATE"));
05ae668c
VZ
847 return false;
848 }
849
850 SubclassWin(m_hWnd);
2bda0e17 851
ecc63060
VZ
852 parent->AddMDIChild(this);
853
4f8090e0 854 return true;
2bda0e17
KB
855}
856
c2dcfdef 857wxMDIChildFrame::~wxMDIChildFrame()
2bda0e17 858{
b38e5da1
VZ
859 // if we hadn't been created, there is nothing to destroy
860 if ( !m_hWnd )
861 return;
862
ecc63060
VZ
863 GetMDIParent()->RemoveMDIChild(this);
864
d1e44484
VZ
865 // will be destroyed by DestroyChildren() but reset them before calling it
866 // to avoid using dangling pointers if a callback comes in the meanwhile
1904aa72 867#if wxUSE_TOOLBAR
627a3091 868 m_frameToolBar = NULL;
1904aa72 869#endif
67a99992 870#if wxUSE_STATUSBAR
627a3091 871 m_frameStatusBar = NULL;
67a99992 872#endif // wxUSE_STATUSBAR
627a3091 873
d1e44484
VZ
874 DestroyChildren();
875
ecc63060 876 MDIRemoveWindowMenu(NULL, m_hMenu);
4e152a23 877
c2dcfdef 878 MSWDestroyWindow();
2bda0e17
KB
879}
880
2596e9fb
VS
881bool wxMDIChildFrame::Show(bool show)
882{
883 m_needsInitialShow = false;
6fa30495
KH
884
885 if (!wxFrame::Show(show))
886 return false;
887
888 // KH: Without this call, new MDI children do not become active.
889 // This was added here after the same BringWindowToTop call was
890 // removed from wxTopLevelWindow::Show (November 2005)
891 if ( show )
892 ::BringWindowToTop(GetHwnd());
893
e45a6885
VZ
894 // we need to refresh the MDI frame window menu to include (or exclude if
895 // we've been hidden) this frame
d2824cdb 896 wxMDIParentFrame * const parent = GetMDIParent();
e45a6885
VZ
897 MDISetMenu(parent->GetClientWindow(), NULL, NULL);
898
6fa30495 899 return true;
2596e9fb
VS
900}
901
0598625c
VZ
902void
903wxMDIChildFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags)
904{
905 // we need to disable client area origin adjustments used for the child
906 // windows for the frame itself
907 wxMDIChildFrameBase::DoSetSize(x, y, width, height, sizeFlags);
908}
909
2bda0e17 910// Set the client size (i.e. leave the calculation of borders etc.
77ffb593 911// to wxWidgets)
cc2b7472 912void wxMDIChildFrame::DoSetClientSize(int width, int height)
2bda0e17 913{
b3818fbe 914 HWND hWnd = GetHwnd();
2bda0e17
KB
915
916 RECT rect;
2de8030d 917 ::GetClientRect(hWnd, &rect);
2bda0e17
KB
918
919 RECT rect2;
920 GetWindowRect(hWnd, &rect2);
921
922 // Find the difference between the entire window (title bar and all)
923 // and the client area; add this to the new client size to move the
924 // window
925 int actual_width = rect2.right - rect2.left - rect.right + width;
926 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
927
67a99992 928#if wxUSE_STATUSBAR
a2327a9f 929 if (GetStatusBar() && GetStatusBar()->IsShown())
2bda0e17 930 {
c2dcfdef
VZ
931 int sx, sy;
932 GetStatusBar()->GetSize(&sx, &sy);
2bda0e17
KB
933 actual_height += sy;
934 }
67a99992 935#endif // wxUSE_STATUSBAR
2bda0e17
KB
936
937 POINT point;
938 point.x = rect2.left;
939 point.y = rect2.top;
940
941 // If there's an MDI parent, must subtract the parent's top left corner
942 // since MoveWindow moves relative to the parent
d2824cdb
VZ
943 wxMDIParentFrame * const mdiParent = GetMDIParent();
944 ::ScreenToClient(GetHwndOf(mdiParent->GetClientWindow()), &point);
2bda0e17 945
4f8090e0 946 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)true);
debe6624 947
5c519b6c
WS
948 wxSize size(width, height);
949 wxSizeEvent event(size, m_windowId);
debe6624 950 event.SetEventObject( this );
937013e0 951 HandleWindowEvent(event);
2bda0e17
KB
952}
953
3e85709e
VZ
954// Unlike other wxTopLevelWindowBase, the mdi child's "GetPosition" is not the
955// same as its GetScreenPosition
956void wxMDIChildFrame::DoGetScreenPosition(int *x, int *y) const
957{
958 HWND hWnd = GetHwnd();
959
960 RECT rect;
961 ::GetWindowRect(hWnd, &rect);
962 if (x)
963 *x = rect.left;
964 if (y)
965 *y = rect.top;
966}
967
968
cc2b7472 969void wxMDIChildFrame::DoGetPosition(int *x, int *y) const
2bda0e17
KB
970{
971 RECT rect;
b3818fbe 972 GetWindowRect(GetHwnd(), &rect);
2bda0e17
KB
973 POINT point;
974 point.x = rect.left;
975 point.y = rect.top;
976
977 // Since we now have the absolute screen coords,
978 // if there's a parent we must subtract its top left corner
d2824cdb
VZ
979 wxMDIParentFrame * const mdiParent = GetMDIParent();
980 ::ScreenToClient(GetHwndOf(mdiParent->GetClientWindow()), &point);
2bda0e17 981
1696dde5
JS
982 if (x)
983 *x = point.x;
984 if (y)
985 *y = point.y;
2bda0e17
KB
986}
987
42e69d6b 988void wxMDIChildFrame::InternalSetMenuBar()
2bda0e17 989{
d2824cdb 990 wxMDIParentFrame * const parent = GetMDIParent();
2bda0e17 991
ecc63060 992 MDIInsertWindowMenu(parent->GetClientWindow(),
4e152a23 993 m_hMenu, GetMDIWindowMenu(parent));
2bda0e17
KB
994}
995
e3307ddd
CE
996void wxMDIChildFrame::DetachMenuBar()
997{
ecc63060 998 MDIRemoveWindowMenu(NULL, m_hMenu);
6bbe97b7 999 wxFrame::DetachMenuBar();
e3307ddd
CE
1000}
1001
82c9f85c
VZ
1002WXHICON wxMDIChildFrame::GetDefaultIcon() const
1003{
94826170
VZ
1004 // we don't have any standard icons (any more)
1005 return (WXHICON)0;
82c9f85c
VZ
1006}
1007
42e69d6b 1008// ---------------------------------------------------------------------------
2bda0e17 1009// MDI operations
42e69d6b
VZ
1010// ---------------------------------------------------------------------------
1011
9b73db3c 1012void wxMDIChildFrame::Maximize(bool maximize)
2bda0e17 1013{
d2824cdb 1014 wxMDIParentFrame * const parent = GetMDIParent();
2bda0e17 1015 if ( parent && parent->GetClientWindow() )
9b73db3c
VZ
1016 {
1017 ::SendMessage(GetWinHwnd(parent->GetClientWindow()),
1018 maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE,
1019 (WPARAM)GetHwnd(), 0);
1020 }
2bda0e17
KB
1021}
1022
c2dcfdef 1023void wxMDIChildFrame::Restore()
2bda0e17 1024{
d2824cdb 1025 wxMDIParentFrame * const parent = GetMDIParent();
2bda0e17 1026 if ( parent && parent->GetClientWindow() )
9b73db3c
VZ
1027 {
1028 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE,
1029 (WPARAM) GetHwnd(), 0);
1030 }
2bda0e17
KB
1031}
1032
c2dcfdef 1033void wxMDIChildFrame::Activate()
2bda0e17 1034{
d2824cdb 1035 wxMDIParentFrame * const parent = GetMDIParent();
2bda0e17 1036 if ( parent && parent->GetClientWindow() )
9b73db3c 1037 {
254dceaa
VZ
1038 // Activating an iconized MDI frame doesn't do anything, so restore it
1039 // first to really present it to the user.
1040 if ( IsIconized() )
1041 Restore();
1042
9b73db3c
VZ
1043 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE,
1044 (WPARAM) GetHwnd(), 0);
1045 }
2bda0e17
KB
1046}
1047
42e69d6b
VZ
1048// ---------------------------------------------------------------------------
1049// MDI window proc and message handlers
1050// ---------------------------------------------------------------------------
1051
c140b7e7 1052WXLRESULT wxMDIChildFrame::MSWWindowProc(WXUINT message,
f4be5cd0
VZ
1053 WXWPARAM wParam,
1054 WXLPARAM lParam)
42e69d6b 1055{
c140b7e7 1056 WXLRESULT rc = 0;
4f8090e0 1057 bool processed = false;
42e69d6b
VZ
1058
1059 switch ( message )
1060 {
42e69d6b 1061 case WM_GETMINMAXINFO:
3ebcfb76
VZ
1062 processed = HandleGetMinMaxInfo((MINMAXINFO *)lParam);
1063 break;
42e69d6b
VZ
1064
1065 case WM_MDIACTIVATE:
1066 {
1067 WXWORD act;
1068 WXHWND hwndAct, hwndDeact;
1069 UnpackMDIActivate(wParam, lParam, &act, &hwndAct, &hwndDeact);
1070
1071 processed = HandleMDIActivate(act, hwndAct, hwndDeact);
1072 }
b3818fbe
VZ
1073 // fall through
1074
1075 case WM_MOVE:
1076 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
1077 // scrollbars if necessary
1078
1079 // fall through
1080
1081 case WM_SIZE:
1082 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
1083 // things happen
1084 MSWDefWindowProc(message, wParam, lParam);
42e69d6b
VZ
1085 break;
1086
1087 case WM_WINDOWPOSCHANGING:
1088 processed = HandleWindowPosChanging((LPWINDOWPOS)lParam);
1089 break;
1090 }
1091
1092 if ( !processed )
1093 rc = wxFrame::MSWWindowProc(message, wParam, lParam);
1094
1095 return rc;
1096}
1097
42e69d6b
VZ
1098bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate),
1099 WXHWND hwndAct,
1100 WXHWND hwndDeact)
2bda0e17 1101{
d2824cdb 1102 wxMDIParentFrame * const parent = GetMDIParent();
2bda0e17 1103
51181d29 1104 WXHMENU hMenuToSet = 0;
57a7b7c1 1105
42e69d6b 1106 bool activated;
57a7b7c1 1107
42e69d6b
VZ
1108 if ( m_hWnd == hwndAct )
1109 {
4f8090e0 1110 activated = true;
1483e5db 1111 parent->SetActiveChild(this);
2bda0e17 1112
51181d29
VZ
1113 WXHMENU hMenuChild = m_hMenu;
1114 if ( hMenuChild )
51181d29 1115 hMenuToSet = hMenuChild;
42e69d6b
VZ
1116 }
1117 else if ( m_hWnd == hwndDeact )
2bda0e17 1118 {
1483e5db 1119 wxASSERT_MSG( parent->GetActiveChild() == this,
223d09f6 1120 wxT("can't deactivate MDI child which wasn't active!") );
42e69d6b 1121
4f8090e0 1122 activated = false;
1483e5db 1123 parent->SetActiveChild(NULL);
2bda0e17 1124
51181d29 1125 WXHMENU hMenuParent = parent->m_hMenu;
f4075804 1126
4c51a665 1127 // activate the parent menu only when there is no other child
f4075804 1128 // that has been activated
51181d29 1129 if ( hMenuParent && !hwndAct )
51181d29 1130 hMenuToSet = hMenuParent;
42e69d6b
VZ
1131 }
1132 else
1133 {
18d2e170 1134 // we have nothing to do with it
4f8090e0 1135 return false;
2bda0e17 1136 }
debe6624 1137
51181d29 1138 if ( hMenuToSet )
42e69d6b 1139 {
4e152a23 1140 MDISetMenu(parent->GetClientWindow(),
51181d29 1141 (HMENU)hMenuToSet, GetMDIWindowMenu(parent));
42e69d6b
VZ
1142 }
1143
1144 wxActivateEvent event(wxEVT_ACTIVATE, activated, m_windowId);
debe6624 1145 event.SetEventObject( this );
2bda0e17 1146
d3b9f782 1147 ResetWindowStyle(NULL);
c03b48d7 1148
937013e0 1149 return HandleWindowEvent(event);
42e69d6b
VZ
1150}
1151
1152bool wxMDIChildFrame::HandleWindowPosChanging(void *pos)
1153{
1154 WINDOWPOS *lpPos = (WINDOWPOS *)pos;
a71d815b 1155
42e69d6b 1156 if (!(lpPos->flags & SWP_NOSIZE))
2bda0e17 1157 {
42e69d6b 1158 RECT rectClient;
b3818fbe
VZ
1159 DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
1160 DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
42e69d6b
VZ
1161 if (ResetWindowStyle((void *) & rectClient) && (dwStyle & WS_MAXIMIZE))
1162 {
4f8090e0 1163 ::AdjustWindowRectEx(&rectClient, dwStyle, false, dwExStyle);
42e69d6b
VZ
1164 lpPos->x = rectClient.left;
1165 lpPos->y = rectClient.top;
1166 lpPos->cx = rectClient.right - rectClient.left;
1167 lpPos->cy = rectClient.bottom - rectClient.top;
1168 }
42e69d6b 1169 }
42e69d6b 1170
4f8090e0 1171 return false;
42e69d6b
VZ
1172}
1173
3ebcfb76
VZ
1174bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo)
1175{
1176 MINMAXINFO *info = (MINMAXINFO *)mmInfo;
1177
1178 // let the default window proc calculate the size of MDI children
1179 // frames because it is based on the size of the MDI client window,
1180 // not on the values specified in wxWindow m_max variables
d9f9aa2d 1181 bool processed = MSWDefWindowProc(WM_GETMINMAXINFO, 0, (LPARAM)mmInfo) != 0;
3ebcfb76 1182
e7dda1ff
VS
1183 int minWidth = GetMinWidth(),
1184 minHeight = GetMinHeight();
1185
3ebcfb76 1186 // but allow GetSizeHints() to set the min size
a71d815b 1187 if ( minWidth != wxDefaultCoord )
3ebcfb76 1188 {
e7dda1ff 1189 info->ptMinTrackSize.x = minWidth;
3ebcfb76 1190
4f8090e0 1191 processed = true;
3ebcfb76
VZ
1192 }
1193
a71d815b 1194 if ( minHeight != wxDefaultCoord )
3ebcfb76 1195 {
e7dda1ff 1196 info->ptMinTrackSize.y = minHeight;
3ebcfb76 1197
4f8090e0 1198 processed = true;
3ebcfb76
VZ
1199 }
1200
4c9d78a4 1201 return processed;
3ebcfb76
VZ
1202}
1203
42e69d6b
VZ
1204// ---------------------------------------------------------------------------
1205// MDI specific message translation/preprocessing
1206// ---------------------------------------------------------------------------
2bda0e17 1207
c140b7e7 1208WXLRESULT wxMDIChildFrame::MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
42e69d6b
VZ
1209{
1210 return DefMDIChildProc(GetHwnd(),
1211 (UINT)message, (WPARAM)wParam, (LPARAM)lParam);
1212}
1213
1214bool wxMDIChildFrame::MSWTranslateMessage(WXMSG* msg)
1215{
1ac76609
VZ
1216 // we must pass the parent frame to ::TranslateAccelerator(), otherwise it
1217 // doesn't do its job correctly for MDI child menus
55ae1551 1218 return MSWDoTranslateMessage(GetMDIParent(), msg);
2bda0e17
KB
1219}
1220
42e69d6b
VZ
1221// ---------------------------------------------------------------------------
1222// misc
1223// ---------------------------------------------------------------------------
1224
c2dcfdef 1225void wxMDIChildFrame::MSWDestroyWindow()
2bda0e17 1226{
d2824cdb 1227 wxMDIParentFrame * const parent = GetMDIParent();
2bda0e17 1228
42e69d6b
VZ
1229 // Must make sure this handle is invalidated (set to NULL) since all sorts
1230 // of things could happen after the child client is destroyed, but before
1231 // the wxFrame is destroyed.
2bda0e17 1232
42e69d6b 1233 HWND oldHandle = (HWND)GetHWND();
b3818fbe
VZ
1234 SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIDESTROY,
1235 (WPARAM)oldHandle, 0);
18d2e170 1236
ecc63060
VZ
1237 if (parent->GetActiveChild() == NULL)
1238 ResetWindowStyle(NULL);
18d2e170 1239
42e69d6b
VZ
1240 if (m_hMenu)
1241 {
1242 ::DestroyMenu((HMENU) m_hMenu);
1243 m_hMenu = 0;
1244 }
ac6482e0 1245 wxRemoveHandleAssociation(this);
42e69d6b 1246 m_hWnd = 0;
2bda0e17
KB
1247}
1248
42e69d6b
VZ
1249// Change the client window's extended style so we don't get a client edge
1250// style when a child is maximised (a double border looks silly.)
2bda0e17
KB
1251bool wxMDIChildFrame::ResetWindowStyle(void *vrect)
1252{
2bda0e17 1253 RECT *rect = (RECT *)vrect;
d2824cdb 1254 wxMDIParentFrame * const pFrameWnd = GetMDIParent();
c2dcfdef 1255 wxMDIChildFrame* pChild = pFrameWnd->GetActiveChild();
a71d815b 1256
c2dcfdef
VZ
1257 if (!pChild || (pChild == this))
1258 {
47ca6bfb 1259 HWND hwndClient = GetWinHwnd(pFrameWnd->GetClientWindow());
8082a771
VZ
1260 DWORD dwStyle = ::GetWindowLong(hwndClient, GWL_EXSTYLE);
1261
1262 // we want to test whether there is a maximized child, so just set
1263 // dwThisStyle to 0 if there is no child at all
1264 DWORD dwThisStyle = pChild
1f3943e0 1265 ? ::GetWindowLong(GetWinHwnd(pChild), GWL_STYLE) : 0;
c2dcfdef 1266 DWORD dwNewStyle = dwStyle;
8082a771 1267 if ( dwThisStyle & WS_MAXIMIZE )
c2dcfdef
VZ
1268 dwNewStyle &= ~(WS_EX_CLIENTEDGE);
1269 else
1270 dwNewStyle |= WS_EX_CLIENTEDGE;
1271
1272 if (dwStyle != dwNewStyle)
1273 {
47ca6bfb
VZ
1274 // force update of everything
1275 ::RedrawWindow(hwndClient, NULL, NULL,
1276 RDW_INVALIDATE | RDW_ALLCHILDREN);
1277 ::SetWindowLong(hwndClient, GWL_EXSTYLE, dwNewStyle);
1278 ::SetWindowPos(hwndClient, NULL, 0, 0, 0, 0,
42e69d6b
VZ
1279 SWP_FRAMECHANGED | SWP_NOACTIVATE |
1280 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
1281 SWP_NOCOPYBITS);
c2dcfdef 1282 if (rect)
47ca6bfb 1283 ::GetClientRect(hwndClient, rect);
2bda0e17 1284
4f8090e0 1285 return true;
2bda0e17 1286 }
c2dcfdef 1287 }
a23fd0e1 1288
4f8090e0 1289 return false;
2bda0e17
KB
1290}
1291
42e69d6b
VZ
1292// ===========================================================================
1293// wxMDIClientWindow: the window of predefined (by Windows) class which
1294// contains the child frames
1295// ===========================================================================
2bda0e17 1296
debe6624 1297bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
2bda0e17 1298{
a756f210 1299 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
2bda0e17 1300
42e69d6b
VZ
1301 CLIENTCREATESTRUCT ccs;
1302 m_windowStyle = style;
1303 m_parent = parent;
c2dcfdef 1304
4e152a23 1305 ccs.hWindowMenu = GetMDIWindowMenu(parent);
42e69d6b 1306 ccs.idFirstChild = wxFIRST_MDI_CHILD;
2bda0e17 1307
5c44cd05 1308 DWORD msStyle = MDIS_ALLCHILDSTYLES | WS_VISIBLE | WS_CHILD |
b0766406
JS
1309 WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
1310
42e69d6b
VZ
1311 if ( style & wxHSCROLL )
1312 msStyle |= WS_HSCROLL;
1313 if ( style & wxVSCROLL )
1314 msStyle |= WS_VSCROLL;
2bda0e17 1315
42e69d6b 1316 DWORD exStyle = WS_EX_CLIENTEDGE;
2bda0e17 1317
b225f659 1318 wxWindowCreationHook hook(this);
42e69d6b
VZ
1319 m_hWnd = (WXHWND)::CreateWindowEx
1320 (
1321 exStyle,
223d09f6 1322 wxT("MDICLIENT"),
42e69d6b
VZ
1323 NULL,
1324 msStyle,
1325 0, 0, 0, 0,
1326 GetWinHwnd(parent),
1327 NULL,
1328 wxGetInstance(),
1329 (LPSTR)(LPCLIENTCREATESTRUCT)&ccs);
1330 if ( !m_hWnd )
1331 {
f6bcfd97 1332 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
2bda0e17 1333
4f8090e0 1334 return false;
42e69d6b 1335 }
2bda0e17 1336
42e69d6b 1337 SubclassWin(m_hWnd);
2bda0e17 1338
4f8090e0 1339 return true;
2bda0e17
KB
1340}
1341
1342// Explicitly call default scroll behaviour
1343void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
1344{
1345 // Note: for client windows, the scroll position is not set in
1346 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1347 // scroll position we're at.
1348 // This makes it hard to paint patterns or bitmaps in the background,
1349 // and have the client area scrollable as well.
1350
1351 if ( event.GetOrientation() == wxHORIZONTAL )
1352 m_scrollX = event.GetPosition(); // Always returns zero!
1353 else
1354 m_scrollY = event.GetPosition(); // Always returns zero!
1355
42e69d6b
VZ
1356 event.Skip();
1357}
1358
ec06b234
JS
1359void wxMDIClientWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1360{
1361 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1362 // client area, you can end up with a non-refreshed portion in the client window
1363 // (see OGL studio sample). So check if the position is changed and if so,
1364 // redraw the MDI child frames.
1365
6bbe97b7 1366 const wxPoint oldPos = GetPosition();
ec06b234 1367
6bbe97b7 1368 wxWindow::DoSetSize(x, y, width, height, sizeFlags | wxSIZE_FORCE);
ec06b234 1369
6bbe97b7 1370 const wxPoint newPos = GetPosition();
ec06b234
JS
1371
1372 if ((newPos.x != oldPos.x) || (newPos.y != oldPos.y))
1373 {
1374 if (GetParent())
1375 {
222ed1d6 1376 wxWindowList::compatibility_iterator node = GetParent()->GetChildren().GetFirst();
ec06b234
JS
1377 while (node)
1378 {
d162a7ee 1379 wxWindow *child = node->GetData();
345c78ca 1380 if (wxDynamicCast(child, wxMDIChildFrame))
ec06b234 1381 {
d162a7ee
VZ
1382 ::RedrawWindow(GetHwndOf(child),
1383 NULL,
1384 NULL,
1385 RDW_FRAME |
1386 RDW_ALLCHILDREN |
1387 RDW_INVALIDATE);
ec06b234 1388 }
4f8090e0 1389 node = node->GetNext();
ec06b234
JS
1390 }
1391 }
1392 }
1393}
1394
f6bcfd97
BP
1395void wxMDIChildFrame::OnIdle(wxIdleEvent& event)
1396{
2596e9fb
VS
1397 // wxMSW prior to 2.5.3 created MDI child frames as visible, which resulted
1398 // in flicker e.g. when the frame contained controls with non-trivial
1399 // layout. Since 2.5.3, the frame is created hidden as all other top level
1400 // windows. In order to maintain backward compatibility, the frame is shown
1401 // in OnIdle, unless Show(false) was called by the programmer before.
1402 if ( m_needsInitialShow )
1403 {
1404 Show(true);
1405 }
5c519b6c 1406
f6bcfd97
BP
1407 // MDI child frames get their WM_SIZE when they're constructed but at this
1408 // moment they don't have any children yet so all child windows will be
1409 // positioned incorrectly when they are added later - to fix this, we
1410 // generate an artificial size event here
1411 if ( m_needsResize )
1412 {
4f8090e0 1413 m_needsResize = false; // avoid any possibility of recursion
f6bcfd97
BP
1414
1415 SendSizeEvent();
1416 }
1417
1418 event.Skip();
1419}
1420
42e69d6b 1421// ---------------------------------------------------------------------------
838e6ed7 1422// private helper functions
42e69d6b
VZ
1423// ---------------------------------------------------------------------------
1424
838e6ed7
VZ
1425namespace
1426{
1427
1428void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow)
42e69d6b 1429{
e45a6885
VZ
1430 if ( hmenuFrame || hmenuWindow )
1431 {
1432 if ( !::SendMessage(GetWinHwnd(win),
1433 WM_MDISETMENU,
1434 (WPARAM)hmenuFrame,
1435 (LPARAM)hmenuWindow) )
1436 {
0d7c4404
VZ
1437 DWORD err = ::GetLastError();
1438 if ( err )
43b2d5e7 1439 {
9a83f860 1440 wxLogApiError(wxT("SendMessage(WM_MDISETMENU)"), err);
43b2d5e7 1441 }
e45a6885
VZ
1442 }
1443 }
42e69d6b
VZ
1444
1445 // update menu bar of the parent window
1446 wxWindow *parent = win->GetParent();
223d09f6 1447 wxCHECK_RET( parent, wxT("MDI client without parent frame? weird...") );
42e69d6b 1448
a967ef9d 1449 ::SendMessage(GetWinHwnd(win), WM_MDIREFRESHMENU, 0, 0L);
788722ac 1450
42e69d6b
VZ
1451 ::DrawMenuBar(GetWinHwnd(parent));
1452}
1453
838e6ed7 1454void MDIInsertWindowMenu(wxWindow *win, WXHMENU hMenu, HMENU menuWin)
42e69d6b 1455{
838e6ed7 1456 HMENU hmenu = (HMENU)hMenu;
df61c009 1457
838e6ed7 1458 if ( menuWin )
df61c009 1459 {
838e6ed7 1460 // Try to insert Window menu in front of Help, otherwise append it.
4e152a23 1461 int N = GetMenuItemCount(hmenu);
838e6ed7 1462 bool inserted = false;
4e152a23 1463 for ( int i = 0; i < N; i++ )
42e69d6b 1464 {
4e152a23 1465 wxChar buf[256];
838e6ed7 1466 if ( !::GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) )
4e152a23
VZ
1467 {
1468 wxLogLastError(wxT("GetMenuString"));
42e69d6b 1469
4e152a23
VZ
1470 continue;
1471 }
1472
838e6ed7
VZ
1473 const wxString label = wxStripMenuCodes(buf);
1474 if ( label == wxGetStockLabel(wxID_HELP, wxSTOCK_NOFLAGS) )
4e152a23 1475 {
838e6ed7 1476 inserted = true;
4e152a23 1477 ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
838e6ed7 1478 (UINT_PTR)menuWin,
017dc06b 1479 wxString(wxGetTranslation(WINDOW_MENU_LABEL)).t_str());
4e152a23
VZ
1480 break;
1481 }
42e69d6b
VZ
1482 }
1483
838e6ed7 1484 if ( !inserted )
42e69d6b 1485 {
dca0f651 1486 ::AppendMenu(hmenu, MF_POPUP,
838e6ed7 1487 (UINT_PTR)menuWin,
017dc06b 1488 wxString(wxGetTranslation(WINDOW_MENU_LABEL)).t_str());
42e69d6b
VZ
1489 }
1490 }
1491
838e6ed7 1492 MDISetMenu(win, hmenu, menuWin);
42e69d6b
VZ
1493}
1494
838e6ed7 1495void MDIRemoveWindowMenu(wxWindow *win, WXHMENU hMenu)
df61c009 1496{
838e6ed7 1497 HMENU hmenu = (HMENU)hMenu;
4e152a23 1498
838e6ed7 1499 if ( hmenu )
df61c009 1500 {
4e152a23
VZ
1501 wxChar buf[1024];
1502
838e6ed7 1503 int N = ::GetMenuItemCount(hmenu);
4e152a23 1504 for ( int i = 0; i < N; i++ )
df61c009 1505 {
838e6ed7 1506 if ( !::GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) )
4e152a23 1507 {
2c62b3c3 1508 // Ignore successful read of menu string with length 0 which
838e6ed7 1509 // occurs, for example, for a maximized MDI child system menu
2c62b3c3
VZ
1510 if ( ::GetLastError() != 0 )
1511 {
1512 wxLogLastError(wxT("GetMenuString"));
1513 }
df61c009 1514
4e152a23
VZ
1515 continue;
1516 }
df61c009 1517
838e6ed7 1518 if ( wxStrcmp(buf, wxGetTranslation(WINDOW_MENU_LABEL)) == 0 )
4e152a23 1519 {
838e6ed7 1520 if ( !::RemoveMenu(hmenu, i, MF_BYPOSITION) )
4e152a23
VZ
1521 {
1522 wxLogLastError(wxT("RemoveMenu"));
1523 }
1524
1525 break;
1526 }
df61c009
JS
1527 }
1528 }
1529
4e152a23
VZ
1530 if ( win )
1531 {
1532 // we don't change the windows menu, but we update the main one
838e6ed7 1533 MDISetMenu(win, hmenu, NULL);
4e152a23 1534 }
df61c009
JS
1535}
1536
838e6ed7 1537void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam,
2917e920 1538 WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact)
42e69d6b 1539{
4f8090e0 1540 *activate = true;
42e69d6b
VZ
1541 *hwndAct = (WXHWND)lParam;
1542 *hwndDeact = (WXHWND)wParam;
2bda0e17 1543}
b9f933ab 1544
838e6ed7
VZ
1545} // anonymous namespace
1546
efd17a1d 1547#endif // wxUSE_MDI && !defined(__WXUNIVERSAL__)