Audacity 3.2.0
Classes | Functions | Variables
ProjectWindow.h File Reference
#include <memory>
#include "ProjectWindowBase.h"
#include "TrackPanelListener.h"
#include "Prefs.h"
#include "Observer.h"
Include dependency graph for ProjectWindow.h:

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 122 of file ProjectWindow.cpp.

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

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

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

Here is the caller graph for this function:

◆ GetNextWindowPlacement()

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

Definition at line 169 of file ProjectWindow.cpp.

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

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

References ThemeBase::Bitmap(), ThemeBase::Colour(), ToolManager::CreateWindows(), ProjectWindowBase::FindProject(), ProjectWindow::FixScrollbars(), ViewInfo::Get(), AdornedRulerPanel::Get(), ProjectManager::Get(), ToolManager::Get(), TrackPanel::Get(), ProjectWindow::GetContainerWindow(), ProjectWindow::GetHorizontalScrollBar(), ProjectWindow::GetTopPanel(), ProjectWindow::GetTrackListWindow(), ProjectWindow::GetVerticalScrollBar(), ToolManager::LayoutToolBars(), mainStatusBarField, 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