+
+// ---------------------------------------------------------------------------
+// non member functions
+// ---------------------------------------------------------------------------
+
+static void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow)
+{
+ ::SendMessage(GetWinHwnd(win), WM_MDISETMENU,
+#ifdef __WIN32__
+ (WPARAM)hmenuFrame, (LPARAM)hmenuWindow
+#else
+ 0, MAKELPARAM(hmenuFrame, hmenuWindow)
+#endif
+ );
+
+ // update menu bar of the parent window
+ wxWindow *parent = win->GetParent();
+ wxCHECK_RET( parent, wxT("MDI client without parent frame? weird...") );
+
+ ::SendMessage(GetWinHwnd(win), WM_MDIREFRESHMENU, 0, 0L);
+
+ ::DrawMenuBar(GetWinHwnd(parent));
+}
+
+static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu)
+{
+ // Try to insert Window menu in front of Help, otherwise append it.
+ HMENU hmenu = (HMENU)menu;
+
+ if (subMenu)
+ {
+ int N = GetMenuItemCount(hmenu);
+ bool success = false;
+ for ( int i = 0; i < N; i++ )
+ {
+ wxChar buf[256];
+ int chars = GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION);
+ if ( chars == 0 )
+ {
+ wxLogLastError(wxT("GetMenuString"));
+
+ continue;
+ }
+
+ if ( wxStripMenuCodes(wxString(buf)).IsSameAs(_("Help")) )
+ {
+ success = true;
+ ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
+ (UINT)subMenu, _("&Window"));
+ break;
+ }
+ }
+
+ if ( !success )
+ {
+ ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, _("&Window"));
+ }
+ }
+
+ MDISetMenu(win, hmenu, subMenu);
+}
+
+static void RemoveWindowMenu(wxWindow *win, WXHMENU menu)
+{
+ HMENU hMenu = (HMENU)menu;
+
+ if ( hMenu )
+ {
+ wxChar buf[1024];
+
+ int N = ::GetMenuItemCount(hMenu);
+ for ( int i = 0; i < N; i++ )
+ {
+ if ( !::GetMenuString(hMenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) )
+ {
+ // Ignore successful read of menu string with length 0 which
+ // occurs, for example, for a maximized MDI childs system menu
+ if ( ::GetLastError() != 0 )
+ {
+ wxLogLastError(wxT("GetMenuString"));
+ }
+
+ continue;
+ }
+
+ if ( wxStrcmp(buf, _("&Window")) == 0 )
+ {
+ if ( !::RemoveMenu(hMenu, i, MF_BYPOSITION) )
+ {
+ wxLogLastError(wxT("RemoveMenu"));
+ }
+
+ break;
+ }
+ }
+ }
+
+ if ( win )
+ {
+ // we don't change the windows menu, but we update the main one
+ MDISetMenu(win, hMenu, NULL);
+ }
+}
+
+static void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam,
+ WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact)
+{
+ *activate = true;
+ *hwndAct = (WXHWND)lParam;
+ *hwndDeact = (WXHWND)wParam;
+}
+
+#endif // wxUSE_MDI && !defined(__WXUNIVERSAL__)
+