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