]> git.saurik.com Git - wxWidgets.git/commitdiff
fix for [ 1020924 ] wx.Display.IsPrimary is wrong
authorRyan Norton <wxprojects@comcast.net>
Sun, 7 Nov 2004 00:48:37 +0000 (00:48 +0000)
committerRyan Norton <wxprojects@comcast.net>
Sun, 7 Nov 2004 00:48:37 +0000 (00:48 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30327 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/display.h
include/wx/msw/display.h
src/msw/display.cpp

index c080a21e2e228c9725a36aaabfa42d753d8eb052..b85a04471c4936c080cff0d166cb455a5dfd46c1 100644 (file)
@@ -67,8 +67,8 @@ public:
     // name may be empty
     virtual wxString GetName() const = 0;
 
-    // display 0 is always the primary display
-    bool IsPrimary() const { return m_index == 0; }
+    // display 0 is usually the primary display
+    virtual bool IsPrimary() const { return m_index == 0; }
 
 
     // enumerate all video modes supported by this display matching the given
index 598326e87aabc5f98a3229fe7a83a17f6b2c3858..b34635e90d8a4c18906eaf0dd55087b5eb78cb63 100644 (file)
@@ -38,6 +38,8 @@ public:
     virtual wxVideoMode GetCurrentMode() const;
     virtual bool ChangeMode(const wxVideoMode& mode = wxVideoMode());
 
+    virtual bool IsPrimary() const;
+
 private:
     // get the display name to use with EnumDisplaySettings()
     wxString GetNameForEnumSettings() const;
index ba43859eda2b1d62689e6a38f2c4163d3e9ca7d7..2933da9ef7f41422afbc7cad7d6b7e5285ff6ade 100644 (file)
@@ -1,7 +1,7 @@
 /////////////////////////////////////////////////////////////////////////////
 // Name:        display.cpp
 // Purpose:     MSW Implementation of wxDisplay class
-// Author:      Royce Mitchell III
+// Author:      Royce Mitchell III, Ryan Norton
 // Modified by: VZ (resolutions enumeration/change support, DirectDraw, ...)
 // Created:     06/21/02
 // RCS-ID:      $Id$
@@ -544,6 +544,30 @@ wxString wxDisplay::GetNameForEnumSettings() const
     return name;
 }
 
+// ----------------------------------------------------------------------------
+// determine if this is the primary display
+// ----------------------------------------------------------------------------
+
+bool wxDisplay::IsPrimary() const
+{
+    wxDisplayInfo& dpyInfo = (*gs_displays)[m_index];
+
+    MONITORINFOEX monInfo;
+    wxZeroMemory(monInfo);
+    monInfo.cbSize = sizeof(monInfo);
+
+    // NB: Cast from MONITORINFOEX* to MONITORINFO* is done because
+    //     Mingw headers - unlike the ones from Microsoft's Platform SDK -
+    //     don't derive the former from the latter in C++ mode and so
+    //     the pointer's type is not converted implicitly.
+    if ( !::GetMonitorInfo(dpyInfo.m_hmon, (LPMONITORINFO)&monInfo) )
+    {
+        wxLogLastError(_T("GetMonitorInfo"));
+    }
+
+    return (monInfo.dwFlags & MONITORINFOF_PRIMARY) == MONITORINFOF_PRIMARY;
+}
+
 // ----------------------------------------------------------------------------
 // video modes enumeration
 // ----------------------------------------------------------------------------