No longer calling mm timers callbacks with mm timer crit sect locked.
[wine.git] / windows / multimon.c
blobe8b407a693977899ead7e1572471377cff4a2697
1 /*
2 * Multimonitor APIs
4 * Copyright 1998 Turchanov Sergey
5 */
7 #include "monitor.h"
8 #include "winbase.h"
9 #include "winuser.h"
11 /**********************************************************************/
13 MONITOR_DRIVER *MONITOR_Driver;
15 /**********************************************************************/
17 #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
19 MONITOR MONITOR_PrimaryMonitor;
21 /***********************************************************************
22 * MONITOR_GetMonitor
24 static MONITOR *MONITOR_GetMonitor(HMONITOR hMonitor)
26 if(hMonitor == xPRIMARY_MONITOR)
28 return &MONITOR_PrimaryMonitor;
30 else
32 return NULL;
36 /***********************************************************************
37 * MONITOR_Initialize
39 void MONITOR_Initialize(MONITOR *pMonitor)
41 MONITOR_Driver->pInitialize(pMonitor);
44 /***********************************************************************
45 * MONITOR_Finalize
47 void MONITOR_Finalize(MONITOR *pMonitor)
49 MONITOR_Driver->pFinalize(pMonitor);
52 /***********************************************************************
53 * MONITOR_IsSingleWindow
55 BOOL MONITOR_IsSingleWindow(MONITOR *pMonitor)
57 return MONITOR_Driver->pIsSingleWindow(pMonitor);
60 /***********************************************************************
61 * MONITOR_GetWidth
63 int MONITOR_GetWidth(MONITOR *pMonitor)
65 return MONITOR_Driver->pGetWidth(pMonitor);
68 /***********************************************************************
69 * MONITOR_GetHeight
71 int MONITOR_GetHeight(MONITOR *pMonitor)
73 return MONITOR_Driver->pGetHeight(pMonitor);
76 /***********************************************************************
77 * MONITOR_GetDepth
79 int MONITOR_GetDepth(MONITOR *pMonitor)
81 return MONITOR_Driver->pGetDepth(pMonitor);
84 /***********************************************************************
85 * MONITOR_GetScreenSaveActive
87 BOOL MONITOR_GetScreenSaveActive(MONITOR *pMonitor)
89 return MONITOR_Driver->pGetScreenSaveActive(pMonitor);
92 /***********************************************************************
93 * MONITOR_SetScreenSaveActive
95 void MONITOR_SetScreenSaveActive(MONITOR *pMonitor, BOOL bActivate)
97 MONITOR_Driver->pSetScreenSaveActive(pMonitor, bActivate);
100 /***********************************************************************
101 * MONITOR_GetScreenSaveTimeout
103 int MONITOR_GetScreenSaveTimeout(MONITOR *pMonitor)
105 return MONITOR_Driver->pGetScreenSaveTimeout(pMonitor);
108 /***********************************************************************
109 * MONITOR_SetScreenSaveTimeout
111 void MONITOR_SetScreenSaveTimeout(MONITOR *pMonitor, int nTimeout)
113 MONITOR_Driver->pSetScreenSaveTimeout(pMonitor, nTimeout);
117 /**********************************************************************/
119 HMONITOR WINAPI MonitorFromPoint(POINT ptScreenCoords, DWORD dwFlags)
121 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
122 ((ptScreenCoords.x >= 0) &&
123 (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
124 (ptScreenCoords.y >= 0) &&
125 (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
127 return xPRIMARY_MONITOR;
129 return NULL;
132 HMONITOR WINAPI MonitorFromRect(LPRECT lprcScreenCoords, DWORD dwFlags)
134 if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
135 ((lprcScreenCoords->right > 0) &&
136 (lprcScreenCoords->bottom > 0) &&
137 (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
138 (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
140 return xPRIMARY_MONITOR;
142 return NULL;
145 HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
147 WINDOWPLACEMENT wp;
149 if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
150 return xPRIMARY_MONITOR;
152 if (IsIconic(hWnd) ?
153 GetWindowPlacement(hWnd, &wp) :
154 GetWindowRect(hWnd, &wp.rcNormalPosition)) {
156 return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
159 return NULL;
162 BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
164 RECT rcWork;
166 if ((hMonitor == xPRIMARY_MONITOR) &&
167 lpMonitorInfo &&
168 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
169 SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
171 lpMonitorInfo->rcMonitor.left = 0;
172 lpMonitorInfo->rcMonitor.top = 0;
173 lpMonitorInfo->rcMonitor.right = GetSystemMetrics(SM_CXSCREEN);
174 lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
175 lpMonitorInfo->rcWork = rcWork;
176 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
178 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
179 lstrcpyA(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
181 return TRUE;
184 return FALSE;
187 BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
189 RECT rcWork;
191 if ((hMonitor == xPRIMARY_MONITOR) &&
192 lpMonitorInfo &&
193 (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
194 SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWork, 0))
196 lpMonitorInfo->rcMonitor.left = 0;
197 lpMonitorInfo->rcMonitor.top = 0;
198 lpMonitorInfo->rcMonitor.right = GetSystemMetrics(SM_CXSCREEN);
199 lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
200 lpMonitorInfo->rcWork = rcWork;
201 lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
203 if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
204 lstrcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, (LPCWSTR)"D\0I\0S\0P\0L\0A\0Y\0\0");
206 return TRUE;
209 return FALSE;
212 BOOL WINAPI EnumDisplayMonitors(
213 HDC hdcOptionalForPainting,
214 LPRECT lprcEnumMonitorsThatIntersect,
215 MONITORENUMPROC lpfnEnumProc,
216 LPARAM dwData)
218 RECT rcLimit;
220 if (!lpfnEnumProc)
221 return FALSE;
223 rcLimit.left = 0;
224 rcLimit.top = 0;
225 rcLimit.right = GetSystemMetrics(SM_CXSCREEN);
226 rcLimit.bottom = GetSystemMetrics(SM_CYSCREEN);
228 if (hdcOptionalForPainting)
230 RECT rcClip;
231 POINT ptOrg;
233 switch (GetClipBox(hdcOptionalForPainting, &rcClip))
235 default:
236 if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
237 return FALSE;
239 OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
240 if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
241 (!lprcEnumMonitorsThatIntersect ||
242 IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
244 break;
246 /*fall thru */
247 case NULLREGION:
248 return TRUE;
249 case ERROR:
250 return FALSE;
252 } else {
253 if ( lprcEnumMonitorsThatIntersect &&
254 !IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
256 return TRUE;
260 return lpfnEnumProc(
261 xPRIMARY_MONITOR,
262 hdcOptionalForPainting,
263 &rcLimit,
264 dwData);