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