Merge branch 'mdi-window'

Fix handling of MDI "Window" menu under MSW when the translation of its
label changes during the program lifetime.

See https://github.com/wxWidgets/wxWidgets/pull/937
This commit is contained in:
Vadim Zeitlin
2018-09-18 14:16:04 +02:00
2 changed files with 31 additions and 15 deletions

View File

@@ -85,6 +85,13 @@ public:
virtual void RemoveMDIChild(wxMDIChildFrame *child); virtual void RemoveMDIChild(wxMDIChildFrame *child);
#endif // wxUSE_MENUS #endif // wxUSE_MENUS
// Retrieve the current window menu label: it can be different from
// "Window" when using non-English translations and can also be different
// from wxGetTranslation("Window") if the locale has changed since the
// "Window" menu was added.
const wxString& MSWGetCurrentWindowMenuLabel() const
{ return m_currentWindowMenuLabel; }
// handlers // handlers
// -------- // --------
@@ -150,6 +157,9 @@ private:
// it was "handled", see OnActivate() and HandleActivate() // it was "handled", see OnActivate() and HandleActivate()
bool m_activationNotHandled; bool m_activationNotHandled;
// holds the current translation for the window menu label
wxString m_currentWindowMenuLabel;
friend class WXDLLIMPEXP_FWD_CORE wxMDIChildFrame; friend class WXDLLIMPEXP_FWD_CORE wxMDIChildFrame;

View File

@@ -75,9 +75,6 @@ const int wxLAST_MDI_CHILD = wxFIRST_MDI_CHILD + 8;
// child. // child.
const int wxID_MDI_MORE_WINDOWS = wxLAST_MDI_CHILD + 1; const int wxID_MDI_MORE_WINDOWS = wxLAST_MDI_CHILD + 1;
// The MDI "Window" menu label
const char *WINDOW_MENU_LABEL = gettext_noop("&Window");
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// private functions // private functions
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -88,10 +85,10 @@ void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow);
// insert the window menu (subMenu) into menu just before "Help" submenu or at // insert the window menu (subMenu) into menu just before "Help" submenu or at
// the very end if not found // the very end if not found
void MDIInsertWindowMenu(wxWindow *win, WXHMENU hMenu, HMENU subMenu); void MDIInsertWindowMenu(wxWindow *win, WXHMENU hMenu, HMENU subMenu, const wxString& windowMenuLabelTranslated);
// Remove the window menu // Remove the window menu
void MDIRemoveWindowMenu(wxWindow *win, WXHMENU hMenu); void MDIRemoveWindowMenu(wxWindow *win, WXHMENU hMenu, const wxString& windowMenuLabelTranslated);
// unpack the parameters of WM_MDIACTIVATE message // unpack the parameters of WM_MDIACTIVATE message
void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam, void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam,
@@ -334,7 +331,12 @@ void wxMDIParentFrame::AddWindowMenu()
// attach it to the menu bar. // attach it to the menu bar.
m_windowMenu->Attach(GetMenuBar()); m_windowMenu->Attach(GetMenuBar());
MDIInsertWindowMenu(GetClientWindow(), m_hMenu, GetMDIWindowMenu(this)); // Store the current translation, we can't use _("Window") later in
// case the locale changes.
m_currentWindowMenuLabel = _("&Window");
MDIInsertWindowMenu(GetClientWindow(), m_hMenu, GetMDIWindowMenu(this),
m_currentWindowMenuLabel);
} }
} }
@@ -342,7 +344,8 @@ void wxMDIParentFrame::RemoveWindowMenu()
{ {
if ( m_windowMenu ) if ( m_windowMenu )
{ {
MDIRemoveWindowMenu(GetClientWindow(), m_hMenu); MDIRemoveWindowMenu(GetClientWindow(), m_hMenu,
m_currentWindowMenuLabel);
m_windowMenu->Detach(); m_windowMenu->Detach();
} }
@@ -926,7 +929,7 @@ wxMDIChildFrame::~wxMDIChildFrame()
DestroyChildren(); DestroyChildren();
MDIRemoveWindowMenu(NULL, m_hMenu); MDIRemoveWindowMenu(NULL, m_hMenu, parent->MSWGetCurrentWindowMenuLabel());
// MDIRemoveWindowMenu() doesn't update the MDI menu when called with NULL // MDIRemoveWindowMenu() doesn't update the MDI menu when called with NULL
// window, so do it ourselves. // window, so do it ourselves.
@@ -1047,12 +1050,15 @@ void wxMDIChildFrame::InternalSetMenuBar()
wxMDIParentFrame * const parent = GetMDIParent(); wxMDIParentFrame * const parent = GetMDIParent();
MDIInsertWindowMenu(parent->GetClientWindow(), MDIInsertWindowMenu(parent->GetClientWindow(),
m_hMenu, GetMDIWindowMenu(parent)); m_hMenu, GetMDIWindowMenu(parent),
parent->MSWGetCurrentWindowMenuLabel());
} }
void wxMDIChildFrame::DetachMenuBar() void wxMDIChildFrame::DetachMenuBar()
{ {
MDIRemoveWindowMenu(NULL, m_hMenu); wxMDIParentFrame * const parent = GetMDIParent();
MDIRemoveWindowMenu(NULL, m_hMenu, parent->MSWGetCurrentWindowMenuLabel());
wxFrame::DetachMenuBar(); wxFrame::DetachMenuBar();
} }
@@ -1552,7 +1558,7 @@ private:
wxDECLARE_NO_COPY_CLASS(MenuIterator); wxDECLARE_NO_COPY_CLASS(MenuIterator);
}; };
void MDIInsertWindowMenu(wxWindow *win, WXHMENU hMenu, HMENU menuWin) void MDIInsertWindowMenu(wxWindow *win, WXHMENU hMenu, HMENU menuWin, const wxString& windowMenuLabelTranslated)
{ {
HMENU hmenu = (HMENU)hMenu; HMENU hmenu = (HMENU)hMenu;
@@ -1571,7 +1577,7 @@ void MDIInsertWindowMenu(wxWindow *win, WXHMENU hMenu, HMENU menuWin)
::InsertMenu(hmenu, it.GetPos(), ::InsertMenu(hmenu, it.GetPos(),
MF_BYPOSITION | MF_POPUP | MF_STRING, MF_BYPOSITION | MF_POPUP | MF_STRING,
(UINT_PTR)menuWin, (UINT_PTR)menuWin,
wxString(wxGetTranslation(WINDOW_MENU_LABEL)).t_str()); windowMenuLabelTranslated.t_str());
break; break;
} }
} }
@@ -1580,14 +1586,14 @@ void MDIInsertWindowMenu(wxWindow *win, WXHMENU hMenu, HMENU menuWin)
{ {
::AppendMenu(hmenu, MF_POPUP, ::AppendMenu(hmenu, MF_POPUP,
(UINT_PTR)menuWin, (UINT_PTR)menuWin,
wxString(wxGetTranslation(WINDOW_MENU_LABEL)).t_str()); windowMenuLabelTranslated.t_str());
} }
} }
MDISetMenu(win, hmenu, menuWin); MDISetMenu(win, hmenu, menuWin);
} }
void MDIRemoveWindowMenu(wxWindow *win, WXHMENU hMenu) void MDIRemoveWindowMenu(wxWindow *win, WXHMENU hMenu, const wxString& windowMenuLabelTranslated)
{ {
HMENU hmenu = (HMENU)hMenu; HMENU hmenu = (HMENU)hMenu;
@@ -1597,7 +1603,7 @@ void MDIRemoveWindowMenu(wxWindow *win, WXHMENU hMenu)
MenuIterator it(hmenu); MenuIterator it(hmenu);
while ( it.GetNext(buf) ) while ( it.GetNext(buf) )
{ {
if ( wxStrcmp(buf, wxGetTranslation(WINDOW_MENU_LABEL)) == 0 ) if ( wxStrcmp(buf, windowMenuLabelTranslated) == 0 )
{ {
if ( !::RemoveMenu(hmenu, it.GetPos(), MF_BYPOSITION) ) if ( !::RemoveMenu(hmenu, it.GetPos(), MF_BYPOSITION) )
{ {