screen manager and screen impls, first cut assuming only one monitor. make the dev context use them. r=pavlov.

This commit is contained in:
pinkerton%netscape.com 2000-03-17 06:09:24 +00:00
Родитель 5502d5ec20
Коммит 120e64e906
4 изменённых файлов: 40 добавлений и 76 удалений

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

@ -37,6 +37,9 @@
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include "nsIScreenManager.h"
#define NS_TO_GDK_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
#define GDK_COLOR_TO_NS_RGB(c) \
@ -80,12 +83,27 @@ nsDeviceContextGTK::~nsDeviceContextGTK()
NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget)
{
GdkVisual *vis;
GtkRequisition req;
GtkWidget *sb;
mWidget = aNativeWidget;
// get the screen object and its width/height
// XXXRight now this will only get the primary monitor.
nsresult ignore;
nsCOMPtr<nsIScreenManager> sm ( do_GetService("component://netscape/gfx/screenmanager", &ignore) );
if ( sm ) {
nsCOMPtr<nsIScreen> screen;
sm->GetPrimaryScreen ( getter_AddRefs(screen) );
if ( screen ) {
PRInt32 width, height, depth;
screen->GetAvailWidth ( &width );
screen->GetAvailHeight ( &height );
screen->GetPixelDepth ( &depth );
mWidthFloat = float(width);
mHeightFloat = float(height);
mDepth = NS_STATIC_CAST ( PRUint32, depth );
}
}
static int initialized = 0;
if (!initialized) {
initialized = 1;
@ -109,9 +127,8 @@ NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget)
}
// Set OSVal to what the operating system thinks the logical resolution is.
float screenWidth = float(::gdk_screen_width());
float screenWidthIn = float(::gdk_screen_width_mm()) / 25.4f;
PRInt32 OSVal = nscoord(screenWidth / screenWidthIn);
PRInt32 OSVal = nscoord(mWidthFloat / screenWidthIn);
if (prefVal > 0) {
// If there's a valid pref value for the logical resolution,
@ -130,9 +147,6 @@ NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget)
SetDPI(mDpi);
vis = gdk_rgb_get_visual();
mDepth = vis->depth;
sb = gtk_vscrollbar_new(NULL);
gtk_widget_ref(sb);
gtk_object_sink(GTK_OBJECT(sb));
@ -149,9 +163,6 @@ NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget)
gtk_widget_destroy(sb);
gtk_widget_unref(sb);
mWidthFloat = (float) gdk_screen_width();
mHeightFloat = (float) gdk_screen_height();
#ifdef DEBUG
static PRBool once = PR_TRUE;
if (once) {
@ -461,12 +472,7 @@ NS_IMETHODIMP nsDeviceContextGTK::EndPage(void)
NS_IMETHODIMP nsDeviceContextGTK::GetDepth(PRUint32& aDepth)
{
GdkVisual * rgb_visual = gdk_rgb_get_visual();
gint rgb_depth = rgb_visual->depth;
aDepth = (PRUint32) rgb_depth;
aDepth = mDepth;
return NS_OK;
}

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

@ -22,14 +22,14 @@
#include "nsScreenGtk.h"
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
nsScreenGtk :: nsScreenGtk ( )
// : mScreen(inScreen)
{
NS_INIT_REFCNT();
//NS_ASSERTION ( inScreen, "Passing null device to nsScreenGtk" );
// 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.
@ -49,7 +49,7 @@ NS_IMPL_ISUPPORTS(nsScreenGtk, NS_GET_IID(nsIScreen))
NS_IMETHODIMP
nsScreenGtk :: GetWidth(PRInt32 *aWidth)
{
//*aWidth = (**mScreen).gdRect.right - (**mScreen).gdRect.left;
*aWidth = gdk_screen_width();
return NS_OK;
} // GetWidth
@ -58,7 +58,7 @@ nsScreenGtk :: GetWidth(PRInt32 *aWidth)
NS_IMETHODIMP
nsScreenGtk :: GetHeight(PRInt32 *aHeight)
{
//*aHeight = (**mScreen).gdRect.bottom - (**mScreen).gdRect.top;
*aHeight = gdk_screen_height();
return NS_OK;
} // GetHeight
@ -67,7 +67,9 @@ nsScreenGtk :: GetHeight(PRInt32 *aHeight)
NS_IMETHODIMP
nsScreenGtk :: GetPixelDepth(PRInt32 *aPixelDepth)
{
//*aPixelDepth = (**(**mScreen).gdPMap).pixelSize;
GdkVisual * rgb_visual = gdk_rgb_get_visual();
*aPixelDepth = rgb_visual->depth;
return NS_OK;
} // GetPixelDepth
@ -76,8 +78,7 @@ nsScreenGtk :: GetPixelDepth(PRInt32 *aPixelDepth)
NS_IMETHODIMP
nsScreenGtk :: GetColorDepth(PRInt32 *aColorDepth)
{
//*aColorDepth = (**(**mScreen).gdPMap).pixelSize;
return NS_OK;
return GetPixelDepth ( aColorDepth );
} // GetColorDepth
@ -85,8 +86,7 @@ nsScreenGtk :: GetColorDepth(PRInt32 *aColorDepth)
NS_IMETHODIMP
nsScreenGtk :: GetAvailWidth(PRInt32 *aAvailWidth)
{
GetWidth(aAvailWidth);
return NS_OK;
return GetWidth(aAvailWidth);
} // GetAvailWidth
@ -94,11 +94,7 @@ nsScreenGtk :: GetAvailWidth(PRInt32 *aAvailWidth)
NS_IMETHODIMP
nsScreenGtk :: GetAvailHeight(PRInt32 *aAvailHeight)
{
//Rect adjustedRect;
//SubtractMenuBar ( (**mScreen).gdRect, &adjustedRect );
//*aAvailHeight = adjustedRect.bottom - adjustedRect.top;
return NS_OK;
return GetHeight(aAvailHeight);
} // GetAvailHeight
@ -106,7 +102,7 @@ nsScreenGtk :: GetAvailHeight(PRInt32 *aAvailHeight)
NS_IMETHODIMP
nsScreenGtk :: GetAvailLeft(PRInt32 *aAvailLeft)
{
//*aAvailLeft = (**mScreen).gdRect.left;
*aAvailLeft = 0;
return NS_OK;
} // GetAvailLeft
@ -115,10 +111,7 @@ nsScreenGtk :: GetAvailLeft(PRInt32 *aAvailLeft)
NS_IMETHODIMP
nsScreenGtk :: GetAvailTop(PRInt32 *aAvailTop)
{
//Rect adjustedRect;
//SubtractMenuBar ( (**mScreen).gdRect, &adjustedRect );
//*aAvailTop = adjustedRect.top;
*aAvailTop = 0;
return NS_OK;
} // GetAvailTop

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

@ -30,7 +30,6 @@
class nsScreenGtk : public nsIScreen
{
public:
//nsScreenGtk ( GDHandle inScreen );
nsScreenGtk ( );
virtual ~nsScreenGtk();
@ -39,11 +38,6 @@ public:
private:
// are we the primary screen? Needed so we can sub out the menubar if
// asked.
//PRBool IsPrimaryScreen ( ) const { return (mScreen == ::GetMainDevice()); }
// GDHandle mScreen; // the device that represents this screen
};
#endif // nsScreenGtk_h___

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

@ -67,39 +67,10 @@ nsScreenManagerGtk :: CreateNewScreenObject ( )
// The coordinates are in pixels (not twips) and in screen coordinates.
//
NS_IMETHODIMP
nsScreenManagerGtk :: ScreenForRect ( PRInt32 inTop, PRInt32 inLeft, PRInt32 inWidth, PRInt32 inHeight,
nsIScreen **outScreen )
nsScreenManagerGtk :: 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
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
*outScreen = CreateNewScreenObject ( deviceWindowIsOn ); // addrefs
#endif
GetPrimaryScreen ( outScreen );
return NS_OK;
} // ScreenForRect
@ -114,7 +85,7 @@ nsScreenManagerGtk :: ScreenForRect ( PRInt32 inTop, PRInt32 inLeft, PRInt32 inW
NS_IMETHODIMP
nsScreenManagerGtk :: GetPrimaryScreen(nsIScreen * *aPrimaryScreen)
{
// *aPrimaryScreen = CreateNewScreenObject ( ::GetMainDevice() ); // addrefs
*aPrimaryScreen = CreateNewScreenObject(); // addrefs
return NS_OK;
} // GetPrimaryScreen