Audacity 3.2.0
Functions | Variables
anonymous_namespace{WindowMenus.cpp} Namespace Reference

Functions

void DoMacMinimize (AudacityProject *project)
 
void RebuildMenu (wxCommandEvent &evt)
 
wxWindowID ReservedID (size_t index, const std::shared_ptr< AudacityProject > &pProject)
 
void OnWindow (wxCommandEvent &evt)
 
BaseItemSharedPtr WindowMenu ()
 
BaseItemSharedPtr ExtraWindowItems ()
 

Variables

std::vector< wxWindowID > sReservedIds
 
std::vector< std::weak_ptr< AudacityProject > > sProjects
 
AttachedItem sAttachment1
 
AttachedItem sAttachment2
 

Function Documentation

◆ DoMacMinimize()

void anonymous_namespace{WindowMenus.cpp}::DoMacMinimize ( AudacityProject project)

Definition at line 34 of file WindowMenus.cpp.

35{
36 if (project) {
37 auto window = &GetProjectFrame( *project );
38#ifdef USE_COCOA
39 // Adapted from mbarman.mm in wxWidgets 3.0.2
40 auto peer = window->GetPeer();
41 peer->GetWXPeer();
42 auto widget = static_cast<wxWidgetCocoaImpl*>(peer)->GetWXWidget();
43 auto nsWindow = [widget window];
44 if (nsWindow) {
45 [nsWindow performMiniaturize:widget];
46 }
47#else
48 window->Iconize(true);
49#endif
50
51 // So that the Minimize menu command disables
52 MenuManager::Get(*project).UpdateMenus();
53 }
54}
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:71
void UpdateMenus(bool checkActive=true)
Definition: Menus.cpp:643

References MenuManager::Get(), GetProjectFrame(), and MenuManager::UpdateMenus().

Referenced by WindowActions::Handler::OnMacMinimize(), and WindowActions::Handler::OnMacMinimizeAll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExtraWindowItems()

BaseItemSharedPtr anonymous_namespace{WindowMenus.cpp}::ExtraWindowItems ( )

Definition at line 248 of file WindowMenus.cpp.

249{
250 static BaseItemSharedPtr items{
252 Items( wxT("MacWindows"),
253 /* i18n-hint: Shrink all project windows to icons on the Macintosh
254 tooldock */
255 Command( wxT("MacMinimizeAll"), XXO("Minimize All Projects"),
256 FN(OnMacMinimizeAll),
257 AlwaysEnabledFlag, wxT("Ctrl+Alt+M") )
258 ) ) };
259 return items;
260}
wxT("CloseDown"))
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:35
#define XXO(s)
Definition: Internat.h:44
static CommandHandlerObject & findCommandHandler(AudacityProject &)
#define FN(X)
std::unique_ptr< MenuItems > Items(const Identifier &internalName, Args &&... args)
std::unique_ptr< CommandItem > Command(const CommandID &name, const TranslatableString &label_in, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, const CommandManager::Options &options={}, CommandHandlerFinder finder=FinderScope::DefaultFinder())
std::shared_ptr< BaseItem > BaseItemSharedPtr
Definition: Registry.h:72

References AlwaysEnabledFlag, MenuTable::Command(), findCommandHandler(), FN, MenuTable::Items(), wxT(), and XXO.

Here is the call graph for this function:

◆ OnWindow()

void anonymous_namespace{WindowMenus.cpp}::OnWindow ( wxCommandEvent &  evt)

Definition at line 90 of file WindowMenus.cpp.

91{
92 const auto begin = sReservedIds.begin(), end = sReservedIds.end(),
93 iter = std::find( begin, end, evt.GetId() );
94 size_t index = iter - begin;
95 if ( index < sProjects.size() ) {
96 auto pProject = sProjects[ index ].lock();
97 if ( pProject ) {
98 // Make it the active project
99 SetActiveProject(pProject.get());
100
101 // And ensure it's visible
102 wxFrame *frame = pProject->GetFrame();
103 if (frame->IsIconized())
104 {
105 frame->Restore();
106 }
107 frame->Raise();
108 }
109 }
110}
void SetActiveProject(AudacityProject *project)
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150
std::vector< wxWindowID > sReservedIds
Definition: WindowMenus.cpp:56
std::vector< std::weak_ptr< AudacityProject > > sProjects
Definition: WindowMenus.cpp:57

References PackedArray::begin(), PackedArray::end(), SetActiveProject(), sProjects, and sReservedIds.

Referenced by WindowMenu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RebuildMenu()

void anonymous_namespace{WindowMenus.cpp}::RebuildMenu ( wxCommandEvent &  evt)

Definition at line 59 of file WindowMenus.cpp.

60{
61 // Let other listeners hear it too
62 evt.Skip();
63
64 // This is a big hammer.
65 // Really we just need to recreate just the Window menu.
66 // This causes the checkmark to be put in the right place for the
67 // currently active project
69}
static void RebuildAllMenuBars()
Definition: Menus.cpp:687

References MenuCreator::RebuildAllMenuBars().

Referenced by ReservedID().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReservedID()

wxWindowID anonymous_namespace{WindowMenus.cpp}::ReservedID ( size_t  index,
const std::shared_ptr< AudacityProject > &  pProject 
)

Definition at line 71 of file WindowMenus.cpp.

73{
74 if ( sReservedIds.empty() ) {
75 // Do this once only per session, and don't worry about unbinding
76 wxTheApp->Bind( EVT_PROJECT_ACTIVATION, RebuildMenu );
77 wxTheApp->Bind( EVT_PROJECT_TITLE_CHANGE, RebuildMenu );
78 }
79
80 while ( sReservedIds.size() <= index )
81 sReservedIds.emplace_back( wxIdManager::ReserveId() );
82
83 if ( sProjects.size() < sReservedIds.size() )
84 sProjects.resize( sReservedIds.size() );
85 sProjects[ index ] = pProject;
86
87 return sReservedIds[ index ];
88}
void RebuildMenu(wxCommandEvent &evt)
Definition: WindowMenus.cpp:59

References RebuildMenu(), sProjects, and sReservedIds.

Referenced by WindowMenu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WindowMenu()

BaseItemSharedPtr anonymous_namespace{WindowMenus.cpp}::WindowMenu ( )

Definition at line 181 of file WindowMenus.cpp.

182{
184 // poor imitation of the Mac Windows Menu
186 static BaseItemSharedPtr menu{
188 Menu( wxT("Window"), XXO("&Window"),
189 Section( "",
190 /* i18n-hint: Standard Macintosh Window menu item: Make (the current
191 * window) shrink to an icon on the dock */
192 Command( wxT("MacMinimize"), XXO("&Minimize"), FN(OnMacMinimize),
193 NotMinimizedFlag(), wxT("Ctrl+M") ),
194 /* i18n-hint: Standard Macintosh Window menu item: Make (the current
195 * window) full sized */
196 Command( wxT("MacZoom"), XXO("&Zoom"),
197 FN(OnMacZoom), NotMinimizedFlag() )
198 ),
199
200 Section( "",
201 /* i18n-hint: Standard Macintosh Window menu item: Make all project
202 * windows un-hidden */
203 Command( wxT("MacBringAllToFront"), XXO("&Bring All to Front"),
204 FN(OnMacBringAllToFront), AlwaysEnabledFlag )
205 ),
206
207 Section( "",
208 Special( wxT("PopulateWindowsStep"),
209 [](AudacityProject &, wxMenu &theMenu)
210 {
211 // Undo previous bindings
212 for ( auto id : sReservedIds )
213 wxTheApp->Unbind( wxEVT_MENU, OnWindow, id );
214
215 // Add all projects to this project's Window menu
216 size_t ii = 0;
217 for (auto project : AllProjects{})
218 {
219 int itemId = ReservedID( ii++, project );
220 wxString itemName = project->GetFrame()->GetTitle();
221 bool isActive = (GetActiveProject() == project.get());
222
223 // This should never really happen, but a menu item must have a name
224 if (itemName.empty())
225 {
226 itemName = _("<untitled>");
227 }
228
229 // Add it to the menu and check it if it's the active project
230 wxMenuItem *item = theMenu.Append(itemId, itemName);
231 item->SetCheckable(true);
232 item->Check(isActive);
233
234 // Bind the callback
235 wxTheApp->Bind( wxEVT_MENU, OnWindow, itemId );
236 }
237 } )
238 )
239 ) ) };
240 return menu;
241}
AUDACITY_DLL_API std::weak_ptr< AudacityProject > GetActiveProject()
const ReservedCommandFlag & NotMinimizedFlag()
#define _(s)
Definition: Internat.h:75
for(int ii=0, nn=names.size();ii< nn;++ii)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
std::unique_ptr< MenuItem > Menu(const Identifier &internalName, const TranslatableString &title, Args &&... args)
std::unique_ptr< MenuPart > Section(const Identifier &internalName, Args &&... args)
std::unique_ptr< SpecialItem > Special(const Identifier &name, const SpecialItem::Appender &fn)
wxWindowID ReservedID(size_t index, const std::shared_ptr< AudacityProject > &pProject)
Definition: WindowMenus.cpp:71
void OnWindow(wxCommandEvent &evt)
Definition: WindowMenus.cpp:90

References _, AlwaysEnabledFlag, MenuTable::Command(), findCommandHandler(), FN, for(), GetActiveProject(), MenuTable::Menu(), NotMinimizedFlag(), OnWindow(), ReservedID(), MenuTable::Section(), MenuTable::Special(), sReservedIds, wxT(), and XXO.

Here is the call graph for this function:

Variable Documentation

◆ sAttachment1

AttachedItem anonymous_namespace{WindowMenus.cpp}::sAttachment1
Initial value:

Definition at line 243 of file WindowMenus.cpp.

◆ sAttachment2

AttachedItem anonymous_namespace{WindowMenus.cpp}::sAttachment2
Initial value:
{
Placement{ wxT("Optional/Extra/Part2/Misc"), OrderingHint::End },
}

Definition at line 262 of file WindowMenus.cpp.

◆ sProjects

std::vector< std::weak_ptr< AudacityProject > > anonymous_namespace{WindowMenus.cpp}::sProjects

Definition at line 57 of file WindowMenus.cpp.

Referenced by OnWindow(), and ReservedID().

◆ sReservedIds

std::vector< wxWindowID > anonymous_namespace{WindowMenus.cpp}::sReservedIds

Definition at line 56 of file WindowMenus.cpp.

Referenced by OnWindow(), ReservedID(), and WindowMenu().