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 "ProjectSnap.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/ChannelView.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 590 of file ProjectWindow.cpp.

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

Function Documentation

◆ CornersOnScreen()

bool CornersOnScreen ( wxRect &  r)

Definition at line 89 of file ProjectWindow.cpp.

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

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

◆ 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: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:

◆ IsWindowAccessible()

bool IsWindowAccessible ( wxRect *  requestedRect)

Definition at line 96 of file ProjectWindow.cpp.

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

References monitor.

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

◆ ScreenContaining()

int ScreenContaining ( wxRect &  r)

Definition at line 74 of file ProjectWindow.cpp.

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

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