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 "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 "widgets/wxPanelWrapper.h"
#include "widgets/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 = 1060
 
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 588 of file ProjectWindow.cpp.

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

Function Documentation

◆ CornersOnScreen()

bool CornersOnScreen ( wxRect &  r)

Definition at line 87 of file ProjectWindow.cpp.

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

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

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

◆ IsWindowAccessible()

bool IsWindowAccessible ( wxRect *  requestedRect)

Definition at line 94 of file ProjectWindow.cpp.

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

References monitor.

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

◆ ScreenContaining()

int ScreenContaining ( wxRect &  r)

Definition at line 72 of file ProjectWindow.cpp.

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

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

ToolManager::TopPanelHook::Scope scope
static
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 1982 of file ProjectWindow.cpp.