From 9abf8f797ffc6cdc57a2e2bce5ae5dd9d121f5e8 Mon Sep 17 00:00:00 2001 From: "mkaply%us.ibm.com" Date: Wed, 11 Jan 2006 21:27:53 +0000 Subject: [PATCH] #45872 r=mkaply, a=brendan Implement Screen and ScreenManager classes on OS/2 - not part of build yet --- widget/src/os2/nsScreenManagerOS2.cpp | 112 ++++++++++++++++++++++++++ widget/src/os2/nsScreenManagerOS2.h | 50 ++++++++++++ widget/src/os2/nsScreenOS2.cpp | 101 +++++++++++++++++++++++ widget/src/os2/nsScreenOS2.h | 43 ++++++++++ 4 files changed, 306 insertions(+) create mode 100644 widget/src/os2/nsScreenManagerOS2.cpp create mode 100644 widget/src/os2/nsScreenManagerOS2.h create mode 100644 widget/src/os2/nsScreenOS2.cpp create mode 100644 widget/src/os2/nsScreenOS2.h diff --git a/widget/src/os2/nsScreenManagerOS2.cpp b/widget/src/os2/nsScreenManagerOS2.cpp new file mode 100644 index 000000000000..4c777bca0994 --- /dev/null +++ b/widget/src/os2/nsScreenManagerOS2.cpp @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 2000 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsScreenManagerOS2.h" +#include "nsScreenOS2.h" + + +nsScreenManagerOS2 :: nsScreenManagerOS2 ( ) +{ + NS_INIT_REFCNT(); + + // 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. +} + + +nsScreenManagerOS2 :: ~nsScreenManagerOS2() +{ + // nothing to see here. +} + + +// addref, release, QI +NS_IMPL_ISUPPORTS(nsScreenManagerOS2, NS_GET_IID(nsIScreenManager)) + + +// +// CreateNewScreenObject +// +// Utility routine. Creates a new screen object from the given device handle +// +// NOTE: For this "single-monitor" impl, we just always return the cached primary +// screen. This should change when a multi-monitor impl is done. +// +nsIScreen* +nsScreenManagerOS2 :: CreateNewScreenObject ( ) +{ + nsIScreen* retval = nsnull; + if ( !mCachedMainScreen ) + mCachedMainScreen = new nsScreenOS2 ( ); + NS_IF_ADDREF(retval = mCachedMainScreen.get()); + + return retval; +} + + +// +// ScreenForRect +// +// Returns the screen that contains the rectangle. If the rect overlaps +// multiple screens, it picks the screen with the greatest area of intersection. +// +// The coordinates are in pixels (not twips) and in screen coordinates. +// +NS_IMETHODIMP +nsScreenManagerOS2 :: ScreenForRect ( PRInt32 /*inLeft*/, PRInt32 /*inTop*/, PRInt32 /*inWidth*/, + PRInt32 /*inHeight*/, nsIScreen **outScreen ) +{ + GetPrimaryScreen ( outScreen ); + return NS_OK; + +} // ScreenForRect + + +// +// GetPrimaryScreen +// +// The screen with the menubar/taskbar. This shouldn't be needed very +// often. +// +NS_IMETHODIMP +nsScreenManagerOS2 :: GetPrimaryScreen(nsIScreen * *aPrimaryScreen) +{ + *aPrimaryScreen = CreateNewScreenObject(); // addrefs + return NS_OK; + +} // GetPrimaryScreen + + +// +// GetNumberOfScreens +// +// Returns how many physical screens are available. +// +NS_IMETHODIMP +nsScreenManagerOS2 :: GetNumberOfScreens(PRUint32 *aNumberOfScreens) +{ + *aNumberOfScreens = 1; + return NS_OK; + +} // GetNumberOfScreens + diff --git a/widget/src/os2/nsScreenManagerOS2.h b/widget/src/os2/nsScreenManagerOS2.h new file mode 100644 index 000000000000..01726093cbbb --- /dev/null +++ b/widget/src/os2/nsScreenManagerOS2.h @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 2000 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef nsScreenManagerOS2_h___ +#define nsScreenManagerOS2_h___ + +#include "nsIScreenManager.h" +#include "nsIScreen.h" +#include "nsCOMPtr.h" + +//------------------------------------------------------------------------ + +class nsScreenManagerOS2 : public nsIScreenManager +{ +public: + nsScreenManagerOS2 ( ); + virtual ~nsScreenManagerOS2(); + + NS_DECL_ISUPPORTS + NS_DECL_NSISCREENMANAGER + +private: + + nsIScreen* CreateNewScreenObject ( ) ; + + // cache the primary screen object to avoid memory allocation every time + nsCOMPtr mCachedMainScreen; + +}; + +#endif // nsScreenManagerOS2_h___ diff --git a/widget/src/os2/nsScreenOS2.cpp b/widget/src/os2/nsScreenOS2.cpp new file mode 100644 index 000000000000..5137762ccc62 --- /dev/null +++ b/widget/src/os2/nsScreenOS2.cpp @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 2000 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsScreenOS2.h" + +#define INCL_PM +#include + + +nsScreenOS2 :: nsScreenOS2 ( ) +{ + NS_INIT_REFCNT(); + + // 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. +} + + +nsScreenOS2 :: ~nsScreenOS2() +{ + // nothing to see here. +} + + +// addref, release, QI +NS_IMPL_ISUPPORTS(nsScreenOS2, NS_GET_IID(nsIScreen)) + + +NS_IMETHODIMP +nsScreenOS2 :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight) +{ + *outTop = 0; + *outLeft = 0; + HDC hdc = WinQueryWindowDC(HWND_DESKTOP); + LONG alArray[2]; + DevQueryCaps(hdc, CAPS_HORIZONTAL_RESOLUTION, CAPS_VERTICAL_RESOLUTION, alArray); + + *outWidth = alArray[0]; + *outHeight = alArray[1]; + + return NS_OK; + +} // GetRect + + +NS_IMETHODIMP +nsScreenOS2 :: GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight) +{ + *outTop = 0; + *outLeft = 0; + *outWidth = WinQuerySysValue( HWND_DESKTOP, SV_CXFULLSCREEN ); + *outHeight = WinQuerySysValue( HWND_DESKTOP, SV_CYFULLSCREEN ); + + return NS_OK; + +} // GetAvailRect + + +NS_IMETHODIMP +nsScreenOS2 :: GetPixelDepth(PRInt32 *aPixelDepth) +{ + LONG lCap; + HDC hdc = WinQueryWindowDC(HWND_DESKTOP); + + DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, CAPS_COLOR_BITCOUNT, &lCap); + + *aPixelDepth = (PRInt32)lCap; + + return NS_OK; + +} // GetPixelDepth + + +NS_IMETHODIMP +nsScreenOS2 :: GetColorDepth(PRInt32 *aColorDepth) +{ + return GetPixelDepth ( aColorDepth ); + +} // GetColorDepth + + diff --git a/widget/src/os2/nsScreenOS2.h b/widget/src/os2/nsScreenOS2.h new file mode 100644 index 000000000000..7184c452708b --- /dev/null +++ b/widget/src/os2/nsScreenOS2.h @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 2000 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef nsScreenOS2_h___ +#define nsScreenOS2_h___ + +#include "nsIScreen.h" + +//------------------------------------------------------------------------ + +class nsScreenOS2 : public nsIScreen +{ +public: + nsScreenOS2 ( ); + virtual ~nsScreenOS2(); + + NS_DECL_ISUPPORTS + NS_DECL_NSISCREEN + +private: + +}; + +#endif // nsScreenOS2_h___