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