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

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

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

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