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