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