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