[Audacity-devel] wxGetClientDisplayRect
A free multi-track audio editor and recorder
Brought to you by:
aosiniao
From: Ed M. <edg...@ya...> - 2009-09-27 06:38:20
|
Delving into the source code for wxRect wxGetClientDisplayRect() I learned some interesting things. Given that my concern was solely with width and height, that is where I focused my inspection. I found that to determine width and height 2 conditions for the Microsoft case exist; for other platforms things are a little confusing to me. In file wx2.8.10\src\common\gdicmn.cpp (line 848): wxRect wxGetClientDisplayRect() { int x, y, width, height; wxClientDisplayRect(&x, &y, &width, &height); // call plat-specific version return wxRect(x, y, width, height); } and in file wx2.8.10\src\msw\utilsgui.cpp (line 337; i.e. building for msw): void wxClientDisplayRect(int *x, int *y, int *width, int *height) { #if defined(__WXMICROWIN__) *x = 0; *y = 0; wxDisplaySize(width, height); #else // Determine the desktop dimensions minus the taskbar and any other // special decorations... RECT r; SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0); if (x) *x = r.left; if (y) *y = r.top; if (width) *width = r.right - r.left; if (height) *height = r.bottom - r.top; #endif } and in file wx2.8.10\src\unix\displayx11.cpp (line 327): #if defined(__WXGTK__) || defined(__X__) [... at line 348]: // NB: this function is implemented using X11 and not GDK calls as it's shared // by wxGTK[12], wxX11 and wxMotif ports void wxClientDisplayRect(int *x, int *y, int *width, int *height) { Display * const dpy = (Display *)wxGetDisplay(); wxCHECK_RET( dpy, _T("can't be called before initializing the GUI") ); const Atom atomWorkArea = XInternAtom(dpy, "_NET_WORKAREA", True); if ( atomWorkArea ) { [...] if ( XGetWindowProperty ( [...] ) == Success && workareas ) { wxX11Ptr x11ptr(workareas); // ensure it will be freed [...] if ( actualType != XA_CARDINAL || format != 32 || numItems != 4 ) { wxLogDebug(_T("XGetWindowProperty(\"_NET_WORKAREA\") failed")); return; } [...] } } // if we get here, _NET_WORKAREA is not supported so return the entire // screen size as fall back [...] wxDisplaySize(width, height); } #else // !(wxGTK or X) void wxClientDisplayRect(int *x, int *y, int *width, int *height) { [...] wxDisplaySize(width, height); } #endif // wxGTK or X in file wx2.8.10\src\msw\utilsgui.cpp (line 278 -- note that as far as I can tell, this is the only definition and declaration of this function even though it's called in file wx2.8.10\src\unix\displayx11.cpp): // Get size of display void wxDisplaySize(int *width, int *height) { #ifdef __WXMICROWIN__ [...] if ( width ) *width = rect.right - rect.left; if ( height ) *height = rect.bottom - rect.top; #else // !__WXMICROWIN__ [...] if ( width ) *width = ::GetDeviceCaps(dc, HORZRES); if ( height ) *height = ::GetDeviceCaps(dc, VERTRES); #endif // __WXMICROWIN__/!__WXMICROWIN__ --------------------------------------------------------- Note that in file: Audacity 1.3.9b\src\Project.cpp(527): // BG: The default size and position of the first window void GetDefaultWindowRect(wxRect *defRect) { [527] *defRect = wxGetClientDisplayRect(); defRect->width = 600; defRect->height = 400; [...] which assumes the platform is capable of supporting a specified resolution. Please also note that in file wx2.8.10\src\unix\displayx11.cpp (line 389): wxLogDebug(_T("XGetWindowProperty(\"_NET_WORKAREA\") failed")); return; the function returns without setting any values for x, y, width or height and might better return a bool that a void. I suppose that needs to be taken up with the wxWidgets developers. Still, Audacity does rely on the x and y values being correctly filled out. In fileAudacity 1.3.9b\src\Project.cpp(line 54 7): wxRect defWndRect; [...] GetDefaultWindowRect(&defWndRect); relies on the default constructor: wxRect() : x(0), y(0), width(0), height(0) { } which at least seeds the values with a non-random number (0). As a sanity check Audacity might check the value of either width or height to ensure that it is not 0. -Ed Musgrove |