Browse Source

Initial fixes for window position at or beyond (0,0) under win32.

This is not the whole story, but is better.

We were messing up the initialisation of num_screens on Win32 in that
it was being set to a non-zero value by a call to 
GetSystemMetrics(SM_CMONITORS) but was then subsequently incremented
even higher by each iteration call to the screen_cb(...) function, 
so what we were storing for the screen rectangles was a bit messed up.

Under fltk-1.1, the code used to explicitly reset num_screens to zero
before starting to iterate the screen_cb(...) function, so that worked OK.

I have sort-of restored that behaviour, and removed the (now redundant)
call to GetSystemMetrics(SM_CMONITORS) since we *always* enumerate the 
monitors now to get the per-screen DPI values out.

I've also put in a commented out stub where we could store the per-screen 
work-area, which it seems we do also need now, though I have not yet 
contrived to actually implement that.
Volunteers welcomed...



git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8981 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
pull/49/head
Ian MacArthur 14 years ago
parent
commit
ce3185a94f
  1. 51
      src/screen_xywh.cxx

51
src/screen_xywh.cxx

@ -35,7 +35,7 @@ static int num_screens = -1;
// functions from the USER32.DLL . If these functions are not available, we // functions from the USER32.DLL . If these functions are not available, we
// will gracefully fall back to single monitor support. // will gracefully fall back to single monitor support.
// //
// If we were to insist on the existence of "EnumDisplayMonitors" and // If we were to insist on the existence of "EnumDisplayMonitors" and
// "GetMonitorInfoA", it would be impossible to use FLTK on Windows 2000 // "GetMonitorInfoA", it would be impossible to use FLTK on Windows 2000
// before SP2 or earlier. // before SP2 or earlier.
@ -59,7 +59,9 @@ static BOOL CALLBACK screen_cb(HMONITOR mon, HDC, LPRECT r, LPARAM) {
// (but we use our self-aquired function pointer instead) // (but we use our self-aquired function pointer instead)
if (fl_gmi(mon, &mi)) { if (fl_gmi(mon, &mi)) {
screens[num_screens] = mi.rcMonitor; screens[num_screens] = mi.rcMonitor;
// If we also want to record the work area, we would also store mi.rcWork at this point
// work_area[num_screens] = mi.rcWork;
// find the pixel size // find the pixel size
if (mi.cbSize == sizeof(mi)) { if (mi.cbSize == sizeof(mi)) {
HDC screen = CreateDC(mi.szDevice, NULL, NULL, NULL); HDC screen = CreateDC(mi.szDevice, NULL, NULL, NULL);
@ -69,14 +71,13 @@ static BOOL CALLBACK screen_cb(HMONITOR mon, HDC, LPRECT r, LPARAM) {
} }
ReleaseDC(0L, screen); ReleaseDC(0L, screen);
} }
num_screens ++; num_screens ++;
} }
return TRUE; return TRUE;
} }
static void screen_init() { static void screen_init() {
num_screens = 0;
// Since not all versions of Windows include multiple monitor support, // Since not all versions of Windows include multiple monitor support,
// we do a run-time check for the required functions... // we do a run-time check for the required functions...
HMODULE hMod = GetModuleHandle("USER32.DLL"); HMODULE hMod = GetModuleHandle("USER32.DLL");
@ -86,21 +87,17 @@ static void screen_init() {
fl_edm_func fl_edm = (fl_edm_func)GetProcAddress(hMod, "EnumDisplayMonitors"); fl_edm_func fl_edm = (fl_edm_func)GetProcAddress(hMod, "EnumDisplayMonitors");
if (fl_edm) { if (fl_edm) {
// We do have EnumDisplayMonitors, so lets find out how many monitors... // we have EnumDisplayMonitors - do we also have GetMonitorInfoA ?
num_screens = GetSystemMetrics(SM_CMONITORS); fl_gmi = (fl_gmi_func)GetProcAddress(hMod, "GetMonitorInfoA");
if (fl_gmi) {
// if (num_screens > 1) { // We have GetMonitorInfoA, enumerate all the screens...
// If there is more than 1 monitor, enumerate them... // EnumDisplayMonitors(0,0,screen_cb,0);
fl_gmi = (fl_gmi_func)GetProcAddress(hMod, "GetMonitorInfoA"); // (but we use our self-aquired function pointer instead)
// NOTE: num_screens is incremented in screen_cb so we must first reset it here...
if (fl_gmi) { num_screens = 0;
// We have GetMonitorInfoA, enumerate all the screens... fl_edm(0, 0, screen_cb, 0);
// EnumDisplayMonitors(0,0,screen_cb,0); return;
// (but we use our self-aquired function pointer instead) }
fl_edm(0, 0, screen_cb, 0);
return;
}
// }
} }
} }
@ -172,7 +169,7 @@ static void screen_init() {
int mm = DisplayWidthMM(fl_display, fl_screen); int mm = DisplayWidthMM(fl_display, fl_screen);
dpi[0] = mm ? Fl::w()*25.4f/mm : 0.0f; dpi[0] = mm ? Fl::w()*25.4f/mm : 0.0f;
mm = DisplayHeightMM(fl_display, fl_screen); mm = DisplayHeightMM(fl_display, fl_screen);
dpi[1] = mm ? Fl::h()*25.4f/mm : dpi[0]; dpi[1] = mm ? Fl::h()*25.4f/mm : dpi[0];
} }
#endif // WIN32 #endif // WIN32
@ -187,7 +184,7 @@ int Fl::screen_count() {
} }
/** /**
Gets the bounding box of a screen Gets the bounding box of a screen
that contains the specified screen position \p mx, \p my that contains the specified screen position \p mx, \p my
\param[out] X,Y,W,H the corresponding screen bounding box \param[out] X,Y,W,H the corresponding screen bounding box
\param[in] mx, my the absolute screen position \param[in] mx, my the absolute screen position
@ -211,10 +208,10 @@ void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my) {
} }
/** /**
Gets the screen bounding rect for the given screen. Gets the screen bounding rect for the given screen.
\param[out] X,Y,W,H the corresponding screen bounding box \param[out] X,Y,W,H the corresponding screen bounding box
\param[in] n the screen number (0 to Fl::screen_count() - 1) \param[in] n the screen number (0 to Fl::screen_count() - 1)
\see void screen_xywh(int &x, int &y, int &w, int &h, int mx, int my) \see void screen_xywh(int &x, int &y, int &w, int &h, int mx, int my)
*/ */
void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int n) { void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int n) {
if (num_screens < 0) screen_init(); if (num_screens < 0) screen_init();
@ -300,20 +297,20 @@ void Fl::screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int
} }
screen_xywh(X, Y, W, H, best_screen); screen_xywh(X, Y, W, H, best_screen);
} }
/** /**
Gets the screen resolution in dots-per-inch for the given screen. Gets the screen resolution in dots-per-inch for the given screen.
\param[out] h, v horizontal and vertical resolution \param[out] h, v horizontal and vertical resolution
\param[in] n the screen number (0 to Fl::screen_count() - 1) \param[in] n the screen number (0 to Fl::screen_count() - 1)
\see void screen_xywh(int &x, int &y, int &w, int &h, int mx, int my) \see void screen_xywh(int &x, int &y, int &w, int &h, int mx, int my)
*/ */
void Fl::screen_dpi(float &h, float &v, int n) void Fl::screen_dpi(float &h, float &v, int n)
{ {
if (num_screens < 0) screen_init(); if (num_screens < 0) screen_init();
h = v = 0.0f; h = v = 0.0f;
#ifdef WIN32 #ifdef WIN32
if (n >= 0 && n < num_screens) { if (n >= 0 && n < num_screens) {
h = float(dpi[n][0]); h = float(dpi[n][0]);

Loading…
Cancel
Save