Audacity  2.2.2
MenusMac.cpp
Go to the documentation of this file.
1 //
2 // MenusMac.cpp
3 // Audacity
4 //
5 // Created by Paul Licameli on 6/28/16.
6 //
7 //
8 
9 // This file collects a few things specific to Mac and requiring some
10 // Objective-C++ . Avoid mixing languages elsewhere.
11 
12 #include "Audacity.h"
13 #include "AudacityApp.h"
14 #include "Project.h"
15 
16 #undef USE_COCOA
17 
18 #ifdef USE_COCOA
19 #include <AppKit/AppKit.h>
20 #include <wx/osx/private.h>
21 #endif
22 
23 #include <objc/objc.h>
24 #include <CoreFoundation/CoreFoundation.h>
25 
27 {
28  auto window = project;
29  if (window) {
30 #ifdef USE_COCOA
31  // Adapted from mbarman.mm in wxWidgets 3.0.2
32  auto peer = window->GetPeer();
33  peer->GetWXPeer();
34  auto widget = static_cast<wxWidgetCocoaImpl*>(peer)->GetWXWidget();
35  auto nsWindow = [widget window];
36  if (nsWindow) {
37  [nsWindow performMiniaturize:widget];
38  }
39 #else
40  window->Iconize(true);
41 #endif
42 
43  // So that the Minimize menu command disables
44  project->UpdateMenus();
45  }
46 }
47 
49 {
50  DoMacMinimize(this);
51 }
52 
54 {
55  for (const auto project : gAudacityProjects) {
56  DoMacMinimize(project.get());
57  }
58 }
59 
61 {
62  auto window = this;
63  auto topWindow = static_cast<wxTopLevelWindow*>(window);
64  auto maximized = topWindow->IsMaximized();
65  if (window) {
66 #ifdef USE_COCOA
67  // Adapted from mbarman.mm in wxWidgets 3.0.2
68  auto peer = window->GetPeer();
69  peer->GetWXPeer();
70  auto widget = static_cast<wxWidgetCocoaImpl*>(peer)->GetWXWidget();
71  auto nsWindow = [widget window];
72  if (nsWindow)
73  [nsWindow performZoom:widget];
74 #else
75  topWindow->Maximize(!maximized);
76 #endif
77  }
78 }
79 
81 {
82  // Reall this de-miniaturizes all, which is not exactly the standard
83  // behavior.
84  for (const auto project : gAudacityProjects) {
85  project->Raise();
86  }
87 }
88 
89 void AudacityApp::MacActivateApp()
90 {
91  id app = [NSApplication sharedApplication];
92  if ( [app respondsToSelector:@selector(activateIgnoringOtherApps:)] )
93  [app activateIgnoringOtherApps:YES];
94 }
void UpdateMenus(bool checkActive=true)
Definition: Menus.cpp:2294
void OnMacMinimizeAll(const CommandContext &context)
Definition: MenusMac.cpp:53
void OnMacMinimize(const CommandContext &context)
Definition: MenusMac.cpp:48
AProjectArray gAudacityProjects
Definition: Project.cpp:295
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
void OnMacBringAllToFront(const CommandContext &context)
Definition: MenusMac.cpp:80
static void DoMacMinimize(AudacityProject *project)
Definition: MenusMac.cpp:26
void OnMacZoom(const CommandContext &context)
Definition: MenusMac.cpp:60