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