Misc. fixes for compiler warnings.
[wine] / windows / multimon.c
1 /*
2  * Multimonitor APIs
3  *
4  * Copyright 1998 Turchanov Sergey
5  */
6
7 #include "monitor.h"
8 #include "windef.h"
9 #include "wingdi.h"
10 #include "winbase.h"
11 #include "winuser.h"
12
13 /**********************************************************************/
14
15 MONITOR_DRIVER *MONITOR_Driver;
16
17 /**********************************************************************/
18
19 #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
20
21 MONITOR MONITOR_PrimaryMonitor;
22
23 /***********************************************************************
24  *              MONITOR_GetMonitor
25  */
26 #if 0
27 static MONITOR *MONITOR_GetMonitor(HMONITOR hMonitor)
28 {
29   if(hMonitor == xPRIMARY_MONITOR)
30     {
31       return &MONITOR_PrimaryMonitor;
32     }
33   else
34     {
35       return NULL;
36     }
37 }
38 #endif
39
40 /***********************************************************************
41  *              MONITOR_Initialize
42  */
43 void MONITOR_Initialize(MONITOR *pMonitor)
44 {
45   MONITOR_Driver->pInitialize(pMonitor);
46 }
47
48 /***********************************************************************
49  *              MONITOR_Finalize
50  */
51 void MONITOR_Finalize(MONITOR *pMonitor)
52 {
53   MONITOR_Driver->pFinalize(pMonitor);
54 }
55
56 /***********************************************************************
57  *              MONITOR_IsSingleWindow
58  */
59 BOOL MONITOR_IsSingleWindow(MONITOR *pMonitor)
60 {
61   return MONITOR_Driver->pIsSingleWindow(pMonitor);
62 }
63
64 /***********************************************************************
65  *              MONITOR_GetWidth
66  */
67 int MONITOR_GetWidth(MONITOR *pMonitor)
68 {
69   return MONITOR_Driver->pGetWidth(pMonitor);
70 }
71
72 /***********************************************************************
73  *              MONITOR_GetHeight
74  */
75 int MONITOR_GetHeight(MONITOR *pMonitor)
76 {
77   return MONITOR_Driver->pGetHeight(pMonitor);
78 }
79
80 /***********************************************************************
81  *              MONITOR_GetDepth
82  */
83 int MONITOR_GetDepth(MONITOR *pMonitor)
84 {
85   return MONITOR_Driver->pGetDepth(pMonitor);
86 }
87
88 /***********************************************************************
89  *              MONITOR_GetScreenSaveActive
90  */
91 BOOL MONITOR_GetScreenSaveActive(MONITOR *pMonitor)
92 {
93   return MONITOR_Driver->pGetScreenSaveActive(pMonitor);
94 }
95
96 /***********************************************************************
97  *              MONITOR_SetScreenSaveActive
98  */
99 void MONITOR_SetScreenSaveActive(MONITOR *pMonitor, BOOL bActivate)
100 {
101   MONITOR_Driver->pSetScreenSaveActive(pMonitor, bActivate);
102 }
103
104 /***********************************************************************
105  *              MONITOR_GetScreenSaveTimeout
106  */
107 int MONITOR_GetScreenSaveTimeout(MONITOR *pMonitor)
108 {
109   return MONITOR_Driver->pGetScreenSaveTimeout(pMonitor);
110 }
111
112 /***********************************************************************
113  *              MONITOR_SetScreenSaveTimeout
114  */
115 void MONITOR_SetScreenSaveTimeout(MONITOR *pMonitor, int nTimeout)
116 {
117   MONITOR_Driver->pSetScreenSaveTimeout(pMonitor, nTimeout);
118 }
119
120
121 /**********************************************************************/
122
123 HMONITOR WINAPI MonitorFromPoint(POINT ptScreenCoords, DWORD dwFlags)
124 {
125     if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
126         ((ptScreenCoords.x >= 0) &&
127         (ptScreenCoords.x < GetSystemMetrics(SM_CXSCREEN)) &&
128         (ptScreenCoords.y >= 0) &&
129         (ptScreenCoords.y < GetSystemMetrics(SM_CYSCREEN))))
130     {
131         return xPRIMARY_MONITOR;
132     }
133         return NULL;
134 }
135
136 HMONITOR WINAPI MonitorFromRect(LPRECT lprcScreenCoords, DWORD dwFlags)
137 {
138     if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
139         ((lprcScreenCoords->right > 0) &&
140         (lprcScreenCoords->bottom > 0) &&
141         (lprcScreenCoords->left < GetSystemMetrics(SM_CXSCREEN)) &&
142         (lprcScreenCoords->top < GetSystemMetrics(SM_CYSCREEN))))
143     {
144         return xPRIMARY_MONITOR;
145     }
146     return NULL;
147 }
148
149 HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
150 {
151     WINDOWPLACEMENT wp;
152
153     if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
154         return xPRIMARY_MONITOR;
155
156     if (IsIconic(hWnd) ? 
157             GetWindowPlacement(hWnd, &wp) : 
158             GetWindowRect(hWnd, &wp.rcNormalPosition)) {
159
160         return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
161     }
162
163     return NULL;
164 }
165
166 BOOL WINAPI GetMonitorInfoA(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
167 {
168     RECT rcWork;
169
170     if ((hMonitor == xPRIMARY_MONITOR) &&
171         lpMonitorInfo &&
172         (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
173         SystemParametersInfoA(SPI_GETWORKAREA, 0, &rcWork, 0))
174     {
175         lpMonitorInfo->rcMonitor.left = 0;
176         lpMonitorInfo->rcMonitor.top  = 0;
177         lpMonitorInfo->rcMonitor.right  = GetSystemMetrics(SM_CXSCREEN);
178         lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
179         lpMonitorInfo->rcWork = rcWork;
180         lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
181         
182         if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXA))
183             lstrcpyA(((MONITORINFOEXA*)lpMonitorInfo)->szDevice, "DISPLAY");
184
185         return TRUE;
186     }
187
188     return FALSE;
189 }
190
191 BOOL WINAPI GetMonitorInfoW(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
192 {
193     RECT rcWork;
194
195     if ((hMonitor == xPRIMARY_MONITOR) &&
196         lpMonitorInfo &&
197         (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
198         SystemParametersInfoW(SPI_GETWORKAREA, 0, &rcWork, 0))
199     {
200         lpMonitorInfo->rcMonitor.left = 0;
201         lpMonitorInfo->rcMonitor.top  = 0;
202         lpMonitorInfo->rcMonitor.right  = GetSystemMetrics(SM_CXSCREEN);
203         lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics(SM_CYSCREEN);
204         lpMonitorInfo->rcWork = rcWork;
205         lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
206
207         if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEXW))
208             lstrcpyW(((MONITORINFOEXW*)lpMonitorInfo)->szDevice, (LPCWSTR)"D\0I\0S\0P\0L\0A\0Y\0\0");
209
210         return TRUE;
211     }
212
213     return FALSE;
214 }
215
216 BOOL WINAPI EnumDisplayMonitors(
217         HDC             hdcOptionalForPainting,
218         LPRECT         lprcEnumMonitorsThatIntersect,
219         MONITORENUMPROC lpfnEnumProc,
220         LPARAM          dwData)
221 {
222     RECT rcLimit;
223
224     if (!lpfnEnumProc)
225         return FALSE;
226
227     rcLimit.left   = 0;
228     rcLimit.top    = 0;
229     rcLimit.right  = GetSystemMetrics(SM_CXSCREEN);
230     rcLimit.bottom = GetSystemMetrics(SM_CYSCREEN);
231
232     if (hdcOptionalForPainting)
233     {
234         RECT    rcClip;
235         POINT   ptOrg;
236
237         switch (GetClipBox(hdcOptionalForPainting, &rcClip))
238         {
239         default:
240             if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
241                 return FALSE;
242
243             OffsetRect(&rcLimit, -ptOrg.x, -ptOrg.y);
244             if (IntersectRect(&rcLimit, &rcLimit, &rcClip) &&
245                 (!lprcEnumMonitorsThatIntersect ||
246                      IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
247
248                 break;
249             }
250             /*fall thru */
251         case NULLREGION:
252              return TRUE;
253         case ERROR:
254              return FALSE;
255         }
256     } else {
257         if (    lprcEnumMonitorsThatIntersect &&
258                 !IntersectRect(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
259
260             return TRUE;
261         }
262     }
263
264     return lpfnEnumProc(
265             xPRIMARY_MONITOR,
266             hdcOptionalForPainting,
267             &rcLimit,
268             dwData);
269 }