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