Audacity 3.2.0
Classes | Namespaces | Enumerations | Functions | Variables
ProjectWindow.cpp File Reference
#include "ProjectWindow.h"
#include "ActiveProject.h"
#include "AllThemeResources.h"
#include "AudioIO.h"
#include "Menus.h"
#include "Project.h"
#include "ProjectAudioIO.h"
#include "ProjectFileIO.h"
#include "ProjectWindows.h"
#include "ProjectStatus.h"
#include "RefreshCode.h"
#include "TrackPanelMouseEvent.h"
#include "TrackPanelAx.h"
#include "UndoManager.h"
#include "ViewInfo.h"
#include "WaveClip.h"
#include "WaveTrack.h"
#include "commands/CommandContext.h"
#include "prefs/ThemePrefs.h"
#include "prefs/TracksPrefs.h"
#include "toolbars/ToolManager.h"
#include "tracks/ui/Scrubbing.h"
#include "tracks/ui/TrackView.h"
#include "wxPanelWrapper.h"
#include "WindowAccessible.h"
#include "ThemedWrappers.h"
#include <wx/app.h>
#include <wx/display.h>
#include <wx/scrolbar.h>
#include <wx/sizer.h>
#include <wx/splitter.h>
#include <wx/wupdlock.h>
#include "TrackPanel.h"
Include dependency graph for ProjectWindow.cpp:

Go to the source code of this file.

Classes

class  anonymous_namespace{ProjectWindow.cpp}::ScrollBar
 

Namespaces

namespace  anonymous_namespace{ProjectWindow.cpp}
 

Enumerations

enum  { FirstID = 1000 , HSBarID , VSBarID , NextID }
 

Functions

int ScreenContaining (wxRect &r)
 
bool CornersOnScreen (wxRect &r)
 
bool IsWindowAccessible (wxRect *requestedRect)
 
void GetDefaultWindowRect (wxRect *defRect)
 
void GetNextWindowPlacement (wxRect *nextRect, bool *pMaximized, bool *pIconized)
 

Variables

constexpr int anonymous_namespace{ProjectWindow.cpp}::DEFAULT_WINDOW_WIDTH = 1120
 
constexpr int anonymous_namespace{ProjectWindow.cpp}::DEFAULT_WINDOW_HEIGHT = 674
 
BoolSetting ProjectWindowMaximized { L"/Window/Maximized", false }
 
BoolSetting ProjectWindowIconized { L"/Window/Iconized", false }
 
IntSetting ProjectWindowX { L"/Window/X", 0 }
 
IntSetting ProjectWindowY { L"/Window/Y", 0 }
 
IntSetting ProjectWindowWidth { L"/Window/Width", DEFAULT_WINDOW_WIDTH }
 
IntSetting ProjectWindowHeight { L"/Window/Height", DEFAULT_WINDOW_HEIGHT }
 
IntSetting ProjectWindowNormalX { L"/Window/Normal_X", 0 }
 
IntSetting ProjectWindowNormalY { L"/Window/Normal_Y", 0 }
 
IntSetting ProjectWindowNormalWidth { L"/Window/Normal_Width", DEFAULT_WINDOW_WIDTH }
 
IntSetting ProjectWindowNormalHeight { L"/Window/Normal_Height", DEFAULT_WINDOW_HEIGHT }
 
static CommonTrackPanelCell::MouseWheelHook::Scope anonymous_namespace{ProjectWindow.cpp}::scope
 
AttachedWindows::RegisteredFactory anonymous_namespace{ProjectWindow.cpp}::sProjectWindowKey
 
const int sbarHjump = 30
 
static ToolManager::TopPanelHook::Scope scope
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FirstID 
HSBarID 
VSBarID 
NextID 

Definition at line 589 of file ProjectWindow.cpp.

589 {
590 FirstID = 1000,
591
592 // Window controls
593
594 HSBarID,
595 VSBarID,
596
597 NextID,
598};
@ VSBarID
@ HSBarID
@ NextID
@ FirstID

Function Documentation

◆ CornersOnScreen()

bool CornersOnScreen ( wxRect &  r)

Definition at line 88 of file ProjectWindow.cpp.

88 {
89 if( wxDisplay::GetFromPoint( r.GetTopLeft() ) == wxNOT_FOUND) return false;
90 if( wxDisplay::GetFromPoint( r.GetBottomRight() ) == wxNOT_FOUND) return false;
91 return true;
92}

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

◆ GetDefaultWindowRect()

void GetDefaultWindowRect ( wxRect *  defRect)

Definition at line 121 of file ProjectWindow.cpp.

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

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

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

◆ IsWindowAccessible()

bool IsWindowAccessible ( wxRect *  requestedRect)

Definition at line 95 of file ProjectWindow.cpp.

96{
97 wxDisplay display;
98 wxRect targetTitleRect(requestedRect->GetLeftTop(), requestedRect->GetBottomRight());
99 // Hackery to approximate a window top bar size from a window size.
100 // and exclude the open/close and borders.
101 targetTitleRect.x += 15;
102 targetTitleRect.width -= 100;
103 if (targetTitleRect.width < 165) targetTitleRect.width = 165;
104 targetTitleRect.height = 15;
105 int targetBottom = targetTitleRect.GetBottom();
106 int targetRight = targetTitleRect.GetRight();
107 // This looks like overkill to check each and every pixel in the ranges.
108 // and decide that if any is visible on screen we are OK.
109 for (int i = targetTitleRect.GetLeft(); i < targetRight; i++) {
110 for (int j = targetTitleRect.GetTop(); j < targetBottom; j++) {
111 int monitor = display.GetFromPoint(wxPoint(i, j));
112 if (monitor != wxNOT_FOUND) {
113 return TRUE;
114 }
115 }
116 }
117 return FALSE;
118}
EventMonitor monitor

References monitor.

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

◆ ScreenContaining()

int ScreenContaining ( wxRect &  r)

Definition at line 73 of file ProjectWindow.cpp.

73 {
74 unsigned int n = wxDisplay::GetCount();
75 for(unsigned int i = 0;i<n;i++){
76 wxDisplay d(i);
77 wxRect scr = d.GetClientArea();
78 if( scr.Contains( r ) )
79 return (int)i;
80 }
81 return -1;
82}

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

Variable Documentation

◆ ProjectWindowHeight

IntSetting ProjectWindowHeight { L"/Window/Height", DEFAULT_WINDOW_HEIGHT }

◆ ProjectWindowIconized

BoolSetting ProjectWindowIconized { L"/Window/Iconized", false }

◆ ProjectWindowMaximized

BoolSetting ProjectWindowMaximized { L"/Window/Maximized", false }

◆ ProjectWindowNormalHeight

IntSetting ProjectWindowNormalHeight { L"/Window/Normal_Height", DEFAULT_WINDOW_HEIGHT }

◆ ProjectWindowNormalWidth

IntSetting ProjectWindowNormalWidth { L"/Window/Normal_Width", DEFAULT_WINDOW_WIDTH }

◆ ProjectWindowNormalX

IntSetting ProjectWindowNormalX { L"/Window/Normal_X", 0 }

◆ ProjectWindowNormalY

IntSetting ProjectWindowNormalY { L"/Window/Normal_Y", 0 }

◆ ProjectWindowWidth

IntSetting ProjectWindowWidth { L"/Window/Width", DEFAULT_WINDOW_WIDTH }

◆ ProjectWindowX

IntSetting ProjectWindowX { L"/Window/X", 0 }

◆ ProjectWindowY

IntSetting ProjectWindowY { L"/Window/Y", 0 }

◆ sbarHjump

const int sbarHjump = 30

◆ scope

Initial value:
{
[]( wxWindow &window ){
auto pProjectWindow = dynamic_cast< ProjectWindow* >( &window );
return pProjectWindow ? pProjectWindow->GetTopPanel() : nullptr;
} }
wxPanel * GetTopPanel() noexcept
Top panel contains project-related controls and tools.

Definition at line 2011 of file ProjectWindow.cpp.