X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/06efac1f8d6acde1610ba23a7b315ade8ed46679..d67fee71b8078272308e3d5601cf72c5e19e715b:/src/msw/display.cpp?ds=sidebyside diff --git a/src/msw/display.cpp b/src/msw/display.cpp index 28cc8067b8..6066895d21 100644 --- a/src/msw/display.cpp +++ b/src/msw/display.cpp @@ -3,9 +3,10 @@ // Purpose: MSW Implementation of wxDisplay class // Author: Royce Mitchell III // Modified by: VZ (resolutions enumeration/change support, DirectDraw, ...) +// Ryan Norton (IsPrimary override) // Created: 06/21/02 // RCS-ID: $Id$ -// Copyright: (c) wxWindows team +// Copyright: (c) wxWidgets team // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -17,7 +18,7 @@ // headers // --------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "display.h" #endif @@ -31,7 +32,9 @@ #if wxUSE_DISPLAY #ifndef WX_PRECOMP + #include "wx/app.h" #include "wx/dynarray.h" + #include "wx/frame.h" #endif #include "wx/dynload.h" @@ -53,6 +56,10 @@ #pragma warning(disable:4706) #endif +// with mingw32, we must include windows.h first and it doesn't hurt with other +// compilers +#include + #include #ifdef _MSC_VER @@ -166,10 +173,10 @@ static wxDisplayInfoArray *gs_displays = NULL; // ---------------------------------------------------------------------------- static BOOL CALLBACK wxmswMonitorEnumProc ( - HMONITOR hMonitor, // handle to display monitor - HDC hdcMonitor, // handle to monitor-appropriate device context (NULL) - LPRECT lprcMonitor, // pointer to monitor intersection rectangle - LPARAM dwData // data passed from EnumDisplayMonitors (unused) + HMONITOR hMonitor, // handle to display monitor + HDC WXUNUSED(hdcMonitor), // handle to monitor-appropriate device context + LPRECT lprcMonitor, // pointer to monitor intersection rectangle + LPARAM WXUNUSED(dwData) // data passed from EnumDisplayMonitors (unused) ) { wxDisplayInfo *info = new wxDisplayInfo(); @@ -193,9 +200,9 @@ static BOOL CALLBACK wxmswMonitorEnumProc ( BOOL PASCAL wxDDEnumExCallback(GUID *pGuid, - LPTSTR driverDescription, + LPTSTR WXUNUSED(driverDescription), LPTSTR driverName, - LPVOID lpContext, + LPVOID WXUNUSED(lpContext), HMONITOR hmon) { if ( pGuid ) @@ -214,11 +221,11 @@ wxDDEnumExCallback(GUID *pGuid, return true; } -HRESULT WINAPI wxDDEnumModesCallback(LPDDSURFACEDESC lpDDSurfaceDesc, +HRESULT WINAPI wxDDEnumModesCallback(LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext) { // we need at least the mode size - static const int FLAGS_REQUIRED = DDSD_HEIGHT | DDSD_WIDTH; + static const DWORD FLAGS_REQUIRED = DDSD_HEIGHT | DDSD_WIDTH; if ( (lpDDSurfaceDesc->dwFlags & FLAGS_REQUIRED) == FLAGS_REQUIRED ) { wxArrayVideoModes * const modes = (wxArrayVideoModes *)lpContext; @@ -240,12 +247,16 @@ HRESULT WINAPI wxDDEnumModesCallback(LPDDSURFACEDESC lpDDSurfaceDesc, // initialize gs_displays using DirectX functions static bool DoInitDirectX() { +#if wxUSE_LOG // suppress the errors if ddraw.dll is not found wxLog::EnableLogging(false); +#endif wxDynamicLibrary dllDX(_T("ddraw.dll")); - wxLog::EnableLogging(true); +#if wxUSE_LOG + wxLog::EnableLogging(); +#endif if ( !dllDX.IsLoaded() ) return false; @@ -297,7 +308,7 @@ static void InitDisplays() gs_displays = new wxDisplayInfoArray(); - if ( gs_useDirectX && !DoInitDirectX() ) + if ( !gs_useDirectX || !DoInitDirectX() ) { // either we were told not to try to use DirectX or fall back to std // functions if DirectX method failed @@ -505,7 +516,11 @@ wxString wxDisplay::GetName() const wxZeroMemory(monInfo); monInfo.cbSize = sizeof(monInfo); - if ( !::GetMonitorInfo(dpyInfo.m_hmon, &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")); } @@ -534,12 +549,36 @@ 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 // ---------------------------------------------------------------------------- wxArrayVideoModes -wxDisplay::DoGetModesDirectX(const wxVideoMode& modeMatch) const +wxDisplay::DoGetModesDirectX(const wxVideoMode& WXUNUSED(modeMatch)) const { wxArrayVideoModes modes; @@ -648,7 +687,7 @@ bool wxDisplay::DoChangeModeDirectX(const wxVideoMode& mode) return false; } - + return true; } @@ -729,6 +768,18 @@ bool wxDisplay::DoChangeModeWindows(const wxVideoMode& mode) { case DISP_CHANGE_SUCCESSFUL: // ok + { + // If we have a top-level, full-screen frame, emulate + // the DirectX behavior and resize it. This makes this + // API quite a bit easier to use. + wxWindow *winTop = wxTheApp->GetTopWindow(); + wxFrame *frameTop = wxDynamicCast(winTop, wxFrame); + if (frameTop && frameTop->IsFullScreen()) + { + wxVideoMode current = GetCurrentMode(); + frameTop->SetClientSize(current.w, current.h); + } + } return true; case DISP_CHANGE_BADMODE: