Audacity  3.0.3
ProjectWindows.cpp
Go to the documentation of this file.
1 /*!********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  @file ProjectWindows.cpp
6 
7  Paul Licameli split from Project.cpp
8 
9 **********************************************************************/
10 
11 #include "ProjectWindows.h"
12 #include "Project.h"
14 
15 #include <wx/frame.h>
16 
17 namespace {
19 {
20  static ProjectWindows &Get( AudacityProject &project );
21  static const ProjectWindows &Get( const AudacityProject &project );
22  explicit ProjectWindows(AudacityProject &project)
23  : mAttachedWindows{project}
24  {}
25 
26  wxWeakRef< wxWindow > mPanel{};
27  wxWeakRef< wxFrame > mFrame{};
28 
30 };
31 
33  [](AudacityProject &project) {
34  return std::make_unique<ProjectWindows>(project);
35  }
36 };
37 
39 {
40  return project.AttachedObjects::Get< ProjectWindows >( key );
41 }
42 
44 {
45  return Get( const_cast< AudacityProject & >( project ) );
46 }
47 }
48 
49 AUDACITY_DLL_API wxWindow &GetProjectPanel( AudacityProject &project )
50 {
51  auto ptr = ProjectWindows::Get(project).mPanel;
52  if ( !ptr )
54  return *ptr;
55 }
56 
57 AUDACITY_DLL_API const wxWindow &GetProjectPanel(
58  const AudacityProject &project )
59 {
60  auto ptr = ProjectWindows::Get(project).mPanel;
61  if ( !ptr )
63  return *ptr;
64 }
65 
66 AUDACITY_DLL_API void SetProjectPanel(
67  AudacityProject &project, wxWindow &panel )
68 {
69  ProjectWindows::Get(project).mPanel = &panel;
70 }
71 
72 AUDACITY_DLL_API wxFrame &GetProjectFrame( AudacityProject &project )
73 {
74  auto ptr = ProjectWindows::Get(project).mFrame;
75  if ( !ptr )
77  return *ptr;
78 }
79 
80 AUDACITY_DLL_API const wxFrame &GetProjectFrame( const AudacityProject &project )
81 {
82  auto ptr = ProjectWindows::Get(project).mFrame;
83  if ( !ptr )
85  return *ptr;
86 }
87 
88 wxFrame *FindProjectFrame( AudacityProject *project ) {
89  if (!project)
90  return nullptr;
91  return ProjectWindows::Get(*project).mFrame;
92 }
93 
94 const wxFrame *FindProjectFrame( const AudacityProject *project ) {
95  if (!project)
96  return nullptr;
97  return ProjectWindows::Get(*project).mFrame;
98 }
99 
100 std::unique_ptr<const BasicUI::WindowPlacement>
102 {
103  if (!project)
104  return std::make_unique<BasicUI::WindowPlacement>();
105  return std::make_unique<wxWidgetsWindowPlacement>(
106  &GetProjectFrame(*project));
107 }
108 
109 void SetProjectFrame(AudacityProject &project, wxFrame &frame )
110 {
111  ProjectWindows::Get(project).mFrame = &frame;
112 }
113 
115 {
116  return ProjectWindows::Get(project).mAttachedWindows;
117 }
AttachedWindows
Definition: ProjectWindows.h:56
ProjectFramePlacement
std::unique_ptr< const BasicUI::WindowPlacement > ProjectFramePlacement(AudacityProject *project)
Make a WindowPlacement object suitable for project (which may be null)
Definition: ProjectWindows.cpp:101
mFrame
ScreenshotBigDialogPtr mFrame
Definition: Screenshot.cpp:131
Project.h
wxWidgetsWindowPlacement.h
ClientData::Base
A convenient default parameter for class template Site.
Definition: ClientData.h:28
anonymous_namespace{ProjectWindows.cpp}::ProjectWindows::ProjectWindows
ProjectWindows(AudacityProject &project)
Definition: ProjectWindows.cpp:22
ClientData::Site::RegisteredFactory
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
GetAttachedWindows
AUDACITY_DLL_API AttachedWindows & GetAttachedWindows(AudacityProject &project)
Definition: ProjectWindows.cpp:114
anonymous_namespace{ProjectWindows.cpp}::ProjectWindows
Definition: ProjectWindows.cpp:19
THROW_INCONSISTENCY_EXCEPTION
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.
Definition: InconsistencyException.h:79
anonymous_namespace{ProjectWindows.cpp}::key
const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: ProjectWindows.cpp:32
ProjectWindows.h
accessors for certain important windows associated with each project
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
anonymous_namespace{ProjectWindows.cpp}::ProjectWindows::mAttachedWindows
AttachedWindows mAttachedWindows
Definition: ProjectWindows.cpp:29
GetProjectFrame
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 ...
Definition: ProjectWindows.cpp:72
SetProjectPanel
AUDACITY_DLL_API void SetProjectPanel(AudacityProject &project, wxWindow &panel)
Definition: ProjectWindows.cpp:66
FindProjectFrame
wxFrame * FindProjectFrame(AudacityProject *project)
Get a pointer to the window associated with a project, or null if the given pointer is null,...
Definition: ProjectWindows.cpp:88
GetProjectPanel
AUDACITY_DLL_API wxWindow & GetProjectPanel(AudacityProject &project)
Get the main sub-window of the project frame that displays track data.
Definition: ProjectWindows.cpp:49
SetProjectFrame
void SetProjectFrame(AudacityProject &project, wxFrame &frame)
Definition: ProjectWindows.cpp:109