Back to index

lightning-sunbird  0.9+nobinonly
nsScreenWin.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 //
00039 // We have to do this in order to have access to the multiple-monitor
00040 // APIs that are only defined when WINVER is >= 0x0500. Don't worry,
00041 // these won't actually be called unless they are present.
00042 //
00043 #undef WINVER
00044 #define WINVER 0x0500
00045 #undef _WIN32_WINNT
00046 #define _WIN32_WINNT 0x0500
00047 
00048 #include "nsScreenWin.h"
00049 
00050 
00051 // needed because there are unicode/ansi versions of this routine
00052 // and we need to make sure we get the correct one.
00053 #ifdef UNICODE
00054 #define GetMonitorInfoQuoted "GetMonitorInfoW"
00055 #else
00056 #define GetMonitorInfoQuoted "GetMonitorInfoA"
00057 #endif
00058 
00059 
00060 #if _MSC_VER >= 1200
00061 typedef BOOL (WINAPI *GetMonitorInfoProc)(HMONITOR inMon, LPMONITORINFO ioInfo); 
00062 #endif
00063 
00064 
00065 nsScreenWin :: nsScreenWin ( void* inScreen )
00066   : mScreen(inScreen), mHasMultiMonitorAPIs(PR_FALSE),
00067       mGetMonitorInfoProc(nsnull)
00068 {
00069 #ifdef DEBUG
00070   HDC hDCScreen = ::GetDC(nsnull);
00071   NS_ASSERTION(hDCScreen,"GetDC Failure");
00072   NS_ASSERTION ( ::GetDeviceCaps(hDCScreen, TECHNOLOGY) == DT_RASDISPLAY, "Not a display screen");
00073   ::ReleaseDC(nsnull,hDCScreen);
00074 #endif
00075    
00076 #if _MSC_VER >= 1200
00077   // figure out if we can call the multiple monitor APIs that are only
00078   // available on Win98/2000.
00079   HMODULE lib = GetModuleHandle("user32.dll");
00080   if ( lib ) {
00081     mGetMonitorInfoProc = GetProcAddress ( lib, GetMonitorInfoQuoted );
00082     if ( mGetMonitorInfoProc )
00083       mHasMultiMonitorAPIs = PR_TRUE;
00084   }
00085 #endif
00086 
00087   // nothing else to do. I guess we could cache a bunch of information
00088   // here, but we want to ask the device at runtime in case anything
00089   // has changed.
00090 }
00091 
00092 
00093 nsScreenWin :: ~nsScreenWin()
00094 {
00095   // nothing to see here.
00096 }
00097 
00098 
00099 // addref, release, QI
00100 NS_IMPL_ISUPPORTS1(nsScreenWin, nsIScreen)
00101 
00102 
00103 NS_IMETHODIMP
00104 nsScreenWin :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
00105 {
00106   BOOL success = FALSE;
00107 #if _MSC_VER >= 1200
00108   if ( mScreen && mHasMultiMonitorAPIs ) {
00109     GetMonitorInfoProc proc = (GetMonitorInfoProc)mGetMonitorInfoProc;
00110     MONITORINFO info;
00111     info.cbSize = sizeof(MONITORINFO);
00112     success = (*proc)( (HMONITOR)mScreen, &info );
00113     if ( success ) {
00114       *outLeft = info.rcMonitor.left;
00115       *outTop = info.rcMonitor.top;
00116       *outWidth = info.rcMonitor.right - info.rcMonitor.left;
00117       *outHeight = info.rcMonitor.bottom - info.rcMonitor.top;
00118     }
00119   }
00120 #endif
00121   if (!success) {
00122      HDC hDCScreen = ::GetDC(nsnull);
00123      NS_ASSERTION(hDCScreen,"GetDC Failure");
00124     
00125      *outTop = *outLeft = 0;
00126      *outWidth = ::GetDeviceCaps(hDCScreen, HORZRES);
00127      *outHeight = ::GetDeviceCaps(hDCScreen, VERTRES); 
00128      
00129      ::ReleaseDC(nsnull, hDCScreen);
00130   }
00131   return NS_OK;
00132 
00133 } // GetRect
00134 
00135 
00136 NS_IMETHODIMP
00137 nsScreenWin :: GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
00138 {
00139   BOOL success = FALSE;
00140 #if _MSC_VER >= 1200
00141   if ( mScreen && mHasMultiMonitorAPIs ) {
00142     GetMonitorInfoProc proc = (GetMonitorInfoProc)mGetMonitorInfoProc;
00143     MONITORINFO info;
00144     info.cbSize = sizeof(MONITORINFO);
00145     success = (*proc)( (HMONITOR)mScreen, &info );
00146     if ( success ) {
00147       *outLeft = info.rcWork.left;
00148       *outTop = info.rcWork.top;
00149       *outWidth = info.rcWork.right - info.rcWork.left;
00150       *outHeight = info.rcWork.bottom - info.rcWork.top;
00151     }
00152   }
00153 #endif
00154   if (!success) {
00155     RECT workArea;
00156     ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
00157     *outLeft = workArea.left;
00158     *outTop = workArea.top;
00159     *outWidth = workArea.right - workArea.left;
00160     *outHeight = workArea.bottom - workArea.top;
00161   }
00162 
00163   return NS_OK;
00164   
00165 } // GetAvailRect
00166 
00167 
00168 
00169 NS_IMETHODIMP 
00170 nsScreenWin :: GetPixelDepth(PRInt32 *aPixelDepth)
00171 {
00172   //XXX not sure how to get this info for multiple monitors, this might be ok...
00173   HDC hDCScreen = ::GetDC(nsnull);
00174   NS_ASSERTION(hDCScreen,"GetDC Failure");
00175 
00176   *aPixelDepth = ::GetDeviceCaps(hDCScreen, BITSPIXEL);
00177 
00178   ::ReleaseDC(nsnull, hDCScreen);
00179   return NS_OK;
00180 
00181 } // GetPixelDepth
00182 
00183 
00184 NS_IMETHODIMP 
00185 nsScreenWin :: GetColorDepth(PRInt32 *aColorDepth)
00186 {
00187   return GetPixelDepth(aColorDepth);
00188 
00189 } // GetColorDepth
00190 
00191