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 "tracks/ui/CommonTrackInfo.h"
#include "ProjectAudioIO.h"
#include "ProjectFileIO.h"
#include "ProjectWindows.h"
#include "ProjectStatus.h"
#include "ViewInfo.h"
#include "WaveClip.h"
#include "WaveTrack.h"
#include "CommandManager.h"
#include "prefs/ThemePrefs.h"
#include "prefs/TracksPrefs.h"
#include "toolbars/ToolManager.h"
#include "tracks/ui/ChannelView.h"
#include "wxPanelWrapper.h"
#include "WindowAccessible.h"
#include "ThemedWrappers.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
 
struct  anonymous_namespace{ProjectWindow.cpp}::Adapter
 

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 }
 
AttachedWindows::RegisteredFactory anonymous_namespace{ProjectWindow.cpp}::sProjectWindowKey
 
static ToolManager::TopPanelHook::Scope scope
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FirstID 
HSBarID 
VSBarID 
NextID 

Definition at line 435 of file ProjectWindow.cpp.

435 {
436 FirstID = 1000,
437
438 // Window controls
439
440 HSBarID,
441 VSBarID,
442
443 NextID,
444};
@ VSBarID
@ HSBarID
@ NextID
@ FirstID

Function Documentation

◆ CornersOnScreen()

bool CornersOnScreen ( wxRect &  r)

Definition at line 78 of file ProjectWindow.cpp.

78 {
79 if( wxDisplay::GetFromPoint( r.GetTopLeft() ) == wxNOT_FOUND) return false;
80 if( wxDisplay::GetFromPoint( r.GetBottomRight() ) == wxNOT_FOUND) return false;
81 return true;
82}

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

◆ GetDefaultWindowRect()

void GetDefaultWindowRect ( wxRect *  defRect)

Definition at line 111 of file ProjectWindow.cpp.

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

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

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

Here is the caller graph for this function:

◆ GetNextWindowPlacement()

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

Definition at line 158 of file ProjectWindow.cpp.

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

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

References monitor.

Referenced by GetNextWindowPlacement().

Here is the caller graph for this function:

◆ ScreenContaining()

int ScreenContaining ( wxRect &  r)

Definition at line 63 of file ProjectWindow.cpp.

63 {
64 unsigned int n = wxDisplay::GetCount();
65 for(unsigned int i = 0;i<n;i++){
66 wxDisplay d(i);
67 wxRect scr = d.GetClientArea();
68 if( scr.Contains( r ) )
69 return (int)i;
70 }
71 return -1;
72}

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 }

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