diff --git a/include/wx/frame.h b/include/wx/frame.h index 5f2cac41cf..4c606c34c7 100644 --- a/include/wx/frame.h +++ b/include/wx/frame.h @@ -23,7 +23,9 @@ extern WXDLLIMPEXP_DATA_CORE(const char) wxStatusLineNameStr[]; extern WXDLLIMPEXP_DATA_CORE(const char) wxToolBarNameStr[]; class WXDLLIMPEXP_FWD_CORE wxFrame; +#if wxUSE_MENUBAR class WXDLLIMPEXP_FWD_CORE wxMenuBar; +#endif class WXDLLIMPEXP_FWD_CORE wxMenuItem; class WXDLLIMPEXP_FWD_CORE wxStatusBar; class WXDLLIMPEXP_FWD_CORE wxToolBar; @@ -78,6 +80,7 @@ public: // ------------------ #if wxUSE_MENUS +#if wxUSE_MENUBAR virtual void SetMenuBar(wxMenuBar *menubar); virtual wxMenuBar *GetMenuBar() const { return m_frameMenuBar; } @@ -85,7 +88,7 @@ public: // and exists mainly in order to be overridden in the MDI parent frame // which also looks at its active child menu bar virtual wxMenuItem *FindItemInMenuBar(int menuId) const; - +#endif // generate menu command corresponding to the given menu item // // returns true if processed @@ -192,7 +195,7 @@ protected: // test whether this window makes part of the frame virtual bool IsOneOfBars(const wxWindow *win) const wxOVERRIDE; -#if wxUSE_MENUS +#if wxUSE_MENUBAR // override to update menu bar position when the frame size changes virtual void PositionMenuBar() { } @@ -203,13 +206,15 @@ protected: // override to do something special when the menu bar is attached to the // frame virtual void AttachMenuBar(wxMenuBar *menubar); +#endif // wxUSE_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(); +#if wxUSE_MENUBAR wxMenuBar *m_frameMenuBar; -#endif // wxUSE_MENUS +#endif // wxUSE_MENUBAR #if wxUSE_STATUSBAR && (wxUSE_MENUS || wxUSE_TOOLBAR) // the saved status bar text overwritten by DoGiveHelp() diff --git a/include/wx/menu.h b/include/wx/menu.h index af9f2e7364..b0877afc98 100644 --- a/include/wx/menu.h +++ b/include/wx/menu.h @@ -282,6 +282,7 @@ public: // handler to use for these events, but this should never be needed. void UpdateUI(wxEvtHandler* source = NULL); +#if wxUSE_MENUBAR // get the menu bar this menu is attached to (may be NULL, always NULL for // popup menus). Traverse up the menu hierarchy to find it. wxMenuBar *GetMenuBar() const; @@ -292,6 +293,7 @@ public: // is the menu attached to a menu bar (or is it a popup one)? bool IsAttached() const { return GetMenuBar() != NULL; } +#endif // set/get the parent of this menu void SetParent(wxMenu *parent) { m_menuParent = parent; } @@ -443,6 +445,8 @@ WX_DECLARE_EXPORTED_LIST(wxMenuInfoHelper, wxMenuInfoHelperList ); // wxMenuBar // ---------------------------------------------------------------------------- +#if wxUSE_MENUBAR + class WXDLLIMPEXP_CORE wxMenuBarBase : public wxWindow { public: @@ -584,6 +588,7 @@ protected: wxDECLARE_NO_COPY_CLASS(wxMenuBarBase); }; +#endif // ---------------------------------------------------------------------------- // include the real class declaration diff --git a/include/wx/osx/frame.h b/include/wx/osx/frame.h index 9a493773fa..4ced3174c9 100644 --- a/include/wx/osx/frame.h +++ b/include/wx/osx/frame.h @@ -90,7 +90,7 @@ protected: virtual void DoGetClientSize(int *width, int *height) const wxOVERRIDE; virtual void DoSetClientSize(int width, int height) wxOVERRIDE; -#if wxUSE_MENUS +#if wxUSE_MENUBAR virtual void DetachMenuBar() wxOVERRIDE; virtual void AttachMenuBar(wxMenuBar *menubar) wxOVERRIDE; #endif diff --git a/include/wx/osx/iphone/chkconf.h b/include/wx/osx/iphone/chkconf.h index 116c5776c8..6fcd86b4da 100644 --- a/include/wx/osx/iphone/chkconf.h +++ b/include/wx/osx/iphone/chkconf.h @@ -255,7 +255,12 @@ #if wxUSE_MENUS #undef wxUSE_MENUS -#define wxUSE_MENUS 0 +#define wxUSE_MENUS 1 +#endif + +#if wxUSE_MENUBAR +#undef wxUSE_MENUBAR +#define wxUSE_MENUBAR 0 #endif /* diff --git a/include/wx/osx/menu.h b/include/wx/osx/menu.h index 279c5b5888..f503a86011 100644 --- a/include/wx/osx/menu.h +++ b/include/wx/osx/menu.h @@ -102,7 +102,7 @@ private: wxDECLARE_DYNAMIC_CLASS(wxMenu); }; -#if wxOSX_USE_COCOA_OR_CARBON +#if wxUSE_MENUBAR // the iphone only has popup-menus diff --git a/src/common/framecmn.cpp b/src/common/framecmn.cpp index 93d2cfc716..9674bb1750 100644 --- a/src/common/framecmn.cpp +++ b/src/common/framecmn.cpp @@ -148,7 +148,7 @@ wxCONSTRUCTOR_6( wxFrame, wxWindow*, Parent, wxWindowID, Id, wxString, Title, \ wxFrameBase::wxFrameBase() { -#if wxUSE_MENUS +#if wxUSE_MENUBAR m_frameMenuBar = NULL; #endif // wxUSE_MENUS @@ -183,7 +183,7 @@ wxFrame *wxFrameBase::New(wxWindow *parent, void wxFrameBase::DeleteAllBars() { -#if wxUSE_MENUS +#if wxUSE_MENUBAR wxDELETE(m_frameMenuBar); #endif // wxUSE_MENUS @@ -198,7 +198,7 @@ void wxFrameBase::DeleteAllBars() bool wxFrameBase::IsOneOfBars(const wxWindow *win) const { -#if wxUSE_MENUS +#if wxUSE_MENUBAR if ( win == GetMenuBar() ) return true; #endif // wxUSE_MENUS @@ -258,11 +258,15 @@ wxPoint wxFrameBase::GetClientAreaOrigin() const bool wxFrameBase::ProcessCommand(int id) { +#if wxUSE_MENUBAR wxMenuItem* const item = FindItemInMenuBar(id); if ( !item ) return false; return ProcessCommand(item); +#else + return false; +#endif } bool wxFrameBase::ProcessCommand(wxMenuItem *item) @@ -308,7 +312,7 @@ void wxFrameBase::UpdateWindowUI(long flags) GetToolBar()->UpdateWindowUI(flags); #endif -#if wxUSE_MENUS +#if wxUSE_MENUBAR if (GetMenuBar()) { // If coming from an idle event, we only want to update the menus if @@ -635,14 +639,18 @@ void wxFrameBase::DoMenuUpdates(wxMenu* menu) { menu->UpdateUI(); } +#if wxUSE_MENUBAR else { wxMenuBar* bar = GetMenuBar(); if (bar != NULL) bar->UpdateMenus(); } +#endif } +#if wxUSE_MENUBAR + void wxFrameBase::DetachMenuBar() { if ( m_frameMenuBar ) @@ -681,4 +689,6 @@ wxMenuItem *wxFrameBase::FindItemInMenuBar(int menuId) const return menuBar ? menuBar->FindItem(menuId) : NULL; } +#endif // wxUSE_MENUBAR + #endif // wxUSE_MENUS diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index f23aa68322..73e0568c50 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -101,9 +101,10 @@ bool wxMenuBarStreamingCallback( const wxObject *WXUNUSED(object), wxObjectWrite } #endif +#if wxUSE_MENUBAR wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxMenuBar, wxWindow, "wx/menu.h", \ wxMenuBarStreamingCallback) - +#endif #if wxUSE_EXTENDED_RTTI WX_DEFINE_LIST( wxMenuInfoHelperList ) @@ -445,8 +446,10 @@ wxMenuItem *wxMenuBase::DoRemove(wxMenuItem *item) if ( submenu ) { submenu->SetParent(NULL); +#if wxUSE_MENUBAR if ( submenu->IsAttached() ) submenu->Detach(); +#endif // wxUSE_MENUBAR } return item; @@ -648,7 +651,11 @@ bool wxMenuBase::DoProcessEvent(wxMenuBase* menu, wxEvent& event, wxWindow* win) { event.SetEventObject(menu); +#if wxUSE_MENUBAR wxMenuBar* const mb = menu ? menu->GetMenuBar() : NULL; +#else + bool mb = false; +#endif // Process event in the menu itself and all its parent menus, if it's a // submenu, first. @@ -669,6 +676,7 @@ bool wxMenuBase::DoProcessEvent(wxMenuBase* menu, wxEvent& event, wxWindow* win) } } +#if wxUSE_MENUBAR // If this menu is part of the menu bar, try the event there. if ( mb ) { @@ -681,6 +689,7 @@ bool wxMenuBase::DoProcessEvent(wxMenuBase* menu, wxEvent& event, wxWindow* win) if ( event.ShouldPropagate() ) return false; } +#endif // wxUSE_MENUBAR // Try the window the menu was popped up from. if ( win ) @@ -712,6 +721,7 @@ wxMenuBase::ProcessMenuEvent(wxMenu* menu, wxMenuEvent& event, wxWindow* win) // wxMenu attaching/detaching to/from menu bar // ---------------------------------------------------------------------------- +#if wxUSE_MENUBAR wxMenuBar* wxMenuBase::GetMenuBar() const { if(GetParent()) @@ -737,6 +747,7 @@ void wxMenuBase::Detach() m_menuBar = NULL; } +#endif // wxUSE_MENUBAR // ---------------------------------------------------------------------------- // wxMenu invoking window handling @@ -746,9 +757,10 @@ void wxMenuBase::SetInvokingWindow(wxWindow *win) { wxASSERT_MSG( !GetParent(), "should only be called for top level popup menus" ); +#if wxUSE_MENUBAR wxASSERT_MSG( !IsAttached(), "menus attached to menu bar can't have invoking window" ); - +#endif m_invokingWindow = win; } @@ -762,8 +774,12 @@ wxWindow *wxMenuBase::GetWindow() const menu = menu->GetParent(); } +#if wxUSE_MENUBAR return menu->GetMenuBar() ? menu->GetMenuBar()->GetFrame() : menu->GetInvokingWindow(); +#else + return menu->GetInvokingWindow(); +#endif } // ---------------------------------------------------------------------------- @@ -842,6 +858,8 @@ wxString wxMenuBase::GetHelpString( int itemid ) const return item->GetHelp(); } +#if wxUSE_MENUBAR + // ---------------------------------------------------------------------------- // wxMenuBarBase ctor and dtor // ---------------------------------------------------------------------------- @@ -1110,4 +1128,6 @@ wxString wxMenuBarBase::GetLabelTop(size_t pos) const } #endif +#endif // wxUSE_MENUBAR + #endif // wxUSE_MENUS diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 12fc75761c..05b6fa002f 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -1261,15 +1261,15 @@ wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString) { -#if wxUSE_MENUS +#if wxUSE_MENUBAR wxMenuBar *menuBar = frame->GetMenuBar (); if ( menuBar ) return menuBar->FindMenuItem (menuString, itemString); -#else // !wxUSE_MENUS +#else // !wxUSE_MENUBAR wxUnusedVar(frame); wxUnusedVar(menuString); wxUnusedVar(itemString); -#endif // wxUSE_MENUS/!wxUSE_MENUS +#endif // wxUSE_MENUBAR/!wxUSE_MENUBAR return wxNOT_FOUND; } diff --git a/src/osx/carbon/app.cpp b/src/osx/carbon/app.cpp index 72dfd06312..22ed5315ff 100644 --- a/src/osx/carbon/app.cpp +++ b/src/osx/carbon/app.cpp @@ -412,7 +412,7 @@ void wxApp::OnIdle(wxIdleEvent& WXUNUSED(event)) // either events to the threads other than main or events posted with // wxPostEvent() functions #ifndef __WXUNIVERSAL__ -#if wxUSE_MENUS +#if wxUSE_MENUBAR if (!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar()) wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar(); #endif diff --git a/src/osx/carbon/frame.cpp b/src/osx/carbon/frame.cpp index 626157f6ea..67d8616303 100644 --- a/src/osx/carbon/frame.cpp +++ b/src/osx/carbon/frame.cpp @@ -84,7 +84,7 @@ bool wxFrame::Enable(bool enable) if ( !wxWindow::Enable(enable) ) return false; -#if wxUSE_MENUS +#if wxUSE_MENUBAR // we should always enable/disable the menubar, even if we are not current, otherwise // we might miss some state change later (happened eg in the docview sample after PrintPreview) if ( m_frameMenuBar /*&& m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar()*/) @@ -156,7 +156,7 @@ void wxFrame::OnActivate(wxActivateEvent& event) } else { -#if wxUSE_MENUS +#if wxUSE_MENUBAR if (m_frameMenuBar != NULL) { m_frameMenuBar->MacInstallMenuBar(); @@ -180,7 +180,7 @@ void wxFrame::OnActivate(wxActivateEvent& event) #endif } -#if wxUSE_MENUS +#if wxUSE_MENUBAR void wxFrame::DetachMenuBar() { wxFrameBase::DetachMenuBar(); @@ -210,7 +210,7 @@ void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) m_frameMenuBar->MacInstallMenuBar(); } } -#endif +#endif // wxUSE_MENUBAR void wxFrame::DoGetClientSize(int *x, int *y) const { @@ -391,7 +391,7 @@ bool wxFrame::Show(bool show) { if ( !show ) { -#if wxUSE_MENUS +#if wxUSE_MENUBAR if (m_frameMenuBar != NULL) { m_frameMenuBar->MacUninstallMenuBar(); diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index 2ea427c278..712f2a95d9 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -66,13 +66,14 @@ void wxMenu::Init() m_peer = wxMenuImpl::Create( this, wxStripMenuCodes(m_title, wxStrip_Menu) ); - - // if we have a title, insert it in the beginning of the menu +#if wxOSX_USE_COCOA + // under macOS there is no built-in title, so if we have a title, insert it in the beginning of the menu if ( !m_title.empty() ) { Append(idMenuTitle, m_title) ; AppendSeparator() ; } +#endif } wxMenu::~wxMenu() @@ -151,9 +152,11 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *item, size_t pos) } } +#if wxUSE_MENUBAR // if we're already attached to the menubar, we must update it if ( IsAttached() && GetMenuBar()->IsAttached() ) GetMenuBar()->Refresh(); +#endif // wxUSE_MENUBAR if ( check ) item->Check(true); @@ -400,6 +403,8 @@ void wxMenu::HandleMenuClosed() DoHandleMenuOpenedOrClosed(wxEVT_MENU_CLOSE); } +#if wxUSE_MENUBAR + // Menu Bar /* @@ -707,5 +712,6 @@ void wxMenuBar::DoGetClientSize(int *width, int *height) const DoGetSize(width, height); } +#endif // wxUSE_MENUBAR #endif // wxUSE_MENUS diff --git a/src/xrc/xh_menu.cpp b/src/xrc/xh_menu.cpp index c2471b2f27..d39625e1a4 100644 --- a/src/xrc/xh_menu.cpp +++ b/src/xrc/xh_menu.cpp @@ -47,12 +47,14 @@ wxObject *wxMenuXmlHandler::DoCreateResource() CreateChildren(menu, true/*only this handler*/); m_insideMenu = oldins; +#if wxUSE_MENUBAR wxMenuBar *p_bar = wxDynamicCast(m_parent, wxMenuBar); if (p_bar) { p_bar->Append(menu, title); } else +#endif // wxUSE_MENUBAR { wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu); if (p_menu) @@ -145,6 +147,8 @@ bool wxMenuXmlHandler::CanHandle(wxXmlNode *node) ); } +#if wxUSE_MENUBAR + wxIMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler, wxXmlResourceHandler); wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler() @@ -184,4 +188,6 @@ bool wxMenuBarXmlHandler::CanHandle(wxXmlNode *node) return IsOfClass(node, wxT("wxMenuBar")); } +#endif // wxUSE_MENUBAR + #endif // wxUSE_XRC && wxUSE_MENUS diff --git a/src/xrc/xmlrsall.cpp b/src/xrc/xmlrsall.cpp index 93596fad65..10697bc734 100644 --- a/src/xrc/xmlrsall.cpp +++ b/src/xrc/xmlrsall.cpp @@ -140,8 +140,10 @@ void wxXmlResource::InitAllHandlers() #endif #if wxUSE_MENUS AddHandler(new wxMenuXmlHandler); +#if wxUSE_MENUBAR AddHandler(new wxMenuBarXmlHandler); #endif +#endif #if wxUSE_NOTEBOOK AddHandler(new wxNotebookXmlHandler); #endif diff --git a/tests/events/propagation.cpp b/tests/events/propagation.cpp index 4558954e3a..9f7a7088ea 100644 --- a/tests/events/propagation.cpp +++ b/tests/events/propagation.cpp @@ -436,10 +436,11 @@ wxMenu* CreateTestMenu(wxFrame* frame) { wxMenu* const menu = new wxMenu; menu->Append(wxID_APPLY); +#if wxUSE_MENUBAR wxMenuBar* const mb = new wxMenuBar; mb->Append(menu, "&Menu"); frame->SetMenuBar(mb); - +#endif return menu; } @@ -464,10 +465,11 @@ void EventPropagationTestCase::MenuEvent() // Create a minimal menu bar. wxMenu* const menu = CreateTestMenu(frame); +#if wxUSE_MENUBAR wxMenuBar* const mb = menu->GetMenuBar(); wxScopedPtr ensureMenuBarDestruction(mb); wxON_BLOCK_EXIT_OBJ1( *frame, wxFrame::SetMenuBar, (wxMenuBar*)NULL ); - +#endif // Check that wxApp gets the event exactly once. ASSERT_MENU_EVENT_RESULT( menu, "aA" ); @@ -491,13 +493,14 @@ void EventPropagationTestCase::MenuEvent() wxEvtHandler::SetNextHandler, (wxEvtHandler*)NULL ); ASSERT_MENU_EVENT_RESULT_FOR( wxID_ABOUT, submenu, "aosomA" ); +#if wxUSE_MENUBAR // Test that the event handler associated with the menu bar gets the event. TestMenuEvtHandler hb('b'); // 'b' for "menu Bar" mb->PushEventHandler(&hb); wxON_BLOCK_EXIT_OBJ1( *mb, wxWindow::PopEventHandler, false ); ASSERT_MENU_EVENT_RESULT( menu, "aomobA" ); - +#endif // Also test that the window to which the menu belongs gets the event. TestMenuEvtHandler hw('w'); // 'w' for "Window" diff --git a/tests/menu/menu.cpp b/tests/menu/menu.cpp index ef957e4f18..151f654ebe 100644 --- a/tests/menu/menu.cpp +++ b/tests/menu/menu.cpp @@ -12,7 +12,7 @@ #include "testprec.h" -#if wxUSE_MENUS +#if wxUSE_MENUBAR #ifdef __BORLANDC__ #pragma hdrstop