From 617fdb387fd56a358510abc0ce33a3d2940a9249 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 28 Jun 2016 15:52:33 -0400 Subject: [PATCH] Bugs 1119, 1198: Bring back the Mac Window menu, at least partly... ... This poor imitation of the standard Mac Window menu only includes Minimize and Zoom. But this may be adequate for the complaints in Bug1198, when the yellow title bar button is hidden and unreachable. --- mac/Audacity.xcodeproj/project.pbxproj | 4 ++ src/AudacityApp.h | 4 +- src/Menus.cpp | 32 +++++++++++++++- src/Menus.h | 4 ++ src/MenusMac.cpp | 51 ++++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 src/MenusMac.cpp diff --git a/mac/Audacity.xcodeproj/project.pbxproj b/mac/Audacity.xcodeproj/project.pbxproj index 670fdfe0e..0c9ccfe4b 100644 --- a/mac/Audacity.xcodeproj/project.pbxproj +++ b/mac/Audacity.xcodeproj/project.pbxproj @@ -1209,6 +1209,7 @@ 28FE4A080ABF4E960056F5C4 /* mmx_optimized.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28FE4A060ABF4E960056F5C4 /* mmx_optimized.cpp */; }; 28FE4A090ABF4E960056F5C4 /* sse_optimized.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28FE4A070ABF4E960056F5C4 /* sse_optimized.cpp */; }; 5E02BFF21D1164DF00EB7578 /* Distortion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E02BFF01D1164DF00EB7578 /* Distortion.cpp */; }; + 5E0A0E311D23019A00CD2567 /* MenusMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E0A0E301D23019A00CD2567 /* MenusMac.cpp */; }; 5E74D2E31CC4429700D88B0B /* EditCursorOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E74D2DD1CC4429700D88B0B /* EditCursorOverlay.cpp */; }; 5E74D2E41CC4429700D88B0B /* PlayIndicatorOverlay.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E74D2DF1CC4429700D88B0B /* PlayIndicatorOverlay.cpp */; }; 5E74D2E51CC4429700D88B0B /* Scrubbing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E74D2E11CC4429700D88B0B /* Scrubbing.cpp */; }; @@ -2978,6 +2979,7 @@ 28FEC1B21A12B6FB00FACE48 /* EffectAutomationParameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EffectAutomationParameters.h; path = ../include/audacity/EffectAutomationParameters.h; sourceTree = SOURCE_ROOT; }; 5E02BFF01D1164DF00EB7578 /* Distortion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Distortion.cpp; sourceTree = ""; }; 5E02BFF11D1164DF00EB7578 /* Distortion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Distortion.h; sourceTree = ""; }; + 5E0A0E301D23019A00CD2567 /* MenusMac.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = MenusMac.cpp; sourceTree = ""; }; 5E4685F81CCA9D84008741F2 /* CommandFunctors.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommandFunctors.h; sourceTree = ""; }; 5E61EE0C1CBAA6BB0009FCF1 /* MemoryX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryX.h; sourceTree = ""; }; 5E74D2D91CC4427B00D88B0B /* TrackPanelCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TrackPanelCell.h; sourceTree = ""; }; @@ -3863,6 +3865,7 @@ 1865A9B61004490500946EE6 /* LyricsWindow.cpp */, 28EBA7FF0A78FAF800C8BB1F /* Matrix.cpp */, 1790B0A709883BFD008A330A /* Menus.cpp */, + 5E0A0E301D23019A00CD2567 /* MenusMac.cpp */, 1790B0AB09883BFD008A330A /* Mix.cpp */, 289E75081006D0BD00CEF79B /* MixerBoard.cpp */, 280A8B4519F4403B0091DE70 /* ModuleManager.cpp */, @@ -7438,6 +7441,7 @@ 283A11AA0A2C0E15004372C4 /* ShuttleGui.cpp in Sources */, 283A11AB0A2C0E15004372C4 /* Theme.cpp in Sources */, 28456AC20A2C180E00C23C1E /* ThemePrefs.cpp in Sources */, + 5E0A0E311D23019A00CD2567 /* MenusMac.cpp in Sources */, 28F1D81D0A2D0019005506A7 /* AttachableScrollBar.cpp in Sources */, 28F1D81E0A2D0019005506A7 /* ExpandingToolBar.cpp in Sources */, 28F1D81F0A2D0019005506A7 /* ImageRoll.cpp in Sources */, diff --git a/src/AudacityApp.h b/src/AudacityApp.h index 9f3906478..e8ef885fa 100644 --- a/src/AudacityApp.h +++ b/src/AudacityApp.h @@ -94,8 +94,8 @@ enum CommandFlag : unsigned long long CanStopAudioStreamFlag = 0x40000000, RulerHasFocus = 0x80000000ULL, // prl -// nextOneHas33BitsWow -// = 0x100000000ULL, // prl + NotMinimizedFlag + = 0x100000000ULL, // prl NoFlagsSpecifed = ~0ULL }; diff --git a/src/Menus.cpp b/src/Menus.cpp index 3bc770965..e084b87dd 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -1021,6 +1021,27 @@ void AudacityProject::CreateMenusAndCommands() c->EndMenu(); +#ifdef __WXMAC__ + ///////////////////////////////////////////////////////////////////////////// + // poor imitation of the Mac Windows Menu + ///////////////////////////////////////////////////////////////////////////// + + { + c->BeginMenu(_("&Window")); + c->AddItem(wxT("MacMinimize"), _("&Minimize"), FN(OnMacMinimize), + wxT("Ctrl+M"), NotMinimizedFlag, NotMinimizedFlag); + c->AddItem(wxT("MacZoom"), _("&Zoom"), FN(OnMacZoom), + wxT(""), NotMinimizedFlag, NotMinimizedFlag); +#if 0 + c->AddSeparator(); + c->AddItem(wxT("MacBringAllToFront"), + _("&Bring All to Front"), FN(OnMacBringAllToFront), + wxT(""), AlwaysEnabledFlag, AlwaysEnabledFlag); +#endif + c->EndMenu(); + } +#endif + ///////////////////////////////////////////////////////////////////////////// // Help Menu ///////////////////////////////////////////////////////////////////////////// @@ -1773,6 +1794,13 @@ CommandFlag AudacityProject::GetUpdateFlags() if (bar->ControlToolBar::CanStopAudioStream()) flags |= CanStopAudioStreamFlag; + if (auto focus = wxWindow::FindFocus()) { + while (focus && !focus->IsTopLevel()) + focus = focus->GetParent(); + if (focus && !static_cast(focus)->IsIconized()) + flags |= NotMinimizedFlag; + } + return flags; } @@ -1864,8 +1892,8 @@ void AudacityProject::UpdateMenus(bool checkActive) if (this != GetActiveProject()) return; - if (checkActive && !IsActive()) - return; + //if (checkActive && !IsActive()) + // return; auto flags = GetUpdateFlags(); auto flags2 = flags; diff --git a/src/Menus.h b/src/Menus.h index 5b0b81572..5f3d60ae4 100644 --- a/src/Menus.h +++ b/src/Menus.h @@ -184,6 +184,10 @@ void OnSnapToNearest(); void OnSnapToPrior(); void OnFullScreen(); +void OnMacMinimize(); +void OnMacZoom(); +void OnMacBringAllToFront(); + // File Menu void OnNew(); diff --git a/src/MenusMac.cpp b/src/MenusMac.cpp new file mode 100644 index 000000000..689e281cf --- /dev/null +++ b/src/MenusMac.cpp @@ -0,0 +1,51 @@ +// +// MenusMac.cpp +// Audacity +// +// Created by Paul Licameli on 6/28/16. +// +// + +#include "Audacity.h" +#include "Project.h" + +#include +#include + +void AudacityProject::OnMacMinimize() +{ + auto window = wxWindow::FindFocus(); + while (window && ! window->IsTopLevel()) + window = window->GetParent(); + if (window) { + auto peer = window->GetPeer(); + peer->GetWXPeer(); + auto widget = static_cast(peer)->GetWXWidget(); + auto nsWindow = [widget window]; + if (nsWindow) { + [nsWindow performMiniaturize:widget]; + } + if (nsWindow) { + this->UpdateMenus(); + } + } +} + +void AudacityProject::OnMacZoom() +{ + auto window = wxWindow::FindFocus(); + while (window && ! window->IsTopLevel()) + window = window->GetParent(); + if (window) { + auto peer = window->GetPeer(); + peer->GetWXPeer(); + auto widget = static_cast(peer)->GetWXWidget(); + auto nsWindow = [widget window]; + if (nsWindow) + [nsWindow performZoom:widget]; + } +} + +void AudacityProject::OnMacBringAllToFront() +{ +}