Audacity 3.2.0
Classes | Functions | Variables
ProjectWindow.h File Reference
#include <memory>
#include "ProjectWindowBase.h"
#include "Prefs.h"
#include "Viewport.h"
Include dependency graph for ProjectWindow.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ProjectWindowDestroyedMessage
 Message sent when the project window is closed. More...
 
class  ProjectWindow
 A top-level window associated with a project, and handling scrollbars and zooming. More...
 
struct  ProjectWindow::PlaybackScrollerMessage
 
class  ProjectWindow::PlaybackScroller
 

Functions

void InitProjectWindow (ProjectWindow &window)
 
void GetDefaultWindowRect (wxRect *defRect)
 
void GetNextWindowPlacement (wxRect *nextRect, bool *pMaximized, bool *pIconized)
 

Variables

AUDACITY_DLL_API BoolSetting ProjectWindowMaximized
 
AUDACITY_DLL_API BoolSetting ProjectWindowIconized
 
AUDACITY_DLL_API IntSetting ProjectWindowX
 
AUDACITY_DLL_API IntSetting ProjectWindowY
 
AUDACITY_DLL_API IntSetting ProjectWindowWidth
 
AUDACITY_DLL_API IntSetting ProjectWindowHeight
 
AUDACITY_DLL_API IntSetting ProjectWindowNormalX
 
AUDACITY_DLL_API IntSetting ProjectWindowNormalY
 
AUDACITY_DLL_API IntSetting ProjectWindowNormalWidth
 
AUDACITY_DLL_API IntSetting ProjectWindowNormalHeight
 

Function Documentation

◆ GetDefaultWindowRect()

void GetDefaultWindowRect ( wxRect *  defRect)

Definition at line 112 of file ProjectWindow.cpp.

113{
114 *defRect = wxGetClientDisplayRect();
115
116 int width = DEFAULT_WINDOW_WIDTH;
117 int height = DEFAULT_WINDOW_HEIGHT;
118
119 //These conditional values assist in improving placement and size
120 //of NEW windows on different platforms.
121#ifdef __WXGTK__
122 height += 20;
123#endif
124
125#ifdef __WXMSW__
126 height += 40;
127#endif
128
129#ifdef __WXMAC__
130 height += 55;
131#endif
132
133 // Use screen size where it is smaller than the values we would like.
134 // Otherwise use the values we would like, and centred.
135 if (width < defRect->width)
136 {
137 defRect->x = (defRect->width - width)/2;
138 defRect->width = width;
139 }
140
141 if (height < defRect->height)
142 {
143 defRect->y = (defRect->height - height)/2;
144 // Bug 1119 workaround
145 // Small adjustment for very small Mac screens.
146 // If there is only a tiny space at the top
147 // then instead of vertical centre, align to bottom.
148 const int pixelsFormenu = 60;
149 if( defRect->y < pixelsFormenu )
150 defRect->y *=2;
151 defRect->height = height;
152 }
153}

References anonymous_namespace{ProjectWindow.cpp}::DEFAULT_WINDOW_HEIGHT, and anonymous_namespace{ProjectWindow.cpp}::DEFAULT_WINDOW_WIDTH.

Referenced by GetNextWindowPlacement(), ProjectManager::SaveWindowSize(), and ProjectWindow::SetToDefaultSize().

Here is the caller graph for this function:

◆ GetNextWindowPlacement()

void GetNextWindowPlacement ( wxRect *  nextRect,
bool *  pMaximized,
bool *  pIconized 
)

Definition at line 159 of file ProjectWindow.cpp.

160{
161 int inc = 25;
162
163 wxRect defaultRect;
164 GetDefaultWindowRect(&defaultRect);
165
166 *pMaximized = ProjectWindowMaximized.Read();
167 *pIconized = ProjectWindowIconized.Read();
168
169 wxRect windowRect;
170 windowRect.x = ProjectWindowX.ReadWithDefault(defaultRect.x);
171 windowRect.y = ProjectWindowY.ReadWithDefault(defaultRect.y);
172 windowRect.width = ProjectWindowWidth.ReadWithDefault(defaultRect.width);
173 windowRect.height = ProjectWindowHeight.ReadWithDefault(defaultRect.height);
174
175 wxRect normalRect;
176 normalRect.x = ProjectWindowNormalX.ReadWithDefault(defaultRect.x);
177 normalRect.y = ProjectWindowNormalY.ReadWithDefault(defaultRect.y);
178 normalRect.width = ProjectWindowNormalWidth.ReadWithDefault(defaultRect.width);
179 normalRect.height = ProjectWindowNormalHeight.ReadWithDefault(defaultRect.height);
180
181 // Workaround 2.1.1 and earlier bug on OSX...affects only normalRect, but let's just
182 // validate for all rects and plats
183 if (normalRect.width == 0 || normalRect.height == 0) {
184 normalRect = defaultRect;
185 }
186 if (windowRect.width == 0 || windowRect.height == 0) {
187 windowRect = defaultRect;
188 }
189
190
191 wxRect screenRect( wxGetClientDisplayRect());
192#if defined(__WXMAC__)
193
194 // On OSX, the top of the window should never be less than the menu height,
195 // so something is amiss if it is
196 if (normalRect.y < screenRect.y) {
197 normalRect = defaultRect;
198 }
199 if (windowRect.y < screenRect.y) {
200 windowRect = defaultRect;
201 }
202#endif
203
204 // IF projects empty, THEN it's the first window.
205 // It lands where the config says it should, and can straddle screen.
206 if (AllProjects{}.empty()) {
207 if (*pMaximized || *pIconized) {
208 *nextRect = normalRect;
209 }
210 else {
211 *nextRect = windowRect;
212 }
213 // Resize, for example if one monitor that was on is now off.
214 if (!CornersOnScreen( wxRect(*nextRect).Deflate( 32, 32 ))) {
215 *nextRect = defaultRect;
216 }
217 if (!IsWindowAccessible(nextRect)) {
218 *nextRect = defaultRect;
219 }
220 // Do not trim the first project window down.
221 // All corners are on screen (or almost so), and
222 // the rect may straddle screens.
223 return;
224 }
225
226
227 // ELSE a subsequent NEW window. It will NOT straddle screens.
228
229 // We don't mind being 32 pixels off the screen in any direction.
230 // Make sure initial sizes (pretty much) fit within the display bounds
231 // We used to trim the sizes which could result in ridiculously small windows.
232 // contributing to bug 1243.
233 // Now instead if the window significantly doesn't fit the screen, we use the default
234 // window instead, which we know does.
235 if (ScreenContaining( wxRect(normalRect).Deflate( 32, 32 ))<0) {
236 normalRect = defaultRect;
237 }
238 if (ScreenContaining( wxRect(windowRect).Deflate( 32, 32 ) )<0) {
239 windowRect = defaultRect;
240 }
241
242 bool validWindowSize = false;
243 ProjectWindow * validProject = NULL;
244 for ( auto iter = AllProjects{}.rbegin(), end = AllProjects{}.rend();
245 iter != end; ++iter
246 ) {
247 auto pProject = *iter;
248 if (!GetProjectFrame( *pProject ).IsIconized()) {
249 validWindowSize = true;
250 validProject = &ProjectWindow::Get( *pProject );
251 break;
252 }
253 }
254 if (validWindowSize) {
255 *nextRect = validProject->GetRect();
256 *pMaximized = validProject->IsMaximized();
257 *pIconized = validProject->IsIconized();
258 // Do not straddle screens.
259 if (ScreenContaining( wxRect(*nextRect).Deflate( 32, 32 ) )<0) {
260 *nextRect = defaultRect;
261 }
262 }
263 else {
264 *nextRect = normalRect;
265 }
266
267 //Placement depends on the increments
268 nextRect->x += inc;
269 nextRect->y += inc;
270
271 // defaultrect is a rectangle on the first screen. It's the right fallback to
272 // use most of the time if things are not working out right with sizing.
273 // windowRect is a saved rectangle size.
274 // normalRect seems to be a substitute for windowRect when iconized or maximised.
275
276 // Windows can say that we are off screen when actually we are not.
277 // On Windows 10 I am seeing miscalculation by about 6 pixels.
278 // To fix this we allow some sloppiness on the edge being counted as off screen.
279 // This matters most when restoring very carefully sized windows that are maximised
280 // in one dimension (height or width) but not both.
281 const int edgeSlop = 10;
282
283 // Next four lines are getting the rectangle for the screen that contains the
284 // top left corner of nextRect (and defaulting to rect of screen 0 otherwise).
285 wxPoint p = nextRect->GetLeftTop();
286 int scr = std::max( 0, wxDisplay::GetFromPoint( p ));
287 wxDisplay d( scr );
288 screenRect = d.GetClientArea();
289
290 // Now we (possibly) start trimming our rectangle down.
291 // Have we hit the right side of the screen?
292 wxPoint bottomRight = nextRect->GetBottomRight();
293 if (bottomRight.x > (screenRect.GetRight()+edgeSlop)) {
294 int newWidth = screenRect.GetWidth() - nextRect->GetLeft();
295 if (newWidth < defaultRect.GetWidth()) {
296 nextRect->x = windowRect.x;
297 nextRect->y = windowRect.y;
298 nextRect->width = windowRect.width;
299 }
300 else {
301 nextRect->width = newWidth;
302 }
303 }
304
305 // Have we hit the bottom of the screen?
306 bottomRight = nextRect->GetBottomRight();
307 if (bottomRight.y > (screenRect.GetBottom()+edgeSlop)) {
308 nextRect->y -= inc;
309 bottomRight = nextRect->GetBottomRight();
310 if (bottomRight.y > (screenRect.GetBottom()+edgeSlop)) {
311 nextRect->SetBottom(screenRect.GetBottom());
312 }
313 }
314
315 // After all that we could have a window that does not have a visible
316 // top bar. [It is unlikely, but something might have gone wrong]
317 // If so, use the safe fallback size.
318 if (!IsWindowAccessible(nextRect)) {
319 *nextRect = defaultRect;
320 }
321}
IntSetting ProjectWindowY
bool CornersOnScreen(wxRect &r)
IntSetting ProjectWindowX
void GetDefaultWindowRect(wxRect *defRect)
IntSetting ProjectWindowWidth
BoolSetting ProjectWindowIconized
bool IsWindowAccessible(wxRect *requestedRect)
BoolSetting ProjectWindowMaximized
IntSetting ProjectWindowNormalHeight
IntSetting ProjectWindowHeight
IntSetting ProjectWindowNormalX
int ScreenContaining(wxRect &r)
IntSetting ProjectWindowNormalWidth
IntSetting ProjectWindowNormalY
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 ...
const_reverse_iterator rend() const
Definition: Project.cpp:37
const_reverse_iterator rbegin() const
Definition: Project.cpp:32
bool empty() const
Definition: Project.h:47
A top-level window associated with a project, and handling scrollbars and zooming.
Definition: ProjectWindow.h:36
static ProjectWindow & Get(AudacityProject &project)
bool IsIconized() const override
bool ReadWithDefault(T *pVar, const T &defaultValue) const
overload of ReadWithDefault returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:211
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:205
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References CornersOnScreen(), AllProjects::empty(), PackedArray::end(), ProjectWindow::Get(), GetDefaultWindowRect(), GetProjectFrame(), ProjectWindow::IsIconized(), IsWindowAccessible(), ProjectWindowHeight, ProjectWindowIconized, ProjectWindowMaximized, ProjectWindowNormalHeight, ProjectWindowNormalWidth, ProjectWindowNormalX, ProjectWindowNormalY, ProjectWindowWidth, ProjectWindowX, ProjectWindowY, AllProjects::rbegin(), Setting< T >::Read(), Setting< T >::ReadWithDefault(), AllProjects::rend(), and ScreenContaining().

Referenced by AudacityApp::InitPart2(), and ProjectManager::New().

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

◆ InitProjectWindow()

void InitProjectWindow ( ProjectWindow window)

Definition at line 161 of file ProjectManager.cpp.

162{
163 auto pProject = window.FindProject();
164 if (!pProject)
165 return;
166 auto &project = *pProject;
167 auto &viewport = Viewport::Get(project);
168
169#ifdef EXPERIMENTAL_DA2
170 SetBackgroundColour(theTheme.Colour( clrMedium ));
171#endif
172 // Note that the first field of the status bar is a dummy, and its width is set
173 // to zero latter in the code. This field is needed for wxWidgets 2.8.12 because
174 // if you move to the menu bar, the first field of the menu bar is cleared, which
175 // is undesirable behaviour.
176 // In addition, the help strings of menu items are by default sent to the first
177 // field. Currently there are no such help strings, but it they were introduced, then
178 // there would need to be an event handler to send them to the appropriate field.
179 auto statusBar = window.CreateStatusBar(4);
180#if wxUSE_ACCESSIBILITY
181 // so that name can be set on a standard control
182 statusBar->SetAccessible(safenew WindowAccessible(statusBar));
183#endif
184 statusBar->SetName(wxT("status_line")); // not localized
185
186 auto &viewInfo = ViewInfo::Get( project );
187
188 // LLL: Read this!!!
189 //
190 // Until the time (and cpu) required to refresh the track panel is
191 // reduced, leave the following window creations in the order specified.
192 // This will place the refresh of the track panel last, allowing all
193 // the others to get done quickly.
194 //
195 // Near as I can tell, this is only a problem under Windows.
196 //
197
198 //
199 // Create the ToolDock
200 //
203
204 //
205 // Create the TrackPanel and the scrollbars
206 //
207
208 auto topPanel = window.GetTopPanel();
209
210 {
211 auto ubs = std::make_unique<wxBoxSizer>(wxVERTICAL);
212 ubs->Add( ToolManager::Get( project ).GetTopDock(), 0, wxEXPAND | wxALIGN_TOP );
213 topPanel->SetSizer(ubs.release());
214 }
215
216 wxBoxSizer *bs;
217 {
218 auto ubs = std::make_unique<wxBoxSizer>(wxVERTICAL);
219 bs = ubs.get();
220 bs->Add(topPanel, 0, wxEXPAND | wxALIGN_TOP);
221 bs->Add(window.GetContainerWindow(), 1, wxEXPAND);
222 bs->Add( ToolManager::Get( project ).GetBotDock(), 0, wxEXPAND );
223 window.SetAutoLayout(true);
224 window.SetSizer(ubs.release());
225 }
226 bs->Layout();
227
228 auto &trackPanel = TrackPanel::Get( project );
229
230 // LLL: When Audacity starts or becomes active after returning from
231 // another application, the first window that can accept focus
232 // will be given the focus even if we try to SetFocus(). By
233 // making the TrackPanel that first window, we resolve several
234 // keyboard focus problems.
235 window.GetContainerWindow()->MoveAfterInTabOrder(topPanel);
236
237 const auto trackListWindow = window.GetTrackListWindow();
238
239 //
240 // Create the horizontal ruler
241 //
243
244 bs = static_cast<wxBoxSizer*>(trackListWindow->GetSizer());
245
246 auto vsBar = &window.GetVerticalScrollBar();
247 auto hsBar = &window.GetHorizontalScrollBar();
248
249 {
250 // Top horizontal grouping
251 auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
252
253 // Track panel
254 hs->Add(&trackPanel, 1, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP);
255
256 {
257 // Vertical grouping
258 auto vs = std::make_unique<wxBoxSizer>(wxVERTICAL);
259
260 // Vertical scroll bar
261 vs->Add(vsBar, 1, wxEXPAND | wxALIGN_TOP);
262 hs->Add(vs.release(), 0, wxEXPAND | wxALIGN_TOP);
263 }
264
265 bs->Add(&ruler, 0, wxEXPAND | wxALIGN_TOP);
266 bs->Add(hs.release(), 1, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP);
267 }
268
269 {
270 // Bottom horizontal grouping
271 auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
272
273 // Bottom scrollbar
274 hs->Add(viewInfo.GetLeftOffset() - 1, 0);
275 hs->Add(hsBar, 1, wxALIGN_BOTTOM);
276 hs->Add(vsBar->GetSize().GetWidth(), 0);
277 bs->Add(hs.release(), 0, wxEXPAND | wxALIGN_LEFT);
278 }
279
280 // Lay it out
281 trackListWindow->SetAutoLayout(true);
282 trackListWindow->Layout();
283
284 wxASSERT( trackPanel.GetProject() == &project );
285
286 // MM: Give track panel the focus to ensure keyboard commands work
287 trackPanel.SetFocus();
288
289 viewport.UpdateScrollbarsForTracks();
290 ruler.SetLeftOffset(viewInfo.GetLeftOffset()); // bevel on AdornedRuler
291
292 //
293 // Set the Icon
294 //
295
296 // loads either the XPM or the windows resource, depending on the platform
297#if !defined(__WXMAC__) && !defined(__WXX11__)
298 {
299#if defined(__WXMSW__)
300 wxIcon ic{ wxICON(AudacityLogo) };
301#elif defined(__WXGTK__)
302 wxIcon ic{wxICON(AudacityLogoAlpha)};
303#else
304 wxIcon ic{};
305 ic.CopyFromBitmap(theTheme.Bitmap(bmpAudacityLogo48x48));
306#endif
307 window.SetIcon(ic);
308 }
309#endif
310
311 window.UpdateStatusWidths();
312 auto msg = XO("Welcome to Audacity version %s")
313 .Format( AUDACITY_VERSION_STRING );
315
316#ifdef EXPERIMENTAL_DA2
317 ClearBackground();// For wxGTK.
318#endif
319}
wxT("CloseDown"))
XO("Cut/Copy/Paste")
#define safenew
Definition: MemoryX.h:10
@ mainStatusBarField
Definition: ProjectStatus.h:26
const auto project
THEME_API Theme theTheme
Definition: Theme.cpp:82
static AdornedRulerPanel & Get(AudacityProject &project)
static ProjectManager & Get(AudacityProject &project)
void SetStatusText(const TranslatableString &text, int number)
std::shared_ptr< AudacityProject > FindProject()
wxScrollBar & GetHorizontalScrollBar()
wxScrollBar & GetVerticalScrollBar()
wxPanel * GetTopPanel() noexcept
Top panel contains project-related controls and tools.
wxWindow * GetTrackListWindow() noexcept
Track list window is the parent container for TrackPanel.
wxSplitterWindow * GetContainerWindow() noexcept
Container is a parent window for both effects panel and track list windows.
void UpdateStatusWidths()
wxColour & Colour(int iIndex)
wxBitmap & Bitmap(int iIndex)
static ToolManager & Get(AudacityProject &project)
void CreateWindows()
void LayoutToolBars()
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:233
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:32
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...

References ThemeBase::Bitmap(), ThemeBase::Colour(), ToolManager::CreateWindows(), ProjectWindowBase::FindProject(), ViewInfo::Get(), Viewport::Get(), AdornedRulerPanel::Get(), ProjectManager::Get(), ToolManager::Get(), TrackPanel::Get(), ProjectWindow::GetContainerWindow(), ProjectWindow::GetHorizontalScrollBar(), ProjectWindow::GetTopPanel(), ProjectWindow::GetTrackListWindow(), ProjectWindow::GetVerticalScrollBar(), ToolManager::LayoutToolBars(), mainStatusBarField, project, anonymous_namespace{TimeTrackVRulerControls.cpp}::ruler(), safenew, ProjectManager::SetStatusText(), theTheme, ProjectWindow::UpdateStatusWidths(), wxT(), and XO().

Referenced by ProjectManager::New().

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

Variable Documentation

◆ ProjectWindowHeight

AUDACITY_DLL_API IntSetting ProjectWindowHeight
extern

◆ ProjectWindowIconized

AUDACITY_DLL_API BoolSetting ProjectWindowIconized
extern

◆ ProjectWindowMaximized

AUDACITY_DLL_API BoolSetting ProjectWindowMaximized
extern

◆ ProjectWindowNormalHeight

AUDACITY_DLL_API IntSetting ProjectWindowNormalHeight
extern

◆ ProjectWindowNormalWidth

AUDACITY_DLL_API IntSetting ProjectWindowNormalWidth
extern

◆ ProjectWindowNormalX

AUDACITY_DLL_API IntSetting ProjectWindowNormalX
extern

◆ ProjectWindowNormalY

AUDACITY_DLL_API IntSetting ProjectWindowNormalY
extern

◆ ProjectWindowWidth

AUDACITY_DLL_API IntSetting ProjectWindowWidth
extern

◆ ProjectWindowX

AUDACITY_DLL_API IntSetting ProjectWindowX
extern

◆ ProjectWindowY

AUDACITY_DLL_API IntSetting ProjectWindowY
extern