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