Fixed some issues found by winapi_check.
[wine/dcerpc.git] / windows / multimon.c
blob1b9617a91b7f134e0ba58b5d8e4f428e872c2d58
1 /*
2 * Multimonitor APIs
4 * Copyright 1998 Turchanov Sergey
5 */
7 #include "monitor.h"
8 #include "windef.h"
9 #include "wingdi.h"
10 #include "winbase.h"
11 #include "winuser.h"
13 /**********************************************************************/
15 MONITOR_DRIVER *MONITOR_Driver;
17 /**********************************************************************/
19 #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
21 MONITOR MONITOR_PrimaryMonitor;
23 /***********************************************************************
24 * MONITOR_GetMonitor
26 static MONITOR *MONITOR_GetMonitor(HMONITOR hMonitor)
28 if(hMonitor == xPRIMARY_MONITOR)
30 return &MONITOR_PrimaryMonitor;
32 else
34 return NULL;
38 /***********************************************************************
39 * MONITOR_Initialize
41 void MONITOR_Initialize(MONITOR *pMonitor)
43 MONITOR_Driver->pInitialize(pMonitor);
46 /***********************************************************************
47 * MONITOR_Finalize
49 void MONITOR_Finalize(MONITOR *pMonitor)
51 MONITOR_Driver->pFinalize(pMonitor);
54 /***********************************************************************
55 * MONITOR_IsSingleWindow
57 BOOL MONITOR_IsSingleWindow(MONITOR *pMonitor)
59 return MONITOR_Driver->pIsSingleWindow(pMonitor);
62 /***********************************************************************
63 * MONITOR_GetWidth
65 int MONITOR_GetWidth(MONITOR *pMonitor)
67 return MONITOR_Driver->pGetWidth(pMonitor);
70 /***********************************************************************
71 * MONITOR_GetHeight
73 int MONITOR_GetHeight(MONITOR *pMonitor)
75 return MONITOR_Driver->pGetHeight(pMonitor);
78 /***********************************************************************
79 * MONITOR_GetDepth
81 int MONITOR_GetDepth(MONITOR *pMonitor)
83 return MONITOR_Driver->pGetDepth(pMonitor);
86 /***********************************************************************
87 * MONITOR_GetScreenSaveActive
89 BOOL MONITOR_GetScreenSaveActive(MONITOR *pMonitor)
91 return MONITOR_Driver->pGetScreenSaveActive(pMonitor);
94 /***********************************************************************
95 * MONITOR_SetScreenSaveActive
97 void MONITOR_SetScreenSaveActive(MONITOR *pMonitor, BOOL bActivate)
99 MONITOR_Driver->pSetScreenSaveActive(pMonitor, bActivate);
102 /***********************************************************************
103 * MONITOR_GetScreenSaveTimeout
105 int MONITOR_GetScreenSaveTimeout(MONITOR *pMonitor)
107 return MONITOR_Driver->pGetScreenSaveTimeout(pMonitor);
110 /***********************************************************************
111 * MONITOR_SetScreenSaveTimeout
113 void MONITOR_SetScreenSaveTimeout(MONITOR *pMonitor, int nTimeout)
115 MONITOR_Driver->pSetScreenSaveTimeout(pMonitor, nTimeout);
119 /**********************************************************************/
121 HMONITOR WINAPI MonitorFromPoint(POINT ptScreenCoords, DWORD dwFlags)
123 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
124 ((ptScreenCoords.x >= 0) &&
125 (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
126 (ptScreenCoords.y >= 0) &&
127 (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
129 return xPRIMARY_MONITOR;
131 return NULL;
134 HMONITOR WINAPI MonitorFromRect(LPRECT lprcScreenCoords, DWORD dwFlags)
136 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
137 ((lprcScreenCoords->right > 0) &&
138 (lprcScreenCoords->bottom > 0) &&
139 (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
140 (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
142 return xPRIMARY_MONITOR;
144 return NULL;
147 HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
149 WINDOWPLACEMENT wp;
151 if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
152 return xPRIMARY_MONITOR;
154 if (IsIconic(hWnd) ?
155 GetWindowPlacement(hWnd, &wp) :
156 GetWindowRect(hWnd, &wp.rcNormalPosition)) {
158 return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
161 return NULL;
164 BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
166 RECT rcWork;
168 if ((hMonitor == xPRIMARY_MONITOR) &&
169 lpMonitorInfo &&
170 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
171 SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
173 lpMonitorInfo->rcMonitor.left = 0;
174 lpMonitorInfo->rcMonitor.top = 0;
175 lpMonitorInfo->rcMonitor.right = GetSystemMetrics(SM_CXSCREEN);
176 lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
177 lpMonitorInfo->rcWork = rcWork;
178 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
180 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
181 lstrcpyA(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
183 return TRUE;
186 return FALSE;
189 BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
191 RECT rcWork;
193 if ((hMonitor == xPRIMARY_MONITOR) &&
194 lpMonitorInfo &&
195 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
196 SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWork, 0))
198 lpMonitorInfo->rcMonitor.left = 0;
199 lpMonitorInfo->rcMonitor.top = 0;
200 lpMonitorInfo->rcMonitor.right = GetSystemMetrics(SM_CXSCREEN);
201 lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
202 lpMonitorInfo->rcWork = rcWork;
203 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
205 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
206 lstrcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, (LPCWSTR)"D\0I\0S\0P\0L\0A\0Y\0\0");
208 return TRUE;
211 return FALSE;
214 BOOL WINAPI EnumDisplayMonitors(
215 HDC hdcOptionalForPainting,
216 LPRECT lprcEnumMonitorsThatIntersect,
217 MONITORENUMPROC lpfnEnumProc,
218 LPARAM dwData)
220 RECT rcLimit;
222 if (!lpfnEnumProc)
223 return FALSE;
225 rcLimit.left = 0;
226 rcLimit.top = 0;
227 rcLimit.right = GetSystemMetrics(SM_CXSCREEN);
228 rcLimit.bottom = GetSystemMetrics(SM_CYSCREEN);
230 if (hdcOptionalForPainting)
232 RECT rcClip;
233 POINT ptOrg;
235 switch (GetClipBox(hdcOptionalForPainting, &rcClip))
237 default:
238 if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
239 return FALSE;
241 OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
242 if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
243 (!lprcEnumMonitorsThatIntersect ||
244 IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
246 break;
248 /*fall thru */
249 case NULLREGION:
250 return TRUE;
251 case ERROR:
252 return FALSE;
254 } else {
255 if ( lprcEnumMonitorsThatIntersect &&
256 !IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
258 return TRUE;
262 return lpfnEnumProc(
263 xPRIMARY_MONITOR,
264 hdcOptionalForPainting,
265 &rcLimit,
266 dwData);