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