Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / widget / src / windows / nsScreenWin.cpp
blobf1bbe2a9c6d475c3a1d65a7bba931ce646261a7e
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2000
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
39 // We have to do this in order to have access to the multiple-monitor
40 // APIs that are only defined when WINVER is >= 0x0500. Don't worry,
41 // these won't actually be called unless they are present.
43 #undef WINVER
44 #define WINVER 0x0500
45 #undef _WIN32_WINNT
46 #define _WIN32_WINNT 0x0500
48 #include "nsScreenWin.h"
53 nsScreenWin :: nsScreenWin ( void* inScreen )
54 : mScreen(inScreen)
56 #ifdef DEBUG
57 HDC hDCScreen = ::GetDC(nsnull);
58 NS_ASSERTION(hDCScreen,"GetDC Failure");
59 NS_ASSERTION ( ::GetDeviceCaps(hDCScreen, TECHNOLOGY) == DT_RASDISPLAY, "Not a display screen");
60 ::ReleaseDC(nsnull,hDCScreen);
61 #endif
63 // nothing else to do. I guess we could cache a bunch of information
64 // here, but we want to ask the device at runtime in case anything
65 // has changed.
69 nsScreenWin :: ~nsScreenWin()
71 // nothing to see here.
75 // addref, release, QI
76 NS_IMPL_ISUPPORTS1(nsScreenWin, nsIScreen)
79 NS_IMETHODIMP
80 nsScreenWin :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
82 BOOL success = FALSE;
83 #if _MSC_VER >= 1200
84 if ( mScreen ) {
85 MONITORINFO info;
86 info.cbSize = sizeof(MONITORINFO);
87 success = ::GetMonitorInfoW( (HMONITOR)mScreen, &info );
88 if ( success ) {
89 *outLeft = info.rcMonitor.left;
90 *outTop = info.rcMonitor.top;
91 *outWidth = info.rcMonitor.right - info.rcMonitor.left;
92 *outHeight = info.rcMonitor.bottom - info.rcMonitor.top;
95 #endif
96 if (!success) {
97 HDC hDCScreen = ::GetDC(nsnull);
98 NS_ASSERTION(hDCScreen,"GetDC Failure");
100 *outTop = *outLeft = 0;
101 *outWidth = ::GetDeviceCaps(hDCScreen, HORZRES);
102 *outHeight = ::GetDeviceCaps(hDCScreen, VERTRES);
104 ::ReleaseDC(nsnull, hDCScreen);
106 return NS_OK;
108 } // GetRect
111 NS_IMETHODIMP
112 nsScreenWin :: GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
114 BOOL success = FALSE;
115 #if _MSC_VER >= 1200
116 if ( mScreen ) {
117 MONITORINFO info;
118 info.cbSize = sizeof(MONITORINFO);
119 success = ::GetMonitorInfoW( (HMONITOR)mScreen, &info );
120 if ( success ) {
121 *outLeft = info.rcWork.left;
122 *outTop = info.rcWork.top;
123 *outWidth = info.rcWork.right - info.rcWork.left;
124 *outHeight = info.rcWork.bottom - info.rcWork.top;
127 #endif
128 if (!success) {
129 RECT workArea;
130 ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
131 *outLeft = workArea.left;
132 *outTop = workArea.top;
133 *outWidth = workArea.right - workArea.left;
134 *outHeight = workArea.bottom - workArea.top;
137 return NS_OK;
139 } // GetAvailRect
143 NS_IMETHODIMP
144 nsScreenWin :: GetPixelDepth(PRInt32 *aPixelDepth)
146 //XXX not sure how to get this info for multiple monitors, this might be ok...
147 HDC hDCScreen = ::GetDC(nsnull);
148 NS_ASSERTION(hDCScreen,"GetDC Failure");
150 *aPixelDepth = ::GetDeviceCaps(hDCScreen, BITSPIXEL);
152 ::ReleaseDC(nsnull, hDCScreen);
153 return NS_OK;
155 } // GetPixelDepth
158 NS_IMETHODIMP
159 nsScreenWin :: GetColorDepth(PRInt32 *aColorDepth)
161 return GetPixelDepth(aColorDepth);
163 } // GetColorDepth