]> git.saurik.com Git - wxWidgets.git/blame - src/msw/mdi.cpp
Corrected wrong use of delete in region code.
[wxWidgets.git] / src / msw / mdi.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
a967ef9d
VZ
2// Name: src/msw/mdi.cpp
3// Purpose: MDI classes for wxMSW
2bda0e17
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
c7527e3f 70extern void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win);
ac6482e0 71extern void wxRemoveHandleAssociation(wxWindow *win);
a23fd0e1 72
42e69d6b
VZ
73static HWND invalidHandle = 0;
74
a23fd0e1
VZ
75// ---------------------------------------------------------------------------
76// constants
77// ---------------------------------------------------------------------------
78
79static const int IDM_WINDOWTILE = 4001;
42e69d6b 80static const int IDM_WINDOWTILEHOR = 4001;
a23fd0e1
VZ
81static const int IDM_WINDOWCASCADE = 4002;
82static const int IDM_WINDOWICONS = 4003;
83static const int IDM_WINDOWNEXT = 4004;
42e69d6b 84static const int IDM_WINDOWTILEVERT = 4005;
a23fd0e1
VZ
85
86// This range gives a maximum of 500 MDI children. Should be enough :-)
87static const int wxFIRST_MDI_CHILD = 4100;
88static const int wxLAST_MDI_CHILD = 4600;
2bda0e17
KB
89
90// Status border dimensions
a23fd0e1
VZ
91static const int wxTHICK_LINE_BORDER = 3;
92static const int wxTHICK_LINE_WIDTH = 1;
2bda0e17 93
42e69d6b
VZ
94// ---------------------------------------------------------------------------
95// private functions
96// ---------------------------------------------------------------------------
97
98// set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
99// of the parent of win (which is supposed to be the MDI client window)
100static void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow);
101
102// insert the window menu (subMenu) into menu just before "Help" submenu or at
103// the very end if not found
104static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu);
105
df61c009
JS
106// Remove the window menu
107static void RemoveWindowMenu(wxWindow *win, WXHMENU menu);
108
42e69d6b
VZ
109// is this an id of an MDI child?
110inline bool IsMdiCommandId(int id)
111{
112 return (id >= wxFIRST_MDI_CHILD) && (id <= wxLAST_MDI_CHILD);
113}
114
4e152a23 115// unpack the parameters of WM_MDIACTIVATE message
2917e920
BM
116static void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam,
117 WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact);
42e69d6b 118
4e152a23
VZ
119// return the HMENU of the MDI menu
120static inline HMENU GetMDIWindowMenu(wxMDIParentFrame *frame)
121{
122 wxMenu *menu = frame->GetWindowMenu();
123 return menu ? GetHmenuOf(menu) : 0;
124}
125
a23fd0e1
VZ
126// ===========================================================================
127// implementation
128// ===========================================================================
129
130// ---------------------------------------------------------------------------
131// wxWin macros
132// ---------------------------------------------------------------------------
2bda0e17 133
225fe9d6
VZ
134IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
135IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
136IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
2bda0e17
KB
137
138BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
a23fd0e1 139 EVT_SIZE(wxMDIParentFrame::OnSize)
a23fd0e1 140 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
2bda0e17
KB
141END_EVENT_TABLE()
142
f6bcfd97
BP
143BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame)
144 EVT_IDLE(wxMDIChildFrame::OnIdle)
145END_EVENT_TABLE()
146
2bda0e17 147BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
a23fd0e1 148 EVT_SCROLL(wxMDIClientWindow::OnScroll)
2bda0e17
KB
149END_EVENT_TABLE()
150
42e69d6b
VZ
151// ===========================================================================
152// wxMDIParentFrame: the frame which contains the client window which manages
153// the children
154// ===========================================================================
2bda0e17 155
c2dcfdef 156wxMDIParentFrame::wxMDIParentFrame()
2bda0e17
KB
157{
158 m_clientWindow = NULL;
159 m_currentChild = NULL;
df61c009 160 m_windowMenu = (wxMenu*) NULL;
2bda0e17 161 m_parentFrameActive = TRUE;
2bda0e17
KB
162}
163
164bool wxMDIParentFrame::Create(wxWindow *parent,
a23fd0e1
VZ
165 wxWindowID id,
166 const wxString& title,
167 const wxPoint& pos,
168 const wxSize& size,
169 long style,
170 const wxString& name)
2bda0e17 171{
2bda0e17
KB
172 m_clientWindow = NULL;
173 m_currentChild = NULL;
df61c009 174
3d8dea7e
VZ
175 // this style can be used to prevent a window from having the standard MDI
176 // "Window" menu
177 if ( style & wxFRAME_NO_WINDOW_MENU )
178 {
179 m_windowMenu = (wxMenu *)NULL;
180 }
181 else // normal case: we have the window menu, so construct it
df61c009 182 {
df61c009
JS
183 m_windowMenu = new wxMenu;
184
b0a2157c
VZ
185 m_windowMenu->Append(IDM_WINDOWCASCADE, _("&Cascade"));
186 m_windowMenu->Append(IDM_WINDOWTILEHOR, _("Tile &Horizontally"));
187 m_windowMenu->Append(IDM_WINDOWTILEVERT, _("Tile &Vertically"));
df61c009 188 m_windowMenu->AppendSeparator();
b0a2157c
VZ
189 m_windowMenu->Append(IDM_WINDOWICONS, _("&Arrange Icons"));
190 m_windowMenu->Append(IDM_WINDOWNEXT, _("&Next"));
df61c009
JS
191 }
192
2bda0e17
KB
193 m_parentFrameActive = TRUE;
194
195 if (!parent)
196 wxTopLevelWindows.Append(this);
197
198 SetName(name);
199 m_windowStyle = style;
200
b225f659
VZ
201 if ( parent )
202 parent->AddChild(this);
2bda0e17
KB
203
204 if ( id > -1 )
205 m_windowId = id;
206 else
b225f659 207 m_windowId = NewControlId();
2bda0e17 208
912c192f
VZ
209 WXDWORD exflags;
210 WXDWORD msflags = MSWGetCreateWindowFlags(&exflags);
2bda0e17 211
b225f659 212 if ( !wxWindow::MSWCreate(wxMDIFrameClassName,
3ca6a5f0 213 title,
b225f659
VZ
214 pos, size,
215 msflags,
216 exflags) )
3ca6a5f0
BP
217 {
218 return FALSE;
219 }
2bda0e17
KB
220
221 wxModelessWindows.Append(this);
222
f6bcfd97
BP
223 // unlike (almost?) all other windows, frames are created hidden
224 m_isShown = FALSE;
225
2bda0e17
KB
226 return TRUE;
227}
228
c2dcfdef 229wxMDIParentFrame::~wxMDIParentFrame()
2bda0e17 230{
42e69d6b 231 DestroyChildren();
4e152a23 232
f048e32f
VZ
233 // already delete by DestroyChildren()
234 m_frameToolBar = NULL;
c0bcc480 235 m_frameStatusBar = NULL;
f048e32f 236
df61c009
JS
237 if (m_windowMenu)
238 {
239 delete m_windowMenu;
240 m_windowMenu = (wxMenu*) NULL;
241 }
2bda0e17 242
4e152a23
VZ
243 // the MDI frame menubar is not automatically deleted by Windows unlike for
244 // the normal frames
245 if ( m_hMenu )
246 {
247 ::DestroyMenu((HMENU)m_hMenu);
7c46a16b 248 m_hMenu = (WXHMENU)NULL;
4e152a23
VZ
249 }
250
42e69d6b
VZ
251 if ( m_clientWindow )
252 {
253 if ( m_clientWindow->MSWGetOldWndProc() )
254 m_clientWindow->UnsubclassWin();
2bda0e17 255
42e69d6b
VZ
256 m_clientWindow->SetHWND(0);
257 delete m_clientWindow;
258 }
2bda0e17
KB
259}
260
1e6feb95
VZ
261#if wxUSE_MENUS_NATIVE
262
42e69d6b 263void wxMDIParentFrame::InternalSetMenuBar()
2bda0e17 264{
42e69d6b 265 m_parentFrameActive = TRUE;
2bda0e17 266
4e152a23 267 InsertWindowMenu(GetClientWindow(), m_hMenu, GetMDIWindowMenu(this));
2bda0e17
KB
268}
269
1e6feb95
VZ
270#endif // wxUSE_MENUS_NATIVE
271
df61c009
JS
272void wxMDIParentFrame::SetWindowMenu(wxMenu* menu)
273{
274 if (m_windowMenu)
275 {
276 if (GetMenuBar())
277 {
278 // Remove old window menu
279 RemoveWindowMenu(GetClientWindow(), m_hMenu);
280 }
281
282 delete m_windowMenu;
283 m_windowMenu = (wxMenu*) NULL;
284 }
4e152a23 285
df61c009
JS
286 if (menu)
287 {
288 m_windowMenu = menu;
289 if (GetMenuBar())
b0a2157c
VZ
290 {
291 InsertWindowMenu(GetClientWindow(), m_hMenu,
88c49a0f 292 GetHmenuOf(m_windowMenu));
b0a2157c 293 }
df61c009
JS
294 }
295}
296
a967ef9d 297void wxMDIParentFrame::OnSize(wxSizeEvent&)
2bda0e17 298{
2bda0e17 299 if ( GetClientWindow() )
42e69d6b
VZ
300 {
301 int width, height;
302 GetClientSize(&width, &height);
2bda0e17 303
42e69d6b
VZ
304 GetClientWindow()->SetSize(0, 0, width, height);
305 }
2bda0e17
KB
306}
307
2bda0e17 308// Returns the active MDI child window
c2dcfdef 309wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const
2bda0e17 310{
a23fd0e1
VZ
311 HWND hWnd = (HWND)::SendMessage(GetWinHwnd(GetClientWindow()),
312 WM_MDIGETACTIVE, 0, 0L);
313 if ( hWnd == 0 )
314 return NULL;
315 else
316 return (wxMDIChildFrame *)wxFindWinFromHandle((WXHWND) hWnd);
2bda0e17
KB
317}
318
a23fd0e1
VZ
319// Create the client window class (don't Create the window, just return a new
320// class)
c2dcfdef 321wxMDIClientWindow *wxMDIParentFrame::OnCreateClient()
2bda0e17 322{
a23fd0e1 323 return new wxMDIClientWindow;
2bda0e17
KB
324}
325
326// Responds to colour changes, and passes event on to children.
327void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
328{
329 if ( m_clientWindow )
330 {
a756f210 331 m_clientWindow->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
2bda0e17
KB
332 m_clientWindow->Refresh();
333 }
2bda0e17 334
42e69d6b 335 event.Skip();
2bda0e17
KB
336}
337
82c9f85c
VZ
338WXHICON wxMDIParentFrame::GetDefaultIcon() const
339{
340 return (WXHICON)(wxSTD_MDIPARENTFRAME_ICON ? wxSTD_MDIPARENTFRAME_ICON
341 : wxDEFAULT_MDIPARENTFRAME_ICON);
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{
2bda0e17 642 SetName(name);
e949bf13 643 wxWindowBase::Show(TRUE); // MDI child frame starts off shown
2bda0e17
KB
644
645 if ( id > -1 )
646 m_windowId = id;
647 else
648 m_windowId = (int)NewControlId();
649
42e69d6b
VZ
650 if ( parent )
651 {
652 parent->AddChild(this);
653 }
2bda0e17 654
2bda0e17
KB
655 int x = pos.x;
656 int y = pos.y;
657 int width = size.x;
658 int height = size.y;
659
660 MDICREATESTRUCT mcs;
c2dcfdef 661
3ca6a5f0
BP
662 mcs.szClass = style & wxNO_FULL_REPAINT_ON_RESIZE
663 ? wxMDIChildFrameClassNameNoRedraw
664 : wxMDIChildFrameClassName;
2bda0e17
KB
665 mcs.szTitle = title;
666 mcs.hOwner = wxGetInstance();
42e69d6b
VZ
667 if (x > -1)
668 mcs.x = x;
669 else
670 mcs.x = CW_USEDEFAULT;
2bda0e17 671
42e69d6b
VZ
672 if (y > -1)
673 mcs.y = y;
674 else
675 mcs.y = CW_USEDEFAULT;
2bda0e17 676
42e69d6b
VZ
677 if (width > -1)
678 mcs.cx = width;
679 else
680 mcs.cx = CW_USEDEFAULT;
2bda0e17 681
42e69d6b
VZ
682 if (height > -1)
683 mcs.cy = height;
684 else
685 mcs.cy = CW_USEDEFAULT;
2bda0e17 686
5c44cd05 687 DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN | WS_THICKFRAME | WS_VISIBLE ;
2bda0e17
KB
688 if (style & wxMINIMIZE_BOX)
689 msflags |= WS_MINIMIZEBOX;
690 if (style & wxMAXIMIZE_BOX)
691 msflags |= WS_MAXIMIZEBOX;
692 if (style & wxTHICK_FRAME)
693 msflags |= WS_THICKFRAME;
694 if (style & wxSYSTEM_MENU)
695 msflags |= WS_SYSMENU;
696 if ((style & wxMINIMIZE) || (style & wxICONIZE))
697 msflags |= WS_MINIMIZE;
698 if (style & wxMAXIMIZE)
699 msflags |= WS_MAXIMIZE;
700 if (style & wxCAPTION)
701 msflags |= WS_CAPTION;
702
703 mcs.style = msflags;
704
705 mcs.lParam = 0;
706
b225f659
VZ
707 wxWindowCreationHook hook(this);
708
3ca6a5f0
BP
709 m_hWnd = (WXHWND)::SendMessage(GetWinHwnd(parent->GetClientWindow()),
710 WM_MDICREATE, 0, (LONG)(LPSTR)&mcs);
2bda0e17 711
c7527e3f 712 wxAssociateWinWithHandle((HWND) GetHWND(), this);
2bda0e17 713
2bda0e17 714 wxModelessWindows.Append(this);
921a43c1 715
2bda0e17
KB
716 return TRUE;
717}
718
c2dcfdef 719wxMDIChildFrame::~wxMDIChildFrame()
2bda0e17 720{
627a3091
JS
721 DestroyChildren();
722
4e152a23 723 // already deleted by DestroyChildren()
627a3091
JS
724 m_frameToolBar = NULL;
725 m_frameStatusBar = NULL;
726
4e152a23
VZ
727 RemoveWindowMenu(NULL, m_hMenu);
728
c2dcfdef 729 MSWDestroyWindow();
2bda0e17
KB
730}
731
732// Set the client size (i.e. leave the calculation of borders etc.
733// to wxWindows)
cc2b7472 734void wxMDIChildFrame::DoSetClientSize(int width, int height)
2bda0e17 735{
b3818fbe 736 HWND hWnd = GetHwnd();
2bda0e17
KB
737
738 RECT rect;
2de8030d 739 ::GetClientRect(hWnd, &rect);
2bda0e17
KB
740
741 RECT rect2;
742 GetWindowRect(hWnd, &rect2);
743
744 // Find the difference between the entire window (title bar and all)
745 // and the client area; add this to the new client size to move the
746 // window
747 int actual_width = rect2.right - rect2.left - rect.right + width;
748 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
749
a2327a9f 750 if (GetStatusBar() && GetStatusBar()->IsShown())
2bda0e17 751 {
c2dcfdef
VZ
752 int sx, sy;
753 GetStatusBar()->GetSize(&sx, &sy);
2bda0e17
KB
754 actual_height += sy;
755 }
756
757 POINT point;
758 point.x = rect2.left;
759 point.y = rect2.top;
760
761 // If there's an MDI parent, must subtract the parent's top left corner
762 // since MoveWindow moves relative to the parent
763 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
764 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
765
766 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
debe6624 767
2bda0e17 768 wxSizeEvent event(wxSize(width, height), m_windowId);
debe6624 769 event.SetEventObject( this );
2bda0e17 770 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
771}
772
cc2b7472 773void wxMDIChildFrame::DoGetPosition(int *x, int *y) const
2bda0e17
KB
774{
775 RECT rect;
b3818fbe 776 GetWindowRect(GetHwnd(), &rect);
2bda0e17
KB
777 POINT point;
778 point.x = rect.left;
779 point.y = rect.top;
780
781 // Since we now have the absolute screen coords,
782 // if there's a parent we must subtract its top left corner
783 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
784 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
785
786 *x = point.x;
787 *y = point.y;
788}
789
42e69d6b 790void wxMDIChildFrame::InternalSetMenuBar()
2bda0e17 791{
42e69d6b 792 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
2bda0e17 793
4e152a23
VZ
794 InsertWindowMenu(parent->GetClientWindow(),
795 m_hMenu, GetMDIWindowMenu(parent));
2bda0e17 796
42e69d6b 797 parent->m_parentFrameActive = FALSE;
2bda0e17
KB
798}
799
82c9f85c
VZ
800WXHICON wxMDIChildFrame::GetDefaultIcon() const
801{
802 return (WXHICON)(wxSTD_MDICHILDFRAME_ICON ? wxSTD_MDICHILDFRAME_ICON
803 : wxDEFAULT_MDICHILDFRAME_ICON);
804}
805
42e69d6b 806// ---------------------------------------------------------------------------
2bda0e17 807// MDI operations
42e69d6b
VZ
808// ---------------------------------------------------------------------------
809
9b73db3c 810void wxMDIChildFrame::Maximize(bool maximize)
2bda0e17
KB
811{
812 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
813 if ( parent && parent->GetClientWindow() )
9b73db3c
VZ
814 {
815 ::SendMessage(GetWinHwnd(parent->GetClientWindow()),
816 maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE,
817 (WPARAM)GetHwnd(), 0);
818 }
2bda0e17
KB
819}
820
c2dcfdef 821void wxMDIChildFrame::Restore()
2bda0e17
KB
822{
823 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
824 if ( parent && parent->GetClientWindow() )
9b73db3c
VZ
825 {
826 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE,
827 (WPARAM) GetHwnd(), 0);
828 }
2bda0e17
KB
829}
830
c2dcfdef 831void wxMDIChildFrame::Activate()
2bda0e17
KB
832{
833 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
834 if ( parent && parent->GetClientWindow() )
9b73db3c
VZ
835 {
836 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE,
837 (WPARAM) GetHwnd(), 0);
838 }
2bda0e17
KB
839}
840
42e69d6b
VZ
841// ---------------------------------------------------------------------------
842// MDI window proc and message handlers
843// ---------------------------------------------------------------------------
844
845long wxMDIChildFrame::MSWWindowProc(WXUINT message,
846 WXWPARAM wParam,
847 WXLPARAM lParam)
848{
849 long rc = 0;
850 bool processed = FALSE;
851
852 switch ( message )
853 {
854 case WM_COMMAND:
855 {
856 WORD id, cmd;
857 WXHWND hwnd;
858 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
859 &id, &hwnd, &cmd);
860
861 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
862 }
863 break;
864
42e69d6b 865 case WM_GETMINMAXINFO:
3ebcfb76
VZ
866 processed = HandleGetMinMaxInfo((MINMAXINFO *)lParam);
867 break;
42e69d6b
VZ
868
869 case WM_MDIACTIVATE:
870 {
871 WXWORD act;
872 WXHWND hwndAct, hwndDeact;
873 UnpackMDIActivate(wParam, lParam, &act, &hwndAct, &hwndDeact);
874
875 processed = HandleMDIActivate(act, hwndAct, hwndDeact);
876 }
b3818fbe
VZ
877 // fall through
878
879 case WM_MOVE:
880 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
881 // scrollbars if necessary
882
883 // fall through
884
885 case WM_SIZE:
886 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
887 // things happen
888 MSWDefWindowProc(message, wParam, lParam);
42e69d6b
VZ
889 break;
890
b3818fbe
VZ
891 case WM_SYSCOMMAND:
892 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
893 // the message (the base class version does not)
894 return MSWDefWindowProc(message, wParam, lParam);
895
42e69d6b
VZ
896 case WM_WINDOWPOSCHANGING:
897 processed = HandleWindowPosChanging((LPWINDOWPOS)lParam);
898 break;
899 }
900
901 if ( !processed )
902 rc = wxFrame::MSWWindowProc(message, wParam, lParam);
903
904 return rc;
905}
906
42e69d6b 907bool wxMDIChildFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND hwnd)
2bda0e17 908{
2bda0e17 909 // In case it's e.g. a toolbar.
42e69d6b
VZ
910 if ( hwnd )
911 {
912 wxWindow *win = wxFindWinFromHandle(hwnd);
913 if (win)
914 return win->MSWCommand(cmd, id);
915 }
2bda0e17 916
e1a6fc11
JS
917 if (wxCurrentPopupMenu)
918 {
919 wxMenu *popupMenu = wxCurrentPopupMenu;
920 wxCurrentPopupMenu = NULL;
921 if (popupMenu->MSWCommand(cmd, id))
922 return TRUE;
923 }
924
3ca6a5f0 925 bool processed;
dd60b9ec 926 if (GetMenuBar() && GetMenuBar()->FindItem(id))
2bda0e17 927 {
3ca6a5f0 928 processed = ProcessCommand(id);
2bda0e17
KB
929 }
930 else
3ca6a5f0
BP
931 {
932 processed = FALSE;
933 }
42e69d6b 934
3ca6a5f0 935 return processed;
2bda0e17
KB
936}
937
42e69d6b
VZ
938bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate),
939 WXHWND hwndAct,
940 WXHWND hwndDeact)
2bda0e17 941{
42e69d6b 942 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
2bda0e17 943
42e69d6b 944 HMENU menuToSet = 0;
57a7b7c1 945
42e69d6b 946 bool activated;
57a7b7c1 947
42e69d6b
VZ
948 if ( m_hWnd == hwndAct )
949 {
950 activated = TRUE;
951 parent->m_currentChild = this;
2bda0e17 952
42e69d6b
VZ
953 HMENU child_menu = (HMENU)GetWinMenu();
954 if ( child_menu )
955 {
956 parent->m_parentFrameActive = FALSE;
2bda0e17 957
42e69d6b
VZ
958 menuToSet = child_menu;
959 }
960 }
961 else if ( m_hWnd == hwndDeact )
2bda0e17 962 {
42e69d6b 963 wxASSERT_MSG( parent->m_currentChild == this,
223d09f6 964 wxT("can't deactivate MDI child which wasn't active!") );
42e69d6b
VZ
965
966 activated = FALSE;
967 parent->m_currentChild = NULL;
2bda0e17 968
42e69d6b 969 HMENU parent_menu = (HMENU)parent->GetWinMenu();
f4075804
VZ
970
971 // activate the the parent menu only when there is no other child
972 // that has been activated
973 if ( parent_menu && !hwndAct )
42e69d6b
VZ
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 {
4e152a23
VZ
988 MDISetMenu(parent->GetClientWindow(),
989 menuToSet, GetMDIWindowMenu(parent));
42e69d6b
VZ
990 }
991
992 wxActivateEvent event(wxEVT_ACTIVATE, activated, m_windowId);
debe6624 993 event.SetEventObject( this );
2bda0e17 994
c03b48d7
GT
995 ResetWindowStyle((void *)NULL);
996
42e69d6b
VZ
997 return GetEventHandler()->ProcessEvent(event);
998}
999
1000bool wxMDIChildFrame::HandleWindowPosChanging(void *pos)
1001{
1002 WINDOWPOS *lpPos = (WINDOWPOS *)pos;
1003#if defined(__WIN95__)
1004 if (!(lpPos->flags & SWP_NOSIZE))
2bda0e17 1005 {
42e69d6b 1006 RECT rectClient;
b3818fbe
VZ
1007 DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
1008 DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
42e69d6b
VZ
1009 if (ResetWindowStyle((void *) & rectClient) && (dwStyle & WS_MAXIMIZE))
1010 {
1011 ::AdjustWindowRectEx(&rectClient, dwStyle, FALSE, dwExStyle);
1012 lpPos->x = rectClient.left;
1013 lpPos->y = rectClient.top;
1014 lpPos->cx = rectClient.right - rectClient.left;
1015 lpPos->cy = rectClient.bottom - rectClient.top;
1016 }
1017 wxMDIParentFrame* pFrameWnd = (wxMDIParentFrame *)GetParent();
a2327a9f 1018 if (pFrameWnd && pFrameWnd->GetToolBar() && pFrameWnd->GetToolBar()->IsShown())
42e69d6b
VZ
1019 {
1020 pFrameWnd->GetToolBar()->Refresh();
1021 }
1022 }
1023#endif // Win95
1024
1025 return FALSE;
1026}
1027
3ebcfb76
VZ
1028bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo)
1029{
1030 MINMAXINFO *info = (MINMAXINFO *)mmInfo;
1031
1032 // let the default window proc calculate the size of MDI children
1033 // frames because it is based on the size of the MDI client window,
1034 // not on the values specified in wxWindow m_max variables
d9f9aa2d 1035 bool processed = MSWDefWindowProc(WM_GETMINMAXINFO, 0, (LPARAM)mmInfo) != 0;
3ebcfb76 1036
e7dda1ff
VS
1037 int minWidth = GetMinWidth(),
1038 minHeight = GetMinHeight();
1039
3ebcfb76 1040 // but allow GetSizeHints() to set the min size
e7dda1ff 1041 if ( minWidth != -1 )
3ebcfb76 1042 {
e7dda1ff 1043 info->ptMinTrackSize.x = minWidth;
3ebcfb76
VZ
1044
1045 processed = TRUE;
1046 }
1047
e7dda1ff 1048 if ( minHeight != -1 )
3ebcfb76 1049 {
e7dda1ff 1050 info->ptMinTrackSize.y = minHeight;
3ebcfb76
VZ
1051
1052 processed = TRUE;
1053 }
1054
1055 return TRUE;
1056}
1057
42e69d6b
VZ
1058// ---------------------------------------------------------------------------
1059// MDI specific message translation/preprocessing
1060// ---------------------------------------------------------------------------
2bda0e17 1061
42e69d6b
VZ
1062long wxMDIChildFrame::MSWDefWindowProc(WXUINT message, WXUINT wParam, WXLPARAM lParam)
1063{
1064 return DefMDIChildProc(GetHwnd(),
1065 (UINT)message, (WPARAM)wParam, (LPARAM)lParam);
1066}
1067
1068bool wxMDIChildFrame::MSWTranslateMessage(WXMSG* msg)
1069{
5a2762f0 1070 return wxFrame::MSWTranslateMessage(msg);
2bda0e17
KB
1071}
1072
42e69d6b
VZ
1073// ---------------------------------------------------------------------------
1074// misc
1075// ---------------------------------------------------------------------------
1076
c2dcfdef 1077void wxMDIChildFrame::MSWDestroyWindow()
2bda0e17 1078{
b3818fbe 1079 invalidHandle = GetHwnd();
2bda0e17 1080
42e69d6b 1081 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
2bda0e17 1082
42e69d6b
VZ
1083 // Must make sure this handle is invalidated (set to NULL) since all sorts
1084 // of things could happen after the child client is destroyed, but before
1085 // the wxFrame is destroyed.
2bda0e17 1086
42e69d6b 1087 HWND oldHandle = (HWND)GetHWND();
b3818fbe
VZ
1088 SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIDESTROY,
1089 (WPARAM)oldHandle, 0);
18d2e170
JS
1090
1091 if (parent->GetActiveChild() == (wxMDIChildFrame*) NULL)
1092 ResetWindowStyle((void*) NULL);
1093
42e69d6b 1094 invalidHandle = 0;
2bda0e17 1095
42e69d6b
VZ
1096 if (m_hMenu)
1097 {
1098 ::DestroyMenu((HMENU) m_hMenu);
1099 m_hMenu = 0;
1100 }
ac6482e0 1101 wxRemoveHandleAssociation(this);
42e69d6b 1102 m_hWnd = 0;
2bda0e17
KB
1103}
1104
42e69d6b
VZ
1105// Change the client window's extended style so we don't get a client edge
1106// style when a child is maximised (a double border looks silly.)
2bda0e17
KB
1107bool wxMDIChildFrame::ResetWindowStyle(void *vrect)
1108{
1109#if defined(__WIN95__)
1110 RECT *rect = (RECT *)vrect;
c2dcfdef
VZ
1111 wxMDIParentFrame* pFrameWnd = (wxMDIParentFrame *)GetParent();
1112 wxMDIChildFrame* pChild = pFrameWnd->GetActiveChild();
1113 if (!pChild || (pChild == this))
1114 {
47ca6bfb 1115 HWND hwndClient = GetWinHwnd(pFrameWnd->GetClientWindow());
8082a771
VZ
1116 DWORD dwStyle = ::GetWindowLong(hwndClient, GWL_EXSTYLE);
1117
1118 // we want to test whether there is a maximized child, so just set
1119 // dwThisStyle to 0 if there is no child at all
1120 DWORD dwThisStyle = pChild
1f3943e0 1121 ? ::GetWindowLong(GetWinHwnd(pChild), GWL_STYLE) : 0;
c2dcfdef 1122 DWORD dwNewStyle = dwStyle;
8082a771 1123 if ( dwThisStyle & WS_MAXIMIZE )
c2dcfdef
VZ
1124 dwNewStyle &= ~(WS_EX_CLIENTEDGE);
1125 else
1126 dwNewStyle |= WS_EX_CLIENTEDGE;
1127
1128 if (dwStyle != dwNewStyle)
1129 {
47ca6bfb
VZ
1130 // force update of everything
1131 ::RedrawWindow(hwndClient, NULL, NULL,
1132 RDW_INVALIDATE | RDW_ALLCHILDREN);
1133 ::SetWindowLong(hwndClient, GWL_EXSTYLE, dwNewStyle);
1134 ::SetWindowPos(hwndClient, NULL, 0, 0, 0, 0,
42e69d6b
VZ
1135 SWP_FRAMECHANGED | SWP_NOACTIVATE |
1136 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
1137 SWP_NOCOPYBITS);
c2dcfdef 1138 if (rect)
47ca6bfb 1139 ::GetClientRect(hwndClient, rect);
2bda0e17 1140
42e69d6b 1141 return TRUE;
2bda0e17 1142 }
c2dcfdef 1143 }
42e69d6b 1144#endif // Win95
a23fd0e1
VZ
1145
1146 return FALSE;
2bda0e17
KB
1147}
1148
42e69d6b
VZ
1149// ===========================================================================
1150// wxMDIClientWindow: the window of predefined (by Windows) class which
1151// contains the child frames
1152// ===========================================================================
2bda0e17 1153
debe6624 1154bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
2bda0e17 1155{
a756f210 1156 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
2bda0e17 1157
42e69d6b
VZ
1158 CLIENTCREATESTRUCT ccs;
1159 m_windowStyle = style;
1160 m_parent = parent;
c2dcfdef 1161
4e152a23 1162 ccs.hWindowMenu = GetMDIWindowMenu(parent);
42e69d6b 1163 ccs.idFirstChild = wxFIRST_MDI_CHILD;
2bda0e17 1164
5c44cd05 1165 DWORD msStyle = MDIS_ALLCHILDSTYLES | WS_VISIBLE | WS_CHILD |
b0766406
JS
1166 WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
1167
42e69d6b
VZ
1168 if ( style & wxHSCROLL )
1169 msStyle |= WS_HSCROLL;
1170 if ( style & wxVSCROLL )
1171 msStyle |= WS_VSCROLL;
2bda0e17
KB
1172
1173#if defined(__WIN95__)
42e69d6b 1174 DWORD exStyle = WS_EX_CLIENTEDGE;
2bda0e17 1175#else
42e69d6b 1176 DWORD exStyle = 0;
2bda0e17
KB
1177#endif
1178
b225f659 1179 wxWindowCreationHook hook(this);
42e69d6b
VZ
1180 m_hWnd = (WXHWND)::CreateWindowEx
1181 (
1182 exStyle,
223d09f6 1183 wxT("MDICLIENT"),
42e69d6b
VZ
1184 NULL,
1185 msStyle,
1186 0, 0, 0, 0,
1187 GetWinHwnd(parent),
1188 NULL,
1189 wxGetInstance(),
1190 (LPSTR)(LPCLIENTCREATESTRUCT)&ccs);
1191 if ( !m_hWnd )
1192 {
f6bcfd97 1193 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
2bda0e17 1194
42e69d6b
VZ
1195 return FALSE;
1196 }
2bda0e17 1197
42e69d6b 1198 SubclassWin(m_hWnd);
2bda0e17 1199
42e69d6b 1200 return TRUE;
2bda0e17
KB
1201}
1202
1203// Explicitly call default scroll behaviour
1204void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
1205{
1206 // Note: for client windows, the scroll position is not set in
1207 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1208 // scroll position we're at.
1209 // This makes it hard to paint patterns or bitmaps in the background,
1210 // and have the client area scrollable as well.
1211
1212 if ( event.GetOrientation() == wxHORIZONTAL )
1213 m_scrollX = event.GetPosition(); // Always returns zero!
1214 else
1215 m_scrollY = event.GetPosition(); // Always returns zero!
1216
42e69d6b
VZ
1217 event.Skip();
1218}
1219
ec06b234
JS
1220void wxMDIClientWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1221{
1222 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1223 // client area, you can end up with a non-refreshed portion in the client window
1224 // (see OGL studio sample). So check if the position is changed and if so,
1225 // redraw the MDI child frames.
1226
1227 wxPoint oldPos = GetPosition();
1228
1229 wxWindow::DoSetSize(x, y, width, height, sizeFlags);
1230
1231 wxPoint newPos = GetPosition();
1232
1233 if ((newPos.x != oldPos.x) || (newPos.y != oldPos.y))
1234 {
1235 if (GetParent())
1236 {
1237 wxNode* node = GetParent()->GetChildren().First();
1238 while (node)
1239 {
1240 wxWindow* child = (wxWindow*) node->Data();
1241 if (child->IsKindOf(CLASSINFO(wxMDIChildFrame)))
1242 {
1243 HWND hWnd = (HWND) child->GetHWND();
1244 ::RedrawWindow(hWnd, NULL, NULL, RDW_FRAME|RDW_ALLCHILDREN|RDW_INVALIDATE );
1245 }
1246 node = node->Next();
1247 }
1248 }
1249 }
1250}
1251
f6bcfd97
BP
1252void wxMDIChildFrame::OnIdle(wxIdleEvent& event)
1253{
1254 // MDI child frames get their WM_SIZE when they're constructed but at this
1255 // moment they don't have any children yet so all child windows will be
1256 // positioned incorrectly when they are added later - to fix this, we
1257 // generate an artificial size event here
1258 if ( m_needsResize )
1259 {
1260 m_needsResize = FALSE; // avoid any possibility of recursion
1261
1262 SendSizeEvent();
1263 }
1264
1265 event.Skip();
1266}
1267
42e69d6b
VZ
1268// ---------------------------------------------------------------------------
1269// non member functions
1270// ---------------------------------------------------------------------------
1271
1272static void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow)
1273{
1274 ::SendMessage(GetWinHwnd(win), WM_MDISETMENU,
1275#ifdef __WIN32__
f6bcfd97 1276 (WPARAM)hmenuFrame, (LPARAM)hmenuWindow
42e69d6b 1277#else
f6bcfd97 1278 0, MAKELPARAM(hmenuFrame, hmenuWindow)
42e69d6b 1279#endif
f6bcfd97 1280 );
42e69d6b
VZ
1281
1282 // update menu bar of the parent window
1283 wxWindow *parent = win->GetParent();
223d09f6 1284 wxCHECK_RET( parent, wxT("MDI client without parent frame? weird...") );
42e69d6b 1285
788722ac 1286#ifndef __WIN16__
a967ef9d 1287 ::SendMessage(GetWinHwnd(win), WM_MDIREFRESHMENU, 0, 0L);
788722ac
JS
1288#endif
1289
42e69d6b
VZ
1290 ::DrawMenuBar(GetWinHwnd(parent));
1291}
1292
1293static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu)
1294{
1295 // Try to insert Window menu in front of Help, otherwise append it.
1296 HMENU hmenu = (HMENU)menu;
df61c009
JS
1297
1298 if (subMenu)
1299 {
4e152a23
VZ
1300 int N = GetMenuItemCount(hmenu);
1301 bool success = FALSE;
1302 for ( int i = 0; i < N; i++ )
42e69d6b 1303 {
4e152a23
VZ
1304 wxChar buf[256];
1305 int chars = GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION);
1306 if ( chars == 0 )
1307 {
1308 wxLogLastError(wxT("GetMenuString"));
42e69d6b 1309
4e152a23
VZ
1310 continue;
1311 }
1312
1313 if ( wxStripMenuCodes(wxString(buf)).IsSameAs(_("Help")) )
1314 {
1315 success = TRUE;
1316 ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
1317 (UINT)subMenu, _("&Window"));
1318 break;
1319 }
42e69d6b
VZ
1320 }
1321
4e152a23 1322 if ( !success )
42e69d6b 1323 {
4e152a23 1324 ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, _("&Window"));
42e69d6b
VZ
1325 }
1326 }
1327
42e69d6b
VZ
1328 MDISetMenu(win, hmenu, subMenu);
1329}
1330
df61c009
JS
1331static void RemoveWindowMenu(wxWindow *win, WXHMENU menu)
1332{
4e152a23
VZ
1333 HMENU hMenu = (HMENU)menu;
1334
1335 if ( hMenu )
df61c009 1336 {
4e152a23
VZ
1337 wxChar buf[1024];
1338
1339 int N = ::GetMenuItemCount(hMenu);
1340 for ( int i = 0; i < N; i++ )
df61c009 1341 {
4e152a23
VZ
1342 if ( !::GetMenuString(hMenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) )
1343 {
1344 wxLogLastError(wxT("GetMenuString"));
df61c009 1345
4e152a23
VZ
1346 continue;
1347 }
df61c009 1348
4e152a23
VZ
1349 if ( wxStrcmp(buf, _("&Window")) == 0 )
1350 {
1351 if ( !::RemoveMenu(hMenu, i, MF_BYPOSITION) )
1352 {
1353 wxLogLastError(wxT("RemoveMenu"));
1354 }
1355
1356 break;
1357 }
df61c009
JS
1358 }
1359 }
1360
4e152a23
VZ
1361 if ( win )
1362 {
1363 // we don't change the windows menu, but we update the main one
1364 MDISetMenu(win, hMenu, NULL);
1365 }
df61c009
JS
1366}
1367
2917e920
BM
1368static void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam,
1369 WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact)
42e69d6b
VZ
1370{
1371#ifdef __WIN32__
1372 *activate = TRUE;
1373 *hwndAct = (WXHWND)lParam;
1374 *hwndDeact = (WXHWND)wParam;
1375#else // Win16
1376 *activate = (WXWORD)wParam;
1377 *hwndAct = (WXHWND)LOWORD(lParam);
1378 *hwndDeact = (WXHWND)HIWORD(lParam);
1379#endif // Win32/Win16
2bda0e17 1380}