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