]> git.saurik.com Git - wxWidgets.git/blame - src/msw/mdi.cpp
fixed an unused parameter warning
[wxWidgets.git] / src / msw / mdi.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
a967ef9d
VZ
2// Name: src/msw/mdi.cpp
3// Purpose: MDI classes for wxMSW
2bda0e17
KB
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
c2dcfdef 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
a23fd0e1
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
a23fd0e1 21 #pragma implementation "mdi.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
a23fd0e1 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
31#ifndef WX_PRECOMP
a23fd0e1
VZ
32 #include "wx/setup.h"
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"
7c0ea335
VZ
38 #if wxUSE_STATUSBAR
39 #include "wx/statusbr.h"
40 #endif
a23fd0e1 41 #include "wx/settings.h"
0c589ad0
BM
42 #include "wx/intl.h"
43 #include "wx/log.h"
2bda0e17
KB
44#endif
45
b9f933ab
JS
46#if wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__)
47
2bda0e17
KB
48#include "wx/mdi.h"
49#include "wx/msw/private.h"
50
7c0ea335 51#if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
3096bd2f 52 #include "wx/msw/statbr95.h"
2bda0e17
KB
53#endif
54
7c0ea335
VZ
55#if wxUSE_TOOLBAR
56 #include "wx/toolbar.h"
57#endif // wxUSE_TOOLBAR
58
2bda0e17
KB
59#include <string.h>
60
a23fd0e1
VZ
61// ---------------------------------------------------------------------------
62// global variables
63// ---------------------------------------------------------------------------
64
65extern wxWindowList wxModelessWindows; // from dialog.cpp
e1a6fc11 66extern wxMenu *wxCurrentPopupMenu;
2bda0e17 67
3ca6a5f0 68extern const wxChar *wxMDIFrameClassName; // from app.cpp
2ffa221c 69extern const wxChar *wxMDIChildFrameClassName;
3ca6a5f0
BP
70extern const wxChar *wxMDIChildFrameClassNameNoRedraw;
71
c7527e3f 72extern void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win);
ac6482e0 73extern void wxRemoveHandleAssociation(wxWindow *win);
a23fd0e1 74
42e69d6b
VZ
75static HWND invalidHandle = 0;
76
a23fd0e1
VZ
77// ---------------------------------------------------------------------------
78// constants
79// ---------------------------------------------------------------------------
80
81static const int IDM_WINDOWTILE = 4001;
42e69d6b 82static const int IDM_WINDOWTILEHOR = 4001;
a23fd0e1
VZ
83static const int IDM_WINDOWCASCADE = 4002;
84static const int IDM_WINDOWICONS = 4003;
85static const int IDM_WINDOWNEXT = 4004;
42e69d6b 86static const int IDM_WINDOWTILEVERT = 4005;
4f3b37fd 87static const int IDM_WINDOWPREV = 4006;
a23fd0e1
VZ
88
89// This range gives a maximum of 500 MDI children. Should be enough :-)
90static const int wxFIRST_MDI_CHILD = 4100;
91static const int wxLAST_MDI_CHILD = 4600;
2bda0e17
KB
92
93// Status border dimensions
a23fd0e1
VZ
94static const int wxTHICK_LINE_BORDER = 3;
95static const int wxTHICK_LINE_WIDTH = 1;
2bda0e17 96
42e69d6b
VZ
97// ---------------------------------------------------------------------------
98// private functions
99// ---------------------------------------------------------------------------
100
101// set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
102// of the parent of win (which is supposed to be the MDI client window)
103static void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow);
104
105// insert the window menu (subMenu) into menu just before "Help" submenu or at
106// the very end if not found
107static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu);
108
df61c009
JS
109// Remove the window menu
110static void RemoveWindowMenu(wxWindow *win, WXHMENU menu);
111
42e69d6b
VZ
112// is this an id of an MDI child?
113inline bool IsMdiCommandId(int id)
114{
115 return (id >= wxFIRST_MDI_CHILD) && (id <= wxLAST_MDI_CHILD);
116}
117
4e152a23 118// unpack the parameters of WM_MDIACTIVATE message
2917e920
BM
119static void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam,
120 WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact);
42e69d6b 121
4e152a23
VZ
122// return the HMENU of the MDI menu
123static inline HMENU GetMDIWindowMenu(wxMDIParentFrame *frame)
124{
125 wxMenu *menu = frame->GetWindowMenu();
126 return menu ? GetHmenuOf(menu) : 0;
127}
128
a23fd0e1
VZ
129// ===========================================================================
130// implementation
131// ===========================================================================
132
133// ---------------------------------------------------------------------------
134// wxWin macros
135// ---------------------------------------------------------------------------
2bda0e17 136
225fe9d6
VZ
137IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
138IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
139IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
2bda0e17
KB
140
141BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
a23fd0e1 142 EVT_SIZE(wxMDIParentFrame::OnSize)
a23fd0e1 143 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
2bda0e17
KB
144END_EVENT_TABLE()
145
f6bcfd97
BP
146BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame)
147 EVT_IDLE(wxMDIChildFrame::OnIdle)
148END_EVENT_TABLE()
149
2bda0e17 150BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
a23fd0e1 151 EVT_SCROLL(wxMDIClientWindow::OnScroll)
2bda0e17
KB
152END_EVENT_TABLE()
153
42e69d6b
VZ
154// ===========================================================================
155// wxMDIParentFrame: the frame which contains the client window which manages
156// the children
157// ===========================================================================
2bda0e17 158
c2dcfdef 159wxMDIParentFrame::wxMDIParentFrame()
2bda0e17
KB
160{
161 m_clientWindow = NULL;
162 m_currentChild = NULL;
df61c009 163 m_windowMenu = (wxMenu*) NULL;
2bda0e17 164 m_parentFrameActive = TRUE;
2bda0e17
KB
165}
166
167bool wxMDIParentFrame::Create(wxWindow *parent,
a23fd0e1
VZ
168 wxWindowID id,
169 const wxString& title,
170 const wxPoint& pos,
171 const wxSize& size,
172 long style,
173 const wxString& name)
2bda0e17 174{
2bda0e17
KB
175 m_clientWindow = NULL;
176 m_currentChild = NULL;
df61c009 177
3d8dea7e
VZ
178 // this style can be used to prevent a window from having the standard MDI
179 // "Window" menu
180 if ( style & wxFRAME_NO_WINDOW_MENU )
181 {
182 m_windowMenu = (wxMenu *)NULL;
183 }
184 else // normal case: we have the window menu, so construct it
df61c009 185 {
df61c009
JS
186 m_windowMenu = new wxMenu;
187
b0a2157c
VZ
188 m_windowMenu->Append(IDM_WINDOWCASCADE, _("&Cascade"));
189 m_windowMenu->Append(IDM_WINDOWTILEHOR, _("Tile &Horizontally"));
190 m_windowMenu->Append(IDM_WINDOWTILEVERT, _("Tile &Vertically"));
df61c009 191 m_windowMenu->AppendSeparator();
b0a2157c
VZ
192 m_windowMenu->Append(IDM_WINDOWICONS, _("&Arrange Icons"));
193 m_windowMenu->Append(IDM_WINDOWNEXT, _("&Next"));
4f3b37fd 194 m_windowMenu->Append(IDM_WINDOWPREV, _("&Previous"));
df61c009
JS
195 }
196
2bda0e17
KB
197 m_parentFrameActive = TRUE;
198
199 if (!parent)
200 wxTopLevelWindows.Append(this);
201
202 SetName(name);
203 m_windowStyle = style;
204
b225f659
VZ
205 if ( parent )
206 parent->AddChild(this);
2bda0e17
KB
207
208 if ( id > -1 )
209 m_windowId = id;
210 else
b225f659 211 m_windowId = NewControlId();
2bda0e17 212
912c192f
VZ
213 WXDWORD exflags;
214 WXDWORD msflags = MSWGetCreateWindowFlags(&exflags);
2bda0e17 215
b225f659 216 if ( !wxWindow::MSWCreate(wxMDIFrameClassName,
3ca6a5f0 217 title,
b225f659
VZ
218 pos, size,
219 msflags,
220 exflags) )
3ca6a5f0
BP
221 {
222 return FALSE;
223 }
2bda0e17
KB
224
225 wxModelessWindows.Append(this);
226
f6bcfd97
BP
227 // unlike (almost?) all other windows, frames are created hidden
228 m_isShown = FALSE;
229
2bda0e17
KB
230 return TRUE;
231}
232
c2dcfdef 233wxMDIParentFrame::~wxMDIParentFrame()
2bda0e17 234{
42e69d6b 235 DestroyChildren();
4e152a23 236
f048e32f
VZ
237 // already delete by DestroyChildren()
238 m_frameToolBar = NULL;
c0bcc480 239 m_frameStatusBar = NULL;
f048e32f 240
df61c009
JS
241 if (m_windowMenu)
242 {
243 delete m_windowMenu;
244 m_windowMenu = (wxMenu*) NULL;
245 }
2bda0e17 246
4e152a23
VZ
247 // the MDI frame menubar is not automatically deleted by Windows unlike for
248 // the normal frames
249 if ( m_hMenu )
250 {
251 ::DestroyMenu((HMENU)m_hMenu);
7c46a16b 252 m_hMenu = (WXHMENU)NULL;
4e152a23
VZ
253 }
254
42e69d6b
VZ
255 if ( m_clientWindow )
256 {
257 if ( m_clientWindow->MSWGetOldWndProc() )
258 m_clientWindow->UnsubclassWin();
2bda0e17 259
42e69d6b
VZ
260 m_clientWindow->SetHWND(0);
261 delete m_clientWindow;
262 }
2bda0e17
KB
263}
264
1e6feb95
VZ
265#if wxUSE_MENUS_NATIVE
266
42e69d6b 267void wxMDIParentFrame::InternalSetMenuBar()
2bda0e17 268{
42e69d6b 269 m_parentFrameActive = TRUE;
2bda0e17 270
4e152a23 271 InsertWindowMenu(GetClientWindow(), m_hMenu, GetMDIWindowMenu(this));
2bda0e17
KB
272}
273
1e6feb95
VZ
274#endif // wxUSE_MENUS_NATIVE
275
df61c009
JS
276void wxMDIParentFrame::SetWindowMenu(wxMenu* menu)
277{
278 if (m_windowMenu)
279 {
280 if (GetMenuBar())
281 {
282 // Remove old window menu
283 RemoveWindowMenu(GetClientWindow(), m_hMenu);
284 }
285
286 delete m_windowMenu;
287 m_windowMenu = (wxMenu*) NULL;
288 }
4e152a23 289
df61c009
JS
290 if (menu)
291 {
292 m_windowMenu = menu;
293 if (GetMenuBar())
b0a2157c
VZ
294 {
295 InsertWindowMenu(GetClientWindow(), m_hMenu,
88c49a0f 296 GetHmenuOf(m_windowMenu));
b0a2157c 297 }
df61c009
JS
298 }
299}
300
a967ef9d 301void wxMDIParentFrame::OnSize(wxSizeEvent&)
2bda0e17 302{
2bda0e17 303 if ( GetClientWindow() )
42e69d6b
VZ
304 {
305 int width, height;
306 GetClientSize(&width, &height);
2bda0e17 307
42e69d6b
VZ
308 GetClientWindow()->SetSize(0, 0, width, height);
309 }
2bda0e17
KB
310}
311
2bda0e17 312// Returns the active MDI child window
c2dcfdef 313wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const
2bda0e17 314{
a23fd0e1
VZ
315 HWND hWnd = (HWND)::SendMessage(GetWinHwnd(GetClientWindow()),
316 WM_MDIGETACTIVE, 0, 0L);
317 if ( hWnd == 0 )
318 return NULL;
319 else
320 return (wxMDIChildFrame *)wxFindWinFromHandle((WXHWND) hWnd);
2bda0e17
KB
321}
322
a23fd0e1
VZ
323// Create the client window class (don't Create the window, just return a new
324// class)
c2dcfdef 325wxMDIClientWindow *wxMDIParentFrame::OnCreateClient()
2bda0e17 326{
a23fd0e1 327 return new wxMDIClientWindow;
2bda0e17
KB
328}
329
330// Responds to colour changes, and passes event on to children.
331void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
332{
333 if ( m_clientWindow )
334 {
a756f210 335 m_clientWindow->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
2bda0e17
KB
336 m_clientWindow->Refresh();
337 }
2bda0e17 338
42e69d6b 339 event.Skip();
2bda0e17
KB
340}
341
82c9f85c
VZ
342WXHICON wxMDIParentFrame::GetDefaultIcon() const
343{
344 return (WXHICON)(wxSTD_MDIPARENTFRAME_ICON ? wxSTD_MDIPARENTFRAME_ICON
345 : wxDEFAULT_MDIPARENTFRAME_ICON);
346}
347
42e69d6b 348// ---------------------------------------------------------------------------
2bda0e17 349// MDI operations
42e69d6b
VZ
350// ---------------------------------------------------------------------------
351
c2dcfdef 352void wxMDIParentFrame::Cascade()
2bda0e17 353{
a23fd0e1 354 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE, 0, 0);
2bda0e17
KB
355}
356
42e69d6b 357// TODO: add a direction argument (hor/vert)
c2dcfdef 358void wxMDIParentFrame::Tile()
2bda0e17 359{
a23fd0e1 360 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE, MDITILE_HORIZONTAL, 0);
2bda0e17
KB
361}
362
c2dcfdef 363void wxMDIParentFrame::ArrangeIcons()
2bda0e17 364{
a23fd0e1 365 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE, 0, 0);
2bda0e17
KB
366}
367
c2dcfdef 368void wxMDIParentFrame::ActivateNext()
2bda0e17 369{
a23fd0e1 370 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 0);
2bda0e17
KB
371}
372
c2dcfdef 373void wxMDIParentFrame::ActivatePrevious()
2bda0e17 374{
a23fd0e1 375 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 1);
2bda0e17
KB
376}
377
42e69d6b 378// ---------------------------------------------------------------------------
a23fd0e1 379// the MDI parent frame window proc
42e69d6b
VZ
380// ---------------------------------------------------------------------------
381
a23fd0e1
VZ
382long wxMDIParentFrame::MSWWindowProc(WXUINT message,
383 WXWPARAM wParam,
384 WXLPARAM lParam)
2bda0e17 385{
a23fd0e1
VZ
386 long rc = 0;
387 bool processed = FALSE;
2bda0e17 388
a23fd0e1
VZ
389 switch ( message )
390 {
42e69d6b
VZ
391 case WM_ACTIVATE:
392 {
393 WXWORD state, minimized;
394 WXHWND hwnd;
395 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
396
397 processed = HandleActivate(state, minimized != 0, hwnd);
398 }
399 break;
400
401 case WM_COMMAND:
402 {
403 WXWORD id, cmd;
404 WXHWND hwnd;
405 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
406
407 (void)HandleCommand(id, cmd, hwnd);
408
409 // even if the frame didn't process it, there is no need to try it
410 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
411 // so pretend we processed the message anyhow
412 processed = TRUE;
413 }
b3818fbe
VZ
414
415 // always pass this message DefFrameProc(), otherwise MDI menu
416 // commands (and sys commands - more surprizingly!) won't work
417 MSWDefWindowProc(message, wParam, lParam);
42e69d6b
VZ
418 break;
419
a23fd0e1
VZ
420 case WM_CREATE:
421 m_clientWindow = OnCreateClient();
422 // Uses own style for client style
423 if ( !m_clientWindow->CreateClient(this, GetWindowStyleFlag()) )
424 {
425 wxLogMessage(_("Failed to create MDI parent frame."));
2bda0e17 426
a23fd0e1
VZ
427 rc = -1;
428 }
2bda0e17 429
a23fd0e1
VZ
430 processed = TRUE;
431 break;
2bda0e17 432
a23fd0e1
VZ
433 case WM_ERASEBKGND:
434 processed = TRUE;
2bda0e17 435
a23fd0e1
VZ
436 // we erase background ourselves
437 rc = TRUE;
438 break;
439
440 case WM_MENUSELECT:
441 {
42e69d6b
VZ
442 WXWORD item, flags;
443 WXHMENU hmenu;
444 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
445
a23fd0e1
VZ
446 if ( m_parentFrameActive )
447 {
42e69d6b 448 processed = HandleMenuSelect(item, flags, hmenu);
a23fd0e1
VZ
449 }
450 else if (m_currentChild)
451 {
452 processed = m_currentChild->
42e69d6b 453 HandleMenuSelect(item, flags, hmenu);
a23fd0e1
VZ
454 }
455 }
456 break;
b3818fbe
VZ
457
458 case WM_SIZE:
0655ad29
VZ
459 // as we don't (usually) resize the MDI client to exactly fit the
460 // client area (we put it below the toolbar, above statusbar &c),
461 // we should not pass this one to DefFrameProc
b3818fbe 462 break;
a23fd0e1 463 }
2bda0e17 464
a23fd0e1
VZ
465 if ( !processed )
466 rc = wxFrame::MSWWindowProc(message, wParam, lParam);
2bda0e17 467
a23fd0e1 468 return rc;
2bda0e17
KB
469}
470
42e69d6b 471bool wxMDIParentFrame::HandleActivate(int state, bool minimized, WXHWND activate)
2bda0e17 472{
a23fd0e1
VZ
473 bool processed = FALSE;
474
42e69d6b 475 if ( wxWindow::HandleActivate(state, minimized, activate) )
a23fd0e1
VZ
476 {
477 // already processed
478 processed = TRUE;
479 }
2bda0e17
KB
480
481 // If this window is an MDI parent, we must also send an OnActivate message
482 // to the current child.
42e69d6b 483 if ( (m_currentChild != NULL) &&
a23fd0e1 484 ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)) )
c2dcfdef 485 {
debe6624
JS
486 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_currentChild->GetId());
487 event.SetEventObject( m_currentChild );
a23fd0e1
VZ
488 if ( m_currentChild->GetEventHandler()->ProcessEvent(event) )
489 processed = TRUE;
2bda0e17 490 }
a23fd0e1
VZ
491
492 return processed;
2bda0e17
KB
493}
494
42e69d6b 495bool wxMDIParentFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND hwnd)
2bda0e17 496{
2bda0e17 497 // In case it's e.g. a toolbar.
42e69d6b 498 if ( hwnd )
e1a6fc11 499 {
42e69d6b
VZ
500 wxWindow *win = wxFindWinFromHandle(hwnd);
501 if ( win )
502 return win->MSWCommand(cmd, id);
e1a6fc11
JS
503 }
504
42e69d6b
VZ
505 // is it one of standard MDI commands?
506 WXWPARAM wParam = 0;
4f3b37fd 507 WXLPARAM lParam = 0;
42e69d6b
VZ
508 int msg;
509 switch ( id )
2bda0e17 510 {
42e69d6b
VZ
511 case IDM_WINDOWCASCADE:
512 msg = WM_MDICASCADE;
513 wParam = MDITILE_SKIPDISABLED;
514 break;
515
516 case IDM_WINDOWTILEHOR:
517 wParam |= MDITILE_HORIZONTAL;
518 // fall through
519
520 case IDM_WINDOWTILEVERT:
521 if ( !wParam )
522 wParam = MDITILE_VERTICAL;
523 msg = WM_MDITILE;
524 wParam |= MDITILE_SKIPDISABLED;
525 break;
526
527 case IDM_WINDOWICONS:
528 msg = WM_MDIICONARRANGE;
529 break;
530
531 case IDM_WINDOWNEXT:
532 msg = WM_MDINEXT;
4f3b37fd
JS
533 lParam = 0; // next child
534 break;
535
536 case IDM_WINDOWPREV:
537 msg = WM_MDINEXT;
538 lParam = 1; // previous child
42e69d6b
VZ
539 break;
540
541 default:
542 msg = 0;
2bda0e17 543 }
c2dcfdef 544
42e69d6b 545 if ( msg )
2bda0e17 546 {
4f3b37fd 547 ::SendMessage(GetWinHwnd(GetClientWindow()), msg, wParam, lParam);
42e69d6b
VZ
548
549 return TRUE;
2bda0e17 550 }
42e69d6b
VZ
551
552 // FIXME VZ: what does this test do??
553 if (id >= 0xF000)
2bda0e17 554 {
42e69d6b 555 return FALSE; // Get WndProc to call default proc
2bda0e17 556 }
42e69d6b
VZ
557
558 if ( IsMdiCommandId(id) )
2bda0e17 559 {
42e69d6b
VZ
560 wxWindowList::Node* node = GetChildren().GetFirst();
561 while ( node )
2bda0e17 562 {
42e69d6b
VZ
563 wxWindow* child = node->GetData();
564 if ( child->GetHWND() )
2bda0e17 565 {
42e69d6b 566 long childId = wxGetWindowId(child->GetHWND());
48c12cb1 567 if (childId == (long)id)
42e69d6b
VZ
568 {
569 ::SendMessage( GetWinHwnd(GetClientWindow()),
570 WM_MDIACTIVATE,
571 (WPARAM)child->GetHWND(), 0);
572 return TRUE;
573 }
2bda0e17 574 }
42e69d6b 575 node = node->GetNext();
2bda0e17 576 }
2bda0e17 577 }
42e69d6b 578 else if ( m_parentFrameActive )
2bda0e17 579 {
42e69d6b
VZ
580 return ProcessCommand(id);
581 }
582 else if ( m_currentChild )
583 {
584 return m_currentChild->HandleCommand(id, cmd, hwnd);
585 }
586 else
587 {
588 // this shouldn't happen because it means that our messages are being
589 // lost (they're not sent to the parent frame nor to the children)
f6bcfd97 590 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
2bda0e17 591 }
2bda0e17 592
42e69d6b 593 return FALSE;
2bda0e17
KB
594}
595
42e69d6b
VZ
596long wxMDIParentFrame::MSWDefWindowProc(WXUINT message,
597 WXWPARAM wParam,
598 WXLPARAM lParam)
2bda0e17 599{
c2dcfdef
VZ
600 WXHWND clientWnd;
601 if ( GetClientWindow() )
602 clientWnd = GetClientWindow()->GetHWND();
603 else
604 clientWnd = 0;
2bda0e17 605
a23fd0e1 606 return DefFrameProc(GetHwnd(), (HWND)clientWnd, message, wParam, lParam);
2bda0e17
KB
607}
608
57a7b7c1
JS
609bool wxMDIParentFrame::MSWTranslateMessage(WXMSG* msg)
610{
a23fd0e1 611 MSG *pMsg = (MSG *)msg;
2bda0e17 612
f6bcfd97 613 // first let the current child get it
a23fd0e1
VZ
614 if ( m_currentChild && m_currentChild->GetHWND() &&
615 m_currentChild->MSWTranslateMessage(msg) )
616 {
617 return TRUE;
618 }
2bda0e17 619
f6bcfd97
BP
620 // then try out accel table (will also check the menu accels)
621 if ( wxFrame::MSWTranslateMessage(msg) )
a23fd0e1
VZ
622 {
623 return TRUE;
624 }
2bda0e17 625
f6bcfd97 626 // finally, check for MDI specific built in accel keys
a23fd0e1
VZ
627 if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN )
628 {
629 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg))
630 return TRUE;
631 }
57a7b7c1 632
a23fd0e1 633 return FALSE;
2bda0e17
KB
634}
635
42e69d6b 636// ===========================================================================
a23fd0e1 637// wxMDIChildFrame
42e69d6b 638// ===========================================================================
2bda0e17 639
f6bcfd97 640void wxMDIChildFrame::Init()
2bda0e17 641{
f6bcfd97 642 m_needsResize = TRUE;
2bda0e17
KB
643}
644
645bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
a23fd0e1
VZ
646 wxWindowID id,
647 const wxString& title,
648 const wxPoint& pos,
649 const wxSize& size,
650 long style,
651 const wxString& name)
2bda0e17 652{
2bda0e17 653 SetName(name);
e949bf13 654 wxWindowBase::Show(TRUE); // MDI child frame starts off shown
2bda0e17
KB
655
656 if ( id > -1 )
657 m_windowId = id;
658 else
659 m_windowId = (int)NewControlId();
660
42e69d6b
VZ
661 if ( parent )
662 {
663 parent->AddChild(this);
664 }
2bda0e17 665
2bda0e17
KB
666 int x = pos.x;
667 int y = pos.y;
668 int width = size.x;
669 int height = size.y;
670
671 MDICREATESTRUCT mcs;
c2dcfdef 672
3ca6a5f0
BP
673 mcs.szClass = style & wxNO_FULL_REPAINT_ON_RESIZE
674 ? wxMDIChildFrameClassNameNoRedraw
675 : wxMDIChildFrameClassName;
2bda0e17
KB
676 mcs.szTitle = title;
677 mcs.hOwner = wxGetInstance();
42e69d6b
VZ
678 if (x > -1)
679 mcs.x = x;
680 else
681 mcs.x = CW_USEDEFAULT;
2bda0e17 682
42e69d6b
VZ
683 if (y > -1)
684 mcs.y = y;
685 else
686 mcs.y = CW_USEDEFAULT;
2bda0e17 687
42e69d6b
VZ
688 if (width > -1)
689 mcs.cx = width;
690 else
691 mcs.cx = CW_USEDEFAULT;
2bda0e17 692
42e69d6b
VZ
693 if (height > -1)
694 mcs.cy = height;
695 else
696 mcs.cy = CW_USEDEFAULT;
2bda0e17 697
5c44cd05 698 DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN | WS_THICKFRAME | WS_VISIBLE ;
2bda0e17
KB
699 if (style & wxMINIMIZE_BOX)
700 msflags |= WS_MINIMIZEBOX;
701 if (style & wxMAXIMIZE_BOX)
702 msflags |= WS_MAXIMIZEBOX;
703 if (style & wxTHICK_FRAME)
704 msflags |= WS_THICKFRAME;
705 if (style & wxSYSTEM_MENU)
706 msflags |= WS_SYSMENU;
707 if ((style & wxMINIMIZE) || (style & wxICONIZE))
708 msflags |= WS_MINIMIZE;
709 if (style & wxMAXIMIZE)
710 msflags |= WS_MAXIMIZE;
711 if (style & wxCAPTION)
712 msflags |= WS_CAPTION;
713
714 mcs.style = msflags;
715
716 mcs.lParam = 0;
717
b225f659
VZ
718 wxWindowCreationHook hook(this);
719
3ca6a5f0
BP
720 m_hWnd = (WXHWND)::SendMessage(GetWinHwnd(parent->GetClientWindow()),
721 WM_MDICREATE, 0, (LONG)(LPSTR)&mcs);
2bda0e17 722
c7527e3f 723 wxAssociateWinWithHandle((HWND) GetHWND(), this);
2bda0e17 724
2bda0e17 725 wxModelessWindows.Append(this);
921a43c1 726
2bda0e17
KB
727 return TRUE;
728}
729
c2dcfdef 730wxMDIChildFrame::~wxMDIChildFrame()
2bda0e17 731{
627a3091
JS
732 DestroyChildren();
733
4e152a23 734 // already deleted by DestroyChildren()
627a3091
JS
735 m_frameToolBar = NULL;
736 m_frameStatusBar = NULL;
737
4e152a23
VZ
738 RemoveWindowMenu(NULL, m_hMenu);
739
c2dcfdef 740 MSWDestroyWindow();
2bda0e17
KB
741}
742
743// Set the client size (i.e. leave the calculation of borders etc.
744// to wxWindows)
cc2b7472 745void wxMDIChildFrame::DoSetClientSize(int width, int height)
2bda0e17 746{
b3818fbe 747 HWND hWnd = GetHwnd();
2bda0e17
KB
748
749 RECT rect;
2de8030d 750 ::GetClientRect(hWnd, &rect);
2bda0e17
KB
751
752 RECT rect2;
753 GetWindowRect(hWnd, &rect2);
754
755 // Find the difference between the entire window (title bar and all)
756 // and the client area; add this to the new client size to move the
757 // window
758 int actual_width = rect2.right - rect2.left - rect.right + width;
759 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
760
a2327a9f 761 if (GetStatusBar() && GetStatusBar()->IsShown())
2bda0e17 762 {
c2dcfdef
VZ
763 int sx, sy;
764 GetStatusBar()->GetSize(&sx, &sy);
2bda0e17
KB
765 actual_height += sy;
766 }
767
768 POINT point;
769 point.x = rect2.left;
770 point.y = rect2.top;
771
772 // If there's an MDI parent, must subtract the parent's top left corner
773 // since MoveWindow moves relative to the parent
774 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
775 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
776
777 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
debe6624 778
2bda0e17 779 wxSizeEvent event(wxSize(width, height), m_windowId);
debe6624 780 event.SetEventObject( this );
2bda0e17 781 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
782}
783
cc2b7472 784void wxMDIChildFrame::DoGetPosition(int *x, int *y) const
2bda0e17
KB
785{
786 RECT rect;
b3818fbe 787 GetWindowRect(GetHwnd(), &rect);
2bda0e17
KB
788 POINT point;
789 point.x = rect.left;
790 point.y = rect.top;
791
792 // Since we now have the absolute screen coords,
793 // if there's a parent we must subtract its top left corner
794 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
795 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
796
797 *x = point.x;
798 *y = point.y;
799}
800
42e69d6b 801void wxMDIChildFrame::InternalSetMenuBar()
2bda0e17 802{
42e69d6b 803 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
2bda0e17 804
4e152a23
VZ
805 InsertWindowMenu(parent->GetClientWindow(),
806 m_hMenu, GetMDIWindowMenu(parent));
2bda0e17 807
42e69d6b 808 parent->m_parentFrameActive = FALSE;
2bda0e17
KB
809}
810
82c9f85c
VZ
811WXHICON wxMDIChildFrame::GetDefaultIcon() const
812{
813 return (WXHICON)(wxSTD_MDICHILDFRAME_ICON ? wxSTD_MDICHILDFRAME_ICON
814 : wxDEFAULT_MDICHILDFRAME_ICON);
815}
816
42e69d6b 817// ---------------------------------------------------------------------------
2bda0e17 818// MDI operations
42e69d6b
VZ
819// ---------------------------------------------------------------------------
820
9b73db3c 821void wxMDIChildFrame::Maximize(bool maximize)
2bda0e17
KB
822{
823 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
824 if ( parent && parent->GetClientWindow() )
9b73db3c
VZ
825 {
826 ::SendMessage(GetWinHwnd(parent->GetClientWindow()),
827 maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE,
828 (WPARAM)GetHwnd(), 0);
829 }
2bda0e17
KB
830}
831
c2dcfdef 832void wxMDIChildFrame::Restore()
2bda0e17
KB
833{
834 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
835 if ( parent && parent->GetClientWindow() )
9b73db3c
VZ
836 {
837 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE,
838 (WPARAM) GetHwnd(), 0);
839 }
2bda0e17
KB
840}
841
c2dcfdef 842void wxMDIChildFrame::Activate()
2bda0e17
KB
843{
844 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
845 if ( parent && parent->GetClientWindow() )
9b73db3c
VZ
846 {
847 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE,
848 (WPARAM) GetHwnd(), 0);
849 }
2bda0e17
KB
850}
851
42e69d6b
VZ
852// ---------------------------------------------------------------------------
853// MDI window proc and message handlers
854// ---------------------------------------------------------------------------
855
856long wxMDIChildFrame::MSWWindowProc(WXUINT message,
857 WXWPARAM wParam,
858 WXLPARAM lParam)
859{
860 long rc = 0;
861 bool processed = FALSE;
862
863 switch ( message )
864 {
865 case WM_COMMAND:
866 {
867 WORD id, cmd;
868 WXHWND hwnd;
869 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
870 &id, &hwnd, &cmd);
871
872 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
873 }
874 break;
875
42e69d6b 876 case WM_GETMINMAXINFO:
3ebcfb76
VZ
877 processed = HandleGetMinMaxInfo((MINMAXINFO *)lParam);
878 break;
42e69d6b
VZ
879
880 case WM_MDIACTIVATE:
881 {
882 WXWORD act;
883 WXHWND hwndAct, hwndDeact;
884 UnpackMDIActivate(wParam, lParam, &act, &hwndAct, &hwndDeact);
885
886 processed = HandleMDIActivate(act, hwndAct, hwndDeact);
887 }
b3818fbe
VZ
888 // fall through
889
890 case WM_MOVE:
891 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
892 // scrollbars if necessary
893
894 // fall through
895
896 case WM_SIZE:
897 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
898 // things happen
899 MSWDefWindowProc(message, wParam, lParam);
42e69d6b
VZ
900 break;
901
b3818fbe
VZ
902 case WM_SYSCOMMAND:
903 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
904 // the message (the base class version does not)
905 return MSWDefWindowProc(message, wParam, lParam);
906
42e69d6b
VZ
907 case WM_WINDOWPOSCHANGING:
908 processed = HandleWindowPosChanging((LPWINDOWPOS)lParam);
909 break;
910 }
911
912 if ( !processed )
913 rc = wxFrame::MSWWindowProc(message, wParam, lParam);
914
915 return rc;
916}
917
42e69d6b 918bool wxMDIChildFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND hwnd)
2bda0e17 919{
2bda0e17 920 // In case it's e.g. a toolbar.
42e69d6b
VZ
921 if ( hwnd )
922 {
923 wxWindow *win = wxFindWinFromHandle(hwnd);
924 if (win)
925 return win->MSWCommand(cmd, id);
926 }
2bda0e17 927
e1a6fc11
JS
928 if (wxCurrentPopupMenu)
929 {
930 wxMenu *popupMenu = wxCurrentPopupMenu;
931 wxCurrentPopupMenu = NULL;
932 if (popupMenu->MSWCommand(cmd, id))
933 return TRUE;
934 }
935
3ca6a5f0 936 bool processed;
dd60b9ec 937 if (GetMenuBar() && GetMenuBar()->FindItem(id))
2bda0e17 938 {
3ca6a5f0 939 processed = ProcessCommand(id);
2bda0e17
KB
940 }
941 else
3ca6a5f0
BP
942 {
943 processed = FALSE;
944 }
42e69d6b 945
3ca6a5f0 946 return processed;
2bda0e17
KB
947}
948
42e69d6b
VZ
949bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate),
950 WXHWND hwndAct,
951 WXHWND hwndDeact)
2bda0e17 952{
42e69d6b 953 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
2bda0e17 954
42e69d6b 955 HMENU menuToSet = 0;
57a7b7c1 956
42e69d6b 957 bool activated;
57a7b7c1 958
42e69d6b
VZ
959 if ( m_hWnd == hwndAct )
960 {
961 activated = TRUE;
962 parent->m_currentChild = this;
2bda0e17 963
42e69d6b
VZ
964 HMENU child_menu = (HMENU)GetWinMenu();
965 if ( child_menu )
966 {
967 parent->m_parentFrameActive = FALSE;
2bda0e17 968
42e69d6b
VZ
969 menuToSet = child_menu;
970 }
971 }
972 else if ( m_hWnd == hwndDeact )
2bda0e17 973 {
42e69d6b 974 wxASSERT_MSG( parent->m_currentChild == this,
223d09f6 975 wxT("can't deactivate MDI child which wasn't active!") );
42e69d6b
VZ
976
977 activated = FALSE;
978 parent->m_currentChild = NULL;
2bda0e17 979
42e69d6b 980 HMENU parent_menu = (HMENU)parent->GetWinMenu();
f4075804
VZ
981
982 // activate the the parent menu only when there is no other child
983 // that has been activated
984 if ( parent_menu && !hwndAct )
42e69d6b
VZ
985 {
986 parent->m_parentFrameActive = TRUE;
987
988 menuToSet = parent_menu;
989 }
990 }
991 else
992 {
18d2e170 993 // we have nothing to do with it
42e69d6b 994 return FALSE;
2bda0e17 995 }
debe6624 996
42e69d6b
VZ
997 if ( menuToSet )
998 {
4e152a23
VZ
999 MDISetMenu(parent->GetClientWindow(),
1000 menuToSet, GetMDIWindowMenu(parent));
42e69d6b
VZ
1001 }
1002
1003 wxActivateEvent event(wxEVT_ACTIVATE, activated, m_windowId);
debe6624 1004 event.SetEventObject( this );
2bda0e17 1005
c03b48d7
GT
1006 ResetWindowStyle((void *)NULL);
1007
42e69d6b
VZ
1008 return GetEventHandler()->ProcessEvent(event);
1009}
1010
1011bool wxMDIChildFrame::HandleWindowPosChanging(void *pos)
1012{
1013 WINDOWPOS *lpPos = (WINDOWPOS *)pos;
1014#if defined(__WIN95__)
1015 if (!(lpPos->flags & SWP_NOSIZE))
2bda0e17 1016 {
42e69d6b 1017 RECT rectClient;
b3818fbe
VZ
1018 DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
1019 DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
42e69d6b
VZ
1020 if (ResetWindowStyle((void *) & rectClient) && (dwStyle & WS_MAXIMIZE))
1021 {
1022 ::AdjustWindowRectEx(&rectClient, dwStyle, FALSE, dwExStyle);
1023 lpPos->x = rectClient.left;
1024 lpPos->y = rectClient.top;
1025 lpPos->cx = rectClient.right - rectClient.left;
1026 lpPos->cy = rectClient.bottom - rectClient.top;
1027 }
1028 wxMDIParentFrame* pFrameWnd = (wxMDIParentFrame *)GetParent();
a2327a9f 1029 if (pFrameWnd && pFrameWnd->GetToolBar() && pFrameWnd->GetToolBar()->IsShown())
42e69d6b
VZ
1030 {
1031 pFrameWnd->GetToolBar()->Refresh();
1032 }
1033 }
1034#endif // Win95
1035
1036 return FALSE;
1037}
1038
3ebcfb76
VZ
1039bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo)
1040{
1041 MINMAXINFO *info = (MINMAXINFO *)mmInfo;
1042
1043 // let the default window proc calculate the size of MDI children
1044 // frames because it is based on the size of the MDI client window,
1045 // not on the values specified in wxWindow m_max variables
d9f9aa2d 1046 bool processed = MSWDefWindowProc(WM_GETMINMAXINFO, 0, (LPARAM)mmInfo) != 0;
3ebcfb76 1047
e7dda1ff
VS
1048 int minWidth = GetMinWidth(),
1049 minHeight = GetMinHeight();
1050
3ebcfb76 1051 // but allow GetSizeHints() to set the min size
e7dda1ff 1052 if ( minWidth != -1 )
3ebcfb76 1053 {
e7dda1ff 1054 info->ptMinTrackSize.x = minWidth;
3ebcfb76
VZ
1055
1056 processed = TRUE;
1057 }
1058
e7dda1ff 1059 if ( minHeight != -1 )
3ebcfb76 1060 {
e7dda1ff 1061 info->ptMinTrackSize.y = minHeight;
3ebcfb76
VZ
1062
1063 processed = TRUE;
1064 }
1065
1066 return TRUE;
1067}
1068
42e69d6b
VZ
1069// ---------------------------------------------------------------------------
1070// MDI specific message translation/preprocessing
1071// ---------------------------------------------------------------------------
2bda0e17 1072
42e69d6b
VZ
1073long wxMDIChildFrame::MSWDefWindowProc(WXUINT message, WXUINT wParam, WXLPARAM lParam)
1074{
1075 return DefMDIChildProc(GetHwnd(),
1076 (UINT)message, (WPARAM)wParam, (LPARAM)lParam);
1077}
1078
1079bool wxMDIChildFrame::MSWTranslateMessage(WXMSG* msg)
1080{
5a2762f0 1081 return wxFrame::MSWTranslateMessage(msg);
2bda0e17
KB
1082}
1083
42e69d6b
VZ
1084// ---------------------------------------------------------------------------
1085// misc
1086// ---------------------------------------------------------------------------
1087
c2dcfdef 1088void wxMDIChildFrame::MSWDestroyWindow()
2bda0e17 1089{
b3818fbe 1090 invalidHandle = GetHwnd();
2bda0e17 1091
42e69d6b 1092 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
2bda0e17 1093
42e69d6b
VZ
1094 // Must make sure this handle is invalidated (set to NULL) since all sorts
1095 // of things could happen after the child client is destroyed, but before
1096 // the wxFrame is destroyed.
2bda0e17 1097
42e69d6b 1098 HWND oldHandle = (HWND)GetHWND();
b3818fbe
VZ
1099 SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIDESTROY,
1100 (WPARAM)oldHandle, 0);
18d2e170
JS
1101
1102 if (parent->GetActiveChild() == (wxMDIChildFrame*) NULL)
1103 ResetWindowStyle((void*) NULL);
1104
42e69d6b 1105 invalidHandle = 0;
2bda0e17 1106
42e69d6b
VZ
1107 if (m_hMenu)
1108 {
1109 ::DestroyMenu((HMENU) m_hMenu);
1110 m_hMenu = 0;
1111 }
ac6482e0 1112 wxRemoveHandleAssociation(this);
42e69d6b 1113 m_hWnd = 0;
2bda0e17
KB
1114}
1115
42e69d6b
VZ
1116// Change the client window's extended style so we don't get a client edge
1117// style when a child is maximised (a double border looks silly.)
2bda0e17
KB
1118bool wxMDIChildFrame::ResetWindowStyle(void *vrect)
1119{
1120#if defined(__WIN95__)
1121 RECT *rect = (RECT *)vrect;
c2dcfdef
VZ
1122 wxMDIParentFrame* pFrameWnd = (wxMDIParentFrame *)GetParent();
1123 wxMDIChildFrame* pChild = pFrameWnd->GetActiveChild();
1124 if (!pChild || (pChild == this))
1125 {
47ca6bfb 1126 HWND hwndClient = GetWinHwnd(pFrameWnd->GetClientWindow());
8082a771
VZ
1127 DWORD dwStyle = ::GetWindowLong(hwndClient, GWL_EXSTYLE);
1128
1129 // we want to test whether there is a maximized child, so just set
1130 // dwThisStyle to 0 if there is no child at all
1131 DWORD dwThisStyle = pChild
1f3943e0 1132 ? ::GetWindowLong(GetWinHwnd(pChild), GWL_STYLE) : 0;
c2dcfdef 1133 DWORD dwNewStyle = dwStyle;
8082a771 1134 if ( dwThisStyle & WS_MAXIMIZE )
c2dcfdef
VZ
1135 dwNewStyle &= ~(WS_EX_CLIENTEDGE);
1136 else
1137 dwNewStyle |= WS_EX_CLIENTEDGE;
1138
1139 if (dwStyle != dwNewStyle)
1140 {
47ca6bfb
VZ
1141 // force update of everything
1142 ::RedrawWindow(hwndClient, NULL, NULL,
1143 RDW_INVALIDATE | RDW_ALLCHILDREN);
1144 ::SetWindowLong(hwndClient, GWL_EXSTYLE, dwNewStyle);
1145 ::SetWindowPos(hwndClient, NULL, 0, 0, 0, 0,
42e69d6b
VZ
1146 SWP_FRAMECHANGED | SWP_NOACTIVATE |
1147 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
1148 SWP_NOCOPYBITS);
c2dcfdef 1149 if (rect)
47ca6bfb 1150 ::GetClientRect(hwndClient, rect);
2bda0e17 1151
42e69d6b 1152 return TRUE;
2bda0e17 1153 }
c2dcfdef 1154 }
42e69d6b 1155#endif // Win95
a23fd0e1
VZ
1156
1157 return FALSE;
2bda0e17
KB
1158}
1159
42e69d6b
VZ
1160// ===========================================================================
1161// wxMDIClientWindow: the window of predefined (by Windows) class which
1162// contains the child frames
1163// ===========================================================================
2bda0e17 1164
debe6624 1165bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
2bda0e17 1166{
a756f210 1167 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
2bda0e17 1168
42e69d6b
VZ
1169 CLIENTCREATESTRUCT ccs;
1170 m_windowStyle = style;
1171 m_parent = parent;
c2dcfdef 1172
4e152a23 1173 ccs.hWindowMenu = GetMDIWindowMenu(parent);
42e69d6b 1174 ccs.idFirstChild = wxFIRST_MDI_CHILD;
2bda0e17 1175
5c44cd05 1176 DWORD msStyle = MDIS_ALLCHILDSTYLES | WS_VISIBLE | WS_CHILD |
b0766406
JS
1177 WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
1178
42e69d6b
VZ
1179 if ( style & wxHSCROLL )
1180 msStyle |= WS_HSCROLL;
1181 if ( style & wxVSCROLL )
1182 msStyle |= WS_VSCROLL;
2bda0e17
KB
1183
1184#if defined(__WIN95__)
42e69d6b 1185 DWORD exStyle = WS_EX_CLIENTEDGE;
2bda0e17 1186#else
42e69d6b 1187 DWORD exStyle = 0;
2bda0e17
KB
1188#endif
1189
b225f659 1190 wxWindowCreationHook hook(this);
42e69d6b
VZ
1191 m_hWnd = (WXHWND)::CreateWindowEx
1192 (
1193 exStyle,
223d09f6 1194 wxT("MDICLIENT"),
42e69d6b
VZ
1195 NULL,
1196 msStyle,
1197 0, 0, 0, 0,
1198 GetWinHwnd(parent),
1199 NULL,
1200 wxGetInstance(),
1201 (LPSTR)(LPCLIENTCREATESTRUCT)&ccs);
1202 if ( !m_hWnd )
1203 {
f6bcfd97 1204 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
2bda0e17 1205
42e69d6b
VZ
1206 return FALSE;
1207 }
2bda0e17 1208
42e69d6b 1209 SubclassWin(m_hWnd);
2bda0e17 1210
42e69d6b 1211 return TRUE;
2bda0e17
KB
1212}
1213
1214// Explicitly call default scroll behaviour
1215void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
1216{
1217 // Note: for client windows, the scroll position is not set in
1218 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1219 // scroll position we're at.
1220 // This makes it hard to paint patterns or bitmaps in the background,
1221 // and have the client area scrollable as well.
1222
1223 if ( event.GetOrientation() == wxHORIZONTAL )
1224 m_scrollX = event.GetPosition(); // Always returns zero!
1225 else
1226 m_scrollY = event.GetPosition(); // Always returns zero!
1227
42e69d6b
VZ
1228 event.Skip();
1229}
1230
ec06b234
JS
1231void wxMDIClientWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1232{
1233 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1234 // client area, you can end up with a non-refreshed portion in the client window
1235 // (see OGL studio sample). So check if the position is changed and if so,
1236 // redraw the MDI child frames.
1237
1238 wxPoint oldPos = GetPosition();
1239
1240 wxWindow::DoSetSize(x, y, width, height, sizeFlags);
1241
1242 wxPoint newPos = GetPosition();
1243
1244 if ((newPos.x != oldPos.x) || (newPos.y != oldPos.y))
1245 {
1246 if (GetParent())
1247 {
1248 wxNode* node = GetParent()->GetChildren().First();
1249 while (node)
1250 {
1251 wxWindow* child = (wxWindow*) node->Data();
1252 if (child->IsKindOf(CLASSINFO(wxMDIChildFrame)))
1253 {
1254 HWND hWnd = (HWND) child->GetHWND();
1255 ::RedrawWindow(hWnd, NULL, NULL, RDW_FRAME|RDW_ALLCHILDREN|RDW_INVALIDATE );
1256 }
1257 node = node->Next();
1258 }
1259 }
1260 }
1261}
1262
f6bcfd97
BP
1263void wxMDIChildFrame::OnIdle(wxIdleEvent& event)
1264{
1265 // MDI child frames get their WM_SIZE when they're constructed but at this
1266 // moment they don't have any children yet so all child windows will be
1267 // positioned incorrectly when they are added later - to fix this, we
1268 // generate an artificial size event here
1269 if ( m_needsResize )
1270 {
1271 m_needsResize = FALSE; // avoid any possibility of recursion
1272
1273 SendSizeEvent();
1274 }
1275
1276 event.Skip();
1277}
1278
42e69d6b
VZ
1279// ---------------------------------------------------------------------------
1280// non member functions
1281// ---------------------------------------------------------------------------
1282
1283static void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow)
1284{
1285 ::SendMessage(GetWinHwnd(win), WM_MDISETMENU,
1286#ifdef __WIN32__
f6bcfd97 1287 (WPARAM)hmenuFrame, (LPARAM)hmenuWindow
42e69d6b 1288#else
f6bcfd97 1289 0, MAKELPARAM(hmenuFrame, hmenuWindow)
42e69d6b 1290#endif
f6bcfd97 1291 );
42e69d6b
VZ
1292
1293 // update menu bar of the parent window
1294 wxWindow *parent = win->GetParent();
223d09f6 1295 wxCHECK_RET( parent, wxT("MDI client without parent frame? weird...") );
42e69d6b 1296
788722ac 1297#ifndef __WIN16__
a967ef9d 1298 ::SendMessage(GetWinHwnd(win), WM_MDIREFRESHMENU, 0, 0L);
788722ac
JS
1299#endif
1300
42e69d6b
VZ
1301 ::DrawMenuBar(GetWinHwnd(parent));
1302}
1303
1304static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu)
1305{
1306 // Try to insert Window menu in front of Help, otherwise append it.
1307 HMENU hmenu = (HMENU)menu;
df61c009
JS
1308
1309 if (subMenu)
1310 {
4e152a23
VZ
1311 int N = GetMenuItemCount(hmenu);
1312 bool success = FALSE;
1313 for ( int i = 0; i < N; i++ )
42e69d6b 1314 {
4e152a23
VZ
1315 wxChar buf[256];
1316 int chars = GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION);
1317 if ( chars == 0 )
1318 {
1319 wxLogLastError(wxT("GetMenuString"));
42e69d6b 1320
4e152a23
VZ
1321 continue;
1322 }
1323
1324 if ( wxStripMenuCodes(wxString(buf)).IsSameAs(_("Help")) )
1325 {
1326 success = TRUE;
1327 ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
1328 (UINT)subMenu, _("&Window"));
1329 break;
1330 }
42e69d6b
VZ
1331 }
1332
4e152a23 1333 if ( !success )
42e69d6b 1334 {
4e152a23 1335 ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, _("&Window"));
42e69d6b
VZ
1336 }
1337 }
1338
42e69d6b
VZ
1339 MDISetMenu(win, hmenu, subMenu);
1340}
1341
df61c009
JS
1342static void RemoveWindowMenu(wxWindow *win, WXHMENU menu)
1343{
4e152a23
VZ
1344 HMENU hMenu = (HMENU)menu;
1345
1346 if ( hMenu )
df61c009 1347 {
4e152a23
VZ
1348 wxChar buf[1024];
1349
1350 int N = ::GetMenuItemCount(hMenu);
1351 for ( int i = 0; i < N; i++ )
df61c009 1352 {
4e152a23
VZ
1353 if ( !::GetMenuString(hMenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) )
1354 {
2c62b3c3
VZ
1355 // Ignore successful read of menu string with length 0 which
1356 // occurs, for example, for a maximized MDI childs system menu
1357 if ( ::GetLastError() != 0 )
1358 {
1359 wxLogLastError(wxT("GetMenuString"));
1360 }
df61c009 1361
4e152a23
VZ
1362 continue;
1363 }
df61c009 1364
4e152a23
VZ
1365 if ( wxStrcmp(buf, _("&Window")) == 0 )
1366 {
1367 if ( !::RemoveMenu(hMenu, i, MF_BYPOSITION) )
1368 {
1369 wxLogLastError(wxT("RemoveMenu"));
1370 }
1371
1372 break;
1373 }
df61c009
JS
1374 }
1375 }
1376
4e152a23
VZ
1377 if ( win )
1378 {
1379 // we don't change the windows menu, but we update the main one
1380 MDISetMenu(win, hMenu, NULL);
1381 }
df61c009
JS
1382}
1383
2917e920
BM
1384static void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam,
1385 WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact)
42e69d6b
VZ
1386{
1387#ifdef __WIN32__
1388 *activate = TRUE;
1389 *hwndAct = (WXHWND)lParam;
1390 *hwndDeact = (WXHWND)wParam;
1391#else // Win16
1392 *activate = (WXWORD)wParam;
1393 *hwndAct = (WXHWND)LOWORD(lParam);
1394 *hwndDeact = (WXHWND)HIWORD(lParam);
1395#endif // Win32/Win16
2bda0e17 1396}
b9f933ab
JS
1397
1398#endif
1399// wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__)
1400