We don't get wxEVT_MENU_OPEN events when using the global menu bar so don't
rely on them for updating the menu items status and fall back to idle time
menu updating if the global menu bar is used.
This required changing wxUSE_IDLEMENUUPDATES tests from compile- to run-time
ones.
Closes #14302.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73009
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// frame
virtual void AttachMenuBar(wxMenuBar *menubar);
// frame
virtual void AttachMenuBar(wxMenuBar *menubar);
+ // Return true if we should update the menu item state from idle event
+ // handler or false if we should delay it until the menu is opened.
+ static bool ShouldUpdateMenuFromIdle();
+
wxMenuBar *m_frameMenuBar;
#endif // wxUSE_MENUS
wxMenuBar *m_frameMenuBar;
#endif // wxUSE_MENUS
// ----------------------------------------------------------------------------
#if wxUSE_MENUS && wxUSE_STATUSBAR
// ----------------------------------------------------------------------------
#if wxUSE_MENUS && wxUSE_STATUSBAR
BEGIN_EVENT_TABLE(wxFrameBase, wxTopLevelWindow)
EVT_MENU_OPEN(wxFrameBase::OnMenuOpen)
EVT_MENU_CLOSE(wxFrameBase::OnMenuClose)
BEGIN_EVENT_TABLE(wxFrameBase, wxTopLevelWindow)
EVT_MENU_OPEN(wxFrameBase::OnMenuOpen)
EVT_MENU_CLOSE(wxFrameBase::OnMenuClose)
EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight)
END_EVENT_TABLE()
EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight)
END_EVENT_TABLE()
-#endif // wxUSE_MENUS && wxUSE_STATUSBAR
+#endif // wxUSE_MENUS && wxUSE_IDLEMENUUPDATES
+
+/* static */
+bool wxFrameBase::ShouldUpdateMenuFromIdle()
+{
+ // Usually this is determined at compile time and is determined by whether
+ // the platform supports wxEVT_MENU_OPEN, however in wxGTK we need to also
+ // check if we're using the global menu bar as we don't get EVT_MENU_OPEN
+ // for it and need to fall back to idle time updating even if normally
+ // wxUSE_IDLEMENUUPDATES is set to 0 for wxGTK.
+#ifdef __WXGTK__
+ if ( wxApp::GTKIsUsingGlobalMenu() )
+ return true;
+#endif // !__WXGTK__
+
+ return wxUSE_IDLEMENUUPDATES != 0;
+}
// ============================================================================
// implementation
// ============================================================================
// implementation
// If coming from an idle event, we only want to update the menus if
// we're in the wxUSE_IDLEMENUUPDATES configuration, otherwise they
// will be update when the menu is opened later
// If coming from an idle event, we only want to update the menus if
// we're in the wxUSE_IDLEMENUUPDATES configuration, otherwise they
// will be update when the menu is opened later
-#if !wxUSE_IDLEMENUUPDATES
- if ( !(flags & wxUPDATE_UI_FROMIDLE) )
-#endif // wxUSE_IDLEMENUUPDATES
+ if ( !(flags & wxUPDATE_UI_FROMIDLE) || ShouldUpdateMenuFromIdle() )
DoMenuUpdates();
}
#endif // wxUSE_MENUS
DoMenuUpdates();
}
#endif // wxUSE_MENUS
void wxFrameBase::OnMenuOpen(wxMenuEvent& event)
{
void wxFrameBase::OnMenuOpen(wxMenuEvent& event)
{
-#if wxUSE_IDLEMENUUPDATES
- wxUnusedVar(event);
-#else // !wxUSE_IDLEMENUUPDATES
- // as we didn't update the menus from idle time, do it now
- DoMenuUpdates(event.GetMenu());
-#endif // wxUSE_IDLEMENUUPDATES/!wxUSE_IDLEMENUUPDATES
+ if ( !ShouldUpdateMenuFromIdle() )
+ {
+ // as we didn't update the menus from idle time, do it now
+ DoMenuUpdates(event.GetMenu());
+ }
}
void wxFrameBase::OnMenuClose(wxMenuEvent& WXUNUSED(event))
}
void wxFrameBase::OnMenuClose(wxMenuEvent& WXUNUSED(event))
{
wxTopLevelWindow::OnInternalIdle();
{
wxTopLevelWindow::OnInternalIdle();
-#if wxUSE_MENUS && wxUSE_IDLEMENUUPDATES
- if (wxUpdateUIEvent::CanUpdate(this))
+#if wxUSE_MENUS
+ if ( ShouldUpdateMenuFromIdle() && wxUpdateUIEvent::CanUpdate(this) )
DoMenuUpdates();
#endif
}
DoMenuUpdates();
#endif
}