CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / widget / src / windows / nsScreenWin.cpp
blob481b24477f9cd9da59e3ae95297bbabc620bc57e
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"
50 #ifdef WINCE
51 #ifdef WINCE_WINDOWS_MOBILE
52 #include "sipapi.h"
53 #endif
54 #define GetMonitorInfoW GetMonitorInfo
55 #endif
58 nsScreenWin :: nsScreenWin ( void* inScreen )
59 : mScreen(inScreen)
61 #ifdef DEBUG
62 HDC hDCScreen = ::GetDC(nsnull);
63 NS_ASSERTION(hDCScreen,"GetDC Failure");
64 NS_ASSERTION ( ::GetDeviceCaps(hDCScreen, TECHNOLOGY) == DT_RASDISPLAY, "Not a display screen");
65 ::ReleaseDC(nsnull,hDCScreen);
66 #endif
68 // nothing else to do. I guess we could cache a bunch of information
69 // here, but we want to ask the device at runtime in case anything
70 // has changed.
74 nsScreenWin :: ~nsScreenWin()
76 // nothing to see here.
80 // addref, release, QI
81 NS_IMPL_ISUPPORTS1(nsScreenWin, nsIScreen)
84 NS_IMETHODIMP
85 nsScreenWin :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
87 BOOL success = FALSE;
88 #if _MSC_VER >= 1200
89 if ( mScreen ) {
90 MONITORINFO info;
91 info.cbSize = sizeof(MONITORINFO);
92 success = ::GetMonitorInfoW( (HMONITOR)mScreen, &info );
93 if ( success ) {
94 *outLeft = info.rcMonitor.left;
95 *outTop = info.rcMonitor.top;
96 *outWidth = info.rcMonitor.right - info.rcMonitor.left;
97 *outHeight = info.rcMonitor.bottom - info.rcMonitor.top;
100 #endif
101 if (!success) {
102 HDC hDCScreen = ::GetDC(nsnull);
103 NS_ASSERTION(hDCScreen,"GetDC Failure");
105 *outTop = *outLeft = 0;
106 *outWidth = ::GetDeviceCaps(hDCScreen, HORZRES);
107 *outHeight = ::GetDeviceCaps(hDCScreen, VERTRES);
109 ::ReleaseDC(nsnull, hDCScreen);
111 return NS_OK;
113 } // GetRect
116 NS_IMETHODIMP
117 nsScreenWin :: GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
119 BOOL success = FALSE;
120 #ifdef WINCE_WINDOWS_MOBILE
121 SIPINFO sipInfo;
122 memset(&sipInfo, 0, sizeof(SIPINFO));
123 sipInfo.cbSize = sizeof(SIPINFO);
124 if (SipGetInfo(&sipInfo) && !(sipInfo.fdwFlags & SIPF_OFF)) {
125 *outLeft = sipInfo.rcVisibleDesktop.left;
126 *outTop = sipInfo.rcVisibleDesktop.top;
127 *outWidth = sipInfo.rcVisibleDesktop.right - sipInfo.rcVisibleDesktop.left;
128 *outHeight = sipInfo.rcVisibleDesktop.bottom - sipInfo.rcVisibleDesktop.top;
129 return NS_OK;
131 #endif
133 #if _MSC_VER >= 1200
134 if ( mScreen ) {
135 MONITORINFO info;
136 info.cbSize = sizeof(MONITORINFO);
137 success = ::GetMonitorInfoW( (HMONITOR)mScreen, &info );
138 if ( success ) {
139 *outLeft = info.rcWork.left;
140 *outTop = info.rcWork.top;
141 *outWidth = info.rcWork.right - info.rcWork.left;
142 *outHeight = info.rcWork.bottom - info.rcWork.top;
145 #endif
146 if (!success) {
147 RECT workArea;
148 ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
149 *outLeft = workArea.left;
150 *outTop = workArea.top;
151 *outWidth = workArea.right - workArea.left;
152 *outHeight = workArea.bottom - workArea.top;
155 return NS_OK;
157 } // GetAvailRect
161 NS_IMETHODIMP
162 nsScreenWin :: GetPixelDepth(PRInt32 *aPixelDepth)
164 //XXX not sure how to get this info for multiple monitors, this might be ok...
165 HDC hDCScreen = ::GetDC(nsnull);
166 NS_ASSERTION(hDCScreen,"GetDC Failure");
168 PRInt32 depth = ::GetDeviceCaps(hDCScreen, BITSPIXEL);
169 if (depth == 32) {
170 // If a device uses 32 bits per pixel, it's still only using 8 bits
171 // per color component, which is what our callers want to know.
172 // (Some devices report 32 and some devices report 24.)
173 depth = 24;
175 *aPixelDepth = depth;
177 ::ReleaseDC(nsnull, hDCScreen);
178 return NS_OK;
180 } // GetPixelDepth
183 NS_IMETHODIMP
184 nsScreenWin :: GetColorDepth(PRInt32 *aColorDepth)
186 return GetPixelDepth(aColorDepth);
188 } // GetColorDepth