Single-monitor impl of screen manager/object for win32 just to get something in place. DevContext

now uses it, but will also have to be tweaked when the multi-monitor impl is implemented. Just
pushing code around for now, nothing major. r=danm.
This commit is contained in:
pinkerton%netscape.com 2000-03-17 04:15:39 +00:00
Родитель 02e9ece97d
Коммит b494f9b5e2
5 изменённых файлов: 61 добавлений и 56 удалений

Просмотреть файл

@ -26,6 +26,10 @@
#include "il_util.h"
#include "nsIPref.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
#include "nsIScreenManager.h"
#include "nsIScreen.h"
// Size of the color cube
#define COLOR_CUBE_SIZE 216
@ -145,13 +149,20 @@ void nsDeviceContextWin :: CommonInit(HDC aDC)
mHeightFloat = (float)mClientRect.height;
if (::GetDeviceCaps(aDC, TECHNOLOGY) == DT_RASDISPLAY)
{
RECT workArea;
::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
mClientRect.x = workArea.left;
mClientRect.y = workArea.top;
mClientRect.width = workArea.right - workArea.left;
mClientRect.height = workArea.bottom - workArea.top;
}
nsresult ignore;
nsCOMPtr<nsIScreenManager> sm ( do_GetService("component://netscape/gfx/screenmanager", &ignore) );
if ( sm ) {
//XXX rewrite this for multiple screens
nsCOMPtr<nsIScreen> screen;
sm->GetPrimaryScreen ( getter_AddRefs(screen) );
if ( screen ) {
screen->GetAvailTop ( &mClientRect.y );
screen->GetAvailLeft ( &mClientRect.x );
screen->GetAvailWidth ( &mClientRect.width );
screen->GetAvailHeight ( &mClientRect.height );
}
}
} // if this dc is not a print device
DeviceContextImpl::CommonInit();
}

Просмотреть файл

@ -50,9 +50,9 @@ NS_IMPL_ISUPPORTS(nsScreenManagerWin, NS_GET_IID(nsIScreenManager))
// Utility routine. Creates a new screen object from the given device handle
//
nsIScreen*
nsScreenManagerWin :: CreateNewScreenObject ( )
nsScreenManagerWin :: CreateNewScreenObject ( HDC inScreen )
{
nsIScreen* retval = new nsScreenWin ( );
nsIScreen* retval = new nsScreenWin ( inScreen );
NS_IF_ADDREF(retval);
return retval;
}
@ -70,34 +70,23 @@ NS_IMETHODIMP
nsScreenManagerWin :: ScreenForRect ( PRInt32 inTop, PRInt32 inLeft, PRInt32 inWidth, PRInt32 inHeight,
nsIScreen **outScreen )
{
#if 0
if ( !(inTop || inLeft || inWidth || inHeight) ) {
NS_WARNING ( "trying to find screen for sizeless window" );
*outScreen = CreateNewScreenObject ( ::GetMainDevice() ); // addrefs
if ( !(inWidth || inHeight) ) {
NS_WARNING ( "trying to find screen for sizeless window, using primary monitor" );
*outScreen = CreateNewScreenObject ( ::GetDC(nsnull) ); // addrefs
return NS_OK;
}
Rect globalWindowBounds = { inTop, inLeft, inTop + inHeight, inLeft + inWidth };
GDHandle currDevice = ::GetDeviceList();
GDHandle deviceWindowIsOn = ::GetMainDevice();
PRInt32 greatestArea = 0;
while ( currDevice ) {
if ( ::TestDeviceAttribute(currDevice, screenDevice) && ::TestDeviceAttribute(currDevice, screenActive) ) {
// calc the intersection.
Rect intersection;
Rect devRect = (**currDevice).gdRect;
::SectRect ( &globalWindowBounds, &devRect, &intersection );
PRInt32 intersectArea = (intersection.right - intersection.left) *
(intersection.bottom - intersection.top);
if ( intersectArea > greatestArea ) {
greatestArea = intersectArea;
deviceWindowIsOn = currDevice;
}
} // if device is a screen and visible
currDevice = ::GetNextDevice(currDevice);
} // foreach device in list
RECT globalWindowBounds = { inLeft, inTop, inLeft + inWidth, inTop + inHeight };
// we want to use ::MonitorFromRect() but it doesn't exist under 95/NT. For now, just
// always return the primary monitor.
*outScreen = CreateNewScreenObject ( ::GetDC(nsnull) ); // addrefs
#if 0
HMONITOR screen = ::MonitorFromRect ( &globalWindowBounds, MONITOR_DEFAULTTOPRIMARY );
*outScreen = CreateNewScreenObject ( deviceWindowIsOn ); // addrefs
#endif
return NS_OK;
@ -112,9 +101,9 @@ nsScreenManagerWin :: ScreenForRect ( PRInt32 inTop, PRInt32 inLeft, PRInt32 inW
// often.
//
NS_IMETHODIMP
nsScreenManagerWin :: GetPrimaryScreen(nsIScreen * *aPrimaryScreen)
nsScreenManagerWin :: GetPrimaryScreen(nsIScreen** aPrimaryScreen)
{
// *aPrimaryScreen = CreateNewScreenObject ( ::GetMainDevice() ); // addrefs
*aPrimaryScreen = CreateNewScreenObject ( ::GetDC(nsnull) ); // addrefs
return NS_OK;
} // GetPrimaryScreen

Просмотреть файл

@ -24,6 +24,7 @@
#define nsScreenManagerWin_h___
#include "nsIScreenManager.h"
#include <windows.h>
class nsIScreen;
@ -40,7 +41,7 @@ public:
private:
nsIScreen* CreateNewScreenObject ( ) ;
nsIScreen* CreateNewScreenObject ( HDC inScreen ) ;
};

Просмотреть файл

@ -23,12 +23,13 @@
#include "nsScreenWin.h"
nsScreenWin :: nsScreenWin ( )
// : mScreen(inScreen)
nsScreenWin :: nsScreenWin ( HDC inScreen )
: mScreen(inScreen)
{
NS_INIT_REFCNT();
//NS_ASSERTION ( inScreen, "Passing null device to nsScreenWin" );
NS_ASSERTION ( inScreen, "Passing null device to nsScreenWin" );
NS_ASSERTION ( ::GetDeviceCaps(inScreen, TECHNOLOGY) == DT_RASDISPLAY, "Not a display screen");
// 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
@ -49,7 +50,7 @@ NS_IMPL_ISUPPORTS(nsScreenWin, NS_GET_IID(nsIScreen))
NS_IMETHODIMP
nsScreenWin :: GetWidth(PRInt32 *aWidth)
{
//*aWidth = (**mScreen).gdRect.right - (**mScreen).gdRect.left;
*aWidth = ::GetDeviceCaps(mScreen, HORZRES);
return NS_OK;
} // GetWidth
@ -58,7 +59,7 @@ nsScreenWin :: GetWidth(PRInt32 *aWidth)
NS_IMETHODIMP
nsScreenWin :: GetHeight(PRInt32 *aHeight)
{
//*aHeight = (**mScreen).gdRect.bottom - (**mScreen).gdRect.top;
*aHeight = ::GetDeviceCaps(mScreen, VERTRES);
return NS_OK;
} // GetHeight
@ -67,7 +68,7 @@ nsScreenWin :: GetHeight(PRInt32 *aHeight)
NS_IMETHODIMP
nsScreenWin :: GetPixelDepth(PRInt32 *aPixelDepth)
{
//*aPixelDepth = (**(**mScreen).gdPMap).pixelSize;
*aPixelDepth = ::GetDeviceCaps(mScreen, BITSPIXEL);
return NS_OK;
} // GetPixelDepth
@ -76,8 +77,7 @@ nsScreenWin :: GetPixelDepth(PRInt32 *aPixelDepth)
NS_IMETHODIMP
nsScreenWin :: GetColorDepth(PRInt32 *aColorDepth)
{
//*aColorDepth = (**(**mScreen).gdPMap).pixelSize;
return NS_OK;
return GetPixelDepth(aColorDepth);
} // GetColorDepth
@ -85,7 +85,10 @@ nsScreenWin :: GetColorDepth(PRInt32 *aColorDepth)
NS_IMETHODIMP
nsScreenWin :: GetAvailWidth(PRInt32 *aAvailWidth)
{
GetWidth(aAvailWidth);
// XXX Needs to be rewritten for a non-primary monitor?
RECT workArea;
::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
*aAvailWidth = workArea.right - workArea.left;
return NS_OK;
} // GetAvailWidth
@ -94,10 +97,9 @@ nsScreenWin :: GetAvailWidth(PRInt32 *aAvailWidth)
NS_IMETHODIMP
nsScreenWin :: GetAvailHeight(PRInt32 *aAvailHeight)
{
//Rect adjustedRect;
//SubtractMenuBar ( (**mScreen).gdRect, &adjustedRect );
//*aAvailHeight = adjustedRect.bottom - adjustedRect.top;
RECT workArea;
::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
*aAvailHeight = workArea.bottom - workArea.top;
return NS_OK;
} // GetAvailHeight
@ -106,7 +108,9 @@ nsScreenWin :: GetAvailHeight(PRInt32 *aAvailHeight)
NS_IMETHODIMP
nsScreenWin :: GetAvailLeft(PRInt32 *aAvailLeft)
{
//*aAvailLeft = (**mScreen).gdRect.left;
RECT workArea;
::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
*aAvailLeft = workArea.left;
return NS_OK;
} // GetAvailLeft
@ -115,9 +119,9 @@ nsScreenWin :: GetAvailLeft(PRInt32 *aAvailLeft)
NS_IMETHODIMP
nsScreenWin :: GetAvailTop(PRInt32 *aAvailTop)
{
//Rect adjustedRect;
//SubtractMenuBar ( (**mScreen).gdRect, &adjustedRect );
//*aAvailTop = adjustedRect.top;
RECT workArea;
::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
*aAvailTop = workArea.top;
return NS_OK;

Просмотреть файл

@ -23,6 +23,7 @@
#ifndef nsScreenWin_h___
#define nsScreenWin_h___
#include <windows.h>
#include "nsIScreen.h"
//------------------------------------------------------------------------
@ -30,8 +31,7 @@
class nsScreenWin : public nsIScreen
{
public:
//nsScreenWin ( GDHandle inScreen );
nsScreenWin ( );
nsScreenWin ( HDC inScreen );
~nsScreenWin();
NS_DECL_ISUPPORTS
@ -43,7 +43,7 @@ private:
// asked.
//PRBool IsPrimaryScreen ( ) const { return (mScreen == ::GetMainDevice()); }
// GDHandle mScreen; // the device that represents this screen
HDC mScreen; // the dc that represents this screen
};
#endif // nsScreenWin_h___