2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsScreenWin.h"
|
|
|
|
|
|
|
|
|
2012-01-04 23:52:22 -08:00
|
|
|
nsScreenWin :: nsScreenWin ( HMONITOR inScreen )
|
2007-03-22 10:30:00 -07:00
|
|
|
: mScreen(inScreen)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2012-07-30 07:20:58 -07:00
|
|
|
HDC hDCScreen = ::GetDC(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(hDCScreen,"GetDC Failure");
|
|
|
|
NS_ASSERTION ( ::GetDeviceCaps(hDCScreen, TECHNOLOGY) == DT_RASDISPLAY, "Not a display screen");
|
2012-07-30 07:20:58 -07:00
|
|
|
::ReleaseDC(nullptr,hDCScreen);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// nothing else to do. I guess we could cache a bunch of information
|
|
|
|
// here, but we want to ask the device at runtime in case anything
|
|
|
|
// has changed.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsScreenWin :: ~nsScreenWin()
|
|
|
|
{
|
|
|
|
// nothing to see here.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsScreenWin :: GetRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
BOOL success = FALSE;
|
|
|
|
if ( mScreen ) {
|
|
|
|
MONITORINFO info;
|
|
|
|
info.cbSize = sizeof(MONITORINFO);
|
2012-01-04 23:52:22 -08:00
|
|
|
success = ::GetMonitorInfoW( mScreen, &info );
|
2007-03-22 10:30:00 -07:00
|
|
|
if ( success ) {
|
|
|
|
*outLeft = info.rcMonitor.left;
|
|
|
|
*outTop = info.rcMonitor.top;
|
|
|
|
*outWidth = info.rcMonitor.right - info.rcMonitor.left;
|
|
|
|
*outHeight = info.rcMonitor.bottom - info.rcMonitor.top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!success) {
|
2012-07-30 07:20:58 -07:00
|
|
|
HDC hDCScreen = ::GetDC(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(hDCScreen,"GetDC Failure");
|
|
|
|
|
|
|
|
*outTop = *outLeft = 0;
|
|
|
|
*outWidth = ::GetDeviceCaps(hDCScreen, HORZRES);
|
|
|
|
*outHeight = ::GetDeviceCaps(hDCScreen, VERTRES);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
::ReleaseDC(nullptr, hDCScreen);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
} // GetRect
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsScreenWin :: GetAvailRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
BOOL success = FALSE;
|
2009-04-13 22:27:39 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ( mScreen ) {
|
|
|
|
MONITORINFO info;
|
|
|
|
info.cbSize = sizeof(MONITORINFO);
|
2012-01-04 23:52:22 -08:00
|
|
|
success = ::GetMonitorInfoW( mScreen, &info );
|
2007-03-22 10:30:00 -07:00
|
|
|
if ( success ) {
|
|
|
|
*outLeft = info.rcWork.left;
|
|
|
|
*outTop = info.rcWork.top;
|
|
|
|
*outWidth = info.rcWork.right - info.rcWork.left;
|
|
|
|
*outHeight = info.rcWork.bottom - info.rcWork.top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!success) {
|
|
|
|
RECT workArea;
|
|
|
|
::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
|
|
|
|
*outLeft = workArea.left;
|
|
|
|
*outTop = workArea.top;
|
|
|
|
*outWidth = workArea.right - workArea.left;
|
|
|
|
*outHeight = workArea.bottom - workArea.top;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
} // GetAvailRect
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsScreenWin :: GetPixelDepth(int32_t *aPixelDepth)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
//XXX not sure how to get this info for multiple monitors, this might be ok...
|
2012-07-30 07:20:58 -07:00
|
|
|
HDC hDCScreen = ::GetDC(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(hDCScreen,"GetDC Failure");
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t depth = ::GetDeviceCaps(hDCScreen, BITSPIXEL);
|
2008-12-23 06:06:56 -08:00
|
|
|
if (depth == 32) {
|
|
|
|
// If a device uses 32 bits per pixel, it's still only using 8 bits
|
|
|
|
// per color component, which is what our callers want to know.
|
|
|
|
// (Some devices report 32 and some devices report 24.)
|
|
|
|
depth = 24;
|
|
|
|
}
|
|
|
|
*aPixelDepth = depth;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
::ReleaseDC(nullptr, hDCScreen);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
} // GetPixelDepth
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsScreenWin :: GetColorDepth(int32_t *aColorDepth)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return GetPixelDepth(aColorDepth);
|
|
|
|
|
|
|
|
} // GetColorDepth
|
|
|
|
|
|
|
|
|