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