Changed // comments to /* */ so WINE compiles with non-gcc compilers
[wine] / windows / multimon.c
1 /*
2  * Multimonitor APIs
3  *
4  * Copyright 1998 Turchanov Sergey
5  */
6
7 #include "windows.h"
8
9 #define xPRIMARY_MONITOR ((HMONITOR)0x12340042)
10
11 HMONITOR WINAPI MonitorFromPoint(POINT32 ptScreenCoords, DWORD dwFlags)
12 {
13     if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
14         ((ptScreenCoords.x >= 0) &&
15         (ptScreenCoords.x < GetSystemMetrics32(SM_CXSCREEN)) &&
16         (ptScreenCoords.y >= 0) &&
17         (ptScreenCoords.y < GetSystemMetrics32(SM_CYSCREEN))))
18     {
19         return xPRIMARY_MONITOR;
20     }
21         return NULL;
22 }
23
24 HMONITOR WINAPI MonitorFromRect(LPRECT32 lprcScreenCoords, DWORD dwFlags)
25 {
26     if ((dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST)) ||
27         ((lprcScreenCoords->right > 0) &&
28         (lprcScreenCoords->bottom > 0) &&
29         (lprcScreenCoords->left < GetSystemMetrics32(SM_CXSCREEN)) &&
30         (lprcScreenCoords->top < GetSystemMetrics32(SM_CYSCREEN))))
31     {
32         return xPRIMARY_MONITOR;
33     }
34     return NULL;
35 }
36
37 HMONITOR WINAPI MonitorFromWindow(HWND32 hWnd, DWORD dwFlags)
38 {
39     WINDOWPLACEMENT32 wp;
40
41     if (dwFlags & (MONITOR_DEFAULTTOPRIMARY | MONITOR_DEFAULTTONEAREST))
42         return xPRIMARY_MONITOR;
43
44     if (IsIconic32(hWnd) ? 
45             GetWindowPlacement32(hWnd, &wp) : 
46             GetWindowRect32(hWnd, &wp.rcNormalPosition)) {
47
48         return MonitorFromRect(&wp.rcNormalPosition, dwFlags);
49     }
50
51     return NULL;
52 }
53
54 BOOL32 WINAPI GetMonitorInfo32A(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
55 {
56     RECT32 rcWork;
57
58     if ((hMonitor == xPRIMARY_MONITOR) &&
59         lpMonitorInfo &&
60         (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
61         SystemParametersInfo32A(SPI_GETWORKAREA, 0, &rcWork, 0))
62     {
63         lpMonitorInfo->rcMonitor.left = 0;
64         lpMonitorInfo->rcMonitor.top  = 0;
65         lpMonitorInfo->rcMonitor.right  = GetSystemMetrics32(SM_CXSCREEN);
66         lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics32(SM_CYSCREEN);
67         lpMonitorInfo->rcWork = rcWork;
68         lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
69         
70         if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEX32A))
71             lstrcpy32A(((MONITORINFOEX32A*)lpMonitorInfo)->szDevice, "DISPLAY");
72
73         return TRUE;
74     }
75
76     return FALSE;
77 }
78
79 BOOL32 WINAPI GetMonitorInfo32W(HMONITOR hMonitor, LPMONITORINFO lpMonitorInfo)
80 {
81     RECT32 rcWork;
82
83     if ((hMonitor == xPRIMARY_MONITOR) &&
84         lpMonitorInfo &&
85         (lpMonitorInfo->cbSize >= sizeof(MONITORINFO)) &&
86         SystemParametersInfo32W(SPI_GETWORKAREA, 0, &rcWork, 0))
87     {
88         lpMonitorInfo->rcMonitor.left = 0;
89         lpMonitorInfo->rcMonitor.top  = 0;
90         lpMonitorInfo->rcMonitor.right  = GetSystemMetrics32(SM_CXSCREEN);
91         lpMonitorInfo->rcMonitor.bottom = GetSystemMetrics32(SM_CYSCREEN);
92         lpMonitorInfo->rcWork = rcWork;
93         lpMonitorInfo->dwFlags = MONITORINFOF_PRIMARY;
94
95         if (lpMonitorInfo->cbSize >= sizeof(MONITORINFOEX32W))
96             lstrcpy32W(((MONITORINFOEX32W*)lpMonitorInfo)->szDevice, (LPCWSTR)"D\0I\0S\0P\0L\0A\0Y\0\0");
97
98         return TRUE;
99     }
100
101     return FALSE;
102 }
103
104 BOOL32 WINAPI EnumDisplayMonitors(
105         HDC32             hdcOptionalForPainting,
106         LPRECT32         lprcEnumMonitorsThatIntersect,
107         MONITORENUMPROC lpfnEnumProc,
108         LPARAM          dwData)
109 {
110     RECT32 rcLimit;
111
112     if (!lpfnEnumProc)
113         return FALSE;
114
115     rcLimit.left   = 0;
116     rcLimit.top    = 0;
117     rcLimit.right  = GetSystemMetrics32(SM_CXSCREEN);
118     rcLimit.bottom = GetSystemMetrics32(SM_CYSCREEN);
119
120     if (hdcOptionalForPainting)
121     {
122         RECT32    rcClip;
123         POINT32   ptOrg;
124
125         switch (GetClipBox32(hdcOptionalForPainting, &rcClip))
126         {
127         default:
128             if (!GetDCOrgEx(hdcOptionalForPainting, &ptOrg))
129                 return FALSE;
130
131             OffsetRect32(&rcLimit, -ptOrg.x, -ptOrg.y);
132             if (IntersectRect32(&rcLimit, &rcLimit, &rcClip) &&
133                 (!lprcEnumMonitorsThatIntersect ||
134                      IntersectRect32(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect))) {
135
136                 break;
137             }
138             /*fall thru */
139         case NULLREGION:
140              return TRUE;
141         case ERROR:
142              return FALSE;
143         }
144     } else {
145         if (    lprcEnumMonitorsThatIntersect &&
146                 !IntersectRect32(&rcLimit, &rcLimit, lprcEnumMonitorsThatIntersect)) {
147
148             return TRUE;
149         }
150     }
151
152     return lpfnEnumProc(
153             xPRIMARY_MONITOR,
154             hdcOptionalForPainting,
155             &rcLimit,
156             dwData);
157 }